2 * pata_artop.c - ARTOP ATA controller driver
5 * (C) 2007 Bartlomiej Zolnierkiewicz
7 * Based in part on drivers/ide/pci/aec62xx.c
8 * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
9 * 865/865R fixes for Macintosh card version from a patch to the old
10 * driver by Thibaut VARENE <varenet@parisc-linux.org>
11 * When setting the PCI latency we must set 0x80 or higher for burst
12 * performance Alessandro Zummo <alessandro.zummo@towertech.it>
15 * Investigate no_dsc on 850R
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/init.h>
23 #include <linux/blkdev.h>
24 #include <linux/delay.h>
25 #include <linux/device.h>
26 #include <scsi/scsi_host.h>
27 #include <linux/libata.h>
28 #include <linux/ata.h>
30 #define DRV_NAME "pata_artop"
31 #define DRV_VERSION "0.4.5"
34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
35 * get PCI bus speed functionality we leave this as 0. Its a variable
36 * for when we get the functionality and also for folks wanting to
42 static int artop6210_pre_reset(struct ata_link
*link
, unsigned long deadline
)
44 struct ata_port
*ap
= link
->ap
;
45 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
46 const struct pci_bits artop_enable_bits
[] = {
47 { 0x4AU
, 1U, 0x02UL
, 0x02UL
}, /* port 0 */
48 { 0x4AU
, 1U, 0x04UL
, 0x04UL
}, /* port 1 */
51 if (!pci_test_config_bits(pdev
, &artop_enable_bits
[ap
->port_no
]))
54 return ata_sff_prereset(link
, deadline
);
58 * artop6260_pre_reset - check for 40/80 pin
60 * @deadline: deadline jiffies for the operation
62 * The ARTOP hardware reports the cable detect bits in register 0x49.
63 * Nothing complicated needed here.
66 static int artop6260_pre_reset(struct ata_link
*link
, unsigned long deadline
)
68 static const struct pci_bits artop_enable_bits
[] = {
69 { 0x4AU
, 1U, 0x02UL
, 0x02UL
}, /* port 0 */
70 { 0x4AU
, 1U, 0x04UL
, 0x04UL
}, /* port 1 */
73 struct ata_port
*ap
= link
->ap
;
74 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
76 /* Odd numbered device ids are the units with enable bits (the -R cards) */
77 if ((pdev
->device
& 1) &&
78 !pci_test_config_bits(pdev
, &artop_enable_bits
[ap
->port_no
]))
81 return ata_sff_prereset(link
, deadline
);
85 * artop6260_cable_detect - identify cable type
88 * Identify the cable type for the ARTOP interface in question
91 static int artop6260_cable_detect(struct ata_port
*ap
)
93 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
95 pci_read_config_byte(pdev
, 0x49, &tmp
);
96 if (tmp
& (1 << ap
->port_no
))
97 return ATA_CBL_PATA40
;
98 return ATA_CBL_PATA80
;
102 * artop6210_load_piomode - Load a set of PATA PIO timings
103 * @ap: Port whose timings we are configuring
107 * Set PIO mode for device, in host controller PCI config space. This
108 * is used both to set PIO timings in PIO mode and also to set the
109 * matching PIO clocking for UDMA, as well as the MWDMA timings.
112 * None (inherited from caller).
115 static void artop6210_load_piomode(struct ata_port
*ap
, struct ata_device
*adev
, unsigned int pio
)
117 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
118 int dn
= adev
->devno
+ 2 * ap
->port_no
;
119 const u16 timing
[2][5] = {
120 { 0x0000, 0x000A, 0x0008, 0x0303, 0x0301 },
121 { 0x0700, 0x070A, 0x0708, 0x0403, 0x0401 }
124 /* Load the PIO timing active/recovery bits */
125 pci_write_config_word(pdev
, 0x40 + 2 * dn
, timing
[clock
][pio
]);
129 * artop6210_set_piomode - Initialize host controller PATA PIO timings
130 * @ap: Port whose timings we are configuring
131 * @adev: Device we are configuring
133 * Set PIO mode for device, in host controller PCI config space. For
134 * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In
135 * the event UDMA is used the later call to set_dmamode will set the
139 * None (inherited from caller).
142 static void artop6210_set_piomode(struct ata_port
*ap
, struct ata_device
*adev
)
144 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
145 int dn
= adev
->devno
+ 2 * ap
->port_no
;
148 artop6210_load_piomode(ap
, adev
, adev
->pio_mode
- XFER_PIO_0
);
150 /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */
151 pci_read_config_byte(pdev
, 0x54, &ultra
);
152 ultra
&= ~(3 << (2 * dn
));
153 pci_write_config_byte(pdev
, 0x54, ultra
);
157 * artop6260_load_piomode - Initialize host controller PATA PIO timings
158 * @ap: Port whose timings we are configuring
159 * @adev: Device we are configuring
162 * Set PIO mode for device, in host controller PCI config space. The
163 * ARTOP6260 and relatives store the timing data differently.
166 * None (inherited from caller).
169 static void artop6260_load_piomode (struct ata_port
*ap
, struct ata_device
*adev
, unsigned int pio
)
171 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
172 int dn
= adev
->devno
+ 2 * ap
->port_no
;
173 const u8 timing
[2][5] = {
174 { 0x00, 0x0A, 0x08, 0x33, 0x31 },
175 { 0x70, 0x7A, 0x78, 0x43, 0x41 }
178 /* Load the PIO timing active/recovery bits */
179 pci_write_config_byte(pdev
, 0x40 + dn
, timing
[clock
][pio
]);
183 * artop6260_set_piomode - Initialize host controller PATA PIO timings
184 * @ap: Port whose timings we are configuring
185 * @adev: Device we are configuring
187 * Set PIO mode for device, in host controller PCI config space. For
188 * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In
189 * the event UDMA is used the later call to set_dmamode will set the
193 * None (inherited from caller).
196 static void artop6260_set_piomode(struct ata_port
*ap
, struct ata_device
*adev
)
198 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
201 artop6260_load_piomode(ap
, adev
, adev
->pio_mode
- XFER_PIO_0
);
203 /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */
204 pci_read_config_byte(pdev
, 0x44 + ap
->port_no
, &ultra
);
205 ultra
&= ~(7 << (4 * adev
->devno
)); /* One nibble per drive */
206 pci_write_config_byte(pdev
, 0x44 + ap
->port_no
, ultra
);
210 * artop6210_set_dmamode - Initialize host controller PATA PIO timings
211 * @ap: Port whose timings we are configuring
212 * @adev: Device whose timings we are configuring
214 * Set DMA mode for device, in host controller PCI config space.
217 * None (inherited from caller).
220 static void artop6210_set_dmamode (struct ata_port
*ap
, struct ata_device
*adev
)
223 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
224 int dn
= adev
->devno
+ 2 * ap
->port_no
;
227 if (adev
->dma_mode
== XFER_MW_DMA_0
)
232 /* Load the PIO timing active/recovery bits */
233 artop6210_load_piomode(ap
, adev
, pio
);
235 pci_read_config_byte(pdev
, 0x54, &ultra
);
236 ultra
&= ~(3 << (2 * dn
));
238 /* Add ultra DMA bits if in UDMA mode */
239 if (adev
->dma_mode
>= XFER_UDMA_0
) {
240 u8 mode
= (adev
->dma_mode
- XFER_UDMA_0
) + 1 - clock
;
243 ultra
|= (mode
<< (2 * dn
));
245 pci_write_config_byte(pdev
, 0x54, ultra
);
249 * artop6260_set_dmamode - Initialize host controller PATA PIO timings
250 * @ap: Port whose timings we are configuring
251 * @adev: Device we are configuring
253 * Set DMA mode for device, in host controller PCI config space. The
254 * ARTOP6260 and relatives store the timing data differently.
257 * None (inherited from caller).
260 static void artop6260_set_dmamode (struct ata_port
*ap
, struct ata_device
*adev
)
262 unsigned int pio
= adev
->pio_mode
- XFER_PIO_0
;
263 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
266 if (adev
->dma_mode
== XFER_MW_DMA_0
)
271 /* Load the PIO timing active/recovery bits */
272 artop6260_load_piomode(ap
, adev
, pio
);
274 /* Add ultra DMA bits if in UDMA mode */
275 pci_read_config_byte(pdev
, 0x44 + ap
->port_no
, &ultra
);
276 ultra
&= ~(7 << (4 * adev
->devno
)); /* One nibble per drive */
277 if (adev
->dma_mode
>= XFER_UDMA_0
) {
278 u8 mode
= adev
->dma_mode
- XFER_UDMA_0
+ 1 - clock
;
281 ultra
|= (mode
<< (4 * adev
->devno
));
283 pci_write_config_byte(pdev
, 0x44 + ap
->port_no
, ultra
);
287 * artop_6210_qc_defer - implement serialization
290 * Issue commands per host on this chip.
293 static int artop6210_qc_defer(struct ata_queued_cmd
*qc
)
295 struct ata_host
*host
= qc
->ap
->host
;
296 struct ata_port
*alt
= host
->ports
[1 ^ qc
->ap
->port_no
];
299 /* First apply the usual rules */
300 rc
= ata_std_qc_defer(qc
);
304 /* Now apply serialization rules. Only allow a command if the
305 other channel state machine is idle */
306 if (alt
&& alt
->qc_active
)
307 return ATA_DEFER_PORT
;
311 static struct scsi_host_template artop_sht
= {
312 ATA_BMDMA_SHT(DRV_NAME
),
315 static struct ata_port_operations artop6210_ops
= {
316 .inherits
= &ata_bmdma_port_ops
,
317 .cable_detect
= ata_cable_40wire
,
318 .set_piomode
= artop6210_set_piomode
,
319 .set_dmamode
= artop6210_set_dmamode
,
320 .prereset
= artop6210_pre_reset
,
321 .qc_defer
= artop6210_qc_defer
,
324 static struct ata_port_operations artop6260_ops
= {
325 .inherits
= &ata_bmdma_port_ops
,
326 .cable_detect
= artop6260_cable_detect
,
327 .set_piomode
= artop6260_set_piomode
,
328 .set_dmamode
= artop6260_set_dmamode
,
329 .prereset
= artop6260_pre_reset
,
334 * artop_init_one - Register ARTOP ATA PCI device with kernel services
335 * @pdev: PCI device to register
336 * @ent: Entry in artop_pci_tbl matching with @pdev
338 * Called from kernel PCI layer.
341 * Inherited from PCI layer (may sleep).
344 * Zero on success, or -ERRNO value.
347 static int artop_init_one (struct pci_dev
*pdev
, const struct pci_device_id
*id
)
349 static const struct ata_port_info info_6210
= {
350 .flags
= ATA_FLAG_SLAVE_POSS
,
351 .pio_mask
= ATA_PIO4
,
352 .mwdma_mask
= ATA_MWDMA2
,
353 .udma_mask
= ATA_UDMA2
,
354 .port_ops
= &artop6210_ops
,
356 static const struct ata_port_info info_626x
= {
357 .flags
= ATA_FLAG_SLAVE_POSS
,
358 .pio_mask
= ATA_PIO4
,
359 .mwdma_mask
= ATA_MWDMA2
,
360 .udma_mask
= ATA_UDMA4
,
361 .port_ops
= &artop6260_ops
,
363 static const struct ata_port_info info_628x
= {
364 .flags
= ATA_FLAG_SLAVE_POSS
,
365 .pio_mask
= ATA_PIO4
,
366 .mwdma_mask
= ATA_MWDMA2
,
367 .udma_mask
= ATA_UDMA5
,
368 .port_ops
= &artop6260_ops
,
370 static const struct ata_port_info info_628x_fast
= {
371 .flags
= ATA_FLAG_SLAVE_POSS
,
372 .pio_mask
= ATA_PIO4
,
373 .mwdma_mask
= ATA_MWDMA2
,
374 .udma_mask
= ATA_UDMA6
,
375 .port_ops
= &artop6260_ops
,
377 const struct ata_port_info
*ppi
[] = { NULL
, NULL
};
380 ata_print_version_once(&pdev
->dev
, DRV_VERSION
);
382 rc
= pcim_enable_device(pdev
);
386 if (id
->driver_data
== 0) { /* 6210 variant */
388 /* BIOS may have left us in UDMA, clear it before libata probe */
389 pci_write_config_byte(pdev
, 0x54, 0);
391 else if (id
->driver_data
== 1) /* 6260 */
393 else if (id
->driver_data
== 2) { /* 6280 or 6280 + fast */
394 unsigned long io
= pci_resource_start(pdev
, 4);
399 ppi
[0] = &info_628x_fast
;
400 /* Mac systems come up with some registers not set as we
403 /* Clear reset & test bits */
404 pci_read_config_byte(pdev
, 0x49, ®
);
405 pci_write_config_byte(pdev
, 0x49, reg
& ~ 0x30);
407 /* PCI latency must be > 0x80 for burst mode, tweak it
410 pci_read_config_byte(pdev
, PCI_LATENCY_TIMER
, ®
);
412 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x90);
414 /* Enable IRQ output and burst mode */
415 pci_read_config_byte(pdev
, 0x4a, ®
);
416 pci_write_config_byte(pdev
, 0x4a, (reg
& ~0x01) | 0x80);
420 BUG_ON(ppi
[0] == NULL
);
422 return ata_pci_bmdma_init_one(pdev
, ppi
, &artop_sht
, NULL
, 0);
425 static const struct pci_device_id artop_pci_tbl
[] = {
426 { PCI_VDEVICE(ARTOP
, 0x0005), 0 },
427 { PCI_VDEVICE(ARTOP
, 0x0006), 1 },
428 { PCI_VDEVICE(ARTOP
, 0x0007), 1 },
429 { PCI_VDEVICE(ARTOP
, 0x0008), 2 },
430 { PCI_VDEVICE(ARTOP
, 0x0009), 2 },
432 { } /* terminate list */
435 static struct pci_driver artop_pci_driver
= {
437 .id_table
= artop_pci_tbl
,
438 .probe
= artop_init_one
,
439 .remove
= ata_pci_remove_one
,
442 static int __init
artop_init(void)
444 return pci_register_driver(&artop_pci_driver
);
447 static void __exit
artop_exit(void)
449 pci_unregister_driver(&artop_pci_driver
);
452 module_init(artop_init
);
453 module_exit(artop_exit
);
455 MODULE_AUTHOR("Alan Cox");
456 MODULE_DESCRIPTION("SCSI low-level driver for ARTOP PATA");
457 MODULE_LICENSE("GPL");
458 MODULE_DEVICE_TABLE(pci
, artop_pci_tbl
);
459 MODULE_VERSION(DRV_VERSION
);