From patchwork Sun Dec 2 19:35:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10708165 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 C3D1A17F0 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 B3FA72A565 for ; Sun, 2 Dec 2018 19:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7CD52A7D2; 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 45F802A565 for ; Sun, 2 Dec 2018 19:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725796AbeLBTgY (ORCPT ); Sun, 2 Dec 2018 14:36:24 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40078 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725710AbeLBTgY (ORCPT ); Sun, 2 Dec 2018 14:36:24 -0500 Received: by mail-wm1-f66.google.com with SMTP id q26so3583272wmf.5; Sun, 02 Dec 2018 11:36:19 -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=DoUGhlj29N+wIU+Q4fWRcK80tjMhqltQopAuxSOzC9Y=; b=P0EkSd5DBx633LXBL5YJ7Vp3qJcAIOxyebti4N9+vSpkoTEG//urIYrTbvBu0WkFOx kBITLqKRUop0T8mQGniSA4NG1DGiIAO2vB2MF3tlfu2H5D8P5K0vFcFCIUnY3BqY0HSo SLnqWuJhwtw9asTGLlEAxRmuuYk2j7aVJnqtTO3o+BhVyZrf5UJOenU3OUiYxPDQERQC JqHGkFAGCEdd2qFWPfIbOJWUmuqQNCC23fmxLb8KgY974Khit7Ap1WZ9Nn8aAr24mTMT EBZHq5QgSdRdJicIMtZ7J3tpui7cXSsTpMGl0RkkPzN6qtvyucmoiJYWKghcMuYaPyjl bjIQ== 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=DoUGhlj29N+wIU+Q4fWRcK80tjMhqltQopAuxSOzC9Y=; b=Xm5RlznY0MwpNSPdM6uEkOTVemKdaNDDfN+fRGO1hqN0a0F8Zi7JIl4WmK1lvdzTRb snun8gEeLhe3Wu6Hh8tT+F4nyelIYiDzLTpeliVO9LWjPe8P0+MBkhp8YzM3hI9gCObE oJPwN6we+u6p1kGdPd2pi9gnuPvjqaT+AqslBR+lZvLdMAE184RlRbJjTmKEpvNhh2Sp Gx/2aHOqz5ylp4oH7gQP57WXE50DnlQ75qG8NZPOtK6c0NpTstpl0RjqjzBHwRXAVcl4 8I+PiAEfRLcnHUGOj26K2zJqCFKotbAN80UZ0oVCnNJxtQfG93xNV/Mj4BpqYI0KKMa8 FowA== X-Gm-Message-State: AA+aEWaxFmIQn6ISXwmpoMji/CaYGXx4jKrHxePMhbXIUIDhJFKX9VTp GYGRsvkJzDA/tApHbc8Jvd71LmzX X-Google-Smtp-Source: AFSGD/V/vC+Nja6aZCV3j8DUmS0LrkdPlthZDmQmWex5fmSU8wCz5yuJ7HVAHb3Crgt2hq5ElIiK6g== X-Received: by 2002:a1c:8302:: with SMTP id f2mr6156658wmd.9.1543779378538; Sun, 02 Dec 2018 11:36:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 11:36:17 -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 07/14] gpio: pca953x: Factor out common code from device_pca95xx_init() Date: Sun, 2 Dec 2018 20:35:46 +0100 Message-Id: <20181202193553.29704-7-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 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 09fd8cde9ca9..dc691bd52a79 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;