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

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

Pull pwm updates from Thierry Reding:
"Mostly cleanups and minor improvements with some new chip support for
some drivers"

* tag 'pwm/for-5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (37 commits)
pwm: Remove set but not set variable 'pwm'
pwm: sun4i: Initialize variables before use
pwm: stm32: Remove automatic output enable
pwm: sun4i: Narrow scope of local variable
pwm: bcm2835: Allow building for ARCH_BRCMSTB
pwm: imx27: Eliminate error message for defer probe
pwm: sun4i: Fix inconsistent IS_ERR and PTR_ERR
pwm: sun4i: Move pwm_calculate() out of spin_lock()
pwm: omap-dmtimer: Allow compiling with COMPILE_TEST
pwm: omap-dmtimer: put_device() after of_find_device_by_node()
pwm: omap-dmtimer: Simplify error handling
pwm: omap-dmtimer: Remove PWM chip in .remove before making it unfunctional
pwm: Implement tracing for .get_state() and .apply_state()
pwm: rcar: Document inability to set duty_cycle = 0
pwm: rcar: Drop useless call to pwm_get_state()
pwm: Fix minor Kconfig whitespace issues
pwm: atmel: Implement .get_state()
pwm: atmel: Use register accessors for channels
pwm: atmel: Document known weaknesses of both hardware and software
pwm: atmel: Replace loop in prescale calculation by ad-hoc calculation
...

