From nobody Mon Nov 25 09:26:08 2024 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D2411D0F56 for ; Mon, 28 Oct 2024 10:12:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110349; cv=none; b=dAYSBq0NqUQd0xr9/26D49JimxiMmS93+gywe75GoZHDHeZ8P0kLjC8UiUKiXQOxW2lCYvjy8sT3NBnc+aMeG2U5XkXFty0RAroRVIr2omVZg4rUGWP3YHttJ11SSQbrr8VZO43zdkhAO16r9cdtMPhirTb+2WsoXaYpJ1X2QZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110349; c=relaxed/simple; bh=E5IKpWlBrs6BrNxKGj8gL69lGAFGxkNE1Vi/39M/35Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PVzbzg24YUMqATXCRUzFR+KElQ+rzoOAO3rCnfmKBPMYQ01/CBFGjYCDAr5IBhqyOFI3dIBiy4v09K/nLWBaVpeRYbAdKn6GcDu2IbE88b/hxe3zZU9c5fcx5E74vNbeFAKr+7b0BfOKu4TqoYw0NHNHw1m0Q+Cm6+UDV/lxN60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Y59vsHYe; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Y59vsHYe" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b14443a71eso427142985a.1 for ; Mon, 28 Oct 2024 03:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730110345; x=1730715145; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=XRIQcTwMhYqGctEPu/xoF4uEWBP35j2ZdxAtYHSbb2E=; b=Y59vsHYecOLkSWgZLMMjGcvS6rtWiYWPwkWp/UtBM2/+2/K1eeS7nRhcpxJ5FBqxLU fJNqw4hGZuJRDiCoNfOour4uOP6iYVMluRQy2rnZUXXE8DQOnC0M7LfmgFP1GR+g0DNO pgq9Rktkud2RsBaYUNC33C1O1tnkVbWZZbZP0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730110345; x=1730715145; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XRIQcTwMhYqGctEPu/xoF4uEWBP35j2ZdxAtYHSbb2E=; b=w/jvWtbVj4ZygZOuaV9cEMp/BRSXxgh1Ct6hSZvg80AMx1DJFCenn7UHs16bS7lVMx UUvemJAJzDq6aftiS/vlFs9pF+wCljXLFTjQI3FeVqokT6LsBq3lBj1pHj83fbafx8pr qhk2k/pbx2JU/93+VijkY0CEH3KKM6M3V132LB1IR3nrQIRaJsagrwSE6Ucs+R63zQFX 1iLP2xLwf+SNUuhDolZbjkeurcAsCZ8Hhkv2dbLT+wJBuJFs4uERxtZZ490KhhVgLd3l rm2vKjsRb9wC9Q8SU9O6abp5a2rDQMBDsC6l+N1doRZrPxkfSL///qb/Tj0yN+lHaRTR 7iVg== X-Forwarded-Encrypted: i=1; AJvYcCXyltD4TESKgZrJoIpJwQGfO7R2clLdxXyYyl1OGZWxKFOcJp3WgrNJV7zZ6oqs3lkHjp18DyZjDUKSZ5I=@vger.kernel.org X-Gm-Message-State: AOJu0YzE5+YvIIS+pQLAuhAm1anqIfJya6jLro/Y6G04s1d232t+7AYH G+NJRsLY/KFX6iq7Cn5U/LvGoj72aWpaBXKEKzOHfq/OrNG5wN/4966fpdViFTccgXEdRTitixg = X-Google-Smtp-Source: AGHT+IHsZfrL95wV+H91XB+R0gfoIc0eDU5H8YGXxr3YjqWTDf3Oef34MoOXLotCH0ugOLZSOTidVw== X-Received: by 2002:a05:620a:2482:b0:7a9:d14f:2374 with SMTP id af79cd13be357-7b193f3e043mr1206071685a.44.1730110345653; Mon, 28 Oct 2024 03:12:25 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d279126sm305483385a.9.2024.10.28.03.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 03:12:24 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 28 Oct 2024 10:12:21 +0000 Subject: [PATCH v2 1/5] iio: hid-sensors: Add proximity and attention IDs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241028-hpd-v2-1-18f6e79154d7@chromium.org> References: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> In-Reply-To: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Cameron , Srinivas Pandruvada , Lars-Peter Clausen Cc: Harvey Yang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 The HID Usage Table at https://usb.org/sites/default/files/hut1_5.pdf reserves: - 0x4b2 for Human Proximity Range Distance between a human and the computer. Default unit of measure is meters; https://www.usb.org/sites/default/files/hutrr39b_0.pdf - 0x4bd for Human Attention Detected Human-Presence sensors detect the presence of humans in the sensor=E2=80=99s field-of-view using diverse and evolving technologies. Some presence sensors are implemented with low resolution video cameras, which can additionally track a subject=E2=80=99s attention (i.e. if the user is =E2=80=98looking=E2=80=99 at the system with the integrated sensor). A Human-Presence sensor, providing a Host with the user=E2=80=99s attention state, allows the Host to optimize its behavior. For example, to brighten/dim the system display, based on the user=E2=80=99s attention to t= he system (potentially prolonging battery life). Default unit is true/false; https://www.usb.org/sites/default/files/hutrr107-humanpresenceattention_1.p= df Signed-off-by: Ricardo Ribalda --- include/linux/hid-sensor-ids.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index 6730ee900ee1..8a03d9696b1c 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -30,6 +30,8 @@ #define HID_USAGE_SENSOR_PROX 0x200011 #define HID_USAGE_SENSOR_DATA_PRESENCE 0x2004b0 #define HID_USAGE_SENSOR_HUMAN_PRESENCE 0x2004b1 +#define HID_USAGE_SENSOR_HUMAN_PROXIMITY 0x2004b2 +#define HID_USAGE_SENSOR_HUMAN_ATTENTION 0x2004bd =20 /* Pressure (200031) */ #define HID_USAGE_SENSOR_PRESSURE 0x200031 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 09:26:08 2024 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837CA1D356C for ; Mon, 28 Oct 2024 10:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110351; cv=none; b=pIxdyeS9vFUhR3Y9BLb4sKP7Ksxo17CAIKO+GbESyDMOPvaAESbqIz61MLLuoRF7FprBdLBsgSlklFdRyWiCvk8UtZvxNwrGgv5jAMuszrP8kwPWCGutpe4enIOOFY6cPvqKRdl+YC5fEKkASIeN0x3uru44/vM4Folb5bLFBU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110351; c=relaxed/simple; bh=NTUbVMYf2x+7q0/8Barwlk+9iZKYWLsfR/svD0SOK6M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GhBCm43is/B1y8hJDVhGh/7XBtJRfNOnzSM5FtXLCV8eiX39hBBi9Q/SJg+HY//BXBDK7jjJUgHhQw8j9X+fs6E5uozBPcfWyV5mVOuuNvvTMrAIPRwrBGSzBpc5SjVtGXrxuzqEqRHhKYL1hw7pnDYCqYqa96UAnnXag1FKd2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=d3oHDZMt; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="d3oHDZMt" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b12a02596aso271001585a.2 for ; Mon, 28 Oct 2024 03:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730110348; x=1730715148; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gQttLL6CFS2JGt87dEF+H1Jt5OZPaXEa5P0U/qvO3f8=; b=d3oHDZMtR18DuCbqysVGh6pi6eeljQ3JK6Yz2PfKryIKssvbyVizk60igQBz6e8yM6 17T5GLtrlJUjQFl5kuhwV2LZks0X0GJzL2RumsNmGypwYTx51+jrHdi4mj+acaSSqqYa 5JLeen0kjS3O9ot4+miMlPaofp/x+xu5dD/l0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730110348; x=1730715148; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gQttLL6CFS2JGt87dEF+H1Jt5OZPaXEa5P0U/qvO3f8=; b=K8wZ0FDBT1fIXDGfxqu09MbGES/DhcXHyOv1ZAJ5xSt/DR/gM3hWGn3ZXHj+Y/f6Zw EaXtgVRUt6mdUi156h59s7Mx5LJICBxYx5an7GNZnhoILcb1BRBeGZdVr6kmdxBSzlfk WIm4c1pEDV1i892AqP5sPgT18fI8U8FIlH1piMPRGjprq2ygSiru/1qMVpC3KCVPZ1Jo b1wrPSgWz/OvyRxzgFdKNifzKgtSiQmC+YEDezn+Hvk4BofUGnJIQtHD2yKfFpGEi000 1BHWb+4uq5HXIm4sY1q0N/YV3pkB2vAC/qV/i2Vi55FRjoMrXDtasST4fF3Hy1H+o99G 4Tcw== X-Forwarded-Encrypted: i=1; AJvYcCX98hSxFEO7ouLx7QwjgELslm7tM/p/HBkjt6Dw64xHBtuOD2+hndrByKzy8FKYSClXkvgHfeE2Y6Prc78=@vger.kernel.org X-Gm-Message-State: AOJu0YylBYLdOiF/VMskOtMNblds5cV4QOVLibbLRaqNzD6/0uwXRfye 6c1PFgZEo9Zc5pRyZiW5p4/0zA3FJJ3Jdb+pvJg8R8ZeTtXfXeaC6SE1LIsQMurz8ZZanHj7xQc = X-Google-Smtp-Source: AGHT+IE7gju3lR9oh1XlvsgIv53d3OKuEjmakLCZimRscmiZdz5oon55ZQwCRr1XRbsUh4kcj4mSzg== X-Received: by 2002:a05:620a:2413:b0:7b1:558e:97b0 with SMTP id af79cd13be357-7b193f75ca1mr1105568885a.66.1730110347886; Mon, 28 Oct 2024 03:12:27 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d279126sm305483385a.9.2024.10.28.03.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 03:12:26 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 28 Oct 2024 10:12:22 +0000 Subject: [PATCH v2 2/5] iio: hid-sensors-prox: Factor-in hid_sensor_push_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241028-hpd-v2-2-18f6e79154d7@chromium.org> References: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> In-Reply-To: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Cameron , Srinivas Pandruvada , Lars-Peter Clausen Cc: Harvey Yang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 The function is only called from one place and it is a one-liner. Signed-off-by: Ricardo Ribalda --- drivers/iio/light/hid-sensor-prox.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-se= nsor-prox.c index 26c481d2998c..d38564fe22df 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -153,14 +153,6 @@ static const struct iio_info prox_info =3D { .write_raw =3D &prox_write_raw, }; =20 -/* Function to push data to buffer */ -static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *da= ta, - int len) -{ - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); - iio_push_to_buffers(indio_dev, data); -} - /* Callback handler to send event after all samples are received and captu= red */ static int prox_proc_event(struct hid_sensor_hub_device *hsdev, unsigned usage_id, @@ -170,10 +162,10 @@ static int prox_proc_event(struct hid_sensor_hub_devi= ce *hsdev, struct prox_state *prox_state =3D iio_priv(indio_dev); =20 dev_dbg(&indio_dev->dev, "prox_proc_event\n"); - if (atomic_read(&prox_state->common_attributes.data_ready)) - hid_sensor_push_data(indio_dev, - &prox_state->human_presence, - sizeof(prox_state->human_presence)); + if (atomic_read(&prox_state->common_attributes.data_ready)) { + dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); + iio_push_to_buffers(indio_dev, &prox_state->human_presence); + } =20 return 0; } --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 09:26:08 2024 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3236C1D5164 for ; Mon, 28 Oct 2024 10:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110353; cv=none; b=J6k5hpj31UDcTWZuXdvejChzHlaNVFnpRGkYsibF6dJtxjWkuV3E1dQiPCKMLdhJ+zkt0QQBAyyDV1uZOrnQs9U/Y7O7wiAzYSLnZI+I9G3rPDmSSFkoTrKmd+pKHa0bNpMvr2ShKAUoX8bnNtddxDzf7ZJLYT/hb0cQSjNnnMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110353; c=relaxed/simple; bh=4bCSwXGldVFEtUT5qrvYVydkbPDWuToQV+lF2z5ko1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nJ7bIexFL9qbZ1ALMGUZasNH5DB5jrG9zOZwMF6J9JTHgGmIi7JuVZF0zYY7ABh2vKDy+Q2zLrjMs/h1HsgVulqhYLbw/w3L0+K7TRa7IZ4cvXwMSvId9wAzPkbfrRNYDtL+u3OYoBDoKe0tsJNV1JOBbPSipESLtnQ4HtiaVDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=c7gFfzld; arc=none smtp.client-ip=209.85.210.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="c7gFfzld" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-71850708dc9so2460628a34.0 for ; Mon, 28 Oct 2024 03:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730110350; x=1730715150; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9/Nw+Z2C8++SkotXhnvxy5oczDl/NlKLGO4AgXeyxps=; b=c7gFfzldP44+pIcn7kWVc/GEBmRlzRW9K7L7u0J8Izx5y8VPQppRx3YkLhEzlAEcvJ 1SMGbxEuDOTw5mdgWWSSx1I3YRYMcM76gu8QZgVpEfPJcgfhFFAVo9AE/D16N4fgTTxk /ynUpCAbBxzHDrGyhTpmBiLM/GVCA7VGsOiiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730110350; x=1730715150; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9/Nw+Z2C8++SkotXhnvxy5oczDl/NlKLGO4AgXeyxps=; b=iqt5Ul2BFcoCcv6fPBw6uGJm86qrrLTDLuANcrl6+W/OCrCySTdBF70j5GcfNYVE1V rC/JJOwMAvgDkOmr9xnCFptw7AxzH7zJKxHb089YGarRAIwPRss0SLRs01FrXflHMUD3 mJ+nP2L0uacjFS4IFhVyoxrUKlyouPvjOuomtojX90jCwS9yIUqkdDduk3nTQ7EfS0Gl 3NQwZWWzmJlebNFm3YeefX6+pPz1hfgbg4hH2uIYEpJPW9sezhLItuzvUg2UAhTwausf DrezikjM6404O6E52HfNugqMLdycJCN5VCiLfK+dGqefDfr+XSBXK5/iVQDnhLiwEzkv RATA== X-Forwarded-Encrypted: i=1; AJvYcCWGEb2JTFaMiNNTLk28C+Y96eTNl36y/dGryyKSdQGu1tqyrJpszTF2P30swRlFFRkqTVySe5e6je0Uz9U=@vger.kernel.org X-Gm-Message-State: AOJu0YxrCrjYE1cEkGxitzEku+2RdfxqIR7TX5q+GfcYuzQUG724oim0 wom905Zmn2Xos/6iikhnfOjUSDCWbhnrTJWvsGcQBJ2Tnlz98tSgxeR3Y+TnMRItrI7PFyBPAi8 = X-Google-Smtp-Source: AGHT+IHU7X7YnOpDH71s5rrRZNp8zyVeEUWpYp93iX9QSZPr5jCTuWTJHx74iwaLdzUD4h7eRmC4bA== X-Received: by 2002:a05:6358:57a2:b0:1bc:7c89:6018 with SMTP id e5c5f4694b2df-1c3f9e6315emr78856255d.9.1730110350005; Mon, 28 Oct 2024 03:12:30 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d279126sm305483385a.9.2024.10.28.03.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 03:12:28 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 28 Oct 2024 10:12:23 +0000 Subject: [PATCH v2 3/5] iio: Add channel type for attention Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241028-hpd-v2-3-18f6e79154d7@chromium.org> References: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> In-Reply-To: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Cameron , Srinivas Pandruvada , Lars-Peter Clausen Cc: Harvey Yang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Add a new channel type representing if the user's attention state to the the system. This usually means if the user is looking at the screen or not. Signed-off-by: Ricardo Ribalda --- Documentation/ABI/testing/sysfs-bus-iio | 7 +++++++ drivers/iio/industrialio-core.c | 1 + include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 2 ++ 4 files changed, 11 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/te= sting/sysfs-bus-iio index 89943c2d54e8..d5a2f93bd051 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -2339,3 +2339,10 @@ KernelVersion: 6.10 Contact: linux-iio@vger.kernel.org Description: The value of current sense resistor in Ohms. + +What: /sys/.../iio:deviceX/in_attention_raw +KernelVersion: 6.13 +Contact: linux-iio@vger.kernel.org +Description: + Boolean value representing the user's attention to the system. + This usually means if the user is looking at the screen or not. diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 6a6568d4a2cb..bdfb51275b68 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -95,6 +95,7 @@ static const char * const iio_chan_type_name_spec[] =3D { [IIO_DELTA_VELOCITY] =3D "deltavelocity", [IIO_COLORTEMP] =3D "colortemp", [IIO_CHROMATICITY] =3D "chromaticity", + [IIO_ATTENTION] =3D "attention", }; =20 static const char * const iio_modifier_names[] =3D { diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h index f2e0b2d50e6b..12886d4465e4 100644 --- a/include/uapi/linux/iio/types.h +++ b/include/uapi/linux/iio/types.h @@ -51,6 +51,7 @@ enum iio_chan_type { IIO_DELTA_VELOCITY, IIO_COLORTEMP, IIO_CHROMATICITY, + IIO_ATTENTION, }; =20 enum iio_modifier { diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c index 8073c9e4fe46..ed9a677f1028 100644 --- a/tools/iio/iio_event_monitor.c +++ b/tools/iio/iio_event_monitor.c @@ -63,6 +63,7 @@ static const char * const iio_chan_type_name_spec[] =3D { [IIO_DELTA_VELOCITY] =3D "deltavelocity", [IIO_COLORTEMP] =3D "colortemp", [IIO_CHROMATICITY] =3D "chromaticity", + [IIO_ATTENTION] =3D "attention", }; =20 static const char * const iio_ev_type_text[] =3D { @@ -183,6 +184,7 @@ static bool event_is_known(struct iio_event_data *event) case IIO_DELTA_VELOCITY: case IIO_COLORTEMP: case IIO_CHROMATICITY: + case IIO_ATTENTION: break; default: return false; --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 09:26:08 2024 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F0961D5ABD for ; Mon, 28 Oct 2024 10:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110354; cv=none; b=JTnvbI6d9zfQIk2v90hYaM0E2LEyFfdtyTfZXxlwivH0E6aMoU9vmQrdTs8Fc0nNmr7iWfTG9k9XgVk265wz+NXow9UiPYEKTJRINjKDHnwaIQnIspHiR3cVrb2mJ4jQ+wOz3bF2w5Ht3jL4DthIGzCFjQiP/cSkdJ9aDRritz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110354; c=relaxed/simple; bh=CUtvkf+t59QX4prslptAVYmO9B9yIfrnRI6r3hKSoAg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=COXh+OY0LYbZV94aK4FTlI0TvWI82pwFqZ7YNz2ZobzH37GrukRW00KUXE5zRPGS8Hs6qieblgxQUJ0ySIaKiFCQVA2SEBgDxzyTUiBTgUNlj1w7N3JPJdPXPFrP8SGoRpRtcJMVy7X/0xqc5JhfnYqyBzCTK82U050SNLgzFJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jJtFebvL; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jJtFebvL" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b1488fde46so327173985a.2 for ; Mon, 28 Oct 2024 03:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730110351; x=1730715151; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=adgmJOhHcaFkex36EFAe1BXPWl8Ng3rQHGIFjAA8UGA=; b=jJtFebvLLF0asJft9hXpQ6nSjl4dbDOVD1SFuDbo4Vk7qc2g4nwkH28z2JhA6sC/pQ t9hKRWlYJaAg08UYdWNkMmRSJT2GeeqWj52GIowJN86J79jdYHohkERrAYAJG9nBwIC8 nJ8E9fipb28kE8RilyhQRekd7L4aooWnhR42Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730110351; x=1730715151; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=adgmJOhHcaFkex36EFAe1BXPWl8Ng3rQHGIFjAA8UGA=; b=BDRFbygukn9rmDTkZR7XnAObq1Cn7Uecqs+z4hLCKPbVABpzriXeYiprLaMoxrPwqd NnC7o69Tq2wBzsDD9F5FOcwhWFvsMM/cjSQrY1ohYIaxrR3qg8900RWYJELMHT6ekshy /K0HdbW2TaxK2LHK74yXqep96dc1nLEiXyb/5zHuOHX3uXyDH8b2fpSgiFLu4oHJzk+g JdlFgPZQIDAadx7c01hBHdQkkcts1tu6EZTdSkYcH0soQ6ztV9KqS92A+DLrxgVfNAP0 5Wbm2uRXnANyK/NLk1Y6CykVNOPnXFnkr4iEQQrTkeR2DzhdFc/Ifq3aTD2tusdA6suY vyJA== X-Forwarded-Encrypted: i=1; AJvYcCXUL1KvrEbI6/IdWYrlS/W68UJBK/o4aCamKp45Zx0PGcIS4fcXnFPMCJbzBSRwV7/2PlBemHOhKsmCnZY=@vger.kernel.org X-Gm-Message-State: AOJu0YyTIil26nVo6FCSI3m5TnTQcaR6ZtXpGKZkplYumgElPNvF1xW1 lhh1OznSdhBAn5hTLJvFqot54xBRP+ASlEv+wNohgLfpQXTiqQpS0ghgvg32y0+AMq61l35Ivuw = X-Google-Smtp-Source: AGHT+IEvNa1/u021S1k1XErRR5bkD/RvaCZqUFQg81oUJKijF5rpiMRdpeKxB40Z9diyYoooWSmBCw== X-Received: by 2002:a05:620a:2801:b0:7af:cf73:d70 with SMTP id af79cd13be357-7b193f0b137mr1497661185a.39.1730110350726; Mon, 28 Oct 2024 03:12:30 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d279126sm305483385a.9.2024.10.28.03.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 03:12:30 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 28 Oct 2024 10:12:24 +0000 Subject: [PATCH v2 4/5] iio: hid-sensors-prox: Make proximity channel indexed Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241028-hpd-v2-4-18f6e79154d7@chromium.org> References: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> In-Reply-To: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Cameron , Srinivas Pandruvada , Lars-Peter Clausen Cc: Harvey Yang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 We are going to introduce more proximity channels. Make proximity a indexed channel now, in a simple patch, so the change can be easily bisected if there are any issues. Signed-off-by: Ricardo Ribalda --- drivers/iio/light/hid-sensor-prox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-se= nsor-prox.c index d38564fe22df..0f12a8a83790 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -40,6 +40,7 @@ static const struct iio_chan_spec prox_channels[] =3D { BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index =3D CHANNEL_SCAN_INDEX_PRESENCE, + .indexed =3D true, } }; =20 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 09:26:08 2024 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB0361D61A2 for ; Mon, 28 Oct 2024 10:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110356; cv=none; b=OYIsZhA8fSMg2mjkPNHSI5CivzWatDHlCZoYoqaL4tyytNp6koAl7u1ic/vzv3XW/ubK8JNTfPo9ddbCbGiH4WqG3M4UqOmHx0ZQGN/nS23WcRB8gpSopWYSQK2GgQcvdDhGumsiX7qgGi88NuoLs8RxQ5YdzU7wyu3piDdNhXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730110356; c=relaxed/simple; bh=NtTBjVPCukfy6qXUeEEjV+EaTIUrNtFyd0P2oXLNfLs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LQ2LvdJ2KeM/gyi4OfuXjFYyhHnM9Jv4j1gDpQO+smugIpTElbLKXFwJIH2+t7/lYXdskKk6wHXI8UKxV7T4Nq1kPIGyl8bEqUKAexbdE8HFbPvH2RRP7lrQX/91Cep3+tDDxjtCSeR/NIgSlCmg4xdQpdIq2vVPK5tWykuCCRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=RQMHDrLQ; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RQMHDrLQ" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b152a23e9aso324259785a.0 for ; Mon, 28 Oct 2024 03:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730110352; x=1730715152; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gYaDRZS7eycBx6nL/lvgNDYBfbu64MJ0DrtpIvQKBd8=; b=RQMHDrLQhO+d7sIe6iDrjc/BIR7bmFWgo+kwrzecqQ+FVGDDICatqCFL1feH8GYYLx cFxF77rFVzWQuCl65nUsHeIt+JXtmPVtS4lB2ADYBXvJSyEyX9/zgT3yiRaJovGsh3aa qHImNSge40P5mtGGMRC/COdvXRFQ2WZdSDdbQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730110352; x=1730715152; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gYaDRZS7eycBx6nL/lvgNDYBfbu64MJ0DrtpIvQKBd8=; b=E1QXzK+FcnBVnzX9iINNyptVhJs3HwOdcqHs68+bcJYfM3vBgXUrVCrvlhuO45GWDs d5sT8imp18QCWvEBoOgoeyyUl50ak25MrfcMbN21vuK4voAVcshiW6v5bjata6h54tTx 3Saz1J6UYk9w3dB9ha6MjbUo+yAaf0ZEF77TXcG/hSKFGfxPnw3/7A2h7fJ4UMQA2WgV L59iLc8D6kfcuEOdtL5h2c3Fz10vd/VNd97I1939wyS2+uyWqPu4DEzq7NNJpolEcvqQ 9bMoqdg0iAlO+rxHHYyT60ghONBziOybnbEWOdfjHKlw5qo6uXHJXJ4pnq3ILPnKYXkY bCvw== X-Forwarded-Encrypted: i=1; AJvYcCWrDvDyBpmBJy552xL1iqZ+NRc+2XsIJ3nqAL9Vm1HowKPjrcXHnJqBL8YPl5utBlTSM1zoYa9SuHc6hFo=@vger.kernel.org X-Gm-Message-State: AOJu0YwR9NcH6H2knjpCVC2ERHudxZZmJ0ma8mCSbaEx7gZFidLlnuir EUBkuvBznZhiFMd7fUGeGGaeVQyM18YujXBnGhOoqIelT5cLXRkx2Pfvo56KcZnYTUsKgtcG61k = X-Google-Smtp-Source: AGHT+IHNdqRNeM3bvpX5KZk4zUyVm0jdxPChZwsuv/lKavdxSlXErx5iCwCVNzmhBEo3DVOxqjQN6g== X-Received: by 2002:a05:620a:2904:b0:7a9:a991:f6d7 with SMTP id af79cd13be357-7b193f4dcb4mr1057542585a.48.1730110352056; Mon, 28 Oct 2024 03:12:32 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b18d279126sm305483385a.9.2024.10.28.03.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 03:12:31 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 28 Oct 2024 10:12:25 +0000 Subject: [PATCH v2 5/5] iio: hid-sensor-prox: Add support for more channels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241028-hpd-v2-5-18f6e79154d7@chromium.org> References: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> In-Reply-To: <20241028-hpd-v2-0-18f6e79154d7@chromium.org> To: Jiri Kosina , Benjamin Tissoires , Jonathan Cameron , Srinivas Pandruvada , Lars-Peter Clausen Cc: Harvey Yang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Egis620 supports 3 channels: presense, proximity and attention. Modify the driver so it can read those channels as well. Signed-off-by: Ricardo Ribalda --- drivers/iio/light/hid-sensor-prox.c | 171 ++++++++++++++++++++------------= ---- 1 file changed, 95 insertions(+), 76 deletions(-) diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-se= nsor-prox.c index 0f12a8a83790..e6f81d40a492 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -13,16 +13,31 @@ #include #include "../common/hid-sensors/hid-sensor-trigger.h" =20 -#define CHANNEL_SCAN_INDEX_PRESENCE 0 +static const u32 prox_usage_ids[] =3D { + HID_USAGE_SENSOR_HUMAN_PRESENCE, + HID_USAGE_SENSOR_HUMAN_PROXIMITY, + HID_USAGE_SENSOR_HUMAN_ATTENTION, +}; +#define MAX_CHANNELS ARRAY_SIZE(prox_usage_ids) + +enum { + HID_HUMAN_PRESENCE, + HID_HUMAN_PROXIMITY, + HID_HUMAN_ATTENTION, +}; =20 struct prox_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; - struct hid_sensor_hub_attribute_info prox_attr; - u32 human_presence; + struct hid_sensor_hub_attribute_info prox_attr[MAX_CHANNELS]; + struct iio_chan_spec channels[MAX_CHANNELS]; + u32 channel2usage[MAX_CHANNELS]; + u32 human_presence[MAX_CHANNELS]; int scale_pre_decml; int scale_post_decml; int scale_precision; + unsigned long scan_mask[2]; // One entry plus one terminator. + int num_channels; }; =20 static const u32 prox_sensitivity_addresses[] =3D { @@ -30,18 +45,23 @@ static const u32 prox_sensitivity_addresses[] =3D { HID_USAGE_SENSOR_DATA_PRESENCE, }; =20 -/* Channel definitions */ -static const struct iio_chan_spec prox_channels[] =3D { - { - .type =3D IIO_PROXIMITY, - .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_OFFSET) | - BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ) | - BIT(IIO_CHAN_INFO_HYSTERESIS), - .scan_index =3D CHANNEL_SCAN_INDEX_PRESENCE, - .indexed =3D true, +#define PROX_CHANNEL(_type, _indexed, _channel) \ + {\ + .type =3D _type,\ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW),\ + .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_OFFSET) |\ + BIT(IIO_CHAN_INFO_SCALE) |\ + BIT(IIO_CHAN_INFO_SAMP_FREQ) |\ + BIT(IIO_CHAN_INFO_HYSTERESIS),\ + .indexed =3D _indexed,\ + .channel =3D _channel,\ } + +/* Channel definitions (same order as prox_usage_ids) */ +static const struct iio_chan_spec prox_channels[] =3D { + PROX_CHANNEL(IIO_PROXIMITY, true, HID_HUMAN_PRESENCE), + PROX_CHANNEL(IIO_PROXIMITY, true, HID_HUMAN_PROXIMITY), + PROX_CHANNEL(IIO_ATTENTION, false, 0), }; =20 /* Adjust channel real bits based on report descriptor */ @@ -63,7 +83,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, { struct prox_state *prox_state =3D iio_priv(indio_dev); struct hid_sensor_hub_device *hsdev; - int report_id =3D -1; + int report_id; u32 address; int ret_type; s32 min; @@ -72,29 +92,20 @@ static int prox_read_raw(struct iio_dev *indio_dev, *val2 =3D 0; switch (mask) { case IIO_CHAN_INFO_RAW: - switch (chan->scan_index) { - case CHANNEL_SCAN_INDEX_PRESENCE: - report_id =3D prox_state->prox_attr.report_id; - min =3D prox_state->prox_attr.logical_minimum; - address =3D HID_USAGE_SENSOR_HUMAN_PRESENCE; - hsdev =3D prox_state->common_attributes.hsdev; - break; - default: - report_id =3D -1; - break; - } - if (report_id >=3D 0) { - hid_sensor_power_state(&prox_state->common_attributes, - true); - *val =3D sensor_hub_input_attr_get_raw_value( - hsdev, hsdev->usage, address, report_id, - SENSOR_HUB_SYNC, min < 0); - hid_sensor_power_state(&prox_state->common_attributes, - false); - } else { - *val =3D 0; + if (chan->scan_index >=3D prox_state->num_channels) return -EINVAL; - } + address =3D prox_state->channel2usage[chan->scan_index]; + report_id =3D prox_state->prox_attr[chan->scan_index].report_id; + hsdev =3D prox_state->common_attributes.hsdev; + min =3D prox_state->prox_attr[chan->scan_index].logical_minimum; + hid_sensor_power_state(&prox_state->common_attributes, true); + *val =3D sensor_hub_input_attr_get_raw_value(hsdev, + hsdev->usage, + address, + report_id, + SENSOR_HUB_SYNC, + min < 0); + hid_sensor_power_state(&prox_state->common_attributes, false); ret_type =3D IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: @@ -104,7 +115,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_OFFSET: *val =3D hid_sensor_convert_exponent( - prox_state->prox_attr.unit_expo); + prox_state->prox_attr[chan->scan_index].unit_expo); ret_type =3D IIO_VAL_INT; break; case IIO_CHAN_INFO_SAMP_FREQ: @@ -179,48 +190,63 @@ static int prox_capture_sample(struct hid_sensor_hub_= device *hsdev, { struct iio_dev *indio_dev =3D platform_get_drvdata(priv); struct prox_state *prox_state =3D iio_priv(indio_dev); - int ret =3D -EINVAL; - - switch (usage_id) { - case HID_USAGE_SENSOR_HUMAN_PRESENCE: - switch (raw_len) { - case 1: - prox_state->human_presence =3D *(u8 *)raw_data; - return 0; - case 4: - prox_state->human_presence =3D *(u32 *)raw_data; - return 0; - default: + int chan; + + for (chan =3D 0; chan < prox_state->num_channels; chan++) + if (prox_state->channel2usage[chan] =3D=3D usage_id) break; - } - break; + if (chan =3D=3D prox_state->num_channels) + return -EINVAL; + + switch (raw_len) { + case 1: + prox_state->human_presence[chan] =3D *(u8 *)raw_data; + return 0; + case 4: + prox_state->human_presence[chan] =3D *(u32 *)raw_data; + return 0; } =20 - return ret; + return -EINVAL; } =20 /* Parse report which is specific to an usage id*/ static int prox_parse_report(struct platform_device *pdev, struct hid_sensor_hub_device *hsdev, - struct iio_chan_spec *channels, - unsigned usage_id, struct prox_state *st) { + struct iio_chan_spec *channels =3D st->channels; + int index =3D 0; int ret; + int i; + + for (i =3D 0; i < MAX_CHANNELS; i++) { + u32 usage_id =3D prox_usage_ids[i]; + + ret =3D sensor_hub_input_get_attribute_info(hsdev, + HID_INPUT_REPORT, + hsdev->usage, + usage_id, + &st->prox_attr[index]); + if (ret < 0) + continue; + st->channel2usage[index] =3D usage_id; + st->scan_mask[0] |=3D BIT(index); + channels[index] =3D prox_channels[i]; + channels[index].scan_index =3D index; + prox_adjust_channel_bit_mask(channels, index, + st->prox_attr[index].size); + dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index, + st->prox_attr[index].report_id); + index++; + } =20 - ret =3D sensor_hub_input_get_attribute_info(hsdev, HID_INPUT_REPORT, - usage_id, - HID_USAGE_SENSOR_HUMAN_PRESENCE, - &st->prox_attr); - if (ret < 0) + if (!index) return ret; - prox_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_PRESENCE, - st->prox_attr.size); =20 - dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr.index, - st->prox_attr.report_id); + st->num_channels =3D index; =20 - return ret; + return 0; } =20 /* Function to initialize the processing for usage id */ @@ -251,22 +277,15 @@ static int hid_prox_probe(struct platform_device *pde= v) return ret; } =20 - indio_dev->channels =3D devm_kmemdup(&pdev->dev, prox_channels, - sizeof(prox_channels), GFP_KERNEL); - if (!indio_dev->channels) { - dev_err(&pdev->dev, "failed to duplicate channels\n"); - return -ENOMEM; - } - - ret =3D prox_parse_report(pdev, hsdev, - (struct iio_chan_spec *)indio_dev->channels, - hsdev->usage, prox_state); + ret =3D prox_parse_report(pdev, hsdev, prox_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); return ret; } =20 - indio_dev->num_channels =3D ARRAY_SIZE(prox_channels); + indio_dev->num_channels =3D prox_state->num_channels; + indio_dev->channels =3D prox_state->channels; + indio_dev->available_scan_masks =3D prox_state->scan_mask; indio_dev->info =3D &prox_info; indio_dev->name =3D name; indio_dev->modes =3D INDIO_DIRECT_MODE; --=20 2.47.0.163.g1226f6d8fa-goog