config.c 8.6 KB

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