From patchwork Wed Jan 4 11:50:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 89904 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8647861qgi; Wed, 4 Jan 2017 11:52:08 -0800 (PST) X-Received: by 10.84.160.204 with SMTP id v12mr148912753plg.122.1483559528323; Wed, 04 Jan 2017 11:52:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z72si52789349pgd.233.2017.01.04.11.52.07; Wed, 04 Jan 2017 11:52:08 -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 S1762052AbdADTva (ORCPT + 25 others); Wed, 4 Jan 2017 14:51:30 -0500 Received: from mail-pf0-f176.google.com ([209.85.192.176]:34607 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754527AbdADTua (ORCPT ); Wed, 4 Jan 2017 14:50:30 -0500 Received: by mail-pf0-f176.google.com with SMTP id 127so3786218pfg.1 for ; Wed, 04 Jan 2017 11:50:29 -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=UYDgbeypEJEGqZ4VnNPFhPDUexPbAvrBeRyIK+RHBCk=; b=Q0sd6TrA+NvUksyStuk0LaJmMUBv8XCfaRNU9+r8cXWAr8G10oRQDEPOy7IF/mwMFr kversHQsZgzGq0XCm+vVTXZTd0JaPgcUtsc6z4Kbceg/MRx1xpW+Ns+MHbmKty74xPwg XVYSobZOJA6JS0Njs4emiN/DD1/6o3efgkSqA= 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=UYDgbeypEJEGqZ4VnNPFhPDUexPbAvrBeRyIK+RHBCk=; b=socmcfzMPBi0dcLCrfoVyFBRzYrNql2r7Ac/APPP3EVSWx+UT+8VQhIZRUhk8HRF2r aB+UXqAiXysBrnvK6fNpMkORfER8koipiFmFqiICz8h6ish8+8HZI2Lul7i1k24X7RLm sZx40JlMExXiENQzDcBgf3ZeabrSE7ehI9S5D28aIrfO+R+MQAMeovssKiEd2RXZ5/DH uASYCKF7++RFs9tG8bq8gMJtcFRgieWTxi0psccA9RD8ubxu+yd1McQiUFw5R0YRbsWF xIYzjXgdpBql3YnCFUo7RzT1t8wShx9ip+mQzTmjHRmHt0k3UBPvkOgZUsCSIv9P644x 3vtw== X-Gm-Message-State: AIkVDXI6VtLsvaH7GJyUehx2q/juJ0WcSK3DdT1S2NFeFkhHogl9BbpbThOLDCvo2JxQeIpL X-Received: by 10.84.210.228 with SMTP id a91mr150732782pli.0.1483559429327; Wed, 04 Jan 2017 11:50:29 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jan 2017 11:50:28 -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 v5 2/5] mfd: lm3533: Support initialization from Device Tree Date: Wed, 4 Jan 2017 03:50:47 -0800 Message-Id: <20170104115050.24770-2-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 driver core and probing child devices 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: - 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 drivers/mfd/lm3533-core.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) -- 2.11.0 diff --git a/drivers/mfd/lm3533-core.c b/drivers/mfd/lm3533-core.c index 5abcbb2e8849..37bcd5a0b99f 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,11 @@ static int lm3533_device_init(struct lm3533 *lm3533) lm3533_device_bl_init(lm3533); lm3533_device_led_init(lm3533); + 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 +595,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 +681,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); }