UPSTREAM: thermal: exynos: Use the new thermal trend type for quick cooling action.

This patch uses the quick thermal cooling trend type macros. This is needed
as exynos5 and other thermal sensors now supports only interrupt method for
thresold temperature check.

Acked-by: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Amit Daniel Kachhap <amit.daniel@samsung.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
(cherry picked from linux-next commit
	ce760ed3f440cfa51785c64dad9b4bd87673bb11)

BUG=chrome-os-partner:18622
TEST=Build and boot on peach-pit.  When thermal throttling is enabled,
observe that the frequency is immediately set to the maximum (or
minimum) cooling state when a threshold is crossed.

Change-Id: Ice76ae06665337ce56c87a162a3cf758e8927e5e
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/58055
UPSTREAM: thermal: step_wise: set throttle target within thermal instance limits

When selecting a target cooling state in get_target_state(), make sure
that the state is at least as high as the minimum when the temperature
is rising and at least as low as the maximum when the temperature is
falling.  This is necessary because, in the THREAML_TREND_RAISING and
THERMAL_TREND_DROPPING cases, the current state may only be incremented
or decremented by one even if it is outside the bounds of the thermal
instance.  This might occur, for example, if the CPU is heating up
and hits a thermal trip point for the first time when it's frequency
is much higher than the range specified by the thermal instance
corresponding to the trip point.

Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Acked-by: Eduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
(cherry picked from linux-next commit
	e79fe642cc21ac922226b5ea9b7975bf329d4e7a)

BUG=chrome-os-partner:18622
TEST=Build and boot on peach-pit.  Manually adjust the thermal trip
points and observe that, when a thermal limit is hit, that the selected
frequency is within the bounds specified for that limit.

Change-Id: Ife71b4aefbf8501af846dbc627cf3c43d4b10e26
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/58056
Commit-Queue: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
exynos: tmu: Request interrupt only when we are ready for it

At present the code requests the interrupt before it has done the
necessary init (in particular the mutex is no set up).

Correct this by moving the devm_request_irq() later in the probe
function.

BUG=chrome-os-partner:18739,chrome-os-partner:18622
TEST=Boot 30 times without TMU error - previously I was able to get this
to crash within 5-10 boots.
TEST=Manually lower the trip point from 85C to 45C and test:
  * Stres CPU to trigger throttling:
    localhost ~ # while true; do true; done &
    [1] 4066
    localhost ~ # while true; do true; done &
    [2] 4067
    localhost ~ # while true; do true; done &
    [3] 4068
    localhost ~ # while true; do true; done &
    [4] 4069
    <wait a few seconds>
    localhost ~ # cat /sys/class/thermal/thermal_zone0/temp
    45000
    localhost ~ # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
    800000
  * Reduce CPU load to trigger de-throttling:
    localhost ~ # kill 4068 4069
    <wait a few seconds>
    localhost ~ # cat /sys/class/thermal/thermal_zone0/temp
    40000
    localhost ~ # cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
    1400000
  * Run suspend/resume and observe that (de)-throttling still works.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit-int.chromium.org/35984
Reviewed-by: Doug Anderson <dianders@google.com>
Commit-Queue: Simon Glass <sjg@google.com>
Tested-by: Simon Glass <sjg@google.com>
(cherry picked from peach-alpha commit
	566197de1e9657f86b18c407fac18878861844db)

Conflicts:
	drivers/thermal/exynos_thermal.c

Change-Id: I446df06d564590f6942f5725c4fca4d88d8b91eb
Signed-off-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/58057
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
ARM/dts: update device tree binding documentation for hdmi susbsystem

Update device tree binding documentation for hdmi subsystem with the
clock information, hdmiphy child node and phy-power-control node.

BUG=chrome-os-partner:19785
TEST=basic hdmi works fine on Snow, smdk5420, peach board.

Change-Id: Iaaf86698eb10ea43b47ebd0160322d73cd2a367e
Signed-off-by: Rahul Sharma <rahul.sharma@samsung.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/57223
Commit-Queue: Shirish S <shirish@chromium.org>
Reviewed-by: Shirish S <shirish@chromium.org>
Tested-by: Shirish S <shirish@chromium.org>
CHROMIUM: workaround for Infineon TPM broken defensive timeout

The SLB9836 TPM by Infineon goes into a self-defense mode when power
is cut in the middle of a command too many times, and a bug prevents
it from coming out of that mode in a reasonable time frame.  This
patch adds a shutdown-time callback that grabs the mutex wrapping a
request-response transaction, so it's less likely that we'll lose
power in the middle of a command.

Note that the TPM may lose power also across suspend/resume (depending
on hardware).  However, the suspend callback sends a SaveState command,
which can only be sent when other running commands have completed.
I am not sure if a command can start after the suspend callback
has completed (I doubt it) but even if it does, it will be
a sufficiently rare event, and the self-defense can tolerate that.

BUG=chromium:234796
TEST=extensively tested with the librarian simulator
Signed-off-by: Luigi Semenzato <semenzato@chromium.org>

Change-Id: If1424f931f3da2c7d259c7d56050ab68f94f1e5a
Reviewed-on: https://gerrit.chromium.org/gerrit/57988
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
CHROMIUM: drm/i915: repin bound framebuffers on resume

During suspend/resume all fences are reset, including their pin
count which is reset to 0. However a framebuffer can be bound across
suspend/resume, which means that after the buffer is unbound on
resume, the pin count for the buffer will be negative. Since the
fence pin count is now negative when available and zero when in use,
the buffer's fence will get recycled when the fence is in use which
is the opposite of what we want. The adverse effect is that since the
fence is recycled the tiling mode goes away while the buffer is being
displayed and we get lines/screens of garbage.

