Skip to content

Commit

Permalink
drivers: w1: add hwmon support structures
Browse files Browse the repository at this point in the history
This patch has changes to w1.h/w1.c generic files to add (optional) hwmon
support structures.

Signed-off-by: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jaghathiswari Rankappagounder Natarajan authored and Greg Kroah-Hartman committed Aug 31, 2017
1 parent db15d73 commit 2eb7954
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/w1/w1.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/hwmon.h>

#include <linux/atomic.h>

Expand Down Expand Up @@ -649,9 +650,24 @@ static int w1_family_notify(unsigned long action, struct w1_slave *sl)
return err;
}
}

if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info) {
struct device *hwmon
= hwmon_device_register_with_info(&sl->dev,
"w1_slave_temp", sl,
fops->chip_info,
NULL);
if (IS_ERR(hwmon)) {
dev_warn(&sl->dev,
"could not create hwmon device\n");
} else {
sl->hwmon = hwmon;
}
}
break;
case BUS_NOTIFY_DEL_DEVICE:
if (IS_REACHABLE(CONFIG_HWMON) && fops->chip_info &&
sl->hwmon)
hwmon_device_unregister(sl->hwmon);
if (fops->remove_slave)
sl->family->fops->remove_slave(sl);
if (fops->groups)
Expand Down
4 changes: 4 additions & 0 deletions include/linux/w1.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct w1_reg_num {
* @family: module for device family type
* @family_data: pointer for use by the family module
* @dev: kernel device identifier
* @hwmon: pointer to hwmon device
*
*/
struct w1_slave {
Expand All @@ -83,6 +84,7 @@ struct w1_slave {
struct w1_family *family;
void *family_data;
struct device dev;
struct device *hwmon;
};

typedef void (*w1_slave_found_callback)(struct w1_master *, u64);
Expand Down Expand Up @@ -250,11 +252,13 @@ void w1_remove_master_device(struct w1_bus_master *master);
* @add_slave: add_slave
* @remove_slave: remove_slave
* @groups: sysfs group
* @chip_info: pointer to struct hwmon_chip_info
*/
struct w1_family_ops {
int (*add_slave)(struct w1_slave *sl);
void (*remove_slave)(struct w1_slave *sl);
const struct attribute_group **groups;
const struct hwmon_chip_info *chip_info;
};

/**
Expand Down

0 comments on commit 2eb7954

Please sign in to comment.