]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/ata/pata_winbond.c
pata_pcmcia: convert to new data_xfer prototype
[net-next-2.6.git] / drivers / ata / pata_winbond.c
CommitLineData
7e45b0e5
AC
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 */
f20b16ff 8
7e45b0e5
AC
9#include <linux/kernel.h>
10#include <linux/module.h>
7e45b0e5
AC
11#include <linux/init.h>
12#include <linux/blkdev.h>
13#include <linux/delay.h>
14#include <scsi/scsi_host.h>
15#include <linux/libata.h>
16#include <linux/platform_device.h>
17
18#define DRV_NAME "pata_winbond"
8bc3fc47 19#define DRV_VERSION "0.0.3"
7e45b0e5
AC
20
21#define NR_HOST 4 /* Two winbond controllers, two channels each */
22
23struct winbond_data {
24 unsigned long config;
25 struct platform_device *platform_dev;
26};
27
28static struct ata_host *winbond_host[NR_HOST];
29static struct winbond_data winbond_data[NR_HOST];
30static int nr_winbond_host;
31
32#ifdef MODULE
33static int probe_winbond = 1;
34#else
35static int probe_winbond;
36#endif
37
22503631 38static DEFINE_SPINLOCK(winbond_lock);
7e45b0e5
AC
39
40static void winbond_writecfg(unsigned long port, u8 reg, u8 val)
41{
42 unsigned long flags;
43 spin_lock_irqsave(&winbond_lock, flags);
44 outb(reg, port + 0x01);
45 outb(val, port + 0x02);
46 spin_unlock_irqrestore(&winbond_lock, flags);
47}
48
49static u8 winbond_readcfg(unsigned long port, u8 reg)
50{
51 u8 val;
52
53 unsigned long flags;
54 spin_lock_irqsave(&winbond_lock, flags);
55 outb(reg, port + 0x01);
56 val = inb(port + 0x02);
57 spin_unlock_irqrestore(&winbond_lock, flags);
58
59 return val;
60}
61
62static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev)
63{
64 struct ata_timing t;
65 struct winbond_data *winbond = ap->host->private_data;
66 int active, recovery;
67 u8 reg;
68 int timing = 0x88 + (ap->port_no * 4) + (adev->devno * 2);
69
70 reg = winbond_readcfg(winbond->config, 0x81);
f20b16ff 71
7e45b0e5
AC
72 /* Get the timing data in cycles */
73 if (reg & 0x40) /* Fast VLB bus, assume 50MHz */
74 ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
75 else
76 ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000);
77
78 active = (FIT(t.active, 3, 17) - 1) & 0x0F;
79 recovery = (FIT(t.recover, 1, 15) + 1) & 0x0F;
80 timing = (active << 4) | recovery;
81 winbond_writecfg(winbond->config, timing, reg);
f20b16ff 82
7e45b0e5 83 /* Load the setup timing */
f20b16ff 84
7e45b0e5
AC
85 reg = 0x35;
86 if (adev->class != ATA_DEV_ATA)
87 reg |= 0x08; /* FIFO off */
88 if (!ata_pio_need_iordy(adev))
89 reg |= 0x02; /* IORDY off */
90 reg |= (FIT(t.setup, 0, 3) << 6);
91 winbond_writecfg(winbond->config, timing + 1, reg);
92}
93
94
55dba312
TH
95static void winbond_data_xfer(struct ata_device *dev, unsigned char *buf,
96 unsigned int buflen, int rw)
7e45b0e5 97{
55dba312 98 struct ata_port *ap = dev->link->ap;
7e45b0e5
AC
99 int slop = buflen & 3;
100
55dba312
TH
101 if (ata_id_has_dword_io(dev->id)) {
102 if (rw == READ)
0d5ff566 103 ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
55dba312
TH
104 else
105 iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
7e45b0e5
AC
106
107 if (unlikely(slop)) {
55dba312
TH
108 u32 pad;
109 if (rw == READ) {
b50e56d8 110 pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
7e45b0e5 111 memcpy(buf + buflen - slop, &pad, slop);
55dba312
TH
112 } else {
113 memcpy(&pad, buf + buflen - slop, slop);
114 iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
7e45b0e5 115 }
55dba312 116 buflen += 4 - slop;
7e45b0e5
AC
117 }
118 } else
55dba312
TH
119 buflen = ata_data_xfer(dev, buf, buflen, rw);
120
121 return buflen;
7e45b0e5
AC
122}
123
124static struct scsi_host_template winbond_sht = {
125 .module = THIS_MODULE,
126 .name = DRV_NAME,
127 .ioctl = ata_scsi_ioctl,
128 .queuecommand = ata_scsi_queuecmd,
129 .can_queue = ATA_DEF_QUEUE,
130 .this_id = ATA_SHT_THIS_ID,
131 .sg_tablesize = LIBATA_MAX_PRD,
7e45b0e5
AC
132 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
133 .emulated = ATA_SHT_EMULATED,
134 .use_clustering = ATA_SHT_USE_CLUSTERING,
135 .proc_name = DRV_NAME,
136 .dma_boundary = ATA_DMA_BOUNDARY,
137 .slave_configure = ata_scsi_slave_config,
c972b60b 138 .slave_destroy = ata_scsi_slave_destroy,
7e45b0e5
AC
139 .bios_param = ata_std_bios_param,
140};
141
142static struct ata_port_operations winbond_port_ops = {
7e45b0e5
AC
143 .set_piomode = winbond_set_piomode,
144
145 .tf_load = ata_tf_load,
146 .tf_read = ata_tf_read,
147 .check_status = ata_check_status,
148 .exec_command = ata_exec_command,
149 .dev_select = ata_std_dev_select,
150
151 .freeze = ata_bmdma_freeze,
152 .thaw = ata_bmdma_thaw,
153 .error_handler = ata_bmdma_error_handler,
154 .post_internal_cmd = ata_bmdma_post_internal_cmd,
2f5344b1 155 .cable_detect = ata_cable_40wire,
7e45b0e5
AC
156
157 .qc_prep = ata_qc_prep,
158 .qc_issue = ata_qc_issue_prot,
159
160 .data_xfer = winbond_data_xfer,
161
7e45b0e5 162 .irq_clear = ata_bmdma_irq_clear,
246ce3b6 163 .irq_on = ata_irq_on,
7e45b0e5 164
81ad1837 165 .port_start = ata_sff_port_start,
7e45b0e5
AC
166};
167
168/**
169 * winbond_init_one - attach a winbond interface
170 * @type: Type to display
171 * @io: I/O port start
172 * @irq: interrupt line
173 * @fast: True if on a > 33Mhz VLB
174 *
175 * Register a VLB bus IDE interface. Such interfaces are PIO and we
176 * assume do not support IRQ sharing.
177 */
178
179static __init int winbond_init_one(unsigned long port)
180{
7e45b0e5 181 struct platform_device *pdev;
7e45b0e5 182 u8 reg;
5d728824 183 int i, rc;
7e45b0e5
AC
184
185 reg = winbond_readcfg(port, 0x81);
186 reg |= 0x80; /* jumpered mode off */
187 winbond_writecfg(port, 0x81, reg);
188 reg = winbond_readcfg(port, 0x83);
189 reg |= 0xF0; /* local control */
190 winbond_writecfg(port, 0x83, reg);
191 reg = winbond_readcfg(port, 0x85);
192 reg |= 0xF0; /* programmable timing */
193 winbond_writecfg(port, 0x85, reg);
194
195 reg = winbond_readcfg(port, 0x81);
f20b16ff 196
7e45b0e5
AC
197 if (!(reg & 0x03)) /* Disabled */
198 return 0;
199
200 for (i = 0; i < 2 ; i ++) {
0d5ff566 201 unsigned long cmd_port = 0x1F0 - (0x80 * i);
cbcdd875 202 unsigned long ctl_port = cmd_port + 0x206;
5d728824
TH
203 struct ata_host *host;
204 struct ata_port *ap;
0d5ff566 205 void __iomem *cmd_addr, *ctl_addr;
7e45b0e5 206
5d728824
TH
207 if (!(reg & (1 << i)))
208 continue;
209
210 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0);
211 if (IS_ERR(pdev))
212 return PTR_ERR(pdev);
213
214 rc = -ENOMEM;
215 host = ata_host_alloc(&pdev->dev, 1);
216 if (!host)
217 goto err_unregister;
cbcdd875 218 ap = host->ports[0];
5d728824
TH
219
220 rc = -ENOMEM;
221 cmd_addr = devm_ioport_map(&pdev->dev, cmd_port, 8);
cbcdd875 222 ctl_addr = devm_ioport_map(&pdev->dev, ctl_port, 1);
5d728824
TH
223 if (!cmd_addr || !ctl_addr)
224 goto err_unregister;
225
cbcdd875
TH
226 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", cmd_port, ctl_port);
227
5d728824
TH
228 ap->ops = &winbond_port_ops;
229 ap->pio_mask = 0x1F;
230 ap->flags |= ATA_FLAG_SLAVE_POSS;
231 ap->ioaddr.cmd_addr = cmd_addr;
232 ap->ioaddr.altstatus_addr = ctl_addr;
233 ap->ioaddr.ctl_addr = ctl_addr;
234 ata_std_ports(&ap->ioaddr);
235
236 /* hook in a private data structure per channel */
237 host->private_data = &winbond_data[nr_winbond_host];
238 winbond_data[nr_winbond_host].config = port;
239 winbond_data[nr_winbond_host].platform_dev = pdev;
240
241 /* activate */
242 rc = ata_host_activate(host, 14 + i, ata_interrupt, 0,
243 &winbond_sht);
244 if (rc)
245 goto err_unregister;
246
247 winbond_host[nr_winbond_host++] = dev_get_drvdata(&pdev->dev);
7e45b0e5
AC
248 }
249
250 return 0;
5d728824
TH
251
252 err_unregister:
253 platform_device_unregister(pdev);
254 return rc;
7e45b0e5
AC
255}
256
257/**
258 * winbond_init - attach winbond interfaces
259 *
260 * Attach winbond IDE interfaces by scanning the ports it may occupy.
261 */
262
263static __init int winbond_init(void)
264{
265 static const unsigned long config[2] = { 0x130, 0x1B0 };
266
267 int ct = 0;
268 int i;
f20b16ff 269
7e45b0e5
AC
270 if (probe_winbond == 0)
271 return -ENODEV;
272
273 /*
274 * Check both base addresses
275 */
276
277 for (i = 0; i < 2; i++) {
278 if (probe_winbond & (1<<i)) {
279 int ret = 0;
280 unsigned long port = config[i];
281
282 if (request_region(port, 2, "pata_winbond")) {
283 ret = winbond_init_one(port);
b447916e 284 if (ret <= 0)
7e45b0e5
AC
285 release_region(port, 2);
286 else ct+= ret;
287 }
288 }
289 }
290 if (ct != 0)
291 return 0;
292 return -ENODEV;
293}
294
295static __exit void winbond_exit(void)
296{
297 int i;
298
299 for (i = 0; i < nr_winbond_host; i++) {
24dc5f33 300 ata_host_detach(winbond_host[i]);
7e45b0e5
AC
301 release_region(winbond_data[i].config, 2);
302 platform_device_unregister(winbond_data[i].platform_dev);
303 }
304}
305
306MODULE_AUTHOR("Alan Cox");
307MODULE_DESCRIPTION("low-level driver for Winbond VL ATA");
308MODULE_LICENSE("GPL");
309MODULE_VERSION(DRV_VERSION);
310
311module_init(winbond_init);
312module_exit(winbond_exit);
313
314module_param(probe_winbond, int, 0);
315