Changeset 71
- Timestamp:
- 12/13/98 09:43:14 (14 years ago)
- Location:
- lm-sensors/trunk
- Files:
-
- 2 modified
-
kernel/chips/eeprom.c (modified) (12 diffs)
-
src/eeprom.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/chips/eeprom.c
r45 r71 28 28 /* Many constants specified below */ 29 29 30 /* EEPROM memory types: */ 31 #define ONE_K 1 32 #define TWO_K 2 33 #define FOUR_K 3 34 #define EIGHT_K 4 35 #define SIXTEEN_K 5 30 36 31 37 /* Conversions */ 32 33 /* Initial values */ 38 /* Size of EEPROM in bytes */ 39 #define EEPROM_SIZE 16 34 40 35 41 /* Each client has this additional data */ … … 41 47 unsigned long last_updated; /* In jiffies */ 42 48 43 /* These need to change. (PAE)*/44 u16 temp,temp_os,temp_hyst; /* Register values */ 49 u8 data[EEPROM_SIZE]; /* Register values */ 50 int memtype; 45 51 }; 46 52 … … 66 72 static int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value); 67 73 68 static void eeprom_ data(struct i2c_client *client, int operation, int ctl_name,74 static void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 69 75 int *nrels_mag, long *results); 70 76 static void eeprom_update_client(struct i2c_client *client); … … 89 95 when a new copy is allocated. */ 90 96 static ctl_table eeprom_dir_table_template[] = { 91 { EEPROM_SYSCTL, "EEPROM", NULL, 0, 0644, NULL, &sensors_proc_real, 92 &sensors_sysctl_real, NULL, &eeprom_data }, 97 { EEPROM_SYSCTL1, "data0-15", NULL, 0, 0644, NULL, &sensors_proc_real, 98 &sensors_sysctl_real, NULL, &eeprom_contents }, 99 { EEPROM_SYSCTL2, "data16-31", NULL, 0, 0644, NULL, &sensors_proc_real, 100 &sensors_sysctl_real, NULL, &eeprom_contents }, 101 { EEPROM_SYSCTL3, "data32-47", NULL, 0, 0644, NULL, &sensors_proc_real, 102 &sensors_sysctl_real, NULL, &eeprom_contents }, 103 { EEPROM_SYSCTL4, "data48-63", NULL, 0, 0644, NULL, &sensors_proc_real, 104 &sensors_sysctl_real, NULL, &eeprom_contents }, 93 105 { 0 } 94 106 }; … … 117 129 impossible too (like out-of-memory). */ 118 130 119 /* Serial EEPROMs for SMBus use addresses from 0x 28 to 0x2f*/120 for (address = 0x 28; (! err) && (address <= 0x2f); address ++) {131 /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ 132 for (address = 0x50; (! err) && (address <= 0x57); address ++) { 121 133 122 134 /* Later on, we will keep a list of registered addresses for each 123 135 adapter, and check whether they are used here */ 124 136 125 if (smbus_read_byte_data(adapter,address,0) < 0) 137 if (smbus_read_byte(adapter,address) < 0) { 138 #ifdef DEBUG 139 printk("eeprom.o: No eeprom found at: 0x%X\n",address); 140 #endif 126 141 continue; 142 } 127 143 128 144 /* Real detection code goes here */ … … 130 146 /* Allocate space for a new client structure */ 131 147 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 132 sizeof(struct eeprom 5_data),148 sizeof(struct eeprom_data), 133 149 GFP_KERNEL))) { 134 150 err = -ENOMEM; … … 170 186 err = 0; 171 187 172 /* Initialize the chip -- No init needed for EEPROMs*/173 174 188 continue; 175 189 /* OK, this is not exactly good programming practice, usually. But it is … … 216 230 } 217 231 218 /* Nothing here yet */219 232 void eeprom_inc_use (struct i2c_client *client) 220 233 { 221 } 222 223 /* Nothing here yet */ 234 #ifdef MODULE 235 MOD_INC_USE_COUNT; 236 #endif 237 } 238 224 239 void eeprom_dec_use (struct i2c_client *client) 225 240 { 241 #ifdef MODULE 242 MOD_DEC_USE_COUNT; 243 #endif 226 244 } 227 245 … … 229 247 { 230 248 return (val >> 8) | (val << 8); 231 }232 233 /* All registers are word-sized, except for the configuration register.234 For some reason, we must swap the low and high byte, but only on235 reading words?!? */236 int eeprom_read_value(struct i2c_client *client, u8 reg)237 {238 if (reg == EEPROM_REG_CONF)239 return smbus_read_byte_data(client->adapter,client->addr,reg);240 else241 return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg));242 249 } 243 250 244 251 /* No swapping needed here! */ 245 252 int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value) 246 { 253 {/* 247 254 if (reg == EEPROM_REG_CONF) 248 255 return smbus_write_byte_data(client->adapter,client->addr,reg,value); 249 256 else 250 return smbus_write_word_data(client->adapter,client->addr,reg,value); 257 return smbus_write_word_data(client->adapter,client->addr,reg,value); */ 258 259 /* No writes yet (PAE) */ 260 return 0; 251 261 } 252 262 … … 254 264 { 255 265 struct eeprom_data *data = client->data; 266 int i; 256 267 257 268 down(&data->update_lock); … … 264 275 #endif 265 276 266 /* Need to read the data here (PAE) */ 267 data->eeprom = eeprom_read_value(client,EEPROM_REG_TEMP); 277 if (smbus_write_byte(client->adapter,client->addr,0)) { 278 #ifdef DEBUG 279 printk("eeprom read start has failed!\n"); 280 #endif 281 } 282 for (i=0;i<EEPROM_SIZE;i++) { 283 data->data[i] = smbus_read_byte(client->adapter,client->addr); 284 } 268 285 269 286 data->last_updated = jiffies; … … 274 291 } 275 292 276 /* ? (PAE) */ 277 void eeprom_ data(struct i2c_client *client, int operation, int ctl_name,293 294 void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 278 295 int *nrels_mag, long *results) 279 296 { 297 int i; 298 int base=0; 280 299 struct eeprom_data *data = client->data; 300 301 if (ctl_name == EEPROM_SYSCTL2){ base=16; } 302 if (ctl_name == EEPROM_SYSCTL3){ base=32; } 303 if (ctl_name == EEPROM_SYSCTL4){ base=48; } 304 281 305 if (operation == SENSORS_PROC_REAL_INFO) 282 *nrels_mag = 1;306 *nrels_mag = 0; 283 307 else if (operation == SENSORS_PROC_REAL_READ) { 284 308 eeprom_update_client(client); 285 results[0] = DATA_FROM_REG(data->temp_os); 286 /* ... More needs to go here (PAE) */ 287 *nrels_mag = 3; 309 /* just for testing, we won't do the whole thing */ 310 for (i=0; i<EEPROM_SIZE; i++) { 311 results[i]=data->data[i + base]; 312 } 313 #ifdef DEBUG 314 printk("eeprom.o: 0x%X EEPROM Contents (base %d): ",client->addr,base); 315 for (i=0; i<EEPROM_SIZE; i++) { 316 printk(" 0x%X",data->data[i + base]); 317 } 318 printk(" .\n"); 319 #endif 320 *nrels_mag = EEPROM_SIZE; 288 321 } else if (operation == SENSORS_PROC_REAL_WRITE) { 289 322 -
lm-sensors/trunk/src/eeprom.c
r45 r71 28 28 /* Many constants specified below */ 29 29 30 /* EEPROM memory types: */ 31 #define ONE_K 1 32 #define TWO_K 2 33 #define FOUR_K 3 34 #define EIGHT_K 4 35 #define SIXTEEN_K 5 30 36 31 37 /* Conversions */ 32 33 /* Initial values */ 38 /* Size of EEPROM in bytes */ 39 #define EEPROM_SIZE 16 34 40 35 41 /* Each client has this additional data */ … … 41 47 unsigned long last_updated; /* In jiffies */ 42 48 43 /* These need to change. (PAE)*/44 u16 temp,temp_os,temp_hyst; /* Register values */ 49 u8 data[EEPROM_SIZE]; /* Register values */ 50 int memtype; 45 51 }; 46 52 … … 66 72 static int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value); 67 73 68 static void eeprom_ data(struct i2c_client *client, int operation, int ctl_name,74 static void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 69 75 int *nrels_mag, long *results); 70 76 static void eeprom_update_client(struct i2c_client *client); … … 89 95 when a new copy is allocated. */ 90 96 static ctl_table eeprom_dir_table_template[] = { 91 { EEPROM_SYSCTL, "EEPROM", NULL, 0, 0644, NULL, &sensors_proc_real, 92 &sensors_sysctl_real, NULL, &eeprom_data }, 97 { EEPROM_SYSCTL1, "data0-15", NULL, 0, 0644, NULL, &sensors_proc_real, 98 &sensors_sysctl_real, NULL, &eeprom_contents }, 99 { EEPROM_SYSCTL2, "data16-31", NULL, 0, 0644, NULL, &sensors_proc_real, 100 &sensors_sysctl_real, NULL, &eeprom_contents }, 101 { EEPROM_SYSCTL3, "data32-47", NULL, 0, 0644, NULL, &sensors_proc_real, 102 &sensors_sysctl_real, NULL, &eeprom_contents }, 103 { EEPROM_SYSCTL4, "data48-63", NULL, 0, 0644, NULL, &sensors_proc_real, 104 &sensors_sysctl_real, NULL, &eeprom_contents }, 93 105 { 0 } 94 106 }; … … 117 129 impossible too (like out-of-memory). */ 118 130 119 /* Serial EEPROMs for SMBus use addresses from 0x 28 to 0x2f*/120 for (address = 0x 28; (! err) && (address <= 0x2f); address ++) {131 /* Serial EEPROMs for SMBus use addresses from 0x50 to 0x57 */ 132 for (address = 0x50; (! err) && (address <= 0x57); address ++) { 121 133 122 134 /* Later on, we will keep a list of registered addresses for each 123 135 adapter, and check whether they are used here */ 124 136 125 if (smbus_read_byte_data(adapter,address,0) < 0) 137 if (smbus_read_byte(adapter,address) < 0) { 138 #ifdef DEBUG 139 printk("eeprom.o: No eeprom found at: 0x%X\n",address); 140 #endif 126 141 continue; 142 } 127 143 128 144 /* Real detection code goes here */ … … 130 146 /* Allocate space for a new client structure */ 131 147 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 132 sizeof(struct eeprom 5_data),148 sizeof(struct eeprom_data), 133 149 GFP_KERNEL))) { 134 150 err = -ENOMEM; … … 170 186 err = 0; 171 187 172 /* Initialize the chip -- No init needed for EEPROMs*/173 174 188 continue; 175 189 /* OK, this is not exactly good programming practice, usually. But it is … … 216 230 } 217 231 218 /* Nothing here yet */219 232 void eeprom_inc_use (struct i2c_client *client) 220 233 { 221 } 222 223 /* Nothing here yet */ 234 #ifdef MODULE 235 MOD_INC_USE_COUNT; 236 #endif 237 } 238 224 239 void eeprom_dec_use (struct i2c_client *client) 225 240 { 241 #ifdef MODULE 242 MOD_DEC_USE_COUNT; 243 #endif 226 244 } 227 245 … … 229 247 { 230 248 return (val >> 8) | (val << 8); 231 }232 233 /* All registers are word-sized, except for the configuration register.234 For some reason, we must swap the low and high byte, but only on235 reading words?!? */236 int eeprom_read_value(struct i2c_client *client, u8 reg)237 {238 if (reg == EEPROM_REG_CONF)239 return smbus_read_byte_data(client->adapter,client->addr,reg);240 else241 return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg));242 249 } 243 250 244 251 /* No swapping needed here! */ 245 252 int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value) 246 { 253 {/* 247 254 if (reg == EEPROM_REG_CONF) 248 255 return smbus_write_byte_data(client->adapter,client->addr,reg,value); 249 256 else 250 return smbus_write_word_data(client->adapter,client->addr,reg,value); 257 return smbus_write_word_data(client->adapter,client->addr,reg,value); */ 258 259 /* No writes yet (PAE) */ 260 return 0; 251 261 } 252 262 … … 254 264 { 255 265 struct eeprom_data *data = client->data; 266 int i; 256 267 257 268 down(&data->update_lock); … … 264 275 #endif 265 276 266 /* Need to read the data here (PAE) */ 267 data->eeprom = eeprom_read_value(client,EEPROM_REG_TEMP); 277 if (smbus_write_byte(client->adapter,client->addr,0)) { 278 #ifdef DEBUG 279 printk("eeprom read start has failed!\n"); 280 #endif 281 } 282 for (i=0;i<EEPROM_SIZE;i++) { 283 data->data[i] = smbus_read_byte(client->adapter,client->addr); 284 } 268 285 269 286 data->last_updated = jiffies; … … 274 291 } 275 292 276 /* ? (PAE) */ 277 void eeprom_ data(struct i2c_client *client, int operation, int ctl_name,293 294 void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, 278 295 int *nrels_mag, long *results) 279 296 { 297 int i; 298 int base=0; 280 299 struct eeprom_data *data = client->data; 300 301 if (ctl_name == EEPROM_SYSCTL2){ base=16; } 302 if (ctl_name == EEPROM_SYSCTL3){ base=32; } 303 if (ctl_name == EEPROM_SYSCTL4){ base=48; } 304 281 305 if (operation == SENSORS_PROC_REAL_INFO) 282 *nrels_mag = 1;306 *nrels_mag = 0; 283 307 else if (operation == SENSORS_PROC_REAL_READ) { 284 308 eeprom_update_client(client); 285 results[0] = DATA_FROM_REG(data->temp_os); 286 /* ... More needs to go here (PAE) */ 287 *nrels_mag = 3; 309 /* just for testing, we won't do the whole thing */ 310 for (i=0; i<EEPROM_SIZE; i++) { 311 results[i]=data->data[i + base]; 312 } 313 #ifdef DEBUG 314 printk("eeprom.o: 0x%X EEPROM Contents (base %d): ",client->addr,base); 315 for (i=0; i<EEPROM_SIZE; i++) { 316 printk(" 0x%X",data->data[i + base]); 317 } 318 printk(" .\n"); 319 #endif 320 *nrels_mag = EEPROM_SIZE; 288 321 } else if (operation == SENSORS_PROC_REAL_WRITE) { 289 322
