Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 1 | /* -------------------------------------------------------------------- */ |
| 2 | /* TQM8xxL Boards by TQ Components */ |
| 3 | /* SC8xx Boards by SinoVee Microsystems */ |
| 4 | /* -------------------------------------------------------------------- */ |
| 5 | #include <common.h> |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 6 | #include <asm/io.h> |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 7 | #ifdef CONFIG_8xx |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 8 | #include <mpc8xx.h> |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 9 | #endif |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 10 | #include <pcmcia.h> |
| 11 | |
| 12 | #undef CONFIG_PCMCIA |
| 13 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 14 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 15 | #define CONFIG_PCMCIA |
| 16 | #endif |
| 17 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 18 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 19 | #define CONFIG_PCMCIA |
| 20 | #endif |
| 21 | |
| 22 | #if defined(CONFIG_PCMCIA) \ |
Masahiro Yamada | d1a4aaf | 2014-08-06 12:59:52 +0900 | [diff] [blame] | 23 | && defined(CONFIG_TQM8xxL) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 24 | |
| 25 | #if defined(CONFIG_VIRTLAB2) |
| 26 | #define PCMCIA_BOARD_MSG "Virtlab2" |
| 27 | #elif defined(CONFIG_TQM8xxL) |
| 28 | #define PCMCIA_BOARD_MSG "TQM8xxL" |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #if defined(CONFIG_NSCU) |
| 32 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 33 | static inline void power_config(int slot) {} |
| 34 | static inline void power_off(int slot) {} |
| 35 | static inline void power_on_5_0(int slot) {} |
| 36 | static inline void power_on_3_3(int slot) {} |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 37 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 38 | #elif defined(CONFIG_VIRTLAB2) |
| 39 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 40 | static inline void power_config(int slot) {} |
| 41 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 42 | static inline void power_off(int slot) |
| 43 | { |
Marek Vasut | 3ebafbf | 2011-10-21 14:17:24 +0000 | [diff] [blame] | 44 | volatile unsigned __iomem *addr; |
| 45 | addr = (volatile unsigned __iomem *)PCMCIA_CTRL; |
| 46 | |
| 47 | out_be32(addr, 0); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static inline void power_on_5_0(int slot) |
| 51 | { |
Marek Vasut | 3ebafbf | 2011-10-21 14:17:24 +0000 | [diff] [blame] | 52 | volatile unsigned __iomem *addr; |
| 53 | addr = (volatile unsigned __iomem *)PCMCIA_CTRL; |
| 54 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 55 | /* Enable 5V Vccout */ |
Marek Vasut | 3ebafbf | 2011-10-21 14:17:24 +0000 | [diff] [blame] | 56 | out_be32(addr, 2); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static inline void power_on_3_3(int slot) |
| 60 | { |
Marek Vasut | 3ebafbf | 2011-10-21 14:17:24 +0000 | [diff] [blame] | 61 | volatile unsigned __iomem *addr; |
| 62 | addr = (volatile unsigned __iomem *)PCMCIA_CTRL; |
| 63 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 64 | /* Enable 3.3V Vccout */ |
Marek Vasut | 3ebafbf | 2011-10-21 14:17:24 +0000 | [diff] [blame] | 65 | out_be32(addr, 1); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | #else |
| 69 | |
| 70 | static inline void power_config(int slot) |
| 71 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 72 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 73 | /* |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 74 | * Configure Port C pins for |
| 75 | * 5 Volts Enable and 3 Volts enable |
| 76 | */ |
| 77 | clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004); |
| 78 | clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline void power_off(int slot) |
| 82 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 83 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 84 | clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static inline void power_on_5_0(int slot) |
| 88 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 89 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 90 | setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004); |
| 91 | setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static inline void power_on_3_3(int slot) |
| 95 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 96 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 97 | setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002); |
| 98 | setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | #endif |
| 102 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 103 | /* |
| 104 | * Function to retrieve the PIPR register, used for debuging purposes. |
| 105 | */ |
| 106 | static inline uint32_t debug_get_pipr(void) |
| 107 | { |
| 108 | uint32_t pipr = 0; |
| 109 | #ifdef DEBUG |
| 110 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 111 | pipr = in_be32(&immap->im_pcmcia.pcmc_pipr); |
| 112 | #endif |
| 113 | return pipr; |
| 114 | } |
| 115 | |
| 116 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 117 | static inline int check_card_is_absent(int slot) |
| 118 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 119 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 120 | uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr); |
| 121 | return pipr & (0x18000000 >> (slot << 4)); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 122 | } |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 123 | |
| 124 | #ifdef NSCU_OE_INV |
| 125 | #define NSCU_GCRX_CXOE 0 |
| 126 | #else |
| 127 | #define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE |
| 128 | #endif |
| 129 | |
| 130 | int pcmcia_hardware_enable(int slot) |
| 131 | { |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 132 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 133 | uint reg, mask; |
| 134 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 135 | debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 136 | |
| 137 | udelay(10000); |
| 138 | |
| 139 | /* |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 140 | * Configure SIUMCR to enable PCMCIA port B |
| 141 | * (VFLS[0:1] are not used for debugging, we connect FRZ# instead) |
| 142 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 143 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 144 | /* Set DBGC to 00 */ |
| 145 | clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11); |
| 146 | |
| 147 | /* Clear interrupt state, and disable interrupts */ |
| 148 | out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot)); |
| 149 | clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot)); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 150 | |
| 151 | /* |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 152 | * Disable interrupts, DMA, and PCMCIA buffers |
| 153 | * (isolate the interface) and assert RESET signal |
| 154 | */ |
| 155 | debug("Disable PCMCIA buffers and assert RESET\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 156 | reg = 0; |
| 157 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 158 | reg |= NSCU_GCRX_CXOE; |
| 159 | |
| 160 | PCMCIA_PGCRX(slot) = reg; |
| 161 | udelay(500); |
| 162 | |
| 163 | power_config(slot); |
| 164 | power_off(slot); |
| 165 | |
| 166 | /* |
| 167 | * Make sure there is a card in the slot, then configure the interface. |
| 168 | */ |
| 169 | udelay(10000); |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 170 | reg = debug_get_pipr(); |
| 171 | debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__, |
| 172 | &immap->im_pcmcia.pcmc_pipr, reg); |
Wolfgang Denk | b87dfd2 | 2006-07-19 13:50:38 +0200 | [diff] [blame] | 173 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 174 | if (check_card_is_absent(slot)) { |
| 175 | printf (" No Card found\n"); |
| 176 | return (1); |
| 177 | } |
| 178 | |
| 179 | /* |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 180 | * Power On. |
| 181 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 182 | mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot); |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 183 | reg = in_be32(&immap->im_pcmcia.pcmc_pipr); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 184 | debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", |
| 185 | reg, |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 186 | (reg & PCMCIA_VS1(slot)) ? "n" : "ff", |
| 187 | (reg & PCMCIA_VS2(slot)) ? "n" : "ff"); |
Wolfgang Denk | b87dfd2 | 2006-07-19 13:50:38 +0200 | [diff] [blame] | 188 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 189 | if ((reg & mask) == mask) { |
| 190 | power_on_5_0(slot); |
| 191 | puts (" 5.0V card found: "); |
| 192 | } else { |
| 193 | power_on_3_3(slot); |
| 194 | puts (" 3.3V card found: "); |
| 195 | } |
| 196 | |
| 197 | #if 0 |
| 198 | /* VCC switch error flag, PCMCIA slot INPACK_ pin */ |
| 199 | cp->cp_pbdir &= ~(0x0020 | 0x0010); |
| 200 | cp->cp_pbpar &= ~(0x0020 | 0x0010); |
| 201 | udelay(500000); |
| 202 | #endif |
| 203 | |
| 204 | udelay(1000); |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 205 | debug("Enable PCMCIA buffers and stop RESET\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 206 | reg = PCMCIA_PGCRX(slot); |
| 207 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 208 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 209 | reg &= ~NSCU_GCRX_CXOE; |
Wolfgang Denk | b87dfd2 | 2006-07-19 13:50:38 +0200 | [diff] [blame] | 210 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 211 | PCMCIA_PGCRX(slot) = reg; |
| 212 | |
| 213 | udelay(250000); /* some cards need >150 ms to come up :-( */ |
| 214 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 215 | debug("# hardware_enable done\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 216 | |
| 217 | return (0); |
| 218 | } |
| 219 | |
| 220 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 221 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 222 | int pcmcia_hardware_disable(int slot) |
| 223 | { |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 224 | u_long reg; |
| 225 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 226 | debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 227 | |
| 228 | /* remove all power */ |
| 229 | power_off(slot); |
| 230 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 231 | debug("Disable PCMCIA buffers and assert RESET\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 232 | reg = 0; |
| 233 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 234 | reg |= NSCU_GCRX_CXOE; /* active low */ |
| 235 | |
| 236 | PCMCIA_PGCRX(slot) = reg; |
| 237 | |
| 238 | udelay(10000); |
| 239 | |
| 240 | return (0); |
| 241 | } |
Jon Loeliger | ddb5d86f | 2007-07-10 11:13:21 -0500 | [diff] [blame] | 242 | #endif |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 243 | |
| 244 | int pcmcia_voltage_set(int slot, int vcc, int vpp) |
| 245 | { |
| 246 | #ifndef CONFIG_NSCU |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 247 | u_long reg; |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 248 | uint32_t pipr = 0; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 249 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 250 | debug("voltage_set: " PCMCIA_BOARD_MSG |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 251 | " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n", |
| 252 | 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10); |
| 253 | |
| 254 | /* |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 255 | * Disable PCMCIA buffers (isolate the interface) |
| 256 | * and assert RESET signal |
| 257 | */ |
| 258 | debug("Disable PCMCIA buffers and assert RESET\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 259 | reg = PCMCIA_PGCRX(slot); |
| 260 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 261 | reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 262 | reg |= NSCU_GCRX_CXOE; /* active low */ |
Wolfgang Denk | b87dfd2 | 2006-07-19 13:50:38 +0200 | [diff] [blame] | 263 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 264 | PCMCIA_PGCRX(slot) = reg; |
| 265 | udelay(500); |
| 266 | |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 267 | debug("PCMCIA power OFF\n"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 268 | power_config(slot); |
| 269 | power_off(slot); |
| 270 | |
| 271 | switch(vcc) { |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 272 | case 0: break; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 273 | case 33: power_on_3_3(slot); break; |
| 274 | case 50: power_on_5_0(slot); break; |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 275 | default: goto done; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* Checking supported voltages */ |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 279 | pipr = debug_get_pipr(); |
| 280 | debug("PIPR: 0x%x --> %s\n", pipr, |
| 281 | (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V"); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 282 | |
| 283 | if (vcc) |
| 284 | debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3"); |
| 285 | else |
| 286 | debug("PCMCIA powered down\n"); |
| 287 | |
| 288 | done: |
| 289 | debug("Enable PCMCIA buffers and stop RESET\n"); |
| 290 | reg = PCMCIA_PGCRX(slot); |
| 291 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 292 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 293 | reg &= ~NSCU_GCRX_CXOE; /* active low */ |
| 294 | |
| 295 | PCMCIA_PGCRX(slot) = reg; |
| 296 | udelay(500); |
| 297 | |
| 298 | debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A'); |
| 299 | #endif /* CONFIG_NSCU */ |
Marek Vasut | 6e96703 | 2011-10-05 02:51:55 +0000 | [diff] [blame] | 300 | return 0; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 301 | } |
| 302 | |
Masahiro Yamada | d1a4aaf | 2014-08-06 12:59:52 +0900 | [diff] [blame] | 303 | #endif /* CONFIG_PCMCIA && CONFIG_TQM8xxL */ |