4 #include <linux/compiler.h>
8 #if defined(CONFIG_CMD_PCMCIA)
12 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
16 #if defined(CONFIG_PCMCIA)
18 #if defined(CONFIG_IDE_8xx_PCCARD)
19 extern int check_ide_device (int slot);
22 extern int pcmcia_hardware_enable (int slot);
23 extern int pcmcia_voltage_set(int slot, int vcc, int vpp);
25 #if defined(CONFIG_CMD_PCMCIA)
26 extern int pcmcia_hardware_disable(int slot);
29 static u_int m8xx_get_graycode(u_int size);
31 static u_int m8xx_get_speed(u_int ns, u_int is_io);
34 /* look up table for pgcrx registers */
35 u_int *pcmcia_pgcrx[2] = {
36 &((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pgcra,
37 &((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pgcrb,
41 * Search this table to see if the windowsize is
45 #define M8XX_SIZES_NO 32
47 static const u_int m8xx_size_to_gray[M8XX_SIZES_NO] =
48 { 0x00000001, 0x00000002, 0x00000008, 0x00000004,
49 0x00000080, 0x00000040, 0x00000010, 0x00000020,
50 0x00008000, 0x00004000, 0x00001000, 0x00002000,
51 0x00000100, 0x00000200, 0x00000800, 0x00000400,
53 0x0fffffff, 0xffffffff, 0xffffffff, 0xffffffff,
54 0x01000000, 0x02000000, 0xffffffff, 0x04000000,
55 0x00010000, 0x00020000, 0x00080000, 0x00040000,
56 0x00800000, 0x00400000, 0x00100000, 0x00200000 };
59 /* -------------------------------------------------------------------- */
61 #if defined(CONFIG_LWMON) || defined(CONFIG_NSCU)
62 #define CONFIG_SYS_PCMCIA_TIMING ( PCMCIA_SHT(9) \
66 #define CONFIG_SYS_PCMCIA_TIMING ( PCMCIA_SHT(2) \
71 /* -------------------------------------------------------------------- */
78 __maybe_unused u_int slotbit;
81 debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n");
83 /* intialize the fixed memory windows */
84 win = (pcmcia_win_t *)(&((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pbr0);
85 base = CONFIG_SYS_PCMCIA_MEM_ADDR;
87 if((reg = m8xx_get_graycode(CONFIG_SYS_PCMCIA_MEM_SIZE)) == -1) {
88 printf ("Cannot set window size to 0x%08x\n",
89 CONFIG_SYS_PCMCIA_MEM_SIZE);
93 slotbit = PCMCIA_SLOT_x;
94 for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) {
97 #if (PCMCIA_SOCKETS_NO == 2)
98 if (i == 4) /* Another slot starting from win 4 */
99 slotbit = (slotbit ? PCMCIA_PSLOT_A : PCMCIA_PSLOT_B);
102 #ifdef CONFIG_IDE_8xx_PCCARD
104 case 0: { /* map attribute memory */
105 win->or = ( PCMCIA_BSIZE_64M
110 | CONFIG_SYS_PCMCIA_TIMING );
114 case 1: { /* map I/O window for data reg */
115 win->or = ( PCMCIA_BSIZE_1K
120 | CONFIG_SYS_PCMCIA_TIMING );
124 case 2: { /* map I/O window for cmd/ctrl reg block */
125 win->or = ( PCMCIA_BSIZE_1K
130 | CONFIG_SYS_PCMCIA_TIMING );
133 #endif /* CONFIG_IDE_8xx_PCCARD */
134 default: /* set to not valid */
139 debug ("MemWin %d: PBR 0x%08lX POR %08lX\n",
140 i, win->br, win->or);
141 base += CONFIG_SYS_PCMCIA_MEM_SIZE;
145 for (i=0, rc=0, slot=_slot_; i<PCMCIA_SOCKETS_NO; i++, slot = !slot) {
146 /* turn off voltage */
147 if ((rc = pcmcia_voltage_set(slot, 0, 0)))
150 /* Enable external hardware */
151 if ((rc = pcmcia_hardware_enable(slot)))
154 #ifdef CONFIG_IDE_8xx_PCCARD
155 if ((rc = check_ide_device(i)))
162 #if defined(CONFIG_CMD_PCMCIA)
163 int pcmcia_off (void)
168 printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n");
170 /* clear interrupt state, and disable interrupts */
171 ((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pscr = PCMCIA_MASK(_slot_);
172 ((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_per &= ~PCMCIA_MASK(_slot_);
174 /* turn off interrupt and disable CxOE */
175 PCMCIA_PGCRX(_slot_) = __MY_PCMCIA_GCRX_CXOE;
177 /* turn off memory windows */
178 win = (pcmcia_win_t *)(&((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pbr0);
180 for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) {
181 /* disable memory window */
186 /* turn off voltage */
187 pcmcia_voltage_set(_slot_, 0, 0);
189 /* disable external hardware */
190 printf ("Shutdown and Poweroff " PCMCIA_SLOT_MSG "\n");
191 pcmcia_hardware_disable(_slot_);
197 static u_int m8xx_get_graycode(u_int size)
201 for (k = 0; k < M8XX_SIZES_NO; k++) {
202 if(m8xx_size_to_gray[k] == size)
206 if((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1))
214 static u_int m8xx_get_speed(u_int ns, u_int is_io)
216 u_int reg, clocks, psst, psl, psht;
221 * We get called with IO maps setup to 0ns
222 * if not specified by the user.
223 * They should be 255ns.
229 ns = 100; /* fast memory if 0 */
233 * In PSST, PSL, PSHT fields we tell the controller
234 * timing parameters in CLKOUT clock cycles.
235 * CLKOUT is the same as GCLK2_50.
238 /* how we want to adjust the timing - in percent */
240 #define ADJ 180 /* 80 % longer accesstime - to be sure */
242 clocks = ((M8XX_BUSFREQ / 1000) * ns) / 1000;
243 clocks = (clocks * ADJ) / (100*1000);
245 if(clocks >= PCMCIA_BMT_LIMIT) {
246 DEBUG(0, "Max access time limit reached\n");
247 clocks = PCMCIA_BMT_LIMIT-1;
250 psst = clocks / 7; /* setup time */
251 psht = clocks / 7; /* hold time */
252 psl = (clocks * 5) / 7; /* strobe length */
254 psst += clocks - (psst + psht + psl);
264 #endif /* CONFIG_PCMCIA */