2 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
3 Philip Edelbrock <phil@netroedge.com>,
4 Ralph Metzler <rjkm@thp.uni-koeln.de>, and
5 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 Based on code written by Ralph Metzler <rjkm@thp.uni-koeln.de> and
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* This interfaces to the I2C bus of the Voodoo3 to gain access to
26 the BT869 and possibly other I2C devices. */
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/pci.h>
32 #include <linux/i2c.h>
33 #include <linux/i2c-algo-bit.h>
36 /* the only registers we use */
40 /* bit locations in the register */
41 #define DDC_ENAB 0x00040000
42 #define DDC_SCL_OUT 0x00080000
43 #define DDC_SDA_OUT 0x00100000
44 #define DDC_SCL_IN 0x00200000
45 #define DDC_SDA_IN 0x00400000
46 #define I2C_ENAB 0x00800000
47 #define I2C_SCL_OUT 0x01000000
48 #define I2C_SDA_OUT 0x02000000
49 #define I2C_SCL_IN 0x04000000
50 #define I2C_SDA_IN 0x08000000
52 /* initialization states */
57 #define CYCLE_DELAY 10
58 #define TIMEOUT (HZ / 2)
61 static void __iomem *ioaddr;
63 /* The voo GPIO registers don't have individual masks for each bit
64 so we always have to read before writing. */
66 static void bit_vooi2c_setscl(void *data, int val)
69 r = readl(ioaddr + REG);
74 writel(r, ioaddr + REG);
75 readl(ioaddr + REG); /* flush posted write */
78 static void bit_vooi2c_setsda(void *data, int val)
81 r = readl(ioaddr + REG);
86 writel(r, ioaddr + REG);
87 readl(ioaddr + REG); /* flush posted write */
90 /* The GPIO pins are open drain, so the pins always remain outputs.
91 We rely on the i2c-algo-bit routines to set the pins high before
92 reading the input from other chips. */
94 static int bit_vooi2c_getscl(void *data)
96 return (0 != (readl(ioaddr + REG) & I2C_SCL_IN));
99 static int bit_vooi2c_getsda(void *data)
101 return (0 != (readl(ioaddr + REG) & I2C_SDA_IN));
104 static void bit_vooddc_setscl(void *data, int val)
107 r = readl(ioaddr + REG);
112 writel(r, ioaddr + REG);
113 readl(ioaddr + REG); /* flush posted write */
116 static void bit_vooddc_setsda(void *data, int val)
119 r = readl(ioaddr + REG);
124 writel(r, ioaddr + REG);
125 readl(ioaddr + REG); /* flush posted write */
128 static int bit_vooddc_getscl(void *data)
130 return (0 != (readl(ioaddr + REG) & DDC_SCL_IN));
133 static int bit_vooddc_getsda(void *data)
135 return (0 != (readl(ioaddr + REG) & DDC_SDA_IN));
138 static int config_v3(struct pci_dev *dev)
142 /* map Voodoo3 memory */
143 cadr = dev->resource[0].start;
144 cadr &= PCI_BASE_ADDRESS_MEM_MASK;
145 ioaddr = ioremap_nocache(cadr, 0x1000);
147 writel(0x8160, ioaddr + REG2);
148 writel(0xcffc0020, ioaddr + REG);
149 dev_info(&dev->dev, "Using Banshee/Voodoo3 I2C device at %p\n", ioaddr);
155 static struct i2c_algo_bit_data voo_i2c_bit_data = {
156 .setsda = bit_vooi2c_setsda,
157 .setscl = bit_vooi2c_setscl,
158 .getsda = bit_vooi2c_getsda,
159 .getscl = bit_vooi2c_getscl,
160 .udelay = CYCLE_DELAY,
164 static struct i2c_adapter voodoo3_i2c_adapter = {
165 .owner = THIS_MODULE,
167 .class = I2C_CLASS_TV_ANALOG,
168 .name = "I2C Voodoo3/Banshee adapter",
169 .algo_data = &voo_i2c_bit_data,
172 static struct i2c_algo_bit_data voo_ddc_bit_data = {
173 .setsda = bit_vooddc_setsda,
174 .setscl = bit_vooddc_setscl,
175 .getsda = bit_vooddc_getsda,
176 .getscl = bit_vooddc_getscl,
177 .udelay = CYCLE_DELAY,
181 static struct i2c_adapter voodoo3_ddc_adapter = {
182 .owner = THIS_MODULE,
184 .class = I2C_CLASS_DDC,
185 .name = "DDC Voodoo3/Banshee adapter",
186 .algo_data = &voo_ddc_bit_data,
189 static struct pci_device_id voodoo3_ids[] __devinitdata = {
190 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3) },
191 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE) },
195 MODULE_DEVICE_TABLE (pci, voodoo3_ids);
197 static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_id *id)
201 retval = config_v3(dev);
205 /* set up the sysfs linkage to our parent device */
206 voodoo3_i2c_adapter.dev.parent = &dev->dev;
207 voodoo3_ddc_adapter.dev.parent = &dev->dev;
209 retval = i2c_bit_add_bus(&voodoo3_i2c_adapter);
212 retval = i2c_bit_add_bus(&voodoo3_ddc_adapter);
214 i2c_del_adapter(&voodoo3_i2c_adapter);
218 static void __devexit voodoo3_remove(struct pci_dev *dev)
220 i2c_del_adapter(&voodoo3_i2c_adapter);
221 i2c_del_adapter(&voodoo3_ddc_adapter);
225 static struct pci_driver voodoo3_driver = {
226 .name = "voodoo3_smbus",
227 .id_table = voodoo3_ids,
228 .probe = voodoo3_probe,
229 .remove = __devexit_p(voodoo3_remove),
232 static int __init i2c_voodoo3_init(void)
234 return pci_register_driver(&voodoo3_driver);
237 static void __exit i2c_voodoo3_exit(void)
239 pci_unregister_driver(&voodoo3_driver);
243 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
244 "Philip Edelbrock <phil@netroedge.com>, "
245 "Ralph Metzler <rjkm@thp.uni-koeln.de>, "
246 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
247 MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver");
248 MODULE_LICENSE("GPL");
250 module_init(i2c_voodoo3_init);
251 module_exit(i2c_voodoo3_exit);