| 1 | /* |
|---|
| 2 | isa.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 1998 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 "i2c.h" |
|---|
| 31 | #ifdef SPINLOCK |
|---|
| 32 | #include <asm/spinlock.h> |
|---|
| 33 | #else |
|---|
| 34 | #include <asm/semaphore.h> |
|---|
| 35 | #endif |
|---|
| 36 | |
|---|
| 37 | #include "version.h" |
|---|
| 38 | #include "isa.h" |
|---|
| 39 | |
|---|
| 40 | static int isa_master_xfer (struct isa_adapter *adap, |
|---|
| 41 | struct i2c_msg msgs[], int num); |
|---|
| 42 | static int isa_slave_send (struct isa_adapter *adap, char *data, int len); |
|---|
| 43 | static int isa_slave_recv (struct isa_adapter *adap, char *data, int len); |
|---|
| 44 | static int isa_algo_control (struct isa_adapter *adap, unsigned int cmd, |
|---|
| 45 | unsigned long arg); |
|---|
| 46 | static int isa_client_register (struct isa_client *client); |
|---|
| 47 | static int isa_client_unregister (struct isa_client *client); |
|---|
| 48 | |
|---|
| 49 | static int isa_init(void); |
|---|
| 50 | static int isa_cleanup(void); |
|---|
| 51 | |
|---|
| 52 | #ifdef MODULE |
|---|
| 53 | extern int init_module(void); |
|---|
| 54 | extern int cleanup_module(void); |
|---|
| 55 | #endif /* MODULE */ |
|---|
| 56 | |
|---|
| 57 | /* This is the actual algorithm we define */ |
|---|
| 58 | static struct isa_algorithm isa_algorithm = { |
|---|
| 59 | /* name */ "ISA bus adapter", |
|---|
| 60 | /* id */ ALGO_ISA, |
|---|
| 61 | /* master_xfer */ &isa_master_xfer, |
|---|
| 62 | /* slave_send */ &isa_slave_send, |
|---|
| 63 | /* slave_rcv */ &isa_slave_recv, |
|---|
| 64 | /* algo_control */ &isa_algo_control, |
|---|
| 65 | /* client_register */ &isa_client_register, |
|---|
| 66 | /* client_unregister*/&isa_client_unregister |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | /* There can only be one... */ |
|---|
| 70 | static struct isa_adapter isa_adapter; |
|---|
| 71 | |
|---|
| 72 | /* Used in isa_init/cleanup */ |
|---|
| 73 | static int isa_initialized; |
|---|
| 74 | |
|---|
| 75 | /* Algorithm master_xfer call-back implementation. Can't do that... */ |
|---|
| 76 | int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], |
|---|
| 77 | int num) |
|---|
| 78 | { |
|---|
| 79 | #ifdef DEBUG |
|---|
| 80 | printk("isa.o: isa_master_xfer called for adapter `%s' " |
|---|
| 81 | "(no i2c level access possible!)\n", |
|---|
| 82 | adap->name); |
|---|
| 83 | #endif |
|---|
| 84 | return -1; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /* Algorithm slave_send call-back implementation. Can't do that... */ |
|---|
| 88 | int isa_slave_send (struct isa_adapter *adap, char *data, int len) |
|---|
| 89 | { |
|---|
| 90 | #ifdef DEBUG |
|---|
| 91 | printk("isa.o: isa_slave_send called for adapter `%s' " |
|---|
| 92 | "(no i2c level access possible!)\n", |
|---|
| 93 | adap->name); |
|---|
| 94 | #endif |
|---|
| 95 | return -1; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | /* Algorithm slave_recv call-back implementation. Can't do that... */ |
|---|
| 99 | int isa_slave_recv (struct isa_adapter *adap, char *data, int len) |
|---|
| 100 | { |
|---|
| 101 | #ifdef DEBUG |
|---|
| 102 | printk("isa.o: isa_slave_recv called for adapter `%s' " |
|---|
| 103 | "(no i2c level access possible!)\n", |
|---|
| 104 | adap->name); |
|---|
| 105 | #endif |
|---|
| 106 | return -1; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /* Here we can put additional calls to modify the workings of the algorithm. |
|---|
| 110 | But right now, there is no need for that. */ |
|---|
| 111 | int isa_algo_control (struct isa_adapter *adap, unsigned int cmd, |
|---|
| 112 | unsigned long arg) |
|---|
| 113 | { |
|---|
| 114 | return 0; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /* Ehm... This is called when a client is registered to an adapter. We could |
|---|
| 118 | do all kinds of neat stuff here like, ehm - returning success? */ |
|---|
| 119 | int isa_client_register (struct isa_client *client) |
|---|
| 120 | { |
|---|
| 121 | return 0; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | int isa_client_unregister (struct isa_client *client) |
|---|
| 125 | { |
|---|
| 126 | return 0; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | int isa_init(void) |
|---|
| 130 | { |
|---|
| 131 | int res; |
|---|
| 132 | printk("isa.o version %s (%s)\n",LM_VERSION,LM_DATE); |
|---|
| 133 | #ifdef DEBUG |
|---|
| 134 | if (isa_initialized) { |
|---|
| 135 | printk("isa.o: Oops, isa_init called a second time!\n"); |
|---|
| 136 | return -EBUSY; |
|---|
| 137 | } |
|---|
| 138 | #endif |
|---|
| 139 | isa_initialized = 0; |
|---|
| 140 | if ((res = isa_add_algorithm(&isa_algorithm))) { |
|---|
| 141 | printk("isa.o: Algorithm registration failed, module not inserted.\n"); |
|---|
| 142 | isa_cleanup(); |
|---|
| 143 | return res; |
|---|
| 144 | } |
|---|
| 145 | isa_initialized++; |
|---|
| 146 | strcpy(isa_adapter.name,"ISA main adapter"); |
|---|
| 147 | isa_adapter.id = ALGO_ISA | ISA_MAIN; |
|---|
| 148 | isa_adapter.algo = &isa_algorithm; |
|---|
| 149 | if ((res = isa_add_adapter(&isa_adapter))) { |
|---|
| 150 | printk("isa.o: Adapter registration failed, " |
|---|
| 151 | "module isa.o is not inserted\n."); |
|---|
| 152 | isa_cleanup(); |
|---|
| 153 | return res; |
|---|
| 154 | } |
|---|
| 155 | isa_initialized++; |
|---|
| 156 | printk("isa.o: ISA bus access for i2c modules initialized.\n"); |
|---|
| 157 | return 0; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | int isa_cleanup(void) |
|---|
| 161 | { |
|---|
| 162 | int res; |
|---|
| 163 | if (isa_initialized >= 2) |
|---|
| 164 | { |
|---|
| 165 | if ((res = isa_del_adapter(&isa_adapter))) { |
|---|
| 166 | printk("isa.o: Adapter deregistration failed, module not removed.\n"); |
|---|
| 167 | return res; |
|---|
| 168 | } else |
|---|
| 169 | isa_initialized--; |
|---|
| 170 | } |
|---|
| 171 | if (isa_initialized >= 1) |
|---|
| 172 | { |
|---|
| 173 | if ((res = isa_del_algorithm(&isa_algorithm))) { |
|---|
| 174 | printk("isa.o: Algorithm deregistration failed, module not removed.\n"); |
|---|
| 175 | return res; |
|---|
| 176 | } else |
|---|
| 177 | isa_initialized--; |
|---|
| 178 | } |
|---|
| 179 | return 0; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | #ifdef MODULE |
|---|
| 183 | |
|---|
| 184 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); |
|---|
| 185 | MODULE_DESCRIPTION("ISA bus access through i2c"); |
|---|
| 186 | |
|---|
| 187 | int init_module(void) |
|---|
| 188 | { |
|---|
| 189 | return isa_init(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | int cleanup_module(void) |
|---|
| 193 | { |
|---|
| 194 | return isa_cleanup(); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | #endif /* MODULE */ |
|---|
| 198 | |
|---|