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

Revision 1201, 18.8 KB (checked in by mds, 12 years ago)

Add MODULE_LICENSE("GPL") to all modules

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