From patchwork Sun Dec 2 19:35:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10708163 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 3A4D913AD for ; Sun, 2 Dec 2018 19:36:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C3A22A565 for ; Sun, 2 Dec 2018 19:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 209302A7D2; Sun, 2 Dec 2018 19:36:21 +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 A9C052A565 for ; Sun, 2 Dec 2018 19:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725793AbeLBTgX (ORCPT ); Sun, 2 Dec 2018 14:36:23 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56094 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbeLBTgX (ORCPT ); Sun, 2 Dec 2018 14:36:23 -0500 Received: by mail-wm1-f66.google.com with SMTP id y139so3624618wmc.5; Sun, 02 Dec 2018 11:36:18 -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=mwZQVspIPtbY5vL5xSazUJPkVrZT6bsInP1qpRE+HWE=; b=ZWF0SLneO+hXIBbbxduY/DtjWGYFw3tHUrAKovtzDpeXtl2lBGunOBZbYDV4Ta/TGO def3W94gMjx7beeLxA15RNNWXDMUzh4PBxR7syV+MlOpvuQdw2oyx8NAti4tfWs4Eayk 4vXaNkOqIK+Ctj24xGa//pfYt7n1Ch4cH9M0tGYElJ1ayAHhsv/VTMSuEEZCABwj7T5D MuhLZDzSQuhJ3VRBaLBBjTdPMh1P+DtDCKHXuYq2joyUaPlhSLDp1HNMC+0iESPUOEJS q3VqI8ioTuA0wMHPjxqoP2ZZFl0lg4STaU/Z+iCvsJzKVFODsB9GFVRPvHY2cj8Bg04o oE2A== 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=mwZQVspIPtbY5vL5xSazUJPkVrZT6bsInP1qpRE+HWE=; b=t0hKHIbjhmyUu/Bl2Y6vZXdEHhFUcNvmemJNTxOAxwlr3xByIkRqbUm8dXj8pfh6C9 vpPnSjxp7H2ceuZfwjlvEZg1ltcP8J6l5XLgUeEVHtDwvJsApFWmw2rRrqSW8V64G5lS sXCOxUWtD9Eo0ZyRJCtBtH4rXoRgJl+W14xyXCEF45/dFbSZryrPeyppEG2ZDh2Tor4N hxhPoTOn6AswjR1sbzyunHuJ6buyKuy3Z3P6I+TcEfhcqm3E1sQDrmbZ7DMwRuQxpRmM m04Pj+7JDJ1fU2aPQ9QdWvXCzZ0qQUgzNQHl+fqNNWch3izRDRdxVDoQHsbF1goinhfD Iihg== X-Gm-Message-State: AA+aEWY96ZnEaFldvRmbJ8wiL08WMXtJt2YbARJRKQGW42zrz0T9H6yf eMseoQ4NHfEcd/YKhdVXVWbJGxoA X-Google-Smtp-Source: AFSGD/XsHawgnqp6lO0b0h9gQJKjXivqdX/xnLR4l18JlB/fbeRKv1uhKFiUUKRQIKu2acqab6SITQ== X-Received: by 2002:a1c:8a09:: with SMTP id m9mr5864203wmd.27.1543779377198; Sun, 02 Dec 2018 11:36:17 -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 y185sm4016628wmg.34.2018.12.02.11.36.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 11:36:16 -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 06/14] gpio: pca953x: Unify pca953x_{read,write}_regs_{8,mul}() Date: Sun, 2 Dec 2018 20:35:45 +0100 Message-Id: <20181202193553.29704-6-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181202193553.29704-1-marek.vasut+renesas@gmail.com> References: <20181202193553.29704-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 551fa69661b2..09fd8cde9ca9 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