Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3766751ybl; Mon, 13 Jan 2020 02:13:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxQRJlglPdW1TaOwCgwzMKLzSiYr5TZ0OUyMIOL1I9/9MQJi3WkmrrmlQafwhotzDcSBGa+ X-Received: by 2002:a9d:518b:: with SMTP id y11mr11774590otg.349.1578910397840; Mon, 13 Jan 2020 02:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578910397; cv=none; d=google.com; s=arc-20160816; b=aQduBYIw3deMRMerRLCIK+qXlR3DrS2Xqajk+ajE24ORIlGbnjepPiF2xhpGIU26+v 1SbUus4ME/LXX+POvWqLR1JEAhrSW0iuFMUzP+zfPbZQGMOfqec1/m0FpR0XhmNXDK9D 9iQDlSIR7okd0WqTnZwlbnDK187UH3cNlz4SH5rlVEDKDjt8xioIhMfRa97zB6CFOlho K6O6Ei+Q1AqWF/gs44KV5mYycaUsdfbKEdHwd5A8lAxk0bEajE1TB0h546dEu60wEEFG pCT/HmZd7qtycNniXPPbmuC0aDIeN4fUKU37D37yGdNO68XdJkUAx4LW7D15+1PNUnT4 x0JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id:date :subject:cc:to:from; bh=PjeBwAWLdP+3A00GSOVKHdwZBmoz8oe9K+GV+I86zNM=; b=L96H0VEhGoYiquaz9quhCIldxrNR+S1llX6pKyoOK7fxnvL4rh9ej7pyNW+eTtZUO3 P66SWFeFfsva4jtBI+JuAmI8/eWueCMHN2TQPfNx3q6c2arIPEdtZcGIXhawk1/gznWV 4zaAcgGVOyqQgg1gVVxkfyPmN5KqY3b4d+jAScKm117bs3nGEC6h5piwgPbHttVXUYB5 cy3E5Wq0JF1UJzxGNUv53Jr1nRa6bycz44sLSLC6rou3a3/odDP3ywKlN/it4MEaNxuo mIIHzq4ByJjVx16mhmMt4PLkJRWhvdOBLDlQ4qjWouMr24gHDQot4ZvZGfsw9E7CzsWL T/3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si6770733oto.207.2020.01.13.02.13.06; Mon, 13 Jan 2020 02:13:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726878AbgAMKMH (ORCPT + 99 others); Mon, 13 Jan 2020 05:12:07 -0500 Received: from comms.puri.sm ([159.203.221.185]:56194 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725978AbgAMKMH (ORCPT ); Mon, 13 Jan 2020 05:12:07 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 52481DF98F; Mon, 13 Jan 2020 02:12:06 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0AKdzV64zIId; Mon, 13 Jan 2020 02:12:05 -0800 (PST) From: Martin Kepplinger To: lorenzo.bianconi83@gmail.com, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Martin Kepplinger Subject: [PATCH v3] iio: imu: st_lsm6dsx: add mount matrix support Date: Mon, 13 Jan 2020 11:11:40 +0100 Message-Id: <20200113101140.24305-1-martin.kepplinger@puri.sm> Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow to read the mount-matrix device tree property and provide the mount_matrix file for userspace to read. Signed-off-by: Martin Kepplinger --- tested using the lsm9ds1 on the librem5-devkit (and userspace tools like iio-sensor-proxy) where this will be needed. thanks, martin revision history ---------------- v3: fix race condition during probe(). thanks Jonathan v2: additions and simplifications according to Lorenzo's review. thanks. drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 19 +++++++++++++++++++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index a763ff46f596..7076fc8c4c3b 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -76,6 +76,7 @@ enum st_lsm6dsx_hw_id { .endianness = IIO_LE, \ }, \ .event_spec = &st_lsm6dsx_event, \ + .ext_info = st_lsm6dsx_accel_ext_info, \ .num_event_specs = 1, \ } @@ -380,6 +381,7 @@ struct st_lsm6dsx_sensor { * @enable_event: enabled event bitmask. * @iio_devs: Pointers to acc/gyro iio_dev instances. * @settings: Pointer to the specific sensor settings in use. + * @orientation: sensor chip orientation relative to main hardware. */ struct st_lsm6dsx_hw { struct device *dev; @@ -406,6 +408,8 @@ struct st_lsm6dsx_hw { struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX]; const struct st_lsm6dsx_settings *settings; + + struct iio_mount_matrix orientation; }; static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = { @@ -479,4 +483,19 @@ st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr, return err; } +static const inline struct iio_mount_matrix * +st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev, + const struct iio_chan_spec *chan) +{ + struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); + struct st_lsm6dsx_hw *hw = sensor->hw; + + return &hw->orientation; +} + +static const struct iio_chan_spec_ext_info st_lsm6dsx_accel_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_lsm6dsx_get_mount_matrix), + { } +}; + #endif /* ST_LSM6DSX_H */ diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 0c64e35c7599..6e4d0a03c8b5 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -2312,6 +2312,10 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, return err; } + err = iio_read_mount_matrix(hw->dev, "mount-matrix", &hw->orientation); + if (err) + return err; + for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) { if (!hw->iio_devs[i]) continue; -- 2.20.1