Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching on backlight #1179

Closed
pssc opened this issue Oct 30, 2015 · 77 comments
Closed

Switching on backlight #1179

pssc opened this issue Oct 30, 2015 · 77 comments

Comments

@pssc
Copy link

pssc commented Oct 30, 2015

[ 165.533763] rpi-backlight rpi_backlight: Backlight change failed
[ 167.085803] rpi-backlight rpi_backlight: Backlight change failed
[ 168.281433] rpi-backlight rpi_backlight: Backlight change failed
[ 169.628353] rpi-backlight rpi_backlight: Backlight change failed
[ 169.742678] rpi-backlight rpi_backlight: Backlight change failed

Linux screenpi 4.1.12-v7+ #824 SMP PREEMPT Wed Oct 28 16:46:35 GMT 2015 armv7l GNU/Linux

I have an application controling the backlight via the

/sys/class/backlight/rpi_backlight/bl_power

Powering off writing 4 into the file seems reliable however power on fails.

I can sometime prod it into life via echoing more stuff into the file manually but its not reliable.

       val = level == 0 and "4" or "0"
        if self:getSettings()["backlight"] and (not only or only == "backlight") then
                dirNodeSetValue("/sys/class/backlight","bl_power",val,skipbacklight)
        end
end

function dirNodeSetValue(dir,node,val,skip)
        for entry in lfs.dir(dir) do repeat
                local entrydir = dir.."/"..entry

                if skip and skip[entry] then
                        break
                end
                local entrymode = lfs.attributes(entrydir, "mode")
                log:debug("dirNodeSetValue: ",entrydir," is ", entrymode)
                if entry:match("^%.") or (entrymode ~= "directory") then
                        break
                end

                local fblank = entrydir.."/"..node
                local mode = lfs.attributes(fblank,"mode")
                log:debug("dirNodeSetValue: ",fblank," mode is ", mode)
                if mode == "file" then
                        local fh = io.open(fblank,"w")
                        if fh then
                                log:info("dirNodeSetValue: ",fblank," to ",val)
                                fh:write(val)
                                fh:flush()
                                fh:close()
                        end
                end
                break -- oddness as we are in a double loop
        until true end
end

Code works on gpio_backlight for fbtft displays (adafruit28rt).

@pssc pssc changed the title Switching on baclight Switching on baclkight Oct 30, 2015
@pssc pssc changed the title Switching on baclkight Switching on backlight Oct 30, 2015
@P33M
Copy link
Contributor

P33M commented Oct 31, 2015

There's a known bug with the firmware glue switching the DSI backlight. A fix is in the patch queue.

@pssc
Copy link
Author

pssc commented Oct 31, 2015

Ok thanks, will retest then as soon as its pushed out...

@popcornmix
Copy link
Collaborator

Firmware is pushed. Please test after running rpi-update.

@pssc
Copy link
Author

pssc commented Nov 1, 2015

@popcornmix one on off cycle then off and back to:-

[   94.898890] rpi-backlight rpi_backlight: Backlight change failed
[   95.883632] rpi-backlight rpi_backlight: Backlight change failed
[   98.683035] rpi-backlight rpi_backlight: Backlight change failed
[  102.183071] rpi-backlight rpi_backlight: Backlight change failed
[  102.465310] rpi-backlight rpi_backlight: Backlight change failed
[  104.654344] rpi-backlight rpi_backlight: Backlight change failed
[  114.677035] rpi-backlight rpi_backlight: Backlight change failed

And if i leave it a while it seems to toggle again sometimes

@P33M
Copy link
Contributor

P33M commented Nov 2, 2015

You're switching the backlight at a fast interval. I can see two entries in the log that are less than 500ms apart.

Switching the backlight on and off that quickly will hit the ratelimit built into the firmware.

Is the issue still present if your do .. until loop incorporates a ~1 second delay?

@pssc
Copy link
Author

pssc commented Nov 2, 2015

