From patchwork Thu Jan 5 11:03:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Song, Hongyan" X-Patchwork-Id: 9498279 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 91CD2606B4 for ; Thu, 5 Jan 2017 02:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88A1C27F10 for ; Thu, 5 Jan 2017 02:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D7D12832F; Thu, 5 Jan 2017 02:40: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=-5.0 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, 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 20F2727F10 for ; Thu, 5 Jan 2017 02:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755095AbdAECkh (ORCPT ); Wed, 4 Jan 2017 21:40:37 -0500 Received: from mga07.intel.com ([134.134.136.100]:64993 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754625AbdAECkg (ORCPT ); Wed, 4 Jan 2017 21:40:36 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP; 04 Jan 2017 18:40:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,318,1477983600"; d="scan'208";a="1079327582" Received: from shsensorbuild.sh.intel.com ([10.239.133.27]) by orsmga001.jf.intel.com with ESMTP; 04 Jan 2017 18:40:34 -0800 From: Song Hongyan To: linux-input@vger.kernel.org, linux-iio@vger.kernel.org Cc: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@intel.com, Song Hongyan Subject: [PATCH v2 2/2] iio: Add linear accel sensor hid support Date: Thu, 5 Jan 2017 19:03:04 +0800 Message-Id: <1483614184-1038-2-git-send-email-hongyan.song@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483614184-1038-1-git-send-email-hongyan.song@intel.com> References: <1483614184-1038-1-git-send-email-hongyan.song@intel.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Linear acceleration is a soft sensor it differs from a standard accel sensor, it provides a three-dimensional vector representing acceleration along each device axis, excluding gravity. The sensor data is derives from standard accelerometer device by filtering out the acceleration which is caused by the force of Earth’s gravity. The value can be used to perform gesture detection, it can also serve as input to an inertial navigation system, which uses dead reckoning. More information can be found in: http://www.usb.org/developers/hidpage/HUTRR59_-_Usages_for_Wearables.pdf Linear accel sensor, gravity sensor and accelerometer have similar channels and share channel usage ids. So the most of the code for accel_3d can be reused. Signed-off-by: Song Hongyan --- changes: unify name not use underline as separator. drivers/iio/accel/hid-sensor-accel-3d.c | 42 +++++++++++++++++++++++++++++++++ include/linux/hid-sensor-ids.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index 9edd574..8829dad 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -91,6 +91,41 @@ struct accel_3d_state { }; /* Channel definitions */ +static const struct iio_chan_spec linearaccel_3d_channels[] = { + { + .type = IIO_LINEARACCEL, + .modified = 1, + .channel2 = IIO_MOD_X, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_SAMP_FREQ) | + BIT(IIO_CHAN_INFO_HYSTERESIS), + .scan_index = CHANNEL_SCAN_INDEX_X, + }, { + .type = IIO_LINEARACCEL, + .modified = 1, + .channel2 = IIO_MOD_Y, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_SAMP_FREQ) | + BIT(IIO_CHAN_INFO_HYSTERESIS), + .scan_index = CHANNEL_SCAN_INDEX_Y, + }, { + .type = IIO_LINEARACCEL, + .modified = 1, + .channel2 = IIO_MOD_Z, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_SAMP_FREQ) | + BIT(IIO_CHAN_INFO_HYSTERESIS), + .scan_index = CHANNEL_SCAN_INDEX_Z, + } +}; + +/* Channel definitions */ static const struct iio_chan_spec gravity_channels[] = { { .type = IIO_GRAVITY, @@ -354,6 +389,10 @@ static int hid_accel_3d_probe(struct platform_device *pdev) name = "accel_3d"; channel_spec = accel_3d_channels; channel_size = sizeof(accel_3d_channels); + } else if (hsdev->usage == HID_USAGE_SENSOR_LINEARACCEL_3D) { + name = "linearaccel_3d"; + channel_spec = linearaccel_3d_channels; + channel_size = sizeof(linearaccel_3d_channels); } else { name = "gravity"; channel_spec = gravity_channels; @@ -452,6 +491,9 @@ static int hid_accel_3d_remove(struct platform_device *pdev) { /* gravity sensor */ .name = "HID-SENSOR-20007b", }, + { /* linear_accel sensor */ + .name = "HID-SENSOR-20007c", + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, hid_accel_3d_ids); diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index b6778fd2..bab8375 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -55,6 +55,9 @@ /* Gravity vector */ #define HID_USAGE_SENSOR_GRAVITY_VECTOR 0x20007B +/* linear accel */ +#define HID_USAGE_SENSOR_LINEARACCEL_3D 0x20007C + /* ORIENTATION: Compass 3D: (200083) */ #define HID_USAGE_SENSOR_COMPASS_3D 0x200083 #define HID_USAGE_SENSOR_DATA_ORIENTATION 0x200470