config.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  24. static struct resource m520x_qspi_resources[] = {
  25. {
  26. .start = MCFQSPI_BASE,
  27. .end = MCFQSPI_BASE + MCFQSPI_SIZE - 1,
  28. .flags = IORESOURCE_MEM,
  29. },
  30. {
  31. .start = MCF_IRQ_QSPI,
  32. .end = MCF_IRQ_QSPI,
  33. .flags = IORESOURCE_IRQ,
  34. },
  35. };
  36. static int m520x_cs_setup(struct mcfqspi_cs_control *cs_control)
  37. {
  38. int status;
  39. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  40. if (status) {
  41. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  42. goto fail0;
  43. }
  44. status = gpio_direction_output(MCFQSPI_CS0, 1);
  45. if (status) {
  46. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  47. goto fail1;
  48. }
  49. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  50. if (status) {
  51. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  52. goto fail1;
  53. }
  54. status = gpio_direction_output(MCFQSPI_CS1, 1);
  55. if (status) {
  56. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  57. goto fail2;
  58. }
  59. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  60. if (status) {
  61. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  62. goto fail2;
  63. }
  64. status = gpio_direction_output(MCFQSPI_CS2, 1);
  65. if (status) {
  66. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  67. goto fail3;
  68. }
  69. return 0;
  70. fail3:
  71. gpio_free(MCFQSPI_CS2);
  72. fail2:
  73. gpio_free(MCFQSPI_CS1);
  74. fail1:
  75. gpio_free(MCFQSPI_CS0);
  76. fail0:
  77. return status;
  78. }
  79. static void m520x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  80. {
  81. gpio_free(MCFQSPI_CS2);
  82. gpio_free(MCFQSPI_CS1);
  83. gpio_free(MCFQSPI_CS0);
  84. }
  85. static void m520x_cs_select(struct mcfqspi_cs_control *cs_control,
  86. u8 chip_select, bool cs_high)
  87. {
  88. switch (chip_select) {
  89. case 0:
  90. gpio_set_value(MCFQSPI_CS0, cs_high);
  91. break;
  92. case 1:
  93. gpio_set_value(MCFQSPI_CS1, cs_high);
  94. break;
  95. case 2:
  96. gpio_set_value(MCFQSPI_CS2, cs_high);
  97. break;
  98. }
  99. }
  100. static void m520x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  101. u8 chip_select, bool cs_high)
  102. {
  103. switch (chip_select) {
  104. case 0:
  105. gpio_set_value(MCFQSPI_CS0, !cs_high);
  106. break;
  107. case 1:
  108. gpio_set_value(MCFQSPI_CS1, !cs_high);
  109. break;
  110. case 2:
  111. gpio_set_value(MCFQSPI_CS2, !cs_high);
  112. break;
  113. }
  114. }
  115. static struct mcfqspi_cs_control m520x_cs_control = {
  116. .setup = m520x_cs_setup,
  117. .teardown = m520x_cs_teardown,
  118. .select = m520x_cs_select,
  119. .deselect = m520x_cs_deselect,
  120. };
  121. static struct mcfqspi_platform_data m520x_qspi_data = {
  122. .bus_num = 0,
  123. .num_chipselect = 3,
  124. .cs_control = &m520x_cs_control,
  125. };
  126. static struct platform_device m520x_qspi = {
  127. .name = "mcfqspi",
  128. .id = 0,
  129. .num_resources = ARRAY_SIZE(m520x_qspi_resources),
  130. .resource = m520x_qspi_resources,
  131. .dev.platform_data = &m520x_qspi_data,
  132. };
  133. static void __init m520x_qspi_init(void)
  134. {
  135. u16 par;
  136. /* setup Port QS for QSPI with gpio CS control */
  137. writeb(0x3f, MCF_GPIO_PAR_QSPI);
  138. /* make U1CTS and U2RTS gpio for cs_control */
  139. par = readw(MCF_GPIO_PAR_UART);
  140. par &= 0x00ff;
  141. writew(par, MCF_GPIO_PAR_UART);
  142. }
  143. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  144. static struct platform_device *m520x_devices[] __initdata = {
  145. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  146. &m520x_qspi,
  147. #endif
  148. };
  149. /***************************************************************************/
  150. static void __init m520x_uarts_init(void)
  151. {
  152. u16 par;
  153. u8 par2;
  154. /* UART0 and UART1 GPIO pin setup */
  155. par = readw(MCF_GPIO_PAR_UART);
  156. par |= MCF_GPIO_PAR_UART_PAR_UTXD0 | MCF_GPIO_PAR_UART_PAR_URXD0;
  157. par |= MCF_GPIO_PAR_UART_PAR_UTXD1 | MCF_GPIO_PAR_UART_PAR_URXD1;
  158. writew(par, MCF_GPIO_PAR_UART);
  159. /* UART1 GPIO pin setup */
  160. par2 = readb(MCF_GPIO_PAR_FECI2C);
  161. par2 &= ~0x0F;
  162. par2 |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2 |
  163. MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2;
  164. writeb(par2, MCF_GPIO_PAR_FECI2C);
  165. }
  166. /***************************************************************************/
  167. static void __init m520x_fec_init(void)
  168. {
  169. u8 v;
  170. /* Set multi-function pins to ethernet mode */
  171. v = readb(MCF_GPIO_PAR_FEC);
  172. writeb(v | 0xf0, MCF_GPIO_PAR_FEC);
  173. v = readb(MCF_GPIO_PAR_FECI2C);
  174. writeb(v | 0x0f, MCF_GPIO_PAR_FECI2C);
  175. }
  176. /***************************************************************************/
  177. static void m520x_cpu_reset(void)
  178. {
  179. local_irq_disable();
  180. __raw_writeb(MCF_RCR_SWRESET, MCF_RCR);
  181. }
  182. /***************************************************************************/
  183. void __init config_BSP(char *commandp, int size)
  184. {
  185. mach_reset = m520x_cpu_reset;
  186. mach_sched_init = hw_timer_init;
  187. m520x_uarts_init();
  188. m520x_fec_init();
  189. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  190. m520x_qspi_init();
  191. #endif
  192. }
  193. /***************************************************************************/
  194. static int __init init_BSP(void)
  195. {
  196. platform_add_devices(m520x_devices, ARRAY_SIZE(m520x_devices));
  197. return 0;
  198. }
  199. arch_initcall(init_BSP);
  200. /***************************************************************************/