@P33M I am triggering on a key press (activating soft off), I left the install overnight and tired triggering again no joy, I am also toggling the frame buffer blanking? at the same time. Even if it skips a setting it should fix after a pause and timer reset, is that rate limit there for any real reason? and as said this code path works fine for backlights provided via gpio_backlight and fbtft,

I will go back and generate an a application log and corresponding kernel log a am fairly sure that I only wrote once in a second to the sysfs bl power file but i didn't save the logs.

Phill.

@P33M
Copy link
Contributor

P33M commented Nov 2, 2015

Setting framebuffer blanking as well as backlight power is unnecessary - blanking the fb will turn off the backlight.

@pssc
Copy link
Author

pssc commented Nov 2, 2015

@P33M ok yes that's probably whats causing the backlight setting in rapid succession though it really should recover gracefully as left overnight and just switching on failed? i am not sure if toggling the blanking on a fbtft frame buffer toggles the bl(and not all display have bl control) which is why the codes in there for the blanking and of course blanking the HDMI output before calling vcgencmd display_power to cause HDMI screen power saving.

@P33M
Copy link
Contributor

P33M commented Nov 2, 2015

Part of the problem is that it appears the linux-side expects a backlight change to never fail - the backlight update function can return a value, but this value is ignored by the framebuffer update.
c.f. http://lxr.free-electrons.com/source/drivers/video/backlight/backlight.c#L40
Therefore there's the possibility that the backlight state and framebuffer blank/unblank could get out of sync until the next time the backlight is set.

I'll think about this a bit more.

@pssc
Copy link
Author

pssc commented Nov 2, 2015

@P33M something doesn't smell right in my case I am setting blank and power off then unblank and poweron, so it shouldn't matter that the second op failed as it would be set to the same state by either call...
I am doing a complete open close for each file toggle and not keeping the descriptor open.

@P33M
Copy link
Contributor

P33M commented Nov 2, 2015

Hm. That's right actually - even with the limit you should still be seeing the backlight actually switch state.

Can you post the full script you use so I can replicate the behaviour?

@pssc
Copy link
Author

pssc commented Nov 2, 2015

@P33M is available but theirs quite an overhead as this is an applet embedded in a build of squeeze play of the Pi debs in https://github.com/pssc/squeezeplay-dist its alpha and if you have don't have a Logitech music server you will have to abort the setup to connect to server by pressing home (q) toggles soft power. Probably best if I try and document my tests tonight with dmesg and application log output, I cant test from here and I can disable blank and/or backlight control will a simple option to test how thats affecting the interaction....

In summary before firmware update:-
Backlight powered off and I could sometimes prod back into life having cated several random values into the bl sysfs file possibly with several attempts at this.
After update:-
Backlight on / off ok then off and suck off but again just sometimes some toggling would bring it back on.

Re toggled off last night wouldn't switch on left for 7hrs tried to power on again in the morning no joy

@pssc
Copy link
Author

pssc commented Nov 3, 2015

@P33M ok disabling the back light control and just toggling the backlight in the app works so its some artefact of setting both bl and blaking

@pssc
Copy link
Author

pssc commented Nov 3, 2015

@P33M also first toggle blanks screen but doesnt toggle the backlight...

@P33M
Copy link
Contributor

P33M commented Nov 5, 2015

I've installed squeezeplay and can see the issue.

@pssc
Copy link
Author

pssc commented Nov 5, 2015

@P33M oh good its not just not me, by default it will toggle both (bl and blanking), there should be a menu option under setup advanced SqueezePi to toggle Bl control/ Blanking also add applet.Linux to info in the logging config so see what’s going on and sqeezeplay.ui to warn to reduce noise. Feed back appreciated as your probably about the 3rd user of that package...

@P33M
Copy link
Contributor

P33M commented Nov 5, 2015

For some reason, pressing Q (or waiting for a backlight wakeup) causes two writes to the mailbox interface in quick succession. The first always has a bl value of 0, the second is what the backlight is supposed to be, which is why switch-off works but not switch-on.

