aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/cy82c693.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/cy82c693.c')
-rw-r--r--drivers/ide/cy82c693.c173
1 files changed, 23 insertions, 150 deletions
diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
index 74fc5401f407..9383f67deae1 100644
--- a/drivers/ide/cy82c693.c
+++ b/drivers/ide/cy82c693.c
@@ -1,43 +1,11 @@
1/* 1/*
2 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer 2 * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer
3 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator 3 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator
4 * Copyright (C) 2007-2010 Bartlomiej Zolnierkiewicz
4 * 5 *
5 * CYPRESS CY82C693 chipset IDE controller 6 * CYPRESS CY82C693 chipset IDE controller
6 * 7 *
7 * The CY82C693 chipset is used on Digital's PC-Alpha 164SX boards. 8 * The CY82C693 chipset is used on Digital's PC-Alpha 164SX boards.
8 * Writing the driver was quite simple, since most of the job is
9 * done by the generic pci-ide support.
10 * The hard part was finding the CY82C693's datasheet on Cypress's
11 * web page :-(. But Altavista solved this problem :-).
12 *
13 *
14 * Notes:
15 * - I recently got a 16.8G IBM DTTA, so I was able to test it with
16 * a large and fast disk - the results look great, so I'd say the
17 * driver is working fine :-)
18 * hdparm -t reports 8.17 MB/sec at about 6% CPU usage for the DTTA
19 * - this is my first linux driver, so there's probably a lot of room
20 * for optimizations and bug fixing, so feel free to do it.
21 * - if using PIO mode it's a good idea to set the PIO mode and
22 * 32-bit I/O support (if possible), e.g. hdparm -p2 -c1 /dev/hda
23 * - I had some problems with my IBM DHEA with PIO modes < 2
24 * (lost interrupts) ?????
25 * - first tests with DMA look okay, they seem to work, but there is a
26 * problem with sound - the BusMaster IDE TimeOut should fixed this
27 *
28 * Ancient History:
29 * AMH@1999-08-24: v0.34 init_cy82c693_chip moved to pci_init_cy82c693
30 * ASK@1999-01-23: v0.33 made a few minor code clean ups
31 * removed DMA clock speed setting by default
32 * added boot message
33 * ASK@1998-11-01: v0.32 added support to set BusMaster IDE TimeOut
34 * added support to set DMA Controller Clock Speed
35 * ASK@1998-10-31: v0.31 fixed problem with setting to high DMA modes
36 * on some drives.
37 * ASK@1998-10-29: v0.3 added support to set DMA modes
38 * ASK@1998-10-28: v0.2 added support to set PIO modes
39 * ASK@1998-10-27: v0.1 first version - chipset detection
40 *
41 */ 9 */
42 10
43#include <linux/module.h> 11#include <linux/module.h>
@@ -51,11 +19,6 @@
51#define DRV_NAME "cy82c693" 19#define DRV_NAME "cy82c693"
52 20
53/* 21/*
54 * The following are used to debug the driver.
55 */
56#define CY82C693_DEBUG_INFO 0
57
58/*
59 * NOTE: the value for busmaster timeout is tricky and I got it by 22 * NOTE: the value for busmaster timeout is tricky and I got it by
60 * trial and error! By using a to low value will cause DMA timeouts 23 * trial and error! By using a to low value will cause DMA timeouts
61 * and drop IDE performance, and by using a to high value will cause 24 * and drop IDE performance, and by using a to high value will cause
@@ -86,87 +49,13 @@
86#define CY82_INDEX_CHANNEL1 0x31 49#define CY82_INDEX_CHANNEL1 0x31
87#define CY82_INDEX_TIMEOUT 0x32 50#define CY82_INDEX_TIMEOUT 0x32
88 51
89/* the min and max PCI bus speed in MHz - from datasheet */
90#define CY82C963_MIN_BUS_SPEED 25
91#define CY82C963_MAX_BUS_SPEED 33
92
93/* the struct for the PIO mode timings */
94typedef struct pio_clocks_s {
95 u8 address_time; /* Address setup (clocks) */
96 u8 time_16r; /* clocks for 16bit IOR (0xF0=Active/data, 0x0F=Recovery) */
97 u8 time_16w; /* clocks for 16bit IOW (0xF0=Active/data, 0x0F=Recovery) */
98 u8 time_8; /* clocks for 8bit (0xF0=Active/data, 0x0F=Recovery) */
99} pio_clocks_t;
100
101/*
102 * calc clocks using bus_speed
103 * returns (rounded up) time in bus clocks for time in ns
104 */
105static int calc_clk(int time, int bus_speed)
106{
107 int clocks;
108
109 clocks = (time*bus_speed+999)/1000 - 1;
110
111 if (clocks < 0)
112 clocks = 0;
113
114 if (clocks > 0x0F)
115 clocks = 0x0F;
116
117 return clocks;
118}
119
120/*
121 * compute the values for the clock registers for PIO
122 * mode and pci_clk [MHz] speed
123 *
124 * NOTE: for mode 0,1 and 2 drives 8-bit IDE command control registers are used
125 * for mode 3 and 4 drives 8 and 16-bit timings are the same
126 *
127 */
128static void compute_clocks(u8 pio, pio_clocks_t *p_pclk)
129{
130 struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio);
131 int clk1, clk2;
132 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
133
134 /* we don't check against CY82C693's min and max speed,
135 * so you can play with the idebus=xx parameter
136 */
137
138 /* let's calc the address setup time clocks */
139 p_pclk->address_time = (u8)calc_clk(t->setup, bus_speed);
140
141 /* let's calc the active and recovery time clocks */
142 clk1 = calc_clk(t->active, bus_speed);
143
144 /* calc recovery timing */
145 clk2 = t->cycle - t->active - t->setup;
146
147 clk2 = calc_clk(clk2, bus_speed);
148
149 clk1 = (clk1<<4)|clk2; /* combine active and recovery clocks */
150
151 /* note: we use the same values for 16bit IOR and IOW
152 * those are all the same, since I don't have other
153 * timings than those from ide-lib.c
154 */
155
156 p_pclk->time_16r = (u8)clk1;
157 p_pclk->time_16w = (u8)clk1;
158
159 /* what are good values for 8bit ?? */
160 p_pclk->time_8 = (u8)clk1;
161}
162
163/* 52/*
164 * set DMA mode a specific channel for CY82C693 53 * set DMA mode a specific channel for CY82C693
165 */ 54 */
166 55
167static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode) 56static void cy82c693_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
168{ 57{
169 ide_hwif_t *hwif = drive->hwif; 58 const u8 mode = drive->dma_mode;
170 u8 single = (mode & 0x10) >> 4, index = 0, data = 0; 59 u8 single = (mode & 0x10) >> 4, index = 0, data = 0;
171 60
172 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0; 61 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0;
@@ -176,11 +65,6 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
176 outb(index, CY82_INDEX_PORT); 65 outb(index, CY82_INDEX_PORT);
177 outb(data, CY82_DATA_PORT); 66 outb(data, CY82_DATA_PORT);
178 67
179#if CY82C693_DEBUG_INFO
180 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
181 drive->name, hwif->channel, drive->dn & 1, mode & 3, single);
182#endif /* CY82C693_DEBUG_INFO */
183
184 /* 68 /*
185 * note: below we set the value for Bus Master IDE TimeOut Register 69 * note: below we set the value for Bus Master IDE TimeOut Register
186 * I'm not absolutly sure what this does, but it solved my problem 70 * I'm not absolutly sure what this does, but it solved my problem
@@ -194,19 +78,16 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
194 data = BUSMASTER_TIMEOUT; 78 data = BUSMASTER_TIMEOUT;
195 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT); 79 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT);
196 outb(data, CY82_DATA_PORT); 80 outb(data, CY82_DATA_PORT);
197
198#if CY82C693_DEBUG_INFO
199 printk(KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n",
200 drive->name, data);
201#endif /* CY82C693_DEBUG_INFO */
202} 81}
203 82
204static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio) 83static void cy82c693_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
205{ 84{
206 ide_hwif_t *hwif = drive->hwif;
207 struct pci_dev *dev = to_pci_dev(hwif->dev); 85 struct pci_dev *dev = to_pci_dev(hwif->dev);
208 pio_clocks_t pclk; 86 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
87 const unsigned long T = 1000000 / bus_speed;
209 unsigned int addrCtrl; 88 unsigned int addrCtrl;
89 struct ide_timing t;
90 u8 time_16, time_8;
210 91
211 /* select primary or secondary channel */ 92 /* select primary or secondary channel */
212 if (hwif->index > 0) { /* drive is on the secondary channel */ 93 if (hwif->index > 0) { /* drive is on the secondary channel */
@@ -219,8 +100,12 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
219 } 100 }
220 } 101 }
221 102
222 /* let's calc the values for this PIO mode */ 103 ide_timing_compute(drive, drive->pio_mode, &t, T, 1);
223 compute_clocks(pio, &pclk); 104
105 time_16 = clamp_val(t.recover - 1, 0, 15) |
106 (clamp_val(t.active - 1, 0, 15) << 4);
107 time_8 = clamp_val(t.act8b - 1, 0, 15) |
108 (clamp_val(t.rec8b - 1, 0, 15) << 4);
224 109
225 /* now let's write the clocks registers */ 110 /* now let's write the clocks registers */
226 if ((drive->dn & 1) == 0) { 111 if ((drive->dn & 1) == 0) {
@@ -232,15 +117,13 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
232 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 117 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
233 118
234 addrCtrl &= (~0xF); 119 addrCtrl &= (~0xF);
235 addrCtrl |= (unsigned int)pclk.address_time; 120 addrCtrl |= clamp_val(t.setup - 1, 0, 15);
236 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl); 121 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl);
237 122
238 /* now let's set the remaining registers */ 123 /* now let's set the remaining registers */
239 pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, pclk.time_16r); 124 pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, time_16);
240 pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, pclk.time_16w); 125 pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, time_16);
241 pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, pclk.time_8); 126 pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, time_8);
242
243 addrCtrl &= 0xF;
244 } else { 127 } else {
245 /* 128 /*
246 * set slave drive 129 * set slave drive
@@ -250,24 +133,14 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
250 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); 133 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
251 134
252 addrCtrl &= (~0xF0); 135 addrCtrl &= (~0xF0);
253 addrCtrl |= ((unsigned int)pclk.address_time<<4); 136 addrCtrl |= (clamp_val(t.setup - 1, 0, 15) << 4);
254 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl); 137 pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl);
255 138
256 /* now let's set the remaining registers */ 139 /* now let's set the remaining registers */
257 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOR, pclk.time_16r); 140 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOR, time_16);
258 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, pclk.time_16w); 141 pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, time_16);
259 pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, pclk.time_8); 142 pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, time_8);
260
261 addrCtrl >>= 4;
262 addrCtrl &= 0xF;
263 } 143 }
264
265#if CY82C693_DEBUG_INFO
266 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
267 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
268 drive->name, hwif->channel, drive->dn & 1,
269 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
270#endif /* CY82C693_DEBUG_INFO */
271} 144}
272 145
273static void __devinit init_iops_cy82c693(ide_hwif_t *hwif) 146static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
@@ -352,6 +225,6 @@ static void __exit cy82c693_ide_exit(void)
352module_init(cy82c693_ide_init); 225module_init(cy82c693_ide_init);
353module_exit(cy82c693_ide_exit); 226module_exit(cy82c693_ide_exit);
354 227
355MODULE_AUTHOR("Andreas Krebs, Andre Hedrick"); 228MODULE_AUTHOR("Andreas Krebs, Andre Hedrick, Bartlomiej Zolnierkiewicz");
356MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE"); 229MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE");
357MODULE_LICENSE("GPL"); 230MODULE_LICENSE("GPL");