From patchwork Tue Jan 29 10:31:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156951 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490652jaa; Tue, 29 Jan 2019 02:32:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN47AgvRLdh2agNld6m8OEgweNS+DR6bgrntq39V2KNHjYCReVSUliSF7mbPQZBBwn4JJtyB X-Received: by 2002:a17:902:8306:: with SMTP id bd6mr25633586plb.217.1548757929347; Tue, 29 Jan 2019 02:32:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757929; cv=none; d=google.com; s=arc-20160816; b=I+98963D0KjrBccZlGttAB7JgE22wEWXgpgtmemyghU6eX/xDErP3w819mDRdnTOTO r7E7zx3pcb4UReBHZgYmg1oYWRGZsOTTnZz7l34PqkmMNC/RouBQf0mZDJFStBk6w9Ze LlhM/lUubvIIcqhyD1jrpV8AgeFXd9QIxS0Y+wN0RRGj4XimFIoOzYlq+DIgBu7/FsqE Wapdq2o9VWi9LcM+DJBCxXXbLwAqKNwHmIPoPm93TaSa8jKnvdsADV71e2pIKxp/6qtu DEDt3MV+Ch3XePL56lInK/IS7iXJ7zMyikPHbQW6f8Hscsbkvg5txL1PnblphW7kqJwt UGIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wJahcj5iUuUuf7WgRSE5QtMRLYgT/VDSwztkiPTjYNw=; b=Z0Mt+LDwYtY6CQfl1UsS5GrqcD6OQXX0paUJe8TEnxsFquvhEfpsXp5KIHb+4xE4ts baRQJ8dAPuZQcFJj7uQ+6pOqX9KkDkNJ1jg4XAl6DGf8GAVIPmPNjmyTok826XbA3fnV FfUjI7/gFJbpbltAS9u+Rn71IBElgavdJT10Am6WbW/aDjsPGgOggv91Oh2bOs1VRcm0 yA3AQ6uYtbbJYA9ghXQccEf9XkAjxrSOJpPHoAYFNQCY0xMlv3EEglREb8G2UTVYRq64 W8ZUTQj4ELtZ2iiiJ8M7k434rIr8p1n61bsXLAsmlfFW9BJt82ZX7DOchprndGtlTDjv RA3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aNeW6RTo; 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 f21si13129156pgb.371.2019.01.29.02.32.08; Tue, 29 Jan 2019 02:32:09 -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=aNeW6RTo; 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 S1728388AbfA2KcH (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:07 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:33674 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbfA2KcG (ORCPT ); Tue, 29 Jan 2019 05:32:06 -0500 Received: by mail-lj1-f194.google.com with SMTP id v1-v6so17056160ljd.0 for ; Tue, 29 Jan 2019 02:32:04 -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:mime-version :content-transfer-encoding; bh=wJahcj5iUuUuf7WgRSE5QtMRLYgT/VDSwztkiPTjYNw=; b=aNeW6RToyfL3Fn+2rDPEJECaaRD9XIkYvWG7C0HpJPyqrSr+jPAl2WuV/zAEgQt1CT D5AyMNE7G2SbszOGU2fnFPtyt4JIvKvpZrVi239477t1MngjUQOi7u3LcFXMxfxqzdHn Kixdev48neO0GRVYmF7ghWutcu/gRSwWKZqxg= 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:mime-version :content-transfer-encoding; bh=wJahcj5iUuUuf7WgRSE5QtMRLYgT/VDSwztkiPTjYNw=; b=ZJiwjYMgsIIg1otKHyuNMe8lcpSLyJSkUzmhIIwiigpTlRjzpwCpMIZrt6SfVhGL+0 udIOTPS76+iMGGx0s9jMTWtwQ5US1SDPqt89VaVxPocesB078ImPeTNSdAAkKyQ4ggAC sFJ+/2zGoIChnXnTMGVIHP4t4TiuB/4x22TF4axN+N6dL1+KIJFjR685in5iaiTOQ5Qq Ur06iPKNyXmhXjJs70sD+BiHGoB/v2rjeunQM+GYgPRxngIdAQ32MgepE4r+MlyKiMI1 HHEahVMrLnJgYR1aUo42NCZg9SFB7guwUJy9A1ujOMuib7m4gFOdpUwrS+jgk5lGXRK/ FJRQ== X-Gm-Message-State: AJcUuke0WnDeACNWIO4/Ze4Y9e50pzPGGuw3e6A//jMvSpcDPYuIzw1h FYad0KVD9ebanr39XIhmcmiikA== X-Received: by 2002:a2e:20f:: with SMTP id 15-v6mr20774866ljc.172.1548757923366; Tue, 29 Jan 2019 02:32:03 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:01 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij , Philipp Zabel , Petr Cvek , Robert Jarzmik , Paul Parsons , Kevin Hilman , Neil Armstrong Subject: [PATCH 1/5 v10] regulator: gpio: Convert to use descriptors Date: Tue, 29 Jan 2019 11:31:52 +0100 Message-Id: <20190129103156.10139-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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. We request the "enable" GPIO separately as before, and make sure that this line is requested as nonexclusive since enable lines can be shared and the regulator core expects this. Most users of the GPIO regulator are using device tree. There are two boards in the kernel using the gpio regulator from a non-devicetree path: PXA hx4700 and magician. Make sure to switch these over to use descriptors as well. Cc: Philipp Zabel # Magician Cc: Petr Cvek # Magician Cc: Robert Jarzmik # PXA Cc: Paul Parsons # hx4700 Cc: Kevin Hilman # Meson Cc: Neil Armstrong # Meson Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Remove reliance on a syntactic change from a later patch in the series: I was using a local dev pointer in .probe() that is only introduced in a later clean-up patch. ChangeLog v8->v9: - Add a missing allocation. - Collect Marek's Tested-by. - Kevin/Neil: would be great if you could test this patch so as to make sure I don't break your stuff again! ChangeLog v7->v8: - Rebase on v5.0-rc1. - Do not use devm_* to fetch the enable GPIO, use the regular call and hand over lifecycle management to the regulator core. ChangeLog v6->v7: - Resend with the rest. ChangeLog v3->v6: - Make sure to request the GPIO line nonexclusive as with other regulator GPIOs. - Request the voltage controlling GPIOs from the name NULL as only "enable-gpio" is explicitly named. - Make sure to delete all unused struct members and assignments in board files. - Change numbering to fit the rest of the patches. ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- arch/arm/mach-pxa/hx4700.c | 23 ++-- arch/arm/mach-pxa/magician.c | 23 ++-- drivers/regulator/gpio-regulator.c | 150 +++++++++-------------- include/linux/regulator/gpio-regulator.h | 12 +- 4 files changed, 95 insertions(+), 113 deletions(-) -- 2.20.1 diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c index b79b757fdd41..51d38d5e776a 100644 --- a/arch/arm/mach-pxa/hx4700.c +++ b/arch/arm/mach-pxa/hx4700.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -702,9 +703,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,12 +713,10 @@ static struct gpio_regulator_state bq24022_states[] = { static struct gpio_regulator_config bq24022_info = { .supply_name = "bq24022", - .enable_gpio = GPIO72_HX4700_BQ24022_nCHARGE_EN, - .enable_high = 0, .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), @@ -736,6 +733,17 @@ 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), + { }, + }, +}; + /* * StrataFlash */ @@ -878,6 +886,7 @@ static void __init hx4700_init(void) pxa_set_btuart_info(NULL); pxa_set_stuart_info(NULL); + gpiod_add_lookup_table(&bq24022_gpiod_table); platform_add_devices(devices, ARRAY_SIZE(devices)); pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup)); diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c index 08b079653c3f..6538a7c0e504 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) }, @@ -657,12 +656,10 @@ static struct gpio_regulator_state bq24022_states[] = { static struct gpio_regulator_config bq24022_info = { .supply_name = "bq24022", - .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN, - .enable_high = 0, .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), @@ -679,6 +676,17 @@ 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), + { }, + }, +}; + /* * fixed regulator for ads7846 */ @@ -1027,6 +1035,7 @@ static void __init magician_init(void) regulator_register_always_on(0, "power", pwm_backlight_supply, ARRAY_SIZE(pwm_backlight_supply), 5000000); + gpiod_add_lookup_table(&bq24022_gpiod_table); platform_add_devices(ARRAY_AND_SIZE(devices)); } diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index b2f5ec4f658a..07fb41abd4e8 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -30,16 +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; @@ -82,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; @@ -119,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; @@ -138,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, @@ -153,59 +153,36 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, config->supply_name = config->init_data->constraints.name; - if (of_property_read_bool(np, "enable-active-high")) - config->enable_high = true; - if (of_property_read_bool(np, "enable-at-boot")) config->enabled_at_boot = true; of_property_read_u32(np, "startup-delay-us", &config->startup_delay); - config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); - if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) - return ERR_PTR(config->enable_gpio); - - /* 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_kcalloc(dev, - config->nr_gpios, sizeof(struct gpio), - 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; - config->gpios[i].label = config->supply_name; - 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"); @@ -255,7 +232,8 @@ static int gpio_regulator_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct gpio_regulator_data *drvdata; struct regulator_config cfg = { }; - int ptr, ret, state; + enum gpiod_flags gflags; + int ptr, ret, state, i; drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), GFP_KERNEL); @@ -275,26 +253,21 @@ static int gpio_regulator_probe(struct platform_device *pdev) return -ENOMEM; } - 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_memgpio; - } + drvdata->gpiods = devm_kzalloc(&pdev->dev, sizeof(struct gpio_desc *), + GFP_KERNEL); + if (!drvdata->gpiods) + return -ENOMEM; + 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]); + /* This is good to know */ + gpiod_set_consumer_name(drvdata->gpiods[i], drvdata->desc.name); } + drvdata->nr_gpios = config->ngpios; drvdata->states = kmemdup(config->states, config->nr_states * @@ -303,7 +276,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_stategpio; + goto err_name; } drvdata->nr_states = config->nr_states; @@ -330,7 +303,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) /* 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; @@ -340,21 +313,19 @@ static int gpio_regulator_probe(struct platform_device *pdev) cfg.driver_data = drvdata; cfg.of_node = np; - if (gpio_is_valid(config->enable_gpio)) { - cfg.ena_gpio = config->enable_gpio; - cfg.ena_gpio_initialized = true; - } - cfg.ena_gpio_invert = !config->enable_high; - if (config->enabled_at_boot) { - if (config->enable_high) - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; - else - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; - } else { - if (config->enable_high) - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; - else - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; + /* + * The signal will be inverted by the GPIO core if flagged so in the + * decriptor. + */ + if (config->enabled_at_boot) + gflags = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE; + else + gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE; + + cfg.ena_gpiod = gpiod_get_optional(&pdev->dev, "enable", gflags); + if (IS_ERR(cfg.ena_gpiod)) { + ret = PTR_ERR(cfg.ena_gpiod); + goto err_memstate; } drvdata->dev = regulator_register(&drvdata->desc, &cfg); @@ -370,10 +341,6 @@ static int gpio_regulator_probe(struct platform_device *pdev) err_memstate: kfree(drvdata->states); -err_stategpio: - gpio_free_array(drvdata->gpios, drvdata->nr_gpios); -err_memgpio: - kfree(drvdata->gpios); err_name: kfree(drvdata->desc.name); return ret; @@ -384,12 +351,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 19fbd267406d..49c407afb944 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; @@ -53,9 +55,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 @@ -74,8 +76,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; From patchwork Tue Jan 29 10:31:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156952 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490710jaa; Tue, 29 Jan 2019 02:32:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN7vqDJYmbc1VRvkT1SBUhLFoE9NKXEWNgc5ehw2axRj/w3nK4L2Q9rq/n+UbLuilQa32ukx X-Received: by 2002:a62:18ce:: with SMTP id 197mr26444081pfy.88.1548757933197; Tue, 29 Jan 2019 02:32:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757933; cv=none; d=google.com; s=arc-20160816; b=mirqsHYbTJm391dDwnRp7SNHiIA/aMHvddRRz6ifgvPqoMwgz56RrRCuuP5c5TJGd+ cG4JUMqnHmeKUDn0wLjdxttX+Wjbv2xsxCt7g27fTaYdB7dDMu59IJrSYguISPTnVSzT aOnFLWEz7V6wtM28bJQ621NZvim/+O6k7cOvSPGMOKeq80ag0mUlvGr60/kP0BWZAFqx qAp1imQjn6TXE1tUSOs5gPi2fRK4mN7wIgpNEx67pX+VpNCevHwMoYgrXoSAIDO4yyqZ PeNN2VDuelGaln1t0oheRcLbsyhUhhGeOLe7cHVUD26+U0AU7GyQeEQ+RHAr5nd6qiDP vPuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cdcA5MnEQ1P9ABN64IQ8GAUqfwQSybvw9fgR9nPfLOI=; b=shzD7VfJvLuMES6gta5kJfGWyo7PUIJD02Lr/UNOXQUoLVy66mms1weqR1Kj9kOacw SiC2N5rwJDz8uYgOWq1GxhlGKTU+X81fs+2g2sNvHt3Bpj7N5tcloAcJILM3IGEgpueJ 0xZQRZO7RDY47un+43QUCKNTVxn/GbVJS0TJBaMjbUN2Wkd7pkWVdeYKFapJfPa9N+4P oJ6PICdKhBcOF6KCCuz0il+6fcZltCkR+jcrNO0bcCb7ojbUDU/TM7cX8GOho/XDcHRd kIAhD+gzlHo7PHUQItgxeGZuy/ogFXVMC30ssDS9pghJjY0Esv1yX40N+K+Y6IP+p7D4 gJqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cBUAQNyR; 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 145si35716294pga.396.2019.01.29.02.32.12; Tue, 29 Jan 2019 02:32:13 -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=cBUAQNyR; 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 S1728447AbfA2KcL (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:11 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:33679 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbfA2KcJ (ORCPT ); Tue, 29 Jan 2019 05:32:09 -0500 Received: by mail-lj1-f193.google.com with SMTP id v1-v6so17056299ljd.0 for ; Tue, 29 Jan 2019 02:32:07 -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 :mime-version:content-transfer-encoding; bh=cdcA5MnEQ1P9ABN64IQ8GAUqfwQSybvw9fgR9nPfLOI=; b=cBUAQNyR12igjIy51lzz1toyUpvEcD7sg6O+xIPyynT+SLflvBbb/eExa8OmC80Y2P eqmLV+ty0MrfHUKWWhzqp3LK5Byph/+KPImK/Lemio9yviYV0qPSYDseZqrpojzt03nm uOIhw+z+DhoE+A2m/mjVe9bVNW4GM/WX23Nas= 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:mime-version:content-transfer-encoding; bh=cdcA5MnEQ1P9ABN64IQ8GAUqfwQSybvw9fgR9nPfLOI=; b=OGY62DfZ2E4PAS33bhvR6KCxonLisOH565MhVonqPancpkThKqwQeBAo92NIHPKE0Q L+7wPpvviYAwqYgka/lVHKNNdJovpv1Qqp9qEToZvysVv4Ghgg1OVZTjG51AkowGBeS8 aU5MLAu8VRxr1Cgld/Y1eai8o5Ox+EMWk9WlCANzunLkPynvVV2i7/yOMLLgme6V5Pqh jwUNUMNCia9gXHrCx0DMLmcodGZPjVV1GqrGqi267chcmvSvkOAfvUkRut+NOmGME680 qezWeMhSZ06X6G86oGCNGrkerdVrNr7nR8C8yjL34mOTYS3bMADxqDU2LT6JX6qa5T4c V4sQ== X-Gm-Message-State: AJcUukc9xdg237YicDbgXyYJd6ikjI3av8DNR2A0+JezQO6LLnGQ0vrd rNwazDkATGyr5TnWk5Not4p8Rg== X-Received: by 2002:a2e:908b:: with SMTP id l11-v6mr20118752ljg.150.1548757926604; Tue, 29 Jan 2019 02:32:06 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:05 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij , Alexander Shiyan , Haojian Zhuang , Aaro Koskinen , Tony Lindgren , Mike Rapoport , Robert Jarzmik , Philipp Zabel , Petr Cvek , Paul Parsons , Daniel Mack , Marc Zyngier , Geert Uytterhoeven , Russell King , Janusz Krzysztofik Subject: [PATCH 2/5 v10] regulator: fixed/gpio: Pull inversion/OD into gpiolib Date: Tue, 29 Jan 2019 11:31:53 +0100 Message-Id: <20190129103156.10139-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129103156.10139-1-linus.walleij@linaro.org> References: <20190129103156.10139-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This pushes the handling of inversion semantics and open drain settings to the GPIO descriptor and gpiolib. All affected board files are also augmented. This is especially nice since we don't have to have any confusing flags passed around to the left and right littering the fixed and GPIO regulator drivers and the regulator core. It is all just very straight-forward: the core asks the GPIO line to be asserted or deasserted and gpiolib deals with the rest depending on how the platform is configured: if the line is active low, it deals with that, if the line is open drain, it deals with that too. Cc: Alexander Shiyan # i.MX boards user Cc: Haojian Zhuang # MMP2 maintainer Cc: Aaro Koskinen # OMAP1 maintainer Cc: Tony Lindgren # OMAP1,2,3 maintainer Cc: Mike Rapoport # EM-X270 maintainer Cc: Robert Jarzmik # EZX maintainer Cc: Philipp Zabel # Magician maintainer Cc: Petr Cvek # Magician Cc: Robert Jarzmik # PXA Cc: Paul Parsons # hx4700 Cc: Daniel Mack # Raumfeld maintainer Cc: Marc Zyngier # Zeus maintainer Cc: Geert Uytterhoeven # SuperH pinctrl/GPIO maintainer Cc: Russell King # SA1100 Tested-by: Marek Szyprowski Tested-by: Janusz Krzysztofik #OMAP1 Amstrad Delta Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Rebase on other changes. ChangeLog v8->v9: - Rebased on other changes. - Collected Marek's Tested-by. ChangeLog v7->v8: - Rebase on v5.0-rc1. - Collected Janusz Tested-by tag for OMAP1. ChangeLog v6->v7: - Fix a missed .enable_high on OMAP1. ChangeLog v4->v6: - Split out parts relation to GPIO regulator descriptor conversion to the right patch. - Renumber to fit the rest of the series. - Daniel Mack says he will probably delete the Raumfeld board file and replace it with a device tree, I suggest we just deal with that conflict upstream. ChangeLog v3->v4: - Rebase on fixed regulator changes. ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch series - Cover the new user added in sa1100 --- arch/arm/mach-imx/mach-mx21ads.c | 1 - arch/arm/mach-imx/mach-mx27ads.c | 2 +- arch/arm/mach-mmp/brownstone.c | 1 - arch/arm/mach-omap1/board-ams-delta.c | 2 -- arch/arm/mach-omap2/pdata-quirks.c | 1 - arch/arm/mach-pxa/em-x270.c | 1 - arch/arm/mach-pxa/ezx.c | 3 +- arch/arm/mach-pxa/raumfeld.c | 1 - arch/arm/mach-pxa/zeus.c | 3 +- arch/arm/mach-sa1100/assabet.c | 1 - arch/sh/boards/mach-ecovec24/setup.c | 2 -- .../intel-mid/device_libs/platform_bcm43xx.c | 1 - drivers/regulator/core.c | 8 ++--- drivers/regulator/da9055-regulator.c | 1 - drivers/regulator/fixed.c | 35 +++++-------------- include/linux/regulator/fixed.h | 10 ------ include/linux/regulator/gpio-regulator.h | 6 ---- 17 files changed, 13 insertions(+), 66 deletions(-) -- 2.20.1 diff --git a/arch/arm/mach-imx/mach-mx21ads.c b/arch/arm/mach-imx/mach-mx21ads.c index 2e1e540f2e5a..d278fb672d40 100644 --- a/arch/arm/mach-imx/mach-mx21ads.c +++ b/arch/arm/mach-imx/mach-mx21ads.c @@ -205,7 +205,6 @@ static struct regulator_init_data mx21ads_lcd_regulator_init_data = { static struct fixed_voltage_config mx21ads_lcd_regulator_pdata = { .supply_name = "LCD", .microvolts = 3300000, - .enable_high = 1, .init_data = &mx21ads_lcd_regulator_init_data, }; diff --git a/arch/arm/mach-imx/mach-mx27ads.c b/arch/arm/mach-imx/mach-mx27ads.c index f5e04047ed13..6dd7f57c332f 100644 --- a/arch/arm/mach-imx/mach-mx27ads.c +++ b/arch/arm/mach-imx/mach-mx27ads.c @@ -237,7 +237,7 @@ static struct fixed_voltage_config mx27ads_lcd_regulator_pdata = { static struct gpiod_lookup_table mx27ads_lcd_regulator_gpiod_table = { .dev_id = "reg-fixed-voltage.0", /* Let's hope ID 0 is what we get */ .table = { - GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_LOW), { }, }, }; diff --git a/arch/arm/mach-mmp/brownstone.c b/arch/arm/mach-mmp/brownstone.c index a04e249c654b..d2560fb1e835 100644 --- a/arch/arm/mach-mmp/brownstone.c +++ b/arch/arm/mach-mmp/brownstone.c @@ -149,7 +149,6 @@ static struct regulator_init_data brownstone_v_5vp_data = { static struct fixed_voltage_config brownstone_v_5vp = { .supply_name = "v_5vp", .microvolts = 5000000, - .enable_high = 1, .enabled_at_boot = 1, .init_data = &brownstone_v_5vp_data, }; diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index c4c0a8ea11e4..be30c3c061b4 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -267,7 +267,6 @@ static struct fixed_voltage_config modem_nreset_config = { .supply_name = "modem_nreset", .microvolts = 3300000, .startup_delay = 25000, - .enable_high = 1, .enabled_at_boot = 1, .init_data = &modem_nreset_data, }; @@ -533,7 +532,6 @@ static struct regulator_init_data keybrd_pwr_initdata = { static struct fixed_voltage_config keybrd_pwr_config = { .supply_name = "keybrd_pwr", .microvolts = 5000000, - .enable_high = 1, .init_data = &keybrd_pwr_initdata, }; diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c index 8a5b6ed4ec36..a2ecc5e69abb 100644 --- a/arch/arm/mach-omap2/pdata-quirks.c +++ b/arch/arm/mach-omap2/pdata-quirks.c @@ -330,7 +330,6 @@ static struct fixed_voltage_config pandora_vwlan = { .supply_name = "vwlan", .microvolts = 1800000, /* 1.8V */ .startup_delay = 50000, /* 50ms */ - .enable_high = 1, .init_data = &pandora_vmmc3, }; diff --git a/arch/arm/mach-pxa/em-x270.c b/arch/arm/mach-pxa/em-x270.c index 32c1edeb3f14..5ba7bb7f7d51 100644 --- a/arch/arm/mach-pxa/em-x270.c +++ b/arch/arm/mach-pxa/em-x270.c @@ -976,7 +976,6 @@ static struct fixed_voltage_config camera_dummy_config = { .supply_name = "camera_vdd", .input_supply = "vcc cam", .microvolts = 2800000, - .enable_high = 0, .init_data = &camera_dummy_initdata, }; diff --git a/arch/arm/mach-pxa/ezx.c b/arch/arm/mach-pxa/ezx.c index 565965e9acc7..5e110e70ce5a 100644 --- a/arch/arm/mach-pxa/ezx.c +++ b/arch/arm/mach-pxa/ezx.c @@ -714,7 +714,6 @@ static struct regulator_init_data camera_regulator_initdata = { static struct fixed_voltage_config camera_regulator_config = { .supply_name = "camera_vdd", .microvolts = 2800000, - .enable_high = 0, .init_data = &camera_regulator_initdata, }; @@ -730,7 +729,7 @@ static struct gpiod_lookup_table camera_supply_gpiod_table = { .dev_id = "reg-fixed-voltage.1", .table = { GPIO_LOOKUP("gpio-pxa", GPIO50_nCAM_EN, - NULL, GPIO_ACTIVE_HIGH), + NULL, GPIO_ACTIVE_LOW), { }, }, }; diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c index e1db072756f2..e13bfc9b01d2 100644 --- a/arch/arm/mach-pxa/raumfeld.c +++ b/arch/arm/mach-pxa/raumfeld.c @@ -883,7 +883,6 @@ static struct regulator_init_data audio_va_initdata = { static struct fixed_voltage_config audio_va_config = { .supply_name = "audio_va", .microvolts = 5000000, - .enable_high = 1, .enabled_at_boot = 0, .init_data = &audio_va_initdata, }; diff --git a/arch/arm/mach-pxa/zeus.c b/arch/arm/mach-pxa/zeus.c index c411f79d4cb5..ebd654302387 100644 --- a/arch/arm/mach-pxa/zeus.c +++ b/arch/arm/mach-pxa/zeus.c @@ -426,7 +426,7 @@ static struct gpiod_lookup_table can_regulator_gpiod_table = { .dev_id = "reg-fixed-voltage.0", .table = { GPIO_LOOKUP("gpio-pxa", ZEUS_CAN_SHDN_GPIO, - NULL, GPIO_ACTIVE_HIGH), + NULL, GPIO_ACTIVE_LOW), { }, }, }; @@ -547,7 +547,6 @@ static struct regulator_init_data zeus_ohci_regulator_data = { static struct fixed_voltage_config zeus_ohci_regulator_config = { .supply_name = "vbus2", .microvolts = 5000000, /* 5.0V */ - .enable_high = 1, .startup_delay = 0, .init_data = &zeus_ohci_regulator_data, }; diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c index dfa42496ec27..d09c3f236186 100644 --- a/arch/arm/mach-sa1100/assabet.c +++ b/arch/arm/mach-sa1100/assabet.c @@ -469,7 +469,6 @@ static struct regulator_consumer_supply assabet_cf_vcc_consumers[] = { static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = { .supply_name = "cf-power", .microvolts = 3300000, - .enable_high = 1, }; static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = { diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c index 22b4106b8084..5495efa07335 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -630,7 +630,6 @@ static struct regulator_init_data cn12_power_init_data = { static struct fixed_voltage_config cn12_power_info = { .supply_name = "CN12 SD/MMC Vdd", .microvolts = 3300000, - .enable_high = 1, .init_data = &cn12_power_init_data, }; @@ -671,7 +670,6 @@ static struct regulator_init_data sdhi0_power_init_data = { static struct fixed_voltage_config sdhi0_power_info = { .supply_name = "CN11 SD/MMC Vdd", .microvolts = 3300000, - .enable_high = 1, .init_data = &sdhi0_power_init_data, }; diff --git a/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c b/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c index 96f438d4b026..1421d5330b2c 100644 --- a/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c +++ b/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c @@ -44,7 +44,6 @@ static struct fixed_voltage_config bcm43xx_vmmc = { */ .microvolts = 2000000, /* 1.8V */ .startup_delay = 250 * 1000, /* 250ms */ - .enable_high = 1, /* active high */ .enabled_at_boot = 0, /* disabled at boot */ .init_data = &bcm43xx_vmmc_data, }; diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b9d7b45c7295..48baa03ff3d8 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -82,7 +82,6 @@ struct regulator_enable_gpio { struct gpio_desc *gpiod; u32 enable_count; /* a number of enabled shared GPIO */ u32 request_count; /* a number of requested shared GPIO */ - unsigned int ena_gpio_invert:1; }; /* @@ -2268,7 +2267,6 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev, } pin->gpiod = gpiod; - pin->ena_gpio_invert = config->ena_gpio_invert; list_add(&pin->list, ®ulator_ena_gpio_list); update_ena_gpio_to_rdev: @@ -2319,8 +2317,7 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) if (enable) { /* Enable GPIO at initial use */ if (pin->enable_count == 0) - gpiod_set_value_cansleep(pin->gpiod, - !pin->ena_gpio_invert); + gpiod_set_value_cansleep(pin->gpiod, 1); pin->enable_count++; } else { @@ -2331,8 +2328,7 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable) /* Disable GPIO if not used */ if (pin->enable_count <= 1) { - gpiod_set_value_cansleep(pin->gpiod, - pin->ena_gpio_invert); + gpiod_set_value_cansleep(pin->gpiod, 0); pin->enable_count = 0; } } diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 588c3d2445cf..417cafe2aba0 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -457,7 +457,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, int gpio_mux = pdata->gpio_ren[id]; config->ena_gpiod = pdata->ena_gpiods[id]; - config->ena_gpio_invert = 1; /* * GPI pin is muxed with regulator to control the diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 9abdb9130766..b5afc9db2c61 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -79,15 +79,6 @@ of_get_fixed_voltage_config(struct device *dev, of_property_read_u32(np, "startup-delay-us", &config->startup_delay); - /* - * FIXME: we pulled active low/high and open drain handling into - * gpiolib so it will be handled there. Delete this in the second - * step when we also remove the custom inversion handling for all - * legacy boardfiles. - */ - config->enable_high = 1; - config->gpio_is_open_drain = 0; - if (of_find_property(np, "vin-supply", NULL)) config->input_supply = "vin"; @@ -151,24 +142,14 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) drvdata->desc.fixed_uV = config->microvolts; - cfg.ena_gpio_invert = !config->enable_high; - if (config->enabled_at_boot) { - if (config->enable_high) - gflags = GPIOD_OUT_HIGH; - else - gflags = GPIOD_OUT_LOW; - } else { - if (config->enable_high) - gflags = GPIOD_OUT_LOW; - else - gflags = GPIOD_OUT_HIGH; - } - if (config->gpio_is_open_drain) { - if (gflags == GPIOD_OUT_HIGH) - gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; - else - gflags = GPIOD_OUT_LOW_OPEN_DRAIN; - } + /* + * The signal will be inverted by the GPIO core if flagged so in the + * decriptor. + */ + if (config->enabled_at_boot) + gflags = GPIOD_OUT_HIGH; + else + gflags = GPIOD_OUT_LOW; /* * Some fixed regulators share the enable line between two diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h index 1a4340ed8e2b..f10140da7145 100644 --- a/include/linux/regulator/fixed.h +++ b/include/linux/regulator/fixed.h @@ -25,14 +25,6 @@ struct regulator_init_data; * @input_supply: Name of the input regulator supply * @microvolts: Output voltage of regulator * @startup_delay: Start-up time in microseconds - * @gpio_is_open_drain: Gpio pin is open drain or normal type. - * If it is open drain type then HIGH will be set - * through PULL-UP with setting gpio as input - * and low will be set as gpio-output with driven - * to low. For non-open-drain case, the gpio will - * will be in output and drive to low/high accordingly. - * @enable_high: Polarity of enable GPIO - * 1 = Active high, 0 = Active low * @enabled_at_boot: Whether regulator has been enabled at * boot or not. 1 = Yes, 0 = No * This is used to keep the regulator at @@ -48,8 +40,6 @@ struct fixed_voltage_config { const char *input_supply; int microvolts; unsigned startup_delay; - unsigned gpio_is_open_drain:1; - unsigned enable_high:1; unsigned enabled_at_boot:1; struct regulator_init_data *init_data; }; diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h index 49c407afb944..11cd6375215d 100644 --- a/include/linux/regulator/gpio-regulator.h +++ b/include/linux/regulator/gpio-regulator.h @@ -46,10 +46,6 @@ struct gpio_regulator_state { /** * struct gpio_regulator_config - config structure * @supply_name: Name of the regulator supply - * @enable_gpio: GPIO to use for enable control - * set to -EINVAL if not used - * @enable_high: Polarity of enable GPIO - * 1 = Active high, 0 = Active low * @enabled_at_boot: Whether regulator has been enabled at * boot or not. 1 = Yes, 0 = No * This is used to keep the regulator at @@ -71,8 +67,6 @@ struct gpio_regulator_state { struct gpio_regulator_config { const char *supply_name; - int enable_gpio; - unsigned enable_high:1; unsigned enabled_at_boot:1; unsigned startup_delay; From patchwork Tue Jan 29 10:31:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156953 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490774jaa; Tue, 29 Jan 2019 02:32:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN4b3Zk7mYVkiPr+fHQOf192wIVlgN3ITJLAO7uKg6klClBp6cf9BHD39ImA+dZHRcDj19Fb X-Received: by 2002:a63:fb4c:: with SMTP id w12mr23291850pgj.321.1548757936444; Tue, 29 Jan 2019 02:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757936; cv=none; d=google.com; s=arc-20160816; b=HA/j6XA5fqV9XVymDp6Bkwe/EiHHf5mvG3m7MfKVsWZjtSsiFfP3NozlTg2bgjTxCM 8Xm0wjUGs600yaUBY2DKOWdHwr1WetCrpcacSloiLU5UsejY+IHB/hBkNVxuxcVAQeWJ AnVe2Zuc+i2xSzjePcoEtJpQlJMOW36oiZDjSZ14rmP357ZzYPMvalwCmCcQDNcbHqpq 99m04CaV6HUl6Py3tmHghcoXscv7wLLdGOwi+mPLUdNFlL7GOF7EcL4q4vOgmnzC3SJo lF1HkLtfBT3e9VDNkLNgWzYXo0szkvpE+NxP+KOSZrVwXrJorkwmumWjasHOI5zGNN3y fV7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nWy4IKgcVotjcGKcL+YOPtGjOTrN/OWg2WWmLAh2Cuc=; b=l2/FRFE8997slLSXKz9XUxrCWi3wLBOKkMU0+6j/d0t9Q+ildDOPEdFbUbtzj8S/xf Fgy8Efo4FFkzPvZ5YK7CGOfwbjsLrGiSuqT/zZBBx8pnjVT9FOiXkIS4/L+ITbkhdH9q /iCqK85ZWsX2BtLxieIVdO9od2s3ieaMU7GbPnhfxSv8buoj9DfziraqhhepvLeSPwCr 3sx/jpFEhDwBm73ku6oV7Sk6GXFNTSw5FuXB59Hr43ktKbY1scua+yjIrpDBBrkU8PaI fWs69OjWBqoGaqv7+PPqL8A0d2GKCU/5cAavLnrpr9G53c/hZbVz/1u82tCPNYeMwRSq 5A3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZhDuyu8L; 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 3si18003201pla.240.2019.01.29.02.32.16; Tue, 29 Jan 2019 02:32:16 -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=ZhDuyu8L; 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 S1728465AbfA2KcN (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:13 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:35073 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbfA2KcL (ORCPT ); Tue, 29 Jan 2019 05:32:11 -0500 Received: by mail-lf1-f65.google.com with SMTP id e26so14229268lfc.2 for ; Tue, 29 Jan 2019 02:32:09 -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 :mime-version:content-transfer-encoding; bh=nWy4IKgcVotjcGKcL+YOPtGjOTrN/OWg2WWmLAh2Cuc=; b=ZhDuyu8LF/gtqxDcoKYwiqntXXSEhkG/QwiwOggiz+VVa5DtPtho1bn4lO/JihJATh j6ogTtNTeOitU8rHlSOgzTJx9VHAShs4Q6/SjPhHeOaB7y8HR17oiklXFM+LU9ROBuWs IonbT2qC1maNUvIPBv+YeydRKVdZ/YKpBhl2Y= 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:mime-version:content-transfer-encoding; bh=nWy4IKgcVotjcGKcL+YOPtGjOTrN/OWg2WWmLAh2Cuc=; b=WU2c1QTh8C1JmI+f9pmoQn4vg5fZhTTtMpxIvDBylwuSUk5WrlXEj1Vb2tu79gW6ew 5NXw91DLkEWvAtyxEksvDqbkqbwdbYXSLYBFXh68v7jcq93PwDizVYSmMQfR1CR0CE6Q QeLrYUqgsnKu6ZTLOxZq2LWthay3737vqJ6ckqciZR7jLApFr6GVLJXO/Yp0nsbslMLn c+7aGlYRcbWQNrBVQ10UAOiuVW0Nnvo7VRfbaNubYLL8JsgBpcapKzm3MlvbPtXhVe9E L+GC65r2SLzOLB8zVmQM+TXgDlpi9c7AeEMSzjxOH7UI7hVnx4fBqnn7Y/Ug5eoEwPuD 3wAg== X-Gm-Message-State: AJcUukfMFWsq3sqAnjfMDRXiV4dPrOgrFnOx+r7wrKZYdyBlik0o2gn7 PFHmcHZ4sq5KftAXxr8V5gW6moiHFys= X-Received: by 2002:a19:6a13:: with SMTP id u19mr20581381lfu.46.1548757929045; Tue, 29 Jan 2019 02:32:09 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:07 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij , devicetree@vger.kernel.org, Rob Herring Subject: [PATCH 3/5 v10] regulator: fixed/gpio: Update device tree bindings Date: Tue, 29 Jan 2019 11:31:54 +0100 Message-Id: <20190129103156.10139-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129103156.10139-1-linus.walleij@linaro.org> References: <20190129103156.10139-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Deprecate the open drain binding for fixed regulator and indicate that we prefer this to be passed in the GPIO phandle flags. Clarify that the line inversion semantics for fixed and GPIO regulators completely overrides the active low flags in the phandle flags. Unfortunately this can not be changed to prefer that we pass the flags in the phandle: the bindings have been specified and deployed such that the presence/absence of this flag and only that controls the line inversion semantics. The crucial semantic is that the absence of the flag means the core will assume the line is active low, which in GPIO terms is an exception, as GPIO lines are normally assumed to be active high. This special device tree semantic cannot be changed without introducing a whole new compatible string for the fixed and GPIO regulators, so we just contain the situation. Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Rebase on other changes. ChangeLog v8->v9: - Rebased on other changes. - Collected Marek's Tested-by. ChangeLog v7->v8: - Rebase on v5.0-rc1. ChangeLog v6->v7: - Resend with the rest. ChangeLog v3->v6: - Resending. ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Collect Rob's ACK. --- .../bindings/regulator/fixed-regulator.txt | 13 +++++++++++-- .../bindings/regulator/gpio-regulator.txt | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt index 0c2a6c8a1536..a7a1cd0dfa6e 100644 --- a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt @@ -8,10 +8,19 @@ Optional properties: - gpio: gpio to use for enable control - startup-delay-us: startup time in microseconds - enable-active-high: Polarity of GPIO is Active high -If this property is missing, the default assumed is Active low. + If this property is missing, the default assumed is Active low. + If the phandle flags to the GPIO handle also flag the line as active + low or high, that will be ignored for fixed regulators and the + presence or absence of this flag solely controls the inversion + semantics. +-vin-supply: Input supply name. + +Deprecated properties: - gpio-open-drain: GPIO is open drain type. If this property is missing then default assumption is false. --vin-supply: Input supply name. + Do not use this property in new device trees: instead use the + phandle flag to indicate to the GPIO provider that the line + should be handled as open drain. Any property defined as part of the core regulator binding, defined in regulator.txt, can also be used. diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt index 1f496159e2bb..8fef3e5358a2 100644 --- a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt @@ -14,6 +14,10 @@ Optional properties: defualt is LOW if nothing is specified. - startup-delay-us : Startup time in microseconds. - enable-active-high : Polarity of GPIO is active high (default is low). + If the phandle flags to the GPIO handle also flag the line as + active low or high, that will be ignored for fixed regulators + and the presence or absence of this flag solely controls the + inversion semantics. - regulator-type : Specifies what is being regulated, must be either "voltage" or "current", defaults to voltage. From patchwork Tue Jan 29 10:31:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156955 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490904jaa; Tue, 29 Jan 2019 02:32:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN6VtKPVuoW1pEx4ZfQlShQRJIgT86o3oNsFRsT9lE0/zzEqxcSUGZKLqs1Dw3erSgDXu1al X-Received: by 2002:a63:193:: with SMTP id 141mr23326685pgb.136.1548757944983; Tue, 29 Jan 2019 02:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757944; cv=none; d=google.com; s=arc-20160816; b=ijBDPhRBzBIF/ys2yAaxHvqyJqzH5lDZLd/xJFXMffI33vaqUqzDMGDiAE1gy3xCnV Fp8+BjBYJp3aYUym6i+IAB6bMi0202RXNx53+JVnCyCBJwomXQ9nE1hoW9Y91U2ZCRVs IKzs0aD8kFwfCyJoQXbMoSDh6vEagf5oJU5Gjp2qvgaldoa5Q4VVV5GAgcZqcQr3C+50 esXZgBCWx7DFyibZvzQJr14pjw88KT6vqxjCA2MZgWUEwpv/5wUzDH0tBoIrDY442kdF /9wAZyJGgd4xbhSD/5I8x9kLhEOmodVoZbRViaUzB/fhWFsGmi46gSBuvOKQlQUjzzxw D0hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=Doh1k++p/BHSgppEV1QwVJBZF5jGJzzG+H4kEbgzeOpF7WWLUWP/EA9eyOeQamN4qn +uZzoBX29vbp3KJT3vqe/QVPPaESrdpIkakWg+W926fWLvaqbNBZwNrAdfKKS3yvewlT zz/xhlQ845aoAOEP7CktfenQYvt6COr0Qn2+mnXu+ovZy6HkHEGRbEqYTmTzbqaCD4Vz vH81g3A+BZqaAwvVY2GI/0Taprj9JZN2m710E8l6T+3s1mcEVInLe1FCWwBQffqxV3BX 0XoXFkPX3swRRy+X5KRB35t0Sa9ApXgFVFKAqLrHO9incaoMSArn4HhvPkBBjBC7uCFw YwPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cu6xwnVB; 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 c1si9997836pld.194.2019.01.29.02.32.24; Tue, 29 Jan 2019 02:32:24 -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=cu6xwnVB; 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 S1728506AbfA2KcR (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:17 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:38002 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728456AbfA2KcO (ORCPT ); Tue, 29 Jan 2019 05:32:14 -0500 Received: by mail-lf1-f67.google.com with SMTP id a8so14222418lfk.5 for ; Tue, 29 Jan 2019 02:32: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 :mime-version:content-transfer-encoding; bh=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=cu6xwnVBbn4OCRaoVmoASeOMq9tuDYqYMI12GrfgklfPYjxz4r/arJ1X/Ndm3JI52A SavJr5iJpKgy8zIaVtLZb5t3Q+F85O7W5qyr/nBeYV2zmFO3poZP5h6I9Qd55rdB0J+r inJvZAWGbvmJkNmLvAtl5RkD3+1oqKGPWDAVI= 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:mime-version:content-transfer-encoding; bh=V5UvtJ3mX5DrioHKtn7NF8k5S+MYyfiW4iemDDngUmk=; b=MFec7UL/xMu0UCVBV2UQje0332uRB4OOrBybha3tTn3mm3b06NniPF9CEq4MVPlIWc KMfnV0rWkdnHW6fMPxt+r6r0iT1bDJyIiO0C3B8e32Vvkgak/34n60WXh3jD5JJA9EmT KxgLne/iPctpH5ry4Auq2J7hOyxdRaljgg7/fEPbSuCTPqAuQ4LyEPkROVmN0cprCeU6 8bNsghBwrwv7Xuvkwj6YA9yuuoXtNxcVX4/0Q0TojSuKgFiipT3WRAy0NEzxtRnlVMG4 vE73fyn/RPpvCtW06Hup7K0AC+OsLSujRT+Q05EZ9J7OfHB3NhSoBv5lDi6QEVvy3LTo c3CQ== X-Gm-Message-State: AJcUukd+tRMl6P8hxFhWrtmSka19yeLjDomW5Lxk6c+rDL+lVPt3LGDG tbhlb9XbFZ6YX0CB4/L7Xv7nsw== X-Received: by 2002:a19:ced3:: with SMTP id e202mr20829827lfg.13.1548757931492; Tue, 29 Jan 2019 02:32:11 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:10 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij Subject: [PATCH 4/5 v10] regulator: gpio: Simplify probe path Date: Tue, 29 Jan 2019 11:31:55 +0100 Message-Id: <20190129103156.10139-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129103156.10139-1-linus.walleij@linaro.org> References: <20190129103156.10139-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use devm_* managed device resources and create a local struct device *dev variable to simplify the code inside probe(). Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Properly change &pdev->dev to local dev pointer in this patch, this was acccidentally exploited in patch 1. - Rebase on other changes. ChangeLog v8->v9: - Rebased on other changes. - Collected Marek's Tested-by. ChangeLog v7->v8: - Rebase on v5.0-rc1. ChangeLog v6->v7: - Resend with the rest. ChangeLog v3->v6: - Rebase on top of the other changes. - Change numbering to fit the rest of the series. ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/gpio-regulator.c | 58 +++++++++++++----------------- 1 file changed, 24 insertions(+), 34 deletions(-) -- 2.20.1 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 07fb41abd4e8..6157001df0a4 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -228,37 +228,38 @@ static struct regulator_ops gpio_regulator_current_ops = { static int gpio_regulator_probe(struct platform_device *pdev) { - struct gpio_regulator_config *config = dev_get_platdata(&pdev->dev); - struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct gpio_regulator_config *config = dev_get_platdata(dev); + struct device_node *np = dev->of_node; struct gpio_regulator_data *drvdata; struct regulator_config cfg = { }; enum gpiod_flags gflags; int ptr, ret, state, i; - drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), + drvdata = devm_kzalloc(dev, sizeof(struct gpio_regulator_data), GFP_KERNEL); if (drvdata == NULL) return -ENOMEM; if (np) { - config = of_get_gpio_regulator_config(&pdev->dev, np, + config = of_get_gpio_regulator_config(dev, np, &drvdata->desc); if (IS_ERR(config)) return PTR_ERR(config); } - drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); + drvdata->desc.name = devm_kstrdup(dev, config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { - dev_err(&pdev->dev, "Failed to allocate supply name\n"); + dev_err(dev, "Failed to allocate supply name\n"); return -ENOMEM; } - drvdata->gpiods = devm_kzalloc(&pdev->dev, sizeof(struct gpio_desc *), + drvdata->gpiods = devm_kzalloc(dev, sizeof(struct gpio_desc *), GFP_KERNEL); if (!drvdata->gpiods) return -ENOMEM; for (i = 0; i < config->ngpios; i++) { - drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, + drvdata->gpiods[i] = devm_gpiod_get_index(dev, NULL, i, config->gflags[i]); @@ -269,14 +270,14 @@ static int gpio_regulator_probe(struct platform_device *pdev) } drvdata->nr_gpios = config->ngpios; - drvdata->states = kmemdup(config->states, - config->nr_states * - sizeof(struct gpio_regulator_state), - GFP_KERNEL); + drvdata->states = devm_kmemdup(dev, + config->states, + config->nr_states * + sizeof(struct gpio_regulator_state), + GFP_KERNEL); if (drvdata->states == NULL) { - dev_err(&pdev->dev, "Failed to allocate state data\n"); - ret = -ENOMEM; - goto err_name; + dev_err(dev, "Failed to allocate state data\n"); + return -ENOMEM; } drvdata->nr_states = config->nr_states; @@ -295,9 +296,8 @@ static int gpio_regulator_probe(struct platform_device *pdev) drvdata->desc.ops = &gpio_regulator_current_ops; break; default: - dev_err(&pdev->dev, "No regulator type set\n"); - ret = -EINVAL; - goto err_memstate; + dev_err(dev, "No regulator type set\n"); + return -EINVAL; } /* build initial state from gpio init data. */ @@ -308,7 +308,7 @@ static int gpio_regulator_probe(struct platform_device *pdev) } drvdata->state = state; - cfg.dev = &pdev->dev; + cfg.dev = dev; cfg.init_data = config->init_data; cfg.driver_data = drvdata; cfg.of_node = np; @@ -322,28 +322,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) else gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE; - cfg.ena_gpiod = gpiod_get_optional(&pdev->dev, "enable", gflags); - if (IS_ERR(cfg.ena_gpiod)) { - ret = PTR_ERR(cfg.ena_gpiod); - goto err_memstate; - } + cfg.ena_gpiod = gpiod_get_optional(dev, "enable", gflags); + if (IS_ERR(cfg.ena_gpiod)) + return PTR_ERR(cfg.ena_gpiod); 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_memstate; + dev_err(dev, "Failed to register regulator: %d\n", ret); + return ret; } platform_set_drvdata(pdev, drvdata); return 0; - -err_memstate: - kfree(drvdata->states); -err_name: - kfree(drvdata->desc.name); - return ret; } static int gpio_regulator_remove(struct platform_device *pdev) @@ -351,8 +343,6 @@ static int gpio_regulator_remove(struct platform_device *pdev) struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev); regulator_unregister(drvdata->dev); - kfree(drvdata->states); - kfree(drvdata->desc.name); return 0; } From patchwork Tue Jan 29 10:31:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 156954 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4490835jaa; Tue, 29 Jan 2019 02:32:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mgv+A4oVxfiTZlw1RvED9QPB6kOxlyMwDFfIMXmvDcxAvDhEnnl9V2A0tqqUyk+lcpiG0 X-Received: by 2002:a65:40c5:: with SMTP id u5mr16118179pgp.46.1548757940775; Tue, 29 Jan 2019 02:32:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548757940; cv=none; d=google.com; s=arc-20160816; b=00vG3pXp28YEjng/mW6exEPupPVY7VTim87RnzGvkx6EtPOxJP9526nbD0qvNsOsEq /dN3VJTrcWIySpecNFB3FTNpn41OAgN+Cee2RthGa+PlKT6HfB8vBtpTthBvGXXfSBF4 WO2XGZKlDh25xC35Tn343Mqwb7NjNeOX56d9f6zLVoHVeH1qv8Jtt4ScF4IaWlEqis3S oR55/3qF0YPFs2+WWiIlPQo+KXzcTOrxmyOKEV3jd2XMUjHQ9YYAToJQK5QC43+KQLhq zHSB8PGA9jjwQsmv9Lex2OwHsTSTQ1DURi922eBlvqx+nbQCoR+eC+3TvhW2vuZ7WtrW K3Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sVatOVqMzKhR+NdEUtHoWq8wqeLbuPk9DS1DaHfqw4g=; b=b+umNE5kAzLeIi2mQ63BaFo1wWRKjdPFvxaBku6yrDfD+7Bw5Gbxd3IYEuE2h/LCow pTTPqyzO8r3IISk9+e/JDNtpHLV4koyDr8W1W6Zyv8dNvMrt9ynlmeJvQO7ZMPJRIq2Z J64xlezw7hYhvzYJnYYJgQFzrwfd4fCLIFFB+7q83DqgwaeUNaA0BXhAPaRcdGL3aw7A RRn/IYfItp47HFqsGhcXtY/VfT5uDhp6OR+wR2LXxmvjrFTnSWhgKTvbvjqsvz76rk6p LkWpPePK5ZrfaglqqhfcnRIQVjE3E0JGQBfGgHnYLGVbqTpTB+Fou3iAM907Z2mbdPXG llIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BkQ5z/bs"; 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 85si34537856pfc.145.2019.01.29.02.32.20; Tue, 29 Jan 2019 02:32:20 -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="BkQ5z/bs"; 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 S1728526AbfA2KcS (ORCPT + 31 others); Tue, 29 Jan 2019 05:32:18 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45801 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728402AbfA2KcQ (ORCPT ); Tue, 29 Jan 2019 05:32:16 -0500 Received: by mail-lf1-f65.google.com with SMTP id b20so14200915lfa.12 for ; Tue, 29 Jan 2019 02:32:14 -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 :mime-version:content-transfer-encoding; bh=sVatOVqMzKhR+NdEUtHoWq8wqeLbuPk9DS1DaHfqw4g=; b=BkQ5z/bsar4BaV3H/6CCzKP2xXlZJhxTPIuCqtSuhM40+xFZNJSI+Sz4KkTsfTp49G PqzlKrhLwzKSU+RuqzyCiNct5jw/wGWdZDZOH215YrtDYt2DLAs3lARs/GRvMiRtV2ru 53axMeWAzs/PRe8+C8xOydaKiNTsm73nN0aGI= 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:mime-version:content-transfer-encoding; bh=sVatOVqMzKhR+NdEUtHoWq8wqeLbuPk9DS1DaHfqw4g=; b=k/zEqdU472sSAjQxEjlTytYYdGk0MWWsd2q+hqtk0ey7ygwOx+vb9DftBHhGQ+7Abg aM7a2OaczMZl62h2O5vwxpai4o3VF9uQvpwgqG9nOmnbJKI97FF+pPj1ptY7RJiRsyyS P+hRBGAuOPkPUxpiZg3tLN4sd7jQ4ZncYikAT3/UNgBSwv2yGF5VDeNF2v9lq3M9gp/g SBsMPoOkw1v5OwaJm2zCu/Yh0yYIknYC6vsV3UVsoQrN53Qrrh3z4mPQZAWb0j7OyEu5 GjImPNS4ckQplD/5jJpGWL6AwckNCl4fVqLks2pD+u+Z+KqcdqfW0LpUXEaellrjTQza uGIQ== X-Gm-Message-State: AJcUukejWorUvESWdWKDCrtFxLROQeFwO6xafgcbkNrjdfVYQCZcLWNu dnqT0bOFTU2iLrZBROpKLq4RKg== X-Received: by 2002:a19:8c1b:: with SMTP id o27mr18961154lfd.90.1548757934028; Tue, 29 Jan 2019 02:32:14 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y9sm3471540lfe.75.2019.01.29.02.32.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 02:32:13 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Charles Keepax , Bartosz Golaszewski , Marek Szyprowski , Linus Walleij Subject: [PATCH 5/5 v10] regulator: core: Only support passing enable GPIO descriptors Date: Tue, 29 Jan 2019 11:31:56 +0100 Message-Id: <20190129103156.10139-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129103156.10139-1-linus.walleij@linaro.org> References: <20190129103156.10139-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we changed all providers to pass descriptors into the core for enable GPIOs instead of a global GPIO number, delete the support for passing GPIO numbers in, and we get a cleanup and size reduction in the core, and from a GPIO point of view we use the modern, cleaner interface. Tested-by: Marek Szyprowski Signed-off-by: Linus Walleij --- ChangeLog v9->v10: - Rebase on other changes. ChangeLog v8->v9: - Rebased on other changes. - Collected Marek's Tested-by. ChangeLog v7->v8: - Rebase on v5.0-rc1. ChangeLog v6->v7: - Resend with the rest. ChangeLog v4->v6: - Rebase on top of the other changes. - Renumber to fit the rest of the series. ChangeLog v3->v4: - Also drop ena_gpio_invert from driver data ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/core.c | 32 ++++++-------------------------- include/linux/regulator/driver.h | 12 +----------- 2 files changed, 7 insertions(+), 37 deletions(-) -- 2.20.1 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 48baa03ff3d8..bb688125ebd4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -2236,35 +2235,19 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev, { struct regulator_enable_gpio *pin; struct gpio_desc *gpiod; - int ret; - if (config->ena_gpiod) - gpiod = config->ena_gpiod; - else - gpiod = gpio_to_desc(config->ena_gpio); + gpiod = config->ena_gpiod; list_for_each_entry(pin, ®ulator_ena_gpio_list, list) { if (pin->gpiod == gpiod) { - rdev_dbg(rdev, "GPIO %d is already used\n", - config->ena_gpio); + rdev_dbg(rdev, "GPIO is already used\n"); goto update_ena_gpio_to_rdev; } } - if (!config->ena_gpiod) { - ret = gpio_request_one(config->ena_gpio, - GPIOF_DIR_OUT | config->ena_gpio_flags, - rdev_get_name(rdev)); - if (ret) - return ret; - } - pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); - if (pin == NULL) { - if (!config->ena_gpiod) - gpio_free(config->ena_gpio); + if (pin == NULL) return -ENOMEM; - } pin->gpiod = gpiod; list_add(&pin->list, ®ulator_ena_gpio_list); @@ -2287,7 +2270,6 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev) if (pin->gpiod == rdev->ena_pin->gpiod) { if (pin->request_count <= 1) { pin->request_count = 0; - gpiod_put(pin->gpiod); list_del(&pin->list); kfree(pin); rdev->ena_pin = NULL; @@ -4971,15 +4953,13 @@ regulator_register(const struct regulator_desc *regulator_desc, goto clean; } - if (config->ena_gpiod || - ((config->ena_gpio || config->ena_gpio_initialized) && - gpio_is_valid(config->ena_gpio))) { + if (config->ena_gpiod) { mutex_lock(®ulator_list_mutex); ret = regulator_ena_gpio_request(rdev, config); mutex_unlock(®ulator_list_mutex); if (ret != 0) { - rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", - config->ena_gpio, ret); + rdev_err(rdev, "Failed to request enable GPIO: %d\n", + ret); goto clean; } /* The regulator core took over the GPIO descriptor */ diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 389bcaf7900f..e511e9d1cc86 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -401,13 +401,7 @@ struct regulator_desc { * NULL). * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is * insufficient. - * @ena_gpio_initialized: GPIO controlling regulator enable was properly - * initialized, meaning that >= 0 is a valid gpio - * identifier and < 0 is a non existent gpio. - * @ena_gpio: GPIO controlling regulator enable. - * @ena_gpiod: GPIO descriptor controlling regulator enable. - * @ena_gpio_invert: Sense for GPIO enable control. - * @ena_gpio_flags: Flags to use when calling gpio_request_one() + * @ena_gpiod: GPIO controlling regulator enable. */ struct regulator_config { struct device *dev; @@ -416,11 +410,7 @@ struct regulator_config { struct device_node *of_node; struct regmap *regmap; - bool ena_gpio_initialized; - int ena_gpio; struct gpio_desc *ena_gpiod; - unsigned int ena_gpio_invert:1; - unsigned int ena_gpio_flags; }; /*