OMAP2+: PM/serial: fix console semaphore acquire during suspend

commit 0d8e2d0dad98a693bad88aea6876ac8b94ad95c6 (OMAP2+: PM/serial:
hold console semaphore while OMAP UARTs are disabled) added use of the
console semaphore to protect UARTs from being accessed after disabled
during idle, but this causes problems in suspend.

During suspend, the console semaphore is acquired by the console
suspend method (console_suspend()) so the try_acquire_console_sem()
will always fail and suspend will be aborted.

To fix, introduce a check so the console semaphore is only attempted
during idle, and not during suspend. Also use the same check so that
the console semaphore is not prematurely released during resume.

Thanks to Paul Walmsley for suggesting adding the same check during
resume.

Cc: Paul Walmsley <paul@pwsan.com>
Tested-by: Jean Pihet <j-pihet@ti.com>
Tested-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>

authored by Kevin Hilman and committed by Tony Lindgren e83df17f 28dd3198

+51 -10
+31 -3
arch/arm/mach-omap2/pm24xx.c
··· 53 53 #include <plat/powerdomain.h> 54 54 #include <plat/clockdomain.h> 55 55 56 + #ifdef CONFIG_SUSPEND 57 + static suspend_state_t suspend_state = PM_SUSPEND_ON; 58 + static inline bool is_suspending(void) 59 + { 60 + return (suspend_state != PM_SUSPEND_ON); 61 + } 62 + #else 63 + static inline bool is_suspending(void) 64 + { 65 + return false; 66 + } 67 + #endif 68 + 56 69 static void (*omap2_sram_idle)(void); 57 70 static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl, 58 71 void __iomem *sdrc_power); ··· 133 120 goto no_sleep; 134 121 135 122 /* Block console output in case it is on one of the OMAP UARTs */ 136 - if (try_acquire_console_sem()) 137 - goto no_sleep; 123 + if (!is_suspending()) 124 + if (try_acquire_console_sem()) 125 + goto no_sleep; 138 126 139 127 omap_uart_prepare_idle(0); 140 128 omap_uart_prepare_idle(1); ··· 150 136 omap_uart_resume_idle(1); 151 137 omap_uart_resume_idle(0); 152 138 153 - release_console_sem(); 139 + if (!is_suspending()) 140 + release_console_sem(); 154 141 155 142 no_sleep: 156 143 if (omap2_pm_debug) { ··· 299 284 local_irq_enable(); 300 285 } 301 286 287 + static int omap2_pm_begin(suspend_state_t state) 288 + { 289 + suspend_state = state; 290 + return 0; 291 + } 292 + 302 293 static int omap2_pm_prepare(void) 303 294 { 304 295 /* We cannot sleep in idle until we have resumed */ ··· 354 333 enable_hlt(); 355 334 } 356 335 336 + static void omap2_pm_end(void) 337 + { 338 + suspend_state = PM_SUSPEND_ON; 339 + } 340 + 357 341 static struct platform_suspend_ops omap_pm_ops = { 342 + .begin = omap2_pm_begin, 358 343 .prepare = omap2_pm_prepare, 359 344 .enter = omap2_pm_enter, 360 345 .finish = omap2_pm_finish, 346 + .end = omap2_pm_end, 361 347 .valid = suspend_valid_only_mem, 362 348 }; 363 349
+20 -7
arch/arm/mach-omap2/pm34xx.c
··· 50 50 #include "sdrc.h" 51 51 #include "control.h" 52 52 53 + #ifdef CONFIG_SUSPEND 54 + static suspend_state_t suspend_state = PM_SUSPEND_ON; 55 + static inline bool is_suspending(void) 56 + { 57 + return (suspend_state != PM_SUSPEND_ON); 58 + } 59 + #else 60 + static inline bool is_suspending(void) 61 + { 62 + return false; 63 + } 64 + #endif 65 + 53 66 /* Scratchpad offsets */ 54 67 #define OMAP343X_TABLE_ADDRESS_OFFSET 0xc4 55 68 #define OMAP343X_TABLE_VALUE_OFFSET 0xc0 ··· 400 387 } 401 388 402 389 /* Block console output in case it is on one of the OMAP UARTs */ 403 - if (per_next_state < PWRDM_POWER_ON || 404 - core_next_state < PWRDM_POWER_ON) 405 - if (try_acquire_console_sem()) 406 - goto console_still_active; 390 + if (!is_suspending()) 391 + if (per_next_state < PWRDM_POWER_ON || 392 + core_next_state < PWRDM_POWER_ON) 393 + if (try_acquire_console_sem()) 394 + goto console_still_active; 407 395 408 396 /* PER */ 409 397 if (per_next_state < PWRDM_POWER_ON) { ··· 484 470 omap_uart_resume_idle(3); 485 471 } 486 472 487 - release_console_sem(); 473 + if (!is_suspending()) 474 + release_console_sem(); 488 475 489 476 console_still_active: 490 477 /* Disable IO-PAD and IO-CHAIN wakeup */ ··· 529 514 } 530 515 531 516 #ifdef CONFIG_SUSPEND 532 - static suspend_state_t suspend_state; 533 - 534 517 static int omap3_pm_prepare(void) 535 518 { 536 519 disable_hlt();