Received: by 10.223.185.116 with SMTP id b49csp4825657wrg; Tue, 27 Feb 2018 03:20:28 -0800 (PST) X-Google-Smtp-Source: AH8x226FO/UTAmKC8EL4a2lvmG34aPGfMqWK0rRGsDhtKlyC18bWLBng8SBgHvErsrQi4csy5lZz X-Received: by 2002:a17:902:aa8e:: with SMTP id d14-v6mr13455346plr.94.1519730428414; Tue, 27 Feb 2018 03:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519730428; cv=none; d=google.com; s=arc-20160816; b=pyTT/5v5DIvJ0tqih/6U8QBdY2UbjhZnTsLN/On18CN+xs63JUlUt5WB3CtRnZP5hT 40AX2h/yWIsesHgdRgx6X2Og5dOA70ZRwFDd5o3dFNv7/qeKJNkajkVCksYL2WIjCsNq dmioB+SSWuivpx/b5thw4ck0fxIaUz5NpByPc/xOr1y/xNLU6lALe7QVu50O2bXkVb2D f4JRVbVasCKA2m546YaF3RjKFIyTpWsDjEo+nKDhTx1N/2XLq55r4EMOzRj/TFy2bpKp Y+3xfbbowEYuOLCnrVfkyfyYRP7dyFycB39x4Uqxr+65MvxmHM5a4iopn6AJ35SoTULp 06AQ== 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=sXr4sLYj6QvmwVo4l0NJs7tD5i5nM4+SuI2bsVx4kbs=; b=LKOnEHzAczmSLyyg73I+t0bEsdjP3z5iOZjO1YzeLEXGQ5ozI+8U9fNxrNhswOqmPf knwkUhbru0dXwBGWjNYhOhSFwEjtwVVTd2JozexUHUzRi3rT9Zu2K5UX003k0eG0ov79 LaduJyDPkPrLCgFA6b72Ur9los/JVamEzr7j/iAirl41OL0Hsq3baIZJZ3oad4fNjDSd mCE6FNkzoewrDhzZOeP6dBuI3x5ZAGdLRYskCX389XPkCn+g5VgR/S5TEc51WOqDB+sn ijdgdXJLZtFd+4u3v9eobBJg2nLI0D/3XhmbHqmxMjldbzvoeRGwYf3zQ4UIcjUv1av/ 7G/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ei6o3LTg; 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 q3si5914707pgt.517.2018.02.27.03.20.13; Tue, 27 Feb 2018 03:20:28 -0800 (PST) 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=ei6o3LTg; 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 S1753027AbeB0Kyz (ORCPT + 99 others); Tue, 27 Feb 2018 05:54:55 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:45308 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752950AbeB0Kyu (ORCPT ); Tue, 27 Feb 2018 05:54:50 -0500 Received: by mail-wr0-f196.google.com with SMTP id p104so24328945wrc.12 for ; Tue, 27 Feb 2018 02:54:49 -0800 (PST) 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=sXr4sLYj6QvmwVo4l0NJs7tD5i5nM4+SuI2bsVx4kbs=; b=ei6o3LTgfGIdPiB1PESPpXjS4u5+DRVFsg/42rjI/Gyv2gLt60NSJvKdWNzXwEWjMR hwPi+5fKkzAOl0SDN1DuqExP4879BoU0/5gQ0mQr3toVEjRXaPsKv3ifGt1zZbZRBA4L MUZtndQZJPaDXhDHvYvVXSb0qpZxHrbz6AwOM= 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=sXr4sLYj6QvmwVo4l0NJs7tD5i5nM4+SuI2bsVx4kbs=; b=KS9Q3G+cuH92UwRmbzxbBL1+jTSoH71sz+xQstoIsG55gCB8HikoTds1APgVB6NlUJ TI7jVD97/Nvl3g1Ckh9xfpp0+4nlgvVzY9VwMoTQmIgWnFozvICKOx+CevhmAgNqcL1u 7mvz5F2hz6bZRs9XrmzgKU56AURYQTL51ixB922GEqJkedGXVIdOX1XveqE8LzyBL4iA pLK2f2CYrgGgKDtvNjfMSK3bgcSzC776woOxL+122Z6E0TngS0/Yk19jhO5p7nA2iuNR YL+jg3b+BhikYBLuXzcF/5V2Fa31NP2BG0o+uFzCKqEv8/UPEVPbNk/AfZj3s6WzJfQv huIw== X-Gm-Message-State: APf1xPCttpl4H5GjwmXqcWWfOeMcG2PTU6jCra4vJEAjrCI6eM20Lu6j /w6pPXFfNQSWGvfl9Vcf6pc3eg== X-Received: by 10.223.148.102 with SMTP id 93mr11840627wrq.154.1519728888929; Tue, 27 Feb 2018 02:54:48 -0800 (PST) Received: from oak.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id v9sm9706053wre.8.2018.02.27.02.54.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Feb 2018 02:54:47 -0800 (PST) Date: Tue, 27 Feb 2018 10:54:44 +0000 From: Daniel Thompson To: Claudiu Beznea Cc: Jani Nikula , thierry.reding@gmail.com, shc_work@mail.ru, kgene@kernel.org, krzk@kernel.org, linux@armlinux.org.uk, mturquette@baylibre.com, sboyd@codeaurora.org, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, airlied@linux.ie, kamil@wypas.org, b.zolnierkie@samsung.com, jdelvare@suse.com, linux@roeck-us.net, dmitry.torokhov@gmail.com, rpurdie@rpsys.net, jacek.anaszewski@gmail.com, pavel@ucw.cz, mchehab@kernel.org, sean@mess.org, lee.jones@linaro.org, jingoohan1@gmail.com, milo.kim@ti.com, robh+dt@kernel.org, mark.rutland@arm.com, corbet@lwn.net, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-clk@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-hwmon@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.org, linux-media@vger.kernel.org, linux-fbdev@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v3 05/10] pwm: add PWM mode to pwm_config() Message-ID: <20180227105444.lo4pee7vh4we3foq@oak.lan> References: <1519300881-8136-1-git-send-email-claudiu.beznea@microchip.com> <1519300881-8136-6-git-send-email-claudiu.beznea@microchip.com> <20180222123308.mypx2r7n6o63mj5z@oak.lan> <87po4s2hve.fsf@intel.com> <3a70b89c-b470-3723-760c-5294d0a75230@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a70b89c-b470-3723-760c-5294d0a75230@microchip.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 26, 2018 at 04:24:15PM +0200, Claudiu Beznea wrote: > On 26.02.2018 11:57, Jani Nikula wrote: > > On Thu, 22 Feb 2018, Daniel Thompson wrote: > >> On Thu, Feb 22, 2018 at 02:01:16PM +0200, Claudiu Beznea wrote: > >>> Add PWM mode to pwm_config() function. The drivers which uses pwm_config() > >>> were adapted to this change. > >>> > >>> Signed-off-by: Claudiu Beznea > >>> --- > >>> arch/arm/mach-s3c24xx/mach-rx1950.c | 11 +++++++++-- > >>> drivers/bus/ts-nbus.c | 2 +- > >>> drivers/clk/clk-pwm.c | 3 ++- > >>> drivers/gpu/drm/i915/intel_panel.c | 17 ++++++++++++++--- > >>> drivers/hwmon/pwm-fan.c | 2 +- > >>> drivers/input/misc/max77693-haptic.c | 2 +- > >>> drivers/input/misc/max8997_haptic.c | 6 +++++- > >>> drivers/leds/leds-pwm.c | 5 ++++- > >>> drivers/media/rc/ir-rx51.c | 5 ++++- > >>> drivers/media/rc/pwm-ir-tx.c | 5 ++++- > >>> drivers/video/backlight/lm3630a_bl.c | 4 +++- > >>> drivers/video/backlight/lp855x_bl.c | 4 +++- > >>> drivers/video/backlight/lp8788_bl.c | 5 ++++- > >>> drivers/video/backlight/pwm_bl.c | 11 +++++++++-- > >>> drivers/video/fbdev/ssd1307fb.c | 3 ++- > >>> include/linux/pwm.h | 6 ++++-- > >>> 16 files changed, 70 insertions(+), 21 deletions(-) > >>> > >>> diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c > >>> index 2030a6b77a09..696fa25dafd2 100644 > >>> --- a/drivers/video/backlight/lm3630a_bl.c > >>> +++ b/drivers/video/backlight/lm3630a_bl.c > >>> @@ -165,8 +165,10 @@ static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) > >>> { > >>> unsigned int period = pchip->pdata->pwm_period; > >>> unsigned int duty = br * period / br_max; > >>> + struct pwm_caps caps = { }; > >>> > >>> - pwm_config(pchip->pwmd, duty, period); > >>> + pwm_get_caps(pchip->pwmd->chip, pchip->pwmd, &caps); > >>> + pwm_config(pchip->pwmd, duty, period, BIT(ffs(caps.modes) - 1)); > >> > >> Well... I admit I've only really looked at the patches that impact > >> backlight but dispersing this really odd looking bit twiddling > >> throughout the kernel doesn't strike me a great API design. > >> > >> IMHO callers should not be required to find the first set bit in > >> some specially crafted set of capability bits simply to get sane > >> default behaviour. > > > > Agreed. IMHO the regular use case becomes rather tedious, ugly, and > > error prone. > > Using simply PWM_MODE(NORMAL) instead of BIT(ffs(caps.modes) - 1) would be OK > from your side? > > Or, what about using a function like pwm_mode_first() to get the first supported > mode by PWM channel? > > Or, would you prefer to solve this inside pwm_config() function, let's say, in > case an invalid mode is passed as argument, to let pwm_config() to choose the > first available PWM mode for PWM channel passed as argument? What is it that actually needs solving? If a driver requests normal mode and the PWM driver cannot support it why not just return an error an move on. Put another way, what is the use case for secretly adopting a mode the caller didn't want? Under what circumstances is this a good thing? Daniel.