Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ac7386e authored by Fenglin Wu's avatar Fenglin Wu Committed by Gerrit - the friendly Code Review server
Browse files

leds: leds-qpnp: Set PWM channel operational mode explicitly



When LED is changing between fully on and blinking, there is a change
in PWM/LPG channel operational mode. Use pwm_change_mode() API to notify
the mode change to the PWM driver. This way, the operational mode and
the underlying configuration for PWM channel can be updated by PWM driver.
For example, this will help with the following use cases where the mode
can be switched at runtime.
  1) When the LED is fully ON, the LPG channel is in PWM mode.
  2) When the LED is blinking, the LPG channel is in LPG mode.

CRs-Fixed: 2070945
Change-Id: Idd7fc31de085b7b1f97c9bf823dfd49a46164018
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent f1ead4e3
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -875,6 +875,14 @@ static int qpnp_mpp_set(struct qpnp_led_data *led)
		}
		if (led->mpp_cfg->pwm_mode == PWM_MODE) {
			/*config pwm for brightness scaling*/
			rc = pwm_change_mode(led->mpp_cfg->pwm_cfg->pwm_dev,
					PM_PWM_MODE_PWM);
			if (rc < 0) {
				dev_err(&led->pdev->dev,
					"Failed to set PWM mode, rc = %d\n",
					rc);
				return rc;
			}
			period_us = led->mpp_cfg->pwm_cfg->pwm_period_us;
			if (period_us > INT_MAX / NSEC_PER_USEC) {
				duty_us = (period_us * led->cdev.brightness) /
@@ -1581,6 +1589,14 @@ static int qpnp_kpdbl_set(struct qpnp_led_data *led)
		}

		if (led->kpdbl_cfg->pwm_cfg->mode == PWM_MODE) {
			rc = pwm_change_mode(led->kpdbl_cfg->pwm_cfg->pwm_dev,
					PM_PWM_MODE_PWM);
			if (rc < 0) {
				dev_err(&led->pdev->dev,
					"Failed to set PWM mode, rc = %d\n",
					rc);
				return rc;
			}
			period_us = led->kpdbl_cfg->pwm_cfg->pwm_period_us;
			if (period_us > INT_MAX / NSEC_PER_USEC) {
				duty_us = (period_us * led->cdev.brightness) /
@@ -1702,6 +1718,14 @@ static int qpnp_rgb_set(struct qpnp_led_data *led)
			led->rgb_cfg->pwm_cfg->mode =
				led->rgb_cfg->pwm_cfg->default_mode;
		if (led->rgb_cfg->pwm_cfg->mode == PWM_MODE) {
			rc = pwm_change_mode(led->rgb_cfg->pwm_cfg->pwm_dev,
					PM_PWM_MODE_PWM);
			if (rc < 0) {
				dev_err(&led->pdev->dev,
					"Failed to set PWM mode, rc = %d\n",
					rc);
				return rc;
			}
			period_us = led->rgb_cfg->pwm_cfg->pwm_period_us;
			if (period_us > INT_MAX / NSEC_PER_USEC) {
				duty_us = (period_us * led->cdev.brightness) /
@@ -2136,6 +2160,11 @@ static int qpnp_pwm_init(struct pwm_config_data *pwm_cfg,
				dev_err(&pdev->dev, "Failed to configure pwm LUT\n");
				return rc;
			}
			rc = pwm_change_mode(pwm_cfg->pwm_dev, PM_PWM_MODE_LPG);
			if (rc < 0) {
				dev_err(&pdev->dev, "Failed to set LPG mode\n");
				return rc;
			}
		}
	} else {
		dev_err(&pdev->dev, "Invalid PWM device\n");