Skip to content

Commit

Permalink
Merge tag 'pwm/for-5.8-rc1' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/thierry.reding/linux-pwm

Pull pwm updates from Thierry Reding:
 "Nothing too exciting for this cycle. A couple of fixes across the
  board, and Lee volunteered to help with patch review"

* tag 'pwm/for-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
  pwm: Add missing "CONFIG_" prefix
  MAINTAINERS: Add Lee Jones as reviewer for the PWM subsystem
  pwm: imx27: Fix rounding behavior
  pwm: rockchip: Simplify rockchip_pwm_get_state()
  pwm: img: Call pm_runtime_put() in pm_runtime_get_sync() failed case
  pwm: tegra: Support dynamic clock frequency configuration
  pwm: jz4740: Add support for the JZ4725B
  pwm: jz4740: Make PWM start with the active part
  pwm: jz4740: Enhance precision in calculation of duty cycle
  pwm: jz4740: Drop dependency on MACH_INGENIC
  pwm: lpss: Fix get_state runtime-pm reference handling
  pwm: sun4i: Support direct clock output on Allwinner A64
  pwm: Add support for Azoteq IQS620A PWM generator
  dt-bindings: pwm: rcar: add r8a77961 support
  pwm: Add missing '\n' in log messages
  • Loading branch information
torvalds committed Jun 12, 2020
2 parents 8f02f36 + f5641d0 commit 9433a51
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ properties:
- renesas,pwm-r8a7794 # R-Car E2
- renesas,pwm-r8a7795 # R-Car H3
- renesas,pwm-r8a7796 # R-Car M3-W
- renesas,pwm-r8a77961 # R-Car M3-W+
- renesas,pwm-r8a77965 # R-Car M3-N
- renesas,pwm-r8a77970 # R-Car V3M
- renesas,pwm-r8a77980 # R-Car V3H
Expand Down
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -13919,6 +13919,7 @@ F: drivers/media/rc/pwm-ir-tx.c
PWM SUBSYSTEM
M: Thierry Reding <[email protected]>
R: Uwe Kleine-König <[email protected]>
M: Lee Jones <[email protected]>
L: [email protected]
S: Maintained
Q: https://patchwork.ozlabs.org/project/linux-pwm/list/
Expand Down
12 changes: 11 additions & 1 deletion drivers/pwm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,19 @@ config PWM_IMX_TPM
To compile this driver as a module, choose M here: the module
will be called pwm-imx-tpm.

config PWM_IQS620A
tristate "Azoteq IQS620A PWM support"
depends on MFD_IQS62X || COMPILE_TEST
help
Generic PWM framework driver for the Azoteq IQS620A multi-function
sensor.

To compile this driver as a module, choose M here: the module will
be called pwm-iqs620a.

config PWM_JZ4740
tristate "Ingenic JZ47xx PWM support"
depends on MACH_INGENIC
depends on MIPS
depends on COMMON_CLK
select MFD_SYSCON
help
Expand Down
1 change: 1 addition & 0 deletions drivers/pwm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ obj-$(CONFIG_PWM_IMG) += pwm-img.o
obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o
obj-$(CONFIG_PWM_IMX27) += pwm-imx27.o
obj-$(CONFIG_PWM_IMX_TPM) += pwm-imx-tpm.o
obj-$(CONFIG_PWM_IQS620A) += pwm-iqs620a.o
obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o
obj-$(CONFIG_PWM_LP3943) += pwm-lp3943.o
obj-$(CONFIG_PWM_LPC18XX_SCT) += pwm-lpc18xx-sct.o
Expand Down
4 changes: 2 additions & 2 deletions drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state);
trace_pwm_get(pwm, &pwm->state);

if (IS_ENABLED(PWM_DEBUG))
if (IS_ENABLED(CONFIG_PWM_DEBUG))
pwm->last = pwm->state;
}

Expand Down Expand Up @@ -537,7 +537,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,

if (!state->enabled && s2.enabled && s2.duty_cycle > 0)
dev_warn(chip->dev,
"requested disabled, but yielded enabled with duty > 0");
"requested disabled, but yielded enabled with duty > 0\n");

/* reapply the state that the driver reported being configured. */
err = chip->ops->apply(chip, pwm, &s1);
Expand Down
8 changes: 6 additions & 2 deletions drivers/pwm/pwm-img.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
duty = DIV_ROUND_UP(timebase * duty_ns, period_ns);

ret = pm_runtime_get_sync(chip->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_autosuspend(chip->dev);
return ret;
}

val = img_pwm_readl(pwm_chip, PWM_CTRL_CFG);
val &= ~(PWM_CTRL_CFG_DIV_MASK << PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm));
Expand Down Expand Up @@ -331,8 +333,10 @@ static int img_pwm_remove(struct platform_device *pdev)
int ret;

ret = pm_runtime_get_sync(&pdev->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put(&pdev->dev);
return ret;
}

for (i = 0; i < pwm_chip->chip.npwm; i++) {
val = img_pwm_readl(pwm_chip, PWM_CTRL_CFG);
Expand Down
20 changes: 10 additions & 10 deletions drivers/pwm/pwm-imx27.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,12 @@ static void pwm_imx27_get_state(struct pwm_chip *chip,

prescaler = MX3_PWMCR_PRESCALER_GET(val);
pwm_clk = clk_get_rate(imx->clk_per);
pwm_clk = DIV_ROUND_CLOSEST_ULL(pwm_clk, prescaler);
val = readl(imx->mmio_base + MX3_PWMPR);
period = val >= MX3_PWMPR_MAX ? MX3_PWMPR_MAX : val;

/* PWMOUT (Hz) = PWMCLK / (PWMPR + 2) */
tmp = NSEC_PER_SEC * (u64)(period + 2);
state->period = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk);
tmp = NSEC_PER_SEC * (u64)(period + 2) * prescaler;
state->period = DIV_ROUND_UP_ULL(tmp, pwm_clk);

/*
* PWMSAR can be read only if PWM is enabled. If the PWM is disabled,
Expand All @@ -167,8 +166,8 @@ static void pwm_imx27_get_state(struct pwm_chip *chip,
else
val = imx->duty_cycle;

tmp = NSEC_PER_SEC * (u64)(val);
state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk);
tmp = NSEC_PER_SEC * (u64)(val) * prescaler;
state->duty_cycle = DIV_ROUND_UP_ULL(tmp, pwm_clk);

pwm_imx27_clk_disable_unprepare(imx);
}
Expand Down Expand Up @@ -220,22 +219,23 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
struct pwm_imx27_chip *imx = to_pwm_imx27_chip(chip);
struct pwm_state cstate;
unsigned long long c;
unsigned long long clkrate;
int ret;
u32 cr;

pwm_get_state(pwm, &cstate);

c = clk_get_rate(imx->clk_per);
c *= state->period;
clkrate = clk_get_rate(imx->clk_per);
c = clkrate * state->period;

do_div(c, 1000000000);
do_div(c, NSEC_PER_SEC);
period_cycles = c;

prescale = period_cycles / 0x10000 + 1;

period_cycles /= prescale;
c = (unsigned long long)period_cycles * state->duty_cycle;
do_div(c, state->period);
c = clkrate * state->duty_cycle;
do_div(c, NSEC_PER_SEC * prescale);
duty_cycles = c;

/*
Expand Down
Loading

0 comments on commit 9433a51

Please sign in to comment.