OMAPDSS: HDMI: Move GPIO handling to HDMI driver

We currently manage HDMI GPIOs in the board files via
platform_enable/disable calls. This won't work with device tree, and in
any case the correct place to manage the GPIOs is in the HDMI driver.

This patch moves the handling of the GPIOs to the HDMI driver. The GPIO
handling is moved to the common hdmi.c file, and this probably needs to
be revisited when adding OMAP5 HDMI support to see if the GPIO handling
needs to be moved to IP specific files.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Backport-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: HDMI: Get HPD interrupts to work on HDMI cable connect

The TPD12S015A HDMI interface chip needs CT_CP_HPD gpio to be enabled
so that 5V supply is available for HPD detection to work.

Keeping CT_CP_HPD always high has a small impact on power. About 30uA@3.3V
vs 1uA@3.3V when it is low.

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: HDMI: Fix potential NULL ptr dereference and L3 errors

The HDMI IRQ handler needs to check if the irq handler hooks are
valid before calling them to prevent NULL pointer dereference.
We also need to use runtime_get/put() around the functions accessing
HDMI registers else we would get L3 bus errors.

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: Add notifier chain for event notification

Users like OMAPDRM would be interested in events like
Hotplug connect/disconnect. We support this be creating
a event notifier chain. Subscribers can register/unregister
to the OMAPDSS event notifier by using omap_dss_add_event_notify()/
omap_dss_remove_event_notify().

Low level code can publish the event by using dss_notify().

Signed-off-by: Roger Quadros <rogerq@ti.com>
omapdrm/OMAPDSS: get rid of omapdrm_hpd_change()

We no longer need this as we will use the DSS event
notifier call chain for hotplug events.

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: HDMI: Handle HDMI hotplug and notify subscribers

Handling GPIO based HPD is the same irrespective of HDMI IP so
it makes sense to have this piece of code in hdmi.c instead
of hdmi_ip_xxx.c.

Signed-off-by: Roger Quadros <rogerq@ti.com>
omapdrm: service the omapdss hotplug event

Now that omapdss publishes hotplug events we can
subscribe to it using omap_dss_add_event_notify()
and make hotplug detection work.

This patch should get HDMI display to work as soon as it
is plugged in. Previously we had to wait a maximum of
10 seconds for the HDMI panel to be probed.

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: HDMI: disable HPD interrupt on system suspend

This patch fixes the following error in this test case

-Boot with HDMI disconnected
-suspend the system
-connect HDMI monitor while system is suspended

