From patchwork Sun Nov 11 14:15:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10677669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AF73139B for ; Sun, 11 Nov 2018 14:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BBB02AA5A for ; Sun, 11 Nov 2018 14:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 004902AA61; Sun, 11 Nov 2018 14:16:00 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 9ACDA2AA5A for ; Sun, 11 Nov 2018 14:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728237AbeKLAEl (ORCPT ); Sun, 11 Nov 2018 19:04:41 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38256 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728098AbeKLAEk (ORCPT ); Sun, 11 Nov 2018 19:04:40 -0500 Received: by mail-wr1-f67.google.com with SMTP id e3-v6so6566672wrs.5 for ; Sun, 11 Nov 2018 06:15:59 -0800 (PST) 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=QW4ISB8SB087o+Raf/rVBBmoxBDw/S7v7t7WpGBFHV4=; b=n0Sbeyt54AVp6goIWUbcP1/h7DF5fAiCnSBLFlSPghCwX/QPSBdZVAnGY/kV9vrILO mYoQbpnC6H2Stzv9qjiG5LYYQHryJ6BLzxb7P26rYtGzwd7uuXReqgwUSqwULh5Q/5ii NcartQpEJwesR7jvatW5ZT6YtQ11EtBHXFP1aSr7XpqaObwooetfHEb9P8trPEwACGga XbruhZYfdIJBtFbXcWOsE2mJXSZ8+Dpmq79JyhaWJIb5CsVxFvY/oGzSRDEq8822BWs9 xRagLRuyBObZuq379akvR9SNMlfQ7f31Q8HE89+tA3wQpw0683X4GApD+UGJzSkmGgKz 3L+A== X-Gm-Message-State: AGRZ1gLZlFNSQiLh8y00yAcTGZf2yTnw/ZSRKUQuKWgeQaFkamVi2+ge SiiMrKpsfFAuhYlevHKxOmzEbQ== X-Google-Smtp-Source: AJdET5caUVM+faGMA9cOxCPE87mvOTKTjMeQzBB4GYYDwi3uFy1RhPYs9iNFygoZYs980XBaTg0C4g== X-Received: by 2002:adf:de0b:: with SMTP id b11-v6mr13787136wrm.119.1541945758522; Sun, 11 Nov 2018 06:15:58 -0800 (PST) Received: from localhost.localdomain ([151.66.8.224]) by smtp.gmail.com with ESMTPSA id w11-v6sm15861685wrr.96.2018.11.11.06.15.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 06:15:58 -0800 (PST) From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 7/9] iio: imu: st_lsm6dsx: add st_lsm6dsx_push_tagged_data routine Date: Sun, 11 Nov 2018 15:15:34 +0100 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 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 Introduce st_lsm6dsx_push_tagged_data routine to push samples to iio buffers. st_lsm6dsx_push_tagged_data will be reused adding hw fifo support to st_lsm6dsx i2c embedded controller in order to improve code readability Signed-off-by: Lorenzo Bianconi --- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index 6a379767b919..4e7ff370cbe0 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -453,6 +453,31 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) return read_len; } +static int +st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, + u8 *data, s64 ts) +{ + struct st_lsm6dsx_sensor *sensor; + struct iio_dev *iio_dev; + + switch (tag) { + case ST_LSM6DSX_GYRO_TAG: + iio_dev = hw->iio_devs[ST_LSM6DSX_ID_GYRO]; + break; + case ST_LSM6DSX_ACC_TAG: + iio_dev = hw->iio_devs[ST_LSM6DSX_ID_ACC]; + break; + default: + return -EINVAL; + } + + sensor = iio_priv(iio_dev); + iio_push_to_buffers_with_timestamp(iio_dev, data, + ts + sensor->ts_ref); + + return 0; +} + /** * st_lsm6dsx_read_tagged_fifo() - LSM6DSO read FIFO routine * @hw: Pointer to instance of struct st_lsm6dsx_hw. @@ -508,8 +533,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) ST_LSM6DSX_SAMPLE_SIZE); tag = hw->buff[i] >> 3; - switch (tag) { - case ST_LSM6DSX_TS_TAG: + if (tag == ST_LSM6DSX_TS_TAG) { /* * hw timestamp is 4B long and it is stored * in FIFO according to this schema: @@ -526,19 +550,9 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) if (!reset_ts && ts >= 0xffff0000) reset_ts = true; ts *= ST_LSM6DSX_TS_SENSITIVITY; - break; - case ST_LSM6DSX_GYRO_TAG: - iio_push_to_buffers_with_timestamp( - hw->iio_devs[ST_LSM6DSX_ID_GYRO], - iio_buff, gyro_sensor->ts_ref + ts); - break; - case ST_LSM6DSX_ACC_TAG: - iio_push_to_buffers_with_timestamp( - hw->iio_devs[ST_LSM6DSX_ID_ACC], - iio_buff, acc_sensor->ts_ref + ts); - break; - default: - break; + } else { + st_lsm6dsx_push_tagged_data(hw, tag, iio_buff, + ts); } } }