To fix this, we reallocate and repin the fences for all bound fbs on
resume, which ensures the pin count is right.

v2: Only repin the fence pin count, not the gem buffer pin count

BUG=chromium:219172,chromium:225056
TEST=by hand, suspend/resume on alex, the artifacts are gone

Change-Id: I5f623a583fe475561cc6643bdf52e7744740b4f1
Signed-off-by: Stéphane Marchesin <marcheu@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47933
Reviewed-on: https://gerrit.chromium.org/gerrit/57379
Reviewed-by: Sean Paul <seanpaul@chromium.org>
UPSTREAM: tty: of_serial: unexport tegra_serial_handle_break

Tegra is only booted through device-tree now; there are no board files
left that use this function. Hence, don't export it. Move the static
inline definition into of_serial.c, so we can delete of_serial.h too.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit f26402e81743d06b938a388925904bd47763277a)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: serial: tegra: add serial driver

NVIDIA's Tegra has multiple UART controller which supports:
- APB DMA based controller fifo read/write.
- End Of Data interrupt in incoming data to know whether end
  of frame achieve or not.
- HW controlled RTS and CTS flow control to reduce SW overhead.

Add serial driver to use all above feature.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Acked-by: Alan Cox <alan@linux.intel.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit e9ea096dd2259454e0d09d0b0445fe8f0117add4)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: serial: tegra: Switch to using struct tty_port

Many of the tty functions were converted to use a struct tty_port
instead of a struct tty_struct. Update the Tegra driver accordingly to
avoid build breakage.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 962963e4ee23bc7518dfee754de5f20d35de71d9)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: serial: tegra: Fix compilation error

Fix compilation error, by adding the correct header file
for Tegra clocks.

Signed-off-by: Venu Byravarasu <vbyravarasu@nvidia.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit dbf5bef8da169b38db804996a661f8d634df8295)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: serial: tegra: assume CONFIG_OF

Tegra only supports, and always enables, device tree. Remove all ifdefs
for DT support from the driver.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c3e1becebfe115f827ea2242218c9a8f627c094f)
Signed-off-by: Olof Johansson <olofj@chromium.org>
spi: tegra slink: remove redundant code

There is no code to set spi->controller_data, and hence the HW CS logic
can never trigger. Remove the unused code.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Olof Johansson <olofj@chromium.org>
spi: tegra sflash: assume CONFIG_OF, remove platform data

Tegra only supports, and always enables, device tree. Remove all ifdefs
and runtime checks for DT support from the driver. Platform data is
therefore no longer required. Rework the driver to parse the device tree
directly into struct tegra_sflash_data.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Olof Johansson <olofj@chromium.org>
spi: tegra slink: assume CONFIG_OF, remove platform data

Tegra only supports, and always enables, device tree. Remove all ifdefs
and runtime checks for DT support from the driver. Platform data is
therefore no longer required. Rework the driver to parse the device tree
directly into struct tegra_slink_data.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Olof Johansson <olofj@chromium.org>
spi: remove unused Tegra platform data header

The platform data header is no longer used. Delete it.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: spi: remove check for bits_per_word on transfer from low level driver

The spi core make sure that each transfer structure have the proper
setting for bits_per_word before calling low level transfer APIs.

Hence it is no more require to check again in low level driver for
this field whether this is set correct or not. Removing such code
from low level driver.

The txx9 change also removes a test for bits_per_word set to 0, and
forcing it to 8 in that case. This can also be removed now since
spi_setup() ensures spi->bits_per_word is not zero.

	if (!spi->bits_per_word)
		spi->bits_per_word = 8;

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
(cherry picked from commit 766ed70447e0a9cfb23d068a4a929e18e54b0022)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: spi/tegra: remove checks for valid speed

SPI core make sure that all transfer has proper speed set
before calling low level spi transfer. Hence, it is not
require to have check in spi driver.

Remove the check for speed validity from transfer and use it directly.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
(cherry picked from commit beb96c2ad4cd5012e39587b960aa7e41661c78ca)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: spi: slink-tegra20: move runtime pm calls to transfer_one_message

The prepare_transfer_hardware() is called in atomic context and
calling synchronous runtime pm calls can create scheduling deadlock.

Therefore, in place of calling runtime PM calls from prepare/unprepare
message transfer, calling this in transfer_one_message().

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
(cherry picked from commit d558c4733759e077cf449246983a5d1fe97fc434)
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: spi/tegra114: add spi driver

Add SPI driver for NVIDIA's Tegra114 SPI controller. This controller
is different than the older SoCs SPI controller in internal design as
well as register interface.

This driver supports the:
- non DMA based transfer for smaller transfer i.e. less than FIFO depth.
- APB DMA based transfer for larger transfer i.e. more than FIFO depth.
- Clock gating through runtime PM callbacks.
- registration through DT only.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
(cherry picked from commit f333a331adfacf8c7a9dbf7e5f72b10a0356156b)
(info separated out the dt change from this driver change and put it
info the dt branch for consistency)
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
Signed-off-by: Olof Johansson <olofj@chromium.org>
UPSTREAM: mfd: palmas: Add rtc irq number as irq resource for palmas-rtc

Palma RTC is capable of generating alarm interrupt. Pass the alarm interrupt
as IRQ_RESOURCE for palmas-rtc sub device driver so that rtc driver can get
irq as platform_get_irq().

Also pass the irq domain in mfd_add_devices() to properly offset the irqs for
sub devices. This is needed when adding device through DT.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
(cherry picked from commit a36516b016f52f0f6e5284025e3487f63b4be33b)
Signed-off-by: Olof Johansson <olofj@chromium.org>