Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4470977ybz; Tue, 21 Apr 2020 00:57:19 -0700 (PDT) X-Google-Smtp-Source: APiQypJokKVgXQk8EZhfGJdsFALECRTzgFNKQVhcEcHfbw5oYcZVHWVRzpE+BU2/nH083xBPjEw3 X-Received: by 2002:a17:906:7f13:: with SMTP id d19mr20105873ejr.57.1587455839644; Tue, 21 Apr 2020 00:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587455839; cv=none; d=google.com; s=arc-20160816; b=vFJJPS0WLQ3U+THo3aBLzI6cLT0yvewp5Lklk7IrfAwOD91vhvSkGU3CSI5OaWGL0Q siH2UQmIjjxXcWztm2kyR3CT76GzLCTGN9HYRLKL0VTakqeVK8DLK6pHWh0gdzA7G1Do 1bC2VEi498CIWnS3Bojxp9NKq5H2d9Ws0VNRbPB6pxsMUOHwGJR/8if5Di37jvkV6+K/ 3Fw+E4s6CXSccAHwU1w1atE4EV1tPocCHgPH5FvIdQjKbD7lhk3UjlIA3ORDvzlRCK2Z 6CPqZz0C84oELD2r9MJ7RcdFNjeN92XGb2u2D0Mo5O6rQWKmlH56SdeABOS9s4MS4sbQ AxSA== 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=Ft7Z4E7wpjgL+bVPOWKXIKxcwd5F2fYmMZS120UmavCOb3Yez5mHfqtVVVWPNBAEmI ZeRCQ2C7yupneZDfAJtzEABKJBEZJKFminNu6bcvMESmar89f9UwyHNI/YLuYFwpS34C F3jx2wjmfHCwW+7GuFY6GL1SBSJFpNlebN46boAMhf9GGrnB4VGJlK3uyXl7PVAwQRK0 IJhEXl8QiOOIJ8M3jEbcc7XITgOb+6zhGoQO+ohZUYyP9mYr0y7McayFAjvDnfWlIMLu YDIvtuw2WeYx2YrhluJB04p0jfM+alGS+VT+Cgv2yGB8ydaMOd3AfQRhuCZgkUy2FlU4 FhbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u5uuKYhZ; 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 f19si1140922edm.263.2020.04.21.00.56.57; Tue, 21 Apr 2020 00:57:19 -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=u5uuKYhZ; 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 S1728314AbgDUHzp (ORCPT + 99 others); Tue, 21 Apr 2020 03:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728261AbgDUHzm (ORCPT ); Tue, 21 Apr 2020 03:55:42 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B861CC061A0F; Tue, 21 Apr 2020 00:55:41 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id f13so15290138wrm.13; Tue, 21 Apr 2020 00:55:41 -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=u5uuKYhZQUAbXG08+ryOgldwFlo7l9hFtEjLupf2p5XUXKMH0ikRBZ/rrDQodbS8fz DbrcrcJl9avb97wqaZQLDIDPeQ28J9xMHnwHhk5ah94lvRF0r9zJDao4bZwzi1C/1a6S YNJ6VezgY62/8uxeQ3sLN8f/w+IkMm3L8mA++ZtuuH9s0JiNSsZXMVtsriNICRPorm2d LEKLj1AMkjgoq5qOuR63nyjObaiy7l05Rq7kh8ip+72D7ByF90gPg/6BKcumjFXat4sr kJ7sQw4U0pdnKzeCILMD4F1D2jpcMggLQwwzrMWw/eHbhVByWvI0/zj38TCZa4Jpk56Q rVQQ== 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=OEUAjHof19B9RfuCikKD8Eg9oJpx73hsj4MKhg0PBQW2DyysJjyYsC4ZPFO/4idZ4K jn23x5aAQjfNzn8fOzC8T6cLoCfz6yZiN4qtmqtMCBF7dQZgOQQ7vL+TMASh9P2BMRM1 017WG8lCcnLDH38VrobxJOg4h2eFV2JY/mhU+9rAWrICUrq3EV0gKQfBqtmjnvWC7qRp pzPpbsakpw2qpcUp7FZ3phtIvLWRScHpVgtWoaYnGtBVskGE1plCFZ1oUSiowHsBZq6g 4mM1ymiaKXSRn18cy8/Moqdlo2RChDKEk6MzJL8iylRM6KHmjwB+clUGbm1hslEf6UOc tnIg== X-Gm-Message-State: AGi0PuZyPF0r1JsHwhgzYnLxiG0lMBPKhqB8KVvltiIj5RJ+yb4+k5ON kdmbeFFm5CXLxKRAAR61dZo= X-Received: by 2002:adf:ee88:: with SMTP id b8mr21941119wro.93.1587455740528; Tue, 21 Apr 2020 00:55:40 -0700 (PDT) Received: from meru.fronius.com ([2a01:cb18:832e:5f00:f9a2:4:b043:a3fb]) by smtp.gmail.com with ESMTPSA id c190sm2514510wme.10.2020.04.21.00.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 00:55:39 -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 v4 1/4] iio: vcnl4000: Factorize data reading and writing. Date: Tue, 21 Apr 2020 09:55:29 +0200 Message-Id: <20200421075532.19192-2-m.othacehe@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200421075532.19192-1-m.othacehe@gmail.com> References: <20200421075532.19192-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