Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4615328rwd; Tue, 30 May 2023 07:44:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7V5T5rvG+giDjpVRIZ5OjtCYddNiqJPGq8texyp7/CO9NBQTNDmUk9MSxV/Nvrm16fHvZb X-Received: by 2002:a17:902:f391:b0:1b0:3c2f:db6 with SMTP id f17-20020a170902f39100b001b03c2f0db6mr2039937ple.58.1685457851422; Tue, 30 May 2023 07:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685457851; cv=none; d=google.com; s=arc-20160816; b=krYRZOZSvDKBTeaHkjpSaUYBIXFY2cN4gv67E9mWutBLg/QWAMAC2PRcGUxlNABmmG 9QOR9Ef9X/7HdHoRi8VMuHLJDip8Y4GT0i39YX5bHfLy3cjular7Gzn3pXOrkSyyQzGU yRvftjrjKfniXlHam38AiIq4sxvCwto2Re7sCNOfnB3zDAE43W9bEF8KMmHRCrT1Em1O AkcO03BW2rEalCbOLpQnYpH6vJhsTI2+fxt0XpZPy4aserDYsWwA7mHDg6w/yJn5lf9u GcE4/LdM5Vp8odMoEfDXujl7QdLFolBLe3XKEgFbUyKJcvKUVoG7KuQb3hJhFi/UJIPu /XOA== 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=Rzg3JmVh3kV17PxaBgNTh7dfKhzh1ljcUYtBx0u5mOs=; b=JFyApbGwRr1ZlLPl+by2X6tSBEqjrLT8ocwAbG2mKemg8xApj0qLGbpreBnv1zKiLy G96PwYzcpvr1YmSGwEdD9/ye7LK0A1TPCBmQeK7dTHMtLkqQ/uQQS4y/yVV5p7YMxPof qjey5xE5c7XAAyxf3mPOCkTFgiR0ndgTou9tO2/CTOiFR5u/FI3LsjTp/CeDsKBbZjoR Y3h8IViXF7xbdyAIXtTIlJGwHhUPxO/YBJGH/DUCulO9xC/3yXIWaiGbxu9vJn0pDRP5 UpnfMtB9/O3WlpfvByfYNDoDEX3LTTz/M0VQlrU64zWTkg781oSwzj9xf+iLHIcaBhIO Rukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=kmTg2BAY; 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=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170903120e00b0019931c82e24si12171673plh.195.2023.05.30.07.43.56; Tue, 30 May 2023 07:44:11 -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 (test mode) header.i=@axis.com header.s=axis-central1 header.b=kmTg2BAY; 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=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232606AbjE3O0a (ORCPT + 99 others); Tue, 30 May 2023 10:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjE3O0H (ORCPT ); Tue, 30 May 2023 10:26:07 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67D11700; Tue, 30 May 2023 07:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1685456710; x=1716992710; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rzg3JmVh3kV17PxaBgNTh7dfKhzh1ljcUYtBx0u5mOs=; b=kmTg2BAYsqGKyITZP2bl7ET3NtcfiEk68CcAHkG4+iFZFxXGV3i0n0TI Cag3kF20sHmxvdzWUyxtN8SYczpiYAy41bduHCVKpQgxRQomGIv/ne2O0 6VYBmVJCvvXhhclwZhusOK9WWdzwywv/4u+4dihrJm5Ja3BCVup4swzlM ROxcd7dvWFqpxjFdqiA99muRRNfDzWaUqk1kJWLFsp5eG0clKa0KaFfP3 djxGEqE1w6GCJc+1QX1SK+IgrCxzCMUf/IAvZJ4LPwcdmsbvgAfejKY5/ lAeaPEP77NMD0t4KY252aOY1KjdfVQTcmY4GPoLOfQyeD+lJkWCmfQxec g==; From: Astrid Rost To: Jonathan Cameron , Lars-Peter Clausen CC: , , , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Mathieu Othacehe , Astrid Rost Subject: [PATCH v5 2/7] iio: light: vcnl4000: Add proximity ps_it for vcnl4200 Date: Tue, 30 May 2023 16:24:00 +0200 Message-ID: <20230530142405.1679146-3-astrid.rost@axis.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230530142405.1679146-1-astrid.rost@axis.com> References: <20230530142405.1679146-1-astrid.rost@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Add ps_it attributes for vcnl4200 (similar to vcnl4040). Add read/write attribute for proximity integration time. Read attribute for available proximity integration times. Change sampling rate depending on integration time. Signed-off-by: Astrid Rost --- drivers/iio/light/vcnl4000.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 565b9c9ea470..090e20229855 100644 --- a/drivers/iio/light/vcnl4000.c +++ b/drivers/iio/light/vcnl4000.c @@ -124,6 +124,15 @@ static const int vcnl4040_ps_it_times[][2] = { {0, 800}, }; +static const int vcnl4200_ps_it_times[][2] = { + {0, 96}, + {0, 144}, + {0, 192}, + {0, 384}, + {0, 768}, + {0, 864}, +}; + #define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend */ enum vcnl4000_device_ids { @@ -166,6 +175,8 @@ struct vcnl4000_chip_spec { irqreturn_t (*irq_thread)(int irq, void *priv); irqreturn_t (*trig_buffer_func)(int irq, void *priv); u8 int_reg; + const int(*ps_it_times)[][2]; + const int num_ps_it_times; }; static const struct i2c_device_id vcnl4000_id[] = { @@ -508,11 +519,11 @@ static int vcnl4040_read_ps_it(struct vcnl4000_data *data, int *val, int *val2) ret = FIELD_GET(VCNL4040_PS_CONF2_PS_IT, ret); - if (ret >= ARRAY_SIZE(vcnl4040_ps_it_times)) + if (ret >= data->chip_spec->num_ps_it_times) return -EINVAL; - *val = vcnl4040_ps_it_times[ret][0]; - *val2 = vcnl4040_ps_it_times[ret][1]; + *val = (*data->chip_spec->ps_it_times)[ret][0]; + *val2 = (*data->chip_spec->ps_it_times)[ret][1]; return 0; } @@ -523,8 +534,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val) int ret, index = -1; u16 regval; - for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_it_times); i++) { - if (val == vcnl4040_ps_it_times[i][1]) { + for (i = 0; i < data->chip_spec->num_ps_it_times; i++) { + if (val == (*data->chip_spec->ps_it_times)[i][1]) { index = i; break; } @@ -533,6 +544,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val) if (index < 0) return -EINVAL; + data->vcnl4200_ps.sampling_rate = ktime_set(0, val * 60 * NSEC_PER_USEC); + mutex_lock(&data->vcnl4000_lock); ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); @@ -620,11 +633,13 @@ static int vcnl4040_read_avail(struct iio_dev *indio_dev, const int **vals, int *type, int *length, long mask) { + struct vcnl4000_data *data = iio_priv(indio_dev); + switch (mask) { case IIO_CHAN_INFO_INT_TIME: - *vals = (int *)vcnl4040_ps_it_times; + *vals = (int *)(*data->chip_spec->ps_it_times); *type = IIO_VAL_INT_PLUS_MICRO; - *length = 2 * ARRAY_SIZE(vcnl4040_ps_it_times); + *length = 2 * data->chip_spec->num_ps_it_times; return IIO_AVAIL_LIST; default: return -EINVAL; @@ -1317,6 +1332,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = { .info = &vcnl4040_info, .irq_thread = vcnl4040_irq_thread, .int_reg = VCNL4040_INT_FLAGS, + .ps_it_times = &vcnl4040_ps_it_times, + .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times), }, [VCNL4200] = { .prod = "VCNL4200", @@ -1329,6 +1346,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = { .info = &vcnl4040_info, .irq_thread = vcnl4040_irq_thread, .int_reg = VCNL4200_INT_FLAGS, + .ps_it_times = &vcnl4200_ps_it_times, + .num_ps_it_times = ARRAY_SIZE(vcnl4200_ps_it_times), }, }; -- 2.30.2