Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp690860img; Tue, 26 Feb 2019 07:04:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IYvo8c1sRUoIclFQ3NwrjqsPm7zxx+DAcIwgeV5TbMxBYYFjL6m0CI+jjxHqUjP1kztnPyl X-Received: by 2002:a65:5c41:: with SMTP id v1mr20350409pgr.404.1551193490481; Tue, 26 Feb 2019 07:04:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551193490; cv=none; d=google.com; s=arc-20160816; b=dDL1eWu15y8i/k5RWcLr15iQPedU8l5DTyEI7XDeskpyZdQk35IXpD94GClk5f1rTQ NWw1Vzn9aQ+fZmmyjAI1zvLPe2+TtjBgmzx6m68qbDigdDvLk5cFztL+x42j8iZ6rlYF cC1HqBLhrtjK0KEKInqsVvP65/VojrLYsa+jmSiEOo9FAV95aYbHGpWhri2BKQijRslB WxiBSYy+MdR9gwbakvP6Q7wKaUBk+VH6PIUiQMYA2yw3e1PncfXCDHL25tBdLG0nYNc1 fYL2nZOGii34yAY35vY9b8RmKdcjd62gsW103R/fg7QTKhsXDAqOaMLgsdtOOQBLq5Vo pXEw== 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=BQwlHrwzp1RLOrIC4DA7URUNC5oz5RRHra4ENzZfAWs=; b=Jld1TyW93FTQ1XutViB2r5pGAYqiD1ITX/7+ZfLJQAbVKcwVDbbdXdQ8yC6ETy6L8d LKj9XSl31duEnfvjDAUBpeAZxuesQCTfKv6F0v9HhbB7eq1vC0ENy5Eovf7XverQ2enF 0XqygAsMTaFpf/L9VWWCGVuXiFZKvx29Qgfdu76eGe116F/KaIHtYn7xaj/5Q4bnAmcn ihRwMh901D0PUFh9SLk1Ec4CBwLyqBHLRysZo+mzHvNaIetJALQc+lxoNMMhsjJkEG5H U8EOknSUhodCZE9q8u3QYEEYp9Mqh4qUdh8Zr8DBA2hmIFfDUO4ZTevkYc388ZqgRmeS DCgw== 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 s143si2411881pgs.411.2019.02.26.07.04.34; Tue, 26 Feb 2019 07:04:50 -0800 (PST) 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 S1727801AbfBZPEL (ORCPT + 99 others); Tue, 26 Feb 2019 10:04:11 -0500 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:55875 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbfBZPEL (ORCPT ); Tue, 26 Feb 2019 10:04:11 -0500 X-Originating-IP: 91.192.165.7 Received: from pc.localdomain (unknown [91.192.165.7]) (Authenticated sender: contact@artur-rojek.eu) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 0633B240003; Tue, 26 Feb 2019 15:04:06 +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 v2 2/2] power: supply: gpio-charger: Add support for charger status. Date: Tue, 26 Feb 2019 16:04:37 +0100 Message-Id: <20190226150437.3704-2-contact@artur-rojek.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190226150437.3704-1-contact@artur-rojek.eu> References: <20190226150437.3704-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 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.21.0