Staging: add TI OMAP Thermal Framework drivers

Add OMAP on-die governor to the thermal fw

Add OMAP on-die governor to the thermal fw

Add the OMAP on-die governor to the thermal framework.
This component will impose the policy for the on-die temp
sensor.

Change-Id: I68d69309c79088e44573991c940139e9710377f1
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>

Thermal Governor: Disable annoying logging statement

Thermal Governor: Disable annoying logging statement

Remove the informative statement from the thermal governor

Change-Id: I2bf574ad7c57ec3b19231c27944f529b345d7cbb
Signed-off-by: Dan Murphy <dmurphy@ti.com>

Thermal Governor: Update the actions for each thermal zone

Thermal Governor: Update the actions for each thermal zone

This patch applies the following changes to the governor:
 - Set the FATAL zone at 125C - accuracy of on-die sensor is already
included in the hot spot temperature extrapolation
 - Updated the formula to extrapolate the hot spot temperature:
the parameters of the formula are updated to keep OMAP in safe
thermal conditions
 - Fixed the main state machine handling the transition between
thermal zones
 - Fixed the thresholds and monitoring rate configuration
for the various thermal zones
 - Moved the cpu throttle from monitor zone to the panic zone
 - Updated the behavior in panic zone to handle consecutives entrance
into the panic zone
To summarize, this patch ensures that the CPU frequency is throttled
by 1 step when hot spot temperature enters into panic zone. Then
maximum CPU frequency is re-enabled when hot spot temperature comes back
into the monitor zone.

Change-Id: Idf870e3ae17c5b23921eeff9e31f2b3f193dbf2d
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

Thermal Governor: Added logging statement

Thermal Governor: Added logging statement

This patch adds log when entering thermal zones

Change-Id: Iec6d70f6625bd756d5018026d3f50fbea7eddf3f
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

Thermal: Modify the panic zone to be more agressive

Thermal: Modify the panic zone to be more agressive

Modify the panic zone to be more agressive with the cooling.
Basically once this zone is reached the governor should set the
threshold windows so that it can be notified if the temp is still
increasing once the the CPU is throttle.  If the temp is still increasing
then go to the next OPP until max throttling.

Change-Id: I4d4698a8f8ead5ce243032d80e136d7638e675f9
Signed-off-by: Dan Murphy <dmurphy@ti.com>

OMAP4 CPU Thermal governor: use PCB sensor to extrapolate hot spot temperature

OMAP4 CPU Thermal governor: use PCB sensor to extrapolate hot spot temperature

Even if OMAP4460/4470 on-die temperature sensor is located as close
as possible to OMAP MPU-SS, there is still an offset between on-die
sensor and OMAP hot spot.
This offset depends a lot on the additional system power:
various laws could be defined depending on the system power.
Relying on a PCB sensor allows correcting this offset temperature:
linear law can be used in thermal policy to adjust the temperature
read on the sensor and correct the offset at run time.

This patch adds the support of PCB temperature in the thermal governor:
- Updated formula to extrapolate hot spot from on-die sensor and PCB sensor
- Updated reconfiguration of thresholds that should take into account the
variation of PCB temperature
- Added additional thread to monitor the on-die temperature and make
average on latest 20 measurements:
This average temperature is mandatory to take care of huge delta
between on-die sensor and PCB sensor when the temperature
increases quickly (burst CPU activity).
This huge delta is coming from different response time between
on-die sensor and PCB sensor.

Change-Id: Ied89a7e3f3edd249808a245c0180cbfd073dcd1c
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

ARM:OMAP4:Thermal Framework:TMP102 registration

ARM:OMAP4:Thermal Framework:TMP102 registration

The external sensor registration to omap die governor. The
sensor is present in som4470

Change-Id: I8b38dcdc4acd377bb544fa8487094cc976f6532f
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>

Add thermal framework to the staging area

Add thermal framework to the staging area

Add a thermal framework to the kernel so that thermal
sensors, thermal governors and thermal cooling agents
can register.

