From: Pavel Machek <pavel@ucw.cz>
To: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Lee Jones <lee.jones@linaro.org>,
Jingoo Han <jingoohan1@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Richard Purdie <rpurdie@rpsys.net>,
Jacek Anaszewski <j.anaszewski@samsung.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org, linux-leds@vger.kernel.org,
Bjorn Andersson <bjorn.andersson@sonymobile.com>
Subject: Re: [PATCH v4 3/5] backlight: lm3533: Support initialization from Device Tree
Date: Tue, 27 Dec 2016 11:49:15 +0100 [thread overview]
Message-ID: <20161227104915.GC15452@amd> (raw)
In-Reply-To: <20161226181153.11271-3-bjorn.andersson@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 5603 bytes --]
On Mon 2016-12-26 10:11:51, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@sonymobile.com>
>
> Implement support for initialization of the lm3533 backlight from Device
> Tree.
>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Bjorn, you may want to fix your email system:
<bjorn.andersson@sonymobile.com>: host
seldsegrel01.sonyericsson.com[37.139.156.29] said: 550 Rule
imposed mailbox
access for this user is refused: user invalid (in reply to
RCPT TO command)
Pavel
> ---
>
> 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(-)
>
> 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,
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2016-12-27 10:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-26 18:11 [PATCH v4 1/5] devicetree: mfd: Add binding for the TI LM3533 Bjorn Andersson
2016-12-26 18:11 ` [PATCH v4 2/5] mfd: lm3533: Support initialization from Device Tree Bjorn Andersson
[not found] ` <20161226181153.11271-2-bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-01-04 11:54 ` Lee Jones
2017-01-04 19:26 ` Bjorn Andersson
2017-01-05 7:49 ` Lee Jones
2017-01-05 16:30 ` Bjorn Andersson
2017-01-06 9:53 ` Lee Jones
2017-01-06 18:54 ` Bjorn Andersson
2017-01-09 8:36 ` Lee Jones
2017-01-11 19:55 ` Bjorn Andersson
2016-12-26 18:11 ` [PATCH v4 3/5] backlight: " Bjorn Andersson
[not found] ` <20161226181153.11271-3-bjorn.andersson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-12-27 10:46 ` Pavel Machek
2016-12-27 18:23 ` Jingoo Han
2016-12-27 10:49 ` Pavel Machek [this message]
2016-12-30 19:50 ` [PATCH v4 1/5] devicetree: mfd: Add binding for the TI LM3533 Jonathan Cameron
2017-01-03 16:56 ` Rob Herring
2017-01-04 11:54 ` Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161227104915.GC15452@amd \
--to=pavel@ucw.cz \
--cc=bjorn.andersson@linaro.org \
--cc=bjorn.andersson@sonymobile.com \
--cc=devicetree@vger.kernel.org \
--cc=j.anaszewski@samsung.com \
--cc=jic23@kernel.org \
--cc=jingoohan1@gmail.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=lee.jones@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=rpurdie@rpsys.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).