From patchwork Mon Jan 30 21:17:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 92940 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1770255qgi; Mon, 30 Jan 2017 21:19:16 -0800 (PST) X-Received: by 10.84.210.232 with SMTP id a95mr36848009pli.31.1485839956768; Mon, 30 Jan 2017 21:19:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21si10301634pgj.268.2017.01.30.21.19.16; Mon, 30 Jan 2017 21:19:16 -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 S1751999AbdAaFR2 (ORCPT + 25 others); Tue, 31 Jan 2017 00:17:28 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33048 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751120AbdAaFQk (ORCPT ); Tue, 31 Jan 2017 00:16:40 -0500 Received: by mail-pf0-f175.google.com with SMTP id y143so99474126pfb.0 for ; Mon, 30 Jan 2017 21:16:14 -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=6EPXRnNeIw1tmWqO4nItfg+5gdJUY+DKPsWuAZQ3r08=; b=Zadv4IgK1K/ZKsm30U6w2skT33ucd6qzhjzMiOwXf2fybJa3oEC06KwLhCYmrIq8sh sth9OWNk5HyyyNI6rUM8lXHcmpYQCNQe5XoNXrKFDyor2/OYVpNpfokjIMLrMm0e3S3b CnwEoJUDQS7a12pu/MSx/YXjnrIqPQZakVtSE= 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=6EPXRnNeIw1tmWqO4nItfg+5gdJUY+DKPsWuAZQ3r08=; b=IpeCDDs/NdusCt96xqKShEcrRPW49NZIHUfQMUokX3/1xyXce9QEGfSLyvv/f0Q07o GpVJ1LzKMDpOsehf0EPJpce7j+mmqubSttLCPZMhMevq09pAhMan41hhfHhSjitzQsDn tN8QefVeSmt17G4j66r6hci2XocOkS3ktNgqpFvjqiNor7eQLZn3s6R8OZF27itVW0mz qK/4aMf2/s/WOg3xo4bVD5Qcga7vTMcZiA6BaPIl1nTN8Hi6A8ZPbMIpjz1B6e3nWoTB KLaViEikzX23UVbhge8dR9KmpHWv5vCNoJobXMGrAobZBqUKQ16RpvejqOItIgGh4IEt E1sw== X-Gm-Message-State: AIkVDXIHpTHMWqd4PWvWv9aimO1gipCW9HQfGHAGu1MT1NpYI5ONBEOR16DDYpabJLdbZAs2 X-Received: by 10.84.162.204 with SMTP id o12mr37080071plg.132.1485839774125; Mon, 30 Jan 2017 21:16:14 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 21:16:12 -0800 (PST) From: Bjorn Andersson To: Lee Jones Cc: Rob Herring , Mark Rutland , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Richard Purdie , Pavel Machek , Jingoo Han , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org Subject: [PATCH v6 2/5] mfd: lm3533: Support initialization from Device Tree Date: Mon, 30 Jan 2017 13:17:16 -0800 Message-Id: <20170130211719.31017-2-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 driver core and probing child devices from Device Tree. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson --- drivers/mfd/lm3533-core.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) Note that this patch can be merged independently of the other patches in the series. Changes since v5: - Added comment re of_platform_populate() Changes since v4: - Moved of_node check into lm3533_pdata_from_of_node() Changes since v3: - Moved parsing of child of nodes into each child driver - Use of_platform_populate() to instanciate child devices -- 2.11.0 diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c index 5abcbb2e8849..89c79328c78e 100644 --- a/drivers/mfd/lm3533-core.c +++ b/drivers/mfd/lm3533-core.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -512,6 +514,16 @@ static int lm3533_device_init(struct lm3533 *lm3533) lm3533_device_bl_init(lm3533); lm3533_device_led_init(lm3533); + /* + * Check of_node as of_platform_populate treats NULL as the root node, + * which would cause side effects in certain unlikely DT/non-DT hybrid + * solutions. + */ + if (lm3533->dev->of_node) { + of_platform_populate(lm3533->dev->of_node, NULL, NULL, + lm3533->dev); + } + ret = sysfs_create_group(&lm3533->dev->kobj, &lm3533_attribute_group); if (ret < 0) { dev_err(lm3533->dev, "failed to create sysfs attributes\n"); @@ -588,10 +600,76 @@ static const struct regmap_config regmap_config = { .precious_reg = lm3533_precious_register, }; +static int lm3533_of_parse_enum(struct device *dev, const char *propname, + const unsigned int *match, size_t num_matches) +{ + size_t i; + int ret; + u32 val; + + ret = of_property_read_u32(dev->of_node, propname, &val); + if (ret < 0) { + dev_err(dev, "failed to parse %s\n", propname); + return ret; + } + + for (i = 0; i < num_matches; i++) { + if (val == match[i]) + return i; + } + + dev_err(dev, "unsupported value of %s\n", propname); + return -EINVAL; +} + +static int lm3533_pdata_from_of_node(struct device *dev) +{ + struct lm3533_platform_data *pdata; + int ret; + const unsigned int freqs[] = { + [LM3533_BOOST_FREQ_500KHZ] = 500000, + [LM3533_BOOST_FREQ_1000KHZ] = 1000000, + }; + const unsigned int ovps[] = { + [LM3533_BOOST_OVP_16V] = 16000, + [LM3533_BOOST_OVP_24V] = 24000, + [LM3533_BOOST_OVP_32V] = 32000, + [LM3533_BOOST_OVP_40V] = 40000, + }; + + if (!dev->of_node) + return 0; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + pdata->gpio_hwen = of_get_named_gpio(dev->of_node, "hwen-gpios", 0); + if (pdata->gpio_hwen < 0) + return pdata->gpio_hwen; + + ret = lm3533_of_parse_enum(dev, "ti,boost-freq-hz", + freqs, ARRAY_SIZE(freqs)); + if (ret < 0) + return ret; + pdata->boost_freq = ret; + + ret = lm3533_of_parse_enum(dev, "ti,boost-ovp-mv", + ovps, ARRAY_SIZE(ovps)); + if (ret < 0) + return ret; + pdata->boost_ovp = ret; + + dev->platform_data = pdata; + + return 0; +} + static int lm3533_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct lm3533 *lm3533; + int ret; dev_dbg(&i2c->dev, "%s\n", __func__); @@ -608,6 +686,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c, lm3533->dev = &i2c->dev; lm3533->irq = i2c->irq; + ret = lm3533_pdata_from_of_node(lm3533->dev); + if (ret < 0) + return ret; + return lm3533_device_init(lm3533); }