common.c 26 KB

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