From patchwork Tue May 7 08:02:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Nyekjaer X-Patchwork-Id: 10932451 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 CA5EC15A6 for ; Tue, 7 May 2019 08:12:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9F7E288EE for ; Tue, 7 May 2019 08:12:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE4A4288ED; Tue, 7 May 2019 08:12:09 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB 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 51AE1288EA for ; Tue, 7 May 2019 08:12:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726561AbfEGIMI (ORCPT ); Tue, 7 May 2019 04:12:08 -0400 Received: from first.geanix.com ([116.203.34.67]:42354 "EHLO first.geanix.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbfEGIMI (ORCPT ); Tue, 7 May 2019 04:12:08 -0400 X-Greylist: delayed 558 seconds by postgrey-1.27 at vger.kernel.org; Tue, 07 May 2019 04:12:07 EDT Received: from zen.localdomain (unknown [85.184.147.232]) by first.geanix.com (Postfix) with ESMTPSA id 7ECF29E9; Tue, 7 May 2019 08:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1557216130; bh=RnULC4LvVGsoENyisFyH/grjsHMX6Q6eNHH1MIF+aB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GYiqvVziIR9pNCof58l4MKz1UxJmzW+yul9a6fyKsolNWa0iW4Ywb5O3awE73dRWL dbDSDL0uBNUxpG70q/jFyxeVJYW8e/XIOkBMd21Nexem4cWZ5Q4ZgT4zwHy1eyKrtx VyrKJHTuSPbJsWPpZBec/yQIOVWXLfiWD6HSmpEfxlAWxCmNs78zaVDYYKgBheMNZe lHq/fhxlCAJ1kq+H3TaBNHRwRfHJquq4v7xBPSH4cBF7KT8+AAy3AaQHJOWpuGRItV R/Sr89aM0R+V7KYiQK8fKzsOuxKMtDOvd53uVcrkuclN1t5O0RsBrDEpjxlU5+uGSZ NVoQgfyl8zZ3Q== From: Sean Nyekjaer To: linux-iio@vger.kernel.org, jic23@kernel.org Cc: Sean Nyekjaer , martin@geanix.com Subject: [PATCH 2/2] iio: imu: st_lsm6dsx: add iio trigger and buffer support Date: Tue, 7 May 2019 10:02:25 +0200 Message-Id: <20190507080225.108000-2-sean@geanix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190507080225.108000-1-sean@geanix.com> References: <20190507080225.108000-1-sean@geanix.com> 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 This adds support for using iio triggers, this is needed because our hardware guys forgot to connect the irq pins from imu device to the SoC. Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 1ca69598678f..65ab853202de 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -40,8 +40,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -945,6 +948,30 @@ static int st_lsm6dsx_init_hw_timer(struct st_lsm6dsx_hw *hw) return 0; } +static irqreturn_t st_lsm6dsx_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct st_lsm6dsx_sensor *sensor = iio_priv(indio_dev); + u16 buffer[4 * sizeof(s64)/sizeof(u16)]; + int tmp, bit; + + memset(buffer, 0, sizeof(buffer)); + + for_each_set_bit(bit, indio_dev->active_scan_mask, indio_dev->masklength) { + st_lsm6dsx_read_oneshot(sensor, + indio_dev->channels[bit].address, &tmp); + buffer[bit] = tmp; + } + + iio_push_to_buffers_with_timestamp(indio_dev, buffer, + iio_get_time_ns(indio_dev)); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw) { u8 drdy_int_reg; @@ -1093,6 +1120,16 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name, err = st_lsm6dsx_fifo_setup(hw); if (err < 0) return err; + } else { + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { + err = devm_iio_triggered_buffer_setup(hw->dev, + hw->iio_devs[i], NULL, + st_lsm6dsx_trigger_handler, NULL); + if (err < 0) { + dev_err(hw->dev, "iio triggered buffer setup failed\n"); + return err; + } + } } for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {