blob: 1cde83a763257126dcad35323138fd6d7e2ccb0b [file] [log] [blame]
wdenk66fd3d12003-05-18 11:30:09 +00001/*
wdenke799d372005-02-07 19:44:17 +00002 * (C) Copyright 2003-2005
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
wdenk66fd3d12003-05-18 11:30:09 +000034#include <command.h>
35#include <pci.h>
36#include <pcmcia.h>
wdenk66fd3d12003-05-18 11:30:09 +000037#include <asm/io.h>
38
39#include <pcmcia/ss.h>
40#include <pcmcia/i82365.h>
wdenk66fd3d12003-05-18 11:30:09 +000041#include <pcmcia/yenta.h>
wdenke2ffd592004-12-31 09:32:47 +000042#ifdef CONFIG_CPC45
43#include <pcmcia/cirrus.h>
44#else
45#include <pcmcia/ti113x.h>
46#endif
wdenk66fd3d12003-05-18 11:30:09 +000047
48static struct pci_device_id supported[] = {
wdenke2ffd592004-12-31 09:32:47 +000049#ifdef CONFIG_CPC45
50 {PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6729},
51#else
wdenk66fd3d12003-05-18 11:30:09 +000052 {PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510},
wdenke2ffd592004-12-31 09:32:47 +000053#endif
wdenk66fd3d12003-05-18 11:30:09 +000054 {0, 0}
55};
56
57#define CYCLE_TIME 120
58
wdenke2ffd592004-12-31 09:32:47 +000059#ifdef CONFIG_CPC45
60extern int SPD67290Init (void);
61#endif
62
wdenk66fd3d12003-05-18 11:30:09 +000063#ifdef DEBUG
64static void i82365_dump_regions (pci_dev_t dev);
65#endif
66
67typedef struct socket_info_t {
wdenke2ffd592004-12-31 09:32:47 +000068 pci_dev_t dev;
69 u_short bcr;
70 u_char pci_lat, cb_lat, sub_bus, cache;
71 u_int cb_phys;
wdenk66fd3d12003-05-18 11:30:09 +000072
wdenke2ffd592004-12-31 09:32:47 +000073 socket_cap_t cap;
74 u_short type;
75 u_int flags;
76#ifdef CONFIG_CPC45
77 cirrus_state_t c_state;
78#else
79 ti113x_state_t state;
80#endif
wdenk66fd3d12003-05-18 11:30:09 +000081} socket_info_t;
82
wdenke2ffd592004-12-31 09:32:47 +000083#ifdef CONFIG_CPC45
84/* These definitions must match the pcic table! */
85typedef enum pcic_id {
86 IS_PD6710, IS_PD672X, IS_VT83C469
87} pcic_id;
88
89typedef struct pcic_t {
90 char *name;
91} pcic_t;
92
93static pcic_t pcic[] = {
94 {" Cirrus PD6710: "},
95 {" Cirrus PD672x: "},
96 {" VIA VT83C469: "},
97};
98#endif
99
wdenk66fd3d12003-05-18 11:30:09 +0000100static socket_info_t socket;
101static socket_state_t state;
102static struct pccard_mem_map mem;
103static struct pccard_io_map io;
104
105/*====================================================================*/
106
107/* Some PCI shortcuts */
108
109static int pci_readb (socket_info_t * s, int r, u_char * v)
110{
111 return pci_read_config_byte (s->dev, r, v);
112}
113static int pci_writeb (socket_info_t * s, int r, u_char v)
114{
115 return pci_write_config_byte (s->dev, r, v);
116}
117static int pci_readw (socket_info_t * s, int r, u_short * v)
118{
119 return pci_read_config_word (s->dev, r, v);
120}
121static int pci_writew (socket_info_t * s, int r, u_short v)
122{
123 return pci_write_config_word (s->dev, r, v);
124}
wdenke2ffd592004-12-31 09:32:47 +0000125#ifndef CONFIG_CPC45
wdenk66fd3d12003-05-18 11:30:09 +0000126static int pci_readl (socket_info_t * s, int r, u_int * v)
127{
128 return pci_read_config_dword (s->dev, r, v);
129}
130static int pci_writel (socket_info_t * s, int r, u_int v)
131{
132 return pci_write_config_dword (s->dev, r, v);
133}
wdenke2ffd592004-12-31 09:32:47 +0000134#endif /* !CONFIG_CPC45 */
135
136/*====================================================================*/
137
138#ifdef CONFIG_CPC45
139
140#define cb_readb(s) readb((s)->cb_phys + 1)
141#define cb_writeb(s, v) writeb(v, (s)->cb_phys)
142#define cb_writeb2(s, v) writeb(v, (s)->cb_phys + 1)
143#define cb_readl(s, r) readl((s)->cb_phys + (r))
144#define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r))
145
146
147static u_char i365_get (socket_info_t * s, u_short reg)
148{
149 u_char val;
wdenke2ffd592004-12-31 09:32:47 +0000150#ifdef CONFIG_PCMCIA_SLOT_A
151 int slot = 0;
152#else
153 int slot = 1;
154#endif
155
156 val = I365_REG (slot, reg);
157
158 cb_writeb (s, val);
159 val = cb_readb (s);
160
161 debug ("i365_get slot:%x reg: %x val: %x\n", slot, reg, val);
162 return val;
163}
164
165static void i365_set (socket_info_t * s, u_short reg, u_char data)
166{
167#ifdef CONFIG_PCMCIA_SLOT_A
168 int slot = 0;
169#else
170 int slot = 1;
171#endif
wdenkc3d2b4b2005-01-22 18:13:04 +0000172 u_char val;
wdenke2ffd592004-12-31 09:32:47 +0000173
wdenkc3d2b4b2005-01-22 18:13:04 +0000174 val = I365_REG (slot, reg);
wdenke2ffd592004-12-31 09:32:47 +0000175
176 cb_writeb (s, val);
177 cb_writeb2 (s, data);
178
179 debug ("i365_set slot:%x reg: %x data:%x\n", slot, reg, data);
180}
181
182#else /* ! CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000183
184#define cb_readb(s, r) readb((s)->cb_phys + (r))
185#define cb_readl(s, r) readl((s)->cb_phys + (r))
186#define cb_writeb(s, r, v) writeb(v, (s)->cb_phys + (r))
187#define cb_writel(s, r, v) writel(v, (s)->cb_phys + (r))
188
wdenk66fd3d12003-05-18 11:30:09 +0000189static u_char i365_get (socket_info_t * s, u_short reg)
190{
191 return cb_readb (s, 0x0800 + reg);
192}
193
194static void i365_set (socket_info_t * s, u_short reg, u_char data)
195{
196 cb_writeb (s, 0x0800 + reg, data);
197}
wdenke2ffd592004-12-31 09:32:47 +0000198#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000199
200static void i365_bset (socket_info_t * s, u_short reg, u_char mask)
201{
202 i365_set (s, reg, i365_get (s, reg) | mask);
203}
204
205static void i365_bclr (socket_info_t * s, u_short reg, u_char mask)
206{
207 i365_set (s, reg, i365_get (s, reg) & ~mask);
208}
209
210#if 0 /* not used */
211static void i365_bflip (socket_info_t * s, u_short reg, u_char mask, int b)
212{
213 u_char d = i365_get (s, reg);
214
215 i365_set (s, reg, (b) ? (d | mask) : (d & ~mask));
216}
217
218static u_short i365_get_pair (socket_info_t * s, u_short reg)
219{
220 return (i365_get (s, reg) + (i365_get (s, reg + 1) << 8));
221}
222#endif /* not used */
223
224static void i365_set_pair (socket_info_t * s, u_short reg, u_short data)
225{
226 i365_set (s, reg, data & 0xff);
227 i365_set (s, reg + 1, data >> 8);
228}
229
wdenke2ffd592004-12-31 09:32:47 +0000230#ifdef CONFIG_CPC45
231/*======================================================================
232
233 Code to save and restore global state information for Cirrus
234 PD67xx controllers, and to set and report global configuration
235 options.
236
237======================================================================*/
238
239#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))
240
241static void cirrus_get_state (socket_info_t * s)
242{
243 int i;
244 cirrus_state_t *p = &s->c_state;
245
246 p->misc1 = i365_get (s, PD67_MISC_CTL_1);
247 p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);
248 p->misc2 = i365_get (s, PD67_MISC_CTL_2);
249 for (i = 0; i < 6; i++)
250 p->timer[i] = i365_get (s, PD67_TIME_SETUP (0) + i);
251
252}
253
254static void cirrus_set_state (socket_info_t * s)
255{
256 int i;
257 u_char misc;
258 cirrus_state_t *p = &s->c_state;
259
260 misc = i365_get (s, PD67_MISC_CTL_2);
261 i365_set (s, PD67_MISC_CTL_2, p->misc2);
262 if (misc & PD67_MC2_SUSPEND)
263 udelay (50000);
264 misc = i365_get (s, PD67_MISC_CTL_1);
265 misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);
266 i365_set (s, PD67_MISC_CTL_1, misc | p->misc1);
267 for (i = 0; i < 6; i++)
268 i365_set (s, PD67_TIME_SETUP (0) + i, p->timer[i]);
269}
270
271static u_int cirrus_set_opts (socket_info_t * s)
272{
273 cirrus_state_t *p = &s->c_state;
274 u_int mask = 0xffff;
Marek Vasut66d1a2e2011-10-21 14:17:30 +0000275 char buf[200] = {0};
wdenke2ffd592004-12-31 09:32:47 +0000276
277 if (has_ring == -1)
278 has_ring = 1;
279 flip (p->misc2, PD67_MC2_IRQ15_RI, has_ring);
280 flip (p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode);
281#if DEBUG
282 if (p->misc2 & PD67_MC2_IRQ15_RI)
283 strcat (buf, " [ring]");
284 if (p->misc2 & PD67_MC2_DYNAMIC_MODE)
285 strcat (buf, " [dyn mode]");
286 if (p->misc1 & PD67_MC1_INPACK_ENA)
287 strcat (buf, " [inpack]");
288#endif
289
290 if (p->misc2 & PD67_MC2_IRQ15_RI)
291 mask &= ~0x8000;
292 if (has_led > 0) {
293#if DEBUG
294 strcat (buf, " [led]");
295#endif
296 mask &= ~0x1000;
297 }
298 if (has_dma > 0) {
299#if DEBUG
300 strcat (buf, " [dma]");
301#endif
302 mask &= ~0x0600;
303 flip (p->misc2, PD67_MC2_FREQ_BYPASS, freq_bypass);
304#if DEBUG
305 if (p->misc2 & PD67_MC2_FREQ_BYPASS)
306 strcat (buf, " [freq bypass]");
307#endif
308 }
309
310 if (setup_time >= 0)
311 p->timer[0] = p->timer[3] = setup_time;
312 if (cmd_time > 0) {
313 p->timer[1] = cmd_time;
314 p->timer[4] = cmd_time * 2 + 4;
315 }
316 if (p->timer[1] == 0) {
317 p->timer[1] = 6;
318 p->timer[4] = 16;
319 if (p->timer[0] == 0)
320 p->timer[0] = p->timer[3] = 1;
321 }
322 if (recov_time >= 0)
323 p->timer[2] = p->timer[5] = recov_time;
324
325 debug ("i82365 Opt: %s [%d/%d/%d] [%d/%d/%d]\n",
326 buf,
327 p->timer[0], p->timer[1], p->timer[2],
328 p->timer[3], p->timer[4], p->timer[5]);
329
330 return mask;
331}
332
333#else /* !CONFIG_CPC45 */
334
wdenk66fd3d12003-05-18 11:30:09 +0000335/*======================================================================
336
337 Code to save and restore global state information for TI 1130 and
338 TI 1131 controllers, and to set and report global configuration
339 options.
wdenk8bde7f72003-06-27 21:31:46 +0000340
wdenk66fd3d12003-05-18 11:30:09 +0000341======================================================================*/
342
343static void ti113x_get_state (socket_info_t * s)
344{
345 ti113x_state_t *p = &s->state;
346
347 pci_readl (s, TI113X_SYSTEM_CONTROL, &p->sysctl);
348 pci_readb (s, TI113X_CARD_CONTROL, &p->cardctl);
349 pci_readb (s, TI113X_DEVICE_CONTROL, &p->devctl);
350 pci_readb (s, TI1250_DIAGNOSTIC, &p->diag);
351 pci_readl (s, TI12XX_IRQMUX, &p->irqmux);
352}
353
354static void ti113x_set_state (socket_info_t * s)
355{
356 ti113x_state_t *p = &s->state;
357
358 pci_writel (s, TI113X_SYSTEM_CONTROL, p->sysctl);
359 pci_writeb (s, TI113X_CARD_CONTROL, p->cardctl);
360 pci_writeb (s, TI113X_DEVICE_CONTROL, p->devctl);
361 pci_writeb (s, TI1250_MULTIMEDIA_CTL, 0);
362 pci_writeb (s, TI1250_DIAGNOSTIC, p->diag);
363 pci_writel (s, TI12XX_IRQMUX, p->irqmux);
364 i365_set_pair (s, TI113X_IO_OFFSET (0), 0);
365 i365_set_pair (s, TI113X_IO_OFFSET (1), 0);
366}
367
368static u_int ti113x_set_opts (socket_info_t * s)
369{
370 ti113x_state_t *p = &s->state;
371 u_int mask = 0xffff;
372
373 p->cardctl &= ~TI113X_CCR_ZVENABLE;
374 p->cardctl |= TI113X_CCR_SPKROUTEN;
375
376 return mask;
377}
wdenke2ffd592004-12-31 09:32:47 +0000378#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000379
380/*======================================================================
381
382 Routines to handle common CardBus options
wdenk8bde7f72003-06-27 21:31:46 +0000383
wdenk66fd3d12003-05-18 11:30:09 +0000384======================================================================*/
385
386/* Default settings for PCI command configuration register */
387#define CMD_DFLT (PCI_COMMAND_IO|PCI_COMMAND_MEMORY| \
388 PCI_COMMAND_MASTER|PCI_COMMAND_WAIT)
389
390static void cb_get_state (socket_info_t * s)
391{
392 pci_readb (s, PCI_CACHE_LINE_SIZE, &s->cache);
393 pci_readb (s, PCI_LATENCY_TIMER, &s->pci_lat);
394 pci_readb (s, CB_LATENCY_TIMER, &s->cb_lat);
395 pci_readb (s, CB_CARDBUS_BUS, &s->cap.cardbus);
396 pci_readb (s, CB_SUBORD_BUS, &s->sub_bus);
397 pci_readw (s, CB_BRIDGE_CONTROL, &s->bcr);
398}
399
400static void cb_set_state (socket_info_t * s)
401{
wdenke2ffd592004-12-31 09:32:47 +0000402#ifndef CONFIG_CPC45
wdenk66fd3d12003-05-18 11:30:09 +0000403 pci_writel (s, CB_LEGACY_MODE_BASE, 0);
404 pci_writel (s, PCI_BASE_ADDRESS_0, s->cb_phys);
wdenke2ffd592004-12-31 09:32:47 +0000405#endif
wdenk66fd3d12003-05-18 11:30:09 +0000406 pci_writew (s, PCI_COMMAND, CMD_DFLT);
407 pci_writeb (s, PCI_CACHE_LINE_SIZE, s->cache);
408 pci_writeb (s, PCI_LATENCY_TIMER, s->pci_lat);
409 pci_writeb (s, CB_LATENCY_TIMER, s->cb_lat);
410 pci_writeb (s, CB_CARDBUS_BUS, s->cap.cardbus);
411 pci_writeb (s, CB_SUBORD_BUS, s->sub_bus);
412 pci_writew (s, CB_BRIDGE_CONTROL, s->bcr);
413}
414
415static void cb_set_opts (socket_info_t * s)
416{
wdenke2ffd592004-12-31 09:32:47 +0000417#ifndef CONFIG_CPC45
wdenk66fd3d12003-05-18 11:30:09 +0000418 if (s->cache == 0)
419 s->cache = 8;
420 if (s->pci_lat == 0)
421 s->pci_lat = 0xa8;
422 if (s->cb_lat == 0)
423 s->cb_lat = 0xb0;
wdenke2ffd592004-12-31 09:32:47 +0000424#endif
wdenk66fd3d12003-05-18 11:30:09 +0000425}
426
427/*======================================================================
428
429 Power control for Cardbus controllers: used both for 16-bit and
430 Cardbus cards.
wdenk8bde7f72003-06-27 21:31:46 +0000431
wdenk66fd3d12003-05-18 11:30:09 +0000432======================================================================*/
433
434static int cb_set_power (socket_info_t * s, socket_state_t * state)
435{
436 u_int reg = 0;
437
wdenke2ffd592004-12-31 09:32:47 +0000438#ifdef CONFIG_CPC45
439
wdenke2ffd592004-12-31 09:32:47 +0000440 reg = I365_PWR_NORESET;
441 if (state->flags & SS_PWR_AUTO)
442 reg |= I365_PWR_AUTO;
443 if (state->flags & SS_OUTPUT_ENA)
444 reg |= I365_PWR_OUT;
445 if (state->Vpp != 0) {
446 if (state->Vpp == 120) {
447 reg |= I365_VPP1_12V;
448 puts (" 12V card found: ");
449 } else if (state->Vpp == state->Vcc) {
450 reg |= I365_VPP1_5V;
wdenke2ffd592004-12-31 09:32:47 +0000451 } else {
452 puts (" power not found: ");
453 return -1;
454 }
455 }
456 if (state->Vcc != 0) {
457 reg |= I365_VCC_5V;
458 if (state->Vcc == 33) {
459 puts (" 3.3V card found: ");
460 i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
461 } else if (state->Vcc == 50) {
462 puts (" 5V card found: ");
463 i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
464 } else {
465 puts (" power not found: ");
466 return -1;
467 }
468 }
wdenke799d372005-02-07 19:44:17 +0000469
470 if (reg != i365_get (s, I365_POWER)) {
471 reg = (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V);
wdenke2ffd592004-12-31 09:32:47 +0000472 i365_set (s, I365_POWER, reg);
wdenke799d372005-02-07 19:44:17 +0000473 }
wdenke2ffd592004-12-31 09:32:47 +0000474
475#else /* ! CONFIG_CPC45 */
476
wdenk66fd3d12003-05-18 11:30:09 +0000477 /* restart card voltage detection if it seems appropriate */
478 if ((state->Vcc == 0) && (state->Vpp == 0) &&
wdenke2ffd592004-12-31 09:32:47 +0000479 !(cb_readl (s, CB_SOCKET_STATE) & CB_SS_VSENSE))
wdenk66fd3d12003-05-18 11:30:09 +0000480 cb_writel (s, CB_SOCKET_FORCE, CB_SF_CVSTEST);
481 switch (state->Vcc) {
482 case 0:
483 reg = 0;
484 break;
485 case 33:
486 reg = CB_SC_VCC_3V;
487 break;
488 case 50:
489 reg = CB_SC_VCC_5V;
490 break;
491 default:
492 return -1;
493 }
494 switch (state->Vpp) {
495 case 0:
496 break;
497 case 33:
498 reg |= CB_SC_VPP_3V;
499 break;
500 case 50:
501 reg |= CB_SC_VPP_5V;
502 break;
503 case 120:
504 reg |= CB_SC_VPP_12V;
505 break;
506 default:
507 return -1;
508 }
509 if (reg != cb_readl (s, CB_SOCKET_CONTROL))
510 cb_writel (s, CB_SOCKET_CONTROL, reg);
wdenke2ffd592004-12-31 09:32:47 +0000511#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000512 return 0;
513}
514
515/*======================================================================
516
517 Generic routines to get and set controller options
wdenk8bde7f72003-06-27 21:31:46 +0000518
wdenk66fd3d12003-05-18 11:30:09 +0000519======================================================================*/
520
521static void get_bridge_state (socket_info_t * s)
522{
wdenke2ffd592004-12-31 09:32:47 +0000523#ifdef CONFIG_CPC45
524 cirrus_get_state (s);
525#else
wdenk66fd3d12003-05-18 11:30:09 +0000526 ti113x_get_state (s);
wdenke2ffd592004-12-31 09:32:47 +0000527#endif
wdenk66fd3d12003-05-18 11:30:09 +0000528 cb_get_state (s);
529}
530
531static void set_bridge_state (socket_info_t * s)
532{
533 cb_set_state (s);
534 i365_set (s, I365_GBLCTL, 0x00);
535 i365_set (s, I365_GENCTL, 0x00);
wdenke2ffd592004-12-31 09:32:47 +0000536#ifdef CONFIG_CPC45
537 cirrus_set_state (s);
538#else
wdenk66fd3d12003-05-18 11:30:09 +0000539 ti113x_set_state (s);
wdenke2ffd592004-12-31 09:32:47 +0000540#endif
wdenk66fd3d12003-05-18 11:30:09 +0000541}
542
543static void set_bridge_opts (socket_info_t * s)
544{
wdenke2ffd592004-12-31 09:32:47 +0000545#ifdef CONFIG_CPC45
546 cirrus_set_opts (s);
547#else
wdenk66fd3d12003-05-18 11:30:09 +0000548 ti113x_set_opts (s);
wdenke2ffd592004-12-31 09:32:47 +0000549#endif
wdenk66fd3d12003-05-18 11:30:09 +0000550 cb_set_opts (s);
551}
552
553/*====================================================================*/
wdenke799d372005-02-07 19:44:17 +0000554#define PD67_EXT_INDEX 0x2e /* Extension index */
555#define PD67_EXT_DATA 0x2f /* Extension data */
556#define PD67_EXD_VS1(s) (0x01 << ((s)<<1))
557
558#define pd67_ext_get(s, r) \
559 (i365_set(s, PD67_EXT_INDEX, r), i365_get(s, PD67_EXT_DATA))
wdenk66fd3d12003-05-18 11:30:09 +0000560
561static int i365_get_status (socket_info_t * s, u_int * value)
562{
563 u_int status;
wdenke2ffd592004-12-31 09:32:47 +0000564#ifdef CONFIG_CPC45
565 u_char val;
566 u_char power, vcc, vpp;
wdenke799d372005-02-07 19:44:17 +0000567 u_int powerstate;
wdenke2ffd592004-12-31 09:32:47 +0000568#endif
569
570 status = i365_get (s, I365_IDENT);
wdenk66fd3d12003-05-18 11:30:09 +0000571 status = i365_get (s, I365_STATUS);
572 *value = ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0;
573 if (i365_get (s, I365_INTCTL) & I365_PC_IOCARD) {
574 *value |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG;
575 } else {
576 *value |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD;
577 *value |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN;
578 }
579 *value |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0;
580 *value |= (status & I365_CS_READY) ? SS_READY : 0;
581 *value |= (status & I365_CS_POWERON) ? SS_POWERON : 0;
582
wdenke2ffd592004-12-31 09:32:47 +0000583#ifdef CONFIG_CPC45
584 /* Check for Cirrus CL-PD67xx chips */
585 i365_set (s, PD67_CHIP_INFO, 0);
586 val = i365_get (s, PD67_CHIP_INFO);
587 s->type = -1;
588 if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
589 val = i365_get (s, PD67_CHIP_INFO);
590 if ((val & PD67_INFO_CHIP_ID) == 0) {
wdenkc3d2b4b2005-01-22 18:13:04 +0000591 s->type = (val & PD67_INFO_SLOTS) ? IS_PD672X : IS_PD6710;
wdenke2ffd592004-12-31 09:32:47 +0000592 i365_set (s, PD67_EXT_INDEX, 0xe5);
593 if (i365_get (s, PD67_EXT_INDEX) != 0xe5)
594 s->type = IS_VT83C469;
595 }
596 } else {
597 printf ("no Cirrus Chip found\n");
598 *value = 0;
599 return -1;
600 }
601
wdenke2ffd592004-12-31 09:32:47 +0000602 power = i365_get (s, I365_POWER);
603 state.flags |= (power & I365_PWR_AUTO) ? SS_PWR_AUTO : 0;
604 state.flags |= (power & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0;
605 vcc = power & I365_VCC_MASK;
606 vpp = power & I365_VPP1_MASK;
607 state.Vcc = state.Vpp = 0;
wdenke799d372005-02-07 19:44:17 +0000608 if((vcc== 0) || (vpp == 0)) {
609 /*
610 * On the Cirrus we get the info which card voltage
611 * we have in EXTERN DATA and write it to MISC_CTL1
612 */
613 powerstate = pd67_ext_get(s, PD67_EXTERN_DATA);
614 if (powerstate & PD67_EXD_VS1(0)) {
615 /* 5V Card */
616 i365_bclr (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
617 } else {
618 /* 3.3V Card */
619 i365_bset (s, PD67_MISC_CTL_1, PD67_MC1_VCC_3V);
620 }
621 i365_set (s, I365_POWER, (I365_PWR_OUT | I365_PWR_NORESET | I365_VCC_5V | I365_VPP1_5V));
622 power = i365_get (s, I365_POWER);
wdenke2ffd592004-12-31 09:32:47 +0000623 }
wdenke799d372005-02-07 19:44:17 +0000624 if (power & I365_VCC_5V) {
625 state.Vcc = (i365_get(s, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) ? 33 : 50;
626 }
627
wdenke2ffd592004-12-31 09:32:47 +0000628 if (power == I365_VPP1_12V)
629 state.Vpp = 120;
630
631 /* IO card, RESET flags, IO interrupt */
632 power = i365_get (s, I365_INTCTL);
633 state.flags |= (power & I365_PC_RESET) ? 0 : SS_RESET;
634 if (power & I365_PC_IOCARD)
635 state.flags |= SS_IOCARD;
636 state.io_irq = power & I365_IRQ_MASK;
637
638 /* Card status change mask */
639 power = i365_get (s, I365_CSCINT);
640 state.csc_mask = (power & I365_CSC_DETECT) ? SS_DETECT : 0;
641 if (state.flags & SS_IOCARD)
642 state.csc_mask |= (power & I365_CSC_STSCHG) ? SS_STSCHG : 0;
643 else {
644 state.csc_mask |= (power & I365_CSC_BVD1) ? SS_BATDEAD : 0;
645 state.csc_mask |= (power & I365_CSC_BVD2) ? SS_BATWARN : 0;
646 state.csc_mask |= (power & I365_CSC_READY) ? SS_READY : 0;
647 }
648 debug ("i82365: GetStatus(0) = flags %#3.3x, Vcc %d, Vpp %d, "
649 "io_irq %d, csc_mask %#2.2x\n", state.flags,
650 state.Vcc, state.Vpp, state.io_irq, state.csc_mask);
651
652#else /* !CONFIG_CPC45 */
653
wdenk66fd3d12003-05-18 11:30:09 +0000654 status = cb_readl (s, CB_SOCKET_STATE);
655 *value |= (status & CB_SS_32BIT) ? SS_CARDBUS : 0;
656 *value |= (status & CB_SS_3VCARD) ? SS_3VCARD : 0;
657 *value |= (status & CB_SS_XVCARD) ? SS_XVCARD : 0;
658 *value |= (status & CB_SS_VSENSE) ? 0 : SS_PENDING;
659 /* For now, ignore cards with unsupported voltage keys */
660 if (*value & SS_XVCARD)
661 *value &= ~(SS_DETECT | SS_3VCARD | SS_XVCARD);
wdenke2ffd592004-12-31 09:32:47 +0000662#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000663 return 0;
664} /* i365_get_status */
665
666static int i365_set_socket (socket_info_t * s, socket_state_t * state)
667{
668 u_char reg;
669
670 set_bridge_state (s);
671
672 /* IO card, RESET flag */
673 reg = 0;
674 reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET;
675 reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0;
676 i365_set (s, I365_INTCTL, reg);
677
wdenke2ffd592004-12-31 09:32:47 +0000678#ifdef CONFIG_CPC45
679 cb_set_power (s, state);
680
681#if 0
682 /* Card status change interrupt mask */
683 reg = s->cs_irq << 4;
684 if (state->csc_mask & SS_DETECT)
685 reg |= I365_CSC_DETECT;
686 if (state->flags & SS_IOCARD) {
687 if (state->csc_mask & SS_STSCHG)
688 reg |= I365_CSC_STSCHG;
689 } else {
690 if (state->csc_mask & SS_BATDEAD)
691 reg |= I365_CSC_BVD1;
692 if (state->csc_mask & SS_BATWARN)
693 reg |= I365_CSC_BVD2;
694 if (state->csc_mask & SS_READY)
695 reg |= I365_CSC_READY;
696 }
697 i365_set (s, I365_CSCINT, reg);
698 i365_get (s, I365_CSC);
699#endif /* 0 */
700
701#else /* !CONFIG_CPC45 */
702
wdenk66fd3d12003-05-18 11:30:09 +0000703 reg = I365_PWR_NORESET;
704 if (state->flags & SS_PWR_AUTO)
705 reg |= I365_PWR_AUTO;
706 if (state->flags & SS_OUTPUT_ENA)
707 reg |= I365_PWR_OUT;
708
709 cb_set_power (s, state);
710 reg |= i365_get (s, I365_POWER) & (I365_VCC_MASK | I365_VPP1_MASK);
711
712 if (reg != i365_get (s, I365_POWER))
713 i365_set (s, I365_POWER, reg);
wdenke2ffd592004-12-31 09:32:47 +0000714#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000715
716 return 0;
717} /* i365_set_socket */
718
719/*====================================================================*/
720
721static int i365_set_mem_map (socket_info_t * s, struct pccard_mem_map *mem)
722{
723 u_short base, i;
724 u_char map;
725
wdenke2ffd592004-12-31 09:32:47 +0000726 debug ("i82365: SetMemMap(%d, %#2.2x, %d ns, %#5.5lx-%#5.5lx, %#5.5x)\n",
727 mem->map, mem->flags, mem->speed,
728 mem->sys_start, mem->sys_stop, mem->card_start);
729
wdenk66fd3d12003-05-18 11:30:09 +0000730 map = mem->map;
731 if ((map > 4) ||
732 (mem->card_start > 0x3ffffff) ||
733 (mem->sys_start > mem->sys_stop) ||
734 (mem->speed > 1000)) {
735 return -1;
736 }
737
738 /* Turn off the window before changing anything */
739 if (i365_get (s, I365_ADDRWIN) & I365_ENA_MEM (map))
740 i365_bclr (s, I365_ADDRWIN, I365_ENA_MEM (map));
741
742 /* Take care of high byte, for PCI controllers */
743 i365_set (s, CB_MEM_PAGE (map), mem->sys_start >> 24);
744
745 base = I365_MEM (map);
746 i = (mem->sys_start >> 12) & 0x0fff;
747 if (mem->flags & MAP_16BIT)
748 i |= I365_MEM_16BIT;
749 if (mem->flags & MAP_0WS)
750 i |= I365_MEM_0WS;
751 i365_set_pair (s, base + I365_W_START, i);
752
753 i = (mem->sys_stop >> 12) & 0x0fff;
754 switch (mem->speed / CYCLE_TIME) {
755 case 0:
756 break;
757 case 1:
758 i |= I365_MEM_WS0;
759 break;
760 case 2:
761 i |= I365_MEM_WS1;
762 break;
763 default:
764 i |= I365_MEM_WS1 | I365_MEM_WS0;
765 break;
766 }
767 i365_set_pair (s, base + I365_W_STOP, i);
768
wdenke2ffd592004-12-31 09:32:47 +0000769#ifdef CONFIG_CPC45
770 i = 0;
771#else
wdenk66fd3d12003-05-18 11:30:09 +0000772 i = ((mem->card_start - mem->sys_start) >> 12) & 0x3fff;
wdenke2ffd592004-12-31 09:32:47 +0000773#endif
wdenk66fd3d12003-05-18 11:30:09 +0000774 if (mem->flags & MAP_WRPROT)
775 i |= I365_MEM_WRPROT;
776 if (mem->flags & MAP_ATTRIB)
777 i |= I365_MEM_REG;
778 i365_set_pair (s, base + I365_W_OFF, i);
779
wdenke2ffd592004-12-31 09:32:47 +0000780#ifdef CONFIG_CPC45
781 /* set System Memory map Upper Adress */
782 i365_set(s, PD67_EXT_INDEX, PD67_MEM_PAGE(map));
783 i365_set(s, PD67_EXT_DATA, ((mem->sys_start >> 24) & 0xff));
784#endif
785
wdenk66fd3d12003-05-18 11:30:09 +0000786 /* Turn on the window if necessary */
787 if (mem->flags & MAP_ACTIVE)
788 i365_bset (s, I365_ADDRWIN, I365_ENA_MEM (map));
789 return 0;
790} /* i365_set_mem_map */
791
792static int i365_set_io_map (socket_info_t * s, struct pccard_io_map *io)
793{
794 u_char map, ioctl;
795
796 map = io->map;
wdenkeedcd072004-09-08 22:03:11 +0000797 /* comment out: comparison is always false due to limited range of data type */
798 if ((map > 1) || /* (io->start > 0xffff) || (io->stop > 0xffff) || */
wdenke2ffd592004-12-31 09:32:47 +0000799 (io->stop < io->start))
wdenk66fd3d12003-05-18 11:30:09 +0000800 return -1;
801 /* Turn off the window before changing anything */
802 if (i365_get (s, I365_ADDRWIN) & I365_ENA_IO (map))
803 i365_bclr (s, I365_ADDRWIN, I365_ENA_IO (map));
804 i365_set_pair (s, I365_IO (map) + I365_W_START, io->start);
805 i365_set_pair (s, I365_IO (map) + I365_W_STOP, io->stop);
806 ioctl = i365_get (s, I365_IOCTL) & ~I365_IOCTL_MASK (map);
807 if (io->speed)
808 ioctl |= I365_IOCTL_WAIT (map);
809 if (io->flags & MAP_0WS)
810 ioctl |= I365_IOCTL_0WS (map);
811 if (io->flags & MAP_16BIT)
812 ioctl |= I365_IOCTL_16BIT (map);
813 if (io->flags & MAP_AUTOSZ)
814 ioctl |= I365_IOCTL_IOCS16 (map);
815 i365_set (s, I365_IOCTL, ioctl);
816 /* Turn on the window if necessary */
817 if (io->flags & MAP_ACTIVE)
818 i365_bset (s, I365_ADDRWIN, I365_ENA_IO (map));
819 return 0;
820} /* i365_set_io_map */
821
822/*====================================================================*/
823
824int i82365_init (void)
825{
826 u_int val;
827 int i;
828
wdenke2ffd592004-12-31 09:32:47 +0000829#ifdef CONFIG_CPC45
830 if (SPD67290Init () != 0)
831 return 1;
832#endif
wdenk66fd3d12003-05-18 11:30:09 +0000833 if ((socket.dev = pci_find_devices (supported, 0)) < 0) {
834 /* Controller not found */
835 return 1;
836 }
wdenke2ffd592004-12-31 09:32:47 +0000837 debug ("i82365 Device Found!\n");
wdenk66fd3d12003-05-18 11:30:09 +0000838
839 pci_read_config_dword (socket.dev, PCI_BASE_ADDRESS_0, &socket.cb_phys);
840 socket.cb_phys &= ~0xf;
841
wdenke2ffd592004-12-31 09:32:47 +0000842#ifdef CONFIG_CPC45
843 /* + 0xfe000000 see MPC 8245 Users Manual Adress Map B */
844 socket.cb_phys += 0xfe000000;
845#endif
846
wdenk66fd3d12003-05-18 11:30:09 +0000847 get_bridge_state (&socket);
848 set_bridge_opts (&socket);
849
wdenke2ffd592004-12-31 09:32:47 +0000850 i = i365_get_status (&socket, &val);
wdenk66fd3d12003-05-18 11:30:09 +0000851
wdenke2ffd592004-12-31 09:32:47 +0000852#ifdef CONFIG_CPC45
853 if (i > -1) {
854 puts (pcic[socket.type].name);
855 } else {
856 printf ("i82365: Controller not found.\n");
857 return 1;
858 }
wdenk436be292005-01-31 22:09:11 +0000859 if((val & SS_DETECT) != SS_DETECT){
860 puts ("No card\n");
861 return 1;
862 }
wdenke2ffd592004-12-31 09:32:47 +0000863#else /* !CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000864 if (val & SS_DETECT) {
865 if (val & SS_3VCARD) {
866 state.Vcc = state.Vpp = 33;
867 puts (" 3.3V card found: ");
868 } else if (!(val & SS_XVCARD)) {
869 state.Vcc = state.Vpp = 50;
870 puts (" 5.0V card found: ");
871 } else {
wdenke2ffd592004-12-31 09:32:47 +0000872 puts ("i82365: unsupported voltage key\n");
wdenk66fd3d12003-05-18 11:30:09 +0000873 state.Vcc = state.Vpp = 0;
874 }
875 } else {
876 /* No card inserted */
wdenke2ffd592004-12-31 09:32:47 +0000877 puts ("No card\n");
wdenk66fd3d12003-05-18 11:30:09 +0000878 return 1;
879 }
wdenke2ffd592004-12-31 09:32:47 +0000880#endif /* CONFIG_CPC45 */
wdenk66fd3d12003-05-18 11:30:09 +0000881
wdenke2ffd592004-12-31 09:32:47 +0000882#ifdef CONFIG_CPC45
883 state.flags |= SS_OUTPUT_ENA;
884#else
wdenk66fd3d12003-05-18 11:30:09 +0000885 state.flags = SS_IOCARD | SS_OUTPUT_ENA;
886 state.csc_mask = 0;
887 state.io_irq = 0;
wdenke2ffd592004-12-31 09:32:47 +0000888#endif
wdenk66fd3d12003-05-18 11:30:09 +0000889
890 i365_set_socket (&socket, &state);
891
892 for (i = 500; i; i--) {
893 if ((i365_get (&socket, I365_STATUS) & I365_CS_READY))
894 break;
895 udelay (1000);
896 }
897
898 if (i == 0) {
899 /* PC Card not ready for data transfer */
wdenke2ffd592004-12-31 09:32:47 +0000900 puts ("i82365 PC Card not ready for data transfer\n");
wdenk66fd3d12003-05-18 11:30:09 +0000901 return 1;
902 }
wdenke2ffd592004-12-31 09:32:47 +0000903 debug (" PC Card ready for data transfer: ");
wdenk66fd3d12003-05-18 11:30:09 +0000904
905 mem.map = 0;
906 mem.flags = MAP_ATTRIB | MAP_ACTIVE;
907 mem.speed = 300;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200908 mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR;
909 mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE - 1;
wdenk66fd3d12003-05-18 11:30:09 +0000910 mem.card_start = 0;
wdenk66fd3d12003-05-18 11:30:09 +0000911 i365_set_mem_map (&socket, &mem);
912
wdenke2ffd592004-12-31 09:32:47 +0000913#ifdef CONFIG_CPC45
914 mem.map = 1;
915 mem.flags = MAP_ACTIVE;
916 mem.speed = 300;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200917 mem.sys_start = CONFIG_SYS_PCMCIA_MEM_ADDR + CONFIG_SYS_PCMCIA_MEM_SIZE;
918 mem.sys_stop = CONFIG_SYS_PCMCIA_MEM_ADDR + (2 * CONFIG_SYS_PCMCIA_MEM_SIZE) - 1;
wdenke2ffd592004-12-31 09:32:47 +0000919 mem.card_start = 0;
920 i365_set_mem_map (&socket, &mem);
921
922#else /* !CONFIG_CPC45 */
923
wdenk66fd3d12003-05-18 11:30:09 +0000924 io.map = 0;
925 io.flags = MAP_AUTOSZ | MAP_ACTIVE;
926 io.speed = 0;
927 io.start = 0x0100;
928 io.stop = 0x010F;
wdenk66fd3d12003-05-18 11:30:09 +0000929 i365_set_io_map (&socket, &io);
930
wdenke2ffd592004-12-31 09:32:47 +0000931#endif /* CONFIG_CPC45 */
932
wdenk66fd3d12003-05-18 11:30:09 +0000933#ifdef DEBUG
934 i82365_dump_regions (socket.dev);
935#endif
936
937 return 0;
938}
939
940void i82365_exit (void)
941{
942 io.map = 0;
943 io.flags = 0;
944 io.speed = 0;
945 io.start = 0;
946 io.stop = 0x1;
947
948 i365_set_io_map (&socket, &io);
949
950 mem.map = 0;
951 mem.flags = 0;
952 mem.speed = 0;
953 mem.sys_start = 0;
954 mem.sys_stop = 0x1000;
955 mem.card_start = 0;
956
957 i365_set_mem_map (&socket, &mem);
958
wdenke2ffd592004-12-31 09:32:47 +0000959#ifdef CONFIG_CPC45
960 mem.map = 1;
961 mem.flags = 0;
962 mem.speed = 0;
963 mem.sys_start = 0;
964 mem.sys_stop = 0x1000;
965 mem.card_start = 0;
wdenk66fd3d12003-05-18 11:30:09 +0000966
wdenke2ffd592004-12-31 09:32:47 +0000967 i365_set_mem_map (&socket, &mem);
968#else /* !CONFIG_CPC45 */
969 socket.state.sysctl &= 0xFFFF00FF;
970#endif
wdenk66fd3d12003-05-18 11:30:09 +0000971 state.Vcc = state.Vpp = 0;
972
973 i365_set_socket (&socket, &state);
974}
975
976/*======================================================================
977
978 Debug stuff
wdenk8bde7f72003-06-27 21:31:46 +0000979
wdenk66fd3d12003-05-18 11:30:09 +0000980======================================================================*/
981
982#ifdef DEBUG
983static void i82365_dump_regions (pci_dev_t dev)
984{
985 u_int tmp[2];
wdenke2ffd592004-12-31 09:32:47 +0000986 u_int *mem = (void *) socket.cb_phys;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200987 u_char *cis = (void *) CONFIG_SYS_PCMCIA_MEM_ADDR;
988 u_char *ide = (void *) (CONFIG_SYS_ATA_BASE_ADDR + CONFIG_SYS_ATA_REG_OFFSET);
wdenk66fd3d12003-05-18 11:30:09 +0000989
990 pci_read_config_dword (dev, 0x00, tmp + 0);
991 pci_read_config_dword (dev, 0x80, tmp + 1);
992
wdenkc3d2b4b2005-01-22 18:13:04 +0000993 printf ("PCI CONF: %08X ... %08X\n",
994 tmp[0], tmp[1]);
995 printf ("PCI MEM: ... %08X ... %08X\n",
996 mem[0x8 / 4], mem[0x800 / 4]);
wdenk66fd3d12003-05-18 11:30:09 +0000997 printf ("CIS: ...%c%c%c%c%c%c%c%c...\n",
998 cis[0x38], cis[0x3a], cis[0x3c], cis[0x3e],
999 cis[0x40], cis[0x42], cis[0x44], cis[0x48]);
1000 printf ("CIS CONF: %02X %02X %02X ...\n",
1001 cis[0x200], cis[0x202], cis[0x204]);
1002 printf ("IDE: %02X %02X %02X %02X %02X %02X %02X %02X\n",
1003 ide[0], ide[1], ide[2], ide[3],
1004 ide[4], ide[5], ide[6], ide[7]);
1005}
1006#endif /* DEBUG */