Blame view

drivers/ata/sata_uli.c 6.85 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /*
   *  sata_uli.c - ULi Electronics SATA
   *
af36d7f0d   Jeff Garzik   [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   Linus Torvalds   Linux-2.6.12-rc2
24
25
   *
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
27
  #include <linux/kernel.h>
  #include <linux/module.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
28
  #include <linux/gfp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
  #include <linux/pci.h>
  #include <linux/init.h>
  #include <linux/blkdev.h>
  #include <linux/delay.h>
  #include <linux/interrupt.h>
a9524a76f   Jeff Garzik   [libata] use dev_...
34
  #include <linux/device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
38
  #include <scsi/scsi_host.h>
  #include <linux/libata.h>
  
  #define DRV_NAME	"sata_uli"
2a3103ce4   Jeff Garzik   [libata] Bump dri...
39
  #define DRV_VERSION	"1.3"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
  
  enum {
  	uli_5289		= 0,
  	uli_5287		= 1,
  	uli_5281		= 2,
50106c5a0   Jeff Garzik   [libata sata_uli]...
45
  	uli_max_ports		= 4,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
50
51
  	/* 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   Jeff Garzik   [libata sata_uli]...
52
53
54
  struct uli_priv {
  	unsigned int		scr_cfg_addr[uli_max_ports];
  };
5796d1c4c   Jeff Garzik   [libata] Address ...
55
  static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
82ef04fb4   Tejun Heo   libata: make SCR ...
56
57
  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   Linus Torvalds   Linux-2.6.12-rc2
58

3b7d697df   Jeff Garzik   [libata] constify...
59
  static const struct pci_device_id uli_pci_tbl[] = {
54bb3a94b   Jeff Garzik   [libata] Use new ...
60
61
62
  	{ PCI_VDEVICE(AL, 0x5289), uli_5289 },
  	{ PCI_VDEVICE(AL, 0x5287), uli_5287 },
  	{ PCI_VDEVICE(AL, 0x5281), uli_5281 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
  	{ }	/* terminate list */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
67
68
69
70
  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   Jeff Garzik   [libata] eliminat...
71
  static struct scsi_host_template uli_sht = {
68d1d07b5   Tejun Heo   libata: implement...
72
  	ATA_BMDMA_SHT(DRV_NAME),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  };
029cfd6b7   Tejun Heo   libata: implement...
74
75
  static struct ata_port_operations uli_ops = {
  	.inherits		= &ata_bmdma_port_ops,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
77
  	.scr_read		= uli_scr_read,
  	.scr_write		= uli_scr_write,
70a3143af   Tejun Heo   sata_uli: hardres...
78
  	.hardreset		= ATA_OP_NULL,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  };
