aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/pci-quirks.c
diff options
context:
space:
mode:
authorAndiry Xu <andiry.xu@amd.com>2011-03-01 01:57:05 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-03-01 16:01:45 -0500
commitad93562bdeecdded7d02eaaaf1aa5705ab57b1b7 (patch)
tree92bd220ce673a8260fb4cb4799024529af664208 /drivers/usb/host/pci-quirks.c
parent53689ac1b677532be666a779e24b0ac9bd266354 (diff)
USB host: Move AMD PLL quirk to pci-quirks.c
This patch moves the AMD PLL quirk code in OHCI/EHCI driver to pci-quirks.c, and exports the functions to be used by xHCI driver later. AMD PLL quirk disable the optional PM feature inside specific SB700/SB800/Hudson-2/3 platforms under the following conditions: 1. If an isochronous device is connected to OHCI/EHCI/xHCI port and is active; 2. Optional PM feature that powers down the internal Bus PLL when the link is in low power state is enabled. Without AMD PLL quirk, USB isochronous stream may stutter or have breaks occasionally, which greatly impair the performance of audio/video streams. Currently AMD PLL quirk is implemented in OHCI and EHCI driver, and will be added to xHCI driver too. They are doing similar things actually, so move the quirk code to pci-quirks.c, which has several advantages: 1. Remove duplicate defines and functions in OHCI/EHCI (and xHCI) driver and make them cleaner; 2. AMD chipset information will be probed only once and then stored. Currently they're probed during every OHCI/EHCI initialization, move the detect code to pci-quirks.c saves the repeat detect cost; 3. Build up synchronization among OHCI/EHCI/xHCI driver. In current code, every host controller enable/disable PLL only according to its own status, and may enable PLL while there is still isoc transfer on other HCs. Move the quirk to pci-quirks.c prevents this issue. Signed-off-by: Andiry Xu <andiry.xu@amd.com> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Alex He <alex.he@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/pci-quirks.c')
-rw-r--r--drivers/usb/host/pci-quirks.c258
1 files changed, 258 insertions, 0 deletions
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 4c502c890ebd..1d586d4f7b56 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -52,6 +52,264 @@
52#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ 52#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
53#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */ 53#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
54 54
55/* AMD quirk use */
56#define AB_REG_BAR_LOW 0xe0
57#define AB_REG_BAR_HIGH 0xe1
58#define AB_REG_BAR_SB700 0xf0
59#define AB_INDX(addr) ((addr) + 0x00)
60#define AB_DATA(addr) ((addr) + 0x04)
61#define AX_INDXC 0x30
62#define AX_DATAC 0x34
63
64#define NB_PCIE_INDX_ADDR 0xe0
65#define NB_PCIE_INDX_DATA 0xe4
66#define PCIE_P_CNTL 0x10040
67#define BIF_NB 0x10002
68#define NB_PIF0_PWRDOWN_0 0x01100012
69#define NB_PIF0_PWRDOWN_1 0x01100013
70
71static struct amd_chipset_info {
72 struct pci_dev *nb_dev;
73 struct pci_dev *smbus_dev;
74 int nb_type;
75 int sb_type;
76 int isoc_reqs;
77 int probe_count;
78 int probe_result;
79} amd_chipset;
80
81static DEFINE_SPINLOCK(amd_lock);
82
83int usb_amd_find_chipset_info(void)
84{
85 u8 rev = 0;
86 unsigned long flags;
87
88 spin_lock_irqsave(&amd_lock, flags);
89
90 amd_chipset.probe_count++;
91 /* probe only once */
92 if (amd_chipset.probe_count > 1) {
93 spin_unlock_irqrestore(&amd_lock, flags);
94 return amd_chipset.probe_result;
95 }
96
97 amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
98 if (amd_chipset.smbus_dev) {
99 rev = amd_chipset.smbus_dev->revision;
100 if (rev >= 0x40)
101 amd_chipset.sb_type = 1;
102 else if (rev >= 0x30 && rev <= 0x3b)
103 amd_chipset.sb_type = 3;
104 } else {
105 amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
106 0x780b, NULL);
107 if (!amd_chipset.smbus_dev) {
108 spin_unlock_irqrestore(&amd_lock, flags);
109 return 0;
110 }
111 rev = amd_chipset.smbus_dev->revision;
112 if (rev >= 0x11 && rev <= 0x18)
113 amd_chipset.sb_type = 2;
114 }
115
116 if (amd_chipset.sb_type == 0) {
117 if (amd_chipset.smbus_dev) {
118 pci_dev_put(amd_chipset.smbus_dev);
119 amd_chipset.smbus_dev = NULL;
120 }
121 spin_unlock_irqrestore(&amd_lock, flags);
122 return 0;
123 }
124
125 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
126 if (amd_chipset.nb_dev) {
127 amd_chipset.nb_type = 1;
128 } else {
129 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
130 0x1510, NULL);
131 if (amd_chipset.nb_dev) {
132 amd_chipset.nb_type = 2;
133 } else {
134 amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
135 0x9600, NULL);
136 if (amd_chipset.nb_dev)
137 amd_chipset.nb_type = 3;
138 }
139 }
140
141 amd_chipset.probe_result = 1;
142 printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
143
144 spin_unlock_irqrestore(&amd_lock, flags);
145 return amd_chipset.probe_result;
146}
147EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
148
149/*
150 * The hardware normally enables the A-link power management feature, which
151 * lets the system lower the power consumption in idle states.
152 *
153 * This USB quirk prevents the link going into that lower power state
154 * during isochronous transfers.
155 *
156 * Without this quirk, isochronous stream on OHCI/EHCI/xHCI controllers of
157 * some AMD platforms may stutter or have breaks occasionally.
158 */
159static void usb_amd_quirk_pll(int disable)
160{
161 u32 addr, addr_low, addr_high, val;
162 u32 bit = disable ? 0 : 1;
163 unsigned long flags;
164
165 spin_lock_irqsave(&amd_lock, flags);
166
167 if (disable) {
168 amd_chipset.isoc_reqs++;
169 if (amd_chipset.isoc_reqs > 1) {
170 spin_unlock_irqrestore(&amd_lock, flags);
171 return;
172 }
173 } else {
174 amd_chipset.isoc_reqs--;
175 if (amd_chipset.isoc_reqs > 0) {
176 spin_unlock_irqrestore(&amd_lock, flags);
177 return;
178 }
179 }
180
181 if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) {
182 outb_p(AB_REG_BAR_LOW, 0xcd6);
183 addr_low = inb_p(0xcd7);
184 outb_p(AB_REG_BAR_HIGH, 0xcd6);
185 addr_high = inb_p(0xcd7);
186 addr = addr_high << 8 | addr_low;
187
188 outl_p(0x30, AB_INDX(addr));
189 outl_p(0x40, AB_DATA(addr));
190 outl_p(0x34, AB_INDX(addr));
191 val = inl_p(AB_DATA(addr));
192 } else if (amd_chipset.sb_type == 3) {
193 pci_read_config_dword(amd_chipset.smbus_dev,
194 AB_REG_BAR_SB700, &addr);
195 outl(AX_INDXC, AB_INDX(addr));
196 outl(0x40, AB_DATA(addr));
197 outl(AX_DATAC, AB_INDX(addr));
198 val = inl(AB_DATA(addr));
199 } else {
200 spin_unlock_irqrestore(&amd_lock, flags);
201 return;
202 }
203
204 if (disable) {
205 val &= ~0x08;
206 val |= (1 << 4) | (1 << 9);
207 } else {
208 val |= 0x08;
209 val &= ~((1 << 4) | (1 << 9));
210 }
211 outl_p(val, AB_DATA(addr));
212
213 if (!amd_chipset.nb_dev) {
214 spin_unlock_irqrestore(&amd_lock, flags);
215 return;
216 }
217
218 if (amd_chipset.nb_type == 1 || amd_chipset.nb_type == 3) {
219 addr = PCIE_P_CNTL;
220 pci_write_config_dword(amd_chipset.nb_dev,
221 NB_PCIE_INDX_ADDR, addr);
222 pci_read_config_dword(amd_chipset.nb_dev,
223 NB_PCIE_INDX_DATA, &val);
224
225 val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12));
226 val |= bit | (bit << 3) | (bit << 12);
227 val |= ((!bit) << 4) | ((!bit) << 9);
228 pci_write_config_dword(amd_chipset.nb_dev,
229 NB_PCIE_INDX_DATA, val);
230
231 addr = BIF_NB;
232 pci_write_config_dword(amd_chipset.nb_dev,
233 NB_PCIE_INDX_ADDR, addr);
234 pci_read_config_dword(amd_chipset.nb_dev,
235 NB_PCIE_INDX_DATA, &val);
236 val &= ~(1 << 8);
237 val |= bit << 8;
238
239 pci_write_config_dword(amd_chipset.nb_dev,
240 NB_PCIE_INDX_DATA, val);
241 } else if (amd_chipset.nb_type == 2) {
242 addr = NB_PIF0_PWRDOWN_0;
243 pci_write_config_dword(amd_chipset.nb_dev,
244 NB_PCIE_INDX_ADDR, addr);
245 pci_read_config_dword(amd_chipset.nb_dev,
246 NB_PCIE_INDX_DATA, &val);
247 if (disable)
248 val &= ~(0x3f << 7);
249 else
250 val |= 0x3f << 7;
251
252 pci_write_config_dword(amd_chipset.nb_dev,
253 NB_PCIE_INDX_DATA, val);
254
255 addr = NB_PIF0_PWRDOWN_1;
256 pci_write_config_dword(amd_chipset.nb_dev,
257 NB_PCIE_INDX_ADDR, addr);
258 pci_read_config_dword(amd_chipset.nb_dev,
259 NB_PCIE_INDX_DATA, &val);
260 if (disable)
261 val &= ~(0x3f << 7);
262 else
263 val |= 0x3f << 7;
264
265 pci_write_config_dword(amd_chipset.nb_dev,
266 NB_PCIE_INDX_DATA, val);
267 }
268
269 spin_unlock_irqrestore(&amd_lock, flags);
270 return;
271}
272
273void usb_amd_quirk_pll_disable(void)
274{
275 usb_amd_quirk_pll(1);
276}
277EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_disable);
278
279void usb_amd_quirk_pll_enable(void)
280{
281 usb_amd_quirk_pll(0);
282}
283EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable);
284
285void usb_amd_dev_put(void)
286{
287 unsigned long flags;
288
289 spin_lock_irqsave(&amd_lock, flags);
290
291 amd_chipset.probe_count--;
292 if (amd_chipset.probe_count > 0) {
293 spin_unlock_irqrestore(&amd_lock, flags);
294 return;
295 }
296
297 if (amd_chipset.nb_dev) {
298 pci_dev_put(amd_chipset.nb_dev);
299 amd_chipset.nb_dev = NULL;
300 }
301 if (amd_chipset.smbus_dev) {
302 pci_dev_put(amd_chipset.smbus_dev);
303 amd_chipset.smbus_dev = NULL;
304 }
305 amd_chipset.nb_type = 0;
306 amd_chipset.sb_type = 0;
307 amd_chipset.isoc_reqs = 0;
308 amd_chipset.probe_result = 0;
309
310 spin_unlock_irqrestore(&amd_lock, flags);
311}
312EXPORT_SYMBOL_GPL(usb_amd_dev_put);
55 313
56/* 314/*
57 * Make sure the controller is completely inactive, unable to 315 * Make sure the controller is completely inactive, unable to