From patchwork Mon Feb 12 13:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 128065 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3201378ljc; Mon, 12 Feb 2018 05:18:22 -0800 (PST) X-Google-Smtp-Source: AH8x226RqQcwnjjvY/fdes5qYYSE3tvdiraZO8hS8Z5Up6gk6TESo+ZU4IHZUTxvPUP+etXQo4bC X-Received: by 2002:a17:902:e83:: with SMTP id 3-v6mr3352179plx.158.1518441502188; Mon, 12 Feb 2018 05:18:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518441502; cv=none; d=google.com; s=arc-20160816; b=LBPVGHxIy5qbZNAyXOso3gUekfe0Fep1o2IY835H1k6iHp1AE634lworPpFIRdi5hI nXBA9IR0t5oRdG2B4lw4FOTG2cYeb0w4o2DoCQJfibq7VW7qF2Btig7iKhWrUJ+704i2 qAxdPyu0bHg3NjDqOGsor1mLnBCR+Y1q2Z/NcnULzdyNABcnR1mIb9VwGb9NCiUNw0O2 jo0SXjlNyUjB++X9pfAos39Jg+WQQhzKuIT6vqjpcQ58iOmMpRDDuTPcA/IMlMwgGJPZ ljyxI1v4r0Cmxbv4BA6h6JI3YHOXodsFcj84U2snCgeOpBA+Ge3RQbPxRr3tlAe5WrQ7 k7ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=pcxLStTOo4dkY8HyqYC7WSpSk5+4mQd1pWhYFYCMwjo=; b=B8Jiwm0XXk0Sk7oxkeWMzIMFgN2g8dEMnGxyyQsOVVp/nlM2ZLob2OdM9jn8rpvrnX xcceC+2dfOdEWBbkAt3qPYI8v1tDsNBpUBtAN/oTrxtfo0lSx2qGdOeAGuHWhsFrUCqX +ffgOthsemBivASxz+GmQlf6S+MpwUjbMES8qfnQSRuxoB7RVC/LjTsd1nLp5oO9ecRX LbmIfkVDAZV9C05Zu2DlbFFQwn13fuseDfRTAJdMNUNtv5Nr6kShqPtYf+9LVskqDPKX MkN9LM/jPlP1MGeYMHaUE6VvTsRqOee1Q73YfaI3orgr2j8gjIeCCKlmIrbvtpE/6CXs TWAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kOK2PO/m; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si1217488pla.619.2018.02.12.05.18.21; Mon, 12 Feb 2018 05:18:22 -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=@linaro.org header.s=google header.b=kOK2PO/m; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935368AbeBLNSS (ORCPT + 13 others); Mon, 12 Feb 2018 08:18:18 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:40869 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933761AbeBLNSN (ORCPT ); Mon, 12 Feb 2018 08:18:13 -0500 Received: by mail-lf0-f66.google.com with SMTP id 37so1518291lfs.7 for ; Mon, 12 Feb 2018 05:18:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pcxLStTOo4dkY8HyqYC7WSpSk5+4mQd1pWhYFYCMwjo=; b=kOK2PO/mC1i0QMixbKiYYdBiJwHlvevWsYx3umNZrpXAyGkh1kFkZ4L2LyLJJWDPFH y/Lo8kMDzgzTvn2Zid8GZnWVWQPCQktpAuGSS0FhN86d47/rfGQvs1q8wkMQhqrMivSF wFPBESui7LmkvnF8Bppvk+sBELvBCw3E7LzQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pcxLStTOo4dkY8HyqYC7WSpSk5+4mQd1pWhYFYCMwjo=; b=syxIFyYnjCvw7AW9bzXcuq466F15Jk1T1XBf2svqQncU2DDF2fc4FTxSUH86yAlro8 gWGtAZqOMUfKO6FtwluA0+W/1HHkhJsctVEqkAzrVQzd/gL/HSg+Y54v3SwAHoq075Ju s9hrfHE3ZvI0+M9ZiY/kj8BjDV4AGP28jiuzYw8vKWnJOxWcL+83aFJKlKCS89u1uIDb wYu7vT/HmtGBtWCrzz6EhwBUTX11md4Jh/XU2bP5ZEuA1TLW1I6EX56eGN0D+2J1a9+2 RmXgDjiXmE5SEgvESXoEV/JPfDfJMWJYrgYYE+aufkk8RvIYVFSI9qznm2NMAqigmj1q TdCA== X-Gm-Message-State: APf1xPAJq2rHgi461qElD+yx1vaAC1gMrzwEALxwkBWg5/ioh3IpqhVC +SGIYe5KCne+jUoNPR4wsz1eBw== X-Received: by 10.46.46.14 with SMTP id u14mr7054490lju.81.1518441491903; Mon, 12 Feb 2018 05:18:11 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r88sm1584648lje.30.2018.02.12.05.18.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 05:18:11 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Linus Walleij Subject: [PATCH 20/21] regulator: gpio: Convert to fully use descriptors Date: Mon, 12 Feb 2018 14:17:16 +0100 Message-Id: <20180212131717.27193-21-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212131717.27193-1-linus.walleij@linaro.org> References: <20180212131717.27193-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This converts the GPIO regulator driver to use decriptors only. We have to let go of the array gpio handling: the fetched descriptors are handled individually anyway, and the array retrieveal function does not make it possible to retrieve each GPIO descriptor with unique flags. Instead get them one by one. Signed-off-by: Linus Walleij --- arch/arm/mach-pxa/hx4700.c | 10 +-- arch/arm/mach-pxa/magician.c | 11 +-- drivers/regulator/gpio-regulator.c | 116 +++++++++++-------------------- include/linux/regulator/gpio-regulator.h | 12 ++-- 4 files changed, 58 insertions(+), 91 deletions(-) -- 2.14.3 diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c index 05148016c620..24ba230340d8 100644 --- a/arch/arm/mach-pxa/hx4700.c +++ b/arch/arm/mach-pxa/hx4700.c @@ -700,9 +700,7 @@ static struct regulator_init_data bq24022_init_data = { .consumer_supplies = bq24022_consumers, }; -static struct gpio bq24022_gpios[] = { - { GPIO96_HX4700_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" }, -}; +static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW }; static struct gpio_regulator_state bq24022_states[] = { { .value = 100000, .gpios = (0 << 0) }, @@ -714,8 +712,8 @@ static struct gpio_regulator_config bq24022_info = { .enabled_at_boot = 0, - .gpios = bq24022_gpios, - .nr_gpios = ARRAY_SIZE(bq24022_gpios), + .gflags = bq24022_gpiod_gflags, + .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags), .states = bq24022_states, .nr_states = ARRAY_SIZE(bq24022_states), @@ -735,6 +733,8 @@ static struct platform_device bq24022 = { static struct gpiod_lookup_table bq24022_gpiod_table = { .dev_id = "gpio-regulator", .table = { + GPIO_LOOKUP("gpio-pxa", GPIO96_HX4700_BQ24022_ISET2, + NULL, GPIO_ACTIVE_HIGH), GPIO_LOOKUP("gpio-pxa", GPIO72_HX4700_BQ24022_nCHARGE_EN, "enable", GPIO_ACTIVE_LOW), { }, diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c index fab63c52d50e..5d21de79135b 100644 --- a/arch/arm/mach-pxa/magician.c +++ b/arch/arm/mach-pxa/magician.c @@ -645,9 +645,8 @@ static struct regulator_init_data bq24022_init_data = { .consumer_supplies = bq24022_consumers, }; -static struct gpio bq24022_gpios[] = { - { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" }, -}; + +static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW }; static struct gpio_regulator_state bq24022_states[] = { { .value = 100000, .gpios = (0 << 0) }, @@ -659,8 +658,8 @@ static struct gpio_regulator_config bq24022_info = { .enabled_at_boot = 1, - .gpios = bq24022_gpios, - .nr_gpios = ARRAY_SIZE(bq24022_gpios), + .gflags = bq24022_gpiod_gflags, + .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags), .states = bq24022_states, .nr_states = ARRAY_SIZE(bq24022_states), @@ -680,6 +679,8 @@ static struct platform_device bq24022 = { static struct gpiod_lookup_table bq24022_gpiod_table = { .dev_id = "gpio-regulator", .table = { + GPIO_LOOKUP("gpio-pxa", EGPIO_MAGICIAN_BQ24022_ISET2, + NULL, GPIO_ACTIVE_HIGH), GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN, "enable", GPIO_ACTIVE_LOW), { }, diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index fb9563de59fc..aecdd3f211ba 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -30,17 +30,15 @@ #include #include #include -#include #include #include #include -#include struct gpio_regulator_data { struct regulator_desc desc; struct regulator_dev *dev; - struct gpio *gpios; + struct gpio_desc **gpiods; int nr_gpios; struct gpio_regulator_state *states; @@ -83,7 +81,7 @@ static int gpio_regulator_set_voltage(struct regulator_dev *dev, for (ptr = 0; ptr < data->nr_gpios; ptr++) { state = (target & (1 << ptr)) >> ptr; - gpio_set_value_cansleep(data->gpios[ptr].gpio, state); + gpiod_set_value_cansleep(data->gpiods[ptr], state); } data->state = target; @@ -120,7 +118,7 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev, for (ptr = 0; ptr < data->nr_gpios; ptr++) { state = (target & (1 << ptr)) >> ptr; - gpio_set_value_cansleep(data->gpios[ptr].gpio, state); + gpiod_set_value_cansleep(data->gpiods[ptr], state); } data->state = target; @@ -139,7 +137,8 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, { struct gpio_regulator_config *config; const char *regtype; - int proplen, gpio, i; + int proplen, i; + int ngpios; int ret; config = devm_kzalloc(dev, @@ -159,46 +158,31 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, of_property_read_u32(np, "startup-delay-us", &config->startup_delay); - /* Fetch GPIOs. - optional property*/ - ret = of_gpio_count(np); - if ((ret < 0) && (ret != -ENOENT)) - return ERR_PTR(ret); - - if (ret > 0) { - config->nr_gpios = ret; - config->gpios = devm_kzalloc(dev, - sizeof(struct gpio) * config->nr_gpios, - GFP_KERNEL); - if (!config->gpios) + /* Fetch GPIO init levels */ + ngpios = gpiod_count(dev, NULL); + if (ngpios > 0) { + config->gflags = devm_kzalloc(dev, + sizeof(enum gpiod_flags) + * ngpios, + GFP_KERNEL); + if (!config->gflags) return ERR_PTR(-ENOMEM); - proplen = of_property_count_u32_elems(np, "gpios-states"); - /* optional property */ - if (proplen < 0) - proplen = 0; + for (i = 0; i < ngpios; i++) { + u32 val; - if (proplen > 0 && proplen != config->nr_gpios) { - dev_warn(dev, "gpios <-> gpios-states mismatch\n"); - proplen = 0; - } + ret = of_property_read_u32_index(np, "gpios-states", i, + &val); - for (i = 0; i < config->nr_gpios; i++) { - gpio = of_get_named_gpio(np, "gpios", i); - if (gpio < 0) { - if (gpio != -ENOENT) - return ERR_PTR(gpio); - break; - } - config->gpios[i].gpio = gpio; - if (proplen > 0) { - of_property_read_u32_index(np, "gpios-states", - i, &ret); - if (ret) - config->gpios[i].flags = - GPIOF_OUT_INIT_HIGH; - } + /* Default to high per specification */ + if (ret) + config->gflags[i] = GPIOD_OUT_HIGH; + else + config->gflags[i] = + val ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; } } + config->ngpios = ngpios; /* Fetch states. */ proplen = of_property_count_u32_elems(np, "states"); @@ -249,7 +233,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) struct gpio_regulator_data *drvdata; struct regulator_config cfg = { }; enum gpiod_flags gflags; - int ptr, ret, state; + int ptr, ret, state, i; drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), GFP_KERNEL); @@ -263,6 +247,16 @@ static int gpio_regulator_probe(struct platform_device *pdev) return PTR_ERR(config); } + for (i = 0; i < config->ngpios; i++) { + drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, + NULL, + i, + config->gflags[i]); + if (IS_ERR(drvdata->gpiods[i])) + return PTR_ERR(drvdata->gpiods[i]); + } + drvdata->nr_gpios = config->ngpios; + drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n"); @@ -270,27 +264,6 @@ static int gpio_regulator_probe(struct platform_device *pdev) goto err; } - if (config->nr_gpios != 0) { - drvdata->gpios = kmemdup(config->gpios, - config->nr_gpios * sizeof(struct gpio), - GFP_KERNEL); - if (drvdata->gpios == NULL) { - dev_err(&pdev->dev, "Failed to allocate gpio data\n"); - ret = -ENOMEM; - goto err_name; - } - - drvdata->nr_gpios = config->nr_gpios; - ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); - if (ret) { - if (ret != -EPROBE_DEFER) - dev_err(&pdev->dev, - "Could not obtain regulator setting GPIOs: %d\n", - ret); - goto err_memstate; - } - } - drvdata->states = kmemdup(config->states, config->nr_states * sizeof(struct gpio_regulator_state), @@ -298,7 +271,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) if (drvdata->states == NULL) { dev_err(&pdev->dev, "Failed to allocate state data\n"); ret = -ENOMEM; - goto err_memgpio; + goto err_name; } drvdata->nr_states = config->nr_states; @@ -319,13 +292,13 @@ static int gpio_regulator_probe(struct platform_device *pdev) default: dev_err(&pdev->dev, "No regulator type set\n"); ret = -EINVAL; - goto err_memgpio; + goto err_memstate; } /* build initial state from gpio init data. */ state = 0; for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) { - if (config->gpios[ptr].flags & GPIOF_OUT_INIT_HIGH) + if (config->gflags[ptr] == GPIOD_OUT_HIGH) state |= (1 << ptr); } drvdata->state = state; @@ -347,26 +320,22 @@ static int gpio_regulator_probe(struct platform_device *pdev) cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags); if (IS_ERR(cfg.ena_gpiod)) { ret = PTR_ERR(cfg.ena_gpiod); - goto err_stategpio; + goto err_memstate; } drvdata->dev = regulator_register(&drvdata->desc, &cfg); if (IS_ERR(drvdata->dev)) { ret = PTR_ERR(drvdata->dev); dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); - goto err_stategpio; + goto err_memstate; } platform_set_drvdata(pdev, drvdata); return 0; -err_stategpio: - gpio_free_array(drvdata->gpios, drvdata->nr_gpios); err_memstate: kfree(drvdata->states); -err_memgpio: - kfree(drvdata->gpios); err_name: kfree(drvdata->desc.name); err: @@ -378,12 +347,7 @@ static int gpio_regulator_remove(struct platform_device *pdev) struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev); regulator_unregister(drvdata->dev); - - gpio_free_array(drvdata->gpios, drvdata->nr_gpios); - kfree(drvdata->states); - kfree(drvdata->gpios); - kfree(drvdata->desc.name); return 0; diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h index 4f3cc1a73ade..11cd6375215d 100644 --- a/include/linux/regulator/gpio-regulator.h +++ b/include/linux/regulator/gpio-regulator.h @@ -21,6 +21,8 @@ #ifndef __REGULATOR_GPIO_H #define __REGULATOR_GPIO_H +#include + struct regulator_init_data; enum regulator_type; @@ -49,9 +51,9 @@ struct gpio_regulator_state { * This is used to keep the regulator at * the default state * @startup_delay: Start-up time in microseconds - * @gpios: Array containing the gpios needed to control - * the setting of the regulator - * @nr_gpios: Number of gpios + * @gflags: Array of GPIO configuration flags for initial + * states + * @ngpios: Number of GPIOs and configurations available * @states: Array of gpio_regulator_state entries describing * the gpio state for specific voltages * @nr_states: Number of states available @@ -68,8 +70,8 @@ struct gpio_regulator_config { unsigned enabled_at_boot:1; unsigned startup_delay; - struct gpio *gpios; - int nr_gpios; + enum gpiod_flags *gflags; + int ngpios; struct gpio_regulator_state *states; int nr_states;