From patchwork Wed Oct 23 23:54:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848115 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.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 B450F1BDDF for ; Wed, 23 Oct 2024 23:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727684; cv=none; b=EeoQJN6TycPLIknRjeSZhXvfrMGCG1fHUKGviQU5EL4/9vZIO7z7Kuxr+mmfz7k3Mb5FAzzxte4AmC5qMcovGE57a/POiMMFAThO0mSHqEhL7GPEXuG+Fe+llzVMVg0m9cdYZ+Om0kWceZyhrFhLJAYnFIN39/iyDWPY2sZXgUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727684; c=relaxed/simple; bh=+qQPhpRBI2xebpxF2IUsDgxiRfAaR2OlImrgtgTUDY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ULBBX3Xw78XuI1645OGiBOjCeIEVYcmUnVX7iojhxnf0M4QwVagKRE548dYTx3C9lFkT29wpaIlnZXt0g+JFKGDoyR7KuaWCrZnEd5+9gCQO/AKaZKP3m+wiCeBbC1m/x2l7V+YAnooWNRK+k9wTQt+L88HuYRp3yMC0Qs5a38A= 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.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="XeADY2iq" Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5ebc0c05e25so160529eaf.3 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=Rt6C1rUiLoJHlcLR9bbHMRv/re3A2oJmegkb11viYDna1UlxU3U6s0OW8IniQy7q9X ZDAcktf42Rg2gFUzkgk2FzGc2NugPMgyrPN59Vyi3bbn1SLHPAx2zwNtSmLtli7Hf60C 3b+uXDyHueVvz7dPII4UnbFpB52HnxSU5wrBIWWKfDr6EcfFGDB4FXS05kk7FQ7pccrw kW0akXel5j/qZz7WnWp5LX6PO9xu5jbmqbIOyUAjvQ/rBNBmRkNq67ZmrFQUY+nlnPXs ArOUUC5sSD338Q5AKZTpj9SGbfxlHxoRAfx8Jlb2UIzuBXcUKoCdCsMQDmM0BkqmGFE9 TIQw== X-Forwarded-Encrypted: i=1; AJvYcCWBt9hxm8LdOsw5lW4qWcQ4g+/dq3SI0dBiN/Imcs+PUUzCd6glyI19qKP7VO3fFrnCHbV8b9xMBIg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywx2DjZrBvqcz5ZlXAsZfoW0uC7QUSS+zqPTQx3H9I7c/rj1zF4 FUY9xoqkykSgnoXMsiQlRteBGWDPW09yHMiMzATPPmKhLOJJe/TGCb61IxeQmNs= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 regmap *regmap, if (st->chip_info->int_vref == 2500) ctrl |= AD5380_CTRL_INT_VREF_2V5; - st->vref_reg = devm_regulator_get(dev, "vref"); - if (!IS_ERR(st->vref_reg)) { - ret = regulator_enable(st->vref_reg); - if (ret) { - dev_err(dev, "Failed to enable vref regulators: %d\n", - ret); - goto error_free_reg; - } - - ret = regulator_get_voltage(st->vref_reg); - if (ret < 0) - goto error_disable_reg; - - st->vref = ret / 1000; - } else { + ret = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (ret < 0 && ret != -ENODEV) { + dev_err(dev, "Failed to get vref voltage: %d\n", ret); + goto error_free_reg; + } + if (ret == -ENODEV) { st->vref = st->chip_info->int_vref; ctrl |= AD5380_CTRL_INT_VREF_EN; + } else { + st->vref = ret / 1000; } ret = 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; } ret = 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; } return 0; -error_disable_reg: - if (!IS_ERR(st->vref_reg)) - regulator_disable(st->vref_reg); error_free_reg: kfree(indio_dev->channels); @@ -445,14 +433,10 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, static void ad5380_remove(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5380_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); kfree(indio_dev->channels); - - if (!IS_ERR(st->vref_reg)) - regulator_disable(st->vref_reg); } static bool ad5380_reg_false(struct device *dev, unsigned int reg) From patchwork Wed Oct 23 23:54:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848116 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 A324D200138 for ; Wed, 23 Oct 2024 23:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727685; cv=none; b=kL1Q8S+1hs2ebmKkmiTlusOiHmZCTii647NYRMthEwyxU8WG8Z5a4bv4lj8wDCsgc147OaXUIm3ypfyVhwRIQ+r5F9nTzgYOBg7xjT2HX9Le68INI4faMTNo2zgzDfJ1gmixXIGtZc+NglZ5WnInGQhLyDL4uS+72XcGKQPbjww= 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.43 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-f43.google.com with SMTP id 46e09a7af769-7180d9d0dcbso173481a34.3 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=hRYdLlYbFXZdiJIfRaT8GAx5X7jG3fYbbLKqIp1s+2KnWOLLjnp1wxfRuUAmHDfQFQ 3xq4QZmpCJwjtObxxjRcuqaXAwMwXIz0eGdrrKRA6UMDUpzB/5jwDtmP7VkD452vgqbJ e6uHnGi/RJuWRqzIwzTIMkbx+ILXbATc5+WoKi0Yl2flwBDMV5LobFevX0PD3bF2RtOa rmtBjlcTI9esVNkMZ99B0jpKHe69BMokmx9WEgQfpquUrqJo91Fv38zkDVc+ahyTgQGR xIsAiL6BCBxdsHubNvNvaEAuC3b4pcrhIpALx8bJYsdSpO3p+rGN7CPgJifc1CR36hTA de8w== X-Forwarded-Encrypted: i=1; AJvYcCXWnW4btBCjRxk0GKN2v5htPhrckJiejjRpHMlOdMVFvg2+rmk83qPkZUNPL81zmEX4QD33Azu/irs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9ZN+olEhWumIJkV4iHmKcvjhUdQlB93II/HuZIfdfmALf7V2o 6ynNFXI6ZIYsGzMth5JbogbjwHkAhuPkqczFFwgC4HEoymdfjS2pAQgWt3ekIfY= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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[] = { }, }; -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 = iio_priv(indio_dev); struct iio_chan_spec *channels; unsigned int i; - channels = kcalloc(st->chip_info->num_channels, - sizeof(struct iio_chan_spec), GFP_KERNEL); + channels = devm_kcalloc(dev, st->chip_info->num_channels, + sizeof(struct iio_chan_spec), GFP_KERNEL); if (!channels) return -ENOMEM; @@ -377,7 +377,6 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, } st = iio_priv(indio_dev); - dev_set_drvdata(dev, indio_dev); st->chip_info = &ad5380_chip_info_tbl[type]; st->regmap = regmap; @@ -389,20 +388,16 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, mutex_init(&st->lock); - ret = ad5380_alloc_channels(indio_dev); - if (ret) { - dev_err(dev, "Failed to allocate channel spec: %d\n", ret); - return ret; - } + ret = ad5380_alloc_channels(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to allocate channel spec\n"); if (st->chip_info->int_vref == 2500) ctrl |= AD5380_CTRL_INT_VREF_2V5; ret = devm_regulator_get_enable_read_voltage(dev, "vref"); - if (ret < 0 && ret != -ENODEV) { - dev_err(dev, "Failed to get vref voltage: %d\n", ret); - goto error_free_reg; - } + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(dev, ret, "Failed to get vref voltage\n"); if (ret == -ENODEV) { st->vref = st->chip_info->int_vref; ctrl |= AD5380_CTRL_INT_VREF_EN; @@ -411,32 +406,14 @@ static int ad5380_probe(struct device *dev, struct regmap *regmap, } ret = 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"); - ret = iio_device_register(indio_dev); - if (ret) { - dev_err(dev, "Failed to register iio device: %d\n", ret); - goto error_free_reg; - } + ret = devm_iio_device_register(dev, indio_dev); + if (ret) + return dev_err_probe(dev, ret, "Failed to register iio device\n"); return 0; - -error_free_reg: - kfree(indio_dev->channels); - - return ret; -} - -static void ad5380_remove(struct device *dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - - iio_device_unregister(indio_dev); - - kfree(indio_dev->channels); } 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); } -static void ad5380_spi_remove(struct spi_device *spi) -{ - ad5380_remove(&spi->dev); -} - static const struct spi_device_id ad5380_spi_ids[] = { { "ad5380-3", ID_AD5380_3 }, { "ad5380-5", ID_AD5380_5 }, @@ -501,7 +473,6 @@ static struct spi_driver ad5380_spi_driver = { .name = "ad5380", }, .probe = ad5380_spi_probe, - .remove = ad5380_spi_remove, .id_table = ad5380_spi_ids, }; @@ -543,11 +514,6 @@ static int ad5380_i2c_probe(struct i2c_client *i2c) return ad5380_probe(&i2c->dev, regmap, id->driver_data, id->name); } -static void ad5380_i2c_remove(struct i2c_client *i2c) -{ - ad5380_remove(&i2c->dev); -} - static const struct i2c_device_id ad5380_i2c_ids[] = { { "ad5380-3", ID_AD5380_3 }, { "ad5380-5", ID_AD5380_5 }, @@ -574,7 +540,6 @@ static struct i2c_driver ad5380_i2c_driver = { .name = "ad5380", }, .probe = ad5380_i2c_probe, - .remove = ad5380_i2c_remove, .id_table = ad5380_i2c_ids, }; From patchwork Wed Oct 23 23:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848117 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.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 6848C200B81 for ; Wed, 23 Oct 2024 23:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727688; cv=none; b=BgrfMpYyAR3lsq1ZHpo1KOaFqKIqlNdey3HCGPvvg+zXB1Q65tyR9QaUeG5essx2t32i0JcYVEy34Pq7UrIz9CNWSeav30pe2z/utKVmBmdfeUAMp8pOWYL4Y0dEMqe7pTaKLT7cELM0A3blaqu9STbBCM1FhvZUFuGpgndtctY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727688; c=relaxed/simple; bh=BZeNhUpFlkIYdGaRA/ukfyi29Qtnq8SmBSpRm9b6skE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j0ZW3EYyHlC3BjfLYrRwNjSBDQLiM/zNfbI9Ue4K2y9JaBrBHo+NeLjFXHdUMnM/mlp//0ilX4w4wqEUqZDfQp6gjehdGj8wxxPiNbiSInbG30OdoWMsu6QQHKl7TeaIeiGtRxdIP+dHOShdLiTC+j0PaNO2HtkZh9tvv9dpQOQ= 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.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="OEN7a9NJ" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5e7ae4c504fso120253eaf.1 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=W7f6IKQJxh5q5KNfi5kzKWRBHjGxtp+vuazZGXhjrf5fR+KQ8ZkaVXTEsvlHBSM5Ka bCU+Q1lvoDjD+2uhz4V9nTr51jroaSVR4JTC5PU30I54klohdS72E4/Hx+SUwUtTh+W7 iqCLmF+cZYW2xF+df4lB5eySxcSiVU5+3HyFoVVetiBZVEbQ3ziSk6CmFR87vjo25kef IhnCoT3CuedVCrUVkcExSSKCacFtf26ws+mS64GXtXL2C1u8KrpqFgtp2Re96qmdhfJq v9W/CBrmtTxObXkTv/L2kLrKBVk8JUTMX8wftDgq4K3fO9wSN3nxbOo5nRa5zvOltcWp tWBQ== X-Forwarded-Encrypted: i=1; AJvYcCW1pkpCLcNHADJ3wIT6YQ7/g7d+Ddia7jggHT5YueC9cTtzckH1FvDz/WZca/9aJ6Xh2JvznLR1pbE=@vger.kernel.org X-Gm-Message-State: AOJu0YxAguCwEzgtoc0XOpia7c53Qo35l2Se51DSIF3opPSXkKF5z7nL D4NLzppTPemEOn0lhjmVx8IJ4N6JO6NdCNc1TODP9gJuYOp/aBxO22KxDl1CR8I= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 == 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 char *name, { struct ad5446_state *st; struct iio_dev *indio_dev; - struct regulator *reg; - int ret, voltage_uv = 0; - - reg = devm_regulator_get(dev, "vcc"); - if (!IS_ERR(reg)) { - ret = regulator_enable(reg); - if (ret) - return ret; - - ret = regulator_get_voltage(reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv = ret; - } + int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*st)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_disable_reg; - } + if (!indio_dev) + return -ENOMEM; + st = iio_priv(indio_dev); st->chip_info = chip_info; dev_set_drvdata(dev, indio_dev); - st->reg = reg; st->dev = dev; indio_dev->name = name; @@ -264,33 +246,26 @@ static int ad5446_probe(struct device *dev, const char *name, st->pwr_down_mode = MODE_PWRDWN_1k; - if (st->chip_info->int_vref_mv) - st->vref_mv = st->chip_info->int_vref_mv; - else if (voltage_uv) - st->vref_mv = voltage_uv / 1000; - else - dev_warn(dev, "reference voltage unspecified\n"); - - ret = iio_device_register(indio_dev); - if (ret) - goto error_disable_reg; - - return 0; + ret = devm_regulator_get_enable_read_voltage(dev, "vcc"); + if (ret < 0 && ret != -ENODEV) + return ret; + if (ret == -ENODEV) { + if (chip_info->int_vref_mv) + st->vref_mv = chip_info->int_vref_mv; + else + dev_warn(dev, "reference voltage unspecified\n"); + } else { + st->vref_mv = ret / 1000; + } -error_disable_reg: - if (!IS_ERR(reg)) - regulator_disable(reg); - return ret; + return iio_device_register(indio_dev); } static void ad5446_remove(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5446_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } #if IS_ENABLED(CONFIG_SPI_MASTER) From patchwork Wed Oct 23 23:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848118 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 2CECD200BB2 for ; Wed, 23 Oct 2024 23:54:49 +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=1729727691; cv=none; b=fJc+6kxZosExThjQD92GKQ/Up99fpsNtp4noFfVhQ0dlWY101HH35HvhA1/qBpF7FDHaXNF1aTX1eBWRw3bMBL1LW9LNJALkynKlYhmRe0sXbu4rCx0+libbEYWdwiWgDQw5UldQ7uW8NunTuXt4tmC/+Yx17ZYdwHBwuH0IszQ= 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.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="GaEJzVMr" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7180d9d0dcbso173496a34.3 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=weCyYFBKzvvlHJLSRzwtwpZX3pMR4yYasO1K/R0ME4roD5b10OayrM+8VYo43b5b36 p8lxqb9auv1pHN152z9uQVx5jLw7D7OEBITK/1owmQqy6/+thqHo9kyz4QRDi5b1NcOP +Y7X3KWvhL9dzhoY+umViy6/cKtkf4t39wYXX76zEKlsvYymz3jt6bgM5GHRS/qpoeQf B+H7f59aHtlBBfQQTVCdymwIUOMS86tmLKe0iWSOpVmzbI4PpjO2W9QrOS7d4yBv2GPu 2hG4nrne9bgDEyKGOLiWXVKrBdo7cNHr6f7jUOdMQEZWkkYsyLDxiefjuOMp06kSISt4 J4QQ== X-Forwarded-Encrypted: i=1; AJvYcCV7CnS6XOky9p6kHgS4fZ76eBmcLmNc/N7yzHNw2ZYS1YH+8GFVgiMdXWftHG7MzRDtXjU3mPchrB8=@vger.kernel.org X-Gm-Message-State: AOJu0YypvIRJQy67dmeLBQzxYPIs+4W6liKyb51+hTxvDBlUr4YPKjWj YUnBoC4lUSNFHO90KQ9DfcurL3MrjxZHK79EVC+dAEw7DlUkosnese7ODg3Bo0BZ2lqTJHysmts D 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = iio_priv(indio_dev); st->chip_info = chip_info; - dev_set_drvdata(dev, indio_dev); st->dev = dev; indio_dev->name = name; @@ -258,14 +257,7 @@ static int ad5446_probe(struct device *dev, const char *name, st->vref_mv = ret / 1000; } - return iio_device_register(indio_dev); -} - -static void ad5446_remove(struct device *dev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(dev, indio_dev); } #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]); } -static void ad5446_spi_remove(struct spi_device *spi) -{ - ad5446_remove(&spi->dev); -} - static struct spi_driver ad5446_spi_driver = { .driver = { .name = "ad5446", .of_match_table = ad5446_of_ids, }, .probe = ad5446_spi_probe, - .remove = ad5446_spi_remove, .id_table = ad5446_spi_ids, }; @@ -550,11 +536,6 @@ static int ad5446_i2c_probe(struct i2c_client *i2c) &ad5446_i2c_chip_info[id->driver_data]); } -static void ad5446_i2c_remove(struct i2c_client *i2c) -{ - ad5446_remove(&i2c->dev); -} - static const struct i2c_device_id ad5446_i2c_ids[] = { {"ad5301", ID_AD5602}, {"ad5311", ID_AD5612}, @@ -571,7 +552,6 @@ static struct i2c_driver ad5446_i2c_driver = { .name = "ad5446", }, .probe = ad5446_i2c_probe, - .remove = ad5446_i2c_remove, .id_table = ad5446_i2c_ids, }; From patchwork Wed Oct 23 23:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848119 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 ED33D200BA8 for ; Wed, 23 Oct 2024 23:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727693; cv=none; b=QNP0aXSIL3UXIbbQ5WxbuTNFZlKzHaog2C8+1TO/OQdAiv5A8B0W3+om0vEgGsM3QNaM7eLxzAMvSaTqmIEX2DlmZXMNy+aTg8PS5irlNpR0Ew9tQLGBRf6e8uDabCZ7HvGfQH/sF6xkbm9odeHTt7UnEQXUAz2hv5gj3ebnl70= 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.51 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-f51.google.com with SMTP id 006d021491bc7-5ebbfcab9f4so138019eaf.2 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=FPHs/TsCXQB75bRtd6/RmHfKEc8e8bVTvSwidpM5mY7a4u5M1GAIffcz8aTiirKeRO 33B7q7neOOis0f8tu8qCWUDTvLWoD6VZNhmv8Gte1fgsxejEv9OxQoDgA8HlIYhKjSD1 Y6YlXhEd1RZdmp8WPxYHlzCEkLKSmEgsjd9BNTZ+3+LWcpa6qCwL3CkYdbMy1bKiM4jF TPGsAVHW2ICyZDMCupfUh2lBMR/bwRh4FS8UcUmbuHGWFeR9oAHltZkg41LofRASgqW2 ko30nRl2noeg8OU2CoTqAVD9Q98PR6ZPfGu5h4l1PK62IiIW+Y7iZeO/ZV92traRKYzc bjrw== X-Forwarded-Encrypted: i=1; AJvYcCXYMrXaqUVBEbtUkP6uOWR21/vIdcUhiJsCER4uqj8sOiSXkpeChhJsGUKBz0WNeK2N1/Ccy2Pm8BM=@vger.kernel.org X-Gm-Message-State: AOJu0YyUUIWal0HA2wJx/bWvmRU6uZpu8arPnjXxYn+9pMhm1e/WrF80 glenWOeMDl2EV9y0DRgweNAY8k8HHVuRE+7IG8Whaqmi0R4IEwTjkiZyAjz1d/A= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = dev_get_platdata(&spi->dev); struct iio_dev *indio_dev; struct ad5504_state *st; - struct regulator *reg; - int ret, voltage_uv = 0; + int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; - reg = devm_regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(reg)) { - ret = regulator_enable(reg); - if (ret) - return ret; - - ret = regulator_get_voltage(reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv = ret; - } spi_set_drvdata(spi, indio_dev); st = iio_priv(indio_dev); - if (voltage_uv) - st->vref_mv = voltage_uv / 1000; - else if (pdata) - st->vref_mv = pdata->vref_mv; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); - st->reg = reg; + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); + if (ret < 0 && ret != -ENODEV) + return ret; + if (ret == -ENODEV) { + if (pdata->vref_mv) + st->vref_mv = pdata->vref_mv; + else + dev_warn(&spi->dev, "reference voltage unspecified\n"); + } else { + st->vref_mv = ret / 1000; + } + st->spi = spi; indio_dev->name = spi_get_device_id(st->spi)->name; indio_dev->info = &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; } - ret = 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); } static void ad5504_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad5504_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } static const struct spi_device_id ad5504_id[] = { From patchwork Wed Oct 23 23:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848120 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 B534920110D for ; Wed, 23 Oct 2024 23:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727695; cv=none; b=gZK8uwVLDyoD7p2d2mtztRV1rccfgZfGrbs8YqFnQFsOUFQNsaUvOI571hisD+SwhlmjBSPx6e+pZ5spHb5z+fA59S6YAcHjbA5IGH+UJWVn7VkoQwp5+ImYDO3415LSg7we7ns0ho7QxwtNUjUFFeZmIHrpx8P3/NHW99svvYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727695; c=relaxed/simple; bh=eodQcTyvrhGf+yUx3CV8lHgZoGBVQssedMmfdXFFW70=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mzi7c7BCrz/sFoitYCLnq9HkxviDspc3gJC2UQPPFXYo7tH3k036CphsALM5bf4tH0rThpowYmTjnMyykYC/TM+WUIeURGsX5eWSq3LNFb3J2mAbL3WueaoVSWvlOHgJIouzqHnv0IqFb4pJ6upulZkATNcCrtECg5WzoflZbHc= 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.53 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-f53.google.com with SMTP id 46e09a7af769-718123ec383so202406a34.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=Z9XQPvwO6ilkE5tL3eIP3Cco2pEnbjM1Nxl/i8wcVSY058aFhK8l+RDwWkKqbBMaKj ZGBylREg/TRs4bulyX+0ngAtXorUSB9JNT7btOkM8MeEpumqfbf/blYFlHc7AT5KuC64 U0pM91WkhiH+mEgSGzuGQKma1v2JHkBq/faBPkF+oSzv+tpqZAJEJJUEnL8qBY1FGpGh gbYjjfR7gCK6A/3Y1zgjnQjmmGOg7pp3TwNSKnOh0E8YmfGrBJ9kmUvhVYYm3OoDA91z 8YCZt9Lrm6ZgKwzX+Dt7svjInPFcdQfdD631LI6nTwofmmDXXpGE085qGDDMU3hDee/C rxWA== X-Forwarded-Encrypted: i=1; AJvYcCWbthMYy+LAyORMkuTI35dtPatiAKcBEJ4XKxuXOM8SkKGCoSkgqOu7JHhqHTf0VR20PRkoU8iuCZs=@vger.kernel.org X-Gm-Message-State: AOJu0YwrOlbSpoV07g/NdDRDuROVvkdqNLm7qhMM66gvmUoja7YGE02g OID6OdAXLycJmxAHh8dykTXKcrSGhSR+8ccN/PhLTvxouZob+k5IRmcWkc+kPd/Gilqb5cEiOJN W 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; - spi_set_drvdata(spi, indio_dev); st = iio_priv(indio_dev); ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); @@ -315,14 +314,7 @@ static int ad5504_probe(struct spi_device *spi) return ret; } - return iio_device_register(indio_dev); -} - -static void ad5504_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad5504_id[] = { @@ -337,7 +329,6 @@ static struct spi_driver ad5504_driver = { .name = "ad5504", }, .probe = ad5504_probe, - .remove = ad5504_remove, .id_table = ad5504_id, }; module_spi_driver(ad5504_driver); From patchwork Wed Oct 23 23:54:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848121 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 A867D2038B5 for ; Wed, 23 Oct 2024 23:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727698; cv=none; b=G/Czh1rvqpAjJPc7/RZ7GmmKDdFx901Z5IkYqqDufsopzOoGFIRiJDmUGz0IjzbUi3l5wtScgHi67Fl9j5DBUhA7RIOWAWafWMgthAR+vSV1IkuCt4NrdIHQly54zk64jzCOozmsusPYDc2D0SasFv5Cjqz2TSZ8vsktHwbMjCo= 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.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="aCC6Ggem" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5ebc04d4777so143532eaf.2 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=TJJeRPr/BVekv2/sC5wHKJ9o9KxBVutOmoSLu4ugDLZ5pwiBGFIaIzjT3Qatr7GnHt JMYCaIdEknRlGt2rGplci0U8wGVB1tjJpLg1LTge3PVGwbVETJug0yckrui5JENu2bMN uRln7pp4myU1SplFgtgWCSmoXCZdrc8otC5+ruRnWz0Xou7pFMe+CJBvk8M+ENv120hc otw7lyMcd+q99qPpsjapoLhz0rLbbt+e8zpjuZqBnGLHinZsFc3Ttzd+2Qu00r/D0pEN 8UmLUpTRsRh3WdQ6QabI7rPM42e+1nH+QIFZNifKCJg4eJgsl2qagn5YbIqJp8ZKUQDH G8wg== X-Forwarded-Encrypted: i=1; AJvYcCXooxOHeNkVdZzrnsDpdK04/+0GasjxouVdSJA/cMPFMLMdDWGpjRIQFX6rdqd6pTt6rbo31zrp+LU=@vger.kernel.org X-Gm-Message-State: AOJu0YyULouFuI2yQDlH9mpd5dg5yDN+P1XKXtIL2+ZVgzwBHHz/VvWp 9wG8dyG0D6yxlbltK4EZLcC/yIN7gJ67Y+UJU0u9GbgcTXCQsZhVE48h69ow8HW2GjWtpsN7MUj u 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = 0; + bool external_vref; + int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - st->reg = devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv = ret; - } else { - if (PTR_ERR(st->reg) != -ENODEV) - return PTR_ERR(st->reg); + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret == -ENODEV) /* Backwards compatibility. This naming is not correct */ - st->reg = devm_regulator_get_optional(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - return ret; - - ret = regulator_get_voltage(st->reg); - if (ret < 0) - goto error_disable_reg; - - voltage_uv = ret; - } - } + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc"); + if (ret < 0 && ret != -ENODEV) + return ret; + + external_vref = ret != -ENODEV; + st->vref_mv = external_vref ? ret / 1000 : st->chip_info->int_vref_mv; spi_set_drvdata(spi, indio_dev); st->chip_info = &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - if (voltage_uv) - st->vref_mv = voltage_uv / 1000; - else - st->vref_mv = st->chip_info->int_vref_mv; - st->us = spi; indio_dev->name = spi_get_device_id(spi)->name; @@ -276,31 +253,18 @@ static int ad5624r_probe(struct spi_device *spi) indio_dev->num_channels = AD5624R_DAC_CHANNELS; ret = ad5624r_spi_write(spi, AD5624R_CMD_INTERNAL_REFER_SETUP, 0, - !!voltage_uv, 16); + external_vref, 16); if (ret) - goto error_disable_reg; - - ret = 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; - return ret; + return iio_device_register(indio_dev); } static void ad5624r_remove(struct spi_device *spi) { struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad5624r_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); } static const struct spi_device_id ad5624r_id[] = { From patchwork Wed Oct 23 23:54:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848122 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 56F6B204008 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-5ebc52deca0so136022eaf.3 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=fU+IBaRDPWUSfHU6jrx+bqir5HqJMMntVJt/AmU0erihWlunjTbzz3zvAi8QB++g3z uW2azNMzA8fzpmkZUc/mgca26aKb9a1ue13SuOCi1o+yLaM8YUDtKxervmX7ZVeUr1ew 6c891KSpnv6u8eE4Is3WBNGUiD6k+m4qTdh2JL6FDcYdydlJhVNjwwcjhMO9ERKZ3TfN XsBbimFYyTs6cQYVCa75Y1lRNd7Fn4bc1AUA70peepGAv249RbMxqLzc/HbFUysEY1tP t7QZD+2qbDGQkR/k7mQHkSaqGqaeS7gKsa75HqWG0OXoPNcEVg62jasvb2uj4OErXwPc 1oYg== X-Forwarded-Encrypted: i=1; AJvYcCXzBPVspTqjvVRByC5EugW4RydEEUY+J+FQVUO4jluZ8m8C7CHPr20gbsJQK8JaEAC2THO4vekMPiI=@vger.kernel.org X-Gm-Message-State: AOJu0YwhWTvqlgkcdLlx6vc6zxkDu4UgLndyknIcqZMlXFAQo0qxUdkW nWCOFekIV0jIsutiefjbLn50O6FlbkqvkKJQR+P19nUoQnYpMSHgwHRzmHEivl0= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = ret != -ENODEV; st->vref_mv = external_vref ? ret / 1000 : st->chip_info->int_vref_mv; - spi_set_drvdata(spi, indio_dev); st->chip_info = &ad5624r_chip_info_tbl[spi_get_device_id(spi)->driver_data]; @@ -257,14 +256,7 @@ static int ad5624r_probe(struct spi_device *spi) if (ret) return ret; - return iio_device_register(indio_dev); -} - -static void ad5624r_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - - iio_device_unregister(indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad5624r_id[] = { @@ -283,7 +275,6 @@ static struct spi_driver ad5624r_driver = { .name = "ad5624r", }, .probe = ad5624r_probe, - .remove = ad5624r_remove, .id_table = ad5624r_id, }; module_spi_driver(ad5624r_driver); From patchwork Wed Oct 23 23:54:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848123 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 64F97204939 for ; Wed, 23 Oct 2024 23:55:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727703; cv=none; b=AOObP8WXTdhSN+wo1udSGVMRZBGu5Z5h5h79WcqEvty+90M3idZGvwj48RIF+RbFsBekSBa9JB+punr1luRbHNLJRdCFAj3fGR7ZaW/DfFS71suleb87h1JEamMXFyDwxWfKAKLs+WOK4v9Hff+oFwiWyndIPQ6yEjaqpmcMzhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727703; c=relaxed/simple; bh=hksfyNtvI8c0zcSVYvltOkcB7HflUdZ/dnRTHZtLyNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D7v5x4NzzfZAlgNrXTYOP03Vh+9ixp0ZhvkTJTSLxSaymHyK09wGsFRxO6DW5NkGp7pG6hlBWFfD55PRRw3fl2Q1FmVK+4T9k4GBl66HOVo7f+pz/KoSdg1+exjsDWq9Sakp9NJrutMFcPVDxa40ANCFBGOVNySPw7PxNUY9Yys= 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.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="z2VZ0kpt" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5ebc52deca0so136035eaf.3 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=gv35L1DhyViOjP07U3kakSwhzWZ1A5Mp61QFuqnMI6eMEXXGPJAWIXiJ5Z1RQnOEyb +MUAC3duTUJL41cCV2VJbn7ogq2R6IKZNbSqLtQLXSZlYkJIq0k5nX7qGWz01VOITdJF 07R8bgkN6VTOBI4+cRzeJcYoXkitv5DJYClaw1Uz+89O30SUilLFmw99U0ojQ1EV7qVH JOA0myNfQA/83HItmwN41YIlb8rDB19tTGofSXp9egS58eyzgc4GBIFkzrTr9k4YaCKW ew+cVEB4krxbIIuu/cv1STUuzlAL1PLD/53rBLnFMoOeP3bHWIRzDh230tAlBpxADt4T rhHw== X-Forwarded-Encrypted: i=1; AJvYcCV20RViSIvyWrzZ4AQy+Dhp8Lkl2MPgPSHQwHPt4XPm8SfQZHOwMIi1G9h+efiq1XyeTVOpldRQazs=@vger.kernel.org X-Gm-Message-State: AOJu0YxOsCG51m+zz6F8H9Q7y00VSon8C4SR7SsnnZzarmgim9E05mv+ Dv80iGNqp2BWhXQWz9dUZwThWWYAZvY0IMqbXZ6opqSfPsTzH3dXAAFvZuPqE/c= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; bool use_intref; @@ -287,63 +285,6 @@ static const struct ad5761_chip_info ad5761_chip_infos[] = { }, }; -static int ad5761_get_vref(struct ad5761_state *st, - const struct ad5761_chip_info *chip_info) -{ - int ret; - - st->vref_reg = devm_regulator_get_optional(&st->spi->dev, "vref"); - if (PTR_ERR(st->vref_reg) == -ENODEV) { - /* Use Internal regulator */ - if (!chip_info->int_vref) { - dev_err(&st->spi->dev, - "Voltage reference not found\n"); - return -EIO; - } - - st->use_intref = true; - st->vref = 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 = regulator_enable(st->vref_reg); - if (ret) { - dev_err(&st->spi->dev, - "Failed to enable voltage reference\n"); - return ret; - } - - ret = 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 = -EIO; - goto disable_regulator_vref; - } - - st->vref = ret / 1000; - st->use_intref = false; - - return 0; - -disable_regulator_vref: - regulator_disable(st->vref_reg); - st->vref_reg = 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 = spi; spi_set_drvdata(spi, iio_dev); - ret = ad5761_get_vref(st, chip_info); - if (ret) - return ret; + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(&spi->dev, ret, + "Failed to get voltage reference value\n"); + if (ret == -ENODEV) { + /* Use Internal regulator */ + if (!chip_info->int_vref) + return dev_err_probe(&spi->dev, -EIO, + "Voltage reference not found\n"); + + st->use_intref = true; + st->vref = 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 = false; + st->vref = ret / 1000; + } if (pdata) voltage_range = pdata->voltage_range; @@ -374,35 +333,22 @@ static int ad5761_probe(struct spi_device *spi) ret = ad5761_spi_set_range(st, voltage_range); if (ret) - goto disable_regulator_err; + return ret; iio_dev->info = &ad5761_info; iio_dev->modes = INDIO_DIRECT_MODE; iio_dev->channels = &chip_info->channel; iio_dev->num_channels = 1; iio_dev->name = spi_get_device_id(st->spi)->name; - ret = iio_device_register(iio_dev); - if (ret) - goto disable_regulator_err; - 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); } static void ad5761_remove(struct spi_device *spi) { struct iio_dev *iio_dev = spi_get_drvdata(spi); - struct ad5761_state *st = iio_priv(iio_dev); iio_device_unregister(iio_dev); - - if (!IS_ERR_OR_NULL(st->vref_reg)) - regulator_disable(st->vref_reg); } static const struct spi_device_id ad5761_id[] = { From patchwork Wed Oct 23 23:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848124 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.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 6682E205E17 for ; Wed, 23 Oct 2024 23:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727705; cv=none; b=FLcpFldLCI/b/2oqAkZsn9LXaIbQMuu7IPHpnHm3CWVERBxFKTCRnY6cXMt5yloxMvrrWBYDPXIb8kMHbGnFX45xKhShqshqwk25RbWCRPsjxKzAQ1YGxxq9fBDQO6bLWn1AzjdqTsms1GizAElv0dUWLjwILnoaTFYsUk0OOnM= 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.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="EUavADAY" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5ebc0c05e25so160601eaf.3 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=Xe0iJVU3I4IrmrOYD22MNixXeezlB3sEcMG/xKd2dgcOYYciMAXumu/xT66VX33Eyw LFyranVxI6bi/QoKd9PA8tGK34lqebUqYJrewEWl/Oy3QVCGGUllrumrw+x3dZxnPIAw yB2UjztDEDCfqnn3MNLGiD3mJ0hJJ2WwLKPcaM50x7pAh90rZX/lPDk0QEeyRb9s7Yvt EHrU/HPdc8C9OzNl/3l7V8SDoKNf7CKhmqQUTvPfZ8Phq/14Cl+qmshfvkDI7b9T92/K Pq8RvgNcMpFLOXnWsBTPi4dOf0xSMnho+hwoLArBFqWM2yLXjypBJZ82a3ldsW6yWBBJ Q8ZA== X-Forwarded-Encrypted: i=1; AJvYcCUzy//R4Tb1uJ2pfpnwCQG8ocCM2/mAG8uwg2flq5QZMxznJyEIFGd7Eye7FHd9B7RAGKI2IfJZWZ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyamHCySIjsBAB0wf95M9HGjDHG6LaCS4Cl33CEsBvLcZNYkAcU AOxeEAHISKin4ib0lJoF/znz2e7qAAZq84m6EqpYmA+P2rZw8U4RUQbMIhtwCqA= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = iio_priv(iio_dev); st->spi = spi; - spi_set_drvdata(spi, iio_dev); ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); if (ret < 0 && ret != -ENODEV) @@ -341,14 +340,7 @@ static int ad5761_probe(struct spi_device *spi) iio_dev->num_channels = 1; iio_dev->name = spi_get_device_id(st->spi)->name; - return iio_device_register(iio_dev); -} - -static void ad5761_remove(struct spi_device *spi) -{ - struct iio_dev *iio_dev = spi_get_drvdata(spi); - - iio_device_unregister(iio_dev); + return devm_iio_device_register(&spi->dev, iio_dev); } static const struct spi_device_id ad5761_id[] = { @@ -365,7 +357,6 @@ static struct spi_driver ad5761_driver = { .name = "ad5761", }, .probe = ad5761_probe, - .remove = ad5761_remove, .id_table = ad5761_id, }; module_spi_driver(ad5761_driver); From patchwork Wed Oct 23 23:54:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13848125 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.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 AEBAD207A26 for ; Wed, 23 Oct 2024 23:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729727708; cv=none; b=YCuzcOEojVrYuhHS4x1xUqaYXcmL2qwkUrroa/K/zjHCcpldciCpaTuT9sV9iC3e/YKdWpuIYIHrGt6oIT9nPdOJZQXeZADUCx+qjWKw4yV23A48I+wq+HtDUM9yCehLjIqbFw7U6ZvcJSCUferHFpDkNUhjU6qVIo2sNFGiDfU= 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.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="EAjHzBmK" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-7181b86a749so211248a34.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=XKE6oEUshcYciwvzsZd0FNHkW5HzLFd1/odlAXnfZ5zb3x60FzLZ0M3jWDse6b2JvV 1KscHbCzWBGHOAK2gry6VezgX/Lrk6+TsBLC3Lrk1W1nKU+b1oAboPv34Qa7KkZ0AF70 kUhO6/reO54AEskoBYUdXxsKbYTzb2AZZ4/eHTOVVcOySalivMrm8zw/sSJZwznkWBge kgc9RbTDWZdcJEKgrByV+V1RRlRGuZ/B7hf17+qgz9el+PNPK3DH4Gd0l7P/FrcKgAsa aiOK+EWyN2znaGm3NVmkgbR7l99AmWywJzf3IbDE8HV4WAZOF1+matdUQWL9j1qO1Ns0 nmBg== X-Forwarded-Encrypted: i=1; AJvYcCU0xTwzDFQrwMNC4t/LjUZA34xOYDaE7sTCaTghgAgwveDoTXo3/EIUw3IE38JzvYmLkoqBhJVVU9M=@vger.kernel.org X-Gm-Message-State: AOJu0YzvpC+fXyibfq4CafDHjboFBF2ZmqjBLApXf3ysqvfILB4iKH8d QcfOF1Ca3nMSWhiKqhz1htGgXQ9iNNCNQUH/iHoQMtjuUujKXFwCbDVpkFBlgvw= 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-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; } -static void ad5770r_disable_regulator(void *data) -{ - struct ad5770r_state *st = 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 = regmap; - st->vref_reg = devm_regulator_get_optional(&spi->dev, "vref"); - if (!IS_ERR(st->vref_reg)) { - ret = regulator_enable(st->vref_reg); - if (ret) { - dev_err(&spi->dev, - "Failed to enable vref regulators: %d\n", ret); - return ret; - } + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); + if (ret < 0 && ret != -ENODEV) + return dev_err_probe(&spi->dev, ret, "Failed to get vref voltage\n"); - ret = devm_add_action_or_reset(&spi->dev, - ad5770r_disable_regulator, - st); - if (ret < 0) - return ret; - - ret = regulator_get_voltage(st->vref_reg); - if (ret < 0) - return ret; - - st->vref = ret / 1000; - } else { - if (PTR_ERR(st->vref_reg) == -ENODEV) { - st->vref = AD5770R_LOW_VREF_mV; - st->internal_ref = true; - } else { - return PTR_ERR(st->vref_reg); - } - } + st->internal_ref = ret == -ENODEV; + st->vref = st->internal_ref ? AD5770R_LOW_VREF_mV : ret / 1000; indio_dev->name = spi_get_device_id(spi)->name; indio_dev->info = &ad5770r_info;