Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 1 | #include <common.h> |
| 2 | #include <mpc8xx.h> |
| 3 | #include <pcmcia.h> |
| 4 | #include <i2c.h> |
| 5 | |
| 6 | #undef CONFIG_PCMCIA |
| 7 | |
Jon Loeliger | c508a4c | 2007-07-09 18:31:28 -0500 | [diff] [blame] | 8 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 9 | #define CONFIG_PCMCIA |
| 10 | #endif |
| 11 | |
Jon Loeliger | c508a4c | 2007-07-09 18:31:28 -0500 | [diff] [blame] | 12 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 13 | #define CONFIG_PCMCIA |
| 14 | #endif |
| 15 | |
| 16 | #ifdef CONFIG_PCMCIA |
| 17 | |
| 18 | #define PCMCIA_BOARD_MSG "LWMON" |
| 19 | |
| 20 | /* #define's for MAX1604 Power Switch */ |
| 21 | #define MAX1604_OP_SUS 0x80 |
| 22 | #define MAX1604_VCCBON 0x40 |
| 23 | #define MAX1604_VCC_35 0x20 |
| 24 | #define MAX1604_VCCBHIZ 0x10 |
| 25 | #define MAX1604_VPPBON 0x08 |
| 26 | #define MAX1604_VPPBPBPGM 0x04 |
| 27 | #define MAX1604_VPPBHIZ 0x02 |
| 28 | /* reserved 0x01 */ |
| 29 | |
| 30 | int pcmcia_hardware_enable(int slot) |
| 31 | { |
| 32 | volatile immap_t *immap; |
| 33 | volatile cpm8xx_t *cp; |
| 34 | volatile pcmconf8xx_t *pcmp; |
| 35 | volatile sysconf8xx_t *sysp; |
| 36 | uint reg, mask; |
| 37 | uchar val; |
| 38 | |
| 39 | |
| 40 | debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
| 41 | |
| 42 | /* Switch on PCMCIA port in PIC register 0x60 */ |
| 43 | reg = pic_read (0x60); |
| 44 | debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg); |
| 45 | reg &= ~0x10; |
| 46 | /* reg |= 0x08; Vpp not needed */ |
| 47 | pic_write (0x60, reg); |
| 48 | #ifdef DEBUG |
| 49 | reg = pic_read (0x60); |
| 50 | printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg); |
| 51 | #endif |
| 52 | udelay(10000); |
| 53 | |
| 54 | immap = (immap_t *)CFG_IMMR; |
| 55 | sysp = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf)); |
| 56 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia)); |
| 57 | cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm)); |
| 58 | |
| 59 | /* |
| 60 | * Configure SIUMCR to enable PCMCIA port B |
| 61 | * (VFLS[0:1] are not used for debugging, we connect FRZ# instead) |
| 62 | */ |
| 63 | sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */ |
| 64 | |
| 65 | /* clear interrupt state, and disable interrupts */ |
| 66 | pcmp->pcmc_pscr = PCMCIA_MASK(_slot_); |
| 67 | pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_); |
| 68 | |
| 69 | /* |
| 70 | * Disable interrupts, DMA, and PCMCIA buffers |
| 71 | * (isolate the interface) and assert RESET signal |
| 72 | */ |
| 73 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 74 | reg = 0; |
| 75 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 76 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 77 | PCMCIA_PGCRX(_slot_) = reg; |
| 78 | udelay(500); |
| 79 | |
| 80 | /* |
| 81 | * Make sure there is a card in the slot, then configure the interface. |
| 82 | */ |
| 83 | udelay(10000); |
| 84 | debug ("[%d] %s: PIPR(%p)=0x%x\n", |
| 85 | __LINE__,__FUNCTION__, |
| 86 | &(pcmp->pcmc_pipr),pcmp->pcmc_pipr); |
| 87 | if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) { |
| 88 | printf (" No Card found\n"); |
| 89 | return (1); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Power On. |
| 94 | */ |
| 95 | mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot); |
| 96 | reg = pcmp->pcmc_pipr; |
| 97 | debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", |
| 98 | reg, |
| 99 | (reg&PCMCIA_VS1(slot))?"n":"ff", |
| 100 | (reg&PCMCIA_VS2(slot))?"n":"ff"); |
| 101 | if ((reg & mask) == mask) { |
| 102 | val = 0; /* VCCB3/5 = 0 ==> use Vx = 5.0 V */ |
| 103 | puts (" 5.0V card found: "); |
| 104 | } else { |
| 105 | val = MAX1604_VCC_35; /* VCCB3/5 = 1 ==> use Vy = 3.3 V */ |
| 106 | puts (" 3.3V card found: "); |
| 107 | } |
| 108 | |
| 109 | /* switch VCC on */ |
| 110 | val |= MAX1604_OP_SUS | MAX1604_VCCBON; |
| 111 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 112 | i2c_write (CFG_I2C_POWER_A_ADDR, 0, 0, &val, 1); |
| 113 | |
| 114 | udelay(500000); |
| 115 | |
| 116 | debug ("Enable PCMCIA buffers and stop RESET\n"); |
| 117 | reg = PCMCIA_PGCRX(_slot_); |
| 118 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 119 | reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 120 | PCMCIA_PGCRX(_slot_) = reg; |
| 121 | |
| 122 | udelay(250000); /* some cards need >150 ms to come up :-( */ |
| 123 | |
| 124 | debug ("# hardware_enable done\n"); |
| 125 | |
| 126 | return (0); |
| 127 | } |
| 128 | |
| 129 | |
Jon Loeliger | c508a4c | 2007-07-09 18:31:28 -0500 | [diff] [blame] | 130 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 131 | int pcmcia_hardware_disable(int slot) |
| 132 | { |
| 133 | volatile immap_t *immap; |
| 134 | volatile pcmconf8xx_t *pcmp; |
| 135 | u_long reg; |
| 136 | uchar val; |
| 137 | |
| 138 | debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
| 139 | |
| 140 | immap = (immap_t *)CFG_IMMR; |
| 141 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia)); |
| 142 | |
| 143 | /* remove all power, put output in high impedance state */ |
| 144 | val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ; |
| 145 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 146 | i2c_write (CFG_I2C_POWER_A_ADDR, 0, 0, &val, 1); |
| 147 | |
| 148 | /* Configure PCMCIA General Control Register */ |
| 149 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 150 | reg = 0; |
| 151 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 152 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 153 | PCMCIA_PGCRX(_slot_) = reg; |
| 154 | |
| 155 | /* Switch off PCMCIA port in PIC register 0x60 */ |
| 156 | reg = pic_read (0x60); |
| 157 | debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg); |
| 158 | reg |= 0x10; |
| 159 | reg &= ~0x08; |
| 160 | pic_write (0x60, reg); |
| 161 | #ifdef DEBUG |
| 162 | reg = pic_read (0x60); |
| 163 | printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg); |
| 164 | #endif |
| 165 | udelay(10000); |
| 166 | |
| 167 | return (0); |
| 168 | } |
Jon Loeliger | d39b574 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 169 | #endif |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 170 | |
| 171 | |
| 172 | int pcmcia_voltage_set(int slot, int vcc, int vpp) |
| 173 | { |
| 174 | volatile immap_t *immap; |
| 175 | volatile pcmconf8xx_t *pcmp; |
| 176 | u_long reg; |
| 177 | uchar val; |
| 178 | |
| 179 | debug ("voltage_set: " |
| 180 | PCMCIA_BOARD_MSG |
| 181 | " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n", |
| 182 | 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10); |
| 183 | |
| 184 | immap = (immap_t *)CFG_IMMR; |
| 185 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia)); |
| 186 | /* |
| 187 | * Disable PCMCIA buffers (isolate the interface) |
| 188 | * and assert RESET signal |
| 189 | */ |
| 190 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 191 | reg = PCMCIA_PGCRX(_slot_); |
| 192 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 193 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 194 | PCMCIA_PGCRX(_slot_) = reg; |
| 195 | udelay(500); |
| 196 | |
| 197 | /* |
| 198 | * Turn off all power (switch to high impedance) |
| 199 | */ |
| 200 | debug ("PCMCIA power OFF\n"); |
| 201 | val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ; |
| 202 | i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE); |
| 203 | i2c_write (CFG_I2C_POWER_A_ADDR, 0, 0, &val, 1); |
| 204 | |
| 205 | val = 0; |
| 206 | switch(vcc) { |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 207 | case 0: break; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 208 | case 33: val = MAX1604_VCC_35; break; |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 209 | case 50: break; |
| 210 | default: goto done; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* Checking supported voltages */ |
| 214 | |
| 215 | debug ("PIPR: 0x%x --> %s\n", |
| 216 | pcmp->pcmc_pipr, |
| 217 | (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V"); |
| 218 | |
| 219 | i2c_write (CFG_I2C_POWER_A_ADDR, 0, 0, &val, 1); |
| 220 | if (val) { |
| 221 | debug ("PCMCIA powered at %sV\n", |
| 222 | (val & MAX1604_VCC_35) ? "3.3" : "5.0"); |
| 223 | } else { |
| 224 | debug ("PCMCIA powered down\n"); |
| 225 | } |
| 226 | |
| 227 | done: |
| 228 | debug ("Enable PCMCIA buffers and stop RESET\n"); |
| 229 | reg = PCMCIA_PGCRX(_slot_); |
| 230 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 231 | reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 232 | PCMCIA_PGCRX(_slot_) = reg; |
| 233 | udelay(500); |
| 234 | |
| 235 | debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", |
| 236 | slot+'A'); |
| 237 | return (0); |
| 238 | } |
| 239 | |
| 240 | #endif /* CONFIG_PCMCIA */ |