From patchwork Fri Mar 23 14:26:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10304799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1721960384 for ; Fri, 23 Mar 2018 14:26:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05BEF28D84 for ; Fri, 23 Mar 2018 14:26:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE77E28DE3; Fri, 23 Mar 2018 14:26:49 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 4A97628D84 for ; Fri, 23 Mar 2018 14:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751739AbeCWO0s (ORCPT ); Fri, 23 Mar 2018 10:26:48 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:38361 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751691AbeCWO0r (ORCPT ); Fri, 23 Mar 2018 10:26:47 -0400 Received: by mail-qk0-f196.google.com with SMTP id 132so13060827qkd.5; Fri, 23 Mar 2018 07:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=o1+wVSW/A5rBHcgQQKkMj99Fd8cvBy516O+IQkiw/IU=; b=uqZn216ULvDU7KsQmbeeH6f8xYv7eNqFP+jksDTqV41wdB7x0beDAVIsNZnl5seExW TayfwVQlavCeS6cRZtcKvcZzUJfrl4HFPcyAo6B9xqmUuNx2cAIhCiRV7H0CgI9uFQJZ t9outMjEk4AsDWh3mCNmtmkenOJQzYycnvab1WVeca0LsDjXwFVYGkWxy3feaNMmvNnY NJ1ToD782r5h6rDCM+MebLloORcM9lt8+64FOSvDgRdzIMnTRzWoZKQaEc1Q0cPonCi6 S2pGTPiK4ZQavr38Cvjiy5wO9ZdjnvzV1WBbHs6Sr0q79jhQYtQFAP2JVlQl9V66ijJc q9iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=o1+wVSW/A5rBHcgQQKkMj99Fd8cvBy516O+IQkiw/IU=; b=jcHCrq76J5hxosGdgaTzYVMuyw1FXs8qxx20d81g9iBNL9gngefkUrHfWcC+oRSdn3 0F0i3Le5O1Pq9BiabtQuRQGdFvhu4UUoSJltcFrt1eUdDBv310YlRNHSD39+WxhlkYT/ T01qAhk4vIkWfwYtv8unVxoBn6w1lHqCfHl0LAB4vOpGbCN6acje1A++Fb0O4J4muHas KpMBMmCprjBYxLF8on0a0LH3g05n3FJkK9RYHydMUiDl/o7j5iMQDMWShhwVPbhj3Vtf Eo8xHul7VvIJgh/LVpP+1W7PRYCMWlZFvvhACWxzcJLjhpgigRXb1iqIDSC0EodEfD5k /9jA== X-Gm-Message-State: AElRT7FW7uqpGNYTyFdCeJ6WwYMmupt1UfQcPhPNBpCxpGlwSPbOPXBj 29dg5P1wHulVDshB/LMlto4= X-Google-Smtp-Source: AG47ELuZWBO6yyJTnKBUx4B+RsiRljWG/SYHkRp77PV84v9edFTv4ak5I8+/TGdhtg0dnHLuW6M04A== X-Received: by 10.55.98.131 with SMTP id w125mr23715624qkb.94.1521815206587; Fri, 23 Mar 2018 07:26:46 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id b10sm6292621qtg.78.2018.03.23.07.26.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Mar 2018 07:26:46 -0700 (PDT) Date: Fri, 23 Mar 2018 11:26:41 -0300 From: Rodrigo Siqueira To: John Syne , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Barry Song <21cnbao@gmail.com> Cc: daniel.baluta@nxp.com, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/8] staging:iio:ade7854: Remove write_reg_* duplications Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch removes code duplications related to the write_reg_* functions and centralizes them in a single function. Also, it eliminates the legacy functions and replaces them by a unique signature that is used by SPI and I2C. Signed-off-by: Rodrigo Siqueira --- Changes in v3: - Update commit message drivers/staging/iio/meter/ade7854-i2c.c | 33 +-------------------------------- drivers/staging/iio/meter/ade7854-spi.c | 33 +-------------------------------- drivers/staging/iio/meter/ade7854.c | 12 ++++++------ drivers/staging/iio/meter/ade7854.h | 9 ++++----- 4 files changed, 12 insertions(+), 75 deletions(-) diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c index c9f46d26b752..29e959fdb932 100644 --- a/drivers/staging/iio/meter/ade7854-i2c.c +++ b/drivers/staging/iio/meter/ade7854-i2c.c @@ -65,34 +65,6 @@ static int ade7854_i2c_write_reg(struct device *dev, return ret < 0 ? ret : 0; } -static int ade7854_i2c_write_reg_8(struct device *dev, - u16 reg_address, - u8 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, 8); -} - -static int ade7854_i2c_write_reg_16(struct device *dev, - u16 reg_address, - u16 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, 16); -} - -static int ade7854_i2c_write_reg_24(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, 24); -} - -static int ade7854_i2c_write_reg_32(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, 32); -} - static int ade7854_i2c_read_reg_8(struct device *dev, u16 reg_address, u8 *val) @@ -213,10 +185,7 @@ static int ade7854_i2c_probe(struct i2c_client *client, st->read_reg_16 = ade7854_i2c_read_reg_16; st->read_reg_24 = ade7854_i2c_read_reg_24; st->read_reg_32 = ade7854_i2c_read_reg_32; - st->write_reg_8 = ade7854_i2c_write_reg_8; - st->write_reg_16 = ade7854_i2c_write_reg_16; - st->write_reg_24 = ade7854_i2c_write_reg_24; - st->write_reg_32 = ade7854_i2c_write_reg_32; + st->write_reg = ade7854_i2c_write_reg; st->i2c = client; st->irq = client->irq; diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index 9c5c16c4d6e0..be7397042850 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -67,34 +67,6 @@ static int ade7854_spi_write_reg(struct device *dev, return ret; } -static int ade7854_spi_write_reg_8(struct device *dev, - u16 reg_address, - u8 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, 8); -} - -static int ade7854_spi_write_reg_16(struct device *dev, - u16 reg_address, - u16 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, 16); -} - -static int ade7854_spi_write_reg_24(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, 24); -} - -static int ade7854_spi_write_reg_32(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, 32); -} - static int ade7854_spi_read_reg_8(struct device *dev, u16 reg_address, u8 *val) @@ -260,10 +232,7 @@ static int ade7854_spi_probe(struct spi_device *spi) st->read_reg_16 = ade7854_spi_read_reg_16; st->read_reg_24 = ade7854_spi_read_reg_24; st->read_reg_32 = ade7854_spi_read_reg_32; - st->write_reg_8 = ade7854_spi_write_reg_8; - st->write_reg_16 = ade7854_spi_write_reg_16; - st->write_reg_24 = ade7854_spi_write_reg_24; - st->write_reg_32 = ade7854_spi_write_reg_32; + st->write_reg = ade7854_spi_write_reg; st->irq = spi->irq; st->spi = spi; diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c index 0193ae3aae29..45984b9a2bee 100644 --- a/drivers/staging/iio/meter/ade7854.c +++ b/drivers/staging/iio/meter/ade7854.c @@ -105,7 +105,7 @@ static ssize_t ade7854_write_8bit(struct device *dev, ret = kstrtou8(buf, 10, &val); if (ret) goto error_ret; - ret = st->write_reg_8(dev, this_attr->address, val); + ret = st->write_reg(dev, this_attr->address, val, 8); error_ret: return ret ? ret : len; @@ -126,7 +126,7 @@ static ssize_t ade7854_write_16bit(struct device *dev, ret = kstrtou16(buf, 10, &val); if (ret) goto error_ret; - ret = st->write_reg_16(dev, this_attr->address, val); + ret = st->write_reg(dev, this_attr->address, val, 16); error_ret: return ret ? ret : len; @@ -147,7 +147,7 @@ static ssize_t ade7854_write_24bit(struct device *dev, ret = kstrtou32(buf, 10, &val); if (ret) goto error_ret; - ret = st->write_reg_24(dev, this_attr->address, val); + ret = st->write_reg(dev, this_attr->address, val, 24); error_ret: return ret ? ret : len; @@ -168,7 +168,7 @@ static ssize_t ade7854_write_32bit(struct device *dev, ret = kstrtou32(buf, 10, &val); if (ret) goto error_ret; - ret = st->write_reg_32(dev, this_attr->address, val); + ret = st->write_reg(dev, this_attr->address, val, 32); error_ret: return ret ? ret : len; @@ -183,7 +183,7 @@ static int ade7854_reset(struct device *dev) st->read_reg_16(dev, ADE7854_CONFIG, &val); val |= BIT(7); /* Software Chip Reset */ - return st->write_reg_16(dev, ADE7854_CONFIG, val); + return st->write_reg(dev, ADE7854_CONFIG, val, 16); } static IIO_DEV_ATTR_AIGAIN(0644, @@ -426,7 +426,7 @@ static int ade7854_set_irq(struct device *dev, bool enable) else irqen &= ~BIT(17); - return st->write_reg_32(dev, ADE7854_MASK0, irqen); + return st->write_reg(dev, ADE7854_MASK0, irqen, 32); } static int ade7854_initial_setup(struct iio_dev *indio_dev) diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h index a82d38224cbd..290adbf56951 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -145,7 +145,8 @@ /** * struct ade7854_state - device instance specific data - * @spi: actual spi_device + * @spi: actual spi_device + * @write_reg Wrapper function for I2C and SPI write * @indio_dev: industrial I/O device structure * @buf_lock: mutex to protect tx and rx * @tx: transmit buffer @@ -158,10 +159,8 @@ struct ade7854_state { int (*read_reg_16)(struct device *dev, u16 reg_address, u16 *val); int (*read_reg_24)(struct device *dev, u16 reg_address, u32 *val); int (*read_reg_32)(struct device *dev, u16 reg_address, u32 *val); - int (*write_reg_8)(struct device *dev, u16 reg_address, u8 val); - int (*write_reg_16)(struct device *dev, u16 reg_address, u16 val); - int (*write_reg_24)(struct device *dev, u16 reg_address, u32 val); - int (*write_reg_32)(struct device *dev, u16 reg_address, u32 val); + int (*write_reg)(struct device *dev, u16 reg_address, u32 val, + int bits); int irq; struct mutex buf_lock; u8 tx[ADE7854_MAX_TX] ____cacheline_aligned;