From patchwork Mon Jul 7 10:34:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 33141 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A11A820969 for ; Mon, 7 Jul 2014 10:35:24 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id w8sf13256903qac.8 for ; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=//Ei/s3Fcq6Pd1f5TjpWOtvwuvjvFNX1IrkjuOgDEmg=; b=QY4+HqcG3BVgyqbUfvLzObW8B5JXzpdncdbfCau5xCSLty4pa85jFptgmti9FBx8+s 6whZw/8ZwdkJbBGeKa9rDycXoEq+yRrJKLBrasKF3mhUw/JqgWy9Ck5ZIW9jd+FcQKTA CUmsTQSSqN+Bc6aKlnykFnxIEIU4Elez1bzXYJgsSYq++zr+n28+1nivWoIEzgJa91Xk p9HVW5VlH+9KH4XM9+mgVegomARUWQRaPq/SNgQzZDM8Ru4SeYihW5/S4WynNSOcHrFx aTtE1TJVO/LOdGuwS7ej6DrT58a30FSjb55rgO+ADF9FoXbIpCHZ41EsiizQQdXx3F50 OhSQ== X-Gm-Message-State: ALoCoQlQRud7bYEOxJIZRqN7U5+cxLr9H/3C+nWxYyAe7jXaViF108554x97bQv9gtPNgbM0hYHa X-Received: by 10.58.41.99 with SMTP id e3mr13009010vel.20.1404729324725; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.50 with SMTP id i47ls1699107qgd.38.gmail; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr10174413vdc.40.1404729324640; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id jb7si18592510vdb.11.2014.07.07.03.35.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 03:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so3916224veb.28 for ; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) X-Received: by 10.58.247.167 with SMTP id yf7mr2382866vec.46.1404729324554; Mon, 07 Jul 2014 03:35:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp655372vcb; Mon, 7 Jul 2014 03:35:24 -0700 (PDT) X-Received: by 10.69.26.103 with SMTP id ix7mr27821634pbd.41.1404729323527; Mon, 07 Jul 2014 03:35:23 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yl3si40770583pbb.96.2014.07.07.03.35.22; Mon, 07 Jul 2014 03:35:22 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752486AbaGGKfM (ORCPT + 27 others); Mon, 7 Jul 2014 06:35:12 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:58745 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751913AbaGGKfJ (ORCPT ); Mon, 7 Jul 2014 06:35:09 -0400 Received: by mail-wi0-f176.google.com with SMTP id n3so15691210wiv.9 for ; Mon, 07 Jul 2014 03:35:06 -0700 (PDT) X-Received: by 10.194.71.161 with SMTP id w1mr3109373wju.51.1404729306886; Mon, 07 Jul 2014 03:35:06 -0700 (PDT) Received: from localhost.localdomain (LPuteaux-656-01-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPSA id ft2sm104611906wib.1.2014.07.07.03.35.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jul 2014 03:35:06 -0700 (PDT) From: Linus Walleij To: Dmitry Eremin-Solenikov , linux-kernel@vger.kernel.org Cc: David Woodhouse , Linus Walleij , Alexandre Courbot Subject: [PATCH v2] power: poweroff: gpio: convert to use descriptors Date: Mon, 7 Jul 2014 12:34:32 +0200 Message-Id: <1404729272-17873-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This switches the GPIO poweroff driver to use GPIO descriptors rather than numeral GPIOs. We get rid of the specific inversion handling as GPIO descriptors know if they are active low or high and can assert the line properly, so we do not need to check the flag OF_GPIO_ACTIVE_LOW returned from the old call of_get_gpio_flags() anymore. Also convert to use managed resources and use dev_* message printing while we're at it. Cc: Alexandre Courbot Signed-off-by: Linus Walleij Reviewed-by: Alexandre Courbot --- ChangeLog v1->v2: - Handled errors from devm_gpiod_get() properly with IS_ERR() and friends (Alexandre's review comment). --- drivers/power/reset/gpio-poweroff.c | 52 ++++++++++++++----------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c index e290d48ddd99..ce849bc9b269 100644 --- a/drivers/power/reset/gpio-poweroff.c +++ b/drivers/power/reset/gpio-poweroff.c @@ -15,31 +15,29 @@ #include #include #include -#include +#include #include -#include #include /* * Hold configuration here, cannot be more than one instance of the driver * since pm_power_off itself is global. */ -static int gpio_num = -1; -static int gpio_active_low; +static struct gpio_desc *reset_gpio; static void gpio_poweroff_do_poweroff(void) { - BUG_ON(!gpio_is_valid(gpio_num)); + BUG_ON(!reset_gpio); /* drive it active, also inactive->active edge */ - gpio_direction_output(gpio_num, !gpio_active_low); + gpiod_direction_output(reset_gpio, 1); mdelay(100); /* drive inactive, also active->inactive edge */ - gpio_set_value(gpio_num, gpio_active_low); + gpiod_set_value(reset_gpio, 0); mdelay(100); /* drive it active, also inactive->active edge */ - gpio_set_value(gpio_num, !gpio_active_low); + gpiod_set_value(reset_gpio, 1); /* give it some time */ mdelay(3000); @@ -49,54 +47,42 @@ static void gpio_poweroff_do_poweroff(void) static int gpio_poweroff_probe(struct platform_device *pdev) { - enum of_gpio_flags flags; bool input = false; - int ret; /* If a pm_power_off function has already been added, leave it alone */ if (pm_power_off != NULL) { - pr_err("%s: pm_power_off function already registered", + dev_err(&pdev->dev, + "%s: pm_power_off function already registered", __func__); return -EBUSY; } - gpio_num = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); - if (!gpio_is_valid(gpio_num)) - return gpio_num; - - gpio_active_low = flags & OF_GPIO_ACTIVE_LOW; + reset_gpio = devm_gpiod_get(&pdev->dev, NULL); + if (IS_ERR(reset_gpio)) + return PTR_ERR(reset_gpio); input = of_property_read_bool(pdev->dev.of_node, "input"); - ret = gpio_request(gpio_num, "poweroff-gpio"); - if (ret) { - pr_err("%s: Could not get GPIO %d", __func__, gpio_num); - return ret; - } if (input) { - if (gpio_direction_input(gpio_num)) { - pr_err("Could not set direction of GPIO %d to input", - gpio_num); - goto err; + if (gpiod_direction_input(reset_gpio)) { + dev_err(&pdev->dev, + "Could not set direction of reset GPIO to input\n"); + return -ENODEV; } } else { - if (gpio_direction_output(gpio_num, gpio_active_low)) { - pr_err("Could not set direction of GPIO %d", gpio_num); - goto err; + if (gpiod_direction_output(reset_gpio, 0)) { + dev_err(&pdev->dev, + "Could not set direction of reset GPIO\n"); + return -ENODEV; } } pm_power_off = &gpio_poweroff_do_poweroff; return 0; - -err: - gpio_free(gpio_num); - return -ENODEV; } static int gpio_poweroff_remove(struct platform_device *pdev) { - gpio_free(gpio_num); if (pm_power_off == &gpio_poweroff_do_poweroff) pm_power_off = NULL;