All of lore.kernel.org
 help / color / mirror / Atom feed
* pwm-samsung: incorrect register values for 100% duty cycle
@ 2014-09-17 23:42 Daniel Drake
  2014-10-01 10:55 ` Tomasz Figa
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Drake @ 2014-09-17 23:42 UTC (permalink / raw)
  To: linux-pwm, linux-samsung-soc, Tomasz Figa

Hi,

I'm using pwm-samsung on Exynos4412 for a variable-brightness LED.

When the LED is set to maximum brightness via the pwm-leds driver, we
arrive at pwm_samsung_config with duty_ns = period_ns, i.e. 100% duty
cycle.

This function does:

    /* -1UL will give 100% duty. */
    --tcmp;
    writel(tcmp, our_chip->base + REG_TCMPB(pwm->hwpwm));

I think that comment is incorrect. If tcmp is written as -1UL then the
LED totally turns off. And there is nothing in the Exynos4412 manual
to suggest that -1UL should be set in the TCMP register for 100% duty.

If I remove that --tcmp line, so that 100% duty cycle is handled as
tcmp=0, the problem is solved: the LED turns on at max brightness when
the leds subsystem requests so.

Any ideas? Is this -1UL thing a quirk from older chip versions not
applicable to Exynos4?

Thanks
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pwm-samsung: incorrect register values for 100% duty cycle
  2014-09-17 23:42 pwm-samsung: incorrect register values for 100% duty cycle Daniel Drake
@ 2014-10-01 10:55 ` Tomasz Figa
  2014-10-02 19:27   ` Daniel Drake
  0 siblings, 1 reply; 5+ messages in thread
From: Tomasz Figa @ 2014-10-01 10:55 UTC (permalink / raw)
  To: Daniel Drake, linux-pwm, linux-samsung-soc

Hi Daniel,

On 18.09.2014 01:42, Daniel Drake wrote:
> Hi,
> 
> I'm using pwm-samsung on Exynos4412 for a variable-brightness LED.
> 
> When the LED is set to maximum brightness via the pwm-leds driver, we
> arrive at pwm_samsung_config with duty_ns = period_ns, i.e. 100% duty
> cycle.
> 
> This function does:
> 
>     /* -1UL will give 100% duty. */
>     --tcmp;
>     writel(tcmp, our_chip->base + REG_TCMPB(pwm->hwpwm));
> 
> I think that comment is incorrect. If tcmp is written as -1UL then the
> LED totally turns off. And there is nothing in the Exynos4412 manual
> to suggest that -1UL should be set in the TCMP register for 100% duty.

Looking at Figure 11-3 in 11.3.2 Basic Timer Operation chapter of Exynos
4412 public datasheet [1] (page 659), the calculation above seems
correct. The default state of timer output is high and if TCMP is set to
a value higher than TCNT, then it will never toggle to low.

[1]
http://www.samsung.com/global/business/semiconductor/file/product/Exynos_4_Quad_User_Manaul_Public_REV1.00-0.pdf

> 
> If I remove that --tcmp line, so that 100% duty cycle is handled as
> tcmp=0, the problem is solved: the LED turns on at max brightness when
> the leds subsystem requests so.

According to my computations, with tcmp=0 you should get exactly the
minimum supported duty cycle (1 / N, where N is the number of ticks of
period), not full brightness. Are you sure that you have the right
output polarity configured?

> 
> Any ideas? Is this -1UL thing a quirk from older chip versions not
> applicable to Exynos4?

Comparing few datasheets, the timers seem identical in this aspect.

Best regards,
Tomasz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pwm-samsung: incorrect register values for 100% duty cycle
  2014-10-01 10:55 ` Tomasz Figa
@ 2014-10-02 19:27   ` Daniel Drake
  2014-10-02 19:49     ` Tomasz Figa
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Drake @ 2014-10-02 19:27 UTC (permalink / raw)
  To: Tomasz Figa; +Cc: linux-pwm, linux-samsung-soc

Hi,

Thanks for looking into this.

On Wed, Oct 1, 2014 at 4:55 AM, Tomasz Figa <tomasz.figa@gmail.com> wrote:
>> I think that comment is incorrect. If tcmp is written as -1UL then the
>> LED totally turns off. And there is nothing in the Exynos4412 manual
>> to suggest that -1UL should be set in the TCMP register for 100% duty.
>
> Looking at Figure 11-3 in 11.3.2 Basic Timer Operation chapter of Exynos
> 4412 public datasheet [1] (page 659), the calculation above seems
> correct. The default state of timer output is high and if TCMP is set to
> a value higher than TCNT, then it will never toggle to low.
>
> [1]
> http://www.samsung.com/global/business/semiconductor/file/product/Exynos_4_Quad_User_Manaul_Public_REV1.00-0.pdf

I read that diagram a bit differently.
The default state of the output is high, but that is while PWM is
"inactive". It goes low at the point when the timer starts, and it
also goes low when the timer later restarts every time. So once we
enable PWM the output should be low.
It will go high once TCMP == TCNT, but because TCMP is placed at the
maximum value which is never hit, that will never happen, so the LED
stays off.

But I am confused on a few counts here...

