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