Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1712460
| From | Hans de Goede <hdegoede@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 09/14] power: supply: bq24190_charger: Export 5V boost converter as regulator |
| Date | 2017-08-15 22:10 +0200 |
| Message-ID | <ueQk4-5RL-49@gated-at.bofh.it> (permalink) |
| References | <ueQk1-5RL-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Register the 5V boost converter as a regulator named "usb_otg_vbus".
This commit also adds support for bq24190_platform_data, through which
non device-tree platforms can pass the regulator_init_data (containing
mappings for the consumer amongst other things).
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Use "usb_otg_vbus" as default name for the regulator
-Add support for passing regulator_init_data for non device-tree platforms
-Register the regulator later, to avoid it showing up and shortly later
disappearing again on probe errors (e.g. -EPROBE_DEFER).
---
drivers/power/supply/bq24190_charger.c | 126 +++++++++++++++++++++++++++++++++
include/linux/power/bq24190_charger.h | 18 +++++
2 files changed, 144 insertions(+)
create mode 100644 include/linux/power/bq24190_charger.h
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index d5a707e..073cd9d 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -16,6 +16,9 @@
#include <linux/of_device.h>
#include <linux/pm_runtime.h>
#include <linux/power_supply.h>
+#include <linux/power/bq24190_charger.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 +507,125 @@ 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 = "usb_otg_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 bq24190_platform_data *pdata = bdi->dev->platform_data;
+ struct regulator_config cfg = { };
+ struct regulator_dev *reg;
+ int ret = 0;
+
+ cfg.dev = bdi->dev;
+ if (pdata && pdata->regulator_init_data)
+ cfg.init_data = pdata->regulator_init_data;
+ else
+ 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
@@ -1577,6 +1699,10 @@ static int bq24190_probe(struct i2c_client *client,
goto out_sysfs;
}
+ ret = bq24190_register_vbus_regulator(bdi);
+ if (ret < 0)
+ goto out_sysfs;
+
if (bdi->extcon) {
INIT_DELAYED_WORK(&bdi->extcon_work, bq24190_extcon_work);
bdi->extcon_nb.notifier_call = bq24190_extcon_event;
diff --git a/include/linux/power/bq24190_charger.h b/include/linux/power/bq24190_charger.h
new file mode 100644
index 0000000..45ce7f1
--- /dev/null
+++ b/include/linux/power/bq24190_charger.h
@@ -0,0 +1,18 @@
+/*
+ * Platform data for the TI bq24190 battery charger driver.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _BQ24190_CHARGER_H_
+#define _BQ24190_CHARGER_H_
+
+#include <linux/regulator/machine.h>
+
+struct bq24190_platform_data {
+ const struct regulator_init_data *regulator_init_data;
+};
+
+#endif
--
2.9.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 00/14] Hookup typec power-negotation to the PMIC and charger Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
[PATCH v2 11/14] power: supply: bq24190_charger: Get input_current_limit from our supplier Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
Re: [PATCH v2 11/14] power: supply: bq24190_charger: Get input_current_limit from our supplier Liam Breck <liam@networkimprov.net> - 2017-08-16 22:30 +0200
[PATCH v2 09/14] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
[PATCH v2 06/14] staging: typec: fusb302: Add support for USB2 charger detection through extcon Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
[PATCH v2 02/14] staging: typec: tcpm: Add get_current_limit tcpc_dev callback Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
Re: [PATCH v2 02/14] staging: typec: tcpm: Add get_current_limit tcpc_dev callback Guenter Roeck <linux@roeck-us.net> - 2017-08-16 17:20 +0200
[PATCH v2 12/14] power: supply: bq24190_charger: Remove extcon handling Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
[PATCH v2 08/14] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
Re: [PATCH v2 08/14] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Tony Lindgren <tony@atomide.com> - 2017-08-16 18:00 +0200
Re: [PATCH v2 08/14] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede <hdegoede@redhat.com> - 2017-08-16 19:40 +0200
Re: [PATCH v2 08/14] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Tony Lindgren <tony@atomide.com> - 2017-08-16 21:30 +0200
[PATCH v2 01/14] i2c: Allow overriding dev_name through board_info Hans de Goede <hdegoede@redhat.com> - 2017-08-15 22:10 +0200
csiph-web