Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932705AbcJMORi (ORCPT ); Thu, 13 Oct 2016 10:17:38 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:27047 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932176AbcJMORG (ORCPT ); Thu, 13 Oct 2016 10:17:06 -0400 X-AuditID: cbfec7ef-f79e76d000005b57-3c-57ff949eb851 Subject: Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue To: Matt Ranostay , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Matt Ranostay , Tony Lindgren From: Jacek Anaszewski Message-id: Date: Thu, 13 Oct 2016 16:05:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-version: 1.0 In-reply-to: <1476364572-26849-1-git-send-email-matt@ranostay.consulting> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgleLIzCtJLcpLzFFi42LZduzned15U/6HG2xbb2ox/8g5VovLu+aw WXz81s9s8fXkMTaL/Ve8HFg9vn2dxOKxc9Zddo+DD5vZPT5vkgtgieKySUnNySxLLdK3S+DK 6Fj1hKXgj0zFvVdb2BsYF4p3MXJySAiYSGz+fYMNwhaTuHBvPZDNxSEksIxRYtK0BnYI5zOj xInTkxhhOp4938kCV/V14xaolmeMEnMm72UHqRIW8Jd4+f4o2FwRgWSJiXP/AdkcHMwCARIT z/GAhNkEDCV+vnjNBGLzCthJHP61C2wBi4CqxNwrZ9lBykUFIiR2302FKBGU+DH5HguIzSng KXFgyxmwVmYBR4kHi3ayQtjyEpvXvGUGOUdCoJ9d4nzvXUaQORICshKbDjBD3O8icXjHXShb WOLV8S3sELaMxOXJ3SwQvZMZJS4eu8kK4axmlNjY2ckCUWUt0fD/FwvENj6JSdumM0Ms4JXo aBOCMD0k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Nz4 brV75d0DvxYK2CbJyF4O9Z7UZLJ46axpdno5i3bVO95be53NXvlsW9XHYxISfq08mXyn80+/ Ljh68uOd5sBfAd7TD6qs3xR06bGuY1ujheS5jL2Tt18Jn/iQJd9/8VYBu2T+dQL7ecMYDux1 6Iyd9vxc6EQ3+foIsfRf/vX9V8vZvuf4KimxFGckGmoxFxUnAgAUIgHstAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161013140517eucas1p13fd0b70b77c874d9478273d2120c9749 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?SmFjZWsgQW5hc3pld3NraRtTUlBPTC1TeXN0ZW0gRlcgIChN?= =?UTF-8?B?Qikb7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?SmFjZWsgQW5hc3pld3NraRtTUlBPTC1TeXN0ZW0gRlcgIChN?= =?UTF-8?B?QikbU2Ftc3VuZyBFbGVjdHJvbmljcxtTZW5pb3IgU29mdHdhcmUgRW5naW5l?= =?UTF-8?B?ZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjc1MjY=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161013131622eucas1p2e419c58b25f2c61da22d390f2adfacfd X-RootMTR: 20161013131622eucas1p2e419c58b25f2c61da22d390f2adfacfd References: <1476364572-26849-1-git-send-email-matt@ranostay.consulting> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3607 Lines: 101 Hi Matt, On 10/13/2016 03:16 PM, Matt Ranostay wrote: > PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed > rate. This patchset add a nxp,period-scale devicetree property to > adjust for this misconfiguration. > > Cc: Tony Lindgren > Cc: Jacek Anaszewski > Signed-off-by: Matt Ranostay > --- > Documentation/devicetree/bindings/leds/pca963x.txt | 3 +++ > drivers/leds/leds-pca963x.c | 18 +++++++++++++++--- > 2 files changed, 18 insertions(+), 3 deletions(-) > > diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt b/Documentation/devicetree/bindings/leds/pca963x.txt > index dafbe9931c2b..dfbdb123a9bf 100644 > --- a/Documentation/devicetree/bindings/leds/pca963x.txt > +++ b/Documentation/devicetree/bindings/leds/pca963x.txt > @@ -7,6 +7,9 @@ Optional properties: > - nxp,totem-pole : use totem pole (push-pull) instead of open-drain (pca9632 defaults > to open-drain, newer chips to totem pole) > - nxp,hw-blink : use hardware blinking instead of software blinking > +- nxp,period-scale : In some configurations, the chip blinks faster than expected. > + This parameter provides a scaling ratio (fixed point, decimal divided > + by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x. Why DT property? Is it somehow dependent on the board configuration? How this period-scale value is calculated? Is it inferred empirically? > Each led is represented as a sub-node of the nxp,pca963x device. > > diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c > index 407eba11e187..b6ce1f2ec33e 100644 > --- a/drivers/leds/leds-pca963x.c > +++ b/drivers/leds/leds-pca963x.c > @@ -59,6 +59,7 @@ struct pca963x_chipdef { > u8 grpfreq; > u8 ledout_base; > int n_leds; > + unsigned int scaling; > }; > > static struct pca963x_chipdef pca963x_chipdefs[] = { > @@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev *led_cdev, > return pca963x_brightness(pca963x, value); > } > > +static unsigned int pca963x_period_scale(struct pca963x_led *pca963x, > + unsigned int val) > +{ > + unsigned int scaling = pca963x->chip->chipdef->scaling; > + > + return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val; > +} > + > static int pca963x_blink_set(struct led_classdev *led_cdev, > unsigned long *delay_on, unsigned long *delay_off) > { > @@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, > time_off = 500; > } > > - period = time_on + time_off; > + period = pca963x_period_scale(pca963x, time_on + time_off); > > /* If period not supported by hardware, default to someting sane. */ > if ((period < PCA963X_BLINK_PERIOD_MIN) || > (period > PCA963X_BLINK_PERIOD_MAX)) { > time_on = 500; > time_off = 500; > - period = time_on + time_off; > + period = pca963x_period_scale(pca963x, 1000); > } > > /* > @@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, > * (time_on / period) = (GDC / 256) -> > * GDC = ((time_on * 256) / period) > */ > - gdc = (time_on * 256) / period; > + gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period; > > /* > * From manual: period = ((GFRQ + 1) / 24) in seconds. > @@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip) > else > pdata->blink_type = PCA963X_SW_BLINK; > > + if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling)) > + chip->scaling = 1000; > + > return pdata; > } > > -- Best regards, Jacek Anaszewski