From patchwork Wed Sep 27 19:29:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 9974605 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 37B3860375 for ; Wed, 27 Sep 2017 19:29:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27EA8292E5 for ; Wed, 27 Sep 2017 19:29:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CCB7292EA; Wed, 27 Sep 2017 19:29:38 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 8DA24292E5 for ; Wed, 27 Sep 2017 19:29:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751436AbdI0T3h (ORCPT ); Wed, 27 Sep 2017 15:29:37 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35311 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751073AbdI0T3g (ORCPT ); Wed, 27 Sep 2017 15:29:36 -0400 Received: by mail-wr0-f195.google.com with SMTP id n64so6171124wrb.2 for ; Wed, 27 Sep 2017 12:29:35 -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; bh=PBCGVhdgZqsy2hcHwZA7Jx0iL7SNgMzDbk0sLtfudCM=; b=JvVHe7QV8kFnt5znyhK+l604nZYWFYA38QW5GSUBkypvShjR4jT77pvzCsvDlMKGcP 7LnjnBEKX2IKGgTfZ5DxVvQ2AFy+grTvfk7eqOqZm8+aY2a6Qh2evkG7HV7w4t48YmMB y0X/tisIrt/bM7OB01uZkBoydgqccuPa9qvUa9djlYwymRUCDUW33oYh3H0WBBN8Pqcg ZE8cumAX6O2ky6GptJoD9ZePqjwEp+J2UZRKzAT/5re0bF3WH7vEXQyrr3395LVVhC7a W2FzyIh/KQlwlIx6RBKRHvVkcPVbNLbY6KE+Uo/Qh4EsujJ8lZnq2IZgJx5QhsRfUi20 BY1g== 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; bh=PBCGVhdgZqsy2hcHwZA7Jx0iL7SNgMzDbk0sLtfudCM=; b=clT7+yIydTNK3a6DfLCP+2QyQABojBmrB3lf3rNZ4lPBQK0aZ+9NdEZaB+CJOCVdcs 0W8KF5iyUyNdFuHWDILu65qG2lwc9qMoaVVmuU5Ti1C4Vt1m3STiqkgI28NxKqYGz09D 4RAh3PFYKVY/XbTqCTAPHkmQDDsTbUCx5HfcvKiN+Bn3nCh+to4RqeQaBoAnAn2X6wGb a1fr0TIKniPec5t0dMTYDn1wy/pNOYAqCBcPFTVb5BZVh6zCm2F+xFxFLr/7KhCv2vUy xuzCHZaKAnCNK09Qcg2+EcgdeBma91F+7+IR16gCWrx7+TqyGBp5cowYXZ81ZREwTbBb uNxQ== X-Gm-Message-State: AHPjjUhmC8e8/RjfAKLendIF5duo8N8+P0H4zmbuEioUSqHOU3lhd7QY IZpR9HoViLAevRAXiwNU0ac= X-Google-Smtp-Source: AOwi7QCcQGcuye1zy7SNrMztJxsAdTjfTOdLwUXuJVs2ijfGSKdzx94Wvi9TYl6605zxlmiCpfjYLg== X-Received: by 10.223.147.98 with SMTP id 89mr1483173wro.123.1506540575063; Wed, 27 Sep 2017 12:29:35 -0700 (PDT) Received: from localhost.localdomain ([151.66.56.134]) by smtp.gmail.com with ESMTPSA id k52sm20702238wrf.62.2017.09.27.12.29.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Sep 2017 12:29:34 -0700 (PDT) From: Lorenzo Bianconi X-Google-Original-From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, lorenzo.bianconi@st.com Subject: [PATCH 3/4] iio: imu: st_lsm6dsx: move decimator info in st_lsm6dsx_sensor_settings Date: Wed, 27 Sep 2017 21:29:27 +0200 Message-Id: <20170927192928.16160-4-lorenzo.bianconi@st.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170927192928.16160-1-lorenzo.bianconi@st.com> References: <20170927192928.16160-1-lorenzo.bianconi@st.com> 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 Move FIFO decimator info in st_lsm6dsx_sensor_settings list since decimator registers are exported in register map just in lsm6ds3/lsm6ds3h/lsm6dsl/lsm6dsm sensors and not in other compliant devices Signed-off-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 10 ++++++-- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 17 +++++++------ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 34 +++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index 46352c7bff43..052db1fbb46e 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -52,10 +52,18 @@ struct st_lsm6dsx_reg { u8 mask; }; +/** + * struct st_lsm6dsx_settings - ST IMU sensor settings + * @wai: Sensor WhoAmI default value. + * @max_fifo_size: Sensor max fifo length in FIFO words. + * @id: List of hw id supported by the driver configuration. + * @decimator: List of decimator register info (addr + mask). + */ struct st_lsm6dsx_settings { u8 wai; u16 max_fifo_size; enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID]; + struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID]; }; enum st_lsm6dsx_sensor_id { @@ -79,7 +87,6 @@ enum st_lsm6dsx_fifo_mode { * @watermark: Sensor watermark level. * @sip: Number of samples in a given pattern. * @decimator: FIFO decimation factor. - * @decimator_mask: Sensor mask for decimation register. * @delta_ts: Delta time between two consecutive interrupts. * @ts: Latest timestamp from the interrupt handler. */ @@ -94,7 +101,6 @@ struct st_lsm6dsx_sensor { u16 watermark; u8 sip; u8 decimator; - u8 decimator_mask; s64 delta_ts; s64 ts; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index 26fb970aed15..cb4f8558a98f 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -38,7 +38,6 @@ #define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06 #define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07 #define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0) -#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08 #define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12 #define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5) #define ST_LSM6DSX_REG_PP_OD_ADDR 0x12 @@ -110,8 +109,9 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr); for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { - sensor = iio_priv(hw->iio_devs[i]); + const struct st_lsm6dsx_reg *dec_reg; + sensor = iio_priv(hw->iio_devs[i]); /* update fifo decimators and sample in pattern */ if (hw->enable_mask & BIT(sensor->id)) { sensor->sip = sensor->odr / min_odr; @@ -123,12 +123,13 @@ static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) data = 0; } - err = st_lsm6dsx_write_with_mask(hw, - ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR, - sensor->decimator_mask, data); - if (err < 0) - return err; - + dec_reg = &hw->settings->decimator[sensor->id]; + if (dec_reg->addr) { + err = st_lsm6dsx_write_with_mask(hw, dec_reg->addr, + dec_reg->mask, data); + if (err < 0) + return err; + } sip += sensor->sip; } hw->sip = sip; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index e6e0363cd1c2..4532671df1be 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -42,8 +42,6 @@ #include "st_lsm6dsx.h" -#define ST_LSM6DSX_REG_ACC_DEC_MASK GENMASK(2, 0) -#define ST_LSM6DSX_REG_GYRO_DEC_MASK GENMASK(5, 3) #define ST_LSM6DSX_REG_INT1_ADDR 0x0d #define ST_LSM6DSX_REG_INT2_ADDR 0x0e #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3) @@ -160,6 +158,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { .id = { [0] = ST_LSM6DS3_ID, }, + .decimator = { + [ST_LSM6DSX_ID_ACC] = { + .addr = 0x08, + .mask = GENMASK(2, 0), + }, + [ST_LSM6DSX_ID_GYRO] = { + .addr = 0x08, + .mask = GENMASK(5, 3), + }, + }, }, { .wai = 0x69, @@ -167,6 +175,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { .id = { [0] = ST_LSM6DS3H_ID, }, + .decimator = { + [ST_LSM6DSX_ID_ACC] = { + .addr = 0x08, + .mask = GENMASK(2, 0), + }, + [ST_LSM6DSX_ID_GYRO] = { + .addr = 0x08, + .mask = GENMASK(5, 3), + }, + }, }, { .wai = 0x6a, @@ -175,6 +193,16 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = { [0] = ST_LSM6DSL_ID, [1] = ST_LSM6DSM_ID, }, + .decimator = { + [ST_LSM6DSX_ID_ACC] = { + .addr = 0x08, + .mask = GENMASK(2, 0), + }, + [ST_LSM6DSX_ID_GYRO] = { + .addr = 0x08, + .mask = GENMASK(5, 3), + }, + }, }, }; @@ -645,7 +673,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels); iio_dev->info = &st_lsm6dsx_acc_info; - sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK; scnprintf(sensor->name, sizeof(sensor->name), "%s_accel", name); break; @@ -654,7 +681,6 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels); iio_dev->info = &st_lsm6dsx_gyro_info; - sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK; scnprintf(sensor->name, sizeof(sensor->name), "%s_gyro", name); break;