RE: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-10 Thread Ran Wang
Hi Scott,

On 2018/9/8 4:35, Scott Wood wrote:
> 
> On Fri, 2018-08-31 at 11:52 +0800, Ran Wang wrote:
> > This driver is to provide a independent framework for PM service
> > provider and consumer to configure system level wake up feature. For
> > example, RCPM driver could register a callback function on this
> > platform first, and Flex timer driver who want to enable timer wake up
> > feature, will call generic API provided by this platform driver, and
> > then it will trigger RCPM driver to do it. The benefit is to isolate
> > the user and service, such as flex timer driver will not have to know
> > the implement details of wakeup function it require. Besides, it is
> > also easy for service side to upgrade its logic when design is changed
> > and remain user side unchanged.
> >
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/soc/fsl/Kconfig   |   14 +
> >  drivers/soc/fsl/Makefile  |1 +
> >  drivers/soc/fsl/plat_pm.c |  144
> > +
> >  include/soc/fsl/plat_pm.h |   22 +++
> >  4 files changed, 181 insertions(+), 0 deletions(-)  create mode
> > 100644 drivers/soc/fsl/plat_pm.c  create mode 100644
> > include/soc/fsl/plat_pm.h
> >
> > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index
> > 7a9fb9b..6517412 100644
> > --- a/drivers/soc/fsl/Kconfig
> > +++ b/drivers/soc/fsl/Kconfig
> > @@ -16,3 +16,17 @@ config FSL_GUTS
> >   Initially only reading SVR and registering soc device are
> > supported.
> >   Other guts accesses, such as reading RCW, should eventually be
> > moved
> >   into this driver as well.
> +
> > +config FSL_PLAT_PM
> > +   bool "Freescale platform PM framework"
> 
> This name seems to be simultaneously too generic (for something that is
> likely intended only for use with certain Freescale/NXP chip families) and too
> specific (for something that seems to be general infrastructure with no real
> hardware dependencies).

Yes, this driver has no real HW dependencies at all. But we'd like to introduce 
it
to help providing more flexibility & generic on FSL PM feature configure (so 
far 
we have RCPM on system wakeup source control). I think it's good
for driver/IP porting among different SoC in the future. As to the name, do you
have better suggestion?

> What specific problems with Linux's generic wakeup infrastructure is this
> trying to solve, and why would those problems not be better solved there?

Actually, I am not sure if generic wakeup infrastructure have this kind of PM 
feature
(keep specific IP alive during system suspend, could you please show me?).
And I think it is not common requirement, so I decide to put it in FSL folder. 

> Also, you should CC linux-pm on these patches.

Yes, thanks for suggestion

Regards,
Ran

> -Scott



RE: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-09 Thread Ran Wang
Hi Dongsheng,

