1
0
Fork 0
alistair23-linux/drivers/pwm
Hans de Goede bf12e769ff 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:57:38 +01:00
..
Kconfig pwm: Changes for v5.4-rc1 2019-09-27 12:19:47 -07:00
Makefile pwm: sprd: Add Spreadtrum PWM support 2019-09-21 01:15:48 +02:00
core.c Revert "pwm: Let pwm_get_state() return the last implemented state" 2019-10-21 16:48:52 +02:00
pwm-ab8500.c
pwm-atmel-hlcdc.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-atmel-tcb.c
pwm-atmel.c pwm: atmel: Consolidate driver data initialization 2019-09-21 03:25:11 +02:00
pwm-bcm-iproc.c pwm: bcm-iproc: handle clk_get_rate() return 2020-08-21 13:05:34 +02:00
pwm-bcm-kona.c
pwm-bcm2835.c pwm: bcm2835: Dynamically allocate base 2020-04-29 16:33:02 +02:00
pwm-berlin.c
pwm-brcmstb.c
pwm-clps711x.c
pwm-crc.c
pwm-cros-ec.c pwm: Changes for v5.4-rc1 2019-09-27 12:19:47 -07:00
pwm-ep93xx.c
pwm-fsl-ftm.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-hibvt.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-img.c pwm: img: Call pm_runtime_put() in pm_runtime_get_sync() failed case 2020-06-24 17:50:18 +02:00
pwm-imx-tpm.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-imx1.c
pwm-imx27.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-jz4740.c pwm: jz4740: Fix build failure 2020-07-16 08:16:48 +02:00
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:57:38 +01:00
pwm-lpss.h
pwm-mediatek.c pwm: mediatek: Add MT7629 compatible string 2019-09-26 13:27:50 +02:00
pwm-meson.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-mtk-disp.c
pwm-mxs.c pwm: mxs: Use devm_platform_ioremap_resource() to simplify code 2019-09-21 00:26:10 +02:00
pwm-omap-dmtimer.c pwm: omap-dmtimer: put_device() after of_find_device_by_node() 2020-03-05 16:43:49 +01:00
pwm-pca9685.c pwm: pca9685: Fix PWM/GPIO inter-operation 2020-04-21 09:04:52 +02:00
pwm-puv3.c
pwm-pxa.c
pwm-rcar.c pwm: rcar: Fix late Runtime PM enablement 2020-04-29 16:32:58 +02:00
pwm-renesas-tpu.c pwm: renesas-tpu: Fix late Runtime PM enablement 2020-04-29 16:33:02 +02:00
pwm-rockchip.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-samsung.c
pwm-sifive.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-spear.c
pwm-sprd.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-sti.c pwm: Remove dev_err() usage after platform_get_irq() 2019-09-21 00:58:35 +02:00
pwm-stm32-lp.c pwm: stm32-lp: Add check in case requested period cannot be achieved 2019-09-21 03:25:10 +02:00
pwm-stm32.c pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
pwm-stmpe.c
pwm-sun4i.c pwm: sun4i: Fix incorrect calculation of duty_cycle/period 2020-01-26 10:01:04 +01:00
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 pwm: Ensure pwm_apply_state() doesn't modify the state argument 2019-09-21 03:25:10 +02:00
sysfs.c pwm: Changes for v5.3-rc1 2019-07-09 08:57:45 -07:00