From patchwork Tue Jan 28 13:30:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2096D1398 for ; Tue, 28 Jan 2020 13:32:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0907A22522 for ; Tue, 28 Jan 2020 13:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725881AbgA1NcD (ORCPT ); Tue, 28 Jan 2020 08:32:03 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:38996 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1NcD (ORCPT ); Tue, 28 Jan 2020 08:32:03 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id 3B079251E7; Tue, 28 Jan 2020 14:32:00 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , devicetree@vger.kernel.org Subject: [PATCH v2 1/7] dt-bindings: iio: light: add support for Dyna-Image AL3320A Date: Tue, 28 Jan 2020 14:30:46 +0100 Message-Id: <20200128133052.201587-2-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This commit add dt-bindings support to al3320a driver and vendor-prefix dynaimage. Partly based on unmerged commit: "iio: Add Dyna-Image AP3223 ambient light and proximity driver" Signed-off-by: David Heidelberg --- .../bindings/iio/light/al3320a.yaml | 40 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + 2 files changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3320a.yaml diff --git a/Documentation/devicetree/bindings/iio/light/al3320a.yaml b/Documentation/devicetree/bindings/iio/light/al3320a.yaml new file mode 100644 index 000000000000..05d01df069a7 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/al3320a.yaml @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/al3320a.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dyna-Image AL3320A sensor + +maintainers: + - David Heidelberg + +properties: + compatible: + const: dynaimage,al3320a + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupt + - vdd-supply + +examples: + - | + i2c { + al3320a@1c { + compatible = "dynaimage,al3320a"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + }; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 9cd52d9e1f7f..8d2ebf3d0aa1 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -267,6 +267,8 @@ patternProperties: description: Dragino Technology Co., Limited "^dserve,.*": description: dServe Technology B.V. + "^dynaimage,.*": + description: Dyna-Image "^ea,.*": description: Embedded Artists AB "^ebs-systart,.*": From patchwork Tue Jan 28 13:30:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354261 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDBAF92A for ; Tue, 28 Jan 2020 13:32:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBF3C22522 for ; Tue, 28 Jan 2020 13:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726066AbgA1NcY (ORCPT ); Tue, 28 Jan 2020 08:32:24 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39016 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1NcY (ORCPT ); Tue, 28 Jan 2020 08:32:24 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id 31541251E8; Tue, 28 Jan 2020 14:32:21 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , devicetree@vger.kernel.org Subject: [PATCH v2 2/7] dt-bindings: iio: light: add support for Dyna-Image AL3010 Date: Tue, 28 Jan 2020 14:30:47 +0100 Message-Id: <20200128133052.201587-3-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The Dyna-Image AL3010 is a 16-bit digital ambient light sensor which provides a multiple gain function with linear response over a dynamic range 1216/4863/19452/77806. Signed-off-by: David Heidelberg Reviewed-by: Dmitry Osipenko --- .../devicetree/bindings/iio/light/al3010.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/light/al3010.yaml diff --git a/Documentation/devicetree/bindings/iio/light/al3010.yaml b/Documentation/devicetree/bindings/iio/light/al3010.yaml new file mode 100644 index 000000000000..9cd1f34a6d63 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/light/al3010.yaml @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/light/al3010.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dyna-Image AL3010 sensor + +maintainers: + - David Heidelberg + +properties: + compatible: + const: dynaimage,al3010 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: + description: Regulator that provides power to the sensor + +required: + - compatible + - reg + - interrupt + - vdd-supply + +examples: + - | + i2c { + al3010@1c { + compatible = "dynaimage,al3010"; + reg = <0x1c>; + vdd-supply = <&vdd_reg>; + interrupts = <0 99 4>; + }; + }; From patchwork Tue Jan 28 13:30:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2281E92A for ; Tue, 28 Jan 2020 13:32:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0177F22522 for ; Tue, 28 Jan 2020 13:32:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbgA1Nce (ORCPT ); Tue, 28 Jan 2020 08:32:34 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39034 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1Nce (ORCPT ); Tue, 28 Jan 2020 08:32:34 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id D270E251E9; Tue, 28 Jan 2020 14:32:31 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v2 3/7] iio: light: al3320a slightly improve code formatting Date: Tue, 28 Jan 2020 14:30:48 +0100 Message-Id: <20200128133052.201587-4-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Modified to be in part with al3010 driver. Signed-off-by: David Heidelberg --- drivers/iio/light/al3320a.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index a21aa99e74e4..613830b7df6e 100644 --- a/drivers/iio/light/al3320a.c +++ b/drivers/iio/light/al3320a.c @@ -38,6 +38,11 @@ #define AL3320A_GAIN_SHIFT 1 #define AL3320A_GAIN_MASK (BIT(2) | BIT(1)) +#define AL3320A_GAIN_READ(g) \ + (((g) & AL3320A_GAIN_MASK) >> AL3320A_GAIN_SHIFT) +#define AL3320A_GAIN_WRITE(g) \ + (((g) << AL3320A_GAIN_SHIFT) & AL3320A_GAIN_MASK) + /* chip params default values */ #define AL3320A_DEFAULT_MEAN_TIME 4 @@ -90,7 +95,7 @@ static int al3320a_init(struct al3320a_data *data) return ret; ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG_RANGE, - AL3320A_RANGE_3 << AL3320A_GAIN_SHIFT); + AL3320A_GAIN_WRITE(AL3320A_RANGE_3)); if (ret < 0) return ret; @@ -133,7 +138,7 @@ static int al3320a_read_raw(struct iio_dev *indio_dev, if (ret < 0) return ret; - ret = (ret & AL3320A_GAIN_MASK) >> AL3320A_GAIN_SHIFT; + ret = AL3320A_GAIN_READ(ret); *val = al3320a_scales[ret][0]; *val2 = al3320a_scales[ret][1]; @@ -152,11 +157,13 @@ static int al3320a_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: for (i = 0; i < ARRAY_SIZE(al3320a_scales); i++) { - if (val == al3320a_scales[i][0] && - val2 == al3320a_scales[i][1]) - return i2c_smbus_write_byte_data(data->client, - AL3320A_REG_CONFIG_RANGE, - i << AL3320A_GAIN_SHIFT); + if (val != al3320a_scales[i][0] || + val2 != al3320a_scales[i][1]) + continue; + + return i2c_smbus_write_byte_data(data->client, + AL3320A_REG_CONFIG_RANGE, + AL3320A_GAIN_WRITE(i)); } break; } From patchwork Tue Jan 28 13:30:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D974C1398 for ; Tue, 28 Jan 2020 13:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B742322522 for ; Tue, 28 Jan 2020 13:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726063AbgA1NdL (ORCPT ); Tue, 28 Jan 2020 08:33:11 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39066 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1NdL (ORCPT ); Tue, 28 Jan 2020 08:33:11 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id B5EF5251EB; Tue, 28 Jan 2020 14:33:08 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Dmitry Osipenko Subject: [PATCH v2 4/7] iio: light: add Dyna-Image AL3010 driver Date: Tue, 28 Jan 2020 14:30:49 +0100 Message-Id: <20200128133052.201587-5-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Based on: - 3320A in-kernel driver - https://www.spinics.net/lists/linux-iio/msg25145.html - https://lore.kernel.org/patchwork/patch/684179/ I decided to keep it aside of AL3320A due to different approach and much simpler design of 3010. Tested on Nexus 7 2012 (grouper/tilapia). Tested-by: David Heidelberg Tested-by: Dmitry Osipenko Signed-off-by: David Heidelberg --- drivers/iio/light/Kconfig | 10 ++ drivers/iio/light/Makefile | 1 + drivers/iio/light/al3010.c | 217 +++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 drivers/iio/light/al3010.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 9968f982fbc7..43d9b830279d 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -43,6 +43,16 @@ config ADUX1020 To compile this driver as a module, choose M here: the module will be called adux1020. +config AL3010 + tristate "AL3010 ambient light sensor" + depends on I2C + help + Say Y here if you want to build a driver for the Dyna Image AL3010 + ambient light sensor. + + To compile this driver as a module, choose M here: the + module will be called al3010. + config AL3320A tristate "AL3320A ambient light sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index c98d1cefb861..88bb93550fcc 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311) += adjd_s311.o obj-$(CONFIG_ADUX1020) += adux1020.o +obj-$(CONFIG_AL3010) += al3010.o obj-$(CONFIG_AL3320A) += al3320a.o obj-$(CONFIG_APDS9300) += apds9300.o obj-$(CONFIG_APDS9960) += apds9960.o diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c new file mode 100644 index 000000000000..4b951c087c83 --- /dev/null +++ b/drivers/iio/light/al3010.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * AL3010 - Dyna Image Ambient Light Sensor + * + * Copyright (c) 2014, Intel Corporation. + * Copyright (c) 2016, Dyna-Image Corp. + * + * IIO driver for AL3010 (7-bit I2C slave address 0x1C). + * + * TODO: interrupt support, thresholds + */ + +#include +#include +#include + +#include +#include + +#define AL3010_DRV_NAME "al3010" + +#define AL3010_REG_SYSTEM 0x00 +#define AL3010_REG_DATA_LOW 0x0c +#define AL3010_REG_CONFIG 0x10 + +#define AL3010_CONFIG_DISABLE 0x00 +#define AL3010_CONFIG_ENABLE 0x01 + +#define AL3010_GAIN_SHIFT 4 +#define AL3010_GAIN_MASK (BIT(6) | BIT(5) | BIT(4)) + +#define AL3010_GAIN_READ(g) \ + (((g) & AL3010_GAIN_MASK) >> AL3010_GAIN_SHIFT) + +#define AL3010_GAIN_WRITE(g) \ + (((g) << AL3010_GAIN_SHIFT) & AL3010_GAIN_MASK) + +#define AL3010_SCALE_AVAILABLE "1.1872 0.2968 0.0742 0.018" + +enum al3xxxx_range { + AL3XXX_RANGE_1, /* 77806 lx */ + AL3XXX_RANGE_2, /* 19542 lx */ + AL3XXX_RANGE_3, /* 4863 lx */ + AL3XXX_RANGE_4 /* 1216 lx */ +}; + +static const int al3010_scales[][2] = { + {0, 1187200}, {0, 296800}, {0, 74200}, {0, 18600} +}; + +struct al3010_data { + struct i2c_client *client; +}; + +static const struct iio_chan_spec al3010_channels[] = { + { + .type = IIO_LIGHT, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + } +}; + +static IIO_CONST_ATTR(in_illuminance_scale_available, AL3010_SCALE_AVAILABLE); + +static struct attribute *al3010_attributes[] = { + &iio_const_attr_in_illuminance_scale_available.dev_attr.attr, + NULL, +}; + +static const struct attribute_group al3010_attribute_group = { + .attrs = al3010_attributes, +}; + +static int al3010_init(struct al3010_data *data) +{ + int ret; + + /* power on */ + ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_SYSTEM, + AL3010_CONFIG_ENABLE); + if (ret < 0) + return ret; + + ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_CONFIG, + AL3010_GAIN_WRITE(AL3XXX_RANGE_3)); + if (ret < 0) + return ret; + + return 0; +} + +static int al3010_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + struct al3010_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + /* + * ALS ADC value is stored in two adjacent registers: + * - low byte of output is stored at AL3010_REG_DATA_LOW + * - high byte of output is stored at AL3010_REG_DATA_LOW + 1 + */ + ret = i2c_smbus_read_word_data(data->client, + AL3010_REG_DATA_LOW); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + ret = i2c_smbus_read_byte_data(data->client, + AL3010_REG_CONFIG); + if (ret < 0) + return ret; + + ret = AL3010_GAIN_READ(ret); + *val = al3010_scales[ret][0]; + *val2 = al3010_scales[ret][1]; + + return IIO_VAL_INT_PLUS_MICRO; + } + return -EINVAL; +} + +static int al3010_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct al3010_data *data = iio_priv(indio_dev); + int i; + + switch (mask) { + case IIO_CHAN_INFO_SCALE: + for (i = 0; i < ARRAY_SIZE(al3010_scales); i++) { + if (val != al3010_scales[i][0] || + val2 != al3010_scales[i][1]) + continue; + + return i2c_smbus_write_byte_data(data->client, + AL3010_REG_CONFIG, + AL3010_GAIN_WRITE(i)); + } + break; + } + return -EINVAL; +} + +static const struct iio_info al3010_info = { + .read_raw = al3010_read_raw, + .write_raw = al3010_write_raw, + .attrs = &al3010_attribute_group, +}; + +static int al3010_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct al3010_data *data; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &al3010_info; + indio_dev->name = AL3010_DRV_NAME; + indio_dev->channels = al3010_channels; + indio_dev->num_channels = ARRAY_SIZE(al3010_channels); + indio_dev->modes = INDIO_DIRECT_MODE; + + ret = al3010_init(data); + if (ret < 0) { + dev_err(&client->dev, "al3010 chip init failed\n"); + return ret; + } + return devm_iio_device_register(&client->dev, indio_dev); +} + +static int al3010_remove(struct i2c_client *client) +{ + return i2c_smbus_write_byte_data(client, AL3010_REG_SYSTEM, + AL3010_CONFIG_DISABLE); +} + +static const struct i2c_device_id al3010_id[] = { + {"al3010", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, al3010_id); + +static const struct of_device_id al3010_of_match[] = { + { .compatible = "dynaimage,al3010", }, + {}, +}; +MODULE_DEVICE_TABLE(of, al3010_of_match); + +static struct i2c_driver al3010_driver = { + .driver = { + .name = AL3010_DRV_NAME, + .of_match_table = al3010_of_match, + }, + .probe = al3010_probe, + .remove = al3010_remove, + .id_table = al3010_id, +}; +module_i2c_driver(al3010_driver); + +MODULE_AUTHOR("Daniel Baluta "); +MODULE_DESCRIPTION("AL3010 Ambient Light Sensor driver"); +MODULE_LICENSE("GPL v2"); From patchwork Tue Jan 28 13:30:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15A0B92A for ; Tue, 28 Jan 2020 13:33:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F287B24688 for ; Tue, 28 Jan 2020 13:33:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726211AbgA1Nd0 (ORCPT ); Tue, 28 Jan 2020 08:33:26 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39076 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1Nd0 (ORCPT ); Tue, 28 Jan 2020 08:33:26 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id D4647251ED; Tue, 28 Jan 2020 14:33:23 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v2 5/7] iio: light: al3010 implement suspend support Date: Tue, 28 Jan 2020 14:30:50 +0100 Message-Id: <20200128133052.201587-6-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org AL3010 is fairly simple chip, so for suspend is enough to disable and later enable it again. Signed-off-by: David Heidelberg Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko --- drivers/iio/light/al3010.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c index 4b951c087c83..202f25b595c8 100644 --- a/drivers/iio/light/al3010.c +++ b/drivers/iio/light/al3010.c @@ -8,6 +8,9 @@ * IIO driver for AL3010 (7-bit I2C slave address 0x1C). * * TODO: interrupt support, thresholds + * When the driver will get support for interrupt handling, then interrupt + * will need to be disabled before turning sensor OFF in order to avoid + * potential races with the interrupt handling. */ #include @@ -71,13 +74,18 @@ static const struct attribute_group al3010_attribute_group = { .attrs = al3010_attributes, }; +static int al3010_set_pwr(struct i2c_client *client, bool pwr) +{ + u8 val = pwr ? AL3010_CONFIG_ENABLE : AL3010_CONFIG_DISABLE; + return i2c_smbus_write_byte_data(client, AL3010_REG_SYSTEM, val); +} + static int al3010_init(struct al3010_data *data) { int ret; - /* power on */ - ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_SYSTEM, - AL3010_CONFIG_ENABLE); + ret = al3010_set_pwr(data->client, true); + if (ret < 0) return ret; @@ -185,10 +193,21 @@ static int al3010_probe(struct i2c_client *client, static int al3010_remove(struct i2c_client *client) { - return i2c_smbus_write_byte_data(client, AL3010_REG_SYSTEM, - AL3010_CONFIG_DISABLE); + return al3010_set_pwr(client, false); } +static int __maybe_unused al3010_suspend(struct device *dev) +{ + return al3010_set_pwr(to_i2c_client(dev), false); +} + +static int __maybe_unused al3010_resume(struct device *dev) +{ + return al3010_set_pwr(to_i2c_client(dev), true); +} + +SIMPLE_DEV_PM_OPS(al3010_pm_ops, al3010_suspend, al3010_resume); + static const struct i2c_device_id al3010_id[] = { {"al3010", 0}, {} @@ -205,6 +224,7 @@ static struct i2c_driver al3010_driver = { .driver = { .name = AL3010_DRV_NAME, .of_match_table = al3010_of_match, + .pm = &al3010_pm_ops, }, .probe = al3010_probe, .remove = al3010_remove, From patchwork Tue Jan 28 13:30:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354269 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB9BE92A for ; Tue, 28 Jan 2020 13:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4D1D24688 for ; Tue, 28 Jan 2020 13:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726111AbgA1Nds (ORCPT ); Tue, 28 Jan 2020 08:33:48 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39092 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1Nds (ORCPT ); Tue, 28 Jan 2020 08:33:48 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id 9A25B251F0; Tue, 28 Jan 2020 14:33:46 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v2 6/7] iio: light: al3320a implement suspend support Date: Tue, 28 Jan 2020 14:30:51 +0100 Message-Id: <20200128133052.201587-7-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org AL3320a is fairly simple chip, so for suspend is enough to disable and later enable it again. Signed-off-by: David Heidelberg --- drivers/iio/light/al3320a.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index 613830b7df6e..d99f9d139b5f 100644 --- a/drivers/iio/light/al3320a.c +++ b/drivers/iio/light/al3320a.c @@ -7,6 +7,9 @@ * IIO driver for AL3320A (7-bit I2C slave address 0x1C). * * TODO: interrupt support, thresholds + * When the driver will get support for interrupt handling, then interrupt + * will need to be disabled before turning sensor OFF in order to avoid + * potential races with the interrupt handling. */ #include @@ -84,13 +87,19 @@ static const struct attribute_group al3320a_attribute_group = { .attrs = al3320a_attributes, }; +static int al3320a_set_pwr(struct i2c_client *client, bool pwr) +{ + u8 val = pwr ? AL3320A_CONFIG_ENABLE : AL3320A_CONFIG_DISABLE; + return i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG, val); +} + + static int al3320a_init(struct al3320a_data *data) { int ret; - /* power on */ - ret = i2c_smbus_write_byte_data(data->client, AL3320A_REG_CONFIG, - AL3320A_CONFIG_ENABLE); + ret = al3320a_set_pwr(data->client, true); + if (ret < 0) return ret; @@ -208,10 +217,21 @@ static int al3320a_probe(struct i2c_client *client, static int al3320a_remove(struct i2c_client *client) { - return i2c_smbus_write_byte_data(client, AL3320A_REG_CONFIG, - AL3320A_CONFIG_DISABLE); + return al3320a_set_pwr(client, false); +} + +static int __maybe_unused al3320a_suspend(struct device *dev) +{ + return al3320a_set_pwr(to_i2c_client(dev), false); +} + +static int __maybe_unused al3320a_resume(struct device *dev) +{ + return al3320a_set_pwr(to_i2c_client(dev), true); } +SIMPLE_DEV_PM_OPS(al3320a_pm_ops, al3320a_suspend, al3320a_resume); + static const struct i2c_device_id al3320a_id[] = { {"al3320a", 0}, {} @@ -221,6 +241,7 @@ MODULE_DEVICE_TABLE(i2c, al3320a_id); static struct i2c_driver al3320a_driver = { .driver = { .name = AL3320A_DRV_NAME, + .pm = &al3320a_pm_ops, }, .probe = al3320a_probe, .remove = al3320a_remove, From patchwork Tue Jan 28 13:30:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 11354271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89F851398 for ; Tue, 28 Jan 2020 13:34:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7226F22522 for ; Tue, 28 Jan 2020 13:34:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbgA1NeG (ORCPT ); Tue, 28 Jan 2020 08:34:06 -0500 Received: from ip-78-45-52-129.net.upcbroadband.cz ([78.45.52.129]:39108 "EHLO ixit.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgA1NeF (ORCPT ); Tue, 28 Jan 2020 08:34:05 -0500 Received: from localhost.localdomain (227.146.230.94.awnet.cz [94.230.146.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ixit.cz (Postfix) with ESMTPSA id C2628251F3; Tue, 28 Jan 2020 14:34:03 +0100 (CET) From: David Heidelberg To: linux-iio@vger.kernel.org Cc: David Heidelberg , Dmitry Osipenko , Daniel Baluta , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v2 7/7] iio: light: al3320a allow module autoload and polish Date: Tue, 28 Jan 2020 14:30:52 +0100 Message-Id: <20200128133052.201587-8-david@ixit.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128133052.201587-1-david@ixit.cz> References: <20200128133052.201587-1-david@ixit.cz> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org - allow autoloading when build as module and defined inside DT - drop init.h and alphabetically sort includes Signed-off-by: David Heidelberg --- drivers/iio/light/al3320a.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iio/light/al3320a.c b/drivers/iio/light/al3320a.c index d99f9d139b5f..d66c85b27907 100644 --- a/drivers/iio/light/al3320a.c +++ b/drivers/iio/light/al3320a.c @@ -12,9 +12,9 @@ * potential races with the interrupt handling. */ -#include -#include #include +#include +#include #include #include @@ -238,9 +238,16 @@ static const struct i2c_device_id al3320a_id[] = { }; MODULE_DEVICE_TABLE(i2c, al3320a_id); +static const struct of_device_id al3320a_of_match[] = { + { .compatible = "dynaimage,al3320a", }, + {}, +}; +MODULE_DEVICE_TABLE(of, al3320a_of_match); + static struct i2c_driver al3320a_driver = { .driver = { .name = AL3320A_DRV_NAME, + .of_match_table = al3320a_of_match, .pm = &al3320a_pm_ops, }, .probe = al3320a_probe,