config.c 6.7 KB

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