On 2018/9/7 18:16, Dongsheng Wang wrote:
> 
> On 2018/9/7 16:49, Ran Wang wrote:
> > Hi Dongsheng
> >
> >> On 2018/9/5 11:05, Dongsheng Wang wrote:
> >>
> >> Please change your comments style.
> >>
> >> On 2018/8/31 11:57, Ran Wang wrote:
> >>> This driver is to provide a independent framework for PM service
> >>> provider and consumer to configure system level wake up feature. For
> >>> example, RCPM driver could register a callback function on this
> >>> platform first, and Flex timer driver who want to enable timer wake
> >>> up feature, will call generic API provided by this platform driver,
> >>> and then it will trigger RCPM driver to do it. The benefit is to
> >>> isolate the user and service, such as flex timer driver will not
> >>> have to know the implement details of wakeup function it require.
> >>> Besides, it is also easy for service side to upgrade its logic when
> >>> design is changed and remain user side unchanged.
> >>>
> >>> Signed-off-by: Ran Wang 
> >>> ---
> >>>  drivers/soc/fsl/Kconfig   |   14 +
> >>>  drivers/soc/fsl/Makefile  |1 +
> >>>  drivers/soc/fsl/plat_pm.c |  144
> >> +
> >>>  include/soc/fsl/plat_pm.h |   22 +++
> >>>  4 files changed, 181 insertions(+), 0 deletions(-)  create mode
> >>> 100644 drivers/soc/fsl/plat_pm.c  create mode 100644
> >>> include/soc/fsl/plat_pm.h
> >>>
> >>> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index
> >>> 7a9fb9b..6517412 100644
> >>> --- a/drivers/soc/fsl/Kconfig
> >>> +++ b/drivers/soc/fsl/Kconfig
> >>> @@ -16,3 +16,17 @@ config FSL_GUTS
> >>> Initially only reading SVR and registering soc device are supported.
> >>> Other guts accesses, such as reading RCW, should eventually be
> >> moved
> >>> into this driver as well.
> >>> +
> >>> +config FSL_PLAT_PM
> >>> + bool "Freescale platform PM framework"
> >>> + help
> >>> +   This driver is to provide a independent framework for PM service
> >>> +   provider and consumer to configure system level wake up feature.
> >> For
> >>> +   example, RCPM driver could register a callback function on this
> >>> +   platform first, and Flex timer driver who want to enable timer wake
> >>> +   up feature, will call generic API provided by this platform driver,
> >>> +   and then it will trigger RCPM driver to do it. The benefit is to
> >>> +   isolate the user and service, such as  flex timer driver will not
> >>> +   have to know the implement details of wakeup function it require.
> >>> +   Besides, it is also easy for service side to upgrade its logic when
> >>> +   design changed and remain user side unchanged.
> >>> diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
> >>> index
> >>> 44b3beb..8f9db23 100644
> >>> --- a/drivers/soc/fsl/Makefile
> >>> +++ b/drivers/soc/fsl/Makefile
> >>> @@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/
> >>>  obj-$(CONFIG_QUICC_ENGINE)   += qe/
> >>>  obj-$(CONFIG_CPM)+= qe/
> >>>  obj-$(CONFIG_FSL_GUTS)   += guts.o
> >>> +obj-$(CONFIG_FSL_PLAT_PM)+= plat_pm.o
> >>> diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c
> >>> new file mode 100644 index 000..19ea14e
> >>> --- /dev/null
> >>> +++ b/drivers/soc/fsl/plat_pm.c
> >>> @@ -0,0 +1,144 @@
> >>> +// SPDX-License-Identifier: GPL-2.0 // // plat_pm.c - Freescale
> >>> +platform PM framework // // Copyright 2018 NXP // // Author: Ran
> >>> +Wang ,
> >>> +
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +
> >>> +
> >>> +struct plat_pm_t {
> >>> + struct list_head node;
> >>> + fsl_plat_pm_handle handle;
> >>> + void *handle_priv;
> >>> + spinlock_t  lock;
> >>> +};
> >>> +
> >>> +static struct plat_pm_t plat_pm;
> >>> +
> >>> +// register_fsl_platform_wakeup_source - Register callback function
> >>> +to plat_pm // @handle: Pointer to handle PM feature requirement //
> >>> +@handle_priv: Handler specific data struct // // Return 0 on
> >>> +success other negative errno int
> >>> +register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle,
> >>> + void *handle_priv)
> >>> +{
> >>> + struct plat_pm_t *p;
> >>> + unsigned long   flags;
> >>> +
> >>> + if (!handle) {
> >>> + pr_err("FSL plat_pm: Handler invalid, reject\n");
> >>> + return -EINVAL;
> >>> + }
> >>> +
> >>> + p = kmalloc(sizeof(*p), GFP_KERNEL);
> >>> + if (!p)
> >>> + return -ENOMEM;
> >>> +
> >>> + p->handle = handle;
> >>> + p->handle_priv = handle_priv;
> >>> +
> >>> + spin_lock_irqsave(_pm.lock, flags);
> >>> + list_add_tail(>node, _pm.node);
> >>> + spin_unlock_irqrestore(_pm.lock, flags);
> >>> +
> >>> + return 0;
> >>> +}
> >>> +EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source);
> >>> +
> >>> +// Deregister_fsl_platform_wakeup_source - deregister callback
> >>> +function // @handle_priv: Handler specific data struct // // Return
> >>> +0 on 

