aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-02-07 12:19:26 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-02-07 12:19:26 -0500
commit6788182602f6862688d9a14e6f527449696f65c6 (patch)
tree6185f646f851f98561033c26d2a73b584a59c6e9 /drivers
parent9c6712c0bcd2954fb4ca58d31f7316292a4b0945 (diff)
ide: it8213 IDE driver update (version 2)
* set ATAPI/IORDY/TIME bits correctly in it8213_tuneproc() * fix UDMA/MWDMA/SWDMA masks in it8213_init_hwif() * in it8213_tune_chipset() SWDMA2 mode should be used instead of MWDMA0 * backport various fixes from piix/slc90e66 drivers: - in it8213_tuneproc() the highest possible PIO mode is PIO4 (not PIO5) - clear ATAPI/IORDY/TIME bits before setting them also for slave device - use ->speedproc in it8213_config_drive_for_dma() - don't try to tune PIO in config_chipset_for_pio() - simplify is_slave calculation in it8213_tuneproc() - misc cleanups * fix it8213_ratemask() and it8213_tuneproc() comments * simplify it8213_init_hwif() * remove init_chipset_it8213() * add missing Copyrights and update MODULE_AUTHOR() * CodingStyle cleanups * remove dead code v2: * PCI_DEVICE_ID_ITE_8213 is only defined in -mm kernels, so just use PCI Device ID (0x8213) directly * fix ->ultra_mask incorrectly changed to 0x3f in v1 version of the patch Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ide/pci/it8213.c172
1 files changed, 66 insertions, 106 deletions
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 6b46edfba811..63248b6909fa 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -1,3 +1,11 @@
1/*
2 * ITE 8213 IDE driver
3 *
4 * Copyright (C) 2006 Jack Lee
5 * Copyright (C) 2006 Alan Cox
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
7 */
8
1#include <linux/kernel.h> 9#include <linux/kernel.h>
2#include <linux/types.h> 10#include <linux/types.h>
3#include <linux/module.h> 11#include <linux/module.h>
@@ -14,14 +22,14 @@
14 * @drive: IDE drive 22 * @drive: IDE drive
15 * 23 *
16 * Compute the available speeds for the devices on the interface. This 24 * Compute the available speeds for the devices on the interface. This
17 * is all modes to ATA100 clipped by drive cable setup. 25 * is all modes to ATA133 clipped by drive cable setup.
18 */ 26 */
19 27
20static u8 it8213_ratemask (ide_drive_t *drive) 28static u8 it8213_ratemask (ide_drive_t *drive)
21{ 29{
22 u8 mode = 4; 30 u8 mode = 4;
23 if (!eighty_ninty_three(drive)) 31 if (!eighty_ninty_three(drive))
24 mode = min(mode, (u8)1); 32 mode = min_t(u8, mode, 1);
25 return mode; 33 return mode;
26} 34}
27 35
@@ -62,55 +70,57 @@ static u8 it8213_dma_2_pio (u8 xfer_rate) {
62 } 70 }
63} 71}
64 72
65static spinlock_t tune_lock = SPIN_LOCK_UNLOCKED;
66
67/* 73/*
68 * it8213_tuneproc - tune a drive 74 * it8213_tuneproc - tune a drive
69 * @drive: drive to tune 75 * @drive: drive to tune
70 * @mode_wanted: the target operating mode 76 * @pio: desired PIO mode
71 *
72 * Load the timing settings for this device mode into the
73 * controller. By the time we are called the mode has been
74 * modified as neccessary to handle the absence of seperate
75 * master/slave timers for MWDMA/PIO.
76 * 77 *
77 * This code is only used in pass through mode. 78 * Set the interface PIO mode.
78 */ 79 */
79 80
80static void it8213_tuneproc (ide_drive_t *drive, u8 pio) 81static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
81{ 82{
82 ide_hwif_t *hwif = HWIF(drive); 83 ide_hwif_t *hwif = HWIF(drive);
83 struct pci_dev *dev = hwif->pci_dev; 84 struct pci_dev *dev = hwif->pci_dev;
84 int is_slave = (&hwif->drives[1] == drive); 85 int is_slave = drive->dn & 1;
85 int master_port = 0x40; 86 int master_port = 0x40;
86 int slave_port = 0x44; 87 int slave_port = 0x44;
87 unsigned long flags; 88 unsigned long flags;
88 u16 master_data; 89 u16 master_data;
89 u8 slave_data; 90 u8 slave_data;
91 static DEFINE_SPINLOCK(tune_lock);
92 int control = 0;
90 93
91 u8 timings[][2] = { { 0, 0 }, 94 static const u8 timings[][2]= {
92 { 0, 0 }, 95 { 0, 0 },
93 { 1, 0 }, 96 { 0, 0 },
94 { 2, 1 }, 97 { 1, 0 },
95 { 2, 3 }, }; 98 { 2, 1 },
99 { 2, 3 }, };
96 100
97 pio = ide_get_best_pio_mode(drive, pio, 5, NULL); 101 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
98 102
99 spin_lock_irqsave(&tune_lock, flags); 103 spin_lock_irqsave(&tune_lock, flags);
100 pci_read_config_word(dev, master_port, &master_data); 104 pci_read_config_word(dev, master_port, &master_data);
105
106 if (pio > 1)
107 control |= 1; /* Programmable timing on */
108 if (drive->media != ide_disk)
109 control |= 4; /* ATAPI */
110 if (pio > 2)
111 control |= 2; /* IORDY */
101 if (is_slave) { 112 if (is_slave) {
102 master_data = master_data | 0x4000; 113 master_data |= 0x4000;
114 master_data &= ~0x0070;
103 if (pio > 1) 115 if (pio > 1)
104 116 master_data = master_data | (control << 4);
105 master_data = master_data | 0x0070;
106 pci_read_config_byte(dev, slave_port, &slave_data); 117 pci_read_config_byte(dev, slave_port, &slave_data);
107 slave_data = slave_data & 0xf0; 118 slave_data = slave_data & 0xf0;
108 slave_data = slave_data | (((timings[pio][0] << 2) | (timings[pio][1]) << 0)); 119 slave_data = slave_data | (timings[pio][0] << 2) | timings[pio][1];
109 } else { 120 } else {
110 master_data = master_data & 0xccf8; 121 master_data &= ~0x3307;
111 if (pio > 1) 122 if (pio > 1)
112 123 master_data = master_data | control;
113 master_data = master_data | 0x0007;
114 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); 124 master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8);
115 } 125 }
116 pci_write_config_word(dev, master_port, master_data); 126 pci_write_config_word(dev, master_port, master_data);
@@ -119,7 +129,6 @@ static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
119 spin_unlock_irqrestore(&tune_lock, flags); 129 spin_unlock_irqrestore(&tune_lock, flags);
120} 130}
121 131
122
123/** 132/**
124 * it8213_tune_chipset - set controller timings 133 * it8213_tune_chipset - set controller timings
125 * @drive: Drive to set up 134 * @drive: Drive to set up
@@ -130,7 +139,7 @@ static void it8213_tuneproc (ide_drive_t *drive, u8 pio)
130 * make the thing work. 139 * make the thing work.
131 */ 140 */
132 141
133static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed) 142static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
134{ 143{
135 144
136 ide_hwif_t *hwif = HWIF(drive); 145 ide_hwif_t *hwif = HWIF(drive);
@@ -154,15 +163,15 @@ static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
154 switch(speed) { 163 switch(speed) {
155 case XFER_UDMA_6: 164 case XFER_UDMA_6:
156 case XFER_UDMA_4: 165 case XFER_UDMA_4:
157 case XFER_UDMA_2:u_speed = 2 << (drive->dn * 4); break; 166 case XFER_UDMA_2: u_speed = 2 << (drive->dn * 4); break;
158 case XFER_UDMA_5: 167 case XFER_UDMA_5:
159 case XFER_UDMA_3: 168 case XFER_UDMA_3:
160 case XFER_UDMA_1:u_speed = 1 << (drive->dn * 4); break; 169 case XFER_UDMA_1: u_speed = 1 << (drive->dn * 4); break;
161 case XFER_UDMA_0:u_speed = 0 << (drive->dn * 4); break; 170 case XFER_UDMA_0: u_speed = 0 << (drive->dn * 4); break;
162 break; 171 break;
163 case XFER_MW_DMA_2: 172 case XFER_MW_DMA_2:
164 case XFER_MW_DMA_1: 173 case XFER_MW_DMA_1:
165 case XFER_MW_DMA_0: 174 case XFER_SW_DMA_2:
166 break; 175 break;
167 case XFER_PIO_4: 176 case XFER_PIO_4:
168 case XFER_PIO_3: 177 case XFER_PIO_3:
@@ -174,8 +183,7 @@ static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
174 return -1; 183 return -1;
175 } 184 }
176 185
177 if (speed >= XFER_UDMA_0) 186 if (speed >= XFER_UDMA_0) {
178 {
179 if (!(reg48 & u_flag)) 187 if (!(reg48 & u_flag))
180 pci_write_config_byte(dev, 0x48, reg48 | u_flag); 188 pci_write_config_byte(dev, 0x48, reg48 | u_flag);
181 if (speed >= XFER_UDMA_5) { 189 if (speed >= XFER_UDMA_5) {
@@ -186,14 +194,12 @@ static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
186 194
187 if ((reg4a & a_speed) != u_speed) 195 if ((reg4a & a_speed) != u_speed)
188 pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); 196 pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
189 if (speed > XFER_UDMA_2) 197 if (speed > XFER_UDMA_2) {
190 {
191 if (!(reg54 & v_flag)) 198 if (!(reg54 & v_flag))
192 pci_write_config_byte(dev, 0x54, reg54 | v_flag); 199 pci_write_config_byte(dev, 0x54, reg54 | v_flag);
193 } else 200 } else
194 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); 201 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
195 } else /*if(speed >= XFER_UDMA_0)*/ 202 } else {
196 {
197 if (reg48 & u_flag) 203 if (reg48 & u_flag)
198 pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); 204 pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
199 if (reg4a & a_speed) 205 if (reg4a & a_speed)
@@ -202,11 +208,10 @@ static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
202 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); 208 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
203 if (reg55 & w_flag) 209 if (reg55 & w_flag)
204 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 210 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
205 } 211 }
206 it8213_tuneproc(drive, it8213_dma_2_pio(speed)); 212 it8213_tuneproc(drive, it8213_dma_2_pio(speed));
207 return ide_config_drive_speed(drive, speed); 213 return ide_config_drive_speed(drive, speed);
208 } 214}
209
210 215
211/* 216/*
212 * config_chipset_for_dma - configure for DMA 217 * config_chipset_for_dma - configure for DMA
@@ -217,48 +222,17 @@ static int it8213_tune_chipset (ide_drive_t *drive, byte xferspeed)
217 222
218static int config_chipset_for_dma (ide_drive_t *drive) 223static int config_chipset_for_dma (ide_drive_t *drive)
219{ 224{
220 u8 speed = ide_dma_speed(drive, it8213_ratemask(drive)); 225 u8 speed = ide_dma_speed(drive, it8213_ratemask(drive));
226
221 if (!speed) 227 if (!speed)
222 { 228 return 0;
223 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 229
224 speed = it8213_dma_2_pio(XFER_PIO_0 + tspeed);
225 }
226// config_it8213_chipset_for_pio(drive, !speed);
227 it8213_tune_chipset(drive, speed); 230 it8213_tune_chipset(drive, speed);
231
228 return ide_dma_enable(drive); 232 return ide_dma_enable(drive);
229} 233}
230 234
231/** 235/**
232 * config_it8213_chipset_for_pio - set drive timings
233 * @drive: drive to tune
234 * @speed we want
235 *
236 * Compute the best pio mode we can for a given device. We must
237 * pick a speed that does not cause problems with the other device
238 * on the cable.
239 */
240/*
241static void config_it8213_chipset_for_pio (ide_drive_t *drive, byte set_speed)
242{
243 ide_hwif_t *hwif = HWIF(drive);
244// u8 unit = drive->select.b.unit;
245 ide_hwif_t *hwif = drive->hwif;
246 ide_drive_t *pair = &hwif->drives[1-unit];
247 u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
248 u8 pair_pio;
249
250 if(pair != NULL) {
251 pair_pio = ide_get_best_pio_mode(pair, 255, 5, NULL);
252 if(pair_pio < set_pio)
253 set_pio = pair_pio;
254 }
255 it8213_tuneproc(drive, set_pio);
256 speed = XFER_PIO_0 + set_pio;
257 if (set_speed)
258 (void) ide_config_drive_speed(drive, speed);
259}
260*/
261/**
262 * it8213_configure_drive_for_dma - set up for DMA transfers 236 * it8213_configure_drive_for_dma - set up for DMA transfers
263 * @drive: drive we are going to set up 237 * @drive: drive we are going to set up
264 * 238 *
@@ -270,26 +244,19 @@ static void config_it8213_chipset_for_pio (ide_drive_t *drive, byte set_speed)
270 244
271static int it8213_config_drive_for_dma (ide_drive_t *drive) 245static int it8213_config_drive_for_dma (ide_drive_t *drive)
272{ 246{
273// ide_hwif_t *hwif = drive->hwif; 247 ide_hwif_t *hwif = drive->hwif;
274// struct hd_driveid *id = drive->id; 248
275 ide_hwif_t *hwif = HWIF(drive);
276 if (ide_use_dma(drive)) { 249 if (ide_use_dma(drive)) {
277 if (config_chipset_for_dma(drive)) 250 if (config_chipset_for_dma(drive))
278 return hwif->ide_dma_on(drive); 251 return hwif->ide_dma_on(drive);
279 } 252 }
280// config_it8213_chipset_for_pio(drive, 1);
281 hwif->tuneproc(drive, 255);
282 return hwif->ide_dma_off_quietly(drive);
283}
284 253
254 hwif->speedproc(drive, XFER_PIO_0
255 + ide_get_best_pio_mode(drive, 255, 4, NULL));
285 256
286static unsigned int __devinit init_chipset_it8213(struct pci_dev *dev, const char *name) 257 return hwif->ide_dma_off_quietly(drive);
287{
288 printk(KERN_INFO "it8213: controller in IDE mode.\n");
289 return 0;
290} 258}
291 259
292
293/** 260/**
294 * init_hwif_it8213 - set up hwif structs 261 * init_hwif_it8213 - set up hwif structs
295 * @hwif: interface to set up 262 * @hwif: interface to set up
@@ -302,9 +269,6 @@ static unsigned int __devinit init_chipset_it8213(struct pci_dev *dev, const cha
302static void __devinit init_hwif_it8213(ide_hwif_t *hwif) 269static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
303{ 270{
304 u8 reg42h = 0, ata66 = 0; 271 u8 reg42h = 0, ata66 = 0;
305 u8 mask = 0x02;
306
307 hwif->atapi_dma = 1;
308 272
309 hwif->speedproc = &it8213_tune_chipset; 273 hwif->speedproc = &it8213_tune_chipset;
310 hwif->tuneproc = &it8213_tuneproc; 274 hwif->tuneproc = &it8213_tuneproc;
@@ -315,19 +279,19 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
315 hwif->drives[1].autotune = 1; 279 hwif->drives[1].autotune = 1;
316 280
317 if (!hwif->dma_base) 281 if (!hwif->dma_base)
318 goto fallback; 282 return;
283
319 hwif->atapi_dma = 1; 284 hwif->atapi_dma = 1;
320 hwif->ultra_mask = 0x7f; 285 hwif->ultra_mask = 0x7f;
321 hwif->mwdma_mask = 0x07; 286 hwif->mwdma_mask = 0x06;
322 hwif->swdma_mask = 0x07; 287 hwif->swdma_mask = 0x04;
323 288
324 pci_read_config_byte(hwif->pci_dev, 0x42, &reg42h); 289 pci_read_config_byte(hwif->pci_dev, 0x42, &reg42h);
325 ata66 = (reg42h & mask) ? 0 : 1; 290 ata66 = (reg42h & 0x02) ? 0 : 1;
326 291
327 hwif->ide_dma_check = &it8213_config_drive_for_dma; 292 hwif->ide_dma_check = &it8213_config_drive_for_dma;
328 if (!(hwif->udma_four)) 293 if (!(hwif->udma_four))
329 hwif->udma_four = ata66; 294 hwif->udma_four = ata66;
330// hwif->udma_four = 0;
331 295
332 /* 296 /*
333 * The BIOS often doesn't set up DMA on this controller 297 * The BIOS often doesn't set up DMA on this controller
@@ -338,20 +302,15 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif)
338 302
339 hwif->drives[0].autodma = hwif->autodma; 303 hwif->drives[0].autodma = hwif->autodma;
340 hwif->drives[1].autodma = hwif->autodma; 304 hwif->drives[1].autodma = hwif->autodma;
341 return;
342fallback:
343 hwif->autodma = 0;
344 return;
345} 305}
346 306
347 307
348#define DECLARE_ITE_DEV(name_str) \ 308#define DECLARE_ITE_DEV(name_str) \
349 { \ 309 { \
350 .name = name_str, \ 310 .name = name_str, \
351 .init_chipset = init_chipset_it8213, \
352 .init_hwif = init_hwif_it8213, \ 311 .init_hwif = init_hwif_it8213, \
353 .channels = 1, \ 312 .channels = 1, \
354 .autodma = AUTODMA, \ 313 .autodma = AUTODMA, \
355 .enablebits = {{0x41,0x80,0x80}}, \ 314 .enablebits = {{0x41,0x80,0x80}}, \
356 .bootable = ON_BOARD, \ 315 .bootable = ON_BOARD, \
357 } 316 }
@@ -379,7 +338,7 @@ static int __devinit it8213_init_one(struct pci_dev *dev, const struct pci_devic
379 338
380 339
381static struct pci_device_id it8213_pci_tbl[] = { 340static struct pci_device_id it8213_pci_tbl[] = {
382 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8213, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 341 { PCI_VENDOR_ID_ITE, 0x8213, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
383 { 0, }, 342 { 0, },
384}; 343};
385 344
@@ -393,10 +352,11 @@ static struct pci_driver driver = {
393 352
394static int __init it8213_ide_init(void) 353static int __init it8213_ide_init(void)
395{ 354{
396 return ide_pci_register_driver(&driver); } 355 return ide_pci_register_driver(&driver);
356}
397 357
398module_init(it8213_ide_init); 358module_init(it8213_ide_init);
399 359
400MODULE_AUTHOR("Jack and Alan Cox"); /* Update this */ 360MODULE_AUTHOR("Jack Lee, Alan Cox");
401MODULE_DESCRIPTION("PCI driver module for the ITE 8213"); 361MODULE_DESCRIPTION("PCI driver module for the ITE 8213");
402MODULE_LICENSE("GPL"); 362MODULE_LICENSE("GPL");