common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * arch/arm/plat-orion/common.c
  3. *
  4. * Marvell Orion SoC common setup code used by multiple mach-/common.c
  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/dma-mapping.h>
  14. #include <linux/serial_8250.h>
  15. #include <linux/mbus.h>
  16. #include <linux/mv643xx_eth.h>
  17. #include <linux/mv643xx_i2c.h>
  18. #include <net/dsa.h>
  19. #include <linux/spi/orion_spi.h>
  20. /* Fill in the resources structure and link it into the platform
  21. device structure. There is always a memory region, and nearly
  22. always an interrupt.*/
  23. static void fill_resources(struct platform_device *device,
  24. struct resource *resources,
  25. resource_size_t mapbase,
  26. resource_size_t size,
  27. unsigned int irq)
  28. {
  29. device->resource = resources;
  30. device->num_resources = 1;
  31. resources[0].flags = IORESOURCE_MEM;
  32. resources[0].start = mapbase;
  33. resources[0].end = mapbase + size;
  34. if (irq != NO_IRQ) {
  35. device->num_resources++;
  36. resources[1].flags = IORESOURCE_IRQ;
  37. resources[1].start = irq;
  38. resources[1].end = irq;
  39. }
  40. }
  41. /*****************************************************************************
  42. * UART
  43. ****************************************************************************/
  44. static void __init uart_complete(
  45. struct platform_device *orion_uart,
  46. struct plat_serial8250_port *data,
  47. struct resource *resources,
  48. unsigned int membase,
  49. resource_size_t mapbase,
  50. unsigned int irq,
  51. unsigned int uartclk)
  52. {
  53. data->mapbase = mapbase;
  54. data->membase = (void __iomem *)membase;
  55. data->irq = irq;
  56. data->uartclk = uartclk;
  57. orion_uart->dev.platform_data = data;
  58. fill_resources(orion_uart, resources, mapbase, 0xff, irq);
  59. platform_device_register(orion_uart);
  60. }
  61. /*****************************************************************************
  62. * UART0
  63. ****************************************************************************/
  64. static struct plat_serial8250_port orion_uart0_data[] = {
  65. {
  66. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  67. .iotype = UPIO_MEM,
  68. .regshift = 2,
  69. }, {
  70. },
  71. };
  72. static struct resource orion_uart0_resources[2];
  73. static struct platform_device orion_uart0 = {
  74. .name = "serial8250",
  75. .id = PLAT8250_DEV_PLATFORM,
  76. };
  77. void __init orion_uart0_init(unsigned int membase,
  78. resource_size_t mapbase,
  79. unsigned int irq,
  80. unsigned int uartclk)
  81. {
  82. uart_complete(&orion_uart0, orion_uart0_data, orion_uart0_resources,
  83. membase, mapbase, irq, uartclk);
  84. }
  85. /*****************************************************************************
  86. * UART1
  87. ****************************************************************************/
  88. static struct plat_serial8250_port orion_uart1_data[] = {
  89. {
  90. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  91. .iotype = UPIO_MEM,
  92. .regshift = 2,
  93. }, {
  94. },
  95. };
  96. static struct resource orion_uart1_resources[2];
  97. static struct platform_device orion_uart1 = {
  98. .name = "serial8250",
  99. .id = PLAT8250_DEV_PLATFORM1,
  100. };
  101. void __init orion_uart1_init(unsigned int membase,
  102. resource_size_t mapbase,
  103. unsigned int irq,
  104. unsigned int uartclk)
  105. {
  106. uart_complete(&orion_uart1, orion_uart1_data, orion_uart1_resources,
  107. membase, mapbase, irq, uartclk);
  108. }
  109. /*****************************************************************************
  110. * UART2
  111. ****************************************************************************/
  112. static struct plat_serial8250_port orion_uart2_data[] = {
  113. {
  114. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  115. .iotype = UPIO_MEM,
  116. .regshift = 2,
  117. }, {
  118. },
  119. };
  120. static struct resource orion_uart2_resources[2];
  121. static struct platform_device orion_uart2 = {
  122. .name = "serial8250",
  123. .id = PLAT8250_DEV_PLATFORM2,
  124. };
  125. void __init orion_uart2_init(unsigned int membase,
  126. resource_size_t mapbase,
  127. unsigned int irq,
  128. unsigned int uartclk)
  129. {
  130. uart_complete(&orion_uart2, orion_uart2_data, orion_uart2_resources,
  131. membase, mapbase, irq, uartclk);
  132. }
  133. /*****************************************************************************
  134. * UART3
  135. ****************************************************************************/
  136. static struct plat_serial8250_port orion_uart3_data[] = {
  137. {
  138. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  139. .iotype = UPIO_MEM,
  140. .regshift = 2,
  141. }, {
  142. },
  143. };
  144. static struct resource orion_uart3_resources[2];
  145. static struct platform_device orion_uart3 = {
  146. .name = "serial8250",
  147. .id = 3,
  148. };
  149. void __init orion_uart3_init(unsigned int membase,
  150. resource_size_t mapbase,
  151. unsigned int irq,
  152. unsigned int uartclk)
  153. {
  154. uart_complete(&orion_uart3, orion_uart3_data, orion_uart3_resources,
  155. membase, mapbase, irq, uartclk);
  156. }
  157. /*****************************************************************************
  158. * SoC RTC
  159. ****************************************************************************/
  160. static struct resource orion_rtc_resource[2];
  161. void __init orion_rtc_init(unsigned long mapbase,
  162. unsigned long irq)
  163. {
  164. orion_rtc_resource[0].start = mapbase;
  165. orion_rtc_resource[0].end = mapbase + SZ_32 - 1;
  166. orion_rtc_resource[0].flags = IORESOURCE_MEM;
  167. orion_rtc_resource[1].start = irq;
  168. orion_rtc_resource[1].end = irq;
  169. orion_rtc_resource[1].flags = IORESOURCE_IRQ;
  170. platform_device_register_simple("rtc-mv", -1, orion_rtc_resource, 2);
  171. }
  172. /*****************************************************************************
  173. * GE
  174. ****************************************************************************/
  175. static __init void ge_complete(
  176. struct mv643xx_eth_shared_platform_data *orion_ge_shared_data,
  177. struct mbus_dram_target_info *mbus_dram_info, int tclk,
  178. struct resource *orion_ge_resource, unsigned long irq,
  179. struct platform_device *orion_ge_shared,
  180. struct mv643xx_eth_platform_data *eth_data,
  181. struct platform_device *orion_ge)
  182. {
  183. orion_ge_shared_data->dram = mbus_dram_info;
  184. orion_ge_shared_data->t_clk = tclk;
  185. orion_ge_resource->start = irq;
  186. orion_ge_resource->end = irq;
  187. eth_data->shared = orion_ge_shared;
  188. orion_ge->dev.platform_data = eth_data;
  189. platform_device_register(orion_ge_shared);
  190. platform_device_register(orion_ge);
  191. }
  192. /*****************************************************************************
  193. * GE00
  194. ****************************************************************************/
  195. struct mv643xx_eth_shared_platform_data orion_ge00_shared_data;
  196. static struct resource orion_ge00_shared_resources[] = {
  197. {
  198. .name = "ge00 base",
  199. }, {
  200. .name = "ge00 err irq",
  201. },
  202. };
  203. static struct platform_device orion_ge00_shared = {
  204. .name = MV643XX_ETH_SHARED_NAME,
  205. .id = 0,
  206. .dev = {
  207. .platform_data = &orion_ge00_shared_data,
  208. },
  209. };
  210. static struct resource orion_ge00_resources[] = {
  211. {
  212. .name = "ge00 irq",
  213. .flags = IORESOURCE_IRQ,
  214. },
  215. };
  216. static struct platform_device orion_ge00 = {
  217. .name = MV643XX_ETH_NAME,
  218. .id = 0,
  219. .num_resources = 1,
  220. .resource = orion_ge00_resources,
  221. .dev = {
  222. .coherent_dma_mask = DMA_BIT_MASK(32),
  223. },
  224. };
  225. void __init orion_ge00_init(struct mv643xx_eth_platform_data *eth_data,
  226. struct mbus_dram_target_info *mbus_dram_info,
  227. unsigned long mapbase,
  228. unsigned long irq,
  229. unsigned long irq_err,
  230. int tclk)
  231. {
  232. fill_resources(&orion_ge00_shared, orion_ge00_shared_resources,
  233. mapbase + 0x2000, SZ_16K - 1, irq_err);
  234. ge_complete(&orion_ge00_shared_data, mbus_dram_info, tclk,
  235. orion_ge00_resources, irq, &orion_ge00_shared,
  236. eth_data, &orion_ge00);
  237. }
  238. /*****************************************************************************
  239. * GE01
  240. ****************************************************************************/
  241. struct mv643xx_eth_shared_platform_data orion_ge01_shared_data = {
  242. .shared_smi = &orion_ge00_shared,
  243. };
  244. static struct resource orion_ge01_shared_resources[] = {
  245. {
  246. .name = "ge01 base",
  247. }, {
  248. .name = "ge01 err irq",
  249. },
  250. };
  251. static struct platform_device orion_ge01_shared = {
  252. .name = MV643XX_ETH_SHARED_NAME,
  253. .id = 1,
  254. .dev = {
  255. .platform_data = &orion_ge01_shared_data,
  256. },
  257. };
  258. static struct resource orion_ge01_resources[] = {
  259. {
  260. .name = "ge01 irq",
  261. .flags = IORESOURCE_IRQ,
  262. },
  263. };
  264. static struct platform_device orion_ge01 = {
  265. .name = MV643XX_ETH_NAME,
  266. .id = 1,
  267. .num_resources = 1,
  268. .resource = orion_ge01_resources,
  269. .dev = {
  270. .coherent_dma_mask = DMA_BIT_MASK(32),
  271. },
  272. };
  273. void __init orion_ge01_init(struct mv643xx_eth_platform_data *eth_data,
  274. struct mbus_dram_target_info *mbus_dram_info,
  275. unsigned long mapbase,
  276. unsigned long irq,
  277. unsigned long irq_err,
  278. int tclk)
  279. {
  280. fill_resources(&orion_ge01_shared, orion_ge01_shared_resources,
  281. mapbase + 0x2000, SZ_16K - 1, irq_err);
  282. ge_complete(&orion_ge01_shared_data, mbus_dram_info, tclk,
  283. orion_ge01_resources, irq, &orion_ge01_shared,
  284. eth_data, &orion_ge01);
  285. }
  286. /*****************************************************************************
  287. * GE10
  288. ****************************************************************************/
  289. struct mv643xx_eth_shared_platform_data orion_ge10_shared_data = {
  290. .shared_smi = &orion_ge00_shared,
  291. };
  292. static struct resource orion_ge10_shared_resources[] = {
  293. {
  294. .name = "ge10 base",
  295. }, {
  296. .name = "ge10 err irq",
  297. },
  298. };
  299. static struct platform_device orion_ge10_shared = {
  300. .name = MV643XX_ETH_SHARED_NAME,
  301. .id = 1,
  302. .dev = {
  303. .platform_data = &orion_ge10_shared_data,
  304. },
  305. };
  306. static struct resource orion_ge10_resources[] = {
  307. {
  308. .name = "ge10 irq",
  309. .flags = IORESOURCE_IRQ,
  310. },
  311. };
  312. static struct platform_device orion_ge10 = {
  313. .name = MV643XX_ETH_NAME,
  314. .id = 1,
  315. .num_resources = 2,
  316. .resource = orion_ge10_resources,
  317. .dev = {
  318. .coherent_dma_mask = DMA_BIT_MASK(32),
  319. },
  320. };
  321. void __init orion_ge10_init(struct mv643xx_eth_platform_data *eth_data,
  322. struct mbus_dram_target_info *mbus_dram_info,
  323. unsigned long mapbase,
  324. unsigned long irq,
  325. unsigned long irq_err,
  326. int tclk)
  327. {
  328. fill_resources(&orion_ge10_shared, orion_ge10_shared_resources,
  329. mapbase + 0x2000, SZ_16K - 1, irq_err);
  330. ge_complete(&orion_ge10_shared_data, mbus_dram_info, tclk,
  331. orion_ge10_resources, irq, &orion_ge10_shared,
  332. eth_data, &orion_ge10);
  333. }
  334. /*****************************************************************************
  335. * GE11
  336. ****************************************************************************/
  337. struct mv643xx_eth_shared_platform_data orion_ge11_shared_data = {
  338. .shared_smi = &orion_ge00_shared,
  339. };
  340. static struct resource orion_ge11_shared_resources[] = {
  341. {
  342. .name = "ge11 base",
  343. }, {
  344. .name = "ge11 err irq",
  345. },
  346. };
  347. static struct platform_device orion_ge11_shared = {
  348. .name = MV643XX_ETH_SHARED_NAME,
  349. .id = 1,
  350. .dev = {
  351. .platform_data = &orion_ge11_shared_data,
  352. },
  353. };
  354. static struct resource orion_ge11_resources[] = {
  355. {
  356. .name = "ge11 irq",
  357. .flags = IORESOURCE_IRQ,
  358. },
  359. };
  360. static struct platform_device orion_ge11 = {
  361. .name = MV643XX_ETH_NAME,
  362. .id = 1,
  363. .num_resources = 2,
  364. .resource = orion_ge11_resources,
  365. .dev = {
  366. .coherent_dma_mask = DMA_BIT_MASK(32),
  367. },
  368. };
  369. void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
  370. struct mbus_dram_target_info *mbus_dram_info,
  371. unsigned long mapbase,
  372. unsigned long irq,
  373. unsigned long irq_err,
  374. int tclk)
  375. {
  376. fill_resources(&orion_ge11_shared, orion_ge11_shared_resources,
  377. mapbase + 0x2000, SZ_16K - 1, irq_err);
  378. ge_complete(&orion_ge11_shared_data, mbus_dram_info, tclk,
  379. orion_ge11_resources, irq, &orion_ge11_shared,
  380. eth_data, &orion_ge11);
  381. }
  382. /*****************************************************************************
  383. * Ethernet switch
  384. ****************************************************************************/
  385. static struct resource orion_switch_resources[] = {
  386. {
  387. .start = 0,
  388. .end = 0,
  389. .flags = IORESOURCE_IRQ,
  390. },
  391. };
  392. static struct platform_device orion_switch_device = {
  393. .name = "dsa",
  394. .id = 0,
  395. .num_resources = 0,
  396. .resource = orion_switch_resources,
  397. };
  398. void __init orion_ge00_switch_init(struct dsa_platform_data *d, int irq)
  399. {
  400. int i;
  401. if (irq != NO_IRQ) {
  402. orion_switch_resources[0].start = irq;
  403. orion_switch_resources[0].end = irq;
  404. orion_switch_device.num_resources = 1;
  405. }
  406. d->netdev = &orion_ge00.dev;
  407. for (i = 0; i < d->nr_chips; i++)
  408. d->chip[i].mii_bus = &orion_ge00_shared.dev;
  409. orion_switch_device.dev.platform_data = d;
  410. platform_device_register(&orion_switch_device);
  411. }
  412. /*****************************************************************************
  413. * I2C
  414. ****************************************************************************/
  415. static struct mv64xxx_i2c_pdata orion_i2c_pdata = {
  416. .freq_n = 3,
  417. .timeout = 1000, /* Default timeout of 1 second */
  418. };
  419. static struct resource orion_i2c_resources[2];
  420. static struct platform_device orion_i2c = {
  421. .name = MV64XXX_I2C_CTLR_NAME,
  422. .id = 0,
  423. .dev = {
  424. .platform_data = &orion_i2c_pdata,
  425. },
  426. };
  427. static struct mv64xxx_i2c_pdata orion_i2c_1_pdata = {
  428. .freq_n = 3,
  429. .timeout = 1000, /* Default timeout of 1 second */
  430. };
  431. static struct resource orion_i2c_1_resources[2];
  432. static struct platform_device orion_i2c_1 = {
  433. .name = MV64XXX_I2C_CTLR_NAME,
  434. .id = 1,
  435. .dev = {
  436. .platform_data = &orion_i2c_1_pdata,
  437. },
  438. };
  439. void __init orion_i2c_init(unsigned long mapbase,
  440. unsigned long irq,
  441. unsigned long freq_m)
  442. {
  443. orion_i2c_pdata.freq_m = freq_m;
  444. fill_resources(&orion_i2c, orion_i2c_resources, mapbase,
  445. SZ_32 - 1, irq);
  446. platform_device_register(&orion_i2c);
  447. }
  448. void __init orion_i2c_1_init(unsigned long mapbase,
  449. unsigned long irq,
  450. unsigned long freq_m)
  451. {
  452. orion_i2c_1_pdata.freq_m = freq_m;
  453. fill_resources(&orion_i2c_1, orion_i2c_1_resources, mapbase,
  454. SZ_32 - 1, irq);
  455. platform_device_register(&orion_i2c_1);
  456. }
  457. /*****************************************************************************
  458. * SPI
  459. ****************************************************************************/
  460. static struct orion_spi_info orion_spi_plat_data;
  461. static struct resource orion_spi_resources;
  462. static struct platform_device orion_spi = {
  463. .name = "orion_spi",
  464. .id = 0,
  465. .dev = {
  466. .platform_data = &orion_spi_plat_data,
  467. },
  468. };
  469. static struct orion_spi_info orion_spi_1_plat_data;
  470. static struct resource orion_spi_1_resources;
  471. static struct platform_device orion_spi_1 = {
  472. .name = "orion_spi",
  473. .id = 1,
  474. .dev = {
  475. .platform_data = &orion_spi_1_plat_data,
  476. },
  477. };
  478. /* Note: The SPI silicon core does have interrupts. However the
  479. * current Linux software driver does not use interrupts. */
  480. void __init orion_spi_init(unsigned long mapbase,
  481. unsigned long tclk)
  482. {
  483. orion_spi_plat_data.tclk = tclk;
  484. fill_resources(&orion_spi, &orion_spi_resources,
  485. mapbase, SZ_512 - 1, NO_IRQ);
  486. platform_device_register(&orion_spi);
  487. }
  488. void __init orion_spi_1_init(unsigned long mapbase,
  489. unsigned long tclk)
  490. {
  491. orion_spi_1_plat_data.tclk = tclk;
  492. fill_resources(&orion_spi_1, &orion_spi_1_resources,
  493. mapbase, SZ_512 - 1, NO_IRQ);
  494. platform_device_register(&orion_spi_1);
  495. }