From patchwork Sun Dec 2 19:35:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 10708153 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 DB77E13AD for ; Sun, 2 Dec 2018 19:36:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC4DC2A7CE for ; Sun, 2 Dec 2018 19:36:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C06BC2A7D4; Sun, 2 Dec 2018 19:36:14 +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 28DBC2A7CE for ; Sun, 2 Dec 2018 19:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725730AbeLBTgQ (ORCPT ); Sun, 2 Dec 2018 14:36:16 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36698 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725616AbeLBTgQ (ORCPT ); Sun, 2 Dec 2018 14:36:16 -0500 Received: by mail-wm1-f66.google.com with SMTP id a18so3621916wmj.1; Sun, 02 Dec 2018 11:36:11 -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=LYlAK5oYDdCUP/Dc3WUFK8DyLWBIup4NN2cLGA4Hjg0=; b=JOjdA/v9JaLGfFC13mznoyXXtLfuyOFjaVgfyKs5G2tOtp+vf0gvfkTU1T8im4ZGNv y0D9NJhQDv++nmQ8/jBslcDYtcoA+2xhEfVmt/Vdi5OO3yzvh9qGGdaTDfKZleFCrjOB 3O4Q6dag3WOb1E28aw/o4fGSdtexuQrtDP+sgic9TiBK87j+sxIxG2DpxceOsqFg2DtQ r+hf0UXk+tTSdO78ou2Jspmo+n5r7UDb2oh+ekAQ1Y50qpNVhYNYsWCyzdD5R9V1EjrV N3aYNbeQpMcAdGUWbkSK0ohNUuLvA4Z+69Zq6aL6wyOvs240rCH5u/c7RMajCxMen/At eSPA== 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=LYlAK5oYDdCUP/Dc3WUFK8DyLWBIup4NN2cLGA4Hjg0=; b=Jgonl2KF7lgw3xgRAkxYViHBeN8KUDf1BvQHFn0Nhszs9vh/WXsT3GS7y8hK0M+ihN tqabOMYwhdf2i1rRoZiB0V01055RodG18rSHgMqdiXlHXbO4yo6z6RxNVVtjDbYkm5FX IiwKpJT1Zz/eQMYJm6G6+VcAtMhAtJBsc2N2tCPhlnbhVO77LBMOMowRK2XOQW5eXXdk ckyzlxaNNC5+fnGZX+bXSd6twnewaP8dOtwrtytdsvynXAXb/WQy1QV2pWz6mIc/tpSO vW9jrf4KpBipy0Bw3oHJ53zOPnCgjfvBEqZqx5SLklBUUl8CBDy8mhzrvpk7p+T3BnN9 fLTg== X-Gm-Message-State: AA+aEWbCjuV+jwPhg8i1akYGTK4aFzS4tdl7owZsdVoKTSkP6Esg69+x cgz2BQYz+RMncl6trekcyBf/Yqw8 X-Google-Smtp-Source: AFSGD/U6vPro2gDx8+94F2Tr5fs5JVWcDpWAK17imYEFdn7osK38eD+WFifAHMM5j+tYRHH/ytBvBQ== X-Received: by 2002:a1c:650b:: with SMTP id z11mr5830218wmb.23.1543779370620; Sun, 02 Dec 2018 11:36:10 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 11:36:09 -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 01/14] gpio: pca953x: Deduplicate the bank_size Date: Sun, 2 Dec 2018 20:35:40 +0100 Message-Id: <20181202193553.29704-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_size = 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 --- 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 023a32cfac42..31e3b1b52330 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++) {