1fd534e9bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
27c4b24daSManuel Lauss /*
36f7c8623SManuel Lauss * DBAu1200/PBAu1200 board platform device registration
47c4b24daSManuel Lauss *
57c4b24daSManuel Lauss * Copyright (C) 2008-2011 Manuel Lauss
67c4b24daSManuel Lauss */
77c4b24daSManuel Lauss
8415e0fecSManuel Lauss #include <linux/clk.h>
97c4b24daSManuel Lauss #include <linux/dma-mapping.h>
107c4b24daSManuel Lauss #include <linux/gpio.h>
117c4b24daSManuel Lauss #include <linux/i2c.h>
127c4b24daSManuel Lauss #include <linux/init.h>
137c4b24daSManuel Lauss #include <linux/interrupt.h>
147c4b24daSManuel Lauss #include <linux/io.h>
157c4b24daSManuel Lauss #include <linux/leds.h>
167c4b24daSManuel Lauss #include <linux/mmc/host.h>
177c4b24daSManuel Lauss #include <linux/mtd/mtd.h>
18c7921bb3SBoris Brezillon #include <linux/mtd/platnand.h>
197c4b24daSManuel Lauss #include <linux/platform_device.h>
207c4b24daSManuel Lauss #include <linux/serial_8250.h>
217c4b24daSManuel Lauss #include <linux/spi/spi.h>
227c4b24daSManuel Lauss #include <linux/spi/flash.h>
237c4b24daSManuel Lauss #include <linux/smc91x.h>
2454ff4a1dSManuel Lauss #include <linux/ata_platform.h>
257c4b24daSManuel Lauss #include <asm/mach-au1x00/au1000.h>
267c4b24daSManuel Lauss #include <asm/mach-au1x00/au1100_mmc.h>
277c4b24daSManuel Lauss #include <asm/mach-au1x00/au1xxx_dbdma.h>
28a16afa53SManuel Lauss #include <asm/mach-au1x00/au1xxx_psc.h>
29a9b71a8fSManuel Lauss #include <asm/mach-au1x00/au1200fb.h>
307c4b24daSManuel Lauss #include <asm/mach-au1x00/au1550_spi.h>
317c4b24daSManuel Lauss #include <asm/mach-db1x00/bcsr.h>
327c4b24daSManuel Lauss
337c4b24daSManuel Lauss #include "platform.h"
347c4b24daSManuel Lauss
35a16afa53SManuel Lauss #define BCSR_INT_IDE 0x0001
36a16afa53SManuel Lauss #define BCSR_INT_ETH 0x0002
37a16afa53SManuel Lauss #define BCSR_INT_PC0 0x0004
38a16afa53SManuel Lauss #define BCSR_INT_PC0STSCHG 0x0008
39a16afa53SManuel Lauss #define BCSR_INT_PC1 0x0010
40a16afa53SManuel Lauss #define BCSR_INT_PC1STSCHG 0x0020
41a16afa53SManuel Lauss #define BCSR_INT_DC 0x0040
42a16afa53SManuel Lauss #define BCSR_INT_FLASHBUSY 0x0080
43a16afa53SManuel Lauss #define BCSR_INT_PC0INSERT 0x0100
44a16afa53SManuel Lauss #define BCSR_INT_PC0EJECT 0x0200
45a16afa53SManuel Lauss #define BCSR_INT_PC1INSERT 0x0400
46a16afa53SManuel Lauss #define BCSR_INT_PC1EJECT 0x0800
47a16afa53SManuel Lauss #define BCSR_INT_SD0INSERT 0x1000
48a16afa53SManuel Lauss #define BCSR_INT_SD0EJECT 0x2000
49a16afa53SManuel Lauss #define BCSR_INT_SD1INSERT 0x4000
50a16afa53SManuel Lauss #define BCSR_INT_SD1EJECT 0x8000
51a16afa53SManuel Lauss
52a16afa53SManuel Lauss #define DB1200_IDE_PHYS_ADDR 0x18800000
53a16afa53SManuel Lauss #define DB1200_IDE_REG_SHIFT 5
54a16afa53SManuel Lauss #define DB1200_IDE_PHYS_LEN (16 << DB1200_IDE_REG_SHIFT)
55a16afa53SManuel Lauss #define DB1200_ETH_PHYS_ADDR 0x19000300
56a16afa53SManuel Lauss #define DB1200_NAND_PHYS_ADDR 0x20000000
57a16afa53SManuel Lauss
58a16afa53SManuel Lauss #define PB1200_IDE_PHYS_ADDR 0x0C800000
59a16afa53SManuel Lauss #define PB1200_ETH_PHYS_ADDR 0x0D000300
60a16afa53SManuel Lauss #define PB1200_NAND_PHYS_ADDR 0x1C000000
61a16afa53SManuel Lauss
62a16afa53SManuel Lauss #define DB1200_INT_BEGIN (AU1000_MAX_INTR + 1)
63a16afa53SManuel Lauss #define DB1200_IDE_INT (DB1200_INT_BEGIN + 0)
64a16afa53SManuel Lauss #define DB1200_ETH_INT (DB1200_INT_BEGIN + 1)
65a16afa53SManuel Lauss #define DB1200_PC0_INT (DB1200_INT_BEGIN + 2)
66a16afa53SManuel Lauss #define DB1200_PC0_STSCHG_INT (DB1200_INT_BEGIN + 3)
67a16afa53SManuel Lauss #define DB1200_PC1_INT (DB1200_INT_BEGIN + 4)
68a16afa53SManuel Lauss #define DB1200_PC1_STSCHG_INT (DB1200_INT_BEGIN + 5)
69a16afa53SManuel Lauss #define DB1200_DC_INT (DB1200_INT_BEGIN + 6)
70a16afa53SManuel Lauss #define DB1200_FLASHBUSY_INT (DB1200_INT_BEGIN + 7)
71a16afa53SManuel Lauss #define DB1200_PC0_INSERT_INT (DB1200_INT_BEGIN + 8)
72a16afa53SManuel Lauss #define DB1200_PC0_EJECT_INT (DB1200_INT_BEGIN + 9)
73a16afa53SManuel Lauss #define DB1200_PC1_INSERT_INT (DB1200_INT_BEGIN + 10)
74a16afa53SManuel Lauss #define DB1200_PC1_EJECT_INT (DB1200_INT_BEGIN + 11)
75a16afa53SManuel Lauss #define DB1200_SD0_INSERT_INT (DB1200_INT_BEGIN + 12)
76a16afa53SManuel Lauss #define DB1200_SD0_EJECT_INT (DB1200_INT_BEGIN + 13)
77a16afa53SManuel Lauss #define PB1200_SD1_INSERT_INT (DB1200_INT_BEGIN + 14)
78a16afa53SManuel Lauss #define PB1200_SD1_EJECT_INT (DB1200_INT_BEGIN + 15)
79a16afa53SManuel Lauss #define DB1200_INT_END (DB1200_INT_BEGIN + 15)
80a16afa53SManuel Lauss
81bd8510dfSManuel Lauss const char *get_system_type(void);
827c4b24daSManuel Lauss
db1200_detect_board(void)83bd8510dfSManuel Lauss static int __init db1200_detect_board(void)
846f7c8623SManuel Lauss {
856f7c8623SManuel Lauss int bid;
866f7c8623SManuel Lauss
87f2711be0SManuel Lauss /* try the DB1200 first */
88f2711be0SManuel Lauss bcsr_init(DB1200_BCSR_PHYS_ADDR,
89f2711be0SManuel Lauss DB1200_BCSR_PHYS_ADDR + DB1200_BCSR_HEXLED_OFS);
90f2711be0SManuel Lauss if (BCSR_WHOAMI_DB1200 == BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI))) {
91f2711be0SManuel Lauss unsigned short t = bcsr_read(BCSR_HEXLEDS);
92f2711be0SManuel Lauss bcsr_write(BCSR_HEXLEDS, ~t);
93f2711be0SManuel Lauss if (bcsr_read(BCSR_HEXLEDS) != t) {
94f2711be0SManuel Lauss bcsr_write(BCSR_HEXLEDS, t);
95f2711be0SManuel Lauss return 0;
96f2711be0SManuel Lauss }
97f2711be0SManuel Lauss }
98f2711be0SManuel Lauss
99f2711be0SManuel Lauss /* okay, try the PB1200 then */
1006f7c8623SManuel Lauss bcsr_init(PB1200_BCSR_PHYS_ADDR,
1016f7c8623SManuel Lauss PB1200_BCSR_PHYS_ADDR + PB1200_BCSR_HEXLED_OFS);
1026f7c8623SManuel Lauss bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
1036f7c8623SManuel Lauss if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
104f2711be0SManuel Lauss (bid == BCSR_WHOAMI_PB1200_DDR2)) {
105f2711be0SManuel Lauss unsigned short t = bcsr_read(BCSR_HEXLEDS);
106f2711be0SManuel Lauss bcsr_write(BCSR_HEXLEDS, ~t);
107f2711be0SManuel Lauss if (bcsr_read(BCSR_HEXLEDS) != t) {
108f2711be0SManuel Lauss bcsr_write(BCSR_HEXLEDS, t);
1096f7c8623SManuel Lauss return 0;
110f2711be0SManuel Lauss }
111f2711be0SManuel Lauss }
1126f7c8623SManuel Lauss
113f2711be0SManuel Lauss return 1; /* it's neither */
1147c4b24daSManuel Lauss }
1157c4b24daSManuel Lauss
db1200_board_setup(void)116bd8510dfSManuel Lauss int __init db1200_board_setup(void)
1177c4b24daSManuel Lauss {
1187c4b24daSManuel Lauss unsigned short whoami;
1197c4b24daSManuel Lauss
120bd8510dfSManuel Lauss if (db1200_detect_board())
121bd8510dfSManuel Lauss return -ENODEV;
1227c4b24daSManuel Lauss
1237c4b24daSManuel Lauss whoami = bcsr_read(BCSR_WHOAMI);
124970e268dSManuel Lauss switch (BCSR_WHOAMI_BOARD(whoami)) {
125970e268dSManuel Lauss case BCSR_WHOAMI_PB1200_DDR1:
126970e268dSManuel Lauss case BCSR_WHOAMI_PB1200_DDR2:
127970e268dSManuel Lauss case BCSR_WHOAMI_DB1200:
128970e268dSManuel Lauss break;
129970e268dSManuel Lauss default:
130970e268dSManuel Lauss return -ENODEV;
131970e268dSManuel Lauss }
132970e268dSManuel Lauss
1336f7c8623SManuel Lauss printk(KERN_INFO "Alchemy/AMD/RMI %s Board, CPLD Rev %d"
134bd8510dfSManuel Lauss " Board-ID %d Daughtercard ID %d\n", get_system_type(),
1357c4b24daSManuel Lauss (whoami >> 4) & 0xf, (whoami >> 8) & 0xf, whoami & 0xf);
1367c4b24daSManuel Lauss
137bd8510dfSManuel Lauss return 0;
1387c4b24daSManuel Lauss }
1397c4b24daSManuel Lauss
1407c4b24daSManuel Lauss /******************************************************************************/
1417c4b24daSManuel Lauss
142994bc7faSManuel Lauss static u64 au1200_all_dmamask = DMA_BIT_MASK(32);
143994bc7faSManuel Lauss
1447c4b24daSManuel Lauss static struct mtd_partition db1200_spiflash_parts[] = {
1457c4b24daSManuel Lauss {
1466f7c8623SManuel Lauss .name = "spi_flash",
1477c4b24daSManuel Lauss .offset = 0,
1487c4b24daSManuel Lauss .size = MTDPART_SIZ_FULL,
1497c4b24daSManuel Lauss },
1507c4b24daSManuel Lauss };
1517c4b24daSManuel Lauss
1527c4b24daSManuel Lauss static struct flash_platform_data db1200_spiflash_data = {
1537c4b24daSManuel Lauss .name = "s25fl001",
1547c4b24daSManuel Lauss .parts = db1200_spiflash_parts,
1557c4b24daSManuel Lauss .nr_parts = ARRAY_SIZE(db1200_spiflash_parts),
1567c4b24daSManuel Lauss .type = "m25p10",
1577c4b24daSManuel Lauss };
1587c4b24daSManuel Lauss
1597c4b24daSManuel Lauss static struct spi_board_info db1200_spi_devs[] __initdata = {
1607c4b24daSManuel Lauss {
1617c4b24daSManuel Lauss /* TI TMP121AIDBVR temp sensor */
1627c4b24daSManuel Lauss .modalias = "tmp121",
1637c4b24daSManuel Lauss .max_speed_hz = 2000000,
1647c4b24daSManuel Lauss .bus_num = 0,
1657c4b24daSManuel Lauss .chip_select = 0,
1667c4b24daSManuel Lauss .mode = 0,
1677c4b24daSManuel Lauss },
1687c4b24daSManuel Lauss {
1697c4b24daSManuel Lauss /* Spansion S25FL001D0FMA SPI flash */
1707c4b24daSManuel Lauss .modalias = "m25p80",
1717c4b24daSManuel Lauss .max_speed_hz = 50000000,
1727c4b24daSManuel Lauss .bus_num = 0,
1737c4b24daSManuel Lauss .chip_select = 1,
1747c4b24daSManuel Lauss .mode = 0,
1757c4b24daSManuel Lauss .platform_data = &db1200_spiflash_data,
1767c4b24daSManuel Lauss },
1777c4b24daSManuel Lauss };
1787c4b24daSManuel Lauss
1797c4b24daSManuel Lauss static struct i2c_board_info db1200_i2c_devs[] __initdata = {
1807c4b24daSManuel Lauss { I2C_BOARD_INFO("24c04", 0x52), }, /* AT24C04-10 I2C eeprom */
1817c4b24daSManuel Lauss { I2C_BOARD_INFO("ne1619", 0x2d), }, /* adm1025-compat hwmon */
1827c4b24daSManuel Lauss { I2C_BOARD_INFO("wm8731", 0x1b), }, /* I2S audio codec WM8731 */
1837c4b24daSManuel Lauss };
1847c4b24daSManuel Lauss
1857c4b24daSManuel Lauss /**********************************************************************/
1867c4b24daSManuel Lauss
au1200_nand_cmd_ctrl(struct nand_chip * this,int cmd,unsigned int ctrl)18747bd59e5SBoris Brezillon static void au1200_nand_cmd_ctrl(struct nand_chip *this, int cmd,
1887c4b24daSManuel Lauss unsigned int ctrl)
1897c4b24daSManuel Lauss {
19082fc5099SBoris Brezillon unsigned long ioaddr = (unsigned long)this->legacy.IO_ADDR_W;
1917c4b24daSManuel Lauss
1927c4b24daSManuel Lauss ioaddr &= 0xffffff00;
1937c4b24daSManuel Lauss
1947c4b24daSManuel Lauss if (ctrl & NAND_CLE) {
1957c4b24daSManuel Lauss ioaddr += MEM_STNAND_CMD;
1967c4b24daSManuel Lauss } else if (ctrl & NAND_ALE) {
1977c4b24daSManuel Lauss ioaddr += MEM_STNAND_ADDR;
1987c4b24daSManuel Lauss } else {
1997c4b24daSManuel Lauss /* assume we want to r/w real data by default */
2007c4b24daSManuel Lauss ioaddr += MEM_STNAND_DATA;
2017c4b24daSManuel Lauss }
20282fc5099SBoris Brezillon this->legacy.IO_ADDR_R = this->legacy.IO_ADDR_W = (void __iomem *)ioaddr;
2037c4b24daSManuel Lauss if (cmd != NAND_CMD_NONE) {
20482fc5099SBoris Brezillon __raw_writeb(cmd, this->legacy.IO_ADDR_W);
2057c4b24daSManuel Lauss wmb();
2067c4b24daSManuel Lauss }
2077c4b24daSManuel Lauss }
2087c4b24daSManuel Lauss
au1200_nand_device_ready(struct nand_chip * this)20947bd59e5SBoris Brezillon static int au1200_nand_device_ready(struct nand_chip *this)
2107c4b24daSManuel Lauss {
2119cf12167SManuel Lauss return alchemy_rdsmem(AU1000_MEM_STSTAT) & 1;
2127c4b24daSManuel Lauss }
2137c4b24daSManuel Lauss
2147c4b24daSManuel Lauss static struct mtd_partition db1200_nand_parts[] = {
2157c4b24daSManuel Lauss {
2167c4b24daSManuel Lauss .name = "NAND FS 0",
2177c4b24daSManuel Lauss .offset = 0,
2187c4b24daSManuel Lauss .size = 8 * 1024 * 1024,
2197c4b24daSManuel Lauss },
2207c4b24daSManuel Lauss {
2217c4b24daSManuel Lauss .name = "NAND FS 1",
2227c4b24daSManuel Lauss .offset = MTDPART_OFS_APPEND,
2237c4b24daSManuel Lauss .size = MTDPART_SIZ_FULL
2247c4b24daSManuel Lauss },
2257c4b24daSManuel Lauss };
2267c4b24daSManuel Lauss
2277c4b24daSManuel Lauss struct platform_nand_data db1200_nand_platdata = {
2287c4b24daSManuel Lauss .chip = {
2297c4b24daSManuel Lauss .nr_chips = 1,
2307c4b24daSManuel Lauss .chip_offset = 0,
2317c4b24daSManuel Lauss .nr_partitions = ARRAY_SIZE(db1200_nand_parts),
2327c4b24daSManuel Lauss .partitions = db1200_nand_parts,
2337c4b24daSManuel Lauss .chip_delay = 20,
2347c4b24daSManuel Lauss },
2357c4b24daSManuel Lauss .ctrl = {
2367c4b24daSManuel Lauss .dev_ready = au1200_nand_device_ready,
2377c4b24daSManuel Lauss .cmd_ctrl = au1200_nand_cmd_ctrl,
2387c4b24daSManuel Lauss },
2397c4b24daSManuel Lauss };
2407c4b24daSManuel Lauss
2417c4b24daSManuel Lauss static struct resource db1200_nand_res[] = {
2427c4b24daSManuel Lauss [0] = {
2437c4b24daSManuel Lauss .start = DB1200_NAND_PHYS_ADDR,
2447c4b24daSManuel Lauss .end = DB1200_NAND_PHYS_ADDR + 0xff,
2457c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
2467c4b24daSManuel Lauss },
2477c4b24daSManuel Lauss };
2487c4b24daSManuel Lauss
2497c4b24daSManuel Lauss static struct platform_device db1200_nand_dev = {
2507c4b24daSManuel Lauss .name = "gen_nand",
2517c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(db1200_nand_res),
2527c4b24daSManuel Lauss .resource = db1200_nand_res,
2537c4b24daSManuel Lauss .id = -1,
2547c4b24daSManuel Lauss .dev = {
2557c4b24daSManuel Lauss .platform_data = &db1200_nand_platdata,
2567c4b24daSManuel Lauss }
2577c4b24daSManuel Lauss };
2587c4b24daSManuel Lauss
2597c4b24daSManuel Lauss /**********************************************************************/
2607c4b24daSManuel Lauss
2617c4b24daSManuel Lauss static struct smc91x_platdata db1200_eth_data = {
2627c4b24daSManuel Lauss .flags = SMC91X_NOWAIT | SMC91X_USE_16BIT,
2637c4b24daSManuel Lauss .leda = RPC_LED_100_10,
2647c4b24daSManuel Lauss .ledb = RPC_LED_TX_RX,
2657c4b24daSManuel Lauss };
2667c4b24daSManuel Lauss
2677c4b24daSManuel Lauss static struct resource db1200_eth_res[] = {
2687c4b24daSManuel Lauss [0] = {
2697c4b24daSManuel Lauss .start = DB1200_ETH_PHYS_ADDR,
2707c4b24daSManuel Lauss .end = DB1200_ETH_PHYS_ADDR + 0xf,
2717c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
2727c4b24daSManuel Lauss },
2737c4b24daSManuel Lauss [1] = {
2747c4b24daSManuel Lauss .start = DB1200_ETH_INT,
2757c4b24daSManuel Lauss .end = DB1200_ETH_INT,
2767c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
2777c4b24daSManuel Lauss },
2787c4b24daSManuel Lauss };
2797c4b24daSManuel Lauss
2807c4b24daSManuel Lauss static struct platform_device db1200_eth_dev = {
2817c4b24daSManuel Lauss .dev = {
2827c4b24daSManuel Lauss .platform_data = &db1200_eth_data,
2837c4b24daSManuel Lauss },
2847c4b24daSManuel Lauss .name = "smc91x",
2857c4b24daSManuel Lauss .id = -1,
2867c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(db1200_eth_res),
2877c4b24daSManuel Lauss .resource = db1200_eth_res,
2887c4b24daSManuel Lauss };
2897c4b24daSManuel Lauss
2907c4b24daSManuel Lauss /**********************************************************************/
2917c4b24daSManuel Lauss
29254ff4a1dSManuel Lauss static struct pata_platform_info db1200_ide_info = {
29354ff4a1dSManuel Lauss .ioport_shift = DB1200_IDE_REG_SHIFT,
29454ff4a1dSManuel Lauss };
29554ff4a1dSManuel Lauss
29654ff4a1dSManuel Lauss #define IDE_ALT_START (14 << DB1200_IDE_REG_SHIFT)
2977c4b24daSManuel Lauss static struct resource db1200_ide_res[] = {
2987c4b24daSManuel Lauss [0] = {
2997c4b24daSManuel Lauss .start = DB1200_IDE_PHYS_ADDR,
30054ff4a1dSManuel Lauss .end = DB1200_IDE_PHYS_ADDR + IDE_ALT_START - 1,
3017c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
3027c4b24daSManuel Lauss },
3037c4b24daSManuel Lauss [1] = {
30454ff4a1dSManuel Lauss .start = DB1200_IDE_PHYS_ADDR + IDE_ALT_START,
30554ff4a1dSManuel Lauss .end = DB1200_IDE_PHYS_ADDR + DB1200_IDE_PHYS_LEN - 1,
30654ff4a1dSManuel Lauss .flags = IORESOURCE_MEM,
30754ff4a1dSManuel Lauss },
30854ff4a1dSManuel Lauss [2] = {
3097c4b24daSManuel Lauss .start = DB1200_IDE_INT,
3107c4b24daSManuel Lauss .end = DB1200_IDE_INT,
3117c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
3127c4b24daSManuel Lauss },
3137c4b24daSManuel Lauss };
3147c4b24daSManuel Lauss
3157c4b24daSManuel Lauss static struct platform_device db1200_ide_dev = {
31654ff4a1dSManuel Lauss .name = "pata_platform",
3177c4b24daSManuel Lauss .id = 0,
3187c4b24daSManuel Lauss .dev = {
319994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
3207c4b24daSManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
32154ff4a1dSManuel Lauss .platform_data = &db1200_ide_info,
3227c4b24daSManuel Lauss },
3237c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(db1200_ide_res),
3247c4b24daSManuel Lauss .resource = db1200_ide_res,
3257c4b24daSManuel Lauss };
3267c4b24daSManuel Lauss
3277c4b24daSManuel Lauss /**********************************************************************/
3287c4b24daSManuel Lauss
329ef8f8f04SChristoph Hellwig #ifdef CONFIG_MMC_AU1X
3307c4b24daSManuel Lauss /* SD carddetects: they're supposed to be edge-triggered, but ack
3317c4b24daSManuel Lauss * doesn't seem to work (CPLD Rev 2). Instead, the screaming one
332cc10815eSManuel Lauss * is disabled and its counterpart enabled. The 200ms timeout is
333cc10815eSManuel Lauss * because the carddetect usually triggers twice, after debounce.
3347c4b24daSManuel Lauss */
db1200_mmc_cd(int irq,void * ptr)3357c4b24daSManuel Lauss static irqreturn_t db1200_mmc_cd(int irq, void *ptr)
3367c4b24daSManuel Lauss {
337cc10815eSManuel Lauss disable_irq_nosync(irq);
338cc10815eSManuel Lauss return IRQ_WAKE_THREAD;
3397c4b24daSManuel Lauss }
3407c4b24daSManuel Lauss
db1200_mmc_cdfn(int irq,void * ptr)341cc10815eSManuel Lauss static irqreturn_t db1200_mmc_cdfn(int irq, void *ptr)
342cc10815eSManuel Lauss {
343d4a5c59aSChristoph Hellwig mmc_detect_change(ptr, msecs_to_jiffies(200));
3447c4b24daSManuel Lauss
345cc10815eSManuel Lauss msleep(100); /* debounce */
346cc10815eSManuel Lauss if (irq == DB1200_SD0_INSERT_INT)
347cc10815eSManuel Lauss enable_irq(DB1200_SD0_EJECT_INT);
348cc10815eSManuel Lauss else
349cc10815eSManuel Lauss enable_irq(DB1200_SD0_INSERT_INT);
350cc10815eSManuel Lauss
3517c4b24daSManuel Lauss return IRQ_HANDLED;
3527c4b24daSManuel Lauss }
3537c4b24daSManuel Lauss
db1200_mmc_cd_setup(void * mmc_host,int en)3547c4b24daSManuel Lauss static int db1200_mmc_cd_setup(void *mmc_host, int en)
3557c4b24daSManuel Lauss {
3567c4b24daSManuel Lauss int ret;
3577c4b24daSManuel Lauss
3587c4b24daSManuel Lauss if (en) {
359cc10815eSManuel Lauss ret = request_threaded_irq(DB1200_SD0_INSERT_INT, db1200_mmc_cd,
360cc10815eSManuel Lauss db1200_mmc_cdfn, 0, "sd_insert", mmc_host);
3617c4b24daSManuel Lauss if (ret)
3627c4b24daSManuel Lauss goto out;
3637c4b24daSManuel Lauss
364cc10815eSManuel Lauss ret = request_threaded_irq(DB1200_SD0_EJECT_INT, db1200_mmc_cd,
365cc10815eSManuel Lauss db1200_mmc_cdfn, 0, "sd_eject", mmc_host);
3667c4b24daSManuel Lauss if (ret) {
3677c4b24daSManuel Lauss free_irq(DB1200_SD0_INSERT_INT, mmc_host);
3687c4b24daSManuel Lauss goto out;
3697c4b24daSManuel Lauss }
3707c4b24daSManuel Lauss
3717c4b24daSManuel Lauss if (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT)
3727c4b24daSManuel Lauss enable_irq(DB1200_SD0_EJECT_INT);
3737c4b24daSManuel Lauss else
3747c4b24daSManuel Lauss enable_irq(DB1200_SD0_INSERT_INT);
3757c4b24daSManuel Lauss
3767c4b24daSManuel Lauss } else {
3777c4b24daSManuel Lauss free_irq(DB1200_SD0_INSERT_INT, mmc_host);
3787c4b24daSManuel Lauss free_irq(DB1200_SD0_EJECT_INT, mmc_host);
3797c4b24daSManuel Lauss }
3807c4b24daSManuel Lauss ret = 0;
3817c4b24daSManuel Lauss out:
3827c4b24daSManuel Lauss return ret;
3837c4b24daSManuel Lauss }
3847c4b24daSManuel Lauss
db1200_mmc_set_power(void * mmc_host,int state)3857c4b24daSManuel Lauss static void db1200_mmc_set_power(void *mmc_host, int state)
3867c4b24daSManuel Lauss {
3877c4b24daSManuel Lauss if (state) {
3887c4b24daSManuel Lauss bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD0PWR);
3897c4b24daSManuel Lauss msleep(400); /* stabilization time */
3907c4b24daSManuel Lauss } else
3917c4b24daSManuel Lauss bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD0PWR, 0);
3927c4b24daSManuel Lauss }
3937c4b24daSManuel Lauss
db1200_mmc_card_readonly(void * mmc_host)3947c4b24daSManuel Lauss static int db1200_mmc_card_readonly(void *mmc_host)
3957c4b24daSManuel Lauss {
3967c4b24daSManuel Lauss return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 1 : 0;
3977c4b24daSManuel Lauss }
3987c4b24daSManuel Lauss
db1200_mmc_card_inserted(void * mmc_host)3997c4b24daSManuel Lauss static int db1200_mmc_card_inserted(void *mmc_host)
4007c4b24daSManuel Lauss {
4017c4b24daSManuel Lauss return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT) ? 1 : 0;
4027c4b24daSManuel Lauss }
4037c4b24daSManuel Lauss
db1200_mmcled_set(struct led_classdev * led,enum led_brightness brightness)4047c4b24daSManuel Lauss static void db1200_mmcled_set(struct led_classdev *led,
4057c4b24daSManuel Lauss enum led_brightness brightness)
4067c4b24daSManuel Lauss {
4077c4b24daSManuel Lauss if (brightness != LED_OFF)
4087c4b24daSManuel Lauss bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
4097c4b24daSManuel Lauss else
4107c4b24daSManuel Lauss bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
4117c4b24daSManuel Lauss }
4127c4b24daSManuel Lauss
4137c4b24daSManuel Lauss static struct led_classdev db1200_mmc_led = {
4147c4b24daSManuel Lauss .brightness_set = db1200_mmcled_set,
4157c4b24daSManuel Lauss };
4167c4b24daSManuel Lauss
4176f7c8623SManuel Lauss /* -- */
4186f7c8623SManuel Lauss
pb1200_mmc1_cd(int irq,void * ptr)4196f7c8623SManuel Lauss static irqreturn_t pb1200_mmc1_cd(int irq, void *ptr)
4206f7c8623SManuel Lauss {
421cc10815eSManuel Lauss disable_irq_nosync(irq);
422cc10815eSManuel Lauss return IRQ_WAKE_THREAD;
4236f7c8623SManuel Lauss }
4246f7c8623SManuel Lauss
pb1200_mmc1_cdfn(int irq,void * ptr)425cc10815eSManuel Lauss static irqreturn_t pb1200_mmc1_cdfn(int irq, void *ptr)
426cc10815eSManuel Lauss {
427d4a5c59aSChristoph Hellwig mmc_detect_change(ptr, msecs_to_jiffies(200));
4286f7c8623SManuel Lauss
429cc10815eSManuel Lauss msleep(100); /* debounce */
430cc10815eSManuel Lauss if (irq == PB1200_SD1_INSERT_INT)
431cc10815eSManuel Lauss enable_irq(PB1200_SD1_EJECT_INT);
432cc10815eSManuel Lauss else
433cc10815eSManuel Lauss enable_irq(PB1200_SD1_INSERT_INT);
434cc10815eSManuel Lauss
4356f7c8623SManuel Lauss return IRQ_HANDLED;
4366f7c8623SManuel Lauss }
4376f7c8623SManuel Lauss
pb1200_mmc1_cd_setup(void * mmc_host,int en)4386f7c8623SManuel Lauss static int pb1200_mmc1_cd_setup(void *mmc_host, int en)
4396f7c8623SManuel Lauss {
4406f7c8623SManuel Lauss int ret;
4416f7c8623SManuel Lauss
4426f7c8623SManuel Lauss if (en) {
443cc10815eSManuel Lauss ret = request_threaded_irq(PB1200_SD1_INSERT_INT, pb1200_mmc1_cd,
444cc10815eSManuel Lauss pb1200_mmc1_cdfn, 0, "sd1_insert", mmc_host);
4456f7c8623SManuel Lauss if (ret)
4466f7c8623SManuel Lauss goto out;
4476f7c8623SManuel Lauss
448cc10815eSManuel Lauss ret = request_threaded_irq(PB1200_SD1_EJECT_INT, pb1200_mmc1_cd,
449cc10815eSManuel Lauss pb1200_mmc1_cdfn, 0, "sd1_eject", mmc_host);
4506f7c8623SManuel Lauss if (ret) {
4516f7c8623SManuel Lauss free_irq(PB1200_SD1_INSERT_INT, mmc_host);
4526f7c8623SManuel Lauss goto out;
4536f7c8623SManuel Lauss }
4546f7c8623SManuel Lauss
4556f7c8623SManuel Lauss if (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT)
4566f7c8623SManuel Lauss enable_irq(PB1200_SD1_EJECT_INT);
4576f7c8623SManuel Lauss else
4586f7c8623SManuel Lauss enable_irq(PB1200_SD1_INSERT_INT);
4596f7c8623SManuel Lauss
4606f7c8623SManuel Lauss } else {
4616f7c8623SManuel Lauss free_irq(PB1200_SD1_INSERT_INT, mmc_host);
4626f7c8623SManuel Lauss free_irq(PB1200_SD1_EJECT_INT, mmc_host);
4636f7c8623SManuel Lauss }
4646f7c8623SManuel Lauss ret = 0;
4656f7c8623SManuel Lauss out:
4666f7c8623SManuel Lauss return ret;
4676f7c8623SManuel Lauss }
4686f7c8623SManuel Lauss
pb1200_mmc1led_set(struct led_classdev * led,enum led_brightness brightness)4696f7c8623SManuel Lauss static void pb1200_mmc1led_set(struct led_classdev *led,
4706f7c8623SManuel Lauss enum led_brightness brightness)
4716f7c8623SManuel Lauss {
4726f7c8623SManuel Lauss if (brightness != LED_OFF)
4736f7c8623SManuel Lauss bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0);
4746f7c8623SManuel Lauss else
4756f7c8623SManuel Lauss bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1);
4766f7c8623SManuel Lauss }
4776f7c8623SManuel Lauss
4786f7c8623SManuel Lauss static struct led_classdev pb1200_mmc1_led = {
4796f7c8623SManuel Lauss .brightness_set = pb1200_mmc1led_set,
4806f7c8623SManuel Lauss };
4816f7c8623SManuel Lauss
pb1200_mmc1_set_power(void * mmc_host,int state)4826f7c8623SManuel Lauss static void pb1200_mmc1_set_power(void *mmc_host, int state)
4836f7c8623SManuel Lauss {
4846f7c8623SManuel Lauss if (state) {
4856f7c8623SManuel Lauss bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD1PWR);
4866f7c8623SManuel Lauss msleep(400); /* stabilization time */
4876f7c8623SManuel Lauss } else
4886f7c8623SManuel Lauss bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD1PWR, 0);
4896f7c8623SManuel Lauss }
4906f7c8623SManuel Lauss
pb1200_mmc1_card_readonly(void * mmc_host)4916f7c8623SManuel Lauss static int pb1200_mmc1_card_readonly(void *mmc_host)
4926f7c8623SManuel Lauss {
4936f7c8623SManuel Lauss return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD1WP) ? 1 : 0;
4946f7c8623SManuel Lauss }
4956f7c8623SManuel Lauss
pb1200_mmc1_card_inserted(void * mmc_host)4966f7c8623SManuel Lauss static int pb1200_mmc1_card_inserted(void *mmc_host)
4976f7c8623SManuel Lauss {
4986f7c8623SManuel Lauss return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD1INSERT) ? 1 : 0;
4996f7c8623SManuel Lauss }
5006f7c8623SManuel Lauss
5016f7c8623SManuel Lauss
5026f7c8623SManuel Lauss static struct au1xmmc_platform_data db1200_mmc_platdata[2] = {
5036f7c8623SManuel Lauss [0] = {
5047c4b24daSManuel Lauss .cd_setup = db1200_mmc_cd_setup,
5057c4b24daSManuel Lauss .set_power = db1200_mmc_set_power,
5067c4b24daSManuel Lauss .card_inserted = db1200_mmc_card_inserted,
5077c4b24daSManuel Lauss .card_readonly = db1200_mmc_card_readonly,
5087c4b24daSManuel Lauss .led = &db1200_mmc_led,
5096f7c8623SManuel Lauss },
5106f7c8623SManuel Lauss [1] = {
5116f7c8623SManuel Lauss .cd_setup = pb1200_mmc1_cd_setup,
5126f7c8623SManuel Lauss .set_power = pb1200_mmc1_set_power,
5136f7c8623SManuel Lauss .card_inserted = pb1200_mmc1_card_inserted,
5146f7c8623SManuel Lauss .card_readonly = pb1200_mmc1_card_readonly,
5156f7c8623SManuel Lauss .led = &pb1200_mmc1_led,
5166f7c8623SManuel Lauss },
5177c4b24daSManuel Lauss };
5187c4b24daSManuel Lauss
5197c4b24daSManuel Lauss static struct resource au1200_mmc0_resources[] = {
5207c4b24daSManuel Lauss [0] = {
5217c4b24daSManuel Lauss .start = AU1100_SD0_PHYS_ADDR,
5227c4b24daSManuel Lauss .end = AU1100_SD0_PHYS_ADDR + 0xfff,
5237c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
5247c4b24daSManuel Lauss },
5257c4b24daSManuel Lauss [1] = {
5267c4b24daSManuel Lauss .start = AU1200_SD_INT,
5277c4b24daSManuel Lauss .end = AU1200_SD_INT,
5287c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
5297c4b24daSManuel Lauss },
5307c4b24daSManuel Lauss [2] = {
5317c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_SDMS_TX0,
5327c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_SDMS_TX0,
5337c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
5347c4b24daSManuel Lauss },
5357c4b24daSManuel Lauss [3] = {
5367c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_SDMS_RX0,
5377c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_SDMS_RX0,
5387c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
5397c4b24daSManuel Lauss }
5407c4b24daSManuel Lauss };
5417c4b24daSManuel Lauss
5427c4b24daSManuel Lauss static struct platform_device db1200_mmc0_dev = {
5437c4b24daSManuel Lauss .name = "au1xxx-mmc",
5447c4b24daSManuel Lauss .id = 0,
5457c4b24daSManuel Lauss .dev = {
546994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
5477c4b24daSManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
5486f7c8623SManuel Lauss .platform_data = &db1200_mmc_platdata[0],
5497c4b24daSManuel Lauss },
5507c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(au1200_mmc0_resources),
5517c4b24daSManuel Lauss .resource = au1200_mmc0_resources,
5527c4b24daSManuel Lauss };
5537c4b24daSManuel Lauss
5546f7c8623SManuel Lauss static struct resource au1200_mmc1_res[] = {
5556f7c8623SManuel Lauss [0] = {
5566f7c8623SManuel Lauss .start = AU1100_SD1_PHYS_ADDR,
5576f7c8623SManuel Lauss .end = AU1100_SD1_PHYS_ADDR + 0xfff,
5586f7c8623SManuel Lauss .flags = IORESOURCE_MEM,
5596f7c8623SManuel Lauss },
5606f7c8623SManuel Lauss [1] = {
5616f7c8623SManuel Lauss .start = AU1200_SD_INT,
5626f7c8623SManuel Lauss .end = AU1200_SD_INT,
5636f7c8623SManuel Lauss .flags = IORESOURCE_IRQ,
5646f7c8623SManuel Lauss },
5656f7c8623SManuel Lauss [2] = {
5666f7c8623SManuel Lauss .start = AU1200_DSCR_CMD0_SDMS_TX1,
5676f7c8623SManuel Lauss .end = AU1200_DSCR_CMD0_SDMS_TX1,
5686f7c8623SManuel Lauss .flags = IORESOURCE_DMA,
5696f7c8623SManuel Lauss },
5706f7c8623SManuel Lauss [3] = {
5716f7c8623SManuel Lauss .start = AU1200_DSCR_CMD0_SDMS_RX1,
5726f7c8623SManuel Lauss .end = AU1200_DSCR_CMD0_SDMS_RX1,
5736f7c8623SManuel Lauss .flags = IORESOURCE_DMA,
5746f7c8623SManuel Lauss }
5756f7c8623SManuel Lauss };
5766f7c8623SManuel Lauss
5776f7c8623SManuel Lauss static struct platform_device pb1200_mmc1_dev = {
5786f7c8623SManuel Lauss .name = "au1xxx-mmc",
5796f7c8623SManuel Lauss .id = 1,
5806f7c8623SManuel Lauss .dev = {
581994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
5826f7c8623SManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
5836f7c8623SManuel Lauss .platform_data = &db1200_mmc_platdata[1],
5846f7c8623SManuel Lauss },
5856f7c8623SManuel Lauss .num_resources = ARRAY_SIZE(au1200_mmc1_res),
5866f7c8623SManuel Lauss .resource = au1200_mmc1_res,
5876f7c8623SManuel Lauss };
588ef8f8f04SChristoph Hellwig #endif /* CONFIG_MMC_AU1X */
5896f7c8623SManuel Lauss
5907c4b24daSManuel Lauss /**********************************************************************/
5917c4b24daSManuel Lauss
db1200fb_panel_index(void)592a9b71a8fSManuel Lauss static int db1200fb_panel_index(void)
593a9b71a8fSManuel Lauss {
594a9b71a8fSManuel Lauss return (bcsr_read(BCSR_SWITCHES) >> 8) & 0x0f;
595a9b71a8fSManuel Lauss }
596a9b71a8fSManuel Lauss
db1200fb_panel_init(void)597a9b71a8fSManuel Lauss static int db1200fb_panel_init(void)
598a9b71a8fSManuel Lauss {
599a9b71a8fSManuel Lauss /* Apply power */
600a9b71a8fSManuel Lauss bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
601a9b71a8fSManuel Lauss BCSR_BOARD_LCDBL);
602a9b71a8fSManuel Lauss return 0;
603a9b71a8fSManuel Lauss }
604a9b71a8fSManuel Lauss
db1200fb_panel_shutdown(void)605a9b71a8fSManuel Lauss static int db1200fb_panel_shutdown(void)
606a9b71a8fSManuel Lauss {
607a9b71a8fSManuel Lauss /* Remove power */
608a9b71a8fSManuel Lauss bcsr_mod(BCSR_BOARD, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
609a9b71a8fSManuel Lauss BCSR_BOARD_LCDBL, 0);
610a9b71a8fSManuel Lauss return 0;
611a9b71a8fSManuel Lauss }
612a9b71a8fSManuel Lauss
613a9b71a8fSManuel Lauss static struct au1200fb_platdata db1200fb_pd = {
614a9b71a8fSManuel Lauss .panel_index = db1200fb_panel_index,
615a9b71a8fSManuel Lauss .panel_init = db1200fb_panel_init,
616a9b71a8fSManuel Lauss .panel_shutdown = db1200fb_panel_shutdown,
617a9b71a8fSManuel Lauss };
618a9b71a8fSManuel Lauss
6197c4b24daSManuel Lauss static struct resource au1200_lcd_res[] = {
6207c4b24daSManuel Lauss [0] = {
6217c4b24daSManuel Lauss .start = AU1200_LCD_PHYS_ADDR,
6227c4b24daSManuel Lauss .end = AU1200_LCD_PHYS_ADDR + 0x800 - 1,
6237c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
6247c4b24daSManuel Lauss },
6257c4b24daSManuel Lauss [1] = {
6267c4b24daSManuel Lauss .start = AU1200_LCD_INT,
6277c4b24daSManuel Lauss .end = AU1200_LCD_INT,
6287c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
6297c4b24daSManuel Lauss }
6307c4b24daSManuel Lauss };
6317c4b24daSManuel Lauss
6327c4b24daSManuel Lauss static struct platform_device au1200_lcd_dev = {
6337c4b24daSManuel Lauss .name = "au1200-lcd",
6347c4b24daSManuel Lauss .id = 0,
6357c4b24daSManuel Lauss .dev = {
636994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
6377c4b24daSManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
638a9b71a8fSManuel Lauss .platform_data = &db1200fb_pd,
6397c4b24daSManuel Lauss },
6407c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(au1200_lcd_res),
6417c4b24daSManuel Lauss .resource = au1200_lcd_res,
6427c4b24daSManuel Lauss };
6437c4b24daSManuel Lauss
6447c4b24daSManuel Lauss /**********************************************************************/
6457c4b24daSManuel Lauss
6467c4b24daSManuel Lauss static struct resource au1200_psc0_res[] = {
6477c4b24daSManuel Lauss [0] = {
6487c4b24daSManuel Lauss .start = AU1550_PSC0_PHYS_ADDR,
6497c4b24daSManuel Lauss .end = AU1550_PSC0_PHYS_ADDR + 0xfff,
6507c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
6517c4b24daSManuel Lauss },
6527c4b24daSManuel Lauss [1] = {
6537c4b24daSManuel Lauss .start = AU1200_PSC0_INT,
6547c4b24daSManuel Lauss .end = AU1200_PSC0_INT,
6557c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
6567c4b24daSManuel Lauss },
6577c4b24daSManuel Lauss [2] = {
6587c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_PSC0_TX,
6597c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_PSC0_TX,
6607c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
6617c4b24daSManuel Lauss },
6627c4b24daSManuel Lauss [3] = {
6637c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_PSC0_RX,
6647c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_PSC0_RX,
6657c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
6667c4b24daSManuel Lauss },
6677c4b24daSManuel Lauss };
6687c4b24daSManuel Lauss
6697c4b24daSManuel Lauss static struct platform_device db1200_i2c_dev = {
6707c4b24daSManuel Lauss .name = "au1xpsc_smbus",
6717c4b24daSManuel Lauss .id = 0, /* bus number */
6727c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(au1200_psc0_res),
6737c4b24daSManuel Lauss .resource = au1200_psc0_res,
6747c4b24daSManuel Lauss };
6757c4b24daSManuel Lauss
db1200_spi_cs_en(struct au1550_spi_info * spi,int cs,int pol)6767c4b24daSManuel Lauss static void db1200_spi_cs_en(struct au1550_spi_info *spi, int cs, int pol)
6777c4b24daSManuel Lauss {
6787c4b24daSManuel Lauss if (cs)
6797c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_SPISEL);
6807c4b24daSManuel Lauss else
6817c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, BCSR_RESETS_SPISEL, 0);
6827c4b24daSManuel Lauss }
6837c4b24daSManuel Lauss
6847c4b24daSManuel Lauss static struct au1550_spi_info db1200_spi_platdata = {
6857c4b24daSManuel Lauss .mainclk_hz = 50000000, /* PSC0 clock */
6867c4b24daSManuel Lauss .num_chipselect = 2,
6877c4b24daSManuel Lauss .activate_cs = db1200_spi_cs_en,
6887c4b24daSManuel Lauss };
6897c4b24daSManuel Lauss
6907c4b24daSManuel Lauss static struct platform_device db1200_spi_dev = {
6917c4b24daSManuel Lauss .dev = {
692994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
6937c4b24daSManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
6947c4b24daSManuel Lauss .platform_data = &db1200_spi_platdata,
6957c4b24daSManuel Lauss },
6967c4b24daSManuel Lauss .name = "au1550-spi",
6977c4b24daSManuel Lauss .id = 0, /* bus number */
6987c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(au1200_psc0_res),
6997c4b24daSManuel Lauss .resource = au1200_psc0_res,
7007c4b24daSManuel Lauss };
7017c4b24daSManuel Lauss
7027c4b24daSManuel Lauss static struct resource au1200_psc1_res[] = {
7037c4b24daSManuel Lauss [0] = {
7047c4b24daSManuel Lauss .start = AU1550_PSC1_PHYS_ADDR,
7057c4b24daSManuel Lauss .end = AU1550_PSC1_PHYS_ADDR + 0xfff,
7067c4b24daSManuel Lauss .flags = IORESOURCE_MEM,
7077c4b24daSManuel Lauss },
7087c4b24daSManuel Lauss [1] = {
7097c4b24daSManuel Lauss .start = AU1200_PSC1_INT,
7107c4b24daSManuel Lauss .end = AU1200_PSC1_INT,
7117c4b24daSManuel Lauss .flags = IORESOURCE_IRQ,
7127c4b24daSManuel Lauss },
7137c4b24daSManuel Lauss [2] = {
7147c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_PSC1_TX,
7157c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_PSC1_TX,
7167c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
7177c4b24daSManuel Lauss },
7187c4b24daSManuel Lauss [3] = {
7197c4b24daSManuel Lauss .start = AU1200_DSCR_CMD0_PSC1_RX,
7207c4b24daSManuel Lauss .end = AU1200_DSCR_CMD0_PSC1_RX,
7217c4b24daSManuel Lauss .flags = IORESOURCE_DMA,
7227c4b24daSManuel Lauss },
7237c4b24daSManuel Lauss };
7247c4b24daSManuel Lauss
7257c4b24daSManuel Lauss /* AC97 or I2S device */
7267c4b24daSManuel Lauss static struct platform_device db1200_audio_dev = {
7277c4b24daSManuel Lauss /* name assigned later based on switch setting */
7287c4b24daSManuel Lauss .id = 1, /* PSC ID */
7297c4b24daSManuel Lauss .num_resources = ARRAY_SIZE(au1200_psc1_res),
7307c4b24daSManuel Lauss .resource = au1200_psc1_res,
7317c4b24daSManuel Lauss };
7327c4b24daSManuel Lauss
7337c4b24daSManuel Lauss /* DB1200 ASoC card device */
7347c4b24daSManuel Lauss static struct platform_device db1200_sound_dev = {
7357c4b24daSManuel Lauss /* name assigned later based on switch setting */
7367c4b24daSManuel Lauss .id = 1, /* PSC ID */
737994bc7faSManuel Lauss .dev = {
738994bc7faSManuel Lauss .dma_mask = &au1200_all_dmamask,
739994bc7faSManuel Lauss .coherent_dma_mask = DMA_BIT_MASK(32),
740994bc7faSManuel Lauss },
7417c4b24daSManuel Lauss };
7427c4b24daSManuel Lauss
7437c4b24daSManuel Lauss static struct platform_device db1200_stac_dev = {
7447c4b24daSManuel Lauss .name = "ac97-codec",
7457c4b24daSManuel Lauss .id = 1, /* on PSC1 */
7467c4b24daSManuel Lauss };
7477c4b24daSManuel Lauss
7487c4b24daSManuel Lauss static struct platform_device db1200_audiodma_dev = {
7497c4b24daSManuel Lauss .name = "au1xpsc-pcm",
7507c4b24daSManuel Lauss .id = 1, /* PSC ID */
7517c4b24daSManuel Lauss };
7527c4b24daSManuel Lauss
7537c4b24daSManuel Lauss static struct platform_device *db1200_devs[] __initdata = {
7547c4b24daSManuel Lauss NULL, /* PSC0, selected by S6.8 */
7557c4b24daSManuel Lauss &db1200_ide_dev,
756ef8f8f04SChristoph Hellwig #ifdef CONFIG_MMC_AU1X
7577c4b24daSManuel Lauss &db1200_mmc0_dev,
758ef8f8f04SChristoph Hellwig #endif
7597c4b24daSManuel Lauss &au1200_lcd_dev,
7607c4b24daSManuel Lauss &db1200_eth_dev,
7617c4b24daSManuel Lauss &db1200_nand_dev,
7627c4b24daSManuel Lauss &db1200_audiodma_dev,
7637c4b24daSManuel Lauss &db1200_audio_dev,
7647c4b24daSManuel Lauss &db1200_stac_dev,
7657c4b24daSManuel Lauss &db1200_sound_dev,
7667c4b24daSManuel Lauss };
7677c4b24daSManuel Lauss
7686f7c8623SManuel Lauss static struct platform_device *pb1200_devs[] __initdata = {
769ef8f8f04SChristoph Hellwig #ifdef CONFIG_MMC_AU1X
7706f7c8623SManuel Lauss &pb1200_mmc1_dev,
771ef8f8f04SChristoph Hellwig #endif
7726f7c8623SManuel Lauss };
7736f7c8623SManuel Lauss
7746f7c8623SManuel Lauss /* Some peripheral base addresses differ on the PB1200 */
pb1200_res_fixup(void)7756f7c8623SManuel Lauss static int __init pb1200_res_fixup(void)
7766f7c8623SManuel Lauss {
7776f7c8623SManuel Lauss /* CPLD Revs earlier than 4 cause problems */
7786f7c8623SManuel Lauss if (BCSR_WHOAMI_CPLD(bcsr_read(BCSR_WHOAMI)) <= 3) {
7796f7c8623SManuel Lauss printk(KERN_ERR "WARNING!!!\n");
7806f7c8623SManuel Lauss printk(KERN_ERR "WARNING!!!\n");
7816f7c8623SManuel Lauss printk(KERN_ERR "PB1200 must be at CPLD rev 4. Please have\n");
7826f7c8623SManuel Lauss printk(KERN_ERR "the board updated to latest revisions.\n");
7836f7c8623SManuel Lauss printk(KERN_ERR "This software will not work reliably\n");
7846f7c8623SManuel Lauss printk(KERN_ERR "on anything older than CPLD rev 4.!\n");
7856f7c8623SManuel Lauss printk(KERN_ERR "WARNING!!!\n");
7866f7c8623SManuel Lauss printk(KERN_ERR "WARNING!!!\n");
7876f7c8623SManuel Lauss return 1;
7886f7c8623SManuel Lauss }
7896f7c8623SManuel Lauss
7906f7c8623SManuel Lauss db1200_nand_res[0].start = PB1200_NAND_PHYS_ADDR;
7916f7c8623SManuel Lauss db1200_nand_res[0].end = PB1200_NAND_PHYS_ADDR + 0xff;
7926f7c8623SManuel Lauss db1200_ide_res[0].start = PB1200_IDE_PHYS_ADDR;
7936f7c8623SManuel Lauss db1200_ide_res[0].end = PB1200_IDE_PHYS_ADDR + DB1200_IDE_PHYS_LEN - 1;
7946f7c8623SManuel Lauss db1200_eth_res[0].start = PB1200_ETH_PHYS_ADDR;
7956f7c8623SManuel Lauss db1200_eth_res[0].end = PB1200_ETH_PHYS_ADDR + 0xff;
7966f7c8623SManuel Lauss return 0;
7976f7c8623SManuel Lauss }
7986f7c8623SManuel Lauss
db1200_dev_setup(void)799bd8510dfSManuel Lauss int __init db1200_dev_setup(void)
8007c4b24daSManuel Lauss {
8017c4b24daSManuel Lauss unsigned long pfc;
8027c4b24daSManuel Lauss unsigned short sw;
8036f7c8623SManuel Lauss int swapped, bid;
804415e0fecSManuel Lauss struct clk *c;
8056f7c8623SManuel Lauss
8066f7c8623SManuel Lauss bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
8076f7c8623SManuel Lauss if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
8086f7c8623SManuel Lauss (bid == BCSR_WHOAMI_PB1200_DDR2)) {
8096f7c8623SManuel Lauss if (pb1200_res_fixup())
8106f7c8623SManuel Lauss return -ENODEV;
8116f7c8623SManuel Lauss }
8127c4b24daSManuel Lauss
8137c4b24daSManuel Lauss /* GPIO7 is low-level triggered CPLD cascade */
8146f7c8623SManuel Lauss irq_set_irq_type(AU1200_GPIO7_INT, IRQ_TYPE_LEVEL_LOW);
8157c4b24daSManuel Lauss bcsr_init_irq(DB1200_INT_BEGIN, DB1200_INT_END, AU1200_GPIO7_INT);
8167c4b24daSManuel Lauss
817415e0fecSManuel Lauss /* SMBus/SPI on PSC0, Audio on PSC1 */
818415e0fecSManuel Lauss pfc = alchemy_rdsys(AU1000_SYS_PINFUNC);
819415e0fecSManuel Lauss pfc &= ~(SYS_PINFUNC_P0A | SYS_PINFUNC_P0B);
820415e0fecSManuel Lauss pfc &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B | SYS_PINFUNC_FS3);
821415e0fecSManuel Lauss pfc |= SYS_PINFUNC_P1C; /* SPI is configured later */
822415e0fecSManuel Lauss alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
823415e0fecSManuel Lauss
824415e0fecSManuel Lauss /* get 50MHz for I2C driver on PSC0 */
825415e0fecSManuel Lauss c = clk_get(NULL, "psc0_intclk");
826415e0fecSManuel Lauss if (!IS_ERR(c)) {
827415e0fecSManuel Lauss pfc = clk_round_rate(c, 50000000);
828415e0fecSManuel Lauss if ((pfc < 1) || (abs(50000000 - pfc) > 2500000))
829a86aadefSColin Ian King pr_warn("DB1200: can't get I2C close to 50MHz\n");
830415e0fecSManuel Lauss else
831415e0fecSManuel Lauss clk_set_rate(c, pfc);
832293076f3SManuel Lauss clk_prepare_enable(c);
833415e0fecSManuel Lauss clk_put(c);
834415e0fecSManuel Lauss }
835415e0fecSManuel Lauss
8367c4b24daSManuel Lauss /* insert/eject pairs: one of both is always screaming. To avoid
8377c4b24daSManuel Lauss * issues they must not be automatically enabled when initially
8387c4b24daSManuel Lauss * requested.
8397c4b24daSManuel Lauss */
8407c4b24daSManuel Lauss irq_set_status_flags(DB1200_SD0_INSERT_INT, IRQ_NOAUTOEN);
8417c4b24daSManuel Lauss irq_set_status_flags(DB1200_SD0_EJECT_INT, IRQ_NOAUTOEN);
8427c4b24daSManuel Lauss irq_set_status_flags(DB1200_PC0_INSERT_INT, IRQ_NOAUTOEN);
8437c4b24daSManuel Lauss irq_set_status_flags(DB1200_PC0_EJECT_INT, IRQ_NOAUTOEN);
8447c4b24daSManuel Lauss irq_set_status_flags(DB1200_PC1_INSERT_INT, IRQ_NOAUTOEN);
8457c4b24daSManuel Lauss irq_set_status_flags(DB1200_PC1_EJECT_INT, IRQ_NOAUTOEN);
8467c4b24daSManuel Lauss
8477c4b24daSManuel Lauss i2c_register_board_info(0, db1200_i2c_devs,
8487c4b24daSManuel Lauss ARRAY_SIZE(db1200_i2c_devs));
8497c4b24daSManuel Lauss spi_register_board_info(db1200_spi_devs,
850*89c4b588SChristophe JAILLET ARRAY_SIZE(db1200_spi_devs));
8517c4b24daSManuel Lauss
8527c4b24daSManuel Lauss /* SWITCHES: S6.8 I2C/SPI selector (OFF=I2C ON=SPI)
8537c4b24daSManuel Lauss * S6.7 AC97/I2S selector (OFF=AC97 ON=I2S)
8546f7c8623SManuel Lauss * or S12 on the PB1200.
8557c4b24daSManuel Lauss */
8567c4b24daSManuel Lauss
8577c4b24daSManuel Lauss /* NOTE: GPIO215 controls OTG VBUS supply. In SPI mode however
8587c4b24daSManuel Lauss * this pin is claimed by PSC0 (unused though, but pinmux doesn't
8597c4b24daSManuel Lauss * allow to free it without crippling the SPI interface).
8607c4b24daSManuel Lauss * As a result, in SPI mode, OTG simply won't work (PSC0 uses
8617c4b24daSManuel Lauss * it as an input pin which is pulled high on the boards).
8627c4b24daSManuel Lauss */
8631d09de7dSManuel Lauss pfc = alchemy_rdsys(AU1000_SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
8647c4b24daSManuel Lauss
8657c4b24daSManuel Lauss /* switch off OTG VBUS supply */
8667c4b24daSManuel Lauss gpio_request(215, "otg-vbus");
8677c4b24daSManuel Lauss gpio_direction_output(215, 1);
8687c4b24daSManuel Lauss
869bd8510dfSManuel Lauss printk(KERN_INFO "%s device configuration:\n", get_system_type());
8707c4b24daSManuel Lauss
8717c4b24daSManuel Lauss sw = bcsr_read(BCSR_SWITCHES);
8727c4b24daSManuel Lauss if (sw & BCSR_SWITCHES_DIP_8) {
8737c4b24daSManuel Lauss db1200_devs[0] = &db1200_i2c_dev;
8747c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC0MUX, 0);
8757c4b24daSManuel Lauss
8767c4b24daSManuel Lauss pfc |= (2 << 17); /* GPIO2 block owns GPIO215 */
8777c4b24daSManuel Lauss
8787c4b24daSManuel Lauss printk(KERN_INFO " S6.8 OFF: PSC0 mode I2C\n");
8797c4b24daSManuel Lauss printk(KERN_INFO " OTG port VBUS supply available!\n");
8807c4b24daSManuel Lauss } else {
8817c4b24daSManuel Lauss db1200_devs[0] = &db1200_spi_dev;
8827c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC0MUX);
8837c4b24daSManuel Lauss
8847c4b24daSManuel Lauss pfc |= (1 << 17); /* PSC0 owns GPIO215 */
8857c4b24daSManuel Lauss
8867c4b24daSManuel Lauss printk(KERN_INFO " S6.8 ON : PSC0 mode SPI\n");
8877c4b24daSManuel Lauss printk(KERN_INFO " OTG port VBUS supply disabled\n");
8887c4b24daSManuel Lauss }
8891d09de7dSManuel Lauss alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
8907c4b24daSManuel Lauss
8917c4b24daSManuel Lauss /* Audio: DIP7 selects I2S(0)/AC97(1), but need I2C for I2S!
8927c4b24daSManuel Lauss * so: DIP7=1 || DIP8=0 => AC97, DIP7=0 && DIP8=1 => I2S
8937c4b24daSManuel Lauss */
8947c4b24daSManuel Lauss sw &= BCSR_SWITCHES_DIP_8 | BCSR_SWITCHES_DIP_7;
8957c4b24daSManuel Lauss if (sw == BCSR_SWITCHES_DIP_8) {
8967c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC1MUX);
8977c4b24daSManuel Lauss db1200_audio_dev.name = "au1xpsc_i2s";
8987c4b24daSManuel Lauss db1200_sound_dev.name = "db1200-i2s";
8997c4b24daSManuel Lauss printk(KERN_INFO " S6.7 ON : PSC1 mode I2S\n");
9007c4b24daSManuel Lauss } else {
9017c4b24daSManuel Lauss bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC1MUX, 0);
9027c4b24daSManuel Lauss db1200_audio_dev.name = "au1xpsc_ac97";
9037c4b24daSManuel Lauss db1200_sound_dev.name = "db1200-ac97";
9047c4b24daSManuel Lauss printk(KERN_INFO " S6.7 OFF: PSC1 mode AC97\n");
9057c4b24daSManuel Lauss }
9067c4b24daSManuel Lauss
9077c4b24daSManuel Lauss /* Audio PSC clock is supplied externally. (FIXME: platdata!!) */
9087c4b24daSManuel Lauss __raw_writel(PSC_SEL_CLK_SERCLK,
9097c4b24daSManuel Lauss (void __iomem *)KSEG1ADDR(AU1550_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
9107c4b24daSManuel Lauss wmb();
9117c4b24daSManuel Lauss
9127c4b24daSManuel Lauss db1x_register_pcmcia_socket(
9137c4b24daSManuel Lauss AU1000_PCMCIA_ATTR_PHYS_ADDR,
9147c4b24daSManuel Lauss AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
9157c4b24daSManuel Lauss AU1000_PCMCIA_MEM_PHYS_ADDR,
9167c4b24daSManuel Lauss AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
9177c4b24daSManuel Lauss AU1000_PCMCIA_IO_PHYS_ADDR,
9187c4b24daSManuel Lauss AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
9197c4b24daSManuel Lauss DB1200_PC0_INT, DB1200_PC0_INSERT_INT,
9207c4b24daSManuel Lauss /*DB1200_PC0_STSCHG_INT*/0, DB1200_PC0_EJECT_INT, 0);
9217c4b24daSManuel Lauss
9227c4b24daSManuel Lauss db1x_register_pcmcia_socket(
9237c4b24daSManuel Lauss AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000,
9247c4b24daSManuel Lauss AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1,
9257c4b24daSManuel Lauss AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000,
9267c4b24daSManuel Lauss AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1,
9277c4b24daSManuel Lauss AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000,
9287c4b24daSManuel Lauss AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1,
9297c4b24daSManuel Lauss DB1200_PC1_INT, DB1200_PC1_INSERT_INT,
9307c4b24daSManuel Lauss /*DB1200_PC1_STSCHG_INT*/0, DB1200_PC1_EJECT_INT, 1);
9317c4b24daSManuel Lauss
9327c4b24daSManuel Lauss swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1200_SWAPBOOT;
9337c4b24daSManuel Lauss db1x_register_norflash(64 << 20, 2, swapped);
9347c4b24daSManuel Lauss
9356f7c8623SManuel Lauss platform_add_devices(db1200_devs, ARRAY_SIZE(db1200_devs));
9366f7c8623SManuel Lauss
9376f7c8623SManuel Lauss /* PB1200 is a DB1200 with a 2nd MMC and Camera connector */
9386f7c8623SManuel Lauss if ((bid == BCSR_WHOAMI_PB1200_DDR1) ||
9396f7c8623SManuel Lauss (bid == BCSR_WHOAMI_PB1200_DDR2))
9406f7c8623SManuel Lauss platform_add_devices(pb1200_devs, ARRAY_SIZE(pb1200_devs));
9416f7c8623SManuel Lauss
9426f7c8623SManuel Lauss return 0;
9437c4b24daSManuel Lauss }
944