[BPI-R2] Control On-board LEDs

Does anyone know how to control(turn on or off) LEDs on the Banana PI R2? There are 6 LEDs and I want to be able to control them.

Hi Roshke

There is a script to control gpio, just for your reference.

SYS_FILE=/sys/devices/platform/1000b000.pinctrl/mt_gpio

mt_gpio_mode()
{
pin=$1
mode=$2

if [ ! -f ${SYS_FILE} ]; then
exit 1
fi

echo "mode $pin $mode" > ${SYS_FILE}

return 0
}

mt_gpio_dir()
{
pin=$1
dir=$2

if [ "x${dir}" == "xout" ]; then
dir_val=1
else
dir_val=0
fi

if [ ! -f ${SYS_FILE} ]; then
exit 1
fi

echo "dir $pin $dir_val" > ${SYS_FILE}

return 0
}

mt_gpio_out()
{
pin=$1
out=$2

if [ ! -f ${SYS_FILE} ]; then
exit 1
fi

echo "out $pin $out" > ${SYS_FILE}

return 0
}

mt_gpio_in()
{
pin=$1

if [ ! -f ${SYS_FILE} ]; then
exit 1
fi

echo "start $1" > ${SYS_FILE}
result=cat ${SYS_FILE} | grep "$1"

if [ "x${result}" == "x" ]; then
echo "can't get $pin status"
exit 2
fi

pin_val=echo ${result} | awk -F ' |-' '{print $5}'
if [ ${pin_val} == "0" ] ; then
return 0
else
return 1
fi

return 0

}

For GPIO22/GPIO23/GPIO24, we need an addtional steps that is to set EINTx_BOND_DIS to 1. image

found only 3 in Schematics

https://drive.google.com/file/d/0B4PAo2nW2KfnbVZzeDJERGd2SDg/view page 20 (LEDs/Keys)

GPIO239=LED0
GPIO241=LED1
GPIO240=LED2

not only just that. bpi-r2 board still has LEDs exported from MT6323 PMIC in upstream driver

&pwrap {
        mt6323 {
                mt6323led: led {
                        compatible = "mediatek,mt6323-led";
                        #address-cells = <1>;
                        #size-cells = <0>;

                        led@0 {
                                reg = <0>;
                                label = "bpi-r2:isink:green";
                                default-state = "off";
                        };

                        led@1 {
                                reg = <1>;
                                label = "bpi-r2:isink:red";
                                default-state = "off";
                        };

                        led@2 {
                                reg = <2>;
                                label = "bpi-r2:isink:blue";
                                default-state = "off";
                        };
                };
        };
};

Hi, I have tried to turn on and off GPIO239, 241 and 240 but no success, green LED stays still max lit and red one half. It’s probably me doing something wrong I’m new to this kinda stuff, never used Linux for GPIO and IOT, only on Dedicated Servers.

and now the interesting part :slight_smile:

how to set them to ON/OFF?

mt6323 sounds like a i2c chip used for sensors

So there’s still not a solution for this? :(( The green LED while power on is really bright and it could degrade with such brigthness I think and I want to have a better control over them so I can make them blink on wifi activity for example or storage I/O.

Why not using the gpio with an additional led+resistor?

My case has special like holes for those 3 LEDs and the green LED is too bright but yeah I will try to put a led with resistor.

Thanks

I’m so sorry that I write in this old subject, but I need exactly the same - have possibility to turn on/off system LEDs. I try to setup automatic configuration for BPI-R2 and I want to use this system LEDs to inform about the setup process finished. I would use sound but I cant find any speaker on this board. I can’t use any additional LEDs and resistors to connect it to GPIO port :frowning: @linkerosa Are you will be able to show me how I can use this mentioned by you? In /sys/devices/platform/ I have only mediatek,dummy_codec/, mediatek,mt7623_audio/, mediatek,mt7623_dai/, mt8173-cpufreq/ regarded to mediatek.

the leds itself seems to be mapped here: /sys/class/leds/ as

bpi-r2:isink:blue/                       
bpi-r2:isink:green/
bpi-r2:isink:red/ 

bpi-r2:pio:blue/   
bpi-r2:pio:green/ 
bpi-r2:pio:red/ 

but currently i have no idea, how to control them

mt6323 pmic has three leds , they can be found on bpi r2 board

you need to add them to dts and enable them in kconfig, as they’re done in upstream kernel https://elixir.bootlin.com/linux/v4.17-rc1/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L485

and how to use ?

on =>

echo 1 > /sys/class/leds/bpi-r2:isink:green/brightness

off =>

echo 0 > /sys/class/leds/bpi-r2:isink:green/brightness

blink =>

echo timer > /sys/class/leds/bpi-r2:isink:green/trigger

change blink frequency (on and off time in ms) =>

echo 100 > /sys/class/leds/bpi-r2:isink:green/delay_on

echo 100 > /sys/class/leds/bpi-r2:isink:green/delay_off

1 Like

thank you @linkerosa

works in my tests…red and blue simply going on with “echo 1”, green blinks in nearly 1s period (~500ms on and ~500ms off)

brightness sounds like a float-value, right? can it be dimmed?

delay-values are not existing in my system (4.14.34), tried to create => permission denied

btw. i had thought, that the leds are these next to gpio, but these are the leds near power-socket

OK, thanks all for exploration. Now, I have only this:

root@bpi-iot-ros-img:~# ls -l /sys/class/leds/
total 0
lrwxrwxrwx 1 root root 0 Apr 17 16:51 input4::capslock -> ../../devices/platform/1a1c0000.usb/usb1/1-1/1-1:1.0/0003:03F0:064A.0003/input/input4/input4::capslock
lrwxrwxrwx 1 root root 0 Apr 17 16:51 input4::numlock -> ../../devices/platform/1a1c0000.usb/usb1/1-1/1-1:1.0/0003:03F0:064A.0003/input/input4/input4::numlock
lrwxrwxrwx 1 root root 0 Apr 17 16:51 input4::scrolllock -> ../../devices/platform/1a1c0000.usb/usb1/1-1/1-1:1.0/0003:03F0:064A.0003/input/input4/input4::scrolllock

Because I use original kernel from Ubuntu image 1.2.1 (recompalied to have build in sata and raid support):

root@bpi-iot-ros-img:~# uname -a
Linux bpi-iot-ros-img 4.4.70-BPI-R2-Kernel

It is true?

/sys/class/leds/bpi-r2:isink:green/brightness can be 1 ~ 6

after you have to input echo timer > /sys/class/leds/bpi-r2:isink:green/trigger

and then the entires

/sys/class/leds/bpi-r2:isink:green/delay_on

and

/sys/class/leds/bpi-r2:isink:green/delay_off

can appear

can blinking disabled? i have echoed timer to trigger, now the delay_on and delay_off node are visible, but i see no difference when i change the values. if i enable these noedes first the green led flickers strange with different times

green is brighter that the other 2

@frank-w In which of your kernel version these system LEDs are supported?

as i wrote above…4.14.34…should be supported also in earlier 4.14.x

Thanks @frank-w and sorry, but I’m not catched this detail. Could you share the link for the sources of this kernel(s)?