Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 943b0830 authored by Mark M. Hoffman's avatar Mark M. Hoffman Committed by Greg Kroah-Hartman
Browse files

[PATCH] I2C hwmon: add hwmon sysfs class to drivers



This patch modifies sensors chip drivers to make use of the new
sysfs class "hwmon".

Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1236441f
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/hwmon.h>
#include <linux/err.h>


/* Addresses to scan */
@@ -89,6 +91,7 @@ clearing it. Weird, ey? --Phil */
/* Each client has this additional data */
struct adm1021_data {
	struct i2c_client client;
	struct class_device *class_dev;
	enum chips type;

	struct semaphore update_lock;
@@ -295,6 +298,12 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
		adm1021_init_client(new_client);

	/* Register sysfs hooks */
	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto error2;
	}

	device_create_file(&new_client->dev, &dev_attr_temp1_max);
	device_create_file(&new_client->dev, &dev_attr_temp1_min);
	device_create_file(&new_client->dev, &dev_attr_temp1_input);
@@ -305,6 +314,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)

	return 0;

error2:
	i2c_detach_client(new_client);
error1:
	kfree(data);
error0:
@@ -322,14 +333,17 @@ static void adm1021_init_client(struct i2c_client *client)

static int adm1021_detach_client(struct i2c_client *client)
{
	struct adm1021_data *data = i2c_get_clientdata(client);
	int err;

	hwmon_device_unregister(data->class_dev);

	if ((err = i2c_detach_client(client))) {
		dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
		return err;
	}

	kfree(i2c_get_clientdata(client));
	kfree(data);
	return 0;
}

+15 −1
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
#include <linux/hwmon.h>
#include <linux/err.h>

/*
 * Addresses to scan
@@ -132,6 +134,7 @@ static struct i2c_driver adm1025_driver = {

struct adm1025_data {
	struct i2c_client client;
	struct class_device *class_dev;
	struct semaphore update_lock;
	char valid; /* zero until following fields are valid */
	unsigned long last_updated; /* in jiffies */
@@ -416,6 +419,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
	adm1025_init_client(new_client);

	/* Register sysfs hooks */
	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto exit_detach;
	}

	device_create_file(&new_client->dev, &dev_attr_in0_input);
	device_create_file(&new_client->dev, &dev_attr_in1_input);
	device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -452,6 +461,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)

	return 0;

exit_detach:
	i2c_detach_client(new_client);
exit_free:
	kfree(data);
exit:
@@ -502,15 +513,18 @@ static void adm1025_init_client(struct i2c_client *client)

static int adm1025_detach_client(struct i2c_client *client)
{
	struct adm1025_data *data = i2c_get_clientdata(client);
	int err;

	hwmon_device_unregister(data->class_dev);

	if ((err = i2c_detach_client(client))) {
		dev_err(&client->dev, "Client deregistration failed, "
			"client not detached.\n");
		return err;
	}

	kfree(i2c_get_clientdata(client));
	kfree(data);
	return 0;
}

+14 −1
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
#include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h>
#include <linux/err.h>

/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -259,6 +261,7 @@ struct pwm_data {

struct adm1026_data {
	struct i2c_client client;
	struct class_device *class_dev;
	struct semaphore lock;
	enum chips type;

@@ -324,8 +327,10 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter)

int adm1026_detach_client(struct i2c_client *client)
{
	struct adm1026_data *data = i2c_get_clientdata(client);
	hwmon_device_unregister(data->class_dev);
	i2c_detach_client(client);
	kfree(i2c_get_clientdata(client));
	kfree(data);
	return 0;
}

@@ -1555,6 +1560,12 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
	adm1026_init_client(new_client);

	/* Register sysfs hooks */
	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto exitdetach;
	}

	device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
	device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
	device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
@@ -1690,6 +1701,8 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
	return 0;

	/* Error out and cleanup code */
exitdetach:
	i2c_detach_client(new_client);
exitfree:
	kfree(data);
exit:
+15 −1
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/hwmon.h>
#include <linux/err.h>

/* Following macros takes channel parameter starting from 0 to 2 */
#define ADM1031_REG_FAN_SPEED(nr)	(0x08 + (nr))
@@ -69,6 +71,7 @@ typedef u8 auto_chan_table_t[8][2];
/* Each client has this additional data */
struct adm1031_data {
	struct i2c_client client;
	struct class_device *class_dev;
	struct semaphore update_lock;
	int chip_type;
	char valid;		/* !=0 if following fields are valid */
@@ -788,6 +791,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
	adm1031_init_client(new_client);

	/* Register sysfs hooks */
	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto exit_detach;
	}

	device_create_file(&new_client->dev, &dev_attr_fan1_input);
	device_create_file(&new_client->dev, &dev_attr_fan1_div);
	device_create_file(&new_client->dev, &dev_attr_fan1_min);
@@ -833,6 +842,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)

	return 0;

exit_detach:
	i2c_detach_client(new_client);
exit_free:
	kfree(data);
exit:
@@ -841,11 +852,14 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)

static int adm1031_detach_client(struct i2c_client *client)
{
	struct adm1031_data *data = i2c_get_clientdata(client);
	int ret;

	hwmon_device_unregister(data->class_dev);
	if ((ret = i2c_detach_client(client)) != 0) {
		return ret;
	}
	kfree(i2c_get_clientdata(client));
	kfree(data);
	return 0;
}

+16 −1
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <linux/i2c-vid.h>
#include <linux/hwmon.h>
#include <linux/err.h>

/* Addresses to scan */
static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
@@ -150,6 +152,7 @@ static struct i2c_driver adm9240_driver = {
struct adm9240_data {
	enum chips type;
	struct i2c_client client;
	struct class_device *class_dev;
	struct semaphore update_lock;
	char valid;
	unsigned long last_updated_measure;
@@ -582,6 +585,12 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
	adm9240_init_client(new_client);

	/* populate sysfs filesystem */
	data->class_dev = hwmon_device_register(&new_client->dev);
	if (IS_ERR(data->class_dev)) {
		err = PTR_ERR(data->class_dev);
		goto exit_detach;
	}

	device_create_file(&new_client->dev, &dev_attr_in0_input);
	device_create_file(&new_client->dev, &dev_attr_in0_min);
	device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -615,6 +624,9 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
	device_create_file(&new_client->dev, &dev_attr_cpu0_vid);

	return 0;

exit_detach:
	i2c_detach_client(new_client);
exit_free:
	kfree(data);
exit:
@@ -630,15 +642,18 @@ static int adm9240_attach_adapter(struct i2c_adapter *adapter)

static int adm9240_detach_client(struct i2c_client *client)
{
	struct adm9240_data *data = i2c_get_clientdata(client);
	int err;

	hwmon_device_unregister(data->class_dev);

	if ((err = i2c_detach_client(client))) {
		dev_err(&client->dev, "Client deregistration failed, "
				"client not detached.\n");
		return err;
	}

	kfree(i2c_get_clientdata(client));
	kfree(data);
	return 0;
}

Loading