This framework presents a single point of thermal integration.
The framework is responsible for receiving the temperature
from the temp sensor and pushing the temperature to the correct
governor.

The temp sensor is expected just to report the temp for a particular domain
The governor is the policy holder for the specifc domain
The cooling device is the agent used to cool the specific domain

The sensor, governor and cooling device are linked via the domain_name
entry in the thermal_dev structure.

Change-Id: I892e52d508dddf4320f7366e0eab3c706c2850bd
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>

Add OMAP on die temp sensor support

Add OMAP on die temp sensor support

Add the OMAP4 on-die temperature sensor support to
the thermal framework

Change-Id: I6b3a5e0de1620b229f2d6e61111da20f148bf7d8
Signed-off-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>

Fix panic on 4430 for the temp sensor idle

Fix panic on 4430 for the temp sensor idle

On 4430 the on-die temp sensor is not used.  But the CPU idle
path still calls the temp sensor idle.  This is not right

Only allow idle on 4460.

Change-Id: I1e9be21bc0d6d05c015d718121b04e01d905efb1
Signed-off-by: Dan Murphy <dmurphy@ti.com>

Update adc to temperature table and the table boundaries

Update adc to temperature table and the table boundaries

The adc value to temperature table is changed. Incorporating
the changes in the table and also changing the boundary values correspondigly.

Change-Id: I1505073269715385459a66d86560e2902f0476f8
Signed-off-by: Keerthy <j-keerthy@ti.com>

OMAP4 TEMP_SENSOR: Update the TSHUT configuration to a safer value

OMAP4 TEMP_SENSOR: Update the TSHUT configuration to a safer value

The configuration of THSUT_HOT value (where a thermal shutdown will occur)
shall take care of the temperature gradient that exists betwen the
on-die sensor and the OMAP hot spot temperature.
Thermal shutdown shall prevent the OMAP hot spot reaching 125C,
TSHUT_HOT (at on-die sensor level) shall be set at 110C.

Change-Id: I769f267c8dd659ea06282a1778b82698bda508b7
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

OMAP4 TEMP_SENSOR: Fix configurations of thresholds and associated masks

OMAP4 TEMP_SENSOR: Fix configurations of thresholds and associated masks

In omap_configure_temp_sensor_thresholds() function, the temporary variable
temp shall not be ORed as it is not always initialized to '0'. This leads
to incorrect configuration of BGAP_TSHUT_OFFSET register.

In omap_set_thresholds() function, the new thresholds are compared
to the current temperature to set/clear corresponding masks.
The current temperature shall be defined in "ADC" code instead of
milli-celsius degree. Otherwise, the comparison fails and the masks
are wrongly set.

Change-Id: Ia3939b2467edab3979513f1f8c48a68ab0d96ac4
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

OMAP4 TEMP_SENSOR: Removed unwanted save/restore of ctrl register

OMAP4 TEMP_SENSOR: Removed unwanted save/restore of ctrl register

This patch fixes issue with switching temperature sensor off after
resume from suspend.

Change-Id: I015a1f8c9a3168e7da518d068e0439aaa950e490
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

Thermal FW: Temp sensor: Update PM ops for runtime

Thermal FW: Temp sensor: Update PM ops for runtime

Update the pm runtime resume handler for context lost
scenario.

Change-Id: I6cf010a396d01e096c5a0a024f6ab12bb0c7f790
Signed-off-by: Dan Murphy <dmurphy@ti.com>

Staging: Temp sensor: Update the logging for missing func name

Staging: Temp sensor: Update the logging for missing func name

Change the logging for the clock on/off statement from err to debug
as this is not really an error.  Add the function name for debugging ease

Change-Id: I8fb5373914812ab10569de0e02d758ac034b95a5
Signed-off-by: Dan Murphy <dmurphy@ti.com>

OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds

OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds

Based on OMAP4460 experiment, it is safer to set values of the
TSHUT_HOT and TSHUT_COLD thresholds to 100 and 80 degrees Celsius
respectively.

