device.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.platform_data = FEC_PDATA,
  132. };
  133. #ifdef MCFFEC_BASE1
  134. static struct resource mcf_fec1_resources[] = {
  135. {
  136. .start = MCFFEC_BASE1,
  137. .end = MCFFEC_BASE1 + MCFFEC_SIZE1 - 1,
  138. .flags = IORESOURCE_MEM,
  139. },
  140. {
  141. .start = MCF_IRQ_FECRX1,
  142. .end = MCF_IRQ_FECRX1,
  143. .flags = IORESOURCE_IRQ,
  144. },
  145. {
  146. .start = MCF_IRQ_FECTX1,
  147. .end = MCF_IRQ_FECTX1,
  148. .flags = IORESOURCE_IRQ,
  149. },
  150. {
  151. .start = MCF_IRQ_FECENTC1,
  152. .end = MCF_IRQ_FECENTC1,
  153. .flags = IORESOURCE_IRQ,
  154. },
  155. };
  156. static struct platform_device mcf_fec1 = {
  157. .name = FEC_NAME,
  158. .id = 1,
  159. .num_resources = ARRAY_SIZE(mcf_fec1_resources),
  160. .resource = mcf_fec1_resources,
  161. .dev.platform_data = FEC_PDATA,
  162. };
  163. #endif /* MCFFEC_BASE1 */
  164. #endif /* CONFIG_FEC */
  165. #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
  166. /*
  167. * The ColdFire QSPI module is an SPI protocol hardware block used
  168. * on a number of different ColdFire CPUs.
  169. */
  170. static struct resource mcf_qspi_resources[] = {
  171. {
  172. .start = MCFQSPI_BASE,
  173. .end = MCFQSPI_BASE + MCFQSPI_SIZE - 1,
  174. .flags = IORESOURCE_MEM,
  175. },
  176. {
  177. .start = MCF_IRQ_QSPI,
  178. .end = MCF_IRQ_QSPI,
  179. .flags = IORESOURCE_IRQ,
  180. },
  181. };
  182. static int mcf_cs_setup(struct mcfqspi_cs_control *cs_control)
  183. {
  184. int status;
  185. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  186. if (status) {
  187. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  188. goto fail0;
  189. }
  190. status = gpio_direction_output(MCFQSPI_CS0, 1);
  191. if (status) {
  192. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  193. goto fail1;
  194. }
  195. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  196. if (status) {
  197. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  198. goto fail1;
  199. }
  200. status = gpio_direction_output(MCFQSPI_CS1, 1);
  201. if (status) {
  202. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  203. goto fail2;
  204. }
  205. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  206. if (status) {
  207. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  208. goto fail2;
  209. }
  210. status = gpio_direction_output(MCFQSPI_CS2, 1);
  211. if (status) {
  212. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  213. goto fail3;
  214. }
  215. #ifdef MCFQSPI_CS3
  216. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  217. if (status) {
  218. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  219. goto fail3;
  220. }
  221. status = gpio_direction_output(MCFQSPI_CS3, 1);
  222. if (status) {
  223. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  224. gpio_free(MCFQSPI_CS3);
  225. goto fail3;
  226. }
  227. #endif
  228. return 0;
  229. fail3:
  230. gpio_free(MCFQSPI_CS2);
  231. fail2:
  232. gpio_free(MCFQSPI_CS1);
  233. fail1:
  234. gpio_free(MCFQSPI_CS0);
  235. fail0:
  236. return status;
  237. }
  238. static void mcf_cs_teardown(struct mcfqspi_cs_control *cs_control)
  239. {
  240. #ifdef MCFQSPI_CS3
  241. gpio_free(MCFQSPI_CS3);
  242. #endif
  243. gpio_free(MCFQSPI_CS2);
  244. gpio_free(MCFQSPI_CS1);
  245. gpio_free(MCFQSPI_CS0);
  246. }
  247. static void mcf_cs_select(struct mcfqspi_cs_control *cs_control,
  248. u8 chip_select, bool cs_high)
  249. {
  250. switch (chip_select) {
  251. case 0:
  252. gpio_set_value(MCFQSPI_CS0, cs_high);
  253. break;
  254. case 1:
  255. gpio_set_value(MCFQSPI_CS1, cs_high);
  256. break;
  257. case 2:
  258. gpio_set_value(MCFQSPI_CS2, cs_high);
  259. break;
  260. #ifdef MCFQSPI_CS3
  261. case 3:
  262. gpio_set_value(MCFQSPI_CS3, cs_high);
  263. break;
  264. #endif
  265. }
  266. }
  267. static void mcf_cs_deselect(struct mcfqspi_cs_control *cs_control,
  268. u8 chip_select, bool cs_high)
  269. {
  270. switch (chip_select) {
  271. case 0:
  272. gpio_set_value(MCFQSPI_CS0, !cs_high);
  273. break;
  274. case 1:
  275. gpio_set_value(MCFQSPI_CS1, !cs_high);
  276. break;
  277. case 2:
  278. gpio_set_value(MCFQSPI_CS2, !cs_high);
  279. break;
  280. #ifdef MCFQSPI_CS3
  281. case 3:
  282. gpio_set_value(MCFQSPI_CS3, !cs_high);
  283. break;
  284. #endif
  285. }
  286. }
  287. static struct mcfqspi_cs_control mcf_cs_control = {
  288. .setup = mcf_cs_setup,
  289. .teardown = mcf_cs_teardown,
  290. .select = mcf_cs_select,
  291. .deselect = mcf_cs_deselect,
  292. };
  293. static struct mcfqspi_platform_data mcf_qspi_data = {
  294. .bus_num = 0,
  295. .num_chipselect = 4,
  296. .cs_control = &mcf_cs_control,
  297. };
  298. static struct platform_device mcf_qspi = {
  299. .name = "mcfqspi",
  300. .id = 0,
  301. .num_resources = ARRAY_SIZE(mcf_qspi_resources),
  302. .resource = mcf_qspi_resources,
  303. .dev.platform_data = &mcf_qspi_data,
  304. };
  305. #endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
  306. static struct platform_device *mcf_devices[] __initdata = {
  307. &mcf_uart,
  308. #ifdef CONFIG_FEC
  309. &mcf_fec0,
  310. #ifdef MCFFEC_BASE1
  311. &mcf_fec1,
  312. #endif
  313. #endif
  314. #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
  315. &mcf_qspi,
  316. #endif
  317. };
  318. /*
  319. * Some ColdFire UARTs let you set the IRQ line to use.
  320. */
  321. static void __init mcf_uart_set_irq(void)
  322. {
  323. #ifdef MCFUART_UIVR
  324. /* UART0 interrupt setup */
  325. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCFSIM_UART1ICR);
  326. writeb(MCF_IRQ_UART0, MCFUART_BASE0 + MCFUART_UIVR);
  327. mcf_mapirq2imr(MCF_IRQ_UART0, MCFINTC_UART0);
  328. /* UART1 interrupt setup */
  329. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI2, MCFSIM_UART2ICR);
  330. writeb(MCF_IRQ_UART1, MCFUART_BASE1 + MCFUART_UIVR);
  331. mcf_mapirq2imr(MCF_IRQ_UART1, MCFINTC_UART1);
  332. #endif
  333. }
  334. static int __init mcf_init_devices(void)
  335. {
  336. mcf_uart_set_irq();
  337. platform_add_devices(mcf_devices, ARRAY_SIZE(mcf_devices));
  338. return 0;
  339. }
  340. arch_initcall(mcf_init_devices);