Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 1 | #include <common.h> |
| 2 | #include <mpc8xx.h> |
| 3 | #include <pcmcia.h> |
| 4 | |
| 5 | #include "csr.h" |
| 6 | |
| 7 | #undef CONFIG_PCMCIA |
| 8 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 9 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 10 | #define CONFIG_PCMCIA |
| 11 | #endif |
| 12 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 13 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD) |
Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 14 | #define CONFIG_PCMCIA |
| 15 | #endif |
| 16 | |
| 17 | #ifdef CONFIG_PCMCIA |
| 18 | |
| 19 | /* A lot of this has been taken from the RPX code in this file it works from me. |
| 20 | I have added the voltage selection for the MBX board. */ |
| 21 | |
| 22 | /* MBX voltage bit in control register #2 */ |
| 23 | #define CR2_VPP12 ((uchar)0x10) |
| 24 | #define CR2_VPPVDD ((uchar)0x20) |
| 25 | #define CR2_VDD5 ((uchar)0x40) |
| 26 | #define CR2_VDD3 ((uchar)0x80) |
| 27 | |
| 28 | #define PCMCIA_BOARD_MSG "MBX860" |
| 29 | |
| 30 | int pcmcia_voltage_set (int slot, int vcc, int vpp) |
| 31 | { |
| 32 | uchar reg = 0; |
| 33 | |
| 34 | debug ("voltage_set: PCMCIA_BOARD_MSG Slot %c, Vcc=%d.%d, Vpp=%d.%d\n", |
| 35 | 'A' + slot, vcc / 10, vcc % 10, vpp / 10, vcc % 10); |
| 36 | |
| 37 | switch (vcc) { |
| 38 | case 0: |
| 39 | break; |
| 40 | case 33: |
| 41 | reg |= CR2_VDD3; |
| 42 | break; |
| 43 | case 50: |
| 44 | reg |= CR2_VDD5; |
| 45 | break; |
| 46 | default: |
| 47 | return 1; |
| 48 | } |
| 49 | |
| 50 | switch (vpp) { |
| 51 | case 0: |
| 52 | break; |
| 53 | case 33: |
| 54 | case 50: |
| 55 | if (vcc == vpp) { |
| 56 | reg |= CR2_VPPVDD; |
| 57 | } else { |
| 58 | return 1; |
| 59 | } |
| 60 | break; |
| 61 | case 120: |
| 62 | reg |= CR2_VPP12; |
| 63 | break; |
| 64 | default: |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | /* first, turn off all power */ |
| 69 | MBX_CSR2 &= ~(CR2_VDDSEL | CR2_VPPSEL); |
| 70 | |
| 71 | /* enable new powersettings */ |
| 72 | MBX_CSR2 |= reg; |
| 73 | debug ("MBX_CSR2 read = 0x%02x\n", MBX_CSR2); |
| 74 | |
| 75 | return (0); |
| 76 | } |
| 77 | |
| 78 | int pcmcia_hardware_enable (int slot) |
| 79 | { |
| 80 | volatile immap_t *immap; |
| 81 | volatile cpm8xx_t *cp; |
| 82 | volatile pcmconf8xx_t *pcmp; |
| 83 | volatile sysconf8xx_t *sysp; |
| 84 | uint reg, mask; |
| 85 | |
| 86 | debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", |
| 87 | 'A' + slot); |
| 88 | |
| 89 | udelay (10000); |
| 90 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | immap = (immap_t *) CONFIG_SYS_IMMR; |
| 92 | sysp = (sysconf8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_siu_conf)); |
| 93 | pcmp = (pcmconf8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_pcmcia)); |
| 94 | cp = (cpm8xx_t *) (&(((immap_t *) CONFIG_SYS_IMMR)->im_cpm)); |
Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 95 | |
| 96 | /* clear interrupt state, and disable interrupts */ |
| 97 | pcmp->pcmc_pscr = PCMCIA_MASK (_slot_); |
| 98 | pcmp->pcmc_per &= ~PCMCIA_MASK (_slot_); |
| 99 | |
| 100 | /* |
| 101 | * Disable interrupts, DMA, and PCMCIA buffers |
| 102 | * (isolate the interface) and assert RESET signal |
| 103 | */ |
| 104 | debug ("Disable PCMCIA buffers and assert RESET\n"); |
| 105 | reg = 0; |
| 106 | reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 107 | reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 108 | PCMCIA_PGCRX (_slot_) = reg; |
| 109 | udelay (500); |
| 110 | |
| 111 | /* remove all power */ |
| 112 | pcmcia_voltage_set (slot, 0, 0); |
| 113 | /* |
| 114 | * Make sure there is a card in the slot, then configure the interface. |
| 115 | */ |
| 116 | udelay(10000); |
| 117 | debug ("[%d] %s: PIPR(%p)=0x%x\n", |
| 118 | __LINE__,__FUNCTION__, |
| 119 | &(pcmp->pcmc_pipr),pcmp->pcmc_pipr); |
| 120 | #ifndef CONFIG_HMI10 |
| 121 | if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) { |
| 122 | #else |
| 123 | if (pcmp->pcmc_pipr & (0x10000000 >> (slot << 4))) { |
| 124 | #endif /* CONFIG_HMI10 */ |
| 125 | printf (" No Card found\n"); |
| 126 | return (1); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Power On. |
| 131 | */ |
| 132 | mask = PCMCIA_VS1 (_slot_) | PCMCIA_VS2 (_slot_); |
| 133 | reg = pcmp->pcmc_pipr; |
| 134 | debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n", reg, |
| 135 | (reg & PCMCIA_VS1 (slot)) ? "n" : "ff", |
| 136 | (reg & PCMCIA_VS2 (slot)) ? "n" : "ff"); |
| 137 | |
| 138 | if ((reg & mask) == mask) { |
| 139 | pcmcia_voltage_set (_slot_, 50, 0); |
| 140 | printf (" 5.0V card found: "); |
| 141 | } else { |
| 142 | pcmcia_voltage_set (_slot_, 33, 0); |
| 143 | printf (" 3.3V card found: "); |
| 144 | } |
| 145 | |
| 146 | debug ("Enable PCMCIA buffers and stop RESET\n"); |
| 147 | reg = PCMCIA_PGCRX (_slot_); |
| 148 | reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */ |
| 149 | reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */ |
| 150 | PCMCIA_PGCRX (_slot_) = reg; |
| 151 | |
| 152 | udelay (250000); /* some cards need >150 ms to come up :-( */ |
| 153 | |
| 154 | debug ("# hardware_enable done\n"); |
| 155 | |
| 156 | return (0); |
| 157 | } |
| 158 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 159 | #if defined(CONFIG_CMD_PCMCIA) |
Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 160 | int pcmcia_hardware_disable (int slot) |
| 161 | { |
| 162 | return 0; /* No hardware to disable */ |
| 163 | } |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 164 | #endif |
Wolfgang Denk | 50440e7 | 2006-07-10 23:07:28 +0200 | [diff] [blame] | 165 | |
| 166 | #endif /* CONFIG_PCMCIA */ |