diff options
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/Kconfig | 3 | ||||
-rw-r--r-- | drivers/hwmon/sis5595.c | 323 |
2 files changed, 177 insertions, 149 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index b432584c49a8..398a52e163e4 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -431,8 +431,7 @@ config SENSORS_PC87427 | |||
431 | 431 | ||
432 | config SENSORS_SIS5595 | 432 | config SENSORS_SIS5595 |
433 | tristate "Silicon Integrated Systems Corp. SiS5595" | 433 | tristate "Silicon Integrated Systems Corp. SiS5595" |
434 | depends on I2C && PCI && EXPERIMENTAL | 434 | depends on PCI |
435 | select I2C_ISA | ||
436 | help | 435 | help |
437 | If you say yes here you get support for the integrated sensors in | 436 | If you say yes here you get support for the integrated sensors in |
438 | SiS5595 South Bridges. | 437 | SiS5595 South Bridges. |
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 3f400263fc0f..c56bae3bd4c7 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -54,8 +54,7 @@ | |||
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> |
60 | #include <linux/err.h> | 59 | #include <linux/err.h> |
61 | #include <linux/init.h> | 60 | #include <linux/init.h> |
@@ -72,10 +71,7 @@ module_param(force_addr, ushort, 0); | |||
72 | MODULE_PARM_DESC(force_addr, | 71 | MODULE_PARM_DESC(force_addr, |
73 | "Initialize the base address of the sensors"); | 72 | "Initialize the base address of the sensors"); |
74 | 73 | ||
75 | /* Device address | 74 | 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 | 75 | ||
80 | /* Many SIS5595 constants specified below */ | 76 | /* Many SIS5595 constants specified below */ |
81 | 77 | ||
@@ -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,21 +186,21 @@ 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 */ |
@@ -228,13 +225,12 @@ static ssize_t show_in_max(struct device *dev, char *buf, int nr) | |||
228 | static ssize_t set_in_min(struct device *dev, const char *buf, | 225 | static ssize_t set_in_min(struct device *dev, const char *buf, |
229 | size_t count, int nr) | 226 | size_t count, int nr) |
230 | { | 227 | { |
231 | struct i2c_client *client = to_i2c_client(dev); | 228 | struct sis5595_data *data = dev_get_drvdata(dev); |
232 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
233 | unsigned long val = simple_strtoul(buf, NULL, 10); | 229 | unsigned long val = simple_strtoul(buf, NULL, 10); |
234 | 230 | ||
235 | mutex_lock(&data->update_lock); | 231 | mutex_lock(&data->update_lock); |
236 | data->in_min[nr] = IN_TO_REG(val); | 232 | data->in_min[nr] = IN_TO_REG(val); |
237 | sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); | 233 | sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); |
238 | mutex_unlock(&data->update_lock); | 234 | mutex_unlock(&data->update_lock); |
239 | return count; | 235 | return count; |
240 | } | 236 | } |
@@ -242,13 +238,12 @@ static ssize_t set_in_min(struct device *dev, const char *buf, | |||
242 | static ssize_t set_in_max(struct device *dev, const char *buf, | 238 | static ssize_t set_in_max(struct device *dev, const char *buf, |
243 | size_t count, int nr) | 239 | size_t count, int nr) |
244 | { | 240 | { |
245 | struct i2c_client *client = to_i2c_client(dev); | 241 | struct sis5595_data *data = dev_get_drvdata(dev); |
246 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
247 | unsigned long val = simple_strtoul(buf, NULL, 10); | 242 | unsigned long val = simple_strtoul(buf, NULL, 10); |
248 | 243 | ||
249 | mutex_lock(&data->update_lock); | 244 | mutex_lock(&data->update_lock); |
250 | data->in_max[nr] = IN_TO_REG(val); | 245 | data->in_max[nr] = IN_TO_REG(val); |
251 | sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); | 246 | sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); |
252 | mutex_unlock(&data->update_lock); | 247 | mutex_unlock(&data->update_lock); |
253 | return count; | 248 | return count; |
254 | } | 249 | } |
@@ -307,13 +302,12 @@ static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, | |||
307 | 302 | ||
308 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 303 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
309 | { | 304 | { |
310 | struct i2c_client *client = to_i2c_client(dev); | 305 | 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); | 306 | long val = simple_strtol(buf, NULL, 10); |
313 | 307 | ||
314 | mutex_lock(&data->update_lock); | 308 | mutex_lock(&data->update_lock); |
315 | data->temp_over = TEMP_TO_REG(val); | 309 | data->temp_over = TEMP_TO_REG(val); |
316 | sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); | 310 | sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over); |
317 | mutex_unlock(&data->update_lock); | 311 | mutex_unlock(&data->update_lock); |
318 | return count; | 312 | return count; |
319 | } | 313 | } |
@@ -326,13 +320,12 @@ static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, | |||
326 | 320 | ||
327 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 321 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
328 | { | 322 | { |
329 | struct i2c_client *client = to_i2c_client(dev); | 323 | 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); | 324 | long val = simple_strtol(buf, NULL, 10); |
332 | 325 | ||
333 | mutex_lock(&data->update_lock); | 326 | mutex_lock(&data->update_lock); |
334 | data->temp_hyst = TEMP_TO_REG(val); | 327 | data->temp_hyst = TEMP_TO_REG(val); |
335 | sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); | 328 | sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst); |
336 | mutex_unlock(&data->update_lock); | 329 | mutex_unlock(&data->update_lock); |
337 | return count; | 330 | return count; |
338 | } | 331 | } |
@@ -361,13 +354,12 @@ static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | |||
361 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 354 | static ssize_t set_fan_min(struct device *dev, const char *buf, |
362 | size_t count, int nr) | 355 | size_t count, int nr) |
363 | { | 356 | { |
364 | struct i2c_client *client = to_i2c_client(dev); | 357 | struct sis5595_data *data = dev_get_drvdata(dev); |
365 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
366 | unsigned long val = simple_strtoul(buf, NULL, 10); | 358 | unsigned long val = simple_strtoul(buf, NULL, 10); |
367 | 359 | ||
368 | mutex_lock(&data->update_lock); | 360 | mutex_lock(&data->update_lock); |
369 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 361 | 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]); | 362 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
371 | mutex_unlock(&data->update_lock); | 363 | mutex_unlock(&data->update_lock); |
372 | return count; | 364 | return count; |
373 | } | 365 | } |
@@ -385,8 +377,7 @@ static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | |||
385 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 377 | static ssize_t set_fan_div(struct device *dev, const char *buf, |
386 | size_t count, int nr) | 378 | size_t count, int nr) |
387 | { | 379 | { |
388 | struct i2c_client *client = to_i2c_client(dev); | 380 | struct sis5595_data *data = dev_get_drvdata(dev); |
389 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
390 | unsigned long min; | 381 | unsigned long min; |
391 | unsigned long val = simple_strtoul(buf, NULL, 10); | 382 | unsigned long val = simple_strtoul(buf, NULL, 10); |
392 | int reg; | 383 | int reg; |
@@ -394,7 +385,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
394 | mutex_lock(&data->update_lock); | 385 | mutex_lock(&data->update_lock); |
395 | min = FAN_FROM_REG(data->fan_min[nr], | 386 | min = FAN_FROM_REG(data->fan_min[nr], |
396 | DIV_FROM_REG(data->fan_div[nr])); | 387 | DIV_FROM_REG(data->fan_div[nr])); |
397 | reg = sis5595_read_value(client, SIS5595_REG_FANDIV); | 388 | reg = sis5595_read_value(data, SIS5595_REG_FANDIV); |
398 | 389 | ||
399 | switch (val) { | 390 | switch (val) { |
400 | case 1: data->fan_div[nr] = 0; break; | 391 | case 1: data->fan_div[nr] = 0; break; |
@@ -402,7 +393,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
402 | case 4: data->fan_div[nr] = 2; break; | 393 | case 4: data->fan_div[nr] = 2; break; |
403 | case 8: data->fan_div[nr] = 3; break; | 394 | case 8: data->fan_div[nr] = 3; break; |
404 | default: | 395 | default: |
405 | dev_err(&client->dev, "fan_div value %ld not " | 396 | dev_err(dev, "fan_div value %ld not " |
406 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 397 | "supported. Choose one of 1, 2, 4 or 8!\n", val); |
407 | mutex_unlock(&data->update_lock); | 398 | mutex_unlock(&data->update_lock); |
408 | return -EINVAL; | 399 | return -EINVAL; |
@@ -416,10 +407,10 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
416 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); | 407 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); |
417 | break; | 408 | break; |
418 | } | 409 | } |
419 | sis5595_write_value(client, SIS5595_REG_FANDIV, reg); | 410 | sis5595_write_value(data, SIS5595_REG_FANDIV, reg); |
420 | data->fan_min[nr] = | 411 | data->fan_min[nr] = |
421 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 412 | 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]); | 413 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
423 | mutex_unlock(&data->update_lock); | 414 | mutex_unlock(&data->update_lock); |
424 | return count; | 415 | return count; |
425 | } | 416 | } |
@@ -473,6 +464,14 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch | |||
473 | } | 464 | } |
474 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 465 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
475 | 466 | ||
467 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
468 | char *buf) | ||
469 | { | ||
470 | struct sis5595_data *data = dev_get_drvdata(dev); | ||
471 | return sprintf(buf, "%s\n", data->name); | ||
472 | } | ||
473 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
474 | |||
476 | static struct attribute *sis5595_attributes[] = { | 475 | static struct attribute *sis5595_attributes[] = { |
477 | &dev_attr_in0_input.attr, | 476 | &dev_attr_in0_input.attr, |
478 | &dev_attr_in0_min.attr, | 477 | &dev_attr_in0_min.attr, |
@@ -495,6 +494,7 @@ static struct attribute *sis5595_attributes[] = { | |||
495 | &dev_attr_fan2_div.attr, | 494 | &dev_attr_fan2_div.attr, |
496 | 495 | ||
497 | &dev_attr_alarms.attr, | 496 | &dev_attr_alarms.attr, |
497 | &dev_attr_name.attr, | ||
498 | NULL | 498 | NULL |
499 | }; | 499 | }; |
500 | 500 | ||
@@ -518,65 +518,32 @@ static const struct attribute_group sis5595_group_opt = { | |||
518 | }; | 518 | }; |
519 | 519 | ||
520 | /* This is called when the module is loaded */ | 520 | /* This is called when the module is loaded */ |
521 | static int sis5595_detect(struct i2c_adapter *adapter) | 521 | static int __devinit sis5595_probe(struct platform_device *pdev) |
522 | { | 522 | { |
523 | int err = 0; | 523 | int err = 0; |
524 | int i; | 524 | int i; |
525 | struct i2c_client *new_client; | ||
526 | struct sis5595_data *data; | 525 | struct sis5595_data *data; |
526 | struct resource *res; | ||
527 | char val; | 527 | char val; |
528 | u16 a; | ||
529 | 528 | ||
530 | if (force_addr) | ||
531 | address = force_addr & ~(SIS5595_EXTENT - 1); | ||
532 | /* Reserve the ISA region */ | 529 | /* Reserve the ISA region */ |
533 | if (!request_region(address, SIS5595_EXTENT, | 530 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
531 | if (!request_region(res->start, SIS5595_EXTENT, | ||
534 | sis5595_driver.driver.name)) { | 532 | sis5595_driver.driver.name)) { |
535 | err = -EBUSY; | 533 | err = -EBUSY; |
536 | goto exit; | 534 | goto exit; |
537 | } | 535 | } |
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 | 536 | ||
568 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { | 537 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { |
569 | err = -ENOMEM; | 538 | err = -ENOMEM; |
570 | goto exit_release; | 539 | goto exit_release; |
571 | } | 540 | } |
572 | 541 | ||
573 | new_client = &data->client; | ||
574 | new_client->addr = address; | ||
575 | mutex_init(&data->lock); | 542 | mutex_init(&data->lock); |
576 | i2c_set_clientdata(new_client, data); | 543 | mutex_init(&data->update_lock); |
577 | new_client->adapter = adapter; | 544 | data->addr = res->start; |
578 | new_client->driver = &sis5595_driver; | 545 | data->name = "sis5595"; |
579 | new_client->flags = 0; | 546 | platform_set_drvdata(pdev, data); |
580 | 547 | ||
581 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ | 548 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ |
582 | pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision)); | 549 | pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision)); |
@@ -589,47 +556,37 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
589 | data->maxins = 4; | 556 | data->maxins = 4; |
590 | } | 557 | } |
591 | 558 | ||
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 */ | 559 | /* Initialize the SIS5595 chip */ |
603 | sis5595_init_client(new_client); | 560 | sis5595_init_device(data); |
604 | 561 | ||
605 | /* A few vars need to be filled upon startup */ | 562 | /* A few vars need to be filled upon startup */ |
606 | for (i = 0; i < 2; i++) { | 563 | for (i = 0; i < 2; i++) { |
607 | data->fan_min[i] = sis5595_read_value(new_client, | 564 | data->fan_min[i] = sis5595_read_value(data, |
608 | SIS5595_REG_FAN_MIN(i)); | 565 | SIS5595_REG_FAN_MIN(i)); |
609 | } | 566 | } |
610 | 567 | ||
611 | /* Register sysfs hooks */ | 568 | /* Register sysfs hooks */ |
612 | if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group))) | 569 | if ((err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group))) |
613 | goto exit_detach; | 570 | goto exit_free; |
614 | if (data->maxins == 4) { | 571 | if (data->maxins == 4) { |
615 | if ((err = device_create_file(&new_client->dev, | 572 | if ((err = device_create_file(&pdev->dev, |
616 | &dev_attr_in4_input)) | 573 | &dev_attr_in4_input)) |
617 | || (err = device_create_file(&new_client->dev, | 574 | || (err = device_create_file(&pdev->dev, |
618 | &dev_attr_in4_min)) | 575 | &dev_attr_in4_min)) |
619 | || (err = device_create_file(&new_client->dev, | 576 | || (err = device_create_file(&pdev->dev, |
620 | &dev_attr_in4_max))) | 577 | &dev_attr_in4_max))) |
621 | goto exit_remove_files; | 578 | goto exit_remove_files; |
622 | } else { | 579 | } else { |
623 | if ((err = device_create_file(&new_client->dev, | 580 | if ((err = device_create_file(&pdev->dev, |
624 | &dev_attr_temp1_input)) | 581 | &dev_attr_temp1_input)) |
625 | || (err = device_create_file(&new_client->dev, | 582 | || (err = device_create_file(&pdev->dev, |
626 | &dev_attr_temp1_max)) | 583 | &dev_attr_temp1_max)) |
627 | || (err = device_create_file(&new_client->dev, | 584 | || (err = device_create_file(&pdev->dev, |
628 | &dev_attr_temp1_max_hyst))) | 585 | &dev_attr_temp1_max_hyst))) |
629 | goto exit_remove_files; | 586 | goto exit_remove_files; |
630 | } | 587 | } |
631 | 588 | ||
632 | data->class_dev = hwmon_device_register(&new_client->dev); | 589 | data->class_dev = hwmon_device_register(&pdev->dev); |
633 | if (IS_ERR(data->class_dev)) { | 590 | if (IS_ERR(data->class_dev)) { |
634 | err = PTR_ERR(data->class_dev); | 591 | err = PTR_ERR(data->class_dev); |
635 | goto exit_remove_files; | 592 | goto exit_remove_files; |
@@ -638,32 +595,26 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
638 | return 0; | 595 | return 0; |
639 | 596 | ||
640 | exit_remove_files: | 597 | exit_remove_files: |
641 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group); | 598 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
642 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt); | 599 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); |
643 | exit_detach: | ||
644 | i2c_detach_client(new_client); | ||
645 | exit_free: | 600 | exit_free: |
646 | kfree(data); | 601 | kfree(data); |
647 | exit_release: | 602 | exit_release: |
648 | release_region(address, SIS5595_EXTENT); | 603 | release_region(res->start, SIS5595_EXTENT); |
649 | exit: | 604 | exit: |
650 | return err; | 605 | return err; |
651 | } | 606 | } |
652 | 607 | ||
653 | static int sis5595_detach_client(struct i2c_client *client) | 608 | static int __devexit sis5595_remove(struct platform_device *pdev) |
654 | { | 609 | { |
655 | struct sis5595_data *data = i2c_get_clientdata(client); | 610 | struct sis5595_data *data = platform_get_drvdata(pdev); |
656 | int err; | ||
657 | 611 | ||
658 | hwmon_device_unregister(data->class_dev); | 612 | hwmon_device_unregister(data->class_dev); |
659 | sysfs_remove_group(&client->dev.kobj, &sis5595_group); | 613 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
660 | sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt); | 614 | 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 | 615 | ||
616 | release_region(data->addr, SIS5595_EXTENT); | ||
617 | platform_set_drvdata(pdev, NULL); | ||
667 | kfree(data); | 618 | kfree(data); |
668 | 619 | ||
669 | return 0; | 620 | return 0; |
@@ -671,41 +622,37 @@ static int sis5595_detach_client(struct i2c_client *client) | |||
671 | 622 | ||
672 | 623 | ||
673 | /* ISA access must be locked explicitly. */ | 624 | /* ISA access must be locked explicitly. */ |
674 | static int sis5595_read_value(struct i2c_client *client, u8 reg) | 625 | static int sis5595_read_value(struct sis5595_data *data, u8 reg) |
675 | { | 626 | { |
676 | int res; | 627 | int res; |
677 | 628 | ||
678 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
679 | mutex_lock(&data->lock); | 629 | mutex_lock(&data->lock); |
680 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 630 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
681 | res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); | 631 | res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET); |
682 | mutex_unlock(&data->lock); | 632 | mutex_unlock(&data->lock); |
683 | return res; | 633 | return res; |
684 | } | 634 | } |
685 | 635 | ||
686 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) | 636 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value) |
687 | { | 637 | { |
688 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
689 | mutex_lock(&data->lock); | 638 | mutex_lock(&data->lock); |
690 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 639 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
691 | outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); | 640 | outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET); |
692 | mutex_unlock(&data->lock); | 641 | mutex_unlock(&data->lock); |
693 | return 0; | ||
694 | } | 642 | } |
695 | 643 | ||
696 | /* Called when we have found a new SIS5595. */ | 644 | /* Called when we have found a new SIS5595. */ |
697 | static void sis5595_init_client(struct i2c_client *client) | 645 | static void __devinit sis5595_init_device(struct sis5595_data *data) |
698 | { | 646 | { |
699 | u8 config = sis5595_read_value(client, SIS5595_REG_CONFIG); | 647 | u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG); |
700 | if (!(config & 0x01)) | 648 | if (!(config & 0x01)) |
701 | sis5595_write_value(client, SIS5595_REG_CONFIG, | 649 | sis5595_write_value(data, SIS5595_REG_CONFIG, |
702 | (config & 0xf7) | 0x01); | 650 | (config & 0xf7) | 0x01); |
703 | } | 651 | } |
704 | 652 | ||
705 | static struct sis5595_data *sis5595_update_device(struct device *dev) | 653 | static struct sis5595_data *sis5595_update_device(struct device *dev) |
706 | { | 654 | { |
707 | struct i2c_client *client = to_i2c_client(dev); | 655 | struct sis5595_data *data = dev_get_drvdata(dev); |
708 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
709 | int i; | 656 | int i; |
710 | 657 | ||
711 | mutex_lock(&data->update_lock); | 658 | mutex_lock(&data->update_lock); |
@@ -715,35 +662,35 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) | |||
715 | 662 | ||
716 | for (i = 0; i <= data->maxins; i++) { | 663 | for (i = 0; i <= data->maxins; i++) { |
717 | data->in[i] = | 664 | data->in[i] = |
718 | sis5595_read_value(client, SIS5595_REG_IN(i)); | 665 | sis5595_read_value(data, SIS5595_REG_IN(i)); |
719 | data->in_min[i] = | 666 | data->in_min[i] = |
720 | sis5595_read_value(client, | 667 | sis5595_read_value(data, |
721 | SIS5595_REG_IN_MIN(i)); | 668 | SIS5595_REG_IN_MIN(i)); |
722 | data->in_max[i] = | 669 | data->in_max[i] = |
723 | sis5595_read_value(client, | 670 | sis5595_read_value(data, |
724 | SIS5595_REG_IN_MAX(i)); | 671 | SIS5595_REG_IN_MAX(i)); |
725 | } | 672 | } |
726 | for (i = 0; i < 2; i++) { | 673 | for (i = 0; i < 2; i++) { |
727 | data->fan[i] = | 674 | data->fan[i] = |
728 | sis5595_read_value(client, SIS5595_REG_FAN(i)); | 675 | sis5595_read_value(data, SIS5595_REG_FAN(i)); |
729 | data->fan_min[i] = | 676 | data->fan_min[i] = |
730 | sis5595_read_value(client, | 677 | sis5595_read_value(data, |
731 | SIS5595_REG_FAN_MIN(i)); | 678 | SIS5595_REG_FAN_MIN(i)); |
732 | } | 679 | } |
733 | if (data->maxins == 3) { | 680 | if (data->maxins == 3) { |
734 | data->temp = | 681 | data->temp = |
735 | sis5595_read_value(client, SIS5595_REG_TEMP); | 682 | sis5595_read_value(data, SIS5595_REG_TEMP); |
736 | data->temp_over = | 683 | data->temp_over = |
737 | sis5595_read_value(client, SIS5595_REG_TEMP_OVER); | 684 | sis5595_read_value(data, SIS5595_REG_TEMP_OVER); |
738 | data->temp_hyst = | 685 | data->temp_hyst = |
739 | sis5595_read_value(client, SIS5595_REG_TEMP_HYST); | 686 | sis5595_read_value(data, SIS5595_REG_TEMP_HYST); |
740 | } | 687 | } |
741 | i = sis5595_read_value(client, SIS5595_REG_FANDIV); | 688 | i = sis5595_read_value(data, SIS5595_REG_FANDIV); |
742 | data->fan_div[0] = (i >> 4) & 0x03; | 689 | data->fan_div[0] = (i >> 4) & 0x03; |
743 | data->fan_div[1] = i >> 6; | 690 | data->fan_div[1] = i >> 6; |
744 | data->alarms = | 691 | data->alarms = |
745 | sis5595_read_value(client, SIS5595_REG_ALARM1) | | 692 | sis5595_read_value(data, SIS5595_REG_ALARM1) | |
746 | (sis5595_read_value(client, SIS5595_REG_ALARM2) << 8); | 693 | (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8); |
747 | data->last_updated = jiffies; | 694 | data->last_updated = jiffies; |
748 | data->valid = 1; | 695 | data->valid = 1; |
749 | } | 696 | } |
@@ -774,10 +721,50 @@ static int blacklist[] __devinitdata = { | |||
774 | PCI_DEVICE_ID_SI_5598, | 721 | PCI_DEVICE_ID_SI_5598, |
775 | 0 }; | 722 | 0 }; |
776 | 723 | ||
724 | static int __devinit sis5595_device_add(unsigned short address) | ||
725 | { | ||
726 | struct resource res = { | ||
727 | .start = address, | ||
728 | .end = address + SIS5595_EXTENT - 1, | ||
729 | .name = "sis5595", | ||
730 | .flags = IORESOURCE_IO, | ||
731 | }; | ||
732 | int err; | ||
733 | |||
734 | pdev = platform_device_alloc("sis5595", address); | ||
735 | if (!pdev) { | ||
736 | err = -ENOMEM; | ||
737 | printk(KERN_ERR "sis5595: Device allocation failed\n"); | ||
738 | goto exit; | ||
739 | } | ||
740 | |||
741 | err = platform_device_add_resources(pdev, &res, 1); | ||
742 | if (err) { | ||
743 | printk(KERN_ERR "sis5595: Device resource addition failed " | ||
744 | "(%d)\n", err); | ||
745 | goto exit_device_put; | ||
746 | } | ||
747 | |||
748 | err = platform_device_add(pdev); | ||
749 | if (err) { | ||
750 | printk(KERN_ERR "sis5595: Device addition failed (%d)\n", | ||
751 | err); | ||
752 | goto exit_device_put; | ||
753 | } | ||
754 | |||
755 | return 0; | ||
756 | |||
757 | exit_device_put: | ||
758 | platform_device_put(pdev); | ||
759 | exit: | ||
760 | return err; | ||
761 | } | ||
762 | |||
777 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, | 763 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, |
778 | const struct pci_device_id *id) | 764 | const struct pci_device_id *id) |
779 | { | 765 | { |
780 | u16 val; | 766 | u16 address; |
767 | u8 enable; | ||
781 | int *i; | 768 | int *i; |
782 | 769 | ||
783 | for (i = blacklist; *i != 0; i++) { | 770 | for (i = blacklist; *i != 0; i++) { |
@@ -790,27 +777,68 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev, | |||
790 | } | 777 | } |
791 | } | 778 | } |
792 | 779 | ||
780 | force_addr &= ~(SIS5595_EXTENT - 1); | ||
781 | if (force_addr) { | ||
782 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); | ||
783 | pci_write_config_word(dev, SIS5595_BASE_REG, force_addr); | ||
784 | } | ||
785 | |||
793 | if (PCIBIOS_SUCCESSFUL != | 786 | if (PCIBIOS_SUCCESSFUL != |
794 | pci_read_config_word(dev, SIS5595_BASE_REG, &val)) | 787 | pci_read_config_word(dev, SIS5595_BASE_REG, &address)) { |
788 | dev_err(&dev->dev, "Failed to read ISA address\n"); | ||
795 | return -ENODEV; | 789 | return -ENODEV; |
790 | } | ||
796 | 791 | ||
797 | address = val & ~(SIS5595_EXTENT - 1); | 792 | address &= ~(SIS5595_EXTENT - 1); |
798 | if (address == 0 && force_addr == 0) { | 793 | if (!address) { |
799 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 794 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); |
800 | return -ENODEV; | 795 | return -ENODEV; |
801 | } | 796 | } |
797 | if (force_addr && address != force_addr) { | ||
798 | /* doesn't work for some chips? */ | ||
799 | dev_err(&dev->dev, "Failed to force ISA address\n"); | ||
800 | return -ENODEV; | ||
801 | } | ||
802 | 802 | ||
803 | s_bridge = pci_dev_get(dev); | 803 | if (PCIBIOS_SUCCESSFUL != |
804 | if (i2c_isa_add_driver(&sis5595_driver)) { | 804 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) { |
805 | pci_dev_put(s_bridge); | 805 | dev_err(&dev->dev, "Failed to read enable register\n"); |
806 | s_bridge = NULL; | 806 | return -ENODEV; |
807 | } | ||
808 | if (!(enable & 0x80)) { | ||
809 | if ((PCIBIOS_SUCCESSFUL != | ||
810 | pci_write_config_byte(dev, SIS5595_ENABLE_REG, | ||
811 | enable | 0x80)) | ||
812 | || (PCIBIOS_SUCCESSFUL != | ||
813 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) | ||
814 | || (!(enable & 0x80))) { | ||
815 | /* doesn't work for some chips! */ | ||
816 | dev_err(&dev->dev, "Failed to enable HWM device\n"); | ||
817 | return -ENODEV; | ||
818 | } | ||
807 | } | 819 | } |
808 | 820 | ||
821 | if (platform_driver_register(&sis5595_driver)) { | ||
822 | dev_dbg(&dev->dev, "Failed to register sis5595 driver\n"); | ||
823 | goto exit; | ||
824 | } | ||
825 | |||
826 | s_bridge = pci_dev_get(dev); | ||
827 | /* Sets global pdev as a side effect */ | ||
828 | if (sis5595_device_add(address)) | ||
829 | goto exit_unregister; | ||
830 | |||
809 | /* Always return failure here. This is to allow other drivers to bind | 831 | /* 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 | 832 | * 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. | 833 | * pci device, we only wanted to read as few register values from it. |
812 | */ | 834 | */ |
813 | return -ENODEV; | 835 | return -ENODEV; |
836 | |||
837 | exit_unregister: | ||
838 | pci_dev_put(dev); | ||
839 | platform_driver_unregister(&sis5595_driver); | ||
840 | exit: | ||
841 | return -ENODEV; | ||
814 | } | 842 | } |
815 | 843 | ||
816 | static struct pci_driver sis5595_pci_driver = { | 844 | static struct pci_driver sis5595_pci_driver = { |
@@ -828,7 +856,8 @@ static void __exit sm_sis5595_exit(void) | |||
828 | { | 856 | { |
829 | pci_unregister_driver(&sis5595_pci_driver); | 857 | pci_unregister_driver(&sis5595_pci_driver); |
830 | if (s_bridge != NULL) { | 858 | if (s_bridge != NULL) { |
831 | i2c_isa_del_driver(&sis5595_driver); | 859 | platform_device_unregister(pdev); |
860 | platform_driver_unregister(&sis5595_driver); | ||
832 | pci_dev_put(s_bridge); | 861 | pci_dev_put(s_bridge); |
833 | s_bridge = NULL; | 862 | s_bridge = NULL; |
834 | } | 863 | } |