TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * (C) Copyright 2000-2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 6 | * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 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 | |
| 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 30 | #include <asm/immap.h> |
TsiChung Liew | 68e4e76 | 2010-03-11 15:04:21 -0600 | [diff] [blame] | 31 | #include <asm/processor.h> |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 32 | #include <asm/rtc.h> |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 33 | #include <asm/io.h> |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 34 | |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 35 | #if defined(CONFIG_CMD_NET) |
| 36 | #include <config.h> |
| 37 | #include <net.h> |
| 38 | #include <asm/fec.h> |
| 39 | #endif |
| 40 | |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 41 | /* |
| 42 | * Breath some life into the CPU... |
| 43 | * |
| 44 | * Set up the memory map, |
| 45 | * initialize a bunch of registers, |
| 46 | * initialize the UPM's |
| 47 | */ |
| 48 | void cpu_init_f(void) |
| 49 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 50 | scm1_t *scm1 = (scm1_t *) MMAP_SCM1; |
| 51 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
| 52 | fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 53 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 54 | out_be32(&scm1->mpr, 0x77777777); |
| 55 | out_be32(&scm1->pacra, 0); |
| 56 | out_be32(&scm1->pacrb, 0); |
| 57 | out_be32(&scm1->pacrc, 0); |
| 58 | out_be32(&scm1->pacrd, 0); |
| 59 | out_be32(&scm1->pacre, 0); |
| 60 | out_be32(&scm1->pacrf, 0); |
| 61 | out_be32(&scm1->pacrg, 0); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 62 | |
| 63 | /* FlexBus */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 64 | out_8(&gpio->par_be, |
| 65 | GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 | |
| 66 | GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0); |
| 67 | out_8(&gpio->par_fbctl, |
| 68 | GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA | |
| 69 | GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 70 | |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 71 | #if !defined(CONFIG_CF_SBF) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL)) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 73 | out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE); |
| 74 | out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); |
| 75 | out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 76 | #endif |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 77 | #endif |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 78 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL)) |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 80 | /* Latch chipselect */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 81 | out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE); |
| 82 | out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); |
| 83 | out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 84 | #endif |
| 85 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL)) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 87 | out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE); |
| 88 | out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); |
| 89 | out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 90 | #endif |
| 91 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL)) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 93 | out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE); |
| 94 | out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); |
| 95 | out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 96 | #endif |
| 97 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL)) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 99 | out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE); |
| 100 | out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); |
| 101 | out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 102 | #endif |
| 103 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL)) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 105 | out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE); |
| 106 | out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); |
| 107 | out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 108 | #endif |
| 109 | |
TsiChung Liew | 68e4e76 | 2010-03-11 15:04:21 -0600 | [diff] [blame] | 110 | /* |
| 111 | * now the flash base address is no longer at 0 (Newer ColdFire family |
| 112 | * boot at address 0 instead of 0xFFnn_nnnn). The vector table must |
| 113 | * also move to the new location. |
| 114 | */ |
| 115 | if (CONFIG_SYS_CS0_BASE != 0) |
| 116 | setvbr(CONFIG_SYS_CS0_BASE); |
| 117 | |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 118 | #ifdef CONFIG_FSL_I2C |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 119 | out_be16(&gpio->par_feci2c, |
| 120 | GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 121 | #endif |
| 122 | |
| 123 | icache_enable(); |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * initialize higher level parts of CPU like timers |
| 128 | */ |
| 129 | int cpu_init_r(void) |
| 130 | { |
TsiChung Liew | bc3ccb1 | 2008-07-09 15:47:27 -0500 | [diff] [blame] | 131 | #ifdef CONFIG_MCFRTC |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 132 | rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE); |
| 133 | rtcex_t *rtcex = (rtcex_t *)&rtc->extended; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 134 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 135 | out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff); |
| 136 | out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | return (0); |
| 140 | } |
| 141 | |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 142 | void uart_port_conf(int port) |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 143 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 144 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 145 | |
| 146 | /* Setup Ports: */ |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 147 | switch (port) { |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 148 | case 0: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 149 | clrbits_8(&gpio->par_uart, |
| 150 | GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); |
| 151 | setbits_8(&gpio->par_uart, |
| 152 | GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 153 | break; |
| 154 | case 1: |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 155 | #ifdef CONFIG_SYS_UART1_PRI_GPIO |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 156 | clrbits_8(&gpio->par_uart, |
| 157 | GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); |
| 158 | setbits_8(&gpio->par_uart, |
| 159 | GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 160 | #elif defined(CONFIG_SYS_UART1_ALT1_GPIO) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 161 | clrbits_be16(&gpio->par_ssi, |
| 162 | ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK)); |
| 163 | setbits_be16(&gpio->par_ssi, |
| 164 | GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD); |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 165 | #endif |
| 166 | break; |
| 167 | case 2: |
| 168 | #if defined(CONFIG_SYS_UART2_ALT1_GPIO) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 169 | clrbits_8(&gpio->par_timer, |
| 170 | ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK)); |
| 171 | setbits_8(&gpio->par_timer, |
| 172 | GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD); |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 173 | #elif defined(CONFIG_SYS_UART2_ALT2_GPIO) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 174 | clrbits_8(&gpio->par_timer, |
| 175 | ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK)); |
| 176 | setbits_8(&gpio->par_timer, |
| 177 | GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD); |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 178 | #endif |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 179 | break; |
| 180 | } |
| 181 | } |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 182 | |
| 183 | #if defined(CONFIG_CMD_NET) |
| 184 | int fecpin_setclear(struct eth_device *dev, int setclear) |
| 185 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 186 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 187 | struct fec_info_s *info = (struct fec_info_s *)dev->priv; |
| 188 | |
| 189 | if (setclear) { |
Wolfgang Wegner | ae49099 | 2010-03-30 19:19:50 +0100 | [diff] [blame] | 190 | #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY |
| 191 | if (info->iobase == CONFIG_SYS_FEC0_IOBASE) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 192 | setbits_be16(&gpio->par_feci2c, |
| 193 | GPIO_PAR_FECI2C_MDC0_MDC0 | |
| 194 | GPIO_PAR_FECI2C_MDIO0_MDIO0); |
Wolfgang Wegner | ae49099 | 2010-03-30 19:19:50 +0100 | [diff] [blame] | 195 | else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 196 | setbits_be16(&gpio->par_feci2c, |
| 197 | GPIO_PAR_FECI2C_MDC1_MDC1 | |
| 198 | GPIO_PAR_FECI2C_MDIO1_MDIO1); |
Wolfgang Wegner | ae49099 | 2010-03-30 19:19:50 +0100 | [diff] [blame] | 199 | #else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 200 | setbits_be16(&gpio->par_feci2c, |
| 201 | GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0); |
Wolfgang Wegner | ae49099 | 2010-03-30 19:19:50 +0100 | [diff] [blame] | 202 | #endif |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 203 | |
| 204 | if (info->iobase == CONFIG_SYS_FEC0_IOBASE) |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 205 | setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO); |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 206 | else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 207 | setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA); |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 208 | } else { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 209 | clrbits_be16(&gpio->par_feci2c, |
| 210 | GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0); |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 211 | |
Wolfgang Wegner | adf5567 | 2010-03-30 19:19:51 +0100 | [diff] [blame] | 212 | if (info->iobase == CONFIG_SYS_FEC0_IOBASE) { |
| 213 | #ifdef CONFIG_SYS_FEC_FULL_MII |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 214 | setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII); |
Wolfgang Wegner | adf5567 | 2010-03-30 19:19:51 +0100 | [diff] [blame] | 215 | #else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 216 | clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK); |
Wolfgang Wegner | adf5567 | 2010-03-30 19:19:51 +0100 | [diff] [blame] | 217 | #endif |
| 218 | } else { |
| 219 | #ifdef CONFIG_SYS_FEC_FULL_MII |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 220 | setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII); |
Wolfgang Wegner | adf5567 | 2010-03-30 19:19:51 +0100 | [diff] [blame] | 221 | #else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 222 | clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK); |
Wolfgang Wegner | adf5567 | 2010-03-30 19:19:51 +0100 | [diff] [blame] | 223 | #endif |
| 224 | } |
TsiChung Liew | f3962d3 | 2008-10-21 13:47:54 +0000 | [diff] [blame] | 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | #endif |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 229 | |
| 230 | #ifdef CONFIG_CF_DSPI |
| 231 | void cfspi_port_conf(void) |
| 232 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 233 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 234 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 235 | out_8(&gpio->par_dspi, |
| 236 | GPIO_PAR_DSPI_SIN_SIN | |
| 237 | GPIO_PAR_DSPI_SOUT_SOUT | |
| 238 | GPIO_PAR_DSPI_SCK_SCK); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | int cfspi_claim_bus(uint bus, uint cs) |
| 242 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 243 | dspi_t *dspi = (dspi_t *) MMAP_DSPI; |
| 244 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 245 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 246 | if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS) |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 247 | return -1; |
| 248 | |
| 249 | /* Clear FIFO and resume transfer */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 250 | clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 251 | |
| 252 | switch (cs) { |
| 253 | case 0: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 254 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); |
| 255 | setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 256 | break; |
| 257 | case 1: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 258 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); |
| 259 | setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 260 | break; |
| 261 | case 2: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 262 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); |
| 263 | setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 264 | break; |
Wolfgang Wegner | e9b43ca | 2010-03-30 19:20:31 +0100 | [diff] [blame] | 265 | case 3: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 266 | clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK); |
| 267 | setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3); |
Wolfgang Wegner | e9b43ca | 2010-03-30 19:20:31 +0100 | [diff] [blame] | 268 | break; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 269 | case 5: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 270 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); |
| 271 | setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 272 | break; |
| 273 | } |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | void cfspi_release_bus(uint bus, uint cs) |
| 279 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 280 | dspi_t *dspi = (dspi_t *) MMAP_DSPI; |
| 281 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 282 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 283 | /* Clear FIFO */ |
| 284 | clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 285 | |
| 286 | switch (cs) { |
| 287 | case 0: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 288 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 289 | break; |
| 290 | case 1: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 291 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 292 | break; |
| 293 | case 2: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 294 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 295 | break; |
Wolfgang Wegner | e9b43ca | 2010-03-30 19:20:31 +0100 | [diff] [blame] | 296 | case 3: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 297 | clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK); |
Wolfgang Wegner | e9b43ca | 2010-03-30 19:20:31 +0100 | [diff] [blame] | 298 | break; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 299 | case 5: |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame^] | 300 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | } |
| 304 | #endif |