forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/hwmon/emc1403.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * emc1403.c - SMSC Thermal Driver
34 *
....@@ -5,18 +6,6 @@
56 *
67 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78 *
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.
209 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2110 */
2211
....@@ -43,8 +32,8 @@
4332 const struct attribute_group *groups[4];
4433 };
4534
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)
4837 {
4938 struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
5039 struct thermal_data *data = dev_get_drvdata(dev);
....@@ -57,8 +46,8 @@
5746 return sprintf(buf, "%d000\n", val);
5847 }
5948
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)
6251 {
6352 struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
6453 struct thermal_data *data = dev_get_drvdata(dev);
....@@ -71,8 +60,8 @@
7160 return sprintf(buf, "%d\n", !!(val & sda->index));
7261 }
7362
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)
7665 {
7766 struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
7867 struct thermal_data *data = dev_get_drvdata(dev);
....@@ -88,8 +77,8 @@
8877 return count;
8978 }
9079
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)
9382 {
9483 struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
9584 struct thermal_data *data = dev_get_drvdata(dev);
....@@ -128,20 +117,20 @@
128117 return sprintf(buf, "%d000\n", is_min ? limit + hyst : limit - hyst);
129118 }
130119
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)
133122 {
134123 return show_hyst_common(dev, attr, buf, false);
135124 }
136125
137
-static ssize_t show_min_hyst(struct device *dev,
126
+static ssize_t min_hyst_show(struct device *dev,
138127 struct device_attribute *attr, char *buf)
139128 {
140129 return show_hyst_common(dev, attr, buf, true);
141130 }
142131
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)
145134 {
146135 struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
147136 struct thermal_data *data = dev_get_drvdata(dev);
....@@ -173,80 +162,54 @@
173162 * Sensors. We pass the actual i2c register to the methods.
174163 */
175164
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);
193175
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);
211187
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);
229199
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);
247211
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);
250213
251214 static struct attribute *emc1402_attrs[] = {
252215 &sensor_dev_attr_temp1_min.dev_attr.attr,
....@@ -328,14 +291,14 @@
328291 * array.
329292 */
330293 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),
334297
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),
339302 };
340303
341304 static struct attribute *emc1402_alarm_attrs[] = {
....@@ -423,11 +386,13 @@
423386 .volatile_reg = emc1403_regmap_is_volatile,
424387 };
425388
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)
428392 {
429393 struct thermal_data *data;
430394 struct device *hwmon_dev;
395
+ const struct i2c_device_id *id = i2c_match_id(emc1403_idtable, client);
431396
432397 data = devm_kzalloc(&client->dev, sizeof(struct thermal_data),
433398 GFP_KERNEL);
....@@ -443,10 +408,10 @@
443408 switch (id->driver_data) {
444409 case emc1404:
445410 data->groups[2] = &emc1404_group;
446
- /* fall through */
411
+ fallthrough;
447412 case emc1403:
448413 data->groups[1] = &emc1403_group;
449
- /* fall through */
414
+ fallthrough;
450415 case emc1402:
451416 data->groups[0] = &emc1402_group;
452417 }
....@@ -489,7 +454,7 @@
489454 .name = "emc1403",
490455 },
491456 .detect = emc1403_detect,
492
- .probe = emc1403_probe,
457
+ .probe_new = emc1403_probe,
493458 .id_table = emc1403_idtable,
494459 .address_list = emc1403_address_list,
495460 };