I may have identified above why a maximum TCMP value would not result
in the output going high, but then why does the rest of the brightness
scale work? If I set brightness 200 (tcmp=6470, tcnt=29999) then the
LED is on dimly. If I set brightness 254 (tcmp=117, tcnt=29999) then
the LED comes on much brighter. But according to my above explanation
and looking at the diagram you referenced, such a decrease in the tcmp
value would result in a shorter time for which the output is high,
i.e. lower brightness, but actually the brightness increases.

If the output is high by default, why don't I see the LED turning on
in uboot before Linux has even loaded?

Does the above diagram really apply to Linux? Because Linux sets the
invert bit for all the channels in pwm_samsung_probe. So maybe that
diagram is irrelevant until we invert the TOUT signal shown there?

Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pwm-samsung: incorrect register values for 100% duty cycle
  2014-10-02 19:27   ` Daniel Drake
@ 2014-10-02 19:49     ` Tomasz Figa
  2014-10-02 20:20       ` Daniel Drake
  0 siblings, 1 reply; 5+ messages in thread
From: Tomasz Figa @ 2014-10-02 19:49 UTC (permalink / raw)
  To: Daniel Drake; +Cc: linux-pwm, linux-samsung-soc

On 02.10.2014 21:27, Daniel Drake wrote:
> Hi,
> 
> Thanks for looking into this.
> 
> On Wed, Oct 1, 2014 at 4:55 AM, Tomasz Figa <tomasz.figa@gmail.com> wrote:
>>> I think that comment is incorrect. If tcmp is written as -1UL then the
>>> LED totally turns off. And there is nothing in the Exynos4412 manual
>>> to suggest that -1UL should be set in the TCMP register for 100% duty.
>>
>> Looking at Figure 11-3 in 11.3.2 Basic Timer Operation chapter of Exynos
>> 4412 public datasheet [1] (page 659), the calculation above seems
>> correct. The default state of timer output is high and if TCMP is set to
>> a value higher than TCNT, then it will never toggle to low.
>>
>> [1]
>> http://www.samsung.com/global/business/semiconductor/file/product/Exynos_4_Quad_User_Manaul_Public_REV1.00-0.pdf
> 
> I read that diagram a bit differently.
> The default state of the output is high, but that is while PWM is
> "inactive". It goes low at the point when the timer starts, and it
> also goes low when the timer later restarts every time. So once we
> enable PWM the output should be low.

That's right. I believe this should match what I wrote in my mail.

> It will go high once TCMP == TCNT, but because TCMP is placed at the
> maximum value which is never hit, that will never happen, so the LED
> stays off.

Right. Although all the levels above don't take into account state of
the inverter. What's shown on the diagram in the datasheet is with
inverter disabled, which corresponds to Linux's PWM_POLARITY_INVERSED.

> 
> But I am confused on a few counts here...
> 
> I may have identified above why a maximum TCMP value would not result
> in the output going high, but then why does the rest of the brightness
> scale work? If I set brightness 200 (tcmp=6470, tcnt=29999) then the
> LED is on dimly. If I set brightness 254 (tcmp=117, tcnt=29999) then
> the LED comes on much brighter. But according to my above explanation
> and looking at the diagram you referenced, such a decrease in the tcmp
> value would result in a shorter time for which the output is high,
> i.e. lower brightness, but actually the brightness increases.

This is strange. I remember verifying various edge cases with a scope on
an Exynos4210-based Origen board and I don't recall any issues.
Unfortunately I don't have appropriate hardware to recheck this specific
case anymore.

Could you specify on what board you are testing this or how the LED is
wired?

> 
> If the output is high by default, why don't I see the LED turning on
> in uboot before Linux has even loaded?

Most likely because u-boot doesn't switch the pinmux from default input
to respective special function.

> 
> Does the above diagram really apply to Linux? Because Linux sets the
> invert bit for all the channels in pwm_samsung_probe. So maybe that
> diagram is irrelevant until we invert the TOUT signal shown there?

The diagram illustrates how the hardware works. It shows TOUT levels
without inverter enabled. Still, the inverter simply negates the signal,
so the diagram is applicable, just with the exception that you need to
consider the output inverted.

Best regards,
Tomasz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pwm-samsung: incorrect register values for 100% duty cycle
  2014-10-02 19:49     ` Tomasz Figa
@ 2014-10-02 20:20       ` Daniel Drake
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Drake @ 2014-10-02 20:20 UTC (permalink / raw)
  To: Tomasz Figa; +Cc: linux-pwm, linux-samsung-soc

On Thu, Oct 2, 2014 at 1:49 PM, Tomasz Figa <tomasz.figa@gmail.com> wrote:
> This is strange. I remember verifying various edge cases with a scope on
> an Exynos4210-based Origen board and I don't recall any issues.
> Unfortunately I don't have appropriate hardware to recheck this specific
> case anymore.
>
> Could you specify on what board you are testing this or how the LED is
> wired?

Its a new board prototype with Exynos4412. The PWM output connects to
a APL5606AKI-TRG chip which does AC-to-DC conversion and multiplies
the voltage, and outputs to a simple LED.

Not the easiest unknown setup to work with, I know. I'll get hold of a
multimeter and try to get a better understanding of what is happening.
You've given me a few ideas.

Thanks
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-02 20:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-17 23:42 pwm-samsung: incorrect register values for 100% duty cycle Daniel Drake
2014-10-01 10:55 ` Tomasz Figa
2014-10-02 19:27   ` Daniel Drake
2014-10-02 19:49     ` Tomasz Figa
2014-10-02 20:20       ` Daniel Drake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.