From nobody Thu Dec 26 12:42:12 2024 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 0F206150981 for ; Thu, 31 Oct 2024 07:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730359081; cv=none; b=Fq5xkP80JlprZfSKffTLldG85ZuEOZsCVEraZVrj8nQjLeADpq8PW0pfbJn43zM3uaB9oS9S2OCXznI7TxlZ0AUQx8PyHJNefvitvwtdt84dtifvh4Puq9j7kLUB0qprhXgY8Tk4QJtx3KL1hVHWiR1ryPm88CPFyZ//9Q9D/No= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730359081; c=relaxed/simple; bh=hRRz6Z3zhjYmY795aPCQsEcsvIGIKzWS3nJb+c+XP1I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lxCrs7TsRmFR7Wb2QBhbp44IRdXfCHqf3AqEituGPz9G3XvjEOEXfHPlUYf+RrjN5GIamYLR7uBQ895DiywV7ulmY3hFOFkdqqmi+X188Mm4wiFBviRxYP/kLDDv40q9qBuoxq4ckqGwUqfBSuiNu7mq2yN10KJb+VccgLBW5UE= 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=X9h3U7uu; arc=none smtp.client-ip=209.85.128.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="X9h3U7uu" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43155abaf0bso5081235e9.0 for ; Thu, 31 Oct 2024 00:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730359076; x=1730963876; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BeRlMEUtBMXjfsJVHTeMu8lQ8IK1457+K1awnOuwaZk=; b=X9h3U7uu0eCiI6Ccz3GK3TAbR2t5XRQCjn4GLKQkgP+IVY5+eLrbgCKzEaZX7tncxb lTWcL1iU1LwTxsmolYHjvfTWPVmrmXPlsrB70lNcaBoMU/8Zl8HDW5YFEg5t4f1zO7+u GZ4ZbfYU04vyEaMKn12pkm3nM1l4gRGJO450xptGZ1n7d9rcFfBRpBSHRfHCxzZUtKz1 E11mqt2Nvcd8KDMInp0hqOMCdtv6oTXwQjXk/BUNermy57l0a8Cx8xm7PlRHWwV8Ww6+ rmwfWjLDXcC0hYEtwWZaarpXwMARe8UlDsD8OdbBDfx3yEKqptod1V4fE+UzB2bKDUgg nOBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730359076; x=1730963876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BeRlMEUtBMXjfsJVHTeMu8lQ8IK1457+K1awnOuwaZk=; b=v4uxSwkw9u949Vpl0q6x7SrynN4BUZireoCHd/xH57G6W0QYIGRVnxRz8TAjp/8y0b Uq1Kg5yD9D9o5ed0dbuLIquxbU0Ff9xyyIocqbHTjSev78ppp+l5z+mAhICiHetu2v37 pEuLzESePNHeEDTleev6qA7k+SXnx+gmPWwGXNz+x2Bpqw+h8JO9CKSHP6pg45zxz7J7 ULWqYDQ860qz10QxyZKj4g7+PPy66D6CW5aVXfO7PF82v6GUSn7cmIdrzQYm3bJTPTSG SHxFvGgckAzPyxJ05uBQqqH9Ri10gXop6AggTeFD5yJsG7qNrDPUDtyEkI+fw4Mwemro X2sw== X-Forwarded-Encrypted: i=1; AJvYcCUPF7DYQe5iuIhJBpeYmqAtAje+1uAiJPHlIA0A7Fwgr5J5taNylTm6mf2OeVWNuIH1emNUJPm3DNFcOu0=@vger.kernel.org X-Gm-Message-State: AOJu0YzxHn8HaY6o7wHLvD4vpQO3tkt07X/sL2OWCnGu8yokZxOxxPkV cIg+DQe9a3jM3B6sHcBY8zC9PiBThaEEkS1+gtU3EgrwtQ3KC8cQ4RaPVZuHSgg= X-Google-Smtp-Source: AGHT+IFXvK55d0CGj9OJo4gCkJhWNNTnKajsdZ89N392DRFUQyDEd53HDsOaPmhrhw5rLrryeaaweQ== X-Received: by 2002:a05:600c:3556:b0:431:5f1b:a7c4 with SMTP id 5b1f17b1804b1-4319ad29d0bmr169902125e9.34.1730359076424; Thu, 31 Oct 2024 00:17:56 -0700 (PDT) Received: from axelh-ThinkPad-T450s.home (lfbn-nic-1-251-169.w2-15.abo.wanadoo.fr. [2.15.94.169]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e694sm1187547f8f.86.2024.10.31.00.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 00:17:55 -0700 (PDT) From: ahaslam@baylibre.com To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Axel Haslam Subject: [PATCH v3 5/6] iio: dac: ad5791: Use devm_regulator_get_enable_read_voltage Date: Thu, 31 Oct 2024 08:17:45 +0100 Message-Id: <20241031071746.848694-6-ahaslam@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031071746.848694-1-ahaslam@baylibre.com> References: <20241031071746.848694-1-ahaslam@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Axel Haslam Simplify probe by using of the devm_regulator_get_enable_read_voltage. Suggested-by: David Lechner Reviewed-by: David Lechner Signed-off-by: Axel Haslam --- drivers/iio/dac/ad5791.c | 58 ++++++++++------------------------------ 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c index c5d4d755d57a..92d47e766fd3 100644 --- a/drivers/iio/dac/ad5791.c +++ b/drivers/iio/dac/ad5791.c @@ -360,32 +360,6 @@ static int ad5791_probe(struct spi_device *spi) if (IS_ERR(st->gpio_ldac)) return PTR_ERR(st->gpio_ldac); =20 - st->reg_vdd =3D devm_regulator_get(&spi->dev, "vdd"); - if (!IS_ERR(st->reg_vdd)) { - ret =3D regulator_enable(st->reg_vdd); - if (ret) - return ret; - - ret =3D regulator_get_voltage(st->reg_vdd); - if (ret < 0) - goto error_disable_reg_pos; - - pos_voltage_uv =3D ret; - } - - st->reg_vss =3D devm_regulator_get(&spi->dev, "vss"); - if (!IS_ERR(st->reg_vss)) { - ret =3D regulator_enable(st->reg_vss); - if (ret) - goto error_disable_reg_pos; - - ret =3D regulator_get_voltage(st->reg_vss); - if (ret < 0) - goto error_disable_reg_neg; - - neg_voltage_uv =3D ret; - } - st->pwr_down =3D true; st->spi =3D spi; =20 @@ -395,7 +369,17 @@ static int ad5791_probe(struct spi_device *spi) use_rbuf_gain2 =3D device_property_read_bool(&spi->dev, "adi,rbuf-gain2-en"); =20 - if (!IS_ERR(st->reg_vss) && !IS_ERR(st->reg_vdd)) { + pos_voltage_uv =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vdd= "); + if (pos_voltage_uv < 0 && pos_voltage_uv !=3D -ENODEV) + return dev_err_probe(&spi->dev, pos_voltage_uv, + "failed to get vdd voltage\n"); + + neg_voltage_uv =3D devm_regulator_get_enable_read_voltage(&spi->dev, "vss= "); + if (neg_voltage_uv < 0 && neg_voltage_uv !=3D -ENODEV) + return dev_err_probe(&spi->dev, neg_voltage_uv, + "failed to get vss voltage\n"); + + if (neg_voltage_uv >=3D 0 && pos_voltage_uv >=3D 0) { st->vref_mv =3D (pos_voltage_uv + neg_voltage_uv) / 1000; st->vref_neg_mv =3D neg_voltage_uv / 1000; } else if (pdata) { @@ -411,7 +395,7 @@ static int ad5791_probe(struct spi_device *spi) } else { ret =3D ad5791_spi_write(st, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET); if (ret) - goto error_disable_reg_neg; + return dev_err_probe(&spi->dev, ret, "fail to reset\n"); } =20 st->chip_info =3D spi_get_device_match_data(spi); @@ -425,7 +409,7 @@ static int ad5791_probe(struct spi_device *spi) ret =3D ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl | AD5791_CTRL_OPGND | AD5791_CTRL_DACTRI); if (ret) - goto error_disable_reg_neg; + return dev_err_probe(&spi->dev, ret, "fail to write ctrl register\n"); =20 spi_set_drvdata(spi, indio_dev); indio_dev->info =3D &ad5791_info; @@ -435,30 +419,16 @@ static int ad5791_probe(struct spi_device *spi) indio_dev->name =3D st->chip_info->name; ret =3D iio_device_register(indio_dev); if (ret) - goto error_disable_reg_neg; + return dev_err_probe(&spi->dev, ret, "unable to register iio device\n"); =20 return 0; - -error_disable_reg_neg: - if (!IS_ERR(st->reg_vss)) - regulator_disable(st->reg_vss); -error_disable_reg_pos: - if (!IS_ERR(st->reg_vdd)) - regulator_disable(st->reg_vdd); - return ret; } =20 static void ad5791_remove(struct spi_device *spi) { struct iio_dev *indio_dev =3D spi_get_drvdata(spi); - struct ad5791_state *st =3D iio_priv(indio_dev); =20 iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg_vdd)) - regulator_disable(st->reg_vdd); - - if (!IS_ERR(st->reg_vss)) - regulator_disable(st->reg_vss); } =20 static const struct of_device_id ad5791_of_match[] =3D { --=20 2.34.1