forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/hwmon/thmc50.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * thmc50.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
45 * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
56 * Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and
67 * Philip Edelbrock <phil@netroedge.com>
7
- *
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; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
218 */
229
2310 #include <linux/module.h>
....@@ -128,16 +115,16 @@
128115 return data;
129116 }
130117
131
-static ssize_t show_analog_out(struct device *dev,
118
+static ssize_t analog_out_show(struct device *dev,
132119 struct device_attribute *attr, char *buf)
133120 {
134121 struct thmc50_data *data = thmc50_update_device(dev);
135122 return sprintf(buf, "%d\n", data->analog_out);
136123 }
137124
138
-static ssize_t set_analog_out(struct device *dev,
139
- struct device_attribute *attr,
140
- const char *buf, size_t count)
125
+static ssize_t analog_out_store(struct device *dev,
126
+ struct device_attribute *attr,
127
+ const char *buf, size_t count)
141128 {
142129 struct thmc50_data *data = dev_get_drvdata(dev);
143130 struct i2c_client *client = data->client;
....@@ -166,14 +153,14 @@
166153 }
167154
168155 /* There is only one PWM mode = DC */
169
-static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
170
- char *buf)
156
+static ssize_t pwm_mode_show(struct device *dev,
157
+ struct device_attribute *attr, char *buf)
171158 {
172159 return sprintf(buf, "0\n");
173160 }
174161
175162 /* Temperatures */
176
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
163
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
177164 char *buf)
178165 {
179166 int nr = to_sensor_dev_attr(attr)->index;
....@@ -181,16 +168,17 @@
181168 return sprintf(buf, "%d\n", data->temp_input[nr] * 1000);
182169 }
183170
184
-static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
185
- char *buf)
171
+static ssize_t temp_min_show(struct device *dev,
172
+ struct device_attribute *attr, char *buf)
186173 {
187174 int nr = to_sensor_dev_attr(attr)->index;
188175 struct thmc50_data *data = thmc50_update_device(dev);
189176 return sprintf(buf, "%d\n", data->temp_min[nr] * 1000);
190177 }
191178
192
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
193
- const char *buf, size_t count)
179
+static ssize_t temp_min_store(struct device *dev,
180
+ struct device_attribute *attr, const char *buf,
181
+ size_t count)
194182 {
195183 int nr = to_sensor_dev_attr(attr)->index;
196184 struct thmc50_data *data = dev_get_drvdata(dev);
....@@ -210,16 +198,17 @@
210198 return count;
211199 }
212200
213
-static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
214
- char *buf)
201
+static ssize_t temp_max_show(struct device *dev,
202
+ struct device_attribute *attr, char *buf)
215203 {
216204 int nr = to_sensor_dev_attr(attr)->index;
217205 struct thmc50_data *data = thmc50_update_device(dev);
218206 return sprintf(buf, "%d\n", data->temp_max[nr] * 1000);
219207 }
220208
221
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
222
- const char *buf, size_t count)
209
+static ssize_t temp_max_store(struct device *dev,
210
+ struct device_attribute *attr, const char *buf,
211
+ size_t count)
223212 {
224213 int nr = to_sensor_dev_attr(attr)->index;
225214 struct thmc50_data *data = dev_get_drvdata(dev);
....@@ -239,16 +228,15 @@
239228 return count;
240229 }
241230
242
-static ssize_t show_temp_critical(struct device *dev,
243
- struct device_attribute *attr,
244
- char *buf)
231
+static ssize_t temp_critical_show(struct device *dev,
232
+ struct device_attribute *attr, char *buf)
245233 {
246234 int nr = to_sensor_dev_attr(attr)->index;
247235 struct thmc50_data *data = thmc50_update_device(dev);
248236 return sprintf(buf, "%d\n", data->temp_critical[nr] * 1000);
249237 }
250238
251
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
239
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
252240 char *buf)
253241 {
254242 int index = to_sensor_dev_attr(attr)->index;
....@@ -257,29 +245,27 @@
257245 return sprintf(buf, "%u\n", (data->alarms >> index) & 1);
258246 }
259247
260
-#define temp_reg(offset) \
261
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
262
- NULL, offset - 1); \
263
-static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
264
- show_temp_min, set_temp_min, offset - 1); \
265
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
266
- show_temp_max, set_temp_max, offset - 1); \
267
-static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO, \
268
- show_temp_critical, NULL, offset - 1);
248
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
249
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_min, 0);
250
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
251
+static SENSOR_DEVICE_ATTR_RO(temp1_crit, temp_critical, 0);
252
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
253
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_min, 1);
254
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
255
+static SENSOR_DEVICE_ATTR_RO(temp2_crit, temp_critical, 1);
256
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
257
+static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_min, 2);
258
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
259
+static SENSOR_DEVICE_ATTR_RO(temp3_crit, temp_critical, 2);
269260
270
-temp_reg(1);
271
-temp_reg(2);
272
-temp_reg(3);
261
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 0);
262
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
263
+static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 1);
264
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 7);
265
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2);
273266
274
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0);
275
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
276
-static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
277
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 7);
278
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2);
279
-
280
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_analog_out,
281
- set_analog_out, 0);
282
-static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
267
+static SENSOR_DEVICE_ATTR_RW(pwm1, analog_out, 0);
268
+static SENSOR_DEVICE_ATTR_RO(pwm1_mode, pwm_mode, 0);
283269
284270 static struct attribute *thmc50_attributes[] = {
285271 &sensor_dev_attr_temp1_max.dev_attr.attr,
....@@ -391,8 +377,9 @@
391377 i2c_smbus_write_byte_data(client, THMC50_REG_CONF, config);
392378 }
393379
394
-static int thmc50_probe(struct i2c_client *client,
395
- const struct i2c_device_id *id)
380
+static const struct i2c_device_id thmc50_id[];
381
+
382
+static int thmc50_probe(struct i2c_client *client)
396383 {
397384 struct device *dev = &client->dev;
398385 struct thmc50_data *data;
....@@ -404,7 +391,7 @@
404391 return -ENOMEM;
405392
406393 data->client = client;
407
- data->type = id->driver_data;
394
+ data->type = i2c_match_id(thmc50_id, client)->driver_data;
408395 mutex_init(&data->update_lock);
409396
410397 thmc50_init_client(data);
....@@ -433,7 +420,7 @@
433420 .driver = {
434421 .name = "thmc50",
435422 },
436
- .probe = thmc50_probe,
423
+ .probe_new = thmc50_probe,
437424 .id_table = thmc50_id,
438425 .detect = thmc50_detect,
439426 .address_list = normal_i2c,