common.c 10 KB

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