config.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  37. static struct resource m5249_qspi_resources[] = {
  38. {
  39. .start = MCFQSPI_IOBASE,
  40. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  41. .flags = IORESOURCE_MEM,
  42. },
  43. {
  44. .start = MCF_IRQ_QSPI,
  45. .end = MCF_IRQ_QSPI,
  46. .flags = IORESOURCE_IRQ,
  47. },
  48. };
  49. #define MCFQSPI_CS0 29
  50. #define MCFQSPI_CS1 24
  51. #define MCFQSPI_CS2 21
  52. #define MCFQSPI_CS3 22
  53. static int m5249_cs_setup(struct mcfqspi_cs_control *cs_control)
  54. {
  55. int status;
  56. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  57. if (status) {
  58. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  59. goto fail0;
  60. }
  61. status = gpio_direction_output(MCFQSPI_CS0, 1);
  62. if (status) {
  63. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  64. goto fail1;
  65. }
  66. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  67. if (status) {
  68. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  69. goto fail1;
  70. }
  71. status = gpio_direction_output(MCFQSPI_CS1, 1);
  72. if (status) {
  73. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  74. goto fail2;
  75. }
  76. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  77. if (status) {
  78. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  79. goto fail2;
  80. }
  81. status = gpio_direction_output(MCFQSPI_CS2, 1);
  82. if (status) {
  83. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  84. goto fail3;
  85. }
  86. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  87. if (status) {
  88. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  89. goto fail3;
  90. }
  91. status = gpio_direction_output(MCFQSPI_CS3, 1);
  92. if (status) {
  93. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  94. goto fail4;
  95. }
  96. return 0;
  97. fail4:
  98. gpio_free(MCFQSPI_CS3);
  99. fail3:
  100. gpio_free(MCFQSPI_CS2);
  101. fail2:
  102. gpio_free(MCFQSPI_CS1);
  103. fail1:
  104. gpio_free(MCFQSPI_CS0);
  105. fail0:
  106. return status;
  107. }
  108. static void m5249_cs_teardown(struct mcfqspi_cs_control *cs_control)
  109. {
  110. gpio_free(MCFQSPI_CS3);
  111. gpio_free(MCFQSPI_CS2);
  112. gpio_free(MCFQSPI_CS1);
  113. gpio_free(MCFQSPI_CS0);
  114. }
  115. static void m5249_cs_select(struct mcfqspi_cs_control *cs_control,
  116. u8 chip_select, bool cs_high)
  117. {
  118. switch (chip_select) {
  119. case 0:
  120. gpio_set_value(MCFQSPI_CS0, cs_high);
  121. break;
  122. case 1:
  123. gpio_set_value(MCFQSPI_CS1, cs_high);
  124. break;
  125. case 2:
  126. gpio_set_value(MCFQSPI_CS2, cs_high);
  127. break;
  128. case 3:
  129. gpio_set_value(MCFQSPI_CS3, cs_high);
  130. break;
  131. }
  132. }
  133. static void m5249_cs_deselect(struct mcfqspi_cs_control *cs_control,
  134. u8 chip_select, bool cs_high)
  135. {
  136. switch (chip_select) {
  137. case 0:
  138. gpio_set_value(MCFQSPI_CS0, !cs_high);
  139. break;
  140. case 1:
  141. gpio_set_value(MCFQSPI_CS1, !cs_high);
  142. break;
  143. case 2:
  144. gpio_set_value(MCFQSPI_CS2, !cs_high);
  145. break;
  146. case 3:
  147. gpio_set_value(MCFQSPI_CS3, !cs_high);
  148. break;
  149. }
  150. }
  151. static struct mcfqspi_cs_control m5249_cs_control = {
  152. .setup = m5249_cs_setup,
  153. .teardown = m5249_cs_teardown,
  154. .select = m5249_cs_select,
  155. .deselect = m5249_cs_deselect,
  156. };
  157. static struct mcfqspi_platform_data m5249_qspi_data = {
  158. .bus_num = 0,
  159. .num_chipselect = 4,
  160. .cs_control = &m5249_cs_control,
  161. };
  162. static struct platform_device m5249_qspi = {
  163. .name = "mcfqspi",
  164. .id = 0,
  165. .num_resources = ARRAY_SIZE(m5249_qspi_resources),
  166. .resource = m5249_qspi_resources,
  167. .dev.platform_data = &m5249_qspi_data,
  168. };
  169. static void __init m5249_qspi_init(void)
  170. {
  171. /* QSPI irq setup */
  172. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL4 | MCFSIM_ICR_PRI0,
  173. MCF_MBAR + MCFSIM_QSPIICR);
  174. mcf_mapirq2imr(MCF_IRQ_QSPI, MCFINTC_QSPI);
  175. }
  176. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  177. static struct platform_device *m5249_devices[] __initdata = {
  178. &m5249_uart,
  179. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  180. &m5249_qspi,
  181. #endif
  182. };
  183. /***************************************************************************/
  184. static void __init m5249_uart_init_line(int line, int irq)
  185. {
  186. if (line == 0) {
  187. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCF_MBAR + MCFSIM_UART1ICR);
  188. writeb(irq, MCF_MBAR + MCFUART_BASE1 + MCFUART_UIVR);
  189. mcf_mapirq2imr(irq, MCFINTC_UART0);
  190. } else if (line == 1) {
  191. writeb(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI2, MCF_MBAR + MCFSIM_UART2ICR);
  192. writeb(irq, MCF_MBAR + MCFUART_BASE2 + MCFUART_UIVR);
  193. mcf_mapirq2imr(irq, MCFINTC_UART1);
  194. }
  195. }
  196. static void __init m5249_uarts_init(void)
  197. {
  198. const int nrlines = ARRAY_SIZE(m5249_uart_platform);
  199. int line;
  200. for (line = 0; (line < nrlines); line++)
  201. m5249_uart_init_line(line, m5249_uart_platform[line].irq);
  202. }
  203. /***************************************************************************/
  204. static void __init m5249_timers_init(void)
  205. {
  206. /* Timer1 is always used as system timer */
  207. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI3,
  208. MCF_MBAR + MCFSIM_TIMER1ICR);
  209. mcf_mapirq2imr(MCF_IRQ_TIMER, MCFINTC_TIMER1);
  210. #ifdef CONFIG_HIGHPROFILE
  211. /* Timer2 is to be used as a high speed profile timer */
  212. writeb(MCFSIM_ICR_AUTOVEC | MCFSIM_ICR_LEVEL7 | MCFSIM_ICR_PRI3,
  213. MCF_MBAR + MCFSIM_TIMER2ICR);
  214. mcf_mapirq2imr(MCF_IRQ_PROFILER, MCFINTC_TIMER2);
  215. #endif
  216. }
  217. /***************************************************************************/
  218. void m5249_cpu_reset(void)
  219. {
  220. local_irq_disable();
  221. /* Set watchdog to soft reset, and enabled */
  222. __raw_writeb(0xc0, MCF_MBAR + MCFSIM_SYPCR);
  223. for (;;)
  224. /* wait for watchdog to timeout */;
  225. }
  226. /***************************************************************************/
  227. void __init config_BSP(char *commandp, int size)
  228. {
  229. mach_reset = m5249_cpu_reset;
  230. m5249_timers_init();
  231. m5249_uarts_init();
  232. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  233. m5249_qspi_init();
  234. #endif
  235. }
  236. /***************************************************************************/
  237. static int __init init_BSP(void)
  238. {
  239. platform_add_devices(m5249_devices, ARRAY_SIZE(m5249_devices));
  240. return 0;
  241. }
  242. arch_initcall(init_BSP);
  243. /***************************************************************************/