diff options
Diffstat (limited to 'drivers/video/backlight/lm3630a_bl.c')
-rw-r--r-- | drivers/video/backlight/lm3630a_bl.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c index e88a2b0e5904..e8b185bb6f5e 100644 --- a/drivers/video/backlight/lm3630a_bl.c +++ b/drivers/video/backlight/lm3630a_bl.c @@ -52,6 +52,7 @@ struct lm3630a_chip { struct gpio_desc *enable_gpio; struct regmap *regmap; struct pwm_device *pwmd; + struct pwm_state pwmd_state; }; /* i2c access */ @@ -167,16 +168,19 @@ static int lm3630a_intr_config(struct lm3630a_chip *pchip) return rval; } -static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) +static int lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) { - unsigned int period = pchip->pdata->pwm_period; - unsigned int duty = br * period / br_max; + int err; - pwm_config(pchip->pwmd, duty, period); - if (duty) - pwm_enable(pchip->pwmd); - else - pwm_disable(pchip->pwmd); + pchip->pwmd_state.period = pchip->pdata->pwm_period; + + err = pwm_set_relative_duty_cycle(&pchip->pwmd_state, br, br_max); + if (err) + return err; + + pchip->pwmd_state.enabled = pchip->pwmd_state.duty_cycle ? true : false; + + return pwm_apply_state(pchip->pwmd, &pchip->pwmd_state); } /* update and get brightness */ @@ -187,11 +191,9 @@ static int lm3630a_bank_a_update_status(struct backlight_device *bl) enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl; /* pwm control */ - if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) { - lm3630a_pwm_ctrl(pchip, bl->props.brightness, - bl->props.max_brightness); - return bl->props.brightness; - } + if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) + return lm3630a_pwm_ctrl(pchip, bl->props.brightness, + bl->props.max_brightness); /* disable sleep */ ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00); @@ -210,8 +212,8 @@ static int lm3630a_bank_a_update_status(struct backlight_device *bl) return 0; out_i2c_err: - dev_err(pchip->dev, "i2c failed to access\n"); - return bl->props.brightness; + dev_err(pchip->dev, "i2c failed to access (%pe)\n", ERR_PTR(ret)); + return ret; } static int lm3630a_bank_a_get_brightness(struct backlight_device *bl) @@ -264,11 +266,9 @@ static int lm3630a_bank_b_update_status(struct backlight_device *bl) enum lm3630a_pwm_ctrl pwm_ctrl = pchip->pdata->pwm_ctrl; /* pwm control */ - if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0) { - lm3630a_pwm_ctrl(pchip, bl->props.brightness, - bl->props.max_brightness); - return bl->props.brightness; - } + if ((pwm_ctrl & LM3630A_PWM_BANK_B) != 0) + return lm3630a_pwm_ctrl(pchip, bl->props.brightness, + bl->props.max_brightness); /* disable sleep */ ret = lm3630a_update(pchip, REG_CTRL, 0x80, 0x00); @@ -287,8 +287,8 @@ static int lm3630a_bank_b_update_status(struct backlight_device *bl) return 0; out_i2c_err: - dev_err(pchip->dev, "i2c failed to access REG_CTRL\n"); - return bl->props.brightness; + dev_err(pchip->dev, "i2c failed to access (%pe)\n", ERR_PTR(ret)); + return ret; } static int lm3630a_bank_b_get_brightness(struct backlight_device *bl) @@ -482,8 +482,10 @@ static int lm3630a_parse_node(struct lm3630a_chip *pchip, device_for_each_child_node(pchip->dev, node) { ret = lm3630a_parse_bank(pdata, node, &seen_led_sources); - if (ret) + if (ret) { + fwnode_handle_put(node); return ret; + } } return ret; @@ -563,11 +565,7 @@ static int lm3630a_probe(struct i2c_client *client, return PTR_ERR(pchip->pwmd); } - /* - * FIXME: pwm_apply_args() should be removed when switching to - * the atomic PWM API. - */ - pwm_apply_args(pchip->pwmd); + pwm_init_state(pchip->pwmd, &pchip->pwmd_state); } /* interrupt enable : irq 0 is not allowed */ |