config.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/527x/config.c
  4. *
  5. * Sub-architcture dependent initialization code for the Freescale
  6. * 5270/5271 CPUs.
  7. *
  8. * Copyright (C) 1999-2004, Greg Ungerer (gerg@snapgear.com)
  9. * Copyright (C) 2001-2004, 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 m527x_qspi_resources[] = {
  26. {
  27. .start = MCFQSPI_BASE,
  28. .end = MCFQSPI_BASE + MCFQSPI_SIZE - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. {
  32. .start = MCF_IRQ_QSPI,
  33. .end = MCF_IRQ_QSPI,
  34. .flags = IORESOURCE_IRQ,
  35. },
  36. };
  37. static int m527x_cs_setup(struct mcfqspi_cs_control *cs_control)
  38. {
  39. int status;
  40. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  41. if (status) {
  42. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  43. goto fail0;
  44. }
  45. status = gpio_direction_output(MCFQSPI_CS0, 1);
  46. if (status) {
  47. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  48. goto fail1;
  49. }
  50. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  51. if (status) {
  52. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  53. goto fail1;
  54. }
  55. status = gpio_direction_output(MCFQSPI_CS1, 1);
  56. if (status) {
  57. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  58. goto fail2;
  59. }
  60. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  61. if (status) {
  62. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  63. goto fail2;
  64. }
  65. status = gpio_direction_output(MCFQSPI_CS2, 1);
  66. if (status) {
  67. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  68. goto fail3;
  69. }
  70. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  71. if (status) {
  72. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  73. goto fail3;
  74. }
  75. status = gpio_direction_output(MCFQSPI_CS3, 1);
  76. if (status) {
  77. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  78. goto fail4;
  79. }
  80. return 0;
  81. fail4:
  82. gpio_free(MCFQSPI_CS3);
  83. fail3:
  84. gpio_free(MCFQSPI_CS2);
  85. fail2:
  86. gpio_free(MCFQSPI_CS1);
  87. fail1:
  88. gpio_free(MCFQSPI_CS0);
  89. fail0:
  90. return status;
  91. }
  92. static void m527x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  93. {
  94. gpio_free(MCFQSPI_CS3);
  95. gpio_free(MCFQSPI_CS2);
  96. gpio_free(MCFQSPI_CS1);
  97. gpio_free(MCFQSPI_CS0);
  98. }
  99. static void m527x_cs_select(struct mcfqspi_cs_control *cs_control,
  100. u8 chip_select, bool cs_high)
  101. {
  102. switch (chip_select) {
  103. case 0:
  104. gpio_set_value(MCFQSPI_CS0, cs_high);
  105. break;
  106. case 1:
  107. gpio_set_value(MCFQSPI_CS1, cs_high);
  108. break;
  109. case 2:
  110. gpio_set_value(MCFQSPI_CS2, cs_high);
  111. break;
  112. case 3:
  113. gpio_set_value(MCFQSPI_CS3, cs_high);
  114. break;
  115. }
  116. }
  117. static void m527x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  118. u8 chip_select, bool cs_high)
  119. {
  120. switch (chip_select) {
  121. case 0:
  122. gpio_set_value(MCFQSPI_CS0, !cs_high);
  123. break;
  124. case 1:
  125. gpio_set_value(MCFQSPI_CS1, !cs_high);
  126. break;
  127. case 2:
  128. gpio_set_value(MCFQSPI_CS2, !cs_high);
  129. break;
  130. case 3:
  131. gpio_set_value(MCFQSPI_CS3, !cs_high);
  132. break;
  133. }
  134. }
  135. static struct mcfqspi_cs_control m527x_cs_control = {
  136. .setup = m527x_cs_setup,
  137. .teardown = m527x_cs_teardown,
  138. .select = m527x_cs_select,
  139. .deselect = m527x_cs_deselect,
  140. };
  141. static struct mcfqspi_platform_data m527x_qspi_data = {
  142. .bus_num = 0,
  143. .num_chipselect = 4,
  144. .cs_control = &m527x_cs_control,
  145. };
  146. static struct platform_device m527x_qspi = {
  147. .name = "mcfqspi",
  148. .id = 0,
  149. .num_resources = ARRAY_SIZE(m527x_qspi_resources),
  150. .resource = m527x_qspi_resources,
  151. .dev.platform_data = &m527x_qspi_data,
  152. };
  153. static void __init m527x_qspi_init(void)
  154. {
  155. #if defined(CONFIG_M5271)
  156. u16 par;
  157. /* setup QSPS pins for QSPI with gpio CS control */
  158. writeb(0x1f, MCFGPIO_PAR_QSPI);
  159. /* and CS2 & CS3 as gpio */
  160. par = readw(MCFGPIO_PAR_TIMER);
  161. par &= 0x3f3f;
  162. writew(par, MCFGPIO_PAR_TIMER);
  163. #elif defined(CONFIG_M5275)
  164. /* setup QSPS pins for QSPI with gpio CS control */
  165. writew(0x003e, MCFGPIO_PAR_QSPI);
  166. #endif
  167. }
  168. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  169. static struct platform_device *m527x_devices[] __initdata = {
  170. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  171. &m527x_qspi,
  172. #endif
  173. };
  174. /***************************************************************************/
  175. static void __init m527x_uarts_init(void)
  176. {
  177. u16 sepmask;
  178. /*
  179. * External Pin Mask Setting & Enable External Pin for Interface
  180. */
  181. sepmask = readw(MCF_IPSBAR + MCF_GPIO_PAR_UART);
  182. sepmask |= UART0_ENABLE_MASK | UART1_ENABLE_MASK | UART2_ENABLE_MASK;
  183. writew(sepmask, MCF_IPSBAR + MCF_GPIO_PAR_UART);
  184. }
  185. /***************************************************************************/
  186. static void __init m527x_fec_init(void)
  187. {
  188. u16 par;
  189. u8 v;
  190. /* Set multi-function pins to ethernet mode for fec0 */
  191. #if defined(CONFIG_M5271)
  192. v = readb(MCF_IPSBAR + 0x100047);
  193. writeb(v | 0xf0, MCF_IPSBAR + 0x100047);
  194. #else
  195. par = readw(MCF_IPSBAR + 0x100082);
  196. writew(par | 0xf00, MCF_IPSBAR + 0x100082);
  197. v = readb(MCF_IPSBAR + 0x100078);
  198. writeb(v | 0xc0, MCF_IPSBAR + 0x100078);
  199. #endif
  200. #ifdef CONFIG_FEC2
  201. /* Set multi-function pins to ethernet mode for fec1 */
  202. par = readw(MCF_IPSBAR + 0x100082);
  203. writew(par | 0xa0, MCF_IPSBAR + 0x100082);
  204. v = readb(MCF_IPSBAR + 0x100079);
  205. writeb(v | 0xc0, MCF_IPSBAR + 0x100079);
  206. #endif
  207. }
  208. /***************************************************************************/
  209. static void m527x_cpu_reset(void)
  210. {
  211. local_irq_disable();
  212. __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR);
  213. }
  214. /***************************************************************************/
  215. void __init config_BSP(char *commandp, int size)
  216. {
  217. mach_reset = m527x_cpu_reset;
  218. mach_sched_init = hw_timer_init;
  219. m527x_uarts_init();
  220. m527x_fec_init();
  221. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  222. m527x_qspi_init();
  223. #endif
  224. }
  225. /***************************************************************************/
  226. static int __init init_BSP(void)
  227. {
  228. platform_add_devices(m527x_devices, ARRAY_SIZE(m527x_devices));
  229. return 0;
  230. }
  231. arch_initcall(init_BSP);
  232. /***************************************************************************/