Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1723368

Re: [PATCH v3 07/11] staging: typec: fusb302: Export current-limit through a power_supply class dev

Path csiph.com!goblin1!goblin.stu.neva.ru!border1.nntp.ams1.giganews.com!nntp.giganews.com!feeds.phibee-telecom.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Guenter Roeck <linux@roeck-us.net>
Newsgroups linux.kernel
Subject Re: [PATCH v3 07/11] staging: typec: fusb302: Export current-limit through a power_supply class dev
Date Wed, 30 Aug 2017 16:10:03 +0200
Message-ID <ukbQT-R3-41@gated-at.bofh.it> (permalink)
References <uk7Ng-6DT-3@gated-at.bofh.it> <uk7WW-6Hb-5@gated-at.bofh.it>
X-Original-To Hans de Goede <hdegoede@redhat.com>, 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>, Heikki Krogerus <heikki.krogerus@linux.intel.com>
Dkim-Signature v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fTIvCW5amO5gmDVGPlesYG1m3n6kd5J+MwmLLgCC+3o=; b=J6vv/Tk+1vkRq/QYNFH0lR9cTy K+vi0YXax60XyBu0Zpwj7dEiUuaPqRsCvawt4PW4jrtfuVaSmcXzhHNc901Af+Faqvlaf0XqzbJZW tu9NKbweOGTe22Klr0YeaOpUGmk7/Pp65lyuaQ5xn7pDsjTHEWQCSeVcn63/RleUv828MqK4RaYqv W8I98ctdWSPNJgPHEOmqBaEZ5RKqLP/tH3tggtKDTmSzYB4djXatLIAgGzEiOP5pdFZ+eZ1ycoUTD ke4Bw78AkV8dITewrUfm/7syB0KN+iXxr0NCtclhQ+/Dl/oK86n3fuutWMDuSJ5o67wdxzse727x1 9x/pSM0Q==;
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
MIME-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Language en-US
Content-Transfer-Encoding 8bit
X-Authenticated_Sender linux@roeck-us.net
X-Outgoing-Spam-Status No, score=-1.0
X-Antiabuse This header was added to track abuse, please include it with any abuse report
X-Antiabuse Primary Hostname - bh-25.webhostbox.net
X-Antiabuse Original Domain - vger.kernel.org
X-Antiabuse Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse Sender Address Domain - roeck-us.net
X-Get-Message-Sender-Via bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net
X-Authenticated-Sender bh-25.webhostbox.net: linux@roeck-us.net
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 162
Organization linux.* mail to news gateway
X-Original-Cc 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, "Yueyao (Nathan) Zhu" <yueyao@google.com>
X-Original-Date Wed, 30 Aug 2017 07:01:38 -0700
X-Original-Message-ID <9e20e69b-2e9d-cada-a6a6-609fe7644479@roeck-us.net>
X-Original-References <20170830094814.17758-1-hdegoede@redhat.com> <20170830094814.17758-8-hdegoede@redhat.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1723368

Show key headers only | View raw


