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 "UC100" |
| 18 | |
| 19 | /* |
| 20 | * Remark: don't turn off OE "__MY_PCMCIA_GCRX_CXOE" on UC100 board. |
| 21 | * This leads to board-hangup! (sr, 8 Dez. 2004) |
| 22 | */ |
| 23 | static void cfg_ports (void) |
| 24 | { |
| 25 | volatile immap_t *immap; |
| 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | immap = (immap_t *)CONFIG_SYS_IMMR; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 28 | |
| 29 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 30 | * Configure Port A for MAX1602 PC-Card Power-Interface Switch |
| 31 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 32 | immap->im_ioport.iop_padat &= ~0x8000; /* set port x output to low */ |
| 33 | immap->im_ioport.iop_padir |= 0x8000; /* enable port x as output */ |
| 34 | |
| 35 | debug ("Set Port A: PAR: %08x DIR: %08x DAT: %08x\n", |
| 36 | immap->im_ioport.iop_papar, immap->im_ioport.iop_padir, |
| 37 | immap->im_ioport.iop_padat); |
| 38 | } |
| 39 | |
| 40 | int pcmcia_hardware_enable(int slot) |
| 41 | { |
| 42 | volatile immap_t *immap; |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 43 | volatile pcmconf8xx_t *pcmp; |
| 44 | volatile sysconf8xx_t *sysp; |
| 45 | uint reg, mask; |
| 46 | |
| 47 | debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
| 48 | |
| 49 | udelay(10000); |
| 50 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | immap = (immap_t *)CONFIG_SYS_IMMR; |
| 52 | sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf)); |
| 53 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia)); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 54 | |
| 55 | /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */ |
| 56 | cfg_ports (); |
| 57 | |
| 58 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 59 | * Configure SIUMCR to enable PCMCIA port B |
| 60 | * (VFLS[0:1] are not used for debugging, we connect FRZ# instead) |
| 61 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 62 | sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */ |
| 63 | |
| 64 | /* clear interrupt state, and disable interrupts */ |
| 65 | pcmp->pcmc_pscr = PCMCIA_MASK(_slot_); |
| 66 | pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_); |
| 67 | |
| 68 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 69 | * Disable interrupts, DMA, and PCMCIA buffers |
| 70 | * (isolate the interface) and assert RESET signal |
| 71 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 72 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 73 | reg = 0; |
| 74 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 75 | PCMCIA_PGCRX(_slot_) = reg; |
| 76 | udelay(500); |
| 77 | |
| 78 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 79 | * Make sure there is a card in the slot, then configure the interface. |
| 80 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 81 | udelay(10000); |
| 82 | debug ("[%d] %s: PIPR(%p)=0x%x\n", |
| 83 | __LINE__,__FUNCTION__, |
| 84 | &(pcmp->pcmc_pipr),pcmp->pcmc_pipr); |
| 85 | if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) { |
| 86 | printf (" No Card found\n"); |
| 87 | return (1); |
| 88 | } |
| 89 | |
| 90 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 91 | * Power On. |
| 92 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 93 | mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot); |
| 94 | reg = pcmp->pcmc_pipr; |
| 95 | debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", |
| 96 | reg, |
| 97 | (reg&PCMCIA_VS1(slot))?"n":"ff", |
| 98 | (reg&PCMCIA_VS2(slot))?"n":"ff"); |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 99 | |
| 100 | if ((reg & mask) == mask) |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 101 | puts (" 5.0V card found: "); |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 102 | else |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 103 | puts (" 3.3V card found: "); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 104 | |
| 105 | /* switch VCC on */ |
| 106 | immap->im_ioport.iop_padat |= 0x8000; /* power enable 3.3V */ |
| 107 | |
| 108 | udelay(10000); |
| 109 | |
| 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; |
| 128 | volatile cpm8xx_t *cp; |
| 129 | volatile pcmconf8xx_t *pcmp; |
| 130 | u_long reg; |
| 131 | |
| 132 | debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot); |
| 133 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | immap = (immap_t *)CONFIG_SYS_IMMR; |
| 135 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia)); |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 136 | |
| 137 | /* switch VCC off */ |
| 138 | immap->im_ioport.iop_padat &= ~0x8000; /* power disable 3.3V */ |
| 139 | |
| 140 | /* Configure PCMCIA General Control Register */ |
| 141 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 142 | reg = 0; |
| 143 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 144 | PCMCIA_PGCRX(_slot_) = reg; |
| 145 | |
| 146 | udelay(10000); |
| 147 | |
| 148 | return (0); |
| 149 | } |
Jon Loeliger | d39b574 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 150 | #endif |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 151 | |
| 152 | |
| 153 | int pcmcia_voltage_set(int slot, int vcc, int vpp) |
| 154 | { |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 155 | u_long reg; |
| 156 | |
| 157 | debug ("voltage_set: " |
| 158 | PCMCIA_BOARD_MSG |
| 159 | " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n", |
| 160 | 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10); |
| 161 | |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 162 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 163 | * Disable PCMCIA buffers (isolate the interface) |
| 164 | * and assert RESET signal |
| 165 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 166 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 167 | reg = PCMCIA_PGCRX(_slot_); |
| 168 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 169 | PCMCIA_PGCRX(_slot_) = reg; |
| 170 | udelay(500); |
| 171 | |
| 172 | /* |
Wolfgang Denk | 561d01a | 2011-11-04 15:55:27 +0000 | [diff] [blame] | 173 | * Configure Port C pins for |
| 174 | * 5 Volts Enable and 3 Volts enable, |
| 175 | * Turn all power pins to Hi-Z |
| 176 | */ |
Wolfgang Denk | 9d40799 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 177 | debug ("PCMCIA power OFF\n"); |
| 178 | cfg_ports (); /* Enables switch, but all in Hi-Z */ |
| 179 | |
| 180 | debug ("Enable PCMCIA buffers and stop RESET\n"); |
| 181 | reg = PCMCIA_PGCRX(_slot_); |
| 182 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 183 | reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 184 | PCMCIA_PGCRX(_slot_) = reg; |
| 185 | udelay(500); |
| 186 | |
| 187 | debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", |
| 188 | slot+'A'); |
| 189 | return (0); |
| 190 | } |
| 191 | |
| 192 | #endif /* CONFIG_PCMCIA */ |