platform.c 13 KB

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