From patchwork Sun Apr 22 23:07:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133945 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp370467lji; Sun, 22 Apr 2018 16:13:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/fw8F9+06w+17zz4RwfUTjMvGQBlVUyzRqo9zdcZ8qXoUEGgrZBi9cztNSztjifJlVytgt X-Received: by 10.101.101.136 with SMTP id u8mr15638752pgv.333.1524438804020; Sun, 22 Apr 2018 16:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524438804; cv=none; d=google.com; s=arc-20160816; b=U3/KQOlfA5+SLWIwztT5S1KGILfsJBBo2f77TSOsfS3Ud4COcKKys5f7CsrY1qyRpE N4shh4IA++FexgH9xzk3YI3lWnpjzXz826KYsEYYkVycrBd4MEMRmBfKJelye5lIFr5V yqb5FreSbc7kIA/1fYEFW+b/T5VhuFJLbjx7qRzT7lgcwZXsNvgS0UEX/GdR7wC4hBX4 szhlMmpcJS9n1BPE0OdrNjkboeS9txHMu7kZx2fesNpPuK3ThArSCISxDnCfoB+KOa2Q O2N8TKkwkUkjeQVa4pgbXf1o+1dxu0JFTm+MURdWqqK5x8jwLn/vq/Q7kAufMMSVfo2h T4bg== 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=KNPDKQdHQ4VwCTuf88fkbPqvezjOX6gJ4Bh0LZDUsh8=; b=WC1rgwf6GPpWrS0JMOf7EsWbeJWYe22pevwWCBatRKUx3V76NVu/VLFgfZLUA7sdw5 eXS0mV/Y12UDuzPwOPIPsyL96+wUcvD5EqDOd9bFcR3X8JvvZkjiIwXJtZoTtxqBVGMF xbfu8pddzSvL9up0PjycyELJe8dGj5iAxU9ekHhlOyQM4Ndro5+LGpPB70NsICMxmzOF vhQOg4qQpaBpkGtvuptV1naZvPPnY++1XLEkIXbSfZIKUAtMpvxKWS+Vh9Tz2AwAAtpa AGsLjAZ1FNhsMsvaTR0Ll9LqLFpTN6FMpSt+7xDpTn3zpEuIlC5Kh7Xg2vGeSLRwMY9h er0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K78qv2j5; 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 90-v6si4474610plc.205.2018.04.22.16.13.23; Sun, 22 Apr 2018 16:13:24 -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=K78qv2j5; 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 S1753946AbeDVXNU (ORCPT + 29 others); Sun, 22 Apr 2018 19:13:20 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36801 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753728AbeDVXKA (ORCPT ); Sun, 22 Apr 2018 19:10:00 -0400 Received: by mail-lf0-f68.google.com with SMTP id d20-v6so12234706lfe.3 for ; Sun, 22 Apr 2018 16:09:59 -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=KNPDKQdHQ4VwCTuf88fkbPqvezjOX6gJ4Bh0LZDUsh8=; b=K78qv2j5zYuh4Itr7Uaa+YW7U+bLS3EuFzbQldOe1EZ1gAx/jfl0LhKxNYWEuYFsO0 f2VYO/1psO5ritQVc6+0GBGR/jGJ4w8OZbj3wZa99Vms/oe7pms94xRHtggTdlON84wq YruwMB59hUTlCtAuyv5VWhilCLe8X5LFy+2/c= 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=KNPDKQdHQ4VwCTuf88fkbPqvezjOX6gJ4Bh0LZDUsh8=; b=eruoUp1Iu/enYwDYDO54Gdj0lphrQiUNE3qaw5ZvgfusWjlC/SyX2cLv8Hy7/9GOX3 60QAmNsmQmtIbDY6l71JJK22ipj7hDWRW0xRqjq+9eqsMTSQolfMACuLO7vWJeOJYR1X kRTBkRmHuumUGch51FxnHt+OiFJ/t7Tj73C/EbJ/8a1KxcIlgws/HYwggcCbPDhkbeHM OmFQiz6nvIllQWic9Zoo2VVFgWNbyDz0kZ84lz70XzD2/H4GgcvSUOUaR4jn3GSAh6ln vJt/EfCZMe6pYdGuCiH50DEUH8cww8QMQEA+5Fr+1KyWVVEma6iVtp5NDb4ApppjCZft BgsA== X-Gm-Message-State: ALQs6tDif7qf4Aodn+W34iSYGNC8+pLXYGD00RlnvuyKpVOu+ndCo0zw Vtmwi7vEmaQZUyDZ9SnOuwTZkA== X-Received: by 2002:a19:8e0c:: with SMTP id q12-v6mr7797255lfd.95.1524438598846; Sun, 22 Apr 2018 16:09:58 -0700 (PDT) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id r25sm2036291ljc.8.2018.04.22.16.09.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Apr 2018 16:09:58 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Cc: linux-kernel@vger.kernel.org, Linus Walleij , Mikko Perttunen , Laxman Dewangan Subject: [PATCH 04/18 v2] regulator: max8973: Pass descriptor instead of GPIO number Date: Mon, 23 Apr 2018 01:07:28 +0200 Message-Id: <20180422230742.3729-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180422230742.3729-1-linus.walleij@linaro.org> References: <20180422230742.3729-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of passing a global GPIO number, pass a descriptor looked up with the standard devm_gpiod_get_optional() call. Cc: Mikko Perttunen Cc: Laxman Dewangan Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase the patch on the other changes. --- drivers/regulator/max8973-regulator.c | 54 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 25 deletions(-) -- 2.14.3 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index e0c747aa9f85..7cd493ec6315 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -114,7 +115,6 @@ struct max8973_chip { struct regulator_desc desc; struct regmap *regmap; bool enable_external_control; - int enable_gpio; int dvs_gpio; int lru_index[MAX8973_MAX_VOUT_REG]; int curr_vout_val[MAX8973_MAX_VOUT_REG]; @@ -567,7 +567,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt( pdata->enable_ext_control = of_property_read_bool(np, "maxim,externally-enable"); - pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0); pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); @@ -633,6 +632,8 @@ static int max8973_probe(struct i2c_client *client, struct max8973_chip *max; bool pdata_from_dt = false; unsigned int chip_id; + struct gpio_desc *gpiod; + enum gpiod_flags gflags; int ret; pdata = dev_get_platdata(&client->dev); @@ -647,8 +648,7 @@ static int max8973_probe(struct i2c_client *client, return -EIO; } - if ((pdata->dvs_gpio == -EPROBE_DEFER) || - (pdata->enable_gpio == -EPROBE_DEFER)) + if (pdata->dvs_gpio == -EPROBE_DEFER) return -EPROBE_DEFER; max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); @@ -696,15 +696,11 @@ static int max8973_probe(struct i2c_client *client, max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; - max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL; max->enable_external_control = pdata->enable_ext_control; max->curr_gpio_val = pdata->dvs_def_state; max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; max->junction_temp_warning = pdata->junction_temp_warning; - if (gpio_is_valid(max->enable_gpio)) - max->enable_external_control = true; - max->lru_index[0] = max->curr_vout_reg; if (gpio_is_valid(max->dvs_gpio)) { @@ -757,27 +753,35 @@ static int max8973_probe(struct i2c_client *client, break; } - if (gpio_is_valid(max->enable_gpio)) { - config.ena_gpio_flags = GPIOF_OUT_INIT_LOW; - if (ridata && (ridata->constraints.always_on || - ridata->constraints.boot_on)) - config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; - config.ena_gpio = max->enable_gpio; + if (ridata && (ridata->constraints.always_on || + ridata->constraints.boot_on)) + gflags = GPIOD_OUT_HIGH; + else + gflags = GPIOD_OUT_LOW; + gpiod = devm_gpiod_get_optional(&client->dev, + "maxim,enable", + gflags); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + if (gpiod) { + config.ena_gpiod = gpiod; + max->enable_external_control = true; } + break; case MAX77621: - if (gpio_is_valid(max->enable_gpio)) { - ret = devm_gpio_request_one(&client->dev, - max->enable_gpio, GPIOF_OUT_INIT_HIGH, - "max8973-en-gpio"); - if (ret) { - dev_err(&client->dev, - "gpio_request for gpio %d failed: %d\n", - max->enable_gpio, ret); - return ret; - } - } + /* + * We do not let the core switch this regulator on/off, + * we just leave it on. + */ + gpiod = devm_gpiod_get_optional(&client->dev, + "maxim,enable", + GPIOD_OUT_HIGH); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + if (gpiod) + max->enable_external_control = true; max->desc.enable_reg = MAX8973_VOUT; max->desc.enable_mask = MAX8973_VOUT_ENABLE;