| 1 | /* |
|---|
| 2 | smbus.c - A Linux module for reading sensor data. |
|---|
| 3 | Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl> |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | #include <linux/module.h> |
|---|
| 21 | #include <linux/kernel.h> |
|---|
| 22 | #include "smbus.h" |
|---|
| 23 | #include "version.h" |
|---|
| 24 | |
|---|
| 25 | static int piix4_init(void); |
|---|
| 26 | static int piix4_cleanup(void); |
|---|
| 27 | static int piix4_setup(void); |
|---|
| 28 | static s32 piix4_access(u8 addr, char read_write, |
|---|
| 29 | u8 command, int size, union smbus_data * data); |
|---|
| 30 | |
|---|
| 31 | #ifdef MODULE |
|---|
| 32 | extern int init_module(void); |
|---|
| 33 | extern int cleanup_module(void); |
|---|
| 34 | #endif /* MODULE */ |
|---|
| 35 | |
|---|
| 36 | static struct smbus_adapter piix4_adapter; |
|---|
| 37 | static int piix4_initialized; |
|---|
| 38 | |
|---|
| 39 | /* Detect whether a PIIX4 can be found, and initialize it, where necessary. |
|---|
| 40 | Return -ENODEV if not found. */ |
|---|
| 41 | int piix4_setup(void) |
|---|
| 42 | { |
|---|
| 43 | return -ENODEV; |
|---|
| 44 | /* TO BE WRITTEN! */ |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /* Return -1 on error. See smbus.h for more information */ |
|---|
| 48 | s32 piix4_access(u8 addr, char read_write, |
|---|
| 49 | u8 command, int size, union smbus_data * data) |
|---|
| 50 | { |
|---|
| 51 | /* TO BE WRITTEN! */ |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | int piix4_init(void) |
|---|
| 56 | { |
|---|
| 57 | int res; |
|---|
| 58 | printk("piix4.o version %s (%s)\n",LM_VERSION,LM_DATE); |
|---|
| 59 | #ifdef DEBUG |
|---|
| 60 | if (piix4_initialized) { |
|---|
| 61 | printk("piix4.o: Oops, piix4_init called a second time!\n"); |
|---|
| 62 | return -EBUSY; |
|---|
| 63 | } |
|---|
| 64 | #endif |
|---|
| 65 | piix4_initialized = 0; |
|---|
| 66 | if ((res = piix4_setup())) { |
|---|
| 67 | printk("piix4.o: PIIX4 not detected, module not inserted\n"); |
|---|
| 68 | piix4_cleanup(); |
|---|
| 69 | return res; |
|---|
| 70 | } |
|---|
| 71 | piix4_initialized ++; |
|---|
| 72 | strcpy(piix4_adapter.name,"SMBus PIIX4 adapter"); |
|---|
| 73 | piix4_adapter.id = ALGO_SMBUS | SMBUS_PIIX4; |
|---|
| 74 | piix4_adapter.algo = &smbus_algorithm; |
|---|
| 75 | piix4_adapter.smbus_access = &piix4_access; |
|---|
| 76 | if ((res = smbus_add_adapter(&piix4_adapter))) { |
|---|
| 77 | printk("piix4.o: smbus_add_adapter failed, module not inserted\n"); |
|---|
| 78 | piix4_cleanup(); |
|---|
| 79 | return res; |
|---|
| 80 | } |
|---|
| 81 | piix4_initialized++; |
|---|
| 82 | printk("piix4.o: PIIX4 bus detected and initialized\n"); |
|---|
| 83 | return 0; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int piix4_cleanup(void) |
|---|
| 87 | { |
|---|
| 88 | int res; |
|---|
| 89 | if (piix4_initialized >= 2) |
|---|
| 90 | { |
|---|
| 91 | if ((res = smbus_del_adapter(&piix4_adapter))) { |
|---|
| 92 | printk("piix4.o: smbus_del_adapter failed, module not removed"); |
|---|
| 93 | return res; |
|---|
| 94 | } |
|---|
| 95 | else |
|---|
| 96 | piix4_initialized--; |
|---|
| 97 | } |
|---|
| 98 | if (piix4_initialized >= 1) { |
|---|
| 99 | /* Undo anything piix4_setup did */ |
|---|
| 100 | piix4_initialized--; |
|---|
| 101 | } |
|---|
| 102 | return 0; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | #ifdef MODULE |
|---|
| 106 | |
|---|
| 107 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); |
|---|
| 108 | MODULE_DESCRIPTION("PIIX4 SMBus driver"); |
|---|
| 109 | |
|---|
| 110 | int init_module(void) |
|---|
| 111 | { |
|---|
| 112 | return piix4_init(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | int cleanup_module(void) |
|---|
| 116 | { |
|---|
| 117 | return piix4_cleanup(); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | #endif /* MODULE */ |
|---|
| 121 | |
|---|