config.c 6.6 KB

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