Rewrite code to suspend firmware to avoid flicker on testpatterns

Some monitors are showing flicker or loss of sync on some test patterns.
This has not been completely root-caused but a workaround is to suspend
the Chrontel firmware. This requires reworking the code.

Some sections of the main loop have been pulled into subroutines.

Because the firmware is suspended, the liveness polling of the CH7036 is
changed to use the value of the reset register. This seems to successfully
detect the chip being turned off in suspend.

When a suspend/resume is detected and there was a monitor connected before
suspend and there is still a monitor connected after resume then the
CH7036 is reloaded and the monitor enabled assuming it is the same monitor.
Only then does the firmware get reloaded and the EDID read (which takes a
while). In the best case the monitor is the same and was turned on quickly.
In the bad case the EDID is different so the monitor is turned off and the
resolution reconfigured based on the new EDID.

One the monitor is disconnected the firmware is re-enabled. This seems
to work correctly.

Testing first includes making sure the code still works on the test monitors.
Testing resume can be done by closing/opening lid.
Testing for flicker can be done by running ch7036_monitor by hand without
the -g /sys/class/gpio/gpio207/value flag. This causes HPD detection to be
done by the firmware, hence the firmware cannot be suspended. This will show
the flicker on tft.vanity.dk with the black/white grad test. Then rerun
with the -g /sys/class/gpio/gpio207/value to use gpio detection and allow
the firmware to be suspended.

BUG=chrome-os-partner:3985
TEST=gmerge to device, test with range of monitors, and tv with flicker

Change-Id: Ib11de83ed71c525472774268e606a853ced8798b
Reviewed-on: http://gerrit.chromium.org/gerrit/2221
Tested-by: Mark Hayter <mdhayter@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
4 files changed