[  214.363311] omapdss CORE: suspend 2
[  214.374176] PM: suspend of devices complete after 64.697 msecs
[  214.380889] PM: late suspend of devices complete after 0.427 msecs
[  214.388763] PM: noirq suspend of devices complete after 1.190 msecs
[  214.395538] Disabling non-boot CPUs ...
[  214.409088] CPU1: shutdown
[  217.305999] Powerdomain (core_pwrdm) didn't enter target state 1 Vs achieved state 3.
[  217.306030] current state 3
[  217.317413] Powerdomain (l4per_pwrdm) didn't enter target state 1 Vs achieved state 3.
[  217.317413] current state 3
[  217.328857] Could not enter target state in pm_suspend
[  217.334625] Enabling non-boot CPUs ...
[  217.355346] CPU1: Booted secondary processor
[  217.355438] CPU1: Unknown IPI message 0x1
[  217.364898] CPU1 is up
[  217.368469] PM: noirq resume of devices complete after 1.037 msecs
[  217.375396] omapdss HDMI: hdmi_runtime_get
[  217.375976] PM: early resume of devices complete after 0.396 msecs
[  217.386474] ------------[ cut here ]------------
[  217.391448] WARNING: at arch/arm/mach-omap2/omap_l3_noc.c:99 l3_interrupt_handler+0x114/0x174()
[  217.400146] Failed to set PHY power mode to 2
[  217.400207] omapdss HDMI: hdmi_runtime_put
[  217.400207] omapdss HDMI: hpd_irq_handler hpd: 1
[  217.414703] L3 standard error: TARGET:DSS  at address 0x6040
[  217.420745] Modules linked in:
[  217.424041] Backtrace:
[  217.426696] [<c0012b58>] (dump_backtrace+0x0/0x114) from [<c04df250>] (dump_stack+0x20/0x24)
[  217.435729]  r6:c0033814 r5:00000009 r4:c06f7e30 r3:c07457cc
[  217.441864] [<c04df230>] (dump_stack+0x0/0x24) from [<c003eccc>] (warn_slowpath_common+0x5c/0x74)
[  217.451385] [<c003ec70>] (warn_slowpath_common+0x0/0x74) from [<c003eda0>] (warn_slowpath_fmt+0x40/0x48)
[  217.461547]  r8:00000000 r7:00000004 r6:00000000 r5:00080001 r4:f003c300
[  217.468597] r3:00000009
[  217.471435] [<c003ed60>] (warn_slowpath_fmt+0x0/0x48) from [<c0033814>] (l3_interrupt_handler+0x114/0x174)
[  217.481781]  r3:c0614d4a r2:c0614c22
[  217.485656] [<c0033700>] (l3_interrupt_handler+0x0/0x174) from [<c008ca50>] (handle_irq_event_percpu+0x98/0x288)
[  217.496551]  r7:0000002a r6:c06fa140 r5:c06f6000 r4:ed0ebd80
[  217.502655] [<c008c9b8>] (handle_irq_event_percpu+0x0/0x288) from [<c008cc8c>] (handle_irq_event+0x4c/0x6c)
[  217.513122] [<c008cc40>] (handle_irq_event+0x0/0x6c) from [<c008fbac>] (handle_fasteoi_irq+0xe0/0x12c)
[  217.523071]  r6:c0718b00 r5:c06fa190 r4:c06fa140 r3:00000000
[  217.529205] [<c008facc>] (handle_fasteoi_irq+0x0/0x12c) from [<c008c360>] (generic_handle_irq+0x30/0x40)
[  217.539337]  r5:00000000 r4:0000002a
[  217.543243] [<c008c330>] (generic_handle_irq+0x0/0x40) from [<c000f5c4>] (handle_IRQ+0x88/0xc8)
[  217.552551]  r4:0000002a r3:00000232
[  217.556427] [<c000f53c>] (handle_IRQ+0x0/0xc8) from [<c000864c>] (gic_handle_irq+0x4c/0x70)
[  217.565368]  r5:fa240100 r4:c06f7f40
[  217.569244] [<c0008600>] (gic_handle_irq+0x0/0x70) from [<c000e180>] (__irq_svc+0x40/0x70)
[  217.578094] Exception stack(0xc06f7f40 to 0xc06f7f88)
[  217.583526] 7f40: c07761a8 aaa2aaaa 4030a43b 00000001 c06f6000 c04ec9c0 ffffffff c06cadec
[  217.592285] 7f60: c0fce1c0 412fc09a 00000000 c06f7f9c c06f7f88 c06f7f88 c000fca4 c000fcb8
[  217.601043] 7f80: 20000113 ffffffff
[  217.604766]  r6:ffffffff r5:20000113 r4:c000fcb8 r3:c000fca4
[  217.610931] [<c000fc18>] (cpu_idle+0x0/0x114) from [<c04ce548>] (rest_init+0x7c/0x94)
[  217.619293]  r5:00000000 r4:00000002
[  217.623199] [<c04ce4cc>] (rest_init+0x0/0x94) from [<c069885c>] (start_kernel+0x2b4/0x304)
[  217.632019]  r4:c0719760 r3:c06d5298
[  217.635894] [<c06985a8>] (start_kernel+0x0/0x304) from [<80008044>] (0x80008044)
[  217.643829] ---[ end trace bfdc309a269b8d17 ]---
[  217.657531] [drm:connector_worker], hotplug event: evt=0, dev=ed3ee800
[  217.664611] omapdss PANEL: tfp410_detect
[  217.669097] omapdss PANEL: tfp410_ddc_read
[  217.673706] omapdss HDMI: hdmi_runtime_get

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: disable l3 errors during suspend/resume

It is possible that DISPC or HDMI interrupt can happen
while DSS core is suspended. In this case runtime_get()
will fail with -EACCESS and we would get L3 errors.

To prevent that we disable the IRQ while suspending and
enable it back on resume.

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: Fix "Failed to set PHY power mode"

This patch fixes the following messages on the console
when HDMI display is suspended.

[  797.372314] Failed to set PHY power mode to 2

Signed-off-by: Roger Quadros <rogerq@ti.com>
OMAPDSS: get rid of l3 error during suspend/resume with ubuntu desktop

Gets rid of the below errors during suspend/resume or with
ubuntu desktop running

