aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-voodoo3.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/i2c/busses/i2c-voodoo3.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/i2c/busses/i2c-voodoo3.c')
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c254
1 files changed, 254 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
new file mode 100644
index 000000000000..3edf0e34155e
--- /dev/null
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -0,0 +1,254 @@
1/*
2 voodoo3.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>,
6 Ralph Metzler <rjkm@thp.uni-koeln.de>, and
7 Mark D. Studebaker <mdsxyz123@yahoo.com>
8
9 Based on code written by Ralph Metzler <rjkm@thp.uni-koeln.de> and
10 Simon Vogl
11
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.
16
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.
21
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.
25*/
26
27/* This interfaces to the I2C bus of the Voodoo3 to gain access to
28 the BT869 and possibly other I2C devices. */
29
30#include <linux/config.h>
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/i2c.h>
36#include <linux/i2c-algo-bit.h>
37#include <asm/io.h>
38
39/* the only registers we use */
40#define REG 0x78
41#define REG2 0x70
42
43/* bit locations in the register */
44#define DDC_ENAB 0x00040000
45#define DDC_SCL_OUT 0x00080000
46#define DDC_SDA_OUT 0x00100000
47#define DDC_SCL_IN 0x00200000
48#define DDC_SDA_IN 0x00400000
49#define I2C_ENAB 0x00800000
50#define I2C_SCL_OUT 0x01000000
51#define I2C_SDA_OUT 0x02000000
52#define I2C_SCL_IN 0x04000000
53#define I2C_SDA_IN 0x08000000
54
55/* initialization states */
56#define INIT2 0x2
57#define INIT3 0x4
58
59/* delays */
60#define CYCLE_DELAY 10
61#define TIMEOUT (HZ / 2)
62
63
64static void __iomem *ioaddr;
65
66/* The voo GPIO registers don't have individual masks for each bit
67 so we always have to read before writing. */
68
69static void bit_vooi2c_setscl(void *data, int val)
70{
71 unsigned int r;
72 r = readl(ioaddr + REG);
73 if (val)
74 r |= I2C_SCL_OUT;
75 else
76 r &= ~I2C_SCL_OUT;
77 writel(r, ioaddr + REG);
78 readl(ioaddr + REG); /* flush posted write */
79}
80
81static void bit_vooi2c_setsda(void *data, int val)
82{
83 unsigned int r;
84 r = readl(ioaddr + REG);
85 if (val)
86 r |= I2C_SDA_OUT;
87 else
88 r &= ~I2C_SDA_OUT;
89 writel(r, ioaddr + REG);
90 readl(ioaddr + REG); /* flush posted write */
91}
92
93/* The GPIO pins are open drain, so the pins always remain outputs.
94 We rely on the i2c-algo-bit routines to set the pins high before
95 reading the input from other chips. */
96
97static int bit_vooi2c_getscl(void *data)
98{
99 return (0 != (readl(ioaddr + REG) & I2C_SCL_IN));
100}
101
102static int bit_vooi2c_getsda(void *data)
103{
104 return (0 != (readl(ioaddr + REG) & I2C_SDA_IN));
105}
106
107static void bit_vooddc_setscl(void *data, int val)
108{
109 unsigned int r;
110 r = readl(ioaddr + REG);
111 if (val)
112 r |= DDC_SCL_OUT;
113 else
114 r &= ~DDC_SCL_OUT;
115 writel(r, ioaddr + REG);
116 readl(ioaddr + REG); /* flush posted write */
117}
118
119static void bit_vooddc_setsda(void *data, int val)
120{
121 unsigned int r;
122 r = readl(ioaddr + REG);
123 if (val)
124 r |= DDC_SDA_OUT;
125 else
126 r &= ~DDC_SDA_OUT;
127 writel(r, ioaddr + REG);
128 readl(ioaddr + REG); /* flush posted write */
129}
130
131static int bit_vooddc_getscl(void *data)
132{
133 return (0 != (readl(ioaddr + REG) & DDC_SCL_IN));
134}
135
136static int bit_vooddc_getsda(void *data)
137{
138 return (0 != (readl(ioaddr + REG) & DDC_SDA_IN));
139}
140
141static int config_v3(struct pci_dev *dev)
142{
143 unsigned long cadr;
144
145 /* map Voodoo3 memory */
146 cadr = dev->resource[0].start;
147 cadr &= PCI_BASE_ADDRESS_MEM_MASK;
148 ioaddr = ioremap_nocache(cadr, 0x1000);
149 if (ioaddr) {
150 writel(0x8160, ioaddr + REG2);
151 writel(0xcffc0020, ioaddr + REG);
152 dev_info(&dev->dev, "Using Banshee/Voodoo3 I2C device at %p\n", ioaddr);
153 return 0;
154 }
155 return -ENODEV;
156}
157
158static struct i2c_algo_bit_data voo_i2c_bit_data = {
159 .setsda = bit_vooi2c_setsda,
160 .setscl = bit_vooi2c_setscl,
161 .getsda = bit_vooi2c_getsda,
162 .getscl = bit_vooi2c_getscl,
163 .udelay = CYCLE_DELAY,
164 .mdelay = CYCLE_DELAY,
165 .timeout = TIMEOUT
166};
167
168static struct i2c_adapter voodoo3_i2c_adapter = {
169 .owner = THIS_MODULE,
170 .class = I2C_CLASS_TV_ANALOG,
171 .name = "I2C Voodoo3/Banshee adapter",
172 .algo_data = &voo_i2c_bit_data,
173};
174
175static struct i2c_algo_bit_data voo_ddc_bit_data = {
176 .setsda = bit_vooddc_setsda,
177 .setscl = bit_vooddc_setscl,
178 .getsda = bit_vooddc_getsda,
179 .getscl = bit_vooddc_getscl,
180 .udelay = CYCLE_DELAY,
181 .mdelay = CYCLE_DELAY,
182 .timeout = TIMEOUT
183};
184
185static struct i2c_adapter voodoo3_ddc_adapter = {
186 .owner = THIS_MODULE,
187 .class = I2C_CLASS_DDC,
188 .name = "DDC Voodoo3/Banshee adapter",
189 .algo_data = &voo_ddc_bit_data,
190};
191
192static struct pci_device_id voodoo3_ids[] __devinitdata = {
193 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3) },
194 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE) },
195 { 0, }
196};
197
198MODULE_DEVICE_TABLE (pci, voodoo3_ids);
199
200static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_id *id)
201{
202 int retval;
203
204 retval = config_v3(dev);
205 if (retval)
206 return retval;
207
208 /* set up the sysfs linkage to our parent device */
209 voodoo3_i2c_adapter.dev.parent = &dev->dev;
210 voodoo3_ddc_adapter.dev.parent = &dev->dev;
211
212 retval = i2c_bit_add_bus(&voodoo3_i2c_adapter);
213 if (retval)
214 return retval;
215 retval = i2c_bit_add_bus(&voodoo3_ddc_adapter);
216 if (retval)
217 i2c_bit_del_bus(&voodoo3_i2c_adapter);
218 return retval;
219}
220
221static void __devexit voodoo3_remove(struct pci_dev *dev)
222{
223 i2c_bit_del_bus(&voodoo3_i2c_adapter);
224 i2c_bit_del_bus(&voodoo3_ddc_adapter);
225 iounmap(ioaddr);
226}
227
228static struct pci_driver voodoo3_driver = {
229 .name = "voodoo3_smbus",
230 .id_table = voodoo3_ids,
231 .probe = voodoo3_probe,
232 .remove = __devexit_p(voodoo3_remove),
233};
234
235static int __init i2c_voodoo3_init(void)
236{
237 return pci_register_driver(&voodoo3_driver);
238}
239
240static void __exit i2c_voodoo3_exit(void)
241{
242 pci_unregister_driver(&voodoo3_driver);
243}
244
245
246MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
247 "Philip Edelbrock <phil@netroedge.com>, "
248 "Ralph Metzler <rjkm@thp.uni-koeln.de>, "
249 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
250MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver");
251MODULE_LICENSE("GPL");
252
253module_init(i2c_voodoo3_init);
254module_exit(i2c_voodoo3_exit);