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

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

Pull pwm updates from Thierry Reding:
"This contains mostly minor bug fixes as well as some new chip support
for existing drivers"

* tag 'pwm/for-4.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
pwm: mediatek: Add MT7628 support
dt-bindings: pwm: Add MT7628 information
dt-bindings: pwm: rcar: Add bindings for R-Car E3 support
pwm: meson: Fix mux clock names
pwm: stm32-lp: Remove useless loop in stm32_pwm_lp_remove()
pwm: omap-dmtimer: Return -EPROBE_DEFER if no dmtimer platform data
pwm: mxs: Switch to SPDX identifier
dt-bindings: pwm: fsl-ftm: Add compatible string for i.MX8QM
pwm: fsl-ftm: Enable support for the new SoC i.MX8QM
pwm: fsl-ftm: Added the support of per-compatible data
pwm: fsl-ftm: Added a dedicated IP interface clock
pwm: cros-ec: Switch to SPDX identifier
pwm: imx: Switch to SPDX identifier
pwm: tiehrpwm: Fix disabling of output of PWMs
pwm: tiehrpwm: Don't use emulation mode bits to control PWM output
pwm: berlin: Don't use broken prescaler values

+115 -66
+4 -1
Documentation/devicetree/bindings/pwm/pwm-fsl-ftm.txt
··· 16 16 17 17 18 18 Required properties: 19 - - compatible: Should be "fsl,vf610-ftm-pwm". 19 + - compatible : should be "fsl,<soc>-ftm-pwm" and one of the following 20 + compatible strings: 21 + - "fsl,vf610-ftm-pwm" for PWM compatible with the one integrated on VF610 22 + - "fsl,imx8qm-ftm-pwm" for PWM compatible with the one integrated on i.MX8QM 20 23 - reg: Physical base address and length of the controller's registers 21 24 - #pwm-cells: Should be 3. See pwm.txt in this directory for a description of 22 25 the cells format.
+3 -1
Documentation/devicetree/bindings/pwm/pwm-mediatek.txt
··· 5 5 - "mediatek,mt2712-pwm": found on mt2712 SoC. 6 6 - "mediatek,mt7622-pwm": found on mt7622 SoC. 7 7 - "mediatek,mt7623-pwm": found on mt7623 SoC. 8 + - "mediatek,mt7628-pwm": found on mt7628 SoC. 8 9 - reg: physical base address and length of the controller's registers. 9 10 - #pwm-cells: must be 2. See pwm.txt in this directory for a description of 10 11 the cell format. 11 12 - clocks: phandle and clock specifier of the PWM reference clock. 12 - - clock-names: must contain the following: 13 + - clock-names: must contain the following, except for MT7628 which 14 + has no clocks 13 15 - "top": the top clock generator 14 16 - "main": clock used by the PWM core 15 17 - "pwm1-8": the eight per PWM clocks for mt2712
+1
Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
··· 12 12 - "renesas,pwm-r8a7795": for R-Car H3 13 13 - "renesas,pwm-r8a7796": for R-Car M3-W 14 14 - "renesas,pwm-r8a77965": for R-Car M3-N 15 + - "renesas,pwm-r8a77990": for R-Car E3 15 16 - "renesas,pwm-r8a77995": for R-Car D3 16 17 - reg: base address and length of the registers block for the PWM. 17 18 - #pwm-cells: should be 2. See pwm.txt in this directory for a description of
+1 -1
drivers/pwm/Kconfig
··· 286 286 287 287 config PWM_MEDIATEK 288 288 tristate "MediaTek PWM support" 289 - depends on ARCH_MEDIATEK || COMPILE_TEST 289 + depends on ARCH_MEDIATEK || RALINK || COMPILE_TEST 290 290 help 291 291 Generic PWM framework driver for Mediatek ARM SoC. 292 292
+25 -20
drivers/pwm/pwm-berlin.c
··· 21 21 #define BERLIN_PWM_EN 0x0 22 22 #define BERLIN_PWM_ENABLE BIT(0) 23 23 #define BERLIN_PWM_CONTROL 0x4 24 - #define BERLIN_PWM_PRESCALE_MASK 0x7 25 - #define BERLIN_PWM_PRESCALE_MAX 4096 24 + /* 25 + * The prescaler claims to support 8 different moduli, configured using the 26 + * low three bits of PWM_CONTROL. (Sequentially, they are 1, 4, 8, 16, 64, 27 + * 256, 1024, and 4096.) However, the moduli from 4 to 1024 appear to be 28 + * implemented by internally shifting TCNT left without adding additional 29 + * bits. So, the max TCNT that actually works for a modulus of 4 is 0x3fff; 30 + * for 8, 0x1fff; and so on. This means that those moduli are entirely 31 + * useless, as we could just do the shift ourselves. The 4096 modulus is 32 + * implemented with a real prescaler, so we do use that, but we treat it 33 + * as a flag instead of pretending the modulus is actually configurable. 34 + */ 35 + #define BERLIN_PWM_PRESCALE_4096 0x7 26 36 #define BERLIN_PWM_INVERT_POLARITY BIT(3) 27 37 #define BERLIN_PWM_DUTY 0x8 28 38 #define BERLIN_PWM_TCNT 0xc ··· 55 45 { 56 46 return container_of(chip, struct berlin_pwm_chip, chip); 57 47 } 58 - 59 - static const u32 prescaler_table[] = { 60 - 1, 4, 8, 16, 64, 256, 1024, 4096 61 - }; 62 48 63 49 static inline u32 berlin_pwm_readl(struct berlin_pwm_chip *chip, 64 50 unsigned int channel, unsigned long offset) ··· 92 86 int duty_ns, int period_ns) 93 87 { 94 88 struct berlin_pwm_chip *pwm = to_berlin_pwm_chip(chip); 95 - unsigned int prescale; 89 + bool prescale_4096 = false; 96 90 u32 value, duty, period; 97 - u64 cycles, tmp; 91 + u64 cycles; 98 92 99 93 cycles = clk_get_rate(pwm->clk); 100 94 cycles *= period_ns; 101 95 do_div(cycles, NSEC_PER_SEC); 102 96 103 - for (prescale = 0; prescale < ARRAY_SIZE(prescaler_table); prescale++) { 104 - tmp = cycles; 105 - do_div(tmp, prescaler_table[prescale]); 97 + if (cycles > BERLIN_PWM_MAX_TCNT) { 98 + prescale_4096 = true; 99 + cycles >>= 12; // Prescaled by 4096 106 100 107 - if (tmp <= BERLIN_PWM_MAX_TCNT) 108 - break; 101 + if (cycles > BERLIN_PWM_MAX_TCNT) 102 + return -ERANGE; 109 103 } 110 104 111 - if (tmp > BERLIN_PWM_MAX_TCNT) 112 - return -ERANGE; 113 - 114 - period = tmp; 115 - cycles = tmp * duty_ns; 105 + period = cycles; 106 + cycles *= duty_ns; 116 107 do_div(cycles, period_ns); 117 108 duty = cycles; 118 109 119 110 value = berlin_pwm_readl(pwm, pwm_dev->hwpwm, BERLIN_PWM_CONTROL); 120 - value &= ~BERLIN_PWM_PRESCALE_MASK; 121 - value |= prescale; 111 + if (prescale_4096) 112 + value |= BERLIN_PWM_PRESCALE_4096; 113 + else 114 + value &= ~BERLIN_PWM_PRESCALE_4096; 122 115 berlin_pwm_writel(pwm, pwm_dev->hwpwm, value, BERLIN_PWM_CONTROL); 123 116 124 117 berlin_pwm_writel(pwm, pwm_dev->hwpwm, duty, BERLIN_PWM_DUTY);
+3 -6
drivers/pwm/pwm-cros-ec.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 - * Copyright (C) 2016 Google, Inc 3 - * 4 - * This program is free software; you can redistribute it and/or modify it 5 - * under the terms of the GNU General Public License version 2, as published by 6 - * the Free Software Foundation. 7 - * 8 3 * Expose a PWM controlled by the ChromeOS EC to the host processor. 4 + * 5 + * Copyright (C) 2016 Google, Inc. 9 6 */ 10 7 11 8 #include <linux/module.h>
+50 -7
drivers/pwm/pwm-fsl-ftm.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/mutex.h> 18 18 #include <linux/of_address.h> 19 + #include <linux/of_device.h> 19 20 #include <linux/platform_device.h> 20 21 #include <linux/pm.h> 21 22 #include <linux/pwm.h> ··· 76 75 FSL_PWM_CLK_MAX 77 76 }; 78 77 78 + struct fsl_ftm_soc { 79 + bool has_enable_bits; 80 + }; 81 + 79 82 struct fsl_pwm_chip { 80 83 struct pwm_chip chip; 81 84 ··· 92 87 93 88 int period_ns; 94 89 90 + struct clk *ipg_clk; 95 91 struct clk *clk[FSL_PWM_CLK_MAX]; 92 + 93 + const struct fsl_ftm_soc *soc; 96 94 }; 97 95 98 96 static inline struct fsl_pwm_chip *to_fsl_chip(struct pwm_chip *chip) ··· 105 97 106 98 static int fsl_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 107 99 { 100 + int ret; 108 101 struct fsl_pwm_chip *fpc = to_fsl_chip(chip); 109 102 110 - return clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 103 + ret = clk_prepare_enable(fpc->ipg_clk); 104 + if (!ret && fpc->soc->has_enable_bits) { 105 + mutex_lock(&fpc->lock); 106 + regmap_update_bits(fpc->regmap, FTM_SC, BIT(pwm->hwpwm + 16), 107 + BIT(pwm->hwpwm + 16)); 108 + mutex_unlock(&fpc->lock); 109 + } 110 + 111 + return ret; 111 112 } 112 113 113 114 static void fsl_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 114 115 { 115 116 struct fsl_pwm_chip *fpc = to_fsl_chip(chip); 116 117 117 - clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 118 + if (fpc->soc->has_enable_bits) { 119 + mutex_lock(&fpc->lock); 120 + regmap_update_bits(fpc->regmap, FTM_SC, BIT(pwm->hwpwm + 16), 121 + 0); 122 + mutex_unlock(&fpc->lock); 123 + } 124 + 125 + clk_disable_unprepare(fpc->ipg_clk); 118 126 } 119 127 120 128 static int fsl_pwm_calculate_default_ps(struct fsl_pwm_chip *fpc, ··· 387 363 { 388 364 int ret; 389 365 390 - ret = clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 366 + ret = clk_prepare_enable(fpc->ipg_clk); 391 367 if (ret) 392 368 return ret; 393 369 ··· 395 371 regmap_write(fpc->regmap, FTM_OUTINIT, 0x00); 396 372 regmap_write(fpc->regmap, FTM_OUTMASK, 0xFF); 397 373 398 - clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 374 + clk_disable_unprepare(fpc->ipg_clk); 399 375 400 376 return 0; 401 377 } ··· 432 408 433 409 mutex_init(&fpc->lock); 434 410 411 + fpc->soc = of_device_get_match_data(&pdev->dev); 435 412 fpc->chip.dev = &pdev->dev; 436 413 437 414 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 465 440 devm_clk_get(fpc->chip.dev, "ftm_cnt_clk_en"); 466 441 if (IS_ERR(fpc->clk[FSL_PWM_CLK_CNTEN])) 467 442 return PTR_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]); 443 + 444 + /* 445 + * ipg_clk is the interface clock for the IP. If not provided, use the 446 + * ftm_sys clock as the default. 447 + */ 448 + fpc->ipg_clk = devm_clk_get(&pdev->dev, "ipg"); 449 + if (IS_ERR(fpc->ipg_clk)) 450 + fpc->ipg_clk = fpc->clk[FSL_PWM_CLK_SYS]; 451 + 468 452 469 453 fpc->chip.ops = &fsl_pwm_ops; 470 454 fpc->chip.of_xlate = of_pwm_xlate_with_flags; ··· 514 480 if (!test_bit(PWMF_REQUESTED, &pwm->flags)) 515 481 continue; 516 482 517 - clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 483 + clk_disable_unprepare(fpc->ipg_clk); 518 484 519 485 if (!pwm_is_enabled(pwm)) 520 486 continue; ··· 537 503 if (!test_bit(PWMF_REQUESTED, &pwm->flags)) 538 504 continue; 539 505 540 - clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 506 + clk_prepare_enable(fpc->ipg_clk); 541 507 542 508 if (!pwm_is_enabled(pwm)) 543 509 continue; ··· 558 524 SET_SYSTEM_SLEEP_PM_OPS(fsl_pwm_suspend, fsl_pwm_resume) 559 525 }; 560 526 527 + static const struct fsl_ftm_soc vf610_ftm_pwm = { 528 + .has_enable_bits = false, 529 + }; 530 + 531 + static const struct fsl_ftm_soc imx8qm_ftm_pwm = { 532 + .has_enable_bits = true, 533 + }; 534 + 561 535 static const struct of_device_id fsl_pwm_dt_ids[] = { 562 - { .compatible = "fsl,vf610-ftm-pwm", }, 536 + { .compatible = "fsl,vf610-ftm-pwm", .data = &vf610_ftm_pwm }, 537 + { .compatible = "fsl,imx8qm-ftm-pwm", .data = &imx8qm_ftm_pwm }, 563 538 { /* sentinel */ } 564 539 }; 565 540 MODULE_DEVICE_TABLE(of, fsl_pwm_dt_ids);
+1 -4
drivers/pwm/pwm-imx.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * simple driver for PWM (Pulse Width Modulator) controller 3 - * 4 - * This program is free software; you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License version 2 as 6 - * published by the Free Software Foundation. 7 4 * 8 5 * Derived from pxa PWM driver by eric miao <eric.miao@marvell.com> 9 6 */
+18 -1
drivers/pwm/pwm-mediatek.c
··· 57 57 struct mtk_pwm_platform_data { 58 58 unsigned int num_pwms; 59 59 bool pwm45_fixup; 60 + bool has_clks; 60 61 }; 61 62 62 63 /** ··· 87 86 struct mtk_pwm_chip *pc = to_mtk_pwm_chip(chip); 88 87 int ret; 89 88 89 + if (!pc->soc->has_clks) 90 + return 0; 91 + 90 92 ret = clk_prepare_enable(pc->clks[MTK_CLK_TOP]); 91 93 if (ret < 0) 92 94 return ret; ··· 115 111 static void mtk_pwm_clk_disable(struct pwm_chip *chip, struct pwm_device *pwm) 116 112 { 117 113 struct mtk_pwm_chip *pc = to_mtk_pwm_chip(chip); 114 + 115 + if (!pc->soc->has_clks) 116 + return; 118 117 119 118 clk_disable_unprepare(pc->clks[MTK_CLK_PWM1 + pwm->hwpwm]); 120 119 clk_disable_unprepare(pc->clks[MTK_CLK_MAIN]); ··· 246 239 if (IS_ERR(pc->regs)) 247 240 return PTR_ERR(pc->regs); 248 241 249 - for (i = 0; i < data->num_pwms + 2; i++) { 242 + for (i = 0; i < data->num_pwms + 2 && pc->soc->has_clks; i++) { 250 243 pc->clks[i] = devm_clk_get(&pdev->dev, mtk_pwm_clk_name[i]); 251 244 if (IS_ERR(pc->clks[i])) { 252 245 dev_err(&pdev->dev, "clock: %s fail: %ld\n", ··· 281 274 static const struct mtk_pwm_platform_data mt2712_pwm_data = { 282 275 .num_pwms = 8, 283 276 .pwm45_fixup = false, 277 + .has_clks = true, 284 278 }; 285 279 286 280 static const struct mtk_pwm_platform_data mt7622_pwm_data = { 287 281 .num_pwms = 6, 288 282 .pwm45_fixup = false, 283 + .has_clks = true, 289 284 }; 290 285 291 286 static const struct mtk_pwm_platform_data mt7623_pwm_data = { 292 287 .num_pwms = 5, 293 288 .pwm45_fixup = true, 289 + .has_clks = true, 290 + }; 291 + 292 + static const struct mtk_pwm_platform_data mt7628_pwm_data = { 293 + .num_pwms = 4, 294 + .pwm45_fixup = true, 295 + .has_clks = false, 294 296 }; 295 297 296 298 static const struct of_device_id mtk_pwm_of_match[] = { 297 299 { .compatible = "mediatek,mt2712-pwm", .data = &mt2712_pwm_data }, 298 300 { .compatible = "mediatek,mt7622-pwm", .data = &mt7622_pwm_data }, 299 301 { .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data }, 302 + { .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data }, 300 303 { }, 301 304 }; 302 305 MODULE_DEVICE_TABLE(of, mtk_pwm_of_match);
+1 -2
drivers/pwm/pwm-meson.c
··· 458 458 struct meson_pwm_channel *channels) 459 459 { 460 460 struct device *dev = meson->chip.dev; 461 - struct device_node *np = dev->of_node; 462 461 struct clk_init_data init; 463 462 unsigned int i; 464 463 char name[255]; ··· 466 467 for (i = 0; i < meson->chip.npwm; i++) { 467 468 struct meson_pwm_channel *channel = &channels[i]; 468 469 469 - snprintf(name, sizeof(name), "%pOF#mux%u", np, i); 470 + snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i); 470 471 471 472 init.name = name; 472 473 init.ops = &clk_mux_ops;
+1 -7
drivers/pwm/pwm-mxs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 1 2 /* 2 3 * Copyright 2012 Freescale Semiconductor, Inc. 3 - * 4 - * The code contained herein is licensed under the GNU General Public 5 - * License. You may obtain a copy of the GNU General Public License 6 - * Version 2 or later at the following locations: 7 - * 8 - * http://www.opensource.org/licenses/gpl-license.html 9 - * http://www.gnu.org/copyleft/gpl.html 10 4 */ 11 5 12 6 #include <linux/clk.h>
+3 -2
drivers/pwm/pwm-omap-dmtimer.c
··· 264 264 265 265 timer_pdata = dev_get_platdata(&timer_pdev->dev); 266 266 if (!timer_pdata) { 267 - dev_err(&pdev->dev, "dmtimer pdata structure NULL\n"); 268 - ret = -EINVAL; 267 + dev_dbg(&pdev->dev, 268 + "dmtimer pdata structure NULL, deferring probe\n"); 269 + ret = -EPROBE_DEFER; 269 270 goto put; 270 271 } 271 272
+1 -3
drivers/pwm/pwm-stm32-lp.c
··· 217 217 static int stm32_pwm_lp_remove(struct platform_device *pdev) 218 218 { 219 219 struct stm32_pwm_lp *priv = platform_get_drvdata(pdev); 220 - unsigned int i; 221 220 222 - for (i = 0; i < priv->chip.npwm; i++) 223 - pwm_disable(&priv->chip.pwms[i]); 221 + pwm_disable(&priv->chip.pwms[0]); 224 222 225 223 return pwmchip_remove(&priv->chip); 226 224 }
+3 -11
drivers/pwm/pwm-tiehrpwm.c
··· 33 33 #define TBCTL 0x00 34 34 #define TBPRD 0x0A 35 35 36 - #define TBCTL_RUN_MASK (BIT(15) | BIT(14)) 37 - #define TBCTL_STOP_NEXT 0 38 - #define TBCTL_STOP_ON_CYCLE BIT(14) 39 - #define TBCTL_FREE_RUN (BIT(15) | BIT(14)) 40 36 #define TBCTL_PRDLD_MASK BIT(3) 41 37 #define TBCTL_PRDLD_SHDW 0 42 38 #define TBCTL_PRDLD_IMDT BIT(3) ··· 356 360 /* Channels polarity can be configured from action qualifier module */ 357 361 configure_polarity(pc, pwm->hwpwm); 358 362 359 - /* Enable TBCLK before enabling PWM device */ 363 + /* Enable TBCLK */ 360 364 ret = clk_enable(pc->tbclk); 361 365 if (ret) { 362 366 dev_err(chip->dev, "Failed to enable TBCLK for %s: %d\n", 363 367 dev_name(pc->chip.dev), ret); 364 368 return ret; 365 369 } 366 - 367 - /* Enable time counter for free_run */ 368 - ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_FREE_RUN); 369 370 370 371 return 0; 371 372 } ··· 381 388 aqcsfrc_mask = AQCSFRC_CSFA_MASK; 382 389 } 383 390 391 + /* Update shadow register first before modifying active register */ 392 + ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val); 384 393 /* 385 394 * Changes to immediate action on Action Qualifier. This puts 386 395 * Action Qualifier control on PWM output from next TBCLK ··· 394 399 395 400 /* Disabling TBCLK on PWM disable */ 396 401 clk_disable(pc->tbclk); 397 - 398 - /* Stop Time base counter */ 399 - ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT); 400 402 401 403 /* Disable clock on PWM disable */ 402 404 pm_runtime_put_sync(chip->dev);