Incorrect sysfs file is used for backlight control

I'm porting Ubuntu Touch to the Xiaomi Redmi K20 Pro. There are two subdirectories in /sys/class/backlight on my device - backlight, and panel0-backlight. panel0-backlight is the display backlight.

Repowerd's current method of choosing the sysfs file to control the backlight with is to iterate through the subdirectories in /sys/class/backlight, looking for one with a brightness file.

In my case, this applies to both subdirectories. backlight comes before panel0-backlight alphebetically, so the former is used instead of the latter - which is not what should happen.

To fix this, I have two suggestions:

  1. Code some sort of prioritisation logic, to make sure the right backlight device is chosen, or
  2. Let the path be configured in a config file.

1 seems cleaner (if it can be done), as it should work automatically.

Edited by Flo Lee