Commit | Line | Data |
---|---|---|
0df0d0a0 AZ |
1 | /* |
2 | * ixp4xx PATA/Compact Flash driver | |
3 | * Copyright (c) 2006 Tower Technologies | |
4 | * Author: Alessandro Zummo <a.zummo@towertech.it> | |
5 | * | |
6 | * An ATA driver to handle a Compact Flash connected | |
7 | * to the ixp4xx expansion bus in TrueIDE mode. The CF | |
8 | * must have it chip selects connected to two CS lines | |
9 | * on the ixp4xx. The interrupt line is optional, if not | |
10 | * specified the driver will run in polling mode. | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License version 2 as | |
14 | * published by the Free Software Foundation. | |
15 | * | |
16 | */ | |
17 | ||
18 | #include <linux/kernel.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/libata.h> | |
21 | #include <linux/irq.h> | |
22 | #include <linux/platform_device.h> | |
23 | #include <scsi/scsi_host.h> | |
24 | ||
25 | #define DRV_NAME "pata_ixp4xx_cf" | |
b229a7b0 | 26 | #define DRV_VERSION "0.1.1ac1" |
0df0d0a0 | 27 | |
b229a7b0 | 28 | static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device *adev) |
0df0d0a0 AZ |
29 | { |
30 | int i; | |
31 | ||
32 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | |
33 | struct ata_device *dev = &ap->device[i]; | |
34 | if (ata_dev_enabled(dev)) { | |
35 | dev->pio_mode = XFER_PIO_0; | |
36 | dev->xfer_mode = XFER_PIO_0; | |
37 | dev->xfer_shift = ATA_SHIFT_PIO; | |
38 | dev->flags |= ATA_DFLAG_PIO; | |
39 | } | |
40 | } | |
b229a7b0 | 41 | return 0; |
0df0d0a0 AZ |
42 | } |
43 | ||
44 | static void ixp4xx_phy_reset(struct ata_port *ap) | |
45 | { | |
46 | ap->cbl = ATA_CBL_PATA40; | |
47 | ata_port_probe(ap); | |
48 | ata_bus_reset(ap); | |
49 | } | |
50 | ||
51 | static void ixp4xx_mmio_data_xfer(struct ata_device *adev, unsigned char *buf, | |
52 | unsigned int buflen, int write_data) | |
53 | { | |
54 | unsigned int i; | |
55 | unsigned int words = buflen >> 1; | |
56 | u16 *buf16 = (u16 *) buf; | |
57 | struct ata_port *ap = adev->ap; | |
58 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; | |
59 | struct ixp4xx_pata_data *data = ap->host->dev->platform_data; | |
60 | ||
61 | /* set the expansion bus in 16bit mode and restore | |
62 | * 8 bit mode after the transaction. | |
63 | */ | |
64 | *data->cs0_cfg &= ~(0x01); | |
65 | udelay(100); | |
66 | ||
67 | /* Transfer multiple of 2 bytes */ | |
68 | if (write_data) { | |
69 | for (i = 0; i < words; i++) | |
70 | writew(buf16[i], mmio); | |
71 | } else { | |
72 | for (i = 0; i < words; i++) | |
73 | buf16[i] = readw(mmio); | |
74 | } | |
75 | ||
76 | /* Transfer trailing 1 byte, if any. */ | |
77 | if (unlikely(buflen & 0x01)) { | |
78 | u16 align_buf[1] = { 0 }; | |
79 | unsigned char *trailing_buf = buf + buflen - 1; | |
80 | ||
81 | if (write_data) { | |
82 | memcpy(align_buf, trailing_buf, 1); | |
83 | writew(align_buf[0], mmio); | |
84 | } else { | |
85 | align_buf[0] = readw(mmio); | |
86 | memcpy(trailing_buf, align_buf, 1); | |
87 | } | |
88 | } | |
89 | ||
90 | udelay(100); | |
91 | *data->cs0_cfg |= 0x01; | |
92 | } | |
93 | ||
94 | static void ixp4xx_irq_clear(struct ata_port *ap) | |
95 | { | |
96 | } | |
97 | ||
0df0d0a0 AZ |
98 | static struct scsi_host_template ixp4xx_sht = { |
99 | .module = THIS_MODULE, | |
100 | .name = DRV_NAME, | |
101 | .ioctl = ata_scsi_ioctl, | |
102 | .queuecommand = ata_scsi_queuecmd, | |
103 | .can_queue = ATA_DEF_QUEUE, | |
104 | .this_id = ATA_SHT_THIS_ID, | |
105 | .sg_tablesize = LIBATA_MAX_PRD, | |
0df0d0a0 AZ |
106 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
107 | .emulated = ATA_SHT_EMULATED, | |
108 | .use_clustering = ATA_SHT_USE_CLUSTERING, | |
109 | .proc_name = DRV_NAME, | |
110 | .dma_boundary = ATA_DMA_BOUNDARY, | |
111 | .slave_configure = ata_scsi_slave_config, | |
c972b60b | 112 | .slave_destroy = ata_scsi_slave_destroy, |
0df0d0a0 AZ |
113 | .bios_param = ata_std_bios_param, |
114 | }; | |
115 | ||
116 | static struct ata_port_operations ixp4xx_port_ops = { | |
117 | .set_mode = ixp4xx_set_mode, | |
118 | .mode_filter = ata_pci_default_filter, | |
119 | ||
120 | .port_disable = ata_port_disable, | |
121 | .tf_load = ata_tf_load, | |
122 | .tf_read = ata_tf_read, | |
123 | .check_status = ata_check_status, | |
124 | .exec_command = ata_exec_command, | |
125 | .dev_select = ata_std_dev_select, | |
126 | ||
127 | .qc_prep = ata_qc_prep, | |
128 | .qc_issue = ata_qc_issue_prot, | |
129 | .eng_timeout = ata_eng_timeout, | |
130 | .data_xfer = ixp4xx_mmio_data_xfer, | |
131 | ||
132 | .irq_handler = ata_interrupt, | |
133 | .irq_clear = ixp4xx_irq_clear, | |
134 | ||
135 | .port_start = ata_port_start, | |
0df0d0a0 AZ |
136 | |
137 | .phy_reset = ixp4xx_phy_reset, | |
138 | }; | |
139 | ||
140 | static void ixp4xx_setup_port(struct ata_ioports *ioaddr, | |
141 | struct ixp4xx_pata_data *data) | |
142 | { | |
143 | ioaddr->cmd_addr = (unsigned long) data->cs0; | |
144 | ioaddr->altstatus_addr = (unsigned long) data->cs1 + 0x06; | |
145 | ioaddr->ctl_addr = (unsigned long) data->cs1 + 0x06; | |
146 | ||
147 | ata_std_ports(ioaddr); | |
148 | ||
149 | #ifndef __ARMEB__ | |
150 | ||
151 | /* adjust the addresses to handle the address swizzling of the | |
152 | * ixp4xx in little endian mode. | |
153 | */ | |
154 | ||
155 | ioaddr->data_addr ^= 0x02; | |
156 | ioaddr->cmd_addr ^= 0x03; | |
157 | ioaddr->altstatus_addr ^= 0x03; | |
158 | ioaddr->ctl_addr ^= 0x03; | |
159 | ioaddr->error_addr ^= 0x03; | |
160 | ioaddr->feature_addr ^= 0x03; | |
161 | ioaddr->nsect_addr ^= 0x03; | |
162 | ioaddr->lbal_addr ^= 0x03; | |
163 | ioaddr->lbam_addr ^= 0x03; | |
164 | ioaddr->lbah_addr ^= 0x03; | |
165 | ioaddr->device_addr ^= 0x03; | |
166 | ioaddr->status_addr ^= 0x03; | |
167 | ioaddr->command_addr ^= 0x03; | |
168 | #endif | |
169 | } | |
170 | ||
171 | static __devinit int ixp4xx_pata_probe(struct platform_device *pdev) | |
172 | { | |
173 | int ret; | |
174 | unsigned int irq; | |
175 | struct resource *cs0, *cs1; | |
176 | struct ata_probe_ent ae; | |
177 | ||
178 | struct ixp4xx_pata_data *data = pdev->dev.platform_data; | |
179 | ||
180 | cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
181 | cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); | |
182 | ||
183 | if (!cs0 || !cs1) | |
184 | return -EINVAL; | |
185 | ||
186 | pdev->dev.coherent_dma_mask = DMA_32BIT_MASK; | |
187 | ||
24dc5f33 TH |
188 | data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000); |
189 | data->cs1 = devm_ioremap(&pdev->dev, cs1->start, 0x1000); | |
0df0d0a0 AZ |
190 | |
191 | irq = platform_get_irq(pdev, 0); | |
192 | if (irq) | |
193 | set_irq_type(irq, IRQT_HIGH); | |
194 | ||
195 | /* Setup expansion bus chip selects */ | |
196 | *data->cs0_cfg = data->cs0_bits; | |
197 | *data->cs1_cfg = data->cs1_bits; | |
198 | ||
199 | memset(&ae, 0, sizeof(struct ata_probe_ent)); | |
200 | INIT_LIST_HEAD(&ae.node); | |
201 | ||
202 | ae.dev = &pdev->dev; | |
203 | ae.port_ops = &ixp4xx_port_ops; | |
204 | ae.sht = &ixp4xx_sht; | |
205 | ae.n_ports = 1; | |
206 | ae.pio_mask = 0x1f; /* PIO4 */ | |
207 | ae.irq = irq; | |
208 | ae.irq_flags = 0; | |
209 | ae.port_flags = ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY | |
210 | | ATA_FLAG_NO_ATAPI | ATA_FLAG_SRST; | |
211 | ||
212 | /* run in polling mode if no irq has been assigned */ | |
213 | if (!irq) | |
214 | ae.port_flags |= ATA_FLAG_PIO_POLLING; | |
215 | ||
216 | ixp4xx_setup_port(&ae.port[0], data); | |
217 | ||
218 | dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); | |
219 | ||
220 | ret = ata_device_add(&ae); | |
221 | if (ret == 0) | |
222 | return -ENODEV; | |
223 | ||
224 | return 0; | |
225 | } | |
226 | ||
227 | static __devexit int ixp4xx_pata_remove(struct platform_device *dev) | |
228 | { | |
229 | struct ata_host *host = platform_get_drvdata(dev); | |
230 | ||
24dc5f33 | 231 | ata_host_detach(host); |
0df0d0a0 AZ |
232 | platform_set_drvdata(dev, NULL); |
233 | ||
234 | return 0; | |
235 | } | |
236 | ||
237 | static struct platform_driver ixp4xx_pata_platform_driver = { | |
238 | .driver = { | |
239 | .name = DRV_NAME, | |
240 | .owner = THIS_MODULE, | |
241 | }, | |
242 | .probe = ixp4xx_pata_probe, | |
243 | .remove = __devexit_p(ixp4xx_pata_remove), | |
244 | }; | |
245 | ||
246 | static int __init ixp4xx_pata_init(void) | |
247 | { | |
248 | return platform_driver_register(&ixp4xx_pata_platform_driver); | |
249 | } | |
250 | ||
251 | static void __exit ixp4xx_pata_exit(void) | |
252 | { | |
253 | platform_driver_unregister(&ixp4xx_pata_platform_driver); | |
254 | } | |
255 | ||
256 | MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); | |
257 | MODULE_DESCRIPTION("low-level driver for ixp4xx Compact Flash PATA"); | |
258 | MODULE_LICENSE("GPL"); | |
259 | MODULE_VERSION(DRV_VERSION); | |
260 | ||
261 | module_init(ixp4xx_pata_init); | |
262 | module_exit(ixp4xx_pata_exit); |