Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp670838rwb; Thu, 11 Aug 2022 08:05:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6yOdkIHqvLvnl09wu5MACu83UM5Jjewx8qy7K/I96w2a3DfqFAvhjnKE6gdpCqiUb5AZ9v X-Received: by 2002:a05:6402:50cb:b0:440:8bac:1e02 with SMTP id h11-20020a05640250cb00b004408bac1e02mr20501160edb.336.1660230302693; Thu, 11 Aug 2022 08:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660230302; cv=none; d=google.com; s=arc-20160816; b=rffLdYFmyk1eJr/PJp+9SBImrqDVthtBY4xaiR2f5AEpTWik8+YMlc6IlmT+/TPp7U GAGc2JGxQUm5lhBBmp3vK3cTj+czmVqK15NAjW+TPIoWxy+fTECBOZ5pxAwufkGqzhcn ise/jZTEb15LeGggjKNcVu+nrMc+Fe8bA5ivL/T53LeUmxb8RrxCCIk72yoiuVG6YnnP Zq8iN+dNPKfop7AHFG6BcRxvP0SDpJSIvx3z3ZwBtq2YodJfu3yy5UrHtj/c88Ktxu/z bdVk5CjAr/5XJJIVKANJ18+UFgA4ES6SPAI3Mayb9aF1HXbCHy8tjNwwtlPkMxo7dnw9 NrFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=++ZqY1BZyai6BnYEhDrDVtdrefmCHt0gEKhmVF9bC2A=; b=qykZpHwLuXl4WQfTkTcyRDtuaulX2cZLR3JVkXc8ySRMSRFKyhSsz5i7fZJcP+A3Nh zwEgbldeB0KjfuKIbe9osSi3smPqQPkTS56c8DOMGg5SH7ZQo06FsS8I5WrofF4x6aH7 NtACyZuAqJVJylgy6/EqdI3EQN2MDADcY10bqHk9oMUf5ooP21zUI3zeyW9dzx+nQaBs WoUKu4TCR75hOpGHPh+NJ1xODIgL1WX/LsQefkHyX44hcS7yKGEXimUT6/bmNALmdWBW tbsb4LbQuc7lhghSDYcyaERYtG4KIW505ryymCF5p4ZsSGdg0TEd1AMLvDzStotenBl/ KqIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KbTB80ZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb38-20020a1709071ca600b007309eacb2f9si9112091ejc.468.2022.08.11.08.04.31; Thu, 11 Aug 2022 08:05:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KbTB80ZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235361AbiHKOSo (ORCPT + 99 others); Thu, 11 Aug 2022 10:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbiHKOSm (ORCPT ); Thu, 11 Aug 2022 10:18:42 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A28374368; Thu, 11 Aug 2022 07:18:41 -0700 (PDT) Received: from [IPV6:2405:201:10:389d:42df:ae4c:c047:294c] (unknown [IPv6:2405:201:10:389d:42df:ae4c:c047:294c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: shreeya) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2C53C6601D2F; Thu, 11 Aug 2022 15:18:37 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1660227519; bh=cxtX52V91rWJFD9wPxapVB6Hwe73avZEgO2Qdf4hr04=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=KbTB80ZWlWeZWqxytaJFOUXXSKsPz2KJ+RSf+REqW+DsjnZjt40AbMP1FJ4bMn9SY Na8FnTNON/tlBd15EPd8sc9S0F3HBhxMVIRHEaSTnZeNU+FV2Cve/AD5wGXBzorAHx AVTIlJthTpFxBL9zh327SNu/1VX0TpRHT1mdZyq1D3NWvnKIvds/6b7cEirtUlD8zt 8cvEBiSgId0BGnUZzqiuK6vhnJSCkWCLNE2VNc22MvnA6KYfLSax2G6kAFmAKAUIij qH0RhF2d1GRGJW0Gu8wZIiEMYwjgohWX6HbV7etL46gljYjpOoTfQ2JWKc+cuxLRUz vMB38egaHZ2GQ== Message-ID: <4e481aa6-eebd-a934-72de-27f0e5e04fb1@collabora.com> Date: Thu, 11 Aug 2022 19:48:33 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] iio: light: Add raw attribute Content-Language: en-US To: Jonathan Cameron Cc: jic23@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, krisman@collabora.com, kernel@collabora.com, alvaro.soliverez@collabora.com References: <20220811101443.499761-1-shreeya.patel@collabora.com> <20220811142518.00000256@huawei.com> From: Shreeya Patel In-Reply-To: <20220811142518.00000256@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/08/22 18:55, Jonathan Cameron wrote: > On Thu, 11 Aug 2022 15:44:43 +0530 > Shreeya Patel wrote: > >> Add IIO_CHAN_INFO_RAW to the mask to be able to read raw values >> from the light sensor. > Why is this useful? It's rare to support _PROCESSED and _RAW for the same channel. > Normally occurred to avoid breaking ABI. Hi Jonathan, For some context, we have been using a downstream driver for ltrf216a in steam deck. The formula for Lux calculation used in that driver is incorrect which we corrected in the driver that has been upstreamed now. The userspace code to handle brightness on steam deck uses the in_illuminance_input value from sysfs and multiplies that value with some constant stored in BIOS at factory calibration time. With the Lux calculation change in upstreamed driver, in_illuminance_input gives us a different value leading to change in the brightness on steam deck. It is also not possible for us to recalculate the constant stored in BIOS. We need a way to add some magic in userspace code so that brightness adjustment works like before. So I'm trying to calculate a constant using the current formula that we are using :- ( greendata * 45 * LTRF216A_WIN_FAC ) / ( data->als_data_gain * data->int_time_fac) Except for the greendata which is ALS_DATA, I have all the other values to calculate a constant, hence, I added RAW attribute so I can read the ALS_DATA value from userspace. Thanks, Shreeya Patel > > Jonathan > >> Signed-off-by: Shreeya Patel >> --- >> drivers/iio/light/ltrf216a.c | 13 +++++++++++++ >> 1 file changed, 13 insertions(+) >> >> diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c >> index e6e24e70d2b9..a717bf99bd2a 100644 >> --- a/drivers/iio/light/ltrf216a.c >> +++ b/drivers/iio/light/ltrf216a.c >> @@ -93,6 +93,7 @@ static const struct iio_chan_spec ltrf216a_channels[] = { >> { >> .type = IIO_LIGHT, >> .info_mask_separate = >> + BIT(IIO_CHAN_INFO_RAW) | >> BIT(IIO_CHAN_INFO_PROCESSED) | >> BIT(IIO_CHAN_INFO_INT_TIME), >> .info_mask_separate_available = >> @@ -259,6 +260,18 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev, >> int ret; >> >> switch (mask) { >> + case IIO_CHAN_INFO_RAW: >> + ret = ltrf216a_set_power_state(data, true); >> + if (ret) >> + return ret; >> + mutex_lock(&data->lock); >> + ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0); >> + mutex_unlock(&data->lock); >> + if (ret < 0) >> + return ret; >> + *val = ret; >> + ltrf216a_set_power_state(data, false); >> + return IIO_VAL_INT; >> case IIO_CHAN_INFO_PROCESSED: >> mutex_lock(&data->lock); >> ret = ltrf216a_get_lux(data);