common.c 20 KB

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