On 08/30/2017 02:48 AM, Hans de Goede wrote:
> The fusb302 Type-C port-controller cannot control the current-limit
> directly, so we need to exported the limit so that another driver
> (e.g. the charger driver) can pick the limit up and configure the
> system accordingly.
> 
> The power-supply subsys already provides infrastructure for this,
> power-supply devices have the notion of being supplied by another
> power-supply and have properties through which we can export the
> current-limit.
> 
> Register a power_supply and export the current-limit through the
> power_supply's current-max property.
> 
> Cc: "Yueyao (Nathan) Zhu" <yueyao@google.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Changes in v2:
> -Put the psy class device code directly in fusb302.c rather then introducing
>   helpers which are only used by fusb302.c
> -Add an online property to the psy so that upower does not mistake it for a
>   second battery in the system
> ---
>   drivers/staging/typec/fusb302/Kconfig   |  2 +-
>   drivers/staging/typec/fusb302/fusb302.c | 63 +++++++++++++++++++++++++++++++--
>   2 files changed, 62 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/typec/fusb302/Kconfig b/drivers/staging/typec/fusb302/Kconfig
> index fce099ff39fe..48a4f2fcee03 100644
> --- a/drivers/staging/typec/fusb302/Kconfig
> +++ b/drivers/staging/typec/fusb302/Kconfig
> @@ -1,6 +1,6 @@
>   config TYPEC_FUSB302
>   	tristate "Fairchild FUSB302 Type-C chip driver"
> -	depends on I2C
> +	depends on I2C && POWER_SUPPLY
>   	help
>   	  The Fairchild FUSB302 Type-C chip driver that works with
>   	  Type-C Port Controller Manager to provide USB PD and USB
> diff --git a/drivers/staging/typec/fusb302/fusb302.c b/drivers/staging/typec/fusb302/fusb302.c
> index 6f007f66d597..cf6355f59cd9 100644
> --- a/drivers/staging/typec/fusb302/fusb302.c
> +++ b/drivers/staging/typec/fusb302/fusb302.c
> @@ -28,6 +28,7 @@
>   #include <linux/of_device.h>
>   #include <linux/of_gpio.h>
>   #include <linux/pinctrl/consumer.h>
> +#include <linux/power_supply.h>
>   #include <linux/proc_fs.h>
>   #include <linux/regulator/consumer.h>
>   #include <linux/sched/clock.h>
> @@ -108,6 +109,11 @@ struct fusb302_chip {
>   	/* lock for sharing chip states */
>   	struct mutex lock;
>   
> +	/* psy + psy status */
> +	struct power_supply *psy;
> +	u32 current_limit;
> +	u32 supply_voltage;
> +
>   	/* chip status */
>   	enum toggling_mode toggling_mode;
>   	enum src_current_status src_current_status;
> @@ -876,11 +882,13 @@ static int tcpm_set_vbus(struct tcpc_dev *dev, bool on, bool charge)
>   		chip->vbus_on = on;
>   		fusb302_log(chip, "vbus := %s", on ? "On" : "Off");
>   	}
> -	if (chip->charge_on == charge)
> +	if (chip->charge_on == charge) {
>   		fusb302_log(chip, "charge is already %s",
>   			    charge ? "On" : "Off");
> -	else
> +	} else {
>   		chip->charge_on = charge;
> +		power_supply_changed(chip->psy);
> +	}
>   
>   done:
>   	mutex_unlock(&chip->lock);
> @@ -896,6 +904,11 @@ static int tcpm_set_current_limit(struct tcpc_dev *dev, u32 max_ma, u32 mv)
>   	fusb302_log(chip, "current limit: %d ma, %d mv (not implemented)",
>   		    max_ma, mv);
>   
> +	chip->supply_voltage = mv;
> +	chip->current_limit = max_ma;
> +
> +	power_supply_changed(chip->psy);
> +
>   	return 0;
>   }
>   
> @@ -1681,6 +1694,43 @@ static irqreturn_t fusb302_irq_intn(int irq, void *dev_id)
>   	return IRQ_HANDLED;
>   }
>   
> +static int fusb302_psy_get_property(struct power_supply *psy,
> +				    enum power_supply_property psp,
> +				    union power_supply_propval *val)
> +{
> +	struct fusb302_chip *chip = power_supply_get_drvdata(psy);
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_ONLINE:
> +		val->intval = chip->charge_on;
> +		break;
> +	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> +		val->intval = chip->supply_voltage * 1000; /* mV -> µV */
> +		break;
> +	case POWER_SUPPLY_PROP_CURRENT_MAX:
> +		val->intval = chip->current_limit * 1000; /* mA -> µA */
> +		break;
> +	default:
> +		return -ENODATA;
> +	}
> +
> +	return 0;
> +}
> +
> +static enum power_supply_property fusb302_psy_properties[] = {
> +	POWER_SUPPLY_PROP_ONLINE,
> +	POWER_SUPPLY_PROP_VOLTAGE_NOW,
> +	POWER_SUPPLY_PROP_CURRENT_MAX,
> +};
> +
> +const struct power_supply_desc fusb302_psy_desc = {
> +	.name		= "fusb302-typec-source",
> +	.type		= POWER_SUPPLY_TYPE_USB_TYPE_C,
> +	.properties	= fusb302_psy_properties,
> +	.num_properties	= ARRAY_SIZE(fusb302_psy_properties),
> +	.get_property	= fusb302_psy_get_property,
> +};
> +
>   static int init_gpio(struct fusb302_chip *chip)
>   {
>   	struct device_node *node;
> @@ -1720,6 +1770,7 @@ static int fusb302_probe(struct i2c_client *client,
>   	struct fusb302_chip *chip;
>   	struct i2c_adapter *adapter;
>   	struct device *dev = &client->dev;
> +	struct power_supply_config cfg = {};
>   	const char *name;
>   	int ret = 0;
>   	u32 v;
> @@ -1766,6 +1817,14 @@ static int fusb302_probe(struct i2c_client *client,
>   			return -EPROBE_DEFER;
>   	}
>   
> +	cfg.drv_data = chip;
> +	chip->psy = devm_power_supply_register(dev, &fusb302_psy_desc, &cfg);
> +	if (IS_ERR(chip->psy)) {
> +		ret = PTR_ERR(chip->psy);
> +		dev_err(chip->dev, "Error registering power-supply: %d\n", ret);
> +		return ret;
> +	}
> +
>   	ret = fusb302_debugfs_init(chip);
>   	if (ret < 0)
>   		return ret;
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/11] Hookup typec power-negotation to the PMIC and charger Hans de Goede <hdegoede@redhat.com> - 2017-08-30 11:50 +0200
  [PATCH v3 04/11] staging: typec: fusb302: Get max snk mv/ma/mw from device-properties Hans de Goede <hdegoede@redhat.com> - 2017-08-30 11:50 +0200
    Re: [PATCH v3 04/11] staging: typec: fusb302: Get max snk mv/ma/mw  from device-properties Guenter Roeck <linux@roeck-us.net> - 2017-08-30 16:00 +0200
  [PATCH v3 07/11] staging: typec: fusb302: Export current-limit through a power_supply class dev Hans de Goede <hdegoede@redhat.com> - 2017-08-30 12:00 +0200
    Re: [PATCH v3 07/11] staging: typec: fusb302: Export current-limit  through a power_supply class dev Guenter Roeck <linux@roeck-us.net> - 2017-08-30 16:10 +0200
  [PATCH v3 01/11] i2c: Allow overriding dev_name through board_info Hans de Goede <hdegoede@redhat.com> - 2017-08-30 12:00 +0200
  [PATCH v3 05/11] staging: typec: fusb302: Use client->irq as irq if set Hans de Goede <hdegoede@redhat.com> - 2017-08-30 12:00 +0200
    Re: [PATCH v3 05/11] staging: typec: fusb302: Use client->irq as irq  if set Guenter Roeck <linux@roeck-us.net> - 2017-08-30 16:00 +0200
  [PATCH v3 03/11] staging: typec: fusb302: Set max supply voltage to 5V Hans de Goede <hdegoede@redhat.com> - 2017-08-30 12:00 +0200
    Re: [PATCH v3 03/11] staging: typec: fusb302: Set max supply voltage  to 5V Guenter Roeck <linux@roeck-us.net> - 2017-08-30 15:40 +0200
  Re: [PATCH v3 00/11] Hookup typec power-negotation to the PMIC and  charger Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-08-31 18:30 +0200

csiph-web