platform.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright (c) 2011 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/phy.h>
  13. #include <linux/serial_8250.h>
  14. #include <linux/stmmac.h>
  15. #include <linux/usb/ehci_pdriver.h>
  16. #include <asm-generic/sizes.h>
  17. #include <cpufreq.h>
  18. #include <loongson1.h>
  19. /* 8250/16550 compatible UART */
  20. #define LS1X_UART(_id) \
  21. { \
  22. .mapbase = LS1X_UART ## _id ## _BASE, \
  23. .irq = LS1X_UART ## _id ## _IRQ, \
  24. .iotype = UPIO_MEM, \
  25. .flags = UPF_IOREMAP | UPF_FIXED_TYPE, \
  26. .type = PORT_16550A, \
  27. }
  28. static struct plat_serial8250_port ls1x_serial8250_pdata[] = {
  29. LS1X_UART(0),
  30. LS1X_UART(1),
  31. LS1X_UART(2),
  32. LS1X_UART(3),
  33. {},
  34. };
  35. struct platform_device ls1x_uart_pdev = {
  36. .name = "serial8250",
  37. .id = PLAT8250_DEV_PLATFORM,
  38. .dev = {
  39. .platform_data = ls1x_serial8250_pdata,
  40. },
  41. };
  42. void __init ls1x_serial_setup(struct platform_device *pdev)
  43. {
  44. struct clk *clk;
  45. struct plat_serial8250_port *p;
  46. clk = clk_get(&pdev->dev, pdev->name);
  47. if (IS_ERR(clk)) {
  48. pr_err("unable to get %s clock, err=%ld",
  49. pdev->name, PTR_ERR(clk));
  50. return;
  51. }
  52. clk_prepare_enable(clk);
  53. for (p = pdev->dev.platform_data; p->flags != 0; ++p)
  54. p->uartclk = clk_get_rate(clk);
  55. }
  56. /* CPUFreq */
  57. static struct plat_ls1x_cpufreq ls1x_cpufreq_pdata = {
  58. .clk_name = "cpu_clk",
  59. .osc_clk_name = "osc_33m_clk",
  60. .max_freq = 266 * 1000,
  61. .min_freq = 33 * 1000,
  62. };
  63. struct platform_device ls1x_cpufreq_pdev = {
  64. .name = "ls1x-cpufreq",
  65. .dev = {
  66. .platform_data = &ls1x_cpufreq_pdata,
  67. },
  68. };
  69. /* Synopsys Ethernet GMAC */
  70. static struct stmmac_mdio_bus_data ls1x_mdio_bus_data = {
  71. .phy_mask = 0,
  72. };
  73. static struct stmmac_dma_cfg ls1x_eth_dma_cfg = {
  74. .pbl = 1,
  75. };
  76. int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
  77. {
  78. struct plat_stmmacenet_data *plat_dat = NULL;
  79. u32 val;
  80. val = __raw_readl(LS1X_MUX_CTRL1);
  81. plat_dat = dev_get_platdata(&pdev->dev);
  82. if (plat_dat->bus_id) {
  83. __raw_writel(__raw_readl(LS1X_MUX_CTRL0) | GMAC1_USE_UART1 |
  84. GMAC1_USE_UART0, LS1X_MUX_CTRL0);
  85. switch (plat_dat->interface) {
  86. case PHY_INTERFACE_MODE_RGMII:
  87. val &= ~(GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
  88. break;
  89. case PHY_INTERFACE_MODE_MII:
  90. val |= (GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
  91. break;
  92. default:
  93. pr_err("unsupported mii mode %d\n",
  94. plat_dat->interface);
  95. return -ENOTSUPP;
  96. }
  97. val &= ~GMAC1_SHUT;
  98. } else {
  99. switch (plat_dat->interface) {
  100. case PHY_INTERFACE_MODE_RGMII:
  101. val &= ~(GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
  102. break;
  103. case PHY_INTERFACE_MODE_MII:
  104. val |= (GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
  105. break;
  106. default:
  107. pr_err("unsupported mii mode %d\n",
  108. plat_dat->interface);
  109. return -ENOTSUPP;
  110. }
  111. val &= ~GMAC0_SHUT;
  112. }
  113. __raw_writel(val, LS1X_MUX_CTRL1);
  114. return 0;
  115. }
  116. static struct plat_stmmacenet_data ls1x_eth0_pdata = {
  117. .bus_id = 0,
  118. .phy_addr = -1,
  119. .interface = PHY_INTERFACE_MODE_MII,
  120. .mdio_bus_data = &ls1x_mdio_bus_data,
  121. .dma_cfg = &ls1x_eth_dma_cfg,
  122. .has_gmac = 1,
  123. .tx_coe = 1,
  124. .init = ls1x_eth_mux_init,
  125. };
  126. static struct resource ls1x_eth0_resources[] = {
  127. [0] = {
  128. .start = LS1X_GMAC0_BASE,
  129. .end = LS1X_GMAC0_BASE + SZ_64K - 1,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. [1] = {
  133. .name = "macirq",
  134. .start = LS1X_GMAC0_IRQ,
  135. .flags = IORESOURCE_IRQ,
  136. },
  137. };
  138. struct platform_device ls1x_eth0_pdev = {
  139. .name = "stmmaceth",
  140. .id = 0,
  141. .num_resources = ARRAY_SIZE(ls1x_eth0_resources),
  142. .resource = ls1x_eth0_resources,
  143. .dev = {
  144. .platform_data = &ls1x_eth0_pdata,
  145. },
  146. };
  147. static struct plat_stmmacenet_data ls1x_eth1_pdata = {
  148. .bus_id = 1,
  149. .phy_addr = -1,
  150. .interface = PHY_INTERFACE_MODE_MII,
  151. .mdio_bus_data = &ls1x_mdio_bus_data,
  152. .dma_cfg = &ls1x_eth_dma_cfg,
  153. .has_gmac = 1,
  154. .tx_coe = 1,
  155. .init = ls1x_eth_mux_init,
  156. };
  157. static struct resource ls1x_eth1_resources[] = {
  158. [0] = {
  159. .start = LS1X_GMAC1_BASE,
  160. .end = LS1X_GMAC1_BASE + SZ_64K - 1,
  161. .flags = IORESOURCE_MEM,
  162. },
  163. [1] = {
  164. .name = "macirq",
  165. .start = LS1X_GMAC1_IRQ,
  166. .flags = IORESOURCE_IRQ,
  167. },
  168. };
  169. struct platform_device ls1x_eth1_pdev = {
  170. .name = "stmmaceth",
  171. .id = 1,
  172. .num_resources = ARRAY_SIZE(ls1x_eth1_resources),
  173. .resource = ls1x_eth1_resources,
  174. .dev = {
  175. .platform_data = &ls1x_eth1_pdata,
  176. },
  177. };
  178. /* USB EHCI */
  179. static u64 ls1x_ehci_dmamask = DMA_BIT_MASK(32);
  180. static struct resource ls1x_ehci_resources[] = {
  181. [0] = {
  182. .start = LS1X_EHCI_BASE,
  183. .end = LS1X_EHCI_BASE + SZ_32K - 1,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. [1] = {
  187. .start = LS1X_EHCI_IRQ,
  188. .flags = IORESOURCE_IRQ,
  189. },
  190. };
  191. static struct usb_ehci_pdata ls1x_ehci_pdata = {
  192. };
  193. struct platform_device ls1x_ehci_pdev = {
  194. .name = "ehci-platform",
  195. .id = -1,
  196. .num_resources = ARRAY_SIZE(ls1x_ehci_resources),
  197. .resource = ls1x_ehci_resources,
  198. .dev = {
  199. .dma_mask = &ls1x_ehci_dmamask,
  200. .platform_data = &ls1x_ehci_pdata,
  201. },
  202. };
  203. /* Real Time Clock */
  204. struct platform_device ls1x_rtc_pdev = {
  205. .name = "ls1x-rtc",
  206. .id = -1,
  207. };