Received: by 10.213.65.68 with SMTP id h4csp1302212imn; Wed, 21 Mar 2018 07:32:08 -0700 (PDT) X-Google-Smtp-Source: AG47ELsOwzaXFRL94LMOLx3DMC9gNKxAFrrKuwfBb30IaY3vB4zseEPrs/RDL50//mDO8xgAkY2n X-Received: by 2002:a17:902:830a:: with SMTP id bd10-v6mr20536366plb.322.1521642728548; Wed, 21 Mar 2018 07:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521642728; cv=none; d=google.com; s=arc-20160816; b=wJrKPH02paeBTiJw9Nw97hnQKudFFgkTYuEyun1fI61rn0m7yriPMGtTCMOqEjzM3Y GD2qXu0QcNwtO/Zo1cq49+qA29ks780gFNESkPVY+uFgnXg7iiPwt1cRVwaVWXa7aWam Y9CNEjb+FB/7g3SsYq9AMfX7PcK/xu0tYxQfnfm4iWx9h2F8pBjdvravwsLtJt7bY7Js 0K/PowHV5nsQEBZ6eTghInGuJsdFj8Zo1qsLuAn9BCxjjq1wPY7F7cqJY01+c/IYr5K3 y1Czk2BgbE1vudW7dXIOidIYpCC672Mxh7D4UsjwSwCfpaGySJhu7lraI2VlqSm5hrL2 eZCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=QQ/aJSRs+3fVlHd8LYk9UThTcwN6pX8NGQ7ygZTNS+Y=; b=vjd8CIjxTBGAW5aoDkwNkMTv1mc20E/Le4rMwh/FC4YrcUQb2tOLotnpvz6NkLRbjr eKHveQC+Uh4k2jGSIdwMr7IIVOcGl3XeInWzHH7RNu4CTQPIcXBMTnPxbchZiNCC+rbb WlyKrSAbcJsv32hCYB7iE39R5TyiEv/ISMAws6bk2MLfUrqO+sU7QjIM/s/pTndXHMp5 ZLEi1OnLfKVOrNDFwIvQIz+q1F0cxZSeFuPUyFblDhLqLJym321clZUDGyjCK/Xt2Vjc 0PYujzt4nohyeI71wAhqij3VcSMmSMf1xevQ6ybtliJKuMqXcWsh/2QdZ6UM7/lPzSoY oArg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=EbASJ83D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si2825127pgc.818.2018.03.21.07.31.53; Wed, 21 Mar 2018 07:32:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=EbASJ83D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752428AbeCUOa2 (ORCPT + 99 others); Wed, 21 Mar 2018 10:30:28 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:35659 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752300AbeCUOaV (ORCPT ); Wed, 21 Mar 2018 10:30:21 -0400 Received: by mail-qt0-f196.google.com with SMTP id s2so5431691qti.2 for ; Wed, 21 Mar 2018 07:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QQ/aJSRs+3fVlHd8LYk9UThTcwN6pX8NGQ7ygZTNS+Y=; b=EbASJ83DgWQcfDwhkNbg2Ml1yWmaMrkBfBpHHL7btavZBK9gdZppZN6kutk4YiQZHY lQgl7l7gHi1C+UwF0/wTX7GYv9W4PHJ0iexWwcAYveo+vqP3BnzXyNpAPtDz24iGzJJ3 As9Ohjfb520vUohNNhUlscQAMn4FHKqv6L08LFDTq0aHVsr9k7ZGQ1olkYpHbLEcHPBw LkGcIzn1ExEY742kwM5D+m2O70M/9eh+lhiLzzNO9WmrkdK1keupAh9n6YYIy3Z1j/9b cACYycVT1q05ZlsKZiAKuMucmvWLNOrghT/07GKJJYfafiueK5v5LHX0AfJU3vg0bPlL 5zCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QQ/aJSRs+3fVlHd8LYk9UThTcwN6pX8NGQ7ygZTNS+Y=; b=SrOnzfwWcHhsYOXg2Zh5doVMZGtWK74EVB165x2Mw7gJ2wDpLI22vQAaQ+Nnt3z0Pj fhqIyfK4IDPvyaOdEj9w5WQFtIOBFa9wbFzJvQ/D7+DUd7yVeR4bq4YdjV1JwDBSr1+k uiDgD3XyY8SFUtsWVNMJcM/ZWrupJZTnuijIJvW+UEwY+bTlXeE57xhFdb6kVq7BfX5X YMqbiRDxXEhjprkT+cjA52dqxIeQRyogbaDIpUUQ0nDFJcvmzeqRfL5xa4vWeJMxEwWO Kv2Ysj6BHjtwtuOgZ11rOZ17iVFVMnkMk2miYOSM4rMoE+RbnCMMWsN7PAyO+HzPv3Lv ZyVg== X-Gm-Message-State: AElRT7F1QSF/xlSKs8EiOaRqDOiePbCKxyDJJhs1i3NIgw2A1Nfuz3se eJNMdS9GpDtro62NeZ+LcJUuOw== X-Received: by 10.200.25.252 with SMTP id s57mr29022683qtk.32.1521642620468; Wed, 21 Mar 2018 07:30:20 -0700 (PDT) Received: from localhost.localdomain ([190.210.56.45]) by smtp.gmail.com with ESMTPSA id g14sm3118592qtk.71.2018.03.21.07.30.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 07:30:19 -0700 (PDT) From: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, hernan@vanguardiasur.com.ar Subject: [PATCH 06/11] staging: iio: ad7746: Add dt-bindings Date: Wed, 21 Mar 2018 11:28:54 -0300 Message-Id: <1521642539-4845-7-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar> References: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds dt bindings by populating a pdata struct in order to modify as little as possible the existing code. It supports both platform_data and dt-bindings but uses only one depending on CONFIG_OF's value. Signed-off-by: HernĂ¡n Gonzalez --- drivers/staging/iio/cdc/ad7746.c | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index cba8cd1..815573c 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -658,6 +658,44 @@ static const struct iio_info ad7746_info = { /* * device probe and remove */ +#ifdef CONFIG_OF +static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct ad7746_platform_data *pdata; + unsigned int tmp; + int ret; + + /* The default excitation outputs are not inverted, it should be stated + * in the dt if needed. + */ + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + + tmp = 0; + ret = of_property_read_u32(np, "adi,exclvl", &tmp); + if (ret || tmp > 3) { + dev_warn(dev, "Wrong exclvl value, using default\n"); + pdata->exclvl = 3; /* default value */ + } else { + pdata->exclvl = tmp; + } + + pdata->exca_inv_en = of_property_read_bool(np, "adi,nexca_en"); + pdata->excb_inv_en = of_property_read_bool(np, "adi,nexcb_en"); + pdata->exca_en = !pdata->exca_inv_en; + pdata->excb_en = !pdata->excb_inv_en; + + return pdata; +} +#else +static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev) +{ + return NULL; +} +#endif static int ad7746_probe(struct i2c_client *client, const struct i2c_device_id *id) @@ -668,6 +706,11 @@ static int ad7746_probe(struct i2c_client *client, unsigned char regval = 0; int ret = 0; + if (client->dev.of_node) + pdata = ad7746_parse_dt(&client->dev); + else + pdata = client->dev.platform_data; + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; @@ -731,12 +774,22 @@ static const struct i2c_device_id ad7746_id[] = { { "ad7747", 7747 }, {} }; - MODULE_DEVICE_TABLE(i2c, ad7746_id); +#ifdef CONFIG_OF +static const struct of_device_id ad7746_of_match[] = { + { .compatible = "adi,ad7745" }, + { .compatible = "adi,ad7746" }, + { .compatible = "adi,ad7747" }, + { } +}; +MODULE_DEVICE_TABLE(of, ad7746_of_match); +#endif + static struct i2c_driver ad7746_driver = { .driver = { .name = KBUILD_MODNAME, + .of_match_table = of_match_ptr(ad7746_of_match), }, .probe = ad7746_probe, .id_table = ad7746_id, -- 2.7.4