Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1688270lqa; Mon, 29 Apr 2024 16:41:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXfDypDLhd/BSqytlzj3P0JN7YmW9h0XreL9C0Pvky8CFtuq3IDcsU7oQgPhRv1Dq66Q2ms/7QY4ZURXah8kfA1uLd0xV8RSwc2XPVWeg== X-Google-Smtp-Source: AGHT+IG6WTlh0VpQ3XNF7QMXeflLpQ3ig2ppkeVJr1WA4M/Bh7A0gT/KFaxzzkdknfFs0+ag4RUh X-Received: by 2002:a05:622a:345:b0:43a:db8c:50de with SMTP id r5-20020a05622a034500b0043adb8c50demr5724568qtw.44.1714434097385; Mon, 29 Apr 2024 16:41:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714434097; cv=pass; d=google.com; s=arc-20160816; b=rCNWwQropvjNCFtdl/CG5zTeQRUprjGl7MHFr0PgGuBSyRqx3Cm3mmnGFJbqkU73bc ioL2uRx7ZF9+HvIaRZNqnHoICirasGyJRiB9yG0SRgBxrWe0cH3VXLh7WE0D5Kx0H2eD sU+DrrkEugDwOAl36t1nCA7xHcPVIfehigbdi5iZQG3J/8rljoZpIoeoKkiJc8pRSPIz hoFNtTlzw9E6FJsYoMsb7lAV2PK1+yJFI20cs++pK/t0cdq7fGHwsitVG5OMWv55L/OT DBWTQmEERDJgYUlkt3iEvHkq8q4L6nMnoOiMj9PdN0ORmAYzfh7UoUlp0qJAUHaGhGa+ L8vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fCu+RSrpWOgpCZSyomahXHu6xaI4OOMemllTcAyzYVE=; fh=IHOtDp9i/j2kpd6IQPZ6/OIsvBAdIDTkcoSzQ2m6hTU=; b=OUHArxZS1o5KNHvUpkgApdKCAFeX9feN/dszHgJt5+HRIAcGUQHp+aYjRHFC2nIaz7 dNE5BTyLxgfXTVi0BFh9QhJbwUtJRAlbtiHvPSgPW7ztAXr1W3N1CDcAO7p6eHHPPmH/ oSbVFzW8qYRbSpjp1r8xzZXphMzCRuQZEpc/ezRVtfjaiEkZ2yAkXzR91TcEI5L0KCS1 jMmzZvCB+kO5Se886gCHeSgjfer9vNIEJGAkfbwdCQdezfuffPbBgLIBZOETwQ/4uDoU sxXx6jund0fevmp5jW9lkc2BMD/53TYVHLnVYEABj3xWpgQ+n0/7hCM8tQWgwU+0GFuc PGvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=QHghTFco; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-163161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163161-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ge10-20020a05622a5c8a00b0043b0b8a9df1si2021196qtb.65.2024.04.29.16.41.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 16:41:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=QHghTFco; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-163161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163161-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 13BFF1C215B5 for ; Mon, 29 Apr 2024 23:41:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF8EF1A0AE7; Mon, 29 Apr 2024 23:40:41 +0000 (UTC) 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="QHghTFco" Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19BAD199E97 for ; Mon, 29 Apr 2024 23:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714434039; cv=none; b=Egfc9fHEx5U7prB7TtYY9Jig4+MDEqSJ8ZukflSWl5mcReZJacdIA8X6pWXnoxB1f4X/UcpUwUfLKC96TUR1m4dJ64DI/AbObMRJT7G42m9ccFlH2smzGMTYuCDlCnINq3NOuPMc0oPqTyBHVKvdSHbwnWWpM0srO7pQvS2+QOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714434039; c=relaxed/simple; bh=FxpiwVEGKQscfaIrKjDK4V3875jn6xFnM8mM/zDKOGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ko6rZPah8PP/CLs6blcK9dNyBPCHJZcbY+kF37T04tOCmKfRu8RB18FEAruH3EQ0m5HAnbL/J3BreJ7epsrBZh9WUC8sr21h7tVFnkTi9sss7s3y3F3lpx8Bn95irZ/M4+ExZwNGXR2oqM8SvRooKzCCX0QMdgyOAVJhL5znS20= 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=QHghTFco; arc=none smtp.client-ip=209.85.167.178 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 Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3c70d8bb618so2346261b6e.2 for ; Mon, 29 Apr 2024 16:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1714434036; x=1715038836; 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=fCu+RSrpWOgpCZSyomahXHu6xaI4OOMemllTcAyzYVE=; b=QHghTFco/zn/C7GqSoc3lNXuq0jTvpQ/JqEjfbqDbonhTVUtLd3/fJLiZsp8U6rYOB 5a/YiM7+GorUDXJvIJULOD7ah1COUSyfeikBmReiLOrTspre3k2kMG5MiRESOwmesINN wDnxn4VlCPBMHyxpv0dMJK1/6omEHRW0Fz85mFNfNpKkVb/7qFjbANf5QKwj9byr1JRB FLsL/H5ng6I4BGADhWywr8ai9lNbMuvay6F4msrhs3IhwnsNK606l6tA3WZxDIvSLlkp dRY3ypyHTch7KjBrxHf8InljEOn/OV3hshj0u6/om1HUbFoj2KF+0/m1EVoNCnbXtFPq H6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714434036; x=1715038836; 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=fCu+RSrpWOgpCZSyomahXHu6xaI4OOMemllTcAyzYVE=; b=MqEFBdt9HHNN6jH9dMlreefD3gtbL6btM0bqZkkeQxViubqtm5QcM3zZRgshDZmYob 6kLo3efueGLa7D7wDP3N6NJoZT2b5J52DSvghjMRhmrq+xQExqJti2Onf77hV8GxxHb7 4H5dlRQuwNHam2M+o725zOL82xv+ZBMN3gYOJ7c3Yopyb3JIGHUAy3wGvsR7j6CpTCjC isT8oZr09zvKaU8hq+ss5q3xdpZikfk3aTyTwj/pD/hD7oLqztKwqt05ZfUB4nUOog6u wiZe3Pmzo73XYD/jp/9wwbRqOSsfpZBnjKAfEyzfLvsYeuu3SiR6vMKE0NSKfMgTFOCo nPiQ== X-Forwarded-Encrypted: i=1; AJvYcCWXj6g2RsstsktaiItNM836896A1isQxlTHHl7XbtMYorzMMiSSj7bxZAng4vW0NnLWJz7XV6P38FQD8piJkTlZuvY+u/fvhtXnHA+m X-Gm-Message-State: AOJu0YxBCz1IjcePCfz8lRSPZUbf3j+AR7oVopvZAUpWUaMW5Fqgsi1n +A6kXK/TokEOplPohRDfcojtFOg27JCCTqOa2MEG7b6ENreri+bLy3oTaH4nGLI= X-Received: by 2002:a05:6870:d911:b0:232:fb5e:c23b with SMTP id gq17-20020a056870d91100b00232fb5ec23bmr16803310oab.26.1714434036129; Mon, 29 Apr 2024 16:40:36 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id hp22-20020a0568709a9600b0023b58aa20afsm2144508oab.25.2024.04.29.16.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 16:40:35 -0700 (PDT) From: David Lechner To: Liam Girdwood , Mark Brown , Jean Delvare , Guenter Roeck , Jonathan Cameron , Dmitry Torokhov Cc: David Lechner , Jonathan Corbet , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Antoniu Miclaus , Greg Kroah-Hartman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org, Jonathan Cameron Subject: [PATCH v2 2/7] hwmon: (adc128d818) Use devm_regulator_get_enable_read_voltage() Date: Mon, 29 Apr 2024 18:40:10 -0500 Message-ID: <20240429-regulator-get-enable-get-votlage-v2-2-b1f11ab766c1@baylibre.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com> References: <20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com> 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" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: 8bit We can reduce boilerplate code and eliminate the driver remove() function by using devm_regulator_get_enable_read_voltage(). A new external_vref flag is added since we no longer have the handle to the regulator to check if it is present. Reviewed-by: Jonathan Cameron Signed-off-by: David Lechner --- v2 changes: * rename to devm_regulator_get_enable_read_voltage() * use vref instead of err for return value * simplify last error check to return PTR_ERR directly --- drivers/hwmon/adc128d818.c | 57 ++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c index 46e3c8c50765..2a35acb011eb 100644 --- a/drivers/hwmon/adc128d818.c +++ b/drivers/hwmon/adc128d818.c @@ -58,7 +58,6 @@ static const u8 num_inputs[] = { 7, 8, 4, 6 }; struct adc128_data { struct i2c_client *client; - struct regulator *regulator; int vref; /* Reference voltage in mV */ struct mutex update_lock; u8 mode; /* Operation mode */ @@ -389,7 +388,7 @@ static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info) return 0; } -static int adc128_init_client(struct adc128_data *data) +static int adc128_init_client(struct adc128_data *data, bool external_vref) { struct i2c_client *client = data->client; int err; @@ -408,7 +407,7 @@ static int adc128_init_client(struct adc128_data *data) regval |= data->mode << 1; /* If external vref is selected, configure the chip to use it */ - if (data->regulator) + if (external_vref) regval |= 0x01; /* Write advanced configuration register */ @@ -430,9 +429,9 @@ static int adc128_init_client(struct adc128_data *data) static int adc128_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct regulator *regulator; struct device *hwmon_dev; struct adc128_data *data; + bool external_vref; int err, vref; data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL); @@ -440,20 +439,15 @@ static int adc128_probe(struct i2c_client *client) return -ENOMEM; /* vref is optional. If specified, is used as chip reference voltage */ - regulator = devm_regulator_get_optional(dev, "vref"); - if (!IS_ERR(regulator)) { - data->regulator = regulator; - err = regulator_enable(regulator); - if (err < 0) - return err; - vref = regulator_get_voltage(regulator); - if (vref < 0) { - err = vref; - goto error; - } - data->vref = DIV_ROUND_CLOSEST(vref, 1000); - } else { + vref = devm_regulator_get_enable_read_voltage(dev, "vref"); + if (vref == -ENODEV) { + external_vref = false; data->vref = 2560; /* 2.56V, in mV */ + } else if (vref < 0) { + return vref; + } else { + external_vref = true; + data->vref = DIV_ROUND_CLOSEST(vref, 1000); } /* Operation mode is optional. If unspecified, keep current mode */ @@ -461,13 +455,12 @@ static int adc128_probe(struct i2c_client *client) if (data->mode > 3) { dev_err(dev, "invalid operation mode %d\n", data->mode); - err = -EINVAL; - goto error; + return -EINVAL; } } else { err = i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV); if (err < 0) - goto error; + return err; data->mode = (err >> 1) & ADC128_REG_MASK; } @@ -476,31 +469,16 @@ static int adc128_probe(struct i2c_client *client) mutex_init(&data->update_lock); /* Initialize the chip */ - err = adc128_init_client(data); + err = adc128_init_client(data, external_vref); if (err < 0) - goto error; + return err; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, adc128_groups); - if (IS_ERR(hwmon_dev)) { - err = PTR_ERR(hwmon_dev); - goto error; - } + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); return 0; - -error: - if (data->regulator) - regulator_disable(data->regulator); - return err; -} - -static void adc128_remove(struct i2c_client *client) -{ - struct adc128_data *data = i2c_get_clientdata(client); - - if (data->regulator) - regulator_disable(data->regulator); } static const struct i2c_device_id adc128_id[] = { @@ -522,7 +500,6 @@ static struct i2c_driver adc128_driver = { .of_match_table = of_match_ptr(adc128_of_match), }, .probe = adc128_probe, - .remove = adc128_remove, .id_table = adc128_id, .detect = adc128_detect, .address_list = normal_i2c, -- 2.43.2