[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / i2c / busses / i2c-hydra.c
blobe0cb3b0f92faba50a64d40f437188f106aaa9c57
1 /*
2 i2c-hydra.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
5 i2c Support for the Apple `Hydra' Mac I/O
7 Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org>
9 Based on i2c Support for Via Technologies 82C586B South Bridge
10 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/types.h>
31 #include <linux/i2c.h>
32 #include <linux/i2c-algo-bit.h>
33 #include <linux/init.h>
34 #include <asm/io.h>
35 #include <asm/hydra.h>
38 #define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */
39 #define HYDRA_CPD_PD1 0x00000002
40 #define HYDRA_CPD_PD2 0x00000004
41 #define HYDRA_CPD_PD3 0x00000008
43 #define HYDRA_SCLK HYDRA_CPD_PD0
44 #define HYDRA_SDAT HYDRA_CPD_PD1
45 #define HYDRA_SCLK_OE 0x00000010
46 #define HYDRA_SDAT_OE 0x00000020
48 static inline void pdregw(void *data, u32 val)
50 struct Hydra *hydra = (struct Hydra *)data;
51 writel(val, &hydra->CachePD);
54 static inline u32 pdregr(void *data)
56 struct Hydra *hydra = (struct Hydra *)data;
57 return readl(&hydra->CachePD);
60 static void hydra_bit_setscl(void *data, int state)
62 u32 val = pdregr(data);
63 if (state)
64 val &= ~HYDRA_SCLK_OE;
65 else {
66 val &= ~HYDRA_SCLK;
67 val |= HYDRA_SCLK_OE;
69 pdregw(data, val);
72 static void hydra_bit_setsda(void *data, int state)
74 u32 val = pdregr(data);
75 if (state)
76 val &= ~HYDRA_SDAT_OE;
77 else {
78 val &= ~HYDRA_SDAT;
79 val |= HYDRA_SDAT_OE;
81 pdregw(data, val);
84 static int hydra_bit_getscl(void *data)
86 return (pdregr(data) & HYDRA_SCLK) != 0;
89 static int hydra_bit_getsda(void *data)
91 return (pdregr(data) & HYDRA_SDAT) != 0;
94 /* ------------------------------------------------------------------------ */
96 static struct i2c_algo_bit_data hydra_bit_data = {
97 .setsda = hydra_bit_setsda,
98 .setscl = hydra_bit_setscl,
99 .getsda = hydra_bit_getsda,
100 .getscl = hydra_bit_getscl,
101 .udelay = 5,
102 .mdelay = 5,
103 .timeout = HZ
106 static struct i2c_adapter hydra_adap = {
107 .owner = THIS_MODULE,
108 .name = "Hydra i2c",
109 .id = I2C_HW_B_HYDRA,
110 .algo_data = &hydra_bit_data,
113 static struct pci_device_id hydra_ids[] = {
114 { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
115 { 0, }
118 MODULE_DEVICE_TABLE (pci, hydra_ids);
120 static int __devinit hydra_probe(struct pci_dev *dev,
121 const struct pci_device_id *id)
123 unsigned long base = pci_resource_start(dev, 0);
124 int res;
126 if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4,
127 hydra_adap.name))
128 return -EBUSY;
130 hydra_bit_data.data = ioremap(base, pci_resource_len(dev, 0));
131 if (hydra_bit_data.data == NULL) {
132 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
133 return -ENODEV;
136 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
137 hydra_adap.dev.parent = &dev->dev;
138 res = i2c_bit_add_bus(&hydra_adap);
139 if (res < 0) {
140 iounmap(hydra_bit_data.data);
141 release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
142 return res;
144 return 0;
147 static void __devexit hydra_remove(struct pci_dev *dev)
149 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
150 i2c_bit_del_bus(&hydra_adap);
151 iounmap(hydra_bit_data.data);
152 release_mem_region(pci_resource_start(dev, 0)+
153 offsetof(struct Hydra, CachePD), 4);
157 static struct pci_driver hydra_driver = {
158 .name = "hydra_smbus",
159 .id_table = hydra_ids,
160 .probe = hydra_probe,
161 .remove = __devexit_p(hydra_remove),
164 static int __init i2c_hydra_init(void)
166 return pci_register_driver(&hydra_driver);
170 static void __exit i2c_hydra_exit(void)
172 pci_unregister_driver(&hydra_driver);
177 MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
178 MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O");
179 MODULE_LICENSE("GPL");
181 module_init(i2c_hydra_init);
182 module_exit(i2c_hydra_exit);