1 /* 2 * TCU (timer/counter unit) support for the JZ4780. 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/tcu-common.h> 32 33 34 class Tcu_jz4780_channel : public Tcu_channel 35 { 36 public: 37 explicit Tcu_jz4780_channel(l4_addr_t start, uint8_t channel, l4_cap_idx_t irq); 38 }; 39 40 41 class Tcu_jz4780_chip : public Tcu_chip 42 { 43 protected: 44 unsigned int num_channels() 45 { return 8; } 46 47 Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel, l4_cap_idx_t irq); 48 49 public: 50 explicit Tcu_jz4780_chip(l4_addr_t start, l4_addr_t end); 51 }; 52 53 #endif /* __cplusplus */ 54 55 56 57 /* C language interface. */ 58 59 EXTERN_C_BEGIN 60 61 void *jz4780_tcu_init(l4_addr_t tcu_base, l4_addr_t tcu_base_end); 62 63 void *jz4780_tcu_get_channel(void *tcu, uint8_t channel, l4_cap_idx_t irq); 64 65 void jz4780_tcu_disable(void *tcu_channel); 66 67 void jz4780_tcu_enable(void *tcu_channel); 68 69 int jz4780_tcu_is_enabled(void *tcu_channel); 70 71 uint8_t jz4780_tcu_get_clock(void *tcu_channel); 72 73 void jz4780_tcu_set_clock(void *tcu_channel, uint8_t clock); 74 75 uint32_t jz4780_tcu_get_prescale(void *tcu_channel); 76 77 void jz4780_tcu_set_prescale(void *tcu_channel, uint32_t prescale); 78 79 uint32_t jz4780_tcu_get_counter(void *tcu_channel); 80 81 void jz4780_tcu_set_counter(void *tcu_channel, uint32_t value); 82 83 uint8_t jz4780_tcu_get_count_mode(void *tcu_channel); 84 85 void jz4780_tcu_set_count_mode(void *tcu_channel, uint8_t mode); 86 87 uint32_t jz4780_tcu_get_full_data_value(void *tcu_channel); 88 89 void jz4780_tcu_set_full_data_value(void *tcu_channel, uint32_t value); 90 91 uint32_t jz4780_tcu_get_half_data_value(void *tcu_channel); 92 93 void jz4780_tcu_set_half_data_value(void *tcu_channel, uint32_t value); 94 95 int jz4780_tcu_get_full_data_mask(void *tcu_channel); 96 97 void jz4780_tcu_set_full_data_mask(void *tcu_channel, int masked); 98 99 int jz4780_tcu_get_half_data_mask(void *tcu_channel); 100 101 void jz4780_tcu_set_half_data_mask(void *tcu_channel, int masked); 102 103 int jz4780_tcu_have_interrupt(void *tcu_channel); 104 105 int jz4780_tcu_wait_for_irq(void *tcu_channel, unsigned int timeout); 106 107 EXTERN_C_END