common.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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. void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
  269. int (*dev_ready)(struct mtd_info *))
  270. {
  271. kirkwood_clk_ctrl |= CGC_RUNIT;
  272. kirkwood_nand_data.parts = parts;
  273. kirkwood_nand_data.nr_parts = nr_parts;
  274. kirkwood_nand_data.dev_ready = dev_ready;
  275. platform_device_register(&kirkwood_nand_flash);
  276. }
  277. /*****************************************************************************
  278. * SoC RTC
  279. ****************************************************************************/
  280. static struct resource kirkwood_rtc_resource = {
  281. .start = RTC_PHYS_BASE,
  282. .end = RTC_PHYS_BASE + SZ_16 - 1,
  283. .flags = IORESOURCE_MEM,
  284. };
  285. static void __init kirkwood_rtc_init(void)
  286. {
  287. platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
  288. }
  289. /*****************************************************************************
  290. * SATA
  291. ****************************************************************************/
  292. static struct resource kirkwood_sata_resources[] = {
  293. {
  294. .name = "sata base",
  295. .start = SATA_PHYS_BASE,
  296. .end = SATA_PHYS_BASE + 0x5000 - 1,
  297. .flags = IORESOURCE_MEM,
  298. }, {
  299. .name = "sata irq",
  300. .start = IRQ_KIRKWOOD_SATA,
  301. .end = IRQ_KIRKWOOD_SATA,
  302. .flags = IORESOURCE_IRQ,
  303. },
  304. };
  305. static struct platform_device kirkwood_sata = {
  306. .name = "sata_mv",
  307. .id = 0,
  308. .dev = {
  309. .coherent_dma_mask = 0xffffffff,
  310. },
  311. .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
  312. .resource = kirkwood_sata_resources,
  313. };
  314. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  315. {
  316. kirkwood_clk_ctrl |= CGC_SATA0;
  317. if (sata_data->n_ports > 1)
  318. kirkwood_clk_ctrl |= CGC_SATA1;
  319. sata_data->dram = &kirkwood_mbus_dram_info;
  320. kirkwood_sata.dev.platform_data = sata_data;
  321. platform_device_register(&kirkwood_sata);
  322. }
  323. /*****************************************************************************
  324. * SD/SDIO/MMC
  325. ****************************************************************************/
  326. static struct resource mvsdio_resources[] = {
  327. [0] = {
  328. .start = SDIO_PHYS_BASE,
  329. .end = SDIO_PHYS_BASE + SZ_1K - 1,
  330. .flags = IORESOURCE_MEM,
  331. },
  332. [1] = {
  333. .start = IRQ_KIRKWOOD_SDIO,
  334. .end = IRQ_KIRKWOOD_SDIO,
  335. .flags = IORESOURCE_IRQ,
  336. },
  337. };
  338. static u64 mvsdio_dmamask = 0xffffffffUL;
  339. static struct platform_device kirkwood_sdio = {
  340. .name = "mvsdio",
  341. .id = -1,
  342. .dev = {
  343. .dma_mask = &mvsdio_dmamask,
  344. .coherent_dma_mask = 0xffffffff,
  345. },
  346. .num_resources = ARRAY_SIZE(mvsdio_resources),
  347. .resource = mvsdio_resources,
  348. };
  349. void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
  350. {
  351. u32 dev, rev;
  352. kirkwood_pcie_id(&dev, &rev);
  353. if (rev == 0) /* catch all Kirkwood Z0's */
  354. mvsdio_data->clock = 100000000;
  355. else
  356. mvsdio_data->clock = 200000000;
  357. mvsdio_data->dram = &kirkwood_mbus_dram_info;
  358. kirkwood_clk_ctrl |= CGC_SDIO;
  359. kirkwood_sdio.dev.platform_data = mvsdio_data;
  360. platform_device_register(&kirkwood_sdio);
  361. }
  362. /*****************************************************************************
  363. * SPI
  364. ****************************************************************************/
  365. static struct orion_spi_info kirkwood_spi_plat_data = {
  366. };
  367. static struct resource kirkwood_spi_resources[] = {
  368. {
  369. .start = SPI_PHYS_BASE,
  370. .end = SPI_PHYS_BASE + SZ_512 - 1,
  371. .flags = IORESOURCE_MEM,
  372. },
  373. };
  374. static struct platform_device kirkwood_spi = {
  375. .name = "orion_spi",
  376. .id = 0,
  377. .resource = kirkwood_spi_resources,
  378. .dev = {
  379. .platform_data = &kirkwood_spi_plat_data,
  380. },
  381. .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
  382. };
  383. void __init kirkwood_spi_init()
  384. {
  385. kirkwood_clk_ctrl |= CGC_RUNIT;
  386. platform_device_register(&kirkwood_spi);
  387. }
  388. /*****************************************************************************
  389. * I2C
  390. ****************************************************************************/
  391. static struct mv64xxx_i2c_pdata kirkwood_i2c_pdata = {
  392. .freq_m = 8, /* assumes 166 MHz TCLK */
  393. .freq_n = 3,
  394. .timeout = 1000, /* Default timeout of 1 second */
  395. };
  396. static struct resource kirkwood_i2c_resources[] = {
  397. {
  398. .start = I2C_PHYS_BASE,
  399. .end = I2C_PHYS_BASE + 0x1f,
  400. .flags = IORESOURCE_MEM,
  401. }, {
  402. .start = IRQ_KIRKWOOD_TWSI,
  403. .end = IRQ_KIRKWOOD_TWSI,
  404. .flags = IORESOURCE_IRQ,
  405. },
  406. };
  407. static struct platform_device kirkwood_i2c = {
  408. .name = MV64XXX_I2C_CTLR_NAME,
  409. .id = 0,
  410. .num_resources = ARRAY_SIZE(kirkwood_i2c_resources),
  411. .resource = kirkwood_i2c_resources,
  412. .dev = {
  413. .platform_data = &kirkwood_i2c_pdata,
  414. },
  415. };
  416. void __init kirkwood_i2c_init(void)
  417. {
  418. platform_device_register(&kirkwood_i2c);
  419. }
  420. /*****************************************************************************
  421. * UART0
  422. ****************************************************************************/
  423. static struct plat_serial8250_port kirkwood_uart0_data[] = {
  424. {
  425. .mapbase = UART0_PHYS_BASE,
  426. .membase = (char *)UART0_VIRT_BASE,
  427. .irq = IRQ_KIRKWOOD_UART_0,
  428. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  429. .iotype = UPIO_MEM,
  430. .regshift = 2,
  431. .uartclk = 0,
  432. }, {
  433. },
  434. };
  435. static struct resource kirkwood_uart0_resources[] = {
  436. {
  437. .start = UART0_PHYS_BASE,
  438. .end = UART0_PHYS_BASE + 0xff,
  439. .flags = IORESOURCE_MEM,
  440. }, {
  441. .start = IRQ_KIRKWOOD_UART_0,
  442. .end = IRQ_KIRKWOOD_UART_0,
  443. .flags = IORESOURCE_IRQ,
  444. },
  445. };
  446. static struct platform_device kirkwood_uart0 = {
  447. .name = "serial8250",
  448. .id = 0,
  449. .dev = {
  450. .platform_data = kirkwood_uart0_data,
  451. },
  452. .resource = kirkwood_uart0_resources,
  453. .num_resources = ARRAY_SIZE(kirkwood_uart0_resources),
  454. };
  455. void __init kirkwood_uart0_init(void)
  456. {
  457. platform_device_register(&kirkwood_uart0);
  458. }
  459. /*****************************************************************************
  460. * UART1
  461. ****************************************************************************/
  462. static struct plat_serial8250_port kirkwood_uart1_data[] = {
  463. {
  464. .mapbase = UART1_PHYS_BASE,
  465. .membase = (char *)UART1_VIRT_BASE,
  466. .irq = IRQ_KIRKWOOD_UART_1,
  467. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  468. .iotype = UPIO_MEM,
  469. .regshift = 2,
  470. .uartclk = 0,
  471. }, {
  472. },
  473. };
  474. static struct resource kirkwood_uart1_resources[] = {
  475. {
  476. .start = UART1_PHYS_BASE,
  477. .end = UART1_PHYS_BASE + 0xff,
  478. .flags = IORESOURCE_MEM,
  479. }, {
  480. .start = IRQ_KIRKWOOD_UART_1,
  481. .end = IRQ_KIRKWOOD_UART_1,
  482. .flags = IORESOURCE_IRQ,
  483. },
  484. };
  485. static struct platform_device kirkwood_uart1 = {
  486. .name = "serial8250",
  487. .id = 1,
  488. .dev = {
  489. .platform_data = kirkwood_uart1_data,
  490. },
  491. .resource = kirkwood_uart1_resources,
  492. .num_resources = ARRAY_SIZE(kirkwood_uart1_resources),
  493. };
  494. void __init kirkwood_uart1_init(void)
  495. {
  496. platform_device_register(&kirkwood_uart1);
  497. }
  498. /*****************************************************************************
  499. * Cryptographic Engines and Security Accelerator (CESA)
  500. ****************************************************************************/
  501. static struct resource kirkwood_crypto_res[] = {
  502. {
  503. .name = "regs",
  504. .start = CRYPTO_PHYS_BASE,
  505. .end = CRYPTO_PHYS_BASE + 0xffff,
  506. .flags = IORESOURCE_MEM,
  507. }, {
  508. .name = "sram",
  509. .start = KIRKWOOD_SRAM_PHYS_BASE,
  510. .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
  511. .flags = IORESOURCE_MEM,
  512. }, {
  513. .name = "crypto interrupt",
  514. .start = IRQ_KIRKWOOD_CRYPTO,
  515. .end = IRQ_KIRKWOOD_CRYPTO,
  516. .flags = IORESOURCE_IRQ,
  517. },
  518. };
  519. static struct platform_device kirkwood_crypto_device = {
  520. .name = "mv_crypto",
  521. .id = -1,
  522. .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
  523. .resource = kirkwood_crypto_res,
  524. };
  525. void __init kirkwood_crypto_init(void)
  526. {
  527. kirkwood_clk_ctrl |= CGC_CRYPTO;
  528. platform_device_register(&kirkwood_crypto_device);
  529. }
  530. /*****************************************************************************
  531. * XOR
  532. ****************************************************************************/
  533. static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
  534. .dram = &kirkwood_mbus_dram_info,
  535. };
  536. static u64 kirkwood_xor_dmamask = DMA_BIT_MASK(32);
  537. /*****************************************************************************
  538. * XOR0
  539. ****************************************************************************/
  540. static struct resource kirkwood_xor0_shared_resources[] = {
  541. {
  542. .name = "xor 0 low",
  543. .start = XOR0_PHYS_BASE,
  544. .end = XOR0_PHYS_BASE + 0xff,
  545. .flags = IORESOURCE_MEM,
  546. }, {
  547. .name = "xor 0 high",
  548. .start = XOR0_HIGH_PHYS_BASE,
  549. .end = XOR0_HIGH_PHYS_BASE + 0xff,
  550. .flags = IORESOURCE_MEM,
  551. },
  552. };
  553. static struct platform_device kirkwood_xor0_shared = {
  554. .name = MV_XOR_SHARED_NAME,
  555. .id = 0,
  556. .dev = {
  557. .platform_data = &kirkwood_xor_shared_data,
  558. },
  559. .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
  560. .resource = kirkwood_xor0_shared_resources,
  561. };
  562. static struct resource kirkwood_xor00_resources[] = {
  563. [0] = {
  564. .start = IRQ_KIRKWOOD_XOR_00,
  565. .end = IRQ_KIRKWOOD_XOR_00,
  566. .flags = IORESOURCE_IRQ,
  567. },
  568. };
  569. static struct mv_xor_platform_data kirkwood_xor00_data = {
  570. .shared = &kirkwood_xor0_shared,
  571. .hw_id = 0,
  572. .pool_size = PAGE_SIZE,
  573. };
  574. static struct platform_device kirkwood_xor00_channel = {
  575. .name = MV_XOR_NAME,
  576. .id = 0,
  577. .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
  578. .resource = kirkwood_xor00_resources,
  579. .dev = {
  580. .dma_mask = &kirkwood_xor_dmamask,
  581. .coherent_dma_mask = DMA_BIT_MASK(64),
  582. .platform_data = &kirkwood_xor00_data,
  583. },
  584. };
  585. static struct resource kirkwood_xor01_resources[] = {
  586. [0] = {
  587. .start = IRQ_KIRKWOOD_XOR_01,
  588. .end = IRQ_KIRKWOOD_XOR_01,
  589. .flags = IORESOURCE_IRQ,
  590. },
  591. };
  592. static struct mv_xor_platform_data kirkwood_xor01_data = {
  593. .shared = &kirkwood_xor0_shared,
  594. .hw_id = 1,
  595. .pool_size = PAGE_SIZE,
  596. };
  597. static struct platform_device kirkwood_xor01_channel = {
  598. .name = MV_XOR_NAME,
  599. .id = 1,
  600. .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
  601. .resource = kirkwood_xor01_resources,
  602. .dev = {
  603. .dma_mask = &kirkwood_xor_dmamask,
  604. .coherent_dma_mask = DMA_BIT_MASK(64),
  605. .platform_data = &kirkwood_xor01_data,
  606. },
  607. };
  608. static void __init kirkwood_xor0_init(void)
  609. {
  610. kirkwood_clk_ctrl |= CGC_XOR0;
  611. platform_device_register(&kirkwood_xor0_shared);
  612. /*
  613. * two engines can't do memset simultaneously, this limitation
  614. * satisfied by removing memset support from one of the engines.
  615. */
  616. dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
  617. dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
  618. platform_device_register(&kirkwood_xor00_channel);
  619. dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
  620. dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
  621. dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
  622. platform_device_register(&kirkwood_xor01_channel);
  623. }
  624. /*****************************************************************************
  625. * XOR1
  626. ****************************************************************************/
  627. static struct resource kirkwood_xor1_shared_resources[] = {
  628. {
  629. .name = "xor 1 low",
  630. .start = XOR1_PHYS_BASE,
  631. .end = XOR1_PHYS_BASE + 0xff,
  632. .flags = IORESOURCE_MEM,
  633. }, {
  634. .name = "xor 1 high",
  635. .start = XOR1_HIGH_PHYS_BASE,
  636. .end = XOR1_HIGH_PHYS_BASE + 0xff,
  637. .flags = IORESOURCE_MEM,
  638. },
  639. };
  640. static struct platform_device kirkwood_xor1_shared = {
  641. .name = MV_XOR_SHARED_NAME,
  642. .id = 1,
  643. .dev = {
  644. .platform_data = &kirkwood_xor_shared_data,
  645. },
  646. .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
  647. .resource = kirkwood_xor1_shared_resources,
  648. };
  649. static struct resource kirkwood_xor10_resources[] = {
  650. [0] = {
  651. .start = IRQ_KIRKWOOD_XOR_10,
  652. .end = IRQ_KIRKWOOD_XOR_10,
  653. .flags = IORESOURCE_IRQ,
  654. },
  655. };
  656. static struct mv_xor_platform_data kirkwood_xor10_data = {
  657. .shared = &kirkwood_xor1_shared,
  658. .hw_id = 0,
  659. .pool_size = PAGE_SIZE,
  660. };
  661. static struct platform_device kirkwood_xor10_channel = {
  662. .name = MV_XOR_NAME,
  663. .id = 2,
  664. .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
  665. .resource = kirkwood_xor10_resources,
  666. .dev = {
  667. .dma_mask = &kirkwood_xor_dmamask,
  668. .coherent_dma_mask = DMA_BIT_MASK(64),
  669. .platform_data = &kirkwood_xor10_data,
  670. },
  671. };
  672. static struct resource kirkwood_xor11_resources[] = {
  673. [0] = {
  674. .start = IRQ_KIRKWOOD_XOR_11,
  675. .end = IRQ_KIRKWOOD_XOR_11,
  676. .flags = IORESOURCE_IRQ,
  677. },
  678. };
  679. static struct mv_xor_platform_data kirkwood_xor11_data = {
  680. .shared = &kirkwood_xor1_shared,
  681. .hw_id = 1,
  682. .pool_size = PAGE_SIZE,
  683. };
  684. static struct platform_device kirkwood_xor11_channel = {
  685. .name = MV_XOR_NAME,
  686. .id = 3,
  687. .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
  688. .resource = kirkwood_xor11_resources,
  689. .dev = {
  690. .dma_mask = &kirkwood_xor_dmamask,
  691. .coherent_dma_mask = DMA_BIT_MASK(64),
  692. .platform_data = &kirkwood_xor11_data,
  693. },
  694. };
  695. static void __init kirkwood_xor1_init(void)
  696. {
  697. kirkwood_clk_ctrl |= CGC_XOR1;
  698. platform_device_register(&kirkwood_xor1_shared);
  699. /*
  700. * two engines can't do memset simultaneously, this limitation
  701. * satisfied by removing memset support from one of the engines.
  702. */
  703. dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
  704. dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
  705. platform_device_register(&kirkwood_xor10_channel);
  706. dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
  707. dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
  708. dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
  709. platform_device_register(&kirkwood_xor11_channel);
  710. }
  711. /*****************************************************************************
  712. * Watchdog
  713. ****************************************************************************/
  714. static struct orion_wdt_platform_data kirkwood_wdt_data = {
  715. .tclk = 0,
  716. };
  717. static struct platform_device kirkwood_wdt_device = {
  718. .name = "orion_wdt",
  719. .id = -1,
  720. .dev = {
  721. .platform_data = &kirkwood_wdt_data,
  722. },
  723. .num_resources = 0,
  724. };
  725. static void __init kirkwood_wdt_init(void)
  726. {
  727. kirkwood_wdt_data.tclk = kirkwood_tclk;
  728. platform_device_register(&kirkwood_wdt_device);
  729. }
  730. /*****************************************************************************
  731. * Time handling
  732. ****************************************************************************/
  733. int kirkwood_tclk;
  734. int __init kirkwood_find_tclk(void)
  735. {
  736. u32 dev, rev;
  737. kirkwood_pcie_id(&dev, &rev);
  738. if (dev == MV88F6281_DEV_ID && (rev == MV88F6281_REV_A0 ||
  739. rev == MV88F6281_REV_A1))
  740. return 200000000;
  741. return 166666667;
  742. }
  743. static void __init kirkwood_timer_init(void)
  744. {
  745. kirkwood_tclk = kirkwood_find_tclk();
  746. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  747. }
  748. struct sys_timer kirkwood_timer = {
  749. .init = kirkwood_timer_init,
  750. };
  751. /*****************************************************************************
  752. * General
  753. ****************************************************************************/
  754. /*
  755. * Identify device ID and revision.
  756. */
  757. static char * __init kirkwood_id(void)
  758. {
  759. u32 dev, rev;
  760. kirkwood_pcie_id(&dev, &rev);
  761. if (dev == MV88F6281_DEV_ID) {
  762. if (rev == MV88F6281_REV_Z0)
  763. return "MV88F6281-Z0";
  764. else if (rev == MV88F6281_REV_A0)
  765. return "MV88F6281-A0";
  766. else if (rev == MV88F6281_REV_A1)
  767. return "MV88F6281-A1";
  768. else
  769. return "MV88F6281-Rev-Unsupported";
  770. } else if (dev == MV88F6192_DEV_ID) {
  771. if (rev == MV88F6192_REV_Z0)
  772. return "MV88F6192-Z0";
  773. else if (rev == MV88F6192_REV_A0)
  774. return "MV88F6192-A0";
  775. else
  776. return "MV88F6192-Rev-Unsupported";
  777. } else if (dev == MV88F6180_DEV_ID) {
  778. if (rev == MV88F6180_REV_A0)
  779. return "MV88F6180-Rev-A0";
  780. else
  781. return "MV88F6180-Rev-Unsupported";
  782. } else {
  783. return "Device-Unknown";
  784. }
  785. }
  786. static void __init kirkwood_l2_init(void)
  787. {
  788. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  789. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  790. feroceon_l2_init(1);
  791. #else
  792. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  793. feroceon_l2_init(0);
  794. #endif
  795. }
  796. void __init kirkwood_init(void)
  797. {
  798. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  799. kirkwood_id(), kirkwood_tclk);
  800. kirkwood_ge00_shared_data.t_clk = kirkwood_tclk;
  801. kirkwood_ge01_shared_data.t_clk = kirkwood_tclk;
  802. kirkwood_spi_plat_data.tclk = kirkwood_tclk;
  803. kirkwood_uart0_data[0].uartclk = kirkwood_tclk;
  804. kirkwood_uart1_data[0].uartclk = kirkwood_tclk;
  805. /*
  806. * Disable propagation of mbus errors to the CPU local bus,
  807. * as this causes mbus errors (which can occur for example
  808. * for PCI aborts) to throw CPU aborts, which we're not set
  809. * up to deal with.
  810. */
  811. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  812. kirkwood_setup_cpu_mbus();
  813. #ifdef CONFIG_CACHE_FEROCEON_L2
  814. kirkwood_l2_init();
  815. #endif
  816. /* internal devices that every board has */
  817. kirkwood_rtc_init();
  818. kirkwood_wdt_init();
  819. kirkwood_xor0_init();
  820. kirkwood_xor1_init();
  821. kirkwood_crypto_init();
  822. }
  823. static int __init kirkwood_clock_gate(void)
  824. {
  825. unsigned int curr = readl(CLOCK_GATING_CTRL);
  826. printk(KERN_DEBUG "Gating clock of unused units\n");
  827. printk(KERN_DEBUG "before: 0x%08x\n", curr);
  828. /* Make sure those units are accessible */
  829. writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0, CLOCK_GATING_CTRL);
  830. /* For SATA: first shutdown the phy */
  831. if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
  832. /* Disable PLL and IVREF */
  833. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  834. /* Disable PHY */
  835. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  836. }
  837. if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
  838. /* Disable PLL and IVREF */
  839. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  840. /* Disable PHY */
  841. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  842. }
  843. /* For PCIe: first shutdown the phy */
  844. if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
  845. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  846. while (1)
  847. if (readl(PCIE_STATUS) & 0x1)
  848. break;
  849. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  850. }
  851. /* Now gate clock the required units */
  852. writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
  853. printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
  854. return 0;
  855. }
  856. late_initcall(kirkwood_clock_gate);