config.c 6.7 KB

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