Re: [PATCH V6 19/30] thermal: exynos: Add TMU features to check instead of using SOC type

2013-06-19 Thread Eduardo Valentin
On 17-06-2013 02:46, Amit Daniel Kachhap wrote:
 This patch adds several features supported by TMU as bitfields.
 This features varies across different SOC type and comparing
 the features present in the TMU is more logical than comparing
 the soc itself.
 
 Acked-by: Kukjin Kim kgene@samsung.com
 Acked-by: Jonghwa Lee jonghwa3@samsung.com
 Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com

Acked-by: Eduardo Valentin eduardo.valen...@ti.com

 ---
  drivers/thermal/samsung/exynos_tmu.c  |   26 +++-
  drivers/thermal/samsung/exynos_tmu.h  |   31 
 +
  drivers/thermal/samsung/exynos_tmu_data.c |6 -
  3 files changed, 52 insertions(+), 11 deletions(-)
 
 diff --git a/drivers/thermal/samsung/exynos_tmu.c 
 b/drivers/thermal/samsung/exynos_tmu.c
 index 1880c4e..877dab8 100644
 --- a/drivers/thermal/samsung/exynos_tmu.c
 +++ b/drivers/thermal/samsung/exynos_tmu.c
 @@ -142,13 +142,15 @@ static int exynos_tmu_initialize(struct platform_device 
 *pdev)
   mutex_lock(data-lock);
   clk_enable(data-clk);
  
 - status = readb(data-base + reg-tmu_status);
 - if (!status) {
 - ret = -EBUSY;
 - goto out;
 + if (TMU_SUPPORTS(pdata, READY_STATUS)) {
 + status = readb(data-base + reg-tmu_status);
 + if (!status) {
 + ret = -EBUSY;
 + goto out;
 + }
   }
  
 - if (data-soc == SOC_ARCH_EXYNOS)
 + if (TMU_SUPPORTS(pdata, TRIM_RELOAD))
   __raw_writel(1, data-base + reg-triminfo_ctrl);
  
   /* Save trimming info in order to perform calibration */
 @@ -287,7 +289,7 @@ static void exynos_tmu_control(struct platform_device 
 *pdev, bool on)
   pdata-trigger_enable[2]  reg-inten_rise2_shift |
   pdata-trigger_enable[1]  reg-inten_rise1_shift |
   pdata-trigger_enable[0]  reg-inten_rise0_shift;
 - if (pdata-threshold_falling)
 + if (TMU_SUPPORTS(pdata, FALLING_TRIP))
   interrupt_en |=
   interrupt_en  reg-inten_fall0_shift;
   } else {
 @@ -329,7 +331,7 @@ static int exynos_tmu_set_emulation(void *drv_data, 
 unsigned long temp)
   unsigned int val;
   int ret = -EINVAL;
  
 - if (data-soc == SOC_ARCH_EXYNOS4210)
 + if (!TMU_SUPPORTS(pdata, EMULATION))
   goto out;
  
   if (temp  temp  MCELSIUS)
 @@ -343,9 +345,13 @@ static int exynos_tmu_set_emulation(void *drv_data, 
 unsigned long temp)
   if (temp) {
   temp /= MCELSIUS;
  
 - val = (EXYNOS_EMUL_TIME  reg-emul_time_shift) |
 - (temp_to_code(data, temp)
 -   reg-emul_temp_shift) | EXYNOS_EMUL_ENABLE;
 + if (TMU_SUPPORTS(pdata, EMUL_TIME)) {
 + val = ~(EXYNOS_EMUL_TIME_MASK  reg-emul_time_shift);
 + val |= (EXYNOS_EMUL_TIME  reg-emul_time_shift);
 + }
 + val = ~(EXYNOS_EMUL_DATA_MASK  reg-emul_temp_shift);
 + val |= (temp_to_code(data, temp)  reg-emul_temp_shift) |
 + EXYNOS_EMUL_ENABLE;
   } else {
   val = ~EXYNOS_EMUL_ENABLE;
   }
 diff --git a/drivers/thermal/samsung/exynos_tmu.h 
 b/drivers/thermal/samsung/exynos_tmu.h
 index b614407..6f55673 100644
 --- a/drivers/thermal/samsung/exynos_tmu.h
 +++ b/drivers/thermal/samsung/exynos_tmu.h
 @@ -41,6 +41,34 @@ enum soc_type {
  };
  
  /**
 + * EXYNOS TMU supported features.
 + * TMU_SUPPORT_EMULATION - This features is used to set user defined
 + *   temperature to the TMU controller.
 + * TMU_SUPPORT_MULTI_INST - This features denotes that the soc
 + *   has many instances of TMU.
 + * TMU_SUPPORT_TRIM_RELOAD - This features shows that trimming can
 + *   be reloaded.
 + * TMU_SUPPORT_FALLING_TRIP - This features shows that interrupt can
 + *   be registered for falling trips also.
 + * TMU_SUPPORT_READY_STATUS - This feature tells that the TMU current
 + *   state(active/idle) can be checked.
 + * TMU_SUPPORT_EMUL_TIME - This features allows to set next temp emulation
 + *   sample time.
 + * TMU_SUPPORT_SHARED_MEMORY - This feature tells that the different TMU
 + *   sensors shares some common registers.
 + * TMU_SUPPORT - macro to compare the above features with the supplied.
 + */
 +#define TMU_SUPPORT_EMULATIONBIT(0)
 +#define TMU_SUPPORT_MULTI_INST   BIT(1)
 +#define TMU_SUPPORT_TRIM_RELOAD  BIT(2)
 +#define TMU_SUPPORT_FALLING_TRIP BIT(3)
 +#define TMU_SUPPORT_READY_STATUS BIT(4)
 +#define TMU_SUPPORT_EMUL_TIMEBIT(5)
 +#define TMU_SUPPORT_SHARED_MEMORYBIT(6)
 +
 +#define TMU_SUPPORTS(a, b)   (a-features  

[PATCH V6 19/30] thermal: exynos: Add TMU features to check instead of using SOC type

2013-06-17 Thread Amit Daniel Kachhap
This patch adds several features supported by TMU as bitfields.
This features varies across different SOC type and comparing
the features present in the TMU is more logical than comparing
the soc itself.

Acked-by: Kukjin Kim kgene@samsung.com
Acked-by: Jonghwa Lee jonghwa3@samsung.com
Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
---
 drivers/thermal/samsung/exynos_tmu.c  |   26 +++-
 drivers/thermal/samsung/exynos_tmu.h  |   31 +
 drivers/thermal/samsung/exynos_tmu_data.c |6 -
 3 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/drivers/thermal/samsung/exynos_tmu.c 
b/drivers/thermal/samsung/exynos_tmu.c
index 1880c4e..877dab8 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -142,13 +142,15 @@ static int exynos_tmu_initialize(struct platform_device 
*pdev)
mutex_lock(data-lock);
clk_enable(data-clk);
 
-   status = readb(data-base + reg-tmu_status);
-   if (!status) {
-   ret = -EBUSY;
-   goto out;
+   if (TMU_SUPPORTS(pdata, READY_STATUS)) {
+   status = readb(data-base + reg-tmu_status);
+   if (!status) {
+   ret = -EBUSY;
+   goto out;
+   }
}
 
-   if (data-soc == SOC_ARCH_EXYNOS)
+   if (TMU_SUPPORTS(pdata, TRIM_RELOAD))
__raw_writel(1, data-base + reg-triminfo_ctrl);
 
/* Save trimming info in order to perform calibration */
@@ -287,7 +289,7 @@ static void exynos_tmu_control(struct platform_device 
*pdev, bool on)
pdata-trigger_enable[2]  reg-inten_rise2_shift |
pdata-trigger_enable[1]  reg-inten_rise1_shift |
pdata-trigger_enable[0]  reg-inten_rise0_shift;
-   if (pdata-threshold_falling)
+   if (TMU_SUPPORTS(pdata, FALLING_TRIP))
interrupt_en |=
interrupt_en  reg-inten_fall0_shift;
} else {
@@ -329,7 +331,7 @@ static int exynos_tmu_set_emulation(void *drv_data, 
unsigned long temp)
unsigned int val;
int ret = -EINVAL;
 
-   if (data-soc == SOC_ARCH_EXYNOS4210)
+   if (!TMU_SUPPORTS(pdata, EMULATION))
goto out;
 
if (temp  temp  MCELSIUS)
@@ -343,9 +345,13 @@ static int exynos_tmu_set_emulation(void *drv_data, 
unsigned long temp)
if (temp) {
temp /= MCELSIUS;
 
-   val = (EXYNOS_EMUL_TIME  reg-emul_time_shift) |
-   (temp_to_code(data, temp)
- reg-emul_temp_shift) | EXYNOS_EMUL_ENABLE;
+   if (TMU_SUPPORTS(pdata, EMUL_TIME)) {
+   val = ~(EXYNOS_EMUL_TIME_MASK  reg-emul_time_shift);
+   val |= (EXYNOS_EMUL_TIME  reg-emul_time_shift);
+   }
+   val = ~(EXYNOS_EMUL_DATA_MASK  reg-emul_temp_shift);
+   val |= (temp_to_code(data, temp)  reg-emul_temp_shift) |
+   EXYNOS_EMUL_ENABLE;
} else {
val = ~EXYNOS_EMUL_ENABLE;
}
diff --git a/drivers/thermal/samsung/exynos_tmu.h 
b/drivers/thermal/samsung/exynos_tmu.h
index b614407..6f55673 100644
--- a/drivers/thermal/samsung/exynos_tmu.h
+++ b/drivers/thermal/samsung/exynos_tmu.h
@@ -41,6 +41,34 @@ enum soc_type {
 };
 
 /**
+ * EXYNOS TMU supported features.
+ * TMU_SUPPORT_EMULATION - This features is used to set user defined
+ * temperature to the TMU controller.
+ * TMU_SUPPORT_MULTI_INST - This features denotes that the soc
+ * has many instances of TMU.
+ * TMU_SUPPORT_TRIM_RELOAD - This features shows that trimming can
+ * be reloaded.
+ * TMU_SUPPORT_FALLING_TRIP - This features shows that interrupt can
+ * be registered for falling trips also.
+ * TMU_SUPPORT_READY_STATUS - This feature tells that the TMU current
+ * state(active/idle) can be checked.
+ * TMU_SUPPORT_EMUL_TIME - This features allows to set next temp emulation
+ * sample time.
+ * TMU_SUPPORT_SHARED_MEMORY - This feature tells that the different TMU
+ * sensors shares some common registers.
+ * TMU_SUPPORT - macro to compare the above features with the supplied.
+ */
+#define TMU_SUPPORT_EMULATION  BIT(0)
+#define TMU_SUPPORT_MULTI_INST BIT(1)
+#define TMU_SUPPORT_TRIM_RELOADBIT(2)
+#define TMU_SUPPORT_FALLING_TRIP   BIT(3)
+#define TMU_SUPPORT_READY_STATUS   BIT(4)
+#define TMU_SUPPORT_EMUL_TIME  BIT(5)
+#define TMU_SUPPORT_SHARED_MEMORY  BIT(6)
+
+#define TMU_SUPPORTS(a, b) (a-features  TMU_SUPPORT_ ## b)
+
+/**
  * struct exynos_tmu_register - register descriptors to access registers and
  * bitfields.