common.c 20 KB

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