lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160331080033.GR2346@piout.net>
Date:	Thu, 31 Mar 2016 10:00:33 +0200
From:	Alexandre Belloni <alexandre.belloni@...e-electrons.com>
To:	Boris Brezillon <boris.brezillon@...e-electrons.com>
Cc:	Thierry Reding <thierry.reding@...il.com>,
	linux-pwm@...r.kernel.org,
	Mike Turquette <mturquette@...libre.com>,
	Stephen Boyd <sboyd@...eaurora.org>, linux-clk@...r.kernel.org,
	Mark Brown <broonie@...nel.org>,
	Liam Girdwood <lgirdwood@...il.com>,
	Kamil Debski <k.debski@...sung.com>, lm-sensors@...sensors.org,
	Jean Delvare <jdelvare@...e.com>,
	Guenter Roeck <linux@...ck-us.net>,
	Dmitry Torokhov <dmitry.torokhov@...il.com>,
	linux-input@...r.kernel.org, Bryan Wu <cooloney@...il.com>,
	Richard Purdie <rpurdie@...ys.net>,
	Jacek Anaszewski <j.anaszewski@...sung.com>,
	linux-leds@...r.kernel.org,
	Maxime Ripard <maxime.ripard@...e-electrons.com>,
	Chen-Yu Tsai <wens@...e.org>, linux-sunxi@...glegroups.com,
	Joachim Eastwood <manabian@...il.com>,
	Thomas Petazzoni <thomas.petazzoni@...e-electrons.com>,
	Heiko Stuebner <heiko@...ech.de>,
	linux-rockchip@...ts.infradead.org,
	Jingoo Han <jingoohan1@...il.com>,
	Lee Jones <lee.jones@...aro.org>, linux-fbdev@...r.kernel.org,
	Jean-Christophe Plagniol-Villard <plagnioj@...osoft.com>,
	Tomi Valkeinen <tomi.valkeinen@...com>,
	Robert Jarzmik <robert.jarzmik@...e.fr>,
	Kukjin Kim <kgene@...nel.org>,
	Krzysztof Kozlowski <k.kozlowski@...sung.com>,
	linux-samsung-soc@...r.kernel.org, intel-gfx@...ts.freedesktop.org,
	Daniel Vetter <daniel.vetter@...el.com>,
	Jani Nikula <jani.nikula@...ux.intel.com>,
	Jonathan Corbet <corbet@....net>, linux-doc@...r.kernel.org,
	David Airlie <airlied@...ux.ie>,
	Daniel Vetter <daniel@...ll.ch>,
	dri-devel@...ts.freedesktop.org,
	linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
	Hartley Sweeten <hsweeten@...ionengravers.com>,
	Ryan Mallon <rmallon@...il.com>,
	Alexander Shiyan <shc_work@...l.ru>, Milo Kim <milo.kim@...com>
Subject: Re: [PATCH v5 26/46] pwm: sun4i: implement hardware readout

On 30/03/2016 at 22:03:49 +0200, Boris Brezillon wrote :
> Implement ->get_state() instead of only initializing the polarity in
> the probe function.
> 
> This implementation also takes care of keeping the PWM clk enabled if at
> least one of the PWM exported by the PWM chip is already enabled, which
> should prevent glitches.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@...e-electrons.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@...e-electrons.com>

> ---
>  drivers/pwm/pwm-sun4i.c | 74 ++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 55 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> index 03a99a5..34cb296 100644
> --- a/drivers/pwm/pwm-sun4i.c
> +++ b/drivers/pwm/pwm-sun4i.c
> @@ -252,11 +252,65 @@ static void sun4i_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
>  	clk_disable_unprepare(sun4i_pwm->clk);
>  }
>  
> +static void sun4i_pwm_get_state(struct pwm_chip *chip,
> +				struct pwm_device *pwm,
> +				struct pwm_state *pstate)
> +{
> +	struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip);
> +	unsigned int clk_rate = clk_get_rate(sun4i_pwm->clk);
> +	int prescaler, prescalerid;
> +	int ret;
> +	u32 val;
> +
> +	ret = clk_prepare_enable(sun4i_pwm->clk);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to enable PWM clock");
> +		return;
> +	}
> +
> +	val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);
> +	if (val & BIT_CH(PWM_ACT_STATE, pwm->hwpwm))
> +		pstate->polarity = PWM_POLARITY_INVERSED;
> +	else
> +		pstate->polarity = PWM_POLARITY_NORMAL;
> +
> +	if ((val & BIT_CH(PWM_EN, pwm->hwpwm)) &&
> +	    (val & BIT_CH(PWM_CLK_GATING, pwm->hwpwm)))
> +		pstate->enabled = true;
> +	else
> +		pstate->enabled = false;
> +
> +	pstate->period = 0;
> +	pstate->duty_cycle = 0;
> +	prescalerid = (val >> (PWMCH_OFFSET * pwm->hwpwm)) & PWM_PRESCAL_MASK;
> +	prescaler = prescaler_table[prescalerid];
> +	if (prescaler) {
> +		u64 timens;
> +
> +		clk_rate /= prescaler;
> +
> +		val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm));
> +
> +		timens = ((val >> 16) & PWM_PRD_MASK) + 1;
> +		timens *= NSEC_PER_SEC;
> +		do_div(timens, clk_rate);
> +		pstate->period = timens;
> +
> +		timens = val & PWM_DTY_MASK;
> +		timens *= NSEC_PER_SEC;
> +		do_div(timens, clk_rate);
> +		pstate->duty_cycle = timens;
> +	}
> +
> +	clk_disable_unprepare(sun4i_pwm->clk);
> +}
> +
>  static const struct pwm_ops sun4i_pwm_ops = {
>  	.config = sun4i_pwm_config,
>  	.set_polarity = sun4i_pwm_set_polarity,
>  	.enable = sun4i_pwm_enable,
>  	.disable = sun4i_pwm_disable,
> +	.get_state = sun4i_pwm_get_state,
>  	.owner = THIS_MODULE,
>  };
>  
> @@ -307,8 +361,7 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
>  {
>  	struct sun4i_pwm_chip *pwm;
>  	struct resource *res;
> -	u32 val;
> -	int i, ret;
> +	int ret;
>  	const struct of_device_id *match;
>  
>  	match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
> @@ -345,24 +398,7 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, pwm);
>  
> -	ret = clk_prepare_enable(pwm->clk);
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to enable PWM clock\n");
> -		goto clk_error;
> -	}
> -
> -	val = sun4i_pwm_readl(pwm, PWM_CTRL_REG);
> -	for (i = 0; i < pwm->chip.npwm; i++)
> -		if (!(val & BIT_CH(PWM_ACT_STATE, i)))
> -			pwm_set_polarity(&pwm->chip.pwms[i],
> -					 PWM_POLARITY_INVERSED);
> -	clk_disable_unprepare(pwm->clk);
> -
>  	return 0;
> -
> -clk_error:
> -	pwmchip_remove(&pwm->chip);
> -	return ret;
>  }
>  
>  static int sun4i_pwm_remove(struct platform_device *pdev)
> -- 
> 2.5.0
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