blob: e20fd33e897d506e6aea417e8f34b784ab42472e [file] [log] [blame]
wdenke5d61c72003-05-18 11:30:09 +00001/*
wdenk54070ab2004-12-31 09:32:47 +00002 * (C) Copyright 2003-2004
wdenke5d61c72003-05-18 11:30:09 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 ********************************************************************
24 *
25 * Lots of code copied from:
26 *
27 * i82365.c 1.352 - Linux driver for Intel 82365 and compatible
28 * PC Card controllers, and Yenta-compatible PCI-to-CardBus controllers.
29 * (C) 1999 David A. Hinds <dahinds@users.sourceforge.net>
30 */
31
32#include <common.h>
33
34#ifdef CONFIG_I82365
35
36#include <command.h>
37#include <pci.h>
38#include <pcmcia.h>
wdenke5d61c72003-05-18 11:30:09 +000039#include <asm/io.h>
40
41#include <pcmcia/ss.h>
42#include <pcmcia/i82365.h>
wdenke5d61c72003-05-18 11:30:09 +000043#include <pcmcia/yenta.h>
wdenk54070ab2004-12-31 09:32:47 +000044#ifdef CONFIG_CPC45
45#include <pcmcia/cirrus.h>
46#else
47#include <pcmcia/ti113x.h>
48#endif
wdenke5d61c72003-05-18 11:30:09 +000049
50static struct pci_device_id supported[] = {
wdenk54070ab2004-12-31 09:32:47 +000051#ifdef CONFIG_CPC45
52 {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6729},
53#else
wdenke5d61c72003-05-18 11:30:09 +000054 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510},
wdenk54070ab2004-12-31 09:32:47 +000055#endif
wdenke5d61c72003-05-18 11:30:09 +000056 {0, 0}
57};
58
59#define CYCLE_TIME 120
60
wdenk54070ab2004-12-31 09:32:47 +000061#ifdef CONFIG_CPC45
62extern int SPD67290Init (void);
63#endif
64
wdenke5d61c72003-05-18 11:30:09 +000065#ifdef DEBUG
66static void i82365_dump_regions (pci_dev_t dev);
67#endif
68
69typedef struct socket_info_t {
wdenk54070ab2004-12-31 09:32:47 +000070 pci_dev_t dev;
71 u_short bcr;
72 u_char pci_lat, cb_lat, sub_bus, cache;
73 u_int cb_phys;
wdenke5d61c72003-05-18 11:30:09 +000074
wdenk54070ab2004-12-31 09:32:47 +000075 socket_cap_t cap;
76 u_short type;
77 u_int flags;
78#ifdef CONFIG_CPC45
79 cirrus_state_t c_state;
80#else
81 ti113x_state_t state;
82#endif
wdenke5d61c72003-05-18 11:30:09 +000083} socket_info_t;
84
wdenk54070ab2004-12-31 09:32:47 +000085#ifdef CONFIG_CPC45
86/* These definitions must match the pcic table! */
87typedef enum pcic_id {
88 IS_PD6710, IS_PD672X, IS_VT83C469
89} pcic_id;
90
91typedef struct pcic_t {
92 char *name;
93} pcic_t;
94
95static pcic_t pcic[] = {
96 {" Cirrus PD6710: "},
97 {" Cirrus PD672x: "},
98 {" VIA VT83C469: "},
99};
100#endif
101
wdenke5d61c72003-05-18 11:30:09 +0000102static socket_info_t socket;
103static socket_state_t state;
104static struct pccard_mem_map mem;
105static struct pccard_io_map io;
106
107/*====================================================================*/
108
109/* Some PCI shortcuts */
110
111static int pci_readb (socket_info_t * s, int r, u_char * v)
112{
113 return pci_read_config_byte (s->dev, r, v);
114}
115static int pci_writeb (socket_info_t * s, int r, u_char v)
116{
117 return pci_write_config_byte (s->dev, r, v);
118}
119static int pci_readw (socket_info_t * s, int r, u_short * v)
120{
121 return pci_read_config_word (s->dev, r, v);
122}
123static int pci_writew (socket_info_t * s, int r, u_short v)
124{
125 return pci_write_config_word (s->dev, r, v);
126}
wdenk54070ab2004-12-31 09:32:47 +0000127#ifndef CONFIG_CPC45
wdenke5d61c72003-05-18 11:30:09 +0000128static int pci_readl (socket_info_t * s, int r, u_int * v)
129{
130 return pci_read_config_dword (s->dev, r, v);
131}
132static int pci_writel (socket_info_t * s, int r, u_int v)
133{
134 return pci_write_config_dword (s->dev, r, v);
135}
wdenk54070ab2004-12-31 09:32:47 +0000136#endif /* !CONFIG_CPC45 */
137
138/*====================================================================*/
139
140#ifdef CONFIG_CPC45
141
142#define cb_readb(s) readb((s)->cb_phys + 1)
143#define cb_writeb(s, v) writeb(v, (s)->cb_phys)
144#define cb_writeb2(s, v) writeb(v, (s)->cb_phys + 1)
145#define cb_readl(s, r) readl((s)->cb_phys + (r))
146#define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r))
147
148
149static u_char i365_get (socket_info_t * s, u_short reg)
150{
151 u_char val;
wdenk54070ab2004-12-31 09:32:47 +0000152#ifdef CONFIG_PCMCIA_SLOT_A
153 int slot = 0;
154#else
155 int slot = 1;
156#endif
157
158 val = I365_REG (slot, reg);
159
160 cb_writeb (s, val);
161 val = cb_readb (s);
162
163 debug ("i365_get slot:%x reg: %x val: %x\n", slot, reg, val);
164 return val;
165}
166
167static void i365_set (socket_info_t * s, u_short reg, u_char data)
168{
169#ifdef CONFIG_PCMCIA_SLOT_A
170 int slot = 0;
171#else
172 int slot = 1;
173#endif
wdenk525d7b62005-01-22 18:13:04 +0000174 u_char val;
wdenk54070ab2004-12-31 09:32:47 +0000175
wdenk525d7b62005-01-22 18:13:04 +0000176 val = I365_REG (slot, reg);
wdenk54070ab2004-12-31 09:32:47 +0000177
178 cb_writeb (s, val);
179 cb_writeb2 (s, data);
180
181 debug ("i365_set slot:%x reg: %x data:%x\n", slot, reg, data);
182}
183
184#else /* ! CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000185
186#define cb_readb(s, r) readb((s)->cb_phys + (r))
187#define cb_readl(s, r) readl((s)->cb_phys + (r))
188#define cb_writeb(s, r, v) writeb(v, (s)->cb_phys + (r))
189#define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r))
190
wdenke5d61c72003-05-18 11:30:09 +0000191static u_char i365_get (socket_info_t * s, u_short reg)
192{
193 return cb_readb (s, 0x0800 + reg);
194}
195
196static void i365_set (socket_info_t * s, u_short reg, u_char data)
197{
198 cb_writeb (s, 0x0800 + reg, data);
199}
wdenk54070ab2004-12-31 09:32:47 +0000200#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000201
202static void i365_bset (socket_info_t * s, u_short reg, u_char mask)
203{
204 i365_set (s, reg, i365_get (s, reg) | mask);
205}
206
207static void i365_bclr (socket_info_t * s, u_short reg, u_char mask)
208{
209 i365_set (s, reg, i365_get (s, reg) & ~mask);
210}
211
212#if 0 /* not used */
213static void i365_bflip (socket_info_t * s, u_short reg, u_char mask, int b)
214{
215 u_char d = i365_get (s, reg);
216
217 i365_set (s, reg, (b) ? (d | mask) : (d & ~mask));
218}
219
220static u_short i365_get_pair (socket_info_t * s, u_short reg)
221{
222 return (i365_get (s, reg) + (i365_get (s, reg + 1) << 8));
223}
224#endif /* not used */
225
226static void i365_set_pair (socket_info_t * s, u_short reg, u_short data)
227{
228 i365_set (s, reg, data & 0xff);
229 i365_set (s, reg + 1, data >> 8);
230}
231
wdenk54070ab2004-12-31 09:32:47 +0000232#ifdef CONFIG_CPC45
233/*======================================================================
234
235 Code to save and restore global state information for Cirrus
236 PD67xx controllers, and to set and report global configuration
237 options.
238
239======================================================================*/
240
241#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))
242
243static void cirrus_get_state (socket_info_t * s)
244{
245 int i;
246 cirrus_state_t *p = &s->c_state;
247
248 p->misc1 = i365_get (s, PD67_MISC_CTL_1);
249 p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);
250 p->misc2 = i365_get (s, PD67_MISC_CTL_2);
251 for (i = 0; i < 6; i++)
252 p->timer[i] = i365_get (s, PD67_TIME_SETUP (0) + i);
253
254}
255
256static void cirrus_set_state (socket_info_t * s)
257{
258 int i;
259 u_char misc;
260 cirrus_state_t *p = &s->c_state;
261
262 misc = i365_get (s, PD67_MISC_CTL_2);
263 i365_set (s, PD67_MISC_CTL_2, p->misc2);
264 if (misc & PD67_MC2_SUSPEND)
265 udelay (50000);
266 misc = i365_get (s, PD67_MISC_CTL_1);
267 misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);
268 i365_set (s, PD67_MISC_CTL_1, misc | p->misc1);
269 for (i = 0; i < 6; i++)
270 i365_set (s, PD67_TIME_SETUP (0) + i, p->timer[i]);
271}
272
273static u_int cirrus_set_opts (socket_info_t * s)
274{
275 cirrus_state_t *p = &s->c_state;
276 u_int mask = 0xffff;
wdenk54070ab2004-12-31 09:32:47 +0000277#if DEBUG
278 char buf[200];
279
280 memset (buf, 0, 200);
281#endif
282
283 if (has_ring == -1)
284 has_ring = 1;
285 flip (p->misc2, PD67_MC2_IRQ15_RI, has_ring);
286 flip (p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode);
287#if DEBUG
288 if (p->misc2 & PD67_MC2_IRQ15_RI)
289 strcat (buf, " [ring]");
290 if (p->misc2 & PD67_MC2_DYNAMIC_MODE)
291 strcat (buf, " [dyn mode]");
292 if (p->misc1 & PD67_MC1_INPACK_ENA)
293 strcat (buf, " [inpack]");
294#endif
295
296 if (p->misc2 & PD67_MC2_IRQ15_RI)
297 mask &= ~0x8000;
298 if (has_led > 0) {
299#if DEBUG
300 strcat (buf, " [led]");
301#endif
302 mask &= ~0x1000;
303 }
304 if (has_dma > 0) {
305#if DEBUG
306 strcat (buf, " [dma]");
307#endif
308 mask &= ~0x0600;
309 flip (p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass);
310#if DEBUG
311 if (p->misc2 & PD67_MC2_FREQ_BYPASS)
312 strcat (buf, " [freq bypass]");
313#endif
314 }
315
316 if (setup_time >= 0)
317 p->timer[0] = p->timer[3] = setup_time;
318 if (cmd_time > 0) {
319 p->timer[1] = cmd_time;
320 p->timer[4] = cmd_time * 2 + 4;
321 }
322 if (p->timer[1] == 0) {
323 p->timer[1] = 6;
324 p->timer[4] = 16;
325 if (p->timer[0] == 0)
326 p->timer[0] = p->timer[3] = 1;
327 }
328 if (recov_time >= 0)
329 p->timer[2] = p->timer[5] = recov_time;
330
331 debug ("i82365 Opt: %s [%d/%d/%d] [%d/%d/%d]\n",
332 buf,
333 p->timer[0], p->timer[1], p->timer[2],
334 p->timer[3], p->timer[4], p->timer[5]);
335
336 return mask;
337}
338
339#else /* !CONFIG_CPC45 */
340
wdenke5d61c72003-05-18 11:30:09 +0000341/*======================================================================
342
343 Code to save and restore global state information for TI 1130 and
344 TI 1131 controllers, and to set and report global configuration
345 options.
wdenk57b2d802003-06-27 21:31:46 +0000346
wdenke5d61c72003-05-18 11:30:09 +0000347======================================================================*/
348
349static void ti113x_get_state (socket_info_t * s)
350{
351 ti113x_state_t *p = &s->state;
352
353 pci_readl (s, TI113X_SYSTEM_CONTROL, &p->sysctl);
354 pci_readb (s, TI113X_CARD_CONTROL, &p->cardctl);
355 pci_readb (s, TI113X_DEVICE_CONTROL, &p->devctl);
356 pci_readb (s, TI1250_DIAGNOSTIC, &p->diag);
357 pci_readl (s, TI12XX_IRQMUX, &p->irqmux);
358}
359
360static void ti113x_set_state (socket_info_t * s)
361{
362 ti113x_state_t *p = &s->state;
363
364 pci_writel (s, TI113X_SYSTEM_CONTROL, p->sysctl);
365 pci_writeb (s, TI113X_CARD_CONTROL, p->cardctl);
366 pci_writeb (s, TI113X_DEVICE_CONTROL, p->devctl);
367 pci_writeb (s, TI1250_MULTIMEDIA_CTL, 0);
368 pci_writeb (s, TI1250_DIAGNOSTIC, p->diag);
369 pci_writel (s, TI12XX_IRQMUX, p->irqmux);
370 i365_set_pair (s, TI113X_IO_OFFSET (0), 0);
371 i365_set_pair (s, TI113X_IO_OFFSET (1), 0);
372}
373
374static u_int ti113x_set_opts (socket_info_t * s)
375{
376 ti113x_state_t *p = &s->state;
377 u_int mask = 0xffff;
378
379 p->cardctl &= ~TI113X_CCR_ZVENABLE;
380 p->cardctl |= TI113X_CCR_SPKROUTEN;
381
382 return mask;
383}
wdenk54070ab2004-12-31 09:32:47 +0000384#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000385
386/*======================================================================
387
388 Routines to handle common CardBus options
wdenk57b2d802003-06-27 21:31:46 +0000389
wdenke5d61c72003-05-18 11:30:09 +0000390======================================================================*/
391
392/* Default settings for PCI command configuration register */
393#define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \
394 PCI_COMMAND_MASTER|PCI_COMMAND_WAIT)
395
396static void cb_get_state (socket_info_t * s)
397{
398 pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache);
399 pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat);
400 pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat);
401 pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus);
402 pci_readb (s, CB_SUBORD_BUS, &s->sub_bus);
403 pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr);
404}
405
406static void cb_set_state (socket_info_t * s)
407{
wdenk54070ab2004-12-31 09:32:47 +0000408#ifndef CONFIG_CPC45
wdenke5d61c72003-05-18 11:30:09 +0000409 pci_writel (s, CB_LEGACY_MODE_BASE, 0);
410 pci_writel (s, PCI_BASE_ADDRESS_0, s->cb_phys);
wdenk54070ab2004-12-31 09:32:47 +0000411#endif
wdenke5d61c72003-05-18 11:30:09 +0000412 pci_writew (s, PCI_COMMAND, CMD_DFLT);
413 pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache);
414 pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat);
415 pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat);
416 pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus);
417 pci_writeb (s, CB_SUBORD_BUS, s->sub_bus);
418 pci_writew (s, CB_BRIDGE_CONTROL, s->bcr);
419}
420
421static void cb_set_opts (socket_info_t * s)
422{
wdenk54070ab2004-12-31 09:32:47 +0000423#ifndef CONFIG_CPC45
wdenke5d61c72003-05-18 11:30:09 +0000424 if (s->cache == 0)
425 s->cache = 8;
426 if (s->pci_lat == 0)
427 s->pci_lat = 0xa8;
428 if (s->cb_lat == 0)
429 s->cb_lat = 0xb0;
wdenk54070ab2004-12-31 09:32:47 +0000430#endif
wdenke5d61c72003-05-18 11:30:09 +0000431}
432
433/*======================================================================
434
435 Power control for Cardbus controllers: used both for 16-bit and
436 Cardbus cards.
wdenk57b2d802003-06-27 21:31:46 +0000437
wdenke5d61c72003-05-18 11:30:09 +0000438======================================================================*/
439
440static int cb_set_power (socket_info_t * s, socket_state_t * state)
441{
442 u_int reg = 0;
443
wdenk54070ab2004-12-31 09:32:47 +0000444#ifdef CONFIG_CPC45
445
446 if ((state->Vcc == 0) && (state->Vpp == 0)) {
447 u_char power, vcc, vpp;
448
449 power = i365_get (s, I365_POWER);
450 state->flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0;
451 state->flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0;
452 vcc = power & I365_VCC_MASK;
453 vpp = power & I365_VPP1_MASK;
454 state->Vcc = state->Vpp = 0;
455 if (i365_get (s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) {
456 if (power & I365_VCC_5V)
457 state->Vcc = 33;
458 if (vpp == I365_VPP1_5V)
459 state->Vpp = 33;
460 } else {
461 if (power & I365_VCC_5V)
462 state->Vcc = 50;
463 if (vpp == I365_VPP1_5V)
464 state->Vpp = 50;
465 }
466 if (power == I365_VPP1_12V)
467 state->Vpp = 120;
468 printf ("POWER Vcc:%d Vpp: %d\n", state->Vcc, state->Vpp);
469 }
470
471 reg = I365_PWR_NORESET;
472 if (state->flags & SS_PWR_AUTO)
473 reg |= I365_PWR_AUTO;
474 if (state->flags & SS_OUTPUT_ENA)
475 reg |= I365_PWR_OUT;
476 if (state->Vpp != 0) {
477 if (state->Vpp == 120) {
478 reg |= I365_VPP1_12V;
479 puts (" 12V card found: ");
480 } else if (state->Vpp == state->Vcc) {
481 reg |= I365_VPP1_5V;
wdenk54070ab2004-12-31 09:32:47 +0000482 } else {
483 puts (" power not found: ");
484 return -1;
485 }
486 }
487 if (state->Vcc != 0) {
488 reg |= I365_VCC_5V;
489 if (state->Vcc == 33) {
490 puts (" 3.3V card found: ");
491 i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
492 } else if (state->Vcc == 50) {
493 puts (" 5V card found: ");
494 i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
495 } else {
496 puts (" power not found: ");
497 return -1;
498 }
499 }
500 if (reg != i365_get (s, I365_POWER))
501 i365_set (s, I365_POWER, reg);
502
503#else /* ! CONFIG_CPC45 */
504
wdenke5d61c72003-05-18 11:30:09 +0000505 /* restart card voltage detection if it seems appropriate */
506 if ((state->Vcc == 0) && (state->Vpp == 0) &&
wdenk54070ab2004-12-31 09:32:47 +0000507 !(cb_readl (s, CB_SOCKET_STATE) & CB_SS_VSENSE))
wdenke5d61c72003-05-18 11:30:09 +0000508 cb_writel (s, CB_SOCKET_FORCE, CB_SF_CVSTEST);
509 switch (state->Vcc) {
510 case 0:
511 reg = 0;
512 break;
513 case 33:
514 reg = CB_SC_VCC_3V;
515 break;
516 case 50:
517 reg = CB_SC_VCC_5V;
518 break;
519 default:
520 return -1;
521 }
522 switch (state->Vpp) {
523 case 0:
524 break;
525 case 33:
526 reg |= CB_SC_VPP_3V;
527 break;
528 case 50:
529 reg |= CB_SC_VPP_5V;
530 break;
531 case 120:
532 reg |= CB_SC_VPP_12V;
533 break;
534 default:
535 return -1;
536 }
537 if (reg != cb_readl (s, CB_SOCKET_CONTROL))
538 cb_writel (s, CB_SOCKET_CONTROL, reg);
wdenk54070ab2004-12-31 09:32:47 +0000539#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000540 return 0;
541}
542
543/*======================================================================
544
545 Generic routines to get and set controller options
wdenk57b2d802003-06-27 21:31:46 +0000546
wdenke5d61c72003-05-18 11:30:09 +0000547======================================================================*/
548
549static void get_bridge_state (socket_info_t * s)
550{
wdenk54070ab2004-12-31 09:32:47 +0000551#ifdef CONFIG_CPC45
552 cirrus_get_state (s);
553#else
wdenke5d61c72003-05-18 11:30:09 +0000554 ti113x_get_state (s);
wdenk54070ab2004-12-31 09:32:47 +0000555#endif
wdenke5d61c72003-05-18 11:30:09 +0000556 cb_get_state (s);
557}
558
559static void set_bridge_state (socket_info_t * s)
560{
561 cb_set_state (s);
562 i365_set (s, I365_GBLCTL, 0x00);
563 i365_set (s, I365_GENCTL, 0x00);
wdenk54070ab2004-12-31 09:32:47 +0000564#ifdef CONFIG_CPC45
565 cirrus_set_state (s);
566#else
wdenke5d61c72003-05-18 11:30:09 +0000567 ti113x_set_state (s);
wdenk54070ab2004-12-31 09:32:47 +0000568#endif
wdenke5d61c72003-05-18 11:30:09 +0000569}
570
571static void set_bridge_opts (socket_info_t * s)
572{
wdenk54070ab2004-12-31 09:32:47 +0000573#ifdef CONFIG_CPC45
574 cirrus_set_opts (s);
575#else
wdenke5d61c72003-05-18 11:30:09 +0000576 ti113x_set_opts (s);
wdenk54070ab2004-12-31 09:32:47 +0000577#endif
wdenke5d61c72003-05-18 11:30:09 +0000578 cb_set_opts (s);
579}
580
581/*====================================================================*/
582
583static int i365_get_status (socket_info_t * s, u_int * value)
584{
585 u_int status;
wdenk54070ab2004-12-31 09:32:47 +0000586#ifdef CONFIG_CPC45
587 u_char val;
588 u_char power, vcc, vpp;
589#endif
590
591 status = i365_get (s, I365_IDENT);
wdenke5d61c72003-05-18 11:30:09 +0000592 status = i365_get (s, I365_STATUS);
593 *value = ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0;
594 if (i365_get (s, I365_INTCTL) & I365_PC_IOCARD) {
595 *value |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG;
596 } else {
597 *value |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD;
598 *value |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN;
599 }
600 *value |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0;
601 *value |= (status & I365_CS_READY) ? SS_READY : 0;
602 *value |= (status & I365_CS_POWERON) ? SS_POWERON : 0;
603
wdenk54070ab2004-12-31 09:32:47 +0000604#ifdef CONFIG_CPC45
605 /* Check for Cirrus CL-PD67xx chips */
606 i365_set (s, PD67_CHIP_INFO, 0);
607 val = i365_get (s, PD67_CHIP_INFO);
608 s->type = -1;
609 if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
610 val = i365_get (s, PD67_CHIP_INFO);
611 if ((val & PD67_INFO_CHIP_ID) == 0) {
wdenk525d7b62005-01-22 18:13:04 +0000612 s->type = (val & PD67_INFO_SLOTS) ? IS_PD672X : IS_PD6710;
wdenk54070ab2004-12-31 09:32:47 +0000613 i365_set (s, PD67_EXT_INDEX, 0xe5);
614 if (i365_get (s, PD67_EXT_INDEX) != 0xe5)
615 s->type = IS_VT83C469;
616 }
617 } else {
618 printf ("no Cirrus Chip found\n");
619 *value = 0;
620 return -1;
621 }
622
623 i365_bset (s, I365_POWER, I365_VCC_5V);
624 power = i365_get (s, I365_POWER);
625 state.flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0;
626 state.flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0;
627 vcc = power & I365_VCC_MASK;
628 vpp = power & I365_VPP1_MASK;
629 state.Vcc = state.Vpp = 0;
630 if (i365_get (s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) {
631 if (power & I365_VCC_5V)
632 state.Vcc = 33;
633 if (vpp == I365_VPP1_5V)
634 state.Vpp = 33;
635 } else {
636 if (power & I365_VCC_5V)
637 state.Vcc = 50;
638 if (vpp == I365_VPP1_5V)
639 state.Vpp = 50;
640 }
641 if (power == I365_VPP1_12V)
642 state.Vpp = 120;
643
644 /* IO card, RESET flags, IO interrupt */
645 power = i365_get (s, I365_INTCTL);
646 state.flags |= (power & I365_PC_RESET) ? 0 : SS_RESET;
647 if (power & I365_PC_IOCARD)
648 state.flags |= SS_IOCARD;
649 state.io_irq = power & I365_IRQ_MASK;
650
651 /* Card status change mask */
652 power = i365_get (s, I365_CSCINT);
653 state.csc_mask = (power & I365_CSC_DETECT) ? SS_DETECT : 0;
654 if (state.flags & SS_IOCARD)
655 state.csc_mask |= (power & I365_CSC_STSCHG) ? SS_STSCHG : 0;
656 else {
657 state.csc_mask |= (power & I365_CSC_BVD1) ? SS_BATDEAD : 0;
658 state.csc_mask |= (power & I365_CSC_BVD2) ? SS_BATWARN : 0;
659 state.csc_mask |= (power & I365_CSC_READY) ? SS_READY : 0;
660 }
661 debug ("i82365: GetStatus(0) = flags %#3.3x, Vcc %d, Vpp %d, "
662 "io_irq %d, csc_mask %#2.2x\n", state.flags,
663 state.Vcc, state.Vpp, state.io_irq, state.csc_mask);
664
665#else /* !CONFIG_CPC45 */
666
wdenke5d61c72003-05-18 11:30:09 +0000667 status = cb_readl (s, CB_SOCKET_STATE);
668 *value |= (status & CB_SS_32BIT) ? SS_CARDBUS : 0;
669 *value |= (status & CB_SS_3VCARD) ? SS_3VCARD : 0;
670 *value |= (status & CB_SS_XVCARD) ? SS_XVCARD : 0;
671 *value |= (status & CB_SS_VSENSE) ? 0 : SS_PENDING;
672 /* For now, ignore cards with unsupported voltage keys */
673 if (*value & SS_XVCARD)
674 *value &= ~(SS_DETECT | SS_3VCARD | SS_XVCARD);
wdenk54070ab2004-12-31 09:32:47 +0000675#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000676 return 0;
677} /* i365_get_status */
678
679static int i365_set_socket (socket_info_t * s, socket_state_t * state)
680{
681 u_char reg;
682
683 set_bridge_state (s);
684
685 /* IO card, RESET flag */
686 reg = 0;
687 reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET;
688 reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0;
689 i365_set (s, I365_INTCTL, reg);
690
wdenk54070ab2004-12-31 09:32:47 +0000691#ifdef CONFIG_CPC45
692 cb_set_power (s, state);
693
694#if 0
695 /* Card status change interrupt mask */
696 reg = s->cs_irq << 4;
697 if (state->csc_mask & SS_DETECT)
698 reg |= I365_CSC_DETECT;
699 if (state->flags & SS_IOCARD) {
700 if (state->csc_mask & SS_STSCHG)
701 reg |= I365_CSC_STSCHG;
702 } else {
703 if (state->csc_mask & SS_BATDEAD)
704 reg |= I365_CSC_BVD1;
705 if (state->csc_mask & SS_BATWARN)
706 reg |= I365_CSC_BVD2;
707 if (state->csc_mask & SS_READY)
708 reg |= I365_CSC_READY;
709 }
710 i365_set (s, I365_CSCINT, reg);
711 i365_get (s, I365_CSC);
712#endif /* 0 */
713
714#else /* !CONFIG_CPC45 */
715
wdenke5d61c72003-05-18 11:30:09 +0000716 reg = I365_PWR_NORESET;
717 if (state->flags & SS_PWR_AUTO)
718 reg |= I365_PWR_AUTO;
719 if (state->flags & SS_OUTPUT_ENA)
720 reg |= I365_PWR_OUT;
721
722 cb_set_power (s, state);
723 reg |= i365_get (s, I365_POWER) & (I365_VCC_MASK | I365_VPP1_MASK);
724
725 if (reg != i365_get (s, I365_POWER))
726 i365_set (s, I365_POWER, reg);
wdenk54070ab2004-12-31 09:32:47 +0000727#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000728
729 return 0;
730} /* i365_set_socket */
731
732/*====================================================================*/
733
734static int i365_set_mem_map (socket_info_t * s, struct pccard_mem_map *mem)
735{
736 u_short base, i;
737 u_char map;
738
wdenk54070ab2004-12-31 09:32:47 +0000739 debug ("i82365: SetMemMap(%d, %#2.2x, %d ns, %#5.5lx-%#5.5lx, %#5.5x)\n",
740 mem->map, mem->flags, mem->speed,
741 mem->sys_start, mem->sys_stop, mem->card_start);
742
wdenke5d61c72003-05-18 11:30:09 +0000743 map = mem->map;
744 if ((map > 4) ||
745 (mem->card_start > 0x3ffffff) ||
746 (mem->sys_start > mem->sys_stop) ||
747 (mem->speed > 1000)) {
748 return -1;
749 }
750
751 /* Turn off the window before changing anything */
752 if (i365_get (s, I365_ADDRWIN) & I365_ENA_MEM (map))
753 i365_bclr (s, I365_ADDRWIN, I365_ENA_MEM (map));
754
755 /* Take care of high byte, for PCI controllers */
756 i365_set (s, CB_MEM_PAGE (map), mem->sys_start >> 24);
757
758 base = I365_MEM (map);
759 i = (mem->sys_start >> 12) & 0x0fff;
760 if (mem->flags & MAP_16BIT)
761 i |= I365_MEM_16BIT;
762 if (mem->flags & MAP_0WS)
763 i |= I365_MEM_0WS;
764 i365_set_pair (s, base + I365_W_START, i);
765
766 i = (mem->sys_stop >> 12) & 0x0fff;
767 switch (mem->speed / CYCLE_TIME) {
768 case 0:
769 break;
770 case 1:
771 i |= I365_MEM_WS0;
772 break;
773 case 2:
774 i |= I365_MEM_WS1;
775 break;
776 default:
777 i |= I365_MEM_WS1 | I365_MEM_WS0;
778 break;
779 }
780 i365_set_pair (s, base + I365_W_STOP, i);
781
wdenk54070ab2004-12-31 09:32:47 +0000782#ifdef CONFIG_CPC45
783 i = 0;
784#else
wdenke5d61c72003-05-18 11:30:09 +0000785 i = ((mem->card_start - mem->sys_start) >> 12) & 0x3fff;
wdenk54070ab2004-12-31 09:32:47 +0000786#endif
wdenke5d61c72003-05-18 11:30:09 +0000787 if (mem->flags & MAP_WRPROT)
788 i |= I365_MEM_WRPROT;
789 if (mem->flags & MAP_ATTRIB)
790 i |= I365_MEM_REG;
791 i365_set_pair (s, base + I365_W_OFF, i);
792
wdenk54070ab2004-12-31 09:32:47 +0000793#ifdef CONFIG_CPC45
794 /* set System Memory map Upper Adress */
795 i365_set(s, PD67_EXT_INDEX, PD67_MEM_PAGE(map));
796 i365_set(s, PD67_EXT_DATA, ((mem->sys_start >> 24) & 0xff));
797#endif
798
wdenke5d61c72003-05-18 11:30:09 +0000799 /* Turn on the window if necessary */
800 if (mem->flags & MAP_ACTIVE)
801 i365_bset (s, I365_ADDRWIN, I365_ENA_MEM (map));
802 return 0;
803} /* i365_set_mem_map */
804
805static int i365_set_io_map (socket_info_t * s, struct pccard_io_map *io)
806{
807 u_char map, ioctl;
808
809 map = io->map;
wdenka0ebde52004-09-08 22:03:11 +0000810 /* comment out: comparison is always false due to limited range of data type */
811 if ((map > 1) || /* (io->start > 0xffff) || (io->stop > 0xffff) || */
wdenk54070ab2004-12-31 09:32:47 +0000812 (io->stop < io->start))
wdenke5d61c72003-05-18 11:30:09 +0000813 return -1;
814 /* Turn off the window before changing anything */
815 if (i365_get (s, I365_ADDRWIN) & I365_ENA_IO (map))
816 i365_bclr (s, I365_ADDRWIN, I365_ENA_IO (map));
817 i365_set_pair (s, I365_IO (map) + I365_W_START, io->start);
818 i365_set_pair (s, I365_IO (map) + I365_W_STOP, io->stop);
819 ioctl = i365_get (s, I365_IOCTL) & ~I365_IOCTL_MASK (map);
820 if (io->speed)
821 ioctl |= I365_IOCTL_WAIT (map);
822 if (io->flags & MAP_0WS)
823 ioctl |= I365_IOCTL_0WS (map);
824 if (io->flags & MAP_16BIT)
825 ioctl |= I365_IOCTL_16BIT (map);
826 if (io->flags & MAP_AUTOSZ)
827 ioctl |= I365_IOCTL_IOCS16 (map);
828 i365_set (s, I365_IOCTL, ioctl);
829 /* Turn on the window if necessary */
830 if (io->flags & MAP_ACTIVE)
831 i365_bset (s, I365_ADDRWIN, I365_ENA_IO (map));
832 return 0;
833} /* i365_set_io_map */
834
835/*====================================================================*/
836
837int i82365_init (void)
838{
839 u_int val;
840 int i;
841
wdenk54070ab2004-12-31 09:32:47 +0000842#ifdef CONFIG_CPC45
843 if (SPD67290Init () != 0)
844 return 1;
845#endif
wdenke5d61c72003-05-18 11:30:09 +0000846 if ((socket.dev = pci_find_devices (supported, 0)) < 0) {
847 /* Controller not found */
848 return 1;
849 }
wdenk54070ab2004-12-31 09:32:47 +0000850 debug ("i82365 Device Found!\n");
wdenke5d61c72003-05-18 11:30:09 +0000851
852 pci_read_config_dword (socket.dev, PCI_BASE_ADDRESS_0, &socket.cb_phys);
853 socket.cb_phys &= ~0xf;
854
wdenk54070ab2004-12-31 09:32:47 +0000855#ifdef CONFIG_CPC45
856 /* + 0xfe000000 see MPC 8245 Users Manual Adress Map B */
857 socket.cb_phys += 0xfe000000;
858#endif
859
wdenke5d61c72003-05-18 11:30:09 +0000860 get_bridge_state (&socket);
861 set_bridge_opts (&socket);
862
wdenk54070ab2004-12-31 09:32:47 +0000863 i = i365_get_status (&socket, &val);
wdenke5d61c72003-05-18 11:30:09 +0000864
wdenk54070ab2004-12-31 09:32:47 +0000865#ifdef CONFIG_CPC45
866 if (i > -1) {
867 puts (pcic[socket.type].name);
868 } else {
869 printf ("i82365: Controller not found.\n");
870 return 1;
871 }
wdenk81414462005-01-31 22:09:11 +0000872 if((val & SS_DETECT) != SS_DETECT){
873 puts ("No card\n");
874 return 1;
875 }
wdenk54070ab2004-12-31 09:32:47 +0000876#else /* !CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000877 if (val & SS_DETECT) {
878 if (val & SS_3VCARD) {
879 state.Vcc = state.Vpp = 33;
880 puts (" 3.3V card found: ");
881 } else if (!(val & SS_XVCARD)) {
882 state.Vcc = state.Vpp = 50;
883 puts (" 5.0V card found: ");
884 } else {
wdenk54070ab2004-12-31 09:32:47 +0000885 puts ("i82365: unsupported voltage key\n");
wdenke5d61c72003-05-18 11:30:09 +0000886 state.Vcc = state.Vpp = 0;
887 }
888 } else {
889 /* No card inserted */
wdenk54070ab2004-12-31 09:32:47 +0000890 puts ("No card\n");
wdenke5d61c72003-05-18 11:30:09 +0000891 return 1;
892 }
wdenk54070ab2004-12-31 09:32:47 +0000893#endif /* CONFIG_CPC45 */
wdenke5d61c72003-05-18 11:30:09 +0000894
wdenk54070ab2004-12-31 09:32:47 +0000895#ifdef CONFIG_CPC45
896 state.flags |= SS_OUTPUT_ENA;
897#else
wdenke5d61c72003-05-18 11:30:09 +0000898 state.flags = SS_IOCARD | SS_OUTPUT_ENA;
899 state.csc_mask = 0;
900 state.io_irq = 0;
wdenk54070ab2004-12-31 09:32:47 +0000901#endif
wdenke5d61c72003-05-18 11:30:09 +0000902
903 i365_set_socket (&socket, &state);
904
905 for (i = 500; i; i--) {
906 if ((i365_get (&socket, I365_STATUS) & I365_CS_READY))
907 break;
908 udelay (1000);
909 }
910
911 if (i == 0) {
912 /* PC Card not ready for data transfer */
wdenk54070ab2004-12-31 09:32:47 +0000913 puts ("i82365 PC Card not ready for data transfer\n");
wdenke5d61c72003-05-18 11:30:09 +0000914 return 1;
915 }
wdenk54070ab2004-12-31 09:32:47 +0000916 debug (" PC Card ready for data transfer: ");
wdenke5d61c72003-05-18 11:30:09 +0000917
918 mem.map = 0;
919 mem.flags = MAP_ATTRIB | MAP_ACTIVE;
920 mem.speed = 300;
921 mem.sys_start = CFG_PCMCIA_MEM_ADDR;
922 mem.sys_stop = CFG_PCMCIA_MEM_ADDR + CFG_PCMCIA_MEM_SIZE - 1;
923 mem.card_start = 0;
wdenk54070ab2004-12-31 09:32:47 +0000924 i365_set_mem_map (&socket, &mem);
wdenke5d61c72003-05-18 11:30:09 +0000925
wdenk54070ab2004-12-31 09:32:47 +0000926#ifdef CONFIG_CPC45
927 mem.map = 1;
928 mem.flags = MAP_ACTIVE;
929 mem.speed = 300;
930 mem.sys_start = CFG_PCMCIA_MEM_ADDR + CFG_PCMCIA_MEM_SIZE;
931 mem.sys_stop = CFG_PCMCIA_MEM_ADDR + (2 * CFG_PCMCIA_MEM_SIZE) - 1;
932 mem.card_start = 0;
wdenke5d61c72003-05-18 11:30:09 +0000933 i365_set_mem_map (&socket, &mem);
934
wdenk54070ab2004-12-31 09:32:47 +0000935#else /* !CONFIG_CPC45 */
936
wdenke5d61c72003-05-18 11:30:09 +0000937 io.map = 0;
938 io.flags = MAP_AUTOSZ | MAP_ACTIVE;
939 io.speed = 0;
940 io.start = 0x0100;
941 io.stop = 0x010F;
wdenke5d61c72003-05-18 11:30:09 +0000942 i365_set_io_map (&socket, &io);
943
wdenk54070ab2004-12-31 09:32:47 +0000944#endif /* CONFIG_CPC45 */
945
wdenke5d61c72003-05-18 11:30:09 +0000946#ifdef DEBUG
947 i82365_dump_regions (socket.dev);
948#endif
949
950 return 0;
951}
952
953void i82365_exit (void)
954{
955 io.map = 0;
956 io.flags = 0;
957 io.speed = 0;
958 io.start = 0;
959 io.stop = 0x1;
960
961 i365_set_io_map (&socket, &io);
962
963 mem.map = 0;
964 mem.flags = 0;
965 mem.speed = 0;
966 mem.sys_start = 0;
967 mem.sys_stop = 0x1000;
968 mem.card_start = 0;
969
970 i365_set_mem_map (&socket, &mem);
971
wdenk54070ab2004-12-31 09:32:47 +0000972#ifdef CONFIG_CPC45
973 mem.map = 1;
974 mem.flags = 0;
975 mem.speed = 0;
976 mem.sys_start = 0;
977 mem.sys_stop = 0x1000;
978 mem.card_start = 0;
wdenke5d61c72003-05-18 11:30:09 +0000979
wdenk54070ab2004-12-31 09:32:47 +0000980 i365_set_mem_map (&socket, &mem);
981#else /* !CONFIG_CPC45 */
982 socket.state.sysctl &= 0xFFFF00FF;
983#endif
wdenke5d61c72003-05-18 11:30:09 +0000984 state.Vcc = state.Vpp = 0;
985
986 i365_set_socket (&socket, &state);
987}
988
989/*======================================================================
990
991 Debug stuff
wdenk57b2d802003-06-27 21:31:46 +0000992
wdenke5d61c72003-05-18 11:30:09 +0000993======================================================================*/
994
995#ifdef DEBUG
996static void i82365_dump_regions (pci_dev_t dev)
997{
998 u_int tmp[2];
wdenk54070ab2004-12-31 09:32:47 +0000999 u_int *mem = (void *) socket.cb_phys;
wdenke5d61c72003-05-18 11:30:09 +00001000 u_char *cis = (void *) CFG_PCMCIA_MEM_ADDR;
1001 u_char *ide = (void *) (CFG_ATA_BASE_ADDR + CFG_ATA_REG_OFFSET);
1002
1003 pci_read_config_dword (dev, 0x00, tmp + 0);
1004 pci_read_config_dword (dev, 0x80, tmp + 1);
1005
wdenk525d7b62005-01-22 18:13:04 +00001006 printf ("PCI CONF: %08X ... %08X\n",
1007 tmp[0], tmp[1]);
1008 printf ("PCI MEM: ... %08X ... %08X\n",
1009 mem[0x8 / 4], mem[0x800 / 4]);
wdenke5d61c72003-05-18 11:30:09 +00001010 printf ("CIS: ...%c%c%c%c%c%c%c%c...\n",
1011 cis[0x38], cis[0x3a], cis[0x3c], cis[0x3e],
1012 cis[0x40], cis[0x42], cis[0x44], cis[0x48]);
1013 printf ("CIS CONF: %02X %02X %02X ...\n",
1014 cis[0x200], cis[0x202], cis[0x204]);
1015 printf ("IDE: %02X %02X %02X %02X %02X %02X %02X %02X\n",
1016 ide[0], ide[1], ide[2], ide[3],
1017 ide[4], ide[5], ide[6], ide[7]);
1018}
1019#endif /* DEBUG */
1020
1021#endif /* CONFIG_I82365 */