Commit d8543e7f authored by Jean Delvare's avatar Jean Delvare Committed by Mark M. Hoffman

hwmon: (adm1025) Use dynamic sysfs callbacks

This lets us get rid of macro-generated functions and shrinks the
driver size by about 30%.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent c7fa3737
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/hwmon-vid.h> #include <linux/hwmon-vid.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -153,86 +154,96 @@ struct adm1025_data { ...@@ -153,86 +154,96 @@ struct adm1025_data {
* Sysfs stuff * Sysfs stuff
*/ */
#define show_in(offset) \ static ssize_t
static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \ show_in(struct device *dev, struct device_attribute *attr, char *buf)
{ \ {
struct adm1025_data *data = adm1025_update_device(dev); \ int index = to_sensor_dev_attr(attr)->index;
return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ struct adm1025_data *data = adm1025_update_device(dev);
in_scale[offset])); \ return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
} \ in_scale[index]));
static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ }
{ \
struct adm1025_data *data = adm1025_update_device(dev); \ static ssize_t
return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
in_scale[offset])); \ {
} \ int index = to_sensor_dev_attr(attr)->index;
static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ struct adm1025_data *data = adm1025_update_device(dev);
{ \ return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
struct adm1025_data *data = adm1025_update_device(dev); \ in_scale[index]));
return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ }
in_scale[offset])); \
} \ static ssize_t
static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
show_in(0); {
show_in(1); int index = to_sensor_dev_attr(attr)->index;
show_in(2); struct adm1025_data *data = adm1025_update_device(dev);
show_in(3); return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
show_in(4); in_scale[index]));
show_in(5); }
#define show_temp(offset) \ static ssize_t
static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \ show_temp(struct device *dev, struct device_attribute *attr, char *buf)
{ \ {
struct adm1025_data *data = adm1025_update_device(dev); \ int index = to_sensor_dev_attr(attr)->index;
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ struct adm1025_data *data = adm1025_update_device(dev);
} \ return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ }
{ \
struct adm1025_data *data = adm1025_update_device(dev); \ static ssize_t
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
} \ {
static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ int index = to_sensor_dev_attr(attr)->index;
{ \ struct adm1025_data *data = adm1025_update_device(dev);
struct adm1025_data *data = adm1025_update_device(dev); \ return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ }
}\
static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL); static ssize_t
show_temp(1); show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
show_temp(2); {
int index = to_sensor_dev_attr(attr)->index;
struct adm1025_data *data = adm1025_update_device(dev);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
}
static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
mutex_lock(&data->update_lock);
data->in_min[index] = IN_TO_REG(val, in_scale[index]);
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
data->in_min[index]);
mutex_unlock(&data->update_lock);
return count;
}
static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
mutex_lock(&data->update_lock);
data->in_max[index] = IN_TO_REG(val, in_scale[index]);
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
data->in_max[index]);
mutex_unlock(&data->update_lock);
return count;
}
#define set_in(offset) \ #define set_in(offset) \
static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
size_t count) \ show_in, NULL, offset); \
{ \ static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
struct i2c_client *client = to_i2c_client(dev); \ show_in_min, set_in_min, offset); \
struct adm1025_data *data = i2c_get_clientdata(client); \ static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
long val = simple_strtol(buf, NULL, 10); \ show_in_max, set_in_max, offset)
\
mutex_lock(&data->update_lock); \
data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
data->in_min[offset]); \
mutex_unlock(&data->update_lock); \
return count; \
} \
static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
size_t count) \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \
\
mutex_lock(&data->update_lock); \
data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
data->in_max[offset]); \
mutex_unlock(&data->update_lock); \
return count; \
} \
static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
show_in##offset##_min, set_in##offset##_min); \
static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
show_in##offset##_max, set_in##offset##_max);
set_in(0); set_in(0);
set_in(1); set_in(1);
set_in(2); set_in(2);
...@@ -240,39 +251,45 @@ set_in(3); ...@@ -240,39 +251,45 @@ set_in(3);
set_in(4); set_in(4);
set_in(5); set_in(5);
static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
mutex_lock(&data->update_lock);
data->temp_min[index] = TEMP_TO_REG(val);
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
data->temp_min[index]);
mutex_unlock(&data->update_lock);
return count;
}
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int index = to_sensor_dev_attr(attr)->index;
struct i2c_client *client = to_i2c_client(dev);
struct adm1025_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
mutex_lock(&data->update_lock);
data->temp_max[index] = TEMP_TO_REG(val);
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
data->temp_max[index]);
mutex_unlock(&data->update_lock);
return count;
}
#define set_temp(offset) \ #define set_temp(offset) \
static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
size_t count) \ show_temp, NULL, offset - 1); \
{ \ static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
struct i2c_client *client = to_i2c_client(dev); \ show_temp_min, set_temp_min, offset - 1); \
struct adm1025_data *data = i2c_get_clientdata(client); \ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
long val = simple_strtol(buf, NULL, 10); \ show_temp_max, set_temp_max, offset - 1)
\
mutex_lock(&data->update_lock); \
data->temp_min[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
data->temp_min[offset-1]); \
mutex_unlock(&data->update_lock); \
return count; \
} \
static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
size_t count) \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
long val = simple_strtol(buf, NULL, 10); \
\
mutex_lock(&data->update_lock); \
data->temp_max[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
data->temp_max[offset-1]); \
mutex_unlock(&data->update_lock); \
return count; \
} \
static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
show_temp##offset##_min, set_temp##offset##_min); \
static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
show_temp##offset##_max, set_temp##offset##_max);
set_temp(1); set_temp(1);
set_temp(2); set_temp(2);
...@@ -316,27 +333,27 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter) ...@@ -316,27 +333,27 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
} }
static struct attribute *adm1025_attributes[] = { static struct attribute *adm1025_attributes[] = {
&dev_attr_in0_input.attr, &sensor_dev_attr_in0_input.dev_attr.attr,
&dev_attr_in1_input.attr, &sensor_dev_attr_in1_input.dev_attr.attr,
&dev_attr_in2_input.attr, &sensor_dev_attr_in2_input.dev_attr.attr,
&dev_attr_in3_input.attr, &sensor_dev_attr_in3_input.dev_attr.attr,
&dev_attr_in5_input.attr, &sensor_dev_attr_in5_input.dev_attr.attr,
&dev_attr_in0_min.attr, &sensor_dev_attr_in0_min.dev_attr.attr,
&dev_attr_in1_min.attr, &sensor_dev_attr_in1_min.dev_attr.attr,
&dev_attr_in2_min.attr, &sensor_dev_attr_in2_min.dev_attr.attr,
&dev_attr_in3_min.attr, &sensor_dev_attr_in3_min.dev_attr.attr,
&dev_attr_in5_min.attr, &sensor_dev_attr_in5_min.dev_attr.attr,
&dev_attr_in0_max.attr, &sensor_dev_attr_in0_max.dev_attr.attr,
&dev_attr_in1_max.attr, &sensor_dev_attr_in1_max.dev_attr.attr,
&dev_attr_in2_max.attr, &sensor_dev_attr_in2_max.dev_attr.attr,
&dev_attr_in3_max.attr, &sensor_dev_attr_in3_max.dev_attr.attr,
&dev_attr_in5_max.attr, &sensor_dev_attr_in5_max.dev_attr.attr,
&dev_attr_temp1_input.attr, &sensor_dev_attr_temp1_input.dev_attr.attr,
&dev_attr_temp2_input.attr, &sensor_dev_attr_temp2_input.dev_attr.attr,
&dev_attr_temp1_min.attr, &sensor_dev_attr_temp1_min.dev_attr.attr,
&dev_attr_temp2_min.attr, &sensor_dev_attr_temp2_min.dev_attr.attr,
&dev_attr_temp1_max.attr, &sensor_dev_attr_temp1_max.dev_attr.attr,
&dev_attr_temp2_max.attr, &sensor_dev_attr_temp2_max.dev_attr.attr,
&dev_attr_alarms.attr, &dev_attr_alarms.attr,
&dev_attr_cpu0_vid.attr, &dev_attr_cpu0_vid.attr,
&dev_attr_vrm.attr, &dev_attr_vrm.attr,
...@@ -348,9 +365,9 @@ static const struct attribute_group adm1025_group = { ...@@ -348,9 +365,9 @@ static const struct attribute_group adm1025_group = {
}; };
static struct attribute *adm1025_attributes_opt[] = { static struct attribute *adm1025_attributes_opt[] = {
&dev_attr_in4_input.attr, &sensor_dev_attr_in4_input.dev_attr.attr,
&dev_attr_in4_min.attr, &sensor_dev_attr_in4_min.dev_attr.attr,
&dev_attr_in4_max.attr, &sensor_dev_attr_in4_max.dev_attr.attr,
NULL NULL
}; };
...@@ -464,11 +481,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -464,11 +481,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
/* Pin 11 is either in4 (+12V) or VID4 */ /* Pin 11 is either in4 (+12V) or VID4 */
if (!(config & 0x20)) { if (!(config & 0x20)) {
if ((err = device_create_file(&new_client->dev, if ((err = device_create_file(&new_client->dev,
&dev_attr_in4_input)) &sensor_dev_attr_in4_input.dev_attr))
|| (err = device_create_file(&new_client->dev, || (err = device_create_file(&new_client->dev,
&dev_attr_in4_min)) &sensor_dev_attr_in4_min.dev_attr))
|| (err = device_create_file(&new_client->dev, || (err = device_create_file(&new_client->dev,
&dev_attr_in4_max))) &sensor_dev_attr_in4_max.dev_attr)))
goto exit_remove; goto exit_remove;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment