From patchwork Mon Jan 30 21:17:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 92937 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1770125qgi; Mon, 30 Jan 2017 21:18:39 -0800 (PST) X-Received: by 10.98.157.83 with SMTP id i80mr26975153pfd.177.1485839919723; Mon, 30 Jan 2017 21:18:39 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si13706003pld.136.2017.01.30.21.18.39; Mon, 30 Jan 2017 21:18:39 -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 sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752167AbdAaFRa (ORCPT + 25 others); Tue, 31 Jan 2017 00:17:30 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:35619 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbdAaFQk (ORCPT ); Tue, 31 Jan 2017 00:16:40 -0500 Received: by mail-pf0-f178.google.com with SMTP id f144so99469546pfa.2 for ; Mon, 30 Jan 2017 21:16:20 -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=ZjWqJRmKI97csunTlNq3KcT10987R40nPy9TMfIKE/s=; b=VCc9QHhwebS/atmTpZXUR4Q9ZS9rafXc/SFXb8fh7b1Ot+qJ9hdSyPh5JZts3WxcUj 96V5FYvsvNBvT91726nWf9dAhef7jNfT/ju2IOqa7oSE5udm1LX8/R8/Ji10/eLt+G60 4fz4hhLzZerNAG8gOxbD0QMH0hK8qhOhL/eh8= 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=ZjWqJRmKI97csunTlNq3KcT10987R40nPy9TMfIKE/s=; b=fWXgVZw8uUcaU8YhvLtWrIRdz0hlNwzP1F3gC83ch0JeI6x+RW2GDTmhQFOk/0FR4j +eJvxk7hxmE/ZF+B22KleetbPcr4WBRsMnqv6s3u8QQBlx31Cdu5MVE5+lgL58XQK4Ns 1WWTKKzEkDVrjdzqMqrM5y4J43wKjJWYm8cXknh8lZ4RRqqc0cQ8XWa82nKhvvgfDxsF 9iOdJpaF8eOqYO84uGVAajZBUqvTuPm4ZxkloQrVCC3LcxhDFZdXN1k4cOoC2hjqBSqD SJcdPFnLDiXukt6w7rTqhRYyImHLs2KkZ0CUAAr7heB43qFdhi57XxLQ/joi02sXOiyM Jdwg== X-Gm-Message-State: AIkVDXIiCamcWibAGS8COQ6FuqbtbL+JYFPSkb7ztX0nEEmYo8PiL2JEUk7lDIBo3thtxIaP X-Received: by 10.84.211.137 with SMTP id c9mr36719827pli.8.1485839780023; Mon, 30 Jan 2017 21:16:20 -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 p66sm36539437pfb.88.2017.01.30.21.16.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 21:16:18 -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 v6 4/5] iio: light: lm3533-als: Support initialization from Device Tree Date: Mon, 30 Jan 2017 13:17:18 -0800 Message-Id: <20170130211719.31017-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170130211719.31017-1-bjorn.andersson@linaro.org> References: <20170130211719.31017-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. Changes since v5: - None 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,