1 /* 2 * TCU support for various chips. 3 * 4 * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/hw_mmio_register_block.h> 32 33 // TCU channel. 34 35 class Tcu_channel 36 { 37 protected: 38 uint8_t _channel; 39 Hw::Register_block<32> _regs; 40 41 uint32_t get_field(uint32_t reg, uint32_t mask, uint8_t shift); 42 void set_field(uint32_t reg, uint32_t mask, uint8_t shift, uint32_t value); 43 44 public: 45 explicit Tcu_channel(l4_addr_t start, uint8_t channel); 46 47 virtual void disable(); 48 virtual void enable(); 49 virtual bool is_enabled(); 50 virtual uint8_t get_clock(); 51 virtual void set_clock(uint8_t clock); 52 virtual uint32_t get_prescale(); 53 virtual void set_prescale(uint32_t prescale); 54 virtual uint32_t get_counter(); 55 virtual void set_counter(uint32_t value); 56 virtual uint8_t get_count_mode(); 57 virtual void set_count_mode(uint8_t mode); 58 virtual uint32_t get_full_data_value(); 59 virtual void set_full_data_value(uint32_t value); 60 virtual uint32_t get_half_data_value(); 61 virtual void set_half_data_value(uint32_t value); 62 }; 63 64 // TCU device control. 65 66 class Tcu_chip 67 { 68 protected: 69 l4_addr_t _start, _end; 70 71 virtual unsigned int num_channels() = 0; 72 73 virtual Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel) = 0; 74 75 public: 76 explicit Tcu_chip(l4_addr_t start, l4_addr_t end); 77 78 Tcu_channel *get_channel(uint8_t channel); 79 }; 80 81 #endif /* __cplusplus */