aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-via.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-via.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-via.c')
-rw-r--r--drivers/i2c/busses/i2c-via.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
new file mode 100644
index 000000000000..2cbc4cd22366
--- /dev/null
+++ b/drivers/i2c/busses/i2c-via.c
@@ -0,0 +1,185 @@
1/*
2 i2c-via.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 i2c Support for Via Technologies 82C586B South Bridge
6
7 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/
23
24#include <linux/config.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/ioport.h>
29#include <linux/init.h>
30#include <linux/i2c.h>
31#include <linux/i2c-algo-bit.h>
32#include <asm/io.h>
33
34/* Power management registers */
35#define PM_CFG_REVID 0x08 /* silicon revision code */
36#define PM_CFG_IOBASE0 0x20
37#define PM_CFG_IOBASE1 0x48
38
39#define I2C_DIR (pm_io_base+0x40)
40#define I2C_OUT (pm_io_base+0x42)
41#define I2C_IN (pm_io_base+0x44)
42#define I2C_SCL 0x02 /* clock bit in DIR/OUT/IN register */
43#define I2C_SDA 0x04
44
45/* io-region reservation */
46#define IOSPACE 0x06
47#define IOTEXT "via-i2c"
48
49static u16 pm_io_base = 0;
50
51/*
52 It does not appear from the datasheet that the GPIO pins are
53 open drain. So a we set a low value by setting the direction to
54 output and a high value by setting the direction to input and
55 relying on the required I2C pullup. The data value is initialized
56 to 0 in via_init() and never changed.
57*/
58static void bit_via_setscl(void *data, int state)
59{
60 outb(state ? inb(I2C_DIR) & ~I2C_SCL : inb(I2C_DIR) | I2C_SCL, I2C_DIR);
61}
62
63static void bit_via_setsda(void *data, int state)
64{
65 outb(state ? inb(I2C_DIR) & ~I2C_SDA : inb(I2C_DIR) | I2C_SDA, I2C_DIR);
66}
67
68static int bit_via_getscl(void *data)
69{
70 return (0 != (inb(I2C_IN) & I2C_SCL));
71}
72
73static int bit_via_getsda(void *data)
74{
75 return (0 != (inb(I2C_IN) & I2C_SDA));
76}
77
78
79static struct i2c_algo_bit_data bit_data = {
80 .setsda = bit_via_setsda,
81 .setscl = bit_via_setscl,
82 .getsda = bit_via_getsda,
83 .getscl = bit_via_getscl,
84 .udelay = 5,
85 .mdelay = 5,
86 .timeout = HZ
87};
88
89static struct i2c_adapter vt586b_adapter = {
90 .owner = THIS_MODULE,
91 .class = I2C_CLASS_HWMON,
92 .name = "VIA i2c",
93 .algo_data = &bit_data,
94};
95
96
97static struct pci_device_id vt586b_ids[] __devinitdata = {
98 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3) },
99 { 0, }
100};
101
102MODULE_DEVICE_TABLE (pci, vt586b_ids);
103
104static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_id *id)
105{
106 u16 base;
107 u8 rev;
108 int res;
109
110 if (pm_io_base) {
111 dev_err(&dev->dev, "i2c-via: Will only support one host\n");
112 return -ENODEV;
113 }
114
115 pci_read_config_byte(dev, PM_CFG_REVID, &rev);
116
117 switch (rev) {
118 case 0x00:
119 base = PM_CFG_IOBASE0;
120 break;
121 case 0x01:
122 case 0x10:
123 base = PM_CFG_IOBASE1;
124 break;
125
126 default:
127 base = PM_CFG_IOBASE1;
128 /* later revision */
129 }
130
131 pci_read_config_word(dev, base, &pm_io_base);
132 pm_io_base &= (0xff << 8);
133
134 if (!request_region(I2C_DIR, IOSPACE, IOTEXT)) {
135 dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE);
136 return -ENODEV;
137 }
138
139 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR);
140 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT);
141
142 /* set up the driverfs linkage to our parent device */
143 vt586b_adapter.dev.parent = &dev->dev;
144
145 res = i2c_bit_add_bus(&vt586b_adapter);
146 if ( res < 0 ) {
147 release_region(I2C_DIR, IOSPACE);
148 pm_io_base = 0;
149 return res;
150 }
151 return 0;
152}
153
154static void __devexit vt586b_remove(struct pci_dev *dev)
155{
156 i2c_bit_del_bus(&vt586b_adapter);
157 release_region(I2C_DIR, IOSPACE);
158 pm_io_base = 0;
159}
160
161
162static struct pci_driver vt586b_driver = {
163 .name = "vt586b_smbus",
164 .id_table = vt586b_ids,
165 .probe = vt586b_probe,
166 .remove = __devexit_p(vt586b_remove),
167};
168
169static int __init i2c_vt586b_init(void)
170{
171 return pci_register_driver(&vt586b_driver);
172}
173
174static void __exit i2c_vt586b_exit(void)
175{
176 pci_unregister_driver(&vt586b_driver);
177}
178
179
180MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>");
181MODULE_DESCRIPTION("i2c for Via vt82c586b southbridge");
182MODULE_LICENSE("GPL");
183
184module_init(i2c_vt586b_init);
185module_exit(i2c_vt586b_exit);