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

Commit 3044bc94 authored by Xu Kai's avatar Xu Kai
Browse files

pwm: qpnp: use the correct parameter to check the change of PWM period



"pwm->period" is an external parameter that will be updated out
of the pwm-qpnp driver unexpectedly. It's improper to use this
parameter to check whether the expected period is different from
the one being used. "chip->pwm_config.pwm_period" is a pwm-qpnp
internal parameter, which always represents the current period,
so use it to fix the problem.

Change-Id: I455b828c8c9270ef0f32ab3533daa1bc2c7d183d
Signed-off-by: default avatarXu Kai <kaixu@codeaurora.org>
parent 04f8a4e5
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1227,6 +1227,7 @@ static int qpnp_pwm_config(struct pwm_chip *pwm_chip,
	int rc;
	unsigned long flags;
	struct qpnp_pwm_chip *chip = qpnp_pwm_from_pwm_chip(pwm_chip);
	int prev_period_us = chip->pwm_config.pwm_period;

	if ((unsigned)period_ns < PM_PWM_PERIOD_MIN * NSEC_PER_USEC) {
		pr_err("Invalid pwm handle or parameters\n");
@@ -1235,7 +1236,8 @@ static int qpnp_pwm_config(struct pwm_chip *pwm_chip,

	spin_lock_irqsave(&chip->lpg_lock, flags);

	if (pwm->period != period_ns) {
	if (prev_period_us > INT_MAX / NSEC_PER_USEC ||
			prev_period_us * NSEC_PER_USEC != period_ns) {
		qpnp_lpg_calc_period(LVL_NSEC, period_ns, chip);
		qpnp_lpg_save_period(chip);
		pwm->period = period_ns;