From patchwork Tue Apr 23 11:52:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 16349 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f199.google.com (mail-gg0-f199.google.com [209.85.161.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 49F002391B for ; Tue, 23 Apr 2013 11:54:03 +0000 (UTC) Received: by mail-gg0-f199.google.com with SMTP id v2sf813886ggc.2 for ; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-beenthere:x-received:received-spf:x-received :x-forwarded-to:x-forwarded-for:delivered-to:x-received:received-spf :from:to:cc:subject:date:message-id:x-mailer:mime-version :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe :content-type; bh=H+ymKkUsWHHWHhbxuMUboD2xxVjmdPMMuJr+zqmu72k=; b=JZTPagbhtup5yNZebP9DhCxmB1xUvFVRuaPTquXlhForiPfFgYX5FBVX+NVH2f9WKE uu9pNLUFmr1cMAhsdBm/r8GUPmeb5/oDONi2LreMO1AncIV/OAu2dhcpY9RuwzEZrNmu vUKQ7nYqklGYmK9Ou7h7lxxSGs8SS4r0/WVpzH11xQJTj6EPke/1ZXHZzb4b2LZPYVxH oCt9NDPmMyHA/lMam0p8V9KfNg70onbhrAlaG38495fbn+k+29AeTQPYLiXnpO2aC+JO IgLY1pBbJPbveTs0Ny7bugRC2QfMWYxD8QktavTBGwOtYkh5Mr82k758owEkyTfD8XZ8 YtZQ== X-Received: by 10.236.111.106 with SMTP id v70mr15205015yhg.34.1366717994456; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.96.2 with SMTP id do2ls265614qeb.62.gmail; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) X-Received: by 10.220.151.203 with SMTP id d11mr22280854vcw.9.1366717994277; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) Received: from mail-vb0-x229.google.com (mail-vb0-x229.google.com [2607:f8b0:400c:c02::229]) by mx.google.com with ESMTPS id ha8si9967083vdb.113.2013.04.23.04.53.14 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 23 Apr 2013 04:53:14 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::229; Received: by mail-vb0-f41.google.com with SMTP id f13so485172vbg.0 for ; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) X-Received: by 10.58.188.48 with SMTP id fx16mr22070592vec.22.1366717994077; Tue, 23 Apr 2013 04:53:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp121025veb; Tue, 23 Apr 2013 04:53:13 -0700 (PDT) X-Received: by 10.15.22.199 with SMTP id f47mr50713266eeu.11.1366717992701; Tue, 23 Apr 2013 04:53:12 -0700 (PDT) Received: from eu1sys200aog114.obsmtp.com (eu1sys200aog114.obsmtp.com [207.126.144.137]) by mx.google.com with SMTP id b4si45141055eef.210.2013.04.23.04.53.07 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 23 Apr 2013 04:53:12 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.137 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.137; Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob114.postini.com ([207.126.147.11]) with SMTP ID DSNKUXZ2I33zFOtKXE9S9kiozZjNN5xedTT1@postini.com; Tue, 23 Apr 2013 11:53:12 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 842C5188; Tue, 23 Apr 2013 11:53:06 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 34E294D27; Tue, 23 Apr 2013 11:53:00 +0000 (GMT) Received: from exdcvycastm004.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm004", Issuer "exdcvycastm004" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id C6C75A8065; Tue, 23 Apr 2013 13:53:00 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.2) with Microsoft SMTP Server (TLS) id 8.3.279.5; Tue, 23 Apr 2013 13:53:05 +0200 From: Linus Walleij To: Bryan Wu , Richard Purdie Cc: , Linus Walleij , Gabriel Fernandez Subject: [PATCH] leds: lp55xx: add support for Device Tree bindings Date: Tue, 23 Apr 2013 13:52:59 +0200 Message-ID: <1366717979-27864-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn/Wg6EP4u1l5P8QohDimoImjNCD0aXhPAzdHoOAKEGANT9Y5tKOK9qzIE/5Z9obDS3wZks X-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::229 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Linus Walleij This patch allows the lp5521 driver to be successfully probed and initialised when Device Tree support is enabled. Based on a patch by Gabriel Fernandez, rewritten in accordance with review feedback. Cc: Gabriel Fernandez Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Move DT parsing into the lp55xx-common code. - Implement probing for lp5523 as well. - Handle errors from all of_property_read* functions. - Rename num-chanel to num-channel - Prefix all compatible strings with "national,*" like "national,lp5521", a bit uncertain about this but seems like the right thing to do. - Since I have now written more than half the patch I have set myself as author so as not to blame Gabriel for all my mistakes. --- .../devicetree/bindings/leds/leds-lp55xx.txt | 21 +++++++++ drivers/leds/leds-lp5521.c | 20 ++++++-- drivers/leds/leds-lp5523.c | 19 ++++++-- drivers/leds/leds-lp55xx-common.c | 54 ++++++++++++++++++++++ drivers/leds/leds-lp55xx-common.h | 4 ++ 5 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/leds-lp55xx.txt diff --git a/Documentation/devicetree/bindings/leds/leds-lp55xx.txt b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt new file mode 100644 index 0000000..348c88e --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt @@ -0,0 +1,21 @@ +Binding for National Semiconductor LP55xx Led Drivers + +Required properties: +- compatible: "national,lp5521" or "national,lp5523" +- label: Used for naming LEDs +- num-channel: Number of LED channels +- led-cur: Current setting at each led channel (mA x10, 0 if led is not connected) +- max-cur: Maximun current at each led channel. +- clock-mode: Input clock mode, (0: automode, 1: internal, 2: external) + +example: + +lp5521@32 { + compatible = "national,lp5521"; + reg = <0x32>; + label = "lp5521_pri"; + num-channel = /bits/ 8 <3>; + led-cur = /bits/ 8 <0x2f 0x2f 0x2f>; + max-cur = /bits/ 8 <0x5f 0x5f 0x5f>; + clock-mode = /bits/8 <2>; +}; diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index 1001347..f3c15f7 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "leds-lp55xx-common.h" @@ -400,12 +401,20 @@ static int lp5521_probe(struct i2c_client *client, int ret; struct lp55xx_chip *chip; struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = client->dev.platform_data; - - if (!pdata) { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; + struct lp55xx_platform_data *pdata; + struct device_node *np = client->dev.of_node; + + if (!client->dev.platform_data) { + if (np) { + ret = lp55xx_of_populate_pdata(&client->dev, np); + if (ret < 0) + return ret; + } else { + dev_err(&client->dev, "no platform data\n"); + return -EINVAL; + } } + pdata = client->dev.platform_data; chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) @@ -465,6 +474,7 @@ static int lp5521_remove(struct i2c_client *client) static const struct i2c_device_id lp5521_id[] = { { "lp5521", 0 }, /* Three channel chip */ + { "national,lp5521", 0 }, /* OF compatible */ { } }; MODULE_DEVICE_TABLE(i2c, lp5521_id); diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 229f734..365e914 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -429,12 +429,20 @@ static int lp5523_probe(struct i2c_client *client, int ret; struct lp55xx_chip *chip; struct lp55xx_led *led; - struct lp55xx_platform_data *pdata = client->dev.platform_data; - - if (!pdata) { - dev_err(&client->dev, "no platform data\n"); - return -EINVAL; + struct lp55xx_platform_data *pdata; + struct device_node *np = client->dev.of_node; + + if (!client->dev.platform_data) { + if (np) { + ret = lp55xx_of_populate_pdata(&client->dev, np); + if (ret < 0) + return ret; + } else { + dev_err(&client->dev, "no platform data\n"); + return -EINVAL; + } } + pdata = client->dev.platform_data; chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip) @@ -495,6 +503,7 @@ static int lp5523_remove(struct i2c_client *client) static const struct i2c_device_id lp5523_id[] = { { "lp5523", LP5523 }, { "lp55231", LP55231 }, + { "national,lp5523", 0 }, /* OF compatible */ { } }; diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index d9eb841..086ce08 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "leds-lp55xx-common.h" @@ -518,6 +519,59 @@ void lp55xx_unregister_sysfs(struct lp55xx_chip *chip) } EXPORT_SYMBOL_GPL(lp55xx_unregister_sysfs); +int lp55xx_of_populate_pdata(struct device *dev, struct device_node *np) +{ + struct lp55xx_platform_data *pdata; + u8 led_cur[3]; + u8 max_cur[3]; + u8 clock_mode; + u8 num_channel; + const char *label; + struct lp55xx_led_config *led_config; + int ret; + int i; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + ret = of_property_read_u8(np, "num-channel", &num_channel); + if (ret < 0) + return ret; + ret = of_property_read_u8_array(np, "led-cur", led_cur, num_channel); + if (ret < 0) + return ret; + ret = of_property_read_u8_array(np, "max-cur", max_cur, num_channel); + if (ret < 0) + return ret; + ret = of_property_read_string(np, "label", &label); + if (ret < 0) + return ret; + ret = of_property_read_u8_array(np, "clock-mode", &clock_mode, 1); + if (ret < 0) + return ret; + + led_config = devm_kzalloc(dev, sizeof(*led_config) * num_channel, + GFP_KERNEL); + if (!led_config) + return -ENOMEM; + + for (i = 0; i < num_channel; i++) { + led_config[i].chan_nr = i; + led_config[i].led_current = led_cur[i]; + led_config[i].max_current = max_cur[i]; + } + pdata->label = kzalloc(sizeof(char) * 32, GFP_KERNEL); + strcpy((char *)pdata->label, (char *) label); + pdata->led_config = &led_config[0]; + pdata->num_channels = num_channel; + pdata->clock_mode = clock_mode; + dev->platform_data = pdata; + + return 0; +} +EXPORT_SYMBOL_GPL(lp55xx_of_populate_pdata); + MODULE_AUTHOR("Milo Kim "); MODULE_DESCRIPTION("LP55xx Common Driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h index ece4761..0708083 100644 --- a/drivers/leds/leds-lp55xx-common.h +++ b/drivers/leds/leds-lp55xx-common.h @@ -131,4 +131,8 @@ extern void lp55xx_unregister_leds(struct lp55xx_led *led, extern int lp55xx_register_sysfs(struct lp55xx_chip *chip); extern void lp55xx_unregister_sysfs(struct lp55xx_chip *chip); +/* common device tree population function */ +extern int lp55xx_of_populate_pdata(struct device *dev, + struct device_node *np); + #endif /* _LEDS_LP55XX_COMMON_H */