| 1 | /* |
|---|
| 2 | eeprom.c - Part of lm_sensors, Linux kernel modules for hardware |
|---|
| 3 | monitoring |
|---|
| 4 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and |
|---|
| 5 | Philip Edelbrock <phil@netroedge.com> |
|---|
| 6 | |
|---|
| 7 | This program is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | This program is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with this program; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include <linux/module.h> |
|---|
| 23 | #include <linux/version.h> |
|---|
| 24 | #include <linux/slab.h> |
|---|
| 25 | #include <linux/i2c.h> |
|---|
| 26 | #include "sensors.h" |
|---|
| 27 | #include "version.h" |
|---|
| 28 | #include <linux/init.h> |
|---|
| 29 | |
|---|
| 30 | #ifdef MODULE_LICENSE |
|---|
| 31 | MODULE_LICENSE("GPL"); |
|---|
| 32 | #endif |
|---|
| 33 | |
|---|
| 34 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)) || \ |
|---|
| 35 | (LINUX_VERSION_CODE == KERNEL_VERSION(2,3,0)) |
|---|
| 36 | #define init_MUTEX(s) do { *(s) = MUTEX; } while(0) |
|---|
| 37 | #endif |
|---|
| 38 | |
|---|
| 39 | #ifndef THIS_MODULE |
|---|
| 40 | #define THIS_MODULE NULL |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | /* Addresses to scan */ |
|---|
| 44 | static unsigned short normal_i2c[] = { SENSORS_I2C_END }; |
|---|
| 45 | static unsigned short normal_i2c_range[] = { 0x50, 0x57, SENSORS_I2C_END }; |
|---|
| 46 | static unsigned int normal_isa[] = { SENSORS_ISA_END }; |
|---|
| 47 | static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; |
|---|
| 48 | |
|---|
| 49 | /* Insmod parameters */ |
|---|
| 50 | SENSORS_INSMOD_1(eeprom); |
|---|
| 51 | |
|---|
| 52 | static int checksum = 0; |
|---|
| 53 | MODULE_PARM(checksum, "i"); |
|---|
| 54 | MODULE_PARM_DESC(checksum, |
|---|
| 55 | "Only accept eeproms whose checksum is correct"); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | /* Many constants specified below */ |
|---|
| 59 | |
|---|
| 60 | /* EEPROM registers */ |
|---|
| 61 | #define EEPROM_REG_CHECKSUM 0x3f |
|---|
| 62 | |
|---|
| 63 | /* EEPROM memory types: */ |
|---|
| 64 | #define ONE_K 1 |
|---|
| 65 | #define TWO_K 2 |
|---|
| 66 | #define FOUR_K 3 |
|---|
| 67 | #define EIGHT_K 4 |
|---|
| 68 | #define SIXTEEN_K 5 |
|---|
| 69 | |
|---|
| 70 | /* Conversions */ |
|---|
| 71 | /* Size of EEPROM in bytes */ |
|---|
| 72 | #define EEPROM_SIZE 256 |
|---|
| 73 | |
|---|
| 74 | /* Each client has this additional data */ |
|---|
| 75 | struct eeprom_data { |
|---|
| 76 | int sysctl_id; |
|---|
| 77 | |
|---|
| 78 | struct semaphore update_lock; |
|---|
| 79 | char valid; /* !=0 if following fields are valid */ |
|---|
| 80 | unsigned long last_updated; /* In jiffies */ |
|---|
| 81 | |
|---|
| 82 | u8 data[EEPROM_SIZE]; /* Register values */ |
|---|
| 83 | #if 0 |
|---|
| 84 | int memtype; |
|---|
| 85 | #endif |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | #ifdef MODULE |
|---|
| 89 | extern int init_module(void); |
|---|
| 90 | extern int cleanup_module(void); |
|---|
| 91 | #endif /* MODULE */ |
|---|
| 92 | |
|---|
| 93 | #ifdef MODULE |
|---|
| 94 | static |
|---|
| 95 | #else |
|---|
| 96 | extern |
|---|
| 97 | #endif |
|---|
| 98 | int __init sensors_eeprom_init(void); |
|---|
| 99 | static int __init eeprom_cleanup(void); |
|---|
| 100 | |
|---|
| 101 | static int eeprom_attach_adapter(struct i2c_adapter *adapter); |
|---|
| 102 | static int eeprom_detect(struct i2c_adapter *adapter, int address, |
|---|
| 103 | unsigned short flags, int kind); |
|---|
| 104 | static int eeprom_detach_client(struct i2c_client *client); |
|---|
| 105 | static int eeprom_command(struct i2c_client *client, unsigned int cmd, |
|---|
| 106 | void *arg); |
|---|
| 107 | |
|---|
| 108 | static void eeprom_inc_use(struct i2c_client *client); |
|---|
| 109 | static void eeprom_dec_use(struct i2c_client *client); |
|---|
| 110 | |
|---|
| 111 | #if 0 |
|---|
| 112 | static int eeprom_write_value(struct i2c_client *client, u8 reg, |
|---|
| 113 | u8 value); |
|---|
| 114 | #endif |
|---|
| 115 | |
|---|
| 116 | static void eeprom_contents(struct i2c_client *client, int operation, |
|---|
| 117 | int ctl_name, int *nrels_mag, long *results); |
|---|
| 118 | static void eeprom_update_client(struct i2c_client *client); |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | /* This is the driver that will be inserted */ |
|---|
| 122 | static struct i2c_driver eeprom_driver = { |
|---|
| 123 | /* name */ "EEPROM READER", |
|---|
| 124 | /* id */ I2C_DRIVERID_EEPROM, |
|---|
| 125 | /* flags */ I2C_DF_NOTIFY, |
|---|
| 126 | /* attach_adapter */ &eeprom_attach_adapter, |
|---|
| 127 | /* detach_client */ &eeprom_detach_client, |
|---|
| 128 | /* command */ &eeprom_command, |
|---|
| 129 | /* inc_use */ &eeprom_inc_use, |
|---|
| 130 | /* dec_use */ &eeprom_dec_use |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | /* These files are created for each detected EEPROM. This is just a template; |
|---|
| 134 | though at first sight, you might think we could use a statically |
|---|
| 135 | allocated list, we need some way to get back to the parent - which |
|---|
| 136 | is done through one of the 'extra' fields which are initialized |
|---|
| 137 | when a new copy is allocated. */ |
|---|
| 138 | static ctl_table eeprom_dir_table_template[] = { |
|---|
| 139 | {EEPROM_SYSCTL1, "00", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 140 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 141 | {EEPROM_SYSCTL2, "10", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 142 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 143 | {EEPROM_SYSCTL3, "20", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 144 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 145 | {EEPROM_SYSCTL4, "30", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 146 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 147 | {EEPROM_SYSCTL5, "40", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 148 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 149 | {EEPROM_SYSCTL6, "50", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 150 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 151 | {EEPROM_SYSCTL7, "60", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 152 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 153 | {EEPROM_SYSCTL8, "70", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 154 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 155 | {EEPROM_SYSCTL9, "80", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 156 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 157 | {EEPROM_SYSCTL10, "90", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 158 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 159 | {EEPROM_SYSCTL11, "a0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 160 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 161 | {EEPROM_SYSCTL12, "b0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 162 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 163 | {EEPROM_SYSCTL13, "c0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 164 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 165 | {EEPROM_SYSCTL14, "d0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 166 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 167 | {EEPROM_SYSCTL15, "e0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 168 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 169 | {EEPROM_SYSCTL16, "f0", NULL, 0, 0444, NULL, &i2c_proc_real, |
|---|
| 170 | &i2c_sysctl_real, NULL, &eeprom_contents}, |
|---|
| 171 | {0} |
|---|
| 172 | }; |
|---|
| 173 | |
|---|
| 174 | /* Used by init/cleanup */ |
|---|
| 175 | static int __initdata eeprom_initialized = 0; |
|---|
| 176 | |
|---|
| 177 | static int eeprom_id = 0; |
|---|
| 178 | |
|---|
| 179 | int eeprom_attach_adapter(struct i2c_adapter *adapter) |
|---|
| 180 | { |
|---|
| 181 | return i2c_detect(adapter, &addr_data, eeprom_detect); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | /* This function is called by i2c_detect */ |
|---|
| 185 | int eeprom_detect(struct i2c_adapter *adapter, int address, |
|---|
| 186 | unsigned short flags, int kind) |
|---|
| 187 | { |
|---|
| 188 | int i, cs; |
|---|
| 189 | struct i2c_client *new_client; |
|---|
| 190 | struct eeprom_data *data; |
|---|
| 191 | int err = 0; |
|---|
| 192 | const char *type_name, *client_name; |
|---|
| 193 | |
|---|
| 194 | /* Make sure we aren't probing the ISA bus!! This is just a safety check |
|---|
| 195 | at this moment; i2c_detect really won't call us. */ |
|---|
| 196 | #ifdef DEBUG |
|---|
| 197 | if (i2c_is_isa_adapter(adapter)) { |
|---|
| 198 | printk |
|---|
| 199 | ("eeprom.o: eeprom_detect called for an ISA bus adapter?!?\n"); |
|---|
| 200 | return 0; |
|---|
| 201 | } |
|---|
| 202 | #endif |
|---|
| 203 | |
|---|
| 204 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
|---|
| 205 | goto ERROR0; |
|---|
| 206 | |
|---|
| 207 | /* OK. For now, we presume we have a valid client. We now create the |
|---|
| 208 | client structure, even though we cannot fill it completely yet. |
|---|
| 209 | But it allows us to access eeprom_{read,write}_value. */ |
|---|
| 210 | if (!(new_client = kmalloc(sizeof(struct i2c_client) + |
|---|
| 211 | sizeof(struct eeprom_data), |
|---|
| 212 | GFP_KERNEL))) { |
|---|
| 213 | err = -ENOMEM; |
|---|
| 214 | goto ERROR0; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | data = (struct eeprom_data *) (new_client + 1); |
|---|
| 218 | new_client->addr = address; |
|---|
| 219 | new_client->data = data; |
|---|
| 220 | new_client->adapter = adapter; |
|---|
| 221 | new_client->driver = &eeprom_driver; |
|---|
| 222 | new_client->flags = 0; |
|---|
| 223 | |
|---|
| 224 | /* Now, we do the remaining detection. It is not there, unless you force |
|---|
| 225 | the checksum to work out. */ |
|---|
| 226 | if (checksum) { |
|---|
| 227 | cs = 0; |
|---|
| 228 | for (i = 0; i <= 0x3e; i++) |
|---|
| 229 | cs += i2c_smbus_read_byte_data(new_client, i); |
|---|
| 230 | cs &= 0xff; |
|---|
| 231 | if (i2c_smbus_read_byte_data |
|---|
| 232 | (new_client, EEPROM_REG_CHECKSUM) != cs) |
|---|
| 233 | goto ERROR1; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | /* Determine the chip type - only one kind supported! */ |
|---|
| 237 | if (kind <= 0) |
|---|
| 238 | kind = eeprom; |
|---|
| 239 | |
|---|
| 240 | if (kind == eeprom) { |
|---|
| 241 | type_name = "eeprom"; |
|---|
| 242 | client_name = "EEPROM chip"; |
|---|
| 243 | } else { |
|---|
| 244 | #ifdef DEBUG |
|---|
| 245 | printk("eeprom.o: Internal error: unknown kind (%d)?!?", |
|---|
| 246 | kind); |
|---|
| 247 | #endif |
|---|
| 248 | goto ERROR1; |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | /* Fill in the remaining client fields and put it into the global list */ |
|---|
| 252 | strcpy(new_client->name, client_name); |
|---|
| 253 | |
|---|
| 254 | new_client->id = eeprom_id++; |
|---|
| 255 | data->valid = 0; |
|---|
| 256 | init_MUTEX(&data->update_lock); |
|---|
| 257 | |
|---|
| 258 | /* Tell the I2C layer a new client has arrived */ |
|---|
| 259 | if ((err = i2c_attach_client(new_client))) |
|---|
| 260 | goto ERROR3; |
|---|
| 261 | |
|---|
| 262 | /* Register a new directory entry with module sensors */ |
|---|
| 263 | if ((i = i2c_register_entry(new_client, type_name, |
|---|
| 264 | eeprom_dir_table_template, |
|---|
| 265 | THIS_MODULE)) < 0) { |
|---|
| 266 | err = i; |
|---|
| 267 | goto ERROR4; |
|---|
| 268 | } |
|---|
| 269 | data->sysctl_id = i; |
|---|
| 270 | |
|---|
| 271 | return 0; |
|---|
| 272 | |
|---|
| 273 | /* OK, this is not exactly good programming practice, usually. But it is |
|---|
| 274 | very code-efficient in this case. */ |
|---|
| 275 | |
|---|
| 276 | ERROR4: |
|---|
| 277 | i2c_detach_client(new_client); |
|---|
| 278 | ERROR3: |
|---|
| 279 | ERROR1: |
|---|
| 280 | kfree(new_client); |
|---|
| 281 | ERROR0: |
|---|
| 282 | return err; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | int eeprom_detach_client(struct i2c_client *client) |
|---|
| 286 | { |
|---|
| 287 | int err; |
|---|
| 288 | |
|---|
| 289 | i2c_deregister_entry(((struct eeprom_data *) (client->data))-> |
|---|
| 290 | sysctl_id); |
|---|
| 291 | |
|---|
| 292 | if ((err = i2c_detach_client(client))) { |
|---|
| 293 | printk |
|---|
| 294 | ("eeprom.o: Client deregistration failed, client not detached.\n"); |
|---|
| 295 | return err; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | kfree(client); |
|---|
| 299 | |
|---|
| 300 | return 0; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | /* No commands defined yet */ |
|---|
| 305 | int eeprom_command(struct i2c_client *client, unsigned int cmd, void *arg) |
|---|
| 306 | { |
|---|
| 307 | return 0; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | void eeprom_inc_use(struct i2c_client *client) |
|---|
| 311 | { |
|---|
| 312 | #ifdef MODULE |
|---|
| 313 | MOD_INC_USE_COUNT; |
|---|
| 314 | #endif |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | void eeprom_dec_use(struct i2c_client *client) |
|---|
| 318 | { |
|---|
| 319 | #ifdef MODULE |
|---|
| 320 | MOD_DEC_USE_COUNT; |
|---|
| 321 | #endif |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | #if 0 |
|---|
| 325 | /* No writes yet (PAE) */ |
|---|
| 326 | int eeprom_write_value(struct i2c_client *client, u8 reg, u8 value) |
|---|
| 327 | { |
|---|
| 328 | return i2c_smbus_write_byte_data(client, reg, value); |
|---|
| 329 | } |
|---|
| 330 | #endif |
|---|
| 331 | |
|---|
| 332 | void eeprom_update_client(struct i2c_client *client) |
|---|
| 333 | { |
|---|
| 334 | struct eeprom_data *data = client->data; |
|---|
| 335 | int i; |
|---|
| 336 | |
|---|
| 337 | down(&data->update_lock); |
|---|
| 338 | |
|---|
| 339 | if ((jiffies - data->last_updated > 300 * HZ) | |
|---|
| 340 | (jiffies < data->last_updated) || !data->valid) { |
|---|
| 341 | |
|---|
| 342 | #ifdef DEBUG |
|---|
| 343 | printk("Starting eeprom update\n"); |
|---|
| 344 | #endif |
|---|
| 345 | |
|---|
| 346 | if (i2c_smbus_write_byte(client, 0)) { |
|---|
| 347 | #ifdef DEBUG |
|---|
| 348 | printk("eeprom read start has failed!\n"); |
|---|
| 349 | #endif |
|---|
| 350 | } |
|---|
| 351 | for (i = 0; i < EEPROM_SIZE; i++) { |
|---|
| 352 | data->data[i] = (u8) i2c_smbus_read_byte(client); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | data->last_updated = jiffies; |
|---|
| 356 | data->valid = 1; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | up(&data->update_lock); |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | void eeprom_contents(struct i2c_client *client, int operation, |
|---|
| 364 | int ctl_name, int *nrels_mag, long *results) |
|---|
| 365 | { |
|---|
| 366 | int i; |
|---|
| 367 | int base = 0; |
|---|
| 368 | struct eeprom_data *data = client->data; |
|---|
| 369 | |
|---|
| 370 | switch (ctl_name) { |
|---|
| 371 | case EEPROM_SYSCTL2: |
|---|
| 372 | base = 16; |
|---|
| 373 | break; |
|---|
| 374 | case EEPROM_SYSCTL3: |
|---|
| 375 | base = 32; |
|---|
| 376 | break; |
|---|
| 377 | case EEPROM_SYSCTL4: |
|---|
| 378 | base = 48; |
|---|
| 379 | break; |
|---|
| 380 | case EEPROM_SYSCTL5: |
|---|
| 381 | base = 64; |
|---|
| 382 | break; |
|---|
| 383 | case EEPROM_SYSCTL6: |
|---|
| 384 | base = 80; |
|---|
| 385 | break; |
|---|
| 386 | case EEPROM_SYSCTL7: |
|---|
| 387 | base = 96; |
|---|
| 388 | break; |
|---|
| 389 | case EEPROM_SYSCTL8: |
|---|
| 390 | base = 112; |
|---|
| 391 | break; |
|---|
| 392 | case EEPROM_SYSCTL9: |
|---|
| 393 | base = 128; |
|---|
| 394 | break; |
|---|
| 395 | case EEPROM_SYSCTL10: |
|---|
| 396 | base = 144; |
|---|
| 397 | break; |
|---|
| 398 | case EEPROM_SYSCTL11: |
|---|
| 399 | base = 160; |
|---|
| 400 | break; |
|---|
| 401 | case EEPROM_SYSCTL12: |
|---|
| 402 | base = 176; |
|---|
| 403 | break; |
|---|
| 404 | case EEPROM_SYSCTL13: |
|---|
| 405 | base = 192; |
|---|
| 406 | break; |
|---|
| 407 | case EEPROM_SYSCTL14: |
|---|
| 408 | base = 208; |
|---|
| 409 | break; |
|---|
| 410 | case EEPROM_SYSCTL15: |
|---|
| 411 | base = 224; |
|---|
| 412 | break; |
|---|
| 413 | case EEPROM_SYSCTL16: |
|---|
| 414 | base = 240; |
|---|
| 415 | break; |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | if (operation == SENSORS_PROC_REAL_INFO) |
|---|
| 419 | *nrels_mag = 0; |
|---|
| 420 | else if (operation == SENSORS_PROC_REAL_READ) { |
|---|
| 421 | eeprom_update_client(client); |
|---|
| 422 | for (i = 0; i < 16; i++) { |
|---|
| 423 | results[i] = data->data[i + base]; |
|---|
| 424 | } |
|---|
| 425 | #ifdef DEBUG |
|---|
| 426 | printk("eeprom.o: 0x%X EEPROM Contents (base %d): ", |
|---|
| 427 | client->addr, base); |
|---|
| 428 | for (i = 0; i < 16; i++) { |
|---|
| 429 | printk(" 0x%X", data->data[i + base]); |
|---|
| 430 | } |
|---|
| 431 | printk(" .\n"); |
|---|
| 432 | #endif |
|---|
| 433 | *nrels_mag = 16; |
|---|
| 434 | } else if (operation == SENSORS_PROC_REAL_WRITE) { |
|---|
| 435 | |
|---|
| 436 | /* No writes to the EEPROM (yet, anyway) (PAE) */ |
|---|
| 437 | printk("eeprom.o: No writes to EEPROMs supported!\n"); |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | int __init sensors_eeprom_init(void) |
|---|
| 442 | { |
|---|
| 443 | int res; |
|---|
| 444 | |
|---|
| 445 | printk("eeprom.o version %s (%s)\n", LM_VERSION, LM_DATE); |
|---|
| 446 | eeprom_initialized = 0; |
|---|
| 447 | if ((res = i2c_add_driver(&eeprom_driver))) { |
|---|
| 448 | printk |
|---|
| 449 | ("eeprom.o: Driver registration failed, module not inserted.\n"); |
|---|
| 450 | eeprom_cleanup(); |
|---|
| 451 | return res; |
|---|
| 452 | } |
|---|
| 453 | eeprom_initialized++; |
|---|
| 454 | return 0; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | int __init eeprom_cleanup(void) |
|---|
| 458 | { |
|---|
| 459 | int res; |
|---|
| 460 | |
|---|
| 461 | if (eeprom_initialized >= 1) { |
|---|
| 462 | if ((res = i2c_del_driver(&eeprom_driver))) { |
|---|
| 463 | printk |
|---|
| 464 | ("eeprom.o: Driver deregistration failed, module not removed.\n"); |
|---|
| 465 | return res; |
|---|
| 466 | } |
|---|
| 467 | } else |
|---|
| 468 | eeprom_initialized--; |
|---|
| 469 | |
|---|
| 470 | return 0; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | EXPORT_NO_SYMBOLS; |
|---|
| 474 | |
|---|
| 475 | #ifdef MODULE |
|---|
| 476 | |
|---|
| 477 | MODULE_AUTHOR |
|---|
| 478 | ("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>"); |
|---|
| 479 | MODULE_DESCRIPTION("EEPROM driver"); |
|---|
| 480 | |
|---|
| 481 | int init_module(void) |
|---|
| 482 | { |
|---|
| 483 | return sensors_eeprom_init(); |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | int cleanup_module(void) |
|---|
| 487 | { |
|---|
| 488 | return eeprom_cleanup(); |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | #endif /* MODULE */ |
|---|