+535 -195
+2 -2
Documentation/devicetree/bindings/pwm/mxs-pwm.txt
··· 3 3 Required properties: 4 4 - compatible: should be "fsl,imx23-pwm" 5 5 - reg: physical base address and length of the controller's registers 6 - - #pwm-cells: should be 2. See pwm.yaml in this directory for a description of 6 + - #pwm-cells: should be 3. See pwm.yaml in this directory for a description of 7 7 the cells format. 8 8 - fsl,pwm-number: the number of PWM devices 9 9 ··· 12 12 pwm: pwm@80064000 { 13 13 compatible = "fsl,imx28-pwm", "fsl,imx23-pwm"; 14 14 reg = <0x80064000 0x2000>; 15 - #pwm-cells = <2>; 15 + #pwm-cells = <3>; 16 16 fsl,pwm-number = <8>; 17 17 };
+5 -4
drivers/pwm/Kconfig
··· 100 100 101 101 config PWM_BCM2835 102 102 tristate "BCM2835 PWM support" 103 - depends on ARCH_BCM2835 103 + depends on ARCH_BCM2835 || ARCH_BRCMSTB 104 104 help 105 105 PWM framework driver for BCM2835 controller (Raspberry Pi) 106 106 ··· 328 328 329 329 config PWM_OMAP_DMTIMER 330 330 tristate "OMAP Dual-Mode Timer PWM support" 331 - depends on OF && ARCH_OMAP && OMAP_DM_TIMER 331 + depends on OF 332 + depends on OMAP_DM_TIMER || COMPILE_TEST 332 333 help 333 334 Generic PWM framework driver for OMAP Dual-Mode Timer PWM output 334 335 ··· 491 490 To compile this driver as a module, choose M here: the module 492 491 will be called pwm-tegra. 493 492 494 - config PWM_TIECAP 493 + config PWM_TIECAP 495 494 tristate "ECAP PWM support" 496 495 depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE || ARCH_K3 497 496 help ··· 500 499 To compile this driver as a module, choose M here: the module 501 500 will be called pwm-tiecap. 502 501 503 - config PWM_TIEHRPWM 502 + config PWM_TIEHRPWM 504 503 tristate "EHRPWM PWM support" 505 504 depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_K3 506 505 help
+10 -3
drivers/pwm/core.c
··· 20 20 21 21 #include <dt-bindings/pwm/pwm.h> 22 22 23 + #define CREATE_TRACE_POINTS 24 + #include <trace/events/pwm.h> 25 + 23 26 #define MAX_PWMS 1024 24 27 25 28 static DEFINE_MUTEX(pwm_lookup_lock); ··· 115 112 module_put(pwm->chip->ops->owner); 116 113 return err; 117 114 } 115 + } 116 + 117 + if (pwm->chip->ops->get_state) { 118 + pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state); 119 + trace_pwm_get(pwm, &pwm->state); 118 120 } 119 121 120 122 set_bit(PWMF_REQUESTED, &pwm->flags); ··· 290 282 pwm->pwm = chip->base + i; 291 283 pwm->hwpwm = i; 292 284 pwm->state.polarity = polarity; 293 - 294 - if (chip->ops->get_state) 295 - chip->ops->get_state(chip, pwm, &pwm->state); 296 285 297 286 radix_tree_insert(&pwm_tree, pwm->pwm, pwm); 298 287 } ··· 476 471 err = chip->ops->apply(chip, pwm, state); 477 472 if (err) 478 473 return err; 474 + 475 + trace_pwm_apply(pwm, state); 479 476 480 477 pwm->state = *state; 481 478 } else {
+74 -13
drivers/pwm/pwm-atmel.c
··· 4 4 * 5 5 * Copyright (C) 2013 Atmel Corporation 6 6 * Bo Shen <voice.shen@atmel.com> 7 + * 8 + * Links to reference manuals for the supported PWM chips can be found in 9 + * Documentation/arm/microchip.rst. 10 + * 11 + * Limitations: 12 + * - Periods start with the inactive level. 13 + * - Hardware has to be stopped in general to update settings. 14 + * 15 + * Software bugs/possible improvements: 16 + * - When atmel_pwm_apply() is called with state->enabled=false a change in 17 + * state->polarity isn't honored. 18 + * - Instead of sleeping to wait for a completed period, the interrupt 19 + * functionality could be used. 7 20 */ 8 21 9 22 #include <linux/clk.h> ··· 60 47 #define PWMV2_CPRD 0x0C 61 48 #define PWMV2_CPRDUPD 0x10 62 49 50 + #define PWM_MAX_PRES 10 51 + 63 52 struct atmel_pwm_registers { 64 53 u8 period; 65 54 u8 period_upd; ··· 70 55 }; 71 56 72 57 struct atmel_pwm_config { 73 - u32 max_period; 74 - u32 max_pres; 58 + u32 period_bits; 75 59 }; 76 60 77 61 struct atmel_pwm_data { ··· 111 97 { 112 98 unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE; 113 99 114 - return readl_relaxed(chip->base + base + offset); 100 + return atmel_pwm_readl(chip, base + offset); 115 101 } 116 102 117 103 static inline void atmel_pwm_ch_writel(struct atmel_pwm_chip *chip, ··· 120 106 { 121 107 unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE; 122 108 123 - writel_relaxed(val, chip->base + base + offset); 109 + atmel_pwm_writel(chip, base + offset, val); 124 110 } 125 111 126 112 static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip, ··· 129 115 { 130 116 struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 131 117 unsigned long long cycles = state->period; 118 + int shift; 132 119 133 120 /* Calculate the period cycles and prescale value */ 134 121 cycles *= clk_get_rate(atmel_pwm->clk); 135 122 do_div(cycles, NSEC_PER_SEC); 136 123 137 - for (*pres = 0; cycles > atmel_pwm->data->cfg.max_period; cycles >>= 1) 138 - (*pres)++; 124 + /* 125 + * The register for the period length is cfg.period_bits bits wide. 126 + * So for each bit the number of clock cycles is wider divide the input 127 + * clock frequency by two using pres and shift cprd accordingly. 128 + */ 129 + shift = fls(cycles) - atmel_pwm->data->cfg.period_bits; 139 130 140 - if (*pres > atmel_pwm->data->cfg.max_pres) { 131 + if (shift > PWM_MAX_PRES) { 141 132 dev_err(chip->dev, "pres exceeds the maximum value\n"); 142 133 return -EINVAL; 134 + } else if (shift > 0) { 135 + *pres = shift; 136 + cycles >>= *pres; 137 + } else { 138 + *pres = 0; 143 139 } 144 140 145 141 *cprd = cycles; ··· 295 271 return 0; 296 272 } 297 273 274 + static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 275 + struct pwm_state *state) 276 + { 277 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 278 + u32 sr, cmr; 279 + 280 + sr = atmel_pwm_readl(atmel_pwm, PWM_SR); 281 + cmr = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); 282 + 283 + if (sr & (1 << pwm->hwpwm)) { 284 + unsigned long rate = clk_get_rate(atmel_pwm->clk); 285 + u32 cdty, cprd, pres; 286 + u64 tmp; 287 + 288 + pres = cmr & PWM_CMR_CPRE_MSK; 289 + 290 + cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, 291 + atmel_pwm->data->regs.period); 292 + tmp = (u64)cprd * NSEC_PER_SEC; 293 + tmp <<= pres; 294 + state->period = DIV64_U64_ROUND_UP(tmp, rate); 295 + 296 + cdty = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, 297 + atmel_pwm->data->regs.duty); 298 + tmp = (u64)cdty * NSEC_PER_SEC; 299 + tmp <<= pres; 300 + state->duty_cycle = DIV64_U64_ROUND_UP(tmp, rate); 301 + 302 + state->enabled = true; 303 + } else { 304 + state->enabled = false; 305 + } 306 + 307 + if (cmr & PWM_CMR_CPOL) 308 + state->polarity = PWM_POLARITY_INVERSED; 309 + else 310 + state->polarity = PWM_POLARITY_NORMAL; 311 + } 312 + 298 313 static const struct pwm_ops atmel_pwm_ops = { 299 314 .apply = atmel_pwm_apply, 315 + .get_state = atmel_pwm_get_state, 300 316 .owner = THIS_MODULE, 301 317 }; 302 318 ··· 349 285 }, 350 286 .cfg = { 351 287 /* 16 bits to keep period and duty. */ 352 - .max_period = 0xffff, 353 - .max_pres = 10, 288 + .period_bits = 16, 354 289 }, 355 290 }; 356 291 ··· 362 299 }, 363 300 .cfg = { 364 301 /* 16 bits to keep period and duty. */ 365 - .max_period = 0xffff, 366 - .max_pres = 10, 302 + .period_bits = 16, 367 303 }, 368 304 }; 369 305 ··· 375 313 }, 376 314 .cfg = { 377 315 /* 32 bits to keep period and duty. */ 378 - .max_period = 0xffffffff, 379 - .max_pres = 10, 316 + .period_bits = 32, 380 317 }, 381 318 }; 382 319
+54 -4
drivers/pwm/pwm-cros-ec.c
··· 25 25 struct pwm_chip chip; 26 26 }; 27 27 28 + /** 29 + * struct cros_ec_pwm - per-PWM driver data 30 + * @duty_cycle: cached duty cycle 31 + */ 32 + struct cros_ec_pwm { 33 + u16 duty_cycle; 34 + }; 35 + 28 36 static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *c) 29 37 { 30 38 return container_of(c, struct cros_ec_pwm_device, chip); 39 + } 40 + 41 + static int cros_ec_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 42 + { 43 + struct cros_ec_pwm *channel; 44 + 45 + channel = kzalloc(sizeof(*channel), GFP_KERNEL); 46 + if (!channel) 47 + return -ENOMEM; 48 + 49 + pwm_set_chip_data(pwm, channel); 50 + 51 + return 0; 52 + } 53 + 54 + static void cros_ec_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 55 + { 56 + struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 57 + 58 + kfree(channel); 31 59 } 32 60 33 61 static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) ··· 124 96 const struct pwm_state *state) 125 97 { 126 98 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip); 127 - int duty_cycle; 99 + struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 100 + u16 duty_cycle; 101 + int ret; 128 102 129 103 /* The EC won't let us change the period */ 130 104 if (state->period != EC_PWM_MAX_DUTY) ··· 138 108 */ 139 109 duty_cycle = state->enabled ? state->duty_cycle : 0; 140 110 141 - return cros_ec_pwm_set_duty(ec_pwm->ec, pwm->hwpwm, duty_cycle); 111 + ret = cros_ec_pwm_set_duty(ec_pwm->ec, pwm->hwpwm, duty_cycle); 112 + if (ret < 0) 113 + return ret; 114 + 115 + channel->duty_cycle = state->duty_cycle; 116 + 117 + return 0; 142 118 } 143 119 144 120 static void cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 145 121 struct pwm_state *state) 146 122 { 147 123 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip); 124 + struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 148 125 int ret; 149 126 150 127 ret = cros_ec_pwm_get_duty(ec_pwm->ec, pwm->hwpwm); ··· 163 126 state->enabled = (ret > 0); 164 127 state->period = EC_PWM_MAX_DUTY; 165 128 166 - /* Note that "disabled" and "duty cycle == 0" are treated the same */ 167 - state->duty_cycle = ret; 129 + /* 130 + * Note that "disabled" and "duty cycle == 0" are treated the same. If 131 + * the cached duty cycle is not zero, used the cached duty cycle. This 132 + * ensures that the configured duty cycle is kept across a disable and 133 + * enable operation and avoids potentially confusing consumers. 134 + * 135 + * For the case of the initial hardware readout, channel->duty_cycle 136 + * will be 0 and the actual duty cycle read from the EC is used. 137 + */ 138 + if (ret == 0 && channel->duty_cycle > 0) 139 + state->duty_cycle = channel->duty_cycle; 140 + else 141 + state->duty_cycle = ret; 168 142 } 169 143 170 144 static struct pwm_device * ··· 197 149 } 198 150 199 151 static const struct pwm_ops cros_ec_pwm_ops = { 152 + .request = cros_ec_pwm_request, 153 + .free = cros_ec_pwm_free, 200 154 .get_state = cros_ec_pwm_get_state, 201 155 .apply = cros_ec_pwm_apply, 202 156 .owner = THIS_MODULE,
+78 -59
drivers/pwm/pwm-imx27.c
··· 85 85 struct clk *clk_per; 86 86 void __iomem *mmio_base; 87 87 struct pwm_chip chip; 88 + 89 + /* 90 + * The driver cannot read the current duty cycle from the hardware if 91 + * the hardware is disabled. Cache the last programmed duty cycle 92 + * value to return in that case. 93 + */ 94 + unsigned int duty_cycle; 88 95 }; 89 96 90 97 #define to_pwm_imx27_chip(chip) container_of(chip, struct pwm_imx27_chip, chip) ··· 162 155 tmp = NSEC_PER_SEC * (u64)(period + 2); 163 156 state->period = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk); 164 157 165 - /* PWMSAR can be read only if PWM is enabled */ 166 - if (state->enabled) { 158 + /* 159 + * PWMSAR can be read only if PWM is enabled. If the PWM is disabled, 160 + * use the cached value. 161 + */ 162 + if (state->enabled) 167 163 val = readl(imx->mmio_base + MX3_PWMSAR); 168 - tmp = NSEC_PER_SEC * (u64)(val); 169 - state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk); 170 - } else { 171 - state->duty_cycle = 0; 172 - } 164 + else 165 + val = imx->duty_cycle; 166 + 167 + tmp = NSEC_PER_SEC * (u64)(val); 168 + state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, pwm_clk); 173 169 174 170 if (!state->enabled) 175 171 pwm_imx27_clk_disable_unprepare(chip); ··· 230 220 231 221 pwm_get_state(pwm, &cstate); 232 222 233 - if (state->enabled) { 234 - c = clk_get_rate(imx->clk_per); 235 - c *= state->period; 223 + c = clk_get_rate(imx->clk_per); 224 + c *= state->period; 236 225 237 - do_div(c, 1000000000); 238 - period_cycles = c; 226 + do_div(c, 1000000000); 227 + period_cycles = c; 239 228 240 - prescale = period_cycles / 0x10000 + 1; 229 + prescale = period_cycles / 0x10000 + 1; 241 230 242 - period_cycles /= prescale; 243 - c = (unsigned long long)period_cycles * state->duty_cycle; 244 - do_div(c, state->period); 245 - duty_cycles = c; 231 + period_cycles /= prescale; 232 + c = (unsigned long long)period_cycles * state->duty_cycle; 233 + do_div(c, state->period); 234 + duty_cycles = c; 246 235 247 - /* 248 - * according to imx pwm RM, the real period value should be 249 - * PERIOD value in PWMPR plus 2. 250 - */ 251 - if (period_cycles > 2) 252 - period_cycles -= 2; 253 - else 254 - period_cycles = 0; 236 + /* 237 + * according to imx pwm RM, the real period value should be PERIOD 238 + * value in PWMPR plus 2. 239 + */ 240 + if (period_cycles > 2) 241 + period_cycles -= 2; 242 + else 243 + period_cycles = 0; 255 244 256 - /* 257 - * Wait for a free FIFO slot if the PWM is already enabled, and 258 - * flush the FIFO if the PWM was disabled and is about to be 259 - * enabled. 260 - */ 261 - if (cstate.enabled) { 262 - pwm_imx27_wait_fifo_slot(chip, pwm); 263 - } else { 264 - ret = pwm_imx27_clk_prepare_enable(chip); 265 - if (ret) 266 - return ret; 245 + /* 246 + * Wait for a free FIFO slot if the PWM is already enabled, and flush 247 + * the FIFO if the PWM was disabled and is about to be enabled. 248 + */ 249 + if (cstate.enabled) { 250 + pwm_imx27_wait_fifo_slot(chip, pwm); 251 + } else { 252 + ret = pwm_imx27_clk_prepare_enable(chip); 253 + if (ret) 254 + return ret; 267 255 268 - pwm_imx27_sw_reset(chip); 269 - } 270 - 271 - writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); 272 - writel(period_cycles, imx->mmio_base + MX3_PWMPR); 273 - 274 - cr = MX3_PWMCR_PRESCALER_SET(prescale) | 275 - MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEN | MX3_PWMCR_WAITEN | 276 - FIELD_PREP(MX3_PWMCR_CLKSRC, MX3_PWMCR_CLKSRC_IPG_HIGH) | 277 - MX3_PWMCR_DBGEN | MX3_PWMCR_EN; 278 - 279 - if (state->polarity == PWM_POLARITY_INVERSED) 280 - cr |= FIELD_PREP(MX3_PWMCR_POUTC, 281 - MX3_PWMCR_POUTC_INVERTED); 282 - 283 - writel(cr, imx->mmio_base + MX3_PWMCR); 284 - } else if (cstate.enabled) { 285 - writel(0, imx->mmio_base + MX3_PWMCR); 286 - 287 - pwm_imx27_clk_disable_unprepare(chip); 256 + pwm_imx27_sw_reset(chip); 288 257 } 258 + 259 + writel(duty_cycles, imx->mmio_base + MX3_PWMSAR); 260 + writel(period_cycles, imx->mmio_base + MX3_PWMPR); 261 + 262 + /* 263 + * Store the duty cycle for future reference in cases where the 264 + * MX3_PWMSAR register can't be read (i.e. when the PWM is disabled). 265 + */ 266 + imx->duty_cycle = duty_cycles; 267 + 268 + cr = MX3_PWMCR_PRESCALER_SET(prescale) | 269 + MX3_PWMCR_STOPEN | MX3_PWMCR_DOZEN | MX3_PWMCR_WAITEN | 270 + FIELD_PREP(MX3_PWMCR_CLKSRC, MX3_PWMCR_CLKSRC_IPG_HIGH) | 271 + MX3_PWMCR_DBGEN; 272 + 273 + if (state->polarity == PWM_POLARITY_INVERSED) 274 + cr |= FIELD_PREP(MX3_PWMCR_POUTC, 275 + MX3_PWMCR_POUTC_INVERTED); 276 + 277 + if (state->enabled) 278 + cr |= MX3_PWMCR_EN; 279 + 280 + writel(cr, imx->mmio_base + MX3_PWMCR); 281 + 282 + if (!state->enabled && cstate.enabled) 283 + pwm_imx27_clk_disable_unprepare(chip); 289 284 290 285 return 0; 291 286 } ··· 319 304 320 305 imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 321 306 if (IS_ERR(imx->clk_ipg)) { 322 - dev_err(&pdev->dev, "getting ipg clock failed with %ld\n", 323 - PTR_ERR(imx->clk_ipg)); 324 - return PTR_ERR(imx->clk_ipg); 307 + int ret = PTR_ERR(imx->clk_ipg); 308 + 309 + if (ret != -EPROBE_DEFER) 310 + dev_err(&pdev->dev, 311 + "getting ipg clock failed with %d\n", 312 + ret); 313 + return ret; 325 314 } 326 315 327 316 imx->clk_per = devm_clk_get(&pdev->dev, "per");
+49 -50
drivers/pwm/pwm-mxs.c
··· 25 25 #define PERIOD_PERIOD(p) ((p) & 0xffff) 26 26 #define PERIOD_PERIOD_MAX 0x10000 27 27 #define PERIOD_ACTIVE_HIGH (3 << 16) 28 + #define PERIOD_ACTIVE_LOW (2 << 16) 29 + #define PERIOD_INACTIVE_HIGH (3 << 18) 28 30 #define PERIOD_INACTIVE_LOW (2 << 18) 31 + #define PERIOD_POLARITY_NORMAL (PERIOD_ACTIVE_HIGH | PERIOD_INACTIVE_LOW) 32 + #define PERIOD_POLARITY_INVERSE (PERIOD_ACTIVE_LOW | PERIOD_INACTIVE_HIGH) 29 33 #define PERIOD_CDIV(div) (((div) & 0x7) << 20) 30 34 #define PERIOD_CDIV_MAX 8 31 35 32 - static const unsigned int cdiv[PERIOD_CDIV_MAX] = { 33 - 1, 2, 4, 8, 16, 64, 256, 1024 36 + static const u8 cdiv_shift[PERIOD_CDIV_MAX] = { 37 + 0, 1, 2, 3, 4, 6, 8, 10 34 38 }; 35 39 36 40 struct mxs_pwm_chip { ··· 45 41 46 42 #define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip) 47 43 48 - static int mxs_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 49 - int duty_ns, int period_ns) 44 + static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 45 + const struct pwm_state *state) 50 46 { 51 47 struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip); 52 48 int ret, div = 0; 53 49 unsigned int period_cycles, duty_cycles; 54 50 unsigned long rate; 55 51 unsigned long long c; 52 + unsigned int pol_bits; 53 + 54 + /* 55 + * If the PWM channel is disabled, make sure to turn on the 56 + * clock before calling clk_get_rate() and writing to the 57 + * registers. Otherwise, just keep it enabled. 58 + */ 59 + if (!pwm_is_enabled(pwm)) { 60 + ret = clk_prepare_enable(mxs->clk); 61 + if (ret) 62 + return ret; 63 + } 64 + 65 + if (!state->enabled && pwm_is_enabled(pwm)) 66 + writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); 56 67 57 68 rate = clk_get_rate(mxs->clk); 58 69 while (1) { 59 - c = rate / cdiv[div]; 60 - c = c * period_ns; 70 + c = rate >> cdiv_shift[div]; 71 + c = c * state->period; 61 72 do_div(c, 1000000000); 62 73 if (c < PERIOD_PERIOD_MAX) 63 74 break; ··· 82 63 } 83 64 84 65 period_cycles = c; 85 - c *= duty_ns; 86 - do_div(c, period_ns); 66 + c *= state->duty_cycle; 67 + do_div(c, state->period); 87 68 duty_cycles = c; 88 69 89 70 /* 90 - * If the PWM channel is disabled, make sure to turn on the clock 91 - * before writing the register. Otherwise, keep it enabled. 71 + * The data sheet the says registers must be written to in 72 + * this order (ACTIVEn, then PERIODn). Also, the new settings 73 + * only take effect at the beginning of a new period, avoiding 74 + * glitches. 92 75 */ 93 - if (!pwm_is_enabled(pwm)) { 94 - ret = clk_prepare_enable(mxs->clk); 95 - if (ret) 96 - return ret; 97 - } 98 76 77 + pol_bits = state->polarity == PWM_POLARITY_NORMAL ? 78 + PERIOD_POLARITY_NORMAL : PERIOD_POLARITY_INVERSE; 99 79 writel(duty_cycles << 16, 100 - mxs->base + PWM_ACTIVE0 + pwm->hwpwm * 0x20); 101 - writel(PERIOD_PERIOD(period_cycles) | PERIOD_ACTIVE_HIGH | 102 - PERIOD_INACTIVE_LOW | PERIOD_CDIV(div), 103 - mxs->base + PWM_PERIOD0 + pwm->hwpwm * 0x20); 80 + mxs->base + PWM_ACTIVE0 + pwm->hwpwm * 0x20); 81 + writel(PERIOD_PERIOD(period_cycles) | pol_bits | PERIOD_CDIV(div), 82 + mxs->base + PWM_PERIOD0 + pwm->hwpwm * 0x20); 104 83 105 - /* 106 - * If the PWM is not enabled, turn the clock off again to save power. 107 - */ 108 - if (!pwm_is_enabled(pwm)) 84 + if (state->enabled) { 85 + if (!pwm_is_enabled(pwm)) { 86 + /* 87 + * The clock was enabled above. Just enable 88 + * the channel in the control register. 89 + */ 90 + writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + SET); 91 + } 92 + } else { 109 93 clk_disable_unprepare(mxs->clk); 110 - 94 + } 111 95 return 0; 112 - } 113 - 114 - static int mxs_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 115 - { 116 - struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip); 117 - int ret; 118 - 119 - ret = clk_prepare_enable(mxs->clk); 120 - if (ret) 121 - return ret; 122 - 123 - writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + SET); 124 - 125 - return 0; 126 - } 127 - 128 - static void mxs_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 129 - { 130 - struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip); 131 - 132 - writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); 133 - 134 - clk_disable_unprepare(mxs->clk); 135 96 } 136 97 137 98 static const struct pwm_ops mxs_pwm_ops = { 138 - .config = mxs_pwm_config, 139 - .enable = mxs_pwm_enable, 140 - .disable = mxs_pwm_disable, 99 + .apply = mxs_pwm_apply, 141 100 .owner = THIS_MODULE, 142 101 }; 143 102 ··· 139 142 140 143 mxs->chip.dev = &pdev->dev; 141 144 mxs->chip.ops = &mxs_pwm_ops; 145 + mxs->chip.of_xlate = of_pwm_xlate_with_flags; 146 + mxs->chip.of_pwm_n_cells = 3; 142 147 mxs->chip.base = -1; 143 148 144 149 ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm);
+39 -15
drivers/pwm/pwm-omap-dmtimer.c
··· 256 256 if (!timer_pdev) { 257 257 dev_err(&pdev->dev, "Unable to find Timer pdev\n"); 258 258 ret = -ENODEV; 259 - goto put; 259 + goto err_find_timer_pdev; 260 260 } 261 261 262 262 timer_pdata = dev_get_platdata(&timer_pdev->dev); ··· 264 264 dev_dbg(&pdev->dev, 265 265 "dmtimer pdata structure NULL, deferring probe\n"); 266 266 ret = -EPROBE_DEFER; 267 - goto put; 267 + goto err_platdata; 268 268 } 269 269 270 270 pdata = timer_pdata->timer_ops; ··· 283 283 !pdata->write_counter) { 284 284 dev_err(&pdev->dev, "Incomplete dmtimer pdata structure\n"); 285 285 ret = -EINVAL; 286 - goto put; 286 + goto err_platdata; 287 287 } 288 288 289 289 if (!of_get_property(timer, "ti,timer-pwm", NULL)) { 290 290 dev_err(&pdev->dev, "Missing ti,timer-pwm capability\n"); 291 291 ret = -ENODEV; 292 - goto put; 292 + goto err_timer_property; 293 293 } 294 294 295 295 dm_timer = pdata->request_by_node(timer); 296 296 if (!dm_timer) { 297 297 ret = -EPROBE_DEFER; 298 - goto put; 298 + goto err_request_timer; 299 299 } 300 - 301 - put: 302 - of_node_put(timer); 303 - if (ret < 0) 304 - return ret; 305 300 306 301 omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL); 307 302 if (!omap) { 308 - pdata->free(dm_timer); 309 - return -ENOMEM; 303 + ret = -ENOMEM; 304 + goto err_alloc_omap; 310 305 } 311 306 312 307 omap->pdata = pdata; ··· 334 339 ret = pwmchip_add(&omap->chip); 335 340 if (ret < 0) { 336 341 dev_err(&pdev->dev, "failed to register PWM\n"); 337 - omap->pdata->free(omap->dm_timer); 338 - return ret; 342 + goto err_pwmchip_add; 339 343 } 344 + 345 + of_node_put(timer); 340 346 341 347 platform_set_drvdata(pdev, omap); 342 348 343 349 return 0; 350 + 351 + err_pwmchip_add: 352 + 353 + /* 354 + * *omap is allocated using devm_kzalloc, 355 + * so no free necessary here 356 + */ 357 + err_alloc_omap: 358 + 359 + pdata->free(dm_timer); 360 + err_request_timer: 361 + 362 + err_timer_property: 363 + err_platdata: 364 + 365 + put_device(&timer_pdev->dev); 366 + err_find_timer_pdev: 367 + 368 + of_node_put(timer); 369 + 370 + return ret; 344 371 } 345 372 346 373 static int pwm_omap_dmtimer_remove(struct platform_device *pdev) 347 374 { 348 375 struct pwm_omap_dmtimer_chip *omap = platform_get_drvdata(pdev); 376 + int ret; 377 + 378 + ret = pwmchip_remove(&omap->chip); 379 + if (ret) 380 + return ret; 349 381 350 382 if (pm_runtime_active(&omap->dm_timer_pdev->dev)) 351 383 omap->pdata->stop(omap->dm_timer); 352 384 353 385 omap->pdata->free(omap->dm_timer); 354 386 387 + put_device(&omap->dm_timer_pdev->dev); 388 + 355 389 mutex_destroy(&omap->mutex); 356 390 357 - return pwmchip_remove(&omap->chip); 391 + return 0; 358 392 } 359 393 360 394 static const struct of_device_id pwm_omap_dmtimer_of_match[] = {
-4
drivers/pwm/pwm-pca9685.c
··· 159 159 static void pca9685_pwm_gpio_free(struct gpio_chip *gpio, unsigned int offset) 160 160 { 161 161 struct pca9685 *pca = gpiochip_get_data(gpio); 162 - struct pwm_device *pwm; 163 162 164 163 pca9685_pwm_gpio_set(gpio, offset, 0); 165 164 pm_runtime_put(pca->chip.dev); 166 - mutex_lock(&pca->lock); 167 - pwm = &pca->chip.pwms[offset]; 168 - mutex_unlock(&pca->lock); 169 165 } 170 166 171 167 static int pca9685_pwm_gpio_get_direction(struct gpio_chip *chip,
+3 -2
drivers/pwm/pwm-rcar.c
··· 3 3 * R-Car PWM Timer driver 4 4 * 5 5 * Copyright (C) 2015 Renesas Electronics Corporation 6 + * 7 + * Limitations: 8 + * - The hardware cannot generate a 0% duty cycle. 6 9 */ 7 10 8 11 #include <linux/clk.h> ··· 164 161 const struct pwm_state *state) 165 162 { 166 163 struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); 167 - struct pwm_state cur_state; 168 164 int div, ret; 169 165 170 166 /* This HW/driver only supports normal polarity */ 171 - pwm_get_state(pwm, &cur_state); 172 167 if (state->polarity != PWM_POLARITY_NORMAL) 173 168 return -ENOTSUPP; 174 169
+1 -3
drivers/pwm/pwm-stm32.c
··· 377 377 else 378 378 regmap_update_bits(priv->regmap, TIM_CCMR2, mask, ccmr); 379 379 380 - regmap_update_bits(priv->regmap, TIM_BDTR, 381 - TIM_BDTR_MOE | TIM_BDTR_AOE, 382 - TIM_BDTR_MOE | TIM_BDTR_AOE); 380 + regmap_update_bits(priv->regmap, TIM_BDTR, TIM_BDTR_MOE, TIM_BDTR_MOE); 383 381 384 382 return 0; 385 383 }
+162 -36
drivers/pwm/pwm-sun4i.c
··· 3 3 * Driver for Allwinner sun4i Pulse Width Modulation Controller 4 4 * 5 5 * Copyright (C) 2014 Alexandre Belloni <alexandre.belloni@free-electrons.com> 6 + * 7 + * Limitations: 8 + * - When outputing the source clock directly, the PWM logic will be bypassed 9 + * and the currently running period is not guaranteed to be completed 6 10 */ 7 11 8 12 #include <linux/bitops.h> ··· 20 16 #include <linux/of_device.h> 21 17 #include <linux/platform_device.h> 22 18 #include <linux/pwm.h> 19 + #include <linux/reset.h> 23 20 #include <linux/slab.h> 24 21 #include <linux/spinlock.h> 25 22 #include <linux/time.h> ··· 77 72 78 73 struct sun4i_pwm_data { 79 74 bool has_prescaler_bypass; 75 + bool has_direct_mod_clk_output; 80 76 unsigned int npwm; 81 77 }; 82 78 83 79 struct sun4i_pwm_chip { 84 80 struct pwm_chip chip; 81 + struct clk *bus_clk; 85 82 struct clk *clk; 83 + struct reset_control *rst; 86 84 void __iomem *base; 87 85 spinlock_t ctrl_lock; 88 86 const struct sun4i_pwm_data *data; ··· 123 115 124 116 val = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 125 117 118 + /* 119 + * PWM chapter in H6 manual has a diagram which explains that if bypass 120 + * bit is set, no other setting has any meaning. Even more, experiment 121 + * proved that also enable bit is ignored in this case. 122 + */ 123 + if ((val & BIT_CH(PWM_BYPASS, pwm->hwpwm)) && 124 + sun4i_pwm->data->has_direct_mod_clk_output) { 125 + state->period = DIV_ROUND_UP_ULL(NSEC_PER_SEC, clk_rate); 126 + state->duty_cycle = DIV_ROUND_UP_ULL(state->period, 2); 127 + state->polarity = PWM_POLARITY_NORMAL; 128 + state->enabled = true; 129 + return; 130 + } 131 + 126 132 if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) && 127 133 sun4i_pwm->data->has_prescaler_bypass) 128 134 prescaler = 1; ··· 168 146 169 147 static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4i_pwm, 170 148 const struct pwm_state *state, 171 - u32 *dty, u32 *prd, unsigned int *prsclr) 149 + u32 *dty, u32 *prd, unsigned int *prsclr, 150 + bool *bypass) 172 151 { 173 152 u64 clk_rate, div = 0; 174 - unsigned int pval, prescaler = 0; 153 + unsigned int prescaler = 0; 175 154 176 155 clk_rate = clk_get_rate(sun4i_pwm->clk); 156 + 157 + *bypass = sun4i_pwm->data->has_direct_mod_clk_output && 158 + state->enabled && 159 + (state->period * clk_rate >= NSEC_PER_SEC) && 160 + (state->period * clk_rate < 2 * NSEC_PER_SEC) && 161 + (state->duty_cycle * clk_rate * 2 >= NSEC_PER_SEC); 162 + 163 + /* Skip calculation of other parameters if we bypass them */ 164 + if (*bypass) 165 + return 0; 177 166 178 167 if (sun4i_pwm->data->has_prescaler_bypass) { 179 168 /* First, test without any prescaler when available */ ··· 203 170 if (prescaler == 0) { 204 171 /* Go up from the first divider */ 205 172 for (prescaler = 0; prescaler < PWM_PRESCAL_MASK; prescaler++) { 206 - if (!prescaler_table[prescaler]) 173 + unsigned int pval = prescaler_table[prescaler]; 174 + 175 + if (!pval) 207 176 continue; 208 - pval = prescaler_table[prescaler]; 177 + 209 178 div = clk_rate; 210 179 do_div(div, pval); 211 180 div = div * state->period; ··· 234 199 { 235 200 struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip); 236 201 struct pwm_state cstate; 237 - u32 ctrl; 202 + u32 ctrl, duty = 0, period = 0, val; 238 203 int ret; 239 - unsigned int delay_us; 204 + unsigned int delay_us, prescaler = 0; 240 205 unsigned long now; 206 + bool bypass; 241 207 242 208 pwm_get_state(pwm, &cstate); 243 209 ··· 250 214 } 251 215 } 252 216 217 + ret = sun4i_pwm_calculate(sun4i_pwm, state, &duty, &period, &prescaler, 218 + &bypass); 219 + if (ret) { 220 + dev_err(chip->dev, "period exceeds the maximum value\n"); 221 + if (!cstate.enabled) 222 + clk_disable_unprepare(sun4i_pwm->clk); 223 + return ret; 224 + } 225 + 253 226 spin_lock(&sun4i_pwm->ctrl_lock); 254 227 ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG); 255 228 256 - if ((cstate.period != state->period) || 257 - (cstate.duty_cycle != state->duty_cycle)) { 258 - u32 period, duty, val; 259 - unsigned int prescaler; 260 - 261 - ret = sun4i_pwm_calculate(sun4i_pwm, state, 262 - &duty, &period, &prescaler); 263 - if (ret) { 264 - dev_err(chip->dev, "period exceeds the maximum value\n"); 265 - spin_unlock(&sun4i_pwm->ctrl_lock); 266 - if (!cstate.enabled) 267 - clk_disable_unprepare(sun4i_pwm->clk); 268 - return ret; 269 - } 270 - 271 - if (PWM_REG_PRESCAL(ctrl, pwm->hwpwm) != prescaler) { 272 - /* Prescaler changed, the clock has to be gated */ 273 - ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 229 + if (sun4i_pwm->data->has_direct_mod_clk_output) { 230 + if (bypass) { 231 + ctrl |= BIT_CH(PWM_BYPASS, pwm->hwpwm); 232 + /* We can skip other parameter */ 274 233 sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); 275 - 276 - ctrl &= ~BIT_CH(PWM_PRESCAL_MASK, pwm->hwpwm); 277 - ctrl |= BIT_CH(prescaler, pwm->hwpwm); 234 + spin_unlock(&sun4i_pwm->ctrl_lock); 235 + return 0; 278 236 } 279 237 280 - val = (duty & PWM_DTY_MASK) | PWM_PRD(period); 281 - sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); 282 - sun4i_pwm->next_period[pwm->hwpwm] = jiffies + 283 - usecs_to_jiffies(cstate.period / 1000 + 1); 284 - sun4i_pwm->needs_delay[pwm->hwpwm] = true; 238 + ctrl &= ~BIT_CH(PWM_BYPASS, pwm->hwpwm); 285 239 } 240 + 241 + if (PWM_REG_PRESCAL(ctrl, pwm->hwpwm) != prescaler) { 242 + /* Prescaler changed, the clock has to be gated */ 243 + ctrl &= ~BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 244 + sun4i_pwm_writel(sun4i_pwm, ctrl, PWM_CTRL_REG); 245 + 246 + ctrl &= ~BIT_CH(PWM_PRESCAL_MASK, pwm->hwpwm); 247 + ctrl |= BIT_CH(prescaler, pwm->hwpwm); 248 + } 249 + 250 + val = (duty & PWM_DTY_MASK) | PWM_PRD(period); 251 + sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); 252 + sun4i_pwm->next_period[pwm->hwpwm] = jiffies + 253 + usecs_to_jiffies(cstate.period / 1000 + 1); 254 + sun4i_pwm->needs_delay[pwm->hwpwm] = true; 286 255 287 256 if (state->polarity != PWM_POLARITY_NORMAL) 288 257 ctrl &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); ··· 295 254 ctrl |= BIT_CH(PWM_ACT_STATE, pwm->hwpwm); 296 255 297 256 ctrl |= BIT_CH(PWM_CLK_GATING, pwm->hwpwm); 257 + 298 258 if (state->enabled) { 299 259 ctrl |= BIT_CH(PWM_EN, pwm->hwpwm); 300 260 } else if (!sun4i_pwm->needs_delay[pwm->hwpwm]) { ··· 361 319 .npwm = 1, 362 320 }; 363 321 322 + static const struct sun4i_pwm_data sun50i_h6_pwm_data = { 323 + .has_prescaler_bypass = true, 324 + .has_direct_mod_clk_output = true, 325 + .npwm = 2, 326 + }; 327 + 364 328 static const struct of_device_id sun4i_pwm_dt_ids[] = { 365 329 { 366 330 .compatible = "allwinner,sun4i-a10-pwm", ··· 383 335 }, { 384 336 .compatible = "allwinner,sun8i-h3-pwm", 385 337 .data = &sun4i_pwm_single_bypass, 338 + }, { 339 + .compatible = "allwinner,sun50i-h6-pwm", 340 + .data = &sun50i_h6_pwm_data, 386 341 }, { 387 342 /* sentinel */ 388 343 }, ··· 411 360 if (IS_ERR(pwm->base)) 412 361 return PTR_ERR(pwm->base); 413 362 414 - pwm->clk = devm_clk_get(&pdev->dev, NULL); 415 - if (IS_ERR(pwm->clk)) 363 + /* 364 + * All hardware variants need a source clock that is divided and 365 + * then feeds the counter that defines the output wave form. In the 366 + * device tree this clock is either unnamed or called "mod". 367 + * Some variants (e.g. H6) need another clock to access the 368 + * hardware registers; this is called "bus". 369 + * So we request "mod" first (and ignore the corner case that a 370 + * parent provides a "mod" clock while the right one would be the 371 + * unnamed one of the PWM device) and if this is not found we fall 372 + * back to the first clock of the PWM. 373 + */ 374 + pwm->clk = devm_clk_get_optional(&pdev->dev, "mod"); 375 + if (IS_ERR(pwm->clk)) { 376 + if (PTR_ERR(pwm->clk) != -EPROBE_DEFER) 377 + dev_err(&pdev->dev, "get mod clock failed %pe\n", 378 + pwm->clk); 416 379 return PTR_ERR(pwm->clk); 380 + } 381 + 382 + if (!pwm->clk) { 383 + pwm->clk = devm_clk_get(&pdev->dev, NULL); 384 + if (IS_ERR(pwm->clk)) { 385 + if (PTR_ERR(pwm->clk) != -EPROBE_DEFER) 386 + dev_err(&pdev->dev, "get unnamed clock failed %pe\n", 387 + pwm->clk); 388 + return PTR_ERR(pwm->clk); 389 + } 390 + } 391 + 392 + pwm->bus_clk = devm_clk_get_optional(&pdev->dev, "bus"); 393 + if (IS_ERR(pwm->bus_clk)) { 394 + if (PTR_ERR(pwm->bus_clk) != -EPROBE_DEFER) 395 + dev_err(&pdev->dev, "get bus clock failed %pe\n", 396 + pwm->bus_clk); 397 + return PTR_ERR(pwm->bus_clk); 398 + } 399 + 400 + pwm->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL); 401 + if (IS_ERR(pwm->rst)) { 402 + if (PTR_ERR(pwm->rst) != -EPROBE_DEFER) 403 + dev_err(&pdev->dev, "get reset failed %pe\n", 404 + pwm->rst); 405 + return PTR_ERR(pwm->rst); 406 + } 407 + 408 + /* Deassert reset */ 409 + ret = reset_control_deassert(pwm->rst); 410 + if (ret) { 411 + dev_err(&pdev->dev, "cannot deassert reset control: %pe\n", 412 + ERR_PTR(ret)); 413 + return ret; 414 + } 415 + 416 + /* 417 + * We're keeping the bus clock on for the sake of simplicity. 418 + * Actually it only needs to be on for hardware register accesses. 419 + */ 420 + ret = clk_prepare_enable(pwm->bus_clk); 421 + if (ret) { 422 + dev_err(&pdev->dev, "cannot prepare and enable bus_clk %pe\n", 423 + ERR_PTR(ret)); 424 + goto err_bus; 425 + } 417 426 418 427 pwm->chip.dev = &pdev->dev; 419 428 pwm->chip.ops = &sun4i_pwm_ops; ··· 487 376 ret = pwmchip_add(&pwm->chip); 488 377 if (ret < 0) { 489 378 dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 490 - return ret; 379 + goto err_pwm_add; 491 380 } 492 381 493 382 platform_set_drvdata(pdev, pwm); 494 383 495 384 return 0; 385 + 386 + err_pwm_add: 387 + clk_disable_unprepare(pwm->bus_clk); 388 + err_bus: 389 + reset_control_assert(pwm->rst); 390 + 391 + return ret; 496 392 } 497 393 498 394 static int sun4i_pwm_remove(struct platform_device *pdev) 499 395 { 500 396 struct sun4i_pwm_chip *pwm = platform_get_drvdata(pdev); 397 + int ret; 501 398 502 - return pwmchip_remove(&pwm->chip); 399 + ret = pwmchip_remove(&pwm->chip); 400 + if (ret) 401 + return ret; 402 + 403 + clk_disable_unprepare(pwm->bus_clk); 404 + reset_control_assert(pwm->rst); 405 + 406 + return 0; 503 407 } 504 408 505 409 static struct platform_driver sun4i_pwm_driver = {
+58
include/trace/events/pwm.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + #undef TRACE_SYSTEM 3 + #define TRACE_SYSTEM pwm 4 + 5 + #if !defined(_TRACE_PWM_H) || defined(TRACE_HEADER_MULTI_READ) 6 + #define _TRACE_PWM_H 7 + 8 + #include <linux/pwm.h> 9 + #include <linux/tracepoint.h> 10 + 11 + DECLARE_EVENT_CLASS(pwm, 12 + 13 + TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), 14 + 15 + TP_ARGS(pwm, state), 16 + 17 + TP_STRUCT__entry( 18 + __field(struct pwm_device *, pwm) 19 + __field(u64, period) 20 + __field(u64, duty_cycle) 21 + __field(enum pwm_polarity, polarity) 22 + __field(bool, enabled) 23 + ), 24 + 25 + TP_fast_assign( 26 + __entry->pwm = pwm; 27 + __entry->period = state->period; 28 + __entry->duty_cycle = state->duty_cycle; 29 + __entry->polarity = state->polarity; 30 + __entry->enabled = state->enabled; 31 + ), 32 + 33 + TP_printk("%p: period=%llu duty_cycle=%llu polarity=%d enabled=%d", 34 + __entry->pwm, __entry->period, __entry->duty_cycle, 35 + __entry->polarity, __entry->enabled) 36 + 37 + ); 38 + 39 + DEFINE_EVENT(pwm, pwm_apply, 40 + 41 + TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), 42 + 43 + TP_ARGS(pwm, state) 44 + 45 + ); 46 + 47 + DEFINE_EVENT(pwm, pwm_get, 48 + 49 + TP_PROTO(struct pwm_device *pwm, const struct pwm_state *state), 50 + 51 + TP_ARGS(pwm, state) 52 + 53 + ); 54 + 55 + #endif /* _TRACE_PWM_H */ 56 + 57 + /* This part must be outside protection */ 58 + #include <trace/define_trace.h>