config.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/523x/config.c
  4. *
  5. * Sub-architcture dependent initialization code for the Freescale
  6. * 523x CPUs.
  7. *
  8. * Copyright (C) 1999-2005, Greg Ungerer (gerg@snapgear.com)
  9. * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
  10. */
  11. /***************************************************************************/
  12. #include <linux/kernel.h>
  13. #include <linux/param.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <linux/spi/spi.h>
  17. #include <linux/gpio.h>
  18. #include <asm/machdep.h>
  19. #include <asm/coldfire.h>
  20. #include <asm/mcfsim.h>
  21. #include <asm/mcfuart.h>
  22. #include <asm/mcfqspi.h>
  23. /***************************************************************************/
  24. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  25. static struct resource m523x_qspi_resources[] = {
  26. {
  27. .start = MCFQSPI_IOBASE,
  28. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. {
  32. .start = MCFINT_VECBASE + MCFINT_QSPI,
  33. .end = MCFINT_VECBASE + MCFINT_QSPI,
  34. .flags = IORESOURCE_IRQ,
  35. },
  36. };
  37. #define MCFQSPI_CS0 91
  38. #define MCFQSPI_CS1 92
  39. #define MCFQSPI_CS2 103
  40. #define MCFQSPI_CS3 99
  41. static int m523x_cs_setup(struct mcfqspi_cs_control *cs_control)
  42. {
  43. int status;
  44. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  45. if (status) {
  46. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  47. goto fail0;
  48. }
  49. status = gpio_direction_output(MCFQSPI_CS0, 1);
  50. if (status) {
  51. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  52. goto fail1;
  53. }
  54. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  55. if (status) {
  56. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  57. goto fail1;
  58. }
  59. status = gpio_direction_output(MCFQSPI_CS1, 1);
  60. if (status) {
  61. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  62. goto fail2;
  63. }
  64. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  65. if (status) {
  66. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  67. goto fail2;
  68. }
  69. status = gpio_direction_output(MCFQSPI_CS2, 1);
  70. if (status) {
  71. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  72. goto fail3;
  73. }
  74. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  75. if (status) {
  76. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  77. goto fail3;
  78. }
  79. status = gpio_direction_output(MCFQSPI_CS3, 1);
  80. if (status) {
  81. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  82. goto fail4;
  83. }
  84. return 0;
  85. fail4:
  86. gpio_free(MCFQSPI_CS3);
  87. fail3:
  88. gpio_free(MCFQSPI_CS2);
  89. fail2:
  90. gpio_free(MCFQSPI_CS1);
  91. fail1:
  92. gpio_free(MCFQSPI_CS0);
  93. fail0:
  94. return status;
  95. }
  96. static void m523x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  97. {
  98. gpio_free(MCFQSPI_CS3);
  99. gpio_free(MCFQSPI_CS2);
  100. gpio_free(MCFQSPI_CS1);
  101. gpio_free(MCFQSPI_CS0);
  102. }
  103. static void m523x_cs_select(struct mcfqspi_cs_control *cs_control,
  104. u8 chip_select, bool cs_high)
  105. {
  106. switch (chip_select) {
  107. case 0:
  108. gpio_set_value(MCFQSPI_CS0, cs_high);
  109. break;
  110. case 1:
  111. gpio_set_value(MCFQSPI_CS1, cs_high);
  112. break;
  113. case 2:
  114. gpio_set_value(MCFQSPI_CS2, cs_high);
  115. break;
  116. case 3:
  117. gpio_set_value(MCFQSPI_CS3, cs_high);
  118. break;
  119. }
  120. }
  121. static void m523x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  122. u8 chip_select, bool cs_high)
  123. {
  124. switch (chip_select) {
  125. case 0:
  126. gpio_set_value(MCFQSPI_CS0, !cs_high);
  127. break;
  128. case 1:
  129. gpio_set_value(MCFQSPI_CS1, !cs_high);
  130. break;
  131. case 2:
  132. gpio_set_value(MCFQSPI_CS2, !cs_high);
  133. break;
  134. case 3:
  135. gpio_set_value(MCFQSPI_CS3, !cs_high);
  136. break;
  137. }
  138. }
  139. static struct mcfqspi_cs_control m523x_cs_control = {
  140. .setup = m523x_cs_setup,
  141. .teardown = m523x_cs_teardown,
  142. .select = m523x_cs_select,
  143. .deselect = m523x_cs_deselect,
  144. };
  145. static struct mcfqspi_platform_data m523x_qspi_data = {
  146. .bus_num = 0,
  147. .num_chipselect = 4,
  148. .cs_control = &m523x_cs_control,
  149. };
  150. static struct platform_device m523x_qspi = {
  151. .name = "mcfqspi",
  152. .id = 0,
  153. .num_resources = ARRAY_SIZE(m523x_qspi_resources),
  154. .resource = m523x_qspi_resources,
  155. .dev.platform_data = &m523x_qspi_data,
  156. };
  157. static void __init m523x_qspi_init(void)
  158. {
  159. u16 par;
  160. /* setup QSPS pins for QSPI with gpio CS control */
  161. writeb(0x1f, MCFGPIO_PAR_QSPI);
  162. /* and CS2 & CS3 as gpio */
  163. par = readw(MCFGPIO_PAR_TIMER);
  164. par &= 0x3f3f;
  165. writew(par, MCFGPIO_PAR_TIMER);
  166. }
  167. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  168. static struct platform_device *m523x_devices[] __initdata = {
  169. &m523x_fec,
  170. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  171. &m523x_qspi,
  172. #endif
  173. };
  174. /***************************************************************************/
  175. static void __init m523x_fec_init(void)
  176. {
  177. u16 par;
  178. u8 v;
  179. /* Set multi-function pins to ethernet use */
  180. par = readw(MCF_IPSBAR + 0x100082);
  181. writew(par | 0xf00, MCF_IPSBAR + 0x100082);
  182. v = readb(MCF_IPSBAR + 0x100078);
  183. writeb(v | 0xc0, MCF_IPSBAR + 0x100078);
  184. }
  185. /***************************************************************************/
  186. static void m523x_cpu_reset(void)
  187. {
  188. local_irq_disable();
  189. __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR);
  190. }
  191. /***************************************************************************/
  192. void __init config_BSP(char *commandp, int size)
  193. {
  194. mach_reset = m523x_cpu_reset;
  195. mach_sched_init = hw_timer_init;
  196. }
  197. /***************************************************************************/
  198. static int __init init_BSP(void)
  199. {
  200. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  201. m523x_qspi_init();
  202. #endif
  203. platform_add_devices(m523x_devices, ARRAY_SIZE(m523x_devices));
  204. return 0;
  205. }
  206. arch_initcall(init_BSP);
  207. /***************************************************************************/