common.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * arch/arm/mach-kirkwood/common.c
  3. *
  4. * Core functions for Marvell Kirkwood 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/mtd/nand.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/clk-provider.h>
  18. #include <linux/spinlock.h>
  19. #include <net/dsa.h>
  20. #include <asm/page.h>
  21. #include <asm/timex.h>
  22. #include <asm/kexec.h>
  23. #include <asm/mach/map.h>
  24. #include <asm/mach/time.h>
  25. #include <mach/kirkwood.h>
  26. #include <mach/bridge-regs.h>
  27. #include <plat/audio.h>
  28. #include <plat/cache-feroceon-l2.h>
  29. #include <plat/mvsdio.h>
  30. #include <plat/orion_nand.h>
  31. #include <plat/ehci-orion.h>
  32. #include <plat/common.h>
  33. #include <plat/time.h>
  34. #include <plat/addr-map.h>
  35. #include <plat/mv_xor.h>
  36. #include "common.h"
  37. /*****************************************************************************
  38. * I/O Address Mapping
  39. ****************************************************************************/
  40. static struct map_desc kirkwood_io_desc[] __initdata = {
  41. {
  42. .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
  43. .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
  44. .length = KIRKWOOD_PCIE_IO_SIZE,
  45. .type = MT_DEVICE,
  46. }, {
  47. .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
  48. .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
  49. .length = KIRKWOOD_PCIE1_IO_SIZE,
  50. .type = MT_DEVICE,
  51. }, {
  52. .virtual = KIRKWOOD_REGS_VIRT_BASE,
  53. .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
  54. .length = KIRKWOOD_REGS_SIZE,
  55. .type = MT_DEVICE,
  56. },
  57. };
  58. void __init kirkwood_map_io(void)
  59. {
  60. iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
  61. }
  62. /*****************************************************************************
  63. * CLK tree
  64. ****************************************************************************/
  65. static void enable_sata0(void)
  66. {
  67. /* Enable PLL and IVREF */
  68. writel(readl(SATA0_PHY_MODE_2) | 0xf, SATA0_PHY_MODE_2);
  69. /* Enable PHY */
  70. writel(readl(SATA0_IF_CTRL) & ~0x200, SATA0_IF_CTRL);
  71. }
  72. static void disable_sata0(void)
  73. {
  74. /* Disable PLL and IVREF */
  75. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  76. /* Disable PHY */
  77. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  78. }
  79. static void enable_sata1(void)
  80. {
  81. /* Enable PLL and IVREF */
  82. writel(readl(SATA1_PHY_MODE_2) | 0xf, SATA1_PHY_MODE_2);
  83. /* Enable PHY */
  84. writel(readl(SATA1_IF_CTRL) & ~0x200, SATA1_IF_CTRL);
  85. }
  86. static void disable_sata1(void)
  87. {
  88. /* Disable PLL and IVREF */
  89. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  90. /* Disable PHY */
  91. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  92. }
  93. static void disable_pcie0(void)
  94. {
  95. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  96. while (1)
  97. if (readl(PCIE_STATUS) & 0x1)
  98. break;
  99. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  100. }
  101. static void disable_pcie1(void)
  102. {
  103. u32 dev, rev;
  104. kirkwood_pcie_id(&dev, &rev);
  105. if (dev == MV88F6282_DEV_ID) {
  106. writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
  107. while (1)
  108. if (readl(PCIE1_STATUS) & 0x1)
  109. break;
  110. writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
  111. }
  112. }
  113. /* An extended version of the gated clk. This calls fn_en()/fn_dis
  114. * before enabling/disabling the clock. We use this to turn on/off
  115. * PHYs etc. */
  116. struct clk_gate_fn {
  117. struct clk_gate gate;
  118. void (*fn_en)(void);
  119. void (*fn_dis)(void);
  120. };
  121. #define to_clk_gate_fn(_gate) container_of(_gate, struct clk_gate_fn, gate)
  122. #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
  123. static int clk_gate_fn_enable(struct clk_hw *hw)
  124. {
  125. struct clk_gate *gate = to_clk_gate(hw);
  126. struct clk_gate_fn *gate_fn = to_clk_gate_fn(gate);
  127. int ret;
  128. ret = clk_gate_ops.enable(hw);
  129. if (!ret && gate_fn->fn_en)
  130. gate_fn->fn_en();
  131. return ret;
  132. }
  133. static void clk_gate_fn_disable(struct clk_hw *hw)
  134. {
  135. struct clk_gate *gate = to_clk_gate(hw);
  136. struct clk_gate_fn *gate_fn = to_clk_gate_fn(gate);
  137. if (gate_fn->fn_dis)
  138. gate_fn->fn_dis();
  139. clk_gate_ops.disable(hw);
  140. }
  141. static struct clk_ops clk_gate_fn_ops;
  142. static struct clk __init *clk_register_gate_fn(struct device *dev,
  143. const char *name,
  144. const char *parent_name, unsigned long flags,
  145. void __iomem *reg, u8 bit_idx,
  146. u8 clk_gate_flags, spinlock_t *lock,
  147. void (*fn_en)(void), void (*fn_dis)(void))
  148. {
  149. struct clk_gate_fn *gate_fn;
  150. struct clk *clk;
  151. struct clk_init_data init;
  152. gate_fn = kzalloc(sizeof(struct clk_gate_fn), GFP_KERNEL);
  153. if (!gate_fn) {
  154. pr_err("%s: could not allocate gated clk\n", __func__);
  155. return ERR_PTR(-ENOMEM);
  156. }
  157. init.name = name;
  158. init.ops = &clk_gate_fn_ops;
  159. init.flags = flags;
  160. init.parent_names = (parent_name ? &parent_name : NULL);
  161. init.num_parents = (parent_name ? 1 : 0);
  162. /* struct clk_gate assignments */
  163. gate_fn->gate.reg = reg;
  164. gate_fn->gate.bit_idx = bit_idx;
  165. gate_fn->gate.flags = clk_gate_flags;
  166. gate_fn->gate.lock = lock;
  167. gate_fn->gate.hw.init = &init;
  168. gate_fn->fn_en = fn_en;
  169. gate_fn->fn_dis = fn_dis;
  170. /* ops is the gate ops, but with our enable/disable functions */
  171. if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
  172. clk_gate_fn_ops.disable != clk_gate_fn_disable) {
  173. clk_gate_fn_ops = clk_gate_ops;
  174. clk_gate_fn_ops.enable = clk_gate_fn_enable;
  175. clk_gate_fn_ops.disable = clk_gate_fn_disable;
  176. }
  177. clk = clk_register(dev, &gate_fn->gate.hw);
  178. if (IS_ERR(clk))
  179. kfree(gate_fn);
  180. return clk;
  181. }
  182. static DEFINE_SPINLOCK(gating_lock);
  183. static struct clk *tclk;
  184. static struct clk __init *kirkwood_register_gate(const char *name, u8 bit_idx)
  185. {
  186. return clk_register_gate(NULL, name, "tclk", 0,
  187. (void __iomem *)CLOCK_GATING_CTRL,
  188. bit_idx, 0, &gating_lock);
  189. }
  190. static struct clk __init *kirkwood_register_gate_fn(const char *name,
  191. u8 bit_idx,
  192. void (*fn_en)(void),
  193. void (*fn_dis)(void))
  194. {
  195. return clk_register_gate_fn(NULL, name, "tclk", 0,
  196. (void __iomem *)CLOCK_GATING_CTRL,
  197. bit_idx, 0, &gating_lock, fn_en, fn_dis);
  198. }
  199. static struct clk *ge0, *ge1;
  200. void __init kirkwood_clk_init(void)
  201. {
  202. struct clk *runit, *sata0, *sata1, *usb0, *sdio;
  203. struct clk *crypto, *xor0, *xor1, *pex0, *pex1, *audio;
  204. tclk = clk_register_fixed_rate(NULL, "tclk", NULL,
  205. CLK_IS_ROOT, kirkwood_tclk);
  206. runit = kirkwood_register_gate("runit", CGC_BIT_RUNIT);
  207. ge0 = kirkwood_register_gate("ge0", CGC_BIT_GE0);
  208. ge1 = kirkwood_register_gate("ge1", CGC_BIT_GE1);
  209. sata0 = kirkwood_register_gate_fn("sata0", CGC_BIT_SATA0,
  210. enable_sata0, disable_sata0);
  211. sata1 = kirkwood_register_gate_fn("sata1", CGC_BIT_SATA1,
  212. enable_sata1, disable_sata1);
  213. usb0 = kirkwood_register_gate("usb0", CGC_BIT_USB0);
  214. sdio = kirkwood_register_gate("sdio", CGC_BIT_SDIO);
  215. crypto = kirkwood_register_gate("crypto", CGC_BIT_CRYPTO);
  216. xor0 = kirkwood_register_gate("xor0", CGC_BIT_XOR0);
  217. xor1 = kirkwood_register_gate("xor1", CGC_BIT_XOR1);
  218. pex0 = kirkwood_register_gate_fn("pex0", CGC_BIT_PEX0,
  219. NULL, disable_pcie0);
  220. pex1 = kirkwood_register_gate_fn("pex1", CGC_BIT_PEX1,
  221. NULL, disable_pcie1);
  222. audio = kirkwood_register_gate("audio", CGC_BIT_AUDIO);
  223. kirkwood_register_gate("tdm", CGC_BIT_TDM);
  224. kirkwood_register_gate("tsu", CGC_BIT_TSU);
  225. /* clkdev entries, mapping clks to devices */
  226. orion_clkdev_add(NULL, "orion_spi.0", runit);
  227. orion_clkdev_add(NULL, "orion_spi.1", runit);
  228. orion_clkdev_add(NULL, MV643XX_ETH_NAME ".0", ge0);
  229. orion_clkdev_add(NULL, MV643XX_ETH_NAME ".1", ge1);
  230. orion_clkdev_add(NULL, "orion_wdt", tclk);
  231. orion_clkdev_add("0", "sata_mv.0", sata0);
  232. orion_clkdev_add("1", "sata_mv.0", sata1);
  233. orion_clkdev_add(NULL, "orion-ehci.0", usb0);
  234. orion_clkdev_add(NULL, "orion_nand", runit);
  235. orion_clkdev_add(NULL, "mvsdio", sdio);
  236. orion_clkdev_add(NULL, "mv_crypto", crypto);
  237. orion_clkdev_add(NULL, MV_XOR_SHARED_NAME ".0", xor0);
  238. orion_clkdev_add(NULL, MV_XOR_SHARED_NAME ".1", xor1);
  239. orion_clkdev_add("0", "pcie", pex0);
  240. orion_clkdev_add("1", "pcie", pex1);
  241. orion_clkdev_add(NULL, "kirkwood-i2s", audio);
  242. /* Marvell says runit is used by SPI, UART, NAND, TWSI, ...,
  243. * so should never be gated.
  244. */
  245. clk_prepare_enable(runit);
  246. }
  247. /*****************************************************************************
  248. * EHCI0
  249. ****************************************************************************/
  250. void __init kirkwood_ehci_init(void)
  251. {
  252. orion_ehci_init(USB_PHYS_BASE, IRQ_KIRKWOOD_USB, EHCI_PHY_NA);
  253. }
  254. /*****************************************************************************
  255. * GE00
  256. ****************************************************************************/
  257. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  258. {
  259. orion_ge00_init(eth_data,
  260. GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
  261. IRQ_KIRKWOOD_GE00_ERR);
  262. /* The interface forgets the MAC address assigned by u-boot if
  263. the clock is turned off, so claim the clk now. */
  264. clk_prepare_enable(ge0);
  265. }
  266. /*****************************************************************************
  267. * GE01
  268. ****************************************************************************/
  269. void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  270. {
  271. orion_ge01_init(eth_data,
  272. GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
  273. IRQ_KIRKWOOD_GE01_ERR);
  274. clk_prepare_enable(ge1);
  275. }
  276. /*****************************************************************************
  277. * Ethernet switch
  278. ****************************************************************************/
  279. void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
  280. {
  281. orion_ge00_switch_init(d, irq);
  282. }
  283. /*****************************************************************************
  284. * NAND flash
  285. ****************************************************************************/
  286. static struct resource kirkwood_nand_resource = {
  287. .flags = IORESOURCE_MEM,
  288. .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
  289. .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
  290. KIRKWOOD_NAND_MEM_SIZE - 1,
  291. };
  292. static struct orion_nand_data kirkwood_nand_data = {
  293. .cle = 0,
  294. .ale = 1,
  295. .width = 8,
  296. };
  297. static struct platform_device kirkwood_nand_flash = {
  298. .name = "orion_nand",
  299. .id = -1,
  300. .dev = {
  301. .platform_data = &kirkwood_nand_data,
  302. },
  303. .resource = &kirkwood_nand_resource,
  304. .num_resources = 1,
  305. };
  306. void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
  307. int chip_delay)
  308. {
  309. kirkwood_nand_data.parts = parts;
  310. kirkwood_nand_data.nr_parts = nr_parts;
  311. kirkwood_nand_data.chip_delay = chip_delay;
  312. platform_device_register(&kirkwood_nand_flash);
  313. }
  314. void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
  315. int (*dev_ready)(struct mtd_info *))
  316. {
  317. kirkwood_nand_data.parts = parts;
  318. kirkwood_nand_data.nr_parts = nr_parts;
  319. kirkwood_nand_data.dev_ready = dev_ready;
  320. platform_device_register(&kirkwood_nand_flash);
  321. }
  322. /*****************************************************************************
  323. * SoC RTC
  324. ****************************************************************************/
  325. static void __init kirkwood_rtc_init(void)
  326. {
  327. orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
  328. }
  329. /*****************************************************************************
  330. * SATA
  331. ****************************************************************************/
  332. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  333. {
  334. orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_KIRKWOOD_SATA);
  335. }
  336. /*****************************************************************************
  337. * SD/SDIO/MMC
  338. ****************************************************************************/
  339. static struct resource mvsdio_resources[] = {
  340. [0] = {
  341. .start = SDIO_PHYS_BASE,
  342. .end = SDIO_PHYS_BASE + SZ_1K - 1,
  343. .flags = IORESOURCE_MEM,
  344. },
  345. [1] = {
  346. .start = IRQ_KIRKWOOD_SDIO,
  347. .end = IRQ_KIRKWOOD_SDIO,
  348. .flags = IORESOURCE_IRQ,
  349. },
  350. };
  351. static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
  352. static struct platform_device kirkwood_sdio = {
  353. .name = "mvsdio",
  354. .id = -1,
  355. .dev = {
  356. .dma_mask = &mvsdio_dmamask,
  357. .coherent_dma_mask = DMA_BIT_MASK(32),
  358. },
  359. .num_resources = ARRAY_SIZE(mvsdio_resources),
  360. .resource = mvsdio_resources,
  361. };
  362. void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
  363. {
  364. u32 dev, rev;
  365. kirkwood_pcie_id(&dev, &rev);
  366. if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
  367. mvsdio_data->clock = 100000000;
  368. else
  369. mvsdio_data->clock = 200000000;
  370. kirkwood_sdio.dev.platform_data = mvsdio_data;
  371. platform_device_register(&kirkwood_sdio);
  372. }
  373. /*****************************************************************************
  374. * SPI
  375. ****************************************************************************/
  376. void __init kirkwood_spi_init()
  377. {
  378. orion_spi_init(SPI_PHYS_BASE);
  379. }
  380. /*****************************************************************************
  381. * I2C
  382. ****************************************************************************/
  383. void __init kirkwood_i2c_init(void)
  384. {
  385. orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
  386. }
  387. /*****************************************************************************
  388. * UART0
  389. ****************************************************************************/
  390. void __init kirkwood_uart0_init(void)
  391. {
  392. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  393. IRQ_KIRKWOOD_UART_0, tclk);
  394. }
  395. /*****************************************************************************
  396. * UART1
  397. ****************************************************************************/
  398. void __init kirkwood_uart1_init(void)
  399. {
  400. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  401. IRQ_KIRKWOOD_UART_1, tclk);
  402. }
  403. /*****************************************************************************
  404. * Cryptographic Engines and Security Accelerator (CESA)
  405. ****************************************************************************/
  406. void __init kirkwood_crypto_init(void)
  407. {
  408. orion_crypto_init(CRYPTO_PHYS_BASE, KIRKWOOD_SRAM_PHYS_BASE,
  409. KIRKWOOD_SRAM_SIZE, IRQ_KIRKWOOD_CRYPTO);
  410. }
  411. /*****************************************************************************
  412. * XOR0
  413. ****************************************************************************/
  414. void __init kirkwood_xor0_init(void)
  415. {
  416. orion_xor0_init(XOR0_PHYS_BASE, XOR0_HIGH_PHYS_BASE,
  417. IRQ_KIRKWOOD_XOR_00, IRQ_KIRKWOOD_XOR_01);
  418. }
  419. /*****************************************************************************
  420. * XOR1
  421. ****************************************************************************/
  422. void __init kirkwood_xor1_init(void)
  423. {
  424. orion_xor1_init(XOR1_PHYS_BASE, XOR1_HIGH_PHYS_BASE,
  425. IRQ_KIRKWOOD_XOR_10, IRQ_KIRKWOOD_XOR_11);
  426. }
  427. /*****************************************************************************
  428. * Watchdog
  429. ****************************************************************************/
  430. void __init kirkwood_wdt_init(void)
  431. {
  432. orion_wdt_init();
  433. }
  434. /*****************************************************************************
  435. * Time handling
  436. ****************************************************************************/
  437. void __init kirkwood_init_early(void)
  438. {
  439. orion_time_set_base(TIMER_VIRT_BASE);
  440. }
  441. int kirkwood_tclk;
  442. static int __init kirkwood_find_tclk(void)
  443. {
  444. u32 dev, rev;
  445. kirkwood_pcie_id(&dev, &rev);
  446. if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
  447. if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
  448. return 200000000;
  449. return 166666667;
  450. }
  451. static void __init kirkwood_timer_init(void)
  452. {
  453. kirkwood_tclk = kirkwood_find_tclk();
  454. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  455. IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  456. }
  457. struct sys_timer kirkwood_timer = {
  458. .init = kirkwood_timer_init,
  459. };
  460. /*****************************************************************************
  461. * Audio
  462. ****************************************************************************/
  463. static struct resource kirkwood_i2s_resources[] = {
  464. [0] = {
  465. .start = AUDIO_PHYS_BASE,
  466. .end = AUDIO_PHYS_BASE + SZ_16K - 1,
  467. .flags = IORESOURCE_MEM,
  468. },
  469. [1] = {
  470. .start = IRQ_KIRKWOOD_I2S,
  471. .end = IRQ_KIRKWOOD_I2S,
  472. .flags = IORESOURCE_IRQ,
  473. },
  474. };
  475. static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
  476. .burst = 128,
  477. };
  478. static struct platform_device kirkwood_i2s_device = {
  479. .name = "kirkwood-i2s",
  480. .id = -1,
  481. .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
  482. .resource = kirkwood_i2s_resources,
  483. .dev = {
  484. .platform_data = &kirkwood_i2s_data,
  485. },
  486. };
  487. static struct platform_device kirkwood_pcm_device = {
  488. .name = "kirkwood-pcm-audio",
  489. .id = -1,
  490. };
  491. void __init kirkwood_audio_init(void)
  492. {
  493. platform_device_register(&kirkwood_i2s_device);
  494. platform_device_register(&kirkwood_pcm_device);
  495. }
  496. /*****************************************************************************
  497. * General
  498. ****************************************************************************/
  499. /*
  500. * Identify device ID and revision.
  501. */
  502. char * __init kirkwood_id(void)
  503. {
  504. u32 dev, rev;
  505. kirkwood_pcie_id(&dev, &rev);
  506. if (dev == MV88F6281_DEV_ID) {
  507. if (rev == MV88F6281_REV_Z0)
  508. return "MV88F6281-Z0";
  509. else if (rev == MV88F6281_REV_A0)
  510. return "MV88F6281-A0";
  511. else if (rev == MV88F6281_REV_A1)
  512. return "MV88F6281-A1";
  513. else
  514. return "MV88F6281-Rev-Unsupported";
  515. } else if (dev == MV88F6192_DEV_ID) {
  516. if (rev == MV88F6192_REV_Z0)
  517. return "MV88F6192-Z0";
  518. else if (rev == MV88F6192_REV_A0)
  519. return "MV88F6192-A0";
  520. else if (rev == MV88F6192_REV_A1)
  521. return "MV88F6192-A1";
  522. else
  523. return "MV88F6192-Rev-Unsupported";
  524. } else if (dev == MV88F6180_DEV_ID) {
  525. if (rev == MV88F6180_REV_A0)
  526. return "MV88F6180-Rev-A0";
  527. else if (rev == MV88F6180_REV_A1)
  528. return "MV88F6180-Rev-A1";
  529. else
  530. return "MV88F6180-Rev-Unsupported";
  531. } else if (dev == MV88F6282_DEV_ID) {
  532. if (rev == MV88F6282_REV_A0)
  533. return "MV88F6282-Rev-A0";
  534. else if (rev == MV88F6282_REV_A1)
  535. return "MV88F6282-Rev-A1";
  536. else
  537. return "MV88F6282-Rev-Unsupported";
  538. } else {
  539. return "Device-Unknown";
  540. }
  541. }
  542. void __init kirkwood_l2_init(void)
  543. {
  544. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  545. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  546. feroceon_l2_init(1);
  547. #else
  548. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  549. feroceon_l2_init(0);
  550. #endif
  551. }
  552. void __init kirkwood_init(void)
  553. {
  554. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  555. kirkwood_id(), kirkwood_tclk);
  556. /*
  557. * Disable propagation of mbus errors to the CPU local bus,
  558. * as this causes mbus errors (which can occur for example
  559. * for PCI aborts) to throw CPU aborts, which we're not set
  560. * up to deal with.
  561. */
  562. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  563. kirkwood_setup_cpu_mbus();
  564. #ifdef CONFIG_CACHE_FEROCEON_L2
  565. kirkwood_l2_init();
  566. #endif
  567. /* Setup root of clk tree */
  568. kirkwood_clk_init();
  569. /* internal devices that every board has */
  570. kirkwood_rtc_init();
  571. kirkwood_wdt_init();
  572. kirkwood_xor0_init();
  573. kirkwood_xor1_init();
  574. kirkwood_crypto_init();
  575. #ifdef CONFIG_KEXEC
  576. kexec_reinit = kirkwood_enable_pcie;
  577. #endif
  578. }
  579. void kirkwood_restart(char mode, const char *cmd)
  580. {
  581. /*
  582. * Enable soft reset to assert RSTOUTn.
  583. */
  584. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  585. /*
  586. * Assert soft reset.
  587. */
  588. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  589. while (1)
  590. ;
  591. }