]> rtime.felk.cvut.cz Git - mf6xx.git/blob - mf614.c
3b522a62c919e92223782b76e0162a0fbb480a76
[mf6xx.git] / mf614.c
1 #include <linux/module.h>
2 #include <linux/pci.h>
3 #include <linux/uio_driver.h>
4
5 #define PCI_VENDOR_ID_HUMUSOFT          0x186c
6 #define PCI_DEVICE_ID_MF614             0x0614
7 #define PCI_SUBVENDOR_ID_HUMUSOFT       0x186c
8 #define PCI_SUBDEVICE_DEVICE            0x0000
9
10 #define STATUS_OFFSET                   0x10
11 #define STATUS_T5INTE                   (u32) (1 << 19)
12 #define STATUS_T5                       (u32) (1 << 18)
13 #define STATUS_CCINTE                   (u32) (1 << 3)
14 #define STATUS_CC                       (u32) (1 << 2)
15
16
17 static irqreturn_t mf614_irq_handler(int irq, struct uio_info *dev_info)
18 {
19         void __iomem *status_reg = dev_info->priv + STATUS_OFFSET;
20
21         if ((ioread16(status_reg) & STATUS_T5INTE) 
22                 && (ioread16(status_reg) & STATUS_T5))
23         {
24                 iowrite16(ioread16(status_reg) & ~STATUS_T5, status_reg);
25                 return IRQ_HANDLED;
26         }
27
28         if ((ioread16(status_reg) & STATUS_CCINTE) 
29                 && (ioread16(status_reg) & STATUS_CC))
30         {
31                 iowrite16(ioread16(status_reg) & ~STATUS_CC, status_reg);
32                 return IRQ_HANDLED;
33         }
34
35         return IRQ_NONE;
36 }
37
38 static int __devinit mf614_pci_probe(struct pci_dev *dev,
39                                      const struct pci_device_id *id)
40 {
41         struct uio_info *info;
42
43         info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
44         if (!info)
45                 return -ENOMEM;
46         
47         if (pci_enable_device(dev)) //FIXME what is return value??
48                 goto out_free;
49
50         if (pci_request_regions(dev, "mf614"))
51                 goto out_disable;
52         
53         info->name = "MF614";
54         info->version = "0.0.1";
55         
56         info->port[0].porttype = UIO_PORT_X86;
57         info->port[0].start = pci_resource_start(dev, 0);
58         if (!info->port[0].start)
59                 goto out_release;
60         info->port[0].size = pci_resource_len(dev, 0);
61         
62         info->port[1].porttype = UIO_PORT_X86;
63         info->port[1].start = pci_resource_start(dev, 2);
64         if (!info->port[1].start)
65                 goto out_release;
66         info->port[1].size = pci_resource_len(dev, 2);
67
68         info->priv = pci_iomap(dev, 2, 0);
69         if (!info->priv)
70                 goto out_release; 
71         
72         info->mem[0].addr = pci_resource_start(dev, 4);
73         if (!info->mem[0].addr)
74                 goto out_release;
75         info->mem[0].size = pci_resource_len(dev, 4);
76         info->mem[0].memtype = UIO_MEM_PHYS;
77         info->mem[0].internal_addr = pci_ioremap_bar(dev, 4);
78         if (!info->mem[0].internal_addr)
79                 goto out_release;
80         
81         info->irq = dev->irq;
82         info->irq_flags = IRQF_SHARED;
83         info->handler = mf614_irq_handler;
84
85         if(uio_register_device(&dev->dev, info))
86                 goto out_unmap;
87
88         pci_set_drvdata(dev, info);
89
90         return 0;
91
92 out_unmap:
93         iounmap(info->mem[0].internal_addr);
94 out_release:
95         pci_release_regions(dev);
96 out_disable:
97         pci_disable_device(dev);
98 out_free:
99         kfree(info);
100         return -ENODEV;
101 }
102
103 static void mf614_pci_remove(struct pci_dev *dev)
104 {
105
106 }
107
108 static struct pci_device_id mf614_pci_id[] __devinitdata = {
109         {
110                 .vendor = PCI_VENDOR_ID_HUMUSOFT,
111                 .device = PCI_DEVICE_ID_MF614,
112                 .subvendor = PCI_SUBVENDOR_ID_HUMUSOFT,
113                 .subdevice = PCI_SUBDEVICE_DEVICE,
114         },
115         { 0, }
116 };
117
118 static struct pci_driver mf614_pci_driver = {
119         .name = "mf614",
120         .id_table = mf614_pci_id,
121         .probe = mf614_pci_probe, 
122         .remove = mf614_pci_remove,
123 };
124
125 static int __init mf614_init_module(void)
126 {
127         return pci_register_driver(&mf614_pci_driver);
128 }
129
130 static void __exit mf614_exit_module(void)
131 {
132         pci_unregister_driver(&mf614_pci_driver);
133 }
134
135 module_init(mf614_init_module);
136 module_exit(mf614_exit_module);
137
138 MODULE_LICENSE("GPL v2");
139 MODULE_AUTHOR("Rostislav Lisovy <lisovy@gmail.com>");