Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-19 Thread amit daniel kachhap
On Sat, May 17, 2014 at 4:01 AM, Rafael J. Wysocki  wrote:
> On Thursday, May 15, 2014 02:33:07 PM Eduardo Valentin wrote:
>> Hello Amit,
>>
>>
>> On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
>> > This patch is in preparation to add notfication support for cpufrequency
>> > cooling changes. This change also removes the unnecessary exposing of
>> > internal housekeeping structure via thermal_cooling_device->devdata to the
>> > users of cpufreq cooling APIs.
>> >
>> > Signed-off-by: Amit Daniel Kachhap 
>> > ---
>> >  drivers/thermal/cpu_cooling.c  |   79 
>> > +++
>> >  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
>> >  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
>> >  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
>> >  include/linux/cpu_cooling.h|5 +-
>> >  5 files changed, 68 insertions(+), 22 deletions(-)
>> >
>> > diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
>> > index 4246262..21f44d4 100644
>> > --- a/drivers/thermal/cpu_cooling.c
>> > +++ b/drivers/thermal/cpu_cooling.c
>> > @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
>> > unsigned int cpufreq_state;
>> > unsigned int cpufreq_val;
>> > struct cpumask allowed_cpus;
>> > +   struct list_head node;
>> >  };
>> >  static DEFINE_IDR(cpufreq_idr);
>> >  static DEFINE_MUTEX(cooling_cpufreq_lock);
>> >
>> > -static unsigned int cpufreq_dev_count;
>> > -
>> >  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>> >  #define NOTIFY_INVALID NULL
>> >  static struct cpufreq_cooling_device *notify_device;
>> >
>> > +/* A list to hold all the cpufreq cooling devices registered */
>> > +static LIST_HEAD(cpufreq_cooling_list);
>> > +
>> >  /**
>> >   * get_idr - function to get a unique id.
>> >   * @idr: struct idr * handle used to create a id.
>> > @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
>> > notifier_block *nb,
>> >  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>> >  unsigned long *state)
>> >  {
>> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> > -   struct cpumask *mask = _device->allowed_cpus;
>> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
>> > +   struct cpumask *mask = NULL;
>> > unsigned int cpu;
>> > unsigned int count = 0;
>> > int ret;
>> >
>> > +   mutex_lock(_cpufreq_lock);
>> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
>> > +   if (cpufreq_device->cool_dev == cdev)
>> > +   break;
>> > +   mutex_unlock(_cpufreq_lock);
>> > +   if (!cpufreq_device) {
>> > +   /* Cooling device pointer not found */
>> > +   return -EINVAL;
>> > +   }
>> > +
>> > +   mask = _device->allowed_cpus;
>> > cpu = cpumask_any(mask);
>> >
>> > ret = get_property(cpu, 0, , GET_MAXL);
>> > @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
>> > thermal_cooling_device *cdev,
>> >  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>> >  unsigned long *state)
>> >  {
>> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
>> > +
>> > +   mutex_lock(_cpufreq_lock);
>> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
>> > +   if (cpufreq_device->cool_dev == cdev)
>> > +   break;
>> > +   mutex_unlock(_cpufreq_lock);
>> > +   if (!cpufreq_device) {
>> > +   /* Cooling device pointer not found */
>> > +   return -EINVAL;
>> > +   }
>> >
>> > *state = cpufreq_device->cpufreq_state;
>> >
>> > @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
>> > thermal_cooling_device *cdev,
>> >  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>> >  unsigned long state)
>> >  {
>> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
>> > +
>> > +   mutex_lock(_cpufreq_lock);
>> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
>> > +   if (cpufreq_device->cool_dev == cdev)
>> > +   break;
>> > +   mutex_unlock(_cpufreq_lock);
>> > +   if (!cpufreq_device) {
>> > +   /* Cooling device pointer not found */
>> > +   return -EINVAL;
>> > +   }
>> >
>> > return cpufreq_apply_cooling(cpufreq_device, state);
>> >  }
>> > @@ -427,6 +460,7 @@ static struct notifier_block 
>> > thermal_cpufreq_notifier_block = {
>> >   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
>> > device
>> >   * @np: a valid struct device_node to the cooling device device tree node
>> >   * @clip_cpus: cpumask of cpus where the frequency constraints will 
>> > happen.
>> > + * @devdata: driver data pointer
>> >   *
>> >   * 

Re: [linux-pm] [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-19 Thread amit daniel kachhap
Hi Eduardo,

Thanks for reviewing these patches.

On Fri, May 16, 2014 at 12:03 AM, Eduardo Valentin  wrote:
> Hello Amit,
>
>
> On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
>> This patch is in preparation to add notfication support for cpufrequency
>> cooling changes. This change also removes the unnecessary exposing of
>> internal housekeeping structure via thermal_cooling_device->devdata to the
>> users of cpufreq cooling APIs.
>>
>> Signed-off-by: Amit Daniel Kachhap 
>> ---
>>  drivers/thermal/cpu_cooling.c  |   79 
>> +++
>>  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
>>  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
>>  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
>>  include/linux/cpu_cooling.h|5 +-
>>  5 files changed, 68 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
>> index 4246262..21f44d4 100644
>> --- a/drivers/thermal/cpu_cooling.c
>> +++ b/drivers/thermal/cpu_cooling.c
>> @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
>>   unsigned int cpufreq_state;
>>   unsigned int cpufreq_val;
>>   struct cpumask allowed_cpus;
>> + struct list_head node;
>>  };
>>  static DEFINE_IDR(cpufreq_idr);
>>  static DEFINE_MUTEX(cooling_cpufreq_lock);
>>
>> -static unsigned int cpufreq_dev_count;
>> -
>>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>>  #define NOTIFY_INVALID NULL
>>  static struct cpufreq_cooling_device *notify_device;
>>
>> +/* A list to hold all the cpufreq cooling devices registered */
>> +static LIST_HEAD(cpufreq_cooling_list);
>> +
>>  /**
>>   * get_idr - function to get a unique id.
>>   * @idr: struct idr * handle used to create a id.
>> @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
>> notifier_block *nb,
>>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>>unsigned long *state)
>>  {
>> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> - struct cpumask *mask = _device->allowed_cpus;
>> + struct cpufreq_cooling_device *cpufreq_device = NULL;
>> + struct cpumask *mask = NULL;
>>   unsigned int cpu;
>>   unsigned int count = 0;
>>   int ret;
>>
>> + mutex_lock(_cpufreq_lock);
>> + list_for_each_entry(cpufreq_device, _cooling_list, node)
>> + if (cpufreq_device->cool_dev == cdev)
>> + break;
>> + mutex_unlock(_cpufreq_lock);
>> + if (!cpufreq_device) {
>> + /* Cooling device pointer not found */
>> + return -EINVAL;
>> + }
>> +
>> + mask = _device->allowed_cpus;
>>   cpu = cpumask_any(mask);
>>
>>   ret = get_property(cpu, 0, , GET_MAXL);
>> @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
>> thermal_cooling_device *cdev,
>>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>>unsigned long *state)
>>  {
>> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> + struct cpufreq_cooling_device *cpufreq_device = NULL;
>> +
>> + mutex_lock(_cpufreq_lock);
>> + list_for_each_entry(cpufreq_device, _cooling_list, node)
>> + if (cpufreq_device->cool_dev == cdev)
>> + break;
>> + mutex_unlock(_cpufreq_lock);
>> + if (!cpufreq_device) {
>> + /* Cooling device pointer not found */
>> + return -EINVAL;
>> + }
>>
>>   *state = cpufreq_device->cpufreq_state;
>>
>> @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
>> thermal_cooling_device *cdev,
>>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>>unsigned long state)
>>  {
>> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>> + struct cpufreq_cooling_device *cpufreq_device = NULL;
>> +
>> + mutex_lock(_cpufreq_lock);
>> + list_for_each_entry(cpufreq_device, _cooling_list, node)
>> + if (cpufreq_device->cool_dev == cdev)
>> + break;
>> + mutex_unlock(_cpufreq_lock);
>> + if (!cpufreq_device) {
>> + /* Cooling device pointer not found */
>> + return -EINVAL;
>> + }
>>
>>   return cpufreq_apply_cooling(cpufreq_device, state);
>>  }
>> @@ -427,6 +460,7 @@ static struct notifier_block 
>> thermal_cpufreq_notifier_block = {
>>   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
>> device
>>   * @np: a valid struct device_node to the cooling device device tree node
>>   * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
>> + * @devdata: driver data pointer
>>   *
>>   * This interface function registers the cpufreq cooling device with the 
>> name
>>   * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq

Re: [linux-pm] [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-19 Thread amit daniel kachhap
Hi Eduardo,

Thanks for reviewing these patches.

On Fri, May 16, 2014 at 12:03 AM, Eduardo Valentin edubez...@gmail.com wrote:
 Hello Amit,


 On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
 This patch is in preparation to add notfication support for cpufrequency
 cooling changes. This change also removes the unnecessary exposing of
 internal housekeeping structure via thermal_cooling_device-devdata to the
 users of cpufreq cooling APIs.

 Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
 ---
  drivers/thermal/cpu_cooling.c  |   79 
 +++
  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
  include/linux/cpu_cooling.h|5 +-
  5 files changed, 68 insertions(+), 22 deletions(-)

 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 4246262..21f44d4 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
   unsigned int cpufreq_state;
   unsigned int cpufreq_val;
   struct cpumask allowed_cpus;
 + struct list_head node;
  };
  static DEFINE_IDR(cpufreq_idr);
  static DEFINE_MUTEX(cooling_cpufreq_lock);

 -static unsigned int cpufreq_dev_count;
 -
  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
  static struct cpufreq_cooling_device *notify_device;

 +/* A list to hold all the cpufreq cooling devices registered */
 +static LIST_HEAD(cpufreq_cooling_list);
 +
  /**
   * get_idr - function to get a unique id.
   * @idr: struct idr * handle used to create a id.
 @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 - struct cpumask *mask = cpufreq_device-allowed_cpus;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 + struct cpumask *mask = NULL;
   unsigned int cpu;
   unsigned int count = 0;
   int ret;

 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }
 +
 + mask = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(mask);

   ret = get_property(cpu, 0, count, GET_MAXL);
 @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 +
 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }

   *state = cpufreq_device-cpufreq_state;

 @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 +
 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }

   return cpufreq_apply_cooling(cpufreq_device, state);
  }
 @@ -427,6 +460,7 @@ static struct notifier_block 
 thermal_cpufreq_notifier_block = {
   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
 device
   * @np: a valid struct device_node to the cooling device device tree node
   * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
 + * @devdata: driver data pointer
   *
   * This interface function registers the cpufreq cooling device with the 
 name
   * thermal-cpufreq-%x. This api can support multiple instances of cpufreq
 @@ -438,7 +472,7 @@ static struct notifier_block 
 thermal_cpufreq_notifier_block = {
   */
  static struct 

Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-19 Thread amit daniel kachhap
On Sat, May 17, 2014 at 4:01 AM, Rafael J. Wysocki r...@rjwysocki.net wrote:
 On Thursday, May 15, 2014 02:33:07 PM Eduardo Valentin wrote:
 Hello Amit,


 On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
  This patch is in preparation to add notfication support for cpufrequency
  cooling changes. This change also removes the unnecessary exposing of
  internal housekeeping structure via thermal_cooling_device-devdata to the
  users of cpufreq cooling APIs.
 
  Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
  ---
   drivers/thermal/cpu_cooling.c  |   79 
  +++
   drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
   drivers/thermal/samsung/exynos_thermal_common.c|2 +-
   drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
   include/linux/cpu_cooling.h|5 +-
   5 files changed, 68 insertions(+), 22 deletions(-)
 
  diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
  index 4246262..21f44d4 100644
  --- a/drivers/thermal/cpu_cooling.c
  +++ b/drivers/thermal/cpu_cooling.c
  @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
  unsigned int cpufreq_state;
  unsigned int cpufreq_val;
  struct cpumask allowed_cpus;
  +   struct list_head node;
   };
   static DEFINE_IDR(cpufreq_idr);
   static DEFINE_MUTEX(cooling_cpufreq_lock);
 
  -static unsigned int cpufreq_dev_count;
  -
   /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
   #define NOTIFY_INVALID NULL
   static struct cpufreq_cooling_device *notify_device;
 
  +/* A list to hold all the cpufreq cooling devices registered */
  +static LIST_HEAD(cpufreq_cooling_list);
  +
   /**
* get_idr - function to get a unique id.
* @idr: struct idr * handle used to create a id.
  @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
  notifier_block *nb,
   static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
   unsigned long *state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  -   struct cpumask *mask = cpufreq_device-allowed_cpus;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +   struct cpumask *mask = NULL;
  unsigned int cpu;
  unsigned int count = 0;
  int ret;
 
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
  +
  +   mask = cpufreq_device-allowed_cpus;
  cpu = cpumask_any(mask);
 
  ret = get_property(cpu, 0, count, GET_MAXL);
  @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
  thermal_cooling_device *cdev,
   static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
   unsigned long *state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
 
  *state = cpufreq_device-cpufreq_state;
 
  @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
  thermal_cooling_device *cdev,
   static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
   unsigned long state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
 
  return cpufreq_apply_cooling(cpufreq_device, state);
   }
  @@ -427,6 +460,7 @@ static struct notifier_block 
  thermal_cpufreq_notifier_block = {
* __cpufreq_cooling_register - helper function to create cpufreq cooling 
  device
* @np: a valid struct device_node to the cooling device device tree node
* @clip_cpus: cpumask of cpus where the frequency constraints will 
  happen.
  + * @devdata: driver data pointer
*
* This interface function registers the cpufreq cooling device with the 
  name
* thermal-cpufreq-%x. This api can support multiple instances of 
  cpufreq
  @@ -438,7 +472,7 @@ static struct notifier_block 
  thermal_cpufreq_notifier_block = {

Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-16 Thread Rafael J. Wysocki
On Thursday, May 15, 2014 02:33:07 PM Eduardo Valentin wrote:
> Hello Amit,
> 
> 
> On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
> > This patch is in preparation to add notfication support for cpufrequency
> > cooling changes. This change also removes the unnecessary exposing of
> > internal housekeeping structure via thermal_cooling_device->devdata to the
> > users of cpufreq cooling APIs.
> > 
> > Signed-off-by: Amit Daniel Kachhap 
> > ---
> >  drivers/thermal/cpu_cooling.c  |   79 
> > +++
> >  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
> >  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
> >  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
> >  include/linux/cpu_cooling.h|5 +-
> >  5 files changed, 68 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> > index 4246262..21f44d4 100644
> > --- a/drivers/thermal/cpu_cooling.c
> > +++ b/drivers/thermal/cpu_cooling.c
> > @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
> > unsigned int cpufreq_state;
> > unsigned int cpufreq_val;
> > struct cpumask allowed_cpus;
> > +   struct list_head node;
> >  };
> >  static DEFINE_IDR(cpufreq_idr);
> >  static DEFINE_MUTEX(cooling_cpufreq_lock);
> >  
> > -static unsigned int cpufreq_dev_count;
> > -
> >  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
> >  #define NOTIFY_INVALID NULL
> >  static struct cpufreq_cooling_device *notify_device;
> >  
> > +/* A list to hold all the cpufreq cooling devices registered */
> > +static LIST_HEAD(cpufreq_cooling_list);
> > +
> >  /**
> >   * get_idr - function to get a unique id.
> >   * @idr: struct idr * handle used to create a id.
> > @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
> > notifier_block *nb,
> >  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
> >  unsigned long *state)
> >  {
> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> > -   struct cpumask *mask = _device->allowed_cpus;
> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
> > +   struct cpumask *mask = NULL;
> > unsigned int cpu;
> > unsigned int count = 0;
> > int ret;
> >  
> > +   mutex_lock(_cpufreq_lock);
> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
> > +   if (cpufreq_device->cool_dev == cdev)
> > +   break;
> > +   mutex_unlock(_cpufreq_lock);
> > +   if (!cpufreq_device) {
> > +   /* Cooling device pointer not found */
> > +   return -EINVAL;
> > +   }
> > +
> > +   mask = _device->allowed_cpus;
> > cpu = cpumask_any(mask);
> >  
> > ret = get_property(cpu, 0, , GET_MAXL);
> > @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
> > thermal_cooling_device *cdev,
> >  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
> >  unsigned long *state)
> >  {
> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
> > +
> > +   mutex_lock(_cpufreq_lock);
> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
> > +   if (cpufreq_device->cool_dev == cdev)
> > +   break;
> > +   mutex_unlock(_cpufreq_lock);
> > +   if (!cpufreq_device) {
> > +   /* Cooling device pointer not found */
> > +   return -EINVAL;
> > +   }
> >  
> > *state = cpufreq_device->cpufreq_state;
> >  
> > @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
> > thermal_cooling_device *cdev,
> >  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
> >  unsigned long state)
> >  {
> > -   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> > +   struct cpufreq_cooling_device *cpufreq_device = NULL;
> > +
> > +   mutex_lock(_cpufreq_lock);
> > +   list_for_each_entry(cpufreq_device, _cooling_list, node)
> > +   if (cpufreq_device->cool_dev == cdev)
> > +   break;
> > +   mutex_unlock(_cpufreq_lock);
> > +   if (!cpufreq_device) {
> > +   /* Cooling device pointer not found */
> > +   return -EINVAL;
> > +   }
> >  
> > return cpufreq_apply_cooling(cpufreq_device, state);
> >  }
> > @@ -427,6 +460,7 @@ static struct notifier_block 
> > thermal_cpufreq_notifier_block = {
> >   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
> > device
> >   * @np: a valid struct device_node to the cooling device device tree node
> >   * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
> > + * @devdata: driver data pointer
> >   *
> >   * This interface function registers the cpufreq cooling device with the 
> > name
> >   * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
> > @@ 

Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-16 Thread Rafael J. Wysocki
On Thursday, May 15, 2014 02:33:07 PM Eduardo Valentin wrote:
 Hello Amit,
 
 
 On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
  This patch is in preparation to add notfication support for cpufrequency
  cooling changes. This change also removes the unnecessary exposing of
  internal housekeeping structure via thermal_cooling_device-devdata to the
  users of cpufreq cooling APIs.
  
  Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
  ---
   drivers/thermal/cpu_cooling.c  |   79 
  +++
   drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
   drivers/thermal/samsung/exynos_thermal_common.c|2 +-
   drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
   include/linux/cpu_cooling.h|5 +-
   5 files changed, 68 insertions(+), 22 deletions(-)
  
  diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
  index 4246262..21f44d4 100644
  --- a/drivers/thermal/cpu_cooling.c
  +++ b/drivers/thermal/cpu_cooling.c
  @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
  unsigned int cpufreq_state;
  unsigned int cpufreq_val;
  struct cpumask allowed_cpus;
  +   struct list_head node;
   };
   static DEFINE_IDR(cpufreq_idr);
   static DEFINE_MUTEX(cooling_cpufreq_lock);
   
  -static unsigned int cpufreq_dev_count;
  -
   /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
   #define NOTIFY_INVALID NULL
   static struct cpufreq_cooling_device *notify_device;
   
  +/* A list to hold all the cpufreq cooling devices registered */
  +static LIST_HEAD(cpufreq_cooling_list);
  +
   /**
* get_idr - function to get a unique id.
* @idr: struct idr * handle used to create a id.
  @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
  notifier_block *nb,
   static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
   unsigned long *state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  -   struct cpumask *mask = cpufreq_device-allowed_cpus;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +   struct cpumask *mask = NULL;
  unsigned int cpu;
  unsigned int count = 0;
  int ret;
   
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
  +
  +   mask = cpufreq_device-allowed_cpus;
  cpu = cpumask_any(mask);
   
  ret = get_property(cpu, 0, count, GET_MAXL);
  @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
  thermal_cooling_device *cdev,
   static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
   unsigned long *state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
   
  *state = cpufreq_device-cpufreq_state;
   
  @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
  thermal_cooling_device *cdev,
   static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
   unsigned long state)
   {
  -   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
  +   struct cpufreq_cooling_device *cpufreq_device = NULL;
  +
  +   mutex_lock(cooling_cpufreq_lock);
  +   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
  +   if (cpufreq_device-cool_dev == cdev)
  +   break;
  +   mutex_unlock(cooling_cpufreq_lock);
  +   if (!cpufreq_device) {
  +   /* Cooling device pointer not found */
  +   return -EINVAL;
  +   }
   
  return cpufreq_apply_cooling(cpufreq_device, state);
   }
  @@ -427,6 +460,7 @@ static struct notifier_block 
  thermal_cpufreq_notifier_block = {
* __cpufreq_cooling_register - helper function to create cpufreq cooling 
  device
* @np: a valid struct device_node to the cooling device device tree node
* @clip_cpus: cpumask of cpus where the frequency constraints will happen.
  + * @devdata: driver data pointer
*
* This interface function registers the cpufreq cooling device with the 
  name
* thermal-cpufreq-%x. This api can support multiple instances of cpufreq
  @@ -438,7 +472,7 @@ static struct notifier_block 
  thermal_cpufreq_notifier_block = {
*/
   static struct thermal_cooling_device *
   

Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-15 Thread Eduardo Valentin
Hello Amit,


On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
> This patch is in preparation to add notfication support for cpufrequency
> cooling changes. This change also removes the unnecessary exposing of
> internal housekeeping structure via thermal_cooling_device->devdata to the
> users of cpufreq cooling APIs.
> 
> Signed-off-by: Amit Daniel Kachhap 
> ---
>  drivers/thermal/cpu_cooling.c  |   79 +++
>  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
>  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
>  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
>  include/linux/cpu_cooling.h|5 +-
>  5 files changed, 68 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index 4246262..21f44d4 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
>   unsigned int cpufreq_state;
>   unsigned int cpufreq_val;
>   struct cpumask allowed_cpus;
> + struct list_head node;
>  };
>  static DEFINE_IDR(cpufreq_idr);
>  static DEFINE_MUTEX(cooling_cpufreq_lock);
>  
> -static unsigned int cpufreq_dev_count;
> -
>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>  #define NOTIFY_INVALID NULL
>  static struct cpufreq_cooling_device *notify_device;
>  
> +/* A list to hold all the cpufreq cooling devices registered */
> +static LIST_HEAD(cpufreq_cooling_list);
> +
>  /**
>   * get_idr - function to get a unique id.
>   * @idr: struct idr * handle used to create a id.
> @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
> notifier_block *nb,
>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>unsigned long *state)
>  {
> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> - struct cpumask *mask = _device->allowed_cpus;
> + struct cpufreq_cooling_device *cpufreq_device = NULL;
> + struct cpumask *mask = NULL;
>   unsigned int cpu;
>   unsigned int count = 0;
>   int ret;
>  
> + mutex_lock(_cpufreq_lock);
> + list_for_each_entry(cpufreq_device, _cooling_list, node)
> + if (cpufreq_device->cool_dev == cdev)
> + break;
> + mutex_unlock(_cpufreq_lock);
> + if (!cpufreq_device) {
> + /* Cooling device pointer not found */
> + return -EINVAL;
> + }
> +
> + mask = _device->allowed_cpus;
>   cpu = cpumask_any(mask);
>  
>   ret = get_property(cpu, 0, , GET_MAXL);
> @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
> thermal_cooling_device *cdev,
>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>unsigned long *state)
>  {
> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> + struct cpufreq_cooling_device *cpufreq_device = NULL;
> +
> + mutex_lock(_cpufreq_lock);
> + list_for_each_entry(cpufreq_device, _cooling_list, node)
> + if (cpufreq_device->cool_dev == cdev)
> + break;
> + mutex_unlock(_cpufreq_lock);
> + if (!cpufreq_device) {
> + /* Cooling device pointer not found */
> + return -EINVAL;
> + }
>  
>   *state = cpufreq_device->cpufreq_state;
>  
> @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
> thermal_cooling_device *cdev,
>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>unsigned long state)
>  {
> - struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> + struct cpufreq_cooling_device *cpufreq_device = NULL;
> +
> + mutex_lock(_cpufreq_lock);
> + list_for_each_entry(cpufreq_device, _cooling_list, node)
> + if (cpufreq_device->cool_dev == cdev)
> + break;
> + mutex_unlock(_cpufreq_lock);
> + if (!cpufreq_device) {
> + /* Cooling device pointer not found */
> + return -EINVAL;
> + }
>  
>   return cpufreq_apply_cooling(cpufreq_device, state);
>  }
> @@ -427,6 +460,7 @@ static struct notifier_block 
> thermal_cpufreq_notifier_block = {
>   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
> device
>   * @np: a valid struct device_node to the cooling device device tree node
>   * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
> + * @devdata: driver data pointer
>   *
>   * This interface function registers the cpufreq cooling device with the name
>   * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
> @@ -438,7 +472,7 @@ static struct notifier_block 
> thermal_cpufreq_notifier_block = {
>   */
>  static struct thermal_cooling_device *
>  __cpufreq_cooling_register(struct device_node *np,
> -

Re: [RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-15 Thread Eduardo Valentin
Hello Amit,


On Thu, May 08, 2014 at 08:07:56PM +0530, Amit Daniel Kachhap wrote:
 This patch is in preparation to add notfication support for cpufrequency
 cooling changes. This change also removes the unnecessary exposing of
 internal housekeeping structure via thermal_cooling_device-devdata to the
 users of cpufreq cooling APIs.
 
 Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
 ---
  drivers/thermal/cpu_cooling.c  |   79 +++
  drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
  drivers/thermal/samsung/exynos_thermal_common.c|2 +-
  drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
  include/linux/cpu_cooling.h|5 +-
  5 files changed, 68 insertions(+), 22 deletions(-)
 
 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 4246262..21f44d4 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
   unsigned int cpufreq_state;
   unsigned int cpufreq_val;
   struct cpumask allowed_cpus;
 + struct list_head node;
  };
  static DEFINE_IDR(cpufreq_idr);
  static DEFINE_MUTEX(cooling_cpufreq_lock);
  
 -static unsigned int cpufreq_dev_count;
 -
  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
  static struct cpufreq_cooling_device *notify_device;
  
 +/* A list to hold all the cpufreq cooling devices registered */
 +static LIST_HEAD(cpufreq_cooling_list);
 +
  /**
   * get_idr - function to get a unique id.
   * @idr: struct idr * handle used to create a id.
 @@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 - struct cpumask *mask = cpufreq_device-allowed_cpus;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 + struct cpumask *mask = NULL;
   unsigned int cpu;
   unsigned int count = 0;
   int ret;
  
 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }
 +
 + mask = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(mask);
  
   ret = get_property(cpu, 0, count, GET_MAXL);
 @@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 +
 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }
  
   *state = cpufreq_device-cpufreq_state;
  
 @@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
  {
 - struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 + struct cpufreq_cooling_device *cpufreq_device = NULL;
 +
 + mutex_lock(cooling_cpufreq_lock);
 + list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
 + if (cpufreq_device-cool_dev == cdev)
 + break;
 + mutex_unlock(cooling_cpufreq_lock);
 + if (!cpufreq_device) {
 + /* Cooling device pointer not found */
 + return -EINVAL;
 + }
  
   return cpufreq_apply_cooling(cpufreq_device, state);
  }
 @@ -427,6 +460,7 @@ static struct notifier_block 
 thermal_cpufreq_notifier_block = {
   * __cpufreq_cooling_register - helper function to create cpufreq cooling 
 device
   * @np: a valid struct device_node to the cooling device device tree node
   * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
 + * @devdata: driver data pointer
   *
   * This interface function registers the cpufreq cooling device with the name
   * thermal-cpufreq-%x. This api can support multiple instances of cpufreq
 @@ -438,7 +472,7 @@ static struct notifier_block 
 thermal_cpufreq_notifier_block = {
   */
  static struct thermal_cooling_device *
  __cpufreq_cooling_register(struct device_node *np,
 -const struct cpumask *clip_cpus)
 

[RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-08 Thread Amit Daniel Kachhap
This patch is in preparation to add notfication support for cpufrequency
cooling changes. This change also removes the unnecessary exposing of
internal housekeeping structure via thermal_cooling_device->devdata to the
users of cpufreq cooling APIs.

Signed-off-by: Amit Daniel Kachhap 
---
 drivers/thermal/cpu_cooling.c  |   79 +++
 drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
 drivers/thermal/samsung/exynos_thermal_common.c|2 +-
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
 include/linux/cpu_cooling.h|5 +-
 5 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262..21f44d4 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
unsigned int cpufreq_state;
unsigned int cpufreq_val;
struct cpumask allowed_cpus;
+   struct list_head node;
 };
 static DEFINE_IDR(cpufreq_idr);
 static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static unsigned int cpufreq_dev_count;
-
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
 static struct cpufreq_cooling_device *notify_device;
 
+/* A list to hold all the cpufreq cooling devices registered */
+static LIST_HEAD(cpufreq_cooling_list);
+
 /**
  * get_idr - function to get a unique id.
  * @idr: struct idr * handle used to create a id.
@@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
-   struct cpumask *mask = _device->allowed_cpus;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+   struct cpumask *mask = NULL;
unsigned int cpu;
unsigned int count = 0;
int ret;
 
+   mutex_lock(_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, _cooling_list, node)
+   if (cpufreq_device->cool_dev == cdev)
+   break;
+   mutex_unlock(_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
+
+   mask = _device->allowed_cpus;
cpu = cpumask_any(mask);
 
ret = get_property(cpu, 0, , GET_MAXL);
@@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+
+   mutex_lock(_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, _cooling_list, node)
+   if (cpufreq_device->cool_dev == cdev)
+   break;
+   mutex_unlock(_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
 
*state = cpufreq_device->cpufreq_state;
 
@@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+
+   mutex_lock(_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, _cooling_list, node)
+   if (cpufreq_device->cool_dev == cdev)
+   break;
+   mutex_unlock(_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
 
return cpufreq_apply_cooling(cpufreq_device, state);
 }
@@ -427,6 +460,7 @@ static struct notifier_block thermal_cpufreq_notifier_block 
= {
  * __cpufreq_cooling_register - helper function to create cpufreq cooling 
device
  * @np: a valid struct device_node to the cooling device device tree node
  * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
+ * @devdata: driver data pointer
  *
  * This interface function registers the cpufreq cooling device with the name
  * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
@@ -438,7 +472,7 @@ static struct notifier_block thermal_cpufreq_notifier_block 
= {
  */
 static struct thermal_cooling_device *
 __cpufreq_cooling_register(struct device_node *np,
-  const struct cpumask *clip_cpus)
+  const struct cpumask *clip_cpus, void *devdata)
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
@@ -477,7 

[RFC PATCH 1/5] thermal: cpu_cooling: Support passing driver private data.

2014-05-08 Thread Amit Daniel Kachhap
This patch is in preparation to add notfication support for cpufrequency
cooling changes. This change also removes the unnecessary exposing of
internal housekeeping structure via thermal_cooling_device-devdata to the
users of cpufreq cooling APIs.

Signed-off-by: Amit Daniel Kachhap amit.dan...@samsung.com
---
 drivers/thermal/cpu_cooling.c  |   79 +++
 drivers/thermal/db8500_cpufreq_cooling.c   |2 +-
 drivers/thermal/samsung/exynos_thermal_common.c|2 +-
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c |2 +-
 include/linux/cpu_cooling.h|5 +-
 5 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262..21f44d4 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -50,16 +50,18 @@ struct cpufreq_cooling_device {
unsigned int cpufreq_state;
unsigned int cpufreq_val;
struct cpumask allowed_cpus;
+   struct list_head node;
 };
 static DEFINE_IDR(cpufreq_idr);
 static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static unsigned int cpufreq_dev_count;
-
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
 static struct cpufreq_cooling_device *notify_device;
 
+/* A list to hold all the cpufreq cooling devices registered */
+static LIST_HEAD(cpufreq_cooling_list);
+
 /**
  * get_idr - function to get a unique id.
  * @idr: struct idr * handle used to create a id.
@@ -357,12 +359,23 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
-   struct cpumask *mask = cpufreq_device-allowed_cpus;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+   struct cpumask *mask = NULL;
unsigned int cpu;
unsigned int count = 0;
int ret;
 
+   mutex_lock(cooling_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
+   if (cpufreq_device-cool_dev == cdev)
+   break;
+   mutex_unlock(cooling_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
+
+   mask = cpufreq_device-allowed_cpus;
cpu = cpumask_any(mask);
 
ret = get_property(cpu, 0, count, GET_MAXL);
@@ -386,7 +399,17 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+
+   mutex_lock(cooling_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
+   if (cpufreq_device-cool_dev == cdev)
+   break;
+   mutex_unlock(cooling_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
 
*state = cpufreq_device-cpufreq_state;
 
@@ -406,7 +429,17 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
+   struct cpufreq_cooling_device *cpufreq_device = NULL;
+
+   mutex_lock(cooling_cpufreq_lock);
+   list_for_each_entry(cpufreq_device, cpufreq_cooling_list, node)
+   if (cpufreq_device-cool_dev == cdev)
+   break;
+   mutex_unlock(cooling_cpufreq_lock);
+   if (!cpufreq_device) {
+   /* Cooling device pointer not found */
+   return -EINVAL;
+   }
 
return cpufreq_apply_cooling(cpufreq_device, state);
 }
@@ -427,6 +460,7 @@ static struct notifier_block thermal_cpufreq_notifier_block 
= {
  * __cpufreq_cooling_register - helper function to create cpufreq cooling 
device
  * @np: a valid struct device_node to the cooling device device tree node
  * @clip_cpus: cpumask of cpus where the frequency constraints will happen.
+ * @devdata: driver data pointer
  *
  * This interface function registers the cpufreq cooling device with the name
  * thermal-cpufreq-%x. This api can support multiple instances of cpufreq
@@ -438,7 +472,7 @@ static struct notifier_block thermal_cpufreq_notifier_block 
= {
  */
 static struct thermal_cooling_device *
 __cpufreq_cooling_register(struct device_node *np,
-  const struct cpumask *clip_cpus)
+  const struct cpumask *clip_cpus, void *devdata)
 {
struct