db1550.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*
  2. * Alchemy Db1550 board support
  3. *
  4. * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com>
  5. */
  6. #include <linux/dma-mapping.h>
  7. #include <linux/gpio.h>
  8. #include <linux/i2c.h>
  9. #include <linux/init.h>
  10. #include <linux/io.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/nand.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/spi/flash.h>
  19. #include <asm/mach-au1x00/au1000.h>
  20. #include <asm/mach-au1x00/au1xxx_eth.h>
  21. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  22. #include <asm/mach-au1x00/au1xxx_psc.h>
  23. #include <asm/mach-au1x00/au1550_spi.h>
  24. #include <asm/mach-db1x00/bcsr.h>
  25. #include <prom.h>
  26. #include "platform.h"
  27. const char *get_system_type(void)
  28. {
  29. return "DB1550";
  30. }
  31. static void __init db1550_hw_setup(void)
  32. {
  33. void __iomem *base;
  34. alchemy_gpio_direction_output(203, 0); /* red led on */
  35. /* complete SPI setup: link psc0_intclk to a 48MHz source,
  36. * and assign GPIO16 to PSC0_SYNC1 (SPI cs# line)
  37. */
  38. base = (void __iomem *)SYS_CLKSRC;
  39. __raw_writel(__raw_readl(base) | 0x000001e0, base);
  40. base = (void __iomem *)SYS_PINFUNC;
  41. __raw_writel(__raw_readl(base) | 1, base);
  42. wmb();
  43. /* reset the AC97 codec now, the reset time in the psc-ac97 driver
  44. * is apparently too short although it's ridiculous as it is.
  45. */
  46. base = (void __iomem *)KSEG1ADDR(AU1550_PSC1_PHYS_ADDR);
  47. __raw_writel(PSC_SEL_CLK_SERCLK | PSC_SEL_PS_AC97MODE,
  48. base + PSC_SEL_OFFSET);
  49. __raw_writel(PSC_CTRL_DISABLE, base + PSC_CTRL_OFFSET);
  50. wmb();
  51. __raw_writel(PSC_AC97RST_RST, base + PSC_AC97RST_OFFSET);
  52. wmb();
  53. alchemy_gpio_direction_output(202, 0); /* green led on */
  54. }
  55. void __init board_setup(void)
  56. {
  57. unsigned short whoami;
  58. bcsr_init(DB1550_BCSR_PHYS_ADDR,
  59. DB1550_BCSR_PHYS_ADDR + DB1550_BCSR_HEXLED_OFS);
  60. whoami = bcsr_read(BCSR_WHOAMI);
  61. printk(KERN_INFO "Alchemy/AMD DB1550 Board, CPLD Rev %d"
  62. " Board-ID %d Daughtercard ID %d\n",
  63. (whoami >> 4) & 0xf, (whoami >> 8) & 0xf, whoami & 0xf);
  64. db1550_hw_setup();
  65. }
  66. /*****************************************************************************/
  67. static struct mtd_partition db1550_spiflash_parts[] = {
  68. {
  69. .name = "spi_flash",
  70. .offset = 0,
  71. .size = MTDPART_SIZ_FULL,
  72. },
  73. };
  74. static struct flash_platform_data db1550_spiflash_data = {
  75. .name = "s25fl010",
  76. .parts = db1550_spiflash_parts,
  77. .nr_parts = ARRAY_SIZE(db1550_spiflash_parts),
  78. .type = "m25p10",
  79. };
  80. static struct spi_board_info db1550_spi_devs[] __initdata = {
  81. {
  82. /* TI TMP121AIDBVR temp sensor */
  83. .modalias = "tmp121",
  84. .max_speed_hz = 2400000,
  85. .bus_num = 0,
  86. .chip_select = 0,
  87. .mode = SPI_MODE_0,
  88. },
  89. {
  90. /* Spansion S25FL001D0FMA SPI flash */
  91. .modalias = "m25p80",
  92. .max_speed_hz = 2400000,
  93. .bus_num = 0,
  94. .chip_select = 1,
  95. .mode = SPI_MODE_0,
  96. .platform_data = &db1550_spiflash_data,
  97. },
  98. };
  99. static struct i2c_board_info db1550_i2c_devs[] __initdata = {
  100. { I2C_BOARD_INFO("24c04", 0x52),}, /* AT24C04-10 I2C eeprom */
  101. { I2C_BOARD_INFO("ne1619", 0x2d),}, /* adm1025-compat hwmon */
  102. { I2C_BOARD_INFO("wm8731", 0x1b),}, /* I2S audio codec WM8731 */
  103. };
  104. /**********************************************************************/
  105. static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  106. unsigned int ctrl)
  107. {
  108. struct nand_chip *this = mtd->priv;
  109. unsigned long ioaddr = (unsigned long)this->IO_ADDR_W;
  110. ioaddr &= 0xffffff00;
  111. if (ctrl & NAND_CLE) {
  112. ioaddr += MEM_STNAND_CMD;
  113. } else if (ctrl & NAND_ALE) {
  114. ioaddr += MEM_STNAND_ADDR;
  115. } else {
  116. /* assume we want to r/w real data by default */
  117. ioaddr += MEM_STNAND_DATA;
  118. }
  119. this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
  120. if (cmd != NAND_CMD_NONE) {
  121. __raw_writeb(cmd, this->IO_ADDR_W);
  122. wmb();
  123. }
  124. }
  125. static int au1550_nand_device_ready(struct mtd_info *mtd)
  126. {
  127. return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
  128. }
  129. static struct mtd_partition db1550_nand_parts[] = {
  130. {
  131. .name = "NAND FS 0",
  132. .offset = 0,
  133. .size = 8 * 1024 * 1024,
  134. },
  135. {
  136. .name = "NAND FS 1",
  137. .offset = MTDPART_OFS_APPEND,
  138. .size = MTDPART_SIZ_FULL
  139. },
  140. };
  141. struct platform_nand_data db1550_nand_platdata = {
  142. .chip = {
  143. .nr_chips = 1,
  144. .chip_offset = 0,
  145. .nr_partitions = ARRAY_SIZE(db1550_nand_parts),
  146. .partitions = db1550_nand_parts,
  147. .chip_delay = 20,
  148. },
  149. .ctrl = {
  150. .dev_ready = au1550_nand_device_ready,
  151. .cmd_ctrl = au1550_nand_cmd_ctrl,
  152. },
  153. };
  154. static struct resource db1550_nand_res[] = {
  155. [0] = {
  156. .start = 0x20000000,
  157. .end = 0x200000ff,
  158. .flags = IORESOURCE_MEM,
  159. },
  160. };
  161. static struct platform_device db1550_nand_dev = {
  162. .name = "gen_nand",
  163. .num_resources = ARRAY_SIZE(db1550_nand_res),
  164. .resource = db1550_nand_res,
  165. .id = -1,
  166. .dev = {
  167. .platform_data = &db1550_nand_platdata,
  168. }
  169. };
  170. /**********************************************************************/
  171. static struct resource au1550_psc0_res[] = {
  172. [0] = {
  173. .start = AU1550_PSC0_PHYS_ADDR,
  174. .end = AU1550_PSC0_PHYS_ADDR + 0xfff,
  175. .flags = IORESOURCE_MEM,
  176. },
  177. [1] = {
  178. .start = AU1550_PSC0_INT,
  179. .end = AU1550_PSC0_INT,
  180. .flags = IORESOURCE_IRQ,
  181. },
  182. [2] = {
  183. .start = AU1550_DSCR_CMD0_PSC0_TX,
  184. .end = AU1550_DSCR_CMD0_PSC0_TX,
  185. .flags = IORESOURCE_DMA,
  186. },
  187. [3] = {
  188. .start = AU1550_DSCR_CMD0_PSC0_RX,
  189. .end = AU1550_DSCR_CMD0_PSC0_RX,
  190. .flags = IORESOURCE_DMA,
  191. },
  192. };
  193. static void db1550_spi_cs_en(struct au1550_spi_info *spi, int cs, int pol)
  194. {
  195. if (cs)
  196. bcsr_mod(BCSR_BOARD, 0, BCSR_BOARD_SPISEL);
  197. else
  198. bcsr_mod(BCSR_BOARD, BCSR_BOARD_SPISEL, 0);
  199. }
  200. static struct au1550_spi_info db1550_spi_platdata = {
  201. .mainclk_hz = 48000000, /* PSC0 clock: max. 2.4MHz SPI clk */
  202. .num_chipselect = 2,
  203. .activate_cs = db1550_spi_cs_en,
  204. };
  205. static u64 spi_dmamask = DMA_BIT_MASK(32);
  206. static struct platform_device db1550_spi_dev = {
  207. .dev = {
  208. .dma_mask = &spi_dmamask,
  209. .coherent_dma_mask = DMA_BIT_MASK(32),
  210. .platform_data = &db1550_spi_platdata,
  211. },
  212. .name = "au1550-spi",
  213. .id = 0, /* bus number */
  214. .num_resources = ARRAY_SIZE(au1550_psc0_res),
  215. .resource = au1550_psc0_res,
  216. };
  217. /**********************************************************************/
  218. static struct resource au1550_psc1_res[] = {
  219. [0] = {
  220. .start = AU1550_PSC1_PHYS_ADDR,
  221. .end = AU1550_PSC1_PHYS_ADDR + 0xfff,
  222. .flags = IORESOURCE_MEM,
  223. },
  224. [1] = {
  225. .start = AU1550_PSC1_INT,
  226. .end = AU1550_PSC1_INT,
  227. .flags = IORESOURCE_IRQ,
  228. },
  229. [2] = {
  230. .start = AU1550_DSCR_CMD0_PSC1_TX,
  231. .end = AU1550_DSCR_CMD0_PSC1_TX,
  232. .flags = IORESOURCE_DMA,
  233. },
  234. [3] = {
  235. .start = AU1550_DSCR_CMD0_PSC1_RX,
  236. .end = AU1550_DSCR_CMD0_PSC1_RX,
  237. .flags = IORESOURCE_DMA,
  238. },
  239. };
  240. static struct platform_device db1550_ac97_dev = {
  241. .name = "au1xpsc_ac97",
  242. .id = 1, /* PSC ID */
  243. .num_resources = ARRAY_SIZE(au1550_psc1_res),
  244. .resource = au1550_psc1_res,
  245. };
  246. static struct resource au1550_psc2_res[] = {
  247. [0] = {
  248. .start = AU1550_PSC2_PHYS_ADDR,
  249. .end = AU1550_PSC2_PHYS_ADDR + 0xfff,
  250. .flags = IORESOURCE_MEM,
  251. },
  252. [1] = {
  253. .start = AU1550_PSC2_INT,
  254. .end = AU1550_PSC2_INT,
  255. .flags = IORESOURCE_IRQ,
  256. },
  257. [2] = {
  258. .start = AU1550_DSCR_CMD0_PSC2_TX,
  259. .end = AU1550_DSCR_CMD0_PSC2_TX,
  260. .flags = IORESOURCE_DMA,
  261. },
  262. [3] = {
  263. .start = AU1550_DSCR_CMD0_PSC2_RX,
  264. .end = AU1550_DSCR_CMD0_PSC2_RX,
  265. .flags = IORESOURCE_DMA,
  266. },
  267. };
  268. static struct platform_device db1550_i2c_dev = {
  269. .name = "au1xpsc_smbus",
  270. .id = 0, /* bus number */
  271. .num_resources = ARRAY_SIZE(au1550_psc2_res),
  272. .resource = au1550_psc2_res,
  273. };
  274. /**********************************************************************/
  275. static struct resource au1550_psc3_res[] = {
  276. [0] = {
  277. .start = AU1550_PSC3_PHYS_ADDR,
  278. .end = AU1550_PSC3_PHYS_ADDR + 0xfff,
  279. .flags = IORESOURCE_MEM,
  280. },
  281. [1] = {
  282. .start = AU1550_PSC3_INT,
  283. .end = AU1550_PSC3_INT,
  284. .flags = IORESOURCE_IRQ,
  285. },
  286. [2] = {
  287. .start = AU1550_DSCR_CMD0_PSC3_TX,
  288. .end = AU1550_DSCR_CMD0_PSC3_TX,
  289. .flags = IORESOURCE_DMA,
  290. },
  291. [3] = {
  292. .start = AU1550_DSCR_CMD0_PSC3_RX,
  293. .end = AU1550_DSCR_CMD0_PSC3_RX,
  294. .flags = IORESOURCE_DMA,
  295. },
  296. };
  297. static struct platform_device db1550_i2s_dev = {
  298. .name = "au1xpsc_i2s",
  299. .id = 3, /* PSC ID */
  300. .num_resources = ARRAY_SIZE(au1550_psc3_res),
  301. .resource = au1550_psc3_res,
  302. };
  303. /**********************************************************************/
  304. static struct platform_device db1550_stac_dev = {
  305. .name = "ac97-codec",
  306. .id = 1, /* on PSC1 */
  307. };
  308. static struct platform_device db1550_ac97dma_dev = {
  309. .name = "au1xpsc-pcm",
  310. .id = 1, /* on PSC3 */
  311. };
  312. static struct platform_device db1550_i2sdma_dev = {
  313. .name = "au1xpsc-pcm",
  314. .id = 3, /* on PSC3 */
  315. };
  316. static struct platform_device db1550_sndac97_dev = {
  317. .name = "db1550-ac97",
  318. };
  319. static struct platform_device db1550_sndi2s_dev = {
  320. .name = "db1550-i2s",
  321. };
  322. /**********************************************************************/
  323. static int db1550_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  324. {
  325. if ((slot < 11) || (slot > 13) || pin == 0)
  326. return -1;
  327. if (slot == 11)
  328. return (pin == 1) ? AU1550_PCI_INTC : 0xff;
  329. if (slot == 12) {
  330. switch (pin) {
  331. case 1: return AU1550_PCI_INTB;
  332. case 2: return AU1550_PCI_INTC;
  333. case 3: return AU1550_PCI_INTD;
  334. case 4: return AU1550_PCI_INTA;
  335. }
  336. }
  337. if (slot == 13) {
  338. switch (pin) {
  339. case 1: return AU1550_PCI_INTA;
  340. case 2: return AU1550_PCI_INTB;
  341. case 3: return AU1550_PCI_INTC;
  342. case 4: return AU1550_PCI_INTD;
  343. }
  344. }
  345. return -1;
  346. }
  347. static struct resource alchemy_pci_host_res[] = {
  348. [0] = {
  349. .start = AU1500_PCI_PHYS_ADDR,
  350. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  351. .flags = IORESOURCE_MEM,
  352. },
  353. };
  354. static struct alchemy_pci_platdata db1550_pci_pd = {
  355. .board_map_irq = db1550_map_pci_irq,
  356. };
  357. static struct platform_device db1550_pci_host_dev = {
  358. .dev.platform_data = &db1550_pci_pd,
  359. .name = "alchemy-pci",
  360. .id = 0,
  361. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  362. .resource = alchemy_pci_host_res,
  363. };
  364. /**********************************************************************/
  365. static struct platform_device *db1550_devs[] __initdata = {
  366. &db1550_nand_dev,
  367. &db1550_i2c_dev,
  368. &db1550_ac97_dev,
  369. &db1550_spi_dev,
  370. &db1550_i2s_dev,
  371. &db1550_stac_dev,
  372. &db1550_ac97dma_dev,
  373. &db1550_i2sdma_dev,
  374. &db1550_sndac97_dev,
  375. &db1550_sndi2s_dev,
  376. };
  377. /* must be arch_initcall; MIPS PCI scans busses in a subsys_initcall */
  378. static int __init db1550_pci_init(void)
  379. {
  380. return platform_device_register(&db1550_pci_host_dev);
  381. }
  382. arch_initcall(db1550_pci_init);
  383. static int __init db1550_dev_init(void)
  384. {
  385. int swapped;
  386. irq_set_irq_type(AU1550_GPIO0_INT, IRQ_TYPE_EDGE_BOTH); /* CD0# */
  387. irq_set_irq_type(AU1550_GPIO1_INT, IRQ_TYPE_EDGE_BOTH); /* CD1# */
  388. irq_set_irq_type(AU1550_GPIO3_INT, IRQ_TYPE_LEVEL_LOW); /* CARD0# */
  389. irq_set_irq_type(AU1550_GPIO5_INT, IRQ_TYPE_LEVEL_LOW); /* CARD1# */
  390. irq_set_irq_type(AU1550_GPIO21_INT, IRQ_TYPE_LEVEL_LOW); /* STSCHG0# */
  391. irq_set_irq_type(AU1550_GPIO22_INT, IRQ_TYPE_LEVEL_LOW); /* STSCHG1# */
  392. i2c_register_board_info(0, db1550_i2c_devs,
  393. ARRAY_SIZE(db1550_i2c_devs));
  394. spi_register_board_info(db1550_spi_devs,
  395. ARRAY_SIZE(db1550_i2c_devs));
  396. /* Audio PSC clock is supplied by codecs (PSC1, 3) FIXME: platdata!! */
  397. __raw_writel(PSC_SEL_CLK_SERCLK,
  398. (void __iomem *)KSEG1ADDR(AU1550_PSC1_PHYS_ADDR) + PSC_SEL_OFFSET);
  399. wmb();
  400. __raw_writel(PSC_SEL_CLK_SERCLK,
  401. (void __iomem *)KSEG1ADDR(AU1550_PSC3_PHYS_ADDR) + PSC_SEL_OFFSET);
  402. wmb();
  403. /* SPI/I2C use internally supplied 50MHz source */
  404. __raw_writel(PSC_SEL_CLK_INTCLK,
  405. (void __iomem *)KSEG1ADDR(AU1550_PSC0_PHYS_ADDR) + PSC_SEL_OFFSET);
  406. wmb();
  407. __raw_writel(PSC_SEL_CLK_INTCLK,
  408. (void __iomem *)KSEG1ADDR(AU1550_PSC2_PHYS_ADDR) + PSC_SEL_OFFSET);
  409. wmb();
  410. db1x_register_pcmcia_socket(
  411. AU1000_PCMCIA_ATTR_PHYS_ADDR,
  412. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
  413. AU1000_PCMCIA_MEM_PHYS_ADDR,
  414. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
  415. AU1000_PCMCIA_IO_PHYS_ADDR,
  416. AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
  417. AU1550_GPIO3_INT, AU1550_GPIO0_INT,
  418. /*AU1550_GPIO21_INT*/0, 0, 0);
  419. db1x_register_pcmcia_socket(
  420. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000,
  421. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1,
  422. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000,
  423. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1,
  424. AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000,
  425. AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1,
  426. AU1550_GPIO5_INT, AU1550_GPIO1_INT,
  427. /*AU1550_GPIO22_INT*/0, 0, 1);
  428. swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT;
  429. db1x_register_norflash(128 << 20, 4, swapped);
  430. return platform_add_devices(db1550_devs, ARRAY_SIZE(db1550_devs));
  431. }
  432. device_initcall(db1550_dev_init);