From patchwork Sat Dec 23 17:16:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10131639 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 A9D6C6019D for ; Sat, 23 Dec 2017 17:16:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2979292C4 for ; Sat, 23 Dec 2017 17:16:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D724F292E1; Sat, 23 Dec 2017 17:16: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.9 required=2.0 tests=BAYES_00,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 763B0292C4 for ; Sat, 23 Dec 2017 17:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752902AbdLWRQu (ORCPT ); Sat, 23 Dec 2017 12:16:50 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:43662 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752857AbdLWRQu (ORCPT ); Sat, 23 Dec 2017 12:16:50 -0500 Received: by mail-wm0-f68.google.com with SMTP id n138so26644364wmg.2 for ; Sat, 23 Dec 2017 09:16:49 -0800 (PST) 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=+rPNNCgs2goDjVEUzFgu2grkW/8kU8fp2itjCp7lNYo=; b=Cep8+0arwhlHKimpdNFprbvSdcB6UTzaKNlUVh0zqTi6xMAdBaL7WUjsdyDeE4sRtF SAny0LNaQcv5IKVqT7TINf1At9XJec1oPOuwRClMMuaUHamS7HfgXw9RCcqmhJ3zvLV3 epJs3kGgt/5jkxgpoZdd/YZINHEGjxcl7POrdrtTc139S2t4UImfN4o8btbbTPWtxgwh qEOO1HbtuvSXmgQNEz+E/Wn/EI7rnA/O0SUbaYxy+393fySuYEF1oJ37Eakrc0N6Yn+V 0zJsRPZak9i84zBX4hUOkIrwWKiYgeP95Q5oX+Cp9LZJ/UlMPvNTDSaQYOtFDgjeUsv6 ylpg== X-Gm-Message-State: AKGB3mIZ0idN0FzcYo+fLCQ3D2dgweBkBUjlkBy9s6xi07gKFWGy/QGA hp8/en2RQ8RThc4lkTrCE24hGf5tv6k= X-Google-Smtp-Source: ACJfBoutsOqWDP1vmBAXsjioEb1jcL3tbzO0J61tDIg1k+dlQ9IU7i1fY/DbEJqUaE2jKmzIcdbrGg== X-Received: by 10.80.201.196 with SMTP id c4mr19827914edi.56.1514049408910; Sat, 23 Dec 2017 09:16:48 -0800 (PST) Received: from localhost.net ([95.232.21.242]) by smtp.gmail.com with ESMTPSA id y3sm22980643edb.37.2017.12.23.09.16.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Dec 2017 09:16:48 -0800 (PST) From: Lorenzo Bianconi To: jic23@kernel.org Cc: linux-iio@vger.kernel.org Subject: [PATCH 1/2] iio: humidity: hts221: move common code in hts221_core Date: Sat, 23 Dec 2017 18:16:20 +0100 Message-Id: <1953687a7f71cbc6a65d51d412c86fa4a5b93f3f.1514042380.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: 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 Move duplicated i2c/spi probe code in hts221_probe() Signed-off-by: Lorenzo Bianconi --- drivers/iio/humidity/hts221.h | 3 ++- drivers/iio/humidity/hts221_core.c | 18 ++++++++++++++++-- drivers/iio/humidity/hts221_i2c.c | 18 ++---------------- drivers/iio/humidity/hts221_spi.c | 18 ++---------------- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h index 51d021966222..c581af8c0f5d 100644 --- a/drivers/iio/humidity/hts221.h +++ b/drivers/iio/humidity/hts221.h @@ -61,7 +61,8 @@ struct hts221_hw { extern const struct dev_pm_ops hts221_pm_ops; int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val); -int hts221_probe(struct iio_dev *iio_dev); +int hts221_probe(struct device *dev, int irq, const char *name, + const struct hts221_transfer_function *tf_ops); int hts221_set_enable(struct hts221_hw *hw, bool enable); int hts221_allocate_buffers(struct hts221_hw *hw); int hts221_allocate_trigger(struct hts221_hw *hw); diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c index daef177219b6..d3f7904766bd 100644 --- a/drivers/iio/humidity/hts221_core.c +++ b/drivers/iio/humidity/hts221_core.c @@ -581,12 +581,26 @@ static const struct iio_info hts221_info = { static const unsigned long hts221_scan_masks[] = {0x3, 0x0}; -int hts221_probe(struct iio_dev *iio_dev) +int hts221_probe(struct device *dev, int irq, const char *name, + const struct hts221_transfer_function *tf_ops) { - struct hts221_hw *hw = iio_priv(iio_dev); + struct iio_dev *iio_dev; + struct hts221_hw *hw; int err; u8 data; + iio_dev = devm_iio_device_alloc(dev, sizeof(*hw)); + if (!iio_dev) + return -ENOMEM; + + dev_set_drvdata(dev, (void *)iio_dev); + + hw = iio_priv(iio_dev); + hw->name = name; + hw->dev = dev; + hw->irq = irq; + hw->tf = tf_ops; + mutex_init(&hw->lock); err = hts221_check_whoami(hw); diff --git a/drivers/iio/humidity/hts221_i2c.c b/drivers/iio/humidity/hts221_i2c.c index f38e4b7e0160..2c97350a0f76 100644 --- a/drivers/iio/humidity/hts221_i2c.c +++ b/drivers/iio/humidity/hts221_i2c.c @@ -66,22 +66,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = { static int hts221_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { - struct hts221_hw *hw; - struct iio_dev *iio_dev; - - iio_dev = devm_iio_device_alloc(&client->dev, sizeof(*hw)); - if (!iio_dev) - return -ENOMEM; - - i2c_set_clientdata(client, iio_dev); - - hw = iio_priv(iio_dev); - hw->name = client->name; - hw->dev = &client->dev; - hw->irq = client->irq; - hw->tf = &hts221_transfer_fn; - - return hts221_probe(iio_dev); + return hts221_probe(&client->dev, client->irq, + client->name, &hts221_transfer_fn); } static const struct acpi_device_id hts221_acpi_match[] = { diff --git a/drivers/iio/humidity/hts221_spi.c b/drivers/iio/humidity/hts221_spi.c index 57cbc256771b..55b29b53b9d1 100644 --- a/drivers/iio/humidity/hts221_spi.c +++ b/drivers/iio/humidity/hts221_spi.c @@ -80,22 +80,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = { static int hts221_spi_probe(struct spi_device *spi) { - struct hts221_hw *hw; - struct iio_dev *iio_dev; - - iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*hw)); - if (!iio_dev) - return -ENOMEM; - - spi_set_drvdata(spi, iio_dev); - - hw = iio_priv(iio_dev); - hw->name = spi->modalias; - hw->dev = &spi->dev; - hw->irq = spi->irq; - hw->tf = &hts221_transfer_fn; - - return hts221_probe(iio_dev); + return hts221_probe(&spi->dev, spi->irq, + spi->modalias, &hts221_transfer_fn); } static const struct of_device_id hts221_spi_of_match[] = {