From patchwork Sun Jun 19 22:27:20 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: 9186763 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 9685A60756 for ; Mon, 20 Jun 2016 07:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D9D423F88 for ; Mon, 20 Jun 2016 07:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70CA024B5E; Mon, 20 Jun 2016 07:24:45 +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=-5.2 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 C1A0923F88 for ; Mon, 20 Jun 2016 07:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752453AbcFTHYn (ORCPT ); Mon, 20 Jun 2016 03:24:43 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33978 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752434AbcFTHYl (ORCPT ); Mon, 20 Jun 2016 03:24:41 -0400 Received: by mail-pf0-f195.google.com with SMTP id 66so11010881pfy.1 for ; Mon, 20 Jun 2016 00:24:09 -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=NDTZIrqrN+z0p7zc5vzjU/9f473KhSd8I/DN1cNXG7A=; b=EUm66C42XgebJvOAO3UD3gg2Jp+AvGKhIW/hRsGZvIq+QWSrtAIbBPAzBSpyDt/Dic +8etBU7JWV2jz9H+9Z+H2GKo0UlG0dWX5WFHj5j0nnfCUNxlaVEHmwP35NNBtx0D49Q2 0NLBIbPoIp+mkKeRUCwcT/TptcdEWXI6cJGhf+xGHB2u+kgRCuOtQPLf1no/qJcViH3t RBZIYuCrQvjqoCNlhdH0sFP5nHHocP2mxlndPZkRlzji7I4BYEtz1yJEzxs0GtC8ipK4 QmUhlP9KoOFb6L99PnOVbvyV0YOTMQx4STYGkaTsKrxuJC7PeZG0PU5NLv1+NoA1csNg 4hQQ== 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=NDTZIrqrN+z0p7zc5vzjU/9f473KhSd8I/DN1cNXG7A=; b=avpDI9/OpQSfBoaiIUbI6lXI3RysUv94ujgdTfqY3GsJlBEC7xMli8y0TQslfW+6g3 xHB6lSd0NyeO1UJKyGJxbLBurQlPOC3uyRB2Sp3MFpQOrXnO8wgHndq1bbAo1LBywnos HmG5k2CbIwEP7cTFerTXkOop4/3IixLRvo4430KdcchIcVQcROIruS5bbtNcz0jfUP7X RUABsNX0VYbHIRlWJUuTCy0Ko1PxLQ7bJ6PwYPpXmtaU+Lmo8uaoCDnOZkTJ+rPC0Vyl A03Fuv3rai2eUQYPwYxVQTJZOvAu7WCAaPrxJh2hU3gO2FHuhOKX0q6G6bE5cuW+6+Js /sOg== X-Gm-Message-State: ALyK8tIjk0+4UYBGHCpMZnbFbXbUFq7BRiCYvSJCESkHz/DrSik0lFIA9ZW3O1XEat6Btg== X-Received: by 10.98.50.1 with SMTP id y1mr19958427pfy.120.1466406450926; Mon, 20 Jun 2016 00:07:30 -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 h5sm78872398pfb.81.2016.06.20.00.07.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 00:07:30 -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 v4 5/7] max8903: removes non zero validity checks on gpios. Date: Mon, 20 Jun 2016 08:27:20 +1000 Message-Id: <1466375242-38354-6-git-send-email-chris@cpdesign.com.au> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466375242-38354-1-git-send-email-chris@cpdesign.com.au> References: <1464849897-21527-3-git-send-email-chris@lapa.com.au> <1466375242-38354-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 |