Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp686414ybz; Wed, 22 Apr 2020 06:12:52 -0700 (PDT) X-Google-Smtp-Source: APiQypISZKgrODieDYDBXLAlS1N4QndTeXSs/BjKNueSLFvUWnFpJNhIFDBQVgFRl2nGMIZrDGpP X-Received: by 2002:aa7:d48a:: with SMTP id b10mr20285380edr.284.1587561171772; Wed, 22 Apr 2020 06:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587561171; cv=none; d=google.com; s=arc-20160816; b=OLUtS1E71IZfwK1+p3X+uCQZNXuSYPUSNsdmclQd1BOLE0fi1eUAib+MIRLwAhTleP uQcla0kihXpRo28Fg+XcET7tOlwHso+RJLMDaGiHGTd7Ld5vuxBLIH9Oh0H5lBM9zBIq ruldBfZjdFe98q3Pp7jmQNyGimoLo9vmkGxNRfTLdZXscT0ONv9Tc9G1SV4Pos0A2+ka BN034I+u0cSLfd5KInm4z3g1d3651yxzOPSMRk54n41jcHqGU0ljEvJtmrGCJen8BkUB Y6YyXP79P9BybshEVU5FumdAt10KXevpMbMztNzfK91f9QpYSvGenNr9dPJq4/CdmaSw PqDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o8ZYjk3I5HUzOWotVnd0+m+B88M3hyy1mHjXl9WA6sE=; b=ha43B1OrDvD8Bbz+Fuui/6xtqBmE7x7DlkzcRND6qqPRmGNe3uVFxDJwsEQIaqqrpL 4w0s+TlCgO8Tfwp9PylLXaZgIFU1UEfgO8h2A1RoN9Hys4kri7kiWwmf3oq2J9a9yRMa Luy+/GTuDc0+jfYd0801XPgOSf+1uYHRjkmEQeFaWqB5gODNC9x4lRq+63MAQ3yVBhZ2 +OJKC1VfJpY82IgKmhpeCfRW0iXvj7yq3kz3EoDMV7j3JYLN2QRZTP3I26NU9nbWHpwf dvUwqssSgEH7iHDVPJw6LJzJBroPNXxoXRcs+JVl9lwStaG2Ym9vJyaaIo5hM/23G5Ap CpWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hK+ks0m1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s27si3391848eja.411.2020.04.22.06.12.27; Wed, 22 Apr 2020 06:12:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hK+ks0m1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbgDVNJK (ORCPT + 99 others); Wed, 22 Apr 2020 09:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbgDVNJI (ORCPT ); Wed, 22 Apr 2020 09:09:08 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79502C03C1A9; Wed, 22 Apr 2020 06:09:08 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id u127so2296494wmg.1; Wed, 22 Apr 2020 06:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o8ZYjk3I5HUzOWotVnd0+m+B88M3hyy1mHjXl9WA6sE=; b=hK+ks0m1mz5ue1YKIErT7o3rOfCS1EuBrtA5xlzhOf3ZWXKvueUPSUzTL8yDEgNZ68 JEwczI7+bw+PAS0Jx06/zbLwURBK5gxwQAHdtvUar+aQR4Gfdjh1nselM8ZzczQafAMP Erp5ITRMLwNV7fdJxcQnBcYHHWI8gaowt98d34RouN5a20ujzv4+pnSv5II6JShCB/B+ u5eeS5JKGWD/bMCKGBd7HyaGtWRLM9d0UN74BiaVughzXZx2ysySWWsr8e6+JPElrrda +0ecFlnuf0r4r/2cLijdEs36prNwd5Pyw4etsgYR3/T/1NEAc4/UXGgFhr80oki5qLvs 4o9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o8ZYjk3I5HUzOWotVnd0+m+B88M3hyy1mHjXl9WA6sE=; b=H2CCIeQcaDAtBFolKa/Aw1dIoi3zIbIKLc5hsLJekNpScZTeIb57o4wloP1/s7TuT9 ZRFv87anyl72vA1G4KISJsw97YbJpLMSbXubrp2zWDjwjLFCqDqcgyPljO6ZNI60EgZn l7AAyVKV02zQd/Ged10sbxOd7yk2JQadeIxGyGslMqjAoqLkgzua1xiKjoXfgM2y7VrR FeNCvSH5iMyd11gkYNZZw8QKg0yXyN1bveea4RRRrbw+N6wk1vgcCLLI5on03RPBQTXx i3ZLhBMA4WtSG/LRVhOvwFGJg+dJPYmYLqGKbf7M+y/v0xWk81x2pcdkC5M6JDsJ5Cr8 0lJQ== X-Gm-Message-State: AGi0Pua8iTjSO61rzfGStdU3aC1TYThWBGoHhyf2z6igONRAD7WOKvel 6b/EI8GNaFOZbtnqXFwYx4U= X-Received: by 2002:a7b:c147:: with SMTP id z7mr11227951wmi.52.1587560947204; Wed, 22 Apr 2020 06:09:07 -0700 (PDT) Received: from meru.fronius.com ([2a01:cb18:832e:5f00:8872:7e71:5cf6:8a5b]) by smtp.gmail.com with ESMTPSA id o3sm2064820wru.68.2020.04.22.06.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 06:09:06 -0700 (PDT) From: Mathieu Othacehe To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Mathieu Othacehe Subject: [PATCH v5 1/4] iio: vcnl4000: Factorize data reading and writing. Date: Wed, 22 Apr 2020 15:08:53 +0200 Message-Id: <20200422130856.1722-2-m.othacehe@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200422130856.1722-1-m.othacehe@gmail.com> References: <20200422130856.1722-1-m.othacehe@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factorize data reading in vcnl4000_measure into a vcnl4000_read_data function. Also add a vcnl4000_write_data function. Signed-off-by: Mathieu Othacehe --- drivers/iio/light/vcnl4000.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 58e97462e803..695a81e95d8d 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -215,11 +215,34 @@ static int vcnl4200_init(struct vcnl4000_data *data) return 0; }; +static int vcnl4000_read_data(struct vcnl4000_data *data, u8 data_reg, int *val) +{ + s32 ret; + + ret = i2c_smbus_read_word_data(data->client, data_reg); + if (ret < 0) + return ret; + + *val = be16_to_cpu(ret); + return 0; +} + +static int vcnl4000_write_data(struct vcnl4000_data *data, u8 data_reg, int val) +{ + __be16 be_val; + + if (val > U16_MAX) + return -ERANGE; + + be_val = cpu_to_be16(val); + return i2c_smbus_write_word_data(data->client, data_reg, be_val); +} + + static int vcnl4000_measure(struct vcnl4000_data *data, u8 req_mask, u8 rdy_mask, u8 data_reg, int *val) { int tries = 20; - __be16 buf; int ret; mutex_lock(&data->vcnl4000_lock); @@ -246,13 +269,11 @@ static int vcnl4000_measure(struct vcnl4000_data *data, u8 req_mask, goto fail; } - ret = i2c_smbus_read_i2c_block_data(data->client, - data_reg, sizeof(buf), (u8 *) &buf); + ret = vcnl4000_read_data(data, data_reg, val); if (ret < 0) goto fail; mutex_unlock(&data->vcnl4000_lock); - *val = be16_to_cpu(buf); return 0; -- 2.26.0