config.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. static struct mcf_platform_uart m523x_uart_platform[] = {
  25. {
  26. .mapbase = MCFUART_BASE1,
  27. .irq = MCFINT_VECBASE + MCFINT_UART0,
  28. },
  29. {
  30. .mapbase = MCFUART_BASE2,
  31. .irq = MCFINT_VECBASE + MCFINT_UART0 + 1,
  32. },
  33. {
  34. .mapbase = MCFUART_BASE3,
  35. .irq = MCFINT_VECBASE + MCFINT_UART0 + 2,
  36. },
  37. { },
  38. };
  39. static struct platform_device m523x_uart = {
  40. .name = "mcfuart",
  41. .id = 0,
  42. .dev.platform_data = m523x_uart_platform,
  43. };
  44. static struct resource m523x_fec_resources[] = {
  45. {
  46. .start = MCFFEC_BASE,
  47. .end = MCFFEC_BASE + MCFFEC_SIZE - 1,
  48. .flags = IORESOURCE_MEM,
  49. },
  50. {
  51. .start = 64 + 23,
  52. .end = 64 + 23,
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. {
  56. .start = 64 + 27,
  57. .end = 64 + 27,
  58. .flags = IORESOURCE_IRQ,
  59. },
  60. {
  61. .start = 64 + 29,
  62. .end = 64 + 29,
  63. .flags = IORESOURCE_IRQ,
  64. },
  65. };
  66. static struct platform_device m523x_fec = {
  67. .name = "fec",
  68. .id = 0,
  69. .num_resources = ARRAY_SIZE(m523x_fec_resources),
  70. .resource = m523x_fec_resources,
  71. };
  72. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  73. static struct resource m523x_qspi_resources[] = {
  74. {
  75. .start = MCFQSPI_IOBASE,
  76. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. {
  80. .start = MCFINT_VECBASE + MCFINT_QSPI,
  81. .end = MCFINT_VECBASE + MCFINT_QSPI,
  82. .flags = IORESOURCE_IRQ,
  83. },
  84. };
  85. #define MCFQSPI_CS0 91
  86. #define MCFQSPI_CS1 92
  87. #define MCFQSPI_CS2 103
  88. #define MCFQSPI_CS3 99
  89. static int m523x_cs_setup(struct mcfqspi_cs_control *cs_control)
  90. {
  91. int status;
  92. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  93. if (status) {
  94. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  95. goto fail0;
  96. }
  97. status = gpio_direction_output(MCFQSPI_CS0, 1);
  98. if (status) {
  99. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  100. goto fail1;
  101. }
  102. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  103. if (status) {
  104. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  105. goto fail1;
  106. }
  107. status = gpio_direction_output(MCFQSPI_CS1, 1);
  108. if (status) {
  109. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  110. goto fail2;
  111. }
  112. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  113. if (status) {
  114. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  115. goto fail2;
  116. }
  117. status = gpio_direction_output(MCFQSPI_CS2, 1);
  118. if (status) {
  119. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  120. goto fail3;
  121. }
  122. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  123. if (status) {
  124. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  125. goto fail3;
  126. }
  127. status = gpio_direction_output(MCFQSPI_CS3, 1);
  128. if (status) {
  129. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  130. goto fail4;
  131. }
  132. return 0;
  133. fail4:
  134. gpio_free(MCFQSPI_CS3);
  135. fail3:
  136. gpio_free(MCFQSPI_CS2);
  137. fail2:
  138. gpio_free(MCFQSPI_CS1);
  139. fail1:
  140. gpio_free(MCFQSPI_CS0);
  141. fail0:
  142. return status;
  143. }
  144. static void m523x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  145. {
  146. gpio_free(MCFQSPI_CS3);
  147. gpio_free(MCFQSPI_CS2);
  148. gpio_free(MCFQSPI_CS1);
  149. gpio_free(MCFQSPI_CS0);
  150. }
  151. static void m523x_cs_select(struct mcfqspi_cs_control *cs_control,
  152. u8 chip_select, bool cs_high)
  153. {
  154. switch (chip_select) {
  155. case 0:
  156. gpio_set_value(MCFQSPI_CS0, cs_high);
  157. break;
  158. case 1:
  159. gpio_set_value(MCFQSPI_CS1, cs_high);
  160. break;
  161. case 2:
  162. gpio_set_value(MCFQSPI_CS2, cs_high);
  163. break;
  164. case 3:
  165. gpio_set_value(MCFQSPI_CS3, cs_high);
  166. break;
  167. }
  168. }
  169. static void m523x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  170. u8 chip_select, bool cs_high)
  171. {
  172. switch (chip_select) {
  173. case 0:
  174. gpio_set_value(MCFQSPI_CS0, !cs_high);
  175. break;
  176. case 1:
  177. gpio_set_value(MCFQSPI_CS1, !cs_high);
  178. break;
  179. case 2:
  180. gpio_set_value(MCFQSPI_CS2, !cs_high);
  181. break;
  182. case 3:
  183. gpio_set_value(MCFQSPI_CS3, !cs_high);
  184. break;
  185. }
  186. }
  187. static struct mcfqspi_cs_control m523x_cs_control = {
  188. .setup = m523x_cs_setup,
  189. .teardown = m523x_cs_teardown,
  190. .select = m523x_cs_select,
  191. .deselect = m523x_cs_deselect,
  192. };
  193. static struct mcfqspi_platform_data m523x_qspi_data = {
  194. .bus_num = 0,
  195. .num_chipselect = 4,
  196. .cs_control = &m523x_cs_control,
  197. };
  198. static struct platform_device m523x_qspi = {
  199. .name = "mcfqspi",
  200. .id = 0,
  201. .num_resources = ARRAY_SIZE(m523x_qspi_resources),
  202. .resource = m523x_qspi_resources,
  203. .dev.platform_data = &m523x_qspi_data,
  204. };
  205. static void __init m523x_qspi_init(void)
  206. {
  207. u16 par;
  208. /* setup QSPS pins for QSPI with gpio CS control */
  209. writeb(0x1f, MCFGPIO_PAR_QSPI);
  210. /* and CS2 & CS3 as gpio */
  211. par = readw(MCFGPIO_PAR_TIMER);
  212. par &= 0x3f3f;
  213. writew(par, MCFGPIO_PAR_TIMER);
  214. }
  215. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  216. static struct platform_device *m523x_devices[] __initdata = {
  217. &m523x_uart,
  218. &m523x_fec,
  219. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  220. &m523x_qspi,
  221. #endif
  222. };
  223. /***************************************************************************/
  224. static void __init m523x_fec_init(void)
  225. {
  226. u16 par;
  227. u8 v;
  228. /* Set multi-function pins to ethernet use */
  229. par = readw(MCF_IPSBAR + 0x100082);
  230. writew(par | 0xf00, MCF_IPSBAR + 0x100082);
  231. v = readb(MCF_IPSBAR + 0x100078);
  232. writeb(v | 0xc0, MCF_IPSBAR + 0x100078);
  233. }
  234. /***************************************************************************/
  235. static void m523x_cpu_reset(void)
  236. {
  237. local_irq_disable();
  238. __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR);
  239. }
  240. /***************************************************************************/
  241. void __init config_BSP(char *commandp, int size)
  242. {
  243. mach_reset = m523x_cpu_reset;
  244. }
  245. /***************************************************************************/
  246. static int __init init_BSP(void)
  247. {
  248. m523x_fec_init();
  249. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  250. m523x_qspi_init();
  251. #endif
  252. platform_add_devices(m523x_devices, ARRAY_SIZE(m523x_devices));
  253. return 0;
  254. }
  255. arch_initcall(init_BSP);
  256. /***************************************************************************/