From patchwork Wed Oct 30 23:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13857291 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 CB45B1C461C; Wed, 30 Oct 2024 23:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730329808; cv=none; b=uf1tWI249Xm1a0m41YWoZoJD0VAMHiZ4RfCN6vpLmOFKuC8AY09Jr1ZSRyvSXvZO0ApTUyxSAjpgwgQBMHnTDyCCFGVwjPjdMoTyzu7CS4c5HlawAcunElfzItsbgpn+Qlxm+Yek7tILYRvt30V9YFa77tb6LQGd23tIxp7XVbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730329808; c=relaxed/simple; bh=qWnR2rmnhwGHq7mAsIHZILDGlSmqxUHxGBDr9jSrTqg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ne6GezB6fonHuYs939+iKCShuuPtaAURdMcPjDwBT8XbR33XGxT7BQYvW7jN2wvLHzYR9rsirPAzVozM8ZLODT9wfDXbDpK2KEKmp4ohpt0XT38Y99dQ9JwGFhqLzgypDUJBoyD4JuePo/nXdohtqQZDk3OT4uZlBZD5yjTx0Pc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JhB396zj; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JhB396zj" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43163667f0eso2942905e9.0; Wed, 30 Oct 2024 16:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730329805; x=1730934605; 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=cumYjcBz0I1e4AdDhe+4/VCui4W7eGiW1fPLdLsyy08=; b=JhB396zjRBYFZrwMg1JeRt1EcnMMuILrPib0dXA1qv2zMigsCVy+zMUbFdXk1j9IMG pUkZ6u+aBOML8P10q4imdiaFTfe23Nw9Lq/+KWPC0UOIIR0zUT/sGxQb5tpmC1STaeNO qYywbQY0e0WOW8gnHKiW1Rv7fNRfzwAHFhMvRTB9meOxPH1MVU0EBJS5jTS7i8yfYtNv l4Ep3RGVPUr86lLQCGPJz0WlIFMyEcUWBwfzspWamzJNf7Iac+RYKFt696VkKEBNWzGm cj4JoWGayzFjHSd6RbaASOnpiFkNS54xOC8XdjqYW5tjoNaSAmVcYOzz254aa083INj5 iByw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730329805; x=1730934605; 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=cumYjcBz0I1e4AdDhe+4/VCui4W7eGiW1fPLdLsyy08=; b=onzWIXHlibAOE2Ah69m1LobCEzdJ9RTucpDQNglMevyVbX3gFIQohiG8Y1Wkg3gXTW dWCdLnHqt/+LdVONdotSMrECjDnYt1fy6ZaIdXopxIPmrrEJH9/2cPkiaFTbZoLlPUK9 gSrPuUXqcHe/KmQnU0yt+RTqI+eJ76E+hip09KtmouipeLsMgh85XzHQs2P7qrF16N44 LIRi9jvlVCMuj2vSwJ5UamEmShVddmJ6kVLsq/PPTXYW3tm1wDm2OKi5o9CIomOpmAuj RI9nPjQcxektq64vRIxMGeVZGHN4wrCCV803HWfphhG2CRAPlUUySj64n8viOauU6B1R KeYg== X-Forwarded-Encrypted: i=1; AJvYcCX/sOeFl+DkbzZLa37e13od503eSRVn2avk76nTvBE3+QcoDEY+salgzVQ9DBMP0peiy4twYphYHmgc@vger.kernel.org, AJvYcCXE/k/xxfq9Gs6wYE+OdY7OoYtUZVJVx3PbyivUB03AKO8uCmFYOYPEB8+UMArM+xRz3HbHg0MqAK4wafle@vger.kernel.org X-Gm-Message-State: AOJu0YxIreQLNZ4LTrmofHn0B25+ZmfTHlE48cbuomeN7bVD1SKs4/Ou gm3vPFsRuCeUnuwj4HdROWalZudIGh8+ORrMG6bZaAFJ3IkJwdjLRQUtwoFQ X-Google-Smtp-Source: AGHT+IGUJjwcoXteocK8oS6I7yQ/VwqNGJ7R/1sTAkTT4YW4Yya20nfyl9cBidfXM7PdgIz11CuAfA== X-Received: by 2002:a05:600c:350b:b0:431:44fe:fd9a with SMTP id 5b1f17b1804b1-4319acb8a7cmr144016295e9.19.1730329804886; Wed, 30 Oct 2024 16:10:04 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-fbf3-0656-23c1-5ba1.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:fbf3:656:23c1:5ba1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd8e848csm34819375e9.3.2024.10.30.16.10.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 16:10:04 -0700 (PDT) From: Javier Carrasco Date: Thu, 31 Oct 2024 00:09:57 +0100 Subject: [PATCH v4 1/2] dt-bindings: iio: light: veml6075: document vishay,rset-ohms Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-veml6070-integration-time-v4-1-c66da6788256@gmail.com> References: <20241031-veml6070-integration-time-v4-0-c66da6788256@gmail.com> In-Reply-To: <20241031-veml6070-integration-time-v4-0-c66da6788256@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1730329801; l=1329; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=qWnR2rmnhwGHq7mAsIHZILDGlSmqxUHxGBDr9jSrTqg=; b=IVgjR+kPGspj5bVmNmpbtCFy9zefsFdIrH/9DZImLKWrpIbh/9MIpBqtUasu7pRvmtzb/5QTM dxYQ3bCWghWB+AXqDelvkGIoJvFv9PzRmPeEEUgFAQebxUtEVWGVi2t X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The veml6070 provides a configurable integration time by means of an external resistor (Rset in the datasheet) with values between 75 and 1200 kohms. Document vishay,rset-ohms to select the integration time. Signed-off-by: Javier Carrasco Reviewed-by: Krzysztof Kozlowski --- .../devicetree/bindings/iio/light/vishay,veml6075.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml b/Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml index 96c1317541fa..d2effccbfb56 100644 --- a/Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml +++ b/Documentation/devicetree/bindings/iio/light/vishay,veml6075.yaml @@ -22,6 +22,13 @@ properties: reg: maxItems: 1 + vishay,rset-ohms: + description: + Resistor used to select the integration time. + default: 270000 + minimum: 75000 + maximum: 1200000 + vdd-supply: true required: @@ -29,6 +36,17 @@ required: - reg - vdd-supply +allOf: + - if: + properties: + compatible: + enum: + - vishay,veml6040 + - vishay,veml6075 + then: + properties: + vishay,rset-ohms: false + additionalProperties: false examples: From patchwork Wed Oct 30 23:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13857292 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 6D099217657; Wed, 30 Oct 2024 23:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730329812; cv=none; b=p4HdJPCIQ5/0D1TbXvYrSr7kk5T6u4IPGthcC5VhrDjXC3/5nQF5H353AOPchto9kY/PNF9tTnvBzMqKuD3VyWpEAOb88/9zw2Bjcq48C0/SaSkJKqc4F2pEUnNetd5WfBYxkTtq+Lul+fPF5fP9xc8+ioTqu7cPkMqW2JuuKMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730329812; c=relaxed/simple; bh=PvMSlb4ER20zgSWWNwE2ypfP9G5WUX3heFVVSw6vmnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c8VPMxsKracknj156i1PXTpC9xG3eWFCsGOIIdHdPZhjwARBIG2K6ex9dHqT4x+lJsl93XeGMNJU2WyRWQqmLI/ek1DSOSzKHz2xrckIEs1XreSVVo9W6kMR9bOWuh1AnRgj9DkjVa4edgF2mexJkvt0L6gYDw2KZwfRjTTnxNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ro9FvwkM; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ro9FvwkM" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4315df7b43fso2899255e9.0; Wed, 30 Oct 2024 16:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730329808; x=1730934608; 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=JEpzUzJ1c5lFszF2kPARxtWbM5pCJuooPUNo/pm7Vmg=; b=Ro9FvwkMvzYIUdb743XXSB3BzBEXdLBW7fOS72iflxQ82z54PNJJm0/sTju8jjhke0 gS9ppU9IdjfqXAEf2xxMpJVKLtW47iVsiUvBE0uzD72L0A37RmET4a3gAwF6j2CgBGAK 9aAL9FnEM0hL7ZC16xoPxxqC7kR6na8JnSRPR4tNFS5Smr2wNzN6q2e6VBL+ECSttqVA wUUp+cSHB17r0TS51FbXwXm4dt/1mbOHEq8pQgBlmZXC9wm/ljLdOaxMuNpVBo8ywAzR ObivbFl1TRkXvdD4JHrMwCxVtNh9CM3hc3FEUuRoYQjbss+pO6wcKOatwOmaqU6132N8 ZdwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730329808; x=1730934608; 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=JEpzUzJ1c5lFszF2kPARxtWbM5pCJuooPUNo/pm7Vmg=; b=aSnu0MuxNKdbs+oFlxH5I2TCDH95bGwFVSZvHzJENXGE0M0GXYHysKcUCjVhqFUre7 YL6nqzhAro/EMFbC+x1hsbXQomoonfGsLf1j/eSW5JL7iw+nfrKaml/tYpfZJy5X4WHR H1ipwPqPsemHYJkQyKP76tIZMOQqihfFAcXLM6hSgIEm4IV1JONJQYEmYUv9i/OjLBMw ZwKVzgyvss0KCYBYEwueZEbAzt9n9ioqKTYVfjltfHNRUn8evf63LK1dDxjmdxu/SOnY 79jLSH5IkzXLaOVjhDxL+w9bUpoP/Pxa753+jkDyoyZJy1sd0nKsginHrKtF/3t8B7Nt EyWw== X-Forwarded-Encrypted: i=1; AJvYcCVp865PUvRNNAI4Zi+wzkKwgNPrjU/fMausQ+ZWT/dix3Q7ZTmYmapOwOtRfe8Ht4WpvMGeqdYOkfZxHoLY@vger.kernel.org, AJvYcCWuWcajWKEQHURlgCSGP0Ayu16lkq0LsfWLLrJPdtpbc3dPBVAZNErpUpxkBP50AJRiH+EUf9UZWi9z@vger.kernel.org X-Gm-Message-State: AOJu0YxPMvK1TYCIqyh3e7FTrU3P08TQ+oS42iHDjsvxCLlUM55bjmax qwT6PUDHwP0M7TxyrIlKia09dVaXsn4Ly6FgusgLsGik0ZpjNsD6 X-Google-Smtp-Source: AGHT+IEPkiJRff+4vPxkrnkgfrNHalMGa4SX2xBvp2YkmFGoSP8+wKhVuaJOhLWXT9KSEb6MoOwpPA== X-Received: by 2002:a05:600c:1d16:b0:42e:d4a2:ce67 with SMTP id 5b1f17b1804b1-431ae9c440cmr107681595e9.17.1730329807502; Wed, 30 Oct 2024 16:10:07 -0700 (PDT) Received: from [127.0.1.1] (2a02-8389-41cf-e200-fbf3-0656-23c1-5ba1.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:fbf3:656:23c1:5ba1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431bd8e848csm34819375e9.3.2024.10.30.16.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 16:10:07 -0700 (PDT) From: Javier Carrasco Date: Thu, 31 Oct 2024 00:09:58 +0100 Subject: [PATCH v4 2/2] iio: light: veml6070: add support for integration time Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-veml6070-integration-time-v4-2-c66da6788256@gmail.com> References: <20241031-veml6070-integration-time-v4-0-c66da6788256@gmail.com> In-Reply-To: <20241031-veml6070-integration-time-v4-0-c66da6788256@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1730329801; l=6758; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=PvMSlb4ER20zgSWWNwE2ypfP9G5WUX3heFVVSw6vmnE=; b=+EdcuvwG1WczhePTCYyzglYFdPFVj9AAVTEJ2sDx/eebrBnlXW5E7l2CVy0ozcUxnP5IPrmsq QjMqAzrLibqAfylLCZFroYqXVhQ8XuKDSCbrbWMoCysGCLt6VfMyMOV X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= The integration time of the veml6070 depends on an external resistor (called Rset in the datasheet) and the value configured in the IT field of the command register, whose supported values are 1/2x, 1x, 2x and 4x. Signed-off-by: Javier Carrasco --- drivers/iio/light/veml6070.c | 131 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 8 deletions(-) diff --git a/drivers/iio/light/veml6070.c b/drivers/iio/light/veml6070.c index d11ae00f61f8..6d4483c85f30 100644 --- a/drivers/iio/light/veml6070.c +++ b/drivers/iio/light/veml6070.c @@ -6,7 +6,7 @@ * * IIO driver for VEML6070 (7-bit I2C slave addresses 0x38 and 0x39) * - * TODO: integration time, ACK signal + * TODO: ACK signal */ #include @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -29,18 +30,79 @@ #define VEML6070_COMMAND_RSRVD BIT(1) /* reserved, set to 1 */ #define VEML6070_COMMAND_SD BIT(0) /* shutdown mode when set */ -#define VEML6070_IT_10 0x01 /* integration time 1x */ +#define VEML6070_IT_05 0x00 +#define VEML6070_IT_10 0x01 +#define VEML6070_IT_20 0x02 +#define VEML6070_IT_40 0x03 + +#define VEML6070_MIN_RSET_KOHM 75 +#define VEML6070_MIN_IT_US 15625 /* Rset = 75 kohm, IT = 1/2 */ struct veml6070_data { struct i2c_client *client1; struct i2c_client *client2; u8 config; struct mutex lock; + u32 rset; + int it[4][2]; }; +static int veml6070_calc_it(struct device *dev, struct veml6070_data *data) +{ + int i, tmp_it; + + data->rset = 270000; + device_property_read_u32(dev, "vishay,rset-ohms", &data->rset); + + if (data->rset < 75000 || data->rset > 1200000) + return dev_err_probe(dev, -EINVAL, "Rset out of range\n"); + + /* + * convert to kohm to avoid overflows and work with the same units as + * in the datasheet and simplify UVI operations. + */ + data->rset /= KILO; + + tmp_it = VEML6070_MIN_IT_US * data->rset / VEML6070_MIN_RSET_KOHM; + for (i = 0; i < ARRAY_SIZE(data->it); i++) { + data->it[i][0] = (tmp_it << i) / MICRO; + data->it[i][1] = (tmp_it << i) % MICRO; + } + + return 0; +} + +static int veml6070_get_it(struct veml6070_data *data, int *val, int *val2) +{ + int it_idx = FIELD_GET(VEML6070_COMMAND_IT, data->config); + + *val = data->it[it_idx][0]; + *val2 = data->it[it_idx][1]; + + return IIO_VAL_INT_PLUS_MICRO; +} + +static int veml6070_set_it(struct veml6070_data *data, int val, int val2) +{ + int it_idx; + + for (it_idx = 0; it_idx < ARRAY_SIZE(data->it); it_idx++) { + if (data->it[it_idx][0] == val && data->it[it_idx][1] == val2) + break; + } + + if (it_idx >= ARRAY_SIZE(data->it)) + return -EINVAL; + + data->config = (data->config & ~VEML6070_COMMAND_IT) | + FIELD_PREP(VEML6070_COMMAND_IT, it_idx); + + return i2c_smbus_write_byte(data->client1, data->config); +} + static int veml6070_read(struct veml6070_data *data) { - int ret; + int ret, it_ms, val, val2; u8 msb, lsb; guard(mutex)(&data->lock); @@ -51,7 +113,9 @@ static int veml6070_read(struct veml6070_data *data) if (ret < 0) return ret; - msleep(125 + 10); /* measurement takes up to 125 ms for IT 1x */ + veml6070_get_it(data, &val, &val2); + it_ms = val * MILLI + val2 / (MICRO / MILLI); + msleep(it_ms + 10); ret = i2c_smbus_read_byte(data->client2); /* read MSB, address 0x39 */ if (ret < 0) @@ -81,26 +145,37 @@ static const struct iio_chan_spec veml6070_channels[] = { .modified = 1, .channel2 = IIO_MOD_LIGHT_UV, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), }, { .type = IIO_UVINDEX, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME), } }; -static int veml6070_to_uv_index(unsigned int val) +static int veml6070_to_uv_index(struct veml6070_data *data, unsigned int val) { /* * conversion of raw UV intensity values to UV index depends on * integration time (IT) and value of the resistor connected to - * the RSET pin (default: 270 KOhm) + * the RSET pin. */ unsigned int uvi[11] = { 187, 373, 560, /* low */ 746, 933, 1120, /* moderate */ 1308, 1494, /* high */ 1681, 1868, 2054}; /* very high */ - int i; + int i, it_idx; + + it_idx = FIELD_GET(VEML6070_COMMAND_IT, data->config); + + if (!it_idx) + val = (val * 270 / data->rset) << 1; + else + val = (val * 270 / data->rset) >> (it_idx - 1); for (i = 0; i < ARRAY_SIZE(uvi); i++) if (val <= uvi[i]) @@ -123,10 +198,44 @@ static int veml6070_read_raw(struct iio_dev *indio_dev, if (ret < 0) return ret; if (mask == IIO_CHAN_INFO_PROCESSED) - *val = veml6070_to_uv_index(ret); + *val = veml6070_to_uv_index(data, ret); else *val = ret; return IIO_VAL_INT; + case IIO_CHAN_INFO_INT_TIME: + return veml6070_get_it(data, val, val2); + default: + return -EINVAL; + } +} + +static int veml6070_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct veml6070_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + *vals = (int *)data->it; + *length = 2 * ARRAY_SIZE(data->it); + *type = IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + +static int veml6070_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct veml6070_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + return veml6070_set_it(data, val, val2); default: return -EINVAL; } @@ -134,6 +243,8 @@ static int veml6070_read_raw(struct iio_dev *indio_dev, static const struct iio_info veml6070_info = { .read_raw = veml6070_read_raw, + .read_avail = veml6070_read_avail, + .write_raw = veml6070_write_raw, }; static void veml6070_i2c_unreg(void *p) @@ -164,6 +275,10 @@ static int veml6070_probe(struct i2c_client *client) indio_dev->name = VEML6070_DRV_NAME; indio_dev->modes = INDIO_DIRECT_MODE; + ret = veml6070_calc_it(&client->dev, data); + if (ret < 0) + return ret; + ret = devm_regulator_get_enable(&client->dev, "vdd"); if (ret < 0) return ret;