Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp969967pxb; Mon, 25 Oct 2021 23:48:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUp9mZZEkVErtE6BkzxdDgI/TVmNZD0kbOVDdKsRYtS2tM5tlr98/WZNaL+rRGaFz6o2el X-Received: by 2002:a17:906:a217:: with SMTP id r23mr18097102ejy.548.1635230921197; Mon, 25 Oct 2021 23:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635230921; cv=none; d=google.com; s=arc-20160816; b=HP3RJ6AYeric7i9pMA6IPLgPdQ+jYZEQYCum/3BJvyj4FDtBmJ0TsJe6cxlhs5Ymsl 3s6Au88LGo2rxPAFJ7w/1GqvbihtX0i4PTrSfrd75AyIL6eL2mwFeaK8LDqI2FuGstjo FcuJW9eL2QTF/+5muNBPYdmTBDtM+cF0OtSFjsDHQOm3VkyvhsCm0hxyvpf4192Ejfsx xhx7kpRviCdfFBynYoV8XgoVO2ClGaMBykRe2vmry3V/a0d7YM6FwbGq3zQjQ75oH4jp i5uEItwR/1UVfJe3XHvqD8o0P7yW51oB1ZC1PjYC0b56sBE0kSaC19zkFRUqze7paFng jT1A== 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=4Ez2FM2W1ucj+BeN5l3HKohFYLr/E/eHfxAGL9YE+Us=; b=zl2I1ILsVLR7YnaPb0Lexq/zb2K8yoWn/tsydS4YGk1q8Xk0CDuSdUcIISJmg0/GFO Kwk6/B4y62UpJ68hV7eJcmVNMjVxMsTsrGluCCMvElmS02ciite8sMzCE2Z1geAG98A4 AuGcbOZyFtHkuU4xyio/u/oAES5e2DIGi7fbq8ZHxjw+97I/fpAl0/QzphGaW72fW/ZN fY1o4xE/Sng4KKqLVSCqhwtvW+9wQRnnY7LWvmge3FTV4sqsfSOM35u03araPHCjihvf zRQyBQGYLPbJJsK3KR+c5XwHHoIDU89rOFWaZ5JD40OnkvbHAeA8LMtv7h0xxRh9ZB8A x2SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="uPFxd/fI"; 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 j1si24715321edf.29.2021.10.25.23.48.18; Mon, 25 Oct 2021 23:48:41 -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="uPFxd/fI"; 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 S234414AbhJZC5w (ORCPT + 99 others); Mon, 25 Oct 2021 22:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234494AbhJZC5s (ORCPT ); Mon, 25 Oct 2021 22:57:48 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5B8C061220 for ; Mon, 25 Oct 2021 19:55:25 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id v2-20020a05683018c200b0054e3acddd91so15233717ote.8 for ; Mon, 25 Oct 2021 19:55:25 -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=4Ez2FM2W1ucj+BeN5l3HKohFYLr/E/eHfxAGL9YE+Us=; b=uPFxd/fIRzayE1+CnnxrH2mQ1ozQKQtZgAQxyiFQgXsE5JZapcz5KNRJmYEFFDbC+a Fk3pFeaPYhIjAtY1CXNyfmYivhmyBHXcyZFzYI5PY3zOsnN622cp7Q/475X+LSWzlWNa nm6HBFpGjhAccYbAptftX1uhcD/VAAtGB6Vmw8VxV/BlWgxKJyTIsC71ZFe5/qOomsSH XHR2Wjzpr+ZFYDQ2FcTV/gXJf8H7yj2q4A8062CwZH4oeoHh8Mb8+/qCzbW9pEplQd07 rBoyIIf+cKp3bkMF4aCaYInqoTNSlKlNBX39vNE6wKWCeumTna9vRgnPtWXXfuWIsnn0 UyKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=4Ez2FM2W1ucj+BeN5l3HKohFYLr/E/eHfxAGL9YE+Us=; b=6Tvt2NPYxs5YwVcPx9THCRUOhxfHSdI+R5ucws//M7HSw2NNEF/9uuAL1Q+/9YRNu/ UHBYAj9ZSJXPjfQEI4R49/mVHyeMzmNCgh81q5HZ21glG+RuNbE5ZLw/LVTxM/Gx3VYL 406m6r/dnxx/KTP70xRBXdXGcXZrwNlpmYacG0w26fyP6gyg9G5uPe9SkANNrgtBXZll cPaiQulWJ9h2BOSdfZIfKubRkVcDdC8PEP+kBlRij4Djsb521niR7iDHnvT6+IpP/GRt FGYa75bchDNZFthSWJrdhMVNs00TG3uHMlT+wFAlrj4y1gwqmjzGyyR1Lc1GTVVhHvxE v4Hw== X-Gm-Message-State: AOAM533Twd/Ewt1X/7akuW2XAY8hMaIS/y85Tv4aJMUdHULinp2nLLgm ja2L+NySaynrGpuILzs2CvdGGg== X-Received: by 2002:a05:6830:2647:: with SMTP id f7mr16928571otu.124.1635216924753; Mon, 25 Oct 2021 19:55:24 -0700 (PDT) Received: from ripper ([2600:1700:a0:3dc8:205:1bff:fec0:b9b3]) by smtp.gmail.com with ESMTPSA id d8sm3889507otc.51.2021.10.25.19.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 19:55:24 -0700 (PDT) Date: Mon, 25 Oct 2021 19:57:02 -0700 From: Bjorn Andersson To: Subbaraman Narayanamurthy Cc: Pavel Machek , Rob Herring , Andy Gross , Thierry Reding , Uwe Kleine-K?nig , Lee Jones , 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, Marijn Suijten , Yassine Oudjana , Luca Weiss Subject: Re: [PATCH v10 2/2] leds: Add driver for Qualcomm LPG Message-ID: References: <20211010043912.136640-1-bjorn.andersson@linaro.org> <20211010043912.136640-2-bjorn.andersson@linaro.org> <1ad508af-f7cb-a88f-07d8-5731c5a45403@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1ad508af-f7cb-a88f-07d8-5731c5a45403@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 25 Oct 17:37 PDT 2021, Subbaraman Narayanamurthy wrote: > Hi Bjorn, > > > +#define LPG_RESOLUTION 512 > > Just a thought. Having this fixed to 9-bit resolution would require a > lot of code churn if this driver ends up supporting higher resolution > PWM later. Would it be possible to have this as a parameter in "struct > lpg_channel" ? > In earlier revisions I had support for picking 6 vs 9 bit resolution dynamically, but looked ahead and iirc saw that we only support 9 bit for the now current generation (it's been a while, so I might misremember). The end result was that I ripped that out to simplify the code from the various heuristics that had been bolted on during the generations. People seem okay with this version and it meets the need of a large number of PMICs and use cases, so I would prefer that we land this and then evolve it based on requirements I haven't yet seen. > > +static const unsigned int lpg_clk_rates[] = {1024, 32768, 19200000}; > > +static const unsigned int lpg_pre_divs[] = {1, 3, 5, 6}; > > + > > +static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period) > > +{ > > + unsigned int clk, best_clk = 0; > > + unsigned int div, best_div = 0; > > + unsigned int m, best_m = 0; > > + unsigned int error; > > + unsigned int best_err = UINT_MAX; > > + u64 best_period = 0; > > + > > + /* > > + * The PWM period is determined by: > > + * > > + * resolution * pre_div * 2^M > > + * period = -------------------------- > > + * refclk > > + * > > + * With resolution fixed at 2^9 bits, pre_div = {1, 3, 5, 6} and > > + * M = [0..7]. > > + * > > + * This allows for periods between 27uS and 384s, as the PWM framework > > + * wants a period of equal or lower length than requested, reject > > + * anything below 27uS. > > + */ > > + if (period <= (u64)NSEC_PER_SEC * LPG_RESOLUTION / 19200000) > > + return -EINVAL; > > + > > + /* Limit period to largest possible value, to avoid overflows */ > > + if (period > (u64)NSEC_PER_SEC * LPG_RESOLUTION * 6 * (1 << LPG_MAX_M) / 1024) > > + period = (u64)NSEC_PER_SEC * LPG_RESOLUTION * 6 * (1 << LPG_MAX_M) / 2014; > > s/2014/1024 ? > Now that's an interesting typo... I will correct this and submit v11. Thanks, Bjorn