1 /* 2 * Access various peripherals on a board using the JZ4780. 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> /* NOTE: To be replaced. */ 23 #include <l4/devices/cpm-jz4780.h> 24 #include <l4/devices/dma-jz4780.h> 25 #include <l4/devices/gpio-jz4780.h> 26 #include <l4/devices/i2c-jz4780.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 long aic_get_buffer(void *channel, uint32_t count, l4_addr_t *addr) 45 { 46 return x1600_aic_get_buffer(channel, count, addr); 47 } 48 49 unsigned int aic_transfer(void *channel, uint32_t count, uint32_t sample_rate, uint8_t sample_size) 50 { 51 return x1600_aic_transfer(channel, count, sample_rate, sample_size); 52 } 53 54 55 56 /* CPM adapter functions. */ 57 58 void *cpm_init(l4_addr_t cpm_base) 59 { 60 return jz4780_cpm_init(cpm_base); 61 } 62 63 const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock) 64 { 65 return jz4780_cpm_clock_type(cpm, clock); 66 } 67 68 int cpm_have_clock(void *cpm, enum Clock_identifiers clock) 69 { 70 return jz4780_cpm_have_clock(cpm, clock); 71 } 72 73 void cpm_start_clock(void *cpm, enum Clock_identifiers clock) 74 { 75 jz4780_cpm_start_clock(cpm, clock); 76 } 77 78 void cpm_stop_clock(void *cpm, enum Clock_identifiers clock) 79 { 80 jz4780_cpm_stop_clock(cpm, clock); 81 } 82 83 int cpm_get_parameters(void *cpm, enum Clock_identifiers clock, 84 uint32_t parameters[]) 85 { 86 return jz4780_cpm_get_parameters(cpm, clock, parameters); 87 } 88 89 int cpm_set_parameters(void *cpm, enum Clock_identifiers clock, 90 int num_parameters, uint32_t parameters[]) 91 { 92 return jz4780_cpm_set_parameters(cpm, clock, num_parameters, parameters); 93 } 94 95 uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock) 96 { 97 return jz4780_cpm_get_source(cpm, clock); 98 } 99 100 void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source) 101 { 102 jz4780_cpm_set_source(cpm, clock, source); 103 } 104 105 enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock) 106 { 107 return jz4780_cpm_get_source_clock(cpm, clock); 108 } 109 110 void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock, enum Clock_identifiers source) 111 { 112 jz4780_cpm_set_source_clock(cpm, clock, source); 113 } 114 115 uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock) 116 { 117 return jz4780_cpm_get_source_frequency(cpm, clock); 118 } 119 120 uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock) 121 { 122 return jz4780_cpm_get_frequency(cpm, clock); 123 } 124 125 int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency) 126 { 127 return jz4780_cpm_set_frequency(cpm, clock, frequency); 128 } 129 130 131 132 /* DMA adapter functions. */ 133 134 void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm) 135 { 136 return jz4780_dma_init(start, end, cpm); 137 } 138 139 void dma_disable(void *dma_chip) 140 { 141 jz4780_dma_disable(dma_chip); 142 } 143 144 void dma_enable(void *dma_chip) 145 { 146 jz4780_dma_enable(dma_chip); 147 } 148 149 void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq) 150 { 151 return jz4780_dma_get_channel(dma, channel, irq); 152 } 153 154 unsigned int dma_transfer(void *dma_channel, 155 uint32_t source, uint32_t destination, 156 unsigned int count, 157 int source_increment, int destination_increment, 158 uint8_t source_width, uint8_t destination_width, 159 uint8_t transfer_unit_size, 160 int type) 161 { 162 return jz4780_dma_transfer(dma_channel, source, destination, count, 163 source_increment, destination_increment, 164 source_width, destination_width, 165 transfer_unit_size, type); 166 } 167 168 unsigned int dma_wait(void *dma_channel) 169 { 170 return jz4780_dma_wait(dma_channel); 171 } 172 173 174 175 /* GPIO adapter functions. */ 176 177 void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins, 178 l4_uint32_t pull_ups, l4_uint32_t pull_downs) 179 { 180 return jz4780_gpio_init(start, end, pins, pull_ups, pull_downs); 181 } 182 183 void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value) 184 { 185 jz4780_gpio_setup(gpio, pin, mode, value); 186 } 187 188 void gpio_config_pull(void *gpio, unsigned pin, unsigned mode) 189 { 190 jz4780_gpio_config_pull(gpio, pin, mode); 191 } 192 193 void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value) 194 { 195 jz4780_gpio_config_pad(gpio, pin, func, value); 196 } 197 198 void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value) 199 { 200 jz4780_gpio_config_get(gpio, pin, reg, value); 201 } 202 203 void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value) 204 { 205 jz4780_gpio_config_pad_get(gpio, pin, func, value); 206 } 207 208 void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues) 209 { 210 jz4780_gpio_multi_setup(gpio, mask, mode, outvalues); 211 } 212 213 void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value) 214 { 215 jz4780_gpio_multi_config_pad(gpio, mask, func, value); 216 } 217 218 void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data) 219 { 220 jz4780_gpio_multi_set(gpio, mask, data); 221 } 222 223 unsigned gpio_multi_get(void *gpio, unsigned offset) 224 { 225 return jz4780_gpio_multi_get(gpio, offset); 226 } 227 228 int gpio_get(void *gpio, unsigned pin) 229 { 230 return jz4780_gpio_get(gpio, pin); 231 } 232 233 void gpio_set(void *gpio, unsigned pin, int value) 234 { 235 jz4780_gpio_set(gpio, pin, value); 236 } 237 238 void *gpio_get_irq(void *gpio, unsigned pin) 239 { 240 return jz4780_gpio_get_irq(gpio, pin); 241 } 242 243 bool gpio_irq_set_mode(void *gpio_irq, unsigned mode) 244 { 245 return jz4780_gpio_irq_set_mode(gpio_irq, mode); 246 } 247 248 249 250 /* I2C adapter functions. */ 251 252 void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 253 uint32_t frequency) 254 { 255 return jz4780_i2c_init(start, end, cpm, frequency); 256 } 257 258 void *i2c_get_channel(void *i2c, uint8_t channel) 259 { 260 return jz4780_i2c_get_channel(i2c, channel); 261 } 262 263 uint32_t i2c_get_frequency(void *i2c_channel) 264 { 265 return jz4780_i2c_get_frequency(i2c_channel); 266 } 267 268 void i2c_set_target(void *i2c_channel, uint8_t addr) 269 { 270 return jz4780_i2c_set_target(i2c_channel, addr); 271 } 272 273 void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 274 int stop) 275 { 276 jz4780_i2c_start_read(i2c_channel, buf, total, stop); 277 } 278 279 void i2c_read(void *i2c_channel) 280 { 281 jz4780_i2c_read(i2c_channel); 282 } 283 284 void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 285 int stop) 286 { 287 jz4780_i2c_start_write(i2c_channel, buf, total, stop); 288 } 289 290 void i2c_write(void *i2c_channel) 291 { 292 jz4780_i2c_write(i2c_channel); 293 } 294 295 int i2c_read_done(void *i2c_channel) 296 { 297 return jz4780_i2c_read_done(i2c_channel); 298 } 299 300 int i2c_write_done(void *i2c_channel) 301 { 302 return jz4780_i2c_write_done(i2c_channel); 303 } 304 305 unsigned int i2c_have_read(void *i2c_channel) 306 { 307 return jz4780_i2c_have_read(i2c_channel); 308 } 309 310 unsigned int i2c_have_written(void *i2c_channel) 311 { 312 return jz4780_i2c_have_written(i2c_channel); 313 } 314 315 int i2c_failed(void *i2c_channel) 316 { 317 return jz4780_i2c_failed(i2c_channel); 318 } 319 320 void i2c_stop(void *i2c_channel) 321 { 322 jz4780_i2c_stop(i2c_channel); 323 } 324 325 326 327 /* SPI adapter functions. */ 328 329 void *spi_get_channel(void *clock_chip, int clock_pin, 330 void *data_chip, int data_pin, 331 void *enable_chip, int enable_pin, 332 uint32_t frequency) 333 { 334 return spi_gpio_get_channel(clock_chip, clock_pin, data_chip, data_pin, enable_chip, enable_pin, frequency); 335 } 336 337 void spi_send(void *channel, int bytes, const uint8_t data[]) 338 { 339 spi_gpio_send(channel, bytes, data); 340 } 341 342 343 344 /* Memory regions. */ 345 346 const char *memory_regions[] = { 347 [AIC] = "jz4780-aic", 348 [CPM] = "jz4780-cpm", 349 [DMA] = "jz4780-dma", 350 [GPIO] = "jz4780-gpio", 351 [I2C] = "jz4780-i2c", 352 }; 353 354 355 356 /* AIC definitions. */ 357 358 void *aic_channels[] = {NULL, NULL}; 359 360 const unsigned int num_aic_channels = 2; 361 362 l4_cap_idx_t aic_irqs[] = {L4_INVALID_CAP}; 363 364 365 366 /* CPM definitions. */ 367 368 struct clock_info clocks[] = { 369 {"ext", Clock_external, "External"}, 370 {"plla", Clock_pll_A, "PLL A"}, 371 {"plle", Clock_pll_E, "PLL E"}, 372 {"pllm", Clock_pll_M, "PLL M"}, 373 {"pllv", Clock_pll_V, "PLL V"}, 374 {"main", Clock_main, "Main"}, 375 {"cpu", Clock_cpu, "CPU"}, 376 {"h2p", Clock_hclock2_pclock, "AHB2/APB"}, 377 {"ahb0", Clock_hclock0, "AHB0"}, 378 {"ahb2", Clock_hclock2, "AHB2"}, 379 {"apb", Clock_pclock, "APB"}, 380 {"dma", Clock_dma, "DMA"}, 381 {"hdmi", Clock_lcd, "HDMI"}, 382 {"lcd", Clock_lcd, "LCD"}, 383 {"lcd0", Clock_lcd_pixel0, "LCD0 pixel"}, 384 {"lcd1", Clock_lcd_pixel1, "LCD1 pixel"}, 385 {"msc", Clock_msc, "MSC"}, 386 {"msc0", Clock_msc0, "MSC0"}, 387 {"msc1", Clock_msc1, "MSC1"}, 388 {"msc2", Clock_msc1, "MSC2"}, 389 {"otg0", Clock_otg0, "USB OTG0"}, 390 {"otg1", Clock_otg1, "USB OTG1"}, 391 {"i2c0", Clock_i2c0, "I2C0"}, 392 {"i2c1", Clock_i2c1, "I2C1"}, 393 {"i2c2", Clock_i2c2, "I2C2"}, 394 {"i2c3", Clock_i2c3, "I2C3"}, 395 {"i2c4", Clock_i2c4, "I2C4"}, 396 {"i2s0", Clock_i2s0, "I2S0"}, 397 {"i2s1", Clock_i2s1, "I2S1"}, 398 {"pcm", Clock_pcm, "PCM"}, 399 {"ssi", Clock_ssi, "SSI"}, 400 {"ssi0", Clock_ssi0, "SSI0"}, 401 {"ssi1", Clock_ssi1, "SSI1"}, 402 {"ssi2", Clock_ssi2, "SSI2"}, 403 {"uart0", Clock_uart0, "UART0"}, 404 {"uart1", Clock_uart1, "UART1"}, 405 {"uart2", Clock_uart2, "UART2"}, 406 {"uart3", Clock_uart3, "UART3"}, 407 {"uart4", Clock_uart4, "UART4"}, 408 {NULL, Clock_undefined, NULL}, 409 }; 410 411 412 413 /* DMA definitions. */ 414 415 void *dma_channels[32] = {NULL}; 416 417 const unsigned int num_dma_channels = 32; 418 419 struct dma_region dma_regions[2]; 420 421 const unsigned int num_dma_regions = 2; 422 423 l4_cap_idx_t dma_irq = L4_INVALID_CAP; 424 425 426 427 /* GPIO definitions. */ 428 429 struct gpio_port gpio_ports[] = { 430 {0x3fff00ff, 0x00000000}, 431 {0xfff0f3fc, 0x000f0c03}, 432 {0x0fffffff, 0x00000000}, 433 {0xffff4fff, 0x0000b000}, 434 {0xf0fff37c, 0x00000483}, 435 {0x7fa7f00f, 0x00580ff0}, 436 }; 437 438 const unsigned int num_gpio_ports = 6; 439 440 const char gpio_port_labels[] = "ABCDEF"; 441 442 443 444 /* I2C definitions. */ 445 446 void *i2c_channels[] = {NULL, NULL, NULL, NULL, NULL}; 447 448 const unsigned int num_i2c_channels = 5; 449 450 l4_cap_idx_t i2c_irqs[] = {L4_INVALID_CAP, L4_INVALID_CAP}; 451 452 453 454 /* SPI definitions. */ 455 456 void *spi_channels[] = {NULL, NULL}; 457 458 const unsigned int num_spi_channels = 2;