common.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/arm/mach-mv78xx0/common.c
  4. *
  5. * Core functions for Marvell MV78xx0 SoCs
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/serial_8250.h>
  12. #include <linux/ata_platform.h>
  13. #include <linux/clk-provider.h>
  14. #include <linux/ethtool.h>
  15. #include <asm/hardware/cache-feroceon-l2.h>
  16. #include <asm/mach/map.h>
  17. #include <asm/mach/time.h>
  18. #include <linux/platform_data/usb-ehci-orion.h>
  19. #include <linux/platform_data/mtd-orion_nand.h>
  20. #include <plat/time.h>
  21. #include <plat/common.h>
  22. #include <plat/addr-map.h>
  23. #include "mv78xx0.h"
  24. #include "bridge-regs.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_freq;
  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_freq = 166666667;
  99. break;
  100. case 3:
  101. tclk_freq = 200000000;
  102. break;
  103. default:
  104. panic("unknown TCLK PLL setting: %.8x\n",
  105. readl(SAMPLE_AT_RESET_HIGH));
  106. }
  107. return tclk_freq;
  108. }
  109. /*****************************************************************************
  110. * I/O Address Mapping
  111. ****************************************************************************/
  112. static struct map_desc mv78xx0_io_desc[] __initdata = {
  113. {
  114. .virtual = (unsigned long) MV78XX0_CORE_REGS_VIRT_BASE,
  115. .pfn = 0,
  116. .length = MV78XX0_CORE_REGS_SIZE,
  117. .type = MT_DEVICE,
  118. }, {
  119. .virtual = (unsigned long) MV78XX0_REGS_VIRT_BASE,
  120. .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
  121. .length = MV78XX0_REGS_SIZE,
  122. .type = MT_DEVICE,
  123. },
  124. };
  125. void __init mv78xx0_map_io(void)
  126. {
  127. unsigned long phys;
  128. /*
  129. * Map the right set of per-core registers depending on
  130. * which core we are running on.
  131. */
  132. if (mv78xx0_core_index() == 0) {
  133. phys = MV78XX0_CORE0_REGS_PHYS_BASE;
  134. } else {
  135. phys = MV78XX0_CORE1_REGS_PHYS_BASE;
  136. }
  137. mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
  138. iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
  139. }
  140. /*****************************************************************************
  141. * CLK tree
  142. ****************************************************************************/
  143. static struct clk *tclk;
  144. static void __init clk_init(void)
  145. {
  146. tclk = clk_register_fixed_rate(NULL, "tclk", NULL, 0, get_tclk());
  147. orion_clkdev_init(tclk);
  148. }
  149. /*****************************************************************************
  150. * EHCI
  151. ****************************************************************************/
  152. void __init mv78xx0_ehci0_init(void)
  153. {
  154. orion_ehci_init(USB0_PHYS_BASE, IRQ_MV78XX0_USB_0, EHCI_PHY_NA);
  155. }
  156. /*****************************************************************************
  157. * EHCI1
  158. ****************************************************************************/
  159. void __init mv78xx0_ehci1_init(void)
  160. {
  161. orion_ehci_1_init(USB1_PHYS_BASE, IRQ_MV78XX0_USB_1);
  162. }
  163. /*****************************************************************************
  164. * EHCI2
  165. ****************************************************************************/
  166. void __init mv78xx0_ehci2_init(void)
  167. {
  168. orion_ehci_2_init(USB2_PHYS_BASE, IRQ_MV78XX0_USB_2);
  169. }
  170. /*****************************************************************************
  171. * GE00
  172. ****************************************************************************/
  173. void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  174. {
  175. orion_ge00_init(eth_data,
  176. GE00_PHYS_BASE, IRQ_MV78XX0_GE00_SUM,
  177. IRQ_MV78XX0_GE_ERR,
  178. MV643XX_TX_CSUM_DEFAULT_LIMIT);
  179. }
  180. /*****************************************************************************
  181. * GE01
  182. ****************************************************************************/
  183. void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  184. {
  185. orion_ge01_init(eth_data,
  186. GE01_PHYS_BASE, IRQ_MV78XX0_GE01_SUM,
  187. MV643XX_TX_CSUM_DEFAULT_LIMIT);
  188. }
  189. /*****************************************************************************
  190. * GE10
  191. ****************************************************************************/
  192. void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
  193. {
  194. u32 dev, rev;
  195. /*
  196. * On the Z0, ge10 and ge11 are internally connected back
  197. * to back, and not brought out.
  198. */
  199. mv78xx0_pcie_id(&dev, &rev);
  200. if (dev == MV78X00_Z0_DEV_ID) {
  201. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  202. eth_data->speed = SPEED_1000;
  203. eth_data->duplex = DUPLEX_FULL;
  204. }
  205. orion_ge10_init(eth_data, GE10_PHYS_BASE, IRQ_MV78XX0_GE10_SUM);
  206. }
  207. /*****************************************************************************
  208. * GE11
  209. ****************************************************************************/
  210. void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
  211. {
  212. u32 dev, rev;
  213. /*
  214. * On the Z0, ge10 and ge11 are internally connected back
  215. * to back, and not brought out.
  216. */
  217. mv78xx0_pcie_id(&dev, &rev);
  218. if (dev == MV78X00_Z0_DEV_ID) {
  219. eth_data->phy_addr = MV643XX_ETH_PHY_NONE;
  220. eth_data->speed = SPEED_1000;
  221. eth_data->duplex = DUPLEX_FULL;
  222. }
  223. orion_ge11_init(eth_data, GE11_PHYS_BASE, IRQ_MV78XX0_GE11_SUM);
  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, 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, 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, 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, tclk);
  271. }
  272. /*****************************************************************************
  273. * Time handling
  274. ****************************************************************************/
  275. void __init mv78xx0_init_early(void)
  276. {
  277. orion_time_set_base(TIMER_VIRT_BASE);
  278. if (mv78xx0_core_index() == 0)
  279. mvebu_mbus_init("marvell,mv78xx0-mbus",
  280. BRIDGE_WINS_CPU0_BASE, BRIDGE_WINS_SZ,
  281. DDR_WINDOW_CPU0_BASE, DDR_WINDOW_CPU_SZ);
  282. else
  283. mvebu_mbus_init("marvell,mv78xx0-mbus",
  284. BRIDGE_WINS_CPU1_BASE, BRIDGE_WINS_SZ,
  285. DDR_WINDOW_CPU1_BASE, DDR_WINDOW_CPU_SZ);
  286. }
  287. void __ref mv78xx0_timer_init(void)
  288. {
  289. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  290. IRQ_MV78XX0_TIMER_1, get_tclk());
  291. }
  292. /*****************************************************************************
  293. * General
  294. ****************************************************************************/
  295. static char * __init mv78xx0_id(void)
  296. {
  297. u32 dev, rev;
  298. mv78xx0_pcie_id(&dev, &rev);
  299. if (dev == MV78X00_Z0_DEV_ID) {
  300. if (rev == MV78X00_REV_Z0)
  301. return "MV78X00-Z0";
  302. else
  303. return "MV78X00-Rev-Unsupported";
  304. } else if (dev == MV78100_DEV_ID) {
  305. if (rev == MV78100_REV_A0)
  306. return "MV78100-A0";
  307. else if (rev == MV78100_REV_A1)
  308. return "MV78100-A1";
  309. else
  310. return "MV78100-Rev-Unsupported";
  311. } else if (dev == MV78200_DEV_ID) {
  312. if (rev == MV78100_REV_A0)
  313. return "MV78200-A0";
  314. else
  315. return "MV78200-Rev-Unsupported";
  316. } else {
  317. return "Device-Unknown";
  318. }
  319. }
  320. static int __init is_l2_writethrough(void)
  321. {
  322. return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
  323. }
  324. void __init mv78xx0_init(void)
  325. {
  326. int core_index;
  327. int hclk;
  328. int pclk;
  329. int l2clk;
  330. core_index = mv78xx0_core_index();
  331. hclk = get_hclk();
  332. get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
  333. printk(KERN_INFO "%s ", mv78xx0_id());
  334. printk("core #%d, ", core_index);
  335. printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
  336. printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
  337. printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
  338. printk("TCLK = %dMHz\n", (get_tclk() + 499999) / 1000000);
  339. if (IS_ENABLED(CONFIG_CACHE_FEROCEON_L2))
  340. feroceon_l2_init(is_l2_writethrough());
  341. /* Setup root of clk tree */
  342. clk_init();
  343. }
  344. void mv78xx0_restart(enum reboot_mode mode, const char *cmd)
  345. {
  346. /*
  347. * Enable soft reset to assert RSTOUTn.
  348. */
  349. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  350. /*
  351. * Assert soft reset.
  352. */
  353. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  354. while (1)
  355. ;
  356. }