CONTROL_TSHUT_THRESHOLD[25:16]	- TSHUT_HOT
CONTROL_TSHUT_THRESHOLD[9:0]	- TSHUT_COLD

Change-Id: Ie4263b74038e290ba593155b109d4802660e4243
Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>

Staging: Temp sensor: Update management of thresholds

Staging: Temp sensor: Update management of thresholds

On one side, the thermal governor reads the current temperature before
updating the temperature thresholds. On the other side, the OMAP temperature
sensor reads again the current temperature before updating the masks associated
to the temperature thresholds.
Race conditions may exist between both drivers if OMAP die temperature
changes between both temperature reads. Finally, temperature thresholds and
associated masks in OMAP Control Module could be misaligned. This may avoid the
generation of thermal events (temperature falls below cold threshold,
temperature rises above hot threshold) from HW logic: thermal manager will not
take appropriate actions (un-throttle CPU frequency when temperature falls;
throttle CPU frequency when temperature rises).

This patch removes the reading of current temperature from OMAP temperature
sensor driver when configuring the thresholds. This updated function relies
now on latest temperature reading done upon thermal alert irq generation.
In case of temperature thresholds setting through SYSFS entry, the
temperature reading is now added.

Change-Id: Id5f7fc3e83dc1d582dcadff5d8abc916a1588256
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

OMAP4 Thermal Framework: added PCB temperature sensor

This patch adds kernel driver for PCB temperature sensor
connected on TWL6030 GPADC (Thermistor).
It calls dedicated function to start GPADC conversion and
convert the result into milli-degrees celsius.

Change-Id: I7b573182611bda187f6a38dc01ba65935c8a5c4b
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>
modified for TUNA board by faux123

OMAP4 Thermal Framework: support multiple sensors per domain

OMAP4 Thermal Framework: support multiple sensors per domain

Current thermal framework implementation supports 1 temperature
sensor per thermal domain.
The OMAP CPU thermal governor needs to support OMAP and PCB temperature
sensors.
This patch updates the thermal framework to support multiple temperature
sensors per domain.
 - Added temperature report from sensors until at least 1 governor, 1 sensor and
1 cooling device are registered to the thermal framework to have pointers to
temperature sensor initialized at governor level.
 - Updated the thermal framework to allow getting temperature from multiple
temperature sensor and not only the last registered one.

Change-Id: I201ffdeaf3ef18ab17ec84ad8c833b9fc074f4f1
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

Revert "OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds"

Revert "OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds"

This patches revert commit 24e7232d9d0ad7c3ac6520c7131b82e75d8f166d.
TSHUT_HOT value was decreased to be safe without the support of
PCB temp sensor into the OMAP thermal management.
Some thermal shutdown are observed when integrating the PCB sensor
into the thermal policy and decreasing the TSHUT_HOT value.
As recommended solution is to use an external PCB temp sensor,
it is better to revert the initial patch.

Change-Id: I27ddf08fab5cdedef7b9537fc934694a5b19954f
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

OMAP4: TEMP_SENSOR: Additional checking for context lost scenario

OMAP4: TEMP_SENSOR: Additional checking for context lost scenario

Calling pm_runtime_get_sync() function during driver initialization
leads to formation of the resume request, which will restore
registers values using not yet initialized data.

To prevent invalid data writing into registers at the early
stage of booting, additional checking has been added.

Change-Id: Ia14368ef1dd8430b8ba561bede0da7d46d9efb0e
Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>

OMAP4470: TEMP_SENSOR: Fatal threshold hardware warm reset generation

OMAP4470: TEMP_SENSOR: Fatal threshold hardware warm reset generation

On 4470 the TSHUT signal can be mapped to the device SCRM external
warm reset logic to activate the PRM.SYS_WARMIN_RST input
when a fatal temperature threshold (TSHUT_HOT) is exceeded.
Hence, a hardware warm reset can be triggered directly on
the device upon a fatal temperature threshold crossing event.

