From patchwork Tue May 8 08:19:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Tresidder X-Patchwork-Id: 10385651 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 6545B602C2 for ; Tue, 8 May 2018 08:19:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5400928AC4 for ; Tue, 8 May 2018 08:19:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46C6D28C6D; Tue, 8 May 2018 08:19:17 +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 B513F28AC4 for ; Tue, 8 May 2018 08:19:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932830AbeEHITP (ORCPT ); Tue, 8 May 2018 04:19:15 -0400 Received: from anchovy3.45ru.net.au ([203.30.46.155]:53005 "EHLO anchovy3.45ru.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932850AbeEHITN (ORCPT ); Tue, 8 May 2018 04:19:13 -0400 Received: (qmail 13822 invoked by uid 5089); 8 May 2018 08:19:11 -0000 Received: by simscan 1.2.0 ppid: 13531, pid: 13533, t: 1.2284s scanners: regex: 1.2.0 attach: 1.2.0 clamav: 0.88.3/m:40/d:1950 spam: 3.1.4 Received: from unknown (HELO ?192.168.0.186?) (rtresidd@electromag.com.au@203.59.235.95) by anchovy2.45ru.net.au with ESMTPA; 8 May 2018 08:19:06 -0000 Subject: [PATCH v3] iio: accell: mma8452: Reduce sleep time when data not ready To: Martin Kepplinger , linux-iio@vger.kernel.org Cc: Jonathan Cameron , knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, harinath922@gmail.com References: <4a845aca-600d-2473-9b66-51dea9d1651b@electromag.com.au> <5aad5eff-b0f4-4795-7c19-e177d415ed8b@electromag.com.au> <58db7210-1c84-3f5e-472d-8fae2b77bdd0@posteo.de> <8128071e-3b73-e0b1-eb2a-f1b245aea3e4@electromag.com.au> <939563a6-19ff-b51a-3a26-e90f10c7bae1@posteo.de> From: Richard Tresidder Message-ID: Date: Tue, 8 May 2018 16:19:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <939563a6-19ff-b51a-3a26-e90f10c7bae1@posteo.de> Content-Language: en-AU 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 Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Signed-off-by: Richard Tresidder --- v3: Changes from v2 * Removed fallthrough fix (will submit separately) * Fixed some blank lines, trailing white spaces. v2: Changes from v1 * Remove whitespace changes * Added fallthrough fix (subsequently removed) drivers/iio/accel/mma8452.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 7a2da7f..5650b59 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -106,6 +106,7 @@ struct mma8452_data { u8 ctrl_reg1; u8 data_cfg; const struct mma_chip_info *chip_info; + int sleep_val; }; /** @@ -193,7 +194,10 @@ static int mma8452_drdy(struct mma8452_data *data) if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) return 0; - msleep(20); + if (data->sleep_val <= 20) + usleep_range(data->sleep_val * 250, data->sleep_val * 500); + else + msleep(20); } dev_err(&data->client->dev, "data not ready\n"); @@ -544,6 +548,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int mma8452_calculate_sleep(struct mma8452_data *data) +{ + int ret, i = mma8452_get_odr_index(data); + + if (mma8452_samp_freq[i][0] > 0) + ret = 1000 / mma8452_samp_freq[i][0]; + else + ret = 1000; + + return ret == 0 ? 1 : ret; +} + static int mma8452_standby(struct mma8452_data *data) { return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, @@ -700,6 +716,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; + data->sleep_val = mma8452_calculate_sleep(data); + ret = mma8452_change_config(data, MMA8452_CTRL_REG1, data->ctrl_reg1); break; @@ -1593,6 +1611,9 @@ static int mma8452_probe(struct i2c_client *client, data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); + + data->sleep_val = mma8452_calculate_sleep(data); + ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, data->ctrl_reg1); if (ret < 0)