platform.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Copyright (c) 2011-2016 Zhang, Keguang <keguang.zhang@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/err.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/sizes.h>
  14. #include <linux/phy.h>
  15. #include <linux/serial_8250.h>
  16. #include <linux/stmmac.h>
  17. #include <linux/usb/ehci_pdriver.h>
  18. #include <loongson1.h>
  19. #include <cpufreq.h>
  20. #include <dma.h>
  21. #include <nand.h>
  22. /* 8250/16550 compatible UART */
  23. #define LS1X_UART(_id) \
  24. { \
  25. .mapbase = LS1X_UART ## _id ## _BASE, \
  26. .irq = LS1X_UART ## _id ## _IRQ, \
  27. .iotype = UPIO_MEM, \
  28. .flags = UPF_IOREMAP | UPF_FIXED_TYPE, \
  29. .type = PORT_16550A, \
  30. }
  31. static struct plat_serial8250_port ls1x_serial8250_pdata[] = {
  32. LS1X_UART(0),
  33. LS1X_UART(1),
  34. LS1X_UART(2),
  35. LS1X_UART(3),
  36. {},
  37. };
  38. struct platform_device ls1x_uart_pdev = {
  39. .name = "serial8250",
  40. .id = PLAT8250_DEV_PLATFORM,
  41. .dev = {
  42. .platform_data = ls1x_serial8250_pdata,
  43. },
  44. };
  45. void __init ls1x_serial_set_uartclk(struct platform_device *pdev)
  46. {
  47. struct clk *clk;
  48. struct plat_serial8250_port *p;
  49. clk = clk_get(&pdev->dev, pdev->name);
  50. if (IS_ERR(clk)) {
  51. pr_err("unable to get %s clock, err=%ld",
  52. pdev->name, PTR_ERR(clk));
  53. return;
  54. }
  55. clk_prepare_enable(clk);
  56. for (p = pdev->dev.platform_data; p->flags != 0; ++p)
  57. p->uartclk = clk_get_rate(clk);
  58. }
  59. /* CPUFreq */
  60. static struct plat_ls1x_cpufreq ls1x_cpufreq_pdata = {
  61. .clk_name = "cpu_clk",
  62. .osc_clk_name = "osc_33m_clk",
  63. .max_freq = 266 * 1000,
  64. .min_freq = 33 * 1000,
  65. };
  66. struct platform_device ls1x_cpufreq_pdev = {
  67. .name = "ls1x-cpufreq",
  68. .dev = {
  69. .platform_data = &ls1x_cpufreq_pdata,
  70. },
  71. };
  72. /* DMA */
  73. static struct resource ls1x_dma_resources[] = {
  74. [0] = {
  75. .start = LS1X_DMAC_BASE,
  76. .end = LS1X_DMAC_BASE + SZ_4 - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. [1] = {
  80. .start = LS1X_DMA0_IRQ,
  81. .end = LS1X_DMA0_IRQ,
  82. .flags = IORESOURCE_IRQ,
  83. },
  84. [2] = {
  85. .start = LS1X_DMA1_IRQ,
  86. .end = LS1X_DMA1_IRQ,
  87. .flags = IORESOURCE_IRQ,
  88. },
  89. [3] = {
  90. .start = LS1X_DMA2_IRQ,
  91. .end = LS1X_DMA2_IRQ,
  92. .flags = IORESOURCE_IRQ,
  93. },
  94. };
  95. struct platform_device ls1x_dma_pdev = {
  96. .name = "ls1x-dma",
  97. .id = -1,
  98. .num_resources = ARRAY_SIZE(ls1x_dma_resources),
  99. .resource = ls1x_dma_resources,
  100. };
  101. void __init ls1x_dma_set_platdata(struct plat_ls1x_dma *pdata)
  102. {
  103. ls1x_dma_pdev.dev.platform_data = pdata;
  104. }
  105. /* Synopsys Ethernet GMAC */
  106. static struct stmmac_mdio_bus_data ls1x_mdio_bus_data = {
  107. .phy_mask = 0,
  108. };
  109. static struct stmmac_dma_cfg ls1x_eth_dma_cfg = {
  110. .pbl = 1,
  111. };
  112. int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
  113. {
  114. struct plat_stmmacenet_data *plat_dat = NULL;
  115. u32 val;
  116. val = __raw_readl(LS1X_MUX_CTRL1);
  117. plat_dat = dev_get_platdata(&pdev->dev);
  118. if (plat_dat->bus_id) {
  119. __raw_writel(__raw_readl(LS1X_MUX_CTRL0) | GMAC1_USE_UART1 |
  120. GMAC1_USE_UART0, LS1X_MUX_CTRL0);
  121. switch (plat_dat->interface) {
  122. case PHY_INTERFACE_MODE_RGMII:
  123. val &= ~(GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
  124. break;
  125. case PHY_INTERFACE_MODE_MII:
  126. val |= (GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
  127. break;
  128. default:
  129. pr_err("unsupported mii mode %d\n",
  130. plat_dat->interface);
  131. return -ENOTSUPP;
  132. }
  133. val &= ~GMAC1_SHUT;
  134. } else {
  135. switch (plat_dat->interface) {
  136. case PHY_INTERFACE_MODE_RGMII:
  137. val &= ~(GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
  138. break;
  139. case PHY_INTERFACE_MODE_MII:
  140. val |= (GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
  141. break;
  142. default:
  143. pr_err("unsupported mii mode %d\n",
  144. plat_dat->interface);
  145. return -ENOTSUPP;
  146. }
  147. val &= ~GMAC0_SHUT;
  148. }
  149. __raw_writel(val, LS1X_MUX_CTRL1);
  150. return 0;
  151. }
  152. static struct plat_stmmacenet_data ls1x_eth0_pdata = {
  153. .bus_id = 0,
  154. .phy_addr = -1,
  155. .interface = PHY_INTERFACE_MODE_MII,
  156. .mdio_bus_data = &ls1x_mdio_bus_data,
  157. .dma_cfg = &ls1x_eth_dma_cfg,
  158. .has_gmac = 1,
  159. .tx_coe = 1,
  160. .init = ls1x_eth_mux_init,
  161. };
  162. static struct resource ls1x_eth0_resources[] = {
  163. [0] = {
  164. .start = LS1X_GMAC0_BASE,
  165. .end = LS1X_GMAC0_BASE + SZ_64K - 1,
  166. .flags = IORESOURCE_MEM,
  167. },
  168. [1] = {
  169. .name = "macirq",
  170. .start = LS1X_GMAC0_IRQ,
  171. .flags = IORESOURCE_IRQ,
  172. },
  173. };
  174. struct platform_device ls1x_eth0_pdev = {
  175. .name = "stmmaceth",
  176. .id = 0,
  177. .num_resources = ARRAY_SIZE(ls1x_eth0_resources),
  178. .resource = ls1x_eth0_resources,
  179. .dev = {
  180. .platform_data = &ls1x_eth0_pdata,
  181. },
  182. };
  183. static struct plat_stmmacenet_data ls1x_eth1_pdata = {
  184. .bus_id = 1,
  185. .phy_addr = -1,
  186. .interface = PHY_INTERFACE_MODE_MII,
  187. .mdio_bus_data = &ls1x_mdio_bus_data,
  188. .dma_cfg = &ls1x_eth_dma_cfg,
  189. .has_gmac = 1,
  190. .tx_coe = 1,
  191. .init = ls1x_eth_mux_init,
  192. };
  193. static struct resource ls1x_eth1_resources[] = {
  194. [0] = {
  195. .start = LS1X_GMAC1_BASE,
  196. .end = LS1X_GMAC1_BASE + SZ_64K - 1,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .name = "macirq",
  201. .start = LS1X_GMAC1_IRQ,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. struct platform_device ls1x_eth1_pdev = {
  206. .name = "stmmaceth",
  207. .id = 1,
  208. .num_resources = ARRAY_SIZE(ls1x_eth1_resources),
  209. .resource = ls1x_eth1_resources,
  210. .dev = {
  211. .platform_data = &ls1x_eth1_pdata,
  212. },
  213. };
  214. /* GPIO */
  215. static struct resource ls1x_gpio0_resources[] = {
  216. [0] = {
  217. .start = LS1X_GPIO0_BASE,
  218. .end = LS1X_GPIO0_BASE + SZ_4 - 1,
  219. .flags = IORESOURCE_MEM,
  220. },
  221. };
  222. struct platform_device ls1x_gpio0_pdev = {
  223. .name = "ls1x-gpio",
  224. .id = 0,
  225. .num_resources = ARRAY_SIZE(ls1x_gpio0_resources),
  226. .resource = ls1x_gpio0_resources,
  227. };
  228. static struct resource ls1x_gpio1_resources[] = {
  229. [0] = {
  230. .start = LS1X_GPIO1_BASE,
  231. .end = LS1X_GPIO1_BASE + SZ_4 - 1,
  232. .flags = IORESOURCE_MEM,
  233. },
  234. };
  235. struct platform_device ls1x_gpio1_pdev = {
  236. .name = "ls1x-gpio",
  237. .id = 1,
  238. .num_resources = ARRAY_SIZE(ls1x_gpio1_resources),
  239. .resource = ls1x_gpio1_resources,
  240. };
  241. /* NAND Flash */
  242. static struct resource ls1x_nand_resources[] = {
  243. [0] = {
  244. .start = LS1X_NAND_BASE,
  245. .end = LS1X_NAND_BASE + SZ_32 - 1,
  246. .flags = IORESOURCE_MEM,
  247. },
  248. [1] = {
  249. /* DMA channel 0 is dedicated to NAND */
  250. .start = LS1X_DMA_CHANNEL0,
  251. .end = LS1X_DMA_CHANNEL0,
  252. .flags = IORESOURCE_DMA,
  253. },
  254. };
  255. struct platform_device ls1x_nand_pdev = {
  256. .name = "ls1x-nand",
  257. .id = -1,
  258. .num_resources = ARRAY_SIZE(ls1x_nand_resources),
  259. .resource = ls1x_nand_resources,
  260. };
  261. void __init ls1x_nand_set_platdata(struct plat_ls1x_nand *pdata)
  262. {
  263. ls1x_nand_pdev.dev.platform_data = pdata;
  264. }
  265. /* USB EHCI */
  266. static u64 ls1x_ehci_dmamask = DMA_BIT_MASK(32);
  267. static struct resource ls1x_ehci_resources[] = {
  268. [0] = {
  269. .start = LS1X_EHCI_BASE,
  270. .end = LS1X_EHCI_BASE + SZ_32K - 1,
  271. .flags = IORESOURCE_MEM,
  272. },
  273. [1] = {
  274. .start = LS1X_EHCI_IRQ,
  275. .flags = IORESOURCE_IRQ,
  276. },
  277. };
  278. static struct usb_ehci_pdata ls1x_ehci_pdata = {
  279. };
  280. struct platform_device ls1x_ehci_pdev = {
  281. .name = "ehci-platform",
  282. .id = -1,
  283. .num_resources = ARRAY_SIZE(ls1x_ehci_resources),
  284. .resource = ls1x_ehci_resources,
  285. .dev = {
  286. .dma_mask = &ls1x_ehci_dmamask,
  287. .platform_data = &ls1x_ehci_pdata,
  288. },
  289. };
  290. /* Real Time Clock */
  291. struct platform_device ls1x_rtc_pdev = {
  292. .name = "ls1x-rtc",
  293. .id = -1,
  294. };