Since this feature have been added for 4470, shutdown thresholds
can be set earlier. So, additional checking has been added to prevent
multiple writing to one time writable register.

Also this patch add corresponding sysfs debug hook functions to
enable/disable hardware reset feature.

Change-Id: I260e16e2808fddc0ecb06211a74aced8c4b12a5d
Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>

OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds

OMAP4: TEMP_SENSOR: Tuning values of TSHUT-thresholds

Based on OMAP4460 experiment, it is safer to set values of the
TSHUT_HOT and TSHUT_COLD thresholds to 100 and 80 degrees Celsius
respectively.

CONTROL_TSHUT_THRESHOLD[25:16]	- TSHUT_HOT
CONTROL_TSHUT_THRESHOLD[9:0]	- TSHUT_COLD

Change-Id: Ie4263b74038e290ba593155b109d4802660e4243
Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>

OMAP4470: TEMP_SENSOR: Thermal sensor support for 4470

OMAP4470: TEMP_SENSOR: Thermal sensor support for 4470

Thermal sensor support is required by a new chip.

Add runtime checking for 4470 to allow usage of
thermal sensor.

Change-Id: I231826df11315a27d6174a8791c578a5abbb4257
Signed-off-by: Leonid Iziumtsev <x0153368@ti.com>

OMAP4: TEMP_SENSOR: Add missing carriage returns in print-function call

OMAP4: TEMP_SENSOR: Add missing carriage returns in print-function call

Due to missing carriage return in print-functions calls
sometimes it's hard to read kernel log.
Fix this so now kernel log reading is more easy.

Change-Id: I399c12f38a8e685ea19c7f79d930fa6ffc59511f
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>

ARM:OMAP4:Temp sensor: Fixed context restoration of OMAP temp sensor

ARM:OMAP4:Temp sensor: Fixed context restoration of OMAP temp sensor

Spurious thermal alert interrupt is generated when restoring the context
of OMAP temperature sensor driver upon a wake-up from CORE OSWRet/OFF modes.
This spurious interrupt is due to the fact that current SW implementation
restores all HW registers without any specific sequence.
Finally, the thermal alert interrupt handler prints error message because
the temperature reported by the sensor is invalid.

This patch applies a SW sequence taking into the HW constraints to avoid
the generation of cold thermal alert.
HW constraints:
- The HW logic decrements the counter and then starts the temperature
measurement.
- An immediate temperature measurement is possible only if counter is set to
low value.
- The HW logic compares the BGAP_TEMP_SENSOR_DTEMP bitfield with threshold as
soon as the clock is enabled.
- To avoid spurious interrupt, it is mandatory to unmask interrupts (cold
and/or hot) when BGAP_TEMP_SENSOR_DTEMP bitfield is different than 0.
- if BGAP_TEMPSOFF bit sit set, then the sensor is stopped and returns 0.

New SW implementation:
1/ If all registers have been reset:
- Force immediate temperature measurement and wait until
BGAP_TEMP_SENSOR_DTEMP bitfield is updated before completing the full context
restoration.
- Ensure that the BGAP_TEMPSOFF bit is not set to 1 during context restoration.
- Complete the context restoration (mask bits and counter).
2/ If registers have not been reset:
- clears TEMPSOFF bit
- Force immediate temperature measurement and wait until
BGAP_TEMP_SENSOR_DTEMP bitfield is different than 0.

Change-Id: I6e18e2882107b93cccee8fc20f7052994565a40d
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

ARM:OMAP4:Temp sensor: Keep constant sampling rate

ARM:OMAP4:Temp sensor: Keep constant sampling rate

The HW control module uses an internal counter to start periodic
temperature measurement. This HW internal counter is incrementing from
0 to the value of CONTROL_BANDGAP_COUNTER register.
If SW decreases the value in CONTROL_BANDGAP_COUNTER to a value lower than
the current internal counter, then HW logic will increment the internal
counter until its maximum value (coded on 24-bits) and start a new
temperature measurement when internal counter reaches again the new value
from CONTROL_BANDGAP_COUNTER register.
Finally, the next temperature measurement could be delayed by 10 to 20
seconds.

