From patchwork Mon Nov 19 07:11:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151455 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324459ljp; Sun, 18 Nov 2018 23:13:43 -0800 (PST) X-Google-Smtp-Source: AJdET5dQ/1NiZOZc9mMsnSpf68Aw/frQTCZ9zWhsRz5Ct8ruGBd+pDIc2iN9zS9CWIyC3q3uIbG4 X-Received: by 2002:a62:3a82:: with SMTP id v2mr21652057pfj.174.1542611623796; Sun, 18 Nov 2018 23:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611623; cv=none; d=google.com; s=arc-20160816; b=e+8Nu8Xp/aUN9j3i8LZX8qoUBOZGNBQumHygz6CSxXKNMC5i7/NPd02wnOOQbF8RK8 VDLPCGG0U86OcankunpVZecG3VDMmi29plvQu27Peb4nZ5+53FVpHdZx2XRWpWgIJSfn VRGgzdT74UDrXdHjasZCTLm8VoZxu5JHn+9H9tO9I81FF/Lu/dE3bOdDrhotKmYETqTr MJIRVUPaL7+8B2mt33jxar2NaEjLJrVkK+Txz8Ot6jYfFqihuhLajf058hBpclBblD5I yrsTHPERuSOVMHcnbXeF/w0j91/qVbCsHDP42cNhvMzsbc+kltV5V0JHyNnQA16Qi9sc gWyw== 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=GV8wLt5hHfOL1c0DE6PwdhctUOmSHpPc3OI7fEiFzVo=; b=Fxyzqjuorwus0jIM8mgh5ibZL7DXj/9YFiFYqJ3KaAe4QYID2jlVsQfvlXwc50zIA5 4mSYZ1iNyiF7IJiVnxnL0nVzJ26OflrmUeiQ5aCacMo/eL35kBv5nwJkEJGiJV4kLq19 dAV6CR2Z7V4mUSaliZitQ23eE1nYN7ydmwQ+IALuEvV1j9VrCzTy2mBq/96vTFxhhxWV /h8lOZ9n1Uw+vuPG4Ux4/CcDOMFQ+5PGeNFUAfe+v1uq/A9WWh9ZTP/T3t4y0ZAegM76 u3iKVLHLwXP2nlU8ZeXRJqj0H0h67V2u/mpZhSRu/1z8I1BTGFFDKKlJ6Nt+9b8pZuoF MGig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d/EKaOm2"; 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 93-v6si13123500plb.17.2018.11.18.23.13.43; Sun, 18 Nov 2018 23:13:43 -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="d/EKaOm2"; 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 S1726289AbeKSRgY (ORCPT + 32 others); Mon, 19 Nov 2018 12:36:24 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41075 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgY (ORCPT ); Mon, 19 Nov 2018 12:36:24 -0500 Received: by mail-lf1-f66.google.com with SMTP id c16so20530814lfj.8 for ; Sun, 18 Nov 2018 23:13:38 -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=GV8wLt5hHfOL1c0DE6PwdhctUOmSHpPc3OI7fEiFzVo=; b=d/EKaOm2UTUeiE+fj1M0Et7OE+b5+32J1IkMNHIO3wO+FyjA6Qopj41GhDqRo1qr4i bhSu5LE/X2O55xFA3p0ZRnsBQvp6qVOsk05JaG1/5rnChDjGZ0mmTkTyGbAYrED0DFO/ 3x8AkfEWynPjSuepsLEFgiAKXI6J4NouRW0GY= 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=GV8wLt5hHfOL1c0DE6PwdhctUOmSHpPc3OI7fEiFzVo=; b=k9APgV2yHsXpS+cofmoTAm0DZtkpLQMMuQ3NU21aNv8iibUGJfVnqULw1r5y7kkfNO /7V+mg30ZCw0g7fAjXVlzpKryUTjhdr5pMs77WJSAEqUQZ1h974Gwju2EpZga5gXlr5I FP5MfNHLoBdArJ1AyAVHCyVEXyOEUB45CtyOk+XcZKIELfAvT5ecL8BhQiXbJwKqFcNt TQTpFExhb8z1RZwQ6ut3oIsx55nTyBMbNlIkxOduKOFg6q7guWiqZJZN84uAXAdLwSMy zhH+J6MOuIGHdX31Vdid0Jjln7DHtokExgm0oEivaSojIBUrHRgvdeVXfopdAYRr2lYG nW6w== X-Gm-Message-State: AGRZ1gLMBbqrZEXVPqAzdb55ppo3VCo04bmJWlGK06haPYW/qzWfbVSF vky2RjjHooO7xCZeQtxNQpmZJg== X-Received: by 2002:a19:750a:: with SMTP id y10mr9796997lfe.43.1542611617636; Sun, 18 Nov 2018 23:13:37 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:35 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Philipp Zabel , Petr Cvek , Robert Jarzmik , Paul Parsons Subject: [PATCH 1/5 v7] regulator: gpio: Convert to use descriptors Date: Mon, 19 Nov 2018 08:11:22 +0100 Message-Id: <20181119071126.8889-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.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 Signed-off-by: Linus Walleij --- 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 | 146 ++++++++--------------- include/linux/regulator/gpio-regulator.h | 12 +- 4 files changed, 91 insertions(+), 113 deletions(-) -- 2.19.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 14c0f80bc9e7..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) }, @@ -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 */ @@ -1007,6 +1015,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..68a6c861bcad 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,17 @@ 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; - } + 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 +272,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 +299,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 +309,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 = devm_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 +337,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 +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 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 Mon Nov 19 07:11:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151456 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324602ljp; Sun, 18 Nov 2018 23:13:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/VS8okN0h9DfC6m66RtzopixBZYyxFchK5vHOxzb67oZwZ5R4zNb6oR755Xp13XM2zqc0NZ X-Received: by 2002:a63:20e:: with SMTP id 14mr3484185pgc.161.1542611636431; Sun, 18 Nov 2018 23:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611636; cv=none; d=google.com; s=arc-20160816; b=HuBx3RZPcEGGRwl/hUgtDFsDrVZjAVthl/wQ3qB++IOYH85XxciwlhiiJqnVqOP118 ht5cZRJL18m6TLe1cUtxMKwpCbkyom9//gQcK9f0RSHY5tZbxCQAasBy+0RN0Zzbi2w4 ZDn+5SH5e8xsOWPINJaGv9j5IQsTH9gsbczjz70ZjLRc5sqW/m41xHOYxUxrNDAu10zM FWknKvwqrwkmLvM5xIL1FspyjG8xH8Eex+SRz9hRUlrViUYYbfrYyFpO/llQycCaWQqe 6fsOCcdDs2S+KohwpKLIG7voHMK/cheIBMg+wjzbktcby0EFQcfgPsmgVIYCBR6R5YsG Ffnw== 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=OwX0jEa0UnMiRsgnGBjEdRBChwNBGU04OLNhFUV8CEU=; b=zI+GyHxDWxQp6luPA1OgC7lMlYSSYYrE1pJlOGDl3CnJim+D2dszV/SA/Vq9bDtfRC L559QD322htOd0GpLKSpdvQPR9D3uzCogg0tq7A8JxSEi6LeYvl0xbXt0bseWn5NVb2L zXxCzh0nya4WV+ahBkaZuvb2OqmpDAScvHSV1k4Glka9qQ6p0JkicMaKAqbtEzjOY67j uA3Dh9WlwVfRDGwLBKaAbw7QLmDVG2xLwO5fS+dIvCDHA3bePQWXv3U5CXi9149PMaxK F6Om4ksXlFkyzZI+ukCgDraWOpUfmalfuLEPc8Yn/8s5b/CoxOpcCzVp4wp+YYNpisiA tSuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jgQw9CMb; 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 e13si38944719pgh.251.2018.11.18.23.13.55; Sun, 18 Nov 2018 23:13:56 -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=jgQw9CMb; 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 S1726418AbeKSRgi (ORCPT + 32 others); Mon, 19 Nov 2018 12:36:38 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40651 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgi (ORCPT ); Mon, 19 Nov 2018 12:36:38 -0500 Received: by mail-lf1-f68.google.com with SMTP id v5so20533359lfe.7 for ; Sun, 18 Nov 2018 23:13:51 -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=OwX0jEa0UnMiRsgnGBjEdRBChwNBGU04OLNhFUV8CEU=; b=jgQw9CMbKjE+G0HSIkSNQbYdA485gyd4UdKh2HWh/maklG6H/i/fZPyZK9NHsN98ON 6bkAPt/u0JlqxzMcbTR8Hadj9fTziBf+0bVCGe3psKlQf72wBcc0w2WXEMs3Msh9ngMY Bzp66YEsmQbgWxCpNi3r53RE54N0l04KegsAI= 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=OwX0jEa0UnMiRsgnGBjEdRBChwNBGU04OLNhFUV8CEU=; b=F3uMPi98IzE/9t+B7vz/XCV1KxJox79pa5W/ie/aD6aCt371gWd7YaoCEeYU4tdLbX TXiulBXcPj8CjaEi2tPHplzAjxCpovxvqdoLGspD+qh9lpzosSMQZw8K3T5uRF3YCzPv PzWfqGfZyN2pMbqAdP+/rVvvgxXJebpYg9yl+r7utHXFzf4nkL0eAYZ15TLS2RuAgEg8 87ZaTavskGk/DcA7abazNCq0e4/lEAcwHlz5O5ZxFttVTEqxU5cTUJj0/PjkMY6KPhaY pKLiCDba2LINHTUX5lh2beoaJrlTgeJf4nVfw2S1EYEGD0iP0AeXfUuFG2MMYgILXzd7 TEgA== X-Gm-Message-State: AGRZ1gKwtHuBAJlooaVtybrKYTSdoNXWaKSQk6+jCrflL/NunBrNtmno Ojk6xymrOtXvsJHhRiE9elPpqA== X-Received: by 2002:a19:4402:: with SMTP id r2mr9623000lfa.111.1542611630929; Sun, 18 Nov 2018 23:13:50 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:49 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Janusz Krzysztofik , 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 Subject: [PATCH 2/5 v7] regulator: fixed/gpio: Pull inversion/OD into gpiolib Date: Mon, 19 Nov 2018 08:11:23 +0100 Message-Id: <20181119071126.8889-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119071126.8889-1-linus.walleij@linaro.org> References: <20181119071126.8889-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: Janusz Krzysztofik # OMAP1 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 Signed-off-by: Linus Walleij --- 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.19.1 Tested-by: Janusz Krzysztofik #OMAP1 Amstrad Delta 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 3d191fd52910..26e9b5969b0a 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -268,7 +268,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, }; @@ -529,7 +528,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 9fec5f84bf77..69a9182a9aff 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 67e37df637f5..97f428e3b77a 100644 --- a/arch/arm/mach-pxa/em-x270.c +++ b/arch/arm/mach-pxa/em-x270.c @@ -984,7 +984,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 bd3c23ad6ce6..cffa182167a9 100644 --- a/arch/arm/mach-pxa/raumfeld.c +++ b/arch/arm/mach-pxa/raumfeld.c @@ -886,7 +886,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 d53ea12fc766..9b8c2cf23111 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 3e8c0948abcc..3723d70af471 100644 --- a/arch/arm/mach-sa1100/assabet.c +++ b/arch/arm/mach-sa1100/assabet.c @@ -468,7 +468,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 06a894526a0b..ffddec161292 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -633,7 +633,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, }; @@ -674,7 +673,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 dbfc5cf2aa93..e3b57c346f3b 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 2c66b528aede..109bd2bee868 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -80,7 +80,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; }; /* @@ -2047,7 +2046,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: @@ -2098,8 +2096,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 { @@ -2110,8 +2107,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 ccc29038f19a..adaac8f5ddca 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 Mon Nov 19 07:11:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151457 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324634ljp; Sun, 18 Nov 2018 23:13:58 -0800 (PST) X-Google-Smtp-Source: AJdET5eDHRbVRQp2CbYrR/xG1CzNBJL02GgITDkFvVDeJwqTLBvgmaFYzft6cJsncfM/BTH2dnYp X-Received: by 2002:a62:c101:: with SMTP id i1mr5508004pfg.80.1542611638494; Sun, 18 Nov 2018 23:13:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611638; cv=none; d=google.com; s=arc-20160816; b=ntQdGeNPi4rcK4/+UaTUUt1anv6Hyp0uXrTdS5yrBnBI1A5BMTYEEaOsgixZ4jXtQY FsAu34ZgXPDy6sdTHnMoQ+dcV+mL8tdS2CiGcpI3g5A1xHccNAeGBaWBDUYR2LSz06hB dRxGV+b0y8W1rDF5HRYBSjYjzO7QhuHWilbLtfm770nqfvY9TVHZjorNrBH/O/xHa4GS OemPYT97I+fzavh2Kx57ZtOCMa5nOm0LipE5qB2KU6caiVNinSDkOVWm0xBvW5tsPWzL V0HdprzigN6QQ7wyOPWUMJZCSPYcEcMcjRadBcvo6CdJbXhdRwKxPeqvyJjk3L9+uHFV UY5Q== 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=IBb3a4hWtaHZwpV0DBM1ehv0fImjohELlIgLSGXL7yo=; b=iK/AxrqBdE7fQ+HgF79cUKRZUQZcMCnCRNfPu4lA+VZvelghNFsfsene29Fc4Yphab fb6qtUkg14EG2qjEkKabHVol5g+3wmBe7Ece4znVOI8NtBrYUnhCL+9tDJYSIU8568CN K0nSOM2cuL4tXWNstHqF5AgcDh4GM0yBAiysLB4z8EIAZ3gcnzI+6hXR2DNg15mOpQbr eVuX5+IPPg9NAQJDOEpFvjg2gpa0RJZlpAjSkQ8e6K6wyDN4RTulOHeIbdkBrJdnjPY7 g0tXf7d5LZAYRyL/HcySoxsxkn4UuaKaekYYq0M3FTHnWI65WK4jETkSiuasIfsyL+E2 yhFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vc1tK/1t"; 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 m14si38070957pgd.326.2018.11.18.23.13.58; Sun, 18 Nov 2018 23:13: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=@linaro.org header.s=google header.b="Vc1tK/1t"; 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 S1726453AbeKSRgk (ORCPT + 32 others); Mon, 19 Nov 2018 12:36:40 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34579 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgj (ORCPT ); Mon, 19 Nov 2018 12:36:39 -0500 Received: by mail-lj1-f196.google.com with SMTP id u6-v6so25208582ljd.1 for ; Sun, 18 Nov 2018 23:13:54 -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=IBb3a4hWtaHZwpV0DBM1ehv0fImjohELlIgLSGXL7yo=; b=Vc1tK/1tr5TVqXv1yFSwORx/LydYEsKqUN6t5rFAZDLbqkQQa2/5ybvY97fW0N6qsA qNq6ogqDH/W94s5NKhzcRSha9xkbtcjJMb2D86/sVVqqZQLrgvA2t6KogSdf/lQ63PPF zX7SCa18Quqhj8f6hqTFpFXo8JYBRjYHUHsPI= 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=IBb3a4hWtaHZwpV0DBM1ehv0fImjohELlIgLSGXL7yo=; b=iLnBaW36EiZBOZr4GN1i2Ez465CPKv9uh1OSvDf0V+2skaSjnagZjOtkblkku+fsad el3Yi0eky4HUO/rwcJyjmT+eilJ3uDr54sKdxcfZCt4AJg/OXDr/Q8jxeKzKz+Asf/L9 zlSMxxu1u3X107ZAzxZREZ4y6FP7Id0+Q5jxDt6OwS3W5QMT3nuEPGTpY1z46vRqhOOE urL/SfBaW0BcorqrB6zQ6FLN+/MKVf7i/3xk6jcq3pJTz2fPB3mbHFjAqWWpF5znNtLI n2+Veo7UTvNFXQ7xem0GRWsXKPfXSC6o5JKZn8cRk1+aZHaR3Xlv1sNEfEZkXAYLy1vq 8QTQ== X-Gm-Message-State: AGRZ1gIxkZKNe0MO+SS6eRuz6mY+2z1fQ1rjd2R1TEGzxxVSiZuc1vcw tACHzfA/SbOdaG1MLI2Jq5hPmA== X-Received: by 2002:a2e:8007:: with SMTP id j7-v6mr11047186ljg.22.1542611633409; Sun, 18 Nov 2018 23:13:53 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:52 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , devicetree@vger.kernel.org Subject: [PATCH 3/5 v7] regulator: fixed/gpio: Update device tree bindings Date: Mon, 19 Nov 2018 08:11:24 +0100 Message-Id: <20181119071126.8889-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119071126.8889-1-linus.walleij@linaro.org> References: <20181119071126.8889-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 Signed-off-by: Linus Walleij --- 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.19.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 Mon Nov 19 07:11:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151458 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324661ljp; Sun, 18 Nov 2018 23:14:00 -0800 (PST) X-Google-Smtp-Source: AJdET5dhmm8hsB5TuVivgKVqk93p72SMr4V+OuHDlUNA2VMKpGPFI4obT2YhMXkpyHzPy/LbVT4X X-Received: by 2002:a63:cc12:: with SMTP id x18mr18930590pgf.33.1542611640149; Sun, 18 Nov 2018 23:14:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611640; cv=none; d=google.com; s=arc-20160816; b=XYfeFlG4zZlGCsBxrFMZYLXfUSoZT9OXThrD6VYa5kZqRba93ViJ34jj21A2yA+sPw vbF7iRlDrPr24X9WQPhhS0pn0cT1E/8UULRTBAO/7nzFfHRZcUGYDDD3dFNCH8Y3IocH TKqOB/RpocOtYjvoKzjBEtGQqWFHAIIDpTv8kzFFft7ab5NfdDVWoIkyJxonV3Dscbi/ aX4rd+JAk1+mLx+b606nq/EJM1pU1Pyo9Y3I/wqvjlOTacEo6cfY9gxBFssOrtFefbPJ t9HKxPI2VkF1+BpCmUvneTdY5gMC24zLLESqAq9aJnfNFE9jkQCohlqERXahElI1vS13 dEGg== 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=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=anQ/4AbGU9z68mQWo/UP9iyZDLYiRUU15gVXbQ2oidc7E75u3amU5P1SivuWagfOsw INI7RJsuTPWQDQmwk5zYWooLiFHlxozX2z1rC8cLoifve+wJvjtHE6h2UzsowM48R7Cs XGLhcOyi86Qp9Dnbga8WW7r/PEIuFGl2Mv7tqxrIOG3Gz5zoqy9qreZMqyXrvhHwBDvZ mA3c0BJnSKi2mjPjLCoavdSArm0w94spT6MjGqa5DepxUpyrmksOfgGTFxeyfkIX0930 Dkeqzssqohli4ZPmmjO0TNwU+fttQc0QImOVix+riwWgrWwBf0VeXxq5g0uGQ1/zpQla agZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UK/JftDz"; 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 m14si38070957pgd.326.2018.11.18.23.13.59; Sun, 18 Nov 2018 23:14:00 -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="UK/JftDz"; 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 S1726487AbeKSRgn (ORCPT + 32 others); Mon, 19 Nov 2018 12:36:43 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:36059 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgm (ORCPT ); Mon, 19 Nov 2018 12:36:42 -0500 Received: by mail-lf1-f68.google.com with SMTP id a16so1748248lfg.3 for ; Sun, 18 Nov 2018 23:13:56 -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=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=UK/JftDz+v2wFpUjHxntmp6dYZ7V7+B+3gDnJjFatuJdvxvVbVz/4tv19pshN8Jd/z mAeBfhfBDlSJK5jMC4xVAUyuKXZg1HoPARR6/ZSbEI79iljdL7U+EGp3YhN8u/RS069O fMx2JJXwkmLbKF2CbLv8xo+HBbFnS511AqvSw= 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=D+3HHA2utaAOxxvaeBViU6uUuc9KWnMizwi/QFCDndE=; b=bM0PbJtZUp9lmc3eBo5qoJPi6pDQjK+evK5HIPXtHpPpkCF/2LrftXPIAPAnJEiMG3 FUazHvzRokeRtxRHbt7/PmgVJ3Ek59E1X8Ho2gWk3P0uguu1xSi5t8tLF8QHdUbCmyWV rQtmjvewRO0bp16YsL0mhlwS8/uU2C0s0qCsceZQDpjWj33i3mSlK6iw8P9yyXn2zecJ PTtnBPM/EihMrWj6o1gHyRabOhsolB1WEfBnyXxVB1U8ZZWQ0q92b4cZfIZ+RlxYEbGb jh0bR3R6gY0dlBFd/n34ZJYKbdvfUbAMJCetUZVE3IH/uhh3uoCyUPaRGuv/S0BF0H65 c48w== X-Gm-Message-State: AGRZ1gIB9E5CTaFf6twmZyA4MvjRr1aXoZN19j1xO7mizi0zrg2pRICV pSIce1AjIEldpT0/kyuLsA5Geg== X-Received: by 2002:a19:a9d2:: with SMTP id s201mr9603189lfe.154.1542611635934; Sun, 18 Nov 2018 23:13:55 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:54 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 4/5 v7] regulator: gpio: Simplify probe path Date: Mon, 19 Nov 2018 08:11:25 +0100 Message-Id: <20181119071126.8889-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119071126.8889-1-linus.walleij@linaro.org> References: <20181119071126.8889-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(). Signed-off-by: Linus Walleij --- 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 | 55 +++++++++++++----------------- 1 file changed, 23 insertions(+), 32 deletions(-) -- 2.19.1 diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 68a6c861bcad..62ddea4a5255 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -228,31 +228,33 @@ 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; } + for (i = 0; i < config->ngpios; i++) { drvdata->gpiods[i] = devm_gpiod_get_index(&pdev->dev, NULL, @@ -265,14 +267,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; @@ -291,9 +293,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. */ @@ -304,7 +305,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; @@ -318,28 +319,20 @@ static int gpio_regulator_probe(struct platform_device *pdev) else gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE; - 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_memstate; - } + cfg.ena_gpiod = devm_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) @@ -347,8 +340,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 Mon Nov 19 07:11:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 151459 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324700ljp; Sun, 18 Nov 2018 23:14:03 -0800 (PST) X-Google-Smtp-Source: AJdET5eK5paiqEsDbup4aCh3u5dqaKJso/7E7xzbN6P7+JsWMfHD+HYt3tiLyO53Wk354sbskJdJ X-Received: by 2002:a17:902:4281:: with SMTP id h1-v6mr21316433pld.114.1542611643313; Sun, 18 Nov 2018 23:14:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542611643; cv=none; d=google.com; s=arc-20160816; b=bgxJgeqbj6qgX0QBX/iODzI5tdGWuYD85KRpysHgG92EOWkXrE4xeuibKaW3KagHV+ mPsA9dYFZ8MFqMQ3DnluNEWPUsNFb3QBTygqcJHop563dfWQnG9a4P3jTbPBv0gkaiWd Fw7VvKNx378W0DkBARV0GRJHSIMKNmDawB2+7OLN6l8TwwgnKVx1sdEvHmClZojb0HYd 506/3lsGf1X+vKo7kMsJAd6MYH2ie59gvanu7J+g3mwCXnPavou9KMcMLg4SnLwIqbiz Qpa9DH74/emRvRU4Vvg6sX3Nrl/NvSczy84clkAa04zBo/ivoCL0TOjVC+9aeG82kw39 eRbA== 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=HzVQH3GnZ9LsCDHn7VdhoAmsZdM0gU2UOjWOy4fiQsI=; b=qiyJRK5fSWdxm9nexewRq2AWaSOIIl5Mo065kCWnDuD/wqAqsh1Chx+dpI7NT1/kmp LsXR3KDaU3SvszUYMG1leOCyzPuj8KV8zJGK1KdcuufxeTsdpBbCCvJ/88fRb3VYUkP9 buZySjjncY+yR1EH0XTcS/bVc2QrKuZS7zUPorffXCBPJllgyIHHLOH/O8vLR2WLBKz6 +Mm31fGuSDkL5anJBKIQyaCckFYKGHbzAYKxI3wMBm5GfFjhmKXRhUz2BBylnRaYh5gT OgHXxgOeP2npfbMqlAYGWfBm52RIp0XRVHvMbBUXem+a6DWSdAexi5JlJr2YyDwzNk2i aB1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IkyY1tVY; 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 h1-v6si39716231pls.281.2018.11.18.23.14.03; Sun, 18 Nov 2018 23:14:03 -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=IkyY1tVY; 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 S1726540AbeKSRgq (ORCPT + 32 others); Mon, 19 Nov 2018 12:36:46 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41916 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbeKSRgp (ORCPT ); Mon, 19 Nov 2018 12:36:45 -0500 Received: by mail-lj1-f193.google.com with SMTP id z80-v6so25198046ljb.8 for ; Sun, 18 Nov 2018 23:13:59 -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=HzVQH3GnZ9LsCDHn7VdhoAmsZdM0gU2UOjWOy4fiQsI=; b=IkyY1tVYjgSxidfHeFLxGdGZ4JSkDBShGUQc1WVmgJkTnW+gaLlP/gm4RDsshqodjO hcvKI0yzW3rusYH+kvcqei3qdPi7nJzO9lJUaadnnmacYQzQEhWoLaZSJ89z4e0GCHw2 a+4OeU4DmMRSXc/xITvBMl+KNbD60qNW1miZo= 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=HzVQH3GnZ9LsCDHn7VdhoAmsZdM0gU2UOjWOy4fiQsI=; b=jipIGBaPkplzDJoOVHGqUXIbvGe8jiKShxln8dWWStzy4T14VZ5g8F4WceR50zKBTz 5P9qEwvePKE24AwT02r0EIMCetNg1cVZoyDTSQDpw0zHwI0dLAlmlJHs0voHPL2+2pfD LjOob7L1Paqx9m81A6cioFS/y6SOjnhl7L92/P2nQWatP4x63HDzXCMI8AE1kKwh4Lot w6UoFFpG6ZT8+nMf9BH/By3/T5y+ETmL9zm6mps0HnsI9/xR58Hg+btwgWi4oUcNzCAX 3hTNKmJ9l6OoKauWcCr+YVYusdoJci03wPFNxVvAvdQnX5S2cGdKlhJcS1gdTBH8CZz5 0foQ== X-Gm-Message-State: AGRZ1gIBUXZihHPdS9jMKKq45e5L6cYWf8jlDCrhjhTirVQhapwkGf04 ZU8P4KHV2nTaEbbuOEYWN366ag== X-Received: by 2002:a2e:2166:: with SMTP id h99-v6mr10379161ljh.53.1542611638438; Sun, 18 Nov 2018 23:13:58 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id 10sm5531584lff.62.2018.11.18.23.13.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Nov 2018 23:13:57 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 5/5 v7] regulator: core: Only support passing enable GPIO descriptors Date: Mon, 19 Nov 2018 08:11:26 +0100 Message-Id: <20181119071126.8889-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119071126.8889-1-linus.walleij@linaro.org> References: <20181119071126.8889-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. Signed-off-by: Linus Walleij --- 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.19.1 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 109bd2bee868..0eb5c48f1162 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -2015,35 +2014,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); @@ -2066,7 +2049,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; @@ -4336,15 +4318,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; } } diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index a9c030192147..10ee158eac00 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -400,13 +400,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; @@ -415,11 +409,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; }; /*