From patchwork Sun Sep 22 16:59:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Dunn X-Patchwork-Id: 2924681 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 929F2BFF05 for ; Sun, 22 Sep 2013 17:00:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C368A2052D for ; Sun, 22 Sep 2013 17:00:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 018252052A for ; Sun, 22 Sep 2013 17:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734Ab3IVRA2 (ORCPT ); Sun, 22 Sep 2013 13:00:28 -0400 Received: from smtp.newsguy.com ([74.209.136.69]:58966 "EHLO smtp.newsguy.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752414Ab3IVRA0 (ORCPT ); Sun, 22 Sep 2013 13:00:26 -0400 Received: from localhost.localdomain (242.sub-70-199-133.myvzw.com [70.199.133.242]) by smtp.newsguy.com (8.14.3/8.14.3) with ESMTP id r8MGxqKF011497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 22 Sep 2013 09:59:53 -0700 (PDT) (envelope-from mikedunn@newsguy.com) From: Mike Dunn To: thierry.reding@gmail.com Cc: Mike Dunn , Richard Purdie , Jingoo Han , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Grant Likely , Rob Herring , linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Robert Jarzmik , Marek Vasut Subject: [PATCH v2] pwm-backlight: allow for non-increasing brightness levels Date: Sun, 22 Sep 2013 09:59:56 -0700 Message-Id: <1379869196-19377-1-git-send-email-mikedunn@newsguy.com> X-Mailer: git-send-email 1.8.1.5 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the driver assumes that the values specified in the brightness-levels device tree property increase as they are parsed from left to right. But boards that invert the signal between the PWM output and the backlight will need to specify decreasing brightness-levels. This patch removes the assumption that the last element of the array is the maximum value, and instead searches the array for the maximum value and uses that in the duty cycle calculation. Signed-off-by: Mike Dunn --- Changelog: v2: - commit message reworded; correct line wrap used - 'max_level' variable renamed to 'scale' - loop counter variable type changed to unsigned int - value held in scale changed from array index to actual maximum level - blank lines added around loop for readability drivers/video/backlight/pwm_bl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 1fea627..5e99b88 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -27,6 +27,7 @@ struct pwm_bl_data { unsigned int period; unsigned int lth_brightness; unsigned int *levels; + unsigned int scale; int (*notify)(struct device *, int brightness); void (*notify_after)(struct device *, @@ -57,7 +58,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl) if (pb->levels) { duty_cycle = pb->levels[brightness]; - max = pb->levels[max]; + max = pb->scale; } else { duty_cycle = brightness; } @@ -195,7 +196,14 @@ static int pwm_backlight_probe(struct platform_device *pdev) } if (data->levels) { - max = data->levels[data->max_brightness]; + unsigned int i; + + for (i = 0; i <= data->max_brightness; i++) { + if (data->levels[i] > pb->scale) + pb->scale = data->levels[i]; + } + + max = pb->scale; pb->levels = data->levels; } else max = data->max_brightness;