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