common.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /*
  2. * arch/arm/mach-mv78xx0/common.c
  3. *
  4. * Core functions for Marvell MV78xx0 SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/serial_8250.h>
  14. #include <linux/mbus.h>
  15. #include <linux/ata_platform.h>
  16. #include <linux/ethtool.h>
  17. #include <asm/mach/map.h>
  18. #include <asm/mach/time.h>
  19. #include <mach/mv78xx0.h>
  20. #include <mach/bridge-regs.h>
  21. #include <plat/cache-feroceon-l2.h>
  22. #include <plat/ehci-orion.h>
  23. #include <plat/orion_nand.h>
  24. #include <plat/time.h>
  25. #include <plat/common.h>
  26. #include "common.h"
  27. static int get_tclk(void);
  28. /*****************************************************************************
  29. * Common bits
  30. ****************************************************************************/
  31. int mv78xx0_core_index(void)
  32. {
  33. u32 extra;
  34. /*
  35. * Read Extra Features register.
  36. */
  37. __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
  38. return !!(extra & 0x00004000);
  39. }
  40. static int get_hclk(void)
  41. {
  42. int hclk;
  43. /*
  44. * HCLK tick rate is configured by DEV_D[7:5] pins.
  45. */
  46. switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
  47. case 0:
  48. hclk = 166666667;
  49. break;
  50. case 1:
  51. hclk = 200000000;
  52. break;
  53. case 2:
  54. hclk = 266666667;
  55. break;
  56. case 3:
  57. hclk = 333333333;
  58. break;
  59. case 4:
  60. hclk = 400000000;
  61. break;
  62. default:
  63. panic("unknown HCLK PLL setting: %.8x\n",
  64. readl(SAMPLE_AT_RESET_LOW));
  65. }
  66. return hclk;
  67. }
  68. static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
  69. {
  70. u32 cfg;
  71. /*
  72. * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
  73. * PCLK/L2CLK by bits [19:14].
  74. */
  75. if (core_index == 0) {
  76. cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
  77. } else {
  78. cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
  79. }
  80. /*
  81. * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
  82. * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
  83. */
  84. *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
  85. /*
  86. * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
  87. * ratio (1, 2, 3).
  88. */
  89. *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
  90. }
  91. static int get_tclk(void)
  92. {
  93. int tclk;
  94. /*
  95. * TCLK tick rate is configured by DEV_A[2:0] strap pins.
  96. */
  97. switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
  98. case 1:
  99. tclk = 166666667;
  100. break;
  101. case 3:
  102. tclk = 200000000;
  103. break;
  104. default:
  105. panic("unknown TCLK PLL setting: %.8x\n",
  106. readl(SAMPLE_AT_RESET_HIGH));
  107. }
  108. return tclk;
  109. }
  110. /*****************************************************************************
  111. * I/O Address Mapping
  112. ****************************************************************************/
  113. static struct map_desc mv78xx0_io_desc[] __initdata = {
  114. {
  115. .virtual = MV78XX0_CORE_REGS_VIRT_BASE,
  116. .pfn = 0,
  117. .length = MV78XX0_CORE_REGS_SIZE,
  118. .type = MT_DEVICE,
  119. }, {
  120. .virtual = MV78XX0_PCIE_IO_VIRT_BASE(0),
  121. .pfn = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
  122. .length = MV78XX0_PCIE_IO_SIZE * 8,
  123. .type = MT_DEVICE,
  124. }, {
  125. .virtual = MV78XX0_REGS_VIRT_BASE,
  126. .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
  127. .length = MV78XX0_REGS_SIZE,
  128. .type = MT_DEVICE,
  129. },
  130. };
  131. void __init mv78xx0_map_io(void)
  132. {
  133. unsigned long phys;
  134. /*
  135. * Map the right set of per-core registers depending on
  136. * which core we are running on.
  137. */
  138. if (mv78xx0_core_index() == 0) {
  139. phys = MV78XX0_CORE0_REGS_PHYS_BASE;
  140. } else {
  141. phys = MV78XX0_CORE1_REGS_PHYS_BASE;
  142. }
  143. mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
  144. iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
  145. }
  146. /*****************************************************************************
  147. * EHCI
  148. ****************************************************************************/
  149. static struct orion_ehci_data mv78xx0_ehci_data = {
  150. .dram = &mv78xx0_mbus_dram_info,
  151. .phy_version = EHCI_PHY_NA,
  152. };
  153. static u64 ehci_dmamask = DMA_BIT_MASK(32);
  154. /*****************************************************************************
  155. * EHCI0
  156. ****************************************************************************/
  157. static struct resource mv78xx0_ehci0_resources[] = {
  158. {
  159. .start = USB0_PHYS_BASE,
  160. .end = USB0_PHYS_BASE + SZ_4K - 1,
  161. .flags = IORESOURCE_MEM,
  162. }, {
  163. .start = IRQ_MV78XX0_USB_0,
  164. .end = IRQ_MV78XX0_USB_0,
  165. .flags = IORESOURCE_IRQ,
  166. },
  167. };
  168. static struct platform_device mv78xx0_ehci0 = {
  169. .name = "orion-ehci",
  170. .id = 0,
  171. .dev = {
  172. .dma_mask = &ehci_dmamask,
  173. .coherent_dma_mask = DMA_BIT_MASK(32),
  174. .platform_data = &mv78xx0_ehci_data,
  175. },
  176. .resource = mv78xx0_ehci0_resources,
  177. .num_resources = ARRAY_SIZE(mv78xx0_ehci0_resources),
  178. };
  179. void __init mv78xx0_ehci0_init(void)
  180. {
  181. platform_device_register(&mv78xx0_ehci0);
  182. }
  183. /*****************************************************************************
  184. * EHCI1
  185. ****************************************************************************/
  186. static struct resource mv78xx0_ehci1_resources[] = {
  187. {
  188. .start = USB1_PHYS_BASE,
  189. .end = USB1_PHYS_BASE + SZ_4K - 1,
  190. .flags = IORESOURCE_MEM,
  191. }, {
  192. .start = IRQ_MV78XX0_USB_1,
  193. .end = IRQ_MV78XX0_USB_1,
  194. .flags = IORESOURCE_IRQ,
  195. },
  196. };
  197. static struct platform_device mv78xx0_ehci1 = {
  198. .name = "orion-ehci",
  199. .id = 1,
  200. .dev = {
  201. .dma_mask = &ehci_dmamask,
  202. .coherent_dma_mask = DMA_BIT_MASK(32),
  203. .platform_data = &mv78xx0_ehci_data,
  204. },
  205. .resource = mv78xx0_ehci1_resources,
  206. .num_resources = ARRAY_SIZE(mv78xx0_ehci1_resources),
  207. };
  208. void __init mv78xx0_ehci1_init(void)
  209. {
  210. platform_device_register(&mv78xx0_ehci1);
  211. }
  212. /*****************************************************************************
  213. * EHCI2
  214. ****************************************************************************/
  215. static struct resource mv78xx0_ehci2_resources[] = {
  216. {
  217. .start = USB2_PHYS_BASE,
  218. .end = USB2_PHYS_BASE + SZ_4K - 1,
  219. .flags = IORESOURCE_MEM,
  220. }, {
  221. .start = IRQ_MV78XX0_USB_2,
  222. .end = IRQ_MV78XX0_USB_2,
  223. .flags = IORESOURCE_IRQ,
  224. },
  225. };
  226. static struct platform_device mv78xx0_ehci2 = {
  227. .name = "orion-ehci",
  228. .id = 2,
  229. .dev = {
  230. .dma_mask = &ehci_dmamask,
  231. .coherent_dma_mask = DMA_BIT_MASK(32),
  232. .platform_data = &mv78xx0_ehci_data,
  233. },
  234. .resource = mv78xx0_ehci2_resources,
  235. .num_resources = ARRAY_SIZE(mv78xx0_ehci2_resources),
  236. };
  237. void __init mv78xx0_ehci2_init(void)
  238. {
  239. platform_device_register(&mv78xx0_ehci2);
  240. }
  241. /*****************************************************************************
  242. * GE00
  243. ****************************************************************************/
  244. void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  245. {
  246. orion_ge00_init(eth_data, &mv78xx0_mbus_dram_info,
  247. GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
  248. IRQ_MV78XX0_GE_ERR, get_tclk());
  249. }
  250. /*****************************************************************************
  251. * GE01
  252. ****************************************************************************/
  253. void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  254. {
  255. orion_ge01_init(eth_data, &mv78xx0_mbus_dram_info,
  256. GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
  257. NO_IRQ, get_tclk());
  258. }
  259. /*****************************************************************************
  260. * GE10
  261. ****************************************************************************/
  262. void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
  263. {
  264. u32 dev, rev;
  265. /*
  266. * On the Z0, ge10 and ge11 are internally connected back
  267. * to back, and not brought out.
  268. */
  269. mv78xx0_pcie_id(&dev, &rev);
  270. if (dev == MV78X00_Z0_DEV_ID) {
  271. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  272. eth_data->speed = SPEED_1000;
  273. eth_data->duplex = DUPLEX_FULL;
  274. }
  275. orion_ge10_init(eth_data, &mv78xx0_mbus_dram_info,
  276. GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
  277. NO_IRQ, get_tclk());
  278. }
  279. /*****************************************************************************
  280. * GE11
  281. ****************************************************************************/
  282. void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
  283. {
  284. u32 dev, rev;
  285. /*
  286. * On the Z0, ge10 and ge11 are internally connected back
  287. * to back, and not brought out.
  288. */
  289. mv78xx0_pcie_id(&dev, &rev);
  290. if (dev == MV78X00_Z0_DEV_ID) {
  291. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  292. eth_data->speed = SPEED_1000;
  293. eth_data->duplex = DUPLEX_FULL;
  294. }
  295. orion_ge11_init(eth_data, &mv78xx0_mbus_dram_info,
  296. GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
  297. NO_IRQ, get_tclk());
  298. }
  299. /*****************************************************************************
  300. * I2C
  301. ****************************************************************************/
  302. void __init mv78xx0_i2c_init(void)
  303. {
  304. orion_i2c_init(I2C_0_PHYS_BASE, IRQ_MV78XX0_I2C_0, 8);
  305. orion_i2c_1_init(I2C_1_PHYS_BASE, IRQ_MV78XX0_I2C_1, 8);
  306. }
  307. /*****************************************************************************
  308. * SATA
  309. ****************************************************************************/
  310. static struct resource mv78xx0_sata_resources[] = {
  311. {
  312. .name = "sata base",
  313. .start = SATA_PHYS_BASE,
  314. .end = SATA_PHYS_BASE + 0x5000 - 1,
  315. .flags = IORESOURCE_MEM,
  316. }, {
  317. .name = "sata irq",
  318. .start = IRQ_MV78XX0_SATA,
  319. .end = IRQ_MV78XX0_SATA,
  320. .flags = IORESOURCE_IRQ,
  321. },
  322. };
  323. static struct platform_device mv78xx0_sata = {
  324. .name = "sata_mv",
  325. .id = 0,
  326. .dev = {
  327. .coherent_dma_mask = DMA_BIT_MASK(32),
  328. },
  329. .num_resources = ARRAY_SIZE(mv78xx0_sata_resources),
  330. .resource = mv78xx0_sata_resources,
  331. };
  332. void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
  333. {
  334. sata_data->dram = &mv78xx0_mbus_dram_info;
  335. mv78xx0_sata.dev.platform_data = sata_data;
  336. platform_device_register(&mv78xx0_sata);
  337. }
  338. /*****************************************************************************
  339. * UART0
  340. ****************************************************************************/
  341. void __init mv78xx0_uart0_init(void)
  342. {
  343. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  344. IRQ_MV78XX0_UART_0, get_tclk());
  345. }
  346. /*****************************************************************************
  347. * UART1
  348. ****************************************************************************/
  349. void __init mv78xx0_uart1_init(void)
  350. {
  351. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  352. IRQ_MV78XX0_UART_1, get_tclk());
  353. }
  354. /*****************************************************************************
  355. * UART2
  356. ****************************************************************************/
  357. void __init mv78xx0_uart2_init(void)
  358. {
  359. orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
  360. IRQ_MV78XX0_UART_2, get_tclk());
  361. }
  362. /*****************************************************************************
  363. * UART3
  364. ****************************************************************************/
  365. void __init mv78xx0_uart3_init(void)
  366. {
  367. orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
  368. IRQ_MV78XX0_UART_3, get_tclk());
  369. }
  370. /*****************************************************************************
  371. * Time handling
  372. ****************************************************************************/
  373. void __init mv78xx0_init_early(void)
  374. {
  375. orion_time_set_base(TIMER_VIRT_BASE);
  376. }
  377. static void mv78xx0_timer_init(void)
  378. {
  379. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  380. IRQ_MV78XX0_TIMER_1, get_tclk());
  381. }
  382. struct sys_timer mv78xx0_timer = {
  383. .init = mv78xx0_timer_init,
  384. };
  385. /*****************************************************************************
  386. * General
  387. ****************************************************************************/
  388. static char * __init mv78xx0_id(void)
  389. {
  390. u32 dev, rev;
  391. mv78xx0_pcie_id(&dev, &rev);
  392. if (dev == MV78X00_Z0_DEV_ID) {
  393. if (rev == MV78X00_REV_Z0)
  394. return "MV78X00-Z0";
  395. else
  396. return "MV78X00-Rev-Unsupported";
  397. } else if (dev == MV78100_DEV_ID) {
  398. if (rev == MV78100_REV_A0)
  399. return "MV78100-A0";
  400. else if (rev == MV78100_REV_A1)
  401. return "MV78100-A1";
  402. else
  403. return "MV78100-Rev-Unsupported";
  404. } else if (dev == MV78200_DEV_ID) {
  405. if (rev == MV78100_REV_A0)
  406. return "MV78200-A0";
  407. else
  408. return "MV78200-Rev-Unsupported";
  409. } else {
  410. return "Device-Unknown";
  411. }
  412. }
  413. static int __init is_l2_writethrough(void)
  414. {
  415. return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
  416. }
  417. void __init mv78xx0_init(void)
  418. {
  419. int core_index;
  420. int hclk;
  421. int pclk;
  422. int l2clk;
  423. int tclk;
  424. core_index = mv78xx0_core_index();
  425. hclk = get_hclk();
  426. get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
  427. tclk = get_tclk();
  428. printk(KERN_INFO "%s ", mv78xx0_id());
  429. printk("core #%d, ", core_index);
  430. printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
  431. printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
  432. printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
  433. printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
  434. mv78xx0_setup_cpu_mbus();
  435. #ifdef CONFIG_CACHE_FEROCEON_L2
  436. feroceon_l2_init(is_l2_writethrough());
  437. #endif
  438. }