devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property
@ 2019-02-05 19:03 Artur Rojek
  2019-02-05 19:03 ` [PATCH 2/2] power: supply: gpio-charger: Add support for charger status Artur Rojek
  2019-02-25 21:53 ` [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Rob Herring
  0 siblings, 2 replies; 4+ messages in thread
From: Artur Rojek @ 2019-02-05 19:03 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Mark Rutland
  Cc: linux-pm, devicetree, linux-kernel, Paul Cercueil, Artur Rojek

Add documentation for the "status-gpios" property.

Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
---
 .../devicetree/bindings/power/supply/gpio-charger.txt         | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
index adbb5dc5b6e9..b98a05a4973c 100644
--- a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
+++ b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
@@ -14,12 +14,16 @@ Required properties :
      usb-cdp (USB charging downstream port)
      usb-aca (USB accessory charger adapter)
 
+Optional properties:
+ - status-gpios: GPIO indicating the charger status
+
 Example:
 
 	usb_charger: charger {
 		compatible = "gpio-charger";
 		charger-type = "usb-sdp";
 		gpios = <&gpf0 2 0 0 0>;
+		status-gpios = <&gpf0 3 0 0 0>;
 	}
 
 	battery {
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] power: supply: gpio-charger: Add support for charger status.
  2019-02-05 19:03 [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Artur Rojek
@ 2019-02-05 19:03 ` Artur Rojek
  2019-02-25 21:53 ` [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Rob Herring
  1 sibling, 0 replies; 4+ messages in thread
From: Artur Rojek @ 2019-02-05 19:03 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Mark Rutland
  Cc: linux-pm, devicetree, linux-kernel, Paul Cercueil, Artur Rojek

Introduce optional support of POWER_SUPPLY_PROP_STATUS for chargers
which provide charging status GPIO.

Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
---
 drivers/power/supply/gpio-charger.c | 53 +++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 7e4f11d5a230..ebe986f09472 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -29,11 +29,13 @@
 
 struct gpio_charger {
 	unsigned int irq;
+	unsigned int status_irq;
 	bool wakeup_enabled;
 
 	struct power_supply *charger;
 	struct power_supply_desc charger_desc;
 	struct gpio_desc *gpiod;
+	struct gpio_desc *status;
 };
 
 static irqreturn_t gpio_charger_irq(int irq, void *devid)
@@ -59,6 +61,12 @@ static int gpio_charger_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_ONLINE:
 		val->intval = gpiod_get_value_cansleep(gpio_charger->gpiod);
 		break;
+	case POWER_SUPPLY_PROP_STATUS:
+		if (gpiod_get_value_cansleep(gpio_charger->status))
+			val->intval = POWER_SUPPLY_STATUS_CHARGING;
+		else
+			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -93,8 +101,29 @@ static enum power_supply_type gpio_charger_get_type(struct device *dev)
 	return POWER_SUPPLY_TYPE_UNKNOWN;
 }
 
+static int gpio_charger_get_irq(struct device *dev, void *dev_id,
+				struct gpio_desc *gpio)
+{
+	int ret, irq = gpiod_to_irq(gpio);
+
+	if (irq > 0) {
+		ret = devm_request_any_context_irq(dev, irq, gpio_charger_irq,
+						   IRQF_TRIGGER_RISING |
+						   IRQF_TRIGGER_FALLING,
+						   dev_name(dev),
+						   dev_id);
+		if (ret < 0) {
+			dev_warn(dev, "Failed to request irq: %d\n", ret);
+			irq = 0;
+		}
+	}
+
+	return irq;
+}
+
 static enum power_supply_property gpio_charger_properties[] = {
 	POWER_SUPPLY_PROP_ONLINE,
+	POWER_SUPPLY_PROP_STATUS /* Must always be last in the array. */
 };
 
 static int gpio_charger_probe(struct platform_device *pdev)
@@ -105,7 +134,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
 	struct gpio_charger *gpio_charger;
 	struct power_supply_desc *charger_desc;
 	unsigned long flags;
-	int irq, ret;
+	int ret;
 
 	if (!pdata && !dev->of_node) {
 		dev_err(dev, "No platform data\n");
@@ -151,9 +180,16 @@ static int gpio_charger_probe(struct platform_device *pdev)
 		return PTR_ERR(gpio_charger->gpiod);
 	}
 
+	gpio_charger->status = devm_gpiod_get_optional(dev, "status", GPIOD_IN);
+	if (IS_ERR(gpio_charger->status))
+		return PTR_ERR(gpio_charger->status);
+
 	charger_desc = &gpio_charger->charger_desc;
 	charger_desc->properties = gpio_charger_properties;
 	charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties);
+	/* Remove POWER_SUPPLY_PROP_STATUS from the supported properties. */
+	if (!gpio_charger->status)
+		charger_desc->num_properties -= 1;
 	charger_desc->get_property = gpio_charger_get_property;
 
 	psy_cfg.of_node = dev->of_node;
@@ -180,16 +216,11 @@ static int gpio_charger_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	irq = gpiod_to_irq(gpio_charger->gpiod);
-	if (irq > 0) {
-		ret = devm_request_any_context_irq(dev, irq, gpio_charger_irq,
-				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-				dev_name(dev), gpio_charger->charger);
-		if (ret < 0)
-			dev_warn(dev, "Failed to request irq: %d\n", ret);
-		else
-			gpio_charger->irq = irq;
-	}
+	gpio_charger->irq = gpio_charger_get_irq(dev, gpio_charger->charger,
+						 gpio_charger->gpiod);
+	gpio_charger->status_irq = gpio_charger_get_irq(dev,
+							gpio_charger->charger,
+							gpio_charger->status);
 
 	platform_set_drvdata(pdev, gpio_charger);
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property
  2019-02-05 19:03 [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Artur Rojek
  2019-02-05 19:03 ` [PATCH 2/2] power: supply: gpio-charger: Add support for charger status Artur Rojek
@ 2019-02-25 21:53 ` Rob Herring
  2019-02-26 14:40   ` Artur Rojek
  1 sibling, 1 reply; 4+ messages in thread
From: Rob Herring @ 2019-02-25 21:53 UTC (permalink / raw)
  To: Artur Rojek
  Cc: Sebastian Reichel, Mark Rutland, linux-pm, devicetree,
	linux-kernel, Paul Cercueil

On Tue, Feb 05, 2019 at 08:03:15PM +0100, Artur Rojek wrote:
> Add documentation for the "status-gpios" property.
> 
> Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
> ---
>  .../devicetree/bindings/power/supply/gpio-charger.txt         | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
> index adbb5dc5b6e9..b98a05a4973c 100644
> --- a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
> +++ b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
> @@ -14,12 +14,16 @@ Required properties :
>       usb-cdp (USB charging downstream port)
>       usb-aca (USB accessory charger adapter)
>  
> +Optional properties:
> + - status-gpios: GPIO indicating the charger status

So when it is asserted it has 'status'? What does status mean?

> +
>  Example:
>  
>  	usb_charger: charger {
>  		compatible = "gpio-charger";
>  		charger-type = "usb-sdp";
>  		gpios = <&gpf0 2 0 0 0>;
> +		status-gpios = <&gpf0 3 0 0 0>;

Humm, not sure what the thinking for 'gpios' was, but it's wrong and you 
just copied it. If we follow the normal cell encoding with 2 cells, this 
means the property takes 3 gpios (though the last 2 are marked not 
present with 0).

Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property
  2019-02-25 21:53 ` [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Rob Herring
@ 2019-02-26 14:40   ` Artur Rojek
  0 siblings, 0 replies; 4+ messages in thread
From: Artur Rojek @ 2019-02-26 14:40 UTC (permalink / raw)
  To: Rob Herring
  Cc: Sebastian Reichel, Mark Rutland, linux-pm, devicetree,
	linux-kernel, Paul Cercueil

Hi Rob.

Thanks for the review.

On 2019-02-25 22:53, Rob Herring wrote:
> On Tue, Feb 05, 2019 at 08:03:15PM +0100, Artur Rojek wrote:
>> Add documentation for the "status-gpios" property.
>> 
>> Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
>> ---
>>  .../devicetree/bindings/power/supply/gpio-charger.txt         | 4 
>> ++++
>>  1 file changed, 4 insertions(+)
>> 
>> diff --git 
>> a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt 
>> b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
>> index adbb5dc5b6e9..b98a05a4973c 100644
>> --- a/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
>> +++ b/Documentation/devicetree/bindings/power/supply/gpio-charger.txt
>> @@ -14,12 +14,16 @@ Required properties :
>>       usb-cdp (USB charging downstream port)
>>       usb-aca (USB accessory charger adapter)
>> 
>> +Optional properties:
>> + - status-gpios: GPIO indicating the charger status
> 
> So when it is asserted it has 'status'? What does status mean?
It is a GPIO indicating whether a battery is charging.
I shall make the description more clear.
> 
>> +
>>  Example:
>> 
>>  	usb_charger: charger {
>>  		compatible = "gpio-charger";
>>  		charger-type = "usb-sdp";
>>  		gpios = <&gpf0 2 0 0 0>;
>> +		status-gpios = <&gpf0 3 0 0 0>;
> 
> Humm, not sure what the thinking for 'gpios' was, but it's wrong and 
> you
> just copied it. If we follow the normal cell encoding with 2 cells, 
> this
> means the property takes 3 gpios (though the last 2 are marked not
> present with 0).
I will replace both of those properties with a valid example.

Artur
> 
> Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-26 14:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-05 19:03 [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Artur Rojek
2019-02-05 19:03 ` [PATCH 2/2] power: supply: gpio-charger: Add support for charger status Artur Rojek
2019-02-25 21:53 ` [PATCH 1/2] dt-bindings: power: supply: gpio-charger: Add status-gpios property Rob Herring
2019-02-26 14:40   ` Artur Rojek

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).