There is an obvious fix to make to the firmware - don't bother ratelimiting unless the backlight actually changes. This solves this particular case.

@P33M
Copy link
Contributor

P33M commented Nov 5, 2015

Can you test the start.elf from this link? Replace start.elf in /boot.

https://www.dropbox.com/s/jvyfhqij1vyb9ll/start.elf?dl=0

@pssc
Copy link
Author

pssc commented Nov 5, 2015

@P33M ware you still getting two writes event with one of the two options disabled? and did you see on the first toggle after reboot to blanking only that it didn't switch off? , say if the values the same not to bother with the rate limiting would seem to me reasonable.

@pssc
Copy link
Author

pssc commented Nov 5, 2015

@P33M start.elf will do, have to wait till about 11 this eve as the PI here at work doesn’t have a Official Pi LCD screen ;-)

@pssc
Copy link
Author

pssc commented Nov 5, 2015

@P33M ok seems to be good with both blanking and bl control enabled, however still seeing first toggle with blanking only not affecting the back light. initial sate odd somewhere?

@P33M
Copy link
Contributor

P33M commented Nov 6, 2015

If I reset the Pi when SqueezePi is running and the backlight is off, on the next boot I either get an infinite loop of backlight calls to the firmware or a call to turn the backlight on, but the framebuffer remains blanked.

The internal state of the driver and firmware remains consistent.

@pssc
Copy link
Author

pssc commented Nov 6, 2015

ok that’s different to the issue I am seeing which is when i reboot the pi the back-light on and console is unblanked and squeezepi is on (console blanks bl remains on and I only have blanking control enabled). I will try replicate that at home.

You could see if the what the application issues by enabling logging(Settings->Advanced->logging) at info of the applet.Linux module stuff should appear is syslog.

Are you running with bl and blanking control? (Settings->Advanced->SqueezePi) and is your instance connected to a server?

@pssc
Copy link
Author

pssc commented Nov 6, 2015

FYI I only issue bl/ blacking contol on soft power on/off events so struggling to figure how that loops occurring in the code unless your not connected to a server and thats causing the loop somehow.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Nov 6, 2015
…m edges

See: #463

firmware: di_adv: Add config setting to add nop delays to shader
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2150605#pid2150605

firmware: vcilcs: Avoid a potential deadlock when very threaded
See: #449

firmware: vrf: Add spinlock around vrf acquire/release calls to avoid restoring an invalid p10 from ISR context

firmware: rpi_display: only ratelimit if the backlight is actually changed
See: raspberrypi/linux#1179

firmware: di_adv: Support multiple instances of qpu deinterlace at SD resolution
See: popcornmix/omxplayer#386

linux: rpi-ft5406: Use interruptible sleep to avoid high load reported
See: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=125034

linux: dts: Added overlay for Adafruit PiTFT 2.8 capacitive touch screen
See: raspberrypi/linux#1192

linux: config: Add MCP320X
See: raspberrypi/linux#1189

linux: Build i2c_gpio module and add a device tree overlay to configure it
See: raspberrypi/linux#1183
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Nov 6, 2015
…m edges

See: raspberrypi/firmware#463

firmware: di_adv: Add config setting to add nop delays to shader
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2150605#pid2150605

firmware: vcilcs: Avoid a potential deadlock when very threaded
See: raspberrypi/firmware#449

firmware: vrf: Add spinlock around vrf acquire/release calls to avoid restoring an invalid p10 from ISR context

firmware: rpi_display: only ratelimit if the backlight is actually changed
See: raspberrypi/linux#1179

firmware: di_adv: Support multiple instances of qpu deinterlace at SD resolution
See: popcornmix/omxplayer#386

linux: rpi-ft5406: Use interruptible sleep to avoid high load reported
See: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=125034

linux: dts: Added overlay for Adafruit PiTFT 2.8 capacitive touch screen
See: raspberrypi/linux#1192

linux: config: Add MCP320X
See: raspberrypi/linux#1189