[ 1028.047668] WARNING: at /work/GIT/KERNELs/kernel-ubuntu/arch/arm/mach-omap2/omap_l3_noc.c:99 l3_interrupt_handler+0x110/0x174()
[ 1028.059875] L3 standard error: TARGET:DSS  at address 0x101c
[ 1028.065887] Modules linked in: omapdrm_pvr(O) wl12xx wlcore mac80211 cfg80211 joydev hid_logitech_dj rfcomm omapdce(C) bnep rpmsg_omx omaprpc(C) bluetooth omap_remoteproc rpmsg_resmgr_common remoteproc ppdev dm_multipath lp omap_rpmsc
[ 1028.104064] [<c001bab4>] (unwind_backtrace+0x0/0xec) from [<c05a1cc8>] (dump_stack+0x20/0x24)
[ 1028.113159] [<c05a1cc8>] (dump_stack+0x20/0x24) from [<c0044e34>] (warn_slowpath_common+0x5c/0x74)
[ 1028.122711] [<c0044e34>] (warn_slowpath_common+0x5c/0x74) from [<c0044f08>] (warn_slowpath_fmt+0x40/0x48)
[ 1028.132904] [<c0044f08>] (warn_slowpath_fmt+0x40/0x48) from [<c0039aec>] (l3_interrupt_handler+0x110/0x174)
[ 1028.143280] [<c0039aec>] (l3_interrupt_handler+0x110/0x174) from [<c00bdfdc>] (handle_irq_event_percpu+0xc4/0x2ac)
[ 1028.154296] [<c00bdfdc>] (handle_irq_event_percpu+0xc4/0x2ac) from [<c00be210>] (handle_irq_event+0x4c/0x6c)
[ 1028.164764] [<c00be210>] (handle_irq_event+0x4c/0x6c) from [<c00c0f9c>] (handle_fasteoi_irq+0xd8/0x124)
[ 1028.174774] [<c00c0f9c>] (handle_fasteoi_irq+0xd8/0x124) from [<c00bd740>] (generic_handle_irq+0x40/0x54)
[ 1028.184997] [<c00bd740>] (generic_handle_irq+0x40/0x54) from [<c0014270>] (handle_IRQ+0x88/0xc8)
[ 1028.194335] [<c0014270>] (handle_IRQ+0x88/0xc8) from [<c000868c>] (gic_handle_irq+0x44/0x68)
[ 1028.203338] [<c000868c>] (gic_handle_irq+0x44/0x68) from [<c05b7e00>] (__irq_svc+0x40/0x70)
[ 1028.212219] Exception stack(0xeb3f1d08 to 0xeb3f1d50)
[ 1028.217590] 1d00:                   c0b1bf34 600f0113 f0058000 00000000 00000000 ebac9800
[ 1028.226318] 1d20: 600f0113 00002000 c045bee8 0000003f 00000000 eb3f1d5c eb3f1d60 eb3f1d50
[ 1028.235015] 1d40: c02ffba4 c05b7260 600f0113 ffffffff
[ 1028.240417] [<c05b7e00>] (__irq_svc+0x40/0x70) from [<c05b7260>] (_raw_spin_unlock_irqrestore+0x2c/0x54)
[ 1028.250518] [<c05b7260>] (_raw_spin_unlock_irqrestore+0x2c/0x54) from [<c02ffba4>] (omap_dispc_register_isr+0xd4/0xe4)
[ 1028.261901] [<c02ffba4>] (omap_dispc_register_isr+0xd4/0xe4) from [<c045c038>] (install_irq+0x34/0x58)
[ 1028.271820] [<c045c038>] (install_irq+0x34/0x58) from [<c045c1bc>] (commit+0x160/0x1dc)
[ 1028.280364] [<c045c1bc>] (commit+0x160/0x1dc) from [<c045c290>] (omap_plane_dpms+0x58/0xbc)
[ 1028.289245] [<c045c290>] (omap_plane_dpms+0x58/0xbc) from [<c045c72c>] (omap_plane_update+0x74/0x78)
[ 1028.298980] [<c045c72c>] (omap_plane_update+0x74/0x78) from [<c0360eac>] (drm_mode_setplane+0x308/0x354)
[ 1028.309082] [<c0360eac>] (drm_mode_setplane+0x308/0x354) from [<c0354478>] (drm_ioctl+0x27c/0x404)
[ 1028.318634] [<c0354478>] (drm_ioctl+0x27c/0x404) from [<c0153478>] (do_vfs_ioctl+0x2a8/0x2e4)
[ 1028.327728] [<c0153478>] (do_vfs_ioctl+0x2a8/0x2e4) from [<c0153514>] (sys_ioctl+0x60/0x84)
[ 1028.336608] [<c0153514>] (sys_ioctl+0x60/0x84) from [<c0013180>] (ret_fast_syscall+0x0/0x30)

Signed-off-by: Roger Quadros <rogerq@ti.com>
UBUNTU: version 3.4.0-1489.2

Signed-off-by: Xavier Boudet <x-boudet@ti.com>