aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorTarun Kanti DebBarma <tarun.kanti@ti.com>2011-09-20 07:30:26 -0400
committerTony Lindgren <tony@atomide.com>2011-09-21 20:26:51 -0400
commitab4eb8b098c7591459b066cec0325a63792e463b (patch)
tree9c4174428352a29778d8d424afe2ad86d009e247 /arch
parentb481113a8af65f49afed46d4c9132b7af9426684 (diff)
ARM: OMAP: dmtimer: add error handling to export APIs
Add error handling code to export APIs. Signed-off-by: Tarun Kanti DebBarma <tarun.kanti@ti.com> Reviewed-by: Santosh Shilimkar <santosh.shilimkar@ti.com> Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/plat-omap/dmtimer.c102
-rw-r--r--arch/arm/plat-omap/include/plat/dmtimer.h24
2 files changed, 89 insertions, 37 deletions
diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
index 43eb75038ba2..de7896fd9b33 100644
--- a/arch/arm/plat-omap/dmtimer.c
+++ b/arch/arm/plat-omap/dmtimer.c
@@ -214,12 +214,16 @@ struct omap_dm_timer *omap_dm_timer_request_specific(int id)
214} 214}
215EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific); 215EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific);
216 216
217void omap_dm_timer_free(struct omap_dm_timer *timer) 217int omap_dm_timer_free(struct omap_dm_timer *timer)
218{ 218{
219 if (unlikely(!timer))
220 return -EINVAL;
221
219 clk_put(timer->fclk); 222 clk_put(timer->fclk);
220 223
221 WARN_ON(!timer->reserved); 224 WARN_ON(!timer->reserved);
222 timer->reserved = 0; 225 timer->reserved = 0;
226 return 0;
223} 227}
224EXPORT_SYMBOL_GPL(omap_dm_timer_free); 228EXPORT_SYMBOL_GPL(omap_dm_timer_free);
225 229
@@ -237,7 +241,9 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_disable);
237 241
238int omap_dm_timer_get_irq(struct omap_dm_timer *timer) 242int omap_dm_timer_get_irq(struct omap_dm_timer *timer)
239{ 243{
240 return timer->irq; 244 if (timer)
245 return timer->irq;
246 return -EINVAL;
241} 247}
242EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq); 248EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq);
243 249
@@ -281,7 +287,9 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask);
281 287
282struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer) 288struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer)
283{ 289{
284 return timer->fclk; 290 if (timer)
291 return timer->fclk;
292 return NULL;
285} 293}
286EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk); 294EXPORT_SYMBOL_GPL(omap_dm_timer_get_fclk);
287 295
@@ -295,21 +303,25 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_modify_idlect_mask);
295 303
296#endif 304#endif
297 305
298void omap_dm_timer_trigger(struct omap_dm_timer *timer) 306int omap_dm_timer_trigger(struct omap_dm_timer *timer)
299{ 307{
300 if (unlikely(pm_runtime_suspended(&timer->pdev->dev))) { 308 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
301 pr_err("%s: timer%d not enabled.\n", __func__, timer->id); 309 pr_err("%s: timer not available or enabled.\n", __func__);
302 return; 310 return -EINVAL;
303 } 311 }
304 312
305 omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0); 313 omap_dm_timer_write_reg(timer, OMAP_TIMER_TRIGGER_REG, 0);
314 return 0;
306} 315}
307EXPORT_SYMBOL_GPL(omap_dm_timer_trigger); 316EXPORT_SYMBOL_GPL(omap_dm_timer_trigger);
308 317
309void omap_dm_timer_start(struct omap_dm_timer *timer) 318int omap_dm_timer_start(struct omap_dm_timer *timer)
310{ 319{
311 u32 l; 320 u32 l;
312 321
322 if (unlikely(!timer))
323 return -EINVAL;
324
313 omap_dm_timer_enable(timer); 325 omap_dm_timer_enable(timer);
314 326
315 if (timer->loses_context) { 327 if (timer->loses_context) {
@@ -327,25 +339,36 @@ void omap_dm_timer_start(struct omap_dm_timer *timer)
327 339
328 /* Save the context */ 340 /* Save the context */
329 timer->context.tclr = l; 341 timer->context.tclr = l;
342 return 0;
330} 343}
331EXPORT_SYMBOL_GPL(omap_dm_timer_start); 344EXPORT_SYMBOL_GPL(omap_dm_timer_start);
332 345
333void omap_dm_timer_stop(struct omap_dm_timer *timer) 346int omap_dm_timer_stop(struct omap_dm_timer *timer)
334{ 347{
335 unsigned long rate = 0; 348 unsigned long rate = 0;
336 struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data; 349 struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data;
337 350
351 if (unlikely(!timer))
352 return -EINVAL;
353
338 if (!pdata->needs_manual_reset) 354 if (!pdata->needs_manual_reset)
339 rate = clk_get_rate(timer->fclk); 355 rate = clk_get_rate(timer->fclk);
340 356
341 __omap_dm_timer_stop(timer, timer->posted, rate); 357 __omap_dm_timer_stop(timer, timer->posted, rate);
358
359 return 0;
342} 360}
343EXPORT_SYMBOL_GPL(omap_dm_timer_stop); 361EXPORT_SYMBOL_GPL(omap_dm_timer_stop);
344 362
345int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source) 363int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source)
346{ 364{
347 int ret; 365 int ret;
348 struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data; 366 struct dmtimer_platform_data *pdata;
367
368 if (unlikely(!timer))
369 return -EINVAL;
370
371 pdata = timer->pdev->dev.platform_data;
349 372
350 if (source < 0 || source >= 3) 373 if (source < 0 || source >= 3)
351 return -EINVAL; 374 return -EINVAL;
@@ -356,11 +379,14 @@ int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source)
356} 379}
357EXPORT_SYMBOL_GPL(omap_dm_timer_set_source); 380EXPORT_SYMBOL_GPL(omap_dm_timer_set_source);
358 381
359void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, 382int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload,
360 unsigned int load) 383 unsigned int load)
361{ 384{
362 u32 l; 385 u32 l;
363 386
387 if (unlikely(!timer))
388 return -EINVAL;
389
364 omap_dm_timer_enable(timer); 390 omap_dm_timer_enable(timer);
365 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); 391 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
366 if (autoreload) 392 if (autoreload)
@@ -375,15 +401,19 @@ void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload,
375 timer->context.tclr = l; 401 timer->context.tclr = l;
376 timer->context.tldr = load; 402 timer->context.tldr = load;
377 omap_dm_timer_disable(timer); 403 omap_dm_timer_disable(timer);
404 return 0;
378} 405}
379EXPORT_SYMBOL_GPL(omap_dm_timer_set_load); 406EXPORT_SYMBOL_GPL(omap_dm_timer_set_load);
380 407
381/* Optimized set_load which removes costly spin wait in timer_start */ 408/* Optimized set_load which removes costly spin wait in timer_start */
382void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, 409int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload,
383 unsigned int load) 410 unsigned int load)
384{ 411{
385 u32 l; 412 u32 l;
386 413
414 if (unlikely(!timer))
415 return -EINVAL;
416
387 omap_dm_timer_enable(timer); 417 omap_dm_timer_enable(timer);
388 418
389 if (timer->loses_context) { 419 if (timer->loses_context) {
@@ -408,14 +438,18 @@ void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload,
408 timer->context.tclr = l; 438 timer->context.tclr = l;
409 timer->context.tldr = load; 439 timer->context.tldr = load;
410 timer->context.tcrr = load; 440 timer->context.tcrr = load;
441 return 0;
411} 442}
412EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start); 443EXPORT_SYMBOL_GPL(omap_dm_timer_set_load_start);
413 444
414void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, 445int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable,
415 unsigned int match) 446 unsigned int match)
416{ 447{
417 u32 l; 448 u32 l;
418 449
450 if (unlikely(!timer))
451 return -EINVAL;
452
419 omap_dm_timer_enable(timer); 453 omap_dm_timer_enable(timer);
420 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); 454 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
421 if (enable) 455 if (enable)
@@ -429,14 +463,18 @@ void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable,
429 timer->context.tclr = l; 463 timer->context.tclr = l;
430 timer->context.tmar = match; 464 timer->context.tmar = match;
431 omap_dm_timer_disable(timer); 465 omap_dm_timer_disable(timer);
466 return 0;
432} 467}
433EXPORT_SYMBOL_GPL(omap_dm_timer_set_match); 468EXPORT_SYMBOL_GPL(omap_dm_timer_set_match);
434 469
435void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, 470int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on,
436 int toggle, int trigger) 471 int toggle, int trigger)
437{ 472{
438 u32 l; 473 u32 l;
439 474
475 if (unlikely(!timer))
476 return -EINVAL;
477
440 omap_dm_timer_enable(timer); 478 omap_dm_timer_enable(timer);
441 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); 479 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
442 l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM | 480 l &= ~(OMAP_TIMER_CTRL_GPOCFG | OMAP_TIMER_CTRL_SCPWM |
@@ -451,13 +489,17 @@ void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on,
451 /* Save the context */ 489 /* Save the context */
452 timer->context.tclr = l; 490 timer->context.tclr = l;
453 omap_dm_timer_disable(timer); 491 omap_dm_timer_disable(timer);
492 return 0;
454} 493}
455EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm); 494EXPORT_SYMBOL_GPL(omap_dm_timer_set_pwm);
456 495
457void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler) 496int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler)
458{ 497{
459 u32 l; 498 u32 l;
460 499
500 if (unlikely(!timer))
501 return -EINVAL;
502
461 omap_dm_timer_enable(timer); 503 omap_dm_timer_enable(timer);
462 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG); 504 l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
463 l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2)); 505 l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2));
@@ -470,12 +512,16 @@ void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler)
470 /* Save the context */ 512 /* Save the context */
471 timer->context.tclr = l; 513 timer->context.tclr = l;
472 omap_dm_timer_disable(timer); 514 omap_dm_timer_disable(timer);
515 return 0;
473} 516}
474EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler); 517EXPORT_SYMBOL_GPL(omap_dm_timer_set_prescaler);
475 518
476void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, 519int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer,
477 unsigned int value) 520 unsigned int value)
478{ 521{
522 if (unlikely(!timer))
523 return -EINVAL;
524
479 omap_dm_timer_enable(timer); 525 omap_dm_timer_enable(timer);
480 __omap_dm_timer_int_enable(timer, value); 526 __omap_dm_timer_int_enable(timer, value);
481 527
@@ -483,6 +529,7 @@ void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer,
483 timer->context.tier = value; 529 timer->context.tier = value;
484 timer->context.twer = value; 530 timer->context.twer = value;
485 omap_dm_timer_disable(timer); 531 omap_dm_timer_disable(timer);
532 return 0;
486} 533}
487EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable); 534EXPORT_SYMBOL_GPL(omap_dm_timer_set_int_enable);
488 535
@@ -490,8 +537,8 @@ unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer)
490{ 537{
491 unsigned int l; 538 unsigned int l;
492 539
493 if (unlikely(pm_runtime_suspended(&timer->pdev->dev))) { 540 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
494 pr_err("%s: timer%d not enabled.\n", __func__, timer->id); 541 pr_err("%s: timer not available or enabled.\n", __func__);
495 return 0; 542 return 0;
496 } 543 }
497 544
@@ -501,18 +548,22 @@ unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer)
501} 548}
502EXPORT_SYMBOL_GPL(omap_dm_timer_read_status); 549EXPORT_SYMBOL_GPL(omap_dm_timer_read_status);
503 550
504void omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value) 551int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value)
505{ 552{
553 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev)))
554 return -EINVAL;
555
506 __omap_dm_timer_write_status(timer, value); 556 __omap_dm_timer_write_status(timer, value);
507 /* Save the context */ 557 /* Save the context */
508 timer->context.tisr = value; 558 timer->context.tisr = value;
559 return 0;
509} 560}
510EXPORT_SYMBOL_GPL(omap_dm_timer_write_status); 561EXPORT_SYMBOL_GPL(omap_dm_timer_write_status);
511 562
512unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer) 563unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer)
513{ 564{
514 if (unlikely(pm_runtime_suspended(&timer->pdev->dev))) { 565 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
515 pr_err("%s: timer%d not enabled.\n", __func__, timer->id); 566 pr_err("%s: timer not iavailable or enabled.\n", __func__);
516 return 0; 567 return 0;
517 } 568 }
518 569
@@ -520,17 +571,18 @@ unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer)
520} 571}
521EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter); 572EXPORT_SYMBOL_GPL(omap_dm_timer_read_counter);
522 573
523void omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value) 574int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value)
524{ 575{
525 if (unlikely(pm_runtime_suspended(&timer->pdev->dev))) { 576 if (unlikely(!timer || pm_runtime_suspended(&timer->pdev->dev))) {
526 pr_err("%s: timer%d not enabled.\n", __func__, timer->id); 577 pr_err("%s: timer not available or enabled.\n", __func__);
527 return; 578 return -EINVAL;
528 } 579 }
529 580
530 omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value); 581 omap_dm_timer_write_reg(timer, OMAP_TIMER_COUNTER_REG, value);
531 582
532 /* Save the context */ 583 /* Save the context */
533 timer->context.tcrr = value; 584 timer->context.tcrr = value;
585 return 0;
534} 586}
535EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter); 587EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter);
536 588
diff --git a/arch/arm/plat-omap/include/plat/dmtimer.h b/arch/arm/plat-omap/include/plat/dmtimer.h
index 9519d87179e1..d11025e6e7a4 100644
--- a/arch/arm/plat-omap/include/plat/dmtimer.h
+++ b/arch/arm/plat-omap/include/plat/dmtimer.h
@@ -109,7 +109,7 @@ struct dmtimer_platform_data {
109 109
110struct omap_dm_timer *omap_dm_timer_request(void); 110struct omap_dm_timer *omap_dm_timer_request(void);
111struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id); 111struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id);
112void omap_dm_timer_free(struct omap_dm_timer *timer); 112int omap_dm_timer_free(struct omap_dm_timer *timer);
113void omap_dm_timer_enable(struct omap_dm_timer *timer); 113void omap_dm_timer_enable(struct omap_dm_timer *timer);
114void omap_dm_timer_disable(struct omap_dm_timer *timer); 114void omap_dm_timer_disable(struct omap_dm_timer *timer);
115 115
@@ -118,23 +118,23 @@ int omap_dm_timer_get_irq(struct omap_dm_timer *timer);
118u32 omap_dm_timer_modify_idlect_mask(u32 inputmask); 118u32 omap_dm_timer_modify_idlect_mask(u32 inputmask);
119struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer); 119struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer);
120 120
121void omap_dm_timer_trigger(struct omap_dm_timer *timer); 121int omap_dm_timer_trigger(struct omap_dm_timer *timer);
122void omap_dm_timer_start(struct omap_dm_timer *timer); 122int omap_dm_timer_start(struct omap_dm_timer *timer);
123void omap_dm_timer_stop(struct omap_dm_timer *timer); 123int omap_dm_timer_stop(struct omap_dm_timer *timer);
124 124
125int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source); 125int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source);
126void omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, unsigned int value); 126int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, unsigned int value);
127void omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, unsigned int value); 127int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, unsigned int value);
128void omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, unsigned int match); 128int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, unsigned int match);
129void omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger); 129int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger);
130void omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler); 130int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler);
131 131
132void omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, unsigned int value); 132int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, unsigned int value);
133 133
134unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer); 134unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer);
135void omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value); 135int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value);
136unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer); 136unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer);
137void omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value); 137int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value);
138 138
139int omap_dm_timers_active(void); 139int omap_dm_timers_active(void);
140 140