Re: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-07 Thread Scott Wood
On Fri, 2018-08-31 at 11:52 +0800, Ran Wang wrote:
> This driver is to provide a independent framework for PM service
> provider and consumer to configure system level wake up feature. For
> example, RCPM driver could register a callback function on this
> platform first, and Flex timer driver who want to enable timer wake
> up feature, will call generic API provided by this platform driver,
> and then it will trigger RCPM driver to do it. The benefit is to
> isolate the user and service, such as flex timer driver will not have
> to know the implement details of wakeup function it require. Besides,
> it is also easy for service side to upgrade its logic when design is
> changed and remain user side unchanged.
> 
> Signed-off-by: Ran Wang 
> ---
>  drivers/soc/fsl/Kconfig   |   14 +
>  drivers/soc/fsl/Makefile  |1 +
>  drivers/soc/fsl/plat_pm.c |  144
> +
>  include/soc/fsl/plat_pm.h |   22 +++
>  4 files changed, 181 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/soc/fsl/plat_pm.c
>  create mode 100644 include/soc/fsl/plat_pm.h
> 
> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
> index 7a9fb9b..6517412 100644
> --- a/drivers/soc/fsl/Kconfig
> +++ b/drivers/soc/fsl/Kconfig
> @@ -16,3 +16,17 @@ config FSL_GUTS
> Initially only reading SVR and registering soc device are
> supported.
> Other guts accesses, such as reading RCW, should eventually be
> moved
> into this driver as well.
+
> +config FSL_PLAT_PM
> + bool "Freescale platform PM framework"

This name seems to be simultaneously too generic (for something that is likely
intended only for use with certain Freescale/NXP chip families) and too
specific (for something that seems to be general infrastructure with no real
hardware dependencies).

What specific problems with Linux's generic wakeup infrastructure is this
trying to solve, and why would those problems not be better solved there?

Also, you should CC linux-pm on these patches.

-Scott