linux: Build i2c_gpio module and add a device tree overlay to configure it
See: raspberrypi/linux#1183
mkreisl added a commit to xbianonpi/xbian-package-firmware that referenced this issue Jan 9, 2017
- firmware: TC358762: Fix bad cast in backlight ratelimiting
  raspberrypi/linux#1179

- firmware: image_fx: Populate vdec_params when running in non-tunneled mode

- firmware: di_adv: Add direct support for YUV420

- bootcode: Enable the RNG as early as possible
- firmware: rng: Avoid initialising if already enabled

- firmware: IL Video_encode: Minimise fragmentation by default
  See: #698

- firmware: IL ISP: Correct image to be nFrameHeight high
- firmware: IL ISP: Handle dec_params from decoder

- firmware: di_adv: Minimise the number of uniform writes
- firmware: di_adv: Do qpu deinterlace in larger chunks
- firmware: di_adv: Also request core_freq=400 for hd deinterlace
- firmware: platform: Calculate volts for pi3 ring oscillator and store it away
- firmware: arm_loader: If boost freq is higher than max freq then increase to boost voltage
  See: arm_loader: If boost freq is higher than max freq then increase to boost voltage

- firmware: CEC code clean up
- firmware: CEC code cleanup 2
- firmware: Don't invert the status bit for broadcast

Revert: CEC code clean up
  See: #710
  See: Hexxeh/rpi-firmware#133
@apjavel
Copy link

apjavel commented Jan 22, 2017

Hi, I have been struggling with the same issues as described by others here. I'm on pi3 and latest official image.
Did a sudo rpi-update as suggested above and The problems went away. Thanks for the fix!

@michalsc
Copy link

@popcornmix Can the firmware be updated, so that small changes in backlight (within few percent from actual value) are allowed at faster rate? 500ms seems to be awfully slow.

My aim is to provide soft backlight adaptions (change from one value to another within approximately 5 seconds) in case of longer screen inactivity. It worked with older versions of firmware pretty good, but with the newest one, where 500ms limit is indeed working, it looks really disgusting :(

@P33M
Copy link
Contributor

P33M commented Feb 17, 2017

Ah. I see an issue here - the ratelimit is always applied, whereas the original reason for applying it was to limit hard switching on v1.0 display boards that only support on or off switching. Other boards don't have this limitation so there's no reason not to allow arbitrary backlight change rates.

popcornmix added a commit to raspberrypi/firmware that referenced this issue Feb 20, 2017
TC358762_DSI.c: Only ratelimit backlight changes on v1.0 boards
See: raspberrypi/linux#1179 (comment)
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this issue Feb 20, 2017
TC358762_DSI.c: Only ratelimit backlight changes on v1.0 boards
See: raspberrypi/linux#1179 (comment)
xingrz added a commit to xingrz/android_vendor_pifoundation_rpi3 that referenced this issue Feb 21, 2017
    commit 2b495acb7ed00d629bd865209858c9eccff8f77f
    Author: popcornmix <[email protected]>
    Date:   Mon Feb 20 14:04:15 2017 +0000

        bootromfs.c: Check for recovery.elf

        TC358762_DSI.c: Only ratelimit backlight changes on v1.0 boards
        See: raspberrypi/linux#1179 (comment)
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
…m edges

See: raspberrypi#463

firmware: di_adv: Add config setting to add nop delays to shader
See: http://forum.kodi.tv/showthread.php?tid=231092&pid=2150605#pid2150605

firmware: vcilcs: Avoid a potential deadlock when very threaded
See: raspberrypi#449

firmware: vrf: Add spinlock around vrf acquire/release calls to avoid restoring an invalid p10 from ISR context

firmware: rpi_display: only ratelimit if the backlight is actually changed
See: raspberrypi/linux#1179

firmware: di_adv: Support multiple instances of qpu deinterlace at SD resolution
See: popcornmix/omxplayer#386

linux: rpi-ft5406: Use interruptible sleep to avoid high load reported
See: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=125034

linux: dts: Added overlay for Adafruit PiTFT 2.8 capacitive touch screen
See: raspberrypi/linux#1192

linux: config: Add MCP320X
See: raspberrypi/linux#1189

linux: Build i2c_gpio module and add a device tree overlay to configure it
See: raspberrypi/linux#1183
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
raspberrypi/linux#1179

firmware: image_fx: Populate vdec_params when running in non-tunneled mode

firmware: di_adv: Add direct support for YUV420
neuschaefer pushed a commit to neuschaefer/raspi-binary-firmware that referenced this issue Feb 27, 2017
TC358762_DSI.c: Only ratelimit backlight changes on v1.0 boards
See: raspberrypi/linux#1179 (comment)
@michalsc
Copy link

michalsc commented Mar 2, 2017

@popcornmix Thank You. The last commits have fixed the issue, I can do slow and smooth backlight changes again :)

