From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 B86D31FAC51 for ; Wed, 23 Oct 2024 23:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727682; cv=none; b=kxh+OZL52Up4oDI+rBMrMdGY9KOCAl8EbKhquxhufi5b1ydcY1rwi8r+GtQbtHlzeprxZsX6E8SbBYfO8YuyYwjg3zbnzZKGiQCZ9k6USox9Myb7ql3mBRVbF3eeOXZ2kEVsj9k/6UePfvo1C++wJVrmzZD2f7nf5OFomV0ERJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727682; c=relaxed/simple; bh=+qQPhpRBI2xebpxF2IUsDgxiRfAaR2OlImrgtgTUDY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TG5vNWKS7XIJfgmgV653oCYEsfs+AEzAW7fHd9uXg5v6wSIn2hKPDN59IpnOWzjuSrifvBYmz5o45kNFqXk6AmhKieOazzoVCwo0FFJ9Ip+l/upbt5L4UQLn2xzS+u1g2hptJak97BTcEU5dxB8D5TJruWNwPcJKqy0cNrzhOXg= 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=XeADY2iq; arc=none smtp.client-ip=209.85.161.46 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="XeADY2iq" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5e5568f1b6eso158867eaf.1 for ; Wed, 23 Oct 2024 16:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727680; x=1730332480; 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=h499UsT6sj6xlYcZ1JadzuP0YnfDcZeLc9oTI16DnbI=; b=XeADY2iqLRL+REpr+OZSm17VgKoloGRHGFJ4+eqC3YT6BwSr7r9aZIULa0t9czILw4 /HuwkkDFkdVKduOjlmzFLW3Gi4UC3vgs4o+FV47Ej3zEAQ9lZE7SGCSAdbcEJ0uYoUF6 cS40p9bFP/cYaSpQ72DmuGz3Pb9Unddm9iV4OwFXH8+2d2uCY7Omz8ikv+9U2AeqnZSM tbYE9Ry8mw0S1tNXg2tifXwzN6HgC7xMEm8K0/zzecIt+LszllIRiGuApSi/jQXoj7GZ jMcXxxXnNJ9+VcmH/zIXoQ0FVsTwe+PGvqWjANqwKAcOVKe6esMaeNAOxw0+yPfhaHxB NSwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727680; x=1730332480; 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=h499UsT6sj6xlYcZ1JadzuP0YnfDcZeLc9oTI16DnbI=; b=QEIkg4/aKw4Kw5EWyzT3LuJSBhdy0ruQZkaD9MiMEDBu5Z5FWd+4mJ8p3DKBAcaR1v 72tm8aJ1RHjQgOAzK9IhWmlcZ9R12LUFy5rNMkS89f4N0hKlK/tbbPrOymxco0lSs9pa wZA1Hl+5Ng2BmM+FHodITII1QJ0gCDnbiTcFv2DkiVAlzMyjI2sgaAQyBURmR2GVoa/n Zx2jFPJY6WpfnE46Ivw5OyZ2t9w8ReDZ92aj4ZedTC8QqD0GhfGzYz1vGF8B5e1GfoHg S42DJXHXslJsIXWZEe2INbbe7Oa63+7PdsBjvPl6rA8P7Viy8/Wg4GCHTXfI3GAL28W0 wB+w== X-Forwarded-Encrypted: i=1; AJvYcCXyqz2ZdPVvFqBT9iwHsf8zOlJSNnywYc6yMNX5VM3r5u6C5vnHAA3ilcYU2HNOJymrNP/Y0y+6zRjY59s=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9pRnmKHHgqkbQZ6wCzF2GpvraIKM1uzgoYWHGWeODmppIK6+X YRH1SHGq+UigfhHTypw/DRVzD7rVxud/NfSS7rOT6T5OJ+VWpSQh+t20hLS7BVo= X-Google-Smtp-Source: AGHT+IG0LoE+A40aIKnVIo1drlkt/dwuoqY7uHdyZBDpLRMrmduBDPpg6jxRGWmIdxyPu5IIHKkMeA== X-Received: by 2002:a4a:ee95:0:b0:5eb:db1c:a860 with SMTP id 006d021491bc7-5ec057e1c3cmr123250eaf.8.1729727679948; Wed, 23 Oct 2024 16:54:39 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:38 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:05 -0500 Subject: [PATCH 01/11] iio: dac: ad5380: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-1-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5380.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c index 2e3e33f92bc0..7d1d7053c29e 100644 --- a/drivers/iio/dac/ad5380.c +++ b/drivers/iio/dac/ad5380.c @@ -47,7 +47,6 @@ struct ad5380_chip_info { * struct ad5380_state - driver instance specific data * @regmap: regmap instance used by the device * @chip_info: chip model specific constants, available modes etc - * @vref_reg: vref supply regulator * @vref: actual reference voltage used in uA * @pwr_down: whether the chip is currently in power down mode * @lock: lock to protect the data buffer during regmap ops @@ -55,7 +54,6 @@ struct ad5380_chip_info { struct ad5380_state { struct regmap *regmap; const struct ad5380_chip_info *chip_info; - struct regulator *vref_reg; int vref; bool pwr_down; struct mutex lock; @@ -400,42 +398,32 @@ static int ad5380_probe(struct device *dev, struct re= gmap *regmap, if (st->chip_info->int_vref =3D=3D 2500) ctrl |=3D AD5380_CTRL_INT_VREF_2V5; =20 - st->vref_reg =3D devm_regulator_get(dev, "vref"); - if (!IS_ERR(st->vref_reg)) { - ret =3D regulator_enable(st->vref_reg); - if (ret) { - dev_err(dev, "Failed to enable vref regulators: %d\n", - ret); - goto error_free_reg; - } - - ret =3D regulator_get_voltage(st->vref_reg); - if (ret < 0) - goto error_disable_reg; - - st->vref =3D ret / 1000; - } else { + ret =3D devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret < 0 && ret !=3D -ENODEV) { + dev_err(dev, "Failed to get vref voltage: %d\n", ret); + goto error_free_reg; + } + if (ret =3D=3D -ENODEV) { st->vref =3D st->chip_info->int_vref; ctrl |=3D AD5380_CTRL_INT_VREF_EN; + } else { + st->vref =3D ret / 1000; } =20 ret =3D regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl); if (ret) { dev_err(dev, "Failed to write to device: %d\n", ret); - goto error_disable_reg; + goto error_free_reg; } =20 ret =3D iio_device_register(indio_dev); if (ret) { dev_err(dev, "Failed to register iio device: %d\n", ret); - goto error_disable_reg; + goto error_free_reg; } =20 return 0; =20 -error_disable_reg: - if (!IS_ERR(st->vref_reg)) - regulator_disable(st->vref_reg); error_free_reg: kfree(indio_dev->channels); =20 @@ -445,14 +433,10 @@ static int ad5380_probe(struct device *dev, struct re= gmap *regmap, static void ad5380_remove(struct device *dev) { struct iio_dev *indio_dev =3D dev_get_drvdata(dev); - struct ad5380_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); =20 kfree(indio_dev->channels); - - if (!IS_ERR(st->vref_reg)) - regulator_disable(st->vref_reg); } =20 static bool ad5380_reg_false(struct device *dev, unsigned int reg) --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 8B2B9200133 for ; Wed, 23 Oct 2024 23:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727685; cv=none; b=Kr2/5xXo/7/SJVKV5wQEXvFX25m/SwbV2FN3BLsV6PeOU6JJfQKhx7p07s5DB6k6pSRlJKsE/wgToRTgCUEbvY3Jhvj4L4ORFS8cOB/+K2QFKX/JXjEPXmmFA8gNNBikd8dY0/QRKv7Sv4oLh8pRm0f969I/w8qcCVCErP5ZaOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727685; c=relaxed/simple; bh=JtWsVW1/ip3tWEUoknaHJGDygDmPAYBD4bgqX9vG02Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tS/mQj+WBaKNzPZ87OF/mqzuHEGFFxC9GdsKdCIbp9EOC5j1zgzlZFlpPagZ0xCQkvHxpI7SrCSorb9OQWr7O4lnZobh77f7vXHo4JIxOITYy3RwsMhvH6PqrHDOf8e+NA7YBwSicX4WAQISAiJNKGCaNrzjV0CiQxJBLL/3Sv0= 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=CpzOMGl8; arc=none smtp.client-ip=209.85.210.50 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="CpzOMGl8" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-71809fe188cso219751a34.0 for ; Wed, 23 Oct 2024 16:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727683; x=1730332483; 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=11WZ5IF5KUkagJDeN3d2nVfidgojedjqvRS83nA7Gyo=; b=CpzOMGl8oBhdlSnTxb8e2+tfug+urxNZPDsTvSDP8Y2BTc1xDMVaI+AQ2TCltswb64 5U3+2GQyI5o0BJqKuUszaFRufSGXcXue///V82qptpuaxK0vOfspCO7BMf5sdDE1zHVS 8p+Se0p3AUJB4F76TbCWiXWrG0nG2akIHKawydlHBG1Qid4BU5CL49TFmWIR5WSPwuc/ 5nKWHCFoBf130W5ZIGW0TmnTIudb/TuPOY1HKcO+wudLGR6QxIKONxQU9PLv+z9USUOH 6apP0YseakEuVfhkANHEQKrVgCjCBMru/+sv290cGBhPj63ZgBjesRTtbYVrbJXa1Fxn tIYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727683; x=1730332483; 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=11WZ5IF5KUkagJDeN3d2nVfidgojedjqvRS83nA7Gyo=; b=jKT2XbOI5/rbo8DNPxSfkj/Ppzv1l40N6dST8mHOGQnqQF+gXtLhR737o8gfl4MxkW 3UQNcLDxsXVrK15VoK1DEkjv24n51ihquiFStyhSwN7S6+dbgNYSixSSv6pUr5BeKBDr 23cTy4L5Iy9285hSLsJzU2y0otC7V7KqJlt9pY896q6VqtVCk3SVQL+OIgK62C1IFUFC XhC1FxzJAxQgIahjvnNCLcTwuH/9dODVFUSjV/MsWmzi8M5AJBj9GQZ+rX8O3yCEpx0/ /sQM6WjiaMs3YEjCFd5TMW+G4ugARwE7CUT6sqv8/UcffOEpEiFYuVN/hsw3EChLIzwR sllw== X-Forwarded-Encrypted: i=1; AJvYcCWInXFXzUZ5QQ/7IwjuX7WA3EkZvOG2DODhXhPO1uDd8KaMjPGPUk8Ha8VmJ0A2NlqS8gr9bMrywBgrxLw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxjg79G97t/fu8vYEcFgg4YwUrUJAj92m0frZ3PNTmbh1Mu3B1d M/45lhEVHoPNFTZwB2jNmkB9Zw7TcGMHwAzZ+hf8g1gZLMkpJhNxk8QSKUOyhII= X-Google-Smtp-Source: AGHT+IHPtJ7lzyKKMxRzAqXtGDZhRStmKcjf90mmLH4koSMdK6Z/hi1YrpCJ0SuS0YG7xtlRaOdYZw== X-Received: by 2002:a05:6830:314c:b0:715:4e38:a1ab with SMTP id 46e09a7af769-7184b32308bmr4590372a34.22.1729727682667; Wed, 23 Oct 2024 16:54:42 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:41 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:06 -0500 Subject: [PATCH 02/11] iio: dac: ad5380: drop driver remove callbacks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-2-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Drop use of the driver remove callbacks in the ad5380 driver. By making use of a few more devm_ helpers, we can avoid the need for remove callbacks entirely. Also make use of dev_err_probe() while at it. Signed-off-by: David Lechner --- drivers/iio/dac/ad5380.c | 61 +++++++++++---------------------------------= ---- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c index 7d1d7053c29e..392a1c7aee03 100644 --- a/drivers/iio/dac/ad5380.c +++ b/drivers/iio/dac/ad5380.c @@ -339,14 +339,14 @@ static const struct ad5380_chip_info ad5380_chip_info= _tbl[] =3D { }, }; =20 -static int ad5380_alloc_channels(struct iio_dev *indio_dev) +static int ad5380_alloc_channels(struct device *dev, struct iio_dev *indio= _dev) { struct ad5380_state *st =3D iio_priv(indio_dev); struct iio_chan_spec *channels; unsigned int i; =20 - channels =3D kcalloc(st->chip_info->num_channels, - sizeof(struct iio_chan_spec), GFP_KERNEL); + channels =3D devm_kcalloc(dev, st->chip_info->num_channels, + sizeof(struct iio_chan_spec), GFP_KERNEL); =20 if (!channels) return -ENOMEM; @@ -377,7 +377,6 @@ static int ad5380_probe(struct device *dev, struct regm= ap *regmap, } =20 st =3D iio_priv(indio_dev); - dev_set_drvdata(dev, indio_dev); =20 st->chip_info =3D &ad5380_chip_info_tbl[type]; st->regmap =3D regmap; @@ -389,20 +388,16 @@ static int ad5380_probe(struct device *dev, struct re= gmap *regmap, =20 mutex_init(&st->lock); =20 - ret =3D ad5380_alloc_channels(indio_dev); - if (ret) { - dev_err(dev, "Failed to allocate channel spec: %d\n", ret); - return ret; - } + ret =3D ad5380_alloc_channels(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to allocate channel spec\n"); =20 if (st->chip_info->int_vref =3D=3D 2500) ctrl |=3D AD5380_CTRL_INT_VREF_2V5; =20 ret =3D devm_regulator_get_enable_read_voltage(dev, "vref"); - if (ret < 0 && ret !=3D -ENODEV) { - dev_err(dev, "Failed to get vref voltage: %d\n", ret); - goto error_free_reg; - } + if (ret < 0 && ret !=3D -ENODEV) + return dev_err_probe(dev, ret, "Failed to get vref voltage\n"); if (ret =3D=3D -ENODEV) { st->vref =3D st->chip_info->int_vref; ctrl |=3D AD5380_CTRL_INT_VREF_EN; @@ -411,32 +406,14 @@ static int ad5380_probe(struct device *dev, struct re= gmap *regmap, } =20 ret =3D regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl); - if (ret) { - dev_err(dev, "Failed to write to device: %d\n", ret); - goto error_free_reg; - } + if (ret) + return dev_err_probe(dev, ret, "Failed to write to device\n"); =20 - ret =3D iio_device_register(indio_dev); - if (ret) { - dev_err(dev, "Failed to register iio device: %d\n", ret); - goto error_free_reg; - } + ret =3D devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to register iio device\n"); =20 return 0; - -error_free_reg: - kfree(indio_dev->channels); - - return ret; -} - -static void ad5380_remove(struct device *dev) -{ - struct iio_dev *indio_dev =3D dev_get_drvdata(dev); - - iio_device_unregister(indio_dev); - - kfree(indio_dev->channels); } =20 static bool ad5380_reg_false(struct device *dev, unsigned int reg) @@ -470,11 +447,6 @@ static int ad5380_spi_probe(struct spi_device *spi) return ad5380_probe(&spi->dev, regmap, id->driver_data, id->name); } =20 -static void ad5380_spi_remove(struct spi_device *spi) -{ - ad5380_remove(&spi->dev); -} - static const struct spi_device_id ad5380_spi_ids[] =3D { { "ad5380-3", ID_AD5380_3 }, { "ad5380-5", ID_AD5380_5 }, @@ -501,7 +473,6 @@ static struct spi_driver ad5380_spi_driver =3D { .name =3D "ad5380", }, .probe =3D ad5380_spi_probe, - .remove =3D ad5380_spi_remove, .id_table =3D ad5380_spi_ids, }; =20 @@ -543,11 +514,6 @@ static int ad5380_i2c_probe(struct i2c_client *i2c) return ad5380_probe(&i2c->dev, regmap, id->driver_data, id->name); } =20 -static void ad5380_i2c_remove(struct i2c_client *i2c) -{ - ad5380_remove(&i2c->dev); -} - static const struct i2c_device_id ad5380_i2c_ids[] =3D { { "ad5380-3", ID_AD5380_3 }, { "ad5380-5", ID_AD5380_5 }, @@ -574,7 +540,6 @@ static struct i2c_driver ad5380_i2c_driver =3D { .name =3D "ad5380", }, .probe =3D ad5380_i2c_probe, - .remove =3D ad5380_i2c_remove, .id_table =3D ad5380_i2c_ids, }; =20 --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.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 651662003DF for ; Wed, 23 Oct 2024 23:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727689; cv=none; b=jgnG94tMYvIEXs72RbXjiG784IK2baG/nxBY4zPSkP0cuhUiKNAxErpGzwUdnmwqLJsdyNlcNapjO/uOUaYk/JsAJk5vbOE+ag/0YUh0BZEP8IG+iIXCc/A4l+X+I9w8zWbwfql3cktbt5/ewheq1LVigdOG4Yd7O0gNMJIKUgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727689; c=relaxed/simple; bh=BZeNhUpFlkIYdGaRA/ukfyi29Qtnq8SmBSpRm9b6skE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IMdjrcnoNbxve91/v8jLn9RcCw2dM+XALE96eIQbMiYTNYFCet0R7N0gD3HAkFQ+YzRBME6fH9ixFlKa2jWW10yrbeLtZL9KWW6usneYvFlO+iyyx+jhNwAxayEoyw71aXP9Kc+vMwLizIUBB+l4qW/aLnVKtEurP0VdjyoaVMg= 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=OEN7a9NJ; arc=none smtp.client-ip=209.85.161.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="OEN7a9NJ" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5eb5f07410aso155375eaf.0 for ; Wed, 23 Oct 2024 16:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727685; x=1730332485; 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=QIpJs6ysMWquyQzdUXSLhEt4udqL7m21w5SiuwdawWo=; b=OEN7a9NJi/wWWUqM8TdHgN8IFz2fiBenKgnNERE8W6gPb6qFMHP9SsxPBkShkzFcmj G326otOw0qdXHQYq7maBUnUTfn6ty8rlBpTqfwt80Tq4p6p8T+KnsZ1a39Mw48wRT59p 2ucb6bvBHbv8bDG0z6bFexXEdRmAxxc8Q2XOIK/YslNDiFlsHLXFOmIR6Al0X1vPzoBU wg9cQ3KO815ibQXylNjAHYchTg7wc86Z94jy1QjZ2pyyTivXMlZXjJIV4mSbOySaSLRr K+a+P/KS4n2gwFJ6KGeKpiMkRBmJvNCIeXegKzBeM0NR2dAqnZdxvOXpMg6JpL+44Vez i5Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727685; x=1730332485; 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=QIpJs6ysMWquyQzdUXSLhEt4udqL7m21w5SiuwdawWo=; b=ao+N2qliQOSdepGJDcjkxeHZo7BNtOJHfFxH+bQaufOjusw6+0cInGZJVHngOMMhhT f8u4k2U6sUFFYkNJE3/PxwOvIm71Aj5Dw05ldOsRI2hKUrF/mciuk61oLheoOrCJjHf7 8ITPBFZNjCaJ25mwo5lX6VYqOsk3il6sLX6pSVkoByzMAWenfkOW1Fuiqn+aq79tj3Rm 6yjlHm5sjYXNeW5fHkCZd+VEnwdRdEK8EPYwEBrG6U0c+qLps1+oC0IUdpGHUYsmpmR9 x0RUJhxVaOlYufcG5o32MQtJGWI1J5sirsay1i3Xj714jomM7avN4fUEmLrygdN4cfIm MOzQ== X-Forwarded-Encrypted: i=1; AJvYcCUUeRRJg2vu0zzuPdZtSqsorrx3drZ8aeLXzpsAUfIxgv4qM315srn9/21oX6o2O+f16r3+tFdRz1omhS4=@vger.kernel.org X-Gm-Message-State: AOJu0YyVCKv8qX4atE3l3D46BBdZHGhUzCpCChUbMuryIqLgWvZwkjt0 SfTMS8ivbRSXMq4MuypcOPEEIiBRaWyJgnST+UPS5fNQjBErXIp/RkkUI32sq2A= X-Google-Smtp-Source: AGHT+IGo8FI1xaZrv+ilwOQNiRHtt7Ey1e86tF2/rnmxXcdoKSdAIdz9WvjSqMtBq2Hp4kNTnjKXhw== X-Received: by 2002:a05:6820:628:b0:5eb:4f45:d209 with SMTP id 006d021491bc7-5ebee6dd82bmr3108682eaf.3.1729727685558; Wed, 23 Oct 2024 16:54:45 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:44 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:07 -0500 Subject: [PATCH 03/11] iio: dac: ad5446: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-3-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Also simplify =3D=3D NULL check while we are touching that line. Signed-off-by: David Lechner --- drivers/iio/dac/ad5446.c | 57 ++++++++++++++------------------------------= ---- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c index 708629efc157..574de97c1c08 100644 --- a/drivers/iio/dac/ad5446.c +++ b/drivers/iio/dac/ad5446.c @@ -32,7 +32,6 @@ * struct ad5446_state - driver instance specific data * @dev: this device * @chip_info: chip model specific constants, available modes etc - * @reg: supply regulator * @vref_mv: actual reference voltage used * @cached_val: store/retrieve values during power down * @pwr_down_mode: power down mode (1k, 100k or tristate) @@ -43,7 +42,6 @@ struct ad5446_state { struct device *dev; const struct ad5446_chip_info *chip_info; - struct regulator *reg; unsigned short vref_mv; unsigned cached_val; unsigned pwr_down_mode; @@ -226,32 +224,16 @@ static int ad5446_probe(struct device *dev, const cha= r *name, { struct ad5446_state *st; struct iio_dev *indio_dev; - struct regulator *reg; - int ret, voltage_uv =3D 0; - - reg =3D devm_regulator_get(dev, "vcc"); - if (!IS_ERR(reg)) { - ret =3D regulator_enable(reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } + int ret; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); - if (indio_dev =3D=3D NULL) { - ret =3D -ENOMEM; - goto error_disable_reg; - } + if (!indio_dev) + return -ENOMEM; + st =3D iio_priv(indio_dev); st->chip_info =3D chip_info; =20 dev_set_drvdata(dev, indio_dev); - st->reg =3D reg; st->dev =3D dev; =20 indio_dev->name =3D name; @@ -264,33 +246,26 @@ static int ad5446_probe(struct device *dev, const cha= r *name, =20 st->pwr_down_mode =3D MODE_PWRDWN_1k; =20 - if (st->chip_info->int_vref_mv) - st->vref_mv =3D st->chip_info->int_vref_mv; - else if (voltage_uv) - st->vref_mv =3D voltage_uv / 1000; - else - dev_warn(dev, "reference voltage unspecified\n"); - - ret =3D iio_device_register(indio_dev); - if (ret) - goto error_disable_reg; - - return 0; + ret =3D devm_regulator_get_enable_read_voltage(dev, "vcc"); + if (ret < 0 && ret !=3D -ENODEV) + return ret; + if (ret =3D=3D -ENODEV) { + if (chip_info->int_vref_mv) + st->vref_mv =3D chip_info->int_vref_mv; + else + dev_warn(dev, "reference voltage unspecified\n"); + } else { + st->vref_mv =3D ret / 1000; + } =20 -error_disable_reg: - if (!IS_ERR(reg)) - regulator_disable(reg); - return ret; + return iio_device_register(indio_dev); } =20 static void ad5446_remove(struct device *dev) { struct iio_dev *indio_dev =3D dev_get_drvdata(dev); - struct ad5446_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } =20 #if IS_ENABLED(CONFIG_SPI_MASTER) --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 2369C200B81 for ; Wed, 23 Oct 2024 23:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727691; cv=none; b=FbW366vlGTnVd9DzmkW+1SpQCw8WppJzjWNqOSnw7kZSKGNG9vKd8EgYyseSajRJjTCLkabVm1wE+yuYHGCuHzxm5FjgtFJvb79FEN4/sQm3CFD3l/RfLINcWzd4fmg5aXiNt+hdlfKsmKIJWTvsuFTO3rXudd4Cv2EOrB3Y8vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727691; c=relaxed/simple; bh=TBWabhQJAgeF/JmlGMB0s6sWkKQPG+fMnDw+4FWx7pY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Re7zd8gEjR1xrukIvj+xzF5CS6q7/cTxwCeq/wchq5zSiaPwySWxS94Eu0LhtBQS0Y0/7OYUm4IpOfzoSSM83o2JDMda4DJ/Ztatp958hrNmMplfKWbGwDKtLvFZifxQhUecLc7NOWmCZK1uewLCB9ma3n+0NaD8T0bfvbUa+34= 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=GaEJzVMr; arc=none smtp.client-ip=209.85.210.50 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="GaEJzVMr" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-71809fe188cso219766a34.0 for ; Wed, 23 Oct 2024 16:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727688; x=1730332488; 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=CCrJsd8Dvmrlhf0cfRAhRXo/5Sfbm74xKaBgF7hdoZw=; b=GaEJzVMrm6Kax5KY5LXuUVdhO/irVQdaDzWouuzrTY9d8kUUKY0WeA9uMLIFMAuDgH al+DhE0gfvLE9Vqdm3cBMBpGgu5xxe/x/v5nX51HVY+hwWaPmqf0tve/TgRb+/xB+p4A dR35srNUkHLLamGBkhZeN8GRukkaHhfHVSMYV8x9mtavn2MuAjvBoqJL0/NbmQkags3V 7hWpTwHcfm+5UhfBRepYpNgdDx/qEDXZ0sURF0myunAbqeeEL/uIZnto4NvkEcjaUtm0 +1NTnW7JqyRCvd+9FVy1x6AZqGgkwCbugPc/pp9XqiWFZOMqHyq+4OlS9NeFSycdjrS9 VhQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727688; x=1730332488; 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=CCrJsd8Dvmrlhf0cfRAhRXo/5Sfbm74xKaBgF7hdoZw=; b=rlzFU1AJNj7Tzf2Y4V7zdEkS71YSpZrA6ZVhLJckdkdBwDxZh3esZLwIRgr+venAgF sP0eChtu6f0exBIJYNG21pg/MK00fvb+wyvIXTiyOT/6XY6Y75H3H0CR20jvaC3+Bcpt WBttgF+6KgjhbXhPJd1pcnX3I/lF31M7Mft9VreZFYDs1ZJaXx7Dq4BZrExoMEQtu4l6 C6ViKyW4pA25fd1WxAoDR+sKvBNI0lz93/NFaqAJqBOpGrX6Jx8HGWZGQyuS+smphqQ1 14xGwKM8zALy8l5FuQsPe+AE7AzEwrVPVJnsIT/MGGxhbmWWDrjZW1keJiq6vREWwEPn qsSA== X-Forwarded-Encrypted: i=1; AJvYcCX6pTJgSaVeX11miT5Zev0NmRcLmAq3bfP2BkSS7vRdxSVlvDSiiNlLtxIlpLxs9NhHyWTWhbQrKRJLZdw=@vger.kernel.org X-Gm-Message-State: AOJu0YxW/WGQQvKY3XrFQsRcbk9+ohYqJgl4X/kqnxJt/NBieI/iv6pA QEj2Y6qv3MzrAX5XWDN16TI8YyLpHGjmgl+d3e+NNiio1fdMIBapzq32LLw+1vY= X-Google-Smtp-Source: AGHT+IFmqtwSvibuxIx443VqJVODLExHgKIwAqImbQsJ68YjECi5O8IiJMzfNAv7dGv+ATRS9zqOcQ== X-Received: by 2002:a05:6830:348e:b0:70c:9c66:af53 with SMTP id 46e09a7af769-7184b3468d7mr4274863a34.25.1729727688300; Wed, 23 Oct 2024 16:54:48 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:47 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:08 -0500 Subject: [PATCH 04/11] iio: dac: ad5446: drop driver remove callbacks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-4-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Drop use of the driver remove callbacks in the ad5446 driver. By making use of a a devm_ helper, we can avoid the need for the remove callbacks entirely. Signed-off-by: David Lechner --- drivers/iio/dac/ad5446.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c index 574de97c1c08..6ad99f97eed5 100644 --- a/drivers/iio/dac/ad5446.c +++ b/drivers/iio/dac/ad5446.c @@ -233,7 +233,6 @@ static int ad5446_probe(struct device *dev, const char = *name, st =3D iio_priv(indio_dev); st->chip_info =3D chip_info; =20 - dev_set_drvdata(dev, indio_dev); st->dev =3D dev; =20 indio_dev->name =3D name; @@ -258,14 +257,7 @@ static int ad5446_probe(struct device *dev, const char= *name, st->vref_mv =3D ret / 1000; } =20 - return iio_device_register(indio_dev); -} - -static void ad5446_remove(struct device *dev) -{ - struct iio_dev *indio_dev =3D dev_get_drvdata(dev); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(dev, indio_dev); } =20 #if IS_ENABLED(CONFIG_SPI_MASTER) @@ -466,18 +458,12 @@ static int ad5446_spi_probe(struct spi_device *spi) &ad5446_spi_chip_info[id->driver_data]); } =20 -static void ad5446_spi_remove(struct spi_device *spi) -{ - ad5446_remove(&spi->dev); -} - static struct spi_driver ad5446_spi_driver =3D { .driver =3D { .name =3D "ad5446", .of_match_table =3D ad5446_of_ids, }, .probe =3D ad5446_spi_probe, - .remove =3D ad5446_spi_remove, .id_table =3D ad5446_spi_ids, }; =20 @@ -550,11 +536,6 @@ static int ad5446_i2c_probe(struct i2c_client *i2c) &ad5446_i2c_chip_info[id->driver_data]); } =20 -static void ad5446_i2c_remove(struct i2c_client *i2c) -{ - ad5446_remove(&i2c->dev); -} - static const struct i2c_device_id ad5446_i2c_ids[] =3D { {"ad5301", ID_AD5602}, {"ad5311", ID_AD5612}, @@ -571,7 +552,6 @@ static struct i2c_driver ad5446_i2c_driver =3D { .name =3D "ad5446", }, .probe =3D ad5446_i2c_probe, - .remove =3D ad5446_i2c_remove, .id_table =3D ad5446_i2c_ids, }; =20 --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 0C81D200C8C for ; Wed, 23 Oct 2024 23:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727693; cv=none; b=Q/dte3FAUUrZsFKlEVHFeF/caytG4chvTPaF14M2W4gH6pqYFgnFAU52yjK1BA2ZAHRNaeChAq+Ole2Esg6AjychyoYbi6AlHvgkLrOGgrRQrRaShJbSbfrVTAaSlFpycvVvseM4JKie5wh3FoUbB0P+VnBuxY0nhGqeptjiQPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727693; c=relaxed/simple; bh=nUH5txR4P/Bv9EVLN478VLSNk/BVSj4cf6PubYC2e5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E60riSF5hsJVnJQHSdbcWxilnzJG1gscJXI3QQmEZ7L7EcdgmJ3Eta6xGyWDbJi6sLTHSqfuSrVadYd3rzX7Pffc5YnRdp4D8SyU7WfbVTEVMeHoR/TK4zr7Hd2+b3yIuKsWEAslO7MiQKC22s4QgojiISSpwiyyBoozUOvTBe8= 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=Iw4fq07Y; arc=none smtp.client-ip=209.85.161.46 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="Iw4fq07Y" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5e98bfea0ceso159689eaf.0 for ; Wed, 23 Oct 2024 16:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727690; x=1730332490; 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=hYgkvqv4R1HU1dFN4HvN+5+Sd8/gJpr63Hs53U7tMP4=; b=Iw4fq07Yn/4+23EI13rcBmkximnUVWcPNnb0goK6aBcK1nd+Ja3gRArRp3vsnpLkyu EwnMp1XIUGcF6C6eAoVPFxsPnPNkH+CbHPHNvlQufgomsCSNFRG9LuDVA8wCbHTU4bV6 CHGX9d692RLVFadGvThGFFe7uKynMheHuSwfwwP8KbMG5a6rPDxfh35ZtlD0Zf/oVbhH oqm4xH0ZLvNKyLw++GD2ssFt1AHcdZ8suU0nO+QkrHCJGvV6JPHFELLSTj0TlA+nORjn EouAW7MXJmiI+3C7xvqRyb/RnM0CZWf9fSqiKpsfii9EjKXPws60lYKpE/NuRVFgjdQI EbQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727690; x=1730332490; 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=hYgkvqv4R1HU1dFN4HvN+5+Sd8/gJpr63Hs53U7tMP4=; b=syghiUyMVbihKh4TjPYJV4J6VLvNCrBxqCjB8rub29W2PsSOrLoh5Wv735kbwP3g4s 8mCH0RegLdbkUA/g5Rq8LReAn4GUJXdu0V4lod5jYltn30EhtTz1CJoV7bxPByV6/vjs /nuOz3EEzqLLjt2AK2gJYO99+s5WvN2jeOMjWRitrSiv4Ili+0LRVIn27q2XVldBxRfL rBGtzSv2sVCtNkColPyrmOumVc1LTHYVObgCdZz5CZS9evn5usDKYamt+gAEVUuTzYWf i262ElLRBtC1jQZKbG96Oeq6lcu/I47DkA3hsLIlhNw3s8jp/hLofXCMi+JZTQUC45xt Plgg== X-Forwarded-Encrypted: i=1; AJvYcCV6FQgTgfB0Yaapj4ce0Cwu8eT/8SOYElZnNp2ljTOA7Vk2kiSDcrJJLVLo4cpM8yjfI5rlEe7gnzGha6Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1LglVlkyH6rpNcYFU1HHmW4/+COZHag1s0NNMIJHtMkleKX41 kXzW8JqqZR407bO4QyJMC4mhuEsUX86WTs4TmcN+9fZdt5VBseTY4AxYO8bdseI= X-Google-Smtp-Source: AGHT+IHcCxKyS2mmLHC5MPxm7YFL188H9iZp31keASBRo+Q1y9yvvaWEd8aS9jAZNjM885evSN5LsA== X-Received: by 2002:a05:6820:1c9a:b0:5e5:7086:ebe8 with SMTP id 006d021491bc7-5ebee308838mr3087385eaf.0.1729727690124; Wed, 23 Oct 2024 16:54:50 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:49 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:09 -0500 Subject: [PATCH 05/11] iio: dac: ad5504: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-5-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5504.c | 52 ++++++++++++++------------------------------= ---- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c index 305cd58cd257..f1717955ddcf 100644 --- a/drivers/iio/dac/ad5504.c +++ b/drivers/iio/dac/ad5504.c @@ -273,35 +273,27 @@ static int ad5504_probe(struct spi_device *spi) const struct ad5504_platform_data *pdata =3D dev_get_platdata(&spi->dev); struct iio_dev *indio_dev; struct ad5504_state *st; - struct regulator *reg; - int ret, voltage_uv =3D 0; + int ret; =20 indio_dev =3D devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - reg =3D devm_regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(reg)) { - ret =3D regulator_enable(reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } =20 spi_set_drvdata(spi, indio_dev); st =3D iio_priv(indio_dev); - if (voltage_uv) - st->vref_mv =3D voltage_uv / 1000; - else if (pdata) - st->vref_mv =3D pdata->vref_mv; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); =20 - st->reg =3D reg; + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); + if (ret < 0 && ret !=3D -ENODEV) + return ret; + if (ret =3D=3D -ENODEV) { + if (pdata->vref_mv) + st->vref_mv =3D pdata->vref_mv; + else + dev_warn(&spi->dev, "reference voltage unspecified\n"); + } else { + st->vref_mv =3D ret / 1000; + } + st->spi =3D spi; indio_dev->name =3D spi_get_device_id(st->spi)->name; indio_dev->info =3D &ad5504_info; @@ -320,31 +312,17 @@ static int ad5504_probe(struct spi_device *spi) spi_get_device_id(st->spi)->name, indio_dev); if (ret) - goto error_disable_reg; + return ret; } =20 - ret =3D iio_device_register(indio_dev); - if (ret) - goto error_disable_reg; - - return 0; - -error_disable_reg: - if (!IS_ERR(reg)) - regulator_disable(reg); - - return ret; + return iio_device_register(indio_dev); } =20 static void ad5504_remove(struct spi_device *spi) { struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - struct ad5504_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); - - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } =20 static const struct spi_device_id ad5504_id[] =3D { --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 C07B62022FE for ; Wed, 23 Oct 2024 23:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727697; cv=none; b=EhewJutiL4fj+CnJ92hZZ1UQttKAz8SNVFR34+ohOgiLnafMH69xAH17P6O+c84S0VVFdDwfrnikE/KrAC6tqKTY13J29XQKfcgyG36JwCGibXUftqKIpXc9pehlcblSQ13iwEMOiyfJM5v29Xta6iEBKmg06/R/xeLjQiaFGuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727697; c=relaxed/simple; bh=eodQcTyvrhGf+yUx3CV8lHgZoGBVQssedMmfdXFFW70=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d0vKFWdAU+KUaQtePBKsBR0E3vqItsJLMzNaloPqpkZpndU3NAPwjIuC0eA3ljSt2MPtjMzrMM94ZhIFk31ZnEYSTIR4zisBB3Yq/fJ/rTPgzR6RVlnsxlaJRSLfYgtX6NfWJ3+WkTQV+BTyJt1ErCWsS2ItLIK6xaJU+a9tjY0= 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=pEHMMLjj; arc=none smtp.client-ip=209.85.210.52 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="pEHMMLjj" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-718123ec383so202405a34.3 for ; Wed, 23 Oct 2024 16:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727693; x=1730332493; 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=PNDl0JsjI2ngL2OUq0CBnv+Q1hyMOtpynagqCTgnhh4=; b=pEHMMLjjBfPq/OGxfTStJ4BXiygNm9szm+eUn+yBT82JC8OO0Stw4QH2+F8t92Mujh J3BvXQdXhr2GE4THd9jHE3tezddcsZ3EFCKMCNpce5xOTvhw+KqVR25pcMQAhZWAFZAR 18m8tSreFrxozz2DMXXRiajJ8u51U86yIAjNvlUELLtOstqzMnMdCgY2OaC7FILjMUq9 1MvAAOeM9ae3G4s7qelBBD/HJkAaan1rX+pzm4hHZq17sYAh5QGxBzGwD4SqN3XRG7IE CJSknZqWomNnrc156eqepHCkhr70wXfAcAHMIb5YJNm5VAEgqz9RYrmppNyoyfLFxJan vayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727693; x=1730332493; 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=PNDl0JsjI2ngL2OUq0CBnv+Q1hyMOtpynagqCTgnhh4=; b=KGbl7HTlA0oIRPij72+NrOEc8hx26qPmskXMaYu0YIeDXfqQ3Y4z2f2BSq40MXfKhp QeUmnuuN/rr1zn/t9itC6LEkkBjfHU2AgRjlyD8UMpgwK8ZHUWf226cJyOqO2AW0jkl5 Pd+sdgI3WkFvDksazFzxAUtN2oFYH8UjAckhVLgpUk0bB29DahlarzbUgQbNTX3AMCKB 5RcOp9tcV/undphhxSp7O2r6+IorCQMQpmbkhG41qrH8NCJQ+TEnZCysmgYcd7n8iKaC 2ZUC6z77dR+nz6N98RisyaUl6WHlTO21UhCvTPjpUcX+pHIk2y0aT1sOqeHNC3L0urwB lEJw== X-Forwarded-Encrypted: i=1; AJvYcCXx05t2MBke1dEjro3vQTmXFA4IELtB9/R3L9PVVic0iQitiJb8vwVS5RrXrWiY9ep7TydBcPVn3hu6oy8=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8vGItlYFfkiSWKuXc9eeznVlJ3K7jcWmhLavM2nBk72vKp/PJ y71Rghs0YiLR8eA1ed5v+E5CGL42TfJJQWnnv6FzHy1g/7fNAPmzlC28s5Xanrs= X-Google-Smtp-Source: AGHT+IFIuwReVcdIdbunzDzkviLkIqgHxfk94OzuL5c7zcvw3lrHA5VqCjHLaUK5+XcjjvThPDRwKA== X-Received: by 2002:a05:6830:448b:b0:710:f375:a6c9 with SMTP id 46e09a7af769-7184b286fd8mr5065169a34.7.1729727692954; Wed, 23 Oct 2024 16:54:52 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:51 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:10 -0500 Subject: [PATCH 06/11] iio: dac: ad5504: drop driver remove callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-6-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Drop use of the driver remove callback in the ad5504 driver. By making use of a a devm_ helper, we can avoid the need for the remove callback entirely. Signed-off-by: David Lechner --- drivers/iio/dac/ad5504.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c index f1717955ddcf..ff0765c8af47 100644 --- a/drivers/iio/dac/ad5504.c +++ b/drivers/iio/dac/ad5504.c @@ -279,7 +279,6 @@ static int ad5504_probe(struct spi_device *spi) if (!indio_dev) return -ENOMEM; =20 - spi_set_drvdata(spi, indio_dev); st =3D iio_priv(indio_dev); =20 ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); @@ -315,14 +314,7 @@ static int ad5504_probe(struct spi_device *spi) return ret; } =20 - return iio_device_register(indio_dev); -} - -static void ad5504_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } =20 static const struct spi_device_id ad5504_id[] =3D { @@ -337,7 +329,6 @@ static struct spi_driver ad5504_driver =3D { .name =3D "ad5504", }, .probe =3D ad5504_probe, - .remove =3D ad5504_remove, .id_table =3D ad5504_id, }; module_spi_driver(ad5504_driver); --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.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 B0B712038B8 for ; Wed, 23 Oct 2024 23:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727698; cv=none; b=vBej1pQdHA/5w5BjW2qpseplgD0zEaTu9cONKJoOVguQ1gu3gebDrmMmYXbxCyZi5k5Tk4EmNYs9fU0KUxAb2rk5Jjsgx4hYChIdEURV+0phm8NKU2Q6MKZPHXP9U2rGvuTM+gjNyoHbm9CkBt08H3Pi6SBYEfY5eSPb6w0SjkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727698; c=relaxed/simple; bh=WXSUGzKXof4KJHuJTVmWwMUBIzaYKCOmAUkj1cLreFY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AjXfJWtPNc7r+NPM2MiYAaPUP3KLo4lmTiRoyd26cI1G7ZHJQpNSv4wCtoEBpEfyH5k2RgyFBUw9Tm5UjwONeBOEtRPvLxwZ61yBDgEcdcGQuld5XS0eacInvuyTyWOFzO3gQ+yzSihTF/yZSiKeeZFPLtqwqnG4tgrM+BDH5kI= 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=aCC6Ggem; arc=none smtp.client-ip=209.85.161.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="aCC6Ggem" Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5e5d0a80db4so142386eaf.3 for ; Wed, 23 Oct 2024 16:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727696; x=1730332496; 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=z/yIm2be4gnK0+kTlIbceXqBvtukZBq6O9tuHYtKMKc=; b=aCC6GgemP32ZW/IW6ShhL3kF3j5NTQnLEBUi6FMRapqVvexVVR1CUUwHcGfRSOjMF9 m7ALe7AOOpB7ldZtG56S6aLI0QCd0TLuSUu/Lpclydff5OPYt5ISpmHQnc89Ifa8nPIg zBc+0uxiJqDZhKCumf7ojIVamDftQnX3+iNaKYhBIB0oKdJ4o+mdFRGTHnDSNeUK+mbO 1kV4p9gwQHkX0f4c586sVdKwNus7Lagg1EE4m1e57FEPWzZEqsX1xsp1rcuFsgfFkNyy REhBbk6QWr8A8M1/rOJLeq3JagWiWpGRxM7FuO8HUxCDTF1YSMzFvVuEjsz0T7orn6Ec 4vng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727696; x=1730332496; 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=z/yIm2be4gnK0+kTlIbceXqBvtukZBq6O9tuHYtKMKc=; b=trciFdVk9UtSIXOGSQVVCa0DcRSnAns67s904qL5m0XcqTZZr7Gr6MOx+enlW5RX+p VdB3K2boXEaVkjy32gUUYcH7NWXK8rPu5NqcYxZnsRYMPH7Aau/DXM9Rgz1ytWeVroAr qmuNU92NK1iDqdFOkqJ4H6eYKHpHCTVlPGcHHuyZaCIfmDhA4R/G/evzyWZCqk1GMDZ2 rFiDv5m5NGGbUbybKK8EphYdh3289XJ++3JirJYwqqrW0Y/nNKCvvq8sn2/NFFx2RLNV MIUySs1ZPnXGp4sJCcok75a5ur7qrWJ70FbpZuTCXcjWkrwuH4TuR+VD2MwytD36ifJn ZGng== X-Forwarded-Encrypted: i=1; AJvYcCXakXtufQG/njBJ+1YIEBkGDXZkkqSttI1Z5rODkN5LtGk/luABqcSnGlquW69JXo4TUNRHiOYbN8dfrkk=@vger.kernel.org X-Gm-Message-State: AOJu0YyNh9TsgO501Fp9a3xGdDr/qoB6054EuXoafylNdrofdXx7anaI ZVVP2Q0NQ0VXV2suc4AHQaRsqrWX0mFXh+alzelZl5MOemByu77Dbv3Ex4UBvY0= X-Google-Smtp-Source: AGHT+IHRTb/aabdrDQ611+8RrwSHC7WNs1WZvC13QFbK4R08i5t4ZJSrfjoYNDOtfVLaC0BtrhH8CQ== X-Received: by 2002:a05:6820:2209:b0:5e1:cd24:c19c with SMTP id 006d021491bc7-5ebee2fe9b2mr3622584eaf.0.1729727695819; Wed, 23 Oct 2024 16:54:55 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:54 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:11 -0500 Subject: [PATCH 07/11] iio: dac: ad5624r: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-7-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5624r.h | 1 - drivers/iio/dac/ad5624r_spi.c | 62 +++++++++------------------------------= ---- 2 files changed, 13 insertions(+), 50 deletions(-) diff --git a/drivers/iio/dac/ad5624r.h b/drivers/iio/dac/ad5624r.h index 13964f3a22a4..14a439b06eb6 100644 --- a/drivers/iio/dac/ad5624r.h +++ b/drivers/iio/dac/ad5624r.h @@ -54,7 +54,6 @@ struct ad5624r_chip_info { struct ad5624r_state { struct spi_device *us; const struct ad5624r_chip_info *chip_info; - struct regulator *reg; unsigned short vref_mv; unsigned pwr_down_mask; unsigned pwr_down_mode; diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c index 9304d0499bae..5a952b45f488 100644 --- a/drivers/iio/dac/ad5624r_spi.c +++ b/drivers/iio/dac/ad5624r_spi.c @@ -223,50 +223,27 @@ static int ad5624r_probe(struct spi_device *spi) { struct ad5624r_state *st; struct iio_dev *indio_dev; - int ret, voltage_uv =3D 0; + bool external_vref; + int ret; =20 indio_dev =3D devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; st =3D iio_priv(indio_dev); - st->reg =3D devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->reg)) { - ret =3D regulator_enable(st->reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } else { - if (PTR_ERR(st->reg) !=3D -ENODEV) - return PTR_ERR(st->reg); + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret =3D=3D -ENODEV) /* Backwards compatibility. This naming is not correct */ - st->reg =3D devm_regulator_get_optional(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret =3D regulator_enable(st->reg); - if (ret) - return ret; - - ret =3D regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv =3D ret; - } - } + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); + if (ret < 0 && ret !=3D -ENODEV) + return ret; + + external_vref =3D ret !=3D -ENODEV; + st->vref_mv =3D external_vref ? ret / 1000 : st->chip_info->int_vref_mv; =20 spi_set_drvdata(spi, indio_dev); st->chip_info =3D &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; =20 - if (voltage_uv) - st->vref_mv =3D voltage_uv / 1000; - else - st->vref_mv =3D st->chip_info->int_vref_mv; - st->us =3D spi; =20 indio_dev->name =3D spi_get_device_id(spi)->name; @@ -276,31 +253,18 @@ static int ad5624r_probe(struct spi_device *spi) indio_dev->num_channels =3D AD5624R_DAC_CHANNELS; =20 ret =3D ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, - !!voltage_uv, 16); + external_vref, 16); if (ret) - goto error_disable_reg; - - ret =3D iio_device_register(indio_dev); - if (ret) - goto error_disable_reg; - - return 0; - -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); + return ret; =20 - return ret; + return iio_device_register(indio_dev); } =20 static void ad5624r_remove(struct spi_device *spi) { struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - struct ad5624r_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } =20 static const struct spi_device_id ad5624r_id[] =3D { --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 56EEB200136 for ; Wed, 23 Oct 2024 23:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727701; cv=none; b=fdd/oh/L1utKiCJ8mS+WwsUfzglnygKqWHnRLIe52+7/AEzdqWAOwX5RAf01AOdaKHXkpyPbsWTWjLEOETOmqOXxFdGIk3SKeYIEPbuEs8PMISgryAnm0xahv0478dR6nCeV1s53m8OuNdZ8/omu059/z5aw1ISOnTXeH79bndo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727701; c=relaxed/simple; bh=kWbL5m1yzz0e2sWADT8Ksi3XtC6+zGVgjhl+x8sAPqs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QxCBPreuseNuG4dEp872mLvYBWNmmTHfVtV5MnTXuIoCfZWLYvZsscIn8M03TZtcIVzqL+O0tLiXtgUiKCCvJf0PtfP0cxZjUTXbWERSGiNThSMaRg+NqC2Vsi39nhSlbFG8r17vLF1n4jkqmCe5HU1pCZEH+W2LFupHaddF2Tc= 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=RhWzKKcf; arc=none smtp.client-ip=209.85.161.49 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="RhWzKKcf" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5eb73ec1e1aso153255eaf.2 for ; Wed, 23 Oct 2024 16:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727698; x=1730332498; 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=NOcP75tMDnvIMGtI3xKCbUIx+y+p1KSP/2T/68I9uVM=; b=RhWzKKcfN9Qg6AEsiWxg8ijz+oVWNfDNU5WXPWaoxxkDaR5KRWFXBlSmcc+qKMBGPF Ec2Vr1z60OtTJaIjM3FE+AOsOFQL+LTvTIJTYCvNOuoE0JJXgsrZz+ERMmzIswNU0ho7 PUFQEUvmPQgNJ8se27VfTH6woeDm1D5VZqRHjZzf3WIy1OSS413YGxkN0Ll+mx91/PD8 hjUyV+MmukgAXFsOm4d9OoQNBk3g0jLvvM2O16+w40I4m0i2IxvQNuPh1p+HhMMKRE+Q fsg335cJqGh2F3taVOKqKY9C7DOYdU4bkDusOv8xNt4arSGQHBbht724X5ueRE/YZgAl rGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727698; x=1730332498; 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=NOcP75tMDnvIMGtI3xKCbUIx+y+p1KSP/2T/68I9uVM=; b=sP1W7tWKemqn8E5Hfj1c2TcfC/tGF9wwhmtE9Coyn7VLFIj4R/tmVO5rhLKTXHYBd5 KSUaWdRb2/aZOC5zMNO/xG72hyR7S4/f8o5SAFJLkrY9Q5ltIm16t5k6x/voyU1JgpXE ccmyeGzHFgaVE+62MCfsRSPYje99UNnXtANIY3a/E96E9ph6f7SPAEOHDdMRp6SiO6jS ygX+LXZTHQHO8QyFi2UxCNifM5JDaLrG/j5e8puIbbl+Ed999qtyeqerjvrb3ffQGoY2 yP1QLr8qTQqK0DJ1cjT2iUwmGzLlquxDs1TaJ1ikEYGzo0oD+d1vv0O9gV0UpPoJJYEO n7gA== X-Forwarded-Encrypted: i=1; AJvYcCU7wto9Z4hvEITGUIbGxO/i7Tv5PGSvhiAMKG5/ZRhFw/xx164BMOMkqFLTUvr1993rVA/rblAULKQIEss=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6ABuCOzrxASV3BBqhRBjwz7nHKM8Jfs9gNfN7xXJrbyigRO8Z bNYzGP1LkLxKQggVOjYWXPWueXfEkDTkOdjlkHq6ZEiHBH8+JEcgVDvwPfogTi0= X-Google-Smtp-Source: AGHT+IEXHXqBoW0/wOw8FRbvwPSBj+8W685mXz843ju+kM6CBnhT5LJwRs3reFQ9YlEwGYZ8so0Anw== X-Received: by 2002:a05:6820:1c8f:b0:5e7:cb2e:e01e with SMTP id 006d021491bc7-5ebee8fb6ebmr3022107eaf.7.1729727698575; Wed, 23 Oct 2024 16:54:58 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:57 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:12 -0500 Subject: [PATCH 08/11] iio: dac: ad5624r: drop driver remove callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-8-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Drop use of the driver remove callback in the ad5624r_spi driver. By making use of a a devm_ helper, we can avoid the need for the remove callback entirely. Signed-off-by: David Lechner --- drivers/iio/dac/ad5624r_spi.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5624r_spi.c b/drivers/iio/dac/ad5624r_spi.c index 5a952b45f488..2fd38ac8f698 100644 --- a/drivers/iio/dac/ad5624r_spi.c +++ b/drivers/iio/dac/ad5624r_spi.c @@ -240,7 +240,6 @@ static int ad5624r_probe(struct spi_device *spi) external_vref =3D ret !=3D -ENODEV; st->vref_mv =3D external_vref ? ret / 1000 : st->chip_info->int_vref_mv; =20 - spi_set_drvdata(spi, indio_dev); st->chip_info =3D &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; =20 @@ -257,14 +256,7 @@ static int ad5624r_probe(struct spi_device *spi) if (ret) return ret; =20 - return iio_device_register(indio_dev); -} - -static void ad5624r_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } =20 static const struct spi_device_id ad5624r_id[] =3D { @@ -283,7 +275,6 @@ static struct spi_driver ad5624r_driver =3D { .name =3D "ad5624r", }, .probe =3D ad5624r_probe, - .remove =3D ad5624r_remove, .id_table =3D ad5624r_id, }; module_spi_driver(ad5624r_driver); --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 700DE204943 for ; Wed, 23 Oct 2024 23:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727704; cv=none; b=WuPFGyj8mEU3BYmQhOjAO8OTyVhDG40yYNmVmb9PzvmC3aSzgYl8nM153veAKnwfmoEv/6/5S4JA4e0RYrzhM7Zf1qFALBInwcd1In7EDjsNniuCyrplmauiSBUc9p4vh5ftUfc4AL3s79gQl4zhjkLF1HRV41ST5k7PZ9yRs4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727704; c=relaxed/simple; bh=hksfyNtvI8c0zcSVYvltOkcB7HflUdZ/dnRTHZtLyNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EobAyvE4FHRDjzHi9sZ9nWJO7siJtR2RCgXWfQwRVv/wMS9RyCPtFCRFlwthYDtAAGZyBXsKOPJ+zytD9YIYtQ3eFhKXvtWSZzrose1fos2Qtej2Dud6jtqQdJQ/tcuYgFG8XJdSKRuhAM270F3/ayywpqbV0BSim6djbsDAqIs= 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=z2VZ0kpt; arc=none smtp.client-ip=209.85.161.46 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="z2VZ0kpt" Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5eb73ec1e1aso153273eaf.2 for ; Wed, 23 Oct 2024 16:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727700; x=1730332500; 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=zXgjcYC4V8hToJDHO7m0/QEhFcbQteqE49QtIsCR78Q=; b=z2VZ0kptcjguzXDG5NWkuGrpzlLQfk5BQU5/g6SD1qalZysxGHX5GZ0GxrkK/0o3Kd MeTodPAZrGgyrf7TwUmKswcDYAcTeAM5ze/wGbV9BLA24BvoclYqpEaRR55lmoZJY7AC V3bgL1d6rWo8OR02PxxsL/dnSyPw5xuMycDMXELGE2AjmjXUSIn+oZD0bDYqHvWxeypZ Zqu4bZ7hwphxFxRVBLuyaEPn7hYO8wfuT9MqBddNvgG6IChXUsLHY9mjo+bbL+E1X68w 7yFShwdO1DN5NDg2QZ1UySZUHf+83lRywDL0gBgEn0LNKkXB8DLjV3Jtw5EbHnVEB7aQ MSFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727700; x=1730332500; 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=zXgjcYC4V8hToJDHO7m0/QEhFcbQteqE49QtIsCR78Q=; b=uYCxEzkiCLLYo+s44GeOK/0nBEakUwHr6QIm71RPkGno3bZUIYJQwxqqzD5VaKJNSL u5YN5DTHz4DJJ44yquSeufVt2l/DZK8ZQIxCE5t0XYIHN/pFFgYqkpRNuPJztrq394hT /FugqHJSrXQ8apn84PzV2gXr9Lft6/nNbgQyNs/pJyM99zHtCha7sP6XHiRHmZy1PXPo BCfNNH+re4CbGQBGbcKZErltJ9Osd1SksSSO+SmtHokWtIuQCchuAmwYDeIRsGpYKkl1 2fELnxxLUo+rBj6f7oxdcHeZE5Jx32AEI3NQOmkiF9Ga7Pk8bqwmpFTm0kSpNTefYc3J 9KEQ== X-Forwarded-Encrypted: i=1; AJvYcCW19H4pdTPU2IJtpwR8WGylD30KFue/jWGIU1nKZ7eU4JE7QgYjVZPB+pOdU/29L54Z2w3WhfUhvyM68hM=@vger.kernel.org X-Gm-Message-State: AOJu0YzEukfAHCI/7Ek7q3EOTEcJ/NLFlFOLdSlZ27D8j2hnysiu0qje yBN4V7O0whTSq5099Lfe53m4jfSLOOxUwugut2WZFd67/UVRwudkfkfWAoBRsiTjMX6AA7D5nsH p X-Google-Smtp-Source: AGHT+IHX8HP07MxzT6bYrvS2Paasp659iMVaVElKbts9GaB7FyQn3FIL5fyqdvanLn34LceSDDaHRA== X-Received: by 2002:a05:6820:1c8f:b0:5e7:cb2e:e01e with SMTP id 006d021491bc7-5ebee8fb6ebmr3022145eaf.7.1729727700604; Wed, 23 Oct 2024 16:55:00 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:54:59 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:13 -0500 Subject: [PATCH 09/11] iio: dac: ad5761: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-9-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Error returns are updated to use dev_err_probe(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5761.c | 100 +++++++++++--------------------------------= ---- 1 file changed, 23 insertions(+), 77 deletions(-) diff --git a/drivers/iio/dac/ad5761.c b/drivers/iio/dac/ad5761.c index 6aa1a068adb0..55e33cf5806e 100644 --- a/drivers/iio/dac/ad5761.c +++ b/drivers/iio/dac/ad5761.c @@ -53,7 +53,6 @@ enum ad5761_supported_device_ids { /** * struct ad5761_state - driver instance specific data * @spi: spi_device - * @vref_reg: reference voltage regulator * @use_intref: true when the internal voltage reference is used * @vref: actual voltage reference in mVolts * @range: output range mode used @@ -62,7 +61,6 @@ enum ad5761_supported_device_ids { */ struct ad5761_state { struct spi_device *spi; - struct regulator *vref_reg; struct mutex lock; =20 bool use_intref; @@ -287,63 +285,6 @@ static const struct ad5761_chip_info ad5761_chip_infos= [] =3D { }, }; =20 -static int ad5761_get_vref(struct ad5761_state *st, - const struct ad5761_chip_info *chip_info) -{ - int ret; - - st->vref_reg =3D devm_regulator_get_optional(&st->spi->dev, "vref"); - if (PTR_ERR(st->vref_reg) =3D=3D -ENODEV) { - /* Use Internal regulator */ - if (!chip_info->int_vref) { - dev_err(&st->spi->dev, - "Voltage reference not found\n"); - return -EIO; - } - - st->use_intref =3D true; - st->vref =3D chip_info->int_vref; - return 0; - } - - if (IS_ERR(st->vref_reg)) { - dev_err(&st->spi->dev, - "Error getting voltage reference regulator\n"); - return PTR_ERR(st->vref_reg); - } - - ret =3D regulator_enable(st->vref_reg); - if (ret) { - dev_err(&st->spi->dev, - "Failed to enable voltage reference\n"); - return ret; - } - - ret =3D regulator_get_voltage(st->vref_reg); - if (ret < 0) { - dev_err(&st->spi->dev, - "Failed to get voltage reference value\n"); - goto disable_regulator_vref; - } - - if (ret < 2000000 || ret > 3000000) { - dev_warn(&st->spi->dev, - "Invalid external voltage ref. value %d uV\n", ret); - ret =3D -EIO; - goto disable_regulator_vref; - } - - st->vref =3D ret / 1000; - st->use_intref =3D false; - - return 0; - -disable_regulator_vref: - regulator_disable(st->vref_reg); - st->vref_reg =3D NULL; - return ret; -} - static int ad5761_probe(struct spi_device *spi) { struct iio_dev *iio_dev; @@ -363,9 +304,27 @@ static int ad5761_probe(struct spi_device *spi) st->spi =3D spi; spi_set_drvdata(spi, iio_dev); =20 - ret =3D ad5761_get_vref(st, chip_info); - if (ret) - return ret; + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret !=3D -ENODEV) + return dev_err_probe(&spi->dev, ret, + "Failed to get voltage reference value\n"); + if (ret =3D=3D -ENODEV) { + /* Use Internal regulator */ + if (!chip_info->int_vref) + return dev_err_probe(&spi->dev, -EIO, + "Voltage reference not found\n"); + + st->use_intref =3D true; + st->vref =3D chip_info->int_vref; + } else { + if (ret < 2000000 || ret > 3000000) + return dev_err_probe(&spi->dev, -EIO, + "Invalid external voltage ref. value %d uV\n", + ret); + + st->use_intref =3D false; + st->vref =3D ret / 1000; + } =20 if (pdata) voltage_range =3D pdata->voltage_range; @@ -374,35 +333,22 @@ static int ad5761_probe(struct spi_device *spi) =20 ret =3D ad5761_spi_set_range(st, voltage_range); if (ret) - goto disable_regulator_err; + return ret; =20 iio_dev->info =3D &ad5761_info; iio_dev->modes =3D INDIO_DIRECT_MODE; iio_dev->channels =3D &chip_info->channel; iio_dev->num_channels =3D 1; iio_dev->name =3D spi_get_device_id(st->spi)->name; - ret =3D iio_device_register(iio_dev); - if (ret) - goto disable_regulator_err; =20 - return 0; - -disable_regulator_err: - if (!IS_ERR_OR_NULL(st->vref_reg)) - regulator_disable(st->vref_reg); - - return ret; + return iio_device_register(iio_dev); } =20 static void ad5761_remove(struct spi_device *spi) { struct iio_dev *iio_dev =3D spi_get_drvdata(spi); - struct ad5761_state *st =3D iio_priv(iio_dev); =20 iio_device_unregister(iio_dev); - - if (!IS_ERR_OR_NULL(st->vref_reg)) - regulator_disable(st->vref_reg); } =20 static const struct spi_device_id ad5761_id[] =3D { --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 653CB205ADC for ; Wed, 23 Oct 2024 23:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727705; cv=none; b=QUF/Gd+NNVyNj/Pb7w92xcDCp42t6y+lWB9g2+js7kPFYv1C3gyDrvzgWh2X7LSVBKo05+YmdmylPuh+vnlfXs8Y28VqBh+zlawsyd7x9l5mihaYgvgdpaCHVdhf2oy5tlAKxV24bPPxFdPKisET4kWKeOhvV3OaQycwJK7c/Yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727705; c=relaxed/simple; bh=rBJqShNgFgDWxiqlxWde8MpySetcVg/+VpgTQLIZJUE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WAzY5mgFd9gO8QLPXDLG51JLf26AZoQRmTjEq1VpFKOM3U1RGh0EKJaG+SF1oU2uDFS38Ei/O23Symw3aLj7qgE6UtAXGc9bXkynN4zsf5GZeO3KTRMSQj9KkWeg/xu5fQkkGJpy2ZAbf+QUg2xQEe/VH92K7SMfDnxUGiA5e0k= 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=EUavADAY; arc=none smtp.client-ip=209.85.161.45 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="EUavADAY" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5e5568f1b6eso158956eaf.1 for ; Wed, 23 Oct 2024 16:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727702; x=1730332502; 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=iwRem8dxk8AeEhZFejKaWT2ehSfFw6/ckoM5Vp45PUA=; b=EUavADAYDrxMasRmVc37fIaLa4HxSilvbdF4KlBfP84ziR8iCRRRNxRq2uCcDnOQF0 Po1BWQThLN6wzzdFRo7+eMrwOUk/pcjSyVzVuNCiBUY99kCJBpPoZmE9j59cT5i0BcMS YxpnTk5Tp1eJUvrBCSvt2uJOo6mdOtjD8HTAzIC1vAZkA09N6DOXJ5hEG3jrMiBKcorv Jez26SIBxPRH53NBO+pE7i2nEllsTfZ/Luzw6jeYwIkTVcF5+yIxW/SQiMzL19qhweEz LOtnJxb1VoQ9pw026qJCUeBdnm3NTFRyMsHejA/jOTuf87fy2BxAzWco3sZNFP+fK1gh hnGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727702; x=1730332502; 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=iwRem8dxk8AeEhZFejKaWT2ehSfFw6/ckoM5Vp45PUA=; b=k4ssfXOn/to3TbQdTtgglbaGlxxOddKAqz3WgDP6M/dok17r18GbgnW7aGGQvjarp1 RzrHZmhMvqQBqExAWQ03P7XPt8H9Hjfxu39QHoe5kX+Y96WpW7UD3MnSwbbfEDosrqal tISzOZ3+7y/uJx3jIh0qOX4zyNZ62yErx8P7y/cguGA+NjJE85U6aniaC+KYlC8bnRKt Wz/hVUWTyDd5bOlwphZCx1mlL/qbCfkU34A/QKpGFqpB7iOc8q2lFYVg92O2WRcA5ZWE 0t9QawXFRDUmU8XoxVFy4VvxTIkbC6R6KOw+84U4JbIBBNATbG60xZfJJMKUGqanCDHh 1ZfA== X-Forwarded-Encrypted: i=1; AJvYcCXadTQ3ubWOwKPpvmZrty/7ru+aUrfcabr1YypH08ByLpdIWk7ei1nahN4kFgksh4woahqOTctZDWhPYdo=@vger.kernel.org X-Gm-Message-State: AOJu0YwYpUBLhYHil7kbGe3m3wa8BB8h2UE/JiHXMGINWVlUwZxYeHk1 ofHmknXhcItKJKdAnK94gUTADppCAfZa6sCZfj814nefflk+B96gRyoythM84F4= X-Google-Smtp-Source: AGHT+IGtkmr2OClSc6SM8EOI86U/pFTbxAUEWIPPhcsQde8YwVmqunCGN/cl7SNixNhWfRGwgJREGw== X-Received: by 2002:a05:6820:81e:b0:5e1:e748:7ad with SMTP id 006d021491bc7-5ec057d1013mr124181eaf.7.1729727702539; Wed, 23 Oct 2024 16:55:02 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:55:01 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:14 -0500 Subject: [PATCH 10/11] iio: dac: ad5761: drop driver remove callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-10-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Drop use of the driver remove callback in the ad5761 driver. By making use of a a devm_ helper, we can avoid the need for the remove callback entirely. Signed-off-by: David Lechner --- drivers/iio/dac/ad5761.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5761.c b/drivers/iio/dac/ad5761.c index 55e33cf5806e..0aa5ba7f4654 100644 --- a/drivers/iio/dac/ad5761.c +++ b/drivers/iio/dac/ad5761.c @@ -302,7 +302,6 @@ static int ad5761_probe(struct spi_device *spi) st =3D iio_priv(iio_dev); =20 st->spi =3D spi; - spi_set_drvdata(spi, iio_dev); =20 ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); if (ret < 0 && ret !=3D -ENODEV) @@ -341,14 +340,7 @@ static int ad5761_probe(struct spi_device *spi) iio_dev->num_channels =3D 1; iio_dev->name =3D spi_get_device_id(st->spi)->name; =20 - return iio_device_register(iio_dev); -} - -static void ad5761_remove(struct spi_device *spi) -{ - struct iio_dev *iio_dev =3D spi_get_drvdata(spi); - - iio_device_unregister(iio_dev); + return devm_iio_device_register(&spi->dev, iio_dev); } =20 static const struct spi_device_id ad5761_id[] =3D { @@ -365,7 +357,6 @@ static struct spi_driver ad5761_driver =3D { .name =3D "ad5761", }, .probe =3D ad5761_probe, - .remove =3D ad5761_remove, .id_table =3D ad5761_id, }; module_spi_driver(ad5761_driver); --=20 2.43.0 From nobody Mon Nov 25 22:32:02 2024 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 BEFAB206057 for ; Wed, 23 Oct 2024 23:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727708; cv=none; b=NWhcgUwZ00Pjf8iI7iJX0GBhBRPszZuz2hEPE90cGhMgIodsrs64rPInwl/oZSEGX4DuK8XNAzIC6OapedwmomaA7eVb5rBm/UIG3l2kwxYiG1O9L7IpTHVObg6sGdBlfRsm6rhNHv+sC+zjN4YXACHdu0Ual3NeNJxqGcFy+64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727708; c=relaxed/simple; bh=7NlO7cRYdSF3gG8gA/man+tCA4mOxbqbKKfGxWwRT8w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JADExKYJA2ERksxr5jXUkc7qJHc2xa50uT/AW+MvR6uG7lihq3XqhxAoyOVrDLecbxQCcMD4UFsMT1HHgANECkZ3lToekQmA/omHI11PukI+/rTUQnCqli+oipfuN7rfARH8+Ck+4ShZF/sTfv4lTeYAW3akB/CQvLTYjbJxSGI= 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=EAjHzBmK; arc=none smtp.client-ip=209.85.210.47 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="EAjHzBmK" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-7181b86a749so211249a34.3 for ; Wed, 23 Oct 2024 16:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1729727706; x=1730332506; 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=NwdVzGcaQF7+SOsHpL7ftp3FlbFCZlW7or80O3tjS30=; b=EAjHzBmKfRNvKxkR7j4ajPcrpsrmP7EyDPxXiEudP3EoWd59EHq9pG9NlaLF9jh1lZ LKm9oHwLajAtdQqsiUJvHKplM/l1Vf/SkJ0MFCbXnqkH0NOhIoJ72+9Q9fq4ziX/nfOF BoRkz+SCgbbSUBCrNRYx3m8r/19IbDVHLVWxa3wlrv6vjxn8oS3qIkKNZoLH/r1kRB06 rTYUTKwyTi91usAWuuRrQArwL2UzDQq1piD7jFC57CSLDrjE3Ohmte/yh/dUjPo5Kkg8 qmQMulE7EtKjBBZBatMiYekVl+KuLzhUVaGfSYhN/Et146wg2PXOwPchc8Rb8nVOrp4s dd5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729727706; x=1730332506; 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=NwdVzGcaQF7+SOsHpL7ftp3FlbFCZlW7or80O3tjS30=; b=NkRXHNtNmgsn13/CWkEam5wGZXLBWGkQAqGJMW1l+S4wUPhp5rwR0+/r6W9uhu+XWf ICKIQ6VuE/1RhqWQzDeyqR7baCJfpc6Q0w6IS3jZ+xxod8m4/HPLWZdksKpY8PKZQyvw w91TvjWv9n7XREzDftdobAJwy02JqvMRosFYvN1zdyzfVllrv7wJmu2UVJiq2sINKrOH ajl5sgKIWMC+2WCivV/4P5nKLIIkviAYMSjrL37xBCXHpmol4ZYBKwvhAqll5XFuz5lc 9z0fuNW8UEPAemrqdWPpYwu5tur4nBwlMMVh+wWNOeVLWc4q4Cohyb+R1uvWgIkiGrcL p8rw== X-Forwarded-Encrypted: i=1; AJvYcCV99RaSrEF+5IZM+d6rWWVznYn5o0Qx79x2rwTKNpGkt7wZLFuxL+yfzlypX0vADHoZIOHT9P0BEiECVNY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/RAnMOY2div4MSPNfM6/XY7crO3lJEdMFBBnACuOt462wW74Y 8epFQAOShHyLWemrJN3xbkiO4/Z3XXxj8JqvAKBruM9ztXnlfMf76bNgRX/ztNtxwxEHcGFKFyK 6 X-Google-Smtp-Source: AGHT+IFFf5uOVklZ3NWR8b1RT59iDDEKxLvxl1mNoMhioyb2CzYSMhqTdom4ES3ddDpjGH7DrlUq6g== X-Received: by 2002:a05:6830:43a7:b0:718:196a:c749 with SMTP id 46e09a7af769-7184b44d2b3mr4807921a34.27.1729727705886; Wed, 23 Oct 2024 16:55:05 -0700 (PDT) Received: from [127.0.1.1] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5ec02c2b25bsm132002eaf.39.2024.10.23.16.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 16:55:04 -0700 (PDT) From: David Lechner Date: Wed, 23 Oct 2024 18:54:15 -0500 Subject: [PATCH 11/11] iio: dac: ad5770r: use devm_regulator_get_enable_read_voltage() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-iio-regulator-refactor-round-5-v1-11-d0bd396b3f50@baylibre.com> References: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> In-Reply-To: <20241023-iio-regulator-refactor-round-5-v1-0-d0bd396b3f50@baylibre.com> To: Jonathan Cameron Cc: Michael Hennerich , Liam Girdwood , Mark Brown , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, David Lechner X-Mailer: b4 0.14.1 Simplify the code by using devm_regulator_get_enable_read_voltage(). Signed-off-by: David Lechner --- drivers/iio/dac/ad5770r.c | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c index 7d7f5110d66a..25cf11d0471b 100644 --- a/drivers/iio/dac/ad5770r.c +++ b/drivers/iio/dac/ad5770r.c @@ -122,7 +122,6 @@ struct ad5770r_out_range { * struct ad5770r_state - driver instance specific data * @spi: spi_device * @regmap: regmap - * @vref_reg: fixed regulator for reference configuration * @gpio_reset: gpio descriptor * @output_mode: array contains channels output ranges * @vref: reference value @@ -134,7 +133,6 @@ struct ad5770r_out_range { struct ad5770r_state { struct spi_device *spi; struct regmap *regmap; - struct regulator *vref_reg; struct gpio_desc *gpio_reset; struct ad5770r_out_range output_mode[AD5770R_MAX_CHANNELS]; int vref; @@ -591,13 +589,6 @@ static int ad5770r_init(struct ad5770r_state *st) return ret; } =20 -static void ad5770r_disable_regulator(void *data) -{ - struct ad5770r_state *st =3D data; - - regulator_disable(st->vref_reg); -} - static int ad5770r_probe(struct spi_device *spi) { struct ad5770r_state *st; @@ -622,34 +613,12 @@ static int ad5770r_probe(struct spi_device *spi) } st->regmap =3D regmap; =20 - st->vref_reg =3D devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->vref_reg)) { - ret =3D regulator_enable(st->vref_reg); - if (ret) { - dev_err(&spi->dev, - "Failed to enable vref regulators: %d\n", ret); - return ret; - } + ret =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret !=3D -ENODEV) + return dev_err_probe(&spi->dev, ret, "Failed to get vref voltage\n"); =20 - ret =3D devm_add_action_or_reset(&spi->dev, - ad5770r_disable_regulator, - st); - if (ret < 0) - return ret; - - ret =3D regulator_get_voltage(st->vref_reg); - if (ret < 0) - return ret; - - st->vref =3D ret / 1000; - } else { - if (PTR_ERR(st->vref_reg) =3D=3D -ENODEV) { - st->vref =3D AD5770R_LOW_VREF_mV; - st->internal_ref =3D true; - } else { - return PTR_ERR(st->vref_reg); - } - } + st->internal_ref =3D ret =3D=3D -ENODEV; + st->vref =3D st->internal_ref ? AD5770R_LOW_VREF_mV : ret / 1000; =20 indio_dev->name =3D spi_get_device_id(spi)->name; indio_dev->info =3D &ad5770r_info; --=20 2.43.0