From ae53db0914beab65bf267ef90ac99da6b9a70a7e Mon Sep 17 00:00:00 2001 From: Michael Abood Date: Sun, 16 Jan 2022 04:21:12 -0500 Subject: [PATCH] arm64: dts: qcom: samsung-gtelwifiue: Add RT8555 backlight driver 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 --- .../dts/qcom/apq8016-samsung-gtelwifiue.dts | 36 +++++++++++++++++++ drivers/video/backlight/rt8555-backlight.c | 18 ++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/apq8016-samsung-gtelwifiue.dts b/arch/arm64/boot/dts/qcom/apq8016-samsung-gtelwifiue.dts index bba56a9eb6ecc3..544587d7be42ac 100644 --- a/arch/arm64/boot/dts/qcom/apq8016-samsung-gtelwifiue.dts +++ b/arch/arm64/boot/dts/qcom/apq8016-samsung-gtelwifiue.dts @@ -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"; @@ -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"; diff --git a/drivers/video/backlight/rt8555-backlight.c b/drivers/video/backlight/rt8555-backlight.c index aee8f6336616be..730ccb3ab54109 100644 --- a/drivers/video/backlight/rt8555-backlight.c +++ b/drivers/video/backlight/rt8555-backlight.c @@ -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); @@ -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; @@ -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; @@ -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; @@ -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); }