Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757306AbcJNGh2 (ORCPT ); Fri, 14 Oct 2016 02:37:28 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:42315 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752245AbcJNGhV (ORCPT ); Fri, 14 Oct 2016 02:37:21 -0400 X-AuditID: cbfec7f2-f79556d000002c42-79-58007ceaecb3 Subject: Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue To: Matt Ranostay Cc: "linux-kernel@vger.kernel.org" , "devicetree@vger.kernel.org" , Matt Ranostay , Tony Lindgren , Rob Herring , Mark Rutland From: Jacek Anaszewski Message-id: <924a896d-b3f2-5fed-62ba-a731e79e1567@samsung.com> Date: Fri, 14 Oct 2016 08:36:23 +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: Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGKsWRmVeSWpSXmKPExsWy7djPc7qvahgiDM5+Z7GYf+Qcq8XlXXPY LJZev8hk8fFbP7PF15PH2Cxa9x5ht9h/xcuB3WPNvDWMHt++TmLx2DnrLrvHplWdbB4HHzaz e3zeJBfAFsVlk5Kak1mWWqRvl8CV8XH3eqaC9xoVk+eeZmtgPCPXxcjJISFgIjFx1WkWCFtM 4sK99WxdjFwcQgJLGSX+f1nPDuF8ZpQ4vHUnG0zHtkOdjBCJZYwSz79MgGp5xijR+HYfE0iV sIC/xMv3R8E6RATUJda29oKNYhaYyiSxafpHsASbgKHEzxevwRp4Bewkup5PYwSxWQRUJc4t 72LuYuTgEBWIkNh9NxWiRFDix+R7YLdyCgRLfGm5DdbKLGAl8exfKyuELS+xec1bZpBdEgLr 2CVWbt7BBDJHQkBWYtMBZogPXCQ+TboO9bOwxKvjW9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3U1 Q4QQb0piZVVqUX58UWlOavEhRlOgJyYyS4km5wMTQF5JvKGJobmloZGxhYW5kZGSOO/UD1fC hQTSE0tSs1NTC1KLYPqYODilGhhtn4jHGipnml6qvdKY/Tz5+zrT3Zli0pbyZmYKvEK9m6p/ pX9nUFdKiD6d91r09Eef7rUuq2TvRe6/8Fry2+Fn702umGbdTrgd/XSDzKK9CdUX1As7so+I XXO7s/92b8ifOZ6TQ/OqdjMePaV0kmXx5n+69V0rzmYriNon/Pxnqi2nZc+2PkOJpTgj0VCL uag4EQABQwNTyAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161014063625eucas1p1db667bf41b70126f9b360fce934d3caf 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: 5089 Lines: 142 On 10/13/2016 04:20 PM, Matt Ranostay wrote: > On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski > wrote: >> 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? >> > > We empirically discovered and verified this with an logic analyzer on > multiple batches of this part. > Reason for the DT entry is we aren't 100% sure that it is always going > to be the same with different board revs. > > Could be that parts clock acts differently with supply voltage. This > has been calculated by setting it an expected value, and measuring the > actual result with the logic analyzer. I'd like to have DT maintainer's ack for this. Cc Rob and Mark. >>> 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 > -- > To unsubscribe from this list: send the line "unsubscribe devicetree" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > > -- Best regards, Jacek Anaszewski