aboutsummaryrefslogtreecommitdiff
path: root/drivers/pwm/pwm-sprd.c
AgeCommit message (Collapse)AuthorFilesLines
2023-10-13pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe()Uwe Kleine-König1-14/+3
Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove function which makes this function empty. Then there is no user of drvdata left and platform_set_drvdata() can be dropped, too. Further simplify and improve error returning using dev_err_probe(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2023-10-13pwm: sprd: Provide a helper to cast a chip to driver dataUwe Kleine-König1-4/+7
Similar to most other PWM drivers provide a static inline function to calculate driver data from a given pwmchip. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2023-10-13pwm: Manage owner assignment implicitly for driversUwe Kleine-König1-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]>
2023-07-24pwm: Explicitly include correct DT includesRob Herring1-0/+1
The DT of_device.h and of_platform.h date back to the separate of_platform_bus_type before it as merged into the regular platform bus. As part of that merge prepping Arm DT support 13 years ago, they "temporarily" include each other. They also include platform_device.h and of.h. As a result, there's a pretty much random mix of those include files used throughout the tree. In order to detangle these headers and replace the implicit includes with struct declarations, users need to explicitly include the correct includes. Signed-off-by: Rob Herring <[email protected]> Reviewed-by: Nobuhiro Iwamatsu <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2023-03-30pwm: sprd: Convert to platform remove callback returning voidUwe Kleine-König1-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]>
2023-03-23pwm: sprd: Explicitly set .polarity in .get_state()Uwe Kleine-König1-0/+1
The driver only supports normal polarity. Complete the implementation of .get_state() by setting .polarity accordingly. Fixes: 8aae4b02e8a6 ("pwm: sprd: Add Spreadtrum PWM support") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2022-12-06pwm: sprd: Propagate errors in .get_state() to the callerUwe Kleine-König1-1/+1
.get_state() can return an error indication. Make use of it to propagate failing hardware accesses. Reviewed-by: Baolin Wang <[email protected]> Acked-by: Conor Dooley <[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]>
2022-12-06pwm: Make .get_state() callback return an error codeUwe Kleine-König1-3/+5
.get_state() might fail in some cases. To make it possible that a driver signals such a failure change the prototype of .get_state() to return an error code. This patch was created using coccinelle and the following semantic patch: @p1@ identifier getstatefunc; identifier driver; @@ struct pwm_ops driver = { ..., .get_state = getstatefunc ,... }; @p2@ identifier p1.getstatefunc; identifier chip, pwm, state; @@ -void +int getstatefunc(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { ... - return; + return 0; ... } plus the actual change of the prototype in include/linux/pwm.h (plus some manual fixing of indentions and empty lines). So for now all drivers return success unconditionally. They are adapted in the following patches to make the changes easier reviewable. Reviewed-by: Heiko Stuebner <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Reviewed-by: Neil Armstrong <[email protected]> Reviewed-by: Nobuhiro Iwamatsu <[email protected]> Reviewed-by: Andre Przywara <[email protected]> Reviewed-by: Dave Stevenson <[email protected]> Acked-by: Douglas Anderson <[email protected]> Acked-by: Jernej Skrabec <[email protected]> Acked-by: Pavel Machek <[email protected]> Acked-by: Conor Dooley <[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]>
2021-07-08pwm: sprd: Ensure configuring period and duty_cycle isn't wrongly skippedUwe Kleine-König1-7/+4
As the last call to sprd_pwm_apply() might have exited early if state->enabled was false, the values for period and duty_cycle stored in pwm->state might not have been written to hardware and it must be ensured that they are configured before enabling the PWM. Fixes: 8aae4b02e8a6 ("pwm: sprd: Add Spreadtrum PWM support") Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2021-06-30pwm: sprd: Don't check the return code of pwmchip_remove()Uwe Kleine-König1-1/+3
pwmchip_remove() returns always 0. Don't use the value to make it possible to eventually change the function to return void. This is a good thing as pwmchip_remove() is usually called from a remove function (mostly for platform devices) and their return value is ignored by the device core anyhow. Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2021-03-22pwm: sprd: Refuse requests with unsupported polarityUwe Kleine-König1-0/+3
The driver only supports normal polarity and so should refuse requests for inversed polarity. Signed-off-by: Uwe Kleine-König <[email protected]> Acked-by: Chunyan Zhang <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2021-03-22pwm: Always allocate PWM chip base ID dynamicallyUwe Kleine-König1-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]>
2020-09-24pwm: sprd: Simplify with dev_err_probe()Krzysztof Kozlowski1-5/+2
Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and also it prints the error value. Signed-off-by: Krzysztof Kozlowski <[email protected]> Acked-by: Chunyan Zhang <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
2019-09-21pwm: Ensure pwm_apply_state() doesn't modify the state argumentUwe Kleine-König1-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]>
2019-09-21pwm: sprd: Add Spreadtrum PWM supportBaolin Wang1-0/+309
This patch adds the Spreadtrum PWM support, which provides maximum 4 channels. Signed-off-by: Neo Hou <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: Thierry Reding <[email protected]>