Skip to content

Commit

Permalink
arm64: dts: qcom: samsung-gtelwifiue: Add RT8555 backlight driver
Browse files Browse the repository at this point in the history
This adds the RT8555 backlight driver to the device tree. Using i2c-gpio
here is necessary, as the backlight ic is not on any i2c pins.

Signed-off-by: Michael Abood <[email protected]>
  • Loading branch information
person4268 committed Jan 17, 2022
1 parent 15da270 commit ae53db0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
36 changes: 36 additions & 0 deletions arch/arm64/boot/dts/qcom/apq8016-samsung-gtelwifiue.dts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@
};
};

i2c-bl {
status = "okay";
compatible = "i2c-gpio";
sda-gpios = <&msmgpio 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
scl-gpios = <&msmgpio 25 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;

pinctrl-names = "default";
pinctrl-0 = <&bl_i2c_default>;

#address-cells = <1>;
#size-cells = <0>;

backlight@31 {
status = "okay";
compatible = "richtek,rt8555-backlight";
gpio = <&msmgpio 69 GPIO_ACTIVE_HIGH>;
reg = <0x31>;
};
};

reg_vdd_tsp: regulator-vdd-tsp {
compatible = "regulator-fixed";
regulator-name = "vdd_tsp";
Expand Down Expand Up @@ -315,6 +335,22 @@
bias-disable;
};

bl_en_default: reg-lcd-en-default {
pins = "gpio69";
function = "gpio";

drive-strength = <2>;
bias-disable;
};

bl_i2c_default: muic-i2c-default {
pins = "gpio24", "gpio25";
function = "gpio";

drive-strength = <2>;
bias-disable;
};

gpio_keys_default: gpio-keys-default {
pins = "gpio107", "gpio109";
function = "gpio";
Expand Down
18 changes: 12 additions & 6 deletions drivers/video/backlight/rt8555-backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ struct rt8555_priv {
static int rt8555_bl_update_status(struct backlight_device *bl_dev)
{
struct rt8555_priv *priv = bl_get_data(bl_dev);
unsigned int brightness = min(backlight_get_brightness(bl_dev), RT8555_MAX_BRIGHTNESS);
unsigned int brightness = min(backlight_get_brightness(bl_dev), priv->bl->props.max_brightness);
int ret;

/* Enable the IC before setting the brightness */
if (brightness)
if (!IS_ERR(priv->enable))
if (!IS_ERR_OR_NULL(priv->enable))
gpiod_set_value(priv->enable, 1);


Expand All @@ -48,7 +48,7 @@ static int rt8555_bl_update_status(struct backlight_device *bl_dev)

/* Disable the IC after setting it to 0 */
if (brightness == 0)
if (!IS_ERR(priv->enable))
if (!IS_ERR_OR_NULL(priv->enable))
gpiod_set_value(priv->enable, 0);

return 0;
Expand All @@ -61,7 +61,7 @@ static int rt8555_bl_get_brightness(struct backlight_device *bl_dev)

/* If the RT8555 is disabled, there's no reason to turn it on just to read
* it back */
if (!IS_ERR(priv->enable))
if (!IS_ERR_OR_NULL(priv->enable))
if (gpiod_get_value(priv->enable) == 0)
return 0;

Expand Down Expand Up @@ -103,9 +103,15 @@ static int rt8555_bl_probe(struct i2c_client *client)
priv->dev = &client->dev;

priv->enable = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_OUT_HIGH);
if (!IS_ERR(priv->enable))
if (!IS_ERR_OR_NULL(priv->enable))
gpiod_set_value(priv->enable, 1);

priv->regmap = devm_regmap_init_i2c(client, &rt8555_regmap_config);
if (!priv->regmap) {
dev_err(&client->dev, "Failed to init regmap\n");
return -ENODEV;
}

ret = device_property_read_u32(&client->dev, "max-brightness", &brightness);
if (ret)
brightness = RT8555_MAX_BRIGHTNESS;
Expand Down Expand Up @@ -144,7 +150,7 @@ static void rt8555_bl_remove(struct i2c_client *client)
bl_dev->props.brightness = 0;
backlight_update_status(priv->bl);

if (!IS_ERR(priv->enable))
if (!IS_ERR_OR_NULL(priv->enable))
gpiod_set_value(priv->enable, 0);
}

Expand Down

0 comments on commit ae53db0

Please sign in to comment.