common.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * arch/arm/mach-orion5x/common.c
  3. *
  4. * Core functions for Marvell Orion 5x SoCs
  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/mbus.h>
  17. #include <linux/mv643xx_eth.h>
  18. #include <linux/mv643xx_i2c.h>
  19. #include <linux/ata_platform.h>
  20. #include <asm/page.h>
  21. #include <asm/setup.h>
  22. #include <asm/timex.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/mach/time.h>
  26. #include <asm/arch/hardware.h>
  27. #include <asm/arch/orion5x.h>
  28. #include <asm/plat-orion/ehci-orion.h>
  29. #include <asm/plat-orion/orion_nand.h>
  30. #include <asm/plat-orion/time.h>
  31. #include "common.h"
  32. /*****************************************************************************
  33. * I/O Address Mapping
  34. ****************************************************************************/
  35. static struct map_desc orion5x_io_desc[] __initdata = {
  36. {
  37. .virtual = ORION5X_REGS_VIRT_BASE,
  38. .pfn = __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
  39. .length = ORION5X_REGS_SIZE,
  40. .type = MT_DEVICE,
  41. }, {
  42. .virtual = ORION5X_PCIE_IO_VIRT_BASE,
  43. .pfn = __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
  44. .length = ORION5X_PCIE_IO_SIZE,
  45. .type = MT_DEVICE,
  46. }, {
  47. .virtual = ORION5X_PCI_IO_VIRT_BASE,
  48. .pfn = __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
  49. .length = ORION5X_PCI_IO_SIZE,
  50. .type = MT_DEVICE,
  51. }, {
  52. .virtual = ORION5X_PCIE_WA_VIRT_BASE,
  53. .pfn = __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
  54. .length = ORION5X_PCIE_WA_SIZE,
  55. .type = MT_DEVICE,
  56. },
  57. };
  58. void __init orion5x_map_io(void)
  59. {
  60. iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
  61. }
  62. /*****************************************************************************
  63. * EHCI
  64. ****************************************************************************/
  65. static struct orion_ehci_data orion5x_ehci_data = {
  66. .dram = &orion5x_mbus_dram_info,
  67. };
  68. static u64 ehci_dmamask = 0xffffffffUL;
  69. /*****************************************************************************
  70. * EHCI0
  71. ****************************************************************************/
  72. static struct resource orion5x_ehci0_resources[] = {
  73. {
  74. .start = ORION5X_USB0_PHYS_BASE,
  75. .end = ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
  76. .flags = IORESOURCE_MEM,
  77. }, {
  78. .start = IRQ_ORION5X_USB0_CTRL,
  79. .end = IRQ_ORION5X_USB0_CTRL,
  80. .flags = IORESOURCE_IRQ,
  81. },
  82. };
  83. static struct platform_device orion5x_ehci0 = {
  84. .name = "orion-ehci",
  85. .id = 0,
  86. .dev = {
  87. .dma_mask = &ehci_dmamask,
  88. .coherent_dma_mask = 0xffffffff,
  89. .platform_data = &orion5x_ehci_data,
  90. },
  91. .resource = orion5x_ehci0_resources,
  92. .num_resources = ARRAY_SIZE(orion5x_ehci0_resources),
  93. };
  94. void __init orion5x_ehci0_init(void)
  95. {
  96. platform_device_register(&orion5x_ehci0);
  97. }
  98. /*****************************************************************************
  99. * EHCI1
  100. ****************************************************************************/
  101. static struct resource orion5x_ehci1_resources[] = {
  102. {
  103. .start = ORION5X_USB1_PHYS_BASE,
  104. .end = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
  105. .flags = IORESOURCE_MEM,
  106. }, {
  107. .start = IRQ_ORION5X_USB1_CTRL,
  108. .end = IRQ_ORION5X_USB1_CTRL,
  109. .flags = IORESOURCE_IRQ,
  110. },
  111. };
  112. static struct platform_device orion5x_ehci1 = {
  113. .name = "orion-ehci",
  114. .id = 1,
  115. .dev = {
  116. .dma_mask = &ehci_dmamask,
  117. .coherent_dma_mask = 0xffffffff,
  118. .platform_data = &orion5x_ehci_data,
  119. },
  120. .resource = orion5x_ehci1_resources,
  121. .num_resources = ARRAY_SIZE(orion5x_ehci1_resources),
  122. };
  123. void __init orion5x_ehci1_init(void)
  124. {
  125. platform_device_register(&orion5x_ehci1);
  126. }
  127. /*****************************************************************************
  128. * GigE
  129. ****************************************************************************/
  130. struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data = {
  131. .dram = &orion5x_mbus_dram_info,
  132. .t_clk = ORION5X_TCLK,
  133. };
  134. static struct resource orion5x_eth_shared_resources[] = {
  135. {
  136. .start = ORION5X_ETH_PHYS_BASE + 0x2000,
  137. .end = ORION5X_ETH_PHYS_BASE + 0x3fff,
  138. .flags = IORESOURCE_MEM,
  139. },
  140. };
  141. static struct platform_device orion5x_eth_shared = {
  142. .name = MV643XX_ETH_SHARED_NAME,
  143. .id = 0,
  144. .dev = {
  145. .platform_data = &orion5x_eth_shared_data,
  146. },
  147. .num_resources = 1,
  148. .resource = orion5x_eth_shared_resources,
  149. };
  150. static struct resource orion5x_eth_resources[] = {
  151. {
  152. .name = "eth irq",
  153. .start = IRQ_ORION5X_ETH_SUM,
  154. .end = IRQ_ORION5X_ETH_SUM,
  155. .flags = IORESOURCE_IRQ,
  156. },
  157. };
  158. static struct platform_device orion5x_eth = {
  159. .name = MV643XX_ETH_NAME,
  160. .id = 0,
  161. .num_resources = 1,
  162. .resource = orion5x_eth_resources,
  163. };
  164. void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
  165. {
  166. eth_data->shared = &orion5x_eth_shared;
  167. orion5x_eth.dev.platform_data = eth_data;
  168. platform_device_register(&orion5x_eth_shared);
  169. platform_device_register(&orion5x_eth);
  170. }
  171. /*****************************************************************************
  172. * I2C
  173. ****************************************************************************/
  174. static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
  175. .freq_m = 8, /* assumes 166 MHz TCLK */
  176. .freq_n = 3,
  177. .timeout = 1000, /* Default timeout of 1 second */
  178. };
  179. static struct resource orion5x_i2c_resources[] = {
  180. {
  181. .name = "i2c base",
  182. .start = I2C_PHYS_BASE,
  183. .end = I2C_PHYS_BASE + 0x1f,
  184. .flags = IORESOURCE_MEM,
  185. }, {
  186. .name = "i2c irq",
  187. .start = IRQ_ORION5X_I2C,
  188. .end = IRQ_ORION5X_I2C,
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static struct platform_device orion5x_i2c = {
  193. .name = MV64XXX_I2C_CTLR_NAME,
  194. .id = 0,
  195. .num_resources = ARRAY_SIZE(orion5x_i2c_resources),
  196. .resource = orion5x_i2c_resources,
  197. .dev = {
  198. .platform_data = &orion5x_i2c_pdata,
  199. },
  200. };
  201. void __init orion5x_i2c_init(void)
  202. {
  203. platform_device_register(&orion5x_i2c);
  204. }
  205. /*****************************************************************************
  206. * SATA
  207. ****************************************************************************/
  208. static struct resource orion5x_sata_resources[] = {
  209. {
  210. .name = "sata base",
  211. .start = ORION5X_SATA_PHYS_BASE,
  212. .end = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
  213. .flags = IORESOURCE_MEM,
  214. }, {
  215. .name = "sata irq",
  216. .start = IRQ_ORION5X_SATA,
  217. .end = IRQ_ORION5X_SATA,
  218. .flags = IORESOURCE_IRQ,
  219. },
  220. };
  221. static struct platform_device orion5x_sata = {
  222. .name = "sata_mv",
  223. .id = 0,
  224. .dev = {
  225. .coherent_dma_mask = 0xffffffff,
  226. },
  227. .num_resources = ARRAY_SIZE(orion5x_sata_resources),
  228. .resource = orion5x_sata_resources,
  229. };
  230. void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
  231. {
  232. sata_data->dram = &orion5x_mbus_dram_info;
  233. orion5x_sata.dev.platform_data = sata_data;
  234. platform_device_register(&orion5x_sata);
  235. }
  236. /*****************************************************************************
  237. * UART0
  238. ****************************************************************************/
  239. static struct plat_serial8250_port orion5x_uart0_data[] = {
  240. {
  241. .mapbase = UART0_PHYS_BASE,
  242. .membase = (char *)UART0_VIRT_BASE,
  243. .irq = IRQ_ORION5X_UART0,
  244. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  245. .iotype = UPIO_MEM,
  246. .regshift = 2,
  247. .uartclk = ORION5X_TCLK,
  248. }, {
  249. },
  250. };
  251. static struct resource orion5x_uart0_resources[] = {
  252. {
  253. .start = UART0_PHYS_BASE,
  254. .end = UART0_PHYS_BASE + 0xff,
  255. .flags = IORESOURCE_MEM,
  256. }, {
  257. .start = IRQ_ORION5X_UART0,
  258. .end = IRQ_ORION5X_UART0,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. };
  262. static struct platform_device orion5x_uart0 = {
  263. .name = "serial8250",
  264. .id = PLAT8250_DEV_PLATFORM,
  265. .dev = {
  266. .platform_data = orion5x_uart0_data,
  267. },
  268. .resource = orion5x_uart0_resources,
  269. .num_resources = ARRAY_SIZE(orion5x_uart0_resources),
  270. };
  271. void __init orion5x_uart0_init(void)
  272. {
  273. platform_device_register(&orion5x_uart0);
  274. }
  275. /*****************************************************************************
  276. * UART1
  277. ****************************************************************************/
  278. static struct plat_serial8250_port orion5x_uart1_data[] = {
  279. {
  280. .mapbase = UART1_PHYS_BASE,
  281. .membase = (char *)UART1_VIRT_BASE,
  282. .irq = IRQ_ORION5X_UART1,
  283. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  284. .iotype = UPIO_MEM,
  285. .regshift = 2,
  286. .uartclk = ORION5X_TCLK,
  287. }, {
  288. },
  289. };
  290. static struct resource orion5x_uart1_resources[] = {
  291. {
  292. .start = UART1_PHYS_BASE,
  293. .end = UART1_PHYS_BASE + 0xff,
  294. .flags = IORESOURCE_MEM,
  295. }, {
  296. .start = IRQ_ORION5X_UART1,
  297. .end = IRQ_ORION5X_UART1,
  298. .flags = IORESOURCE_IRQ,
  299. },
  300. };
  301. static struct platform_device orion5x_uart1 = {
  302. .name = "serial8250",
  303. .id = PLAT8250_DEV_PLATFORM1,
  304. .dev = {
  305. .platform_data = orion5x_uart1_data,
  306. },
  307. .resource = orion5x_uart1_resources,
  308. .num_resources = ARRAY_SIZE(orion5x_uart1_resources),
  309. };
  310. void __init orion5x_uart1_init(void)
  311. {
  312. platform_device_register(&orion5x_uart1);
  313. }
  314. /*****************************************************************************
  315. * Time handling
  316. ****************************************************************************/
  317. static void orion5x_timer_init(void)
  318. {
  319. orion_time_init(IRQ_ORION5X_BRIDGE, ORION5X_TCLK);
  320. }
  321. struct sys_timer orion5x_timer = {
  322. .init = orion5x_timer_init,
  323. };
  324. /*****************************************************************************
  325. * General
  326. ****************************************************************************/
  327. /*
  328. * Identify device ID and rev from PCIe configuration header space '0'.
  329. */
  330. static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
  331. {
  332. orion5x_pcie_id(dev, rev);
  333. if (*dev == MV88F5281_DEV_ID) {
  334. if (*rev == MV88F5281_REV_D2) {
  335. *dev_name = "MV88F5281-D2";
  336. } else if (*rev == MV88F5281_REV_D1) {
  337. *dev_name = "MV88F5281-D1";
  338. } else {
  339. *dev_name = "MV88F5281-Rev-Unsupported";
  340. }
  341. } else if (*dev == MV88F5182_DEV_ID) {
  342. if (*rev == MV88F5182_REV_A2) {
  343. *dev_name = "MV88F5182-A2";
  344. } else {
  345. *dev_name = "MV88F5182-Rev-Unsupported";
  346. }
  347. } else if (*dev == MV88F5181_DEV_ID) {
  348. if (*rev == MV88F5181_REV_B1) {
  349. *dev_name = "MV88F5181-Rev-B1";
  350. } else if (*rev == MV88F5181L_REV_A1) {
  351. *dev_name = "MV88F5181L-Rev-A1";
  352. } else {
  353. *dev_name = "MV88F5181(L)-Rev-Unsupported";
  354. }
  355. } else {
  356. *dev_name = "Device-Unknown";
  357. }
  358. }
  359. void __init orion5x_init(void)
  360. {
  361. char *dev_name;
  362. u32 dev, rev;
  363. orion5x_id(&dev, &rev, &dev_name);
  364. printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION5X_TCLK);
  365. /*
  366. * Setup Orion address map
  367. */
  368. orion5x_setup_cpu_mbus_bridge();
  369. }
  370. /*
  371. * Many orion-based systems have buggy bootloader implementations.
  372. * This is a common fixup for bogus memory tags.
  373. */
  374. void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
  375. char **from, struct meminfo *meminfo)
  376. {
  377. for (; t->hdr.size; t = tag_next(t))
  378. if (t->hdr.tag == ATAG_MEM &&
  379. (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
  380. t->u.mem.start & ~PAGE_MASK)) {
  381. printk(KERN_WARNING
  382. "Clearing invalid memory bank %dKB@0x%08x\n",
  383. t->u.mem.size / 1024, t->u.mem.start);
  384. t->hdr.tag = 0;
  385. }
  386. }