Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp127048pxb; Fri, 16 Apr 2021 01:10:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAoeYc8hdd7lFooTjtBMZiv7QteZMOWK+y1LwgF4AsrH1E3xAPwkULEq+qaOBbkKrOTsOE X-Received: by 2002:a17:902:cec3:b029:eb:5441:9897 with SMTP id d3-20020a170902cec3b02900eb54419897mr8147636plg.48.1618560649889; Fri, 16 Apr 2021 01:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618560649; cv=none; d=google.com; s=arc-20160816; b=ch+juYuAx/sJHtzhU4tWBcijD9JxVXY6ov2b45RZNi26DzISMV93OdG0n/yGqzRnxa 2k4qPeugtTb6XM0U+R+oJX2jJbgryGiHfJn4bLkWHePOdJGfqV3GflWIBN0gfj5B6ec3 4E9SkP3r4W/rXkt0H+au5m1yt+mEdX83WPcW2vJ9Xr2Z5yXeFXSo9rGaq+S985tUsQxU CI6CVkRMoiyYy2Y3tj9GOkiQprKyGQQkR2zfow206FXjEw/jKKa1s7P1fvrvJzkH9Jh1 5cDXuO5X3wZqImg32PUNK+OIFuDpcpSDDvi9wsaDoqxZSgSOCv+vIe0D8cL+6qzMUZOm fH2A== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=o1mrqA/R0CXlEpgWTeuVOy4HtqFtnZVVF2CdjYdwYq4=; b=nXADQ5ffZGq5HmERozw6n9ejSZeoBDpwKKtkb+UPbvPYEpBkrLxOf/3jmq2fwkkHa3 zQCa8nv4XWrdf3Du4AHvrDnHmsBwCg8toJ1MdOcrMlLUVOC9DoHNe3SaOFb8vJU7tHWz N9tcK9IWbo3aYTNXnWggYKgyx8cZgWG7QqXbrYI6TDkgbWupZX+5JdZAw+qXD903GUJu IE+rklA+MJFWUhE1Oc19fajb0tO6A6Nh5YDgA+3oBv0UUhzIg6qgRIK9B16Y+JkIIj0y Sk19gM1Cw92npVAHOYUyf58lm/zwJd2FpNKGOmCktuIDzEfV+DRe5BqYxg835AOyYsZK bgrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=toshiba.co.jp Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si5531529pfh.98.2021.04.16.01.10.38; Fri, 16 Apr 2021 01:10:49 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=toshiba.co.jp Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239228AbhDPIIY (ORCPT + 99 others); Fri, 16 Apr 2021 04:08:24 -0400 Received: from mo-csw1515.securemx.jp ([210.130.202.154]:51128 "EHLO mo-csw.securemx.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235020AbhDPIIW (ORCPT ); Fri, 16 Apr 2021 04:08:22 -0400 Received: by mo-csw.securemx.jp (mx-mo-csw1515) id 13G87UGW003391; Fri, 16 Apr 2021 17:07:30 +0900 X-Iguazu-Qid: 34tr9jB2dbDVDmZAI3 X-Iguazu-QSIG: v=2; s=0; t=1618560450; q=34tr9jB2dbDVDmZAI3; m=yhkDNzpcSRv3VLZjqeMnV3i50xF81NUOuQ8lkDquMT8= Received: from imx12-a.toshiba.co.jp (imx12-a.toshiba.co.jp [61.202.160.135]) by relay.securemx.jp (mx-mr1511) id 13G87Sx8021320 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 16 Apr 2021 17:07:28 +0900 Received: from enc02.toshiba.co.jp (enc02.toshiba.co.jp [61.202.160.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by imx12-a.toshiba.co.jp (Postfix) with ESMTPS id BE3501000AA; Fri, 16 Apr 2021 17:07:28 +0900 (JST) Received: from hop101.toshiba.co.jp ([133.199.85.107]) by enc02.toshiba.co.jp with ESMTP id 13G87Sho013100; Fri, 16 Apr 2021 17:07:28 +0900 Date: Fri, 16 Apr 2021 17:07:21 +0900 From: Nobuhiro Iwamatsu To: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= Cc: Rob Herring , Thierry Reding , Lee Jones , devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, punit1.agrawal@toshiba.co.jp, yuji2.ishikawa@toshiba.co.jp, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/2] pwm: visconti: Add Toshiba Visconti SoC PWM support X-TSB-HOP: ON Message-ID: <20210416080721.oa7xdvu22w2b2rkf@toshiba.co.jp> References: <20210409230837.1919744-1-nobuhiro1.iwamatsu@toshiba.co.jp> <20210409230837.1919744-3-nobuhiro1.iwamatsu@toshiba.co.jp> <20210410135321.oissremqropvrpd3@pengutronix.de> <20210412025536.i5chpp6sighunvfx@toshiba.co.jp> <20210412070232.6q3cgqvuj53p4cmi@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210412070232.6q3cgqvuj53p4cmi@pengutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Thanks for your review. On Mon, Apr 12, 2021 at 09:02:32AM +0200, Uwe Kleine-K?nig wrote: > On Mon, Apr 12, 2021 at 11:55:36AM +0900, Nobuhiro Iwamatsu wrote: > > Hi Uwe, > > > > Thanks for your review. > > > > On Sat, Apr 10, 2021 at 03:53:21PM +0200, Uwe Kleine-K?nig wrote: > > > Hello, > > > > > > just a few small details left to criticize ... > > > > > > On Sat, Apr 10, 2021 at 08:08:37AM +0900, Nobuhiro Iwamatsu wrote: > > > > diff --git a/drivers/pwm/pwm-visconti.c b/drivers/pwm/pwm-visconti.c > > > > new file mode 100644 > > > > index 000000000000..99d83f94ed86 > > > > --- /dev/null > > > > +++ b/drivers/pwm/pwm-visconti.c > > > > @@ -0,0 +1,188 @@ > > > > +// SPDX-License-Identifier: GPL-2.0-only > > > > +/* > > > > + * Toshiba Visconti pulse-width-modulation controller driver > > > > + * > > > > + * Copyright (c) 2020 TOSHIBA CORPORATION > > > > + * Copyright (c) 2020 Toshiba Electronic Devices & Storage Corporation > > > > + * > > > > + * Authors: Nobuhiro Iwamatsu > > > > + * > > > > + */ > > > > + > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > + > > > > +#define PIPGM_PCSR(ch) (0x400 + 4 * (ch)) > > > > +#define PIPGM_PDUT(ch) (0x420 + 4 * (ch)) > > > > +#define PIPGM_PWMC(ch) (0x440 + 4 * (ch)) > > > > + > > > > +#define PIPGM_PWMC_PWMACT BIT(5) > > > > +#define PIPGM_PWMC_CLK_MASK GENMASK(1, 0) > > > > +#define PIPGM_PWMC_POLARITY_MASK GENMASK(5, 5) > > > > + > > > > +struct visconti_pwm_chip { > > > > + struct pwm_chip chip; > > > > + void __iomem *base; > > > > +}; > > > > + > > > > +static inline struct visconti_pwm_chip *to_visconti_chip(struct pwm_chip *chip) > > > > +{ > > > > + return container_of(chip, struct visconti_pwm_chip, chip); > > > > +} > > > > + > > > > +static int visconti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > > > + const struct pwm_state *state) > > > > +{ > > > > + struct visconti_pwm_chip *priv = to_visconti_chip(chip); > > > > + u32 period, duty_cycle, pwmc0; > > > > + > > > > + /* > > > > + * pwmc is a 2-bit divider for the input clock running at 1 MHz. > > > > + * When the settings of the PWM are modified, the new values are shadowed in hardware until > > > > + * the period register (PCSR) is written and the currently running period is completed. This > > > > + * way the hardware switches atomically from the old setting to the new. > > > > + * Also, disabling the hardware completes the currently running period and keeps the output > > > > + * at low level at all times. > > > > > > Can you please put a paragraph analogous to the one in pwm-sifive in the > > > same format. This simplified keeping an overview about the oddities of > > > the various supported chips. > > > > OK, I will check pwm-sifive's, and add. I will add the following : * Limitations: * - PIPGM_PWMC is a 2-bit divider (00: 1, 01: 2, 10: 4, 11: 8) for the input * clock running at 1 MHz. * - When the settings of the PWM are modified, the new values are shadowed * in hardware until the PIPGM_PCSR register is written and the currently * running period is completed. This way the hardware switches atomically * from the old setting to the new. * - Disabling the hardware completes the currently running period and keeps * the output at low level at all times. > > > > > > > > > + */ > > > > + if (!state->enabled) { > > > > + writel(0, priv->base + PIPGM_PCSR(pwm->hwpwm)); > > > > + return 0; > > > > + } > > > > + > > > > [...] > > > > + > > > > +static void visconti_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > > > > + struct pwm_state *state) > > > > +{ > > > > + struct visconti_pwm_chip *priv = chip_to_priv(chip); > > > > + u32 period, duty, pwmc0, pwmc0_clk; > > > > + > > > > + period = readl(priv->base + PIPGM_PCSR(pwm->hwpwm)); > > > > + if (period) > > > > + state->enabled = true; > > > > + else > > > > + state->enabled = false; > > > > > > If PIPGM_PCSR is 0 the hardware is still active and setting a new > > > configuration completes the currently running period, right? Then I > > > think having always state->enabled = true is a better match. > > > > If PIPGM_PCSR is 0, the hardware is stopped. Even if the settings of > > other registers are written, the values of other registers will not work > > unless PIPGM_PCSR is written. > > Correct me if I'm wrong, but how I understand it, PCSR is special as the > other registers are shadow until PCSR is written. (And that is > irrespective of which value is active in PCSR or what is written to > PCSR.) This is correct. > > > However, as a logic, if PIPGM_PCSR becomes 0, it is only > > visconti_pwm_apply () in this driver, > > so I think that this process should always be state-> enabled = true > > as you pointed out. > > I wil drop this, thanks. > > For me the critical (and only) difference between "off" and > "duty cycle = 0" is that when a new configuration is to be applied. In > the "off" state a new period can (and should) start immediately, while > with "duty_cycle = 0" the rising edge should be delayed until the > currently running period is over.[1] > > So the thing to do here (IMHO) is: > > Iff with PIPGM_PCSR = 0 configuring a new setting (that is finalized > with writing a non-zero value to PIPGM_PCSR) completes the currently > running period, then always assume the PWM as enabled. Yes, this device works that way. > > And so if the hardware is stopped and the counter is reset when 0 is > written to PIPGM_PCSR, model that as enabled = false. I don't think the current this driver can handle the above. As far as I can see your comment, I think I need to implement this, but after writing 0 to PIPGM_PCSR, driver need to confirm that signal has changed to low level and change state->enabled to false. But with this device has no way of knowing that the signal has changed to low level. > > Best regards > Uwe > > [1] In practise this is more difficult because several PWMs don't > complete periods in general. But the hardware under discussion luckily > isn't one of these. And (worse) there are other hardware implementations > where off doesn't emit an inactive level. I see. Best regards, Nobuhiro