1 /* 2 * Access various peripherals on a board using the X1600. 3 * 4 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/devices/aic-x1600.h> 23 #include <l4/devices/cpm-x1600.h> 24 #include <l4/devices/dma-x1600.h> 25 #include <l4/devices/gpio-x1600.h> 26 #include <l4/devices/i2c-x1600.h> 27 #include <l4/devices/spi-gpio.h> 28 #include "common.h" 29 30 31 32 /* AIC adapter functions. */ 33 34 void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm) 35 { 36 return x1600_aic_init(aic_start, start, end, cpm); 37 } 38 39 void *aic_get_channel(void *aic, int num, void *channel) 40 { 41 return x1600_aic_get_channel(aic, num, channel); 42 } 43 44 unsigned int aic_transfer(void *channel, l4re_dma_space_dma_addr_t paddr, 45 uint32_t count, uint32_t sample_rate, 46 uint8_t sample_size) 47 { 48 return x1600_aic_transfer(channel, paddr, count, sample_rate, sample_size); 49 } 50 51 52 53 /* CPM adapter functions. */ 54 55 void *cpm_init(l4_addr_t cpm_base) 56 { 57 return x1600_cpm_init(cpm_base); 58 } 59 60 const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock) 61 { 62 return x1600_cpm_clock_type(cpm, clock); 63 } 64 65 int cpm_have_clock(void *cpm, enum Clock_identifiers clock) 66 { 67 return x1600_cpm_have_clock(cpm, clock); 68 } 69 70 void cpm_start_clock(void *cpm, enum Clock_identifiers clock) 71 { 72 x1600_cpm_start_clock(cpm, clock); 73 } 74 75 void cpm_stop_clock(void *cpm, enum Clock_identifiers clock) 76 { 77 x1600_cpm_stop_clock(cpm, clock); 78 } 79 80 int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 81 uint32_t parameters[]) 82 { 83 return x1600_cpm_get_parameters(cpm, clock, parameters); 84 } 85 86 int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 87 int num_parameters, uint32_t parameters[]) 88 { 89 return x1600_cpm_set_parameters(cpm, clock, num_parameters, parameters); 90 } 91 92 uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock) 93 { 94 return x1600_cpm_get_source(cpm, clock); 95 } 96 97 void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source) 98 { 99 x1600_cpm_set_source(cpm, clock, source); 100 } 101 102 enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock) 103 { 104 return x1600_cpm_get_source_clock(cpm, clock); 105 } 106 107 void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source) 108 { 109 x1600_cpm_set_source_clock(cpm, clock, source); 110 } 111 112 uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock) 113 { 114 return x1600_cpm_get_source_frequency(cpm, clock); 115 } 116 117 uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock) 118 { 119 return x1600_cpm_get_frequency(cpm, clock); 120 } 121 122 int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency) 123 { 124 return x1600_cpm_set_frequency(cpm, clock, frequency); 125 } 126 127 128 129 /* DMA adapter functions. */ 130 131 void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm) 132 { 133 return x1600_dma_init(start, end, cpm); 134 } 135 136 void dma_disable(void *dma_chip) 137 { 138 x1600_dma_disable(dma_chip); 139 } 140 141 void dma_enable(void *dma_chip) 142 { 143 x1600_dma_enable(dma_chip); 144 } 145 146 void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq) 147 { 148 return x1600_dma_get_channel(dma, channel, irq); 149 } 150 151 unsigned int dma_transfer(void *dma_channel, 152 uint32_t source, uint32_t destination, 153 unsigned int count, 154 int source_increment, int destination_increment, 155 uint8_t source_width, uint8_t destination_width, 156 uint8_t transfer_unit_size, 157 int type) 158 { 159 return x1600_dma_transfer(dma_channel, source, destination, count, 160 source_increment, destination_increment, 161 source_width, destination_width, 162 transfer_unit_size, type); 163 } 164 165 unsigned int dma_wait(void *dma_channel) 166 { 167 return x1600_dma_wait(dma_channel); 168 } 169 170 171 172 /* GPIO adapter functions. */ 173 174 void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, 175 l4_uint32_t pull_ups, l4_uint32_t pull_downs) 176 { 177 return x1600_gpio_init(start, end, pins, pull_ups, pull_downs); 178 } 179 180 void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) 181 { 182 x1600_gpio_setup(gpio, pin, mode, value); 183 } 184 185 void gpio_config_pull(void *gpio, unsigned pin, unsigned mode) 186 { 187 x1600_gpio_config_pull(gpio, pin, mode); 188 } 189 190 void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value) 191 { 192 x1600_gpio_config_pad(gpio, pin, func, value); 193 } 194 195 void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value) 196 { 197 x1600_gpio_config_get(gpio, pin, reg, value); 198 } 199 200 void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value) 201 { 202 x1600_gpio_config_pad_get(gpio, pin, func, value); 203 } 204 205 void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues) 206 { 207 x1600_gpio_multi_setup(gpio, mask, mode, outvalues); 208 } 209 210 void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value) 211 { 212 x1600_gpio_multi_config_pad(gpio, mask, func, value); 213 } 214 215 void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data) 216 { 217 x1600_gpio_multi_set(gpio, mask, data); 218 } 219 220 unsigned gpio_multi_get(void *gpio, unsigned offset) 221 { 222 return x1600_gpio_multi_get(gpio, offset); 223 } 224 225 int gpio_get(void *gpio, unsigned pin) 226 { 227 return x1600_gpio_get(gpio, pin); 228 } 229 230 void gpio_set(void *gpio, unsigned pin, int value) 231 { 232 x1600_gpio_set(gpio, pin, value); 233 } 234 235 void *gpio_get_irq(void *gpio, unsigned pin) 236 { 237 return x1600_gpio_get_irq(gpio, pin); 238 } 239 240 bool gpio_irq_set_mode(void *gpio_irq, unsigned mode) 241 { 242 return x1600_gpio_irq_set_mode(gpio_irq, mode); 243 } 244 245 246 247 /* I2C adapter functions. */ 248 249 void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 250 uint32_t frequency) 251 { 252 return x1600_i2c_init(start, end, cpm, frequency); 253 } 254 255 void *i2c_get_channel(void *i2c, uint8_t channel) 256 { 257 return x1600_i2c_get_channel(i2c, channel); 258 } 259 260 uint32_t i2c_get_frequency(void *i2c_channel) 261 { 262 return x1600_i2c_get_frequency(i2c_channel); 263 } 264 265 void i2c_set_target(void *i2c_channel, uint8_t addr) 266 { 267 return x1600_i2c_set_target(i2c_channel, addr); 268 } 269 270 void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 271 int stop) 272 { 273 x1600_i2c_start_read(i2c_channel, buf, total, stop); 274 } 275 276 void i2c_read(void *i2c_channel) 277 { 278 x1600_i2c_read(i2c_channel); 279 } 280 281 void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 282 int stop) 283 { 284 x1600_i2c_start_write(i2c_channel, buf, total, stop); 285 } 286 287 void i2c_write(void *i2c_channel) 288 { 289 x1600_i2c_write(i2c_channel); 290 } 291 292 int i2c_read_done(void *i2c_channel) 293 { 294 return x1600_i2c_read_done(i2c_channel); 295 } 296 297 int i2c_write_done(void *i2c_channel) 298 { 299 return x1600_i2c_write_done(i2c_channel); 300 } 301 302 unsigned int i2c_have_read(void *i2c_channel) 303 { 304 return x1600_i2c_have_read(i2c_channel); 305 } 306 307 unsigned int i2c_have_written(void *i2c_channel) 308 { 309 return x1600_i2c_have_written(i2c_channel); 310 } 311 312 int i2c_failed(void *i2c_channel) 313 { 314 return x1600_i2c_failed(i2c_channel); 315 } 316 317 void i2c_stop(void *i2c_channel) 318 { 319 x1600_i2c_stop(i2c_channel); 320 } 321 322 323 324 /* SPI adapter functions. */ 325 326 void *spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, void *cpm) 327 { 328 (void) spi_start; (void) start; (void) end; (void) cpm; 329 return NULL; 330 } 331 332 void *spi_get_channel(void *spi, uint8_t num, void *channel, uint64_t frequency) 333 { 334 (void) spi; (void) num; (void) channel; (void) frequency; 335 return NULL; 336 } 337 338 void *spi_get_channel_gpio(void *clock_chip, int clock_pin, 339 void *data_chip, int data_pin, 340 void *enable_chip, int enable_pin, 341 uint64_t frequency) 342 { 343 return spi_gpio_get_channel(clock_chip, clock_pin, data_chip, data_pin, enable_chip, enable_pin, frequency); 344 } 345 346 void spi_send(void *channel, int bytes, const uint8_t data[], uint8_t unit_size, 347 uint8_t char_size) 348 { 349 /* NOTE: Not yet supported. */ 350 351 (void) channel; (void) bytes; (void) data; (void) unit_size; (void) char_size; 352 // x1600_spi_send(channel, bytes, data, unit_size, char_size); 353 } 354 355 void spi_send_gpio(void *channel, int bytes, const uint8_t data[]) 356 { 357 spi_gpio_send(channel, bytes, data); 358 } 359 360 uint32_t spi_transfer(void *channel, l4re_dma_space_dma_addr_t paddr, 361 uint32_t count, uint8_t unit_size, uint8_t char_size) 362 { 363 /* NOTE: Not yet supported. */ 364 365 (void) channel; (void) paddr; (void) count; (void) unit_size; (void) char_size; 366 // return x1600_spi_transfer(channel, paddr, count, unit_size, char_size); 367 return 0; 368 } 369 370 371 372 /* Memory regions. */ 373 374 const char *memory_regions[] = { 375 [AIC] = "x1600-aic", 376 [CPM] = "x1600-cpm", 377 [DMA] = "x1600-dma", 378 [GPIO] = "x1600-gpio", 379 [I2C] = "x1600-i2c", 380 [SSI] = "x1600-ssi", 381 }; 382 383 384 385 /* AIC definitions. */ 386 387 void *aic_channels[] = {NULL}; 388 389 const unsigned int num_aic_channels = 1; 390 391 l4_cap_idx_t aic_irqs[] = {L4_INVALID_CAP}; 392 393 394 395 /* CPM definitions. */ 396 397 struct clock_info clocks[] = { 398 {"ext", Clock_external, "External"}, 399 {"plla", Clock_pll_A, "PLL A"}, 400 {"plle", Clock_pll_E, "PLL E"}, 401 {"pllm", Clock_pll_M, "PLL M"}, 402 {"main", Clock_main, "Main"}, 403 {"cpu", Clock_cpu, "CPU"}, 404 {"ahb0", Clock_hclock0, "AHB0"}, 405 {"ahb2", Clock_hclock2, "AHB2"}, 406 {"apb", Clock_pclock, "APB"}, 407 {"aic", Clock_aic, "AIC"}, 408 {"dma", Clock_dma, "DMA"}, 409 {"lcd0", Clock_lcd_pixel0, "LCD pixel"}, 410 {"msc0", Clock_msc0, "MSC0"}, 411 {"msc1", Clock_msc1, "MSC1"}, 412 {"otg", Clock_otg0, "USB OTG"}, 413 {"i2c0", Clock_i2c0, "I2C0"}, 414 {"i2c1", Clock_i2c1, "I2C1"}, 415 {"i2s0", Clock_i2s0, "I2S0"}, 416 {"i2s1", Clock_i2s1, "I2S1"}, 417 {"i2s0r", Clock_i2s0_rx, "I2S0 RX"}, 418 {"i2s0t", Clock_i2s0_tx, "I2S0 TX"}, 419 {"ssi0", Clock_ssi0, "SSI"}, 420 {"uart0", Clock_uart0, "UART0"}, 421 {"uart1", Clock_uart1, "UART1"}, 422 {"uart2", Clock_uart2, "UART2"}, 423 {"uart3", Clock_uart3, "UART3"}, 424 {NULL, Clock_undefined, NULL}, 425 }; 426 427 428 429 /* DMA definitions. */ 430 431 void *dma_channels[32] = {NULL}; 432 433 const unsigned int num_dma_channels = 32; 434 435 struct dma_region dma_regions[8]; 436 437 const unsigned int num_dma_regions = 8; 438 439 l4_cap_idx_t dma_irq = L4_INVALID_CAP; 440 441 442 443 /* GPIO definitions. */ 444 445 struct gpio_port gpio_ports[] = { 446 {0xffffffff, 0x00000000}, 447 {0xdffbf7bf, 0x00000000}, 448 {0x987e0000, 0x07000007}, 449 {0x0000003f, 0x00000000} 450 }; 451 452 const unsigned int num_gpio_ports = 4; 453 454 const char gpio_port_labels[] = "ABCD"; 455 456 457 458 /* I2C definitions. */ 459 460 void *i2c_channels[] = {NULL, NULL}; 461 462 const unsigned int num_i2c_channels = 2; 463 464 l4_cap_idx_t i2c_irqs[] = {L4_INVALID_CAP, L4_INVALID_CAP}; 465 466 467 468 /* SPI definitions. */ 469 470 void *spi_channels[] = {NULL}; 471 472 const unsigned int num_spi_channels = 1;