Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp912819pxy; Wed, 28 Apr 2021 17:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+Py4nYIG9brC3HRN36mD9ikiDVwPgZPbMDu4zeMOVBpROS48dbq4wJGB3Qf5qFuApJ6Qw X-Received: by 2002:a17:906:38c5:: with SMTP id r5mr30801612ejd.230.1619655231929; Wed, 28 Apr 2021 17:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619655231; cv=none; d=google.com; s=arc-20160816; b=F/zTGqNDwqWDQSQUd0lhV2LHVOpHPVcygHinjdYJnLfe3oIK932G+OGVKsLQOzEw37 mT/nOhWjyF5FdEFGQDKR0TNFDMu/ogzedSf8OlUAjOb8aeqgGkNZS/vgjM3OTMK9GdkS i//3iA1bs/gJOz8wWXp/6exCURroimLCTpBpST+ZfSsexigJhQuuRHBsYH0cKGo4o/qM eSX2PzZ9DVuncgjxcy8pDncv+TZ5wu2pSDEBWIt854Zqb4H96os/YfHBxneU7/BHfBOh th9HE7NGsOHewpnLyqZ2TwvIUy+FNqySANphkf0L3zABDhXakzo39KG4sla+QXW61t38 c94Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SBQkZZ+AM0rdRiolN8pMUJvJaHdqRcP6uvGtBB7hbVU=; b=My62HBQ68MeXnO6xMBipfNOLY5m17G+7rVh9BA5bm2qRGvPnSiUcs0CQVThTHOWEv9 wYIXy9iHMNDnikffkOSoMze5/EGio+LmTcSqQ1H49YIXet+UTMCjeuVroDTVav0kr5gy b6yHdRZ9dPpKistFObes7Zi0sxX3/STw95YVlcsCgxbWCgcK7uwwWcchSTd8gt1GxdvK X5N0KUWj1btrFeQ/HN+157QSOhEmGWVo+eOs2hjSBAzQrGnWUEbxhrQOo1cKn5FlWLcp D6n35OPxzZyUsv3qf4VQBUH9sVssXpUQms8E9Hf9QQ20PK4LSQ4ZSPiNpV/uA8i4k0W4 OflQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZoTQshL6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id oq20si1592339ejb.122.2021.04.28.17.13.29; Wed, 28 Apr 2021 17:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZoTQshL6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231932AbhD2AMu (ORCPT + 99 others); Wed, 28 Apr 2021 20:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231858AbhD2AMu (ORCPT ); Wed, 28 Apr 2021 20:12:50 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49FE1C06138E for ; Wed, 28 Apr 2021 17:12:04 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id i11so2856385oig.8 for ; Wed, 28 Apr 2021 17:12:04 -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; bh=SBQkZZ+AM0rdRiolN8pMUJvJaHdqRcP6uvGtBB7hbVU=; b=ZoTQshL6LSUn3Lj4/ZAJK9Rw3XfU8aTAMNv0jvQ6LotAVOdLClfvB+3CeSpCEioye0 Xtopma3PqjaDfDfsQayOuP4TbqJWt9iSo+X07bTjJZrtqsrpD62HHGpNjKK8gv1NaNtS j+jH6knXMDHPhdU/nGtL0OIOSn/aAekpdbSYjfJzWoxRqf7OTjh4v4eEpfubQ2W/pv6d Z+RgHfkEWL9+um/+yz3n1MeBS04aaAlWZ1J852+CB8wQARNwCvxGxntYdB7vjtAt8hzm umKD+6zJY4V0bBk45x5b0yvwel00U0JtsWLN76hqI9/nZIU2JQov5EqcHbyL4pPBuLAT GL4w== 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; bh=SBQkZZ+AM0rdRiolN8pMUJvJaHdqRcP6uvGtBB7hbVU=; b=pJeRA2RLfAwUeDKfHO6KrX8xpNKGzonIw2k5lMroJ6Eaw+cB6DvprQ+H6M/p+3oeLt 5lhLS20/uioU7oTdiuA3wEsU0/zgNdTL09lhPp9sEIsg8wqQpha6vlT03TBpdWbaXFdc xd/X7Ic/IYZn7+WzQYrR8NhFh5zaf7v2S8BBYU3nW8aWd6YdeLiooJ/cipwPJQHIKrWc 6uk64cGV8K8guS5woOL6HqohnoB/i5I4ZqiX/4fOmejo8kYG24aRfFe8yYvJxx3mzfU4 oG1S6AG0dSqp66YuixfenwDSJrwR9zVvhKw4hnzwW1007gm+HpnAXT7irOsnyaDEXIZA FxwQ== X-Gm-Message-State: AOAM530WxvECCmhnlSKFTDeNMvpimO1PAYIPAqlqiIAsAcT4aM+MO9rK pPGy2xhZErNb3C0PkS3T0Cm3Tg== X-Received: by 2002:aca:5845:: with SMTP id m66mr5007370oib.0.1619655123470; Wed, 28 Apr 2021 17:12:03 -0700 (PDT) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id r63sm305743oia.43.2021.04.28.17.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 17:12:03 -0700 (PDT) Date: Wed, 28 Apr 2021 19:12:00 -0500 From: Bjorn Andersson To: Pavel Machek Cc: Dan Murphy , Rob Herring , Andy Gross , Thierry Reding , Uwe Kleine-K?nig , Lee Jones , Martin Botka , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-pwm@vger.kernel.org Subject: Re: [PATCH v6 2/4] leds: Add driver for Qualcomm LPG Message-ID: References: <20201021201224.3430546-1-bjorn.andersson@linaro.org> <20201021201224.3430546-3-bjorn.andersson@linaro.org> <20201029181357.GE26053@duo.ucw.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201029181357.GE26053@duo.ucw.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 29 Oct 13:13 CDT 2020, Pavel Machek wrote: > Hi! > > > The Light Pulse Generator (LPG) is a PWM-block found in a wide range of > > PMICs from Qualcomm. It can operate on fixed parameters or based on a > > lookup-table, altering the duty cycle over time - which provides the > > means for e.g. hardware assisted transitions of LED brightness. > > > > Signed-off-by: Bjorn Andersson > > --- > > > > Changes since v5: > > - Make sure to not used the state of the last channel in a group to determine > > if the current sink should be active for all channels in the group. > > - Replacement of unsigned -1 with UINT_MAX > > - Work around potential overflow by using larger data types, instead of separate code paths > > - Use cpu_to_l16() rather than hand rolling them > > - Minor style cleanups > > > > drivers/leds/Kconfig | 9 + > > drivers/leds/Makefile | 1 + > > drivers/leds/leds-qcom-lpg.c | 1190 ++++++++++++++++++++++++++++++++++ > > 3 files changed, 1200 insertions(+) > > create mode 100644 drivers/leds/leds-qcom-lpg.c > > Let's put this into drivers/leds/rgb/. You may need to create it. > Will do so. > > > +static int lpg_lut_store(struct lpg *lpg, struct led_pattern *pattern, > > + size_t len, unsigned int *lo_idx, unsigned int *hi_idx) > > +{ > > + unsigned int idx; > > + __le16 val; > > No need for __XX variants outside of headers meant for userspace. > __le16 is the in-kernel return type for cpu_to_le16(), but after further review I believe I don't need to do this. > > +#define LPG_ENABLE_GLITCH_REMOVAL BIT(5) > > + > > +static void lpg_enable_glitch(struct lpg_channel *chan) > > +{ > > + struct lpg *lpg = chan->lpg; > > + > > + regmap_update_bits(lpg->map, chan->base + PWM_TYPE_CONFIG_REG, > > + LPG_ENABLE_GLITCH_REMOVAL, 0); > > +} > > + > > +static void lpg_disable_glitch(struct lpg_channel *chan) > > +{ > > + struct lpg *lpg = chan->lpg; > > + > > + regmap_update_bits(lpg->map, chan->base + PWM_TYPE_CONFIG_REG, > > + LPG_ENABLE_GLITCH_REMOVAL, > > + LPG_ENABLE_GLITCH_REMOVAL); > > +} > > Helper functions for single register write is kind of overkill... > Yes, it is, but it keep lpg_apply() tidy. > > +static int lpg_blink_set(struct lpg_led *led, > > + unsigned long delay_on, unsigned long delay_off) > > +{ > > + struct lpg_channel *chan; > > + unsigned int period_us; > > + unsigned int duty_us; > > + int i; > > + > > + if (!delay_on && !delay_off) { > > + delay_on = 500; > > + delay_off = 500; > > + } > > Aren't you supposed to modify the values passed to you, so that > userspace knows what the default rate is? > I had missed this. > > > + ret = lpg_lut_store(lpg, pattern, len, &lo_idx, &hi_idx); > > + if (ret < 0) > > + goto out; > > Just do direct return. > Will do. > > +out: > > + return ret; > > +} > > > +static const struct pwm_ops lpg_pwm_ops = { > > + .request = lpg_pwm_request, > > + .apply = lpg_pwm_apply, > > + .owner = THIS_MODULE, > > +}; > > + > > +static int lpg_add_pwm(struct lpg *lpg) > > +{ > > + int ret; > > + > > + lpg->pwm.base = -1; > > + lpg->pwm.dev = lpg->dev; > > + lpg->pwm.npwm = lpg->num_channels; > > + lpg->pwm.ops = &lpg_pwm_ops; > > + > > + ret = pwmchip_add(&lpg->pwm); > > + if (ret) > > + dev_err(lpg->dev, "failed to add PWM chip: ret %d\n", ret); > > + > > + return ret; > > +} > > Do we need to do this? I'd rather have LED driver, than LED+PWM > driver... > Yes, I believe we need to do this. Because each piece of hardware has N channels, which can be wired to LEDs, grouped with other channels and wired to multicolor LEDs or be used as PWM signals. And this configuration is board specific. One such example is the laptop in front of me, which has 3 channels wired to an RGB LED and 1 channel wired as a backlight control signal (i.e. using pwm-backlight). Another example is a devboard where the 4 channels are wired to 4 LEDs. Regards, Bjorn