From patchwork Wed Dec 12 01:39:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725433 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 366B5112E for ; Wed, 12 Dec 2018 01:40:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 222782A7C3 for ; Wed, 12 Dec 2018 01:40:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FC332A7E2; Wed, 12 Dec 2018 01:40:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F8482A7C3 for ; Wed, 12 Dec 2018 01:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbeLLBka (ORCPT ); Tue, 11 Dec 2018 20:40:30 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50356 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLLBk3 (ORCPT ); Tue, 11 Dec 2018 20:40:29 -0500 Received: by mail-wm1-f66.google.com with SMTP id n190so4154583wmd.0; Tue, 11 Dec 2018 17:40:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rCibx6093XLv0OtPOKaZrSvbB8TaTTmfDw79TizC/XM=; b=P/NEJVutKq97idZtSWRcz/BW+S8LjnLnXDoj+pzPLE+RcZkP62R5vpQFbP5pQqDYIt DWkm70d5iklWxpBfSYkC63rNXtIAAeK1BhMX/0b36yYwFxk7j01fKGETQ1vLK+WXUY7L TbfZY1UePc+6vCkOnIsL8j3uEInCc0cyRNZPeE++wLtdBr4BQGeIidaEVsxGkMMHTtpK WQFgEdFKO2PxmfeLS2Yp6cCSdWpuKuNbkJQiDC/izN3Myxy/qq+I8AnIbnc10WWF/PrZ cADYJzn/pdmhP+ZKXUd8AEBNnA8GrN54bBVBqOEhVjFEz43ftTPEofgWvMSB/WgMqGXf 7Smw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rCibx6093XLv0OtPOKaZrSvbB8TaTTmfDw79TizC/XM=; b=s2+MgM/XxsvXTkTNCSfSQTXITbgGAI/dKedfvCZDWEK+mhQGup23g/l+Y8nHspUUN4 6BZfnl8fAzgeeyAWPoCzZ8b82S9FlSPB9rQN2nRh/KMjLvze9zdGvpgYn/BKsjnzs+nO sq9Yz7ZklO9E54wK+kBLpYU8QEq/drn7GOA+H2AqeuS+gtFBjclBVln5UWLjr949dqWw dz8Ov/2nHE++ZG2hSqX2orMjiq+2r3wrtJkPyKbMsh5IKNHS0ArJH59+N6Phtb5DQ2EQ UtaRTRsnUiDkdxJAElg3l/Emtxe8A2jbgj+Q1o/eUroyXpA7dFiDn9VfV5COnHahVsTZ sd9g== X-Gm-Message-State: AA+aEWaA8zfqWfd8wnlNXw49EBy5Gp+l4wrBUZJDGJiREvTVRz5u6H0+ IVT/J04FaNTLeTrdoiuIla1q6p6H X-Google-Smtp-Source: AFSGD/V04La3Fdy7SyhKuslYc6m3IMyse2fMkyRDa0U4OsvA5h6uB37fi+/Er9jn0Ar5KQgKIgU7Eg== X-Received: by 2002:a1c:d7d3:: with SMTP id o202mr4677958wmg.135.1544578827462; Tue, 11 Dec 2018 17:40:27 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:26 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 01/14] gpio: pca953x: Deduplicate the bank_shift Date: Wed, 12 Dec 2018 02:39:49 +0100 Message-Id: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The bank_shift = fls(...) code was duplicated in the driver 5 times, pull it into separate function. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski Reviewed-by: Kieran Bingham --- V2: Replace bank_size with bank_shift in commit message --- drivers/gpio/gpio-pca953x.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 540166443c34..afe6de4c48c4 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -159,11 +159,16 @@ struct pca953x_chip { int (*read_regs)(struct pca953x_chip *, int, u8 *); }; +static int pca953x_bank_shift(struct pca953x_chip *chip) +{ + return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); +} + static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, int off) { int ret; - int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); + int bank_shift = pca953x_bank_shift(chip); int offset = off / BANK_SZ; ret = i2c_smbus_read_byte_data(chip->client, @@ -182,7 +187,7 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, int off) { int ret; - int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); + int bank_shift = pca953x_bank_shift(chip); int offset = off / BANK_SZ; ret = i2c_smbus_write_byte_data(chip->client, @@ -221,7 +226,7 @@ static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val) { - int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); + int bank_shift = pca953x_bank_shift(chip); int addr = (reg & PCAL_GPIO_MASK) << bank_shift; int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; @@ -265,7 +270,7 @@ static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val) { - int bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); + int bank_shift = pca953x_bank_shift(chip); int addr = (reg & PCAL_GPIO_MASK) << bank_shift; int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; @@ -402,13 +407,12 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { struct pca953x_chip *chip = gpiochip_get_data(gc); + int bank_shift = pca953x_bank_shift(chip); unsigned int bank_mask, bank_val; - int bank_shift, bank; + int bank; u8 reg_val[MAX_BANK]; int ret; - bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); - mutex_lock(&chip->i2c_lock); memcpy(reg_val, chip->reg_output, NBANK(chip)); for (bank = 0; bank < NBANK(chip); bank++) { From patchwork Wed Dec 12 01:39:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725435 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93D69112E for ; Wed, 12 Dec 2018 01:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 817182A7C3 for ; Wed, 12 Dec 2018 01:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74E102A7E2; Wed, 12 Dec 2018 01:40:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 222242A7C3 for ; Wed, 12 Dec 2018 01:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726285AbeLLBkb (ORCPT ); Tue, 11 Dec 2018 20:40:31 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46530 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLLBkb (ORCPT ); Tue, 11 Dec 2018 20:40:31 -0500 Received: by mail-wr1-f67.google.com with SMTP id l9so15970526wrt.13; Tue, 11 Dec 2018 17:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OgIpEdc0NDVKGcQHMl3maDPaoBVLT3/5ZZoqfVJ5oSY=; b=crl1M4gBgYxyefUD1hKpS314r7kp/nq7jYJZtXOVK392lHZXKG+8mq/5/A+FMWh3Pf MrBi5r4KwWkrlSVlx3bKwjOe9tMJmQfTrni0hve6iDfVBdwC6L6LWPDQOW3DNmlza8bJ o+jBKUzWuVaeCxoXYR8UrZj9V+Qc12ojKzCGNhWHJs0/xDv2CSu6oYlwaF/YQvlyIVkC 6vjG0xsz6HQatjkly27jOQH8vtBM2CckRbBA4MGy48Wx06T3YMQL6BMb/X0o+uqiSRJ3 opVLVaKHdZHWuzORYP+KyFCGHED524LAoka3qQIcPngvWVgPqvsGtzVurk850ymu5P7M PfGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OgIpEdc0NDVKGcQHMl3maDPaoBVLT3/5ZZoqfVJ5oSY=; b=GlXjz55/TwJaVyT96ZOPh1a1ExXJqpiOL+QdjCwRsGTjvWH5x9B/SRCQXd60Q/m8cG U4hofREa8luc2a+Z4AJwcBcUu0IektBA1TtgUMxG2eZ71kQHVZQNpbDyG6xULnlAsUVS C1LDmLY6az0efaM1a/WCqmHv+ZxxpmWG1zihyltqIrphum8c9eSGu/aizmBLiUUWrm7/ FxROPKuePBhYhTvXaFGvC9HgSRE94a5ajjU3Hj1kjDZS4LEONzv5n6xNdBMQpA1tgdHV 7eLpXFon2YtRTqCbvJU/Jl0vFlcFuNDya8plmoBren58hWOPEnvKc8mhSGjnRKOYfLkv xyjg== X-Gm-Message-State: AA+aEWYXesZMNW61QXzGO6/x2p5YXiSWMLFyaCSrIc1uxgk7KcbSZXd0 z+9NY9RoC+A/fJM9F0s1zkUht5NM X-Google-Smtp-Source: AFSGD/V8Jwe0w7gmrnOjkAbMcivFmL+YQnzjYR/UllGCsk+zFduNDkDBcxL559zMvMUmxqr80Mnikg== X-Received: by 2002:adf:8342:: with SMTP id 60mr14604756wrd.212.1544578828765; Tue, 11 Dec 2018 17:40:28 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:27 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 02/14] gpio: pca953x: Fix AI overflow on PCAL6524 Date: Wed, 12 Dec 2018 02:39:50 +0100 Message-Id: <20181212014002.4753-2-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The PCAL_PINCTRL_MASK is too large. The extended register block on PCAL6524, which is the largest chip with this block, has the block limited to address range 0x40..0x7f. This is because the bit 7 in the command register is used for the Address Increment functionality. Trim the mask to 0x60 to match the datasheet and to prevent accidental overwrite of the AI bit. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski Reviewed-by: Bartosz Golaszewski --- V2: Add RB from Bart --- drivers/gpio/gpio-pca953x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index afe6de4c48c4..ec9fd11cd21c 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -58,7 +58,7 @@ #define PCA_GPIO_MASK 0x00FF #define PCAL_GPIO_MASK 0x1f -#define PCAL_PINCTRL_MASK 0xe0 +#define PCAL_PINCTRL_MASK 0x60 #define PCA_INT 0x0100 #define PCA_PCAL 0x0200 From patchwork Wed Dec 12 01:39:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725437 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75459159A for ; Wed, 12 Dec 2018 01:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 600612A7C3 for ; Wed, 12 Dec 2018 01:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F2F82A7E2; Wed, 12 Dec 2018 01:40:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF75A2A7C3 for ; Wed, 12 Dec 2018 01:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726309AbeLLBkd (ORCPT ); Tue, 11 Dec 2018 20:40:33 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38318 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLLBkd (ORCPT ); Tue, 11 Dec 2018 20:40:33 -0500 Received: by mail-wm1-f67.google.com with SMTP id m22so4229850wml.3; Tue, 11 Dec 2018 17:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lbs5gg62732h5zCjnUEcSBYfHb4JmLXnFfVOZ2cKzYw=; b=ngMFkEOWBmsDCdFT2pPwJ7q05rOc5zlopVJf2eWHOTNoheQHEaLA0t06GlM3MEndlE Ud0dToBlUazYwg2yCVcujAl1DB2pIP3qE9bo+bbcnhINbz1hG2UmIRqfpnyEp9GyLT79 tW/Jqh0w9uLiOyI6LYZhVzi8x6ZY0kRswoptB59WGka1hhDfNUAizYdxO26RBq8XEZQ5 BEJLe+Hi6+ASKBJQNmw0gONSo7zSQ5NRkkD3XkXUR7HOWDiQW/T9Z5dm7Upsl7QyAs6D fb5W1M0NcvqUIs8JQZG6jnRQ451hdSWzGGVVT4cdgc5L+oOCOwQjiRY+3y3FycI9EPca UydQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lbs5gg62732h5zCjnUEcSBYfHb4JmLXnFfVOZ2cKzYw=; b=CPP9eyaPeFO1SX/bRuskzbn+6ihWFd18X19VzrVdpk1kAX6Csu08mbIN++lxc4ZWDN L4A4ctHEGh3dQq5+2g27xAyV0cwIqLz8X6gyJQRIx6HektbDnC7bwWxPBnjDHCv6ZTBb Gg3Ey1FS52rLykme+SbU7IGBMYZinGL96sVJN0vZf8GLGEsOmFe+WYBCMrzY9UQZQsY1 WAdK6fwqV9/hzgyGUNWmRRRlrn5+uiLC41K6l77go7IENCajv6O7Fj9FimP081qM51Ax yeNIWso+VeFYdjGoAZjIxO5a6NaVnRmn5Lmh9EvhrtNJUznWUXXSV9RIeu/jeT4vyp6l jviw== X-Gm-Message-State: AA+aEWagJWZq41fq79xLOM4NReeTOeG9STCUUjJe5HnwbhCKz19B3Zat 5Tw2O2S22hmC/CE4zieC6LaTPFSK X-Google-Smtp-Source: AFSGD/UyHH3JWJ17NuRExW0vBAVmnuYGPvVLHLVl5Q/5y16E69QdTJqZVJoqaeo3hf4RiuJZiV98/A== X-Received: by 2002:a7b:c442:: with SMTP id l2mr4428315wmi.140.1544578830104; Tue, 11 Dec 2018 17:40:30 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:29 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 03/14] gpio: pca953x: Repair multi-byte IO address increment on PCA9575 Date: Wed, 12 Dec 2018 02:39:51 +0100 Message-Id: <20181212014002.4753-3-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The multi-byte IO on various pca953x chips requires the auto-increment bit, while other chips toggle the LSbit automatically. Note that LSbit toggling only alternates between two registers during the IO, it is not the same as address auto-increment. The driver currently assumes that #gpios > 16 implies auto-increment, while #gpios <= 16 implies LSbit toggling. This is incorrect at there are chips with 16 GPIOs which require the auto-increment bit. The PCA9575, according to NXP datasheet rev. 4.2 from 16 April 2015, section 7.3 Command Register, the bit 7 in command register is the auto-increment bit, which allows programming multiple registers sequentially. Set this bit both in pca953x_gpio_set_multiple(), where it fixes the multi register programming, and in pca957x_write_regs_16(), where is simplifies the function. In fact, the pca957x_write_regs_16() now looks rather similar to pca953x_write_regs_24() and pca953x_write_regs_16(), which is intended for subsequent patches. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index ec9fd11cd21c..8f6478f4545f 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -215,13 +215,10 @@ static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) { - int ret; - - ret = i2c_smbus_write_byte_data(chip->client, reg << 1, val[0]); - if (ret < 0) - return ret; + u32 regaddr = (reg << 1) | REG_ADDR_AI; - return i2c_smbus_write_byte_data(chip->client, (reg << 1) + 1, val[1]); + return i2c_smbus_write_i2c_block_data(chip->client, regaddr, + NBANK(chip), val); } static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val) @@ -408,6 +405,7 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, { struct pca953x_chip *chip = gpiochip_get_data(gc); int bank_shift = pca953x_bank_shift(chip); + u32 regaddr = chip->regs->output << bank_shift; unsigned int bank_mask, bank_val; int bank; u8 reg_val[MAX_BANK]; @@ -426,8 +424,13 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, } } - ret = i2c_smbus_write_i2c_block_data(chip->client, - chip->regs->output << bank_shift, + /* PCA9575 needs address-increment on multi-byte writes */ + if ((PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) && + (NBANK(chip) > 1)) { + regaddr |= REG_ADDR_AI; + } + + ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr, NBANK(chip), reg_val); if (ret) goto exit; From patchwork Wed Dec 12 01:39:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725439 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 371F13E9D for ; Wed, 12 Dec 2018 01:40:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27D9D2A7C3 for ; Wed, 12 Dec 2018 01:40:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C5CF2A7E2; Wed, 12 Dec 2018 01:40:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B384E2A7C3 for ; Wed, 12 Dec 2018 01:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbeLLBke (ORCPT ); Tue, 11 Dec 2018 20:40:34 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46530 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeLLBke (ORCPT ); Tue, 11 Dec 2018 20:40:34 -0500 Received: by mail-wr1-f65.google.com with SMTP id l9so15970607wrt.13; Tue, 11 Dec 2018 17:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PoFi/6xWt0t7twyJW3rX+5VrLthttOb8iXjJTwRe0ZM=; b=ahFdpLPOrZHYw1Zyxw8P+OTz+BMg+aIRpOdW0wDx/wPsAKbZgfsuAAqpukeU96883a 7NyVJxElQ4eKdIHoFB8eivZRnAl8iPtYxKNRA3i+go8J0rIYigf+KbbMVhUU7bMO5jSa Oeu3Z0hoF+KOquh9x/Zitw7QcW74nFFOyq4w1iU4QWi8f0PmHP8uPW4KfzY1dWrEd6mj zGybhCIN14YPS8B25WyPna8MTtjobDTDff52eXEY9l1LC0edz7j+y01PiZTJLY8E9l1/ bGO0dIB0xFN440oIcUDj4t5V9b5hfBVTwp2cSm45ueJ0tje2qDAKAEmCET+1A6FYwE7V d+/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PoFi/6xWt0t7twyJW3rX+5VrLthttOb8iXjJTwRe0ZM=; b=K0qjUZqXaaXJo+zcm/zBktFClmkeWrOzwFpW2Yp+tq29wvrU+d35r41KGD1/7qkNvu 7f8Muw+35fLuOygXyX+wB51t/GO0wp8AXI1eY1qkVoZvZwVkjI7J6cSkAwp7TSHGBgWi GY+edE4BV7/i/hls2DzLOlkEBf2vP7dqHY6UE4vXQyUWgpa5VGYTY5ZI4BCrRCqZhbcn PzEsjlK8zcMEA58oCXHY8GK7NSPnhfbYfKW6cTxTzLhzmvbL+EY41M93WDpIQdm16zNL 0PeSVjAsgiHN5ZURujF+DQC45D+EiuFWan59BuO6T3CgMTQqyBJDxhNxPqtU4kzZZ156 +sOA== X-Gm-Message-State: AA+aEWYPCcEEJiN33MUQE/x1adPWDPr076qN5uXC1ADZBRu95mLjcO+2 a1Q3XPL2DbCjZJhfQXvcqU31CQ9a X-Google-Smtp-Source: AFSGD/V7hTRuWMkCXh9wRcVHk8RHq4Tsy2RoQOeZb9qTrxRdMKV9halWxofOrIjw8YQICI8LYPdhLg== X-Received: by 2002:a5d:6710:: with SMTP id o16mr15834046wru.152.1544578831609; Tue, 11 Dec 2018 17:40:31 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:30 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 04/14] gpio: pca953x: Unify pca95{3,7}x_write_regs_16() Date: Wed, 12 Dec 2018 02:39:52 +0100 Message-Id: <20181212014002.4753-4-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At this point, these two functions only differ in whether they do or do not set the address increment bit on PCA9575. Merge these two functions together to simplify the code a bit. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 8f6478f4545f..7288a589a6b7 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -208,14 +208,11 @@ static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) { - u16 word = get_unaligned((u16 *)val); + u32 regaddr = (reg << 1); - return i2c_smbus_write_word_data(chip->client, reg << 1, word); -} - -static int pca957x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) -{ - u32 regaddr = (reg << 1) | REG_ADDR_AI; + /* PCA9575 needs address-increment on multi-byte writes */ + if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) + regaddr |= REG_ADDR_AI; return i2c_smbus_write_i2c_block_data(chip->client, regaddr, NBANK(chip), val); @@ -892,10 +889,7 @@ static int pca953x_probe(struct i2c_client *client, chip->write_regs = pca953x_write_regs_24; chip->read_regs = pca953x_read_regs_24; } else { - if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) - chip->write_regs = pca953x_write_regs_16; - else - chip->write_regs = pca957x_write_regs_16; + chip->write_regs = pca953x_write_regs_16; chip->read_regs = pca953x_read_regs_16; } From patchwork Wed Dec 12 01:39:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725441 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 756FA112E for ; Wed, 12 Dec 2018 01:40:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6515B2A7C3 for ; Wed, 12 Dec 2018 01:40:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 596632A7E2; Wed, 12 Dec 2018 01:40:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFA652A7C3 for ; Wed, 12 Dec 2018 01:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbeLLBkf (ORCPT ); Tue, 11 Dec 2018 20:40:35 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37545 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLLBkf (ORCPT ); Tue, 11 Dec 2018 20:40:35 -0500 Received: by mail-wr1-f66.google.com with SMTP id j10so16020035wru.4; Tue, 11 Dec 2018 17:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4PbaR0V9EmRCLg24iwUIkDoVUH0vr7nly0FBuvzjG1c=; b=mK0JEQheWToyJzvpWCDqOE33jXNa2J+6t9cHmt20sKAT1u/2r6oRz73d2Yno2fqBj3 3xO/oc2URQjUXpykk2CFuXuysF1BCOFhhHRaKUsNcZrWTiMTfEJ5Mt7up2j3eXU5q/sp R4E4fvGfQ3pKqukygZ5+q+WCZNd7RuLjNCEgG3bBdUHwK/Eg89sEKeDYJMaSHA6nU2LP fSpjl5qNO4p47vzcd6LebAXk2mEjpt4MeQjd1psp/AunbAJrS1eZCdTmQtJLDQconeGq necteSBoViUUe1sQk3gQhnCt176eqZcoiI1FxzJvmlztZMlaM64lEC2zrAeVrAGoAAW3 zDmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4PbaR0V9EmRCLg24iwUIkDoVUH0vr7nly0FBuvzjG1c=; b=cgtuYOnKnaDVHd26LkUlfg+IWz778FM3u6hYHcHtFKtRR2IsD4QaMgpurhUBG/A74y J6w4MePopftzpxJkdLDSighglWEaKX2qd1zNjsaKTeHyR+UBzLgSbV2rQsvbqwasNe6R wrjHJ0hpPVFuEyIHy8WHUj+xQLyiLGBC6je1SsSf8KbJND/I3kj1B7WdaglMmyHzEEyK OgvGH1UIEbMlxePtPNZGEwtbIAsN2BpHXmolu+cSNxblofIG6xUiPHOHYsUnf6A2zd3B avXPBKC59daA+iV/eqrxfvZAbVxRaahQZnH8Fac+L47hgft5yl75nl0T/N9IjLcMBPwD MXJw== X-Gm-Message-State: AA+aEWaaLaW2oTUdso6qQuSCoRw2AARf+32p8IPFdS8BYxvuIK30aboy 8Cf5A7ypUDnE3xOFN8uXLmJGnObI X-Google-Smtp-Source: AFSGD/VoXWXZdE25EcJu+sjiawARxCQQbcswlbQhHNCE/Xy2+e+bpZVGyWzzk7DSpDA2CI0zX1KhGQ== X-Received: by 2002:adf:ff09:: with SMTP id k9mr14756785wrr.97.1544578832896; Tue, 11 Dec 2018 17:40:32 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:31 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 05/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{16,24}() Date: Wed, 12 Dec 2018 02:39:53 +0100 Message-Id: <20181212014002.4753-5-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At this point, these two functions only differ in whether they do or do not set the address increment bit. The 16 GPIO case does not need to set the AI bit, except for PCA9575 on write, while the 24 GPIO and more case does set the AI bit always. Merge these two functions together to simplify the code a bit. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 49 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 7288a589a6b7..9b37dbbb63cb 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -206,9 +206,16 @@ static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val) return i2c_smbus_write_byte_data(chip->client, reg, *val); } -static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) +static int pca953x_write_regs_mul(struct pca953x_chip *chip, int reg, u8 *val) { - u32 regaddr = (reg << 1); + int bank_shift = pca953x_bank_shift(chip); + int addr = (reg & PCAL_GPIO_MASK) << bank_shift; + int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; + u8 regaddr = pinctrl | addr; + + /* Chips with 24 and more GPIOs always support Auto Increment */ + if (NBANK(chip) > 2) + regaddr |= REG_ADDR_AI; /* PCA9575 needs address-increment on multi-byte writes */ if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) @@ -218,17 +225,6 @@ static int pca953x_write_regs_16(struct pca953x_chip *chip, int reg, u8 *val) NBANK(chip), val); } -static int pca953x_write_regs_24(struct pca953x_chip *chip, int reg, u8 *val) -{ - int bank_shift = pca953x_bank_shift(chip); - int addr = (reg & PCAL_GPIO_MASK) << bank_shift; - int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; - - return i2c_smbus_write_i2c_block_data(chip->client, - pinctrl | addr | REG_ADDR_AI, - NBANK(chip), val); -} - static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) { int ret = 0; @@ -252,24 +248,18 @@ static int pca953x_read_regs_8(struct pca953x_chip *chip, int reg, u8 *val) return ret; } -static int pca953x_read_regs_16(struct pca953x_chip *chip, int reg, u8 *val) -{ - int ret; - - ret = i2c_smbus_read_word_data(chip->client, reg << 1); - put_unaligned(ret, (u16 *)val); - - return ret; -} - -static int pca953x_read_regs_24(struct pca953x_chip *chip, int reg, u8 *val) +static int pca953x_read_regs_mul(struct pca953x_chip *chip, int reg, u8 *val) { int bank_shift = pca953x_bank_shift(chip); int addr = (reg & PCAL_GPIO_MASK) << bank_shift; int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; + u8 regaddr = pinctrl | addr; + + /* Chips with 24 and more GPIOs always support Auto Increment */ + if (NBANK(chip) > 2) + regaddr |= REG_ADDR_AI; - return i2c_smbus_read_i2c_block_data(chip->client, - pinctrl | addr | REG_ADDR_AI, + return i2c_smbus_read_i2c_block_data(chip->client, regaddr, NBANK(chip), val); } @@ -885,12 +875,9 @@ static int pca953x_probe(struct i2c_client *client, if (chip->gpio_chip.ngpio <= 8) { chip->write_regs = pca953x_write_regs_8; chip->read_regs = pca953x_read_regs_8; - } else if (chip->gpio_chip.ngpio >= 24) { - chip->write_regs = pca953x_write_regs_24; - chip->read_regs = pca953x_read_regs_24; } else { - chip->write_regs = pca953x_write_regs_16; - chip->read_regs = pca953x_read_regs_16; + chip->write_regs = pca953x_write_regs_mul; + chip->read_regs = pca953x_read_regs_mul; } if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) From patchwork Wed Dec 12 01:39:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725443 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01293112E for ; Wed, 12 Dec 2018 01:40:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FFF2A7C3 for ; Wed, 12 Dec 2018 01:40:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA8CC2A7E2; Wed, 12 Dec 2018 01:40:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EBF52A7C3 for ; Wed, 12 Dec 2018 01:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbeLLBkh (ORCPT ); Tue, 11 Dec 2018 20:40:37 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46532 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeLLBkh (ORCPT ); Tue, 11 Dec 2018 20:40:37 -0500 Received: by mail-wr1-f65.google.com with SMTP id l9so15970663wrt.13; Tue, 11 Dec 2018 17:40:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iOl5Aj9f9bLTGhk6xSvzlIBjjGnlsrh8kgQMMvzCAZ0=; b=ZohIxevRAsWB+cehGMVywEY+17F9cHfYEjmuAkkSjm8rtC/cdq7vmFX6Kub1lFfPNC vBKHtp3lFhaJUuusxnA0iOsDzq8nUm7di5zzZH5cf9Iiq52D8JHHWY8CjRSaIdZPt+0U Nwm6BXauPwyjJIf442Q7eCNIJPN/yk5zG9IMK3tfvG4CH3WTnHF8gCSeRzZC4NFgbRDv XIoy7eLAChGhKESLS0KJpev5AufPXik5IXi8urNga5o+6voUp3OZv280i2rdRRMKQ6oB co25/kKohDir9VMdWzsUdYqJXa6JYVRgZFFP4af0NtixRd25ilbLIElbAJne57Qf+Y1E RmBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iOl5Aj9f9bLTGhk6xSvzlIBjjGnlsrh8kgQMMvzCAZ0=; b=NidpKghONhh0OmCd8CzdcDawvRPXEZ7FqIRzvwpH9FvIIaRwmF2FR6H4T5VkzTi3AV r3h56Sq7SKBazlLq/C6/xFuHoX65KDTdmdwk+b6MTMjkPEnY+RCMlbTF39SpJCK0yCAi vmiFIqBxdbiB8ja2fmBmeNtVVd7HXRJfvG7L2KK5CwHSjZTES6Gm1HA5rwX+HvLoazi2 XDmfr2r7buU3BpKERXZSXPRJQdxh6bLOD7dWd+pgE1Nde7kC0VY3MzR7hA5pA0nawlpj tuhz2HjLY7HKMHlMbhD9qBtDQGzZHaiGmvwNsK2mNvtfaMHu19KU7YyyqcOojGAqEH+F qtyA== X-Gm-Message-State: AA+aEWZGjmOa3qZr1gQMexX1hWjQ0hjhUmwFHUfkn0F3Mngivy3aCh/6 8Y2IW+n08Xd4Bgd6XVpPL+5V6BQw X-Google-Smtp-Source: AFSGD/UsJG5Z5FPt+vUciSlTolyg3sVE5vHyVA9MIsndkv1rxU+IQo3DqGu62EHoQ0K6wEz0E4kkbg== X-Received: by 2002:a5d:4c8a:: with SMTP id z10mr15024447wrs.75.1544578834224; Tue, 11 Dec 2018 17:40:34 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:33 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 06/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{8,mul}() Date: Wed, 12 Dec 2018 02:39:54 +0100 Message-Id: <20181212014002.4753-6-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP At this point, the pca953x_{read,write}_regs_mul() can read single bank PCA953x GPIO chips as well. Merge the _8 and _mul functions together to simplify the code a bit. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 54 ++++++------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 9b37dbbb63cb..626cbe040985 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -154,9 +154,6 @@ struct pca953x_chip { struct regulator *regulator; const struct pca953x_reg_config *regs; - - int (*write_regs)(struct pca953x_chip *, int, u8 *); - int (*read_regs)(struct pca953x_chip *, int, u8 *); }; static int pca953x_bank_shift(struct pca953x_chip *chip) @@ -201,17 +198,13 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, return 0; } -static int pca953x_write_regs_8(struct pca953x_chip *chip, int reg, u8 *val) -{ - return i2c_smbus_write_byte_data(chip->client, reg, *val); -} - -static int pca953x_write_regs_mul(struct pca953x_chip *chip, int reg, u8 *val) +static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) { int bank_shift = pca953x_bank_shift(chip); int addr = (reg & PCAL_GPIO_MASK) << bank_shift; int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; u8 regaddr = pinctrl | addr; + int ret; /* Chips with 24 and more GPIOs always support Auto Increment */ if (NBANK(chip) > 2) @@ -221,15 +214,8 @@ static int pca953x_write_regs_mul(struct pca953x_chip *chip, int reg, u8 *val) if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) regaddr |= REG_ADDR_AI; - return i2c_smbus_write_i2c_block_data(chip->client, regaddr, - NBANK(chip), val); -} - -static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) -{ - int ret = 0; - - ret = chip->write_regs(chip, reg, val); + ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr, + NBANK(chip), val); if (ret < 0) { dev_err(&chip->client->dev, "failed writing register\n"); return ret; @@ -238,36 +224,20 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) return 0; } -static int pca953x_read_regs_8(struct pca953x_chip *chip, int reg, u8 *val) -{ - int ret; - - ret = i2c_smbus_read_byte_data(chip->client, reg); - *val = ret; - - return ret; -} - -static int pca953x_read_regs_mul(struct pca953x_chip *chip, int reg, u8 *val) +static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) { int bank_shift = pca953x_bank_shift(chip); int addr = (reg & PCAL_GPIO_MASK) << bank_shift; int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; u8 regaddr = pinctrl | addr; + int ret; /* Chips with 24 and more GPIOs always support Auto Increment */ if (NBANK(chip) > 2) regaddr |= REG_ADDR_AI; - return i2c_smbus_read_i2c_block_data(chip->client, regaddr, - NBANK(chip), val); -} - -static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) -{ - int ret; - - ret = chip->read_regs(chip, reg, val); + ret = i2c_smbus_read_i2c_block_data(chip->client, regaddr, + NBANK(chip), val); if (ret < 0) { dev_err(&chip->client->dev, "failed reading register\n"); return ret; @@ -872,14 +842,6 @@ static int pca953x_probe(struct i2c_client *client, */ pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); - if (chip->gpio_chip.ngpio <= 8) { - chip->write_regs = pca953x_write_regs_8; - chip->read_regs = pca953x_read_regs_8; - } else { - chip->write_regs = pca953x_write_regs_mul; - chip->read_regs = pca953x_read_regs_mul; - } - if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) ret = device_pca953x_init(chip, invert); else From patchwork Wed Dec 12 01:39:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725445 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A03D159A for ; Wed, 12 Dec 2018 01:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDCB32A7C3 for ; Wed, 12 Dec 2018 01:40:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1E3E2A7E2; Wed, 12 Dec 2018 01:40:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F04D2A7C3 for ; Wed, 12 Dec 2018 01:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbeLLBki (ORCPT ); Tue, 11 Dec 2018 20:40:38 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44361 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbeLLBkh (ORCPT ); Tue, 11 Dec 2018 20:40:37 -0500 Received: by mail-wr1-f67.google.com with SMTP id z5so15994707wrt.11; Tue, 11 Dec 2018 17:40:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pEmhkbC3iLD7LabI4+PzzqzviIhBSZ0BSKCYclh2Dv8=; b=cqFjhVeQbROIBPfotC8KmJtQRWcAThvHbUrG+izXBJ2+aigD3YHTORc4JIhMZbx7ET qIkLlvB73gvA33NBCLExoqy0+TEw7Hd/YDycStBwmrEa8Kb1gjonBqHVJiR9hmpEWWWA AJO6bm5r+h0I3Ae+9mXokGLQGxVpHeHUx+GSiHxOyQk5EO5k57/ZIpW+3j5rCr2z6xq2 Co2Iz6yy1VYywEUxL8OLL4thnoTLTfID15UInva/8ZKgVCLxySZIMS9RvywHws57RRCG YJQBQuRMBkv0Xvey3XZ6+FDmwa2yQxoyPcTUBaaMHcfIKZ5r3KgBLsM6OYQjpxxv42fZ I9Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pEmhkbC3iLD7LabI4+PzzqzviIhBSZ0BSKCYclh2Dv8=; b=IalSDb+oiTrK9eHoMrv78Ng492P+f0u1fVtgb3PGgbjxRtJ6JnrpX9qZcr/QkhOu+o q2lXwYCYVsyd2c4mJ9uHnwdhll3iyoZbBfScTjvpYjrfG7hm00CeUcGqNf2n1fN5/lZe THRbjF3Ntq50/u0wawFJ50u4pqwNFmGYciindPgDpFr5mCIjTqfqUuL/RPgALMHiOG/i aR3PEXsTekOCbftWddcyt+O7lKNk0dsZT7iHkr+sVhP+mRXVtezb1XI/zdqK4F7LVHR1 junVfy4rZcqqbbyvzLwetLZbPcuHal4vxFua4powyXG0VwgEwwShxIahdyPgP+FOl/fa eh1g== X-Gm-Message-State: AA+aEWanzL8xbVGAk1IEA0GJ/J7Jvmcskz4MYlJmRycvsEw8S0yyNj1k z9FxQni+RHRg1vTJAVZoIB3gCbCP X-Google-Smtp-Source: AFSGD/UJMCVUj5e1LRFQYAf8MRIxvRDopGdtFtMDMsDvA2r7Nh18IMAH/UJ96cop7GaN8Lro9FvdPQ== X-Received: by 2002:adf:e78f:: with SMTP id n15mr16009294wrm.115.1544578835599; Tue, 11 Dec 2018 17:40:35 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:34 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 07/14] gpio: pca953x: Factor out common code from device_pca95xx_init() Date: Wed, 12 Dec 2018 02:39:55 +0100 Message-Id: <20181212014002.4753-7-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The PCA957x and PCA953x init functions are almost the same, except for the different register mapping and one extra write to BKEN register in case of PCA957x. Factor out the common code. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 626cbe040985..d4b8946ea710 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -119,18 +119,21 @@ struct pca953x_reg_config { int direction; int output; int input; + int invert; }; static const struct pca953x_reg_config pca953x_regs = { .direction = PCA953X_DIRECTION, .output = PCA953X_OUTPUT, .input = PCA953X_INPUT, + .invert = PCA953X_INVERT, }; static const struct pca953x_reg_config pca957x_regs = { .direction = PCA957X_CFG, .output = PCA957X_OUT, .input = PCA957X_IN, + .invert = PCA957X_INVRT, }; struct pca953x_chip { @@ -679,13 +682,11 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, } #endif -static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) +static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) { int ret; u8 val[MAX_BANK]; - chip->regs = &pca953x_regs; - ret = pca953x_read_regs(chip, chip->regs->output, chip->reg_output); if (ret) goto out; @@ -701,7 +702,7 @@ static int device_pca953x_init(struct pca953x_chip *chip, u32 invert) else memset(val, 0, NBANK(chip)); - ret = pca953x_write_regs(chip, PCA953X_INVERT, val); + ret = pca953x_write_regs(chip, chip->regs->invert, val); out: return ret; } @@ -711,22 +712,7 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert) int ret; u8 val[MAX_BANK]; - chip->regs = &pca957x_regs; - - ret = pca953x_read_regs(chip, chip->regs->output, chip->reg_output); - if (ret) - goto out; - ret = pca953x_read_regs(chip, chip->regs->direction, - chip->reg_direction); - if (ret) - goto out; - - /* set platform specific polarity inversion */ - if (invert) - memset(val, 0xFF, NBANK(chip)); - else - memset(val, 0, NBANK(chip)); - ret = pca953x_write_regs(chip, PCA957X_INVRT, val); + ret = device_pca95xx_init(chip, invert); if (ret) goto out; @@ -842,10 +828,13 @@ static int pca953x_probe(struct i2c_client *client, */ pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); - if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) - ret = device_pca953x_init(chip, invert); - else + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { + chip->regs = &pca953x_regs; + ret = device_pca95xx_init(chip, invert); + } else { + chip->regs = &pca957x_regs; ret = device_pca957x_init(chip, invert); + } if (ret) goto err_exit; From patchwork Wed Dec 12 01:39:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725447 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B7F7159A for ; Wed, 12 Dec 2018 01:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CA8E2A7C3 for ; Wed, 12 Dec 2018 01:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40FF02A7E2; Wed, 12 Dec 2018 01:40:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94192A7C3 for ; Wed, 12 Dec 2018 01:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726242AbeLLBkj (ORCPT ); Tue, 11 Dec 2018 20:40:39 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46537 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeLLBkj (ORCPT ); Tue, 11 Dec 2018 20:40:39 -0500 Received: by mail-wr1-f68.google.com with SMTP id l9so15970720wrt.13; Tue, 11 Dec 2018 17:40:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qQls99DGa2P09dzhm2GX4qgbvkumagW/IWb4YMXEQx8=; b=Wekuk2+l4jrAfgZ4J5Bp83hPuY9MXavtxE5wZ0S9CIwzn+TSwENV1qfzu/hR7kPeof pnIZ3oN2YEIHtG1vkmU0PLoqzhSlB+50jJYquJdtFLF7pO05U7YPQeAb2FhyURxLMI51 +X9op0ZSAV2rCLAht0pen2ZV2yk6HwC0f2AkL8ek8XmxqYloGjwohSPV+L3O+rAdJdbo trga0bBddjN9pW5A52akiyJ4LhtRGwpoST+yuGiN4+bGCzeni9s4+ov6T5ns4wF1UUoR A59DeROraEZPyoIGKFqsIWE+kVXIJrWJ+/b2gTunUhZ8VfiQL4oZGpYk+3Z4dETmEJpj gQog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qQls99DGa2P09dzhm2GX4qgbvkumagW/IWb4YMXEQx8=; b=NUD2xnrBkFpu1dNPu9oDwfBVy3t3UZXG0/KK51wHv2LdJoacFBZ/4hKQqefm7uRD/N RNooONp+8nW+tKpt+zqRbW/WUr69dMi/98jZwyprCRqdz9Zyr2jccuPzk493K/CokVhZ zsUAIHHgV/cdScrsxJfKvPjDEB8d3aGeyQb1797sR0VsRmu2ccmkTBOIK+2RRfvMGTpH LQgXBHDmy5BlnkydaeZa7dA+BItdzHOPlztLR7OLUOXcGdjGbGpwZmEJDmZVw+7eGO0R 22+p4j5qo9YzH902rSGMSNkcckMK/mRG7gBaFMXf8tTiHZraHnRKcYsXWiEflT3fMTKi KpNQ== X-Gm-Message-State: AA+aEWYis5pp2h8wWiGUCvB2X/8IUPpPRQheCmykhM7W9t8pUHvQBgFU hubW1En20c6HAplD9XiVuvUNOgn0 X-Google-Smtp-Source: AFSGD/WH7TjweDqtSemuGHrQlbHBxnJHdOeKu1B1wI6M5GbYrip1Zs9bsnc36G1Kk4d7tLku0aETVg== X-Received: by 2002:adf:a78a:: with SMTP id j10mr15841849wrc.191.1544578837146; Tue, 11 Dec 2018 17:40:37 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:35 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 08/14] gpio: pca953x: Zap ad-hoc I2C block write in multi GPIO set Date: Wed, 12 Dec 2018 02:39:56 +0100 Message-Id: <20181212014002.4753-8-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ad-hoc i2c block write can be replaced by standard register accessor function, which correctly handles all the chip details and differences. Do so to simplify the code. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index d4b8946ea710..cbc3b82b9385 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -364,8 +364,6 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { struct pca953x_chip *chip = gpiochip_get_data(gc); - int bank_shift = pca953x_bank_shift(chip); - u32 regaddr = chip->regs->output << bank_shift; unsigned int bank_mask, bank_val; int bank; u8 reg_val[MAX_BANK]; @@ -384,14 +382,7 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, } } - /* PCA9575 needs address-increment on multi-byte writes */ - if ((PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) && - (NBANK(chip) > 1)) { - regaddr |= REG_ADDR_AI; - } - - ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr, - NBANK(chip), reg_val); + ret = pca953x_write_regs(chip, chip->regs->output, reg_val); if (ret) goto exit; From patchwork Wed Dec 12 01:39:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725449 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82DA0112E for ; Wed, 12 Dec 2018 01:40:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73E3D2A7E3 for ; Wed, 12 Dec 2018 01:40:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 682A02A80D; Wed, 12 Dec 2018 01:40:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9F3B2A7C3 for ; Wed, 12 Dec 2018 01:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726324AbeLLBkl (ORCPT ); Tue, 11 Dec 2018 20:40:41 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44362 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726272AbeLLBkl (ORCPT ); Tue, 11 Dec 2018 20:40:41 -0500 Received: by mail-wr1-f65.google.com with SMTP id z5so15994766wrt.11; Tue, 11 Dec 2018 17:40:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DpWZb5WRsY4Q4jAkVb7pINizqUtxsA/DsJDqWLhxDcY=; b=llJRcM8Ej3271+MVzjMfMED57goFGaW243Ea8FM3aVbBlVz2QDpx2/7g9zQdqqjkhg 1KqHbml6VdTEvaC0tJjBqSxrT+OD+mvbU40c+bKJmcNlitg1JwHliVUtKmnAnbOUU+bq t2lXb/L8PPhiKLDkrHeq2TdNueQPoFMSx8h+CpE6ZPVJInnOaKcGi/xzVeiLJp6NfRk+ SO8Pax52oj5oNgW6ZUpZxn9bJCsLcmFcabAnKa9twaPx+n75Ut5sAHAkxYkR4Aisf/tg J93d3n5bMWvevWN8pt8Riqqfn93QQN1H0bYsuA+T+TBSxhSsYVrC7q+JF4MfAK7r6wEU foFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DpWZb5WRsY4Q4jAkVb7pINizqUtxsA/DsJDqWLhxDcY=; b=HJd5/tsoZtAX1iTlOCublSlq/vmMzJe4A1WxNZGLgboG21A9wOGgTZq9q7RVAwNDgI bG2H2WE651Q9EcZ/k6GMt3v35TKPeYMy8XxhdZrbtDOyndRfuh0mGinwzXi4IGh92yBY z0EDekXm+2oCbUGux87CwMHyxGBaRvqoQ6MSK0g7A12EgW0pUrpyuFuW1uMhWPq3oUsw sKh/GH2cTyUZbXYyV6+N87If36P2c+1DzbceaF4fkixQeYC9MTtFzaYid3IrtXV3UGef /uTgfVMw5Q5iL5Bq40SXqL3C3jpF+xxsdYuYOO827IG7q/DYd1gRS10iOsA3ekybhTLE TTsw== X-Gm-Message-State: AA+aEWaeVel0vSXnb1mk7yjCNlLtS57ati6WZ8u7aZsvwfulzuNlbdGH oHY+v7xqeTFXdr/ih11TDs2E6Kqd X-Google-Smtp-Source: AFSGD/XYsZo4cEJC6b4pTn5XPAoZtg4wPY06flrZ/Yuwoyo4ytsp2DX5e743o8U2BR+PLGxQ7SGknw== X-Received: by 2002:a5d:4b42:: with SMTP id w2mr15643119wrs.156.1544578838660; Tue, 11 Dec 2018 17:40:38 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:37 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 09/14] gpio: pca953x: Extract the register address mangling to single function Date: Wed, 12 Dec 2018 02:39:57 +0100 Message-Id: <20181212014002.4753-9-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of having the I2C register calculation function spread across multiple accessor functions, pull it out into a single function which returns the adjusted register address. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 59 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index cbc3b82b9385..b08e071ad48c 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -164,17 +164,37 @@ static int pca953x_bank_shift(struct pca953x_chip *chip) return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); } +static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off, + bool write, bool addrinc) +{ + int bank_shift = pca953x_bank_shift(chip); + int addr = (reg & PCAL_GPIO_MASK) << bank_shift; + int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; + u8 regaddr = pinctrl | addr | (off / BANK_SZ); + + /* Single byte read doesn't need AI bit set. */ + if (!addrinc) + return regaddr; + + /* Chips with 24 and more GPIOs always support Auto Increment */ + if (write && NBANK(chip) > 2) + regaddr |= REG_ADDR_AI; + + /* PCA9575 needs address-increment on multi-byte writes */ + if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) + regaddr |= REG_ADDR_AI; + + return regaddr; +} + static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, int off) { + u8 regaddr = pca953x_recalc_addr(chip, reg, off, false, false); int ret; - int bank_shift = pca953x_bank_shift(chip); - int offset = off / BANK_SZ; - ret = i2c_smbus_read_byte_data(chip->client, - (reg << bank_shift) + offset); + ret = i2c_smbus_read_byte_data(chip->client, regaddr); *val = ret; - if (ret < 0) { dev_err(&chip->client->dev, "failed reading register\n"); return ret; @@ -186,13 +206,10 @@ static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, int off) { + u8 regaddr = pca953x_recalc_addr(chip, reg, off, true, false); int ret; - int bank_shift = pca953x_bank_shift(chip); - int offset = off / BANK_SZ; - - ret = i2c_smbus_write_byte_data(chip->client, - (reg << bank_shift) + offset, val); + ret = i2c_smbus_write_byte_data(chip->client, regaddr, val); if (ret < 0) { dev_err(&chip->client->dev, "failed writing register\n"); return ret; @@ -203,20 +220,9 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) { - int bank_shift = pca953x_bank_shift(chip); - int addr = (reg & PCAL_GPIO_MASK) << bank_shift; - int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; - u8 regaddr = pinctrl | addr; + u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); int ret; - /* Chips with 24 and more GPIOs always support Auto Increment */ - if (NBANK(chip) > 2) - regaddr |= REG_ADDR_AI; - - /* PCA9575 needs address-increment on multi-byte writes */ - if (PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) - regaddr |= REG_ADDR_AI; - ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr, NBANK(chip), val); if (ret < 0) { @@ -229,16 +235,9 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) { - int bank_shift = pca953x_bank_shift(chip); - int addr = (reg & PCAL_GPIO_MASK) << bank_shift; - int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; - u8 regaddr = pinctrl | addr; + u8 regaddr = pca953x_recalc_addr(chip, reg, 0, false, true); int ret; - /* Chips with 24 and more GPIOs always support Auto Increment */ - if (NBANK(chip) > 2) - regaddr |= REG_ADDR_AI; - ret = i2c_smbus_read_i2c_block_data(chip->client, regaddr, NBANK(chip), val); if (ret < 0) { From patchwork Wed Dec 12 01:39:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725451 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BB93159A for ; Wed, 12 Dec 2018 01:40:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF7462A7C3 for ; Wed, 12 Dec 2018 01:40:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB9DD2A7C9; Wed, 12 Dec 2018 01:40:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35D1E2A80D for ; Wed, 12 Dec 2018 01:40:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726272AbeLLBkn (ORCPT ); Tue, 11 Dec 2018 20:40:43 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33337 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeLLBkm (ORCPT ); Tue, 11 Dec 2018 20:40:42 -0500 Received: by mail-wr1-f68.google.com with SMTP id c14so16064203wrr.0; Tue, 11 Dec 2018 17:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wV3VPs7htZve5ZzShSwNEmSJrFJ2PTmLnUp+SPpIHrE=; b=Hizu0FR5lxe80RKdfeu9nL5VhirOR+kC+Tca9XUvgmlF9d4Igvt64BfrN1vl8STi8a kU7yBRsBnpQl5biZ8CioJWSr3qFgIpMC2MzNOaaq1uBrR5xGiMuPP8R+fYxk7ePJtVg8 OAKqvFGgoKyFBffuMs7RrA2AkjyTAPE+3AdapILBLgnQ3IE0MnzVr8EnsFOCXwQky9Az DRmvhKu/JeTRe5nReDRr15ww4fm3xW1oTnghefkU51ZTrdou0Le8fOYGAeepFQFUsoQx wPg7ue4KJW4c0iINx9JfpLpDQdjp2FH9ttKe4b2ISAVf6Q4obV+O22f1AiDgEaDWAwJH oiew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wV3VPs7htZve5ZzShSwNEmSJrFJ2PTmLnUp+SPpIHrE=; b=Yb8vpt7oP5zB9o1uOqwG3kp0++3q05zENi/HKs8KREEgCvfUCVg31RrEdA6y40zvS9 YQPFKsjWe1E1rjwUNEPlxAv7JUXCA6yguT5Y4xL2lQGzIhBjuLs+2KVM0r6OpT/0FRE4 b7HnVQKK9kwA4rR9Rf0M+yww6wo9nmAOpao4dD/gFHFRsnoeV+7ecXD4ili8HAQTAFDA fk6t1RCHWa+Ar6OG+JSLtmgcfAY6De4ZpvXAFoyq9Vbwv5q6G91WZBeNDF5YPc53H2Pi s9d8IyJRR3HaJyYZETtd9UeJAXLy3SBYhaPoPGu0g97TB0CZwb41/NgZiPbYy6ZY7n0w oSzw== X-Gm-Message-State: AA+aEWb8M2SpBm0LjTgbRzCXtdav50T0ioZ+OnD3cO4MkoQ0ZAQ4WZF8 pgTB6LphkM/+PQdcZuKDwrtVygFq X-Google-Smtp-Source: AFSGD/U435cV9+urR1oBY3Ep4w85eRPJj2ps9KKMjJwYCbxV93fHm4NcdLjQi37S5ZHaLfsHhabb9w== X-Received: by 2002:adf:9323:: with SMTP id 32mr15265078wro.213.1544578840072; Tue, 11 Dec 2018 17:40:40 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:39 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 10/14] gpio: pca953x: Perform basic regmap conversion Date: Wed, 12 Dec 2018 02:39:58 +0100 Message-Id: <20181212014002.4753-10-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the driver to use regmap to access the chips. Due to the convoluted register mapping scheme, implement read/write/volatile check functions that untangle the mess and perform check accordingly. This patch does not zap the internal register cache of the PCA953x driver, nor does it push the regmap access down into the gpiochip accessors to simplify the review. All that is in subsequent patches. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 159 ++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index b08e071ad48c..3b845b16031e 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,8 @@ #define PCA953X_INVERT 0x02 #define PCA953X_DIRECTION 0x03 +#define REG_ADDR_MASK 0x3f +#define REG_ADDR_EXT 0x40 #define REG_ADDR_AI 0x80 #define PCA957X_IN 0x00 @@ -141,6 +144,7 @@ struct pca953x_chip { u8 reg_output[MAX_BANK]; u8 reg_direction[MAX_BANK]; struct mutex i2c_lock; + struct regmap *regmap; #ifdef CONFIG_GPIO_PCA953X_IRQ struct mutex irq_lock; @@ -164,6 +168,141 @@ static int pca953x_bank_shift(struct pca953x_chip *chip) return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); } +#define PCA953x_BANK_INPUT BIT(0) +#define PCA953x_BANK_OUTPUT BIT(1) +#define PCA953x_BANK_POLARITY BIT(2) +#define PCA953x_BANK_CONFIG BIT(3) + +#define PCA957x_BANK_INPUT BIT(0) +#define PCA957x_BANK_POLARITY BIT(1) +#define PCA957x_BANK_BUSHOLD BIT(2) +#define PCA957x_BANK_CONFIG BIT(4) +#define PCA957x_BANK_OUTPUT BIT(5) + +#define PCAL9xxx_BANK_IN_LATCH BIT(8 + 2) +#define PCAL9xxx_BANK_IRQ_MASK BIT(8 + 5) +#define PCAL9xxx_BANK_IRQ_STAT BIT(8 + 6) + +/* + * We care about the following registers: + * - Standard set, below 0x40, each port can be replicated up to 8 times + * - PCA953x standard + * Input port 0x00 + 0 * bank_size R + * Output port 0x00 + 1 * bank_size RW + * Polarity Inversion port 0x00 + 2 * bank_size RW + * Configuration port 0x00 + 3 * bank_size RW + * - PCA957x with mixed up registers + * Input port 0x00 + 0 * bank_size R + * Polarity Inversion port 0x00 + 1 * bank_size RW + * Bus hold port 0x00 + 2 * bank_size RW + * Configuration port 0x00 + 4 * bank_size RW + * Output port 0x00 + 5 * bank_size RW + * + * - Extended set, above 0x40, often chip specific. + * - PCAL6524/PCAL9555A with custom PCAL IRQ handling: + * Input latch register 0x40 + 2 * bank_size RW + * Interrupt mask register 0x40 + 5 * bank_size RW + * Interrupt status register 0x40 + 6 * bank_size R + * + * - Registers with bit 0x80 set, the AI bit + * The bit is cleared and the registers fall into one of the + * categories above. + */ + +static bool pca953x_check_register(struct pca953x_chip *chip, unsigned int reg, + u32 checkbank) +{ + int bank_shift = pca953x_bank_shift(chip); + int bank = (reg & REG_ADDR_MASK) >> bank_shift; + int offset = reg & (BIT(bank_shift) - 1); + + /* Special PCAL extended register check. */ + if (reg & REG_ADDR_EXT) { + if (!(chip->driver_data & PCA_PCAL)) + return false; + bank += 8; + } + + /* Register is not in the matching bank. */ + if (!(BIT(bank) & checkbank)) + return false; + + /* Register is not within allowed range of bank. */ + if (offset >= NBANK(chip)) + return false; + + return true; +} + +static bool pca953x_readable_register(struct device *dev, unsigned int reg) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + u32 bank; + + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { + bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | + PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; + } else { + bank = PCA957x_BANK_INPUT | PCA957x_BANK_OUTPUT | + PCA957x_BANK_POLARITY | PCA957x_BANK_CONFIG | + PCA957x_BANK_BUSHOLD; + } + + if (chip->driver_data & PCA_PCAL) { + bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK | + PCAL9xxx_BANK_IRQ_STAT; + } + + return pca953x_check_register(chip, reg, bank); +} + +static bool pca953x_writeable_register(struct device *dev, unsigned int reg) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + u32 bank; + + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { + bank = PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | + PCA953x_BANK_CONFIG; + } else { + bank = PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | + PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; + } + + if (chip->driver_data & PCA_PCAL) + bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK; + + return pca953x_check_register(chip, reg, bank); +} + +static bool pca953x_volatile_register(struct device *dev, unsigned int reg) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + u32 bank; + + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) + bank = PCA953x_BANK_INPUT; + else + bank = PCA957x_BANK_INPUT; + + if (chip->driver_data & PCA_PCAL) + bank |= PCAL9xxx_BANK_IRQ_STAT; + + return pca953x_check_register(chip, reg, bank); +} + +const struct regmap_config pca953x_i2c_regmap = { + .reg_bits = 8, + .val_bits = 8, + + .readable_reg = pca953x_readable_register, + .writeable_reg = pca953x_writeable_register, + .volatile_reg = pca953x_volatile_register, + + .cache_type = REGCACHE_RBTREE, + .max_register = 0x7f, +}; + static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off, bool write, bool addrinc) { @@ -193,8 +332,7 @@ static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, u8 regaddr = pca953x_recalc_addr(chip, reg, off, false, false); int ret; - ret = i2c_smbus_read_byte_data(chip->client, regaddr); - *val = ret; + ret = regmap_read(chip->regmap, regaddr, val); if (ret < 0) { dev_err(&chip->client->dev, "failed reading register\n"); return ret; @@ -209,7 +347,7 @@ static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, u8 regaddr = pca953x_recalc_addr(chip, reg, off, true, false); int ret; - ret = i2c_smbus_write_byte_data(chip->client, regaddr, val); + ret = regmap_write(chip->regmap, regaddr, val); if (ret < 0) { dev_err(&chip->client->dev, "failed writing register\n"); return ret; @@ -223,8 +361,7 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); int ret; - ret = i2c_smbus_write_i2c_block_data(chip->client, regaddr, - NBANK(chip), val); + ret = regmap_bulk_write(chip->regmap, regaddr, val, NBANK(chip)); if (ret < 0) { dev_err(&chip->client->dev, "failed writing register\n"); return ret; @@ -238,8 +375,7 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) u8 regaddr = pca953x_recalc_addr(chip, reg, 0, false, true); int ret; - ret = i2c_smbus_read_i2c_block_data(chip->client, regaddr, - NBANK(chip), val); + ret = regmap_bulk_read(chip->regmap, regaddr, val, NBANK(chip)); if (ret < 0) { dev_err(&chip->client->dev, "failed reading register\n"); return ret; @@ -793,6 +929,14 @@ static int pca953x_probe(struct i2c_client *client, } } + i2c_set_clientdata(client, chip); + + chip->regmap = devm_regmap_init_i2c(client, &pca953x_i2c_regmap); + if (IS_ERR(chip->regmap)) { + ret = PTR_ERR(chip->regmap); + goto err_exit; + } + mutex_init(&chip->i2c_lock); /* * In case we have an i2c-mux controlled by a GPIO provided by an @@ -843,7 +987,6 @@ static int pca953x_probe(struct i2c_client *client, dev_warn(&client->dev, "setup failed, %d\n", ret); } - i2c_set_clientdata(client, chip); return 0; err_exit: From patchwork Wed Dec 12 01:39:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725453 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E492112E for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EAE12A7C3 for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02B8C2A7E2; Wed, 12 Dec 2018 01:40:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C1AC2A7C3 for ; Wed, 12 Dec 2018 01:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbeLLBkp (ORCPT ); Tue, 11 Dec 2018 20:40:45 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41853 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726305AbeLLBkp (ORCPT ); Tue, 11 Dec 2018 20:40:45 -0500 Received: by mail-wr1-f66.google.com with SMTP id x10so15995636wrs.8; Tue, 11 Dec 2018 17:40:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bgfwqcrv6eNII/YZ+7Ip9skuBgPeoZ8jM1yk/YrNOks=; b=h/CxTCSs0eYkdr7LqR76hqvfsjstVl9OKvwtVUM2n5GSHphJc4Mrnwk/YMUPXa7qSV UzTcHeIFumMzqhgohRdQQqIovLZ8S18dnuqXb/ZzdMRo+eYpDfyyiBQJMrH+zQqejeGn ySv8cN1LZxQuiJn5WrdXGtME9EARcVvs1tDqWxIBcWIg3/23444//cujMyyDokiB7gwZ HamzhcwyDQJBqM4WDklWRjIK+z+RGWk+mOMPBEjLJnrG7uyUhE6N4bW5Ku5pepNGV6qD Km//cqRAJMT7rNOIS0IrshNzUcqgi6gmv+xaCDyUKdvyETqzTCVtLQDoPJDfE+nJld6h 5uWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bgfwqcrv6eNII/YZ+7Ip9skuBgPeoZ8jM1yk/YrNOks=; b=L7BWqn1N5FQ1OHkHPPbUtAObAsmzL8Qaw3gizbAAyPkYIMEiKmCRXKSJr41hP5mpSt VU/5qxv19Ae/f2j0OrePBfmjRiwGEQ7jzy/eWAZHTeR9O+6VKtEKUXmlfUHgiKGlyRn9 xWJOIqIdY6RPrCTVjbpdvN7QAS9iC6DFdrCkf/IR/2/4+3rrg7qJPIfhl3F6H/N3hlG1 DqRzJj0dc1nHFHc+R0ZJt3gy3kVy+cyzkRS3xmYnA8lMpsKY+D6jKloZ3o4BspZ/i5Dx vDjxJKaJzTTDOTEUcwSKDXIRyKv0G1gl0hKZc/U6fU0n/9cUizOf5IIrbaxWyQxwcQmL vrsA== X-Gm-Message-State: AA+aEWbu1jR04PCKL1GuSsZNerHpf0t2v/JmlZY+S3SK5S7+klV55Q0e LtWzAfJzPYbcl/tk0+zmBnkQAylZ X-Google-Smtp-Source: AFSGD/VQ5BCzmnRTjdlI9jKITJOtwD/3/ZCztx/DnKhTouGoBUqdzsEqadAMd4YAVD5UUQPY2tYEDw== X-Received: by 2002:adf:d0c9:: with SMTP id z9mr14938434wrh.317.1544578841427; Tue, 11 Dec 2018 17:40:41 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:40 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 11/14] gpio: pca953x: Zap ad-hoc reg_direction cache Date: Wed, 12 Dec 2018 02:39:59 +0100 Message-Id: <20181212014002.4753-11-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the ad-hoc reg_direction direction register caching with generic regcache cache. This reduces code duplication. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- V2: Fix the IRQ handling code as well --- drivers/gpio/gpio-pca953x.c | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 3b845b16031e..08fd7c17fcb6 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -142,7 +142,6 @@ static const struct pca953x_reg_config pca957x_regs = { struct pca953x_chip { unsigned gpio_start; u8 reg_output[MAX_BANK]; - u8 reg_direction[MAX_BANK]; struct mutex i2c_lock; struct regmap *regmap; @@ -387,18 +386,13 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val) static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) { struct pca953x_chip *chip = gpiochip_get_data(gc); - u8 reg_val; + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, + true, false); + u8 bit = BIT(off % BANK_SZ); int ret; mutex_lock(&chip->i2c_lock); - reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ)); - - ret = pca953x_write_single(chip, chip->regs->direction, reg_val, off); - if (ret) - goto exit; - - chip->reg_direction[off / BANK_SZ] = reg_val; -exit: + ret = regmap_write_bits(chip->regmap, dirreg, bit, bit); mutex_unlock(&chip->i2c_lock); return ret; } @@ -407,6 +401,9 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, unsigned off, int val) { struct pca953x_chip *chip = gpiochip_get_data(gc); + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, + true, false); + u8 bit = BIT(off % BANK_SZ); u8 reg_val; int ret; @@ -426,12 +423,7 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, chip->reg_output[off / BANK_SZ] = reg_val; /* then direction */ - reg_val = chip->reg_direction[off / BANK_SZ] & ~(1u << (off % BANK_SZ)); - ret = pca953x_write_single(chip, chip->regs->direction, reg_val, off); - if (ret) - goto exit; - - chip->reg_direction[off / BANK_SZ] = reg_val; + ret = regmap_write_bits(chip->regmap, dirreg, bit, 0); exit: mutex_unlock(&chip->i2c_lock); return ret; @@ -483,16 +475,19 @@ static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) { struct pca953x_chip *chip = gpiochip_get_data(gc); + u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, + true, false); + u8 bit = BIT(off % BANK_SZ); u32 reg_val; int ret; mutex_lock(&chip->i2c_lock); - ret = pca953x_read_single(chip, chip->regs->direction, ®_val, off); + ret = regmap_read(chip->regmap, dirreg, ®_val); mutex_unlock(&chip->i2c_lock); if (ret < 0) return ret; - return !!(reg_val & (1u << (off % BANK_SZ))); + return !!(reg_val & bit); } static void pca953x_gpio_set_multiple(struct gpio_chip *gc, @@ -580,6 +575,10 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) u8 new_irqs; int level, i; u8 invert_irq_mask[MAX_BANK]; + int reg_direction[MAX_BANK]; + + regmap_bulk_read(chip->regmap, chip->regs->direction, reg_direction, + NBANK(chip)); if (chip->driver_data & PCA_PCAL) { /* Enable latch on interrupt-enabled inputs */ @@ -595,7 +594,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) /* Look for any newly setup interrupt */ for (i = 0; i < NBANK(chip); i++) { new_irqs = chip->irq_trig_fall[i] | chip->irq_trig_raise[i]; - new_irqs &= ~chip->reg_direction[i]; + new_irqs &= reg_direction[i]; while (new_irqs) { level = __ffs(new_irqs); @@ -660,6 +659,7 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending) bool pending_seen = false; bool trigger_seen = false; u8 trigger[MAX_BANK]; + int reg_direction[MAX_BANK]; int ret, i; if (chip->driver_data & PCA_PCAL) { @@ -690,8 +690,10 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending) return false; /* Remove output pins from the equation */ + regmap_bulk_read(chip->regmap, chip->regs->direction, reg_direction, + NBANK(chip)); for (i = 0; i < NBANK(chip); i++) - cur_stat[i] &= chip->reg_direction[i]; + cur_stat[i] &= reg_direction[i]; memcpy(old_stat, chip->irq_stat, NBANK(chip)); @@ -745,6 +747,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base) { struct i2c_client *client = chip->client; + int reg_direction[MAX_BANK]; int ret, i; if (client->irq && irq_base != -1 @@ -759,8 +762,10 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, * interrupt. We have to rely on the previous read for * this purpose. */ + regmap_bulk_read(chip->regmap, chip->regs->direction, + reg_direction, NBANK(chip)); for (i = 0; i < NBANK(chip); i++) - chip->irq_stat[i] &= chip->reg_direction[i]; + chip->irq_stat[i] &= reg_direction[i]; mutex_init(&chip->irq_lock); ret = devm_request_threaded_irq(&client->dev, @@ -817,9 +822,9 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) if (ret) goto out; - ret = pca953x_read_regs(chip, chip->regs->direction, - chip->reg_direction); - if (ret) + ret = regcache_sync_region(chip->regmap, chip->regs->direction, + chip->regs->direction + NBANK(chip)); + if (ret != 0) goto out; /* set platform specific polarity inversion */ @@ -937,6 +942,8 @@ static int pca953x_probe(struct i2c_client *client, goto err_exit; } + regcache_mark_dirty(chip->regmap); + mutex_init(&chip->i2c_lock); /* * In case we have an i2c-mux controlled by a GPIO provided by an From patchwork Wed Dec 12 01:40:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725455 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB644112E for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC5F22A7C3 for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0F1D2A7E2; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 535462A7C3 for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726339AbeLLBkq (ORCPT ); Tue, 11 Dec 2018 20:40:46 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37553 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726331AbeLLBkp (ORCPT ); Tue, 11 Dec 2018 20:40:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id j10so16020235wru.4; Tue, 11 Dec 2018 17:40:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RPSboOIXYSs3EZ+UCpdc91XX1RSm52w01logS8Oqatc=; b=Kfm1TMmKa8z+VK3KcWFfDdOjzVxfZxiMW0Nd0vpxwNqPVosjhK2nURdQ+GBfkkY9Lm Iwb5appBR9lpmhX63zcQpxPu6Poil417xwuydGj5BVdTDzxk/CCUjMKsgQopffd7tc9s 2qhrUjMigh1X/QLt+5/A/+vURdp9z69c2EkC0Gd4j39Pf4FGk2AHHkRQ2YHMUSP5c+YD FGU7xIgdE/E/pQdB9m9YpMpEhjuU2EPd+em4e3EUq/xZ+14Hfhs0anXm7vuWV/frcpq6 dM8PasbXQrgypxHz3WKRugB4Qq1I76f+V9o5vQpKuv3DjUl3EnSZQ9krUKp6puNfGfd4 SM5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RPSboOIXYSs3EZ+UCpdc91XX1RSm52w01logS8Oqatc=; b=WwvFIsHw5xxhH1NEPJRRAKYWdFmDrRJieIkpE9WN3k1xjoRPSK8q9wn1EOr0gun1I0 6dedq7T3693hnsZiap+7m8yvmKGkRkS6Gb3kCzBoSHjMKbmPj4JmXhCh4QGMvWXM2PUg r2qFveumQWm9g319nmqywqeWin0aOj1oKQb18PARobGoXFGRi/fxpJTvXUv5/Nf3PIR8 R9Th4WLQ5qHcaACL2O+bUvtdZqnX+SEI/8Hmg3SfKtf75bxbHnPwtBDRSq/DoCaLQLrr tiE30XjCrAKAmMS+SSn+KJ+q6BG/5Ic21Ow7gehV0a0lok0+zdiVTCIRVPNMAJuYHc7F TUiQ== X-Gm-Message-State: AA+aEWaGZKYr3kSuj5XPVmlrH2PTvOPXBOgTtS/uH2dtE+auB611sl2F 6WZjLUzhL/P3kcvDpRHnPWGJtc43 X-Google-Smtp-Source: AFSGD/VJI/VO7MYv9ACFmi6MA8rdRbDEnSWSixsMCNsn2JpgQbttpehFbyHrgxbDBOy21hggFosAJQ== X-Received: by 2002:adf:f4c2:: with SMTP id h2mr15050919wrp.21.1544578842831; Tue, 11 Dec 2018 17:40:42 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:41 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 12/14] gpio: pca953x: Zap ad-hoc reg_output cache Date: Wed, 12 Dec 2018 02:40:00 +0100 Message-Id: <20181212014002.4753-12-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the ad-hoc reg_output output register caching with generic regcache cache. Drop pca953x_write_single() which is no longer used. This reduces code duplication. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 65 +++++++++---------------------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 08fd7c17fcb6..a349f68c4025 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -141,7 +141,6 @@ static const struct pca953x_reg_config pca957x_regs = { struct pca953x_chip { unsigned gpio_start; - u8 reg_output[MAX_BANK]; struct mutex i2c_lock; struct regmap *regmap; @@ -340,21 +339,6 @@ static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, return 0; } -static int pca953x_write_single(struct pca953x_chip *chip, int reg, u32 val, - int off) -{ - u8 regaddr = pca953x_recalc_addr(chip, reg, off, true, false); - int ret; - - ret = regmap_write(chip->regmap, regaddr, val); - if (ret < 0) { - dev_err(&chip->client->dev, "failed writing register\n"); - return ret; - } - - return 0; -} - static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) { u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); @@ -403,25 +387,17 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, struct pca953x_chip *chip = gpiochip_get_data(gc); u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off, true, false); + u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, + true, false); u8 bit = BIT(off % BANK_SZ); - u8 reg_val; int ret; mutex_lock(&chip->i2c_lock); /* set output level */ - if (val) - reg_val = chip->reg_output[off / BANK_SZ] - | (1u << (off % BANK_SZ)); - else - reg_val = chip->reg_output[off / BANK_SZ] - & ~(1u << (off % BANK_SZ)); - - ret = pca953x_write_single(chip, chip->regs->output, reg_val, off); + ret = regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); if (ret) goto exit; - chip->reg_output[off / BANK_SZ] = reg_val; - /* then direction */ ret = regmap_write_bits(chip->regmap, dirreg, bit, 0); exit: @@ -452,23 +428,12 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) { struct pca953x_chip *chip = gpiochip_get_data(gc); - u8 reg_val; - int ret; + u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off, + true, false); + u8 bit = BIT(off % BANK_SZ); mutex_lock(&chip->i2c_lock); - if (val) - reg_val = chip->reg_output[off / BANK_SZ] - | (1u << (off % BANK_SZ)); - else - reg_val = chip->reg_output[off / BANK_SZ] - & ~(1u << (off % BANK_SZ)); - - ret = pca953x_write_single(chip, chip->regs->output, reg_val, off); - if (ret) - goto exit; - - chip->reg_output[off / BANK_SZ] = reg_val; -exit: + regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); mutex_unlock(&chip->i2c_lock); } @@ -500,7 +465,10 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, int ret; mutex_lock(&chip->i2c_lock); - memcpy(reg_val, chip->reg_output, NBANK(chip)); + ret = pca953x_read_regs(chip, chip->regs->output, reg_val); + if (ret) + goto exit; + for (bank = 0; bank < NBANK(chip); bank++) { bank_mask = mask[bank / sizeof(*mask)] >> ((bank % sizeof(*mask)) * 8); @@ -512,11 +480,7 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, } } - ret = pca953x_write_regs(chip, chip->regs->output, reg_val); - if (ret) - goto exit; - - memcpy(chip->reg_output, reg_val, NBANK(chip)); + pca953x_write_regs(chip, chip->regs->output, reg_val); exit: mutex_unlock(&chip->i2c_lock); } @@ -818,8 +782,9 @@ static int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) int ret; u8 val[MAX_BANK]; - ret = pca953x_read_regs(chip, chip->regs->output, chip->reg_output); - if (ret) + ret = regcache_sync_region(chip->regmap, chip->regs->output, + chip->regs->output + NBANK(chip)); + if (ret != 0) goto out; ret = regcache_sync_region(chip->regmap, chip->regs->direction, From patchwork Wed Dec 12 01:40:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725457 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D25E159A for ; Wed, 12 Dec 2018 01:40:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8B82A7C3 for ; Wed, 12 Dec 2018 01:40:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 335012A7C9; Wed, 12 Dec 2018 01:40:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF1182A7E3 for ; Wed, 12 Dec 2018 01:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726331AbeLLBkq (ORCPT ); Tue, 11 Dec 2018 20:40:46 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52381 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbeLLBkq (ORCPT ); Tue, 11 Dec 2018 20:40:46 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so3499051wml.2; Tue, 11 Dec 2018 17:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sdnkb9xXemjnqlwb44sWyooul4B0KAlemcE323jrTE8=; b=VEQQBkXFKJrddvHDsdEWvkc3kIe8AU3QmNQHjFjdk7jYDEWN+SjOguX3E+9OwZgaQk hS22alczjxw7Ho6uoflQ46eDF6KytUwbvyhJg8F6HuC0JPxGkoMEJ8yc5JpAUT5t0vWG wCgqQBsfoUPxvmp+MFu+pNgsCvo5TVFZgTCN34D3f0jJXXjkdOuvvUdHyiCgnI2KQAGn gdfoXGzXwpzcAQ63Vuls+BSbsG1Iz/QtEb375pn8Ynnj940FP/t/d4YI/L6eAqRJJQvu Ku8ti5qUWiN3Neoekd8nvMEB9CQlgCf5xTkEljYBcSR3RETvGlp+5KEhgwJavh9ZaDwU XEIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sdnkb9xXemjnqlwb44sWyooul4B0KAlemcE323jrTE8=; b=hAAMCPn72OMdvM9cyt7f4Burz1BkvB3cNgwE4HhnOEwoqBVdF7pfv7avNGn7JLeFTe 3+msmUJYVMqP82TNlYxbC/RcFlGgKcMV2BnuIv0k5TK13MfwGOEPeWGugVRDVczpf+Ck u2LbUz9Slh2BW8OCn7jWsZQf/NGrB45XrNYjF6/i3tkhx9VPjVuHI3MmsRLoVumUJpiE cmIl4u2cWIPmOISJrESHZ8VeT7oWIai132xFnhh/eIlUBTRrJ4+0t3n5ibMZNY8a9u5L f2nMk8cI5VdMVqh9OStXwit9/utsMHmAAWj2jp+DbkxyLfpzDYdwnQV1xr8O4ysqdwIW olPw== X-Gm-Message-State: AA+aEWbUh+XrAWaZZQrPiWGPv9gzpSHMW1ukGR87Ug8+W2dLI60i6Wk0 ZUv1I29dxmNdxdVdvCKb08SPycUF X-Google-Smtp-Source: AFSGD/UxN+Fg5SywOsS87rQ6waJrErKFG5NcyDIARMAjpaNqDm/BHG2yLS7ksvfwI5LkFU8hUGfPKA== X-Received: by 2002:a1c:ac85:: with SMTP id v127mr3952871wme.62.1544578844162; Tue, 11 Dec 2018 17:40:44 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:43 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 13/14] gpio: pca953x: Zap single use of pca953x_read_single() Date: Wed, 12 Dec 2018 02:40:01 +0100 Message-Id: <20181212014002.4753-13-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Drop pca953x_write_single() which is used in one place. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index a349f68c4025..6f50cf14bb23 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -324,21 +324,6 @@ static u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off, return regaddr; } -static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, - int off) -{ - u8 regaddr = pca953x_recalc_addr(chip, reg, off, false, false); - int ret; - - ret = regmap_read(chip->regmap, regaddr, val); - if (ret < 0) { - dev_err(&chip->client->dev, "failed reading register\n"); - return ret; - } - - return 0; -} - static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val) { u8 regaddr = pca953x_recalc_addr(chip, reg, 0, true, true); @@ -408,11 +393,14 @@ static int pca953x_gpio_direction_output(struct gpio_chip *gc, static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) { struct pca953x_chip *chip = gpiochip_get_data(gc); + u8 inreg = pca953x_recalc_addr(chip, chip->regs->input, off, + true, false); + u8 bit = BIT(off % BANK_SZ); u32 reg_val; int ret; mutex_lock(&chip->i2c_lock); - ret = pca953x_read_single(chip, chip->regs->input, ®_val, off); + ret = regmap_read(chip->regmap, inreg, ®_val); mutex_unlock(&chip->i2c_lock); if (ret < 0) { /* NOTE: diagnostic already emitted; that's all we should @@ -422,7 +410,7 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) return 0; } - return (reg_val & (1u << (off % BANK_SZ))) ? 1 : 0; + return !!(reg_val & bit); } static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) From patchwork Wed Dec 12 01:40:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10725459 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96F6B159A for ; Wed, 12 Dec 2018 01:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 887722A7C3 for ; Wed, 12 Dec 2018 01:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D0FC2A7E2; Wed, 12 Dec 2018 01:40:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17E122A7C3 for ; Wed, 12 Dec 2018 01:40:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726341AbeLLBkr (ORCPT ); Tue, 11 Dec 2018 20:40:47 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38350 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbeLLBkr (ORCPT ); Tue, 11 Dec 2018 20:40:47 -0500 Received: by mail-wr1-f65.google.com with SMTP id v13so16035118wrw.5; Tue, 11 Dec 2018 17:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B3y60QNGnEeNUo7z75DsEI4zO/MsYhoXLy0FOACkVxc=; b=SkcA7nwGRX+TB5nEo1ydwGlG3RIlAZsQSTlmQtHI73gpjuEqE1TFfkF3hZqLzDCPXF K0Yu0uc9Pi5YX5jKGSbkx7vIPgSDVSnweoxAplM8ut9dfg6TMtazcE44Z1v8/eVsXzLI BbqErP7Swe8uJ9uZj4YnlZmDp/Uvrzsuc+jRzqSIbaw4HLRwOSyCNNGOM9y+gYHygYEw lkxNk+qxn2jSulcFHZyEJP8ub2uetPKw+S92gImubDW0/fC08iIuiApk6JmwunXuXZ1J /86LrLmtx0hzbK7+5M/0tdjY3TUNJ5c61jeYF/Fx7dmr61UzmRMiCgxWDdmuzrSpmrgk ukiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B3y60QNGnEeNUo7z75DsEI4zO/MsYhoXLy0FOACkVxc=; b=ZvORTxhj+RgfUoxz+1Um+Ud4PGjHc7nzPXxO6erTvf/IP6Hrg4hXJgy1rGTPkQjvLg 36+GxTgM/ZnqA3SuVkUZit3bJ2kMIaKwl7XfA0bg4MKOpLg9AS62BxDUWDmZ/1RlYv8f JhCzOoAk2B2UEn2CB0pCw38g6dFqo6drvUXtyAr/H1nEQELJDLObcTGzAYTYMyM8V0wi XKvgs5BAAO4A4QzO0Wt3zsAfBrpyeKVdVX/x/cgiB2FF6ZMFMAL4Z3EhkRnrxaOb3Wjy jkXYVFANAgLk3aQaFQcOEYMj/FnuA1Rp2DkExlSn4lds4FUBYgaGSpkgDdxc0CZdVvWs SiNA== X-Gm-Message-State: AA+aEWay4n33IkssCcHzOlD6AiilN3DvPHrIKaaBTVTqMb+1GHi7lbtz CjaBHrialvJLp2Xh/JJmdXDgfs6a X-Google-Smtp-Source: AFSGD/W28CBGt6F+7W73FL1yCfoJRcaiF43OzhPP8DZo3UGjcu66dss7Y4BJ/hQaYyMO1+lFT34ufQ== X-Received: by 2002:adf:f091:: with SMTP id n17mr15424382wro.292.1544578845608; Tue, 11 Dec 2018 17:40:45 -0800 (PST) Received: from kurokawa.lan (ip-86-49-110-70.net.upcbroadband.cz. [86.49.110.70]) by smtp.gmail.com with ESMTPSA id c12sm12719214wrs.82.2018.12.11.17.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 17:40:44 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: linux-gpio@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Marek Vasut , Linus Walleij , Bartosz Golaszewski Subject: [PATCH V2 14/14] gpio: pca953x: Restore registers after suspend/resume cycle Date: Wed, 12 Dec 2018 02:40:02 +0100 Message-Id: <20181212014002.4753-14-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> References: <20181212014002.4753-1-marek.vasut+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is possible that the PCA953x is powered down during suspend. Use regmap cache to assure the registers in the PCA953x are in line with the driver state after resume. Signed-off-by: Marek Vasut Cc: Linus Walleij Cc: Bartosz Golaszewski --- V2: - Drop the regcache_sync() calls from suspend callback - Fix build with CONFIG_GPIO_PCA953X_IRQ --- drivers/gpio/gpio-pca953x.c | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 6f50cf14bb23..83617fdc661d 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -975,6 +975,91 @@ static int pca953x_remove(struct i2c_client *client) return ret; } +#ifdef CONFIG_PM_SLEEP +static int pca953x_regcache_sync(struct device *dev) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + int ret; + + /* + * The ordering between direction and output is important, + * sync these registers first and only then sync the rest. + */ + ret = regcache_sync_region(chip->regmap, chip->regs->direction, + chip->regs->direction + NBANK(chip)); + if (ret != 0) { + dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret); + return ret; + } + + ret = regcache_sync_region(chip->regmap, chip->regs->output, + chip->regs->output + NBANK(chip)); + if (ret != 0) { + dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret); + return ret; + } + +#ifdef CONFIG_GPIO_PCA953X_IRQ + if (chip->driver_data & PCA_PCAL) { + ret = regcache_sync_region(chip->regmap, PCAL953X_IN_LATCH, + PCAL953X_IN_LATCH + NBANK(chip)); + if (ret != 0) { + dev_err(dev, "Failed to sync INT latch registers: %d\n", + ret); + return ret; + } + + ret = regcache_sync_region(chip->regmap, PCAL953X_INT_MASK, + PCAL953X_INT_MASK + NBANK(chip)); + if (ret != 0) { + dev_err(dev, "Failed to sync INT mask registers: %d\n", + ret); + return ret; + } + } +#endif + + return 0; +} + +static int pca953x_suspend(struct device *dev) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + + regcache_cache_only(chip->regmap, true); + + regulator_disable(chip->regulator); + + return 0; +} + +static int pca953x_resume(struct device *dev) +{ + struct pca953x_chip *chip = dev_get_drvdata(dev); + int ret; + + ret = regulator_enable(chip->regulator); + if (ret != 0) { + dev_err(dev, "Failed to enable regulator: %d\n", ret); + return 0; + } + + regcache_cache_only(chip->regmap, false); + regcache_mark_dirty(chip->regmap); + ret = pca953x_regcache_sync(dev); + if (ret) + return ret; + + ret = regcache_sync(chip->regmap); + if (ret != 0) { + dev_err(dev, "Failed to restore register map: %d\n", ret); + return ret; + } + + return 0; +} +#endif + /* convenience to stop overlong match-table lines */ #define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) #define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) @@ -1018,9 +1103,12 @@ static const struct of_device_id pca953x_dt_ids[] = { MODULE_DEVICE_TABLE(of, pca953x_dt_ids); +static SIMPLE_DEV_PM_OPS(pca953x_pm_ops, pca953x_suspend, pca953x_resume); + static struct i2c_driver pca953x_driver = { .driver = { .name = "pca953x", + .pm = &pca953x_pm_ops, .of_match_table = pca953x_dt_ids, .acpi_match_table = ACPI_PTR(pca953x_acpi_ids), },