root/lm-sensors/trunk/kernel/busses/i2c-i801.c @ 990

Revision 990, 18.7 KB (checked in by mds, 12 years ago)

add correct ifdef'ed declaration of i2c_i801_init() to remove

external symbol.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    i801.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>, and Mark D. Studebaker
6    <mdsxyz123@yahoo.com>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23/*
24    This driver supports the Intel 82801AA, 82801AB, and 82801BA
25    I/O Controller Hubs (ICH). They are similar to the PIIX4 and are part
26    of Intel's '810' and other chipsets.
27    See the doc/busses/i2c-i801 file for details.
28*/
29
30/* Note: we assume there can only be one I801, with one SMBus interface */
31
32#include <linux/version.h>
33#include <linux/module.h>
34#include <linux/pci.h>
35#include <asm/io.h>
36#include <linux/kernel.h>
37#include <linux/stddef.h>
38#include <linux/sched.h>
39#include <linux/ioport.h>
40#include <linux/init.h>
41#include <linux/i2c.h>
42#include "version.h"
43
44#ifndef PCI_DEVICE_ID_INTEL_82801AA_3
45#define PCI_DEVICE_ID_INTEL_82801AA_3   0x2413
46#endif
47#ifndef PCI_DEVICE_ID_INTEL_82801AB_3
48#define PCI_DEVICE_ID_INTEL_82801AB_3   0x2423
49#endif
50#ifndef PCI_DEVICE_ID_INTEL_82801BA_3
51#define PCI_DEVICE_ID_INTEL_82801BA_3   0x2443
52#endif
53
54/* I801 SMBus address offsets */
55#define SMBHSTSTS (0 + i801_smba)
56#define SMBHSTCNT (2 + i801_smba)
57#define SMBHSTCMD (3 + i801_smba)
58#define SMBHSTADD (4 + i801_smba)
59#define SMBHSTDAT0 (5 + i801_smba)
60#define SMBHSTDAT1 (6 + i801_smba)
61#define SMBBLKDAT (7 + i801_smba)
62
63/* PCI Address Constants */
64#define SMBBA     0x020
65#define SMBHSTCFG 0x040
66#define SMBREV    0x008
67
68/* Host configuration bits for SMBHSTCFG */
69#define SMBHSTCFG_HST_EN      1
70#define SMBHSTCFG_SMB_SMI_EN  2
71#define SMBHSTCFG_I2C_EN      4
72
73/* Other settings */
74#define MAX_TIMEOUT 500
75#define  ENABLE_INT9 0
76
77/* I801 command constants */
78#define I801_QUICK          0x00
79#define I801_BYTE           0x04
80#define I801_BYTE_DATA      0x08
81#define I801_WORD_DATA      0x0C
82#define I801_BLOCK_DATA     0x14
83#define I801_I2C_BLOCK_DATA 0x18        /* unimplemented */
84#define I801_BLOCK_LAST     0x34
85#define I801_I2C_BLOCK_LAST 0x38        /* unimplemented */
86
87/* insmod parameters */
88
89/* If force is set to anything different from 0, we forcibly enable the
90   I801. DANGEROUS! */
91static int force = 0;
92MODULE_PARM(force, "i");
93MODULE_PARM_DESC(force, "Forcibly enable the I801. DANGEROUS!");
94
95/* If force_addr is set to anything different from 0, we forcibly enable
96   the I801 at the given address. VERY DANGEROUS! */
97static int force_addr = 0;
98MODULE_PARM(force_addr, "i");
99MODULE_PARM_DESC(force_addr,
100                 "Forcibly enable the I801 at the given address. "
101                 "EXTREMELY DANGEROUS!");
102
103#ifdef MODULE
104static
105#else
106extern
107#endif
108int __init i2c_i801_init(void);
109static int __init i801_cleanup(void);
110static int i801_setup(void);
111static s32 i801_access(struct i2c_adapter *adap, u16 addr,
112                       unsigned short flags, char read_write,
113                       u8 command, int size, union i2c_smbus_data *data);
114static void i801_do_pause(unsigned int amount);
115static int i801_transaction(void);
116static int i801_block_transaction(union i2c_smbus_data *data,
117                                  char read_write, int i2c_enable);
118static void i801_inc(struct i2c_adapter *adapter);
119static void i801_dec(struct i2c_adapter *adapter);
120static u32 i801_func(struct i2c_adapter *adapter);
121
122#ifdef MODULE
123extern int init_module(void);
124extern int cleanup_module(void);
125#endif                          /* MODULE */
126
127static struct i2c_algorithm smbus_algorithm = {
128        /* name */ "Non-I2C SMBus adapter",
129        /* id */ I2C_ALGO_SMBUS,
130        /* master_xfer */ NULL,
131        /* smbus_xfer */ i801_access,
132        /* slave_send */ NULL,
133        /* slave_rcv */ NULL,
134        /* algo_control */ NULL,
135        /* functionality */ i801_func,
136};
137
138static struct i2c_adapter i801_adapter = {
139        "unset",
140        I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801,
141        &smbus_algorithm,
142        NULL,
143        i801_inc,
144        i801_dec,
145        NULL,
146        NULL,
147};
148
149static int __initdata i801_initialized;
150static unsigned short i801_smba = 0;
151static struct pci_dev *I801_dev = NULL;
152
153
154/* Detect whether a I801 can be found, and initialize it, where necessary.
155   Note the differences between kernels with the old PCI BIOS interface and
156   newer kernels with the real PCI interface. In compat.h some things are
157   defined to make the transition easier. */
158int i801_setup(void)
159{
160        int error_return = 0;
161        unsigned char temp;
162
163        /* First check whether we can access PCI at all */
164        if (pci_present() == 0) {
165                printk("i2c-i801.o: Error: No PCI-bus found!\n");
166                error_return = -ENODEV;
167                goto END;
168        }
169
170        /* Look for the I801, function 3 */
171        /* Have to check for both the 82801AA and 82801AB */
172        /* Note: we keep on searching until we have found 'function 3' */
173        I801_dev = NULL;
174        do
175                I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
176                                           PCI_DEVICE_ID_INTEL_82801AA_3,
177                                           I801_dev);
178        while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
179        if (I801_dev == NULL) {
180                do
181                        I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
182                                           PCI_DEVICE_ID_INTEL_82801AB_3,
183                                           I801_dev);
184                while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
185        }
186        if (I801_dev == NULL) {
187                do
188                        I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
189                                           PCI_DEVICE_ID_INTEL_82801BA_3,
190                                           I801_dev);
191                while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
192        }
193        if (I801_dev == NULL) {
194                printk
195                    ("i2c-i801.o: Error: Can't detect I801, function 3!\n");
196                error_return = -ENODEV;
197                goto END;
198        }
199
200/* Determine the address of the SMBus areas */
201        if (force_addr) {
202                i801_smba = force_addr & 0xfff0;
203                force = 0;
204        } else {
205                pci_read_config_word(I801_dev, SMBBA, &i801_smba);
206                i801_smba &= 0xfff0;
207        }
208
209        if (check_region(i801_smba, 8)) {
210                printk
211                    ("i2c-i801.o: I801_smb region 0x%x already in use!\n",
212                     i801_smba);
213                error_return = -ENODEV;
214                goto END;
215        }
216
217        pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
218/* If force_addr is set, we program the new address here. Just to make
219   sure, we disable the I801 first. */
220        if (force_addr) {
221                pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe);
222                pci_write_config_word(I801_dev, SMBBA, i801_smba);
223                pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01);
224                printk
225                    ("i2c-i801.o: WARNING: I801 SMBus interface set to new "
226                     "address %04x!\n", i801_smba);
227        } else if ((temp & 1) == 0) {
228                if (force) {
229/* This should never need to be done, but has been noted that
230   many Dell machines have the SMBus interface on the PIIX4
231   disabled!? NOTE: This assumes I/O space and other allocations WERE
232   done by the Bios!  Don't complain if your hardware does weird
233   things after enabling this. :') Check for Bios updates before
234   resorting to this.  */
235                        pci_write_config_byte(I801_dev, SMBHSTCFG,
236                                              temp | 1);
237                        printk
238                            ("i2c-i801.o: WARNING: I801 SMBus interface has been FORCEFULLY "
239                             "ENABLED!\n");
240                } else {
241                        printk
242                            ("SMBUS: Error: Host SMBus controller not enabled!\n");
243                        error_return = -ENODEV;
244                        goto END;
245                }
246        }
247
248        /* note: we assumed that the BIOS picked SMBus or I2C Bus timing
249           appropriately (bit 2 in SMBHSTCFG) */
250        /* Everything is happy, let's grab the memory and set things up. */
251        request_region(i801_smba, 8, "i801-smbus");
252
253#ifdef DEBUG
254        if (temp & 0x02)
255                printk
256                    ("i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n");
257        else
258                printk
259                    ("i2c-i801.o: I801 using PCI Interrupt for SMBus.\n");
260
261        pci_read_config_byte(I801_dev, SMBREV, &temp);
262        printk("i2c-i801.o: SMBREV = 0x%X\n", temp);
263        printk("i2c-i801.o: I801_smba = 0x%X\n", i801_smba);
264#endif                          /* DEBUG */
265
266      END:
267        return error_return;
268}
269
270
271/* Internally used pause function */
272void i801_do_pause(unsigned int amount)
273{
274        current->state = TASK_INTERRUPTIBLE;
275        schedule_timeout(amount);
276}
277
278/* Another internally used function */
279int i801_transaction(void)
280{
281        int temp;
282        int result = 0;
283        int timeout = 0;
284
285#ifdef DEBUG
286        printk
287            ("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, "
288             "DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
289             inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
290#endif
291
292        /* Make sure the SMBus host is ready to start transmitting */
293        /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
294        if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
295#ifdef DEBUG
296                printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n",
297                       temp);
298#endif
299                outb_p(temp, SMBHSTSTS);
300                if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
301#ifdef DEBUG
302                        printk("i2c-i801.o: Failed! (%02x)\n", temp);
303#endif
304                        return -1;
305                } else {
306#ifdef DEBUG
307                        printk("i2c-i801.o: Successfull!\n");
308#endif
309                }
310        }
311
312        /* start the transaction by setting bit 6 */
313        outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
314
315        /* We will always wait for a fraction of a second! */
316        do {
317                i801_do_pause(1);
318                temp = inb_p(SMBHSTSTS);
319        } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
320
321        /* If the SMBus is still busy, we give up */
322        if (timeout >= MAX_TIMEOUT) {
323#ifdef DEBUG
324                printk("i2c-i801.o: SMBus Timeout!\n");
325                result = -1;
326#endif
327        }
328
329        if (temp & 0x10) {
330                result = -1;
331#ifdef DEBUG
332                printk("i2c-i801.o: Error: Failed bus transaction\n");
333#endif
334        }
335
336        if (temp & 0x08) {
337                result = -1;
338                printk
339                    ("i2c-i801.o: Bus collision! SMBus may be locked until next hard\n"
340                     "reset. (sorry!)\n");
341                /* Clock stops and slave is stuck in mid-transmission */
342        }
343
344        if (temp & 0x04) {
345                result = -1;
346#ifdef DEBUG
347                printk("i2c-i801.o: Error: no response!\n");
348#endif
349        }
350
351        if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00)
352                outb_p(inb(SMBHSTSTS), SMBHSTSTS);
353
354        if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
355#ifdef DEBUG
356                printk
357                    ("i2c-i801.o: Failed reset at end of transaction (%02x)\n",
358                     temp);
359#endif
360        }
361#ifdef DEBUG
362        printk
363            ("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, "
364             "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
365             inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
366#endif
367        return result;
368}
369
370/* All-inclusive block transaction function */
371int i801_block_transaction(union i2c_smbus_data *data, char read_write, 
372                           int i2c_enable)
373{
374        int i, len;
375        int smbcmd;
376        int temp;
377        int result = 0;
378        int timeout = 0;
379        unsigned char hostc, errmask;
380
381        if (i2c_enable) {
382                if (read_write == I2C_SMBUS_WRITE) {
383                        /* set I2C_EN bit in configuration register */
384                        pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc);
385                        pci_write_config_byte(I801_dev, SMBHSTCFG, 
386                                              hostc | SMBHSTCFG_I2C_EN);
387                } else {
388                        printk("i2c-i801.o: "
389                               "I2C_SMBUS_I2C_BLOCK_READ not supported!\n");
390                        return -1;
391                }
392        }
393
394        if (read_write == I2C_SMBUS_WRITE) {
395                len = data->block[0];
396                if (len < 1)
397                        len = 1;
398                if (len > 32)
399                        len = 32;
400                outb_p(len, SMBHSTDAT0);
401                outb_p(data->block[1], SMBBLKDAT);
402        } else {
403                len = 32;       /* max for reads */
404        }
405
406        for (i = 1; i <= len; i++) {
407                if (i == len && read_write == I2C_SMBUS_READ)
408                        smbcmd = I801_BLOCK_LAST;
409                else
410                        smbcmd = I801_BLOCK_DATA;
411
412                outb_p((smbcmd & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
413
414#ifdef DEBUG
415                printk
416                    ("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, "
417                     "DAT0=%02x, BLKDAT=%02x\n", inb_p(SMBHSTCNT),
418                     inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
419                     inb_p(SMBBLKDAT));
420#endif
421
422                /* Make sure the SMBus host is ready to start transmitting */
423                temp = inb_p(SMBHSTSTS);
424                if (i == 1) {
425                    /* Erronenous conditions before transaction:
426                     * Byte_Done, Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
427                    errmask=0x9f; 
428                } else {
429                    /* Erronenous conditions during transaction:
430                     * Failed, Bus_Err, Dev_Err, Intr */
431                    errmask=0x1e; 
432                }
433                if (temp & errmask) {
434#ifdef DEBUG
435                        printk
436                            ("i2c-i801.o: SMBus busy (%02x). Resetting... \n",
437                             temp);
438#endif
439                        outb_p(temp, SMBHSTSTS);
440                        if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
441                                printk
442                                    ("i2c-i801.o: Reset failed! (%02x)\n",
443                                     temp);
444                                result = -1;
445                                goto END;
446                        }
447                        if (i != 1) {
448                                result = -1;  /* if die in middle of block transaction, fail */
449                                goto END;
450                        }
451                }
452
453                /* start the transaction by setting bit 6 */
454                if (i==1) outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
455
456                /* We will always wait for a fraction of a second! */
457                do {
458                        temp = inb_p(SMBHSTSTS);
459                        i801_do_pause(1);
460                }
461                    while (
462                           (((i >= len) && (temp & 0x01))
463                            || ((i < len) && !(temp & 0x80)))
464                           && (timeout++ < MAX_TIMEOUT));
465
466                /* If the SMBus is still busy, we give up */
467                if (timeout >= MAX_TIMEOUT) {
468                        result = -1;
469#ifdef DEBUG
470                        printk("i2c-i801.o: SMBus Timeout!\n");
471#endif
472                }
473
474                if (temp & 0x10) {
475                        result = -1;
476#ifdef DEBUG
477                        printk
478                            ("i2c-i801.o: Error: Failed bus transaction\n");
479#endif
480                } else if (temp & 0x08) {
481                        result = -1;
482                        printk
483                            ("i2c-i801.o: Bus collision! SMBus may be locked until next hard"
484                             " reset. (sorry!)\n");
485                        /* Clock stops and slave is stuck in mid-transmission */
486                } else if (temp & 0x04) {
487                        result = -1;
488#ifdef DEBUG
489                        printk("i2c-i801.o: Error: no response!\n");
490#endif
491                }
492
493                if (i == 1 && read_write == I2C_SMBUS_READ) {
494                        len = inb_p(SMBHSTDAT0);
495                        if (len < 1)
496                                len = 1;
497                        if (len > 32)
498                                len = 32;
499                        data->block[0] = len;
500                }
501
502                /* Retrieve/store value in SMBBLKDAT */
503                if (read_write == I2C_SMBUS_READ)
504                        data->block[i] = inb_p(SMBBLKDAT);
505                if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
506                        outb_p(data->block[i+1], SMBBLKDAT);
507                if ((temp & 0x9e) != 0x00)
508                        outb_p(temp, SMBHSTSTS);  /* signals SMBBLKDAT ready */
509
510                temp = inb_p(SMBHSTSTS);
511                if ((temp = (0x1e & inb_p(SMBHSTSTS))) != 0x00) {
512#ifdef DEBUG
513                        printk
514                            ("i2c-i801.o: Failed reset at end of transaction (%02x)\n",
515                             temp);
516#endif
517                }
518#ifdef DEBUG
519                printk
520                    ("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, "
521                     "DAT0=%02x, BLKDAT=%02x\n", inb_p(SMBHSTCNT),
522                     inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
523                     inb_p(SMBBLKDAT));
524#endif
525
526                if (result < 0) {
527                        goto END;
528                }
529        }
530        result = 0;
531END:
532        if (i2c_enable) {
533                /* restore saved configuration register value */
534                pci_write_config_byte(I801_dev, SMBHSTCFG, hostc);
535        }
536        return result;
537}
538
539/* Return -1 on error. See smbus.h for more information */
540s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
541                char read_write, u8 command, int size,
542                union i2c_smbus_data * data)
543{
544
545        switch (size) {
546        case I2C_SMBUS_PROC_CALL:
547                printk("i2c-i801.o: I2C_SMBUS_PROC_CALL not supported!\n");
548                return -1;
549        case I2C_SMBUS_QUICK:
550                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
551                       SMBHSTADD);
552                size = I801_QUICK;
553                break;
554        case I2C_SMBUS_BYTE:
555                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
556                       SMBHSTADD);
557                if (read_write == I2C_SMBUS_WRITE)
558                        outb_p(command, SMBHSTCMD);
559                size = I801_BYTE;
560                break;
561        case I2C_SMBUS_BYTE_DATA:
562                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
563                       SMBHSTADD);
564                outb_p(command, SMBHSTCMD);
565                if (read_write == I2C_SMBUS_WRITE)
566                        outb_p(data->byte, SMBHSTDAT0);
567                size = I801_BYTE_DATA;
568                break;
569        case I2C_SMBUS_WORD_DATA:
570                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
571                       SMBHSTADD);
572                outb_p(command, SMBHSTCMD);
573                if (read_write == I2C_SMBUS_WRITE) {
574                        outb_p(data->word & 0xff, SMBHSTDAT0);
575                        outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
576                }
577                size = I801_WORD_DATA;
578                break;
579        case I2C_SMBUS_BLOCK_DATA:
580        case I2C_SMBUS_I2C_BLOCK_DATA:
581                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
582                       SMBHSTADD);
583                outb_p(command, SMBHSTCMD);
584                /* Block transactions are very different from piix4 block
585                   and from the other i801 transactions. Handle in the
586                   i801_block_transaction() routine. */
587                return i801_block_transaction(data, read_write, 
588                                              size==I2C_SMBUS_I2C_BLOCK_DATA);
589        }
590
591        /* 'size' is really the transaction type */
592        outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
593
594        if (i801_transaction()) /* Error in transaction */
595                return -1;
596
597        if ((read_write == I2C_SMBUS_WRITE) || (size == I801_QUICK))
598                return 0;
599
600
601        switch (size) {
602        case I801_BYTE: /* Result put in SMBHSTDAT0 */
603                data->byte = inb_p(SMBHSTDAT0);
604                break;
605        case I801_BYTE_DATA:
606                data->byte = inb_p(SMBHSTDAT0);
607                break;
608        case I801_WORD_DATA:
609                data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
610                break;
611        }
612        return 0;
613}
614
615void i801_inc(struct i2c_adapter *adapter)
616{
617        MOD_INC_USE_COUNT;
618}
619
620void i801_dec(struct i2c_adapter *adapter)
621{
622        MOD_DEC_USE_COUNT;
623}
624
625u32 i801_func(struct i2c_adapter *adapter)
626{
627        return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
628            I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
629            I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK;
630}
631
632int __init i2c_i801_init(void)
633{
634        int res;
635        printk("i2c-i801.o version %s (%s)\n", LM_VERSION, LM_DATE);
636#ifdef DEBUG
637/* PE- It might be good to make this a permanent part of the code! */
638        if (i801_initialized) {
639                printk
640                    ("i2c-i801.o: Oops, i801_init called a second time!\n");
641                return -EBUSY;
642        }
643#endif
644        i801_initialized = 0;
645        if ((res = i801_setup())) {
646                printk
647                    ("i2c-i801.o: I801 not detected, module not inserted.\n");
648                i801_cleanup();
649                return res;
650        }
651        i801_initialized++;
652        sprintf(i801_adapter.name, "SMBus I801 adapter at %04x",
653                i801_smba);
654        if ((res = i2c_add_adapter(&i801_adapter))) {
655                printk
656                    ("i2c-i801.o: Adapter registration failed, module not inserted.\n");
657                i801_cleanup();
658                return res;
659        }
660        i801_initialized++;
661        printk("i2c-i801.o: I801 bus detected and initialized\n");
662        return 0;
663}
664
665int __init i801_cleanup(void)
666{
667        int res;
668        if (i801_initialized >= 2) {
669                if ((res = i2c_del_adapter(&i801_adapter))) {
670                        printk
671                            ("i2c-i801.o: i2c_del_adapter failed, module not removed\n");
672                        return res;
673                } else
674                        i801_initialized--;
675        }
676        if (i801_initialized >= 1) {
677                release_region(i801_smba, 8);
678                i801_initialized--;
679        }
680        return 0;
681}
682
683EXPORT_NO_SYMBOLS;
684
685#ifdef MODULE
686
687MODULE_AUTHOR
688    ("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>");
689MODULE_DESCRIPTION("I801 SMBus driver");
690
691int init_module(void)
692{
693        return i2c_i801_init();
694}
695
696int cleanup_module(void)
697{
698        return i801_cleanup();
699}
700
701#endif                          /* MODULE */
Note: See TracBrowser for help on using the browser.