| | 30 | /* Addresses to scan */ |
| | 31 | static unsigned short normal_i2c[] = {SENSORS_I2C_END}; |
| | 32 | static unsigned short normal_i2c_range[] = {0x50,0x57,SENSORS_I2C_END}; |
| | 33 | static unsigned int normal_isa[] = {SENSORS_ISA_END}; |
| | 34 | static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; |
| | 35 | |
| | 36 | /* Insmod parameters */ |
| | 37 | SENSORS_INSMOD_1(eeprom); |
| | 38 | |
| | 39 | static int checksum = 0; |
| | 40 | MODULE_PARM(checksum,"i"); |
| | 41 | MODULE_PARM_DESC(checksum,"Only accept eeproms whose checksum is correct"); |
| | 42 | |
| | 43 | |
| 132 | | |
| 133 | | err = 0; |
| 134 | | /* Make sure we aren't probing the ISA bus!! */ |
| 135 | | if (i2c_is_isa_adapter(adapter)) return 0; |
| | 155 | int err=0; |
| | 156 | const char *type_name,*client_name; |
| | 157 | |
| | 158 | /* Make sure we aren't probing the ISA bus!! This is just a safety check |
| | 159 | at this moment; sensors_detect really won't call us. */ |
| | 160 | #ifdef DEBUG |
| | 161 | if (i2c_is_isa_adapter(adapter)) { |
| | 162 | printk("eeprom.o: eeprom_detect called for an ISA bus adapter?!?\n"); |
| | 163 | return 0; |
| | 164 | } |
| | 165 | #endif |
| | 166 | |
| | 167 | /* Here, we have to do the address registration check for the I2C bus. |
| | 168 | But that is not yet implemented. */ |
| | 169 | |
| | 170 | /* OK. For now, we presume we have a valid client. We now create the |
| | 171 | client structure, even though we cannot fill it completely yet. |
| | 172 | But it allows us to access eeprom_{read,write}_value. */ |
| | 173 | if (! (new_client = kmalloc(sizeof(struct i2c_client) + |
| | 174 | sizeof(struct eeprom_data), |
| | 175 | GFP_KERNEL))) { |
| | 176 | err = -ENOMEM; |
| | 177 | goto ERROR0; |
| | 178 | } |
| | 179 | |
| | 180 | data = (struct eeprom_data *) (((struct i2c_client *) new_client) + 1); |
| | 181 | new_client->addr = address; |
| | 182 | new_client->data = data; |
| | 183 | new_client->adapter = adapter; |
| | 184 | new_client->driver = &eeprom_driver; |
| | 185 | |
| | 186 | /* Now, we do the remaining detection. It is not there, unless you force |
| | 187 | the checksum to work out. */ |
| | 188 | if (checksum) { |
| | 189 | cs = 0; |
| | 190 | for (i = 0; i <= 0x3e; i++) |
| | 191 | cs += smbus_read_byte_data(adapter,address,i); |
| | 192 | cs &= 0xff; |
| | 193 | if (smbus_read_byte_data(adapter,address,EEPROM_REG_CHECKSUM) != cs) |
| | 194 | goto ERROR1; |
| | 195 | } |
| 137 | | /* OK, this is no detection. I know. It will do for now, though. */ |
| 138 | | |
| 139 | | /* Set err only if a global error would make registering other clients |
| 140 | | impossible too (like out-of-memory). */ |
| 141 | | |
| 142 | | /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ |
| 143 | | for (address = 0x50; (! err) && (address <= 0x57); address ++) { |
| 144 | | |
| 145 | | /* Later on, we will keep a list of registered addresses for each |
| 146 | | adapter, and check whether they are used here */ |
| 147 | | |
| 148 | | if (smbus_read_byte(adapter,address) < 0) { |
| | 197 | /* Determine the chip type - only one kind supported! */ |
| | 198 | if (kind <= 0) |
| | 199 | kind = eeprom; |
| | 200 | |
| | 201 | if (kind == eeprom) { |
| | 202 | type_name = "eeprom"; |
| | 203 | client_name = "EEPROM chip"; |
| | 204 | } else { |
| 150 | | printk("eeprom.o: No eeprom found at: 0x%X\n",address); |
| 151 | | #endif |
| 152 | | continue; |
| 153 | | } |
| 154 | | |
| 155 | | /* Real detection code goes here */ |
| 156 | | |
| 157 | | /* Allocate space for a new client structure */ |
| 158 | | if (! (new_client = kmalloc(sizeof(struct i2c_client) + |
| 159 | | sizeof(struct eeprom_data), |
| 160 | | GFP_KERNEL))) { |
| 161 | | err = -ENOMEM; |
| 162 | | continue; |
| 163 | | } |
| 164 | | |
| 165 | | /* Find a place in our global list */ |
| 166 | | for (i = 0; i < MAX_EEPROM_NR; i++) |
| 167 | | if (! eeprom_list[i]) |
| 168 | | break; |
| 169 | | if (i == MAX_EEPROM_NR) { |
| 170 | | err = -ENOMEM; |
| 171 | | printk("eeprom.o: No empty slots left, recompile and heighten " |
| 172 | | "MAX_EEPROM_NR!\n"); |
| 173 | | goto ERROR1; |
| 174 | | } |
| 175 | | eeprom_list[i] = new_client; |
| 176 | | |
| 177 | | /* Fill the new client structure with data */ |
| 178 | | data = (struct eeprom_data *) (new_client + 1); |
| 179 | | new_client->data = data; |
| 180 | | new_client->id = i; |
| 181 | | new_client->addr = address; |
| 182 | | new_client->adapter = adapter; |
| 183 | | new_client->driver = &eeprom_driver; |
| 184 | | strcpy(new_client->name,"EEPROM chip"); |
| 185 | | data->valid = 0; |
| 186 | | data->update_lock = MUTEX; |
| 187 | | |
| 188 | | /* Tell i2c-core a new client has arrived */ |
| 189 | | if ((err = i2c_attach_client(new_client))) |
| 190 | | goto ERROR2; |
| 191 | | |
| 192 | | /* Register a new directory entry with module sensors */ |
| 193 | | if ((err = sensors_register_entry(new_client,"eeprom", |
| 194 | | eeprom_dir_table_template)) < 0) |
| 195 | | goto ERROR3; |
| 196 | | data->sysctl_id = err; |
| 197 | | err = 0; |
| 198 | | |
| 199 | | continue; |
| | 206 | printk("eeprom.o: Internal error: unknown kind (%d)?!?",kind); |
| | 207 | #endif |
| | 208 | goto ERROR1; |
| | 209 | } |
| | 210 | |
| | 211 | /* Fill in the remaining client fields and put it into the global list */ |
| | 212 | strcpy(new_client->name,client_name); |
| | 213 | |
| | 214 | /* Find a place in our global list */ |
| | 215 | for (i = 0; i < MAX_EEPROM_NR; i++) |
| | 216 | if (! eeprom_list[i]) |
| | 217 | break; |
| | 218 | if (i == MAX_EEPROM_NR) { |
| | 219 | err = -ENOMEM; |
| | 220 | printk("eeprom.o: No empty slots left, recompile and heighten " |
| | 221 | "MAX_EEPROM_NR!\n"); |
| | 222 | goto ERROR2; |
| | 223 | } |
| | 224 | eeprom_list[i] = new_client; |
| | 225 | new_client->id = i; |
| | 226 | data->valid = 0; |
| | 227 | data->update_lock = MUTEX; |
| | 228 | |
| | 229 | /* Tell the I2C layer a new client has arrived */ |
| | 230 | if ((err = i2c_attach_client(new_client))) |
| | 231 | goto ERROR3; |
| | 232 | |
| | 233 | /* Register a new directory entry with module sensors */ |
| | 234 | if ((i = sensors_register_entry(new_client,type_name, |
| | 235 | eeprom_dir_table_template)) < 0) { |
| | 236 | err = i; |
| | 237 | goto ERROR4; |
| | 238 | } |
| | 239 | data->sysctl_id = i; |
| | 240 | |
| | 241 | return 0; |
| | 242 | |