]> err.no Git - linux-2.6/blob - drivers/ide/ppc/mpc8xx.c
ide-mpc8xx: make m8xx_ide_init_ports() return an error value
[linux-2.6] / drivers / ide / ppc / mpc8xx.c
1 /*
2  *  Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de
3  *  Modified for direct IDE interface
4  *      by Thomas Lange, thomas@corelatus.com
5  *  Modified for direct IDE interface on 8xx without using the PCMCIA
6  *  controller
7  *      by Steven.Scholz@imc-berlin.de
8  *  Moved out of arch/ppc/kernel/m8xx_setup.c, other minor cleanups
9  *      by Mathew Locke <mattl@mvista.com>
10  */
11
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/stddef.h>
16 #include <linux/unistd.h>
17 #include <linux/ptrace.h>
18 #include <linux/slab.h>
19 #include <linux/user.h>
20 #include <linux/tty.h>
21 #include <linux/major.h>
22 #include <linux/interrupt.h>
23 #include <linux/reboot.h>
24 #include <linux/init.h>
25 #include <linux/ioport.h>
26 #include <linux/ide.h>
27 #include <linux/bootmem.h>
28
29 #include <asm/mpc8xx.h>
30 #include <asm/mmu.h>
31 #include <asm/processor.h>
32 #include <asm/io.h>
33 #include <asm/pgtable.h>
34 #include <asm/ide.h>
35 #include <asm/8xx_immap.h>
36 #include <asm/machdep.h>
37 #include <asm/irq.h>
38
39 static int identify  (volatile u8 *p);
40 static void print_fixed (volatile u8 *p);
41 static void print_funcid (int func);
42 static int check_ide_device (unsigned long base);
43
44 static void ide_interrupt_ack (void *dev);
45 static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio);
46
47 typedef struct ide_ioport_desc {
48         unsigned long   base_off;               /* Offset to PCMCIA memory      */
49         unsigned long   reg_off[IDE_NR_PORTS];  /* controller register offsets  */
50         int             irq;                    /* IRQ                          */
51 } ide_ioport_desc_t;
52
53 ide_ioport_desc_t ioport_dsc[MAX_HWIFS] = {
54 #ifdef IDE0_BASE_OFFSET
55         { IDE0_BASE_OFFSET,
56             {
57                 IDE0_DATA_REG_OFFSET,
58                 IDE0_ERROR_REG_OFFSET,
59                 IDE0_NSECTOR_REG_OFFSET,
60                 IDE0_SECTOR_REG_OFFSET,
61                 IDE0_LCYL_REG_OFFSET,
62                 IDE0_HCYL_REG_OFFSET,
63                 IDE0_SELECT_REG_OFFSET,
64                 IDE0_STATUS_REG_OFFSET,
65                 IDE0_CONTROL_REG_OFFSET,
66                 IDE0_IRQ_REG_OFFSET,
67             },
68             IDE0_INTERRUPT,
69         },
70 #ifdef IDE1_BASE_OFFSET
71         { IDE1_BASE_OFFSET,
72             {
73                 IDE1_DATA_REG_OFFSET,
74                 IDE1_ERROR_REG_OFFSET,
75                 IDE1_NSECTOR_REG_OFFSET,
76                 IDE1_SECTOR_REG_OFFSET,
77                 IDE1_LCYL_REG_OFFSET,
78                 IDE1_HCYL_REG_OFFSET,
79                 IDE1_SELECT_REG_OFFSET,
80                 IDE1_STATUS_REG_OFFSET,
81                 IDE1_CONTROL_REG_OFFSET,
82                 IDE1_IRQ_REG_OFFSET,
83             },
84             IDE1_INTERRUPT,
85         },
86 #endif /* IDE1_BASE_OFFSET */
87 #endif  /* IDE0_BASE_OFFSET */
88 };
89
90 ide_pio_timings_t ide_pio_clocks[6];
91 int hold_time[6] =  {30, 20, 15, 10, 10, 10 };   /* PIO Mode 5 with IORDY (nonstandard) */
92
93 /*
94  * Warning: only 1 (ONE) PCMCIA slot supported here,
95  * which must be correctly initialized by the firmware (PPCBoot).
96  */
97 static int _slot_ = -1;                 /* will be read from PCMCIA registers   */
98
99 /* Make clock cycles and always round up */
100 #define PCMCIA_MK_CLKS( t, T ) (( (t) * ((T)/1000000) + 999U ) / 1000U )
101
102 #define M8XX_PCMCIA_CD2(slot)      (0x10000000 >> (slot << 4))
103 #define M8XX_PCMCIA_CD1(slot)      (0x08000000 >> (slot << 4))
104
105 /*
106  * The TQM850L hardware has two pins swapped! Grrrrgh!
107  */
108 #ifdef  CONFIG_TQM850L
109 #define __MY_PCMCIA_GCRX_CXRESET        PCMCIA_GCRX_CXOE
110 #define __MY_PCMCIA_GCRX_CXOE           PCMCIA_GCRX_CXRESET
111 #else
112 #define __MY_PCMCIA_GCRX_CXRESET        PCMCIA_GCRX_CXRESET
113 #define __MY_PCMCIA_GCRX_CXOE           PCMCIA_GCRX_CXOE
114 #endif
115
116 #if defined(CONFIG_BLK_DEV_MPC8xx_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
117 #define PCMCIA_SCHLVL IDE0_INTERRUPT    /* Status Change Interrupt Level        */
118 static int pcmcia_schlvl = PCMCIA_SCHLVL;
119 #endif
120
121 /*
122  * See include/linux/ide.h for definition of hw_regs_t (p, base)
123  */
124
125 /*
126  * m8xx_ide_init_ports() for a direct IDE interface _using_
127  * MPC8xx's internal PCMCIA interface
128  */
129 #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
130 static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
131 {
132         unsigned long *p = hw->io_ports;
133         int i;
134
135         typedef struct {
136                 ulong br;
137                 ulong or;
138         } pcmcia_win_t;
139         volatile pcmcia_win_t *win;
140         volatile pcmconf8xx_t *pcmp;
141
142         uint *pgcrx;
143         u32 pcmcia_phy_base;
144         u32 pcmcia_phy_end;
145         static unsigned long pcmcia_base = 0;
146         unsigned long base;
147
148         *p = 0;
149
150         pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
151
152         if (!pcmcia_base) {
153                 /*
154                  * Read out PCMCIA registers. Since the reset values
155                  * are undefined, we sure hope that they have been
156                  * set up by firmware
157                  */
158
159                 /* Scan all registers for valid settings */
160                 pcmcia_phy_base = 0xFFFFFFFF;
161                 pcmcia_phy_end = 0;
162                 /* br0 is start of brX and orX regs */
163                 win = (pcmcia_win_t *) \
164                         (&(((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0));
165                 for (i = 0; i < 8; i++) {
166                         if (win->or & 1) {      /* This bank is marked as valid */
167                                 if (win->br < pcmcia_phy_base) {
168                                         pcmcia_phy_base = win->br;
169                                 }
170                                 if ((win->br + PCMCIA_MEM_SIZE) > pcmcia_phy_end) {
171                                         pcmcia_phy_end  = win->br + PCMCIA_MEM_SIZE;
172                                 }
173                                 /* Check which slot that has been defined */
174                                 _slot_ = (win->or >> 2) & 1;
175
176                         }                                       /* Valid bank */
177                         win++;
178                 }                                               /* for */
179
180                 printk ("PCMCIA slot %c: phys mem %08x...%08x (size %08x)\n",
181                         'A' + _slot_,
182                         pcmcia_phy_base, pcmcia_phy_end,
183                         pcmcia_phy_end - pcmcia_phy_base);
184
185                 pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base,
186                                                    pcmcia_phy_end-pcmcia_phy_base);
187
188 #ifdef DEBUG
189                 printk ("PCMCIA virt base: %08lx\n", pcmcia_base);
190 #endif
191                 /* Compute clock cycles for PIO timings */
192                 for (i=0; i<6; ++i) {
193                         bd_t    *binfo = (bd_t *)__res;
194
195                         hold_time[i]   =
196                                 PCMCIA_MK_CLKS (hold_time[i],
197                                                 binfo->bi_busfreq);
198                         ide_pio_clocks[i].setup_time  =
199                                 PCMCIA_MK_CLKS (ide_pio_timings[i].setup_time,
200                                                 binfo->bi_busfreq);
201                         ide_pio_clocks[i].active_time =
202                                 PCMCIA_MK_CLKS (ide_pio_timings[i].active_time,
203                                                 binfo->bi_busfreq);
204                         ide_pio_clocks[i].cycle_time  =
205                                 PCMCIA_MK_CLKS (ide_pio_timings[i].cycle_time,
206                                                 binfo->bi_busfreq);
207 #if 0
208                         printk ("PIO mode %d timings: %d/%d/%d => %d/%d/%d\n",
209                                 i,
210                                 ide_pio_clocks[i].setup_time,
211                                 ide_pio_clocks[i].active_time,
212                                 ide_pio_clocks[i].hold_time,
213                                 ide_pio_clocks[i].cycle_time,
214                                 ide_pio_timings[i].setup_time,
215                                 ide_pio_timings[i].active_time,
216                                 ide_pio_timings[i].hold_time,
217                                 ide_pio_timings[i].cycle_time);
218 #endif
219                 }
220         }
221
222         if (_slot_ == -1) {
223                 printk ("PCMCIA slot has not been defined! Using A as default\n");
224                 _slot_ = 0;
225         }
226
227 #ifdef CONFIG_IDE_8xx_PCCARD
228
229 #ifdef DEBUG
230         printk ("PIPR = 0x%08X  slot %c ==> mask = 0x%X\n",
231                 pcmp->pcmc_pipr,
232                 'A' + _slot_,
233                 M8XX_PCMCIA_CD1(_slot_) | M8XX_PCMCIA_CD2(_slot_) );
234 #endif /* DEBUG */
235
236         if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) {
237                 printk ("No card in slot %c: PIPR=%08x\n",
238                         'A' + _slot_, (u32) pcmp->pcmc_pipr);
239                 return -ENODEV;         /* No card in slot */
240         }
241
242         check_ide_device (pcmcia_base);
243
244 #endif  /* CONFIG_IDE_8xx_PCCARD */
245
246         base = pcmcia_base + ioport_dsc[data_port].base_off;
247 #ifdef DEBUG
248         printk ("base: %08x + %08x = %08x\n",
249                         pcmcia_base, ioport_dsc[data_port].base_off, base);
250 #endif
251
252         for (i = 0; i < IDE_NR_PORTS; ++i) {
253 #ifdef DEBUG
254                 printk ("port[%d]: %08x + %08x = %08x\n",
255                         i,
256                         base,
257                         ioport_dsc[data_port].reg_off[i],
258                         i, base + ioport_dsc[data_port].reg_off[i]);
259 #endif
260                 *p++ = base + ioport_dsc[data_port].reg_off[i];
261         }
262
263         hw->irq = ioport_dsc[data_port].irq;
264         hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack;
265
266 #ifdef CONFIG_IDE_8xx_PCCARD
267         {
268                 unsigned int reg;
269
270                 if (_slot_)
271                         pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcrb;
272                 else
273                         pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcra;
274
275                 reg = *pgcrx;
276                 reg |= mk_int_int_mask (pcmcia_schlvl) << 24;
277                 reg |= mk_int_int_mask (pcmcia_schlvl) << 16;
278                 *pgcrx = reg;
279         }
280 #endif  /* CONFIG_IDE_8xx_PCCARD */
281
282         /* Enable Harddisk Interrupt,
283          * and make it edge sensitive
284          */
285         /* (11-18) Set edge detect for irq, no wakeup from low power mode */
286         ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel |=
287                                         (0x80000000 >> ioport_dsc[data_port].irq);
288
289 #ifdef CONFIG_IDE_8xx_PCCARD
290         /* Make sure we don't get garbage irq */
291         ((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pscr = 0xFFFF;
292
293         /* Enable falling edge irq */
294         pcmp->pcmc_per = 0x100000 >> (16 * _slot_);
295 #endif  /* CONFIG_IDE_8xx_PCCARD */
296
297         return 0;
298 }
299 #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */
300
301 /*
302  * m8xx_ide_init_ports() for a direct IDE interface _not_ using
303  * MPC8xx's internal PCMCIA interface
304  */
305 #if defined(CONFIG_IDE_EXT_DIRECT)
306 static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port)
307 {
308         unsigned long *p = hw->io_ports;
309         int i;
310
311         u32 ide_phy_base;
312         u32 ide_phy_end;
313         static unsigned long ide_base = 0;
314         unsigned long base;
315
316         *p = 0;
317
318         if (!ide_base) {
319
320                 /* TODO:
321                  * - add code to read ORx, BRx
322                  */
323                 ide_phy_base = CFG_ATA_BASE_ADDR;
324                 ide_phy_end  = CFG_ATA_BASE_ADDR + 0x200;
325
326                 printk ("IDE phys mem : %08x...%08x (size %08x)\n",
327                         ide_phy_base, ide_phy_end,
328                         ide_phy_end - ide_phy_base);
329                 
330                 ide_base=(unsigned long)ioremap(ide_phy_base,
331                                                 ide_phy_end-ide_phy_base);
332
333 #ifdef DEBUG
334                 printk ("IDE virt base: %08lx\n", ide_base);
335 #endif
336         }
337
338         base = ide_base + ioport_dsc[data_port].base_off;
339 #ifdef DEBUG
340         printk ("base: %08x + %08x = %08x\n",
341                 ide_base, ioport_dsc[data_port].base_off, base);
342 #endif
343
344         for (i = 0; i < IDE_NR_PORTS; ++i) {
345 #ifdef DEBUG
346                 printk ("port[%d]: %08x + %08x = %08x\n",
347                         i,
348                         base,
349                         ioport_dsc[data_port].reg_off[i],
350                         i, base + ioport_dsc[data_port].reg_off[i]);
351 #endif
352                 *p++ = base + ioport_dsc[data_port].reg_off[i];
353         }
354
355         /* direct connected IDE drive, i.e. external IRQ */
356         hw->irq = ioport_dsc[data_port].irq;
357         hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack;
358
359         /* Enable Harddisk Interrupt,
360          * and make it edge sensitive
361          */
362         /* (11-18) Set edge detect for irq, no wakeup from low power mode */
363         ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |=
364                         (0x80000000 >> ioport_dsc[data_port].irq);
365
366         return 0;
367 }
368 #endif  /* CONFIG_IDE_8xx_DIRECT */
369
370
371 /* -------------------------------------------------------------------- */
372
373
374 /* PCMCIA Timing */
375 #ifndef PCMCIA_SHT
376 #define PCMCIA_SHT(t)   ((t & 0x0F)<<16)        /* Strobe Hold  Time    */
377 #define PCMCIA_SST(t)   ((t & 0x0F)<<12)        /* Strobe Setup Time    */
378 #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length   */
379 #endif
380
381 /* Calculate PIO timings */
382 static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
383 {
384 #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT)
385         volatile pcmconf8xx_t   *pcmp;
386         ulong timing, mask, reg;
387
388         pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia));
389
390         mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF));
391
392         timing  = PCMCIA_SHT(hold_time[pio]  )
393                 | PCMCIA_SST(ide_pio_clocks[pio].setup_time )
394                 | PCMCIA_SL (ide_pio_clocks[pio].active_time)
395                 ;
396
397 #if 1
398         printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing);
399 #endif
400         if ((reg = pcmp->pcmc_por0 & mask) != 0)
401                 pcmp->pcmc_por0 = reg | timing;
402
403         if ((reg = pcmp->pcmc_por1 & mask) != 0)
404                 pcmp->pcmc_por1 = reg | timing;
405
406         if ((reg = pcmp->pcmc_por2 & mask) != 0)
407                 pcmp->pcmc_por2 = reg | timing;
408
409         if ((reg = pcmp->pcmc_por3 & mask) != 0)
410                 pcmp->pcmc_por3 = reg | timing;
411
412         if ((reg = pcmp->pcmc_por4 & mask) != 0)
413                 pcmp->pcmc_por4 = reg | timing;
414
415         if ((reg = pcmp->pcmc_por5 & mask) != 0)
416                 pcmp->pcmc_por5 = reg | timing;
417
418         if ((reg = pcmp->pcmc_por6 & mask) != 0)
419                 pcmp->pcmc_por6 = reg | timing;
420
421         if ((reg = pcmp->pcmc_por7 & mask) != 0)
422                 pcmp->pcmc_por7 = reg | timing;
423
424 #elif defined(CONFIG_IDE_EXT_DIRECT)
425
426         printk("%s[%d] %s: not implemented yet!\n",
427                 __FILE__,__LINE__,__FUNCTION__);
428 #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */
429 }
430
431 static void
432 ide_interrupt_ack (void *dev)
433 {
434 #ifdef CONFIG_IDE_8xx_PCCARD
435         u_int pscr, pipr;
436
437 #if (PCMCIA_SOCKETS_NO == 2)
438         u_int _slot_;
439 #endif
440
441         /* get interrupt sources */
442
443         pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr;
444         pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr;
445
446         /*
447          * report only if both card detect signals are the same
448          * not too nice done,
449          * we depend on that CD2 is the bit to the left of CD1...
450          */
451
452         if(_slot_==-1){
453           printk("PCMCIA slot has not been defined! Using A as default\n");
454           _slot_=0;
455         }
456
457         if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^
458            (pipr & M8XX_PCMCIA_CD1(_slot_))         ) {
459           printk ("card detect interrupt\n");
460         }
461         /* clear the interrupt sources */
462         ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr;
463
464 #else /* ! CONFIG_IDE_8xx_PCCARD */
465         /*
466          * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the
467          * MPC8xx's PCMCIA controller, so there is nothing to be done here
468          * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT.
469          * The interrupt is handled somewhere else.     -- Steven
470          */
471 #endif /* CONFIG_IDE_8xx_PCCARD */
472 }
473
474
475
476 /*
477  * CIS Tupel codes
478  */
479 #define CISTPL_NULL             0x00
480 #define CISTPL_DEVICE           0x01
481 #define CISTPL_LONGLINK_CB      0x02
482 #define CISTPL_INDIRECT         0x03
483 #define CISTPL_CONFIG_CB        0x04
484 #define CISTPL_CFTABLE_ENTRY_CB 0x05
485 #define CISTPL_LONGLINK_MFC     0x06
486 #define CISTPL_BAR              0x07
487 #define CISTPL_PWR_MGMNT        0x08
488 #define CISTPL_EXTDEVICE        0x09
489 #define CISTPL_CHECKSUM         0x10
490 #define CISTPL_LONGLINK_A       0x11
491 #define CISTPL_LONGLINK_C       0x12
492 #define CISTPL_LINKTARGET       0x13
493 #define CISTPL_NO_LINK          0x14
494 #define CISTPL_VERS_1           0x15
495 #define CISTPL_ALTSTR           0x16
496 #define CISTPL_DEVICE_A         0x17
497 #define CISTPL_JEDEC_C          0x18
498 #define CISTPL_JEDEC_A          0x19
499 #define CISTPL_CONFIG           0x1a
500 #define CISTPL_CFTABLE_ENTRY    0x1b
501 #define CISTPL_DEVICE_OC        0x1c
502 #define CISTPL_DEVICE_OA        0x1d
503 #define CISTPL_DEVICE_GEO       0x1e
504 #define CISTPL_DEVICE_GEO_A     0x1f
505 #define CISTPL_MANFID           0x20
506 #define CISTPL_FUNCID           0x21
507 #define CISTPL_FUNCE            0x22
508 #define CISTPL_SWIL             0x23
509 #define CISTPL_END              0xff
510
511 /*
512  * CIS Function ID codes
513  */
514 #define CISTPL_FUNCID_MULTI     0x00
515 #define CISTPL_FUNCID_MEMORY    0x01
516 #define CISTPL_FUNCID_SERIAL    0x02
517 #define CISTPL_FUNCID_PARALLEL  0x03
518 #define CISTPL_FUNCID_FIXED     0x04
519 #define CISTPL_FUNCID_VIDEO     0x05
520 #define CISTPL_FUNCID_NETWORK   0x06
521 #define CISTPL_FUNCID_AIMS      0x07
522 #define CISTPL_FUNCID_SCSI      0x08
523
524 /*
525  * Fixed Disk FUNCE codes
526  */
527 #define CISTPL_IDE_INTERFACE    0x01
528
529 #define CISTPL_FUNCE_IDE_IFACE  0x01
530 #define CISTPL_FUNCE_IDE_MASTER 0x02
531 #define CISTPL_FUNCE_IDE_SLAVE  0x03
532
533 /* First feature byte */
534 #define CISTPL_IDE_SILICON      0x04
535 #define CISTPL_IDE_UNIQUE       0x08
536 #define CISTPL_IDE_DUAL         0x10
537
538 /* Second feature byte */
539 #define CISTPL_IDE_HAS_SLEEP    0x01
540 #define CISTPL_IDE_HAS_STANDBY  0x02
541 #define CISTPL_IDE_HAS_IDLE     0x04
542 #define CISTPL_IDE_LOW_POWER    0x08
543 #define CISTPL_IDE_REG_INHIBIT  0x10
544 #define CISTPL_IDE_HAS_INDEX    0x20
545 #define CISTPL_IDE_IOIS16       0x40
546
547
548 /* -------------------------------------------------------------------- */
549
550
551 #define MAX_TUPEL_SZ    512
552 #define MAX_FEATURES    4
553
554 static int check_ide_device (unsigned long base)
555 {
556         volatile u8 *ident = NULL;
557         volatile u8 *feature_p[MAX_FEATURES];
558         volatile u8 *p, *start;
559         int n_features = 0;
560         u8 func_id = ~0;
561         u8 code, len;
562         unsigned short config_base = 0;
563         int found = 0;
564         int i;
565
566 #ifdef DEBUG
567         printk ("PCMCIA MEM: %08lX\n", base);
568 #endif
569         start = p = (volatile u8 *) base;
570
571         while ((p - start) < MAX_TUPEL_SZ) {
572
573                 code = *p; p += 2;
574
575                 if (code == 0xFF) { /* End of chain */
576                         break;
577                 }
578
579                 len = *p; p += 2;
580 #ifdef  DEBUG_PCMCIA
581                 { volatile u8 *q = p;
582                         printk ("\nTuple code %02x  length %d\n\tData:",
583                                 code, len);
584
585                         for (i = 0; i < len; ++i) {
586                                 printk (" %02x", *q);
587                                 q+= 2;
588                         }
589                 }
590 #endif  /* DEBUG_PCMCIA */
591                 switch (code) {
592                 case CISTPL_VERS_1:
593                         ident = p + 4;
594                         break;
595                 case CISTPL_FUNCID:
596                         func_id = *p;
597                         break;
598                 case CISTPL_FUNCE:
599                         if (n_features < MAX_FEATURES)
600                                 feature_p[n_features++] = p;
601                         break;
602                 case CISTPL_CONFIG:
603                         config_base = (*(p+6) << 8) + (*(p+4));
604                 default:
605                         break;
606                 }
607                 p += 2 * len;
608         }
609
610         found = identify (ident);
611
612         if (func_id != ((u8)~0)) {
613                 print_funcid (func_id);
614
615                 if (func_id == CISTPL_FUNCID_FIXED)
616                         found = 1;
617                 else
618                         return (1);     /* no disk drive */
619         }
620
621         for (i=0; i<n_features; ++i) {
622                 print_fixed (feature_p[i]);
623         }
624
625         if (!found) {
626                 printk ("unknown card type\n");
627                 return (1);
628         }
629
630         /* set level mode irq and I/O mapped device in config reg*/
631         *((u8 *)(base + config_base)) = 0x41;
632
633         return (0);
634 }
635
636 /* ------------------------------------------------------------------------- */
637
638 static void print_funcid (int func)
639 {
640         switch (func) {
641         case CISTPL_FUNCID_MULTI:
642                 printk (" Multi-Function");
643                 break;
644         case CISTPL_FUNCID_MEMORY:
645                 printk (" Memory");
646                 break;
647         case CISTPL_FUNCID_SERIAL:
648                 printk (" Serial Port");
649                 break;
650         case CISTPL_FUNCID_PARALLEL:
651                 printk (" Parallel Port");
652                 break;
653         case CISTPL_FUNCID_FIXED:
654                 printk (" Fixed Disk");
655                 break;
656         case CISTPL_FUNCID_VIDEO:
657                 printk (" Video Adapter");
658                 break;
659         case CISTPL_FUNCID_NETWORK:
660                 printk (" Network Adapter");
661                 break;
662         case CISTPL_FUNCID_AIMS:
663                 printk (" AIMS Card");
664                 break;
665         case CISTPL_FUNCID_SCSI:
666                 printk (" SCSI Adapter");
667                 break;
668         default:
669                 printk (" Unknown");
670                 break;
671         }
672         printk (" Card\n");
673 }
674
675 /* ------------------------------------------------------------------------- */
676
677 static void print_fixed (volatile u8 *p)
678 {
679         if (p == NULL)
680                 return;
681
682         switch (*p) {
683         case CISTPL_FUNCE_IDE_IFACE:
684             {   u8 iface = *(p+2);
685
686                 printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown");
687                 printk (" interface ");
688                 break;
689             }
690         case CISTPL_FUNCE_IDE_MASTER:
691         case CISTPL_FUNCE_IDE_SLAVE:
692             {   u8 f1 = *(p+2);
693                 u8 f2 = *(p+4);
694
695                 printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]");
696
697                 if (f1 & CISTPL_IDE_UNIQUE)
698                         printk (" [unique]");
699
700                 printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]");
701
702                 if (f2 & CISTPL_IDE_HAS_SLEEP)
703                         printk (" [sleep]");
704
705                 if (f2 & CISTPL_IDE_HAS_STANDBY)
706                         printk (" [standby]");
707
708                 if (f2 & CISTPL_IDE_HAS_IDLE)
709                         printk (" [idle]");
710
711                 if (f2 & CISTPL_IDE_LOW_POWER)
712                         printk (" [low power]");
713
714                 if (f2 & CISTPL_IDE_REG_INHIBIT)
715                         printk (" [reg inhibit]");
716
717                 if (f2 & CISTPL_IDE_HAS_INDEX)
718                         printk (" [index]");
719
720                 if (f2 & CISTPL_IDE_IOIS16)
721                         printk (" [IOis16]");
722
723                 break;
724             }
725         }
726         printk ("\n");
727 }
728
729 /* ------------------------------------------------------------------------- */
730
731
732 #define MAX_IDENT_CHARS         64
733 #define MAX_IDENT_FIELDS        4
734
735 static u8 *known_cards[] = {
736         "ARGOSY PnPIDE D5",
737         NULL
738 };
739
740 static int identify  (volatile u8 *p)
741 {
742         u8 id_str[MAX_IDENT_CHARS];
743         u8 data;
744         u8 *t;
745         u8 **card;
746         int i, done;
747
748         if (p == NULL)
749                 return (0);     /* Don't know */
750
751         t = id_str;
752         done =0;
753
754         for (i=0; i<=4 && !done; ++i, p+=2) {
755                 while ((data = *p) != '\0') {
756                         if (data == 0xFF) {
757                                 done = 1;
758                                 break;
759                         }
760                         *t++ = data;
761                         if (t == &id_str[MAX_IDENT_CHARS-1]) {
762                                 done = 1;
763                                 break;
764                         }
765                         p += 2;
766                 }
767                 if (!done)
768                         *t++ = ' ';
769         }
770         *t = '\0';
771         while (--t > id_str) {
772                 if (*t == ' ')
773                         *t = '\0';
774                 else
775                         break;
776         }
777         printk ("Card ID: %s\n", id_str);
778
779         for (card=known_cards; *card; ++card) {
780                 if (strcmp(*card, id_str) == 0) {       /* found! */
781                         return (1);
782                 }
783         }
784
785         return (0);     /* don't know */
786 }
787
788 static int __init mpc8xx_ide_probe(void)
789 {
790         hw_regs_t hw;
791         u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
792
793 #ifdef IDE0_BASE_OFFSET
794         memset(&hw, 0, sizeof(hw));
795         if (!m8xx_ide_init_ports(&hw, 0)) {
796                 ide_hwif_t *hwif = &ide_hwifs[0];
797
798                 ide_init_port_hw(hwif, &hw);
799                 hwif->pio_mask = ATA_PIO4;
800                 hwif->set_pio_mode = m8xx_ide_set_pio_mode;
801
802                 idx[0] = 0;
803         }
804 #ifdef IDE1_BASE_OFFSET
805         memset(&hw, 0, sizeof(hw));
806         if (!m8xx_ide_init_ports(&hw, 1)) {
807                 ide_hwif_t *mate = &ide_hwifs[1];
808
809                 ide_init_port_hw(mate, &hw);
810                 mate->pio_mask = ATA_PIO4;
811                 mate->set_pio_mode = m8xx_ide_set_pio_mode;
812
813                 idx[1] = 1;
814         }
815 #endif
816 #endif
817
818         ide_device_add(idx, NULL);
819
820         return 0;
821 }
822
823 module_init(mpc8xx_ide_probe);
824
825 MODULE_LICENSE("GPL");