linux-stable/drivers/pwm
Hans de Goede de01ce3e40 pwm: lpss: Add range limit check for the base_unit register value
[ Upstream commit ef9f60daab ]

When the user requests a high enough period ns value, then the
calculations in pwm_lpss_prepare() might result in a base_unit value of 0.

But according to the data-sheet the way the PWM controller works is that
each input clock-cycle the base_unit gets added to a N bit counter and
that counter overflowing determines the PWM output frequency. Adding 0
to the counter is a no-op. The data-sheet even explicitly states that
writing 0 to the base_unit bits will result in the PWM outputting a
continuous 0 signal.

When the user requestes a low enough period ns value, then the
calculations in pwm_lpss_prepare() might result in a base_unit value
which is bigger then base_unit_range - 1. Currently the codes for this
deals with this by applying a mask:

	base_unit &= (base_unit_range - 1);

But this means that we let the value overflow the range, we throw away the
higher bits and store whatever value is left in the lower bits into the
register leading to a random output frequency, rather then clamping the
output frequency to the highest frequency which the hardware can do.

This commit fixes both issues by clamping the base_unit value to be
between 1 and (base_unit_range - 1).

Fixes: 684309e504 ("pwm: lpss: Avoid potential overflow of base_unit")
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200903112337.4113-5-hdegoede@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-10-29 09:07:05 +01:00
..
core.c pwm: Clear chip_data in pwm_put() 2019-12-05 15:38:12 +01:00
Kconfig
Makefile
pwm-ab8500.c
pwm-atmel-hlcdc.c
pwm-atmel-tcb.c
pwm-atmel.c
pwm-bcm-iproc.c pwm: bcm-iproc: handle clk_get_rate() return 2020-08-21 09:48:21 +02:00
pwm-bcm-kona.c
pwm-bcm2835.c pwm: bcm2835: Dynamically allocate base 2020-05-02 17:24:15 +02:00
pwm-berlin.c pwm: Clear chip_data in pwm_put() 2019-12-05 15:38:12 +01:00
pwm-bfin.c
pwm-brcmstb.c
pwm-clps711x.c pwm: clps711x: Fix period calculation 2019-12-05 15:37:48 +01:00
pwm-crc.c
pwm-cros-ec.c
pwm-ep93xx.c
pwm-fsl-ftm.c
pwm-hibvt.c
pwm-img.c
pwm-imx.c
pwm-jz4740.c
pwm-lp3943.c
pwm-lpc18xx-sct.c
pwm-lpc32xx.c
pwm-lpss-pci.c
pwm-lpss-platform.c
pwm-lpss.c pwm: lpss: Add range limit check for the base_unit register value 2020-10-29 09:07:05 +01:00
pwm-lpss.h
pwm-mediatek.c
pwm-meson.c pwm: meson: Don't disable PWM when setting duty repeatedly 2020-01-27 14:46:34 +01:00
pwm-mtk-disp.c
pwm-mxs.c
pwm-omap-dmtimer.c pwm: omap-dmtimer: Remove PWM chip in .remove before making it unfunctional 2020-02-28 16:36:05 +01:00
pwm-pca9685.c pwm: pca9685: Fix PWM/GPIO inter-operation 2020-04-24 08:00:55 +02:00
pwm-puv3.c
pwm-pxa.c
pwm-rcar.c pwm: rcar: Fix late Runtime PM enablement 2020-05-02 17:24:13 +02:00
pwm-renesas-tpu.c pwm: renesas-tpu: Fix late Runtime PM enablement 2020-05-02 17:24:15 +02:00
pwm-rockchip.c
pwm-samsung.c pwm: Clear chip_data in pwm_put() 2019-12-05 15:38:12 +01:00
pwm-spear.c
pwm-sti.c
pwm-stm32-lp.c pwm: stm32-lp: Add check in case requested period cannot be achieved 2019-10-11 18:18:40 +02:00
pwm-stm32.c
pwm-stmpe.c
pwm-sun4i.c
pwm-tegra.c
pwm-tiecap.c
pwm-tiehrpwm.c
pwm-tipwmss.c
pwm-twl-led.c
pwm-twl.c
pwm-vt8500.c
pwm-zx.c
sysfs.c pwm: Fix deadlock warning when removing PWM device 2019-06-15 11:54:59 +02:00