As there is no way to reset this internal counter or to read the intern
counter, the only valid workaround is to keep a constant value in
CONTROL_BANDGAP_COUNTER register and ensure that SW never changes.
This patch uses 250 ms whatever is the thermal zone.

Change-Id: I139a1205e4eb06a558e6442e1c78e83a8c75f0df
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

Thermal Governor: OMAP4: cancel work task while suspending.

Thermal Governor: OMAP4: cancel work task while suspending.

Cancel work task while going to suspend and re-schedule after
resume.

Fixes:
	[  331.767303] CPU1: shutdown
	[  331.768310] Resume caused by I/O pad:
	CONTROL_PADCONF_WAKEUPEVENT_4[2]
	[  331.768310]    PD_CORE curr=ON prev=ON logic=ON
	[  331.768310]    PD_L4_PER curr=ON prev=ON logic=ON
	[  331.768310]          I2C1 mode=ENABLED idlest=ON

Change-Id: Ie69f404305e678e93c7b32ddff6ca536b0c9eed3
Tested-by: Ramajayam S <ramajayam.samudi@ti.com>
Signed-off-by: Ambresh K <ambresh@ti.com>

TI Thermal Governor: Updated the parameters for OMAP hot spot extrapolation

TI Thermal Governor: Updated the parameters for OMAP hot spot extrapolation

Due to a different OMAP die size between OMAP4460 and OMAP4470, the parameters
used to extrapolate the hot spot temperature from
the on-die sensor and the PCB sensor are different between 4460 and 4470.
When running thermal simulations, it appears that current parameters used on
OMAP4460 are not optimal.

This patch adds the capability to select the slope/const parameters according
to the OMAP44xx silicon revision and aligns these parameters with latest thermal
simulations (28th March 2012).

Change-Id: I828291504f6a23a1640c589af2d4913cf00f9745
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

TI thermal framework: Remove unused index

TI thermal framework: Remove unused index

This patch removes index information as it is never used.

Change-Id: Ic2bfb1677d8fec2cafa7b47626deb432232a0ef6
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: improve thermal domain manipulations

TI thermal framework: improve thermal domain manipulations

This patch changes the thermal device data structures
to have a pointer to thermal domain. This way, once
an operation is required on a thermal device, there is
no need to iterate on thermal domains lists.

This patch also centralizes the operations to search and create
thermal domain data structures. Idea is to improve code readability,
having these operations done in one place only.

The patch does not change the code functionality so far.

Change-Id: I482d82feac854270c300273efbef0ef07cdec0b2
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: release allocated memory for thermal domains

TI thermal framework: release allocated memory for thermal domains

Upon module exit, release all memory allocated on thermal domains.

Change-Id: I74640cc9a9b74dd9cd0a62253ca2444bd00ac31b
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: No need to return on end of void functions

TI thermal framework: No need to return on end of void functions

Remove unnecessary return at the end of void functions

Change-Id: I6e53e8c1d7b7d33e867b836013a0fecb3f38a3c1
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: standardize thermal device ops

TI thermal framework: standardize thermal device ops

This patch changes the .process_temp callback of governor
type of thermal devices. The aim is to make all callbacks
standard. Now, all callbacks receive as first parameter
the affected thermal device.

Change-Id: I9857146e852a7f7d6ac502d044b7f104aa7eb466
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: introduce thermal_device_call helper macro

TI thermal framework: introduce thermal_device_call helper macro

This patch adds a helper macro to call thermal device callback
functions. It will include some pointer checks before calling
the callback. In case the pointer checks fails, it will return
-EOPNOTSUPP, otherwise the callback return value.

The patch also improves the thermal framework core code by
using this helper macro.

