From patchwork Mon May 14 08:06: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: 135669 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1439098lji; Mon, 14 May 2018 01:07:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpRGpRcxa6NfjM4zhrS8h9uj/0/c/YLpqDN2YEAY63FIx33/3YDmgq8edeKbr1DU7S66jFH X-Received: by 2002:a17:902:585e:: with SMTP id f30-v6mr8747765plj.50.1526285223595; Mon, 14 May 2018 01:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526285223; cv=none; d=google.com; s=arc-20160816; b=Wo6gv5rsx+qEUpjDhNsTn+czltgOXUW9r7SbWjZxFgkj7wgu1/hEyT0FebzMbyQ3hz bfAYXEEEhrsp/R1PNLjAa6NM2f3ZQ3xYeC46Yvty1hwF3Q5R15i/y55T4bNC3Y2Ya13G GRJF5bJFk3ac8upcXrApPz9KnjrdxHVQ07pI1/2XodOUiaZ+T6Qoed2NZdVYKyGW0xTu Yrn88LJuyU1tjoMFjtje/2syeZFVCd8/ZaX6gBuHD/K+nP1tIKaMlyD4UuywHSXzBNn7 eG/iKIhilWOd7N/OnFP8PQFKePDdjVP94Vvs/a5PQ4ikPzmBnae6SiWsClcK3ABaZVbb lj2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=HqLIC+WFm2iVOJGu9EtARwz57472VcP26ZroaLfea/8=; b=tgJfU8yl/r54xtTkbmCMcsV1OfeIWinsWJUUQrTvUERW0Yh4CRM0D6MnkLv995FmxN mkVu2l121MF/S1Js8SpWKKRgLg/UK3dQIWxprm8L4v/e1r0/3BH2jvTxzPu8KJh//5/P 3ZL6HBp0JJiB1TxJ0mY6nVxE3ScjwLJBIykEdHlHhs3UIgFX2rW2shYzEvflmEErmSDp r0atqttnXULBXqO3GYu4dYk12aDpSiflEzpmBVPiPy/JhqTEJIp9B5EfotkzSG3pMviX XjByRxQP8bHuJo2ExGZMnFZjRbGNWv6JOLyb26NzIpCkV1lccWWmAvVRi725r12fFiKk NcHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N7dNssyG; 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 75-v6si7154566pgf.653.2018.05.14.01.07.03; Mon, 14 May 2018 01:07:03 -0700 (PDT) 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=N7dNssyG; 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 S1752168AbeENIHA (ORCPT + 29 others); Mon, 14 May 2018 04:07:00 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:41445 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbeENIGv (ORCPT ); Mon, 14 May 2018 04:06:51 -0400 Received: by mail-lf0-f65.google.com with SMTP id m17-v6so11386975lfj.8 for ; Mon, 14 May 2018 01:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HqLIC+WFm2iVOJGu9EtARwz57472VcP26ZroaLfea/8=; b=N7dNssyGBr0BhVrGEW/CuiiqqlzKNtE83k5E3Gjj8wIPIDswKtfYwkX+koVocZugZ5 A3liwRAPNRHZHViF33CS/+zbYhwtR8vPzc6lMjtTBIREKPC4AcvGd82fCfKMhgpv9Mri 5/CvCuKKemFw8w/yL9wq548SNeHhlUcOJZ0OA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HqLIC+WFm2iVOJGu9EtARwz57472VcP26ZroaLfea/8=; b=ekJefdKiTOv9NHOpd0O2hDYRndx8CWb3fpf2PiZ4HM/fif2rzqqW+H4yMcXF9FDpdE HXWRKQTvg9YNr4TQOU+sV0EvcVGOMp8QPNMV2lP5U6t0L+BW/OWODgpuSWqG5WujlNlR Xx3+bvbzPOb9MoSv6bm5+sUxOqwvw91Lt780k2C9Hpr0g4eSQtGG1NI9CEiQpZVVPFQy AxiknLLt777poojUaXVpwcM6Ip5dtU621nlVdTpdoO2EYfz2d3l51hbJXtxeWCDpwBl/ yL0iMt+qsSYNlhsf9xW+OlAMKMU7Tl32itnAQQMGSW0CUfzWIOy9hMjcT18u2cutfcfs 8sjg== X-Gm-Message-State: ALKqPwcl6j3619GAzKeiv4rW/MKlQvb4ldr533pAw64iSsTx+2pGBlnQ aiy576dNaDZZtpD5MdodtenNn5Bc4uc= X-Received: by 2002:a2e:89d7:: with SMTP id c23-v6mr3887480ljk.22.1526285210129; Mon, 14 May 2018 01:06:50 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id s4-v6sm1725265ljh.9.2018.05.14.01.06.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 01:06:48 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Philipp Zabel Subject: [PATCH 02/19 v3] regulator: gpio: Get enable GPIO using GPIO descriptor Date: Mon, 14 May 2018 10:06:23 +0200 Message-Id: <20180514080640.12515-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514080640.12515-1-linus.walleij@linaro.org> References: <20180514080640.12515-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We augment the GPIO regulator to get the *enable* regulator GPIO line (not the other lines) using a descriptor rather than a global number. We then pass this into the regulator core which has been prepared to hande enable descriptors in a separate patch. Switch over the two boardfiles using this facility and clean up so we only pass descriptors around. Cc: Philipp Zabel # HX4700/Magician maintainer Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Resending. ChangeLog v1->v2: - Rebase the patch on the other changes. --- arch/arm/mach-pxa/hx4700.c | 12 +++++++++++- arch/arm/mach-pxa/magician.c | 11 ++++++++++- drivers/regulator/gpio-regulator.c | 23 +++++++++++------------ include/linux/regulator/gpio-regulator.h | 3 --- 4 files changed, 32 insertions(+), 17 deletions(-) -- 2.17.0 diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c index e2e7f247a645..6717a10180eb 100644 --- a/arch/arm/mach-pxa/hx4700.c +++ b/arch/arm/mach-pxa/hx4700.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -711,7 +712,6 @@ 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, @@ -733,6 +733,15 @@ static struct platform_device bq24022 = { }, }; +static struct gpiod_lookup_table bq24022_gpiod_table = { + .dev_id = "gpio-regulator", + .table = { + GPIO_LOOKUP("gpio-pxa", GPIO72_HX4700_BQ24022_nCHARGE_EN, + "enable", GPIO_ACTIVE_HIGH), + { }, + }, +}; + /* * StrataFlash */ @@ -875,6 +884,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..9a5bda3ea194 100644 --- a/arch/arm/mach-pxa/magician.c +++ b/arch/arm/mach-pxa/magician.c @@ -657,7 +657,6 @@ 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, @@ -679,6 +678,15 @@ static struct platform_device bq24022 = { }, }; +static struct gpiod_lookup_table bq24022_gpiod_table = { + .dev_id = "gpio-regulator", + .table = { + GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN, + "enable", GPIO_ACTIVE_HIGH), + { }, + }, +}; + /* * 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 a86b8997bb54..9d6094c4d71c 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -161,10 +162,6 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np, 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)) @@ -255,6 +252,7 @@ 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 = { }; + enum gpiod_flags gflags; int ptr, ret, state; drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), @@ -340,21 +338,22 @@ 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; + gflags = GPIOD_OUT_HIGH; else - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; + gflags = GPIOD_OUT_LOW; } else { if (config->enable_high) - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; + gflags = GPIOD_OUT_LOW; else - cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; + gflags = GPIOD_OUT_HIGH; + } + cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags); + if (IS_ERR(cfg.ena_gpiod)) { + ret = PTR_ERR(cfg.ena_gpiod); + goto err_stategpio; } drvdata->dev = regulator_register(&drvdata->desc, &cfg); diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h index 19fbd267406d..536cab86f2d5 100644 --- a/include/linux/regulator/gpio-regulator.h +++ b/include/linux/regulator/gpio-regulator.h @@ -44,8 +44,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 @@ -69,7 +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;