mbox series

[v3,0/6] pwm: ensure pwm_apply_state() doesn't modify the state argument

Message ID 20190824153707.13746-1-uwe@kleine-koenig.org (mailing list archive)
Headers show
Series pwm: ensure pwm_apply_state() doesn't modify the state argument | expand

Message

Uwe Kleine-König Aug. 24, 2019, 3:37 p.m. UTC
Hello,

this series eventually changes the prototype of pwm_apply_state to take
a const struct pwm_state *, see the last patch for a rationale.

Changes since v2 apart from rebasing and so covering a few more drivers
is mainly addressing the concern that after state was rounded and
applied at least pwm_get_state should return the rounded values. See
patch 2.

Uwe Kleine-König (6):
  pwm: introduce local struct pwm_chip in pwm_apply_state()
  pwm: let pwm_get_state() return the last implemented state
  pwm: rockchip: Don't update the state for the caller of
    pwm_apply_state()
  pwm: sun4i: Don't update the state for the caller of pwm_apply_state()
  pwm: fsl-ftm: Don't update the state for the caller of
    pwm_apply_state()
  pwm: ensure pwm_apply_state() doesn't modify the state argument

 drivers/pwm/core.c            | 39 +++++++++++++++++++++--------------
 drivers/pwm/pwm-atmel-hlcdc.c |  2 +-
 drivers/pwm/pwm-atmel.c       |  2 +-
 drivers/pwm/pwm-bcm-iproc.c   |  2 +-
 drivers/pwm/pwm-cros-ec.c     |  2 +-
 drivers/pwm/pwm-fsl-ftm.c     |  8 ++-----
 drivers/pwm/pwm-hibvt.c       |  2 +-
 drivers/pwm/pwm-imx-tpm.c     |  4 ++--
 drivers/pwm/pwm-imx27.c       |  2 +-
 drivers/pwm/pwm-jz4740.c      |  2 +-
 drivers/pwm/pwm-lpss.c        |  2 +-
 drivers/pwm/pwm-meson.c       |  4 ++--
 drivers/pwm/pwm-rcar.c        |  2 +-
 drivers/pwm/pwm-rockchip.c    | 10 ++-------
 drivers/pwm/pwm-sifive.c      |  2 +-
 drivers/pwm/pwm-stm32-lp.c    |  2 +-
 drivers/pwm/pwm-stm32.c       |  4 ++--
 drivers/pwm/pwm-sun4i.c       | 10 ++-------
 drivers/pwm/pwm-zx.c          |  2 +-
 include/linux/pwm.h           |  4 ++--
 20 files changed, 49 insertions(+), 58 deletions(-)

Comments

Uwe Kleine-König Sept. 2, 2019, 8:19 p.m. UTC | #1
On Sat, Aug 24, 2019 at 05:37:01PM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> this series eventually changes the prototype of pwm_apply_state to take
> a const struct pwm_state *, see the last patch for a rationale.
> 
> Changes since v2 apart from rebasing and so covering a few more drivers
> is mainly addressing the concern that after state was rounded and
> applied at least pwm_get_state should return the rounded values. See
> patch 2.

I thought a bit on this series and there is a question about it.
Depending on what is considered the right answer for it, this series
might have to change.

The key question is:

  - Is pwm_get_state() supposed to return
    a) the last requested configuration; or
    b) the last actually implemented configuration?

(If the difference is unclear: consider a PWM that can only implement
the following periods:

	1 ms, 2 ms, 3 ms, 4 ms, 5 ms, 6 ms, ...

and a consumer requested 4.2 ms. Should pwm_get_state() return .period = 4
ms (assuming this was picked) or 4.2 ms?)

As of v5.3-rc5 it depends on the backend driver. For most of them 4.2 ms
is returned. My series tries to push it to return 4 ms instead. (But
this only works for backends that implement the .get_state() callback.
And it gets more complicated as the drivers are not free of surprises.)

Maybe we need functions for both answers?

Best regards
Uwe