Re: [PATCH v2 07/17] thermal: cpu_cooling: Modify exynos thermal code to use device tree for cpu cooling configuration

2015-01-12 Thread Lukasz Majewski
Hi Eduardo,

 On Wed, Dec 10, 2014 at 01:09:46PM +0100, Lukasz Majewski wrote:
  Up till now exynos_tmu_data.c was used for storing CPU cooling
  configuration data. Now the Exynos thermal core code uses device
  tree to get this data. For this purpose generic thermal code for
  configuring CPU cooling was used.
 
 Title prefix also does not help here, I would use 'thermal:
 exynos: '

Ok.

 
  
  Signed-off-by: Lukasz Majewski l.majew...@samsung.com
  ---
  Changes for v2:
  - None
  ---
   drivers/cpufreq/exynos-cpufreq.c|  23 -
   drivers/thermal/samsung/exynos_thermal_common.c | 122
  ++--
  drivers/thermal/samsung/exynos_tmu.c|   7 --
  drivers/thermal/samsung/exynos_tmu.h|   5 -
  drivers/thermal/samsung/exynos_tmu_data.c   |  42 +--- 5
  files changed, 94 insertions(+), 105 deletions(-)
  
  diff --git a/drivers/cpufreq/exynos-cpufreq.c
  b/drivers/cpufreq/exynos-cpufreq.c index 1e0ec57..fdedb8d 100644
  --- a/drivers/cpufreq/exynos-cpufreq.c
  +++ b/drivers/cpufreq/exynos-cpufreq.c
  @@ -18,10 +18,13 @@
   #include linux/cpufreq.h
   #include linux/platform_device.h
   #include linux/of.h
  +#include linux/cpu_cooling.h
  +#include linux/cpu.h
   
   #include exynos-cpufreq.h
   
   static struct exynos_dvfs_info *exynos_info;
  +static struct thermal_cooling_device *cdev;
   static struct regulator *arm_regulator;
   static unsigned int locking_frequency;
   
  @@ -156,6 +159,7 @@ static struct cpufreq_driver exynos_driver = {
   
   static int exynos_cpufreq_probe(struct platform_device *pdev)
   {
  +   struct device_node *np;
  int ret = -EINVAL;
   
  exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
  @@ -198,9 +202,24 @@ static int exynos_cpufreq_probe(struct
  platform_device *pdev) /* Done here as we want to capture boot
  frequency */ locking_frequency =
  clk_get_rate(exynos_info-cpu_clk) / 1000; 
  -   if (!cpufreq_register_driver(exynos_driver))
  -   return 0;
  +   if (cpufreq_register_driver(exynos_driver))
  +   goto err;
   
  +   np = of_find_node_by_path(/cpus/cpu@0);
  +   if (!np) {
  +   pr_err(failed to find cpu0 node\n);
  +   return -ENOENT;
  +   }
  +   if (of_find_property(np, #cooling-cells, NULL)) {
  +   cdev = of_cpufreq_cooling_register(np,
  cpu_present_mask);
  +   if (IS_ERR(cdev))
  +   pr_err(running cpufreq without cooling
  device: %ld\n,
  +  PTR_ERR(cdev));
  +   }
  +   of_node_put(np);
  +
  +   return 0;
  + err:
  dev_err(pdev-dev, failed to register cpufreq driver\n);
  regulator_put(arm_regulator);
   err_vdd_arm:
  diff --git a/drivers/thermal/samsung/exynos_thermal_common.c
  b/drivers/thermal/samsung/exynos_thermal_common.c index
  6dc3815..00aa688 100644 ---
  a/drivers/thermal/samsung/exynos_thermal_common.c +++
  b/drivers/thermal/samsung/exynos_thermal_common.c @@ -133,47
  +133,62 @@ static int exynos_get_crit_temp(struct
  thermal_zone_device *thermal, static int exynos_bind(struct
  thermal_zone_device *thermal, struct thermal_cooling_device *cdev) {
  -   int ret = 0, i, tab_size, level;
  -   struct freq_clip_table *tab_ptr, *clip_data;
  struct exynos_thermal_zone *th_zone = thermal-devdata;
  struct thermal_sensor_conf *data = th_zone-sensor_conf;
  +   struct device_node *child, *gchild, *np;
  +   struct of_phandle_args cooling_spec;
  +   unsigned long max, state = 0;
  +   int ret = 0, i = 0;
   
  -   tab_ptr = (struct freq_clip_table
  *)data-cooling_data.freq_data;
  -   tab_size = data-cooling_data.freq_clip_count;
  -
  -   if (tab_ptr == NULL || tab_size == 0)
  +   /*
  +* Below code is necessary to skip binding when cpufreq's
  +* frequency table is not yet initialized.
  +*/
  +   cdev-ops-get_max_state(cdev, state);
  +   if (!state  !th_zone-cool_dev_size) {
  +   th_zone-cool_dev_size = 1;
  +   th_zone-cool_dev[0] = cdev;
  +   th_zone-bind = false;
  return 0;
  +   }
   
  -   /* find the cooling device registered*/
  -   for (i = 0; i  th_zone-cool_dev_size; i++)
  -   if (cdev == th_zone-cool_dev[i])
  -   break;
  +   np = of_find_node_by_path(/thermal-zones/cpu-thermal);
  +   if (!np) {
  +   pr_err(failed to find thmerla-zones/cpu-thermal
  node\n);
  +   return -ENOENT;
  +   }
   
  -   /* No matching cooling device */
  -   if (i == th_zone-cool_dev_size)
  -   return 0;
  +   child = of_get_child_by_name(np, cooling-maps);
   
  -   /* Bind the thermal zone to the cpufreq cooling device */
  -   for (i = 0; i  tab_size; i++) {
  -   clip_data = (struct freq_clip_table
  *)(tab_ptr[i]);
  -   level = cpufreq_cooling_get_level(0,
  clip_data-freq_clip_max);
  -   if (level == THERMAL_CSTATE_INVALID)
  -   return 0;
  -   switch (GET_ZONE(i)) {
  -   case MONITOR_ZONE:
 

Re: [PATCH v2 07/17] thermal: cpu_cooling: Modify exynos thermal code to use device tree for cpu cooling configuration

2015-01-02 Thread Eduardo Valentin
On Wed, Dec 10, 2014 at 01:09:46PM +0100, Lukasz Majewski wrote:
 Up till now exynos_tmu_data.c was used for storing CPU cooling configuration
 data. Now the Exynos thermal core code uses device tree to get this data.
 For this purpose generic thermal code for configuring CPU cooling was
 used.

Title prefix also does not help here, I would use 'thermal: exynos: '

 
 Signed-off-by: Lukasz Majewski l.majew...@samsung.com
 ---
 Changes for v2:
 - None
 ---
  drivers/cpufreq/exynos-cpufreq.c|  23 -
  drivers/thermal/samsung/exynos_thermal_common.c | 122 
 ++--
  drivers/thermal/samsung/exynos_tmu.c|   7 --
  drivers/thermal/samsung/exynos_tmu.h|   5 -
  drivers/thermal/samsung/exynos_tmu_data.c   |  42 +---
  5 files changed, 94 insertions(+), 105 deletions(-)
 
 diff --git a/drivers/cpufreq/exynos-cpufreq.c 
 b/drivers/cpufreq/exynos-cpufreq.c
 index 1e0ec57..fdedb8d 100644
 --- a/drivers/cpufreq/exynos-cpufreq.c
 +++ b/drivers/cpufreq/exynos-cpufreq.c
 @@ -18,10 +18,13 @@
  #include linux/cpufreq.h
  #include linux/platform_device.h
  #include linux/of.h
 +#include linux/cpu_cooling.h
 +#include linux/cpu.h
  
  #include exynos-cpufreq.h
  
  static struct exynos_dvfs_info *exynos_info;
 +static struct thermal_cooling_device *cdev;
  static struct regulator *arm_regulator;
  static unsigned int locking_frequency;
  
 @@ -156,6 +159,7 @@ static struct cpufreq_driver exynos_driver = {
  
  static int exynos_cpufreq_probe(struct platform_device *pdev)
  {
 + struct device_node *np;
   int ret = -EINVAL;
  
   exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
 @@ -198,9 +202,24 @@ static int exynos_cpufreq_probe(struct platform_device 
 *pdev)
   /* Done here as we want to capture boot frequency */
   locking_frequency = clk_get_rate(exynos_info-cpu_clk) / 1000;
  
 - if (!cpufreq_register_driver(exynos_driver))
 - return 0;
 + if (cpufreq_register_driver(exynos_driver))
 + goto err;
  
 + np = of_find_node_by_path(/cpus/cpu@0);
 + if (!np) {
 + pr_err(failed to find cpu0 node\n);
 + return -ENOENT;
 + }
 + if (of_find_property(np, #cooling-cells, NULL)) {
 + cdev = of_cpufreq_cooling_register(np, cpu_present_mask);
 + if (IS_ERR(cdev))
 + pr_err(running cpufreq without cooling device: %ld\n,
 +PTR_ERR(cdev));
 + }
 + of_node_put(np);
 +
 + return 0;
 + err:
   dev_err(pdev-dev, failed to register cpufreq driver\n);
   regulator_put(arm_regulator);
  err_vdd_arm:
 diff --git a/drivers/thermal/samsung/exynos_thermal_common.c 
 b/drivers/thermal/samsung/exynos_thermal_common.c
 index 6dc3815..00aa688 100644
 --- a/drivers/thermal/samsung/exynos_thermal_common.c
 +++ b/drivers/thermal/samsung/exynos_thermal_common.c
 @@ -133,47 +133,62 @@ static int exynos_get_crit_temp(struct 
 thermal_zone_device *thermal,
  static int exynos_bind(struct thermal_zone_device *thermal,
   struct thermal_cooling_device *cdev)
  {
 - int ret = 0, i, tab_size, level;
 - struct freq_clip_table *tab_ptr, *clip_data;
   struct exynos_thermal_zone *th_zone = thermal-devdata;
   struct thermal_sensor_conf *data = th_zone-sensor_conf;
 + struct device_node *child, *gchild, *np;
 + struct of_phandle_args cooling_spec;
 + unsigned long max, state = 0;
 + int ret = 0, i = 0;
  
 - tab_ptr = (struct freq_clip_table *)data-cooling_data.freq_data;
 - tab_size = data-cooling_data.freq_clip_count;
 -
 - if (tab_ptr == NULL || tab_size == 0)
 + /*
 +  * Below code is necessary to skip binding when cpufreq's
 +  * frequency table is not yet initialized.
 +  */
 + cdev-ops-get_max_state(cdev, state);
 + if (!state  !th_zone-cool_dev_size) {
 + th_zone-cool_dev_size = 1;
 + th_zone-cool_dev[0] = cdev;
 + th_zone-bind = false;
   return 0;
 + }
  
 - /* find the cooling device registered*/
 - for (i = 0; i  th_zone-cool_dev_size; i++)
 - if (cdev == th_zone-cool_dev[i])
 - break;
 + np = of_find_node_by_path(/thermal-zones/cpu-thermal);
 + if (!np) {
 + pr_err(failed to find thmerla-zones/cpu-thermal node\n);
 + return -ENOENT;
 + }
  
 - /* No matching cooling device */
 - if (i == th_zone-cool_dev_size)
 - return 0;
 + child = of_get_child_by_name(np, cooling-maps);
  
 - /* Bind the thermal zone to the cpufreq cooling device */
 - for (i = 0; i  tab_size; i++) {
 - clip_data = (struct freq_clip_table *)(tab_ptr[i]);
 - level = cpufreq_cooling_get_level(0, clip_data-freq_clip_max);
 - if (level == THERMAL_CSTATE_INVALID)
 - return 0;
 - switch (GET_ZONE(i)) {
 - 

[PATCH v2 07/17] thermal: cpu_cooling: Modify exynos thermal code to use device tree for cpu cooling configuration

2014-12-10 Thread Lukasz Majewski
Up till now exynos_tmu_data.c was used for storing CPU cooling configuration
data. Now the Exynos thermal core code uses device tree to get this data.
For this purpose generic thermal code for configuring CPU cooling was
used.

Signed-off-by: Lukasz Majewski l.majew...@samsung.com
---
Changes for v2:
- None
---
 drivers/cpufreq/exynos-cpufreq.c|  23 -
 drivers/thermal/samsung/exynos_thermal_common.c | 122 ++--
 drivers/thermal/samsung/exynos_tmu.c|   7 --
 drivers/thermal/samsung/exynos_tmu.h|   5 -
 drivers/thermal/samsung/exynos_tmu_data.c   |  42 +---
 5 files changed, 94 insertions(+), 105 deletions(-)

diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index 1e0ec57..fdedb8d 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -18,10 +18,13 @@
 #include linux/cpufreq.h
 #include linux/platform_device.h
 #include linux/of.h
+#include linux/cpu_cooling.h
+#include linux/cpu.h
 
 #include exynos-cpufreq.h
 
 static struct exynos_dvfs_info *exynos_info;
+static struct thermal_cooling_device *cdev;
 static struct regulator *arm_regulator;
 static unsigned int locking_frequency;
 
@@ -156,6 +159,7 @@ static struct cpufreq_driver exynos_driver = {
 
 static int exynos_cpufreq_probe(struct platform_device *pdev)
 {
+   struct device_node *np;
int ret = -EINVAL;
 
exynos_info = kzalloc(sizeof(*exynos_info), GFP_KERNEL);
@@ -198,9 +202,24 @@ static int exynos_cpufreq_probe(struct platform_device 
*pdev)
/* Done here as we want to capture boot frequency */
locking_frequency = clk_get_rate(exynos_info-cpu_clk) / 1000;
 
-   if (!cpufreq_register_driver(exynos_driver))
-   return 0;
+   if (cpufreq_register_driver(exynos_driver))
+   goto err;
 
+   np = of_find_node_by_path(/cpus/cpu@0);
+   if (!np) {
+   pr_err(failed to find cpu0 node\n);
+   return -ENOENT;
+   }
+   if (of_find_property(np, #cooling-cells, NULL)) {
+   cdev = of_cpufreq_cooling_register(np, cpu_present_mask);
+   if (IS_ERR(cdev))
+   pr_err(running cpufreq without cooling device: %ld\n,
+  PTR_ERR(cdev));
+   }
+   of_node_put(np);
+
+   return 0;
+ err:
dev_err(pdev-dev, failed to register cpufreq driver\n);
regulator_put(arm_regulator);
 err_vdd_arm:
diff --git a/drivers/thermal/samsung/exynos_thermal_common.c 
b/drivers/thermal/samsung/exynos_thermal_common.c
index 6dc3815..00aa688 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -133,47 +133,62 @@ static int exynos_get_crit_temp(struct 
thermal_zone_device *thermal,
 static int exynos_bind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
 {
-   int ret = 0, i, tab_size, level;
-   struct freq_clip_table *tab_ptr, *clip_data;
struct exynos_thermal_zone *th_zone = thermal-devdata;
struct thermal_sensor_conf *data = th_zone-sensor_conf;
+   struct device_node *child, *gchild, *np;
+   struct of_phandle_args cooling_spec;
+   unsigned long max, state = 0;
+   int ret = 0, i = 0;
 
-   tab_ptr = (struct freq_clip_table *)data-cooling_data.freq_data;
-   tab_size = data-cooling_data.freq_clip_count;
-
-   if (tab_ptr == NULL || tab_size == 0)
+   /*
+* Below code is necessary to skip binding when cpufreq's
+* frequency table is not yet initialized.
+*/
+   cdev-ops-get_max_state(cdev, state);
+   if (!state  !th_zone-cool_dev_size) {
+   th_zone-cool_dev_size = 1;
+   th_zone-cool_dev[0] = cdev;
+   th_zone-bind = false;
return 0;
+   }
 
-   /* find the cooling device registered*/
-   for (i = 0; i  th_zone-cool_dev_size; i++)
-   if (cdev == th_zone-cool_dev[i])
-   break;
+   np = of_find_node_by_path(/thermal-zones/cpu-thermal);
+   if (!np) {
+   pr_err(failed to find thmerla-zones/cpu-thermal node\n);
+   return -ENOENT;
+   }
 
-   /* No matching cooling device */
-   if (i == th_zone-cool_dev_size)
-   return 0;
+   child = of_get_child_by_name(np, cooling-maps);
 
-   /* Bind the thermal zone to the cpufreq cooling device */
-   for (i = 0; i  tab_size; i++) {
-   clip_data = (struct freq_clip_table *)(tab_ptr[i]);
-   level = cpufreq_cooling_get_level(0, clip_data-freq_clip_max);
-   if (level == THERMAL_CSTATE_INVALID)
-   return 0;
-   switch (GET_ZONE(i)) {
-   case MONITOR_ZONE:
-   case WARN_ZONE:
-   if (thermal_zone_bind_cooling_device(thermal, i, cdev,
-