aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-12 16:07:08 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:21 -0400
commitb8fe58e9532d8cbaa8efcedf95a9c18f726e75ce (patch)
tree30a1d18fc9c1828ebad0e9cc520b4c2b65f6c48b
parentc6f1e7ab91b9cec14d4d3938cddafe371070e7ec (diff)
hwmon: (lm92) Drop function macros
Function macros obfuscate code and increase code size, so drop them. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/lm92.c167
1 files changed, 84 insertions, 83 deletions
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 7193a92dda9c..42188a0fe6d1 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -89,6 +89,23 @@ static inline u8 ALARMS_FROM_REG(s16 reg)
89 return reg & 0x0007; 89 return reg & 0x0007;
90} 90}
91 91
92enum temp_index {
93 t_input,
94 t_crit,
95 t_min,
96 t_max,
97 t_hyst,
98 t_num_regs
99};
100
101static const u8 regs[t_num_regs] = {
102 [t_input] = LM92_REG_TEMP,
103 [t_crit] = LM92_REG_TEMP_CRIT,
104 [t_min] = LM92_REG_TEMP_LOW,
105 [t_max] = LM92_REG_TEMP_HIGH,
106 [t_hyst] = LM92_REG_TEMP_HYST,
107};
108
92/* Client data (each client gets its own) */ 109/* Client data (each client gets its own) */
93struct lm92_data { 110struct lm92_data {
94 struct device *hwmon_dev; 111 struct device *hwmon_dev;
@@ -97,10 +114,9 @@ struct lm92_data {
97 unsigned long last_updated; /* in jiffies */ 114 unsigned long last_updated; /* in jiffies */
98 115
99 /* registers values */ 116 /* registers values */
100 s16 temp1_input, temp1_crit, temp1_min, temp1_max, temp1_hyst; 117 s16 temp[t_num_regs]; /* index with enum temp_index */
101}; 118};
102 119
103
104/* 120/*
105 * Sysfs attributes and callback functions 121 * Sysfs attributes and callback functions
106 */ 122 */
@@ -109,23 +125,17 @@ static struct lm92_data *lm92_update_device(struct device *dev)
109{ 125{
110 struct i2c_client *client = to_i2c_client(dev); 126 struct i2c_client *client = to_i2c_client(dev);
111 struct lm92_data *data = i2c_get_clientdata(client); 127 struct lm92_data *data = i2c_get_clientdata(client);
128 int i;
112 129
113 mutex_lock(&data->update_lock); 130 mutex_lock(&data->update_lock);
114 131
115 if (time_after(jiffies, data->last_updated + HZ) 132 if (time_after(jiffies, data->last_updated + HZ)
116 || !data->valid) { 133 || !data->valid) {
117 dev_dbg(&client->dev, "Updating lm92 data\n"); 134 dev_dbg(&client->dev, "Updating lm92 data\n");
118 data->temp1_input = i2c_smbus_read_word_swapped(client, 135 for (i = 0; i < t_num_regs; i++) {
119 LM92_REG_TEMP); 136 data->temp[i] =
120 data->temp1_hyst = i2c_smbus_read_word_swapped(client, 137 i2c_smbus_read_word_swapped(client, regs[i]);
121 LM92_REG_TEMP_HYST); 138 }
122 data->temp1_crit = i2c_smbus_read_word_swapped(client,
123 LM92_REG_TEMP_CRIT);
124 data->temp1_min = i2c_smbus_read_word_swapped(client,
125 LM92_REG_TEMP_LOW);
126 data->temp1_max = i2c_smbus_read_word_swapped(client,
127 LM92_REG_TEMP_HIGH);
128
129 data->last_updated = jiffies; 139 data->last_updated = jiffies;
130 data->valid = 1; 140 data->valid = 1;
131 } 141 }
@@ -135,66 +145,58 @@ static struct lm92_data *lm92_update_device(struct device *dev)
135 return data; 145 return data;
136} 146}
137 147
138#define show_temp(value) \ 148static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
139static ssize_t show_##value(struct device *dev, struct device_attribute *attr, \ 149 char *buf)
140 char *buf) \ 150{
141{ \ 151 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
142 struct lm92_data *data = lm92_update_device(dev); \ 152 struct lm92_data *data = lm92_update_device(dev);
143 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ 153
144} 154 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
145show_temp(temp1_input);
146show_temp(temp1_crit);
147show_temp(temp1_min);
148show_temp(temp1_max);
149
150#define set_temp(value, reg) \
151static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
152 const char *buf, \
153 size_t count) \
154{ \
155 struct i2c_client *client = to_i2c_client(dev); \
156 struct lm92_data *data = i2c_get_clientdata(client); \
157 long val; \
158 int err = kstrtol(buf, 10, &val); \
159 if (err) \
160 return err; \
161\
162 mutex_lock(&data->update_lock); \
163 data->value = TEMP_TO_REG(val); \
164 i2c_smbus_write_word_swapped(client, reg, data->value); \
165 mutex_unlock(&data->update_lock); \
166 return count; \
167} 155}
168set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
169set_temp(temp1_min, LM92_REG_TEMP_LOW);
170set_temp(temp1_max, LM92_REG_TEMP_HIGH);
171 156
172static ssize_t show_temp1_crit_hyst(struct device *dev, 157static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
173 struct device_attribute *attr, char *buf) 158 const char *buf, size_t count)
174{ 159{
175 struct lm92_data *data = lm92_update_device(dev); 160 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
176 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit) 161 struct i2c_client *client = to_i2c_client(dev);
177 - TEMP_FROM_REG(data->temp1_hyst)); 162 struct lm92_data *data = i2c_get_clientdata(client);
163 int nr = attr->index;
164 long val;
165 int err;
166
167 err = kstrtol(buf, 10, &val);
168 if (err)
169 return err;
170
171 mutex_lock(&data->update_lock);
172 data->temp[nr] = TEMP_TO_REG(val);
173 i2c_smbus_write_word_swapped(client, regs[nr], data->temp[nr]);
174 mutex_unlock(&data->update_lock);
175 return count;
178} 176}
179static ssize_t show_temp1_max_hyst(struct device *dev, 177
180 struct device_attribute *attr, char *buf) 178static ssize_t show_temp_hyst(struct device *dev,
179 struct device_attribute *devattr, char *buf)
181{ 180{
181 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
182 struct lm92_data *data = lm92_update_device(dev); 182 struct lm92_data *data = lm92_update_device(dev);
183 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max) 183 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])
184 - TEMP_FROM_REG(data->temp1_hyst)); 184 - TEMP_FROM_REG(data->temp[t_hyst]));
185} 185}
186static ssize_t show_temp1_min_hyst(struct device *dev, 186
187 struct device_attribute *attr, char *buf) 187static ssize_t show_temp_min_hyst(struct device *dev,
188 struct device_attribute *attr, char *buf)
188{ 189{
189 struct lm92_data *data = lm92_update_device(dev); 190 struct lm92_data *data = lm92_update_device(dev);
190 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min) 191 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[t_min])
191 + TEMP_FROM_REG(data->temp1_hyst)); 192 + TEMP_FROM_REG(data->temp[t_hyst]));
192} 193}
193 194
194static ssize_t set_temp1_crit_hyst(struct device *dev, 195static ssize_t set_temp_hyst(struct device *dev,
195 struct device_attribute *attr, 196 struct device_attribute *devattr,
196 const char *buf, size_t count) 197 const char *buf, size_t count)
197{ 198{
199 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
198 struct i2c_client *client = to_i2c_client(dev); 200 struct i2c_client *client = to_i2c_client(dev);
199 struct lm92_data *data = i2c_get_clientdata(client); 201 struct lm92_data *data = i2c_get_clientdata(client);
200 long val; 202 long val;
@@ -205,9 +207,9 @@ static ssize_t set_temp1_crit_hyst(struct device *dev,
205 return err; 207 return err;
206 208
207 mutex_lock(&data->update_lock); 209 mutex_lock(&data->update_lock);
208 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; 210 data->temp[t_hyst] = TEMP_FROM_REG(data->temp[attr->index]) - val;
209 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST, 211 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST,
210 TEMP_TO_REG(data->temp1_hyst)); 212 TEMP_TO_REG(data->temp[t_hyst]));
211 mutex_unlock(&data->update_lock); 213 mutex_unlock(&data->update_lock);
212 return count; 214 return count;
213} 215}
@@ -216,7 +218,7 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
216 char *buf) 218 char *buf)
217{ 219{
218 struct lm92_data *data = lm92_update_device(dev); 220 struct lm92_data *data = lm92_update_device(dev);
219 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input)); 221 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp[t_input]));
220} 222}
221 223
222static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, 224static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
@@ -224,26 +226,25 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
224{ 226{
225 int bitnr = to_sensor_dev_attr(attr)->index; 227 int bitnr = to_sensor_dev_attr(attr)->index;
226 struct lm92_data *data = lm92_update_device(dev); 228 struct lm92_data *data = lm92_update_device(dev);
227 return sprintf(buf, "%d\n", (data->temp1_input >> bitnr) & 1); 229 return sprintf(buf, "%d\n", (data->temp[t_input] >> bitnr) & 1);
228} 230}
229 231
230static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1_input, NULL); 232static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input);
231static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp1_crit, 233static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp, set_temp,
232 set_temp1_crit); 234 t_crit);
233static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp1_crit_hyst, 235static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst,
234 set_temp1_crit_hyst); 236 set_temp_hyst, t_crit);
235static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp1_min, 237static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp,
236 set_temp1_min); 238 t_min);
237static DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp1_min_hyst, NULL); 239static DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp_min_hyst, NULL);
238static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp1_max, 240static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp,
239 set_temp1_max); 241 t_max);
240static DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp1_max_hyst, NULL); 242static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max);
241static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 243static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
242static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2); 244static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
243static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 245static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
244static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); 246static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
245 247
246
247/* 248/*
248 * Detection and registration 249 * Detection and registration
249 */ 250 */
@@ -316,13 +317,13 @@ static int max6635_check(struct i2c_client *client)
316} 317}
317 318
318static struct attribute *lm92_attributes[] = { 319static struct attribute *lm92_attributes[] = {
319 &dev_attr_temp1_input.attr, 320 &sensor_dev_attr_temp1_input.dev_attr.attr,
320 &dev_attr_temp1_crit.attr, 321 &sensor_dev_attr_temp1_crit.dev_attr.attr,
321 &dev_attr_temp1_crit_hyst.attr, 322 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
322 &dev_attr_temp1_min.attr, 323 &sensor_dev_attr_temp1_min.dev_attr.attr,
323 &dev_attr_temp1_min_hyst.attr, 324 &dev_attr_temp1_min_hyst.attr,
324 &dev_attr_temp1_max.attr, 325 &sensor_dev_attr_temp1_max.dev_attr.attr,
325 &dev_attr_temp1_max_hyst.attr, 326 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
326 &dev_attr_alarms.attr, 327 &dev_attr_alarms.attr,
327 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 328 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
328 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, 329 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,