1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * IDE tuning and bus mastering support for the CS5510/CS5520
3*4882a593Smuzhiyun * chipsets
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * The CS5510/CS5520 are slightly unusual devices. Unlike the
6*4882a593Smuzhiyun * typical IDE controllers they do bus mastering with the drive in
7*4882a593Smuzhiyun * PIO mode and smarter silicon.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * The practical upshot of this is that we must always tune the
10*4882a593Smuzhiyun * drive for the right PIO mode. We must also ignore all the blacklists
11*4882a593Smuzhiyun * and the drive bus mastering DMA information.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * *** This driver is strictly experimental ***
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * (c) Copyright Red Hat Inc 2002
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it
18*4882a593Smuzhiyun * under the terms of the GNU General Public License as published by the
19*4882a593Smuzhiyun * Free Software Foundation; either version 2, or (at your option) any
20*4882a593Smuzhiyun * later version.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
23*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
24*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25*4882a593Smuzhiyun * General Public License for more details.
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun * For the avoidance of doubt the "preferred form" of this code is one which
28*4882a593Smuzhiyun * is in an open non patent encumbered format. Where cryptographic key signing
29*4882a593Smuzhiyun * forms part of the process of creating an executable the information
30*4882a593Smuzhiyun * including keys needed to generate an equivalently functional executable
31*4882a593Smuzhiyun * are deemed to be part of the source code.
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include <linux/module.h>
36*4882a593Smuzhiyun #include <linux/types.h>
37*4882a593Smuzhiyun #include <linux/kernel.h>
38*4882a593Smuzhiyun #include <linux/init.h>
39*4882a593Smuzhiyun #include <linux/pci.h>
40*4882a593Smuzhiyun #include <linux/ide.h>
41*4882a593Smuzhiyun #include <linux/dma-mapping.h>
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #define DRV_NAME "cs5520"
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun struct pio_clocks
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun int address;
48*4882a593Smuzhiyun int assert;
49*4882a593Smuzhiyun int recovery;
50*4882a593Smuzhiyun };
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun static struct pio_clocks cs5520_pio_clocks[]={
53*4882a593Smuzhiyun {3, 6, 11},
54*4882a593Smuzhiyun {2, 5, 6},
55*4882a593Smuzhiyun {1, 4, 3},
56*4882a593Smuzhiyun {1, 3, 2},
57*4882a593Smuzhiyun {1, 2, 1}
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun
cs5520_set_pio_mode(ide_hwif_t * hwif,ide_drive_t * drive)60*4882a593Smuzhiyun static void cs5520_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun struct pci_dev *pdev = to_pci_dev(hwif->dev);
63*4882a593Smuzhiyun int controller = drive->dn > 1 ? 1 : 0;
64*4882a593Smuzhiyun const u8 pio = drive->pio_mode - XFER_PIO_0;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun /* 8bit CAT/CRT - 8bit command timing for channel */
67*4882a593Smuzhiyun pci_write_config_byte(pdev, 0x62 + controller,
68*4882a593Smuzhiyun (cs5520_pio_clocks[pio].recovery << 4) |
69*4882a593Smuzhiyun (cs5520_pio_clocks[pio].assert));
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* 0x64 - 16bit Primary, 0x68 - 16bit Secondary */
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /* FIXME: should these use address ? */
74*4882a593Smuzhiyun /* Data read timing */
75*4882a593Smuzhiyun pci_write_config_byte(pdev, 0x64 + 4*controller + (drive->dn&1),
76*4882a593Smuzhiyun (cs5520_pio_clocks[pio].recovery << 4) |
77*4882a593Smuzhiyun (cs5520_pio_clocks[pio].assert));
78*4882a593Smuzhiyun /* Write command timing */
79*4882a593Smuzhiyun pci_write_config_byte(pdev, 0x66 + 4*controller + (drive->dn&1),
80*4882a593Smuzhiyun (cs5520_pio_clocks[pio].recovery << 4) |
81*4882a593Smuzhiyun (cs5520_pio_clocks[pio].assert));
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun
cs5520_set_dma_mode(ide_hwif_t * hwif,ide_drive_t * drive)84*4882a593Smuzhiyun static void cs5520_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun printk(KERN_ERR "cs55x0: bad ide timing.\n");
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun drive->pio_mode = XFER_PIO_0 + 0;
89*4882a593Smuzhiyun cs5520_set_pio_mode(hwif, drive);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun static const struct ide_port_ops cs5520_port_ops = {
93*4882a593Smuzhiyun .set_pio_mode = cs5520_set_pio_mode,
94*4882a593Smuzhiyun .set_dma_mode = cs5520_set_dma_mode,
95*4882a593Smuzhiyun };
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun static const struct ide_port_info cyrix_chipset = {
98*4882a593Smuzhiyun .name = DRV_NAME,
99*4882a593Smuzhiyun .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
100*4882a593Smuzhiyun .port_ops = &cs5520_port_ops,
101*4882a593Smuzhiyun .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_CS5520,
102*4882a593Smuzhiyun .pio_mask = ATA_PIO4,
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * The 5510/5520 are a bit weird. They don't quite set up the way
107*4882a593Smuzhiyun * the PCI helper layer expects so we must do much of the set up
108*4882a593Smuzhiyun * work longhand.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun
cs5520_init_one(struct pci_dev * dev,const struct pci_device_id * id)111*4882a593Smuzhiyun static int cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
112*4882a593Smuzhiyun {
113*4882a593Smuzhiyun const struct ide_port_info *d = &cyrix_chipset;
114*4882a593Smuzhiyun struct ide_hw hw[2], *hws[] = { NULL, NULL };
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun ide_setup_pci_noise(dev, d);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /* We must not grab the entire device, it has 'ISA' space in its
119*4882a593Smuzhiyun * BARS too and we will freak out other bits of the kernel
120*4882a593Smuzhiyun */
121*4882a593Smuzhiyun if (pci_enable_device_io(dev)) {
122*4882a593Smuzhiyun printk(KERN_WARNING "%s: Unable to enable 55x0.\n", d->name);
123*4882a593Smuzhiyun return -ENODEV;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun pci_set_master(dev);
126*4882a593Smuzhiyun if (dma_set_mask(&dev->dev, DMA_BIT_MASK(32))) {
127*4882a593Smuzhiyun printk(KERN_WARNING "%s: No suitable DMA available.\n",
128*4882a593Smuzhiyun d->name);
129*4882a593Smuzhiyun return -ENODEV;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /*
133*4882a593Smuzhiyun * Now the chipset is configured we can let the core
134*4882a593Smuzhiyun * do all the device setup for us
135*4882a593Smuzhiyun */
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun ide_pci_setup_ports(dev, d, &hw[0], &hws[0]);
138*4882a593Smuzhiyun hw[0].irq = 14;
139*4882a593Smuzhiyun hw[1].irq = 15;
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun return ide_host_add(d, hws, 2, NULL);
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun static const struct pci_device_id cs5520_pci_tbl[] = {
145*4882a593Smuzhiyun { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), 0 },
146*4882a593Smuzhiyun { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), 1 },
147*4882a593Smuzhiyun { 0, },
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun static struct pci_driver cs5520_pci_driver = {
152*4882a593Smuzhiyun .name = "Cyrix_IDE",
153*4882a593Smuzhiyun .id_table = cs5520_pci_tbl,
154*4882a593Smuzhiyun .probe = cs5520_init_one,
155*4882a593Smuzhiyun .suspend = ide_pci_suspend,
156*4882a593Smuzhiyun .resume = ide_pci_resume,
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun
cs5520_ide_init(void)159*4882a593Smuzhiyun static int __init cs5520_ide_init(void)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun return ide_pci_register_driver(&cs5520_pci_driver);
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun module_init(cs5520_ide_init);
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun MODULE_AUTHOR("Alan Cox");
167*4882a593Smuzhiyun MODULE_DESCRIPTION("PCI driver module for Cyrix 5510/5520 IDE");
168*4882a593Smuzhiyun MODULE_LICENSE("GPL");
169