aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-13 14:28:29 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:26 -0400
commit85b3ee07b986e90d5e9821dcb28bde340dfc7805 (patch)
tree5572dcfed9358318c8ca909becb5a957093cbbde /drivers/hwmon
parent1adf3a3e1cf2ceb30c32642ff35cb05467dc7a75 (diff)
hwmon: (lm80) Convert fan display function macros into functions
Convert fan display function macros into functions to reduce code size and improve code readability. Code size reduction is about 200 bytes on x86_64. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm80.c75
1 files changed, 41 insertions, 34 deletions
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 8a3fa9aa07f8..420ad7c5ec28 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -116,6 +116,12 @@ enum in_index {
116 i_num_in 116 i_num_in
117}; 117};
118 118
119enum fan_index {
120 f_input,
121 f_min,
122 f_num_fan
123};
124
119/* 125/*
120 * Client data (each client gets its own) 126 * Client data (each client gets its own)
121 */ 127 */
@@ -128,8 +134,7 @@ struct lm80_data {
128 unsigned long last_updated; /* In jiffies */ 134 unsigned long last_updated; /* In jiffies */
129 135
130 u8 in[i_num_in][7]; /* Register value, 1st index is enum in_index */ 136 u8 in[i_num_in][7]; /* Register value, 1st index is enum in_index */
131 u8 fan[2]; /* Register value */ 137 u8 fan[f_num_fan][2]; /* Register value, 1st index enum fan_index */
132 u8 fan_min[2]; /* Register value */
133 u8 fan_div[2]; /* Register encoding, shifted right */ 138 u8 fan_div[2]; /* Register encoding, shifted right */
134 s16 temp[t_num_temp]; /* Register values, normalized to 16 bit */ 139 s16 temp[t_num_temp]; /* Register values, normalized to 16 bit */
135 u16 alarms; /* Register encoding, combined */ 140 u16 alarms; /* Register encoding, combined */
@@ -207,19 +212,17 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
207 return count; 212 return count;
208} 213}
209 214
210#define show_fan(suffix, value) \ 215static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
211static ssize_t show_fan_##suffix(struct device *dev, \ 216 char *buf)
212 struct device_attribute *attr, char *buf) \ 217{
213{ \ 218 int index = to_sensor_dev_attr_2(attr)->index;
214 int nr = to_sensor_dev_attr(attr)->index; \ 219 int nr = to_sensor_dev_attr_2(attr)->nr;
215 struct lm80_data *data = lm80_update_device(dev); \ 220 struct lm80_data *data = lm80_update_device(dev);
216 if (IS_ERR(data)) \ 221 if (IS_ERR(data))
217 return PTR_ERR(data); \ 222 return PTR_ERR(data);
218 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \ 223 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr][index],
219 DIV_FROM_REG(data->fan_div[nr]))); \ 224 DIV_FROM_REG(data->fan_div[index])));
220} 225}
221show_fan(min, fan_min)
222show_fan(input, fan)
223 226
224static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 227static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
225 char *buf) 228 char *buf)
@@ -234,7 +237,8 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
234static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 237static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
235 const char *buf, size_t count) 238 const char *buf, size_t count)
236{ 239{
237 int nr = to_sensor_dev_attr(attr)->index; 240 int index = to_sensor_dev_attr_2(attr)->index;
241 int nr = to_sensor_dev_attr_2(attr)->nr;
238 struct lm80_data *data = dev_get_drvdata(dev); 242 struct lm80_data *data = dev_get_drvdata(dev);
239 struct i2c_client *client = data->client; 243 struct i2c_client *client = data->client;
240 unsigned long val; 244 unsigned long val;
@@ -243,8 +247,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
243 return err; 247 return err;
244 248
245 mutex_lock(&data->update_lock); 249 mutex_lock(&data->update_lock);
246 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 250 data->fan[nr][index] = FAN_TO_REG(val,
247 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); 251 DIV_FROM_REG(data->fan_div[index]));
252 lm80_write_value(client, LM80_REG_FAN_MIN(index + 1),
253 data->fan[nr][index]);
248 mutex_unlock(&data->update_lock); 254 mutex_unlock(&data->update_lock);
249 return count; 255 return count;
250} 256}
@@ -269,7 +275,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
269 275
270 /* Save fan_min */ 276 /* Save fan_min */
271 mutex_lock(&data->update_lock); 277 mutex_lock(&data->update_lock);
272 min = FAN_FROM_REG(data->fan_min[nr], 278 min = FAN_FROM_REG(data->fan[f_min][nr],
273 DIV_FROM_REG(data->fan_div[nr])); 279 DIV_FROM_REG(data->fan_div[nr]));
274 280
275 switch (val) { 281 switch (val) {
@@ -293,13 +299,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
293 return -EINVAL; 299 return -EINVAL;
294 } 300 }
295 301
296 reg = (lm80_read_value(client, LM80_REG_FANDIV) & ~(3 << (2 * (nr + 1)))) 302 reg = (lm80_read_value(client, LM80_REG_FANDIV) &
297 | (data->fan_div[nr] << (2 * (nr + 1))); 303 ~(3 << (2 * (nr + 1)))) | (data->fan_div[nr] << (2 * (nr + 1)));
298 lm80_write_value(client, LM80_REG_FANDIV, reg); 304 lm80_write_value(client, LM80_REG_FANDIV, reg);
299 305
300 /* Restore fan_min */ 306 /* Restore fan_min */
301 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 307 data->fan[f_min][nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
302 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); 308 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1),
309 data->fan[f_min][nr]);
303 mutex_unlock(&data->update_lock); 310 mutex_unlock(&data->update_lock);
304 311
305 return count; 312 return count;
@@ -388,12 +395,12 @@ static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, i_input, 3);
388static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, i_input, 4); 395static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, i_input, 4);
389static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, i_input, 5); 396static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, i_input, 5);
390static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, i_input, 6); 397static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, i_input, 6);
391static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, 398static SENSOR_DEVICE_ATTR_2(fan1_min, S_IWUSR | S_IRUGO,
392 show_fan_min, set_fan_min, 0); 399 show_fan, set_fan_min, f_min, 0);
393static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, 400static SENSOR_DEVICE_ATTR_2(fan2_min, S_IWUSR | S_IRUGO,
394 show_fan_min, set_fan_min, 1); 401 show_fan, set_fan_min, f_min, 1);
395static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); 402static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, f_input, 0);
396static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); 403static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, f_input, 1);
397static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, 404static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
398 show_fan_div, set_fan_div, 0); 405 show_fan_div, set_fan_div, 0);
399static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, 406static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
@@ -537,8 +544,8 @@ static int lm80_probe(struct i2c_client *client,
537 lm80_init_client(client); 544 lm80_init_client(client);
538 545
539 /* A few vars need to be filled upon startup */ 546 /* A few vars need to be filled upon startup */
540 data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1)); 547 data->fan[f_min][0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
541 data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2)); 548 data->fan[f_min][1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
542 549
543 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 550 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
544 data, lm80_groups); 551 data, lm80_groups);
@@ -608,22 +615,22 @@ static struct lm80_data *lm80_update_device(struct device *dev)
608 rv = lm80_read_value(client, LM80_REG_FAN1); 615 rv = lm80_read_value(client, LM80_REG_FAN1);
609 if (rv < 0) 616 if (rv < 0)
610 goto abort; 617 goto abort;
611 data->fan[0] = rv; 618 data->fan[f_input][0] = rv;
612 619
613 rv = lm80_read_value(client, LM80_REG_FAN_MIN(1)); 620 rv = lm80_read_value(client, LM80_REG_FAN_MIN(1));
614 if (rv < 0) 621 if (rv < 0)
615 goto abort; 622 goto abort;
616 data->fan_min[0] = rv; 623 data->fan[f_min][0] = rv;
617 624
618 rv = lm80_read_value(client, LM80_REG_FAN2); 625 rv = lm80_read_value(client, LM80_REG_FAN2);
619 if (rv < 0) 626 if (rv < 0)
620 goto abort; 627 goto abort;
621 data->fan[1] = rv; 628 data->fan[f_input][1] = rv;
622 629
623 rv = lm80_read_value(client, LM80_REG_FAN_MIN(2)); 630 rv = lm80_read_value(client, LM80_REG_FAN_MIN(2));
624 if (rv < 0) 631 if (rv < 0)
625 goto abort; 632 goto abort;
626 data->fan_min[1] = rv; 633 data->fan[f_min][1] = rv;
627 634
628 prev_rv = rv = lm80_read_value(client, LM80_REG_TEMP); 635 prev_rv = rv = lm80_read_value(client, LM80_REG_TEMP);
629 if (rv < 0) 636 if (rv < 0)