common.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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/ata_platform.h>
  15. #include <linux/clk-provider.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 <plat/addr-map.h>
  27. #include "common.h"
  28. static int get_tclk(void);
  29. /*****************************************************************************
  30. * Common bits
  31. ****************************************************************************/
  32. int mv78xx0_core_index(void)
  33. {
  34. u32 extra;
  35. /*
  36. * Read Extra Features register.
  37. */
  38. __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
  39. return !!(extra & 0x00004000);
  40. }
  41. static int get_hclk(void)
  42. {
  43. int hclk;
  44. /*
  45. * HCLK tick rate is configured by DEV_D[7:5] pins.
  46. */
  47. switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
  48. case 0:
  49. hclk = 166666667;
  50. break;
  51. case 1:
  52. hclk = 200000000;
  53. break;
  54. case 2:
  55. hclk = 266666667;
  56. break;
  57. case 3:
  58. hclk = 333333333;
  59. break;
  60. case 4:
  61. hclk = 400000000;
  62. break;
  63. default:
  64. panic("unknown HCLK PLL setting: %.8x\n",
  65. readl(SAMPLE_AT_RESET_LOW));
  66. }
  67. return hclk;
  68. }
  69. static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
  70. {
  71. u32 cfg;
  72. /*
  73. * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
  74. * PCLK/L2CLK by bits [19:14].
  75. */
  76. if (core_index == 0) {
  77. cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
  78. } else {
  79. cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
  80. }
  81. /*
  82. * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
  83. * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
  84. */
  85. *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
  86. /*
  87. * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
  88. * ratio (1, 2, 3).
  89. */
  90. *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
  91. }
  92. static int get_tclk(void)
  93. {
  94. int tclk_freq;
  95. /*
  96. * TCLK tick rate is configured by DEV_A[2:0] strap pins.
  97. */
  98. switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
  99. case 1:
  100. tclk_freq = 166666667;
  101. break;
  102. case 3:
  103. tclk_freq = 200000000;
  104. break;
  105. default:
  106. panic("unknown TCLK PLL setting: %.8x\n",
  107. readl(SAMPLE_AT_RESET_HIGH));
  108. }
  109. return tclk_freq;
  110. }
  111. /*****************************************************************************
  112. * I/O Address Mapping
  113. ****************************************************************************/
  114. static struct map_desc mv78xx0_io_desc[] __initdata = {
  115. {
  116. .virtual = MV78XX0_CORE_REGS_VIRT_BASE,
  117. .pfn = 0,
  118. .length = MV78XX0_CORE_REGS_SIZE,
  119. .type = MT_DEVICE,
  120. }, {
  121. .virtual = MV78XX0_PCIE_IO_VIRT_BASE(0),
  122. .pfn = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
  123. .length = MV78XX0_PCIE_IO_SIZE * 8,
  124. .type = MT_DEVICE,
  125. }, {
  126. .virtual = MV78XX0_REGS_VIRT_BASE,
  127. .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
  128. .length = MV78XX0_REGS_SIZE,
  129. .type = MT_DEVICE,
  130. },
  131. };
  132. void __init mv78xx0_map_io(void)
  133. {
  134. unsigned long phys;
  135. /*
  136. * Map the right set of per-core registers depending on
  137. * which core we are running on.
  138. */
  139. if (mv78xx0_core_index() == 0) {
  140. phys = MV78XX0_CORE0_REGS_PHYS_BASE;
  141. } else {
  142. phys = MV78XX0_CORE1_REGS_PHYS_BASE;
  143. }
  144. mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
  145. iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
  146. }
  147. /*****************************************************************************
  148. * CLK tree
  149. ****************************************************************************/
  150. static struct clk *tclk;
  151. static void __init clk_init(void)
  152. {
  153. tclk = clk_register_fixed_rate(NULL, "tclk", NULL, CLK_IS_ROOT,
  154. get_tclk());
  155. orion_clkdev_init(tclk);
  156. }
  157. /*****************************************************************************
  158. * EHCI
  159. ****************************************************************************/
  160. void __init mv78xx0_ehci0_init(void)
  161. {
  162. orion_ehci_init(USB0_PHYS_BASE, IRQ_MV78XX0_USB_0, EHCI_PHY_NA);
  163. }
  164. /*****************************************************************************
  165. * EHCI1
  166. ****************************************************************************/
  167. void __init mv78xx0_ehci1_init(void)
  168. {
  169. orion_ehci_1_init(USB1_PHYS_BASE, IRQ_MV78XX0_USB_1);
  170. }
  171. /*****************************************************************************
  172. * EHCI2
  173. ****************************************************************************/
  174. void __init mv78xx0_ehci2_init(void)
  175. {
  176. orion_ehci_2_init(USB2_PHYS_BASE, IRQ_MV78XX0_USB_2);
  177. }
  178. /*****************************************************************************
  179. * GE00
  180. ****************************************************************************/
  181. void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  182. {
  183. orion_ge00_init(eth_data,
  184. GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
  185. IRQ_MV78XX0_GE_ERR,
  186. MV643XX_TX_CSUM_DEFAULT_LIMIT);
  187. }
  188. /*****************************************************************************
  189. * GE01
  190. ****************************************************************************/
  191. void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  192. {
  193. orion_ge01_init(eth_data,
  194. GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
  195. NO_IRQ,
  196. MV643XX_TX_CSUM_DEFAULT_LIMIT);
  197. }
  198. /*****************************************************************************
  199. * GE10
  200. ****************************************************************************/
  201. void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
  202. {
  203. u32 dev, rev;
  204. /*
  205. * On the Z0, ge10 and ge11 are internally connected back
  206. * to back, and not brought out.
  207. */
  208. mv78xx0_pcie_id(&dev, &rev);
  209. if (dev == MV78X00_Z0_DEV_ID) {
  210. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  211. eth_data->speed = SPEED_1000;
  212. eth_data->duplex = DUPLEX_FULL;
  213. }
  214. orion_ge10_init(eth_data,
  215. GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
  216. NO_IRQ);
  217. }
  218. /*****************************************************************************
  219. * GE11
  220. ****************************************************************************/
  221. void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
  222. {
  223. u32 dev, rev;
  224. /*
  225. * On the Z0, ge10 and ge11 are internally connected back
  226. * to back, and not brought out.
  227. */
  228. mv78xx0_pcie_id(&dev, &rev);
  229. if (dev == MV78X00_Z0_DEV_ID) {
  230. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  231. eth_data->speed = SPEED_1000;
  232. eth_data->duplex = DUPLEX_FULL;
  233. }
  234. orion_ge11_init(eth_data,
  235. GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
  236. NO_IRQ);
  237. }
  238. /*****************************************************************************
  239. * I2C
  240. ****************************************************************************/
  241. void __init mv78xx0_i2c_init(void)
  242. {
  243. orion_i2c_init(I2C_0_PHYS_BASE, IRQ_MV78XX0_I2C_0, 8);
  244. orion_i2c_1_init(I2C_1_PHYS_BASE, IRQ_MV78XX0_I2C_1, 8);
  245. }
  246. /*****************************************************************************
  247. * SATA
  248. ****************************************************************************/
  249. void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
  250. {
  251. orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_MV78XX0_SATA);
  252. }
  253. /*****************************************************************************
  254. * UART0
  255. ****************************************************************************/
  256. void __init mv78xx0_uart0_init(void)
  257. {
  258. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  259. IRQ_MV78XX0_UART_0, tclk);
  260. }
  261. /*****************************************************************************
  262. * UART1
  263. ****************************************************************************/
  264. void __init mv78xx0_uart1_init(void)
  265. {
  266. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  267. IRQ_MV78XX0_UART_1, tclk);
  268. }
  269. /*****************************************************************************
  270. * UART2
  271. ****************************************************************************/
  272. void __init mv78xx0_uart2_init(void)
  273. {
  274. orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
  275. IRQ_MV78XX0_UART_2, tclk);
  276. }
  277. /*****************************************************************************
  278. * UART3
  279. ****************************************************************************/
  280. void __init mv78xx0_uart3_init(void)
  281. {
  282. orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
  283. IRQ_MV78XX0_UART_3, tclk);
  284. }
  285. /*****************************************************************************
  286. * Time handling
  287. ****************************************************************************/
  288. void __init mv78xx0_init_early(void)
  289. {
  290. orion_time_set_base(TIMER_VIRT_BASE);
  291. }
  292. static void mv78xx0_timer_init(void)
  293. {
  294. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  295. IRQ_MV78XX0_TIMER_1, get_tclk());
  296. }
  297. struct sys_timer mv78xx0_timer = {
  298. .init = mv78xx0_timer_init,
  299. };
  300. /*****************************************************************************
  301. * General
  302. ****************************************************************************/
  303. static char * __init mv78xx0_id(void)
  304. {
  305. u32 dev, rev;
  306. mv78xx0_pcie_id(&dev, &rev);
  307. if (dev == MV78X00_Z0_DEV_ID) {
  308. if (rev == MV78X00_REV_Z0)
  309. return "MV78X00-Z0";
  310. else
  311. return "MV78X00-Rev-Unsupported";
  312. } else if (dev == MV78100_DEV_ID) {
  313. if (rev == MV78100_REV_A0)
  314. return "MV78100-A0";
  315. else if (rev == MV78100_REV_A1)
  316. return "MV78100-A1";
  317. else
  318. return "MV78100-Rev-Unsupported";
  319. } else if (dev == MV78200_DEV_ID) {
  320. if (rev == MV78100_REV_A0)
  321. return "MV78200-A0";
  322. else
  323. return "MV78200-Rev-Unsupported";
  324. } else {
  325. return "Device-Unknown";
  326. }
  327. }
  328. static int __init is_l2_writethrough(void)
  329. {
  330. return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
  331. }
  332. void __init mv78xx0_init(void)
  333. {
  334. int core_index;
  335. int hclk;
  336. int pclk;
  337. int l2clk;
  338. core_index = mv78xx0_core_index();
  339. hclk = get_hclk();
  340. get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
  341. printk(KERN_INFO "%s ", mv78xx0_id());
  342. printk("core #%d, ", core_index);
  343. printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
  344. printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
  345. printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
  346. printk("TCLK = %dMHz\n", (get_tclk() + 499999) / 1000000);
  347. mv78xx0_setup_cpu_mbus();
  348. #ifdef CONFIG_CACHE_FEROCEON_L2
  349. feroceon_l2_init(is_l2_writethrough());
  350. #endif
  351. /* Setup root of clk tree */
  352. clk_init();
  353. }
  354. void mv78xx0_restart(char mode, const char *cmd)
  355. {
  356. /*
  357. * Enable soft reset to assert RSTOUTn.
  358. */
  359. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  360. /*
  361. * Assert soft reset.
  362. */
  363. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  364. while (1)
  365. ;
  366. }