thermal: Add braces around suspect code

It looks like this code is missing braces, otherwise the if
statement shouldn't have been indented. Fix it.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
thermal: Bind cooling devices with the correct arguments

When binding cooling devices to thermal zones created from the device
tree the minimum and maximum cooling states are in the wrong order
leading to failure to bind.

Fix the order of cooling states in the call to
thermal_zone_bind_cooling_device to fix this.

Cc:Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
thermal: imx: update formula for thermal sensor

Thermal sensor used to need two calibration points which are
in fuse map to get a slope for converting thermal sensor's raw
data to real temperature in degree C. Due to the chip calibration
limitation, hardware team provides an universal formula to get
real temperature from internal thermal sensor raw data:

Slope = 0.4297157 - (0.0015976 * 25C fuse);

Update the formula, as there will be no hot point calibration
data in fuse map from now on.

Signed-off-by: Anson Huang <b20788@freescale.com>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Thermal: imx: correct critical trip temperature setting

On latest i.MX6 SOC with thermal calibration data of 0x5A100000,
the critical trip temperature will be an invalid value and
cause system auto shutdown as below log:

thermal thermal_zone0: critical temperature reached(42 C),shutting down

So, with universal formula for thermal sensor, only room
temperature point is calibrated, which means the calibration
data read from fuse only has valid data of bit [31:20], others
are all 0, the critical trip point temperature can NOT depend
on the hot point calibration data, here we set it to 20 C higher
than default passive temperature.

Signed-off-by: Anson Huang <b20788@freescale.com>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
thermal: trace: Trace temperature changes

Create a new event to trace the temperature of a thermal zone. Using
this event trace the temperature changes of the thermal zone every-time
it is updated.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
thermal: trace: Trace when a cooling device's state is updated

Introduce and use an event to trace when a cooling device's state is
updated. This is useful to follow the effect of governor decisions on
cooling devices.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
thermal: trace: Trace when temperature is above a trip point

Create a new event to trace when the temperature is above a trip
point. Use the trace-point when handling non-critical and critical
trip pionts.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Thermal:Remove usless if(!result) before return tz

result is always zero when comes here.

Signed-off-by: Yao Dongdong <yaodongdong@huawei.com>
Acked-by: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
thermal: imx: correct driver load sequence for cpu cooling

thermal driver should be regisetered after cpufreq driver has
been registered and probed. Doing so is to make sure that thermal
driver can get the max cpu cooling states correctly when calling
get_property.

Signed-off-by: Bai Ping <b51503@freescale.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
thermal: imx_thermal: Second cooling device uses devfreq driver

The second cooling device was being registered as another cpu
frequency device.  This is incorrect register it as a device
frequency device.
thermal: imx_thermal: re-org the _probe function to fix unbalanced interrupts

Initializing the thermal_device causes get_temp to get called which in turns
tries to enable interrupts.  Move clock code and the enable_irq setting
up in the probe function to get rid of the kernel warnings on boot.
thermal: imx_thermal: Add a trip point for each cpu_freq state

The driver currently would only trip at 85C and then bring the
SOC and GPU down to the slowest speeds until it reached 75C.

Now we read the number of cpufreq states and spread out trip points
between 85C and critical temp.  At each trip point we drop the
top cpufrequency down and don't raise it again until the temp is
lower than the previous zones trip point.
thermal: step_wise: Add and fix debug output

Add some additional debug output to track the changes being
detected by the driver.  Also fix the typing of some variables
to verify that they print out properly in the debug output.
thermal: devfreq_cooling: Allow max_states to be variable

This allows max_state to be set at the time the devfreq cooling
device is instantiated.  This allows events to match the cpufreq
cooling device and gives tighter grained control over the
devices listening.

Currently I am using state 5 as the critical event number.  This
could be dynamic as well but since only the imx_thermal and galcore
use this driver I am okay hardcoding it for testing.
thermal: imx_thermal: Set max_events for devfreq_cooling

Tell the devfreq device how many cooling states it will have.
gpu: galcore: Handle additional cooling information

Rather than just scaling down the GPU's 3D core to the slowest
speed at the first passive cooling trip point, we slowly scale back
the core clock speed trying to achieve balance.  If we reach the
critical speed we scale all the way back to the lowest freq.

*TEST* the divider number is completely guestimated and needs to be
tested.
char: fsl_otp: Enable kernel config option to enable write support

Write access to the fuses is very dangerous as they can only be
written once.  This is the first commit in locking this down a bit.
Now you must explicitely enable this functionality in the kernel.
char: fsl_otp: Add function to read otp values

Instead of having all drivers mapping the otp memory and checking
values provide a function so they can do it through the driver.
mach: imx: Use fsl_otp helper function

Instead of checking device-tree for the otp definition and mapping
memory ourselves, use the new helper function to read fuse values.
thermal: imx: Rework driver for better flexibility

This should probably be broken up into multiple patches but I will
do that when I get them ready for upstreaming.  Functionality that
I have added is follows.

- read grade of chip from otp and set critical based on this value.
- base the default passive trip points based on the number of cpu
frequency points and the critical thermal temperature.
- allow the user to change the trip_point0 up to a maximum of 85c
and then scale the trip points based on that.