Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp990748imu; Fri, 11 Jan 2019 12:50:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN5KSPYDERFWcCy/STkAbQF8VeyGTGrAWELpOJ0KMUnl20ttnmqAjGFMfTVL+8M+Y9ep02F9 X-Received: by 2002:a17:902:9897:: with SMTP id s23mr15441719plp.69.1547239858749; Fri, 11 Jan 2019 12:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547239858; cv=none; d=google.com; s=arc-20160816; b=SRx+yq51WK2icXzdwQF7r37xHeWCQK53AUpD9DvvCWUVKf5kSbInrTuwt0gjPi8Nsp aUdCfHA/kwNam36TXg/KV/Yfg8rHUOfY3XDMlWwxq4Zai4fAor6/aiIVdjAciBtgd1WY 2vcDqxIGKv/95XlOG8QUFcqOzjDdLwdT2NaDfdrmfxsxUNAfATErWkAn+lWHTGYGDBWy FKxhDM2OfBB7cjjuqkT6lnIZVKS/Pvz5K/jNBB4UNPb4KG2CPKF1+6nclm/+6xogiHRZ MwamcjV/H4KFeUKTOiHyTqZ4U209cmuJube4LI7xRxa6r9WLM4rtdeQUaserngiCQrb+ a8jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+ReSD/TX9uAjWKvqhV67HQWcyyXx4iVR8ymrKAh5gzA=; b=Sjw3abOKhiupHGoMy+sF7mRX3GvNZvirKM1yIZMpoGrKnukn/UVWwJ//hlCmuzfLul uw388rbL1+A2lAWM/PwtiEcufy39hYBaRN9yd+b18tqDr2bFnMdHMFbuS00vFZzJdW6a FKDweHDsyP2hbob/2JizwwEd6nKibPm4XRGsLkUZHHup1Cf0DqpkktOsskSj9nd6e4Ax +FR2PKg/dTQpT5JwVRi51AmXWHClze7c0CkY2kElDvw1BXx4stIgYg919gJsh+uFJ76q xoZ/vRCDqaDyHv7cNoxV+EULBbhoNTc3H583kumY5Pyy7sq6uxEhL7yjNcGtEnUQnBL9 E7Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c1x3BDe9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si68132939pgs.264.2019.01.11.12.50.43; Fri, 11 Jan 2019 12:50:58 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c1x3BDe9; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731046AbfAKPiy (ORCPT + 99 others); Fri, 11 Jan 2019 10:38:54 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42854 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728632AbfAKPiy (ORCPT ); Fri, 11 Jan 2019 10:38:54 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so6449160pga.9 for ; Fri, 11 Jan 2019 07:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+ReSD/TX9uAjWKvqhV67HQWcyyXx4iVR8ymrKAh5gzA=; b=c1x3BDe9XIDVzf4d9xPu+kyRI2cUDdmWiribMP5I8kE5ukKJvNVTPU1zGXc+kRIeM8 xGRHmoCu4Yfd4iCbum+0KNFQ3+pBAnrgCfzf6otYLO1eoO1YAwMZtYNUKKyox84r42EG P2mWk0oXZnfM5qnN/Jvl455wBUvQCAKvwu9yreRh1DuiKg7CUO3qmPOvFWGJcZ6o7wU0 n9JUT//w2i3fB/9802pZUxA7yLnf+665uZmcKS2ECEptLcaj5vbOsb3gZQXQEMtMt5U1 izJt0lhtsRwMBxYJeM/Dfi7/y68vstKddbyAt85HKKfz4626PquD2r24VOcpgyAyUuHc 5oMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+ReSD/TX9uAjWKvqhV67HQWcyyXx4iVR8ymrKAh5gzA=; b=tzRiqRZ0pyJ7w60gEU7RZDbVDCkk95y936Z1YFGg4Q+wq7gg2tPWfgKmAlBv8VDTPy hKTNk1PsQ135HigOcOjnt7raUnq10imRcAg7a260zY9An+n0ad3k8uvWNr1LPqJ7h+R2 TcttDIdyaT6bIibwB54d5yUdTuuyWP4O6TpXQKXh7p389nfittwAw/BY9vnCZQaMluhR xy56d9/FGEdtJ2CftCGUtel/GpuXPV+1+ognQ4jv6yrAhBSQpFYh/tQCc+G3v14q6AC+ zK/FeXmwPunoCl8bfR8rOPmvk6KA9nBtcz8Wt4CMr14kTWRZt/qOdCdH4JzCSHdCRp0h Bg9g== X-Gm-Message-State: AJcUukd3exM0j40Un8EYWEpyRS7g6FW4AQgcOf7YLVmVysp4/FzMC0p3 kncljhCU7ljNvTmCGlODeN4= X-Received: by 2002:a63:40c6:: with SMTP id n189mr13491491pga.355.1547221132797; Fri, 11 Jan 2019 07:38:52 -0800 (PST) Received: from nishad ([106.51.25.107]) by smtp.gmail.com with ESMTPSA id h10sm107549020pgn.11.2019.01.11.07.38.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jan 2019 07:38:52 -0800 (PST) Date: Fri, 11 Jan 2019 21:08:46 +0530 From: Nishad Kamdar To: Johan Hovold Cc: Greg Kroah-Hartman , Alex Elder , Rui Miguel Silva , greybus-dev@lists.linaro.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Nishad Kamdar Subject: [PATCH v6 1/2] staging: greybus: arche-apb-ctrl.c: Switch to the gpio descriptor interface Message-ID: <9b6a9734dfa670b620acac8f70d8bf026da3405a.1547219996.git.nishadkamdar@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the gpiod interface instead of the deprecated old non-descriptor interface while continuing to ignore gpio flags from device tree in functions "deassert_reset()" and "assert_reset()" for now. Reviewed-by: Johan Hovold Signed-off-by: Nishad Kamdar --- Changes in v6: - Remove some unnecessary line breaks. Changes in v5: - Change the commit message. - Restore the names of the gpio device-tree properties without the "-gpio" suffix. Changes in v4: - Use gpiod_set_raw_value() for deassert_reset() and assert_reset() as gpiod_set_value() will change the sematics of these calls by taking any gpio flags into account. - Remove some unnecesssary line breaks. - Restore 'spi_en' gpio check in fw_flashing_seq() as it is currently optional. Changes in v3: - Add this patch in a patchset. Changes in v2: - Resolved compilation errors. --- drivers/staging/greybus/arche-apb-ctrl.c | 152 +++++++++-------------- 1 file changed, 61 insertions(+), 91 deletions(-) diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c index be5ffed90bcf..bbf3ba744fc4 100644 --- a/drivers/staging/greybus/arche-apb-ctrl.c +++ b/drivers/staging/greybus/arche-apb-ctrl.c @@ -8,9 +8,8 @@ #include #include -#include +#include #include -#include #include #include #include @@ -24,12 +23,12 @@ static void apb_bootret_deassert(struct device *dev); struct arche_apb_ctrl_drvdata { /* Control GPIO signals to and from AP <=> AP Bridges */ - int resetn_gpio; - int boot_ret_gpio; - int pwroff_gpio; - int wake_in_gpio; - int wake_out_gpio; - int pwrdn_gpio; + struct gpio_desc *resetn; + struct gpio_desc *boot_ret; + struct gpio_desc *pwroff; + struct gpio_desc *wake_in; + struct gpio_desc *wake_out; + struct gpio_desc *pwrdn; enum arche_platform_state state; bool init_disabled; @@ -37,28 +36,28 @@ struct arche_apb_ctrl_drvdata { struct regulator *vcore; struct regulator *vio; - int clk_en_gpio; + struct gpio_desc *clk_en; struct clk *clk; struct pinctrl *pinctrl; struct pinctrl_state *pin_default; /* V2: SPI Bus control */ - int spi_en_gpio; + struct gpio_desc *spi_en; bool spi_en_polarity_high; }; /* * Note that these low level api's are active high */ -static inline void deassert_reset(unsigned int gpio) +static inline void deassert_reset(struct gpio_desc *gpio) { - gpio_set_value(gpio, 1); + gpiod_set_raw_value(gpio, 1); } -static inline void assert_reset(unsigned int gpio) +static inline void assert_reset(struct gpio_desc *gpio) { - gpio_set_value(gpio, 0); + gpiod_set_raw_value(gpio, 0); } /* @@ -75,11 +74,10 @@ static int coldboot_seq(struct platform_device *pdev) return 0; /* Hold APB in reset state */ - assert_reset(apb->resetn_gpio); + assert_reset(apb->resetn); - if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && - gpio_is_valid(apb->spi_en_gpio)) - devm_gpio_free(dev, apb->spi_en_gpio); + if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en) + devm_gpiod_put(dev, apb->spi_en); /* Enable power to APB */ if (!IS_ERR(apb->vcore)) { @@ -101,13 +99,13 @@ static int coldboot_seq(struct platform_device *pdev) apb_bootret_deassert(dev); /* On DB3 clock was not mandatory */ - if (gpio_is_valid(apb->clk_en_gpio)) - gpio_set_value(apb->clk_en_gpio, 1); + if (apb->clk_en) + gpiod_set_value(apb->clk_en, 1); usleep_range(100, 200); /* deassert reset to APB : Active-low signal */ - deassert_reset(apb->resetn_gpio); + deassert_reset(apb->resetn); apb->state = ARCHE_PLATFORM_STATE_ACTIVE; @@ -136,25 +134,25 @@ static int fw_flashing_seq(struct platform_device *pdev) return ret; } - if (gpio_is_valid(apb->spi_en_gpio)) { + if (apb->spi_en) { unsigned long flags; if (apb->spi_en_polarity_high) - flags = GPIOF_OUT_INIT_HIGH; + flags = GPIOD_OUT_HIGH; else - flags = GPIOF_OUT_INIT_LOW; + flags = GPIOD_OUT_LOW; - ret = devm_gpio_request_one(dev, apb->spi_en_gpio, - flags, "apb_spi_en"); - if (ret) { - dev_err(dev, "Failed requesting SPI bus en gpio %d\n", - apb->spi_en_gpio); + apb->spi_en = devm_gpiod_get(dev, "spi-en", flags); + if (IS_ERR(apb->spi_en)) { + ret = PTR_ERR(apb->spi_en); + dev_err(dev, "Failed requesting SPI bus en GPIO: %d\n", + ret); return ret; } } /* for flashing device should be in reset state */ - assert_reset(apb->resetn_gpio); + assert_reset(apb->resetn); apb->state = ARCHE_PLATFORM_STATE_FW_FLASHING; return 0; @@ -176,9 +174,8 @@ static int standby_boot_seq(struct platform_device *pdev) apb->state == ARCHE_PLATFORM_STATE_OFF) return 0; - if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && - gpio_is_valid(apb->spi_en_gpio)) - devm_gpio_free(dev, apb->spi_en_gpio); + if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en) + devm_gpiod_put(dev, apb->spi_en); /* * As per WDM spec, do nothing @@ -201,13 +198,12 @@ static void poweroff_seq(struct platform_device *pdev) if (apb->init_disabled || apb->state == ARCHE_PLATFORM_STATE_OFF) return; - if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && - gpio_is_valid(apb->spi_en_gpio)) - devm_gpio_free(dev, apb->spi_en_gpio); + if (apb->state == ARCHE_PLATFORM_STATE_FW_FLASHING && apb->spi_en) + devm_gpiod_put(dev, apb->spi_en); /* disable the clock */ - if (gpio_is_valid(apb->clk_en_gpio)) - gpio_set_value(apb->clk_en_gpio, 0); + if (apb->clk_en) + gpiod_set_value(apb->clk_en, 0); if (!IS_ERR(apb->vcore) && regulator_is_enabled(apb->vcore) > 0) regulator_disable(apb->vcore); @@ -216,7 +212,7 @@ static void poweroff_seq(struct platform_device *pdev) regulator_disable(apb->vio); /* As part of exit, put APB back in reset state */ - assert_reset(apb->resetn_gpio); + assert_reset(apb->resetn); apb->state = ARCHE_PLATFORM_STATE_OFF; /* TODO: May have to send an event to SVC about this exit */ @@ -226,7 +222,7 @@ static void apb_bootret_deassert(struct device *dev) { struct arche_apb_ctrl_drvdata *apb = dev_get_drvdata(dev); - gpio_set_value(apb->boot_ret_gpio, 0); + gpiod_set_value(apb->boot_ret, 0); } int apb_ctrl_coldboot(struct device *dev) @@ -322,66 +318,44 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev, struct arche_apb_ctrl_drvdata *apb) { struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; int ret; - apb->resetn_gpio = of_get_named_gpio(np, "reset-gpios", 0); - if (apb->resetn_gpio < 0) { - dev_err(dev, "failed to get reset gpio\n"); - return apb->resetn_gpio; - } - ret = devm_gpio_request_one(dev, apb->resetn_gpio, - GPIOF_OUT_INIT_LOW, "apb-reset"); - if (ret) { - dev_err(dev, "Failed requesting reset gpio %d\n", - apb->resetn_gpio); + apb->resetn = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(apb->resetn)) { + ret = PTR_ERR(apb->resetn); + dev_err(dev, "Failed requesting reset GPIO: %d\n", ret); return ret; } - apb->boot_ret_gpio = of_get_named_gpio(np, "boot-ret-gpios", 0); - if (apb->boot_ret_gpio < 0) { - dev_err(dev, "failed to get boot retention gpio\n"); - return apb->boot_ret_gpio; - } - ret = devm_gpio_request_one(dev, apb->boot_ret_gpio, - GPIOF_OUT_INIT_LOW, "boot retention"); - if (ret) { - dev_err(dev, "Failed requesting bootret gpio %d\n", - apb->boot_ret_gpio); + apb->boot_ret = devm_gpiod_get(dev, "boot-ret", GPIOD_OUT_LOW); + if (IS_ERR(apb->boot_ret)) { + ret = PTR_ERR(apb->boot_ret); + dev_err(dev, "Failed requesting bootret GPIO: %d\n", ret); return ret; } /* It's not mandatory to support power management interface */ - apb->pwroff_gpio = of_get_named_gpio(np, "pwr-off-gpios", 0); - if (apb->pwroff_gpio < 0) { - dev_err(dev, "failed to get power off gpio\n"); - return apb->pwroff_gpio; - } - ret = devm_gpio_request_one(dev, apb->pwroff_gpio, - GPIOF_IN, "pwroff_n"); - if (ret) { - dev_err(dev, "Failed requesting pwroff_n gpio %d\n", - apb->pwroff_gpio); + apb->pwroff = devm_gpiod_get_optional(dev, "pwr-off", GPIOD_IN); + if (IS_ERR(apb->pwroff)) { + ret = PTR_ERR(apb->pwroff); + dev_err(dev, "Failed requesting pwroff_n GPIO: %d\n", ret); return ret; } /* Do not make clock mandatory as of now (for DB3) */ - apb->clk_en_gpio = of_get_named_gpio(np, "clock-en-gpio", 0); - if (apb->clk_en_gpio < 0) { - dev_warn(dev, "failed to get clock en gpio\n"); - } else if (gpio_is_valid(apb->clk_en_gpio)) { - ret = devm_gpio_request_one(dev, apb->clk_en_gpio, - GPIOF_OUT_INIT_LOW, "apb_clk_en"); - if (ret) { - dev_warn(dev, "Failed requesting APB clock en gpio %d\n", - apb->clk_en_gpio); - return ret; - } + apb->clk_en = devm_gpiod_get_optional(dev, "clock-en", GPIOD_OUT_LOW); + if (IS_ERR(apb->clk_en)) { + ret = PTR_ERR(apb->clk_en); + dev_err(dev, "Failed requesting APB clock en GPIO: %d\n", ret); + return ret; } - apb->pwrdn_gpio = of_get_named_gpio(np, "pwr-down-gpios", 0); - if (apb->pwrdn_gpio < 0) - dev_warn(dev, "failed to get power down gpio\n"); + apb->pwrdn = devm_gpiod_get(dev, "pwr-down", GPIOD_OUT_LOW); + if (IS_ERR(apb->pwrdn)) { + ret = PTR_ERR(apb->pwrdn); + dev_warn(dev, "Failed requesting power down GPIO: %d\n", ret); + return ret; + } /* Regulators are optional, as we may have fixed supply coming in */ apb->vcore = devm_regulator_get(dev, "vcore"); @@ -404,12 +378,8 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev, } /* Only applicable for platform >= V2 */ - apb->spi_en_gpio = of_get_named_gpio(np, "spi-en-gpio", 0); - if (apb->spi_en_gpio >= 0) { - if (of_property_read_bool(pdev->dev.of_node, - "spi-en-active-high")) - apb->spi_en_polarity_high = true; - } + if (of_property_read_bool(pdev->dev.of_node, "gb,spi-en-active-high")) + apb->spi_en_polarity_high = true; return 0; } -- 2.17.1