Change-Id: I7db80271ec2509eb14670ae04532cff06cdf002c
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: remove unnecessary checks on thermal domain list

TI thermal framework: remove unnecessary checks on thermal domain list

The domain can be fetch from each thermal device. Because of that,
there is no need to check for the emptiness of thermal domain list.

Change-Id: I786b82f6353711c376bcfcb24d0cca5eeb96a8d3
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: avoid free memory not allocated by the fw

TI thermal framework: avoid free memory not allocated by the fw

Because the objects passed to the thermal framework are already
allocated, it does not make sense to free them inside the thermal
framework. This patch removes all memory release calls to memory
areas not owned by the thermal framework.

Change-Id: Ie49e99b7f6285cf435f5eab7ad26a61257ed86df
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: add helper macro to call ops on several thermal devices

TI thermal framework: add helper macro to call ops on several thermal devices

This patch introduces a helper macro to execute same callback of several
thermal devices, linked by a list. It will attempt to reach all devices,
even if some of them are missing the callback or if the callback is
returning error values.

Because of the introduction of this helper, there is no need to have
a specific function to set the cooling level on a list of cooling devices.

Change-Id: I430a885400c17b81e98736c9a0ca1b675493b610
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: translate sensor helper functions into macro helpers

TI thermal framework: translate sensor helper functions into macro helpers

This patch removes helper functions operations that can be resolved by
the existing helper macros.

Change-Id: I11c8d2efc45c14bacffcddac944afddbc456e3e0
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: omap die governor: simplify the cooling device search

TI thermal framework: omap die governor: simplify the cooling device search

Inside each zone entering function, there is a search for cooling devices.
This search is not really needed as the registered devices are already
supposed to be part of that thermal zone. The checks for the missing pointers
are done by the caller macro helper.

Change-Id: I4a227933f3b7c723675007c5b7dc7d3ce1ec1ac6
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: omap die governor: introduce enter zone helper function

TI thermal framework: omap die governor: introduce enter zone helper function

This code changes the OMAP DIE governor to use a helper function to enter
a thermal zone, instead of using a function for each zone. Idea is to
reduce the amount of duplicated code.

This code also introduces a data structure to represent a thermal zone.
The enter zone helper function is based on this data structure.

The logic alert zone logic computation, which depends on if we
are rising or lowering in temperature, is now moved to the zone
matching function. This place is much more convenient, then inside
the enter zone helper.

Change-Id: Ibcb9228556c793104d2ec6f8df092a1c7ea99966
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: set temperature when domain is ready

TI thermal framework: set temperature when domain is ready

Instead of reading domain temperature when a domain is ready,
this patch changes the flow to set the temperature. Now,
the temperature will be report to the governor when its domain
is ready with all needed pieces: sensor, governor, cooling agents.

Change-Id: I680bd6ff535dbe452d7b6cb9562594fa37826148
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: introduce thermal_lookup_temp function

TI thermal framework: introduce thermal_lookup_temp function

This patch adds a helper function to get temperature of
a thermal domain, based on the domain name.

It will perform a domain name lookup and use its thermal
sensor device to fetch the temperature. If the domain
is not ready to report temperature, it will return an
error code.

Change-Id: I55d173c686e61650cb3a18ff4ae434711f2ebf37
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

DRIVERS: MISC: Add OMAP4430 Static Thermal Policy

Adding Static Thermal Policy for OMAP4430.
Added new driver module to control max opp duty cycle.

Change-Id: I9781f4db19b055eefb0a4bf28bf5f5c516307509
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
modified for Tuna board by faux123

DRIVERS: MISC: move DC from misc to thermal_framework

We have special place for thermal framework. Duty cycle was placed
to separate place. The patch moves DC to thermal_framework place.

Change-Id: Id1e85d853df2fbbd597a5dd87e658fce58e4ae24
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
modified for TUNA by faux123

Thermal Governor: Added duty cycle governor

board/omap2plus: add missing thermal framework code from OMAPZOOM.org

