diff options
-rw-r--r-- | drivers/ata/Kconfig | 7 | ||||
-rw-r--r-- | drivers/ata/Makefile | 1 | ||||
-rw-r--r-- | drivers/ata/pata_winbond.c | 306 |
3 files changed, 314 insertions, 0 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 03f6338acc8f..b38e2c325ea7 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig | |||
@@ -483,6 +483,13 @@ config PATA_WINBOND | |||
483 | 483 | ||
484 | If unsure, say N. | 484 | If unsure, say N. |
485 | 485 | ||
486 | config PATA_WINBOND_VLB | ||
487 | tristate "Winbond W83759A VLB PATA support (Experimental)" | ||
488 | depends on ISA && EXPERIMENTAL | ||
489 | help | ||
490 | Support for the Winbond W83759A controller on Vesa Local Bus | ||
491 | systems. | ||
492 | |||
486 | endif | 493 | endif |
487 | endmenu | 494 | endmenu |
488 | 495 | ||
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index 72243a677f9b..ff6c6db22baf 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile | |||
@@ -51,6 +51,7 @@ obj-$(CONFIG_PATA_SERVERWORKS) += pata_serverworks.o | |||
51 | obj-$(CONFIG_PATA_SIL680) += pata_sil680.o | 51 | obj-$(CONFIG_PATA_SIL680) += pata_sil680.o |
52 | obj-$(CONFIG_PATA_VIA) += pata_via.o | 52 | obj-$(CONFIG_PATA_VIA) += pata_via.o |
53 | obj-$(CONFIG_PATA_WINBOND) += pata_sl82c105.o | 53 | obj-$(CONFIG_PATA_WINBOND) += pata_sl82c105.o |
54 | obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o | ||
54 | obj-$(CONFIG_PATA_SIS) += pata_sis.o | 55 | obj-$(CONFIG_PATA_SIS) += pata_sis.o |
55 | obj-$(CONFIG_PATA_TRIFLEX) += pata_triflex.o | 56 | obj-$(CONFIG_PATA_TRIFLEX) += pata_triflex.o |
56 | # Should be last but one libata driver | 57 | # Should be last but one libata driver |
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c new file mode 100644 index 000000000000..48941d0757e9 --- /dev/null +++ b/drivers/ata/pata_winbond.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | * pata_winbond.c - Winbond VLB ATA controllers | ||
3 | * (C) 2006 Red Hat <alan@redhat.com> | ||
4 | * | ||
5 | * Support for the Winbond 83759A when operating in advanced mode. | ||
6 | * Multichip mode is not currently supported. | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/pci.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/blkdev.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <scsi/scsi_host.h> | ||
16 | #include <linux/libata.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | |||
19 | #define DRV_NAME "pata_winbond" | ||
20 | #define DRV_VERSION "0.0.1" | ||
21 | |||
22 | #define NR_HOST 4 /* Two winbond controllers, two channels each */ | ||
23 | |||
24 | struct winbond_data { | ||
25 | unsigned long config; | ||
26 | struct platform_device *platform_dev; | ||
27 | }; | ||
28 | |||
29 | static struct ata_host *winbond_host[NR_HOST]; | ||
30 | static struct winbond_data winbond_data[NR_HOST]; | ||
31 | static int nr_winbond_host; | ||
32 | |||
33 | #ifdef MODULE | ||
34 | static int probe_winbond = 1; | ||
35 | #else | ||
36 | static int probe_winbond; | ||
37 | #endif | ||
38 | |||
39 | static spinlock_t winbond_lock = SPIN_LOCK_UNLOCKED; | ||
40 | |||
41 | static void winbond_writecfg(unsigned long port, u8 reg, u8 val) | ||
42 | { | ||
43 | unsigned long flags; | ||
44 | spin_lock_irqsave(&winbond_lock, flags); | ||
45 | outb(reg, port + 0x01); | ||
46 | outb(val, port + 0x02); | ||
47 | spin_unlock_irqrestore(&winbond_lock, flags); | ||
48 | } | ||
49 | |||
50 | static u8 winbond_readcfg(unsigned long port, u8 reg) | ||
51 | { | ||
52 | u8 val; | ||
53 | |||
54 | unsigned long flags; | ||
55 | spin_lock_irqsave(&winbond_lock, flags); | ||
56 | outb(reg, port + 0x01); | ||
57 | val = inb(port + 0x02); | ||
58 | spin_unlock_irqrestore(&winbond_lock, flags); | ||
59 | |||
60 | return val; | ||
61 | } | ||
62 | |||
63 | static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev) | ||
64 | { | ||
65 | struct ata_timing t; | ||
66 | struct winbond_data *winbond = ap->host->private_data; | ||
67 | int active, recovery; | ||
68 | u8 reg; | ||
69 | int timing = 0x88 + (ap->port_no * 4) + (adev->devno * 2); | ||
70 | |||
71 | reg = winbond_readcfg(winbond->config, 0x81); | ||
72 | |||
73 | /* Get the timing data in cycles */ | ||
74 | if (reg & 0x40) /* Fast VLB bus, assume 50MHz */ | ||
75 | ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000); | ||
76 | else | ||
77 | ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000); | ||
78 | |||
79 | active = (FIT(t.active, 3, 17) - 1) & 0x0F; | ||
80 | recovery = (FIT(t.recover, 1, 15) + 1) & 0x0F; | ||
81 | timing = (active << 4) | recovery; | ||
82 | winbond_writecfg(winbond->config, timing, reg); | ||
83 | |||
84 | /* Load the setup timing */ | ||
85 | |||
86 | reg = 0x35; | ||
87 | if (adev->class != ATA_DEV_ATA) | ||
88 | reg |= 0x08; /* FIFO off */ | ||
89 | if (!ata_pio_need_iordy(adev)) | ||
90 | reg |= 0x02; /* IORDY off */ | ||
91 | reg |= (FIT(t.setup, 0, 3) << 6); | ||
92 | winbond_writecfg(winbond->config, timing + 1, reg); | ||
93 | } | ||
94 | |||
95 | |||
96 | static void winbond_data_xfer(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data) | ||
97 | { | ||
98 | struct ata_port *ap = adev->ap; | ||
99 | int slop = buflen & 3; | ||
100 | |||
101 | if (ata_id_has_dword_io(adev->id)) { | ||
102 | if (write_data) | ||
103 | outsl(ap->ioaddr.data_addr, buf, buflen >> 2); | ||
104 | else | ||
105 | insl(ap->ioaddr.data_addr, buf, buflen >> 2); | ||
106 | |||
107 | if (unlikely(slop)) { | ||
108 | u32 pad; | ||
109 | if (write_data) { | ||
110 | memcpy(&pad, buf + buflen - slop, slop); | ||
111 | outl(le32_to_cpu(pad), ap->ioaddr.data_addr); | ||
112 | } else { | ||
113 | pad = cpu_to_le16(inl(ap->ioaddr.data_addr)); | ||
114 | memcpy(buf + buflen - slop, &pad, slop); | ||
115 | } | ||
116 | } | ||
117 | } else | ||
118 | ata_pio_data_xfer(adev, buf, buflen, write_data); | ||
119 | } | ||
120 | |||
121 | static struct scsi_host_template winbond_sht = { | ||
122 | .module = THIS_MODULE, | ||
123 | .name = DRV_NAME, | ||
124 | .ioctl = ata_scsi_ioctl, | ||
125 | .queuecommand = ata_scsi_queuecmd, | ||
126 | .can_queue = ATA_DEF_QUEUE, | ||
127 | .this_id = ATA_SHT_THIS_ID, | ||
128 | .sg_tablesize = LIBATA_MAX_PRD, | ||
129 | .max_sectors = ATA_MAX_SECTORS, | ||
130 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, | ||
131 | .emulated = ATA_SHT_EMULATED, | ||
132 | .use_clustering = ATA_SHT_USE_CLUSTERING, | ||
133 | .proc_name = DRV_NAME, | ||
134 | .dma_boundary = ATA_DMA_BOUNDARY, | ||
135 | .slave_configure = ata_scsi_slave_config, | ||
136 | .bios_param = ata_std_bios_param, | ||
137 | }; | ||
138 | |||
139 | static struct ata_port_operations winbond_port_ops = { | ||
140 | .port_disable = ata_port_disable, | ||
141 | .set_piomode = winbond_set_piomode, | ||
142 | |||
143 | .tf_load = ata_tf_load, | ||
144 | .tf_read = ata_tf_read, | ||
145 | .check_status = ata_check_status, | ||
146 | .exec_command = ata_exec_command, | ||
147 | .dev_select = ata_std_dev_select, | ||
148 | |||
149 | .freeze = ata_bmdma_freeze, | ||
150 | .thaw = ata_bmdma_thaw, | ||
151 | .error_handler = ata_bmdma_error_handler, | ||
152 | .post_internal_cmd = ata_bmdma_post_internal_cmd, | ||
153 | |||
154 | .qc_prep = ata_qc_prep, | ||
155 | .qc_issue = ata_qc_issue_prot, | ||
156 | |||
157 | .data_xfer = winbond_data_xfer, | ||
158 | |||
159 | .irq_handler = ata_interrupt, | ||
160 | .irq_clear = ata_bmdma_irq_clear, | ||
161 | |||
162 | .port_start = ata_port_start, | ||
163 | .port_stop = ata_port_stop, | ||
164 | .host_stop = ata_host_stop | ||
165 | }; | ||
166 | |||
167 | /** | ||
168 | * winbond_init_one - attach a winbond interface | ||
169 | * @type: Type to display | ||
170 | * @io: I/O port start | ||
171 | * @irq: interrupt line | ||
172 | * @fast: True if on a > 33Mhz VLB | ||
173 | * | ||
174 | * Register a VLB bus IDE interface. Such interfaces are PIO and we | ||
175 | * assume do not support IRQ sharing. | ||
176 | */ | ||
177 | |||
178 | static __init int winbond_init_one(unsigned long port) | ||
179 | { | ||
180 | struct ata_probe_ent ae; | ||
181 | struct platform_device *pdev; | ||
182 | int ret; | ||
183 | u8 reg; | ||
184 | int i; | ||
185 | |||
186 | reg = winbond_readcfg(port, 0x81); | ||
187 | reg |= 0x80; /* jumpered mode off */ | ||
188 | winbond_writecfg(port, 0x81, reg); | ||
189 | reg = winbond_readcfg(port, 0x83); | ||
190 | reg |= 0xF0; /* local control */ | ||
191 | winbond_writecfg(port, 0x83, reg); | ||
192 | reg = winbond_readcfg(port, 0x85); | ||
193 | reg |= 0xF0; /* programmable timing */ | ||
194 | winbond_writecfg(port, 0x85, reg); | ||
195 | |||
196 | reg = winbond_readcfg(port, 0x81); | ||
197 | |||
198 | if (!(reg & 0x03)) /* Disabled */ | ||
199 | return 0; | ||
200 | |||
201 | for (i = 0; i < 2 ; i ++) { | ||
202 | |||
203 | if (reg & (1 << i)) { | ||
204 | /* | ||
205 | * Fill in a probe structure first of all | ||
206 | */ | ||
207 | |||
208 | pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0); | ||
209 | if (pdev == NULL) | ||
210 | return -ENOMEM; | ||
211 | |||
212 | memset(&ae, 0, sizeof(struct ata_probe_ent)); | ||
213 | INIT_LIST_HEAD(&ae.node); | ||
214 | ae.dev = &pdev->dev; | ||
215 | |||
216 | ae.port_ops = &winbond_port_ops; | ||
217 | ae.pio_mask = 0x1F; | ||
218 | |||
219 | ae.sht = &winbond_sht; | ||
220 | |||
221 | ae.n_ports = 1; | ||
222 | ae.irq = 14 + i; | ||
223 | ae.irq_flags = 0; | ||
224 | ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; | ||
225 | ae.port[0].cmd_addr = 0x1F0 - (0x80 * i); | ||
226 | ae.port[0].altstatus_addr = ae.port[0].cmd_addr + 0x0206; | ||
227 | ae.port[0].ctl_addr = ae.port[0].altstatus_addr; | ||
228 | ata_std_ports(&ae.port[0]); | ||
229 | /* | ||
230 | * Hook in a private data structure per channel | ||
231 | */ | ||
232 | ae.private_data = &winbond_data[nr_winbond_host]; | ||
233 | winbond_data[nr_winbond_host].config = port; | ||
234 | winbond_data[nr_winbond_host].platform_dev = pdev; | ||
235 | |||
236 | ret = ata_device_add(&ae); | ||
237 | if (ret == 0) { | ||
238 | platform_device_unregister(pdev); | ||
239 | return -ENODEV; | ||
240 | } | ||
241 | winbond_host[nr_winbond_host++] = dev_get_drvdata(&pdev->dev); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | /** | ||
249 | * winbond_init - attach winbond interfaces | ||
250 | * | ||
251 | * Attach winbond IDE interfaces by scanning the ports it may occupy. | ||
252 | */ | ||
253 | |||
254 | static __init int winbond_init(void) | ||
255 | { | ||
256 | static const unsigned long config[2] = { 0x130, 0x1B0 }; | ||
257 | |||
258 | int ct = 0; | ||
259 | int i; | ||
260 | |||
261 | if (probe_winbond == 0) | ||
262 | return -ENODEV; | ||
263 | |||
264 | /* | ||
265 | * Check both base addresses | ||
266 | */ | ||
267 | |||
268 | for (i = 0; i < 2; i++) { | ||
269 | if (probe_winbond & (1<<i)) { | ||
270 | int ret = 0; | ||
271 | unsigned long port = config[i]; | ||
272 | |||
273 | if (request_region(port, 2, "pata_winbond")) { | ||
274 | ret = winbond_init_one(port); | ||
275 | if(ret <= 0) | ||
276 | release_region(port, 2); | ||
277 | else ct+= ret; | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | if (ct != 0) | ||
282 | return 0; | ||
283 | return -ENODEV; | ||
284 | } | ||
285 | |||
286 | static __exit void winbond_exit(void) | ||
287 | { | ||
288 | int i; | ||
289 | |||
290 | for (i = 0; i < nr_winbond_host; i++) { | ||
291 | ata_host_remove(winbond_host[i]); | ||
292 | release_region(winbond_data[i].config, 2); | ||
293 | platform_device_unregister(winbond_data[i].platform_dev); | ||
294 | } | ||
295 | } | ||
296 | |||
297 | MODULE_AUTHOR("Alan Cox"); | ||
298 | MODULE_DESCRIPTION("low-level driver for Winbond VL ATA"); | ||
299 | MODULE_LICENSE("GPL"); | ||
300 | MODULE_VERSION(DRV_VERSION); | ||
301 | |||
302 | module_init(winbond_init); | ||
303 | module_exit(winbond_exit); | ||
304 | |||
305 | module_param(probe_winbond, int, 0); | ||
306 | |||