staging: omap-thermal: several code refactoring
cover staging: omap-thermal: several code refactoring
Hello Greg,
Here is a series of patches improving the way the omap-thermal driver is written. There is a mix of added documentation, with functions rewrites and cleanups regarding coding style. I am also adding myself as maintainer of this driver.
Next I will be still improving the code in this way, but also working on the policy readiness and testing on other devices. I will probably rename the driver also to something that reflect the support to AMxx devices as well.
Hopefully, it should be soon ready for moving to drivers/thermal/.
All these are based on your staging/staging-next branch.
For those interested in testing and trying the driver, these patches are
also available, as usual, here:
[email protected]:thermal-framework/thermal-framework.git thermal_work/omap/omap-thermal-optimizations
https://git.gitorious.org/thermal-framework/thermal-framework.git thermal_work/omap/omap-thermal-optimizations
For lo guys, I will appreciate your testing results on other devices.
Cheers,
Eduardo Valentin (50):
staging: omap-thermal: use BIT() macro
staging: omap-thermal: remove unused _SHIFT macros
staging: omap-thermal: create header for register, bitfields and
definitions
staging: omap-thermal: update documentation of omap-bandgap.h
staging: omap-thermal: style cleanup on omap-bandgap.c
staging: omap-thermal: fix error checking
staging: omap-thermal: introduce RMW_BITS macro
staging: omap-thermal: add documentation for register access
functions
staging: omap-thermal: make a omap_bandgap_power with only one exit
point
staging: omap-thermal: add documentation for omap_bandgap_power
staging: omap-thermal: add documentation for omap_bandgap_read_temp
staging: omap-thermal: rename talert handler
staging: omap-thermal: update documentation for talert irq handler
staging: omap-thermal: update tshut IRQ handler documentation
staging: omap-thermal: remove duplicated code
staging: omap-thermal: read status only once inside alert IRQ
staging: omap-thermal: add a section of register manipulation
staging: omap-thermal: section of basic helpers
staging: omap-thermal: IRQ handler section
staging: omap-thermal: ADC section
staging: omap-thermal: name adc_to_temp_conversion in a better way
staging: omap-thermal: rewrite omap_bandgap_adc_to_mcelsius on kernel
coding style
staging: omap-thermal: add documentation for
omap_bandgap_adc_to_mcelsius
staging: omap-thermal: name temp_to_adc_conversion in a better way
staging: omap-thermal: rewrite omap_bandgap_mcelsius_to_adc on kernel
coding style
staging: omap-thermal: move conv table limits out of sensor data
staging: omap-thermal: add documentation for
omap_bandgap_mcelsius_to_adc
staging: omap-thermal: rename add_hyst to omap_bandgap_add_hyst
staging: omap-thermal: document omap_bandgap_add_hyst function
staging: omap-thermal: threshold manipulation section
staging: omap-thermal: refactor temp_sensor_unmask_interrupts
staging: omap-thermal: update omap_bandgap_unmask_interrupts
documentation
staging: omap-thermal: refactor APIs handling threshold values
staging: omap-thermal: device initialization section
staging: omap-thermal: section of device driver callbacks
staging: omap-thermal: rename enable_continuous_mode
staging: omap-thermal: update omap_bandgap_set_continous_mode
documentation
staging: omap-thermal: document omap_bandgap_force_single_read
staging: omap-thermal: document omap_bandgap_update_alert_threshold
function
staging: omap-thermal: document _omap_bandgap_write_threshold
function
staging: omap-thermal: document _omap_bandgap_read_threshold function
staging: omap-thermal: document omap_bandgap_tshut_init function
staging: omap-thermal: document omap_bandgap_alert_init function
staging: omap-thermal: document omap_bandgap_build function
staging: omap-thermal: change Kconfig dependency method
staging: Add a MAINTAINERS entry for TI bandgap and thermal driver
staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
staging: omap-thermal: remove TODO entry suggesting regmap usage
staging: omap-thermal: remove TODO entry for exposed APIs
staging: omap-thermal: add documentation for omap_bandgap_validate
MAINTAINERS | 6 + drivers/staging/omap-thermal/Kconfig | 2 +- drivers/staging/omap-thermal/TODO | 4 - drivers/staging/omap-thermal/omap-bandgap.c | 793 +++++++++++--------- drivers/staging/omap-thermal/omap-bandgap.h | 498 +++++-------- drivers/staging/omap-thermal/omap-thermal-common.c | 4 +- drivers/staging/omap-thermal/omap4-thermal-data.c | 11 +- drivers/staging/omap-thermal/omap4xxx-bandgap.h | 175 +++++ drivers/staging/omap-thermal/omap5-thermal-data.c | 9 +- drivers/staging/omap-thermal/omap5xxx-bandgap.h | 199 +++++ 10 files changed, 1030 insertions(+), 671 deletions(-) create mode 100644 drivers/staging/omap-thermal/omap4xxx-bandgap.h create mode 100644 drivers/staging/omap-thermal/omap5xxx-bandgap.h
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 1/50 staging: omap-thermal: use BIT() macro
For code readability, this patch changes the bit definition under omap-bandgap.h to use the BIT() macro.
--- drivers/staging/omap-thermal/omap-bandgap.h | 96 +++++++++++++------------- 1 files changed, 48 insertions(+), 48 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.h +48 -48
@@ -29,17 +29,17 @@/* TEMP_SENSOR OMAP4430 */ #define OMAP4430_BGAP_TSHUT_SHIFT 11 -#define OMAP4430_BGAP_TSHUT_MASK (1 << 11) +#define OMAP4430_BGAP_TSHUT_MASK BIT(11)/* TEMP_SENSOR OMAP4430 */ #define OMAP4430_BGAP_TEMPSOFF_SHIFT 12 -#define OMAP4430_BGAP_TEMPSOFF_MASK (1 << 12) +#define OMAP4430_BGAP_TEMPSOFF_MASK BIT(12)#define OMAP4430_SINGLE_MODE_SHIFT 10 -#define OMAP4430_SINGLE_MODE_MASK (1 << 10) +#define OMAP4430_SINGLE_MODE_MASK BIT(10)#define OMAP4430_BGAP_TEMP_SENSOR_SOC_SHIFT 9 -#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK (1 << 9) +#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK BIT(9)#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 8 -#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 8) +#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(8)#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK (0xff << 0)
@@ -53,21 +53,21 @@/* TEMP_SENSOR OMAP4460 */ #define OMAP4460_BGAP_TEMPSOFF_SHIFT 13 -#define OMAP4460_BGAP_TEMPSOFF_MASK (1 << 13) +#define OMAP4460_BGAP_TEMPSOFF_MASK BIT(13)#define OMAP4460_BGAP_TEMP_SENSOR_SOC_SHIFT 11 -#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK (1 << 11) +#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK BIT(11)#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10 -#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 10) +#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10)#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)/* BANDGAP_CTRL */ #define OMAP4460_SINGLE_MODE_SHIFT 31 -#define OMAP4460_SINGLE_MODE_MASK (1 << 31) +#define OMAP4460_SINGLE_MODE_MASK BIT(31)#define OMAP4460_MASK_HOT_SHIFT 1 -#define OMAP4460_MASK_HOT_MASK (1 << 1) +#define OMAP4460_MASK_HOT_MASK BIT(1)#define OMAP4460_MASK_COLD_SHIFT 0 -#define OMAP4460_MASK_COLD_MASK (1 << 0) +#define OMAP4460_MASK_COLD_MASK BIT(0)/* BANDGAP_COUNTER */ #define OMAP4460_COUNTER_SHIFT 0
@@ -87,57 +87,57 @@/* BANDGAP_STATUS */ #define OMAP4460_CLEAN_STOP_SHIFT 3 -#define OMAP4460_CLEAN_STOP_MASK (1 << 3) +#define OMAP4460_CLEAN_STOP_MASK BIT(3)#define OMAP4460_BGAP_ALERT_SHIFT 2 -#define OMAP4460_BGAP_ALERT_MASK (1 << 2) +#define OMAP4460_BGAP_ALERT_MASK BIT(2)#define OMAP4460_HOT_FLAG_SHIFT 1 -#define OMAP4460_HOT_FLAG_MASK (1 << 1) +#define OMAP4460_HOT_FLAG_MASK BIT(1)#define OMAP4460_COLD_FLAG_SHIFT 0 -#define OMAP4460_COLD_FLAG_MASK (1 << 0) +#define OMAP4460_COLD_FLAG_MASK BIT(0)/* TEMP_SENSOR OMAP5430 */ #define OMAP5430_BGAP_TEMP_SENSOR_SOC_SHIFT 12 -#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK (1 << 12) +#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK BIT(12)#define OMAP5430_BGAP_TEMPSOFF_SHIFT 11 -#define OMAP5430_BGAP_TEMPSOFF_MASK (1 << 11) +#define OMAP5430_BGAP_TEMPSOFF_MASK BIT(11)#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10 -#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK (1 << 10) +#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10)#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)/* BANDGAP_CTRL */ #define OMAP5430_MASK_HOT_CORE_SHIFT 5 -#define OMAP5430_MASK_HOT_CORE_MASK (1 << 5) +#define OMAP5430_MASK_HOT_CORE_MASK BIT(5)#define OMAP5430_MASK_COLD_CORE_SHIFT 4 -#define OMAP5430_MASK_COLD_CORE_MASK (1 << 4) +#define OMAP5430_MASK_COLD_CORE_MASK BIT(4)#define OMAP5430_MASK_HOT_GPU_SHIFT 3 -#define OMAP5430_MASK_HOT_GPU_MASK (1 << 3) +#define OMAP5430_MASK_HOT_GPU_MASK BIT(3)#define OMAP5430_MASK_COLD_GPU_SHIFT 2 -#define OMAP5430_MASK_COLD_GPU_MASK (1 << 2) +#define OMAP5430_MASK_COLD_GPU_MASK BIT(2)#define OMAP5430_MASK_HOT_MPU_SHIFT 1 -#define OMAP5430_MASK_HOT_MPU_MASK (1 << 1) +#define OMAP5430_MASK_HOT_MPU_MASK BIT(1)#define OMAP5430_MASK_COLD_MPU_SHIFT 0 -#define OMAP5430_MASK_COLD_MPU_MASK (1 << 0) +#define OMAP5430_MASK_COLD_MPU_MASK BIT(0)#define OMAP5430_MASK_SIDLEMODE_SHIFT 30#define OMAP5430_MASK_SIDLEMODE_MASK (0x3 << 30)#define OMAP5430_MASK_FREEZE_CORE_SHIFT 23 -#define OMAP5430_MASK_FREEZE_CORE_MASK (1 << 23) +#define OMAP5430_MASK_FREEZE_CORE_MASK BIT(23)#define OMAP5430_MASK_FREEZE_GPU_SHIFT 22 -#define OMAP5430_MASK_FREEZE_GPU_MASK (1 << 22) +#define OMAP5430_MASK_FREEZE_GPU_MASK BIT(22)#define OMAP5430_MASK_FREEZE_MPU_SHIFT 21 -#define OMAP5430_MASK_FREEZE_MPU_MASK (1 << 21) +#define OMAP5430_MASK_FREEZE_MPU_MASK BIT(21)#define OMAP5430_MASK_CLEAR_CORE_SHIFT 20 -#define OMAP5430_MASK_CLEAR_CORE_MASK (1 << 20) +#define OMAP5430_MASK_CLEAR_CORE_MASK BIT(20)#define OMAP5430_MASK_CLEAR_GPU_SHIFT 19 -#define OMAP5430_MASK_CLEAR_GPU_MASK (1 << 19) +#define OMAP5430_MASK_CLEAR_GPU_MASK BIT(19)#define OMAP5430_MASK_CLEAR_MPU_SHIFT 18 -#define OMAP5430_MASK_CLEAR_MPU_MASK (1 << 18) +#define OMAP5430_MASK_CLEAR_MPU_MASK BIT(18)#define OMAP5430_MASK_CLEAR_ACCUM_CORE_SHIFT 17 -#define OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK (1 << 17) +#define OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK BIT(17)#define OMAP5430_MASK_CLEAR_ACCUM_GPU_SHIFT 16 -#define OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK (1 << 16) +#define OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK BIT(16)#define OMAP5430_MASK_CLEAR_ACCUM_MPU_SHIFT 15 -#define OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK (1 << 15) +#define OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK BIT(15)/* BANDGAP_COUNTER */ #define OMAP5430_COUNTER_SHIFT 0
@@ -169,19 +169,19 @@/* BANDGAP_STATUS */ #define OMAP5430_BGAP_ALERT_SHIFT 31 -#define OMAP5430_BGAP_ALERT_MASK (1 << 31) +#define OMAP5430_BGAP_ALERT_MASK BIT(31)#define OMAP5430_HOT_CORE_FLAG_SHIFT 5 -#define OMAP5430_HOT_CORE_FLAG_MASK (1 << 5) +#define OMAP5430_HOT_CORE_FLAG_MASK BIT(5)#define OMAP5430_COLD_CORE_FLAG_SHIFT 4 -#define OMAP5430_COLD_CORE_FLAG_MASK (1 << 4) +#define OMAP5430_COLD_CORE_FLAG_MASK BIT(4)#define OMAP5430_HOT_GPU_FLAG_SHIFT 3 -#define OMAP5430_HOT_GPU_FLAG_MASK (1 << 3) +#define OMAP5430_HOT_GPU_FLAG_MASK BIT(3)#define OMAP5430_COLD_GPU_FLAG_SHIFT 2 -#define OMAP5430_COLD_GPU_FLAG_MASK (1 << 2) +#define OMAP5430_COLD_GPU_FLAG_MASK BIT(2)#define OMAP5430_HOT_MPU_FLAG_SHIFT 1 -#define OMAP5430_HOT_MPU_FLAG_MASK (1 << 1) +#define OMAP5430_HOT_MPU_FLAG_MASK BIT(1)#define OMAP5430_COLD_MPU_FLAG_SHIFT 0 -#define OMAP5430_COLD_MPU_FLAG_MASK (1 << 0) +#define OMAP5430_COLD_MPU_FLAG_MASK BIT(0)/* Offsets from the base of temperature sensor registers */
@@ -434,14 +434,14 @@ struct omap_temp_sensor {* @expose_sensor: callback to export sensor to thermal API */ struct omap_bandgap_data { -#define OMAP_BANDGAP_FEATURE_TSHUT (1 << 0) -#define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG (1 << 1) -#define OMAP_BANDGAP_FEATURE_TALERT (1 << 2) -#define OMAP_BANDGAP_FEATURE_MODE_CONFIG (1 << 3) -#define OMAP_BANDGAP_FEATURE_COUNTER (1 << 4) -#define OMAP_BANDGAP_FEATURE_POWER_SWITCH (1 << 5) -#define OMAP_BANDGAP_FEATURE_CLK_CTRL (1 << 6) -#define OMAP_BANDGAP_FEATURE_FREEZE_BIT (1 << 7) +#define OMAP_BANDGAP_FEATURE_TSHUT BIT(0) +#define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG BIT(1) +#define OMAP_BANDGAP_FEATURE_TALERT BIT(2) +#define OMAP_BANDGAP_FEATURE_MODE_CONFIG BIT(3) +#define OMAP_BANDGAP_FEATURE_COUNTER BIT(4) +#define OMAP_BANDGAP_FEATURE_POWER_SWITCH BIT(5) +#define OMAP_BANDGAP_FEATURE_CLK_CTRL BIT(6) +#define OMAP_BANDGAP_FEATURE_FREEZE_BIT BIT(7)#define OMAP_BANDGAP_HAS (b, f) \ ((b)->conf->features & OMAP_BANDGAP_FEATURE_ ## f)unsigned int features;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 2/50 staging: omap-thermal: remove unused _SHIFT macros
In reply to Eduardo ValentinAs these macros are not used on any part of the code, this patch removes all the *_SHIT defines.
--- drivers/staging/omap-thermal/omap-bandgap.h | 57 --------------------------- 1 files changed, 0 insertions(+), 57 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.h +0 -57
@@ -28,19 +28,13 @@#include <linux/err.h> /* TEMP_SENSOR OMAP4430 */ -#define OMAP4430_BGAP_TSHUT_SHIFT 11#define OMAP4430_BGAP_TSHUT_MASK BIT(11)/* TEMP_SENSOR OMAP4430 */ -#define OMAP4430_BGAP_TEMPSOFF_SHIFT 12#define OMAP4430_BGAP_TEMPSOFF_MASK BIT(12) -#define OMAP4430_SINGLE_MODE_SHIFT 10#define OMAP4430_SINGLE_MODE_MASK BIT(10) -#define OMAP4430_BGAP_TEMP_SENSOR_SOC_SHIFT 9#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK BIT(9) -#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 8#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(8) -#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK (0xff << 0)#define OMAP4430_ADC_START_VALUE 0
@@ -52,135 +46,84 @@#define OMAP4430_HYST_VAL 5000/* TEMP_SENSOR OMAP4460 */ -#define OMAP4460_BGAP_TEMPSOFF_SHIFT 13#define OMAP4460_BGAP_TEMPSOFF_MASK BIT(13) -#define OMAP4460_BGAP_TEMP_SENSOR_SOC_SHIFT 11#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK BIT(11) -#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10) -#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)/* BANDGAP_CTRL */ -#define OMAP4460_SINGLE_MODE_SHIFT 31#define OMAP4460_SINGLE_MODE_MASK BIT(31) -#define OMAP4460_MASK_HOT_SHIFT 1#define OMAP4460_MASK_HOT_MASK BIT(1) -#define OMAP4460_MASK_COLD_SHIFT 0#define OMAP4460_MASK_COLD_MASK BIT(0)/* BANDGAP_COUNTER */ -#define OMAP4460_COUNTER_SHIFT 0#define OMAP4460_COUNTER_MASK (0xffffff << 0)/* BANDGAP_THRESHOLD */ -#define OMAP4460_T_HOT_SHIFT 16#define OMAP4460_T_HOT_MASK (0x3ff << 16) -#define OMAP4460_T_COLD_SHIFT 0#define OMAP4460_T_COLD_MASK (0x3ff << 0)/* TSHUT_THRESHOLD */ -#define OMAP4460_TSHUT_HOT_SHIFT 16#define OMAP4460_TSHUT_HOT_MASK (0x3ff << 16) -#define OMAP4460_TSHUT_COLD_SHIFT 0#define OMAP4460_TSHUT_COLD_MASK (0x3ff << 0)/* BANDGAP_STATUS */ -#define OMAP4460_CLEAN_STOP_SHIFT 3#define OMAP4460_CLEAN_STOP_MASK BIT(3) -#define OMAP4460_BGAP_ALERT_SHIFT 2#define OMAP4460_BGAP_ALERT_MASK BIT(2) -#define OMAP4460_HOT_FLAG_SHIFT 1#define OMAP4460_HOT_FLAG_MASK BIT(1) -#define OMAP4460_COLD_FLAG_SHIFT 0#define OMAP4460_COLD_FLAG_MASK BIT(0)/* TEMP_SENSOR OMAP5430 */ -#define OMAP5430_BGAP_TEMP_SENSOR_SOC_SHIFT 12#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK BIT(12) -#define OMAP5430_BGAP_TEMPSOFF_SHIFT 11#define OMAP5430_BGAP_TEMPSOFF_MASK BIT(11) -#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_SHIFT 10#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10) -#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_SHIFT 0#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0)/* BANDGAP_CTRL */ -#define OMAP5430_MASK_HOT_CORE_SHIFT 5#define OMAP5430_MASK_HOT_CORE_MASK BIT(5) -#define OMAP5430_MASK_COLD_CORE_SHIFT 4#define OMAP5430_MASK_COLD_CORE_MASK BIT(4) -#define OMAP5430_MASK_HOT_GPU_SHIFT 3#define OMAP5430_MASK_HOT_GPU_MASK BIT(3) -#define OMAP5430_MASK_COLD_GPU_SHIFT 2#define OMAP5430_MASK_COLD_GPU_MASK BIT(2) -#define OMAP5430_MASK_HOT_MPU_SHIFT 1#define OMAP5430_MASK_HOT_MPU_MASK BIT(1) -#define OMAP5430_MASK_COLD_MPU_SHIFT 0#define OMAP5430_MASK_COLD_MPU_MASK BIT(0) -#define OMAP5430_MASK_SIDLEMODE_SHIFT 30#define OMAP5430_MASK_SIDLEMODE_MASK (0x3 << 30) -#define OMAP5430_MASK_FREEZE_CORE_SHIFT 23#define OMAP5430_MASK_FREEZE_CORE_MASK BIT(23) -#define OMAP5430_MASK_FREEZE_GPU_SHIFT 22#define OMAP5430_MASK_FREEZE_GPU_MASK BIT(22) -#define OMAP5430_MASK_FREEZE_MPU_SHIFT 21#define OMAP5430_MASK_FREEZE_MPU_MASK BIT(21) -#define OMAP5430_MASK_CLEAR_CORE_SHIFT 20#define OMAP5430_MASK_CLEAR_CORE_MASK BIT(20) -#define OMAP5430_MASK_CLEAR_GPU_SHIFT 19#define OMAP5430_MASK_CLEAR_GPU_MASK BIT(19) -#define OMAP5430_MASK_CLEAR_MPU_SHIFT 18#define OMAP5430_MASK_CLEAR_MPU_MASK BIT(18) -#define OMAP5430_MASK_CLEAR_ACCUM_CORE_SHIFT 17#define OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK BIT(17) -#define OMAP5430_MASK_CLEAR_ACCUM_GPU_SHIFT 16#define OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK BIT(16) -#define OMAP5430_MASK_CLEAR_ACCUM_MPU_SHIFT 15#define OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK BIT(15)/* BANDGAP_COUNTER */ -#define OMAP5430_COUNTER_SHIFT 0#define OMAP5430_COUNTER_MASK (0xffffff << 0)/* BANDGAP_THRESHOLD */ -#define OMAP5430_T_HOT_SHIFT 16#define OMAP5430_T_HOT_MASK (0x3ff << 16) -#define OMAP5430_T_COLD_SHIFT 0#define OMAP5430_T_COLD_MASK (0x3ff << 0)/* TSHUT_THRESHOLD */ -#define OMAP5430_TSHUT_HOT_SHIFT 16#define OMAP5430_TSHUT_HOT_MASK (0x3ff << 16) -#define OMAP5430_TSHUT_COLD_SHIFT 0#define OMAP5430_TSHUT_COLD_MASK (0x3ff << 0)/* BANDGAP_CUMUL_DTEMP_MPU */ -#define OMAP5430_CUMUL_DTEMP_MPU_SHIFT 0#define OMAP5430_CUMUL_DTEMP_MPU_MASK (0xffffffff << 0)/* BANDGAP_CUMUL_DTEMP_GPU */ -#define OMAP5430_CUMUL_DTEMP_GPU_SHIFT 0#define OMAP5430_CUMUL_DTEMP_GPU_MASK (0xffffffff << 0)/* BANDGAP_CUMUL_DTEMP_CORE */ -#define OMAP5430_CUMUL_DTEMP_CORE_SHIFT 0#define OMAP5430_CUMUL_DTEMP_CORE_MASK (0xffffffff << 0)/* BANDGAP_STATUS */ -#define OMAP5430_BGAP_ALERT_SHIFT 31#define OMAP5430_BGAP_ALERT_MASK BIT(31) -#define OMAP5430_HOT_CORE_FLAG_SHIFT 5#define OMAP5430_HOT_CORE_FLAG_MASK BIT(5) -#define OMAP5430_COLD_CORE_FLAG_SHIFT 4#define OMAP5430_COLD_CORE_FLAG_MASK BIT(4) -#define OMAP5430_HOT_GPU_FLAG_SHIFT 3#define OMAP5430_HOT_GPU_FLAG_MASK BIT(3) -#define OMAP5430_COLD_GPU_FLAG_SHIFT 2#define OMAP5430_COLD_GPU_FLAG_MASK BIT(2) -#define OMAP5430_HOT_MPU_FLAG_SHIFT 1#define OMAP5430_HOT_MPU_FLAG_MASK BIT(1) -#define OMAP5430_COLD_MPU_FLAG_SHIFT 0#define OMAP5430_COLD_MPU_FLAG_MASK BIT(0)/* Offsets from the base of temperature sensor registers */
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 3/50 staging: omap-thermal: create header for register, bitfields and definitions
In reply to Eduardo ValentinIn order to have a better code readability and organization, this patch splits omap-bandgap.h into three headers.
. omap-bandgap.h will contain only the driver related data structures definitions and macros
. omap4xxx-bandgap.h will contain only defines and bitfields related to OMAP4 based devices
. omap5xxx-bandgap.h will contain only defines and bitfields related to OMAP5 based devices
--- drivers/staging/omap-thermal/omap-bandgap.h | 195 -------------------- drivers/staging/omap-thermal/omap4-thermal-data.c | 1 + drivers/staging/omap-thermal/omap4xxx-bandgap.h | 175 ++++++++++++++++++ drivers/staging/omap-thermal/omap5-thermal-data.c | 1 + drivers/staging/omap-thermal/omap5xxx-bandgap.h | 199 +++++++++++++++++++++ 5 files changed, 376 insertions(+), 195 deletions(-) create mode 100644 drivers/staging/omap-thermal/omap4xxx-bandgap.h create mode 100644 drivers/staging/omap-thermal/omap5xxx-bandgap.h
drivers/staging/omap-thermal/omap-bandgap.h +0 -195
@@ -27,201 +27,6 @@#include <linux/types.h> #include <linux/err.h> -/* TEMP_SENSOR OMAP4430 */ -#define OMAP4430_BGAP_TSHUT_MASK BIT(11) - -/* TEMP_SENSOR OMAP4430 */ -#define OMAP4430_BGAP_TEMPSOFF_MASK BIT(12) -#define OMAP4430_SINGLE_MODE_MASK BIT(10) -#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK BIT(9) -#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(8) -#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK (0xff << 0) - -#define OMAP4430_ADC_START_VALUE 0 -#define OMAP4430_ADC_END_VALUE 127 -#define OMAP4430_MAX_FREQ 32768 -#define OMAP4430_MIN_FREQ 32768 -#define OMAP4430_MIN_TEMP -40000 -#define OMAP4430_MAX_TEMP 125000 -#define OMAP4430_HYST_VAL 5000 - -/* TEMP_SENSOR OMAP4460 */ -#define OMAP4460_BGAP_TEMPSOFF_MASK BIT(13) -#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK BIT(11) -#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10) -#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0) - -/* BANDGAP_CTRL */ -#define OMAP4460_SINGLE_MODE_MASK BIT(31) -#define OMAP4460_MASK_HOT_MASK BIT(1) -#define OMAP4460_MASK_COLD_MASK BIT(0) - -/* BANDGAP_COUNTER */ -#define OMAP4460_COUNTER_MASK (0xffffff << 0) - -/* BANDGAP_THRESHOLD */ -#define OMAP4460_T_HOT_MASK (0x3ff << 16) -#define OMAP4460_T_COLD_MASK (0x3ff << 0) - -/* TSHUT_THRESHOLD */ -#define OMAP4460_TSHUT_HOT_MASK (0x3ff << 16) -#define OMAP4460_TSHUT_COLD_MASK (0x3ff << 0) - -/* BANDGAP_STATUS */ -#define OMAP4460_CLEAN_STOP_MASK BIT(3) -#define OMAP4460_BGAP_ALERT_MASK BIT(2) -#define OMAP4460_HOT_FLAG_MASK BIT(1) -#define OMAP4460_COLD_FLAG_MASK BIT(0) - -/* TEMP_SENSOR OMAP5430 */ -#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK BIT(12) -#define OMAP5430_BGAP_TEMPSOFF_MASK BIT(11) -#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK BIT(10) -#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK (0x3ff << 0) - -/* BANDGAP_CTRL */ -#define OMAP5430_MASK_HOT_CORE_MASK BIT(5) -#define OMAP5430_MASK_COLD_CORE_MASK BIT(4) -#define OMAP5430_MASK_HOT_GPU_MASK BIT(3) -#define OMAP5430_MASK_COLD_GPU_MASK BIT(2) -#define OMAP5430_MASK_HOT_MPU_MASK BIT(1) -#define OMAP5430_MASK_COLD_MPU_MASK BIT(0) -#define OMAP5430_MASK_SIDLEMODE_MASK (0x3 << 30) -#define OMAP5430_MASK_FREEZE_CORE_MASK BIT(23) -#define OMAP5430_MASK_FREEZE_GPU_MASK BIT(22) -#define OMAP5430_MASK_FREEZE_MPU_MASK BIT(21) -#define OMAP5430_MASK_CLEAR_CORE_MASK BIT(20) -#define OMAP5430_MASK_CLEAR_GPU_MASK BIT(19) -#define OMAP5430_MASK_CLEAR_MPU_MASK BIT(18) -#define OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK BIT(17) -#define OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK BIT(16) -#define OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK BIT(15) - -/* BANDGAP_COUNTER */ -#define OMAP5430_COUNTER_MASK (0xffffff << 0) - -/* BANDGAP_THRESHOLD */ -#define OMAP5430_T_HOT_MASK (0x3ff << 16) -#define OMAP5430_T_COLD_MASK (0x3ff << 0) - -/* TSHUT_THRESHOLD */ -#define OMAP5430_TSHUT_HOT_MASK (0x3ff << 16) -#define OMAP5430_TSHUT_COLD_MASK (0x3ff << 0) - -/* BANDGAP_CUMUL_DTEMP_MPU */ -#define OMAP5430_CUMUL_DTEMP_MPU_MASK (0xffffffff << 0) - -/* BANDGAP_CUMUL_DTEMP_GPU */ -#define OMAP5430_CUMUL_DTEMP_GPU_MASK (0xffffffff << 0) - -/* BANDGAP_CUMUL_DTEMP_CORE */ -#define OMAP5430_CUMUL_DTEMP_CORE_MASK (0xffffffff << 0) - -/* BANDGAP_STATUS */ -#define OMAP5430_BGAP_ALERT_MASK BIT(31) -#define OMAP5430_HOT_CORE_FLAG_MASK BIT(5) -#define OMAP5430_COLD_CORE_FLAG_MASK BIT(4) -#define OMAP5430_HOT_GPU_FLAG_MASK BIT(3) -#define OMAP5430_COLD_GPU_FLAG_MASK BIT(2) -#define OMAP5430_HOT_MPU_FLAG_MASK BIT(1) -#define OMAP5430_COLD_MPU_FLAG_MASK BIT(0) - -/* Offsets from the base of temperature sensor registers */ - -/* 4430 - All goes relative to OPP_BGAP */ -#define OMAP4430_FUSE_OPP_BGAP 0x0 -#define OMAP4430_TEMP_SENSOR_CTRL_OFFSET 0xCC - -/* 4460 - All goes relative to OPP_BGAP */ -#define OMAP4460_FUSE_OPP_BGAP 0x0 -#define OMAP4460_TEMP_SENSOR_CTRL_OFFSET 0xCC -#define OMAP4460_BGAP_CTRL_OFFSET 0x118 -#define OMAP4460_BGAP_COUNTER_OFFSET 0x11C -#define OMAP4460_BGAP_THRESHOLD_OFFSET 0x120 -#define OMAP4460_BGAP_TSHUT_OFFSET 0x124 -#define OMAP4460_BGAP_STATUS_OFFSET 0x128 - -/* 5430 - All goes relative to OPP_BGAP_GPU */ -#define OMAP5430_FUSE_OPP_BGAP_GPU 0x0 -#define OMAP5430_TEMP_SENSOR_GPU_OFFSET 0x150 -#define OMAP5430_BGAP_THRESHOLD_GPU_OFFSET 0x1A8 -#define OMAP5430_BGAP_TSHUT_GPU_OFFSET 0x1B4 -#define OMAP5430_BGAP_CUMUL_DTEMP_GPU_OFFSET 0x1C0 -#define OMAP5430_BGAP_DTEMP_GPU_0_OFFSET 0x1F4 -#define OMAP5430_BGAP_DTEMP_GPU_1_OFFSET 0x1F8 -#define OMAP5430_BGAP_DTEMP_GPU_2_OFFSET 0x1FC -#define OMAP5430_BGAP_DTEMP_GPU_3_OFFSET 0x200 -#define OMAP5430_BGAP_DTEMP_GPU_4_OFFSET 0x204 - -#define OMAP5430_FUSE_OPP_BGAP_MPU 0x4 -#define OMAP5430_TEMP_SENSOR_MPU_OFFSET 0x14C -#define OMAP5430_BGAP_CTRL_OFFSET 0x1A0 -#define OMAP5430_BGAP_THRESHOLD_MPU_OFFSET 0x1A4 -#define OMAP5430_BGAP_TSHUT_MPU_OFFSET 0x1B0 -#define OMAP5430_BGAP_CUMUL_DTEMP_MPU_OFFSET 0x1BC -#define OMAP5430_BGAP_DTEMP_MPU_0_OFFSET 0x1E0 -#define OMAP5430_BGAP_DTEMP_MPU_1_OFFSET 0x1E4 -#define OMAP5430_BGAP_DTEMP_MPU_2_OFFSET 0x1E8 -#define OMAP5430_BGAP_DTEMP_MPU_3_OFFSET 0x1EC -#define OMAP5430_BGAP_DTEMP_MPU_4_OFFSET 0x1F0 - -#define OMAP5430_FUSE_OPP_BGAP_CORE 0x8 -#define OMAP5430_TEMP_SENSOR_CORE_OFFSET 0x154 -#define OMAP5430_BGAP_THRESHOLD_CORE_OFFSET 0x1AC -#define OMAP5430_BGAP_TSHUT_CORE_OFFSET 0x1B8 -#define OMAP5430_BGAP_CUMUL_DTEMP_CORE_OFFSET 0x1C4 -#define OMAP5430_BGAP_DTEMP_CORE_0_OFFSET 0x208 -#define OMAP5430_BGAP_DTEMP_CORE_1_OFFSET 0x20C -#define OMAP5430_BGAP_DTEMP_CORE_2_OFFSET 0x210 -#define OMAP5430_BGAP_DTEMP_CORE_3_OFFSET 0x214 -#define OMAP5430_BGAP_DTEMP_CORE_4_OFFSET 0x218 - -#define OMAP5430_BGAP_STATUS_OFFSET 0x1C8 - -#define OMAP4460_TSHUT_HOT 900/* 122 deg C */ -#define OMAP4460_TSHUT_COLD 895/* 100 deg C */ -#define OMAP4460_T_HOT 800/* 73 deg C */ -#define OMAP4460_T_COLD 795/* 71 deg C */ -#define OMAP4460_MAX_FREQ 1500000 -#define OMAP4460_MIN_FREQ 1000000 -#define OMAP4460_MIN_TEMP -40000 -#define OMAP4460_MAX_TEMP 123000 -#define OMAP4460_HYST_VAL 5000 -#define OMAP4460_ADC_START_VALUE 530 -#define OMAP4460_ADC_END_VALUE 932 - -#define OMAP5430_MPU_TSHUT_HOT 915 -#define OMAP5430_MPU_TSHUT_COLD 900 -#define OMAP5430_MPU_T_HOT 800 -#define OMAP5430_MPU_T_COLD 795 -#define OMAP5430_MPU_MAX_FREQ 1500000 -#define OMAP5430_MPU_MIN_FREQ 1000000 -#define OMAP5430_MPU_MIN_TEMP -40000 -#define OMAP5430_MPU_MAX_TEMP 125000 -#define OMAP5430_MPU_HYST_VAL 5000 -#define OMAP5430_ADC_START_VALUE 540 -#define OMAP5430_ADC_END_VALUE 945 - -#define OMAP5430_GPU_TSHUT_HOT 915 -#define OMAP5430_GPU_TSHUT_COLD 900 -#define OMAP5430_GPU_T_HOT 800 -#define OMAP5430_GPU_T_COLD 795 -#define OMAP5430_GPU_MAX_FREQ 1500000 -#define OMAP5430_GPU_MIN_FREQ 1000000 -#define OMAP5430_GPU_MIN_TEMP -40000 -#define OMAP5430_GPU_MAX_TEMP 125000 -#define OMAP5430_GPU_HYST_VAL 5000 - -#define OMAP5430_CORE_TSHUT_HOT 915 -#define OMAP5430_CORE_TSHUT_COLD 900 -#define OMAP5430_CORE_T_HOT 800 -#define OMAP5430_CORE_T_COLD 795 -#define OMAP5430_CORE_MAX_FREQ 1500000 -#define OMAP5430_CORE_MIN_FREQ 1000000 -#define OMAP5430_CORE_MIN_TEMP -40000 -#define OMAP5430_CORE_MAX_TEMP 125000 -#define OMAP5430_CORE_HYST_VAL 5000 -/** * The register offsets and bit fields might change across * OMAP versions hence populating them in this structure.
drivers/staging/omap-thermal/omap4-thermal-data.c +1 -0
@@ -18,6 +18,7 @@#include "omap-thermal.h" #include "omap-bandgap.h" +#include "omap4xxx-bandgap.h" /* * OMAP4430 has one instance of thermal sensor for MPU
drivers/staging/omap-thermal/omap4xxx-bandgap.h new file +175 -0
175 lines not on this page · raw message
drivers/staging/omap-thermal/omap5-thermal-data.c +1 -0
@@ -17,6 +17,7 @@*/ #include "omap-bandgap.h" +#include "omap5xxx-bandgap.h" #include "omap-thermal.h" /*
drivers/staging/omap-thermal/omap5xxx-bandgap.h new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 4/50 staging: omap-thermal: update documentation of omap-bandgap.h
In reply to Eduardo ValentinThis patch updates the existing data structures for omap bandgap, inside omap-bandgap.h.
TODO: remove unused fields.
--- drivers/staging/omap-thermal/omap-bandgap.h | 230 ++++++++++++++++++++++----- 1 files changed, 189 insertions(+), 41 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.h +189 -41
@@ -28,24 +28,101 @@#include <linux/err.h> /** -* The register offsets and bit fields might change across -* OMAP versions hence populating them in this structure. +* DOC: bandgap driver data structure +* ================================== +* +---------------------+ +-----------------+ +* | struct omap_bandgap |-->| struct device * | +* +----------+----------+ +-----------------+ +* | +* | +* V +* +--------------------------+ +* | struct omap_bandgap_data | +* +--------------------------+ +* | +* | +* * (Array of) +* +------------+------------------------------------------------------+ +* | +----------+--------------+ +-------------------------+ | +* | | struct omap_temp_sensor |-->| struct temp_sensor_data | | +* | +-------------------------+ +------------+------------+ | +* | | | +* | +--------------------------+ | +* | V V | +* | +----------+- --------------+ +----+-------------------------+ | +* | | struct temp_sensor_regval | | struct temp_sensor_registers | | +* | +---------------------------+ +------------------------------+ | +* | | +* +-------------------------------------------------------------------+ +* +* Above is a simple diagram describing how the data structure below +* are organized. For each bandgap device there should be a omap_bandgap_data +* containing the device instance configuration, as well as, an array of +* sensors, representing every sensor instance present in this bandgap. +*/ + +/** +* struct temp_sensor_registers - descriptor to access registers and bitfields +* @temp_sensor_ctrl: TEMP_SENSOR_CTRL register offset +* @bgap_tempsoff_mask: mask to temp_sensor_ctrl.tempsoff +* @bgap_soc_mask: mask to temp_sensor_ctrl.soc +* @bgap_eocz_mask: mask to temp_sensor_ctrl.eocz +* @bgap_dtemp_mask: mask to temp_sensor_ctrl.dtemp +* @bgap_mask_ctrl: BANDGAP_MASK_CTRL register offset +* @mask_hot_mask: mask to bandgap_mask_ctrl.mask_hot +* @mask_cold_mask: mask to bandgap_mask_ctrl.mask_cold +* @mask_sidlemode_mask: mask to bandgap_mask_ctrl.mask_sidlemode +* @mask_freeze_mask: mask to bandgap_mask_ctrl.mask_free +* @mask_clear_mask: mask to bandgap_mask_ctrl.mask_clear +* @mask_clear_accum_mask: mask to bandgap_mask_ctrl.mask_clear_accum +* @bgap_mode_ctrl: BANDGAP_MODE_CTRL register offset +* @mode_ctrl_mask: mask to bandgap_mode_ctrl.mode_ctrl +* @bgap_counter: BANDGAP_COUNTER register offset +* @counter_mask: mask to bandgap_counter.counter +* @bgap_threshold: BANDGAP_THRESHOLD register offset (TALERT thresholds) +* @threshold_thot_mask: mask to bandgap_threhold.thot +* @threshold_tcold_mask: mask to bandgap_threhold.tcold +* @tshut_threshold: TSHUT_THRESHOLD register offset (TSHUT thresholds) +* @tshut_efuse_mask: mask to tshut_threshold.tshut_efuse +* @tshut_efuse_shift: shift to tshut_threshold.tshut_efuse +* @tshut_hot_mask: mask to tshut_threhold.thot +* @tshut_cold_mask: mask to tshut_threhold.thot +* @bgap_status: BANDGAP_STATUS register offset +* @status_clean_stop_mask: mask to bandgap_status.clean_stop +* @status_bgap_alert_mask: mask to bandgap_status.bandgap_alert +* @status_hot_mask: mask to bandgap_status.hot +* @status_cold_mask: mask to bandgap_status.cold +* @bgap_cumul_dtemp: BANDGAP_CUMUL_DTEMP register offset +* @ctrl_dtemp_0: CTRL_DTEMP0 register offset +* @ctrl_dtemp_1: CTRL_DTEMP1 register offset +* @ctrl_dtemp_2: CTRL_DTEMP2 register offset +* @ctrl_dtemp_3: CTRL_DTEMP3 register offset +* @ctrl_dtemp_4: CTRL_DTEMP4 register offset +* @bgap_efuse: BANDGAP_EFUSE register offset +* +* The register offsets and bitfields might change across +* OMAP and variants versions. Hence this struct serves as a +* descriptor map on how to access the registers and the bitfields. +* +* This descriptor contains registers of all versions of bandgap chips. +* Not all versions will use all registers, depending on the available +* features. Please read TRMs for descriptive explanation on each bitfield. */ struct temp_sensor_registers {u32 temp_sensor_ctrl;u32 bgap_tempsoff_mask;u32 bgap_soc_mask; -u32 bgap_eocz_mask; +u32 bgap_eocz_mask;/* not used: but needs revisit */ u32 bgap_dtemp_mask;u32 bgap_mask_ctrl;u32 mask_hot_mask;u32 mask_cold_mask; -u32 mask_sidlemode_mask; +u32 mask_sidlemode_mask;/* not used: but may be needed for pm */ u32 mask_freeze_mask; -u32 mask_clear_mask; -u32 mask_clear_accum_mask; +u32 mask_clear_mask;/* not used: but needed for trending */ +u32 mask_clear_accum_mask;/* not used: but needed for trending */ u32 bgap_mode_ctrl;u32 mode_ctrl_mask;
@@ -58,28 +135,45 @@ struct temp_sensor_registers {u32 threshold_tcold_mask;u32 tshut_threshold; -u32 tshut_efuse_mask; -u32 tshut_efuse_shift; +u32 tshut_efuse_mask;/* not used */ +u32 tshut_efuse_shift;/* not used */ u32 tshut_hot_mask;u32 tshut_cold_mask;u32 bgap_status; -u32 status_clean_stop_mask; -u32 status_bgap_alert_mask; +u32 status_clean_stop_mask;/* not used: but needed for trending */ +u32 status_bgap_alert_mask;/* not used */ u32 status_hot_mask;u32 status_cold_mask; -u32 bgap_cumul_dtemp; -u32 ctrl_dtemp_0; -u32 ctrl_dtemp_1; -u32 ctrl_dtemp_2; -u32 ctrl_dtemp_3; -u32 ctrl_dtemp_4; +u32 bgap_cumul_dtemp;/* not used: but needed for trending */ +u32 ctrl_dtemp_0;/* not used: but needed for trending */ +u32 ctrl_dtemp_1;/* not used: but needed for trending */ +u32 ctrl_dtemp_2;/* not used: but needed for trending */ +u32 ctrl_dtemp_3;/* not used: but needed for trending */ +u32 ctrl_dtemp_4;/* not used: but needed for trending */ u32 bgap_efuse; };/** -* The thresholds and limits for temperature sensors. +* struct temp_sensor_data - The thresholds and limits for temperature sensors. +* @tshut_hot: temperature to trigger a thermal reset (initial value) +* @tshut_cold: temp to get the plat out of reset due to thermal (init val) +* @t_hot: temperature to trigger a thermal alert (high initial value) +* @t_cold: temperature to trigger a thermal alert (low initial value) +* @min_freq: sensor minimum clock rate +* @max_freq: sensor maximum clock rate +* @max_temp: sensor maximum temperature +* @min_temp: sensor minimum temperature +* @hyst_val: temperature hysteresis considered while converting ADC values +* @adc_start_val: ADC conversion table starting value +* @adc_end_val: ADC conversion table ending value +* @update_int1: update interval +* @update_int2: update interval +* +* This data structure will hold the required thresholds and temperature limits +* for a specific temperature sensor, like shutdown temperature, alert +* temperature, clock / rate used, ADC conversion limits and update intervals */ struct temp_sensor_data {u32 tshut_hot;
@@ -93,23 +187,27 @@ struct temp_sensor_data {int hyst_val;u32 adc_start_val;u32 adc_end_val; -u32 update_int1; -u32 update_int2; +u32 update_int1;/* not used */ +u32 update_int2;/* not used */ };struct omap_bandgap_data ;/** * struct omap_bandgap - bandgap device structure -* @dev: device pointer -* @conf: platform data with sensor data +* @dev: struct device pointer +* @base: io memory base address +* @conf: struct with bandgap configuration set (# sensors, conv_table, etc) * @fclock: pointer to functional clock of temperature sensor -* @div_clk: pointer to parent clock of temperature sensor fclk -* @conv_table: Pointer to adc to temperature conversion table -* @bg_mutex: Mutex for sysfs, irq and PM -* @irq: MPU Irq number for thermal alert +* @div_clk: pointer to divider clock of temperature sensor fclk +* @bg_mutex: mutex for omap_bandgap structure +* @irq: MPU IRQ number for thermal alert * @tshut_gpio: GPIO where Tshut signal is routed * @clk_rate: Holds current clock rate +* +* The bandgap device structure representing the bandgap device instance. +* It holds most of the dynamic stuff. Configurations and sensor specific +* entries are inside the @conf structure. */ struct omap_bandgap {struct device *dev;
@@ -117,7 +215,7 @@ struct omap_bandgap {struct omap_bandgap_data *conf;struct clk *fclock;struct clk *div_clk; -struct mutex bg_mutex;/* Mutex for irq and PM */ +struct mutex bg_mutex;/* shields this struct */ int irq;int tshut_gpio;u32 clk_rate;
@@ -130,6 +228,9 @@ struct omap_bandgap {* @bg_counter: bandgap counter value * @bg_threshold: bandgap threshold register value * @tshut_threshold: bandgap tshut register value +* +* Data structure to save and restore bandgap register set context. Only +* required registers are shadowed, when needed. */ struct temp_sensor_regval {u32 bg_mode_ctrl;
@@ -140,21 +241,26 @@ struct temp_sensor_regval { };/** -* struct omap_temp_sensor - bandgap temperature sensor platform data +* struct omap_temp_sensor - bandgap temperature sensor configuration data * @ts_data: pointer to struct with thresholds, limits of temperature sensor * @registers: pointer to the list of register offsets and bitfields * @regval: temperature sensor register values * @domain: the name of the domain where the sensor is located -* @cooling_data: description on how the zone should be cooled off. -* @slope: sensor gradient slope info for hotspot extrapolation -* @const: sensor gradient const info for hotspot extrapolation -* @slope_pcb: sensor gradient slope info for hotspot extrapolation +* @slope: sensor gradient slope info for hotspot extrapolation equation +* @const: sensor gradient const info for hotspot extrapolation equation +* @slope_pcb: sensor gradient slope info for hotspot extrapolation equation * with no external influence -* @const_pcb: sensor gradient const info for hotspot extrapolation +* @constant_pcb: sensor gradient const info for hotspot extrapolation equation * with no external influence * @data: private data * @register_cooling: function to describe how this sensor is going to be cooled * @unregister_cooling: function to release cooling data +* +* Data structure to describe a temperature sensor handled by a bandgap device. +* It should provide configuration details on this sensor, such as how to +* access the registers affecting this sensor, shadow register buffer, how to +* assess the gradient from hotspot, how to cooldown the domain when sensor +* reports too hot temperature. */ struct omap_temp_sensor {struct temp_sensor_data *ts_data;
@@ -172,16 +278,38 @@ struct omap_temp_sensor { };/** -* struct omap_bandgap_data - bandgap platform data structure -* @features: a bitwise flag set to describe the device features -* @conv_table: Pointer to adc to temperature conversion table -* @fclock_name: clock name of the functional clock -* @div_ck_nme: clock name of the clock divisor -* @sensor_count: count of temperature sensor device in scm -* @sensors: array of sensors present in this bandgap instance -* @expose_sensor: callback to export sensor to thermal API +* DOC: omap bandgap feature types +* +* OMAP_BANDGAP_FEATURE_TSHUT - used when the thermal shutdown signal output +* of a bandgap device instance is routed to the processor. This means +* the system must react and perform the shutdown by itself (handle an +* IRQ, for instance). +* +* OMAP_BANDGAP_FEATURE_TSHUT_CONFIG - used when the bandgap device has control +* over the thermal shutdown configuration. This means that the thermal +* shutdown thresholds are programmable, for instance. +* +* OMAP_BANDGAP_FEATURE_TALERT - used when the bandgap device instance outputs +* a signal representing violation of programmable alert thresholds. +* +* OMAP_BANDGAP_FEATURE_MODE_CONFIG - used when it is possible to choose which +* mode, continuous or one shot, the bandgap device instance will operate. +* +* OMAP_BANDGAP_FEATURE_COUNTER - used when the bandgap device instance allows +* programming the update interval of its internal state machine. +* +* OMAP_BANDGAP_FEATURE_POWER_SWITCH - used when the bandgap device allows +* itself to be switched on/off. +* +* OMAP_BANDGAP_FEATURE_CLK_CTRL - used when the clocks feeding the bandgap +* device are gateable or not. +* +* OMAP_BANDGAP_FEATURE_FREEZE_BIT - used when the bandgap device features +* a history buffer that its update can be freezed/unfreezed. +* +* OMAP_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a +* specific feature (above) or not. Return non-zero, if yes. */ -struct omap_bandgap_data {#define OMAP_BANDGAP_FEATURE_TSHUT BIT(0)#define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG BIT(1)#define OMAP_BANDGAP_FEATURE_TALERT BIT(2)
@@ -192,6 +320,26 @@ struct omap_bandgap_data {#define OMAP_BANDGAP_FEATURE_FREEZE_BIT BIT(7)#define OMAP_BANDGAP_HAS (b, f) \ ((b)->conf->features & OMAP_BANDGAP_FEATURE_ ## f) + +/** +* struct omap_bandgap_data - omap bandgap data configuration structure +* @features: a bitwise flag set to describe the device features +* @conv_table: Pointer to ADC to temperature conversion table +* @fclock_name: clock name of the functional clock +* @div_ck_name: clock name of the clock divisor +* @sensor_count: count of temperature sensor within this bandgap device +* @report_temperature: callback to report thermal alert to thermal API +* @expose_sensor: callback to export sensor to thermal API +* @remove_sensor: callback to destroy sensor from thermal API +* @sensors: array of sensors present in this bandgap instance +* +* This is a data structure which should hold most of the static configuration +* of a bandgap device instance. It should describe which features this instance +* is capable of, the clock names to feed this device, the amount of sensors and +* their configuration representation, and how to export and unexport them to +* a thermal API. +*/ +struct omap_bandgap_data {unsigned int features;const int *conv_table;char *fclock_name;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 5/50 staging: omap-thermal: style cleanup on omap-bandgap.c
In reply to Eduardo Valentinsimple changes on alignments and white spaces
--- drivers/staging/omap-thermal/omap-bandgap.c | 32 ++++++++++++-------------- 1 files changed, 15 insertions(+), 17 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +15 -17
@@ -437,7 +437,7 @@ static inline int omap_bandgap_validate(struct omap_bandgap *bg_ptr, int id)* returns 0 on success or the proper error code */ int omap_bandgap_read_thot (struct omap_bandgap *bg_ptr,int id, -int *thot) +int *thot) {struct temp_sensor_registers *tsr;u32 temp;
@@ -512,7 +512,7 @@ int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val)* returns 0 on success or the proper error code */ int omap_bandgap_read_tcold (struct omap_bandgap *bg_ptr,int id, -int *tcold) +int *tcold) {struct temp_sensor_registers *tsr;u32 temp;
@@ -617,7 +617,7 @@ int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,* returns 0 on success or the proper error code */ int omap_bandgap_write_update_interval (struct omap_bandgap *bg_ptr, -int id,u32 interval) +int id,u32 interval) {int ret =omap_bandgap_validate (bg_ptr, id);if (ret)
@@ -643,7 +643,7 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,* returns 0 on success or the proper error code */ int omap_bandgap_read_temperature (struct omap_bandgap *bg_ptr,int id, -int *temperature) +int *temperature) {struct temp_sensor_registers *tsr;u32 temp;
@@ -677,7 +677,7 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,* returns 0 on success or the proper error code */ int omap_bandgap_set_sensor_data (struct omap_bandgap *bg_ptr,int id, -void *data) +void *data) {int ret =omap_bandgap_validate (bg_ptr, id);if (ret)
@@ -762,7 +762,7 @@ static int enable_continuous_mode(struct omap_bandgap *bg_ptr) }static int omap_bandgap_tshut_init (struct omap_bandgap *bg_ptr, -struct platform_device *pdev) +struct platform_device *pdev) {int gpio_nr = bg_ptr->tshut_gpio;int status;
@@ -795,7 +795,7 @@ static int omap_bandgap_tshut_init(struct omap_bandgap *bg_ptr,/* Initialization of Talert. Call it only if HAS(TALERT) is set */ static int omap_bandgap_talert_init (struct omap_bandgap *bg_ptr, -struct platform_device *pdev) +struct platform_device *pdev) {int ret;
@@ -855,7 +855,7 @@ static struct omap_bandgap *omap_bandgap_build(struct platform_device *pdev) bg_ptr->base = chunk;if (IS_ERR (chunk))return ERR_CAST (chunk); - + i++; }while (res);
@@ -1108,9 +1108,8 @@ static int omap_bandgap_restore_ctxt(struct omap_bandgap *bg_ptr) val =omap_bandgap_readl (bg_ptr, tsr->bgap_counter);if (OMAP_BANDGAP_HAS (bg_ptr,TSHUT_CONFIG )) -omap_bandgap_writel (bg_ptr, - rval->tshut_threshold, - tsr->tshut_threshold); +omap_bandgap_writel (bg_ptr, rval->tshut_threshold, + tsr->tshut_threshold);/* Force immediate temperature measurement and update * of the DTEMP field */
@@ -1118,16 +1117,15 @@ static int omap_bandgap_restore_ctxt(struct omap_bandgap *bg_ptr)if (OMAP_BANDGAP_HAS (bg_ptr,COUNTER ))omap_bandgap_writel (bg_ptr, rval->bg_counter, - tsr->bgap_counter); + tsr->bgap_counter);if (OMAP_BANDGAP_HAS (bg_ptr,MODE_CONFIG ))omap_bandgap_writel (bg_ptr, rval->bg_mode_ctrl, - tsr->bgap_mode_ctrl); + tsr->bgap_mode_ctrl);if (OMAP_BANDGAP_HAS (bg_ptr,TALERT )) { -omap_bandgap_writel (bg_ptr, - rval->bg_threshold, - tsr->bgap_threshold); +omap_bandgap_writel (bg_ptr, rval->bg_threshold, + tsr->bgap_threshold);omap_bandgap_writel (bg_ptr, rval->bg_ctrl, - tsr->bgap_mask_ctrl); + tsr->bgap_mask_ctrl); } }
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 6/50 staging: omap-thermal: fix error checking
In reply to Eduardo ValentinThe omap_bandgap_get_sensor_data() function returns ERR_PTR(), but it can also return NULL, in case of initilization, so we need to use IS_ERR_OR_NULL() rather than only IS_ERR().
--- drivers/staging/omap-thermal/omap-thermal-common.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/omap-thermal-common.c +2 -2
@@ -260,7 +260,7 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id, data =omap_bandgap_get_sensor_data (bg_ptr, id); -if (IS_ERR (data)) +if (IS_ERR_OR_NULL (data)) data =omap_thermal_build_data (bg_ptr, id);if (!data)
@@ -309,7 +309,7 @@ int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)struct omap_thermal_data *data; data =omap_bandgap_get_sensor_data (bg_ptr, id); -if (IS_ERR (data)) +if (IS_ERR_OR_NULL (data)) data =omap_thermal_build_data (bg_ptr, id);if (!data)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 7/50 staging: omap-thermal: introduce RMW_BITS macro
In reply to Eduardo ValentinThis patch introduce a macro to read, update, write bitfields. It will be specific to bandgap data structures.
--- drivers/staging/omap-thermal/omap-bandgap.c | 178 +++++++-------------------- 1 files changed, 46 insertions(+), 132 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +46 -132
@@ -52,25 +52,29 @@ static void omap_bandgap_writel(struct omap_bandgap *bg_ptr, u32 val, u32 reg)writel (val, bg_ptr->base + reg); } +/* update bits, value will be shifted */ +#define RMW_BITS (bg_ptr, id, reg, mask, val) \ +do { \ + struct temp_sensor_registers *t; \ + u32 r; \ + \ + t = bg_ptr->conf->sensors[(id)].registers; \ + r = omap_bandgap_readl(bg_ptr, t->reg); \ + r &= ~t->mask; \ + r |= (val) << __ffs(t->mask); \ + omap_bandgap_writel(bg_ptr, r, t->reg); \ +} while (0) +static int omap_bandgap_power (struct omap_bandgap *bg_ptr,bool on) { -struct temp_sensor_registers *tsr;int i; -u32 ctrl;if (!OMAP_BANDGAP_HAS (bg_ptr,POWER_SWITCH ))return 0 ; -for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { - tsr = bg_ptr->conf->sensors[i].registers; - ctrl =omap_bandgap_readl (bg_ptr, tsr->temp_sensor_ctrl); - ctrl &= ~tsr->bgap_tempsoff_mask; +for (i =0 ; i < bg_ptr->conf->sensor_count; i++)/* active on 0 */ - ctrl |= !on <<__ffs (tsr->bgap_tempsoff_mask); - -/* write BGAP_TEMPSOFF should be reset to 0 */ -omap_bandgap_writel (bg_ptr, ctrl, tsr->temp_sensor_ctrl); - } +RMW_BITS (bg_ptr, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);return 0 ; }
@@ -78,15 +82,13 @@ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)static u32 omap_bandgap_read_temp (struct omap_bandgap *bg_ptr,int id) {struct temp_sensor_registers *tsr; -u32 temp, ctrl, reg; +u32 temp, reg; tsr = bg_ptr->conf->sensors[id].registers; reg = tsr->temp_sensor_ctrl;if (OMAP_BANDGAP_HAS (bg_ptr,FREEZE_BIT )) { - ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_mask_ctrl); - ctrl |= tsr->mask_freeze_mask; -omap_bandgap_writel (bg_ptr, ctrl, tsr->bgap_mask_ctrl); +RMW_BITS (bg_ptr, id, bgap_mask_ctrl, mask_freeze_mask,1 );/* * In case we cannot read from cur_dtemp / dtemp_0, * then we read from the last valid temp read
@@ -98,11 +100,8 @@ static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id) temp =omap_bandgap_readl (bg_ptr, reg); temp &= tsr->bgap_dtemp_mask; -if (OMAP_BANDGAP_HAS (bg_ptr,FREEZE_BIT )) { - ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_mask_ctrl); - ctrl &= ~tsr->mask_freeze_mask; -omap_bandgap_writel (bg_ptr, ctrl, tsr->bgap_mask_ctrl); - } +if (OMAP_BANDGAP_HAS (bg_ptr,FREEZE_BIT )) +RMW_BITS (bg_ptr, id, bgap_mask_ctrl, mask_freeze_mask,0 );return temp; }
@@ -290,37 +289,6 @@ int temp_sensor_configure_thot(struct omap_bandgap *bg_ptr, int id, int t_hot)return temp_sensor_unmask_interrupts (bg_ptr, id, t_hot, cold); } -/* Talert Thot and Tcold thresholds. Call it only if HAS(TALERT) is set */ -static -int temp_sensor_init_talert_thresholds (struct omap_bandgap *bg_ptr,int id, -int t_hot,int t_cold) -{ -struct temp_sensor_registers *tsr; -u32 reg_val, thresh_val; - - tsr = bg_ptr->conf->sensors[id].registers; - thresh_val =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - -/* write the new t_cold value */ - reg_val = thresh_val & ~tsr->threshold_tcold_mask; - reg_val |= (t_cold <<__ffs (tsr->threshold_tcold_mask)); -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); - - thresh_val =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - -/* write the new t_hot value */ - reg_val = thresh_val & ~tsr->threshold_thot_mask; - reg_val |= (t_hot <<__ffs (tsr->threshold_thot_mask)); -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); - - reg_val =omap_bandgap_readl (bg_ptr, tsr->bgap_mask_ctrl); - reg_val |= tsr->mask_hot_mask; - reg_val |= tsr->mask_cold_mask; -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_mask_ctrl); - -return 0 ; -} -/* Talert Tcold threshold. Call it only if HAS(TALERT) is set */ static int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,
@@ -359,54 +327,6 @@ int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,return temp_sensor_unmask_interrupts (bg_ptr, id, hot, t_cold); } -/* This is Tshut Thot config. Call it only if HAS(TSHUT_CONFIG) is set */ -static int temp_sensor_configure_tshut_hot (struct omap_bandgap *bg_ptr, -int id,int tshut_hot) -{ -struct temp_sensor_registers *tsr; -u32 reg_val; - - tsr = bg_ptr->conf->sensors[id].registers; - reg_val =omap_bandgap_readl (bg_ptr, tsr->tshut_threshold); - reg_val &= ~tsr->tshut_hot_mask; - reg_val |= tshut_hot <<__ffs (tsr->tshut_hot_mask); -omap_bandgap_writel (bg_ptr, reg_val, tsr->tshut_threshold); - -return 0 ; -} - -/* This is Tshut Tcold config. Call it only if HAS(TSHUT_CONFIG) is set */ -static int temp_sensor_configure_tshut_cold (struct omap_bandgap *bg_ptr, -int id,int tshut_cold) -{ -struct temp_sensor_registers *tsr; -u32 reg_val; - - tsr = bg_ptr->conf->sensors[id].registers; - reg_val =omap_bandgap_readl (bg_ptr, tsr->tshut_threshold); - reg_val &= ~tsr->tshut_cold_mask; - reg_val |= tshut_cold <<__ffs (tsr->tshut_cold_mask); -omap_bandgap_writel (bg_ptr, reg_val, tsr->tshut_threshold); - -return 0 ; -} - -/* This is counter config. Call it only if HAS(COUNTER) is set */ -static int configure_temp_sensor_counter (struct omap_bandgap *bg_ptr,int id, -u32 counter) -{ -struct temp_sensor_registers *tsr; -u32 val; - - tsr = bg_ptr->conf->sensors[id].registers; - val =omap_bandgap_readl (bg_ptr, tsr->bgap_counter); - val &= ~tsr->counter_mask; - val |= counter <<__ffs (tsr->counter_mask); -omap_bandgap_writel (bg_ptr, val, tsr->bgap_counter); - -return 0 ; -} -#define bandgap_is_valid (b) \ (!IS_ERR_OR_NULL(b))#define bandgap_is_valid_sensor_id (b, i) \
@@ -628,7 +548,7 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr, interval = interval * bg_ptr->clk_rate /1000 ;mutex_lock (&bg_ptr->bg_mutex); -configure_temp_sensor_counter (bg_ptr, id, interval); +RMW_BITS (bg_ptr, id, bgap_counter, counter_mask, interval);mutex_unlock (&bg_ptr->bg_mutex);return 0 ;
@@ -645,7 +565,6 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,int omap_bandgap_read_temperature (struct omap_bandgap *bg_ptr,int id,int *temperature) { -struct temp_sensor_registers *tsr;u32 temp;int ret;
@@ -653,7 +572,6 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,if (ret)return ret; - tsr = bg_ptr->conf->sensors[id].registers;mutex_lock (&bg_ptr->bg_mutex); temp =omap_bandgap_read_temp (bg_ptr, id);mutex_unlock (&bg_ptr->bg_mutex);
@@ -708,31 +626,23 @@ void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id)static int omap_bandgap_force_single_read (struct omap_bandgap *bg_ptr,int id) { -struct temp_sensor_registers *tsr;u32 temp =0 , counter =1000 ; - tsr = bg_ptr->conf->sensors[id].registers;/* Select single conversion mode */ -if (OMAP_BANDGAP_HAS (bg_ptr,MODE_CONFIG )) { - temp =omap_bandgap_readl (bg_ptr, tsr->bgap_mode_ctrl); - temp &= ~(1 <<__ffs (tsr->mode_ctrl_mask)); -omap_bandgap_writel (bg_ptr, temp, tsr->bgap_mode_ctrl); - } +if (OMAP_BANDGAP_HAS (bg_ptr,MODE_CONFIG )) +RMW_BITS (bg_ptr, id, bgap_mode_ctrl, mode_ctrl_mask,0 );/* Start of Conversion = 1 */ - temp =omap_bandgap_readl (bg_ptr, tsr->temp_sensor_ctrl); - temp |=1 <<__ffs (tsr->bgap_soc_mask); -omap_bandgap_writel (bg_ptr, temp, tsr->temp_sensor_ctrl); +RMW_BITS (bg_ptr, id, temp_sensor_ctrl, bgap_soc_mask,1 );/* Wait until DTEMP is updated */ temp =omap_bandgap_read_temp (bg_ptr, id);while ((temp ==0 ) && --counter) temp =omap_bandgap_read_temp (bg_ptr, id); +/* REVISIT: Check correct condition for end of conversion */ /* Start of Conversion = 0 */ - temp =omap_bandgap_readl (bg_ptr, tsr->temp_sensor_ctrl); - temp &= ~(1 <<__ffs (tsr->bgap_soc_mask)); -omap_bandgap_writel (bg_ptr, temp, tsr->temp_sensor_ctrl); +RMW_BITS (bg_ptr, id, temp_sensor_ctrl, bgap_soc_mask,0 );return 0 ; }
@@ -745,17 +655,12 @@ omap_bandgap_force_single_read(struct omap_bandgap *bg_ptr, int id)*/ static int enable_continuous_mode (struct omap_bandgap *bg_ptr) { -struct temp_sensor_registers *tsr;int i; -u32 val;for (i =0 ; i < bg_ptr->conf->sensor_count; i++) {/* Perform a single read just before enabling continuous */ omap_bandgap_force_single_read (bg_ptr, i); - tsr = bg_ptr->conf->sensors[i].registers; - val =omap_bandgap_readl (bg_ptr, tsr->bgap_mode_ctrl); - val |=1 <<__ffs (tsr->mode_ctrl_mask); -omap_bandgap_writel (bg_ptr, val, tsr->bgap_mode_ctrl); +RMW_BITS (bg_ptr, i, bgap_mode_ctrl, mode_ctrl_mask,1 ); }return 0 ;
@@ -955,22 +860,31 @@ int omap_bandgap_probe(struct platform_device *pdev)/* Set default counter to 1 for now */ if (OMAP_BANDGAP_HAS (bg_ptr,COUNTER ))for (i =0 ; i < bg_ptr->conf->sensor_count; i++) -configure_temp_sensor_counter (bg_ptr, i,1 ); +RMW_BITS (bg_ptr, i, bgap_counter, counter_mask,1 ); +/* Set default thresholds for alert and shutdown */ for (i =0 ; i < bg_ptr->conf->sensor_count; i++) {struct temp_sensor_data *ts_data; ts_data = bg_ptr->conf->sensors[i].ts_data; -if (OMAP_BANDGAP_HAS (bg_ptr,TALERT )) -temp_sensor_init_talert_thresholds (bg_ptr, i, - ts_data->t_hot, - ts_data->t_cold); +if (OMAP_BANDGAP_HAS (bg_ptr,TALERT )) { +/* Set initial Talert thresholds */ +RMW_BITS (bg_ptr, i, bgap_threshold, + threshold_tcold_mask, ts_data->t_cold); +RMW_BITS (bg_ptr, i, bgap_threshold, + threshold_thot_mask, ts_data->t_hot); +/* Enable the alert events */ +RMW_BITS (bg_ptr, i, bgap_mask_ctrl, mask_hot_mask,1 ); +RMW_BITS (bg_ptr, i, bgap_mask_ctrl, mask_cold_mask,1 ); + } +if (OMAP_BANDGAP_HAS (bg_ptr,TSHUT_CONFIG )) { -temp_sensor_configure_tshut_hot (bg_ptr, i, - ts_data->tshut_hot); -temp_sensor_configure_tshut_cold (bg_ptr, i, - ts_data->tshut_cold); +/* Set initial Tshut thresholds */ +RMW_BITS (bg_ptr, i, tshut_threshold, + tshut_hot_mask, ts_data->tshut_hot); +RMW_BITS (bg_ptr, i, tshut_threshold, + tshut_cold_mask, ts_data->tshut_cold); } }
@@ -980,8 +894,8 @@ int omap_bandgap_probe(struct platform_device *pdev)/* Set .250 seconds time as default counter */ if (OMAP_BANDGAP_HAS (bg_ptr,COUNTER ))for (i =0 ; i < bg_ptr->conf->sensor_count; i++) -configure_temp_sensor_counter (bg_ptr, i, - bg_ptr->clk_rate /4 ); +RMW_BITS (bg_ptr, i, bgap_counter, counter_mask, + bg_ptr->clk_rate /4 );/* Every thing is good? Then expose the sensors */ for (i =0 ; i < bg_ptr->conf->sensor_count; i++) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 8/50 staging: omap-thermal: add documentation for register access functions
In reply to Eduardo ValentinDocument the helper functions that manipulates registers and their bitfields. All of them work based of the io mapped area.
--- drivers/staging/omap-thermal/omap-bandgap.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +22 -1
@@ -42,17 +42,38 @@#include "omap-bandgap.h" +/** +* omap_bandgap_readl() - simple read helper function +* @bg_ptr: pointer to omap_bandgap structure +* @reg: desired register (offset) to be read +* +* Helper function to read bandgap registers. It uses the io remapped area. +* Returns the register value. +*/ static u32 omap_bandgap_readl (struct omap_bandgap *bg_ptr,u32 reg) {return readl (bg_ptr->base + reg); } +/** +* omap_bandgap_writel() - simple write helper function +* @bg_ptr: pointer to omap_bandgap structure +* @val: desired register value to be written +* @reg: desired register (offset) to be written +* +* Helper function to write bandgap registers. It uses the io remapped area. +*/ static void omap_bandgap_writel (struct omap_bandgap *bg_ptr,u32 val,u32 reg) {writel (val, bg_ptr->base + reg); } -/* update bits, value will be shifted */ +/** +* DOC: macro to update bits. +* +* RMW_BITS() - used to read, modify and update bandgap bitfields. +* The value passed will be shifted. +*/ #define RMW_BITS (bg_ptr, id, reg, mask, val) \ do { \ struct temp_sensor_registers *t; \
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 9/50 staging: omap-thermal: make a omap_bandgap_power with only one exit point
In reply to Eduardo ValentinChange the way the omap_bandgap_power is written so that it has only one exit entry (Documentation/CodingStyle).
--- drivers/staging/omap-thermal/omap-bandgap.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -1
@@ -91,12 +91,13 @@ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)int i;if (!OMAP_BANDGAP_HAS (bg_ptr,POWER_SWITCH )) -return 0 ; + goto exit;for (i =0 ; i < bg_ptr->conf->sensor_count; i++)/* active on 0 */ RMW_BITS (bg_ptr, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on); +exit:return 0 ; }
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 10/50 staging: omap-thermal: add documentation for omap_bandgap_power
In reply to Eduardo ValentinDocument the helper function to turn a bandgap device on and off.
--- drivers/staging/omap-thermal/omap-bandgap.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +8 -0
@@ -86,6 +86,14 @@ do { \omap_bandgap_writel (bg_ptr, r, t->reg); \ }while (0 ) +/** +* omap_bandgap_power() - controls the power state of a bandgap device +* @bg_ptr: pointer to omap_bandgap structure +* @on: desired power state (1 - on, 0 - off) +* +* Used to power on/off a bandgap device instance. Only used on those +* that features tempsoff bit. +*/ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on) {int i;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 11/50 staging: omap-thermal: add documentation for omap_bandgap_read_temp
In reply to Eduardo ValentinDocument function which reads temperature register, depending on bandgap device version.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +10 -0
@@ -109,6 +109,16 @@ exit:return 0 ; } +/** +* omap_bandgap_read_temp() - helper function to read sensor temperature +* @bg_ptr: pointer to omap_bandgap structure +* @id: bandgap sensor id +* +* Function to concentrate the steps to read sensor temperature register. +* This function is desired because, depending on bandgap device version, +* it might be needed to freeze the bandgap state machine, before fetching +* the register value. +*/ static u32 omap_bandgap_read_temp (struct omap_bandgap *bg_ptr,int id) {struct temp_sensor_registers *tsr;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 12/50 staging: omap-thermal: rename talert handler
In reply to Eduardo ValentinSimple rename to cope with file naming pattern.
--- drivers/staging/omap-thermal/omap-bandgap.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -2
@@ -147,7 +147,7 @@ static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id) }/* This is the Talert handler. Call it only if HAS(TALERT) is set */ -static irqreturn_t talert_irq_handler (int irq,void *data) +static irqreturn_t omap_bandgap_talert_irq_handler (int irq,void *data) {struct omap_bandgap *bg_ptr = data;struct temp_sensor_registers *tsr;
@@ -750,7 +750,7 @@ static int omap_bandgap_talert_init(struct omap_bandgap *bg_ptr,return bg_ptr->irq; } ret =request_threaded_irq (bg_ptr->irq,NULL , - talert_irq_handler, + omap_bandgap_talert_irq_handler,IRQF_TRIGGER_HIGH |IRQF_ONESHOT ,"talert" , bg_ptr);if (ret) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 13/50 staging: omap-thermal: update documentation for talert irq handler
In reply to Eduardo ValentinDocument the Talert IRQ handler.
--- drivers/staging/omap-thermal/omap-bandgap.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +11 -1
@@ -146,7 +146,17 @@ static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)return temp; } -/* This is the Talert handler. Call it only if HAS(TALERT) is set */ +/** +* omap_bandgap_talert_irq_handler() - handles Temperature alert IRQs +* @irq: IRQ number +* @data: private data (struct omap_bandgap *) +* +* This is the Talert handler. Use it only if bandgap device features +* HAS(TALERT). This handler goes over all sensors and checks their +* conditions and acts accordingly. In case there are events pending, +* it will reset the event mask to wait for the opposite event (next event). +* Every time there is a new event, it will be reported to thermal layer. +*/ static irqreturn_t omap_bandgap_talert_irq_handler (int irq,void *data) {struct omap_bandgap *bg_ptr = data;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 14/50 staging: omap-thermal: update tshut IRQ handler documentation
In reply to Eduardo ValentinDocuments tshut handler better.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +9 -1
@@ -207,7 +207,15 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)return IRQ_HANDLED ; } -/* This is the Tshut handler. Call it only if HAS(TSHUT) is set */ +/** +* omap_bandgap_tshut_irq_handler() - handles Temperature shutdown signal +* @irq: IRQ number +* @data: private data (unused) +* +* This is the Tshut handler. Use it only if bandgap device features +* HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown +* the system. +*/ static irqreturn_t omap_bandgap_tshut_irq_handler (int irq,void *data) { pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n",
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 15/50 staging: omap-thermal: remove duplicated code
In reply to Eduardo ValentinThere is no need to assign twice the same variable with the very same value.
--- drivers/staging/omap-thermal/omap-bandgap.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +0 -1
@@ -164,7 +164,6 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)u32 t_hot =0 , t_cold =0 , ctrl;int i; - bg_ptr = data;/* Read the status of t_hot */ for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { tsr = bg_ptr->conf->sensors[i].registers;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 16/50 staging: omap-thermal: read status only once inside alert IRQ
In reply to Eduardo ValentinThere is no need to re-read status register.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +5 -5
@@ -164,15 +164,15 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)u32 t_hot =0 , t_cold =0 , ctrl;int i; -/* Read the status of t_hot */ for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { tsr = bg_ptr->conf->sensors[i].registers; - t_hot =omap_bandgap_readl (bg_ptr, tsr->bgap_status); - t_hot &= tsr->status_hot_mask; + ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_status); + +/* Read the status of t_hot */ + t_hot = ctrl & tsr->status_hot_mask;/* Read the status of t_cold */ - t_cold =omap_bandgap_readl (bg_ptr, tsr->bgap_status); - t_cold &= tsr->status_cold_mask; + t_cold = ctrl & tsr->status_cold_mask;if (!t_cold && !t_hot)continue ;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 17/50 staging: omap-thermal: add a section of register manipulation
In reply to Eduardo ValentinThis is introduces a series of marks inside the code to better organize functions per group, aggregating their functionality.
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -42,6 +42,8 @@#include "omap-bandgap.h" +/*** Helper functions to access registers and their bitfields ***/ +/** * omap_bandgap_readl() - simple read helper function * @bg_ptr: pointer to omap_bandgap structure
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 18/50 staging: omap-thermal: section of basic helpers
In reply to Eduardo ValentinGroup of simple functions aggregating basic functionality.
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -88,6 +88,8 @@ do { \omap_bandgap_writel (bg_ptr, r, t->reg); \ }while (0 ) +/*** Basic helper functions ***/ +/** * omap_bandgap_power() - controls the power state of a bandgap device * @bg_ptr: pointer to omap_bandgap structure
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 19/50 staging: omap-thermal: IRQ handler section
In reply to Eduardo ValentinSection of IRQ handlers
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -150,6 +150,8 @@ static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)return temp; } +/*** IRQ handlers ***/ +/** * omap_bandgap_talert_irq_handler() - handles Temperature alert IRQs * @irq: IRQ number
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 20/50 staging: omap-thermal: ADC section
In reply to Eduardo ValentinSection of ADC helpers functions
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -231,6 +231,8 @@ static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)return IRQ_HANDLED ; } +/*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/ +static int adc_to_temp_conversion (struct omap_bandgap *bg_ptr,int id,int adc_val,int *t)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 21/50 staging: omap-thermal: name adc_to_temp_conversion in a better way
In reply to Eduardo ValentinRename adc_to_temp_conversion to omap_bandgap_adc_to_mcelsius. This name, though longer, describes better the function.
--- drivers/staging/omap-thermal/omap-bandgap.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +6 -6
@@ -234,8 +234,8 @@ static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)/*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/ static -int adc_to_temp_conversion (struct omap_bandgap *bg_ptr,int id,int adc_val, -int *t) +int omap_bandgap_adc_to_mcelsius (struct omap_bandgap *bg_ptr,int id, +int adc_val,int *t) {struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data;
@@ -308,7 +308,7 @@ int add_hyst(int adc_val, int hyst_val, struct omap_bandgap *bg_ptr, int i, {int temp, ret; - ret =adc_to_temp_conversion (bg_ptr, i, adc_val, &temp); + ret =omap_bandgap_adc_to_mcelsius (bg_ptr, i, adc_val, &temp);if (ret <0 )return ret;
@@ -439,7 +439,7 @@ int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); temp = (temp & tsr->threshold_thot_mask) >>__ffs (tsr->threshold_thot_mask); - ret |=adc_to_temp_conversion (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp);if (ret) {dev_err (bg_ptr->dev,"failed to read thot\n" );return -EIO ;
@@ -514,7 +514,7 @@ int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); temp = (temp & tsr->threshold_tcold_mask) >>__ffs (tsr->threshold_tcold_mask); - ret |=adc_to_temp_conversion (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp);if (ret)return -EIO ;
@@ -641,7 +641,7 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_read_temp (bg_ptr, id);mutex_unlock (&bg_ptr->bg_mutex); - ret |=adc_to_temp_conversion (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp);if (ret)return -EIO ;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 22/50 staging: omap-thermal: rewrite omap_bandgap_adc_to_mcelsius on kernel coding style
In reply to Eduardo ValentinFollow Documentation/CodingStyle while doing omap_bandgap_adc_to_mcelsius.
--- drivers/staging/omap-thermal/omap-bandgap.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +8 -3
@@ -238,14 +238,19 @@ int omap_bandgap_adc_to_mcelsius(struct omap_bandgap *bg_ptr, int id, int adc_val, int *t) { struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data; +int ret =0 ;/* look up for temperature in the table and return the temperature */ -if (adc_val < ts_data->adc_start_val || adc_val > ts_data->adc_end_val) -return -ERANGE ; +if (adc_val < ts_data->adc_start_val || + adc_val > ts_data->adc_end_val) { + ret = -ERANGE ; + goto exit; + } *t = bg_ptr->conf->conv_table[adc_val - ts_data->adc_start_val]; -return 0 ; +exit: +return ret; } static int temp_to_adc_conversion(long temp, struct omap_bandgap *bg_ptr, int i,
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 23/50 staging: omap-thermal: add documentation for omap_bandgap_adc_to_mcelsius
In reply to Eduardo ValentinDocument the conversion function.
--- drivers/staging/omap-thermal/omap-bandgap.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +11 -0
@@ -233,6 +233,17 @@ static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)/*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/ +/** +* omap_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale +* @bg_ptr: struct omap_bandgap pointer +* @id: sensor id +* @adc_val: value in ADC representation +* @t: address where to write the resulting temperature in mCelsius +* +* Simple conversion from ADC representation to mCelsius. In case the ADC value +* is out of the ADC conv table range, it returns -ERANGE, 0 on success. +* The conversion table is indexed by the ADC values. +*/ static int omap_bandgap_adc_to_mcelsius (struct omap_bandgap *bg_ptr,int id,int adc_val,int *t)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 24/50 staging: omap-thermal: name temp_to_adc_conversion in a better way
In reply to Eduardo ValentinRename temp_to_adc_conversion to omap_bandgap_mcelsius_to_adc. This name, though longer, describes better the function.
This patch also changes this function signature so the function follows the style of this file.
--- drivers/staging/omap-thermal/omap-bandgap.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +6 -5
@@ -264,8 +264,9 @@ exit:return ret; } -static int temp_to_adc_conversion (long temp,struct omap_bandgap *bg_ptr,int i, -int *adc) +static +int omap_bandgap_mcelsius_to_adc (struct omap_bandgap *bg_ptr,int i,long temp, +int *adc) {struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[i].ts_data;const int *conv_table = bg_ptr->conf->conv_table;
@@ -330,7 +331,7 @@ int add_hyst(int adc_val, int hyst_val, struct omap_bandgap *bg_ptr, int i, temp += hyst_val; -return temp_to_adc_conversion (temp, bg_ptr, i, sum); +return omap_bandgap_mcelsius_to_adc (bg_ptr, i, temp, sum); }/* Talert Thot threshold. Call it only if HAS(TALERT) is set */
@@ -493,7 +494,7 @@ int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val)if (val < ts_data->min_temp + ts_data->hyst_val)return -EINVAL ; - ret =temp_to_adc_conversion (val, bg_ptr, id, &t_hot); + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, id, val, &t_hot);if (ret <0 )return ret;
@@ -566,7 +567,7 @@ int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val)if (val > ts_data->max_temp + ts_data->hyst_val)return -EINVAL ; - ret =temp_to_adc_conversion (val, bg_ptr, id, &t_cold); + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, id, val, &t_cold);if (ret <0 )return ret;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 25/50 staging: omap-thermal: rewrite omap_bandgap_mcelsius_to_adc on kernel coding style
In reply to Eduardo ValentinFollow Documentation/CodingStyle while doing omap_bandgap_mcelsius_to_adc
--- drivers/staging/omap-thermal/omap-bandgap.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +7 -4
@@ -270,14 +270,16 @@ int omap_bandgap_mcelsius_to_adc(struct omap_bandgap *bg_ptr, int i, long temp, {struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[i].ts_data;const int *conv_table = bg_ptr->conf->conv_table; -int high, low, mid; +int high, low, mid, ret =0 ; low =0 ; high = ts_data->adc_end_val - ts_data->adc_start_val; mid = (high + low) /2 ; -if (temp < conv_table[low] || temp > conv_table[high]) -return -EINVAL ; +if (temp < conv_table[low] || temp > conv_table[high]) { + ret = -ERANGE ; + goto exit; + }while (low < high) {if (temp < conv_table[mid])
@@ -289,7 +291,8 @@ int omap_bandgap_mcelsius_to_adc(struct omap_bandgap *bg_ptr, int i, long temp, *adc = ts_data->adc_start_val + low; -return 0 ; +exit: +return ret; }/* Talert masks. Call it only if HAS(TALERT) is set */
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 26/50 staging: omap-thermal: move conv table limits out of sensor data
In reply to Eduardo ValentinAs we have one conv table per bandgap device and not per sensor, this patch changes the data structures so that the conv table min and max values are now part of bandgap_data and not sensor_data.
--- drivers/staging/omap-thermal/omap-bandgap.c | 39 +++++++++----------- drivers/staging/omap-thermal/omap-bandgap.h | 8 ++-- drivers/staging/omap-thermal/omap4-thermal-data.c | 10 +++-- drivers/staging/omap-thermal/omap5-thermal-data.c | 8 +--- 4 files changed, 30 insertions(+), 35 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +18 -21
@@ -236,7 +236,6 @@ static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)/** * omap_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale * @bg_ptr: struct omap_bandgap pointer -* @id: sensor id * @adc_val: value in ADC representation * @t: address where to write the resulting temperature in mCelsius *
@@ -245,35 +244,34 @@ static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)* The conversion table is indexed by the ADC values. */ static -int omap_bandgap_adc_to_mcelsius (struct omap_bandgap *bg_ptr,int id, +int omap_bandgap_adc_to_mcelsius (struct omap_bandgap *bg_ptr,int adc_val,int *t) { -struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data; +struct omap_bandgap_data *conf = bg_ptr->conf;int ret =0 ;/* look up for temperature in the table and return the temperature */ -if (adc_val < ts_data->adc_start_val || - adc_val > ts_data->adc_end_val) { +if (adc_val < conf->adc_start_val || adc_val > conf->adc_end_val) { ret = -ERANGE ; goto exit; } - *t = bg_ptr->conf->conv_table[adc_val - ts_data->adc_start_val]; + *t = bg_ptr->conf->conv_table[adc_val - conf->adc_start_val]; exit:return ret; }static -int omap_bandgap_mcelsius_to_adc (struct omap_bandgap *bg_ptr,int i,long temp, +int omap_bandgap_mcelsius_to_adc (struct omap_bandgap *bg_ptr,long temp,int *adc) { -struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[i].ts_data; +struct omap_bandgap_data *conf = bg_ptr->conf;const int *conv_table = bg_ptr->conf->conv_table;int high, low, mid, ret =0 ; low =0 ; - high = ts_data->adc_end_val - ts_data->adc_start_val; + high = conf->adc_end_val - conf->adc_start_val; mid = (high + low) /2 ;if (temp < conv_table[low] || temp > conv_table[high]) {
@@ -289,7 +287,7 @@ int omap_bandgap_mcelsius_to_adc(struct omap_bandgap *bg_ptr, int i, long temp, mid = (low + high) /2 ; } - *adc = ts_data->adc_start_val + low; + *adc = conf->adc_start_val + low; exit:return ret;
@@ -323,18 +321,17 @@ static int temp_sensor_unmask_interrupts(struct omap_bandgap *bg_ptr, int id, }static -int add_hyst (int adc_val,int hyst_val,struct omap_bandgap *bg_ptr,int i, -u32 *sum) +int add_hyst (int adc_val,int hyst_val,struct omap_bandgap *bg_ptr,u32 *sum) {int temp, ret; - ret =omap_bandgap_adc_to_mcelsius (bg_ptr, i, adc_val, &temp); + ret =omap_bandgap_adc_to_mcelsius (bg_ptr, adc_val, &temp);if (ret <0 )return ret; temp += hyst_val; -return omap_bandgap_mcelsius_to_adc (bg_ptr, i, temp, sum); +return omap_bandgap_mcelsius_to_adc (bg_ptr, temp, sum); }/* Talert Thot threshold. Call it only if HAS(TALERT) is set */
@@ -354,7 +351,7 @@ int temp_sensor_configure_thot(struct omap_bandgap *bg_ptr, int id, int t_hot)__ffs (tsr->threshold_tcold_mask);if (t_hot <= cold) {/* change the t_cold to t_hot - 5000 millidegrees */ - err |=add_hyst (t_hot, -ts_data->hyst_val, bg_ptr, id, &cold); + err |=add_hyst (t_hot, -ts_data->hyst_val, bg_ptr, &cold);/* write the new t_cold value */ reg_val = thresh_val & (~tsr->threshold_tcold_mask); reg_val |= cold <<__ffs (tsr->threshold_tcold_mask);
@@ -392,7 +389,7 @@ int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,if (t_cold >= hot) {/* change the t_hot to t_cold + 5000 millidegrees */ - err |=add_hyst (t_cold, ts_data->hyst_val, bg_ptr, id, &hot); + err |=add_hyst (t_cold, ts_data->hyst_val, bg_ptr, &hot);/* write the new t_hot value */ reg_val = thresh_val & (~tsr->threshold_thot_mask); reg_val |= hot <<__ffs (tsr->threshold_thot_mask);
@@ -459,7 +456,7 @@ int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); temp = (temp & tsr->threshold_thot_mask) >>__ffs (tsr->threshold_thot_mask); - ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp);if (ret) {dev_err (bg_ptr->dev,"failed to read thot\n" );return -EIO ;
@@ -497,7 +494,7 @@ int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val)if (val < ts_data->min_temp + ts_data->hyst_val)return -EINVAL ; - ret =omap_bandgap_mcelsius_to_adc (bg_ptr, id, val, &t_hot); + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, val, &t_hot);if (ret <0 )return ret;
@@ -534,7 +531,7 @@ int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); temp = (temp & tsr->threshold_tcold_mask) >>__ffs (tsr->threshold_tcold_mask); - ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp);if (ret)return -EIO ;
@@ -570,7 +567,7 @@ int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val)if (val > ts_data->max_temp + ts_data->hyst_val)return -EINVAL ; - ret =omap_bandgap_mcelsius_to_adc (bg_ptr, id, val, &t_cold); + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, val, &t_cold);if (ret <0 )return ret;
@@ -661,7 +658,7 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id, temp =omap_bandgap_read_temp (bg_ptr, id);mutex_unlock (&bg_ptr->bg_mutex); - ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, id, temp, &temp); + ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp);if (ret)return -EIO ;
drivers/staging/omap-thermal/omap-bandgap.h +4 -4
@@ -166,8 +166,6 @@ struct temp_sensor_registers {* @max_temp: sensor maximum temperature * @min_temp: sensor minimum temperature * @hyst_val: temperature hysteresis considered while converting ADC values -* @adc_start_val: ADC conversion table starting value -* @adc_end_val: ADC conversion table ending value * @update_int1: update interval * @update_int2: update interval *
@@ -185,8 +183,6 @@ struct temp_sensor_data {int max_temp;int min_temp;int hyst_val; -u32 adc_start_val; -u32 adc_end_val;u32 update_int1;/* not used */ u32 update_int2;/* not used */ };
@@ -325,6 +321,8 @@ struct omap_temp_sensor {* struct omap_bandgap_data - omap bandgap data configuration structure * @features: a bitwise flag set to describe the device features * @conv_table: Pointer to ADC to temperature conversion table +* @adc_start_val: ADC conversion table starting value +* @adc_end_val: ADC conversion table ending value * @fclock_name: clock name of the functional clock * @div_ck_name: clock name of the clock divisor * @sensor_count: count of temperature sensor within this bandgap device
@@ -342,6 +340,8 @@ struct omap_temp_sensor {struct omap_bandgap_data {unsigned int features;const int *conv_table; +u32 adc_start_val; +u32 adc_end_val;char *fclock_name;char *div_ck_name;int sensor_count;
drivers/staging/omap-thermal/omap4-thermal-data.c +6 -4
@@ -45,8 +45,6 @@ static struct temp_sensor_data omap4430_mpu_temp_sensor_data = { .max_temp = OMAP4430_MAX_TEMP, .min_temp = OMAP4430_MIN_TEMP, .hyst_val = OMAP4430_HYST_VAL, - .adc_start_val = OMAP4430_ADC_START_VALUE, - .adc_end_val = OMAP4430_ADC_END_VALUE, };/*
@@ -75,6 +73,8 @@ const struct omap_bandgap_data omap4430_data = { .fclock_name = "bandgap_fclk", .div_ck_name = "bandgap_fclk", .conv_table = omap4430_adc_to_temp, + .adc_start_val = OMAP4430_ADC_START_VALUE, + .adc_end_val = OMAP4430_ADC_END_VALUE, .expose_sensor = omap_thermal_expose_sensor, .remove_sensor = omap_thermal_remove_sensor, .sensors = {
@@ -142,8 +142,6 @@ static struct temp_sensor_data omap4460_mpu_temp_sensor_data = { .max_temp = OMAP4460_MAX_TEMP, .min_temp = OMAP4460_MIN_TEMP, .hyst_val = OMAP4460_HYST_VAL, - .adc_start_val = OMAP4460_ADC_START_VALUE, - .adc_end_val = OMAP4460_ADC_END_VALUE, .update_int1 = 1000, .update_int2 = 2000, };
@@ -214,6 +212,8 @@ const struct omap_bandgap_data omap4460_data = { .fclock_name = "bandgap_ts_fclk", .div_ck_name = "div_ts_ck", .conv_table = omap4460_adc_to_temp, + .adc_start_val = OMAP4460_ADC_START_VALUE, + .adc_end_val = OMAP4460_ADC_END_VALUE, .expose_sensor = omap_thermal_expose_sensor, .remove_sensor = omap_thermal_remove_sensor, .sensors = {
@@ -244,6 +244,8 @@ const struct omap_bandgap_data omap4470_data = { .fclock_name = "bandgap_ts_fclk", .div_ck_name = "div_ts_ck", .conv_table = omap4460_adc_to_temp, + .adc_start_val = OMAP4460_ADC_START_VALUE, + .adc_end_val = OMAP4460_ADC_END_VALUE, .expose_sensor = omap_thermal_expose_sensor, .remove_sensor = omap_thermal_remove_sensor, .sensors = {
drivers/staging/omap-thermal/omap5-thermal-data.c +2 -6
@@ -171,8 +171,6 @@ static struct temp_sensor_data omap5430_mpu_temp_sensor_data = { .max_temp = OMAP5430_MPU_MAX_TEMP, .min_temp = OMAP5430_MPU_MIN_TEMP, .hyst_val = OMAP5430_MPU_HYST_VAL, - .adc_start_val = OMAP5430_ADC_START_VALUE, - .adc_end_val = OMAP5430_ADC_END_VALUE, .update_int1 = 1000, .update_int2 = 2000, };
@@ -188,8 +186,6 @@ static struct temp_sensor_data omap5430_gpu_temp_sensor_data = { .max_temp = OMAP5430_GPU_MAX_TEMP, .min_temp = OMAP5430_GPU_MIN_TEMP, .hyst_val = OMAP5430_GPU_HYST_VAL, - .adc_start_val = OMAP5430_ADC_START_VALUE, - .adc_end_val = OMAP5430_ADC_END_VALUE, .update_int1 = 1000, .update_int2 = 2000, };
@@ -205,8 +201,6 @@ static struct temp_sensor_data omap5430_core_temp_sensor_data = { .max_temp = OMAP5430_CORE_MAX_TEMP, .min_temp = OMAP5430_CORE_MIN_TEMP, .hyst_val = OMAP5430_CORE_HYST_VAL, - .adc_start_val = OMAP5430_ADC_START_VALUE, - .adc_end_val = OMAP5430_ADC_END_VALUE, .update_int1 = 1000, .update_int2 = 2000, };
@@ -325,6 +319,8 @@ const struct omap_bandgap_data omap5430_data = { .fclock_name = "l3instr_ts_gclk_div", .div_ck_name = "l3instr_ts_gclk_div", .conv_table = omap5430_adc_to_temp, + .adc_start_val = OMAP5430_ADC_START_VALUE, + .adc_end_val = OMAP5430_ADC_END_VALUE, .expose_sensor = omap_thermal_expose_sensor, .remove_sensor = omap_thermal_remove_sensor, .sensors = {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 27/50 staging: omap-thermal: add documentation for omap_bandgap_mcelsius_to_adc
In reply to Eduardo ValentinDocument the conversion function.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +10 -0
@@ -262,6 +262,16 @@ exit:return ret; } +/** +* omap_bandgap_mcelsius_to_adc() - converts a mCelsius value to ADC scale +* @bg_ptr: struct omap_bandgap pointer +* @temp: value in mCelsius +* @adc: address where to write the resulting temperature in ADC representation +* +* Simple conversion from mCelsius to ADC values. In case the temp value +* is out of the ADC conv table range, it returns -ERANGE, 0 on success. +* The conversion table is indexed by the ADC values. +*/ static int omap_bandgap_mcelsius_to_adc (struct omap_bandgap *bg_ptr,long temp,int *adc)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 28/50 staging: omap-thermal: rename add_hyst to omap_bandgap_add_hyst
In reply to Eduardo ValentinThis patch improves the add_hyst function by:
. Renaming it to omap_bandgap_add_hyst
. Moving it to the ADC conversion functions section . Changing its signature to follow the driver standard
--- drivers/staging/omap-thermal/omap-bandgap.c | 42 ++++++++++++++++---------- 1 files changed, 26 insertions(+), 16 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +26 -16
@@ -303,6 +303,28 @@ exit:return ret; } +static +int omap_bandgap_add_hyst (struct omap_bandgap *bg_ptr,int adc_val, +int hyst_val,u32 *sum) +{ +int temp, ret; + +/* +* Need to add in the mcelsius domain, so we have a temperature +* the conv_table range +*/ + ret =omap_bandgap_adc_to_mcelsius (bg_ptr, adc_val, &temp); +if (ret <0 ) + goto exit; + + temp += hyst_val; + + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, temp, sum); + +exit: +return ret; +} +/* Talert masks. Call it only if HAS(TALERT) is set */ static int temp_sensor_unmask_interrupts (struct omap_bandgap *bg_ptr,int id,u32 t_hot,u32 t_cold)
@@ -330,20 +352,6 @@ static int temp_sensor_unmask_interrupts(struct omap_bandgap *bg_ptr, int id,return 0 ; } -static -int add_hyst (int adc_val,int hyst_val,struct omap_bandgap *bg_ptr,u32 *sum) -{ -int temp, ret; - - ret =omap_bandgap_adc_to_mcelsius (bg_ptr, adc_val, &temp); -if (ret <0 ) -return ret; - - temp += hyst_val; - -return omap_bandgap_mcelsius_to_adc (bg_ptr, temp, sum); -} -/* Talert Thot threshold. Call it only if HAS(TALERT) is set */ static int temp_sensor_configure_thot (struct omap_bandgap *bg_ptr,int id,int t_hot)
@@ -361,7 +369,8 @@ int temp_sensor_configure_thot(struct omap_bandgap *bg_ptr, int id, int t_hot)__ffs (tsr->threshold_tcold_mask);if (t_hot <= cold) {/* change the t_cold to t_hot - 5000 millidegrees */ - err |=add_hyst (t_hot, -ts_data->hyst_val, bg_ptr, &cold); + err |=omap_bandgap_add_hyst (bg_ptr, t_hot, + -ts_data->hyst_val, &cold);/* write the new t_cold value */ reg_val = thresh_val & (~tsr->threshold_tcold_mask); reg_val |= cold <<__ffs (tsr->threshold_tcold_mask);
@@ -399,7 +408,8 @@ int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,if (t_cold >= hot) {/* change the t_hot to t_cold + 5000 millidegrees */ - err |=add_hyst (t_cold, ts_data->hyst_val, bg_ptr, &hot); + err |=omap_bandgap_add_hyst (bg_ptr, t_cold, + ts_data->hyst_val, &hot);/* write the new t_hot value */ reg_val = thresh_val & (~tsr->threshold_thot_mask); reg_val |= hot <<__ffs (tsr->threshold_thot_mask);
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 29/50 staging: omap-thermal: document omap_bandgap_add_hyst function
In reply to Eduardo ValentinDocument function to handle hysteresis.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +10 -0
@@ -303,6 +303,16 @@ exit:return ret; } +/** +* omap_bandgap_add_hyst() - add hysteresis (in mCelsius) to an ADC value +* @bg_ptr: struct omap_bandgap pointer +* @adc_val: temperature value in ADC representation +* @hyst_val: hysteresis value in mCelsius +* @sum: address where to write the resulting temperature (in ADC scale) +* +* Adds an hysteresis value (in mCelsius) to a ADC temperature value. +* Returns 0 on success, -ERANGE otherwise. +*/ static int omap_bandgap_add_hyst (struct omap_bandgap *bg_ptr,int adc_val,int hyst_val,u32 *sum)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 30/50 staging: omap-thermal: threshold manipulation section
In reply to Eduardo ValentinSection of functions manipulating thresholds for Alert and Shutdown.
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -335,6 +335,8 @@ exit:return ret; } +/*** Helper functions handling device Alert/Shutdown signals ***/ +/* Talert masks. Call it only if HAS(TALERT) is set */ static int temp_sensor_unmask_interrupts (struct omap_bandgap *bg_ptr,int id,u32 t_hot,u32 t_cold)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 31/50 staging: omap-thermal: refactor temp_sensor_unmask_interrupts
In reply to Eduardo ValentinThis change improves temp_sensor_unmask_interrupts by:
. renaming it to omap_bandgap_unmask_interrupts
. making it a void function, as there is nothing really to report an error.
--- drivers/staging/omap-thermal/omap-bandgap.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +8 -6
@@ -338,8 +338,8 @@ exit:/*** Helper functions handling device Alert/Shutdown signals ***/ /* Talert masks. Call it only if HAS(TALERT) is set */ -static int temp_sensor_unmask_interrupts (struct omap_bandgap *bg_ptr,int id, -u32 t_hot,u32 t_cold) +static void omap_bandgap_unmask_interrupts (struct omap_bandgap *bg_ptr,int id, +u32 t_hot,u32 t_cold) {struct temp_sensor_registers *tsr;u32 temp, reg_val;
@@ -360,8 +360,6 @@ static int temp_sensor_unmask_interrupts(struct omap_bandgap *bg_ptr, int id,else reg_val &= ~tsr->mask_cold_mask;omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_mask_ctrl); - -return 0 ; }/* Talert Thot threshold. Call it only if HAS(TALERT) is set */
@@ -399,7 +397,9 @@ int temp_sensor_configure_thot(struct omap_bandgap *bg_ptr, int id, int t_hot)return -EIO ; } -return temp_sensor_unmask_interrupts (bg_ptr, id, t_hot, cold); +omap_bandgap_unmask_interrupts (bg_ptr, id, t_hot, cold); + +return 0 ; }/* Talert Tcold threshold. Call it only if HAS(TALERT) is set */
@@ -438,7 +438,9 @@ int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,return -EIO ; } -return temp_sensor_unmask_interrupts (bg_ptr, id, hot, t_cold); +omap_bandgap_unmask_interrupts (bg_ptr, id, hot, t_cold); + +return 0 ; }#define bandgap_is_valid (b) \
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 32/50 staging: omap-thermal: update omap_bandgap_unmask_interrupts documentation
In reply to Eduardo ValentinProper document the function to configure the IRQ event masks.
--- drivers/staging/omap-thermal/omap-bandgap.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +9 -1
@@ -337,7 +337,15 @@ exit:/*** Helper functions handling device Alert/Shutdown signals ***/ -/* Talert masks. Call it only if HAS(TALERT) is set */ +/** +* omap_bandgap_unmask_interrupts() - unmasks the events of thot & tcold +* @bg_ptr: struct omap_bandgap pointer +* @t_hot: hot temperature value to trigger alert signal +* @t_cold: cold temperature value to trigger alert signal +* +* Checks the requested t_hot and t_cold values and configures the IRQ event +* masks accordingly. Call this function only if bandgap features HAS(TALERT). +*/ static void omap_bandgap_unmask_interrupts (struct omap_bandgap *bg_ptr,int id,u32 t_hot,u32 t_cold) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 33/50 staging: omap-thermal: refactor APIs handling threshold values
In reply to Eduardo ValentinThis patch improves the code that handles threshold values by creating single functions that are usable for tcold and thot. This way we won't have duplicated functionality just because it is handling different bitfields. Now the added functions are reused in several places where it is needed to update any threshold.
This patch also removes macros that are used only inside the _validate helper function.
In this patch there is also an addition of an extra function section for Exposed APIs, used outside the omap-bandgap.c, but inside the omap-thermal driver.
--- drivers/staging/omap-thermal/omap-bandgap.c | 278 +++++++++++---------------- 1 files changed, 117 insertions(+), 161 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +117 -161
@@ -370,145 +370,172 @@ static void omap_bandgap_unmask_interrupts(struct omap_bandgap *bg_ptr, int id,omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_mask_ctrl); } -/* Talert Thot threshold. Call it only if HAS(TALERT) is set */ static -int temp_sensor_configure_thot (struct omap_bandgap *bg_ptr,int id,int t_hot) +int omap_bandgap_update_alert_threshold (struct omap_bandgap *bg_ptr,int id, +int val,bool hot) {struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data;struct temp_sensor_registers *tsr; -u32 thresh_val, reg_val; -int cold, err =0 ; +u32 thresh_val, reg_val, t_hot, t_cold; +int err =0 ; tsr = bg_ptr->conf->sensors[id].registers; -/* obtain the T cold value */ +/* obtain the current value */ thresh_val =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - cold = (thresh_val & tsr->threshold_tcold_mask) >> -__ffs (tsr->threshold_tcold_mask); -if (t_hot <= cold) { -/* change the t_cold to t_hot - 5000 millidegrees */ - err |=omap_bandgap_add_hyst (bg_ptr, t_hot, - -ts_data->hyst_val, &cold); -/* write the new t_cold value */ - reg_val = thresh_val & (~tsr->threshold_tcold_mask); - reg_val |= cold <<__ffs (tsr->threshold_tcold_mask); -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); - thresh_val = reg_val; + t_cold = (thresh_val & tsr->threshold_tcold_mask) >> +__ffs (tsr->threshold_tcold_mask); + t_hot = (thresh_val & tsr->threshold_thot_mask) >> +__ffs (tsr->threshold_thot_mask); +if (hot) + t_hot = val; +else + t_cold = val; + +if (t_cold < t_hot) { +if (hot) + err =omap_bandgap_add_hyst (bg_ptr, t_hot, + -ts_data->hyst_val, + &t_cold); +else + err =omap_bandgap_add_hyst (bg_ptr, t_cold, + ts_data->hyst_val, + &t_hot); } -/* write the new t_hot value */ +/* write the new threshold values */ reg_val = thresh_val & ~tsr->threshold_thot_mask; reg_val |= (t_hot <<__ffs (tsr->threshold_thot_mask)); + reg_val |= thresh_val & ~tsr->threshold_tcold_mask; + reg_val |= (t_cold <<__ffs (tsr->threshold_tcold_mask));omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); +if (err) {dev_err (bg_ptr->dev,"failed to reprogram thot threshold\n" ); -return -EIO ; + err = -EIO ; + goto exit; } -omap_bandgap_unmask_interrupts (bg_ptr, id, t_hot, cold); - -return 0 ; +omap_bandgap_unmask_interrupts (bg_ptr, id, t_hot, t_cold); +exit: +return err; } -/* Talert Tcold threshold. Call it only if HAS(TALERT) is set */ -static -int temp_sensor_configure_tcold (struct omap_bandgap *bg_ptr,int id, -int t_cold) +static inline int omap_bandgap_validate (struct omap_bandgap *bg_ptr,int id) { -struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data; -struct temp_sensor_registers *tsr; -u32 thresh_val, reg_val; -int hot, err =0 ; +int ret =0 ; - tsr = bg_ptr->conf->sensors[id].registers; -/* obtain the T cold value */ - thresh_val =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - hot = (thresh_val & tsr->threshold_thot_mask) >> -__ffs (tsr->threshold_thot_mask); - -if (t_cold >= hot) { -/* change the t_hot to t_cold + 5000 millidegrees */ - err |=omap_bandgap_add_hyst (bg_ptr, t_cold, - ts_data->hyst_val, &hot); -/* write the new t_hot value */ - reg_val = thresh_val & (~tsr->threshold_thot_mask); - reg_val |= hot <<__ffs (tsr->threshold_thot_mask); -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); - thresh_val = reg_val; +if (IS_ERR_OR_NULL (bg_ptr)) { +pr_err ("%s: invalid bandgap pointer\n" , __func__); + ret = -EINVAL ; + goto exit; } -/* write the new t_cold value */ - reg_val = thresh_val & ~tsr->threshold_tcold_mask; - reg_val |= (t_cold <<__ffs (tsr->threshold_tcold_mask)); -omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_threshold); -if (err) { -dev_err (bg_ptr->dev,"failed to reprogram tcold threshold\n" ); -return -EIO ; +if ((id <0 ) || (id >= bg_ptr->conf->sensor_count)) { +dev_err (bg_ptr->dev,"%s: sensor id out of range (%d)\n" , + __func__, id); + ret = -ERANGE ; } -omap_bandgap_unmask_interrupts (bg_ptr, id, hot, t_cold); - -return 0 ; +exit: +return ret; } -#define bandgap_is_valid (b) \ - (!IS_ERR_OR_NULL(b)) -#define bandgap_is_valid_sensor_id (b, i) \ - ((i) >= 0 && (i) < (b)->conf->sensor_count) -static inline int omap_bandgap_validate (struct omap_bandgap *bg_ptr,int id) +int _omap_bandgap_write_threshold (struct omap_bandgap *bg_ptr,int id,int val, +bool hot) { -if (!bandgap_is_valid (bg_ptr)) { -pr_err ("%s: invalid bandgap pointer\n" , __func__); -return -EINVAL ; +struct temp_sensor_data *ts_data; +struct temp_sensor_registers *tsr; +u32 adc_val; +int ret; + + ret =omap_bandgap_validate (bg_ptr, id); +if (ret) + goto exit; + +if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) { + ret = -ENOTSUPP ; + goto exit; } -if (!bandgap_is_valid_sensor_id (bg_ptr, id)) { -dev_err (bg_ptr->dev,"%s: sensor id out of range (%d)\n" , - __func__, id); -return -ERANGE ; + ts_data = bg_ptr->conf->sensors[id].ts_data; + tsr = bg_ptr->conf->sensors[id].registers; +if (hot) { +if (val < ts_data->min_temp + ts_data->hyst_val) + ret = -EINVAL ; + }else { +if (val > ts_data->max_temp + ts_data->hyst_val) + ret = -EINVAL ; } -return 0 ; +if (ret) + goto exit; + + ret =omap_bandgap_mcelsius_to_adc (bg_ptr, val, &adc_val); +if (ret <0 ) + goto exit; + +mutex_lock (&bg_ptr->bg_mutex); +omap_bandgap_update_alert_threshold (bg_ptr, id, adc_val, hot); +mutex_unlock (&bg_ptr->bg_mutex); + +exit: +return ret; } -/* Exposed APIs */ -/** -* omap_bandgap_read_thot() - reads sensor current thot -* @bg_ptr - pointer to bandgap instance -* @id - sensor id -* @thot - resulting current thot value -* -* returns 0 on success or the proper error code -*/ -int omap_bandgap_read_thot (struct omap_bandgap *bg_ptr,int id, -int *thot) +int _omap_bandgap_read_threshold (struct omap_bandgap *bg_ptr,int id, +int *val,bool hot) {struct temp_sensor_registers *tsr; -u32 temp; -int ret; +u32 temp, mask; +int ret =0 ; ret =omap_bandgap_validate (bg_ptr, id);if (ret) -return ret; + goto exit; -if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) -return -ENOTSUPP ; +if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) { + ret = -ENOTSUPP ; + goto exit; + } tsr = bg_ptr->conf->sensors[id].registers; +if (hot) + mask = tsr->threshold_thot_mask; +else + mask = tsr->threshold_tcold_mask; + temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - temp = (temp & tsr->threshold_thot_mask) >> -__ffs (tsr->threshold_thot_mask); + temp = (temp & mask) >>__ffs (mask); ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp);if (ret) {dev_err (bg_ptr->dev,"failed to read thot\n" ); -return -EIO ; + ret = -EIO ; + goto exit; } - *thot = temp; + *val = temp; +exit:return 0 ; } +/*** Exposed APIs ***/ + +/** +* omap_bandgap_read_thot() - reads sensor current thot +* @bg_ptr - pointer to bandgap instance +* @id - sensor id +* @thot - resulting current thot value +* +* returns 0 on success or the proper error code +*/ +int omap_bandgap_read_thot (struct omap_bandgap *bg_ptr,int id, +int *thot) +{ +return _omap_bandgap_read_threshold (bg_ptr, id, thot, true); +} +/** * omap_bandgap_write_thot() - sets sensor current thot * @bg_ptr - pointer to bandgap instance
@@ -519,32 +546,7 @@ int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id,*/ int omap_bandgap_write_thot (struct omap_bandgap *bg_ptr,int id,int val) { -struct temp_sensor_data *ts_data; -struct temp_sensor_registers *tsr; -u32 t_hot; -int ret; - - ret =omap_bandgap_validate (bg_ptr, id); -if (ret) -return ret; - -if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) -return -ENOTSUPP ; - - ts_data = bg_ptr->conf->sensors[id].ts_data; - tsr = bg_ptr->conf->sensors[id].registers; - -if (val < ts_data->min_temp + ts_data->hyst_val) -return -EINVAL ; - ret =omap_bandgap_mcelsius_to_adc (bg_ptr, val, &t_hot); -if (ret <0 ) -return ret; - -mutex_lock (&bg_ptr->bg_mutex); -temp_sensor_configure_thot (bg_ptr, id, t_hot); -mutex_unlock (&bg_ptr->bg_mutex); - -return 0 ; +return _omap_bandgap_write_threshold (bg_ptr, id, val, true); }/**
@@ -558,28 +560,7 @@ int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val)int omap_bandgap_read_tcold (struct omap_bandgap *bg_ptr,int id,int *tcold) { -struct temp_sensor_registers *tsr; -u32 temp; -int ret; - - ret =omap_bandgap_validate (bg_ptr, id); -if (ret) -return ret; - -if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) -return -ENOTSUPP ; - - tsr = bg_ptr->conf->sensors[id].registers; - temp =omap_bandgap_readl (bg_ptr, tsr->bgap_threshold); - temp = (temp & tsr->threshold_tcold_mask) - >>__ffs (tsr->threshold_tcold_mask); - ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp); -if (ret) -return -EIO ; - - *tcold = temp; - -return 0 ; +return _omap_bandgap_read_threshold (bg_ptr, id, tcold, false); }/**
@@ -592,32 +573,7 @@ int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id,*/ int omap_bandgap_write_tcold (struct omap_bandgap *bg_ptr,int id,int val) { -struct temp_sensor_data *ts_data; -struct temp_sensor_registers *tsr; -u32 t_cold; -int ret; - - ret =omap_bandgap_validate (bg_ptr, id); -if (ret) -return ret; - -if (!OMAP_BANDGAP_HAS (bg_ptr,TALERT )) -return -ENOTSUPP ; - - ts_data = bg_ptr->conf->sensors[id].ts_data; - tsr = bg_ptr->conf->sensors[id].registers; -if (val > ts_data->max_temp + ts_data->hyst_val) -return -EINVAL ; - - ret =omap_bandgap_mcelsius_to_adc (bg_ptr, val, &t_cold); -if (ret <0 ) -return ret; - -mutex_lock (&bg_ptr->bg_mutex); -temp_sensor_configure_tcold (bg_ptr, id, t_cold); -mutex_unlock (&bg_ptr->bg_mutex); - -return 0 ; +return _omap_bandgap_write_threshold (bg_ptr, id, val, false); }/**
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 34/50 staging: omap-thermal: device initialization section
In reply to Eduardo ValentinSection of helper functions to initilize the bandgap device
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -703,6 +703,8 @@ void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id)return bg_ptr->conf->sensors[id].data; } +/*** Helper functions used during device initialization ***/ +static int omap_bandgap_force_single_read (struct omap_bandgap *bg_ptr,int id) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 35/50 staging: omap-thermal: section of device driver callbacks
In reply to Eduardo ValentinSection with platform device callbacks
--- drivers/staging/omap-thermal/omap-bandgap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -0
@@ -862,6 +862,8 @@ static struct omap_bandgap *omap_bandgap_build(struct platform_device *pdev)return bg_ptr; } +/*** Device driver call backs ***/ +static int omap_bandgap_probe (struct platform_device *pdev) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 36/50 staging: omap-thermal: rename enable_continuous_mode
In reply to Eduardo ValentinThis patch names 'enable_continuous_mode' accordingly to the file standard naming.
--- drivers/staging/omap-thermal/omap-bandgap.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +2 -2
@@ -735,7 +735,7 @@ omap_bandgap_force_single_read(struct omap_bandgap *bg_ptr, int id)* * Call this function only if HAS(MODE_CONFIG) is set */ -static int enable_continuous_mode (struct omap_bandgap *bg_ptr) +static int omap_bandgap_set_continuous_mode (struct omap_bandgap *bg_ptr) {int i;
@@ -973,7 +973,7 @@ int omap_bandgap_probe(struct platform_device *pdev) }if (OMAP_BANDGAP_HAS (bg_ptr,MODE_CONFIG )) -enable_continuous_mode (bg_ptr); +omap_bandgap_set_continuous_mode (bg_ptr);/* Set .250 seconds time as default counter */ if (OMAP_BANDGAP_HAS (bg_ptr,COUNTER ))
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 37/50 staging: omap-thermal: update omap_bandgap_set_continous_mode documentation
In reply to Eduardo ValentinSimple update on function documentation.
--- drivers/staging/omap-thermal/omap-bandgap.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +6 -3
@@ -730,10 +730,13 @@ omap_bandgap_force_single_read(struct omap_bandgap *bg_ptr, int id) }/** -* enable_continuous_mode() - One time enabling of continuous conversion mode -* @bg_ptr - pointer to scm instance +* omap_bandgap_set_continous_mode() - One time enabling of continuous mode +* @bg_ptr: pointer to struct omap_bandgap * -* Call this function only if HAS(MODE_CONFIG) is set +* Call this function only if HAS(MODE_CONFIG) is set. As this driver may +* be used for junction temperature monitoring, it is desirable that the +* sensors are operational all the time, so that alerts are generated +* properly. */ static int omap_bandgap_set_continuous_mode (struct omap_bandgap *bg_ptr) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 38/50 staging: omap-thermal: document omap_bandgap_force_single_read
In reply to Eduardo ValentinDocument function to initialize the conversion state machine.
--- drivers/staging/omap-thermal/omap-bandgap.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +8 -0
@@ -705,6 +705,14 @@ void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id)/*** Helper functions used during device initialization ***/ +/** +* omap_bandgap_force_single_read() - executes 1 single ADC conversion +* @bg_ptr: pointer to struct omap_bandgap +* @id: sensor id which it is desired to read 1 temperature +* +* Used to initialize the conversion state machine and set it to a valid +* state. Called during device initialization and context restore events. +*/ static int omap_bandgap_force_single_read (struct omap_bandgap *bg_ptr,int id) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 39/50 staging: omap-thermal: document omap_bandgap_update_alert_threshold function
In reply to Eduardo ValentinDocument function to program alert thresholds
--- drivers/staging/omap-thermal/omap-bandgap.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +14 -0
@@ -370,6 +370,20 @@ static void omap_bandgap_unmask_interrupts(struct omap_bandgap *bg_ptr, int id,omap_bandgap_writel (bg_ptr, reg_val, tsr->bgap_mask_ctrl); } +/** +* omap_bandgap_update_alert_threshold() - sequence to update thresholds +* @bg_ptr: struct omap_bandgap pointer +* @id: bandgap sensor id +* @val: value (ADC) of a new threshold +* @hot: desired threshold to be updated. true if threshold hot, false if +* threshold cold +* +* It will program the required thresholds (hot and cold) for TALERT signal. +* This function can be used to update t_hot or t_cold, depending on @hot value. +* It checks the resulting t_hot and t_cold values, based on the new passed @val +* and configures the thresholds so that t_hot is always greater than t_cold. +* Call this function only if bandgap features HAS(TALERT). +*/ static int omap_bandgap_update_alert_threshold (struct omap_bandgap *bg_ptr,int id,int val,bool hot)
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 40/50 staging: omap-thermal: document _omap_bandgap_write_threshold function
In reply to Eduardo ValentinDocument function to update alert thresholds.
--- drivers/staging/omap-thermal/omap-bandgap.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +13 -0
@@ -455,6 +455,19 @@ exit:return ret; } +/** +* _omap_bandgap_write_threshold() - helper to update TALERT t_cold or t_hot +* @bg_ptr: struct omap_bandgap pointer +* @id: bandgap sensor id +* @val: value (mCelsius) of a new threshold +* @hot: desired threshold to be updated. true if threshold hot, false if +* threshold cold +* +* It will update the required thresholds (hot and cold) for TALERT signal. +* This function can be used to update t_hot or t_cold, depending on @hot value. +* Validates the mCelsius range and update the requested threshold. +* Call this function only if bandgap features HAS(TALERT). +*/ int _omap_bandgap_write_threshold (struct omap_bandgap *bg_ptr,int id,int val,bool hot) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 41/50 staging: omap-thermal: document _omap_bandgap_read_threshold function
In reply to Eduardo ValentinAdd documentation of the function for reading alert thresholds
--- drivers/staging/omap-thermal/omap-bandgap.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +12 -0
@@ -510,6 +510,18 @@ exit:return ret; } +/** +* _omap_bandgap_read_threshold() - helper to read TALERT t_cold or t_hot +* @bg_ptr: struct omap_bandgap pointer +* @id: bandgap sensor id +* @val: value (mCelsius) of a threshold +* @hot: desired threshold to be read. true if threshold hot, false if +* threshold cold +* +* It will fetch the required thresholds (hot and cold) for TALERT signal. +* This function can be used to read t_hot or t_cold, depending on @hot value. +* Call this function only if bandgap features HAS(TALERT). +*/ int _omap_bandgap_read_threshold (struct omap_bandgap *bg_ptr,int id,int *val,bool hot) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 42/50 staging: omap-thermal: document omap_bandgap_tshut_init function
In reply to Eduardo ValentinAdd documentation for the function to setup TSHUT handling
--- drivers/staging/omap-thermal/omap-bandgap.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +12 -0
@@ -798,6 +798,18 @@ static int omap_bandgap_set_continuous_mode(struct omap_bandgap *bg_ptr)return 0 ; } +/** +* omap_bandgap_tshut_init() - setup and initialize tshut handling +* @bg_ptr: pointer to struct omap_bandgap +* @pdev: pointer to device struct platform_device +* +* Call this function only in case the bandgap features HAS(TSHUT). +* In this case, the driver needs to handle the TSHUT signal as an IRQ. +* The IRQ is wired as a GPIO, and for this purpose, it is required +* to specify which GPIO line is used. TSHUT IRQ is fired anytime +* one of the bandgap sensors violates the TSHUT high/hot threshold. +* And in that case, the system must go off. +*/ static int omap_bandgap_tshut_init (struct omap_bandgap *bg_ptr,struct platform_device *pdev) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 43/50 staging: omap-thermal: document omap_bandgap_alert_init function
In reply to Eduardo ValentinDocument function that sets talert handling up.
--- drivers/staging/omap-thermal/omap-bandgap.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +11 -1
@@ -842,7 +842,17 @@ static int omap_bandgap_tshut_init(struct omap_bandgap *bg_ptr,return 0 ; } -/* Initialization of Talert. Call it only if HAS(TALERT) is set */ +/** +* omap_bandgap_alert_init() - setup and initialize talert handling +* @bg_ptr: pointer to struct omap_bandgap +* @pdev: pointer to device struct platform_device +* +* Call this function only in case the bandgap features HAS(TALERT). +* In this case, the driver needs to handle the TALERT signals as an IRQs. +* TALERT is a normal IRQ and it is fired any time thresholds (hot or cold) +* are violated. In these situation, the driver must reprogram the thresholds, +* accordingly to specified policy. +*/ static int omap_bandgap_talert_init (struct omap_bandgap *bg_ptr,struct platform_device *pdev) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 44/50 staging: omap-thermal: document omap_bandgap_build function
In reply to Eduardo ValentinDocument function to build omap_bandgap structure
--- drivers/staging/omap-thermal/omap-bandgap.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +9 -0
@@ -875,6 +875,15 @@ static int omap_bandgap_talert_init(struct omap_bandgap *bg_ptr,return 0 ; } +/** +* omap_bandgap_build() - parse DT and setup a struct omap_bandgap +* @bg_ptr: pointer to struct omap_bandgap +* @pdev: pointer to device struct platform_device +* +* Used to read the device tree properties accordingly to the bandgap +* matching version. Based on bandgap version and its capabilities it +* will build a struct omap_bandgap out of the required DT entries. +*/ static const struct of_device_id of_omap_bandgap_match[];static struct omap_bandgap *omap_bandgap_build (struct platform_device *pdev) {
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 45/50 staging: omap-thermal: change Kconfig dependency method
In reply to Eduardo ValentinNow arch code has to specify CONFIG_ARCH_HAS_BANDGAP. So, this driver will be selectable only if the platform reports itself as having a bandgap device.
Any OMAP variant or any other OMAP version needs to
select ARCH_HAS_BANDGAP
so that the driver will be applicable. A part from that it is required to device the data structures that maps the registers and their bitfields. The DT compatible list must also be updated.
--- drivers/staging/omap-thermal/Kconfig | 2 +- drivers/staging/omap-thermal/TODO | 1 - 2 files changed, 1 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/Kconfig +1 -1
@@ -1,7 +1,7 @@ config OMAP_BANDGAP tristate "Texas Instruments OMAP4+ temperature sensor driver" depends on THERMAL - depends on ARCH_OMAP4 || SOC_OMAP5 + depends on ARCH_HAS_BANDGAP help If you say yes here you get support for the Texas Instruments OMAP4460+ on die bandgap temperature sensor support. The register
drivers/staging/omap-thermal/TODO +0 -1
@@ -20,7 +20,6 @@ on omap5-thermal.c - Add support for GPU cooling generally: -- write Kconfig dependencies so that omap variants are covered - make checkpatch.pl and sparse happy - make sure this code works on OMAP4430, OMAP4460 and OMAP5430 - update documentation
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 46/50 staging: Add a MAINTAINERS entry for TI bandgap and thermal driver
In reply to Eduardo ValentinAdd myself as maintainer of the TI bandgap and thermal driver.
--- MAINTAINERS | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
@@ -7915,6 +7915,12 @@ T: git git://repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git S: Maintained F: drivers/platform/x86/thinkpad_acpi.c +TI BANDGAP AND THERMAL DRIVER +M: Eduardo Valentin <[email protected]> +L: [email protected] +S: Maintained +F: drivers/staging/omap-thermal/ + TI FLASH MEDIA INTERFACE DRIVER M: Alex Dubov <[email protected]> S: Maintained
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 47/50 staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
In reply to Eduardo ValentinBecause there is a need to lock inside IRQ handler, this patch changes the locking mechanism inside the omap-bandgap.[c,h] to spinlocks. Now this lock is used to protect omap_bandgap struct during APIs exposed (possibly used in sysfs handling functions) and inside the ALERT IRQ handler.
Because there are registers shared among the sensors, this lock is global, not per sensor.
--- drivers/staging/omap-thermal/TODO | 1 - drivers/staging/omap-thermal/omap-bandgap.c | 18 ++++++++++-------- drivers/staging/omap-thermal/omap-bandgap.h | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/staging/omap-thermal/TODO +0 -1
@@ -1,7 +1,6 @@ List of TODOs (by Eduardo Valentin) on omap-bandgap.c: -- Rework locking - Improve driver code by adding usage of regmap-mmio - Test every exposed API to userland - Add support to hwmon
drivers/staging/omap-thermal/omap-bandgap.c +10 -8
@@ -33,7 +33,7 @@#include <linux/platform_device.h> #include <linux/err.h> #include <linux/types.h> -#include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/reboot.h> #include <linux/of_device.h> #include <linux/of_platform.h>
@@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)u32 t_hot =0 , t_cold =0 , ctrl;int i; +spin_lock (&bg_ptr->lock);for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { tsr = bg_ptr->conf->sensors[i].registers; ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_status);
@@ -208,6 +209,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)if (bg_ptr->conf->report_temperature) bg_ptr->conf->report_temperature (bg_ptr, i); } +spin_unlock (&bg_ptr->lock);return IRQ_HANDLED ; }
@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,if (ret <0 ) goto exit; -mutex_lock (&bg_ptr->bg_mutex); +spin_lock (&bg_ptr->lock);omap_bandgap_update_alert_threshold (bg_ptr, id, adc_val, hot); -mutex_unlock (&bg_ptr->bg_mutex); +spin_unlock (&bg_ptr->lock); exit:return ret;
@@ -666,9 +668,9 @@ int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,return -ENOTSUPP ; interval = interval * bg_ptr->clk_rate /1000 ; -mutex_lock (&bg_ptr->bg_mutex); +spin_lock (&bg_ptr->lock);RMW_BITS (bg_ptr, id, bgap_counter, counter_mask, interval); -mutex_unlock (&bg_ptr->bg_mutex); +spin_unlock (&bg_ptr->lock);return 0 ; }
@@ -691,9 +693,9 @@ int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,if (ret)return ret; -mutex_lock (&bg_ptr->bg_mutex); +spin_lock (&bg_ptr->lock); temp =omap_bandgap_read_temp (bg_ptr, id); -mutex_unlock (&bg_ptr->bg_mutex); +spin_unlock (&bg_ptr->lock); ret |=omap_bandgap_adc_to_mcelsius (bg_ptr, temp, &temp);if (ret)
@@ -1016,7 +1018,7 @@ int omap_bandgap_probe(struct platform_device *pdev)clk_prepare_enable (bg_ptr->fclock); -mutex_init (&bg_ptr->bg_mutex); +spin_lock_init (&bg_ptr->lock); bg_ptr->dev = &pdev->dev;platform_set_drvdata (pdev, bg_ptr);
drivers/staging/omap-thermal/omap-bandgap.h +2 -2
@@ -23,7 +23,7 @@#ifndef __OMAP_BANDGAP_H#define __OMAP_BANDGAP_H -#include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/types.h> #include <linux/err.h>
@@ -211,7 +211,7 @@ struct omap_bandgap {struct omap_bandgap_data *conf;struct clk *fclock;struct clk *div_clk; -struct mutex bg_mutex;/* shields this struct */ +spinlock_t lock;/* shields this struct */ int irq;int tshut_gpio;u32 clk_rate;
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 48/50 staging: omap-thermal: remove TODO entry suggesting regmap usage
In reply to Eduardo ValentinIt is hard to use regmap because benefit of using regmap cache may not be applicable as there is a specific sequence to restore the bandgap context.
--- drivers/staging/omap-thermal/TODO | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/TODO +0 -1
@@ -1,7 +1,6 @@ List of TODOs (by Eduardo Valentin) on omap-bandgap.c: -- Improve driver code by adding usage of regmap-mmio - Test every exposed API to userland - Add support to hwmon - Review and revisit all API exposed
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 49/50 staging: omap-thermal: remove TODO entry for exposed APIs
In reply to Eduardo ValentinNot all APIs exposed today are used. However all unused APIs will be required once the thermal layer allows IRQ based policies.
--- drivers/staging/omap-thermal/TODO | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/staging/omap-thermal/TODO +0 -1
@@ -3,7 +3,6 @@ List of TODOs (by Eduardo Valentin) on omap-bandgap.c: - Test every exposed API to userland - Add support to hwmon -- Review and revisit all API exposed - Revisit PM support - Revisit data structures and simplify them - Once SCM-core api settles, update this driver accordingly
Signature · 1 line
1.7.7.1.488.ge8e1c
PATCH 50/50 staging: omap-thermal: add documentation for omap_bandgap_validate
In reply to Eduardo ValentinDocument the helper to validate a struct omap_bandgap and a sensor id.
--- drivers/staging/omap-thermal/omap-bandgap.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/staging/omap-thermal/omap-bandgap.c +8 -0
@@ -437,6 +437,14 @@ exit:return err; } +/** +* omap_bandgap_validate() - helper to check the sanity of a struct omap_bandgap +* @bg_ptr: struct omap_bandgap pointer +* @id: bandgap sensor id +* +* Checks if the bandgap pointer is valid and if the sensor id is also +* applicable. +*/ static inline int omap_bandgap_validate (struct omap_bandgap *bg_ptr,int id) {int ret =0 ;
Signature · 1 line
1.7.7.1.488.ge8e1c
Re: [PATCH 07/50] staging: omap-thermal: introduce RMW_BITS macro
In reply to Eduardo ValentinQuoted 54 lines · Eduardo Valentin
This patch introduce a macro to read, update, write bitfields. It will be specific to bandgap data structures.
Signed-off-by Eduardo Valentin <[email protected]>--- drivers/staging/omap-thermal/omap-bandgap.c | 178 +++++++-------------------- 1 files changed, 46 insertions(+), 132 deletions(-)drivers/staging/omap-thermal/omap-bandgap.c +15
-11@@ -52,25 +52,29 @@ static void omap_bandgap_writel(struct omap_bandgap *bg_ptr, u32 val, u32 reg)writel (val, bg_ptr->base + reg); } +/* update bits, value will be shifted */ +#define RMW_BITS (bg_ptr, id, reg, mask, val) \ +do { \ + struct temp_sensor_registers *t; \ + u32 r; \ + \ + t = bg_ptr->conf->sensors[(id)].registers; \ + r = omap_bandgap_readl(bg_ptr, t->reg); \ + r &= ~t->mask; \ + r |= (val) << __ffs(t->mask); \ + omap_bandgap_writel(bg_ptr, r, t->reg); \ +} while (0) +static int omap_bandgap_power (struct omap_bandgap *bg_ptr,bool on) { -struct temp_sensor_registers *tsr;int i; -u32 ctrl;if (!OMAP_BANDGAP_HAS (bg_ptr,POWER_SWITCH ))return 0 ; -for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { - tsr = bg_ptr->conf->sensors[i].registers; - ctrl =omap_bandgap_readl (bg_ptr, tsr->temp_sensor_ctrl); - ctrl &= ~tsr->bgap_tempsoff_mask; +for (i =0 ; i < bg_ptr->conf->sensor_count; i++)/* active on 0 */ - ctrl |= !on <<__ffs (tsr->bgap_tempsoff_mask); - -/* write BGAP_TEMPSOFF should be reset to 0 */ -omap_bandgap_writel (bg_ptr, ctrl, tsr->temp_sensor_ctrl); - } +RMW_BITS (bg_ptr, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);return 0 ; }
drivers/staging/omap-thermal/omap-bandgap.c static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on) · line 83
Quoted 2 lines
drivers/staging/omap-thermal/omap-bandgap.c +0
-0@@ -78,15 +82,13 @@ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)static u32 omap_bandgap_read_temp (struct omap_bandgap *bg_ptr,int id) {
This patch is fine and it makes it cleaner than before.
But that said, I don't care for the RMW_BITS() very much as a long term thing. If we just used pointers instead of passing the offset into the bg_ptr->conf->sensors[] array then everything would be a lot cleaner.
In other words, instead of this:
static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)
We would have:
static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr,
struct temp_sensor_registers *tsr)
If you have the pointer then it's easy write RMW_BITS() as a function.
static void rmw_bits(struct omap_bandgap *bg_ptr, u32 reg, u32 mask, u32 val)
{
u32 r;
r = omap_bandgap_readl(bg_ptr, reg);
r &= ~mask;
r |= val << __ffs(mask);
omap_bandgap_writel(bg_ptr, r, reg);
}It's called like:
rmw_bits(bg_ptr, tsr->bgap_mask_ctrl, tsr->mask_freeze_mask, 1);
regards,
dan carpenter
Re: [PATCH 09/50] staging: omap-thermal: make a omap_bandgap_power with only one exit point
In reply to Eduardo ValentinQuoted 3 lines · Eduardo Valentin
Change the way the
omap_bandgap_poweris written so that it has only one exit entry (Documentation/CodingStyle).
It's only if there is an unlock or something that you should do this. Otherwise the pointless bunny hop is misleading and annoying.
regards,
dan carpenter
Re: [PATCH 22/50] staging: omap-thermal: rewrite omap_bandgap_adc_to_mcelsius on kernel coding style
In reply to Eduardo ValentinQuoted 1 line · Eduardo Valentin
Follow
Documentation/CodingStylewhile doingomap_bandgap_adc_to_mcelsius.
Someone should probably fix CodingStyle to be more clear. That's not what was intended at all... :/
regards,
dan carpenter
Re: [PATCH 25/50] staging: omap-thermal: rewrite omap_bandgap_mcelsius_to_adc on kernel coding style
In reply to Eduardo ValentinQuoted 2 lines · Eduardo Valentin
Follow
Documentation/CodingStylewhile doingomap_bandgap_mcelsius_to_adc
I have the same response for all these bunny hop patches.
When you're reading the code and you see a goto then you assume that it's there for a reason so it's misleading when it doesn't do anything. It's simpler if the code is simple.
regards,
dan carpenter
Re: [PATCH 33/50] staging: omap-thermal: refactor APIs handling threshold values
In reply to Eduardo Valentindrivers/staging/omap-thermal/omap-bandgap.c static void omap_bandgap_unmask_interrupts(struct omap_bandgap *bg_ptr, int id, · line 521
Quoted 13 lines · Eduardo Valentin
drivers/staging/omap-thermal/omap-bandgap.c +4
-2if (ret) {dev_err (bg_ptr->dev,"failed to read thot\n" ); -return -EIO ; + ret = -EIO ; + goto exit; } - *thot = temp; + *val = temp; +exit:return 0 ; }
The bunny hop has introduced a bug and this always returns success.
regards,
dan carpenter
Re: [PATCH 47/50] staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
In reply to Eduardo ValentinQuoted 58 lines · Eduardo Valentin
Because there is a need to lock inside IRQ handler, this patch changes the locking mechanism inside the omap-bandgap.[c,h] to spinlocks. Now this lock is used to protect
omap_bandgapstruct during APIs exposed (possibly used in sysfs handling functions) and inside the ALERT IRQ handler.Because there are registers shared among the sensors, this lock is global, not per sensor.
Signed-off-by Eduardo Valentin <[email protected]>--- drivers/staging/omap-thermal/TODO | 1 - drivers/staging/omap-thermal/omap-bandgap.c | 18 ++++++++++-------- drivers/staging/omap-thermal/omap-bandgap.h | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-)drivers/staging/omap-thermal/TODO +0
-1@@ -1,7 +1,6 @@ List of TODOs (by Eduardo Valentin) on omap-bandgap.c: -- Rework locking - Improve driver code by adding usage of regmap-mmio - Test every exposed API to userland - Add support to hwmondrivers/staging/omap-thermal/omap-bandgap.c +3
-1@@ -33,7 +33,7 @@#include <linux/platform_device.h> #include <linux/err.h> #include <linux/types.h> -#include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/reboot.h> #include <linux/of_device.h> #include <linux/of_platform.h> @@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)u32 t_hot =0 , t_cold =0 , ctrl;int i; +spin_lock (&bg_ptr->lock);for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { tsr = bg_ptr->conf->sensors[i].registers; ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_status);@@ -208,6 +209,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)if (bg_ptr->conf->report_temperature) bg_ptr->conf->report_temperature (bg_ptr, i); } +spin_unlock (&bg_ptr->lock);return IRQ_HANDLED ; }
drivers/staging/omap-thermal/omap-bandgap.c int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val, · line 507
Quoted 5 lines
drivers/staging/omap-thermal/omap-bandgap.c +1
-1@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,if (ret <0 ) goto exit; -mutex_lock (&bg_ptr->bg_mutex); +spin_lock (&bg_ptr->lock);
These need to disable interrupts because we take the spin lock in the IRQ handler.
regards,
dan carpenter
I've reviewed this set.
I hate to make people redo whole patchset sets, and I hate re-reviewing code. Obviously, I don't really like the bunny hop patches and I'm trying to discourage that going forward. ;P But I wouldn't say it's a "Redo the whole thing" kind of problem.
Could just resend patch 33 and 47? You should probably be able to redo those without changing the rest.
regards,
dan carpenter
Re: [PATCH 07/50] staging: omap-thermal: introduce RMW_BITS macro
In reply to Dan CarpenterHello Dan,
Quoted 65 lines · Dan Carpenter
Quoted 54 lines · Eduardo Valentin
This patch introduce a macro to read, update, write bitfields. It will be specific to bandgap data structures.
Signed-off-by Eduardo Valentin <[email protected]>--- drivers/staging/omap-thermal/omap-bandgap.c | 178 +++++++-------------------- 1 files changed, 46 insertions(+), 132 deletions(-)drivers/staging/omap-thermal/omap-bandgap.c +15
-11@@ -52,25 +52,29 @@ static void omap_bandgap_writel(struct omap_bandgap *bg_ptr, u32 val, u32 reg)writel (val, bg_ptr->base + reg); } +/* update bits, value will be shifted */ +#define RMW_BITS (bg_ptr, id, reg, mask, val) \ +do { \ + struct temp_sensor_registers *t; \ + u32 r; \ + \ + t = bg_ptr->conf->sensors[(id)].registers; \ + r = omap_bandgap_readl(bg_ptr, t->reg); \ + r &= ~t->mask; \ + r |= (val) << __ffs(t->mask); \ + omap_bandgap_writel(bg_ptr, r, t->reg); \ +} while (0) +static int omap_bandgap_power (struct omap_bandgap *bg_ptr,bool on) { -struct temp_sensor_registers *tsr;int i; -u32 ctrl;if (!OMAP_BANDGAP_HAS (bg_ptr,POWER_SWITCH ))return 0 ; -for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { - tsr = bg_ptr->conf->sensors[i].registers; - ctrl =omap_bandgap_readl (bg_ptr, tsr->temp_sensor_ctrl); - ctrl &= ~tsr->bgap_tempsoff_mask; +for (i =0 ; i < bg_ptr->conf->sensor_count; i++)/* active on 0 */ - ctrl |= !on <<__ffs (tsr->bgap_tempsoff_mask); - -/* write BGAP_TEMPSOFF should be reset to 0 */ -omap_bandgap_writel (bg_ptr, ctrl, tsr->temp_sensor_ctrl); - } +RMW_BITS (bg_ptr, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);return 0 ; }drivers/staging/omap-thermal/omap-bandgap.c static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on) · line 83
Quoted 2 lines
drivers/staging/omap-thermal/omap-bandgap.c +0
-0@@ -78,15 +82,13 @@ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)static u32 omap_bandgap_read_temp (struct omap_bandgap *bg_ptr,int id) {This patch is fine and it makes it cleaner than before.
But that said, I don't care for the
RMW_BITS()very much as a long term thing. If we just used pointers instead of passing the offset into the bg_ptr->conf->sensors[] array then everything would be a lot cleaner.
Quoted 8 lines
In other words, instead of this:
static u32
omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)We would have:
static u32 omap_bandgap_read_temp(struct
omap_bandgap*bg_ptr,
structtemp_sensor_registers*tsr)
I see. That will require a change in the whole driver though. If you see, the driver as of today uses the former approach, not only for read_temp or rmw_bits.
Quoted 14 lines
If you have the pointer then it's easy write
RMW_BITS()as a function.static void
rmw_bits(struct omap_bandgap *bg_ptr, u32 reg, u32 mask, u32 val){ u32 r; r = omap_bandgap_readl(bg_ptr, reg); r &= ~mask; r |= val << __ffs(mask); omap_bandgap_writel(bg_ptr, r, reg); }
Quoted 3 lines
It's called like:
rmw_bits(bg_ptr, tsr->bgap_mask_ctrl, tsr->mask_freeze_mask, 1);
This is nice, but it will require fetching tsr from .conf before every call o rmw_bits. And for that you need the sensor index.
Quoted 3 lines
regards,
dan carpenter
Thanks for your time reviewing this patch and suggesting improvements.
Quoted 4 lines
Re: [PATCH 09/50] staging: omap-thermal: make a omap_bandgap_power with only one exit point
In reply to Dan CarpenterHey Dan,
Quoted 7 lines · Dan Carpenter
Quoted 3 lines · Eduardo Valentin
Change the way the
omap_bandgap_poweris written so that it has only one exit entry (Documentation/CodingStyle).It's only if there is an unlock or something that you should do this. Otherwise the pointless bunny hop is misleading and annoying.
Well, if that is the case the Chapter 7 needs to be rewritten, don't you think? The way it is stated, it is clear that it is a design decision to use it for keeping only one exit point (quoting):
"Albeit deprecated by some people, the equivalent of the goto statement is used frequently by compilers in form of the unconditional jump instruction.
The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done.
The rationale is:
- unconditional statements are easier to understand and follow
- nesting is reduced
- errors by not updating individual exit points when making modifications are prevented
- saves the compiler work to optimize redundant code away ;)"
I believe this patch falls into at least three of the above rationale.
Quoted 6 lines
regards,
dan carpenter
Re: [PATCH 47/50] staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
In reply to Dan CarpenterQuoted 62 lines · Dan Carpenter
Quoted 61 lines · Eduardo Valentin
Because there is a need to lock inside IRQ handler, this patch changes the locking mechanism inside the omap-bandgap.[c,h] to spinlocks. Now this lock is used to protect
omap_bandgapstruct during APIs exposed (possibly used in sysfs handling functions) and inside the ALERT IRQ handler.Because there are registers shared among the sensors, this lock is global, not per sensor.
Signed-off-by Eduardo Valentin <[email protected]>--- drivers/staging/omap-thermal/TODO | 1 - drivers/staging/omap-thermal/omap-bandgap.c | 18 ++++++++++-------- drivers/staging/omap-thermal/omap-bandgap.h | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-)drivers/staging/omap-thermal/TODO +0
-1@@ -1,7 +1,6 @@ List of TODOs (by Eduardo Valentin) on omap-bandgap.c: -- Rework locking - Improve driver code by adding usage of regmap-mmio - Test every exposed API to userland - Add support to hwmondrivers/staging/omap-thermal/omap-bandgap.c +3
-1@@ -33,7 +33,7 @@#include <linux/platform_device.h> #include <linux/err.h> #include <linux/types.h> -#include <linux/mutex.h> +#include <linux/spinlock.h> #include <linux/reboot.h> #include <linux/of_device.h> #include <linux/of_platform.h> @@ -170,6 +170,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)u32 t_hot =0 , t_cold =0 , ctrl;int i; +spin_lock (&bg_ptr->lock);for (i =0 ; i < bg_ptr->conf->sensor_count; i++) { tsr = bg_ptr->conf->sensors[i].registers; ctrl =omap_bandgap_readl (bg_ptr, tsr->bgap_status);@@ -208,6 +209,7 @@ static irqreturn_t omap_bandgap_talert_irq_handler(int irq, void *data)if (bg_ptr->conf->report_temperature) bg_ptr->conf->report_temperature (bg_ptr, i); } +spin_unlock (&bg_ptr->lock);return IRQ_HANDLED ; }@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,if (ret <0 ) goto exit;
Quoted 5 lines
drivers/staging/omap-thermal/omap-bandgap.c int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val, · line 507
Quoted 2 lines
drivers/staging/omap-thermal/omap-bandgap.c +1
-1-mutex_lock (&bg_ptr->bg_mutex); +spin_lock (&bg_ptr->lock);These need to disable interrupts because we take the spin lock in the IRQ handler.
This IRQ gets masked at the IRQ controller level when served (ONE_SHOT). Not sure if your comment is applicable in this case..
Quoted 7 lines
regards,
dan carpenter
Hello Dan,
Quoted 9 lines · Dan Carpenter
I've reviewed this set.
I hate to make people redo whole patchset sets, and I hate re-reviewing code. Obviously, I don't really like the bunny hop patches and I'm trying to discourage that going forward. ;P But I wouldn't say it's a "Redo the whole thing" kind of problem.
Could just resend patch 33 and 47? You should probably be able to redo those without changing the rest.
I could of course change them if the comment is better clarified. As I mentioned as reply to one of your comments, those changes are following what is suggested in CodingStyle file.
I can of course send a diff on top of 33, to fix the introduce bug.
For 47, I'm not sure the comment is fully applicable.
Quoted 6 lines
regards,
dan carpenter
Re: [PATCH 33/50] staging: omap-thermal: refactor APIs handling threshold values
In reply to Dan CarpenterQuoted 11 lines · Dan Carpenter
Quoted 10 lines · Eduardo Valentin
if (ret) { dev_err(bg_ptr->dev, "failed to read thot\n");drivers/staging/omap-thermal/omap-bandgap.c +3
-2-return -EIO ; + ret = -EIO ; + goto exit; } - *thot = temp; + *val = temp;
Quoted 6 lines
Quoted 3 lines
+exit:
return 0;
}The bunny hop has introduced a bug and this always returns success.
What was the bug introduced?
I will send a patch to fix the return value.
Quoted 6 lines
regards,
dan carpenter
Re: [PATCH 09/50] staging: omap-thermal: make a omap_bandgap_power with only one exit point
In reply to Eduardo ValentinQuoted 23 lines · Eduardo Valentin
Hey Dan,
Quoted 7 lines · Dan Carpenter
Quoted 3 lines · Eduardo Valentin
Change the way the
omap_bandgap_poweris written so that it has only one exit entry (Documentation/CodingStyle).It's only if there is an unlock or something that you should do this. Otherwise the pointless bunny hop is misleading and annoying.
Well, if that is the case the Chapter 7 needs to be rewritten, don't you think? The way it is stated, it is clear that it is a design decision to use it for keeping only one exit point (quoting):
"Albeit deprecated by some people, the equivalent of the goto statement is used frequently by compilers in form of the unconditional jump instruction.
The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done.
The rationale is:
Quoted 7 lines
- unconditional statements are easier to understand and follow
- nesting is reduced
- errors by not updating individual exit points when making modifications are prevented
- saves the compiler work to optimize redundant code away ;)"I believe this patch falls into at least three of the above rationale.
There isn't any cleanup work done. That's what I was explaining about. When I see a goto I expect cleanup work to be done, but in this case it was misleading.
Where you would do the one exit point is when there is cleanup:
ret = function_one(); if (ret) goto unlock; ret = function_two(); if (ret) goto unlock;
That's better than:
ret = function_one();
if (ret) {
mutex_unlock();
return ret;
}
ret = function_two();
if (ret) {
mutex_unlock();
return ret;
}On the one hand, I think the documentation should be updated because obviously people get confused by it. But on the other hand, to me the documentation is already pretty clear. There is no style guideline that says every function should only have a single return. That would be silly.
regards,
dan carpenter
Re: [PATCH 33/50] staging: omap-thermal: refactor APIs handling threshold values
In reply to Eduardo ValentinQuoted 19 lines · Eduardo Valentin
Quoted 11 lines · Dan Carpenter
Quoted 10 lines · Eduardo Valentin
drivers/staging/omap-thermal/omap-bandgap.c +3
-2if (ret) {dev_err (bg_ptr->dev,"failed to read thot\n" ); -return -EIO ; + ret = -EIO ; + goto exit; } - *thot = temp; + *val = temp;Quoted 6 lines
drivers/staging/omap-thermal/omap-bandgap.c static void omap_bandgap_unmask_interrupts(struct omap_bandgap *bg_ptr, int id, · line 521
Quoted 3 lines
drivers/staging/omap-thermal/omap-bandgap.c +1
-0+exit:return 0 ; }The bunny hop has introduced a bug and this always returns success.
Quoted 3 lines
What was the bug introduced?
I will send a patch to fix the return value.
Returning the wrong value *is* the bug.
regards,
dan carpenter
Re: [PATCH 07/50] staging: omap-thermal: introduce RMW_BITS macro
In reply to Eduardo ValentinQuoted 9 lines · Eduardo Valentin
Quoted 9 lines
But that said, I don't care for the
RMW_BITS()very much as a long term thing. If we just used pointers instead of passing the offset into the bg_ptr->conf->sensors[] array then everything would be a lot cleaner.In other words, instead of this:
static u32
omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)
Quoted 8 lines
Quoted 4 lines
We would have:
static u32 omap_bandgap_read_temp(struct
omap_bandgap*bg_ptr,
structtemp_sensor_registers*tsr)I see. That will require a change in the whole driver though. If you see, the driver as of today uses the former approach, not only for
read_temporrmw_bits.
Yep.
Quoted 15 lines
Quoted 15 lines
If you have the pointer then it's easy write
RMW_BITS()as a function.static void
rmw_bits(struct omap_bandgap *bg_ptr, u32 reg, u32 mask, u32 val){ u32 r; r = omap_bandgap_readl(bg_ptr, reg); r &= ~mask; r |= val << __ffs(mask); omap_bandgap_writel(bg_ptr, r, reg); }
Quoted 7 lines
Quoted 3 lines
It's called like:
rmw_bits(bg_ptr, tsr->bgap_mask_ctrl, tsr->mask_freeze_mask, 1);This is nice, but it will require fetching tsr from .conf before every call o
rmw_bits. And for that you need the sensor index.
No. I'm suggesting that you re-write the driver to pass the tsr pointer directly instead of the index.
regards,
dan carpenter
Re: [PATCH 47/50] staging: omap-thermal: switch mutex to spinlock inside omap-bandgap
In reply to Eduardo ValentinQuoted 6 lines · Eduardo Valentin
Quoted 5 lines · Dan Carpenter
Quoted 4 lines · Eduardo Valentin
drivers/staging/omap-thermal/omap-bandgap.c +0
-0@@ -502,9 +504,9 @@ int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val,if (ret <0 ) goto exit;
Quoted 8 lines
Quoted 5 lines
Review int _omap_bandgap_write_threshold(struct omap_bandgap *bg_ptr, int id, int val, · line 507
Quoted 2 lines
(quoted diff) +1
-1- mutex_lock(&bg_ptr->bg_mutex); + spin_lock(&bg_ptr->lock);These need to disable interrupts because we take the spin lock in the IRQ handler.
This IRQ gets masked at the IRQ controller level when served (
ONE_SHOT). Not sure if your comment is applicable in this case..
Yes. It still applies. We need to disable IRQs from the current CPU while we are holding a spin_lock which they will need.
regards,
dan carpenter
Greg KH
maintainerQuoted 13 lines · Eduardo Valentin
Hello Dan,
Quoted 9 lines · Dan Carpenter
I've reviewed this set.
I hate to make people redo whole patchset sets, and I hate re-reviewing code. Obviously, I don't really like the bunny hop patches and I'm trying to discourage that going forward. ;P But I wouldn't say it's a "Redo the whole thing" kind of problem.
Could just resend patch 33 and 47? You should probably be able to redo those without changing the rest.
Quoted 7 lines
I could of course change them if the comment is better clarified. As I mentioned as reply to one of your comments, those changes are following what is suggested in CodingStyle file.
I can of course send a diff on top of 33, to fix the introduce bug.
For 47, I'm not sure the comment is fully applicable.
As I've taken all of these already (sorry Dan, I was fast and I didn't review them as well as you did), you will have to just send incremental patches on top of the whole series in order for me to be able to apply them.
thanks,
greg k-h
Greg, Dan,
Quoted 18 lines · Greg KH
Quoted 17 lines · Eduardo Valentin
Hello Dan,
Quoted 9 lines · Dan Carpenter
I've reviewed this set.
I hate to make people redo whole patchset sets, and I hate re-reviewing code. Obviously, I don't really like the bunny hop patches and I'm trying to discourage that going forward. ;P But I wouldn't say it's a "Redo the whole thing" kind of problem.
Could just resend patch 33 and 47? You should probably be able to redo those without changing the rest.
I could of course change them if the comment is better clarified. As I mentioned as reply to one of your comments, those changes are following what is suggested in CodingStyle file.
Quoted 8 lines
Quoted 3 lines
I can of course send a diff on top of 33, to fix the introduce bug.
For 47, I'm not sure the comment is fully applicable.
As I've taken all of these already (sorry Dan, I was fast and I didn't review them as well as you did), you will have to just send incremental patches on top of the whole series in order for me to be able to apply them.
No issues here, I am going to send soon incremental patches, copying Dan, to fix the above mentioned issues on 33 and 47.
Quoted 6 lines
thanks,
greg k-h