blob: 4c2b669d7de686cf2ff332a218a29aaab6f381eb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Promise TX2/TX4/TX2000/133 IDE driver
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Split from:
10 * linux/drivers/ide/pdc202xx.c Version 0.35 Mar. 30, 2002
11 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
Sergei Shtylyov35198232007-09-11 22:28:34 +020012 * Copyright (C) 2005-2007 MontaVista Software, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * Portions Copyright (C) 1999 Promise Technology, Inc.
14 * Author: Frank Tiernan (frankt@promise.com)
15 * Released under terms of General Public License
16 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/kernel.h>
21#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/hdreg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/pci.h>
24#include <linux/init.h>
25#include <linux/ide.h>
26
27#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#ifdef CONFIG_PPC_PMAC
30#include <asm/prom.h>
31#include <asm/pci-bridge.h>
32#endif
33
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080034#undef DEBUG
35
36#ifdef DEBUG
Harvey Harrisoneb639632008-04-26 22:25:20 +020037#define DBG(fmt, args...) printk("%s: " fmt, __func__, ## args)
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080038#else
39#define DBG(fmt, args...)
40#endif
41
Jesper Juhl3c6bee12006-01-09 20:54:01 -080042static const char *pdc_quirk_drives[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 "QUANTUM FIREBALLlct08 08",
44 "QUANTUM FIREBALLP KA6.4",
45 "QUANTUM FIREBALLP KA9.1",
46 "QUANTUM FIREBALLP LM20.4",
47 "QUANTUM FIREBALLP KX13.6",
48 "QUANTUM FIREBALLP KX20.5",
49 "QUANTUM FIREBALLP KX27.3",
50 "QUANTUM FIREBALLP LM20.5",
51 NULL
52};
53
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080054static u8 max_dma_rate(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 u8 mode;
57
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080058 switch(pdev->device) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 case PCI_DEVICE_ID_PROMISE_20277:
60 case PCI_DEVICE_ID_PROMISE_20276:
61 case PCI_DEVICE_ID_PROMISE_20275:
62 case PCI_DEVICE_ID_PROMISE_20271:
63 case PCI_DEVICE_ID_PROMISE_20269:
64 mode = 4;
65 break;
66 case PCI_DEVICE_ID_PROMISE_20270:
67 case PCI_DEVICE_ID_PROMISE_20268:
68 mode = 3;
69 break;
70 default:
71 return 0;
72 }
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return mode;
75}
76
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080077/**
78 * get_indexed_reg - Get indexed register
79 * @hwif: for the port address
80 * @index: index of the indexed register
81 */
82static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
83{
84 u8 value;
85
Bartlomiej Zolnierkiewicz41051a12008-04-28 23:44:42 +020086 outb(index, hwif->dma_base + 1);
87 value = inb(hwif->dma_base + 3);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -080088
89 DBG("index[%02X] value[%02X]\n", index, value);
90 return value;
91}
92
93/**
94 * set_indexed_reg - Set indexed register
95 * @hwif: for the port address
96 * @index: index of the indexed register
97 */
98static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value)
99{
Bartlomiej Zolnierkiewicz41051a12008-04-28 23:44:42 +0200100 outb(index, hwif->dma_base + 1);
101 outb(value, hwif->dma_base + 3);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800102 DBG("index[%02X] value[%02X]\n", index, value);
103}
104
105/*
106 * ATA Timing Tables based on 133 MHz PLL output clock.
107 *
108 * If the PLL outputs 100 MHz clock, the ASIC hardware will set
109 * the timing registers automatically when "set features" command is
110 * issued to the device. However, if the PLL output clock is 133 MHz,
111 * the following tables must be used.
112 */
113static struct pio_timing {
114 u8 reg0c, reg0d, reg13;
115} pio_timings [] = {
116 { 0xfb, 0x2b, 0xac }, /* PIO mode 0, IORDY off, Prefetch off */
117 { 0x46, 0x29, 0xa4 }, /* PIO mode 1, IORDY off, Prefetch off */
118 { 0x23, 0x26, 0x64 }, /* PIO mode 2, IORDY off, Prefetch off */
119 { 0x27, 0x0d, 0x35 }, /* PIO mode 3, IORDY on, Prefetch off */
120 { 0x23, 0x09, 0x25 }, /* PIO mode 4, IORDY on, Prefetch off */
121};
122
123static struct mwdma_timing {
124 u8 reg0e, reg0f;
125} mwdma_timings [] = {
126 { 0xdf, 0x5f }, /* MWDMA mode 0 */
127 { 0x6b, 0x27 }, /* MWDMA mode 1 */
128 { 0x69, 0x25 }, /* MWDMA mode 2 */
129};
130
131static struct udma_timing {
132 u8 reg10, reg11, reg12;
133} udma_timings [] = {
134 { 0x4a, 0x0f, 0xd5 }, /* UDMA mode 0 */
135 { 0x3a, 0x0a, 0xd0 }, /* UDMA mode 1 */
136 { 0x2a, 0x07, 0xcd }, /* UDMA mode 2 */
137 { 0x1a, 0x05, 0xcd }, /* UDMA mode 3 */
138 { 0x1a, 0x03, 0xcd }, /* UDMA mode 4 */
139 { 0x1a, 0x02, 0xcb }, /* UDMA mode 5 */
140 { 0x1a, 0x01, 0xcb }, /* UDMA mode 6 */
141};
142
Bartlomiej Zolnierkiewiczad4ba7d2008-01-25 22:17:18 +0100143static void pdcnew_set_dma_mode(ide_drive_t *drive, const u8 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100146 struct pci_dev *dev = to_pci_dev(hwif->dev);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800147 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800149 /*
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200150 * IDE core issues SETFEATURES_XFER to the drive first (thanks to
151 * IDE_HFLAG_POST_SET_MODE in ->host_flags). PDC202xx hardware will
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800152 * automatically set the timing registers based on 100 MHz PLL output.
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200153 *
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800154 * As we set up the PLL to output 133 MHz for UltraDMA/133 capable
155 * chips, we must override the default register settings...
156 */
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100157 if (max_dma_rate(dev) == 4) {
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800158 u8 mode = speed & 0x07;
159
Bartlomiej Zolnierkiewicz4db90a12008-01-25 22:17:18 +0100160 if (speed >= XFER_UDMA_0) {
161 set_indexed_reg(hwif, 0x10 + adj,
162 udma_timings[mode].reg10);
163 set_indexed_reg(hwif, 0x11 + adj,
164 udma_timings[mode].reg11);
165 set_indexed_reg(hwif, 0x12 + adj,
166 udma_timings[mode].reg12);
167 } else {
168 set_indexed_reg(hwif, 0x0e + adj,
169 mwdma_timings[mode].reg0e);
170 set_indexed_reg(hwif, 0x0f + adj,
171 mwdma_timings[mode].reg0f);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800172 }
173 } else if (speed == XFER_UDMA_2) {
174 /* Set tHOLD bit to 0 if using UDMA mode 2 */
175 u8 tmp = get_indexed_reg(hwif, 0x10 + adj);
176
177 set_indexed_reg(hwif, 0x10 + adj, tmp & 0x7f);
178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200181static void pdcnew_set_pio_mode(ide_drive_t *drive, const u8 pio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Bartlomiej Zolnierkiewiczad4ba7d2008-01-25 22:17:18 +0100183 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100184 struct pci_dev *dev = to_pci_dev(hwif->dev);
Bartlomiej Zolnierkiewiczad4ba7d2008-01-25 22:17:18 +0100185 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
186
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +0100187 if (max_dma_rate(dev) == 4) {
Bartlomiej Zolnierkiewiczad4ba7d2008-01-25 22:17:18 +0100188 set_indexed_reg(hwif, 0x0c + adj, pio_timings[pio].reg0c);
189 set_indexed_reg(hwif, 0x0d + adj, pio_timings[pio].reg0d);
190 set_indexed_reg(hwif, 0x13 + adj, pio_timings[pio].reg13);
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
Bartlomiej Zolnierkiewiczbfa14b42008-02-02 19:56:31 +0100194static u8 __devinit pdcnew_cable_detect(ide_hwif_t *hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +0200196 if (get_indexed_reg(hwif, 0x0b) & 0x04)
197 return ATA_CBL_PATA40;
198 else
199 return ATA_CBL_PATA80;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800201
Bartlomiej Zolnierkiewiczf01393e2008-01-26 20:13:03 +0100202static void pdcnew_quirkproc(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Sergei Shtylyovd24ec422007-02-07 18:18:39 +0100204 const char **list, *model = drive->id->model;
205
206 for (list = pdc_quirk_drives; *list != NULL; list++)
Bartlomiej Zolnierkiewiczf01393e2008-01-26 20:13:03 +0100207 if (strstr(model, *list) != NULL) {
208 drive->quirk_list = 2;
209 return;
210 }
211
212 drive->quirk_list = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800215static void pdcnew_reset(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
217 /*
218 * Deleted this because it is redundant from the caller.
219 */
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800220 printk(KERN_WARNING "pdc202xx_new: %s channel reset.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 HWIF(drive)->channel ? "Secondary" : "Primary");
222}
223
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800224/**
225 * read_counter - Read the byte count registers
226 * @dma_base: for the port address
227 */
228static long __devinit read_counter(u32 dma_base)
229{
230 u32 pri_dma_base = dma_base, sec_dma_base = dma_base + 0x08;
231 u8 cnt0, cnt1, cnt2, cnt3;
232 long count = 0, last;
233 int retry = 3;
234
235 do {
236 last = count;
237
238 /* Read the current count */
239 outb(0x20, pri_dma_base + 0x01);
240 cnt0 = inb(pri_dma_base + 0x03);
241 outb(0x21, pri_dma_base + 0x01);
242 cnt1 = inb(pri_dma_base + 0x03);
243 outb(0x20, sec_dma_base + 0x01);
244 cnt2 = inb(sec_dma_base + 0x03);
245 outb(0x21, sec_dma_base + 0x01);
246 cnt3 = inb(sec_dma_base + 0x03);
247
248 count = (cnt3 << 23) | (cnt2 << 15) | (cnt1 << 8) | cnt0;
249
250 /*
251 * The 30-bit decrementing counter is read in 4 pieces.
252 * Incorrect value may be read when the most significant bytes
253 * are changing...
254 */
255 } while (retry-- && (((last ^ count) & 0x3fff8000) || last < count));
256
257 DBG("cnt0[%02X] cnt1[%02X] cnt2[%02X] cnt3[%02X]\n",
258 cnt0, cnt1, cnt2, cnt3);
259
260 return count;
261}
262
263/**
264 * detect_pll_input_clock - Detect the PLL input clock in Hz.
265 * @dma_base: for the port address
266 * E.g. 16949000 on 33 MHz PCI bus, i.e. half of the PCI clock.
267 */
268static long __devinit detect_pll_input_clock(unsigned long dma_base)
269{
Albert Lee8006bf52007-07-03 22:28:36 +0200270 struct timeval start_time, end_time;
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800271 long start_count, end_count;
Albert Lee8006bf52007-07-03 22:28:36 +0200272 long pll_input, usec_elapsed;
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800273 u8 scr1;
274
275 start_count = read_counter(dma_base);
Albert Lee8006bf52007-07-03 22:28:36 +0200276 do_gettimeofday(&start_time);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800277
278 /* Start the test mode */
279 outb(0x01, dma_base + 0x01);
280 scr1 = inb(dma_base + 0x03);
281 DBG("scr1[%02X]\n", scr1);
282 outb(scr1 | 0x40, dma_base + 0x03);
283
284 /* Let the counter run for 10 ms. */
285 mdelay(10);
286
287 end_count = read_counter(dma_base);
Albert Lee8006bf52007-07-03 22:28:36 +0200288 do_gettimeofday(&end_time);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800289
290 /* Stop the test mode */
291 outb(0x01, dma_base + 0x01);
292 scr1 = inb(dma_base + 0x03);
293 DBG("scr1[%02X]\n", scr1);
294 outb(scr1 & ~0x40, dma_base + 0x03);
295
296 /*
297 * Calculate the input clock in Hz
298 * (the clock counter is 30 bit wide and counts down)
299 */
Albert Lee8006bf52007-07-03 22:28:36 +0200300 usec_elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
301 (end_time.tv_usec - start_time.tv_usec);
Mikael Pettersson56fe23d2007-09-11 22:28:37 +0200302 pll_input = ((start_count - end_count) & 0x3fffffff) / 10 *
Albert Lee8006bf52007-07-03 22:28:36 +0200303 (10000000 / usec_elapsed);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800304
305 DBG("start[%ld] end[%ld]\n", start_count, end_count);
306
307 return pll_input;
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310#ifdef CONFIG_PPC_PMAC
311static void __devinit apple_kiwi_init(struct pci_dev *pdev)
312{
313 struct device_node *np = pci_device_to_OF_node(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 u8 conf;
315
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000316 if (np == NULL || !of_device_is_compatible(np, "kiwi-root"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return;
318
Bartlomiej Zolnierkiewiczfc212bb2007-10-19 00:30:08 +0200319 if (pdev->revision >= 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* Setup chip magic config stuff (from darwin) */
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800321 pci_read_config_byte (pdev, 0x40, &conf);
322 pci_write_config_byte(pdev, 0x40, (conf | 0x01));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325#endif /* CONFIG_PPC_PMAC */
326
327static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const char *name)
328{
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800329 unsigned long dma_base = pci_resource_start(dev, 4);
330 unsigned long sec_dma_base = dma_base + 0x08;
331 long pll_input, pll_output, ratio;
332 int f, r;
333 u8 pll_ctl0, pll_ctl1;
334
Bartlomiej Zolnierkiewicz01cc6432007-08-20 22:42:56 +0200335 if (dma_base == 0)
336 return -EFAULT;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#ifdef CONFIG_PPC_PMAC
339 apple_kiwi_init(dev);
340#endif
341
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800342 /* Calculate the required PLL output frequency */
343 switch(max_dma_rate(dev)) {
344 case 4: /* it's 133 MHz for Ultra133 chips */
345 pll_output = 133333333;
346 break;
347 case 3: /* and 100 MHz for Ultra100 chips */
348 default:
349 pll_output = 100000000;
350 break;
351 }
352
353 /*
354 * Detect PLL input clock.
355 * On some systems, where PCI bus is running at non-standard clock rate
356 * (e.g. 25 or 40 MHz), we have to adjust the cycle time.
357 * PDC20268 and newer chips employ PLL circuit to help correct timing
358 * registers setting.
359 */
360 pll_input = detect_pll_input_clock(dma_base);
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200361 printk(KERN_INFO "%s %s: PLL input clock is %ld kHz\n",
362 name, pci_name(dev), pll_input / 1000);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800363
364 /* Sanity check */
365 if (unlikely(pll_input < 5000000L || pll_input > 70000000L)) {
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200366 printk(KERN_ERR "%s %s: Bad PLL input clock %ld Hz, giving up!"
367 "\n", name, pci_name(dev), pll_input);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800368 goto out;
369 }
370
371#ifdef DEBUG
372 DBG("pll_output is %ld Hz\n", pll_output);
373
374 /* Show the current clock value of PLL control register
375 * (maybe already configured by the BIOS)
376 */
377 outb(0x02, sec_dma_base + 0x01);
378 pll_ctl0 = inb(sec_dma_base + 0x03);
379 outb(0x03, sec_dma_base + 0x01);
380 pll_ctl1 = inb(sec_dma_base + 0x03);
381
382 DBG("pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
383#endif
384
385 /*
386 * Calculate the ratio of F, R and NO
387 * POUT = (F + 2) / (( R + 2) * NO)
388 */
389 ratio = pll_output / (pll_input / 1000);
390 if (ratio < 8600L) { /* 8.6x */
391 /* Using NO = 0x01, R = 0x0d */
392 r = 0x0d;
393 } else if (ratio < 12900L) { /* 12.9x */
394 /* Using NO = 0x01, R = 0x08 */
395 r = 0x08;
396 } else if (ratio < 16100L) { /* 16.1x */
397 /* Using NO = 0x01, R = 0x06 */
398 r = 0x06;
399 } else if (ratio < 64000L) { /* 64x */
400 r = 0x00;
401 } else {
402 /* Invalid ratio */
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200403 printk(KERN_ERR "%s %s: Bad ratio %ld, giving up!\n",
404 name, pci_name(dev), ratio);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800405 goto out;
406 }
407
408 f = (ratio * (r + 2)) / 1000 - 2;
409
410 DBG("F[%d] R[%d] ratio*1000[%ld]\n", f, r, ratio);
411
412 if (unlikely(f < 0 || f > 127)) {
413 /* Invalid F */
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200414 printk(KERN_ERR "%s %s: F[%d] invalid!\n",
415 name, pci_name(dev), f);
Sergei Shtylyov47694bb2006-12-10 02:19:13 -0800416 goto out;
417 }
418
419 pll_ctl0 = (u8) f;
420 pll_ctl1 = (u8) r;
421
422 DBG("Writing pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
423
424 outb(0x02, sec_dma_base + 0x01);
425 outb(pll_ctl0, sec_dma_base + 0x03);
426 outb(0x03, sec_dma_base + 0x01);
427 outb(pll_ctl1, sec_dma_base + 0x03);
428
429 /* Wait the PLL circuit to be stable */
430 mdelay(30);
431
432#ifdef DEBUG
433 /*
434 * Show the current clock value of PLL control register
435 */
436 outb(0x02, sec_dma_base + 0x01);
437 pll_ctl0 = inb(sec_dma_base + 0x03);
438 outb(0x03, sec_dma_base + 0x01);
439 pll_ctl1 = inb(sec_dma_base + 0x03);
440
441 DBG("pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
442#endif
443
444 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return dev->irq;
446}
447
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200448static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200450 struct pci_dev *dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Bartlomiej Zolnierkiewiczeadb6ec2007-12-12 23:31:58 +0100452 dev2 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn) + 1,
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200453 PCI_FUNC(dev->devfn)));
Bartlomiej Zolnierkiewiczeadb6ec2007-12-12 23:31:58 +0100454
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200455 if (dev2 &&
456 dev2->vendor == dev->vendor &&
457 dev2->device == dev->device) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200459 if (dev2->irq != dev->irq) {
460 dev2->irq = dev->irq;
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200461 printk(KERN_INFO "PDC20270 %s: PCI config space "
462 "interrupt fixed\n", pci_name(dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200464
465 return dev2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200468 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200471static const struct ide_port_ops pdcnew_port_ops = {
472 .set_pio_mode = pdcnew_set_pio_mode,
473 .set_dma_mode = pdcnew_set_dma_mode,
474 .quirkproc = pdcnew_quirkproc,
475 .resetproc = pdcnew_reset,
476 .cable_detect = pdcnew_cable_detect,
477};
478
Bartlomiej Zolnierkiewicz05d7e6c2007-10-19 00:30:10 +0200479#define DECLARE_PDCNEW_DEV(name_str, udma) \
480 { \
481 .name = name_str, \
482 .init_chipset = init_chipset_pdcnew, \
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200483 .port_ops = &pdcnew_port_ops, \
Bartlomiej Zolnierkiewicz05d7e6c2007-10-19 00:30:10 +0200484 .host_flags = IDE_HFLAG_POST_SET_MODE | \
Bartlomiej Zolnierkiewiczed67b922007-10-19 00:30:10 +0200485 IDE_HFLAG_ERROR_STOPS_FIFO | \
Bartlomiej Zolnierkiewicz05d7e6c2007-10-19 00:30:10 +0200486 IDE_HFLAG_OFF_BOARD, \
487 .pio_mask = ATA_PIO4, \
488 .mwdma_mask = ATA_MWDMA2, \
489 .udma_mask = udma, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
Bartlomiej Zolnierkiewicz05d7e6c2007-10-19 00:30:10 +0200491
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +0200492static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
Bartlomiej Zolnierkiewicz05d7e6c2007-10-19 00:30:10 +0200493 /* 0 */ DECLARE_PDCNEW_DEV("PDC20268", ATA_UDMA5),
494 /* 1 */ DECLARE_PDCNEW_DEV("PDC20269", ATA_UDMA6),
495 /* 2 */ DECLARE_PDCNEW_DEV("PDC20270", ATA_UDMA5),
496 /* 3 */ DECLARE_PDCNEW_DEV("PDC20271", ATA_UDMA6),
497 /* 4 */ DECLARE_PDCNEW_DEV("PDC20275", ATA_UDMA6),
498 /* 5 */ DECLARE_PDCNEW_DEV("PDC20276", ATA_UDMA6),
499 /* 6 */ DECLARE_PDCNEW_DEV("PDC20277", ATA_UDMA6),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500};
501
502/**
503 * pdc202new_init_one - called when a pdc202xx is found
504 * @dev: the pdc202new device
505 * @id: the matching pci id
506 *
507 * Called when the PCI registration layer (or the IDE initialization)
508 * finds a device matching our IDE device tables.
509 */
510
511static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_device_id *id)
512{
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +0200513 const struct ide_port_info *d;
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200514 struct pci_dev *bridge = dev->bus->self;
515 u8 idx = id->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200517 d = &pdcnew_chipsets[idx];
518
519 if (idx == 2 && bridge &&
520 bridge->vendor == PCI_VENDOR_ID_DEC &&
521 bridge->device == PCI_DEVICE_ID_DEC_21150) {
522 struct pci_dev *dev2;
523
524 if (PCI_SLOT(dev->devfn) & 2)
525 return -ENODEV;
526
527 dev2 = pdc20270_get_dev2(dev);
528
529 if (dev2) {
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200530 int ret = ide_pci_init_two(dev, dev2, d, NULL);
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200531 if (ret < 0)
532 pci_dev_put(dev2);
533 return ret;
534 }
535 }
536
537 if (idx == 5 && bridge &&
538 bridge->vendor == PCI_VENDOR_ID_INTEL &&
539 (bridge->device == PCI_DEVICE_ID_INTEL_I960 ||
540 bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) {
Bartlomiej Zolnierkiewicz28cfd8a2008-07-24 22:53:31 +0200541 printk(KERN_INFO "PDC20276 %s: attached to I2O RAID controller,"
542 " skipping\n", pci_name(dev));
Bartlomiej Zolnierkiewicz099b1f42007-10-19 00:30:09 +0200543 return -ENODEV;
544 }
545
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200546 return ide_pci_init_one(dev, d, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
Bartlomiej Zolnierkiewiczd69c8f82008-07-24 22:53:23 +0200549static void __devexit pdc202new_remove(struct pci_dev *dev)
550{
551 struct ide_host *host = pci_get_drvdata(dev);
552 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
553
554 ide_pci_remove(dev);
555 pci_dev_put(dev2);
556}
557
Bartlomiej Zolnierkiewicz9cbcc5e2007-10-16 22:29:56 +0200558static const struct pci_device_id pdc202new_pci_tbl[] = {
559 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20268), 0 },
560 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20269), 1 },
561 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20270), 2 },
562 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20271), 3 },
563 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20275), 4 },
564 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20276), 5 },
565 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20277), 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 { 0, },
567};
568MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
569
570static struct pci_driver driver = {
571 .name = "Promise_IDE",
572 .id_table = pdc202new_pci_tbl,
573 .probe = pdc202new_init_one,
Bartlomiej Zolnierkiewiczd69c8f82008-07-24 22:53:23 +0200574 .remove = pdc202new_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575};
576
Bartlomiej Zolnierkiewicz82ab1ee2007-01-27 13:46:56 +0100577static int __init pdc202new_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 return ide_pci_register_driver(&driver);
580}
581
Bartlomiej Zolnierkiewiczd69c8f82008-07-24 22:53:23 +0200582static void __exit pdc202new_ide_exit(void)
583{
584 pci_unregister_driver(&driver);
585}
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587module_init(pdc202new_ide_init);
Bartlomiej Zolnierkiewiczd69c8f82008-07-24 22:53:23 +0200588module_exit(pdc202new_ide_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
591MODULE_DESCRIPTION("PCI driver module for Promise PDC20268 and higher");
592MODULE_LICENSE("GPL");