Commit graph

6 commits

Author SHA1 Message Date
Nikolaus Voss e2e0897010 pwm: atmel: Fix calculation of prescale value
The prescale value used for calculating the period was incremented
afterwards, thus the resulting prescale value is by one too high.
This resulted in a PWM frequency only half as high as requested.

This patch moves the 64 bit division out of the prescale loop to
correct the above issue and make the calculation more efficient.

Signed-off-by: Nikolaus Voss <n.voss@weinmann-emt.de>
Tested-by: Bo Shen <voice.shen@atmel.com>
Acked-by: Bo Shen <voice.shen@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2014-09-25 08:52:39 +02:00
Alexandre Belloni cf3a384b34 pwm: atmel: set pwm_chip can_sleep flag
atmel_pwm_config() calls clk_get_rate() which might sleep, so we need to
set pwm_chip can_sleep flag.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2014-05-21 12:08:57 +02:00
Alexandre Belloni 916030db43 pwm: atmel: correct CDTY calculation
From the datasheet, the actual duty cycle is:

	(period - (1 / clk) * CDTY) / period

This actually correct the polarity of the PWM and solves the issue that
pwm-leds exhibits: when setting a duty cycle of 0 and then disabling a
channel, the level was wrong (1 when the polarity was normal and 0 when
the polarity was inversed).

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2014-03-18 20:47:48 +01:00
Alexandre Belloni 8db9e29fe5 pwm: atmel: Fix polarity handling
When atmel_pwm_config() calculates and then sets the prescaler, it is
overwriting the channel's CMR register so we are losing the CPOL
configuration.

As atmel_pwm_config() is always called before enabling a channel,
inverting the polarity doesn't work.

Fix that by reading CMR first and only overwriting the prescaler bits.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2014-03-18 20:47:31 +01:00
Bo Shen 6a6833563f pwm: atmel-pwm: Do not unprepare clock after successful registration
When the PWM controller is registered successfully, the clock can not
unprepare, so fix it.

Signed-off-by: Bo Shen <voice.shen@atmel.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2013-12-20 10:48:43 +01:00
Bo Shen 32b16d46e4 pwm: atmel-pwm: Add Atmel PWM controller driver
Add a PWM framework driver for the PWM controller found on Atmel SoCs.

Signed-off-by: Bo Shen <voice.shen@atmel.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
[thierry.reding: coding style and other minor cleanups]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
2013-12-17 11:26:42 +01:00