common.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * arch/arm/mach-orion/common.c
  3. *
  4. * Core functions for Marvell Orion System On Chip
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/serial_8250.h>
  16. #include <linux/mv643xx_eth.h>
  17. #include <linux/mv643xx_i2c.h>
  18. #include <asm/page.h>
  19. #include <asm/timex.h>
  20. #include <asm/mach/map.h>
  21. #include <asm/arch/hardware.h>
  22. #include "common.h"
  23. /*****************************************************************************
  24. * I/O Address Mapping
  25. ****************************************************************************/
  26. static struct map_desc orion_io_desc[] __initdata = {
  27. {
  28. .virtual = ORION_REGS_VIRT_BASE,
  29. .pfn = __phys_to_pfn(ORION_REGS_PHYS_BASE),
  30. .length = ORION_REGS_SIZE,
  31. .type = MT_DEVICE
  32. },
  33. {
  34. .virtual = ORION_PCIE_IO_VIRT_BASE,
  35. .pfn = __phys_to_pfn(ORION_PCIE_IO_PHYS_BASE),
  36. .length = ORION_PCIE_IO_SIZE,
  37. .type = MT_DEVICE
  38. },
  39. {
  40. .virtual = ORION_PCI_IO_VIRT_BASE,
  41. .pfn = __phys_to_pfn(ORION_PCI_IO_PHYS_BASE),
  42. .length = ORION_PCI_IO_SIZE,
  43. .type = MT_DEVICE
  44. },
  45. {
  46. .virtual = ORION_PCIE_WA_VIRT_BASE,
  47. .pfn = __phys_to_pfn(ORION_PCIE_WA_PHYS_BASE),
  48. .length = ORION_PCIE_WA_SIZE,
  49. .type = MT_DEVICE
  50. },
  51. };
  52. void __init orion_map_io(void)
  53. {
  54. iotable_init(orion_io_desc, ARRAY_SIZE(orion_io_desc));
  55. }
  56. /*****************************************************************************
  57. * UART
  58. ****************************************************************************/
  59. static struct resource orion_uart_resources[] = {
  60. {
  61. .start = UART0_PHYS_BASE,
  62. .end = UART0_PHYS_BASE + 0xff,
  63. .flags = IORESOURCE_MEM,
  64. },
  65. {
  66. .start = IRQ_ORION_UART0,
  67. .end = IRQ_ORION_UART0,
  68. .flags = IORESOURCE_IRQ,
  69. },
  70. {
  71. .start = UART1_PHYS_BASE,
  72. .end = UART1_PHYS_BASE + 0xff,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. {
  76. .start = IRQ_ORION_UART1,
  77. .end = IRQ_ORION_UART1,
  78. .flags = IORESOURCE_IRQ,
  79. },
  80. };
  81. static struct plat_serial8250_port orion_uart_data[] = {
  82. {
  83. .mapbase = UART0_PHYS_BASE,
  84. .membase = (char *)UART0_VIRT_BASE,
  85. .irq = IRQ_ORION_UART0,
  86. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  87. .iotype = UPIO_MEM,
  88. .regshift = 2,
  89. .uartclk = ORION_TCLK,
  90. },
  91. {
  92. .mapbase = UART1_PHYS_BASE,
  93. .membase = (char *)UART1_VIRT_BASE,
  94. .irq = IRQ_ORION_UART1,
  95. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  96. .iotype = UPIO_MEM,
  97. .regshift = 2,
  98. .uartclk = ORION_TCLK,
  99. },
  100. { },
  101. };
  102. static struct platform_device orion_uart = {
  103. .name = "serial8250",
  104. .id = PLAT8250_DEV_PLATFORM,
  105. .dev = {
  106. .platform_data = orion_uart_data,
  107. },
  108. .resource = orion_uart_resources,
  109. .num_resources = ARRAY_SIZE(orion_uart_resources),
  110. };
  111. /*******************************************************************************
  112. * USB Controller - 2 interfaces
  113. ******************************************************************************/
  114. static struct resource orion_ehci0_resources[] = {
  115. {
  116. .start = ORION_USB0_PHYS_BASE,
  117. .end = ORION_USB0_PHYS_BASE + SZ_4K,
  118. .flags = IORESOURCE_MEM,
  119. },
  120. {
  121. .start = IRQ_ORION_USB0_CTRL,
  122. .end = IRQ_ORION_USB0_CTRL,
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. };
  126. static struct resource orion_ehci1_resources[] = {
  127. {
  128. .start = ORION_USB1_PHYS_BASE,
  129. .end = ORION_USB1_PHYS_BASE + SZ_4K,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. {
  133. .start = IRQ_ORION_USB1_CTRL,
  134. .end = IRQ_ORION_USB1_CTRL,
  135. .flags = IORESOURCE_IRQ,
  136. },
  137. };
  138. static u64 ehci_dmamask = 0xffffffffUL;
  139. static struct platform_device orion_ehci0 = {
  140. .name = "orion-ehci",
  141. .id = 0,
  142. .dev = {
  143. .dma_mask = &ehci_dmamask,
  144. .coherent_dma_mask = 0xffffffff,
  145. },
  146. .resource = orion_ehci0_resources,
  147. .num_resources = ARRAY_SIZE(orion_ehci0_resources),
  148. };
  149. static struct platform_device orion_ehci1 = {
  150. .name = "orion-ehci",
  151. .id = 1,
  152. .dev = {
  153. .dma_mask = &ehci_dmamask,
  154. .coherent_dma_mask = 0xffffffff,
  155. },
  156. .resource = orion_ehci1_resources,
  157. .num_resources = ARRAY_SIZE(orion_ehci1_resources),
  158. };
  159. /*****************************************************************************
  160. * Gigabit Ethernet port
  161. * (The Orion and Discovery (MV643xx) families use the same Ethernet driver)
  162. ****************************************************************************/
  163. static struct resource orion_eth_shared_resources[] = {
  164. {
  165. .start = ORION_ETH_PHYS_BASE,
  166. .end = ORION_ETH_PHYS_BASE + 0xffff,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. };
  170. static struct platform_device orion_eth_shared = {
  171. .name = MV643XX_ETH_SHARED_NAME,
  172. .id = 0,
  173. .num_resources = 1,
  174. .resource = orion_eth_shared_resources,
  175. };
  176. static struct resource orion_eth_resources[] = {
  177. {
  178. .name = "eth irq",
  179. .start = IRQ_ORION_ETH_SUM,
  180. .end = IRQ_ORION_ETH_SUM,
  181. .flags = IORESOURCE_IRQ,
  182. }
  183. };
  184. static struct platform_device orion_eth = {
  185. .name = MV643XX_ETH_NAME,
  186. .id = 0,
  187. .num_resources = 1,
  188. .resource = orion_eth_resources,
  189. };
  190. void __init orion_eth_init(struct mv643xx_eth_platform_data *eth_data)
  191. {
  192. orion_eth.dev.platform_data = eth_data;
  193. platform_device_register(&orion_eth_shared);
  194. platform_device_register(&orion_eth);
  195. }
  196. /*****************************************************************************
  197. * I2C controller
  198. * (The Orion and Discovery (MV643xx) families share the same I2C controller)
  199. ****************************************************************************/
  200. static struct mv64xxx_i2c_pdata orion_i2c_pdata = {
  201. .freq_m = 8, /* assumes 166 MHz TCLK */
  202. .freq_n = 3,
  203. .timeout = 1000, /* Default timeout of 1 second */
  204. };
  205. static struct resource orion_i2c_resources[] = {
  206. {
  207. .name = "i2c base",
  208. .start = I2C_PHYS_BASE,
  209. .end = I2C_PHYS_BASE + 0x20 -1,
  210. .flags = IORESOURCE_MEM,
  211. },
  212. {
  213. .name = "i2c irq",
  214. .start = IRQ_ORION_I2C,
  215. .end = IRQ_ORION_I2C,
  216. .flags = IORESOURCE_IRQ,
  217. },
  218. };
  219. static struct platform_device orion_i2c = {
  220. .name = MV64XXX_I2C_CTLR_NAME,
  221. .id = 0,
  222. .num_resources = ARRAY_SIZE(orion_i2c_resources),
  223. .resource = orion_i2c_resources,
  224. .dev = {
  225. .platform_data = &orion_i2c_pdata,
  226. },
  227. };
  228. /*****************************************************************************
  229. * Sata port
  230. ****************************************************************************/
  231. static struct resource orion_sata_resources[] = {
  232. {
  233. .name = "sata base",
  234. .start = ORION_SATA_PHYS_BASE,
  235. .end = ORION_SATA_PHYS_BASE + 0x5000 - 1,
  236. .flags = IORESOURCE_MEM,
  237. },
  238. {
  239. .name = "sata irq",
  240. .start = IRQ_ORION_SATA,
  241. .end = IRQ_ORION_SATA,
  242. .flags = IORESOURCE_IRQ,
  243. },
  244. };
  245. static struct platform_device orion_sata = {
  246. .name = "sata_mv",
  247. .id = 0,
  248. .dev = {
  249. .coherent_dma_mask = 0xffffffff,
  250. },
  251. .num_resources = ARRAY_SIZE(orion_sata_resources),
  252. .resource = orion_sata_resources,
  253. };
  254. void __init orion_sata_init(struct mv_sata_platform_data *sata_data)
  255. {
  256. orion_sata.dev.platform_data = sata_data;
  257. platform_device_register(&orion_sata);
  258. }
  259. /*****************************************************************************
  260. * General
  261. ****************************************************************************/
  262. /*
  263. * Identify device ID and rev from PCIE configuration header space '0'.
  264. */
  265. static void orion_id(u32 *dev, u32 *rev, char **dev_name)
  266. {
  267. orion_pcie_id(dev, rev);
  268. if (*dev == MV88F5281_DEV_ID) {
  269. if (*rev == MV88F5281_REV_D2) {
  270. *dev_name = "MV88F5281-D2";
  271. } else if (*rev == MV88F5281_REV_D1) {
  272. *dev_name = "MV88F5281-D1";
  273. } else {
  274. *dev_name = "MV88F5281-Rev-Unsupported";
  275. }
  276. } else if (*dev == MV88F5182_DEV_ID) {
  277. if (*rev == MV88F5182_REV_A2) {
  278. *dev_name = "MV88F5182-A2";
  279. } else {
  280. *dev_name = "MV88F5182-Rev-Unsupported";
  281. }
  282. } else if (*dev == MV88F5181_DEV_ID) {
  283. if (*rev == MV88F5181_REV_B1) {
  284. *dev_name = "MV88F5181-Rev-B1";
  285. } else {
  286. *dev_name = "MV88F5181-Rev-Unsupported";
  287. }
  288. } else {
  289. *dev_name = "Device-Unknown";
  290. }
  291. }
  292. void __init orion_init(void)
  293. {
  294. char *dev_name;
  295. u32 dev, rev;
  296. orion_id(&dev, &rev, &dev_name);
  297. printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION_TCLK);
  298. /*
  299. * Setup Orion address map
  300. */
  301. orion_setup_cpu_wins();
  302. orion_setup_usb_wins();
  303. orion_setup_eth_wins();
  304. orion_setup_pci_wins();
  305. orion_setup_pcie_wins();
  306. if (dev == MV88F5182_DEV_ID)
  307. orion_setup_sata_wins();
  308. /*
  309. * REgister devices
  310. */
  311. platform_device_register(&orion_uart);
  312. platform_device_register(&orion_ehci0);
  313. if (dev == MV88F5182_DEV_ID)
  314. platform_device_register(&orion_ehci1);
  315. platform_device_register(&orion_i2c);
  316. }