From patchwork Mon Jun 9 09:22:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 31540 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2F5620675 for ; Mon, 9 Jun 2014 09:22:21 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f73sf20158112yha.3 for ; Mon, 09 Jun 2014 02:22:21 -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=6OFefNria9z8H8R0dVPaow12Cts313uSso1wtq07cAk=; b=McUivQPAWHOixgOHC4JA3YIGg/h0ZF38mm0rGh3HilZVtpoWxlyha6ZKGJdcaUp0g4 XJ3YxJCHfhRCQ0qGXWkD87K+HfuNnLOh83TWT0EXoUoaoyF9ej4+Y4Q8PqE+AFFFKJml 2XAlFLihP0EAXZK0ePOfkVGEpd4U22v4/J6IWmoE4WCie70es6XhS9+IjKVVoP3aablf 35ds/+wF9u8JdQLhqVHNWe7HgabeG+Km+woELqKbgv2L1R2JCGDh+wvK0Z+PahRyKqQx SXILyhD3LcH1CrUM4vLLrnuCkkLTqkFo/GEhDFU1AKe4BLV17dYyEnZTLjvAIvwO2XE3 ji8w== X-Gm-Message-State: ALoCoQlcgkr62mFV6QbecYcfKXOZl2sJAQE+g+bpImtk8CB2IbZU0HKUlaqeMgWBpe+pTbN8/yzg X-Received: by 10.58.187.107 with SMTP id fr11mr13163204vec.34.1402305741645; Mon, 09 Jun 2014 02:22:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.196 with SMTP id l62ls1521307qgl.35.gmail; Mon, 09 Jun 2014 02:22:21 -0700 (PDT) X-Received: by 10.220.183.4 with SMTP id ce4mr606799vcb.54.1402305741497; Mon, 09 Jun 2014 02:22:21 -0700 (PDT) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id zc15si11618764vdb.79.2014.06.09.02.22.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 09 Jun 2014 02:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.176 as permitted sender) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id db12so3203409veb.7 for ; Mon, 09 Jun 2014 02:22:21 -0700 (PDT) X-Received: by 10.220.163.3 with SMTP id y3mr24837220vcx.7.1402305741425; Mon, 09 Jun 2014 02:22:21 -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.54.6 with SMTP id vs6csp127989vcb; Mon, 9 Jun 2014 02:22:21 -0700 (PDT) X-Received: by 10.68.201.226 with SMTP id kd2mr2177959pbc.157.1402305740646; Mon, 09 Jun 2014 02:22:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oq10si1683313pac.48.2014.06.09.02.22.20; Mon, 09 Jun 2014 02:22:20 -0700 (PDT) Received-SPF: none (google.com: linux-gpio-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 S936192AbaFIJWT (ORCPT + 1 other); Mon, 9 Jun 2014 05:22:19 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:56792 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936175AbaFIJWR (ORCPT ); Mon, 9 Jun 2014 05:22:17 -0400 Received: by mail-wg0-f44.google.com with SMTP id x13so2740042wgg.15 for ; Mon, 09 Jun 2014 02:22:16 -0700 (PDT) X-Received: by 10.180.183.131 with SMTP id em3mr18466480wic.56.1402305736562; Mon, 09 Jun 2014 02:22:16 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id bq7sm9047799wib.7.2014.06.09.02.22.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jun 2014 02:22:15 -0700 (PDT) From: Linus Walleij To: Dmitry Eremin-Solenikov , linux-kernel@vger.kernel.org Cc: David Woodhouse , linux-gpio@vger.kernel.org, Linus Walleij , Alexandre Courbot Subject: [PATCH] power: poweroff: gpio: convert to use descriptors Date: Mon, 9 Jun 2014 11:22:08 +0200 Message-Id: <1402305728-2155-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@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.176 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 --- 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..41e1594589d5 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 (!reset_gpio) + return -ENODEV; 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;