Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3823894imm; Mon, 30 Jul 2018 04:15:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdEtKvuUkz/hORAeLJpXIJVJcDoCDhS86hlsd+oP+SRCwOW5SFst1IrckagQ7ZwYi4+BbzP X-Received: by 2002:a62:e511:: with SMTP id n17-v6mr4344524pff.210.1532949342129; Mon, 30 Jul 2018 04:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532949342; cv=none; d=google.com; s=arc-20160816; b=SGpPPFlNB0OAS/cAE0ipKr+GL56wmmFDetR6rzTnp1ShWWJ4EcezVBi70pyrFuHpXX gA6O6ES0brPlCiodAGxsnjCXXPFTBWYx7o0GRVA1hGOo8TtesWGo3HOmXzv8aoD4+bRJ YmgBBWE3c4wHWzpr2fH3jp4EppIUcuppBEOa+hr5qOy4RL+e1eyfDqMc4HXWXy42vf7U n+kiSUTiZmP1qkTx3ZzxpBGUY5Dl5Sn0f2PTT0+ZhHamcLoLS9MrPIunSPPoS9HP9BOF 0R5lqA7O02JPCt3vhi0f2Yi+nLyHRkvYhZ2+nS4jXHIN5FxzEzJhLuLkUOQ926UNPsAx QyFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=uCdhdFY6DbFvcQej9Q3xvESg1fjy1AXLb3cYlSLsN1g=; b=LPchOp5EEKEb2S/HHNjv5P/5ZlwPbmhdrHc5Z3Dnh0K/oy0jbI4IvRuSiP1+ohfQtB +49EvHl/3oJSoZ6S8eETh/zO01P6blSyT6iF2NxhZypSTnjPK2o46jI26tsmajn81ZWF 1MFILzFEH9r0ED076qH8GhcwjZoH7W+lxu+/A8kQNg4/S2nud4JvTavXAgFAoXaDqXth o54Yak3pq4bke5msYqBxREazOrNdM9cESPo88ebBnGneG0HSJNx49anLrk/yGlUkZ+QH rxnqsTBsN4GEIraJkHuZnW8eThfuXbb0caMHikD6DUhwc159jft8zedCxjAlzsgSuEkR WTtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I8gi8z6l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25-v6si11318225pfi.138.2018.07.30.04.15.04; Mon, 30 Jul 2018 04:15:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I8gi8z6l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbeG3Mre (ORCPT + 99 others); Mon, 30 Jul 2018 08:47:34 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34857 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbeG3Mre (ORCPT ); Mon, 30 Jul 2018 08:47:34 -0400 Received: by mail-wm0-f65.google.com with SMTP id o18-v6so13359737wmc.0 for ; Mon, 30 Jul 2018 04:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=uCdhdFY6DbFvcQej9Q3xvESg1fjy1AXLb3cYlSLsN1g=; b=I8gi8z6lV25HCk+fpjWFPaL4binQKd7d+dFOiAL1tVxoBlrRn1wp1Zkxful04EI22l h2nchDfK135TTInLtrBOijDopvuk6M6YMbnSjc7dRi1d5TZydBaPATjzYBH6PqNIDASi C7LJq6G9kgedsxX/hHFUy4LfLy27Q4br3SiyY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=uCdhdFY6DbFvcQej9Q3xvESg1fjy1AXLb3cYlSLsN1g=; b=dUlRvi/62/tCZzY+Wspqhzjrhb2AJEdakYHWyPtcCblPRcWl2Lv0v7J0V8hknK28uJ ulhbxsfZDSpEKxzn/5JHsYg2OFW/+zY9ugf4HIfmoRQBMwqBkzRgwM89p6cQWaPYks22 pWk1VR6aqg2JW1nXefya/D8awF6TOqodmTvsEmTq+euoi9mFldLgLFNrJrms4jv59sBz IWg5lXjBk6ej+nXvK97MZ3Gg8cFAMcZqsyNgiOsp0n0GFbtJhwZ7Wk8RQpuGG+SJZhSa 5V4/KfLidD8su58UdCrEfU/Sm49kR4HHNo0I04EL4g/PcY2XgeHxS8ZwxzzEI9+s0YN1 efCQ== X-Gm-Message-State: AOUpUlFa3nBFtPmLe5BlgogToUM1Ki0gSoL/cH4esPmmMLXwVeAZdmwD TqSTvqHPVEguhZ/G8XIohbf51w== X-Received: by 2002:a1c:6d1c:: with SMTP id i28-v6mr15497389wmc.97.1532949183258; Mon, 30 Jul 2018 04:13:03 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id w23-v6sm6874336wmc.43.2018.07.30.04.13.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Jul 2018 04:13:02 -0700 (PDT) Date: Mon, 30 Jul 2018 12:12:59 +0100 From: Daniel Thompson To: Enric Balletbo i Serra Cc: linux-kernel@vger.kernel.org, kernel@collabora.com, cl@rock-chips.com, linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Thierry Reding , Bartlomiej Zolnierkiewicz , dri-devel@lists.freedesktop.org, Jingoo Han , Lee Jones Subject: Re: [PATCH v2] backlight: pwm_bl: switch to using "atomic" PWM API Message-ID: <20180730111259.5qjtchfo67nquila@holly.lan> References: <20180727151121.12296-1-enric.balletbo@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180727151121.12296-1-enric.balletbo@collabora.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 27, 2018 at 05:11:21PM +0200, Enric Balletbo i Serra wrote: > The "atomic" API allows us to configure PWM period and duty_cycle and > enable it in one call. > > The patch also moves the pwm_init_state just before any use of the > pwm_state struct, this fixes a potential bug where pwm_get_state > can be called before pwm_init_state. > > Signed-off-by: Enric Balletbo i Serra > --- > > Changes in v2: > - Do not force the PWM be off in the first call to pwm_apply_state. > - Delayed applying the state until we know what the period is. > - Removed pb->period as after the conversion is not needed. Re-reading this I have spotted a couple of things I probably could have mentioned against v1... sorry. I think it's looking good though, I expect to be able to ack v3. > drivers/video/backlight/pwm_bl.c | 71 ++++++++++++++++++-------------- > 1 file changed, 41 insertions(+), 30 deletions(-) > > diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c > index bdfcc0a71db1..dd1cb29b5332 100644 > --- a/drivers/video/backlight/pwm_bl.c > +++ b/drivers/video/backlight/pwm_bl.c > @@ -28,7 +28,6 @@ > struct pwm_bl_data { > struct pwm_device *pwm; > struct device *dev; > - unsigned int period; > unsigned int lth_brightness; > unsigned int *levels; > bool enabled; > @@ -46,7 +45,8 @@ struct pwm_bl_data { > void (*exit)(struct device *); > }; > > -static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) > +static void pwm_backlight_power_on(struct pwm_bl_data *pb, > + struct pwm_state *state) > { > int err; > > @@ -57,7 +57,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) > if (err < 0) > dev_err(pb->dev, "failed to enable power supply\n"); > > - pwm_enable(pb->pwm); > + state->enabled = true; > + pwm_apply_state(pb->pwm, state); > > if (pb->post_pwm_on_delay) > msleep(pb->post_pwm_on_delay); > @@ -70,6 +71,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) > > static void pwm_backlight_power_off(struct pwm_bl_data *pb) > { > + struct pwm_state state; > + > if (!pb->enabled) > return; > > @@ -79,8 +82,10 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) > if (pb->pwm_off_delay) > msleep(pb->pwm_off_delay); > > - pwm_config(pb->pwm, 0, pb->period); > - pwm_disable(pb->pwm); > + pwm_get_state(pb->pwm, &state); > + state.enabled = false; > + state.duty_cycle = 0; > + pwm_apply_state(pb->pwm, &state); This is an in exact conversion because this code ignores a failure to set the duty cycle to zero whilst pwm_apply_state() does not. This would only matter if pwm_config() returns an error and given that a PWM which does not support a duty cycle of zero is permitted to adjust zero to the smallest supported value there is no *need* for a driver to return an error here. In other words... this is a subtle change of behaviour and perhaps (even probably) irrelevant. However I'm still interested whether you did any work to confirm or deny whether drivers that reports error on zero duty cycle actually exist. > regulator_disable(pb->power_supply); > pb->enabled = false; > @@ -89,14 +94,17 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) > static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) > { > unsigned int lth = pb->lth_brightness; > + struct pwm_state state; > u64 duty_cycle; > > + pwm_get_state(pb->pwm, &state); > + > if (pb->levels) > duty_cycle = pb->levels[brightness]; > else > duty_cycle = brightness; > > - duty_cycle *= pb->period - lth; > + duty_cycle *= state.period - lth; > do_div(duty_cycle, pb->scale); > > return duty_cycle + lth; > @@ -106,6 +114,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl) > { > struct pwm_bl_data *pb = bl_get_data(bl); > int brightness = bl->props.brightness; > + struct pwm_state state; > int duty_cycle; > > if (bl->props.power != FB_BLANK_UNBLANK || > @@ -118,8 +127,12 @@ static int pwm_backlight_update_status(struct backlight_device *bl) > > if (brightness > 0) { > duty_cycle = compute_duty_cycle(pb, brightness); > - pwm_config(pb->pwm, duty_cycle, pb->period); In principle the same subtle change applies here... but if pwm_config() reported an error here then the backlight probably didn't work before your change either so less need to worry about it! > - pwm_backlight_power_on(pb, brightness); > + pwm_get_state(pb->pwm, &state); > + state.duty_cycle = duty_cycle; > + if (!state.enabled) > + pwm_backlight_power_on(pb, &state); It verges towards nit picking but I don't really like the way a half updated state is shared between ...update_status and ...power_on. I'd rather it looked something like: pwm_get_state(pb->pwm, &state); if (!state.enabled) { pwm_backlight_power_on(pb); <-- no sharing here, make on match off } else { pwm_backlight_update_duty_cycle(pb, &state, brightness); pwm_apply_state(pb->pwm, &state); } (and have pwm_backlight_power_on() also call ...update_duty_cycle too) Thoughts? Daniel.