CHROMIUM: video: tegra: check the fb handle before access

The framebuffer is allocated dynamically since the commit
116cdd07b1b6b (CHROMIUM: video: tegra: Allocate framebuffer
dynamically). The allocation is executed in an asynchronous
notifier call - tegra_dc_create_fb. If we access dc->fb
before the tegra_dc_create_fb gets called, we will hit
null pointer deference error. A known case is booting with
hdmi connected. This patch tries to check the fb and defer
the operation if fb is not available yet.

BUG=chrome-os-partner:30196
TEST=Boots fine with hdmi connected.

Change-Id: Ia220f839c4ce14e54f1b2a3def6120bda9467028
Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/206439
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit bea97f5cb068b4a6b233ef8514d4d796b197a0fb)
Reviewed-on: https://chromium-review.googlesource.com/207412
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: ARM: dts: blaze: update T-SKIN trip temperature

Update T-skin trip temperature to 45 Celsius.

BUG=chrome-os-partner:29744
TEST=build, download and verified by thermal test

Change-Id: I6eddfd61385160f1b749824e8e31d3a8fbc5ad0f
Signed-off-by: Neil Chen <neilc@nvidia.com>
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/207341
Reviewed-by: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit fcb1c6fc33e679b89ba8b4b6946b8c590f91e5f0)
Reviewed-on: https://chromium-review.googlesource.com/207406
CHROMIUM: HACK: mmc: tegra: don't clock gate across suspend/resume

Sometimes the Marvell SD8897 generates a SDIO interrupt after it should
have been suspended, which will cause a hard hang if the SDIO IRQ thread
runs while the clock is gated.  Don't clock gate the SDHCI host to avoid
this hang.

Note that this only works around the hard hang issue.  If the SDIO IRQ
thread runs after the host has been suspended, there are likely to be
other issues, e.g. MMC transfers issued by the IRQ thread failing or
timing out.

BUG=chrome-os-partner:28553
TEST=10000 LP0 iterations pass

Change-Id: Icddc460332054503a26b495e7536468e4943847c
Signed-off-by: Peer Chen <pchen@nvidia.com>
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/206800
(cherry picked from commit bd35685295ff5e2845029b59b6132ae548417397)
Reviewed-on: https://chromium-review.googlesource.com/207551
UPSTREAM: Bluetooth: btmrvl: wait for HOST_SLEEP_ENABLE event in suspend

After BT_CMD_HOST_SLEEP_ENABLE command finishes, driver should
wait until getting BT_EVENT_HOST_SLEEP_ENABLE event to complete
suspend procedure.
Without this patch the suspend handler would return success
earlier. By the time when the BT_EVENT_HOST_SLEEP_ENABLE event
comes in the controller driver could have already turned off the
bus clock. This causes kernel crash or system reboot eventually.

Cc: <stable@vger.kernel.org> # 3.13+
Signed-off-by: Chin-Ran Lo <crlo@marvell.com>
Signed-off-by: Jeff CF Chen <jeffc@marvell.com>
Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

BUG=chrome-os-partner:29565,chrome-os-partner:28553,chrome-os-partner:25091
TEST=WLAN connected to AP; BT running A2DP; suspend_stress_test.
Unit test passed overnight.
Based on ODM's test result, 10 out of 13 passed 600 iterations.
It used to fail on every unit.
Without this patch, the current in suspend mode was 7.1mA,
deep sleep 2.2mA. With this patch applied, the current in suspend
mode drops to 2.2mA, same as in deep sleep mode.

Change-Id: I0341c5a5bd938b419af68d3f1671f7c137531fd3
Reviewed-on: https://chromium-review.googlesource.com/206341
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Bing Zhao <bzhao@marvell.com>
Commit-Queue: Bing Zhao <bzhao@marvell.com>
(cherry picked from commit ddab6fb066da0d3e7cb8f49ef71e4329679adbf8)
Reviewed-on: https://chromium-review.googlesource.com/207560
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: video: tegra: Fix sched error and recovery race

Fix race between channel recovery and sched error.

BUG=chrome-os-partner:29236
TEST=emerged kernel, pass Graphic stress 24 hours

Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Change-Id: I7194d5b602f403a7c28c671ff5ce2a0f339600f4
Signed-off-by: Neil Chen <neilc@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/206966
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit cf53de5a2a7760a1c82a29820874a7f7b6068645)
Reviewed-on: https://chromium-review.googlesource.com/207476
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: drm/edid: Update short blanking modes

