| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * HX711: analog to digital converter for weight sensor module |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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. |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | #include <linux/err.h> |
|---|
| 17 | 8 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 32 | 23 | |
|---|
| 33 | 24 | /* gain to pulse and scale conversion */ |
|---|
| 34 | 25 | #define HX711_GAIN_MAX 3 |
|---|
| 26 | +#define HX711_RESET_GAIN 128 |
|---|
| 35 | 27 | |
|---|
| 36 | 28 | struct hx711_gain_to_scale { |
|---|
| 37 | 29 | int gain; |
|---|
| .. | .. |
|---|
| 194 | 186 | |
|---|
| 195 | 187 | static int hx711_reset(struct hx711_data *hx711_data) |
|---|
| 196 | 188 | { |
|---|
| 197 | | - int ret; |
|---|
| 198 | | - int val = gpiod_get_value(hx711_data->gpiod_dout); |
|---|
| 189 | + int val = hx711_wait_for_ready(hx711_data); |
|---|
| 199 | 190 | |
|---|
| 200 | 191 | if (val) { |
|---|
| 201 | 192 | /* |
|---|
| .. | .. |
|---|
| 211 | 202 | msleep(10); |
|---|
| 212 | 203 | gpiod_set_value(hx711_data->gpiod_pd_sck, 0); |
|---|
| 213 | 204 | |
|---|
| 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 | | - */ |
|---|
| 229 | 205 | val = hx711_wait_for_ready(hx711_data); |
|---|
| 206 | + |
|---|
| 207 | + /* after a reset the gain is 128 */ |
|---|
| 208 | + hx711_data->gain_set = HX711_RESET_GAIN; |
|---|
| 230 | 209 | } |
|---|
| 231 | 210 | |
|---|
| 232 | 211 | return val; |
|---|
| .. | .. |
|---|
| 572 | 551 | platform_set_drvdata(pdev, indio_dev); |
|---|
| 573 | 552 | |
|---|
| 574 | 553 | indio_dev->name = "hx711"; |
|---|
| 575 | | - indio_dev->dev.parent = &pdev->dev; |
|---|
| 576 | 554 | indio_dev->info = &hx711_iio_info; |
|---|
| 577 | 555 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 578 | 556 | indio_dev->channels = hx711_chan_spec; |
|---|