From patchwork Mon Jan 30 21:17:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 92939 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1770245qgi; Mon, 30 Jan 2017 21:19:13 -0800 (PST) X-Received: by 10.84.130.99 with SMTP id 90mr37025127plc.167.1485839953479; Mon, 30 Jan 2017 21:19:13 -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.13; Mon, 30 Jan 2017 21:19:13 -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 S1752061AbdAaFR2 (ORCPT + 25 others); Tue, 31 Jan 2017 00:17:28 -0500 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33907 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751388AbdAaFQk (ORCPT ); Tue, 31 Jan 2017 00:16:40 -0500 Received: by mail-pf0-f176.google.com with SMTP id e4so99103970pfg.1 for ; Mon, 30 Jan 2017 21:16:22 -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=ECuZmmpgcM/FgKxC8Ru3LG+qtAzvB5kie4yUheomvJs=; b=OXCr/LiKKA1YvV34dt3dz8oRb+eyzkd1YCoZuSX13ALM7gCIkqmuD9MQroDg14UR1b PceAvMuCGSM9/yWYQ0ZegrvnLOywpModdcEiztG1wXTLf45CSe54JICQ4oUKQLE+OXxC MdfRikY9fXzchvFNh+zUNRSTaqm+xmMeWGmow= 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=ECuZmmpgcM/FgKxC8Ru3LG+qtAzvB5kie4yUheomvJs=; b=aMM6igBLkBp0RJC6kP+r64JAsqGtsMvaZOSXAYcDBTLXEQY9IcWN7GkWlTd1SwheIS 3IsX/l8JuAktMLkjb0iT42lWAyuig4QhWzOEI3/2gvcY/6ZwvNHVVBssCID75KebuShB wGjWb+NlMd+9SoKKYZ1+Sn8dK4FTdH0SPclaKmiPCTpamgyh4YW/a2riKWiHJykmh6Ro 6e2mPNF2xEm30IbOEe5DbLruZ676gYbWbEIoEKbPrJcLCuTdKnfZWP5UhW9shlaWzYNO f2e8uLSKi/NbOtUxUQuYANy8Q9X8uX3b8dqvGmU1oRHHJ7tTMkJzxDt68Tft4IAcBAMZ L3Ug== X-Gm-Message-State: AIkVDXLfM1ub3j/KH7KCfnYyW1C7YX5doi94YYt6lm3PVUJqZk9Np/SPRS/mUyVf6Af77tM/ X-Received: by 10.98.13.18 with SMTP id v18mr27279571pfi.62.1485839781930; Mon, 30 Jan 2017 21:16:21 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 21:16:20 -0800 (PST) From: Bjorn Andersson To: Richard Purdie , Pavel Machek Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, Lee Jones Subject: [PATCH v6 5/5] leds: lm3533: Support initialization from Device Tree Date: Mon, 30 Jan 2017 13:17:19 -0800 Message-Id: <20170130211719.31017-5-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 LED 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 LED DT parsing from mfd driver - Gave driver its own compatible drivers/leds/leds-lm3533.c | 98 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/leds/leds-lm3533.c b/drivers/leds/leds-lm3533.c index 5b529dc013d2..3eedad0ea9df 100644 --- a/drivers/leds/leds-lm3533.c +++ b/drivers/leds/leds-lm3533.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -648,12 +649,92 @@ static int lm3533_led_setup(struct lm3533_led *led, return lm3533_ctrlbank_set_pwm(&led->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_led_platform_data *lm3533_led_of_parse(struct device *dev, + int *id) +{ + struct lm3533_led_platform_data *led_pdata; + struct device_node *node = dev->of_node; + int ret; + u32 reg; + u32 val; + + led_pdata = devm_kzalloc(dev, sizeof(*led_pdata), GFP_KERNEL); + if (!led_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 **)&led_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; + } + led_pdata->max_current = val; + + ret = of_property_read_string(node, "linux,default-trigger", + &led_pdata->default_trigger); + if (ret < 0 && ret != -EINVAL) { + dev_err(dev, "unable to parse default-trigger\n"); + return NULL; + } + + ret = lm3533_of_parse_pwm_zones(node); + if (ret < 0) { + dev_err(dev, "failed to parse ti,pwm-zones\n"); + return NULL; + } + led_pdata->pwm = ret; + + return led_pdata; +} + static int lm3533_led_probe(struct platform_device *pdev) { struct lm3533 *lm3533; struct lm3533_led_platform_data *pdata; struct lm3533_led *led; int ret; + int id; dev_dbg(&pdev->dev, "%s\n", __func__); @@ -661,14 +742,18 @@ static int lm3533_led_probe(struct platform_device *pdev) if (!lm3533) return -EINVAL; + id = pdev->id; pdata = dev_get_platdata(&pdev->dev); + if (!pdata) + pdata = lm3533_led_of_parse(&pdev->dev, &id); + if (!pdata) { dev_err(&pdev->dev, "no platform data\n"); return -EINVAL; } - if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) { - dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id); + if (id < 0 || id >= LM3533_LVCTRLBANK_COUNT) { + dev_err(&pdev->dev, "illegal LED id %d\n", id); return -EINVAL; } @@ -684,7 +769,7 @@ static int lm3533_led_probe(struct platform_device *pdev) led->cdev.blink_set = lm3533_led_blink_set; led->cdev.brightness = LED_OFF; led->cdev.groups = lm3533_led_attribute_groups, - led->id = pdev->id; + led->id = id; mutex_init(&led->mutex); @@ -739,9 +824,16 @@ static void lm3533_led_shutdown(struct platform_device *pdev) lm3533_led_set(&led->cdev, LED_OFF); /* disable blink */ } +static const struct of_device_id lm3533_led_of_match[] = { + { .compatible = "ti,lm3533-led", }, + { }, +}; +MODULE_DEVICE_TABLE(of, lm3533_led_of_match); + static struct platform_driver lm3533_led_driver = { .driver = { .name = "lm3533-leds", + .of_match_table = lm3533_led_of_match, }, .probe = lm3533_led_probe, .remove = lm3533_led_remove,