blob: 41b8d42b4c2a6872c051e4a0e5138ef77f7690a1 [file] [log] [blame]
wdenk66fd3d12003-05-18 11:30:09 +00001/*
wdenke2ffd592004-12-31 09:32:47 +00002 * (C) Copyright 2003-2004
wdenk66fd3d12003-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>
wdenk66fd3d12003-05-18 11:30:09 +000039#include <asm/io.h>
40
41#include <pcmcia/ss.h>
42#include <pcmcia/i82365.h>
wdenk66fd3d12003-05-18 11:30:09 +000043#include <pcmcia/yenta.h>
wdenke2ffd592004-12-31 09:32:47 +000044#ifdef CONFIG_CPC45
45#include <pcmcia/cirrus.h>
46#else
47#include <pcmcia/ti113x.h>
48#endif
wdenk66fd3d12003-05-18 11:30:09 +000049
50static struct pci_device_id supported[] = {
wdenke2ffd592004-12-31 09:32:47 +000051#ifdef CONFIG_CPC45
52 {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6729},
53#else
wdenk66fd3d12003-05-18 11:30:09 +000054 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510},
wdenke2ffd592004-12-31 09:32:47 +000055#endif
wdenk66fd3d12003-05-18 11:30:09 +000056 {0, 0}
57};
58
59#define CYCLE_TIME 120
60
wdenke2ffd592004-12-31 09:32:47 +000061#ifdef CONFIG_CPC45
62extern int SPD67290Init (void);
63#endif
64
wdenk66fd3d12003-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 {
wdenke2ffd592004-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;
wdenk66fd3d12003-05-18 11:30:09 +000074
wdenke2ffd592004-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
wdenk66fd3d12003-05-18 11:30:09 +000083} socket_info_t;
84
wdenke2ffd592004-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
wdenk66fd3d12003-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}
wdenke2ffd592004-12-31 09:32:47 +0000127#ifndef CONFIG_CPC45
wdenk66fd3d12003-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}
wdenke2ffd592004-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;
152
153#ifdef CONFIG_PCMCIA_SLOT_A
154 int slot = 0;
155#else
156 int slot = 1;
157#endif
158
159 val = I365_REG (slot, reg);
160
161 cb_writeb (s, val);
162 val = cb_readb (s);
163
164 debug ("i365_get slot:%x reg: %x val: %x\n", slot, reg, val);
165 return val;
166}
167
168static void i365_set (socket_info_t * s, u_short reg, u_char data)
169{
170#ifdef CONFIG_PCMCIA_SLOT_A
171 int slot = 0;
172#else
173 int slot = 1;
174#endif
175
176 u_char val = I365_REG (slot, reg);
177
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 */
wdenk66fd3d12003-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
wdenk66fd3d12003-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}
wdenke2ffd592004-12-31 09:32:47 +0000200#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-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
wdenke2ffd592004-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;
277
278#if DEBUG
279 char buf[200];
280
281 memset (buf, 0, 200);
282#endif
283
284 if (has_ring == -1)
285 has_ring = 1;
286 flip (p->misc2, PD67_MC2_IRQ15_RI, has_ring);
287 flip (p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode);
288#if DEBUG
289 if (p->misc2 & PD67_MC2_IRQ15_RI)
290 strcat (buf, " [ring]");
291 if (p->misc2 & PD67_MC2_DYNAMIC_MODE)
292 strcat (buf, " [dyn mode]");
293 if (p->misc1 & PD67_MC1_INPACK_ENA)
294 strcat (buf, " [inpack]");
295#endif
296
297 if (p->misc2 & PD67_MC2_IRQ15_RI)
298 mask &= ~0x8000;
299 if (has_led > 0) {
300#if DEBUG
301 strcat (buf, " [led]");
302#endif
303 mask &= ~0x1000;
304 }
305 if (has_dma > 0) {
306#if DEBUG
307 strcat (buf, " [dma]");
308#endif
309 mask &= ~0x0600;
310 flip (p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass);
311#if DEBUG
312 if (p->misc2 & PD67_MC2_FREQ_BYPASS)
313 strcat (buf, " [freq bypass]");
314#endif
315 }
316
317 if (setup_time >= 0)
318 p->timer[0] = p->timer[3] = setup_time;
319 if (cmd_time > 0) {
320 p->timer[1] = cmd_time;
321 p->timer[4] = cmd_time * 2 + 4;
322 }
323 if (p->timer[1] == 0) {
324 p->timer[1] = 6;
325 p->timer[4] = 16;
326 if (p->timer[0] == 0)
327 p->timer[0] = p->timer[3] = 1;
328 }
329 if (recov_time >= 0)
330 p->timer[2] = p->timer[5] = recov_time;
331
332 debug ("i82365 Opt: %s [%d/%d/%d] [%d/%d/%d]\n",
333 buf,
334 p->timer[0], p->timer[1], p->timer[2],
335 p->timer[3], p->timer[4], p->timer[5]);
336
337 return mask;
338}
339
340#else /* !CONFIG_CPC45 */
341
wdenk66fd3d12003-05-18 11:30:09 +0000342/*======================================================================
343
344 Code to save and restore global state information for TI 1130 and
345 TI 1131 controllers, and to set and report global configuration
346 options.
wdenk8bde7f72003-06-27 21:31:46 +0000347
wdenk66fd3d12003-05-18 11:30:09 +0000348======================================================================*/
349
350static void ti113x_get_state (socket_info_t * s)
351{
352 ti113x_state_t *p = &s->state;
353
354 pci_readl (s, TI113X_SYSTEM_CONTROL, &p->sysctl);
355 pci_readb (s, TI113X_CARD_CONTROL, &p->cardctl);
356 pci_readb (s, TI113X_DEVICE_CONTROL, &p->devctl);
357 pci_readb (s, TI1250_DIAGNOSTIC, &p->diag);
358 pci_readl (s, TI12XX_IRQMUX, &p->irqmux);
359}
360
361static void ti113x_set_state (socket_info_t * s)
362{
363 ti113x_state_t *p = &s->state;
364
365 pci_writel (s, TI113X_SYSTEM_CONTROL, p->sysctl);
366 pci_writeb (s, TI113X_CARD_CONTROL, p->cardctl);
367 pci_writeb (s, TI113X_DEVICE_CONTROL, p->devctl);
368 pci_writeb (s, TI1250_MULTIMEDIA_CTL, 0);
369 pci_writeb (s, TI1250_DIAGNOSTIC, p->diag);
370 pci_writel (s, TI12XX_IRQMUX, p->irqmux);
371 i365_set_pair (s, TI113X_IO_OFFSET (0), 0);
372 i365_set_pair (s, TI113X_IO_OFFSET (1), 0);
373}
374
375static u_int ti113x_set_opts (socket_info_t * s)
376{
377 ti113x_state_t *p = &s->state;
378 u_int mask = 0xffff;
379
380 p->cardctl &= ~TI113X_CCR_ZVENABLE;
381 p->cardctl |= TI113X_CCR_SPKROUTEN;
382
383 return mask;
384}
wdenke2ffd592004-12-31 09:32:47 +0000385#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000386
387/*======================================================================
388
389 Routines to handle common CardBus options
wdenk8bde7f72003-06-27 21:31:46 +0000390
wdenk66fd3d12003-05-18 11:30:09 +0000391======================================================================*/
392
393/* Default settings for PCI command configuration register */
394#define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \
395 PCI_COMMAND_MASTER|PCI_COMMAND_WAIT)
396
397static void cb_get_state (socket_info_t * s)
398{
399 pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache);
400 pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat);
401 pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat);
402 pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus);
403 pci_readb (s, CB_SUBORD_BUS, &s->sub_bus);
404 pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr);
405}
406
407static void cb_set_state (socket_info_t * s)
408{
wdenke2ffd592004-12-31 09:32:47 +0000409#ifndef CONFIG_CPC45
wdenk66fd3d12003-05-18 11:30:09 +0000410 pci_writel (s, CB_LEGACY_MODE_BASE, 0);
411 pci_writel (s, PCI_BASE_ADDRESS_0, s->cb_phys);
wdenke2ffd592004-12-31 09:32:47 +0000412#endif
wdenk66fd3d12003-05-18 11:30:09 +0000413 pci_writew (s, PCI_COMMAND, CMD_DFLT);
414 pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache);
415 pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat);
416 pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat);
417 pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus);
418 pci_writeb (s, CB_SUBORD_BUS, s->sub_bus);
419 pci_writew (s, CB_BRIDGE_CONTROL, s->bcr);
420}
421
422static void cb_set_opts (socket_info_t * s)
423{
wdenke2ffd592004-12-31 09:32:47 +0000424#ifndef CONFIG_CPC45
wdenk66fd3d12003-05-18 11:30:09 +0000425 if (s->cache == 0)
426 s->cache = 8;
427 if (s->pci_lat == 0)
428 s->pci_lat = 0xa8;
429 if (s->cb_lat == 0)
430 s->cb_lat = 0xb0;
wdenke2ffd592004-12-31 09:32:47 +0000431#endif
wdenk66fd3d12003-05-18 11:30:09 +0000432}
433
434/*======================================================================
435
436 Power control for Cardbus controllers: used both for 16-bit and
437 Cardbus cards.
wdenk8bde7f72003-06-27 21:31:46 +0000438
wdenk66fd3d12003-05-18 11:30:09 +0000439======================================================================*/
440
441static int cb_set_power (socket_info_t * s, socket_state_t * state)
442{
443 u_int reg = 0;
444
wdenke2ffd592004-12-31 09:32:47 +0000445#ifdef CONFIG_CPC45
446
447 if ((state->Vcc == 0) && (state->Vpp == 0)) {
448 u_char power, vcc, vpp;
449
450 power = i365_get (s, I365_POWER);
451 state->flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0;
452 state->flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0;
453 vcc = power & I365_VCC_MASK;
454 vpp = power & I365_VPP1_MASK;
455 state->Vcc = state->Vpp = 0;
456 if (i365_get (s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) {
457 if (power & I365_VCC_5V)
458 state->Vcc = 33;
459 if (vpp == I365_VPP1_5V)
460 state->Vpp = 33;
461 } else {
462 if (power & I365_VCC_5V)
463 state->Vcc = 50;
464 if (vpp == I365_VPP1_5V)
465 state->Vpp = 50;
466 }
467 if (power == I365_VPP1_12V)
468 state->Vpp = 120;
469 printf ("POWER Vcc:%d Vpp: %d\n", state->Vcc, state->Vpp);
470 }
471
472 reg = I365_PWR_NORESET;
473 if (state->flags & SS_PWR_AUTO)
474 reg |= I365_PWR_AUTO;
475 if (state->flags & SS_OUTPUT_ENA)
476 reg |= I365_PWR_OUT;
477 if (state->Vpp != 0) {
478 if (state->Vpp == 120) {
479 reg |= I365_VPP1_12V;
480 puts (" 12V card found: ");
481 } else if (state->Vpp == state->Vcc) {
482 reg |= I365_VPP1_5V;
483 puts (" 5V card found: ");
484 } else {
485 puts (" power not found: ");
486 return -1;
487 }
488 }
489 if (state->Vcc != 0) {
490 reg |= I365_VCC_5V;
491 if (state->Vcc == 33) {
492 puts (" 3.3V card found: ");
493 i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
494 } else if (state->Vcc == 50) {
495 puts (" 5V card found: ");
496 i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
497 } else {
498 puts (" power not found: ");
499 return -1;
500 }
501 }
502 if (reg != i365_get (s, I365_POWER))
503 i365_set (s, I365_POWER, reg);
504
505#else /* ! CONFIG_CPC45 */
506
wdenk66fd3d12003-05-18 11:30:09 +0000507 /* restart card voltage detection if it seems appropriate */
508 if ((state->Vcc == 0) && (state->Vpp == 0) &&
wdenke2ffd592004-12-31 09:32:47 +0000509 !(cb_readl (s, CB_SOCKET_STATE) & CB_SS_VSENSE))
wdenk66fd3d12003-05-18 11:30:09 +0000510 cb_writel (s, CB_SOCKET_FORCE, CB_SF_CVSTEST);
511 switch (state->Vcc) {
512 case 0:
513 reg = 0;
514 break;
515 case 33:
516 reg = CB_SC_VCC_3V;
517 break;
518 case 50:
519 reg = CB_SC_VCC_5V;
520 break;
521 default:
522 return -1;
523 }
524 switch (state->Vpp) {
525 case 0:
526 break;
527 case 33:
528 reg |= CB_SC_VPP_3V;
529 break;
530 case 50:
531 reg |= CB_SC_VPP_5V;
532 break;
533 case 120:
534 reg |= CB_SC_VPP_12V;
535 break;
536 default:
537 return -1;
538 }
539 if (reg != cb_readl (s, CB_SOCKET_CONTROL))
540 cb_writel (s, CB_SOCKET_CONTROL, reg);
wdenke2ffd592004-12-31 09:32:47 +0000541#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000542 return 0;
543}
544
545/*======================================================================
546
547 Generic routines to get and set controller options
wdenk8bde7f72003-06-27 21:31:46 +0000548
wdenk66fd3d12003-05-18 11:30:09 +0000549======================================================================*/
550
551static void get_bridge_state (socket_info_t * s)
552{
wdenke2ffd592004-12-31 09:32:47 +0000553#ifdef CONFIG_CPC45
554 cirrus_get_state (s);
555#else
wdenk66fd3d12003-05-18 11:30:09 +0000556 ti113x_get_state (s);
wdenke2ffd592004-12-31 09:32:47 +0000557#endif
wdenk66fd3d12003-05-18 11:30:09 +0000558 cb_get_state (s);
559}
560
561static void set_bridge_state (socket_info_t * s)
562{
563 cb_set_state (s);
564 i365_set (s, I365_GBLCTL, 0x00);
565 i365_set (s, I365_GENCTL, 0x00);
wdenke2ffd592004-12-31 09:32:47 +0000566#ifdef CONFIG_CPC45
567 cirrus_set_state (s);
568#else
wdenk66fd3d12003-05-18 11:30:09 +0000569 ti113x_set_state (s);
wdenke2ffd592004-12-31 09:32:47 +0000570#endif
wdenk66fd3d12003-05-18 11:30:09 +0000571}
572
573static void set_bridge_opts (socket_info_t * s)
574{
wdenke2ffd592004-12-31 09:32:47 +0000575#ifdef CONFIG_CPC45
576 cirrus_set_opts (s);
577#else
wdenk66fd3d12003-05-18 11:30:09 +0000578 ti113x_set_opts (s);
wdenke2ffd592004-12-31 09:32:47 +0000579#endif
wdenk66fd3d12003-05-18 11:30:09 +0000580 cb_set_opts (s);
581}
582
583/*====================================================================*/
584
585static int i365_get_status (socket_info_t * s, u_int * value)
586{
587 u_int status;
588
wdenke2ffd592004-12-31 09:32:47 +0000589#ifdef CONFIG_CPC45
590 u_char val;
591 u_char power, vcc, vpp;
592#endif
593
594 status = i365_get (s, I365_IDENT);
wdenk66fd3d12003-05-18 11:30:09 +0000595 status = i365_get (s, I365_STATUS);
596 *value = ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0;
597 if (i365_get (s, I365_INTCTL) & I365_PC_IOCARD) {
598 *value |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG;
599 } else {
600 *value |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD;
601 *value |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN;
602 }
603 *value |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0;
604 *value |= (status & I365_CS_READY) ? SS_READY : 0;
605 *value |= (status & I365_CS_POWERON) ? SS_POWERON : 0;
606
wdenke2ffd592004-12-31 09:32:47 +0000607#ifdef CONFIG_CPC45
608 /* Check for Cirrus CL-PD67xx chips */
609 i365_set (s, PD67_CHIP_INFO, 0);
610 val = i365_get (s, PD67_CHIP_INFO);
611 s->type = -1;
612 if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
613 val = i365_get (s, PD67_CHIP_INFO);
614 if ((val & PD67_INFO_CHIP_ID) == 0) {
615 s->type =
616 (val & PD67_INFO_SLOTS) ? IS_PD672X :
617 IS_PD6710;
618 i365_set (s, PD67_EXT_INDEX, 0xe5);
619 if (i365_get (s, PD67_EXT_INDEX) != 0xe5)
620 s->type = IS_VT83C469;
621 }
622 } else {
623 printf ("no Cirrus Chip found\n");
624 *value = 0;
625 return -1;
626 }
627
628 i365_bset (s, I365_POWER, I365_VCC_5V);
629 power = i365_get (s, I365_POWER);
630 state.flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0;
631 state.flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0;
632 vcc = power & I365_VCC_MASK;
633 vpp = power & I365_VPP1_MASK;
634 state.Vcc = state.Vpp = 0;
635 if (i365_get (s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) {
636 if (power & I365_VCC_5V)
637 state.Vcc = 33;
638 if (vpp == I365_VPP1_5V)
639 state.Vpp = 33;
640 } else {
641 if (power & I365_VCC_5V)
642 state.Vcc = 50;
643 if (vpp == I365_VPP1_5V)
644 state.Vpp = 50;
645 }
646 if (power == I365_VPP1_12V)
647 state.Vpp = 120;
648
649 /* IO card, RESET flags, IO interrupt */
650 power = i365_get (s, I365_INTCTL);
651 state.flags |= (power & I365_PC_RESET) ? 0 : SS_RESET;
652 if (power & I365_PC_IOCARD)
653 state.flags |= SS_IOCARD;
654 state.io_irq = power & I365_IRQ_MASK;
655
656 /* Card status change mask */
657 power = i365_get (s, I365_CSCINT);
658 state.csc_mask = (power & I365_CSC_DETECT) ? SS_DETECT : 0;
659 if (state.flags & SS_IOCARD)
660 state.csc_mask |= (power & I365_CSC_STSCHG) ? SS_STSCHG : 0;
661 else {
662 state.csc_mask |= (power & I365_CSC_BVD1) ? SS_BATDEAD : 0;
663 state.csc_mask |= (power & I365_CSC_BVD2) ? SS_BATWARN : 0;
664 state.csc_mask |= (power & I365_CSC_READY) ? SS_READY : 0;
665 }
666 debug ("i82365: GetStatus(0) = flags %#3.3x, Vcc %d, Vpp %d, "
667 "io_irq %d, csc_mask %#2.2x\n", state.flags,
668 state.Vcc, state.Vpp, state.io_irq, state.csc_mask);
669
670#else /* !CONFIG_CPC45 */
671
wdenk66fd3d12003-05-18 11:30:09 +0000672 status = cb_readl (s, CB_SOCKET_STATE);
673 *value |= (status & CB_SS_32BIT) ? SS_CARDBUS : 0;
674 *value |= (status & CB_SS_3VCARD) ? SS_3VCARD : 0;
675 *value |= (status & CB_SS_XVCARD) ? SS_XVCARD : 0;
676 *value |= (status & CB_SS_VSENSE) ? 0 : SS_PENDING;
677 /* For now, ignore cards with unsupported voltage keys */
678 if (*value & SS_XVCARD)
679 *value &= ~(SS_DETECT | SS_3VCARD | SS_XVCARD);
wdenke2ffd592004-12-31 09:32:47 +0000680#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000681 return 0;
682} /* i365_get_status */
683
684static int i365_set_socket (socket_info_t * s, socket_state_t * state)
685{
686 u_char reg;
687
688 set_bridge_state (s);
689
690 /* IO card, RESET flag */
691 reg = 0;
692 reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET;
693 reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0;
694 i365_set (s, I365_INTCTL, reg);
695
wdenke2ffd592004-12-31 09:32:47 +0000696#ifdef CONFIG_CPC45
697 cb_set_power (s, state);
698
699#if 0
700 /* Card status change interrupt mask */
701 reg = s->cs_irq << 4;
702 if (state->csc_mask & SS_DETECT)
703 reg |= I365_CSC_DETECT;
704 if (state->flags & SS_IOCARD) {
705 if (state->csc_mask & SS_STSCHG)
706 reg |= I365_CSC_STSCHG;
707 } else {
708 if (state->csc_mask & SS_BATDEAD)
709 reg |= I365_CSC_BVD1;
710 if (state->csc_mask & SS_BATWARN)
711 reg |= I365_CSC_BVD2;
712 if (state->csc_mask & SS_READY)
713 reg |= I365_CSC_READY;
714 }
715 i365_set (s, I365_CSCINT, reg);
716 i365_get (s, I365_CSC);
717#endif /* 0 */
718
719#else /* !CONFIG_CPC45 */
720
wdenk66fd3d12003-05-18 11:30:09 +0000721 reg = I365_PWR_NORESET;
722 if (state->flags & SS_PWR_AUTO)
723 reg |= I365_PWR_AUTO;
724 if (state->flags & SS_OUTPUT_ENA)
725 reg |= I365_PWR_OUT;
726
727 cb_set_power (s, state);
728 reg |= i365_get (s, I365_POWER) & (I365_VCC_MASK | I365_VPP1_MASK);
729
730 if (reg != i365_get (s, I365_POWER))
731 i365_set (s, I365_POWER, reg);
wdenke2ffd592004-12-31 09:32:47 +0000732#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000733
734 return 0;
735} /* i365_set_socket */
736
737/*====================================================================*/
738
739static int i365_set_mem_map (socket_info_t * s, struct pccard_mem_map *mem)
740{
741 u_short base, i;
742 u_char map;
743
wdenke2ffd592004-12-31 09:32:47 +0000744 debug ("i82365: SetMemMap(%d, %#2.2x, %d ns, %#5.5lx-%#5.5lx, %#5.5x)\n",
745 mem->map, mem->flags, mem->speed,
746 mem->sys_start, mem->sys_stop, mem->card_start);
747
wdenk66fd3d12003-05-18 11:30:09 +0000748 map = mem->map;
749 if ((map > 4) ||
750 (mem->card_start > 0x3ffffff) ||
751 (mem->sys_start > mem->sys_stop) ||
752 (mem->speed > 1000)) {
753 return -1;
754 }
755
756 /* Turn off the window before changing anything */
757 if (i365_get (s, I365_ADDRWIN) & I365_ENA_MEM (map))
758 i365_bclr (s, I365_ADDRWIN, I365_ENA_MEM (map));
759
760 /* Take care of high byte, for PCI controllers */
761 i365_set (s, CB_MEM_PAGE (map), mem->sys_start >> 24);
762
763 base = I365_MEM (map);
764 i = (mem->sys_start >> 12) & 0x0fff;
765 if (mem->flags & MAP_16BIT)
766 i |= I365_MEM_16BIT;
767 if (mem->flags & MAP_0WS)
768 i |= I365_MEM_0WS;
769 i365_set_pair (s, base + I365_W_START, i);
770
771 i = (mem->sys_stop >> 12) & 0x0fff;
772 switch (mem->speed / CYCLE_TIME) {
773 case 0:
774 break;
775 case 1:
776 i |= I365_MEM_WS0;
777 break;
778 case 2:
779 i |= I365_MEM_WS1;
780 break;
781 default:
782 i |= I365_MEM_WS1 | I365_MEM_WS0;
783 break;
784 }
785 i365_set_pair (s, base + I365_W_STOP, i);
786
wdenke2ffd592004-12-31 09:32:47 +0000787#ifdef CONFIG_CPC45
788 i = 0;
789#else
wdenk66fd3d12003-05-18 11:30:09 +0000790 i = ((mem->card_start - mem->sys_start) >> 12) & 0x3fff;
wdenke2ffd592004-12-31 09:32:47 +0000791#endif
wdenk66fd3d12003-05-18 11:30:09 +0000792 if (mem->flags & MAP_WRPROT)
793 i |= I365_MEM_WRPROT;
794 if (mem->flags & MAP_ATTRIB)
795 i |= I365_MEM_REG;
796 i365_set_pair (s, base + I365_W_OFF, i);
797
wdenke2ffd592004-12-31 09:32:47 +0000798#ifdef CONFIG_CPC45
799 /* set System Memory map Upper Adress */
800 i365_set(s, PD67_EXT_INDEX, PD67_MEM_PAGE(map));
801 i365_set(s, PD67_EXT_DATA, ((mem->sys_start >> 24) & 0xff));
802#endif
803
wdenk66fd3d12003-05-18 11:30:09 +0000804 /* Turn on the window if necessary */
805 if (mem->flags & MAP_ACTIVE)
806 i365_bset (s, I365_ADDRWIN, I365_ENA_MEM (map));
807 return 0;
808} /* i365_set_mem_map */
809
810static int i365_set_io_map (socket_info_t * s, struct pccard_io_map *io)
811{
812 u_char map, ioctl;
813
814 map = io->map;
wdenkeedcd072004-09-08 22:03:11 +0000815 /* comment out: comparison is always false due to limited range of data type */
816 if ((map > 1) || /* (io->start > 0xffff) || (io->stop > 0xffff) || */
wdenke2ffd592004-12-31 09:32:47 +0000817 (io->stop < io->start))
wdenk66fd3d12003-05-18 11:30:09 +0000818 return -1;
819 /* Turn off the window before changing anything */
820 if (i365_get (s, I365_ADDRWIN) & I365_ENA_IO (map))
821 i365_bclr (s, I365_ADDRWIN, I365_ENA_IO (map));
822 i365_set_pair (s, I365_IO (map) + I365_W_START, io->start);
823 i365_set_pair (s, I365_IO (map) + I365_W_STOP, io->stop);
824 ioctl = i365_get (s, I365_IOCTL) & ~I365_IOCTL_MASK (map);
825 if (io->speed)
826 ioctl |= I365_IOCTL_WAIT (map);
827 if (io->flags & MAP_0WS)
828 ioctl |= I365_IOCTL_0WS (map);
829 if (io->flags & MAP_16BIT)
830 ioctl |= I365_IOCTL_16BIT (map);
831 if (io->flags & MAP_AUTOSZ)
832 ioctl |= I365_IOCTL_IOCS16 (map);
833 i365_set (s, I365_IOCTL, ioctl);
834 /* Turn on the window if necessary */
835 if (io->flags & MAP_ACTIVE)
836 i365_bset (s, I365_ADDRWIN, I365_ENA_IO (map));
837 return 0;
838} /* i365_set_io_map */
839
840/*====================================================================*/
841
842int i82365_init (void)
843{
844 u_int val;
845 int i;
846
wdenke2ffd592004-12-31 09:32:47 +0000847#ifdef CONFIG_CPC45
848 if (SPD67290Init () != 0)
849 return 1;
850#endif
wdenk66fd3d12003-05-18 11:30:09 +0000851 if ((socket.dev = pci_find_devices (supported, 0)) < 0) {
852 /* Controller not found */
853 return 1;
854 }
wdenke2ffd592004-12-31 09:32:47 +0000855 debug ("i82365 Device Found!\n");
wdenk66fd3d12003-05-18 11:30:09 +0000856
857 pci_read_config_dword (socket.dev, PCI_BASE_ADDRESS_0, &socket.cb_phys);
858 socket.cb_phys &= ~0xf;
859
wdenke2ffd592004-12-31 09:32:47 +0000860#ifdef CONFIG_CPC45
861 /* + 0xfe000000 see MPC 8245 Users Manual Adress Map B */
862 socket.cb_phys += 0xfe000000;
863#endif
864
wdenk66fd3d12003-05-18 11:30:09 +0000865 get_bridge_state (&socket);
866 set_bridge_opts (&socket);
867
wdenke2ffd592004-12-31 09:32:47 +0000868 i = i365_get_status (&socket, &val);
wdenk66fd3d12003-05-18 11:30:09 +0000869
wdenke2ffd592004-12-31 09:32:47 +0000870#ifdef CONFIG_CPC45
871 if (i > -1) {
872 puts (pcic[socket.type].name);
873 } else {
874 printf ("i82365: Controller not found.\n");
875 return 1;
876 }
877#else /* !CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000878 if (val & SS_DETECT) {
879 if (val & SS_3VCARD) {
880 state.Vcc = state.Vpp = 33;
881 puts (" 3.3V card found: ");
882 } else if (!(val & SS_XVCARD)) {
883 state.Vcc = state.Vpp = 50;
884 puts (" 5.0V card found: ");
885 } else {
wdenke2ffd592004-12-31 09:32:47 +0000886 puts ("i82365: unsupported voltage key\n");
wdenk66fd3d12003-05-18 11:30:09 +0000887 state.Vcc = state.Vpp = 0;
888 }
889 } else {
890 /* No card inserted */
wdenke2ffd592004-12-31 09:32:47 +0000891 puts ("No card\n");
wdenk66fd3d12003-05-18 11:30:09 +0000892 return 1;
893 }
wdenke2ffd592004-12-31 09:32:47 +0000894#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000895
wdenke2ffd592004-12-31 09:32:47 +0000896#ifdef CONFIG_CPC45
897 state.flags |= SS_OUTPUT_ENA;
898#else
wdenk66fd3d12003-05-18 11:30:09 +0000899 state.flags = SS_IOCARD | SS_OUTPUT_ENA;
900 state.csc_mask = 0;
901 state.io_irq = 0;
wdenke2ffd592004-12-31 09:32:47 +0000902#endif
wdenk66fd3d12003-05-18 11:30:09 +0000903
904 i365_set_socket (&socket, &state);
905
906 for (i = 500; i; i--) {
907 if ((i365_get (&socket, I365_STATUS) & I365_CS_READY))
908 break;
909 udelay (1000);
910 }
911
912 if (i == 0) {
913 /* PC Card not ready for data transfer */
wdenke2ffd592004-12-31 09:32:47 +0000914 puts ("i82365 PC Card not ready for data transfer\n");
wdenk66fd3d12003-05-18 11:30:09 +0000915 return 1;
916 }
wdenke2ffd592004-12-31 09:32:47 +0000917 debug (" PC Card ready for data transfer: ");
wdenk66fd3d12003-05-18 11:30:09 +0000918
919 mem.map = 0;
920 mem.flags = MAP_ATTRIB | MAP_ACTIVE;
921 mem.speed = 300;
922 mem.sys_start = CFG_PCMCIA_MEM_ADDR;
923 mem.sys_stop = CFG_PCMCIA_MEM_ADDR + CFG_PCMCIA_MEM_SIZE - 1;
924 mem.card_start = 0;
wdenk66fd3d12003-05-18 11:30:09 +0000925 i365_set_mem_map (&socket, &mem);
926
wdenke2ffd592004-12-31 09:32:47 +0000927#ifdef CONFIG_CPC45
928 mem.map = 1;
929 mem.flags = MAP_ACTIVE;
930 mem.speed = 300;
931 mem.sys_start = CFG_PCMCIA_MEM_ADDR + CFG_PCMCIA_MEM_SIZE;
932 mem.sys_stop = CFG_PCMCIA_MEM_ADDR + (2 * CFG_PCMCIA_MEM_SIZE) - 1;
933 mem.card_start = 0;
934 i365_set_mem_map (&socket, &mem);
935
936#else /* !CONFIG_CPC45 */
937
wdenk66fd3d12003-05-18 11:30:09 +0000938 io.map = 0;
939 io.flags = MAP_AUTOSZ | MAP_ACTIVE;
940 io.speed = 0;
941 io.start = 0x0100;
942 io.stop = 0x010F;
wdenk66fd3d12003-05-18 11:30:09 +0000943 i365_set_io_map (&socket, &io);
944
wdenke2ffd592004-12-31 09:32:47 +0000945#endif /* CONFIG_CPC45 */
946
wdenk66fd3d12003-05-18 11:30:09 +0000947#ifdef DEBUG
948 i82365_dump_regions (socket.dev);
949#endif
950
951 return 0;
952}
953
954void i82365_exit (void)
955{
956 io.map = 0;
957 io.flags = 0;
958 io.speed = 0;
959 io.start = 0;
960 io.stop = 0x1;
961
962 i365_set_io_map (&socket, &io);
963
964 mem.map = 0;
965 mem.flags = 0;
966 mem.speed = 0;
967 mem.sys_start = 0;
968 mem.sys_stop = 0x1000;
969 mem.card_start = 0;
970
971 i365_set_mem_map (&socket, &mem);
972
wdenke2ffd592004-12-31 09:32:47 +0000973#ifdef CONFIG_CPC45
974 mem.map = 1;
975 mem.flags = 0;
976 mem.speed = 0;
977 mem.sys_start = 0;
978 mem.sys_stop = 0x1000;
979 mem.card_start = 0;
wdenk66fd3d12003-05-18 11:30:09 +0000980
wdenke2ffd592004-12-31 09:32:47 +0000981 i365_set_mem_map (&socket, &mem);
982#else /* !CONFIG_CPC45 */
983 socket.state.sysctl &= 0xFFFF00FF;
984#endif
wdenk66fd3d12003-05-18 11:30:09 +0000985 state.Vcc = state.Vpp = 0;
986
987 i365_set_socket (&socket, &state);
988}
989
990/*======================================================================
991
992 Debug stuff
wdenk8bde7f72003-06-27 21:31:46 +0000993
wdenk66fd3d12003-05-18 11:30:09 +0000994======================================================================*/
995
996#ifdef DEBUG
997static void i82365_dump_regions (pci_dev_t dev)
998{
999 u_int tmp[2];
wdenke2ffd592004-12-31 09:32:47 +00001000 u_int *mem = (void *) socket.cb_phys;
wdenk66fd3d12003-05-18 11:30:09 +00001001 u_char *cis = (void *) CFG_PCMCIA_MEM_ADDR;
1002 u_char *ide = (void *) (CFG_ATA_BASE_ADDR + CFG_ATA_REG_OFFSET);
1003
1004 pci_read_config_dword (dev, 0x00, tmp + 0);
1005 pci_read_config_dword (dev, 0x80, tmp + 1);
1006
1007 printf ("PCI CONF: %08X ... %08X\n", tmp[0], tmp[1]);
1008 printf ("PCI MEM: ... %08X ... %08X\n", mem[0x8 / 4], mem[0x800 / 4]);
1009 printf ("CIS: ...%c%c%c%c%c%c%c%c...\n",
1010 cis[0x38], cis[0x3a], cis[0x3c], cis[0x3e],
1011 cis[0x40], cis[0x42], cis[0x44], cis[0x48]);
1012 printf ("CIS CONF: %02X %02X %02X ...\n",
1013 cis[0x200], cis[0x202], cis[0x204]);
1014 printf ("IDE: %02X %02X %02X %02X %02X %02X %02X %02X\n",
1015 ide[0], ide[1], ide[2], ide[3],
1016 ide[4], ide[5], ide[6], ide[7]);
1017}
1018#endif /* DEBUG */
1019
1020#endif /* CONFIG_I82365 */