config.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/5249/config.c
  4. *
  5. * Copyright (C) 2002, Greg Ungerer (gerg@snapgear.com)
  6. */
  7. /***************************************************************************/
  8. #include <linux/kernel.h>
  9. #include <linux/param.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/gpio.h>
  14. #include <asm/machdep.h>
  15. #include <asm/coldfire.h>
  16. #include <asm/mcfsim.h>
  17. #include <asm/mcfuart.h>
  18. #include <asm/mcfqspi.h>
  19. /***************************************************************************/
  20. static struct mcf_platform_uart m5249_uart_platform[] = {
  21. {
  22. .mapbase = MCF_MBAR + MCFUART_BASE1,
  23. .irq = 73,
  24. },
  25. {
  26. .mapbase = MCF_MBAR + MCFUART_BASE2,
  27. .irq = 74,
  28. },
  29. { },
  30. };
  31. static struct platform_device m5249_uart = {
  32. .name = "mcfuart",
  33. .id = 0,
  34. .dev.platform_data = m5249_uart_platform,
  35. };
  36. #ifdef CONFIG_M5249C3
  37. static struct resource m5249_smc91x_resources[] = {
  38. {
  39. .start = 0xe0000300,
  40. .end = 0xe0000300 + 0x100,
  41. .flags = IORESOURCE_MEM,
  42. },
  43. {
  44. .start = MCFINTC2_GPIOIRQ6,
  45. .end = MCFINTC2_GPIOIRQ6,
  46. .flags = IORESOURCE_IRQ,
  47. },
  48. };
  49. static struct platform_device m5249_smc91x = {
  50. .name = "smc91x",
  51. .id = 0,
  52. .num_resources = ARRAY_SIZE(m5249_smc91x_resources),
  53. .resource = m5249_smc91x_resources,
  54. };
  55. #endif /* CONFIG_M5249C3 */
  56. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  57. static struct resource m5249_qspi_resources[] = {
  58. {
  59. .start = MCFQSPI_IOBASE,
  60. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  61. .flags = IORESOURCE_MEM,
  62. },
  63. {
  64. .start = MCF_IRQ_QSPI,
  65. .end = MCF_IRQ_QSPI,
  66. .flags = IORESOURCE_IRQ,
  67. },
  68. };
  69. #define MCFQSPI_CS0 29
  70. #define MCFQSPI_CS1 24
  71. #define MCFQSPI_CS2 21
  72. #define MCFQSPI_CS3 22
  73. static int m5249_cs_setup(struct mcfqspi_cs_control *cs_control)
  74. {
  75. int status;
  76. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  77. if (status) {
  78. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  79. goto fail0;
  80. }
  81. status = gpio_direction_output(MCFQSPI_CS0, 1);
  82. if (status) {
  83. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  84. goto fail1;
  85. }
  86. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  87. if (status) {
  88. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  89. goto fail1;
  90. }
  91. status = gpio_direction_output(MCFQSPI_CS1, 1);
  92. if (status) {
  93. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  94. goto fail2;
  95. }
  96. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  97. if (status) {
  98. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  99. goto fail2;
  100. }
  101. status = gpio_direction_output(MCFQSPI_CS2, 1);
  102. if (status) {
  103. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  104. goto fail3;
  105. }
  106. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  107. if (status) {
  108. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  109. goto fail3;
  110. }
  111. status = gpio_direction_output(MCFQSPI_CS3, 1);
  112. if (status) {
  113. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  114. goto fail4;
  115. }
  116. return 0;
  117. fail4:
  118. gpio_free(MCFQSPI_CS3);
  119. fail3:
  120. gpio_free(MCFQSPI_CS2);
  121. fail2:
  122. gpio_free(MCFQSPI_CS1);
  123. fail1:
  124. gpio_free(MCFQSPI_CS0);
  125. fail0:
  126. return status;
  127. }
  128. static void m5249_cs_teardown(struct mcfqspi_cs_control *cs_control)
  129. {
  130. gpio_free(MCFQSPI_CS3);
  131. gpio_free(MCFQSPI_CS2);
  132. gpio_free(MCFQSPI_CS1);
  133. gpio_free(MCFQSPI_CS0);
  134. }
  135. static void m5249_cs_select(struct mcfqspi_cs_control *cs_control,
  136. u8 chip_select, bool cs_high)
  137. {
  138. switch (chip_select) {
  139. case 0:
  140. gpio_set_value(MCFQSPI_CS0, cs_high);
  141. break;
  142. case 1:
  143. gpio_set_value(MCFQSPI_CS1, cs_high);
  144. break;
  145. case 2:
  146. gpio_set_value(MCFQSPI_CS2, cs_high);
  147. break;
  148. case 3:
  149. gpio_set_value(MCFQSPI_CS3, cs_high);
  150. break;
  151. }
  152. }
  153. static void m5249_cs_deselect(struct mcfqspi_cs_control *cs_control,
  154. u8 chip_select, bool cs_high)
  155. {
  156. switch (chip_select) {
  157. case 0:
  158. gpio_set_value(MCFQSPI_CS0, !cs_high);
  159. break;
  160. case 1:
  161. gpio_set_value(MCFQSPI_CS1, !cs_high);
  162. break;
  163. case 2:
  164. gpio_set_value(MCFQSPI_CS2, !cs_high);
  165. break;
  166. case 3:
  167. gpio_set_value(MCFQSPI_CS3, !cs_high);
  168. break;
  169. }
  170. }
  171. static struct mcfqspi_cs_control m5249_cs_control = {
  172. .setup = m5249_cs_setup,
  173. .teardown = m5249_cs_teardown,
  174. .select = m5249_cs_select,
  175. .deselect = m5249_cs_deselect,
  176. };
  177. static struct mcfqspi_platform_data m5249_qspi_data = {
  178. .bus_num = 0,
  179. .num_chipselect = 4,
  180. .cs_control = &m5249_cs_control,
  181. };
  182. static struct platform_device m5249_qspi = {
  183. .name = "mcfqspi",
  184. .id = 0,
  185. .num_resources = ARRAY_SIZE(m5249_qspi_resources),
  186. .resource = m5249_qspi_resources,
  187. .dev.platform_data = &m5249_qspi_data,
  188. };
  189. static void __init m5249_qspi_init(void)
  190. {
  191. /* QSPI irq setup */
  192. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI0,
  193. MCF_MBAR + MCFSIM_QSPIICR);
  194. mcf_mapirq2imr(MCF_IRQ_QSPI, MCFINTC_QSPI);
  195. }
  196. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  197. static struct platform_device *m5249_devices[] __initdata = {
  198. &m5249_uart,
  199. #ifdef CONFIG_M5249C3
  200. &m5249_smc91x,
  201. #endif
  202. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  203. &m5249_qspi,
  204. #endif
  205. };
  206. /***************************************************************************/
  207. static void __init m5249_uart_init_line(int line, int irq)
  208. {
  209. if (line == 0) {
  210. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCF_MBAR + MCFSIM_UART1ICR);
  211. writeb(irq, MCF_MBAR + MCFUART_BASE1 + MCFUART_UIVR);
  212. mcf_mapirq2imr(irq, MCFINTC_UART0);
  213. } else if (line == 1) {
  214. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI2, MCF_MBAR + MCFSIM_UART2ICR);
  215. writeb(irq, MCF_MBAR + MCFUART_BASE2 + MCFUART_UIVR);
  216. mcf_mapirq2imr(irq, MCFINTC_UART1);
  217. }
  218. }
  219. static void __init m5249_uarts_init(void)
  220. {
  221. const int nrlines = ARRAY_SIZE(m5249_uart_platform);
  222. int line;
  223. for (line = 0; (line < nrlines); line++)
  224. m5249_uart_init_line(line, m5249_uart_platform[line].irq);
  225. }
  226. /***************************************************************************/
  227. #ifdef CONFIG_M5249C3
  228. static void __init m5249_smc91x_init(void)
  229. {
  230. u32 gpio;
  231. /* Set the GPIO line as interrupt source for smc91x device */
  232. gpio = readl(MCF_MBAR2 + MCFSIM2_GPIOINTENABLE);
  233. writel(gpio | 0x40, MCF_MBAR2 + MCFSIM2_GPIOINTENABLE);
  234. gpio = readl(MCF_MBAR2 + MCFSIM2_INTLEVEL5);
  235. writel(gpio | 0x04000000, MCF_MBAR2 + MCFSIM2_INTLEVEL5);
  236. }
  237. #endif /* CONFIG_M5249C3 */
  238. /***************************************************************************/
  239. static void __init m5249_timers_init(void)
  240. {
  241. /* Timer1 is always used as system timer */
  242. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI3,
  243. MCF_MBAR + MCFSIM_TIMER1ICR);
  244. mcf_mapirq2imr(MCF_IRQ_TIMER, MCFINTC_TIMER1);
  245. #ifdef CONFIG_HIGHPROFILE
  246. /* Timer2 is to be used as a high speed profile timer */
  247. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3,
  248. MCF_MBAR + MCFSIM_TIMER2ICR);
  249. mcf_mapirq2imr(MCF_IRQ_PROFILER, MCFINTC_TIMER2);
  250. #endif
  251. }
  252. /***************************************************************************/
  253. void m5249_cpu_reset(void)
  254. {
  255. local_irq_disable();
  256. /* Set watchdog to soft reset, and enabled */
  257. __raw_writeb(0xc0, MCF_MBAR + MCFSIM_SYPCR);
  258. for (;;)
  259. /* wait for watchdog to timeout */;
  260. }
  261. /***************************************************************************/
  262. void __init config_BSP(char *commandp, int size)
  263. {
  264. mach_reset = m5249_cpu_reset;
  265. m5249_timers_init();
  266. m5249_uarts_init();
  267. #ifdef CONFIG_M5249C3
  268. m5249_smc91x_init();
  269. #endif
  270. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  271. m5249_qspi_init();
  272. #endif
  273. }
  274. /***************************************************************************/
  275. static int __init init_BSP(void)
  276. {
  277. platform_add_devices(m5249_devices, ARRAY_SIZE(m5249_devices));
  278. return 0;
  279. }
  280. arch_initcall(init_BSP);
  281. /***************************************************************************/