1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DBAu1000/1500/1100 PBAu1100/1500 board support
5 * Copyright 2000, 2008 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc. <source@mvista.com>
10 #include <linux/dma-mapping.h>
11 #include <linux/gpio.h>
12 #include <linux/gpio/machine.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/leds.h>
16 #include <linux/mmc/host.h>
17 #include <linux/platform_device.h>
19 #include <linux/spi/spi.h>
20 #include <linux/spi/spi_gpio.h>
21 #include <linux/spi/ads7846.h>
22 #include <asm/mach-au1x00/au1000.h>
23 #include <asm/mach-au1x00/gpio-au1000.h>
24 #include <asm/mach-au1x00/au1000_dma.h>
25 #include <asm/mach-au1x00/au1100_mmc.h>
26 #include <asm/mach-db1x00/bcsr.h>
27 #include <asm/reboot.h>
31 #define F_SWAPPED (bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT)
33 const char *get_system_type(void);
35 int __init db1000_board_setup(void)
37 /* initialize board register space */
38 bcsr_init(DB1000_BCSR_PHYS_ADDR,
39 DB1000_BCSR_PHYS_ADDR + DB1000_BCSR_HEXLED_OFS);
41 switch (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI))) {
42 case BCSR_WHOAMI_DB1000:
43 case BCSR_WHOAMI_DB1500:
44 case BCSR_WHOAMI_DB1100:
45 case BCSR_WHOAMI_PB1500:
46 case BCSR_WHOAMI_PB1500R2:
47 case BCSR_WHOAMI_PB1100:
48 pr_info("AMD Alchemy %s Board\n", get_system_type());
54 static int db1500_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
56 if ((slot < 12) || (slot > 13) || pin == 0)
59 return (pin == 1) ? AU1500_PCI_INTA : 0xff;
62 case 1: return AU1500_PCI_INTA;
63 case 2: return AU1500_PCI_INTB;
64 case 3: return AU1500_PCI_INTC;
65 case 4: return AU1500_PCI_INTD;
71 static u64 au1xxx_all_dmamask = DMA_BIT_MASK(32);
73 static struct resource alchemy_pci_host_res[] = {
75 .start = AU1500_PCI_PHYS_ADDR,
76 .end = AU1500_PCI_PHYS_ADDR + 0xfff,
77 .flags = IORESOURCE_MEM,
81 static struct alchemy_pci_platdata db1500_pci_pd = {
82 .board_map_irq = db1500_map_pci_irq,
85 static struct platform_device db1500_pci_host_dev = {
86 .dev.platform_data = &db1500_pci_pd,
87 .name = "alchemy-pci",
89 .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
90 .resource = alchemy_pci_host_res,
93 int __init db1500_pci_setup(void)
95 return platform_device_register(&db1500_pci_host_dev);
98 static struct resource au1100_lcd_resources[] = {
100 .start = AU1100_LCD_PHYS_ADDR,
101 .end = AU1100_LCD_PHYS_ADDR + 0x800 - 1,
102 .flags = IORESOURCE_MEM,
105 .start = AU1100_LCD_INT,
106 .end = AU1100_LCD_INT,
107 .flags = IORESOURCE_IRQ,
111 static struct platform_device au1100_lcd_device = {
112 .name = "au1100-lcd",
115 .dma_mask = &au1xxx_all_dmamask,
116 .coherent_dma_mask = DMA_BIT_MASK(32),
118 .num_resources = ARRAY_SIZE(au1100_lcd_resources),
119 .resource = au1100_lcd_resources,
122 static struct resource alchemy_ac97c_res[] = {
124 .start = AU1000_AC97_PHYS_ADDR,
125 .end = AU1000_AC97_PHYS_ADDR + 0xfff,
126 .flags = IORESOURCE_MEM,
129 .start = DMA_ID_AC97C_TX,
130 .end = DMA_ID_AC97C_TX,
131 .flags = IORESOURCE_DMA,
134 .start = DMA_ID_AC97C_RX,
135 .end = DMA_ID_AC97C_RX,
136 .flags = IORESOURCE_DMA,
140 static struct platform_device alchemy_ac97c_dev = {
141 .name = "alchemy-ac97c",
143 .resource = alchemy_ac97c_res,
144 .num_resources = ARRAY_SIZE(alchemy_ac97c_res),
147 static struct platform_device alchemy_ac97c_dma_dev = {
148 .name = "alchemy-pcm-dma",
152 static struct platform_device db1x00_codec_dev = {
153 .name = "ac97-codec",
157 static struct platform_device db1x00_audio_dev = {
158 .name = "db1000-audio",
160 .dma_mask = &au1xxx_all_dmamask,
161 .coherent_dma_mask = DMA_BIT_MASK(32),
165 /******************************************************************************/
167 static irqreturn_t db1100_mmc_cd(int irq, void *ptr)
169 mmc_detect_change(ptr, msecs_to_jiffies(500));
173 static int db1100_mmc_cd_setup(void *mmc_host, int en)
177 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100)
178 irq = AU1100_GPIO19_INT;
180 irq = AU1100_GPIO14_INT; /* PB1100 SD0 CD# */
183 irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
184 ret = request_irq(irq, db1100_mmc_cd, 0,
187 free_irq(irq, mmc_host);
191 static int db1100_mmc1_cd_setup(void *mmc_host, int en)
195 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100)
196 irq = AU1100_GPIO20_INT;
198 irq = AU1100_GPIO15_INT; /* PB1100 SD1 CD# */
201 irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
202 ret = request_irq(irq, db1100_mmc_cd, 0,
205 free_irq(irq, mmc_host);
209 static int db1100_mmc_card_readonly(void *mmc_host)
211 /* testing suggests that this bit is inverted */
212 return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 0 : 1;
215 static int db1100_mmc_card_inserted(void *mmc_host)
217 return !alchemy_gpio_get_value(19);
220 static void db1100_mmc_set_power(void *mmc_host, int state)
224 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100)
225 bit = BCSR_BOARD_SD0PWR;
227 bit = BCSR_BOARD_PB1100_SD0PWR;
230 bcsr_mod(BCSR_BOARD, 0, bit);
231 msleep(400); /* stabilization time */
233 bcsr_mod(BCSR_BOARD, bit, 0);
236 static void db1100_mmcled_set(struct led_classdev *led, enum led_brightness b)
239 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
241 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
244 static struct led_classdev db1100_mmc_led = {
245 .brightness_set = db1100_mmcled_set,
248 static int db1100_mmc1_card_readonly(void *mmc_host)
250 return (bcsr_read(BCSR_BOARD) & BCSR_BOARD_SD1WP) ? 1 : 0;
253 static int db1100_mmc1_card_inserted(void *mmc_host)
255 return !alchemy_gpio_get_value(20);
258 static void db1100_mmc1_set_power(void *mmc_host, int state)
262 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100)
263 bit = BCSR_BOARD_SD1PWR;
265 bit = BCSR_BOARD_PB1100_SD1PWR;
268 bcsr_mod(BCSR_BOARD, 0, bit);
269 msleep(400); /* stabilization time */
271 bcsr_mod(BCSR_BOARD, bit, 0);
274 static void db1100_mmc1led_set(struct led_classdev *led, enum led_brightness b)
277 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0);
279 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1);
282 static struct led_classdev db1100_mmc1_led = {
283 .brightness_set = db1100_mmc1led_set,
286 static struct au1xmmc_platform_data db1100_mmc_platdata[2] = {
288 .cd_setup = db1100_mmc_cd_setup,
289 .set_power = db1100_mmc_set_power,
290 .card_inserted = db1100_mmc_card_inserted,
291 .card_readonly = db1100_mmc_card_readonly,
292 .led = &db1100_mmc_led,
295 .cd_setup = db1100_mmc1_cd_setup,
296 .set_power = db1100_mmc1_set_power,
297 .card_inserted = db1100_mmc1_card_inserted,
298 .card_readonly = db1100_mmc1_card_readonly,
299 .led = &db1100_mmc1_led,
303 static struct resource au1100_mmc0_resources[] = {
305 .start = AU1100_SD0_PHYS_ADDR,
306 .end = AU1100_SD0_PHYS_ADDR + 0xfff,
307 .flags = IORESOURCE_MEM,
310 .start = AU1100_SD_INT,
311 .end = AU1100_SD_INT,
312 .flags = IORESOURCE_IRQ,
315 .start = DMA_ID_SD0_TX,
316 .end = DMA_ID_SD0_TX,
317 .flags = IORESOURCE_DMA,
320 .start = DMA_ID_SD0_RX,
321 .end = DMA_ID_SD0_RX,
322 .flags = IORESOURCE_DMA,
326 static struct platform_device db1100_mmc0_dev = {
327 .name = "au1xxx-mmc",
330 .dma_mask = &au1xxx_all_dmamask,
331 .coherent_dma_mask = DMA_BIT_MASK(32),
332 .platform_data = &db1100_mmc_platdata[0],
334 .num_resources = ARRAY_SIZE(au1100_mmc0_resources),
335 .resource = au1100_mmc0_resources,
338 static struct resource au1100_mmc1_res[] = {
340 .start = AU1100_SD1_PHYS_ADDR,
341 .end = AU1100_SD1_PHYS_ADDR + 0xfff,
342 .flags = IORESOURCE_MEM,
345 .start = AU1100_SD_INT,
346 .end = AU1100_SD_INT,
347 .flags = IORESOURCE_IRQ,
350 .start = DMA_ID_SD1_TX,
351 .end = DMA_ID_SD1_TX,
352 .flags = IORESOURCE_DMA,
355 .start = DMA_ID_SD1_RX,
356 .end = DMA_ID_SD1_RX,
357 .flags = IORESOURCE_DMA,
361 static struct platform_device db1100_mmc1_dev = {
362 .name = "au1xxx-mmc",
365 .dma_mask = &au1xxx_all_dmamask,
366 .coherent_dma_mask = DMA_BIT_MASK(32),
367 .platform_data = &db1100_mmc_platdata[1],
369 .num_resources = ARRAY_SIZE(au1100_mmc1_res),
370 .resource = au1100_mmc1_res,
373 /******************************************************************************/
375 static struct ads7846_platform_data db1100_touch_pd = {
380 static struct spi_gpio_platform_data db1100_spictl_pd = {
384 static struct gpiod_lookup_table db1100_touch_gpio_table = {
387 GPIO_LOOKUP("alchemy-gpio2", 21,
388 "pendown", GPIO_ACTIVE_LOW),
393 static struct spi_board_info db1100_spi_info[] __initdata = {
395 .modalias = "ads7846",
396 .max_speed_hz = 3250000,
400 .irq = AU1100_GPIO21_INT,
401 .platform_data = &db1100_touch_pd,
405 static struct platform_device db1100_spi_dev = {
409 .platform_data = &db1100_spictl_pd,
410 .dma_mask = &au1xxx_all_dmamask,
411 .coherent_dma_mask = DMA_BIT_MASK(32),
416 * Alchemy GPIO 2 has its base at 200 so the GPIO lines
417 * 207 thru 210 are GPIOs at offset 7 thru 10 at this chip.
419 static struct gpiod_lookup_table db1100_spi_gpiod_table = {
420 .dev_id = "spi_gpio",
422 GPIO_LOOKUP("alchemy-gpio2", 9,
423 "sck", GPIO_ACTIVE_HIGH),
424 GPIO_LOOKUP("alchemy-gpio2", 8,
425 "mosi", GPIO_ACTIVE_HIGH),
426 GPIO_LOOKUP("alchemy-gpio2", 7,
427 "miso", GPIO_ACTIVE_HIGH),
428 GPIO_LOOKUP("alchemy-gpio2", 10,
429 "cs", GPIO_ACTIVE_HIGH),
434 static struct platform_device *db1x00_devs[] = {
436 &alchemy_ac97c_dma_dev,
441 static struct platform_device *db1100_devs[] = {
447 int __init db1000_dev_setup(void)
449 int board = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
450 int c0, c1, d0, d1, s0, s1, flashsize = 32, twosocks = 1;
454 if (board == BCSR_WHOAMI_DB1500) {
455 c0 = AU1500_GPIO2_INT;
456 c1 = AU1500_GPIO5_INT;
457 d0 = 0; /* GPIO number, NOT irq! */
458 d1 = 3; /* GPIO number, NOT irq! */
459 s0 = AU1500_GPIO1_INT;
460 s1 = AU1500_GPIO4_INT;
461 } else if (board == BCSR_WHOAMI_DB1100) {
462 c0 = AU1100_GPIO2_INT;
463 c1 = AU1100_GPIO5_INT;
464 d0 = 0; /* GPIO number, NOT irq! */
465 d1 = 3; /* GPIO number, NOT irq! */
466 s0 = AU1100_GPIO1_INT;
467 s1 = AU1100_GPIO4_INT;
469 gpio_request(19, "sd0_cd");
470 gpio_request(20, "sd1_cd");
471 gpio_direction_input(19); /* sd0 cd# */
472 gpio_direction_input(20); /* sd1 cd# */
474 /* spi_gpio on SSI0 pins */
475 pfc = alchemy_rdsys(AU1000_SYS_PINFUNC);
476 pfc |= (1 << 0); /* SSI0 pins as GPIOs */
477 alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
479 gpiod_add_lookup_table(&db1100_touch_gpio_table);
480 spi_register_board_info(db1100_spi_info,
481 ARRAY_SIZE(db1100_spi_info));
483 /* link LCD clock to AUXPLL */
484 p = clk_get(NULL, "auxpll_clk");
485 c = clk_get(NULL, "lcd_intclk");
486 if (!IS_ERR(c) && !IS_ERR(p)) {
487 clk_set_parent(c, p);
488 clk_set_rate(c, clk_get_rate(p));
495 platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs));
496 gpiod_add_lookup_table(&db1100_spi_gpiod_table);
497 platform_device_register(&db1100_spi_dev);
498 } else if (board == BCSR_WHOAMI_DB1000) {
499 c0 = AU1000_GPIO2_INT;
500 c1 = AU1000_GPIO5_INT;
501 d0 = 0; /* GPIO number, NOT irq! */
502 d1 = 3; /* GPIO number, NOT irq! */
503 s0 = AU1000_GPIO1_INT;
504 s1 = AU1000_GPIO4_INT;
505 } else if ((board == BCSR_WHOAMI_PB1500) ||
506 (board == BCSR_WHOAMI_PB1500R2)) {
507 c0 = AU1500_GPIO203_INT;
508 d0 = 1; /* GPIO number, NOT irq! */
509 s0 = AU1500_GPIO202_INT;
512 /* RTC and daughtercard irqs */
513 irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_LOW);
514 irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW);
515 /* EPSON S1D13806 0x1b000000
516 * SRAM 1MB/2MB 0x1a000000
517 * DS1693 RTC 0x0c000000
519 } else if (board == BCSR_WHOAMI_PB1100) {
520 c0 = AU1100_GPIO11_INT;
521 d0 = 9; /* GPIO number, NOT irq! */
522 s0 = AU1100_GPIO10_INT;
525 /* pendown, rtc, daughtercard irqs */
526 irq_set_irq_type(AU1100_GPIO8_INT, IRQ_TYPE_LEVEL_LOW);
527 irq_set_irq_type(AU1100_GPIO12_INT, IRQ_TYPE_LEVEL_LOW);
528 irq_set_irq_type(AU1100_GPIO13_INT, IRQ_TYPE_LEVEL_LOW);
529 /* EPSON S1D13806 0x1b000000
530 * SRAM 1MB/2MB 0x1a000000
531 * DiskOnChip 0x0d000000
532 * DS1693 RTC 0x0c000000
534 platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs));
536 return 0; /* unknown board, no further dev setup to do */
538 irq_set_irq_type(c0, IRQ_TYPE_LEVEL_LOW);
539 irq_set_irq_type(s0, IRQ_TYPE_LEVEL_LOW);
541 db1x_register_pcmcia_socket(
542 AU1000_PCMCIA_ATTR_PHYS_ADDR,
543 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
544 AU1000_PCMCIA_MEM_PHYS_ADDR,
545 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
546 AU1000_PCMCIA_IO_PHYS_ADDR,
547 AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
548 c0, d0, /*s0*/0, 0, 0);
551 irq_set_irq_type(c1, IRQ_TYPE_LEVEL_LOW);
552 irq_set_irq_type(s1, IRQ_TYPE_LEVEL_LOW);
554 db1x_register_pcmcia_socket(
555 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000,
556 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1,
557 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000,
558 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1,
559 AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000,
560 AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1,
561 c1, d1, /*s1*/0, 0, 1);
564 platform_add_devices(db1x00_devs, ARRAY_SIZE(db1x00_devs));
565 db1x_register_norflash(flashsize << 20, 4 /* 32bit */, F_SWAPPED);