Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 2 | /* |
| 3 | * ECAP PWM driver |
| 4 | * |
Alexander A. Klimov | 216a094 | 2020-07-08 19:59:24 +0200 | [diff] [blame] | 5 | * Copyright (C) 2012 Texas Instruments, Inc. - https://www.ti.com/ |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/clk.h> |
| 13 | #include <linux/pm_runtime.h> |
| 14 | #include <linux/pwm.h> |
Philip, Avinash | 333b08e | 2012-11-27 14:18:09 +0530 | [diff] [blame] | 15 | #include <linux/of_device.h> |
| 16 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 17 | /* ECAP registers and bits definitions */ |
| 18 | #define CAP1 0x08 |
| 19 | #define CAP2 0x0C |
| 20 | #define CAP3 0x10 |
| 21 | #define CAP4 0x14 |
| 22 | #define ECCTL2 0x2A |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 23 | #define ECCTL2_APWM_POL_LOW BIT(10) |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 24 | #define ECCTL2_APWM_MODE BIT(9) |
| 25 | #define ECCTL2_SYNC_SEL_DISA (BIT(7) | BIT(6)) |
| 26 | #define ECCTL2_TSCTR_FREERUN BIT(4) |
| 27 | |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 28 | struct ecap_context { |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 29 | u32 cap3; |
| 30 | u32 cap4; |
| 31 | u16 ecctl2; |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 32 | }; |
| 33 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 34 | struct ecap_pwm_chip { |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 35 | struct pwm_chip chip; |
| 36 | unsigned int clk_rate; |
| 37 | void __iomem *mmio_base; |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 38 | struct ecap_context ctx; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | static inline struct ecap_pwm_chip *to_ecap_pwm_chip(struct pwm_chip *chip) |
| 42 | { |
| 43 | return container_of(chip, struct ecap_pwm_chip, chip); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * period_ns = 10^9 * period_cycles / PWM_CLK_RATE |
| 48 | * duty_ns = 10^9 * duty_cycles / PWM_CLK_RATE |
| 49 | */ |
| 50 | static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 51 | int duty_ns, int period_ns, int enabled) |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 52 | { |
| 53 | struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 54 | u32 period_cycles, duty_cycles; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 55 | unsigned long long c; |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 56 | u16 value; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 57 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 58 | c = pc->clk_rate; |
| 59 | c = c * period_ns; |
| 60 | do_div(c, NSEC_PER_SEC); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 61 | period_cycles = (u32)c; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 62 | |
| 63 | if (period_cycles < 1) { |
| 64 | period_cycles = 1; |
| 65 | duty_cycles = 1; |
| 66 | } else { |
| 67 | c = pc->clk_rate; |
| 68 | c = c * duty_ns; |
| 69 | do_div(c, NSEC_PER_SEC); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 70 | duty_cycles = (u32)c; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | pm_runtime_get_sync(pc->chip.dev); |
| 74 | |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 75 | value = readw(pc->mmio_base + ECCTL2); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 76 | |
| 77 | /* Configure APWM mode & disable sync option */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 78 | value |= ECCTL2_APWM_MODE | ECCTL2_SYNC_SEL_DISA; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 79 | |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 80 | writew(value, pc->mmio_base + ECCTL2); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 81 | |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 82 | if (!enabled) { |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 83 | /* Update active registers if not running */ |
| 84 | writel(duty_cycles, pc->mmio_base + CAP2); |
| 85 | writel(period_cycles, pc->mmio_base + CAP1); |
| 86 | } else { |
| 87 | /* |
| 88 | * Update shadow registers to configure period and |
| 89 | * compare values. This helps current PWM period to |
| 90 | * complete on reconfiguring |
| 91 | */ |
| 92 | writel(duty_cycles, pc->mmio_base + CAP4); |
| 93 | writel(period_cycles, pc->mmio_base + CAP3); |
| 94 | } |
| 95 | |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 96 | if (!enabled) { |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 97 | value = readw(pc->mmio_base + ECCTL2); |
Philip, Avinash | c06fad9 | 2012-08-23 12:29:46 +0530 | [diff] [blame] | 98 | /* Disable APWM mode to put APWM output Low */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 99 | value &= ~ECCTL2_APWM_MODE; |
| 100 | writew(value, pc->mmio_base + ECCTL2); |
Philip, Avinash | c06fad9 | 2012-08-23 12:29:46 +0530 | [diff] [blame] | 101 | } |
| 102 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 103 | pm_runtime_put_sync(pc->chip.dev); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 104 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 108 | static int ecap_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 109 | enum pwm_polarity polarity) |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 110 | { |
| 111 | struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 112 | u16 value; |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 113 | |
| 114 | pm_runtime_get_sync(pc->chip.dev); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 115 | |
| 116 | value = readw(pc->mmio_base + ECCTL2); |
| 117 | |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 118 | if (polarity == PWM_POLARITY_INVERSED) |
| 119 | /* Duty cycle defines LOW period of PWM */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 120 | value |= ECCTL2_APWM_POL_LOW; |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 121 | else |
| 122 | /* Duty cycle defines HIGH period of PWM */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 123 | value &= ~ECCTL2_APWM_POL_LOW; |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 124 | |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 125 | writew(value, pc->mmio_base + ECCTL2); |
| 126 | |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 127 | pm_runtime_put_sync(pc->chip.dev); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 128 | |
Philip, Avinash | 454870a | 2012-09-06 10:40:02 +0530 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 132 | static int ecap_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) |
| 133 | { |
| 134 | struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 135 | u16 value; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 136 | |
| 137 | /* Leave clock enabled on enabling PWM */ |
| 138 | pm_runtime_get_sync(pc->chip.dev); |
| 139 | |
| 140 | /* |
| 141 | * Enable 'Free run Time stamp counter mode' to start counter |
| 142 | * and 'APWM mode' to enable APWM output |
| 143 | */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 144 | value = readw(pc->mmio_base + ECCTL2); |
| 145 | value |= ECCTL2_TSCTR_FREERUN | ECCTL2_APWM_MODE; |
| 146 | writew(value, pc->mmio_base + ECCTL2); |
| 147 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static void ecap_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) |
| 152 | { |
| 153 | struct ecap_pwm_chip *pc = to_ecap_pwm_chip(chip); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 154 | u16 value; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * Disable 'Free run Time stamp counter mode' to stop counter |
| 158 | * and 'APWM mode' to put APWM output to low |
| 159 | */ |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 160 | value = readw(pc->mmio_base + ECCTL2); |
| 161 | value &= ~(ECCTL2_TSCTR_FREERUN | ECCTL2_APWM_MODE); |
| 162 | writew(value, pc->mmio_base + ECCTL2); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 163 | |
| 164 | /* Disable clock on PWM disable */ |
| 165 | pm_runtime_put_sync(pc->chip.dev); |
| 166 | } |
| 167 | |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 168 | static int ecap_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, |
| 169 | const struct pwm_state *state) |
| 170 | { |
| 171 | int err; |
| 172 | int enabled = pwm->state.enabled; |
| 173 | |
| 174 | if (state->polarity != pwm->state.polarity) { |
| 175 | |
| 176 | if (enabled) { |
| 177 | ecap_pwm_disable(chip, pwm); |
| 178 | enabled = false; |
| 179 | } |
| 180 | |
| 181 | err = ecap_pwm_set_polarity(chip, pwm, state->polarity); |
| 182 | if (err) |
| 183 | return err; |
| 184 | } |
| 185 | |
| 186 | if (!state->enabled) { |
| 187 | if (enabled) |
| 188 | ecap_pwm_disable(chip, pwm); |
| 189 | return 0; |
| 190 | } |
| 191 | |
Uwe Kleine-König | 25f70b8 | 2021-07-01 10:27:53 +0200 | [diff] [blame] | 192 | if (state->period > NSEC_PER_SEC) |
| 193 | return -ERANGE; |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 194 | |
Uwe Kleine-König | 25f70b8 | 2021-07-01 10:27:53 +0200 | [diff] [blame] | 195 | err = ecap_pwm_config(chip, pwm, state->duty_cycle, |
| 196 | state->period, enabled); |
| 197 | if (err) |
| 198 | return err; |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 199 | |
| 200 | if (!enabled) |
| 201 | return ecap_pwm_enable(chip, pwm); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 206 | static const struct pwm_ops ecap_pwm_ops = { |
Uwe Kleine-König | 0ca7acd | 2021-05-01 18:01:39 +0200 | [diff] [blame] | 207 | .apply = ecap_pwm_apply, |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 208 | .owner = THIS_MODULE, |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 209 | }; |
| 210 | |
Philip, Avinash | 333b08e | 2012-11-27 14:18:09 +0530 | [diff] [blame] | 211 | static const struct of_device_id ecap_of_match[] = { |
Cooper Jr., Franklin | ae5200d | 2016-05-03 10:56:52 -0500 | [diff] [blame] | 212 | { .compatible = "ti,am3352-ecap" }, |
Philip, Avinash | 333b08e | 2012-11-27 14:18:09 +0530 | [diff] [blame] | 213 | { .compatible = "ti,am33xx-ecap" }, |
| 214 | {}, |
| 215 | }; |
| 216 | MODULE_DEVICE_TABLE(of, ecap_of_match); |
| 217 | |
Bill Pemberton | 3e9fe83 | 2012-11-19 13:23:14 -0500 | [diff] [blame] | 218 | static int ecap_pwm_probe(struct platform_device *pdev) |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 219 | { |
Cooper Jr., Franklin | ae5200d | 2016-05-03 10:56:52 -0500 | [diff] [blame] | 220 | struct device_node *np = pdev->dev.of_node; |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 221 | struct ecap_pwm_chip *pc; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 222 | struct clk *clk; |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 223 | int ret; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 224 | |
| 225 | pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); |
Jingoo Han | c10d506 | 2014-04-23 18:41:27 +0900 | [diff] [blame] | 226 | if (!pc) |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 227 | return -ENOMEM; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 228 | |
| 229 | clk = devm_clk_get(&pdev->dev, "fck"); |
| 230 | if (IS_ERR(clk)) { |
Cooper Jr., Franklin | ae5200d | 2016-05-03 10:56:52 -0500 | [diff] [blame] | 231 | if (of_device_is_compatible(np, "ti,am33xx-ecap")) { |
| 232 | dev_warn(&pdev->dev, "Binding is obsolete.\n"); |
| 233 | clk = devm_clk_get(pdev->dev.parent, "fck"); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if (IS_ERR(clk)) { |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 238 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 239 | return PTR_ERR(clk); |
| 240 | } |
| 241 | |
| 242 | pc->clk_rate = clk_get_rate(clk); |
| 243 | if (!pc->clk_rate) { |
| 244 | dev_err(&pdev->dev, "failed to get clock rate\n"); |
| 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | pc->chip.dev = &pdev->dev; |
| 249 | pc->chip.ops = &ecap_pwm_ops; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 250 | pc->chip.npwm = 1; |
| 251 | |
Yangtao Li | 1dcf052 | 2019-12-29 08:05:59 +0000 | [diff] [blame] | 252 | pc->mmio_base = devm_platform_ioremap_resource(pdev, 0); |
Thierry Reding | 6d4294d | 2013-01-21 11:09:16 +0100 | [diff] [blame] | 253 | if (IS_ERR(pc->mmio_base)) |
| 254 | return PTR_ERR(pc->mmio_base); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 255 | |
Uwe Kleine-König | a64a585 | 2021-07-07 18:28:18 +0200 | [diff] [blame] | 256 | ret = devm_pwmchip_add(&pdev->dev, &pc->chip); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 257 | if (ret < 0) { |
| 258 | dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); |
| 259 | return ret; |
| 260 | } |
| 261 | |
Thierry Reding | 23f373e | 2017-08-21 08:31:37 +0200 | [diff] [blame] | 262 | platform_set_drvdata(pdev, pc); |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 263 | pm_runtime_enable(&pdev->dev); |
Philip, Avinash | 333b08e | 2012-11-27 14:18:09 +0530 | [diff] [blame] | 264 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
Bill Pemberton | 77f3791 | 2012-11-19 13:26:09 -0500 | [diff] [blame] | 268 | static int ecap_pwm_remove(struct platform_device *pdev) |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 269 | { |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 270 | pm_runtime_disable(&pdev->dev); |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 271 | |
Uwe Kleine-König | a64a585 | 2021-07-07 18:28:18 +0200 | [diff] [blame] | 272 | return 0; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 273 | } |
| 274 | |
Jingoo Han | 3943a65 | 2013-08-02 15:11:18 +0900 | [diff] [blame] | 275 | #ifdef CONFIG_PM_SLEEP |
Axel Lin | a38c989 | 2013-03-26 22:54:58 +0800 | [diff] [blame] | 276 | static void ecap_pwm_save_context(struct ecap_pwm_chip *pc) |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 277 | { |
| 278 | pm_runtime_get_sync(pc->chip.dev); |
| 279 | pc->ctx.ecctl2 = readw(pc->mmio_base + ECCTL2); |
| 280 | pc->ctx.cap4 = readl(pc->mmio_base + CAP4); |
| 281 | pc->ctx.cap3 = readl(pc->mmio_base + CAP3); |
| 282 | pm_runtime_put_sync(pc->chip.dev); |
| 283 | } |
| 284 | |
Axel Lin | a38c989 | 2013-03-26 22:54:58 +0800 | [diff] [blame] | 285 | static void ecap_pwm_restore_context(struct ecap_pwm_chip *pc) |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 286 | { |
| 287 | writel(pc->ctx.cap3, pc->mmio_base + CAP3); |
| 288 | writel(pc->ctx.cap4, pc->mmio_base + CAP4); |
| 289 | writew(pc->ctx.ecctl2, pc->mmio_base + ECCTL2); |
| 290 | } |
| 291 | |
| 292 | static int ecap_pwm_suspend(struct device *dev) |
| 293 | { |
| 294 | struct ecap_pwm_chip *pc = dev_get_drvdata(dev); |
| 295 | struct pwm_device *pwm = pc->chip.pwms; |
| 296 | |
| 297 | ecap_pwm_save_context(pc); |
| 298 | |
| 299 | /* Disable explicitly if PWM is running */ |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 300 | if (pwm_is_enabled(pwm)) |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 301 | pm_runtime_put_sync(dev); |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int ecap_pwm_resume(struct device *dev) |
| 307 | { |
| 308 | struct ecap_pwm_chip *pc = dev_get_drvdata(dev); |
| 309 | struct pwm_device *pwm = pc->chip.pwms; |
| 310 | |
| 311 | /* Enable explicitly if PWM was running */ |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 312 | if (pwm_is_enabled(pwm)) |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 313 | pm_runtime_get_sync(dev); |
| 314 | |
| 315 | ecap_pwm_restore_context(pc); |
| 316 | return 0; |
| 317 | } |
Jingoo Han | b78f5fc | 2013-03-11 11:12:58 +0900 | [diff] [blame] | 318 | #endif |
Philip Avinash | 0d75c20 | 2013-01-17 14:50:03 +0530 | [diff] [blame] | 319 | |
| 320 | static SIMPLE_DEV_PM_OPS(ecap_pwm_pm_ops, ecap_pwm_suspend, ecap_pwm_resume); |
| 321 | |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 322 | static struct platform_driver ecap_pwm_driver = { |
| 323 | .driver = { |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 324 | .name = "ecap", |
Philip, Avinash | 333b08e | 2012-11-27 14:18:09 +0530 | [diff] [blame] | 325 | .of_match_table = ecap_of_match, |
Thierry Reding | 53c7972 | 2017-08-21 08:29:41 +0200 | [diff] [blame] | 326 | .pm = &ecap_pwm_pm_ops, |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 327 | }, |
| 328 | .probe = ecap_pwm_probe, |
Bill Pemberton | fd10911 | 2012-11-19 13:21:28 -0500 | [diff] [blame] | 329 | .remove = ecap_pwm_remove, |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 330 | }; |
Philip, Avinash | 8e0cb05b | 2012-07-25 16:58:18 +0530 | [diff] [blame] | 331 | module_platform_driver(ecap_pwm_driver); |
| 332 | |
| 333 | MODULE_DESCRIPTION("ECAP PWM driver"); |
| 334 | MODULE_AUTHOR("Texas Instruments"); |
| 335 | MODULE_LICENSE("GPL"); |