From patchwork Mon Apr 15 19:46:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 16137 Return-Path: X-Original-To: linaro@staging.patches.linaro.org Delivered-To: linaro@staging.patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 617B92395C for ; Mon, 15 Apr 2013 19:47:41 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id 14sf2445480vea.9 for ; Mon, 15 Apr 2013 12:47:10 -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=1CpYe5gzH+DmPZSlvx/M/SVA0G5JJLvX2Z+am8Gegr4=; b=ET7D2m4NsnGbGqOR7zNihjeQSvsq5BCqYv9YHVCDSPkeMgaIqg714AqlBdI7hxgxgj HAKxAXOU0RMPTZmwW/dEUNAM2LG3c1RGoPk9fepuDBLJ8jCDKzARm/tpeoeTf1U+AdXx o0UBlF7LNzi0u+uM20WLtGC5oal5dujFa4yCvE05OspBONRgb1Ot04+1PqM21RFd/m9q i8YI4fBlX1Nw4ooKwIe7cKXMOMj5JJCKM9WPYDFhO+Bx+czjJB5kGR8wBbcD8REu4DMe rrMoyNlQbx8p+Q9ZUtUpK/pSeQTIGvr1cQ1lUVN85ei95IJ4RpPvnxgsw+w5Y7zLx31Z LeHw== X-Received: by 10.236.47.136 with SMTP id t8mr11638741yhb.13.1366055229865; Mon, 15 Apr 2013 12:47:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.78 with SMTP id b14ls1016127qen.18.gmail; Mon, 15 Apr 2013 12:47:09 -0700 (PDT) X-Received: by 10.220.168.202 with SMTP id v10mr17040696vcy.71.1366055229708; Mon, 15 Apr 2013 12:47:09 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id ez9si9521616vdb.29.2013.04.15.12.47.09 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Apr 2013 12:47:09 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hx10so4347415vcb.0 for ; Mon, 15 Apr 2013 12:47:09 -0700 (PDT) X-Received: by 10.58.188.48 with SMTP id fx16mr10229269vec.22.1366055229296; Mon, 15 Apr 2013 12:47:09 -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 nf2csp196568veb; Mon, 15 Apr 2013 12:47:08 -0700 (PDT) X-Received: by 10.194.176.228 with SMTP id cl4mr34815377wjc.10.1366055228016; Mon, 15 Apr 2013 12:47:08 -0700 (PDT) Received: from eu1sys200aog121.obsmtp.com (eu1sys200aog121.obsmtp.com [207.126.144.151]) by mx.google.com with SMTP id e45si30936610eep.228.2013.04.15.12.47.01 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 15 Apr 2013 12:47:08 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.151 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.151; Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob121.postini.com ([207.126.147.11]) with SMTP ID DSNKUWxZNd9KTYUqLz9qAw5DifTeb707Fm+R@postini.com; Mon, 15 Apr 2013 19:47:07 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 C1BA9CF; Mon, 15 Apr 2013 19:46:58 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 97DEFA4AD; Mon, 15 Apr 2013 19:46:54 +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 relay1.stm.gmessaging.net (Postfix) with ESMTPS id 219A824C07D; Mon, 15 Apr 2013 21:46:48 +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; Mon, 15 Apr 2013 21:46:58 +0200 From: Linus Walleij To: Bryan Wu , Richard Purdie Cc: , Gabriel Fernandez , Linus Walleij Subject: [PATCH] leds: lp5521: add support for Device Tree bindings Date: Mon, 15 Apr 2013 21:46:52 +0200 Message-ID: <1366055212-15350-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: ALoCoQk92bZnUq04OC0FPfALXXsoe+MIB9OnerWbltiEaMrbUmu4eTKOGzn4hNdCWumTedbaMdEh X-Original-Sender: linus.walleij@stericsson.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 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: Gabriel Fernandez This patch allows the lp5521 driver to be successfully probed and initialised when Device Tree support is enabled. Signed-off-by: Gabriel Fernandez Signed-off-by: Linus Walleij --- .../devicetree/bindings/leds/leds-lp55xx.txt | 22 ++++++++ drivers/leds/leds-lp5521.c | 61 ++++++++++++++++++++-- 2 files changed, 78 insertions(+), 5 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..893284b --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-lp55xx.txt @@ -0,0 +1,22 @@ +Binding for LP55xx Led Driver + +Required properties: +- compatible: "lp5521" or "lp5523" +- label: Used for naming LEDs +- num-chanel: 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 = "lp5521"; + reg = <0x32>; + label = "lp5521_pri"; + num-chanel = /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..87c8254 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" @@ -394,18 +395,68 @@ static struct lp55xx_device_config lp5521_cfg = { .dev_attr_group = &lp5521_group, }; +static int lp5521_of_probe(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 i; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + of_property_read_u8(np, "num-chanel", &num_channel); + of_property_read_u8_array(np, "led-cur", led_cur, num_channel); + of_property_read_u8_array(np, "max-cur", max_cur, num_channel); + of_property_read_string(np, "label", &label); + of_property_read_u8_array(np, "clock-mode", &clock_mode, 1); + + 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; +} + static int lp5521_probe(struct i2c_client *client, const struct i2c_device_id *id) { 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 = lp5521_of_probe(&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)