From: "H. Nikolaus Schaller" <hns@goldelico.com>
To: Sebastian Reichel <sre@kernel.org>,
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
David Woodhouse <dwmw2@infradead.org>
Cc: Grazvydas Ignotas <notasas@gmail.com>,
Andreas Kemnade <andreas@kemnade.info>,
linux-pm@vger.kernel.org, letux-kernel@openphoenux.org,
linux-kernel@vger.kernel.org,
"H. Nikolaus Schaller" <hns@goldelico.com>
Subject: [PATCH v3 2/3] drivers:power:twl4030-charger: add INPUT_CURRENT_LIMIT property and make it writeable
Date: Fri, 14 Apr 2017 20:25:56 +0200 [thread overview]
Message-ID: <ed229ae8e6a4a9bd040e389d101b5257296d54ff.1492194356.git.hns@goldelico.com> (raw)
In-Reply-To: <cover.1492194356.git.hns@goldelico.com>
In-Reply-To: <cover.1492194356.git.hns@goldelico.com>
Currently, the twl4030 charger defines its own max_current by directly
creating sysfs nodes. It should use the input_current_limit property
which is e.g. used by the bq24257 driver.
This patch adds the input_current_property with the same semantics as
the max_current property. The code to manage the max_current property
is removed by a separate patch.
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/power/supply/twl4030_charger.c | 59 ++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 34e389d..e70c4ed 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -893,6 +893,28 @@ static int twl4030_bci_get_property(struct power_supply *psy,
twl4030_bci_state_to_status(state) !=
POWER_SUPPLY_STATUS_NOT_CHARGING;
break;
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ val->intval = -1;
+ if (psy->desc->type != POWER_SUPPLY_TYPE_USB) {
+ if (!bci->ac_is_active)
+ val->intval = bci->ac_cur;
+ } else {
+ if (bci->ac_is_active)
+ val->intval = bci->usb_cur_target;
+ }
+ if (val->intval < 0) {
+ u8 bcictl1;
+
+ val->intval = twl4030bci_read_adc_val(TWL4030_BCIIREF1);
+ if (val->intval < 0)
+ return val->intval;
+ ret = twl4030_bci_read(TWL4030_BCICTL1, &bcictl1);
+ if (ret < 0)
+ return ret;
+ val->intval = regval2ua(val->intval, bcictl1 &
+ TWL4030_CGAIN);
+ }
+ break;
default:
return -EINVAL;
}
@@ -900,11 +922,44 @@ static int twl4030_bci_get_property(struct power_supply *psy,
return 0;
}
+static int twl4030_bci_set_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ const union power_supply_propval *val)
+{
+ struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent);
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ if (psy->desc->type == POWER_SUPPLY_TYPE_USB)
+ bci->usb_cur_target = val->intval;
+ else
+ bci->ac_cur = val->intval;
+ twl4030_charger_update_current(bci);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int twl4030_bci_property_is_writeable(struct power_supply *psy,
+ enum power_supply_property psp)
+{
+ switch (psp) {
+ case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ return true;
+ default:
+ return false;
+ }
+}
+
static enum power_supply_property twl4030_charger_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
+ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
};
#ifdef CONFIG_OF
@@ -941,6 +996,8 @@ static const struct power_supply_desc twl4030_bci_ac_desc = {
.properties = twl4030_charger_props,
.num_properties = ARRAY_SIZE(twl4030_charger_props),
.get_property = twl4030_bci_get_property,
+ .set_property = twl4030_bci_set_property,
+ .property_is_writeable = twl4030_bci_property_is_writeable,
};
static const struct power_supply_desc twl4030_bci_usb_desc = {
@@ -949,6 +1006,8 @@ static const struct power_supply_desc twl4030_bci_usb_desc = {
.properties = twl4030_charger_props,
.num_properties = ARRAY_SIZE(twl4030_charger_props),
.get_property = twl4030_bci_get_property,
+ .set_property = twl4030_bci_set_property,
+ .property_is_writeable = twl4030_bci_property_is_writeable,
};
static int twl4030_bci_probe(struct platform_device *pdev)
--
2.7.3
next prev parent reply other threads:[~2017-04-14 18:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-14 18:25 [PATCH v3 0/3] Fixes for twl4030 charger H. Nikolaus Schaller
2017-04-14 18:25 ` [PATCH v3 1/3] drivers:power:twl4030-charger: don't check if battery is present H. Nikolaus Schaller
2017-04-14 18:25 ` H. Nikolaus Schaller [this message]
2017-05-01 11:15 ` [PATCH v3 2/3] drivers:power:twl4030-charger: add INPUT_CURRENT_LIMIT property and make it writeable Sebastian Reichel
2017-05-03 12:18 ` H. Nikolaus Schaller
2017-04-14 18:25 ` [PATCH v3 3/3] drivers:power:twl4030-charger: remove nonstandard max_current sysfs attribute H. Nikolaus Schaller
2017-05-01 11:26 ` Sebastian Reichel
2017-05-03 12:20 ` H. Nikolaus Schaller
2017-05-11 22:35 ` Pavel Machek
2017-05-12 8:07 ` H. Nikolaus Schaller
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=ed229ae8e6a4a9bd040e389d101b5257296d54ff.1492194356.git.hns@goldelico.com \
--to=hns@goldelico.com \
--cc=andreas@kemnade.info \
--cc=dbaryshkov@gmail.com \
--cc=dwmw2@infradead.org \
--cc=letux-kernel@openphoenux.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=notasas@gmail.com \
--cc=sre@kernel.org \
/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).