blob: ee7a8b3dbed9083debf3b93f15e08c8bcaac08c1 [file] [log] [blame]
Philip, Avinash19891b22012-07-25 16:58:19 +05301/*
2 * EHRPWM PWM driver
3 *
4 * Copyright (C) 2012 Texas Instruments, Inc. - http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/pwm.h>
24#include <linux/io.h>
25#include <linux/err.h>
26#include <linux/clk.h>
27#include <linux/pm_runtime.h>
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +053028#include <linux/of_device.h>
29
30#include "pwm-tipwmss.h"
Philip, Avinash19891b22012-07-25 16:58:19 +053031
32/* EHRPWM registers and bits definitions */
33
34/* Time base module registers */
35#define TBCTL 0x00
36#define TBPRD 0x0A
37
38#define TBCTL_RUN_MASK (BIT(15) | BIT(14))
39#define TBCTL_STOP_NEXT 0
40#define TBCTL_STOP_ON_CYCLE BIT(14)
41#define TBCTL_FREE_RUN (BIT(15) | BIT(14))
42#define TBCTL_PRDLD_MASK BIT(3)
43#define TBCTL_PRDLD_SHDW 0
44#define TBCTL_PRDLD_IMDT BIT(3)
45#define TBCTL_CLKDIV_MASK (BIT(12) | BIT(11) | BIT(10) | BIT(9) | \
46 BIT(8) | BIT(7))
47#define TBCTL_CTRMODE_MASK (BIT(1) | BIT(0))
48#define TBCTL_CTRMODE_UP 0
49#define TBCTL_CTRMODE_DOWN BIT(0)
50#define TBCTL_CTRMODE_UPDOWN BIT(1)
51#define TBCTL_CTRMODE_FREEZE (BIT(1) | BIT(0))
52
53#define TBCTL_HSPCLKDIV_SHIFT 7
54#define TBCTL_CLKDIV_SHIFT 10
55
56#define CLKDIV_MAX 7
57#define HSPCLKDIV_MAX 7
58#define PERIOD_MAX 0xFFFF
59
60/* compare module registers */
61#define CMPA 0x12
62#define CMPB 0x14
63
64/* Action qualifier module registers */
65#define AQCTLA 0x16
66#define AQCTLB 0x18
67#define AQSFRC 0x1A
68#define AQCSFRC 0x1C
69
70#define AQCTL_CBU_MASK (BIT(9) | BIT(8))
71#define AQCTL_CBU_FRCLOW BIT(8)
72#define AQCTL_CBU_FRCHIGH BIT(9)
73#define AQCTL_CBU_FRCTOGGLE (BIT(9) | BIT(8))
74#define AQCTL_CAU_MASK (BIT(5) | BIT(4))
75#define AQCTL_CAU_FRCLOW BIT(4)
76#define AQCTL_CAU_FRCHIGH BIT(5)
77#define AQCTL_CAU_FRCTOGGLE (BIT(5) | BIT(4))
78#define AQCTL_PRD_MASK (BIT(3) | BIT(2))
79#define AQCTL_PRD_FRCLOW BIT(2)
80#define AQCTL_PRD_FRCHIGH BIT(3)
81#define AQCTL_PRD_FRCTOGGLE (BIT(3) | BIT(2))
82#define AQCTL_ZRO_MASK (BIT(1) | BIT(0))
83#define AQCTL_ZRO_FRCLOW BIT(0)
84#define AQCTL_ZRO_FRCHIGH BIT(1)
85#define AQCTL_ZRO_FRCTOGGLE (BIT(1) | BIT(0))
86
Philip, Avinashdaa56292012-09-06 10:40:03 +053087#define AQCTL_CHANA_POLNORMAL (AQCTL_CAU_FRCLOW | AQCTL_PRD_FRCHIGH | \
88 AQCTL_ZRO_FRCHIGH)
89#define AQCTL_CHANA_POLINVERSED (AQCTL_CAU_FRCHIGH | AQCTL_PRD_FRCLOW | \
90 AQCTL_ZRO_FRCLOW)
91#define AQCTL_CHANB_POLNORMAL (AQCTL_CBU_FRCLOW | AQCTL_PRD_FRCHIGH | \
92 AQCTL_ZRO_FRCHIGH)
93#define AQCTL_CHANB_POLINVERSED (AQCTL_CBU_FRCHIGH | AQCTL_PRD_FRCLOW | \
94 AQCTL_ZRO_FRCLOW)
95
Philip, Avinash19891b22012-07-25 16:58:19 +053096#define AQSFRC_RLDCSF_MASK (BIT(7) | BIT(6))
97#define AQSFRC_RLDCSF_ZRO 0
98#define AQSFRC_RLDCSF_PRD BIT(6)
99#define AQSFRC_RLDCSF_ZROPRD BIT(7)
100#define AQSFRC_RLDCSF_IMDT (BIT(7) | BIT(6))
101
102#define AQCSFRC_CSFB_MASK (BIT(3) | BIT(2))
103#define AQCSFRC_CSFB_FRCDIS 0
104#define AQCSFRC_CSFB_FRCLOW BIT(2)
105#define AQCSFRC_CSFB_FRCHIGH BIT(3)
106#define AQCSFRC_CSFB_DISSWFRC (BIT(3) | BIT(2))
107#define AQCSFRC_CSFA_MASK (BIT(1) | BIT(0))
108#define AQCSFRC_CSFA_FRCDIS 0
109#define AQCSFRC_CSFA_FRCLOW BIT(0)
110#define AQCSFRC_CSFA_FRCHIGH BIT(1)
111#define AQCSFRC_CSFA_DISSWFRC (BIT(1) | BIT(0))
112
113#define NUM_PWM_CHANNEL 2 /* EHRPWM channels */
114
115struct ehrpwm_pwm_chip {
116 struct pwm_chip chip;
117 unsigned int clk_rate;
118 void __iomem *mmio_base;
Philip, Avinash01b2d452012-09-06 10:44:25 +0530119 unsigned long period_cycles[NUM_PWM_CHANNEL];
Philip, Avinashdaa56292012-09-06 10:40:03 +0530120 enum pwm_polarity polarity[NUM_PWM_CHANNEL];
Philip, Avinashd91861d2012-11-27 14:18:12 +0530121 struct clk *tbclk;
Philip, Avinash19891b22012-07-25 16:58:19 +0530122};
123
124static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip(struct pwm_chip *chip)
125{
126 return container_of(chip, struct ehrpwm_pwm_chip, chip);
127}
128
129static void ehrpwm_write(void *base, int offset, unsigned int val)
130{
131 writew(val & 0xFFFF, base + offset);
132}
133
134static void ehrpwm_modify(void *base, int offset,
135 unsigned short mask, unsigned short val)
136{
137 unsigned short regval;
138
139 regval = readw(base + offset);
140 regval &= ~mask;
141 regval |= val & mask;
142 writew(regval, base + offset);
143}
144
145/**
146 * set_prescale_div - Set up the prescaler divider function
147 * @rqst_prescaler: prescaler value min
148 * @prescale_div: prescaler value set
149 * @tb_clk_div: Time Base Control prescaler bits
150 */
151static int set_prescale_div(unsigned long rqst_prescaler,
152 unsigned short *prescale_div, unsigned short *tb_clk_div)
153{
154 unsigned int clkdiv, hspclkdiv;
155
156 for (clkdiv = 0; clkdiv <= CLKDIV_MAX; clkdiv++) {
157 for (hspclkdiv = 0; hspclkdiv <= HSPCLKDIV_MAX; hspclkdiv++) {
158
159 /*
160 * calculations for prescaler value :
161 * prescale_div = HSPCLKDIVIDER * CLKDIVIDER.
162 * HSPCLKDIVIDER = 2 ** hspclkdiv
163 * CLKDIVIDER = (1), if clkdiv == 0 *OR*
164 * (2 * clkdiv), if clkdiv != 0
165 *
166 * Configure prescale_div value such that period
167 * register value is less than 65535.
168 */
169
170 *prescale_div = (1 << clkdiv) *
171 (hspclkdiv ? (hspclkdiv * 2) : 1);
172 if (*prescale_div > rqst_prescaler) {
173 *tb_clk_div = (clkdiv << TBCTL_CLKDIV_SHIFT) |
174 (hspclkdiv << TBCTL_HSPCLKDIV_SHIFT);
175 return 0;
176 }
177 }
178 }
179 return 1;
180}
181
Philip, Avinashdaa56292012-09-06 10:40:03 +0530182static void configure_polarity(struct ehrpwm_pwm_chip *pc, int chan)
Philip, Avinash19891b22012-07-25 16:58:19 +0530183{
Philip, Avinashdaa56292012-09-06 10:40:03 +0530184 int aqctl_reg;
Philip, Avinash19891b22012-07-25 16:58:19 +0530185 unsigned short aqctl_val, aqctl_mask;
186
187 /*
Philip, Avinashdaa56292012-09-06 10:40:03 +0530188 * Configure PWM output to HIGH/LOW level on counter
189 * reaches compare register value and LOW/HIGH level
190 * on counter value reaches period register value and
191 * zero value on counter
Philip, Avinash19891b22012-07-25 16:58:19 +0530192 */
193 if (chan == 1) {
194 aqctl_reg = AQCTLB;
Philip, Avinash19891b22012-07-25 16:58:19 +0530195 aqctl_mask = AQCTL_CBU_MASK;
Philip, Avinashdaa56292012-09-06 10:40:03 +0530196
197 if (pc->polarity[chan] == PWM_POLARITY_INVERSED)
198 aqctl_val = AQCTL_CHANB_POLINVERSED;
199 else
200 aqctl_val = AQCTL_CHANB_POLNORMAL;
Philip, Avinash19891b22012-07-25 16:58:19 +0530201 } else {
Philip, Avinash19891b22012-07-25 16:58:19 +0530202 aqctl_reg = AQCTLA;
Philip, Avinash19891b22012-07-25 16:58:19 +0530203 aqctl_mask = AQCTL_CAU_MASK;
Philip, Avinashdaa56292012-09-06 10:40:03 +0530204
205 if (pc->polarity[chan] == PWM_POLARITY_INVERSED)
206 aqctl_val = AQCTL_CHANA_POLINVERSED;
207 else
208 aqctl_val = AQCTL_CHANA_POLNORMAL;
Philip, Avinash19891b22012-07-25 16:58:19 +0530209 }
210
Philip, Avinash19891b22012-07-25 16:58:19 +0530211 aqctl_mask |= AQCTL_PRD_MASK | AQCTL_ZRO_MASK;
Philip, Avinashdaa56292012-09-06 10:40:03 +0530212 ehrpwm_modify(pc->mmio_base, aqctl_reg, aqctl_mask, aqctl_val);
Philip, Avinash19891b22012-07-25 16:58:19 +0530213}
214
215/*
216 * period_ns = 10^9 * (ps_divval * period_cycles) / PWM_CLK_RATE
217 * duty_ns = 10^9 * (ps_divval * duty_cycles) / PWM_CLK_RATE
218 */
219static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
220 int duty_ns, int period_ns)
221{
222 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
223 unsigned long long c;
224 unsigned long period_cycles, duty_cycles;
225 unsigned short ps_divval, tb_divval;
Philip, Avinashdaa56292012-09-06 10:40:03 +0530226 int i, cmp_reg;
Philip, Avinash19891b22012-07-25 16:58:19 +0530227
Thierry Redingc2d476a2012-09-02 22:13:40 +0200228 if (period_ns > NSEC_PER_SEC)
Philip, Avinash19891b22012-07-25 16:58:19 +0530229 return -ERANGE;
230
231 c = pc->clk_rate;
232 c = c * period_ns;
233 do_div(c, NSEC_PER_SEC);
234 period_cycles = (unsigned long)c;
235
236 if (period_cycles < 1) {
237 period_cycles = 1;
238 duty_cycles = 1;
239 } else {
240 c = pc->clk_rate;
241 c = c * duty_ns;
242 do_div(c, NSEC_PER_SEC);
243 duty_cycles = (unsigned long)c;
244 }
245
Philip, Avinash01b2d452012-09-06 10:44:25 +0530246 /*
247 * Period values should be same for multiple PWM channels as IP uses
248 * same period register for multiple channels.
249 */
250 for (i = 0; i < NUM_PWM_CHANNEL; i++) {
251 if (pc->period_cycles[i] &&
252 (pc->period_cycles[i] != period_cycles)) {
253 /*
254 * Allow channel to reconfigure period if no other
255 * channels being configured.
256 */
257 if (i == pwm->hwpwm)
258 continue;
259
260 dev_err(chip->dev, "Period value conflicts with channel %d\n",
261 i);
262 return -EINVAL;
263 }
264 }
265
266 pc->period_cycles[pwm->hwpwm] = period_cycles;
267
Philip, Avinash19891b22012-07-25 16:58:19 +0530268 /* Configure clock prescaler to support Low frequency PWM wave */
269 if (set_prescale_div(period_cycles/PERIOD_MAX, &ps_divval,
270 &tb_divval)) {
271 dev_err(chip->dev, "Unsupported values\n");
272 return -EINVAL;
273 }
274
275 pm_runtime_get_sync(chip->dev);
276
277 /* Update clock prescaler values */
278 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CLKDIV_MASK, tb_divval);
279
280 /* Update period & duty cycle with presacler division */
281 period_cycles = period_cycles / ps_divval;
282 duty_cycles = duty_cycles / ps_divval;
283
284 /* Configure shadow loading on Period register */
285 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_PRDLD_MASK, TBCTL_PRDLD_SHDW);
286
287 ehrpwm_write(pc->mmio_base, TBPRD, period_cycles);
288
289 /* Configure ehrpwm counter for up-count mode */
290 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_CTRMODE_MASK,
291 TBCTL_CTRMODE_UP);
292
Philip, Avinashdaa56292012-09-06 10:40:03 +0530293 if (pwm->hwpwm == 1)
294 /* Channel 1 configured with compare B register */
295 cmp_reg = CMPB;
296 else
297 /* Channel 0 configured with compare A register */
298 cmp_reg = CMPA;
299
300 ehrpwm_write(pc->mmio_base, cmp_reg, duty_cycles);
301
Philip, Avinash19891b22012-07-25 16:58:19 +0530302 pm_runtime_put_sync(chip->dev);
303 return 0;
304}
305
Philip, Avinashdaa56292012-09-06 10:40:03 +0530306static int ehrpwm_pwm_set_polarity(struct pwm_chip *chip,
307 struct pwm_device *pwm, enum pwm_polarity polarity)
308{
309 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
310
311 /* Configuration of polarity in hardware delayed, do at enable */
312 pc->polarity[pwm->hwpwm] = polarity;
313 return 0;
314}
315
Philip, Avinash19891b22012-07-25 16:58:19 +0530316static int ehrpwm_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
317{
318 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
319 unsigned short aqcsfrc_val, aqcsfrc_mask;
320
321 /* Leave clock enabled on enabling PWM */
322 pm_runtime_get_sync(chip->dev);
323
324 /* Disabling Action Qualifier on PWM output */
325 if (pwm->hwpwm) {
326 aqcsfrc_val = AQCSFRC_CSFB_FRCDIS;
327 aqcsfrc_mask = AQCSFRC_CSFB_MASK;
328 } else {
329 aqcsfrc_val = AQCSFRC_CSFA_FRCDIS;
330 aqcsfrc_mask = AQCSFRC_CSFA_MASK;
331 }
332
333 /* Changes to shadow mode */
334 ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK,
335 AQSFRC_RLDCSF_ZRO);
336
337 ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val);
338
Philip, Avinashdaa56292012-09-06 10:40:03 +0530339 /* Channels polarity can be configured from action qualifier module */
340 configure_polarity(pc, pwm->hwpwm);
341
Philip, Avinashd91861d2012-11-27 14:18:12 +0530342 /* Enable TBCLK before enabling PWM device */
343 clk_enable(pc->tbclk);
344
Philip, Avinash19891b22012-07-25 16:58:19 +0530345 /* Enable time counter for free_run */
346 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_FREE_RUN);
347 return 0;
348}
349
350static void ehrpwm_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
351{
352 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
353 unsigned short aqcsfrc_val, aqcsfrc_mask;
354
355 /* Action Qualifier puts PWM output low forcefully */
356 if (pwm->hwpwm) {
357 aqcsfrc_val = AQCSFRC_CSFB_FRCLOW;
358 aqcsfrc_mask = AQCSFRC_CSFB_MASK;
359 } else {
360 aqcsfrc_val = AQCSFRC_CSFA_FRCLOW;
361 aqcsfrc_mask = AQCSFRC_CSFA_MASK;
362 }
363
364 /*
365 * Changes to immediate action on Action Qualifier. This puts
366 * Action Qualifier control on PWM output from next TBCLK
367 */
368 ehrpwm_modify(pc->mmio_base, AQSFRC, AQSFRC_RLDCSF_MASK,
369 AQSFRC_RLDCSF_IMDT);
370
371 ehrpwm_modify(pc->mmio_base, AQCSFRC, aqcsfrc_mask, aqcsfrc_val);
372
Philip, Avinashd91861d2012-11-27 14:18:12 +0530373 /* Disabling TBCLK on PWM disable */
374 clk_disable(pc->tbclk);
375
Philip, Avinash19891b22012-07-25 16:58:19 +0530376 /* Stop Time base counter */
377 ehrpwm_modify(pc->mmio_base, TBCTL, TBCTL_RUN_MASK, TBCTL_STOP_NEXT);
378
379 /* Disable clock on PWM disable */
380 pm_runtime_put_sync(chip->dev);
381}
382
383static void ehrpwm_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
384{
Philip, Avinash01b2d452012-09-06 10:44:25 +0530385 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip);
386
Philip, Avinash19891b22012-07-25 16:58:19 +0530387 if (test_bit(PWMF_ENABLED, &pwm->flags)) {
388 dev_warn(chip->dev, "Removing PWM device without disabling\n");
389 pm_runtime_put_sync(chip->dev);
390 }
Philip, Avinash01b2d452012-09-06 10:44:25 +0530391
392 /* set period value to zero on free */
393 pc->period_cycles[pwm->hwpwm] = 0;
Philip, Avinash19891b22012-07-25 16:58:19 +0530394}
395
396static const struct pwm_ops ehrpwm_pwm_ops = {
397 .free = ehrpwm_pwm_free,
398 .config = ehrpwm_pwm_config,
Philip, Avinashdaa56292012-09-06 10:40:03 +0530399 .set_polarity = ehrpwm_pwm_set_polarity,
Philip, Avinash19891b22012-07-25 16:58:19 +0530400 .enable = ehrpwm_pwm_enable,
401 .disable = ehrpwm_pwm_disable,
402 .owner = THIS_MODULE,
403};
404
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530405static const struct of_device_id ehrpwm_of_match[] = {
406 { .compatible = "ti,am33xx-ehrpwm" },
407 {},
408};
409MODULE_DEVICE_TABLE(of, ehrpwm_of_match);
410
Philip, Avinash19891b22012-07-25 16:58:19 +0530411static int __devinit ehrpwm_pwm_probe(struct platform_device *pdev)
412{
413 int ret;
414 struct resource *r;
415 struct clk *clk;
416 struct ehrpwm_pwm_chip *pc;
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530417 u16 status;
Philip, Avinash19891b22012-07-25 16:58:19 +0530418
419 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
420 if (!pc) {
421 dev_err(&pdev->dev, "failed to allocate memory\n");
422 return -ENOMEM;
423 }
424
425 clk = devm_clk_get(&pdev->dev, "fck");
426 if (IS_ERR(clk)) {
427 dev_err(&pdev->dev, "failed to get clock\n");
428 return PTR_ERR(clk);
429 }
430
431 pc->clk_rate = clk_get_rate(clk);
432 if (!pc->clk_rate) {
433 dev_err(&pdev->dev, "failed to get clock rate\n");
434 return -EINVAL;
435 }
436
437 pc->chip.dev = &pdev->dev;
438 pc->chip.ops = &ehrpwm_pwm_ops;
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530439 pc->chip.of_xlate = of_pwm_xlate_with_flags;
440 pc->chip.of_pwm_n_cells = 3;
Philip, Avinash19891b22012-07-25 16:58:19 +0530441 pc->chip.base = -1;
442 pc->chip.npwm = NUM_PWM_CHANNEL;
443
444 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
445 if (!r) {
446 dev_err(&pdev->dev, "no memory resource defined\n");
447 return -ENODEV;
448 }
449
450 pc->mmio_base = devm_request_and_ioremap(&pdev->dev, r);
Axel Lin2ffdc9a2012-08-03 21:43:54 +0800451 if (!pc->mmio_base)
Philip, Avinash19891b22012-07-25 16:58:19 +0530452 return -EADDRNOTAVAIL;
Philip, Avinash19891b22012-07-25 16:58:19 +0530453
Philip, Avinashd91861d2012-11-27 14:18:12 +0530454 /* Acquire tbclk for Time Base EHRPWM submodule */
455 pc->tbclk = devm_clk_get(&pdev->dev, "tbclk");
456 if (IS_ERR(pc->tbclk)) {
457 dev_err(&pdev->dev, "Failed to get tbclk\n");
458 return PTR_ERR(pc->tbclk);
459 }
460
Philip, Avinash19891b22012-07-25 16:58:19 +0530461 ret = pwmchip_add(&pc->chip);
462 if (ret < 0) {
463 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
464 return ret;
465 }
466
467 pm_runtime_enable(&pdev->dev);
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530468 pm_runtime_get_sync(&pdev->dev);
469
470 status = pwmss_submodule_state_change(pdev->dev.parent,
471 PWMSS_EPWMCLK_EN);
472 if (!(status & PWMSS_EPWMCLK_EN_ACK)) {
473 dev_err(&pdev->dev, "PWMSS config space clock enable failed\n");
474 ret = -EINVAL;
475 goto pwmss_clk_failure;
476 }
477
478 pm_runtime_put_sync(&pdev->dev);
479
Philip, Avinash19891b22012-07-25 16:58:19 +0530480 platform_set_drvdata(pdev, pc);
481 return 0;
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530482
483pwmss_clk_failure:
484 pm_runtime_put_sync(&pdev->dev);
485 pm_runtime_disable(&pdev->dev);
486 pwmchip_remove(&pc->chip);
487 return ret;
Philip, Avinash19891b22012-07-25 16:58:19 +0530488}
489
490static int __devexit ehrpwm_pwm_remove(struct platform_device *pdev)
491{
492 struct ehrpwm_pwm_chip *pc = platform_get_drvdata(pdev);
493
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530494 pm_runtime_get_sync(&pdev->dev);
495 /*
496 * Due to hardware misbehaviour, acknowledge of the stop_req
497 * is missing. Hence checking of the status bit skipped.
498 */
499 pwmss_submodule_state_change(pdev->dev.parent, PWMSS_EPWMCLK_STOP_REQ);
500 pm_runtime_put_sync(&pdev->dev);
501
Philip, Avinash19891b22012-07-25 16:58:19 +0530502 pm_runtime_put_sync(&pdev->dev);
503 pm_runtime_disable(&pdev->dev);
504 return pwmchip_remove(&pc->chip);
505}
506
507static struct platform_driver ehrpwm_pwm_driver = {
508 .driver = {
Philip, Avinash53ad9e8d2012-11-27 14:18:13 +0530509 .name = "ehrpwm",
510 .owner = THIS_MODULE,
511 .of_match_table = ehrpwm_of_match,
Philip, Avinash19891b22012-07-25 16:58:19 +0530512 },
513 .probe = ehrpwm_pwm_probe,
514 .remove = __devexit_p(ehrpwm_pwm_remove),
515};
516
517module_platform_driver(ehrpwm_pwm_driver);
518
519MODULE_DESCRIPTION("EHRPWM PWM driver");
520MODULE_AUTHOR("Texas Instruments");
521MODULE_LICENSE("GPL");