aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-rcar.c
Commit message (Collapse)AuthorAgeFilesLines
* pwm: rcar: Improve register calculationUwe Kleine-König2025-04-041-11/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There were several issues in the function rcar_pwm_set_counter(): - The u64 values period_ns and duty_ns were cast to int on function call which might loose bits on 32 bit architectures. Fix: Make parameters to rcar_pwm_set_counter() u64 - The algorithm divided by the result of a division which looses precision. Fix: Make use of mul_u64_u64_div_u64() - The calculated values were just masked to fit the respective register fields which again might loose bits. Fix: Explicitly check for overlow Implement the respective fixes. A side effect of fixing the 2nd issue is that there is no division by 0 if clk_get_rate() returns 0. Fixes: ed6c1476bf7f ("pwm: Add support for R-Car PWM Timer") Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/ab3dac794b2216cc1cc56d65c93dd164f8bd461b.1743501688.git.u.kleine-koenig@baylibre.com [ukleinek: Added an explicit #include <linux/bitfield.h> to please the 0day build bot] Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Uwe Kleine-König <[email protected]>
* pwm: Switch back to struct platform_driver::remove()Uwe Kleine-König2024-09-161-1/+1
| | | | | | | | | | | | | | | After commit 0edb555a65d1 ("platform: Make platform_driver::remove() return void") .remove() is (again) the right callback to implement for platform drivers. Convert all pwm drivers to use .remove(), with the eventual goal to drop struct platform_driver::remove_new(). As .remove() and .remove_new() have the same prototypes, conversion is done by just changing the structure member name in the driver initializer. Signed-off-by: Uwe Kleine-König <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
* pwm: rcar: Make use of devm_pwmchip_alloc() functionUwe Kleine-König2024-02-191-8/+5
| | | | | | | | | This prepares the pwm-rcar driver to further changes of the pwm core outlined in the commit introducing devm_pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Link: https://lore.kernel.org/r/a37a167364366b6cbe2dd299dce02731706213b2.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
* pwm: rcar: Prepare removing pwm_chip from driver dataUwe Kleine-König2024-02-191-7/+9
| | | | | | | | | | This prepares the driver for further changes that will drop struct pwm_chip chip from struct rcar_pwm_chip. Use the pwm_chip as driver data instead of the rcar_pwm_chip to get access to the pwm_chip in the .remove() callbacks without using rcar_pwm->chip. Link: https://lore.kernel.org/r/e588e3ccdd0ac1c9c3f3a79b3e52112f83f9d71c.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
* pwm: rcar: Make use of pwmchip_parent() accessorUwe Kleine-König2024-02-191-2/+2
| | | | | | | | | struct pwm_chip::dev is about to change. To not have to touch this driver in the same commit as struct pwm_chip::dev, use the accessor function provided for exactly this purpose. Link: https://lore.kernel.org/r/8b33a106c84517430d90ee4a8dcb878d0fc3bad5.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
* pwm: Manage owner assignment implicitly for driversUwe Kleine-König2023-10-131-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Instead of requiring each driver to care for assigning the owner member of struct pwm_ops, handle that implicitly using a macro. Note that the owner member has to be moved to struct pwm_chip, as the ops structure usually lives in read-only memory and so cannot be modified. The upside is that new low level drivers cannot forget the assignment and save one line each. The pwm-crc driver didn't assign .owner, that's not a problem in practice though as the driver cannot be compiled as a module. Acked-by: Andy Shevchenko <[email protected]> # Intel LPSS Reviewed-by: Florian Fainelli <[email protected]> # pwm-{bcm,brcm}*.c Acked-by: Jernej Skrabec <[email protected]> # sun4i Acked-by: Andi Shyti <[email protected]> Acked-by: Nobuhiro Iwamatsu <[email protected]> # pwm-visconti Acked-by: Heiko Stuebner <[email protected]> # pwm-rockchip Acked-by: Michael Walle <[email protected]> # pwm-sl28cpld Acked-by: Neil Armstrong <[email protected]> # pwm-meson Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Drop of_match_ptr for ID tableKrzysztof Kozlowski2023-04-061-1/+1
| | | | | | | | | | | | | | The driver can match only via the DT table so the table should be always used and the of_match_ptr does not have any sense (this also allows ACPI matching via PRP0001, even though it might not be relevant here). This also fixes the following compiler warning: drivers/pwm/pwm-rcar.c:252:34: error: ‘rcar_pwm_of_table’ defined but not used [-Werror=unused-const-variable=] for builds with CONFIG_OF=n, CONFIG_PWM_RCAR=y and W=1. Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Convert to platform remove callback returning voidUwe Kleine-König2023-03-301-4/+2
| | | | | | | | | | | | | | | | The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is (mostly) ignored and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new() which already returns void. Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Simplify multiplication/shift logicGeert Uytterhoeven2022-02-241-1/+1
| | | | | | | | | | - Remove the superfluous cast; the multiplication will yield a 64-bit result due to the "100ULL" anyway, - "a * (1 << b)" == "a << b". Signed-off-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Don't check the return code of pwmchip_remove()Uwe Kleine-König2021-09-021-3/+2
| | | | | | | | | pwmchip_remove() returns always 0. Don't use the value to make it possible to eventually change the function to return void. Also the driver core ignores the return value of rcar_pwm_remove(). Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: Always allocate PWM chip base ID dynamicallyUwe Kleine-König2021-03-221-1/+0
| | | | | | | | | | Since commit 5e5da1e9fbee ("pwm: ab8500: Explicitly allocate pwm chip base dynamically") all drivers use dynamic ID allocation explicitly. New drivers are supposed to do the same, so remove support for driver specified base IDs and drop all assignments in the low-level drivers. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: Use -EINVAL for unsupported polarityThierry Reding2020-12-171-1/+1
| | | | | | | | | | Instead of using a mix of -EOPNOTSUPP and -ENOTSUPP, use the more standard -EINVAL to signal that the specified polarity value was invalid. Acked-by: Uwe Kleine-König <[email protected]> Acked-by: Lee Jones <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Convert to devm_platform_ioremap_resource()Yangtao Li2020-12-171-3/+1
| | | | | | | | Use devm_platform_ioremap_resource() to simplify code. Signed-off-by: Yangtao Li <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Fix late Runtime PM enablementGeert Uytterhoeven2020-03-301-3/+7
| | | | | | | | | | | | | Runtime PM should be enabled before calling pwmchip_add(), as PWM users can appear immediately after the PWM chip has been added. Likewise, Runtime PM should be disabled after the removal of the PWM chip. Fixes: ed6c1476bf7f16d5 ("pwm: Add support for R-Car PWM Timer") Signed-off-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Document inability to set duty_cycle = 0Uwe Kleine-König2020-01-201-0/+3
| | | | | | | | | | When .apply() is called with state->duty_cycle = 0 the duty_ns parameter to rcar_pwm_set_counter() is 0 which results in ph being 0 and rcar_pwm_set_counter() returning -EINVAL. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Drop useless call to pwm_get_state()Uwe Kleine-König2020-01-201-2/+0
| | | | | | | | | | | | | pwm_get_state has no side effects and the resulting pwm_state is unused. So drop the call to pwm_get_state() and the local variable from rcar_pwm_apply(). The call was introduced in commit 7f68ce8287d3 ("pwm: rcar: Add support "atomic" API") and already then was useless. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: Ensure pwm_apply_state() doesn't modify the state argumentUwe Kleine-König2019-09-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is surprising for a PWM consumer when the variable holding the requested state is modified by pwm_apply_state(). Consider for example a driver doing: #define PERIOD 5000000 #define DUTY_LITTLE 10 ... struct pwm_state state = { .period = PERIOD, .duty_cycle = DUTY_LITTLE, .polarity = PWM_POLARITY_NORMAL, .enabled = true, }; pwm_apply_state(mypwm, &state); ... state.duty_cycle = PERIOD / 2; pwm_apply_state(mypwm, &state); For sure the second call to pwm_apply_state() should still have state.period = PERIOD and not something the hardware driver chose for a reason that doesn't necessarily apply to the second call. So declare the state argument as a pointer to a const type and adapt all drivers' .apply callbacks. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Remove a redundant condition in rcar_pwm_apply()Yoshihiro Shimoda2019-09-201-1/+1
| | | | | | | | | | | Since the rcar_pwm_apply() has already checked whether state->enabled is set or not, this patch removes a redundant condition. Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Remove suspend/resume supportYoshihiro Shimoda2019-06-261-39/+0
| | | | | | | | | | | According to the Documentation/pwm.txt, all PWM consumers should implement power management instead of the PWM driver. So, this patch removes suspend/resume support. Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Improve calculation of dividerYoshihiro Shimoda2019-03-041-9/+7
| | | | | | | | | | | | The rcar_pwm_get_clock_division() has a loop to calculate the divider, but the value of div should be calculatable without a loop. So, this patch improves it. This algorithm is suggested by Uwe Kleine-König and Laurent Pinchart. Signed-off-by: Yoshihiro Shimoda <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Remove legacy APIsYoshihiro Shimoda2019-03-041-40/+4
| | | | | | | | | | This patch removes legacy APIs. Since rcar_pwm_{en,dis}able() functions are reused on "atomic" API, this patch changes the arguments of these functions. No change in behavior. Signed-off-by: Yoshihiro Shimoda <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Use "atomic" API on rcar_pwm_resume()Yoshihiro Shimoda2019-03-041-5/+3
| | | | | | | | | To remove legacy API related functions in the future, this patch uses "atomic" related function instead. No change in behavior. Signed-off-by: Yoshihiro Shimoda <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Add support "atomic" APIYoshihiro Shimoda2019-03-041-0/+37
| | | | | | | | | | | | | | | | | | | This patch adds support for "atomic" API. This behavior differs with legacy APIs a little. Legacy APIs: The PWMCNT register will be updated in rcar_pwm_config() even if the PWM state is disabled. Atomic API: The PWMCNT register will be updated in rcar_pwm_apply() only if the PWM state is enabled. Otherwize, if a PWM runs with 30% duty cycles and the pwm_apply_state() is called with state->enabled = 0, ->duty_cycle = 60 and ->period = 100, this is possible to output a 60% duty cycle. Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: Use SPDX identifier for Renesas driversWolfram Sang2018-10-121-4/+1
| | | | | | Signed-off-by: Wolfram Sang <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: simplify getting .drvdataWolfram Sang2018-04-301-2/+1
| | | | | | | | | We should get drvdata from struct device directly. Going via platform_device is an unneeded step back and forth. Signed-off-by: Wolfram Sang <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Add suspend/resume supportYoshihiro Shimoda2018-03-271-0/+42
| | | | | | | This patch adds suspend/resume support for Renesas PWM driver. Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Use PM Runtime to control module clockHien Dang2018-03-271-6/+2
| | | | | | | | | | | Runtime PM API (pm_runtime_get_sync/pm_runtime_put) should be used to control module clock instead of clk_prepare_enable and clk_disable_unprepare. Signed-off-by: Hien Dang <[email protected]> Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Fix a condition to prevent mismatch value setting to dutyRyo Kodama2018-03-271-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes an issue that is possible to set mismatch value to duty for R-Car PWM if we input the following commands: # cd /sys/class/pwm/<pwmchip>/ # echo 0 > export # cd pwm0 # echo 30 > period # echo 30 > duty_cycle # echo 0 > duty_cycle # cat duty_cycle 0 # echo 1 > enable --> Then, the actual duty_cycle is 30, not 0. So, this patch adds a condition into rcar_pwm_config() to fix this issue. Signed-off-by: Ryo Kodama <[email protected]> [shimoda: revise the commit log and add Fixes and Cc tags] Fixes: ed6c1476bf7f ("pwm: Add support for R-Car PWM Timer") Cc: Cc: <[email protected]> # v4.4+ Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Make use of pwm_is_enabled()Boris BREZILLON2016-05-171-1/+1
| | | | | | | | | | | | | Commit 5c31252c4a86 ("pwm: Add the pwm_is_enabled() helper") introduced a new function to test whether a PWM device is enabled or not without manipulating PWM internal fields. Hiding this is necessary if we want to smoothly move to the atomic PWM config approach without impacting PWM drivers. Fix this driver to use pwm_is_enabled() instead of directly accessing the ->flags field. Signed-off-by: Boris Brezillon <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: rcar: Improve accuracy of frequency division settingRyo Kodama2015-12-161-1/+1
| | | | | | | | | | | | From: Ryo Kodama <[email protected]> When period_ns is set to the same value of RCAR_PWM_MAX_CYCLE in rcar_pwm_get_clock_division(), this function should allow such value for improving accuracy of frequency division setting. Signed-off-by: Ryo Kodama <[email protected]> Signed-off-by: Yoshihiro Shimoda <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
* pwm: Add support for R-Car PWM TimerYoshihiro Shimoda2015-10-061-0/+274
This patch adds support for R-Car SoCs PWM Timer. The PWM timer of R-Car H2 has 7 channels. So, we can use the channels if we describe device tree nodes. Signed-off-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Thierry Reding <[email protected]>