From patchwork Fri Jul 12 16:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731932 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 0CC5D1741D2 for ; Fri, 12 Jul 2024 16:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800247; cv=none; b=ewfIGgwNrDDBLG5QVJdmyvKMryC5wmpQv3ecbpuHG0fw4N5FGeA5ZxwFx9xaS291/TgpLfGU36tzUGo1R8qnk+dt9izTlU3v4V9j/9hs9sOoe2P/oMeDyniWYQOWZ6rRx3QhsxWW0qI/t8AB2HTqPEGiJVuIsKPCOPKb1i9++fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800247; c=relaxed/simple; bh=0VbOetS204hz3J5pkBmUitCsW+y9jRjY3qZVNN6H5vs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GmezHfj4FTFqXiqWAEJsaOWiqEfvHa1KWXyZTOkxhjt8VWGAT1YiQV/3B2xa+zbIwV3z7ZIKAKjM+48X8EtVjwIw0qT6f2EdjXchZEK7qXwNgBOieVrGLsK+tv2GxQE1xJPuTTffZAgBGGUbFPxCdaWjc7QrwtXbsofTu43+oEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=lBSiWQge; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="lBSiWQge" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-70368b53cc0so1040322a34.1 for ; Fri, 12 Jul 2024 09:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800244; x=1721405044; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y+/He1wcvWjmLAJpdLkPUiwNIP+C83lJXvlwPZpJIgw=; b=lBSiWQgerEAy2fr7z4pByWR48BuAsT1R87VwVII8U/2Iy0eC8oiOgil7MkIr9/CeAu nPbSsLaRyiaWBOJujo9GEC2uAB3yFftpX9MOGmhyT4GfRrBXQFRiwQX4O84TR8MuyI8j ZzGe4/oBuRLoZVNo5fkr8o9NAx3f86iTQoijV6RMmqHnKD6bDbLBJS4NAc1Iu2y7oc4t NKkRSaBHjRkTp6ycfwl1JkhN/EMWAUDCtwyDHYwsFir8OY8vlgkR6jpoGgyCIedbTZej t7HWotzEcMjn2jxTQDZg5tbrcKQwIJ5LA/igeVW870hGR+6FKINx/ohuajkFPqtPUcG/ d50Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800244; x=1721405044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y+/He1wcvWjmLAJpdLkPUiwNIP+C83lJXvlwPZpJIgw=; b=JAXDOIySj0KbktJfeRegAWBnqbovaEyDHrTAjwZZeeQO8YlOukedecOsCh92iD7Q1s ei0IrRZS6RtcgvG2MENQGmfHdMRXTm6SHpNtt3zIyNGG/+FPI2Lrd65wfoUefyX5OrIb 6FvfhjyFN67Q+P5EEI9vy2m8gkPTjOEzt+zgVEP3lAFuO8OCKzH1OdvtyS1COijAHzpg zgIiWIR+It596qfBIvOQ2jALQs/wGfhGWXHAkPpbtYNx3vaFyAS7QZhufJH0ZT0Ape0n N1hYHB/x73QtsvX0sAkGPGMpeyvWRFT97LnHFLqud9lCGIKzKHBovGaBHx8gkc0Yvslm Fb0g== X-Forwarded-Encrypted: i=1; AJvYcCWSeIo3qQr9qfRBTiPdwLF28WWXSnN50nWVFLlXt1GUQo4ytS9Qy4INqd++MP/xxee95uL/NuL2ubEBMqMraNO5IBIIL5Yxf1M6 X-Gm-Message-State: AOJu0YzZd+aU8LbRBxzzDq4JdAwSYLRE7A/4d/7BQqM/ffFfFvucIsFx mSNivXnmWF0K000nGPM0qNQ3ls7xzNkE7Z8j+HQ+HbWMWASTLJlFQpQYDGhI/f0= X-Google-Smtp-Source: AGHT+IH/srFVuntJPDWvs53ehKj/qU4WBBDG3GMrsOa1plrNwF2SxPQ7RJAITmopV3xaWH2vtGNyxQ== X-Received: by 2002:a05:6870:d69e:b0:254:9ded:a3bf with SMTP id 586e51a60fabf-25eaebdfb43mr10277746fac.45.1720800244107; Fri, 12 Jul 2024 09:04:04 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:03 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] iio: dac: mcp4728: rename err to ret in probe function Date: Fri, 12 Jul 2024 11:03:52 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-1-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 To prepare for using a function that returns a non-error value, rename the variable 'err' to 'ret' in the probe function. Signed-off-by: David Lechner --- drivers/iio/dac/mcp4728.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/iio/dac/mcp4728.c b/drivers/iio/dac/mcp4728.c index c449ca949465..300985beb35d 100644 --- a/drivers/iio/dac/mcp4728.c +++ b/drivers/iio/dac/mcp4728.c @@ -540,7 +540,7 @@ static int mcp4728_probe(struct i2c_client *client) const struct i2c_device_id *id = i2c_client_get_device_id(client); struct mcp4728_data *data; struct iio_dev *indio_dev; - int err; + int ret; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) @@ -554,14 +554,14 @@ static int mcp4728_probe(struct i2c_client *client) if (IS_ERR(data->vdd_reg)) return PTR_ERR(data->vdd_reg); - err = regulator_enable(data->vdd_reg); - if (err) - return err; + ret = regulator_enable(data->vdd_reg); + if (ret) + return ret; - err = devm_add_action_or_reset(&client->dev, mcp4728_reg_disable, + ret = devm_add_action_or_reset(&client->dev, mcp4728_reg_disable, data->vdd_reg); - if (err) - return err; + if (ret) + return ret; /* * MCP4728 has internal EEPROM that save each channel boot @@ -569,15 +569,15 @@ static int mcp4728_probe(struct i2c_client *client) * driver at kernel boot. mcp4728_init_channels_data() reads back DAC * settings and stores them in data structure. */ - err = mcp4728_init_channels_data(data); - if (err) { - return dev_err_probe(&client->dev, err, + ret = mcp4728_init_channels_data(data); + if (ret) { + return dev_err_probe(&client->dev, ret, "failed to read mcp4728 current configuration\n"); } - err = mcp4728_init_scales_avail(data); - if (err) { - return dev_err_probe(&client->dev, err, + ret = mcp4728_init_scales_avail(data); + if (ret) { + return dev_err_probe(&client->dev, ret, "failed to init scales\n"); } From patchwork Fri Jul 12 16:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731931 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 F0D6F175545 for ; Fri, 12 Jul 2024 16:04:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800247; cv=none; b=IJDoWvWjadGm5014qN+ETbbavs66YK7B5NQ2OxEMEjq8Yk5ptTaZ0j6LIArJq+6hQDpGVVFRCd5oEKHlqNH4uqrTOKEXnI+0Ge0Af+2oHHuhiltsn7UkwiHWd0xDlLF0LY1MLHQvmTW1cSXSGltiAz1Jm8B3OG0NXSBR3F2ttD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800247; c=relaxed/simple; bh=Y/k/wdBv/5beOfFpJAQFfQXG5QorlewTAyQxhJSger4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=to68mJ4VT3ktQgUsLgUy0mPHjLq7p5Si2RT3D2Q3L/3tt23pb8CVwGviHo4kk6/VHU0THXr8usonYkGSI3AnPdpdIGmDoSjvy0djIOkCuiBu8zorPI+o4PhRp1fGw90chShxtlJaabOio5+plychYufz+U8nF5fS9vD9Q1mVkrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=QnmO49jl; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="QnmO49jl" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7037c464792so1128396a34.2 for ; Fri, 12 Jul 2024 09:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800245; x=1721405045; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xtk0UvTBio0HdPiv9SeTHdQ/nYZSzty+YaDbepVhjDk=; b=QnmO49jlVfOP5X+O3cHivPKymPZJd4lFil1HBGfoJ4qvg0IbvoPY9m5+ZokpaLpA7I n8X+LlmymvsfE/47bQaV69wiGdOq4DIOIeymue6tFahIFyx3XueT678CYrhADLp/U35t Gi78sFv2PYchfiYGMJJjcs0AWleJTuJu94gBBTtU8xO8uKivjWKDpyDYaZLwxW6btNlt 9HKfm4CxTucC66ijB11ptNxaug7uHPVY68m4fGMTJbf3ITmjFrlBnF7oE+XFFtCBNzaJ 1/uzj0V7sXa3Wd5Rm1QFGSoM+Cl5wZWSzfM94o0qaRY9aHu+SOodD7Wo0atNq0RXYVqV SAXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800245; x=1721405045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xtk0UvTBio0HdPiv9SeTHdQ/nYZSzty+YaDbepVhjDk=; b=eQXyOneyyjJZCCq1+HHus3njBYvh091+tZ6hOBVpTqu7kY5+M4SyzT7iSpYDbsV6n8 TyxRpox56nBxna7vq3uzcGKYqmnXALP8uYS+3Bxvc2huQROMXPh451LEXBlRqWDGjTi0 xZ9aB7CpPrY0KLnswNx7k3ulnudV3OMqWr6J7abAplK/XVb3KVdlU2T7VSIP/CTwEjna fyLvQmDiFTLd2tYmoZMFEYh9e/vQpJYlxl2vV9JLFJ2ICRQP550TwJheJZzkCI5p5ka8 HusQLiEFLqb3MSwd6A9gGOuRHqqGNi51GLiYHL0Iht29zP3TBx9Fgj22ejT1FKk256Y4 2LFg== X-Forwarded-Encrypted: i=1; AJvYcCVxu5Xm51OtgdrAxy+RH3Nibaa5Gv8mg8Co0oQQz8rbMetHv0Rkuick1ZBOH43V+i4qM63cruMWsfoqYR+tGm5EP0e1XeR8oqUB X-Gm-Message-State: AOJu0Yzhc15OS5d3qB+ilLcoZKwBVHog4d7RSst+QIEWTJepxslW99ne pciLOkIojKbz8W/yRWQtuIfZ0YBvAq8vNOQrc0iQRb5TeC6SA1ValCs4uZe8AWk= X-Google-Smtp-Source: AGHT+IH9XtVdLylUZCQ+EzQ5KpOpsjBt1EAapLPX8XGhtAR2cvYah4rBJcTwPGQIOWEJcZUPCn7lRA== X-Received: by 2002:a05:6870:d612:b0:25e:8509:160e with SMTP id 586e51a60fabf-25eae74a09amr10623112fac.3.1720800244908; Fri, 12 Jul 2024 09:04:04 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:04 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] iio: dac: mcp4728: use devm_regulator_get_enable_read_voltage() Date: Fri, 12 Jul 2024 11:03:53 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-2-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 This makes use of the new devm_regulator_get_enable_read_voltage() helper function to reduce boilerplate code in the MCP4728 DAC driver. Signed-off-by: David Lechner --- drivers/iio/dac/mcp4728.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/iio/dac/mcp4728.c b/drivers/iio/dac/mcp4728.c index 300985beb35d..192175dc6419 100644 --- a/drivers/iio/dac/mcp4728.c +++ b/drivers/iio/dac/mcp4728.c @@ -84,7 +84,6 @@ enum mcp4728_scale { struct mcp4728_data { struct i2c_client *client; - struct regulator *vdd_reg; bool powerdown; int scales_avail[MCP4728_N_SCALES * 2]; struct mcp4728_channel_data chdata[MCP4728_N_CHANNELS]; @@ -415,15 +414,9 @@ static void mcp4728_init_scale_avail(enum mcp4728_scale scale, int vref_mv, data->scales_avail[scale * 2 + 1] = value_micro; } -static int mcp4728_init_scales_avail(struct mcp4728_data *data) +static int mcp4728_init_scales_avail(struct mcp4728_data *data, int vdd_mv) { - int ret; - - ret = regulator_get_voltage(data->vdd_reg); - if (ret < 0) - return ret; - - mcp4728_init_scale_avail(MCP4728_SCALE_VDD, ret / 1000, data); + mcp4728_init_scale_avail(MCP4728_SCALE_VDD, vdd_mv, data); mcp4728_init_scale_avail(MCP4728_SCALE_VINT_NO_GAIN, 2048, data); mcp4728_init_scale_avail(MCP4728_SCALE_VINT_GAIN_X2, 4096, data); @@ -530,17 +523,12 @@ static int mcp4728_init_channels_data(struct mcp4728_data *data) return 0; } -static void mcp4728_reg_disable(void *reg) -{ - regulator_disable(reg); -} - static int mcp4728_probe(struct i2c_client *client) { const struct i2c_device_id *id = i2c_client_get_device_id(client); struct mcp4728_data *data; struct iio_dev *indio_dev; - int ret; + int ret, vdd_mv; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) @@ -550,18 +538,11 @@ static int mcp4728_probe(struct i2c_client *client) i2c_set_clientdata(client, indio_dev); data->client = client; - data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); - if (IS_ERR(data->vdd_reg)) - return PTR_ERR(data->vdd_reg); - - ret = regulator_enable(data->vdd_reg); - if (ret) + ret = devm_regulator_get_enable_read_voltage(&client->dev, "vdd"); + if (ret < 0) return ret; - ret = devm_add_action_or_reset(&client->dev, mcp4728_reg_disable, - data->vdd_reg); - if (ret) - return ret; + vdd_mv = ret / 1000; /* * MCP4728 has internal EEPROM that save each channel boot @@ -575,7 +556,7 @@ static int mcp4728_probe(struct i2c_client *client) "failed to read mcp4728 current configuration\n"); } - ret = mcp4728_init_scales_avail(data); + ret = mcp4728_init_scales_avail(data, vdd_mv); if (ret) { return dev_err_probe(&client->dev, ret, "failed to init scales\n"); From patchwork Fri Jul 12 16:03:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731933 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 DC63917557E for ; Fri, 12 Jul 2024 16:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800248; cv=none; b=gkNjPunhN6iaVWZdTt1yN165jpIqJvnWD5JKhI1ZBYaUCokyDN5rlmArH5zJDKldLKx9GpWSwqpifq0jybr9VUjMr+Ao2L0jN0aX2PvNABD/2kGUMtZXmslHxN6TVIFrcrau1gChl67nGkIx2lcyTyrNhgJk8Lm5BOvnPFXuUso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800248; c=relaxed/simple; bh=LiCm3tBJ7AYWSQZO/TCKsxT1uryLYML0nN19d4B4ZF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pWw76Tb2V+2EO2Jq06JHkCYB0OP8G6uwmhhHbGXAUuVUHRzstMho8SPR/TIajLaocR36OpzHhJAcS2f++T4RLXm6r+ZZXo1wcQalPNtpqlCI/k5qTwKDF/u4tannpjGeYtTs24ojc1I4A8GuJNS4bE9r4eXsLRE1n7zwlIGuJTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=KeMt8SQl; arc=none smtp.client-ip=209.85.160.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="KeMt8SQl" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-25e3bc751daso1170541fac.3 for ; Fri, 12 Jul 2024 09:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800246; x=1721405046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6yfWKG0y/JQs2Xv+AEtYK/Qt5yfxPJbz/kYQptJy6iA=; b=KeMt8SQlM0UjK4ie+NebsRt8QVaRmBzyREDsbvp7BBBBXeUmIwCVV5au67+bk861oH IsXsIQH3dygQEvxQoRPNyhGIxOf8yJuEho4nI5YEMbeimzXkOpx0NxjRhaVYJKwwtyYz cOx8nSo/DmI68jo9Z16I+/oZzrqnOXz26e3kAVXvF3a7rRh0xO/eQDScyzb99PTmNGAG /Iu9RWgUogGmojxW/iFu0ohf4Pf8/pDH6uPShT1o1p/5y6e32OVoEuphuGzaksFqB618 R6QuWo8qXf3i9ylXRnMw8uOg/JxnaPTRSevR327PEuRzrtd8Fh/B+PwPHsRXW7WxhypW 2TmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800246; x=1721405046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6yfWKG0y/JQs2Xv+AEtYK/Qt5yfxPJbz/kYQptJy6iA=; b=PoGuyxnyZ+geu8RhKTk1uslGlKz7UzT/BT7m3DrIcaKtYiRamJdu8LHlblBhW0qYkJ C65FmaZhzGCZpEurCeTHkBw7N8UTH1/oWgf4izKj78r10JExfiedjKysg00uyBgUN4HL 0Dg7wL/yeJw2UadPLtwtR8lttszL3Y56dvEhYfgzw3Bck7AMftYHXB6B/49vy9IJT7tI Ehg/2FHx8hgi8VmU9OaaQoo0o8vr9CabXfIGi44GL69Kw4oUHvJwUAUtAHd2fqFa1xoB 730keBO4xjjAhQ9HGlQo4U95VvJx/uA6sWPtW2/4zm5vI19KtPyZ+qr7qe5sdseCB6aN +iqg== X-Forwarded-Encrypted: i=1; AJvYcCXT8gJeT/afGAM1odGkbpjP0KFp2SjXxfpgvcA9m3z23sZkDEunZrhvFCh+g1LfmNsoNpr2grHcxBBQP1VS4Gm6c1Zzs+TCaAm9 X-Gm-Message-State: AOJu0YwDQIkJfNY3hrDRBrV6XotJ0jQyuPP1Ftvr46czZxAiQHffV3L+ DmGCs1pPnVn5JkqoQatDw/d/9CJW3i46II9Ktw/fFL2+5ZRVdkqM3zA+CZSjiVg= X-Google-Smtp-Source: AGHT+IFZ4u28V0aXqe1EKH1JX+VjsznMpOJ+/9Zy0MPgBrfQDd+ZR7G8IEC/bVTMldowmHzd8Hm2Ug== X-Received: by 2002:a05:6870:a11a:b0:254:a57e:1aed with SMTP id 586e51a60fabf-25eae84e38dmr10560652fac.26.1720800245795; Fri, 12 Jul 2024 09:04:05 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:05 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] iio: dac: mcp4922: use devm_regulator_get_enable_read_voltage() Date: Fri, 12 Jul 2024 11:03:54 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-3-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 This makes use of the new devm_regulator_get_enable_read_voltage() helper function to reduce boilerplate code in the MCP4922 DAC driver. The error message is slightly different because there is only one error return path now. Signed-off-by: David Lechner --- drivers/iio/dac/mcp4922.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c index da4327624d45..f89af70fa5af 100644 --- a/drivers/iio/dac/mcp4922.c +++ b/drivers/iio/dac/mcp4922.c @@ -30,7 +30,6 @@ struct mcp4922_state { struct spi_device *spi; unsigned int value[MCP4922_NUM_CHANNELS]; unsigned int vref_mv; - struct regulator *vref_reg; u8 mosi[2] __aligned(IIO_DMA_MINALIGN); }; @@ -132,24 +131,11 @@ static int mcp4922_probe(struct spi_device *spi) state = iio_priv(indio_dev); state->spi = spi; - state->vref_reg = devm_regulator_get(&spi->dev, "vref"); - if (IS_ERR(state->vref_reg)) - return dev_err_probe(&spi->dev, PTR_ERR(state->vref_reg), - "Vref regulator not specified\n"); - ret = regulator_enable(state->vref_reg); - if (ret) { - dev_err(&spi->dev, "Failed to enable vref regulator: %d\n", - ret); - return ret; - } + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0) + return dev_err_probe(&spi->dev, ret, "Failed to get vref voltage\n"); - ret = regulator_get_voltage(state->vref_reg); - if (ret < 0) { - dev_err(&spi->dev, "Failed to read vref regulator: %d\n", - ret); - goto error_disable_reg; - } state->vref_mv = ret / 1000; spi_set_drvdata(spi, indio_dev); @@ -167,25 +153,17 @@ static int mcp4922_probe(struct spi_device *spi) if (ret) { dev_err(&spi->dev, "Failed to register iio device: %d\n", ret); - goto error_disable_reg; + return ret; } return 0; - -error_disable_reg: - regulator_disable(state->vref_reg); - - return ret; } static void mcp4922_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct mcp4922_state *state; iio_device_unregister(indio_dev); - state = iio_priv(indio_dev); - regulator_disable(state->vref_reg); } static const struct spi_device_id mcp4922_id[] = { From patchwork Fri Jul 12 16:03:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731934 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 A601217623A for ; Fri, 12 Jul 2024 16:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800249; cv=none; b=sCk1GOr6B3fHn4i6Ecr0gO7DX3QEdcA+4BZMxUZvJPy/cnVJe7ePoWe48YqhMEku8FoD0hrofPh6maJ3iY3nGdINchT/ti/SUd8s9fhXUdXXA2ahwwPNs1wtpUlGest7EMfx3+nFfLBcAPWZoC9/Sf74kPMffX0TcitBYXgtYMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800249; c=relaxed/simple; bh=jcbI0ILmzg2rz8ajY9fDpFx5bxGc9dBImltD76qGtXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I506oqGvfnF2AReoVklFUegUgvUgSANul3viLLcJL23cGb8R8KPz7L+Zy0jxCEQxl7HdqXJCf69AMTczQOFxDOczyKM5t5AS0xFnu/Or4s9Ap+Hn4i+2USehxAAmWTtLVddS6+JN5d0rLsuYhzZoSjP56M4Sp+iiWGb46t3SX6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=XADlh/Ml; arc=none smtp.client-ip=209.85.210.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="XADlh/Ml" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-704466b19c4so1110615a34.0 for ; Fri, 12 Jul 2024 09:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800247; x=1721405047; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=60eUVwKVeZ7BrLO6pxv9nbYIZ9oGCgCB8H4hO/TeI/g=; b=XADlh/MlstSnuIy9Po0NBK6gB/5MwLA2JBwujo5/dxAw6HK0PCWcxbpCuQbYr9lAi5 0H33dyyCBQ2Sh4TlCY5zASlVDiQSwtO0/Z63h5e0evVqQMXRuk0voySi52RFC6M/fjv4 Yl+tMyWXs36VMO3BlJRCfGiyIcbVRC99BQieuhqLE49y7jzQ20VtPMVN9cUigcnV9/6F 2mgqm9Mz7ZY3BtRzObZa2u+5Sjj47f/PzIk2vz4CQ9TLsJvJRoB9LiPgYGNCcKbd8s3U iuS9s/N/hZtvLJVMexCHFs2cSu48EcWtl3u6ximw+xehO740PWhBn6RK5lnhZ8FoOwLe iufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800247; x=1721405047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=60eUVwKVeZ7BrLO6pxv9nbYIZ9oGCgCB8H4hO/TeI/g=; b=bVeJqOMZ0WNaOoySqsMs6fRrldlCeMHvOiiY2ClDc0kpPDyV7rwKHdXb/2j6/xxvAG j7df965typfitT+K8BD9Rn5ucNMtc98QxO6ilaQBTV/2u8YLjVIzgRvXpcvjfv+xWjn5 Z6PklekUYCPzMD+ISPxB6bWEApjnWNCgM9+fJW32xgEvO6wheJwv1hJ7lEwDqwX2+dzf HytZH/X6lOAdzAZ34uXer1wDS3LMkTFGeRvpkt5MuuG4Zz2Os3np2JpSER4nDBskc2Vp FKNrTbtPJSaDzR20hYZ8XMKQcCIh/WLt7qPEiVkOr/Fb7MHWZS4eUtgtJP8DtZpR/upw xWrA== X-Forwarded-Encrypted: i=1; AJvYcCXRL6YS1ACE45pLlSl1yoSUKmuwXsw2YUulXDbC5BhnogYm201yK1nYEJ6QA3cyn81QG9Oz/eeC6I+NQGt9wCgfC30As5VbqfFs X-Gm-Message-State: AOJu0Yw6pHzTvmA9cMHyMFJEJBd8WPqcOcqmK9BBjamVaSTmu3HIM1pq HvFR6Jghmcm9n9dNDxAI18xjHilS9isSmzvT8qzzTj026l8SbAuUeWuzEgE+gJ8= X-Google-Smtp-Source: AGHT+IEuQNhkpjMbmrtQ5ogRBVhUZBpJ4I4zgpDiKAPbDUpxqOcQNOVerUGUqq5HZO5btAfIiNVRjw== X-Received: by 2002:a9d:6a56:0:b0:704:45bb:267f with SMTP id 46e09a7af769-70445bb3223mr13140566a34.5.1720800246613; Fri, 12 Jul 2024 09:04:06 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:06 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] iio: dac: mcp4922: drop remove() callback Date: Fri, 12 Jul 2024 11:03:55 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-4-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 By using devm_iio_device_register(), we can drop the remove() callback in the mcp4922 driver. We can also remove spi_set_drvdata() since there are no more callers of spi_get_drvdata(). Also use dev_err_probe() while we are at it. Signed-off-by: David Lechner --- drivers/iio/dac/mcp4922.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/iio/dac/mcp4922.c b/drivers/iio/dac/mcp4922.c index f89af70fa5af..26aa99059813 100644 --- a/drivers/iio/dac/mcp4922.c +++ b/drivers/iio/dac/mcp4922.c @@ -138,7 +138,6 @@ static int mcp4922_probe(struct spi_device *spi) state->vref_mv = ret / 1000; - spi_set_drvdata(spi, indio_dev); id = spi_get_device_id(spi); indio_dev->info = &mcp4922_info; indio_dev->modes = INDIO_DIRECT_MODE; @@ -149,22 +148,13 @@ static int mcp4922_probe(struct spi_device *spi) indio_dev->num_channels = MCP4922_NUM_CHANNELS; indio_dev->name = id->name; - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(&spi->dev, "Failed to register iio device: %d\n", - ret); - return ret; - } + ret = devm_iio_device_register(&spi->dev, indio_dev); + if (ret) + return dev_err_probe(&spi->dev, ret, "Failed to register iio device\n"); return 0; } -static void mcp4922_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); -} static const struct spi_device_id mcp4922_id[] = { {"mcp4902", ID_MCP4902}, @@ -180,7 +170,6 @@ static struct spi_driver mcp4922_driver = { .name = "mcp4922", }, .probe = mcp4922_probe, - .remove = mcp4922_remove, .id_table = mcp4922_id, }; module_spi_driver(mcp4922_driver); From patchwork Fri Jul 12 16:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731935 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 7C079176256 for ; Fri, 12 Jul 2024 16:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800250; cv=none; b=McPFLhqFTbEGnrDirZB4JOE3fMeV+Ix45kBP0Xq3dLdOiWiO5RhkcZdoOidR37H+TwECeogC6oLZyunZQ+eZL4lhThpU9rR6g7wtFGMAMZmJcd6/BS9AWDTex+Tk1qJFX+nKCjk2lM9y3UNtW/z89PbQcfP8zdfiqwvHr/dXs4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800250; c=relaxed/simple; bh=mIcfdse/+rlP58eFFA/PEI/fcZHOFfe3jGuPELWLLNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uRu8HNTh1NMkm3Pm+eXn5v/DL0Vxi27a3wwky69vDJYY45fpJqE+UAYb6R/6vNzWZRKRmhz1/htp/PGVTFQmEyrcKA3KpdOmhiavtKyJDDzaMMFpwUOnKpi7HY9pHJxp3AQ114RnGFPdR0spee9LHuWnBYmbEFZM+Out2V6VfDc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=WHNli7Et; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="WHNli7Et" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7044c085338so1190748a34.2 for ; Fri, 12 Jul 2024 09:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800248; x=1721405048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z+LRn09+VizRf0JvYt3kqJDUqFvXhYNVL1CgwtRvMbM=; b=WHNli7Et3K9tDbM9vidxaU1Scfyo/sTxka4kgSuR4WWMUIA+/KsbS77Xd5sbgbjkqj lJPQEvoElvoRnpn83n9+ZVos8wrxy5MSFLZJIGeu+FX7CU15oKrdXiE8qIwAu4CYcyXn rPDdXLj2ZpTa8SVaXS0bBnkD0Z4qVIT9XoFuKPnk/PU0lfWwqao3R7Qvyce8tWVwfkyd pa206ND/nqNphVMfR3zUJAZQxbUjPV8nvbFH3sEtxt9RmrgB3tyCL+iUefBGG7Spz/Z5 8gEszvbEhjNMcgmtompTmYwWntpawOiel4FQc0wmGiVfa+jDSGxGEPZpZRTaD6thrsDz DtMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800248; x=1721405048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z+LRn09+VizRf0JvYt3kqJDUqFvXhYNVL1CgwtRvMbM=; b=WbiyAGvLIEsHoG0VXbG9xEeBTbGuEZy2e7Jq0nDtL8EeDwVdvQX+YkmR1NDXQcseGu TAwmNoQ7Ajbm/M83HJGdAMx2kmVS4oiMSq7S3w+mOVluOkN3uH9F/bLD2cL8o1PKaxiQ 0lgWPHGhi4YJ7rKu3d2MiBAxiVIhAp1X+9QJmFvPX9yYls/o4PXQwSz528VfTUJhwTmB kCmEaEsZ6fRWU1tlwNj0JMvDATyzIODq89IaxRNXyAs4ZFfz+Uc2vjscGlIIHu3EDQmq DNQV1ruUzK0ctDKXwxuFUvXIvJIqWQWdxxUgu45ASy7ZDTCL7jKcjJhgtzOm/6DDZZgx L0+Q== X-Forwarded-Encrypted: i=1; AJvYcCX2JhU9uLxejTGxSaQx8NVNJwMFyshFwzHUkCydsB8vNiNiRAEvnkydbGe3f76M4eQzGcBjYm2nHfZ+IQT7X+Aj24XgDtg61BVE X-Gm-Message-State: AOJu0Yzd3uWmNo9z7aP0tNVV/MMdkP2Y7wu/K7h0vHCDafmD6vSHrlVe 03OBuzhkKsBJ5kNMaISVu6P2fLKf8EmL86BkoMG8i/Aackh5lj49vhWChdbo2v8= X-Google-Smtp-Source: AGHT+IFJqQ4jVYwcPc+YyB6lTtaO4ZRCyIF+arWnpBOToBO1d5MfWdt5nWxhs6AalNLw9FExThA36Q== X-Received: by 2002:a05:6870:c110:b0:25e:1f67:b3bb with SMTP id 586e51a60fabf-25eae784d0cmr10096191fac.10.1720800247429; Fri, 12 Jul 2024 09:04:07 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:07 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] iio: adc: mcp3564: use devm_regulator_get_enable_read_voltage() Date: Fri, 12 Jul 2024 11:03:56 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-5-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 This makes use of the new devm_regulator_get_enable_read_voltage() helper function to reduce boilerplate code in the MCP3564 ADC driver. The error message is slightly changed since there are fewer error return paths. Setting adc->vref_mv is consolidated into a single place to make the logic easier to follow. A use_auto_zeroing_ref_attr local variable is added to make it more obvious what the difference between the two iio info structures is. The return value of the "Unknown Vref" dev_err_probe() is hard-coded to -ENODEV instead of ret since it was getting a bit far from where ret was set and logically that is the only value it could have. Signed-off-by: David Lechner --- drivers/iio/adc/mcp3564.c | 54 ++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c index d83bed0e63d2..34903b7b3cc4 100644 --- a/drivers/iio/adc/mcp3564.c +++ b/drivers/iio/adc/mcp3564.c @@ -349,8 +349,6 @@ struct mcp3564_chip_info { * struct mcp3564_state - working data for a ADC device * @chip_info: chip specific data * @spi: SPI device structure - * @vref: the regulator device used as a voltage reference in case - * external voltage reference is used * @vref_mv: voltage reference value in miliVolts * @lock: synchronize access to driver's state members * @dev_addr: hardware device address @@ -369,7 +367,6 @@ struct mcp3564_chip_info { struct mcp3564_state { const struct mcp3564_chip_info *chip_info; struct spi_device *spi; - struct regulator *vref; unsigned short vref_mv; struct mutex lock; /* Synchronize access to driver's state members */ u8 dev_addr; @@ -1085,11 +1082,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) return 0; } -static void mcp3564_disable_reg(void *reg) -{ - regulator_disable(reg); -} - static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc) { unsigned int pow = adc->chip_info->resolution - 1; @@ -1110,7 +1102,7 @@ static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc) } } -static int mcp3564_config(struct iio_dev *indio_dev) +static int mcp3564_config(struct iio_dev *indio_dev, bool *use_auto_zeroing_ref_attr) { struct mcp3564_state *adc = iio_priv(indio_dev); struct device *dev = &adc->spi->dev; @@ -1119,6 +1111,7 @@ static int mcp3564_config(struct iio_dev *indio_dev) enum mcp3564_ids ids; int ret = 0; unsigned int tmp = 0x01; + bool internal_vref; bool err = false; /* @@ -1218,36 +1211,22 @@ static int mcp3564_config(struct iio_dev *indio_dev) dev_dbg(dev, "Found %s chip\n", adc->chip_info->name); - adc->vref = devm_regulator_get_optional(dev, "vref"); - if (IS_ERR(adc->vref)) { - if (PTR_ERR(adc->vref) != -ENODEV) - return dev_err_probe(dev, PTR_ERR(adc->vref), - "failed to get regulator\n"); + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(dev, ret, "Failed to get vref voltage\n"); + + internal_vref = ret == -ENODEV; + adc->vref_mv = internal_vref ? MCP3564R_INT_VREF_MV : ret / MILLI; + *use_auto_zeroing_ref_attr = internal_vref; + if (internal_vref) { /* Check if chip has internal vref */ if (!adc->have_vref) - return dev_err_probe(dev, PTR_ERR(adc->vref), - "Unknown Vref\n"); - adc->vref = NULL; + return dev_err_probe(dev, -ENODEV, "Unknown Vref\n"); + dev_dbg(dev, "%s: Using internal Vref\n", __func__); } else { - ret = regulator_enable(adc->vref); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, mcp3564_disable_reg, - adc->vref); - if (ret) - return ret; - dev_dbg(dev, "%s: Using External Vref\n", __func__); - - ret = regulator_get_voltage(adc->vref); - if (ret < 0) - return dev_err_probe(dev, ret, - "Failed to read vref regulator\n"); - - adc->vref_mv = ret / MILLI; } ret = mcp3564_parse_fw_children(indio_dev); @@ -1350,10 +1329,8 @@ static int mcp3564_config(struct iio_dev *indio_dev) tmp_reg |= FIELD_PREP(MCP3564_CONFIG0_CLK_SEL_MASK, MCP3564_CONFIG0_USE_INT_CLK); tmp_reg |= MCP3456_CONFIG0_BIT6_DEFAULT; - if (!adc->vref) { + if (internal_vref) tmp_reg |= FIELD_PREP(MCP3456_CONFIG0_VREF_MASK, 1); - adc->vref_mv = MCP3564R_INT_VREF_MV; - } ret = mcp3564_write_8bits(adc, MCP3564_CONFIG0_REG, tmp_reg); @@ -1412,6 +1389,7 @@ static int mcp3564_probe(struct spi_device *spi) int ret; struct iio_dev *indio_dev; struct mcp3564_state *adc; + bool use_auto_zeroing_ref_attr; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); if (!indio_dev) @@ -1428,7 +1406,7 @@ static int mcp3564_probe(struct spi_device *spi) * enable/disable certain channels * change the sampling rate to the requested value */ - ret = mcp3564_config(indio_dev); + ret = mcp3564_config(indio_dev, &use_auto_zeroing_ref_attr); if (ret) return dev_err_probe(&spi->dev, ret, "Can't configure MCP356X device\n"); @@ -1440,7 +1418,7 @@ static int mcp3564_probe(struct spi_device *spi) indio_dev->name = adc->chip_info->name; indio_dev->modes = INDIO_DIRECT_MODE; - if (!adc->vref) + if (use_auto_zeroing_ref_attr) indio_dev->info = &mcp3564r_info; else indio_dev->info = &mcp3564_info; From patchwork Fri Jul 12 16:03:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13731936 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 38170176AB5 for ; Fri, 12 Jul 2024 16:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800250; cv=none; b=YWfRyCzBEAJ2iBxkiScsOuUwJSMHe+grB5XFD81wwj1Piyj9biEJmWm+0+sc0AcEPudbziAbJFUuLXfYCM8xIe1XkVKd66Yt/g1y+vLnbM4uyEM695Y1/SWU/LhxWUS/CXAro9/Z8Il5kefxIN1RBsFGUuuU4c2quwGfXdOMM08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720800250; c=relaxed/simple; bh=NF0ttJPPJHx2bQ6REVEW0ZebK541cG8BKuKiRadWNyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q8T+iImMIzcfh7Ary4kbJoczB7I2qXNWeRUiMQDDJqfDgqR97Z8JEh4kreZjP8pgbycy02RzOse1BZWdw/6/L0kMHryGUqyoT01Hvp1LwK0LTdVw+7daz1A+IuYHFCjxcwXpOCD4BLbPurF99X/UrU8GAdSkY2VELc75XyXzbf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=LR+SA9hH; arc=none smtp.client-ip=209.85.160.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="LR+SA9hH" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-25e150603a6so1076887fac.3 for ; Fri, 12 Jul 2024 09:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1720800248; x=1721405048; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6TvJj9OS9pLYtOuscI8ghIcPdBvxWYcRECb9BgIFeXA=; b=LR+SA9hHdA7x/xxy9MhsYIXz5RKJ57gGHaBGlhMWcExbf5o2l4eId0ZowoQDVnA/zJ ZtWvAffuQIRCSrPB5zgea8oi9ywOO0HNq5Y7TsD4wlqYVneMafVQjAhav2kknAy2xbld 2XgsrlFHNeUAgfByF2z5YoCkhyRGsE4fsH1pGMUkI+nRG5vlhXFYb/H6vI+eWMLyMSaP E15l4jmU9+lUgEik+GSmzDEed80R7DvUiNNFjv3E01DVLEsswIcudASc9OmZRWOoCheh bGhcdU/q0jXPwwG0rt8pk17XSgqZ9VvVLgRFUMoUMnykRnWh3X8SfJA7igKJf/6NGF5u 7eAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720800248; x=1721405048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6TvJj9OS9pLYtOuscI8ghIcPdBvxWYcRECb9BgIFeXA=; b=GgfPDBSF2r3u9u+U4GvmEBiIgIywzULbPrWkMLEeN7eTAidPBVBdek7/e6mnrdZEcs FNC+P3VdqXBTOGfHIO+TXSRwxv2msxwPvMWQUTHOM/jkYzEOGjIcoLmAyrklwYwjT+NB WjRPT0QtFStcwozw/aXwhaCcdLe4UlP/HUrKKHUKiXzSuro+CGmcLVUUvPeheT4demEj 3uKTBe6fND2MFoJMgc2TjszEAdmUJKsz1cZfmDPI9hzI2MWUYh63DyEcd0XhsmIPdKS4 c4j9/Z5F3jsS029b6YI0MQVPVk3tm8BP8FzzU2fBPdAOgiEyHRZ3yy95lpGJR14iP1cR OGNg== X-Forwarded-Encrypted: i=1; AJvYcCVj5t5aERwJUb3VypgGnKTVMM0ixJxfGa9a5yMA4JAjeZCoYqcrazcSjT0pRBWuEpKzJi2xaCp0XEBK+qTmSQ+8HW6Y4jSBfCzd X-Gm-Message-State: AOJu0YwKFj1zHQBZ4eP9ZlVkkVLKf0pP305i0Y+0OtiNFYJnOu/uajNS QG5wGseEHvR2MU8q38seH5TwLz1pgNJct49PmT9jv33uZn9v792aHHO667965cM= X-Google-Smtp-Source: AGHT+IGr7GtUz90d3Lh/5u99HidVD4eSXHr2INczAl7WDJoabqqvA5RKlDdYHdNqgwfxm7B6k4j9qg== X-Received: by 2002:a05:6870:6387:b0:25e:4365:c5d6 with SMTP id 586e51a60fabf-25eae7b880emr9984254fac.20.1720800248273; Fri, 12 Jul 2024 09:04:08 -0700 (PDT) Received: from localhost.localdomain (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-70374f78d35sm1615131a34.23.2024.07.12.09.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:04:07 -0700 (PDT) From: David Lechner To: Jonathan Cameron , Marius Cristea , Marcus Folkesson , Kent Gustavsson Cc: David Lechner , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] iio: adc: mcp3911: use devm_regulator_get_enable_read_voltage() Date: Fri, 12 Jul 2024 11:03:57 -0500 Message-ID: <20240712-iio-regulator-refactor-round-3-v1-6-835017bae43d@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> References: <20240712-iio-regulator-refactor-round-3-v1-0-835017bae43d@baylibre.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.14.0 This makes use of the new devm_regulator_get_enable_read_voltage() helper function to reduce boilerplate code in the MCP3911 ADC driver. The error message is slightly changed since there are fewer error return paths. An extra parameter is added to the config callback to avoid adding state that is not used outside of the probe() function. Signed-off-by: David Lechner Reviewed-by: Marcus Folkesson --- drivers/iio/adc/mcp3911.c | 59 +++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c index 7a32e7a1be9d..5076028f541d 100644 --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -103,7 +103,7 @@ struct mcp3911_chip_info { const struct iio_chan_spec *channels; unsigned int num_channels; - int (*config)(struct mcp3911 *adc); + int (*config)(struct mcp3911 *adc, bool external_vref); int (*get_osr)(struct mcp3911 *adc, u32 *val); int (*set_osr)(struct mcp3911 *adc, u32 val); int (*enable_offset)(struct mcp3911 *adc, bool enable); @@ -115,7 +115,6 @@ struct mcp3911_chip_info { struct mcp3911 { struct spi_device *spi; struct mutex lock; - struct regulator *vref; struct clk *clki; u32 dev_addr; struct iio_trigger *trig; @@ -385,23 +384,11 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, } } -static int mcp3911_calc_scale_table(struct mcp3911 *adc) +static int mcp3911_calc_scale_table(u32 vref_mv) { - struct device *dev = &adc->spi->dev; - u32 ref = MCP3911_INT_VREF_MV; u32 div; - int ret; u64 tmp; - if (adc->vref) { - ret = regulator_get_voltage(adc->vref); - if (ret < 0) { - return dev_err_probe(dev, ret, "failed to get vref voltage\n"); - } - - ref = ret / 1000; - } - /* * For 24-bit Conversion * Raw = ((Voltage)/(Vref) * 2^23 * Gain * 1.5 @@ -412,7 +399,7 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc) */ for (int i = 0; i < MCP3911_NUM_SCALES; i++) { div = 12582912 * BIT(i); - tmp = div_s64((s64)ref * 1000000000LL, div); + tmp = div_s64((s64)vref_mv * 1000000000LL, div); mcp3911_scale_table[i][0] = 0; mcp3911_scale_table[i][1] = tmp; @@ -544,7 +531,7 @@ static const struct iio_info mcp3911_info = { .write_raw_get_fmt = mcp3911_write_raw_get_fmt, }; -static int mcp3911_config(struct mcp3911 *adc) +static int mcp3911_config(struct mcp3911 *adc, bool external_vref) { struct device *dev = &adc->spi->dev; u32 regval; @@ -555,7 +542,7 @@ static int mcp3911_config(struct mcp3911 *adc) return ret; regval &= ~MCP3911_CONFIG_VREFEXT; - if (adc->vref) { + if (external_vref) { dev_dbg(dev, "use external voltage reference\n"); regval |= FIELD_PREP(MCP3911_CONFIG_VREFEXT, 1); } else { @@ -610,7 +597,7 @@ static int mcp3911_config(struct mcp3911 *adc) return mcp3911_write(adc, MCP3911_REG_GAIN, regval, 1); } -static int mcp3910_config(struct mcp3911 *adc) +static int mcp3910_config(struct mcp3911 *adc, bool external_vref) { struct device *dev = &adc->spi->dev; u32 regval; @@ -621,7 +608,7 @@ static int mcp3910_config(struct mcp3911 *adc) return ret; regval &= ~MCP3910_CONFIG1_VREFEXT; - if (adc->vref) { + if (external_vref) { dev_dbg(dev, "use external voltage reference\n"); regval |= FIELD_PREP(MCP3910_CONFIG1_VREFEXT, 1); } else { @@ -677,11 +664,6 @@ static int mcp3910_config(struct mcp3911 *adc) return adc->chip->enable_offset(adc, 0); } -static void mcp3911_cleanup_regulator(void *vref) -{ - regulator_disable(vref); -} - static int mcp3911_set_trigger_state(struct iio_trigger *trig, bool enable) { struct mcp3911 *adc = iio_trigger_get_drvdata(trig); @@ -704,6 +686,8 @@ static int mcp3911_probe(struct spi_device *spi) struct device *dev = &spi->dev; struct iio_dev *indio_dev; struct mcp3911 *adc; + bool external_vref; + u32 vref_mv; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); @@ -714,23 +698,12 @@ static int mcp3911_probe(struct spi_device *spi) adc->spi = spi; adc->chip = spi_get_device_match_data(spi); - adc->vref = devm_regulator_get_optional(dev, "vref"); - if (IS_ERR(adc->vref)) { - if (PTR_ERR(adc->vref) == -ENODEV) { - adc->vref = NULL; - } else { - return dev_err_probe(dev, PTR_ERR(adc->vref), "failed to get regulator\n"); - } + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(dev, ret, "failed to get vref voltage\n"); - } else { - ret = regulator_enable(adc->vref); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, mcp3911_cleanup_regulator, adc->vref); - if (ret) - return ret; - } + external_vref = ret != -ENODEV; + vref_mv = external_vref ? ret / 1000 : MCP3911_INT_VREF_MV; adc->clki = devm_clk_get_enabled(dev, NULL); if (IS_ERR(adc->clki)) { @@ -755,11 +728,11 @@ static int mcp3911_probe(struct spi_device *spi) } dev_dbg(dev, "use device address %i\n", adc->dev_addr); - ret = adc->chip->config(adc); + ret = adc->chip->config(adc, external_vref); if (ret) return ret; - ret = mcp3911_calc_scale_table(adc); + ret = mcp3911_calc_scale_table(vref_mv); if (ret) return ret;