From patchwork Wed Jan 4 11:50:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 89906 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8648075qgi; Wed, 4 Jan 2017 11:52:47 -0800 (PST) X-Received: by 10.98.147.93 with SMTP id b90mr62892164pfe.170.1483559567129; Wed, 04 Jan 2017 11:52:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si73536120pla.24.2017.01.04.11.52.46; Wed, 04 Jan 2017 11:52:47 -0800 (PST) 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=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762013AbdADTv3 (ORCPT + 25 others); Wed, 4 Jan 2017 14:51:29 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33300 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759622AbdADTud (ORCPT ); Wed, 4 Jan 2017 14:50:33 -0500 Received: by mail-pg0-f49.google.com with SMTP id g1so191530244pgn.0 for ; Wed, 04 Jan 2017 11:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9VU0yIVOZ29Hy6avtTQSyQo42a/KA4+98Sc4XgCsH6c=; b=FHpoN7yiT6jEoBm/VJYZ16TX+rk0tSFKHZHMwf/W2ONJjvpswi3iBS0Eeau92FwaHr mILtttO+xUTQEcz67GaR/JUtxTRXoqYsR9Y0/g8eSoIbNUOTs5uWCi4TGWetT6ngUkS3 JiHcXbG1+sZwouJzOy0SOuKi8Ig79H456EAXk= 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=9VU0yIVOZ29Hy6avtTQSyQo42a/KA4+98Sc4XgCsH6c=; b=tbrZ/GflmHroC6jZjJaZdERirhZ7YBYNDRe5QJEkYEkfysdpk1wozOLv7UJ+xmAckb 2HNP2RmQgmM1nZqqCBvzDJ3BP6U4oF9QRyMzY+hQMZ8RgOsx4KuH6CVY3zMT/R3j0qpE aO2/otKiknkzSAAYGqfN+AsC1cs+i2PYPnYpMCQrv/FpLnGU1Nniq24xdXY6z0E5ujtc tTN8KT6VgizzTpGgM59w5vWDYsVuVui+w6N9g8DyC5isUQItBKlJl5/FkyOALuLZVC7q d5JHDSnXXPgu8Y5M44MPF8yEFYZUzlp8Dect1yNHDGYDGZf6PSuPhAL9OgLu+7CevSNT hXsQ== X-Gm-Message-State: AIkVDXI0cDHjwOwAQ+Hg8DB07LQMQc6pREikJjsounTpdNemRWX4xanaF2qfThArJ+Iyn5y+ X-Received: by 10.84.217.216 with SMTP id d24mr148444335plj.101.1483559433170; Wed, 04 Jan 2017 11:50:33 -0800 (PST) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id u64sm142701623pgc.39.2017.01.04.11.50.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 11:50:32 -0800 (PST) From: Bjorn Andersson To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Jones Subject: [PATCH v5 4/5] iio: light: lm3533-als: Support initialization from Device Tree Date: Wed, 4 Jan 2017 03:50:49 -0800 Message-Id: <20170104115050.24770-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170104115050.24770-1-bjorn.andersson@linaro.org> References: <20170104115050.24770-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bjorn Andersson Implement support for initialization of the lm3533 als driver from Device Tree. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson --- Note that this patch can be merged independently of the other patches in the series, pending approval of the DT binding. Changes since v4: - None Changes since v3: - Moved als DT parsing from mfd driver - Gave driver its own compatible drivers/iio/light/lm3533-als.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c index f409c2047c05..eef9f06eb0b1 100644 --- a/drivers/iio/light/lm3533-als.c +++ b/drivers/iio/light/lm3533-als.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -831,6 +832,32 @@ static const struct iio_info lm3533_als_info = { .read_raw = &lm3533_als_read_raw, }; +static struct lm3533_als_platform_data *lm3533_als_of_parse(struct device *dev) +{ + struct lm3533_als_platform_data *als_pdata; + struct device_node *node = dev->of_node; + int ret; + u32 val; + + als_pdata = devm_kzalloc(dev, sizeof(*als_pdata), GFP_KERNEL); + if (!als_pdata) + return NULL; + + als_pdata->pwm_mode = of_property_read_bool(node, "ti,pwm-mode"); + + ret = of_property_read_u32(node, "ti,als-resistance-ohm", &val); + if (ret < 0 && ret != -EINVAL) { + dev_err(dev, "unable to read ti,als-resistance-ohm"); + return NULL; + } + + /* Leave at high-Z, if the property was omitted or specified as 0 */ + if (!ret && val != 0) + als_pdata->r_select = 200000 / val; + + return als_pdata; +} + static int lm3533_als_probe(struct platform_device *pdev) { struct lm3533 *lm3533; @@ -843,7 +870,11 @@ static int lm3533_als_probe(struct platform_device *pdev) if (!lm3533) return -EINVAL; - pdata = pdev->dev.platform_data; + if (pdev->dev.of_node) + pdata = lm3533_als_of_parse(&pdev->dev); + else + pdata = pdev->dev.platform_data; + if (!pdata) { dev_err(&pdev->dev, "no platform data\n"); return -EINVAL; @@ -914,9 +945,16 @@ static int lm3533_als_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id lm3533_als_of_match[] = { + { .compatible = "ti,lm3533-als", }, + { }, +}; +MODULE_DEVICE_TABLE(of, lm3533_als_of_match); + static struct platform_driver lm3533_als_driver = { .driver = { .name = "lm3533-als", + .of_match_table = lm3533_als_of_match, }, .probe = lm3533_als_probe, .remove = lm3533_als_remove,