Commit d6dbdf0d authored by Vladimir Zapolskiy's avatar Vladimir Zapolskiy Committed by Thierry Reding
Browse files

pwm: lpc32xx: return ERANGE, if requested period is not supported



Instead of silent acceptance of unsupported requested configuration
for PWM period and setting the boundary supported value, return
-ERANGE to a caller.

Duty period value equal to 0 or period is still accepted to allow
configuration by PWM sysfs interface, when it is set to 0 by default.

For reference this is a list of restrictions on period_ns == 1/freq:

  | PWM parent clock | parent clock divisor | max freq | min freq |
  +------------------+----------------------+----------+----------+
  |   HCLK == 13 MHz |      1 (min)         | 50.7 KHz | 198.3 Hz |
  |   HCLK == 13 MHz |     15 (max)         | 3.38 KHz | 13.22 Hz |
  |  RTC == 32.7 KHz |      1 (min)         |   128 Hz |   0.5 Hz |
  |  RTC == 32.7 KHz |     15 (max)         | 8.533 Hz | 0.033 Hz |

Note that PWM sysfs interface does not support setting of period more
than NSEC_PER_SEC / MAX_INT32 ~ 2 seconds, however this PWM controller
supports a period up to 30 seconds.

Signed-off-by: default avatarVladimir Zapolskiy <vz@mleia.com>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 5a9fc9c6
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -41,9 +41,9 @@ static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
	/* The highest acceptable divisor is 256, which is represented by 0 */
	/* The highest acceptable divisor is 256, which is represented by 0 */
	period_cycles = div64_u64(c * period_ns,
	period_cycles = div64_u64(c * period_ns,
			       (unsigned long long)NSEC_PER_SEC * 256);
			       (unsigned long long)NSEC_PER_SEC * 256);
	if (!period_cycles)
	if (!period_cycles || period_cycles > 256)
		period_cycles = 1;
		return -ERANGE;
	if (period_cycles > 255)
	if (period_cycles == 256)
		period_cycles = 0;
		period_cycles = 0;


	/* Compute 256 x #duty/period value and care for corner cases */
	/* Compute 256 x #duty/period value and care for corner cases */