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 l4_cap_idx_t _irq; 40 Hw::Register_block<32> _regs; 41 42 uint32_t get_field(uint32_t reg, uint32_t mask, uint8_t shift); 43 void set_field(uint32_t reg, uint32_t mask, uint8_t shift, uint32_t value); 44 45 public: 46 explicit Tcu_channel(l4_addr_t start, uint8_t channel, l4_cap_idx_t irq); 47 48 virtual void disable(); 49 virtual void enable(); 50 virtual bool is_enabled(); 51 virtual uint8_t get_clock(); 52 virtual void set_clock(uint8_t clock); 53 virtual uint32_t get_prescale(); 54 virtual void set_prescale(uint32_t prescale); 55 virtual uint32_t get_counter(); 56 virtual void set_counter(uint32_t value); 57 virtual uint8_t get_count_mode(); 58 virtual void set_count_mode(uint8_t mode); 59 virtual uint32_t get_full_data_value(); 60 virtual void set_full_data_value(uint32_t value); 61 virtual uint32_t get_half_data_value(); 62 virtual void set_half_data_value(uint32_t value); 63 64 // Interrupt-related operations. 65 66 virtual bool get_full_data_mask(); 67 virtual void set_full_data_mask(bool masked); 68 virtual bool get_half_data_mask(); 69 virtual void set_half_data_mask(bool masked); 70 71 virtual void ack_irq(); 72 virtual bool have_interrupt(); 73 virtual bool wait_for_irq(); 74 virtual bool wait_for_irq(unsigned int timeout); 75 }; 76 77 // TCU device control. 78 79 class Tcu_chip 80 { 81 protected: 82 l4_addr_t _start, _end; 83 84 virtual unsigned int num_channels() = 0; 85 86 virtual Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel, 87 l4_cap_idx_t irq) = 0; 88 89 public: 90 explicit Tcu_chip(l4_addr_t start, l4_addr_t end); 91 92 Tcu_channel *get_channel(uint8_t channel, l4_cap_idx_t irq); 93 }; 94 95 #endif /* __cplusplus */