config.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 resource m528x_fec_resources[] = {
  246. {
  247. .start = MCF_MBAR + 0x1000,
  248. .end = MCF_MBAR + 0x1000 + 0x7ff,
  249. .flags = IORESOURCE_MEM,
  250. },
  251. {
  252. .start = 64 + 23,
  253. .end = 64 + 23,
  254. .flags = IORESOURCE_IRQ,
  255. },
  256. {
  257. .start = 64 + 27,
  258. .end = 64 + 27,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. {
  262. .start = 64 + 29,
  263. .end = 64 + 29,
  264. .flags = IORESOURCE_IRQ,
  265. },
  266. };
  267. static struct platform_device m528x_fec = {
  268. .name = "fec",
  269. .id = 0,
  270. .num_resources = ARRAY_SIZE(m528x_fec_resources),
  271. .resource = m528x_fec_resources,
  272. };
  273. static struct platform_device *m528x_devices[] __initdata = {
  274. &m528x_uart,
  275. &m528x_fec,
  276. };
  277. /***************************************************************************/
  278. #define INTC0 (MCF_MBAR + MCFICM_INTC0)
  279. static void __init m528x_uart_init_line(int line, int irq)
  280. {
  281. u8 port;
  282. u32 imr;
  283. if ((line < 0) || (line > 2))
  284. return;
  285. /* level 6, line based priority */
  286. writeb(0x30+line, INTC0 + MCFINTC_ICR0 + MCFINT_UART0 + line);
  287. imr = readl(INTC0 + MCFINTC_IMRL);
  288. imr &= ~((1 << (irq - MCFINT_VECBASE)) | 1);
  289. writel(imr, INTC0 + MCFINTC_IMRL);
  290. /* make sure PUAPAR is set for UART0 and UART1 */
  291. if (line < 2) {
  292. port = readb(MCF_MBAR + MCF5282_GPIO_PUAPAR);
  293. port |= (0x03 << (line * 2));
  294. writeb(port, MCF_MBAR + MCF5282_GPIO_PUAPAR);
  295. }
  296. }
  297. static void __init m528x_uarts_init(void)
  298. {
  299. const int nrlines = ARRAY_SIZE(m528x_uart_platform);
  300. int line;
  301. for (line = 0; (line < nrlines); line++)
  302. m528x_uart_init_line(line, m528x_uart_platform[line].irq);
  303. }
  304. /***************************************************************************/
  305. static void __init m528x_fec_init(void)
  306. {
  307. u32 imr;
  308. u16 v16;
  309. /* Unmask FEC interrupts at ColdFire interrupt controller */
  310. writeb(0x28, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 23);
  311. writeb(0x27, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 27);
  312. writeb(0x26, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_ICR0 + 29);
  313. imr = readl(MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH);
  314. imr &= ~0xf;
  315. writel(imr, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH);
  316. imr = readl(MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL);
  317. imr &= ~0xff800001;
  318. writel(imr, MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL);
  319. /* Set multi-function pins to ethernet mode for fec0 */
  320. v16 = readw(MCF_IPSBAR + 0x100056);
  321. writew(v16 | 0xf00, MCF_IPSBAR + 0x100056);
  322. writeb(0xc0, MCF_IPSBAR + 0x100058);
  323. }
  324. /***************************************************************************/
  325. void mcf_disableall(void)
  326. {
  327. *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRH)) = 0xffffffff;
  328. *((volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 + MCFINTC_IMRL)) = 0xffffffff;
  329. }
  330. /***************************************************************************/
  331. void mcf_autovector(unsigned int vec)
  332. {
  333. /* Everything is auto-vectored on the 5272 */
  334. }
  335. /***************************************************************************/
  336. #ifdef CONFIG_WILDFIRE
  337. void wildfire_halt(void)
  338. {
  339. writeb(0, 0x30000007);
  340. writeb(0x2, 0x30000007);
  341. }
  342. #endif
  343. #ifdef CONFIG_WILDFIREMOD
  344. void wildfiremod_halt(void)
  345. {
  346. printk(KERN_INFO "WildFireMod hibernating...\n");
  347. /* Set portE.5 to Digital IO */
  348. MCF5282_GPIO_PEPAR &= ~(1 << (5 * 2));
  349. /* Make portE.5 an output */
  350. MCF5282_GPIO_DDRE |= (1 << 5);
  351. /* Now toggle portE.5 from low to high */
  352. MCF5282_GPIO_PORTE &= ~(1 << 5);
  353. MCF5282_GPIO_PORTE |= (1 << 5);
  354. printk(KERN_EMERG "Failed to hibernate. Halting!\n");
  355. }
  356. #endif
  357. void __init config_BSP(char *commandp, int size)
  358. {
  359. mcf_disableall();
  360. #ifdef CONFIG_WILDFIRE
  361. mach_halt = wildfire_halt;
  362. #endif
  363. #ifdef CONFIG_WILDFIREMOD
  364. mach_halt = wildfiremod_halt;
  365. #endif
  366. }
  367. /***************************************************************************/
  368. static int __init init_BSP(void)
  369. {
  370. m528x_uarts_init();
  371. m528x_fec_init();
  372. platform_add_devices(m528x_devices, ARRAY_SIZE(m528x_devices));
  373. return 0;
  374. }
  375. arch_initcall(init_BSP);
  376. /***************************************************************************/