From patchwork Mon Feb 5 18:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 13546060 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EDFE482CC; Mon, 5 Feb 2024 18:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; cv=none; b=VeCu1w7c3TnX4n38z71ZMKKKVSerUFuamJSdFJYL+FgsOROed9qWwJ21BMn3aC9XwuP2VaLKDNtDeM5I4sdK4Ab2GGjDe3yCq5r89440usQiI668sUuZKB7ir3FSEId5h7UlcpTnUxhb+oEFZNEquagn7daQC5eu2G0ZCin9n84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; c=relaxed/simple; bh=bQYlN6dlbdaq+WNtCgja2G3ihpO71CWagRR5E/44ecY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VxycM1pOPJ9ziqtGE3Nphd9gmQ+hvlmKY8vee2gLkIrQkv0we7m/CYJIyruTqoPQ52NGQz6TGdRlrSZ7uEd3vIoD0uXz12pbqlsDVP8A+gvLd9ORol7l28WkbnKJY+kGEvMJA9GmvS3Ndpe7S2sLv389XxwXo9RUmDkmi8xe+wk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZDap84gl; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZDap84gl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707159570; x=1738695570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bQYlN6dlbdaq+WNtCgja2G3ihpO71CWagRR5E/44ecY=; b=ZDap84gl2nIUHE7Sjn/bwL9VRzHeJap1Dwz7TN+pqb0R9MnA2l4NKBAf 1AeQTkT6gE3TrkPYuPi4cWdIV3sWG050z3TIVAZOgk4W3pMJDRwrYJIYL fXRz8fgzzUMFkX0/gTvh1oy70JBTGS2qOTNkSWiGTkBCtBLNFycDwDnii ztnrzOZztgrPhdFLMcy5RFE2zMxD7hyDGmsHu62KePgh0n/bF7Ff/T3zH vhD/u1HQ/2n0eObII7KdSWOfhDpXoMJrnNbwZ3wO9lqKrjvsn8xN1ZQYM eL+lkFKBa2034DDjQc8cY042K4mCvNzlVOISwWqHsEjssHJnl57YUI6ZG g==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="11320384" X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="11320384" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 10:59:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="31879442" Received: from spandruv-desk.jf.intel.com ([10.54.75.14]) by fmviesa001.fm.intel.com with ESMTP; 05 Feb 2024 10:59:28 -0800 From: Srinivas Pandruvada To: jikos@kernel.org, jic23@kernel.org, lars@metafoo.de, Basavaraj.Natikar@amd.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH v5 1/4] iio: hid-sensor-als: Assign channels dynamically Date: Mon, 5 Feb 2024 10:59:23 -0800 Message-Id: <20240205185926.3030521-2-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> References: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of assuming that every channel defined statically by als_channels[] is present, assign dynamically based on presence of the respective usage id in the descriptor. This will allow to register ALS with limited channel support. Append the timestamp as the last channel. Update available_scan_mask to specify all channels which are present. There is no intentional function changes done. Signed-off-by: Srinivas Pandruvada --- v5: - Move als_scan_mask to struct als_state v4: Addressed comments from Jonthan: - Use available_scan_masks - timestamp location is fixed and left gaps in sample data for absent channels - Use CHANNEL_SCAN_INDEX_MAX as limit to check presence of usage ids, otherwise it will miss newer channels added in subsequent patches. v3: Addressed comments from Jonthan: - Remove channel allocation and move to iio_priv() - Parse all usage IDs in a single loop and continue for failure. This way the temperature and chromaticity will not need any special processing to parse usage ids. - Don't leave empty channel indexes v2: New change drivers/iio/light/hid-sensor-als.c | 51 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index b6c4bef2a7bb..ed5c42aa7cca 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -25,6 +25,7 @@ struct als_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info als[CHANNEL_SCAN_INDEX_MAX]; + struct iio_chan_spec channels[CHANNEL_SCAN_INDEX_MAX + 1]; struct { u32 illum[CHANNEL_SCAN_INDEX_MAX]; u64 timestamp __aligned(8); @@ -33,7 +34,15 @@ struct als_state { int scale_post_decml; int scale_precision; int value_offset; + int num_channels; s64 timestamp; + unsigned long als_scan_mask[2]; +}; + +/* The order of usage ids must match scan index starting from CHANNEL_SCAN_INDEX_INTENSITY */ +static const u32 als_usage_ids[] = { + HID_USAGE_SENSOR_LIGHT_ILLUM, + HID_USAGE_SENSOR_LIGHT_ILLUM, }; static const u32 als_sensitivity_addresses[] = { @@ -238,27 +247,38 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev, /* Parse report which is specific to an usage id*/ static int als_parse_report(struct platform_device *pdev, struct hid_sensor_hub_device *hsdev, - struct iio_chan_spec *channels, unsigned usage_id, struct als_state *st) { - int ret; + struct iio_chan_spec *channels; + int ret, index = 0; int i; - for (i = 0; i <= CHANNEL_SCAN_INDEX_ILLUM; ++i) { + channels = st->channels; + + for (i = 0; i < CHANNEL_SCAN_INDEX_MAX; ++i) { ret = sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT, usage_id, - HID_USAGE_SENSOR_LIGHT_ILLUM, + als_usage_ids[i], &st->als[i]); if (ret < 0) - return ret; - als_adjust_channel_bit_mask(channels, i, st->als[i].size); + continue; + + channels[index] = als_channels[i]; + st->als_scan_mask[0] |= BIT(i); + als_adjust_channel_bit_mask(channels, index, st->als[i].size); + ++index; dev_dbg(&pdev->dev, "als %x:%x\n", st->als[i].index, st->als[i].report_id); } + st->num_channels = index; + /* Return success even if one usage id is present */ + if (index) + ret = 0; + st->scale_precision = hid_sensor_format_scale(usage_id, &st->als[CHANNEL_SCAN_INDEX_INTENSITY], &st->scale_pre_decml, &st->scale_post_decml); @@ -294,15 +314,7 @@ static int hid_als_probe(struct platform_device *pdev) return ret; } - indio_dev->channels = devm_kmemdup(&pdev->dev, als_channels, - sizeof(als_channels), GFP_KERNEL); - if (!indio_dev->channels) { - dev_err(&pdev->dev, "failed to duplicate channels\n"); - return -ENOMEM; - } - ret = als_parse_report(pdev, hsdev, - (struct iio_chan_spec *)indio_dev->channels, hsdev->usage, als_state); if (ret) { @@ -310,8 +322,15 @@ static int hid_als_probe(struct platform_device *pdev) return ret; } - indio_dev->num_channels = - ARRAY_SIZE(als_channels); + /* Add timestamp channel */ + als_state->channels[als_state->num_channels] = als_channels[CHANNEL_SCAN_INDEX_TIMESTAMP]; + + /* +1 for adding timestamp channel */ + indio_dev->num_channels = als_state->num_channels + 1; + + indio_dev->channels = als_state->channels; + indio_dev->available_scan_masks = als_state->als_scan_mask; + indio_dev->info = &als_info; indio_dev->name = name; indio_dev->modes = INDIO_DIRECT_MODE; From patchwork Mon Feb 5 18:59:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 13546061 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 269583CF58; Mon, 5 Feb 2024 18:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; cv=none; b=P/kJ9EFesFtDObdfAw3cvP9/T26QWwNRn8Xfx3RjdwmGn0uXWTkbgs3ACW0+lxBZtc4Lqa6M6ab1jMn4XU+VlOVMb1bPCtE0gvlaGtAGJNeWUswgeE8fhrnACKPsmCd5jnuQeks7RFks45BWIReXFKlIxC+g+AJgFNfLMPZF69Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; c=relaxed/simple; bh=UEIOHhvL4g19aA5VxyfFMvMc+35jqRicCI0VD6kXsR8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QO6v4okRUoAeMjydYZiV/HutBVyJRUlG+uePzDkDaf8vfMU54RAeimmZGAXcd0mXKi3lVpfsLTLPGujvCIfRTyjsOkzadkZIDdbHRvjpBZDs2QlEjRDDtB0V97wDRL6yNcUZRQJgiLeZIe174bQc7QftX3RD9/NzFlDOFoAqLWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IRo+KYJ6; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IRo+KYJ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707159571; x=1738695571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UEIOHhvL4g19aA5VxyfFMvMc+35jqRicCI0VD6kXsR8=; b=IRo+KYJ6BRVCUOaUV03qrnvml5JDcKOgCwvzNIEAV9cmJAmyUPdWN1Hw ugQEUFCtAIuubVoR5CgpGG6IU7iO63/BHzMf5t3qOz0YTbJbxQ8u7tCWO bb1s5jhmjHkJP3gXLEDXe6kdOP8nxgb8sgWhxZk1QpoJlLEshbD8BHxkJ 67f6zGnvBzZF9llsD1QkADznm9qLcss2qzKoMUO/3D4Ubt9AmO2wU0ndt 6532gcgdUH/VNyNqR+Pq484kgaHPLSqMFhVNPQ3jiH5oXPth/6YOhlvSC BkAbYRfxkJTER8ejXpSIq6DD3Om9SBF5QREt7bltHmkQh4ww1dulZZe2P Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="11320390" X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="11320390" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 10:59:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="31879446" Received: from spandruv-desk.jf.intel.com ([10.54.75.14]) by fmviesa001.fm.intel.com with ESMTP; 05 Feb 2024 10:59:28 -0800 From: Srinivas Pandruvada To: jikos@kernel.org, jic23@kernel.org, lars@metafoo.de, Basavaraj.Natikar@amd.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH v5 2/4] iio: hid-sensor-als: Remove hardcoding of values for enums Date: Mon, 5 Feb 2024 10:59:24 -0800 Message-Id: <20240205185926.3030521-3-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> References: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove hardcoding of values for enum CHANNEL_SCAN_INDEX_INTENSITY and CHANNEL_SCAN_INDEX_ILLUM. Signed-off-by: Srinivas Pandruvada --- v5: No change v4: NO change v3: New patch. Added as the next patch removed the hardcoding of enum values when submitted. To remove unrelated changes, created a patch to just remove hardcoding of values. drivers/iio/light/hid-sensor-als.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index ed5c42aa7cca..144c02fbbbc0 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -14,8 +14,8 @@ #include "../common/hid-sensors/hid-sensor-trigger.h" enum { - CHANNEL_SCAN_INDEX_INTENSITY = 0, - CHANNEL_SCAN_INDEX_ILLUM = 1, + CHANNEL_SCAN_INDEX_INTENSITY, + CHANNEL_SCAN_INDEX_ILLUM, CHANNEL_SCAN_INDEX_MAX }; From patchwork Mon Feb 5 18:59:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 13546062 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41531482DB; Mon, 5 Feb 2024 18:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; cv=none; b=aXxK94eRqVCjrY1C+fyhBe7iZymPyvRc3b85t6tUZi2GsJtlcPbPwxyq3KR+9KSkCANVR5MmX1Wq8PJEYhX4VsRSiU81gRL+HQMIawLuvSVqg2jp0ZkKMc+pMYqEYRmrScGFuaD4BiOstxVDYSOYlU7ZK59h+kpd+ENcB/7965s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159572; c=relaxed/simple; bh=cB5gQgDrAgQIpJclgZYRkO9vSJtOG3M66a2Hh0BO8pY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ab2BcOFKc6LCcoknKSeGmCf4p1jd8ru+UEk6II5TpDOxbyVpEaS7WChfuNBkE+iV78ql66nmV5FAHohb1NGSwwJzckKESNGJSkkkssWDhzCR2LmdeXaltWyUV5UcQoFf6fTkzEvgAECRTCoKwuPydsDgxLlyHoNqDU3ua7LRDzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=e2f+sgUH; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e2f+sgUH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707159571; x=1738695571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cB5gQgDrAgQIpJclgZYRkO9vSJtOG3M66a2Hh0BO8pY=; b=e2f+sgUHBD7e+VPYorD84jpPGmek6So5xlMzz8VvA2JQH5smUFFi8VpR AC1ckAPHQ01aY4JaiHA9YLE+Nji7P4OTEsexfH6ZivdMEAtq6hYv7JpN2 3qDp/PBEtmSzrFdDJ0fo7LAEEKh+L6uLPLZc+w8R6oR3dZYYf2xEx2e2J WPEYTUynwK+qS49DSe6aNRCy7hjSh73q1/nDDN3PdyHN6WQkePb9ksTre JYQIlYCbaKgqDZWj8jUKHcAIVQ6eOy7dXNHctg7fpuf3BwwHj1WFmgAXU KAX7l2hYanCrIou2bV8QJl/G7xPQAKiJXAnDOqLKjOxbFpcrAbRBHALXr Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="11320395" X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="11320395" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 10:59:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="31879449" Received: from spandruv-desk.jf.intel.com ([10.54.75.14]) by fmviesa001.fm.intel.com with ESMTP; 05 Feb 2024 10:59:29 -0800 From: Srinivas Pandruvada To: jikos@kernel.org, jic23@kernel.org, lars@metafoo.de, Basavaraj.Natikar@amd.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH v5 3/4] iio: hid-sensor-als: Add light color temperature support Date: Mon, 5 Feb 2024 10:59:25 -0800 Message-Id: <20240205185926.3030521-4-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> References: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Basavaraj Natikar On some platforms, ambient color sensors also support light color temperature. Add support of light color temperature. Signed-off-by: Basavaraj Natikar Signed-off-by: Srinivas Pandruvada --- v5: No change v4: - Index is fixed for each channel instead of packing for absent channels v3: Simplilified as no special processing is required in als_parse_report() v2: Original patch from Basavaraj Natikar is modified to prevent failure when the new usage id is not found in the descriptor. drivers/iio/light/hid-sensor-als.c | 21 +++++++++++++++++++++ include/linux/hid-sensor-ids.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 144c02fbbbc0..c17902823629 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -16,6 +16,7 @@ enum { CHANNEL_SCAN_INDEX_INTENSITY, CHANNEL_SCAN_INDEX_ILLUM, + CHANNEL_SCAN_INDEX_COLOR_TEMP, CHANNEL_SCAN_INDEX_MAX }; @@ -43,6 +44,7 @@ struct als_state { static const u32 als_usage_ids[] = { HID_USAGE_SENSOR_LIGHT_ILLUM, HID_USAGE_SENSOR_LIGHT_ILLUM, + HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE, }; static const u32 als_sensitivity_addresses[] = { @@ -74,6 +76,16 @@ static const struct iio_chan_spec als_channels[] = { BIT(IIO_CHAN_INFO_HYSTERESIS_RELATIVE), .scan_index = CHANNEL_SCAN_INDEX_ILLUM, }, + { + .type = IIO_COLORTEMP, + .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) | + BIT(IIO_CHAN_INFO_HYSTERESIS_RELATIVE), + .scan_index = CHANNEL_SCAN_INDEX_COLOR_TEMP, + }, IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP) }; @@ -112,6 +124,11 @@ static int als_read_raw(struct iio_dev *indio_dev, min = als_state->als[chan->scan_index].logical_minimum; address = HID_USAGE_SENSOR_LIGHT_ILLUM; break; + case CHANNEL_SCAN_INDEX_COLOR_TEMP: + report_id = als_state->als[chan->scan_index].report_id; + min = als_state->als[chan->scan_index].logical_minimum; + address = HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE; + break; default: report_id = -1; break; @@ -232,6 +249,10 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev, als_state->scan.illum[CHANNEL_SCAN_INDEX_ILLUM] = sample_data; ret = 0; break; + case HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE: + als_state->scan.illum[CHANNEL_SCAN_INDEX_COLOR_TEMP] = sample_data; + ret = 0; + break; case HID_USAGE_SENSOR_TIME_TIMESTAMP: als_state->timestamp = hid_sensor_convert_timestamp(&als_state->common_attributes, *(s64 *)raw_data); diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index 13b1e65fbdcc..8af4fb3e0254 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -21,6 +21,7 @@ #define HID_USAGE_SENSOR_ALS 0x200041 #define HID_USAGE_SENSOR_DATA_LIGHT 0x2004d0 #define HID_USAGE_SENSOR_LIGHT_ILLUM 0x2004d1 +#define HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE 0x2004d2 /* PROX (200011) */ #define HID_USAGE_SENSOR_PROX 0x200011 From patchwork Mon Feb 5 18:59:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: srinivas pandruvada X-Patchwork-Id: 13546063 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 405C648783; Mon, 5 Feb 2024 18:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159574; cv=none; b=gGu6u4C+ncadMrGKWZrYE1lzs8n5Qexj7NMMgVD94CXTiLeXYKAurSUMOueN5XTwxIRlFaYJo3mqf56mZ/k4sBmCYt3wPlu5BVxqjOACcJPuHs2a9UEv2NhgKdpEaJwjd0iUOQngqXu+Y6vi/MaNFp3AtIMs/GMuw1BAlDOUwJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707159574; c=relaxed/simple; bh=QNmSf9FjffWDC7IlX3FZxCVIQSQApsSGNGFX5xhujI8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FbTgoSvinLj3x56+fjiM0AXAcYcvIl9NAmGz+/iHlyzj74HXEk7N6XZHIt8lrJRmBXJKvX1A1+mJUERAfkM+Ke//z4wNwawoYiMXQmsqlOciDZA9EhfmcumF11jC0dBYLjwwMIMQWVV7bR8836EXGyS6Ka0WrrVFH76f7oBc1nM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=iVT3+r+v; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iVT3+r+v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707159572; x=1738695572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QNmSf9FjffWDC7IlX3FZxCVIQSQApsSGNGFX5xhujI8=; b=iVT3+r+veRdtGUL1mblPf07iKeYPJ1QHMyw6/3PRRSrduMWTDCYFjSpf tinNiM8OMwME1r+7VfxGNGLJkfaDuvxKBT6SZGYOvJdMv/ZhN0PtRU9nB M7rBEFgM7KJLfiWtbkDRaeZWwaZ+lvMTmsSO2UYsJCuMGmtgU6UM67Zm3 okmVIAgCRHcwWfdOhG5gRlbNXQlmMMqsa2gDxE4j/fYRn8KxbBkP1YDAy Ew5Mi3aKQ4FxwdrG0rzBz8LUOtxwoOhJigrq9KJFoveS+w9R9rL6hFJu9 zCW65JYpTotVTp8/QTY/CApiSRYUCkAmNJ1ANjUpXfCFbEhB8o7YUybYZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="11320400" X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="11320400" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 10:59:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="31879451" Received: from spandruv-desk.jf.intel.com ([10.54.75.14]) by fmviesa001.fm.intel.com with ESMTP; 05 Feb 2024 10:59:29 -0800 From: Srinivas Pandruvada To: jikos@kernel.org, jic23@kernel.org, lars@metafoo.de, Basavaraj.Natikar@amd.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Pandruvada Subject: [PATCH v5 4/4] iio: hid-sensor-als: Add light chromaticity support Date: Mon, 5 Feb 2024 10:59:26 -0800 Message-Id: <20240205185926.3030521-5-srinivas.pandruvada@linux.intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> References: <20240205185926.3030521-1-srinivas.pandruvada@linux.intel.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Basavaraj Natikar On some platforms, ambient color sensors also support the x and y light colors, which represent the coordinates on the CIE 1931 chromaticity diagram. Add light chromaticity x and y. Signed-off-by: Basavaraj Natikar Signed-off-by: Srinivas Pandruvada --- v5: No change v4: - Index is fixed for each channel instead of packing for absent channels v3: Simplilified as no special processing is required in als_parse_report() v2: Original patch from Basavaraj Natikar is modified to prevent failure when the new usage id is not found in the descriptor. drivers/iio/light/hid-sensor-als.c | 46 ++++++++++++++++++++++++++++++ include/linux/hid-sensor-ids.h | 3 ++ 2 files changed, 49 insertions(+) diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index c17902823629..260281194f61 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -17,6 +17,8 @@ enum { CHANNEL_SCAN_INDEX_INTENSITY, CHANNEL_SCAN_INDEX_ILLUM, CHANNEL_SCAN_INDEX_COLOR_TEMP, + CHANNEL_SCAN_INDEX_CHROMATICITY_X, + CHANNEL_SCAN_INDEX_CHROMATICITY_Y, CHANNEL_SCAN_INDEX_MAX }; @@ -45,6 +47,8 @@ static const u32 als_usage_ids[] = { HID_USAGE_SENSOR_LIGHT_ILLUM, HID_USAGE_SENSOR_LIGHT_ILLUM, HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE, + HID_USAGE_SENSOR_LIGHT_CHROMATICITY_X, + HID_USAGE_SENSOR_LIGHT_CHROMATICITY_Y, }; static const u32 als_sensitivity_addresses[] = { @@ -86,6 +90,30 @@ static const struct iio_chan_spec als_channels[] = { BIT(IIO_CHAN_INFO_HYSTERESIS_RELATIVE), .scan_index = CHANNEL_SCAN_INDEX_COLOR_TEMP, }, + { + .type = IIO_CHROMATICITY, + .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) | + BIT(IIO_CHAN_INFO_HYSTERESIS_RELATIVE), + .scan_index = CHANNEL_SCAN_INDEX_CHROMATICITY_X, + }, + { + .type = IIO_CHROMATICITY, + .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) | + BIT(IIO_CHAN_INFO_HYSTERESIS_RELATIVE), + .scan_index = CHANNEL_SCAN_INDEX_CHROMATICITY_Y, + }, IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP) }; @@ -129,6 +157,16 @@ static int als_read_raw(struct iio_dev *indio_dev, min = als_state->als[chan->scan_index].logical_minimum; address = HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE; break; + case CHANNEL_SCAN_INDEX_CHROMATICITY_X: + report_id = als_state->als[chan->scan_index].report_id; + min = als_state->als[chan->scan_index].logical_minimum; + address = HID_USAGE_SENSOR_LIGHT_CHROMATICITY_X; + break; + case CHANNEL_SCAN_INDEX_CHROMATICITY_Y: + report_id = als_state->als[chan->scan_index].report_id; + min = als_state->als[chan->scan_index].logical_minimum; + address = HID_USAGE_SENSOR_LIGHT_CHROMATICITY_Y; + break; default: report_id = -1; break; @@ -253,6 +291,14 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev, als_state->scan.illum[CHANNEL_SCAN_INDEX_COLOR_TEMP] = sample_data; ret = 0; break; + case HID_USAGE_SENSOR_LIGHT_CHROMATICITY_X: + als_state->scan.illum[CHANNEL_SCAN_INDEX_CHROMATICITY_X] = sample_data; + ret = 0; + break; + case HID_USAGE_SENSOR_LIGHT_CHROMATICITY_Y: + als_state->scan.illum[CHANNEL_SCAN_INDEX_CHROMATICITY_Y] = sample_data; + ret = 0; + break; case HID_USAGE_SENSOR_TIME_TIMESTAMP: als_state->timestamp = hid_sensor_convert_timestamp(&als_state->common_attributes, *(s64 *)raw_data); diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index 8af4fb3e0254..6730ee900ee1 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -22,6 +22,9 @@ #define HID_USAGE_SENSOR_DATA_LIGHT 0x2004d0 #define HID_USAGE_SENSOR_LIGHT_ILLUM 0x2004d1 #define HID_USAGE_SENSOR_LIGHT_COLOR_TEMPERATURE 0x2004d2 +#define HID_USAGE_SENSOR_LIGHT_CHROMATICITY 0x2004d3 +#define HID_USAGE_SENSOR_LIGHT_CHROMATICITY_X 0x2004d4 +#define HID_USAGE_SENSOR_LIGHT_CHROMATICITY_Y 0x2004d5 /* PROX (200011) */ #define HID_USAGE_SENSOR_PROX 0x200011