From patchwork Fri Jun 24 02:26:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chris@lapa.com.au X-Patchwork-Id: 9196411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DFD960871 for ; Fri, 24 Jun 2016 02:27:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E9842847E for ; Fri, 24 Jun 2016 02:27:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 731D528485; Fri, 24 Jun 2016 02:27:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0C7C2847E for ; Fri, 24 Jun 2016 02:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752258AbcFXC0p (ORCPT ); Thu, 23 Jun 2016 22:26:45 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34402 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752093AbcFXC0n (ORCPT ); Thu, 23 Jun 2016 22:26:43 -0400 Received: by mail-pf0-f196.google.com with SMTP id 66so7995735pfy.1 for ; Thu, 23 Jun 2016 19:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lapa-com-au.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=bZ+HLwar0Ys4tsCWhcfgumteVtys7MqK99XWtzexCj8=; b=iNy8Hk4hlY1KAgolD9wR5yoscnTJz+RUdsqmq2G4J+2BUIh4AtDaxAh1vOqA5Y6E8e 33oH/8GS2WagR9WZEWOmWTUO8WRpqwjuF/6X8GrSBPNx2bSyiDwDhUHY3aJX5/jHEFOc a4a09WUWt2YyHosMg9ou/MXq/KG1ThHWm4nkUPdlXpXfMwun1BEwm/vlw5UDK0rNS3QG fbbXLz5L5+8Vj3iIC4eChpPNdWwV12G9l2IbmdhFsYFX25yK9SAOIeQl80ln++4bgjFb W4Vcnw0nHtasOZizvnAZmeYZfUQZKCMsHvz+h63JanO2jKz0C8zINCWdeCmS03t10qEs B2Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=bZ+HLwar0Ys4tsCWhcfgumteVtys7MqK99XWtzexCj8=; b=iXqdHgFimho5Wxwi246kECSYlkonQAAq3g45+PZFer+D0rJtj5C7q2lJDpyBZBppMv r91RSf08gN0UcuJ5qwlIBTlOblI/86R20LcrRp+ChclCzObLLe6iHZvp/8wVvF9Ih9A4 Id7786eENdckJKilKphRddhUmRsNRw3YECvs/SEZEz5JRptgGF3VLjCZg8Z4kQ5kbMLp EjMSEX4xmNosLhTWMnYnITczu9XzQ/8DwyFRwzvDiRdCCK2ofctLCDM/tHX0qhcdKHrT uta7H9tiLRRtIuUN9Xt+JbBbwztCE5JHCPDibbLZ1dTns6roSOy7jxCTCFS6xNgiIBu8 m4WA== X-Gm-Message-State: ALyK8tIff8qlHngz4QKZjTuvMqSQm5533OF9UN5AXF+mZtjJIb+q8zB3rzmJFobVrL2CkA== X-Received: by 10.98.12.22 with SMTP id u22mr2867438pfi.80.1466735203123; Thu, 23 Jun 2016 19:26:43 -0700 (PDT) Received: from bbb-dev.management.cpd (163.164.70.115.static.exetel.com.au. [115.70.164.163]) by smtp.gmail.com with ESMTPSA id y63sm3094614pfb.13.2016.06.23.19.26.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2016 19:26:42 -0700 (PDT) From: Chris Lapa X-Google-Original-From: Chris Lapa To: k.kozlowski@samsung.com, dwmw2@infradead.org, dbaryshkov@gmail.com, sre@kernel.org, mark.rutland@arm.com, robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Chris Lapa Subject: [PATCH v5 5/7] max8903: removes non zero validity checks on gpios. Date: Fri, 24 Jun 2016 12:26:10 +1000 Message-Id: <1466735172-13372-6-git-send-email-chris@cpdesign.com.au> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466735172-13372-1-git-send-email-chris@cpdesign.com.au> References: <1464849897-21527-3-git-send-email-chris@lapa.com.au> <1466735172-13372-1-git-send-email-chris@cpdesign.com.au> In-Reply-To: <1464849897-21527-3-git-send-email-chris@lapa.com.au> References: <1464849897-21527-3-git-send-email-chris@lapa.com.au> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Lapa Prior to this commit a zero gpio was treated as invalid. Whereas gpio_is_valid() will treat a zero gpio as valid. This commit removes the confusion and explicitly uses gpio_is_valid() throughout. Which in turn results in several of the error messages becoming redundant and thus removed. Signed-off-by: Chris Lapa Reviewed-by: Krzysztof Kozlowski --- drivers/power/max8903_charger.c | 115 ++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 68 deletions(-) diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c index 3f35593..643a87a 100644 --- a/drivers/power/max8903_charger.c +++ b/drivers/power/max8903_charger.c @@ -53,7 +53,7 @@ static int max8903_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_STATUS: val->intval = POWER_SUPPLY_STATUS_UNKNOWN; - if (data->pdata->chg) { + if (gpio_is_valid(data->pdata->chg)) { if (gpio_get_value(data->pdata->chg) == 0) val->intval = POWER_SUPPLY_STATUS_CHARGING; else if (data->usb_in || data->ta_in) @@ -93,11 +93,11 @@ static irqreturn_t max8903_dcin(int irq, void *_data) data->ta_in = ta_in; /* Set Current-Limit-Mode 1:DC 0:USB */ - if (pdata->dcm) + if (gpio_is_valid(pdata->dcm)) gpio_set_value(pdata->dcm, ta_in ? 1 : 0); /* Charger Enable / Disable (cen is negated) */ - if (pdata->cen) + if (gpio_is_valid(pdata->cen)) gpio_set_value(pdata->cen, ta_in ? 0 : (data->usb_in ? 0 : 1)); @@ -136,7 +136,7 @@ static irqreturn_t max8903_usbin(int irq, void *_data) /* Do not touch Current-Limit-Mode */ /* Charger Enable / Disable (cen is negated) */ - if (pdata->cen) + if (gpio_is_valid(pdata->cen)) gpio_set_value(pdata->cen, usb_in ? 0 : (data->ta_in ? 0 : 1)); @@ -190,7 +190,7 @@ static int max8903_setup_gpios(struct platform_device *pdev) int usb_in = 0; if (pdata->dc_valid) { - if (pdata->dok && gpio_is_valid(pdata->dok)) { + if (gpio_is_valid(pdata->dok)) { ret = devm_gpio_request(dev, pdata->dok, data->psy_desc.name); if (ret) { @@ -208,27 +208,21 @@ static int max8903_setup_gpios(struct platform_device *pdev) } } - if (pdata->dcm) { - if (gpio_is_valid(pdata->dcm)) { - ret = devm_gpio_request(dev, pdata->dcm, - data->psy_desc.name); - if (ret) { - dev_err(dev, - "Failed GPIO request for dcm: %d err %d\n", - pdata->dcm, ret); - return ret; - } - - gpio = pdata->dcm; /* Output */ - gpio_set_value(gpio, ta_in); - } else { - dev_err(dev, "Invalid pin: dcm.\n"); - return -EINVAL; + if (gpio_is_valid(pdata->dcm)) { + ret = devm_gpio_request(dev, pdata->dcm, data->psy_desc.name); + if (ret) { + dev_err(dev, + "Failed GPIO request for dcm: %d err %d\n", + pdata->dcm, ret); + return ret; } + + gpio = pdata->dcm; /* Output */ + gpio_set_value(gpio, ta_in); } if (pdata->usb_valid) { - if (pdata->uok && gpio_is_valid(pdata->uok)) { + if (gpio_is_valid(pdata->uok)) { ret = devm_gpio_request(dev, pdata->uok, data->psy_desc.name); if (ret) { @@ -247,60 +241,45 @@ static int max8903_setup_gpios(struct platform_device *pdev) } } - if (pdata->cen) { - if (gpio_is_valid(pdata->cen)) { - ret = devm_gpio_request(dev, pdata->cen, - data->psy_desc.name); - if (ret) { - dev_err(dev, - "Failed GPIO request for cen: %d err %d\n", - pdata->cen, ret); - return ret; - } - - gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1); - } else { - dev_err(dev, "Invalid pin: cen.\n"); - return -EINVAL; + if (gpio_is_valid(pdata->cen)) { + ret = devm_gpio_request(dev, pdata->cen, data->psy_desc.name); + if (ret) { + dev_err(dev, + "Failed GPIO request for cen: %d err %d\n", + pdata->cen, ret); + return ret; } + + gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1); } - if (pdata->chg) { - if (gpio_is_valid(pdata->chg)) { - ret = devm_gpio_request(dev, pdata->chg, - data->psy_desc.name); - if (ret) { - dev_err(dev, - "Failed GPIO request for chg: %d err %d\n", - pdata->chg, ret); - return ret; - } + if (gpio_is_valid(pdata->chg)) { + ret = devm_gpio_request(dev, pdata->chg, data->psy_desc.name); + if (ret) { + dev_err(dev, + "Failed GPIO request for chg: %d err %d\n", + pdata->chg, ret); + return ret; } } - if (pdata->flt) { - if (gpio_is_valid(pdata->flt)) { - ret = devm_gpio_request(dev, pdata->flt, - data->psy_desc.name); - if (ret) { - dev_err(dev, - "Failed GPIO request for flt: %d err %d\n", - pdata->flt, ret); - return ret; - } + if (gpio_is_valid(pdata->flt)) { + ret = devm_gpio_request(dev, pdata->flt, data->psy_desc.name); + if (ret) { + dev_err(dev, + "Failed GPIO request for flt: %d err %d\n", + pdata->flt, ret); + return ret; } } - if (pdata->usus) { - if (gpio_is_valid(pdata->usus)) { - ret = devm_gpio_request(dev, pdata->usus, - data->psy_desc.name); - if (ret) { - dev_err(dev, - "Failed GPIO request for usus: %d err %d\n", - pdata->usus, ret); - return ret; - } + if (gpio_is_valid(pdata->usus)) { + ret = devm_gpio_request(dev, pdata->usus, data->psy_desc.name); + if (ret) { + dev_err(dev, + "Failed GPIO request for usus: %d err %d\n", + pdata->usus, ret); + return ret; } } @@ -385,7 +364,7 @@ static int max8903_probe(struct platform_device *pdev) } } - if (pdata->flt) { + if (gpio_is_valid(pdata->flt)) { ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->flt), NULL, max8903_fault, IRQF_TRIGGER_FALLING |