Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp60942lfe; Fri, 15 Apr 2022 19:31:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnt1oMsqq5uh+dZSZj5v8eG+h3OZeyGsdpQ2eT9lTjPis5cu9ZymaZBgrco61VBuRY9CVR X-Received: by 2002:a17:90b:3ec3:b0:1c7:24c4:e28f with SMTP id rm3-20020a17090b3ec300b001c724c4e28fmr7250781pjb.191.1650076311584; Fri, 15 Apr 2022 19:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076311; cv=none; d=google.com; s=arc-20160816; b=JrzcqeT94UBfEQb9RIh6pVWEJ4qK6t4tWBtSNieV+Gr5L6m040xi3KI3Mulr8M7iGV YzqgxMWsOboauXBQcZYQM3hXZJ8L8/z2a4KeYU8bGPEypiBE8Buf8YIzhuwqKE58X9bE 6hD3zZM8q8BvSs2+DGhTvoMQC9ar4NetZrY5VFuY5O4oB6A3pVft7Ad2f/lPzEfu0Ahf fOQmNLpcpYDJt/LSlSo2eWt0iam6lKV7J6tlOBEDC4/edjalNpBukqek+AzglDb5wtF9 JNbfoiXcRfTDbqwsjYiTRu2Cx5HI6oXX9Nj8KHFnLWTY15l/Y0y5fAipseBvVwTJCJ0a kGdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sI85OEbV26wWmvlA824fWyu89BOYDpvXt00298VQTSQ=; b=ymkleOMZf5u3TGjbVCkkjsr+qeDfX3w1Fe7YbMyIwWgqLGCgFBMCx9rlCrwEWP/rTy GFjIlR1PH22GGi6J2lrM6hX8hkT/Bs/wfmbSsIxXRa8jyYAbWHNr0HNvQG0NVLwKRjyP Vxtn3ELYxUcidMeAZ5lc9AGhFDpGTDHep/MM/jET9F8aqCP4j5jctXSJSnq2q5+f4tOB EVRo0chT4Qj/E2Q4ADFcZwTVfToBtdrxsK4MpxxPqojHGLhGgcgRA67hb6Ul86MILTgI hTbHWLB9u/xYSahQVDrYO6H09Ks6EZbV+qEk1iPthHF1q7u4T4AjTRxGlnGhYrnWBRBV 4Vzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=R92ppw2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x62-20020a638641000000b0039d6958e6afsi2881198pgd.492.2022.04.15.19.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:31:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=R92ppw2x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFC60135FF3; Fri, 15 Apr 2022 18:42:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351621AbiDOIxI (ORCPT + 99 others); Fri, 15 Apr 2022 04:53:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351544AbiDOIxB (ORCPT ); Fri, 15 Apr 2022 04:53:01 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F346B82E6; Fri, 15 Apr 2022 01:50:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: aferraris) with ESMTPSA id 684331F47DD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650012632; bh=qJ1psTuJGHQwoRp08D0s9aPEEp7dXucZN9uyn4vkW2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R92ppw2xMQBaPq2XBYdHITM9Qn9ensz/3XCBDC5FwQVVIaigQG+EWX+3OQzWUbiPr EWMBYGC/mN4wDMukmdgjK+zhFtsW+alOdcE7SFCzcfP85NIBTMPjMUOrMq73Q/QxRG O9S3HbWYF40mogsqYKqBBqjy3oIFUYYB9CUBnutbGzqhdgNum3jCk5HXNm4jnXDvCc G1efsrq8uKiQQilQSLSRrxmJQ+SF3Ged2rmqgUYINICFwtKjhKEbwuMJFRkyw0aWLm ErRNt6YANY1rQSkw4BhFnqlqFfRKb6UHJ0/TMEV8179Fq0SHcXJQQBG1Z6QF7w58KO 0+l5RC6nDPXdg== From: Arnaud Ferraris To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: [PATCH 2/2] iio: stk3310: Export near level property for proximity sensor Date: Fri, 15 Apr 2022 10:50:18 +0200 Message-Id: <20220415085018.35063-3-arnaud.ferraris@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220415085018.35063-1-arnaud.ferraris@collabora.com> References: <20220415085018.35063-1-arnaud.ferraris@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no 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 This makes the value from which an object should be considered "near" available to userspace. This hardware-dependent value should be set in the device-tree. Signed-off-by: Arnaud Ferraris --- drivers/iio/light/stk3310.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 1d02dfbc29d1..7792456323ef 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -106,6 +106,7 @@ struct stk3310_data { struct mutex lock; bool als_enabled; bool ps_enabled; + uint32_t ps_near_level; u64 timestamp; struct regmap *regmap; struct regmap_field *reg_state; @@ -135,6 +136,25 @@ static const struct iio_event_spec stk3310_events[] = { }, }; +static ssize_t stk3310_read_near_level(struct iio_dev *indio_dev, + uintptr_t priv, + const struct iio_chan_spec *chan, + char *buf) +{ + struct stk3310_data *data = iio_priv(indio_dev); + + return sprintf(buf, "%u\n", data->ps_near_level); +} + +static const struct iio_chan_spec_ext_info stk3310_ext_info[] = { + { + .name = "nearlevel", + .shared = IIO_SEPARATE, + .read = stk3310_read_near_level, + }, + { /* sentinel */ } +}; + static const struct iio_chan_spec stk3310_channels[] = { { .type = IIO_LIGHT, @@ -151,6 +171,7 @@ static const struct iio_chan_spec stk3310_channels[] = { BIT(IIO_CHAN_INFO_INT_TIME), .event_spec = stk3310_events, .num_event_specs = ARRAY_SIZE(stk3310_events), + .ext_info = stk3310_ext_info, } }; @@ -581,6 +602,11 @@ static int stk3310_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; i2c_set_clientdata(client, indio_dev); + + if (device_property_read_u32(&client->dev, "proximity-near-level", + &data->ps_near_level)) + data->ps_near_level = 0; + mutex_init(&data->lock); ret = stk3310_regmap_init(data); -- 2.35.1