This updates the list of short blanking modes:
- remove CMN panels whose min clock is 72.6MHz. We could reduce the
  blanking on those panels, but since the minimum clock is 72.6MHz,
  this is more than what fits in a single eDP lane, so no power
  savings are possible there.
- add short blanking for a bunch of other panels where this is
  possible, this usually saves ~80mW.

BUG=chrome-os-partner:29738
TEST=on swanky/glimmer/squawks check that the panel works without artifacts

Change-Id: I38d55e449f0d5e1582122a0b330d40e413d6ef51
Reviewed-on: https://chromium-review.googlesource.com/205274
Reviewed-by: Shawn Nematbakhsh <shawnn@chromium.org>
Commit-Queue: Stéphane Marchesin <marcheu@chromium.org>
Tested-by: Stéphane Marchesin <marcheu@chromium.org>
(cherry picked from commit f8928f12346e094f68410542ddc395b8bdffd97c)
Reviewed-on: https://chromium-review.googlesource.com/207583
Commit-Queue: Shawn Nematbakhsh <shawnn@chromium.org>
Tested-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
CHROMIUM: video: tegra: Fixup bandwidth calculation

The current bandwidth calculation can overflow when the compiler
optimizer re-arranges some of the operands.  We add brackets to
expressions that makes sense and limits the overflow condition.

BUG=chrome-os-partner:29116
TEST=3840x2160 now works without flickering.

Change-Id: I874e7145e84109ef9f912aa4a4fd1d64daa9520c
Signed-off-by: David Ung <davidu@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/206549
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit a4451aaae411c15fcf3d43be4dcf279218209fc2)
Reviewed-on: https://chromium-review.googlesource.com/207723
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
UPSTREAM: drm/i915: Use frame counter for intel_wait_for_vblank() on CTG

Use the same wait_for_vblank code for CTG that we use for ILK+.

Also fix the name of the frame counter register while at it.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
Reviewed-by: Imre Deak <imre.deak@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 57e22f4add51b0f42b76a6960c4a4daa71e8f832)
Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>

BUG=chrome-os-partner:28200,chrome-os-partner:24085,chrome-os-partner:25575
TEST=Manual: Boot and suspend/resume Rambi with drm.debug=0x06.
Check that there are a reduced number of vblank timeouts.

Original-Change-Id: I066d322e104ed5ad9b6573820e1b9b036c7b7f6e
Originally-reviewed-on: https://chromium-review.googlesource.com/203782
Originally-reviewed-by: Benson Leung <bleung@chromium.org>
Originally-reviewed-by: Kevin Strasser <kevin.strasser@intel.com>
Commit-Queue: Kevin Strasser <kevin.strasser@intel.com>
Tested-by: Kevin Strasser <kevin.strasser@intel.com>
(cherry picked from commit a096bed37feeb4077f7e3e8a723fd69a53a6fc7c)

Change-Id: Id466e7fd1203df84663594806f1727db633f2eba
Reviewed-on: https://chromium-review.googlesource.com/207924
Reviewed-by: Benson Leung <bleung@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
CHROMIUM: thermal: update cdev updated field

Set cdev->updated to false, whatever the target state is same as
current state or not.
Because if a cooling device return an error in set_cur_state
callback, we should give the cooling device a chance in the next
passive check to configure itself to the target state.

BUG=chrome-os-partner:30260
TEST=hack the trip temp of gpu-balanced to 40C and the pid
governor to return the max throttle state, then observe below
on boot:
1. without this change, thermal_cdev_update failed then no retry.
2. while with this change, succeeded after couple retries.

Change-Id: I1999b5840b8a85837f4303fae2992bfecba40a82
Signed-off-by: Ken Chang <kenc@nvidia.com>
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207501
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit b73a27e7a1e24a9af3c44ec6821a9815aae61dd4)
Reviewed-on: https://chromium-review.googlesource.com/207984
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: video: tegra: check driver initialization before access

The tegra throttling driver might access the gk20a clk driver
before clk is initialized due to overheating when booting.
So we have to check the driver's readiness first.

BUG=chrome-os-partner:30260
TEST=None

Change-Id: I0b9461ca4e395e6428b7b2a86e676bb8c923415f
Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207320
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Ken Chang <kenc@nvidia.com>
Tested-by: Ken Chang <kenc@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit 2b92289c837727ec7fb29dd29de4b3d3186eb7ee)
Reviewed-on: https://chromium-review.googlesource.com/207992
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: thermal: tegra: return gpu throttling result

If update state failed, it would not change the cur_state.
And return the actual result for set_cur_state and let
the user space decide what to do next.

