config.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/520x/config.c
  4. *
  5. * Copyright (C) 2005, Freescale (www.freescale.com)
  6. * Copyright (C) 2005, Intec Automation (mike@steroidmicros.com)
  7. * Copyright (C) 1999-2007, Greg Ungerer (gerg@snapgear.com)
  8. * Copyright (C) 2001-2003, SnapGear Inc. (www.snapgear.com)
  9. */
  10. /***************************************************************************/
  11. #include <linux/kernel.h>
  12. #include <linux/param.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/gpio.h>
  17. #include <asm/machdep.h>
  18. #include <asm/coldfire.h>
  19. #include <asm/mcfsim.h>
  20. #include <asm/mcfuart.h>
  21. #include <asm/mcfqspi.h>
  22. /***************************************************************************/
  23. static struct mcf_platform_uart m520x_uart_platform[] = {
  24. {
  25. .mapbase = MCFUART_BASE1,
  26. .irq = MCFINT_VECBASE + MCFINT_UART0,
  27. },
  28. {
  29. .mapbase = MCFUART_BASE2,
  30. .irq = MCFINT_VECBASE + MCFINT_UART1,
  31. },
  32. {
  33. .mapbase = MCFUART_BASE3,
  34. .irq = MCFINT_VECBASE + MCFINT_UART2,
  35. },
  36. { },
  37. };
  38. static struct platform_device m520x_uart = {
  39. .name = "mcfuart",
  40. .id = 0,
  41. .dev.platform_data = m520x_uart_platform,
  42. };
  43. static struct resource m520x_fec_resources[] = {
  44. {
  45. .start = MCFFEC_BASE,
  46. .end = MCFFEC_BASE + MCFFEC_SIZE - 1,
  47. .flags = IORESOURCE_MEM,
  48. },
  49. {
  50. .start = 64 + 36,
  51. .end = 64 + 36,
  52. .flags = IORESOURCE_IRQ,
  53. },
  54. {
  55. .start = 64 + 40,
  56. .end = 64 + 40,
  57. .flags = IORESOURCE_IRQ,
  58. },
  59. {
  60. .start = 64 + 42,
  61. .end = 64 + 42,
  62. .flags = IORESOURCE_IRQ,
  63. },
  64. };
  65. static struct platform_device m520x_fec = {
  66. .name = "fec",
  67. .id = 0,
  68. .num_resources = ARRAY_SIZE(m520x_fec_resources),
  69. .resource = m520x_fec_resources,
  70. };
  71. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  72. static struct resource m520x_qspi_resources[] = {
  73. {
  74. .start = MCFQSPI_IOBASE,
  75. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. {
  79. .start = MCFINT_VECBASE + MCFINT_QSPI,
  80. .end = MCFINT_VECBASE + MCFINT_QSPI,
  81. .flags = IORESOURCE_IRQ,
  82. },
  83. };
  84. #define MCFQSPI_CS0 62
  85. #define MCFQSPI_CS1 63
  86. #define MCFQSPI_CS2 44
  87. static int m520x_cs_setup(struct mcfqspi_cs_control *cs_control)
  88. {
  89. int status;
  90. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  91. if (status) {
  92. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  93. goto fail0;
  94. }
  95. status = gpio_direction_output(MCFQSPI_CS0, 1);
  96. if (status) {
  97. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  98. goto fail1;
  99. }
  100. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  101. if (status) {
  102. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  103. goto fail1;
  104. }
  105. status = gpio_direction_output(MCFQSPI_CS1, 1);
  106. if (status) {
  107. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  108. goto fail2;
  109. }
  110. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  111. if (status) {
  112. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  113. goto fail2;
  114. }
  115. status = gpio_direction_output(MCFQSPI_CS2, 1);
  116. if (status) {
  117. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  118. goto fail3;
  119. }
  120. return 0;
  121. fail3:
  122. gpio_free(MCFQSPI_CS2);
  123. fail2:
  124. gpio_free(MCFQSPI_CS1);
  125. fail1:
  126. gpio_free(MCFQSPI_CS0);
  127. fail0:
  128. return status;
  129. }
  130. static void m520x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  131. {
  132. gpio_free(MCFQSPI_CS2);
  133. gpio_free(MCFQSPI_CS1);
  134. gpio_free(MCFQSPI_CS0);
  135. }
  136. static void m520x_cs_select(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. }
  150. }
  151. static void m520x_cs_deselect(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. }
  165. }
  166. static struct mcfqspi_cs_control m520x_cs_control = {
  167. .setup = m520x_cs_setup,
  168. .teardown = m520x_cs_teardown,
  169. .select = m520x_cs_select,
  170. .deselect = m520x_cs_deselect,
  171. };
  172. static struct mcfqspi_platform_data m520x_qspi_data = {
  173. .bus_num = 0,
  174. .num_chipselect = 3,
  175. .cs_control = &m520x_cs_control,
  176. };
  177. static struct platform_device m520x_qspi = {
  178. .name = "mcfqspi",
  179. .id = 0,
  180. .num_resources = ARRAY_SIZE(m520x_qspi_resources),
  181. .resource = m520x_qspi_resources,
  182. .dev.platform_data = &m520x_qspi_data,
  183. };
  184. static void __init m520x_qspi_init(void)
  185. {
  186. u16 par;
  187. /* setup Port QS for QSPI with gpio CS control */
  188. writeb(0x3f, MCF_GPIO_PAR_QSPI);
  189. /* make U1CTS and U2RTS gpio for cs_control */
  190. par = readw(MCF_GPIO_PAR_UART);
  191. par &= 0x00ff;
  192. writew(par, MCF_GPIO_PAR_UART);
  193. }
  194. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  195. static struct platform_device *m520x_devices[] __initdata = {
  196. &m520x_uart,
  197. &m520x_fec,
  198. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  199. &m520x_qspi,
  200. #endif
  201. };
  202. /***************************************************************************/
  203. static void __init m520x_uart_init_line(int line, int irq)
  204. {
  205. u16 par;
  206. u8 par2;
  207. switch (line) {
  208. case 0:
  209. par = readw(MCF_GPIO_PAR_UART);
  210. par |= MCF_GPIO_PAR_UART_PAR_UTXD0 |
  211. MCF_GPIO_PAR_UART_PAR_URXD0;
  212. writew(par, MCF_GPIO_PAR_UART);
  213. break;
  214. case 1:
  215. par = readw(MCF_GPIO_PAR_UART);
  216. par |= MCF_GPIO_PAR_UART_PAR_UTXD1 |
  217. MCF_GPIO_PAR_UART_PAR_URXD1;
  218. writew(par, MCF_GPIO_PAR_UART);
  219. break;
  220. case 2:
  221. par2 = readb(MCF_GPIO_PAR_FECI2C);
  222. par2 &= ~0x0F;
  223. par2 |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2 |
  224. MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2;
  225. writeb(par2, MCF_GPIO_PAR_FECI2C);
  226. break;
  227. }
  228. }
  229. static void __init m520x_uarts_init(void)
  230. {
  231. const int nrlines = ARRAY_SIZE(m520x_uart_platform);
  232. int line;
  233. for (line = 0; (line < nrlines); line++)
  234. m520x_uart_init_line(line, m520x_uart_platform[line].irq);
  235. }
  236. /***************************************************************************/
  237. static void __init m520x_fec_init(void)
  238. {
  239. u8 v;
  240. /* Set multi-function pins to ethernet mode */
  241. v = readb(MCF_GPIO_PAR_FEC);
  242. writeb(v | 0xf0, MCF_GPIO_PAR_FEC);
  243. v = readb(MCF_GPIO_PAR_FECI2C);
  244. writeb(v | 0x0f, MCF_GPIO_PAR_FECI2C);
  245. }
  246. /***************************************************************************/
  247. static void m520x_cpu_reset(void)
  248. {
  249. local_irq_disable();
  250. __raw_writeb(MCF_RCR_SWRESET, MCF_RCR);
  251. }
  252. /***************************************************************************/
  253. void __init config_BSP(char *commandp, int size)
  254. {
  255. mach_reset = m520x_cpu_reset;
  256. m520x_uarts_init();
  257. m520x_fec_init();
  258. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  259. m520x_qspi_init();
  260. #endif
  261. }
  262. /***************************************************************************/
  263. static int __init init_BSP(void)
  264. {
  265. platform_add_devices(m520x_devices, ARRAY_SIZE(m520x_devices));
  266. return 0;
  267. }
  268. arch_initcall(init_BSP);
  269. /***************************************************************************/