From patchwork Tue Nov 25 09:31:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rojhalat Ibrahim X-Patchwork-Id: 414350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2B4261401B1 for ; Tue, 25 Nov 2014 20:31:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750913AbaKYJb2 (ORCPT ); Tue, 25 Nov 2014 04:31:28 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:42737 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbaKYJb0 (ORCPT ); Tue, 25 Nov 2014 04:31:26 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3jn0NS4Y2Zz3hjQg; Tue, 25 Nov 2014 10:31:19 +0100 (CET) Received: from mail.dmz.schenk (host-82-135-47-202.customer.m-online.net [82.135.47.202]) by mail.mnet-online.de (Postfix) with ESMTP id 3jn0NR28RTzvh3f; Tue, 25 Nov 2014 10:31:19 +0100 (CET) Received: from gwhaus.rt.schenk (gwhaus.rt.schenk [172.22.0.4]) by mail.dmz.schenk (Postfix) with SMTP id 079DD1C0529; Tue, 25 Nov 2014 10:31:19 +0100 (CET) Received: from pcimr.localnet (pcimr.rt.schenk [172.22.10.20]) by gwhaus.rt.schenk (Postfix) with ESMTP id D4E862405B6; Tue, 25 Nov 2014 10:31:18 +0100 (CET) From: Rojhalat Ibrahim To: "linux-gpio@vger.kernel.org" , netdev@vger.kernel.org Cc: Linus Walleij , Alexandre Courbot , David Miller , Florian Fainelli , David Daney Subject: [PATCH][v2] mdio-mux-gpio: Use GPIO descriptor interface and new gpiod_set_array function Date: Tue, 25 Nov 2014 10:31:18 +0100 Message-ID: <2814617.OrXEO01vgP@pcimr> User-Agent: KMail/4.12.5 (Linux/3.13.6; KDE/4.12.5; x86_64; ; ) MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Convert mdio-mux-gpio to the GPIO descriptor interface and use the new gpiod_set_array function to set all output signals simultaneously. Signed-off-by: Rojhalat Ibrahim Acked-by: David S. Miller --- This patch depends on the gpiod_set_array function, which is available in the linux-gpio devel tree. v2: fix gpiod_get_index usage drivers/net/phy/mdio-mux-gpio.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index 0966951..1167c5b 100644 --- a/drivers/net/phy/mdio-mux-gpio.c +++ b/drivers/net/phy/mdio-mux-gpio.c @@ -14,13 +14,13 @@ #include #include -#define DRV_VERSION "1.0" +#define DRV_VERSION "1.1" #define DRV_DESCRIPTION "GPIO controlled MDIO bus multiplexer driver" #define MDIO_MUX_GPIO_MAX_BITS 8 struct mdio_mux_gpio_state { - int gpio[MDIO_MUX_GPIO_MAX_BITS]; + struct gpio_desc *gpio[MDIO_MUX_GPIO_MAX_BITS]; unsigned int num_gpios; void *mux_handle; }; @@ -28,29 +28,23 @@ struct mdio_mux_gpio_state { static int mdio_mux_gpio_switch_fn(int current_child, int desired_child, void *data) { - int change; + int values[MDIO_MUX_GPIO_MAX_BITS]; unsigned int n; struct mdio_mux_gpio_state *s = data; if (current_child == desired_child) return 0; - change = current_child == -1 ? -1 : current_child ^ desired_child; - for (n = 0; n < s->num_gpios; n++) { - if (change & 1) - gpio_set_value_cansleep(s->gpio[n], - (desired_child & 1) != 0); - change >>= 1; - desired_child >>= 1; + values[n] = (desired_child >> n) & 1; } + gpiod_set_array_cansleep(s->num_gpios, s->gpio, values); return 0; } static int mdio_mux_gpio_probe(struct platform_device *pdev) { - enum of_gpio_flags f; struct mdio_mux_gpio_state *s; int num_gpios; unsigned int n; @@ -70,22 +64,14 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev) s->num_gpios = num_gpios; for (n = 0; n < num_gpios; ) { - int gpio = of_get_gpio_flags(pdev->dev.of_node, n, &f); - if (gpio < 0) { - r = (gpio == -ENODEV) ? -EPROBE_DEFER : gpio; + struct gpio_desc *gpio = gpiod_get_index(&pdev->dev, NULL, n, + GPIOD_OUT_LOW); + if (IS_ERR(gpio)) { + r = PTR_ERR(gpio); goto err; } s->gpio[n] = gpio; - n++; - - r = gpio_request(gpio, "mdio_mux_gpio"); - if (r) - goto err; - - r = gpio_direction_output(gpio, 0); - if (r) - goto err; } r = mdio_mux_init(&pdev->dev, @@ -98,15 +84,19 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev) err: while (n) { n--; - gpio_free(s->gpio[n]); + gpiod_put(s->gpio[n]); } return r; } static int mdio_mux_gpio_remove(struct platform_device *pdev) { + unsigned int n; struct mdio_mux_gpio_state *s = dev_get_platdata(&pdev->dev); mdio_mux_uninit(s->mux_handle); + for (n = 0; n < s->num_gpios; n++) { + gpiod_put(s->gpio[n]); + } return 0; }