lights: boot: use DSI panel regulator driver
* Old rpi_backlight driver is no longer used on recent kernel versions. Regulator driver is used for backlight instead. * Change the backlight path and implement scaling to support the official Raspberry Pi 7" DSI Touch Display & Touch Display 2. * The original Touch Display has max brightness of 255 while the new Touch Display 2 has 31.
This commit is contained in:
@@ -13,7 +13,7 @@ disable_overscan=1
|
|||||||
|
|
||||||
# Display panel
|
# Display panel
|
||||||
#dtoverlay=vc4-kms-dsi-7inch
|
#dtoverlay=vc4-kms-dsi-7inch
|
||||||
#dtoverlay=rpi-backlight
|
#dtoverlay=vc4-kms-dsi-ili9881-7inch
|
||||||
|
|
||||||
# Graphics acceleration
|
# Graphics acceleration
|
||||||
dtoverlay=vc4-kms-v3d
|
dtoverlay=vc4-kms-v3d
|
||||||
|
@@ -19,28 +19,39 @@
|
|||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
|
||||||
|
using ::android::base::ReadFileToString;
|
||||||
using ::android::base::WriteStringToFile;
|
using ::android::base::WriteStringToFile;
|
||||||
|
|
||||||
namespace aidl::android::hardware::light {
|
namespace aidl::android::hardware::light {
|
||||||
|
|
||||||
static const std::string backlightFiles[] = {
|
static const uint32_t defaultMaxBrightness = 255;
|
||||||
"/sys/class/backlight/rpi_backlight/brightness"
|
|
||||||
};
|
|
||||||
|
|
||||||
const static std::vector<HwLight> availableLights = {
|
static const std::string backlightBrightnessPath = "/sys/class/backlight/11-0045/brightness";
|
||||||
|
static const std::string backlightMaxBrightnessPath = "/sys/class/backlight/11-0045/max_brightness";
|
||||||
|
|
||||||
|
static const std::vector<HwLight> availableLights = {
|
||||||
{.id = (int)LightType::BACKLIGHT, .type = LightType::BACKLIGHT, .ordinal = 0}
|
{.id = (int)LightType::BACKLIGHT, .type = LightType::BACKLIGHT, .ordinal = 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Lights::Lights() {
|
||||||
|
maxBrightness = defaultMaxBrightness;
|
||||||
|
|
||||||
|
if (!access(backlightMaxBrightnessPath.c_str(), R_OK)) {
|
||||||
|
std::string maxBrightnessValue;
|
||||||
|
if (ReadFileToString(backlightMaxBrightnessPath, &maxBrightnessValue)) {
|
||||||
|
maxBrightness = std::stoi(maxBrightnessValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) {
|
ndk::ScopedAStatus Lights::setLightState(int id, const HwLightState& state) {
|
||||||
HwLight const& light = availableLights[id];
|
HwLight const& light = availableLights[id];
|
||||||
std::string const brightness = std::to_string(rgbToBrightness(state));
|
std::string const brightness = std::to_string(rgbToScaledBrightness(state, maxBrightness));
|
||||||
|
|
||||||
switch (light.type) {
|
switch (light.type) {
|
||||||
case LightType::BACKLIGHT:
|
case LightType::BACKLIGHT:
|
||||||
for (auto &file : backlightFiles) {
|
if (!access(backlightBrightnessPath.c_str(), W_OK)) {
|
||||||
if (!access(file.c_str(), W_OK)) {
|
WriteStringToFile(brightness, backlightBrightnessPath);
|
||||||
WriteStringToFile(brightness, file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -58,10 +69,11 @@ ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* lights) {
|
|||||||
return ndk::ScopedAStatus::ok();
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Lights::rgbToBrightness(const HwLightState& state) {
|
uint32_t Lights::rgbToScaledBrightness(const HwLightState& state, uint32_t maxBrightness) {
|
||||||
uint32_t color = state.color & 0x00ffffff;
|
uint32_t color = state.color & 0x00ffffff;
|
||||||
return ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) +
|
uint32_t brightness = ((77 * ((color >> 16) & 0xff)) + (150 * ((color >> 8) & 0xff)) +
|
||||||
(29 * (color & 0xff))) >> 8;
|
(29 * (color & 0xff))) >> 8;
|
||||||
|
return brightness * maxBrightness / 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // aidl::android::hardware::light
|
} // aidl::android::hardware::light
|
||||||
|
@@ -23,11 +23,14 @@ namespace aidl::android::hardware::light {
|
|||||||
|
|
||||||
class Lights : public BnLights {
|
class Lights : public BnLights {
|
||||||
public:
|
public:
|
||||||
|
Lights();
|
||||||
|
|
||||||
ndk::ScopedAStatus setLightState(int id, const HwLightState& state) override;
|
ndk::ScopedAStatus setLightState(int id, const HwLightState& state) override;
|
||||||
ndk::ScopedAStatus getLights(std::vector<HwLight>* types) override;
|
ndk::ScopedAStatus getLights(std::vector<HwLight>* types) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t rgbToBrightness(const HwLightState& state);
|
uint32_t maxBrightness;
|
||||||
|
uint32_t rgbToScaledBrightness(const HwLightState& state, uint32_t maxBrightness);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // aidl::android::hardware::light
|
} // aidl::android::hardware::light
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
on early-boot
|
on early-boot
|
||||||
chown system system /sys/class/backlight/rpi_backlight/brightness
|
chown system system /sys/class/backlight/11-0045/brightness
|
||||||
chmod 660 /sys/class/backlight/rpi_backlight/brightness
|
chown system system /sys/class/backlight/11-0045/max_brightness
|
||||||
|
chmod 660 /sys/class/backlight/11-0045/brightness
|
||||||
|
chmod 440 /sys/class/backlight/11-0045/max_brightness
|
||||||
|
|
||||||
service vendor.light-default /vendor/bin/hw/android.hardware.light-service.rpi
|
service vendor.light-default /vendor/bin/hw/android.hardware.light-service.rpi
|
||||||
class hal
|
class hal
|
||||||
|
@@ -38,8 +38,8 @@
|
|||||||
/vendor/bin/hw/android\.hardware\.health-service\.rpi u:object_r:hal_health_default_exec:s0
|
/vendor/bin/hw/android\.hardware\.health-service\.rpi u:object_r:hal_health_default_exec:s0
|
||||||
|
|
||||||
# Lights
|
# Lights
|
||||||
/sys/class/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0
|
/sys/class/backlight/11-0045/brightness u:object_r:sysfs_leds:s0
|
||||||
/sys/devices/platform/rpi_backlight/backlight/rpi_backlight/brightness u:object_r:sysfs_leds:s0
|
/sys/class/backlight/11-0045/max_brightness u:object_r:sysfs_leds:s0
|
||||||
/vendor/bin/hw/android\.hardware\.light-service\.rpi u:object_r:hal_light_default_exec:s0
|
/vendor/bin/hw/android\.hardware\.light-service\.rpi u:object_r:hal_light_default_exec:s0
|
||||||
|
|
||||||
# Partitions
|
# Partitions
|
||||||
|
Reference in New Issue
Block a user