2 * DBAu1000/1500/1100 PBAu1100/1500 board support
4 * Copyright 2000, 2008 MontaVista Software Inc.
5 * Author: MontaVista Software, Inc. <source@mvista.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <linux/clk.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/gpio.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/leds.h>
28 #include <linux/mmc/host.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
32 #include <linux/spi/spi.h>
33 #include <linux/spi/spi_gpio.h>
34 #include <linux/spi/ads7846.h>
35 #include <asm/mach-au1x00/au1000.h>
36 #include <asm/mach-au1x00/gpio-au1000.h>
37 #include <asm/mach-au1x00/au1000_dma.h>
38 #include <asm/mach-au1x00/au1100_mmc.h>
39 #include <asm/mach-db1x00/bcsr.h>
40 #include <asm/reboot.h>
44 #define F_SWAPPED (bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT)
46 const char *get_system_type(void);
48 int __init
db1000_board_setup(void)
50 /* initialize board register space */
51 bcsr_init(DB1000_BCSR_PHYS_ADDR
,
52 DB1000_BCSR_PHYS_ADDR
+ DB1000_BCSR_HEXLED_OFS
);
54 switch (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
))) {
55 case BCSR_WHOAMI_DB1000
:
56 case BCSR_WHOAMI_DB1500
:
57 case BCSR_WHOAMI_DB1100
:
58 case BCSR_WHOAMI_PB1500
:
59 case BCSR_WHOAMI_PB1500R2
:
60 case BCSR_WHOAMI_PB1100
:
61 pr_info("AMD Alchemy %s Board\n", get_system_type());
67 static int db1500_map_pci_irq(const struct pci_dev
*d
, u8 slot
, u8 pin
)
69 if ((slot
< 12) || (slot
> 13) || pin
== 0)
72 return (pin
== 1) ? AU1500_PCI_INTA
: 0xff;
75 case 1: return AU1500_PCI_INTA
;
76 case 2: return AU1500_PCI_INTB
;
77 case 3: return AU1500_PCI_INTC
;
78 case 4: return AU1500_PCI_INTD
;
84 static struct resource alchemy_pci_host_res
[] = {
86 .start
= AU1500_PCI_PHYS_ADDR
,
87 .end
= AU1500_PCI_PHYS_ADDR
+ 0xfff,
88 .flags
= IORESOURCE_MEM
,
92 static struct alchemy_pci_platdata db1500_pci_pd
= {
93 .board_map_irq
= db1500_map_pci_irq
,
96 static struct platform_device db1500_pci_host_dev
= {
97 .dev
.platform_data
= &db1500_pci_pd
,
98 .name
= "alchemy-pci",
100 .num_resources
= ARRAY_SIZE(alchemy_pci_host_res
),
101 .resource
= alchemy_pci_host_res
,
104 int __init
db1500_pci_setup(void)
106 return platform_device_register(&db1500_pci_host_dev
);
109 static struct resource au1100_lcd_resources
[] = {
111 .start
= AU1100_LCD_PHYS_ADDR
,
112 .end
= AU1100_LCD_PHYS_ADDR
+ 0x800 - 1,
113 .flags
= IORESOURCE_MEM
,
116 .start
= AU1100_LCD_INT
,
117 .end
= AU1100_LCD_INT
,
118 .flags
= IORESOURCE_IRQ
,
122 static u64 au1100_lcd_dmamask
= DMA_BIT_MASK(32);
124 static struct platform_device au1100_lcd_device
= {
125 .name
= "au1100-lcd",
128 .dma_mask
= &au1100_lcd_dmamask
,
129 .coherent_dma_mask
= DMA_BIT_MASK(32),
131 .num_resources
= ARRAY_SIZE(au1100_lcd_resources
),
132 .resource
= au1100_lcd_resources
,
135 static struct resource alchemy_ac97c_res
[] = {
137 .start
= AU1000_AC97_PHYS_ADDR
,
138 .end
= AU1000_AC97_PHYS_ADDR
+ 0xfff,
139 .flags
= IORESOURCE_MEM
,
142 .start
= DMA_ID_AC97C_TX
,
143 .end
= DMA_ID_AC97C_TX
,
144 .flags
= IORESOURCE_DMA
,
147 .start
= DMA_ID_AC97C_RX
,
148 .end
= DMA_ID_AC97C_RX
,
149 .flags
= IORESOURCE_DMA
,
153 static struct platform_device alchemy_ac97c_dev
= {
154 .name
= "alchemy-ac97c",
156 .resource
= alchemy_ac97c_res
,
157 .num_resources
= ARRAY_SIZE(alchemy_ac97c_res
),
160 static struct platform_device alchemy_ac97c_dma_dev
= {
161 .name
= "alchemy-pcm-dma",
165 static struct platform_device db1x00_codec_dev
= {
166 .name
= "ac97-codec",
170 static struct platform_device db1x00_audio_dev
= {
171 .name
= "db1000-audio",
174 /******************************************************************************/
176 static irqreturn_t
db1100_mmc_cd(int irq
, void *ptr
)
178 void (*mmc_cd
)(struct mmc_host
*, unsigned long);
179 /* link against CONFIG_MMC=m */
180 mmc_cd
= symbol_get(mmc_detect_change
);
181 mmc_cd(ptr
, msecs_to_jiffies(500));
182 symbol_put(mmc_detect_change
);
187 static int db1100_mmc_cd_setup(void *mmc_host
, int en
)
191 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
)) == BCSR_WHOAMI_DB1100
)
192 irq
= AU1100_GPIO19_INT
;
194 irq
= AU1100_GPIO14_INT
; /* PB1100 SD0 CD# */
197 irq_set_irq_type(irq
, IRQ_TYPE_EDGE_BOTH
);
198 ret
= request_irq(irq
, db1100_mmc_cd
, 0,
201 free_irq(irq
, mmc_host
);
205 static int db1100_mmc1_cd_setup(void *mmc_host
, int en
)
209 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
)) == BCSR_WHOAMI_DB1100
)
210 irq
= AU1100_GPIO20_INT
;
212 irq
= AU1100_GPIO15_INT
; /* PB1100 SD1 CD# */
215 irq_set_irq_type(irq
, IRQ_TYPE_EDGE_BOTH
);
216 ret
= request_irq(irq
, db1100_mmc_cd
, 0,
219 free_irq(irq
, mmc_host
);
223 static int db1100_mmc_card_readonly(void *mmc_host
)
225 /* testing suggests that this bit is inverted */
226 return (bcsr_read(BCSR_STATUS
) & BCSR_STATUS_SD0WP
) ? 0 : 1;
229 static int db1100_mmc_card_inserted(void *mmc_host
)
231 return !alchemy_gpio_get_value(19);
234 static void db1100_mmc_set_power(void *mmc_host
, int state
)
238 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
)) == BCSR_WHOAMI_DB1100
)
239 bit
= BCSR_BOARD_SD0PWR
;
241 bit
= BCSR_BOARD_PB1100_SD0PWR
;
244 bcsr_mod(BCSR_BOARD
, 0, bit
);
245 msleep(400); /* stabilization time */
247 bcsr_mod(BCSR_BOARD
, bit
, 0);
250 static void db1100_mmcled_set(struct led_classdev
*led
, enum led_brightness b
)
253 bcsr_mod(BCSR_LEDS
, BCSR_LEDS_LED0
, 0);
255 bcsr_mod(BCSR_LEDS
, 0, BCSR_LEDS_LED0
);
258 static struct led_classdev db1100_mmc_led
= {
259 .brightness_set
= db1100_mmcled_set
,
262 static int db1100_mmc1_card_readonly(void *mmc_host
)
264 return (bcsr_read(BCSR_BOARD
) & BCSR_BOARD_SD1WP
) ? 1 : 0;
267 static int db1100_mmc1_card_inserted(void *mmc_host
)
269 return !alchemy_gpio_get_value(20);
272 static void db1100_mmc1_set_power(void *mmc_host
, int state
)
276 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
)) == BCSR_WHOAMI_DB1100
)
277 bit
= BCSR_BOARD_SD1PWR
;
279 bit
= BCSR_BOARD_PB1100_SD1PWR
;
282 bcsr_mod(BCSR_BOARD
, 0, bit
);
283 msleep(400); /* stabilization time */
285 bcsr_mod(BCSR_BOARD
, bit
, 0);
288 static void db1100_mmc1led_set(struct led_classdev
*led
, enum led_brightness b
)
291 bcsr_mod(BCSR_LEDS
, BCSR_LEDS_LED1
, 0);
293 bcsr_mod(BCSR_LEDS
, 0, BCSR_LEDS_LED1
);
296 static struct led_classdev db1100_mmc1_led
= {
297 .brightness_set
= db1100_mmc1led_set
,
300 static struct au1xmmc_platform_data db1100_mmc_platdata
[2] = {
302 .cd_setup
= db1100_mmc_cd_setup
,
303 .set_power
= db1100_mmc_set_power
,
304 .card_inserted
= db1100_mmc_card_inserted
,
305 .card_readonly
= db1100_mmc_card_readonly
,
306 .led
= &db1100_mmc_led
,
309 .cd_setup
= db1100_mmc1_cd_setup
,
310 .set_power
= db1100_mmc1_set_power
,
311 .card_inserted
= db1100_mmc1_card_inserted
,
312 .card_readonly
= db1100_mmc1_card_readonly
,
313 .led
= &db1100_mmc1_led
,
317 static struct resource au1100_mmc0_resources
[] = {
319 .start
= AU1100_SD0_PHYS_ADDR
,
320 .end
= AU1100_SD0_PHYS_ADDR
+ 0xfff,
321 .flags
= IORESOURCE_MEM
,
324 .start
= AU1100_SD_INT
,
325 .end
= AU1100_SD_INT
,
326 .flags
= IORESOURCE_IRQ
,
329 .start
= DMA_ID_SD0_TX
,
330 .end
= DMA_ID_SD0_TX
,
331 .flags
= IORESOURCE_DMA
,
334 .start
= DMA_ID_SD0_RX
,
335 .end
= DMA_ID_SD0_RX
,
336 .flags
= IORESOURCE_DMA
,
340 static u64 au1xxx_mmc_dmamask
= DMA_BIT_MASK(32);
342 static struct platform_device db1100_mmc0_dev
= {
343 .name
= "au1xxx-mmc",
346 .dma_mask
= &au1xxx_mmc_dmamask
,
347 .coherent_dma_mask
= DMA_BIT_MASK(32),
348 .platform_data
= &db1100_mmc_platdata
[0],
350 .num_resources
= ARRAY_SIZE(au1100_mmc0_resources
),
351 .resource
= au1100_mmc0_resources
,
354 static struct resource au1100_mmc1_res
[] = {
356 .start
= AU1100_SD1_PHYS_ADDR
,
357 .end
= AU1100_SD1_PHYS_ADDR
+ 0xfff,
358 .flags
= IORESOURCE_MEM
,
361 .start
= AU1100_SD_INT
,
362 .end
= AU1100_SD_INT
,
363 .flags
= IORESOURCE_IRQ
,
366 .start
= DMA_ID_SD1_TX
,
367 .end
= DMA_ID_SD1_TX
,
368 .flags
= IORESOURCE_DMA
,
371 .start
= DMA_ID_SD1_RX
,
372 .end
= DMA_ID_SD1_RX
,
373 .flags
= IORESOURCE_DMA
,
377 static struct platform_device db1100_mmc1_dev
= {
378 .name
= "au1xxx-mmc",
381 .dma_mask
= &au1xxx_mmc_dmamask
,
382 .coherent_dma_mask
= DMA_BIT_MASK(32),
383 .platform_data
= &db1100_mmc_platdata
[1],
385 .num_resources
= ARRAY_SIZE(au1100_mmc1_res
),
386 .resource
= au1100_mmc1_res
,
389 /******************************************************************************/
391 static void db1000_irda_set_phy_mode(int mode
)
393 unsigned short mask
= BCSR_RESETS_IRDA_MODE_MASK
| BCSR_RESETS_FIR_SEL
;
396 case AU1000_IRDA_PHY_MODE_OFF
:
397 bcsr_mod(BCSR_RESETS
, mask
, BCSR_RESETS_IRDA_MODE_OFF
);
399 case AU1000_IRDA_PHY_MODE_SIR
:
400 bcsr_mod(BCSR_RESETS
, mask
, BCSR_RESETS_IRDA_MODE_FULL
);
402 case AU1000_IRDA_PHY_MODE_FIR
:
403 bcsr_mod(BCSR_RESETS
, mask
, BCSR_RESETS_IRDA_MODE_FULL
|
404 BCSR_RESETS_FIR_SEL
);
409 static struct au1k_irda_platform_data db1000_irda_platdata
= {
410 .set_phy_mode
= db1000_irda_set_phy_mode
,
413 static struct resource au1000_irda_res
[] = {
415 .start
= AU1000_IRDA_PHYS_ADDR
,
416 .end
= AU1000_IRDA_PHYS_ADDR
+ 0x0fff,
417 .flags
= IORESOURCE_MEM
,
420 .start
= AU1000_IRDA_TX_INT
,
421 .end
= AU1000_IRDA_TX_INT
,
422 .flags
= IORESOURCE_IRQ
,
425 .start
= AU1000_IRDA_RX_INT
,
426 .end
= AU1000_IRDA_RX_INT
,
427 .flags
= IORESOURCE_IRQ
,
431 static struct platform_device db1000_irda_dev
= {
432 .name
= "au1000-irda",
435 .platform_data
= &db1000_irda_platdata
,
437 .resource
= au1000_irda_res
,
438 .num_resources
= ARRAY_SIZE(au1000_irda_res
),
441 /******************************************************************************/
443 static struct ads7846_platform_data db1100_touch_pd
= {
449 static struct spi_gpio_platform_data db1100_spictl_pd
= {
456 static struct spi_board_info db1100_spi_info
[] __initdata
= {
458 .modalias
= "ads7846",
459 .max_speed_hz
= 3250000,
463 .irq
= AU1100_GPIO21_INT
,
464 .platform_data
= &db1100_touch_pd
,
465 .controller_data
= (void *)210, /* for spi_gpio: CS# GPIO210 */
469 static struct platform_device db1100_spi_dev
= {
473 .platform_data
= &db1100_spictl_pd
,
478 static struct platform_device
*db1x00_devs
[] = {
480 &alchemy_ac97c_dma_dev
,
485 static struct platform_device
*db1000_devs
[] = {
489 static struct platform_device
*db1100_devs
[] = {
496 int __init
db1000_dev_setup(void)
498 int board
= BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI
));
499 int c0
, c1
, d0
, d1
, s0
, s1
, flashsize
= 32, twosocks
= 1;
503 if (board
== BCSR_WHOAMI_DB1500
) {
504 c0
= AU1500_GPIO2_INT
;
505 c1
= AU1500_GPIO5_INT
;
506 d0
= 0; /* GPIO number, NOT irq! */
507 d1
= 3; /* GPIO number, NOT irq! */
508 s0
= AU1500_GPIO1_INT
;
509 s1
= AU1500_GPIO4_INT
;
510 } else if (board
== BCSR_WHOAMI_DB1100
) {
511 c0
= AU1100_GPIO2_INT
;
512 c1
= AU1100_GPIO5_INT
;
513 d0
= 0; /* GPIO number, NOT irq! */
514 d1
= 3; /* GPIO number, NOT irq! */
515 s0
= AU1100_GPIO1_INT
;
516 s1
= AU1100_GPIO4_INT
;
518 gpio_request(19, "sd0_cd");
519 gpio_request(20, "sd1_cd");
520 gpio_direction_input(19); /* sd0 cd# */
521 gpio_direction_input(20); /* sd1 cd# */
523 /* spi_gpio on SSI0 pins */
524 pfc
= alchemy_rdsys(AU1000_SYS_PINFUNC
);
525 pfc
|= (1 << 0); /* SSI0 pins as GPIOs */
526 alchemy_wrsys(pfc
, AU1000_SYS_PINFUNC
);
528 spi_register_board_info(db1100_spi_info
,
529 ARRAY_SIZE(db1100_spi_info
));
531 /* link LCD clock to AUXPLL */
532 p
= clk_get(NULL
, "auxpll_clk");
533 c
= clk_get(NULL
, "lcd_intclk");
534 if (!IS_ERR(c
) && !IS_ERR(p
)) {
535 clk_set_parent(c
, p
);
536 clk_set_rate(c
, clk_get_rate(p
));
543 platform_add_devices(db1100_devs
, ARRAY_SIZE(db1100_devs
));
544 platform_device_register(&db1100_spi_dev
);
545 } else if (board
== BCSR_WHOAMI_DB1000
) {
546 c0
= AU1000_GPIO2_INT
;
547 c1
= AU1000_GPIO5_INT
;
548 d0
= 0; /* GPIO number, NOT irq! */
549 d1
= 3; /* GPIO number, NOT irq! */
550 s0
= AU1000_GPIO1_INT
;
551 s1
= AU1000_GPIO4_INT
;
552 platform_add_devices(db1000_devs
, ARRAY_SIZE(db1000_devs
));
553 } else if ((board
== BCSR_WHOAMI_PB1500
) ||
554 (board
== BCSR_WHOAMI_PB1500R2
)) {
555 c0
= AU1500_GPIO203_INT
;
556 d0
= 1; /* GPIO number, NOT irq! */
557 s0
= AU1500_GPIO202_INT
;
560 /* RTC and daughtercard irqs */
561 irq_set_irq_type(AU1500_GPIO204_INT
, IRQ_TYPE_LEVEL_LOW
);
562 irq_set_irq_type(AU1500_GPIO205_INT
, IRQ_TYPE_LEVEL_LOW
);
563 /* EPSON S1D13806 0x1b000000
564 * SRAM 1MB/2MB 0x1a000000
565 * DS1693 RTC 0x0c000000
567 } else if (board
== BCSR_WHOAMI_PB1100
) {
568 c0
= AU1100_GPIO11_INT
;
569 d0
= 9; /* GPIO number, NOT irq! */
570 s0
= AU1100_GPIO10_INT
;
573 /* pendown, rtc, daughtercard irqs */
574 irq_set_irq_type(AU1100_GPIO8_INT
, IRQ_TYPE_LEVEL_LOW
);
575 irq_set_irq_type(AU1100_GPIO12_INT
, IRQ_TYPE_LEVEL_LOW
);
576 irq_set_irq_type(AU1100_GPIO13_INT
, IRQ_TYPE_LEVEL_LOW
);
577 /* EPSON S1D13806 0x1b000000
578 * SRAM 1MB/2MB 0x1a000000
579 * DiskOnChip 0x0d000000
580 * DS1693 RTC 0x0c000000
582 platform_add_devices(db1100_devs
, ARRAY_SIZE(db1100_devs
));
584 return 0; /* unknown board, no further dev setup to do */
586 irq_set_irq_type(c0
, IRQ_TYPE_LEVEL_LOW
);
587 irq_set_irq_type(s0
, IRQ_TYPE_LEVEL_LOW
);
589 db1x_register_pcmcia_socket(
590 AU1000_PCMCIA_ATTR_PHYS_ADDR
,
591 AU1000_PCMCIA_ATTR_PHYS_ADDR
+ 0x000400000 - 1,
592 AU1000_PCMCIA_MEM_PHYS_ADDR
,
593 AU1000_PCMCIA_MEM_PHYS_ADDR
+ 0x000400000 - 1,
594 AU1000_PCMCIA_IO_PHYS_ADDR
,
595 AU1000_PCMCIA_IO_PHYS_ADDR
+ 0x000010000 - 1,
596 c0
, d0
, /*s0*/0, 0, 0);
599 irq_set_irq_type(c1
, IRQ_TYPE_LEVEL_LOW
);
600 irq_set_irq_type(s1
, IRQ_TYPE_LEVEL_LOW
);
602 db1x_register_pcmcia_socket(
603 AU1000_PCMCIA_ATTR_PHYS_ADDR
+ 0x004000000,
604 AU1000_PCMCIA_ATTR_PHYS_ADDR
+ 0x004400000 - 1,
605 AU1000_PCMCIA_MEM_PHYS_ADDR
+ 0x004000000,
606 AU1000_PCMCIA_MEM_PHYS_ADDR
+ 0x004400000 - 1,
607 AU1000_PCMCIA_IO_PHYS_ADDR
+ 0x004000000,
608 AU1000_PCMCIA_IO_PHYS_ADDR
+ 0x004010000 - 1,
609 c1
, d1
, /*s1*/0, 0, 1);
612 platform_add_devices(db1x00_devs
, ARRAY_SIZE(db1x00_devs
));
613 db1x_register_norflash(flashsize
<< 20, 4 /* 32bit */, F_SWAPPED
);