common.c 9.2 KB

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