Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3687581imc; Thu, 14 Mar 2019 03:01:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiNgHZj0/qInQeZ82N7B0nKydAXnEkjOYHvsJuNbL+QgZmJhNoOknI0z6yBgnhfQUDZvEX X-Received: by 2002:a17:902:8602:: with SMTP id f2mr50991216plo.263.1552557711148; Thu, 14 Mar 2019 03:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552557711; cv=none; d=google.com; s=arc-20160816; b=F3kVQU80jjASA6dVLlAb673XWKilhMA9gPtYaU8M8v4K/xGRzJbGQxoVkGWNCKdCft 3zvAd2ZjeO4DMHqSFe3bcnWmak6b0NNrw2JVpOYUOD4EdrGb5ojTCQrAz1cDSNkJ0S0R /pekss6oezBiPuRM7cSV7h5hCD+jEnB4z0hJ2Aq5/WwbURy1b98X/HNcpb/v3WEbPdPA 9k4O9SzDnO5sESk12AEMHzM+XVFO+ZPo3ghTb1Y6zI00Of0AVQn80aUW4xg/q7a3cvX2 sVTVv9HRUUoPV1SS1tPy2EQ9eOCPuSENOU9CSySOBTgI+9aJ2bcNyuC+9vHaGrmi+klo t/ow== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=9l0J7fn3ogpdczaHLWom9Isw929IkvHt9jiztahWcOc=; b=PMG7BXfj1bHMg/tX77ZqwbtADPAsINEEc2FRfOCsN9COmee83EP2D5zXCdgdDWTrHS D92P4/7ZbDIhnohyaNOpERc+7UqB6Dx5FNI2T4T/aUW8+XCmyUGWlIGHHYzAkJ5phHjJ l6+1d/N1pyDj+GGLjFtlzNHTihGSG3lzYWUqhVrONC//i4S/rSHuUlwbNStYdweHcnYe DgLQ5xn2g0g5PZ3fWX1FCb/DwGUi7T422Y1y869+WHtxsoZ296KM/lvAFleb6wy8p0vz cbmB07pdQFJUBrRjuyqfQ/ZBms0NGtaXtlxhT3Fld5Oc/Zb/90v4ZfR7bwEvjOGDbA4Q C1RQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si12228611pgf.93.2019.03.14.03.01.35; Thu, 14 Mar 2019 03:01:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726848AbfCNKA5 (ORCPT + 99 others); Thu, 14 Mar 2019 06:00:57 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46827 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726653AbfCNKA5 (ORCPT ); Thu, 14 Mar 2019 06:00:57 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1h4NAJ-0006O9-DV; Thu, 14 Mar 2019 11:00:43 +0100 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1h4NAI-0002HD-JJ; Thu, 14 Mar 2019 11:00:42 +0100 Date: Thu, 14 Mar 2019 11:00:42 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Anson Huang Cc: "thierry.reding@gmail.com" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "linux@armlinux.org.uk" , "stefan@agner.ch" , "otavio@ossystems.com.br" , Leonard Crestez , "schnitzeltony@gmail.com" , "jan.tuerk@emtrion.com" , Robin Gong , "linux-pwm@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: Re: [PATCH V2 2/5] pwm: Add i.MX TPM PWM driver support Message-ID: <20190314100042.fl4kdwn7awcw4aov@pengutronix.de> References: <1552461970-20813-1-git-send-email-Anson.Huang@nxp.com> <1552461970-20813-3-git-send-email-Anson.Huang@nxp.com> <20190314091702.sooxvnzd4mqr2ilz@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Mar 14, 2019 at 09:49:06AM +0000, Anson Huang wrote: > > On Wed, Mar 13, 2019 at 07:31:16AM +0000, Anson Huang wrote: > > > +static void imx_tpm_pwm_config(struct pwm_chip *chip, > > > + struct pwm_device *pwm, > > > + struct pwm_state *state) > > > +{ > > > + struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip); > > > + static bool tpm_cnt_initialized; > > > + unsigned int duty_cnt; > > > + u32 val; > > > + u64 tmp; > > > + > > > + /* > > > + * TPM counter is shared by multi channels, let's make it to be > > > + * ONLY first channel can config TPM counter's precale and period > > > + * count. > > > + */ > > > + if (!tpm_cnt_initialized) { > > > + imx_tpm_pwm_config_counter(chip, state->period); > > > + tpm_cnt_initialized = true; > > > + } > > > > So the period can only be configured once. That is not as good as it could be. > > You should allow a change whenever there is exactly one PWM in use. > > OK, maybe I can add check for other channels' statue here, and allow the period > update if ONLY 1 channel is enabled. See how the SiFive patch that I already pointed out solves this same problem. > > > + /* set duty counter */ > > > + tmp = readl(tpm->base + TPM_MOD) & TPM_MOD_MOD_MASK; > > > + tmp *= state->duty_cycle; > > > + duty_cnt = DIV_ROUND_CLOSEST_ULL(tmp, state->period); > > > > Uah, you use state->period here even though for the 2nd PWM the Divider > > might not be setup appropriately. > > I think that is 1 limitation here, the dts should make sure the period used for > different channels are same or at least they can share same divider, otherwise, > what if multiple channels can NOT find a divider good for every channel? How to > deal with this case? You should return -ERANGE or -EINVAL for the calls that cannot be satisfied. > > > [...] > > > +static int imx_tpm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > > + struct pwm_state *state) > > > +{ > > > + struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip); > > > + struct pwm_state curstate; > > > + unsigned long flags; > > > + > > > + imx_tpm_pwm_get_state(chip, pwm, &curstate); > > > + > > > + spin_lock_irqsave(&tpm->lock, flags); > > > + > > > + if (state->period != curstate.period || > > > + state->duty_cycle != curstate.duty_cycle || > > > + state->polarity != curstate.polarity) > > > + imx_tpm_pwm_config(chip, pwm, state); > > > + > > > + if (state->enabled != curstate.enabled) > > > + imx_tpm_pwm_enable(chip, pwm, state->enabled); > > > > This is wrong. This sequence: > > > > pwm_apply_state(pwm, { .duty_cycle = 0, .period = 10000, .enabled = > > true }); > > pwm_apply_state(pwm, { .duty_cycle = 10000, .period = > > 10000, .enabled = false }); > > > > must keep the output pin low which isn't guaranteed here. > > So you mean for every .apply operation, the channel MUST be disabled first, then config > it, then enable it? No. I only say that you should not configure the new period and duty cycle if in the end the hardware should be disabled. Always disabling is wrong, too. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |