paul@218 | 1 | /* |
paul@253 | 2 | * Common definitions and adapter function signatures for access to |
paul@253 | 3 | * board-specific functionality. |
paul@218 | 4 | * |
paul@253 | 5 | * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk> |
paul@218 | 6 | * |
paul@218 | 7 | * This program is free software; you can redistribute it and/or |
paul@218 | 8 | * modify it under the terms of the GNU General Public License as |
paul@218 | 9 | * published by the Free Software Foundation; either version 2 of |
paul@218 | 10 | * the License, or (at your option) any later version. |
paul@218 | 11 | * |
paul@218 | 12 | * This program is distributed in the hope that it will be useful, |
paul@218 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@218 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@218 | 15 | * GNU General Public License for more details. |
paul@218 | 16 | * |
paul@218 | 17 | * You should have received a copy of the GNU General Public License |
paul@218 | 18 | * along with this program; if not, write to the Free Software |
paul@218 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@218 | 20 | * Boston, MA 02110-1301, USA |
paul@218 | 21 | */ |
paul@218 | 22 | |
paul@218 | 23 | #pragma once |
paul@218 | 24 | |
paul@264 | 25 | #include <l4/devices/clocks.h> |
paul@264 | 26 | #include <l4/devices/dma.h> |
paul@264 | 27 | #include <l4/devices/gpio.h> |
paul@218 | 28 | #include <l4/sys/types.h> |
paul@218 | 29 | #include <stdint.h> |
paul@218 | 30 | |
paul@218 | 31 | |
paul@218 | 32 | |
paul@218 | 33 | /* AIC adapter functions. */ |
paul@218 | 34 | |
paul@218 | 35 | void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm); |
paul@218 | 36 | |
paul@218 | 37 | void *aic_get_channel(void *aic, int num, void *channel); |
paul@218 | 38 | |
paul@221 | 39 | unsigned int aic_transfer(void *channel, l4re_dma_space_dma_addr_t paddr, |
paul@221 | 40 | uint32_t count, uint32_t sample_rate, |
paul@218 | 41 | uint8_t sample_size); |
paul@218 | 42 | |
paul@218 | 43 | |
paul@218 | 44 | |
paul@218 | 45 | /* CPM adapter functions. */ |
paul@218 | 46 | |
paul@218 | 47 | void *cpm_init(l4_addr_t cpm_base); |
paul@218 | 48 | |
paul@218 | 49 | const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock); |
paul@218 | 50 | |
paul@218 | 51 | int cpm_have_clock(void *cpm, enum Clock_identifiers clock); |
paul@218 | 52 | |
paul@218 | 53 | void cpm_start_clock(void *cpm, enum Clock_identifiers clock); |
paul@218 | 54 | |
paul@218 | 55 | void cpm_stop_clock(void *cpm, enum Clock_identifiers clock); |
paul@218 | 56 | |
paul@218 | 57 | int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, |
paul@218 | 58 | uint32_t parameters[]); |
paul@218 | 59 | |
paul@218 | 60 | int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, |
paul@218 | 61 | int num_parameters, uint32_t parameters[]); |
paul@218 | 62 | |
paul@218 | 63 | uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock); |
paul@218 | 64 | |
paul@218 | 65 | void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source); |
paul@218 | 66 | |
paul@218 | 67 | enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock); |
paul@218 | 68 | |
paul@218 | 69 | void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, |
paul@218 | 70 | enum Clock_identifiers source); |
paul@218 | 71 | |
paul@218 | 72 | uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock); |
paul@218 | 73 | |
paul@218 | 74 | uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock); |
paul@218 | 75 | |
paul@218 | 76 | int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency); |
paul@218 | 77 | |
paul@218 | 78 | |
paul@218 | 79 | |
paul@218 | 80 | /* DMA adapter functions. */ |
paul@218 | 81 | |
paul@218 | 82 | void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm); |
paul@218 | 83 | |
paul@218 | 84 | void dma_disable(void *dma_chip); |
paul@218 | 85 | |
paul@218 | 86 | void dma_enable(void *dma_chip); |
paul@218 | 87 | |
paul@218 | 88 | void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq); |
paul@218 | 89 | |
paul@218 | 90 | unsigned int dma_transfer(void *dma_channel, |
paul@218 | 91 | uint32_t source, uint32_t destination, |
paul@218 | 92 | unsigned int count, |
paul@218 | 93 | int source_increment, int destination_increment, |
paul@218 | 94 | uint8_t source_width, uint8_t destination_width, |
paul@218 | 95 | uint8_t transfer_unit_size, |
paul@218 | 96 | int type); |
paul@218 | 97 | |
paul@218 | 98 | unsigned int dma_wait(void *dma_channel); |
paul@218 | 99 | |
paul@218 | 100 | |
paul@218 | 101 | |
paul@218 | 102 | /* GPIO adapter functions. */ |
paul@218 | 103 | |
paul@218 | 104 | void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, |
paul@218 | 105 | l4_uint32_t pull_ups, l4_uint32_t pull_downs); |
paul@218 | 106 | |
paul@218 | 107 | void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value); |
paul@218 | 108 | |
paul@218 | 109 | void gpio_config_pull(void *gpio, unsigned pin, unsigned mode); |
paul@218 | 110 | |
paul@218 | 111 | void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value); |
paul@218 | 112 | |
paul@218 | 113 | void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value); |
paul@218 | 114 | |
paul@218 | 115 | void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value); |
paul@218 | 116 | |
paul@218 | 117 | void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues); |
paul@218 | 118 | |
paul@218 | 119 | void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value); |
paul@218 | 120 | |
paul@218 | 121 | void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data); |
paul@218 | 122 | |
paul@218 | 123 | unsigned gpio_multi_get(void *gpio, unsigned offset); |
paul@218 | 124 | |
paul@218 | 125 | int gpio_get(void *gpio, unsigned pin); |
paul@218 | 126 | |
paul@218 | 127 | void gpio_set(void *gpio, unsigned pin, int value); |
paul@218 | 128 | |
paul@218 | 129 | void *gpio_get_irq(void *gpio, unsigned pin); |
paul@218 | 130 | |
paul@218 | 131 | bool gpio_irq_set_mode(void *gpio_irq, unsigned mode); |
paul@218 | 132 | |
paul@218 | 133 | |
paul@218 | 134 | |
paul@218 | 135 | /* I2C adapter functions. */ |
paul@218 | 136 | |
paul@218 | 137 | void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency); |
paul@218 | 138 | |
paul@218 | 139 | void *i2c_get_channel(void *i2c, uint8_t channel); |
paul@218 | 140 | |
paul@218 | 141 | uint32_t i2c_get_frequency(void *i2c_channel); |
paul@218 | 142 | |
paul@218 | 143 | void i2c_set_target(void *i2c_channel, uint8_t addr); |
paul@218 | 144 | |
paul@218 | 145 | void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, |
paul@218 | 146 | int stop); |
paul@218 | 147 | |
paul@218 | 148 | void i2c_read(void *i2c_channel); |
paul@218 | 149 | |
paul@218 | 150 | void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, |
paul@218 | 151 | int stop); |
paul@218 | 152 | |
paul@218 | 153 | void i2c_write(void *i2c_channel); |
paul@218 | 154 | |
paul@218 | 155 | int i2c_read_done(void *i2c_channel); |
paul@218 | 156 | |
paul@218 | 157 | int i2c_write_done(void *i2c_channel); |
paul@218 | 158 | |
paul@218 | 159 | unsigned int i2c_have_read(void *i2c_channel); |
paul@218 | 160 | |
paul@218 | 161 | unsigned int i2c_have_written(void *i2c_channel); |
paul@218 | 162 | |
paul@218 | 163 | int i2c_failed(void *i2c_channel); |
paul@218 | 164 | |
paul@218 | 165 | void i2c_stop(void *i2c_channel); |
paul@218 | 166 | |
paul@218 | 167 | |
paul@218 | 168 | |
paul@258 | 169 | /* MSC adapter functions. */ |
paul@258 | 170 | |
paul@264 | 171 | void *msc_init(l4_addr_t msc_start, l4_addr_t start, l4_addr_t end, void *cpm); |
paul@258 | 172 | |
paul@258 | 173 | void *msc_get_channel(void *msc, uint8_t channel, l4_cap_idx_t irq, void *dma); |
paul@258 | 174 | |
paul@263 | 175 | struct msc_card *msc_get_cards(void *msc_channel); |
paul@263 | 176 | |
paul@263 | 177 | uint8_t msc_num_cards(void *msc_channel); |
paul@258 | 178 | |
paul@258 | 179 | void msc_enable(void *msc_channel); |
paul@258 | 180 | |
paul@261 | 181 | uint32_t msc_read_blocks(void *msc_channel, uint8_t card, |
paul@264 | 182 | struct dma_region *region, |
paul@261 | 183 | uint32_t block_address, uint32_t block_count); |
paul@258 | 184 | |
paul@258 | 185 | |
paul@258 | 186 | |
paul@237 | 187 | /* RTC adapter functions. */ |
paul@237 | 188 | |
paul@240 | 189 | void *rtc_init(l4_addr_t start, void *cpm); |
paul@237 | 190 | |
paul@237 | 191 | void rtc_disable(void *rtc); |
paul@237 | 192 | |
paul@237 | 193 | void rtc_enable(void *rtc); |
paul@237 | 194 | |
paul@239 | 195 | void rtc_alarm_disable(void *rtc); |
paul@239 | 196 | |
paul@239 | 197 | void rtc_alarm_enable(void *rtc); |
paul@239 | 198 | |
paul@237 | 199 | uint32_t rtc_get_seconds(void *rtc); |
paul@237 | 200 | |
paul@237 | 201 | void rtc_set_seconds(void *rtc, uint32_t seconds); |
paul@237 | 202 | |
paul@237 | 203 | uint32_t rtc_get_alarm_seconds(void *rtc); |
paul@237 | 204 | |
paul@237 | 205 | void rtc_set_alarm_seconds(void *rtc, uint32_t seconds); |
paul@237 | 206 | |
paul@238 | 207 | void rtc_hibernate(void *rtc); |
paul@238 | 208 | |
paul@237 | 209 | void rtc_power_down(void *rtc); |
paul@237 | 210 | |
paul@237 | 211 | void rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment); |
paul@237 | 212 | |
paul@237 | 213 | |
paul@237 | 214 | |
paul@218 | 215 | /* SPI adapter functions. */ |
paul@218 | 216 | |
paul@221 | 217 | void *spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, void *cpm); |
paul@221 | 218 | |
paul@222 | 219 | void *spi_get_channel(void *spi, uint8_t num, void *channel, uint64_t frequency, |
paul@222 | 220 | void *control_chip, int control_pin, int control_alt_func); |
paul@218 | 221 | |
paul@222 | 222 | void *spi_get_channel_gpio(uint64_t frequency, |
paul@222 | 223 | void *clock_chip, int clock_pin, |
paul@221 | 224 | void *data_chip, int data_pin, |
paul@221 | 225 | void *enable_chip, int enable_pin, |
paul@222 | 226 | void *control_chip, int control_pin); |
paul@222 | 227 | |
paul@222 | 228 | void spi_acquire_control(void *channel, int level); |
paul@221 | 229 | |
paul@222 | 230 | void spi_release_control(void *channel); |
paul@221 | 231 | |
paul@235 | 232 | void spi_send(void *channel, uint32_t bytes, const uint8_t data[]); |
paul@222 | 233 | |
paul@222 | 234 | void spi_send_units(void *channel, uint32_t bytes, const uint8_t data[], |
paul@236 | 235 | uint8_t unit_size, uint8_t char_size, int big_endian); |
paul@221 | 236 | |
paul@236 | 237 | uint32_t spi_transfer(void *channel, l4_addr_t vaddr, |
paul@236 | 238 | l4re_dma_space_dma_addr_t paddr, uint32_t count, |
paul@236 | 239 | uint8_t unit_size, uint8_t char_size, |
paul@223 | 240 | l4_addr_t desc_vaddr, l4re_dma_space_dma_addr_t desc_paddr); |
paul@218 | 241 | |
paul@218 | 242 | |
paul@218 | 243 | |
paul@253 | 244 | /* TCU adapter functions. */ |
paul@253 | 245 | |
paul@253 | 246 | void *tcu_init(l4_addr_t start, l4_addr_t end); |
paul@253 | 247 | |
paul@253 | 248 | void *tcu_get_channel(void *tcu, uint8_t channel, l4_cap_idx_t irq); |
paul@253 | 249 | |
paul@253 | 250 | void tcu_disable(void *tcu_channel); |
paul@253 | 251 | |
paul@253 | 252 | void tcu_enable(void *tcu_channel); |
paul@253 | 253 | |
paul@253 | 254 | int tcu_is_enabled(void *tcu_channel); |
paul@253 | 255 | |
paul@253 | 256 | uint8_t tcu_get_clock(void *tcu_channel); |
paul@253 | 257 | |
paul@253 | 258 | void tcu_set_clock(void *tcu_channel, uint8_t clock); |
paul@253 | 259 | |
paul@253 | 260 | uint32_t tcu_get_prescale(void *tcu_channel); |
paul@253 | 261 | |
paul@253 | 262 | void tcu_set_prescale(void *tcu_channel, uint32_t prescale); |
paul@253 | 263 | |
paul@253 | 264 | uint32_t tcu_get_counter(void *tcu_channel); |
paul@253 | 265 | |
paul@253 | 266 | void tcu_set_counter(void *tcu_channel, uint32_t value); |
paul@253 | 267 | |
paul@253 | 268 | uint8_t tcu_get_count_mode(void *tcu_channel); |
paul@253 | 269 | |
paul@253 | 270 | void tcu_set_count_mode(void *tcu_channel, uint8_t mode); |
paul@253 | 271 | |
paul@253 | 272 | uint32_t tcu_get_full_data_value(void *tcu_channel); |
paul@253 | 273 | |
paul@253 | 274 | void tcu_set_full_data_value(void *tcu_channel, uint32_t value); |
paul@253 | 275 | |
paul@253 | 276 | uint32_t tcu_get_half_data_value(void *tcu_channel); |
paul@253 | 277 | |
paul@253 | 278 | void tcu_set_half_data_value(void *tcu_channel, uint32_t value); |
paul@253 | 279 | |
paul@253 | 280 | int tcu_get_full_data_mask(void *tcu_channel); |
paul@253 | 281 | |
paul@253 | 282 | void tcu_set_full_data_mask(void *tcu_channel, int masked); |
paul@253 | 283 | |
paul@253 | 284 | int tcu_get_half_data_mask(void *tcu_channel); |
paul@253 | 285 | |
paul@253 | 286 | void tcu_set_half_data_mask(void *tcu_channel, int masked); |
paul@253 | 287 | |
paul@253 | 288 | int tcu_have_interrupt(void *tcu_channel); |
paul@253 | 289 | |
paul@253 | 290 | int tcu_wait_for_irq(void *tcu_channel, uint32_t timeout); |
paul@253 | 291 | |
paul@253 | 292 | |
paul@253 | 293 | |
paul@218 | 294 | /* Memory regions. */ |
paul@218 | 295 | |
paul@218 | 296 | enum memory_regions |
paul@218 | 297 | { |
paul@258 | 298 | AIC, CPM, DMA, GPIO, I2C, MSC, RTC, SSI, TCU |
paul@218 | 299 | }; |
paul@218 | 300 | |
paul@218 | 301 | |
paul@218 | 302 | |
paul@218 | 303 | /* CPM definitions. */ |
paul@218 | 304 | |
paul@218 | 305 | struct clock_info |
paul@218 | 306 | { |
paul@218 | 307 | const char *id; |
paul@218 | 308 | enum Clock_identifiers clock; |
paul@218 | 309 | const char *name; |
paul@218 | 310 | }; |
paul@218 | 311 | |
paul@218 | 312 | |
paul@218 | 313 | |
paul@218 | 314 | /* GPIO definitions. */ |
paul@218 | 315 | |
paul@218 | 316 | struct gpio_port |
paul@218 | 317 | { |
paul@218 | 318 | const uint32_t pull_ups, pull_downs; |
paul@218 | 319 | }; |
paul@236 | 320 | |
paul@236 | 321 | |
paul@236 | 322 | |
paul@236 | 323 | /* Memory definitions. */ |
paul@236 | 324 | |
paul@236 | 325 | struct memory_region |
paul@236 | 326 | { |
paul@236 | 327 | unsigned int size; |
paul@236 | 328 | l4_addr_t addr; |
paul@236 | 329 | }; |