common.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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/mbus.h>
  15. #include <linux/mv643xx_eth.h>
  16. #include <linux/mv643xx_i2c.h>
  17. #include <linux/ata_platform.h>
  18. #include <linux/mtd/nand.h>
  19. #include <linux/spi/orion_spi.h>
  20. #include <net/dsa.h>
  21. #include <asm/page.h>
  22. #include <asm/timex.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/cache-feroceon-l2.h>
  28. #include <plat/ehci-orion.h>
  29. #include <plat/mvsdio.h>
  30. #include <plat/mv_xor.h>
  31. #include <plat/orion_nand.h>
  32. #include <plat/orion_wdt.h>
  33. #include <plat/time.h>
  34. #include "common.h"
  35. /*****************************************************************************
  36. * I/O Address Mapping
  37. ****************************************************************************/
  38. static struct map_desc kirkwood_io_desc[] __initdata = {
  39. {
  40. .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
  41. .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
  42. .length = KIRKWOOD_PCIE_IO_SIZE,
  43. .type = MT_DEVICE,
  44. }, {
  45. .virtual = KIRKWOOD_REGS_VIRT_BASE,
  46. .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
  47. .length = KIRKWOOD_REGS_SIZE,
  48. .type = MT_DEVICE,
  49. },
  50. };
  51. void __init kirkwood_map_io(void)
  52. {
  53. iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
  54. }
  55. /*
  56. * Default clock control bits. Any bit _not_ set in this variable
  57. * will be cleared from the hardware after platform devices have been
  58. * registered. Some reserved bits must be set to 1.
  59. */
  60. unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
  61. /*****************************************************************************
  62. * EHCI
  63. ****************************************************************************/
  64. static struct orion_ehci_data kirkwood_ehci_data = {
  65. .dram = &kirkwood_mbus_dram_info,
  66. .phy_version = EHCI_PHY_NA,
  67. };
  68. static u64 ehci_dmamask = 0xffffffffUL;
  69. /*****************************************************************************
  70. * EHCI0
  71. ****************************************************************************/
  72. static struct resource kirkwood_ehci_resources[] = {
  73. {
  74. .start = USB_PHYS_BASE,
  75. .end = USB_PHYS_BASE + 0x0fff,
  76. .flags = IORESOURCE_MEM,
  77. }, {
  78. .start = IRQ_KIRKWOOD_USB,
  79. .end = IRQ_KIRKWOOD_USB,
  80. .flags = IORESOURCE_IRQ,
  81. },
  82. };
  83. static struct platform_device kirkwood_ehci = {
  84. .name = "orion-ehci",
  85. .id = 0,
  86. .dev = {
  87. .dma_mask = &ehci_dmamask,
  88. .coherent_dma_mask = 0xffffffff,
  89. .platform_data = &kirkwood_ehci_data,
  90. },
  91. .resource = kirkwood_ehci_resources,
  92. .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
  93. };
  94. void __init kirkwood_ehci_init(void)
  95. {
  96. kirkwood_clk_ctrl |= CGC_USB0;
  97. platform_device_register(&kirkwood_ehci);
  98. }
  99. /*****************************************************************************
  100. * GE00
  101. ****************************************************************************/
  102. struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
  103. .dram = &kirkwood_mbus_dram_info,
  104. };
  105. static struct resource kirkwood_ge00_shared_resources[] = {
  106. {
  107. .name = "ge00 base",
  108. .start = GE00_PHYS_BASE + 0x2000,
  109. .end = GE00_PHYS_BASE + 0x3fff,
  110. .flags = IORESOURCE_MEM,
  111. }, {
  112. .name = "ge00 err irq",
  113. .start = IRQ_KIRKWOOD_GE00_ERR,
  114. .end = IRQ_KIRKWOOD_GE00_ERR,
  115. .flags = IORESOURCE_IRQ,
  116. },
  117. };
  118. static struct platform_device kirkwood_ge00_shared = {
  119. .name = MV643XX_ETH_SHARED_NAME,
  120. .id = 0,
  121. .dev = {
  122. .platform_data = &kirkwood_ge00_shared_data,
  123. },
  124. .num_resources = ARRAY_SIZE(kirkwood_ge00_shared_resources),
  125. .resource = kirkwood_ge00_shared_resources,
  126. };
  127. static struct resource kirkwood_ge00_resources[] = {
  128. {
  129. .name = "ge00 irq",
  130. .start = IRQ_KIRKWOOD_GE00_SUM,
  131. .end = IRQ_KIRKWOOD_GE00_SUM,
  132. .flags = IORESOURCE_IRQ,
  133. },
  134. };
  135. static struct platform_device kirkwood_ge00 = {
  136. .name = MV643XX_ETH_NAME,
  137. .id = 0,
  138. .num_resources = 1,
  139. .resource = kirkwood_ge00_resources,
  140. .dev = {
  141. .coherent_dma_mask = 0xffffffff,
  142. },
  143. };
  144. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  145. {
  146. kirkwood_clk_ctrl |= CGC_GE0;
  147. eth_data->shared = &kirkwood_ge00_shared;
  148. kirkwood_ge00.dev.platform_data = eth_data;
  149. platform_device_register(&kirkwood_ge00_shared);
  150. platform_device_register(&kirkwood_ge00);
  151. }
  152. /*****************************************************************************
  153. * GE01
  154. ****************************************************************************/
  155. struct mv643xx_eth_shared_platform_data kirkwood_ge01_shared_data = {
  156. .dram = &kirkwood_mbus_dram_info,
  157. .shared_smi = &kirkwood_ge00_shared,
  158. };
  159. static struct resource kirkwood_ge01_shared_resources[] = {
  160. {
  161. .name = "ge01 base",
  162. .start = GE01_PHYS_BASE + 0x2000,
  163. .end = GE01_PHYS_BASE + 0x3fff,
  164. .flags = IORESOURCE_MEM,
  165. }, {
  166. .name = "ge01 err irq",
  167. .start = IRQ_KIRKWOOD_GE01_ERR,
  168. .end = IRQ_KIRKWOOD_GE01_ERR,
  169. .flags = IORESOURCE_IRQ,
  170. },
  171. };
  172. static struct platform_device kirkwood_ge01_shared = {
  173. .name = MV643XX_ETH_SHARED_NAME,
  174. .id = 1,
  175. .dev = {
  176. .platform_data = &kirkwood_ge01_shared_data,
  177. },
  178. .num_resources = ARRAY_SIZE(kirkwood_ge01_shared_resources),
  179. .resource = kirkwood_ge01_shared_resources,
  180. };
  181. static struct resource kirkwood_ge01_resources[] = {
  182. {
  183. .name = "ge01 irq",
  184. .start = IRQ_KIRKWOOD_GE01_SUM,
  185. .end = IRQ_KIRKWOOD_GE01_SUM,
  186. .flags = IORESOURCE_IRQ,
  187. },
  188. };
  189. static struct platform_device kirkwood_ge01 = {
  190. .name = MV643XX_ETH_NAME,
  191. .id = 1,
  192. .num_resources = 1,
  193. .resource = kirkwood_ge01_resources,
  194. .dev = {
  195. .coherent_dma_mask = 0xffffffff,
  196. },
  197. };
  198. void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  199. {
  200. kirkwood_clk_ctrl |= CGC_GE1;
  201. eth_data->shared = &kirkwood_ge01_shared;
  202. kirkwood_ge01.dev.platform_data = eth_data;
  203. platform_device_register(&kirkwood_ge01_shared);
  204. platform_device_register(&kirkwood_ge01);
  205. }
  206. /*****************************************************************************
  207. * Ethernet switch
  208. ****************************************************************************/
  209. static struct resource kirkwood_switch_resources[] = {
  210. {
  211. .start = 0,
  212. .end = 0,
  213. .flags = IORESOURCE_IRQ,
  214. },
  215. };
  216. static struct platform_device kirkwood_switch_device = {
  217. .name = "dsa",
  218. .id = 0,
  219. .num_resources = 0,
  220. .resource = kirkwood_switch_resources,
  221. };
  222. void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
  223. {
  224. int i;
  225. if (irq != NO_IRQ) {
  226. kirkwood_switch_resources[0].start = irq;
  227. kirkwood_switch_resources[0].end = irq;
  228. kirkwood_switch_device.num_resources = 1;
  229. }
  230. d->netdev = &kirkwood_ge00.dev;
  231. for (i = 0; i < d->nr_chips; i++)
  232. d->chip[i].mii_bus = &kirkwood_ge00_shared.dev;
  233. kirkwood_switch_device.dev.platform_data = d;
  234. platform_device_register(&kirkwood_switch_device);
  235. }
  236. /*****************************************************************************
  237. * NAND flash
  238. ****************************************************************************/
  239. static struct resource kirkwood_nand_resource = {
  240. .flags = IORESOURCE_MEM,
  241. .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
  242. .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
  243. KIRKWOOD_NAND_MEM_SIZE - 1,
  244. };
  245. static struct orion_nand_data kirkwood_nand_data = {
  246. .cle = 0,
  247. .ale = 1,
  248. .width = 8,
  249. };
  250. static struct platform_device kirkwood_nand_flash = {
  251. .name = "orion_nand",
  252. .id = -1,
  253. .dev = {
  254. .platform_data = &kirkwood_nand_data,
  255. },
  256. .resource = &kirkwood_nand_resource,
  257. .num_resources = 1,
  258. };
  259. void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
  260. int chip_delay)
  261. {
  262. kirkwood_clk_ctrl |= CGC_RUNIT;
  263. kirkwood_nand_data.parts = parts;
  264. kirkwood_nand_data.nr_parts = nr_parts;
  265. kirkwood_nand_data.chip_delay = chip_delay;
  266. platform_device_register(&kirkwood_nand_flash);
  267. }
  268. /*****************************************************************************
  269. * SoC RTC
  270. ****************************************************************************/
  271. static struct resource kirkwood_rtc_resource = {
  272. .start = RTC_PHYS_BASE,
  273. .end = RTC_PHYS_BASE + SZ_16 - 1,
  274. .flags = IORESOURCE_MEM,
  275. };
  276. static void __init kirkwood_rtc_init(void)
  277. {
  278. platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
  279. }
  280. /*****************************************************************************
  281. * SATA
  282. ****************************************************************************/
  283. static struct resource kirkwood_sata_resources[] = {
  284. {
  285. .name = "sata base",
  286. .start = SATA_PHYS_BASE,
  287. .end = SATA_PHYS_BASE + 0x5000 - 1,
  288. .flags = IORESOURCE_MEM,
  289. }, {
  290. .name = "sata irq",
  291. .start = IRQ_KIRKWOOD_SATA,
  292. .end = IRQ_KIRKWOOD_SATA,
  293. .flags = IORESOURCE_IRQ,
  294. },
  295. };
  296. static struct platform_device kirkwood_sata = {
  297. .name = "sata_mv",
  298. .id = 0,
  299. .dev = {
  300. .coherent_dma_mask = 0xffffffff,
  301. },
  302. .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
  303. .resource = kirkwood_sata_resources,
  304. };
  305. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  306. {
  307. kirkwood_clk_ctrl |= CGC_SATA0;
  308. if (sata_data->n_ports > 1)
  309. kirkwood_clk_ctrl |= CGC_SATA1;
  310. sata_data->dram = &kirkwood_mbus_dram_info;
  311. kirkwood_sata.dev.platform_data = sata_data;
  312. platform_device_register(&kirkwood_sata);
  313. }
  314. /*****************************************************************************
  315. * SD/SDIO/MMC
  316. ****************************************************************************/
  317. static struct resource mvsdio_resources[] = {
  318. [0] = {
  319. .start = SDIO_PHYS_BASE,
  320. .end = SDIO_PHYS_BASE + SZ_1K - 1,
  321. .flags = IORESOURCE_MEM,
  322. },
  323. [1] = {
  324. .start = IRQ_KIRKWOOD_SDIO,
  325. .end = IRQ_KIRKWOOD_SDIO,
  326. .flags = IORESOURCE_IRQ,
  327. },
  328. };
  329. static u64 mvsdio_dmamask = 0xffffffffUL;
  330. static struct platform_device kirkwood_sdio = {
  331. .name = "mvsdio",
  332. .id = -1,
  333. .dev = {
  334. .dma_mask = &mvsdio_dmamask,
  335. .coherent_dma_mask = 0xffffffff,
  336. },
  337. .num_resources = ARRAY_SIZE(mvsdio_resources),
  338. .resource = mvsdio_resources,
  339. };
  340. void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
  341. {
  342. u32 dev, rev;
  343. kirkwood_pcie_id(&dev, &rev);
  344. if (rev == 0) /* catch all Kirkwood Z0's */
  345. mvsdio_data->clock = 100000000;
  346. else
  347. mvsdio_data->clock = 200000000;
  348. mvsdio_data->dram = &kirkwood_mbus_dram_info;
  349. kirkwood_clk_ctrl |= CGC_SDIO;
  350. kirkwood_sdio.dev.platform_data = mvsdio_data;
  351. platform_device_register(&kirkwood_sdio);
  352. }
  353. /*****************************************************************************
  354. * SPI
  355. ****************************************************************************/
  356. static struct orion_spi_info kirkwood_spi_plat_data = {
  357. };
  358. static struct resource kirkwood_spi_resources[] = {
  359. {
  360. .start = SPI_PHYS_BASE,
  361. .end = SPI_PHYS_BASE + SZ_512 - 1,
  362. .flags = IORESOURCE_MEM,
  363. },
  364. };
  365. static struct platform_device kirkwood_spi = {
  366. .name = "orion_spi",
  367. .id = 0,
  368. .resource = kirkwood_spi_resources,
  369. .dev = {
  370. .platform_data = &kirkwood_spi_plat_data,
  371. },
  372. .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
  373. };
  374. void __init kirkwood_spi_init()
  375. {
  376. kirkwood_clk_ctrl |= CGC_RUNIT;
  377. platform_device_register(&kirkwood_spi);
  378. }
  379. /*****************************************************************************
  380. * I2C
  381. ****************************************************************************/
  382. static struct mv64xxx_i2c_pdata kirkwood_i2c_pdata = {
  383. .freq_m = 8, /* assumes 166 MHz TCLK */
  384. .freq_n = 3,
  385. .timeout = 1000, /* Default timeout of 1 second */
  386. };
  387. static struct resource kirkwood_i2c_resources[] = {
  388. {
  389. .start = I2C_PHYS_BASE,
  390. .end = I2C_PHYS_BASE + 0x1f,
  391. .flags = IORESOURCE_MEM,
  392. }, {
  393. .start = IRQ_KIRKWOOD_TWSI,
  394. .end = IRQ_KIRKWOOD_TWSI,
  395. .flags = IORESOURCE_IRQ,
  396. },
  397. };
  398. static struct platform_device kirkwood_i2c = {
  399. .name = MV64XXX_I2C_CTLR_NAME,
  400. .id = 0,
  401. .num_resources = ARRAY_SIZE(kirkwood_i2c_resources),
  402. .resource = kirkwood_i2c_resources,
  403. .dev = {
  404. .platform_data = &kirkwood_i2c_pdata,
  405. },
  406. };
  407. void __init kirkwood_i2c_init(void)
  408. {
  409. platform_device_register(&kirkwood_i2c);
  410. }
  411. /*****************************************************************************
  412. * UART0
  413. ****************************************************************************/
  414. static struct plat_serial8250_port kirkwood_uart0_data[] = {
  415. {
  416. .mapbase = UART0_PHYS_BASE,
  417. .membase = (char *)UART0_VIRT_BASE,
  418. .irq = IRQ_KIRKWOOD_UART_0,
  419. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  420. .iotype = UPIO_MEM,
  421. .regshift = 2,
  422. .uartclk = 0,
  423. }, {
  424. },
  425. };
  426. static struct resource kirkwood_uart0_resources[] = {
  427. {
  428. .start = UART0_PHYS_BASE,
  429. .end = UART0_PHYS_BASE + 0xff,
  430. .flags = IORESOURCE_MEM,
  431. }, {
  432. .start = IRQ_KIRKWOOD_UART_0,
  433. .end = IRQ_KIRKWOOD_UART_0,
  434. .flags = IORESOURCE_IRQ,
  435. },
  436. };
  437. static struct platform_device kirkwood_uart0 = {
  438. .name = "serial8250",
  439. .id = 0,
  440. .dev = {
  441. .platform_data = kirkwood_uart0_data,
  442. },
  443. .resource = kirkwood_uart0_resources,
  444. .num_resources = ARRAY_SIZE(kirkwood_uart0_resources),
  445. };
  446. void __init kirkwood_uart0_init(void)
  447. {
  448. platform_device_register(&kirkwood_uart0);
  449. }
  450. /*****************************************************************************
  451. * UART1
  452. ****************************************************************************/
  453. static struct plat_serial8250_port kirkwood_uart1_data[] = {
  454. {
  455. .mapbase = UART1_PHYS_BASE,
  456. .membase = (char *)UART1_VIRT_BASE,
  457. .irq = IRQ_KIRKWOOD_UART_1,
  458. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  459. .iotype = UPIO_MEM,
  460. .regshift = 2,
  461. .uartclk = 0,
  462. }, {
  463. },
  464. };
  465. static struct resource kirkwood_uart1_resources[] = {
  466. {
  467. .start = UART1_PHYS_BASE,
  468. .end = UART1_PHYS_BASE + 0xff,
  469. .flags = IORESOURCE_MEM,
  470. }, {
  471. .start = IRQ_KIRKWOOD_UART_1,
  472. .end = IRQ_KIRKWOOD_UART_1,
  473. .flags = IORESOURCE_IRQ,
  474. },
  475. };
  476. static struct platform_device kirkwood_uart1 = {
  477. .name = "serial8250",
  478. .id = 1,
  479. .dev = {
  480. .platform_data = kirkwood_uart1_data,
  481. },
  482. .resource = kirkwood_uart1_resources,
  483. .num_resources = ARRAY_SIZE(kirkwood_uart1_resources),
  484. };
  485. void __init kirkwood_uart1_init(void)
  486. {
  487. platform_device_register(&kirkwood_uart1);
  488. }
  489. /*****************************************************************************
  490. * Cryptographic Engines and Security Accelerator (CESA)
  491. ****************************************************************************/
  492. static struct resource kirkwood_crypto_res[] = {
  493. {
  494. .name = "regs",
  495. .start = CRYPTO_PHYS_BASE,
  496. .end = CRYPTO_PHYS_BASE + 0xffff,
  497. .flags = IORESOURCE_MEM,
  498. }, {
  499. .name = "sram",
  500. .start = KIRKWOOD_SRAM_PHYS_BASE,
  501. .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
  502. .flags = IORESOURCE_MEM,
  503. }, {
  504. .name = "crypto interrupt",
  505. .start = IRQ_KIRKWOOD_CRYPTO,
  506. .end = IRQ_KIRKWOOD_CRYPTO,
  507. .flags = IORESOURCE_IRQ,
  508. },
  509. };
  510. static struct platform_device kirkwood_crypto_device = {
  511. .name = "mv_crypto",
  512. .id = -1,
  513. .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
  514. .resource = kirkwood_crypto_res,
  515. };
  516. void __init kirkwood_crypto_init(void)
  517. {
  518. kirkwood_clk_ctrl |= CGC_CRYPTO;
  519. platform_device_register(&kirkwood_crypto_device);
  520. }
  521. /*****************************************************************************
  522. * XOR
  523. ****************************************************************************/
  524. static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
  525. .dram = &kirkwood_mbus_dram_info,
  526. };
  527. static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
  528. /*****************************************************************************
  529. * XOR0
  530. ****************************************************************************/
  531. static struct resource kirkwood_xor0_shared_resources[] = {
  532. {
  533. .name = "xor 0 low",
  534. .start = XOR0_PHYS_BASE,
  535. .end = XOR0_PHYS_BASE + 0xff,
  536. .flags = IORESOURCE_MEM,
  537. }, {
  538. .name = "xor 0 high",
  539. .start = XOR0_HIGH_PHYS_BASE,
  540. .end = XOR0_HIGH_PHYS_BASE + 0xff,
  541. .flags = IORESOURCE_MEM,
  542. },
  543. };
  544. static struct platform_device kirkwood_xor0_shared = {
  545. .name = MV_XOR_SHARED_NAME,
  546. .id = 0,
  547. .dev = {
  548. .platform_data = &kirkwood_xor_shared_data,
  549. },
  550. .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
  551. .resource = kirkwood_xor0_shared_resources,
  552. };
  553. static struct resource kirkwood_xor00_resources[] = {
  554. [0] = {
  555. .start = IRQ_KIRKWOOD_XOR_00,
  556. .end = IRQ_KIRKWOOD_XOR_00,
  557. .flags = IORESOURCE_IRQ,
  558. },
  559. };
  560. static struct mv_xor_platform_data kirkwood_xor00_data = {
  561. .shared = &kirkwood_xor0_shared,
  562. .hw_id = 0,
  563. .pool_size = PAGE_SIZE,
  564. };
  565. static struct platform_device kirkwood_xor00_channel = {
  566. .name = MV_XOR_NAME,
  567. .id = 0,
  568. .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
  569. .resource = kirkwood_xor00_resources,
  570. .dev = {
  571. .dma_mask = &kirkwood_xor_dmamask,
  572. .coherent_dma_mask = DMA_BIT_MASK(64),
  573. .platform_data = (void *)&kirkwood_xor00_data,
  574. },
  575. };
  576. static struct resource kirkwood_xor01_resources[] = {
  577. [0] = {
  578. .start = IRQ_KIRKWOOD_XOR_01,
  579. .end = IRQ_KIRKWOOD_XOR_01,
  580. .flags = IORESOURCE_IRQ,
  581. },
  582. };
  583. static struct mv_xor_platform_data kirkwood_xor01_data = {
  584. .shared = &kirkwood_xor0_shared,
  585. .hw_id = 1,
  586. .pool_size = PAGE_SIZE,
  587. };
  588. static struct platform_device kirkwood_xor01_channel = {
  589. .name = MV_XOR_NAME,
  590. .id = 1,
  591. .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
  592. .resource = kirkwood_xor01_resources,
  593. .dev = {
  594. .dma_mask = &kirkwood_xor_dmamask,
  595. .coherent_dma_mask = DMA_BIT_MASK(64),
  596. .platform_data = (void *)&kirkwood_xor01_data,
  597. },
  598. };
  599. static void __init kirkwood_xor0_init(void)
  600. {
  601. kirkwood_clk_ctrl |= CGC_XOR0;
  602. platform_device_register(&kirkwood_xor0_shared);
  603. /*
  604. * two engines can't do memset simultaneously, this limitation
  605. * satisfied by removing memset support from one of the engines.
  606. */
  607. dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
  608. dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
  609. platform_device_register(&kirkwood_xor00_channel);
  610. dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
  611. dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
  612. dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
  613. platform_device_register(&kirkwood_xor01_channel);
  614. }
  615. /*****************************************************************************
  616. * XOR1
  617. ****************************************************************************/
  618. static struct resource kirkwood_xor1_shared_resources[] = {
  619. {
  620. .name = "xor 1 low",
  621. .start = XOR1_PHYS_BASE,
  622. .end = XOR1_PHYS_BASE + 0xff,
  623. .flags = IORESOURCE_MEM,
  624. }, {
  625. .name = "xor 1 high",
  626. .start = XOR1_HIGH_PHYS_BASE,
  627. .end = XOR1_HIGH_PHYS_BASE + 0xff,
  628. .flags = IORESOURCE_MEM,
  629. },
  630. };
  631. static struct platform_device kirkwood_xor1_shared = {
  632. .name = MV_XOR_SHARED_NAME,
  633. .id = 1,
  634. .dev = {
  635. .platform_data = &kirkwood_xor_shared_data,
  636. },
  637. .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
  638. .resource = kirkwood_xor1_shared_resources,
  639. };
  640. static struct resource kirkwood_xor10_resources[] = {
  641. [0] = {
  642. .start = IRQ_KIRKWOOD_XOR_10,
  643. .end = IRQ_KIRKWOOD_XOR_10,
  644. .flags = IORESOURCE_IRQ,
  645. },
  646. };
  647. static struct mv_xor_platform_data kirkwood_xor10_data = {
  648. .shared = &kirkwood_xor1_shared,
  649. .hw_id = 0,
  650. .pool_size = PAGE_SIZE,
  651. };
  652. static struct platform_device kirkwood_xor10_channel = {
  653. .name = MV_XOR_NAME,
  654. .id = 2,
  655. .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
  656. .resource = kirkwood_xor10_resources,
  657. .dev = {
  658. .dma_mask = &kirkwood_xor_dmamask,
  659. .coherent_dma_mask = DMA_BIT_MASK(64),
  660. .platform_data = (void *)&kirkwood_xor10_data,
  661. },
  662. };
  663. static struct resource kirkwood_xor11_resources[] = {
  664. [0] = {
  665. .start = IRQ_KIRKWOOD_XOR_11,
  666. .end = IRQ_KIRKWOOD_XOR_11,
  667. .flags = IORESOURCE_IRQ,
  668. },
  669. };
  670. static struct mv_xor_platform_data kirkwood_xor11_data = {
  671. .shared = &kirkwood_xor1_shared,
  672. .hw_id = 1,
  673. .pool_size = PAGE_SIZE,
  674. };
  675. static struct platform_device kirkwood_xor11_channel = {
  676. .name = MV_XOR_NAME,
  677. .id = 3,
  678. .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
  679. .resource = kirkwood_xor11_resources,
  680. .dev = {
  681. .dma_mask = &kirkwood_xor_dmamask,
  682. .coherent_dma_mask = DMA_BIT_MASK(64),
  683. .platform_data = (void *)&kirkwood_xor11_data,
  684. },
  685. };
  686. static void __init kirkwood_xor1_init(void)
  687. {
  688. kirkwood_clk_ctrl |= CGC_XOR1;
  689. platform_device_register(&kirkwood_xor1_shared);
  690. /*
  691. * two engines can't do memset simultaneously, this limitation
  692. * satisfied by removing memset support from one of the engines.
  693. */
  694. dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
  695. dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
  696. platform_device_register(&kirkwood_xor10_channel);
  697. dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
  698. dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
  699. dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
  700. platform_device_register(&kirkwood_xor11_channel);
  701. }
  702. /*****************************************************************************
  703. * Watchdog
  704. ****************************************************************************/
  705. static struct orion_wdt_platform_data kirkwood_wdt_data = {
  706. .tclk = 0,
  707. };
  708. static struct platform_device kirkwood_wdt_device = {
  709. .name = "orion_wdt",
  710. .id = -1,
  711. .dev = {
  712. .platform_data = &kirkwood_wdt_data,
  713. },
  714. .num_resources = 0,
  715. };
  716. static void __init kirkwood_wdt_init(void)
  717. {
  718. kirkwood_wdt_data.tclk = kirkwood_tclk;
  719. platform_device_register(&kirkwood_wdt_device);
  720. }
  721. /*****************************************************************************
  722. * Time handling
  723. ****************************************************************************/
  724. int kirkwood_tclk;
  725. int __init kirkwood_find_tclk(void)
  726. {
  727. u32 dev, rev;
  728. kirkwood_pcie_id(&dev, &rev);
  729. if (dev == MV88F6281_DEV_ID && (rev == MV88F6281_REV_A0 ||
  730. rev == MV88F6281_REV_A1))
  731. return 200000000;
  732. return 166666667;
  733. }
  734. static void __init kirkwood_timer_init(void)
  735. {
  736. kirkwood_tclk = kirkwood_find_tclk();
  737. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  738. }
  739. struct sys_timer kirkwood_timer = {
  740. .init = kirkwood_timer_init,
  741. };
  742. /*****************************************************************************
  743. * General
  744. ****************************************************************************/
  745. /*
  746. * Identify device ID and revision.
  747. */
  748. static char * __init kirkwood_id(void)
  749. {
  750. u32 dev, rev;
  751. kirkwood_pcie_id(&dev, &rev);
  752. if (dev == MV88F6281_DEV_ID) {
  753. if (rev == MV88F6281_REV_Z0)
  754. return "MV88F6281-Z0";
  755. else if (rev == MV88F6281_REV_A0)
  756. return "MV88F6281-A0";
  757. else if (rev == MV88F6281_REV_A1)
  758. return "MV88F6281-A1";
  759. else
  760. return "MV88F6281-Rev-Unsupported";
  761. } else if (dev == MV88F6192_DEV_ID) {
  762. if (rev == MV88F6192_REV_Z0)
  763. return "MV88F6192-Z0";
  764. else if (rev == MV88F6192_REV_A0)
  765. return "MV88F6192-A0";
  766. else
  767. return "MV88F6192-Rev-Unsupported";
  768. } else if (dev == MV88F6180_DEV_ID) {
  769. if (rev == MV88F6180_REV_A0)
  770. return "MV88F6180-Rev-A0";
  771. else
  772. return "MV88F6180-Rev-Unsupported";
  773. } else {
  774. return "Device-Unknown";
  775. }
  776. }
  777. static void __init kirkwood_l2_init(void)
  778. {
  779. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  780. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  781. feroceon_l2_init(1);
  782. #else
  783. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  784. feroceon_l2_init(0);
  785. #endif
  786. }
  787. void __init kirkwood_init(void)
  788. {
  789. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  790. kirkwood_id(), kirkwood_tclk);
  791. kirkwood_ge00_shared_data.t_clk = kirkwood_tclk;
  792. kirkwood_ge01_shared_data.t_clk = kirkwood_tclk;
  793. kirkwood_spi_plat_data.tclk = kirkwood_tclk;
  794. kirkwood_uart0_data[0].uartclk = kirkwood_tclk;
  795. kirkwood_uart1_data[0].uartclk = kirkwood_tclk;
  796. /*
  797. * Disable propagation of mbus errors to the CPU local bus,
  798. * as this causes mbus errors (which can occur for example
  799. * for PCI aborts) to throw CPU aborts, which we're not set
  800. * up to deal with.
  801. */
  802. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  803. kirkwood_setup_cpu_mbus();
  804. #ifdef CONFIG_CACHE_FEROCEON_L2
  805. kirkwood_l2_init();
  806. #endif
  807. /* internal devices that every board has */
  808. kirkwood_rtc_init();
  809. kirkwood_wdt_init();
  810. kirkwood_xor0_init();
  811. kirkwood_xor1_init();
  812. kirkwood_crypto_init();
  813. }
  814. static int __init kirkwood_clock_gate(void)
  815. {
  816. unsigned int curr = readl(CLOCK_GATING_CTRL);
  817. printk(KERN_DEBUG "Gating clock of unused units\n");
  818. printk(KERN_DEBUG "before: 0x%08x\n", curr);
  819. /* Make sure those units are accessible */
  820. writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0, CLOCK_GATING_CTRL);
  821. /* For SATA: first shutdown the phy */
  822. if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
  823. /* Disable PLL and IVREF */
  824. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  825. /* Disable PHY */
  826. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  827. }
  828. if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
  829. /* Disable PLL and IVREF */
  830. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  831. /* Disable PHY */
  832. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  833. }
  834. /* For PCIe: first shutdown the phy */
  835. if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
  836. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  837. while (1)
  838. if (readl(PCIE_STATUS) & 0x1)
  839. break;
  840. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  841. }
  842. /* Now gate clock the required units */
  843. writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
  844. printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
  845. return 0;
  846. }
  847. late_initcall(kirkwood_clock_gate);