diff options
Diffstat (limited to 'drivers/hwmon/sis5595.c')
| -rw-r--r-- | drivers/hwmon/sis5595.c | 510 | 
1 files changed, 255 insertions, 255 deletions
| diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 3f400263fc0f..83321b28cf0e 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
| @@ -54,9 +54,9 @@ | |||
| 54 | #include <linux/slab.h> | 54 | #include <linux/slab.h> | 
| 55 | #include <linux/ioport.h> | 55 | #include <linux/ioport.h> | 
| 56 | #include <linux/pci.h> | 56 | #include <linux/pci.h> | 
| 57 | #include <linux/i2c.h> | 57 | #include <linux/platform_device.h> | 
| 58 | #include <linux/i2c-isa.h> | ||
| 59 | #include <linux/hwmon.h> | 58 | #include <linux/hwmon.h> | 
| 59 | #include <linux/hwmon-sysfs.h> | ||
| 60 | #include <linux/err.h> | 60 | #include <linux/err.h> | 
| 61 | #include <linux/init.h> | 61 | #include <linux/init.h> | 
| 62 | #include <linux/jiffies.h> | 62 | #include <linux/jiffies.h> | 
| @@ -72,17 +72,13 @@ module_param(force_addr, ushort, 0); | |||
| 72 | MODULE_PARM_DESC(force_addr, | 72 | MODULE_PARM_DESC(force_addr, | 
| 73 | "Initialize the base address of the sensors"); | 73 | "Initialize the base address of the sensors"); | 
| 74 | 74 | ||
| 75 | /* Device address | 75 | static struct platform_device *pdev; | 
| 76 | Note that we can't determine the ISA address until we have initialized | ||
| 77 | our module */ | ||
| 78 | static unsigned short address; | ||
| 79 | 76 | ||
| 80 | /* Many SIS5595 constants specified below */ | 77 | /* Many SIS5595 constants specified below */ | 
| 81 | 78 | ||
| 82 | /* Length of ISA address segment */ | 79 | /* Length of ISA address segment */ | 
| 83 | #define SIS5595_EXTENT 8 | 80 | #define SIS5595_EXTENT 8 | 
| 84 | /* PCI Config Registers */ | 81 | /* PCI Config Registers */ | 
| 85 | #define SIS5595_REVISION_REG 0x08 | ||
| 86 | #define SIS5595_BASE_REG 0x68 | 82 | #define SIS5595_BASE_REG 0x68 | 
| 87 | #define SIS5595_PIN_REG 0x7A | 83 | #define SIS5595_PIN_REG 0x7A | 
| 88 | #define SIS5595_ENABLE_REG 0x7B | 84 | #define SIS5595_ENABLE_REG 0x7B | 
| @@ -165,7 +161,8 @@ static inline u8 DIV_TO_REG(int val) | |||
| 165 | /* For each registered chip, we need to keep some data in memory. | 161 | /* For each registered chip, we need to keep some data in memory. | 
| 166 | The structure is dynamically allocated. */ | 162 | The structure is dynamically allocated. */ | 
| 167 | struct sis5595_data { | 163 | struct sis5595_data { | 
| 168 | struct i2c_client client; | 164 | unsigned short addr; | 
| 165 | const char *name; | ||
| 169 | struct class_device *class_dev; | 166 | struct class_device *class_dev; | 
| 170 | struct mutex lock; | 167 | struct mutex lock; | 
| 171 | 168 | ||
| @@ -189,102 +186,88 @@ struct sis5595_data { | |||
| 189 | 186 | ||
| 190 | static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ | 187 | static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ | 
| 191 | 188 | ||
| 192 | static int sis5595_detect(struct i2c_adapter *adapter); | 189 | static int sis5595_probe(struct platform_device *pdev); | 
| 193 | static int sis5595_detach_client(struct i2c_client *client); | 190 | static int sis5595_remove(struct platform_device *pdev); | 
| 194 | 191 | ||
| 195 | static int sis5595_read_value(struct i2c_client *client, u8 reg); | 192 | static int sis5595_read_value(struct sis5595_data *data, u8 reg); | 
| 196 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value); | 193 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value); | 
| 197 | static struct sis5595_data *sis5595_update_device(struct device *dev); | 194 | static struct sis5595_data *sis5595_update_device(struct device *dev); | 
| 198 | static void sis5595_init_client(struct i2c_client *client); | 195 | static void sis5595_init_device(struct sis5595_data *data); | 
| 199 | 196 | ||
| 200 | static struct i2c_driver sis5595_driver = { | 197 | static struct platform_driver sis5595_driver = { | 
| 201 | .driver = { | 198 | .driver = { | 
| 202 | .owner = THIS_MODULE, | 199 | .owner = THIS_MODULE, | 
| 203 | .name = "sis5595", | 200 | .name = "sis5595", | 
| 204 | }, | 201 | }, | 
| 205 | .attach_adapter = sis5595_detect, | 202 | .probe = sis5595_probe, | 
| 206 | .detach_client = sis5595_detach_client, | 203 | .remove = __devexit_p(sis5595_remove), | 
| 207 | }; | 204 | }; | 
| 208 | 205 | ||
| 209 | /* 4 Voltages */ | 206 | /* 4 Voltages */ | 
| 210 | static ssize_t show_in(struct device *dev, char *buf, int nr) | 207 | static ssize_t show_in(struct device *dev, struct device_attribute *da, | 
| 208 | char *buf) | ||
| 211 | { | 209 | { | 
| 212 | struct sis5595_data *data = sis5595_update_device(dev); | 210 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 211 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 212 | int nr = attr->index; | ||
| 213 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 213 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 
| 214 | } | 214 | } | 
| 215 | 215 | ||
| 216 | static ssize_t show_in_min(struct device *dev, char *buf, int nr) | 216 | static ssize_t show_in_min(struct device *dev, struct device_attribute *da, | 
| 217 | char *buf) | ||
| 217 | { | 218 | { | 
| 218 | struct sis5595_data *data = sis5595_update_device(dev); | 219 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 220 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 221 | int nr = attr->index; | ||
| 219 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 222 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 
| 220 | } | 223 | } | 
| 221 | 224 | ||
| 222 | static ssize_t show_in_max(struct device *dev, char *buf, int nr) | 225 | static ssize_t show_in_max(struct device *dev, struct device_attribute *da, | 
| 226 | char *buf) | ||
| 223 | { | 227 | { | 
| 224 | struct sis5595_data *data = sis5595_update_device(dev); | 228 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 229 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 230 | int nr = attr->index; | ||
| 225 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 231 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 
| 226 | } | 232 | } | 
| 227 | 233 | ||
| 228 | static ssize_t set_in_min(struct device *dev, const char *buf, | 234 | static ssize_t set_in_min(struct device *dev, struct device_attribute *da, | 
| 229 | size_t count, int nr) | 235 | const char *buf, size_t count) | 
| 230 | { | 236 | { | 
| 231 | struct i2c_client *client = to_i2c_client(dev); | 237 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 232 | struct sis5595_data *data = i2c_get_clientdata(client); | 238 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 
| 239 | int nr = attr->index; | ||
| 233 | unsigned long val = simple_strtoul(buf, NULL, 10); | 240 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
| 234 | 241 | ||
| 235 | mutex_lock(&data->update_lock); | 242 | mutex_lock(&data->update_lock); | 
| 236 | data->in_min[nr] = IN_TO_REG(val); | 243 | data->in_min[nr] = IN_TO_REG(val); | 
| 237 | sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); | 244 | sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); | 
| 238 | mutex_unlock(&data->update_lock); | 245 | mutex_unlock(&data->update_lock); | 
| 239 | return count; | 246 | return count; | 
| 240 | } | 247 | } | 
| 241 | 248 | ||
| 242 | static ssize_t set_in_max(struct device *dev, const char *buf, | 249 | static ssize_t set_in_max(struct device *dev, struct device_attribute *da, | 
| 243 | size_t count, int nr) | 250 | const char *buf, size_t count) | 
| 244 | { | 251 | { | 
| 245 | struct i2c_client *client = to_i2c_client(dev); | 252 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 246 | struct sis5595_data *data = i2c_get_clientdata(client); | 253 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 
| 254 | int nr = attr->index; | ||
| 247 | unsigned long val = simple_strtoul(buf, NULL, 10); | 255 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
| 248 | 256 | ||
| 249 | mutex_lock(&data->update_lock); | 257 | mutex_lock(&data->update_lock); | 
| 250 | data->in_max[nr] = IN_TO_REG(val); | 258 | data->in_max[nr] = IN_TO_REG(val); | 
| 251 | sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); | 259 | sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); | 
| 252 | mutex_unlock(&data->update_lock); | 260 | mutex_unlock(&data->update_lock); | 
| 253 | return count; | 261 | return count; | 
| 254 | } | 262 | } | 
| 255 | 263 | ||
| 256 | #define show_in_offset(offset) \ | 264 | #define show_in_offset(offset) \ | 
| 257 | static ssize_t \ | 265 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 
| 258 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 266 | show_in, NULL, offset); \ | 
| 259 | { \ | 267 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | 
| 260 | return show_in(dev, buf, offset); \ | 268 | show_in_min, set_in_min, offset); \ | 
| 261 | } \ | 269 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | 
| 262 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 270 | show_in_max, set_in_max, offset); | 
| 263 | show_in##offset, NULL); \ | ||
| 264 | static ssize_t \ | ||
| 265 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
| 266 | { \ | ||
| 267 | return show_in_min(dev, buf, offset); \ | ||
| 268 | } \ | ||
| 269 | static ssize_t \ | ||
| 270 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
| 271 | { \ | ||
| 272 | return show_in_max(dev, buf, offset); \ | ||
| 273 | } \ | ||
| 274 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
| 275 | const char *buf, size_t count) \ | ||
| 276 | { \ | ||
| 277 | return set_in_min(dev, buf, count, offset); \ | ||
| 278 | } \ | ||
| 279 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
| 280 | const char *buf, size_t count) \ | ||
| 281 | { \ | ||
| 282 | return set_in_max(dev, buf, count, offset); \ | ||
| 283 | } \ | ||
| 284 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
| 285 | show_in##offset##_min, set_in##offset##_min); \ | ||
| 286 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
| 287 | show_in##offset##_max, set_in##offset##_max); | ||
| 288 | 271 | ||
| 289 | show_in_offset(0); | 272 | show_in_offset(0); | 
| 290 | show_in_offset(1); | 273 | show_in_offset(1); | 
| @@ -307,13 +290,12 @@ static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, | |||
| 307 | 290 | ||
| 308 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 291 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| 309 | { | 292 | { | 
| 310 | struct i2c_client *client = to_i2c_client(dev); | 293 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 311 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
| 312 | long val = simple_strtol(buf, NULL, 10); | 294 | long val = simple_strtol(buf, NULL, 10); | 
| 313 | 295 | ||
| 314 | mutex_lock(&data->update_lock); | 296 | mutex_lock(&data->update_lock); | 
| 315 | data->temp_over = TEMP_TO_REG(val); | 297 | data->temp_over = TEMP_TO_REG(val); | 
| 316 | sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); | 298 | sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over); | 
| 317 | mutex_unlock(&data->update_lock); | 299 | mutex_unlock(&data->update_lock); | 
| 318 | return count; | 300 | return count; | 
| 319 | } | 301 | } | 
| @@ -326,13 +308,12 @@ static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, | |||
| 326 | 308 | ||
| 327 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 309 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| 328 | { | 310 | { | 
| 329 | struct i2c_client *client = to_i2c_client(dev); | 311 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 330 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
| 331 | long val = simple_strtol(buf, NULL, 10); | 312 | long val = simple_strtol(buf, NULL, 10); | 
| 332 | 313 | ||
| 333 | mutex_lock(&data->update_lock); | 314 | mutex_lock(&data->update_lock); | 
| 334 | data->temp_hyst = TEMP_TO_REG(val); | 315 | data->temp_hyst = TEMP_TO_REG(val); | 
| 335 | sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); | 316 | sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst); | 
| 336 | mutex_unlock(&data->update_lock); | 317 | mutex_unlock(&data->update_lock); | 
| 337 | return count; | 318 | return count; | 
| 338 | } | 319 | } | 
| @@ -344,37 +325,47 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, | |||
| 344 | show_temp_hyst, set_temp_hyst); | 325 | show_temp_hyst, set_temp_hyst); | 
| 345 | 326 | ||
| 346 | /* 2 Fans */ | 327 | /* 2 Fans */ | 
| 347 | static ssize_t show_fan(struct device *dev, char *buf, int nr) | 328 | static ssize_t show_fan(struct device *dev, struct device_attribute *da, | 
| 329 | char *buf) | ||
| 348 | { | 330 | { | 
| 349 | struct sis5595_data *data = sis5595_update_device(dev); | 331 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 332 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 333 | int nr = attr->index; | ||
| 350 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 334 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 
| 351 | DIV_FROM_REG(data->fan_div[nr])) ); | 335 | DIV_FROM_REG(data->fan_div[nr])) ); | 
| 352 | } | 336 | } | 
| 353 | 337 | ||
| 354 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | 338 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, | 
| 339 | char *buf) | ||
| 355 | { | 340 | { | 
| 356 | struct sis5595_data *data = sis5595_update_device(dev); | 341 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 342 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 343 | int nr = attr->index; | ||
| 357 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], | 344 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], | 
| 358 | DIV_FROM_REG(data->fan_div[nr])) ); | 345 | DIV_FROM_REG(data->fan_div[nr])) ); | 
| 359 | } | 346 | } | 
| 360 | 347 | ||
| 361 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 348 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, | 
| 362 | size_t count, int nr) | 349 | const char *buf, size_t count) | 
| 363 | { | 350 | { | 
| 364 | struct i2c_client *client = to_i2c_client(dev); | 351 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 365 | struct sis5595_data *data = i2c_get_clientdata(client); | 352 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 
| 353 | int nr = attr->index; | ||
| 366 | unsigned long val = simple_strtoul(buf, NULL, 10); | 354 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
| 367 | 355 | ||
| 368 | mutex_lock(&data->update_lock); | 356 | mutex_lock(&data->update_lock); | 
| 369 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 357 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 
| 370 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 358 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 
| 371 | mutex_unlock(&data->update_lock); | 359 | mutex_unlock(&data->update_lock); | 
| 372 | return count; | 360 | return count; | 
| 373 | } | 361 | } | 
| 374 | 362 | ||
| 375 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | 363 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, | 
| 364 | char *buf) | ||
| 376 | { | 365 | { | 
| 377 | struct sis5595_data *data = sis5595_update_device(dev); | 366 | struct sis5595_data *data = sis5595_update_device(dev); | 
| 367 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
| 368 | int nr = attr->index; | ||
| 378 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 369 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 
| 379 | } | 370 | } | 
| 380 | 371 | ||
| @@ -382,11 +373,12 @@ static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | |||
| 382 | determined in part by the fan divisor. This follows the principle of | 373 | determined in part by the fan divisor. This follows the principle of | 
| 383 | least surprise; the user doesn't expect the fan minimum to change just | 374 | least surprise; the user doesn't expect the fan minimum to change just | 
| 384 | because the divisor changed. */ | 375 | because the divisor changed. */ | 
| 385 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 376 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, | 
| 386 | size_t count, int nr) | 377 | const char *buf, size_t count) | 
| 387 | { | 378 | { | 
| 388 | struct i2c_client *client = to_i2c_client(dev); | 379 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 389 | struct sis5595_data *data = i2c_get_clientdata(client); | 380 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 
| 381 | int nr = attr->index; | ||
| 390 | unsigned long min; | 382 | unsigned long min; | 
| 391 | unsigned long val = simple_strtoul(buf, NULL, 10); | 383 | unsigned long val = simple_strtoul(buf, NULL, 10); | 
| 392 | int reg; | 384 | int reg; | 
| @@ -394,7 +386,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
| 394 | mutex_lock(&data->update_lock); | 386 | mutex_lock(&data->update_lock); | 
| 395 | min = FAN_FROM_REG(data->fan_min[nr], | 387 | min = FAN_FROM_REG(data->fan_min[nr], | 
| 396 | DIV_FROM_REG(data->fan_div[nr])); | 388 | DIV_FROM_REG(data->fan_div[nr])); | 
| 397 | reg = sis5595_read_value(client, SIS5595_REG_FANDIV); | 389 | reg = sis5595_read_value(data, SIS5595_REG_FANDIV); | 
| 398 | 390 | ||
| 399 | switch (val) { | 391 | switch (val) { | 
| 400 | case 1: data->fan_div[nr] = 0; break; | 392 | case 1: data->fan_div[nr] = 0; break; | 
| @@ -402,7 +394,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
| 402 | case 4: data->fan_div[nr] = 2; break; | 394 | case 4: data->fan_div[nr] = 2; break; | 
| 403 | case 8: data->fan_div[nr] = 3; break; | 395 | case 8: data->fan_div[nr] = 3; break; | 
| 404 | default: | 396 | default: | 
| 405 | dev_err(&client->dev, "fan_div value %ld not " | 397 | dev_err(dev, "fan_div value %ld not " | 
| 406 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 398 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 
| 407 | mutex_unlock(&data->update_lock); | 399 | mutex_unlock(&data->update_lock); | 
| 408 | return -EINVAL; | 400 | return -EINVAL; | 
| @@ -416,55 +408,25 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
| 416 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); | 408 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); | 
| 417 | break; | 409 | break; | 
| 418 | } | 410 | } | 
| 419 | sis5595_write_value(client, SIS5595_REG_FANDIV, reg); | 411 | sis5595_write_value(data, SIS5595_REG_FANDIV, reg); | 
| 420 | data->fan_min[nr] = | 412 | data->fan_min[nr] = | 
| 421 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 413 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 
| 422 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 414 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 
| 423 | mutex_unlock(&data->update_lock); | 415 | mutex_unlock(&data->update_lock); | 
| 424 | return count; | 416 | return count; | 
| 425 | } | 417 | } | 
| 426 | 418 | ||
| 427 | #define show_fan_offset(offset) \ | 419 | #define show_fan_offset(offset) \ | 
| 428 | static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 420 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | 
| 429 | { \ | 421 | show_fan, NULL, offset - 1); \ | 
| 430 | return show_fan(dev, buf, offset - 1); \ | 422 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | 
| 431 | } \ | 423 | show_fan_min, set_fan_min, offset - 1); \ | 
| 432 | static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | 424 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | 
| 433 | { \ | 425 | show_fan_div, set_fan_div, offset - 1); | 
| 434 | return show_fan_min(dev, buf, offset - 1); \ | ||
| 435 | } \ | ||
| 436 | static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
| 437 | { \ | ||
| 438 | return show_fan_div(dev, buf, offset - 1); \ | ||
| 439 | } \ | ||
| 440 | static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
| 441 | const char *buf, size_t count) \ | ||
| 442 | { \ | ||
| 443 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
| 444 | } \ | ||
| 445 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ | ||
| 446 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
| 447 | show_fan_##offset##_min, set_fan_##offset##_min); | ||
| 448 | 426 | ||
| 449 | show_fan_offset(1); | 427 | show_fan_offset(1); | 
| 450 | show_fan_offset(2); | 428 | show_fan_offset(2); | 
| 451 | 429 | ||
| 452 | static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
| 453 | size_t count) | ||
| 454 | { | ||
| 455 | return set_fan_div(dev, buf, count, 0) ; | ||
| 456 | } | ||
| 457 | |||
| 458 | static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
| 459 | size_t count) | ||
| 460 | { | ||
| 461 | return set_fan_div(dev, buf, count, 1) ; | ||
| 462 | } | ||
| 463 | static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, | ||
| 464 | show_fan_1_div, set_fan_1_div); | ||
| 465 | static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, | ||
| 466 | show_fan_2_div, set_fan_2_div); | ||
| 467 | |||
| 468 | /* Alarms */ | 430 | /* Alarms */ | 
| 469 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 431 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 
| 470 | { | 432 | { | 
| @@ -473,28 +435,37 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch | |||
| 473 | } | 435 | } | 
| 474 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 436 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 
| 475 | 437 | ||
| 438 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
| 439 | char *buf) | ||
| 440 | { | ||
| 441 | struct sis5595_data *data = dev_get_drvdata(dev); | ||
| 442 | return sprintf(buf, "%s\n", data->name); | ||
| 443 | } | ||
| 444 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
| 445 | |||
| 476 | static struct attribute *sis5595_attributes[] = { | 446 | static struct attribute *sis5595_attributes[] = { | 
| 477 | &dev_attr_in0_input.attr, | 447 | &sensor_dev_attr_in0_input.dev_attr.attr, | 
| 478 | &dev_attr_in0_min.attr, | 448 | &sensor_dev_attr_in0_min.dev_attr.attr, | 
| 479 | &dev_attr_in0_max.attr, | 449 | &sensor_dev_attr_in0_max.dev_attr.attr, | 
| 480 | &dev_attr_in1_input.attr, | 450 | &sensor_dev_attr_in1_input.dev_attr.attr, | 
| 481 | &dev_attr_in1_min.attr, | 451 | &sensor_dev_attr_in1_min.dev_attr.attr, | 
| 482 | &dev_attr_in1_max.attr, | 452 | &sensor_dev_attr_in1_max.dev_attr.attr, | 
| 483 | &dev_attr_in2_input.attr, | 453 | &sensor_dev_attr_in2_input.dev_attr.attr, | 
| 484 | &dev_attr_in2_min.attr, | 454 | &sensor_dev_attr_in2_min.dev_attr.attr, | 
| 485 | &dev_attr_in2_max.attr, | 455 | &sensor_dev_attr_in2_max.dev_attr.attr, | 
| 486 | &dev_attr_in3_input.attr, | 456 | &sensor_dev_attr_in3_input.dev_attr.attr, | 
| 487 | &dev_attr_in3_min.attr, | 457 | &sensor_dev_attr_in3_min.dev_attr.attr, | 
| 488 | &dev_attr_in3_max.attr, | 458 | &sensor_dev_attr_in3_max.dev_attr.attr, | 
| 489 | 459 | ||
| 490 | &dev_attr_fan1_input.attr, | 460 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 
| 491 | &dev_attr_fan1_min.attr, | 461 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 
| 492 | &dev_attr_fan1_div.attr, | 462 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 
| 493 | &dev_attr_fan2_input.attr, | 463 | &sensor_dev_attr_fan2_input.dev_attr.attr, | 
| 494 | &dev_attr_fan2_min.attr, | 464 | &sensor_dev_attr_fan2_min.dev_attr.attr, | 
| 495 | &dev_attr_fan2_div.attr, | 465 | &sensor_dev_attr_fan2_div.dev_attr.attr, | 
| 496 | 466 | ||
| 497 | &dev_attr_alarms.attr, | 467 | &dev_attr_alarms.attr, | 
| 468 | &dev_attr_name.attr, | ||
| 498 | NULL | 469 | NULL | 
| 499 | }; | 470 | }; | 
| 500 | 471 | ||
| @@ -503,9 +474,9 @@ static const struct attribute_group sis5595_group = { | |||
| 503 | }; | 474 | }; | 
| 504 | 475 | ||
| 505 | static struct attribute *sis5595_attributes_opt[] = { | 476 | static struct attribute *sis5595_attributes_opt[] = { | 
| 506 | &dev_attr_in4_input.attr, | 477 | &sensor_dev_attr_in4_input.dev_attr.attr, | 
| 507 | &dev_attr_in4_min.attr, | 478 | &sensor_dev_attr_in4_min.dev_attr.attr, | 
| 508 | &dev_attr_in4_max.attr, | 479 | &sensor_dev_attr_in4_max.dev_attr.attr, | 
| 509 | 480 | ||
| 510 | &dev_attr_temp1_input.attr, | 481 | &dev_attr_temp1_input.attr, | 
| 511 | &dev_attr_temp1_max.attr, | 482 | &dev_attr_temp1_max.attr, | 
| @@ -518,68 +489,35 @@ static const struct attribute_group sis5595_group_opt = { | |||
| 518 | }; | 489 | }; | 
| 519 | 490 | ||
| 520 | /* This is called when the module is loaded */ | 491 | /* This is called when the module is loaded */ | 
| 521 | static int sis5595_detect(struct i2c_adapter *adapter) | 492 | static int __devinit sis5595_probe(struct platform_device *pdev) | 
| 522 | { | 493 | { | 
| 523 | int err = 0; | 494 | int err = 0; | 
| 524 | int i; | 495 | int i; | 
| 525 | struct i2c_client *new_client; | ||
| 526 | struct sis5595_data *data; | 496 | struct sis5595_data *data; | 
| 497 | struct resource *res; | ||
| 527 | char val; | 498 | char val; | 
| 528 | u16 a; | ||
| 529 | 499 | ||
| 530 | if (force_addr) | ||
| 531 | address = force_addr & ~(SIS5595_EXTENT - 1); | ||
| 532 | /* Reserve the ISA region */ | 500 | /* Reserve the ISA region */ | 
| 533 | if (!request_region(address, SIS5595_EXTENT, | 501 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 
| 502 | if (!request_region(res->start, SIS5595_EXTENT, | ||
| 534 | sis5595_driver.driver.name)) { | 503 | sis5595_driver.driver.name)) { | 
| 535 | err = -EBUSY; | 504 | err = -EBUSY; | 
| 536 | goto exit; | 505 | goto exit; | 
| 537 | } | 506 | } | 
| 538 | if (force_addr) { | ||
| 539 | dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", address); | ||
| 540 | if (PCIBIOS_SUCCESSFUL != | ||
| 541 | pci_write_config_word(s_bridge, SIS5595_BASE_REG, address)) | ||
| 542 | goto exit_release; | ||
| 543 | if (PCIBIOS_SUCCESSFUL != | ||
| 544 | pci_read_config_word(s_bridge, SIS5595_BASE_REG, &a)) | ||
| 545 | goto exit_release; | ||
| 546 | if ((a & ~(SIS5595_EXTENT - 1)) != address) | ||
| 547 | /* doesn't work for some chips? */ | ||
| 548 | goto exit_release; | ||
| 549 | } | ||
| 550 | |||
| 551 | if (PCIBIOS_SUCCESSFUL != | ||
| 552 | pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) { | ||
| 553 | goto exit_release; | ||
| 554 | } | ||
| 555 | if ((val & 0x80) == 0) { | ||
| 556 | if (PCIBIOS_SUCCESSFUL != | ||
| 557 | pci_write_config_byte(s_bridge, SIS5595_ENABLE_REG, | ||
| 558 | val | 0x80)) | ||
| 559 | goto exit_release; | ||
| 560 | if (PCIBIOS_SUCCESSFUL != | ||
| 561 | pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) | ||
| 562 | goto exit_release; | ||
| 563 | if ((val & 0x80) == 0) | ||
| 564 | /* doesn't work for some chips! */ | ||
| 565 | goto exit_release; | ||
| 566 | } | ||
| 567 | 507 | ||
| 568 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { | 508 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { | 
| 569 | err = -ENOMEM; | 509 | err = -ENOMEM; | 
| 570 | goto exit_release; | 510 | goto exit_release; | 
| 571 | } | 511 | } | 
| 572 | 512 | ||
| 573 | new_client = &data->client; | ||
| 574 | new_client->addr = address; | ||
| 575 | mutex_init(&data->lock); | 513 | mutex_init(&data->lock); | 
| 576 | i2c_set_clientdata(new_client, data); | 514 | mutex_init(&data->update_lock); | 
| 577 | new_client->adapter = adapter; | 515 | data->addr = res->start; | 
| 578 | new_client->driver = &sis5595_driver; | 516 | data->name = "sis5595"; | 
| 579 | new_client->flags = 0; | 517 | platform_set_drvdata(pdev, data); | 
| 580 | 518 | ||
| 581 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ | 519 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ | 
| 582 | pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision)); | 520 | pci_read_config_byte(s_bridge, PCI_REVISION_ID, &data->revision); | 
| 583 | /* 4 voltages, 1 temp */ | 521 | /* 4 voltages, 1 temp */ | 
| 584 | data->maxins = 3; | 522 | data->maxins = 3; | 
| 585 | if (data->revision >= REV2MIN) { | 523 | if (data->revision >= REV2MIN) { | 
| @@ -589,47 +527,37 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
| 589 | data->maxins = 4; | 527 | data->maxins = 4; | 
| 590 | } | 528 | } | 
| 591 | 529 | ||
| 592 | /* Fill in the remaining client fields and put it into the global list */ | ||
| 593 | strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); | ||
| 594 | |||
| 595 | data->valid = 0; | ||
| 596 | mutex_init(&data->update_lock); | ||
| 597 | |||
| 598 | /* Tell the I2C layer a new client has arrived */ | ||
| 599 | if ((err = i2c_attach_client(new_client))) | ||
| 600 | goto exit_free; | ||
| 601 | |||
| 602 | /* Initialize the SIS5595 chip */ | 530 | /* Initialize the SIS5595 chip */ | 
| 603 | sis5595_init_client(new_client); | 531 | sis5595_init_device(data); | 
| 604 | 532 | ||
| 605 | /* A few vars need to be filled upon startup */ | 533 | /* A few vars need to be filled upon startup */ | 
| 606 | for (i = 0; i < 2; i++) { | 534 | for (i = 0; i < 2; i++) { | 
| 607 | data->fan_min[i] = sis5595_read_value(new_client, | 535 | data->fan_min[i] = sis5595_read_value(data, | 
| 608 | SIS5595_REG_FAN_MIN(i)); | 536 | SIS5595_REG_FAN_MIN(i)); | 
| 609 | } | 537 | } | 
| 610 | 538 | ||
| 611 | /* Register sysfs hooks */ | 539 | /* Register sysfs hooks */ | 
| 612 | if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group))) | 540 | if ((err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group))) | 
| 613 | goto exit_detach; | 541 | goto exit_free; | 
| 614 | if (data->maxins == 4) { | 542 | if (data->maxins == 4) { | 
| 615 | if ((err = device_create_file(&new_client->dev, | 543 | if ((err = device_create_file(&pdev->dev, | 
| 616 | &dev_attr_in4_input)) | 544 | &sensor_dev_attr_in4_input.dev_attr)) | 
| 617 | || (err = device_create_file(&new_client->dev, | 545 | || (err = device_create_file(&pdev->dev, | 
| 618 | &dev_attr_in4_min)) | 546 | &sensor_dev_attr_in4_min.dev_attr)) | 
| 619 | || (err = device_create_file(&new_client->dev, | 547 | || (err = device_create_file(&pdev->dev, | 
| 620 | &dev_attr_in4_max))) | 548 | &sensor_dev_attr_in4_max.dev_attr))) | 
| 621 | goto exit_remove_files; | 549 | goto exit_remove_files; | 
| 622 | } else { | 550 | } else { | 
| 623 | if ((err = device_create_file(&new_client->dev, | 551 | if ((err = device_create_file(&pdev->dev, | 
| 624 | &dev_attr_temp1_input)) | 552 | &dev_attr_temp1_input)) | 
| 625 | || (err = device_create_file(&new_client->dev, | 553 | || (err = device_create_file(&pdev->dev, | 
| 626 | &dev_attr_temp1_max)) | 554 | &dev_attr_temp1_max)) | 
| 627 | || (err = device_create_file(&new_client->dev, | 555 | || (err = device_create_file(&pdev->dev, | 
| 628 | &dev_attr_temp1_max_hyst))) | 556 | &dev_attr_temp1_max_hyst))) | 
| 629 | goto exit_remove_files; | 557 | goto exit_remove_files; | 
| 630 | } | 558 | } | 
| 631 | 559 | ||
| 632 | data->class_dev = hwmon_device_register(&new_client->dev); | 560 | data->class_dev = hwmon_device_register(&pdev->dev); | 
| 633 | if (IS_ERR(data->class_dev)) { | 561 | if (IS_ERR(data->class_dev)) { | 
| 634 | err = PTR_ERR(data->class_dev); | 562 | err = PTR_ERR(data->class_dev); | 
| 635 | goto exit_remove_files; | 563 | goto exit_remove_files; | 
| @@ -638,32 +566,26 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
| 638 | return 0; | 566 | return 0; | 
| 639 | 567 | ||
| 640 | exit_remove_files: | 568 | exit_remove_files: | 
| 641 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group); | 569 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); | 
| 642 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt); | 570 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); | 
| 643 | exit_detach: | ||
| 644 | i2c_detach_client(new_client); | ||
| 645 | exit_free: | 571 | exit_free: | 
| 646 | kfree(data); | 572 | kfree(data); | 
| 647 | exit_release: | 573 | exit_release: | 
| 648 | release_region(address, SIS5595_EXTENT); | 574 | release_region(res->start, SIS5595_EXTENT); | 
| 649 | exit: | 575 | exit: | 
| 650 | return err; | 576 | return err; | 
| 651 | } | 577 | } | 
| 652 | 578 | ||
| 653 | static int sis5595_detach_client(struct i2c_client *client) | 579 | static int __devexit sis5595_remove(struct platform_device *pdev) | 
| 654 | { | 580 | { | 
| 655 | struct sis5595_data *data = i2c_get_clientdata(client); | 581 | struct sis5595_data *data = platform_get_drvdata(pdev); | 
| 656 | int err; | ||
| 657 | 582 | ||
| 658 | hwmon_device_unregister(data->class_dev); | 583 | hwmon_device_unregister(data->class_dev); | 
| 659 | sysfs_remove_group(&client->dev.kobj, &sis5595_group); | 584 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); | 
| 660 | sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt); | 585 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); | 
| 661 | |||
| 662 | if ((err = i2c_detach_client(client))) | ||
| 663 | return err; | ||
| 664 | |||
| 665 | release_region(client->addr, SIS5595_EXTENT); | ||
| 666 | 586 | ||
| 587 | release_region(data->addr, SIS5595_EXTENT); | ||
| 588 | platform_set_drvdata(pdev, NULL); | ||
| 667 | kfree(data); | 589 | kfree(data); | 
| 668 | 590 | ||
| 669 | return 0; | 591 | return 0; | 
| @@ -671,41 +593,37 @@ static int sis5595_detach_client(struct i2c_client *client) | |||
| 671 | 593 | ||
| 672 | 594 | ||
| 673 | /* ISA access must be locked explicitly. */ | 595 | /* ISA access must be locked explicitly. */ | 
| 674 | static int sis5595_read_value(struct i2c_client *client, u8 reg) | 596 | static int sis5595_read_value(struct sis5595_data *data, u8 reg) | 
| 675 | { | 597 | { | 
| 676 | int res; | 598 | int res; | 
| 677 | 599 | ||
| 678 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
| 679 | mutex_lock(&data->lock); | 600 | mutex_lock(&data->lock); | 
| 680 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 601 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); | 
| 681 | res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); | 602 | res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET); | 
| 682 | mutex_unlock(&data->lock); | 603 | mutex_unlock(&data->lock); | 
| 683 | return res; | 604 | return res; | 
| 684 | } | 605 | } | 
| 685 | 606 | ||
| 686 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) | 607 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value) | 
| 687 | { | 608 | { | 
| 688 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
| 689 | mutex_lock(&data->lock); | 609 | mutex_lock(&data->lock); | 
| 690 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 610 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); | 
| 691 | outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); | 611 | outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET); | 
| 692 | mutex_unlock(&data->lock); | 612 | mutex_unlock(&data->lock); | 
| 693 | return 0; | ||
| 694 | } | 613 | } | 
| 695 | 614 | ||
| 696 | /* Called when we have found a new SIS5595. */ | 615 | /* Called when we have found a new SIS5595. */ | 
| 697 | static void sis5595_init_client(struct i2c_client *client) | 616 | static void __devinit sis5595_init_device(struct sis5595_data *data) | 
| 698 | { | 617 | { | 
| 699 | u8 config = sis5595_read_value(client, SIS5595_REG_CONFIG); | 618 | u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG); | 
| 700 | if (!(config & 0x01)) | 619 | if (!(config & 0x01)) | 
| 701 | sis5595_write_value(client, SIS5595_REG_CONFIG, | 620 | sis5595_write_value(data, SIS5595_REG_CONFIG, | 
| 702 | (config & 0xf7) | 0x01); | 621 | (config & 0xf7) | 0x01); | 
| 703 | } | 622 | } | 
| 704 | 623 | ||
| 705 | static struct sis5595_data *sis5595_update_device(struct device *dev) | 624 | static struct sis5595_data *sis5595_update_device(struct device *dev) | 
| 706 | { | 625 | { | 
| 707 | struct i2c_client *client = to_i2c_client(dev); | 626 | struct sis5595_data *data = dev_get_drvdata(dev); | 
| 708 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
| 709 | int i; | 627 | int i; | 
| 710 | 628 | ||
| 711 | mutex_lock(&data->update_lock); | 629 | mutex_lock(&data->update_lock); | 
| @@ -715,35 +633,35 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) | |||
| 715 | 633 | ||
| 716 | for (i = 0; i <= data->maxins; i++) { | 634 | for (i = 0; i <= data->maxins; i++) { | 
| 717 | data->in[i] = | 635 | data->in[i] = | 
| 718 | sis5595_read_value(client, SIS5595_REG_IN(i)); | 636 | sis5595_read_value(data, SIS5595_REG_IN(i)); | 
| 719 | data->in_min[i] = | 637 | data->in_min[i] = | 
| 720 | sis5595_read_value(client, | 638 | sis5595_read_value(data, | 
| 721 | SIS5595_REG_IN_MIN(i)); | 639 | SIS5595_REG_IN_MIN(i)); | 
| 722 | data->in_max[i] = | 640 | data->in_max[i] = | 
| 723 | sis5595_read_value(client, | 641 | sis5595_read_value(data, | 
| 724 | SIS5595_REG_IN_MAX(i)); | 642 | SIS5595_REG_IN_MAX(i)); | 
| 725 | } | 643 | } | 
| 726 | for (i = 0; i < 2; i++) { | 644 | for (i = 0; i < 2; i++) { | 
| 727 | data->fan[i] = | 645 | data->fan[i] = | 
| 728 | sis5595_read_value(client, SIS5595_REG_FAN(i)); | 646 | sis5595_read_value(data, SIS5595_REG_FAN(i)); | 
| 729 | data->fan_min[i] = | 647 | data->fan_min[i] = | 
| 730 | sis5595_read_value(client, | 648 | sis5595_read_value(data, | 
| 731 | SIS5595_REG_FAN_MIN(i)); | 649 | SIS5595_REG_FAN_MIN(i)); | 
| 732 | } | 650 | } | 
| 733 | if (data->maxins == 3) { | 651 | if (data->maxins == 3) { | 
| 734 | data->temp = | 652 | data->temp = | 
| 735 | sis5595_read_value(client, SIS5595_REG_TEMP); | 653 | sis5595_read_value(data, SIS5595_REG_TEMP); | 
| 736 | data->temp_over = | 654 | data->temp_over = | 
| 737 | sis5595_read_value(client, SIS5595_REG_TEMP_OVER); | 655 | sis5595_read_value(data, SIS5595_REG_TEMP_OVER); | 
| 738 | data->temp_hyst = | 656 | data->temp_hyst = | 
| 739 | sis5595_read_value(client, SIS5595_REG_TEMP_HYST); | 657 | sis5595_read_value(data, SIS5595_REG_TEMP_HYST); | 
| 740 | } | 658 | } | 
| 741 | i = sis5595_read_value(client, SIS5595_REG_FANDIV); | 659 | i = sis5595_read_value(data, SIS5595_REG_FANDIV); | 
| 742 | data->fan_div[0] = (i >> 4) & 0x03; | 660 | data->fan_div[0] = (i >> 4) & 0x03; | 
| 743 | data->fan_div[1] = i >> 6; | 661 | data->fan_div[1] = i >> 6; | 
| 744 | data->alarms = | 662 | data->alarms = | 
| 745 | sis5595_read_value(client, SIS5595_REG_ALARM1) | | 663 | sis5595_read_value(data, SIS5595_REG_ALARM1) | | 
| 746 | (sis5595_read_value(client, SIS5595_REG_ALARM2) << 8); | 664 | (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8); | 
| 747 | data->last_updated = jiffies; | 665 | data->last_updated = jiffies; | 
| 748 | data->valid = 1; | 666 | data->valid = 1; | 
| 749 | } | 667 | } | 
| @@ -774,10 +692,50 @@ static int blacklist[] __devinitdata = { | |||
| 774 | PCI_DEVICE_ID_SI_5598, | 692 | PCI_DEVICE_ID_SI_5598, | 
| 775 | 0 }; | 693 | 0 }; | 
| 776 | 694 | ||
| 695 | static int __devinit sis5595_device_add(unsigned short address) | ||
| 696 | { | ||
| 697 | struct resource res = { | ||
| 698 | .start = address, | ||
| 699 | .end = address + SIS5595_EXTENT - 1, | ||
| 700 | .name = "sis5595", | ||
| 701 | .flags = IORESOURCE_IO, | ||
| 702 | }; | ||
| 703 | int err; | ||
| 704 | |||
| 705 | pdev = platform_device_alloc("sis5595", address); | ||
| 706 | if (!pdev) { | ||
| 707 | err = -ENOMEM; | ||
| 708 | printk(KERN_ERR "sis5595: Device allocation failed\n"); | ||
| 709 | goto exit; | ||
| 710 | } | ||
| 711 | |||
| 712 | err = platform_device_add_resources(pdev, &res, 1); | ||
| 713 | if (err) { | ||
| 714 | printk(KERN_ERR "sis5595: Device resource addition failed " | ||
| 715 | "(%d)\n", err); | ||
| 716 | goto exit_device_put; | ||
| 717 | } | ||
| 718 | |||
| 719 | err = platform_device_add(pdev); | ||
| 720 | if (err) { | ||
| 721 | printk(KERN_ERR "sis5595: Device addition failed (%d)\n", | ||
| 722 | err); | ||
| 723 | goto exit_device_put; | ||
| 724 | } | ||
| 725 | |||
| 726 | return 0; | ||
| 727 | |||
| 728 | exit_device_put: | ||
| 729 | platform_device_put(pdev); | ||
| 730 | exit: | ||
| 731 | return err; | ||
| 732 | } | ||
| 733 | |||
| 777 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, | 734 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, | 
| 778 | const struct pci_device_id *id) | 735 | const struct pci_device_id *id) | 
| 779 | { | 736 | { | 
| 780 | u16 val; | 737 | u16 address; | 
| 738 | u8 enable; | ||
| 781 | int *i; | 739 | int *i; | 
| 782 | 740 | ||
| 783 | for (i = blacklist; *i != 0; i++) { | 741 | for (i = blacklist; *i != 0; i++) { | 
| @@ -790,27 +748,68 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev, | |||
| 790 | } | 748 | } | 
| 791 | } | 749 | } | 
| 792 | 750 | ||
| 751 | force_addr &= ~(SIS5595_EXTENT - 1); | ||
| 752 | if (force_addr) { | ||
| 753 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); | ||
| 754 | pci_write_config_word(dev, SIS5595_BASE_REG, force_addr); | ||
| 755 | } | ||
| 756 | |||
| 793 | if (PCIBIOS_SUCCESSFUL != | 757 | if (PCIBIOS_SUCCESSFUL != | 
| 794 | pci_read_config_word(dev, SIS5595_BASE_REG, &val)) | 758 | pci_read_config_word(dev, SIS5595_BASE_REG, &address)) { | 
| 759 | dev_err(&dev->dev, "Failed to read ISA address\n"); | ||
| 795 | return -ENODEV; | 760 | return -ENODEV; | 
| 761 | } | ||
| 796 | 762 | ||
| 797 | address = val & ~(SIS5595_EXTENT - 1); | 763 | address &= ~(SIS5595_EXTENT - 1); | 
| 798 | if (address == 0 && force_addr == 0) { | 764 | if (!address) { | 
| 799 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 765 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 
| 800 | return -ENODEV; | 766 | return -ENODEV; | 
| 801 | } | 767 | } | 
| 768 | if (force_addr && address != force_addr) { | ||
| 769 | /* doesn't work for some chips? */ | ||
| 770 | dev_err(&dev->dev, "Failed to force ISA address\n"); | ||
| 771 | return -ENODEV; | ||
| 772 | } | ||
| 802 | 773 | ||
| 803 | s_bridge = pci_dev_get(dev); | 774 | if (PCIBIOS_SUCCESSFUL != | 
| 804 | if (i2c_isa_add_driver(&sis5595_driver)) { | 775 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) { | 
| 805 | pci_dev_put(s_bridge); | 776 | dev_err(&dev->dev, "Failed to read enable register\n"); | 
| 806 | s_bridge = NULL; | 777 | return -ENODEV; | 
| 778 | } | ||
| 779 | if (!(enable & 0x80)) { | ||
| 780 | if ((PCIBIOS_SUCCESSFUL != | ||
| 781 | pci_write_config_byte(dev, SIS5595_ENABLE_REG, | ||
| 782 | enable | 0x80)) | ||
| 783 | || (PCIBIOS_SUCCESSFUL != | ||
| 784 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) | ||
| 785 | || (!(enable & 0x80))) { | ||
| 786 | /* doesn't work for some chips! */ | ||
| 787 | dev_err(&dev->dev, "Failed to enable HWM device\n"); | ||
| 788 | return -ENODEV; | ||
| 789 | } | ||
| 807 | } | 790 | } | 
| 808 | 791 | ||
| 792 | if (platform_driver_register(&sis5595_driver)) { | ||
| 793 | dev_dbg(&dev->dev, "Failed to register sis5595 driver\n"); | ||
| 794 | goto exit; | ||
| 795 | } | ||
| 796 | |||
| 797 | s_bridge = pci_dev_get(dev); | ||
| 798 | /* Sets global pdev as a side effect */ | ||
| 799 | if (sis5595_device_add(address)) | ||
| 800 | goto exit_unregister; | ||
| 801 | |||
| 809 | /* Always return failure here. This is to allow other drivers to bind | 802 | /* Always return failure here. This is to allow other drivers to bind | 
| 810 | * to this pci device. We don't really want to have control over the | 803 | * to this pci device. We don't really want to have control over the | 
| 811 | * pci device, we only wanted to read as few register values from it. | 804 | * pci device, we only wanted to read as few register values from it. | 
| 812 | */ | 805 | */ | 
| 813 | return -ENODEV; | 806 | return -ENODEV; | 
| 807 | |||
| 808 | exit_unregister: | ||
| 809 | pci_dev_put(dev); | ||
| 810 | platform_driver_unregister(&sis5595_driver); | ||
| 811 | exit: | ||
| 812 | return -ENODEV; | ||
| 814 | } | 813 | } | 
| 815 | 814 | ||
| 816 | static struct pci_driver sis5595_pci_driver = { | 815 | static struct pci_driver sis5595_pci_driver = { | 
| @@ -828,7 +827,8 @@ static void __exit sm_sis5595_exit(void) | |||
| 828 | { | 827 | { | 
| 829 | pci_unregister_driver(&sis5595_pci_driver); | 828 | pci_unregister_driver(&sis5595_pci_driver); | 
| 830 | if (s_bridge != NULL) { | 829 | if (s_bridge != NULL) { | 
| 831 | i2c_isa_del_driver(&sis5595_driver); | 830 | platform_device_unregister(pdev); | 
| 831 | platform_driver_unregister(&sis5595_driver); | ||
| 832 | pci_dev_put(s_bridge); | 832 | pci_dev_put(s_bridge); | 
| 833 | s_bridge = NULL; | 833 | s_bridge = NULL; | 
| 834 | } | 834 | } | 
