config.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. static struct resource m527x_fec0_resources[] = {
  25. {
  26. .start = MCFFEC_BASE0,
  27. .end = MCFFEC_BASE0 + MCFFEC_SIZE0 - 1,
  28. .flags = IORESOURCE_MEM,
  29. },
  30. {
  31. .start = MCF_IRQ_FECRX0,
  32. .end = MCF_IRQ_FECRX0,
  33. .flags = IORESOURCE_IRQ,
  34. },
  35. {
  36. .start = MCF_IRQ_FECTX0,
  37. .end = MCF_IRQ_FECTX0,
  38. .flags = IORESOURCE_IRQ,
  39. },
  40. {
  41. .start = MCF_IRQ_FECENTC0,
  42. .end = MCF_IRQ_FECENTC0,
  43. .flags = IORESOURCE_IRQ,
  44. },
  45. };
  46. static struct resource m527x_fec1_resources[] = {
  47. {
  48. .start = MCFFEC_BASE1,
  49. .end = MCFFEC_BASE1 + MCFFEC_SIZE1 - 1,
  50. .flags = IORESOURCE_MEM,
  51. },
  52. {
  53. .start = MCF_IRQ_FECRX1,
  54. .end = MCF_IRQ_FECRX1,
  55. .flags = IORESOURCE_IRQ,
  56. },
  57. {
  58. .start = MCF_IRQ_FECTX1,
  59. .end = MCF_IRQ_FECTX1,
  60. .flags = IORESOURCE_IRQ,
  61. },
  62. {
  63. .start = MCF_IRQ_FECENTC1,
  64. .end = MCF_IRQ_FECENTC1,
  65. .flags = IORESOURCE_IRQ,
  66. },
  67. };
  68. static struct platform_device m527x_fec[] = {
  69. {
  70. .name = "fec",
  71. .id = 0,
  72. .num_resources = ARRAY_SIZE(m527x_fec0_resources),
  73. .resource = m527x_fec0_resources,
  74. },
  75. {
  76. .name = "fec",
  77. .id = 1,
  78. .num_resources = ARRAY_SIZE(m527x_fec1_resources),
  79. .resource = m527x_fec1_resources,
  80. },
  81. };
  82. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  83. static struct resource m527x_qspi_resources[] = {
  84. {
  85. .start = MCFQSPI_IOBASE,
  86. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  87. .flags = IORESOURCE_MEM,
  88. },
  89. {
  90. .start = MCFINT_VECBASE + MCFINT_QSPI,
  91. .end = MCFINT_VECBASE + MCFINT_QSPI,
  92. .flags = IORESOURCE_IRQ,
  93. },
  94. };
  95. #if defined(CONFIG_M5271)
  96. #define MCFQSPI_CS0 91
  97. #define MCFQSPI_CS1 92
  98. #define MCFQSPI_CS2 99
  99. #define MCFQSPI_CS3 103
  100. #elif defined(CONFIG_M5275)
  101. #define MCFQSPI_CS0 59
  102. #define MCFQSPI_CS1 60
  103. #define MCFQSPI_CS2 61
  104. #define MCFQSPI_CS3 62
  105. #endif
  106. static int m527x_cs_setup(struct mcfqspi_cs_control *cs_control)
  107. {
  108. int status;
  109. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  110. if (status) {
  111. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  112. goto fail0;
  113. }
  114. status = gpio_direction_output(MCFQSPI_CS0, 1);
  115. if (status) {
  116. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  117. goto fail1;
  118. }
  119. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  120. if (status) {
  121. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  122. goto fail1;
  123. }
  124. status = gpio_direction_output(MCFQSPI_CS1, 1);
  125. if (status) {
  126. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  127. goto fail2;
  128. }
  129. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  130. if (status) {
  131. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  132. goto fail2;
  133. }
  134. status = gpio_direction_output(MCFQSPI_CS2, 1);
  135. if (status) {
  136. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  137. goto fail3;
  138. }
  139. status = gpio_request(MCFQSPI_CS3, "MCFQSPI_CS3");
  140. if (status) {
  141. pr_debug("gpio_request for MCFQSPI_CS3 failed\n");
  142. goto fail3;
  143. }
  144. status = gpio_direction_output(MCFQSPI_CS3, 1);
  145. if (status) {
  146. pr_debug("gpio_direction_output for MCFQSPI_CS3 failed\n");
  147. goto fail4;
  148. }
  149. return 0;
  150. fail4:
  151. gpio_free(MCFQSPI_CS3);
  152. fail3:
  153. gpio_free(MCFQSPI_CS2);
  154. fail2:
  155. gpio_free(MCFQSPI_CS1);
  156. fail1:
  157. gpio_free(MCFQSPI_CS0);
  158. fail0:
  159. return status;
  160. }
  161. static void m527x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  162. {
  163. gpio_free(MCFQSPI_CS3);
  164. gpio_free(MCFQSPI_CS2);
  165. gpio_free(MCFQSPI_CS1);
  166. gpio_free(MCFQSPI_CS0);
  167. }
  168. static void m527x_cs_select(struct mcfqspi_cs_control *cs_control,
  169. u8 chip_select, bool cs_high)
  170. {
  171. switch (chip_select) {
  172. case 0:
  173. gpio_set_value(MCFQSPI_CS0, cs_high);
  174. break;
  175. case 1:
  176. gpio_set_value(MCFQSPI_CS1, cs_high);
  177. break;
  178. case 2:
  179. gpio_set_value(MCFQSPI_CS2, cs_high);
  180. break;
  181. case 3:
  182. gpio_set_value(MCFQSPI_CS3, cs_high);
  183. break;
  184. }
  185. }
  186. static void m527x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  187. u8 chip_select, bool cs_high)
  188. {
  189. switch (chip_select) {
  190. case 0:
  191. gpio_set_value(MCFQSPI_CS0, !cs_high);
  192. break;
  193. case 1:
  194. gpio_set_value(MCFQSPI_CS1, !cs_high);
  195. break;
  196. case 2:
  197. gpio_set_value(MCFQSPI_CS2, !cs_high);
  198. break;
  199. case 3:
  200. gpio_set_value(MCFQSPI_CS3, !cs_high);
  201. break;
  202. }
  203. }
  204. static struct mcfqspi_cs_control m527x_cs_control = {
  205. .setup = m527x_cs_setup,
  206. .teardown = m527x_cs_teardown,
  207. .select = m527x_cs_select,
  208. .deselect = m527x_cs_deselect,
  209. };
  210. static struct mcfqspi_platform_data m527x_qspi_data = {
  211. .bus_num = 0,
  212. .num_chipselect = 4,
  213. .cs_control = &m527x_cs_control,
  214. };
  215. static struct platform_device m527x_qspi = {
  216. .name = "mcfqspi",
  217. .id = 0,
  218. .num_resources = ARRAY_SIZE(m527x_qspi_resources),
  219. .resource = m527x_qspi_resources,
  220. .dev.platform_data = &m527x_qspi_data,
  221. };
  222. static void __init m527x_qspi_init(void)
  223. {
  224. #if defined(CONFIG_M5271)
  225. u16 par;
  226. /* setup QSPS pins for QSPI with gpio CS control */
  227. writeb(0x1f, MCFGPIO_PAR_QSPI);
  228. /* and CS2 & CS3 as gpio */
  229. par = readw(MCFGPIO_PAR_TIMER);
  230. par &= 0x3f3f;
  231. writew(par, MCFGPIO_PAR_TIMER);
  232. #elif defined(CONFIG_M5275)
  233. /* setup QSPS pins for QSPI with gpio CS control */
  234. writew(0x003e, MCFGPIO_PAR_QSPI);
  235. #endif
  236. }
  237. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  238. static struct platform_device *m527x_devices[] __initdata = {
  239. &m527x_fec[0],
  240. #ifdef CONFIG_FEC2
  241. &m527x_fec[1],
  242. #endif
  243. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  244. &m527x_qspi,
  245. #endif
  246. };
  247. /***************************************************************************/
  248. static void __init m527x_uarts_init(void)
  249. {
  250. u16 sepmask;
  251. /*
  252. * External Pin Mask Setting & Enable External Pin for Interface
  253. */
  254. sepmask = readw(MCF_IPSBAR + MCF_GPIO_PAR_UART);
  255. sepmask |= UART0_ENABLE_MASK | UART1_ENABLE_MASK | UART2_ENABLE_MASK;
  256. writew(sepmask, MCF_IPSBAR + MCF_GPIO_PAR_UART);
  257. }
  258. /***************************************************************************/
  259. static void __init m527x_fec_init(void)
  260. {
  261. u16 par;
  262. u8 v;
  263. /* Set multi-function pins to ethernet mode for fec0 */
  264. #if defined(CONFIG_M5271)
  265. v = readb(MCF_IPSBAR + 0x100047);
  266. writeb(v | 0xf0, MCF_IPSBAR + 0x100047);
  267. #else
  268. par = readw(MCF_IPSBAR + 0x100082);
  269. writew(par | 0xf00, MCF_IPSBAR + 0x100082);
  270. v = readb(MCF_IPSBAR + 0x100078);
  271. writeb(v | 0xc0, MCF_IPSBAR + 0x100078);
  272. #endif
  273. #ifdef CONFIG_FEC2
  274. /* Set multi-function pins to ethernet mode for fec1 */
  275. par = readw(MCF_IPSBAR + 0x100082);
  276. writew(par | 0xa0, MCF_IPSBAR + 0x100082);
  277. v = readb(MCF_IPSBAR + 0x100079);
  278. writeb(v | 0xc0, MCF_IPSBAR + 0x100079);
  279. #endif
  280. }
  281. /***************************************************************************/
  282. static void m527x_cpu_reset(void)
  283. {
  284. local_irq_disable();
  285. __raw_writeb(MCF_RCR_SWRESET, MCF_IPSBAR + MCF_RCR);
  286. }
  287. /***************************************************************************/
  288. void __init config_BSP(char *commandp, int size)
  289. {
  290. mach_reset = m527x_cpu_reset;
  291. mach_sched_init = hw_timer_init;
  292. m527x_uarts_init();
  293. m527x_fec_init();
  294. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  295. m527x_qspi_init();
  296. #endif
  297. }
  298. /***************************************************************************/
  299. static int __init init_BSP(void)
  300. {
  301. platform_add_devices(m527x_devices, ARRAY_SIZE(m527x_devices));
  302. return 0;
  303. }
  304. arch_initcall(init_BSP);
  305. /***************************************************************************/