common.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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/ehci-orion.h>
  22. #include <plat/orion_nand.h>
  23. #include <plat/time.h>
  24. #include <plat/common.h>
  25. #include <plat/addr-map.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. void __init mv78xx0_ehci0_init(void)
  150. {
  151. orion_ehci_init(USB0_PHYS_BASE, IRQ_MV78XX0_USB_0, EHCI_PHY_NA);
  152. }
  153. /*****************************************************************************
  154. * EHCI1
  155. ****************************************************************************/
  156. void __init mv78xx0_ehci1_init(void)
  157. {
  158. orion_ehci_1_init(USB1_PHYS_BASE, IRQ_MV78XX0_USB_1);
  159. }
  160. /*****************************************************************************
  161. * EHCI2
  162. ****************************************************************************/
  163. void __init mv78xx0_ehci2_init(void)
  164. {
  165. orion_ehci_2_init(USB2_PHYS_BASE, IRQ_MV78XX0_USB_2);
  166. }
  167. /*****************************************************************************
  168. * GE00
  169. ****************************************************************************/
  170. void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  171. {
  172. orion_ge00_init(eth_data,
  173. GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
  174. IRQ_MV78XX0_GE_ERR, get_tclk());
  175. }
  176. /*****************************************************************************
  177. * GE01
  178. ****************************************************************************/
  179. void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  180. {
  181. orion_ge01_init(eth_data,
  182. GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
  183. NO_IRQ, get_tclk());
  184. }
  185. /*****************************************************************************
  186. * GE10
  187. ****************************************************************************/
  188. void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
  189. {
  190. u32 dev, rev;
  191. /*
  192. * On the Z0, ge10 and ge11 are internally connected back
  193. * to back, and not brought out.
  194. */
  195. mv78xx0_pcie_id(&dev, &rev);
  196. if (dev == MV78X00_Z0_DEV_ID) {
  197. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  198. eth_data->speed = SPEED_1000;
  199. eth_data->duplex = DUPLEX_FULL;
  200. }
  201. orion_ge10_init(eth_data,
  202. GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM,
  203. NO_IRQ, get_tclk());
  204. }
  205. /*****************************************************************************
  206. * GE11
  207. ****************************************************************************/
  208. void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
  209. {
  210. u32 dev, rev;
  211. /*
  212. * On the Z0, ge10 and ge11 are internally connected back
  213. * to back, and not brought out.
  214. */
  215. mv78xx0_pcie_id(&dev, &rev);
  216. if (dev == MV78X00_Z0_DEV_ID) {
  217. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  218. eth_data->speed = SPEED_1000;
  219. eth_data->duplex = DUPLEX_FULL;
  220. }
  221. orion_ge11_init(eth_data,
  222. GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM,
  223. NO_IRQ, get_tclk());
  224. }
  225. /*****************************************************************************
  226. * I2C
  227. ****************************************************************************/
  228. void __init mv78xx0_i2c_init(void)
  229. {
  230. orion_i2c_init(I2C_0_PHYS_BASE, IRQ_MV78XX0_I2C_0, 8);
  231. orion_i2c_1_init(I2C_1_PHYS_BASE, IRQ_MV78XX0_I2C_1, 8);
  232. }
  233. /*****************************************************************************
  234. * SATA
  235. ****************************************************************************/
  236. void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
  237. {
  238. orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_MV78XX0_SATA);
  239. }
  240. /*****************************************************************************
  241. * UART0
  242. ****************************************************************************/
  243. void __init mv78xx0_uart0_init(void)
  244. {
  245. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  246. IRQ_MV78XX0_UART_0, get_tclk());
  247. }
  248. /*****************************************************************************
  249. * UART1
  250. ****************************************************************************/
  251. void __init mv78xx0_uart1_init(void)
  252. {
  253. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  254. IRQ_MV78XX0_UART_1, get_tclk());
  255. }
  256. /*****************************************************************************
  257. * UART2
  258. ****************************************************************************/
  259. void __init mv78xx0_uart2_init(void)
  260. {
  261. orion_uart2_init(UART2_VIRT_BASE, UART2_PHYS_BASE,
  262. IRQ_MV78XX0_UART_2, get_tclk());
  263. }
  264. /*****************************************************************************
  265. * UART3
  266. ****************************************************************************/
  267. void __init mv78xx0_uart3_init(void)
  268. {
  269. orion_uart3_init(UART3_VIRT_BASE, UART3_PHYS_BASE,
  270. IRQ_MV78XX0_UART_3, get_tclk());
  271. }
  272. /*****************************************************************************
  273. * Time handling
  274. ****************************************************************************/
  275. void __init mv78xx0_init_early(void)
  276. {
  277. orion_time_set_base(TIMER_VIRT_BASE);
  278. }
  279. static void mv78xx0_timer_init(void)
  280. {
  281. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  282. IRQ_MV78XX0_TIMER_1, get_tclk());
  283. }
  284. struct sys_timer mv78xx0_timer = {
  285. .init = mv78xx0_timer_init,
  286. };
  287. /*****************************************************************************
  288. * General
  289. ****************************************************************************/
  290. static char * __init mv78xx0_id(void)
  291. {
  292. u32 dev, rev;
  293. mv78xx0_pcie_id(&dev, &rev);
  294. if (dev == MV78X00_Z0_DEV_ID) {
  295. if (rev == MV78X00_REV_Z0)
  296. return "MV78X00-Z0";
  297. else
  298. return "MV78X00-Rev-Unsupported";
  299. } else if (dev == MV78100_DEV_ID) {
  300. if (rev == MV78100_REV_A0)
  301. return "MV78100-A0";
  302. else if (rev == MV78100_REV_A1)
  303. return "MV78100-A1";
  304. else
  305. return "MV78100-Rev-Unsupported";
  306. } else if (dev == MV78200_DEV_ID) {
  307. if (rev == MV78100_REV_A0)
  308. return "MV78200-A0";
  309. else
  310. return "MV78200-Rev-Unsupported";
  311. } else {
  312. return "Device-Unknown";
  313. }
  314. }
  315. static int __init is_l2_writethrough(void)
  316. {
  317. return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
  318. }
  319. void __init mv78xx0_init(void)
  320. {
  321. int core_index;
  322. int hclk;
  323. int pclk;
  324. int l2clk;
  325. int tclk;
  326. core_index = mv78xx0_core_index();
  327. hclk = get_hclk();
  328. get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
  329. tclk = get_tclk();
  330. printk(KERN_INFO "%s ", mv78xx0_id());
  331. printk("core #%d, ", core_index);
  332. printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
  333. printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
  334. printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
  335. printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
  336. mv78xx0_setup_cpu_mbus();
  337. #ifdef CONFIG_CACHE_FEROCEON_L2
  338. feroceon_l2_init(is_l2_writethrough());
  339. #endif
  340. }
  341. void mv78xx0_restart(char mode, const char *cmd)
  342. {
  343. /*
  344. * Enable soft reset to assert RSTOUTn.
  345. */
  346. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  347. /*
  348. * Assert soft reset.
  349. */
  350. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  351. while (1)
  352. ;
  353. }