blob: ad31b8afec6fc6050f55cd79382a836e5227c348 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sata_promise.c - Promise SATA
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2003-2004 Red Hat, Inc.
9 *
10 * The contents of this file are subject to the Open
11 * Software License version 1.1 that can be found at
12 * http://www.opensource.org/licenses/osl-1.1.txt and is included herein
13 * by reference.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU General Public License version 2 (the "GPL") as distributed
17 * in the kernel source COPYING file, in which case the provisions of
18 * the GPL are applicable instead of the above. If you wish to allow
19 * the use of your version of this file only under the terms of the
20 * GPL and not to allow others to use your version of this file under
21 * the OSL, indicate your decision by deleting the provisions above and
22 * replace them with the notice and other provisions required by the GPL.
23 * If you do not delete the provisions above, a recipient may use your
24 * version of this file under either the OSL or the GPL.
25 *
26 */
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/blkdev.h>
33#include <linux/delay.h>
34#include <linux/interrupt.h>
35#include <linux/sched.h>
36#include "scsi.h"
37#include <scsi/scsi_host.h>
38#include <linux/libata.h>
39#include <asm/io.h>
40#include "sata_promise.h"
41
42#define DRV_NAME "sata_promise"
Jeff Garzik68854332005-08-23 02:53:51 -040043#define DRV_VERSION "1.02"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45
46enum {
47 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
48 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
49 PDC_TBG_MODE = 0x41, /* TBG mode */
50 PDC_FLASH_CTL = 0x44, /* Flash control register */
51 PDC_PCI_CTL = 0x48, /* PCI control and status register */
52 PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
53 PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
54 PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
55 PDC_SLEW_CTL = 0x470, /* slew rate control reg */
56
57 PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
58 (1<<8) | (1<<9) | (1<<10),
59
60 board_2037x = 0, /* FastTrak S150 TX2plus */
61 board_20319 = 1, /* FastTrak S150 TX4 */
Tobias Lorenzf497ba72005-05-12 15:51:01 -040062 board_20619 = 2, /* FastTrak TX4000 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */
65
66 PDC_RESET = (1 << 11), /* HDMA reset */
67};
68
69
70struct pdc_port_priv {
71 u8 *pkt;
72 dma_addr_t pkt_dma;
73};
74
75static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
78static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
79static void pdc_eng_timeout(struct ata_port *ap);
80static int pdc_port_start(struct ata_port *ap);
81static void pdc_port_stop(struct ata_port *ap);
Jeff Garzik2cba5822005-08-29 05:12:30 -040082static void pdc_pata_phy_reset(struct ata_port *ap);
83static void pdc_sata_phy_reset(struct ata_port *ap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static void pdc_qc_prep(struct ata_queued_cmd *qc);
85static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf);
86static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf);
87static void pdc_irq_clear(struct ata_port *ap);
88static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
89
90static Scsi_Host_Template pdc_ata_sht = {
91 .module = THIS_MODULE,
92 .name = DRV_NAME,
93 .ioctl = ata_scsi_ioctl,
94 .queuecommand = ata_scsi_queuecmd,
95 .eh_strategy_handler = ata_scsi_error,
96 .can_queue = ATA_DEF_QUEUE,
97 .this_id = ATA_SHT_THIS_ID,
98 .sg_tablesize = LIBATA_MAX_PRD,
99 .max_sectors = ATA_MAX_SECTORS,
100 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
101 .emulated = ATA_SHT_EMULATED,
102 .use_clustering = ATA_SHT_USE_CLUSTERING,
103 .proc_name = DRV_NAME,
104 .dma_boundary = ATA_DMA_BOUNDARY,
105 .slave_configure = ata_scsi_slave_config,
106 .bios_param = ata_std_bios_param,
107 .ordered_flush = 1,
108};
109
Jeff Garzik2cba5822005-08-29 05:12:30 -0400110static struct ata_port_operations pdc_sata_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 .port_disable = ata_port_disable,
112 .tf_load = pdc_tf_load_mmio,
113 .tf_read = ata_tf_read,
114 .check_status = ata_check_status,
115 .exec_command = pdc_exec_command_mmio,
116 .dev_select = ata_std_dev_select,
Jeff Garzik2cba5822005-08-29 05:12:30 -0400117
118 .phy_reset = pdc_sata_phy_reset,
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .qc_prep = pdc_qc_prep,
121 .qc_issue = pdc_qc_issue_prot,
122 .eng_timeout = pdc_eng_timeout,
123 .irq_handler = pdc_interrupt,
124 .irq_clear = pdc_irq_clear,
Jeff Garzik2cba5822005-08-29 05:12:30 -0400125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .scr_read = pdc_sata_scr_read,
127 .scr_write = pdc_sata_scr_write,
128 .port_start = pdc_port_start,
129 .port_stop = pdc_port_stop,
Jeff Garzikaa8f0dc2005-05-26 21:54:27 -0400130 .host_stop = ata_host_stop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131};
132
Jeff Garzik2cba5822005-08-29 05:12:30 -0400133static struct ata_port_operations pdc_pata_ops = {
134 .port_disable = ata_port_disable,
135 .tf_load = pdc_tf_load_mmio,
136 .tf_read = ata_tf_read,
137 .check_status = ata_check_status,
138 .exec_command = pdc_exec_command_mmio,
139 .dev_select = ata_std_dev_select,
140
141 .phy_reset = pdc_pata_phy_reset,
142
143 .qc_prep = pdc_qc_prep,
144 .qc_issue = pdc_qc_issue_prot,
145 .eng_timeout = pdc_eng_timeout,
146 .irq_handler = pdc_interrupt,
147 .irq_clear = pdc_irq_clear,
148
149 .port_start = pdc_port_start,
150 .port_stop = pdc_port_stop,
151 .host_stop = ata_host_stop,
152};
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static struct ata_port_info pdc_port_info[] = {
155 /* board_2037x */
156 {
157 .sht = &pdc_ata_sht,
158 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
159 ATA_FLAG_SRST | ATA_FLAG_MMIO,
160 .pio_mask = 0x1f, /* pio0-4 */
161 .mwdma_mask = 0x07, /* mwdma0-2 */
162 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400163 .port_ops = &pdc_sata_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 },
165
166 /* board_20319 */
167 {
168 .sht = &pdc_ata_sht,
169 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
170 ATA_FLAG_SRST | ATA_FLAG_MMIO,
171 .pio_mask = 0x1f, /* pio0-4 */
172 .mwdma_mask = 0x07, /* mwdma0-2 */
173 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400174 .port_ops = &pdc_sata_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 },
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400176
177 /* board_20619 */
178 {
179 .sht = &pdc_ata_sht,
180 .host_flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
181 ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS,
182 .pio_mask = 0x1f, /* pio0-4 */
183 .mwdma_mask = 0x07, /* mwdma0-2 */
184 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400185 .port_ops = &pdc_pata_ops,
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400186 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
189static struct pci_device_id pdc_ata_pci_tbl[] = {
190 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
191 board_2037x },
Francisco Javier4c3a53d2005-05-25 19:29:37 -0400192 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
193 board_2037x },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
195 board_2037x },
196 { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
197 board_2037x },
198 { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
199 board_2037x },
200 { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
201 board_2037x },
202 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
203 board_2037x },
204
205 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
206 board_20319 },
207 { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
208 board_20319 },
209 { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
210 board_20319 },
211
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400212 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
213 board_20619 },
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 { } /* terminate list */
216};
217
218
219static struct pci_driver pdc_ata_pci_driver = {
220 .name = DRV_NAME,
221 .id_table = pdc_ata_pci_tbl,
222 .probe = pdc_ata_init_one,
223 .remove = ata_pci_remove_one,
224};
225
226
227static int pdc_port_start(struct ata_port *ap)
228{
229 struct device *dev = ap->host_set->dev;
230 struct pdc_port_priv *pp;
231 int rc;
232
233 rc = ata_port_start(ap);
234 if (rc)
235 return rc;
236
237 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
238 if (!pp) {
239 rc = -ENOMEM;
240 goto err_out;
241 }
242 memset(pp, 0, sizeof(*pp));
243
244 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
245 if (!pp->pkt) {
246 rc = -ENOMEM;
247 goto err_out_kfree;
248 }
249
250 ap->private_data = pp;
251
252 return 0;
253
254err_out_kfree:
255 kfree(pp);
256err_out:
257 ata_port_stop(ap);
258 return rc;
259}
260
261
262static void pdc_port_stop(struct ata_port *ap)
263{
264 struct device *dev = ap->host_set->dev;
265 struct pdc_port_priv *pp = ap->private_data;
266
267 ap->private_data = NULL;
268 dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
269 kfree(pp);
270 ata_port_stop(ap);
271}
272
273
274static void pdc_reset_port(struct ata_port *ap)
275{
276 void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
277 unsigned int i;
278 u32 tmp;
279
280 for (i = 11; i > 0; i--) {
281 tmp = readl(mmio);
282 if (tmp & PDC_RESET)
283 break;
284
285 udelay(100);
286
287 tmp |= PDC_RESET;
288 writel(tmp, mmio);
289 }
290
291 tmp &= ~PDC_RESET;
292 writel(tmp, mmio);
293 readl(mmio); /* flush */
294}
295
Jeff Garzik2cba5822005-08-29 05:12:30 -0400296static void pdc_sata_phy_reset(struct ata_port *ap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
298 pdc_reset_port(ap);
299 sata_phy_reset(ap);
300}
301
Jeff Garzik2cba5822005-08-29 05:12:30 -0400302static void pdc_pata_phy_reset(struct ata_port *ap)
303{
304 /* FIXME: add cable detect. Don't assume 40-pin cable */
305 ap->cbl = ATA_CBL_PATA40;
306 ap->udma_mask &= ATA_UDMA_MASK_40C;
307
308 pdc_reset_port(ap);
309 ata_port_probe(ap);
310 ata_bus_reset(ap);
311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
314{
315 if (sc_reg > SCR_CONTROL)
316 return 0xffffffffU;
317 return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4));
318}
319
320
321static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
322 u32 val)
323{
324 if (sc_reg > SCR_CONTROL)
325 return;
326 writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4));
327}
328
329static void pdc_qc_prep(struct ata_queued_cmd *qc)
330{
331 struct pdc_port_priv *pp = qc->ap->private_data;
332 unsigned int i;
333
334 VPRINTK("ENTER\n");
335
336 switch (qc->tf.protocol) {
337 case ATA_PROT_DMA:
338 ata_qc_prep(qc);
339 /* fall through */
340
341 case ATA_PROT_NODATA:
342 i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
343 qc->dev->devno, pp->pkt);
344
345 if (qc->tf.flags & ATA_TFLAG_LBA48)
346 i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
347 else
348 i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
349
350 pdc_pkt_footer(&qc->tf, pp->pkt, i);
351 break;
352
353 default:
354 break;
355 }
356}
357
358static void pdc_eng_timeout(struct ata_port *ap)
359{
360 u8 drv_stat;
361 struct ata_queued_cmd *qc;
362
363 DPRINTK("ENTER\n");
364
365 qc = ata_qc_from_tag(ap, ap->active_tag);
366 if (!qc) {
367 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
368 ap->id);
369 goto out;
370 }
371
372 /* hack alert! We cannot use the supplied completion
373 * function from inside the ->eh_strategy_handler() thread.
374 * libata is the only user of ->eh_strategy_handler() in
375 * any kernel, so the default scsi_done() assumes it is
376 * not being called from the SCSI EH.
377 */
378 qc->scsidone = scsi_finish_command;
379
380 switch (qc->tf.protocol) {
381 case ATA_PROT_DMA:
382 case ATA_PROT_NODATA:
383 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
384 ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR);
385 break;
386
387 default:
388 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
389
390 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
391 ap->id, qc->tf.command, drv_stat);
392
393 ata_qc_complete(qc, drv_stat);
394 break;
395 }
396
397out:
398 DPRINTK("EXIT\n");
399}
400
401static inline unsigned int pdc_host_intr( struct ata_port *ap,
402 struct ata_queued_cmd *qc)
403{
404 u8 status;
405 unsigned int handled = 0, have_err = 0;
406 u32 tmp;
407 void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
408
409 tmp = readl(mmio);
410 if (tmp & PDC_ERR_MASK) {
411 have_err = 1;
412 pdc_reset_port(ap);
413 }
414
415 switch (qc->tf.protocol) {
416 case ATA_PROT_DMA:
417 case ATA_PROT_NODATA:
418 status = ata_wait_idle(ap);
419 if (have_err)
420 status |= ATA_ERR;
421 ata_qc_complete(qc, status);
422 handled = 1;
423 break;
424
425 default:
426 ap->stats.idle_irq++;
427 break;
428 }
429
430 return handled;
431}
432
433static void pdc_irq_clear(struct ata_port *ap)
434{
435 struct ata_host_set *host_set = ap->host_set;
436 void *mmio = host_set->mmio_base;
437
438 readl(mmio + PDC_INT_SEQMASK);
439}
440
441static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
442{
443 struct ata_host_set *host_set = dev_instance;
444 struct ata_port *ap;
445 u32 mask = 0;
446 unsigned int i, tmp;
447 unsigned int handled = 0;
448 void *mmio_base;
449
450 VPRINTK("ENTER\n");
451
452 if (!host_set || !host_set->mmio_base) {
453 VPRINTK("QUICK EXIT\n");
454 return IRQ_NONE;
455 }
456
457 mmio_base = host_set->mmio_base;
458
459 /* reading should also clear interrupts */
460 mask = readl(mmio_base + PDC_INT_SEQMASK);
461
462 if (mask == 0xffffffff) {
463 VPRINTK("QUICK EXIT 2\n");
464 return IRQ_NONE;
465 }
466 mask &= 0xffff; /* only 16 tags possible */
467 if (!mask) {
468 VPRINTK("QUICK EXIT 3\n");
469 return IRQ_NONE;
470 }
471
472 spin_lock(&host_set->lock);
473
474 writel(mask, mmio_base + PDC_INT_SEQMASK);
475
476 for (i = 0; i < host_set->n_ports; i++) {
477 VPRINTK("port %u\n", i);
478 ap = host_set->ports[i];
479 tmp = mask & (1 << (i + 1));
480 if (tmp && ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) {
481 struct ata_queued_cmd *qc;
482
483 qc = ata_qc_from_tag(ap, ap->active_tag);
484 if (qc && (!(qc->tf.ctl & ATA_NIEN)))
485 handled += pdc_host_intr(ap, qc);
486 }
487 }
488
489 spin_unlock(&host_set->lock);
490
491 VPRINTK("EXIT\n");
492
493 return IRQ_RETVAL(handled);
494}
495
496static inline void pdc_packet_start(struct ata_queued_cmd *qc)
497{
498 struct ata_port *ap = qc->ap;
499 struct pdc_port_priv *pp = ap->private_data;
500 unsigned int port_no = ap->port_no;
501 u8 seq = (u8) (port_no + 1);
502
503 VPRINTK("ENTER, ap %p\n", ap);
504
505 writel(0x00000001, ap->host_set->mmio_base + (seq * 4));
506 readl(ap->host_set->mmio_base + (seq * 4)); /* flush */
507
508 pp->pkt[2] = seq;
509 wmb(); /* flush PRD, pkt writes */
510 writel(pp->pkt_dma, (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
511 readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
512}
513
514static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
515{
516 switch (qc->tf.protocol) {
517 case ATA_PROT_DMA:
518 case ATA_PROT_NODATA:
519 pdc_packet_start(qc);
520 return 0;
521
522 case ATA_PROT_ATAPI_DMA:
523 BUG();
524 break;
525
526 default:
527 break;
528 }
529
530 return ata_qc_issue_prot(qc);
531}
532
533static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
534{
535 WARN_ON (tf->protocol == ATA_PROT_DMA ||
536 tf->protocol == ATA_PROT_NODATA);
537 ata_tf_load(ap, tf);
538}
539
540
541static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
542{
543 WARN_ON (tf->protocol == ATA_PROT_DMA ||
544 tf->protocol == ATA_PROT_NODATA);
545 ata_exec_command(ap, tf);
546}
547
548
549static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
550{
551 port->cmd_addr = base;
552 port->data_addr = base;
553 port->feature_addr =
554 port->error_addr = base + 0x4;
555 port->nsect_addr = base + 0x8;
556 port->lbal_addr = base + 0xc;
557 port->lbam_addr = base + 0x10;
558 port->lbah_addr = base + 0x14;
559 port->device_addr = base + 0x18;
560 port->command_addr =
561 port->status_addr = base + 0x1c;
562 port->altstatus_addr =
563 port->ctl_addr = base + 0x38;
564}
565
566
567static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
568{
569 void *mmio = pe->mmio_base;
570 u32 tmp;
571
572 /*
573 * Except for the hotplug stuff, this is voodoo from the
574 * Promise driver. Label this entire section
575 * "TODO: figure out why we do this"
576 */
577
578 /* change FIFO_SHD to 8 dwords, enable BMR_BURST */
579 tmp = readl(mmio + PDC_FLASH_CTL);
580 tmp |= 0x12000; /* bit 16 (fifo 8 dw) and 13 (bmr burst?) */
581 writel(tmp, mmio + PDC_FLASH_CTL);
582
583 /* clear plug/unplug flags for all ports */
584 tmp = readl(mmio + PDC_SATA_PLUG_CSR);
585 writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR);
586
587 /* mask plug/unplug ints */
588 tmp = readl(mmio + PDC_SATA_PLUG_CSR);
589 writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR);
590
591 /* reduce TBG clock to 133 Mhz. */
592 tmp = readl(mmio + PDC_TBG_MODE);
593 tmp &= ~0x30000; /* clear bit 17, 16*/
594 tmp |= 0x10000; /* set bit 17:16 = 0:1 */
595 writel(tmp, mmio + PDC_TBG_MODE);
596
597 readl(mmio + PDC_TBG_MODE); /* flush */
598 msleep(10);
599
600 /* adjust slew rate control register. */
601 tmp = readl(mmio + PDC_SLEW_CTL);
602 tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
603 tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
604 writel(tmp, mmio + PDC_SLEW_CTL);
605}
606
607static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
608{
609 static int printed_version;
610 struct ata_probe_ent *probe_ent = NULL;
611 unsigned long base;
612 void *mmio_base;
613 unsigned int board_idx = (unsigned int) ent->driver_data;
614 int pci_dev_busy = 0;
615 int rc;
616
617 if (!printed_version++)
618 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
619
620 /*
621 * If this driver happens to only be useful on Apple's K2, then
622 * we should check that here as it has a normal Serverworks ID
623 */
624 rc = pci_enable_device(pdev);
625 if (rc)
626 return rc;
627
628 rc = pci_request_regions(pdev, DRV_NAME);
629 if (rc) {
630 pci_dev_busy = 1;
631 goto err_out;
632 }
633
634 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
635 if (rc)
636 goto err_out_regions;
637 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
638 if (rc)
639 goto err_out_regions;
640
641 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
642 if (probe_ent == NULL) {
643 rc = -ENOMEM;
644 goto err_out_regions;
645 }
646
647 memset(probe_ent, 0, sizeof(*probe_ent));
648 probe_ent->dev = pci_dev_to_dev(pdev);
649 INIT_LIST_HEAD(&probe_ent->node);
650
651 mmio_base = ioremap(pci_resource_start(pdev, 3),
652 pci_resource_len(pdev, 3));
653 if (mmio_base == NULL) {
654 rc = -ENOMEM;
655 goto err_out_free_ent;
656 }
657 base = (unsigned long) mmio_base;
658
659 probe_ent->sht = pdc_port_info[board_idx].sht;
660 probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
661 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
662 probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
663 probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
664 probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
665
666 probe_ent->irq = pdev->irq;
667 probe_ent->irq_flags = SA_SHIRQ;
668 probe_ent->mmio_base = mmio_base;
669
670 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
671 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
672
673 probe_ent->port[0].scr_addr = base + 0x400;
674 probe_ent->port[1].scr_addr = base + 0x500;
675
676 /* notice 4-port boards */
677 switch (board_idx) {
678 case board_20319:
679 probe_ent->n_ports = 4;
680
681 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
682 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
683
684 probe_ent->port[2].scr_addr = base + 0x600;
685 probe_ent->port[3].scr_addr = base + 0x700;
686 break;
687 case board_2037x:
688 probe_ent->n_ports = 2;
689 break;
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400690 case board_20619:
691 probe_ent->n_ports = 4;
692
693 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
694 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
695
696 probe_ent->port[2].scr_addr = base + 0x600;
697 probe_ent->port[3].scr_addr = base + 0x700;
698 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 default:
700 BUG();
701 break;
702 }
703
704 pci_set_master(pdev);
705
706 /* initialize adapter */
707 pdc_host_init(board_idx, probe_ent);
708
709 /* FIXME: check ata_device_add return value */
710 ata_device_add(probe_ent);
711 kfree(probe_ent);
712
713 return 0;
714
715err_out_free_ent:
716 kfree(probe_ent);
717err_out_regions:
718 pci_release_regions(pdev);
719err_out:
720 if (!pci_dev_busy)
721 pci_disable_device(pdev);
722 return rc;
723}
724
725
726static int __init pdc_ata_init(void)
727{
728 return pci_module_init(&pdc_ata_pci_driver);
729}
730
731
732static void __exit pdc_ata_exit(void)
733{
734 pci_unregister_driver(&pdc_ata_pci_driver);
735}
736
737
738MODULE_AUTHOR("Jeff Garzik");
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400739MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740MODULE_LICENSE("GPL");
741MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
742MODULE_VERSION(DRV_VERSION);
743
744module_init(pdc_ata_init);
745module_exit(pdc_ata_exit);