1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/pci.h>
40#include <linux/blkdev.h>
41#include <linux/delay.h>
42#include <scsi/scsi_host.h>
43#include <linux/libata.h>
44
45#define DRV_NAME "pata_ninja32"
46#define DRV_VERSION "0.1.5"
47
48
49
50
51
52
53
54
55
56
57
58static void ninja32_set_piomode(struct ata_port *ap, struct ata_device *adev)
59{
60 static u16 pio_timing[5] = {
61 0xd6, 0x85, 0x44, 0x33, 0x13
62 };
63 iowrite8(pio_timing[adev->pio_mode - XFER_PIO_0],
64 ap->ioaddr.bmdma_addr + 0x1f);
65 ap->private_data = adev;
66}
67
68
69static void ninja32_dev_select(struct ata_port *ap, unsigned int device)
70{
71 struct ata_device *adev = &ap->link.device[device];
72 if (ap->private_data != adev) {
73 iowrite8(0xd6, ap->ioaddr.bmdma_addr + 0x1f);
74 ata_sff_dev_select(ap, device);
75 ninja32_set_piomode(ap, adev);
76 }
77}
78
79static struct scsi_host_template ninja32_sht = {
80 ATA_BMDMA_SHT(DRV_NAME),
81};
82
83static struct ata_port_operations ninja32_port_ops = {
84 .inherits = &ata_bmdma_port_ops,
85 .sff_dev_select = ninja32_dev_select,
86 .cable_detect = ata_cable_40wire,
87 .set_piomode = ninja32_set_piomode,
88 .sff_data_xfer = ata_sff_data_xfer32
89};
90
91static void ninja32_program(void __iomem *base)
92{
93 iowrite8(0x05, base + 0x01);
94 iowrite8(0xBE, base + 0x02);
95 iowrite8(0x01, base + 0x03);
96 iowrite8(0x20, base + 0x04);
97 iowrite8(0x8f, base + 0x05);
98 iowrite8(0xa4, base + 0x1c);
99 iowrite8(0x83, base + 0x1d);
100}
101
102static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id)
103{
104 struct ata_host *host;
105 struct ata_port *ap;
106 void __iomem *base;
107 int rc;
108
109 host = ata_host_alloc(&dev->dev, 1);
110 if (!host)
111 return -ENOMEM;
112 ap = host->ports[0];
113
114
115 rc = pcim_enable_device(dev);
116 if (rc)
117 return rc;
118 rc = pcim_iomap_regions(dev, 1 << 0, DRV_NAME);
119 if (rc == -EBUSY)
120 pcim_pin_device(dev);
121 if (rc)
122 return rc;
123
124 host->iomap = pcim_iomap_table(dev);
125 rc = pci_set_dma_mask(dev, ATA_DMA_MASK);
126 if (rc)
127 return rc;
128 rc = pci_set_consistent_dma_mask(dev, ATA_DMA_MASK);
129 if (rc)
130 return rc;
131 pci_set_master(dev);
132
133
134
135 base = host->iomap[0];
136 if (!base)
137 return -ENOMEM;
138 ap->ops = &ninja32_port_ops;
139 ap->pio_mask = ATA_PIO4;
140 ap->flags |= ATA_FLAG_SLAVE_POSS;
141
142 ap->ioaddr.cmd_addr = base + 0x10;
143 ap->ioaddr.ctl_addr = base + 0x1E;
144 ap->ioaddr.altstatus_addr = base + 0x1E;
145 ap->ioaddr.bmdma_addr = base;
146 ata_sff_std_ports(&ap->ioaddr);
147 ap->pflags = ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
148
149 ninja32_program(base);
150
151 return ata_host_activate(host, dev->irq, ata_bmdma_interrupt,
152 IRQF_SHARED, &ninja32_sht);
153}
154
155#ifdef CONFIG_PM
156
157static int ninja32_reinit_one(struct pci_dev *pdev)
158{
159 struct ata_host *host = dev_get_drvdata(&pdev->dev);
160 int rc;
161
162 rc = ata_pci_device_do_resume(pdev);
163 if (rc)
164 return rc;
165 ninja32_program(host->iomap[0]);
166 ata_host_resume(host);
167 return 0;
168}
169#endif
170
171static const struct pci_device_id ninja32[] = {
172 { 0x10FC, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
173 { 0x1145, 0x8008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
174 { 0x1145, 0xf008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
175 { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
176 { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
177 { 0x1145, 0xf02C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
178 { },
179};
180
181static struct pci_driver ninja32_pci_driver = {
182 .name = DRV_NAME,
183 .id_table = ninja32,
184 .probe = ninja32_init_one,
185 .remove = ata_pci_remove_one,
186#ifdef CONFIG_PM
187 .suspend = ata_pci_device_suspend,
188 .resume = ninja32_reinit_one,
189#endif
190};
191
192module_pci_driver(ninja32_pci_driver);
193
194MODULE_AUTHOR("Alan Cox");
195MODULE_DESCRIPTION("low-level driver for Ninja32 ATA");
196MODULE_LICENSE("GPL");
197MODULE_DEVICE_TABLE(pci, ninja32);
198MODULE_VERSION(DRV_VERSION);
199