hwmon: (pc87427) Add support for the second logical device
The second logical device contains the voltage and temperature registers. We have to extend the driver to support a second logical device before we can add support for these features. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
This commit is contained in:
parent
328716bc16
commit
9d32df192d
|
@ -65,6 +65,7 @@ struct pc87427_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pc87427_sio_data {
|
struct pc87427_sio_data {
|
||||||
|
unsigned short address[2];
|
||||||
u8 has_fanin;
|
u8 has_fanin;
|
||||||
u8 has_fanout;
|
u8 has_fanout;
|
||||||
};
|
};
|
||||||
|
@ -608,6 +609,46 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
|
||||||
* Device detection, attach and detach
|
* Device detection, attach and detach
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static void pc87427_release_regions(struct platform_device *pdev, int count)
|
||||||
|
{
|
||||||
|
struct resource *res;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
res = platform_get_resource(pdev, IORESOURCE_IO, i);
|
||||||
|
release_region(res->start, resource_size(res));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __devinit pc87427_request_regions(struct platform_device *pdev,
|
||||||
|
int count)
|
||||||
|
{
|
||||||
|
struct resource *res;
|
||||||
|
int i, err = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
res = platform_get_resource(pdev, IORESOURCE_IO, i);
|
||||||
|
if (!res) {
|
||||||
|
err = -ENOENT;
|
||||||
|
dev_err(&pdev->dev, "Missing resource #%d\n", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!request_region(res->start, resource_size(res), DRVNAME)) {
|
||||||
|
err = -EBUSY;
|
||||||
|
dev_err(&pdev->dev,
|
||||||
|
"Failed to request region 0x%lx-0x%lx\n",
|
||||||
|
(unsigned long)res->start,
|
||||||
|
(unsigned long)res->end);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err && i)
|
||||||
|
pc87427_release_regions(pdev, i);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
static void __devinit pc87427_init_device(struct device *dev)
|
static void __devinit pc87427_init_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct pc87427_sio_data *sio_data = dev->platform_data;
|
struct pc87427_sio_data *sio_data = dev->platform_data;
|
||||||
|
@ -664,9 +705,9 @@ static void __devinit pc87427_init_device(struct device *dev)
|
||||||
|
|
||||||
static int __devinit pc87427_probe(struct platform_device *pdev)
|
static int __devinit pc87427_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct pc87427_sio_data *sio_data = pdev->dev.platform_data;
|
||||||
struct pc87427_data *data;
|
struct pc87427_data *data;
|
||||||
struct resource *res;
|
int i, err, res_count;
|
||||||
int i, err;
|
|
||||||
|
|
||||||
data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
|
data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@ -675,16 +716,13 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This will need to be revisited when we add support for
|
data->address[0] = sio_data->address[0];
|
||||||
temperature and voltage monitoring. */
|
data->address[1] = sio_data->address[1];
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
res_count = (data->address[0] != 0) + (data->address[1] != 0);
|
||||||
if (!request_region(res->start, resource_size(res), DRVNAME)) {
|
|
||||||
err = -EBUSY;
|
err = pc87427_request_regions(pdev, res_count);
|
||||||
dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n",
|
if (err)
|
||||||
(unsigned long)res->start, (unsigned long)res->end);
|
|
||||||
goto exit_kfree;
|
goto exit_kfree;
|
||||||
}
|
|
||||||
data->address[0] = res->start;
|
|
||||||
|
|
||||||
mutex_init(&data->lock);
|
mutex_init(&data->lock);
|
||||||
data->name = "pc87427";
|
data->name = "pc87427";
|
||||||
|
@ -733,7 +771,7 @@ exit_remove_files:
|
||||||
sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);
|
sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_pwm[i]);
|
||||||
}
|
}
|
||||||
exit_release_region:
|
exit_release_region:
|
||||||
release_region(res->start, resource_size(res));
|
pc87427_release_regions(pdev, res_count);
|
||||||
exit_kfree:
|
exit_kfree:
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
kfree(data);
|
kfree(data);
|
||||||
|
@ -744,8 +782,9 @@ exit:
|
||||||
static int __devexit pc87427_remove(struct platform_device *pdev)
|
static int __devexit pc87427_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct pc87427_data *data = platform_get_drvdata(pdev);
|
struct pc87427_data *data = platform_get_drvdata(pdev);
|
||||||
struct resource *res;
|
int i, res_count;
|
||||||
int i;
|
|
||||||
|
res_count = (data->address[0] != 0) + (data->address[1] != 0);
|
||||||
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
hwmon_device_unregister(data->hwmon_dev);
|
||||||
device_remove_file(&pdev->dev, &dev_attr_name);
|
device_remove_file(&pdev->dev, &dev_attr_name);
|
||||||
|
@ -762,8 +801,7 @@ static int __devexit pc87427_remove(struct platform_device *pdev)
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
kfree(data);
|
kfree(data);
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
pc87427_release_regions(pdev, res_count);
|
||||||
release_region(res->start, resource_size(res));
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -778,29 +816,37 @@ static struct platform_driver pc87427_driver = {
|
||||||
.remove = __devexit_p(pc87427_remove),
|
.remove = __devexit_p(pc87427_remove),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init pc87427_device_add(unsigned short address,
|
static int __init pc87427_device_add(const struct pc87427_sio_data *sio_data)
|
||||||
const struct pc87427_sio_data *sio_data)
|
|
||||||
{
|
{
|
||||||
struct resource res = {
|
struct resource res[2] = {
|
||||||
.start = address,
|
{ .flags = IORESOURCE_IO },
|
||||||
.end = address + REGION_LENGTH - 1,
|
{ .flags = IORESOURCE_IO },
|
||||||
.name = logdev_str[0],
|
|
||||||
.flags = IORESOURCE_IO,
|
|
||||||
};
|
};
|
||||||
int err;
|
int err, i, res_count;
|
||||||
|
|
||||||
err = acpi_check_resource_conflict(&res);
|
res_count = 0;
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
if (!sio_data->address[i])
|
||||||
|
continue;
|
||||||
|
res[res_count].start = sio_data->address[i];
|
||||||
|
res[res_count].end = sio_data->address[i] + REGION_LENGTH - 1;
|
||||||
|
res[res_count].name = logdev_str[i];
|
||||||
|
|
||||||
|
err = acpi_check_resource_conflict(&res[res_count]);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
pdev = platform_device_alloc(DRVNAME, address);
|
res_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdev = platform_device_alloc(DRVNAME, res[0].start);
|
||||||
if (!pdev) {
|
if (!pdev) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
printk(KERN_ERR DRVNAME ": Device allocation failed\n");
|
printk(KERN_ERR DRVNAME ": Device allocation failed\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = platform_device_add_resources(pdev, &res, 1);
|
err = platform_device_add_resources(pdev, res, res_count);
|
||||||
if (err) {
|
if (err) {
|
||||||
printk(KERN_ERR DRVNAME ": Device resource addition failed "
|
printk(KERN_ERR DRVNAME ": Device resource addition failed "
|
||||||
"(%d)\n", err);
|
"(%d)\n", err);
|
||||||
|
@ -829,8 +875,7 @@ exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init pc87427_find(int sioaddr, unsigned short *address,
|
static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
|
||||||
struct pc87427_sio_data *sio_data)
|
|
||||||
{
|
{
|
||||||
u16 val;
|
u16 val;
|
||||||
u8 cfg, cfg_b;
|
u8 cfg, cfg_b;
|
||||||
|
@ -844,7 +889,7 @@ static int __init pc87427_find(int sioaddr, unsigned short *address,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
address[i] = 0;
|
sio_data->address[i] = 0;
|
||||||
/* Select logical device */
|
/* Select logical device */
|
||||||
superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]);
|
superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]);
|
||||||
|
|
||||||
|
@ -869,7 +914,13 @@ static int __init pc87427_find(int sioaddr, unsigned short *address,
|
||||||
"for logical device 0x%02x\n", logdev[i]);
|
"for logical device 0x%02x\n", logdev[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
address[i] = val;
|
sio_data->address[i] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No point in loading the driver if everything is disabled */
|
||||||
|
if (!sio_data->address[0] && !sio_data->address[1]) {
|
||||||
|
err = -ENODEV;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check which fan inputs are wired */
|
/* Check which fan inputs are wired */
|
||||||
|
@ -923,16 +974,10 @@ exit:
|
||||||
static int __init pc87427_init(void)
|
static int __init pc87427_init(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
unsigned short address[2];
|
|
||||||
struct pc87427_sio_data sio_data;
|
struct pc87427_sio_data sio_data;
|
||||||
|
|
||||||
if (pc87427_find(0x2e, address, &sio_data)
|
if (pc87427_find(0x2e, &sio_data)
|
||||||
&& pc87427_find(0x4e, address, &sio_data))
|
&& pc87427_find(0x4e, &sio_data))
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
/* For now the driver only handles fans so we only care about the
|
|
||||||
first address. */
|
|
||||||
if (!address[0])
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
err = platform_driver_register(&pc87427_driver);
|
err = platform_driver_register(&pc87427_driver);
|
||||||
|
@ -940,7 +985,7 @@ static int __init pc87427_init(void)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
/* Sets global pdev as a side effect */
|
/* Sets global pdev as a side effect */
|
||||||
err = pc87427_device_add(address[0], &sio_data);
|
err = pc87427_device_add(&sio_data);
|
||||||
if (err)
|
if (err)
|
||||||
goto exit_driver;
|
goto exit_driver;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue