Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2433944pxb; Sat, 30 Jan 2021 02:27:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsC1faUtlDIYxVt9YOueXzl12VKZAjMjxGYY9EIVBvM57XgrD168sAvLwBI3jKU+WsHq+b X-Received: by 2002:a05:6402:942:: with SMTP id h2mr9550150edz.128.1612002476019; Sat, 30 Jan 2021 02:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612002476; cv=none; d=google.com; s=arc-20160816; b=fIh8CV2/50ESv35R237cZ33dfQ79ApdGPJK0+WLzXnofZRysB8CdMxgxcEjayx2ycv YIi5CIl4SdQwDmL2C3xdiKwkIq8cWFJzeSIvVZWb/2WVibisB+ibPvkmENQsV0l9Q4X3 D/eHny7Zm1giGNj/zsE5E/S12t+BIvpu/1JV0sClD6NmzWq+XIqVcfDahg3tLV3aVsH7 valmEdiPxWiJHvuh8RmtAufEB842xktOPVBWZHvRWrxRzAp49CT1o75Mquy/2NaM9jJe DdQn5a73RFDJ3ibb4hGpg+RG0+FBlew7PjCX7vTs5n2OtMEDu4FNQ8VDsdDxPWsLIW4M LZhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=pWGDG8atMobEAPsphkgQ14cPGBE10HOE/lX1n0Xl0js=; b=gaBI5CkgUmDLseXB9VdT9rrsJgsBjY/Gp4XvZ7fO0gMpCs/mNDo3ArfEkJo7yG2Mrs NiKJHBje7cFvaiMX8d30Js9Jxr3NqmNkSsiFSoW4TtWGtiduOnbTGbKIIoN985kGQfl5 iaobNpwjKQU9Ok8CGYjMHthRsZS+5mMjIf+61dY57/5+VWWHw4uynOcMd3G9nKDnagFN O6DNHWeYvOZRawhf5VyT0ofi+7os6byer+N0WEcgtl0xX9OmBO0QBPo0DlIWa2pZPpMo P4GKLBiO07iZ7vALGOrvOcv92H40LavvH1TkU9gvv4NNWsTcalhCjRF5Y/DrW/61gbtq juvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gu20si6623647ejb.562.2021.01.30.02.27.32; Sat, 30 Jan 2021 02:27:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231894AbhA3KZy (ORCPT + 99 others); Sat, 30 Jan 2021 05:25:54 -0500 Received: from mga06.intel.com ([134.134.136.31]:30877 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232221AbhA3KZ1 (ORCPT ); Sat, 30 Jan 2021 05:25:27 -0500 IronPort-SDR: 6T4EdNHxqpBM86DW1PHI4oBEkmKLbznH81XNqfpnx1ofSuemt/mV6Wd34BGWniD/51yhGMGnX/ nbggDZKluB8A== X-IronPort-AV: E=McAfee;i="6000,8403,9879"; a="242045419" X-IronPort-AV: E=Sophos;i="5.79,388,1602572400"; d="scan'208";a="242045419" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2021 02:24:46 -0800 IronPort-SDR: p+YYND8MYMPvvWpMw0zIWV9d8gKMIumjcD0mHYFFIAm6//U4QAYX8iywbuz5cigbYoKtLuUK7q DVyfY01yN9eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,388,1602572400"; d="scan'208";a="352940978" Received: from host.sh.intel.com ([10.239.154.115]) by fmsmga007.fm.intel.com with ESMTP; 30 Jan 2021 02:24:44 -0800 From: Ye Xiang To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Xiang Subject: [PATCH v2] iio: hid-sensor-rotation: Fix quaternion data not correct Date: Sat, 30 Jan 2021 18:25:46 +0800 Message-Id: <20210130102546.31397-1-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because the data of HID_USAGE_SENSOR_ORIENT_QUATERNION defined by ISH FW is s16, but quaternion data type is in_rot_quaternion_type(le:s16/32X4>>0), need to transform data type from s16 to s32 Fixes: fc18dddc0625 ("iio: hid-sensors: Added device rotation support") Signed-off-by: Ye Xiang --- v2: - Add Fixes tag --- drivers/iio/orientation/hid-sensor-rotation.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c index b0245b3b7ffc..cf7f57a47681 100644 --- a/drivers/iio/orientation/hid-sensor-rotation.c +++ b/drivers/iio/orientation/hid-sensor-rotation.c @@ -21,7 +21,7 @@ struct dev_rot_state { struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info quaternion; struct { - u32 sampled_vals[4] __aligned(16); + s32 sampled_vals[4] __aligned(16); u64 timestamp __aligned(8); } scan; int scale_pre_decml; @@ -175,8 +175,15 @@ static int dev_rot_capture_sample(struct hid_sensor_hub_device *hsdev, struct dev_rot_state *rot_state = iio_priv(indio_dev); if (usage_id == HID_USAGE_SENSOR_ORIENT_QUATERNION) { - memcpy(&rot_state->scan.sampled_vals, raw_data, - sizeof(rot_state->scan.sampled_vals)); + if (raw_len / 4 == sizeof(s16)) { + rot_state->scan.sampled_vals[0] = ((s16 *)raw_data)[0]; + rot_state->scan.sampled_vals[1] = ((s16 *)raw_data)[1]; + rot_state->scan.sampled_vals[2] = ((s16 *)raw_data)[2]; + rot_state->scan.sampled_vals[3] = ((s16 *)raw_data)[3]; + } else { + memcpy(&rot_state->scan.sampled_vals, raw_data, + sizeof(rot_state->scan.sampled_vals)); + } dev_dbg(&indio_dev->dev, "Recd Quat len:%zu::%zu\n", raw_len, sizeof(rot_state->scan.sampled_vals)); -- 2.17.1