From patchwork Tue Apr 14 15:34:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11488339 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 66D64913 for ; Tue, 14 Apr 2020 15:34:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 443C62076B for ; Tue, 14 Apr 2020 15:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878482; bh=8NmgVLUUS5Ln4TZqfeKplY2vLy6j085/h6+xraogB48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yjqMbrH8x4UwNTQ4QnE7pM/Kvoe1A8oSBbeSjhzKM4cfqbkGviC2Ca7iP0BaknUnn IlsFoe8u6h3+t7adzzNYuMzkMLhr77oaJL2GLyKWh78pisItLb9PjxBeDt+Y2dUyyA 2vhPJFh+A5Qcjs0VRDWyAq6QWETYJ4ohNoMEGUGU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439870AbgDNPei (ORCPT ); Tue, 14 Apr 2020 11:34:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:51830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439849AbgDNPee (ORCPT ); Tue, 14 Apr 2020 11:34:34 -0400 Received: from localhost.localdomain (unknown [157.50.36.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A8182075E; Tue, 14 Apr 2020 15:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878473; bh=8NmgVLUUS5Ln4TZqfeKplY2vLy6j085/h6+xraogB48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aytUxXRcWQpLpAZMwoqdlUAAitOGoeLB2iKU10rczRmAGB8XSWNTxk+1WLVNjQXf2 khWBAaKcD3xDk+6QVHdrLWenYDU+ufSpdOgOjmStTJbIAjoR7zm9dpEIZN5eN8W6LC AUnefMLIdw4+y21DqeaGTGbr07hY4mWZzomhYSeo= From: mani@kernel.org To: jic23@kernel.org, robh+dt@kernel.org, narcisaanamaria12@gmail.com Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, Manivannan Sadhasivam Subject: [PATCH v2 1/3] dt-bindings: iio: chemical: Add binding for CCS811 VOC sensor Date: Tue, 14 Apr 2020 21:04:13 +0530 Message-Id: <20200414153415.957-2-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414153415.957-1-mani@kernel.org> References: <20200414153415.957-1-mani@kernel.org> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Manivannan Sadhasivam This commit adds devicetree binding for AMS CCS811 VOC sensor. Signed-off-by: Manivannan Sadhasivam --- .../bindings/iio/chemical/ams,ccs811.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/ams,ccs811.yaml diff --git a/Documentation/devicetree/bindings/iio/chemical/ams,ccs811.yaml b/Documentation/devicetree/bindings/iio/chemical/ams,ccs811.yaml new file mode 100644 index 000000000000..5cb068666a3e --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/ams,ccs811.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/ams,ccs811.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AMS CCS811 VOC Sensor + +maintainers: + - Narcisa Vasile + +description: | + Ultra-Low Power Digital Gas Sensor for Monitoring Indoor Air Quality. + +properties: + compatible: + enum: + - ams,ccs811 + reg: + maxItems: 1 + + reset-gpios: + description: GPIO connected to the nRESET line. This is an active low + input to CCS811. + maxItems: 1 + + wakeup-gpios: + description: GPIO connected to the nWAKE line. This is an active low + input to CCS811. + maxItems: 1 + +required: + - compatible + - reg + +examples: + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + voc@5b { + compatible = "ams,ccs811"; + reg = <0x5b>; + reset-gpios = <&gpioa 11 GPIO_ACTIVE_LOW>; + wakeup-gpios = <&gpioa 12 GPIO_ACTIVE_LOW>; + }; + }; + +... From patchwork Tue Apr 14 15:34:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11488341 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 62BBB92C for ; Tue, 14 Apr 2020 15:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B2562075E for ; Tue, 14 Apr 2020 15:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878487; bh=O2nCUlLkJdqecXXgDbJtU1hU3YR6xYvefuGSMW4F7dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Rswbq0UPAkLrS6ekz1dtTmVnvKuPQ8/tCT4bsv7VVX1GNmHI8ChWeNuVaZFpZ/FJg cTjG36wpVYP/ITuSW9IdHujjF5bttLm96EBkcV4YNqF/WHS3c3bEAqc/5IhC6JBOFj PTcKs5PN0Zgh1VqHQgbvGPf9m2JaTBgoMX/hO5qQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439881AbgDNPeo (ORCPT ); Tue, 14 Apr 2020 11:34:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:51848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439872AbgDNPej (ORCPT ); Tue, 14 Apr 2020 11:34:39 -0400 Received: from localhost.localdomain (unknown [157.50.36.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C904B206D5; Tue, 14 Apr 2020 15:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878478; bh=O2nCUlLkJdqecXXgDbJtU1hU3YR6xYvefuGSMW4F7dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ASW+44lXLVTsBQbwa6RrfkR0SkmGoZ9HhbR3VSccKrsRVjoqWQ+uOXVnup9bwmAjZ N3CT23y6KMBmFkPYW6iUYyi8ky937iBeVi3wbpdanCi3bWUdqjvMZZvCHw3oSwyVIQ J+vGE3P79F7/p/5IKtekNOFFwCQaVX8zr+oUVmW8= From: mani@kernel.org To: jic23@kernel.org, robh+dt@kernel.org, narcisaanamaria12@gmail.com Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, Manivannan Sadhasivam Subject: [PATCH v2 2/3] iio: chemical: Add support for external Reset and Wakeup in CCS811 Date: Tue, 14 Apr 2020 21:04:14 +0530 Message-Id: <20200414153415.957-3-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414153415.957-1-mani@kernel.org> References: <20200414153415.957-1-mani@kernel.org> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Manivannan Sadhasivam CCS811 VOC sensor exposes nRESET and nWAKE pins which can be connected to GPIO pins of the host controller. These pins can be used to externally release the device from reset and also to wake it up before any I2C transaction. The initial driver support assumed that the nRESET pin is not connected and the nWAKE pin is tied to ground. This commit improves it by adding support for controlling those two pins externally using a host controller. For the case of reset, if the hardware reset is not available, the mechanism to do software reset is also added. As a side effect of doing this, the IIO device allocation needs to be slightly moved to top of probe to make use of priv data early. Signed-off-by: Manivannan Sadhasivam --- drivers/iio/chemical/ccs811.c | 88 +++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 8 deletions(-) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 2ebdfc35bcda..951358710f64 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -36,6 +37,7 @@ #define CCS811_ERR 0xE0 /* Used to transition from boot to application mode */ #define CCS811_APP_START 0xF4 +#define CCS811_SW_RESET 0xFF /* Status register flags */ #define CCS811_STATUS_ERROR BIT(0) @@ -74,6 +76,7 @@ struct ccs811_data { struct mutex lock; /* Protect readings */ struct ccs811_reading buffer; struct iio_trigger *drdy_trig; + struct gpio_desc *wakeup_gpio; bool drdy_trig_on; }; @@ -166,10 +169,25 @@ static int ccs811_setup(struct i2c_client *client) CCS811_MODE_IAQ_1SEC); } +static void ccs811_set_wakeup(struct ccs811_data *data, bool enable) +{ + if (!data->wakeup_gpio) + return; + + gpiod_set_value(data->wakeup_gpio, enable); + + if (enable) + usleep_range(50, 60); + else + usleep_range(20, 30); +} + static int ccs811_get_measurement(struct ccs811_data *data) { int ret, tries = 11; + ccs811_set_wakeup(data, true); + /* Maximum waiting time: 1s, as measurements are made every second */ while (tries-- > 0) { ret = i2c_smbus_read_byte_data(data->client, CCS811_STATUS); @@ -183,9 +201,12 @@ static int ccs811_get_measurement(struct ccs811_data *data) if (!(ret & CCS811_STATUS_DATA_READY)) return -EIO; - return i2c_smbus_read_i2c_block_data(data->client, + ret = i2c_smbus_read_i2c_block_data(data->client, CCS811_ALG_RESULT_DATA, 8, (char *)&data->buffer); + ccs811_set_wakeup(data, false); + + return ret; } static int ccs811_read_raw(struct iio_dev *indio_dev, @@ -336,6 +357,42 @@ static irqreturn_t ccs811_data_rdy_trigger_poll(int irq, void *private) return IRQ_HANDLED; } +static int ccs811_reset(struct i2c_client *client) +{ + struct gpio_desc *reset_gpio; + int ret; + + reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(reset_gpio)) { + dev_err(&client->dev, "Failed to acquire reset gpio\n"); + return PTR_ERR(reset_gpio); + } + + /* Try to reset using nRESET pin if available else do SW reset */ + if (reset_gpio) { + gpiod_set_value(reset_gpio, 1); + usleep_range(20, 30); + gpiod_set_value(reset_gpio, 0); + } else { + static const u8 reset_seq[] = { + 0xFF, 0x11, 0xE5, 0x72, 0x8A, + }; + + ret = i2c_smbus_write_i2c_block_data(client, CCS811_SW_RESET, + sizeof(reset_seq), reset_seq); + if (ret < 0) { + dev_err(&client->dev, "Failed to reset sensor\n"); + return ret; + } + } + + /* tSTART delay required after reset */ + usleep_range(1000, 2000); + + return 0; +} + static int ccs811_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -348,6 +405,27 @@ static int ccs811_probe(struct i2c_client *client, | I2C_FUNC_SMBUS_READ_I2C_BLOCK)) return -EOPNOTSUPP; + 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; + + data->wakeup_gpio = devm_gpiod_get_optional(&client->dev, "wakeup", + GPIOD_OUT_HIGH); + if (IS_ERR(data->wakeup_gpio)) { + dev_err(&client->dev, "Failed to acquire wakeup gpio\n"); + return PTR_ERR(data->wakeup_gpio); + } + + ccs811_set_wakeup(data, true); + + ret = ccs811_reset(client); + if (ret) + return ret; + /* Check hardware id (should be 0x81 for this family of devices) */ ret = i2c_smbus_read_byte_data(client, CCS811_HW_ID); if (ret < 0) @@ -367,17 +445,11 @@ static int ccs811_probe(struct i2c_client *client, return -ENODEV; } - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); - if (!indio_dev) - return -ENOMEM; - ret = ccs811_setup(client); if (ret < 0) return ret; - data = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); - data->client = client; + ccs811_set_wakeup(data, false); mutex_init(&data->lock); From patchwork Tue Apr 14 15:34:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11488343 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 9CF0D92C for ; Tue, 14 Apr 2020 15:34:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 866C020768 for ; Tue, 14 Apr 2020 15:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878494; bh=Oc9ojVnSei1ncXI3HlXO8s4gqtOD7PSAftmFoOPklOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=YMdoiuD3J/5Jezc3jO3aL/fnIsLdNOmo8YSdV4mtcIvD8zW840N4h8uB65Pkh61hW cG2YQDzCbjNfHM4WcMZeVWQ/cQ0ixroj+YpsB27ORoP8B0ypcrK0HAE8l1x0Koj8hS yKRSkwU3Ds+sHLr7eoq2SHUpYY1WOoZpDLE7XU2I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439892AbgDNPeu (ORCPT ); Tue, 14 Apr 2020 11:34:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:51870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439882AbgDNPep (ORCPT ); Tue, 14 Apr 2020 11:34:45 -0400 Received: from localhost.localdomain (unknown [157.50.36.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E4DDD20678; Tue, 14 Apr 2020 15:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586878484; bh=Oc9ojVnSei1ncXI3HlXO8s4gqtOD7PSAftmFoOPklOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=enZpW1mZ6n3HX88iREH1EmVvt8RxSbz6X/eYdqubeNcGeWvc633gbp6FGhVNgj7XO LgJoHPshqy6WMTUyZ3S7XsQaMrHbi+9wwCRaoTQN/BsZnfpM699Qn/F5NzEqXNZ5BH EuYzQN1PnBRvx+fskzc47UcfSFBlgscEDAwqRttc= From: mani@kernel.org To: jic23@kernel.org, robh+dt@kernel.org, narcisaanamaria12@gmail.com Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, Manivannan Sadhasivam Subject: [PATCH v2 3/3] iio: chemical: Add OF match table for CCS811 VOC sensor Date: Tue, 14 Apr 2020 21:04:15 +0530 Message-Id: <20200414153415.957-4-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414153415.957-1-mani@kernel.org> References: <20200414153415.957-1-mani@kernel.org> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Manivannan Sadhasivam Add devicetree OF match table support for CCS811 VOC sensor. Signed-off-by: Manivannan Sadhasivam Reviewed-by: Andy Shevchenko --- drivers/iio/chemical/ccs811.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 951358710f64..310e9dedc9ba 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -538,9 +538,16 @@ static const struct i2c_device_id ccs811_id[] = { }; MODULE_DEVICE_TABLE(i2c, ccs811_id); +static const struct of_device_id ccs811_dt_ids[] = { + { .compatible = "ams,ccs811" }, + { } +}; +MODULE_DEVICE_TABLE(of, ccs811_dt_ids); + static struct i2c_driver ccs811_driver = { .driver = { .name = "ccs811", + .of_match_table = ccs811_dt_ids, }, .probe = ccs811_probe, .remove = ccs811_remove,