platform.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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/au1000.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. [ALCHEMY_CPU_AU1300] = {
  80. PORT(AU1300_UART0_PHYS_ADDR, AU1300_UART0_INT),
  81. PORT(AU1300_UART1_PHYS_ADDR, AU1300_UART1_INT),
  82. PORT(AU1300_UART2_PHYS_ADDR, AU1300_UART2_INT),
  83. PORT(AU1300_UART3_PHYS_ADDR, AU1300_UART3_INT),
  84. },
  85. };
  86. static struct platform_device au1xx0_uart_device = {
  87. .name = "serial8250",
  88. .id = PLAT8250_DEV_AU1X00,
  89. };
  90. static void __init alchemy_setup_uarts(int ctype)
  91. {
  92. unsigned int uartclk = get_au1x00_uart_baud_base() * 16;
  93. int s = sizeof(struct plat_serial8250_port);
  94. int c = alchemy_get_uarts(ctype);
  95. struct plat_serial8250_port *ports;
  96. ports = kzalloc(s * (c + 1), GFP_KERNEL);
  97. if (!ports) {
  98. printk(KERN_INFO "Alchemy: no memory for UART data\n");
  99. return;
  100. }
  101. memcpy(ports, au1x00_uart_data[ctype], s * c);
  102. au1xx0_uart_device.dev.platform_data = ports;
  103. /* Fill up uartclk. */
  104. for (s = 0; s < c; s++)
  105. ports[s].uartclk = uartclk;
  106. if (platform_device_register(&au1xx0_uart_device))
  107. printk(KERN_INFO "Alchemy: failed to register UARTs\n");
  108. }
  109. /* The dmamask must be set for OHCI/EHCI to work */
  110. static u64 alchemy_ohci_dmamask = DMA_BIT_MASK(32);
  111. static u64 __maybe_unused alchemy_ehci_dmamask = DMA_BIT_MASK(32);
  112. static unsigned long alchemy_ohci_data[][2] __initdata = {
  113. [ALCHEMY_CPU_AU1000] = { AU1000_USB_OHCI_PHYS_ADDR, AU1000_USB_HOST_INT },
  114. [ALCHEMY_CPU_AU1500] = { AU1000_USB_OHCI_PHYS_ADDR, AU1500_USB_HOST_INT },
  115. [ALCHEMY_CPU_AU1100] = { AU1000_USB_OHCI_PHYS_ADDR, AU1100_USB_HOST_INT },
  116. [ALCHEMY_CPU_AU1550] = { AU1550_USB_OHCI_PHYS_ADDR, AU1550_USB_HOST_INT },
  117. [ALCHEMY_CPU_AU1200] = { AU1200_USB_OHCI_PHYS_ADDR, AU1200_USB_INT },
  118. [ALCHEMY_CPU_AU1300] = { AU1300_USB_OHCI0_PHYS_ADDR, AU1300_USB_INT },
  119. };
  120. static unsigned long alchemy_ehci_data[][2] __initdata = {
  121. [ALCHEMY_CPU_AU1200] = { AU1200_USB_EHCI_PHYS_ADDR, AU1200_USB_INT },
  122. [ALCHEMY_CPU_AU1300] = { AU1300_USB_EHCI_PHYS_ADDR, AU1300_USB_INT },
  123. };
  124. static int __init _new_usbres(struct resource **r, struct platform_device **d)
  125. {
  126. *r = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
  127. if (!*r)
  128. return -ENOMEM;
  129. *d = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
  130. if (!*d) {
  131. kfree(*r);
  132. return -ENOMEM;
  133. }
  134. (*d)->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  135. (*d)->num_resources = 2;
  136. (*d)->resource = *r;
  137. return 0;
  138. }
  139. static void __init alchemy_setup_usb(int ctype)
  140. {
  141. struct resource *res;
  142. struct platform_device *pdev;
  143. /* setup OHCI0. Every variant has one */
  144. if (_new_usbres(&res, &pdev))
  145. return;
  146. res[0].start = alchemy_ohci_data[ctype][0];
  147. res[0].end = res[0].start + 0x100 - 1;
  148. res[0].flags = IORESOURCE_MEM;
  149. res[1].start = alchemy_ohci_data[ctype][1];
  150. res[1].end = res[1].start;
  151. res[1].flags = IORESOURCE_IRQ;
  152. pdev->name = "au1xxx-ohci";
  153. pdev->id = 0;
  154. pdev->dev.dma_mask = &alchemy_ohci_dmamask;
  155. if (platform_device_register(pdev))
  156. printk(KERN_INFO "Alchemy USB: cannot add OHCI0\n");
  157. /* setup EHCI0: Au1200/Au1300 */
  158. if ((ctype == ALCHEMY_CPU_AU1200) || (ctype == ALCHEMY_CPU_AU1300)) {
  159. if (_new_usbres(&res, &pdev))
  160. return;
  161. res[0].start = alchemy_ehci_data[ctype][0];
  162. res[0].end = res[0].start + 0x100 - 1;
  163. res[0].flags = IORESOURCE_MEM;
  164. res[1].start = alchemy_ehci_data[ctype][1];
  165. res[1].end = res[1].start;
  166. res[1].flags = IORESOURCE_IRQ;
  167. pdev->name = "au1xxx-ehci";
  168. pdev->id = 0;
  169. pdev->dev.dma_mask = &alchemy_ehci_dmamask;
  170. if (platform_device_register(pdev))
  171. printk(KERN_INFO "Alchemy USB: cannot add EHCI0\n");
  172. }
  173. /* Au1300: OHCI1 */
  174. if (ctype == ALCHEMY_CPU_AU1300) {
  175. if (_new_usbres(&res, &pdev))
  176. return;
  177. res[0].start = AU1300_USB_OHCI1_PHYS_ADDR;
  178. res[0].end = res[0].start + 0x100 - 1;
  179. res[0].flags = IORESOURCE_MEM;
  180. res[1].start = AU1300_USB_INT;
  181. res[1].end = res[1].start;
  182. res[1].flags = IORESOURCE_IRQ;
  183. pdev->name = "au1xxx-ohci";
  184. pdev->id = 1;
  185. pdev->dev.dma_mask = &alchemy_ohci_dmamask;
  186. if (platform_device_register(pdev))
  187. printk(KERN_INFO "Alchemy USB: cannot add OHCI1\n");
  188. }
  189. }
  190. /* Macro to help defining the Ethernet MAC resources */
  191. #define MAC_RES_COUNT 4 /* MAC regs, MAC en, MAC INT, MACDMA regs */
  192. #define MAC_RES(_base, _enable, _irq, _macdma) \
  193. { \
  194. .start = _base, \
  195. .end = _base + 0xffff, \
  196. .flags = IORESOURCE_MEM, \
  197. }, \
  198. { \
  199. .start = _enable, \
  200. .end = _enable + 0x3, \
  201. .flags = IORESOURCE_MEM, \
  202. }, \
  203. { \
  204. .start = _irq, \
  205. .end = _irq, \
  206. .flags = IORESOURCE_IRQ \
  207. }, \
  208. { \
  209. .start = _macdma, \
  210. .end = _macdma + 0x1ff, \
  211. .flags = IORESOURCE_MEM, \
  212. }
  213. static struct resource au1xxx_eth0_resources[][MAC_RES_COUNT] __initdata = {
  214. [ALCHEMY_CPU_AU1000] = {
  215. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  216. AU1000_MACEN_PHYS_ADDR,
  217. AU1000_MAC0_DMA_INT,
  218. AU1000_MACDMA0_PHYS_ADDR)
  219. },
  220. [ALCHEMY_CPU_AU1500] = {
  221. MAC_RES(AU1500_MAC0_PHYS_ADDR,
  222. AU1500_MACEN_PHYS_ADDR,
  223. AU1500_MAC0_DMA_INT,
  224. AU1000_MACDMA0_PHYS_ADDR)
  225. },
  226. [ALCHEMY_CPU_AU1100] = {
  227. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  228. AU1000_MACEN_PHYS_ADDR,
  229. AU1100_MAC0_DMA_INT,
  230. AU1000_MACDMA0_PHYS_ADDR)
  231. },
  232. [ALCHEMY_CPU_AU1550] = {
  233. MAC_RES(AU1000_MAC0_PHYS_ADDR,
  234. AU1000_MACEN_PHYS_ADDR,
  235. AU1550_MAC0_DMA_INT,
  236. AU1000_MACDMA0_PHYS_ADDR)
  237. },
  238. };
  239. static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
  240. .phy1_search_mac0 = 1,
  241. };
  242. static struct platform_device au1xxx_eth0_device = {
  243. .name = "au1000-eth",
  244. .id = 0,
  245. .num_resources = MAC_RES_COUNT,
  246. .dev.platform_data = &au1xxx_eth0_platform_data,
  247. };
  248. static struct resource au1xxx_eth1_resources[][MAC_RES_COUNT] __initdata = {
  249. [ALCHEMY_CPU_AU1000] = {
  250. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  251. AU1000_MACEN_PHYS_ADDR + 4,
  252. AU1000_MAC1_DMA_INT,
  253. AU1000_MACDMA1_PHYS_ADDR)
  254. },
  255. [ALCHEMY_CPU_AU1500] = {
  256. MAC_RES(AU1500_MAC1_PHYS_ADDR,
  257. AU1500_MACEN_PHYS_ADDR + 4,
  258. AU1500_MAC1_DMA_INT,
  259. AU1000_MACDMA1_PHYS_ADDR)
  260. },
  261. [ALCHEMY_CPU_AU1550] = {
  262. MAC_RES(AU1000_MAC1_PHYS_ADDR,
  263. AU1000_MACEN_PHYS_ADDR + 4,
  264. AU1550_MAC1_DMA_INT,
  265. AU1000_MACDMA1_PHYS_ADDR)
  266. },
  267. };
  268. static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
  269. .phy1_search_mac0 = 1,
  270. };
  271. static struct platform_device au1xxx_eth1_device = {
  272. .name = "au1000-eth",
  273. .id = 1,
  274. .num_resources = MAC_RES_COUNT,
  275. .dev.platform_data = &au1xxx_eth1_platform_data,
  276. };
  277. void __init au1xxx_override_eth_cfg(unsigned int port,
  278. struct au1000_eth_platform_data *eth_data)
  279. {
  280. if (!eth_data || port > 1)
  281. return;
  282. if (port == 0)
  283. memcpy(&au1xxx_eth0_platform_data, eth_data,
  284. sizeof(struct au1000_eth_platform_data));
  285. else
  286. memcpy(&au1xxx_eth1_platform_data, eth_data,
  287. sizeof(struct au1000_eth_platform_data));
  288. }
  289. static void __init alchemy_setup_macs(int ctype)
  290. {
  291. int ret, i;
  292. unsigned char ethaddr[6];
  293. struct resource *macres;
  294. /* Handle 1st MAC */
  295. if (alchemy_get_macs(ctype) < 1)
  296. return;
  297. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  298. if (!macres) {
  299. printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
  300. return;
  301. }
  302. memcpy(macres, au1xxx_eth0_resources[ctype],
  303. sizeof(struct resource) * MAC_RES_COUNT);
  304. au1xxx_eth0_device.resource = macres;
  305. i = prom_get_ethernet_addr(ethaddr);
  306. if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
  307. memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);
  308. ret = platform_device_register(&au1xxx_eth0_device);
  309. if (ret)
  310. printk(KERN_INFO "Alchemy: failed to register MAC0\n");
  311. /* Handle 2nd MAC */
  312. if (alchemy_get_macs(ctype) < 2)
  313. return;
  314. macres = kmalloc(sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
  315. if (!macres) {
  316. printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
  317. return;
  318. }
  319. memcpy(macres, au1xxx_eth1_resources[ctype],
  320. sizeof(struct resource) * MAC_RES_COUNT);
  321. au1xxx_eth1_device.resource = macres;
  322. ethaddr[5] += 1; /* next addr for 2nd MAC */
  323. if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
  324. memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
  325. /* Register second MAC if enabled in pinfunc */
  326. if (!(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2)) {
  327. ret = platform_device_register(&au1xxx_eth1_device);
  328. if (ret)
  329. printk(KERN_INFO "Alchemy: failed to register MAC1\n");
  330. }
  331. }
  332. static int __init au1xxx_platform_init(void)
  333. {
  334. int ctype = alchemy_get_cputype();
  335. alchemy_setup_uarts(ctype);
  336. alchemy_setup_macs(ctype);
  337. alchemy_setup_usb(ctype);
  338. return 0;
  339. }
  340. arch_initcall(au1xxx_platform_init);