From patchwork Fri Oct 27 19:45:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Meerwald-Stadler X-Patchwork-Id: 10030547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E4F616034B for ; Fri, 27 Oct 2017 19:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2F9528F52 for ; Fri, 27 Oct 2017 19:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7BE828F5D; Fri, 27 Oct 2017 19:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60C7F28F52 for ; Fri, 27 Oct 2017 19:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932488AbdJ0Tp6 (ORCPT ); Fri, 27 Oct 2017 15:45:58 -0400 Received: from ns.pmeerw.net ([84.19.176.117]:46976 "EHLO vps.pmeerw.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932485AbdJ0Tp6 (ORCPT ); Fri, 27 Oct 2017 15:45:58 -0400 Received: by vps.pmeerw.net (Postfix, from userid 113) id 0E8FBE24F9; Fri, 27 Oct 2017 21:45:56 +0200 (CEST) Received: from sirene2.lan (unknown [85.13.17.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pmeerw@vps.pmeerw.net) by vps.pmeerw.net (Postfix) with ESMTPSA id A1E08E0054; Fri, 27 Oct 2017 21:45:48 +0200 (CEST) From: Peter Meerwald-Stadler To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, Peter Meerwald-Stadler , Matt Ranostay Subject: [PATCH v2 11/13] iio: health: max30102: Prepare for copying varying number of measurements Date: Fri, 27 Oct 2017 21:45:41 +0200 Message-Id: <1509133543-4597-12-git-send-email-pmeerw@pmeerw.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509133543-4597-1-git-send-email-pmeerw@pmeerw.net> References: <1509133543-4597-1-git-send-email-pmeerw@pmeerw.net> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current code assumes always 2 measurements (6 bytes) have to be copied, prepare for more flexibility Signed-off-by: Peter Meerwald-Stadler Cc: Matt Ranostay Acked-by: Matt Ranostay --- drivers/iio/health/max30102.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c index 1c7fe63..86058f0 100644 --- a/drivers/iio/health/max30102.c +++ b/drivers/iio/health/max30102.c @@ -58,7 +58,7 @@ enum max3012_led_idx { #define MAX30102_REG_FIFO_OVR_CTR 0x05 #define MAX30102_REG_FIFO_RD_PTR 0x06 #define MAX30102_REG_FIFO_DATA 0x07 -#define MAX30102_REG_FIFO_DATA_ENTRY_LEN 6 +#define MAX30102_REG_FIFO_DATA_BYTES 3 #define MAX30102_REG_FIFO_CONFIG 0x08 #define MAX30102_REG_FIFO_CONFIG_AVG_4SAMPLES BIT(1) @@ -198,6 +198,11 @@ static inline int max30102_fifo_count(struct max30102_data *data) return 0; } +#define MAX30102_COPY_DATA(i) \ + memcpy(&data->processed_buffer[(i)], \ + &buffer[(i) * MAX30102_REG_FIFO_DATA_BYTES], \ + MAX30102_REG_FIFO_DATA_BYTES) + static int max30102_read_measurement(struct max30102_data *data) { int ret; @@ -205,13 +210,13 @@ static int max30102_read_measurement(struct max30102_data *data) ret = i2c_smbus_read_i2c_block_data(data->client, MAX30102_REG_FIFO_DATA, - MAX30102_REG_FIFO_DATA_ENTRY_LEN, + 2 * MAX30102_REG_FIFO_DATA_BYTES, buffer); - memcpy(&data->processed_buffer[0], &buffer[0], 3); - memcpy(&data->processed_buffer[1], &buffer[3], 3); + MAX30102_COPY_DATA(0); + MAX30102_COPY_DATA(1); - return (ret == MAX30102_REG_FIFO_DATA_ENTRY_LEN) ? 0 : -EINVAL; + return (ret == 2 * MAX30102_REG_FIFO_DATA_BYTES) ? 0 : -EINVAL; } static irqreturn_t max30102_interrupt_handler(int irq, void *private)