From patchwork Fri Mar 16 22:49:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10290433 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 572FE602BD for ; Fri, 16 Mar 2018 22:49:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46685290DA for ; Fri, 16 Mar 2018 22:49:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B084290DC; Fri, 16 Mar 2018 22:49:50 +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 99932290DA for ; Fri, 16 Mar 2018 22:49:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752077AbeCPWts (ORCPT ); Fri, 16 Mar 2018 18:49:48 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:37789 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752761AbeCPWtq (ORCPT ); Fri, 16 Mar 2018 18:49:46 -0400 Received: by mail-qk0-f193.google.com with SMTP id y137so12744153qka.4; Fri, 16 Mar 2018 15:49:46 -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=Mkl+dV2O4b/I5KaaABrYKyz9bg2TGUa2holFzK4j8uY=; b=TmhuW9+DAbsEJPzc71tIDJSkdaoiLUfh1B3jKShb0OyfQe9cFus3X0U+CWSNq3bM0g xW2/UaVT6KcW1NjWa2cuqYYgI8wif7C+OHqnuPZQDWjAaNRXBVTdX7WAdEfTQx6hJjHd 6m+u0B4LNlFrdydMeatqIdEvxYZ0v8Ejgp7hBay6Jr+U1q2gsDbOaylibp4jmJxO+5D7 uxEiCkc2Z0Ikc+bDp4VKffnR5lYZtFGYb4G/KD76mME4pLrwYmMdQdNyHtrKJjuugsBZ BZ8C14Dtci6IT5XzZC1vslkVMq7KzitDv5bpsUw80tCViDKBAxFLDk0MRu7y6AC3561B VLLg== 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=Mkl+dV2O4b/I5KaaABrYKyz9bg2TGUa2holFzK4j8uY=; b=By83gpFk3X5pkV8s7/7+thxE2Ok37HzfTKIqL/AYOPRUSaTDS7XoUyy8UIeI+zi6hA 9IXROF0vPZITv+dW4TZIwo2MA/vT79ZJs2UQmq2bux5C5KywSc+RaVOf2WoWM23yh4Pc YXGQK6GRnKssE21tjKrAGR7Koss9NFKEgGFOKTP6ttqPXQSXv/XTOfHvTpjAk9MCEHhk x8+hwlT9mbyA2bz6RJ0VJI5Oq2kOF6gngGdnU+UEJskPoPwvuKjRGiUQjewqW40uBu4Y e19LRGT3w0S+lZKYfrjFY4VbCKJROXpdo5u0eBCYzlv+S0oa3XbkQPXZtuQAys4nNBd6 Atyw== X-Gm-Message-State: AElRT7Gv6ozKDdiGPUNlTr3OVTvYRdIPmA34ue7hc5MZgmE7tTGZgNJ7 VkR7lbNb4h5aRNHD/Vkd6VE= X-Google-Smtp-Source: AG47ELvhhv0ZWmQ0eCJrr4ryCm391JT8Q7Ga45qdOvctKa44bzyD6XbKaymHsAC9swSFwKEGbujG8g== X-Received: by 10.233.223.193 with SMTP id t184mr5335576qkf.109.1521240585737; Fri, 16 Mar 2018 15:49:45 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id f6sm6420624qtb.35.2018.03.16.15.49.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Mar 2018 15:49:45 -0700 (PDT) Date: Fri, 16 Mar 2018 19:49:40 -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 v2 5/8] staging:iio:ade7854: Replace many functions for one function Message-ID: <518e40bdf740819b7ca0e5d8dc5a5756337a3bd8.1521239766.git.rodrigosiqueiramelo@gmail.com> 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 --- 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 1daad42b1e92..e95147a1bac1 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, DATA_SIZE_8_BITS); -} - -static int ade7854_i2c_write_reg_16(struct device *dev, - u16 reg_address, - u16 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, DATA_SIZE_16_BITS); -} - -static int ade7854_i2c_write_reg_24(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, DATA_SIZE_24_BITS); -} - -static int ade7854_i2c_write_reg_32(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_i2c_write_reg(dev, reg_address, val, DATA_SIZE_32_BITS); -} - 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 f21dc24194fb..1eba3044b86f 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, DATA_SIZE_8_BITS); -} - -static int ade7854_spi_write_reg_16(struct device *dev, - u16 reg_address, - u16 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, DATA_SIZE_16_BITS); -} - -static int ade7854_spi_write_reg_24(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, DATA_SIZE_24_BITS); -} - -static int ade7854_spi_write_reg_32(struct device *dev, - u16 reg_address, - u32 val) -{ - return ade7854_spi_write_reg(dev, reg_address, val, DATA_SIZE_32_BITS); -} - 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..4aa7c6ce0016 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, DATA_SIZE_8_BITS); 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, DATA_SIZE_16_BITS); 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, DATA_SIZE_24_BITS); 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, DATA_SIZE_32_BITS); 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, DATA_SIZE_16_BITS); } 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, DATA_SIZE_32_BITS); } 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 71bdd638f348..aa29faf7c91f 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -152,7 +152,8 @@ enum data_size { /** * 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 @@ -165,10 +166,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 type); int irq; struct mutex buf_lock; u8 tx[ADE7854_MAX_TX] ____cacheline_aligned;