From patchwork Tue Feb 20 08:36:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 203478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp265086dyc; Tue, 20 Feb 2024 00:37:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+41AYJ8lCGO+x6aUHVW2q5gw2uLdosViT4bzell6bDY15pyaHeVo3kVGv/A9vD+d6CQSoGD0QlFhcS9yWDpJ/+n63cQ== X-Google-Smtp-Source: AGHT+IGiyIQnLZDkisw2RPfkJ3M9cXsY90NHLDev+ai4LR/52tMyT6bZpi9R9d2luW3ulFZMeuEE X-Received: by 2002:ad4:5aa7:0:b0:68f:52a9:3b24 with SMTP id u7-20020ad45aa7000000b0068f52a93b24mr7893982qvg.29.1708418223766; Tue, 20 Feb 2024 00:37:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708418223; cv=pass; d=google.com; s=arc-20160816; b=SSJlTkJICZ31CHp6jSPIb4v+Y3PBScRXplrABjSVYqeWyVobwWIDOU8fheKyUFtLXJ z5akmniZ77YG+3oFnWDqyESl6MF9rm1NRVZ28rLQvmg7YaPINF/FbNS3jj4l2Vzzy1kx ULrQ7pHGvlBKVTeOYxeB8Av6SWfSVdw2+/h46APiHVBTszmUnYCEqWjQhSeTDqa2T4db kyhM8Wm6rnD8wmb2oH+jpc/NqN02Df5dtrXb/PTShofVnjBDLG47MZcbhlxfgul9ISi1 /9Z5L09X2HUNHCb9yoaPvX8BtPaTvlvEpwojGDVEGDoNs7qSXp9FZ4WHq6WVdbnWxYsb ZfuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=928LPkm/7Nxxi2kK6MUa7iVBvhdKBt6BA4yDf3dLRoI=; fh=j1yS28tmtQOJHnBdCDYBJgx1/yVVBS1Kot++6x+bjk8=; b=aepGGtt8A0UAPDpFi9/Wb9sop1lagfEtQNnUMYfzfT5Sw02PAnOLazFpw2pbBf7oSI M896o4dkF8UPwF3Od9Q+gMrkthQAoRSi8BX2AIDGpAqYRJcoN1TBpGY7enG7jX5foUhx icYE3nO5OKAUgJyFucsxPM/ynmXlFE/dephwr9BtuDwgzmRa7yk6+nrtHd0CrzjLw+IT pDrvpjxkH45AKh8jcKwO1+Rb+mI5+AQB6XJvGnecVCBp0K5ewJLAKgIryMauqcnEzp5q ruT7ZRmV3qwuiVe4XF/mcLjGsajjJhWYq3pIwqoNdaudwgOQSrdzPzGyBlL0tuQpiIJ8 AZQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ye4gITr9; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72569-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72569-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 3-20020a0562140d6300b0068c6cb82b51si8130095qvs.192.2024.02.20.00.37.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:37:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72569-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ye4gITr9; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72569-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72569-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7AEB91C20EB9 for ; Tue, 20 Feb 2024 08:37:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F16FB5D8F1; Tue, 20 Feb 2024 08:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ye4gITr9" Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B046B5CDEE for ; Tue, 20 Feb 2024 08:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418189; cv=none; b=DJpNIhzOk8nfPlR5IN75i4sTSSnCASZaB0gfargln7YfQrYNIcRb7fFBR4rRWyPcH9Km6pOWCID73VTqlFKGhMittj7WP78EyW5Ca6Cc7I2ljR+sSioXNTur7DCtLPKxITS2KpQ3Ni4/HLWzROrztAtQBbu3KygQ4lWHHpxNR8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418189; c=relaxed/simple; bh=ATwedi7r0f8J9Ug8Epyk/2KLGwmag5JdWfXjjEF/N7Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HXp7w1p3l2lDcHjlY5WqrrvY8pGPQmw3CQ4kR0yEGCJqHLdECbUN3+lE715BZ+ivF0IRcaeI/VM0qnykDiqbisiOxoAFlo2uWGiZjS4rhEhOrU+z/HfsppxxTTmEpIrfcysa9EU09Q3acT2P8+jOnWJUmMLHo6i+JntMgE2pYFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Ye4gITr9; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d180d6bd32so55576461fa.1 for ; Tue, 20 Feb 2024 00:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708418186; x=1709022986; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=928LPkm/7Nxxi2kK6MUa7iVBvhdKBt6BA4yDf3dLRoI=; b=Ye4gITr9ETUvlY65Dj19ABpg+fOaI7ss9lfWKHPElbYsAg+jmrgOTBBmVedWKcp3Vy 4DSgU92NvYndJlQYghlo6PAgnxC5IfKD/C8Js6OjyxI0MhWcupgJHlGRknypTBo6BiKi G4SsPct89EDOtPOHQCJwVzHaZRtFMWmgxvbEhehrFkZCFXPSGWgCvrlCOBmZ8e/C89aV nfgIxcxvOKW1YfBFyBI58B3q579msExzSf+PUR4KjPqYjgmwxax7nU8oA0Ylm1JwcVqq nI0aX0PbCAQBodmm2gsT7xDjTnZECRFrohydQqbvhBilJEneyuGZhi5ACl2dFRcBA/lK a7Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708418186; x=1709022986; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=928LPkm/7Nxxi2kK6MUa7iVBvhdKBt6BA4yDf3dLRoI=; b=cZFrV39H9QduP4Sm2NgaPWbT9rX/XjXKIcTGIp1qSyzYZjCVkTBEpDxVEZ0GcKkMxn BvaMoQZLSBXFnBFjIniLNeW1Vq6MI67NfEndoT6CFD9kHBszvfc4CJE3LvwXNrpiY/jW eDhxhPJsGaX0YnC+CzMmaSftUYHkAhdIVsaYvTRVyq58k5mqM6rOdgKKYwaJuQKVU2nl veknuZnm0E0+PuNoPC/JZ3XlqXIeaVz2tiUd4B1ie+hQ2BTuq2QQs87DkJRJyae66Tp7 NbnfHgI9nZqDQBkjC2bGtLroiox9mcvMXgwG/U4KrKz4xdKZjuP5CkmAfo+8OA+vIow5 AsyA== X-Gm-Message-State: AOJu0YyGd8LU9D8HnBBP6tnMJMEDIqlreglf/OGvR7EkB9zXUvLg5QYV Q94CVoJzrxY9naMhWHPOLSSsCw1YhM86hHaQrbveN2icwPRZAvAbq3UURv8a374ATGKxU3USTAZ q X-Received: by 2002:a2e:b7ca:0:b0:2d2:36fa:dd2 with SMTP id p10-20020a2eb7ca000000b002d236fa0dd2mr3377102ljo.23.1708418185819; Tue, 20 Feb 2024 00:36:25 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id k1-20020a2e2401000000b002d2468d3bacsm195317ljk.9.2024.02.20.00.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:36:25 -0800 (PST) From: Linus Walleij Date: Tue, 20 Feb 2024 09:36:24 +0100 Subject: [PATCH 1/5] regulator: max8973: Finalize switch to GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-descriptors-regulators-v1-1-097f608694be@linaro.org> References: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> In-Reply-To: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> To: Liam Girdwood , Mark Brown , Support Opensource , Lee Jones Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791406347578756549 X-GMAIL-MSGID: 1791406347578756549 The dvs gpio was still using a legacy number passed from the platform data. There are no in-tree users of the platform data so just switch it to a gpio descriptor and obtain it in probe(), the device tree users will work just as fine with this. Drop the entirely unused enable_gpio from the platform data as well. The device tree bindings mentions this but the driver does not look for it and makes no use of it: it should probably be implemented properly in a separate patch. Signed-off-by: Linus Walleij --- drivers/regulator/max8973-regulator.c | 36 ++++++++++------------------- include/linux/regulator/max8973-regulator.h | 6 ----- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index 8d5193207552..f8bb6828feef 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -20,9 +20,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -102,7 +100,7 @@ struct max8973_chip { struct regulator_desc desc; struct regmap *regmap; bool enable_external_control; - int dvs_gpio; + struct gpio_desc *dvs_gpiod; int lru_index[MAX8973_MAX_VOUT_REG]; int curr_vout_val[MAX8973_MAX_VOUT_REG]; int curr_vout_reg; @@ -184,7 +182,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev, * If gpios are available to select the VOUT register then least * recently used register for new configuration. */ - if (gpio_is_valid(max->dvs_gpio)) + if (max->dvs_gpiod) found = find_voltage_set_register(max, vsel, &vout_reg, &gpio_val); @@ -201,8 +199,8 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev, } /* Select proper VOUT register vio gpios */ - if (gpio_is_valid(max->dvs_gpio)) { - gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); + if (max->dvs_gpiod) { + gpiod_set_value_cansleep(max->dvs_gpiod, gpio_val & 0x1); max->curr_gpio_val = gpio_val; } return 0; @@ -531,7 +529,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt( pdata->enable_ext_control = of_property_read_bool(np, "maxim,externally-enable"); - pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); if (!ret) @@ -612,13 +609,17 @@ static int max8973_probe(struct i2c_client *client) return -EIO; } - if (pdata->dvs_gpio == -EPROBE_DEFER) - return -EPROBE_DEFER; - max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); if (!max) return -ENOMEM; + max->dvs_gpiod = devm_gpiod_get_optional(&client->dev, "maxim,dvs", + (pdata->dvs_def_state) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW); + if (IS_ERR(max->dvs_gpiod)) + return dev_err_probe(&client->dev, PTR_ERR(max->dvs_gpiod), + "failed to obtain dvs gpio\n"); + gpiod_set_consumer_name(max->dvs_gpiod, "max8973-dvs"); + max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config); if (IS_ERR(max->regmap)) { ret = PTR_ERR(max->regmap); @@ -663,7 +664,6 @@ static int max8973_probe(struct i2c_client *client) max->desc.ramp_delay_table = max8973_buck_ramp_table; max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table); - max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_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; @@ -671,21 +671,9 @@ static int max8973_probe(struct i2c_client *client) max->lru_index[0] = max->curr_vout_reg; - if (gpio_is_valid(max->dvs_gpio)) { - int gpio_flags; + if (max->dvs_gpiod) { int i; - gpio_flags = (pdata->dvs_def_state) ? - GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; - ret = devm_gpio_request_one(&client->dev, max->dvs_gpio, - gpio_flags, "max8973-dvs"); - if (ret) { - dev_err(&client->dev, - "gpio_request for gpio %d failed, err = %d\n", - max->dvs_gpio, ret); - return ret; - } - /* * Initialize the lru index with vout_reg id * The index 0 will be most recently used and diff --git a/include/linux/regulator/max8973-regulator.h b/include/linux/regulator/max8973-regulator.h index 8313e7ed6aec..a225e9eeb30d 100644 --- a/include/linux/regulator/max8973-regulator.h +++ b/include/linux/regulator/max8973-regulator.h @@ -48,10 +48,6 @@ * control signal from EN input pin. If it is false then * voltage output will be enabled/disabled through EN bit of * device register. - * @enable_gpio: Enable GPIO. If EN pin is controlled through GPIO from host - * then GPIO number can be provided. If no GPIO controlled then - * it should be -1. - * @dvs_gpio: GPIO for dvs. It should be -1 if this is tied with fixed logic. * @dvs_def_state: Default state of dvs. 1 if it is high else 0. */ struct max8973_regulator_platform_data { @@ -59,8 +55,6 @@ struct max8973_regulator_platform_data { unsigned long control_flags; unsigned long junction_temp_warning; bool enable_ext_control; - int enable_gpio; - int dvs_gpio; unsigned dvs_def_state:1; }; From patchwork Tue Feb 20 08:36:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 203479 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp265164dyc; Tue, 20 Feb 2024 00:37:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcQCUpxwvqXIUB7eNm3tFnwbcQGW4Ne7Pg35BJVbInwPR/RQFIXlda+YsSHu1oT4x5QL1tmsPFSFk8Cl9U889nT3UNUw== X-Google-Smtp-Source: AGHT+IEtalnaoyF58DHb6fhjZhOaEdCmbg37lGNSyNla+sewHeRR9Zi3uUj/dfcDrzocfFXEIc2m X-Received: by 2002:a1f:dec3:0:b0:4c8:8742:5bfa with SMTP id v186-20020a1fdec3000000b004c887425bfamr4679308vkg.11.1708418236506; Tue, 20 Feb 2024 00:37:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708418236; cv=pass; d=google.com; s=arc-20160816; b=N4sgUQYiepzOzK4ceehc3AnDTic9ugKgWEhY+585gDgMuvfsspwiMQ3TnaF01lGw8x caupE6Dd1JTVSR9sRMUXkKxwo3QtjE9AFtICP7aK9Ui7PADlP3W8LYdVFgIJjY2Srir1 OdBMirclGZwkoWVwlaLrAarHCaStS2L9TlhSaZ6wbRfInwfCIKG9mzLp6yly3+Z2behJ YycCOVOUTXIwrucFGvBV4Wy4aT/KhdN/KMqHl1D9Gu7UBT+6HpiOKf7IqqCMpLvkmbjE 1x58PA7gTC1wYriiDjpsct0IYzghwSrDJlWUSRqRZFwHyqf0j8fpT1Sjj+fznn8X2O7R G1Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=QjY74HkehgK0i0REEpSEnW6XrJ8Vf9fEs6vzbNOlqqI=; fh=j1yS28tmtQOJHnBdCDYBJgx1/yVVBS1Kot++6x+bjk8=; b=W+okB4l0DBmmTnCSjAacUYIxV1+5tmh3mdreGl6MZagQZ6xzhny74v2AFg3/lrTXaQ CxtvpSs7McDKt69ZURUhzdPnLpy29mpxhGGd34+FbCDq7qJyH0AXqrffO9loVc/FtTyB rAnY95iSlVfw5BpjpTzEteH+QFef6wFO8+PKz+WLiiQ+ZWhF+HUd6ZwU/C+rvG922D+X /27F7uclLzVMbuMyasDqO2a3gK50QKe1KhhLCCtlvqRzy+3iETL1Mocn3klwOlKywYPo Baxi6j3kopSqLkqGAsZAV3m0FiTJ1O+l/KQg+0aO901NPZPiHjYD6gb4LWrYMTPNM2SW NiLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=szowWkGw; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72570-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72570-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fq6-20020a056214258600b0068d0ef28d1bsi8166147qvb.189.2024.02.20.00.37.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:37:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72570-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=szowWkGw; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72570-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72570-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 399031C21552 for ; Tue, 20 Feb 2024 08:37:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 257BA5DF3B; Tue, 20 Feb 2024 08:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="szowWkGw" Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D29FC5CDF7 for ; Tue, 20 Feb 2024 08:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418190; cv=none; b=Efk5NibMvYwjbmzXGvDj56gWPgOjCUCTsT6PBHpZ75jJCcwc9W+fDtpaTTkEphEs7aY4DYXWQmSTKdaL36b0cGLkSrR7T4Y0fG/+BOk/qVjz5NOrIe9S1RaF4hqPZBDzRlEOcOSCQMAX/Iit5VY/jyTKWXWG3jIkhdyQLzVgWC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418190; c=relaxed/simple; bh=z2cxCTfWPEPydtoKnMFvKQ2VIVJj/81Jcc3ebBTGNY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qrnLdS4SrTxVWy6x11LtdVqH4XNMO1Gj8Y7fP49U2pOXemOz5TqbcnMFeOnlvKHTpiiYI2MwMGUK64Xf72JF4vZ/xHZCMRa5/ao8gyhPDiPlEbv7VA3+BYlISWMMmqGAn5+3n34/cLRvd5AZ6VInJYQPyE+v2GflpIQZeKEK53I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=szowWkGw; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2d21e2b2245so51188321fa.0 for ; Tue, 20 Feb 2024 00:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708418187; x=1709022987; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QjY74HkehgK0i0REEpSEnW6XrJ8Vf9fEs6vzbNOlqqI=; b=szowWkGwA6s3nMSRE7+RhWh8RiSag87faBDhwxs11NygN66QA/sL+i8/Lb4++FuE7o WChY1iu1rLVgCx3stfEBniyrh1tvWJktzRKTkmwi6S9+VxulpkuXHwJg9jN/d7oJNrDN XqS0ZbZf4omWjxHQQu7zCmkg4CBnzXCMupI2l971kbVkp5PGJoL/KaDj0/UmvE0QvL+e ShmWGGxmp/BfbQ8cCnUeej1UjztRgctf5DP1/wl5p7hj2AYgF4AUKu6BF0dR70jVjks2 gWsctd05graCvPSDtm1gzF5AaJhe1+eu8IPu0dcdpkzfN8sNrN97SONoZqmg3NuKpd8X 7hEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708418187; x=1709022987; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QjY74HkehgK0i0REEpSEnW6XrJ8Vf9fEs6vzbNOlqqI=; b=OaLWncHpFBqW2XI4+6TLbkNGwurhEu6OQMRjE/x7DUyoLApN3NAwAeD+guo1i1uj1l sSzBcSsi28hsrhPVWaQ3LiGLLql0xUuATSOzT/Q5vVgAndXbu6jTxcHQ4affg8axQ7jr nKoY5/vhIRZwzymWGaKXatCZF9hvxSeBEnD6UrJE3PDf0esVQWMqBA1Nlu6GWsEFH7H5 hmwIBaNtnTk1FPDzbWtSOs0uZu6xf9x7FnmTOsDpoJYWSz5s8x2eDG6jCni0MzVrhkJP Qr+9qAgSFYmRCSxtv+4tbRdAbw+e+u3C8Z7ZZQ35Hn4xaKzLHvPSPLJ20o8puoaXByU9 D3GQ== X-Gm-Message-State: AOJu0YwD1NP2+Ga4Cs1ftVf2adJE0Ykfhnnn6WQ23S4v2uetq+YUnPCA Mdj3TsHdvFf3hRXxvuo6diMBlHsfrNz+OXUu7Haz16FV/s1T8Su3TZqSUs9T23Q= X-Received: by 2002:a2e:a68f:0:b0:2d2:366c:b219 with SMTP id q15-20020a2ea68f000000b002d2366cb219mr3488096lje.51.1708418187103; Tue, 20 Feb 2024 00:36:27 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id k1-20020a2e2401000000b002d2468d3bacsm195317ljk.9.2024.02.20.00.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:36:26 -0800 (PST) From: Linus Walleij Date: Tue, 20 Feb 2024 09:36:25 +0100 Subject: [PATCH 2/5] regulator: da9055: Fully convert to GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-descriptors-regulators-v1-2-097f608694be@linaro.org> References: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> In-Reply-To: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> To: Liam Girdwood , Mark Brown , Support Opensource , Lee Jones Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791406361074885126 X-GMAIL-MSGID: 1791406361074885126 The DA9055 regulator was touched before, requireing enable GPIOs to be passed from pdata. As we have a device for each regulator, obtain the three gpios ren ("regulator enable"), rsel ("regulator select") and the ena ("enable") GPIO associated with the regulator enable directly from the device and cut down on the amount of GPIO numbers passed as platform data. The ren and rsel are just requested as inputs: these are actually handled by hardware. The ena gpios are driven actively by the regulator core. There are no in-tree users, but the regulators are instantiated from the (undocumed) device tree nodes with "dlg,da9055-regulator" as compatible, and by simply adding regulator-enable-gpios, regulator-select-gpios and enable-gpios to this DT node, all will work as before. Signed-off-by: Linus Walleij --- drivers/regulator/da9055-regulator.c | 48 ++++++++++++++++++------------------ include/linux/mfd/da9055/pdata.h | 13 ---------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 8fd9ac787588..352547c375bd 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -413,31 +412,35 @@ static struct da9055_regulator_info da9055_regulator_info[] = { * GPIO can control regulator state and/or select the regulator register * set A/B for voltage ramping. */ -static int da9055_gpio_init(struct da9055_regulator *regulator, +static int da9055_gpio_init(struct device *dev, + struct da9055_regulator *regulator, struct regulator_config *config, struct da9055_pdata *pdata, int id) { struct da9055_regulator_info *info = regulator->info; + struct gpio_desc *ren; + struct gpio_desc *ena; + struct gpio_desc *rsel; int ret = 0; - if (!pdata) - return 0; + /* Look for "regulator-enable-gpios" GPIOs in the regulator node */ + ren = devm_gpiod_get_optional(dev, "regulator-enable", GPIOD_IN); + if (IS_ERR(ren)) + return PTR_ERR(ren); - if (pdata->gpio_ren && pdata->gpio_ren[id]) { - char name[18]; - int gpio_mux = pdata->gpio_ren[id]; + if (ren) { + /* This GPIO is not optional at this point */ + ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); + if (IS_ERR(ena)) + return PTR_ERR(ena); - config->ena_gpiod = pdata->ena_gpiods[id]; + config->ena_gpiod = ena; /* * GPI pin is muxed with regulator to control the * regulator state. */ - sprintf(name, "DA9055 GPI %d", gpio_mux); - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, - name); - if (ret < 0) - goto err; + gpiod_set_consumer_name(ren, "DA9055 ren GPI"); /* * Let the regulator know that its state is controlled @@ -448,24 +451,22 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, pdata->reg_ren[id] << DA9055_E_GPI_SHIFT); if (ret < 0) - goto err; + return ret; } - if (pdata->gpio_rsel && pdata->gpio_rsel[id]) { - char name[18]; - int gpio_mux = pdata->gpio_rsel[id]; + /* Look for "regulator-select-gpios" GPIOs in the regulator node */ + rsel = devm_gpiod_get_optional(dev, "regulator-select", GPIOD_IN); + if (IS_ERR(rsel)) + return PTR_ERR(rsel); + if (rsel) { regulator->reg_rselect = pdata->reg_rsel[id]; /* * GPI pin is muxed with regulator to select the * regulator register set A/B for voltage ramping. */ - sprintf(name, "DA9055 GPI %d", gpio_mux); - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, - name); - if (ret < 0) - goto err; + gpiod_set_consumer_name(rsel, "DA9055 rsel GPI"); /* * Let the regulator know that its register set A/B @@ -477,7 +478,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, << DA9055_V_GPI_SHIFT); } -err: return ret; } @@ -532,7 +532,7 @@ static int da9055_regulator_probe(struct platform_device *pdev) if (pdata) config.init_data = pdata->regulators[pdev->id]; - ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); + ret = da9055_gpio_init(&pdev->dev, regulator, &config, pdata, pdev->id); if (ret < 0) return ret; diff --git a/include/linux/mfd/da9055/pdata.h b/include/linux/mfd/da9055/pdata.h index d3f126990ad0..137a2b067512 100644 --- a/include/linux/mfd/da9055/pdata.h +++ b/include/linux/mfd/da9055/pdata.h @@ -7,7 +7,6 @@ #define DA9055_MAX_REGULATORS 8 struct da9055; -struct gpio_desc; enum gpio_select { NO_GPIO = 0, @@ -23,16 +22,6 @@ struct da9055_pdata { struct regulator_init_data *regulators[DA9055_MAX_REGULATORS]; /* Enable RTC in RESET Mode */ bool reset_enable; - /* - * GPI muxed pin to control - * regulator state A/B, 0 if not available. - */ - int *gpio_ren; - /* - * GPI muxed pin to control - * regulator set, 0 if not available. - */ - int *gpio_rsel; /* * Regulator mode control bits value (GPI offset) that * controls the regulator state, 0 if not available. @@ -43,7 +32,5 @@ struct da9055_pdata { * controls the regulator set A/B, 0 if not available. */ enum gpio_select *reg_rsel; - /* GPIO descriptors to enable regulator, NULL if not available */ - struct gpio_desc **ena_gpiods; }; #endif /* __DA9055_PDATA_H */ From patchwork Tue Feb 20 08:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 203480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp265227dyc; Tue, 20 Feb 2024 00:37:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTTtxa0TCqtJ2B4ZLQtluMC1yQ6ez4cBlTaP+FzoBdFbI7x52l0359xKBmnmCSEcDkbLbD7aMfRnsVHBwiq5Z77dyaMQ== X-Google-Smtp-Source: AGHT+IE+6nFDEbPWxA4Zfp0lx9hr0AlfH9xhs1gKT6NM5vxmBF29iYQ6m29YHAxTDo8k7Zi2UevU X-Received: by 2002:a05:620a:28c3:b0:787:7493:c5e8 with SMTP id l3-20020a05620a28c300b007877493c5e8mr3617645qkp.21.1708418245459; Tue, 20 Feb 2024 00:37:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708418245; cv=pass; d=google.com; s=arc-20160816; b=ZfnLWTJuP0pKGEdf+xYJoDgGULIKOk9W8wQtOLQH/aapNNecMioSGFgBxR+dcIaXi1 RDKAzC3bEUP5qCpZat0JOtZuPg/IRa6cYkEQbWGcwkmaDMOz4IHgqG+M6iG9JtrnY7UR 8FR8vr1zDQmbvUuQh6FoQihAzZw6j8Uqh09Ql/YMJM19a0CEx1lifYLvNjVPALcnl182 wZsP5K/YCz5FvYPKtyh8X44D8ddNYcknz8clfxRkG65ifPnDJz5w+C8BlCG1XRPk/wwP WJ/irZ/GOFZQrGGkDfdNdyTUaPa9P3vepKcl+N5CedTbh95bIthwT75DiDTGezE1bbyd 9n9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=SZGKzH/426CN3opzPjYcCV0wzHXep85KgnBvxUchGh8=; fh=j1yS28tmtQOJHnBdCDYBJgx1/yVVBS1Kot++6x+bjk8=; b=aU/UNQA1sfWkAFmk0UNsEqtHSPAJZ0LQ3qxROEwRpasxU7hVjniWkKpO0yGAcqfztK 5EhOhT38soCuFWLcIavZxlyc5TxEhiXYiWV3Ok+Ox/tEbK58HgX0PuhV62PxXc26qIJw bbSqpjc0Q3x411OtqGOALslD2ew3OZdlVd51M5FzIMPwQPJo2o8cPI2XDcaw6JzI6PHw 61ec2ttfwN5NnQ5rJg0Lo+JO/5TL8NSJo0G6LTnONhuKkiHzv7NeVcyRBE8x6mLoygdq k0RxkZ38F/WJSrP3QesNlpYe5kcR+866Kh2NPwYPFSdI9XDSgPEXguccpjQeWqNVImHX IQXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r+bCQ0Ie; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72571-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72571-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h13-20020a05620a21cd00b007876813650fsi4055297qka.472.2024.02.20.00.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72571-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r+bCQ0Ie; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72571-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72571-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D02C1C21163 for ; Tue, 20 Feb 2024 08:37:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07BDE5F46D; Tue, 20 Feb 2024 08:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="r+bCQ0Ie" Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C7525D464 for ; Tue, 20 Feb 2024 08:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418191; cv=none; b=Jp0OankRUIiQ/L/4mKgD3A3iQgHlUf0X8JLJDpH7h2601CKh59h8W/rzED+QndnsNq0edgHDm0RU9/WQNA3R2Fz4V9HiCcBGizNFjUmd9XpaBpul5r6B70v9Wb9cZYuEDNhnSZ51M98x1MglkgSJbv+kNA5NCq1+/uSR+DIowEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418191; c=relaxed/simple; bh=6Gz51bBXN6Q8boWrX2GQVXiS/ekJ2yeDalfCuLeQcy0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BETeOmx3narAS3s8NYgNQKJ14Bg7pOIxiFBqVyfkprVWnHf2191iaS54oXpA/aCwF+ouBmBfJObJKqAwoTrH/IIeKboSRK8+SPYAEqYo1/PkNQPdZVVfyly8nEcuu4N5gnrDyoiCcB1z2DbT5f2qZYZHoc/fJhGFdDbE8nKsGMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=r+bCQ0Ie; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d220e39907so50657061fa.1 for ; Tue, 20 Feb 2024 00:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708418188; x=1709022988; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SZGKzH/426CN3opzPjYcCV0wzHXep85KgnBvxUchGh8=; b=r+bCQ0Ieb9atk9w1QNme+6RsGpRgEFD8Gcz4hHHMH72vNqqRga+/ns+Ra16j9z8U9T DodDTE3SXgjeZnhm6Fny+dKPVgD9CY+2dexvj1Y1RCUS5P6hFnhyc/jrBumzw1Tfr/xr lfv/bNfeqRZr22W1qLDUif4X0KPDnkFW1vWxUHuAlvuXK+tvcEFEIss1zvQfHLeoJsa9 lTqsSguobYLLPojvtJx7PwDVKA+hR3Rc/0EeBtb7wwd/R+lMxSjrwiSeYUIugQJPD371 yHrZLps0/FM5KNAnpY1lSd/vHsICdgJ/0+5W0s8oBm4CxmLqxd3ReGH2xV7AEsYIt0+r XCfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708418188; x=1709022988; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SZGKzH/426CN3opzPjYcCV0wzHXep85KgnBvxUchGh8=; b=ncOF3Q7ZVWPhf/tQCOwlTdDLpc4dRrn1tVjhxWpTBObeGruG4QKQQYDsDawHx13144 FVWjvIEpdhgVclMFWpbk/XgMyVsIV42YqwYWexqv4r1+WhpBJUVfZhsMZAc9E0KfZ4/Q nK4P6rbEF8Wzii0T5E4T2WGYPFQfEgQOMnCmry8if8/JhH1hWjd9SKYQHv9snUNDgCgx xmW/VLDPON7ZZOpGAbuQctMmQlyYpgRnjOozanGAXgLG3V+mwAuOVz5X0cTMRlPfWOgY slnrx4Ll5SJx8pckcT7dzESWSBJKirIkkQOOPe8YTePp8b6qxTDkZBvOHryiY26p5KZb /Jew== X-Gm-Message-State: AOJu0YzF60NjbH+aAD0N789Aks8n3gfZRJqfwyXLqRiQREgvaUC7SRzS 8NsC1IEEq/wcZQEHlXpZY2Pd1OeMq9MUOikMuo0nsDCmnzjnw5lCIGjpkhIWAfs= X-Received: by 2002:a2e:3318:0:b0:2d2:426b:455c with SMTP id d24-20020a2e3318000000b002d2426b455cmr3262023ljc.0.1708418187964; Tue, 20 Feb 2024 00:36:27 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id k1-20020a2e2401000000b002d2468d3bacsm195317ljk.9.2024.02.20.00.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:36:27 -0800 (PST) From: Linus Walleij Date: Tue, 20 Feb 2024 09:36:26 +0100 Subject: [PATCH 3/5] regulator: lp8788-buck: Fully convert to GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-descriptors-regulators-v1-3-097f608694be@linaro.org> References: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> In-Reply-To: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> To: Liam Girdwood , Mark Brown , Support Opensource , Lee Jones Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791406370294291385 X-GMAIL-MSGID: 1791406370294291385 This converts the LP8788 BUCK regulator driver to use GPIO descriptors. BUCK1 can use one DVS GPIO and BUCK2 can use two DVS GPIOS, and no more so just hardcode two GPIO descriptors into the per-DVS state containers. Obtain the descriptors from each regulators subdevice. As there are no in-tree users, board files need to populate descriptor tables for the buck regulator devices when they want to use this driver. BUCK1 need a GPIO descriptor at index 0 and BUCK2 needs two GPIO descriptors at indices 0 and 1. Signed-off-by: Linus Walleij --- drivers/regulator/lp8788-buck.c | 64 +++++++++++++++++------------------------ include/linux/mfd/lp8788.h | 9 ++---- 2 files changed, 28 insertions(+), 45 deletions(-) diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c index e97ade09dede..712eaa6ff8ab 100644 --- a/drivers/regulator/lp8788-buck.c +++ b/drivers/regulator/lp8788-buck.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include /* register address */ #define LP8788_EN_BUCK 0x0C @@ -69,8 +69,8 @@ #define BUCK_FPWM_SHIFT(x) (x) enum lp8788_dvs_state { - DVS_LOW = GPIOF_OUT_INIT_LOW, - DVS_HIGH = GPIOF_OUT_INIT_HIGH, + DVS_LOW = 0, + DVS_HIGH = 1, }; enum lp8788_dvs_mode { @@ -89,6 +89,8 @@ struct lp8788_buck { struct lp8788 *lp; struct regulator_dev *regulator; void *dvs; + struct gpio_desc *gpio1; + struct gpio_desc *gpio2; /* Only used on BUCK2 */ }; /* BUCK 1 ~ 4 voltage ranges */ @@ -106,8 +108,7 @@ static void lp8788_buck1_set_dvs(struct lp8788_buck *buck) return; pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH; - if (gpio_is_valid(dvs->gpio)) - gpio_set_value(dvs->gpio, pinstate); + gpiod_set_value(buck->gpio1, pinstate); } static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) @@ -139,11 +140,8 @@ static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) return; } - if (gpio_is_valid(dvs->gpio[0])) - gpio_set_value(dvs->gpio[0], pin1); - - if (gpio_is_valid(dvs->gpio[1])) - gpio_set_value(dvs->gpio[1], pin2); + gpiod_set_value(buck->gpio1, pin1); + gpiod_set_value(buck->gpio2, pin2); } static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) @@ -202,19 +200,13 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck, enum lp8788_buck_id id) { enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id); - struct lp8788_buck1_dvs *b1_dvs; - struct lp8788_buck2_dvs *b2_dvs; u8 val, idx, addr; int pin1, pin2; switch (id) { case BUCK1: if (mode == EXTPIN) { - b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs; - if (!b1_dvs) - goto err; - - idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0; + idx = gpiod_get_value(buck->gpio1); } else { lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; @@ -223,12 +215,8 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck, break; case BUCK2: if (mode == EXTPIN) { - b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs; - if (!b2_dvs) - goto err; - - pin1 = gpio_get_value(b2_dvs->gpio[0]); - pin2 = gpio_get_value(b2_dvs->gpio[1]); + pin1 = gpiod_get_value(buck->gpio1); + pin2 = gpiod_get_value(buck->gpio2); if (pin1 == PIN_LOW && pin2 == PIN_LOW) idx = 0; @@ -424,28 +412,28 @@ static int lp8788_dvs_gpio_request(struct platform_device *pdev, enum lp8788_buck_id id) { struct lp8788_platform_data *pdata = buck->lp->pdata; - char *b1_name = "LP8788_B1_DVS"; - char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" }; - int i, gpio, ret; + struct device *dev = &pdev->dev; switch (id) { case BUCK1: - gpio = pdata->buck1_dvs->gpio; - ret = devm_gpio_request_one(&pdev->dev, gpio, DVS_LOW, - b1_name); - if (ret) - return ret; + buck->gpio1 = devm_gpiod_get(dev, "dvs", GPIOD_OUT_LOW); + if (IS_ERR(buck->gpio1)) + return PTR_ERR(buck->gpio1); + gpiod_set_consumer_name(buck->gpio1, "LP8788_B1_DVS"); buck->dvs = pdata->buck1_dvs; break; case BUCK2: - for (i = 0; i < LP8788_NUM_BUCK2_DVS; i++) { - gpio = pdata->buck2_dvs->gpio[i]; - ret = devm_gpio_request_one(&pdev->dev, gpio, - DVS_LOW, b2_name[i]); - if (ret) - return ret; - } + buck->gpio1 = devm_gpiod_get_index(dev, "dvs", 0, GPIOD_OUT_LOW); + if (IS_ERR(buck->gpio1)) + return PTR_ERR(buck->gpio1); + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS1"); + + buck->gpio2 = devm_gpiod_get_index(dev, "dvs", 1, GPIOD_OUT_LOW); + if (IS_ERR(buck->gpio1)) + return PTR_ERR(buck->gpio1); + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS2"); + buck->dvs = pdata->buck2_dvs; break; default: diff --git a/include/linux/mfd/lp8788.h b/include/linux/mfd/lp8788.h index 3d5c480d58ea..51b47966a04d 100644 --- a/include/linux/mfd/lp8788.h +++ b/include/linux/mfd/lp8788.h @@ -10,7 +10,6 @@ #ifndef __MFD_LP8788_H__ #define __MFD_LP8788_H__ -#include #include #include #include @@ -159,21 +158,17 @@ struct lp8788; /* * lp8788_buck1_dvs - * @gpio : gpio pin number for dvs control * @vsel : dvs selector for buck v1 register */ struct lp8788_buck1_dvs { - int gpio; enum lp8788_dvs_sel vsel; }; /* * lp8788_buck2_dvs - * @gpio : two gpio pin numbers are used for dvs * @vsel : dvs selector for buck v2 register */ struct lp8788_buck2_dvs { - int gpio[LP8788_NUM_BUCK2_DVS]; enum lp8788_dvs_sel vsel; }; @@ -268,8 +263,8 @@ struct lp8788_vib_platform_data { * @buck_data : regulator initial data for buck * @dldo_data : regulator initial data for digital ldo * @aldo_data : regulator initial data for analog ldo - * @buck1_dvs : gpio configurations for buck1 dvs - * @buck2_dvs : gpio configurations for buck2 dvs + * @buck1_dvs : configurations for buck1 dvs + * @buck2_dvs : configurations for buck2 dvs * @chg_pdata : platform data for charger driver * @alarm_sel : rtc alarm selection (1 or 2) * @bl_pdata : configurable data for backlight driver From patchwork Tue Feb 20 08:36:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 203482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp265786dyc; Tue, 20 Feb 2024 00:39:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUcqSjU8j4L3sixW8RpmGArdYb+mIsFvs6m92PxSDoPsdctuzL96G0egC/U5G9PnN2OOXydfraM/XK26ANZli9bxhYI+w== X-Google-Smtp-Source: AGHT+IGINsEfDAr0ZUKyJC2KNGbGTdPpGuYrPKy8ji+P290B4/Snso7LxgLVGzLiKw6+NfbDfuxH X-Received: by 2002:a17:903:605:b0:1db:dba7:84b7 with SMTP id kg5-20020a170903060500b001dbdba784b7mr5593890plb.17.1708418350921; Tue, 20 Feb 2024 00:39:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708418350; cv=pass; d=google.com; s=arc-20160816; b=f7MCH6pGK0WXPYyWCusu72ZApgsez1S/CgulvMUgHp80LfU6bm+S68dRdVa7Hww5Cf VjUklzdke93kbgfIM+70xYqQxazQl/GgPZEbpmpEeFYCqmrb5obSV5evYGgcnfkSqAK/ Pg8KjRzWxnQZ5XPq2j9Ja3PIFh5Lp+9Ma5gImhxuv/APELyxz4hUzV8wGUmXUM3z2Cz9 0oqbQ6DRPC0bbZSG2DVbMbhrFCRkRDdrxICe9L/Uunb79C5+OahIWHRYlKDajm4MHtyf TgQnKndsw77JMbHDZFVnrFMgZTIoNfUiyK8rEASJQLm2M2c3xK5RTKF8oebHxxK/Iday JTOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=0x3UN1/hSlN2X5bdmRGWv4D2ePFNha6T0KTmRcIOERc=; fh=j1yS28tmtQOJHnBdCDYBJgx1/yVVBS1Kot++6x+bjk8=; b=H57MC1yGFfsnIMg0+K84IHXgxjW/tgIzqIjp87OspuIoNmzJ9lZOXmJR11Ku9kC8X0 D7Xcy4TamDh+jRcjkKcsIM+RSsu+8huEnnH6id+kotRzdmpylacEH9G/XuFQCshnLMTc Y9Vupi1/qh5rYuHDJorMCetvFPAs9vGfrpys6gUbNwJy525R+mA72PTQPUPl2BLR7eRE QW+Vx3hwzITaXrOw2ztQLHtrhh3/lzTTpCe2NCx4M/ZcdoTQzfmDmAvfNUFrpN6M5TM9 Dd8X8RA+dhtVdgIFkHGSdRLwHaP8CxZTeunI1itPL77a/wXXnY6HvmPVYxEz7+TX31qo b/MQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rAKHZuPU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72572-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bz9-20020a056a02060900b005dc85a758cfsi5952686pgb.169.2024.02.20.00.39.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:39:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rAKHZuPU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72572-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72572-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D09E5B21315 for ; Tue, 20 Feb 2024 08:37:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1CE65F48D; Tue, 20 Feb 2024 08:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rAKHZuPU" Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87A545D484 for ; Tue, 20 Feb 2024 08:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418192; cv=none; b=jzahJ8MepehO+PZrd5EJKk/2ahHcE/4ae79SBW7YN6hMpJITJgkKRUhdRTHJU9FwyDYjQ5zHFfV22b0SCsjGCNvDCLlVVd2rFiEa9NqMYDIyq8i5CPx5qUEF66joeqMIEXX+4ck6yBW5AXRjS0Bvss0PB9G96cU+lwpLOKljjaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418192; c=relaxed/simple; bh=h4aoiZFCXudIevMl0A7g8PBQbZQmaC+2h4xWUS34kOg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tBwDubSCFwAsGFtRXCAnt711V5Z2mS7SmaLc59DyE700l8ktJG1GcYAO5E3VnUV5aNiWdTPa2eCMqIDtO2moT9gpNJB31UCz/hKcX4L1DxlPAAHxaYhQpU86EkVuWDXcDspfrBykqOBarjq14Sl+C+TNYDbNzJONs7jP2xApDiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rAKHZuPU; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d241ff062cso18374551fa.3 for ; Tue, 20 Feb 2024 00:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708418189; x=1709022989; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0x3UN1/hSlN2X5bdmRGWv4D2ePFNha6T0KTmRcIOERc=; b=rAKHZuPUsjDzDKbMWBdsdarYLdjfLEaw5ngwqqzEZcJu1EaZA53zBv0vOwQwT/N478 BZoaftHqfGEvAb49E8ViCfr/5YhkI4kT4pjbtMcKXyZhwaaVUEkVec8QPHgn6OhyUeop Vhh+624u4B4uMJbnBIKaAolXvFuaIcOCC1sYtmeIEh/ZHSD3hWIZ7ts3YLnYQwjYLdzj MsugCnWia3kC6C14KEyhIWCyzYTyerG48NTXjXFf5xkMkOZMHUNVmFruTBb8WkUjsJGh W7tFT0ADZXwRX54LXDvyIQI9k7Otqt0fCmR4fyltxd43ZnMVKTCiz66azFjLwBxXdBYt 2byw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708418189; x=1709022989; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0x3UN1/hSlN2X5bdmRGWv4D2ePFNha6T0KTmRcIOERc=; b=RY1eZnGqUQgk3gJTQ/zX7WzV6IPbMmv3LDNhCZZBbsfetjjPYGfg5ZTf0dxT1UPjex i7ayGdPjnk/1m3W9NbUxFc0hmAmfyiHOQoC5tNMkwNjJdKjW7lsBfr0Kk4HUOmtFsWAO rZDV1f3MMksG2Dw02kMbcVRfNUlevlOxb/r0K73hg7wER4CUdTH1MK2vC0hjnREEuJuH MXoP8bovu0SpQW5bAFJ1sUiY35+ZJBjA1HxaiqNxHG1nUSkiJBlV7MEW0ve0x6cJ4a2Y YZwlrjo1ZUfpfDM4etzCGDPKo9kWtMLCjw08c9/G32ojOEy71WwqcMDpMY/mYucXReos K5Pw== X-Gm-Message-State: AOJu0YxUZHFfNSsazTZcFP4NUwstx1nY0mVJn7QzY2umH4fZ7G7uZokC Q9GzjlWp0lS0AR+ydz2h1CfRodA83/WDoEUx25MktPBAl2faYrRotb8k54ugYZ4= X-Received: by 2002:a2e:8716:0:b0:2d2:39dc:ada1 with SMTP id m22-20020a2e8716000000b002d239dcada1mr2978992lji.15.1708418188869; Tue, 20 Feb 2024 00:36:28 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id k1-20020a2e2401000000b002d2468d3bacsm195317ljk.9.2024.02.20.00.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:36:28 -0800 (PST) From: Linus Walleij Date: Tue, 20 Feb 2024 09:36:27 +0100 Subject: [PATCH 4/5] regulator: max8997: Convert to GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-descriptors-regulators-v1-4-097f608694be@linaro.org> References: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> In-Reply-To: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> To: Liam Girdwood , Mark Brown , Support Opensource , Lee Jones Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791406480442783862 X-GMAIL-MSGID: 1791406480442783862 This rewrites the max8997 regulator driver to fetch the dvs regulators as descriptors. This will likely mostly come from the device tree since there are no in-tree users of the platform data, but supplying GPIO descriptor tables from board files is also possible if needed. Signed-off-by: Linus Walleij --- drivers/regulator/max8997-regulator.c | 85 +++++++++++------------------------ include/linux/mfd/max8997.h | 1 - 2 files changed, 25 insertions(+), 61 deletions(-) diff --git a/drivers/regulator/max8997-regulator.c b/drivers/regulator/max8997-regulator.c index 0b38eaa73597..5f201ee9a5b8 100644 --- a/drivers/regulator/max8997-regulator.c +++ b/drivers/regulator/max8997-regulator.c @@ -9,8 +9,7 @@ #include #include -#include -#include +#include #include #include #include @@ -32,7 +31,7 @@ struct max8997_data { u8 buck1_vol[8]; u8 buck2_vol[8]; u8 buck5_vol[8]; - int buck125_gpios[3]; + struct gpio_desc *buck125_gpiods[3]; int buck125_gpioindex; bool ignore_gpiodvs_side_effect; @@ -52,9 +51,9 @@ static inline void max8997_set_gpio(struct max8997_data *max8997) int set2 = ((max8997->buck125_gpioindex) >> 1) & 0x1; int set1 = ((max8997->buck125_gpioindex) >> 2) & 0x1; - gpio_set_value(max8997->buck125_gpios[0], set1); - gpio_set_value(max8997->buck125_gpios[1], set2); - gpio_set_value(max8997->buck125_gpios[2], set3); + gpiod_set_value(max8997->buck125_gpiods[0], set1); + gpiod_set_value(max8997->buck125_gpiods[1], set2); + gpiod_set_value(max8997->buck125_gpiods[2], set3); } struct voltage_map_desc { @@ -873,31 +872,13 @@ static struct regulator_desc regulators[] = { }; #ifdef CONFIG_OF -static int max8997_pmic_dt_parse_dvs_gpio(struct platform_device *pdev, - struct max8997_platform_data *pdata, - struct device_node *pmic_np) -{ - int i, gpio; - - for (i = 0; i < 3; i++) { - gpio = of_get_named_gpio(pmic_np, - "max8997,pmic-buck125-dvs-gpios", i); - if (!gpio_is_valid(gpio)) { - dev_err(&pdev->dev, "invalid gpio[%d]: %d\n", i, gpio); - return -EINVAL; - } - pdata->buck125_gpios[i] = gpio; - } - return 0; -} - static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, struct max8997_platform_data *pdata) { struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); struct device_node *pmic_np, *regulators_np, *reg_np; struct max8997_regulator_data *rdata; - unsigned int i, dvs_voltage_nr = 1, ret; + unsigned int i, dvs_voltage_nr = 1; pmic_np = iodev->dev->of_node; if (!pmic_np) { @@ -949,10 +930,6 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev, if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || pdata->buck5_gpiodvs) { - ret = max8997_pmic_dt_parse_dvs_gpio(pdev, pdata, pmic_np); - if (ret) - return -EINVAL; - if (of_property_read_u32(pmic_np, "max8997,pmic-buck125-default-dvs-idx", &pdata->buck125_default_idx)) { @@ -1039,7 +1016,6 @@ static int max8997_pmic_probe(struct platform_device *pdev) max8997->buck1_gpiodvs = pdata->buck1_gpiodvs; max8997->buck2_gpiodvs = pdata->buck2_gpiodvs; max8997->buck5_gpiodvs = pdata->buck5_gpiodvs; - memcpy(max8997->buck125_gpios, pdata->buck125_gpios, sizeof(int) * 3); max8997->ignore_gpiodvs_side_effect = pdata->ignore_gpiodvs_side_effect; nr_dvs = (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || @@ -1110,38 +1086,27 @@ static int max8997_pmic_probe(struct platform_device *pdev) */ if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || pdata->buck5_gpiodvs) { + const char *gpio_names[3] = {"MAX8997 SET1", "MAX8997 SET2", "MAX8997 SET3"}; - if (!gpio_is_valid(pdata->buck125_gpios[0]) || - !gpio_is_valid(pdata->buck125_gpios[1]) || - !gpio_is_valid(pdata->buck125_gpios[2])) { - dev_err(&pdev->dev, "GPIO NOT VALID\n"); - return -EINVAL; - } + for (i = 0; i < 3; i++) { + enum gpiod_flags flags; - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], - "MAX8997 SET1"); - if (ret) - return ret; - - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], - "MAX8997 SET2"); - if (ret) - return ret; - - ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], - "MAX8997 SET3"); - if (ret) - return ret; - - gpio_direction_output(pdata->buck125_gpios[0], - (max8997->buck125_gpioindex >> 2) - & 0x1); /* SET1 */ - gpio_direction_output(pdata->buck125_gpios[1], - (max8997->buck125_gpioindex >> 1) - & 0x1); /* SET2 */ - gpio_direction_output(pdata->buck125_gpios[2], - (max8997->buck125_gpioindex >> 0) - & 0x1); /* SET3 */ + if (max8997->buck125_gpioindex & BIT(2 - i)) + flags = GPIOD_OUT_HIGH; + else + flags = GPIOD_OUT_LOW; + + max8997->buck125_gpiods[i] = devm_gpiod_get_index(iodev->dev, + "max8997,pmic-buck125-dvs", + i, + flags); + if (IS_ERR(max8997->buck125_gpiods[i])) { + ret = PTR_ERR(max8997->buck125_gpiods[i]); + return dev_err_probe(iodev->dev, ret, "cant get GPIO %d (%d)\n", + i, ret); + } + gpiod_set_consumer_name(max8997->buck125_gpiods[i], gpio_names[i]); + } } /* DVS-GPIO disabled */ diff --git a/include/linux/mfd/max8997.h b/include/linux/mfd/max8997.h index 6193905abbb5..5c2cc1103437 100644 --- a/include/linux/mfd/max8997.h +++ b/include/linux/mfd/max8997.h @@ -178,7 +178,6 @@ struct max8997_platform_data { * */ bool ignore_gpiodvs_side_effect; - int buck125_gpios[3]; /* GPIO of [0]SET1, [1]SET2, [2]SET3 */ int buck125_default_idx; /* Default value of SET1, 2, 3 */ unsigned int buck1_voltage[8]; /* buckx_voltage in uV */ bool buck1_gpiodvs; From patchwork Tue Feb 20 08:36:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 203481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp265314dyc; Tue, 20 Feb 2024 00:37:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUsHg9E1z0dnkNDlaGgNjVqTHmjpFImvYQ4980E66cnPeIyJG7bI9ccz3OOfkG3p/eKkfQYjIKMQ7mEWenMba/a5OzLeQ== X-Google-Smtp-Source: AGHT+IE/hImoXeVrO2hzs/lKM9fYcACN10ngkxtMRlqifdhp4vRB3d7XjezG65jZhqdluUDLjpMa X-Received: by 2002:a17:906:7f92:b0:a3e:6465:4195 with SMTP id f18-20020a1709067f9200b00a3e64654195mr3733276ejr.63.1708418261153; Tue, 20 Feb 2024 00:37:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708418261; cv=pass; d=google.com; s=arc-20160816; b=SbxbpqPihUy7zXZHHwqlZIrEDoRET5l9q4VtvVFZDhfcRbLowqLJLeHgZ5DoncRLfG k4jIq0nIxg5e1ls1PwrYSAzzRUK43QljFtczPwTA3soDv3wgP1kIMwV6yBLMIadzMLJj Hl0VJYLyEjepq1XbymY5ryk1J2gyRpeQutCToRITMuYilvVpqQkydh1PkKCAKpnN6Y1G QzPTUIIggOgpdY6Fxyxpr68CI/XZ7ZM6UYOshrCU+7TNPreHykF4EyfYoQB9ZhbLOn7q YhmaCO8Fov1yZqNLyHLodBGXcXb5pu0WR4GsEhi8nqQ95ZOQkiX74ClERw42Jp8MWtfN +Pbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=uE6eEEsx/5e/WVNE54y1IYM2rczvEuy341hCQZHsSiQ=; fh=j1yS28tmtQOJHnBdCDYBJgx1/yVVBS1Kot++6x+bjk8=; b=WiArdg3jd7ibJvCRoOvsgjTtOi3vbBibt44O8bdv7HP1DXNg3CAVqMswJq2j1r48v3 lavPP5+/+Erl0wqO8JW1PADlIuyqCcmoO8k9DD0vGx90GjIAtyAQC6L5mqcI7nKhHCTc OF8FJ5O0+vx/+TNU8SsRGwEL1aqf0rOCo0OjFjgul7zcDgmQP/nOJ4Rqh0wiqLG6tTTS ZhmXsyJehZ90POL8h1BixZZ0y8z7FTtDtWFSwTlUU3t8JmTu0u3FMwYBSUApTK3WxaIj v4wMHdn/jZwZ+mLu3reCRSHFvixWVWWoAYVAg4wv6Wf60ZwjAsDuvON43Y1qRFBNKGrW 3bLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=khJdv0r1; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l2-20020a1709060e0200b00a3da0479388si3370573eji.791.2024.02.20.00.37.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=khJdv0r1; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-72573-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72573-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7BCD01F21070 for ; Tue, 20 Feb 2024 08:37:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFAD45F552; Tue, 20 Feb 2024 08:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="khJdv0r1" Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88B085D734 for ; Tue, 20 Feb 2024 08:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418193; cv=none; b=AlHqxhIf16/DRjzODn2gLF0oCq9rHE1otJZqJPMOJQrEP+icDcUhyoGA7kj71c9D33RenB5kTWJhqyHoQB6hpw925WV0SI7Iz3nZD1aufMwnQzbST8j3zDxueTM6LONDPRIRhXljJDKdraQmoMwbdYfaxgYRilTExSn4yUoYBkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708418193; c=relaxed/simple; bh=fyH53ptZ4KyW3Du56DUQ5YuVOX6CkzmPU/Yac+/WEZQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kco7AjnNJyJMg7x5+pAq29A6APQz7erF3CefOKKuiAcvuM+HTa7koFlbhf2wWsJNiMsnBZoDpPj4Avztt5FxsDlCC1qedtkaSafeCZ8QV+pCjeoJ/3utN+HPd6o459WO4DnSP63HKj3Ms4rbp/GqKfs0h1Qw+mrBrmt7itrW3lg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=khJdv0r1; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d208d0b282so69034541fa.0 for ; Tue, 20 Feb 2024 00:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708418190; x=1709022990; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uE6eEEsx/5e/WVNE54y1IYM2rczvEuy341hCQZHsSiQ=; b=khJdv0r1Rg/wr4Nvatxr1VRAndM5tulqZuNlda7jAL4Ivz+zXwf8aDX16pss5pI2rQ xGuzI3K2n9SmffzLEO95JOgRULFUB4pMWxW7DAVG5Nz7c62ZPZsO7j8FwqRMAqauXCxS yz8uc2HuEz02Q5XN/jKKcPAuiGfmbuuMvtWKRPj5Z8hSHsHQfCHFTde+ILrE63dNkpct Txh9p7vddFZSm3CWoOBYiAWsXlZWMDG1QWgAe7JE2Wi4faMGRqCYAy9strq3G7xh0JoD PXOXJaea3GsdQFJ+mI1BOItxrwH8ld29mkpOIfcJNpvwPs0MtI43jnbszP8f+I6OWDOV 8n6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708418190; x=1709022990; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uE6eEEsx/5e/WVNE54y1IYM2rczvEuy341hCQZHsSiQ=; b=koN8Y5g9MH8y+RZtHiWBT7bIUrAKbTIUrvPiL2MQukWru4HLQxEuTwAsvS7cL/sqSP 8kmZy/wXBtBeuuXTM60xlmaweYuEn9sD+zajv1YEYne4k37qKr5j91OIoneKwLaJbx2o p4MXkuz/9LWZGdFmghPz5mNNhsQ9kj61wWxflq90UqNfVeDjv5BG+Ljzf8n0K2Nbpl44 +RS/KgHVQwOgf87dniQ/1oq33asi+ohDpAak0WARQqfS+Z+fjGpL7I0fHhEHZXntjyX/ ICMWILm7t/yZ1sGtsJQMJU9P85VbBMpV2lCY04C4nBW8fmU0tnNOtcAGuSKNgQKdoUX1 2nog== X-Gm-Message-State: AOJu0YxBcrvkKZLmC6yCmWs9DX8NLJI96yWG3G1YV72do5HM65Sl/M4f nlHtbtDFvkTXYRvdDJDyIdj/b9bwDym6y8O3DiOFYWf7/um0i+a1Yj5zpBXA5Yc= X-Received: by 2002:a05:651c:1423:b0:2d2:3978:a11 with SMTP id u35-20020a05651c142300b002d239780a11mr3449620lje.36.1708418189760; Tue, 20 Feb 2024 00:36:29 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id k1-20020a2e2401000000b002d2468d3bacsm195317ljk.9.2024.02.20.00.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 00:36:29 -0800 (PST) From: Linus Walleij Date: Tue, 20 Feb 2024 09:36:28 +0100 Subject: [PATCH 5/5] regulator: max8998: Convert to GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240220-descriptors-regulators-v1-5-097f608694be@linaro.org> References: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> In-Reply-To: <20240220-descriptors-regulators-v1-0-097f608694be@linaro.org> To: Liam Girdwood , Mark Brown , Support Opensource , Lee Jones Cc: linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791406386516550391 X-GMAIL-MSGID: 1791406386516550391 This rewrites the max8998 regulator driver to fetch the dvs regulators as descriptors. This will likely mostly come from the device tree since there are no in-tree users of the platform data, but supplying GPIO descriptor tables from board files is also possible if needed. Signed-off-by: Linus Walleij --- drivers/regulator/max8998.c | 150 ++++++++++++++++---------------------------- include/linux/mfd/max8998.h | 6 -- 2 files changed, 54 insertions(+), 102 deletions(-) diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index fadb4717384a..254a77887f66 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c @@ -10,12 +10,12 @@ #include #include #include -#include +#include +#include #include #include #include #include -#include #include #include #include @@ -31,6 +31,9 @@ struct max8998_data { unsigned int buck1_idx; /* index to last changed voltage */ /* value in a set */ unsigned int buck2_idx; + struct gpio_desc *buck1_gpio1; + struct gpio_desc *buck1_gpio2; + struct gpio_desc *buck2_gpio; }; static const unsigned int charger_current_table[] = { @@ -227,15 +230,15 @@ static int max8998_set_voltage_ldo_sel(struct regulator_dev *rdev, return ret; } -static inline void buck1_gpio_set(int gpio1, int gpio2, int v) +static inline void buck1_gpio_set(struct gpio_desc *gpio1, struct gpio_desc *gpio2, int v) { - gpio_set_value(gpio1, v & 0x1); - gpio_set_value(gpio2, (v >> 1) & 0x1); + gpiod_set_value(gpio1, v & 0x1); + gpiod_set_value(gpio2, (v >> 1) & 0x1); } -static inline void buck2_gpio_set(int gpio, int v) +static inline void buck2_gpio_set(struct gpio_desc *gpio, int v) { - gpio_set_value(gpio, v & 0x1); + gpiod_set_value(gpio, v & 0x1); } static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, @@ -260,16 +263,15 @@ static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, selector, max8998->buck1_vol[0], max8998->buck1_vol[1], max8998->buck1_vol[2], max8998->buck1_vol[3]); - if (gpio_is_valid(pdata->buck1_set1) && - gpio_is_valid(pdata->buck1_set2)) { + if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { /* check if requested voltage */ /* value is already defined */ for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { if (max8998->buck1_vol[j] == selector) { max8998->buck1_idx = j; - buck1_gpio_set(pdata->buck1_set1, - pdata->buck1_set2, j); + buck1_gpio_set(max8998->buck1_gpio1, + max8998->buck1_gpio2, j); goto buck1_exit; } } @@ -286,13 +288,13 @@ static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, &shift, &mask); ret = max8998_write_reg(i2c, reg, selector); - buck1_gpio_set(pdata->buck1_set1, - pdata->buck1_set2, max8998->buck1_idx); + buck1_gpio_set(max8998->buck1_gpio1, + max8998->buck1_gpio2, max8998->buck1_idx); buck1_last_val++; buck1_exit: dev_dbg(max8998->dev, "%s: SET1:%d, SET2:%d\n", - i2c->name, gpio_get_value(pdata->buck1_set1), - gpio_get_value(pdata->buck1_set2)); + i2c->name, gpiod_get_value(max8998->buck1_gpio1), + gpiod_get_value(max8998->buck1_gpio2)); break; } else { ret = max8998_write_reg(i2c, reg, selector); @@ -303,14 +305,13 @@ static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, dev_dbg(max8998->dev, "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n", selector, max8998->buck2_vol[0], max8998->buck2_vol[1]); - if (gpio_is_valid(pdata->buck2_set3)) { - + if (max8998->buck2_gpio) { /* check if requested voltage */ /* value is already defined */ for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { if (max8998->buck2_vol[j] == selector) { max8998->buck2_idx = j; - buck2_gpio_set(pdata->buck2_set3, j); + buck2_gpio_set(max8998->buck2_gpio, j); goto buck2_exit; } } @@ -322,10 +323,10 @@ static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, ®, &shift, &mask); ret = max8998_write_reg(i2c, reg, selector); max8998->buck2_vol[max8998->buck2_idx] = selector; - buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); + buck2_gpio_set(max8998->buck2_gpio, max8998->buck2_idx); buck2_exit: dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, - gpio_get_value(pdata->buck2_set3)); + gpiod_get_value(max8998->buck2_gpio)); } else { ret = max8998_write_reg(i2c, reg, selector); } @@ -539,36 +540,6 @@ static const struct regulator_desc regulators[] = { charger_current_table, MAX8998_REG_CHGR1, 0x7), }; -static int max8998_pmic_dt_parse_dvs_gpio(struct max8998_dev *iodev, - struct max8998_platform_data *pdata, - struct device_node *pmic_np) -{ - int gpio; - - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 0); - if (!gpio_is_valid(gpio)) { - dev_err(iodev->dev, "invalid buck1 gpio[0]: %d\n", gpio); - return -EINVAL; - } - pdata->buck1_set1 = gpio; - - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck1-dvs-gpios", 1); - if (!gpio_is_valid(gpio)) { - dev_err(iodev->dev, "invalid buck1 gpio[1]: %d\n", gpio); - return -EINVAL; - } - pdata->buck1_set2 = gpio; - - gpio = of_get_named_gpio(pmic_np, "max8998,pmic-buck2-dvs-gpio", 0); - if (!gpio_is_valid(gpio)) { - dev_err(iodev->dev, "invalid buck 2 gpio: %d\n", gpio); - return -EINVAL; - } - pdata->buck2_set3 = gpio; - - return 0; -} - static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev, struct max8998_platform_data *pdata) { @@ -614,10 +585,6 @@ static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev, of_node_put(reg_np); of_node_put(regulators_np); - ret = max8998_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); - if (ret) - return -EINVAL; - pdata->buck_voltage_lock = of_property_read_bool(pmic_np, "max8998,pmic-buck-voltage-lock"); ret = of_property_read_u32(pmic_np, @@ -665,6 +632,7 @@ static int max8998_pmic_probe(struct platform_device *pdev) struct regulator_dev *rdev; struct max8998_data *max8998; struct i2c_client *i2c; + enum gpiod_flags flags; int i, ret; unsigned int v; @@ -693,37 +661,38 @@ static int max8998_pmic_probe(struct platform_device *pdev) max8998->buck1_idx = pdata->buck1_default_idx; max8998->buck2_idx = pdata->buck2_default_idx; - /* NOTE: */ - /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */ - /* will be displayed */ - /* Check if MAX8998 voltage selection GPIOs are defined */ - if (gpio_is_valid(pdata->buck1_set1) && - gpio_is_valid(pdata->buck1_set2)) { - /* Check if SET1 is not equal to 0 */ - if (!pdata->buck1_set1) { - dev_err(&pdev->dev, - "MAX8998 SET1 GPIO defined as 0 !\n"); - WARN_ON(!pdata->buck1_set1); - return -EIO; - } - /* Check if SET2 is not equal to 0 */ - if (!pdata->buck1_set2) { - dev_err(&pdev->dev, - "MAX8998 SET2 GPIO defined as 0 !\n"); - WARN_ON(!pdata->buck1_set2); - return -EIO; - } - - gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); - gpio_direction_output(pdata->buck1_set1, - max8998->buck1_idx & 0x1); - - - gpio_request(pdata->buck1_set2, "MAX8998 BUCK1_SET2"); - gpio_direction_output(pdata->buck1_set2, - (max8998->buck1_idx >> 1) & 0x1); - + flags = (max8998->buck1_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + max8998->buck1_gpio1 = devm_gpiod_get_index_optional(iodev->dev, + "max8998,pmic-buck1-dvs", + 0, + flags); + if (IS_ERR(max8998->buck1_gpio1)) + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio1), + "could not get BUCK1 GPIO1\n"); + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET1"); + + flags = (max8998->buck1_idx & BIT(1)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + max8998->buck1_gpio2 = devm_gpiod_get_index_optional(iodev->dev, + "max8998,pmic-buck1-dvs", + 1, + flags); + if (IS_ERR(max8998->buck1_gpio2)) + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck1_gpio2), + "could not get BUCK1 GPIO2\n"); + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK1_SET2"); + + flags = (max8998->buck2_idx & BIT(0)) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + max8998->buck2_gpio = devm_gpiod_get_index_optional(iodev->dev, + "max8998,pmic-buck2-dvs", + 0, + flags); + if (IS_ERR(max8998->buck2_gpio)) + return dev_err_probe(&pdev->dev, PTR_ERR(max8998->buck2_gpio), + "could not get BUCK2 GPIO\n"); + gpiod_set_consumer_name(max8998->buck1_gpio1, "MAX8998 BUCK2_SET3"); + + if (max8998->buck1_gpio1 && max8998->buck1_gpio2) { /* Set predefined values for BUCK1 registers */ for (v = 0; v < ARRAY_SIZE(pdata->buck1_voltage); ++v) { int index = MAX8998_BUCK1 - MAX8998_LDO2; @@ -742,18 +711,7 @@ static int max8998_pmic_probe(struct platform_device *pdev) } } - if (gpio_is_valid(pdata->buck2_set3)) { - /* Check if SET3 is not equal to 0 */ - if (!pdata->buck2_set3) { - dev_err(&pdev->dev, - "MAX8998 SET3 GPIO defined as 0 !\n"); - WARN_ON(!pdata->buck2_set3); - return -EIO; - } - gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); - gpio_direction_output(pdata->buck2_set3, - max8998->buck2_idx & 0x1); - + if (max8998->buck2_gpio) { /* Set predefined values for BUCK2 registers */ for (v = 0; v < ARRAY_SIZE(pdata->buck2_voltage); ++v) { int index = MAX8998_BUCK2 - MAX8998_LDO2; diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h index 79c020bd0c70..a054e55c8646 100644 --- a/include/linux/mfd/max8998.h +++ b/include/linux/mfd/max8998.h @@ -65,10 +65,7 @@ struct max8998_regulator_data { * be other than the preset values. * @buck1_voltage: BUCK1 DVS mode 1 voltage registers * @buck2_voltage: BUCK2 DVS mode 2 voltage registers - * @buck1_set1: BUCK1 gpio pin 1 to set output voltage - * @buck1_set2: BUCK1 gpio pin 2 to set output voltage * @buck1_default_idx: Default for BUCK1 gpio pin 1, 2 - * @buck2_set3: BUCK2 gpio pin to set output voltage * @buck2_default_idx: Default for BUCK2 gpio pin. * @wakeup: Allow to wake up from suspend * @rtc_delay: LP3974 RTC chip bug that requires delay after a register @@ -91,10 +88,7 @@ struct max8998_platform_data { bool buck_voltage_lock; int buck1_voltage[4]; int buck2_voltage[2]; - int buck1_set1; - int buck1_set2; int buck1_default_idx; - int buck2_set3; int buck2_default_idx; bool wakeup; bool rtc_delay;