From patchwork Mon Dec 26 18:11:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 89049 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp4784196qgi; Mon, 26 Dec 2016 18:12:24 -0800 (PST) X-Received: by 10.99.43.8 with SMTP id r8mr54268142pgr.83.1482804744841; Mon, 26 Dec 2016 18:12:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si44764036pgp.204.2016.12.26.18.12.24; Mon, 26 Dec 2016 18:12:24 -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 S1756583AbcL0CL5 (ORCPT + 25 others); Mon, 26 Dec 2016 21:11:57 -0500 Received: from mail-pg0-f53.google.com ([74.125.83.53]:36641 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756502AbcL0CLv (ORCPT ); Mon, 26 Dec 2016 21:11:51 -0500 Received: by mail-pg0-f53.google.com with SMTP id f188so139479561pgc.3 for ; Mon, 26 Dec 2016 18:11:51 -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=boMw9f1pZuB25GvfYvdxmnMAtYJ5YG+SBcPMbd/6w4k=; b=O3Qc9rwowKIRnpTNPpJkRd40K6wOUyjbfImeMsqR7YqCKpxQAIsbebxCmIvRqfvRNv sSOeXpcPJuHZHOfAfo1n7LSaFttCmSB9t5Ms/RFG/HeUvkvWve3rwzi6dGCbL0RyV3Ve 0zvjFQAoCK/tsiafoK8EHVLeDklygBMudxWUY= 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=boMw9f1pZuB25GvfYvdxmnMAtYJ5YG+SBcPMbd/6w4k=; b=i7C+twEKITjLA8Jj7H7zkPseHqZOmZwJohhtPQvWQ93HIni81PMthST24eQ2cvV4zp UNO5X3be7FXgUvcCegmJ1LjwPTEJW4qYHSEXnZfDHuKywfGU0l/T+05EH6nKo7TUkCY7 ZofL+xveKI9CAw8dgsjP6zQmkaayHPZTahPb0IMSY2Yv53HQWlau5vKCRZPLnWmQX1Hd a1/cnqlVi+lxVsycjexeXsqJgBzJi/sGiKh01dBSrBIf7lETnJMC2SrVj/LJo/mN/V38 itKYZkssFROmKiy9Nb9i2zByAA88KcviwKB2mrNT2fCjWLEDubKFjBtXcw1xBIiS4eUV COpA== X-Gm-Message-State: AIkVDXIWCZIqMgy9nw3ku2Be7Eqv6XEmJXl5kQVcdSTTXMX4hpWfWL8OvlwikFCPp/AmKVXC X-Received: by 10.84.225.130 with SMTP id u2mr37348128plj.39.1482804710776; Mon, 26 Dec 2016 18:11:50 -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 g82sm84886867pfb.43.2016.12.26.18.11.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Dec 2016 18:11:49 -0800 (PST) From: Bjorn Andersson To: Lee Jones , Jingoo Han Cc: Rob Herring , Mark Rutland , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Richard Purdie , Jacek Anaszewski , Pavel Machek , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-leds@vger.kernel.org, Bjorn Andersson Subject: [PATCH v4 3/5] backlight: lm3533: Support initialization from Device Tree Date: Mon, 26 Dec 2016 10:11:51 -0800 Message-Id: <20161226181153.11271-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161226181153.11271-1-bjorn.andersson@linaro.org> References: <20161226181153.11271-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 backlight from Device Tree. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson --- This patch only depends on the acceptance of the DT binding (doesn't have to be merged together with the mfd patch). Changes since v3: - Moved backlight DT parsing from mfd driver - Gave driver its own compatible drivers/video/backlight/lm3533_bl.c | 98 +++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c index 0e2337f367b6..2f132199e604 100644 --- a/drivers/video/backlight/lm3533_bl.c +++ b/drivers/video/backlight/lm3533_bl.c @@ -22,6 +22,7 @@ #define LM3533_HVCTRLBANK_COUNT 2 +#define LM3533_BL_DEFAULT_BRIGHTNESS 200 #define LM3533_BL_MAX_BRIGHTNESS 255 #define LM3533_REG_CTRLBANK_AB_BCONF 0x1a @@ -269,6 +270,86 @@ static int lm3533_bl_setup(struct lm3533_bl *bl, return lm3533_ctrlbank_set_pwm(&bl->cb, pdata->pwm); } +static int lm3533_of_parse_pwm_zones(struct device_node *node) +{ + const char *propname = "ti,pwm-zones"; + u32 zones[5]; + int count; + int ret; + int i; + + count = of_property_count_u32_elems(node, propname); + if (count == -EINVAL) + return 0; + if (count <= 0) + return count; + if (count >= ARRAY_SIZE(zones)) + return -EINVAL; + + ret = of_property_read_u32_array(node, propname, zones, count); + if (ret < 0) + return ret; + + /* Enable pwm input, and enable the selected zones */ + ret = BIT(0); + for (i = 0; i < count; i++) + ret |= BIT(zones[i] + 1); + + return ret; +} + +static struct lm3533_bl_platform_data *lm3533_bl_of_parse(struct device *dev, + int *id) +{ + struct lm3533_bl_platform_data *bl_pdata; + struct device_node *node = dev->of_node; + int ret; + u32 reg; + u32 val; + + bl_pdata = devm_kzalloc(dev, sizeof(*bl_pdata), GFP_KERNEL); + if (!bl_pdata) + return NULL; + + ret = of_property_read_u32(node, "reg", ®); + if (ret < 0) { + dev_err(dev, "invalid reg property\n"); + return NULL; + } + *id = reg; + + ret = of_property_read_string(node, "label", + (const char **)&bl_pdata->name); + if (ret < 0) { + dev_err(dev, "unable to parse label\n"); + return NULL; + } + + ret = of_property_read_u32(node, "led-max-microamp", &val); + if (ret < 0) { + dev_err(dev, "unable to parse led-max-microamp\n"); + return NULL; + } + bl_pdata->max_current = val; + + val = LM3533_BL_DEFAULT_BRIGHTNESS; + ret = of_property_read_u32(node, "default-brightness", &val); + if (ret < 0 && ret != -EINVAL) { + dev_err(dev, "unable to parse default-brightness\n"); + return NULL; + } + bl_pdata->default_brightness = val; + + ret = lm3533_of_parse_pwm_zones(node); + if (ret < 0) { + dev_err(dev, "failed to parse ti,pwm-zones\n"); + return NULL; + } + bl_pdata->pwm = ret; + + return bl_pdata; +} + static int lm3533_bl_probe(struct platform_device *pdev) { struct lm3533 *lm3533; @@ -277,6 +358,7 @@ static int lm3533_bl_probe(struct platform_device *pdev) struct backlight_device *bd; struct backlight_properties props; int ret; + int id; dev_dbg(&pdev->dev, "%s\n", __func__); @@ -284,14 +366,17 @@ static int lm3533_bl_probe(struct platform_device *pdev) if (!lm3533) return -EINVAL; + id = pdev->id; pdata = dev_get_platdata(&pdev->dev); + if (!pdata) + pdata = lm3533_bl_of_parse(&pdev->dev, &id); if (!pdata) { dev_err(&pdev->dev, "no platform data\n"); return -EINVAL; } - if (pdev->id < 0 || pdev->id >= LM3533_HVCTRLBANK_COUNT) { - dev_err(&pdev->dev, "illegal backlight id %d\n", pdev->id); + if (id < 0 || id >= LM3533_HVCTRLBANK_COUNT) { + dev_err(&pdev->dev, "illegal backlight id %d\n", id); return -EINVAL; } @@ -300,7 +385,7 @@ static int lm3533_bl_probe(struct platform_device *pdev) return -ENOMEM; bl->lm3533 = lm3533; - bl->id = pdev->id; + bl->id = id; bl->cb.lm3533 = lm3533; bl->cb.id = lm3533_bl_get_ctrlbank_id(bl); @@ -394,10 +479,17 @@ static void lm3533_bl_shutdown(struct platform_device *pdev) lm3533_ctrlbank_disable(&bl->cb); } +static const struct of_device_id lm3533_bl_of_match[] = { + { .compatible = "ti,lm3533-backlight", }, + { }, +}; +MODULE_DEVICE_TABLE(of, lm3533_bl_of_match); + static struct platform_driver lm3533_bl_driver = { .driver = { .name = "lm3533-backlight", .pm = &lm3533_bl_pm_ops, + .of_match_table = lm3533_bl_of_match, }, .probe = lm3533_bl_probe, .remove = lm3533_bl_remove,