1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/conf/landfall-examples/mips-jz4780-info.cfg Mon Oct 30 17:25:00 2023 +0100 1.3 @@ -0,0 +1,30 @@ 1.4 +# this is a configuration to start 'ex_jz4780_info' 1.5 + 1.6 +local L4 = require("L4"); 1.7 + 1.8 +local l = L4.default_loader; 1.9 + 1.10 +local io_buses = 1.11 + { 1.12 + common = l:new_channel(); 1.13 + }; 1.14 + 1.15 +l:start({ 1.16 + caps = { 1.17 + common = io_buses.common:svr(), 1.18 + icu = L4.Env.icu, 1.19 + sigma0 = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0), 1.20 + }, 1.21 + log = { "IO", "y" }, 1.22 + l4re_dbg = L4.Dbg.Warn, 1.23 + }, 1.24 + "rom/io rom/hw_devices.io rom/mips-jz4780-info.io"); 1.25 + 1.26 +l:start({ 1.27 + log = L4.Env.log, 1.28 + caps = { 1.29 + icu = L4.Env.icu, 1.30 + vbus = io_buses.common, 1.31 + }, 1.32 + }, 1.33 + "rom/ex_jz4780_info");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/conf/landfall-examples/mips-jz4780-info.io Mon Oct 30 17:25:00 2023 +0100 2.3 @@ -0,0 +1,15 @@ 2.4 +-- vi:ft=lua 2.5 +-- configuration file for io 2.6 + 2.7 +local hw = Io.system_bus() 2.8 + 2.9 +local bus = Io.Vi.System_bus 2.10 +{ 2.11 + AIC = wrap(hw:match("jz4780-aic")); 2.12 + CPM = wrap(hw:match("jz4780-cpm")); 2.13 + DMA = wrap(hw:match("jz4780-dma")); 2.14 + GPIO = wrap(hw:match("jz4780-gpio")); 2.15 + I2C = wrap(hw:match("jz4780-i2c")); 2.16 +} 2.17 + 2.18 +Io.add_vbus("common", bus)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/conf/landfall-examples/mips-jz4780-info.list Mon Oct 30 17:25:00 2023 +0100 3.3 @@ -0,0 +1,15 @@ 3.4 + 3.5 +modaddr 0x1100000 3.6 + 3.7 +entry mips-jz4780-info-example 3.8 +bootstrap bootstrap -serial 3.9 +kernel fiasco -serial_esc 3.10 +roottask moe rom/mips-jz4780-info.cfg 3.11 +module mips-jz4780-info.cfg 3.12 +module mips-jz4780-info.io 3.13 +module plat-ingenic-jz4780/hw_devices.io 3.14 +module l4re 3.15 +module io 3.16 +module ned 3.17 +module ex_jz4780_info 3.18 +module piano-3.raw
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/conf/landfall-examples/mips-x1600-info.cfg Mon Oct 30 17:25:00 2023 +0100 4.3 @@ -0,0 +1,30 @@ 4.4 +# this is a configuration to start 'ex_x1600_info' 4.5 + 4.6 +local L4 = require("L4"); 4.7 + 4.8 +local l = L4.default_loader; 4.9 + 4.10 +local io_buses = 4.11 + { 4.12 + common = l:new_channel(); 4.13 + }; 4.14 + 4.15 +l:start({ 4.16 + caps = { 4.17 + common = io_buses.common:svr(), 4.18 + icu = L4.Env.icu, 4.19 + sigma0 = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0), 4.20 + }, 4.21 + log = { "IO", "y" }, 4.22 + l4re_dbg = L4.Dbg.Warn, 4.23 + }, 4.24 + "rom/io rom/hw_devices.io rom/mips-x1600-info.io"); 4.25 + 4.26 +l:start({ 4.27 + log = L4.Env.log, 4.28 + caps = { 4.29 + icu = L4.Env.icu, 4.30 + vbus = io_buses.common, 4.31 + }, 4.32 + }, 4.33 + "rom/ex_x1600_info");
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/conf/landfall-examples/mips-x1600-info.io Mon Oct 30 17:25:00 2023 +0100 5.3 @@ -0,0 +1,15 @@ 5.4 +-- vi:ft=lua 5.5 +-- configuration file for io 5.6 + 5.7 +local hw = Io.system_bus() 5.8 + 5.9 +local bus = Io.Vi.System_bus 5.10 +{ 5.11 + AIC = wrap(hw:match("x1600-aic")); 5.12 + CPM = wrap(hw:match("x1600-cpm")); 5.13 + DMA = wrap(hw:match("x1600-dma")); 5.14 + GPIO = wrap(hw:match("x1600-gpio")); 5.15 + I2C = wrap(hw:match("x1600-i2c")); 5.16 +} 5.17 + 5.18 +Io.add_vbus("common", bus)
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/conf/landfall-examples/mips-x1600-info.list Mon Oct 30 17:25:00 2023 +0100 6.3 @@ -0,0 +1,15 @@ 6.4 + 6.5 +modaddr 0x1100000 6.6 + 6.7 +entry mips-x1600-info-example 6.8 +bootstrap bootstrap -serial 6.9 +kernel fiasco -serial_esc 6.10 +roottask moe rom/mips-x1600-info.cfg 6.11 +module mips-x1600-info.cfg 6.12 +module mips-x1600-info.io 6.13 +module plat-ingenic-x1600/hw_devices.io 6.14 +module l4re 6.15 +module io 6.16 +module ned 6.17 +module ex_x1600_info 6.18 +module piano-3.raw
7.1 Binary file conf/landfall-examples/piano-3.raw has changed
8.1 --- a/docs/COPYING.txt Mon Oct 30 17:24:21 2023 +0100 8.2 +++ b/docs/COPYING.txt Mon Oct 30 17:25:00 2023 +0100 8.3 @@ -4,7 +4,7 @@ 8.4 All original work in this distribution is covered by the following copyright 8.5 and licensing information: 8.6 8.7 -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk> 8.8 +Copyright (C) 2015-2023 Paul Boddie <paul@boddie.org.uk> 8.9 8.10 This software is free software; you can redistribute it and/or 8.11 modify it under the terms of the GNU General Public License as 8.12 @@ -82,3 +82,27 @@ 8.13 to your version of the font, but you are not obligated 8.14 to do so. If you do not wish to do so, delete this 8.15 exception statement from your version. 8.16 + 8.17 +---- 8.18 + 8.19 +The piano-3.raw sound file was generated as follows: 8.20 + 8.21 +sox -v 0.25 /usr/share/sounds/sound-icons/piano-3.wav conf/landfall-examples/piano-3.raw 8.22 + 8.23 +The original file is provided by the sound-icons package on Debian systems. 8.24 + 8.25 + Copyright (C) 2003 Brailcom, o.p.s. 8.26 + 8.27 + This program is free software; you can redistribute it and/or modify 8.28 + it under the terms of the GNU General Public License as published by 8.29 + the Free Software Foundation; either version 2 of the License, or 8.30 + (at your option) any later version. 8.31 + 8.32 + This program is distributed in the hope that it will be useful, 8.33 + but WITHOUT ANY WARRANTY; without even the implied warranty of 8.34 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8.35 + GNU General Public License for more details. 8.36 + 8.37 + You should have received a copy of the GNU General Public License 8.38 + along with this program; if not, write to the Free Software 8.39 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/pkg/landfall-examples/hw_info/Makefile Mon Oct 30 17:25:00 2023 +0100 9.3 @@ -0,0 +1,12 @@ 9.4 +PKGDIR ?= .. 9.5 +L4DIR ?= $(PKGDIR)/../.. 9.6 + 9.7 +TARGET = ex_jz4780_info ex_x1600_info 9.8 +SRC_C_ex_jz4780_info = hw_info.c jz4780.c 9.9 +SRC_C_ex_x1600_info = hw_info.c x1600.c 9.10 +REQUIRES_LIBS = \ 9.11 + libio l4re_c-util libdrivers-aic libdrivers-cpm \ 9.12 + libdrivers-dma libdrivers-gpio libdrivers-i2c \ 9.13 + libdrivers-spi libdevice-util 9.14 + 9.15 +include $(L4DIR)/mk/prog.mk
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/pkg/landfall-examples/hw_info/common.h Mon Oct 30 17:25:00 2023 +0100 10.3 @@ -0,0 +1,218 @@ 10.4 +/* 10.5 + * Access various peripherals on a board. 10.6 + * 10.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 10.8 + * 10.9 + * This program is free software; you can redistribute it and/or 10.10 + * modify it under the terms of the GNU General Public License as 10.11 + * published by the Free Software Foundation; either version 2 of 10.12 + * the License, or (at your option) any later version. 10.13 + * 10.14 + * This program is distributed in the hope that it will be useful, 10.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10.17 + * GNU General Public License for more details. 10.18 + * 10.19 + * You should have received a copy of the GNU General Public License 10.20 + * along with this program; if not, write to the Free Software 10.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 10.22 + * Boston, MA 02110-1301, USA 10.23 + */ 10.24 + 10.25 +#pragma once 10.26 + 10.27 +#include <l4/re/c/dma_space.h> 10.28 +#include <l4/sys/types.h> 10.29 +#include <l4/devices/clocks.h> 10.30 +#include <l4/devices/gpio.h> 10.31 +#include <stdint.h> 10.32 + 10.33 + 10.34 + 10.35 +/* AIC adapter functions. */ 10.36 + 10.37 +void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm); 10.38 + 10.39 +void *aic_get_channel(void *aic, int num, void *channel); 10.40 + 10.41 +long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr); 10.42 + 10.43 +unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, 10.44 + uint8_t sample_size); 10.45 + 10.46 + 10.47 + 10.48 +/* CPM adapter functions. */ 10.49 + 10.50 +void *cpm_init(l4_addr_t cpm_base); 10.51 + 10.52 +const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock); 10.53 + 10.54 +int cpm_have_clock(void *cpm, enum Clock_identifiers clock); 10.55 + 10.56 +void cpm_start_clock(void *cpm, enum Clock_identifiers clock); 10.57 + 10.58 +void cpm_stop_clock(void *cpm, enum Clock_identifiers clock); 10.59 + 10.60 +int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 10.61 + uint32_t parameters[]); 10.62 + 10.63 +int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 10.64 + int num_parameters, uint32_t parameters[]); 10.65 + 10.66 +uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock); 10.67 + 10.68 +void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source); 10.69 + 10.70 +enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock); 10.71 + 10.72 +void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, 10.73 + enum Clock_identifiers source); 10.74 + 10.75 +uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock); 10.76 + 10.77 +uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock); 10.78 + 10.79 +int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency); 10.80 + 10.81 + 10.82 + 10.83 +/* DMA adapter functions. */ 10.84 + 10.85 +void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm); 10.86 + 10.87 +void dma_disable(void *dma_chip); 10.88 + 10.89 +void dma_enable(void *dma_chip); 10.90 + 10.91 +void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq); 10.92 + 10.93 +unsigned int dma_transfer(void *dma_channel, 10.94 + uint32_t source, uint32_t destination, 10.95 + unsigned int count, 10.96 + int source_increment, int destination_increment, 10.97 + uint8_t source_width, uint8_t destination_width, 10.98 + uint8_t transfer_unit_size, 10.99 + int type); 10.100 + 10.101 +unsigned int dma_wait(void *dma_channel); 10.102 + 10.103 + 10.104 + 10.105 +/* GPIO adapter functions. */ 10.106 + 10.107 +void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, 10.108 + l4_uint32_t pull_ups, l4_uint32_t pull_downs); 10.109 + 10.110 +void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); 10.111 + 10.112 +void gpio_config_pull(void *gpio, unsigned pin, unsigned mode); 10.113 + 10.114 +void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value); 10.115 + 10.116 +void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value); 10.117 + 10.118 +void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value); 10.119 + 10.120 +void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues); 10.121 + 10.122 +void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value); 10.123 + 10.124 +void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data); 10.125 + 10.126 +unsigned gpio_multi_get(void *gpio, unsigned offset); 10.127 + 10.128 +int gpio_get(void *gpio, unsigned pin); 10.129 + 10.130 +void gpio_set(void *gpio, unsigned pin, int value); 10.131 + 10.132 +void *gpio_get_irq(void *gpio, unsigned pin); 10.133 + 10.134 +bool gpio_irq_set_mode(void *gpio_irq, unsigned mode); 10.135 + 10.136 + 10.137 + 10.138 +/* I2C adapter functions. */ 10.139 + 10.140 +void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency); 10.141 + 10.142 +void *i2c_get_channel(void *i2c, uint8_t channel); 10.143 + 10.144 +uint32_t i2c_get_frequency(void *i2c_channel); 10.145 + 10.146 +void i2c_set_target(void *i2c_channel, uint8_t addr); 10.147 + 10.148 +void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 10.149 + int stop); 10.150 + 10.151 +void i2c_read(void *i2c_channel); 10.152 + 10.153 +void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 10.154 + int stop); 10.155 + 10.156 +void i2c_write(void *i2c_channel); 10.157 + 10.158 +int i2c_read_done(void *i2c_channel); 10.159 + 10.160 +int i2c_write_done(void *i2c_channel); 10.161 + 10.162 +unsigned int i2c_have_read(void *i2c_channel); 10.163 + 10.164 +unsigned int i2c_have_written(void *i2c_channel); 10.165 + 10.166 +int i2c_failed(void *i2c_channel); 10.167 + 10.168 +void i2c_stop(void *i2c_channel); 10.169 + 10.170 + 10.171 + 10.172 +/* SPI adapter functions. */ 10.173 + 10.174 +void *spi_get_channel(void *clock_chip, int clock_pin, 10.175 + void *data_chip, int data_pin, 10.176 + void *enable_chip, int enable_pin, 10.177 + uint32_t frequency); 10.178 + 10.179 +void spi_send(void *channel, int bytes, const uint8_t data[]); 10.180 + 10.181 + 10.182 + 10.183 +/* Memory regions. */ 10.184 + 10.185 +enum memory_regions 10.186 +{ 10.187 + AIC, CPM, DMA, GPIO, I2C 10.188 +}; 10.189 + 10.190 + 10.191 + 10.192 +/* CPM definitions. */ 10.193 + 10.194 +struct clock_info 10.195 +{ 10.196 + const char *id; 10.197 + enum Clock_identifiers clock; 10.198 + const char *name; 10.199 +}; 10.200 + 10.201 + 10.202 + 10.203 +/* DMA definitions. */ 10.204 + 10.205 +struct dma_region 10.206 +{ 10.207 + unsigned int size; 10.208 + unsigned int align; 10.209 + l4_addr_t vaddr; 10.210 + l4re_dma_space_dma_addr_t paddr; 10.211 + l4_cap_idx_t mem; 10.212 +}; 10.213 + 10.214 + 10.215 + 10.216 +/* GPIO definitions. */ 10.217 + 10.218 +struct gpio_port 10.219 +{ 10.220 + const uint32_t pull_ups, pull_downs; 10.221 +};
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/pkg/landfall-examples/hw_info/defs.h Mon Oct 30 17:25:00 2023 +0100 11.3 @@ -0,0 +1,88 @@ 11.4 +/* 11.5 + * Common declarations for chip-specific definitions. 11.6 + * 11.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 11.8 + * 11.9 + * This program is free software; you can redistribute it and/or 11.10 + * modify it under the terms of the GNU General Public License as 11.11 + * published by the Free Software Foundation; either version 2 of 11.12 + * the License, or (at your option) any later version. 11.13 + * 11.14 + * This program is distributed in the hope that it will be useful, 11.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11.17 + * GNU General Public License for more details. 11.18 + * 11.19 + * You should have received a copy of the GNU General Public License 11.20 + * along with this program; if not, write to the Free Software 11.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 11.22 + * Boston, MA 02110-1301, USA 11.23 + */ 11.24 + 11.25 +#pragma once 11.26 + 11.27 +#include "common.h" 11.28 + 11.29 + 11.30 + 11.31 +/* Memory regions. */ 11.32 + 11.33 +extern const char *memory_regions[]; 11.34 + 11.35 + 11.36 + 11.37 +/* AIC definitions. */ 11.38 + 11.39 +extern void *aic_channels[]; 11.40 + 11.41 +extern const unsigned int num_aic_channels; 11.42 + 11.43 +extern l4_cap_idx_t aic_irqs[]; 11.44 + 11.45 + 11.46 + 11.47 +/* CPM definitions. */ 11.48 + 11.49 +extern struct clock_info clocks[]; 11.50 + 11.51 + 11.52 + 11.53 +/* DMA definitions. */ 11.54 + 11.55 +extern void *dma_channels[]; 11.56 + 11.57 +extern const unsigned int num_dma_channels; 11.58 + 11.59 +extern struct dma_region dma_regions[]; 11.60 + 11.61 +extern const unsigned int num_dma_regions; 11.62 + 11.63 +extern l4_cap_idx_t dma_irq; 11.64 + 11.65 + 11.66 + 11.67 +/* GPIO definitions. */ 11.68 + 11.69 +extern const unsigned int num_gpio_ports; 11.70 + 11.71 +extern struct gpio_port gpio_ports[]; 11.72 + 11.73 +extern const char gpio_port_labels[]; 11.74 + 11.75 + 11.76 + 11.77 +/* I2C definitions. */ 11.78 + 11.79 +extern void *i2c_channels[]; 11.80 + 11.81 +extern const unsigned int num_i2c_channels; 11.82 + 11.83 +extern l4_cap_idx_t i2c_irqs[]; 11.84 + 11.85 + 11.86 + 11.87 +/* SPI definitions. */ 11.88 + 11.89 +extern void *spi_channels[]; 11.90 + 11.91 +extern const unsigned int num_spi_channels;
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Mon Oct 30 17:25:00 2023 +0100 12.3 @@ -0,0 +1,1365 @@ 12.4 +/* 12.5 + * Access various peripherals on the MIPS Creator CI20 board. 12.6 + * 12.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 12.8 + * 12.9 + * This program is free software; you can redistribute it and/or 12.10 + * modify it under the terms of the GNU General Public License as 12.11 + * published by the Free Software Foundation; either version 2 of 12.12 + * the License, or (at your option) any later version. 12.13 + * 12.14 + * This program is distributed in the hope that it will be useful, 12.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12.17 + * GNU General Public License for more details. 12.18 + * 12.19 + * You should have received a copy of the GNU General Public License 12.20 + * along with this program; if not, write to the Free Software 12.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 12.22 + * Boston, MA 02110-1301, USA 12.23 + */ 12.24 + 12.25 +#include "common.h" 12.26 +#include "defs.h" 12.27 + 12.28 +#include <l4/devices/dma.h> 12.29 +#include <l4/devices/memory.h> 12.30 + 12.31 +#include <l4/io/io.h> 12.32 +#include <l4/re/env.h> 12.33 +#include <l4/re/c/util/cap_alloc.h> 12.34 +#include <l4/sys/cache.h> 12.35 +#include <l4/sys/factory.h> 12.36 +#include <l4/sys/icu.h> 12.37 +#include <l4/sys/ipc.h> 12.38 +#include <l4/sys/irq.h> 12.39 +#include <l4/sys/rcv_endpoint.h> 12.40 +#include <l4/vbus/vbus.h> 12.41 + 12.42 +#include <stdio.h> 12.43 +#include <unistd.h> 12.44 +#include <stdint.h> 12.45 +#include <stdlib.h> 12.46 +#include <string.h> 12.47 + 12.48 + 12.49 + 12.50 +/* Common configuration. */ 12.51 + 12.52 +static l4_cap_idx_t icucap; 12.53 + 12.54 + 12.55 + 12.56 +/* Device and resource discovery. */ 12.57 + 12.58 +static long item_in_range(long start, long end, long index) 12.59 +{ 12.60 + if (start < end) 12.61 + return start + index; 12.62 + else if (start > end) 12.63 + return start - index; 12.64 + else 12.65 + return start; 12.66 +} 12.67 + 12.68 + 12.69 + 12.70 +/* Common functions. */ 12.71 + 12.72 +static int init_irq(int num, l4_cap_idx_t irq, l4_uint32_t start, l4_uint32_t end) 12.73 +{ 12.74 + /* Create interrupt object. */ 12.75 + 12.76 + long err = l4_error(l4_factory_create_irq(l4re_global_env->factory, irq)); 12.77 + 12.78 + if (err) 12.79 + { 12.80 + printf("Could not create IRQ object: %ld\n", err); 12.81 + return 1; 12.82 + } 12.83 + 12.84 + /* Bind interrupt objects to IRQ numbers. */ 12.85 + 12.86 + err = l4_error(l4_icu_bind(icucap, 12.87 + item_in_range(start, end, num), 12.88 + irq)); 12.89 + 12.90 + if (err) 12.91 + { 12.92 + printf("Could not bind IRQ to the ICU: %ld\n", err); 12.93 + return 1; 12.94 + } 12.95 + 12.96 + /* Attach ourselves to the interrupt handler. */ 12.97 + 12.98 + err = l4_error(l4_rcv_ep_bind_thread(irq, l4re_env()->main_thread, num)); 12.99 + 12.100 + if (err) 12.101 + { 12.102 + printf("Could not attach to IRQs: %ld\n", err); 12.103 + return 1; 12.104 + } 12.105 + 12.106 + return 0; 12.107 +} 12.108 + 12.109 +static const char *delimiters = " \n"; 12.110 + 12.111 +static char *read_token(const char *message) 12.112 +{ 12.113 + char *token; 12.114 + 12.115 + if ((token = strtok(NULL, delimiters)) == NULL) 12.116 + { 12.117 + if (message != NULL) 12.118 + printf("%s?\n", message); 12.119 + } 12.120 + 12.121 + return token; 12.122 +} 12.123 + 12.124 +static int read_increment(const char *message, int *increment) 12.125 +{ 12.126 + char *token = read_token(message); 12.127 + 12.128 + if (token == NULL) 12.129 + return 0; 12.130 + 12.131 + *increment = !strncmp(token, "i", 1); 12.132 + return 1; 12.133 +} 12.134 + 12.135 +static int read_encoded_number(const char *message, const char *format, unsigned int *num) 12.136 +{ 12.137 + char *token = read_token(message); 12.138 + 12.139 + if (token == NULL) 12.140 + return 0; 12.141 + 12.142 + sscanf(token, format, num); 12.143 + return 1; 12.144 +} 12.145 + 12.146 +static int read_number(const char *message, unsigned int *num) 12.147 +{ 12.148 + char *token = read_token(message); 12.149 + 12.150 + if (token == NULL) 12.151 + return 0; 12.152 + 12.153 + if (!strncmp(token, "0x", 2) || !strncmp(token, "0X", 2)) 12.154 + sscanf(token, "%x", num); 12.155 + else 12.156 + *num = atoi(token); 12.157 + 12.158 + return 1; 12.159 +} 12.160 + 12.161 +static int get_resource_number(const char *type, unsigned int available) 12.162 +{ 12.163 + unsigned int num; 12.164 + 12.165 + if (!read_number(type, &num)) 12.166 + return -1; 12.167 + 12.168 + if (num >= available) 12.169 + { 12.170 + printf("%s number out of range.\n", type); 12.171 + return -1; 12.172 + } 12.173 + 12.174 + return num; 12.175 +} 12.176 + 12.177 +static int get_channel_number(unsigned int available) 12.178 +{ 12.179 + return get_resource_number("Channel", available); 12.180 +} 12.181 + 12.182 +static int get_region_number(unsigned int available) 12.183 +{ 12.184 + return get_resource_number("Region", available); 12.185 +} 12.186 + 12.187 +static void *get_channel(int num_channels, void *channels[], int *num) 12.188 +{ 12.189 + int n = get_channel_number(num_channels); 12.190 + void *channel; 12.191 + 12.192 + if (n < 0) 12.193 + return NULL; 12.194 + 12.195 + channel = channels[n]; 12.196 + 12.197 + if (channel == NULL) 12.198 + printf("Channel needs creating.\n"); 12.199 + 12.200 + if (num != NULL) 12.201 + *num = n; 12.202 + 12.203 + return channel; 12.204 +} 12.205 + 12.206 +static void list_channels(int num_channels, void *channels[]) 12.207 +{ 12.208 + int num; 12.209 + void *channel; 12.210 + 12.211 + for (num = 0; num < num_channels; num++) 12.212 + { 12.213 + printf("Channel %d: ", num); 12.214 + 12.215 + channel = channels[num]; 12.216 + 12.217 + if (channel == NULL) 12.218 + printf("(inactive)\n"); 12.219 + else 12.220 + printf("active\n"); 12.221 + } 12.222 +} 12.223 + 12.224 + 12.225 + 12.226 +/* AIC/I2S configuration. */ 12.227 + 12.228 +static l4_uint32_t aic_irq_start = 0, aic_irq_end = 0; 12.229 + 12.230 +/* AIC/I2S operations. */ 12.231 + 12.232 +static void new_aic_channel(void *aic) 12.233 +{ 12.234 + l4_cap_idx_t irqcap; 12.235 + int num = get_channel_number(num_aic_channels); 12.236 + void *channel; 12.237 + 12.238 + if (num < 0) 12.239 + return; 12.240 + 12.241 + channel = get_channel(num_dma_channels, dma_channels, NULL); 12.242 + 12.243 + if (channel == NULL) 12.244 + return; 12.245 + 12.246 + irqcap = l4re_util_cap_alloc(); 12.247 + 12.248 + if (init_irq(num, irqcap, aic_irq_start, aic_irq_end)) 12.249 + return; 12.250 + 12.251 + aic_channels[num] = aic_get_channel(aic, num, channel); 12.252 + aic_irqs[num] = irqcap; 12.253 +} 12.254 + 12.255 +static void set_aic_buffer(void) 12.256 +{ 12.257 + char *token; 12.258 + FILE *fp; 12.259 + void *channel = get_channel(num_aic_channels, aic_channels, NULL); 12.260 + unsigned int size; 12.261 + l4_addr_t vaddr; 12.262 + 12.263 + if (channel == NULL) 12.264 + return; 12.265 + 12.266 + if (!read_number("Buffer size", &size)) 12.267 + return; 12.268 + 12.269 + if (aic_get_buffer(channel, size, &vaddr)) 12.270 + { 12.271 + printf("Could not get buffer.\n"); 12.272 + return; 12.273 + } 12.274 + 12.275 + memset((void *) vaddr, 0, size); 12.276 + 12.277 + if ((token = read_token("Filename")) == NULL) 12.278 + return; 12.279 + 12.280 + /* Populate the region from the file. */ 12.281 + 12.282 + fp = fopen(token, "r"); 12.283 + 12.284 + if (fp == NULL) 12.285 + { 12.286 + printf("File not readable.\n"); 12.287 + return; 12.288 + } 12.289 + 12.290 + fread((char *) vaddr, sizeof(char), size, fp); 12.291 + fclose(fp); 12.292 + 12.293 + l4_cache_flush_data(vaddr, vaddr + size); 12.294 +} 12.295 + 12.296 +static void aic_transfer_data(void) 12.297 +{ 12.298 + void *channel = get_channel(num_aic_channels, aic_channels, NULL); 12.299 + unsigned int count, rate, resolution, transferred; 12.300 + 12.301 + if (channel == NULL) 12.302 + return; 12.303 + 12.304 + if (!read_number("Sample size", &count)) 12.305 + return; 12.306 + 12.307 + if (!read_number("Sample rate", &rate)) 12.308 + return; 12.309 + 12.310 + if (!read_number("Sample resolution", &resolution)) 12.311 + return; 12.312 + 12.313 + transferred = aic_transfer(channel, count, rate, resolution); 12.314 + 12.315 + printf("Transferred: %d\n", transferred); 12.316 +} 12.317 + 12.318 + 12.319 + 12.320 +/* CPM operations. */ 12.321 + 12.322 +static const char *clock_id(enum Clock_identifiers clock) 12.323 +{ 12.324 + for (int i = 0; clocks[i].id != NULL; i++) 12.325 + if (clock == clocks[i].clock) 12.326 + return clocks[i].id; 12.327 + 12.328 + return NULL; 12.329 +} 12.330 + 12.331 +static enum Clock_identifiers get_clock(char *id) 12.332 +{ 12.333 + if (id != NULL) 12.334 + { 12.335 + for (int i = 0; clocks[i].id != NULL; i++) 12.336 + if (!strcmp(id, clocks[i].id)) 12.337 + return clocks[i].clock; 12.338 + } 12.339 + 12.340 + return Clock_undefined; 12.341 +} 12.342 + 12.343 +static const char list_clocks_separator[] = "--------------------------------"; 12.344 + 12.345 +#define sep(x) (list_clocks_separator + sizeof(list_clocks_separator) - 1 - x) 12.346 + 12.347 +static void list_clocks(void *cpm) 12.348 +{ 12.349 + /* Read information from the clock and power management unit. */ 12.350 + 12.351 + printf("%-5s %-10s %-7s %-6s %-12s %-12s %-24s %-12s %-3s\n" 12.352 + "%-5s %-10s %-7s %-6s %-12s %-12s %-24s %-12s %-3s\n", 12.353 + "Id", "Clock", "Type", "Source", "Source Clock", "Source Freq.", 12.354 + "Parameters", "Frequency", "On", 12.355 + sep(5), sep(10), sep(7), sep(6), sep(12), sep(12), 12.356 + sep(24), sep(12), sep(3)); 12.357 + 12.358 + for (int i = 0; clocks[i].id != NULL; i++) 12.359 + { 12.360 + uint32_t parameters[4]; 12.361 + char parameter_str[25] = {0}; 12.362 + const char *source_id = clock_id(cpm_get_source_clock(cpm, clocks[i].clock)); 12.363 + int num_parameters = cpm_get_parameters(cpm, clocks[i].clock, parameters); 12.364 + 12.365 + for (int p = 0, pos = 0; p < num_parameters; p++) 12.366 + { 12.367 + int result = sprintf(parameter_str + pos, "%-7d ", parameters[p]); 12.368 + if (result < 0) 12.369 + break; 12.370 + pos += result; 12.371 + } 12.372 + 12.373 + printf("%-5s %-10s %-7s %-6d %-12s %-12lld %-24s %-12lld %-3s\n", 12.374 + clocks[i].id, 12.375 + clocks[i].name, 12.376 + cpm_clock_type(cpm, clocks[i].clock), 12.377 + cpm_get_source(cpm, clocks[i].clock), 12.378 + source_id != NULL ? source_id : "...", 12.379 + cpm_get_source_frequency(cpm, clocks[i].clock), 12.380 + parameter_str, 12.381 + cpm_get_frequency(cpm, clocks[i].clock), 12.382 + cpm_have_clock(cpm, clocks[i].clock) ? "on" : "off"); 12.383 + } 12.384 +} 12.385 + 12.386 +static enum Clock_identifiers get_clock_by_name(void) 12.387 +{ 12.388 + char *token; 12.389 + enum Clock_identifiers clock; 12.390 + 12.391 + if ((token = read_token("Clock")) == NULL) 12.392 + return Clock_undefined; 12.393 + 12.394 + clock = get_clock(token); 12.395 + 12.396 + if (clock == Clock_undefined) 12.397 + { 12.398 + printf("Unrecognised clock: %s\n", token); 12.399 + return Clock_undefined; 12.400 + } 12.401 + 12.402 + return clock; 12.403 +} 12.404 + 12.405 +static void set_frequency(void *cpm) 12.406 +{ 12.407 + enum Clock_identifiers clock; 12.408 + unsigned int frequency; 12.409 + 12.410 + clock = get_clock_by_name(); 12.411 + 12.412 + if (clock == Clock_undefined) 12.413 + return; 12.414 + 12.415 + if (!read_number("Frequency", &frequency)) 12.416 + return; 12.417 + 12.418 + if (!cpm_set_frequency(cpm, clock, frequency)) 12.419 + printf("Frequency not set.\n"); 12.420 +} 12.421 + 12.422 +static void set_parameters(void *cpm) 12.423 +{ 12.424 + char *token; 12.425 + enum Clock_identifiers clock; 12.426 + uint32_t parameters[4]; 12.427 + int num_parameters; 12.428 + 12.429 + clock = get_clock_by_name(); 12.430 + 12.431 + if (clock == Clock_undefined) 12.432 + return; 12.433 + 12.434 + for (num_parameters = 0; num_parameters < 4; num_parameters++) 12.435 + { 12.436 + if ((token = read_token(NULL)) == NULL) 12.437 + break; 12.438 + 12.439 + parameters[num_parameters] = atoi(token); 12.440 + } 12.441 + 12.442 + if (!num_parameters) 12.443 + { 12.444 + printf("Parameters?\n"); 12.445 + return; 12.446 + } 12.447 + 12.448 + if (!cpm_set_parameters(cpm, clock, num_parameters, parameters)) 12.449 + printf("Too few or invalid parameters.\n"); 12.450 +} 12.451 + 12.452 +static void set_source(void *cpm) 12.453 +{ 12.454 + enum Clock_identifiers clock; 12.455 + unsigned int source; 12.456 + 12.457 + clock = get_clock_by_name(); 12.458 + 12.459 + if (clock == Clock_undefined) 12.460 + return; 12.461 + 12.462 + if (!read_number("Source", &source)) 12.463 + return; 12.464 + 12.465 + cpm_set_source(cpm, clock, source); 12.466 +} 12.467 + 12.468 +static void start_clock(void *cpm) 12.469 +{ 12.470 + enum Clock_identifiers clock; 12.471 + 12.472 + clock = get_clock_by_name(); 12.473 + 12.474 + if (clock == Clock_undefined) 12.475 + return; 12.476 + 12.477 + cpm_start_clock(cpm, clock); 12.478 +} 12.479 + 12.480 +static void stop_clock(void *cpm) 12.481 +{ 12.482 + enum Clock_identifiers clock; 12.483 + 12.484 + clock = get_clock_by_name(); 12.485 + 12.486 + if (clock == Clock_undefined) 12.487 + return; 12.488 + 12.489 + cpm_stop_clock(cpm, clock); 12.490 +} 12.491 + 12.492 + 12.493 + 12.494 +/* DMA configuration. */ 12.495 + 12.496 +static l4_uint32_t dma_irq_start = 0, dma_irq_end = 0; 12.497 + 12.498 +/* DMA operations. */ 12.499 + 12.500 +static int init_dma(void) 12.501 +{ 12.502 + unsigned int i; 12.503 + 12.504 + for (i = 0; i < num_dma_regions; i++) 12.505 + dma_regions[i].mem = L4_INVALID_CAP; 12.506 + 12.507 + /* Here, only one IRQ is used. */ 12.508 + 12.509 + dma_irq = l4re_util_cap_alloc(); 12.510 + return init_irq(0, dma_irq, dma_irq_start, dma_irq_end); 12.511 +} 12.512 + 12.513 +static struct dma_region *_get_dma_region(void) 12.514 +{ 12.515 + int num = get_region_number(num_dma_regions); 12.516 + 12.517 + if (num < 0) 12.518 + return NULL; 12.519 + 12.520 + return &dma_regions[num]; 12.521 +} 12.522 + 12.523 +static void list_dma_regions(void) 12.524 +{ 12.525 + unsigned int num; 12.526 + struct dma_region *region; 12.527 + unsigned int i; 12.528 + 12.529 + for (num = 0; num < num_dma_regions; num++) 12.530 + { 12.531 + printf("Region %d: ", num); 12.532 + 12.533 + region = &dma_regions[num]; 12.534 + 12.535 + if (l4_is_invalid_cap(region->mem)) 12.536 + printf("(inactive)\n"); 12.537 + else 12.538 + { 12.539 + printf("size = %d; align = %d; virtual = 0x%lx; physical = 0x%llx\ndata =", 12.540 + region->size, region->align, region->vaddr, region->paddr); 12.541 + 12.542 + for (i = 0; (i < region->size) && (i < 16); i++) 12.543 + printf(" %02x", *((uint8_t *) region->vaddr + i)); 12.544 + 12.545 + printf("\n"); 12.546 + } 12.547 + } 12.548 +} 12.549 + 12.550 +static void new_dma_channel(void *dma) 12.551 +{ 12.552 + int num = get_channel_number(num_dma_channels); 12.553 + 12.554 + if (num < 0) 12.555 + return; 12.556 + 12.557 + if (dma_channels[num] != NULL) 12.558 + { 12.559 + printf("Channel already defined.\n"); 12.560 + return; 12.561 + } 12.562 + 12.563 + dma_channels[num] = dma_get_channel(dma, num, dma_irq); 12.564 +} 12.565 + 12.566 +static void new_dma_region(void) 12.567 +{ 12.568 + struct dma_region *region = _get_dma_region(); 12.569 + 12.570 + if (region == NULL) 12.571 + { 12.572 + list_dma_regions(); 12.573 + return; 12.574 + } 12.575 + 12.576 + if (l4_is_valid_cap(region->mem)) 12.577 + { 12.578 + printf("Region already defined.\n"); 12.579 + return; 12.580 + } 12.581 + 12.582 + if (!read_number("Size", ®ion->size)) 12.583 + return; 12.584 + 12.585 + if (!read_number("Alignment", ®ion->align)) 12.586 + return; 12.587 + 12.588 + if (get_dma_region(region->size, region->align, ®ion->vaddr, ®ion->paddr, ®ion->mem)) 12.589 + printf("Could not allocate region.\n"); 12.590 +} 12.591 + 12.592 +static void set_dma_region(void) 12.593 +{ 12.594 + char *token; 12.595 + struct dma_region *region = _get_dma_region(); 12.596 + FILE *fp; 12.597 + 12.598 + if (region == NULL) 12.599 + { 12.600 + list_dma_regions(); 12.601 + return; 12.602 + } 12.603 + 12.604 + if (l4_is_invalid_cap(region->mem)) 12.605 + { 12.606 + printf("Region needs creating.\n"); 12.607 + return; 12.608 + } 12.609 + 12.610 + memset((void *) region->vaddr, 0, region->size); 12.611 + 12.612 + if ((token = read_token("Filename")) == NULL) 12.613 + return; 12.614 + 12.615 + /* Populate the region from the file. */ 12.616 + 12.617 + fp = fopen(token, "r"); 12.618 + 12.619 + if (fp == NULL) 12.620 + { 12.621 + printf("File not readable.\n"); 12.622 + return; 12.623 + } 12.624 + 12.625 + fread((char *) region->vaddr, sizeof(char), region->size, fp); 12.626 + fclose(fp); 12.627 + 12.628 + l4_cache_flush_data(region->vaddr, region->vaddr + region->size); 12.629 +} 12.630 + 12.631 +static void dma_transfer_data(void) 12.632 +{ 12.633 + unsigned int count, to_transfer, transferred; 12.634 + unsigned int source_address, destination_address, source_width, destination_width, 12.635 + transfer_unit_size, request_type; 12.636 + int source_increment, destination_increment; 12.637 + void *channel = get_channel(num_dma_channels, dma_channels, NULL); 12.638 + unsigned int i; 12.639 + 12.640 + if (channel == NULL) 12.641 + return; 12.642 + 12.643 + if (!read_number("Source address", &source_address)) 12.644 + return; 12.645 + 12.646 + if (!read_number("Destination address", &destination_address)) 12.647 + return; 12.648 + 12.649 + if (!read_number("Transfer size", &count)) 12.650 + return; 12.651 + 12.652 + if (!read_increment("Source increment", &source_increment)) 12.653 + return; 12.654 + 12.655 + if (!read_increment("Destination increment", &destination_increment)) 12.656 + return; 12.657 + 12.658 + if (!read_number("Source width", &source_width)) 12.659 + return; 12.660 + 12.661 + if (!read_number("Destination width", &destination_width)) 12.662 + return; 12.663 + 12.664 + if (!read_number("Transfer unit size", &transfer_unit_size)) 12.665 + return; 12.666 + 12.667 + if (!read_number("Request type", &request_type)) 12.668 + return; 12.669 + 12.670 + /* Invalidate DMA region contents in case of transfers between regions. */ 12.671 + 12.672 + for (i = 0; i < num_dma_regions; i++) 12.673 + l4_cache_inv_data(dma_regions[i].vaddr, dma_regions[i].vaddr + dma_regions[i].size); 12.674 + 12.675 + to_transfer = dma_transfer(channel, source_address, destination_address, 12.676 + count, 12.677 + source_increment, destination_increment, 12.678 + source_width, destination_width, 12.679 + transfer_unit_size, 12.680 + request_type); 12.681 + 12.682 + transferred = to_transfer ? count - dma_wait(channel) : 0; 12.683 + 12.684 + printf("Transferred: %d\n", transferred); 12.685 +} 12.686 + 12.687 + 12.688 + 12.689 +/* GPIO operations. */ 12.690 + 12.691 +static char get_gpio_dir_label(unsigned int value, unsigned int level) 12.692 +{ 12.693 + return value == Fix_input ? (level ? 'I' : 'i') : (level ? 'O' : 'o'); 12.694 +} 12.695 + 12.696 +static char get_gpio_irq_label(unsigned int value) 12.697 +{ 12.698 + switch (value) 12.699 + { 12.700 + case L4_IRQ_F_NEG_EDGE: return 'f'; 12.701 + case L4_IRQ_F_POS_EDGE: return 'r'; 12.702 + case L4_IRQ_F_LEVEL_LOW: return 'l'; 12.703 + case L4_IRQ_F_LEVEL_HIGH: return 'h'; 12.704 + default: return '?'; 12.705 + } 12.706 +} 12.707 + 12.708 +static void list_gpios(void *gpio[]) 12.709 +{ 12.710 + unsigned int port, pin; 12.711 + unsigned int func, value, level; 12.712 + 12.713 + printf("gpio: I = input high; i = input low; O = output high; o = output low\n" 12.714 + "irq: h = high level; l = low level; r = rising edge; f = falling edge\n" 12.715 + "alt: function number\n\n"); 12.716 + 12.717 + /* Show pin numbering. */ 12.718 + 12.719 + printf("Port/Pin "); 12.720 + 12.721 + for (pin = 0; pin < 32; pin++) 12.722 + { 12.723 + if (!(pin % 10)) 12.724 + printf(" %d", pin); 12.725 + else 12.726 + printf(" %d", pin % 10); 12.727 + } 12.728 + 12.729 + printf("\n"); 12.730 + 12.731 + for (port = 0; port < num_gpio_ports; port++) 12.732 + { 12.733 + /* Show port and pin configuration. */ 12.734 + 12.735 + printf("%c ", gpio_port_labels[port]); 12.736 + 12.737 + for (pin = 0; pin < 32; pin++) 12.738 + { 12.739 + /* Pad below the first pin digit for multiples of ten other than zero. */ 12.740 + 12.741 + if (pin && !(pin % 10)) 12.742 + printf(" "); 12.743 + 12.744 + gpio_config_pad_get(gpio[port], pin, &func, &value); 12.745 + 12.746 + switch (func) 12.747 + { 12.748 + case Function_alt: printf(" %d", value); break; 12.749 + case Function_irq: printf(" %c", get_gpio_irq_label(value)); break; 12.750 + case Function_gpio: 12.751 + { 12.752 + level = gpio_get(gpio[port], pin); 12.753 + printf(" %c", get_gpio_dir_label(value, level)); 12.754 + break; 12.755 + } 12.756 + default: printf(" ?"); break; 12.757 + } 12.758 + } 12.759 + 12.760 + printf("\n"); 12.761 + } 12.762 +} 12.763 + 12.764 +static int get_port_and_pin(unsigned int *port, unsigned int *pin) 12.765 +{ 12.766 + char *token; 12.767 + 12.768 + if ((token = read_token("Port")) == NULL) 12.769 + return 0; 12.770 + 12.771 + if ((token[0] < 'A') || ((unsigned int) token[0] - (unsigned int) 'A' >= num_gpio_ports)) 12.772 + { 12.773 + printf("Bad port: %c\n", token[0]); 12.774 + return 0; 12.775 + } 12.776 + 12.777 + *port = (unsigned int) token[0] - (unsigned int) 'A'; 12.778 + 12.779 + if (!read_number("Pin", pin)) 12.780 + return 0; 12.781 + 12.782 + return 1; 12.783 +} 12.784 + 12.785 +static void set_gpio_alt_func(void *gpio[]) 12.786 +{ 12.787 + unsigned int port, pin, value; 12.788 + 12.789 + if (!get_port_and_pin(&port, &pin)) 12.790 + return; 12.791 + 12.792 + if (!read_number("Function", &value)) 12.793 + return; 12.794 + 12.795 + gpio_config_pad(gpio[port], pin, Function_alt, value); 12.796 +} 12.797 + 12.798 +static void set_gpio_pad(void *gpio[]) 12.799 +{ 12.800 + char *token; 12.801 + unsigned int port, pin, mode, value = 0; 12.802 + 12.803 + if (!get_port_and_pin(&port, &pin)) 12.804 + return; 12.805 + 12.806 + if ((token = read_token("Mode")) == NULL) 12.807 + return; 12.808 + 12.809 + if (!strcmp(token, "in")) 12.810 + mode = Fix_input; 12.811 + else if (!strcmp(token, "irq")) 12.812 + mode = Fix_irq; 12.813 + else if (!strcmp(token, "out")) 12.814 + { 12.815 + mode = Fix_output; 12.816 + 12.817 + if ((token = read_token(NULL)) != NULL) 12.818 + value = atoi(token); 12.819 + } 12.820 + else 12.821 + { 12.822 + printf("Mode not recognised.\n"); 12.823 + return; 12.824 + } 12.825 + 12.826 + gpio_setup(gpio[port], pin, mode, value); 12.827 +} 12.828 + 12.829 +static void set_gpio_pull(void *gpio[]) 12.830 +{ 12.831 + char *token; 12.832 + unsigned int port, pin, mode; 12.833 + 12.834 + if (!get_port_and_pin(&port, &pin)) 12.835 + return; 12.836 + 12.837 + if ((token = read_token("Mode")) == NULL) 12.838 + return; 12.839 + 12.840 + if (!strcmp(token, "down")) 12.841 + mode = Pull_down; 12.842 + else if (!strcmp(token, "none")) 12.843 + mode = Pull_none; 12.844 + else if (!strcmp(token, "up")) 12.845 + mode = Pull_up; 12.846 + else 12.847 + { 12.848 + printf("Mode not recognised.\n"); 12.849 + return; 12.850 + } 12.851 + 12.852 + gpio_config_pull(gpio[port], pin, mode); 12.853 +} 12.854 + 12.855 + 12.856 + 12.857 +/* I2C configuration. */ 12.858 + 12.859 +static l4_uint32_t i2c_irq_start = 0, i2c_irq_end = 0; 12.860 + 12.861 +/* I2C operations. */ 12.862 + 12.863 +static int _i2c_read(void *channel, uint8_t *buf, unsigned length, 12.864 + int stop, l4_cap_idx_t irqcap, unsigned timeout) 12.865 +{ 12.866 + l4_msgtag_t tag; 12.867 + 12.868 + i2c_start_read(channel, buf, length, stop); 12.869 + 12.870 + while (!i2c_read_done(channel)) 12.871 + { 12.872 + tag = l4_irq_receive(irqcap, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4_timeout_from_us(timeout))); 12.873 + 12.874 + // NOTE: Error not returned. 12.875 + 12.876 + if (l4_ipc_error(tag, l4_utcb())) 12.877 + break; 12.878 + 12.879 + if (i2c_failed(channel)) 12.880 + break; 12.881 + 12.882 + i2c_read(channel); 12.883 + } 12.884 + 12.885 + if (stop) 12.886 + i2c_stop(channel); 12.887 + 12.888 + return i2c_have_read(channel); 12.889 +} 12.890 + 12.891 +static int _i2c_write(void *channel, uint8_t *buf, unsigned length, 12.892 + int stop, l4_cap_idx_t irqcap, unsigned timeout) 12.893 +{ 12.894 + l4_msgtag_t tag; 12.895 + 12.896 + i2c_start_write(channel, buf, length, stop); 12.897 + 12.898 + while (!i2c_write_done(channel)) 12.899 + { 12.900 + tag = l4_irq_receive(irqcap, l4_timeout(L4_IPC_TIMEOUT_NEVER, l4_timeout_from_us(timeout))); 12.901 + 12.902 + // NOTE: Error not returned. 12.903 + 12.904 + if (l4_ipc_error(tag, l4_utcb())) 12.905 + break; 12.906 + 12.907 + if (i2c_failed(channel)) 12.908 + break; 12.909 + 12.910 + i2c_write(channel); 12.911 + } 12.912 + 12.913 + if (stop) 12.914 + i2c_stop(channel); 12.915 + 12.916 + return i2c_have_written(channel); 12.917 +} 12.918 + 12.919 +static void list_i2c_channels(void) 12.920 +{ 12.921 + unsigned int num; 12.922 + void *channel; 12.923 + 12.924 + printf("i2c: channel\n\n"); 12.925 + 12.926 + for (num = 0; num < num_i2c_channels; num++) 12.927 + { 12.928 + printf("Channel %d: ", num); 12.929 + 12.930 + channel = i2c_channels[num]; 12.931 + 12.932 + if (channel == NULL) 12.933 + printf("(inactive)\n"); 12.934 + else 12.935 + printf("%d Hz\n", i2c_get_frequency(channel)); 12.936 + } 12.937 +} 12.938 + 12.939 +static void new_i2c_channel(void *i2c) 12.940 +{ 12.941 + l4_cap_idx_t irqcap; 12.942 + int num = get_channel_number(num_i2c_channels); 12.943 + 12.944 + if (num < 0) 12.945 + return; 12.946 + 12.947 + irqcap = l4re_util_cap_alloc(); 12.948 + 12.949 + if (init_irq(num, irqcap, i2c_irq_start, i2c_irq_end)) 12.950 + return; 12.951 + 12.952 + i2c_channels[num] = i2c_get_channel(i2c, num); 12.953 + i2c_irqs[num] = irqcap; 12.954 +} 12.955 + 12.956 +static void i2c_get(void) 12.957 +{ 12.958 + void *channel; 12.959 + int num; 12.960 + uint8_t buffer[32]; 12.961 + unsigned int address, reg, count; 12.962 + int i, transferred; 12.963 + 12.964 + channel = get_channel(num_i2c_channels, i2c_channels, &num); 12.965 + 12.966 + if (channel == NULL) 12.967 + return; 12.968 + 12.969 + if (!read_encoded_number("Address", "%2x", &address)) 12.970 + return; 12.971 + 12.972 + if (address >= 0x80) 12.973 + { 12.974 + printf("Address must be less than 80.\n"); 12.975 + return; 12.976 + } 12.977 + 12.978 + if (!read_encoded_number("Register", "%2x", ®)) 12.979 + return; 12.980 + 12.981 + if (!read_number(NULL, &count)) 12.982 + count = 1; 12.983 + 12.984 + buffer[0] = (uint8_t) (reg & 0xff); 12.985 + 12.986 + i2c_set_target(channel, address); 12.987 + 12.988 + if (!_i2c_write(channel, buffer, 1, 0, i2c_irqs[num], 1000000)) 12.989 + { 12.990 + printf("Register request failed.\n"); 12.991 + return; 12.992 + } 12.993 + 12.994 + transferred = _i2c_read(channel, buffer, count, 1, i2c_irqs[num], 1000000); 12.995 + 12.996 + if (!transferred) 12.997 + { 12.998 + printf("Register read failed.\n"); 12.999 + return; 12.1000 + } 12.1001 + 12.1002 + for (i = 0; i < transferred; i++) 12.1003 + printf("%02x ", buffer[i]); 12.1004 + printf("\n"); 12.1005 +} 12.1006 + 12.1007 +static void i2c_scan(void) 12.1008 +{ 12.1009 + void *channel; 12.1010 + unsigned int address; 12.1011 + uint8_t buffer[1]; 12.1012 + int num; 12.1013 + 12.1014 + channel = get_channel(num_i2c_channels, i2c_channels, &num); 12.1015 + 12.1016 + if (channel == NULL) 12.1017 + return; 12.1018 + 12.1019 + for (address = 0; address < 0x20; address++) 12.1020 + printf("%02x ", address); 12.1021 + printf("\n"); 12.1022 + 12.1023 + for (address = 0; address < 0x20; address++) 12.1024 + printf("-- "); 12.1025 + 12.1026 + for (address = 0; address < 0x80; address++) 12.1027 + { 12.1028 + if ((address % 32) == 0) 12.1029 + printf("\n"); 12.1030 + 12.1031 + i2c_set_target(channel, address); 12.1032 + 12.1033 + if (_i2c_read(channel, buffer, 1, 1, i2c_irqs[num], 1000)) 12.1034 + printf("%02x ", address); 12.1035 + else 12.1036 + printf("-- "); 12.1037 + } 12.1038 + 12.1039 + printf("\n"); 12.1040 + for (address = 0; address < 0x20; address++) 12.1041 + printf("-- "); 12.1042 + printf("\n\n"); 12.1043 +} 12.1044 + 12.1045 + 12.1046 + 12.1047 +/* SPI operations. */ 12.1048 + 12.1049 +static void new_spi_channel(void *gpio[]) 12.1050 +{ 12.1051 + unsigned int clock_port, clock_pin, data_port, data_pin, enable_port, enable_pin; 12.1052 + int num = get_channel_number(num_spi_channels); 12.1053 + uint32_t frequency; 12.1054 + 12.1055 + if (num < 0) 12.1056 + return; 12.1057 + 12.1058 + if (!get_port_and_pin(&clock_port, &clock_pin)) 12.1059 + return; 12.1060 + 12.1061 + if (!get_port_and_pin(&data_port, &data_pin)) 12.1062 + return; 12.1063 + 12.1064 + if (!get_port_and_pin(&enable_port, &enable_pin)) 12.1065 + return; 12.1066 + 12.1067 + if (!read_number("Frequency", &frequency)) 12.1068 + return; 12.1069 + 12.1070 + spi_channels[num] = spi_get_channel(gpio[clock_port], clock_pin, 12.1071 + gpio[data_port], data_pin, 12.1072 + gpio[enable_port], enable_pin, 12.1073 + frequency); 12.1074 +} 12.1075 + 12.1076 +static void spi_send_data(void) 12.1077 +{ 12.1078 + void *channel = get_channel(num_spi_channels, spi_channels, NULL); 12.1079 + int bytes; 12.1080 + unsigned int byte; 12.1081 + uint8_t buffer[256]; 12.1082 + 12.1083 + bytes = 0; 12.1084 + 12.1085 + while (read_encoded_number(NULL, "%2x", &byte)) 12.1086 + { 12.1087 + buffer[bytes] = (uint8_t) (byte & 0xff); 12.1088 + bytes++; 12.1089 + } 12.1090 + 12.1091 + spi_send(channel, bytes, buffer); 12.1092 +} 12.1093 + 12.1094 + 12.1095 + 12.1096 +/* Command processing. */ 12.1097 + 12.1098 +static void handle_aic(void *aic) 12.1099 +{ 12.1100 + char *token; 12.1101 + 12.1102 + if ((token = read_token(NULL)) != NULL) 12.1103 + { 12.1104 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1105 + list_channels(num_aic_channels, aic_channels); 12.1106 + else if (!strcmp(token, "c") || !strcmp(token, "channel")) 12.1107 + new_aic_channel(aic); 12.1108 + else if (!strcmp(token, "s") || !strcmp(token, "set")) 12.1109 + set_aic_buffer(); 12.1110 + else if (!strcmp(token, "t") || !strcmp(token, "transfer")) 12.1111 + aic_transfer_data(); 12.1112 + else 12.1113 + printf("aic channel | list | set | transfer\n"); 12.1114 + } 12.1115 + else 12.1116 + list_channels(num_aic_channels, aic_channels); 12.1117 +} 12.1118 + 12.1119 +static void handle_cpm(void *cpm) 12.1120 +{ 12.1121 + char *token; 12.1122 + 12.1123 + if ((token = read_token(NULL)) != NULL) 12.1124 + { 12.1125 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1126 + list_clocks(cpm); 12.1127 + else if (!strcmp(token, "f") || !strcmp(token, "frequency")) 12.1128 + set_frequency(cpm); 12.1129 + else if (!strcmp(token, "p") || !strcmp(token, "parameters")) 12.1130 + set_parameters(cpm); 12.1131 + else if (!strcmp(token, "s") || !strcmp(token, "source")) 12.1132 + set_source(cpm); 12.1133 + else if (!strcmp(token, "start")) 12.1134 + start_clock(cpm); 12.1135 + else if (!strcmp(token, "stop")) 12.1136 + stop_clock(cpm); 12.1137 + else 12.1138 + printf("cpm list | frequency | parameters | source | start | stop\n"); 12.1139 + } 12.1140 + else 12.1141 + list_clocks(cpm); 12.1142 +} 12.1143 + 12.1144 +static void handle_dma(void *dma) 12.1145 +{ 12.1146 + char *token; 12.1147 + 12.1148 + if ((token = read_token(NULL)) != NULL) 12.1149 + { 12.1150 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1151 + list_channels(num_dma_channels, dma_channels); 12.1152 + else if (!strcmp(token, "c") || !strcmp(token, "channel")) 12.1153 + new_dma_channel(dma); 12.1154 + else if (!strcmp(token, "r") || !strcmp(token, "region")) 12.1155 + new_dma_region(); 12.1156 + else if (!strcmp(token, "s") || !strcmp(token, "set")) 12.1157 + set_dma_region(); 12.1158 + else if (!strcmp(token, "t") || !strcmp(token, "transfer")) 12.1159 + dma_transfer_data(); 12.1160 + else 12.1161 + printf("dma channel | list | region | set | transfer\n"); 12.1162 + } 12.1163 + else 12.1164 + list_channels(num_dma_channels, dma_channels); 12.1165 +} 12.1166 + 12.1167 +static void handle_gpio(void *gpio[]) 12.1168 +{ 12.1169 + char *token; 12.1170 + 12.1171 + if ((token = read_token(NULL)) != NULL) 12.1172 + { 12.1173 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1174 + list_gpios(gpio); 12.1175 + else if (!strcmp(token, "a") || !strcmp(token, "alt")) 12.1176 + set_gpio_alt_func(gpio); 12.1177 + else if (!strcmp(token, "i") || !strcmp(token, "io")) 12.1178 + set_gpio_pad(gpio); 12.1179 + else if (!strcmp(token, "p") || !strcmp(token, "pull")) 12.1180 + set_gpio_pull(gpio); 12.1181 + else 12.1182 + printf("gpio list | alt | io | pull\n"); 12.1183 + } 12.1184 + else 12.1185 + list_gpios(gpio); 12.1186 +} 12.1187 + 12.1188 +static void handle_i2c(void *i2c) 12.1189 +{ 12.1190 + char *token; 12.1191 + 12.1192 + if ((token = read_token(NULL)) != NULL) 12.1193 + { 12.1194 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1195 + list_i2c_channels(); 12.1196 + else if (!strcmp(token, "c") || !strcmp(token, "channel")) 12.1197 + new_i2c_channel(i2c); 12.1198 + else if (!strcmp(token, "g") || !strcmp(token, "get")) 12.1199 + i2c_get(); 12.1200 + else if (!strcmp(token, "s") || !strcmp(token, "scan")) 12.1201 + i2c_scan(); 12.1202 + else 12.1203 + printf("i2c channel | get | list | scan\n"); 12.1204 + } 12.1205 + else 12.1206 + list_i2c_channels(); 12.1207 +} 12.1208 + 12.1209 +static void handle_spi(void *gpio[]) 12.1210 +{ 12.1211 + char *token; 12.1212 + 12.1213 + if ((token = read_token(NULL)) != NULL) 12.1214 + { 12.1215 + if (!strcmp(token, "l") || !strcmp(token, "list")) 12.1216 + list_channels(num_spi_channels, spi_channels); 12.1217 + else if (!strcmp(token, "c") || !strcmp(token, "channel")) 12.1218 + new_spi_channel(gpio); 12.1219 + else if (!strcmp(token, "s") || !strcmp(token, "send")) 12.1220 + spi_send_data(); 12.1221 + else 12.1222 + printf("spi channel | list | send\n"); 12.1223 + } 12.1224 + else 12.1225 + list_channels(num_spi_channels, spi_channels); 12.1226 +} 12.1227 + 12.1228 + 12.1229 + 12.1230 +int main(void) 12.1231 +{ 12.1232 + l4_addr_t aic_base = 0, aic_base_end = 0; 12.1233 + l4_addr_t aic_phys_base = 0, aic_phys_base_end = 0; 12.1234 + l4_addr_t cpm_base = 0, cpm_base_end = 0; 12.1235 + l4_addr_t dma_base = 0, dma_base_end = 0; 12.1236 + l4_addr_t gpio_base = 0, gpio_base_end = 0; 12.1237 + l4_addr_t i2c_base = 0, i2c_base_end = 0; 12.1238 + void *aic, *cpm, *dma, *gpio[num_gpio_ports], *i2c; 12.1239 + int result = 0; 12.1240 + unsigned int port; 12.1241 + 12.1242 + icucap = l4re_env_get_cap("icu"); 12.1243 + 12.1244 + /* Obtain resource details describing I/O memory. */ 12.1245 + 12.1246 + printf("Access CPM...\n"); 12.1247 + 12.1248 + if ((result = get_memory(memory_regions[CPM], &cpm_base, &cpm_base_end)) < 0) 12.1249 + return 1; 12.1250 + 12.1251 + printf("CPM at 0x%lx...0x%lx.\n", cpm_base, cpm_base_end); 12.1252 + 12.1253 + cpm = cpm_init(cpm_base); 12.1254 + 12.1255 + printf("Access DMA...\n"); 12.1256 + 12.1257 + if ((result = get_memory(memory_regions[DMA], &dma_base, &dma_base_end)) < 0) 12.1258 + return 1; 12.1259 + 12.1260 + printf("DMA at 0x%lx...0x%lx.\n", dma_base, dma_base_end); 12.1261 + 12.1262 + dma = dma_init(dma_base, dma_base_end, cpm); 12.1263 + 12.1264 + if (get_irq(memory_regions[DMA], &dma_irq_start, &dma_irq_end) < 0) 12.1265 + return 1; 12.1266 + 12.1267 + printf("IRQ range at %d...%d.\n", dma_irq_start, dma_irq_end); 12.1268 + 12.1269 + if (init_dma()) 12.1270 + return 1; 12.1271 + 12.1272 + dma_enable(dma); 12.1273 + 12.1274 + printf("Access GPIO...\n"); 12.1275 + 12.1276 + if ((result = get_memory(memory_regions[GPIO], &gpio_base, &gpio_base_end)) < 0) 12.1277 + return 1; 12.1278 + 12.1279 + printf("GPIO at 0x%lx...0x%lx.\n", gpio_base, gpio_base_end); 12.1280 + 12.1281 + for (port = 0; port < num_gpio_ports; port++) 12.1282 + gpio[port] = gpio_init(gpio_base + port * 0x100, gpio_base + (port + 1) * 0x100, 12.1283 + 32, gpio_ports[port].pull_ups, gpio_ports[port].pull_downs); 12.1284 + 12.1285 + printf("Access I2C...\n"); 12.1286 + 12.1287 + if ((result = get_memory(memory_regions[I2C], &i2c_base, &i2c_base_end)) < 0) 12.1288 + return 1; 12.1289 + 12.1290 + printf("I2C at 0x%lx...0x%lx.\n", i2c_base, i2c_base_end); 12.1291 + 12.1292 + i2c = i2c_init(i2c_base, i2c_base_end, cpm, 100000); 12.1293 + 12.1294 + if (get_irq(memory_regions[I2C], &i2c_irq_start, &i2c_irq_end) < 0) 12.1295 + return 1; 12.1296 + 12.1297 + printf("IRQ range at %d...%d.\n", i2c_irq_start, i2c_irq_end); 12.1298 + 12.1299 + printf("Access AIC...\n"); 12.1300 + 12.1301 + if ((result = get_memory_complete(memory_regions[AIC], &aic_base, &aic_base_end, 12.1302 + &aic_phys_base, &aic_phys_base_end)) < 0) 12.1303 + return 1; 12.1304 + 12.1305 + printf("AIC at 0x%lx...0x%lx.\n", aic_base, aic_base_end); 12.1306 + 12.1307 + aic = aic_init(aic_phys_base, aic_base, aic_base_end, cpm); 12.1308 + 12.1309 + if (get_irq(memory_regions[AIC], &aic_irq_start, &aic_irq_end) < 0) 12.1310 + return 1; 12.1311 + 12.1312 + printf("IRQ range at %d...%d.\n", aic_irq_start, aic_irq_end); 12.1313 + 12.1314 + /* Start the interactive session. */ 12.1315 + 12.1316 + printf("aic, cpm, dma, gpio, i2c, spi\n"); 12.1317 + 12.1318 + while (1) 12.1319 + { 12.1320 + char cmdline[256], *token; 12.1321 + 12.1322 + printf("> "); 12.1323 + 12.1324 + token = fgets(cmdline, 64, stdin); 12.1325 + 12.1326 + if (token == NULL) 12.1327 + break; 12.1328 + 12.1329 + if ((token = strtok(cmdline, delimiters)) == NULL) 12.1330 + continue; 12.1331 + 12.1332 + /* AIC/I2S commands. */ 12.1333 + 12.1334 + if (!strcmp(token, "a") || !strcmp(token, "aic") || !strcmp(token, "i2s")) 12.1335 + handle_aic(aic); 12.1336 + 12.1337 + /* CPM commands. */ 12.1338 + 12.1339 + else if (!strcmp(token, "c") || !strcmp(token, "cpm")) 12.1340 + handle_cpm(cpm); 12.1341 + 12.1342 + /* DMA commands. */ 12.1343 + 12.1344 + else if (!strcmp(token, "d") || !strcmp(token, "dma")) 12.1345 + handle_dma(dma); 12.1346 + 12.1347 + /* GPIO commands. */ 12.1348 + 12.1349 + else if (!strcmp(token, "g") || !strcmp(token, "gpio")) 12.1350 + handle_gpio(gpio); 12.1351 + 12.1352 + /* I2C commands. */ 12.1353 + 12.1354 + else if (!strcmp(token, "i") || !strcmp(token, "i2c")) 12.1355 + handle_i2c(i2c); 12.1356 + 12.1357 + /* SPI commands. */ 12.1358 + 12.1359 + else if (!strcmp(token, "s") || !strcmp(token, "spi")) 12.1360 + handle_spi(gpio); 12.1361 + 12.1362 + else 12.1363 + printf("Command?\n"); 12.1364 + } 12.1365 + 12.1366 + printf("End of session.\n"); 12.1367 + return 0; 12.1368 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/pkg/landfall-examples/hw_info/jz4780.c Mon Oct 30 17:25:00 2023 +0100 13.3 @@ -0,0 +1,458 @@ 13.4 +/* 13.5 + * Access various peripherals on a board using the JZ4780. 13.6 + * 13.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 13.8 + * 13.9 + * This program is free software; you can redistribute it and/or 13.10 + * modify it under the terms of the GNU General Public License as 13.11 + * published by the Free Software Foundation; either version 2 of 13.12 + * the License, or (at your option) any later version. 13.13 + * 13.14 + * This program is distributed in the hope that it will be useful, 13.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13.17 + * GNU General Public License for more details. 13.18 + * 13.19 + * You should have received a copy of the GNU General Public License 13.20 + * along with this program; if not, write to the Free Software 13.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 13.22 + * Boston, MA 02110-1301, USA 13.23 + */ 13.24 + 13.25 +#include <l4/devices/aic-x1600.h> /* NOTE: To be replaced. */ 13.26 +#include <l4/devices/cpm-jz4780.h> 13.27 +#include <l4/devices/dma-jz4780.h> 13.28 +#include <l4/devices/gpio-jz4780.h> 13.29 +#include <l4/devices/i2c-jz4780.h> 13.30 +#include <l4/devices/spi-gpio.h> 13.31 +#include "common.h" 13.32 + 13.33 + 13.34 + 13.35 +/* AIC adapter functions. */ 13.36 + 13.37 +void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm) 13.38 +{ 13.39 + return x1600_aic_init(aic_start, start, end, cpm); 13.40 +} 13.41 + 13.42 +void *aic_get_channel(void *aic, int num, void *channel) 13.43 +{ 13.44 + return x1600_aic_get_channel(aic, num, channel); 13.45 +} 13.46 + 13.47 +long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr) 13.48 +{ 13.49 + return x1600_aic_get_buffer(channel, count, addr); 13.50 +} 13.51 + 13.52 +unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size) 13.53 +{ 13.54 + return x1600_aic_transfer(channel, count, sample_rate, sample_size); 13.55 +} 13.56 + 13.57 + 13.58 + 13.59 +/* CPM adapter functions. */ 13.60 + 13.61 +void *cpm_init(l4_addr_t cpm_base) 13.62 +{ 13.63 + return jz4780_cpm_init(cpm_base); 13.64 +} 13.65 + 13.66 +const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock) 13.67 +{ 13.68 + return jz4780_cpm_clock_type(cpm, clock); 13.69 +} 13.70 + 13.71 +int cpm_have_clock(void *cpm, enum Clock_identifiers clock) 13.72 +{ 13.73 + return jz4780_cpm_have_clock(cpm, clock); 13.74 +} 13.75 + 13.76 +void cpm_start_clock(void *cpm, enum Clock_identifiers clock) 13.77 +{ 13.78 + jz4780_cpm_start_clock(cpm, clock); 13.79 +} 13.80 + 13.81 +void cpm_stop_clock(void *cpm, enum Clock_identifiers clock) 13.82 +{ 13.83 + jz4780_cpm_stop_clock(cpm, clock); 13.84 +} 13.85 + 13.86 +int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 13.87 + uint32_t parameters[]) 13.88 +{ 13.89 + return jz4780_cpm_get_parameters(cpm, clock, parameters); 13.90 +} 13.91 + 13.92 +int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 13.93 + int num_parameters, uint32_t parameters[]) 13.94 +{ 13.95 + return jz4780_cpm_set_parameters(cpm, clock, num_parameters, parameters); 13.96 +} 13.97 + 13.98 +uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock) 13.99 +{ 13.100 + return jz4780_cpm_get_source(cpm, clock); 13.101 +} 13.102 + 13.103 +void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source) 13.104 +{ 13.105 + jz4780_cpm_set_source(cpm, clock, source); 13.106 +} 13.107 + 13.108 +enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock) 13.109 +{ 13.110 + return jz4780_cpm_get_source_clock(cpm, clock); 13.111 +} 13.112 + 13.113 +void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source) 13.114 +{ 13.115 + jz4780_cpm_set_source_clock(cpm, clock, source); 13.116 +} 13.117 + 13.118 +uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock) 13.119 +{ 13.120 + return jz4780_cpm_get_source_frequency(cpm, clock); 13.121 +} 13.122 + 13.123 +uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock) 13.124 +{ 13.125 + return jz4780_cpm_get_frequency(cpm, clock); 13.126 +} 13.127 + 13.128 +int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency) 13.129 +{ 13.130 + return jz4780_cpm_set_frequency(cpm, clock, frequency); 13.131 +} 13.132 + 13.133 + 13.134 + 13.135 +/* DMA adapter functions. */ 13.136 + 13.137 +void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm) 13.138 +{ 13.139 + return jz4780_dma_init(start, end, cpm); 13.140 +} 13.141 + 13.142 +void dma_disable(void *dma_chip) 13.143 +{ 13.144 + jz4780_dma_disable(dma_chip); 13.145 +} 13.146 + 13.147 +void dma_enable(void *dma_chip) 13.148 +{ 13.149 + jz4780_dma_enable(dma_chip); 13.150 +} 13.151 + 13.152 +void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq) 13.153 +{ 13.154 + return jz4780_dma_get_channel(dma, channel, irq); 13.155 +} 13.156 + 13.157 +unsigned int dma_transfer(void *dma_channel, 13.158 + uint32_t source, uint32_t destination, 13.159 + unsigned int count, 13.160 + int source_increment, int destination_increment, 13.161 + uint8_t source_width, uint8_t destination_width, 13.162 + uint8_t transfer_unit_size, 13.163 + int type) 13.164 +{ 13.165 + return jz4780_dma_transfer(dma_channel, source, destination, count, 13.166 + source_increment, destination_increment, 13.167 + source_width, destination_width, 13.168 + transfer_unit_size, type); 13.169 +} 13.170 + 13.171 +unsigned int dma_wait(void *dma_channel) 13.172 +{ 13.173 + return jz4780_dma_wait(dma_channel); 13.174 +} 13.175 + 13.176 + 13.177 + 13.178 +/* GPIO adapter functions. */ 13.179 + 13.180 +void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, 13.181 + l4_uint32_t pull_ups, l4_uint32_t pull_downs) 13.182 +{ 13.183 + return jz4780_gpio_init(start, end, pins, pull_ups, pull_downs); 13.184 +} 13.185 + 13.186 +void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) 13.187 +{ 13.188 + jz4780_gpio_setup(gpio, pin, mode, value); 13.189 +} 13.190 + 13.191 +void gpio_config_pull(void *gpio, unsigned pin, unsigned mode) 13.192 +{ 13.193 + jz4780_gpio_config_pull(gpio, pin, mode); 13.194 +} 13.195 + 13.196 +void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value) 13.197 +{ 13.198 + jz4780_gpio_config_pad(gpio, pin, func, value); 13.199 +} 13.200 + 13.201 +void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value) 13.202 +{ 13.203 + jz4780_gpio_config_get(gpio, pin, reg, value); 13.204 +} 13.205 + 13.206 +void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value) 13.207 +{ 13.208 + jz4780_gpio_config_pad_get(gpio, pin, func, value); 13.209 +} 13.210 + 13.211 +void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues) 13.212 +{ 13.213 + jz4780_gpio_multi_setup(gpio, mask, mode, outvalues); 13.214 +} 13.215 + 13.216 +void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value) 13.217 +{ 13.218 + jz4780_gpio_multi_config_pad(gpio, mask, func, value); 13.219 +} 13.220 + 13.221 +void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data) 13.222 +{ 13.223 + jz4780_gpio_multi_set(gpio, mask, data); 13.224 +} 13.225 + 13.226 +unsigned gpio_multi_get(void *gpio, unsigned offset) 13.227 +{ 13.228 + return jz4780_gpio_multi_get(gpio, offset); 13.229 +} 13.230 + 13.231 +int gpio_get(void *gpio, unsigned pin) 13.232 +{ 13.233 + return jz4780_gpio_get(gpio, pin); 13.234 +} 13.235 + 13.236 +void gpio_set(void *gpio, unsigned pin, int value) 13.237 +{ 13.238 + jz4780_gpio_set(gpio, pin, value); 13.239 +} 13.240 + 13.241 +void *gpio_get_irq(void *gpio, unsigned pin) 13.242 +{ 13.243 + return jz4780_gpio_get_irq(gpio, pin); 13.244 +} 13.245 + 13.246 +bool gpio_irq_set_mode(void *gpio_irq, unsigned mode) 13.247 +{ 13.248 + return jz4780_gpio_irq_set_mode(gpio_irq, mode); 13.249 +} 13.250 + 13.251 + 13.252 + 13.253 +/* I2C adapter functions. */ 13.254 + 13.255 +void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 13.256 + uint32_t frequency) 13.257 +{ 13.258 + return jz4780_i2c_init(start, end, cpm, frequency); 13.259 +} 13.260 + 13.261 +void *i2c_get_channel(void *i2c, uint8_t channel) 13.262 +{ 13.263 + return jz4780_i2c_get_channel(i2c, channel); 13.264 +} 13.265 + 13.266 +uint32_t i2c_get_frequency(void *i2c_channel) 13.267 +{ 13.268 + return jz4780_i2c_get_frequency(i2c_channel); 13.269 +} 13.270 + 13.271 +void i2c_set_target(void *i2c_channel, uint8_t addr) 13.272 +{ 13.273 + return jz4780_i2c_set_target(i2c_channel, addr); 13.274 +} 13.275 + 13.276 +void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 13.277 + int stop) 13.278 +{ 13.279 + jz4780_i2c_start_read(i2c_channel, buf, total, stop); 13.280 +} 13.281 + 13.282 +void i2c_read(void *i2c_channel) 13.283 +{ 13.284 + jz4780_i2c_read(i2c_channel); 13.285 +} 13.286 + 13.287 +void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 13.288 + int stop) 13.289 +{ 13.290 + jz4780_i2c_start_write(i2c_channel, buf, total, stop); 13.291 +} 13.292 + 13.293 +void i2c_write(void *i2c_channel) 13.294 +{ 13.295 + jz4780_i2c_write(i2c_channel); 13.296 +} 13.297 + 13.298 +int i2c_read_done(void *i2c_channel) 13.299 +{ 13.300 + return jz4780_i2c_read_done(i2c_channel); 13.301 +} 13.302 + 13.303 +int i2c_write_done(void *i2c_channel) 13.304 +{ 13.305 + return jz4780_i2c_write_done(i2c_channel); 13.306 +} 13.307 + 13.308 +unsigned int i2c_have_read(void *i2c_channel) 13.309 +{ 13.310 + return jz4780_i2c_have_read(i2c_channel); 13.311 +} 13.312 + 13.313 +unsigned int i2c_have_written(void *i2c_channel) 13.314 +{ 13.315 + return jz4780_i2c_have_written(i2c_channel); 13.316 +} 13.317 + 13.318 +int i2c_failed(void *i2c_channel) 13.319 +{ 13.320 + return jz4780_i2c_failed(i2c_channel); 13.321 +} 13.322 + 13.323 +void i2c_stop(void *i2c_channel) 13.324 +{ 13.325 + jz4780_i2c_stop(i2c_channel); 13.326 +} 13.327 + 13.328 + 13.329 + 13.330 +/* SPI adapter functions. */ 13.331 + 13.332 +void *spi_get_channel(void *clock_chip, int clock_pin, 13.333 + void *data_chip, int data_pin, 13.334 + void *enable_chip, int enable_pin, 13.335 + uint32_t frequency) 13.336 +{ 13.337 + return spi_gpio_get_channel(clock_chip, clock_pin, data_chip, data_pin, enable_chip, enable_pin, frequency); 13.338 +} 13.339 + 13.340 +void spi_send(void *channel, int bytes, const uint8_t data[]) 13.341 +{ 13.342 + spi_gpio_send(channel, bytes, data); 13.343 +} 13.344 + 13.345 + 13.346 + 13.347 +/* Memory regions. */ 13.348 + 13.349 +const char *memory_regions[] = { 13.350 + [AIC] = "jz4780-aic", 13.351 + [CPM] = "jz4780-cpm", 13.352 + [DMA] = "jz4780-dma", 13.353 + [GPIO] = "jz4780-gpio", 13.354 + [I2C] = "jz4780-i2c", 13.355 +}; 13.356 + 13.357 + 13.358 + 13.359 +/* AIC definitions. */ 13.360 + 13.361 +void *aic_channels[] = {NULL, NULL}; 13.362 + 13.363 +const unsigned int num_aic_channels = 2; 13.364 + 13.365 +l4_cap_idx_t aic_irqs[] = {L4_INVALID_CAP}; 13.366 + 13.367 + 13.368 + 13.369 +/* CPM definitions. */ 13.370 + 13.371 +struct clock_info clocks[] = { 13.372 + {"ext", Clock_external, "External"}, 13.373 + {"plla", Clock_pll_A, "PLL A"}, 13.374 + {"plle", Clock_pll_E, "PLL E"}, 13.375 + {"pllm", Clock_pll_M, "PLL M"}, 13.376 + {"pllv", Clock_pll_V, "PLL V"}, 13.377 + {"main", Clock_main, "Main"}, 13.378 + {"cpu", Clock_cpu, "CPU"}, 13.379 + {"h2p", Clock_hclock2_pclock, "AHB2/APB"}, 13.380 + {"ahb0", Clock_hclock0, "AHB0"}, 13.381 + {"ahb2", Clock_hclock2, "AHB2"}, 13.382 + {"apb", Clock_pclock, "APB"}, 13.383 + {"dma", Clock_dma, "DMA"}, 13.384 + {"hdmi", Clock_lcd, "HDMI"}, 13.385 + {"lcd", Clock_lcd, "LCD"}, 13.386 + {"lcd0", Clock_lcd_pixel0, "LCD0 pixel"}, 13.387 + {"lcd1", Clock_lcd_pixel1, "LCD1 pixel"}, 13.388 + {"msc", Clock_msc, "MSC"}, 13.389 + {"msc0", Clock_msc0, "MSC0"}, 13.390 + {"msc1", Clock_msc1, "MSC1"}, 13.391 + {"msc2", Clock_msc1, "MSC2"}, 13.392 + {"otg0", Clock_otg0, "USB OTG0"}, 13.393 + {"otg1", Clock_otg1, "USB OTG1"}, 13.394 + {"i2c0", Clock_i2c0, "I2C0"}, 13.395 + {"i2c1", Clock_i2c1, "I2C1"}, 13.396 + {"i2c2", Clock_i2c2, "I2C2"}, 13.397 + {"i2c3", Clock_i2c3, "I2C3"}, 13.398 + {"i2c4", Clock_i2c4, "I2C4"}, 13.399 + {"i2s0", Clock_i2s0, "I2S0"}, 13.400 + {"i2s1", Clock_i2s1, "I2S1"}, 13.401 + {"pcm", Clock_pcm, "PCM"}, 13.402 + {"ssi", Clock_ssi, "SSI"}, 13.403 + {"ssi0", Clock_ssi0, "SSI0"}, 13.404 + {"ssi1", Clock_ssi1, "SSI1"}, 13.405 + {"ssi2", Clock_ssi2, "SSI2"}, 13.406 + {"uart0", Clock_uart0, "UART0"}, 13.407 + {"uart1", Clock_uart1, "UART1"}, 13.408 + {"uart2", Clock_uart2, "UART2"}, 13.409 + {"uart3", Clock_uart3, "UART3"}, 13.410 + {"uart4", Clock_uart4, "UART4"}, 13.411 + {NULL, Clock_undefined, NULL}, 13.412 +}; 13.413 + 13.414 + 13.415 + 13.416 +/* DMA definitions. */ 13.417 + 13.418 +void *dma_channels[32] = {NULL}; 13.419 + 13.420 +const unsigned int num_dma_channels = 32; 13.421 + 13.422 +struct dma_region dma_regions[2]; 13.423 + 13.424 +const unsigned int num_dma_regions = 2; 13.425 + 13.426 +l4_cap_idx_t dma_irq = L4_INVALID_CAP; 13.427 + 13.428 + 13.429 + 13.430 +/* GPIO definitions. */ 13.431 + 13.432 +struct gpio_port gpio_ports[] = { 13.433 + {0x3fff00ff, 0x00000000}, 13.434 + {0xfff0f3fc, 0x000f0c03}, 13.435 + {0x0fffffff, 0x00000000}, 13.436 + {0xffff4fff, 0x0000b000}, 13.437 + {0xf0fff37c, 0x00000483}, 13.438 + {0x7fa7f00f, 0x00580ff0}, 13.439 +}; 13.440 + 13.441 +const unsigned int num_gpio_ports = 6; 13.442 + 13.443 +const char gpio_port_labels[] = "ABCDEF"; 13.444 + 13.445 + 13.446 + 13.447 +/* I2C definitions. */ 13.448 + 13.449 +void *i2c_channels[] = {NULL, NULL, NULL, NULL, NULL}; 13.450 + 13.451 +const unsigned int num_i2c_channels = 5; 13.452 + 13.453 +l4_cap_idx_t i2c_irqs[] = {L4_INVALID_CAP, L4_INVALID_CAP}; 13.454 + 13.455 + 13.456 + 13.457 +/* SPI definitions. */ 13.458 + 13.459 +void *spi_channels[] = {NULL, NULL}; 13.460 + 13.461 +const unsigned int num_spi_channels = 2;
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/pkg/landfall-examples/hw_info/x1600.c Mon Oct 30 17:25:00 2023 +0100 14.3 @@ -0,0 +1,443 @@ 14.4 +/* 14.5 + * Access various peripherals on a board using the X1600. 14.6 + * 14.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 14.8 + * 14.9 + * This program is free software; you can redistribute it and/or 14.10 + * modify it under the terms of the GNU General Public License as 14.11 + * published by the Free Software Foundation; either version 2 of 14.12 + * the License, or (at your option) any later version. 14.13 + * 14.14 + * This program is distributed in the hope that it will be useful, 14.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14.17 + * GNU General Public License for more details. 14.18 + * 14.19 + * You should have received a copy of the GNU General Public License 14.20 + * along with this program; if not, write to the Free Software 14.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 14.22 + * Boston, MA 02110-1301, USA 14.23 + */ 14.24 + 14.25 +#include <l4/devices/aic-x1600.h> 14.26 +#include <l4/devices/cpm-x1600.h> 14.27 +#include <l4/devices/dma-x1600.h> 14.28 +#include <l4/devices/gpio-x1600.h> 14.29 +#include <l4/devices/i2c-x1600.h> 14.30 +#include <l4/devices/spi-gpio.h> 14.31 +#include "common.h" 14.32 + 14.33 + 14.34 + 14.35 +/* AIC adapter functions. */ 14.36 + 14.37 +void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm) 14.38 +{ 14.39 + return x1600_aic_init(aic_start, start, end, cpm); 14.40 +} 14.41 + 14.42 +void *aic_get_channel(void *aic, int num, void *channel) 14.43 +{ 14.44 + return x1600_aic_get_channel(aic, num, channel); 14.45 +} 14.46 + 14.47 +long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr) 14.48 +{ 14.49 + return x1600_aic_get_buffer(channel, count, addr); 14.50 +} 14.51 + 14.52 +unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size) 14.53 +{ 14.54 + return x1600_aic_transfer(channel, count, sample_rate, sample_size); 14.55 +} 14.56 + 14.57 + 14.58 + 14.59 +/* CPM adapter functions. */ 14.60 + 14.61 +void *cpm_init(l4_addr_t cpm_base) 14.62 +{ 14.63 + return x1600_cpm_init(cpm_base); 14.64 +} 14.65 + 14.66 +const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock) 14.67 +{ 14.68 + return x1600_cpm_clock_type(cpm, clock); 14.69 +} 14.70 + 14.71 +int cpm_have_clock(void *cpm, enum Clock_identifiers clock) 14.72 +{ 14.73 + return x1600_cpm_have_clock(cpm, clock); 14.74 +} 14.75 + 14.76 +void cpm_start_clock(void *cpm, enum Clock_identifiers clock) 14.77 +{ 14.78 + x1600_cpm_start_clock(cpm, clock); 14.79 +} 14.80 + 14.81 +void cpm_stop_clock(void *cpm, enum Clock_identifiers clock) 14.82 +{ 14.83 + x1600_cpm_stop_clock(cpm, clock); 14.84 +} 14.85 + 14.86 +int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 14.87 + uint32_t parameters[]) 14.88 +{ 14.89 + return x1600_cpm_get_parameters(cpm, clock, parameters); 14.90 +} 14.91 + 14.92 +int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 14.93 + int num_parameters, uint32_t parameters[]) 14.94 +{ 14.95 + return x1600_cpm_set_parameters(cpm, clock, num_parameters, parameters); 14.96 +} 14.97 + 14.98 +uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock) 14.99 +{ 14.100 + return x1600_cpm_get_source(cpm, clock); 14.101 +} 14.102 + 14.103 +void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source) 14.104 +{ 14.105 + x1600_cpm_set_source(cpm, clock, source); 14.106 +} 14.107 + 14.108 +enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock) 14.109 +{ 14.110 + return x1600_cpm_get_source_clock(cpm, clock); 14.111 +} 14.112 + 14.113 +void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source) 14.114 +{ 14.115 + x1600_cpm_set_source_clock(cpm, clock, source); 14.116 +} 14.117 + 14.118 +uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock) 14.119 +{ 14.120 + return x1600_cpm_get_source_frequency(cpm, clock); 14.121 +} 14.122 + 14.123 +uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock) 14.124 +{ 14.125 + return x1600_cpm_get_frequency(cpm, clock); 14.126 +} 14.127 + 14.128 +int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency) 14.129 +{ 14.130 + return x1600_cpm_set_frequency(cpm, clock, frequency); 14.131 +} 14.132 + 14.133 + 14.134 + 14.135 +/* DMA adapter functions. */ 14.136 + 14.137 +void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm) 14.138 +{ 14.139 + return x1600_dma_init(start, end, cpm); 14.140 +} 14.141 + 14.142 +void dma_disable(void *dma_chip) 14.143 +{ 14.144 + x1600_dma_disable(dma_chip); 14.145 +} 14.146 + 14.147 +void dma_enable(void *dma_chip) 14.148 +{ 14.149 + x1600_dma_enable(dma_chip); 14.150 +} 14.151 + 14.152 +void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq) 14.153 +{ 14.154 + return x1600_dma_get_channel(dma, channel, irq); 14.155 +} 14.156 + 14.157 +unsigned int dma_transfer(void *dma_channel, 14.158 + uint32_t source, uint32_t destination, 14.159 + unsigned int count, 14.160 + int source_increment, int destination_increment, 14.161 + uint8_t source_width, uint8_t destination_width, 14.162 + uint8_t transfer_unit_size, 14.163 + int type) 14.164 +{ 14.165 + return x1600_dma_transfer(dma_channel, source, destination, count, 14.166 + source_increment, destination_increment, 14.167 + source_width, destination_width, 14.168 + transfer_unit_size, type); 14.169 +} 14.170 + 14.171 +unsigned int dma_wait(void *dma_channel) 14.172 +{ 14.173 + return x1600_dma_wait(dma_channel); 14.174 +} 14.175 + 14.176 + 14.177 + 14.178 +/* GPIO adapter functions. */ 14.179 + 14.180 +void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, 14.181 + l4_uint32_t pull_ups, l4_uint32_t pull_downs) 14.182 +{ 14.183 + return x1600_gpio_init(start, end, pins, pull_ups, pull_downs); 14.184 +} 14.185 + 14.186 +void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) 14.187 +{ 14.188 + x1600_gpio_setup(gpio, pin, mode, value); 14.189 +} 14.190 + 14.191 +void gpio_config_pull(void *gpio, unsigned pin, unsigned mode) 14.192 +{ 14.193 + x1600_gpio_config_pull(gpio, pin, mode); 14.194 +} 14.195 + 14.196 +void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value) 14.197 +{ 14.198 + x1600_gpio_config_pad(gpio, pin, func, value); 14.199 +} 14.200 + 14.201 +void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value) 14.202 +{ 14.203 + x1600_gpio_config_get(gpio, pin, reg, value); 14.204 +} 14.205 + 14.206 +void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value) 14.207 +{ 14.208 + x1600_gpio_config_pad_get(gpio, pin, func, value); 14.209 +} 14.210 + 14.211 +void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues) 14.212 +{ 14.213 + x1600_gpio_multi_setup(gpio, mask, mode, outvalues); 14.214 +} 14.215 + 14.216 +void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value) 14.217 +{ 14.218 + x1600_gpio_multi_config_pad(gpio, mask, func, value); 14.219 +} 14.220 + 14.221 +void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data) 14.222 +{ 14.223 + x1600_gpio_multi_set(gpio, mask, data); 14.224 +} 14.225 + 14.226 +unsigned gpio_multi_get(void *gpio, unsigned offset) 14.227 +{ 14.228 + return x1600_gpio_multi_get(gpio, offset); 14.229 +} 14.230 + 14.231 +int gpio_get(void *gpio, unsigned pin) 14.232 +{ 14.233 + return x1600_gpio_get(gpio, pin); 14.234 +} 14.235 + 14.236 +void gpio_set(void *gpio, unsigned pin, int value) 14.237 +{ 14.238 + x1600_gpio_set(gpio, pin, value); 14.239 +} 14.240 + 14.241 +void *gpio_get_irq(void *gpio, unsigned pin) 14.242 +{ 14.243 + return x1600_gpio_get_irq(gpio, pin); 14.244 +} 14.245 + 14.246 +bool gpio_irq_set_mode(void *gpio_irq, unsigned mode) 14.247 +{ 14.248 + return x1600_gpio_irq_set_mode(gpio_irq, mode); 14.249 +} 14.250 + 14.251 + 14.252 + 14.253 +/* I2C adapter functions. */ 14.254 + 14.255 +void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 14.256 + uint32_t frequency) 14.257 +{ 14.258 + return x1600_i2c_init(start, end, cpm, frequency); 14.259 +} 14.260 + 14.261 +void *i2c_get_channel(void *i2c, uint8_t channel) 14.262 +{ 14.263 + return x1600_i2c_get_channel(i2c, channel); 14.264 +} 14.265 + 14.266 +uint32_t i2c_get_frequency(void *i2c_channel) 14.267 +{ 14.268 + return x1600_i2c_get_frequency(i2c_channel); 14.269 +} 14.270 + 14.271 +void i2c_set_target(void *i2c_channel, uint8_t addr) 14.272 +{ 14.273 + return x1600_i2c_set_target(i2c_channel, addr); 14.274 +} 14.275 + 14.276 +void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 14.277 + int stop) 14.278 +{ 14.279 + x1600_i2c_start_read(i2c_channel, buf, total, stop); 14.280 +} 14.281 + 14.282 +void i2c_read(void *i2c_channel) 14.283 +{ 14.284 + x1600_i2c_read(i2c_channel); 14.285 +} 14.286 + 14.287 +void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 14.288 + int stop) 14.289 +{ 14.290 + x1600_i2c_start_write(i2c_channel, buf, total, stop); 14.291 +} 14.292 + 14.293 +void i2c_write(void *i2c_channel) 14.294 +{ 14.295 + x1600_i2c_write(i2c_channel); 14.296 +} 14.297 + 14.298 +int i2c_read_done(void *i2c_channel) 14.299 +{ 14.300 + return x1600_i2c_read_done(i2c_channel); 14.301 +} 14.302 + 14.303 +int i2c_write_done(void *i2c_channel) 14.304 +{ 14.305 + return x1600_i2c_write_done(i2c_channel); 14.306 +} 14.307 + 14.308 +unsigned int i2c_have_read(void *i2c_channel) 14.309 +{ 14.310 + return x1600_i2c_have_read(i2c_channel); 14.311 +} 14.312 + 14.313 +unsigned int i2c_have_written(void *i2c_channel) 14.314 +{ 14.315 + return x1600_i2c_have_written(i2c_channel); 14.316 +} 14.317 + 14.318 +int i2c_failed(void *i2c_channel) 14.319 +{ 14.320 + return x1600_i2c_failed(i2c_channel); 14.321 +} 14.322 + 14.323 +void i2c_stop(void *i2c_channel) 14.324 +{ 14.325 + x1600_i2c_stop(i2c_channel); 14.326 +} 14.327 + 14.328 + 14.329 + 14.330 +/* SPI adapter functions. */ 14.331 + 14.332 +void *spi_get_channel(void *clock_chip, int clock_pin, 14.333 + void *data_chip, int data_pin, 14.334 + void *enable_chip, int enable_pin, 14.335 + uint32_t frequency) 14.336 +{ 14.337 + return spi_gpio_get_channel(clock_chip, clock_pin, data_chip, data_pin, enable_chip, enable_pin, frequency); 14.338 +} 14.339 + 14.340 +void spi_send(void *channel, int bytes, const uint8_t data[]) 14.341 +{ 14.342 + spi_gpio_send(channel, bytes, data); 14.343 +} 14.344 + 14.345 + 14.346 + 14.347 +/* Memory regions. */ 14.348 + 14.349 +const char *memory_regions[] = { 14.350 + [AIC] = "x1600-aic", 14.351 + [CPM] = "x1600-cpm", 14.352 + [DMA] = "x1600-dma", 14.353 + [GPIO] = "x1600-gpio", 14.354 + [I2C] = "x1600-i2c", 14.355 +}; 14.356 + 14.357 + 14.358 + 14.359 +/* AIC definitions. */ 14.360 + 14.361 +void *aic_channels[] = {NULL}; 14.362 + 14.363 +const unsigned int num_aic_channels = 1; 14.364 + 14.365 +l4_cap_idx_t aic_irqs[] = {L4_INVALID_CAP}; 14.366 + 14.367 + 14.368 + 14.369 +/* CPM definitions. */ 14.370 + 14.371 +struct clock_info clocks[] = { 14.372 + {"ext", Clock_external, "External"}, 14.373 + {"plla", Clock_pll_A, "PLL A"}, 14.374 + {"plle", Clock_pll_E, "PLL E"}, 14.375 + {"pllm", Clock_pll_M, "PLL M"}, 14.376 + {"main", Clock_main, "Main"}, 14.377 + {"cpu", Clock_cpu, "CPU"}, 14.378 + {"ahb0", Clock_hclock0, "AHB0"}, 14.379 + {"ahb2", Clock_hclock2, "AHB2"}, 14.380 + {"apb", Clock_pclock, "APB"}, 14.381 + {"aic", Clock_aic, "AIC"}, 14.382 + {"dma", Clock_dma, "DMA"}, 14.383 + {"lcd", Clock_lcd_pixel0, "LCD pixel"}, 14.384 + {"msc0", Clock_msc0, "MSC0"}, 14.385 + {"msc1", Clock_msc1, "MSC1"}, 14.386 + {"otg", Clock_otg0, "USB OTG"}, 14.387 + {"i2c0", Clock_i2c0, "I2C0"}, 14.388 + {"i2c1", Clock_i2c1, "I2C1"}, 14.389 + {"i2s0", Clock_i2s0, "I2S0"}, 14.390 + {"i2s1", Clock_i2s1, "I2S1"}, 14.391 + {"i2s0r", Clock_i2s0_rx, "I2S0 RX"}, 14.392 + {"i2s0t", Clock_i2s0_tx, "I2S0 TX"}, 14.393 + {"ssi", Clock_ssi0, "SSI"}, 14.394 + {"uart0", Clock_uart0, "UART0"}, 14.395 + {"uart1", Clock_uart1, "UART1"}, 14.396 + {"uart2", Clock_uart2, "UART2"}, 14.397 + {"uart3", Clock_uart3, "UART3"}, 14.398 + {NULL, Clock_undefined, NULL}, 14.399 +}; 14.400 + 14.401 + 14.402 + 14.403 +/* DMA definitions. */ 14.404 + 14.405 +void *dma_channels[32] = {NULL}; 14.406 + 14.407 +const unsigned int num_dma_channels = 32; 14.408 + 14.409 +struct dma_region dma_regions[2]; 14.410 + 14.411 +const unsigned int num_dma_regions = 2; 14.412 + 14.413 +l4_cap_idx_t dma_irq = L4_INVALID_CAP; 14.414 + 14.415 + 14.416 + 14.417 +/* GPIO definitions. */ 14.418 + 14.419 +struct gpio_port gpio_ports[] = { 14.420 + {0xffffffff, 0x00000000}, 14.421 + {0xdffbf7bf, 0x00000000}, 14.422 + {0x987e0000, 0x07000007}, 14.423 + {0x0000003f, 0x00000000} 14.424 +}; 14.425 + 14.426 +const unsigned int num_gpio_ports = 4; 14.427 + 14.428 +const char gpio_port_labels[] = "ABCD"; 14.429 + 14.430 + 14.431 + 14.432 +/* I2C definitions. */ 14.433 + 14.434 +void *i2c_channels[] = {NULL, NULL}; 14.435 + 14.436 +const unsigned int num_i2c_channels = 2; 14.437 + 14.438 +l4_cap_idx_t i2c_irqs[] = {L4_INVALID_CAP, L4_INVALID_CAP}; 14.439 + 14.440 + 14.441 + 14.442 +/* SPI definitions. */ 14.443 + 14.444 +void *spi_channels[] = {NULL}; 14.445 + 14.446 +const unsigned int num_spi_channels = 1;