Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pwm/for-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm

Pull pwm updates from Thierry Reding:
"Various changes and minor fixes across a couple of drivers"

* tag 'pwm/for-5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
pwm: stm32: Pass breakinput instead of its values
pwm: stm32: Remove clutter from ternary operator
pwm: stm32: Validate breakinput data from DT
pwm: Update comment on struct pwm_ops::apply
pwm: sun4i: Fix incorrect calculation of duty_cycle/period
pwm: stm32: Add power management support
pwm: stm32: Split breakinput apply routine to ease PM support
dt-bindings: pwm-stm32: Document pinctrl sleep state
pwm: sun4i: Drop redundant assignment to variable pval
dt-bindings: pwm: mediatek: Remove gratuitous compatible string for MT7629

+90 -46
+1 -1
Documentation/devicetree/bindings/pwm/pwm-mediatek.txt
··· 6 6 - "mediatek,mt7622-pwm": found on mt7622 SoC. 7 7 - "mediatek,mt7623-pwm": found on mt7623 SoC. 8 8 - "mediatek,mt7628-pwm": found on mt7628 SoC. 9 - - "mediatek,mt7629-pwm", "mediatek,mt7622-pwm": found on mt7629 SoC. 9 + - "mediatek,mt7629-pwm": found on mt7629 SoC. 10 10 - "mediatek,mt8516-pwm": found on mt8516 SoC. 11 11 - reg: physical base address and length of the controller's registers. 12 12 - #pwm-cells: must be 2. See pwm.yaml in this directory for a description of
+82 -30
drivers/pwm/pwm-stm32.c
··· 12 12 #include <linux/mfd/stm32-timers.h> 13 13 #include <linux/module.h> 14 14 #include <linux/of.h> 15 + #include <linux/pinctrl/consumer.h> 15 16 #include <linux/platform_device.h> 16 17 #include <linux/pwm.h> 17 18 18 19 #define CCMR_CHANNEL_SHIFT 8 19 20 #define CCMR_CHANNEL_MASK 0xFF 20 21 #define MAX_BREAKINPUT 2 22 + 23 + struct stm32_breakinput { 24 + u32 index; 25 + u32 level; 26 + u32 filter; 27 + }; 21 28 22 29 struct stm32_pwm { 23 30 struct pwm_chip chip; ··· 33 26 struct regmap *regmap; 34 27 u32 max_arr; 35 28 bool have_complementary_output; 29 + struct stm32_breakinput breakinputs[MAX_BREAKINPUT]; 30 + unsigned int num_breakinputs; 36 31 u32 capture[4] ____cacheline_aligned; /* DMA'able buffer */ 37 - }; 38 - 39 - struct stm32_breakinput { 40 - u32 index; 41 - u32 level; 42 - u32 filter; 43 32 }; 44 33 45 34 static inline struct stm32_pwm *to_stm32_pwm_dev(struct pwm_chip *chip) ··· 491 488 }; 492 489 493 490 static int stm32_pwm_set_breakinput(struct stm32_pwm *priv, 494 - int index, int level, int filter) 491 + const struct stm32_breakinput *bi) 495 492 { 496 - u32 bke = (index == 0) ? TIM_BDTR_BKE : TIM_BDTR_BK2E; 497 - int shift = (index == 0) ? TIM_BDTR_BKF_SHIFT : TIM_BDTR_BK2F_SHIFT; 498 - u32 mask = (index == 0) ? TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF 499 - : TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F; 500 - u32 bdtr = bke; 493 + u32 shift = TIM_BDTR_BKF_SHIFT(bi->index); 494 + u32 bke = TIM_BDTR_BKE(bi->index); 495 + u32 bkp = TIM_BDTR_BKP(bi->index); 496 + u32 bkf = TIM_BDTR_BKF(bi->index); 497 + u32 mask = bkf | bkp | bke; 498 + u32 bdtr; 501 499 502 - /* 503 - * The both bits could be set since only one will be wrote 504 - * due to mask value. 505 - */ 506 - if (level) 507 - bdtr |= TIM_BDTR_BKP | TIM_BDTR_BK2P; 500 + bdtr = (bi->filter & TIM_BDTR_BKF_MASK) << shift | bke; 508 501 509 - bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift; 502 + if (bi->level) 503 + bdtr |= bkp; 510 504 511 505 regmap_update_bits(priv->regmap, TIM_BDTR, mask, bdtr); 512 506 ··· 512 512 return (bdtr & bke) ? 0 : -EINVAL; 513 513 } 514 514 515 - static int stm32_pwm_apply_breakinputs(struct stm32_pwm *priv, 515 + static int stm32_pwm_apply_breakinputs(struct stm32_pwm *priv) 516 + { 517 + unsigned int i; 518 + int ret; 519 + 520 + for (i = 0; i < priv->num_breakinputs; i++) { 521 + ret = stm32_pwm_set_breakinput(priv, &priv->breakinputs[i]); 522 + if (ret < 0) 523 + return ret; 524 + } 525 + 526 + return 0; 527 + } 528 + 529 + static int stm32_pwm_probe_breakinputs(struct stm32_pwm *priv, 516 530 struct device_node *np) 517 531 { 518 - struct stm32_breakinput breakinput[MAX_BREAKINPUT]; 519 - int nb, ret, i, array_size; 532 + int nb, ret, array_size; 533 + unsigned int i; 520 534 521 535 nb = of_property_count_elems_of_size(np, "st,breakinput", 522 536 sizeof(struct stm32_breakinput)); ··· 545 531 if (nb > MAX_BREAKINPUT) 546 532 return -EINVAL; 547 533 534 + priv->num_breakinputs = nb; 548 535 array_size = nb * sizeof(struct stm32_breakinput) / sizeof(u32); 549 536 ret = of_property_read_u32_array(np, "st,breakinput", 550 - (u32 *)breakinput, array_size); 537 + (u32 *)priv->breakinputs, array_size); 551 538 if (ret) 552 539 return ret; 553 540 554 - for (i = 0; i < nb && !ret; i++) { 555 - ret = stm32_pwm_set_breakinput(priv, 556 - breakinput[i].index, 557 - breakinput[i].level, 558 - breakinput[i].filter); 541 + for (i = 0; i < priv->num_breakinputs; i++) { 542 + if (priv->breakinputs[i].index > 1 || 543 + priv->breakinputs[i].level > 1 || 544 + priv->breakinputs[i].filter > 15) 545 + return -EINVAL; 559 546 } 560 547 561 - return ret; 548 + return stm32_pwm_apply_breakinputs(priv); 562 549 } 563 550 564 551 static void stm32_pwm_detect_complementary(struct stm32_pwm *priv) ··· 629 614 if (!priv->regmap || !priv->clk) 630 615 return -EINVAL; 631 616 632 - ret = stm32_pwm_apply_breakinputs(priv, np); 617 + ret = stm32_pwm_probe_breakinputs(priv, np); 633 618 if (ret) 634 619 return ret; 635 620 ··· 662 647 return 0; 663 648 } 664 649 650 + static int __maybe_unused stm32_pwm_suspend(struct device *dev) 651 + { 652 + struct stm32_pwm *priv = dev_get_drvdata(dev); 653 + unsigned int i; 654 + u32 ccer, mask; 655 + 656 + /* Look for active channels */ 657 + ccer = active_channels(priv); 658 + 659 + for (i = 0; i < priv->chip.npwm; i++) { 660 + mask = TIM_CCER_CC1E << (i * 4); 661 + if (ccer & mask) { 662 + dev_err(dev, "PWM %u still in use by consumer %s\n", 663 + i, priv->chip.pwms[i].label); 664 + return -EBUSY; 665 + } 666 + } 667 + 668 + return pinctrl_pm_select_sleep_state(dev); 669 + } 670 + 671 + static int __maybe_unused stm32_pwm_resume(struct device *dev) 672 + { 673 + struct stm32_pwm *priv = dev_get_drvdata(dev); 674 + int ret; 675 + 676 + ret = pinctrl_pm_select_default_state(dev); 677 + if (ret) 678 + return ret; 679 + 680 + /* restore breakinput registers that may have been lost in low power */ 681 + return stm32_pwm_apply_breakinputs(priv); 682 + } 683 + 684 + static SIMPLE_DEV_PM_OPS(stm32_pwm_pm_ops, stm32_pwm_suspend, stm32_pwm_resume); 685 + 665 686 static const struct of_device_id stm32_pwm_of_match[] = { 666 687 { .compatible = "st,stm32-pwm", }, 667 688 { /* end node */ }, ··· 710 659 .driver = { 711 660 .name = "stm32-pwm", 712 661 .of_match_table = stm32_pwm_of_match, 662 + .pm = &stm32_pwm_pm_ops, 713 663 }, 714 664 }; 715 665 module_platform_driver(stm32_pwm_driver);
+2 -3
drivers/pwm/pwm-sun4i.c
··· 137 137 138 138 val = sun4i_pwm_readl(sun4i_pwm, PWM_CH_PRD(pwm->hwpwm)); 139 139 140 - tmp = prescaler * NSEC_PER_SEC * PWM_REG_DTY(val); 140 + tmp = (u64)prescaler * NSEC_PER_SEC * PWM_REG_DTY(val); 141 141 state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); 142 142 143 - tmp = prescaler * NSEC_PER_SEC * PWM_REG_PRD(val); 143 + tmp = (u64)prescaler * NSEC_PER_SEC * PWM_REG_PRD(val); 144 144 state->period = DIV_ROUND_CLOSEST_ULL(tmp, clk_rate); 145 145 } 146 146 ··· 156 156 if (sun4i_pwm->data->has_prescaler_bypass) { 157 157 /* First, test without any prescaler when available */ 158 158 prescaler = PWM_PRESCAL_MASK; 159 - pval = 1; 160 159 /* 161 160 * When not using any prescaler, the clock period in nanoseconds 162 161 * is not an integer so round it half up instead of
+4 -8
include/linux/mfd/stm32-timers.h
··· 70 70 #define TIM_CCER_CC4E BIT(12) /* Capt/Comp 4 out Ena */ 71 71 #define TIM_CCER_CC4P BIT(13) /* Capt/Comp 4 Polarity */ 72 72 #define TIM_CCER_CCXE (BIT(0) | BIT(4) | BIT(8) | BIT(12)) 73 - #define TIM_BDTR_BKE BIT(12) /* Break input enable */ 74 - #define TIM_BDTR_BKP BIT(13) /* Break input polarity */ 73 + #define TIM_BDTR_BKE(x) BIT(12 + (x) * 12) /* Break input enable */ 74 + #define TIM_BDTR_BKP(x) BIT(13 + (x) * 12) /* Break input polarity */ 75 75 #define TIM_BDTR_AOE BIT(14) /* Automatic Output Enable */ 76 76 #define TIM_BDTR_MOE BIT(15) /* Main Output Enable */ 77 - #define TIM_BDTR_BKF (BIT(16) | BIT(17) | BIT(18) | BIT(19)) 78 - #define TIM_BDTR_BK2F (BIT(20) | BIT(21) | BIT(22) | BIT(23)) 79 - #define TIM_BDTR_BK2E BIT(24) /* Break 2 input enable */ 80 - #define TIM_BDTR_BK2P BIT(25) /* Break 2 input polarity */ 77 + #define TIM_BDTR_BKF(x) (0xf << (16 + (x) * 4)) 81 78 #define TIM_DCR_DBA GENMASK(4, 0) /* DMA base addr */ 82 79 #define TIM_DCR_DBL GENMASK(12, 8) /* DMA burst len */ 83 80 ··· 84 87 #define TIM_CR2_MMS2_SHIFT 20 85 88 #define TIM_SMCR_TS_SHIFT 4 86 89 #define TIM_BDTR_BKF_MASK 0xF 87 - #define TIM_BDTR_BKF_SHIFT 16 88 - #define TIM_BDTR_BK2F_SHIFT 20 90 + #define TIM_BDTR_BKF_SHIFT(x) (16 + (x) * 4) 89 91 90 92 enum stm32_timers_dmas { 91 93 STM32_TIMERS_DMA_CH1,
+1 -4
include/linux/pwm.h
··· 243 243 * @request: optional hook for requesting a PWM 244 244 * @free: optional hook for freeing a PWM 245 245 * @capture: capture and report PWM signal 246 - * @apply: atomically apply a new PWM config. The state argument 247 - * should be adjusted with the real hardware config (if the 248 - * approximate the period or duty_cycle value, state should 249 - * reflect it) 246 + * @apply: atomically apply a new PWM config 250 247 * @get_state: get the current PWM state. This function is only 251 248 * called once per PWM device when the PWM chip is 252 249 * registered.