BUG=chrome-os-partner:30260
TEST=Ran WebGl Aquarium to let the GPU temp hit 60C
then hack the trip temp of gpu-balanced to 40C then reboot
the unit.
Observed tegra_gpu_set_speed_cap() failed on some
throttling states then succeeded in the next target state
which is set by the governor policy or the next passive retry.

Change-Id: I99fd71bde7a5b745ff27ecc720e0bf45afd32463
Signed-off-by: Vince Hsu <vinceh@nvidia.com>
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207299
Reviewed-by: Ken Chang <kenc@nvidia.com>
Tested-by: Ken Chang <kenc@nvidia.com>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit af126a2b0680fbb5121a1425d035660e7aec0402)
Reviewed-on: https://chromium-review.googlesource.com/207993
Tested-by: Andrew Bresticker <abrestic@chromium.org>
BACKPORT: drm/i915/vlv: T12 eDP panel timing enforcement during reboot

The panel power sequencer on vlv doesn't appear to accept changes to its
T12 power down duration during warm reboots. This change forces a delay
for warm reboots to the T12 panel timing as defined in the VBT table for
the connected panel.

Ver2: removed redundant pr_crit(), commented magic value for pp_div_reg

Ver3: moved SYS_RESTART check earlier, new name for pp_div.

Ver4: Minor issue changes

Ver5: Move registration of reboot notifier to edp_connector_init,
      Added warning comment to handler about lack of PM notification.

BUG=chrome-os-partner:25159
TEST=Connect scope to LCDVCC line to panel. Measure T12 timing during
reboot minimum of 500ms required.

Signed-off-by: Clint Taylor <clinton.a.taylor@intel.com>
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
(cherry picked from commit 01527b3127997ef6370d5ad4fa25d96847fbf12a)
Signed-off-by: Clint Taylor <clinton.a.taylor@intel.com>

Conflicts:
	drivers/gpu/drm/i915/intel_dp.c
	drivers/gpu/drm/i915/intel_drv.h

Change-Id: I04590ac98b7a9f8266373a0a73522af2e3b68b17
Reviewed-on: https://chromium-review.googlesource.com/198548
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Commit-Queue: Clinton A Taylor <clinton.a.taylor@intel.com>
Tested-by: Clinton A Taylor <clinton.a.taylor@intel.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
(cherry picked from commit 33c362a248c78b1d8eb67ed2b5cee1462c49e726)
Reviewed-on: https://chromium-review.googlesource.com/210006
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
CHROMIUM: video: tegra: Correct the gk20a fifo interrupt mask

We disable the gk20a fifo schedule error interrupt when doing
gk20a_fifo_recovery. But we disabled fifo channel interrupt
accidentally when doing that. We need to correct that despite
currently gk20a driver doesn't care about fifo channel interrupt.

BUG=chrome-os-partner:30499
TEST=System boots OK

Change-Id: I68cfa8b201d4afeb45f0abc1aca835a1282bdb68
Signed-off-by: Mark Zhang <markz@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/208293
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit b767f8574888185c42d92f52e3bf44747fdbaa27)
Reviewed-on: https://chromium-review.googlesource.com/210027
Commit-Queue: Katie Roberts-Hoffman <katierh@chromium.org>
Tested-by: Katie Roberts-Hoffman <katierh@chromium.org>
CHROMIUM: video: tegra: fix race condition in hdmi_disable and hdcp

After lp0 resume, the usersapce will send fb_blank_powerdown request
to disable dc, but at that time the hdmi may try to run hdcp work queue,
there will have race condition between them. So sometimes the hdcp is running,
but hdmi will be disabled, then the system hang up.
Use hdcp lock in hdmi_disable and hdcp workqueue to synchronize them.

BUG=chrome-os-partner:29474
TEST=plugged HDMI device, run lp0 stress test, passed 4000+ cycles.

Change-Id: I218b70031563b92ac3d6e2038eac179ee0f36b8b
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/207752
Tested-by: Wei Ni <wni.nvidia@gmail.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: David Ung <davidu@nvidia.com>
(cherry picked from commit 7572779ca861592bb6c86f73d135f8b1ceea3f9f)
Reviewed-on: https://chromium-review.googlesource.com/210543
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
CHERRY-PICK: CHROMIUM: ASoC: Intel: Fixed audio noise after resume

read real dsp position when sst_byt_pcm_pointer is getting called

Signed-off-by: yang fang <yang.a.fang@intel.com>

BUG=chrome-os-partner:29906
TEST=play any audio and suspend the system make sure no noise after
resume.

