platform.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. /* OHCI (USB full speed host controller) */
  104. static struct resource au1xxx_usb_ohci_resources[] = {
  105. [0] = {
  106. .start = USB_OHCI_BASE,
  107. .end = USB_OHCI_BASE + USB_OHCI_LEN - 1,
  108. .flags = IORESOURCE_MEM,
  109. },
  110. [1] = {
  111. .start = FOR_PLATFORM_C_USB_HOST_INT,
  112. .end = FOR_PLATFORM_C_USB_HOST_INT,
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. };
  116. /* The dmamask must be set for OHCI to work */
  117. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  118. static struct platform_device au1xxx_usb_ohci_device = {
  119. .name = "au1xxx-ohci",
  120. .id = 0,
  121. .dev = {
  122. .dma_mask = &ohci_dmamask,
  123. .coherent_dma_mask = DMA_BIT_MASK(32),
  124. },
  125. .num_resources = ARRAY_SIZE(au1xxx_usb_ohci_resources),
  126. .resource = au1xxx_usb_ohci_resources,
  127. };
  128. /*** AU1100 LCD controller ***/
  129. #ifdef CONFIG_FB_AU1100
  130. static struct resource au1100_lcd_resources[] = {
  131. [0] = {
  132. .start = LCD_PHYS_ADDR,
  133. .end = LCD_PHYS_ADDR + 0x800 - 1,
  134. .flags = IORESOURCE_MEM,
  135. },
  136. [1] = {
  137. .start = AU1100_LCD_INT,
  138. .end = AU1100_LCD_INT,
  139. .flags = IORESOURCE_IRQ,
  140. }
  141. };
  142. static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32);
  143. static struct platform_device au1100_lcd_device = {
  144. .name = "au1100-lcd",
  145. .id = 0,
  146. .dev = {
  147. .dma_mask = &au1100_lcd_dmamask,
  148. .coherent_dma_mask = DMA_BIT_MASK(32),
  149. },
  150. .num_resources = ARRAY_SIZE(au1100_lcd_resources),
  151. .resource = au1100_lcd_resources,
  152. };
  153. #endif
  154. #ifdef CONFIG_SOC_AU1200
  155. /* EHCI (USB high speed host controller) */
  156. static struct resource au1xxx_usb_ehci_resources[] = {
  157. [0] = {
  158. .start = USB_EHCI_BASE,
  159. .end = USB_EHCI_BASE + USB_EHCI_LEN - 1,
  160. .flags = IORESOURCE_MEM,
  161. },
  162. [1] = {
  163. .start = AU1200_USB_INT,
  164. .end = AU1200_USB_INT,
  165. .flags = IORESOURCE_IRQ,
  166. },
  167. };
  168. static u64 ehci_dmamask = DMA_BIT_MASK(32);
  169. static struct platform_device au1xxx_usb_ehci_device = {
  170. .name = "au1xxx-ehci",
  171. .id = 0,
  172. .dev = {
  173. .dma_mask = &ehci_dmamask,
  174. .coherent_dma_mask = DMA_BIT_MASK(32),
  175. },
  176. .num_resources = ARRAY_SIZE(au1xxx_usb_ehci_resources),
  177. .resource = au1xxx_usb_ehci_resources,
  178. };
  179. /* Au1200 UDC (USB gadget controller) */
  180. static struct resource au1xxx_usb_gdt_resources[] = {
  181. [0] = {
  182. .start = USB_UDC_BASE,
  183. .end = USB_UDC_BASE + USB_UDC_LEN - 1,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. [1] = {
  187. .start = AU1200_USB_INT,
  188. .end = AU1200_USB_INT,
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static u64 udc_dmamask = DMA_BIT_MASK(32);
  193. static struct platform_device au1xxx_usb_gdt_device = {
  194. .name = "au1xxx-udc",
  195. .id = 0,
  196. .dev = {
  197. .dma_mask = &udc_dmamask,
  198. .coherent_dma_mask = DMA_BIT_MASK(32),
  199. },
  200. .num_resources = ARRAY_SIZE(au1xxx_usb_gdt_resources),
  201. .resource = au1xxx_usb_gdt_resources,
  202. };
  203. /* Au1200 UOC (USB OTG controller) */
  204. static struct resource au1xxx_usb_otg_resources[] = {
  205. [0] = {
  206. .start = USB_UOC_BASE,
  207. .end = USB_UOC_BASE + USB_UOC_LEN - 1,
  208. .flags = IORESOURCE_MEM,
  209. },
  210. [1] = {
  211. .start = AU1200_USB_INT,
  212. .end = AU1200_USB_INT,
  213. .flags = IORESOURCE_IRQ,
  214. },
  215. };
  216. static u64 uoc_dmamask = DMA_BIT_MASK(32);
  217. static struct platform_device au1xxx_usb_otg_device = {
  218. .name = "au1xxx-uoc",
  219. .id = 0,
  220. .dev = {
  221. .dma_mask = &uoc_dmamask,
  222. .coherent_dma_mask = DMA_BIT_MASK(32),
  223. },
  224. .num_resources = ARRAY_SIZE(au1xxx_usb_otg_resources),
  225. .resource = au1xxx_usb_otg_resources,
  226. };
  227. static struct resource au1200_lcd_resources[] = {
  228. [0] = {
  229. .start = LCD_PHYS_ADDR,
  230. .end = LCD_PHYS_ADDR + 0x800 - 1,
  231. .flags = IORESOURCE_MEM,
  232. },
  233. [1] = {
  234. .start = AU1200_LCD_INT,
  235. .end = AU1200_LCD_INT,
  236. .flags = IORESOURCE_IRQ,
  237. }
  238. };
  239. static u64 au1200_lcd_dmamask = DMA_BIT_MASK(32);
  240. static struct platform_device au1200_lcd_device = {
  241. .name = "au1200-lcd",
  242. .id = 0,
  243. .dev = {
  244. .dma_mask = &au1200_lcd_dmamask,
  245. .coherent_dma_mask = DMA_BIT_MASK(32),
  246. },
  247. .num_resources = ARRAY_SIZE(au1200_lcd_resources),
  248. .resource = au1200_lcd_resources,
  249. };
  250. static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32);
  251. extern struct au1xmmc_platform_data au1xmmc_platdata[2];
  252. static struct resource au1200_mmc0_resources[] = {
  253. [0] = {
  254. .start = AU1100_SD0_PHYS_ADDR,
  255. .end = AU1100_SD0_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_TX0,
  265. .end = DSCR_CMD0_SDMS_TX0,
  266. .flags = IORESOURCE_DMA,
  267. },
  268. [3] = {
  269. .start = DSCR_CMD0_SDMS_RX0,
  270. .end = DSCR_CMD0_SDMS_RX0,
  271. .flags = IORESOURCE_DMA,
  272. }
  273. };
  274. static struct platform_device au1200_mmc0_device = {
  275. .name = "au1xxx-mmc",
  276. .id = 0,
  277. .dev = {
  278. .dma_mask = &au1xxx_mmc_dmamask,
  279. .coherent_dma_mask = DMA_BIT_MASK(32),
  280. .platform_data = &au1xmmc_platdata[0],
  281. },
  282. .num_resources = ARRAY_SIZE(au1200_mmc0_resources),
  283. .resource = au1200_mmc0_resources,
  284. };
  285. #ifndef CONFIG_MIPS_DB1200
  286. static struct resource au1200_mmc1_resources[] = {
  287. [0] = {
  288. .start = AU1100_SD1_PHYS_ADDR,
  289. .end = AU1100_SD1_PHYS_ADDR + 0xfff,
  290. .flags = IORESOURCE_MEM,
  291. },
  292. [1] = {
  293. .start = AU1200_SD_INT,
  294. .end = AU1200_SD_INT,
  295. .flags = IORESOURCE_IRQ,
  296. },
  297. [2] = {
  298. .start = DSCR_CMD0_SDMS_TX1,
  299. .end = DSCR_CMD0_SDMS_TX1,
  300. .flags = IORESOURCE_DMA,
  301. },
  302. [3] = {
  303. .start = DSCR_CMD0_SDMS_RX1,
  304. .end = DSCR_CMD0_SDMS_RX1,
  305. .flags = IORESOURCE_DMA,
  306. }
  307. };
  308. static struct platform_device au1200_mmc1_device = {
  309. .name = "au1xxx-mmc",
  310. .id = 1,
  311. .dev = {
  312. .dma_mask = &au1xxx_mmc_dmamask,
  313. .coherent_dma_mask = DMA_BIT_MASK(32),
  314. .platform_data = &au1xmmc_platdata[1],
  315. },
  316. .num_resources = ARRAY_SIZE(au1200_mmc1_resources),
  317. .resource = au1200_mmc1_resources,
  318. };
  319. #endif /* #ifndef CONFIG_MIPS_DB1200 */
  320. #endif /* #ifdef CONFIG_SOC_AU1200 */
  321. /* All Alchemy demoboards with I2C have this #define in their headers */
  322. #ifdef SMBUS_PSC_BASE
  323. static struct resource pbdb_smbus_resources[] = {
  324. {
  325. .start = CPHYSADDR(SMBUS_PSC_BASE),
  326. .end = CPHYSADDR(SMBUS_PSC_BASE + 0xfffff),
  327. .flags = IORESOURCE_MEM,
  328. },
  329. };
  330. static struct platform_device pbdb_smbus_device = {
  331. .name = "au1xpsc_smbus",
  332. .id = 0, /* bus number */
  333. .num_resources = ARRAY_SIZE(pbdb_smbus_resources),
  334. .resource = pbdb_smbus_resources,
  335. };
  336. #endif
  337. /* Macro to help defining the Ethernet MAC resources */
  338. #define MAC_RES_COUNT 3 /* MAC regs base, MAC enable reg, MAC INT */
  339. #define MAC_RES(_base, _enable, _irq) \
  340. { \
  341. .start = _base, \
  342. .end = _base + 0xffff, \
  343. .flags = IORESOURCE_MEM, \
  344. }, \
  345. { \
  346. .start = _enable, \
  347. .end = _enable + 0x3, \
  348. .flags = IORESOURCE_MEM, \
  349. }, \
  350. { \
  351. .start = _irq, \
  352. .end = _irq, \
  353. .flags = IORESOURCE_IRQ \
  354. }
  355. static struct resource au1xxx_eth0_resources[][MAC_RES_COUNT] __initdata = {
  356. [ALCHEMY_CPU_AU1000] = {
  357. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  358. AU1000_MACEN_PHYS_ADDR,
  359. AU1000_MAC0_DMA_INT)
  360. },
  361. [ALCHEMY_CPU_AU1500] = {
  362. MAC_RES(AU1500_MAC0_PHYS_ADDR,
  363. AU1500_MACEN_PHYS_ADDR,
  364. AU1500_MAC0_DMA_INT)
  365. },
  366. [ALCHEMY_CPU_AU1100] = {
  367. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  368. AU1000_MACEN_PHYS_ADDR,
  369. AU1100_MAC0_DMA_INT)
  370. },
  371. [ALCHEMY_CPU_AU1550] = {
  372. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  373. AU1000_MACEN_PHYS_ADDR,
  374. AU1550_MAC0_DMA_INT)
  375. },
  376. };
  377. static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
  378. .phy1_search_mac0 = 1,
  379. };
  380. static struct platform_device au1xxx_eth0_device = {
  381. .name = "au1000-eth",
  382. .id = 0,
  383. .num_resources = MAC_RES_COUNT,
  384. .dev.platform_data = &au1xxx_eth0_platform_data,
  385. };
  386. static struct resource au1xxx_eth1_resources[][MAC_RES_COUNT] __initdata = {
  387. [ALCHEMY_CPU_AU1000] = {
  388. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  389. AU1000_MACEN_PHYS_ADDR + 4,
  390. AU1000_MAC1_DMA_INT)
  391. },
  392. [ALCHEMY_CPU_AU1500] = {
  393. MAC_RES(AU1500_MAC1_PHYS_ADDR,
  394. AU1500_MACEN_PHYS_ADDR + 4,
  395. AU1500_MAC1_DMA_INT)
  396. },
  397. [ALCHEMY_CPU_AU1550] = {
  398. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  399. AU1000_MACEN_PHYS_ADDR + 4,
  400. AU1550_MAC1_DMA_INT)
  401. },
  402. };
  403. static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
  404. .phy1_search_mac0 = 1,
  405. };
  406. static struct platform_device au1xxx_eth1_device = {
  407. .name = "au1000-eth",
  408. .id = 1,
  409. .num_resources = MAC_RES_COUNT,
  410. .dev.platform_data = &au1xxx_eth1_platform_data,
  411. };
  412. void __init au1xxx_override_eth_cfg(unsigned int port,
  413. struct au1000_eth_platform_data *eth_data)
  414. {
  415. if (!eth_data || port > 1)
  416. return;
  417. if (port == 0)
  418. memcpy(&au1xxx_eth0_platform_data, eth_data,
  419. sizeof(struct au1000_eth_platform_data));
  420. else
  421. memcpy(&au1xxx_eth1_platform_data, eth_data,
  422. sizeof(struct au1000_eth_platform_data));
  423. }
  424. static void __init alchemy_setup_macs(int ctype)
  425. {
  426. int ret, i;
  427. unsigned char ethaddr[6];
  428. struct resource *macres;
  429. /* Handle 1st MAC */
  430. if (alchemy_get_macs(ctype) < 1)
  431. return;
  432. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  433. if (!macres) {
  434. printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
  435. return;
  436. }
  437. memcpy(macres, au1xxx_eth0_resources[ctype],
  438. sizeof(struct resource) * MAC_RES_COUNT);
  439. au1xxx_eth0_device.resource = macres;
  440. i = prom_get_ethernet_addr(ethaddr);
  441. if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
  442. memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);
  443. ret = platform_device_register(&au1xxx_eth0_device);
  444. if (!ret)
  445. printk(KERN_INFO "Alchemy: failed to register MAC0\n");
  446. /* Handle 2nd MAC */
  447. if (alchemy_get_macs(ctype) < 2)
  448. return;
  449. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  450. if (!macres) {
  451. printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
  452. return;
  453. }
  454. memcpy(macres, au1xxx_eth1_resources[ctype],
  455. sizeof(struct resource) * MAC_RES_COUNT);
  456. au1xxx_eth1_device.resource = macres;
  457. ethaddr[5] += 1; /* next addr for 2nd MAC */
  458. if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
  459. memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
  460. /* Register second MAC if enabled in pinfunc */
  461. if (!(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2)) {
  462. ret = platform_device_register(&au1xxx_eth1_device);
  463. if (ret)
  464. printk(KERN_INFO "Alchemy: failed to register MAC1\n");
  465. }
  466. }
  467. static struct platform_device *au1xxx_platform_devices[] __initdata = {
  468. &au1xxx_usb_ohci_device,
  469. #ifdef CONFIG_FB_AU1100
  470. &au1100_lcd_device,
  471. #endif
  472. #ifdef CONFIG_SOC_AU1200
  473. &au1xxx_usb_ehci_device,
  474. &au1xxx_usb_gdt_device,
  475. &au1xxx_usb_otg_device,
  476. &au1200_lcd_device,
  477. &au1200_mmc0_device,
  478. #ifndef CONFIG_MIPS_DB1200
  479. &au1200_mmc1_device,
  480. #endif
  481. #endif
  482. #ifdef SMBUS_PSC_BASE
  483. &pbdb_smbus_device,
  484. #endif
  485. };
  486. static int __init au1xxx_platform_init(void)
  487. {
  488. int err, ctype = alchemy_get_cputype();
  489. alchemy_setup_uarts(ctype);
  490. alchemy_setup_macs(ctype);
  491. err = platform_add_devices(au1xxx_platform_devices,
  492. ARRAY_SIZE(au1xxx_platform_devices));
  493. return err;
  494. }
  495. arch_initcall(au1xxx_platform_init);