PINE64
Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: ROCK64 (https://forum.pine64.org/forumdisplay.php?fid=85)
+--- Forum: Linux on Rock64 (https://forum.pine64.org/forumdisplay.php?fid=88)
+--- Thread: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins (/showthread.php?tid=5764)



Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - prof7bit - 02-24-2018

Are the two LEDs (white and red) that are connected to the RK805-1 out1 and out2 pins (which seem to be general purpose IO pins according to the data sheet) controllable from user space somehow? I have noticed that at least the u-boot-spi flash tool can blink the red LED and also at least one of the available images I tried turned off the red LED after successful boot. The image I am currently running leaves both LEDs turned on all the time.


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - t4_4t - 02-24-2018

The purpose is to turn off the LEDs?


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - prof7bit - 02-25-2018

The purpose would be to make them usable for my own application.

I have searched through /sys and found device tree entries, so there was at least the intention to make them known to the kernel and use them somehow:
Code:
find /sys -name *-led
/sys/firmware/devicetree/base/leds/power-led
/sys/firmware/devicetree/base/leds/standby-led

Code:
ls -la /sys/firmware/devicetree/base/leds/standby-led
total 0
drwxr-xr-x 2 root root  0 Feb 24 11:32 .
drwxr-xr-x 4 root root  0 Feb 24 11:31 ..
-r--r--r-- 1 root root  3 Feb 24 12:06 default-state
-r--r--r-- 1 root root 12 Feb 24 12:06 gpios
-r--r--r-- 1 root root 14 Feb 24 12:06 linux,default-trigger
-r--r--r-- 1 root root 12 Feb 24 12:06 name

Code:
cat /sys/firmware/devicetree/base/leds/standby-led/linux,default-trigger
disk-activity

Code:
cat -v /sys/firmware/devicetree/base/leds/standby-led/gpios
^@^@^@z^@^@^@^@^@^@^@^A

Some things like trigger look very similar to what I have read elsewhere about other Linux LED drivers but none of these tutorials does really apply to this one and I cannot find any device node to control them.


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - prof7bit - 02-25-2018

I have found that I can control them by bypassing the driver and directly writing to the chip registers. The RK805 is connected to i2c-1 with address 0x18 and the two GPIOs can be controlled by the two lowest bits in register 0x52.

They are low-active, so to turn them both off write 3 to the register (binary 0b00000011):


Code:
i2cset -f -y 1 0x18 0x52 3



and to turn them on set the corresponding bit to 0, so by writing any of the numbers 0, 1, 2, 3 to that register both LEDs can be controlled.

But this is not the proper way to do it!

I had to use -f because the rk808 driver is already using that bus address! I'm interfering with its function in a very dangerous way by issuing commands directly to the chip behind the driver's back. And it is the power supply chip, I guess I could wreak havok by accidentally changing one of the output voltages, I would rather not mess around on the i2c of this chip directly.
Is here somebody who knows enough about the rk808 driver to tell me the proper way to control these two bits in the out register of the chip or whether they are already registered in the sysfs as a gpio under some other obscure name that I did not find? Where should I look next?

there is also /sys/bus/platform/devices/rk8xx-gpio which belongs to this driver but I have no idea how it works and how to use it.

writing 0b11 to this register to turn them off will even survive a warm reboot! The LEDs are still off!
So neither the rk808 driver nor anything else will even try to initialize them, they don't seem to be controlled by anything at the moment, despite the entries in the device tree.


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - t4_4t - 02-25-2018

Code:
-- Override tiriger-source --
$ sudo sh -c "echo 'none' > /sys/devices/platform/leds/leds/power-led/trigger"
$ sudo sh -c "echo 'none' > /sys/devices/platform/leds/leds/standby-led/trigger"

-- LED on/off --
$ sudo sh -c "echo '0' > /sys/devices/platform/leds/leds/power-led/brightness"
$ sudo sh -c "echo '0' > /sys/devices/platform/leds/leds/standby-led/brightness"
$ sudo sh -c "echo '255' > /sys/devices/platform/leds/leds/power-led/brightness"
$ sudo sh -c "echo '255' > /sys/devices/platform/leds/leds/standby-led/brightness"

> So neither the rk808 driver nor anything else will even try to initialize them...
Some version of kernel that fails to initialize rk8xx-gpio also exists.
Therefore, its symptom depends on the version of kernel.


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - prof7bit - 02-25-2018

Quote:t4_4tCode:
-- Override tiriger-source --
$ sudo sh -c "echo 'none' > /sys/devices/platform/leds/leds/power-led/trigger"
$ sudo sh -c "echo 'none' > /sys/devices/platform/leds/leds/standby-led/trigger"

-- LED on/off --
$ sudo sh -c "echo '0' > /sys/devices/platform/leds/leds/power-led/brightness"
$ sudo sh -c "echo '0' > /sys/devices/platform/leds/leds/standby-led/brightness"
$ sudo sh -c "echo '255' > /sys/devices/platform/leds/leds/power-led/brightness"
$ sudo sh -c "echo '255' > /sys/devices/platform/leds/leds/standby-led/brightness"

> So neither the rk808 driver nor anything else will even try to initialize them...
Some version of kernel that fails to initialize rk8xx-gpio also exists.
Therefore, its symptom depends on the version of kernel.

there are no leds at all in /sys/devices/platform/leds

Code:
--(#)-- ls -la /sys/devices/platform/leds/
total 0
drwxr-xr-x  3 root root    0 Feb 25 12:13 .
drwxr-xr-x 76 root root    0 Feb 25 10:23 ..
-rw-r--r--  1 root root 4096 Feb 25 12:13 driver_override
-r--r--r--  1 root root 4096 Feb 25 12:13 modalias
lrwxrwxrwx  1 root root    0 Feb 25 12:13 of_node -> ../../../firmware/devicetree/base/leds
drwxr-xr-x  2 root root    0 Feb 25 12:13 power
lrwxrwxrwx  1 root root    0 Feb 25 12:13 subsystem -> ../../../bus/platform
-rw-r--r--  1 root root 4096 Feb 25 12:13 uevent


Code:
--(#)-- uname -r
4.4.103-rockchip-ayufan-175

I can't remember which of the downloadable images that was, i suspect it was one of the 0.6.x ones. I have already configured lots of stuff all over the place, so I can't just start over with a different image.

Can I install just the kernel from a different image without having to install and configure all the stuff again from scratch?


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - t4_4t - 02-25-2018

The kernel you are using is a version problem with "rk8xx-gpio".
As far as I know, I know that there are problems with the following Kernel versions.

x 0.6.2: jenkins-linux-build-rock-64-146 <-> 0.6.16: jenkins-linux-build-rock-64-177
# dmesg | grep "rk8xx-gpio: register"
[ 2.431774] rk8xx-gpio rk8xx-gpio: register rk8xx gpiochip fail: -28
# ls /sys/devices/platform/leds/leds/
ls: cannot access '/sys/devices/platform/leds/leds/': No such file or directory

----
o Other-ver:
# dmesg | grep "rk8xx-gpio: register"
[ 2.381873] rk8xx-gpio rk8xx-gpio: register rk8050 gpio successful
# ls /sys/devices/platform/leds/leds/
power-led standby-led

----
As kernel-upgrading may involve side effects,
Please do after taking a backup etc.

kernel upgrade: https://github.com/ayufan-rock64/linux-build/releases
example: ( @Stretch-minimal image )
download linux-image-4.4.103-rockchip-ayufan-187_0.6.21_arm64.deb
after
dpkg -i ./linux-image-4.4.103-rockchip-ayufan-187_0.6.21_arm64.deb


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - xalius - 02-25-2018

It also depends on how the leds are configured/bound in the devicetree for a certain kernel/image version:

https://github.com/ayufan-rock64/linux-kernel/blob/release-4.4/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts#L54


RE: Onboard LEDs connected to the RK805-1 out1 and out2 GPIO pins - prof7bit - 03-03-2018

it works indeed the way t4_4t said when I use a newer kernel than the one I accidentally happened to use when I posted this thread. There are now entries in the sysfs for both LEDs and they work.