Received: by 10.192.165.156 with SMTP id m28csp897596imm; Fri, 13 Apr 2018 09:40:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/s1xVmWSXXHUGsQsAqn+EWVLiy4PTm2wtDBAec94PHC5Nx2N8GigPA9v+1w3rLqbZ6dhIc X-Received: by 10.167.128.194 with SMTP id a2mr12067101pfn.130.1523637610557; Fri, 13 Apr 2018 09:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523637610; cv=none; d=google.com; s=arc-20160816; b=tibINrb/uRhuITXMa9ctnwYi+V1tTGUYr7iCaNTLYHhlNg867X7+RZK1dEbi6u/O40 anldl0uoy69laE2/gsL+An/wbUBfL/VO9qrgnVSSPzM5cyZ/b9vvaXzhkX1kCiVDTTGv HjxaNzB2eHqr5EDf3CzPYE1ybOsdBGK1vhmxzw6uz2ggjsDK3fhgjb6mI+yEjzDp+bUN tJakrfM45U3yfDblGPCaMcQVl5QMF3RYXTU9/6DfsY6RmDOGQv9Peg0Y88KX6Ka0PdNu TpRXM+2SkHdUTotv0u2myu996GbiGPLUZoOgzdjZEqfHXg8KjciiZ2XQqn/BbItfuI2t iuxA== 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:cc:to:from :dkim-signature:arc-authentication-results; bh=gCLllH3REqUzI1sPIV3bnZhs1KmvZS77Al6RA0oTClI=; b=YFf4a9LLOIgmEPg6TPIfPT/bgbhZiu2FX8S7TMnSnnWCjlgEgqxKY1u6OD6Ccv9Uns kFTYSTY0EQ3+g4RRmjlGqlVJJWGZN/rAJOU9/vdBUU7AMWPEqLqfw8t+vbPujUnPdzVI J9aseQyurgT2p2EDnIUtsGQihP7kpnaTQhq/ttB2aPV22rl1vobc/hcqmKY23JpytjME xiaG+vlS4pkGJjBBwWYrmdNTq/jOiYljdjNfDD6CRVm7v/CX9bksAtZXEs6Yzq6QTY9y VnXDF/i/vFCG2YUDt7dkC1uifyAQxv4xjNXtOmZMWRBWD10xBe91ZYfRD1xQyfQ7pP52 SDig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=ODyU1ZFq; 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 m11si4396952pgc.224.2018.04.13.09.39.56; Fri, 13 Apr 2018 09:40:10 -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=ODyU1ZFq; 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 S1753146AbeDMQid (ORCPT + 99 others); Fri, 13 Apr 2018 12:38:33 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:43545 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752796AbeDMQib (ORCPT ); Fri, 13 Apr 2018 12:38:31 -0400 Received: by mail-qt0-f193.google.com with SMTP id s48so8630815qtb.10 for ; Fri, 13 Apr 2018 09:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gCLllH3REqUzI1sPIV3bnZhs1KmvZS77Al6RA0oTClI=; b=ODyU1ZFqHys5wMF6bQCVqa5bNNxo8v8X9QFdRWPoqCN5WUpgHdEQ+lZLJarvQ5fYUs LU1Ma/Upj8ItArmjAc11jS9p46j6Db7KWi00qsF5KrSKoZT5cKw1DwVmW87XWcJgLbfy YvffH4rKepW+MIAGzztI4kB0Xd4M6SdT8iqCNIpWAhx6yl0eYfLk5W3mswg1Iw5nS30Z UXUhZ2e9sbEoQVfSUHQeCgaxgECK2bg+gw6TJtrXdhT0/D7hmPI26cyRMRSceZkXRJh7 9hx16uyWiTK3pLXIV7RvTGi2W1uBTPWHC5YEW+QzlP+SsPInfXJdI4hwGjGHqlli8BHA mGxQ== 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:mime-version:content-transfer-encoding; bh=gCLllH3REqUzI1sPIV3bnZhs1KmvZS77Al6RA0oTClI=; b=c9LEfkYGHzgOSbq50y1wQWVSzxVuMFL6scRh3XgMyvgsTIvLmOXPStbP0Z3+XxwE/U BIj3D+o6D3tNG465tHLeM6Vte55PKOVYj9d+uW5mV5KNNf2vDbBMuC6Np/dj2qbW/fPK End239RUW1rpCK1phQwvAFO+5yQy6QvSZohtW5N1SQshZ9frjRZnHF0XuD4pi2yiHo4q MewMhwrXHT9yPGK6KhyrpUxhIRbmmCdiaCc0KbFPSbvmFsUfDbZYizWyFJcKDhZEvWQ0 kM8Mrk7bfhxd355BHCngitfmPuSOysEXQseVo2VB92fXz4YdiibboktrPpWTkeF2NVbj SKjw== X-Gm-Message-State: ALQs6tDi+uw6srttaDAlCSNQSHtsTe9i+FXsbyhKhQ4DYYgHYzbX4kn7 NsFjsMXxr3xwwP7SkWFdIb63TLsD X-Received: by 10.200.39.39 with SMTP id g36mr3668023qtg.227.1523637510750; Fri, 13 Apr 2018 09:38:30 -0700 (PDT) Received: from localhost.localdomain ([190.210.56.45]) by smtp.gmail.com with ESMTPSA id t82sm5024687qke.52.2018.04.13.09.38.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Apr 2018 09:38:30 -0700 (PDT) From: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= Subject: [PATCH v2 08/14] staging: iio: ad7746: Add dt-bindings Date: Fri, 13 Apr 2018 13:36:45 -0300 Message-Id: <1523637411-8531-9-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523637411-8531-1-git-send-email-hernan@vanguardiasur.com.ar> References: <1523637411-8531-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 | 54 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index d39ab34..c29a221 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -666,6 +666,43 @@ 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; + + 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_en = true; + pdata->excb_en = true; + pdata->exca_inv_en = of_property_read_bool(np, "adi,nexca_en"); + pdata->excb_inv_en = of_property_read_bool(np, "adi,nexcb_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) @@ -676,6 +713,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; @@ -739,12 +781,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