hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/iio/adc/hx711.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * HX711: analog to digital converter for weight sensor module
34 *
45 * Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167 #include <linux/err.h>
178 #include <linux/kernel.h>
....@@ -32,6 +23,7 @@
3223
3324 /* gain to pulse and scale conversion */
3425 #define HX711_GAIN_MAX 3
26
+#define HX711_RESET_GAIN 128
3527
3628 struct hx711_gain_to_scale {
3729 int gain;
....@@ -194,8 +186,7 @@
194186
195187 static int hx711_reset(struct hx711_data *hx711_data)
196188 {
197
- int ret;
198
- int val = gpiod_get_value(hx711_data->gpiod_dout);
189
+ int val = hx711_wait_for_ready(hx711_data);
199190
200191 if (val) {
201192 /*
....@@ -211,22 +202,10 @@
211202 msleep(10);
212203 gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
213204
214
- ret = hx711_wait_for_ready(hx711_data);
215
- if (ret)
216
- return ret;
217
- /*
218
- * after a reset the gain is 128 so we do a dummy read
219
- * to set the gain for the next read
220
- */
221
- ret = hx711_read(hx711_data);
222
- if (ret < 0)
223
- return ret;
224
-
225
- /*
226
- * after a dummy read we need to wait vor readiness
227
- * for not mixing gain pulses with the clock
228
- */
229205 val = hx711_wait_for_ready(hx711_data);
206
+
207
+ /* after a reset the gain is 128 */
208
+ hx711_data->gain_set = HX711_RESET_GAIN;
230209 }
231210
232211 return val;
....@@ -572,7 +551,6 @@
572551 platform_set_drvdata(pdev, indio_dev);
573552
574553 indio_dev->name = "hx711";
575
- indio_dev->dev.parent = &pdev->dev;
576554 indio_dev->info = &hx711_iio_info;
577555 indio_dev->modes = INDIO_DIRECT_MODE;
578556 indio_dev->channels = hx711_chan_spec;