linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>,
	Wolfram Sang <wsa@the-dreams.de>,
	Sebastian Reichel <sre@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	Liam Breck <liam@networkimprov.net>,
	Tony Lindgren <tony@atomide.com>,
	linux-pm@vger.kernel.org, devel@driverdev.osuosl.org
Subject: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator
Date: Sun,  6 Aug 2017 14:35:50 +0200	[thread overview]
Message-ID: <20170806123555.5124-14-hdegoede@redhat.com> (raw)
In-Reply-To: <20170806123555.5124-1-hdegoede@redhat.com>

Register the 5V boost converter as a regulator named
"regulator-bq24190-usb-vbus". Note the name includes "bq24190" because
the bq24190 family is also used on ACPI devices where there are no
device-tree phandles, so regulator_get will fallback to the name and thus
it must be unique on the system.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/supply/bq24190_charger.c | 121 +++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index d5a707e14526..f25ea9c4acca 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -16,6 +16,8 @@
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/power_supply.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
@@ -504,6 +506,121 @@ static int bq24190_sysfs_create_group(struct bq24190_dev_info *bdi)
 static inline void bq24190_sysfs_remove_group(struct bq24190_dev_info *bdi) {}
 #endif
 
+#ifdef CONFIG_REGULATOR
+static int bq24190_vbus_enable(struct regulator_dev *dev)
+{
+	struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
+	int ret;
+
+	ret = pm_runtime_get_sync(bdi->dev);
+	if (ret < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
+		pm_runtime_put_noidle(bdi->dev);
+		return ret;
+	}
+
+	ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
+				 BQ24190_REG_POC_CHG_CONFIG_MASK,
+				 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+				 BQ24190_REG_POC_CHG_CONFIG_OTG);
+
+	pm_runtime_mark_last_busy(bdi->dev);
+	pm_runtime_put_autosuspend(bdi->dev);
+
+	return ret;
+}
+
+static int bq24190_vbus_disable(struct regulator_dev *dev)
+{
+	struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
+	int ret;
+
+	ret = pm_runtime_get_sync(bdi->dev);
+	if (ret < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
+		pm_runtime_put_noidle(bdi->dev);
+		return ret;
+	}
+
+	ret = bq24190_write_mask(bdi, BQ24190_REG_POC,
+				 BQ24190_REG_POC_CHG_CONFIG_MASK,
+				 BQ24190_REG_POC_CHG_CONFIG_SHIFT,
+				 BQ24190_REG_POC_CHG_CONFIG_CHARGE);
+
+	pm_runtime_mark_last_busy(bdi->dev);
+	pm_runtime_put_autosuspend(bdi->dev);
+
+	return ret;
+}
+
+static int bq24190_vbus_is_enabled(struct regulator_dev *dev)
+{
+	struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
+	int ret;
+	u8 val;
+
+	ret = pm_runtime_get_sync(bdi->dev);
+	if (ret < 0) {
+		dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", ret);
+		pm_runtime_put_noidle(bdi->dev);
+		return ret;
+	}
+
+	ret = bq24190_read_mask(bdi, BQ24190_REG_POC,
+				BQ24190_REG_POC_CHG_CONFIG_MASK,
+				BQ24190_REG_POC_CHG_CONFIG_SHIFT, &val);
+
+	pm_runtime_mark_last_busy(bdi->dev);
+	pm_runtime_put_autosuspend(bdi->dev);
+
+	return ret ? ret : val == BQ24190_REG_POC_CHG_CONFIG_OTG;
+}
+
+static const struct regulator_ops bq24190_vbus_ops = {
+	.enable = bq24190_vbus_enable,
+	.disable = bq24190_vbus_disable,
+	.is_enabled = bq24190_vbus_is_enabled,
+};
+
+static const struct regulator_desc bq24190_vbus_desc = {
+	.name = "regulator-bq24190-usb-vbus",
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+	.ops = &bq24190_vbus_ops,
+	.fixed_uV = 5000000,
+	.n_voltages = 1,
+};
+
+static const struct regulator_init_data bq24190_vbus_init_data = {
+	.constraints = {
+		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
+	},
+};
+
+static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
+{
+	struct regulator_config cfg = { };
+	struct regulator_dev *reg;
+	int ret = 0;
+
+	cfg.dev = bdi->dev;
+	cfg.init_data = &bq24190_vbus_init_data;
+	cfg.driver_data = bdi;
+	reg = devm_regulator_register(bdi->dev, &bq24190_vbus_desc, &cfg);
+	if (IS_ERR(reg)) {
+		ret = PTR_ERR(reg);
+		dev_err(bdi->dev, "Can't register regulator: %d\n", ret);
+	}
+
+	return ret;
+}
+#else
+static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
+{
+	return 0;
+}
+#endif
+
 /*
  * According to the "Host Mode and default Mode" section of the
  * manual, a write to any register causes the bq24190 to switch
@@ -1530,6 +1647,10 @@ static int bq24190_probe(struct i2c_client *client,
 		goto out_pmrt;
 	}
 
+	ret = bq24190_register_vbus_regulator(bdi);
+	if (ret < 0)
+		goto out_pmrt;
+
 	ret = bq24190_hw_init(bdi);
 	if (ret < 0) {
 		dev_err(dev, "Hardware init failed\n");
-- 
2.13.3

  parent reply	other threads:[~2017-08-06 12:36 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-06 12:35 [PATCH 00/18] Hookup typec power-negotation to the PMIC and charger Hans de Goede
2017-08-06 12:35 ` [PATCH 01/18] staging: typec: tcpm: Add get_usb2_current_limit tcpc_dev callback Hans de Goede
2017-08-06 14:18   ` Guenter Roeck
2017-08-06 14:29     ` Hans de Goede
2017-08-06 14:52       ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect Hans de Goede
2017-08-06 14:07   ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 03/18] staging: typec: tcpm: Split tcpm code into tcpm-core.c and tcpm-helpers.c Hans de Goede
2017-08-06 12:35 ` [PATCH 04/18] staging: typec: tcpm: Add helpers for exporting current-limit through a psy Hans de Goede
2017-08-06 14:13   ` Guenter Roeck
2017-08-06 14:21     ` Hans de Goede
2017-08-06 14:41       ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 05/18] staging: typec: fusb302: Set max supply voltage to 5V Hans de Goede
2017-08-06 12:35 ` [PATCH 06/18] staging: typec: fusb302: Get max snk mv/ma/mw from device-properties Hans de Goede
2017-08-06 14:03   ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 07/18] staging: typec: fusb302: Use client->irq as irq if set Hans de Goede
2017-08-06 12:35 ` [PATCH 08/18] staging: typec: fusb302: Add support for USB2 charger detection through extcon Hans de Goede
2017-08-06 14:22   ` Guenter Roeck
2017-08-06 14:36     ` Hans de Goede
2017-08-06 14:58       ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 09/18] staging: typec: fusb302: Use tcpm_set_current_limit_psy Hans de Goede
2017-08-06 14:24   ` Guenter Roeck
2017-08-06 12:35 ` [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede
2017-08-06 14:30   ` Guenter Roeck
2017-08-06 14:52     ` Hans de Goede
2017-08-06 15:20       ` Guenter Roeck
2017-08-06 15:44     ` Hans de Goede
2017-08-07 11:10       ` Mark Brown
2017-08-07 14:41         ` Hans de Goede
2017-08-07 15:41           ` Mark Brown
2017-08-07 19:20             ` Hans de Goede
2017-08-08  9:39               ` Mark Brown
     [not found]                 ` <0b75c318-0f71-c536-7c7f-9ba16b215690@redhat.com>
     [not found]                   ` <20170808144217.c2fm25uge75p4lo2@sirena.org.uk>
2017-08-08 20:53                     ` Hans de Goede
2017-08-06 12:35 ` [PATCH 11/18] power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate Hans de Goede
2017-08-06 14:31   ` Guenter Roeck
2017-08-06 14:54     ` Hans de Goede
2017-08-06 12:35 ` [PATCH 12/18] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede
2017-08-06 12:35 ` Hans de Goede [this message]
2017-08-08  4:15   ` [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Tony Lindgren
2017-08-08  8:39   ` Liam Breck
2017-08-08  9:00     ` Hans de Goede
2017-08-08 18:57       ` Liam Breck
2017-08-08 21:09         ` Hans de Goede
2017-08-06 12:35 ` [PATCH 14/18] power: supply: bq24190_charger: Add input_current_limit property Hans de Goede
2017-08-06 12:35 ` [PATCH 15/18] power: supply: bq24190_charger: Get input_current_limit from our supplier Hans de Goede
2017-08-08  8:24   ` Liam Breck
2017-08-08  9:11     ` Hans de Goede
2017-08-06 12:35 ` [PATCH 16/18] power: supply: bq24190_charger: Remove extcon handling Hans de Goede
2017-08-08  8:27   ` Liam Breck
2017-08-08  9:12     ` Hans de Goede
2017-08-06 12:35 ` [PATCH 17/18] platform/x86: intel_cht_int33fe Update fusb302 type string, add properties Hans de Goede
2017-08-06 12:35 ` [PATCH 18/18] i2c-cht-wc: Add device-properties for fusb302 integration Hans de Goede
2017-08-06 14:35   ` Guenter Roeck
2017-08-06 15:05     ` Hans de Goede
2017-08-06 16:29       ` Andy Shevchenko

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=20170806123555.5124-14-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andy@infradead.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=dvhart@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=liam@networkimprov.net \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=tony@atomide.com \
    --cc=wsa@the-dreams.de \
    /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).