1626aeb88   Tejun Heo   libata: clean up ...
80
  static const struct ata_port_info uli_port_info = {
b2a8bbe67   Tejun Heo   libata: implement...
81
82
  	.flags		= ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  			  ATA_FLAG_IGN_SIMPLEX,
14bdef982   Erik Inge Bolsø   [libata] convert ...
83
  	.pio_mask       = ATA_PIO4,
bf6263a85   Jeff Garzik   [libata] Use ATA_...
84
  	.udma_mask      = ATA_UDMA6,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
88
89
90
91
92
93
94
95
96
  	.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   Jeff Garzik   libata: Grand ren...
97
  	struct uli_priv *hpriv = ap->host->private_data;
50106c5a0   Jeff Garzik   [libata sata_uli]...
98
  	return hpriv->scr_cfg_addr[ap->port_no] + (4 * sc_reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
  }
82ef04fb4   Tejun Heo   libata: make SCR ...
100
  static u32 uli_scr_cfg_read(struct ata_link *link, unsigned int sc_reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
  {
82ef04fb4   Tejun Heo   libata: make SCR ...
102
103
  	struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  	unsigned int cfg_addr = get_scr_cfg_addr(link->ap, sc_reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
108
  	u32 val;
  
  	pci_read_config_dword(pdev, cfg_addr, &val);
  	return val;
  }
82ef04fb4   Tejun Heo   libata: make SCR ...
109
  static void uli_scr_cfg_write(struct ata_link *link, unsigned int scr, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  {
82ef04fb4   Tejun Heo   libata: make SCR ...
111
112
  	struct pci_dev *pdev = to_pci_dev(link->ap->host->dev);
  	unsigned int cfg_addr = get_scr_cfg_addr(link->ap, scr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
115
  
  	pci_write_config_dword(pdev, cfg_addr, val);
  }
82ef04fb4   Tejun Heo   libata: make SCR ...
116
  static int uli_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
  {
  	if (sc_reg > SCR_CONTROL)
da3dbb17a   Tejun Heo   libata: make ->sc...
119
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120

82ef04fb4   Tejun Heo   libata: make SCR ...
121
  	*val = uli_scr_cfg_read(link, sc_reg);
da3dbb17a   Tejun Heo   libata: make ->sc...
122
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  }
82ef04fb4   Tejun Heo   libata: make SCR ...
124
  static int uli_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
  {
5796d1c4c   Jeff Garzik   [libata] Address ...
126
  	if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0
da3dbb17a   Tejun Heo   libata: make ->sc...
127
  		return -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128

82ef04fb4   Tejun Heo   libata: make SCR ...
129
  	uli_scr_cfg_write(link, sc_reg, val);
da3dbb17a   Tejun Heo   libata: make ->sc...
130
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  }
5796d1c4c   Jeff Garzik   [libata] Address ...
132
  static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
  {
a9524a76f   Jeff Garzik   [libata] use dev_...
134
  	static int printed_version;
9a829ccfc   Tejun Heo   libata: convert a...
135
  	const struct ata_port_info *ppi[] = { &uli_port_info, NULL };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  	unsigned int board_idx = (unsigned int) ent->driver_data;
9a829ccfc   Tejun Heo   libata: convert a...
137
  	struct ata_host *host;
50106c5a0   Jeff Garzik   [libata sata_uli]...
138
  	struct uli_priv *hpriv;
0d5ff5667   Tejun Heo   libata: convert t...
139
  	void __iomem * const *iomap;
9a829ccfc   Tejun Heo   libata: convert a...
140
141
  	struct ata_ioports *ioaddr;
  	int n_ports, rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142

a9524a76f   Jeff Garzik   [libata] use dev_...
143
144
145
  	if (!printed_version++)
  		dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "
  ");
24dc5f33e   Tejun Heo   libata: update li...
146
  	rc = pcim_enable_device(pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
148
  	if (rc)
  		return rc;
9a829ccfc   Tejun Heo   libata: convert a...
149
150
151
  	n_ports = 2;
  	if (board_idx == uli_5287)
  		n_ports = 4;
1626aeb88   Tejun Heo   libata: clean up ...
152
153
154
155
156
  
  	/* allocate the host */
  	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  	if (!host)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157

24dc5f33e   Tejun Heo   libata: update li...
158
159
160
  	hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
  	if (!hpriv)
  		return -ENOMEM;
9a829ccfc   Tejun Heo   libata: convert a...
161
  	host->private_data = hpriv;
50106c5a0   Jeff Garzik   [libata sata_uli]...
162

1626aeb88   Tejun Heo   libata: clean up ...
163
  	/* the first two ports are standard SFF */
9363c3825   Tejun Heo   libata: rename SF...
164
  	rc = ata_pci_sff_init_host(host);
1626aeb88   Tejun Heo   libata: clean up ...
165
166
  	if (rc)
  		return rc;
c7087652e   Tejun Heo   libata-sff: clean...
167
  	ata_pci_bmdma_init(host);
1626aeb88   Tejun Heo   libata: clean up ...
168

9a829ccfc   Tejun Heo   libata: convert a...
169
  	iomap = host->iomap;
0d5ff5667   Tejun Heo   libata: convert t...
170

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
  	switch (board_idx) {
  	case uli_5287:
1626aeb88   Tejun Heo   libata: clean up ...
173
174
175
  		/* If there are four, the last two live right after
  		 * the standard SFF ports.
  		 */
50106c5a0   Jeff Garzik   [libata sata_uli]...
176
177
  		hpriv->scr_cfg_addr[0] = ULI5287_BASE;
  		hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178

9a829ccfc   Tejun Heo   libata: convert a...
179
180
181
182
  		ioaddr = &host->ports[2]->ioaddr;
  		ioaddr->cmd_addr = iomap[0] + 8;
  		ioaddr->altstatus_addr =
  		ioaddr->ctl_addr = (void __iomem *)
0d5ff5667   Tejun Heo   libata: convert t...
183
  			((unsigned long)iomap[1] | ATA_PCI_CTL_OFS) + 4;
9a829ccfc   Tejun Heo   libata: convert a...
184
  		ioaddr->bmdma_addr = iomap[4] + 16;
50106c5a0   Jeff Garzik   [libata sata_uli]...
185
  		hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4;
9363c3825   Tejun Heo   libata: rename SF...
186
  		ata_sff_std_ports(ioaddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187

cbcdd8759   Tejun Heo   libata: implement...
188
189
190
191
192
  		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   Tejun Heo   libata: convert a...
193
194
195
196
  		ioaddr = &host->ports[3]->ioaddr;
  		ioaddr->cmd_addr = iomap[2] + 8;
  		ioaddr->altstatus_addr =
  		ioaddr->ctl_addr = (void __iomem *)
0d5ff5667   Tejun Heo   libata: convert t...
197
  			((unsigned long)iomap[3] | ATA_PCI_CTL_OFS) + 4;
9a829ccfc   Tejun Heo   libata: convert a...
198
  		ioaddr->bmdma_addr = iomap[4] + 24;
50106c5a0   Jeff Garzik   [libata sata_uli]...
199
  		hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5;
9363c3825   Tejun Heo   libata: rename SF...
200
  		ata_sff_std_ports(ioaddr);
cbcdd8759   Tejun Heo   libata: implement...
201
202
203
204
205
206
  
  		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   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
  		break;
  
  	case uli_5289:
50106c5a0   Jeff Garzik   [libata sata_uli]...
210
211
  		hpriv->scr_cfg_addr[0] = ULI5287_BASE;
  		hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
213
214
  		break;
  
  	case uli_5281:
50106c5a0   Jeff Garzik   [libata sata_uli]...
215
216
  		hpriv->scr_cfg_addr[0] = ULI5281_BASE;
  		hpriv->scr_cfg_addr[1] = ULI5281_BASE + ULI5281_OFFS;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
219
220
221
222
223
224
  		break;
  
  	default:
  		BUG();
  		break;
  	}
  
  	pci_set_master(pdev);
a04ce0ffc   Brett M Russ   [PATCH] PCI/libat...
225
  	pci_intx(pdev, 1);
c3b288942   Tejun Heo   libata-sff: separ...
226
  	return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
9363c3825   Tejun Heo   libata: rename SF...
227
  				 IRQF_SHARED, &uli_sht);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
229
230
231
  }
  
  static int __init uli_init(void)
  {
b7887196e   Pavel Roskin   [PATCH] libata: r...
232
  	return pci_register_driver(&uli_pci_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
237
238
239
240
241
242
  }
  
  static void __exit uli_exit(void)
  {
  	pci_unregister_driver(&uli_pci_driver);
  }
  
  
  module_init(uli_init);
  module_exit(uli_exit);