public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Heidelberg <david@ixit.cz>
To: Sebastian Reichel <sre@kernel.org>,
	Jonghwa Lee <jonghwa3.lee@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Myungjoo Ham <myungjoo.ham@samsung.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	John Stultz <john.stultz@linaro.org>,
	Vinay Simha BN <simhavcs@gmail.com>,
	mika.westerberg@linux.intel.com, ramakrishna.pallala@intel.com,
	Dmitry Osipenko <digetx@gmail.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: David Heidelberg <david@ixit.cz>
Subject: [PATCH 5/9] power: supply: smb347-charger: Implement device-tree support
Date: Sun, 29 Mar 2020 18:21:24 +0200	[thread overview]
Message-ID: <20200329162128.218584-6-david@ixit.cz> (raw)
In-Reply-To: <20200329161552.215075-1-david@ixit.cz>

This patch makes smb347 charger driver to support dt binding. All legacy
platform data now can be parsed from dt.
Because of that smb347 is i2c client driver, IRQ number can be passed
automatically through client's irq variable if it is defined in dt.
No more to use requesting gpio to irq manually in dt-way.

Based on: https://patchwork.kernel.org/patch/4284731/
Original author: Jonghwa Lee <jonghwa3.lee@samsung.com>

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: David Heidelberg <david@ixit.cz>
---
 drivers/power/supply/smb347-charger.c | 107 +++++++++++++++++++++++---
 1 file changed, 97 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/smb347-charger.c b/drivers/power/supply/smb347-charger.c
index 4add9f64ba90..852d2ab566e0 100644
--- a/drivers/power/supply/smb347-charger.c
+++ b/drivers/power/supply/smb347-charger.c
@@ -1180,6 +1180,87 @@ static bool smb347_readable_reg(struct device *dev, unsigned int reg)
 	return smb347_volatile_reg(dev, reg);
 }
 
+static void smb347_dt_parse_pdata(struct device_node *np,
+				  struct smb347_charger_platform_data *pdata)
+{
+	/* Charging constraints */
+	of_property_read_u32(np, "summit,max-chg-curr",
+			     &pdata->max_charge_current);
+	of_property_read_u32(np, "summit,max-chg-volt",
+			     &pdata->max_charge_voltage);
+	of_property_read_u32(np, "summit,pre-chg-curr",
+			     &pdata->pre_charge_current);
+	of_property_read_u32(np, "summit,term-curr",
+			     &pdata->termination_current);
+	of_property_read_u32(np, "summit,fast-volt-threshold",
+			     &pdata->pre_to_fast_voltage);
+	of_property_read_u32(np, "summit,mains-curr-limit",
+			     &pdata->mains_current_limit);
+	of_property_read_u32(np, "summit,usb-curr-limit",
+			     &pdata->usb_hc_current_limit);
+
+	/* For thermometer monitoring */
+	of_property_read_u32(np, "summit,chip-temp-threshold",
+			     &pdata->chip_temp_threshold);
+	if (of_property_read_u32(np, "summit,soft-cold-temp-limit",
+				 &pdata->soft_cold_temp_limit))
+		pdata->soft_cold_temp_limit = SMB347_TEMP_USE_DEFAULT;
+	if (of_property_read_u32(np, "summit,soft-hot-temp-limit",
+				 &pdata->soft_hot_temp_limit))
+		pdata->soft_hot_temp_limit = SMB347_TEMP_USE_DEFAULT;
+	if (of_property_read_u32(np, "summit,hard-cold-temp-limit",
+				 &pdata->hard_cold_temp_limit))
+		pdata->hard_cold_temp_limit = SMB347_TEMP_USE_DEFAULT;
+	if (of_property_read_u32(np, "summit,hard-hot-temp-limit",
+				 &pdata->hard_hot_temp_limit))
+		pdata->hard_hot_temp_limit = SMB347_TEMP_USE_DEFAULT;
+
+	/* Suspend when battery temperature is outside hard limits */
+	if (pdata->hard_cold_temp_limit != SMB347_TEMP_USE_DEFAULT ||
+	    pdata->hard_hot_temp_limit != SMB347_TEMP_USE_DEFAULT)
+		pdata->suspend_on_hard_temp_limit = true;
+
+	if (of_property_read_u32(np, "summit,soft-comp-method",
+				 &pdata->soft_temp_limit_compensation))
+		pdata->soft_temp_limit_compensation =
+				SMB347_SOFT_TEMP_COMPENSATE_DEFAULT;
+
+	of_property_read_u32(np, "summit,chg-curr-comp",
+			     &pdata->charge_current_compensation);
+
+	/* Supported charging mode */
+	pdata->use_mains =
+		of_property_read_bool(np, "summit,enable-mains-charging");
+	pdata->use_usb =
+		of_property_read_bool(np, "summit,enable-usb-charging");
+	pdata->use_usb_otg =
+		of_property_read_bool(np, "summit,enable-otg-charging");
+
+	/* Enable charging method */
+	of_property_read_u32(np, "summit,enable-chg-ctrl",
+			     &pdata->enable_control);
+
+	/* If IRQ is enabled or not */
+	if (!of_find_property(np, "interrupts", NULL))
+		pdata->irq_gpio = -1;
+}
+
+static struct smb347_charger_platform_data
+			*smb347_get_platdata(struct device *dev)
+{
+	struct smb347_charger_platform_data *pdata;
+
+	if (dev->of_node) {
+		pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+		if (pdata)
+			smb347_dt_parse_pdata(dev->of_node, pdata);
+	} else {
+		pdata = dev_get_platdata(dev);
+	}
+
+	return pdata;
+}
+
 static const struct regmap_config smb347_regmap = {
 	.reg_bits	= 8,
 	.val_bits	= 8,
@@ -1216,28 +1297,26 @@ static int smb347_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
 	static char *battery[] = { "smb347-battery" };
-	const struct smb347_charger_platform_data *pdata;
 	struct power_supply_config mains_usb_cfg = {}, battery_cfg = {};
 	struct device *dev = &client->dev;
 	struct smb347_charger *smb;
 	int ret;
 
-	pdata = dev->platform_data;
-	if (!pdata)
-		return -EINVAL;
-
-	if (!pdata->use_mains && !pdata->use_usb)
-		return -EINVAL;
-
 	smb = devm_kzalloc(dev, sizeof(*smb), GFP_KERNEL);
 	if (!smb)
 		return -ENOMEM;
 
+	smb->pdata = smb347_get_platdata(dev);
+	if (!smb->pdata)
+		return -ENODEV;
+
+	if (!smb->pdata->use_mains && !smb->pdata->use_usb)
+		return -EINVAL;
+
 	i2c_set_clientdata(client, smb);
 
 	mutex_init(&smb->lock);
 	smb->dev = &client->dev;
-	smb->pdata = pdata;
 
 	smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap);
 	if (IS_ERR(smb->regmap))
