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 #define CONFIG_SYS_PCMCIA_TIMING ( PCMCIA_SHT(2) \
65 /* -------------------------------------------------------------------- */
72 __maybe_unused u_int slotbit;
75 debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n");
77 /* intialize the fixed memory windows */
78 win = (pcmcia_win_t *)(&((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pbr0);
79 base = CONFIG_SYS_PCMCIA_MEM_ADDR;
81 if((reg = m8xx_get_graycode(CONFIG_SYS_PCMCIA_MEM_SIZE)) == -1) {
82 printf ("Cannot set window size to 0x%08x\n",
83 CONFIG_SYS_PCMCIA_MEM_SIZE);
87 slotbit = PCMCIA_SLOT_x;
88 for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) {
91 #if (PCMCIA_SOCKETS_NO == 2)
92 if (i == 4) /* Another slot starting from win 4 */
93 slotbit = (slotbit ? PCMCIA_PSLOT_A : PCMCIA_PSLOT_B);
96 #ifdef CONFIG_IDE_8xx_PCCARD
98 case 0: { /* map attribute memory */
99 win->or = ( PCMCIA_BSIZE_64M
104 | CONFIG_SYS_PCMCIA_TIMING );
108 case 1: { /* map I/O window for data reg */
109 win->or = ( PCMCIA_BSIZE_1K
114 | CONFIG_SYS_PCMCIA_TIMING );
118 case 2: { /* map I/O window for cmd/ctrl reg block */
119 win->or = ( PCMCIA_BSIZE_1K
124 | CONFIG_SYS_PCMCIA_TIMING );
127 #endif /* CONFIG_IDE_8xx_PCCARD */
128 default: /* set to not valid */
133 debug ("MemWin %d: PBR 0x%08lX POR %08lX\n",
134 i, win->br, win->or);
135 base += CONFIG_SYS_PCMCIA_MEM_SIZE;
139 for (i=0, rc=0, slot=_slot_; i<PCMCIA_SOCKETS_NO; i++, slot = !slot) {
140 /* turn off voltage */
141 if ((rc = pcmcia_voltage_set(slot, 0, 0)))
144 /* Enable external hardware */
145 if ((rc = pcmcia_hardware_enable(slot)))
148 #ifdef CONFIG_IDE_8xx_PCCARD
149 if ((rc = check_ide_device(i)))
156 #if defined(CONFIG_CMD_PCMCIA)
157 int pcmcia_off (void)
162 printf ("Disable PCMCIA " PCMCIA_SLOT_MSG "\n");
164 /* clear interrupt state, and disable interrupts */
165 ((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pscr = PCMCIA_MASK(_slot_);
166 ((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_per &= ~PCMCIA_MASK(_slot_);
168 /* turn off interrupt and disable CxOE */
169 PCMCIA_PGCRX(_slot_) = __MY_PCMCIA_GCRX_CXOE;
171 /* turn off memory windows */
172 win = (pcmcia_win_t *)(&((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia.pcmc_pbr0);
174 for (i=0; i<PCMCIA_MEM_WIN_NO; ++i) {
175 /* disable memory window */
180 /* turn off voltage */
181 pcmcia_voltage_set(_slot_, 0, 0);
183 /* disable external hardware */
184 printf ("Shutdown and Poweroff " PCMCIA_SLOT_MSG "\n");
185 pcmcia_hardware_disable(_slot_);
191 static u_int m8xx_get_graycode(u_int size)
195 for (k = 0; k < M8XX_SIZES_NO; k++) {
196 if(m8xx_size_to_gray[k] == size)
200 if((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1))
208 static u_int m8xx_get_speed(u_int ns, u_int is_io)
210 u_int reg, clocks, psst, psl, psht;
215 * We get called with IO maps setup to 0ns
216 * if not specified by the user.
217 * They should be 255ns.
223 ns = 100; /* fast memory if 0 */
227 * In PSST, PSL, PSHT fields we tell the controller
228 * timing parameters in CLKOUT clock cycles.
229 * CLKOUT is the same as GCLK2_50.
232 /* how we want to adjust the timing - in percent */
234 #define ADJ 180 /* 80 % longer accesstime - to be sure */
236 clocks = ((M8XX_BUSFREQ / 1000) * ns) / 1000;
237 clocks = (clocks * ADJ) / (100*1000);
239 if(clocks >= PCMCIA_BMT_LIMIT) {
240 DEBUG(0, "Max access time limit reached\n");
241 clocks = PCMCIA_BMT_LIMIT-1;
244 psst = clocks / 7; /* setup time */
245 psht = clocks / 7; /* hold time */
246 psl = (clocks * 5) / 7; /* strobe length */
248 psst += clocks - (psst + psht + psl);
258 #endif /* CONFIG_PCMCIA */