18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
22 #include <linux/pci.h>
28 #ifdef CONFIG_PPC_PMAC
30 #include <asm/pci-bridge.h>
33 #define DRV_NAME "pdc202xx_new"
38 #define DBG(fmt, args...) printk("%s: " fmt, __func__, ## args)
40 #define DBG(fmt, args...)
43 static u8 max_dma_rate(
struct pci_dev *pdev)
78 DBG(
"index[%02X] value[%02X]\n", index, value);
91 DBG(
"index[%02X] value[%02X]\n", index, value);
102 static struct pio_timing {
103 u8 reg0c, reg0d, reg13;
105 { 0xfb, 0x2b, 0xac },
106 { 0x46, 0x29, 0xa4 },
107 { 0x23, 0x26, 0x64 },
108 { 0x27, 0x0d, 0x35 },
109 { 0x23, 0x09, 0x25 },
112 static struct mwdma_timing {
114 } mwdma_timings [] = {
120 static struct udma_timing {
121 u8 reg10, reg11, reg12;
122 } udma_timings [] = {
123 { 0x4a, 0x0f, 0xd5 },
124 { 0x3a, 0x0a, 0xd0 },
125 { 0x2a, 0x07, 0xcd },
126 { 0x1a, 0x05, 0xcd },
127 { 0x1a, 0x03, 0xcd },
128 { 0x1a, 0x02, 0xcb },
129 { 0x1a, 0x01, 0xcb },
135 u8 adj = (drive->
dn & 1) ? 0x08 : 0x00;
146 if (max_dma_rate(dev) == 4) {
150 set_indexed_reg(hwif, 0x10 + adj,
151 udma_timings[mode].reg10);
152 set_indexed_reg(hwif, 0x11 + adj,
153 udma_timings[mode].reg11);
154 set_indexed_reg(hwif, 0x12 + adj,
155 udma_timings[mode].reg12);
157 set_indexed_reg(hwif, 0x0e + adj,
158 mwdma_timings[mode].reg0e);
159 set_indexed_reg(hwif, 0x0f + adj,
160 mwdma_timings[mode].reg0f);
164 u8 tmp = get_indexed_reg(hwif, 0x10 + adj);
166 set_indexed_reg(hwif, 0x10 + adj, tmp & 0x7f);
173 u8 adj = (drive->
dn & 1) ? 0x08 : 0x00;
176 if (max_dma_rate(dev) == 4) {
177 set_indexed_reg(hwif, 0x0c + adj, pio_timings[pio].reg0c);
178 set_indexed_reg(hwif, 0x0d + adj, pio_timings[pio].reg0d);
179 set_indexed_reg(hwif, 0x13 + adj, pio_timings[pio].reg13);
185 if (get_indexed_reg(hwif, 0x0b) & 0x04)
197 drive->
hwif->channel ?
"Secondary" :
"Primary");
206 u32 pri_dma_base = dma_base, sec_dma_base = dma_base + 0x08;
207 u8 cnt0, cnt1, cnt2, cnt3;
215 outb(0x20, pri_dma_base + 0x01);
216 cnt0 =
inb(pri_dma_base + 0x03);
217 outb(0x21, pri_dma_base + 0x01);
218 cnt1 =
inb(pri_dma_base + 0x03);
219 outb(0x20, sec_dma_base + 0x01);
220 cnt2 =
inb(sec_dma_base + 0x03);
221 outb(0x21, sec_dma_base + 0x01);
222 cnt3 =
inb(sec_dma_base + 0x03);
224 count = (cnt3 << 23) | (cnt2 << 15) | (cnt1 << 8) | cnt0;
231 }
while (retry-- && (((last ^ count) & 0x3fff8000) ||
last <
count));
233 DBG(
"cnt0[%02X] cnt1[%02X] cnt2[%02X] cnt3[%02X]\n",
234 cnt0, cnt1, cnt2, cnt3);
244 static long detect_pll_input_clock(
unsigned long dma_base)
247 long start_count, end_count;
248 long pll_input, usec_elapsed;
255 outb(0x01, dma_base + 0x01);
256 scr1 =
inb(dma_base + 0x03);
257 DBG(
"scr1[%02X]\n", scr1);
258 outb(scr1 | 0x40, dma_base + 0x03);
267 outb(0x01, dma_base + 0x01);
268 scr1 =
inb(dma_base + 0x03);
269 DBG(
"scr1[%02X]\n", scr1);
270 outb(scr1 & ~0x40, dma_base + 0x03);
276 usec_elapsed = (end_time.tv_sec -
start_time.tv_sec) * 1000000 +
278 pll_input = ((start_count - end_count) & 0x3fffffff) / 10 *
279 (10000000 / usec_elapsed);
281 DBG(
"start[%ld] end[%ld]\n", start_count, end_count);
286 #ifdef CONFIG_PPC_PMAC
287 static void apple_kiwi_init(
struct pci_dev *pdev)
289 struct device_node *np = pci_device_to_OF_node(pdev);
297 pci_read_config_byte (pdev, 0x40, &conf);
298 pci_write_config_byte(pdev, 0x40, (conf | 0x01));
303 static int init_chipset_pdcnew(
struct pci_dev *dev)
307 unsigned long sec_dma_base = dma_base + 0x08;
308 long pll_input, pll_output,
ratio;
310 u8 pll_ctl0, pll_ctl1;
315 #ifdef CONFIG_PPC_PMAC
316 apple_kiwi_init(dev);
320 switch(max_dma_rate(dev)) {
322 pll_output = 133333333;
326 pll_output = 100000000;
337 pll_input = detect_pll_input_clock(dma_base);
339 name, pci_name(dev), pll_input / 1000);
342 if (
unlikely(pll_input < 5000000L || pll_input > 70000000L)) {
344 "\n", name, pci_name(dev), pll_input);
349 DBG(
"pll_output is %ld Hz\n", pll_output);
354 outb(0x02, sec_dma_base + 0x01);
355 pll_ctl0 =
inb(sec_dma_base + 0x03);
356 outb(0x03, sec_dma_base + 0x01);
357 pll_ctl1 =
inb(sec_dma_base + 0x03);
359 DBG(
"pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
366 ratio = pll_output / (pll_input / 1000);
370 }
else if (ratio < 12900L) {
373 }
else if (ratio < 16100L) {
376 }
else if (ratio < 64000L) {
381 name, pci_name(dev), ratio);
385 f = (ratio * (r + 2)) / 1000 - 2;
387 DBG(
"F[%d] R[%d] ratio*1000[%ld]\n", f, r, ratio);
392 name, pci_name(dev), f);
399 DBG(
"Writing pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
401 outb(0x02, sec_dma_base + 0x01);
402 outb(pll_ctl0, sec_dma_base + 0x03);
403 outb(0x03, sec_dma_base + 0x01);
404 outb(pll_ctl1, sec_dma_base + 0x03);
413 outb(0x02, sec_dma_base + 0x01);
414 pll_ctl0 =
inb(sec_dma_base + 0x03);
415 outb(0x03, sec_dma_base + 0x01);
416 pll_ctl1 =
inb(sec_dma_base + 0x03);
418 DBG(
"pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
436 if (dev2->
irq != dev->
irq) {
439 "interrupt fixed\n", pci_name(dev));
449 .set_pio_mode = pdcnew_set_pio_mode,
450 .set_dma_mode = pdcnew_set_dma_mode,
451 .resetproc = pdcnew_reset,
452 .cable_detect = pdcnew_cable_detect,
455 #define DECLARE_PDCNEW_DEV(udma) \
458 .init_chipset = init_chipset_pdcnew, \
459 .port_ops = &pdcnew_port_ops, \
460 .host_flags = IDE_HFLAG_POST_SET_MODE | \
461 IDE_HFLAG_ERROR_STOPS_FIFO | \
462 IDE_HFLAG_OFF_BOARD, \
463 .pio_mask = ATA_PIO4, \
464 .mwdma_mask = ATA_MWDMA2, \
484 const struct ide_port_info *
d = &pdcnew_chipsets[
id->driver_data];
495 dev2 = pdc20270_get_dev2(dev);
510 " skipping\n", pci_name(dev));
538 static struct pci_driver pdc202new_pci_driver = {
539 .name =
"Promise_IDE",
540 .id_table = pdc202new_pci_tbl,
541 .probe = pdc202new_init_one,
547 static int __init pdc202new_ide_init(
void)
552 static void __exit pdc202new_ide_exit(
void)