You are not logged in.

#1 2013-03-17 22:03:09

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

[SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Hi.
I'm seeking for a person who is eager to make a contribution to opensource wink

Recently I've got Lenovo X220 laptop and noticed that it makes me sick. Eventually I discovered a screen flickering that is caused by low PWM frequency (backlight brightness is controlled with PWM).

This issue is so ubiquitous, that some folk created simple utility for Windows to adjust PWM frequency by interacting with Intel driver.
http://pastebin.com/6iirMbfc

It's only 50 lines of code. So I hope that accomplishing the same under linux won't be very hard.

As you might have guessed, I don't have any experience nor knowledge in C. Thus I'm asking here for help.

So... anyone eager to create similar utility for linux?
Hails and beer for the author implied wink

P.S. Of course, I would be very glad to hear, that my question is non-sense because our belowed linux already provides handy ways to control PWM frequency (though, I was not able to find anything like this).

UPD: that damn screen flickering made me not only sick, but also dull.
I've just found this in archwiki
https://wiki.archlinux.org/index.php/Ba … at_care.29
Seems like it does the same, that mentioned utility does. Though, some background knowledge is required. Appreciate any help with this.

Solution
Thank you all, folks.
Solution is an wiki already.
https://wiki.archlinux.org/index.php/Ba … 15_only.29

Last edited by eDio (2013-04-21 16:22:23)

Offline

#2 2013-03-18 00:09:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,193

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

That Windows code does depend on a call to the Windows driver.  Unfortunately, that means that code cannot be directly ported to linux -- It is highly unlikely the Linux driver has the same API as does Windows.
Setpci might work, but to use it one must know about the register map for the PCI card.  Of course, there is no guarantee that the backlight is even controlled by a PCI card.  What video system does that laptop use?

The only suggestion I can offer in the short term is to try running the brightness all the way up.  If the PWM duty cycle is 100% (or close to it), you will experience less flicker.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2013-03-18 22:01:35

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Thanks for your reply.
Unfortunately running the brightness all the way up is not a solution, screen is too bright.
Answering your question about video in that laptop: it is Intel HD3000 (Sandy Bridge).

I made a quick search regarding backlight control in Linux. Seems like there is (was) even some API for backlight control. At least, some related header files in kernel sources are mentioned on internet. Unfortunately, I have no time right now to learn all this stuff (very interesting stuff, I have to say), but I have strong belief, that driver API may expose some procedures to adjust PWM frequency.

I'm eager to try to ask for some help on mailing lists which Intel driver developers might attend in. Do you know such mailing lists? And do you think this is appropriate?

As for setpci. Readme of the IntelPWMControl states that PWM frequency adjustment is achieved by writing some values to HW registers. I had no enough time to perform a thorough search, but googling by keywords "Intel HD3000 registers", "HD3000 developers guide" and similar gave no meaningful results.
I've already tried to contact developer of the mentioned Windows utility (still waiting for his response). Perhaps, he knows, what those calls to Windows driver do.

Not too much done from my side yet. I'm really very low on free time right now, but will write about any progress here.

Offline

#4 2013-03-18 23:08:25

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,193

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

eDio wrote:

Thanks for your reply.
Unfortunately running the brightness all the way up is not a solution, screen is too bright....

non-polarized sun glasses tongue


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2013-03-19 07:07:00

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

ewaller wrote:

non-polarized sun glasses tongue

In my particular case, polarization is not an issue: polarization direction in my polaroid glasses is collinear with polarization of light emitted by display tongue And yes, I've tried that already smile)))

Found this whitepaper
http://download.intel.com/embedded/proc … 324567.pdf

Offline

#6 2013-03-21 22:12:35

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

I've found some patch to fix default PWM frequency in i915
http://web.archiveorange.com/archive/v/ … BgDr5oIynd

From the code of this patch I've got an address of a register that controls PWM frequency 0xc8254. I was not able to determine anything else. That patch seems to be applicable to an old kernel so I had no any context (new kernel in the Linus's github repo doesn't look very similar). Also, my "native" programming language is java so I'm a little bit scared by C syntax smile .

To manipulate Intel GPU registers one can use intel_reg_read and intel_reg_write programs from the community/intel-gpu-tools.

By default, register contained value

0 x 12 28 12 28

Experimentally I was able to determine, that register controls the period of PWM modulation (1/frequency).

The most comfortable value for me is *0x03000000*.

I'm going to put this info to the wiki on the weekend. I'm sure it'll be useful for others.

C+Linux programming adepts are welcome to write an application for user-friendly PWM modulation frequency adjustment wink

P.S. forgot to mention that Linux rocks! I can't imagine investigations like this in other OSes.

Last edited by eDio (2013-03-21 22:16:18)

Offline

#7 2013-03-22 16:16:59

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Nice job!

Intel docs are here https://01.org/linuxgraphics/documentat … ation-prms
for sandy bridge https://01.org/linuxgraphics/sites/defa … _part3.pdf (page 54,55)

It works just fine.  Added "intel_reg_write 0xc8254 0x07a107a1" to /etc/rc.local to get 500 Hz PWM on Toshiba C850 (default is 200 Hz).

Offline

#8 2013-03-23 13:57:11

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

medvegiypreved
Thanks for the info! It is very helpful.
P.S. I like your nickname, by the way wink

Offline

#9 2013-03-23 14:32:09

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Could you please tell me if my understanding is correct?

Resulting PWM modulation frequency is determined by formula
(reg_c6204 * 1e6 * 128) / (reg_c8254)

where reg_n is register with address n.

reg_c6204 thus is reference clock
reg_c8254 represents a value lineary dependent of pwm modulation period

If reference clock is 125 MHz (0x7D), then default value of reg_c8254 in my laptop (0x12281228) will lead to frequency of 52.5 Hz (at least, it feels almost like this). So formula seems to be correct, though I would like to be sure.

Thanks in advance.

Offline

#10 2013-03-23 15:00:54

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,193

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

That looks like it might be correct.  Running your numbers, I came up with 52.5Hz.

But... You stated 125MHz as a reference clock, but the numerator = reg_c6204 * 128 * 1e6.  Is there a disconnect between the 125 and the 128 ??

Also, I am sure your power line frequency is 50Hz.  A 52Hz PWM may well beat with 50Hz flicker in your lighting to create a 2.5Hz beat frequency.

Re-running the numbers using 125 instead of 128 comes up with 51.3 Hz.  That would create a more palatable 1.3Hz beat.  You might play with the numbers to try to hit 50Hz exactly.  On the other hand, I grew up in the world of NTSC TV rather than PAL.  Our frame rate is 60Hz rather then PAL's 50Hz.  Whenever I visited a country that used PAL, I was startled at how the 50Hz frame rates had noticeable flicker. 

In the end, I guess it is up to the observer flicker, or beat?
Great job, by the way... This thread is probably very useful to many members.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#11 2013-03-23 21:24:46

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

I didn't feel any beats because by coincidence I've used laptop only on daylight or under fluorescent light.
As for the 128 multiplier, it is mentioned in Intel docs

This value represents the period of the
PWM stream in PCH display raw clocks multiplied by 128.

In the end, I guess it is up to the observer flicker, or beat?

I'm sorry, I didn't get your last question (my English isn't good enough).

Last edited by eDio (2013-03-23 21:25:16)

Offline

#12 2013-03-23 22:12:50

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,193

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Observer generally means the person who is watching (observing) an experiment or other event.
By flicker, I mean something that flashes at a fairly high rate, but at a rate that can be perceived.

Beat is a phenomenon in which, if there are two signals that have different frequencies, say 50Hz, and 52.5Hz; the signals will mix such that an observer will perceive (see)  a signal that is the sum of the two frequencies (102.5 Hz), and another that is the difference of the two frequencies (2.5Hz).  The 102.5Hz will not be noticed by the human eye.  The 2.5Hz will be seen as the brightness 'pulsing' every third of a second or so.  What I meant by the question was, the science does not matter as long as what you see makes you happy.

In English, there is a great cliché: "Beauty is in the eye of the beholder"


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#13 2013-03-24 16:58:57

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

eDio, I think, you've made a mistake somewhere. 180 is absolute minimum PWM AFAIK.

Looks like it is

PWM = base clock in register 0xc6204 / 128 / 31:16 bits value in register 0xc8254.

For example, your PWM will be = 125 MHz / 128 / 0x1228 = 125000000 / 128 / 4632 = 210,829555268

...and value, you should write to 0xc8254, is = base clock / 128 / desired PWM

And don't forget about 0:15 bits in 0xc8254. Looks like it's not used on my machine, but I think it's safe to just write the same value here too, because it is said in pdf 

This value overrides the CPU control of PWM duty cycle when the PWM PCH Override Enable bit is
set. This field determines the number of time base events for the active portion of the PWM backlight
control. This should never be larger than the frequency field.

So, if you get 0x1228, just write 0x12281228 to the register.

And thanks for base freq register hint. wink

Last edited by medvegiypreved (2013-03-24 17:07:27)

Offline

#14 2013-03-24 21:41:19

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

medvegiypreved
Seems like you're right. Thanks for pointing out!

This means, that 0x03000300 corresponds to 1.2 kHz. Doesn't feel safe! Lowered the value to 0x05000500 (approx. 700 Hz).

The only thing I still can't believe is that default value 1228 corresponds to 200 Hz. I understand that LEDs don't have any afterglow (comparing to CRT monitors and incandescence lamps), but I couldn't expect 200 Hz flicker to be so noticeable and hard on my eyes.

Offline

#15 2013-03-25 00:37:34

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

200 Hz is not the rate of the flicker you are noticing. The threshold at which the human eye can observe flicker is around 60 Hz, same rate as NTSC TV (more by coincidence than by design, IIRC). What you see is caused by some other periodic signal that interacts with the 200 Hz PWM signal to give a beat frequency that is just at the edge of your perception, probably 50-70 Hz. That secondary signal could be from some part of the laptop, although off the top of my head the power outlet seems a more likely culprit.

It could also be that because the PWM frequency (200 Hz) is a whole number multiple of the AC power frequency, you're seeing a 50Hz flicker exaggerated by the fact that every "trough" in the 50Hz signal coincides exactly with another "trough" in the 200 Hz signal. You could test that theory, since you have a laptop, by disconnecting it from mains power and taking it somewhere the 50Hz signal couldn't reach you.

You could also try setting the frequency lower than 200 but not at a multiple of 50, say 188 Hz or something like that, and see if you continue to see flicker. No guarantees.

Last edited by Trent (2013-03-25 00:38:13)

Offline

#16 2013-03-25 08:37:11

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

but I couldn't expect 200 Hz flicker to be so noticeable and hard on my eyes.

I can see 200 Hz on solid 60% gray and x2go client login screen (gray fill on right). I can even  see it on default ubuntu background image if I try hard.

It might be some interference with 60 Hz refresh or something else, so it's not actually 200, like Trent said. Anyway, altering pwm freq fixed it for me.

Your flicker may be from lcd inversion (infamous Vcom voltage). Check on this page (info and inversion tests) http://www.techmind.org/lcd/

And, do you still see flicker on 700 Hz?

Trent wrote:

The threshold at which the human eye can observe flicker is around 60 Hz

Very common misunderstanding

same rate as NTSC TV (more by coincidence than by design, IIRC).

Nope, it is all because of electricity frequency and bad filters. wink

Last edited by medvegiypreved (2013-03-26 09:20:00)

Offline

#17 2013-03-25 10:48:48

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

medvegiypreved wrote:

I can see 200 Hz on solid 60% gray and x2go client login screen (purple fill on right). I can even  see it on default ubuntu background image if I try hard.

On a screen with a 200 Hz refresh rate, powered by a battery and removed from any AC power source?

Trent wrote:

The threshold at which the human eye can observe flicker is around 60 Hz

Very common misunderstanding

Care to elaborate? I'm always willing to correct my misunderstandings...

Nope, it is all because of electricity frequency and bad filters. wink

That's what I meant by "coincidence". 60 Hz was a more or less arbitrary choice for AC power distribution back before TV was a thing. It just happens to approximately coincide with the flicker fusion threshold. (It also happens to be right around the most hazardous frequency to be shocked at.)

Edited for accuracy and source

Last edited by Trent (2013-03-25 13:29:50)

Offline

#18 2013-03-26 09:42:44

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

On a screen with a 200 Hz refresh rate, powered by a battery and removed from any AC power source?

Yes, both

Care to elaborate?

Not really big_smile http://www.100fps.com/how_many_frames_c … ns_see.htm
Nice site about video deinterlace.

(It also happens to be right around the most hazardous frequency to be shocked at.)

Heh :E

Offline

#19 2013-03-26 23:31:20

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

medvegiypreved wrote:

On a screen with a 200 Hz refresh rate, powered by a battery and removed from any AC power source?

Yes, both

Interesting. It still seems more likely to me that you're seeing a beat frequency caused by some other signal. There are plenty of possible candidates.

I'm not sure what on that page suggests to you that the eye can detect flicker of a static image at rates greater than 60 Hz... but this is beginning to go way OT.

Offline

#20 2013-03-27 07:08:31

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

It still seems more likely to me that you're seeing a beat frequency caused by some other signal.

Photo resistor does not shows any other frequency except 200 and some noise

I'm not sure what on that page suggests to you

I'm not sure what you have read the page. Not going to quote it here.

Offline

#21 2013-07-02 23:07:21

jberryman
Member
Registered: 2013-07-02
Posts: 1

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Does anyone have guidance on what would be a safe maximum frequency, or if that's hardware-specific is there a way to figure that out?

Also I'm puzzled by something: when I have my screen brightness on the maximum (via the hotkeys, I'm not sure what mechanism is used under the hood) and then bump up the PWM frequency the screen brightness immediately increases. Does this mean that the maximum brightness at the previous PWM frequency was still pulsing?

Offline

#22 2013-07-08 16:24:05

medvegiypreved
Member
Registered: 2013-03-22
Posts: 6

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

jberryman wrote:

...when I have my screen brightness on the maximum ... and then bump up the PWM frequency the screen brightness immediately increases.

I don't see any changes on my hardware.

Does this mean that the maximum brightness at the previous PWM frequency was still pulsing?

Use pencil test, Luke! smile

Offline

#23 2013-09-01 13:27:55

AleXoundOS
Member
From: Russia
Registered: 2009-07-18
Posts: 31
Website

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Does anyone know the maximum allowed frequency and what's the drawback of using very high frequency (maybe it affects powersaving or damages screen) ?

Offline

#24 2014-11-22 04:09:52

mark001
Banned
Registered: 2014-11-17
Posts: 9

Re: [SOLVED] Control PWM frequency of LED-backlight in Thinkpad laptops

Hello

Please give me a tip...

I faced the pwm problem for i915 as well - intel HD Graphics/Bay Trail/ Sandy Bridge... Currently I have 60Hz by default but EDID outputs I need 77.000MHz... It causes eyes strain in 20-30 minutes... I found this link https://wiki.archlinux.org/index.php/ba … 15_only.29 to solve the issue; So I installed the  intel-gpu-tools but every time I input

- intel_reg_read 0x61254
or
- intel_reg_read 0xC8254

... it returns 0x0 only sad So I am a bit confused how do I know what address I should enter in my case and how to know the address? Please guide me

p.s kernel 3.16.5

Last edited by mark001 (2014-11-22 04:16:36)

Offline

Board footer

Powered by FluxBB