platform.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * Platform device support for Au1x00 SoCs.
  3. *
  4. * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  5. *
  6. * (C) Copyright Embedded Alley Solutions, Inc 2005
  7. * Author: Pantelis Antoniou <pantelis@embeddedalley.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/dma-mapping.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/serial_8250.h>
  18. #include <linux/slab.h>
  19. #include <asm/mach-au1x00/au1xxx.h>
  20. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  21. #include <asm/mach-au1x00/au1100_mmc.h>
  22. #include <asm/mach-au1x00/au1xxx_eth.h>
  23. #include <prom.h>
  24. static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
  25. unsigned int old_state)
  26. {
  27. #ifdef CONFIG_SERIAL_8250
  28. switch (state) {
  29. case 0:
  30. alchemy_uart_enable(CPHYSADDR(port->membase));
  31. serial8250_do_pm(port, state, old_state);
  32. break;
  33. case 3: /* power off */
  34. serial8250_do_pm(port, state, old_state);
  35. alchemy_uart_disable(CPHYSADDR(port->membase));
  36. break;
  37. default:
  38. serial8250_do_pm(port, state, old_state);
  39. break;
  40. }
  41. #endif
  42. }
  43. #define PORT(_base, _irq) \
  44. { \
  45. .mapbase = _base, \
  46. .irq = _irq, \
  47. .regshift = 2, \
  48. .iotype = UPIO_AU, \
  49. .flags = UPF_SKIP_TEST | UPF_IOREMAP | \
  50. UPF_FIXED_TYPE, \
  51. .type = PORT_16550A, \
  52. .pm = alchemy_8250_pm, \
  53. }
  54. static struct plat_serial8250_port au1x00_uart_data[][4] __initdata = {
  55. [ALCHEMY_CPU_AU1000] = {
  56. PORT(AU1000_UART0_PHYS_ADDR, AU1000_UART0_INT),
  57. PORT(AU1000_UART1_PHYS_ADDR, AU1000_UART1_INT),
  58. PORT(AU1000_UART2_PHYS_ADDR, AU1000_UART2_INT),
  59. PORT(AU1000_UART3_PHYS_ADDR, AU1000_UART3_INT),
  60. },
  61. [ALCHEMY_CPU_AU1500] = {
  62. PORT(AU1000_UART0_PHYS_ADDR, AU1500_UART0_INT),
  63. PORT(AU1000_UART3_PHYS_ADDR, AU1500_UART3_INT),
  64. },
  65. [ALCHEMY_CPU_AU1100] = {
  66. PORT(AU1000_UART0_PHYS_ADDR, AU1100_UART0_INT),
  67. PORT(AU1000_UART1_PHYS_ADDR, AU1100_UART1_INT),
  68. PORT(AU1000_UART3_PHYS_ADDR, AU1100_UART3_INT),
  69. },
  70. [ALCHEMY_CPU_AU1550] = {
  71. PORT(AU1000_UART0_PHYS_ADDR, AU1550_UART0_INT),
  72. PORT(AU1000_UART1_PHYS_ADDR, AU1550_UART1_INT),
  73. PORT(AU1000_UART3_PHYS_ADDR, AU1550_UART3_INT),
  74. },
  75. [ALCHEMY_CPU_AU1200] = {
  76. PORT(AU1000_UART0_PHYS_ADDR, AU1200_UART0_INT),
  77. PORT(AU1000_UART1_PHYS_ADDR, AU1200_UART1_INT),
  78. },
  79. };
  80. static struct platform_device au1xx0_uart_device = {
  81. .name = "serial8250",
  82. .id = PLAT8250_DEV_AU1X00,
  83. };
  84. static void __init alchemy_setup_uarts(int ctype)
  85. {
  86. unsigned int uartclk = get_au1x00_uart_baud_base() * 16;
  87. int s = sizeof(struct plat_serial8250_port);
  88. int c = alchemy_get_uarts(ctype);
  89. struct plat_serial8250_port *ports;
  90. ports = kzalloc(s * (c + 1), GFP_KERNEL);
  91. if (!ports) {
  92. printk(KERN_INFO "Alchemy: no memory for UART data\n");
  93. return;
  94. }
  95. memcpy(ports, au1x00_uart_data[ctype], s * c);
  96. au1xx0_uart_device.dev.platform_data = ports;
  97. /* Fill up uartclk. */
  98. for (s = 0; s < c; s++)
  99. ports[s].uartclk = uartclk;
  100. if (platform_device_register(&au1xx0_uart_device))
  101. printk(KERN_INFO "Alchemy: failed to register UARTs\n");
  102. }
  103. /* The dmamask must be set for OHCI/EHCI to work */
  104. static u64 alchemy_ohci_dmamask = DMA_BIT_MASK(32);
  105. static u64 __maybe_unused alchemy_ehci_dmamask = DMA_BIT_MASK(32);
  106. static unsigned long alchemy_ohci_data[][2] __initdata = {
  107. [ALCHEMY_CPU_AU1000] = { AU1000_USB_OHCI_PHYS_ADDR, AU1000_USB_HOST_INT },
  108. [ALCHEMY_CPU_AU1500] = { AU1000_USB_OHCI_PHYS_ADDR, AU1500_USB_HOST_INT },
  109. [ALCHEMY_CPU_AU1100] = { AU1000_USB_OHCI_PHYS_ADDR, AU1100_USB_HOST_INT },
  110. [ALCHEMY_CPU_AU1550] = { AU1550_USB_OHCI_PHYS_ADDR, AU1550_USB_HOST_INT },
  111. [ALCHEMY_CPU_AU1200] = { AU1200_USB_OHCI_PHYS_ADDR, AU1200_USB_INT },
  112. };
  113. static unsigned long alchemy_ehci_data[][2] __initdata = {
  114. [ALCHEMY_CPU_AU1200] = { AU1200_USB_EHCI_PHYS_ADDR, AU1200_USB_INT },
  115. };
  116. static int __init _new_usbres(struct resource **r, struct platform_device **d)
  117. {
  118. *r = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
  119. if (!*r)
  120. return -ENOMEM;
  121. *d = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
  122. if (!*d) {
  123. kfree(*r);
  124. return -ENOMEM;
  125. }
  126. (*d)->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  127. (*d)->num_resources = 2;
  128. (*d)->resource = *r;
  129. return 0;
  130. }
  131. static void __init alchemy_setup_usb(int ctype)
  132. {
  133. struct resource *res;
  134. struct platform_device *pdev;
  135. /* setup OHCI0. Every variant has one */
  136. if (_new_usbres(&res, &pdev))
  137. return;
  138. res[0].start = alchemy_ohci_data[ctype][0];
  139. res[0].end = res[0].start + 0x100 - 1;
  140. res[0].flags = IORESOURCE_MEM;
  141. res[1].start = alchemy_ohci_data[ctype][1];
  142. res[1].end = res[1].start;
  143. res[1].flags = IORESOURCE_IRQ;
  144. pdev->name = "au1xxx-ohci";
  145. pdev->id = 0;
  146. pdev->dev.dma_mask = &alchemy_ohci_dmamask;
  147. if (platform_device_register(pdev))
  148. printk(KERN_INFO "Alchemy USB: cannot add OHCI0\n");
  149. /* setup EHCI0: Au1200 */
  150. if (ctype == ALCHEMY_CPU_AU1200) {
  151. if (_new_usbres(&res, &pdev))
  152. return;
  153. res[0].start = alchemy_ehci_data[ctype][0];
  154. res[0].end = res[0].start + 0x100 - 1;
  155. res[0].flags = IORESOURCE_MEM;
  156. res[1].start = alchemy_ehci_data[ctype][1];
  157. res[1].end = res[1].start;
  158. res[1].flags = IORESOURCE_IRQ;
  159. pdev->name = "au1xxx-ehci";
  160. pdev->id = 0;
  161. pdev->dev.dma_mask = &alchemy_ehci_dmamask;
  162. if (platform_device_register(pdev))
  163. printk(KERN_INFO "Alchemy USB: cannot add EHCI0\n");
  164. }
  165. }
  166. /*** AU1100 LCD controller ***/
  167. #ifdef CONFIG_FB_AU1100
  168. static struct resource au1100_lcd_resources[] = {
  169. [0] = {
  170. .start = AU1100_LCD_PHYS_ADDR,
  171. .end = AU1100_LCD_PHYS_ADDR + 0x800 - 1,
  172. .flags = IORESOURCE_MEM,
  173. },
  174. [1] = {
  175. .start = AU1100_LCD_INT,
  176. .end = AU1100_LCD_INT,
  177. .flags = IORESOURCE_IRQ,
  178. }
  179. };
  180. static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32);
  181. static struct platform_device au1100_lcd_device = {
  182. .name = "au1100-lcd",
  183. .id = 0,
  184. .dev = {
  185. .dma_mask = &au1100_lcd_dmamask,
  186. .coherent_dma_mask = DMA_BIT_MASK(32),
  187. },
  188. .num_resources = ARRAY_SIZE(au1100_lcd_resources),
  189. .resource = au1100_lcd_resources,
  190. };
  191. #endif
  192. #ifdef CONFIG_SOC_AU1200
  193. static struct resource au1200_lcd_resources[] = {
  194. [0] = {
  195. .start = AU1200_LCD_PHYS_ADDR,
  196. .end = AU1200_LCD_PHYS_ADDR + 0x800 - 1,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .start = AU1200_LCD_INT,
  201. .end = AU1200_LCD_INT,
  202. .flags = IORESOURCE_IRQ,
  203. }
  204. };
  205. static u64 au1200_lcd_dmamask = DMA_BIT_MASK(32);
  206. static struct platform_device au1200_lcd_device = {
  207. .name = "au1200-lcd",
  208. .id = 0,
  209. .dev = {
  210. .dma_mask = &au1200_lcd_dmamask,
  211. .coherent_dma_mask = DMA_BIT_MASK(32),
  212. },
  213. .num_resources = ARRAY_SIZE(au1200_lcd_resources),
  214. .resource = au1200_lcd_resources,
  215. };
  216. static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32);
  217. extern struct au1xmmc_platform_data au1xmmc_platdata[2];
  218. static struct resource au1200_mmc0_resources[] = {
  219. [0] = {
  220. .start = AU1100_SD0_PHYS_ADDR,
  221. .end = AU1100_SD0_PHYS_ADDR + 0xfff,
  222. .flags = IORESOURCE_MEM,
  223. },
  224. [1] = {
  225. .start = AU1200_SD_INT,
  226. .end = AU1200_SD_INT,
  227. .flags = IORESOURCE_IRQ,
  228. },
  229. [2] = {
  230. .start = DSCR_CMD0_SDMS_TX0,
  231. .end = DSCR_CMD0_SDMS_TX0,
  232. .flags = IORESOURCE_DMA,
  233. },
  234. [3] = {
  235. .start = DSCR_CMD0_SDMS_RX0,
  236. .end = DSCR_CMD0_SDMS_RX0,
  237. .flags = IORESOURCE_DMA,
  238. }
  239. };
  240. static struct platform_device au1200_mmc0_device = {
  241. .name = "au1xxx-mmc",
  242. .id = 0,
  243. .dev = {
  244. .dma_mask = &au1xxx_mmc_dmamask,
  245. .coherent_dma_mask = DMA_BIT_MASK(32),
  246. .platform_data = &au1xmmc_platdata[0],
  247. },
  248. .num_resources = ARRAY_SIZE(au1200_mmc0_resources),
  249. .resource = au1200_mmc0_resources,
  250. };
  251. #ifndef CONFIG_MIPS_DB1200
  252. static struct resource au1200_mmc1_resources[] = {
  253. [0] = {
  254. .start = AU1100_SD1_PHYS_ADDR,
  255. .end = AU1100_SD1_PHYS_ADDR + 0xfff,
  256. .flags = IORESOURCE_MEM,
  257. },
  258. [1] = {
  259. .start = AU1200_SD_INT,
  260. .end = AU1200_SD_INT,
  261. .flags = IORESOURCE_IRQ,
  262. },
  263. [2] = {
  264. .start = DSCR_CMD0_SDMS_TX1,
  265. .end = DSCR_CMD0_SDMS_TX1,
  266. .flags = IORESOURCE_DMA,
  267. },
  268. [3] = {
  269. .start = DSCR_CMD0_SDMS_RX1,
  270. .end = DSCR_CMD0_SDMS_RX1,
  271. .flags = IORESOURCE_DMA,
  272. }
  273. };
  274. static struct platform_device au1200_mmc1_device = {
  275. .name = "au1xxx-mmc",
  276. .id = 1,
  277. .dev = {
  278. .dma_mask = &au1xxx_mmc_dmamask,
  279. .coherent_dma_mask = DMA_BIT_MASK(32),
  280. .platform_data = &au1xmmc_platdata[1],
  281. },
  282. .num_resources = ARRAY_SIZE(au1200_mmc1_resources),
  283. .resource = au1200_mmc1_resources,
  284. };
  285. #endif /* #ifndef CONFIG_MIPS_DB1200 */
  286. #endif /* #ifdef CONFIG_SOC_AU1200 */
  287. /* All Alchemy demoboards with I2C have this #define in their headers */
  288. #ifdef SMBUS_PSC_BASE
  289. static struct resource pbdb_smbus_resources[] = {
  290. {
  291. .start = SMBUS_PSC_BASE,
  292. .end = SMBUS_PSC_BASE + 0xfff,
  293. .flags = IORESOURCE_MEM,
  294. },
  295. };
  296. static struct platform_device pbdb_smbus_device = {
  297. .name = "au1xpsc_smbus",
  298. .id = 0, /* bus number */
  299. .num_resources = ARRAY_SIZE(pbdb_smbus_resources),
  300. .resource = pbdb_smbus_resources,
  301. };
  302. #endif
  303. /* Macro to help defining the Ethernet MAC resources */
  304. #define MAC_RES_COUNT 4 /* MAC regs, MAC en, MAC INT, MACDMA regs */
  305. #define MAC_RES(_base, _enable, _irq, _macdma) \
  306. { \
  307. .start = _base, \
  308. .end = _base + 0xffff, \
  309. .flags = IORESOURCE_MEM, \
  310. }, \
  311. { \
  312. .start = _enable, \
  313. .end = _enable + 0x3, \
  314. .flags = IORESOURCE_MEM, \
  315. }, \
  316. { \
  317. .start = _irq, \
  318. .end = _irq, \
  319. .flags = IORESOURCE_IRQ \
  320. }, \
  321. { \
  322. .start = _macdma, \
  323. .end = _macdma + 0x1ff, \
  324. .flags = IORESOURCE_MEM, \
  325. }
  326. static struct resource au1xxx_eth0_resources[][MAC_RES_COUNT] __initdata = {
  327. [ALCHEMY_CPU_AU1000] = {
  328. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  329. AU1000_MACEN_PHYS_ADDR,
  330. AU1000_MAC0_DMA_INT,
  331. AU1000_MACDMA0_PHYS_ADDR)
  332. },
  333. [ALCHEMY_CPU_AU1500] = {
  334. MAC_RES(AU1500_MAC0_PHYS_ADDR,
  335. AU1500_MACEN_PHYS_ADDR,
  336. AU1500_MAC0_DMA_INT,
  337. AU1000_MACDMA0_PHYS_ADDR)
  338. },
  339. [ALCHEMY_CPU_AU1100] = {
  340. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  341. AU1000_MACEN_PHYS_ADDR,
  342. AU1100_MAC0_DMA_INT,
  343. AU1000_MACDMA0_PHYS_ADDR)
  344. },
  345. [ALCHEMY_CPU_AU1550] = {
  346. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  347. AU1000_MACEN_PHYS_ADDR,
  348. AU1550_MAC0_DMA_INT,
  349. AU1000_MACDMA0_PHYS_ADDR)
  350. },
  351. };
  352. static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
  353. .phy1_search_mac0 = 1,
  354. };
  355. static struct platform_device au1xxx_eth0_device = {
  356. .name = "au1000-eth",
  357. .id = 0,
  358. .num_resources = MAC_RES_COUNT,
  359. .dev.platform_data = &au1xxx_eth0_platform_data,
  360. };
  361. static struct resource au1xxx_eth1_resources[][MAC_RES_COUNT] __initdata = {
  362. [ALCHEMY_CPU_AU1000] = {
  363. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  364. AU1000_MACEN_PHYS_ADDR + 4,
  365. AU1000_MAC1_DMA_INT,
  366. AU1000_MACDMA1_PHYS_ADDR)
  367. },
  368. [ALCHEMY_CPU_AU1500] = {
  369. MAC_RES(AU1500_MAC1_PHYS_ADDR,
  370. AU1500_MACEN_PHYS_ADDR + 4,
  371. AU1500_MAC1_DMA_INT,
  372. AU1000_MACDMA1_PHYS_ADDR)
  373. },
  374. [ALCHEMY_CPU_AU1550] = {
  375. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  376. AU1000_MACEN_PHYS_ADDR + 4,
  377. AU1550_MAC1_DMA_INT,
  378. AU1000_MACDMA1_PHYS_ADDR)
  379. },
  380. };
  381. static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
  382. .phy1_search_mac0 = 1,
  383. };
  384. static struct platform_device au1xxx_eth1_device = {
  385. .name = "au1000-eth",
  386. .id = 1,
  387. .num_resources = MAC_RES_COUNT,
  388. .dev.platform_data = &au1xxx_eth1_platform_data,
  389. };
  390. void __init au1xxx_override_eth_cfg(unsigned int port,
  391. struct au1000_eth_platform_data *eth_data)
  392. {
  393. if (!eth_data || port > 1)
  394. return;
  395. if (port == 0)
  396. memcpy(&au1xxx_eth0_platform_data, eth_data,
  397. sizeof(struct au1000_eth_platform_data));
  398. else
  399. memcpy(&au1xxx_eth1_platform_data, eth_data,
  400. sizeof(struct au1000_eth_platform_data));
  401. }
  402. static void __init alchemy_setup_macs(int ctype)
  403. {
  404. int ret, i;
  405. unsigned char ethaddr[6];
  406. struct resource *macres;
  407. /* Handle 1st MAC */
  408. if (alchemy_get_macs(ctype) < 1)
  409. return;
  410. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  411. if (!macres) {
  412. printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
  413. return;
  414. }
  415. memcpy(macres, au1xxx_eth0_resources[ctype],
  416. sizeof(struct resource) * MAC_RES_COUNT);
  417. au1xxx_eth0_device.resource = macres;
  418. i = prom_get_ethernet_addr(ethaddr);
  419. if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
  420. memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);
  421. ret = platform_device_register(&au1xxx_eth0_device);
  422. if (ret)
  423. printk(KERN_INFO "Alchemy: failed to register MAC0\n");
  424. /* Handle 2nd MAC */
  425. if (alchemy_get_macs(ctype) < 2)
  426. return;
  427. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  428. if (!macres) {
  429. printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
  430. return;
  431. }
  432. memcpy(macres, au1xxx_eth1_resources[ctype],
  433. sizeof(struct resource) * MAC_RES_COUNT);
  434. au1xxx_eth1_device.resource = macres;
  435. ethaddr[5] += 1; /* next addr for 2nd MAC */
  436. if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
  437. memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
  438. /* Register second MAC if enabled in pinfunc */
  439. if (!(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2)) {
  440. ret = platform_device_register(&au1xxx_eth1_device);
  441. if (ret)
  442. printk(KERN_INFO "Alchemy: failed to register MAC1\n");
  443. }
  444. }
  445. static struct platform_device *au1xxx_platform_devices[] __initdata = {
  446. #ifdef CONFIG_FB_AU1100
  447. &au1100_lcd_device,
  448. #endif
  449. #ifdef CONFIG_SOC_AU1200
  450. &au1200_lcd_device,
  451. &au1200_mmc0_device,
  452. #ifndef CONFIG_MIPS_DB1200
  453. &au1200_mmc1_device,
  454. #endif
  455. #endif
  456. #ifdef SMBUS_PSC_BASE
  457. &pbdb_smbus_device,
  458. #endif
  459. };
  460. static int __init au1xxx_platform_init(void)
  461. {
  462. int err, ctype = alchemy_get_cputype();
  463. alchemy_setup_uarts(ctype);
  464. alchemy_setup_macs(ctype);
  465. alchemy_setup_usb(ctype);
  466. err = platform_add_devices(au1xxx_platform_devices,
  467. ARRAY_SIZE(au1xxx_platform_devices));
  468. return err;
  469. }
  470. arch_initcall(au1xxx_platform_init);