1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/landfall-examples/hw_info/common.h Mon Oct 30 17:25:00 2023 +0100
1.3 @@ -0,0 +1,218 @@
1.4 +/*
1.5 + * Access various peripherals on a board.
1.6 + *
1.7 + * Copyright (C) 2023 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/re/c/dma_space.h>
1.28 +#include <l4/sys/types.h>
1.29 +#include <l4/devices/clocks.h>
1.30 +#include <l4/devices/gpio.h>
1.31 +#include <stdint.h>
1.32 +
1.33 +
1.34 +
1.35 +/* AIC adapter functions. */
1.36 +
1.37 +void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm);
1.38 +
1.39 +void *aic_get_channel(void *aic, int num, void *channel);
1.40 +
1.41 +long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr);
1.42 +
1.43 +unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate,
1.44 + uint8_t sample_size);
1.45 +
1.46 +
1.47 +
1.48 +/* CPM adapter functions. */
1.49 +
1.50 +void *cpm_init(l4_addr_t cpm_base);
1.51 +
1.52 +const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock);
1.53 +
1.54 +int cpm_have_clock(void *cpm, enum Clock_identifiers clock);
1.55 +
1.56 +void cpm_start_clock(void *cpm, enum Clock_identifiers clock);
1.57 +
1.58 +void cpm_stop_clock(void *cpm, enum Clock_identifiers clock);
1.59 +
1.60 +int cpm_get_parameters(void *cpm, enum Clock_identifiers clock,
1.61 + uint32_t parameters[]);
1.62 +
1.63 +int cpm_set_parameters(void *cpm, enum Clock_identifiers clock,
1.64 + int num_parameters, uint32_t parameters[]);
1.65 +
1.66 +uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock);
1.67 +
1.68 +void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source);
1.69 +
1.70 +enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock);
1.71 +
1.72 +void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock,
1.73 + enum Clock_identifiers source);
1.74 +
1.75 +uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock);
1.76 +
1.77 +uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock);
1.78 +
1.79 +int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency);
1.80 +
1.81 +
1.82 +
1.83 +/* DMA adapter functions. */
1.84 +
1.85 +void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm);
1.86 +
1.87 +void dma_disable(void *dma_chip);
1.88 +
1.89 +void dma_enable(void *dma_chip);
1.90 +
1.91 +void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq);
1.92 +
1.93 +unsigned int dma_transfer(void *dma_channel,
1.94 + uint32_t source, uint32_t destination,
1.95 + unsigned int count,
1.96 + int source_increment, int destination_increment,
1.97 + uint8_t source_width, uint8_t destination_width,
1.98 + uint8_t transfer_unit_size,
1.99 + int type);
1.100 +
1.101 +unsigned int dma_wait(void *dma_channel);
1.102 +
1.103 +
1.104 +
1.105 +/* GPIO adapter functions. */
1.106 +
1.107 +void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins,
1.108 + l4_uint32_t pull_ups, l4_uint32_t pull_downs);
1.109 +
1.110 +void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value);
1.111 +
1.112 +void gpio_config_pull(void *gpio, unsigned pin, unsigned mode);
1.113 +
1.114 +void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value);
1.115 +
1.116 +void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value);
1.117 +
1.118 +void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value);
1.119 +
1.120 +void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues);
1.121 +
1.122 +void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value);
1.123 +
1.124 +void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data);
1.125 +
1.126 +unsigned gpio_multi_get(void *gpio, unsigned offset);
1.127 +
1.128 +int gpio_get(void *gpio, unsigned pin);
1.129 +
1.130 +void gpio_set(void *gpio, unsigned pin, int value);
1.131 +
1.132 +void *gpio_get_irq(void *gpio, unsigned pin);
1.133 +
1.134 +bool gpio_irq_set_mode(void *gpio_irq, unsigned mode);
1.135 +
1.136 +
1.137 +
1.138 +/* I2C adapter functions. */
1.139 +
1.140 +void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency);
1.141 +
1.142 +void *i2c_get_channel(void *i2c, uint8_t channel);
1.143 +
1.144 +uint32_t i2c_get_frequency(void *i2c_channel);
1.145 +
1.146 +void i2c_set_target(void *i2c_channel, uint8_t addr);
1.147 +
1.148 +void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total,
1.149 + int stop);
1.150 +
1.151 +void i2c_read(void *i2c_channel);
1.152 +
1.153 +void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total,
1.154 + int stop);
1.155 +
1.156 +void i2c_write(void *i2c_channel);
1.157 +
1.158 +int i2c_read_done(void *i2c_channel);
1.159 +
1.160 +int i2c_write_done(void *i2c_channel);
1.161 +
1.162 +unsigned int i2c_have_read(void *i2c_channel);
1.163 +
1.164 +unsigned int i2c_have_written(void *i2c_channel);
1.165 +
1.166 +int i2c_failed(void *i2c_channel);
1.167 +
1.168 +void i2c_stop(void *i2c_channel);
1.169 +
1.170 +
1.171 +
1.172 +/* SPI adapter functions. */
1.173 +
1.174 +void *spi_get_channel(void *clock_chip, int clock_pin,
1.175 + void *data_chip, int data_pin,
1.176 + void *enable_chip, int enable_pin,
1.177 + uint32_t frequency);
1.178 +
1.179 +void spi_send(void *channel, int bytes, const uint8_t data[]);
1.180 +
1.181 +
1.182 +
1.183 +/* Memory regions. */
1.184 +
1.185 +enum memory_regions
1.186 +{
1.187 + AIC, CPM, DMA, GPIO, I2C
1.188 +};
1.189 +
1.190 +
1.191 +
1.192 +/* CPM definitions. */
1.193 +
1.194 +struct clock_info
1.195 +{
1.196 + const char *id;
1.197 + enum Clock_identifiers clock;
1.198 + const char *name;
1.199 +};
1.200 +
1.201 +
1.202 +
1.203 +/* DMA definitions. */
1.204 +
1.205 +struct dma_region
1.206 +{
1.207 + unsigned int size;
1.208 + unsigned int align;
1.209 + l4_addr_t vaddr;
1.210 + l4re_dma_space_dma_addr_t paddr;
1.211 + l4_cap_idx_t mem;
1.212 +};
1.213 +
1.214 +
1.215 +
1.216 +/* GPIO definitions. */
1.217 +
1.218 +struct gpio_port
1.219 +{
1.220 + const uint32_t pull_ups, pull_downs;
1.221 +};