From nobody Sun May 10 13:34:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671D3C433F5 for ; Tue, 3 May 2022 14:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237318AbiECOsg (ORCPT ); Tue, 3 May 2022 10:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237300AbiECOsc (ORCPT ); Tue, 3 May 2022 10:48:32 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF83339166; Tue, 3 May 2022 07:44:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 217381F44133 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651589098; bh=UNeNPgpw1R6Fw0IfN3Kfn3Etg70pun757On7XIN528E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcpg1rk0zkxHc4rAvmUykbgwByfzuZShfN2aykJ2Ap+3ifGbwDlPW5fex+5m/hMGS XU7OX3SJAt73mliZph8jEa9V1f9XLrPcCW7MvOTeZ+WcRBERqCcTfTiYh6ljywmO1T NamTLqauTc34ID60g5IEVHZRE3T8FdWDN9gjLTSHdmnE2bOIad+2l/hidqIKQTfOs6 C2feR8p/CGApgR7Al9OKsr0WIl02P+ko6E4ula1GO+i3ZwIg/vDH8O2csWxhtPa1Xm FvJnd9Zw5y+Yo6A6woksV0J6+fscGe/iUINiQcTeLvwqzJu693ZjEQE+62QnuOdn6s Vrjvc0z4dthhw== From: Shreeya Patel To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com, krzk@kernel.org, krisman@collabora.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, alvaro.soliverez@collabora.com, Shreeya Patel Subject: [PATCH v3 1/3] dt-bindings: vendor-prefixes: Add 'ltr' as deprecated vendor prefix Date: Tue, 3 May 2022 20:13:52 +0530 Message-Id: <20220503144354.75438-2-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220503144354.75438-1-shreeya.patel@collabora.com> References: <20220503144354.75438-1-shreeya.patel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 'liteon' is the correct vendor prefix for devices released by LITE-ON Technology Corp. But one of the released device which uses ltr216a light sensor exposes the vendor prefix name as 'ltr' through ACPI. Hence, add 'ltr' as a deprecated vendor prefix which would suppress the following warning in case the compatible string used in ltrf216a driver is "ltr,ltrf216a" WARNING: DT compatible string vendor "ltr" appears un-documented -- check ./Documentation/devicetree/bindings/vendor-prefixes.yaml 364: FILE: drivers/iio/light/ltrf216a.c:313: + { .compatible =3D "ltr,ltrf216a" }, Reviewed-by: Krzysztof Kozlowski Signed-off-by: Shreeya Patel --- Changes in v2 - Add vendor prefix name as per the alphabetical order. Documentation/devicetree/bindings/vendor-prefixes.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index 01430973ecec..02f94fba03b6 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -716,6 +716,9 @@ patternProperties: description: Loongson Technology Corporation Limited "^lsi,.*": description: LSI Corp. (LSI Logic) + "^ltr,.*": + description: LITE-ON Technology Corp. + deprecated: true "^lwn,.*": description: Liebherr-Werk Nenzing GmbH "^lxa,.*": --=20 2.30.2 From nobody Sun May 10 13:34:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A868C43219 for ; Tue, 3 May 2022 14:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237340AbiECOtJ (ORCPT ); Tue, 3 May 2022 10:49:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbiECOsi (ORCPT ); Tue, 3 May 2022 10:48:38 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70B8B39145; Tue, 3 May 2022 07:45:05 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 0F2731F44139 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651589104; bh=/I6H16hNm7gAwn16uNo8eZZIr/zboi499kJmx5/AwaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A7p49alo4NdNI69oba+CLXyPIxJ9Qd+YH+Pc2VXdCWsTu2haLmoCeniyXwGn1s4fu 4yKuRds7WX5SNROuuUXvGoxMgU2QMkiyEFXrHvNrFmgMpmbgkqBm0eugmP3/g8SPgU PVjFg2KeUyGTKxHwVYQGhsDfmfh8lSRUSvSMF+uEXFdPxSiljj977s7LooJafelYsB 0ExY00/Uf4pfAHd0YsbTbw9UoatAvinHOJHPnN9YZoGLzX3RJIMaHoE6S1kyp/h2wG AQ4rbbhzyy3cgtF9sbgmVze+lh5nnqzhCuBqJ6gwQ1SzLaETJ5Q0qcE33FZuHaUkvZ ocKoAqkwuog6Q== From: Shreeya Patel To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com, krzk@kernel.org, krisman@collabora.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, alvaro.soliverez@collabora.com, Shreeya Patel , Krzysztof Kozlowski Subject: [PATCH v3 2/3] dt-bindings: Document ltrf216a light sensor bindings Date: Tue, 3 May 2022 20:13:53 +0530 Message-Id: <20220503144354.75438-3-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220503144354.75438-1-shreeya.patel@collabora.com> References: <20220503144354.75438-1-shreeya.patel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add devicetree bindings for ltrf216a ambient light sensor. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Shreeya Patel --- Changes in v3 - Fix indentation in the example section Changes in v2 - Take over the maintainership for the bindings - Add interrupt and power supply property in DT bindings .../bindings/iio/light/liteon,ltrf216a.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/liteon,ltrf= 216a.yaml diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.ya= ml b/Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml new file mode 100644 index 000000000000..1389639cd7fd --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/liteon,ltrf216a.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/liteon,ltrf216a.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTRF216A Ambient Light Sensor + +maintainers: + - Shreeya Patel + +description: + Ambient light sensing with an i2c interface. + +properties: + compatible: + oneOf: + - const: liteon,ltrf216a + - const: ltr,ltrf216a + deprecated: true + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor. + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + light-sensor@53 { + compatible =3D "liteon,ltrf216a"; + reg =3D <0x53>; + vdd-supply =3D <&vdd_regulator>; + interrupt-parent =3D <&gpio0>; + interrupts =3D <5 IRQ_TYPE_LEVEL_LOW>; + }; + }; --=20 2.30.2 From nobody Sun May 10 13:34:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 290A0C433FE for ; Tue, 3 May 2022 14:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234502AbiECOtM (ORCPT ); Tue, 3 May 2022 10:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237344AbiECOst (ORCPT ); Tue, 3 May 2022 10:48:49 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B89239686; Tue, 3 May 2022 07:45:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: shreeya) with ESMTPSA id 4273F1F4413E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651589109; bh=SWJEy8hYXd/PvdeqSPkkKXwtcl6wyLhk9EvFPwDWa30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OwycVvmR5ZhlaWHVmIMC5N43fi9PYWb6siDgKXFy1XYt/2nU9Dlx7fuVymJ6YqT0n H57YbbIOnP+/h86aS2yGlHJycmLr9gMuBUeGPr/eNeLieGHPeKZ32BtMzVedzFwLia EqowRM8OyN4oldVcLf05kSbeuxlj2O4IzGQycGxtypNWARcIv2kBfzAkTjXxjQ/MRK 4qRhLqEs9wpfAQfE0+jWBTyCjJt56cmRXvAyGJRr9YkQDttM6Vq3lIkU0p8qg71nPQ XvInsWouRjVhyWWTc+cNYbiBFHxTkoNEs/HBHU9nbnlqHQab3OVRJB6UGHcebCIA1p 9pCsYTGxxrWqA== From: Shreeya Patel To: jic23@kernel.org, lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com, krzk@kernel.org, krisman@collabora.com Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, alvaro.soliverez@collabora.com, Shreeya Patel Subject: [PATCH v3 3/3] iio: light: Add support for ltrf216a sensor Date: Tue, 3 May 2022 20:13:54 +0530 Message-Id: <20220503144354.75438-4-shreeya.patel@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220503144354.75438-1-shreeya.patel@collabora.com> References: <20220503144354.75438-1-shreeya.patel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhigang Shi Add initial support for ltrf216a ambient light sensor. Datasheet: gitlab.steamos.cloud/shreeya/iio/-/blob/main/LTRF216A.pdf Co-developed-by: Shreeya Patel Signed-off-by: Shreeya Patel Signed-off-by: Zhigang Shi --- Changes in v3 - Use u16 instead of u8 for int_time_fac - Reorder headers in ltrf216a.c file - Remove int_time_mapping table and use int_time_available Changes in v2 - Add support for 25ms and 50ms integration time. - Rename some of the macros as per names given in datasheet - Add a comment for the mutex lock - Use read_avail callback instead of attributes and set the appropriate _available bit. - Use FIELD_PREP() at appropriate places. - Add a constant lookup table for integration time and reg val - Use BIT() macro for magic numbers. - Improve error handling at few places. - Use get_unaligned_le24() and div_u64() - Use probe_new() callback and devm functions - Return errors in probe using dev_err_probe() - Use DEFINE_SIMPLE_DEV_PM_OPS() - Correct the formula for lux to use 0.45 instead of 0.8 drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/ltrf216a.c | 343 +++++++++++++++++++++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100644 drivers/iio/light/ltrf216a.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index a62c7b4b8678..33d2b24ba1da 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -318,6 +318,16 @@ config SENSORS_LM3533 changes. The ALS-control output values can be set per zone for the three current output channels. =20 +config LTRF216A + tristate "Liteon LTRF216A Light Sensor" + depends on I2C + help + If you say Y or M here, you get support for Liteon LTRF216A + Ambient Light Sensor. + + If built as a dynamically linked module, it will be called + ltrf216a. + config LTR501 tristate "LTR-501ALS-01 light sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index d10912faf964..8fa91b9fe5b6 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_SENSORS_ISL29028) +=3D isl29028.o obj-$(CONFIG_ISL29125) +=3D isl29125.o obj-$(CONFIG_JSA1212) +=3D jsa1212.o obj-$(CONFIG_SENSORS_LM3533) +=3D lm3533-als.o +obj-$(CONFIG_LTRF216A) +=3D ltrf216a.o obj-$(CONFIG_LTR501) +=3D ltr501.o obj-$(CONFIG_LV0104CS) +=3D lv0104cs.o obj-$(CONFIG_MAX44000) +=3D max44000.o diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c new file mode 100644 index 000000000000..1ad1eb4a4c6d --- /dev/null +++ b/drivers/iio/light/ltrf216a.c @@ -0,0 +1,343 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * LTRF216A Ambient Light Sensor + * + * Copyright (C) 2021 Lite-On Technology Corp (Singapore) + * Author: Shi Zhigang + * + * IIO driver for LTRF216A (7-bit I2C slave address 0x53). + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LTRF216A_DRV_NAME "ltrf216a" + +#define LTRF216A_MAIN_CTRL 0x00 + +#define LTRF216A_ALS_DATA_STATUS BIT(3) +#define LTRF216A_ALS_ENABLE_MASK BIT(1) + +#define LTRF216A_ALS_MEAS_RES 0x04 +#define LTRF216A_MAIN_STATUS 0x07 +#define LTRF216A_CLEAR_DATA_0 0x0A + +#define LTRF216A_ALS_DATA_0 0x0D + +static const int ltrf216a_int_time_available[5][2] =3D { + {0, 400000}, + {0, 200000}, + {0, 100000}, + {0, 50000}, + {0, 25000}, +}; + +static const int ltrf216a_int_time_reg[5][2] =3D { + {400, 0x03}, + {200, 0x13}, + {100, 0x22}, + {50, 0x31}, + {25, 0x40}, +}; + +struct ltrf216a_data { + struct i2c_client *client; + u32 int_time; + u16 int_time_fac; + u8 als_gain_fac; + struct mutex mutex; /* Protect read and write operations */ +}; + +/* open air. need to update based on TP transmission rate. */ +#define WIN_FAC 1 + +static const struct iio_chan_spec ltrf216a_channels[] =3D { + { + .type =3D IIO_LIGHT, + .info_mask_separate =3D + BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_INT_TIME), + .info_mask_separate_available =3D + BIT(IIO_CHAN_INFO_INT_TIME), + } +}; + +static int ltrf216a_init(struct iio_dev *indio_dev) +{ + int ret; + struct ltrf216a_data *data =3D iio_priv(indio_dev); + + ret =3D i2c_smbus_read_byte_data(data->client, LTRF216A_MAIN_CTRL); + if (ret < 0) { + dev_err(&data->client->dev, "Error reading LTRF216A_MAIN_CTRL\n"); + return ret; + } + + /* enable sensor */ + ret |=3D FIELD_PREP(LTRF216A_ALS_ENABLE_MASK, 1); + ret =3D i2c_smbus_write_byte_data(data->client, LTRF216A_MAIN_CTRL, ret); + if (ret < 0) { + dev_err(&data->client->dev, "Error writing LTRF216A_MAIN_CTRL\n"); + return ret; + } + + return 0; +} + +static int ltrf216a_disable(struct iio_dev *indio_dev) +{ + int ret; + struct ltrf216a_data *data =3D iio_priv(indio_dev); + + ret =3D i2c_smbus_write_byte_data(data->client, LTRF216A_MAIN_CTRL, 0); + if (ret < 0) + dev_err(&data->client->dev, "Error writing LTRF216A_MAIN_CTRL\n"); + + return ret; +} + +static void als_ltrf216a_disable(void *data) +{ + struct iio_dev *indio_dev =3D data; + + ltrf216a_disable(indio_dev); +} + +static int ltrf216a_set_int_time(struct ltrf216a_data *data, int itime) +{ + int i, ret, index =3D -1; + u8 reg_val; + + for (i =3D 0; i < ARRAY_SIZE(ltrf216a_int_time_available); i++) { + if (ltrf216a_int_time_available[i][1] =3D=3D itime) { + index =3D i; + break; + } + } + + if (index < 0) + return -EINVAL; + + reg_val =3D ltrf216a_int_time_reg[index][1]; + data->int_time_fac =3D ltrf216a_int_time_reg[index][0]; + + ret =3D i2c_smbus_write_byte_data(data->client, LTRF216A_ALS_MEAS_RES, re= g_val); + if (ret < 0) + return ret; + + data->int_time =3D itime; + + return 0; +} + +static int ltrf216a_get_int_time(struct ltrf216a_data *data, int *val, int= *val2) +{ + *val =3D 0; + *val2 =3D data->int_time; + return IIO_VAL_INT_PLUS_MICRO; +} + +static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr) +{ + int i, ret =3D -1, tries =3D 25; + u8 buf[3]; + + while (tries--) { + ret =3D i2c_smbus_read_byte_data(data->client, LTRF216A_MAIN_STATUS); + if (ret < 0) + return ret; + if (ret & LTRF216A_ALS_DATA_STATUS) + break; + msleep(20); + } + + for (i =3D 0; i < 3; i++) { + ret =3D i2c_smbus_read_byte_data(data->client, addr); + if (ret < 0) + return ret; + buf[i] =3D ret; + addr++; + } + + return get_unaligned_le24(&buf[0]); +} + +static int ltrf216a_get_lux(struct ltrf216a_data *data) +{ + int greendata, cleardata; + u64 lux, div; + + greendata =3D ltrf216a_read_data(data, LTRF216A_ALS_DATA_0); + cleardata =3D ltrf216a_read_data(data, LTRF216A_CLEAR_DATA_0); + + if (greendata < 0 || cleardata < 0) + return -EINVAL; + + lux =3D greendata * 45 * WIN_FAC * 100; + div =3D data->als_gain_fac * data->int_time_fac * 100; + + return div_u64(lux, div); +} + +static int ltrf216a_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + int ret; + struct ltrf216a_data *data =3D iio_priv(indio_dev); + + mutex_lock(&data->mutex); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + ret =3D ltrf216a_get_lux(data); + if (ret < 0) + return ret; + *val =3D ret; + ret =3D IIO_VAL_INT; + break; + case IIO_CHAN_INFO_INT_TIME: + ret =3D ltrf216a_get_int_time(data, val, val2); + break; + default: + ret =3D -EINVAL; + } + + mutex_unlock(&data->mutex); + + return ret; +} + +static int ltrf216a_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct ltrf216a_data *data =3D iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + if (val !=3D 0) + return -EINVAL; + mutex_lock(&data->mutex); + ret =3D ltrf216a_set_int_time(data, val2); + mutex_unlock(&data->mutex); + return ret; + default: + return -EINVAL; + } +} + +static int ltrf216a_read_available(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_INT_TIME: + *length =3D ARRAY_SIZE(ltrf216a_int_time_available) * 2; + *vals =3D (const int *)ltrf216a_int_time_available; + *type =3D IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + +static const struct iio_info ltrf216a_info =3D { + .read_raw =3D ltrf216a_read_raw, + .write_raw =3D ltrf216a_write_raw, + .read_avail =3D ltrf216a_read_available, +}; + +static int ltrf216a_probe(struct i2c_client *client) +{ + struct ltrf216a_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data =3D iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client =3D client; + + mutex_init(&data->mutex); + + indio_dev->info =3D <rf216a_info; + indio_dev->name =3D LTRF216A_DRV_NAME; + indio_dev->channels =3D ltrf216a_channels; + indio_dev->num_channels =3D ARRAY_SIZE(ltrf216a_channels); + indio_dev->modes =3D INDIO_DIRECT_MODE; + + ret =3D ltrf216a_init(indio_dev); + if (ret < 0) + return dev_err_probe(&client->dev, ret, + "ltrf216a chip init failed\n"); + + data->int_time =3D 100000; + data->int_time_fac =3D 100; + data->als_gain_fac =3D 3; + + ret =3D devm_add_action_or_reset(&client->dev, als_ltrf216a_disable, + indio_dev); + if (ret < 0) + return ret; + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static int ltrf216a_suspend(struct device *dev) +{ + struct iio_dev *indio_dev =3D i2c_get_clientdata(to_i2c_client(dev)); + + return ltrf216a_disable(indio_dev); +} + +static int ltrf216a_resume(struct device *dev) +{ + struct iio_dev *indio_dev =3D i2c_get_clientdata(to_i2c_client(dev)); + + return ltrf216a_init(indio_dev); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(ltrf216a_pm_ops, ltrf216a_suspend, ltrf216= a_resume); + +static const struct i2c_device_id ltrf216a_id[] =3D { + { LTRF216A_DRV_NAME, 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, ltrf216a_id); + +static const struct of_device_id ltrf216a_of_match[] =3D { + { .compatible =3D "liteon,ltrf216a", }, + { .compatible =3D "ltr,ltrf216a", }, + {} +}; +MODULE_DEVICE_TABLE(of, ltrf216a_of_match); + +static struct i2c_driver ltrf216a_driver =3D { + .driver =3D { + .name =3D LTRF216A_DRV_NAME, + .pm =3D pm_sleep_ptr(<rf216a_pm_ops), + .of_match_table =3D ltrf216a_of_match, + }, + .probe_new =3D ltrf216a_probe, + .id_table =3D ltrf216a_id, +}; + +module_i2c_driver(ltrf216a_driver); + +MODULE_AUTHOR("Shi Zhigang "); +MODULE_DESCRIPTION("LTRF216A ambient light sensor driver"); +MODULE_LICENSE("GPL"); --=20 2.30.2