ppc/ppc4xx: remove ppc_ide_md hooks
[deliverable/linux.git] / drivers / ide / ppc / pmac.c
CommitLineData
1da177e4 1/*
1da177e4 2 * Support for IDE interfaces on PowerMacs.
58f189fc 3 *
1da177e4
LT
4 * These IDE interfaces are memory-mapped and have a DBDMA channel
5 * for doing DMA.
6 *
7 * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt
c15d5d43 8 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
1da177e4
LT
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 * Some code taken from drivers/ide/ide-dma.c:
16 *
17 * Copyright (c) 1995-1998 Mark Lord
18 *
19 * TODO: - Use pre-calculated (kauai) timing tables all the time and
20 * get rid of the "rounded" tables used previously, so we have the
21 * same table format for all controllers and can then just have one
22 * big table
23 *
24 */
1da177e4
LT
25#include <linux/types.h>
26#include <linux/kernel.h>
1da177e4
LT
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/ide.h>
30#include <linux/notifier.h>
31#include <linux/reboot.h>
32#include <linux/pci.h>
33#include <linux/adb.h>
34#include <linux/pmu.h>
35#include <linux/scatterlist.h>
36
37#include <asm/prom.h>
38#include <asm/io.h>
39#include <asm/dbdma.h>
40#include <asm/ide.h>
41#include <asm/pci-bridge.h>
42#include <asm/machdep.h>
43#include <asm/pmac_feature.h>
44#include <asm/sections.h>
45#include <asm/irq.h>
46
47#ifndef CONFIG_PPC64
48#include <asm/mediabay.h>
49#endif
50
9e5755bc 51#include "../ide-timing.h"
1da177e4
LT
52
53#undef IDE_PMAC_DEBUG
54
55#define DMA_WAIT_TIMEOUT 50
56
57typedef struct pmac_ide_hwif {
58 unsigned long regbase;
59 int irq;
60 int kind;
61 int aapl_bus_id;
62 unsigned cable_80 : 1;
63 unsigned mediabay : 1;
64 unsigned broken_dma : 1;
65 unsigned broken_dma_warn : 1;
66 struct device_node* node;
67 struct macio_dev *mdev;
68 u32 timings[4];
69 volatile u32 __iomem * *kauai_fcr;
70#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
71 /* Those fields are duplicating what is in hwif. We currently
72 * can't use the hwif ones because of some assumptions that are
73 * beeing done by the generic code about the kind of dma controller
74 * and format of the dma table. This will have to be fixed though.
75 */
76 volatile struct dbdma_regs __iomem * dma_regs;
77 struct dbdma_cmd* dma_table_cpu;
78#endif
79
80} pmac_ide_hwif_t;
81
aacaf9bd 82static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
1da177e4
LT
83
84enum {
85 controller_ohare, /* OHare based */
86 controller_heathrow, /* Heathrow/Paddington */
87 controller_kl_ata3, /* KeyLargo ATA-3 */
88 controller_kl_ata4, /* KeyLargo ATA-4 */
89 controller_un_ata6, /* UniNorth2 ATA-6 */
90 controller_k2_ata6, /* K2 ATA-6 */
91 controller_sh_ata6, /* Shasta ATA-6 */
92};
93
94static const char* model_name[] = {
95 "OHare ATA", /* OHare based */
96 "Heathrow ATA", /* Heathrow/Paddington */
97 "KeyLargo ATA-3", /* KeyLargo ATA-3 (MDMA only) */
98 "KeyLargo ATA-4", /* KeyLargo ATA-4 (UDMA/66) */
99 "UniNorth ATA-6", /* UniNorth2 ATA-6 (UDMA/100) */
100 "K2 ATA-6", /* K2 ATA-6 (UDMA/100) */
101 "Shasta ATA-6", /* Shasta ATA-6 (UDMA/133) */
102};
103
104/*
105 * Extra registers, both 32-bit little-endian
106 */
107#define IDE_TIMING_CONFIG 0x200
108#define IDE_INTERRUPT 0x300
109
110/* Kauai (U2) ATA has different register setup */
111#define IDE_KAUAI_PIO_CONFIG 0x200
112#define IDE_KAUAI_ULTRA_CONFIG 0x210
113#define IDE_KAUAI_POLL_CONFIG 0x220
114
115/*
116 * Timing configuration register definitions
117 */
118
119/* Number of IDE_SYSCLK_NS ticks, argument is in nanoseconds */
120#define SYSCLK_TICKS(t) (((t) + IDE_SYSCLK_NS - 1) / IDE_SYSCLK_NS)
121#define SYSCLK_TICKS_66(t) (((t) + IDE_SYSCLK_66_NS - 1) / IDE_SYSCLK_66_NS)
122#define IDE_SYSCLK_NS 30 /* 33Mhz cell */
123#define IDE_SYSCLK_66_NS 15 /* 66Mhz cell */
124
125/* 133Mhz cell, found in shasta.
126 * See comments about 100 Mhz Uninorth 2...
127 * Note that PIO_MASK and MDMA_MASK seem to overlap
128 */
129#define TR_133_PIOREG_PIO_MASK 0xff000fff
130#define TR_133_PIOREG_MDMA_MASK 0x00fff800
131#define TR_133_UDMAREG_UDMA_MASK 0x0003ffff
132#define TR_133_UDMAREG_UDMA_EN 0x00000001
133
134/* 100Mhz cell, found in Uninorth 2. I don't have much infos about
135 * this one yet, it appears as a pci device (106b/0033) on uninorth
136 * internal PCI bus and it's clock is controlled like gem or fw. It
137 * appears to be an evolution of keylargo ATA4 with a timing register
138 * extended to 2 32bits registers and a similar DBDMA channel. Other
139 * registers seem to exist but I can't tell much about them.
140 *
141 * So far, I'm using pre-calculated tables for this extracted from
142 * the values used by the MacOS X driver.
143 *
144 * The "PIO" register controls PIO and MDMA timings, the "ULTRA"
145 * register controls the UDMA timings. At least, it seems bit 0
146 * of this one enables UDMA vs. MDMA, and bits 4..7 are the
147 * cycle time in units of 10ns. Bits 8..15 are used by I don't
148 * know their meaning yet
149 */
150#define TR_100_PIOREG_PIO_MASK 0xff000fff
151#define TR_100_PIOREG_MDMA_MASK 0x00fff000
152#define TR_100_UDMAREG_UDMA_MASK 0x0000ffff
153#define TR_100_UDMAREG_UDMA_EN 0x00000001
154
155
156/* 66Mhz cell, found in KeyLargo. Can do ultra mode 0 to 2 on
157 * 40 connector cable and to 4 on 80 connector one.
158 * Clock unit is 15ns (66Mhz)
159 *
160 * 3 Values can be programmed:
161 * - Write data setup, which appears to match the cycle time. They
162 * also call it DIOW setup.
163 * - Ready to pause time (from spec)
164 * - Address setup. That one is weird. I don't see where exactly
165 * it fits in UDMA cycles, I got it's name from an obscure piece
166 * of commented out code in Darwin. They leave it to 0, we do as
167 * well, despite a comment that would lead to think it has a
168 * min value of 45ns.
169 * Apple also add 60ns to the write data setup (or cycle time ?) on
170 * reads.
171 */
172#define TR_66_UDMA_MASK 0xfff00000
173#define TR_66_UDMA_EN 0x00100000 /* Enable Ultra mode for DMA */
174#define TR_66_UDMA_ADDRSETUP_MASK 0xe0000000 /* Address setup */
175#define TR_66_UDMA_ADDRSETUP_SHIFT 29
176#define TR_66_UDMA_RDY2PAUS_MASK 0x1e000000 /* Ready 2 pause time */
177#define TR_66_UDMA_RDY2PAUS_SHIFT 25
178#define TR_66_UDMA_WRDATASETUP_MASK 0x01e00000 /* Write data setup time */
179#define TR_66_UDMA_WRDATASETUP_SHIFT 21
180#define TR_66_MDMA_MASK 0x000ffc00
181#define TR_66_MDMA_RECOVERY_MASK 0x000f8000
182#define TR_66_MDMA_RECOVERY_SHIFT 15
183#define TR_66_MDMA_ACCESS_MASK 0x00007c00
184#define TR_66_MDMA_ACCESS_SHIFT 10
185#define TR_66_PIO_MASK 0x000003ff
186#define TR_66_PIO_RECOVERY_MASK 0x000003e0
187#define TR_66_PIO_RECOVERY_SHIFT 5
188#define TR_66_PIO_ACCESS_MASK 0x0000001f
189#define TR_66_PIO_ACCESS_SHIFT 0
190
191/* 33Mhz cell, found in OHare, Heathrow (& Paddington) and KeyLargo
192 * Can do pio & mdma modes, clock unit is 30ns (33Mhz)
193 *
194 * The access time and recovery time can be programmed. Some older
195 * Darwin code base limit OHare to 150ns cycle time. I decided to do
196 * the same here fore safety against broken old hardware ;)
197 * The HalfTick bit, when set, adds half a clock (15ns) to the access
198 * time and removes one from recovery. It's not supported on KeyLargo
199 * implementation afaik. The E bit appears to be set for PIO mode 0 and
200 * is used to reach long timings used in this mode.
201 */
202#define TR_33_MDMA_MASK 0x003ff800
203#define TR_33_MDMA_RECOVERY_MASK 0x001f0000
204#define TR_33_MDMA_RECOVERY_SHIFT 16
205#define TR_33_MDMA_ACCESS_MASK 0x0000f800
206#define TR_33_MDMA_ACCESS_SHIFT 11
207#define TR_33_MDMA_HALFTICK 0x00200000
208#define TR_33_PIO_MASK 0x000007ff
209#define TR_33_PIO_E 0x00000400
210#define TR_33_PIO_RECOVERY_MASK 0x000003e0
211#define TR_33_PIO_RECOVERY_SHIFT 5
212#define TR_33_PIO_ACCESS_MASK 0x0000001f
213#define TR_33_PIO_ACCESS_SHIFT 0
214
215/*
216 * Interrupt register definitions
217 */
218#define IDE_INTR_DMA 0x80000000
219#define IDE_INTR_DEVICE 0x40000000
220
221/*
222 * FCR Register on Kauai. Not sure what bit 0x4 is ...
223 */
224#define KAUAI_FCR_UATA_MAGIC 0x00000004
225#define KAUAI_FCR_UATA_RESET_N 0x00000002
226#define KAUAI_FCR_UATA_ENABLE 0x00000001
227
228#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
229
230/* Rounded Multiword DMA timings
231 *
232 * I gave up finding a generic formula for all controller
233 * types and instead, built tables based on timing values
234 * used by Apple in Darwin's implementation.
235 */
236struct mdma_timings_t {
237 int accessTime;
238 int recoveryTime;
239 int cycleTime;
240};
241
aacaf9bd 242struct mdma_timings_t mdma_timings_33[] =
1da177e4
LT
243{
244 { 240, 240, 480 },
245 { 180, 180, 360 },
246 { 135, 135, 270 },
247 { 120, 120, 240 },
248 { 105, 105, 210 },
249 { 90, 90, 180 },
250 { 75, 75, 150 },
251 { 75, 45, 120 },
252 { 0, 0, 0 }
253};
254
aacaf9bd 255struct mdma_timings_t mdma_timings_33k[] =
1da177e4
LT
256{
257 { 240, 240, 480 },
258 { 180, 180, 360 },
259 { 150, 150, 300 },
260 { 120, 120, 240 },
261 { 90, 120, 210 },
262 { 90, 90, 180 },
263 { 90, 60, 150 },
264 { 90, 30, 120 },
265 { 0, 0, 0 }
266};
267
aacaf9bd 268struct mdma_timings_t mdma_timings_66[] =
1da177e4
LT
269{
270 { 240, 240, 480 },
271 { 180, 180, 360 },
272 { 135, 135, 270 },
273 { 120, 120, 240 },
274 { 105, 105, 210 },
275 { 90, 90, 180 },
276 { 90, 75, 165 },
277 { 75, 45, 120 },
278 { 0, 0, 0 }
279};
280
281/* KeyLargo ATA-4 Ultra DMA timings (rounded) */
282struct {
283 int addrSetup; /* ??? */
284 int rdy2pause;
285 int wrDataSetup;
aacaf9bd 286} kl66_udma_timings[] =
1da177e4
LT
287{
288 { 0, 180, 120 }, /* Mode 0 */
289 { 0, 150, 90 }, /* 1 */
290 { 0, 120, 60 }, /* 2 */
291 { 0, 90, 45 }, /* 3 */
292 { 0, 90, 30 } /* 4 */
293};
294
295/* UniNorth 2 ATA/100 timings */
296struct kauai_timing {
297 int cycle_time;
298 u32 timing_reg;
299};
300
aacaf9bd 301static struct kauai_timing kauai_pio_timings[] =
1da177e4
LT
302{
303 { 930 , 0x08000fff },
304 { 600 , 0x08000a92 },
305 { 383 , 0x0800060f },
306 { 360 , 0x08000492 },
307 { 330 , 0x0800048f },
308 { 300 , 0x080003cf },
309 { 270 , 0x080003cc },
310 { 240 , 0x0800038b },
311 { 239 , 0x0800030c },
312 { 180 , 0x05000249 },
c15d5d43
BZ
313 { 120 , 0x04000148 },
314 { 0 , 0 },
1da177e4
LT
315};
316
aacaf9bd 317static struct kauai_timing kauai_mdma_timings[] =
1da177e4
LT
318{
319 { 1260 , 0x00fff000 },
320 { 480 , 0x00618000 },
321 { 360 , 0x00492000 },
322 { 270 , 0x0038e000 },
323 { 240 , 0x0030c000 },
324 { 210 , 0x002cb000 },
325 { 180 , 0x00249000 },
326 { 150 , 0x00209000 },
327 { 120 , 0x00148000 },
328 { 0 , 0 },
329};
330
aacaf9bd 331static struct kauai_timing kauai_udma_timings[] =
1da177e4
LT
332{
333 { 120 , 0x000070c0 },
334 { 90 , 0x00005d80 },
335 { 60 , 0x00004a60 },
336 { 45 , 0x00003a50 },
337 { 30 , 0x00002a30 },
338 { 20 , 0x00002921 },
339 { 0 , 0 },
340};
341
aacaf9bd 342static struct kauai_timing shasta_pio_timings[] =
1da177e4
LT
343{
344 { 930 , 0x08000fff },
345 { 600 , 0x0A000c97 },
346 { 383 , 0x07000712 },
347 { 360 , 0x040003cd },
348 { 330 , 0x040003cd },
349 { 300 , 0x040003cd },
350 { 270 , 0x040003cd },
351 { 240 , 0x040003cd },
352 { 239 , 0x040003cd },
353 { 180 , 0x0400028b },
c15d5d43
BZ
354 { 120 , 0x0400010a },
355 { 0 , 0 },
1da177e4
LT
356};
357
aacaf9bd 358static struct kauai_timing shasta_mdma_timings[] =
1da177e4
LT
359{
360 { 1260 , 0x00fff000 },
361 { 480 , 0x00820800 },
362 { 360 , 0x00820800 },
363 { 270 , 0x00820800 },
364 { 240 , 0x00820800 },
365 { 210 , 0x00820800 },
366 { 180 , 0x00820800 },
367 { 150 , 0x0028b000 },
368 { 120 , 0x001ca000 },
369 { 0 , 0 },
370};
371
aacaf9bd 372static struct kauai_timing shasta_udma133_timings[] =
1da177e4
LT
373{
374 { 120 , 0x00035901, },
375 { 90 , 0x000348b1, },
376 { 60 , 0x00033881, },
377 { 45 , 0x00033861, },
378 { 30 , 0x00033841, },
379 { 20 , 0x00033031, },
380 { 15 , 0x00033021, },
381 { 0 , 0 },
382};
383
384
385static inline u32
386kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
387{
388 int i;
389
390 for (i=0; table[i].cycle_time; i++)
391 if (cycle_time > table[i+1].cycle_time)
392 return table[i].timing_reg;
90a87ea4 393 BUG();
1da177e4
LT
394 return 0;
395}
396
397/* allow up to 256 DBDMA commands per xfer */
398#define MAX_DCMDS 256
399
400/*
401 * Wait 1s for disk to answer on IDE bus after a hard reset
402 * of the device (via GPIO/FCR).
403 *
404 * Some devices seem to "pollute" the bus even after dropping
405 * the BSY bit (typically some combo drives slave on the UDMA
406 * bus) after a hard reset. Since we hard reset all drives on
407 * KeyLargo ATA66, we have to keep that delay around. I may end
408 * up not hard resetting anymore on these and keep the delay only
409 * for older interfaces instead (we have to reset when coming
410 * from MacOS...) --BenH.
411 */
412#define IDE_WAKEUP_DELAY (1*HZ)
413
c413b9b9 414static int pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
1da177e4 415static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
1da177e4
LT
416static void pmac_ide_selectproc(ide_drive_t *drive);
417static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
418
419#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
420
1da177e4
LT
421/*
422 * N.B. this can't be an initfunc, because the media-bay task can
423 * call ide_[un]register at any time.
424 */
aacaf9bd 425void
1da177e4
LT
426pmac_ide_init_hwif_ports(hw_regs_t *hw,
427 unsigned long data_port, unsigned long ctrl_port,
428 int *irq)
429{
430 int i, ix;
431
432 if (data_port == 0)
433 return;
434
435 for (ix = 0; ix < MAX_HWIFS; ++ix)
436 if (data_port == pmac_ide[ix].regbase)
437 break;
438
d26805fd
BZ
439 if (ix >= MAX_HWIFS)
440 return; /* not an IDE PMAC interface */
1da177e4
LT
441
442 for (i = 0; i < 8; ++i)
443 hw->io_ports[i] = data_port + i * 0x10;
444 hw->io_ports[8] = data_port + 0x160;
445
446 if (irq != NULL)
447 *irq = pmac_ide[ix].irq;
22192ccd
BH
448
449 hw->dev = &pmac_ide[ix].mdev->ofdev.dev;
1da177e4
LT
450}
451
23579a2a
BZ
452#define PMAC_IDE_REG(x) \
453 ((void __iomem *)((drive)->hwif->io_ports[IDE_DATA_OFFSET] + (x)))
1da177e4
LT
454
455/*
456 * Apply the timings of the proper unit (master/slave) to the shared
457 * timing register when selecting that unit. This version is for
458 * ASICs with a single timing register
459 */
aacaf9bd 460static void
1da177e4
LT
461pmac_ide_selectproc(ide_drive_t *drive)
462{
463 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
464
465 if (pmif == NULL)
466 return;
467
468 if (drive->select.b.unit & 0x01)
469 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
470 else
471 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
472 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
473}
474
475/*
476 * Apply the timings of the proper unit (master/slave) to the shared
477 * timing register when selecting that unit. This version is for
478 * ASICs with a dual timing register (Kauai)
479 */
aacaf9bd 480static void
1da177e4
LT
481pmac_ide_kauai_selectproc(ide_drive_t *drive)
482{
483 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
484
485 if (pmif == NULL)
486 return;
487
488 if (drive->select.b.unit & 0x01) {
489 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
490 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
491 } else {
492 writel(pmif->timings[0], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
493 writel(pmif->timings[2], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
494 }
495 (void)readl(PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
496}
497
498/*
499 * Force an update of controller timing values for a given drive
500 */
aacaf9bd 501static void
1da177e4
LT
502pmac_ide_do_update_timings(ide_drive_t *drive)
503{
504 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
505
506 if (pmif == NULL)
507 return;
508
509 if (pmif->kind == controller_sh_ata6 ||
510 pmif->kind == controller_un_ata6 ||
511 pmif->kind == controller_k2_ata6)
512 pmac_ide_kauai_selectproc(drive);
513 else
514 pmac_ide_selectproc(drive);
515}
516
517static void
518pmac_outbsync(ide_drive_t *drive, u8 value, unsigned long port)
519{
520 u32 tmp;
521
522 writeb(value, (void __iomem *) port);
523 tmp = readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
524}
525
1da177e4
LT
526/*
527 * Old tuning functions (called on hdparm -p), sets up drive PIO timings
528 */
aacaf9bd 529static void
26bcb879 530pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
1da177e4 531{
0b46ff2e 532 u32 *timings, t;
1da177e4
LT
533 unsigned accessTicks, recTicks;
534 unsigned accessTime, recTime;
535 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
7dd00083
BZ
536 unsigned int cycle_time;
537
1da177e4
LT
538 if (pmif == NULL)
539 return;
540
541 /* which drive is it ? */
542 timings = &pmif->timings[drive->select.b.unit & 0x01];
0b46ff2e 543 t = *timings;
1da177e4 544
7dd00083 545 cycle_time = ide_pio_cycle_time(drive, pio);
1da177e4
LT
546
547 switch (pmif->kind) {
548 case controller_sh_ata6: {
549 /* 133Mhz cell */
7dd00083 550 u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time);
0b46ff2e 551 t = (t & ~TR_133_PIOREG_PIO_MASK) | tr;
1da177e4
LT
552 break;
553 }
554 case controller_un_ata6:
555 case controller_k2_ata6: {
556 /* 100Mhz cell */
7dd00083 557 u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time);
0b46ff2e 558 t = (t & ~TR_100_PIOREG_PIO_MASK) | tr;
1da177e4
LT
559 break;
560 }
561 case controller_kl_ata4:
562 /* 66Mhz cell */
7dd00083 563 recTime = cycle_time - ide_pio_timings[pio].active_time
1da177e4
LT
564 - ide_pio_timings[pio].setup_time;
565 recTime = max(recTime, 150U);
566 accessTime = ide_pio_timings[pio].active_time;
567 accessTime = max(accessTime, 150U);
568 accessTicks = SYSCLK_TICKS_66(accessTime);
569 accessTicks = min(accessTicks, 0x1fU);
570 recTicks = SYSCLK_TICKS_66(recTime);
571 recTicks = min(recTicks, 0x1fU);
0b46ff2e
BH
572 t = (t & ~TR_66_PIO_MASK) |
573 (accessTicks << TR_66_PIO_ACCESS_SHIFT) |
574 (recTicks << TR_66_PIO_RECOVERY_SHIFT);
1da177e4
LT
575 break;
576 default: {
577 /* 33Mhz cell */
578 int ebit = 0;
7dd00083 579 recTime = cycle_time - ide_pio_timings[pio].active_time
1da177e4
LT
580 - ide_pio_timings[pio].setup_time;
581 recTime = max(recTime, 150U);
582 accessTime = ide_pio_timings[pio].active_time;
583 accessTime = max(accessTime, 150U);
584 accessTicks = SYSCLK_TICKS(accessTime);
585 accessTicks = min(accessTicks, 0x1fU);
586 accessTicks = max(accessTicks, 4U);
587 recTicks = SYSCLK_TICKS(recTime);
588 recTicks = min(recTicks, 0x1fU);
589 recTicks = max(recTicks, 5U) - 4;
590 if (recTicks > 9) {
591 recTicks--; /* guess, but it's only for PIO0, so... */
592 ebit = 1;
593 }
0b46ff2e 594 t = (t & ~TR_33_PIO_MASK) |
1da177e4
LT
595 (accessTicks << TR_33_PIO_ACCESS_SHIFT) |
596 (recTicks << TR_33_PIO_RECOVERY_SHIFT);
597 if (ebit)
0b46ff2e 598 t |= TR_33_PIO_E;
1da177e4
LT
599 break;
600 }
601 }
602
603#ifdef IDE_PMAC_DEBUG
604 printk(KERN_ERR "%s: Set PIO timing for mode %d, reg: 0x%08x\n",
605 drive->name, pio, *timings);
606#endif
607
0b46ff2e 608 *timings = t;
c15d5d43 609 pmac_ide_do_update_timings(drive);
1da177e4
LT
610}
611
612#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
613
614/*
615 * Calculate KeyLargo ATA/66 UDMA timings
616 */
aacaf9bd 617static int
1da177e4
LT
618set_timings_udma_ata4(u32 *timings, u8 speed)
619{
620 unsigned rdyToPauseTicks, wrDataSetupTicks, addrTicks;
621
622 if (speed > XFER_UDMA_4)
623 return 1;
624
625 rdyToPauseTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].rdy2pause);
626 wrDataSetupTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].wrDataSetup);
627 addrTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].addrSetup);
628
629 *timings = ((*timings) & ~(TR_66_UDMA_MASK | TR_66_MDMA_MASK)) |
630 (wrDataSetupTicks << TR_66_UDMA_WRDATASETUP_SHIFT) |
631 (rdyToPauseTicks << TR_66_UDMA_RDY2PAUS_SHIFT) |
632 (addrTicks <<TR_66_UDMA_ADDRSETUP_SHIFT) |
633 TR_66_UDMA_EN;
634#ifdef IDE_PMAC_DEBUG
635 printk(KERN_ERR "ide_pmac: Set UDMA timing for mode %d, reg: 0x%08x\n",
636 speed & 0xf, *timings);
637#endif
638
639 return 0;
640}
641
642/*
643 * Calculate Kauai ATA/100 UDMA timings
644 */
aacaf9bd 645static int
1da177e4
LT
646set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed)
647{
648 struct ide_timing *t = ide_timing_find_mode(speed);
649 u32 tr;
650
651 if (speed > XFER_UDMA_5 || t == NULL)
652 return 1;
653 tr = kauai_lookup_timing(kauai_udma_timings, (int)t->udma);
1da177e4
LT
654 *ultra_timings = ((*ultra_timings) & ~TR_100_UDMAREG_UDMA_MASK) | tr;
655 *ultra_timings = (*ultra_timings) | TR_100_UDMAREG_UDMA_EN;
656
657 return 0;
658}
659
660/*
661 * Calculate Shasta ATA/133 UDMA timings
662 */
aacaf9bd 663static int
1da177e4
LT
664set_timings_udma_shasta(u32 *pio_timings, u32 *ultra_timings, u8 speed)
665{
666 struct ide_timing *t = ide_timing_find_mode(speed);
667 u32 tr;
668
669 if (speed > XFER_UDMA_6 || t == NULL)
670 return 1;
671 tr = kauai_lookup_timing(shasta_udma133_timings, (int)t->udma);
1da177e4
LT
672 *ultra_timings = ((*ultra_timings) & ~TR_133_UDMAREG_UDMA_MASK) | tr;
673 *ultra_timings = (*ultra_timings) | TR_133_UDMAREG_UDMA_EN;
674
675 return 0;
676}
677
678/*
679 * Calculate MDMA timings for all cells
680 */
90f72eca 681static void
1da177e4 682set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
90f72eca 683 u8 speed)
1da177e4
LT
684{
685 int cycleTime, accessTime = 0, recTime = 0;
686 unsigned accessTicks, recTicks;
90f72eca 687 struct hd_driveid *id = drive->id;
1da177e4
LT
688 struct mdma_timings_t* tm = NULL;
689 int i;
690
691 /* Get default cycle time for mode */
692 switch(speed & 0xf) {
693 case 0: cycleTime = 480; break;
694 case 1: cycleTime = 150; break;
695 case 2: cycleTime = 120; break;
696 default:
90f72eca
BZ
697 BUG();
698 break;
1da177e4 699 }
90f72eca
BZ
700
701 /* Check if drive provides explicit DMA cycle time */
702 if ((id->field_valid & 2) && id->eide_dma_time)
703 cycleTime = max_t(int, id->eide_dma_time, cycleTime);
704
1da177e4
LT
705 /* OHare limits according to some old Apple sources */
706 if ((intf_type == controller_ohare) && (cycleTime < 150))
707 cycleTime = 150;
708 /* Get the proper timing array for this controller */
709 switch(intf_type) {
710 case controller_sh_ata6:
711 case controller_un_ata6:
712 case controller_k2_ata6:
713 break;
714 case controller_kl_ata4:
715 tm = mdma_timings_66;
716 break;
717 case controller_kl_ata3:
718 tm = mdma_timings_33k;
719 break;
720 default:
721 tm = mdma_timings_33;
722 break;
723 }
724 if (tm != NULL) {
725 /* Lookup matching access & recovery times */
726 i = -1;
727 for (;;) {
728 if (tm[i+1].cycleTime < cycleTime)
729 break;
730 i++;
731 }
1da177e4
LT
732 cycleTime = tm[i].cycleTime;
733 accessTime = tm[i].accessTime;
734 recTime = tm[i].recoveryTime;
735
736#ifdef IDE_PMAC_DEBUG
737 printk(KERN_ERR "%s: MDMA, cycleTime: %d, accessTime: %d, recTime: %d\n",
738 drive->name, cycleTime, accessTime, recTime);
739#endif
740 }
741 switch(intf_type) {
742 case controller_sh_ata6: {
743 /* 133Mhz cell */
744 u32 tr = kauai_lookup_timing(shasta_mdma_timings, cycleTime);
1da177e4
LT
745 *timings = ((*timings) & ~TR_133_PIOREG_MDMA_MASK) | tr;
746 *timings2 = (*timings2) & ~TR_133_UDMAREG_UDMA_EN;
747 }
748 case controller_un_ata6:
749 case controller_k2_ata6: {
750 /* 100Mhz cell */
751 u32 tr = kauai_lookup_timing(kauai_mdma_timings, cycleTime);
1da177e4
LT
752 *timings = ((*timings) & ~TR_100_PIOREG_MDMA_MASK) | tr;
753 *timings2 = (*timings2) & ~TR_100_UDMAREG_UDMA_EN;
754 }
755 break;
756 case controller_kl_ata4:
757 /* 66Mhz cell */
758 accessTicks = SYSCLK_TICKS_66(accessTime);
759 accessTicks = min(accessTicks, 0x1fU);
760 accessTicks = max(accessTicks, 0x1U);
761 recTicks = SYSCLK_TICKS_66(recTime);
762 recTicks = min(recTicks, 0x1fU);
763 recTicks = max(recTicks, 0x3U);
764 /* Clear out mdma bits and disable udma */
765 *timings = ((*timings) & ~(TR_66_MDMA_MASK | TR_66_UDMA_MASK)) |
766 (accessTicks << TR_66_MDMA_ACCESS_SHIFT) |
767 (recTicks << TR_66_MDMA_RECOVERY_SHIFT);
768 break;
769 case controller_kl_ata3:
770 /* 33Mhz cell on KeyLargo */
771 accessTicks = SYSCLK_TICKS(accessTime);
772 accessTicks = max(accessTicks, 1U);
773 accessTicks = min(accessTicks, 0x1fU);
774 accessTime = accessTicks * IDE_SYSCLK_NS;
775 recTicks = SYSCLK_TICKS(recTime);
776 recTicks = max(recTicks, 1U);
777 recTicks = min(recTicks, 0x1fU);
778 *timings = ((*timings) & ~TR_33_MDMA_MASK) |
779 (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
780 (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
781 break;
782 default: {
783 /* 33Mhz cell on others */
784 int halfTick = 0;
785 int origAccessTime = accessTime;
786 int origRecTime = recTime;
787
788 accessTicks = SYSCLK_TICKS(accessTime);
789 accessTicks = max(accessTicks, 1U);
790 accessTicks = min(accessTicks, 0x1fU);
791 accessTime = accessTicks * IDE_SYSCLK_NS;
792 recTicks = SYSCLK_TICKS(recTime);
793 recTicks = max(recTicks, 2U) - 1;
794 recTicks = min(recTicks, 0x1fU);
795 recTime = (recTicks + 1) * IDE_SYSCLK_NS;
796 if ((accessTicks > 1) &&
797 ((accessTime - IDE_SYSCLK_NS/2) >= origAccessTime) &&
798 ((recTime - IDE_SYSCLK_NS/2) >= origRecTime)) {
799 halfTick = 1;
800 accessTicks--;
801 }
802 *timings = ((*timings) & ~TR_33_MDMA_MASK) |
803 (accessTicks << TR_33_MDMA_ACCESS_SHIFT) |
804 (recTicks << TR_33_MDMA_RECOVERY_SHIFT);
805 if (halfTick)
806 *timings |= TR_33_MDMA_HALFTICK;
807 }
808 }
809#ifdef IDE_PMAC_DEBUG
810 printk(KERN_ERR "%s: Set MDMA timing for mode %d, reg: 0x%08x\n",
811 drive->name, speed & 0xf, *timings);
812#endif
1da177e4
LT
813}
814#endif /* #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC */
815
88b2b32b 816static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
1da177e4
LT
817{
818 int unit = (drive->select.b.unit & 0x01);
819 int ret = 0;
820 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
085798b1 821 u32 *timings, *timings2, tl[2];
1da177e4 822
1da177e4
LT
823 timings = &pmif->timings[unit];
824 timings2 = &pmif->timings[unit+2];
085798b1
BZ
825
826 /* Copy timings to local image */
827 tl[0] = *timings;
828 tl[1] = *timings2;
829
1da177e4 830#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
4db90a14
BZ
831 if (speed >= XFER_UDMA_0) {
832 if (pmif->kind == controller_kl_ata4)
833 ret = set_timings_udma_ata4(&tl[0], speed);
834 else if (pmif->kind == controller_un_ata6
835 || pmif->kind == controller_k2_ata6)
836 ret = set_timings_udma_ata6(&tl[0], &tl[1], speed);
837 else if (pmif->kind == controller_sh_ata6)
838 ret = set_timings_udma_shasta(&tl[0], &tl[1], speed);
839 else
840 ret = -1;
841 } else
842 set_timings_mdma(drive, pmif->kind, &tl[0], &tl[1], speed);
1da177e4 843#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
1da177e4 844 if (ret)
88b2b32b 845 return;
085798b1
BZ
846
847 /* Apply timings to controller */
848 *timings = tl[0];
849 *timings2 = tl[1];
850
1da177e4 851 pmac_ide_do_update_timings(drive);
1da177e4
LT
852}
853
854/*
855 * Blast some well known "safe" values to the timing registers at init or
856 * wakeup from sleep time, before we do real calculation
857 */
aacaf9bd 858static void
1da177e4
LT
859sanitize_timings(pmac_ide_hwif_t *pmif)
860{
861 unsigned int value, value2 = 0;
862
863 switch(pmif->kind) {
864 case controller_sh_ata6:
865 value = 0x0a820c97;
866 value2 = 0x00033031;
867 break;
868 case controller_un_ata6:
869 case controller_k2_ata6:
870 value = 0x08618a92;
871 value2 = 0x00002921;
872 break;
873 case controller_kl_ata4:
874 value = 0x0008438c;
875 break;
876 case controller_kl_ata3:
877 value = 0x00084526;
878 break;
879 case controller_heathrow:
880 case controller_ohare:
881 default:
882 value = 0x00074526;
883 break;
884 }
885 pmif->timings[0] = pmif->timings[1] = value;
886 pmif->timings[2] = pmif->timings[3] = value2;
887}
888
aacaf9bd 889unsigned long
1da177e4
LT
890pmac_ide_get_base(int index)
891{
892 return pmac_ide[index].regbase;
893}
894
1da177e4
LT
895/* Suspend call back, should be called after the child devices
896 * have actually been suspended
897 */
898static int
899pmac_ide_do_suspend(ide_hwif_t *hwif)
900{
901 pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
902
903 /* We clear the timings */
904 pmif->timings[0] = 0;
905 pmif->timings[1] = 0;
906
616299af
BH
907 disable_irq(pmif->irq);
908
1da177e4
LT
909 /* The media bay will handle itself just fine */
910 if (pmif->mediabay)
911 return 0;
912
913 /* Kauai has bus control FCRs directly here */
914 if (pmif->kauai_fcr) {
915 u32 fcr = readl(pmif->kauai_fcr);
916 fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE);
917 writel(fcr, pmif->kauai_fcr);
918 }
919
920 /* Disable the bus on older machines and the cell on kauai */
921 ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id,
922 0);
923
924 return 0;
925}
926
927/* Resume call back, should be called before the child devices
928 * are resumed
929 */
930static int
931pmac_ide_do_resume(ide_hwif_t *hwif)
932{
933 pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
934
935 /* Hard reset & re-enable controller (do we really need to reset ? -BenH) */
936 if (!pmif->mediabay) {
937 ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 1);
938 ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 1);
939 msleep(10);
940 ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 0);
1da177e4
LT
941
942 /* Kauai has it different */
943 if (pmif->kauai_fcr) {
944 u32 fcr = readl(pmif->kauai_fcr);
945 fcr |= KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE;
946 writel(fcr, pmif->kauai_fcr);
947 }
616299af
BH
948
949 msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
1da177e4
LT
950 }
951
952 /* Sanitize drive timings */
953 sanitize_timings(pmif);
954
616299af
BH
955 enable_irq(pmif->irq);
956
1da177e4
LT
957 return 0;
958}
959
c413b9b9
BZ
960static const struct ide_port_info pmac_port_info = {
961 .chipset = ide_pmac,
962 .host_flags = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
963 IDE_HFLAG_PIO_NO_DOWNGRADE |
964 IDE_HFLAG_POST_SET_MODE |
965 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
966 IDE_HFLAG_UNMASK_IRQS,
967 .pio_mask = ATA_PIO4,
968 .mwdma_mask = ATA_MWDMA2,
969};
970
1da177e4
LT
971/*
972 * Setup, register & probe an IDE channel driven by this driver, this is
973 * called by one of the 2 probe functions (macio or PCI). Note that a channel
974 * that ends up beeing free of any device is not kept around by this driver
975 * (it is kept in 2.4). This introduce an interface numbering change on some
976 * rare machines unfortunately, but it's better this way.
977 */
468e4681 978static int __devinit
57c802e8 979pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
1da177e4
LT
980{
981 struct device_node *np = pmif->node;
018a3d1d 982 const int *bidp;
8447d9d5 983 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
c413b9b9 984 struct ide_port_info d = pmac_port_info;
1da177e4
LT
985
986 pmif->cable_80 = 0;
987 pmif->broken_dma = pmif->broken_dma_warn = 0;
c413b9b9 988 if (of_device_is_compatible(np, "shasta-ata")) {
1da177e4 989 pmif->kind = controller_sh_ata6;
c413b9b9
BZ
990 d.udma_mask = ATA_UDMA6;
991 } else if (of_device_is_compatible(np, "kauai-ata")) {
1da177e4 992 pmif->kind = controller_un_ata6;
c413b9b9
BZ
993 d.udma_mask = ATA_UDMA5;
994 } else if (of_device_is_compatible(np, "K2-UATA")) {
1da177e4 995 pmif->kind = controller_k2_ata6;
c413b9b9
BZ
996 d.udma_mask = ATA_UDMA5;
997 } else if (of_device_is_compatible(np, "keylargo-ata")) {
998 if (strcmp(np->name, "ata-4") == 0) {
1da177e4 999 pmif->kind = controller_kl_ata4;
c413b9b9
BZ
1000 d.udma_mask = ATA_UDMA4;
1001 } else
1da177e4 1002 pmif->kind = controller_kl_ata3;
c413b9b9 1003 } else if (of_device_is_compatible(np, "heathrow-ata")) {
1da177e4 1004 pmif->kind = controller_heathrow;
c413b9b9 1005 } else {
1da177e4
LT
1006 pmif->kind = controller_ohare;
1007 pmif->broken_dma = 1;
1008 }
1009
40cd3a45 1010 bidp = of_get_property(np, "AAPL,bus-id", NULL);
1da177e4
LT
1011 pmif->aapl_bus_id = bidp ? *bidp : 0;
1012
1013 /* Get cable type from device-tree */
1014 if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
1015 || pmif->kind == controller_k2_ata6
1016 || pmif->kind == controller_sh_ata6) {
40cd3a45 1017 const char* cable = of_get_property(np, "cable-type", NULL);
1da177e4
LT
1018 if (cable && !strncmp(cable, "80-", 3))
1019 pmif->cable_80 = 1;
1020 }
1021 /* G5's seem to have incorrect cable type in device-tree. Let's assume
1022 * they have a 80 conductor cable, this seem to be always the case unless
1023 * the user mucked around
1024 */
55b61fec
SR
1025 if (of_device_is_compatible(np, "K2-UATA") ||
1026 of_device_is_compatible(np, "shasta-ata"))
1da177e4
LT
1027 pmif->cable_80 = 1;
1028
1029 /* On Kauai-type controllers, we make sure the FCR is correct */
1030 if (pmif->kauai_fcr)
1031 writel(KAUAI_FCR_UATA_MAGIC |
1032 KAUAI_FCR_UATA_RESET_N |
1033 KAUAI_FCR_UATA_ENABLE, pmif->kauai_fcr);
1034
1035 pmif->mediabay = 0;
1036
1037 /* Make sure we have sane timings */
1038 sanitize_timings(pmif);
1039
1040#ifndef CONFIG_PPC64
1041 /* XXX FIXME: Media bay stuff need re-organizing */
1042 if (np->parent && np->parent->name
1043 && strcasecmp(np->parent->name, "media-bay") == 0) {
8c870933 1044#ifdef CONFIG_PMAC_MEDIABAY
2dde7861
BZ
1045 media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq,
1046 hwif);
8c870933 1047#endif /* CONFIG_PMAC_MEDIABAY */
1da177e4
LT
1048 pmif->mediabay = 1;
1049 if (!bidp)
1050 pmif->aapl_bus_id = 1;
1051 } else if (pmif->kind == controller_ohare) {
1052 /* The code below is having trouble on some ohare machines
1053 * (timing related ?). Until I can put my hand on one of these
1054 * units, I keep the old way
1055 */
1056 ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, 0, 1);
1057 } else
1058#endif
1059 {
1060 /* This is necessary to enable IDE when net-booting */
1061 ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 1);
1062 ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, pmif->aapl_bus_id, 1);
1063 msleep(10);
1064 ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 0);
1065 msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
1066 }
1067
1068 /* Setup MMIO ops */
1069 default_hwif_mmiops(hwif);
1070 hwif->OUTBSYNC = pmac_outbsync;
1071
1072 /* Tell common code _not_ to mess with resources */
2ad1e558 1073 hwif->mmio = 1;
1da177e4 1074 hwif->hwif_data = pmif;
57c802e8
BZ
1075 ide_init_port_hw(hwif, hw);
1076 hwif->noprobe = pmif->mediabay;
49521f97 1077 hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
26bcb879 1078 hwif->set_pio_mode = pmac_ide_set_pio_mode;
1da177e4
LT
1079 if (pmif->kind == controller_un_ata6
1080 || pmif->kind == controller_k2_ata6
1081 || pmif->kind == controller_sh_ata6)
1082 hwif->selectproc = pmac_ide_kauai_selectproc;
1083 else
1084 hwif->selectproc = pmac_ide_selectproc;
88b2b32b 1085 hwif->set_dma_mode = pmac_ide_set_dma_mode;
1da177e4 1086
1da177e4
LT
1087 printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
1088 hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
1089 pmif->mediabay ? " (mediabay)" : "", hwif->irq);
1090
8c870933 1091#ifdef CONFIG_PMAC_MEDIABAY
1da177e4
LT
1092 if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
1093 hwif->noprobe = 0;
8c870933 1094#endif /* CONFIG_PMAC_MEDIABAY */
1da177e4 1095
1da177e4 1096#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
c413b9b9
BZ
1097 if (pmif->cable_80 == 0)
1098 d.udma_mask &= ATA_UDMA2;
1da177e4 1099 /* has a DBDMA controller channel */
c413b9b9
BZ
1100 if (pmif->dma_regs == 0 || pmac_ide_setup_dma(pmif, hwif) < 0)
1101#endif
1102 d.udma_mask = d.mwdma_mask = 0;
1da177e4 1103
8447d9d5 1104 idx[0] = hwif->index;
1da177e4 1105
c413b9b9 1106 ide_device_add(idx, &d);
5cbf79cd 1107
1da177e4
LT
1108 return 0;
1109}
1110
1111/*
1112 * Attach to a macio probed interface
1113 */
1114static int __devinit
5e655772 1115pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1da177e4
LT
1116{
1117 void __iomem *base;
1118 unsigned long regbase;
1119 int irq;
1120 ide_hwif_t *hwif;
1121 pmac_ide_hwif_t *pmif;
1122 int i, rc;
57c802e8 1123 hw_regs_t hw;
1da177e4
LT
1124
1125 i = 0;
1126 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0
1127 || pmac_ide[i].node != NULL))
1128 ++i;
1129 if (i >= MAX_HWIFS) {
1130 printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
1131 printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name);
1132 return -ENODEV;
1133 }
1134
1135 pmif = &pmac_ide[i];
1136 hwif = &ide_hwifs[i];
1137
cc5d0189 1138 if (macio_resource_count(mdev) == 0) {
1da177e4
LT
1139 printk(KERN_WARNING "ide%d: no address for %s\n",
1140 i, mdev->ofdev.node->full_name);
1141 return -ENXIO;
1142 }
1143
1144 /* Request memory resource for IO ports */
1145 if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
1146 printk(KERN_ERR "ide%d: can't request mmio resource !\n", i);
1147 return -EBUSY;
1148 }
1149
1150 /* XXX This is bogus. Should be fixed in the registry by checking
1151 * the kind of host interrupt controller, a bit like gatwick
1152 * fixes in irq.c. That works well enough for the single case
1153 * where that happens though...
1154 */
1155 if (macio_irq_count(mdev) == 0) {
1156 printk(KERN_WARNING "ide%d: no intrs for device %s, using 13\n",
1157 i, mdev->ofdev.node->full_name);
69917c26 1158 irq = irq_create_mapping(NULL, 13);
1da177e4
LT
1159 } else
1160 irq = macio_irq(mdev, 0);
1161
1162 base = ioremap(macio_resource_start(mdev, 0), 0x400);
1163 regbase = (unsigned long) base;
1164
36501650 1165 hwif->dev = &mdev->bus->pdev->dev;
1da177e4
LT
1166
1167 pmif->mdev = mdev;
1168 pmif->node = mdev->ofdev.node;
1169 pmif->regbase = regbase;
1170 pmif->irq = irq;
1171 pmif->kauai_fcr = NULL;
1172#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
1173 if (macio_resource_count(mdev) >= 2) {
1174 if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
1175 printk(KERN_WARNING "ide%d: can't request DMA resource !\n", i);
1176 else
1177 pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000);
1178 } else
1179 pmif->dma_regs = NULL;
1180#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
1181 dev_set_drvdata(&mdev->ofdev.dev, hwif);
1182
57c802e8
BZ
1183 memset(&hw, 0, sizeof(hw));
1184 pmac_ide_init_hwif_ports(&hw, pmif->regbase, 0, NULL);
1185 hw.irq = irq;
1186 hw.dev = &mdev->ofdev.dev;
1187
1188 rc = pmac_ide_setup_device(pmif, hwif, &hw);
1da177e4
LT
1189 if (rc != 0) {
1190 /* The inteface is released to the common IDE layer */
1191 dev_set_drvdata(&mdev->ofdev.dev, NULL);
1192 iounmap(base);
ed908fa1 1193 if (pmif->dma_regs) {
1da177e4 1194 iounmap(pmif->dma_regs);
ed908fa1
BZ
1195 macio_release_resource(mdev, 1);
1196 }
1da177e4
LT
1197 memset(pmif, 0, sizeof(*pmif));
1198 macio_release_resource(mdev, 0);
1da177e4
LT
1199 }
1200
1201 return rc;
1202}
1203
1204static int
8b4b8a24 1205pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
1da177e4
LT
1206{
1207 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1208 int rc = 0;
1209
8b4b8a24 1210 if (mesg.event != mdev->ofdev.dev.power.power_state.event
3a2d5b70 1211 && (mesg.event & PM_EVENT_SLEEP)) {
1da177e4
LT
1212 rc = pmac_ide_do_suspend(hwif);
1213 if (rc == 0)
8b4b8a24 1214 mdev->ofdev.dev.power.power_state = mesg;
1da177e4
LT
1215 }
1216
1217 return rc;
1218}
1219
1220static int
1221pmac_ide_macio_resume(struct macio_dev *mdev)
1222{
1223 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1224 int rc = 0;
1225
ca078bae 1226 if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
1da177e4
LT
1227 rc = pmac_ide_do_resume(hwif);
1228 if (rc == 0)
829ca9a3 1229 mdev->ofdev.dev.power.power_state = PMSG_ON;
1da177e4
LT
1230 }
1231
1232 return rc;
1233}
1234
1235/*
1236 * Attach to a PCI probed interface
1237 */
1238static int __devinit
1239pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1240{
1241 ide_hwif_t *hwif;
1242 struct device_node *np;
1243 pmac_ide_hwif_t *pmif;
1244 void __iomem *base;
1245 unsigned long rbase, rlen;
1246 int i, rc;
57c802e8 1247 hw_regs_t hw;
1da177e4
LT
1248
1249 np = pci_device_to_OF_node(pdev);
1250 if (np == NULL) {
1251 printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
1252 return -ENODEV;
1253 }
1254 i = 0;
1255 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0
1256 || pmac_ide[i].node != NULL))
1257 ++i;
1258 if (i >= MAX_HWIFS) {
1259 printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
1260 printk(KERN_ERR " %s\n", np->full_name);
1261 return -ENODEV;
1262 }
1263
1264 pmif = &pmac_ide[i];
1265 hwif = &ide_hwifs[i];
1266
1267 if (pci_enable_device(pdev)) {
1268 printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n",
1269 i, np->full_name);
1270 return -ENXIO;
1271 }
1272 pci_set_master(pdev);
1273
1274 if (pci_request_regions(pdev, "Kauai ATA")) {
1275 printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n",
1276 i, np->full_name);
1277 return -ENXIO;
1278 }
1279
36501650 1280 hwif->dev = &pdev->dev;
1da177e4
LT
1281 pmif->mdev = NULL;
1282 pmif->node = np;
1283
1284 rbase = pci_resource_start(pdev, 0);
1285 rlen = pci_resource_len(pdev, 0);
1286
1287 base = ioremap(rbase, rlen);
1288 pmif->regbase = (unsigned long) base + 0x2000;
1289#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
1290 pmif->dma_regs = base + 0x1000;
1291#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
1292 pmif->kauai_fcr = base;
1293 pmif->irq = pdev->irq;
1294
1295 pci_set_drvdata(pdev, hwif);
1296
57c802e8
BZ
1297 memset(&hw, 0, sizeof(hw));
1298 pmac_ide_init_hwif_ports(&hw, pmif->regbase, 0, NULL);
1299 hw.irq = pdev->irq;
1300 hw.dev = &pdev->dev;
1301
1302 rc = pmac_ide_setup_device(pmif, hwif, &hw);
1da177e4
LT
1303 if (rc != 0) {
1304 /* The inteface is released to the common IDE layer */
1305 pci_set_drvdata(pdev, NULL);
1306 iounmap(base);
1307 memset(pmif, 0, sizeof(*pmif));
1308 pci_release_regions(pdev);
1309 }
1310
1311 return rc;
1312}
1313
1314static int
8b4b8a24 1315pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
1da177e4
LT
1316{
1317 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1318 int rc = 0;
1319
8b4b8a24 1320 if (mesg.event != pdev->dev.power.power_state.event
3a2d5b70 1321 && (mesg.event & PM_EVENT_SLEEP)) {
1da177e4
LT
1322 rc = pmac_ide_do_suspend(hwif);
1323 if (rc == 0)
8b4b8a24 1324 pdev->dev.power.power_state = mesg;
1da177e4
LT
1325 }
1326
1327 return rc;
1328}
1329
1330static int
1331pmac_ide_pci_resume(struct pci_dev *pdev)
1332{
1333 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1334 int rc = 0;
1335
ca078bae 1336 if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
1da177e4
LT
1337 rc = pmac_ide_do_resume(hwif);
1338 if (rc == 0)
829ca9a3 1339 pdev->dev.power.power_state = PMSG_ON;
1da177e4
LT
1340 }
1341
1342 return rc;
1343}
1344
5e655772 1345static struct of_device_id pmac_ide_macio_match[] =
1da177e4
LT
1346{
1347 {
1348 .name = "IDE",
1da177e4
LT
1349 },
1350 {
1351 .name = "ATA",
1da177e4
LT
1352 },
1353 {
1da177e4 1354 .type = "ide",
1da177e4
LT
1355 },
1356 {
1da177e4 1357 .type = "ata",
1da177e4
LT
1358 },
1359 {},
1360};
1361
1362static struct macio_driver pmac_ide_macio_driver =
1363{
1364 .name = "ide-pmac",
1365 .match_table = pmac_ide_macio_match,
1366 .probe = pmac_ide_macio_attach,
1367 .suspend = pmac_ide_macio_suspend,
1368 .resume = pmac_ide_macio_resume,
1369};
1370
9cbcc5e3
BZ
1371static const struct pci_device_id pmac_ide_pci_match[] = {
1372 { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA), 0 },
1373 { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100), 0 },
1374 { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100), 0 },
1375 { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_SH_ATA), 0 },
1376 { PCI_VDEVICE(APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA), 0 },
71e4eda8 1377 {},
1da177e4
LT
1378};
1379
1380static struct pci_driver pmac_ide_pci_driver = {
1381 .name = "ide-pmac",
1382 .id_table = pmac_ide_pci_match,
1383 .probe = pmac_ide_pci_attach,
1384 .suspend = pmac_ide_pci_suspend,
1385 .resume = pmac_ide_pci_resume,
1386};
1387MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
1388
9e5755bc 1389int __init pmac_ide_probe(void)
1da177e4 1390{
9e5755bc
AM
1391 int error;
1392
e8222502 1393 if (!machine_is(powermac))
9e5755bc 1394 return -ENODEV;
1da177e4
LT
1395
1396#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
9e5755bc
AM
1397 error = pci_register_driver(&pmac_ide_pci_driver);
1398 if (error)
1399 goto out;
1400 error = macio_register_driver(&pmac_ide_macio_driver);
1401 if (error) {
1402 pci_unregister_driver(&pmac_ide_pci_driver);
1403 goto out;
1404 }
1da177e4 1405#else
9e5755bc
AM
1406 error = macio_register_driver(&pmac_ide_macio_driver);
1407 if (error)
1408 goto out;
1409 error = pci_register_driver(&pmac_ide_pci_driver);
1410 if (error) {
1411 macio_unregister_driver(&pmac_ide_macio_driver);
1412 goto out;
1413 }
1beb6a7d 1414#endif
9e5755bc
AM
1415out:
1416 return error;
1da177e4
LT
1417}
1418
1419#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
1420
1421/*
1422 * pmac_ide_build_dmatable builds the DBDMA command list
1423 * for a transfer and sets the DBDMA channel to point to it.
1424 */
aacaf9bd 1425static int
1da177e4
LT
1426pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
1427{
1428 struct dbdma_cmd *table;
1429 int i, count = 0;
1430 ide_hwif_t *hwif = HWIF(drive);
1431 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
1432 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1433 struct scatterlist *sg;
1434 int wr = (rq_data_dir(rq) == WRITE);
1435
1436 /* DMA table is already aligned */
1437 table = (struct dbdma_cmd *) pmif->dma_table_cpu;
1438
1439 /* Make sure DMA controller is stopped (necessary ?) */
1440 writel((RUN|PAUSE|FLUSH|WAKE|DEAD) << 16, &dma->control);
1441 while (readl(&dma->status) & RUN)
1442 udelay(1);
1443
1444 hwif->sg_nents = i = ide_build_sglist(drive, rq);
1445
1446 if (!i)
1447 return 0;
1448
1449 /* Build DBDMA commands list */
1450 sg = hwif->sg_table;
1451 while (i && sg_dma_len(sg)) {
1452 u32 cur_addr;
1453 u32 cur_len;
1454
1455 cur_addr = sg_dma_address(sg);
1456 cur_len = sg_dma_len(sg);
1457
1458 if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) {
1459 if (pmif->broken_dma_warn == 0) {
aca38a51 1460 printk(KERN_WARNING "%s: DMA on non aligned address, "
1da177e4
LT
1461 "switching to PIO on Ohare chipset\n", drive->name);
1462 pmif->broken_dma_warn = 1;
1463 }
1464 goto use_pio_instead;
1465 }
1466 while (cur_len) {
1467 unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
1468
1469 if (count++ >= MAX_DCMDS) {
1470 printk(KERN_WARNING "%s: DMA table too small\n",
1471 drive->name);
1472 goto use_pio_instead;
1473 }
1474 st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE);
1475 st_le16(&table->req_count, tc);
1476 st_le32(&table->phy_addr, cur_addr);
1477 table->cmd_dep = 0;
1478 table->xfer_status = 0;
1479 table->res_count = 0;
1480 cur_addr += tc;
1481 cur_len -= tc;
1482 ++table;
1483 }
55c16a70 1484 sg = sg_next(sg);
1da177e4
LT
1485 i--;
1486 }
1487
1488 /* convert the last command to an input/output last command */
1489 if (count) {
1490 st_le16(&table[-1].command, wr? OUTPUT_LAST: INPUT_LAST);
1491 /* add the stop command to the end of the list */
1492 memset(table, 0, sizeof(struct dbdma_cmd));
1493 st_le16(&table->command, DBDMA_STOP);
1494 mb();
1495 writel(hwif->dmatable_dma, &dma->cmdptr);
1496 return 1;
1497 }
1498
1499 printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name);
f6fb786d
BZ
1500
1501use_pio_instead:
1502 ide_destroy_dmatable(drive);
1503
1da177e4
LT
1504 return 0; /* revert to PIO for this request */
1505}
1506
1507/* Teardown mappings after DMA has completed. */
aacaf9bd 1508static void
1da177e4
LT
1509pmac_ide_destroy_dmatable (ide_drive_t *drive)
1510{
1511 ide_hwif_t *hwif = drive->hwif;
1da177e4 1512
f6fb786d
BZ
1513 if (hwif->sg_nents) {
1514 ide_destroy_dmatable(drive);
1da177e4
LT
1515 hwif->sg_nents = 0;
1516 }
1517}
1518
1da177e4
LT
1519/*
1520 * Prepare a DMA transfer. We build the DMA table, adjust the timings for
1521 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
1522 */
aacaf9bd 1523static int
1da177e4
LT
1524pmac_ide_dma_setup(ide_drive_t *drive)
1525{
1526 ide_hwif_t *hwif = HWIF(drive);
1527 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
1528 struct request *rq = HWGROUP(drive)->rq;
1529 u8 unit = (drive->select.b.unit & 0x01);
1530 u8 ata4;
1531
1532 if (pmif == NULL)
1533 return 1;
1534 ata4 = (pmif->kind == controller_kl_ata4);
1535
1536 if (!pmac_ide_build_dmatable(drive, rq)) {
1537 ide_map_sg(drive, rq);
1538 return 1;
1539 }
1540
1541 /* Apple adds 60ns to wrDataSetup on reads */
1542 if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) {
1543 writel(pmif->timings[unit] + (!rq_data_dir(rq) ? 0x00800000UL : 0),
1544 PMAC_IDE_REG(IDE_TIMING_CONFIG));
1545 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
1546 }
1547
1548 drive->waiting_for_dma = 1;
1549
1550 return 0;
1551}
1552
aacaf9bd 1553static void
1da177e4
LT
1554pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
1555{
1556 /* issue cmd to drive */
1557 ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, NULL);
1558}
1559
1560/*
1561 * Kick the DMA controller into life after the DMA command has been issued
1562 * to the drive.
1563 */
aacaf9bd 1564static void
1da177e4
LT
1565pmac_ide_dma_start(ide_drive_t *drive)
1566{
1567 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
1568 volatile struct dbdma_regs __iomem *dma;
1569
1570 dma = pmif->dma_regs;
1571
1572 writel((RUN << 16) | RUN, &dma->control);
1573 /* Make sure it gets to the controller right now */
1574 (void)readl(&dma->control);
1575}
1576
1577/*
1578 * After a DMA transfer, make sure the controller is stopped
1579 */
aacaf9bd 1580static int
1da177e4
LT
1581pmac_ide_dma_end (ide_drive_t *drive)
1582{
1583 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
1584 volatile struct dbdma_regs __iomem *dma;
1585 u32 dstat;
1586
1587 if (pmif == NULL)
1588 return 0;
1589 dma = pmif->dma_regs;
1590
1591 drive->waiting_for_dma = 0;
1592 dstat = readl(&dma->status);
1593 writel(((RUN|WAKE|DEAD) << 16), &dma->control);
1594 pmac_ide_destroy_dmatable(drive);
1595 /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
1596 * in theory, but with ATAPI decices doing buffer underruns, that would
1597 * cause us to disable DMA, which isn't what we want
1598 */
1599 return (dstat & (RUN|DEAD)) != RUN;
1600}
1601
1602/*
1603 * Check out that the interrupt we got was for us. We can't always know this
1604 * for sure with those Apple interfaces (well, we could on the recent ones but
1605 * that's not implemented yet), on the other hand, we don't have shared interrupts
1606 * so it's not really a problem
1607 */
aacaf9bd 1608static int
1da177e4
LT
1609pmac_ide_dma_test_irq (ide_drive_t *drive)
1610{
1611 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
1612 volatile struct dbdma_regs __iomem *dma;
1613 unsigned long status, timeout;
1614
1615 if (pmif == NULL)
1616 return 0;
1617 dma = pmif->dma_regs;
1618
1619 /* We have to things to deal with here:
1620 *
1621 * - The dbdma won't stop if the command was started
1622 * but completed with an error without transferring all
1623 * datas. This happens when bad blocks are met during
1624 * a multi-block transfer.
1625 *
1626 * - The dbdma fifo hasn't yet finished flushing to
1627 * to system memory when the disk interrupt occurs.
1628 *
1629 */
1630
1631 /* If ACTIVE is cleared, the STOP command have passed and
1632 * transfer is complete.
1633 */
1634 status = readl(&dma->status);
1635 if (!(status & ACTIVE))
1636 return 1;
1637 if (!drive->waiting_for_dma)
1638 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1639 called while not waiting\n", HWIF(drive)->index);
1640
1641 /* If dbdma didn't execute the STOP command yet, the
1642 * active bit is still set. We consider that we aren't
1643 * sharing interrupts (which is hopefully the case with
1644 * those controllers) and so we just try to flush the
1645 * channel for pending data in the fifo
1646 */
1647 udelay(1);
1648 writel((FLUSH << 16) | FLUSH, &dma->control);
1649 timeout = 0;
1650 for (;;) {
1651 udelay(1);
1652 status = readl(&dma->status);
1653 if ((status & FLUSH) == 0)
1654 break;
1655 if (++timeout > 100) {
1656 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1657 timeout flushing channel\n", HWIF(drive)->index);
1658 break;
1659 }
1660 }
1661 return 1;
1662}
1663
15ce926a 1664static void pmac_ide_dma_host_set(ide_drive_t *drive, int on)
1da177e4 1665{
1da177e4
LT
1666}
1667
841d2a9b
SS
1668static void
1669pmac_ide_dma_lost_irq (ide_drive_t *drive)
1da177e4
LT
1670{
1671 pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
1672 volatile struct dbdma_regs __iomem *dma;
1673 unsigned long status;
1674
1675 if (pmif == NULL)
841d2a9b 1676 return;
1da177e4
LT
1677 dma = pmif->dma_regs;
1678
1679 status = readl(&dma->status);
1680 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
1da177e4
LT
1681}
1682
1683/*
1684 * Allocate the data structures needed for using DMA with an interface
1685 * and fill the proper list of functions pointers
1686 */
c413b9b9 1687static int __devinit pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1da177e4 1688{
36501650
BZ
1689 struct pci_dev *dev = to_pci_dev(hwif->dev);
1690
1da177e4
LT
1691 /* We won't need pci_dev if we switch to generic consistent
1692 * DMA routines ...
1693 */
36501650 1694 if (dev == NULL)
c413b9b9 1695 return -ENODEV;
1da177e4
LT
1696 /*
1697 * Allocate space for the DBDMA commands.
1698 * The +2 is +1 for the stop command and +1 to allow for
1699 * aligning the start address to a multiple of 16 bytes.
1700 */
1701 pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent(
36501650 1702 dev,
1da177e4
LT
1703 (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
1704 &hwif->dmatable_dma);
1705 if (pmif->dma_table_cpu == NULL) {
1706 printk(KERN_ERR "%s: unable to allocate DMA command list\n",
1707 hwif->name);
c413b9b9 1708 return -ENOMEM;
1da177e4
LT
1709 }
1710
4f52a329
BZ
1711 hwif->sg_max_nents = MAX_DCMDS;
1712
15ce926a 1713 hwif->dma_host_set = &pmac_ide_dma_host_set;
1da177e4
LT
1714 hwif->dma_setup = &pmac_ide_dma_setup;
1715 hwif->dma_exec_cmd = &pmac_ide_dma_exec_cmd;
1716 hwif->dma_start = &pmac_ide_dma_start;
1717 hwif->ide_dma_end = &pmac_ide_dma_end;
1718 hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
c283f5db 1719 hwif->dma_timeout = &ide_dma_timeout;
841d2a9b 1720 hwif->dma_lost_irq = &pmac_ide_dma_lost_irq;
1da177e4 1721
c413b9b9 1722 return 0;
1da177e4
LT
1723}
1724
1725#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
ade2daf9
BZ
1726
1727module_init(pmac_ide_probe);
de9facbf
AB
1728
1729MODULE_LICENSE("GPL");
This page took 0.36826 seconds and 5 git commands to generate.