Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp529261imm; Wed, 6 Jun 2018 01:35:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIZZEHaBNObkL7nWQKc5rwng/NAlte55XCaso6guKFDEDsOl22jodcRBctnfAfax00rjs7C X-Received: by 2002:a62:968f:: with SMTP id s15-v6mr1512454pfk.191.1528274137582; Wed, 06 Jun 2018 01:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528274137; cv=none; d=google.com; s=arc-20160816; b=yZcVgjNUoVCw9DbM4DHJEB5/xfYZtPo/FlOb2FTu919092FSYijON+Nf31WoTYAka+ llh7WJC0qcc/SGk6+qedayUV5xpSjYYfpuHAFVu0KmqrfdRYi5wfKm/pkZY3GUJs6psm DHwNcnb4l1FejGsF8z8D+djwHvfu61fPKH6+FOJsCyW2pFus114Fo006uimF3D+rMJdO 24CBYoMrBb6w6ppyuLmLCRtHFXIRQG4LU9w1EQiOSgaEraXhnsfDgMfLWQY0pxjy2z7O Hb20mT0KI2KI2g1FFyoKraSiHzjIcUySA1EvE1W1KL3Z2/7vS+Cb/fIzw5u2+/N+FMSh Sksg== 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=yvK1+oE8Ji+tsGEq/cbT7A/rqMuNi+sXAu3mW4e2mqs=; b=zdrE8EpOa4s5B7Cs2sw2m84yMf7iUhru5gfk3VOnzbOn2yq1eUytlIn+kFptQmpCe+ fHYGrDIDdh9MbRtz1bNtxa9P06LEprHyUTD6cyOl1883X4TlgzTmFIU9jDwaYb8qItn2 23GS5QecuiGuN8wjOXpvM+bj4Db+r6Gea0RHKHpFG0FQmVIgqMoPLgVzbqwHrmuUXpKI cev0lninyXN4wK747T5iMPTgnZ8HutdJoi5FKjsg4qfuMNC5XlenJORQzlcw642u8g51 3TRuDTp6IdKECCZZ/yls74iOzw50jq8inbu/gArdFvDA0v4lsf4j23/Ypf0ngOb5X1Zv QyMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jJTarXqH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x65-v6si14181107pgb.598.2018.06.06.01.35.23; Wed, 06 Jun 2018 01:35:37 -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=@gmail.com header.s=20161025 header.b=jJTarXqH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932639AbeFFIea (ORCPT + 99 others); Wed, 6 Jun 2018 04:34:30 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39850 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932397AbeFFIe1 (ORCPT ); Wed, 6 Jun 2018 04:34:27 -0400 Received: by mail-wr0-f194.google.com with SMTP id w7-v6so5287554wrn.6; Wed, 06 Jun 2018 01:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=yvK1+oE8Ji+tsGEq/cbT7A/rqMuNi+sXAu3mW4e2mqs=; b=jJTarXqHWzRCqXExadVnwigEnplGeCkvVRB9u5JplwNCHqV0RzlB/QEM4WvRtmoyfC DjcVsUJKU3ldLZ/oJQ4cxYSrusPw0/7peno2yepPVD2Y5tEhqdB1w5VFIkqtN60+Ddi3 ImqWflvlXDcnaiSaQAkJZyRg0SFmRRMcQ59v91fr5a3s/JCWgsulurHuNS0VpE5j79O6 ZeYv8I8lReF9gd0YYe+owDDkiVnUUpvX9I4NT6kEmQnL9BzjztzlJrRmGj4SIA3wRFFn gwpgrvaTgWA0WftNqv3N0JO5F2EaVDaaDXuVp2+vAepM3czrOZfHp/gFA11U/D0pffO3 Cy1Q== 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=yvK1+oE8Ji+tsGEq/cbT7A/rqMuNi+sXAu3mW4e2mqs=; b=cErY7I0bGXRUSYYKT1rH7/Ta0797Jjs3xiBH1Q9Vmnw0e83epc4bCIhDycEZiRo4FC 94T1wIBCL2J+fMl4YjVVGqC4j1/XTbegQSE0hCcDwPgCVySbAhUEwXUf8amhHl74kVSO /UdtznMCDlsjAET4MHOMk+m78JGCUO5A9+HoxAk5fF9f/JS1Ld1yBP9XAfvvKiVhgCyB XeyZAaJIvL2fBprJ0nfggXI7Pu8jE3PTHj/BXT1VDb8/VCmyqdtD8Q6rUwqZeve39D6L wgcSxBIg1PQXXx5LP1B/SFpFZraOf2zYTrBb0sRyd8QEmX5fHZTH9lSXhtpbgnicCdn4 BVlg== X-Gm-Message-State: APt69E3w1AalNrhhD/eqTPzGOq30pTkHCRyaL1HFx3T5NxyJr7XRoWK6 I5HpVnPv7jmNygK+pYimx60= X-Received: by 2002:adf:e987:: with SMTP id h7-v6mr1477330wrm.102.1528274065805; Wed, 06 Jun 2018 01:34:25 -0700 (PDT) Received: from localhost (pD9E510DD.dip0.t-ipconnect.de. [217.229.16.221]) by smtp.gmail.com with ESMTPSA id u11-v6sm4936879wmd.7.2018.06.06.01.34.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Jun 2018 01:34:25 -0700 (PDT) Date: Wed, 6 Jun 2018 10:34:23 +0200 From: Thierry Reding To: shenwei.wang@nxp.com Cc: linux-pwm@vger.kernel.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] pwm: fsl-ftm: Support the new version of FTM block on i.MX8x Message-ID: <20180606083423.GE11810@ulmo> References: <20180524180848.61844-1-shenwei.wang@nxp.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="XuV1QlJbYrcVoo+x" Content-Disposition: inline In-Reply-To: <20180524180848.61844-1-shenwei.wang@nxp.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --XuV1QlJbYrcVoo+x Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 24, 2018 at 01:08:48PM -0500, shenwei.wang@nxp.com wrote: > On the new i.MX8x SoC family, the following changes were made on the FTM > block: >=20 > 1. Need to enable the IPG clock before accessing any FTM registers. Becau= se > the IPG clock is not an option for FTM counter clock source, it can't be > used as the ftm_sys clock. >=20 > 2. An additional PWM enable bit was added for each PWM channel in register > FTM_SC[16:23]. It supports 8 channels. Bit16 is for channel 0, and bit23 > for channel 7. Generally if you need to itemize changes in your commit message it is a good indication that you should be splitting up the patch into multiple logical changes. In this case, one possibility would be to turn this into three patches: 1. Introduce the concept on an "interface" clock which is by default the same as the ftm_sys clock. 2. Add support for enable bits, based on some per-compatible data structure (see for example pwm-tegra.c for an example of how to do this). 3. Enable support for the new SoC family by adding an instance of the per-compatible structure for that compatible string. > As the IP version information can not be obtained in any of the FTM > registers, a property of "fsl,has-pwmen-bits" is added in the ftm pwm > device node. If it has the property, the driver set the PWM enable bit > when a PWM channel is requested. I don't see a corresponding device tree bindings update for this change. Also, I don't think doing this via a separate property is the right way, you can just derive this from the new compatible string which you need to add anyway. So to the above patches, add: 0. Add DT bindings for new SoC family with a mention that they need to provide the new IPG clock. >=20 > Signed-off-by: Shenwei Wang > --- > drivers/pwm/pwm-fsl-ftm.c | 35 +++++++++++++++++++++++++++++------ > 1 file changed, 29 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c > index 557b4ea..0426458f 100644 > --- a/drivers/pwm/pwm-fsl-ftm.c > +++ b/drivers/pwm/pwm-fsl-ftm.c > @@ -86,7 +86,9 @@ struct fsl_pwm_chip { > struct regmap *regmap; > =20 > int period_ns; > + bool has_pwmen; > =20 > + struct clk *ipg_clk; > struct clk *clk[FSL_PWM_CLK_MAX]; > }; > =20 > @@ -97,16 +99,31 @@ static inline struct fsl_pwm_chip *to_fsl_chip(struct= pwm_chip *chip) > =20 > static int fsl_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) > { > + int ret; > struct fsl_pwm_chip *fpc =3D to_fsl_chip(chip); > =20 > - return clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); > + ret =3D clk_prepare_enable(fpc->ipg_clk); This is confusing because it looks as if you're breaking existing drivers, until you realize that... > + > + if ((!ret) && (fpc->has_pwmen)) { > + mutex_lock(&fpc->lock); > + regmap_update_bits(fpc->regmap, FTM_SC, > + BIT(pwm->hwpwm + 16), BIT(pwm->hwpwm + 16)); > + mutex_unlock(&fpc->lock); > + } > + > + return ret; > } > =20 > static void fsl_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) > { > struct fsl_pwm_chip *fpc =3D to_fsl_chip(chip); > =20 > - clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); > + if (fpc->has_pwmen) { > + mutex_lock(&fpc->lock); > + regmap_update_bits(fpc->regmap, FTM_SC, BIT(pwm->hwpwm + 16), 0); > + mutex_unlock(&fpc->lock); > + } > + clk_disable_unprepare(fpc->ipg_clk); > } > =20 > static int fsl_pwm_calculate_default_ps(struct fsl_pwm_chip *fpc, > @@ -363,7 +380,7 @@ static int fsl_pwm_init(struct fsl_pwm_chip *fpc) > { > int ret; > =20 > - ret =3D clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); > + ret =3D clk_prepare_enable(fpc->ipg_clk); > if (ret) > return ret; > =20 > @@ -371,7 +388,7 @@ static int fsl_pwm_init(struct fsl_pwm_chip *fpc) > regmap_write(fpc->regmap, FTM_OUTINIT, 0x00); > regmap_write(fpc->regmap, FTM_OUTMASK, 0xFF); > =20 > - clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); > + clk_disable_unprepare(fpc->ipg_clk); > =20 > return 0; > } > @@ -428,6 +445,10 @@ static int fsl_pwm_probe(struct platform_device *pde= v) > return PTR_ERR(fpc->clk[FSL_PWM_CLK_SYS]); > } > =20 > + fpc->ipg_clk =3D devm_clk_get(&pdev->dev, "ipg"); > + if (IS_ERR(fpc->ipg_clk)) > + fpc->ipg_clk =3D fpc->clk[FSL_PWM_CLK_SYS]; =2E.. fpc->ipg_clk is actually the same as fpc->clk[FSL_PWM_CLK_SYS] for older chips. I think this could be made more obvious by splitting this patch into several smaller ones as suggested above. > + > fpc->clk[FSL_PWM_CLK_FIX] =3D devm_clk_get(fpc->chip.dev, "ftm_fix"); > if (IS_ERR(fpc->clk[FSL_PWM_CLK_FIX])) > return PTR_ERR(fpc->clk[FSL_PWM_CLK_FIX]); > @@ -446,6 +467,8 @@ static int fsl_pwm_probe(struct platform_device *pdev) > fpc->chip.of_pwm_n_cells =3D 3; > fpc->chip.base =3D -1; > fpc->chip.npwm =3D 8; > + fpc->has_pwmen =3D of_property_read_bool(pdev->dev.of_node, > + "fsl,ftm-has-pwmen-bits"); As I said earlier, I think this should be derived from the compatible string. That is, you could have a data structure such as: struct fsl_pwm_soc { bool has_enable_bits; }; static const struct fsl_pwm_soc vf610_ftm_pwm =3D { .has_enable_bits =3D false, }; /* up to here would be part of patch 2 */ /* and this is part of patch 3, along with an entry in the OF * match table */ static const struct fsl_pwm_soc imx8x_ftm_pwm =3D { .has_enable_bits =3D true, }; Thierry --XuV1QlJbYrcVoo+x Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAlsXnIwACgkQ3SOs138+ s6GZMw/9Fpn2QrvI7aIOf1dAZDhR5JDtMV28XOGGLCJ/eRvyol+ApUp+AE1R0mUb CswVojEYCx+lWRewD96ESw6vvyQ0gt/6JWwsW5+0dAxr5+tis1dAdh5nqATU/nNV b7o2au+wKceweqghxfmdhPLdnKXfii7D54vMvait+PNl+pZWp55jwZil3x4ivDMz xfgmNH0IUwulQ10Mz/oPDYe/4QS5CIyIzfVRrtNNtiBo9Clez21Kna+qVWEGQvO0 iJhV9uFXx99yfBFmZkKoYHTNi5Ycz6o3RuEy+HJv8B5WXnnQ5Rh2SJPkmGXT31Fw 4HaOfQayB4n9JxEyh2NARiTxIL+ma1MZLjGJTuXxdJz+Q11shMALoopPA1xf2DKm XXLKl8qX+33KVE3Ez9ywVJCQFNw0ZtJPfq2yRXXaSuZyT5UZfS4igzcYFPau1U4r MCXIe7Ix94tCQkBUI5HVJsxKEM8y48MuIeP9VdPvJ08PPjHsgwvTG0matNHdFa1M t9cr30finADbgjd2h4dn/FGgCFDqHHoWS7/Euhl0ab1LNWQU6/797BV822rMar9B 6c+lc4cZLlr7u25suU/XZydp/Xg91FPCZUpVhMGfhJDNSBiT02kevUoGUTFH+vZX ELXKZRHAPSg08PoLHEU4Zj+4tCFD1RNiUm3A1Ub1hJI+v0HeSYg= =qFyJ -----END PGP SIGNATURE----- --XuV1QlJbYrcVoo+x--