@roblan
Copy link

roblan commented Mar 4, 2017

@popcornmix Do You know when this fix will be available in stable apt-get update?

@popcornmix
Copy link
Collaborator

@roblan apt-get firmware is dated March 3rd, so will include the latest backlight fix.

@GreenEyes2796
Copy link

I have been having the touch screen wake up problem since we upgraded to Jessie - Dec 7 2016. I did an update and dist-upgrade on March 9 2017 and it has had no effect on the wake up problem. Any idea when the proper fix will be available or a simple mod to the OS ?

@GreenEyes2796
Copy link

I should add that the sometimes the screen will not wake up on touch or keyboard, but then a few minutes later it seems to work fine.

@popcornmix
Copy link
Collaborator

@GreenEyes2796 what does vcgencmd version report for you?

@GreenEyes2796
Copy link

Nov 25 2016 16:03:50
Copyright (c) 2012 Broadcam
version (long hex string) (clean) (releases)

Do you need the hex string version number? Thanks

@popcornmix
Copy link
Collaborator

Your firmware is too old. The dist-upgrade version should be newer than that (with a March date).

@GreenEyes2796
Copy link

Hmm. Just ran update and upgrade again and the version did not change. Known working internet connection. Any idea why I'm stuck in Nov. 2016?

@popcornmix
Copy link
Collaborator

I assume you rebooted after updating?
Have you ever run rpi-update or otherwise manually updated firmware?
You could try:

sudo apt-get update && sudo apt-get upgrade --reinstall raspberrypi-bootloader

@GreenEyes2796
Copy link

Yes. Did reboot after update and dist-upgrade.
I'll try your reinstall.

@GreenEyes2796
Copy link

It failed. I think all the dist-upgrades are failing, Maybe I should just download a current distribution?

@popcornmix
Copy link
Collaborator

Yes, I think installing the latest raspbian jessie image is probably advisable.

Something is wrong on your image. It may be possible to fix it, but that will probably be harder than reinstalling, and you'll never know if you have fixed everything.

@GreenEyes2796
Copy link

GreenEyes2796 commented Mar 13, 2017 via email

@GreenEyes2796
Copy link

GreenEyes2796 commented Mar 14, 2017 via email

@P33M P33M closed this as completed May 17, 2017
popcornmix pushed a commit that referenced this issue Jul 21, 2021
To dereference bond->curr_active_slave, it uses rcu_dereference().
But it and the caller doesn't acquire RCU so a warning occurs.
So add rcu_read_lock().

Splat looks like:
WARNING: suspicious RCU usage
5.13.0-rc6+ #1179 Not tainted
drivers/net/bonding/bond_main.c:571 suspicious
rcu_dereference_check() usage!

other info that might help us debug this:

rcu_scheduler_active = 2, debug_locks = 1
1 lock held by ping/974:
 #0: ffff888109e7db70 (sk_lock-AF_INET){+.+.}-{0:0},
at: raw_sendmsg+0x1303/0x2cb0

