From patchwork Sun Nov 11 14:15:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10677667 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 4A682139B for ; Sun, 11 Nov 2018 14:15:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AD922AA5B for ; Sun, 11 Nov 2018 14:15:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EEEC2AA62; Sun, 11 Nov 2018 14:15:57 +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 BEE8F2AA5B for ; Sun, 11 Nov 2018 14:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728174AbeKLAEh (ORCPT ); Sun, 11 Nov 2018 19:04:37 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33813 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728236AbeKLAEh (ORCPT ); Sun, 11 Nov 2018 19:04:37 -0500 Received: by mail-wr1-f68.google.com with SMTP id j26-v6so6559303wre.1 for ; Sun, 11 Nov 2018 06:15:55 -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=hAzz6SXMUypLda8GdMX1VufjiyTEgzHqjtlpAjlB+W4=; b=CRBqTU9Iu9IFbTW/DsYmjap+237NJU2fT4DGRu29wTEMqtL8nnAB8BIE+iVUDl3p6i x+BBJ0OLjjnQyTH0CrEUfeBNjynZ7NLZKTw4LY++dZFPVHVQXd/nmxwmVuFrHtPcF8MH ZK8WuVOqM8Q+tEbSejsk1iecUF5kbbwYlVPwFrJks1raYXPs6agkSPfX5MQO3Nsh2Geg IvVYS6tqydswUbl06FlqJxenEHj2e5g98evP6Jw7Qs9S8mkccyDfZgvy3qRhLb7Po/kj pels1TYBjzMuhj9KH4aGfT9dc/Yp5RhTKZG1qpXVKCJL+uHc5TmDW2Byb56R73QP/2WA uDBw== X-Gm-Message-State: AGRZ1gKmuk0PWt6tROD+fdn7O8gGTnTmBuFUuLqbQJpCELe6+s5ONJ60 A/3ihXxj6Zm51VJfZx4RbYLvpsxSElY= X-Google-Smtp-Source: AJdET5fCoXctyPVLgcqjZqxTZowkdBtoknx1j71Ybib3UrXQJKmJ7pK3x3XQxtNaZWuj2U7Mrx5zyA== X-Received: by 2002:adf:f68e:: with SMTP id v14-v6mr4968635wrp.261.1541945754503; Sun, 11 Nov 2018 06:15:54 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 06:15:54 -0800 (PST) From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 5/9] iio: imu: st_lsm6dsx: introduce st_lsm6dsx_sensor_set_enable routine Date: Sun, 11 Nov 2018 15:15:32 +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 Add st_lsm6dsx_sensor_set_enable routine and remove st_lsm6dsx_sensor_{enable/disable} ones in order to make the code more readable and remove unnecessary functions Signed-off-by: Lorenzo Bianconi --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 4 +-- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 12 ++----- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 32 ++++++------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index 4c8385d19c78..2beb4f563892 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -185,8 +185,8 @@ extern const struct dev_pm_ops st_lsm6dsx_pm_ops; int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, struct regmap *regmap); -int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor); -int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor); +int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor, + bool enable); int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val); int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index f4804008b585..6a379767b919 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -579,15 +579,9 @@ static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable) goto out; } - if (enable) { - err = st_lsm6dsx_sensor_enable(sensor); - if (err < 0) - goto out; - } else { - err = st_lsm6dsx_sensor_disable(sensor); - if (err < 0) - goto out; - } + err = st_lsm6dsx_sensor_set_enable(sensor, enable); + if (err < 0) + goto out; err = st_lsm6dsx_set_fifo_odr(sensor, enable); if (err < 0) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 8885c9755456..28ddedbd1304 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -530,33 +530,21 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr) return st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data); } -int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor) -{ - int err; - - err = st_lsm6dsx_set_odr(sensor, sensor->odr); - if (err < 0) - return err; - - sensor->hw->enable_mask |= BIT(sensor->id); - - return 0; -} - -int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor) +int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor, + bool enable) { struct st_lsm6dsx_hw *hw = sensor->hw; - const struct st_lsm6dsx_reg *reg; - unsigned int data; + u16 odr = enable ? sensor->odr : 0; int err; - reg = &st_lsm6dsx_odr_table[sensor->id].reg; - data = ST_LSM6DSX_SHIFT_VAL(0, reg->mask); - err = st_lsm6dsx_update_bits_locked(hw, reg->addr, reg->mask, data); + err = st_lsm6dsx_set_odr(sensor, odr); if (err < 0) return err; - sensor->hw->enable_mask &= ~BIT(sensor->id); + if (enable) + hw->enable_mask |= BIT(sensor->id); + else + hw->enable_mask &= ~BIT(sensor->id); return 0; } @@ -568,7 +556,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, int err, delay; __le16 data; - err = st_lsm6dsx_sensor_enable(sensor); + err = st_lsm6dsx_sensor_set_enable(sensor, true); if (err < 0) return err; @@ -579,7 +567,7 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor, if (err < 0) return err; - st_lsm6dsx_sensor_disable(sensor); + st_lsm6dsx_sensor_set_enable(sensor, false); *val = (s16)le16_to_cpu(data);