Blame view
drivers/ata/sata_uli.c
6.56 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 |
/* * sata_uli.c - ULi Electronics SATA * |
af36d7f0d [libata] license ... |
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * * libata documentation is available via 'make {ps|pdf}docs', * as Documentation/DocBook/libata.* * * Hardware documentation available under NDA. |
1da177e4c Linux-2.6.12-rc2 |
24 25 |
* */ |
1da177e4c Linux-2.6.12-rc2 |
26 27 |
#include <linux/kernel.h> #include <linux/module.h> |
5a0e3ad6a include cleanup: ... |
28 |
#include <linux/gfp.h> |
1da177e4c Linux-2.6.12-rc2 |
29 |
#include <linux/pci.h> |
1da177e4c Linux-2.6.12-rc2 |
30 31 32 |
#include <linux/blkdev.h> #include <linux/delay.h> #include <linux/interrupt.h> |
a9524a76f [libata] use dev_... |
33 |
#include <linux/device.h> |
1da177e4c Linux-2.6.12-rc2 |
34 35 36 37 |
#include <scsi/scsi_host.h> #include <linux/libata.h> #define DRV_NAME "sata_uli" |
2a3103ce4 [libata] Bump dri... |
38 |
#define DRV_VERSION "1.3" |
1da177e4c Linux-2.6.12-rc2 |
39 40 41 42 43 |
enum { uli_5289 = 0, uli_5287 = 1, uli_5281 = 2, |
50106c5a0 [libata sata_uli]... |
44 |
uli_max_ports = 4, |
1da177e4c Linux-2.6.12-rc2 |
45 46 47 48 49 50 |
/* PCI configuration registers */ ULI5287_BASE = 0x90, /* sata0 phy SCR registers */ ULI5287_OFFS = 0x10, /* offset from sata0->sata1 phy regs */ ULI5281_BASE = 0x60, /* sata0 phy SCR registers */ ULI5281_OFFS = 0x60, /* offset from sata0->sata1 phy regs */ }; |
50106c5a0 [libata sata_uli]... |
51 52 53 |
struct uli_priv { unsigned int scr_cfg_addr[uli_max_ports]; }; |
5796d1c4c [libata] Address ... |
54 |
static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
82ef04fb4 libata: make SCR ... |
55 56 |
static int uli_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val); static int uli_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val); |
1da177e4c Linux-2.6.12-rc2 |
57 |
|
3b7d697df [libata] constify... |
58 |
static const struct pci_device_id uli_pci_tbl[] = { |
54bb3a94b [libata] Use new ... |
59 60 61 |
{ PCI_VDEVICE(AL, 0x5289), uli_5289 }, { PCI_VDEVICE(AL, 0x5287), uli_5287 }, { PCI_VDEVICE(AL, 0x5281), uli_5281 }, |
1da177e4c Linux-2.6.12-rc2 |
62 63 |
{ } /* terminate list */ }; |
1da177e4c Linux-2.6.12-rc2 |
64 65 66 67 68 69 |
static struct pci_driver uli_pci_driver = { .name = DRV_NAME, .id_table = uli_pci_tbl, .probe = uli_init_one, .remove = ata_pci_remove_one, }; |
193515d51 [libata] eliminat... |
70 |
static struct scsi_host_template uli_sht = { |
68d1d07b5 libata: implement... |
71 |
ATA_BMDMA_SHT(DRV_NAME), |
1da177e4c Linux-2.6.12-rc2 |
72 |
}; |
029cfd6b7 libata: implement... |
73 74 |
static struct ata_port_operations uli_ops = { .inherits = &ata_bmdma_port_ops, |
1da177e4c Linux-2.6.12-rc2 |
75 76 |
.scr_read = uli_scr_read, .scr_write = uli_scr_write, |
70a3143af sata_uli: hardres... |
77 |
.hardreset = ATA_OP_NULL, |
1da177e4c Linux-2.6.12-rc2 |
78 |
}; |
1626aeb88 libata: clean up ... |
79 |
static const struct ata_port_info uli_port_info = { |
9cbe056f6 libata: remove AT... |
80 |
.flags = ATA_FLAG_SATA | ATA_FLAG_IGN_SIMPLEX, |
14bdef982 [libata] convert ... |
81 |
.pio_mask = ATA_PIO4, |
bf6263a85 [libata] Use ATA_... |
82 |
.udma_mask = ATA_UDMA6, |
1da177e4c Linux-2.6.12-rc2 |
83 84 85 86 87 88 89 90 91 92 93 94 |
.port_ops = &uli_ops, }; MODULE_AUTHOR("Peer Chen"); MODULE_DESCRIPTION("low-level driver for ULi Electronics SATA controller"); MODULE_LICENSE("GPL"); MODULE_DEVICE_TABLE(pci, uli_pci_tbl); MODULE_VERSION(DRV_VERSION); static unsigned int get_scr_cfg_addr(struct ata_port *ap, unsigned int sc_reg) { |
cca3974e4 libata: Grand ren... |
95 |
struct uli_priv *hpriv = ap->host->private_data; |
50106c5a0 [libata sata_uli]... |
96 |
return hpriv->scr_cfg_addr[ap->port_no] + (4 * sc_reg); |
1da177e4c Linux-2.6.12-rc2 |
97 |
} |
82ef04fb4 libata: make SCR ... |
98 |
static u32 uli_scr_cfg_read(struct ata_link *link, unsigned int sc_reg) |
1da177e4c Linux-2.6.12-rc2 |
99 |
{ |
82ef04fb4 libata: make SCR ... |
100 101 |
struct pci_dev *pdev = to_pci_dev(link->ap->host->dev); unsigned int cfg_addr = get_scr_cfg_addr(link->ap, sc_reg); |
1da177e4c Linux-2.6.12-rc2 |
102 103 104 105 106 |
u32 val; pci_read_config_dword(pdev, cfg_addr, &val); return val; } |
82ef04fb4 libata: make SCR ... |
107 |
static void uli_scr_cfg_write(struct ata_link *link, unsigned int scr, u32 val) |
1da177e4c Linux-2.6.12-rc2 |
108 |
{ |
82ef04fb4 libata: make SCR ... |
109 110 |
struct pci_dev *pdev = to_pci_dev(link->ap->host->dev); unsigned int cfg_addr = get_scr_cfg_addr(link->ap, scr); |
1da177e4c Linux-2.6.12-rc2 |
111 112 113 |
pci_write_config_dword(pdev, cfg_addr, val); } |
82ef04fb4 libata: make SCR ... |
114 |
static int uli_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val) |
1da177e4c Linux-2.6.12-rc2 |
115 116 |
{ if (sc_reg > SCR_CONTROL) |
da3dbb17a libata: make ->sc... |
117 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
118 |
|
82ef04fb4 libata: make SCR ... |
119 |
*val = uli_scr_cfg_read(link, sc_reg); |
da3dbb17a libata: make ->sc... |
120 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
121 |
} |
82ef04fb4 libata: make SCR ... |
122 |
static int uli_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val) |
1da177e4c Linux-2.6.12-rc2 |
123 |
{ |
5796d1c4c [libata] Address ... |
124 |
if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0 |
da3dbb17a libata: make ->sc... |
125 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
126 |
|
82ef04fb4 libata: make SCR ... |
127 |
uli_scr_cfg_write(link, sc_reg, val); |
da3dbb17a libata: make ->sc... |
128 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
129 |
} |
5796d1c4c [libata] Address ... |
130 |
static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
1da177e4c Linux-2.6.12-rc2 |
131 |
{ |
9a829ccfc libata: convert a... |
132 |
const struct ata_port_info *ppi[] = { &uli_port_info, NULL }; |
1da177e4c Linux-2.6.12-rc2 |
133 |
unsigned int board_idx = (unsigned int) ent->driver_data; |
9a829ccfc libata: convert a... |
134 |
struct ata_host *host; |
50106c5a0 [libata sata_uli]... |
135 |
struct uli_priv *hpriv; |
0d5ff5667 libata: convert t... |
136 |
void __iomem * const *iomap; |
9a829ccfc libata: convert a... |
137 138 |
struct ata_ioports *ioaddr; int n_ports, rc; |
1da177e4c Linux-2.6.12-rc2 |
139 |
|
06296a1e6 ata: Add and use ... |
140 |
ata_print_version_once(&pdev->dev, DRV_VERSION); |
a9524a76f [libata] use dev_... |
141 |
|
24dc5f33e libata: update li... |
142 |
rc = pcim_enable_device(pdev); |
1da177e4c Linux-2.6.12-rc2 |
143 144 |
if (rc) return rc; |
9a829ccfc libata: convert a... |
145 146 147 |
n_ports = 2; if (board_idx == uli_5287) n_ports = 4; |
1626aeb88 libata: clean up ... |
148 149 150 151 152 |
/* allocate the host */ host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); if (!host) return -ENOMEM; |
1da177e4c Linux-2.6.12-rc2 |
153 |
|
24dc5f33e libata: update li... |
154 155 156 |
hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); if (!hpriv) return -ENOMEM; |
9a829ccfc libata: convert a... |
157 |
host->private_data = hpriv; |
50106c5a0 [libata sata_uli]... |
158 |
|
1626aeb88 libata: clean up ... |
159 |
/* the first two ports are standard SFF */ |
9363c3825 libata: rename SF... |
160 |
rc = ata_pci_sff_init_host(host); |
1626aeb88 libata: clean up ... |
161 162 |
if (rc) return rc; |
c7087652e libata-sff: clean... |
163 |
ata_pci_bmdma_init(host); |
1626aeb88 libata: clean up ... |
164 |
|
9a829ccfc libata: convert a... |
165 |
iomap = host->iomap; |
0d5ff5667 libata: convert t... |
166 |
|
1da177e4c Linux-2.6.12-rc2 |
167 168 |
switch (board_idx) { case uli_5287: |
1626aeb88 libata: clean up ... |
169 170 171 |
/* If there are four, the last two live right after * the standard SFF ports. */ |
50106c5a0 [libata sata_uli]... |
172 173 |
hpriv->scr_cfg_addr[0] = ULI5287_BASE; hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS; |
1da177e4c Linux-2.6.12-rc2 |
174 |
|
9a829ccfc libata: convert a... |
175 176 177 178 |
ioaddr = &host->ports[2]->ioaddr; ioaddr->cmd_addr = iomap[0] + 8; ioaddr->altstatus_addr = ioaddr->ctl_addr = (void __iomem *) |
0d5ff5667 libata: convert t... |
179 |
((unsigned long)iomap[1] | ATA_PCI_CTL_OFS) + 4; |
9a829ccfc libata: convert a... |
180 |
ioaddr->bmdma_addr = iomap[4] + 16; |
50106c5a0 [libata sata_uli]... |
181 |
hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4; |
9363c3825 libata: rename SF... |
182 |
ata_sff_std_ports(ioaddr); |
1da177e4c Linux-2.6.12-rc2 |
183 |
|
cbcdd8759 libata: implement... |
184 185 186 187 188 |
ata_port_desc(host->ports[2], "cmd 0x%llx ctl 0x%llx bmdma 0x%llx", (unsigned long long)pci_resource_start(pdev, 0) + 8, ((unsigned long long)pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS) + 4, (unsigned long long)pci_resource_start(pdev, 4) + 16); |
9a829ccfc libata: convert a... |
189 190 191 192 |
ioaddr = &host->ports[3]->ioaddr; ioaddr->cmd_addr = iomap[2] + 8; ioaddr->altstatus_addr = ioaddr->ctl_addr = (void __iomem *) |
0d5ff5667 libata: convert t... |
193 |
((unsigned long)iomap[3] | ATA_PCI_CTL_OFS) + 4; |
9a829ccfc libata: convert a... |
194 |
ioaddr->bmdma_addr = iomap[4] + 24; |
50106c5a0 [libata sata_uli]... |
195 |
hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5; |
9363c3825 libata: rename SF... |
196 |
ata_sff_std_ports(ioaddr); |
cbcdd8759 libata: implement... |
197 198 199 200 201 202 |
ata_port_desc(host->ports[2], "cmd 0x%llx ctl 0x%llx bmdma 0x%llx", (unsigned long long)pci_resource_start(pdev, 2) + 9, ((unsigned long long)pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS) + 4, (unsigned long long)pci_resource_start(pdev, 4) + 24); |
1da177e4c Linux-2.6.12-rc2 |
203 204 205 |
break; case uli_5289: |
50106c5a0 [libata sata_uli]... |
206 207 |
hpriv->scr_cfg_addr[0] = ULI5287_BASE; hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS; |
1da177e4c Linux-2.6.12-rc2 |
208 209 210 |
break; case uli_5281: |
50106c5a0 [libata sata_uli]... |
211 212 |
hpriv->scr_cfg_addr[0] = ULI5281_BASE; hpriv->scr_cfg_addr[1] = ULI5281_BASE + ULI5281_OFFS; |
1da177e4c Linux-2.6.12-rc2 |
213 214 215 216 217 218 219 220 |
break; default: BUG(); break; } pci_set_master(pdev); |
a04ce0ffc [PATCH] PCI/libat... |
221 |
pci_intx(pdev, 1); |
c3b288942 libata-sff: separ... |
222 |
return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt, |
9363c3825 libata: rename SF... |
223 |
IRQF_SHARED, &uli_sht); |
1da177e4c Linux-2.6.12-rc2 |
224 |
} |
2fc75da0c ata: use module_p... |
225 |
module_pci_driver(uli_pci_driver); |