cpu_init.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. *
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
  7. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <asm/immap.h>
  30. #include <asm/processor.h>
  31. #include <asm/rtc.h>
  32. #include <asm/io.h>
  33. #include <linux/compiler.h>
  34. #if defined(CONFIG_CMD_NET)
  35. #include <config.h>
  36. #include <net.h>
  37. #include <asm/fec.h>
  38. #endif
  39. void init_fbcs(void)
  40. {
  41. fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
  42. #if !defined(CONFIG_SERIAL_BOOT)
  43. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
  44. out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
  45. out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
  46. out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
  47. #endif
  48. #endif
  49. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
  50. /* Latch chipselect */
  51. out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
  52. out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
  53. out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
  54. #endif
  55. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
  56. out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
  57. out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
  58. out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
  59. #endif
  60. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
  61. out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
  62. out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
  63. out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
  64. #endif
  65. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
  66. out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
  67. out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
  68. out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
  69. #endif
  70. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
  71. out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
  72. out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
  73. out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
  74. #endif
  75. }
  76. /*
  77. * Breath some life into the CPU...
  78. *
  79. * Set up the memory map,
  80. * initialize a bunch of registers,
  81. * initialize the UPM's
  82. */
  83. void cpu_init_f(void)
  84. {
  85. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  86. #ifdef CONFIG_MCF5441x
  87. scm_t *scm = (scm_t *) MMAP_SCM;
  88. pm_t *pm = (pm_t *) MMAP_PM;
  89. /* Disable Switch */
  90. *(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0;
  91. /* Disable core watchdog */
  92. out_be16(&scm->cwcr, 0);
  93. out_8(&gpio->par_fbctl,
  94. GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE |
  95. GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW |
  96. GPIO_PAR_FBCTL_TA_TA);
  97. out_8(&gpio->par_be,
  98. GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
  99. GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
  100. /* eDMA */
  101. out_8(&pm->pmcr0, 17);
  102. /* INTR0 - INTR2 */
  103. out_8(&pm->pmcr0, 18);
  104. out_8(&pm->pmcr0, 19);
  105. out_8(&pm->pmcr0, 20);
  106. /* I2C */
  107. out_8(&pm->pmcr0, 22);
  108. out_8(&pm->pmcr1, 4);
  109. out_8(&pm->pmcr1, 7);
  110. /* DTMR0 - DTMR3*/
  111. out_8(&pm->pmcr0, 28);
  112. out_8(&pm->pmcr0, 29);
  113. out_8(&pm->pmcr0, 30);
  114. out_8(&pm->pmcr0, 31);
  115. /* PIT0 - PIT3 */
  116. out_8(&pm->pmcr0, 32);
  117. out_8(&pm->pmcr0, 33);
  118. out_8(&pm->pmcr0, 34);
  119. out_8(&pm->pmcr0, 35);
  120. /* Edge Port */
  121. out_8(&pm->pmcr0, 36);
  122. out_8(&pm->pmcr0, 37);
  123. /* USB OTG */
  124. out_8(&pm->pmcr0, 44);
  125. /* USB Host */
  126. out_8(&pm->pmcr0, 45);
  127. /* ESDHC */
  128. out_8(&pm->pmcr0, 51);
  129. /* ENET0 - ENET1 */
  130. out_8(&pm->pmcr0, 53);
  131. out_8(&pm->pmcr0, 54);
  132. /* NAND */
  133. out_8(&pm->pmcr0, 63);
  134. #ifdef CONFIG_SYS_I2C_0
  135. out_8(&gpio->par_cani2c, 0xF0);
  136. /* I2C0 pull up */
  137. out_be16(&gpio->pcr_b, 0x003C);
  138. /* I2C0 max speed */
  139. out_8(&gpio->srcr_cani2c, 0x03);
  140. #endif
  141. #ifdef CONFIG_SYS_I2C_2
  142. /* I2C2 */
  143. out_8(&gpio->par_ssi0h, 0xA0);
  144. /* I2C2, UART7 */
  145. out_8(&gpio->par_ssi0h, 0xA8);
  146. /* UART7 */
  147. out_8(&gpio->par_ssi0l, 0x2);
  148. /* UART8, UART9 */
  149. out_8(&gpio->par_cani2c, 0xAA);
  150. /* UART4, UART0 */
  151. out_8(&gpio->par_uart0, 0xAF);
  152. /* UART5, UART1 */
  153. out_8(&gpio->par_uart1, 0xAF);
  154. /* UART6, UART2 */
  155. out_8(&gpio->par_uart2, 0xAF);
  156. /* I2C2 pull up */
  157. out_be16(&gpio->pcr_h, 0xF000);
  158. #endif
  159. #ifdef CONFIG_SYS_I2C_5
  160. /* I2C5 */
  161. out_8(&gpio->par_uart1, 0x0A);
  162. /* I2C5 pull up */
  163. out_be16(&gpio->pcr_e, 0x0003);
  164. out_be16(&gpio->pcr_f, 0xC000);
  165. #endif
  166. /* Lowest slew rate for UART0,1,2 */
  167. out_8(&gpio->srcr_uart, 0x00);
  168. #endif /* CONFIG_MCF5441x */
  169. #ifdef CONFIG_MCF5445x
  170. scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  171. out_be32(&scm1->mpr, 0x77777777);
  172. out_be32(&scm1->pacra, 0);
  173. out_be32(&scm1->pacrb, 0);
  174. out_be32(&scm1->pacrc, 0);
  175. out_be32(&scm1->pacrd, 0);
  176. out_be32(&scm1->pacre, 0);
  177. out_be32(&scm1->pacrf, 0);
  178. out_be32(&scm1->pacrg, 0);
  179. /* FlexBus */
  180. out_8(&gpio->par_be,
  181. GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
  182. GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
  183. out_8(&gpio->par_fbctl,
  184. GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
  185. GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
  186. #ifdef CONFIG_FSL_I2C
  187. out_be16(&gpio->par_feci2c,
  188. GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
  189. #endif
  190. #endif /* CONFIG_MCF5445x */
  191. /* FlexBus Chipselect */
  192. init_fbcs();
  193. /*
  194. * now the flash base address is no longer at 0 (Newer ColdFire family
  195. * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
  196. * also move to the new location.
  197. */
  198. if (CONFIG_SYS_CS0_BASE != 0)
  199. setvbr(CONFIG_SYS_CS0_BASE);
  200. icache_enable();
  201. }
  202. /*
  203. * initialize higher level parts of CPU like timers
  204. */
  205. int cpu_init_r(void)
  206. {
  207. #ifdef CONFIG_MCFRTC
  208. rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
  209. rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
  210. out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
  211. out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
  212. #endif
  213. return (0);
  214. }
  215. void uart_port_conf(int port)
  216. {
  217. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  218. #ifdef CONFIG_MCF5441x
  219. pm_t *pm = (pm_t *) MMAP_PM;
  220. #endif
  221. /* Setup Ports: */
  222. switch (port) {
  223. #ifdef CONFIG_MCF5441x
  224. case 0:
  225. /* UART0 */
  226. out_8(&pm->pmcr0, 24);
  227. clrbits_8(&gpio->par_uart0,
  228. ~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
  229. setbits_8(&gpio->par_uart0,
  230. GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
  231. break;
  232. case 1:
  233. /* UART1 */
  234. out_8(&pm->pmcr0, 25);
  235. clrbits_8(&gpio->par_uart1,
  236. ~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
  237. setbits_8(&gpio->par_uart1,
  238. GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
  239. break;
  240. case 2:
  241. /* UART2 */
  242. out_8(&pm->pmcr0, 26);
  243. clrbits_8(&gpio->par_uart2,
  244. ~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
  245. setbits_8(&gpio->par_uart2,
  246. GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
  247. break;
  248. case 3:
  249. /* UART3 */
  250. out_8(&pm->pmcr0, 27);
  251. clrbits_8(&gpio->par_dspi0,
  252. ~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
  253. setbits_8(&gpio->par_dspi0,
  254. GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
  255. break;
  256. case 4:
  257. /* UART4 */
  258. out_8(&pm->pmcr1, 24);
  259. clrbits_8(&gpio->par_uart0,
  260. ~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
  261. setbits_8(&gpio->par_uart0,
  262. GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
  263. break;
  264. case 5:
  265. /* UART5 */
  266. out_8(&pm->pmcr1, 25);
  267. clrbits_8(&gpio->par_uart1,
  268. ~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
  269. setbits_8(&gpio->par_uart1,
  270. GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
  271. break;
  272. case 6:
  273. /* UART6 */
  274. out_8(&pm->pmcr1, 26);
  275. clrbits_8(&gpio->par_uart2,
  276. ~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
  277. setbits_8(&gpio->par_uart2,
  278. GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
  279. break;
  280. case 7:
  281. /* UART7 */
  282. out_8(&pm->pmcr1, 27);
  283. clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
  284. clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
  285. setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
  286. setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
  287. break;
  288. case 8:
  289. /* UART8 */
  290. out_8(&pm->pmcr0, 28);
  291. clrbits_8(&gpio->par_cani2c,
  292. ~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
  293. setbits_8(&gpio->par_cani2c,
  294. GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
  295. break;
  296. case 9:
  297. /* UART9 */
  298. out_8(&pm->pmcr1, 29);
  299. clrbits_8(&gpio->par_cani2c,
  300. ~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
  301. setbits_8(&gpio->par_cani2c,
  302. GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
  303. break;
  304. #endif
  305. #ifdef CONFIG_MCF5445x
  306. case 0:
  307. clrbits_8(&gpio->par_uart,
  308. GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
  309. setbits_8(&gpio->par_uart,
  310. GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
  311. break;
  312. case 1:
  313. #ifdef CONFIG_SYS_UART1_PRI_GPIO
  314. clrbits_8(&gpio->par_uart,
  315. GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
  316. setbits_8(&gpio->par_uart,
  317. GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
  318. #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
  319. clrbits_be16(&gpio->par_ssi,
  320. ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
  321. setbits_be16(&gpio->par_ssi,
  322. GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
  323. #endif
  324. break;
  325. case 2:
  326. #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
  327. clrbits_8(&gpio->par_timer,
  328. ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
  329. setbits_8(&gpio->par_timer,
  330. GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
  331. #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
  332. clrbits_8(&gpio->par_timer,
  333. ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
  334. setbits_8(&gpio->par_timer,
  335. GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
  336. #endif
  337. break;
  338. #endif /* CONFIG_MCF5445x */
  339. }
  340. }
  341. #if defined(CONFIG_CMD_NET)
  342. int fecpin_setclear(struct eth_device *dev, int setclear)
  343. {
  344. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  345. struct fec_info_s *info = (struct fec_info_s *)dev->priv;
  346. #ifdef CONFIG_MCF5445x
  347. if (setclear) {
  348. #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
  349. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  350. setbits_be16(&gpio->par_feci2c,
  351. GPIO_PAR_FECI2C_MDC0_MDC0 |
  352. GPIO_PAR_FECI2C_MDIO0_MDIO0);
  353. else
  354. setbits_be16(&gpio->par_feci2c,
  355. GPIO_PAR_FECI2C_MDC1_MDC1 |
  356. GPIO_PAR_FECI2C_MDIO1_MDIO1);
  357. #else
  358. setbits_be16(&gpio->par_feci2c,
  359. GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  360. #endif
  361. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  362. setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
  363. else
  364. setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
  365. } else {
  366. clrbits_be16(&gpio->par_feci2c,
  367. GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  368. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  369. #ifdef CONFIG_SYS_FEC_FULL_MII
  370. setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
  371. #else
  372. clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
  373. #endif
  374. } else {
  375. #ifdef CONFIG_SYS_FEC_FULL_MII
  376. setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
  377. #else
  378. clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
  379. #endif
  380. }
  381. }
  382. #endif /* CONFIG_MCF5445x */
  383. #ifdef CONFIG_MCF5441x
  384. if (setclear) {
  385. out_8(&gpio->par_fec, 0x03);
  386. out_8(&gpio->srcr_fec, 0x0F);
  387. clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
  388. GPIO_PAR_SIMP0H_DAT_GPIO);
  389. clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
  390. GPIO_PDDR_G4_OUTPUT);
  391. clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
  392. } else
  393. clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
  394. #endif
  395. return 0;
  396. }
  397. #endif
  398. #ifdef CONFIG_CF_DSPI
  399. void cfspi_port_conf(void)
  400. {
  401. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  402. #ifdef CONFIG_MCF5445x
  403. out_8(&gpio->par_dspi,
  404. GPIO_PAR_DSPI_SIN_SIN |
  405. GPIO_PAR_DSPI_SOUT_SOUT |
  406. GPIO_PAR_DSPI_SCK_SCK);
  407. #endif
  408. #ifdef CONFIG_MCF5441x
  409. pm_t *pm = (pm_t *) MMAP_PM;
  410. out_8(&gpio->par_dspi0,
  411. GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
  412. GPIO_PAR_DSPI0_SCK_DSPI0SCK);
  413. out_8(&gpio->srcr_dspiow, 3);
  414. /* DSPI0 */
  415. out_8(&pm->pmcr0, 23);
  416. #endif
  417. }
  418. int cfspi_claim_bus(uint bus, uint cs)
  419. {
  420. dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  421. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  422. if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
  423. return -1;
  424. /* Clear FIFO and resume transfer */
  425. clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  426. #ifdef CONFIG_MCF5445x
  427. switch (cs) {
  428. case 0:
  429. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
  430. setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
  431. break;
  432. case 1:
  433. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
  434. setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
  435. break;
  436. case 2:
  437. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
  438. setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
  439. break;
  440. case 3:
  441. clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
  442. setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
  443. break;
  444. case 5:
  445. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
  446. setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
  447. break;
  448. }
  449. #endif
  450. #ifdef CONFIG_MCF5441x
  451. switch (cs) {
  452. case 0:
  453. clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK);
  454. setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0);
  455. break;
  456. case 1:
  457. clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
  458. setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
  459. break;
  460. }
  461. #endif
  462. return 0;
  463. }
  464. void cfspi_release_bus(uint bus, uint cs)
  465. {
  466. dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  467. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  468. /* Clear FIFO */
  469. clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  470. #ifdef CONFIG_MCF5445x
  471. switch (cs) {
  472. case 0:
  473. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
  474. break;
  475. case 1:
  476. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
  477. break;
  478. case 2:
  479. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
  480. break;
  481. case 3:
  482. clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
  483. break;
  484. case 5:
  485. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
  486. break;
  487. }
  488. #endif
  489. #ifdef CONFIG_MCF5441x
  490. if (cs == 1)
  491. clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
  492. #endif
  493. }
  494. #endif