1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/landfall-examples/hw_info/x1600.c Mon Oct 30 17:25:00 2023 +0100
1.3 @@ -0,0 +1,443 @@
1.4 +/*
1.5 + * Access various peripherals on a board using the X1600.
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 +#include <l4/devices/aic-x1600.h>
1.26 +#include <l4/devices/cpm-x1600.h>
1.27 +#include <l4/devices/dma-x1600.h>
1.28 +#include <l4/devices/gpio-x1600.h>
1.29 +#include <l4/devices/i2c-x1600.h>
1.30 +#include <l4/devices/spi-gpio.h>
1.31 +#include "common.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 + return x1600_aic_init(aic_start, start, end, cpm);
1.40 +}
1.41 +
1.42 +void *aic_get_channel(void *aic, int num, void *channel)
1.43 +{
1.44 + return x1600_aic_get_channel(aic, num, channel);
1.45 +}
1.46 +
1.47 +long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr)
1.48 +{
1.49 + return x1600_aic_get_buffer(channel, count, addr);
1.50 +}
1.51 +
1.52 +unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size)
1.53 +{
1.54 + return x1600_aic_transfer(channel, count, sample_rate, sample_size);
1.55 +}
1.56 +
1.57 +
1.58 +
1.59 +/* CPM adapter functions. */
1.60 +
1.61 +void *cpm_init(l4_addr_t cpm_base)
1.62 +{
1.63 + return x1600_cpm_init(cpm_base);
1.64 +}
1.65 +
1.66 +const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock)
1.67 +{
1.68 + return x1600_cpm_clock_type(cpm, clock);
1.69 +}
1.70 +
1.71 +int cpm_have_clock(void *cpm, enum Clock_identifiers clock)
1.72 +{
1.73 + return x1600_cpm_have_clock(cpm, clock);
1.74 +}
1.75 +
1.76 +void cpm_start_clock(void *cpm, enum Clock_identifiers clock)
1.77 +{
1.78 + x1600_cpm_start_clock(cpm, clock);
1.79 +}
1.80 +
1.81 +void cpm_stop_clock(void *cpm, enum Clock_identifiers clock)
1.82 +{
1.83 + x1600_cpm_stop_clock(cpm, clock);
1.84 +}
1.85 +
1.86 +int cpm_get_parameters(void *cpm, enum Clock_identifiers clock,
1.87 + uint32_t parameters[])
1.88 +{
1.89 + return x1600_cpm_get_parameters(cpm, clock, parameters);
1.90 +}
1.91 +
1.92 +int cpm_set_parameters(void *cpm, enum Clock_identifiers clock,
1.93 + int num_parameters, uint32_t parameters[])
1.94 +{
1.95 + return x1600_cpm_set_parameters(cpm, clock, num_parameters, parameters);
1.96 +}
1.97 +
1.98 +uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock)
1.99 +{
1.100 + return x1600_cpm_get_source(cpm, clock);
1.101 +}
1.102 +
1.103 +void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source)
1.104 +{
1.105 + x1600_cpm_set_source(cpm, clock, source);
1.106 +}
1.107 +
1.108 +enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock)
1.109 +{
1.110 + return x1600_cpm_get_source_clock(cpm, clock);
1.111 +}
1.112 +
1.113 +void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source)
1.114 +{
1.115 + x1600_cpm_set_source_clock(cpm, clock, source);
1.116 +}
1.117 +
1.118 +uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock)
1.119 +{
1.120 + return x1600_cpm_get_source_frequency(cpm, clock);
1.121 +}
1.122 +
1.123 +uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock)
1.124 +{
1.125 + return x1600_cpm_get_frequency(cpm, clock);
1.126 +}
1.127 +
1.128 +int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency)
1.129 +{
1.130 + return x1600_cpm_set_frequency(cpm, clock, frequency);
1.131 +}
1.132 +
1.133 +
1.134 +
1.135 +/* DMA adapter functions. */
1.136 +
1.137 +void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm)
1.138 +{
1.139 + return x1600_dma_init(start, end, cpm);
1.140 +}
1.141 +
1.142 +void dma_disable(void *dma_chip)
1.143 +{
1.144 + x1600_dma_disable(dma_chip);
1.145 +}
1.146 +
1.147 +void dma_enable(void *dma_chip)
1.148 +{
1.149 + x1600_dma_enable(dma_chip);
1.150 +}
1.151 +
1.152 +void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq)
1.153 +{
1.154 + return x1600_dma_get_channel(dma, channel, irq);
1.155 +}
1.156 +
1.157 +unsigned int dma_transfer(void *dma_channel,
1.158 + uint32_t source, uint32_t destination,
1.159 + unsigned int count,
1.160 + int source_increment, int destination_increment,
1.161 + uint8_t source_width, uint8_t destination_width,
1.162 + uint8_t transfer_unit_size,
1.163 + int type)
1.164 +{
1.165 + return x1600_dma_transfer(dma_channel, source, destination, count,
1.166 + source_increment, destination_increment,
1.167 + source_width, destination_width,
1.168 + transfer_unit_size, type);
1.169 +}
1.170 +
1.171 +unsigned int dma_wait(void *dma_channel)
1.172 +{
1.173 + return x1600_dma_wait(dma_channel);
1.174 +}
1.175 +
1.176 +
1.177 +
1.178 +/* GPIO adapter functions. */
1.179 +
1.180 +void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins,
1.181 + l4_uint32_t pull_ups, l4_uint32_t pull_downs)
1.182 +{
1.183 + return x1600_gpio_init(start, end, pins, pull_ups, pull_downs);
1.184 +}
1.185 +
1.186 +void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value)
1.187 +{
1.188 + x1600_gpio_setup(gpio, pin, mode, value);
1.189 +}
1.190 +
1.191 +void gpio_config_pull(void *gpio, unsigned pin, unsigned mode)
1.192 +{
1.193 + x1600_gpio_config_pull(gpio, pin, mode);
1.194 +}
1.195 +
1.196 +void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value)
1.197 +{
1.198 + x1600_gpio_config_pad(gpio, pin, func, value);
1.199 +}
1.200 +
1.201 +void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value)
1.202 +{
1.203 + x1600_gpio_config_get(gpio, pin, reg, value);
1.204 +}
1.205 +
1.206 +void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value)
1.207 +{
1.208 + x1600_gpio_config_pad_get(gpio, pin, func, value);
1.209 +}
1.210 +
1.211 +void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues)
1.212 +{
1.213 + x1600_gpio_multi_setup(gpio, mask, mode, outvalues);
1.214 +}
1.215 +
1.216 +void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value)
1.217 +{
1.218 + x1600_gpio_multi_config_pad(gpio, mask, func, value);
1.219 +}
1.220 +
1.221 +void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data)
1.222 +{
1.223 + x1600_gpio_multi_set(gpio, mask, data);
1.224 +}
1.225 +
1.226 +unsigned gpio_multi_get(void *gpio, unsigned offset)
1.227 +{
1.228 + return x1600_gpio_multi_get(gpio, offset);
1.229 +}
1.230 +
1.231 +int gpio_get(void *gpio, unsigned pin)
1.232 +{
1.233 + return x1600_gpio_get(gpio, pin);
1.234 +}
1.235 +
1.236 +void gpio_set(void *gpio, unsigned pin, int value)
1.237 +{
1.238 + x1600_gpio_set(gpio, pin, value);
1.239 +}
1.240 +
1.241 +void *gpio_get_irq(void *gpio, unsigned pin)
1.242 +{
1.243 + return x1600_gpio_get_irq(gpio, pin);
1.244 +}
1.245 +
1.246 +bool gpio_irq_set_mode(void *gpio_irq, unsigned mode)
1.247 +{
1.248 + return x1600_gpio_irq_set_mode(gpio_irq, mode);
1.249 +}
1.250 +
1.251 +
1.252 +
1.253 +/* I2C adapter functions. */
1.254 +
1.255 +void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm,
1.256 + uint32_t frequency)
1.257 +{
1.258 + return x1600_i2c_init(start, end, cpm, frequency);
1.259 +}
1.260 +
1.261 +void *i2c_get_channel(void *i2c, uint8_t channel)
1.262 +{
1.263 + return x1600_i2c_get_channel(i2c, channel);
1.264 +}
1.265 +
1.266 +uint32_t i2c_get_frequency(void *i2c_channel)
1.267 +{
1.268 + return x1600_i2c_get_frequency(i2c_channel);
1.269 +}
1.270 +
1.271 +void i2c_set_target(void *i2c_channel, uint8_t addr)
1.272 +{
1.273 + return x1600_i2c_set_target(i2c_channel, addr);
1.274 +}
1.275 +
1.276 +void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total,
1.277 + int stop)
1.278 +{
1.279 + x1600_i2c_start_read(i2c_channel, buf, total, stop);
1.280 +}
1.281 +
1.282 +void i2c_read(void *i2c_channel)
1.283 +{
1.284 + x1600_i2c_read(i2c_channel);
1.285 +}
1.286 +
1.287 +void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total,
1.288 + int stop)
1.289 +{
1.290 + x1600_i2c_start_write(i2c_channel, buf, total, stop);
1.291 +}
1.292 +
1.293 +void i2c_write(void *i2c_channel)
1.294 +{
1.295 + x1600_i2c_write(i2c_channel);
1.296 +}
1.297 +
1.298 +int i2c_read_done(void *i2c_channel)
1.299 +{
1.300 + return x1600_i2c_read_done(i2c_channel);
1.301 +}
1.302 +
1.303 +int i2c_write_done(void *i2c_channel)
1.304 +{
1.305 + return x1600_i2c_write_done(i2c_channel);
1.306 +}
1.307 +
1.308 +unsigned int i2c_have_read(void *i2c_channel)
1.309 +{
1.310 + return x1600_i2c_have_read(i2c_channel);
1.311 +}
1.312 +
1.313 +unsigned int i2c_have_written(void *i2c_channel)
1.314 +{
1.315 + return x1600_i2c_have_written(i2c_channel);
1.316 +}
1.317 +
1.318 +int i2c_failed(void *i2c_channel)
1.319 +{
1.320 + return x1600_i2c_failed(i2c_channel);
1.321 +}
1.322 +
1.323 +void i2c_stop(void *i2c_channel)
1.324 +{
1.325 + x1600_i2c_stop(i2c_channel);
1.326 +}
1.327 +
1.328 +
1.329 +
1.330 +/* SPI adapter functions. */
1.331 +
1.332 +void *spi_get_channel(void *clock_chip, int clock_pin,
1.333 + void *data_chip, int data_pin,
1.334 + void *enable_chip, int enable_pin,
1.335 + uint32_t frequency)
1.336 +{
1.337 + return spi_gpio_get_channel(clock_chip, clock_pin, data_chip, data_pin, enable_chip, enable_pin, frequency);
1.338 +}
1.339 +
1.340 +void spi_send(void *channel, int bytes, const uint8_t data[])
1.341 +{
1.342 + spi_gpio_send(channel, bytes, data);
1.343 +}
1.344 +
1.345 +
1.346 +
1.347 +/* Memory regions. */
1.348 +
1.349 +const char *memory_regions[] = {
1.350 + [AIC] = "x1600-aic",
1.351 + [CPM] = "x1600-cpm",
1.352 + [DMA] = "x1600-dma",
1.353 + [GPIO] = "x1600-gpio",
1.354 + [I2C] = "x1600-i2c",
1.355 +};
1.356 +
1.357 +
1.358 +
1.359 +/* AIC definitions. */
1.360 +
1.361 +void *aic_channels[] = {NULL};
1.362 +
1.363 +const unsigned int num_aic_channels = 1;
1.364 +
1.365 +l4_cap_idx_t aic_irqs[] = {L4_INVALID_CAP};
1.366 +
1.367 +
1.368 +
1.369 +/* CPM definitions. */
1.370 +
1.371 +struct clock_info clocks[] = {
1.372 + {"ext", Clock_external, "External"},
1.373 + {"plla", Clock_pll_A, "PLL A"},
1.374 + {"plle", Clock_pll_E, "PLL E"},
1.375 + {"pllm", Clock_pll_M, "PLL M"},
1.376 + {"main", Clock_main, "Main"},
1.377 + {"cpu", Clock_cpu, "CPU"},
1.378 + {"ahb0", Clock_hclock0, "AHB0"},
1.379 + {"ahb2", Clock_hclock2, "AHB2"},
1.380 + {"apb", Clock_pclock, "APB"},
1.381 + {"aic", Clock_aic, "AIC"},
1.382 + {"dma", Clock_dma, "DMA"},
1.383 + {"lcd", Clock_lcd_pixel0, "LCD pixel"},
1.384 + {"msc0", Clock_msc0, "MSC0"},
1.385 + {"msc1", Clock_msc1, "MSC1"},
1.386 + {"otg", Clock_otg0, "USB OTG"},
1.387 + {"i2c0", Clock_i2c0, "I2C0"},
1.388 + {"i2c1", Clock_i2c1, "I2C1"},
1.389 + {"i2s0", Clock_i2s0, "I2S0"},
1.390 + {"i2s1", Clock_i2s1, "I2S1"},
1.391 + {"i2s0r", Clock_i2s0_rx, "I2S0 RX"},
1.392 + {"i2s0t", Clock_i2s0_tx, "I2S0 TX"},
1.393 + {"ssi", Clock_ssi0, "SSI"},
1.394 + {"uart0", Clock_uart0, "UART0"},
1.395 + {"uart1", Clock_uart1, "UART1"},
1.396 + {"uart2", Clock_uart2, "UART2"},
1.397 + {"uart3", Clock_uart3, "UART3"},
1.398 + {NULL, Clock_undefined, NULL},
1.399 +};
1.400 +
1.401 +
1.402 +
1.403 +/* DMA definitions. */
1.404 +
1.405 +void *dma_channels[32] = {NULL};
1.406 +
1.407 +const unsigned int num_dma_channels = 32;
1.408 +
1.409 +struct dma_region dma_regions[2];
1.410 +
1.411 +const unsigned int num_dma_regions = 2;
1.412 +
1.413 +l4_cap_idx_t dma_irq = L4_INVALID_CAP;
1.414 +
1.415 +
1.416 +
1.417 +/* GPIO definitions. */
1.418 +
1.419 +struct gpio_port gpio_ports[] = {
1.420 + {0xffffffff, 0x00000000},
1.421 + {0xdffbf7bf, 0x00000000},
1.422 + {0x987e0000, 0x07000007},
1.423 + {0x0000003f, 0x00000000}
1.424 +};
1.425 +
1.426 +const unsigned int num_gpio_ports = 4;
1.427 +
1.428 +const char gpio_port_labels[] = "ABCD";
1.429 +
1.430 +
1.431 +
1.432 +/* I2C definitions. */
1.433 +
1.434 +void *i2c_channels[] = {NULL, NULL};
1.435 +
1.436 +const unsigned int num_i2c_channels = 2;
1.437 +
1.438 +l4_cap_idx_t i2c_irqs[] = {L4_INVALID_CAP, L4_INVALID_CAP};
1.439 +
1.440 +
1.441 +
1.442 +/* SPI definitions. */
1.443 +
1.444 +void *spi_channels[] = {NULL};
1.445 +
1.446 +const unsigned int num_spi_channels = 1;