common.c 27 KB

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