From patchwork Fri Nov 16 09:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 10685759 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 5410414D6 for ; Fri, 16 Nov 2018 09:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 445F4294F6 for ; Fri, 16 Nov 2018 09:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38BD32C428; Fri, 16 Nov 2018 09:47:11 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 E84992C3D4 for ; Fri, 16 Nov 2018 09:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbeKPT6l (ORCPT ); Fri, 16 Nov 2018 14:58:41 -0500 Received: from smtpo.poczta.interia.pl ([217.74.65.153]:44402 "EHLO smtpo.poczta.interia.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727398AbeKPT6l (ORCPT ); Fri, 16 Nov 2018 14:58:41 -0500 X-Interia-R: Interia X-Interia-R-IP: 188.121.17.172 X-Interia-R-Helo: Received: from localhost (ipv4-188-121-17-172.net.internetunion.pl [188.121.17.172]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Fri, 16 Nov 2018 10:47:03 +0100 (CET) From: Slawomir Stepien To: lars@metafoo.de, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org Subject: [PATCH 1/2] iio: potentiometer: mcp4131: use of_device_get_match_data() Date: Fri, 16 Nov 2018 10:47:21 +0100 Message-Id: <20181116094722.1070-2-sst@poczta.fm> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116094722.1070-1-sst@poczta.fm> References: <20181116094722.1070-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1542361625; bh=SeQC6ADhfMqcJrWpPiLEeByOpdwr13442Jk8BpWL0W4=; h=X-Interia-R:X-Interia-R-IP:X-Interia-R-Helo:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Interia-Antivirus; b=MN/HJj/Vgs5RKXdB0BmR+ZE6QUfmU/VUknjbCLBnv+i0oQzsL+IdoFDO6pjq3kjIp ZpxdwBPM34EEl3pRASzxQSOazFccAxvjppy60HZ0RGvh9ocOhYucu36PXeceYyv1eo tgPgjIlE2iqB7a+a3EoF+vSHCxkogCp1TtBBDzcA= 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 Try to get the device's data using OF API. In case of failure, fallback to the spi_get_device_id() method. Signed-off-by: Slawomir Stepien --- drivers/iio/potentiometer/mcp4131.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/potentiometer/mcp4131.c b/drivers/iio/potentiometer/mcp4131.c index b3e30db246cc..55f526a59215 100644 --- a/drivers/iio/potentiometer/mcp4131.c +++ b/drivers/iio/potentiometer/mcp4131.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #define MCP4131_WRITE (0x00 << 2) @@ -254,7 +255,9 @@ static int mcp4131_probe(struct spi_device *spi) data = iio_priv(indio_dev); spi_set_drvdata(spi, indio_dev); data->spi = spi; - data->cfg = &mcp4131_cfg[devid]; + data->cfg = of_device_get_match_data(&spi->dev); + if (!data->cfg) + data->cfg = &mcp4131_cfg[devid]; mutex_init(&data->lock); @@ -273,7 +276,6 @@ static int mcp4131_probe(struct spi_device *spi) return 0; } -#if defined(CONFIG_OF) static const struct of_device_id mcp4131_dt_ids[] = { { .compatible = "microchip,mcp4131-502", .data = &mcp4131_cfg[MCP413x_502] }, @@ -406,7 +408,6 @@ static const struct of_device_id mcp4131_dt_ids[] = { {} }; MODULE_DEVICE_TABLE(of, mcp4131_dt_ids); -#endif /* CONFIG_OF */ static const struct spi_device_id mcp4131_id[] = { { "mcp4131-502", MCP413x_502 }, From patchwork Fri Nov 16 09:47:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 10685757 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 6D5EB14D6 for ; Fri, 16 Nov 2018 09:47:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58754294F6 for ; Fri, 16 Nov 2018 09:47:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C86A2C428; Fri, 16 Nov 2018 09:47:10 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 EDAD62D3A4 for ; Fri, 16 Nov 2018 09:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727398AbeKPT6m (ORCPT ); Fri, 16 Nov 2018 14:58:42 -0500 Received: from smtpo.poczta.interia.pl ([217.74.65.153]:57072 "EHLO smtpo.poczta.interia.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727567AbeKPT6m (ORCPT ); Fri, 16 Nov 2018 14:58:42 -0500 X-Interia-R: Interia X-Interia-R-IP: 188.121.17.172 X-Interia-R-Helo: Received: from localhost (ipv4-188-121-17-172.net.internetunion.pl [188.121.17.172]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Fri, 16 Nov 2018 10:47:06 +0100 (CET) From: Slawomir Stepien To: lars@metafoo.de, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org Subject: [PATCH 2/2] iio: potentiometer mcp4131: use spi_get_device_id() only when needed Date: Fri, 16 Nov 2018 10:47:22 +0100 Message-Id: <20181116094722.1070-3-sst@poczta.fm> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116094722.1070-1-sst@poczta.fm> References: <20181116094722.1070-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1542361627; bh=nrDT1JLHy/XZfCoytDbgiycDFFa0WHJZPwNcLiawBEE=; h=X-Interia-R:X-Interia-R-IP:X-Interia-R-Helo:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Interia-Antivirus; b=TDTfGrLL0/B3Kff9x7aZOCo5NWcPa69fsbRkrplwVpgMDOOd9DM9f7wvJTXiF4ly/ wvKO+NxQ1adwf80wllTVfQrey20lPupvqlfMtxIlNLMjI+BJyVxqEci5FIF60LLBFP MgFKjKnFresmrpDy46cQY7qITFvTfjrMMwzIpziQ= 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 There is no need to find the device id up front, since the of_device_get_match_data() might return the correct data. Signed-off-by: Slawomir Stepien --- drivers/iio/potentiometer/mcp4131.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iio/potentiometer/mcp4131.c b/drivers/iio/potentiometer/mcp4131.c index 55f526a59215..efe035ce010d 100644 --- a/drivers/iio/potentiometer/mcp4131.c +++ b/drivers/iio/potentiometer/mcp4131.c @@ -244,7 +244,7 @@ static int mcp4131_probe(struct spi_device *spi) { int err; struct device *dev = &spi->dev; - unsigned long devid = spi_get_device_id(spi)->driver_data; + unsigned long devid; struct mcp4131_data *data; struct iio_dev *indio_dev; @@ -256,8 +256,10 @@ static int mcp4131_probe(struct spi_device *spi) spi_set_drvdata(spi, indio_dev); data->spi = spi; data->cfg = of_device_get_match_data(&spi->dev); - if (!data->cfg) + if (!data->cfg) { + devid = spi_get_device_id(spi)->driver_data; data->cfg = &mcp4131_cfg[devid]; + } mutex_init(&data->lock);