Re: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-07 Thread Wang, Dongsheng
On 2018/9/7 16:49, Ran Wang wrote:
> Hi Dongsheng
>
>> On 2018/9/5 11:05, Dongsheng Wang wrote:
>>
>> Please change your comments style.
>>
>> On 2018/8/31 11:57, Ran Wang wrote:
>>> This driver is to provide a independent framework for PM service
>>> provider and consumer to configure system level wake up feature. For
>>> example, RCPM driver could register a callback function on this
>>> platform first, and Flex timer driver who want to enable timer wake up
>>> feature, will call generic API provided by this platform driver, and
>>> then it will trigger RCPM driver to do it. The benefit is to isolate
>>> the user and service, such as flex timer driver will not have to know
>>> the implement details of wakeup function it require. Besides, it is
>>> also easy for service side to upgrade its logic when design is changed
>>> and remain user side unchanged.
>>>
>>> Signed-off-by: Ran Wang 
>>> ---
>>>  drivers/soc/fsl/Kconfig   |   14 +
>>>  drivers/soc/fsl/Makefile  |1 +
>>>  drivers/soc/fsl/plat_pm.c |  144
>> +
>>>  include/soc/fsl/plat_pm.h |   22 +++
>>>  4 files changed, 181 insertions(+), 0 deletions(-)  create mode
>>> 100644 drivers/soc/fsl/plat_pm.c  create mode 100644
>>> include/soc/fsl/plat_pm.h
>>>
>>> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index
>>> 7a9fb9b..6517412 100644
>>> --- a/drivers/soc/fsl/Kconfig
>>> +++ b/drivers/soc/fsl/Kconfig
>>> @@ -16,3 +16,17 @@ config FSL_GUTS
>>>   Initially only reading SVR and registering soc device are supported.
>>>   Other guts accesses, such as reading RCW, should eventually be
>> moved
>>>   into this driver as well.
>>> +
>>> +config FSL_PLAT_PM
>>> +   bool "Freescale platform PM framework"
>>> +   help
>>> + This driver is to provide a independent framework for PM service
>>> + provider and consumer to configure system level wake up feature.
>> For
>>> + example, RCPM driver could register a callback function on this
>>> + platform first, and Flex timer driver who want to enable timer wake
>>> + up feature, will call generic API provided by this platform driver,
>>> + and then it will trigger RCPM driver to do it. The benefit is to
>>> + isolate the user and service, such as  flex timer driver will not
>>> + have to know the implement details of wakeup function it require.
>>> + Besides, it is also easy for service side to upgrade its logic when
>>> + design changed and remain user side unchanged.
>>> diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile index
>>> 44b3beb..8f9db23 100644
>>> --- a/drivers/soc/fsl/Makefile
>>> +++ b/drivers/soc/fsl/Makefile
>>> @@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/
>>>  obj-$(CONFIG_QUICC_ENGINE) += qe/
>>>  obj-$(CONFIG_CPM)  += qe/
>>>  obj-$(CONFIG_FSL_GUTS) += guts.o
>>> +obj-$(CONFIG_FSL_PLAT_PM)  += plat_pm.o
>>> diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c new
>>> file mode 100644 index 000..19ea14e
>>> --- /dev/null
>>> +++ b/drivers/soc/fsl/plat_pm.c
>>> @@ -0,0 +1,144 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +//
>>> +// plat_pm.c - Freescale platform PM framework // // Copyright 2018
>>> +NXP // // Author: Ran Wang ,
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +
>>> +struct plat_pm_t {
>>> +   struct list_head node;
>>> +   fsl_plat_pm_handle handle;
>>> +   void *handle_priv;
>>> +   spinlock_t  lock;
>>> +};
>>> +
>>> +static struct plat_pm_t plat_pm;
>>> +
>>> +// register_fsl_platform_wakeup_source - Register callback function
>>> +to plat_pm // @handle: Pointer to handle PM feature requirement //
>>> +@handle_priv: Handler specific data struct // // Return 0 on success
>>> +other negative errno int
>>> +register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle,
>>> +   void *handle_priv)
>>> +{
>>> +   struct plat_pm_t *p;
>>> +   unsigned long   flags;
>>> +
>>> +   if (!handle) {
>>> +   pr_err("FSL plat_pm: Handler invalid, reject\n");
>>> +   return -EINVAL;
>>> +   }
>>> +
>>> +   p = kmalloc(sizeof(*p), GFP_KERNEL);
>>> +   if (!p)
>>> +   return -ENOMEM;
>>> +
>>> +   p->handle = handle;
>>> +   p->handle_priv = handle_priv;
>>> +
>>> +   spin_lock_irqsave(_pm.lock, flags);
>>> +   list_add_tail(>node, _pm.node);
>>> +   spin_unlock_irqrestore(_pm.lock, flags);
>>> +
>>> +   return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source);
>>> +
>>> +// Deregister_fsl_platform_wakeup_source - deregister callback
>>> +function // @handle_priv: Handler specific data struct // // Return 0
>>> +on success other negative errno int
>>> +deregister_fsl_platform_wakeup_source(void *handle_priv) {
>>> +   struct plat_pm_t *p, *tmp;
>>> +   unsigned long   flags;
>>> +
>>> +   spin_lock_irqsave(_pm.lock, flags);
>>> +   list_for_each_entry_safe(p, 

RE: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-07 Thread Ran Wang
Hi Dongsheng

> On 2018/9/5 11:05, Dongsheng Wang wrote:
> 
> Please change your comments style.
> 
> On 2018/8/31 11:57, Ran Wang wrote:
> > This driver is to provide a independent framework for PM service
> > provider and consumer to configure system level wake up feature. For
> > example, RCPM driver could register a callback function on this
> > platform first, and Flex timer driver who want to enable timer wake up
> > feature, will call generic API provided by this platform driver, and
> > then it will trigger RCPM driver to do it. The benefit is to isolate
> > the user and service, such as flex timer driver will not have to know
> > the implement details of wakeup function it require. Besides, it is
> > also easy for service side to upgrade its logic when design is changed
> > and remain user side unchanged.
> >
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/soc/fsl/Kconfig   |   14 +
> >  drivers/soc/fsl/Makefile  |1 +
> >  drivers/soc/fsl/plat_pm.c |  144
> +
> >  include/soc/fsl/plat_pm.h |   22 +++
> >  4 files changed, 181 insertions(+), 0 deletions(-)  create mode
> > 100644 drivers/soc/fsl/plat_pm.c  create mode 100644
> > include/soc/fsl/plat_pm.h
> >
> > diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index
> > 7a9fb9b..6517412 100644
> > --- a/drivers/soc/fsl/Kconfig
> > +++ b/drivers/soc/fsl/Kconfig
> > @@ -16,3 +16,17 @@ config FSL_GUTS
> >   Initially only reading SVR and registering soc device are supported.
> >   Other guts accesses, such as reading RCW, should eventually be
> moved
> >   into this driver as well.
> > +
> > +config FSL_PLAT_PM
> > +   bool "Freescale platform PM framework"
> > +   help
> > + This driver is to provide a independent framework for PM service
> > + provider and consumer to configure system level wake up feature.
> For
> > + example, RCPM driver could register a callback function on this
> > + platform first, and Flex timer driver who want to enable timer wake
> > + up feature, will call generic API provided by this platform driver,
> > + and then it will trigger RCPM driver to do it. The benefit is to
> > + isolate the user and service, such as  flex timer driver will not
> > + have to know the implement details of wakeup function it require.
> > + Besides, it is also easy for service side to upgrade its logic when
> > + design changed and remain user side unchanged.
> > diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile index
> > 44b3beb..8f9db23 100644
> > --- a/drivers/soc/fsl/Makefile
> > +++ b/drivers/soc/fsl/Makefile
> > @@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/
> >  obj-$(CONFIG_QUICC_ENGINE) += qe/
> >  obj-$(CONFIG_CPM)  += qe/
> >  obj-$(CONFIG_FSL_GUTS) += guts.o
> > +obj-$(CONFIG_FSL_PLAT_PM)  += plat_pm.o
> > diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c new
> > file mode 100644 index 000..19ea14e
> > --- /dev/null
> > +++ b/drivers/soc/fsl/plat_pm.c
> > @@ -0,0 +1,144 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// plat_pm.c - Freescale platform PM framework // // Copyright 2018
> > +NXP // // Author: Ran Wang ,
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +
> > +struct plat_pm_t {
> > +   struct list_head node;
> > +   fsl_plat_pm_handle handle;
> > +   void *handle_priv;
> > +   spinlock_t  lock;
> > +};
> > +
> > +static struct plat_pm_t plat_pm;
> > +
> > +// register_fsl_platform_wakeup_source - Register callback function
> > +to plat_pm // @handle: Pointer to handle PM feature requirement //
> > +@handle_priv: Handler specific data struct // // Return 0 on success
> > +other negative errno int
> > +register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle,
> > +   void *handle_priv)
> > +{
> > +   struct plat_pm_t *p;
> > +   unsigned long   flags;
> > +
> > +   if (!handle) {
> > +   pr_err("FSL plat_pm: Handler invalid, reject\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   p = kmalloc(sizeof(*p), GFP_KERNEL);
> > +   if (!p)
> > +   return -ENOMEM;
> > +
> > +   p->handle = handle;
> > +   p->handle_priv = handle_priv;
> > +
> > +   spin_lock_irqsave(_pm.lock, flags);
> > +   list_add_tail(>node, _pm.node);
> > +   spin_unlock_irqrestore(_pm.lock, flags);
> > +
> > +   return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source);
> > +
> > +// Deregister_fsl_platform_wakeup_source - deregister callback
> > +function // @handle_priv: Handler specific data struct // // Return 0
> > +on success other negative errno int
> > +deregister_fsl_platform_wakeup_source(void *handle_priv) {
> > +   struct plat_pm_t *p, *tmp;
> > +   unsigned long   flags;
> > +
> > +   spin_lock_irqsave(_pm.lock, flags);
> > +   list_for_each_entry_safe(p, tmp, _pm.node, node) {
> > +   if 

Re: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-09-04 Thread Wang, Dongsheng
Please change your comments style.

On 2018/8/31 11:57, Ran Wang wrote:
> This driver is to provide a independent framework for PM service
> provider and consumer to configure system level wake up feature. For
> example, RCPM driver could register a callback function on this
> platform first, and Flex timer driver who want to enable timer wake
> up feature, will call generic API provided by this platform driver,
> and then it will trigger RCPM driver to do it. The benefit is to
> isolate the user and service, such as flex timer driver will not have
> to know the implement details of wakeup function it require. Besides,
> it is also easy for service side to upgrade its logic when design is
> changed and remain user side unchanged.
>
> Signed-off-by: Ran Wang 
> ---
>  drivers/soc/fsl/Kconfig   |   14 +
>  drivers/soc/fsl/Makefile  |1 +
>  drivers/soc/fsl/plat_pm.c |  144 
> +
>  include/soc/fsl/plat_pm.h |   22 +++
>  4 files changed, 181 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/soc/fsl/plat_pm.c
>  create mode 100644 include/soc/fsl/plat_pm.h
>
> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
> index 7a9fb9b..6517412 100644
> --- a/drivers/soc/fsl/Kconfig
> +++ b/drivers/soc/fsl/Kconfig
> @@ -16,3 +16,17 @@ config FSL_GUTS
> Initially only reading SVR and registering soc device are supported.
> Other guts accesses, such as reading RCW, should eventually be moved
> into this driver as well.
> +
> +config FSL_PLAT_PM
> + bool "Freescale platform PM framework"
> + help
> +   This driver is to provide a independent framework for PM service
> +   provider and consumer to configure system level wake up feature. For
> +   example, RCPM driver could register a callback function on this
> +   platform first, and Flex timer driver who want to enable timer wake
> +   up feature, will call generic API provided by this platform driver,
> +   and then it will trigger RCPM driver to do it. The benefit is to
> +   isolate the user and service, such as  flex timer driver will not
> +   have to know the implement details of wakeup function it require.
> +   Besides, it is also easy for service side to upgrade its logic when
> +   design changed and remain user side unchanged.
> diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
> index 44b3beb..8f9db23 100644
> --- a/drivers/soc/fsl/Makefile
> +++ b/drivers/soc/fsl/Makefile
> @@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/
>  obj-$(CONFIG_QUICC_ENGINE)   += qe/
>  obj-$(CONFIG_CPM)+= qe/
>  obj-$(CONFIG_FSL_GUTS)   += guts.o
> +obj-$(CONFIG_FSL_PLAT_PM)+= plat_pm.o
> diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c
> new file mode 100644
> index 000..19ea14e
> --- /dev/null
> +++ b/drivers/soc/fsl/plat_pm.c
> @@ -0,0 +1,144 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// plat_pm.c - Freescale platform PM framework
> +//
> +// Copyright 2018 NXP
> +//
> +// Author: Ran Wang ,
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +
> +struct plat_pm_t {
> + struct list_head node;
> + fsl_plat_pm_handle handle;
> + void *handle_priv;
> + spinlock_t  lock;
> +};
> +
> +static struct plat_pm_t plat_pm;
> +
> +// register_fsl_platform_wakeup_source - Register callback function to 
> plat_pm
> +// @handle: Pointer to handle PM feature requirement
> +// @handle_priv: Handler specific data struct
> +//
> +// Return 0 on success other negative errno
> +int register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle,
> + void *handle_priv)
> +{
> + struct plat_pm_t *p;
> + unsigned long   flags;
> +
> + if (!handle) {
> + pr_err("FSL plat_pm: Handler invalid, reject\n");
> + return -EINVAL;
> + }
> +
> + p = kmalloc(sizeof(*p), GFP_KERNEL);
> + if (!p)
> + return -ENOMEM;
> +
> + p->handle = handle;
> + p->handle_priv = handle_priv;
> +
> + spin_lock_irqsave(_pm.lock, flags);
> + list_add_tail(>node, _pm.node);
> + spin_unlock_irqrestore(_pm.lock, flags);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source);
> +
> +// Deregister_fsl_platform_wakeup_source - deregister callback function
> +// @handle_priv: Handler specific data struct
> +//
> +// Return 0 on success other negative errno
> +int deregister_fsl_platform_wakeup_source(void *handle_priv)
> +{
> + struct plat_pm_t *p, *tmp;
> + unsigned long   flags;
> +
> + spin_lock_irqsave(_pm.lock, flags);
> + list_for_each_entry_safe(p, tmp, _pm.node, node) {
> + if (p->handle_priv == handle_priv) {
> + list_del(>node);
> + kfree(p);
> + }
> + }
> + spin_unlock_irqrestore(_pm.lock, flags);
> + return 

[PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms

2018-08-30 Thread Ran Wang
This driver is to provide a independent framework for PM service
provider and consumer to configure system level wake up feature. For
example, RCPM driver could register a callback function on this
platform first, and Flex timer driver who want to enable timer wake
up feature, will call generic API provided by this platform driver,
and then it will trigger RCPM driver to do it. The benefit is to
isolate the user and service, such as flex timer driver will not have
to know the implement details of wakeup function it require. Besides,
it is also easy for service side to upgrade its logic when design is
changed and remain user side unchanged.

Signed-off-by: Ran Wang 
---
 drivers/soc/fsl/Kconfig   |   14 +
 drivers/soc/fsl/Makefile  |1 +
 drivers/soc/fsl/plat_pm.c |  144 +
 include/soc/fsl/plat_pm.h |   22 +++
 4 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 drivers/soc/fsl/plat_pm.c
 create mode 100644 include/soc/fsl/plat_pm.h

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index 7a9fb9b..6517412 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -16,3 +16,17 @@ config FSL_GUTS
  Initially only reading SVR and registering soc device are supported.
  Other guts accesses, such as reading RCW, should eventually be moved
  into this driver as well.
+
+config FSL_PLAT_PM
+   bool "Freescale platform PM framework"
+   help
+ This driver is to provide a independent framework for PM service
+ provider and consumer to configure system level wake up feature. For
+ example, RCPM driver could register a callback function on this
+ platform first, and Flex timer driver who want to enable timer wake
+ up feature, will call generic API provided by this platform driver,
+ and then it will trigger RCPM driver to do it. The benefit is to
+ isolate the user and service, such as  flex timer driver will not
+ have to know the implement details of wakeup function it require.
+ Besides, it is also easy for service side to upgrade its logic when
+ design changed and remain user side unchanged.
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 44b3beb..8f9db23 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
 obj-$(CONFIG_FSL_GUTS) += guts.o
+obj-$(CONFIG_FSL_PLAT_PM)  += plat_pm.o
diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c
new file mode 100644
index 000..19ea14e
--- /dev/null
+++ b/drivers/soc/fsl/plat_pm.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// plat_pm.c - Freescale platform PM framework
+//
+// Copyright 2018 NXP
+//
+// Author: Ran Wang ,
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+struct plat_pm_t {
+   struct list_head node;
+   fsl_plat_pm_handle handle;
+   void *handle_priv;
+   spinlock_t  lock;
+};
+
+static struct plat_pm_t plat_pm;
+
+// register_fsl_platform_wakeup_source - Register callback function to plat_pm
+// @handle: Pointer to handle PM feature requirement
+// @handle_priv: Handler specific data struct
+//
+// Return 0 on success other negative errno
+int register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle,
+   void *handle_priv)
+{
+   struct plat_pm_t *p;
+   unsigned long   flags;
+
+   if (!handle) {
+   pr_err("FSL plat_pm: Handler invalid, reject\n");
+   return -EINVAL;
+   }
+
+   p = kmalloc(sizeof(*p), GFP_KERNEL);
+   if (!p)
+   return -ENOMEM;
+
+   p->handle = handle;
+   p->handle_priv = handle_priv;
+
+   spin_lock_irqsave(_pm.lock, flags);
+   list_add_tail(>node, _pm.node);
+   spin_unlock_irqrestore(_pm.lock, flags);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source);
+
+// Deregister_fsl_platform_wakeup_source - deregister callback function
+// @handle_priv: Handler specific data struct
+//
+// Return 0 on success other negative errno
+int deregister_fsl_platform_wakeup_source(void *handle_priv)
+{
+   struct plat_pm_t *p, *tmp;
+   unsigned long   flags;
+
+   spin_lock_irqsave(_pm.lock, flags);
+   list_for_each_entry_safe(p, tmp, _pm.node, node) {
+   if (p->handle_priv == handle_priv) {
+   list_del(>node);
+   kfree(p);
+   }
+   }
+   spin_unlock_irqrestore(_pm.lock, flags);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(deregister_fsl_platform_wakeup_source);
+
+// fsl_platform_wakeup_config - Configure wakeup source by calling handlers
+// @dev: pointer to user's device struct
+// @flag: to tell enable or disable wakeup source
+//
+//