@@ -1250,6 +1329,7 @@ static int smb347_probe(struct i2c_client *client,
 	mains_usb_cfg.supplied_to = battery;
 	mains_usb_cfg.num_supplicants = ARRAY_SIZE(battery);
 	mains_usb_cfg.drv_data = smb;
+	mains_usb_cfg.of_node = dev->of_node;
 	if (smb->pdata->use_mains) {
 		smb->mains = power_supply_register(dev, &smb347_mains_desc,
 						   &mains_usb_cfg);
@@ -1282,7 +1362,7 @@ static int smb347_probe(struct i2c_client *client,
 	 * Interrupt pin is optional. If it is connected, we setup the
 	 * interrupt support here.
 	 */
-	if (pdata->irq_gpio >= 0) {
+	if (smb->pdata->irq_gpio >= 0) {
 		ret = smb347_irq_init(smb, client);
 		if (ret < 0) {
 			dev_warn(dev, "failed to initialize IRQ: %d\n", ret);
@@ -1316,9 +1396,16 @@ static const struct i2c_device_id smb347_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, smb347_id);
 
+static const struct of_device_id smb3xx_of_match[] = {
+	{ .compatible = "summit,smb347" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, smb3xx_of_match);
+
 static struct i2c_driver smb347_driver = {
 	.driver = {
 		.name = "smb347",
+		.of_match_table = smb3xx_of_match,
 	},
 	.probe        = smb347_probe,
 	.remove       = smb347_remove,
-- 
2.25.0


  parent reply	other threads:[~2020-03-29 16:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-29 16:15 [PATCH 0/9] Summit SMB3xx driver & device-tree David Heidelberg
2020-03-29 16:15 ` [PATCH 1/9] power: supply: smb347-charger: IRQSTAT_D is volatile David Heidelberg
2020-05-10 16:28   ` Sebastian Reichel
2020-03-29 16:15 ` [PATCH 2/9] power: supply: smb347-charger: Add delay before getting IRQSTAT David Heidelberg
2020-05-10 16:28   ` Sebastian Reichel
2020-03-29 16:15 ` [PATCH 3/9] power: supply: smb347-charger: Use resource-managed API David Heidelberg
2020-05-10 16:33   ` Sebastian Reichel
2020-03-29 16:21 ` [PATCH 4/9] dt-bindings: power: supply: Add device-tree binding for Summit SMB3xx David Heidelberg
2020-04-10 16:49   ` Rob Herring
2020-04-10 19:02     ` Dmitry Osipenko
2020-04-15 14:27       ` Rob Herring
2020-04-15 15:30         ` Dmitry Osipenko
2020-05-09  1:14           ` Sebastian Reichel
2020-05-14 19:34             ` Dmitry Osipenko
2020-03-29 16:21 ` David Heidelberg [this message]
2020-03-31  0:25   ` [PATCH 5/9] power: supply: smb347-charger: Implement device-tree support Jonghwa Lee
2020-03-31 17:20     ` Dmitry Osipenko
2020-03-29 16:21 ` [PATCH 6/9] power: supply: smb347-charger: Support SMB345 and SMB358 David Heidelberg
2020-05-10 16:40   ` Sebastian Reichel
2020-03-29 16:21 ` [PATCH 7/9] power: supply: smb347-charger: Remove virtual smb347-battery David Heidelberg
2020-03-29 16:21 ` [PATCH 8/9] power: supply: smb347-charger: Replace mutex with IRQ disable/enable David Heidelberg
2020-03-29 16:21 ` [PATCH 9/9] arm: dts: qcom: apq8064-nexus7: Add smb345 charger node David Heidelberg

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=20200329162128.218584-6-david@ixit.cz \
    --to=david@ixit.cz \
    --cc=cw00.choi@samsung.com \
    --cc=digetx@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=jonghwa3.lee@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=ramakrishna.pallala@intel.com \
    --cc=simhavcs@gmail.com \
    --cc=sre@kernel.org \
    --cc=sumit.semwal@linaro.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