From patchwork Fri Jan 24 02:50:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 3532791 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 343159F2D6 for ; Fri, 24 Jan 2014 02:50:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BBB9201CE for ; Fri, 24 Jan 2014 02:50:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AE43201C8 for ; Fri, 24 Jan 2014 02:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751390AbaAXCuj (ORCPT ); Thu, 23 Jan 2014 21:50:39 -0500 Received: from mga01.intel.com ([192.55.52.88]:54241 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751162AbaAXCuj (ORCPT ); Thu, 23 Jan 2014 21:50:39 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 23 Jan 2014 18:50:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,710,1384329600"; d="scan'208";a="470012560" Received: from unknown (HELO spandruv-linux-hsb-test.amr.corp.intel.com) ([10.255.13.54]) by fmsmga002.fm.intel.com with ESMTP; 23 Jan 2014 18:50:30 -0800 From: Srinivas Pandruvada To: jic23@kernel.org, jkosina@suse.cz Cc: linux-iio@vger.kernel.org, linux-input@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH 1/2] hid: hid-sensor-hub: Add selector api Date: Thu, 23 Jan 2014 18:50:21 -0800 Message-Id: <1390531822-7640-1-git-send-email-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 1.8.3.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In some report descriptors, they leave holes in the selectors. In this case if we use hardcoded selector values, this will result in invalid values. For example, if there is selectors defined for Power State from OFF to D0 to D3. We can't use indexes of these states if some states are not implemented or not present in the report decriptors. In this case, we need to get the indexes from report descriptors. One API is added to get the index of a selector. This API will search for usage id in the field usage list and return the index. Signed-off-by: Srinivas Pandruvada --- drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++++ include/linux/hid-sensor-hub.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 46f4480..ad2b869 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -291,6 +291,28 @@ err_free: } EXPORT_SYMBOL_GPL(sensor_hub_input_attr_get_raw_value); +int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, + u32 report_id, int field_index, u32 usage_id) +{ + struct hid_report *report; + struct hid_field *field; + int i; + + report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); + if (!report || (field_index >= report->maxfield)) + goto done_proc; + + field = report->field[field_index]; + for (i = 0; i < field->maxusage; ++i) { + if (field->usage[i].hid == usage_id) + return field->usage[i].usage_index; + } + +done_proc: + return -EINVAL; +} +EXPORT_SYMBOL_GPL(hid_sensor_get_usage_index); + int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, u8 type, u32 usage_id, diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index b914ca3..205eba0 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -218,4 +218,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int *val1, int *val2); +int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, + u32 report_id, int field_index, u32 usage_id); + #endif