.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * emc1403.c - SMSC Thermal Driver |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * |
---|
6 | 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
7 | 8 | * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; version 2 of the License. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, but |
---|
13 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | | - * General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License along |
---|
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
---|
19 | | - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
---|
20 | 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
21 | 10 | */ |
---|
22 | 11 | |
---|
.. | .. |
---|
43 | 32 | const struct attribute_group *groups[4]; |
---|
44 | 33 | }; |
---|
45 | 34 | |
---|
46 | | -static ssize_t show_temp(struct device *dev, |
---|
47 | | - struct device_attribute *attr, char *buf) |
---|
| 35 | +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, |
---|
| 36 | + char *buf) |
---|
48 | 37 | { |
---|
49 | 38 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
---|
50 | 39 | struct thermal_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
57 | 46 | return sprintf(buf, "%d000\n", val); |
---|
58 | 47 | } |
---|
59 | 48 | |
---|
60 | | -static ssize_t show_bit(struct device *dev, |
---|
61 | | - struct device_attribute *attr, char *buf) |
---|
| 49 | +static ssize_t bit_show(struct device *dev, struct device_attribute *attr, |
---|
| 50 | + char *buf) |
---|
62 | 51 | { |
---|
63 | 52 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
---|
64 | 53 | struct thermal_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
71 | 60 | return sprintf(buf, "%d\n", !!(val & sda->index)); |
---|
72 | 61 | } |
---|
73 | 62 | |
---|
74 | | -static ssize_t store_temp(struct device *dev, |
---|
75 | | - struct device_attribute *attr, const char *buf, size_t count) |
---|
| 63 | +static ssize_t temp_store(struct device *dev, struct device_attribute *attr, |
---|
| 64 | + const char *buf, size_t count) |
---|
76 | 65 | { |
---|
77 | 66 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
---|
78 | 67 | struct thermal_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
88 | 77 | return count; |
---|
89 | 78 | } |
---|
90 | 79 | |
---|
91 | | -static ssize_t store_bit(struct device *dev, |
---|
92 | | - struct device_attribute *attr, const char *buf, size_t count) |
---|
| 80 | +static ssize_t bit_store(struct device *dev, struct device_attribute *attr, |
---|
| 81 | + const char *buf, size_t count) |
---|
93 | 82 | { |
---|
94 | 83 | struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); |
---|
95 | 84 | struct thermal_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
128 | 117 | return sprintf(buf, "%d000\n", is_min ? limit + hyst : limit - hyst); |
---|
129 | 118 | } |
---|
130 | 119 | |
---|
131 | | -static ssize_t show_hyst(struct device *dev, |
---|
132 | | - struct device_attribute *attr, char *buf) |
---|
| 120 | +static ssize_t hyst_show(struct device *dev, struct device_attribute *attr, |
---|
| 121 | + char *buf) |
---|
133 | 122 | { |
---|
134 | 123 | return show_hyst_common(dev, attr, buf, false); |
---|
135 | 124 | } |
---|
136 | 125 | |
---|
137 | | -static ssize_t show_min_hyst(struct device *dev, |
---|
| 126 | +static ssize_t min_hyst_show(struct device *dev, |
---|
138 | 127 | struct device_attribute *attr, char *buf) |
---|
139 | 128 | { |
---|
140 | 129 | return show_hyst_common(dev, attr, buf, true); |
---|
141 | 130 | } |
---|
142 | 131 | |
---|
143 | | -static ssize_t store_hyst(struct device *dev, |
---|
144 | | - struct device_attribute *attr, const char *buf, size_t count) |
---|
| 132 | +static ssize_t hyst_store(struct device *dev, struct device_attribute *attr, |
---|
| 133 | + const char *buf, size_t count) |
---|
145 | 134 | { |
---|
146 | 135 | struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); |
---|
147 | 136 | struct thermal_data *data = dev_get_drvdata(dev); |
---|
.. | .. |
---|
173 | 162 | * Sensors. We pass the actual i2c register to the methods. |
---|
174 | 163 | */ |
---|
175 | 164 | |
---|
176 | | -static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, |
---|
177 | | - show_temp, store_temp, 0x06); |
---|
178 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, |
---|
179 | | - show_temp, store_temp, 0x05); |
---|
180 | | -static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, |
---|
181 | | - show_temp, store_temp, 0x20); |
---|
182 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0x00); |
---|
183 | | -static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, |
---|
184 | | - show_bit, NULL, 0x36, 0x01); |
---|
185 | | -static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, |
---|
186 | | - show_bit, NULL, 0x35, 0x01); |
---|
187 | | -static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, |
---|
188 | | - show_bit, NULL, 0x37, 0x01); |
---|
189 | | -static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x06); |
---|
190 | | -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_hyst, NULL, 0x05); |
---|
191 | | -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR, |
---|
192 | | - show_hyst, store_hyst, 0x20); |
---|
| 165 | +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 0x06); |
---|
| 166 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 0x05); |
---|
| 167 | +static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, 0x20); |
---|
| 168 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0x00); |
---|
| 169 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, bit, 0x36, 0x01); |
---|
| 170 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, bit, 0x35, 0x01); |
---|
| 171 | +static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, bit, 0x37, 0x01); |
---|
| 172 | +static SENSOR_DEVICE_ATTR_RO(temp1_min_hyst, min_hyst, 0x06); |
---|
| 173 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_hyst, hyst, 0x05); |
---|
| 174 | +static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, hyst, 0x20); |
---|
193 | 175 | |
---|
194 | | -static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, |
---|
195 | | - show_temp, store_temp, 0x08); |
---|
196 | | -static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, |
---|
197 | | - show_temp, store_temp, 0x07); |
---|
198 | | -static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, |
---|
199 | | - show_temp, store_temp, 0x19); |
---|
200 | | -static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0x01); |
---|
201 | | -static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x02); |
---|
202 | | -static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, |
---|
203 | | - show_bit, NULL, 0x36, 0x02); |
---|
204 | | -static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, |
---|
205 | | - show_bit, NULL, 0x35, 0x02); |
---|
206 | | -static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, |
---|
207 | | - show_bit, NULL, 0x37, 0x02); |
---|
208 | | -static SENSOR_DEVICE_ATTR(temp2_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x08); |
---|
209 | | -static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO, show_hyst, NULL, 0x07); |
---|
210 | | -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_hyst, NULL, 0x19); |
---|
| 176 | +static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, 0x08); |
---|
| 177 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, 0x07); |
---|
| 178 | +static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, 0x19); |
---|
| 179 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 0x01); |
---|
| 180 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, bit, 0x1b, 0x02); |
---|
| 181 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, bit, 0x36, 0x02); |
---|
| 182 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, bit, 0x35, 0x02); |
---|
| 183 | +static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, bit, 0x37, 0x02); |
---|
| 184 | +static SENSOR_DEVICE_ATTR_RO(temp2_min_hyst, min_hyst, 0x08); |
---|
| 185 | +static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, hyst, 0x07); |
---|
| 186 | +static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, hyst, 0x19); |
---|
211 | 187 | |
---|
212 | | -static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, |
---|
213 | | - show_temp, store_temp, 0x16); |
---|
214 | | -static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, |
---|
215 | | - show_temp, store_temp, 0x15); |
---|
216 | | -static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO | S_IWUSR, |
---|
217 | | - show_temp, store_temp, 0x1A); |
---|
218 | | -static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 0x23); |
---|
219 | | -static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x04); |
---|
220 | | -static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, |
---|
221 | | - show_bit, NULL, 0x36, 0x04); |
---|
222 | | -static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, |
---|
223 | | - show_bit, NULL, 0x35, 0x04); |
---|
224 | | -static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, |
---|
225 | | - show_bit, NULL, 0x37, 0x04); |
---|
226 | | -static SENSOR_DEVICE_ATTR(temp3_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x16); |
---|
227 | | -static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO, show_hyst, NULL, 0x15); |
---|
228 | | -static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_hyst, NULL, 0x1A); |
---|
| 188 | +static SENSOR_DEVICE_ATTR_RW(temp3_min, temp, 0x16); |
---|
| 189 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp, 0x15); |
---|
| 190 | +static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp, 0x1A); |
---|
| 191 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 0x23); |
---|
| 192 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, bit, 0x1b, 0x04); |
---|
| 193 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, bit, 0x36, 0x04); |
---|
| 194 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, bit, 0x35, 0x04); |
---|
| 195 | +static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, bit, 0x37, 0x04); |
---|
| 196 | +static SENSOR_DEVICE_ATTR_RO(temp3_min_hyst, min_hyst, 0x16); |
---|
| 197 | +static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, hyst, 0x15); |
---|
| 198 | +static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, hyst, 0x1A); |
---|
229 | 199 | |
---|
230 | | -static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, |
---|
231 | | - show_temp, store_temp, 0x2D); |
---|
232 | | -static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, |
---|
233 | | - show_temp, store_temp, 0x2C); |
---|
234 | | -static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO | S_IWUSR, |
---|
235 | | - show_temp, store_temp, 0x30); |
---|
236 | | -static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 0x2A); |
---|
237 | | -static SENSOR_DEVICE_ATTR_2(temp4_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x08); |
---|
238 | | -static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, |
---|
239 | | - show_bit, NULL, 0x36, 0x08); |
---|
240 | | -static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, |
---|
241 | | - show_bit, NULL, 0x35, 0x08); |
---|
242 | | -static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, |
---|
243 | | - show_bit, NULL, 0x37, 0x08); |
---|
244 | | -static SENSOR_DEVICE_ATTR(temp4_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x2D); |
---|
245 | | -static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IRUGO, show_hyst, NULL, 0x2C); |
---|
246 | | -static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO, show_hyst, NULL, 0x30); |
---|
| 200 | +static SENSOR_DEVICE_ATTR_RW(temp4_min, temp, 0x2D); |
---|
| 201 | +static SENSOR_DEVICE_ATTR_RW(temp4_max, temp, 0x2C); |
---|
| 202 | +static SENSOR_DEVICE_ATTR_RW(temp4_crit, temp, 0x30); |
---|
| 203 | +static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 0x2A); |
---|
| 204 | +static SENSOR_DEVICE_ATTR_2_RO(temp4_fault, bit, 0x1b, 0x08); |
---|
| 205 | +static SENSOR_DEVICE_ATTR_2_RO(temp4_min_alarm, bit, 0x36, 0x08); |
---|
| 206 | +static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, bit, 0x35, 0x08); |
---|
| 207 | +static SENSOR_DEVICE_ATTR_2_RO(temp4_crit_alarm, bit, 0x37, 0x08); |
---|
| 208 | +static SENSOR_DEVICE_ATTR_RO(temp4_min_hyst, min_hyst, 0x2D); |
---|
| 209 | +static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, hyst, 0x2C); |
---|
| 210 | +static SENSOR_DEVICE_ATTR_RO(temp4_crit_hyst, hyst, 0x30); |
---|
247 | 211 | |
---|
248 | | -static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR, |
---|
249 | | - show_bit, store_bit, 0x03, 0x40); |
---|
| 212 | +static SENSOR_DEVICE_ATTR_2_RW(power_state, bit, 0x03, 0x40); |
---|
250 | 213 | |
---|
251 | 214 | static struct attribute *emc1402_attrs[] = { |
---|
252 | 215 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
---|
.. | .. |
---|
328 | 291 | * array. |
---|
329 | 292 | */ |
---|
330 | 293 | static struct sensor_device_attribute_2 emc1402_alarms[] = { |
---|
331 | | - SENSOR_ATTR_2(temp1_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x20), |
---|
332 | | - SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x40), |
---|
333 | | - SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x01), |
---|
| 294 | + SENSOR_ATTR_2_RO(temp1_min_alarm, bit, 0x02, 0x20), |
---|
| 295 | + SENSOR_ATTR_2_RO(temp1_max_alarm, bit, 0x02, 0x40), |
---|
| 296 | + SENSOR_ATTR_2_RO(temp1_crit_alarm, bit, 0x02, 0x01), |
---|
334 | 297 | |
---|
335 | | - SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x02, 0x04), |
---|
336 | | - SENSOR_ATTR_2(temp2_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x08), |
---|
337 | | - SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x10), |
---|
338 | | - SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x02), |
---|
| 298 | + SENSOR_ATTR_2_RO(temp2_fault, bit, 0x02, 0x04), |
---|
| 299 | + SENSOR_ATTR_2_RO(temp2_min_alarm, bit, 0x02, 0x08), |
---|
| 300 | + SENSOR_ATTR_2_RO(temp2_max_alarm, bit, 0x02, 0x10), |
---|
| 301 | + SENSOR_ATTR_2_RO(temp2_crit_alarm, bit, 0x02, 0x02), |
---|
339 | 302 | }; |
---|
340 | 303 | |
---|
341 | 304 | static struct attribute *emc1402_alarm_attrs[] = { |
---|
.. | .. |
---|
423 | 386 | .volatile_reg = emc1403_regmap_is_volatile, |
---|
424 | 387 | }; |
---|
425 | 388 | |
---|
426 | | -static int emc1403_probe(struct i2c_client *client, |
---|
427 | | - const struct i2c_device_id *id) |
---|
| 389 | +static const struct i2c_device_id emc1403_idtable[]; |
---|
| 390 | + |
---|
| 391 | +static int emc1403_probe(struct i2c_client *client) |
---|
428 | 392 | { |
---|
429 | 393 | struct thermal_data *data; |
---|
430 | 394 | struct device *hwmon_dev; |
---|
| 395 | + const struct i2c_device_id *id = i2c_match_id(emc1403_idtable, client); |
---|
431 | 396 | |
---|
432 | 397 | data = devm_kzalloc(&client->dev, sizeof(struct thermal_data), |
---|
433 | 398 | GFP_KERNEL); |
---|
.. | .. |
---|
443 | 408 | switch (id->driver_data) { |
---|
444 | 409 | case emc1404: |
---|
445 | 410 | data->groups[2] = &emc1404_group; |
---|
446 | | - /* fall through */ |
---|
| 411 | + fallthrough; |
---|
447 | 412 | case emc1403: |
---|
448 | 413 | data->groups[1] = &emc1403_group; |
---|
449 | | - /* fall through */ |
---|
| 414 | + fallthrough; |
---|
450 | 415 | case emc1402: |
---|
451 | 416 | data->groups[0] = &emc1402_group; |
---|
452 | 417 | } |
---|
.. | .. |
---|
489 | 454 | .name = "emc1403", |
---|
490 | 455 | }, |
---|
491 | 456 | .detect = emc1403_detect, |
---|
492 | | - .probe = emc1403_probe, |
---|
| 457 | + .probe_new = emc1403_probe, |
---|
493 | 458 | .id_table = emc1403_idtable, |
---|
494 | 459 | .address_list = emc1403_address_list, |
---|
495 | 460 | }; |
---|