get rid of i2c-isa - h now - fixes of w82627ehf
Hi all,
Thanks for the review. I fixed the issues. Moreover I did:
0) fixed the Kconfig - deps fixed plus now it mentions the DHG.
1) forgot the name attribute - so it is fixed now
2) removed unsigned short address * (I put that into sio_data)
3) removed global REG and VAL for sio access
4) chip w83627ehg report its name in "name" attribute as w83627ehf to preserve compatibility of libsensors
4) changed the resource handling, platform device allocates the full 8byte region, and report itself there with sio name. So in my case:
0290-0297 : W83627EHG
0295-0296 : w83627ehf
The datasheet mentions that the chip decodes just +5 and +6 but it also mentions that last three bits belong to the chip. I must check if it will hoose acpi pnp or not.
David, this patch works for me, care to test it on DHG too? (Again be careful, this is very hot patch ;) Maybe you can read and check the DHG specific changes.
Thanks,
Rudolf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: w83627ehf-convert-to-platform-driver.patch
Type: text/x-diff
Size: 38392 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20070311/f8cca0b2/attachment-0001.bin
Hi Rudolf,
I cannot compile today, so I will report tomorrow whether the module compiles OK and if it loads.
The sio_names[] array is the same as the names[] array:
Review
Quoted 5 lines
(quoted diff) +5
-0+static const char *sio_names[] = { + "W83627EHF", + "W83627EHG", + "W83627DHG", +};
What is the difference between sio_names[] and names[] ? Why does capitalization matter?
Review
Quoted 13 lines
(quoted diff) +9
-2+static int __devinit w83627ehf_probe(struct platform_device *pdev) { - struct i2c_client *client; struct w83627ehf_data *data; - struct device *dev; + struct device *dev = &pdev->dev; + struct w83627ehf_sio_data *sio_data = dev->platform_data; + struct resource *res; + static const char *names[] = { + "w83627ehf", + "w83627ehf", /* treat ehg as ehf (same features) */ + "w83627dhg", + };
It would be less code / less bytes to only use one array. If sio_names[] and names[] are identical, sio_data->name and data->name are the same thing as well. Am I missing something?
Review line 84
Quoted 10 lines
(quoted diff) +2
-3@@ -83,38 +79,37 @@ #define SIO_ID_MASK 0xFFF0 static inline void -superio_outb(int reg, int val) +superio_outb(int reg, int val, int ioreg) { - outb(reg, REG); - outb(val, VAL); + outb(reg, ioreg + 1);
Should not be ioreg + 1 here. When I apply the patch tomorrow, I'll manually change that to ioreg.
Quoted 17 lines
(quoted diff) +4
-4+ outb(val, ioreg + 1); } static inline int -superio_inb(int reg) -{ - outb(reg, REG); - return inb(VAL); +superio_inb(int reg, int ioreg) +{ outb(reg, ioreg); + return inb(ioreg + 1); }
Review line 293
Quoted 6 lines
(quoted diff) +3
-0@@ -290,6 +288,17 @@ u8 fan_stop_time[4]; }; +/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This + * value is also used in w83627ehf_detect() to export a device name in sysfs + * (e.g. w83627ehf or w83627dhg) */
This comment does not apply any more. w83627ehf_device_remove_files() and w83627ehf_probe() use data->in_num and not data->kind, but is the correct code and does not need additional explanation. I think we can delete the comment completely.
Quoted 5 lines
(quoted diff) +5
-0+ +struct w83627ehf_sio_data { + enum kinds kind; + int sioreg; /* IO base for Super I/O */ + int hm_base; /* IO base of hw monitor block */
Review
Quoted 10 lines
(quoted diff) +3
-4+ const char *name; +}; + -static int w83627ehf_detach_client(struct i2c_client *client) -{ - struct w83627ehf_data *data = i2c_get_clientdata(client); - int err;
I don't understand why int err is deleted here. Does this compile? I have not compiled it yet.
Review
Quoted 12 lines
(quoted diff) +8
-0+static int __devexit w83627ehf_remove(struct platform_device *pdev) +{ + pdev = platform_device_alloc(DRVNAME, sio_data->hm_base); + if (!pdev) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit; + }
AFAICS we don't need a goto here. Would not a return err eliminate the goto and the exit: label below?
Review
Quoted 9 lines
(quoted diff) +8
-1- return i2c_isa_add_driver(&w83627ehf_driver); + err = platform_driver_register(&w83627ehf_driver); + if (err) + goto exit; + + /* Sets global pdev as a side effect */ + err = w83627ehf_device_add(&sio_data); + if (err) + goto exit_driver;
Could also remove the goto here. goto exit could be return err. goto exit_driver could be:
+ if (err) {
+ platform_driver_unregister(&w83627ehf_driver);
+ return err;
+ }
Hope that helps,
David
Quoted 32 lines · Rudolf Marek
Hi all,
Thanks for the review. I fixed the issues. Moreover I did:
0) fixed the
Kconfig- deps fixed plus now it mentions the DHG.
1) forgot the name attribute - so it is fixed now
2) removed unsigned short address * (I put that intosio_data)
3) removed global REG and VAL for sio access
4) chip w83627ehg report its name in "name" attribute as w83627ehf to preserve compatibility of libsensors
4) changed the resource handling, platform device allocates the full 8byte region, and report itself there with sio name. So in my case:0290-0297 : W83627EHG
0295-0296 : w83627ehfThe datasheet mentions that the chip decodes just +5 and +6 but it also mentions
that last three bits belong to the chip. I must check if it will hoose acpi pnp
or not.David, this patch works for me, care to test it on DHG too? (Again be careful,
this is very hot patch ;) Maybe you can read and check the DHG specific changes.Thanks,
Rudolf
Hi David,
Quoted 25 lines · David Hubbard
Hi Rudolf,
I cannot compile today, so I will report tomorrow whether the module compiles OK and if it loads.
The sio_names[] array is the same as the names[] array:
Review
Quoted 5 lines
(quoted diff) +5
-0+static const char *sio_names[] = { + "W83627EHF", + "W83627EHG", + "W83627DHG", +};What is the difference between sio_names[] and names[] ? Why does capitalization matter?
Quoted 9 lines
(quoted diff) +5
-2+static int __devinit w83627ehf_probe(struct platform_device *pdev) { - struct i2c_client *client; struct w83627ehf_data *data; - struct device *dev; + struct device *dev = &pdev->dev; + struct w83627ehf_sio_data *sio_data = dev->platform_data; + struct resource *res; + static const char *names[] = {
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ "w83627ehf", + "w83627ehf", /* treat ehg as ehf (same features) */ + "w83627dhg", + };It would be less code / less bytes to only use one array. If sio_names[] and names[] are identical,
sio_data->nameanddata->nameare the same thing as well. Am I missing something?
The upper-case strings refer to device names, the lower-case strings refer to chip prefix as expected by libsensors. They are different things - as a matter of fact, we use prefix w83627eh_f_ the W83627EH_G_. It's convenient to use the same prefix for libsensors when two chips can be handled exactly the same way, but it is still valuable to print the exact chip name in the logs for debugging/support purposes.
In my w83627hf patch, I've made the upper-case strings __initdata so they are removed from memory after driver initialization.
Quoted 14 lines
Review line 84
Quoted 10 lines
(quoted diff) +2
-3@@ -83,38 +79,37 @@ #define SIO_ID_MASK 0xFFF0 static inline void -superio_outb(int reg, int val) +superio_outb(int reg, int val, int ioreg) { - outb(reg, REG); - outb(val, VAL); + outb(reg, ioreg + 1);Should not be ioreg + 1 here. When I apply the patch tomorrow, I'll manually change that to ioreg.
Quoted 2 lines
Review line 86
Quoted 2 lines
(quoted diff) +1
-0+ outb(val, ioreg + 1); }
Good catch.
Quoted 10 lines
Review line 94
Quoted 4 lines
(quoted diff) +0
-4-static int w83627ehf_detach_client(struct i2c_client *client) -{ - struct w83627ehf_data *data = i2c_get_clientdata(client); - int err;I don't understand why int err is deleted here. Does this compile? I have not compiled it yet.
Review line 88
Quoted 2 lines
(quoted diff) +2
-0+static int __devexit w83627ehf_remove(struct platform_device *pdev) +{
There's nothing which can actually fail in w83627ehf_remove, so what would we do with "err"?
Quoted 9 lines
Review line 94
Quoted 6 lines
(quoted diff) +6
-0+ pdev = platform_device_alloc(DRVNAME, sio_data->hm_base); + if (!pdev) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit; + }AFAICS we don't need a goto here. Would not a return err eliminate the goto and the exit: label below?
Unified error paths are considered a good practice.
Signature · 1 line
Jean Delvare
Hi Rudolf,
Quoted 6 lines · Rudolf Marek
Hi all,
Thanks for the review. I fixed the issues. Moreover I did:
0) fixed the
Kconfig- deps fixed plus now it mentions the DHG.
1) forgot the name attribute - so it is fixed now
Yeah, I was bitten by this one too ;)
Quoted 2 lines
2) removed unsigned short address * (I put that into
sio_data)
3) removed global REG and VAL for sio access
I would have prefered a separate patch for that, now it makes you patch even larger (39 kB). Same goes for the help text updates in Kconfig.
Quoted 11 lines
4) chip w83627ehg report its name in "name" attribute as w83627ehf to preserve compatibility of libsensors
4) changed the resource handling, platform device allocates the full 8byte region, and report itself there with sio name. So in my case:0290-0297 : W83627EHG
0295-0296 : w83627ehfThe datasheet mentions that the chip decodes just +5 and +6 but it also mentions that last three bits belong to the chip. I must check if it will hoose acpi pnp or not.
This is a risky change. I know for a fact that some motherboards with a W83627HF reserve 0x295-0x296 as a PNP resource, so we must not ask for the whole 0x290-0x297 range at the device declaration level, otherwise the driver core will reject our request. The W83627EHF might be different but I would be surprised. As a matter of fact, see:
What you are doing here is pretty much the opposite of the fix Petr committed over a year ago. So I think you should back up this change.
I suppose that the clean fix to this problem would be to use the pnp device when available instead of declaring our own platform device. But I'm not familiar with pnp so I don't really know, and I also prefer that we concentrate on killing i2c-isa for now. Further cleanups can happen later.
As for using the Super-I/O chip name as the resource name, I considered it, but then realized it means we need to keep these name strings in memory forever. So I decided to use the driver name everywhere. But it doesn't really matter, do as you wish.
Quoted 1 line
+enum kinds { w83627ehf, w83627ehg, w83627dhg };
Why define a separate kind for w83627ehg given that you treat it everywhere as a w83627ehf? I think it's convenient that the enum matches the prefixes used in every driver.
Review
Quoted 9 lines
static inline int
(quoted diff) +3
-4-superio_inb(int reg) -{ - outb(reg, REG); - return inb(VAL); +superio_inb(int reg, int ioreg) +{ outb(reg, ioreg); + return inb(ioreg + 1); }
Bad coding style.
Also, only two drivers pass the Super-I/O base address as a parameter to the superio functions right now (pc87360 and pc87427), and both pass it as the first parameter, while you pass it as the last. I'd like all drivers to use the same convention to avoid unnecessary confusion.
(Ultimately, I think we want to share all this code between all our Super-I/O drivers to kill the redundancy and enforce the conventions.)
Review
Quoted 4 lines
struct
w83627ehf_data{(quoted diff) +2
-1- struct i2c_client client; + int addr; + enum kinds kind;
You don't actually use "kind" anywhere.
Review
Quoted 3 lines
(quoted diff) +3
-0+struct w83627ehf_sio_data { + enum kinds kind; + int sioreg; /* IO base for Super I/O */
Ideally you should not access the Super-I/O config area past the initial detection in w83627ehf_find, so you shouldn't need to store this value in sio_data. But I agree this can be left for a future cleanup, it doesn't really belong to this patch. The f71805f driver does it right already, the w83627hf driver not yet.
Review
Quoted 3 lines
(quoted diff) +3
-0+ int hm_base; /* IO base of hw monitor block */ + const char *name; +};
I think "hwm" is a more popular abbreviation of hardware monitor.
Quoted 26 lines
(quoted diff) +11
-7+static int __devinit w83627ehf_probe(struct platform_device *pdev) { - struct i2c_client *client; struct w83627ehf_data *data; - struct device *dev; + struct device *dev = &pdev->dev; + struct w83627ehf_sio_data *sio_data = dev->platform_data; + struct resource *res; + static const char *names[] = { + "w83627ehf", + "w83627ehf", /* treat ehg as ehf (same features) */ + "w83627dhg", + }; u8 fan4pin, fan5pin; int i, err = 0; - if (!request_region(address + REGION_OFFSET, REGION_LENGTH, - w83627ehf_driver.driver.name)) { - err = -EBUSY; + if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { + err = -ENOMEM; goto exit; } - if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { - err = -ENOMEM;
Review
Quoted 10 lines
(quoted diff) +8
-1- goto exit_release; + res = platform_get_resource(pdev, IORESOURCE_IO, 0); + if (!request_region(res->start + REGION_OFFSET, REGION_LENGTH, + DRVNAME)) { + err = -EBUSY; + dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", + (unsigned long)(res->start + REGION_OFFSET), + (unsigned long)(res->start + REGION_OFFSET + 1)); + goto exit_remove; }
You don't have to swap the memory allocation and the I/O resource request. It's OK to get the memory first, and it will make you patch a bit smaller and more readable to not change the order.
Quoted 4 lines
(...)
(quoted diff) +2
-0+exit_release_region: + release_region(res->start + ADDR_REG_OFFSET, 2); exit_remove:
Review
Quoted 10 lines
(quoted diff) +1
-4w83627ehf_device_remove_files(dev); - i2c_detach_client(client); -exit_free: + platform_set_drvdata(pdev, NULL); kfree(data); -exit_release: - release_region(address + REGION_OFFSET, REGION_LENGTH); exit: return err; }
The error path doesn't look quite right to me. You can't release the region before removing the sysfs files, it's not safe.
Quoted 58 lines
(quoted diff) +23
-18+static int __init w83627ehf_find(int sioaddr, struct w83627ehf_sio_data *sio_data) { u16 val; - REG = sioaddr; - VAL = sioaddr + 1; - superio_enter(); + superio_enter(sioaddr); - val = (superio_inb(SIO_REG_DEVID) << 8) - | superio_inb(SIO_REG_DEVID + 1); + val = (superio_inb(SIO_REG_DEVID, sioaddr) << 8) + | superio_inb(SIO_REG_DEVID + 1, sioaddr); switch (val & SIO_ID_MASK) { - case SIO_W83627DHG_ID: - w83627ehf_num_in = 9; - break; case SIO_W83627EHF_ID: + sio_data->kind = w83627ehf; + break; case SIO_W83627EHG_ID: - w83627ehf_num_in = 10; + sio_data->kind = w83627ehg; + break; + case SIO_W83627DHG_ID: + sio_data->kind = w83627dhg; break; default: - printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n", + pr_info(DRVNAME ": unsupported chip ID: 0x%04x\n", val); - superio_exit(); + superio_exit(sioaddr); return -ENODEV; } - superio_select(W83627EHF_LD_HWM); - val = (superio_inb(SIO_REG_ADDR) << 8) - | superio_inb(SIO_REG_ADDR + 1); - *addr = val & REGION_ALIGNMENT; - if (*addr = 0) { - superio_exit(); + /* we have known chip find the HWMON base */ + + sio_data->sioreg = sioaddr; + sio_data->name = sio_names[sio_data->kind]; + superio_select(W83627EHF_LD_HWM, sio_data->sioreg); + val = (superio_inb(SIO_REG_ADDR, sio_data->sioreg) << 8) + | superio_inb(SIO_REG_ADDR + 1, sio_data->sioreg); + sio_data->hm_base = val & REGION_ALIGNMENT; + if (sio_data->hm_base = 0) { + superio_exit(sio_data->sioreg); return -ENODEV; } /* Activate logical device if needed */ - val = superio_inb(SIO_REG_ENABLE); + val = superio_inb(SIO_REG_ENABLE, sio_data->sioreg);
Review
Quoted 10 lines
(quoted diff) +4
-2if (!(val & 0x01)) - superio_outb(SIO_REG_ENABLE, val | 0x01); + superio_outb(SIO_REG_ENABLE, val | 0x01, sio_data->sioreg); - superio_exit(); + superio_exit(sio_data->sioreg); + pr_info(DRVNAME ": Found %s chip at %#x\n", + sio_data->name, sio_data->hm_base); return 0; }
I suggest adding warning messages when the base I/O isn't set and when we need to forcibly enable the device, as I did in the w83627hf driver. This will make support easier.
Thanks,
Signature · 1 line
Jean Delvare
Hi Rudolf,
Quoted 8 lines · Jean Delvare
The upper-case strings refer to device names, the lower-case strings refer to chip prefix as expected by libsensors. They are different things - as a matter of fact, we use prefix
w83627eh_f_theW83627EH_G_. It's convenient to use the same prefix for libsensors when two chips can be handled exactly the same way, but it is still valuable to print the exact chip name in the logs for debugging/support purposes.
Quoted 8 lines
In my w83627hf patch, I've made the upper-case strings
__initdataso they are removed from memory after driver initialization.There's nothing which can actually fail in
w83627ehf_remove, so what would we do with "err"?Unified error paths are considered a good practice.
Thanks for the explanation, Jean. Sounds good to me. I'm swamped at work this week, but I could still at least do a quick test of a patch. However, I think I've lost track of this discussion. Sorry! Rudolf, let me know if there's a patch you would like me to test. With luck, I can run it on both the EHF and DHG on Saturday.
David
Hi Rudolf,
I'm going to put in an hour or so and incorporate the changes Jean suggests:
Quoted 2 lines · Jean Delvare
I would have prefered a separate patch for that, now it makes you patch even larger (39 kB). Same goes for the help text updates in
Kconfig.
(snip)
Quoted 2 lines
What you are doing here is pretty much the opposite of the fix Petr committed over a year ago. So I think you should back up this change.
(snip)
Quoted 5 lines
Quoted 1 line
+enum kinds { w83627ehf, w83627ehg, w83627dhg };
Why define a separate kind for w83627ehg given that you treat it everywhere as a w83627ehf? I think it's convenient that the enum matches the prefixes used in every driver.
(things I'll work on in here, but snipped)
Quoted 3 lines
I suggest adding warning messages when the base I/O isn't set and when we need to forcibly enable the device, as I did in the w83627hf driver. This will make support easier.
I'll still need review of the patch when I've done this, so I'll post back then.
David
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Jean, Rudolf,
There's something wrong with the way the driver is registered. This patch is UNUSABLE. But here's the progress I have so far. I might be able to finish it, if time permits.
Quoted 2 lines · Jean Delvare
I would have prefered a separate patch for that, now it makes you patch even larger (39 kB). Same goes for the help text updates in
Kconfig.
After looking at it, the globals can only be removed when we move them into the w83627ehf_data (which is referenced from dev->platform_data). So we need to do it all at once (though, I agree, it would be nice to do in two patches when that's a possibility).
Quoted 5 lines
Review
Quoted 4 lines
struct
w83627ehf_data{(quoted diff) +2
-1- struct i2c_client client; + int addr; + enum kinds kind;
Quoted 7 lines
You don't actually use "kind" anywhere.
Quoted 1 line
+enum kinds { w83627ehf, w83627ehg, w83627dhg };
Why define a separate kind for w83627ehg given that you treat it everywhere as a w83627ehf? I think it's convenient that the enum matches the prefixes used in every driver.
I removed static const char * sio_names and placed it in w83627ehf_find(), where I marked it __initdata. Since I use it to initialize sio_name, I'm not sure if I need to keep it the way it is, as a separate array. If I embedded the static strings in the switch(), would they still be __initdata?
At this point, it looks like I can merge w83627ehf_sio_data and w83627ehf_data. This eliminates the duplicate sio_data->name == data->name, and sio_data->hm_base == data->addr, and saves a little memory by only allocating one block instead of two.
Storing w83627ehf_data as pdev->dev.platform_data only makes sense as long as the driver only has one instance. This is a FIXME that I'll address once the deadlock below is fixed.
Quoted 7 lines
Also, only two drivers pass the Super-I/O base address as a parameter to the superio functions right now (pc87360 and pc87427), and both pass it as the first parameter, while you pass it as the last. I'd like all drivers to use the same convention to avoid unnecessary confusion.
(Ultimately, I think we want to share all this code between all our Super-I/O drivers to kill the redundancy and enforce the conventions.)
This is something I'm excited to see (someday). I reversed the order of the superio_* functions, but I'd appreciate it if someone would double-check me, since the arguments are all the same type... it would be very easy to get the argument order wrong or miss a superio_inb() somewhere.
Quoted 29 lines
Quoted 11 lines
4) chip w83627ehg report its name in "name" attribute as w83627ehf to preserve compatibility of libsensors
4) changed the resource handling, platform device allocates the full 8byte region, and report itself there with sio name. So in my case:0290-0297 : W83627EHG
0295-0296 : w83627ehfThe datasheet mentions that the chip decodes just +5 and +6 but it also mentions that last three bits belong to the chip. I must check if it will hoose acpi pnp or not.
This is a risky change. I know for a fact that some motherboards with a W83627HF reserve 0x295-0x296 as a PNP resource, so we must not ask for the whole 0x290-0x297 range at the device declaration level, otherwise the driver core will reject our request. The W83627EHF might be different but I would be surprised. As a matter of fact, see:
What you are doing here is pretty much the opposite of the fix Petr committed over a year ago. So I think you should back up this change.
I suppose that the clean fix to this problem would be to use the pnp device when available instead of declaring our own platform device. But I'm not familiar with pnp so I don't really know, and I also prefer that we concentrate on killing i2c-isa for now. Further cleanups can happen later.
Quoted 4 lines
As for using the Super-I/O chip name as the resource name, I considered it, but then realized it means we need to keep these name strings in memory forever. So I decided to use the driver name everywhere. But it doesn't really matter, do as you wish.
This is the code I changed to address this, please review:
+ memset(&res, 0, sizeof(res));
+ data->name = w83627ehf_device_names[data->kind];
+ res.name = data->name;
+ res.start = data->addr + REGION_OFFSET;
+ res.end = data->addr + REGION_OFFSET + REGION_LENGTH - 1;
+ res.flags = IORESOURCE_IO;
+ err = platform_device_add_resources(pdev, &res, 1);
Quoted 5 lines
Ideally you should not access the Super-I/O config area past the initial detection in
w83627ehf_find, so you shouldn't need to store this value insio_data. But I agree this can be left for a future cleanup, it doesn't really belong to this patch. The f71805f driver does it right already, the w83627hf driver not yet.
I think it's an easy thing to do -- maybe this will be the next patch.
Quoted 2 lines
The error path doesn't look quite right to me. You can't release the region before removing the sysfs files, it's not safe.
I reversed the order of these.
Quoted 3 lines
I suggest adding warning messages when the base I/O isn't set and when we need to forcibly enable the device, as I did in the w83627hf driver. This will make support easier.
I'm not clear on which part of the w83627hf driver does this. I can't find the patch in the mail archives that converts w83627hf to a platform driver, but I think this is the section of code (pre-platform-driver) that you're talking about: w83627hf.c lines 1399-1403:
/* Minimize conflicts with other winbond i2c-only clients... */
/* disable i2c subclients... how to disable main i2c client?? */
/* force i2c address to relatively uncommon address */
w83627hf_write_value(client, W83781D_REG_I2C_SUBADDR, 0x89);
w83627hf_write_value(client, W83781D_REG_I2C_ADDR, force_i2c);Let's make the "forcibly enable the device" a separate patch.
Again, the attached patch deadlocks when the module is being removed. The call trace is:
__sched_text_startwait_for_completiondefault_wake_functionklist_remove__device_release_driverdevice_release_driverbus_remove_devicedevice_delplatform_device_delplatform_device_unregistersensors_w83627ehf_ea_unreg_fnsensors_w83627ehf_exit
What this means is that line 321 of drivers/base/dd.c:klist_remove(&dev->knode_driver)
is deadlocking. I don't know what the code is doing incorrectly when registering the driver.
Here is the patch, if you'd like to take a look.
David
drivers/hwmon/w83627ehf.c +329 -235
@@ -41,8 +41,8 @@#include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> -#include <linux/i2c.h> -#include <linux/i2c-isa.h> +#include <linux/jiffies.h> +#include <linux/platform_device.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h>
@@ -50,25 +50,19 @@#include <asm/io.h> #include "lm75.h" -/* The actual ISA address is read from Super-I/O configuration space */ -static unsigned short address; +enum kinds { w83627ehf, w83627dhg }; -/* -* Super-I/O constants and functions -*/ +/* used to set data->name = w83627ehf_device_names[data->kind] */ +static const char * w83627ehf_device_names[] = { +"w83627ehf" , +"w83627dhg" , +}; + +#define DRVNAME "w83627ehf"/* -* The three following globals are initialized in w83627ehf_find(), before -* the i2c-isa device is created. Otherwise, they could be stored in -* w83627ehf_data. This is ugly, but necessary, and when the driver is next -* updated to become a platform driver, the globals will disappear. +* Super-I/O constants and functions */ -static int REG ;/* The register to read/write */ -static int VAL ;/* The value to read/write */ -/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This -* value is also used in w83627ehf_detect() to export a device name in sysfs -* (e.g. w83627ehf or w83627dhg) */ -static int w83627ehf_num_in;#define W83627EHF_LD_HWM 0x0b
@@ -83,38 +77,38 @@#define SIO_ID_MASK 0xFFF0static inline void -superio_outb (int reg,int val) +superio_outb (int ioreg,int reg,int val) { -outb (reg,REG ); -outb (val,VAL ); +outb (reg, ioreg); +outb (val, ioreg +1 ); }static inline int -superio_inb (int reg) +superio_inb (int ioreg,int reg) { -outb (reg,REG ); -return inb (VAL ); +outb (reg, ioreg); +return inb (ioreg +1 ); }static inline void -superio_select (int ld) +superio_select (int ioreg,int ld) { -outb (SIO_REG_LDSEL ,REG ); -outb (ld,VAL ); +outb (SIO_REG_LDSEL , ioreg); +outb (ld, ioreg +1 ); }static inline void -superio_enter (void ) +superio_enter (int ioreg) { -outb (0x87 ,REG ); -outb (0x87 ,REG ); +outb (0x87 , ioreg); +outb (0x87 , ioreg); }static inline void -superio_exit (void ) +superio_exit (int ioreg) { -outb (0x02 ,REG ); -outb (0x02 ,VAL ); +outb (0x02 , ioreg); +outb (0x02 , ioreg +1 ); }/*
@@ -255,7 +249,11 @@*/ struct w83627ehf_data { -struct i2c_client client; +int sioreg; +enum kinds kind; +int addr;/* IO base of hw monitor block */ +const char *name; +struct class_device *class_dev;struct mutex lock;
@@ -264,6 +262,7 @@unsigned long last_updated;/* In jiffies */ /* Register values */ +u8 in_num;/* number of in inputs we have */ u8 in[10 ];/* Register value */ u8 in_max[10 ];/* Register value */ u8 in_min[10 ];/* Register value */
@@ -303,121 +302,117 @@nothing for registers which live in bank 0. For others, they respectively set the bank register to the correct value (before the register is accessed), and back to 0 (afterwards). */ -static inline void w83627ehf_set_bank (struct i2c_client *client,u16 reg) +static inline void w83627ehf_set_bank (struct w83627ehf_data *data,u16 reg) {if (reg &0xff00 ) { -outb_p (W83627EHF_REG_BANK , client->addr +ADDR_REG_OFFSET ); -outb_p (reg >>8 , client->addr +DATA_REG_OFFSET ); +outb_p (W83627EHF_REG_BANK , data->addr +ADDR_REG_OFFSET ); +outb_p (reg >>8 , data->addr +DATA_REG_OFFSET ); } } -static inline void w83627ehf_reset_bank (struct i2c_client *client,u16 reg) +static inline void w83627ehf_reset_bank (struct w83627ehf_data *data,u16 reg) {if (reg &0xff00 ) { -outb_p (W83627EHF_REG_BANK , client->addr +ADDR_REG_OFFSET ); -outb_p (0 , client->addr +DATA_REG_OFFSET ); +outb_p (W83627EHF_REG_BANK , data->addr +ADDR_REG_OFFSET ); +outb_p (0 , data->addr +DATA_REG_OFFSET ); } } -static u16 w83627ehf_read_value (struct i2c_client *client,u16 reg) +static u16 w83627ehf_read_value (struct w83627ehf_data *data,u16 reg) { -struct w83627ehf_data *data =i2c_get_clientdata (client);int res, word_sized =is_word_sized (reg);mutex_lock (&data->lock); -w83627ehf_set_bank (client, reg); -outb_p (reg &0xff , client->addr +ADDR_REG_OFFSET ); - res =inb_p (client->addr +DATA_REG_OFFSET ); +w83627ehf_set_bank (data, reg); +outb_p (reg &0xff , data->addr +ADDR_REG_OFFSET ); + res =inb_p (data->addr +DATA_REG_OFFSET );if (word_sized) {outb_p ((reg &0xff ) +1 , - client->addr +ADDR_REG_OFFSET ); - res = (res <<8 ) +inb_p (client->addr +DATA_REG_OFFSET ); + data->addr +ADDR_REG_OFFSET ); + res = (res <<8 ) +inb_p (data->addr +DATA_REG_OFFSET ); } -w83627ehf_reset_bank (client, reg); +w83627ehf_reset_bank (data, reg);mutex_unlock (&data->lock);return res; } -static int w83627ehf_write_value (struct i2c_client *client,u16 reg,u16 value) +static int w83627ehf_write_value (struct w83627ehf_data *data,u16 reg,u16 value) { -struct w83627ehf_data *data =i2c_get_clientdata (client);int word_sized =is_word_sized (reg);mutex_lock (&data->lock); -w83627ehf_set_bank (client, reg); -outb_p (reg &0xff , client->addr +ADDR_REG_OFFSET ); +w83627ehf_set_bank (data, reg); +outb_p (reg &0xff , data->addr +ADDR_REG_OFFSET );if (word_sized) { -outb_p (value >>8 , client->addr +DATA_REG_OFFSET ); +outb_p (value >>8 , data->addr +DATA_REG_OFFSET );outb_p ((reg &0xff ) +1 , - client->addr +ADDR_REG_OFFSET ); + data->addr +ADDR_REG_OFFSET ); } -outb_p (value &0xff , client->addr +DATA_REG_OFFSET ); -w83627ehf_reset_bank (client, reg); +outb_p (value &0xff , data->addr +DATA_REG_OFFSET ); +w83627ehf_reset_bank (data, reg);mutex_unlock (&data->lock);return 0 ; }/* This function assumes that the caller holds data->update_lock */ -static void w83627ehf_write_fan_div (struct i2c_client *client,int nr) +static void w83627ehf_write_fan_div (struct w83627ehf_data *data,int nr) { -struct w83627ehf_data *data =i2c_get_clientdata (client);u8 reg;switch (nr) {case 0 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ) &0xcf ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ) &0xcf ) | ((data->fan_div[0 ] &0x03 ) <<4 );/* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 <<4 )) ?1 :0 ; -w83627ehf_write_value (client,W83627EHF_REG_FANDIV1 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0xdf ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV1 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0xdf ) | ((data->fan_div[0 ] &0x04 ) <<3 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 1 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ) &0x3f ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ) &0x3f ) | ((data->fan_div[1 ] &0x03 ) <<6 );/* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 <<4 )) ?1 :0 ; -w83627ehf_write_value (client,W83627EHF_REG_FANDIV1 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0xbf ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV1 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0xbf ) | ((data->fan_div[1 ] &0x04 ) <<4 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 2 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV2 ) &0x3f ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV2 ) &0x3f ) | ((data->fan_div[2 ] &0x03 ) <<6 ); -w83627ehf_write_value (client,W83627EHF_REG_FANDIV2 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0x7f ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV2 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0x7f ) | ((data->fan_div[2 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 3 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_DIODE ) &0xfc ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_DIODE ) &0xfc ) | (data->fan_div[3 ] &0x03 ); -w83627ehf_write_value (client,W83627EHF_REG_DIODE , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_SMI_OVT ) &0x7f ) +w83627ehf_write_value (data,W83627EHF_REG_DIODE , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_SMI_OVT ) &0x7f ) | ((data->fan_div[3 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_SMI_OVT , reg); +w83627ehf_write_value (data,W83627EHF_REG_SMI_OVT , reg);break ;case 4 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_DIODE ) &0x73 ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_DIODE ) &0x73 ) | ((data->fan_div[4 ] &0x03 ) <<3 ) | ((data->fan_div[4 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_DIODE , reg); +w83627ehf_write_value (data,W83627EHF_REG_DIODE , reg);break ; } }static struct w83627ehf_data *w83627ehf_update_device (struct device *dev) { -struct i2c_client *client =to_i2c_client (dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); +struct w83627ehf_data *data = dev->platform_data;int pwmcfg =0 , tolerance =0 ;/* shut up the compiler */ int i;
@@ -426,33 +421,33 @@if (time_after (jiffies, data->last_updated +HZ ) || !data->valid) {/* Fan clock dividers */ - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ); data->fan_div[0 ] = (i >>4 ) &0x03 ; data->fan_div[1 ] = (i >>6 ) &0x03 ; - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV2 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV2 ); data->fan_div[2 ] = (i >>6 ) &0x03 ; - i =w83627ehf_read_value (client,W83627EHF_REG_VBAT ); + i =w83627ehf_read_value (data,W83627EHF_REG_VBAT ); data->fan_div[0 ] |= (i >>3 ) &0x04 ; data->fan_div[1 ] |= (i >>4 ) &0x04 ; data->fan_div[2 ] |= (i >>5 ) &0x04 ;if (data->has_fan & ((1 <<3 ) | (1 <<4 ))) { - i =w83627ehf_read_value (client,W83627EHF_REG_DIODE ); + i =w83627ehf_read_value (data,W83627EHF_REG_DIODE ); data->fan_div[3 ] = i &0x03 ; data->fan_div[4 ] = ((i >>2 ) &0x03 ) | ((i >>5 ) &0x04 ); }if (data->has_fan & (1 <<3 )) { - i =w83627ehf_read_value (client,W83627EHF_REG_SMI_OVT ); + i =w83627ehf_read_value (data,W83627EHF_REG_SMI_OVT ); data->fan_div[3 ] |= (i >>5 ) &0x04 ; }/* Measured voltages and limits */ -for (i =0 ; i < w83627ehf_num_in; i++) { - data->in[i] =w83627ehf_read_value (client, +for (i =0 ; i < data->in_num; i++) { + data->in[i] =w83627ehf_read_value (data,W83627EHF_REG_IN (i)); - data->in_min[i] =w83627ehf_read_value (client, + data->in_min[i] =w83627ehf_read_value (data,W83627EHF_REG_IN_MIN (i)); - data->in_max[i] =w83627ehf_read_value (client, + data->in_max[i] =w83627ehf_read_value (data,W83627EHF_REG_IN_MAX (i)); }
@@ -461,9 +456,9 @@if (!(data->has_fan & (1 << i)))continue ; - data->fan[i] =w83627ehf_read_value (client, + data->fan[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN [i]); - data->fan_min[i] =w83627ehf_read_value (client, + data->fan_min[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN [i]);/* If we failed to measure the fan speed and clock
@@ -471,16 +466,16 @@time */ if (data->fan[i] ==0xff && data->fan_div[i] <0x07 ) { -dev_dbg (&client->dev,"Increasing fan %d " +dev_dbg (dev,"Increasing fan %d " "clock divider from %u to %u\n" , i,div_from_reg (data->fan_div[i]),div_from_reg (data->fan_div[i] +1 )); data->fan_div[i]++; -w83627ehf_write_fan_div (client, i); +w83627ehf_write_fan_div (data, i);/* Preserve min limit if possible */ if (data->fan_min[i] >=2 && data->fan_min[i] !=255 ) -w83627ehf_write_value (client, +w83627ehf_write_value (data,W83627EHF_REG_FAN_MIN [i], (data->fan_min[i] /=2 )); }
@@ -489,9 +484,9 @@for (i =0 ; i <4 ; i++) {/* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ if (i !=1 ) { - pwmcfg =w83627ehf_read_value (client, + pwmcfg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [i]); - tolerance =w83627ehf_read_value (client, + tolerance =w83627ehf_read_value (data,W83627EHF_REG_TOLERANCE [i]); } data->pwm_mode[i] =
@@ -500,14 +495,14 @@ data->pwm_enable[i] = ((pwmcfg >>W83627EHF_PWM_ENABLE_SHIFT [i]) &3 ) +1 ; - data->pwm[i] =w83627ehf_read_value (client, + data->pwm[i] =w83627ehf_read_value (data,W83627EHF_REG_PWM [i]); - data->fan_min_output[i] =w83627ehf_read_value (client, + data->fan_min_output[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN_OUTPUT [i]); - data->fan_stop_time[i] =w83627ehf_read_value (client, + data->fan_stop_time[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_STOP_TIME [i]); data->target_temp[i] = -w83627ehf_read_value (client, +w83627ehf_read_value (data,W83627EHF_REG_TARGET [i]) & (data->pwm_mode[i] ==1 ?0x7f :0xff ); data->tolerance[i] = (tolerance >> (i ==1 ?4 :0 ))
@@ -515,26 +510,26 @@ }/* Measured temperatures and limits */ - data->temp1 =w83627ehf_read_value (client, + data->temp1 =w83627ehf_read_value (data,W83627EHF_REG_TEMP1 ); - data->temp1_max =w83627ehf_read_value (client, + data->temp1_max =w83627ehf_read_value (data,W83627EHF_REG_TEMP1_OVER ); - data->temp1_max_hyst =w83627ehf_read_value (client, + data->temp1_max_hyst =w83627ehf_read_value (data,W83627EHF_REG_TEMP1_HYST );for (i =0 ; i <2 ; i++) { - data->temp[i] =w83627ehf_read_value (client, + data->temp[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP [i]); - data->temp_max[i] =w83627ehf_read_value (client, + data->temp_max[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP_OVER [i]); - data->temp_max_hyst[i] =w83627ehf_read_value (client, + data->temp_max_hyst[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP_HYST [i]); } - data->alarms =w83627ehf_read_value (client, + data->alarms =w83627ehf_read_value (data,W83627EHF_REG_ALARM1 ) | - (w83627ehf_read_value (client, + (w83627ehf_read_value (data,W83627EHF_REG_ALARM2 ) <<8 ) | - (w83627ehf_read_value (client, + (w83627ehf_read_value (data,W83627EHF_REG_ALARM3 ) <<16 ); data->last_updated = jiffies;
@@ -567,15 +562,14 @@ store_in_##reg (struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev->platform_data; \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->in_##reg[nr] = in_to_reg(val, nr); \ - w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ + w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ data->in_##reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -673,8 +667,7 @@ store_fan_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;unsigned int val =simple_strtoul (buf,NULL ,10 );
@@ -725,9 +718,9 @@ nr +1 ,div_from_reg (data->fan_div[nr]), div_from_reg(new_div)); data->fan_div[nr] = new_div; -w83627ehf_write_fan_div (client, nr); +w83627ehf_write_fan_div (data, nr); } -w83627ehf_write_value (client,W83627EHF_REG_FAN_MIN [nr], +w83627ehf_write_value (data,W83627EHF_REG_FAN_MIN [nr], data->fan_min[nr]);mutex_unlock (&data->update_lock);
@@ -788,13 +781,12 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev->platform_data; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \ data->temp1_##reg); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -822,15 +814,14 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev->platform_data; \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->reg[nr] = LM75_TEMP_TO_REG(val); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ data->reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -877,8 +868,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =simple_strtoul (buf,NULL ,10 );
@@ -887,12 +877,12 @@if (val >1 )return -EINVAL ;mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_PWM_ENABLE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [nr]); data->pwm_mode[nr] = val; reg &= ~(1 <<W83627EHF_PWM_MODE_SHIFT [nr]);if (!val) reg |=1 <<W83627EHF_PWM_MODE_SHIFT [nr]; -w83627ehf_write_value (client,W83627EHF_REG_PWM_ENABLE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_PWM_ENABLE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -901,15 +891,14 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =SENSORS_LIMIT (simple_strtoul (buf,NULL ,10 ),0 ,255 );mutex_lock (&data->update_lock); data->pwm[nr] = val; -w83627ehf_write_value (client,W83627EHF_REG_PWM [nr], val); +w83627ehf_write_value (data,W83627EHF_REG_PWM [nr], val);mutex_unlock (&data->update_lock);return count; }
@@ -918,8 +907,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =simple_strtoul (buf,NULL ,10 );
@@ -928,11 +916,11 @@if (!val || (val >2 ))/* only modes 1 and 2 are supported */ return -EINVAL ;mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_PWM_ENABLE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [nr]); data->pwm_enable[nr] = val; reg &= ~(0x03 <<W83627EHF_PWM_ENABLE_SHIFT [nr]); reg |= (val -1 ) <<W83627EHF_PWM_ENABLE_SHIFT [nr]; -w83627ehf_write_value (client,W83627EHF_REG_PWM_ENABLE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_PWM_ENABLE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -955,15 +943,14 @@ store_target_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u8 val =temp1_to_reg (simple_strtoul (buf,NULL ,10 ),0 ,127000 );mutex_lock (&data->update_lock); data->target_temp[nr] = val; -w83627ehf_write_value (client,W83627EHF_REG_TARGET [nr], val); +w83627ehf_write_value (data,W83627EHF_REG_TARGET [nr], val);mutex_unlock (&data->update_lock);return count; }
@@ -972,8 +959,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev->platform_data;struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u16 reg;
@@ -981,13 +967,13 @@u8 val =temp1_to_reg (simple_strtoul (buf,NULL ,10 ),0 ,15000 );mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_TOLERANCE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_TOLERANCE [nr]); data->tolerance[nr] = val;if (nr ==1 ) reg = (reg &0x0f ) | (val <<4 );else reg = (reg &0xf0 ) | val; -w83627ehf_write_value (client,W83627EHF_REG_TOLERANCE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_TOLERANCE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -1058,14 +1044,13 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ {\ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev->platform_data; \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ }
@@ -1087,21 +1072,29 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev->platform_data; \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ data->pwm_mode[nr]); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ } \ fan_time_functions(fan_stop_time, FAN_STOP_TIME) +static ssize_t show_name (struct device *dev,struct device_attribute + *devattr,char *buf) +{ +struct w83627ehf_data *data = dev->platform_data; + +return sprintf (buf,"%s\n" , data->name); +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
@@ -1126,7 +1119,7 @@ };/* -* Driver and client management +* Driver and platform management */ static void w83627ehf_device_remove_files (struct device *dev)
@@ -1134,12 +1127,13 @@/* some entries in the following arrays may not have been used in * device_create_file(), but device_remove_file() will ignore them */ int i; +struct w83627ehf_data *data = dev->platform_data;for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays); i++)device_remove_file (dev, &sda_sf3_arrays[i].dev_attr);for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++)device_remove_file (dev, &sda_sf3_arrays_fan4[i].dev_attr); -for (i =0 ; i < w83627ehf_num_in; i++) { +for (i =0 ; i < data->in_num; i++) {device_remove_file (dev, &sda_in_input[i].dev_attr);device_remove_file (dev, &sda_in_alarm[i].dev_attr);device_remove_file (dev, &sda_in_min[i].dev_attr);
@@ -1160,86 +1154,75 @@ }for (i =0 ; i <ARRAY_SIZE (sda_temp); i++)device_remove_file (dev, &sda_temp[i].dev_attr); -} -static struct i2c_driver w83627ehf_driver; +device_remove_file (dev, &dev_attr_name); +} -static void w83627ehf_init_client (struct i2c_client *client) +/* w83627ehf_init_device() gets the monitoring functions started */ +static inline void __devinit w83627ehf_init_device (struct w83627ehf_data *data) {int i;u8 tmp;/* Start monitoring is needed */ - tmp =w83627ehf_read_value (client,W83627EHF_REG_CONFIG ); + tmp =w83627ehf_read_value (data,W83627EHF_REG_CONFIG );if (!(tmp &0x01 )) -w83627ehf_write_value (client,W83627EHF_REG_CONFIG , +w83627ehf_write_value (data,W83627EHF_REG_CONFIG , tmp |0x01 );/* Enable temp2 and temp3 if needed */ for (i =0 ; i <2 ; i++) { - tmp =w83627ehf_read_value (client, + tmp =w83627ehf_read_value (data,W83627EHF_REG_TEMP_CONFIG [i]);if (tmp &0x01 ) -w83627ehf_write_value (client, +w83627ehf_write_value (data,W83627EHF_REG_TEMP_CONFIG [i], tmp &0xfe ); } } -static int w83627ehf_detect (struct i2c_adapter *adapter) +/* w83627ehf_probe() looks for a Super-I/O chip at known addresses */ +static int __devinit w83627ehf_probe (struct platform_device *pdev) { -struct i2c_client *client; -struct w83627ehf_data *data; -struct device *dev; +struct device *dev = &pdev->dev; +struct w83627ehf_data *data = dev->platform_data;u8 fan4pin, fan5pin;int i, err =0 ; -if (!request_region (address +REGION_OFFSET ,REGION_LENGTH , - w83627ehf_driver.driver.name)) { + printk(KERN_ERR DRVNAME ": w83627ehf_probe data=%lx\n", + (unsigned long) data); +if (!request_region (data->addr +REGION_OFFSET ,REGION_LENGTH , +DRVNAME )) { err = -EBUSY ; +dev_err (dev,"Failed to request region 0x%lx-0x%lx\n" , + (unsigned long ) (data->addr +REGION_OFFSET ), + (unsigned long ) ( + data->addr +REGION_OFFSET +REGION_LENGTH -1 )); goto exit; } -if (!(data =kzalloc (sizeof (struct w83627ehf_data ),GFP_KERNEL ))) { - err = -ENOMEM ; - goto exit_release; - } - - client = &data->client; -i2c_set_clientdata (client, data); - client->addr = address; -mutex_init (&data->lock); - client->adapter = adapter; - client->driver = &w83627ehf_driver; - client->flags =0 ; - dev = &client->dev; - -if (w83627ehf_num_in ==9 ) -strlcpy (client->name,"w83627dhg" ,I2C_NAME_SIZE ); -else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ -strlcpy (client->name,"w83627ehf" ,I2C_NAME_SIZE ); +/* fill in fields in *data so w83627ehf_read_value(), etc., work */ data->valid =0 ; +mutex_init (&data->lock);mutex_init (&data->update_lock); -/* Tell the i2c layer a new client has arrived */ -if ((err =i2c_attach_client (client))) - goto exit_free; +/* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ + data->in_num = (data->kind == w83627dhg) ?9 :10 ;/* Initialize the chip */ -w83627ehf_init_client (client); +w83627ehf_init_device (data); -/* A few vars need to be filled upon startup */ for (i =0 ; i <5 ; i++) - data->fan_min[i] =w83627ehf_read_value (client, + data->fan_min[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN [i]);/* fan4 and fan5 share some pins with the GPIO and serial flash */ -superio_enter (); - fan5pin =superio_inb (0x24 ) &0x2 ; - fan4pin =superio_inb (0x29 ) &0x6 ; -superio_exit (); +superio_enter (data->sioreg); + fan5pin =superio_inb (data->sioreg,0x24 ) &0x2 ; + fan4pin =superio_inb (data->sioreg,0x29 ) &0x6 ; +superio_exit (data->sioreg);/* It looks like fan4 and fan5 pins can be alternatively used as fan on/off switches, but fan5 control is write only :/
@@ -1248,7 +1231,7 @@is not the default. */ data->has_fan =0x07 ;/* fan1, fan2 and fan3 */ - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 );if ((i & (1 <<2 )) && (!fan4pin)) data->has_fan |= (1 <<3 );if (!(i & (1 <<1 )) && (!fan5pin))
@@ -1257,18 +1240,17 @@/* Register sysfs hooks */ for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays); i++)if ((err =device_create_file (dev, - &sda_sf3_arrays[i].dev_attr))) + &sda_sf3_arrays[i].dev_attr))) goto exit_remove;/* if fan4 is enabled create the sf3 files for it */ if (data->has_fan & (1 <<3 )) -for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++) { +for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++)if ((err =device_create_file (dev, - &sda_sf3_arrays_fan4[i].dev_attr))) + &sda_sf3_arrays_fan4[i].dev_attr))) goto exit_remove; - } -for (i =0 ; i < w83627ehf_num_in; i++) +for (i =0 ; i < data->in_num; i++)if ((err =device_create_file (dev, &sda_in_input[i].dev_attr)) || (err =device_create_file (dev, &sda_in_alarm[i].dev_attr))
@@ -1308,105 +1290,217 @@if ((err =device_create_file (dev, &sda_temp[i].dev_attr))) goto exit_remove; + err =device_create_file (dev, &dev_attr_name); +if (err) + goto exit_remove; + + printk(KERN_ERR DRVNAME ": hwmon_device_register\n"); data->class_dev =hwmon_device_register (dev);if (IS_ERR (data->class_dev)) { err =PTR_ERR (data->class_dev); goto exit_remove; } + printk(KERN_ERR DRVNAME ": w83627ehf_probe success\n");return 0 ; exit_remove:w83627ehf_device_remove_files (dev); -i2c_detach_client (client); -exit_free: -kfree (data); -exit_release: -release_region (address +REGION_OFFSET ,REGION_LENGTH ); +release_region (data->addr +REGION_OFFSET ,REGION_LENGTH ); exit:return err; } -static int w83627ehf_detach_client (struct i2c_client *client) +static int __devexit w83627ehf_remove(struct platform_device *pdev) { -struct w83627ehf_data *data =i2c_get_clientdata (client); -int err; +struct w83627ehf_data *data = pdev->dev.platform_data; + printk(KERN_ERR DRVNAME ": w83627ehf_remove data=%lx\n", + (unsigned long) data); + + printk(KERN_ERR DRVNAME ": hwmon_device_unregister\n");hwmon_device_unregister (data->class_dev); -w83627ehf_device_remove_files (&client->dev); -if ((err =i2c_detach_client (client))) -return err; -release_region (client->addr +REGION_OFFSET ,REGION_LENGTH ); -kfree (data); + printk(KERN_ERR DRVNAME ": w83627ehf_device_remove_files\n"); +w83627ehf_device_remove_files (&pdev->dev); + printk(KERN_ERR DRVNAME ": w83627ehf_remove success\n");return 0 ; } -static struct i2c_driver w83627ehf_driver = { +static struct platform_driver w83627ehf_driver = { .driver = { .owner =THIS_MODULE , - .name ="w83627ehf" , + .name =DRVNAME , }, - .attach_adapter = w83627ehf_detect, - .detach_client = w83627ehf_detach_client, + .probe = w83627ehf_probe, + .remove =__devexit_p (w83627ehf_remove), }; -static int __init w83627ehf_find (int sioaddr,unsigned short *addr) +/* w83627ehf_superio_probe() looks for a '627 in the Super-I/O config space */ +static int __init w83627ehf_superio_probe (int sioaddr, +struct w83627ehf_data *data) {u16 val; -REG = sioaddr; -VAL = sioaddr +1 ; -superio_enter (); +static const char *__initdata sio_names[] = { +"W83627EHF" , +"W83627EHG" , +"W83627DHG" , + }; + +const char * sio_name; + + data->sioreg = sioaddr; - val = (superio_inb (SIO_REG_DEVID ) <<8 ) - |superio_inb (SIO_REG_DEVID +1 ); +superio_enter (data->sioreg); + + val = (superio_inb (data->sioreg,SIO_REG_DEVID ) <<8 ) + |superio_inb (data->sioreg,SIO_REG_DEVID +1 );switch (val &SIO_ID_MASK ) { -case SIO_W83627DHG_ID : - w83627ehf_num_in =9 ; -break ;case SIO_W83627EHF_ID : + data->kind = w83627ehf; + sio_name = sio_names[0 ]; +break ;case SIO_W83627EHG_ID : - w83627ehf_num_in =10 ; + data->kind = w83627ehf; + sio_name = sio_names[1 ]; +break ; +case SIO_W83627DHG_ID : + data->kind = w83627dhg; + sio_name = sio_names[2 ];break ;default : -printk (KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n" , +pr_info (DRVNAME ": unsupported chip ID: 0x%04x\n" , val); -superio_exit (); +superio_exit (data->sioreg);return -ENODEV ; } -superio_select (W83627EHF_LD_HWM ); - val = (superio_inb (SIO_REG_ADDR ) <<8 ) - |superio_inb (SIO_REG_ADDR +1 ); - *addr = val ®ION_ALIGNMENT ; -if (*addr ==0 ) { -superio_exit (); +/* we have known chip find the HWMON base */ + +superio_select (data->sioreg,W83627EHF_LD_HWM ); + val = (superio_inb (data->sioreg,SIO_REG_ADDR ) <<8 ) + |superio_inb (data->sioreg,SIO_REG_ADDR +1 ); + data->addr = val ®ION_ALIGNMENT ; +if (data->addr ==0 ) { +superio_exit (data->sioreg);return -ENODEV ; }/* Activate logical device if needed */ - val =superio_inb (SIO_REG_ENABLE ); + val =superio_inb (data->sioreg,SIO_REG_ENABLE );if (!(val &0x01 )) -superio_outb (SIO_REG_ENABLE , val |0x01 ); +superio_outb (data->sioreg,SIO_REG_ENABLE , val |0x01 ); -superio_exit (); +superio_exit (data->sioreg); +pr_info (DRVNAME ": Found %s chip at %#x\n" , + sio_name, data->addr);return 0 ; }static int __init sensors_w83627ehf_init (void ) { -if (w83627ehf_find (0x2e , &address) - &&w83627ehf_find (0x4e , &address)) -return -ENODEV ; +int err; +struct resource res; +struct platform_device *pdev; +struct w83627ehf_data *data; + +if (!(data =kzalloc (sizeof (struct w83627ehf_data ),GFP_KERNEL ))) { + err = -ENOMEM ; + goto exit; + } + +/* initialize data->kind, data->sioreg, and data->addr. +* +* when Super-I/O functions move to a separate file, the Super-I/O +* driver will probe 0x23 and 0x4e and auto-detect the presence of a +* w83627ehf hardware monitor, and call probe() */ +if (w83627ehf_superio_probe (0x2e , data) && +w83627ehf_superio_probe (0x4e , data)) { + err = -ENODEV ; + goto exit_free; + } -return i2c_isa_add_driver (&w83627ehf_driver); + printk(KERN_ERR DRVNAME ": platform_driver_register\n"); +if ((err =platform_driver_register (&w83627ehf_driver))!=0 ) + goto exit_free; + + printk(KERN_ERR DRVNAME ": platform_device_alloc\n"); +if (!(pdev =platform_device_alloc (DRVNAME , data->addr))) { + err = -ENOMEM ; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit_unregister; + } + + printk(KERN_ERR DRVNAME ": pdev->dev.platform_data = %lx\n", + (unsigned long) data); + pdev->dev.platform_data = data; + +memset (&res,0 ,sizeof (res)); + data->name = w83627ehf_device_names[data->kind]; + res.name = data->name; + res.start = data->addr +REGION_OFFSET ; + res.end = data->addr +REGION_OFFSET +REGION_LENGTH -1 ; + res.flags =IORESOURCE_IO ; + err =platform_device_add_resources (pdev, &res,1 ); +if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + +/* platform_device_add calls probe() */ + printk(KERN_ERR DRVNAME ": platform_device_add %lx\n", + (unsigned long) pdev); + err =platform_device_add (pdev); +if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + + printk(KERN_ERR DRVNAME ": sensors_w83627ehf_init success\n"); +return 0 ; + +exit_device_put: + pdev->dev.platform_data =NULL ; +platform_device_put (pdev); +exit_unregister: +platform_driver_unregister (&w83627ehf_driver); +exit_free: +kfree (data); +exit: +return err; +} + +static int __exit sensors_w83627ehf_ea_unreg_fn(struct device * dev, +void * data) +{ +struct platform_device *pdev; +int i; + + pdev =to_platform_device (dev); + printk(KERN_ERR DRVNAME ": sensors_w83627ehf_ea_unreg_fn %lx\n", + (unsigned long) pdev); +platform_device_unregister (pdev); + printk(KERN_ERR DRVNAME ": sensors_w83627ehf_ea_unreg_fn success\n"); +return 0 ; } static void __exit sensors_w83627ehf_exit(void) { -i2c_isa_del_driver (&w83627ehf_driver); +/* when Super-I/O functions move to a separate file, devices +* will be unregistered before unloading the module. +* +* for now, only one device is added in sensors_w83627ehf_init */ + printk(KERN_ERR DRVNAME ": sensors_w83627ehf_exit start\n"); +if (driver_for_each_device (&w83627ehf_driver.driver,0 ,0 , + sensors_w83627ehf_ea_unreg_fn)) + printk(KERN_ERR DRVNAME ": driver is NULL\n"); + printk(KERN_ERR DRVNAME ": platform_driver_unregister\n"); +platform_driver_unregister (&w83627ehf_driver); + printk(KERN_ERR DRVNAME ": sensors_w83627ehf_exit success\n"); }MODULE_AUTHOR ("Jean Delvare <[email protected]>" );
drivers/hwmon/Kconfig +6 -9
@@ -527,7 +527,6 @@ config SENSORS_W83793 tristate "Winbond W83793" depends on HWMON && I2C && EXPERIMENTAL - select HWMON_VID help If you say yes here you get support for the Winbond W83793 hardware monitoring chip.
@@ -560,17 +559,15 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF" - depends on HWMON && I2C && EXPERIMENTAL - select I2C_ISA + tristate "Winbond W83627EHF/DHG" + depends on HWMON && EXPERIMENTAL help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that. + If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip. This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a version suited for specific Intel processor sensing (PECI). This driver can also be built as a module. If so, the module will be called w83627ehf.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Jean, Rudolf,
Here's a patch for your review.
Thanks,
David
This patch removes i2c-isa from the w83627ehf driver, moving over to a platform driver.
drivers/hwmon/w83627ehf.c +298 -234
@@ -41,8 +41,8 @@#include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> -#include <linux/i2c.h> -#include <linux/i2c-isa.h> +#include <linux/jiffies.h> +#include <linux/platform_device.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h>
@@ -50,25 +50,19 @@#include <asm/io.h> #include "lm75.h" -/* The actual ISA address is read from Super-I/O configuration space */ -static unsigned short address; +enum kinds { w83627ehf, w83627dhg }; -/* -* Super-I/O constants and functions -*/ +/* used to set data->name = w83627ehf_device_names[data->kind] */ +static const char * w83627ehf_device_names[] = { +"w83627ehf" , +"w83627dhg" , +}; + +#define DRVNAME "w83627ehf"/* -* The three following globals are initialized in w83627ehf_find(), before -* the i2c-isa device is created. Otherwise, they could be stored in -* w83627ehf_data. This is ugly, but necessary, and when the driver is next -* updated to become a platform driver, the globals will disappear. +* Super-I/O constants and functions */ -static int REG ;/* The register to read/write */ -static int VAL ;/* The value to read/write */ -/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This -* value is also used in w83627ehf_detect() to export a device name in sysfs -* (e.g. w83627ehf or w83627dhg) */ -static int w83627ehf_num_in;#define W83627EHF_LD_HWM 0x0b
@@ -83,38 +77,38 @@#define SIO_ID_MASK 0xFFF0static inline void -superio_outb (int reg,int val) +superio_outb (int ioreg,int reg,int val) { -outb (reg,REG ); -outb (val,VAL ); +outb (reg, ioreg); +outb (val, ioreg +1 ); }static inline int -superio_inb (int reg) +superio_inb (int ioreg,int reg) { -outb (reg,REG ); -return inb (VAL ); +outb (reg, ioreg); +return inb (ioreg +1 ); }static inline void -superio_select (int ld) +superio_select (int ioreg,int ld) { -outb (SIO_REG_LDSEL ,REG ); -outb (ld,VAL ); +outb (SIO_REG_LDSEL , ioreg); +outb (ld, ioreg +1 ); }static inline void -superio_enter (void ) +superio_enter (int ioreg) { -outb (0x87 ,REG ); -outb (0x87 ,REG ); +outb (0x87 , ioreg); +outb (0x87 , ioreg); }static inline void -superio_exit (void ) +superio_exit (int ioreg) { -outb (0x02 ,REG ); -outb (0x02 ,VAL ); +outb (0x02 , ioreg); +outb (0x02 , ioreg +1 ); }/*
@@ -255,7 +249,11 @@*/ struct w83627ehf_data { -struct i2c_client client; +int sioreg; +enum kinds kind; +int addr;/* IO base of hw monitor block */ +const char *name; +struct class_device *class_dev;struct mutex lock;
@@ -264,6 +262,7 @@unsigned long last_updated;/* In jiffies */ /* Register values */ +u8 in_num;/* number of in inputs we have */ u8 in[10 ];/* Register value */ u8 in_max[10 ];/* Register value */ u8 in_min[10 ];/* Register value */
@@ -303,121 +302,117 @@nothing for registers which live in bank 0. For others, they respectively set the bank register to the correct value (before the register is accessed), and back to 0 (afterwards). */ -static inline void w83627ehf_set_bank (struct i2c_client *client,u16 reg) +static inline void w83627ehf_set_bank (struct w83627ehf_data *data,u16 reg) {if (reg &0xff00 ) { -outb_p (W83627EHF_REG_BANK , client->addr +ADDR_REG_OFFSET ); -outb_p (reg >>8 , client->addr +DATA_REG_OFFSET ); +outb_p (W83627EHF_REG_BANK , data->addr +ADDR_REG_OFFSET ); +outb_p (reg >>8 , data->addr +DATA_REG_OFFSET ); } } -static inline void w83627ehf_reset_bank (struct i2c_client *client,u16 reg) +static inline void w83627ehf_reset_bank (struct w83627ehf_data *data,u16 reg) {if (reg &0xff00 ) { -outb_p (W83627EHF_REG_BANK , client->addr +ADDR_REG_OFFSET ); -outb_p (0 , client->addr +DATA_REG_OFFSET ); +outb_p (W83627EHF_REG_BANK , data->addr +ADDR_REG_OFFSET ); +outb_p (0 , data->addr +DATA_REG_OFFSET ); } } -static u16 w83627ehf_read_value (struct i2c_client *client,u16 reg) +static u16 w83627ehf_read_value (struct w83627ehf_data *data,u16 reg) { -struct w83627ehf_data *data =i2c_get_clientdata (client);int res, word_sized =is_word_sized (reg);mutex_lock (&data->lock); -w83627ehf_set_bank (client, reg); -outb_p (reg &0xff , client->addr +ADDR_REG_OFFSET ); - res =inb_p (client->addr +DATA_REG_OFFSET ); +w83627ehf_set_bank (data, reg); +outb_p (reg &0xff , data->addr +ADDR_REG_OFFSET ); + res =inb_p (data->addr +DATA_REG_OFFSET );if (word_sized) {outb_p ((reg &0xff ) +1 , - client->addr +ADDR_REG_OFFSET ); - res = (res <<8 ) +inb_p (client->addr +DATA_REG_OFFSET ); + data->addr +ADDR_REG_OFFSET ); + res = (res <<8 ) +inb_p (data->addr +DATA_REG_OFFSET ); } -w83627ehf_reset_bank (client, reg); +w83627ehf_reset_bank (data, reg);mutex_unlock (&data->lock);return res; } -static int w83627ehf_write_value (struct i2c_client *client,u16 reg,u16 value) +static int w83627ehf_write_value (struct w83627ehf_data *data,u16 reg,u16 value) { -struct w83627ehf_data *data =i2c_get_clientdata (client);int word_sized =is_word_sized (reg);mutex_lock (&data->lock); -w83627ehf_set_bank (client, reg); -outb_p (reg &0xff , client->addr +ADDR_REG_OFFSET ); +w83627ehf_set_bank (data, reg); +outb_p (reg &0xff , data->addr +ADDR_REG_OFFSET );if (word_sized) { -outb_p (value >>8 , client->addr +DATA_REG_OFFSET ); +outb_p (value >>8 , data->addr +DATA_REG_OFFSET );outb_p ((reg &0xff ) +1 , - client->addr +ADDR_REG_OFFSET ); + data->addr +ADDR_REG_OFFSET ); } -outb_p (value &0xff , client->addr +DATA_REG_OFFSET ); -w83627ehf_reset_bank (client, reg); +outb_p (value &0xff , data->addr +DATA_REG_OFFSET ); +w83627ehf_reset_bank (data, reg);mutex_unlock (&data->lock);return 0 ; }/* This function assumes that the caller holds data->update_lock */ -static void w83627ehf_write_fan_div (struct i2c_client *client,int nr) +static void w83627ehf_write_fan_div (struct w83627ehf_data *data,int nr) { -struct w83627ehf_data *data =i2c_get_clientdata (client);u8 reg;switch (nr) {case 0 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ) &0xcf ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ) &0xcf ) | ((data->fan_div[0 ] &0x03 ) <<4 );/* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 <<4 )) ?1 :0 ; -w83627ehf_write_value (client,W83627EHF_REG_FANDIV1 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0xdf ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV1 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0xdf ) | ((data->fan_div[0 ] &0x04 ) <<3 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 1 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ) &0x3f ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ) &0x3f ) | ((data->fan_div[1 ] &0x03 ) <<6 );/* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 <<4 )) ?1 :0 ; -w83627ehf_write_value (client,W83627EHF_REG_FANDIV1 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0xbf ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV1 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0xbf ) | ((data->fan_div[1 ] &0x04 ) <<4 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 2 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_FANDIV2 ) &0x3f ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_FANDIV2 ) &0x3f ) | ((data->fan_div[2 ] &0x03 ) <<6 ); -w83627ehf_write_value (client,W83627EHF_REG_FANDIV2 , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_VBAT ) &0x7f ) +w83627ehf_write_value (data,W83627EHF_REG_FANDIV2 , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_VBAT ) &0x7f ) | ((data->fan_div[2 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_VBAT , reg); +w83627ehf_write_value (data,W83627EHF_REG_VBAT , reg);break ;case 3 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_DIODE ) &0xfc ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_DIODE ) &0xfc ) | (data->fan_div[3 ] &0x03 ); -w83627ehf_write_value (client,W83627EHF_REG_DIODE , reg); - reg = (w83627ehf_read_value (client,W83627EHF_REG_SMI_OVT ) &0x7f ) +w83627ehf_write_value (data,W83627EHF_REG_DIODE , reg); + reg = (w83627ehf_read_value (data,W83627EHF_REG_SMI_OVT ) &0x7f ) | ((data->fan_div[3 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_SMI_OVT , reg); +w83627ehf_write_value (data,W83627EHF_REG_SMI_OVT , reg);break ;case 4 : - reg = (w83627ehf_read_value (client,W83627EHF_REG_DIODE ) &0x73 ) + reg = (w83627ehf_read_value (data,W83627EHF_REG_DIODE ) &0x73 ) | ((data->fan_div[4 ] &0x03 ) <<3 ) | ((data->fan_div[4 ] &0x04 ) <<5 ); -w83627ehf_write_value (client,W83627EHF_REG_DIODE , reg); +w83627ehf_write_value (data,W83627EHF_REG_DIODE , reg);break ; } }static struct w83627ehf_data *w83627ehf_update_device (struct device *dev) { -struct i2c_client *client =to_i2c_client (dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); +struct w83627ehf_data *data =dev_get_drvdata (dev);int pwmcfg =0 , tolerance =0 ;/* shut up the compiler */ int i;
@@ -426,33 +421,33 @@if (time_after (jiffies, data->last_updated +HZ ) || !data->valid) {/* Fan clock dividers */ - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 ); data->fan_div[0 ] = (i >>4 ) &0x03 ; data->fan_div[1 ] = (i >>6 ) &0x03 ; - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV2 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV2 ); data->fan_div[2 ] = (i >>6 ) &0x03 ; - i =w83627ehf_read_value (client,W83627EHF_REG_VBAT ); + i =w83627ehf_read_value (data,W83627EHF_REG_VBAT ); data->fan_div[0 ] |= (i >>3 ) &0x04 ; data->fan_div[1 ] |= (i >>4 ) &0x04 ; data->fan_div[2 ] |= (i >>5 ) &0x04 ;if (data->has_fan & ((1 <<3 ) | (1 <<4 ))) { - i =w83627ehf_read_value (client,W83627EHF_REG_DIODE ); + i =w83627ehf_read_value (data,W83627EHF_REG_DIODE ); data->fan_div[3 ] = i &0x03 ; data->fan_div[4 ] = ((i >>2 ) &0x03 ) | ((i >>5 ) &0x04 ); }if (data->has_fan & (1 <<3 )) { - i =w83627ehf_read_value (client,W83627EHF_REG_SMI_OVT ); + i =w83627ehf_read_value (data,W83627EHF_REG_SMI_OVT ); data->fan_div[3 ] |= (i >>5 ) &0x04 ; }/* Measured voltages and limits */ -for (i =0 ; i < w83627ehf_num_in; i++) { - data->in[i] =w83627ehf_read_value (client, +for (i =0 ; i < data->in_num; i++) { + data->in[i] =w83627ehf_read_value (data,W83627EHF_REG_IN (i)); - data->in_min[i] =w83627ehf_read_value (client, + data->in_min[i] =w83627ehf_read_value (data,W83627EHF_REG_IN_MIN (i)); - data->in_max[i] =w83627ehf_read_value (client, + data->in_max[i] =w83627ehf_read_value (data,W83627EHF_REG_IN_MAX (i)); }
@@ -461,9 +456,9 @@if (!(data->has_fan & (1 << i)))continue ; - data->fan[i] =w83627ehf_read_value (client, + data->fan[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN [i]); - data->fan_min[i] =w83627ehf_read_value (client, + data->fan_min[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN [i]);/* If we failed to measure the fan speed and clock
@@ -471,16 +466,16 @@time */ if (data->fan[i] ==0xff && data->fan_div[i] <0x07 ) { -dev_dbg (&client->dev,"Increasing fan %d " +dev_dbg (dev,"Increasing fan %d " "clock divider from %u to %u\n" , i,div_from_reg (data->fan_div[i]),div_from_reg (data->fan_div[i] +1 )); data->fan_div[i]++; -w83627ehf_write_fan_div (client, i); +w83627ehf_write_fan_div (data, i);/* Preserve min limit if possible */ if (data->fan_min[i] >=2 && data->fan_min[i] !=255 ) -w83627ehf_write_value (client, +w83627ehf_write_value (data,W83627EHF_REG_FAN_MIN [i], (data->fan_min[i] /=2 )); }
@@ -489,9 +484,9 @@for (i =0 ; i <4 ; i++) {/* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ if (i !=1 ) { - pwmcfg =w83627ehf_read_value (client, + pwmcfg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [i]); - tolerance =w83627ehf_read_value (client, + tolerance =w83627ehf_read_value (data,W83627EHF_REG_TOLERANCE [i]); } data->pwm_mode[i] =
@@ -500,14 +495,14 @@ data->pwm_enable[i] = ((pwmcfg >>W83627EHF_PWM_ENABLE_SHIFT [i]) &3 ) +1 ; - data->pwm[i] =w83627ehf_read_value (client, + data->pwm[i] =w83627ehf_read_value (data,W83627EHF_REG_PWM [i]); - data->fan_min_output[i] =w83627ehf_read_value (client, + data->fan_min_output[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN_OUTPUT [i]); - data->fan_stop_time[i] =w83627ehf_read_value (client, + data->fan_stop_time[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_STOP_TIME [i]); data->target_temp[i] = -w83627ehf_read_value (client, +w83627ehf_read_value (data,W83627EHF_REG_TARGET [i]) & (data->pwm_mode[i] ==1 ?0x7f :0xff ); data->tolerance[i] = (tolerance >> (i ==1 ?4 :0 ))
@@ -515,26 +510,26 @@ }/* Measured temperatures and limits */ - data->temp1 =w83627ehf_read_value (client, + data->temp1 =w83627ehf_read_value (data,W83627EHF_REG_TEMP1 ); - data->temp1_max =w83627ehf_read_value (client, + data->temp1_max =w83627ehf_read_value (data,W83627EHF_REG_TEMP1_OVER ); - data->temp1_max_hyst =w83627ehf_read_value (client, + data->temp1_max_hyst =w83627ehf_read_value (data,W83627EHF_REG_TEMP1_HYST );for (i =0 ; i <2 ; i++) { - data->temp[i] =w83627ehf_read_value (client, + data->temp[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP [i]); - data->temp_max[i] =w83627ehf_read_value (client, + data->temp_max[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP_OVER [i]); - data->temp_max_hyst[i] =w83627ehf_read_value (client, + data->temp_max_hyst[i] =w83627ehf_read_value (data,W83627EHF_REG_TEMP_HYST [i]); } - data->alarms =w83627ehf_read_value (client, + data->alarms =w83627ehf_read_value (data,W83627EHF_REG_ALARM1 ) | - (w83627ehf_read_value (client, + (w83627ehf_read_value (data,W83627EHF_REG_ALARM2 ) <<8 ) | - (w83627ehf_read_value (client, + (w83627ehf_read_value (data,W83627EHF_REG_ALARM3 ) <<16 ); data->last_updated = jiffies;
@@ -567,15 +562,14 @@ store_in_##reg (struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->in_##reg[nr] = in_to_reg(val, nr); \ - w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ + w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ data->in_##reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -673,8 +667,7 @@ store_fan_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;unsigned int val =simple_strtoul (buf,NULL ,10 );
@@ -725,9 +718,9 @@ nr +1 ,div_from_reg (data->fan_div[nr]), div_from_reg(new_div)); data->fan_div[nr] = new_div; -w83627ehf_write_fan_div (client, nr); +w83627ehf_write_fan_div (data, nr); } -w83627ehf_write_value (client,W83627EHF_REG_FAN_MIN [nr], +w83627ehf_write_value (data,W83627EHF_REG_FAN_MIN [nr], data->fan_min[nr]);mutex_unlock (&data->update_lock);
@@ -788,13 +781,12 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \ data->temp1_##reg); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -822,15 +814,14 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->reg[nr] = LM75_TEMP_TO_REG(val); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ data->reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \
@@ -877,8 +868,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =simple_strtoul (buf,NULL ,10 );
@@ -887,12 +877,12 @@if (val >1 )return -EINVAL ;mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_PWM_ENABLE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [nr]); data->pwm_mode[nr] = val; reg &= ~(1 <<W83627EHF_PWM_MODE_SHIFT [nr]);if (!val) reg |=1 <<W83627EHF_PWM_MODE_SHIFT [nr]; -w83627ehf_write_value (client,W83627EHF_REG_PWM_ENABLE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_PWM_ENABLE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -901,15 +891,14 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =SENSORS_LIMIT (simple_strtoul (buf,NULL ,10 ),0 ,255 );mutex_lock (&data->update_lock); data->pwm[nr] = val; -w83627ehf_write_value (client,W83627EHF_REG_PWM [nr], val); +w83627ehf_write_value (data,W83627EHF_REG_PWM [nr], val);mutex_unlock (&data->update_lock);return count; }
@@ -918,8 +907,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u32 val =simple_strtoul (buf,NULL ,10 );
@@ -928,11 +916,11 @@if (!val || (val >2 ))/* only modes 1 and 2 are supported */ return -EINVAL ;mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_PWM_ENABLE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_PWM_ENABLE [nr]); data->pwm_enable[nr] = val; reg &= ~(0x03 <<W83627EHF_PWM_ENABLE_SHIFT [nr]); reg |= (val -1 ) <<W83627EHF_PWM_ENABLE_SHIFT [nr]; -w83627ehf_write_value (client,W83627EHF_REG_PWM_ENABLE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_PWM_ENABLE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -955,15 +943,14 @@ store_target_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u8 val =temp1_to_reg (simple_strtoul (buf,NULL ,10 ),0 ,127000 );mutex_lock (&data->update_lock); data->target_temp[nr] = val; -w83627ehf_write_value (client,W83627EHF_REG_TARGET [nr], val); +w83627ehf_write_value (data,W83627EHF_REG_TARGET [nr], val);mutex_unlock (&data->update_lock);return count; }
@@ -972,8 +959,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); -struct w83627ehf_data *data =i2c_get_clientdata (client); + struct w83627ehf_data *data = dev_get_drvdata(dev);struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);int nr = sensor_attr->index;u16 reg;
@@ -981,13 +967,13 @@u8 val =temp1_to_reg (simple_strtoul (buf,NULL ,10 ),0 ,15000 );mutex_lock (&data->update_lock); - reg =w83627ehf_read_value (client,W83627EHF_REG_TOLERANCE [nr]); + reg =w83627ehf_read_value (data,W83627EHF_REG_TOLERANCE [nr]); data->tolerance[nr] = val;if (nr ==1 ) reg = (reg &0x0f ) | (val <<4 );else reg = (reg &0xf0 ) | val; -w83627ehf_write_value (client,W83627EHF_REG_TOLERANCE [nr], reg); +w83627ehf_write_value (data,W83627EHF_REG_TOLERANCE [nr], reg);mutex_unlock (&data->update_lock);return count; }
@@ -1058,14 +1044,13 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ {\ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ }
@@ -1087,21 +1072,29 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ data->pwm_mode[nr]); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ } \ fan_time_functions(fan_stop_time, FAN_STOP_TIME) +static ssize_t show_name (struct device *dev,struct device_attribute + *devattr,char *buf) +{ +struct w83627ehf_data *data =dev_get_drvdata (dev); + +return sprintf (buf,"%s\n" , data->name); +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
@@ -1126,7 +1119,7 @@ };/* -* Driver and client management +* Driver and platform management */ static void w83627ehf_device_remove_files (struct device *dev)
@@ -1134,12 +1127,13 @@/* some entries in the following arrays may not have been used in * device_create_file(), but device_remove_file() will ignore them */ int i; +struct w83627ehf_data *data =dev_get_drvdata (dev);for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays); i++)device_remove_file (dev, &sda_sf3_arrays[i].dev_attr);for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++)device_remove_file (dev, &sda_sf3_arrays_fan4[i].dev_attr); -for (i =0 ; i < w83627ehf_num_in; i++) { +for (i =0 ; i < data->in_num; i++) {device_remove_file (dev, &sda_in_input[i].dev_attr);device_remove_file (dev, &sda_in_alarm[i].dev_attr);device_remove_file (dev, &sda_in_min[i].dev_attr);
@@ -1160,86 +1154,73 @@ }for (i =0 ; i <ARRAY_SIZE (sda_temp); i++)device_remove_file (dev, &sda_temp[i].dev_attr); -} -static struct i2c_driver w83627ehf_driver; +device_remove_file (dev, &dev_attr_name); +} -static void w83627ehf_init_client (struct i2c_client *client) +/* w83627ehf_init_device() gets the monitoring functions started */ +static inline void __devinit w83627ehf_init_device (struct w83627ehf_data *data) {int i;u8 tmp;/* Start monitoring is needed */ - tmp =w83627ehf_read_value (client,W83627EHF_REG_CONFIG ); + tmp =w83627ehf_read_value (data,W83627EHF_REG_CONFIG );if (!(tmp &0x01 )) -w83627ehf_write_value (client,W83627EHF_REG_CONFIG , +w83627ehf_write_value (data,W83627EHF_REG_CONFIG , tmp |0x01 );/* Enable temp2 and temp3 if needed */ for (i =0 ; i <2 ; i++) { - tmp =w83627ehf_read_value (client, + tmp =w83627ehf_read_value (data,W83627EHF_REG_TEMP_CONFIG [i]);if (tmp &0x01 ) -w83627ehf_write_value (client, +w83627ehf_write_value (data,W83627EHF_REG_TEMP_CONFIG [i], tmp &0xfe ); } } -static int w83627ehf_detect (struct i2c_adapter *adapter) +/* w83627ehf_probe() looks for a Super-I/O chip at known addresses */ +static int __devinit w83627ehf_probe (struct platform_device *pdev) { -struct i2c_client *client; -struct w83627ehf_data *data; -struct device *dev; +struct device *dev = &pdev->dev; +struct w83627ehf_data *data =dev_get_drvdata (dev);u8 fan4pin, fan5pin;int i, err =0 ; -if (!request_region (address +REGION_OFFSET ,REGION_LENGTH , - w83627ehf_driver.driver.name)) { +if (!request_region (data->addr +REGION_OFFSET ,REGION_LENGTH , +DRVNAME )) { err = -EBUSY ; +dev_err (dev,"Failed to request region 0x%lx-0x%lx\n" , + (unsigned long ) (data->addr +REGION_OFFSET ), + (unsigned long ) ( + data->addr +REGION_OFFSET +REGION_LENGTH -1 )); goto exit; } -if (!(data =kzalloc (sizeof (struct w83627ehf_data ),GFP_KERNEL ))) { - err = -ENOMEM ; - goto exit_release; - } - - client = &data->client; -i2c_set_clientdata (client, data); - client->addr = address; -mutex_init (&data->lock); - client->adapter = adapter; - client->driver = &w83627ehf_driver; - client->flags =0 ; - dev = &client->dev; - -if (w83627ehf_num_in ==9 ) -strlcpy (client->name,"w83627dhg" ,I2C_NAME_SIZE ); -else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ -strlcpy (client->name,"w83627ehf" ,I2C_NAME_SIZE ); +/* fill in fields in *data so w83627ehf_read_value(), etc., work */ data->valid =0 ; +mutex_init (&data->lock);mutex_init (&data->update_lock); -/* Tell the i2c layer a new client has arrived */ -if ((err =i2c_attach_client (client))) - goto exit_free; +/* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ + data->in_num = (data->kind == w83627dhg) ?9 :10 ;/* Initialize the chip */ -w83627ehf_init_client (client); +w83627ehf_init_device (data); -/* A few vars need to be filled upon startup */ for (i =0 ; i <5 ; i++) - data->fan_min[i] =w83627ehf_read_value (client, + data->fan_min[i] =w83627ehf_read_value (data,W83627EHF_REG_FAN_MIN [i]);/* fan4 and fan5 share some pins with the GPIO and serial flash */ -superio_enter (); - fan5pin =superio_inb (0x24 ) &0x2 ; - fan4pin =superio_inb (0x29 ) &0x6 ; -superio_exit (); +superio_enter (data->sioreg); + fan5pin =superio_inb (data->sioreg,0x24 ) &0x2 ; + fan4pin =superio_inb (data->sioreg,0x29 ) &0x6 ; +superio_exit (data->sioreg);/* It looks like fan4 and fan5 pins can be alternatively used as fan on/off switches, but fan5 control is write only :/
@@ -1248,7 +1229,7 @@is not the default. */ data->has_fan =0x07 ;/* fan1, fan2 and fan3 */ - i =w83627ehf_read_value (client,W83627EHF_REG_FANDIV1 ); + i =w83627ehf_read_value (data,W83627EHF_REG_FANDIV1 );if ((i & (1 <<2 )) && (!fan4pin)) data->has_fan |= (1 <<3 );if (!(i & (1 <<1 )) && (!fan5pin))
@@ -1257,18 +1238,17 @@/* Register sysfs hooks */ for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays); i++)if ((err =device_create_file (dev, - &sda_sf3_arrays[i].dev_attr))) + &sda_sf3_arrays[i].dev_attr))) goto exit_remove;/* if fan4 is enabled create the sf3 files for it */ if (data->has_fan & (1 <<3 )) -for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++) { +for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++)if ((err =device_create_file (dev, - &sda_sf3_arrays_fan4[i].dev_attr))) + &sda_sf3_arrays_fan4[i].dev_attr))) goto exit_remove; - } -for (i =0 ; i < w83627ehf_num_in; i++) +for (i =0 ; i < data->in_num; i++)if ((err =device_create_file (dev, &sda_in_input[i].dev_attr)) || (err =device_create_file (dev, &sda_in_alarm[i].dev_attr))
@@ -1308,6 +1288,10 @@if ((err =device_create_file (dev, &sda_temp[i].dev_attr))) goto exit_remove; + err =device_create_file (dev, &dev_attr_name); +if (err) + goto exit_remove; + data->class_dev =hwmon_device_register (dev);if (IS_ERR (data->class_dev)) { err =PTR_ERR (data->class_dev);
@@ -1318,95 +1302,175 @@ exit_remove:w83627ehf_device_remove_files (dev); -i2c_detach_client (client); -exit_free: -kfree (data); -exit_release: -release_region (address +REGION_OFFSET ,REGION_LENGTH ); +release_region (data->addr +REGION_OFFSET ,REGION_LENGTH ); exit:return err; } -static int w83627ehf_detach_client (struct i2c_client *client) +static int __devexit w83627ehf_remove(struct platform_device *pdev) { -struct w83627ehf_data *data =i2c_get_clientdata (client); -int err; +struct w83627ehf_data *data =platform_get_drvdata (pdev);hwmon_device_unregister (data->class_dev); -w83627ehf_device_remove_files (&client->dev); +w83627ehf_device_remove_files (&pdev->dev); +platform_set_drvdata (pdev,NULL ); -if ((err =i2c_detach_client (client))) -return err; -release_region (client->addr +REGION_OFFSET ,REGION_LENGTH );kfree (data);return 0 ; } -static struct i2c_driver w83627ehf_driver = { +static struct platform_driver w83627ehf_driver = { .driver = { .owner =THIS_MODULE , - .name ="w83627ehf" , + .name =DRVNAME , }, - .attach_adapter = w83627ehf_detect, - .detach_client = w83627ehf_detach_client, + .probe = w83627ehf_probe, + .remove =__devexit_p (w83627ehf_remove), }; -static int __init w83627ehf_find (int sioaddr,unsigned short *addr) +/* w83627ehf_superio_probe() looks for a '627 in the Super-I/O config space */ +static int __init w83627ehf_superio_probe (int sioaddr, +struct w83627ehf_data *data) {u16 val; -REG = sioaddr; -VAL = sioaddr +1 ; -superio_enter (); +static const char *__initdata sio_names[] = { +"W83627EHF" , +"W83627EHG" , +"W83627DHG" , + }; + +const char * sio_name; - val = (superio_inb (SIO_REG_DEVID ) <<8 ) - |superio_inb (SIO_REG_DEVID +1 ); + data->sioreg = sioaddr; + +superio_enter (data->sioreg); + + val = (superio_inb (data->sioreg,SIO_REG_DEVID ) <<8 ) + |superio_inb (data->sioreg,SIO_REG_DEVID +1 );switch (val &SIO_ID_MASK ) { -case SIO_W83627DHG_ID : - w83627ehf_num_in =9 ; -break ;case SIO_W83627EHF_ID : + data->kind = w83627ehf; + sio_name = sio_names[0 ]; +break ;case SIO_W83627EHG_ID : - w83627ehf_num_in =10 ; + data->kind = w83627ehf; + sio_name = sio_names[1 ]; +break ; +case SIO_W83627DHG_ID : + data->kind = w83627dhg; + sio_name = sio_names[2 ];break ;default : -printk (KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n" , +pr_info (DRVNAME ": unsupported chip ID: 0x%04x\n" , val); -superio_exit (); +superio_exit (data->sioreg);return -ENODEV ; } -superio_select (W83627EHF_LD_HWM ); - val = (superio_inb (SIO_REG_ADDR ) <<8 ) - |superio_inb (SIO_REG_ADDR +1 ); - *addr = val ®ION_ALIGNMENT ; -if (*addr ==0 ) { -superio_exit (); +/* we have known chip find the HWMON base */ + +superio_select (data->sioreg,W83627EHF_LD_HWM ); + val = (superio_inb (data->sioreg,SIO_REG_ADDR ) <<8 ) + |superio_inb (data->sioreg,SIO_REG_ADDR +1 ); + data->addr = val ®ION_ALIGNMENT ; +if (data->addr ==0 ) { +superio_exit (data->sioreg);return -ENODEV ; }/* Activate logical device if needed */ - val =superio_inb (SIO_REG_ENABLE ); + val =superio_inb (data->sioreg,SIO_REG_ENABLE );if (!(val &0x01 )) -superio_outb (SIO_REG_ENABLE , val |0x01 ); +superio_outb (data->sioreg,SIO_REG_ENABLE , val |0x01 ); -superio_exit (); +superio_exit (data->sioreg); +pr_info (DRVNAME ": Found %s chip at %#x\n" , + sio_name, data->addr);return 0 ; } +/* when Super-I/O functions move to a separate file, the Super-I/O +* bus will manage the lifetime of the device and the w83627ehf driver +* but since we platform_device_alloc(), we must keep track of the device */ +struct platform_device * pdev; +static int __init sensors_w83627ehf_init (void ) { -if (w83627ehf_find (0x2e , &address) - &&w83627ehf_find (0x4e , &address)) -return -ENODEV ; +int err; +struct resource res; +struct w83627ehf_data *data; + +if (!(data =kzalloc (sizeof (struct w83627ehf_data ),GFP_KERNEL ))) { + err = -ENOMEM ; + goto exit; + } + +/* initialize data->kind, data->sioreg, and data->addr. +* +* when Super-I/O functions move to a separate file, the Super-I/O +* driver will probe 0x23 and 0x4e and auto-detect the presence of a +* w83627ehf hardware monitor, and call probe() */ +if (w83627ehf_superio_probe (0x2e , data) && +w83627ehf_superio_probe (0x4e , data)) { + err = -ENODEV ; + goto exit_free; + } -return i2c_isa_add_driver (&w83627ehf_driver); +if ((err =platform_driver_register (&w83627ehf_driver))!=0 ) + goto exit_free; + +if (!(pdev =platform_device_alloc (DRVNAME , data->addr))) { + err = -ENOMEM ; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit_unregister; + } + +platform_set_drvdata (pdev, data); + +memset (&res,0 ,sizeof (res)); + data->name = w83627ehf_device_names[data->kind]; + res.name = data->name; + res.start = data->addr +REGION_OFFSET ; + res.end = data->addr +REGION_OFFSET +REGION_LENGTH -1 ; + res.flags =IORESOURCE_IO ; + err =platform_device_add_resources (pdev, &res,1 ); +if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + +/* platform_device_add calls probe() */ + err =platform_device_add (pdev); +if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + +return 0 ; + +exit_device_put: + pdev->dev.platform_data =NULL ; +platform_device_put (pdev); +exit_unregister: +platform_driver_unregister (&w83627ehf_driver); +exit_free: +kfree (data); +exit: +return err; } static void __exit sensors_w83627ehf_exit(void) { -i2c_isa_del_driver (&w83627ehf_driver); +/* when Super-I/O functions move to a separate file, devices +* will be unregistered before unloading the module. +* +* for now, only one device is added in sensors_w83627ehf_init */ +platform_device_unregister (pdev); +platform_driver_unregister (&w83627ehf_driver); }MODULE_AUTHOR ("Jean Delvare <[email protected]>" );
drivers/hwmon/Kconfig +6 -9
@@ -527,7 +527,6 @@ config SENSORS_W83793 tristate "Winbond W83793" depends on HWMON && I2C && EXPERIMENTAL - select HWMON_VID help If you say yes here you get support for the Winbond W83793 hardware monitoring chip.
@@ -560,17 +559,15 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF" - depends on HWMON && I2C && EXPERIMENTAL - select I2C_ISA + tristate "Winbond W83627EHF/DHG" + depends on HWMON && EXPERIMENTAL help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that. + If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip. This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a version suited for specific Intel processor sensing (PECI). This driver can also be built as a module. If so, the module will be called w83627ehf.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi David,
Sorry for the late answer,
Quoted 9 lines · David Hubbard
Quoted 3 lines
I suggest adding warning messages when the base I/O isn't set and when we need to forcibly enable the device, as I did in the w83627hf driver. This will make support easier.
I'm not clear on which part of the w83627hf driver does this. I can't find the patch in the mail archives that converts w83627hf to a platform driver, but I think this is the section of code (pre-platform-driver) that you're talking about:
w83627hf.clines 1399-1403:
Quoted 7 lines
/* Minimize conflicts with other winbond i2c-only clients... */ /* disable i2c subclients... how to disable main i2c client?? */ /* force i2c address to relatively uncommon address */ w83627hf_write_value(client, W83781D_REG_I2C_SUBADDR, 0x89); w83627hf_write_value(client, W83781D_REG_I2C_ADDR, force_i2c);Let's make the "forcibly enable the device" a separate patch.
No, what I was referring to is something completely different:
static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
{
(...)
/* Activate logical device if needed */
val = superio_inb(SIO_REG_ENABLE);
if (!(val & 0x01))
superio_outb(SIO_REG_ENABLE, val | 0x01);
(...)
}Here we enable the device if we found it was disabled. My experience is that Super-I/O logical devices which aren't enabled by the BIOS are typically not meant to be used, they aren't wired properly. So the least we can do if we have to enable it is to log it to serve as a hint for users if the sensors readings don't make sense. The w83627hf driver does this.
But I do agree that this isn't related to the platform driver conversion and should be added in a different patch.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi David,
Quoted 1 line · David Hubbard
Here's a patch for your review.
Sorry for the delay, here's my review. Next time please avoid patches as base64 attachments.
Quoted 820 lines
This patch removes i2c-isa from the w83627ehf driver, moving over to a platform driver.
Signed-off-by David Hubbard <[email protected]>Index:
linux-2.6.21-rc3/drivers/hwmon/w83627ehf.c
=================================> ---linux-2.6.21-rc5/drivers/hwmon/w83627ehf.c2007-03-28 19:52:44.000000000 -0700
+++linux-2.6.21-rc5/drivers/hwmon/w83627ehf.c2007-03-29 12:55:53.000000000 -0700(quoted diff) +88
-93@@ -41,8 +41,8 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> -#include <linux/i2c.h> -#include <linux/i2c-isa.h> +#include <linux/jiffies.h> +#include <linux/platform_device.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h>@@ -50,25 +50,19 @@ #include <asm/io.h> #include "lm75.h" -/* The actual ISA address is read from Super-I/O configuration space */ -static unsigned short address; +enum kinds { w83627ehf, w83627dhg }; -/* - * Super-I/O constants and functions - */ +/* used to set data->name = w83627ehf_device_names[data->kind] */ +static const char * w83627ehf_device_names[] = { + "w83627ehf", + "w83627dhg", +}; + +#define DRVNAME "w83627ehf" /* - * The three following globals are initialized in w83627ehf_find(), before - * the i2c-isa device is created. Otherwise, they could be stored in - * w83627ehf_data. This is ugly, but necessary, and when the driver is next - * updated to become a platform driver, the globals will disappear. + * Super-I/O constants and functions */ -static int REG; /* The register to read/write */ -static int VAL; /* The value to read/write */ -/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This - * value is also used in w83627ehf_detect() to export a device name in sysfs - * (e.g. w83627ehf or w83627dhg) */ -static int w83627ehf_num_in; #define W83627EHF_LD_HWM 0x0b@@ -83,38 +77,38 @@ #define SIO_ID_MASK 0xFFF0 static inline void -superio_outb(int reg, int val) +superio_outb(int ioreg, int reg, int val) { - outb(reg, REG); - outb(val, VAL); + outb(reg, ioreg); + outb(val, ioreg + 1); } static inline int -superio_inb(int reg) +superio_inb(int ioreg, int reg) { - outb(reg, REG); - return inb(VAL); + outb(reg, ioreg); + return inb(ioreg + 1); } static inline void -superio_select(int ld) +superio_select(int ioreg, int ld) { - outb(SIO_REG_LDSEL, REG); - outb(ld, VAL); + outb(SIO_REG_LDSEL, ioreg); + outb(ld, ioreg + 1); } static inline void -superio_enter(void) +superio_enter(int ioreg) { - outb(0x87, REG); - outb(0x87, REG); + outb(0x87, ioreg); + outb(0x87, ioreg); } static inline void -superio_exit(void) +superio_exit(int ioreg) { - outb(0x02, REG); - outb(0x02, VAL); + outb(0x02, ioreg); + outb(0x02, ioreg + 1); } /*@@ -255,7 +249,11 @@ */ struct w83627ehf_data { - struct i2c_client client; + int sioreg; + enum kinds kind; + int addr; /* IO base of hw monitor block */ + const char *name; + struct class_device *class_dev; struct mutex lock;@@ -264,6 +262,7 @@ unsigned long last_updated; /* In jiffies */ /* Register values */ + u8 in_num; /* number of in inputs we have */ u8 in[10]; /* Register value */ u8 in_max[10]; /* Register value */ u8 in_min[10]; /* Register value */@@ -303,121 +302,117 @@ nothing for registers which live in bank 0. For others, they respectively set the bank register to the correct value (before the register is accessed), and back to 0 (afterwards). */ -static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg) +static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) { if (reg & 0xff00) { - outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); - outb_p(reg >> 8, client->addr + DATA_REG_OFFSET); + outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); + outb_p(reg >> 8, data->addr + DATA_REG_OFFSET); } } -static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg) +static inline void w83627ehf_reset_bank(struct w83627ehf_data *data, u16 reg) { if (reg & 0xff00) { - outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); - outb_p(0, client->addr + DATA_REG_OFFSET); + outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); + outb_p(0, data->addr + DATA_REG_OFFSET); } } -static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg) +static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) { - struct w83627ehf_data *data = i2c_get_clientdata(client); int res, word_sized = is_word_sized(reg); mutex_lock(&data->lock); - w83627ehf_set_bank(client, reg); - outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); - res = inb_p(client->addr + DATA_REG_OFFSET); + w83627ehf_set_bank(data, reg); + outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); + res = inb_p(data->addr + DATA_REG_OFFSET); if (word_sized) { outb_p((reg & 0xff) + 1, - client->addr + ADDR_REG_OFFSET); - res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET); + data->addr + ADDR_REG_OFFSET); + res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); } - w83627ehf_reset_bank(client, reg); + w83627ehf_reset_bank(data, reg); mutex_unlock(&data->lock); return res; } -static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value) +static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, u16 value) { - struct w83627ehf_data *data = i2c_get_clientdata(client); int word_sized = is_word_sized(reg); mutex_lock(&data->lock); - w83627ehf_set_bank(client, reg); - outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); + w83627ehf_set_bank(data, reg); + outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); if (word_sized) { - outb_p(value >> 8, client->addr + DATA_REG_OFFSET); + outb_p(value >> 8, data->addr + DATA_REG_OFFSET); outb_p((reg & 0xff) + 1, - client->addr + ADDR_REG_OFFSET); + data->addr + ADDR_REG_OFFSET); } - outb_p(value & 0xff, client->addr + DATA_REG_OFFSET); - w83627ehf_reset_bank(client, reg); + outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); + w83627ehf_reset_bank(data, reg); mutex_unlock(&data->lock); return 0; } /* This function assumes that the caller holds data->update_lock */ -static void w83627ehf_write_fan_div(struct i2c_client *client, int nr) +static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) { - struct w83627ehf_data *data = i2c_get_clientdata(client); u8 reg; switch (nr) { case 0: - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf) + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) | ((data->fan_div[0] & 0x03) << 4); /* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 << 4)) ? 1 : 0; - w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf) + w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) | ((data->fan_div[0] & 0x04) << 3); - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); break; case 1: - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f) + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) | ((data->fan_div[1] & 0x03) << 6); /* fan5 input control bit is write only, compute the value */ reg |= (data->has_fan & (1 << 4)) ? 1 : 0; - w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf) + w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) | ((data->fan_div[1] & 0x04) << 4); - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); break; case 2: - reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f) + reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) | ((data->fan_div[2] & 0x03) << 6); - w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg); - reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f) + w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); + reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) | ((data->fan_div[2] & 0x04) << 5); - w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); + w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); break; case 3: - reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc) + reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) | (data->fan_div[3] & 0x03); - w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); - reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f) + w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); + reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) | ((data->fan_div[3] & 0x04) << 5); - w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg); + w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); break; case 4: - reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73) + reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) | ((data->fan_div[4] & 0x03) << 3) | ((data->fan_div[4] & 0x04) << 5); - w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); + w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); break; } } static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ int i;@@ -426,33 +421,33 @@ if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { /* Fan clock dividers */ - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); data->fan_div[0] = (i >> 4) & 0x03; data->fan_div[1] = (i >> 6) & 0x03; - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2); + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); data->fan_div[2] = (i >> 6) & 0x03; - i = w83627ehf_read_value(client, W83627EHF_REG_VBAT); + i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); data->fan_div[0] |= (i >> 3) & 0x04; data->fan_div[1] |= (i >> 4) & 0x04; data->fan_div[2] |= (i >> 5) & 0x04; if (data->has_fan & ((1 << 3) | (1 << 4))) { - i = w83627ehf_read_value(client, W83627EHF_REG_DIODE); + i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); data->fan_div[3] = i & 0x03; data->fan_div[4] = ((i >> 2) & 0x03) | ((i >> 5) & 0x04); } if (data->has_fan & (1 << 3)) { - i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT); + i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); data->fan_div[3] |= (i >> 5) & 0x04; } /* Measured voltages and limits */ - for (i = 0; i < w83627ehf_num_in; i++) { - data->in[i] = w83627ehf_read_value(client, + for (i = 0; i < data->in_num; i++) { + data->in[i] = w83627ehf_read_value(data, W83627EHF_REG_IN(i)); - data->in_min[i] = w83627ehf_read_value(client, + data->in_min[i] = w83627ehf_read_value(data, W83627EHF_REG_IN_MIN(i)); - data->in_max[i] = w83627ehf_read_value(client, + data->in_max[i] = w83627ehf_read_value(data, W83627EHF_REG_IN_MAX(i)); }@@ -461,9 +456,9 @@ if (!(data->has_fan & (1 << i))) continue; - data->fan[i] = w83627ehf_read_value(client, + data->fan[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN[i]); - data->fan_min[i] = w83627ehf_read_value(client, + data->fan_min[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN_MIN[i]); /* If we failed to measure the fan speed and clock@@ -471,16 +466,16 @@ time */ if (data->fan[i] = 0xff && data->fan_div[i] < 0x07) { - dev_dbg(&client->dev, "Increasing fan %d " + dev_dbg(dev, "Increasing fan %d " "clock divider from %u to %u\n", i, div_from_reg(data->fan_div[i]), div_from_reg(data->fan_div[i] + 1)); data->fan_div[i]++; - w83627ehf_write_fan_div(client, i); + w83627ehf_write_fan_div(data, i); /* Preserve min limit if possible */ if (data->fan_min[i] >= 2 && data->fan_min[i] != 255) - w83627ehf_write_value(client, + w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[i], (data->fan_min[i] /= 2)); }@@ -489,9 +484,9 @@ for (i = 0; i < 4; i++) { /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ if (i != 1) { - pwmcfg = w83627ehf_read_value(client, + pwmcfg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[i]); - tolerance = w83627ehf_read_value(client, + tolerance = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[i]); } data->pwm_mode[i] > @@ -500,14 +495,14 @@(quoted diff) +81
-94data->pwm_enable[i] > ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) & 3) + 1; - data->pwm[i] = w83627ehf_read_value(client, + data->pwm[i] = w83627ehf_read_value(data, W83627EHF_REG_PWM[i]); - data->fan_min_output[i] = w83627ehf_read_value(client, + data->fan_min_output[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN_MIN_OUTPUT[i]); - data->fan_stop_time[i] = w83627ehf_read_value(client, + data->fan_stop_time[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN_STOP_TIME[i]); data->target_temp[i] > - w83627ehf_read_value(client, + w83627ehf_read_value(data, W83627EHF_REG_TARGET[i]) & (data->pwm_mode[i] = 1 ? 0x7f : 0xff); data->tolerance[i] = (tolerance >> (i = 1 ? 4 : 0))@@ -515,26 +510,26 @@ } /* Measured temperatures and limits */ - data->temp1 = w83627ehf_read_value(client, + data->temp1 = w83627ehf_read_value(data, W83627EHF_REG_TEMP1); - data->temp1_max = w83627ehf_read_value(client, + data->temp1_max = w83627ehf_read_value(data, W83627EHF_REG_TEMP1_OVER); - data->temp1_max_hyst = w83627ehf_read_value(client, + data->temp1_max_hyst = w83627ehf_read_value(data, W83627EHF_REG_TEMP1_HYST); for (i = 0; i < 2; i++) { - data->temp[i] = w83627ehf_read_value(client, + data->temp[i] = w83627ehf_read_value(data, W83627EHF_REG_TEMP[i]); - data->temp_max[i] = w83627ehf_read_value(client, + data->temp_max[i] = w83627ehf_read_value(data, W83627EHF_REG_TEMP_OVER[i]); - data->temp_max_hyst[i] = w83627ehf_read_value(client, + data->temp_max_hyst[i] = w83627ehf_read_value(data, W83627EHF_REG_TEMP_HYST[i]); } - data->alarms = w83627ehf_read_value(client, + data->alarms = w83627ehf_read_value(data, W83627EHF_REG_ALARM1) | - (w83627ehf_read_value(client, + (w83627ehf_read_value(data, W83627EHF_REG_ALARM2) << 8) | - (w83627ehf_read_value(client, + (w83627ehf_read_value(data, W83627EHF_REG_ALARM3) << 16); data->last_updated = jiffies;@@ -567,15 +562,14 @@ store_in_##reg (struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->in_##reg[nr] = in_to_reg(val, nr); \ - w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ + w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ data->in_##reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \@@ -673,8 +667,7 @@ store_fan_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; unsigned int val = simple_strtoul(buf, NULL, 10);@@ -725,9 +718,9 @@ nr + 1, div_from_reg(data->fan_div[nr]), div_from_reg(new_div)); data->fan_div[nr] = new_div; - w83627ehf_write_fan_div(client, nr); + w83627ehf_write_fan_div(data, nr); } - w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr], + w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[nr], data->fan_min[nr]); mutex_unlock(&data->update_lock);@@ -788,13 +781,12 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \ data->temp1_##reg); \ mutex_unlock(&data->update_lock); \ return count; \@@ -822,15 +814,14 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = simple_strtoul(buf, NULL, 10); \ \ mutex_lock(&data->update_lock); \ data->reg[nr] = LM75_TEMP_TO_REG(val); \ - w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ + w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ data->reg[nr]); \ mutex_unlock(&data->update_lock); \ return count; \@@ -877,8 +868,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; u32 val = simple_strtoul(buf, NULL, 10);@@ -887,12 +877,12 @@ if (val > 1) return -EINVAL; mutex_lock(&data->update_lock); - reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); + reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); data->pwm_mode[nr] = val; reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); if (!val) reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; - w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); + w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); mutex_unlock(&data->update_lock); return count; }@@ -901,15 +891,14 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); mutex_lock(&data->update_lock); data->pwm[nr] = val; - w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val); + w83627ehf_write_value(data, W83627EHF_REG_PWM[nr], val); mutex_unlock(&data->update_lock); return count; }@@ -918,8 +907,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; u32 val = simple_strtoul(buf, NULL, 10);@@ -928,11 +916,11 @@ if (!val || (val > 2)) /* only modes 1 and 2 are supported */ return -EINVAL; mutex_lock(&data->update_lock); - reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); + reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); data->pwm_enable[nr] = val; reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; - w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); + w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); mutex_unlock(&data->update_lock); return count; }@@ -955,15 +943,14 @@ store_target_temp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); mutex_lock(&data->update_lock); data->target_temp[nr] = val; - w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val); + w83627ehf_write_value(data, W83627EHF_REG_TARGET[nr], val); mutex_unlock(&data->update_lock); return count; }@@ -972,8 +959,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct i2c_client *client = to_i2c_client(dev); - struct w83627ehf_data *data = i2c_get_clientdata(client); + struct w83627ehf_data *data = dev_get_drvdata(dev); struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int nr = sensor_attr->index; u16 reg;@@ -981,13 +967,13 @@ u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); mutex_lock(&data->update_lock); - reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]); + reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); data->tolerance[nr] = val; if (nr = 1) reg = (reg & 0x0f) | (val << 4); else reg = (reg & 0xf0) | val; - w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg); + w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); mutex_unlock(&data->update_lock); return count; }@@ -1058,14 +1044,13 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ {\ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ }@@ -1087,21 +1072,29 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83627ehf_data *data = i2c_get_clientdata(client); \ + struct w83627ehf_data *data = dev_get_drvdata(dev); \ struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ int nr = sensor_attr->index; \ u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ data->pwm_mode[nr]); \ mutex_lock(&data->update_lock); \ data->reg[nr] = val; \ - w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ + w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ mutex_unlock(&data->update_lock); \ return count; \ } \ fan_time_functions(fan_stop_time, FAN_STOP_TIME) +static ssize_t show_name(struct device *dev, struct device_attribute + *devattr, char *buf) +{ + struct w83627ehf_data *data = dev_get_drvdata(dev); + + return sprintf(buf, "%s\n", data->name); +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,@@ -1126,7 +1119,7 @@ }; /* - * Driver and client management + * Driver and platform management */ static void w83627ehf_device_remove_files(struct device *dev)@@ -1134,12 +1127,13 @@ /* some entries in the following arrays may not have been used in * device_create_file(), but device_remove_file() will ignore them */ int i; + struct w83627ehf_data *data = dev_get_drvdata(dev); for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); - for (i = 0; i < w83627ehf_num_in; i++) { + for (i = 0; i < data->in_num; i++) { device_remove_file(dev, &sda_in_input[i].dev_attr); device_remove_file(dev, &sda_in_alarm[i].dev_attr); device_remove_file(dev, &sda_in_min[i].dev_attr);@@ -1160,86 +1154,73 @@ } for (i = 0; i < ARRAY_SIZE(sda_temp); i++) device_remove_file(dev, &sda_temp[i].dev_attr); -} -static struct i2c_driver w83627ehf_driver; + device_remove_file(dev, &dev_attr_name); +} -static void w83627ehf_init_client(struct i2c_client *client) +/* w83627ehf_init_device() gets the monitoring functions started */ +static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data) { int i; u8 tmp; /* Start monitoring is needed */ - tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG); + tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); if (!(tmp & 0x01)) - w83627ehf_write_value(client, W83627EHF_REG_CONFIG, + w83627ehf_write_value(data, W83627EHF_REG_CONFIG, tmp | 0x01); /* Enable temp2 and temp3 if needed */ for (i = 0; i < 2; i++) { - tmp = w83627ehf_read_value(client, + tmp = w83627ehf_read_value(data, W83627EHF_REG_TEMP_CONFIG[i]); if (tmp & 0x01) - w83627ehf_write_value(client, + w83627ehf_write_value(data, W83627EHF_REG_TEMP_CONFIG[i], tmp & 0xfe); } } -static int w83627ehf_detect(struct i2c_adapter *adapter) +/* w83627ehf_probe() looks for a Super-I/O chip at known addresses */ +static int __devinit w83627ehf_probe(struct platform_device *pdev) { - struct i2c_client *client; - struct w83627ehf_data *data; - struct device *dev; + struct device *dev = &pdev->dev; + struct w83627ehf_data *data = dev_get_drvdata(dev); u8 fan4pin, fan5pin; int i, err = 0; - if (!request_region(address + REGION_OFFSET, REGION_LENGTH, - w83627ehf_driver.driver.name)) { + if (!request_region(data->addr + REGION_OFFSET, REGION_LENGTH, + DRVNAME)) { err = -EBUSY; + dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", + (unsigned long) (data->addr + REGION_OFFSET), + (unsigned long) ( + data->addr + REGION_OFFSET + REGION_LENGTH - 1)); goto exit; } - if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit_release; - } - - client = &data->client; - i2c_set_clientdata(client, data); - client->addr = address; - mutex_init(&data->lock); - client->adapter = adapter; - client->driver = &w83627ehf_driver; - client->flags = 0; - dev = &client->dev; - - if (w83627ehf_num_in = 9) - strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE); - else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ - strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); + /* fill in fields in *data so w83627ehf_read_value(), etc., work */ data->valid = 0; + mutex_init(&data->lock); mutex_init(&data->update_lock); - /* Tell the i2c layer a new client has arrived */ - if ((err = i2c_attach_client(client))) - goto exit_free; + /* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ + data->in_num = (data->kind = w83627dhg) ? 9 : 10; /* Initialize the chip */ - w83627ehf_init_client(client); + w83627ehf_init_device(data); - /* A few vars need to be filled upon startup */ for (i = 0; i < 5; i++) - data->fan_min[i] = w83627ehf_read_value(client, + data->fan_min[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN_MIN[i]); /* fan4 and fan5 share some pins with the GPIO and serial flash */ - superio_enter(); - fan5pin = superio_inb(0x24) & 0x2; - fan4pin = superio_inb(0x29) & 0x6; - superio_exit(); + superio_enter(data->sioreg); + fan5pin = superio_inb(data->sioreg, 0x24) & 0x2; + fan4pin = superio_inb(data->sioreg, 0x29) & 0x6; + superio_exit(data->sioreg); /* It looks like fan4 and fan5 pins can be alternatively used as fan on/off switches, but fan5 control is write only :/@@ -1248,7 +1229,7 @@ is not the default. */ data->has_fan = 0x07; /* fan1, fan2 and fan3 */ - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); if ((i & (1 << 2)) && (!fan4pin)) data->has_fan |= (1 << 3); if (!(i & (1 << 1)) && (!fan5pin))@@ -1257,18 +1238,17 @@ /* Register sysfs hooks */ for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) if ((err = device_create_file(dev, - &sda_sf3_arrays[i].dev_attr))) + &sda_sf3_arrays[i].dev_attr))) goto exit_remove;
Review line 1269
Quoted 10 lines
(quoted diff) +2
-3/* if fan4 is enabled create the sf3 files for it */ if (data->has_fan & (1 << 3)) - for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) { + for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) if ((err = device_create_file(dev, - &sda_sf3_arrays_fan4[i].dev_attr))) + &sda_sf3_arrays_fan4[i].dev_attr))) goto exit_remove; - }
These are cleanups which do not belong to this patch.
Quoted 36 lines
(quoted diff) +7
-9- for (i = 0; i < w83627ehf_num_in; i++) + for (i = 0; i < data->in_num; i++) if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) || (err = device_create_file(dev, &sda_in_alarm[i].dev_attr))@@ -1308,6 +1288,10 @@ if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) goto exit_remove; + err = device_create_file(dev, &dev_attr_name); + if (err) + goto exit_remove; + data->class_dev = hwmon_device_register(dev); if (IS_ERR(data->class_dev)) { err = PTR_ERR(data->class_dev);@@ -1318,95 +1302,175 @@ exit_remove: w83627ehf_device_remove_files(dev); - i2c_detach_client(client); -exit_free: - kfree(data); -exit_release: - release_region(address + REGION_OFFSET, REGION_LENGTH); + release_region(data->addr + REGION_OFFSET, REGION_LENGTH); exit: return err; } -static int w83627ehf_detach_client(struct i2c_client *client) +static int __devexit w83627ehf_remove(struct platform_device *pdev) { - struct w83627ehf_data *data = i2c_get_clientdata(client); - int err;
Review line 1340
Quoted 10 lines
(quoted diff) +3
-4+ struct w83627ehf_data *data = platform_get_drvdata(pdev); hwmon_device_unregister(data->class_dev); - w83627ehf_device_remove_files(&client->dev); + w83627ehf_device_remove_files(&pdev->dev); + platform_set_drvdata(pdev, NULL); - if ((err = i2c_detach_client(client))) - return err; - release_region(client->addr + REGION_OFFSET, REGION_LENGTH);
You shouldn't remove this. You requested the region in .probe(), you _must_ release it in .remove()!
Review line 1318
Quoted 1 line
(quoted diff) +0
-0kfree(data);
OTOH it's weird to free data here while you did not allocate it in .probe().
Quoted 22 lines
(quoted diff) +7
-5return 0; } -static struct i2c_driver w83627ehf_driver = { +static struct platform_driver w83627ehf_driver = { .driver = { .owner = THIS_MODULE, - .name = "w83627ehf", + .name = DRVNAME, }, - .attach_adapter = w83627ehf_detect, - .detach_client = w83627ehf_detach_client, + .probe = w83627ehf_probe, + .remove = __devexit_p(w83627ehf_remove), }; -static int __init w83627ehf_find(int sioaddr, unsigned short *addr) +/* w83627ehf_superio_probe() looks for a '627 in the Super-I/O config space */ +static int __init w83627ehf_superio_probe(int sioaddr, + struct w83627ehf_data *data) {
Review line 1341
Quoted 10 lines
(quoted diff) +5
-3u16 val; - REG = sioaddr; - VAL = sioaddr + 1; - superio_enter(); + static const char * __initdata sio_names[] = { + "W83627EHF", + "W83627EHG", + "W83627DHG", + };
This probably doesn't do what you think it does. Here the __initdata only applies to the pointers, not to the strings. So you aren't saving anything compared to putting the strings directly in the switch/case code.
If you really want the strings themselves to be __initdata, then you have to define an array of arrays of chars, not an array of pointers:
static const char __initdata sio_names[][10] = {
"W83627EHF",
"W83627EHG",
"W83627DHG",
};With the drawback that you have to be careful to size the buffers properly. gcc will unfortunately not complain if the trailing \0 doesn't fit, so it seems safer to explicitly add it yourself. (I consider it a bug in gcc.)
Quite frankly, I don't think this is worth the trouble, and I would put the strings in the code directly.
Quoted 41 lines
(quoted diff) +19
-12+ + const char * sio_name; - val = (superio_inb(SIO_REG_DEVID) << 8) - | superio_inb(SIO_REG_DEVID + 1); + data->sioreg = sioaddr; + + superio_enter(data->sioreg); + + val = (superio_inb(data->sioreg, SIO_REG_DEVID) << 8) + | superio_inb(data->sioreg, SIO_REG_DEVID + 1); switch (val & SIO_ID_MASK) { - case SIO_W83627DHG_ID: - w83627ehf_num_in = 9; - break; case SIO_W83627EHF_ID: + data->kind = w83627ehf; + sio_name = sio_names[0]; + break; case SIO_W83627EHG_ID: - w83627ehf_num_in = 10; + data->kind = w83627ehf; + sio_name = sio_names[1]; + break; + case SIO_W83627DHG_ID: + data->kind = w83627dhg; + sio_name = sio_names[2]; break; default: - printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n", + pr_info(DRVNAME ": unsupported chip ID: 0x%04x\n", val); - superio_exit(); + superio_exit(data->sioreg); return -ENODEV; } - superio_select(W83627EHF_LD_HWM); - val = (superio_inb(SIO_REG_ADDR) << 8) - | superio_inb(SIO_REG_ADDR + 1); - *addr = val & REGION_ALIGNMENT;
Review line 1378
Quoted 10 lines
(quoted diff) +8
-2- if (*addr = 0) { - superio_exit(); + /* we have known chip find the HWMON base */ + + superio_select(data->sioreg, W83627EHF_LD_HWM); + val = (superio_inb(data->sioreg, SIO_REG_ADDR) << 8) + | superio_inb(data->sioreg, SIO_REG_ADDR + 1); + data->addr = val & REGION_ALIGNMENT; + if (data->addr = 0) { + superio_exit(data->sioreg);
Note for a future patch: it would be user-friendly to log the reason why we're exiting here.
Review line 1385
Quoted 9 lines
(quoted diff) +2
-2return -ENODEV; } /* Activate logical device if needed */ - val = superio_inb(SIO_REG_ENABLE); + val = superio_inb(data->sioreg, SIO_REG_ENABLE); if (!(val & 0x01)) - superio_outb(SIO_REG_ENABLE, val | 0x01); + superio_outb(data->sioreg, SIO_REG_ENABLE, val | 0x01);
Note for a future patch: it would be user-friendly to warn that the device was forcibly enabled and that the readings may not make sense.
Review line 1394
Quoted 11 lines
(quoted diff) +6
-1- superio_exit(); + superio_exit(data->sioreg); + pr_info(DRVNAME ": Found %s chip at %#x\n", + sio_name, data->addr); return 0; } +/* when Super-I/O functions move to a separate file, the Super-I/O + * bus will manage the lifetime of the device and the w83627ehf driver + * but since we platform_device_alloc(), we must keep track of the device */
The "and the w83627ehf driver" part of your sentence doesn't make much sense and should be removed? Either that, or a part is missing.
Review line 1395
Quoted 1 line
(quoted diff) +1
-0+struct platform_device * pdev;
Should be declared static. Usually we leave no space between the "*" and the variable name.
Quoted 4 lines
(quoted diff) +1
-1+ static int __init sensors_w83627ehf_init(void) { - if (w83627ehf_find(0x2e, &address)
Review line 1406
Quoted 10 lines
(quoted diff) +8
-2- && w83627ehf_find(0x4e, &address)) - return -ENODEV; + int err; + struct resource res; + struct w83627ehf_data *data; + + if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + }
This is an interesting approach. I did it differently in the other drivers. Your way saves some memory and some code, but OTOH it breaks the device driver model. The platform-specific data is supposed to be stored in dev.platform_data, NOT dev.driver_data. The code which instantiates the device isn't supposed to know how the driver is implemented. Nothing prevents a given device from being supported by more than one driver!
So setting dev.driver_dat before .probe() is called sounds bad, and I suspect we will have to move this part to the .probe() function once we have a superio subsystem, anyway. So we might as well do it now. What do you think?
Review line 1411
Quoted 5 lines
(quoted diff) +5
-0+ + /* initialize data->kind, data->sioreg, and data->addr. + * + * when Super-I/O functions move to a separate file, the Super-I/O + * driver will probe 0x23 and 0x4e and auto-detect the presence of a
Typo: 0x2e, not Ox23.
Review line 1420
Quoted 10 lines
(quoted diff) +8
-1+ * w83627ehf hardware monitor, and call probe() */ + if (w83627ehf_superio_probe(0x2e, data) && + w83627ehf_superio_probe(0x4e, data)) { + err = -ENODEV; + goto exit_free; + } - return i2c_isa_add_driver(&w83627ehf_driver); + if ((err = platform_driver_register(&w83627ehf_driver))!=0) + goto exit_free;
Please remove the "!=0".
Quoted 4 lines
(quoted diff) +4
-0+ + if (!(pdev = platform_device_alloc(DRVNAME, data->addr))) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n");
Review line 1434
Quoted 10 lines
(quoted diff) +10
-0+ goto exit_unregister; + } + + platform_set_drvdata(pdev, data); + + memset(&res, 0, sizeof(res)); + data->name = w83627ehf_device_names[data->kind]; + res.name = data->name; + res.start = data->addr + REGION_OFFSET; + res.end = data->addr + REGION_OFFSET + REGION_LENGTH - 1;
No alignment in code blocks please.
Quoted 24 lines
(quoted diff) +24
-0+ res.flags = IORESOURCE_IO; + err = platform_device_add_resources(pdev, &res, 1); + if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + + /* platform_device_add calls probe() */ + err = platform_device_add(pdev); + if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + + return 0; + +exit_device_put: + pdev->dev.platform_data = NULL; + platform_device_put(pdev); +exit_unregister: + platform_driver_unregister(&w83627ehf_driver); +exit_free:
Review line 1467
Quoted 10 lines
(quoted diff) +5
-1+ kfree(data); +exit: + return err; } static void __exit sensors_w83627ehf_exit(void) { - i2c_isa_del_driver(&w83627ehf_driver); + /* when Super-I/O functions move to a separate file, devices + * will be unregistered before unloading the module.
Not true. When Super-I/O handling is moved to a separate module, devices will live their life independently from a driver being loaded for them or not. So devices will survive the w83627ehf driver unloading.
Quoted 10 lines
(quoted diff) +4
-0+ * + * for now, only one device is added in sensors_w83627ehf_init */ + platform_device_unregister(pdev); + platform_driver_unregister(&w83627ehf_driver); } MODULE_AUTHOR("Jean Delvare <[email protected]>");
drivers/hwmon/Kconfig line 532
Quoted 7 lines
drivers/hwmon/Kconfig +0
-1@@ -527,7 +527,6 @@ config SENSORS_W83793 tristate "Winbond W83793" depends on HWMON && I2C && EXPERIMENTAL - select HWMON_VID help If you say yes here you get support for the Winbond W83793 hardware monitoring chip.
You definitely don't want to do that.
Quoted 14 lines
drivers/hwmon/Kconfig +2
-7@@ -560,17 +559,15 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF" - depends on HWMON && I2C && EXPERIMENTAL - select I2C_ISA + tristate "Winbond W83627EHF/DHG" + depends on HWMON && EXPERIMENTAL help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that.
drivers/hwmon/Kconfig line 573
Quoted 10 lines
drivers/hwmon/Kconfig +4
-1+ If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip. This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a version suited for specific Intel processor sensing (PECI). This driver can also be built as a module. If so, the module will be called w83627ehf.
Most of this doesn't belong to this patch and should be moved to a separate patch.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Jean,
Quoted 7 lines
Hi David,
Quoted 1 line · David Hubbard
Here's a patch for your review.
Sorry for the delay, here's my review. Next time please avoid patches as base64 attachments.
Gmail picks a bad encoding for .patch files, and I forgot to send them as .patch.txt. Sorry :-)
Quoted 1 line
These are cleanups which do not belong to this patch.
I removed them.
(snip)
Quoted 20 lines
Quoted 6 lines
(quoted diff) +1
-3-static int w83627ehf_detach_client(struct i2c_client *client) +static int __devexit w83627ehf_remove(struct platform_device *pdev) { - struct w83627ehf_data *data = i2c_get_clientdata(client); - int err;Review
Quoted 10 lines
(quoted diff) +3
-4+ struct w83627ehf_data *data = platform_get_drvdata(pdev); hwmon_device_unregister(data->class_dev); - w83627ehf_device_remove_files(&client->dev); + w83627ehf_device_remove_files(&pdev->dev); + platform_set_drvdata(pdev, NULL); - if ((err = i2c_detach_client(client))) - return err; - release_region(client->addr + REGION_OFFSET, REGION_LENGTH);You shouldn't remove this. You requested the region in .probe(), you _must_ release it in .remove()!
Quoted 4 lines
Quoted 1 line
kfree(data);OTOH it's weird to free data here while you did not allocate it in .probe().
So I added release_region() to w83627ehf_remove(). I left the kfree() in place (notice that the patch doesn't move it) even though I modified the way the data was allocated, because it is the simplest way of freeing the data. A more correct approach would be to get pdev->dev.platform_data in sensors_w83627ehf_exit and free it there. It does break the device driver model, and needs revision when the driver is moved over to a Super-I/O bus. I added a comment noting this.
Quoted 47 lines
Quoted 22 lines
return 0;}
(quoted diff) +7
-5-static struct i2c_driver w83627ehf_driver = { +static struct platform_driver w83627ehf_driver = { .driver = { .owner = THIS_MODULE, - .name = "w83627ehf", + .name = DRVNAME, }, - .attach_adapter = w83627ehf_detect, - .detach_client = w83627ehf_detach_client, + .probe = w83627ehf_probe, + .remove = __devexit_p(w83627ehf_remove), }; -static int __init w83627ehf_find(int sioaddr, unsigned short *addr) +/* w83627ehf_superio_probe() looks for a '627 in the Super-I/O config space */ +static int __init w83627ehf_superio_probe(int sioaddr, + struct w83627ehf_data *data) {Review
Quoted 10 lines
(quoted diff) +5
-3u16 val; - REG = sioaddr; - VAL = sioaddr + 1; - superio_enter(); + static const char * __initdata sio_names[] = { + "W83627EHF", + "W83627EHG", + "W83627DHG", + };This probably doesn't do what you think it does. Here the
__initdataonly applies to the pointers, not to the strings. So you aren't saving anything compared to putting the strings directly in the switch/case code.If you really want the strings themselves to be
__initdata, then you have to define an array of arrays of chars, not an array of pointers:static const char __initdata sio_names[][10] = { "W83627EHF", "W83627EHG", "W83627DHG", };
Quoted 7 lines
With the drawback that you have to be careful to size the buffers properly. gcc will unfortunately not complain if the trailing \0 doesn't fit, so it seems safer to explicitly add it yourself. (I consider it a bug in gcc.)
Quite frankly, I don't think this is worth the trouble, and I would put the strings in the code directly.
I revised the code to declare three separate __initdata strings. This should work.
Quoted 46 lines
Quoted 46 lines
(quoted diff) +22
-14+ + const char * sio_name; - val = (superio_inb(SIO_REG_DEVID) << 8) - | superio_inb(SIO_REG_DEVID + 1); + data->sioreg = sioaddr; + + superio_enter(data->sioreg); + + val = (superio_inb(data->sioreg, SIO_REG_DEVID) << 8) + | superio_inb(data->sioreg, SIO_REG_DEVID + 1); switch (val & SIO_ID_MASK) { - case SIO_W83627DHG_ID: - w83627ehf_num_in = 9; - break; case SIO_W83627EHF_ID: + data->kind = w83627ehf; + sio_name = sio_names[0]; + break; case SIO_W83627EHG_ID: - w83627ehf_num_in = 10; + data->kind = w83627ehf; + sio_name = sio_names[1]; + break; + case SIO_W83627DHG_ID: + data->kind = w83627dhg; + sio_name = sio_names[2]; break; default: - printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n", + pr_info(DRVNAME ": unsupported chip ID: 0x%04x\n", val); - superio_exit(); + superio_exit(data->sioreg); return -ENODEV; } - superio_select(W83627EHF_LD_HWM); - val = (superio_inb(SIO_REG_ADDR) << 8) - | superio_inb(SIO_REG_ADDR + 1); - *addr = val & REGION_ALIGNMENT; - if (*addr == 0) { - superio_exit(); + /* we have known chip find the HWMON base */ + + superio_select(data->sioreg, W83627EHF_LD_HWM);
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ val = (superio_inb(data->sioreg, SIO_REG_ADDR) << 8) + | superio_inb(data->sioreg, SIO_REG_ADDR + 1); + data->addr = val & REGION_ALIGNMENT; + if (data->addr == 0) { + superio_exit(data->sioreg);Note for a future patch: it would be user-friendly to log the reason why we're exiting here.
I am sending four patches this time. They apply to 2.6.22-rc2 and the third adds a warning here, as you suggest.
Quoted 10 lines
Review
Quoted 9 lines
return -ENODEV; } /* Activate logical device if needed */(quoted diff) +2
-2- val = superio_inb(SIO_REG_ENABLE); + val = superio_inb(data->sioreg, SIO_REG_ENABLE); if (!(val & 0x01)) - superio_outb(SIO_REG_ENABLE, val | 0x01); + superio_outb(data->sioreg, SIO_REG_ENABLE, val | 0x01);
Quoted 2 lines
Note for a future patch: it would be user-friendly to warn that the device was forcibly enabled and that the readings may not make sense.
Patch 03 adds a warning here also.
Quoted 8 lines
Quoted 8 lines
(quoted diff) +3
-1- superio_exit(); + superio_exit(data->sioreg); + pr_info(DRVNAME ": Found %s chip at %#x\n", + sio_name, data->addr); return 0; }
Quoted 6 lines
Quoted 3 lines
+/* when Super-I/O functions move to a separate file, the Super-I/O
+ * bus will manage the lifetime of the device and the w83627ehf driver
+ * but since weplatform_device_alloc(), we must keep track of the device */The "and the w83627ehf driver" part of your sentence doesn't make much sense and should be removed? Either that, or a part is missing.
You're right. I updated the comment.
Quoted 5 lines
Quoted 2 lines
+struct
platform_device* pdev;Should be declared static. Usually we leave no space between the "*" and the variable name.
Fixed.
Quoted 23 lines
Quoted 4 lines
(quoted diff) +1
-1+ static int __init sensors_w83627ehf_init(void) { - if (w83627ehf_find(0x2e, &address)Review
Quoted 10 lines
(quoted diff) +8
-2- && w83627ehf_find(0x4e, &address)) - return -ENODEV; + int err; + struct resource res; + struct w83627ehf_data *data; + + if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + }This is an interesting approach. I did it differently in the other drivers. Your way saves some memory and some code, but OTOH it breaks the device driver model. The platform-specific data is supposed to be stored in dev.platform_data, NOT dev.driver_data. The code which instantiates the device isn't supposed to know how the driver is implemented. Nothing prevents a given device from being supported by more than one driver!
Quoted 4 lines
So setting dev.driver_dat before .probe() is called sounds bad, and I suspect we will have to move this part to the .probe() function once we have a superio subsystem, anyway. So we might as well do it now. What do you think?
Yes, I've changed the code to use dev.platform_data instead of dev.driver_data. I guess I was uncomfortable with dev.platform_data because I looked at the function platform_device_add_data():
int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size)
{
void *d;
d = kmalloc(size, GFP_KERNEL);
if (d) {
memcpy(d, data, size);
pdev->dev.platform_data = d;
}
return d ? 0 : -ENOMEM;
}EXPORT_SYMBOL_GPL(platform_device_add_data);
If pdev->dev.platform_data is non-null on entry to this function it does not warn, it just leaks memory. (Example: a broken driver calls platform_device_add_data() twice in a row.) Or, I have misunderstood the function.
Is this a bug in platform.c? I notice you just modify pdev->dev.platform_data directly in w83627hf.c (2.6.22-rc2).
Either way, the driver needs revision in the future when devices are probed from a Super-I/O bus driver.
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + /* initialize data->kind, data->sioreg, and data->addr. + * + * when Super-I/O functions move to a separate file, the Super-I/O + * driver will probe 0x23 and 0x4e and auto-detect the presence of aTypo:
0x2e, not Ox23.
Good catch. Fixed.
Quoted 7 lines
Quoted 7 lines
(quoted diff) +6
-0+ * w83627ehf hardware monitor, and call probe() */ + if (w83627ehf_superio_probe(0x2e, data) && + w83627ehf_superio_probe(0x4e, data)) { + err = -ENODEV; + goto exit_free; + }
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-1- return i2c_isa_add_driver(&w83627ehf_driver); + if ((err = platform_driver_register(&w83627ehf_driver))!=0) + goto exit_free;Please remove the "!=0".
When I do that, I get the following warning:
CC [M] drivers/hwmon/w83627ehf.odrivers/hwmon/w83627ehf.c: In function 'sensors_w83627ehf_init':drivers/hwmon/w83627ehf.c:1428: warning: suggest parentheses around assignment used as truth value
So for now, the !=0 is still there, but I also added a comment.
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+ + if (!(pdev = platform_device_alloc(DRVNAME, data->addr))) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit_unregister; + } + + platform_set_drvdata(pdev, data);
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + memset(&res, 0, sizeof(res)); + data->name = w83627ehf_device_names[data->kind]; + res.name = data->name; + res.start = data->addr + REGION_OFFSET; + res.end = data->addr + REGION_OFFSET + REGION_LENGTH - 1;No alignment in code blocks please.
Fixed.
Quoted 29 lines
Quoted 29 lines
(quoted diff) +27
-0+ res.flags = IORESOURCE_IO; + err = platform_device_add_resources(pdev, &res, 1); + if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + + /* platform_device_add calls probe() */ + err = platform_device_add(pdev); + if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + + return 0; + +exit_device_put: + pdev->dev.platform_data = NULL; + platform_device_put(pdev); +exit_unregister: + platform_driver_unregister(&w83627ehf_driver); +exit_free: + kfree(data); +exit: + return err; }
Quoted 9 lines
Review
Quoted 5 lines
static void
__exitsensors_w83627ehf_exit(void)
{(quoted diff) +2
-1- i2c_isa_del_driver(&w83627ehf_driver); + /* when Super-I/O functions move to a separate file, devices + * will be unregistered before unloading the module.Not true. When Super-I/O handling is moved to a separate module, devices will live their life independently from a driver being loaded for them or not. So devices will survive the w83627ehf driver unloading.
Thank you for (patiently!) getting this through my head. So, I fixed the comment. I'll try to keep it from creeping in again. ;-)
Quoted 6 lines
Quoted 6 lines
(quoted diff) +4
-0+ * + * for now, only one device is added in sensors_w83627ehf_init */ + platform_device_unregister(pdev); + platform_driver_unregister(&w83627ehf_driver); }
Quoted 13 lines
drivers/hwmon/Kconfig 2007-03-28 20:50:11.000000000 -0700 line 532
Quoted 11 lines
MODULE_AUTHOR("Jean Delvare <[email protected]>");drivers/hwmon/Kconfig 2007-03-28 20:50:11.000000000 -0700 renamed from drivers/hwmon/Kconfig 2007-03-28 17:25:43.000000000 -0700 +0
-1@@ -527,7 +527,6 @@ config SENSORS_W83793 tristate "Winbond W83793" depends on HWMON && I2C && EXPERIMENTAL - select HWMON_VID help If you say yes here you get support for the Winbond W83793 hardware monitoring chip.You definitely don't want to do that.
Patch problems here stemmed from using the wrong file as the "original." Fixed. Note that there are Kconfig changes in both patch 01 and patch 02.
Quoted 22 lines
Quoted 22 lines
drivers/hwmon/Kconfig 2007-03-28 20:50:11.000000000 -0700 renamed from drivers/hwmon/Kconfig 2007-03-28 17:25:43.000000000 -0700 +6
-8@@ -560,17 +559,15 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF" - depends on HWMON && I2C && EXPERIMENTAL - select I2C_ISA + tristate "Winbond W83627EHF/DHG" + depends on HWMON && EXPERIMENTAL help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that. + If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip. This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a version suited for specific Intel processor sensing (PECI).
Quoted 5 lines
drivers/hwmon/Kconfig 2007-03-28 20:50:11.000000000 -0700 line 573
Quoted 2 lines
drivers/hwmon/Kconfig 2007-03-28 20:50:11.000000000 -0700 renamed from drivers/hwmon/Kconfig 2007-03-28 17:25:43.000000000 -0700 +0
-0This driver can also be built as a module. If so, the module will be called w83627ehf.Most of this doesn't belong to this patch and should be moved to a separate patch.
So it's now patch 01. The stuff that belongs in patch 02 is (I think) now all in patch 02. Patch 03 revises the error handling in a couple of places to give more meaningful error messages. Patch 04 fixes a long-standing bug where the driver outputs "Increasing fan 4 clock divider from 4 to 8" and fills up the kernel message log.
Please review when you get time.
Thanks,
David
Add descriptions for w83627ehg and w83627dhg chips to Kconfig
drivers/hwmon/Kconfig +6 -6
@@ -584,17 +584,17 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF" + tristate "Winbond W83627EHF/DHG" depends on I2C && EXPERIMENTAL select I2C_ISA help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that. + If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip. This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a similar chip suited for specific Intel processors that + use PECI such as the Core 2 Duo. This driver can also be built as a module. If so, the module will be called w83627ehf.
This patch removes i2c-isa from the w83627ehf driver, and uses a platform driver instead.
drivers/hwmon/w83627ehf.c +311 -237
1,044 lines not on this page · raw message
drivers/hwmon/Kconfig +1 -2
@@ -585,8 +585,7 @@ config SENSORS_W83627EHF tristate "Winbond W83627EHF/DHG" - depends on I2C && EXPERIMENTAL - select I2C_ISA + depends on HWMON && EXPERIMENTAL help If you say yes here you get support for the hardware monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip.
This patch adds more useful error messages for two error cases. If the Super-I/O device is disabled, it is likely the BIOS has a good reason for leaving it disabled, so give a warning when enabling it -- it's not likely to be wired correctly or be able to give good data.
Also, if the Super-I/O device is configured with an address of 0, the driver refuses to initialize it.
drivers/hwmon/w83627ehf.c +6 -1
@@ -1383,14 +1383,19 @@ | superio_inb(data->sioreg, SIO_REG_ADDR + 1); data->addr = val ®ION_ALIGNMENT ;if (data->addr ==0 ) { + printk(KERN_ERR DRVNAME ": refusing to enable a Super-I/O " + "device with a base I/O port 0.\n");superio_exit (data->sioreg);return -ENODEV ; }/* Activate logical device if needed */ val =superio_inb (data->sioreg,SIO_REG_ENABLE ); -if (!(val &0x01 )) +if (!(val &0x01 )) { + printk(KERN_WARNING DRVNAME ": Forcibly enabling Super-I/O. " + "Sensor is probably unusable.\n");superio_outb (data->sioreg,SIO_REG_ENABLE , val |0x01 ); + }superio_exit (data->sioreg); pr_info(DRVNAME ": Found %s chip at %#x\n",
This patch fixes a bug where the driver outputs
"Increasing fan 4 clock divider from 4 to 8" and fills up the kernel message log.
drivers/hwmon/w83627ehf.c +4 -5
@@ -403,7 +403,7 @@break ;case 4 : reg = (w83627ehf_read_value (data,W83627EHF_REG_DIODE ) &0x73 ) - | ((data->fan_div[4 ] &0x03 ) <<3 ) + | ((data->fan_div[4 ] &0x03 ) <<2 ) | ((data->fan_div[4 ] &0x04 ) <<5 );w83627ehf_write_value (data,W83627EHF_REG_DIODE , reg);break ;
@@ -468,7 +468,7 @@ && data->fan_div[i] < 0x07) {dev_dbg (dev,"Increasing fan %d " "clock divider from %u to %u\n" , - i,div_from_reg (data->fan_div[i]), + i+1 ,div_from_reg (data->fan_div[i]),div_from_reg (data->fan_div[i] +1 )); data->fan_div[i]++;w83627ehf_write_fan_div (data, i);
@@ -1243,11 +1243,10 @@/* if fan4 is enabled create the sf3 files for it */ if (data->has_fan & (1 <<3 )) -for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++) { +for (i =0 ; i <ARRAY_SIZE (sda_sf3_arrays_fan4); i++)if ((err =device_create_file (dev, - &sda_sf3_arrays_fan4[i].dev_attr))) + &sda_sf3_arrays_fan4[i].dev_attr))) goto exit_remove; - }for (i =0 ; i < data->in_num; i++) if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi David,
Quoted 25 lines · David Hubbard
Quoted 20 lines · David Hubbard
Quoted 5 lines
(quoted diff) +1
-3-static int w83627ehf_detach_client(struct i2c_client *client) +static int __devexit w83627ehf_remove(struct platform_device *pdev) { - struct w83627ehf_data *data = i2c_get_clientdata(client); - int err;Review
Quoted 10 lines
(quoted diff) +3
-4+ struct w83627ehf_data *data = platform_get_drvdata(pdev); hwmon_device_unregister(data->class_dev); - w83627ehf_device_remove_files(&client->dev); + w83627ehf_device_remove_files(&pdev->dev); + platform_set_drvdata(pdev, NULL); - if ((err = i2c_detach_client(client))) - return err; - release_region(client->addr + REGION_OFFSET, REGION_LENGTH);You shouldn't remove this. You requested the region in .probe(), you _must_ release it in .remove()!
Quoted 4 lines
Quoted 1 line
kfree(data);OTOH it's weird to free data here while you did not allocate it in .probe().
Quoted 8 lines
So I added
release_region()tow83627ehf_remove(). I left thekfree()in place (notice that the patch doesn't move it) even though I modified the way the data was allocated, because it is the simplest way of freeing the data. A more correct approach would be to getpdev->dev.platform_datainsensors_w83627ehf_exitand free it there. It does break the device driver model, and needs revision when the driver is moved over to a Super-I/O bus. I added a comment noting this.
A more correct approach, actually, would be to allocate data in .probe(). The data structure holds driver-specific data. More on that below.
Quoted 42 lines
Quoted 22 lines
Review
Quoted 13 lines
static int
__initsensors_w83627ehf_init(void)
{(quoted diff) +8
-3- if (w83627ehf_find(0x2e, &address) - && w83627ehf_find(0x4e, &address)) - return -ENODEV; + int err; + struct resource res; + struct w83627ehf_data *data; + + if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + }This is an interesting approach. I did it differently in the other drivers. Your way saves some memory and some code, but OTOH it breaks the device driver model. The platform-specific data is supposed to be stored in dev.platform_data, NOT dev.driver_data. The code which instantiates the device isn't supposed to know how the driver is implemented. Nothing prevents a given device from being supported by more than one driver!
Quoted 4 lines
So setting dev.driver_dat before .probe() is called sounds bad, and I suspect we will have to move this part to the .probe() function once we have a superio subsystem, anyway. So we might as well do it now. What do you think?
Yes, I've changed the code to use dev.platform_data instead of dev.driver_data. I guess I was uncomfortable with dev.platform_data because I looked at the function
platform_device_add_data():
intplatform_device_add_data(struct platform_device *pdev, const void *data, size_t size){ void *d; d = kmalloc(size, GFP_KERNEL); if (d) { memcpy(d, data, size); pdev->dev.platform_data = d; } return d ? 0 : -ENOMEM; }
Quoted 6 lines
EXPORT_SYMBOL_GPL(platform_device_add_data);If
pdev->dev.platform_datais non-null on entry to this function it does not warn, it just leaks memory. (Example: a broken driver callsplatform_device_add_data()twice in a row.) Or, I have misunderstood the function.
No, you're right, that's what the function does.
Quoted 1 line
Is this a bug in
platform.c?
No, the bug would be to call this function twice. You really have no reason to do that. You shouldn't expect all core functions to correct your usage mistakes. I know some functions do, but this has a cost in terms of performance and code readability so I'm glad this wasn't generalized.
Quoted 2 lines
I notice you just modify
pdev->dev.platform_datadirectly inw83627hf.c(2.6.22-rc2).
I probably didn't know platform_device_add_data() existed! I should have been using it, thanks for pointing this out. The w83627hf driver should be updated, as well as the f71805f and smsc47m1 drivers. Patch follows.
Quoted 2 lines
Either way, the driver needs revision in the future when devices are probed from a Super-I/O bus driver.
Sure, but if the driver already follows the device driver model, the amount of required changes will be smaller.
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +6
-0+ * w83627ehf hardware monitor, and call probe() */ + if (w83627ehf_superio_probe(0x2e, data) && + w83627ehf_superio_probe(0x4e, data)) { + err = -ENODEV; + goto exit_free; + }Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-1- return i2c_isa_add_driver(&w83627ehf_driver); + if ((err = platform_driver_register(&w83627ehf_driver))!=0) + goto exit_free;Please remove the "!=0".
Quoted 8 lines
When I do that, I get the following warning:
CC [M]
drivers/hwmon/w83627ehf.odrivers/hwmon/w83627ehf.c: In function 'sensors_w83627ehf_init':drivers/hwmon/w83627ehf.c:1428: warning: suggest parentheses around assignment used as truth valueSo for now, the !=0 is still there, but I also added a comment.
I suspect you have been removing the !=0 _and_ the extra parentheses. If I only remove the !=0 (which is what I wanted you to do) I do not get the warning.
Quoted 5 lines
So it's now patch 01. The stuff that belongs in patch 02 is (I think) now all in patch 02. Patch 03 revises the error handling in a couple of places to give more meaningful error messages. Patch 04 fixes a long-standing bug where the driver outputs "Increasing fan 4 clock divider from 4 to 8" and fills up the kernel message log.
Thanks for splitting the changes in multiple patches, this is very much appreciated. However there's a major problem with your patchset. The bug which your patch 04 fixes... it is _already_ fixed upstream:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h3725ad36d48c09e9537d3d7e680471c298539a9
The problem is that your patch 02 _reverts_ the fix. I guess you messed up when porting your patches to 2.6.22-rc2. I can only suggest using quilt to manage your patches.
Likewise, your patch 02 reverts this patch of mine which is upstream as well:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h641fceb6bb6b0930db1aadbda1aaf5711d65d6
So I must ask you to rework your patchset so that these two patches are no longer reverted. This will make your patch 02 smaller and your patch 04 will no longer exist.
Quoted 1 line
Please review when you get time.
Here you go. Patch 01:
Quoted 12 lines
Add descriptions for w83627ehg and w83627dhg chips to
KconfigSigned-off-by David Hubbard <[email protected]>Index: linux-2.6.22-rc2/drivers/hwmon/Kconfig
=================================> --- linux-2.6.22-rc2/drivers/hwmon/Kconfig 2007-05-17 11:01:23.000000000 -0700
+++ linux-2.6.22-rc2/drivers/hwmon/Kconfig 2007-05-17 11:20:52.000000000 -0700(quoted diff) +0
-1@@ -584,17 +584,17 @@ will be called w83627hf. config SENSORS_W83627EHF - tristate "Winbond W83627EHF"
Review line 592
Quoted 10 lines
(quoted diff) +3
-4+ tristate "Winbond W83627EHF/DHG" depends on I2C && EXPERIMENTAL select I2C_ISA help - If you say yes here you get preliminary support for the hardware - monitoring functionality of the Winbond W83627EHF Super-I/O chip. - Only fan and temperature inputs are supported at the moment, while - the chip does much more than that. + If you say yes here you get support for the hardware + monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip.
You can't list the DHG as supported here...
Review line 596
Quoted 6 lines
(quoted diff) +3
-1This driver also supports the W83627EHG, which is the lead-free - version of the W83627EHF. + version of the W83627EHF. The driver also supports the W83627DHG, + which is a similar chip suited for specific Intel processors that + use PECI such as the Core 2 Duo.
... and then say it's "also supported" there.
Review line 598
Quoted 3 lines
(quoted diff) +0
-0This driver can also be built as a module. If so, the module will be called w83627ehf.
Otherwise this patch could go in 2.6.22.
Patch 02 (quoting only the relevant parts):
Quoted 94 lines
This patch removes i2c-isa from the w83627ehf driver, and uses a platform driver instead.
Signed-off-by David Hubbard <[email protected]>Index:
linux-2.6.22-rc2/drivers/hwmon/w83627ehf.c
=================================> (...)(quoted diff) +21
-35-static int w83627ehf_detect(struct i2c_adapter *adapter) +/* w83627ehf_probe() looks for a Super-I/O chip at known addresses */ +static int __devinit w83627ehf_probe(struct platform_device *pdev) { - struct i2c_client *client; - struct w83627ehf_data *data; - struct device *dev; + struct device *dev = &pdev->dev; + struct w83627ehf_data *data = pdev->dev.platform_data; u8 fan4pin, fan5pin; int i, err = 0; - if (!request_region(address + IOREGION_OFFSET, IOREGION_LENGTH, - w83627ehf_driver.driver.name)) { + if (!request_region(data->addr + REGION_OFFSET, REGION_LENGTH, + DRVNAME)) { err = -EBUSY; + dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", + (unsigned long) (data->addr + REGION_OFFSET), + (unsigned long) ( + data->addr + REGION_OFFSET + REGION_LENGTH - 1)); goto exit; } - if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit_release; - } - - client = &data->client; - i2c_set_clientdata(client, data); - client->addr = address; - mutex_init(&data->lock); - client->adapter = adapter; - client->driver = &w83627ehf_driver; - client->flags = 0; - dev = &client->dev; - - if (w83627ehf_num_in = 9) - strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE); - else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ - strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); + /* fill in fields in *data so w83627ehf_read_value(), etc., work */ data->valid = 0; + mutex_init(&data->lock); mutex_init(&data->update_lock); - /* Tell the i2c layer a new client has arrived */ - if ((err = i2c_attach_client(client))) - goto exit_free; + /* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ + data->in_num = (data->kind = w83627dhg) ? 9 : 10; /* Initialize the chip */ - w83627ehf_init_client(client); + w83627ehf_init_device(data); - /* A few vars need to be filled upon startup */ for (i = 0; i < 5; i++) - data->fan_min[i] = w83627ehf_read_value(client, + data->fan_min[i] = w83627ehf_read_value(data, W83627EHF_REG_FAN_MIN[i]); /* fan4 and fan5 share some pins with the GPIO and serial flash */ - superio_enter(); - fan5pin = superio_inb(0x24) & 0x2; - fan4pin = superio_inb(0x29) & 0x6; - superio_exit(); + superio_enter(data->sioreg); + fan5pin = superio_inb(data->sioreg, 0x24) & 0x2; + fan4pin = superio_inb(data->sioreg, 0x29) & 0x6; + superio_exit(data->sioreg); /* It looks like fan4 and fan5 pins can be alternatively used as fan on/off switches, but fan5 control is write only :/@@ -1248,7 +1229,7 @@ is not the default. */ data->has_fan = 0x07; /* fan1, fan2 and fan3 */ - i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); + i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); if ((i & (1 << 2)) && (!fan4pin)) data->has_fan |= (1 << 3); if (!(i & (1 << 1)) && (!fan5pin))
Review line 1244
Quoted 8 lines
(quoted diff) +1
-1@@ -1257,7 +1238,7 @@ /* Register sysfs hooks */ for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) if ((err = device_create_file(dev, - &sda_sf3_arrays[i].dev_attr))) + &sda_sf3_arrays[i].dev_attr))) goto exit_remove; /* if fan4 is enabled create the sf3 files for it */
This cleanup would be better moved to the next patch.
Quoted 43 lines
(quoted diff) +12
-7@@ -1268,7 +1249,7 @@ goto exit_remove; } - for (i = 0; i < w83627ehf_num_in; i++) + for (i = 0; i < data->in_num; i++) if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) || (err = device_create_file(dev, &sda_in_alarm[i].dev_attr))@@ -1308,6 +1289,10 @@ if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) goto exit_remove; + err = device_create_file(dev, &dev_attr_name); + if (err) + goto exit_remove; + data->class_dev = hwmon_device_register(dev); if (IS_ERR(data->class_dev)) { err = PTR_ERR(data->class_dev);@@ -1318,95 +1303,184 @@ exit_remove: w83627ehf_device_remove_files(dev); - i2c_detach_client(client); -exit_free: - kfree(data); -exit_release: - release_region(address + IOREGION_OFFSET, IOREGION_LENGTH); + release_region(data->addr + REGION_OFFSET, REGION_LENGTH); exit: return err; } +/* when Super-I/O functions move to a separate file, the Super-I/O + * bus will manage the lifetime of the device and this module will only keep + * track of the w83627ehf driver. But since we platform_device_alloc(), we + * must keep track of the device */ +static struct platform_device *pdev; + static int __init sensors_w83627ehf_init(void) { - if (w83627ehf_find(0x2e, &address)
Review line 1326
Quoted 10 lines
(quoted diff) +8
-2- && w83627ehf_find(0x4e, &address)) - return -ENODEV; + int err; + struct resource res; + struct w83627ehf_data *data; + + if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { + err = -ENOMEM; + goto exit; + }
I still do not agree with your allocation scheme. It is correct that for now the w83627ehf driver must take care of both the platform data and the driver data, however these are still two different things. The platform data should be allocated and filled before .probe() is called. The driver data should be allocated _by_ .probe(). Here you're putting everything in the platform data structure, this isn't acceptable. Please look at the w83627hf driver and follow the same allocation scheme. This is far better than adding comments saying that you're aware you're not doing the right thing.
Quoted 63 lines
(quoted diff) +56
-1+ + /* initialize data->kind, data->sioreg, and data->addr. + * + * when Super-I/O functions move to a separate file, the Super-I/O + * driver will probe 0x2e and 0x4e and auto-detect the presence of a + * w83627ehf hardware monitor, and call probe() */ + if (w83627ehf_superio_probe(0x2e, data) && + w83627ehf_superio_probe(0x4e, data)) { + err = -ENODEV; + goto exit_free; + } - return i2c_isa_add_driver(&w83627ehf_driver); + /* !=0 to suppress warning: + * suggest parentheses around assignment used as truth value */ + if ((err = platform_driver_register(&w83627ehf_driver))!=0) + goto exit_free; + + if (!(pdev = platform_device_alloc(DRVNAME, data->addr))) { + err = -ENOMEM; + printk(KERN_ERR DRVNAME ": Device allocation failed\n"); + goto exit_unregister; + } + + pdev->dev.platform_data = data; + + memset(&res, 0, sizeof(res)); + data->name = w83627ehf_device_names[data->kind]; + res.name = data->name; + res.start = data->addr + REGION_OFFSET; + res.end = data->addr + REGION_OFFSET + REGION_LENGTH - 1; + res.flags = IORESOURCE_IO; + err = platform_device_add_resources(pdev, &res, 1); + if (err) { + printk(KERN_ERR DRVNAME ": Device resource addition failed " + "(%d)\n", err); + goto exit_device_put; + } + + /* platform_device_add calls probe() */ + err = platform_device_add(pdev); + if (err) { + printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", + err); + goto exit_device_put; + } + + return 0; + +exit_device_put: + pdev->dev.platform_data = NULL; + platform_device_put(pdev); +exit_unregister: + platform_driver_unregister(&w83627ehf_driver); +exit_free: + kfree(data); +exit: + return err; }
drivers/hwmon/Kconfig line 588
Quoted 6 lines
drivers/hwmon/Kconfig +1
-2@@ -585,8 +585,7 @@ config SENSORS_W83627EHF tristate "Winbond W83627EHF/DHG" - depends on I2C && EXPERIMENTAL - select I2C_ISA + depends on HWMON && EXPERIMENTAL
You're adding back HWMON which is no longer needed and has been removed upstream:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h72acf91abb327e25137ad2e371c1a788b34e45
drivers/hwmon/Kconfig line 591
Quoted 3 lines
drivers/hwmon/Kconfig +0
-0help If you say yes here you get support for the hardware monitoring functionality of the Winbond W83627EHF/DHG Super-I/O chip.
Rest looks OK.
Patch 03: OK.
Thanks,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors