| 1 | /* |
|---|
| 2 | i2c-isa.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | /* This implements an i2c algorithm/adapter for ISA bus. Not that this is |
|---|
| 22 | on first sight very useful; almost no functionality is preserved. |
|---|
| 23 | Except that it makes writing drivers for chips which can be on both |
|---|
| 24 | the SMBus and the ISA bus very much easier. See lm78.c for an example |
|---|
| 25 | of this. */ |
|---|
| 26 | |
|---|
| 27 | #include <linux/module.h> |
|---|
| 28 | #include <linux/kernel.h> |
|---|
| 29 | |
|---|
| 30 | #include "compat.h" |
|---|
| 31 | |
|---|
| 32 | #include <linux/i2c.h> |
|---|
| 33 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,19) |
|---|
| 34 | #include <linux/sched.h> |
|---|
| 35 | #else |
|---|
| 36 | #include <asm/semaphore.h> |
|---|
| 37 | #endif |
|---|
| 38 | |
|---|
| 39 | #include "version.h" |
|---|
| 40 | #include "i2c-isa.h" |
|---|
| 41 | |
|---|
| 42 | static int isa_master_xfer (struct isa_adapter *adap, |
|---|
| 43 | struct i2c_msg msgs[], int num); |
|---|
| 44 | static int isa_slave_send (struct isa_adapter *adap, char *data, int len); |
|---|
| 45 | static int isa_slave_recv (struct isa_adapter *adap, char *data, int len); |
|---|
| 46 | static int isa_algo_control (struct isa_adapter *adap, unsigned int cmd, |
|---|
| 47 | unsigned long arg); |
|---|
| 48 | static int isa_client_register (struct isa_client *client); |
|---|
| 49 | static int isa_client_unregister (struct isa_client *client); |
|---|
| 50 | |
|---|
| 51 | static int isa_init(void); |
|---|
| 52 | static int isa_cleanup(void); |
|---|
| 53 | |
|---|
| 54 | #ifdef MODULE |
|---|
| 55 | extern int init_module(void); |
|---|
| 56 | extern int cleanup_module(void); |
|---|
| 57 | #endif /* MODULE */ |
|---|
| 58 | |
|---|
| 59 | /* This is the actual algorithm we define */ |
|---|
| 60 | static struct isa_algorithm isa_algorithm = { |
|---|
| 61 | /* name */ "ISA bus adapter", |
|---|
| 62 | /* id */ ALGO_ISA, |
|---|
| 63 | /* master_xfer */ &isa_master_xfer, |
|---|
| 64 | /* slave_send */ &isa_slave_send, |
|---|
| 65 | /* slave_rcv */ &isa_slave_recv, |
|---|
| 66 | /* algo_control */ &isa_algo_control, |
|---|
| 67 | /* client_register */ &isa_client_register, |
|---|
| 68 | /* client_unregister*/&isa_client_unregister |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | /* There can only be one... */ |
|---|
| 72 | static struct isa_adapter isa_adapter; |
|---|
| 73 | |
|---|
| 74 | /* Used in isa_init/cleanup */ |
|---|
| 75 | static int isa_initialized; |
|---|
| 76 | |
|---|
| 77 | /* Algorithm master_xfer call-back implementation. Can't do that... */ |
|---|
| 78 | int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], |
|---|
| 79 | int num) |
|---|
| 80 | { |
|---|
| 81 | #ifdef DEBUG |
|---|
| 82 | printk("i2c-isa.o: isa_master_xfer called for adapter `%s' " |
|---|
| 83 | "(no i2c level access possible!)\n", |
|---|
| 84 | adap->name); |
|---|
| 85 | #endif |
|---|
| 86 | return -1; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /* Algorithm slave_send call-back implementation. Can't do that... */ |
|---|
| 90 | int isa_slave_send (struct isa_adapter *adap, char *data, int len) |
|---|
| 91 | { |
|---|
| 92 | #ifdef DEBUG |
|---|
| 93 | printk("i2c-isa.o: isa_slave_send called for adapter `%s' " |
|---|
| 94 | "(no i2c level access possible!)\n", |
|---|
| 95 | adap->name); |
|---|
| 96 | #endif |
|---|
| 97 | return -1; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /* Algorithm slave_recv call-back implementation. Can't do that... */ |
|---|
| 101 | int isa_slave_recv (struct isa_adapter *adap, char *data, int len) |
|---|
| 102 | { |
|---|
| 103 | #ifdef DEBUG |
|---|
| 104 | printk("i2c-isa.o: isa_slave_recv called for adapter `%s' " |
|---|
| 105 | "(no i2c level access possible!)\n", |
|---|
| 106 | adap->name); |
|---|
| 107 | #endif |
|---|
| 108 | return -1; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /* Here we can put additional calls to modify the workings of the algorithm. |
|---|
| 112 | But right now, there is no need for that. */ |
|---|
| 113 | int isa_algo_control (struct isa_adapter *adap, unsigned int cmd, |
|---|
| 114 | unsigned long arg) |
|---|
| 115 | { |
|---|
| 116 | return 0; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /* Ehm... This is called when a client is registered to an adapter. We could |
|---|
| 120 | do all kinds of neat stuff here like, ehm - returning success? */ |
|---|
| 121 | int isa_client_register (struct isa_client *client) |
|---|
| 122 | { |
|---|
| 123 | return 0; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | int isa_client_unregister (struct isa_client *client) |
|---|
| 127 | { |
|---|
| 128 | return 0; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | int isa_init(void) |
|---|
| 132 | { |
|---|
| 133 | int res; |
|---|
| 134 | printk("isa.o version %s (%s)\n",LM_VERSION,LM_DATE); |
|---|
| 135 | #ifdef DEBUG |
|---|
| 136 | if (isa_initialized) { |
|---|
| 137 | printk("i2c-isa.o: Oops, isa_init called a second time!\n"); |
|---|
| 138 | return -EBUSY; |
|---|
| 139 | } |
|---|
| 140 | #endif |
|---|
| 141 | isa_initialized = 0; |
|---|
| 142 | if ((res = isa_add_algorithm(&isa_algorithm))) { |
|---|
| 143 | printk("i2c-isa.o: Algorithm registration failed, module not inserted.\n"); |
|---|
| 144 | isa_cleanup(); |
|---|
| 145 | return res; |
|---|
| 146 | } |
|---|
| 147 | isa_initialized++; |
|---|
| 148 | strcpy(isa_adapter.name,"ISA main adapter"); |
|---|
| 149 | isa_adapter.id = ALGO_ISA | ISA_MAIN; |
|---|
| 150 | isa_adapter.algo = &isa_algorithm; |
|---|
| 151 | if ((res = isa_add_adapter(&isa_adapter))) { |
|---|
| 152 | printk("i2c-isa.o: Adapter registration failed, " |
|---|
| 153 | "module isa.o is not inserted\n."); |
|---|
| 154 | isa_cleanup(); |
|---|
| 155 | return res; |
|---|
| 156 | } |
|---|
| 157 | isa_initialized++; |
|---|
| 158 | printk("i2c-isa.o: ISA bus access for i2c modules initialized.\n"); |
|---|
| 159 | return 0; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | int isa_cleanup(void) |
|---|
| 163 | { |
|---|
| 164 | int res; |
|---|
| 165 | if (isa_initialized >= 2) |
|---|
| 166 | { |
|---|
| 167 | if ((res = isa_del_adapter(&isa_adapter))) { |
|---|
| 168 | printk("i2c-isa.o: Adapter deregistration failed, module not removed.\n"); |
|---|
| 169 | return res; |
|---|
| 170 | } else |
|---|
| 171 | isa_initialized--; |
|---|
| 172 | } |
|---|
| 173 | if (isa_initialized >= 1) |
|---|
| 174 | { |
|---|
| 175 | if ((res = isa_del_algorithm(&isa_algorithm))) { |
|---|
| 176 | printk("i2c-isa.o: Algorithm deregistration failed, module not removed.\n"); |
|---|
| 177 | return res; |
|---|
| 178 | } else |
|---|
| 179 | isa_initialized--; |
|---|
| 180 | } |
|---|
| 181 | return 0; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | #ifdef MODULE |
|---|
| 185 | |
|---|
| 186 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); |
|---|
| 187 | MODULE_DESCRIPTION("ISA bus access through i2c"); |
|---|
| 188 | |
|---|
| 189 | int init_module(void) |
|---|
| 190 | { |
|---|
| 191 | return isa_init(); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | int cleanup_module(void) |
|---|
| 195 | { |
|---|
| 196 | return isa_cleanup(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | #endif /* MODULE */ |
|---|
| 200 | |
|---|