platform.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * DBAu1200 board platform device registration
  3. *
  4. * Copyright (C) 2008-2009 Manuel Lauss
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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 St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/dma-mapping.h>
  21. #include <linux/gpio.h>
  22. #include <linux/i2c.h>
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include <linux/leds.h>
  26. #include <linux/mmc/host.h>
  27. #include <linux/mtd/mtd.h>
  28. #include <linux/mtd/nand.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/serial_8250.h>
  32. #include <linux/spi/spi.h>
  33. #include <linux/spi/flash.h>
  34. #include <linux/smc91x.h>
  35. #include <asm/mach-au1x00/au1100_mmc.h>
  36. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  37. #include <asm/mach-au1x00/au1550_spi.h>
  38. #include <asm/mach-db1x00/bcsr.h>
  39. #include <asm/mach-db1x00/db1200.h>
  40. #include "../platform.h"
  41. static struct mtd_partition db1200_spiflash_parts[] = {
  42. {
  43. .name = "DB1200 SPI flash",
  44. .offset = 0,
  45. .size = MTDPART_SIZ_FULL,
  46. },
  47. };
  48. static struct flash_platform_data db1200_spiflash_data = {
  49. .name = "s25fl001",
  50. .parts = db1200_spiflash_parts,
  51. .nr_parts = ARRAY_SIZE(db1200_spiflash_parts),
  52. .type = "m25p10",
  53. };
  54. static struct spi_board_info db1200_spi_devs[] __initdata = {
  55. {
  56. /* TI TMP121AIDBVR temp sensor */
  57. .modalias = "tmp121",
  58. .max_speed_hz = 2000000,
  59. .bus_num = 0,
  60. .chip_select = 0,
  61. .mode = 0,
  62. },
  63. {
  64. /* Spansion S25FL001D0FMA SPI flash */
  65. .modalias = "m25p80",
  66. .max_speed_hz = 50000000,
  67. .bus_num = 0,
  68. .chip_select = 1,
  69. .mode = 0,
  70. .platform_data = &db1200_spiflash_data,
  71. },
  72. };
  73. static struct i2c_board_info db1200_i2c_devs[] __initdata = {
  74. {
  75. /* AT24C04-10 I2C eeprom */
  76. I2C_BOARD_INFO("24c04", 0x52),
  77. },
  78. {
  79. /* Philips NE1619 temp/voltage sensor (adm1025 drv) */
  80. I2C_BOARD_INFO("ne1619", 0x2d),
  81. },
  82. {
  83. /* I2S audio codec WM8731 */
  84. I2C_BOARD_INFO("wm8731", 0x1b),
  85. },
  86. };
  87. /**********************************************************************/
  88. static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  89. unsigned int ctrl)
  90. {
  91. struct nand_chip *this = mtd->priv;
  92. unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
  93. ioaddr &= 0xffffff00;
  94. if (ctrl & NAND_CLE) {
  95. ioaddr += MEM_STNAND_CMD;
  96. } else if (ctrl & NAND_ALE) {
  97. ioaddr += MEM_STNAND_ADDR;
  98. } else {
  99. /* assume we want to r/w real data by default */
  100. ioaddr += MEM_STNAND_DATA;
  101. }
  102. this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
  103. if (cmd != NAND_CMD_NONE) {
  104. __raw_writeb(cmd, this->IO_ADDR_W);
  105. wmb();
  106. }
  107. }
  108. static int au1200_nand_device_ready(struct mtd_info *mtd)
  109. {
  110. return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
  111. }
  112. static const char *db1200_part_probes[] = { "cmdlinepart", NULL };
  113. static struct mtd_partition db1200_nand_parts[] = {
  114. {
  115. .name = "NAND FS 0",
  116. .offset = 0,
  117. .size = 8 * 1024 * 1024,
  118. },
  119. {
  120. .name = "NAND FS 1",
  121. .offset = MTDPART_OFS_APPEND,
  122. .size = MTDPART_SIZ_FULL
  123. },
  124. };
  125. struct platform_nand_data db1200_nand_platdata = {
  126. .chip = {
  127. .nr_chips = 1,
  128. .chip_offset = 0,
  129. .nr_partitions = ARRAY_SIZE(db1200_nand_parts),
  130. .partitions = db1200_nand_parts,
  131. .chip_delay = 20,
  132. .part_probe_types = db1200_part_probes,
  133. },
  134. .ctrl = {
  135. .dev_ready = au1200_nand_device_ready,
  136. .cmd_ctrl = au1200_nand_cmd_ctrl,
  137. },
  138. };
  139. static struct resource db1200_nand_res[] = {
  140. [0] = {
  141. .start = DB1200_NAND_PHYS_ADDR,
  142. .end = DB1200_NAND_PHYS_ADDR + 0xff,
  143. .flags = IORESOURCE_MEM,
  144. },
  145. };
  146. static struct platform_device db1200_nand_dev = {
  147. .name = "gen_nand",
  148. .num_resources = ARRAY_SIZE(db1200_nand_res),
  149. .resource = db1200_nand_res,
  150. .id = -1,
  151. .dev = {
  152. .platform_data = &db1200_nand_platdata,
  153. }
  154. };
  155. /**********************************************************************/
  156. static struct smc91x_platdata db1200_eth_data = {
  157. .flags = SMC91X_NOWAIT | SMC91X_USE_16BIT,
  158. .leda = RPC_LED_100_10,
  159. .ledb = RPC_LED_TX_RX,
  160. };
  161. static struct resource db1200_eth_res[] = {
  162. [0] = {
  163. .start = DB1200_ETH_PHYS_ADDR,
  164. .end = DB1200_ETH_PHYS_ADDR + 0xf,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. [1] = {
  168. .start = DB1200_ETH_INT,
  169. .end = DB1200_ETH_INT,
  170. .flags = IORESOURCE_IRQ,
  171. },
  172. };
  173. static struct platform_device db1200_eth_dev = {
  174. .dev = {
  175. .platform_data = &db1200_eth_data,
  176. },
  177. .name = "smc91x",
  178. .id = -1,
  179. .num_resources = ARRAY_SIZE(db1200_eth_res),
  180. .resource = db1200_eth_res,
  181. };
  182. /**********************************************************************/
  183. static struct resource db1200_ide_res[] = {
  184. [0] = {
  185. .start = DB1200_IDE_PHYS_ADDR,
  186. .end = DB1200_IDE_PHYS_ADDR + DB1200_IDE_PHYS_LEN - 1,
  187. .flags = IORESOURCE_MEM,
  188. },
  189. [1] = {
  190. .start = DB1200_IDE_INT,
  191. .end = DB1200_IDE_INT,
  192. .flags = IORESOURCE_IRQ,
  193. }
  194. };
  195. static u64 ide_dmamask = DMA_32BIT_MASK;
  196. static struct platform_device db1200_ide_dev = {
  197. .name = "au1200-ide",
  198. .id = 0,
  199. .dev = {
  200. .dma_mask = &ide_dmamask,
  201. .coherent_dma_mask = DMA_32BIT_MASK,
  202. },
  203. .num_resources = ARRAY_SIZE(db1200_ide_res),
  204. .resource = db1200_ide_res,
  205. };
  206. /**********************************************************************/
  207. static struct platform_device db1200_rtc_dev = {
  208. .name = "rtc-au1xxx",
  209. .id = -1,
  210. };
  211. /**********************************************************************/
  212. /* SD carddetects: they're supposed to be edge-triggered, but ack
  213. * doesn't seem to work (CPLD Rev 2). Instead, the screaming one
  214. * is disabled and its counterpart enabled. The 500ms timeout is
  215. * because the carddetect isn't debounced in hardware.
  216. */
  217. static irqreturn_t db1200_mmc_cd(int irq, void *ptr)
  218. {
  219. void(*mmc_cd)(struct mmc_host *, unsigned long);
  220. if (irq == DB1200_SD0_INSERT_INT) {
  221. disable_irq_nosync(DB1200_SD0_INSERT_INT);
  222. enable_irq(DB1200_SD0_EJECT_INT);
  223. } else {
  224. disable_irq_nosync(DB1200_SD0_EJECT_INT);
  225. enable_irq(DB1200_SD0_INSERT_INT);
  226. }
  227. /* link against CONFIG_MMC=m */
  228. mmc_cd = symbol_get(mmc_detect_change);
  229. if (mmc_cd) {
  230. mmc_cd(ptr, msecs_to_jiffies(500));
  231. symbol_put(mmc_detect_change);
  232. }
  233. return IRQ_HANDLED;
  234. }
  235. static int db1200_mmc_cd_setup(void *mmc_host, int en)
  236. {
  237. int ret;
  238. if (en) {
  239. ret = request_irq(DB1200_SD0_INSERT_INT, db1200_mmc_cd,
  240. IRQF_DISABLED, "sd_insert", mmc_host);
  241. if (ret)
  242. goto out;
  243. ret = request_irq(DB1200_SD0_EJECT_INT, db1200_mmc_cd,
  244. IRQF_DISABLED, "sd_eject", mmc_host);
  245. if (ret) {
  246. free_irq(DB1200_SD0_INSERT_INT, mmc_host);
  247. goto out;
  248. }
  249. if (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT)
  250. enable_irq(DB1200_SD0_EJECT_INT);
  251. else
  252. enable_irq(DB1200_SD0_INSERT_INT);
  253. } else {
  254. free_irq(DB1200_SD0_INSERT_INT, mmc_host);
  255. free_irq(DB1200_SD0_EJECT_INT, mmc_host);
  256. }
  257. ret = 0;
  258. out:
  259. return ret;
  260. }
  261. static void db1200_mmc_set_power(void *mmc_host, int state)
  262. {
  263. if (state) {
  264. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SD0PWR);
  265. msleep(400); /* stabilization time */
  266. } else
  267. bcsr_mod(BCSR_BOARD, BCSR_BOARD_SD0PWR, 0);
  268. }
  269. static int db1200_mmc_card_readonly(void *mmc_host)
  270. {
  271. return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 1 : 0;
  272. }
  273. static int db1200_mmc_card_inserted(void *mmc_host)
  274. {
  275. return (bcsr_read(BCSR_SIGSTAT) & BCSR_INT_SD0INSERT) ? 1 : 0;
  276. }
  277. static void db1200_mmcled_set(struct led_classdev *led,
  278. enum led_brightness brightness)
  279. {
  280. if (brightness != LED_OFF)
  281. bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0);
  282. else
  283. bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0);
  284. }
  285. static struct led_classdev db1200_mmc_led = {
  286. .brightness_set = db1200_mmcled_set,
  287. };
  288. /* needed by arch/mips/alchemy/common/platform.c */
  289. struct au1xmmc_platform_data au1xmmc_platdata[] = {
  290. [0] = {
  291. .cd_setup = db1200_mmc_cd_setup,
  292. .set_power = db1200_mmc_set_power,
  293. .card_inserted = db1200_mmc_card_inserted,
  294. .card_readonly = db1200_mmc_card_readonly,
  295. .led = &db1200_mmc_led,
  296. },
  297. };
  298. /**********************************************************************/
  299. static struct resource au1200_psc0_res[] = {
  300. [0] = {
  301. .start = PSC0_PHYS_ADDR,
  302. .end = PSC0_PHYS_ADDR + 0x000fffff,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .start = AU1200_PSC0_INT,
  307. .end = AU1200_PSC0_INT,
  308. .flags = IORESOURCE_IRQ,
  309. },
  310. [2] = {
  311. .start = DSCR_CMD0_PSC0_TX,
  312. .end = DSCR_CMD0_PSC0_TX,
  313. .flags = IORESOURCE_DMA,
  314. },
  315. [3] = {
  316. .start = DSCR_CMD0_PSC0_RX,
  317. .end = DSCR_CMD0_PSC0_RX,
  318. .flags = IORESOURCE_DMA,
  319. },
  320. };
  321. static struct platform_device db1200_i2c_dev = {
  322. .name = "au1xpsc_smbus",
  323. .id = 0, /* bus number */
  324. .num_resources = ARRAY_SIZE(au1200_psc0_res),
  325. .resource = au1200_psc0_res,
  326. };
  327. static void db1200_spi_cs_en(struct au1550_spi_info *spi, int cs, int pol)
  328. {
  329. if (cs)
  330. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_SPISEL);
  331. else
  332. bcsr_mod(BCSR_RESETS, BCSR_RESETS_SPISEL, 0);
  333. }
  334. static struct au1550_spi_info db1200_spi_platdata = {
  335. .mainclk_hz = 50000000, /* PSC0 clock */
  336. .num_chipselect = 2,
  337. .activate_cs = db1200_spi_cs_en,
  338. };
  339. static u64 spi_dmamask = DMA_32BIT_MASK;
  340. static struct platform_device db1200_spi_dev = {
  341. .dev = {
  342. .dma_mask = &spi_dmamask,
  343. .coherent_dma_mask = DMA_32BIT_MASK,
  344. .platform_data = &db1200_spi_platdata,
  345. },
  346. .name = "au1550-spi",
  347. .id = 0, /* bus number */
  348. .num_resources = ARRAY_SIZE(au1200_psc0_res),
  349. .resource = au1200_psc0_res,
  350. };
  351. static struct resource au1200_psc1_res[] = {
  352. [0] = {
  353. .start = PSC1_PHYS_ADDR,
  354. .end = PSC1_PHYS_ADDR + 0x000fffff,
  355. .flags = IORESOURCE_MEM,
  356. },
  357. [1] = {
  358. .start = AU1200_PSC1_INT,
  359. .end = AU1200_PSC1_INT,
  360. .flags = IORESOURCE_IRQ,
  361. },
  362. [2] = {
  363. .start = DSCR_CMD0_PSC1_TX,
  364. .end = DSCR_CMD0_PSC1_TX,
  365. .flags = IORESOURCE_DMA,
  366. },
  367. [3] = {
  368. .start = DSCR_CMD0_PSC1_RX,
  369. .end = DSCR_CMD0_PSC1_RX,
  370. .flags = IORESOURCE_DMA,
  371. },
  372. };
  373. static struct platform_device db1200_audio_dev = {
  374. /* name assigned later based on switch setting */
  375. .id = 1, /* PSC ID */
  376. .num_resources = ARRAY_SIZE(au1200_psc1_res),
  377. .resource = au1200_psc1_res,
  378. };
  379. static struct platform_device *db1200_devs[] __initdata = {
  380. NULL, /* PSC0, selected by S6.8 */
  381. &db1200_ide_dev,
  382. &db1200_eth_dev,
  383. &db1200_rtc_dev,
  384. &db1200_nand_dev,
  385. &db1200_audio_dev,
  386. };
  387. static int __init db1200_dev_init(void)
  388. {
  389. unsigned long pfc;
  390. unsigned short sw;
  391. int swapped;
  392. i2c_register_board_info(0, db1200_i2c_devs,
  393. ARRAY_SIZE(db1200_i2c_devs));
  394. spi_register_board_info(db1200_spi_devs,
  395. ARRAY_SIZE(db1200_i2c_devs));
  396. /* SWITCHES: S6.8 I2C/SPI selector (OFF=I2C ON=SPI)
  397. * S6.7 AC97/I2S selector (OFF=AC97 ON=I2S)
  398. */
  399. /* NOTE: GPIO215 controls OTG VBUS supply. In SPI mode however
  400. * this pin is claimed by PSC0 (unused though, but pinmux doesn't
  401. * allow to free it without crippling the SPI interface).
  402. * As a result, in SPI mode, OTG simply won't work (PSC0 uses
  403. * it as an input pin which is pulled high on the boards).
  404. */
  405. pfc = __raw_readl((void __iomem *)SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
  406. /* switch off OTG VBUS supply */
  407. gpio_request(215, "otg-vbus");
  408. gpio_direction_output(215, 1);
  409. printk(KERN_INFO "DB1200 device configuration:\n");
  410. sw = bcsr_read(BCSR_SWITCHES);
  411. if (sw & BCSR_SWITCHES_DIP_8) {
  412. db1200_devs[0] = &db1200_i2c_dev;
  413. bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC0MUX, 0);
  414. pfc |= (2 << 17); /* GPIO2 block owns GPIO215 */
  415. printk(KERN_INFO " S6.8 OFF: PSC0 mode I2C\n");
  416. printk(KERN_INFO " OTG port VBUS supply available!\n");
  417. } else {
  418. db1200_devs[0] = &db1200_spi_dev;
  419. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC0MUX);
  420. pfc |= (1 << 17); /* PSC0 owns GPIO215 */
  421. printk(KERN_INFO " S6.8 ON : PSC0 mode SPI\n");
  422. printk(KERN_INFO " OTG port VBUS supply disabled\n");
  423. }
  424. __raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
  425. wmb();
  426. /* Audio: DIP7 selects I2S(0)/AC97(1), but need I2C for I2S!
  427. * so: DIP7=1 || DIP8=0 => AC97, DIP7=0 && DIP8=1 => I2S
  428. */
  429. sw &= BCSR_SWITCHES_DIP_8 | BCSR_SWITCHES_DIP_7;
  430. if (sw == BCSR_SWITCHES_DIP_8) {
  431. bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_PSC1MUX);
  432. db1200_audio_dev.name = "au1xpsc_i2s";
  433. printk(KERN_INFO " S6.7 ON : PSC1 mode I2S\n");
  434. } else {
  435. bcsr_mod(BCSR_RESETS, BCSR_RESETS_PSC1MUX, 0);
  436. db1200_audio_dev.name = "au1xpsc_ac97";
  437. printk(KERN_INFO " S6.7 OFF: PSC1 mode AC97\n");
  438. }
  439. /* Audio PSC clock is supplied externally. (FIXME: platdata!!) */
  440. __raw_writel(PSC_SEL_CLK_SERCLK,
  441. (void __iomem *)KSEG1ADDR(PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
  442. wmb();
  443. db1x_register_pcmcia_socket(PCMCIA_ATTR_PHYS_ADDR,
  444. PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
  445. PCMCIA_MEM_PHYS_ADDR,
  446. PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
  447. PCMCIA_IO_PHYS_ADDR,
  448. PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
  449. DB1200_PC0_INT,
  450. DB1200_PC0_INSERT_INT,
  451. /*DB1200_PC0_STSCHG_INT*/0,
  452. DB1200_PC0_EJECT_INT,
  453. 0);
  454. db1x_register_pcmcia_socket(PCMCIA_ATTR_PHYS_ADDR + 0x004000000,
  455. PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1,
  456. PCMCIA_MEM_PHYS_ADDR + 0x004000000,
  457. PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1,
  458. PCMCIA_IO_PHYS_ADDR + 0x004000000,
  459. PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1,
  460. DB1200_PC1_INT,
  461. DB1200_PC1_INSERT_INT,
  462. /*DB1200_PC1_STSCHG_INT*/0,
  463. DB1200_PC1_EJECT_INT,
  464. 1);
  465. swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1200_SWAPBOOT;
  466. db1x_register_norflash(64 << 20, 2, swapped);
  467. return platform_add_devices(db1200_devs, ARRAY_SIZE(db1200_devs));
  468. }
  469. device_initcall(db1200_dev_init);
  470. /* au1200fb calls these: STERBT EINEN TRAGISCHEN TOD!!! */
  471. int board_au1200fb_panel(void)
  472. {
  473. return (bcsr_read(BCSR_SWITCHES) >> 8) & 0x0f;
  474. }
  475. int board_au1200fb_panel_init(void)
  476. {
  477. /* Apply power */
  478. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
  479. BCSR_BOARD_LCDBL);
  480. return 0;
  481. }
  482. int board_au1200fb_panel_shutdown(void)
  483. {
  484. /* Remove power */
  485. bcsr_mod(BCSR_BOARD, BCSR_BOARD_LCDVEE | BCSR_BOARD_LCDVDD |
  486. BCSR_BOARD_LCDBL, 0);
  487. return 0;
  488. }