Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1274006yba; Sun, 14 Apr 2019 05:39:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHOjVZhRTatbJ3ld8Cs/zcKy87X30kAi08yV85aIHKgEe80Z4IlxDP9AuKQ7ZbQiTeoaQ1 X-Received: by 2002:a17:902:6bc7:: with SMTP id m7mr21318360plt.146.1555245590410; Sun, 14 Apr 2019 05:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555245590; cv=none; d=google.com; s=arc-20160816; b=NSShuS1GG8Pr9iq53OFBcm0ehV/WsuwuSRMb47za0UyR3fz3Qe2u2QMcX4Bzt0eNWf avSp31VkykDpH1HFY+tiz4ROT4BXqGsIeSC500sPII+F1lWz+3VHbSzzf0CHKwucKuDe uKpdjxvdZ8PkhtCbs2mSiqMZjR5UsLH1JH1kNzg4/F7Bfik1YWAnusc8tTwrIWBGxkFQ yBmLWUeUELR7LNy/PhJnWO+GYIaUjLzurVSW4hlYq9AEZqzUr3apcCOTfuomV4vLV/7X 96xUR9eAt1ZPadGP7ba1Ji0xbWhGx47rnfGM2JR6YHTDnXBo7Ax9A/+H8OHfZjTFbkJy X/cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oeEeFJh/amajnvyRQ2AK7kHQ9ivmtwmBGHQ9spap6wE=; b=Z3xP38X62yuYg9qd/JN9R5cqKfhbAIDLW1Gj1/89FGI1YKriaNc08zytZbwwgAMtOg 63tMnutcZzAbI1JI2P5BxqYduqUtBsxcdJexKQo3o0//INM8176d9Mzzem7Ll3lvO3Hi 0thwmra6DYBvJGPYPbQu3A7zFVWBQDK4Q0iIL+i4EpcMmw28A5y2oawcWiCJZIWEQNUB TgTiBVhIUpiIl/bzOl0jzjrULjbRJJY625lpdhKm2/WLwtUfsu47CKKDXE467ZIKCa67 L8wQ9d+ULRMzGyRlSfELoi845sC/PUKbJHTGcNPS5i5Q5M834zORHVUR2ium9jleJQhF B2kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si38894025pga.498.2019.04.14.05.39.34; Sun, 14 Apr 2019 05:39:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbfDNMin (ORCPT + 99 others); Sun, 14 Apr 2019 08:38:43 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:52411 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbfDNMim (ORCPT ); Sun, 14 Apr 2019 08:38:42 -0400 Received: from pc.localdomain (unknown [195.189.32.242]) (Authenticated sender: contact@artur-rojek.eu) by relay12.mail.gandi.net (Postfix) with ESMTPSA id A301C200008; Sun, 14 Apr 2019 12:38:36 +0000 (UTC) From: Artur Rojek To: Sebastian Reichel , Rob Herring , Mark Rutland Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Artur Rojek Subject: [PATCH v3 2/2] power: supply: gpio-charger: Add support for charger status. Date: Sun, 14 Apr 2019 14:40:39 +0200 Message-Id: <20190414124039.10040-2-contact@artur-rojek.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190414124039.10040-1-contact@artur-rojek.eu> References: <20190414124039.10040-1-contact@artur-rojek.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce optional support of POWER_SUPPLY_PROP_STATUS for chargers which provide charging status GPIO. Signed-off-by: Artur Rojek --- Changes: v2: no change v3: rename "status_irq" and "status" fields to "charge_status_irq" and "charge_status" accordingly drivers/power/supply/gpio-charger.c | 57 +++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c index 7e4f11d5a230..f99e8f1eef23 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 charge_status_irq; bool wakeup_enabled; struct power_supply *charger; struct power_supply_desc charger_desc; struct gpio_desc *gpiod; + struct gpio_desc *charge_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->charge_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) @@ -104,8 +133,10 @@ static int gpio_charger_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct gpio_charger *gpio_charger; struct power_supply_desc *charger_desc; + struct gpio_desc *charge_status; + int charge_status_irq; unsigned long flags; - int irq, ret; + int ret; if (!pdata && !dev->of_node) { dev_err(dev, "No platform data\n"); @@ -151,9 +182,17 @@ static int gpio_charger_probe(struct platform_device *pdev) return PTR_ERR(gpio_charger->gpiod); } + charge_status = devm_gpiod_get_optional(dev, "charge-status", GPIOD_IN); + gpio_charger->charge_status = charge_status; + if (IS_ERR(gpio_charger->charge_status)) + return PTR_ERR(gpio_charger->charge_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->charge_status) + charger_desc->num_properties -= 1; charger_desc->get_property = gpio_charger_get_property; psy_cfg.of_node = dev->of_node; @@ -180,16 +219,12 @@ 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); + + charge_status_irq = gpio_charger_get_irq(dev, gpio_charger->charger, + gpio_charger->charge_status); + gpio_charger->charge_status_irq = charge_status_irq; platform_set_drvdata(pdev, gpio_charger); -- 2.21.0