From patchwork Tue Apr 14 18:41:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11488999 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 79A6292C for ; Tue, 14 Apr 2020 18:42:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BDF720787 for ; Tue, 14 Apr 2020 18:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889731; bh=GmR7lfNoDSQr8Ig6vDLzXWqlig8GgJx5VD62/dqRlrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=LrnOBQDm/IxdKX1uOUrXqL5xbSpLO+AraWcCkf6fDscHFbduApcvh9jrk04k0ZlP3 r0PKoZ/874nFeVFl4QK1rzkESCAkdazT3dFoJs3UKrtgCxkQBOO9W+qwxpuWlZ1av7 NJkU9oua5W4KgtIByGz1BaBHqAldkl/PGWYBtaf8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504174AbgDNSmJ (ORCPT ); Tue, 14 Apr 2020 14:42:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504169AbgDNSmG (ORCPT ); Tue, 14 Apr 2020 14:42:06 -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 2C1442078A; Tue, 14 Apr 2020 18:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889725; bh=GmR7lfNoDSQr8Ig6vDLzXWqlig8GgJx5VD62/dqRlrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q3d82hU1cv8zRNH4RBVEcdGMMxnC6rril8XOse701E9rKVvEjJvzPfulyERNm+fvY HyIg+QZVXKdy2wK1tIG68vUGkMLladoEDHmbvtrH2kNJ3iKNdDs/x5OcXyqdD8u4/U pSarCcjSI7AHkroaaNZ+M8xBg+lQ8qftR468N1bY= 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 v3 1/3] iio: chemical: Add support for external Reset and Wakeup in CCS811 Date: Wed, 15 Apr 2020 00:11:45 +0530 Message-Id: <20200414184147.4857-2-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414184147.4857-1-mani@kernel.org> References: <20200414184147.4857-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 | 105 ++++++++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 11 deletions(-) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index 2ebdfc35bcda..1500e4b0dfbd 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,45 @@ 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)) + 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 { + /* + * As per the datasheet, this sequence of values needs to be + * written to the SW_RESET register for triggering the soft + * reset in the device and placing it in boot mode. + */ + static const u8 reset_seq[] = { + 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,36 +408,59 @@ 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)) + return PTR_ERR(data->wakeup_gpio); + + ccs811_set_wakeup(data, true); + + ret = ccs811_reset(client); + if (ret) { + ccs811_set_wakeup(data, false); + 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) + if (ret < 0) { + ccs811_set_wakeup(data, false); return ret; + } if (ret != CCS811_HW_ID_VALUE) { dev_err(&client->dev, "hardware id doesn't match CCS81x\n"); + ccs811_set_wakeup(data, false); return -ENODEV; } ret = i2c_smbus_read_byte_data(client, CCS811_HW_VERSION); - if (ret < 0) + if (ret < 0) { + ccs811_set_wakeup(data, false); return ret; + } if ((ret & CCS811_HW_VERSION_MASK) != CCS811_HW_VERSION_VALUE) { dev_err(&client->dev, "no CCS811 sensor\n"); + ccs811_set_wakeup(data, false); return -ENODEV; } - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); - if (!indio_dev) - return -ENOMEM; - ret = ccs811_setup(client); - if (ret < 0) + if (ret < 0) { + ccs811_set_wakeup(data, false); 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 18:41:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11489001 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 1487192C for ; Tue, 14 Apr 2020 18:42:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4A3E20787 for ; Tue, 14 Apr 2020 18:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889739; bh=Qr/sUzlLBeiS7flY0fWa67V38Y7Io0QddHUGCTBCdz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jEjjrCf2kzP/bCYa3MCANaVjLWdTgzLZ5Pxd9iObuv+H+8u2VlI5X+1Y3jgSo/zIy SRSCdDyT22LKTr0EkR4uHTlPaM7Uv57Rt0wtULD2WIzgQ1c9rkR8alZZ1hw29aHrKe p2FMOIeIePcO7wR77F9aqaPxjy06RqYhZMN+qdN8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504181AbgDNSmP (ORCPT ); Tue, 14 Apr 2020 14:42:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504176AbgDNSmL (ORCPT ); Tue, 14 Apr 2020 14:42:11 -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 09D582074D; Tue, 14 Apr 2020 18:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889730; bh=Qr/sUzlLBeiS7flY0fWa67V38Y7Io0QddHUGCTBCdz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wuUYtJ8paNt9+xhemECaglrMTbULZRC3febZULUIXOEiWsg4QK5aWc8ZGoaPPMyM1 vbMRkqPzAmaIgAaJ0eyO+O7No7q2RDMvoAOsb8PLgboJRFTsqVoi3ZWLXXJRhqriDD lY6lBJKDmwnd2K9ZmWb9Oyd3+ES5cRI6QdRnhHCg= 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 v3 2/3] iio: chemical: Add OF match table for CCS811 VOC sensor Date: Wed, 15 Apr 2020 00:11:46 +0530 Message-Id: <20200414184147.4857-3-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414184147.4857-1-mani@kernel.org> References: <20200414184147.4857-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. Reviewed-by: Andy Shevchenko Signed-off-by: Manivannan Sadhasivam --- 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 1500e4b0dfbd..3ecd633f9ed3 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -549,9 +549,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, From patchwork Tue Apr 14 18:41:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 11489003 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 46D3A14DD for ; Tue, 14 Apr 2020 18:42:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E16F2074D for ; Tue, 14 Apr 2020 18:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889749; bh=lfSCUvZbahM1QeSSb7gds/7IyrvOA74gzlG0YM7J3PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FZQ58Qc0ikW4o+c3FARYX2t4sOcf4Plzu5E8ITfZvs0p/rxznCTchArtTqdxoWbyw sbAyA/2KskD3ymoPUqsfM/LJAZar9+45499Ulzxea7KF3XMrXE3pBObkkpxHJhmCqS DDxAtquhqiQCR8KKeaYIehVkHg921zQw20XH3YUA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504189AbgDNSmW (ORCPT ); Tue, 14 Apr 2020 14:42:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:39228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504184AbgDNSmR (ORCPT ); Tue, 14 Apr 2020 14:42:17 -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 6C7B2208FE; Tue, 14 Apr 2020 18:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586889737; bh=lfSCUvZbahM1QeSSb7gds/7IyrvOA74gzlG0YM7J3PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kq9hj8bzUBKBAXYzKGghDESvE+FHwmEbLm3Uo1eZ7vJlewn1ZeIz02zPskSlR1lAH Lv+7741CN1QAw45svmDXbfSzkRXBriwJ4b65yLNqtrViWmn9dgo43DcDx7bn16yRJj ERq1lG1O7baibJqrwl5OwpcTR39ZM9U/6Tzb5lgg= 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 v3 3/3] dt-bindings: serial: Add binding for software flow control in STM32 UART Date: Wed, 15 Apr 2020 00:11:47 +0530 Message-Id: <20200414184147.4857-4-mani@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414184147.4857-1-mani@kernel.org> References: <20200414184147.4857-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 binding for software flow control in STM32 UART controller. While at it, let's also fix one schema error reported by `make dtbs_check`. Signed-off-by: Manivannan Sadhasivam --- .../devicetree/bindings/serial/st,stm32-uart.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml index 238c44192d31..ea5797a1b403 100644 --- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml +++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml @@ -38,13 +38,26 @@ properties: description: enable hardware flow control $ref: /schemas/types.yaml#/definitions/flag + st,sw-flow-ctrl: + description: enable software flow control + $ref: /schemas/types.yaml#/definitions/flag + + rts-gpios: + description: RTS pin used if st,sw-flow-ctrl is true + maxItems: 1 + + cts-gpios: + description: CTS pin used if st,sw-flow-ctrl is true + maxItems: 1 + dmas: minItems: 1 maxItems: 2 dma-names: items: - enum: [ rx, tx ] + - const: rx + - const: tx minItems: 1 maxItems: 2