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