device.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * device.c -- common ColdFire SoC device support
  3. *
  4. * (C) Copyright 2011, Greg Ungerer <gerg@uclinux.org>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/gpio.h>
  15. #include <linux/fec.h>
  16. #include <asm/traps.h>
  17. #include <asm/coldfire.h>
  18. #include <asm/mcfsim.h>
  19. #include <asm/mcfuart.h>
  20. #include <asm/mcfqspi.h>
  21. /*
  22. * All current ColdFire parts contain from 2, 3, 4 or 10 UARTS.
  23. */
  24. static struct mcf_platform_uart mcf_uart_platform_data[] = {
  25. {
  26. .mapbase = MCFUART_BASE0,
  27. .irq = MCF_IRQ_UART0,
  28. },
  29. {
  30. .mapbase = MCFUART_BASE1,
  31. .irq = MCF_IRQ_UART1,
  32. },
  33. #ifdef MCFUART_BASE2
  34. {
  35. .mapbase = MCFUART_BASE2,
  36. .irq = MCF_IRQ_UART2,
  37. },
  38. #endif
  39. #ifdef MCFUART_BASE3
  40. {
  41. .mapbase = MCFUART_BASE3,
  42. .irq = MCF_IRQ_UART3,
  43. },
  44. #endif
  45. #ifdef MCFUART_BASE4
  46. {
  47. .mapbase = MCFUART_BASE4,
  48. .irq = MCF_IRQ_UART4,
  49. },
  50. #endif
  51. #ifdef MCFUART_BASE5
  52. {
  53. .mapbase = MCFUART_BASE5,
  54. .irq = MCF_IRQ_UART5,
  55. },
  56. #endif
  57. #ifdef MCFUART_BASE6
  58. {
  59. .mapbase = MCFUART_BASE6,
  60. .irq = MCF_IRQ_UART6,
  61. },
  62. #endif
  63. #ifdef MCFUART_BASE7
  64. {
  65. .mapbase = MCFUART_BASE7,
  66. .irq = MCF_IRQ_UART7,
  67. },
  68. #endif
  69. #ifdef MCFUART_BASE8
  70. {
  71. .mapbase = MCFUART_BASE8,
  72. .irq = MCF_IRQ_UART8,
  73. },
  74. #endif
  75. #ifdef MCFUART_BASE9
  76. {
  77. .mapbase = MCFUART_BASE9,
  78. .irq = MCF_IRQ_UART9,
  79. },
  80. #endif
  81. { },
  82. };
  83. static struct platform_device mcf_uart = {
  84. .name = "mcfuart",
  85. .id = 0,
  86. .dev.platform_data = mcf_uart_platform_data,
  87. };
  88. #ifdef CONFIG_FEC
  89. #ifdef CONFIG_M5441x
  90. #define FEC_NAME "enet-fec"
  91. static struct fec_platform_data fec_pdata = {
  92. .phy = PHY_INTERFACE_MODE_RMII,
  93. };
  94. #define FEC_PDATA (&fec_pdata)
  95. #else
  96. #define FEC_NAME "fec"
  97. #define FEC_PDATA NULL
  98. #endif
  99. /*
  100. * Some ColdFire cores contain the Fast Ethernet Controller (FEC)
  101. * block. It is Freescale's own hardware block. Some ColdFires
  102. * have 2 of these.
  103. */
  104. static struct resource mcf_fec0_resources[] = {
  105. {
  106. .start = MCFFEC_BASE0,
  107. .end = MCFFEC_BASE0 + MCFFEC_SIZE0 - 1,
  108. .flags = IORESOURCE_MEM,
  109. },
  110. {
  111. .start = MCF_IRQ_FECRX0,
  112. .end = MCF_IRQ_FECRX0,
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. {
  116. .start = MCF_IRQ_FECTX0,
  117. .end = MCF_IRQ_FECTX0,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. {
  121. .start = MCF_IRQ_FECENTC0,
  122. .end = MCF_IRQ_FECENTC0,
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. };
  126. static struct platform_device mcf_fec0 = {
  127. .name = FEC_NAME,
  128. .id = 0,
  129. .num_resources = ARRAY_SIZE(mcf_fec0_resources),
  130. .resource = mcf_fec0_resources,
  131. .dev = {
  132. .dma_mask = &mcf_fec0.dev.coherent_dma_mask,
  133. .coherent_dma_mask = DMA_BIT_MASK(32),
  134. .platform_data = FEC_PDATA,
  135. }
  136. };
  137. #ifdef MCFFEC_BASE1
  138. static struct resource mcf_fec1_resources[] = {
  139. {
  140. .start = MCFFEC_BASE1,
  141. .end = MCFFEC_BASE1 + MCFFEC_SIZE1 - 1,
  142. .flags = IORESOURCE_MEM,
  143. },
  144. {
  145. .start = MCF_IRQ_FECRX1,
  146. .end = MCF_IRQ_FECRX1,
  147. .flags = IORESOURCE_IRQ,
  148. },
  149. {
  150. .start = MCF_IRQ_FECTX1,
  151. .end = MCF_IRQ_FECTX1,
  152. .flags = IORESOURCE_IRQ,
  153. },
  154. {
  155. .start = MCF_IRQ_FECENTC1,
  156. .end = MCF_IRQ_FECENTC1,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. };
  160. static struct platform_device mcf_fec1 = {
  161. .name = FEC_NAME,
  162. .id = 1,
  163. .num_resources = ARRAY_SIZE(mcf_fec1_resources),
  164. .resource = mcf_fec1_resources,
  165. .dev = {
  166. .dma_mask = &mcf_fec1.dev.coherent_dma_mask,
  167. .coherent_dma_mask = DMA_BIT_MASK(32),
  168. .platform_data = FEC_PDATA,
  169. }
  170. };
  171. #endif /* MCFFEC_BASE1 */
  172. #endif /* CONFIG_FEC */
  173. #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
  174. /*
  175. * The ColdFire QSPI module is an SPI protocol hardware block used
  176. * on a number of different ColdFire CPUs.
  177. */
  178. static struct resource mcf_qspi_resources[] = {
  179. {
  180. .start = MCFQSPI_BASE,
  181. .end = MCFQSPI_BASE + MCFQSPI_SIZE - 1,
  182. .flags = IORESOURCE_MEM,
  183. },
  184. {
  185. .start = MCF_IRQ_QSPI,
  186. .end = MCF_IRQ_QSPI,
  187. .flags = IORESOURCE_IRQ,
  188. },
  189. };
  190. static int mcf_cs_setup(struct mcfqspi_cs_control *cs_control)
  191. {
  192. int status;
  193. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  194. if (status) {
  195. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  196. goto fail0;
  197. }
  198. status = gpio_direction_output(MCFQSPI_CS0, 1);
  199. if (status) {
  200. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  201. goto fail1;
  202. }
  203. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  204. if (status) {
  205. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  206. goto fail1;
  207. }
  208. status = gpio_direction_output(MCFQSPI_CS1, 1);
  209. if (status) {
  210. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  211. goto fail2;
  212. }
  213. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  214. if (status) {
  215. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  216. goto fail2;
  217. }
  218. status = gpio_direction_output(MCFQSPI_CS2, 1);
  219. if (status) {
  220. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  221. goto fail3;
  222. }
  223. #ifdef MCFQSPI_CS3
  224. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  225. if (status) {
  226. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  227. goto fail3;
  228. }
  229. status = gpio_direction_output(MCFQSPI_CS3, 1);
  230. if (status) {
  231. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  232. gpio_free(MCFQSPI_CS3);
  233. goto fail3;
  234. }
  235. #endif
  236. return 0;
  237. fail3:
  238. gpio_free(MCFQSPI_CS2);
  239. fail2:
  240. gpio_free(MCFQSPI_CS1);
  241. fail1:
  242. gpio_free(MCFQSPI_CS0);
  243. fail0:
  244. return status;
  245. }
  246. static void mcf_cs_teardown(struct mcfqspi_cs_control *cs_control)
  247. {
  248. #ifdef MCFQSPI_CS3
  249. gpio_free(MCFQSPI_CS3);
  250. #endif
  251. gpio_free(MCFQSPI_CS2);
  252. gpio_free(MCFQSPI_CS1);
  253. gpio_free(MCFQSPI_CS0);
  254. }
  255. static void mcf_cs_select(struct mcfqspi_cs_control *cs_control,
  256. u8 chip_select, bool cs_high)
  257. {
  258. switch (chip_select) {
  259. case 0:
  260. gpio_set_value(MCFQSPI_CS0, cs_high);
  261. break;
  262. case 1:
  263. gpio_set_value(MCFQSPI_CS1, cs_high);
  264. break;
  265. case 2:
  266. gpio_set_value(MCFQSPI_CS2, cs_high);
  267. break;
  268. #ifdef MCFQSPI_CS3
  269. case 3:
  270. gpio_set_value(MCFQSPI_CS3, cs_high);
  271. break;
  272. #endif
  273. }
  274. }
  275. static void mcf_cs_deselect(struct mcfqspi_cs_control *cs_control,
  276. u8 chip_select, bool cs_high)
  277. {
  278. switch (chip_select) {
  279. case 0:
  280. gpio_set_value(MCFQSPI_CS0, !cs_high);
  281. break;
  282. case 1:
  283. gpio_set_value(MCFQSPI_CS1, !cs_high);
  284. break;
  285. case 2:
  286. gpio_set_value(MCFQSPI_CS2, !cs_high);
  287. break;
  288. #ifdef MCFQSPI_CS3
  289. case 3:
  290. gpio_set_value(MCFQSPI_CS3, !cs_high);
  291. break;
  292. #endif
  293. }
  294. }
  295. static struct mcfqspi_cs_control mcf_cs_control = {
  296. .setup = mcf_cs_setup,
  297. .teardown = mcf_cs_teardown,
  298. .select = mcf_cs_select,
  299. .deselect = mcf_cs_deselect,
  300. };
  301. static struct mcfqspi_platform_data mcf_qspi_data = {
  302. .bus_num = 0,
  303. .num_chipselect = 4,
  304. .cs_control = &mcf_cs_control,
  305. };
  306. static struct platform_device mcf_qspi = {
  307. .name = "mcfqspi",
  308. .id = 0,
  309. .num_resources = ARRAY_SIZE(mcf_qspi_resources),
  310. .resource = mcf_qspi_resources,
  311. .dev.platform_data = &mcf_qspi_data,
  312. };
  313. #endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
  314. static struct platform_device *mcf_devices[] __initdata = {
  315. &mcf_uart,
  316. #ifdef CONFIG_FEC
  317. &mcf_fec0,
  318. #ifdef MCFFEC_BASE1
  319. &mcf_fec1,
  320. #endif
  321. #endif
  322. #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
  323. &mcf_qspi,
  324. #endif
  325. };
  326. /*
  327. * Some ColdFire UARTs let you set the IRQ line to use.
  328. */
  329. static void __init mcf_uart_set_irq(void)
  330. {
  331. #ifdef MCFUART_UIVR
  332. /* UART0 interrupt setup */
  333. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCFSIM_UART1ICR);
  334. writeb(MCF_IRQ_UART0, MCFUART_BASE0 + MCFUART_UIVR);
  335. mcf_mapirq2imr(MCF_IRQ_UART0, MCFINTC_UART0);
  336. /* UART1 interrupt setup */
  337. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI2, MCFSIM_UART2ICR);
  338. writeb(MCF_IRQ_UART1, MCFUART_BASE1 + MCFUART_UIVR);
  339. mcf_mapirq2imr(MCF_IRQ_UART1, MCFINTC_UART1);
  340. #endif
  341. }
  342. static int __init mcf_init_devices(void)
  343. {
  344. mcf_uart_set_irq();
  345. platform_add_devices(mcf_devices, ARRAY_SIZE(mcf_devices));
  346. return 0;
  347. }
  348. arch_initcall(mcf_init_devices);