From: Baolin Wang <baolin.wang@linaro.org>
To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com
Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com,
baolin.wang@linaro.org, broonie@kernel.org, zhang.lyra@gmail.com,
orsonzhai@gmail.com
Subject: [PATCH 2/4] power: supply: sc27xx: Add one property to read charge voltage
Date: Tue, 15 Jan 2019 18:32:35 +0800 [thread overview]
Message-ID: <bb75e6c5c7bd89100c7c667c877b8c97b359ff8a.1547544142.git.baolin.wang@linaro.org> (raw)
In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org>
In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org>
Add POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE property to get charge
voltage sampling by ADC controller, which is used to validate if the
charge voltage is in normal range or not in charger manager.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index 76da189..4926b8a 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -72,6 +72,7 @@
* @lock: protect the structure
* @gpiod: GPIO for battery detection
* @channel: IIO channel to get battery temperature
+ * @charge_chan: IIO channel to get charge voltage
* @internal_resist: the battery internal resistance in mOhm
* @total_cap: the total capacity of the battery in mAh
* @init_cap: the initial capacity of the battery in mAh
@@ -92,6 +93,7 @@ struct sc27xx_fgu_data {
struct mutex lock;
struct gpio_desc *gpiod;
struct iio_channel *channel;
+ struct iio_channel *charge_chan;
bool bat_present;
int internal_resist;
int total_cap;
@@ -391,6 +393,18 @@ static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val)
return 0;
}
+static int sc27xx_fgu_get_charge_vol(struct sc27xx_fgu_data *data, int *val)
+{
+ int ret, vol;
+
+ ret = iio_read_channel_processed(data->charge_chan, &vol);
+ if (ret < 0)
+ return ret;
+
+ *val = vol * 1000;
+ return 0;
+}
+
static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp)
{
return iio_read_channel_processed(data->channel, temp);
@@ -502,6 +516,14 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
val->intval = value;
break;
+ case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
+ ret = sc27xx_fgu_get_charge_vol(data, &value);
+ if (ret)
+ goto error;
+
+ val->intval = value;
+ break;
+
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_CURRENT_AVG:
ret = sc27xx_fgu_get_current(data, &value);
@@ -567,6 +589,7 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
POWER_SUPPLY_PROP_VOLTAGE_OCV,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CURRENT_AVG,
+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
};
static const struct power_supply_desc sc27xx_fgu_desc = {
@@ -907,6 +930,12 @@ static int sc27xx_fgu_probe(struct platform_device *pdev)
return PTR_ERR(data->channel);
}
+ data->charge_chan = devm_iio_channel_get(&pdev->dev, "charge-vol");
+ if (IS_ERR(data->charge_chan)) {
+ dev_err(&pdev->dev, "failed to get charge IIO channel\n");
+ return PTR_ERR(data->charge_chan);
+ }
+
data->gpiod = devm_gpiod_get(&pdev->dev, "bat-detect", GPIOD_IN);
if (IS_ERR(data->gpiod)) {
dev_err(&pdev->dev, "failed to get battery detection GPIO\n");
--
1.7.9.5
next prev parent reply other threads:[~2019-01-15 10:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 10:32 [PATCH 1/4] dt-bindings: power: sc27xx: Add one IIO channel to read charge voltage Baolin Wang
2019-01-15 10:32 ` Baolin Wang [this message]
2019-01-15 10:32 ` [PATCH 3/4] power: supply: sc27xx: Fix the incorrect formula when converting capacity to coulomb counter Baolin Wang
2019-01-15 10:32 ` [PATCH 4/4] power: supply: sc27xx: Fix capacity saving function Baolin Wang
2019-01-22 0:50 ` [PATCH 1/4] dt-bindings: power: sc27xx: Add one IIO channel to read charge voltage Rob Herring
2019-01-23 20:27 ` Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bb75e6c5c7bd89100c7c667c877b8c97b359ff8a.1547544142.git.baolin.wang@linaro.org \
--to=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=orsonzhai@gmail.com \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
--cc=yuanjiang.yu@unisoc.com \
--cc=zhang.lyra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).