Change-Id: I38495d7c92738c0b45ecc891f6631eeb3d75e8c9
Original-Change-Id: I1c7abacbeb789899ad7c139414e3ee3aa4d7c30d
Reviewed-on: https://chromium-review.googlesource.com/209381
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210617
Commit-Queue: Gaggery Tsai <gaggery.tsai@intel.com>
Tested-by: Gaggery Tsai <gaggery.tsai@intel.com>
CHROMIUM: video: tegra: get limit voltage matching target gk20a rate

When increase gk20a freq rate, it will try to set voltage first,
when it calculated a target voltage, it will call
gk20a_dvfs_rail_apply_limits() to check if the voltage between
min/max_volt. But in this function, it use current freq to get
max_volt, not the target freq rate, so it will cause problems,
it mean the gk20a may run with lower voltage when increase freq.
This change use the target rate to scan the limited values to
get the right voltage.

BUG=chrome-os-partner:30499
TEST=added debug messages to check the voltage when running gpu
dvfs, the valuses are expected.

Change-Id: If6047f2cd1d5fa8f553757f14dd278faa5366668
Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/210632
Tested-by: Wei Ni <wni.nvidia@gmail.com>
Tested-by: Kary Jin <karyj@nvidia.com>
Reviewed-by: Vince Hsu <vinceh@nvidia.com>
Tested-by: Vince Hsu <vinceh@nvidia.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit be0c22aa0f9c8403d1fe65e2f971df38a48c25f4)
Reviewed-on: https://chromium-review.googlesource.com/210637
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
CHROMIUM: tegra: dts: nyan: configure 3v3 run

Explicitly configure the 3v3 run regulator controlled by
am3722 gpio.  Configure this as the vcc supply for the
temperature sensor.

BUG=chrome-os-partner:29179
TEST=3x3000 reboot cycles

Change-Id: I36fde8aa0557fdbb2c609a92ca9fd3a7ed310963
Signed-off-by: Christopher Freeman <cfreeman@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/210376
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit 33fa98bdee6393da6a25386b50840c002869cb06)
Reviewed-on: https://chromium-review.googlesource.com/211210
CHROMIUM: ARM: dts: blaze: update EMC DFS tables

This change updated the EMC tables with emc_reg_tool 5.0.18,
for below memory SKUs:

 - Hynix H5TC4G63AFR-PBR 2GB, ramcode = 0
 - Micron MT41K256M16HA-125 2GB, ramcode = 1
 - Samsung K4B4G1646Q-HYK0 2GB, ramcode = 2
 - Hynix H5TC8G63AFR-PBR 4GB, ramcode = 8
 - Micron MT41K512M16TNA-125 4GB, ramcode = 9
 - Samsung K4B8G1646Q-MYKO 4GB, ramcode = 10

BUG=chrome-os-partner:30963
TEST=emerged kernel, booted successfully.

Change-Id: Iaf5b2548314f6bdc9b332e90711b8602856b28c1
Signed-off-by: Ken Chang <kenc@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/209997
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Neil Chen <neilc@nvidia.com>
(cherry picked from commit a084a046e0eddcd75cbacacefe0a33ebd7a36998)
Reviewed-on: https://chromium-review.googlesource.com/211230
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CHROMIUM: ARM: tegra: enable ram-repair

The RAMs in the CPU cluster need to support RAM repair. Since the power
rail to the CPU cluster would be shut down in the CPU idle cluster power
down state and cluster switching, the RAM repair information will be
lost. It needs to be reprogrammed again after power resume. There is a
HW approach to do that by disabling RAM_REPAIR_BYPASS_EN in the flow
controller.

BUG=chrome-os-partner:30430
TEST=boot on nyan and suspend_stress_test

Change-Id: Ieb44da94ca8e0060b3af020d92207a9da06f976b
Signed-off-by: Joseph Lo <josephl@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/208614
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit 8d31a21d806a6a232d74fcd079dd20303406dc5a)
Reviewed-on: https://chromium-review.googlesource.com/211231
Tested-by: Dylan Reid <dgreid@chromium.org>
CHROMIUM: clk: tegra124: enable fuse clock during CPU cluster suspend/resume

The RAMs in the CPU cluster need to support RAM repair. But the logic is
depended on the fuse clock. So enable it during CPU cluster
suspend/resume routine.

BUG=chrome-os-partner:30430
TEST=boot on nyan

Change-Id: I1eb4eb330f432f62dd8ec4ed5300a869f897e001
Signed-off-by: Joseph Lo <josephl@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/208613
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit 86c912d0305efded476abd23520ef0a4de53701a)
Reviewed-on: https://chromium-review.googlesource.com/211201
Tested-by: Dylan Reid <dgreid@chromium.org>