1
2
3
4
5
6
7
8
9
10
11
12#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/pci.h>
15#include <linux/interrupt.h>
16#include <linux/mc146818rtc.h>
17
18#include <asm/pci-bridge.h>
19
20#define ULI_PIRQA 0x08
21#define ULI_PIRQB 0x09
22#define ULI_PIRQC 0x0a
23#define ULI_PIRQD 0x0b
24#define ULI_PIRQE 0x0c
25#define ULI_PIRQF 0x0d
26#define ULI_PIRQG 0x0e
27
28#define ULI_8259_NONE 0x00
29#define ULI_8259_IRQ1 0x08
30#define ULI_8259_IRQ3 0x02
31#define ULI_8259_IRQ4 0x04
32#define ULI_8259_IRQ5 0x05
33#define ULI_8259_IRQ6 0x07
34#define ULI_8259_IRQ7 0x06
35#define ULI_8259_IRQ9 0x01
36#define ULI_8259_IRQ10 0x03
37#define ULI_8259_IRQ11 0x09
38#define ULI_8259_IRQ12 0x0b
39#define ULI_8259_IRQ14 0x0d
40#define ULI_8259_IRQ15 0x0f
41
42u8 uli_pirq_to_irq[8] = {
43 ULI_8259_IRQ9,
44 ULI_8259_IRQ10,
45 ULI_8259_IRQ11,
46 ULI_8259_IRQ12,
47 ULI_8259_IRQ5,
48 ULI_8259_IRQ6,
49 ULI_8259_IRQ7,
50 ULI_8259_NONE,
51};
52
53static inline bool is_quirk_valid(void)
54{
55 return (machine_is(mpc86xx_hpcn) ||
56 machine_is(mpc8544_ds) ||
57 machine_is(p2020_ds) ||
58 machine_is(mpc8572_ds));
59}
60
61
62static void early_uli5249(struct pci_dev *dev)
63{
64 unsigned char temp;
65
66 if (!is_quirk_valid())
67 return;
68
69 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO |
70 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
71
72
73 pci_read_config_byte(dev, 0x7c, &temp);
74 pci_write_config_byte(dev, 0x7c, 0x80);
75
76
77 pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
78 dev->class |= 0x1;
79
80
81 pci_write_config_byte(dev, 0x7c, temp);
82}
83
84
85static void quirk_uli1575(struct pci_dev *dev)
86{
87 int i;
88
89 if (!is_quirk_valid())
90 return;
91
92
93
94
95
96
97 for (i = 0; i < 4; i++) {
98 u8 val = uli_pirq_to_irq[i*2] | (uli_pirq_to_irq[i*2+1] << 4);
99 pci_write_config_byte(dev, 0x48 + i, val);
100 }
101
102
103 pci_write_config_byte(dev, 0x86, ULI_PIRQD);
104
105
106 pci_write_config_byte(dev, 0x87, ULI_PIRQA);
107
108
109 pci_write_config_byte(dev, 0x88, ULI_PIRQB);
110
111
112 pci_write_config_byte(dev, 0x89, ULI_PIRQF);
113
114
115 pci_write_config_byte(dev, 0x8a, ULI_PIRQF);
116
117
118 pci_write_config_byte(dev, 0x8b, ULI_PIRQF);
119
120
121 pci_write_config_byte(dev, 0x8c, ULI_PIRQF);
122
123
124 pci_write_config_byte(dev, 0x8d, ULI_PIRQE);
125
126
127 pci_write_config_byte(dev, 0x8e, ULI_PIRQG);
128
129
130 pci_write_config_byte(dev, 0x8f, ULI_PIRQG);
131
132
133 pci_write_config_byte(dev, 0x74, ULI_8259_IRQ11);
134
135
136
137
138 pci_write_config_byte(dev, 0x44, 0x30 | ULI_8259_IRQ14);
139 pci_write_config_byte(dev, 0x75, ULI_8259_IRQ15);
140}
141
142static void quirk_final_uli1575(struct pci_dev *dev)
143{
144
145
146
147
148
149
150
151
152
153
154
155
156
157 if (!is_quirk_valid())
158 return;
159
160 outb(0xfa, 0x4d0);
161 outb(0x1e, 0x4d1);
162
163
164 CMOS_WRITE(RTC_SET, RTC_CONTROL);
165 CMOS_WRITE(RTC_24H, RTC_CONTROL);
166
167
168 CMOS_WRITE(0, RTC_VALID);
169
170 outb_p(0x7c, 0x72);
171 outb_p(RTC_ALARM_DONT_CARE, 0x73);
172
173 outb_p(0x7d, 0x72);
174 outb_p(RTC_ALARM_DONT_CARE, 0x73);
175}
176
177
178static void quirk_uli5288(struct pci_dev *dev)
179{
180 unsigned char c;
181 unsigned int d;
182
183 if (!is_quirk_valid())
184 return;
185
186
187 pci_read_config_byte(dev, 0x83, &c);
188 pci_write_config_byte(dev, 0x83, c|0x80);
189
190 pci_read_config_dword(dev, PCI_CLASS_REVISION, &d);
191 d = (d & 0xff) | (PCI_CLASS_STORAGE_SATA_AHCI << 8);
192 pci_write_config_dword(dev, PCI_CLASS_REVISION, d);
193
194
195 pci_write_config_byte(dev, 0x83, c);
196
197
198 pci_read_config_byte(dev, 0x84, &c);
199 pci_write_config_byte(dev, 0x84, c & ~0x01);
200}
201
202
203static void quirk_uli5229(struct pci_dev *dev)
204{
205 unsigned short temp;
206
207 if (!is_quirk_valid())
208 return;
209
210 pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_INTX_DISABLE |
211 PCI_COMMAND_MASTER | PCI_COMMAND_IO);
212
213
214 pci_read_config_word(dev, 0x4a, &temp);
215 pci_write_config_word(dev, 0x4a, temp | 0x1000);
216}
217
218
219static void quirk_final_uli5249(struct pci_dev *dev)
220{
221 int i;
222 u8 *dummy;
223 struct pci_bus *bus = dev->bus;
224 struct resource *res;
225 resource_size_t end = 0;
226
227 for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCES+3; i++) {
228 unsigned long flags = pci_resource_flags(dev, i);
229 if ((flags & (IORESOURCE_MEM|IORESOURCE_PREFETCH)) == IORESOURCE_MEM)
230 end = pci_resource_end(dev, i);
231 }
232
233 pci_bus_for_each_resource(bus, res, i) {
234 if (res && res->flags & IORESOURCE_MEM) {
235 if (res->end == end)
236 dummy = ioremap(res->start, 0x4);
237 else
238 dummy = ioremap(res->end - 3, 0x4);
239 if (dummy) {
240 in_8(dummy);
241 iounmap(dummy);
242 }
243 break;
244 }
245 }
246}
247
248DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);
249DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
250DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
251DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
252DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5249, quirk_final_uli5249);
253DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x1575, quirk_final_uli1575);
254DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
255
256static void hpcd_quirk_uli1575(struct pci_dev *dev)
257{
258 u32 temp32;
259
260 if (!machine_is(mpc86xx_hpcd))
261 return;
262
263
264 pci_read_config_dword(dev, 0x48, &temp32);
265 pci_write_config_dword(dev, 0x48, (temp32 | 1<<26));
266
267
268 pci_read_config_dword(dev, 0x90, &temp32);
269 pci_write_config_dword(dev, 0x90, (temp32 | 1<<22));
270}
271
272static void hpcd_quirk_uli5288(struct pci_dev *dev)
273{
274 unsigned char c;
275
276 if (!machine_is(mpc86xx_hpcd))
277 return;
278
279 pci_read_config_byte(dev, 0x83, &c);
280 c |= 0x80;
281 pci_write_config_byte(dev, 0x83, c);
282
283 pci_write_config_byte(dev, PCI_CLASS_PROG, 0x01);
284 pci_write_config_byte(dev, PCI_CLASS_DEVICE, 0x06);
285
286 pci_read_config_byte(dev, 0x83, &c);
287 c &= 0x7f;
288 pci_write_config_byte(dev, 0x83, c);
289}
290
291
292
293
294
295
296
297
298static void hpcd_quirk_uli5229(struct pci_dev *dev)
299{
300 unsigned char c;
301
302 if (!machine_is(mpc86xx_hpcd))
303 return;
304
305 pci_read_config_byte(dev, 0x4b, &c);
306 c |= 0x10;
307 pci_write_config_byte(dev, 0x4b, c);
308}
309
310
311
312
313
314
315
316
317
318
319
320static void hpcd_final_uli5288(struct pci_dev *dev)
321{
322 struct pci_controller *hose = pci_bus_to_host(dev->bus);
323 struct device_node *hosenode = hose ? hose->dn : NULL;
324 struct of_phandle_args oirq;
325 u32 laddr[3];
326
327 if (!machine_is(mpc86xx_hpcd))
328 return;
329
330 if (!hosenode)
331 return;
332
333 oirq.np = hosenode;
334 oirq.args[0] = 2;
335 oirq.args_count = 1;
336 laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(31, 0) << 8);
337 laddr[1] = laddr[2] = 0;
338 of_irq_parse_raw(laddr, &oirq);
339 dev->irq = irq_create_of_mapping(&oirq);
340}
341
342DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, hpcd_quirk_uli1575);
343DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, hpcd_quirk_uli5288);
344DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, hpcd_quirk_uli5229);
345DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, 0x5288, hpcd_final_uli5288);
346
347int uli_exclude_device(struct pci_controller *hose,
348 u_char bus, u_char devfn)
349{
350 if (bus == (hose->first_busno + 2)) {
351
352 if ((PCI_SLOT(devfn) == 29) && (PCI_FUNC(devfn) == 1))
353 return PCIBIOS_DEVICE_NOT_FOUND;
354
355
356 if ((PCI_SLOT(devfn) == 29) && (PCI_FUNC(devfn) == 2))
357 return PCIBIOS_DEVICE_NOT_FOUND;
358 }
359
360 return PCIBIOS_SUCCESSFUL;
361}
362