DRIVERS: MISC: change the DC cpufreq control to TF control

Duty cycle uses sys fs to control cpufreq. It is not safe.
The user(overclocker) can burn the device using simple script that
changes max_frequency. The thermal framework has own mechanism for
this and the patch changes the duty cycle mechanism to thermal
framework variant of cpufreq control.

Change-Id: Ifc0f8b81addb7524eb67d116e4780978739a67f3
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
modified for TUNA board by faux123

board/omap2plus: fix duty cycle cooling coding error

TI thermal framework: register cpufreq cooling device in module init

TI thermal framework: register cpufreq cooling device in module init

the CPUfreq cooling device is being registered in the wrong place.
We don't want to register a cooling device every time a CPU is
initialized. This is fundamentally wrong. Thus, this patch moves
the cooling device registration to module init instead.

Change-Id: I7886eb14c68e1bf696ef77e86326a62ea05b8c8b
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

ARM:OMAP4:Thermal Framework:added TMP102 temperature sensor

ARM:OMAP4:Thermal Framework:added TMP102 temperature sensor

This patch adds kernel driver for TMP102 temperature sensor
TMP102 is controled through I2C bus.

Change-Id: I4012a0ab53945ad8a240f395bb321cf09ebeb3ea
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>

TI thermal framework: fix initialization sequence and introduce "pcb" domain

TI thermal framework: fix initialization sequence and introduce "pcb" domain

This patch creates a new thermal domain, named "pcb". Also it teaches
the omap die governor how to be aware of a separated domain.

The pcb sensor will not be part of the "cpu" domain, but instead, it
is now part of the "pcb" domain. This will change the system so that,
instead of wrongly attempt to register two sensors on the same domain,
they will be registered on two different domains, but the governor
is aware of both domains.

By doing so, it is not necessary to keep track of sensors being
registered on the same domain, and deciding by looking up the
sensor names.

Now that governors can fetch the temperature from a different domain,
there is no need to keep feeding the framework with temperature reports
by means of running workqueues. This workaround was necessary
because there was an initialization issue while registering several
sensors in the same domain.

Now, because there are multiple domains, there is no need to keep
track on sensors being registered and their reports. For now,
these workqueues are not needed.

Change-Id: I6e2764fc1d49fbe97953c2a9a5192f8585c91aab
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI thermal framework: introduce the thermal framework debug capability

TI thermal framework: introduce the thermal framework debug capability

This is a initial implementation of the TI thermal framework debug entries.

As of now, the structure is like this:
<debugfs_dir>
  |- thermal_debug
      |- domains
          |- <domain_name file 0>
          .
          .
          .
          |- <domain_name file n>
      |- devices
          |- device_name 0
          |    |- <device_name 0 own entries>
          .
          .
          .
          |- device_name n
          |    |- <device_name 0 own entries>

Each domain_name file contains a report of the its corresponding domain, e.g.:

 # cat /sys/kernel/debug/thermal_debug/cpu
Domain name: cpu
Temperature sensor:
     Name: omap_ondie_sensor
     Current temperature: 62400
Governor:
     Name: omap_ondie_governor
Cooling agents:
     Name: cpufreq_cooling

Each thermal device participating in a specific thermal domain
will have the opportunity to report their own specific debug
entries on this debug file for that domain. This is achieved
by means of the new thermal device ops callback .debug_report
which receives the target seq file.

Besides, each device registered in this framework will also
have the opportunity to create its own debug entries (directories
or files) under a directory with its name under the "devices"
directory. This is achieved by means of the .register_debug_entries
callback function.

Because we have now a debugfs dependency, this framework is
now initialized by means of the fs_initcall. This way
it will be ready before any registration of thermal devices.

Change-Id: I8b2d861a9263baa2d8af9c6a5edf07a8cfb88388
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

TI TFW: omap die governor:fix for staying in PANIC zone

TI TFW: omap die governor:fix for staying in PANIC zone

