1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/tcu/include/tcu-common.h Thu Feb 01 01:16:04 2024 +0100
1.3 @@ -0,0 +1,81 @@
1.4 +/*
1.5 + * TCU support for various chips.
1.6 + *
1.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <l4/sys/types.h>
1.28 +#include <stdint.h>
1.29 +
1.30 +
1.31 +
1.32 +#ifdef __cplusplus
1.33 +
1.34 +#include <l4/devices/hw_mmio_register_block.h>
1.35 +
1.36 +// TCU channel.
1.37 +
1.38 +class Tcu_channel
1.39 +{
1.40 +protected:
1.41 + uint8_t _channel;
1.42 + Hw::Register_block<32> _regs;
1.43 +
1.44 + uint32_t get_field(uint32_t reg, uint32_t mask, uint8_t shift);
1.45 + void set_field(uint32_t reg, uint32_t mask, uint8_t shift, uint32_t value);
1.46 +
1.47 +public:
1.48 + explicit Tcu_channel(l4_addr_t start, uint8_t channel);
1.49 +
1.50 + virtual void disable();
1.51 + virtual void enable();
1.52 + virtual bool is_enabled();
1.53 + virtual uint8_t get_clock();
1.54 + virtual void set_clock(uint8_t clock);
1.55 + virtual uint32_t get_prescale();
1.56 + virtual void set_prescale(uint32_t prescale);
1.57 + virtual uint32_t get_counter();
1.58 + virtual void set_counter(uint32_t value);
1.59 + virtual uint8_t get_count_mode();
1.60 + virtual void set_count_mode(uint8_t mode);
1.61 + virtual uint32_t get_full_data_value();
1.62 + virtual void set_full_data_value(uint32_t value);
1.63 + virtual uint32_t get_half_data_value();
1.64 + virtual void set_half_data_value(uint32_t value);
1.65 +};
1.66 +
1.67 +// TCU device control.
1.68 +
1.69 +class Tcu_chip
1.70 +{
1.71 +protected:
1.72 + l4_addr_t _start, _end;
1.73 +
1.74 + virtual unsigned int num_channels() = 0;
1.75 +
1.76 + virtual Tcu_channel *_get_channel(l4_addr_t addr, uint8_t channel) = 0;
1.77 +
1.78 +public:
1.79 + explicit Tcu_chip(l4_addr_t start, l4_addr_t end);
1.80 +
1.81 + Tcu_channel *get_channel(uint8_t channel);
1.82 +};
1.83 +
1.84 +#endif /* __cplusplus */