root/lm-sensors/trunk/kernel/busses/i2c-savage4.c @ 1343

Revision 1343, 8.1 KB (checked in by mds, 11 years ago)

compile fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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/version.h>
31#include <linux/module.h>
32#include <linux/pci.h>
33#include <asm/io.h>
34#include <linux/i2c.h>
35#include <linux/i2c-algo-bit.h>
36#include "version.h"
37#include <linux/init.h>
38
39#ifdef MODULE_LICENSE
40MODULE_LICENSE("GPL");
41#endif
42
43/* 3DFX defines */
44/* #define PCI_VENDOR_ID_S3             0x5333 */
45#define PCI_CHIP_SAVAGE3D       0x8A20
46#define PCI_CHIP_SAVAGE3D_MV    0x8A21
47#define PCI_CHIP_SAVAGE4        0x8A22
48#define PCI_CHIP_SAVAGE2000     0x9102
49#define PCI_CHIP_PROSAVAGE_PM   0x8A25
50#define PCI_CHIP_PROSAVAGE_KM   0x8A26
51#define PCI_CHIP_SAVAGE_MX_MV   0x8c10
52#define PCI_CHIP_SAVAGE_MX      0x8c11
53#define PCI_CHIP_SAVAGE_IX_MV   0x8c12
54#define PCI_CHIP_SAVAGE_IX      0x8c13
55
56/* the only registers we use */
57//#define REG   0x78
58//#define REG2  0x70
59#define REG 0xff20      /* Serial Port 1 Register */
60
61/* bit locations in the register */
62//#define DDC_ENAB      0x00040000
63//#define DDC_SCL_OUT   0x00080000
64//#define DDC_SDA_OUT   0x00100000
65//#define DDC_SCL_IN    0x00200000
66//#define DDC_SDA_IN    0x00400000
67#define I2C_ENAB        0x00000020
68#define I2C_SCL_OUT     0x00000001
69#define I2C_SDA_OUT     0x00000002
70#define I2C_SCL_IN      0x00000008
71#define I2C_SDA_IN      0x00000010
72
73/* initialization states */
74#define INIT2   0x20
75/* #define INIT3        0x4 */
76
77/* delays */
78#define CYCLE_DELAY     10
79#define TIMEOUT         50
80
81#ifdef MODULE
82static
83#else
84extern
85#endif
86int __init i2c_voodoo3_init(void);
87static int __init voodoo3_cleanup(void);
88static int voodoo3_setup(void);
89static void config_v3(struct pci_dev *dev);
90static void voodoo3_inc(struct i2c_adapter *adapter);
91static void voodoo3_dec(struct i2c_adapter *adapter);
92
93#ifdef MODULE
94extern int init_module(void);
95extern int cleanup_module(void);
96#endif                          /* MODULE */
97
98
99static int __initdata voodoo3_initialized;
100static unsigned char *mem;
101
102extern inline void outlong(unsigned int dat)
103{
104        *((unsigned int *) (mem + REG)) = dat;
105}
106
107extern inline unsigned int readlong(void)
108{
109        return *((unsigned int *) (mem + REG));
110}
111
112/* The voo GPIO registers don't have individual masks for each bit
113   so we always have to read before writing. */
114
115static void bit_vooi2c_setscl(void *data, int val)
116{
117        unsigned int r;
118        r = readlong();
119        if(val)
120                r |= I2C_SCL_OUT;
121        else
122                r &= ~I2C_SCL_OUT;
123        outlong(r);
124}
125
126static void bit_vooi2c_setsda(void *data, int val)
127{
128        unsigned int r;
129        r = readlong();
130        if(val)
131                r |= I2C_SDA_OUT;
132        else
133                r &= ~I2C_SDA_OUT;
134        outlong(r);
135}
136
137/* The GPIO pins are open drain, so the pins always remain outputs.
138   We rely on the i2c-algo-bit routines to set the pins high before
139   reading the input from other chips. */
140
141static int bit_vooi2c_getscl(void *data)
142{
143        return (0 != (readlong() & I2C_SCL_IN));
144}
145
146static int bit_vooi2c_getsda(void *data)
147{
148        return (0 != (readlong() & I2C_SDA_IN));
149}
150
151/*static void bit_vooddc_setscl(void *data, int val)
152{
153        unsigned int r;
154        r = readlong();
155        if(val)
156                r |= DDC_SCL_OUT;
157        else
158                r &= ~DDC_SCL_OUT;
159        outlong(r);
160}
161
162static void bit_vooddc_setsda(void *data, int val)
163{
164        unsigned int r;
165        r = readlong();
166        if(val)
167                r |= DDC_SDA_OUT;
168        else
169                r &= ~DDC_SDA_OUT;
170        outlong(r);
171}
172
173static int bit_vooddc_getscl(void *data)
174{
175        return (0 != (readlong() & DDC_SCL_IN));
176}
177
178static int bit_vooddc_getsda(void *data)
179{
180        return (0 != (readlong() & DDC_SDA_IN));
181}
182*/
183static struct i2c_algo_bit_data voo_i2c_bit_data = {
184        NULL,
185        bit_vooi2c_setsda,
186        bit_vooi2c_setscl,
187        bit_vooi2c_getsda,
188        bit_vooi2c_getscl,
189        CYCLE_DELAY, CYCLE_DELAY, TIMEOUT
190};
191
192static struct i2c_adapter voodoo3_i2c_adapter = {
193        "I2C Voodoo3/Banshee adapter",
194        I2C_HW_B_VOO,
195        NULL,
196        &voo_i2c_bit_data,
197        voodoo3_inc,
198        voodoo3_dec,
199        NULL,
200        NULL,
201};
202/*
203static struct i2c_algo_bit_data voo_ddc_bit_data = {
204        NULL,
205        bit_vooddc_setsda,
206        bit_vooddc_setscl,
207        bit_vooddc_getsda,
208        bit_vooddc_getscl,
209        CYCLE_DELAY, CYCLE_DELAY, TIMEOUT
210};
211
212static struct i2c_adapter voodoo3_ddc_adapter = {
213        "DDC Voodoo3/Banshee adapter",
214        I2C_HW_B_VOO,
215        NULL,
216        &voo_ddc_bit_data,
217        voodoo3_inc,
218        voodoo3_dec,
219        NULL,
220        NULL,
221};
222*/
223/* Configures the chip */
224
225void config_v3(struct pci_dev *dev)
226{
227        unsigned int cadr;
228
229        /* map Voodoo3 memory */
230#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
231        cadr = dev->resource[0].start;
232#else
233        cadr = dev->base_address[0];
234#endif
235        cadr &= PCI_BASE_ADDRESS_MEM_MASK;
236        mem = ioremap_nocache(cadr, 0x0080000);
237
238//      *((unsigned int *) (mem + REG2)) = 0x8160;
239        *((unsigned int *) (mem + REG)) = 0x00000020;
240        printk("i2c-voodoo3: Using Banshee/Voodoo3 at 0x%p\n", mem);
241}
242
243/* Detect whether a Voodoo3 or a Banshee can be found,
244   and initialize it. */
245static int voodoo3_setup(void)
246{
247        struct pci_dev *dev;
248        int v3_num;
249
250        v3_num = 0;
251
252        dev = NULL;
253        do {
254                if ((dev = pci_find_device(PCI_VENDOR_ID_S3,
255                                           PCI_CHIP_SAVAGE4,
256                                           dev))) {
257                        if (!v3_num)
258                                config_v3(dev);
259                        v3_num++;
260                }
261        } while (dev);
262
263        dev = NULL;
264        do {
265                if ((dev = pci_find_device(PCI_VENDOR_ID_S3,
266                                           PCI_CHIP_SAVAGE2000,
267                                           dev))) {
268                        if (!v3_num)
269                                config_v3(dev);
270                        v3_num++;
271                }
272        } while (dev);
273
274        if (v3_num > 0) {
275                printk("i2c-voodoo3: %d Banshee/Voodoo3 found.\n", v3_num);
276                if (v3_num > 1)
277                        printk("i2c-voodoo3: warning: only 1 supported.\n");
278                return 0;
279        } else {
280                printk("i2c-voodoo3: No Voodoo3 found.\n");
281                return -ENODEV;
282        }
283}
284
285void voodoo3_inc(struct i2c_adapter *adapter)
286{
287        MOD_INC_USE_COUNT;
288}
289
290void voodoo3_dec(struct i2c_adapter *adapter)
291{
292        MOD_DEC_USE_COUNT;
293}
294
295int __init i2c_voodoo3_init(void)
296{
297        int res;
298        printk("i2c-voodoo3.o version %s (%s)\n", LM_VERSION, LM_DATE);
299        voodoo3_initialized = 0;
300        if ((res = voodoo3_setup())) {
301                printk
302                    ("i2c-voodoo3.o: Voodoo3 not detected, module not inserted.\n");
303                voodoo3_cleanup();
304                return res;
305        }
306        if ((res = i2c_bit_add_bus(&voodoo3_i2c_adapter))) {
307                printk("i2c-voodoo3.o: I2C adapter registration failed\n");
308        } else {
309                printk("i2c-voodoo3.o: I2C bus initialized\n");
310                voodoo3_initialized |= INIT2;
311        }
312/*
313        if ((res = i2c_bit_add_bus(&voodoo3_ddc_adapter))) {
314                printk("i2c-voodoo3.o: DDC adapter registration failed\n");
315        } else {
316                printk("i2c-voodoo3.o: DDC bus initialized\n");
317                voodoo3_initialized |= INIT3;
318        }
319*/
320        if(!(voodoo3_initialized & (INIT2 /* | INIT3 */ ))) {
321                printk("i2c-voodoo3.o: Both registrations failed, module not inserted\n");
322                voodoo3_cleanup();
323                return res;
324        }
325        return 0;
326}
327
328int __init voodoo3_cleanup(void)
329{
330        int res;
331
332        iounmap(mem);
333/*
334        if (voodoo3_initialized & INIT3) {
335                if ((res = i2c_bit_del_bus(&voodoo3_ddc_adapter))) {
336                        printk
337                            ("i2c-voodoo3.o: i2c_bit_del_bus failed, module not removed\n");
338                        return res;
339                }
340        }
341*/
342        if (voodoo3_initialized & INIT2) {
343                if ((res = i2c_bit_del_bus(&voodoo3_i2c_adapter))) {
344                        printk
345                            ("i2c-voodoo3.o: i2c_bit_del_bus failed, module not removed\n");
346                        return res;
347                }
348        }
349        return 0;
350}
351
352EXPORT_NO_SYMBOLS;
353
354#ifdef MODULE
355
356MODULE_AUTHOR
357    ("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, Ralph Metzler <rjkm@thp.uni-koeln.de>, and Mark D. Studebaker <mdsxyz123@yahoo.com>");
358MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver");
359
360
361int init_module(void)
362{
363        return i2c_voodoo3_init();
364}
365
366int cleanup_module(void)
367{
368        return voodoo3_cleanup();
369}
370
371#endif                          /* MODULE */
Note: See TracBrowser for help on using the browser.