the OMAP4470 more heats up. The patch adds timer which
helps to avoid staying in PANIC zone too long time.

patch realises following algorithm

1. panic_zone_reached == 1;
2. schedule work to be executed after 2s;
3. scheduled work will cancelled if zone will be changed through 2s;
4. after 2s executes scheduled work
5. panic_zone_reached == 2;
6. schedule work to be executed after 4s relative to point 1
7. etc

Change-Id: Ide8bd588b0bf504e2378b5a655fefdeee51c90b1
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>

OMAP4 CPU Thermal governor:removes repetitive info

OMAP4 CPU Thermal governor:removes repetitive info

The thermal governor prints info after each crossing of a thermal treshold.
Often treshold is crossed but thermal zone was not changed. The printed info
to clogs a console and dosen't give an effective information. The patch
removes repetitive info for all zone except for the panic zone. The
panic zone is critical and a duplicate info must be.

Change-Id: I278a938b615296264446fe7d5b209021ec0121c0
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>

TI thermal framework: rework initialization sequence

TI thermal framework: rework initialization sequence

The duty cooling device is being registered in the
wrong place. We don't want to register a cooling device
every time a CPU is initialized.  Thus, this patch moves
the cooling device registration to module init instead.

Change-Id: Ib3cf55e8dde719c5736b201d9682ff515d2b1399
Signed-off-by: Eugen Mandrenko <ievgen.mandrenko@ti.com>
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>

Staging Thermal FW: PCB Temp Sensor: Fix management of ADC conversion

Staging Thermal FW: PCB Temp Sensor: Fix management of ADC conversion

When an NTC thermistor is connected to the TWL6030 GPADC Channel #4,
twl6030_gpadc_conversion() function (from twl6030-gpadc driver) is
invoked.
This function stores different results into twl6030_gpadc_request
structure.
The PCB temp sensor driver shall use the ADC code instead of the
converted voltage value.
Later, the PCB temp sensor convert the ADC code into temperature
through a dedicated lookup table.

Change-Id: I1582e96035797f8c0dd6e529c65160a71e54cd6a
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

ARM:OMAP4:Temp sensor: fix low limit for thresholds

ARM:OMAP4:Temp sensor: fix low limit for thresholds

As the full temperature range is -40 DegC to 125 Deg C,
this patch ensures that thresholds are higher than the low
limit (-40 Deg C) instead of 0 Deg C.

Change-Id: I28c49cd53703f9d9ed61458bc61612f4dbb476bb
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>

ARM:OMAP4:Temp Sensor: Define TALERT_IRQ as High level interrupt sensitive

ARM:OMAP4:Temp Sensor: Define TALERT_IRQ as High level interrupt sensitive

The thermal alert IRQ is registered as a threaded IRQ with TRIGGER_RISING and
ONESHOT flags.
This means that omap_talert_irq_handler() IRQ handler will be called upon a
rising edge of the T_ALERT (HW signal coming from HW comparison of current
temperature with hot & cold thresholds).
This means also that the irq line is disabled until the threaded handler has
been run (due to ONESHOT flag): the T_ALERT IRQ is masked at GIC level during
the threaded handler execution.
Any new thermal event occurring during the execution of the threaded handler
will not be detected. This may occur if OMAP on-die temperature variations are
fast and if the T_ALERT IRQ handler is delayed by higher priority interrupts.
Finally, the thermal governor is not informed of the new event and could
maintain incorrect constraints on CPU frequency for example.

This patch defines the TALERT_IRQ as TRIGGER_HIGH interrupt instead of
TRIGGER_RISING interrupt. Even if interrupt line is disabled during the handler
execution, HW will maintain the T_ALERT signal to high level if a second thermal
event occurs. When re-enabling the interrupt line, the omap_talert_irq_handler()
IRQ handler will be called again if needed.

Change-Id: I629d5a66702fb60b5f96773c717a2d87238dff2c
Signed-off-by: Sebastien Sabatier <s-sabatier1@ti.com>