platform.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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/platform_device.h>
  16. #include <linux/serial_8250.h>
  17. #include <linux/init.h>
  18. #include <asm/mach-au1x00/au1xxx.h>
  19. #include <asm/mach-au1x00/au1xxx_dbdma.h>
  20. #include <asm/mach-au1x00/au1100_mmc.h>
  21. #include <asm/mach-au1x00/au1xxx_eth.h>
  22. #include <prom.h>
  23. static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
  24. unsigned int old_state)
  25. {
  26. #ifdef CONFIG_SERIAL_8250
  27. switch (state) {
  28. case 0:
  29. alchemy_uart_enable(CPHYSADDR(port->membase));
  30. serial8250_do_pm(port, state, old_state);
  31. break;
  32. case 3: /* power off */
  33. serial8250_do_pm(port, state, old_state);
  34. alchemy_uart_disable(CPHYSADDR(port->membase));
  35. break;
  36. default:
  37. serial8250_do_pm(port, state, old_state);
  38. break;
  39. }
  40. #endif
  41. }
  42. #define PORT(_base, _irq) \
  43. { \
  44. .mapbase = _base, \
  45. .irq = _irq, \
  46. .regshift = 2, \
  47. .iotype = UPIO_AU, \
  48. .flags = UPF_SKIP_TEST | UPF_IOREMAP | \
  49. UPF_FIXED_TYPE, \
  50. .type = PORT_16550A, \
  51. .pm = alchemy_8250_pm, \
  52. }
  53. static struct plat_serial8250_port au1x00_uart_data[][4] __initdata = {
  54. [ALCHEMY_CPU_AU1000] = {
  55. PORT(AU1000_UART0_PHYS_ADDR, AU1000_UART0_INT),
  56. PORT(AU1000_UART1_PHYS_ADDR, AU1000_UART1_INT),
  57. PORT(AU1000_UART2_PHYS_ADDR, AU1000_UART2_INT),
  58. PORT(AU1000_UART3_PHYS_ADDR, AU1000_UART3_INT),
  59. },
  60. [ALCHEMY_CPU_AU1500] = {
  61. PORT(AU1000_UART0_PHYS_ADDR, AU1500_UART0_INT),
  62. PORT(AU1000_UART3_PHYS_ADDR, AU1500_UART3_INT),
  63. },
  64. [ALCHEMY_CPU_AU1100] = {
  65. PORT(AU1000_UART0_PHYS_ADDR, AU1100_UART0_INT),
  66. PORT(AU1000_UART1_PHYS_ADDR, AU1100_UART1_INT),
  67. PORT(AU1000_UART3_PHYS_ADDR, AU1100_UART3_INT),
  68. },
  69. [ALCHEMY_CPU_AU1550] = {
  70. PORT(AU1000_UART0_PHYS_ADDR, AU1550_UART0_INT),
  71. PORT(AU1000_UART1_PHYS_ADDR, AU1550_UART1_INT),
  72. PORT(AU1000_UART3_PHYS_ADDR, AU1550_UART3_INT),
  73. },
  74. [ALCHEMY_CPU_AU1200] = {
  75. PORT(AU1000_UART0_PHYS_ADDR, AU1200_UART0_INT),
  76. PORT(AU1000_UART1_PHYS_ADDR, AU1200_UART1_INT),
  77. },
  78. };
  79. static struct platform_device au1xx0_uart_device = {
  80. .name = "serial8250",
  81. .id = PLAT8250_DEV_AU1X00,
  82. };
  83. static void __init alchemy_setup_uarts(int ctype)
  84. {
  85. unsigned int uartclk = get_au1x00_uart_baud_base() * 16;
  86. int s = sizeof(struct plat_serial8250_port);
  87. int c = alchemy_get_uarts(ctype);
  88. struct plat_serial8250_port *ports;
  89. ports = kzalloc(s * (c + 1), GFP_KERNEL);
  90. if (!ports) {
  91. printk(KERN_INFO "Alchemy: no memory for UART data\n");
  92. return;
  93. }
  94. memcpy(ports, au1x00_uart_data[ctype], s * c);
  95. au1xx0_uart_device.dev.platform_data = ports;
  96. /* Fill up uartclk. */
  97. for (s = 0; s < c; s++)
  98. ports[s].uartclk = uartclk;
  99. if (platform_device_register(&au1xx0_uart_device))
  100. printk(KERN_INFO "Alchemy: failed to register UARTs\n");
  101. }
  102. /* OHCI (USB full speed host controller) */
  103. static struct resource au1xxx_usb_ohci_resources[] = {
  104. [0] = {
  105. .start = USB_OHCI_BASE,
  106. .end = USB_OHCI_BASE + USB_OHCI_LEN - 1,
  107. .flags = IORESOURCE_MEM,
  108. },
  109. [1] = {
  110. .start = FOR_PLATFORM_C_USB_HOST_INT,
  111. .end = FOR_PLATFORM_C_USB_HOST_INT,
  112. .flags = IORESOURCE_IRQ,
  113. },
  114. };
  115. /* The dmamask must be set for OHCI to work */
  116. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  117. static struct platform_device au1xxx_usb_ohci_device = {
  118. .name = "au1xxx-ohci",
  119. .id = 0,
  120. .dev = {
  121. .dma_mask = &ohci_dmamask,
  122. .coherent_dma_mask = DMA_BIT_MASK(32),
  123. },
  124. .num_resources = ARRAY_SIZE(au1xxx_usb_ohci_resources),
  125. .resource = au1xxx_usb_ohci_resources,
  126. };
  127. /*** AU1100 LCD controller ***/
  128. #ifdef CONFIG_FB_AU1100
  129. static struct resource au1100_lcd_resources[] = {
  130. [0] = {
  131. .start = LCD_PHYS_ADDR,
  132. .end = LCD_PHYS_ADDR + 0x800 - 1,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. [1] = {
  136. .start = AU1100_LCD_INT,
  137. .end = AU1100_LCD_INT,
  138. .flags = IORESOURCE_IRQ,
  139. }
  140. };
  141. static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32);
  142. static struct platform_device au1100_lcd_device = {
  143. .name = "au1100-lcd",
  144. .id = 0,
  145. .dev = {
  146. .dma_mask = &au1100_lcd_dmamask,
  147. .coherent_dma_mask = DMA_BIT_MASK(32),
  148. },
  149. .num_resources = ARRAY_SIZE(au1100_lcd_resources),
  150. .resource = au1100_lcd_resources,
  151. };
  152. #endif
  153. #ifdef CONFIG_SOC_AU1200
  154. /* EHCI (USB high speed host controller) */
  155. static struct resource au1xxx_usb_ehci_resources[] = {
  156. [0] = {
  157. .start = USB_EHCI_BASE,
  158. .end = USB_EHCI_BASE + USB_EHCI_LEN - 1,
  159. .flags = IORESOURCE_MEM,
  160. },
  161. [1] = {
  162. .start = AU1200_USB_INT,
  163. .end = AU1200_USB_INT,
  164. .flags = IORESOURCE_IRQ,
  165. },
  166. };
  167. static u64 ehci_dmamask = DMA_BIT_MASK(32);
  168. static struct platform_device au1xxx_usb_ehci_device = {
  169. .name = "au1xxx-ehci",
  170. .id = 0,
  171. .dev = {
  172. .dma_mask = &ehci_dmamask,
  173. .coherent_dma_mask = DMA_BIT_MASK(32),
  174. },
  175. .num_resources = ARRAY_SIZE(au1xxx_usb_ehci_resources),
  176. .resource = au1xxx_usb_ehci_resources,
  177. };
  178. /* Au1200 UDC (USB gadget controller) */
  179. static struct resource au1xxx_usb_gdt_resources[] = {
  180. [0] = {
  181. .start = USB_UDC_BASE,
  182. .end = USB_UDC_BASE + USB_UDC_LEN - 1,
  183. .flags = IORESOURCE_MEM,
  184. },
  185. [1] = {
  186. .start = AU1200_USB_INT,
  187. .end = AU1200_USB_INT,
  188. .flags = IORESOURCE_IRQ,
  189. },
  190. };
  191. static u64 udc_dmamask = DMA_BIT_MASK(32);
  192. static struct platform_device au1xxx_usb_gdt_device = {
  193. .name = "au1xxx-udc",
  194. .id = 0,
  195. .dev = {
  196. .dma_mask = &udc_dmamask,
  197. .coherent_dma_mask = DMA_BIT_MASK(32),
  198. },
  199. .num_resources = ARRAY_SIZE(au1xxx_usb_gdt_resources),
  200. .resource = au1xxx_usb_gdt_resources,
  201. };
  202. /* Au1200 UOC (USB OTG controller) */
  203. static struct resource au1xxx_usb_otg_resources[] = {
  204. [0] = {
  205. .start = USB_UOC_BASE,
  206. .end = USB_UOC_BASE + USB_UOC_LEN - 1,
  207. .flags = IORESOURCE_MEM,
  208. },
  209. [1] = {
  210. .start = AU1200_USB_INT,
  211. .end = AU1200_USB_INT,
  212. .flags = IORESOURCE_IRQ,
  213. },
  214. };
  215. static u64 uoc_dmamask = DMA_BIT_MASK(32);
  216. static struct platform_device au1xxx_usb_otg_device = {
  217. .name = "au1xxx-uoc",
  218. .id = 0,
  219. .dev = {
  220. .dma_mask = &uoc_dmamask,
  221. .coherent_dma_mask = DMA_BIT_MASK(32),
  222. },
  223. .num_resources = ARRAY_SIZE(au1xxx_usb_otg_resources),
  224. .resource = au1xxx_usb_otg_resources,
  225. };
  226. static struct resource au1200_lcd_resources[] = {
  227. [0] = {
  228. .start = LCD_PHYS_ADDR,
  229. .end = LCD_PHYS_ADDR + 0x800 - 1,
  230. .flags = IORESOURCE_MEM,
  231. },
  232. [1] = {
  233. .start = AU1200_LCD_INT,
  234. .end = AU1200_LCD_INT,
  235. .flags = IORESOURCE_IRQ,
  236. }
  237. };
  238. static u64 au1200_lcd_dmamask = DMA_BIT_MASK(32);
  239. static struct platform_device au1200_lcd_device = {
  240. .name = "au1200-lcd",
  241. .id = 0,
  242. .dev = {
  243. .dma_mask = &au1200_lcd_dmamask,
  244. .coherent_dma_mask = DMA_BIT_MASK(32),
  245. },
  246. .num_resources = ARRAY_SIZE(au1200_lcd_resources),
  247. .resource = au1200_lcd_resources,
  248. };
  249. static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32);
  250. extern struct au1xmmc_platform_data au1xmmc_platdata[2];
  251. static struct resource au1200_mmc0_resources[] = {
  252. [0] = {
  253. .start = SD0_PHYS_ADDR,
  254. .end = SD0_PHYS_ADDR + 0x7ffff,
  255. .flags = IORESOURCE_MEM,
  256. },
  257. [1] = {
  258. .start = AU1200_SD_INT,
  259. .end = AU1200_SD_INT,
  260. .flags = IORESOURCE_IRQ,
  261. },
  262. [2] = {
  263. .start = DSCR_CMD0_SDMS_TX0,
  264. .end = DSCR_CMD0_SDMS_TX0,
  265. .flags = IORESOURCE_DMA,
  266. },
  267. [3] = {
  268. .start = DSCR_CMD0_SDMS_RX0,
  269. .end = DSCR_CMD0_SDMS_RX0,
  270. .flags = IORESOURCE_DMA,
  271. }
  272. };
  273. static struct platform_device au1200_mmc0_device = {
  274. .name = "au1xxx-mmc",
  275. .id = 0,
  276. .dev = {
  277. .dma_mask = &au1xxx_mmc_dmamask,
  278. .coherent_dma_mask = DMA_BIT_MASK(32),
  279. .platform_data = &au1xmmc_platdata[0],
  280. },
  281. .num_resources = ARRAY_SIZE(au1200_mmc0_resources),
  282. .resource = au1200_mmc0_resources,
  283. };
  284. #ifndef CONFIG_MIPS_DB1200
  285. static struct resource au1200_mmc1_resources[] = {
  286. [0] = {
  287. .start = SD1_PHYS_ADDR,
  288. .end = SD1_PHYS_ADDR + 0x7ffff,
  289. .flags = IORESOURCE_MEM,
  290. },
  291. [1] = {
  292. .start = AU1200_SD_INT,
  293. .end = AU1200_SD_INT,
  294. .flags = IORESOURCE_IRQ,
  295. },
  296. [2] = {
  297. .start = DSCR_CMD0_SDMS_TX1,
  298. .end = DSCR_CMD0_SDMS_TX1,
  299. .flags = IORESOURCE_DMA,
  300. },
  301. [3] = {
  302. .start = DSCR_CMD0_SDMS_RX1,
  303. .end = DSCR_CMD0_SDMS_RX1,
  304. .flags = IORESOURCE_DMA,
  305. }
  306. };
  307. static struct platform_device au1200_mmc1_device = {
  308. .name = "au1xxx-mmc",
  309. .id = 1,
  310. .dev = {
  311. .dma_mask = &au1xxx_mmc_dmamask,
  312. .coherent_dma_mask = DMA_BIT_MASK(32),
  313. .platform_data = &au1xmmc_platdata[1],
  314. },
  315. .num_resources = ARRAY_SIZE(au1200_mmc1_resources),
  316. .resource = au1200_mmc1_resources,
  317. };
  318. #endif /* #ifndef CONFIG_MIPS_DB1200 */
  319. #endif /* #ifdef CONFIG_SOC_AU1200 */
  320. /* All Alchemy demoboards with I2C have this #define in their headers */
  321. #ifdef SMBUS_PSC_BASE
  322. static struct resource pbdb_smbus_resources[] = {
  323. {
  324. .start = CPHYSADDR(SMBUS_PSC_BASE),
  325. .end = CPHYSADDR(SMBUS_PSC_BASE + 0xfffff),
  326. .flags = IORESOURCE_MEM,
  327. },
  328. };
  329. static struct platform_device pbdb_smbus_device = {
  330. .name = "au1xpsc_smbus",
  331. .id = 0, /* bus number */
  332. .num_resources = ARRAY_SIZE(pbdb_smbus_resources),
  333. .resource = pbdb_smbus_resources,
  334. };
  335. #endif
  336. /* Macro to help defining the Ethernet MAC resources */
  337. #define MAC_RES(_base, _enable, _irq) \
  338. { \
  339. .start = CPHYSADDR(_base), \
  340. .end = CPHYSADDR(_base + 0xffff), \
  341. .flags = IORESOURCE_MEM, \
  342. }, \
  343. { \
  344. .start = CPHYSADDR(_enable), \
  345. .end = CPHYSADDR(_enable + 0x3), \
  346. .flags = IORESOURCE_MEM, \
  347. }, \
  348. { \
  349. .start = _irq, \
  350. .end = _irq, \
  351. .flags = IORESOURCE_IRQ \
  352. }
  353. static struct resource au1xxx_eth0_resources[] = {
  354. #if defined(CONFIG_SOC_AU1000)
  355. MAC_RES(AU1000_ETH0_BASE, AU1000_MAC0_ENABLE, AU1000_MAC0_DMA_INT),
  356. #elif defined(CONFIG_SOC_AU1100)
  357. MAC_RES(AU1100_ETH0_BASE, AU1100_MAC0_ENABLE, AU1100_MAC0_DMA_INT),
  358. #elif defined(CONFIG_SOC_AU1550)
  359. MAC_RES(AU1550_ETH0_BASE, AU1550_MAC0_ENABLE, AU1550_MAC0_DMA_INT),
  360. #elif defined(CONFIG_SOC_AU1500)
  361. MAC_RES(AU1500_ETH0_BASE, AU1500_MAC0_ENABLE, AU1500_MAC0_DMA_INT),
  362. #endif
  363. };
  364. static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
  365. .phy1_search_mac0 = 1,
  366. };
  367. static struct platform_device au1xxx_eth0_device = {
  368. .name = "au1000-eth",
  369. .id = 0,
  370. .num_resources = ARRAY_SIZE(au1xxx_eth0_resources),
  371. .resource = au1xxx_eth0_resources,
  372. .dev.platform_data = &au1xxx_eth0_platform_data,
  373. };
  374. #ifndef CONFIG_SOC_AU1100
  375. static struct resource au1xxx_eth1_resources[] = {
  376. #if defined(CONFIG_SOC_AU1000)
  377. MAC_RES(AU1000_ETH1_BASE, AU1000_MAC1_ENABLE, AU1000_MAC1_DMA_INT),
  378. #elif defined(CONFIG_SOC_AU1550)
  379. MAC_RES(AU1550_ETH1_BASE, AU1550_MAC1_ENABLE, AU1550_MAC1_DMA_INT),
  380. #elif defined(CONFIG_SOC_AU1500)
  381. MAC_RES(AU1500_ETH1_BASE, AU1500_MAC1_ENABLE, AU1500_MAC1_DMA_INT),
  382. #endif
  383. };
  384. static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
  385. .phy1_search_mac0 = 1,
  386. };
  387. static struct platform_device au1xxx_eth1_device = {
  388. .name = "au1000-eth",
  389. .id = 1,
  390. .num_resources = ARRAY_SIZE(au1xxx_eth1_resources),
  391. .resource = au1xxx_eth1_resources,
  392. .dev.platform_data = &au1xxx_eth1_platform_data,
  393. };
  394. #endif
  395. void __init au1xxx_override_eth_cfg(unsigned int port,
  396. struct au1000_eth_platform_data *eth_data)
  397. {
  398. if (!eth_data || port > 1)
  399. return;
  400. if (port == 0)
  401. memcpy(&au1xxx_eth0_platform_data, eth_data,
  402. sizeof(struct au1000_eth_platform_data));
  403. #ifndef CONFIG_SOC_AU1100
  404. else
  405. memcpy(&au1xxx_eth1_platform_data, eth_data,
  406. sizeof(struct au1000_eth_platform_data));
  407. #endif
  408. }
  409. static struct platform_device *au1xxx_platform_devices[] __initdata = {
  410. &au1xxx_usb_ohci_device,
  411. #ifdef CONFIG_FB_AU1100
  412. &au1100_lcd_device,
  413. #endif
  414. #ifdef CONFIG_SOC_AU1200
  415. &au1xxx_usb_ehci_device,
  416. &au1xxx_usb_gdt_device,
  417. &au1xxx_usb_otg_device,
  418. &au1200_lcd_device,
  419. &au1200_mmc0_device,
  420. #ifndef CONFIG_MIPS_DB1200
  421. &au1200_mmc1_device,
  422. #endif
  423. #endif
  424. #ifdef SMBUS_PSC_BASE
  425. &pbdb_smbus_device,
  426. #endif
  427. &au1xxx_eth0_device,
  428. };
  429. static int __init au1xxx_platform_init(void)
  430. {
  431. int err, i, ctype = alchemy_get_cputype();
  432. unsigned char ethaddr[6];
  433. alchemy_setup_uarts(ctype);
  434. /* use firmware-provided mac addr if available and necessary */
  435. i = prom_get_ethernet_addr(ethaddr);
  436. if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
  437. memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);
  438. err = platform_add_devices(au1xxx_platform_devices,
  439. ARRAY_SIZE(au1xxx_platform_devices));
  440. #ifndef CONFIG_SOC_AU1100
  441. ethaddr[5] += 1; /* next addr for 2nd MAC */
  442. if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
  443. memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
  444. /* Register second MAC if enabled in pinfunc */
  445. if (!err && !(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2))
  446. err = platform_device_register(&au1xxx_eth1_device);
  447. #endif
  448. return err;
  449. }
  450. arch_initcall(au1xxx_platform_init);