diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-12 13:28:50 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:25 -0400 |
commit | f83111964ed74c3b2cd0a7d6363afb17efd87623 (patch) | |
tree | fcc0a1bb201ec9629fd2f9435d79f56ac7bd3e71 | |
parent | 40089a9fe265cae0669e84c5ee6fafa59949c215 (diff) |
hwmon: (max1619) Drop function macros
Function macros make the code larger and difficult ro read.
Drop them and reduce code size (on x86_64) by ~1800 bytes.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/max1619.c | 141 |
1 files changed, 73 insertions, 68 deletions
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index c8a729734df5..4125128898af 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -71,6 +71,16 @@ static int temp_to_reg(int val) | |||
71 | return (val < 0 ? val+0x100*1000 : val) / 1000; | 71 | return (val < 0 ? val+0x100*1000 : val) / 1000; |
72 | } | 72 | } |
73 | 73 | ||
74 | enum temp_index { | ||
75 | t_input1 = 0, | ||
76 | t_input2, | ||
77 | t_low2, | ||
78 | t_high2, | ||
79 | t_crit2, | ||
80 | t_hyst2, | ||
81 | t_num_regs | ||
82 | }; | ||
83 | |||
74 | /* | 84 | /* |
75 | * Client data (each client gets its own) | 85 | * Client data (each client gets its own) |
76 | */ | 86 | */ |
@@ -82,35 +92,39 @@ struct max1619_data { | |||
82 | unsigned long last_updated; /* in jiffies */ | 92 | unsigned long last_updated; /* in jiffies */ |
83 | 93 | ||
84 | /* registers values */ | 94 | /* registers values */ |
85 | u8 temp_input1; /* local */ | 95 | u8 temp[t_num_regs]; /* index with enum temp_index */ |
86 | u8 temp_input2, temp_low2, temp_high2; /* remote */ | ||
87 | u8 temp_crit2; | ||
88 | u8 temp_hyst2; | ||
89 | u8 alarms; | 96 | u8 alarms; |
90 | }; | 97 | }; |
91 | 98 | ||
99 | static const u8 regs_read[t_num_regs] = { | ||
100 | [t_input1] = MAX1619_REG_R_LOCAL_TEMP, | ||
101 | [t_input2] = MAX1619_REG_R_REMOTE_TEMP, | ||
102 | [t_low2] = MAX1619_REG_R_REMOTE_LOW, | ||
103 | [t_high2] = MAX1619_REG_R_REMOTE_HIGH, | ||
104 | [t_crit2] = MAX1619_REG_R_REMOTE_CRIT, | ||
105 | [t_hyst2] = MAX1619_REG_R_TCRIT_HYST, | ||
106 | }; | ||
107 | |||
108 | static const u8 regs_write[t_num_regs] = { | ||
109 | [t_low2] = MAX1619_REG_W_REMOTE_LOW, | ||
110 | [t_high2] = MAX1619_REG_W_REMOTE_HIGH, | ||
111 | [t_crit2] = MAX1619_REG_W_REMOTE_CRIT, | ||
112 | [t_hyst2] = MAX1619_REG_W_TCRIT_HYST, | ||
113 | }; | ||
114 | |||
92 | static struct max1619_data *max1619_update_device(struct device *dev) | 115 | static struct max1619_data *max1619_update_device(struct device *dev) |
93 | { | 116 | { |
94 | struct i2c_client *client = to_i2c_client(dev); | 117 | struct i2c_client *client = to_i2c_client(dev); |
95 | struct max1619_data *data = i2c_get_clientdata(client); | 118 | struct max1619_data *data = i2c_get_clientdata(client); |
96 | int config; | 119 | int config, i; |
97 | 120 | ||
98 | mutex_lock(&data->update_lock); | 121 | mutex_lock(&data->update_lock); |
99 | 122 | ||
100 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | 123 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
101 | dev_dbg(&client->dev, "Updating max1619 data.\n"); | 124 | dev_dbg(&client->dev, "Updating max1619 data.\n"); |
102 | data->temp_input1 = i2c_smbus_read_byte_data(client, | 125 | for (i = 0; i < t_num_regs; i++) |
103 | MAX1619_REG_R_LOCAL_TEMP); | 126 | data->temp[i] = i2c_smbus_read_byte_data(client, |
104 | data->temp_input2 = i2c_smbus_read_byte_data(client, | 127 | regs_read[i]); |
105 | MAX1619_REG_R_REMOTE_TEMP); | ||
106 | data->temp_high2 = i2c_smbus_read_byte_data(client, | ||
107 | MAX1619_REG_R_REMOTE_HIGH); | ||
108 | data->temp_low2 = i2c_smbus_read_byte_data(client, | ||
109 | MAX1619_REG_R_REMOTE_LOW); | ||
110 | data->temp_crit2 = i2c_smbus_read_byte_data(client, | ||
111 | MAX1619_REG_R_REMOTE_CRIT); | ||
112 | data->temp_hyst2 = i2c_smbus_read_byte_data(client, | ||
113 | MAX1619_REG_R_TCRIT_HYST); | ||
114 | data->alarms = i2c_smbus_read_byte_data(client, | 128 | data->alarms = i2c_smbus_read_byte_data(client, |
115 | MAX1619_REG_R_STATUS); | 129 | MAX1619_REG_R_STATUS); |
116 | /* If OVERT polarity is low, reverse alarm bit */ | 130 | /* If OVERT polarity is low, reverse alarm bit */ |
@@ -131,43 +145,33 @@ static struct max1619_data *max1619_update_device(struct device *dev) | |||
131 | * Sysfs stuff | 145 | * Sysfs stuff |
132 | */ | 146 | */ |
133 | 147 | ||
134 | #define show_temp(value) \ | 148 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
135 | static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \ | 149 | char *buf) |
136 | char *buf) \ | 150 | { |
137 | { \ | 151 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
138 | struct max1619_data *data = max1619_update_device(dev); \ | 152 | struct max1619_data *data = max1619_update_device(dev); |
139 | return sprintf(buf, "%d\n", temp_from_reg(data->value)); \ | 153 | |
140 | } | 154 | return sprintf(buf, "%d\n", temp_from_reg(data->temp[attr->index])); |
141 | show_temp(temp_input1); | ||
142 | show_temp(temp_input2); | ||
143 | show_temp(temp_low2); | ||
144 | show_temp(temp_high2); | ||
145 | show_temp(temp_crit2); | ||
146 | show_temp(temp_hyst2); | ||
147 | |||
148 | #define set_temp2(value, reg) \ | ||
149 | static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \ | ||
150 | const char *buf, \ | ||
151 | size_t count) \ | ||
152 | { \ | ||
153 | struct i2c_client *client = to_i2c_client(dev); \ | ||
154 | struct max1619_data *data = i2c_get_clientdata(client); \ | ||
155 | long val; \ | ||
156 | int err = kstrtol(buf, 10, &val); \ | ||
157 | if (err) \ | ||
158 | return err; \ | ||
159 | \ | ||
160 | mutex_lock(&data->update_lock); \ | ||
161 | data->value = temp_to_reg(val); \ | ||
162 | i2c_smbus_write_byte_data(client, reg, data->value); \ | ||
163 | mutex_unlock(&data->update_lock); \ | ||
164 | return count; \ | ||
165 | } | 155 | } |
166 | 156 | ||
167 | set_temp2(temp_low2, MAX1619_REG_W_REMOTE_LOW); | 157 | static ssize_t set_temp(struct device *dev, struct device_attribute *devattr, |
168 | set_temp2(temp_high2, MAX1619_REG_W_REMOTE_HIGH); | 158 | const char *buf, size_t count) |
169 | set_temp2(temp_crit2, MAX1619_REG_W_REMOTE_CRIT); | 159 | { |
170 | set_temp2(temp_hyst2, MAX1619_REG_W_TCRIT_HYST); | 160 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
161 | struct i2c_client *client = to_i2c_client(dev); | ||
162 | struct max1619_data *data = i2c_get_clientdata(client); | ||
163 | long val; | ||
164 | int err = kstrtol(buf, 10, &val); | ||
165 | if (err) | ||
166 | return err; | ||
167 | |||
168 | mutex_lock(&data->update_lock); | ||
169 | data->temp[attr->index] = temp_to_reg(val); | ||
170 | i2c_smbus_write_byte_data(client, regs_write[attr->index], | ||
171 | data->temp[attr->index]); | ||
172 | mutex_unlock(&data->update_lock); | ||
173 | return count; | ||
174 | } | ||
171 | 175 | ||
172 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | 176 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
173 | char *buf) | 177 | char *buf) |
@@ -184,16 +188,17 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | |||
184 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); | 188 | return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); |
185 | } | 189 | } |
186 | 190 | ||
187 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL); | 191 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input1); |
188 | static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input2, NULL); | 192 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, t_input2); |
189 | static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_low2, | 193 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp, set_temp, |
190 | set_temp_low2); | 194 | t_low2); |
191 | static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_high2, | 195 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp, set_temp, |
192 | set_temp_high2); | 196 | t_high2); |
193 | static DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit2, | 197 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp, set_temp, |
194 | set_temp_crit2); | 198 | t_crit2); |
195 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst2, | 199 | static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp, |
196 | set_temp_hyst2); | 200 | set_temp, t_hyst2); |
201 | |||
197 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 202 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
198 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | 203 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
199 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); | 204 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
@@ -201,12 +206,12 @@ static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | |||
201 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 206 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
202 | 207 | ||
203 | static struct attribute *max1619_attributes[] = { | 208 | static struct attribute *max1619_attributes[] = { |
204 | &dev_attr_temp1_input.attr, | 209 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
205 | &dev_attr_temp2_input.attr, | 210 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
206 | &dev_attr_temp2_min.attr, | 211 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
207 | &dev_attr_temp2_max.attr, | 212 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
208 | &dev_attr_temp2_crit.attr, | 213 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
209 | &dev_attr_temp2_crit_hyst.attr, | 214 | &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, |
210 | 215 | ||
211 | &dev_attr_alarms.attr, | 216 | &dev_attr_alarms.attr, |
212 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 217 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |