config.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/528x/config.c
  4. *
  5. * Sub-architcture dependant initialization code for the Motorola
  6. * 5280 and 5282 CPUs.
  7. *
  8. * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
  9. * Copyright (C) 2001-2003, 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/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/spi/flash.h>
  19. #include <linux/io.h>
  20. #include <asm/machdep.h>
  21. #include <asm/coldfire.h>
  22. #include <asm/mcfsim.h>
  23. #include <asm/mcfuart.h>
  24. #include <asm/mcfqspi.h>
  25. #ifdef CONFIG_MTD_PARTITIONS
  26. #include <linux/mtd/partitions.h>
  27. #endif
  28. /***************************************************************************/
  29. void coldfire_reset(void);
  30. static void coldfire_qspi_cs_control(u8 cs, u8 command);
  31. /***************************************************************************/
  32. #if defined(CONFIG_SPI)
  33. #if defined(CONFIG_WILDFIRE)
  34. #define SPI_NUM_CHIPSELECTS 0x02
  35. #define SPI_PAR_VAL 0x07 /* Enable DIN, DOUT, CLK */
  36. #define SPI_CS_MASK 0x18
  37. #define FLASH_BLOCKSIZE (1024*64)
  38. #define FLASH_NUMBLOCKS 16
  39. #define FLASH_TYPE "m25p80"
  40. #define M25P80_CS 0
  41. #define MMC_CS 1
  42. #ifdef CONFIG_MTD_PARTITIONS
  43. static struct mtd_partition stm25p_partitions[] = {
  44. /* sflash */
  45. [0] = {
  46. .name = "stm25p80",
  47. .offset = 0x00000000,
  48. .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS,
  49. .mask_flags = 0
  50. }
  51. };
  52. #endif
  53. #elif defined(CONFIG_WILDFIREMOD)
  54. #define SPI_NUM_CHIPSELECTS 0x08
  55. #define SPI_PAR_VAL 0x07 /* Enable DIN, DOUT, CLK */
  56. #define SPI_CS_MASK 0x78
  57. #define FLASH_BLOCKSIZE (1024*64)
  58. #define FLASH_NUMBLOCKS 64
  59. #define FLASH_TYPE "m25p32"
  60. /* Reserve 1M for the kernel parition */
  61. #define FLASH_KERNEL_SIZE (1024 * 1024)
  62. #define M25P80_CS 5
  63. #define MMC_CS 6
  64. #ifdef CONFIG_MTD_PARTITIONS
  65. static struct mtd_partition stm25p_partitions[] = {
  66. /* sflash */
  67. [0] = {
  68. .name = "kernel",
  69. .offset = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS - FLASH_KERNEL_SIZE,
  70. .size = FLASH_KERNEL_SIZE,
  71. .mask_flags = 0
  72. },
  73. [1] = {
  74. .name = "image",
  75. .offset = 0x00000000,
  76. .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS - FLASH_KERNEL_SIZE,
  77. .mask_flags = 0
  78. },
  79. [2] = {
  80. .name = "all",
  81. .offset = 0x00000000,
  82. .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS,
  83. .mask_flags = 0
  84. }
  85. };
  86. #endif
  87. #else
  88. #define SPI_NUM_CHIPSELECTS 0x04
  89. #define SPI_PAR_VAL 0x7F /* Enable DIN, DOUT, CLK, CS0 - CS4 */
  90. #endif
  91. #ifdef MMC_CS
  92. static struct coldfire_spi_chip flash_chip_info = {
  93. .mode = SPI_MODE_0,
  94. .bits_per_word = 16,
  95. .del_cs_to_clk = 17,
  96. .del_after_trans = 1,
  97. .void_write_data = 0
  98. };
  99. static struct coldfire_spi_chip mmc_chip_info = {
  100. .mode = SPI_MODE_0,
  101. .bits_per_word = 16,
  102. .del_cs_to_clk = 17,
  103. .del_after_trans = 1,
  104. .void_write_data = 0xFFFF
  105. };
  106. #endif
  107. #ifdef M25P80_CS
  108. static struct flash_platform_data stm25p80_platform_data = {
  109. .name = "ST M25P80 SPI Flash chip",
  110. #ifdef CONFIG_MTD_PARTITIONS
  111. .parts = stm25p_partitions,
  112. .nr_parts = sizeof(stm25p_partitions) / sizeof(*stm25p_partitions),
  113. #endif
  114. .type = FLASH_TYPE
  115. };
  116. #endif
  117. static struct spi_board_info spi_board_info[] __initdata = {
  118. #ifdef M25P80_CS
  119. {
  120. .modalias = "m25p80",
  121. .max_speed_hz = 16000000,
  122. .bus_num = 1,
  123. .chip_select = M25P80_CS,
  124. .platform_data = &stm25p80_platform_data,
  125. .controller_data = &flash_chip_info
  126. },
  127. #endif
  128. #ifdef MMC_CS
  129. {
  130. .modalias = "mmc_spi",
  131. .max_speed_hz = 16000000,
  132. .bus_num = 1,
  133. .chip_select = MMC_CS,
  134. .controller_data = &mmc_chip_info
  135. }
  136. #endif
  137. };
  138. static struct coldfire_spi_master coldfire_master_info = {
  139. .bus_num = 1,
  140. .num_chipselect = SPI_NUM_CHIPSELECTS,
  141. .irq_source = MCF5282_QSPI_IRQ_SOURCE,
  142. .irq_vector = MCF5282_QSPI_IRQ_VECTOR,
  143. .irq_mask = ((0x01 << MCF5282_QSPI_IRQ_SOURCE) | 0x01),
  144. .irq_lp = 0x2B, /* Level 5 and Priority 3 */
  145. .par_val = SPI_PAR_VAL,
  146. .cs_control = coldfire_qspi_cs_control,
  147. };
  148. static struct resource coldfire_spi_resources[] = {
  149. [0] = {
  150. .name = "qspi-par",
  151. .start = MCF5282_QSPI_PAR,
  152. .end = MCF5282_QSPI_PAR,
  153. .flags = IORESOURCE_MEM
  154. },
  155. [1] = {
  156. .name = "qspi-module",
  157. .start = MCF5282_QSPI_QMR,
  158. .end = MCF5282_QSPI_QMR + 0x18,
  159. .flags = IORESOURCE_MEM
  160. },
  161. [2] = {
  162. .name = "qspi-int-level",
  163. .start = MCF5282_INTC0 + MCFINTC_ICR0 + MCF5282_QSPI_IRQ_SOURCE,
  164. .end = MCF5282_INTC0 + MCFINTC_ICR0 + MCF5282_QSPI_IRQ_SOURCE,
  165. .flags = IORESOURCE_MEM
  166. },
  167. [3] = {
  168. .name = "qspi-int-mask",
  169. .start = MCF5282_INTC0 + MCFINTC_IMRL,
  170. .end = MCF5282_INTC0 + MCFINTC_IMRL,
  171. .flags = IORESOURCE_MEM
  172. }
  173. };
  174. static struct platform_device coldfire_spi = {
  175. .name = "spi_coldfire",
  176. .id = -1,
  177. .resource = coldfire_spi_resources,
  178. .num_resources = ARRAY_SIZE(coldfire_spi_resources),
  179. .dev = {
  180. .platform_data = &coldfire_master_info,
  181. }
  182. };
  183. static void coldfire_qspi_cs_control(u8 cs, u8 command)
  184. {
  185. u8 cs_bit = ((0x01 << cs) << 3) & SPI_CS_MASK;
  186. #if defined(CONFIG_WILDFIRE)
  187. u8 cs_mask = ~(((0x01 << cs) << 3) & SPI_CS_MASK);
  188. #endif
  189. #if defined(CONFIG_WILDFIREMOD)
  190. u8 cs_mask = (cs << 3) & SPI_CS_MASK;
  191. #endif
  192. /*
  193. * Don't do anything if the chip select is not
  194. * one of the port qs pins.
  195. */
  196. if (command & QSPI_CS_INIT) {
  197. #if defined(CONFIG_WILDFIRE)
  198. MCF5282_GPIO_DDRQS |= cs_bit;
  199. MCF5282_GPIO_PQSPAR &= ~cs_bit;
  200. #endif
  201. #if defined(CONFIG_WILDFIREMOD)
  202. MCF5282_GPIO_DDRQS |= SPI_CS_MASK;
  203. MCF5282_GPIO_PQSPAR &= ~SPI_CS_MASK;
  204. #endif
  205. }
  206. if (command & QSPI_CS_ASSERT) {
  207. MCF5282_GPIO_PORTQS &= ~SPI_CS_MASK;
  208. MCF5282_GPIO_PORTQS |= cs_mask;
  209. } else if (command & QSPI_CS_DROP) {
  210. MCF5282_GPIO_PORTQS |= SPI_CS_MASK;
  211. }
  212. }
  213. static int __init spi_dev_init(void)
  214. {
  215. int retval;
  216. retval = platform_device_register(&coldfire_spi);
  217. if (retval < 0)
  218. return retval;
  219. if (ARRAY_SIZE(spi_board_info))
  220. retval = spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
  221. return retval;
  222. }
  223. #endif /* CONFIG_SPI */
  224. /***************************************************************************/
  225. static struct mcf_platform_uart m528x_uart_platform[] = {
  226. {
  227. .mapbase = MCF_MBAR + MCFUART_BASE1,
  228. .irq = MCFINT_VECBASE + MCFINT_UART0,
  229. },
  230. {
  231. .mapbase = MCF_MBAR + MCFUART_BASE2,
  232. .irq = MCFINT_VECBASE + MCFINT_UART0 + 1,
  233. },
  234. {
  235. .mapbase = MCF_MBAR + MCFUART_BASE3,
  236. .irq = MCFINT_VECBASE + MCFINT_UART0 + 2,
  237. },
  238. { },
  239. };
  240. static struct platform_device m528x_uart = {
  241. .name = "mcfuart",
  242. .id = 0,
  243. .dev.platform_data = m528x_uart_platform,
  244. };
  245. static struct platform_device *m528x_devices[] __initdata = {
  246. &m528x_uart,
  247. };
  248. /***************************************************************************/
  249. #define INTC0 (MCF_MBAR + MCFICM_INTC0)
  250. static void __init m528x_uart_init_line(int line, int irq)
  251. {
  252. u8 port;
  253. u32 imr;
  254. if ((line < 0) || (line > 2))
  255. return;
  256. /* level 6, line based priority */
  257. writeb(0x30+line, INTC0 + MCFINTC_ICR0 + MCFINT_UART0 + line);
  258. imr = readl(INTC0 + MCFINTC_IMRL);
  259. imr &= ~((1 << (irq - MCFINT_VECBASE)) | 1);
  260. writel(imr, INTC0 + MCFINTC_IMRL);
  261. /* make sure PUAPAR is set for UART0 and UART1 */
  262. if (line < 2) {
  263. port = readb(MCF_MBAR + MCF5282_GPIO_PUAPAR);
  264. port |= (0x03 << (line * 2));
  265. writeb(port, MCF_MBAR + MCF5282_GPIO_PUAPAR);
  266. }
  267. }
  268. static void __init m528x_uarts_init(void)
  269. {
  270. const int nrlines = ARRAY_SIZE(m528x_uart_platform);
  271. int line;
  272. for (line = 0; (line < nrlines); line++)
  273. m528x_uart_init_line(line, m528x_uart_platform[line].irq);
  274. }
  275. /***************************************************************************/
  276. void mcf_disableall(void)
  277. {
  278. *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH)) = 0xffffffff;
  279. *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL)) = 0xffffffff;
  280. }
  281. /***************************************************************************/
  282. void mcf_autovector(unsigned int vec)
  283. {
  284. /* Everything is auto-vectored on the 5272 */
  285. }
  286. /***************************************************************************/
  287. #ifdef CONFIG_WILDFIRE
  288. void wildfire_halt(void)
  289. {
  290. writeb(0, 0x30000007);
  291. writeb(0x2, 0x30000007);
  292. }
  293. #endif
  294. #ifdef CONFIG_WILDFIREMOD
  295. void wildfiremod_halt(void)
  296. {
  297. printk(KERN_INFO "WildFireMod hibernating...\n");
  298. /* Set portE.5 to Digital IO */
  299. MCF5282_GPIO_PEPAR &= ~(1 << (5 * 2));
  300. /* Make portE.5 an output */
  301. MCF5282_GPIO_DDRE |= (1 << 5);
  302. /* Now toggle portE.5 from low to high */
  303. MCF5282_GPIO_PORTE &= ~(1 << 5);
  304. MCF5282_GPIO_PORTE |= (1 << 5);
  305. printk(KERN_EMERG "Failed to hibernate. Halting!\n");
  306. }
  307. #endif
  308. void __init config_BSP(char *commandp, int size)
  309. {
  310. mcf_disableall();
  311. #ifdef CONFIG_WILDFIRE
  312. mach_halt = wildfire_halt;
  313. #endif
  314. #ifdef CONFIG_WILDFIREMOD
  315. mach_halt = wildfiremod_halt;
  316. #endif
  317. }
  318. /***************************************************************************/
  319. static int __init init_BSP(void)
  320. {
  321. m528x_uarts_init();
  322. platform_add_devices(m528x_devices, ARRAY_SIZE(m528x_devices));
  323. return 0;
  324. }
  325. arch_initcall(init_BSP);
  326. /***************************************************************************/