stack backtrace:
CPU: 2 PID: 974 Comm: ping Not tainted 5.13.0-rc6+ #1179
Call Trace:
 dump_stack+0xa4/0xe5
 bond_ipsec_offload_ok+0x1f4/0x260 [bonding]
 xfrm_output+0x179/0x890
 xfrm4_output+0xfa/0x410
 ? __xfrm4_output+0x4b0/0x4b0
 ? __ip_make_skb+0xecc/0x2030
 ? xfrm4_udp_encap_rcv+0x800/0x800
 ? ip_local_out+0x21/0x3a0
 ip_send_skb+0x37/0xa0
 raw_sendmsg+0x1bfd/0x2cb0

Fixes: 18cb261 ("bonding: support hardware encryption offload to slaves")
Signed-off-by: Taehee Yoo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
pelwell pushed a commit to pelwell/linux that referenced this issue Aug 2, 2021
[ Upstream commit 955b785 ]

To dereference bond->curr_active_slave, it uses rcu_dereference().
But it and the caller doesn't acquire RCU so a warning occurs.
So add rcu_read_lock().

Splat looks like:
WARNING: suspicious RCU usage
5.13.0-rc6+ raspberrypi#1179 Not tainted
drivers/net/bonding/bond_main.c:571 suspicious
rcu_dereference_check() usage!

other info that might help us debug this:

rcu_scheduler_active = 2, debug_locks = 1
1 lock held by ping/974:
 #0: ffff888109e7db70 (sk_lock-AF_INET){+.+.}-{0:0},
at: raw_sendmsg+0x1303/0x2cb0

stack backtrace:
CPU: 2 PID: 974 Comm: ping Not tainted 5.13.0-rc6+ raspberrypi#1179
Call Trace:
 dump_stack+0xa4/0xe5
 bond_ipsec_offload_ok+0x1f4/0x260 [bonding]
 xfrm_output+0x179/0x890
 xfrm4_output+0xfa/0x410
 ? __xfrm4_output+0x4b0/0x4b0
 ? __ip_make_skb+0xecc/0x2030
 ? xfrm4_udp_encap_rcv+0x800/0x800
 ? ip_local_out+0x21/0x3a0
 ip_send_skb+0x37/0xa0
 raw_sendmsg+0x1bfd/0x2cb0

Fixes: 18cb261 ("bonding: support hardware encryption offload to slaves")
Signed-off-by: Taehee Yoo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
popcornmix pushed a commit that referenced this issue Aug 11, 2021
[ Upstream commit 955b785 ]

To dereference bond->curr_active_slave, it uses rcu_dereference().
But it and the caller doesn't acquire RCU so a warning occurs.
So add rcu_read_lock().

Splat looks like:
WARNING: suspicious RCU usage
5.13.0-rc6+ #1179 Not tainted
drivers/net/bonding/bond_main.c:571 suspicious
rcu_dereference_check() usage!

other info that might help us debug this:

rcu_scheduler_active = 2, debug_locks = 1
1 lock held by ping/974:
 #0: ffff888109e7db70 (sk_lock-AF_INET){+.+.}-{0:0},
at: raw_sendmsg+0x1303/0x2cb0

stack backtrace:
CPU: 2 PID: 974 Comm: ping Not tainted 5.13.0-rc6+ #1179
Call Trace:
 dump_stack+0xa4/0xe5
 bond_ipsec_offload_ok+0x1f4/0x260 [bonding]
 xfrm_output+0x179/0x890
 xfrm4_output+0xfa/0x410
 ? __xfrm4_output+0x4b0/0x4b0
 ? __ip_make_skb+0xecc/0x2030
 ? xfrm4_udp_encap_rcv+0x800/0x800
 ? ip_local_out+0x21/0x3a0
 ip_send_skb+0x37/0xa0
 raw_sendmsg+0x1bfd/0x2cb0

Fixes: 18cb261 ("bonding: support hardware encryption offload to slaves")
Signed-off-by: Taehee Yoo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests