Linux Power Management development
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
To: Hans de Goede <hdegoede@redhat.com>
Cc: devel@driverdev.osuosl.org,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	Tony Lindgren <tony@atomide.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org,
	Liam Breck <liam@networkimprov.net>,
	Guenter Roeck <linux@roeck-us.net>,
	Darren Hart <dvhart@infradead.org>,
	Andy Shevchenko <andy@infradead.org>,
	linux-i2c@vger.kernel.org
Subject: Re: [PATCH v2 09/14] power: supply: bq24190_charger: Export 5V boost converter as regulator
Date: Tue, 29 Aug 2017 13:28:42 +0200	[thread overview]
Message-ID: <20170829112842.lvkzig6uwky6gjk5@earth> (raw)
In-Reply-To: <20170815200502.17339-10-hdegoede@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 6711 bytes --]

Hi,

On Tue, Aug 15, 2017 at 10:04:57PM +0200, Hans de Goede wrote:
> 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;
> +}

Let's reduce code duplication:

static int bq24190_vbus_set(dev, val) {
    ...
}

static int bq24190_vbus_enable(dev) {
    return bq24190_vbus_set(dev, BQ24190_REG_POC_CHG_CONFIG_OTG);
}

static int bq24190_vbus_disable(dev) {
    return bq24190_vbus_set(dev, BQ24190_REG_POC_CHG_CONFIG_CHARGE);
}

> +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
> 

Otherwise looks fine to me.

-- Sebastian

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2017-08-29 11:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 20:04 [PATCH v2 00/14] Hookup typec power-negotation to the PMIC and charger Hans de Goede
2017-08-15 20:04 ` [PATCH v2 01/14] i2c: Allow overriding dev_name through board_info Hans de Goede
2017-08-15 20:04 ` [PATCH v2 02/14] staging: typec: tcpm: Add get_current_limit tcpc_dev callback Hans de Goede
2017-08-16 15:11   ` Guenter Roeck
2017-08-15 20:04 ` [PATCH v2 03/14] staging: typec: fusb302: Set max supply voltage to 5V Hans de Goede
2017-08-15 20:04 ` [PATCH v2 04/14] staging: typec: fusb302: Get max snk mv/ma/mw from device-properties Hans de Goede
     [not found]   ` <20170815200502.17339-5-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-08-17 21:41     ` Rob Herring
2017-08-28 16:11       ` Hans de Goede
2017-08-15 20:04 ` [PATCH v2 05/14] staging: typec: fusb302: Use client->irq as irq if set Hans de Goede
2017-08-15 20:04 ` [PATCH v2 06/14] staging: typec: fusb302: Add support for USB2 charger detection through extcon Hans de Goede
2017-08-15 20:04 ` [PATCH v2 07/14] staging: typec: fusb302: Export current-limit through a power_supply class dev Hans de Goede
2017-08-15 20:04 ` [PATCH v2 08/14] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede
2017-08-16 15:54   ` Tony Lindgren
2017-08-16 17:38     ` Hans de Goede
2017-08-16 19:21       ` Tony Lindgren
2017-08-29 10:54   ` Sebastian Reichel
2017-08-15 20:04 ` [PATCH v2 09/14] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede
2017-08-29 11:28   ` Sebastian Reichel [this message]
2017-08-15 20:04 ` [PATCH v2 10/14] power: supply: bq24190_charger: Add input_current_limit property Hans de Goede
2017-08-29 11:29   ` Sebastian Reichel
2017-08-15 20:04 ` [PATCH v2 11/14] power: supply: bq24190_charger: Get input_current_limit from our supplier Hans de Goede
2017-08-16 20:28   ` Liam Breck
2017-08-28 16:04     ` Hans de Goede
2017-08-28 17:02       ` Liam Breck
2017-08-28 18:07       ` Liam Breck
2017-08-28 19:08         ` Hans de Goede
2017-08-29 11:40   ` Sebastian Reichel
2017-08-29 11:53     ` Hans de Goede
2017-08-29 12:12       ` Sebastian Reichel
2017-08-15 20:05 ` [PATCH v2 12/14] power: supply: bq24190_charger: Remove extcon handling Hans de Goede
2017-08-15 20:05 ` [PATCH v2 13/14] i2c-cht-wc: Add device-properties for fusb302 integration Hans de Goede
2017-08-15 20:05 ` [PATCH v2 14/14] platform/x86: intel_cht_int33fe: Update fusb302 type string, add properties Hans de Goede

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=20170829112842.lvkzig6uwky6gjk5@earth \
    --to=sebastian.reichel@collabora.co.uk \
    --cc=andy@infradead.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=dvhart@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --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=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