[PATCH v7] soc: fsl: enable acpi support in RCPM driver

2021-04-07 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v7:
 - Update comment for checking RCPM node which refferred to

Change in v6:
 - Remove copyright udpate to rebase on latest mainline

Change in v5:
 - Fix panic when dev->of_node is null

Change in v4:
 - Make commit subject more accurate
 - Remove unrelated new blank line

Change in v3:
 - Add #ifdef CONFIG_ACPI for acpi_device_id
 - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids

Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index 4ace28cab314..90d3f4060b0c 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -78,10 +79,20 @@ static int rcpm_pm_prepare(struct device *dev)
"fsl,rcpm-wakeup", value,
rcpm->wakeup_cells + 1);
 
-   /*  Wakeup source should refer to current rcpm device */
-   if (ret || (np->phandle != value[0]))
+   if (ret)
continue;
 
+   /*
+* For DT mode, would handle devices with "fsl,rcpm-wakeup"
+* pointing to the current RCPM node.
+*
+* For ACPI mode, currently we assume there is only one
+* RCPM controller existing.
+*/
+   if (is_of_node(dev->fwnode))
+   if (np->phandle != value[0])
+   continue;
+
/* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines the
 * number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
 * of wakeup source IP contains an integer array: 

RE: [PATCH v6] soc: fsl: enable acpi support in RCPM driver

2021-04-06 Thread Ran Wang
Hi Leo,

On Wednesday, April 7, 2021 5:45 AM, Li Yang wrote:
> 
> On Fri, Mar 12, 2021 at 2:56 AM Ran Wang  wrote:
> >
> > From: Peng Ma 
> >
> > This patch enables ACPI support in RCPM driver.
> >
> > Signed-off-by: Peng Ma 
> > Signed-off-by: Ran Wang 
> > ---
> > Change in v6:
> >  - Remove copyright udpate to rebase on latest mainline
> >
> > Change in v5:
> >  - Fix panic when dev->of_node is null
> >
> > Change in v4:
> >  - Make commit subject more accurate
> >  - Remove unrelated new blank line
> >
> > Change in v3:
> >  - Add #ifdef CONFIG_ACPI for acpi_device_id
> >  - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids
> >
> > Change in v2:
> >  - Update acpi_device_id to fix conflict with other driver
> >
> >  drivers/soc/fsl/rcpm.c | 18 --
> >  1 file changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> > 4ace28cab314..7aa997b932d1 100644
> > --- a/drivers/soc/fsl/rcpm.c
> > +++ b/drivers/soc/fsl/rcpm.c
> > @@ -13,6 +13,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  #define RCPM_WAKEUP_CELL_MAX_SIZE  7
> >
> > @@ -78,10 +79,14 @@ static int rcpm_pm_prepare(struct device *dev)
> > "fsl,rcpm-wakeup", value,
> > rcpm->wakeup_cells + 1);
> >
> > -   /*  Wakeup source should refer to current rcpm device */
> > -   if (ret || (np->phandle != value[0]))
> > +   if (ret)
> > continue;
> >
> > +   if (is_of_node(dev->fwnode))
> > +   /*  Should refer to current rcpm device */
> > +   if (np->phandle != value[0])
> > +   continue;
> 
> It looks like that we assume that in the ACPI scenario there will only be one 
> RCPM controller and all devices are controlled by this single
> PM controller.  This probably is true for all existing SoCs with a RCPM.  But 
> since the driver tried to support multiple RCPMs, maybe we
> should continue to support multiple RCPM controllers or at least mention that 
> in the comment.

How about adding some comment as below:

/* For ACPI mode, currently we assume there is only one RCPM controller 
existing */

Regards,
Ran

> 
> > +
> > /* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines 
> > the
> >  * number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
> >  * of wakeup source IP contains an integer array:
> >  > rcpm_of_match[] = {  };  MODULE_DEVICE_TABLE(of, rcpm_of_match);
> >
> > +#ifdef CONFIG_ACPI
> > +static const struct acpi_device_id rcpm_acpi_ids[] = {
> > +   {"NXP0015",},
> > +   { }
> > +};
> > +MODULE_DEVICE_TABLE(acpi, rcpm_acpi_ids); #endif
> > +
> >  static struct platform_driver rcpm_driver = {
> > .driver = {
> > .name = "rcpm",
> > .of_match_table = rcpm_of_match,
> > +   .acpi_match_table = ACPI_PTR(rcpm_acpi_ids),
> > .pm = _pm_ops,
> > },
> > .probe = rcpm_probe,
> > --
> > 2.25.1
> >


RE: [PATCH v4] gpio: mpc8xxx: Add ACPI support

2021-04-05 Thread Ran Wang
Hello,

On Monday, March 22, 2021 11:39 AM, Ran Wang wrote:
> 
> Current implementation only supports DT, now add ACPI support.
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v4:
>  - Update error print for gpiochip_add_data() to fix wrong info. in ACPI case.
>  - Update error print for devm_request_irq() to fix panic in ACPI case.
>  - Add include property.h and mod_devicetable.h.
>  - Correct error handling for mpc8xxx_gc->regs.
>  - Replace "!(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))" with 
> "is_acpi_node(fwnode)"

Could this version be accepted, or any comment/suggestion?

Thanks & Regards,
Ran

 
> Change in v3:
>  - Recover ls1028a and ls1088a compatilbe checking logic
> 
> Change in v2:
>  - Initialize devtype with NULL to fix compile warning.
>  - Replace of_device_get_match_data() and acpi_match_device with 
> device_get_match_data().
>  - Replace acpi_match_device() with simpler checking logic per Andy's 
> suggestion.
> 
>  drivers/gpio/gpio-mpc8xxx.c | 47 ++---
>  1 file changed, 33 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c index 
> 6dfca83bcd90..4b9157a69fca 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -9,6 +9,7 @@
>   * kind, whether express or implied.
>   */
> 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -18,6 +19,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -303,8 +306,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
>   struct device_node *np = pdev->dev.of_node;
>   struct mpc8xxx_gpio_chip *mpc8xxx_gc;
>   struct gpio_chip*gc;
> - const struct mpc8xxx_gpio_devtype *devtype =
> - of_device_get_match_data(>dev);
> + const struct mpc8xxx_gpio_devtype *devtype = NULL;
> + struct fwnode_handle *fwnode;
>   int ret;
> 
>   mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL); 
> @@ -315,14 +318,14 @@ static int
> mpc8xxx_probe(struct platform_device *pdev)
> 
>   raw_spin_lock_init(_gc->lock);
> 
> - mpc8xxx_gc->regs = of_iomap(np, 0);
> - if (!mpc8xxx_gc->regs)
> - return -ENOMEM;
> + mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(mpc8xxx_gc->regs))
> + return PTR_ERR(mpc8xxx_gc->regs);
> 
>   gc = _gc->gc;
>   gc->parent = >dev;
> 
> - if (of_property_read_bool(np, "little-endian")) {
> + if (device_property_read_bool(>dev, "little-endian")) {
>   ret = bgpio_init(gc, >dev, 4,
>mpc8xxx_gc->regs + GPIO_DAT,
>NULL, NULL,
> @@ -345,6 +348,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
> 
>   mpc8xxx_gc->direction_output = gc->direction_output;
> 
> + devtype = device_get_match_data(>dev);
>   if (!devtype)
>   devtype = _gpio_devtype_default;
> 
> @@ -369,24 +373,29 @@ static int mpc8xxx_probe(struct platform_device *pdev)
>* associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
>* the port value to the GPIO Data Register.
>*/
> + fwnode = dev_fwnode(>dev);
>   if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
>   of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
> - of_device_is_compatible(np, "fsl,ls1088a-gpio"))
> + of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
> + is_acpi_node(fwnode))
>   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
> 
>   ret = gpiochip_add_data(gc, mpc8xxx_gc);
>   if (ret) {
> - pr_err("%pOF: GPIO chip registration failed with status %d\n",
> -np, ret);
> + dev_err(>dev,
> + "GPIO chip registration failed with status %d\n", ret);
>   goto err;
>   }
> 
> - mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
> + mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
>   if (!mpc8xxx_gc->irqn)
>   return 0;
> 
> - mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
> - _gpio_irq_ops, mpc8xxx_gc);
> + mpc8xxx_gc->irq = irq_domain_create_linear(fwnode,
> +MPC8XXX_GPIO_PINS,
> +_gpio_irq_ops

[PATCH v4] gpio: mpc8xxx: Add ACPI support

2021-03-21 Thread Ran Wang
Current implementation only supports DT, now add ACPI support.

Signed-off-by: Ran Wang 
---
Change in v4:
 - Update error print for gpiochip_add_data() to fix wrong info. in ACPI case.
 - Update error print for devm_request_irq() to fix panic in ACPI case.
 - Add include property.h and mod_devicetable.h.
 - Correct error handling for mpc8xxx_gc->regs.
 - Replace "!(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))" with 
"is_acpi_node(fwnode)"

Change in v3:
 - Recover ls1028a and ls1088a compatilbe checking logic

Change in v2:
 - Initialize devtype with NULL to fix compile warning.
 - Replace of_device_get_match_data() and acpi_match_device with 
device_get_match_data().
 - Replace acpi_match_device() with simpler checking logic per Andy's 
suggestion.

 drivers/gpio/gpio-mpc8xxx.c | 47 ++---
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 6dfca83bcd90..4b9157a69fca 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
  * kind, whether express or implied.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -18,6 +19,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -303,8 +306,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct gpio_chip*gc;
-   const struct mpc8xxx_gpio_devtype *devtype =
-   of_device_get_match_data(>dev);
+   const struct mpc8xxx_gpio_devtype *devtype = NULL;
+   struct fwnode_handle *fwnode;
int ret;
 
mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
@@ -315,14 +318,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
raw_spin_lock_init(_gc->lock);
 
-   mpc8xxx_gc->regs = of_iomap(np, 0);
-   if (!mpc8xxx_gc->regs)
-   return -ENOMEM;
+   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
+   if (IS_ERR(mpc8xxx_gc->regs))
+   return PTR_ERR(mpc8xxx_gc->regs);
 
gc = _gc->gc;
gc->parent = >dev;
 
-   if (of_property_read_bool(np, "little-endian")) {
+   if (device_property_read_bool(>dev, "little-endian")) {
ret = bgpio_init(gc, >dev, 4,
 mpc8xxx_gc->regs + GPIO_DAT,
 NULL, NULL,
@@ -345,6 +348,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
mpc8xxx_gc->direction_output = gc->direction_output;
 
+   devtype = device_get_match_data(>dev);
if (!devtype)
devtype = _gpio_devtype_default;
 
@@ -369,24 +373,29 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 * the port value to the GPIO Data Register.
 */
+   fwnode = dev_fwnode(>dev);
if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
+   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
+   is_acpi_node(fwnode))
gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
 
ret = gpiochip_add_data(gc, mpc8xxx_gc);
if (ret) {
-   pr_err("%pOF: GPIO chip registration failed with status %d\n",
-  np, ret);
+   dev_err(>dev,
+   "GPIO chip registration failed with status %d\n", ret);
goto err;
}
 
-   mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
+   mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
if (!mpc8xxx_gc->irqn)
return 0;
 
-   mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
-   _gpio_irq_ops, mpc8xxx_gc);
+   mpc8xxx_gc->irq = irq_domain_create_linear(fwnode,
+  MPC8XXX_GPIO_PINS,
+  _gpio_irq_ops,
+  mpc8xxx_gc);
+
if (!mpc8xxx_gc->irq)
return 0;
 
@@ -399,8 +408,9 @@ static int mpc8xxx_probe(struct platform_device *pdev)
   IRQF_SHARED, "gpio-cascade",
   mpc8xxx_gc);
if (ret) {
-   dev_err(>dev, "%s: failed to devm_request_irq(%d), ret = 
%d\n",
-   np->full_name, mpc8xxx_gc->irqn, ret);
+   dev_err(>dev,
+   "failed to devm_request_irq(%d), ret = %d\n"

RE: [PATCH v3] gpio: mpc8xxx: Add ACPI support

2021-03-21 Thread Ran Wang
Hi Andy,

On Friday, March 19, 2021 6:32 PM, Andy Shevchenko wrote:
> 
> On Fri, Mar 19, 2021 at 10:10 AM Ran Wang  wrote:
> >
> > Current implementation only supports DT, now add ACPI support.
> 
> Thanks for an update, my comments below.
> 
> ...
> 
> > +#include 
> 
> Missed
> property.h
> mod_devicetable.h.

Got it.
 
> ...
> 
> > -   mpc8xxx_gc->regs = of_iomap(np, 0);
> > +   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
> 
> > if (!mpc8xxx_gc->regs)
> 
> This is wrong now.

Yes, will correct this in next version

> > return -ENOMEM;
> 
> This too.

Got it.
 
> ...
> 
> > +   fwnode = dev_fwnode(>dev);
> > if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
> > of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
> > -   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
> > +   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
> 
> > +   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))
> 
> Since you left acpi.h inclusion, you may switch this to
> 
> is_acpi_node(fwnode)
> 
> or drop fwnode and use
> 
> has_acpi_companion(>dev)

OK, will use is_acpi_node(fwnode) instead (since fwnode is referred in 
following irq_domain_create_linear()

Thanks for your patient educate :)

Regards,
Ran



[PATCH v3] gpio: mpc8xxx: Add ACPI support

2021-03-19 Thread Ran Wang
Current implementation only supports DT, now add ACPI support.

Signed-off-by: Ran Wang 
---
Change in v3:
 - Recover ls1028a and ls1088a compatilbe checking logic

Change in v2:
 - Initialize devtype with NULL to fix compile warning.
 - Replace of_device_get_match_data() and acpi_match_device with 
device_get_match_data().
 - Replace acpi_match_device() with simpler checking logic per Andy's 
suggestion.

 drivers/gpio/gpio-mpc8xxx.c | 32 
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 6dfca83bcd90..25ac7db847af 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
  * kind, whether express or implied.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -303,8 +304,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct gpio_chip*gc;
-   const struct mpc8xxx_gpio_devtype *devtype =
-   of_device_get_match_data(>dev);
+   const struct mpc8xxx_gpio_devtype *devtype = NULL;
+   struct fwnode_handle *fwnode;
int ret;
 
mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
@@ -315,14 +316,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
raw_spin_lock_init(_gc->lock);
 
-   mpc8xxx_gc->regs = of_iomap(np, 0);
+   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
if (!mpc8xxx_gc->regs)
return -ENOMEM;
 
gc = _gc->gc;
gc->parent = >dev;
 
-   if (of_property_read_bool(np, "little-endian")) {
+   if (device_property_read_bool(>dev, "little-endian")) {
ret = bgpio_init(gc, >dev, 4,
 mpc8xxx_gc->regs + GPIO_DAT,
 NULL, NULL,
@@ -345,6 +346,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
mpc8xxx_gc->direction_output = gc->direction_output;
 
+   devtype = device_get_match_data(>dev);
if (!devtype)
devtype = _gpio_devtype_default;
 
@@ -369,9 +371,11 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 * the port value to the GPIO Data Register.
 */
+   fwnode = dev_fwnode(>dev);
if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
+   of_device_is_compatible(np, "fsl,ls1088a-gpio") ||
+   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))
gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
 
ret = gpiochip_add_data(gc, mpc8xxx_gc);
@@ -381,12 +385,15 @@ static int mpc8xxx_probe(struct platform_device *pdev)
goto err;
}
 
-   mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
+   mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
if (!mpc8xxx_gc->irqn)
return 0;
 
-   mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
-   _gpio_irq_ops, mpc8xxx_gc);
+   mpc8xxx_gc->irq = irq_domain_create_linear(fwnode,
+  MPC8XXX_GPIO_PINS,
+  _gpio_irq_ops,
+  mpc8xxx_gc);
+
if (!mpc8xxx_gc->irq)
return 0;
 
@@ -425,12 +432,21 @@ static int mpc8xxx_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id gpio_acpi_ids[] = {
+   {"NXP0031",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
+#endif
+
 static struct platform_driver mpc8xxx_plat_driver = {
.probe  = mpc8xxx_probe,
.remove = mpc8xxx_remove,
.driver = {
.name = "gpio-mpc8xxx",
.of_match_table = mpc8xxx_gpio_ids,
+   .acpi_match_table = ACPI_PTR(gpio_acpi_ids),
},
 };
 
-- 
2.25.1



RE: [PATCH v2] gpio: mpc8xxx: Add ACPI support

2021-03-19 Thread Ran Wang
Hi Michael,

On Friday, March 19, 2021 3:52 PM, Michael Walle wrote:
> 
> Am 2021-03-19 03:53, schrieb Ran Wang:
> > Current implementation only supports DT, now add ACPI support.
> >
> > Note that compared to device of 'fsl,qoriq-gpio', LS1028A and
> > LS1088A's GPIO have no extra programming, so simplify related checking.
> >
> > Signed-off-by: Ran Wang 
> > ---
> > Change in v2:
> >  - Initialize devtype with NULL to fix compile warning.
> >  - Replace of_device_get_match_data() and acpi_match_device with
> > device_get_match_data().
> >  - Replace acpi_match_device() with simpler checking logic per Andy's
> > suggestion.
> >
> >  drivers/gpio/gpio-mpc8xxx.c | 34 +++---
> >  1 file changed, 23 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> > index 6dfca83bcd90..646225fa3e73 100644
> > --- a/drivers/gpio/gpio-mpc8xxx.c
> > +++ b/drivers/gpio/gpio-mpc8xxx.c
> > @@ -9,6 +9,7 @@
> >   * kind, whether express or implied.
> >   */
> >
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -292,8 +293,6 @@ static const struct of_device_id
> > mpc8xxx_gpio_ids[] = {
> > { .compatible = "fsl,mpc5121-gpio", .data = _gpio_devtype, },
> > { .compatible = "fsl,mpc5125-gpio", .data = _gpio_devtype, },
> > { .compatible = "fsl,pq3-gpio", },
> > -   { .compatible = "fsl,ls1028a-gpio", },
> > -   { .compatible = "fsl,ls1088a-gpio", },
> > { .compatible = "fsl,qoriq-gpio",   },
> > {}
> >  };
> > @@ -303,8 +302,8 @@ static int mpc8xxx_probe(struct platform_device
> > *pdev)
> > struct device_node *np = pdev->dev.of_node;
> > struct mpc8xxx_gpio_chip *mpc8xxx_gc;
> > struct gpio_chip*gc;
> > -   const struct mpc8xxx_gpio_devtype *devtype =
> > -   of_device_get_match_data(>dev);
> > +   const struct mpc8xxx_gpio_devtype *devtype = NULL;
> > +   struct fwnode_handle *fwnode;
> > int ret;
> >
> > mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc),
> > GFP_KERNEL); @@ -315,14 +314,14 @@ static int mpc8xxx_probe(struct
> > platform_device
> > *pdev)
> >
> > raw_spin_lock_init(_gc->lock);
> >
> > -   mpc8xxx_gc->regs = of_iomap(np, 0);
> > +   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
> > if (!mpc8xxx_gc->regs)
> > return -ENOMEM;
> >
> > gc = _gc->gc;
> > gc->parent = >dev;
> >
> > -   if (of_property_read_bool(np, "little-endian")) {
> > +   if (device_property_read_bool(>dev, "little-endian")) {
> > ret = bgpio_init(gc, >dev, 4,
> >  mpc8xxx_gc->regs + GPIO_DAT,
> >  NULL, NULL,
> > @@ -345,6 +344,7 @@ static int mpc8xxx_probe(struct platform_device
> > *pdev)
> >
> > mpc8xxx_gc->direction_output = gc->direction_output;
> >
> > +   devtype = device_get_match_data(>dev);
> > if (!devtype)
> > devtype = _gpio_devtype_default;
> >
> > @@ -369,9 +369,9 @@ static int mpc8xxx_probe(struct platform_device
> > *pdev)
> >  * associated input enable must be set (GPIOxGPIE[IEn]=1) to
> > propagate
> >  * the port value to the GPIO Data Register.
> >  */
> > +   fwnode = dev_fwnode(>dev);
> > if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
> > -   of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
> > -   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
> 
> Again, please keep this. The DT bindings don't mention "fsl,qoriq-gpio"
> is required. Alternatively, change the binding (ideally convert it to
> YAML) and get an ack by Rob.

OK, I will keep this in next version

Regards,
Ran

> -michael


[PATCH v2] gpio: mpc8xxx: Add ACPI support

2021-03-18 Thread Ran Wang
Current implementation only supports DT, now add ACPI support.

Note that compared to device of 'fsl,qoriq-gpio', LS1028A and
LS1088A's GPIO have no extra programming, so simplify related checking.

Signed-off-by: Ran Wang 
---
Change in v2:
 - Initialize devtype with NULL to fix compile warning.
 - Replace of_device_get_match_data() and acpi_match_device with 
device_get_match_data().
 - Replace acpi_match_device() with simpler checking logic per Andy's 
suggestion.

 drivers/gpio/gpio-mpc8xxx.c | 34 +++---
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 6dfca83bcd90..646225fa3e73 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
  * kind, whether express or implied.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -292,8 +293,6 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
{ .compatible = "fsl,mpc5121-gpio", .data = _gpio_devtype, },
{ .compatible = "fsl,mpc5125-gpio", .data = _gpio_devtype, },
{ .compatible = "fsl,pq3-gpio", },
-   { .compatible = "fsl,ls1028a-gpio", },
-   { .compatible = "fsl,ls1088a-gpio", },
{ .compatible = "fsl,qoriq-gpio",   },
{}
 };
@@ -303,8 +302,8 @@ static int mpc8xxx_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct gpio_chip*gc;
-   const struct mpc8xxx_gpio_devtype *devtype =
-   of_device_get_match_data(>dev);
+   const struct mpc8xxx_gpio_devtype *devtype = NULL;
+   struct fwnode_handle *fwnode;
int ret;
 
mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
@@ -315,14 +314,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
raw_spin_lock_init(_gc->lock);
 
-   mpc8xxx_gc->regs = of_iomap(np, 0);
+   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
if (!mpc8xxx_gc->regs)
return -ENOMEM;
 
gc = _gc->gc;
gc->parent = >dev;
 
-   if (of_property_read_bool(np, "little-endian")) {
+   if (device_property_read_bool(>dev, "little-endian")) {
ret = bgpio_init(gc, >dev, 4,
 mpc8xxx_gc->regs + GPIO_DAT,
 NULL, NULL,
@@ -345,6 +344,7 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
mpc8xxx_gc->direction_output = gc->direction_output;
 
+   devtype = device_get_match_data(>dev);
if (!devtype)
devtype = _gpio_devtype_default;
 
@@ -369,9 +369,9 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 * the port value to the GPIO Data Register.
 */
+   fwnode = dev_fwnode(>dev);
if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
+   !(IS_ERR_OR_NULL(fwnode) || is_of_node(fwnode)))
gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
 
ret = gpiochip_add_data(gc, mpc8xxx_gc);
@@ -381,12 +381,15 @@ static int mpc8xxx_probe(struct platform_device *pdev)
goto err;
}
 
-   mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
+   mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
if (!mpc8xxx_gc->irqn)
return 0;
 
-   mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
-   _gpio_irq_ops, mpc8xxx_gc);
+   mpc8xxx_gc->irq = irq_domain_create_linear(fwnode,
+  MPC8XXX_GPIO_PINS,
+  _gpio_irq_ops,
+  mpc8xxx_gc);
+
if (!mpc8xxx_gc->irq)
return 0;
 
@@ -425,12 +428,21 @@ static int mpc8xxx_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id gpio_acpi_ids[] = {
+   {"NXP0031",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
+#endif
+
 static struct platform_driver mpc8xxx_plat_driver = {
.probe  = mpc8xxx_probe,
.remove = mpc8xxx_remove,
.driver = {
.name = "gpio-mpc8xxx",
.of_match_table = mpc8xxx_gpio_ids,
+   .acpi_match_table = ACPI_PTR(gpio_acpi_ids),
},
 };
 
-- 
2.25.1



RE: [PATCH] optee: enable apci support

2021-03-18 Thread Ran Wang
Hi Ard,

On Thursday, March 18, 2021 3:48 PM, Ard Biesheuvel wrote:
> 
> On Thu, 18 Mar 2021 at 08:29, Ran Wang  wrote:
> >
> > Hi Ard,
> >
> >
> > On Wednesday, March 17, 2021 4:29 PM, Ard Biesheuvel wrote:
> > >
> > > On Wed, 17 Mar 2021 at 09:04, Jens Wiklander  
> > > wrote:
> > > >
> > > > On Fri, Mar 12, 2021 at 04:36:53PM +0800, Ran Wang wrote:
> > > > > This patch add ACPI support for optee driver.
> > > > >
> > > > > Signed-off-by: Ran Wang 
> > > > > ---
> > > > >  drivers/tee/optee/core.c | 10 ++
> > > > >  1 file changed, 10 insertions(+)
> > > > >
> > > > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > > > > index cf4718c6d35d..8fb261f4b9db 100644
> > > > > --- a/drivers/tee/optee/core.c
> > > > > +++ b/drivers/tee/optee/core.c
> > > > > @@ -5,6 +5,7 @@
> > > > >
> > > > >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> > > > >
> > > > > +#include 
> > > > >  #include 
> > > > >  #include 
> > > > >  #include 
> > > > > @@ -735,12 +736,21 @@ static const struct of_device_id
> > > > > optee_dt_match[] = {  };  MODULE_DEVICE_TABLE(of,
> > > > > optee_dt_match);
> > > > >
> > > > > +#ifdef CONFIG_ACPI
> > > > > +static const struct acpi_device_id optee_acpi_match[] = {
> > > > > + { "OPTEE01",},
> > >
> > > You cannot just invent ACPI HIDs like that. The 4 character prefix
> > > is a vendor ID that is assigned by the UEFI forum, the 4 following
> > > digits are up to the vendor to assign,
> >
> > Thanks for this info. Could you please show me where I can find the 
> > guide/example for this assign process?
> >
> 
> I think it is better to ask around internally. As far as I know, NXP already 
> owns a ACPI/PNP vendor prefix.

OK

> > > > > + { },
> > > > > +};
> > > > > +MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
> > >
> > > dwc3_acpi_match ?? Does this even build?
> >
> > My bad, I was referring dwc3 code as an example, will correct it.
> >
> > But looks this typo didn’t trigger error in my unit-test.
> >
> 
> Does your build have CONFIG_ACPI enabled?

Yes

> > >
> > > > > +#endif
> > > > > +
> > > > >  static struct platform_driver optee_driver = {
> > > > >   .probe  = optee_probe,
> > > > >   .remove = optee_remove,
> > > > >   .driver = {
> > > > >   .name = "optee",
> > > > >   .of_match_table = optee_dt_match,
> > > > > + .acpi_match_table = ACPI_PTR(optee_acpi_match),
> > > > >   },
> > > > >  };
> > > > >  module_platform_driver(optee_driver);
> > > > > --
> > > > > 2.25.1
> > > > >
> > > >
> > > > This looks simple enough. Ard, is this what you had in mind earlier?
> > > >
> > >
> > > Not really.
> > >
> > > On SynQuacer, we use
> > >
> > > Device (TOS0) {
> > >   Name (_HID, "PRP0001")
> > >   Name (_UID, 0x0)
> > >   Name (_DSD, Package () {
> > > ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> > > Package () {
> > >   Package (2) { "compatible", "linaro,optee-tz" },
> > >   Package (2) { "method", "smc" },
> > > }
> > >   })
> > > }
> > >
> > > which does not require any changes to Linux. So I don't think this patch 
> > > is needed at all tbh.
> >
> > Thanks for this example, but actually I failed to trigger kernel optee
> > probe function by using above code in ACPI table.
> >
> > And I am curious how this 'compatible' properties be picked up by kernel 
> > when try to match driver in ACPI mode?
> >
> 
> On SynQuacer,
> 
> $ cat /sys/devices/platform/PRP0001:00/firmware_node/modalias
> of:Ntos0TClinaro,optee-tz
> 
> > My understanding is to get it done by feeding .acpi_match_table with 
> > something, right?
> >
> 
> The PRP0001 HID is handled in a special way. Please grep the Linux source if 
> you are curious to understand how this is implemented.

Yes, my failure is due to without PRP0001, and I have found the Doc in kernel 
code explaining that. Now it works fine on my side :)
Thanks for the educate!

Regards,
Ran


RE: [PATCH] optee: enable apci support

2021-03-18 Thread Ran Wang
Hi Ard,


On Wednesday, March 17, 2021 4:29 PM, Ard Biesheuvel wrote:
> 
> On Wed, 17 Mar 2021 at 09:04, Jens Wiklander  
> wrote:
> >
> > On Fri, Mar 12, 2021 at 04:36:53PM +0800, Ran Wang wrote:
> > > This patch add ACPI support for optee driver.
> > >
> > > Signed-off-by: Ran Wang 
> > > ---
> > >  drivers/tee/optee/core.c | 10 ++
> > >  1 file changed, 10 insertions(+)
> > >
> > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > > index cf4718c6d35d..8fb261f4b9db 100644
> > > --- a/drivers/tee/optee/core.c
> > > +++ b/drivers/tee/optee/core.c
> > > @@ -5,6 +5,7 @@
> > >
> > >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> > >
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -735,12 +736,21 @@ static const struct of_device_id
> > > optee_dt_match[] = {  };  MODULE_DEVICE_TABLE(of, optee_dt_match);
> > >
> > > +#ifdef CONFIG_ACPI
> > > +static const struct acpi_device_id optee_acpi_match[] = {
> > > + { "OPTEE01",},
> 
> You cannot just invent ACPI HIDs like that. The 4 character prefix is a 
> vendor ID that is assigned by the UEFI forum, the 4 following digits are
> up to the vendor to assign,

Thanks for this info. Could you please show me where I can find the 
guide/example for this assign process?

> > > + { },
> > > +};
> > > +MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
> 
> dwc3_acpi_match ?? Does this even build?

My bad, I was referring dwc3 code as an example, will correct it.

But looks this typo didn’t trigger error in my unit-test.
 
> 
> > > +#endif
> > > +
> > >  static struct platform_driver optee_driver = {
> > >   .probe  = optee_probe,
> > >   .remove = optee_remove,
> > >   .driver = {
> > >   .name = "optee",
> > >   .of_match_table = optee_dt_match,
> > > + .acpi_match_table = ACPI_PTR(optee_acpi_match),
> > >   },
> > >  };
> > >  module_platform_driver(optee_driver);
> > > --
> > > 2.25.1
> > >
> >
> > This looks simple enough. Ard, is this what you had in mind earlier?
> >
> 
> Not really.
> 
> On SynQuacer, we use
> 
> Device (TOS0) {
>   Name (_HID, "PRP0001")
>   Name (_UID, 0x0)
>   Name (_DSD, Package () {
> ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> Package () {
>   Package (2) { "compatible", "linaro,optee-tz" },
>   Package (2) { "method", "smc" },
> }
>   })
> }
> 
> which does not require any changes to Linux. So I don't think this patch is 
> needed at all tbh.

Thanks for this example, but actually I failed to trigger kernel optee probe 
function by using
above code in ACPI table.

And I am curious how this 'compatible' properties be picked up by kernel when 
try to match driver in ACPI mode?

My understanding is to get it done by feeding .acpi_match_table with something, 
right?

Regards,
Ran



RE: [PATCH] gpio: mpc8xxx: Add ACPI support

2021-03-15 Thread Ran Wang
Hi Michael, Bartosz,

On Sunday, March 14, 2021 8:11 AM, Michael Walle wrote:
> 
> Am 2021-03-12 12:07, schrieb Bartosz Golaszewski:
> > On Fri, Mar 12, 2021 at 7:51 AM Ran Wang  wrote:
> >>
> >> Current implementation only supports DT, now add ACPI support.
> >>
> >> Note that compared to device of 'fsl,qoriq-gpio', LS1028A and
> >> LS1088A's GPIO have no extra programming, so simplify related
> >> checking.
> >>
> >> Signed-off-by: Ran Wang 
> >> ---
> >>  drivers/gpio/gpio-mpc8xxx.c | 50
> >> +++--
> >>  1 file changed, 37 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/drivers/gpio/gpio-mpc8xxx.c
> >> b/drivers/gpio/gpio-mpc8xxx.c index 6dfca83bcd90..de5b7e17cde3 100644
> >> --- a/drivers/gpio/gpio-mpc8xxx.c
> >> +++ b/drivers/gpio/gpio-mpc8xxx.c
> >> @@ -9,6 +9,7 @@
> >>   * kind, whether express or implied.
> >>   */
> >>
> >> +#include 
> >>  #include 
> >>  #include 
> >>  #include 
> >> @@ -292,8 +293,6 @@ static const struct of_device_id
> >> mpc8xxx_gpio_ids[] = {
> >> { .compatible = "fsl,mpc5121-gpio", .data =
> >> _gpio_devtype, },
> >> { .compatible = "fsl,mpc5125-gpio", .data =
> >> _gpio_devtype, },
> >> { .compatible = "fsl,pq3-gpio", },
> >> -   { .compatible = "fsl,ls1028a-gpio", },
> >> -   { .compatible = "fsl,ls1088a-gpio", },
> >
> > Why are you removing support for those?
> 
> I guess because it doesn't matter because usually
>   compatible = "fsl,ls1028a-gpio", "fsl,qoriq-gpio"; is used.

Yes,

>But I just had a look at the dt binding and it doesn't mandate it. So please 
>keep it.

For now, strictly speaking, QorIQ pressors belong to Power Architecture
and Layerscape processor (LS1012A, LS1021A, LS1043A, LS1046A, LS1088A,
LS2088A, LX2160A, etc) belong to Arm Architecture

Although they are integrated the same GPIO controller IP with
minor difference (endian perspective), it would be find to use
SoC specific compatible + "qoriq-gpio" to make it work for all
Layerscape platforms (with "little-endian" accordingly).

But for mpc8xxx_gpio_ids, I think it would not be necessary
to list all LS/LX compatible strings. what do you say?

Regards,
Ran

> -michael
> 
> >
> > Bart
> >


RE: [PATCH] gpio: mpc8xxx: Add ACPI support

2021-03-15 Thread Ran Wang
Hi Andy,

On Sunday, March 14, 2021 9:52 PM, Andy Shevchenko wrote:
> 
> On Fri, Mar 12, 2021 at 8:53 AM Ran Wang  wrote:
> 
> First of all, please add me to the Cc list for the next version of the patch.
> 
> > Current implementation only supports DT, now add ACPI support.
> >
> > Note that compared to device of 'fsl,qoriq-gpio', LS1028A and
> 
> to devices
> 
> > LS1088A's GPIO have no extra programming, so simplify related checking.
> 
> ...
> 
> > +#include 
> 
> Nope, you rather need property.h and mod_devicetable.h.

If I replace acpi.h, will encounter below error (even have added property.h 
mod_devicetable.h):

CC  drivers/gpio/gpio-mpc8xxx.o
drivers/gpio/gpio-mpc8xxx.c:439:1: warning: data definition has no type or 
storage class
  439 | MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
  | ^~~
drivers/gpio/gpio-mpc8xxx.c:439:1: error: type defaults to ‘int’ in declaration 
of ‘MODULE_DEVICE_TABLE’ [-Werror=implicit-int]
drivers/gpio/gpio-mpc8xxx.c:439:1: warning: parameter names (without types) in 
function declaration
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:271: drivers/gpio/gpio-mpc8xxx.o] Error 1
make[1]: *** [scripts/Makefile.build:514: drivers/gpio] Error 2
make: *** [Makefile:1849: drivers] Error 2
make: *** Waiting for unfinished jobs

> ...
> 
> > +   if (pdev->dev.of_node) {
> > +   devtype = of_device_get_match_data(>dev);
> > +   } else {
> > +   acpi_id = 
> > acpi_match_device(pdev->dev.driver->acpi_match_table,
> > +   >dev);
> > +   if (acpi_id)
> > +   devtype = (struct mpc8xxx_gpio_devtype *) 
> > acpi_id->driver_data;
> > +   }
> 
> No, please use device_get_match_data() instead of the entire conditional 
> block.

OK

> 
> > +   if (pdev->dev.of_node) {
> > +   if (of_device_is_compatible(np, "fsl,qoriq-gpio"))
> > +   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 
> > 0x);
> > +   } else {
> > +   if (acpi_match_device(pdev->dev.driver->acpi_match_table,
> > +   >dev))
> > +   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 
> > 0x);
> > +   }
> 
> Yeah, no need to call acpi_match_device() here.
> Instead use stuff from OF, like
> 
> if (of_device_is_compatible() || !(IS_ERR_OR_NULL(fwnode) ||
> is_of_node(fwnode)))
> (check the logic)

Got it!

> ...
> 
> > +#ifdef CONFIG_ACPI
> 
> No ugly ifdeffery, please.

Remove it will cause same compile error above.

> > +static const struct acpi_device_id gpio_acpi_ids[] = {
> > +   {"NXP0031",},
> > +   { }
> > +};
> > +MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids); #endif
> > +
> >  static struct platform_driver mpc8xxx_plat_driver = {
> > .probe  = mpc8xxx_probe,
> > .remove = mpc8xxx_remove,m
> > .driver = {
> > .name = "gpio-mpc8xxx",
> > .of_match_table = mpc8xxx_gpio_ids,
> 
> > +   .acpi_match_table = ACPI_PTR(gpio_acpi_ids),
> 
> Drop ACPI_PTR().

Will encounter below error if !CONFIG_ACPI:

CC  drivers/gpio/gpio-mpc8xxx.o
drivers/gpio/gpio-mpc8xxx.c:449:23: error: ‘gpio_acpi_ids’ undeclared here (not 
in a function)
  449 |   .acpi_match_table = gpio_acpi_ids,
  |   ^
make[2]: *** [scripts/Makefile.build:271: drivers/gpio/gpio-mpc8xxx.o] Error 1
make[1]: *** [scripts/Makefile.build:514: drivers/gpio] Error 2
make[1]: *** Waiting for unfinished jobs
  CC  net/core/page_pool.o
make: *** [Makefile:1849: drivers] Error 2
make: *** Waiting for unfinished jobs

Thanks & Regards,
Ran




[PATCH v6] soc: fsl: enable acpi support in RCPM driver

2021-03-12 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v6:
 - Remove copyright udpate to rebase on latest mainline

Change in v5:
 - Fix panic when dev->of_node is null

Change in v4:
 - Make commit subject more accurate
 - Remove unrelated new blank line

Change in v3:
 - Add #ifdef CONFIG_ACPI for acpi_device_id
 - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids

Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index 4ace28cab314..7aa997b932d1 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -78,10 +79,14 @@ static int rcpm_pm_prepare(struct device *dev)
"fsl,rcpm-wakeup", value,
rcpm->wakeup_cells + 1);
 
-   /*  Wakeup source should refer to current rcpm device */
-   if (ret || (np->phandle != value[0]))
+   if (ret)
continue;
 
+   if (is_of_node(dev->fwnode))
+   /*  Should refer to current rcpm device */
+   if (np->phandle != value[0])
+   continue;
+
/* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines the
 * number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
 * of wakeup source IP contains an integer array: 

[PATCH] optee: enable apci support

2021-03-12 Thread Ran Wang
This patch add ACPI support for optee driver.

Signed-off-by: Ran Wang 
---
 drivers/tee/optee/core.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index cf4718c6d35d..8fb261f4b9db 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -5,6 +5,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include 
 #include 
 #include 
 #include 
@@ -735,12 +736,21 @@ static const struct of_device_id optee_dt_match[] = {
 };
 MODULE_DEVICE_TABLE(of, optee_dt_match);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id optee_acpi_match[] = {
+   { "OPTEE01",},
+   { },
+};
+MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
+#endif
+
 static struct platform_driver optee_driver = {
.probe  = optee_probe,
.remove = optee_remove,
.driver = {
.name = "optee",
.of_match_table = optee_dt_match,
+   .acpi_match_table = ACPI_PTR(optee_acpi_match),
},
 };
 module_platform_driver(optee_driver);
-- 
2.25.1



[PATCH] gpio: mpc8xxx: Add ACPI support

2021-03-11 Thread Ran Wang
Current implementation only supports DT, now add ACPI support.

Note that compared to device of 'fsl,qoriq-gpio', LS1028A and
LS1088A's GPIO have no extra programming, so simplify related checking.

Signed-off-by: Ran Wang 
---
 drivers/gpio/gpio-mpc8xxx.c | 50 +++--
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 6dfca83bcd90..de5b7e17cde3 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -9,6 +9,7 @@
  * kind, whether express or implied.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -292,8 +293,6 @@ static const struct of_device_id mpc8xxx_gpio_ids[] = {
{ .compatible = "fsl,mpc5121-gpio", .data = _gpio_devtype, },
{ .compatible = "fsl,mpc5125-gpio", .data = _gpio_devtype, },
{ .compatible = "fsl,pq3-gpio", },
-   { .compatible = "fsl,ls1028a-gpio", },
-   { .compatible = "fsl,ls1088a-gpio", },
{ .compatible = "fsl,qoriq-gpio",   },
{}
 };
@@ -303,10 +302,19 @@ static int mpc8xxx_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
struct gpio_chip*gc;
-   const struct mpc8xxx_gpio_devtype *devtype =
-   of_device_get_match_data(>dev);
+   const struct mpc8xxx_gpio_devtype *devtype;
+   const struct acpi_device_id *acpi_id;
int ret;
 
+   if (pdev->dev.of_node) {
+   devtype = of_device_get_match_data(>dev);
+   } else {
+   acpi_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
+   >dev);
+   if (acpi_id)
+   devtype = (struct mpc8xxx_gpio_devtype *) 
acpi_id->driver_data;
+   }
+
mpc8xxx_gc = devm_kzalloc(>dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
if (!mpc8xxx_gc)
return -ENOMEM;
@@ -315,14 +323,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 
raw_spin_lock_init(_gc->lock);
 
-   mpc8xxx_gc->regs = of_iomap(np, 0);
+   mpc8xxx_gc->regs = devm_platform_ioremap_resource(pdev, 0);
if (!mpc8xxx_gc->regs)
return -ENOMEM;
 
gc = _gc->gc;
gc->parent = >dev;
 
-   if (of_property_read_bool(np, "little-endian")) {
+   if (device_property_read_bool(>dev, "little-endian")) {
ret = bgpio_init(gc, >dev, 4,
 mpc8xxx_gc->regs + GPIO_DAT,
 NULL, NULL,
@@ -369,10 +377,14 @@ static int mpc8xxx_probe(struct platform_device *pdev)
 * associated input enable must be set (GPIOxGPIE[IEn]=1) to propagate
 * the port value to the GPIO Data Register.
 */
-   if (of_device_is_compatible(np, "fsl,qoriq-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1028a-gpio") ||
-   of_device_is_compatible(np, "fsl,ls1088a-gpio"))
-   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
+   if (pdev->dev.of_node) {
+   if (of_device_is_compatible(np, "fsl,qoriq-gpio"))
+   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
+   } else {
+   if (acpi_match_device(pdev->dev.driver->acpi_match_table,
+   >dev))
+   gc->write_reg(mpc8xxx_gc->regs + GPIO_IBE, 0x);
+   }
 
ret = gpiochip_add_data(gc, mpc8xxx_gc);
if (ret) {
@@ -381,12 +393,15 @@ static int mpc8xxx_probe(struct platform_device *pdev)
goto err;
}
 
-   mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
+   mpc8xxx_gc->irqn = platform_get_irq(pdev, 0);
if (!mpc8xxx_gc->irqn)
return 0;
 
-   mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
-   _gpio_irq_ops, mpc8xxx_gc);
+   mpc8xxx_gc->irq = irq_domain_create_linear(dev_fwnode(>dev),
+  MPC8XXX_GPIO_PINS,
+  _gpio_irq_ops,
+  mpc8xxx_gc);
+
if (!mpc8xxx_gc->irq)
return 0;
 
@@ -425,12 +440,21 @@ static int mpc8xxx_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id gpio_acpi_ids[] = {
+   {"NXP0031",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, gpio_acpi_ids);
+#endif
+
 static struct platform_driver mpc8xxx_plat_driver = {
.probe  = mpc8xxx_probe,
.remove = mpc8xxx_remove,
.driver = {
.name = "gpio-mpc8xxx",
.of_match_table = mpc8xxx_gpio_ids,
+   .acpi_match_table = ACPI_PTR(gpio_acpi_ids),
},
 };
 
-- 
2.25.1



RE: [PATCH] [RFC] rt: kernel/sched/core: fix kthread_park() pending too long when CPU un-plugged

2021-01-08 Thread Ran Wang
Hi Sebastian,

On Friday, January 8, 2021 5:05 PM, Sebastian Siewior wrote:
> 
> On 2021-01-08 08:45:14 [+0000], Ran Wang wrote:
> > Hi Sebastian, Peter
> Hi,
> 
> > > I had a similar patch in -RT and dropped it in v5.10-rc7-rt16.
> > > It was added because RT couldn't boot since creating the boot-threads 
> > > didn't work before the ksoftirqd was up. This was fixed by commit
> > >26c7295be0c5e ("kthread: Do not preempt current task if it is
> > > going to call schedule()")
> >
> > I tried applying above commit to linux-5.6.y-rt, it could resolve my 
> > problem on LX2160ARDB, THANKS!
> 
> so in other words all this could have been avoided by using a supported or 
> maintained RT series. The v5.4 series has this patch, v5.6 isn't
> maintained anymore so it is likely that there is more missing.

Thanks for let me know this.

The reason I trying linux-5.6-rt is that I have encountered other more serious 
issues on later RT version (even with v5.10-rc7-rt16), one of them
is CPU hot plug got stuck in irq_work_sync() which called by sugov_stop(), 
failure happen at 1st loop stress test every time.
I will try to collect more information and create another mail thread later.

Thanks & Regards,
Ran

> Sebastian


RE: [PATCH] [RFC] rt: kernel/sched/core: fix kthread_park() pending too long when CPU un-plugged

2021-01-08 Thread Ran Wang
Hi Sebastian, Peter

Thursday, January 7, 2021 11:29 PM, Sebastian Siewior wrote:
> 
> On 2021-01-07 11:45:39 [+0100], Peter Zijlstra wrote:
> > On Thu, Jan 07, 2021 at 05:18:41PM +0800, Ran Wang wrote:
> > > +
> > > + if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
> > > + !strncmp(p->comm, "ksoftirqd/", 10))
> > > + schedule_hrtimeout(,
> > > + HRTIMER_MODE_REL | HRTIMER_MODE_HARD);
> > > + else
> > > + schedule_hrtimeout(, HRTIMER_MODE_REL);
> >
> > This is horrific, why did you not self-censor and spare me the mental
> > anguish of having to formulate a CoC compliant response?
> >
> > It also violates coding style, but given the total lack of any sense,
> > that seems like a minor detail.
> >
> > Why can't we use HRTIMER_MODE_HARD unconditionally?
> 
> I had a similar patch in -RT and dropped it in v5.10-rc7-rt16.
> It was added because RT couldn't boot since creating the boot-threads didn't 
> work before the ksoftirqd was up. This was fixed by commit
>26c7295be0c5e ("kthread: Do not preempt current task if it is going to 
> call schedule()")

I tried applying above commit to linux-5.6.y-rt, it could resolve my problem on 
LX2160ARDB, THANKS!

> and live was good again.
> tglx (also) suggested to add HRTIMER_MODE_HARD unconditionally (it looked at 
> SYSTEM_STATE back then) and I was only worried some
> abuse via userland.

Got it.

Regards,
Ran

> This sleep can be triggered by ptrace/strace() and with brief testing I can 
> trigger the sleep there but I don't get it anywhere near where I
> would notice it with cyclictest.
> 
> Sebastian


RE: [PATCH] [RFC] rt: kernel/sched/core: fix kthread_park() pending too long when CPU un-plugged

2021-01-07 Thread Ran Wang
Hi,

On Thursday, January 7, 2021 5:19 PM, Ran Wang wrote:
> 
> When doing CPU un-plug stress test, function smpboot_park_threads() would get 
> call to park kernel threads (which including ksoftirqd) on
> that CPU core, and function wait_task_inactive() would yield for those queued
> task(s) by calling schedule_hrtimerout() with mode of HRTIMER_MODE_REL.
> 
> stack trace:
> ...
> smpboot_thread_fn
> cpuhp_thread_fun
> cpuhp_invoke_callback
> smpboot_park_threads
>   smpboot_park_thread: ksoftirqd/1
> kthread_park
>   wait_task_inactive
>  schedule_hrtimerout
> 
> However, when PREEMPT_RT is set, this would cause a pending issue since
> schedule_hrtimerout() depend on thread ksoftirqd to complete related work if 
> it using HRTIMER_MODE_SOFT. So force using
> HRTIMER_MODE_HARD in such case.

This issue was observed on LX2160ARDB (arm64, 16 A72 cores) when selecting 
PREEMPT_RT, 
non-RT kernel works fine.And I could verify that fix on both linux-5.6.y-rt and 
linux-5.4.y-rt.
But for linux-5.9.y-rt and linux-5.10.y-rt, looks there are other issues which 
blocking
verification currently. Below is the steps for issue reproducing:

1. Kernel menuconfig:
CONFIG_QORIQ_CPUFREQ=y

CONFIG_HAVE_PREEMPT_LAZY=y
CONFIG_PREEMPT_LAZY=y
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_RT=y
CONFIG_PREEMPT_COUNT=y
CONFIG_PREEMPTION=y

2. Shell commands (Issue would happen within roughly 400 rounds of below loop)
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu8/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu9/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu10/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu11/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu12/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu13/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu14/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu15/cpufreq/scaling_governor

count=1
while [ $? -eq 0 ]
do
echo "$count th test"
sleep 3
let "count=count+1"

echo 0 > /sys/devices/system/cpu/cpu0/online
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 0 > /sys/devices/system/cpu/cpu2/online
echo 0 > /sys/devices/system/cpu/cpu3/online
echo 0 > /sys/devices/system/cpu/cpu4/online
echo 0 > /sys/devices/system/cpu/cpu5/online
echo 0 > /sys/devices/system/cpu/cpu6/online
echo 0 > /sys/devices/system/cpu/cpu7/online
echo 0 > /sys/devices/system/cpu/cpu8/online
echo 0 > /sys/devices/system/cpu/cpu9/online
echo 0 > /sys/devices/system/cpu/cpu10/online
echo 0 > /sys/devices/system/cpu/cpu11/online
echo 0 > /sys/devices/system/cpu/cpu12/online
echo 0 > /sys/devices/system/cpu/cpu13/online
echo 0 > /sys/devices/system/cpu/cpu14/online

echo 1 > /sys/devices/system/cpu/cpu0/online
echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online
echo 1 > /sys/devices/system/cpu/cpu4/online
echo 1 > /sys/devices/system/cpu/cpu5/online
echo 1 > /sys/devices/system/cpu/cpu6/online
echo 1 > /sys/devices/system/cpu/cpu7/online
echo 1 > /sys/devices/system/cpu/cpu8/online
echo 1 > /sys/devices/system/cpu/cpu9/online
echo 1 > /sys/devices/system/cpu/cpu10/online
echo 1 > /sys/devices/system/cpu/cpu11/online
echo 1 > /sys/devices/system/cpu/cpu12/online
echo 1 > /sys/devices/system/cpu/cpu13/online
echo 1 > /sys/devices/system/cpu/cpu14/online
done

To be honest, I am not sure how non-RT kernel could avoid this issue. Could 
anybody give some input/suggestion on this?
Thank you.

Regards,
Ran
 
> Suggested-by: Jiafei Pan 
> Signed-off-by: Ran Wang 
> ---
>  kernel/sched/core.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/k

[PATCH] [RFC] rt: kernel/sched/core: fix kthread_park() pending too long when CPU un-plugged

2021-01-07 Thread Ran Wang
When doing CPU un-plug stress test, function smpboot_park_threads() would
get call to park kernel threads (which including ksoftirqd) on that
CPU core, and function wait_task_inactive() would yield for those queued
task(s) by calling schedule_hrtimerout() with mode of HRTIMER_MODE_REL.

stack trace:
...
smpboot_thread_fn
cpuhp_thread_fun
cpuhp_invoke_callback
smpboot_park_threads
  smpboot_park_thread: ksoftirqd/1
kthread_park
  wait_task_inactive
 schedule_hrtimerout

However, when PREEMPT_RT is set, this would cause a pending issue since
schedule_hrtimerout() depend on thread ksoftirqd to complete related
work if it using HRTIMER_MODE_SOFT. So force using HRTIMER_MODE_HARD
in such case.

Suggested-by: Jiafei Pan 
Signed-off-by: Ran Wang 
---
 kernel/sched/core.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 792da55..4cc742a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2054,10 +2054,15 @@ unsigned long wait_task_inactive(struct task_struct *p, 
long match_state)
ktime_t to = NSEC_PER_SEC / HZ;
 
set_current_state(TASK_UNINTERRUPTIBLE);
-   schedule_hrtimeout(, HRTIMER_MODE_REL);
+
+   if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
+   !strncmp(p->comm, "ksoftirqd/", 10))
+   schedule_hrtimeout(,
+   HRTIMER_MODE_REL | HRTIMER_MODE_HARD);
+   else
+   schedule_hrtimeout(, HRTIMER_MODE_REL);
continue;
}
-
/*
 * Ahh, all good. It wasn't running, and it wasn't
 * runnable, which means that it will never become
-- 
2.7.4



[PATCH] spi: spi-nxp-fspi: fix fspi panic by unexpected interrupts

2020-11-22 Thread Ran Wang
Given the case that bootloader(such as UEFI)'s FSPI driver might not
handle all interrupts before loading kernel, those legacy interrupts
would assert immidiately once kernel's FSPI driver enable them. Further,
if it was FSPI_INTR_IPCMDDONE, the irq handler nxp_fspi_irq_handler()
would call complete(>c) to notify others. However, f->c might not be
initialized yet at that time, then cause kernel panic.

Of cause, we should fix this issue within bootloader. But it would be
better to have this pacth to make dirver more robust (by clearing all
interrupt status bits before enabling interrupts).

Suggested-by: Han Xu 
Signed-off-by: Ran Wang 
---
 drivers/spi/spi-nxp-fspi.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index 0d41406..ab90356 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -1001,6 +1001,7 @@ static int nxp_fspi_probe(struct platform_device *pdev)
struct resource *res;
struct nxp_fspi *f;
int ret;
+   u32 reg;
 
ctlr = spi_alloc_master(>dev, sizeof(*f));
if (!ctlr)
@@ -1032,6 +1033,12 @@ static int nxp_fspi_probe(struct platform_device *pdev)
goto err_put_ctrl;
}
 
+   /* Clear potential interrupts */
+   reg = fspi_readl(f, f->iobase + FSPI_INTR);
+   if (reg)
+   fspi_writel(f, reg, f->iobase + FSPI_INTR);
+
+
/* find the resources - controller memory mapped space */
if (is_acpi_node(f->dev->fwnode))
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-- 
2.7.4



[PATCH v4 3/3] arm: dts: ls1021a: fix rcpm failed to claim resource

2020-11-01 Thread Ran Wang
The range of dcfg reg is wrong, which overlap with other device,
such as rcpm. This issue causing rcpm driver failed to claim
reg resource when calling devm_ioremap_resource().

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v4:
 - None

Change in v3:
 - None

Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index e12809d6..16744f64 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -173,7 +173,7 @@
 
dcfg: dcfg@1ee {
compatible = "fsl,ls1021a-dcfg", "syscon";
-   reg = <0x0 0x1ee 0x0 0x1>;
+   reg = <0x0 0x1ee 0x0 0x1000>;
big-endian;
};
 
-- 
2.7.4



[PATCH v4 2/3] arm: dts: ls1021a: fix flextimer failed to wake system

2020-11-01 Thread Ran Wang
The data of property 'fsl,rcpm-wakeup' is not corrcet, which causing
RCPM driver incorrectly program register IPPDEXPCR1, then flextimer is
wrongly clock gated during system suspend, can't send interrupt to
wake.

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v4:
 - None

Change in v3:
 - None

Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 827373e..e12809d6 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1013,7 +1013,7 @@
compatible = "fsl,ls1021a-ftm-alarm";
reg = <0x0 0x29d 0x0 0x1>;
reg-names = "ftm";
-   fsl,rcpm-wakeup = < 0x2 0x0>;
+   fsl,rcpm-wakeup = < 0x0 0x2000>;
interrupts = ;
big-endian;
};
-- 
2.7.4



[PATCH v4 1/3] soc: fsl: handle RCPM errata A-008646 on SoC LS1021A

2020-11-01 Thread Ran Wang
From: Biwen Li 

Hardware issue:
- Reading register RCPM_IPPDEXPCR1 always return zero, this causes
  system firmware could not get correct information and wrongly do
  clock gating for all wakeup source IP during system suspend. Then
  those IPs will never get chance to wake system.

Workaround:
- Copy register RCPM_IPPDEXPCR1's setting to register SCFG_SPARECR8
  to allow system firmware's psci method read it and do things accordingly.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v4:
 - Replace property 'fsl,ippdexpcr1-alt-reg' with compatible checking as the
   workaround trigger condition.

Change in v3:
 - Add  copy_ippdexpcr1_setting(), simplize workaournd's implementation
   according to binding update.
 - Minor update on commit message.

Change in v2:
 - Update commit message to be more clear.
 - Replace device_property_read_u32_array() with 
syscon_regmap_lookup_by_phandle_args()
   to make code simpler.

 drivers/soc/fsl/rcpm.c | 35 ++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..4ace28c 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -22,6 +22,28 @@ struct rcpm {
boollittle_endian;
 };
 
+#define  SCFG_SPARECR8 0x051c
+
+static void copy_ippdexpcr1_setting(u32 val)
+{
+   struct device_node *np;
+   void __iomem *regs;
+   u32 reg_val;
+
+   np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-scfg");
+   if (!np)
+   return;
+
+   regs = of_iomap(np, 0);
+   if (!regs)
+   return;
+
+   reg_val = ioread32be(regs + SCFG_SPARECR8);
+   iowrite32be(val | reg_val, regs + SCFG_SPARECR8);
+
+   iounmap(regs);
+}
+
 /**
  * rcpm_pm_prepare - performs device-level tasks associated with power
  * management, such as programming related to the wakeup source control.
@@ -90,6 +112,17 @@ static int rcpm_pm_prepare(struct device *dev)
tmp |= ioread32be(address);
iowrite32be(tmp, address);
}
+   /*
+* Workaround of errata A-008646 on SoC LS1021A:
+* There is a bug of register ippdexpcr1.
+* Reading configuration register RCPM_IPPDEXPCR1
+* always return zero. So save ippdexpcr1's value
+* to register SCFG_SPARECR8.And the value of
+* ippdexpcr1 will be read from SCFG_SPARECR8.
+*/
+   if (dev_of_node(dev) && (i == 1))
+   if (of_device_is_compatible(np, "fsl,ls1021a-rcpm"))
+   copy_ippdexpcr1_setting(tmp);
}
 
return 0;
-- 
2.7.4



[PATCH] usb: gadget: fsl: fix null pointer checking

2020-10-15 Thread Ran Wang
fsl_ep_fifo_status() should return error if _ep->desc is null.

Fixes: 75eaa498c99e (“usb: gadget: Correct NULL pointer checking in fsl gadget”)
Signed-off-by: Ran Wang 
---
 drivers/usb/gadget/udc/fsl_udc_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c 
b/drivers/usb/gadget/udc/fsl_udc_core.c
index de528e3..ad6ff9c 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -1051,7 +1051,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
u32 bitmask;
struct ep_queue_head *qh;
 
-   if (!_ep || _ep->desc || !(_ep->desc->bEndpointAddress&0xF))
+   if (!_ep || !_ep->desc || !(_ep->desc->bEndpointAddress&0xF))
return -ENODEV;
 
ep = container_of(_ep, struct fsl_ep, ep);
-- 
2.7.4



RE: [PATCH] usb: host: fsl-mph-dr-of: check return of dma_set_mask()

2020-10-14 Thread Ran Wang
Hi Peter,

On Sunday, October 11, 2020 7:41 AM Peter Chen wrote:
> 
> On 20-10-10 14:03:08, Ran Wang wrote:
> > fsl_usb2_device_register() should stop init if dma_set_mask() return
> > error.
> >
> > Fixes: cae058610465 ("drivers/usb/host: fsl: Set DMA_MASK of usb
> > platform device")
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/usb/host/fsl-mph-dr-of.c | 9 ++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/host/fsl-mph-dr-of.c
> > b/drivers/usb/host/fsl-mph-dr-of.c
> > index ae8f60f..44a7e58 100644
> > --- a/drivers/usb/host/fsl-mph-dr-of.c
> > +++ b/drivers/usb/host/fsl-mph-dr-of.c
> > @@ -94,10 +94,13 @@ static struct platform_device
> > *fsl_usb2_device_register(
> >
> > pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
> >
> > -   if (!pdev->dev.dma_mask)
> > +   if (!pdev->dev.dma_mask) {
> > pdev->dev.dma_mask = >dev.coherent_dma_mask;
> > -   else
> > -   dma_set_mask(>dev, DMA_BIT_MASK(32));
> > +   } else {
> > +   retval = dma_set_mask(>dev, DMA_BIT_MASK(32));
> > +   if (retval)
> > +   goto error;
> > +   }
> >
> > retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
> > if (retval)
> > --
> > 2.7.4
> >
> 
> Reviewed-by: Peter Chen 
> 
> One more place need to fix, if platform_device_alloc returns NULL,
> it should not call platform_device_put to release platform
> device memory.
> 
>   pdev = platform_device_alloc(name, id);
>   if (!pdev) {
>   retval = -ENOMEM;
>   goto error;
>   }
>   ...
> error:
>   platform_device_put(pdev);
>   return ERR_PTR(retval);

Got it, let me check this later.

Thanks & Regards,
Ran



[PATCH] usb: host: fsl-mph-dr-of: check return of dma_set_mask()

2020-10-10 Thread Ran Wang
fsl_usb2_device_register() should stop init if dma_set_mask() return
error.

Fixes: cae058610465 ("drivers/usb/host: fsl: Set DMA_MASK of usb platform 
device")
Signed-off-by: Ran Wang 
---
 drivers/usb/host/fsl-mph-dr-of.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index ae8f60f..44a7e58 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -94,10 +94,13 @@ static struct platform_device *fsl_usb2_device_register(
 
pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
 
-   if (!pdev->dev.dma_mask)
+   if (!pdev->dev.dma_mask) {
pdev->dev.dma_mask = >dev.coherent_dma_mask;
-   else
-   dma_set_mask(>dev, DMA_BIT_MASK(32));
+   } else {
+   retval = dma_set_mask(>dev, DMA_BIT_MASK(32));
+   if (retval)
+   goto error;
+   }
 
retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
if (retval)
-- 
2.7.4



RE: [PATCH v3 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-reg' property

2020-10-09 Thread Ran Wang
Hi Rob,

On Tuesday, September 29, 2020 4:23 PM, Ran Wang wrote:
> 
> From: Biwen Li 
> 
> The 'fsl,ippdexpcr1-alt-reg' property is used to handle an errata A-008646 on
> LS1021A.
> 
> Signed-off-by: Biwen Li 
> Signed-off-by: Ran Wang 
> ---
> Change in v3:
>  - Simplize related proterty definition and rename it.

Could you please comment for this version? Thanks in advance.

Regards,
Ran

> Change in v2:
>  - None
> 
>  Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> index 5a33619..62a22fc 100644
> --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> @@ -34,6 +34,9 @@ Chassis Version Example Chips
>  Optional properties:
>   - little-endian : RCPM register block is Little Endian. Without it RCPM
> will be Big Endian (default case).
> + - fsl,ippdexpcr1-alt-reg : The property is trying to workaround a
> +   hardware issue (found on SoC LS1021A only), if pressent, RCPM driver
> +   will use SCFG_SPARECR8 as a shadow register for RCPM_IPPDEXPCR1.
> 
>  Example:
>  The RCPM node for T4240:
> @@ -43,6 +46,15 @@ The RCPM node for T4240:
>   #fsl,rcpm-wakeup-cells = <2>;
>   };
> 
> +The RCPM node for LS1021A:
> + rcpm: rcpm@1ee2140 {
> + compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
> + reg = <0x0 0x1ee2140 0x0 0x8>;
> + #fsl,rcpm-wakeup-cells = <2>;
> + fsl,ippdexpcr1-alt-reg;
> + };
> +
> +
>  * Freescale RCPM Wakeup Source Device Tree Bindings
>  ---
>  Required fsl,rcpm-wakeup property should be added to a device node if the
> device
> --
> 2.7.4



[PATCH v3 5/5] arm: dts: ls1021a: fix rcpm failed to claim resource

2020-09-29 Thread Ran Wang
The range of dcfg reg is wrong, which overlap with other device,
such as rcpm. This issue causing rcpm driver failed to claim
reg resource when calling devm_ioremap_resource().

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v3:
 - None

Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index cb95964..9e588ad 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -173,7 +173,7 @@
 
dcfg: dcfg@1ee {
compatible = "fsl,ls1021a-dcfg", "syscon";
-   reg = <0x0 0x1ee 0x0 0x1>;
+   reg = <0x0 0x1ee 0x0 0x1000>;
big-endian;
};
 
-- 
2.7.4



[PATCH v3 4/5] arm: dts: ls1021a: fix flextimer failed to wake system

2020-09-29 Thread Ran Wang
The data of property 'fsl,rcpm-wakeup' is not corrcet, which causing
RCPM driver incorrectly program register IPPDEXPCR1, then flextimer is
wrongly clock gated during system suspend, can't send interrupt to
wake.

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v3:
 - None

Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 98b597e..cb95964 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1014,7 +1014,7 @@
compatible = "fsl,ls1021a-ftm-alarm";
reg = <0x0 0x29d 0x0 0x1>;
reg-names = "ftm";
-   fsl,rcpm-wakeup = < 0x2 0x0>;
+   fsl,rcpm-wakeup = < 0x0 0x2000>;
interrupts = ;
big-endian;
};
-- 
2.7.4



[PATCH v3 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-reg' property

2020-09-29 Thread Ran Wang
From: Biwen Li 

The 'fsl,ippdexpcr1-alt-reg' property is used to handle an errata A-008646
on LS1021A.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v3:
 - Simplize related proterty definition and rename it.

Change in v2:
 - None

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 12 
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index 5a33619..62a22fc 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -34,6 +34,9 @@ Chassis Version   Example Chips
 Optional properties:
  - little-endian : RCPM register block is Little Endian. Without it RCPM
will be Big Endian (default case).
+ - fsl,ippdexpcr1-alt-reg : The property is trying to workaround a
+   hardware issue (found on SoC LS1021A only), if pressent, RCPM driver
+   will use SCFG_SPARECR8 as a shadow register for RCPM_IPPDEXPCR1.
 
 Example:
 The RCPM node for T4240:
@@ -43,6 +46,15 @@ The RCPM node for T4240:
#fsl,rcpm-wakeup-cells = <2>;
};
 
+The RCPM node for LS1021A:
+   rcpm: rcpm@1ee2140 {
+   compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
+   reg = <0x0 0x1ee2140 0x0 0x8>;
+   #fsl,rcpm-wakeup-cells = <2>;
+   fsl,ippdexpcr1-alt-reg;
+   };
+
+
 * Freescale RCPM Wakeup Source Device Tree Bindings
 ---
 Required fsl,rcpm-wakeup property should be added to a device node if the 
device
-- 
2.7.4



[PATCH v3 2/5] soc: fsl: handle RCPM errata A-008646 on SoC LS1021A

2020-09-29 Thread Ran Wang
From: Biwen Li 

Hardware issue:
- Reading register RCPM_IPPDEXPCR1 always return zero, this causes
  system firmware could not get correct information and wrongly do
  clock gating for all wakeup source IP during system suspend. Then
  those IPs will never get chance to wake system.

Workaround:
- Copy register RCPM_IPPDEXPCR1's setting to register SCFG_SPARECR8
  to allow system firmware's psci method read it and do things accordingly.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v3:
 - Add  copy_ippdexpcr1_setting(), simplize workaournd's implementation
   according to binding update.
 - Minor update on commit message.

Change in v2:
 - Update commit message to be more clear.
 - Replace device_property_read_u32_array() with 
syscon_regmap_lookup_by_phandle_args()
   to make code simpler.

 drivers/soc/fsl/rcpm.c | 35 ++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..4ac2a77 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -22,6 +22,28 @@ struct rcpm {
boollittle_endian;
 };
 
+#define  SCFG_SPARECR8 0x051c
+
+static void copy_ippdexpcr1_setting(u32 val)
+{
+   struct device_node *np;
+   void __iomem *regs;
+   u32 reg_val;
+
+   np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-scfg");
+   if (!np)
+   return;
+
+   regs = of_iomap(np, 0);
+   if (!regs)
+   return;
+
+   reg_val = ioread32be(regs + SCFG_SPARECR8);
+   iowrite32be(val | reg_val, regs + SCFG_SPARECR8);
+
+   iounmap(regs);
+}
+
 /**
  * rcpm_pm_prepare - performs device-level tasks associated with power
  * management, such as programming related to the wakeup source control.
@@ -90,6 +112,17 @@ static int rcpm_pm_prepare(struct device *dev)
tmp |= ioread32be(address);
iowrite32be(tmp, address);
}
+   /*
+* Workaround of errata A-008646 on SoC LS1021A:
+* There is a bug of register ippdexpcr1.
+* Reading configuration register RCPM_IPPDEXPCR1
+* always return zero. So save ippdexpcr1's value
+* to register SCFG_SPARECR8.And the value of
+* ippdexpcr1 will be read from SCFG_SPARECR8.
+*/
+   if (dev_of_node(dev) && (i == 1))
+   if (device_property_read_bool(dev, 
"fsl,ippdexpcr1-alt-reg"))
+   copy_ippdexpcr1_setting(tmp);
}
 
return 0;
-- 
2.7.4



[PATCH v3 3/5] arm: dts: ls1021a: enable RCPM workaround for erratum A-008646

2020-09-29 Thread Ran Wang
From: Biwen Li 

The patch fixes a bug that FlexTimer cannot
wakeup system in deep sleep.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v3:
 - Update proterty according to binding and driver change.

Change in v2:
 - Change subject of commit message to be consistent with other related patches.

 arch/arm/boot/dts/ls1021a.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 827373e..98b597e 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1007,6 +1007,7 @@
compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1ee2140 0x0 0x8>;
#fsl,rcpm-wakeup-cells = <2>;
+   fsl,ippdexpcr1-alt-reg;
};
 
ftm_alarm0: timer0@29d {
-- 
2.7.4



[PATCH v2] arm64: dts: fix endianness issue of rcpm

2020-09-28 Thread Ran Wang
From: Biwen Li 

Add little-endian property to RCPM node (for ls1028a,ls1088a,ls208xa),
otherwise RCPM driver will program hardware with incorrect setting,
causing system (such as LS1028ARDB) failed to be waked by wakeup source.

Fixes: 791c88ca5713 (“arm64: dts: ls1028a: Add ftm_alarm0 DT node”)
Fixes: f4fe3a8665495 (“arm64: dts: layerscape: add ftm_alarm0 node”)
Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v2:
 - Update commit message with more details
 - Add Fixes and Singed-off tags

 arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 1 +
 arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 1 +
 arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi | 1 +
 3 files changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
index 0efeb8f..651bfe1 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
@@ -1012,6 +1012,7 @@
compatible = "fsl,ls1028a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x1c>;
#fsl,rcpm-wakeup-cells = <7>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
index 169f474..2ef812d 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
@@ -787,6 +787,7 @@
compatible = "fsl,ls1088a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x18>;
#fsl,rcpm-wakeup-cells = <6>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
index 41102da..141b3d2 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
@@ -769,6 +769,7 @@
compatible = "fsl,ls208xa-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x18>;
#fsl,rcpm-wakeup-cells = <6>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
-- 
2.7.4



RE: [PATCH] arm64: dts: fix endianness of rcpm

2020-09-28 Thread Ran Wang
Hi Fabio,

On Tuesday, September 29, 2020 3:20 AM, Fabio Estevam wrote:
> 
> Hi Ran,
> 
> On Mon, Sep 28, 2020 at 6:14 AM Ran Wang  wrote:
> >
> > From: Biwen Li 
> >
> > Add little-endian property of rcpm for ls1028a,ls1088a,ls208xa
> >
> > Signed-off-by: Biwen Li 
> 
> You missed your Signed-off-by tag.

Oh, thanks for pointing out, will update in next version.
 
> What about adding a Fixes tag?

Sure, will add it.

Regards,
Ran


RE: [PATCH 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-28 Thread Ran Wang
Hi Rob,

On Monday, September 28, 2020 9:57 PM, Rob Herring wrote:
> 
> On Wed, Sep 23, 2020 at 1:44 AM Ran Wang  wrote:
> >
> > Hi Rob,
> >
> > On Wednesday, September 23, 2020 10:33 AM, Rob Herring wrote:
> > >
> > > On Wed, Sep 16, 2020 at 04:18:27PM +0800, Ran Wang wrote:
> > > > From: Biwen Li 
> > > >
> > > > The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata
> > > > A-008646 on LS1021A
> > > >
> > > > Signed-off-by: Biwen Li 
> > > > Signed-off-by: Ran Wang 
> > > > ---
> > > >  Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19
> > > > +++
> > > >  1 file changed, 19 insertions(+)
> > > >
> > > > diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > > b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > > index 5a33619..1be58a3 100644
> > > > --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > > +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > > @@ -34,6 +34,11 @@ Chassis Version  Example Chips
> > > >  Optional properties:
> > > >   - little-endian : RCPM register block is Little Endian. Without it 
> > > > RCPM
> > > > will be Big Endian (default case).
> > > > + - fsl,ippdexpcr1-alt-addr : The property is related to a hardware 
> > > > issue
> > > > +   on SoC LS1021A and only needed on SoC LS1021A.
> > > > +   Must include 2 entries:
> > > > +   The first entry must be a link to the SCFG device node.
> > > > +   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
> > >
> > > You don't need a DT change for this. You can find SCFG node by its
> > > compatible string and then the offset should be known given this issue is
> only on 1 SoC.
> >
> > Did you mean that RCPM driver just to access IPPDEXPCR1 shadowed
> > register in SCFG directly without fetching it's offset info. from DT?
> 
> Yes. There's only 1 possible value of the offset because there's only one 
> SoC, so
> the driver can hardcode the offset. And I assume there's only one SCFG node,
> so you can find it by its compatible string (of_find_compatible_node).

Got it, let me update this in next version, thank you.

Regards,
Ran

> Rob


[PATCH] arm64: dts: fix endianness of rcpm

2020-09-28 Thread Ran Wang
From: Biwen Li 

Add little-endian property of rcpm for ls1028a,ls1088a,ls208xa

Signed-off-by: Biwen Li 
---
 arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 1 +
 arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 1 +
 arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi | 1 +
 3 files changed, 3 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
index 0efeb8f..651bfe1 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
@@ -1012,6 +1012,7 @@
compatible = "fsl,ls1028a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x1c>;
#fsl,rcpm-wakeup-cells = <7>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
index 169f474..2ef812d 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
@@ -787,6 +787,7 @@
compatible = "fsl,ls1088a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x18>;
#fsl,rcpm-wakeup-cells = <6>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
index 41102da..141b3d2 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi
@@ -769,6 +769,7 @@
compatible = "fsl,ls208xa-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1e34040 0x0 0x18>;
#fsl,rcpm-wakeup-cells = <6>;
+   little-endian;
};
 
ftm_alarm0: timer@280 {
-- 
2.7.4



RE: [PATCH 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-27 Thread Ran Wang
Hi Rob

Not sure whether you have missed this mail with my query.

Regards,
Ran

On Wednesday, September 23, 2020 2:44 PM Ran Wang wrote:
> 
> Hi Rob,
> 
> On Wednesday, September 23, 2020 10:33 AM, Rob Herring wrote:
> >
> > On Wed, Sep 16, 2020 at 04:18:27PM +0800, Ran Wang wrote:
> > > From: Biwen Li 
> > >
> > > The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata
> > > A-008646 on LS1021A
> > >
> > > Signed-off-by: Biwen Li 
> > > Signed-off-by: Ran Wang 
> > > ---
> > >  Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19
> > > +++
> > >  1 file changed, 19 insertions(+)
> > >
> > > diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > index 5a33619..1be58a3 100644
> > > --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > > @@ -34,6 +34,11 @@ Chassis VersionExample Chips
> > >  Optional properties:
> > >   - little-endian : RCPM register block is Little Endian. Without it RCPM
> > > will be Big Endian (default case).
> > > + - fsl,ippdexpcr1-alt-addr : The property is related to a hardware issue
> > > +   on SoC LS1021A and only needed on SoC LS1021A.
> > > +   Must include 2 entries:
> > > +   The first entry must be a link to the SCFG device node.
> > > +   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
> >
> > You don't need a DT change for this. You can find SCFG node by its
> > compatible string and then the offset should be known given this issue is
> only on 1 SoC.
> 
> Did you mean that RCPM driver just to access IPPDEXPCR1 shadowed register
> in SCFG directly without fetching it's offset info. from DT?
> 
> Regards,
> Ran



RE: [PATCH 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-23 Thread Ran Wang
Hi Rob,

On Wednesday, September 23, 2020 10:33 AM, Rob Herring wrote:
> 
> On Wed, Sep 16, 2020 at 04:18:27PM +0800, Ran Wang wrote:
> > From: Biwen Li 
> >
> > The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata
> > A-008646 on LS1021A
> >
> > Signed-off-by: Biwen Li 
> > Signed-off-by: Ran Wang 
> > ---
> >  Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19
> > +++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > index 5a33619..1be58a3 100644
> > --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > @@ -34,6 +34,11 @@ Chassis Version  Example Chips
> >  Optional properties:
> >   - little-endian : RCPM register block is Little Endian. Without it RCPM
> > will be Big Endian (default case).
> > + - fsl,ippdexpcr1-alt-addr : The property is related to a hardware issue
> > +   on SoC LS1021A and only needed on SoC LS1021A.
> > +   Must include 2 entries:
> > +   The first entry must be a link to the SCFG device node.
> > +   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
> 
> You don't need a DT change for this. You can find SCFG node by its compatible
> string and then the offset should be known given this issue is only on 1 SoC.

Did you mean that RCPM driver just to access IPPDEXPCR1 shadowed register in 
SCFG
directly without fetching it's offset info. from DT?

Regards,
Ran



[PATCH v2 3/5] arm: dts: ls1021a: enable RCPM workaround for erratum A-008646

2020-09-23 Thread Ran Wang
From: Biwen Li 

The patch fixes a bug that FlexTimer cannot
wakeup system in deep sleep.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v2:
 - Change subject of commit message to be consistent with other related patches.

 arch/arm/boot/dts/ls1021a.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 827373e..089fe86 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1007,6 +1007,7 @@
compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1ee2140 0x0 0x8>;
#fsl,rcpm-wakeup-cells = <2>;
+   fsl,ippdexpcr1-alt-addr = < 0x51c>;
};
 
ftm_alarm0: timer0@29d {
-- 
2.7.4



[PATCH v2 4/5] arm: dts: ls1021a: fix flextimer failed to wake system

2020-09-23 Thread Ran Wang
The data of property 'fsl,rcpm-wakeup' is not corrcet, which causing
RCPM driver incorrectly program register IPPDEXPCR1, then flextimer is
wrongly clock gated during system suspend, can't send interrupt to
wake.

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 089fe86..e372630f 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1014,7 +1014,7 @@
compatible = "fsl,ls1021a-ftm-alarm";
reg = <0x0 0x29d 0x0 0x1>;
reg-names = "ftm";
-   fsl,rcpm-wakeup = < 0x2 0x0>;
+   fsl,rcpm-wakeup = < 0x0 0x2000>;
interrupts = ;
big-endian;
};
-- 
2.7.4



[PATCH v2 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-23 Thread Ran Wang
From: Biwen Li 

The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata A-008646
on LS1021A

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v2:
 - None

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index 5a33619..1be58a3 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -34,6 +34,11 @@ Chassis Version  Example Chips
 Optional properties:
  - little-endian : RCPM register block is Little Endian. Without it RCPM
will be Big Endian (default case).
+ - fsl,ippdexpcr1-alt-addr : The property is related to a hardware issue
+   on SoC LS1021A and only needed on SoC LS1021A.
+   Must include 2 entries:
+   The first entry must be a link to the SCFG device node.
+   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
 
 Example:
 The RCPM node for T4240:
@@ -43,6 +48,20 @@ The RCPM node for T4240:
#fsl,rcpm-wakeup-cells = <2>;
};
 
+The RCPM node for LS1021A:
+   rcpm: rcpm@1ee2140 {
+   compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
+   reg = <0x0 0x1ee2140 0x0 0x8>;
+   #fsl,rcpm-wakeup-cells = <2>;
+
+   /*
+* The second and third entry compose an alt offset
+* address for IPPDEXPCR1(SCFG_SPARECR8)
+*/
+   fsl,ippdexpcr1-alt-addr = < 0x51c>;
+   };
+
+
 * Freescale RCPM Wakeup Source Device Tree Bindings
 ---
 Required fsl,rcpm-wakeup property should be added to a device node if the 
device
-- 
2.7.4



[PATCH v2 2/5] soc: fsl: handle RCPM errata A-008646 on SoC LS1021A

2020-09-23 Thread Ran Wang
From: Biwen Li 

Hardware issue:
- Reading register RCPM_IPPDEXPCR1 always return zero, this causes
  system firmware could not get correct information and wrongly do
  clock gating for all wakeup source IP during system suspend. Then
  those IPs will never get chance to wake system.

Workaround:
- Duplicate register RCPM_IPPDEXPCR1's setting to register SCFG_SPARECR8
  to allow system firmware's psci method read it and do things accordingly.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
Change in v2:
 - Update commit message to be more clear.
 - Replace device_property_read_u32_array() with 
syscon_regmap_lookup_by_phandle_args()
   to make code simpler.

 drivers/soc/fsl/rcpm.c | 31 ++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..6e3 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -37,6 +40,9 @@ static int rcpm_pm_prepare(struct device *dev)
struct device_node  *np = dev->of_node;
u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1];
u32 setting[RCPM_WAKEUP_CELL_MAX_SIZE] = {0};
+   struct regmap *scfg_addr_regmap = NULL;
+   u32 reg_offset = 0;
+   u32 reg_value = 0;
 
rcpm = dev_get_drvdata(dev);
if (!rcpm)
@@ -90,6 +96,29 @@ static int rcpm_pm_prepare(struct device *dev)
tmp |= ioread32be(address);
iowrite32be(tmp, address);
}
+   /*
+* Workaround of errata A-008646 on SoC LS1021A:
+* There is a bug of register ippdexpcr1.
+* Reading configuration register RCPM_IPPDEXPCR1
+* always return zero. So save ippdexpcr1's value
+* to register SCFG_SPARECR8.And the value of
+* ippdexpcr1 will be read from SCFG_SPARECR8.
+*/
+   if (dev_of_node(dev) && (i == 1)) {
+   scfg_addr_regmap = 
syscon_regmap_lookup_by_phandle_args(np,
+   "fsl,ippdexpcr1-alt-addr",
+   1,
+   _offset);
+   if (!IS_ERR_OR_NULL(scfg_addr_regmap)) {
+   /* Update value on register SCFG_SPARECR8 */
+   regmap_read(scfg_addr_regmap,
+   reg_offset,
+   _value);
+   regmap_write(scfg_addr_regmap,
+   reg_offset,
+   tmp | reg_value);
+   }
+   }
}
 
return 0;
-- 
2.7.4



[PATCH v2 5/5] arm: dts: ls1021a: fix rcpm failed to claim resource

2020-09-23 Thread Ran Wang
The range of dcfg reg is wrong, which overlap with other device,
such as rcpm. This issue causing rcpm driver failed to claim
reg resource when calling devm_ioremap_resource().

Signed-off-by: Ran Wang 
Acked-by: Li Yang 
---
Change in v2:
 - None

 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index e372630f..286c547 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -173,7 +173,7 @@
 
dcfg: dcfg@1ee {
compatible = "fsl,ls1021a-dcfg", "syscon";
-   reg = <0x0 0x1ee 0x0 0x1>;
+   reg = <0x0 0x1ee 0x0 0x1000>;
big-endian;
};
 
-- 
2.7.4



RE: [PATCH 3/5] arm: dts: ls1021a: fix that FlexTimer cannot wakeup system in deep sleep

2020-09-21 Thread Ran Wang
Hi Leo,

On Tuesday, September 22, 2020 6:59 AM, Leo Li wrote:
> 
> > -Original Message-
> > From: Ran Wang 
> > Sent: Wednesday, September 16, 2020 3:18 AM
> > To: Leo Li ; Rob Herring ;
> > Shawn Guo 
> > Cc: linuxppc-...@lists.ozlabs.org;
> > linux-arm-ker...@lists.infradead.org;
> > devicet...@vger.kernel.org; linux-kernel@vger.kernel.org; Biwen Li
> > ; Ran Wang 
> > Subject: [PATCH 3/5] arm: dts: ls1021a: fix that FlexTimer cannot
> > wakeup system in deep sleep
> 
> A better description should be enabling the A-008646 workaround to be
> consistent with other patches.

OK, will update this.

Regards,
Ran
> >
> > From: Biwen Li 
> >
> > The patch fixes a bug that FlexTimer cannot wakeup system in deep sleep.
> >
> > Signed-off-by: Biwen Li 
> > Signed-off-by: Ran Wang 
> > ---
> >  arch/arm/boot/dts/ls1021a.dtsi | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/arm/boot/dts/ls1021a.dtsi
> > b/arch/arm/boot/dts/ls1021a.dtsi index 827373e..089fe86 100644
> > --- a/arch/arm/boot/dts/ls1021a.dtsi
> > +++ b/arch/arm/boot/dts/ls1021a.dtsi
> > @@ -1007,6 +1007,7 @@
> > compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm- 2.1+";
> > reg = <0x0 0x1ee2140 0x0 0x8>;
> > #fsl,rcpm-wakeup-cells = <2>;
> > +   fsl,ippdexpcr1-alt-addr = < 0x51c>;
> > };
> >
> > ftm_alarm0: timer0@29d {
> > --
> > 2.7.4



RE: [PATCH 2/5] soc: fsl: handle RCPM errata A-008646 on SoC LS1021A

2020-09-21 Thread Ran Wang
Hi Leo

Tuesday, September 22, 2020 6:43 AM, Leo Li wrote:
> 
> 
> > -Original Message-
> > From: Ran Wang 
> > Sent: Wednesday, September 16, 2020 3:18 AM
> > To: Leo Li ; Rob Herring ;
> > Shawn Guo 
> > Cc: linuxppc-...@lists.ozlabs.org;
> > linux-arm-ker...@lists.infradead.org;
> > devicet...@vger.kernel.org; linux-kernel@vger.kernel.org; Biwen Li
> > ; Ran Wang 
> > Subject: [PATCH 2/5] soc: fsl: handle RCPM errata A-008646 on SoC
> > LS1021A
> >
> > From: Biwen Li 
> >
> > Description:
> > - Reading configuration register RCPM_IPPDEXPCR1
> >   always return zero
> >
> > Workaround:
> > - Save register RCPM_IPPDEXPCR1's value to
> >   register SCFG_SPARECR8.(uboot's psci also
> >   need reading value from the register SCFG_SPARECR8
> >   to set register RCPM_IPPDEXPCR1)
> >
> > Impact:
> > - FlexTimer module will cannot wakeup system in
> Will not..
> Also it will be better to merge this with the issue description part above to
> prevent confusion.

OK

> >   deep sleep on SoC LS1021A
> >
> > Signed-off-by: Biwen Li 
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/soc/fsl/rcpm.c | 42
> > +-
> >  1 file changed, 41 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> > a093dbe..e6354f5 100644
> > --- a/drivers/soc/fsl/rcpm.c
> > +++ b/drivers/soc/fsl/rcpm.c
> > @@ -2,7 +2,7 @@
> >  //
> >  // rcpm.c - Freescale QorIQ RCPM driver  // -// Copyright 2019 NXP
> > +// Copyright 2019-2020 NXP
> >  //
> >  // Author: Ran Wang 
> >
> > @@ -13,6 +13,9 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> > +#include 
> >
> >  #define RCPM_WAKEUP_CELL_MAX_SIZE  7
> >
> > @@ -37,6 +40,9 @@ static int rcpm_pm_prepare(struct device *dev)
> > struct device_node  *np = dev->of_node;
> > u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1];
> > u32 setting[RCPM_WAKEUP_CELL_MAX_SIZE] = {0};
> > +   struct regmap *scfg_addr_regmap = NULL;
> > +   u32 reg_offset[2];
> > +   u32 reg_value = 0;
> >
> > rcpm = dev_get_drvdata(dev);
> > if (!rcpm)
> > @@ -90,6 +96,40 @@ static int rcpm_pm_prepare(struct device *dev)
> > tmp |= ioread32be(address);
> > iowrite32be(tmp, address);
> > }
> > +   /*
> > +* Workaround of errata A-008646 on SoC LS1021A:
> > +* There is a bug of register ippdexpcr1.
> > +* Reading configuration register RCPM_IPPDEXPCR1
> > +* always return zero. So save ippdexpcr1's value
> > +* to register SCFG_SPARECR8.And the value of
> > +* ippdexpcr1 will be read from SCFG_SPARECR8.
> > +*/
> > +   if (device_property_present(dev, "fsl,ippdexpcr1-alt-addr"))
> > {
> > +   if (dev_of_node(dev)) {
> > +   scfg_addr_regmap =
> > syscon_regmap_lookup_by_phandle(np,
> > +
> >"fsl,ippdexpcr1-alt-addr");
> > +   } else if (is_acpi_node(dev->fwnode)) {
> > +   continue;
> > +   }
> > +
> > +   if (scfg_addr_regmap && (i == 1)) {
> > +   if (device_property_read_u32_array(dev,
> > +   "fsl,ippdexpcr1-alt-addr",
> > +   reg_offset,
> > +   2)) {
> 
> It is not necessary to read out the whole fsl,ippdexpcr1-alt-addr property if 
> we
> only need the offset.  Also you can change to use the
> syscon_regmap_lookup_by_phandle_args() API above to simplify the code.

Got it, will update it in next version, thanks.

Regards,
Ran

> > +   scfg_addr_regmap = NULL;
> > +   continue;
> > +   }
> > +   /* Read value from register SCFG_SPARECR8
> > */
> > +   regmap_read(scfg_addr_regmap,
> > +   reg_offset[1],
> > +   _value);
> > +   /* Write value to register SCFG_SPARECR8 */
> > +   regmap_write(scfg_addr_regmap,
> > +reg_offset[1],
> > +tmp | reg_value);
> > +   }
> > +   }
> > }
> >
> > return 0;
> > --
> > 2.7.4



RE: [PATCH 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-21 Thread Ran Wang
Hi Leo, Rob,


On Tuesday, September 22, 2020 6:20 AM, Leo Li wrote:
> 
> > -Original Message-
> > From: Ran Wang 
> > Sent: Wednesday, September 16, 2020 3:18 AM
> > To: Leo Li ; Rob Herring ;
> > Shawn Guo 
> > Cc: linuxppc-...@lists.ozlabs.org;
> > linux-arm-ker...@lists.infradead.org;
> > devicet...@vger.kernel.org; linux-kernel@vger.kernel.org; Biwen Li
> > ; Ran Wang 
> > Subject: [PATCH 1/5] Documentation: dt: binding: fsl: Add
> > 'fsl,ippdexpcr1-alt- addr' property
> >
> > From: Biwen Li 
> >
> > The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata
> > A-008646 on LS1021A
> 
> It looks like the previous version of this patch has gotten the reviewed-by 
> from
> Rob.  It would be good to be added to the patch for new submission.

Actually this patch has one update from previous version 
(https://lore.kernel.org/patchwork/patch/1161631/):
Reduce entry number from 3 to 2.

So I'd like to have a review for this one, sorry for not highlight this in 
advance.

Regards,
Ran

> >
> > Signed-off-by: Biwen Li 
> > Signed-off-by: Ran Wang 
> > ---
> >  Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19
> > +++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > index 5a33619..1be58a3 100644
> > --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
> > @@ -34,6 +34,11 @@ Chassis Version  Example Chips
> >  Optional properties:
> >   - little-endian : RCPM register block is Little Endian. Without it RCPM
> > will be Big Endian (default case).
> > + - fsl,ippdexpcr1-alt-addr : The property is related to a hardware issue
> > +   on SoC LS1021A and only needed on SoC LS1021A.
> > +   Must include 2 entries:
> > +   The first entry must be a link to the SCFG device node.
> > +   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
> >
> >  Example:
> >  The RCPM node for T4240:
> > @@ -43,6 +48,20 @@ The RCPM node for T4240:
> > #fsl,rcpm-wakeup-cells = <2>;
> > };
> >
> > +The RCPM node for LS1021A:
> > +   rcpm: rcpm@1ee2140 {
> > +   compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
> > +   reg = <0x0 0x1ee2140 0x0 0x8>;
> > +   #fsl,rcpm-wakeup-cells = <2>;
> > +
> > +   /*
> > +* The second and third entry compose an alt offset
> > +* address for IPPDEXPCR1(SCFG_SPARECR8)
> > +*/
> > +   fsl,ippdexpcr1-alt-addr = < 0x51c>;
> > +   };
> > +
> > +
> >  * Freescale RCPM Wakeup Source Device Tree Bindings
> >  ---
> >  Required fsl,rcpm-wakeup property should be added to a device node if
> > the device
> > --
> > 2.7.4



[PATCH 2/5] soc: fsl: handle RCPM errata A-008646 on SoC LS1021A

2020-09-16 Thread Ran Wang
From: Biwen Li 

Description:
- Reading configuration register RCPM_IPPDEXPCR1
  always return zero

Workaround:
- Save register RCPM_IPPDEXPCR1's value to
  register SCFG_SPARECR8.(uboot's psci also
  need reading value from the register SCFG_SPARECR8
  to set register RCPM_IPPDEXPCR1)

Impact:
- FlexTimer module will cannot wakeup system in
  deep sleep on SoC LS1021A

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
 drivers/soc/fsl/rcpm.c | 42 +-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..e6354f5 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -37,6 +40,9 @@ static int rcpm_pm_prepare(struct device *dev)
struct device_node  *np = dev->of_node;
u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1];
u32 setting[RCPM_WAKEUP_CELL_MAX_SIZE] = {0};
+   struct regmap *scfg_addr_regmap = NULL;
+   u32 reg_offset[2];
+   u32 reg_value = 0;
 
rcpm = dev_get_drvdata(dev);
if (!rcpm)
@@ -90,6 +96,40 @@ static int rcpm_pm_prepare(struct device *dev)
tmp |= ioread32be(address);
iowrite32be(tmp, address);
}
+   /*
+* Workaround of errata A-008646 on SoC LS1021A:
+* There is a bug of register ippdexpcr1.
+* Reading configuration register RCPM_IPPDEXPCR1
+* always return zero. So save ippdexpcr1's value
+* to register SCFG_SPARECR8.And the value of
+* ippdexpcr1 will be read from SCFG_SPARECR8.
+*/
+   if (device_property_present(dev, "fsl,ippdexpcr1-alt-addr")) {
+   if (dev_of_node(dev)) {
+   scfg_addr_regmap = 
syscon_regmap_lookup_by_phandle(np,
+   
   "fsl,ippdexpcr1-alt-addr");
+   } else if (is_acpi_node(dev->fwnode)) {
+   continue;
+   }
+
+   if (scfg_addr_regmap && (i == 1)) {
+   if (device_property_read_u32_array(dev,
+   "fsl,ippdexpcr1-alt-addr",
+   reg_offset,
+   2)) {
+   scfg_addr_regmap = NULL;
+   continue;
+   }
+   /* Read value from register SCFG_SPARECR8 */
+   regmap_read(scfg_addr_regmap,
+   reg_offset[1],
+   _value);
+   /* Write value to register SCFG_SPARECR8 */
+   regmap_write(scfg_addr_regmap,
+reg_offset[1],
+tmp | reg_value);
+   }
+   }
}
 
return 0;
-- 
2.7.4



[PATCH 4/5] arm: dts: ls1021a: fix flextimer failed to wake system

2020-09-16 Thread Ran Wang
The data of property 'fsl,rcpm-wakeup' is not corrcet, which causing
RCPM driver incorrectly program register IPPDEXPCR1, then flextimer is
wrongly clock gated during system suspend, can't send interrupt to
wake.

Signed-off-by: Ran Wang 
---
 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 089fe86..e372630f 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1014,7 +1014,7 @@
compatible = "fsl,ls1021a-ftm-alarm";
reg = <0x0 0x29d 0x0 0x1>;
reg-names = "ftm";
-   fsl,rcpm-wakeup = < 0x2 0x0>;
+   fsl,rcpm-wakeup = < 0x0 0x2000>;
interrupts = ;
big-endian;
};
-- 
2.7.4



[PATCH 3/5] arm: dts: ls1021a: fix that FlexTimer cannot wakeup system in deep sleep

2020-09-16 Thread Ran Wang
From: Biwen Li 

The patch fixes a bug that FlexTimer cannot
wakeup system in deep sleep.

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
 arch/arm/boot/dts/ls1021a.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index 827373e..089fe86 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -1007,6 +1007,7 @@
compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
reg = <0x0 0x1ee2140 0x0 0x8>;
#fsl,rcpm-wakeup-cells = <2>;
+   fsl,ippdexpcr1-alt-addr = < 0x51c>;
};
 
ftm_alarm0: timer0@29d {
-- 
2.7.4



[PATCH 5/5] arm: dts: ls1021a: fix rcpm failed to claim resource

2020-09-16 Thread Ran Wang
The range of dcfg reg is wrong, which overlap with other device,
such as rcpm. This issue causing rcpm driver failed to claim
reg resource when calling devm_ioremap_resource().

Signed-off-by: Ran Wang 
---
 arch/arm/boot/dts/ls1021a.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index e372630f..286c547 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -173,7 +173,7 @@
 
dcfg: dcfg@1ee {
compatible = "fsl,ls1021a-dcfg", "syscon";
-   reg = <0x0 0x1ee 0x0 0x1>;
+   reg = <0x0 0x1ee 0x0 0x1000>;
big-endian;
};
 
-- 
2.7.4



[PATCH 1/5] Documentation: dt: binding: fsl: Add 'fsl,ippdexpcr1-alt-addr' property

2020-09-16 Thread Ran Wang
From: Biwen Li 

The 'fsl,ippdexpcr1-alt-addr' property is used to handle an errata A-008646
on LS1021A

Signed-off-by: Biwen Li 
Signed-off-by: Ran Wang 
---
 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index 5a33619..1be58a3 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -34,6 +34,11 @@ Chassis Version  Example Chips
 Optional properties:
  - little-endian : RCPM register block is Little Endian. Without it RCPM
will be Big Endian (default case).
+ - fsl,ippdexpcr1-alt-addr : The property is related to a hardware issue
+   on SoC LS1021A and only needed on SoC LS1021A.
+   Must include 2 entries:
+   The first entry must be a link to the SCFG device node.
+   The 2nd entry must be offset of register IPPDEXPCR1 in SCFG.
 
 Example:
 The RCPM node for T4240:
@@ -43,6 +48,20 @@ The RCPM node for T4240:
#fsl,rcpm-wakeup-cells = <2>;
};
 
+The RCPM node for LS1021A:
+   rcpm: rcpm@1ee2140 {
+   compatible = "fsl,ls1021a-rcpm", "fsl,qoriq-rcpm-2.1+";
+   reg = <0x0 0x1ee2140 0x0 0x8>;
+   #fsl,rcpm-wakeup-cells = <2>;
+
+   /*
+* The second and third entry compose an alt offset
+* address for IPPDEXPCR1(SCFG_SPARECR8)
+*/
+   fsl,ippdexpcr1-alt-addr = < 0x51c>;
+   };
+
+
 * Freescale RCPM Wakeup Source Device Tree Bindings
 ---
 Required fsl,rcpm-wakeup property should be added to a device node if the 
device
-- 
2.7.4



RE: [PATCH v1] soc: fsl: rcpm: Add ACPI support

2020-09-16 Thread Ran Wang
Hi Ard,

On Wednesday, September 16, 2020 2:11 PM, Ard Biesheuvel wrote:
> Subject: Re: [PATCH v1] soc: fsl: rcpm: Add ACPI support
> 
> On 9/16/20 3:32 AM, Ran Wang wrote:
> > Hi Ard,
> >
> > On Tuesday, September 15, 2020 7:10 PM, Ard Biesheuvel wrote:
> >> Subject: Re: [PATCH v1] soc: fsl: rcpm: Add ACPI support
> >>
> >> On 9/15/20 1:06 PM, kuldip dwivedi wrote:
> >>> Add ACPI support in fsl RCPM driver. This is required to support
> >>> ACPI
> >>> S3 state. S3 is the ACPI sleep state that is known as "sleep" or
> >>> "suspend to RAM".
> >>> It essentially turns off most power of the system but keeps memory
> >>> powered.
> >>>
> >>> Signed-off-by: tanveer 
> >>> Signed-off-by: kuldip dwivedi 
> >>
> >> Why does the OS need to program this device? Can't this be done by
> >> firmware?
> >
> > This device is use to tell HW which IP (such as USB, SDHC, SATA, etc)
> > should not be clock gated during system enter low power state (to
> > allow that IP work as a wakeup source). And user does this configuration in
> device tree.
> 
> The point of ACPI is *not* to describe a DT topology using a table format that
> is not suited for it. The point of ACPI is to describe a machine that is more
> abstracted from the hardware than is typically possible with DT, where the
> abstractions are implemented by AML code that is provided by the firmware,
> but executed in the context of the OS.
> 
> So the idea is *not* finding the shortest possible path to get your existing 
> DT
> driver code running on a system that boots via ACPI.
> Instead, you should carefully think about the abstract ACPI machine that you
> will expose to the OS, and hide everything else in firmware.
> 
> In this particular case, it seems like your USB, SDHC and SATA device objects
> may need power state dependent AML methods that program this block
> directly.

Actually the scenario is a little bit complicated for RCPM function: it need to 
query
kernel wakeup source framework (see for_each_wakeup_source(ws)) to fetch all
potential candidates then do the programming accordingly. If we implement
this logic in AML methods, I have no idea how to collect those information 
stored in
wakeup source data of kernel.

Regards,
Ran

> 
> 
> > So implement
> > this RCPM driver to do it in kernel rather than firmware.
> >
> > Regards,
> > Ran
> >
> >>> ---
> >>>
> >>> Notes:
> >>>   1. Add ACPI match table
> >>>   2. NXP team members are added for confirming HID changes
> >>>   3. There is only one node in ACPI so no need to check for
> >>>  current device explicitly
> >>>   4. These changes are tested on LX2160A and LS1046A platforms
> >>>
> >>>drivers/soc/fsl/rcpm.c | 22 +++---
> >>>1 file changed, 19 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> >>> a093dbe6d2cb..e75a436fb159 100644
> >>> --- a/drivers/soc/fsl/rcpm.c
> >>> +++ b/drivers/soc/fsl/rcpm.c
> >>> @@ -2,10 +2,12 @@
> >>>//
> >>>// rcpm.c - Freescale QorIQ RCPM driver
> >>>//
> >>> -// Copyright 2019 NXP
> >>> +// Copyright 2019-2020 NXP
> >>> +// Copyright 2020 Puresoftware Ltd.
> >>>//
> >>>// Author: Ran Wang 
> >>>
> >>> +#include 
> >>>#include 
> >>>#include 
> >>>#include  @@ -57,8 +59,13 @@ static int
> >>> rcpm_pm_prepare(struct device *dev)
> >>>   rcpm->wakeup_cells + 1);
> >>>
> >>>   /*  Wakeup source should refer to current rcpm device */
> >>> - if (ret || (np->phandle != value[0]))
> >>> - continue;
> >>> + if (is_acpi_node(dev->fwnode)) {
> >>> + if (ret)
> >>> + continue;
> >>> + } else {
> >>> + if (ret || (np->phandle != value[0]))
> >>> + continue;
> >>> + }
> >>>
> >>>   /* Property "#fsl,rcpm-wakeup-cells" of rcpm node 
> >>> defines the
> >>>* number of IPPDEXPCR register cells, and 
> >>> "fsl,rcpm-wakeup"
> >>> @@ -139,10 +146,19 @@ static const struct of_device_id
> >>> rcpm_of_match[]
> >> = {
> >>>};
> >>>MODULE_DEVICE_TABLE(of, rcpm_of_match);
> >>>
> >>> +#ifdef CONFIG_ACPI
> >>> +static const struct acpi_device_id rcpm_acpi_match[] = {
> >>> + { "NXP0015", },
> >>> + { }
> >>> +};
> >>> +MODULE_DEVICE_TABLE(acpi, rcpm_acpi_match); #endif
> >>> +
> >>>static struct platform_driver rcpm_driver = {
> >>>   .driver = {
> >>>   .name = "rcpm",
> >>>   .of_match_table = rcpm_of_match,
> >>> + .acpi_match_table = ACPI_PTR(rcpm_acpi_match),
> >>>   .pm = _pm_ops,
> >>>   },
> >>>   .probe = rcpm_probe,
> >>>
> >



RE: [PATCH v1] soc: fsl: rcpm: Add ACPI support

2020-09-15 Thread Ran Wang
Hi Ard,

On Tuesday, September 15, 2020 7:10 PM, Ard Biesheuvel wrote:
> Subject: Re: [PATCH v1] soc: fsl: rcpm: Add ACPI support
> 
> On 9/15/20 1:06 PM, kuldip dwivedi wrote:
> > Add ACPI support in fsl RCPM driver. This is required to support ACPI
> > S3 state. S3 is the ACPI sleep state that is known as "sleep" or
> > "suspend to RAM".
> > It essentially turns off most power of the system but keeps memory
> > powered.
> >
> > Signed-off-by: tanveer 
> > Signed-off-by: kuldip dwivedi 
> 
> Why does the OS need to program this device? Can't this be done by
> firmware?

This device is use to tell HW which IP (such as USB, SDHC, SATA, etc) should 
not be
clock gated during system enter low power state (to allow that IP work as a
wakeup source). And user does this configuration in device tree. So implement
this RCPM driver to do it in kernel rather than firmware.

Regards,
Ran

> > ---
> >
> > Notes:
> >  1. Add ACPI match table
> >  2. NXP team members are added for confirming HID changes
> >  3. There is only one node in ACPI so no need to check for
> > current device explicitly
> >  4. These changes are tested on LX2160A and LS1046A platforms
> >
> >   drivers/soc/fsl/rcpm.c | 22 +++---
> >   1 file changed, 19 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> > a093dbe6d2cb..e75a436fb159 100644
> > --- a/drivers/soc/fsl/rcpm.c
> > +++ b/drivers/soc/fsl/rcpm.c
> > @@ -2,10 +2,12 @@
> >   //
> >   // rcpm.c - Freescale QorIQ RCPM driver
> >   //
> > -// Copyright 2019 NXP
> > +// Copyright 2019-2020 NXP
> > +// Copyright 2020 Puresoftware Ltd.
> >   //
> >   // Author: Ran Wang 
> >
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -57,8 +59,13 @@ static int rcpm_pm_prepare(struct device *dev)
> > rcpm->wakeup_cells + 1);
> >
> > /*  Wakeup source should refer to current rcpm device */
> > -   if (ret || (np->phandle != value[0]))
> > -   continue;
> > +   if (is_acpi_node(dev->fwnode)) {
> > +   if (ret)
> > +   continue;
> > +   } else {
> > +   if (ret || (np->phandle != value[0]))
> > +   continue;
> > +   }
> >
> > /* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines the
> >  * number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
> > @@ -139,10 +146,19 @@ static const struct of_device_id rcpm_of_match[]
> = {
> >   };
> >   MODULE_DEVICE_TABLE(of, rcpm_of_match);
> >
> > +#ifdef CONFIG_ACPI
> > +static const struct acpi_device_id rcpm_acpi_match[] = {
> > +   { "NXP0015", },
> > +   { }
> > +};
> > +MODULE_DEVICE_TABLE(acpi, rcpm_acpi_match); #endif
> > +
> >   static struct platform_driver rcpm_driver = {
> > .driver = {
> > .name = "rcpm",
> > .of_match_table = rcpm_of_match,
> > +   .acpi_match_table = ACPI_PTR(rcpm_acpi_match),
> > .pm = _pm_ops,
> > },
> > .probe = rcpm_probe,
> >



RE: [PATCH v1] soc: fsl: rcpm: Add ACPI support

2020-09-15 Thread Ran Wang
Hi Kuldip,

On Tuesday, September 15, 2020 7:07 PM, kuldip dwivedi wrote:
> Subject: [PATCH v1] soc: fsl: rcpm: Add ACPI support

Actually I also post a patch for this recently: 
https://lore.kernel.org/patchwork/patch/1299959/  :)

Regards,
Ran

> Add ACPI support in fsl RCPM driver. This is required to support ACPI S3 
> state.
> S3 is the ACPI sleep state that is known as "sleep" or "suspend to RAM".
> It essentially turns off most power of the system but keeps memory powered.

Actually the low power mode is to gate clocks rather than power down on 
Layerscape platforms.

> Signed-off-by: tanveer 
> Signed-off-by: kuldip dwivedi 
> ---
> 
> Notes:
> 1. Add ACPI match table
> 2. NXP team members are added for confirming HID changes
> 3. There is only one node in ACPI so no need to check for
>current device explicitly
> 4. These changes are tested on LX2160A and LS1046A platforms
> 
>  drivers/soc/fsl/rcpm.c | 22 +++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> a093dbe6d2cb..e75a436fb159 100644
> --- a/drivers/soc/fsl/rcpm.c
> +++ b/drivers/soc/fsl/rcpm.c
> @@ -2,10 +2,12 @@
>  //
>  // rcpm.c - Freescale QorIQ RCPM driver  // -// Copyright 2019 NXP
> +// Copyright 2019-2020 NXP
> +// Copyright 2020 Puresoftware Ltd.
>  //
>  // Author: Ran Wang 
> 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -57,8 +59,13 @@ static int rcpm_pm_prepare(struct device *dev)
>   rcpm->wakeup_cells + 1);
> 
>   /*  Wakeup source should refer to current rcpm device */
> - if (ret || (np->phandle != value[0]))
> - continue;
> + if (is_acpi_node(dev->fwnode)) {
> + if (ret)
> + continue;
> + } else {
> + if (ret || (np->phandle != value[0]))
> + continue;
> + }
>   /* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines the
>* number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
> @@ -139,10 +146,19 @@ static const struct of_device_id rcpm_of_match[] =
> {  };  MODULE_DEVICE_TABLE(of, rcpm_of_match);
> 
> +#ifdef CONFIG_ACPI
> +static const struct acpi_device_id rcpm_acpi_match[] = {
> + { "NXP0015", },
> + { }
> +};
> +MODULE_DEVICE_TABLE(acpi, rcpm_acpi_match); #endif
> +
>  static struct platform_driver rcpm_driver = {
>   .driver = {
>   .name = "rcpm",
>   .of_match_table = rcpm_of_match,
> + .acpi_match_table = ACPI_PTR(rcpm_acpi_match),
>   .pm = _pm_ops,
>   },
>   .probe = rcpm_probe,
> --
> 2.17.1



[PATCH v5] soc: fsl: enable acpi support in RCPM driver

2020-09-03 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v5:
 - Fix panic when dev->of_node is null

Change in v4:
 - Make commit subject more accurate
 - Remove unrelated new blank line

Change in v3:
 - Add #ifdef CONFIG_ACPI for acpi_device_id
 - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids

Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..58870f4 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -56,10 +57,14 @@ static int rcpm_pm_prepare(struct device *dev)
"fsl,rcpm-wakeup", value,
rcpm->wakeup_cells + 1);
 
-   /*  Wakeup source should refer to current rcpm device */
-   if (ret || (np->phandle != value[0]))
+   if (ret)
continue;
 
+   if (is_of_node(dev->fwnode))
+   /*  Should refer to current rcpm device */
+   if (np->phandle != value[0])
+   continue;
+
/* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines the
 * number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
 * of wakeup source IP contains an integer array: 

[PATCH v4] soc: fsl: enable acpi support in RCPM driver

2020-08-19 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v4:
 - Make commit subject more accurate
 - Remove unrelated new blank line

Change in v3:
 - Add #ifdef CONFIG_ACPI for acpi_device_id
 - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids

Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..b5aa6db 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -139,10 +140,19 @@ static const struct of_device_id rcpm_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, rcpm_of_match);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id rcpm_acpi_ids[] = {
+   {"NXP0015",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, rcpm_acpi_ids);
+#endif
+
 static struct platform_driver rcpm_driver = {
.driver = {
.name = "rcpm",
.of_match_table = rcpm_of_match,
+   .acpi_match_table = ACPI_PTR(rcpm_acpi_ids),
.pm = _pm_ops,
},
.probe = rcpm_probe,
-- 
2.7.4



RE: [PATCH v3] soc: fsl: enable acpi support

2020-08-19 Thread Ran Wang
Hi Christophe

On Wednesday, August 19, 2020 2:48 PM, Christophe Leroy wrote:
> 
> 
> 
> Le 19/08/2020 à 06:00, Ran Wang a écrit :
> > From: Peng Ma 
> >
> > This patch enables ACPI support in RCPM driver.
> 
> Can you change the subject to "soc: fsl: enable acpi support in RCPM driver" ?

Sure.

> >
> > Signed-off-by: Peng Ma 
> > Signed-off-by: Ran Wang 
> > ---
> > Change in v3:
> >   - Add #ifdef CONFIG_ACPI for acpi_device_id
> >   - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids
> >
> > Change in v2:
> >   - Update acpi_device_id to fix conflict with other driver
> >
> >   drivers/soc/fsl/rcpm.c | 13 -
> >   1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c index
> > a093dbe..55d1d73 100644
> > --- a/drivers/soc/fsl/rcpm.c
> > +++ b/drivers/soc/fsl/rcpm.c
> > @@ -2,7 +2,7 @@
> >   //
> >   // rcpm.c - Freescale QorIQ RCPM driver
> >   //
> > -// Copyright 2019 NXP
> > +// Copyright 2019-2020 NXP
> >   //
> >   // Author: Ran Wang 
> >
> > @@ -13,6 +13,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >
> >   #define RCPM_WAKEUP_CELL_MAX_SIZE 7
> >
> > @@ -125,6 +126,7 @@ static int rcpm_probe(struct platform_device
> > *pdev)
> >
> > ret = device_property_read_u32(>dev,
> > "#fsl,rcpm-wakeup-cells", >wakeup_cells);
> > +
> 
> This blank line addition is unrelated to the patch and shouldn't be there.

Got it, will remove this in v4, thanks.

Regards,
Ran

> Christophe
> 
> > if (ret)
> > return ret;
> >
> > @@ -139,10 +141,19 @@ static const struct of_device_id rcpm_of_match[]
> = {
> >   };
> >   MODULE_DEVICE_TABLE(of, rcpm_of_match);
> >
> > +#ifdef CONFIG_ACPI
> > +static const struct acpi_device_id rcpm_acpi_ids[] = {
> > +   {"NXP0015",},
> > +   { }
> > +};
> > +MODULE_DEVICE_TABLE(acpi, rcpm_acpi_ids); #endif
> > +
> >   static struct platform_driver rcpm_driver = {
> > .driver = {
> > .name = "rcpm",
> > .of_match_table = rcpm_of_match,
> > +   .acpi_match_table = ACPI_PTR(rcpm_acpi_ids),
> > .pm = _pm_ops,
> > },
> > .probe = rcpm_probe,
> >


[PATCH v3] soc: fsl: enable acpi support

2020-08-18 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v3:
 - Add #ifdef CONFIG_ACPI for acpi_device_id
 - Rename rcpm_acpi_imx_ids to rcpm_acpi_ids

Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..55d1d73 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -125,6 +126,7 @@ static int rcpm_probe(struct platform_device *pdev)
 
ret = device_property_read_u32(>dev,
"#fsl,rcpm-wakeup-cells", >wakeup_cells);
+
if (ret)
return ret;
 
@@ -139,10 +141,19 @@ static const struct of_device_id rcpm_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, rcpm_of_match);
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id rcpm_acpi_ids[] = {
+   {"NXP0015",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, rcpm_acpi_ids);
+#endif
+
 static struct platform_driver rcpm_driver = {
.driver = {
.name = "rcpm",
.of_match_table = rcpm_of_match,
+   .acpi_match_table = ACPI_PTR(rcpm_acpi_ids),
.pm = _pm_ops,
},
.probe = rcpm_probe,
-- 
2.7.4



[PATCH v2] soc: fsl: enable acpi support

2020-08-18 Thread Ran Wang
From: Peng Ma 

This patch enables ACPI support in RCPM driver.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
Change in v2:
 - Update acpi_device_id to fix conflict with other driver

 drivers/soc/fsl/rcpm.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
index a093dbe..230c232 100644
--- a/drivers/soc/fsl/rcpm.c
+++ b/drivers/soc/fsl/rcpm.c
@@ -2,7 +2,7 @@
 //
 // rcpm.c - Freescale QorIQ RCPM driver
 //
-// Copyright 2019 NXP
+// Copyright 2019-2020 NXP
 //
 // Author: Ran Wang 
 
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RCPM_WAKEUP_CELL_MAX_SIZE  7
 
@@ -125,6 +126,7 @@ static int rcpm_probe(struct platform_device *pdev)
 
ret = device_property_read_u32(>dev,
"#fsl,rcpm-wakeup-cells", >wakeup_cells);
+
if (ret)
return ret;
 
@@ -139,10 +141,17 @@ static const struct of_device_id rcpm_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, rcpm_of_match);
 
+static const struct acpi_device_id rcpm_imx_acpi_ids[] = {
+   {"NXP0015",},
+   { }
+};
+MODULE_DEVICE_TABLE(acpi, rcpm_imx_acpi_ids);
+
 static struct platform_driver rcpm_driver = {
.driver = {
.name = "rcpm",
.of_match_table = rcpm_of_match,
+   .acpi_match_table = ACPI_PTR(rcpm_imx_acpi_ids),
.pm = _pm_ops,
},
.probe = rcpm_probe,
-- 
2.7.4



[PATCH] rtc: fsl-ftm-alarm: update acpi device id

2020-08-18 Thread Ran Wang
From: Peng Ma 

Original device id would conflict with crypto driver, change it.

Signed-off-by: Peng Ma 
Signed-off-by: Ran Wang 
---
 drivers/rtc/rtc-fsl-ftm-alarm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c
index 68f0a18..48d3b38 100644
--- a/drivers/rtc/rtc-fsl-ftm-alarm.c
+++ b/drivers/rtc/rtc-fsl-ftm-alarm.c
@@ -3,7 +3,7 @@
  * Freescale FlexTimer Module (FTM) alarm device driver.
  *
  * Copyright 2014 Freescale Semiconductor, Inc.
- * Copyright 2019 NXP
+ * Copyright 2019-2020 NXP
  *
  */
 
@@ -312,7 +312,7 @@ static const struct of_device_id ftm_rtc_match[] = {
 };
 
 static const struct acpi_device_id ftm_imx_acpi_ids[] = {
-   {"NXP0011",},
+   {"NXP0014",},
{ }
 };
 MODULE_DEVICE_TABLE(acpi, ftm_imx_acpi_ids);
-- 
2.7.4



[PATCH] arm64: dts: ls1043a: update USB nodes status to match board config

2020-07-07 Thread Ran Wang
ls1043a-rdb and ls1043a-qds board’s default HW config (such as
pin mux selection) would not enable some USB controllers’
data path, which causing over-current detected on those
controllers. This will hit the case of ‘xhci driver prevent bus suspend
if a root hub port detected over-current condition’, causing system
failed to be suspended. So disable them in device tree to resolve this
issue.

Signed-off-by: Ran Wang 
---
 arch/arm64/boot/dts/freescale/fsl-ls1043a-qds.dts | 4 
 arch/arm64/boot/dts/freescale/fsl-ls1043a-rdb.dts | 8 
 arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi| 3 +++
 3 files changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a-qds.dts 
b/arch/arm64/boot/dts/freescale/fsl-ls1043a-qds.dts
index 1aac81d..fea167d 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a-qds.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a-qds.dts
@@ -148,4 +148,8 @@
};
 };
 
+ {
+   status = "okay";
+};
+
 #include "fsl-ls1043-post.dtsi"
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a-rdb.dts 
b/arch/arm64/boot/dts/freescale/fsl-ls1043a-rdb.dts
index bfa9d95..3516af4 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a-rdb.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a-rdb.dts
@@ -209,3 +209,11 @@
fsl,tdm-interface;
};
 };
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
index 3b641bd..c6d8dcb 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
@@ -677,6 +677,7 @@
snps,quirk-frame-length-adjustment = <0x20>;
snps,dis_rxdet_inp3_quirk;
snps,incr-burst-type-adjustment = <1>, <4>, <8>, <16>;
+   status = "disabled";
};
 
usb1: usb3@300 {
@@ -687,6 +688,7 @@
snps,quirk-frame-length-adjustment = <0x20>;
snps,dis_rxdet_inp3_quirk;
snps,incr-burst-type-adjustment = <1>, <4>, <8>, <16>;
+   status = "disabled";
};
 
usb2: usb3@310 {
@@ -697,6 +699,7 @@
snps,quirk-frame-length-adjustment = <0x20>;
snps,dis_rxdet_inp3_quirk;
snps,incr-burst-type-adjustment = <1>, <4>, <8>, <16>;
+   status = "disabled";
};
 
sata: sata@320 {
-- 
2.7.4



RE: [PATCH 2/2] USB: phy: fsl-usb: remove character device usage

2020-07-02 Thread Ran Wang
Hi

On Thursday, July 2, 2020 5:08 PM, Peter Chen wrote
> >
> > No idea why this driver is using a char device node, statically
> > allocated, with no dynamic allocation or hook up with devtmpfs, along
> > with a reserverd major number, for "special" operations, not all of which 
> > ever
> were implemented.
> >
> > So just rip it out, as no one must be using it because no modern
> > system will ever actually create the /dev/ node it needs.
> >
> 
> Add related people from NXP.
> 

Reviewed-by: Ran Wang 

Regards,
Ran





RE: [PATCH 1/2] USB: phy: fsl-usb: remove sysfs abuse

2020-07-02 Thread Ran Wang
Hi,

On Thursday, July 2, 2020 5:07 PM, wrote:
> >
> > This file has a HUGE debugging sysfs file that spews out a lot of
> > information all at once, which violates the one-value-per-file rule
> > for sysfs.  If this is really needed, it should go into debugfs, but
> > given the age of this driver, I strongly doubt anyone is using it anymore.
> >
> > So just remove the file entirely, it was never documented, so
> > obviously, no one actually needed it :)
> >
> 
> 
> Add related people from NXP.

Thanks for having me. Agree to clean this up for above reasons.

Regards,
Ran

> Peter
> 
> > Cc: Felipe Balbi 
> > Signed-off-by: Greg Kroah-Hartman 
> > ---
> >  drivers/usb/phy/phy-fsl-usb.c | 93
> > ---
> >  1 file changed, 93 deletions(-)
> >
> > diff --git a/drivers/usb/phy/phy-fsl-usb.c
> > b/drivers/usb/phy/phy-fsl-usb.c index
> > b451f4695f3f..93d2257aeec8 100644
> > --- a/drivers/usb/phy/phy-fsl-usb.c
> > +++ b/drivers/usb/phy/phy-fsl-usb.c
> > @@ -957,98 +957,6 @@ int usb_otg_start(struct platform_device *pdev)
> > return 0;
> >  }
> >
> > -/*
> > - * state file in sysfs
> > - */
> > -static ssize_t show_fsl_usb2_otg_state(struct device *dev,
> > -  struct device_attribute *attr, char *buf)
> > -{
> > -   struct otg_fsm *fsm = _otg_dev->fsm;
> > -   char *next = buf;
> > -   unsigned size = PAGE_SIZE;
> > -   int t;
> > -
> > -   mutex_lock(>lock);
> > -
> > -   /* basic driver infomation */
> > -   t = scnprintf(next, size,
> > -   DRIVER_DESC "\n" "fsl_usb2_otg version: %s\n\n",
> > -   DRIVER_VERSION);
> > -   size -= t;
> > -   next += t;
> > -
> > -   /* Registers */
> > -   t = scnprintf(next, size,
> > -   "OTGSC:   0x%08x\n"
> > -   "PORTSC:  0x%08x\n"
> > -   "USBMODE: 0x%08x\n"
> > -   "USBCMD:  0x%08x\n"
> > -   "USBSTS:  0x%08x\n"
> > -   "USBINTR: 0x%08x\n",
> > -   fsl_readl(_dr_regs->otgsc),
> > -   fsl_readl(_dr_regs->portsc),
> > -   fsl_readl(_dr_regs->usbmode),
> > -   fsl_readl(_dr_regs->usbcmd),
> > -   fsl_readl(_dr_regs->usbsts),
> > -   fsl_readl(_dr_regs->usbintr));
> > -   size -= t;
> > -   next += t;
> > -
> > -   /* State */
> > -   t = scnprintf(next, size,
> > - "OTG state: %s\n\n",
> > - usb_otg_state_string(fsl_otg_dev->phy.otg->state));
> > -   size -= t;
> > -   next += t;
> > -
> > -   /* State Machine Variables */
> > -   t = scnprintf(next, size,
> > -   "a_bus_req: %d\n"
> > -   "b_bus_req: %d\n"
> > -   "a_bus_resume: %d\n"
> > -   "a_bus_suspend: %d\n"
> > -   "a_conn: %d\n"
> > -   "a_sess_vld: %d\n"
> > -   "a_srp_det: %d\n"
> > -   "a_vbus_vld: %d\n"
> > -   "b_bus_resume: %d\n"
> > -   "b_bus_suspend: %d\n"
> > -   "b_conn: %d\n"
> > -   "b_se0_srp: %d\n"
> > -   "b_ssend_srp: %d\n"
> > -   "b_sess_vld: %d\n"
> > -   "id: %d\n",
> > -   fsm->a_bus_req,
> > -   fsm->b_bus_req,
> > -   fsm->a_bus_resume,
> > -   fsm->a_bus_suspend,
> > -   fsm->a_conn,
> > -   fsm->a_sess_vld,
> > -   fsm->a_srp_det,
> > -   fsm->a_vbus_vld,
> > -   fsm->b_bus_resume,
> > -   fsm->b_bus_suspend,
> > -   fsm->b_conn,
> > -   fsm->b_se0_srp,
> > -   fsm->b_ssend_srp,
> > -   fsm->b_sess_vld,
> > -   fsm->id);
> > -   size -= t;
> > -   next += t;
> > -
> > -   mutex_unlock(>lock);
> > -
> > -   return PAGE_SIZE - size;
> > -}
> > -
> > -static DEVICE_ATTR(fsl_usb2_otg_state, S_IRUGO,
> > show_fsl_usb2_otg_state, NULL);
> > -
> > -static struct attribute *fsl_otg_attrs[] = {
> > -   _attr_fsl_usb2_otg_state.attr,
> > -   NULL,
> > -};
> > -ATTRIBUTE_GROUPS(fsl_otg);
> > -
> >  /* Char driver interface to control some OTG input */
> >
> >  /*
> > @@ -1167,7 +1075,6 @@ struct platform_driver fsl_otg_driver = {
> > .driver = {
> > .name = driver_name,
> > .owner = THIS_MODULE,
> > -   .dev_groups = fsl_otg_groups,
> > },
> >  };
> >
> > --
> > 2.27.0



RE: [kbuild] drivers/usb/gadget/udc/fsl_udc_core.c:1055 fsl_ep_fifo_status() error: we previously assumed '_ep->desc' could be null (see line 1055)

2020-06-22 Thread Ran Wang
Hi Dan

On Tuesday, June 23, 2020 2:20 AM, Dan Carpenter wrote:



> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
> Reported-by: Dan Carpenter 
> 
> New smatch warnings:
> drivers/usb/gadget/udc/fsl_udc_core.c:1055 fsl_ep_fifo_status() error: we
> previously assumed '_ep->desc' could be null (see line 1055)
> 



> 
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1047  static int fsl_ep_fifo_status(struct usb_ep *_ep)
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1048  {
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1049  struct fsl_ep *ep;
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1050  struct fsl_udc *udc;
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1051  int size = 0;
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1052  u32 bitmask;
> 6414e94c203d92 drivers/usb/gadget/fsl_udc_core.c Li Yang
> 2011-11-23  1053  struct ep_queue_head *qh;
> 2ea6698d7b9266 drivers/usb/gadget/fsl_udc_core.c Anatolij Gustschin
> 2011-04-18  1054
> 75eaa498c99eeb drivers/usb/gadget/udc/fsl_udc_core.c Nikhil Badola
> 2019-10-21 @1055  if (!_ep || _ep->desc || 
> !(_ep->desc->bEndpointAddress&0xF))
>  ^ Reversed NULL test.  This 
> will always return -ENODEV.  (Or possibly crash.  But I suspect it always 
> returns -ENODEV instead of crashing).

So the kernel test reports warning in case of '_ep->desc is null', right? 

My understanding is that this judgement would return -ENODEV when
executing '... || _ep-desc ||..' and never execute 
'_ep->desc->bEndpointAddress' part,
so crash would not happen, am I right?

> The container_of() macro doesn't dereference anything, btw.  It just does
> pointer math.  I think it would be cleaner to use ep_index() like the original
> code did.  In other words, perhaps it would look best written like this:

Yes, I agree using ep_index() would be easier for reading, just feel a little 
bit
uncomfortable to mix checking on _ep and it's container (ep) in the same line.

>   ep = container_of(_ep, struct fsl_ep, ep);
>   if (!_ep || !_ep->desc || ep_index(ep) == 0)
> 
> 

BTW, Nikhil Badola has left NXP (Freesale), so his email address is invalid now.

Thanks & Regards,
Ran


[PATCH v2] rtc: fsl-ftm-alarm: fix freeze(s2idle) failed to wake

2020-06-01 Thread Ran Wang
Use dev_pm_set_wake_irq() instead of flag IRQF_NO_SUSPEND to enable
wakeup system feature for both freeze(s2idle) and mem(deep).

Signed-off-by: Ran Wang 
---
Change in v2:
 - Remove wakeup-source control since the irq should be able to wakeup.
   And this is not the case that RTC interrupt line is not connected
   directly to SoC.

 drivers/rtc/rtc-fsl-ftm-alarm.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c
index 756af62..6775205 100644
--- a/drivers/rtc/rtc-fsl-ftm-alarm.c
+++ b/drivers/rtc/rtc-fsl-ftm-alarm.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define FTM_SC_CLK(c)  ((c) << FTM_SC_CLK_MASK_SHIFT)
 
@@ -274,7 +275,7 @@ static int ftm_rtc_probe(struct platform_device *pdev)
}
 
ret = devm_request_irq(>dev, irq, ftm_rtc_alarm_interrupt,
-  IRQF_NO_SUSPEND, dev_name(>dev), rtc);
+  0, dev_name(>dev), rtc);
if (ret < 0) {
dev_err(>dev, "failed to request irq\n");
return ret;
@@ -287,6 +288,9 @@ static int ftm_rtc_probe(struct platform_device *pdev)
rtc->rtc_dev->ops = _rtc_ops;
 
device_init_wakeup(>dev, true);
+   ret = dev_pm_set_wake_irq(>dev, irq);
+   if (ret)
+   dev_err(>dev, "failed to enable irq wake\n");
 
ret = rtc_register_device(rtc->rtc_dev);
if (ret) {
-- 
2.7.4



[PATCH 1/2] dt-bindings: rtc: add wakeup-source for FlexTimer

2020-05-29 Thread Ran Wang
Signed-off-by: Ran Wang 
---
 Documentation/devicetree/bindings/rtc/rtc-fsl-ftm-alarm.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/rtc/rtc-fsl-ftm-alarm.txt 
b/Documentation/devicetree/bindings/rtc/rtc-fsl-ftm-alarm.txt
index fffac74..d7c482c 100644
--- a/Documentation/devicetree/bindings/rtc/rtc-fsl-ftm-alarm.txt
+++ b/Documentation/devicetree/bindings/rtc/rtc-fsl-ftm-alarm.txt
@@ -20,6 +20,7 @@ Required properties:
 Optional properties:
 - big-endian: If the host controller is big-endian mode, specify this property.
   The default endian mode is little-endian.
+- wakeup-source: Enable it as a wakeup source
 
 Example:
 rcpm: rcpm@1e34040 {
@@ -32,5 +33,6 @@ ftm_alarm0: timer@280 {
compatible = "fsl,ls1088a-ftm-alarm";
reg = <0x0 0x280 0x0 0x1>;
fsl,rcpm-wakeup = < 0x0 0x0 0x0 0x0 0x4000 0x0>;
+   wakeup-source;
interrupts = <0 44 4>;
 };
-- 
2.7.4



[PATCH 2/2] rtc: fsl-ftm-alarm: fix freeze(s2idle) doesnot wake

2020-05-29 Thread Ran Wang
Use dev_pm_set_wake_irq() instead of flag IRQF_NO_SUSPEND to enable
wakeup system feature for both freeze(s2idle) and mem(deep).

Use property 'wakeup-source' to control this feature.

Signed-off-by: Ran Wang 
---
 drivers/rtc/rtc-fsl-ftm-alarm.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-fsl-ftm-alarm.c b/drivers/rtc/rtc-fsl-ftm-alarm.c
index 756af62..c6945d84 100644
--- a/drivers/rtc/rtc-fsl-ftm-alarm.c
+++ b/drivers/rtc/rtc-fsl-ftm-alarm.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define FTM_SC_CLK(c)  ((c) << FTM_SC_CLK_MASK_SHIFT)
 
@@ -41,6 +42,7 @@ struct ftm_rtc {
struct rtc_device *rtc_dev;
void __iomem *base;
bool big_endian;
+   bool wakeup;
u32 alarm_freq;
 };
 
@@ -267,6 +269,9 @@ static int ftm_rtc_probe(struct platform_device *pdev)
return PTR_ERR(rtc->base);
}
 
+   rtc->wakeup =
+   device_property_read_bool(>dev, "wakeup-source");
+
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_err(>dev, "can't get irq number\n");
@@ -274,7 +279,7 @@ static int ftm_rtc_probe(struct platform_device *pdev)
}
 
ret = devm_request_irq(>dev, irq, ftm_rtc_alarm_interrupt,
-  IRQF_NO_SUSPEND, dev_name(>dev), rtc);
+  0, dev_name(>dev), rtc);
if (ret < 0) {
dev_err(>dev, "failed to request irq\n");
return ret;
@@ -286,7 +291,10 @@ static int ftm_rtc_probe(struct platform_device *pdev)
rtc->alarm_freq = (u32)FIXED_FREQ_CLK / (u32)MAX_FREQ_DIV;
rtc->rtc_dev->ops = _rtc_ops;
 
-   device_init_wakeup(>dev, true);
+   device_init_wakeup(>dev, rtc->wakeup);
+   ret = dev_pm_set_wake_irq(>dev, irq);
+   if (ret)
+   dev_err(>dev, "irq wake enable failed.\n");
 
ret = rtc_register_device(rtc->rtc_dev);
if (ret) {
-- 
2.7.4



RE: [PATCH v9 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-10-23 Thread Ran Wang
Hi Rafael,

On Wednesday, October 23, 2019 17:07, Rafael J. Wysocki wrote:
> 
> On Wed, Oct 23, 2019 at 10:24 AM Ran Wang  wrote:
> >
> > Some user might want to go through all registered wakeup sources and
> > doing things accordingly. For example, SoC PM driver might need to do
> > HW programming to prevent powering down specific IP which wakeup
> > source depending on. So add this API to help walk through all
> > registered wakeup source objects on that list and return them one by one.
> >
> > Signed-off-by: Ran Wang 
> > Tested-by: Leonard Crestez 
> 
> OK, thanks for making all of the requested changes:

Thanks for your patient direction :)
Actually Leo and me planed to have a f2f discussion with you about this patch on
LPC 2019 but unfortunately missed the opportunity finally (v6 review was
pending at time).
 
> Reviewed-by: Rafael J. Wysocki 
> 
> and please feel free to push this through the appropriate arch/platform tree.

Yes, we will do this later.

> Alternatively, please let me know if you want me to take this series, but 
> then I
> need an ACK from the appropriate
> maintainer(s) on patch 3.

Thanks again, I will wait Leo's comment on patch 3.

Regards,
Ran



RE: [PATCH v9 3/3] soc: fsl: add RCPM driver

2019-10-23 Thread Ran Wang
Hi Rafael,

On Wednesday, October 23, 2019 17:12, Rafael J. Wysocki wrote:
> 
> On Wed, Oct 23, 2019 at 10:24 AM Ran Wang  wrote:
> >
> > The NXP's QorIQ Processors based on ARM Core have RCPM module (Run
> > Control and Power Management), which performs system level tasks
> > associated with power management such as wakeup source control.
> >
> > This driver depends on PM wakeup source framework which help to
> > collect wake information.
> >
> > Signed-off-by: Ran Wang 
> > ---
> > Change in v9:
> > - Add kerneldoc for rcpm_pm_prepare().
> > - Use pr_debug() to replace dev_info(), to print message when decide
> >   skip current wakeup object, this is mainly for debugging (in order
> >   to detect potential improper implementation on device tree which
> >   might cause this skip).
> > - Refactor looping implementation in rcpm_pm_prepare(), add more
> >   comments to help clarify.
> >
> > Change in v8:
> > - Adjust related API usage to meet wakeup.c's update in patch 1/3.
> > - Add sanity checking for the case of ws->dev or ws->dev->parent
> >   is null.
> >

> > +
> > +   /*  Wakeup source should refer to current rcpm device */
> > +   if (ret || (np->phandle != value[0])) {
> > +   pr_debug("%s doesn't refer to this rcpm\n",
> > + ws->name);
> 
> I'm still quite unsure why it is useful to print this message instead of 
> printing one
> when the wakeup source does match (there may be many wakeup source
> objects you don't care about in principle), but whatever.

OK, my previous idea was that user might likely mis-understand related 
description in
bindings when adding node and property "fsl,rcpm-wakeup". Add this print might
help him/her to get alerted that RCPM driver doesn't successfully parsing info 
which
they didn't expect. Currently on LS1088ARDB board, I can only see one wakeup 
source
the RCPM driver doesn’t need to care.

> > +   continue;
> > +   }
> > +
> > +   /* Property "#fsl,rcpm-wakeup-cells" of rcpm node defines 
> > the
> > +* number of IPPDEXPCR register cells, and "fsl,rcpm-wakeup"
> > +* of wakeup source IP contains an integer array:  > to
> > +* RCPM node, IPPDEXPCR0 setting, IPPDEXPCR1 setting,
> > +* IPPDEXPCR2 setting, etc>.
> > +*
> > +* So we will go thought them and do programming accordngly.
> > +*/
> > +   for (i = 0; i < rcpm->wakeup_cells; i++) {
> > +   u32 tmp = value[i + 1];
> > +   void __iomem *address = base + i * 4;
> > +
> > +   if (!tmp)
> > +   continue;
> > +
> > +   /* We can only OR related bits */
> > +   if (rcpm->little_endian) {
> > +   tmp |= ioread32(address);
> > +   iowrite32(tmp, address);
> > +   } else {
> > +   tmp |= ioread32be(address);
> > +   iowrite32be(tmp, address);
> > +   }
> > +   }
> > +   }
> > +
> > +   wakeup_sources_read_unlock(idx);
> > +
> > +   return 0;
> > +}
> > +
> > +static const struct dev_pm_ops rcpm_pm_ops = {
> > +   .prepare =  rcpm_pm_prepare,
> > +};
> 
> For the above:
> 
> Reviewed-by: Rafael J. Wysocki 

Thanks for your time.

Regards,
Ran


[PATCH v9 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-10-23 Thread Ran Wang
By default, QorIQ SoC's RCPM register block is Big Endian. But
there are some exceptions, such as LS1088A and LS2088A, are
Little Endian. So add this optional property to help identify
them.

Actually LS2021A and other Layerscapes won't totally follow Chassis
2.1, so separate them from powerpc SoC.

Signed-off-by: Ran Wang 
Reviewed-by: Rob Herring 
---
Change in v9:
- None

Change in v8:
- None.

Change in v7:
- None.

Change in v6:
- None.

Change in v5:
- Add 'Reviewed-by: Rob Herring ' to commit message.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.

Change in v3:
- None.

Change in v2:
- None.

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index e284e4e..5a33619 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -5,7 +5,7 @@ and power management.
 
 Required properites:
   - reg : Offset and length of the register set of the RCPM block.
-  - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
+  - #fsl,rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
fsl,rcpm-wakeup property.
   - compatible : Must contain a chip-specific RCPM block compatible string
and (if applicable) may contain a chassis-version RCPM compatible
@@ -20,6 +20,7 @@ Required properites:
* "fsl,qoriq-rcpm-1.0": for chassis 1.0 rcpm
* "fsl,qoriq-rcpm-2.0": for chassis 2.0 rcpm
* "fsl,qoriq-rcpm-2.1": for chassis 2.1 rcpm
+   * "fsl,qoriq-rcpm-2.1+": for chassis 2.1+ rcpm
 
 All references to "1.0" and "2.0" refer to the QorIQ chassis version to
 which the chip complies.
@@ -27,14 +28,19 @@ Chassis Version Example Chips
 ------
 1.0p4080, p5020, p5040, p2041, p3041
 2.0t4240, b4860, b4420
-2.1t1040, ls1021
+2.1t1040,
+2.1+   ls1021a, ls1012a, ls1043a, ls1046a
+
+Optional properties:
+ - little-endian : RCPM register block is Little Endian. Without it RCPM
+   will be Big Endian (default case).
 
 Example:
 The RCPM node for T4240:
rcpm: global-utilities@e2000 {
compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0";
reg = <0xe2000 0x1000>;
-   fsl,#rcpm-wakeup-cells = <2>;
+   #fsl,rcpm-wakeup-cells = <2>;
};
 
 * Freescale RCPM Wakeup Source Device Tree Bindings
@@ -44,7 +50,7 @@ can be used as a wakeup source.
 
   - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR
register cells. The number of IPPDEXPCR register cells is defined in
-   "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is
+   "#fsl,rcpm-wakeup-cells" in the rcpm node. The first register cell is
the bit mask that should be set in IPPDEXPCR0, and the second register
cell is for IPPDEXPCR1, and so on.
 
-- 
2.7.4



[PATCH v9 3/3] soc: fsl: add RCPM driver

2019-10-23 Thread Ran Wang
The NXP's QorIQ Processors based on ARM Core have RCPM module
(Run Control and Power Management), which performs system level
tasks associated with power management such as wakeup source control.

This driver depends on PM wakeup source framework which help to
collect wake information.

Signed-off-by: Ran Wang 
---
Change in v9:
- Add kerneldoc for rcpm_pm_prepare().
- Use pr_debug() to replace dev_info(), to print message when decide
  skip current wakeup object, this is mainly for debugging (in order
  to detect potential improper implementation on device tree which
  might cause this skip).
- Refactor looping implementation in rcpm_pm_prepare(), add more
  comments to help clarify.

Change in v8:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.
- Add sanity checking for the case of ws->dev or ws->dev->parent
  is null.

Change in v7:
- Replace 'ws->dev' with 'ws->dev->parent' to get aligned with
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs")
- Remove '+obj-y += ftm_alarm.o' since it is wrong.
- Cosmetic work.

Change in v6:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.

Change in v5:
- Fix v4 regression of the return value of wakeup_source_get_next()
didn't pass to ws in while loop.
- Rename wakeup_source member 'attached_dev' to 'dev'.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Remove extra ',' in author line of rcpm.c
- Update usage of wakeup_source_get_next() to be less confusing to the
reader, code logic remain the same.

Change in v3:
- Some whitespace ajdustment.

Change in v2:
- Rebase Kconfig and Makefile update to latest mainline.

 drivers/soc/fsl/Kconfig  |   8 +++
 drivers/soc/fsl/Makefile |   1 +
 drivers/soc/fsl/rcpm.c   | 148 +++
 3 files changed, 157 insertions(+)
 create mode 100644 drivers/soc/fsl/rcpm.c

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index f9ad8ad..4918856 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -40,4 +40,12 @@ config DPAA2_CONSOLE
  /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
  which can be used to dump the Management Complex and AIOP
  firmware logs.
+
+config FSL_RCPM
+   bool "Freescale RCPM support"
+   depends on PM_SLEEP
+   help
+ The NXP QorIQ Processors based on ARM Core have RCPM module
+ (Run Control and Power Management), which performs all device-level
+ tasks associated with power management, such as wakeup source control.
 endmenu
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 71dee8d..906f1cd 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_RCPM) += rcpm.o
 obj-$(CONFIG_FSL_GUTS) += guts.o
 obj-$(CONFIG_FSL_MC_DPIO)  += dpio/
 obj-$(CONFIG_DPAA2_CONSOLE)+= dpaa2-console.o
diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
new file mode 100644
index 000..9378073
--- /dev/null
+++ b/drivers/soc/fsl/rcpm.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rcpm.c - Freescale QorIQ RCPM driver
+//
+// Copyright 2019 NXP
+//
+// Author: Ran Wang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RCPM_WAKEUP_CELL_MAX_SIZE  7
+
+struct rcpm {
+   unsigned intwakeup_cells;
+   void __iomem*ippdexpcr_base;
+   boollittle_endian;
+};
+
+/**
+ * rcpm_pm_prepare - performs device-level tasks associated with power
+ * management, such as programming related to the wakeup source control.
+ * @dev: Device to handle.
+ *
+ */
+static int rcpm_pm_prepare(struct device *dev)
+{
+   int i, ret, idx;
+   void __iomem *base;
+   struct wakeup_source*ws;
+   struct rcpm *rcpm;
+   struct device_node  *np = dev->of_node;
+   u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1];
+
+   rcpm = dev_get_drvdata(dev);
+   if (!rcpm)
+   return -EINVAL;
+
+   base = rcpm->ippdexpcr_base;
+   idx = wakeup_sources_read_lock();
+
+   /* Begin with first registered wakeup source */
+   for_each_wakeup_source(ws) {
+
+   /* skip object which is not attached to device */
+   if (!ws->dev || !ws->dev->parent)
+   continue;
+
+   ret = device_property_read_u32_array(ws->dev->parent,
+   "fsl,rcpm-wa

[PATCH v9 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-10-23 Thread Ran Wang
Some user might want to go through all registered wakeup sources
and doing things accordingly. For example, SoC PM driver might need to
do HW programming to prevent powering down specific IP which wakeup
source depending on. So add this API to help walk through all registered
wakeup source objects on that list and return them one by one.

Signed-off-by: Ran Wang 
Tested-by: Leonard Crestez 
---
Change in v9:
- Supplement comments for wakeup_sources_read_lock(),
  wakeup_sources_read_unlock, wakeup_sources_walk_start and
  wakeup_sources_walk_next().

Change in v8:
- Rename wakeup_source_get_next() to wakeup_sources_walk_next().
- Add wakeup_sources_read_lock() to take over locking job of
  wakeup_source_get_star().
- Rename wakeup_source_get_start() to wakeup_sources_walk_start().
- Replace wakeup_source_get_stop() with wakeup_sources_read_unlock().
- Define macro for_each_wakeup_source(ws).

Change in v7:
- Remove define of member *dev in wake_irq to fix conflict with commit 
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs"), user 
will use ws->dev->parent instead.
- Remove '#include ' because it is not used.

Change in v6:
- Add wakeup_source_get_star() and wakeup_source_get_stop() to aligned 
with wakeup_sources_stats_seq_start/nex/stop.

Change in v5:
- Update commit message, add decription of walk through all wakeup
source objects.
- Add SCU protection in function wakeup_source_get_next().
- Rename wakeup_source member 'attached_dev' to 'dev' and move it up
(before wakeirq).

Change in v4:
- None.

Change in v3:
- Adjust indentation of *attached_dev;.

Change in v2:
- None.

 drivers/base/power/wakeup.c | 54 +
 include/linux/pm_wakeup.h   |  9 
 2 files changed, 63 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 5817b51..70a9edb 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -248,6 +248,60 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
 
 /**
+ * wakeup_sources_read_lock - Lock wakeup source list for read.
+ *
+ * Returns an index of srcu lock for struct wakeup_srcu.
+ * This index must be passed to the matching wakeup_sources_read_unlock().
+ */
+int wakeup_sources_read_lock(void)
+{
+   return srcu_read_lock(_srcu);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_read_lock);
+
+/**
+ * wakeup_sources_read_unlock - Unlock wakeup source list.
+ * @idx: return value from corresponding wakeup_sources_read_lock()
+ */
+void wakeup_sources_read_unlock(int idx)
+{
+   srcu_read_unlock(_srcu, idx);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_read_unlock);
+
+/**
+ * wakeup_sources_walk_start - Begin a walk on wakeup source list
+ *
+ * Returns first object of the list of wakeup sources.
+ *
+ * Note that to be safe, wakeup sources list needs to be locked by calling
+ * wakeup_source_read_lock() for this.
+ */
+struct wakeup_source *wakeup_sources_walk_start(void)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_entry_rcu(ws_head->next, struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_walk_start);
+
+/**
+ * wakeup_sources_walk_next - Get next wakeup source from the list
+ * @ws: Previous wakeup source object
+ *
+ * Note that to be safe, wakeup sources list needs to be locked by calling
+ * wakeup_source_read_lock() for this.
+ */
+struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_next_or_null_rcu(ws_head, >entry,
+   struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_walk_next);
+
+/**
  * device_wakeup_attach - Attach a wakeup source object to a device object.
  * @dev: Device to handle.
  * @ws: Wakeup source object to attach to @dev.
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 661efa0..aa3da66 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -63,6 +63,11 @@ struct wakeup_source {
boolautosleep_enabled:1;
 };
 
+#define for_each_wakeup_source(ws) \
+   for ((ws) = wakeup_sources_walk_start();\
+(ws);  \
+(ws) = wakeup_sources_walk_next((ws)))
+
 #ifdef CONFIG_PM_SLEEP
 
 /*
@@ -92,6 +97,10 @@ extern void wakeup_source_remove(struct wakeup_source *ws);
 extern struct wakeup_source *wakeup_source_register(struct device *dev,
const char *name);
 extern void wakeup_source_unregister(struct wakeup_source *ws);
+extern int wakeup_sources_read_lock(void);
+extern void wakeup_sources_read_unlock(int idx);
+extern struct wakeup_source *wakeup_s

[PATCH 3/3] soc: fsl: add RCPM driver

2019-10-22 Thread Ran Wang
The NXP's QorIQ Processors based on ARM Core have RCPM module
(Run Control and Power Management), which performs system level
tasks associated with power management such as wakeup source control.

This driver depends on PM wakeup source framework which help to
collect wake information.

Signed-off-by: Ran Wang 
---
Change in v8:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.
- Add sanity checking for the case of ws->dev or ws->dev->parent
  is null.

Change in v7:
- Replace 'ws->dev' with 'ws->dev->parent' to get aligned with
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs")
- Remove '+obj-y += ftm_alarm.o' since it is wrong.
- Cosmetic work.

Change in v6:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.

Change in v5:
- Fix v4 regression of the return value of wakeup_source_get_next()
didn't pass to ws in while loop.
- Rename wakeup_source member 'attached_dev' to 'dev'.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Remove extra ',' in author line of rcpm.c
- Update usage of wakeup_source_get_next() to be less confusing to the
reader, code logic remain the same.

Change in v3:
- Some whitespace ajdustment.

Change in v2:
- Rebase Kconfig and Makefile update to latest mainline.

 drivers/soc/fsl/Kconfig  |   8 +++
 drivers/soc/fsl/Makefile |   1 +
 drivers/soc/fsl/rcpm.c   | 133 +++
 3 files changed, 142 insertions(+)
 create mode 100644 drivers/soc/fsl/rcpm.c

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index f9ad8ad..4918856 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -40,4 +40,12 @@ config DPAA2_CONSOLE
  /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
  which can be used to dump the Management Complex and AIOP
  firmware logs.
+
+config FSL_RCPM
+   bool "Freescale RCPM support"
+   depends on PM_SLEEP
+   help
+ The NXP QorIQ Processors based on ARM Core have RCPM module
+ (Run Control and Power Management), which performs all device-level
+ tasks associated with power management, such as wakeup source control.
 endmenu
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 71dee8d..906f1cd 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_RCPM) += rcpm.o
 obj-$(CONFIG_FSL_GUTS) += guts.o
 obj-$(CONFIG_FSL_MC_DPIO)  += dpio/
 obj-$(CONFIG_DPAA2_CONSOLE)+= dpaa2-console.o
diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
new file mode 100644
index 000..3ed135e
--- /dev/null
+++ b/drivers/soc/fsl/rcpm.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rcpm.c - Freescale QorIQ RCPM driver
+//
+// Copyright 2019 NXP
+//
+// Author: Ran Wang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RCPM_WAKEUP_CELL_MAX_SIZE  7
+
+struct rcpm {
+   unsigned intwakeup_cells;
+   void __iomem*ippdexpcr_base;
+   boollittle_endian;
+};
+
+static int rcpm_pm_prepare(struct device *dev)
+{
+   int i, ret, idx;
+   void __iomem *base;
+   struct wakeup_source*ws;
+   struct rcpm *rcpm;
+   struct device_node  *np = dev->of_node;
+   u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1], tmp;
+
+   rcpm = dev_get_drvdata(dev);
+   if (!rcpm)
+   return -EINVAL;
+
+   base = rcpm->ippdexpcr_base;
+   idx = wakeup_sources_read_lock();
+
+   /* Begin with first registered wakeup source */
+   for_each_wakeup_source(ws) {
+
+   /* skip object which is not attached to device */
+   if (!ws->dev || !ws->dev->parent)
+   continue;
+
+   ret = device_property_read_u32_array(ws->dev->parent,
+   "fsl,rcpm-wakeup", value,
+   rcpm->wakeup_cells + 1);
+
+   /*  Wakeup source should refer to current rcpm device */
+   if (ret || (np->phandle != value[0])) {
+   dev_info(dev, "%s doesn't refer to this rcpm\n",
+   ws->name);
+   continue;
+   }
+
+   for (i = 0; i < rcpm->wakeup_cells; i++) {
+   /* We can only OR related bits */
+   if (value[i + 1]) {
+   

[PATCH 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-10-22 Thread Ran Wang
By default, QorIQ SoC's RCPM register block is Big Endian. But
there are some exceptions, such as LS1088A and LS2088A, are
Little Endian. So add this optional property to help identify
them.

Actually LS2021A and other Layerscapes won't totally follow Chassis
2.1, so separate them from powerpc SoC.

Signed-off-by: Ran Wang 
Reviewed-by: Rob Herring 
---
Change in v8:
- None.

Change in v7:
- None.

Change in v6:
- None.

Change in v5:
- Add 'Reviewed-by: Rob Herring ' to commit message.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.

Change in v3:
- None.

Change in v2:
- None.

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index e284e4e..5a33619 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -5,7 +5,7 @@ and power management.
 
 Required properites:
   - reg : Offset and length of the register set of the RCPM block.
-  - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
+  - #fsl,rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
fsl,rcpm-wakeup property.
   - compatible : Must contain a chip-specific RCPM block compatible string
and (if applicable) may contain a chassis-version RCPM compatible
@@ -20,6 +20,7 @@ Required properites:
* "fsl,qoriq-rcpm-1.0": for chassis 1.0 rcpm
* "fsl,qoriq-rcpm-2.0": for chassis 2.0 rcpm
* "fsl,qoriq-rcpm-2.1": for chassis 2.1 rcpm
+   * "fsl,qoriq-rcpm-2.1+": for chassis 2.1+ rcpm
 
 All references to "1.0" and "2.0" refer to the QorIQ chassis version to
 which the chip complies.
@@ -27,14 +28,19 @@ Chassis Version Example Chips
 ------
 1.0p4080, p5020, p5040, p2041, p3041
 2.0t4240, b4860, b4420
-2.1t1040, ls1021
+2.1t1040,
+2.1+   ls1021a, ls1012a, ls1043a, ls1046a
+
+Optional properties:
+ - little-endian : RCPM register block is Little Endian. Without it RCPM
+   will be Big Endian (default case).
 
 Example:
 The RCPM node for T4240:
rcpm: global-utilities@e2000 {
compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0";
reg = <0xe2000 0x1000>;
-   fsl,#rcpm-wakeup-cells = <2>;
+   #fsl,rcpm-wakeup-cells = <2>;
};
 
 * Freescale RCPM Wakeup Source Device Tree Bindings
@@ -44,7 +50,7 @@ can be used as a wakeup source.
 
   - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR
register cells. The number of IPPDEXPCR register cells is defined in
-   "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is
+   "#fsl,rcpm-wakeup-cells" in the rcpm node. The first register cell is
the bit mask that should be set in IPPDEXPCR0, and the second register
cell is for IPPDEXPCR1, and so on.
 
-- 
2.7.4



[PATCH 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-10-22 Thread Ran Wang
Some user might want to go through all registered wakeup sources
and doing things accordingly. For example, SoC PM driver might need to
do HW programming to prevent powering down specific IP which wakeup
source depending on. So add this API to help walk through all registered
wakeup source objects on that list and return them one by one.

Signed-off-by: Ran Wang 
Tested-by: Leonard Crestez 
---
Change in v8
- Rename wakeup_source_get_next() to wakeup_sources_walk_next().
- Add wakeup_sources_read_lock() to take over locking job of
  wakeup_source_get_star().
- Rename wakeup_source_get_start() to wakeup_sources_walk_start().
- Replace wakeup_source_get_stop() with wakeup_sources_read_unlock().
- Define macro for_each_wakeup_source(ws).

Change in v7:
- Remove define of member *dev in wake_irq to fix conflict with commit 
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs"), user 
will use ws->dev->parent instead.
- Remove '#include ' because it is not used.

Change in v6:
- Add wakeup_source_get_star() and wakeup_source_get_stop() to aligned 
with wakeup_sources_stats_seq_start/nex/stop.

Change in v5:
- Update commit message, add decription of walk through all wakeup
source objects.
- Add SCU protection in function wakeup_source_get_next().
- Rename wakeup_source member 'attached_dev' to 'dev' and move it up
(before wakeirq).

Change in v4:
- None.

Change in v3:
- Adjust indentation of *attached_dev;.

Change in v2:
- None.

 drivers/base/power/wakeup.c | 42 ++
 include/linux/pm_wakeup.h   |  9 +
 2 files changed, 51 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 5817b51..8c7a5f9 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -248,6 +248,48 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
 
 /**
+ * wakeup_sources_read_lock - Lock wakeup source list for read.
+ */
+int wakeup_sources_read_lock(void)
+{
+   return srcu_read_lock(_srcu);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_read_lock);
+
+/**
+ * wakeup_sources_read_unlock - Unlock wakeup source list.
+ */
+void wakeup_sources_read_unlock(int idx)
+{
+   srcu_read_unlock(_srcu, idx);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_read_unlock);
+
+/**
+ * wakeup_sources_walk_start - Begin a walk on wakeup source list
+ */
+struct wakeup_source *wakeup_sources_walk_start(void)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_entry_rcu(ws_head->next, struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_walk_start);
+
+/**
+ * wakeup_sources_walk_next - Get next wakeup source from the list
+ * @ws: Previous wakeup source object
+ */
+struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_next_or_null_rcu(ws_head, >entry,
+   struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_sources_walk_next);
+
+/**
  * device_wakeup_attach - Attach a wakeup source object to a device object.
  * @dev: Device to handle.
  * @ws: Wakeup source object to attach to @dev.
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 661efa0..aa3da66 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -63,6 +63,11 @@ struct wakeup_source {
boolautosleep_enabled:1;
 };
 
+#define for_each_wakeup_source(ws) \
+   for ((ws) = wakeup_sources_walk_start();\
+(ws);  \
+(ws) = wakeup_sources_walk_next((ws)))
+
 #ifdef CONFIG_PM_SLEEP
 
 /*
@@ -92,6 +97,10 @@ extern void wakeup_source_remove(struct wakeup_source *ws);
 extern struct wakeup_source *wakeup_source_register(struct device *dev,
const char *name);
 extern void wakeup_source_unregister(struct wakeup_source *ws);
+extern int wakeup_sources_read_lock(void);
+extern void wakeup_sources_read_unlock(int idx);
+extern struct wakeup_source *wakeup_sources_walk_start(void);
+extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source 
*ws);
 extern int device_wakeup_enable(struct device *dev);
 extern int device_wakeup_disable(struct device *dev);
 extern void device_set_wakeup_capable(struct device *dev, bool capable);
-- 
2.7.4



[PATCH v7 3/3] soc: fsl: add RCPM driver

2019-10-20 Thread Ran Wang
The NXP's QorIQ Processors based on ARM Core have RCPM module
(Run Control and Power Management), which performs system level
tasks associated with power management such as wakeup source control.

This driver depends on PM wakeup source framework which help to
collect wake information.

Signed-off-by: Ran Wang 
---
Change in v7:
- Replace 'ws->dev' with 'ws->dev->parent' to get aligned with
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs")
- Remove '+obj-y += ftm_alarm.o' since it is wrong.
- Cosmetic work.

Change in v6:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.

Change in v5:
- Fix v4 regression of the return value of wakeup_source_get_next()
didn't pass to ws in while loop.
- Rename wakeup_source member 'attached_dev' to 'dev'.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Remove extra ',' in author line of rcpm.c
- Update usage of wakeup_source_get_next() to be less confusing to the
reader, code logic remain the same.

Change in v3:
- Some whitespace ajdustment.

Change in v2:
- Rebase Kconfig and Makefile update to latest mainline.

 drivers/soc/fsl/Kconfig  |   8 +++
 drivers/soc/fsl/Makefile |   1 +
 drivers/soc/fsl/rcpm.c   | 132 +++
 3 files changed, 141 insertions(+)
 create mode 100644 drivers/soc/fsl/rcpm.c

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index f9ad8ad..4918856 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -40,4 +40,12 @@ config DPAA2_CONSOLE
  /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
  which can be used to dump the Management Complex and AIOP
  firmware logs.
+
+config FSL_RCPM
+   bool "Freescale RCPM support"
+   depends on PM_SLEEP
+   help
+ The NXP QorIQ Processors based on ARM Core have RCPM module
+ (Run Control and Power Management), which performs all device-level
+ tasks associated with power management, such as wakeup source control.
 endmenu
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 71dee8d..906f1cd 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_RCPM) += rcpm.o
 obj-$(CONFIG_FSL_GUTS) += guts.o
 obj-$(CONFIG_FSL_MC_DPIO)  += dpio/
 obj-$(CONFIG_DPAA2_CONSOLE)+= dpaa2-console.o
diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
new file mode 100644
index 000..3da9fc3
--- /dev/null
+++ b/drivers/soc/fsl/rcpm.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rcpm.c - Freescale QorIQ RCPM driver
+//
+// Copyright 2019 NXP
+//
+// Author: Ran Wang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RCPM_WAKEUP_CELL_MAX_SIZE  7
+
+struct rcpm {
+   unsigned intwakeup_cells;
+   void __iomem*ippdexpcr_base;
+   boollittle_endian;
+};
+
+static int rcpm_pm_prepare(struct device *dev)
+{
+   int i, ret, idx;
+   void __iomem *base;
+   struct wakeup_source*ws;
+   struct rcpm *rcpm;
+   struct device_node  *np = dev->of_node;
+   u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1], tmp;
+
+   rcpm = dev_get_drvdata(dev);
+   if (!rcpm)
+   return -EINVAL;
+
+   base = rcpm->ippdexpcr_base;
+
+   /* Begin with first registered wakeup source */
+   ws = wakeup_source_get_start();
+   do {
+   /* skip object which is not attached to device */
+   if (!ws->dev->parent)
+   continue;
+
+   ret = device_property_read_u32_array(ws->dev->parent,
+   "fsl,rcpm-wakeup", value,
+   rcpm->wakeup_cells + 1);
+
+   /*  Wakeup source should refer to current rcpm device */
+   if (ret || (np->phandle != value[0])) {
+   dev_info(dev, "%s doesn't refer to this rcpm\n",
+   ws->name);
+   continue;
+   }
+
+   for (i = 0; i < rcpm->wakeup_cells; i++) {
+   /* We can only OR related bits */
+   if (value[i + 1]) {
+   if (rcpm->little_endian) {
+   tmp = ioread32(base + i * 4);
+   tmp |= value[i + 1];
+   iowrite32(tmp, base + i * 4);
+

[PATCH v7 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-10-20 Thread Ran Wang
Some user might want to go through all registered wakeup sources
and doing things accordingly. For example, SoC PM driver might need to
do HW programming to prevent powering down specific IP which wakeup
source depending on. So add this API to help walk through all registered
wakeup source objects on that list and return them one by one.

Signed-off-by: Ran Wang 
Tested-by: Leonard Crestez 
---
Change in v7:
- Remove define of member *dev in wake_irq to fix conflict with commit 
c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs"), user 
will use ws->dev->parent instead.
- Remove '#include ' because it is not used.

Change in v6:
- Add wakeup_source_get_star() and wakeup_source_get_stop() to aligned 
with wakeup_sources_stats_seq_start/nex/stop.

Change in v5:
- Update commit message, add decription of walk through all wakeup
source objects.
- Add SCU protection in function wakeup_source_get_next().
- Rename wakeup_source member 'attached_dev' to 'dev' and move it up
(before wakeirq).

Change in v4:
- None.

Change in v3:
- Adjust indentation of *attached_dev;.

Change in v2:
- None.

 drivers/base/power/wakeup.c | 37 +
 include/linux/pm_wakeup.h   |  3 +++
 2 files changed, 40 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 5817b51..dee1b09 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -248,6 +248,43 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
 
 /**
+ * wakeup_source_get_star - Begin a walk on wakeup source list
+ * @srcuidx: Lock index allocated for this caller.
+ */
+struct wakeup_source *wakeup_source_get_start(int *srcuidx)
+{
+   struct list_head *ws_head = _sources;
+
+   *srcuidx = srcu_read_lock(_srcu);
+
+   return list_entry_rcu(ws_head->next, struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_start);
+
+/**
+ * wakeup_source_get_next - Get next wakeup source from the list
+ * @ws: Previous wakeup source object
+ */
+struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_next_or_null_rcu(ws_head, >entry,
+   struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_next);
+
+/**
+ * wakeup_source_get_stop - Stop a walk on wakeup source list
+ * @idx: Dedicated lock index of this caller.
+ */
+void wakeup_source_get_stop(int idx)
+{
+   srcu_read_unlock(_srcu, idx);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_stop);
+
+/**
  * device_wakeup_attach - Attach a wakeup source object to a device object.
  * @dev: Device to handle.
  * @ws: Wakeup source object to attach to @dev.
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 661efa0..172e76c 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -92,6 +92,9 @@ extern void wakeup_source_remove(struct wakeup_source *ws);
 extern struct wakeup_source *wakeup_source_register(struct device *dev,
const char *name);
 extern void wakeup_source_unregister(struct wakeup_source *ws);
+extern struct wakeup_source *wakeup_source_get_start(int *srcuidx);
+extern struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws);
+extern void wakeup_source_get_stop(int idx);
 extern int device_wakeup_enable(struct device *dev);
 extern int device_wakeup_disable(struct device *dev);
 extern void device_set_wakeup_capable(struct device *dev, bool capable);
-- 
2.7.4



[PATCH v7 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-10-20 Thread Ran Wang
By default, QorIQ SoC's RCPM register block is Big Endian. But
there are some exceptions, such as LS1088A and LS2088A, are
Little Endian. So add this optional property to help identify
them.

Actually LS2021A and other Layerscapes won't totally follow Chassis
2.1, so separate them from powerpc SoC.

Signed-off-by: Ran Wang 
Reviewed-by: Rob Herring 
---
Change in v7:
- None.

Change in v6:
- None.

Change in v5:
- Add 'Reviewed-by: Rob Herring ' to commit message.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.

Change in v3:
- None.

Change in v2:
- None.

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index e284e4e..5a33619 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -5,7 +5,7 @@ and power management.
 
 Required properites:
   - reg : Offset and length of the register set of the RCPM block.
-  - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
+  - #fsl,rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
fsl,rcpm-wakeup property.
   - compatible : Must contain a chip-specific RCPM block compatible string
and (if applicable) may contain a chassis-version RCPM compatible
@@ -20,6 +20,7 @@ Required properites:
* "fsl,qoriq-rcpm-1.0": for chassis 1.0 rcpm
* "fsl,qoriq-rcpm-2.0": for chassis 2.0 rcpm
* "fsl,qoriq-rcpm-2.1": for chassis 2.1 rcpm
+   * "fsl,qoriq-rcpm-2.1+": for chassis 2.1+ rcpm
 
 All references to "1.0" and "2.0" refer to the QorIQ chassis version to
 which the chip complies.
@@ -27,14 +28,19 @@ Chassis Version Example Chips
 ------
 1.0p4080, p5020, p5040, p2041, p3041
 2.0t4240, b4860, b4420
-2.1t1040, ls1021
+2.1t1040,
+2.1+   ls1021a, ls1012a, ls1043a, ls1046a
+
+Optional properties:
+ - little-endian : RCPM register block is Little Endian. Without it RCPM
+   will be Big Endian (default case).
 
 Example:
 The RCPM node for T4240:
rcpm: global-utilities@e2000 {
compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0";
reg = <0xe2000 0x1000>;
-   fsl,#rcpm-wakeup-cells = <2>;
+   #fsl,rcpm-wakeup-cells = <2>;
};
 
 * Freescale RCPM Wakeup Source Device Tree Bindings
@@ -44,7 +50,7 @@ can be used as a wakeup source.
 
   - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR
register cells. The number of IPPDEXPCR register cells is defined in
-   "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is
+   "#fsl,rcpm-wakeup-cells" in the rcpm node. The first register cell is
the bit mask that should be set in IPPDEXPCR0, and the second register
cell is for IPPDEXPCR1, and so on.
 
-- 
2.7.4



RE: [PATCH V2 1/2] usb: dwc3: Add node to update cache type setting

2019-10-08 Thread Ran Wang
Hi Rob, Felipe,

On Tuesday, September 24, 2019 00:38, Yang Li wrote:
> 
> On Thu, Jul 25, 2019 at 4:56 PM Rob Herring  wrote:
> >
> > On Wed, Jul 24, 2019 at 8:29 PM Ran Wang  wrote:
> > >
> > > Hi Rob,
> > >
> > > On Thursday, July 25, 2019 04:42 Rob Herring  wrote:
> > > >
> > > > On Fri, Jul 12, 2019 at 02:42:05PM +0800, Ran Wang wrote:
> > > > > Some Layerscape paltforms (such as LS1088A, LS2088A, etc)
> > > > > encounter USB detect failues when adding dma-coherent to DWC3
> > > > > node. This is because the HW default cache type configuration of
> > > > > those SoC are not right, need to be updated in DTS.
> > > > >
> > > > > Signed-off-by: Ran Wang 
> > > > > ---
> > > > > Change in v2:
> > > > > - New file.
> > > > >
> > > > >  Documentation/devicetree/bindings/usb/dwc3.txt | 43
> > > > > ++
> > > > >  1 file changed, 43 insertions(+)
> > > > >
> > > > > diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt
> > > > > b/Documentation/devicetree/bindings/usb/dwc3.txt
> > > > > index 8e5265e..7bc1cef 100644
> > > > > --- a/Documentation/devicetree/bindings/usb/dwc3.txt
> > > > > +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
> > > > > @@ -110,6 +110,43 @@ Optional properties:
> > > > >   - in addition all properties from usb-xhci.txt from the current 
> > > > > directory
> are
> > > > > supported as well
> > > > >
> > > > > +* Cache type nodes (optional)
> > > > > +
> > > > > +The Cache type node is used to tell how to configure cache type
> > > > > +on 4 different transfer types: Data Read, Desc Read, Data Write
> > > > > +and Desc write. For each treasfer type, controller has a 4-bit
> > > > > +register field to enable different cache type. Quoted from DWC3
> > > > > +data book Table 6-5
> > > > Cache Type Bit Assignments:
> > > > > +
> > > > > +MBUS_TYPE| bit[3]   |bit[2]   |bit[1] |bit[0]
> > > > > +
> > > > > +AHB  |Cacheable |Bufferable   |Privilegge |Data
> > > > > +AXI3 |Write Allocate|Read Allocate|Cacheable  |Bufferable
> > > > > +AXI4 |Allocate Other|Allocate |Modifiable |Bufferable
> > > > > +AXI4 |Other Allocate|Allocate |Modifiable |Bufferable
> > > > > +Native   |Same as AXI   |Same as AXI  |Same as AXI|Same as AXI
> > > > > +---
> > > > > +-
> > > > > +Note: The AHB, AXI3, AXI4, and PCIe busses use different names
> > > > > +for certain signals, which have the same meaning:
> > > > > +  Bufferable = Posted
> > > > > +  Cacheable = Modifiable = Snoop (negation of No Snoop)
> > > >
> > > > This should all be implied from the SoC specific compatible strings.
> > >
> > > Did you mean I could implement a soc driver which can be matched by
> compatible of 'fsl,ls1088a-dwc3' which will pass known bus type to DWC3 
> driver?
> If yes, how to pass?
> >
> > Yes. The DT match table can have data associated with that compatible
> > string. Beyond that, I'm not really familiar with the DWC3 driver.
> 
> Hi Rob,
> 
> It looks like that the current dwc3 binding perfers to define general quirks 
> in
> device tree properties instead of trying to rely on the compatible string to
> determine quirks.  In this case, can we keep following the existing preference
> instead of choosing the other way?

Looks like you have different opinions on this solution, so I 'd like to have 
all opens
get settled here to help me find a acceptable solution for both of you. 
Please let me explain more about this:

1. This feature (configure cache type) is natively from DWC3 IP (we can find it 
from data book),
not a SoC specific feature (more details please see v1 discussion: 
https://lore.kernel.org/patchwork/patch/851306/)

2. However, in most SoC, the HW default setting looks fine (no need driver 
help), but some case
(like Layerscape) might need driver to do some programming to fix USB no 
detect issue.
That's why I implement this patch.

3. For now, Rob think this should be handled by SoC specific code rather than 
adding a property to
control it (by DWC3 core driver). And Felipe prefer to avoid using glue 
diver. So I am not sure how
to meet this requirements at the same time. 
   
Any further suggestion are really appreciated. Thank you.

Regards,
Ran


RE: [PATCH] usb: hub add filter for device with specific VID

2019-09-28 Thread Ran Wang
Hi Alan,

On Sunday, September 29, 2019 10:35, wrote:
> 
> Hi Alan,
> 
> On Saturday, September 28, 2019 01:08, Alan Stern wrote:

> >
> > In fact, the system should respond the same way to any unrecognized
> > device that doesn't support HNP, right?  There's nothing special about
> > these VID/PID values.
> 
> Yes, but I saw there are already some implementation in upstream kernel for 
> this
> purpose, just PID different: drivers/usb/core/otg_whitelist.h function
> is_targeted()
> 
> > > > And why those specific vid/pid values?  What do they refer to?
> > >
> > > For step 5, we got the VID / PID number from USB IF certified
> > > lab(Allion.inc at Taiwang). Looks like this is a reserved ID pair
> > > and will not be allocated to any vendor for their products. So it's
> > > hence used for
> > this case test (like saying: you should be able to pop a not-support
> > message for this reserved VID).
> >
> > Don't we do this already?
> 
> Yes, but in function is_stargeted(), I found it's a little be different:
> Current upstream: VID = 0x1a0a, PID = 0x0200
> Info from USB-IF certified lab: VID = 0x1a0a, PID = 0x0201
> 

Sorry that I mis-understood the logic of is_stargeted() and it's caller.

So the proper way to resolve my problem is:
1. Select CONFIG_USB_OTG in .config
2. Add property 'tpl-support' to device tree
3. Customize whitelist_table[] according to my Target-Peripheral-List
requirement.

Am I right? :)

Regards,
Ran


RE: [PATCH] usb: hub add filter for device with specific VID

2019-09-28 Thread Ran Wang
Hi Alan,

On Saturday, September 28, 2019 01:08, Alan Stern wrote:
> 
> On Tue, 24 Sep 2019, Ran Wang wrote:
> 
> > Hi Greg,
> >
> > On Monday, September 23, 2019 19:07, Greg Kroah-Hartman wrote:
> > >
> > > On Mon, Sep 23, 2019 at 06:51:02PM +0800, Ran Wang wrote:
> > > > USB 2.0 Embedded Host PET Automated Test (CH6) 6.7.23 A-UUT
> > > > "Unsupported Device" Message require to stop enumerating device
> > > > with VID=0x1a0a PID=0x0201 and pop message to declare this device
> > > > is not
> > > supported.
> > >
> > > Why is this a requirement?
> >
> > This comes from  > Plan for the On-The-Go& Embedded Host Supplement Revision2.0>
> 
> How much do we care about our support for USB OTG?  Isn't it dying off?

As I know, some vendors still want to pass this Embedded Host compliance test
to make sure their product's quality. And above test case is included.

> > Below is related description I quote from it:
> > 6.7.23 A-UUT "Unsupported Device" Message
> > Purpose: This test verifies that an A-UUT produces a device non-supported
> error message
> > when a device it doesn't recognize, and does not support HNP, connects
> to it.
> > Applies to: All Targeted Hosts
> > Description: Get VBUS turned on, and connect to the A-UUT. Get enumerated
> and respond
> > as an unknown device not supporting HNP. Check that a suitable error
> message is generated.
> > Pass Criteria: Message "Unsupported Device"or similar is displayed on
> > UUT
> >
> > 6.7.23.1 Test Procedure
> > 1. Start with cable still attached, PET applying 10 F capacitance and 10k  
> > pull-
> down
> > resistance between VBUS and ground, data lines not pulled up.
> > 2. Get VBUS turned on, using the method described in Section6.7.1.
> > 3. Wait for almost TB_SVLD_BCON max (1s - 0.1s = 0.9s) from VBUS reaching
> VOTG_SESS_VLD max.
> > 4. Connect PET using D+ pull-up.
> > 5. Allow A-UUT to enumerate PET, responding with a VID / PID combination
> not on the TPL
> > of the UUT and also with the OTG descriptor stating that it does not 
> > support
> HNP.
> > 6. Start 30s timer when Device Descriptor is read.
> > 7. Display Message "Click OK if 'Unsupported Device' indication displayed on
> UUT".
> > 8. If operator clicks OK before 30s timer expires, then UUT passes test.
> > 9. If 30selapses first, then UUT fails test.
> > 10. PET disconnects by removing any termination on the data lines, but 
> > leaves
> a capacitance of
> > 10 F and a pull-down resistance of 10k  connected across VBUS.
> > 11. Wait 2s to allow disconnection to be detected.
> > End of Test.
> 
> In fact, the system should respond the same way to any unrecognized device
> that doesn't support HNP, right?  There's nothing special about these VID/PID
> values.

Yes, but I saw there are already some implementation in upstream kernel for 
this purpose,
just PID different: drivers/usb/core/otg_whitelist.h function is_targeted()

> > > And why those specific vid/pid values?  What do they refer to?
> >
> > For step 5, we got the VID / PID number from USB IF certified
> > lab(Allion.inc at Taiwang). Looks like this is a reserved ID pair and
> > will not be allocated to any vendor for their products. So it's hence used 
> > for
> this case test (like saying: you should be able to pop a not-support message 
> for
> this reserved VID).
> 
> Don't we do this already?

Yes, but in function is_stargeted(), I found it's a little be different:
Current upstream: VID = 0x1a0a, PID = 0x0200
Info from USB-IF certified lab: VID = 0x1a0a, PID = 0x0201

Regards,
Ran

> Alan Stern



RE: [PATCH] usb: hub add filter for device with specific VID

2019-09-23 Thread Ran Wang
Hi Alan,

On Monday, September 23, 2019 23:01, Alan Stern wrote:
> 
> On Mon, 23 Sep 2019, Ran Wang wrote:
> 
> > USB 2.0 Embedded Host PET Automated Test (CH6) 6.7.23 A-UUT
> > "Unsupported Device" Message require to stop enumerating device with
> > VID=0x1a0a PID=0x0201 and pop message to declare this device is not
> supported.
> >
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/usb/core/hub.c | 12 
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index
> > bbcfa63..3cda0da 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -4982,6 +4982,18 @@ static void hub_port_connect(struct usb_hub *hub,
> int port1, u16 portstatus,
> > if (status < 0)
> > goto loop;
> >
> > +/* USB 2.0 Embedded Host PET Automated Test (CH6)
> > +* 6.7.23 A-UUT "Unsupported Device" Message
> > +* require to filter out below device when enumeration
> > +*/
> > +   if ((udev->descriptor.idVendor == 0x1a0a)
> > +&& (udev->descriptor.idProduct == 0x0201)) {
> > +   dev_err(>dev, "This device is not supported:
> idVendor=0x%x idProduct=0x%x\n",
> > +   udev->descriptor.idVendor,
> > +   udev->descriptor.idProduct);
> 
> There's no need to write out the Vendor and Product IDs.  They already appear
> in the "New device" message.

OK

> > +   goto done;
> > +   }
> > +
> > if (udev->quirks & USB_QUIRK_DELAY_INIT)
> > msleep(2000);
> 
> Shouldn't this be implemented as a device quirk?

Yes, I was also looking for the way in quirk but not quite sure currently.
So we can stop initializing a device (with specific VID) in quirk, right?

Actually in drivers/usb/core/hub.c function usb_enumerate_device(), it will
call is_targeted(udev) which has below implementation:

54 /* OTG PET device is always targeted (see OTG 2.0 ECN 6.4.2) */  

55 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&  
 
56  le16_to_cpu(dev->descriptor.idProduct) == 0x0200))  

57 return 1;

The ID is very close to what I need to response. So, do I need to add code here?

Thanks.
Ran



RE: [PATCH] usb: hub add filter for device with specific VID

2019-09-23 Thread Ran Wang
Hi Greg,

On Monday, September 23, 2019 19:07, Greg Kroah-Hartman wrote:
> 
> On Mon, Sep 23, 2019 at 06:51:02PM +0800, Ran Wang wrote:
> > USB 2.0 Embedded Host PET Automated Test (CH6) 6.7.23 A-UUT
> > "Unsupported Device" Message require to stop enumerating device with
> > VID=0x1a0a PID=0x0201 and pop message to declare this device is not
> supported.
> 
> Why is this a requirement?

This comes from 

Below is related description I quote from it:
6.7.23 A-UUT "Unsupported Device" Message
Purpose: This test verifies that an A-UUT produces a device non-supported error 
message
when a device it doesn't recognize, and does not support HNP, connects 
to it.
Applies to: All Targeted Hosts
Description: Get VBUS turned on, and connect to the A-UUT. Get enumerated and 
respond
as an unknown device not supporting HNP. Check that a suitable error 
message is generated.
Pass Criteria: Message "Unsupported Device"or similar is displayed on UUT

6.7.23.1 Test Procedure
1. Start with cable still attached, PET applying 10μF capacitance and 10kΩ 
pull-down
resistance between VBUS and ground, data lines not pulled up.
2. Get VBUS turned on, using the method described in Section6.7.1.
3. Wait for almost TB_SVLD_BCON max (1s - 0.1s = 0.9s) from VBUS reaching 
VOTG_SESS_VLD max.
4. Connect PET using D+ pull-up.
5. Allow A-UUT to enumerate PET, responding with a VID / PID combination not on 
the TPL
of the UUT and also with the OTG descriptor stating that it does not 
support HNP.
6. Start 30s timer when Device Descriptor is read.
7. Display Message "Click OK if 'Unsupported Device' indication displayed on 
UUT".
8. If operator clicks OK before 30s timer expires, then UUT passes test.
9. If 30selapses first, then UUT fails test.
10. PET disconnects by removing any termination on the data lines, but leaves a 
capacitance of
10μF and a pull-down resistance of 10kΩ connected across VBUS.
11. Wait 2s to allow disconnection to be detected.
End of Test.

> And why those specific vid/pid values?  What do they refer to?

For step 5, we got the VID / PID number from USB IF certified lab(Allion.inc at 
Taiwang). Looks like
this is a reserved ID pair and will not be allocated to any vendor for their 
products. So it's hence used for this
case test (like saying: you should be able to pop a not-support message for 
this reserved VID).
 
> >
> > Signed-off-by: Ran Wang 
> > ---
> >  drivers/usb/core/hub.c | 12 
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index
> > bbcfa63..3cda0da 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -4982,6 +4982,18 @@ static void hub_port_connect(struct usb_hub *hub,
> int port1, u16 portstatus,
> > if (status < 0)
> > goto loop;
> >
> > +/* USB 2.0 Embedded Host PET Automated Test (CH6)
> > +* 6.7.23 A-UUT "Unsupported Device" Message
> > +* require to filter out below device when enumeration
> > +*/
> 
> Nit, can you align your comment lines, to match the other multi-line comments
> in this file?  Otherwise it starts to look bad over time.

Yes, will update.

> 
> 
> > +   if ((udev->descriptor.idVendor == 0x1a0a)
> > +&& (udev->descriptor.idProduct == 0x0201)) {
> 
> Are you sure you don't have to convert this value into cpu endian before
> checking it?

Thanks for pointing out, how about this:
if ((le16_to_cpu(udev->descriptor.idVendor) == 0x1a0a)
 && (le16_to_cpu(udev->descriptor.idProduct) == 0x0201)) {

Regards,
Ran


[PATCH] usb: hub add filter for device with specific VID

2019-09-23 Thread Ran Wang
USB 2.0 Embedded Host PET Automated Test (CH6) 6.7.23 A-UUT "Unsupported
Device" Message require to stop enumerating device with VID=0x1a0a PID=0x0201
and pop message to declare this device is not supported.

Signed-off-by: Ran Wang 
---
 drivers/usb/core/hub.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index bbcfa63..3cda0da 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4982,6 +4982,18 @@ static void hub_port_connect(struct usb_hub *hub, int 
port1, u16 portstatus,
if (status < 0)
goto loop;
 
+/* USB 2.0 Embedded Host PET Automated Test (CH6)
+* 6.7.23 A-UUT "Unsupported Device" Message
+* require to filter out below device when enumeration
+*/
+   if ((udev->descriptor.idVendor == 0x1a0a)
+&& (udev->descriptor.idProduct == 0x0201)) {
+   dev_err(>dev, "This device is not supported: 
idVendor=0x%x idProduct=0x%x\n",
+   udev->descriptor.idVendor,
+   udev->descriptor.idProduct);
+   goto done;
+   }
+
if (udev->quirks & USB_QUIRK_DELAY_INIT)
msleep(2000);
 
-- 
2.7.4



[PATCH] arm64: dts: lx2160a: Correct CPU core idle state name

2019-09-17 Thread Ran Wang
lx2160a support PW15 but not PW20, correct name to avoid confusing.

Signed-off-by: Ran Wang 
---
 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 36 +-
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
index 408e0ec..b032f38 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
@@ -33,7 +33,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@1 {
@@ -49,7 +49,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@100 {
@@ -65,7 +65,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@101 {
@@ -81,7 +81,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@200 {
@@ -97,7 +97,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@201 {
@@ -113,7 +113,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@300 {
@@ -129,7 +129,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@301 {
@@ -145,7 +145,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@400 {
@@ -161,7 +161,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@401 {
@@ -177,7 +177,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@500 {
@@ -193,7 +193,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@501 {
@@ -209,7 +209,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@600 {
@@ -225,7 +225,7 @@
i-cache-line-size = <64>;
i-cache-sets = <192>;
next-level-cache = <_l2>;
-   cpu-idle-states = <_pw20>;
+   cpu-idle-states = <_pw15>;
};
 
cpu@601 {
@@ -241,7 +241,7 @@
  

RE: [PATCH v6 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-09-16 Thread Ran Wang
Hi Rafael,

On Wednesday, August 21, 2019 11:16, Ran Wang wrote:
> 
> Some user might want to go through all registered wakeup sources and doing
> things accordingly. For example, SoC PM driver might need to do HW
> programming to prevent powering down specific IP which wakeup source
> depending on. So add this API to help walk through all registered wakeup 
> source
> objects on that list and return them one by one.
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v6:
>   - Add wakeup_source_get_star() and wakeup_source_get_stop() to
> aligned
>   with wakeup_sources_stats_seq_start/nex/stop.

How about this version, could you please give any comment? Thanks.

Regards,
Ran 





RE: [PATCH v6 3/3] soc: fsl: add RCPM driver

2019-08-20 Thread Ran Wang
Hi Pavel,

On Wednesday, August 21, 2019 11:16, Ran Wang wrote:
> 
> The NXP's QorIQ Processors based on ARM Core have RCPM module (Run
> Control and Power Management), which performs system level tasks associated
> with power management such as wakeup source control.
> 
> This driver depends on PM wakeup source framework which help to collect wake
> information.
> 
> Signed-off-by: Ran Wang 
> ---
> Change in v6:
>   - Adjust related API usage to meet wakeup.c's update in patch 1/3.
> Change in v5:
>   - Fix v4 regression of the return value of wakeup_source_get_next()
>   didn't pass to ws in while loop.
>   - Rename wakeup_source member 'attached_dev' to 'dev'.
>   - Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
>   please see
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kern
> el.org%2Fpatchwork%2Fpatch%2F1101022%2Fdata=02%7C01%7Cran.wa
> ng_1%40nxp.com%7C27cff523c0a54ce89afe08d725e5987b%7C686ea1d3bc2b4
> c6fa92cd99c5c301635%7C0%7C0%7C637019540358555022sdata=4YYGD
> lwvB%2B4Y1436c1bOUzFyjYEqTU5HbiUFv5%2FCxi0%3Dreserved=0
> 
> Change in v4:
>   - Remove extra ',' in author line of rcpm.c
>   - Update usage of wakeup_source_get_next() to be less confusing to
> the reader, code logic remain the same.
> 
> Change in v3:
>   - Some whitespace ajdustment.
> 
> Change in v2:
>   - Rebase Kconfig and Makefile update to latest mainline.
> 
>  drivers/soc/fsl/Kconfig  |   8 +++
>  drivers/soc/fsl/Makefile |   2 +
>  drivers/soc/fsl/rcpm.c   | 128
> +++
>  3 files changed, 138 insertions(+)
>  create mode 100644 drivers/soc/fsl/rcpm.c
> 
> diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index
> f9ad8ad..4918856 100644
> --- a/drivers/soc/fsl/Kconfig
> +++ b/drivers/soc/fsl/Kconfig
> @@ -40,4 +40,12 @@ config DPAA2_CONSOLE
> /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
> which can be used to dump the Management Complex and AIOP
> firmware logs.
> +
> +config FSL_RCPM
> + bool "Freescale RCPM support"
> + depends on PM_SLEEP
> + help
> +   The NXP QorIQ Processors based on ARM Core have RCPM module
> +   (Run Control and Power Management), which performs all device-level
> +   tasks associated with power management, such as wakeup source
> control.
>  endmenu
> diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile index
> 71dee8d..28c6dac 100644
> --- a/drivers/soc/fsl/Makefile
> +++ b/drivers/soc/fsl/Makefile
> @@ -6,6 +6,8 @@
>  obj-$(CONFIG_FSL_DPAA) += qbman/
>  obj-$(CONFIG_QUICC_ENGINE)   += qe/
>  obj-$(CONFIG_CPM)+= qe/
> +obj-$(CONFIG_FSL_RCPM)   += rcpm.o
>  obj-$(CONFIG_FSL_GUTS)   += guts.o
>  obj-$(CONFIG_FSL_MC_DPIO)+= dpio/
>  obj-$(CONFIG_DPAA2_CONSOLE)  += dpaa2-console.o
> +obj-y += ftm_alarm.o
> diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c new file mode
> 100644 index 000..82c0ad5
> --- /dev/null
> +++ b/drivers/soc/fsl/rcpm.c
> @@ -0,0 +1,128 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// rcpm.c - Freescale QorIQ RCPM driver // // Copyright 2019 NXP // //
> +Author: Ran Wang 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define RCPM_WAKEUP_CELL_MAX_SIZE7
> +
> +struct rcpm {
> + unsigned intwakeup_cells;
> + void __iomem*ippdexpcr_base;
> + boollittle_endian;
> +};
> +
> +static int rcpm_pm_prepare(struct device *dev) {
> + struct device_node  *np = dev->of_node;
> + struct wakeup_source*ws;
> + struct rcpm *rcpm;
> + u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1], tmp;
> + int i, ret, idx;
> +
> + rcpm = dev_get_drvdata(dev);
> + if (!rcpm)
> + return -EINVAL;
> +
> + /* Begin with first registered wakeup source */
> + ws = wakeup_source_get_start();

Since I have mad some change in this version, could you please take a look on 
this.
If it's OK to you, I would re-add 'Acked-by: Pavel Machek  '

> + do {
> + /* skip object which is not attached to device */
> + if (!ws->dev)
> + continue;
> +
> + ret = device_property_read_u32_array(ws->dev,
> + "fsl,rcpm-wakeup", value, rcpm->wakeup_cells
> + 1);
> +
> + /*  Wakeup source should refer to current rcpm device */
> + if (ret || (np->p

[PATCH v6 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-08-20 Thread Ran Wang
Some user might want to go through all registered wakeup sources
and doing things accordingly. For example, SoC PM driver might need to
do HW programming to prevent powering down specific IP which wakeup
source depending on. So add this API to help walk through all registered
wakeup source objects on that list and return them one by one.

Signed-off-by: Ran Wang 
---
Change in v6:
- Add wakeup_source_get_star() and wakeup_source_get_stop() to aligned 
with wakeup_sources_stats_seq_start/nex/stop.

Change in v5:
- Update commit message, add decription of walk through all wakeup
source objects.
- Add SCU protection in function wakeup_source_get_next().
- Rename wakeup_source member 'attached_dev' to 'dev' and move it up
(before wakeirq).

Change in v4:
- None.

Change in v3:
- Adjust indentation of *attached_dev;.

Change in v2:
- None.

 drivers/base/power/wakeup.c | 39 +++
 include/linux/pm_wakeup.h   |  5 +
 2 files changed, 44 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index ee31d4f..61bc16b 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -228,6 +229,43 @@ void wakeup_source_unregister(struct wakeup_source *ws)
 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
 
 /**
+ * wakeup_source_get_star - Begin a walk on wakeup source list
+ * @srcuidx: Lock index allocated for this caller.
+ */
+struct wakeup_source *wakeup_source_get_start(int *srcuidx)
+{
+   struct list_head *ws_head = _sources;
+
+   *srcuidx = srcu_read_lock(_srcu);
+
+   return list_entry_rcu(ws_head->next, struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_start);
+
+/**
+ * wakeup_source_get_next - Get next wakeup source from the list
+ * @ws: Previous wakeup source object
+ */
+struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws)
+{
+   struct list_head *ws_head = _sources;
+
+   return list_next_or_null_rcu(ws_head, >entry,
+   struct wakeup_source, entry);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_next);
+
+/**
+ * wakeup_source_get_stop - Stop a walk on wakeup source list
+ * @idx: Dedicated lock index of this caller.
+ */
+void wakeup_source_get_stop(int idx)
+{
+   srcu_read_unlock(_srcu, idx);
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_stop);
+
+/**
  * device_wakeup_attach - Attach a wakeup source object to a device object.
  * @dev: Device to handle.
  * @ws: Wakeup source object to attach to @dev.
@@ -242,6 +280,7 @@ static int device_wakeup_attach(struct device *dev, struct 
wakeup_source *ws)
return -EEXIST;
}
dev->power.wakeup = ws;
+   ws->dev = dev;
if (dev->power.wakeirq)
device_wakeup_attach_irq(dev, dev->power.wakeirq);
spin_unlock_irq(>power.lock);
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 9102760..e6b47b6 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -23,6 +23,7 @@ struct wake_irq;
  * @name: Name of the wakeup source
  * @entry: Wakeup source list entry
  * @lock: Wakeup source lock
+ * @dev: The device it attached to
  * @wakeirq: Optional device specific wakeirq
  * @timer: Wakeup timer list
  * @timer_expires: Wakeup timer expiration
@@ -42,6 +43,7 @@ struct wakeup_source {
const char  *name;
struct list_headentry;
spinlock_t  lock;
+   struct device   *dev;
struct wake_irq *wakeirq;
struct timer_list   timer;
unsigned long   timer_expires;
@@ -88,6 +90,9 @@ extern void wakeup_source_add(struct wakeup_source *ws);
 extern void wakeup_source_remove(struct wakeup_source *ws);
 extern struct wakeup_source *wakeup_source_register(const char *name);
 extern void wakeup_source_unregister(struct wakeup_source *ws);
+extern struct wakeup_source *wakeup_source_get_start(int *srcuidx);
+extern struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws);
+extern void wakeup_source_get_stop(int idx);
 extern int device_wakeup_enable(struct device *dev);
 extern int device_wakeup_disable(struct device *dev);
 extern void device_set_wakeup_capable(struct device *dev, bool capable);
-- 
2.7.4



[PATCH v6 3/3] soc: fsl: add RCPM driver

2019-08-20 Thread Ran Wang
The NXP's QorIQ Processors based on ARM Core have RCPM module
(Run Control and Power Management), which performs system level
tasks associated with power management such as wakeup source control.

This driver depends on PM wakeup source framework which help to
collect wake information.

Signed-off-by: Ran Wang 
---
Change in v6:
- Adjust related API usage to meet wakeup.c's update in patch 1/3.

Change in v5:
- Fix v4 regression of the return value of wakeup_source_get_next()
didn't pass to ws in while loop.
- Rename wakeup_source member 'attached_dev' to 'dev'.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Remove extra ',' in author line of rcpm.c
- Update usage of wakeup_source_get_next() to be less confusing to the
reader, code logic remain the same.

Change in v3:
- Some whitespace ajdustment.

Change in v2:
- Rebase Kconfig and Makefile update to latest mainline.

 drivers/soc/fsl/Kconfig  |   8 +++
 drivers/soc/fsl/Makefile |   2 +
 drivers/soc/fsl/rcpm.c   | 128 +++
 3 files changed, 138 insertions(+)
 create mode 100644 drivers/soc/fsl/rcpm.c

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index f9ad8ad..4918856 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -40,4 +40,12 @@ config DPAA2_CONSOLE
  /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
  which can be used to dump the Management Complex and AIOP
  firmware logs.
+
+config FSL_RCPM
+   bool "Freescale RCPM support"
+   depends on PM_SLEEP
+   help
+ The NXP QorIQ Processors based on ARM Core have RCPM module
+ (Run Control and Power Management), which performs all device-level
+ tasks associated with power management, such as wakeup source control.
 endmenu
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 71dee8d..28c6dac 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,6 +6,8 @@
 obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_RCPM) += rcpm.o
 obj-$(CONFIG_FSL_GUTS) += guts.o
 obj-$(CONFIG_FSL_MC_DPIO)  += dpio/
 obj-$(CONFIG_DPAA2_CONSOLE)+= dpaa2-console.o
+obj-y += ftm_alarm.o
diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
new file mode 100644
index 000..82c0ad5
--- /dev/null
+++ b/drivers/soc/fsl/rcpm.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rcpm.c - Freescale QorIQ RCPM driver
+//
+// Copyright 2019 NXP
+//
+// Author: Ran Wang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RCPM_WAKEUP_CELL_MAX_SIZE  7
+
+struct rcpm {
+   unsigned intwakeup_cells;
+   void __iomem*ippdexpcr_base;
+   boollittle_endian;
+};
+
+static int rcpm_pm_prepare(struct device *dev)
+{
+   struct device_node  *np = dev->of_node;
+   struct wakeup_source*ws;
+   struct rcpm *rcpm;
+   u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1], tmp;
+   int i, ret, idx;
+
+   rcpm = dev_get_drvdata(dev);
+   if (!rcpm)
+   return -EINVAL;
+
+   /* Begin with first registered wakeup source */
+   ws = wakeup_source_get_start();
+   do {
+   /* skip object which is not attached to device */
+   if (!ws->dev)
+   continue;
+
+   ret = device_property_read_u32_array(ws->dev,
+   "fsl,rcpm-wakeup", value, rcpm->wakeup_cells + 
1);
+
+   /*  Wakeup source should refer to current rcpm device */
+   if (ret || (np->phandle != value[0])) {
+   dev_info(dev, "%s doesn't refer to this rcpm\n",
+   ws->name);
+   continue;
+   }
+
+   for (i = 0; i < rcpm->wakeup_cells; i++) {
+   /* We can only OR related bits */
+   if (value[i + 1]) {
+   if (rcpm->little_endian) {
+   tmp = ioread32(rcpm->ippdexpcr_base + i 
* 4);
+   tmp |= value[i + 1];
+   iowrite32(tmp, rcpm->ippdexpcr_base + i 
* 4);
+   } else {
+   tmp = ioread32be(rcpm->ippdexpcr_base + 
i * 4);
+   tmp |= value[i + 1];
+   iowrite32be(tmp, rcpm->ippdexpcr_base + 
i * 4);
+   }
+ 

[PATCH v6 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-08-20 Thread Ran Wang
By default, QorIQ SoC's RCPM register block is Big Endian. But
there are some exceptions, such as LS1088A and LS2088A, are
Little Endian. So add this optional property to help identify
them.

Actually LS2021A and other Layerscapes won't totally follow Chassis
2.1, so separate them from powerpc SoC.

Signed-off-by: Ran Wang 
Reviewed-by: Rob Herring 
---
Change in v6:
- None.

Change in v5:
- Add 'Reviewed-by: Rob Herring ' to commit message.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.

Change in v3:
- None.

Change in v2:
- None.

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index e284e4e..5a33619 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -5,7 +5,7 @@ and power management.
 
 Required properites:
   - reg : Offset and length of the register set of the RCPM block.
-  - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
+  - #fsl,rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
fsl,rcpm-wakeup property.
   - compatible : Must contain a chip-specific RCPM block compatible string
and (if applicable) may contain a chassis-version RCPM compatible
@@ -20,6 +20,7 @@ Required properites:
* "fsl,qoriq-rcpm-1.0": for chassis 1.0 rcpm
* "fsl,qoriq-rcpm-2.0": for chassis 2.0 rcpm
* "fsl,qoriq-rcpm-2.1": for chassis 2.1 rcpm
+   * "fsl,qoriq-rcpm-2.1+": for chassis 2.1+ rcpm
 
 All references to "1.0" and "2.0" refer to the QorIQ chassis version to
 which the chip complies.
@@ -27,14 +28,19 @@ Chassis Version Example Chips
 ------
 1.0p4080, p5020, p5040, p2041, p3041
 2.0t4240, b4860, b4420
-2.1t1040, ls1021
+2.1t1040,
+2.1+   ls1021a, ls1012a, ls1043a, ls1046a
+
+Optional properties:
+ - little-endian : RCPM register block is Little Endian. Without it RCPM
+   will be Big Endian (default case).
 
 Example:
 The RCPM node for T4240:
rcpm: global-utilities@e2000 {
compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0";
reg = <0xe2000 0x1000>;
-   fsl,#rcpm-wakeup-cells = <2>;
+   #fsl,rcpm-wakeup-cells = <2>;
};
 
 * Freescale RCPM Wakeup Source Device Tree Bindings
@@ -44,7 +50,7 @@ can be used as a wakeup source.
 
   - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR
register cells. The number of IPPDEXPCR register cells is defined in
-   "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is
+   "#fsl,rcpm-wakeup-cells" in the rcpm node. The first register cell is
the bit mask that should be set in IPPDEXPCR0, and the second register
cell is for IPPDEXPCR1, and so on.
 
-- 
2.7.4



RE: [PATCH v5 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-08-19 Thread Ran Wang
Hi Rafael,

On Monday, August 19, 2019 16:20, Rafael J. Wysocki wrote:
> 
> On Mon, Aug 19, 2019 at 10:15 AM Ran Wang  wrote:
> >
> > Hi Rafael,
> >
> > On Monday, August 05, 2019 17:59, Rafael J. Wysocki wrote:
> > >
> > > On Wednesday, July 24, 2019 9:47:20 AM CEST Ran Wang wrote:
> > > > Some user might want to go through all registered wakeup sources
> > > > and doing things accordingly. For example, SoC PM driver might
> > > > need to do HW programming to prevent powering down specific IP
> > > > which wakeup source depending on. So add this API to help walk
> > > > through all registered wakeup source objects on that list and return 
> > > > them
> one by one.
> > > >
> > > > Signed-off-by: Ran Wang 
> > > > ---
> > > > Change in v5:
> > > > - Update commit message, add decription of walk through all wakeup
> > > > source objects.
> > > > - Add SCU protection in function wakeup_source_get_next().
> > > > - Rename wakeup_source member 'attached_dev' to 'dev' and move
> > > > it
> > > up
> > > > (before wakeirq).
> > > >
> > > > Change in v4:
> > > > - None.
> > > >
> > > > Change in v3:
> > > > - Adjust indentation of *attached_dev;.
> > > >
> > > > Change in v2:
> > > > - None.
> > > >
> > > >  drivers/base/power/wakeup.c | 24 
> > > >  include/linux/pm_wakeup.h   |  3 +++
> > > >  2 files changed, 27 insertions(+)
> > > >
> > > > diff --git a/drivers/base/power/wakeup.c
> > > > b/drivers/base/power/wakeup.c index ee31d4f..2fba891 100644
> > > > --- a/drivers/base/power/wakeup.c
> > > > +++ b/drivers/base/power/wakeup.c
> > > > @@ -14,6 +14,7 @@
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > +#include 
> > > >  #include 
> > > >  #include 
> > > >
> > > > @@ -226,6 +227,28 @@ void wakeup_source_unregister(struct
> > > wakeup_source *ws)
> > > > }
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(wakeup_source_unregister);
> > > > +/**
> > > > + * wakeup_source_get_next - Get next wakeup source from the list
> > > > + * @ws: Previous wakeup source object, null means caller want first 
> > > > one.
> > > > + */
> > > > +struct wakeup_source *wakeup_source_get_next(struct wakeup_source
> > > > +*ws) {
> > > > +   struct list_head *ws_head = _sources;
> > > > +   struct wakeup_source *next_ws = NULL;
> > > > +   int idx;
> > > > +
> > > > +   idx = srcu_read_lock(_srcu);
> > > > +   if (ws)
> > > > +   next_ws = list_next_or_null_rcu(ws_head, >entry,
> > > > +   struct wakeup_source, entry);
> > > > +   else
> > > > +   next_ws = list_entry_rcu(ws_head->next,
> > > > +   struct wakeup_source, entry);
> > > > +   srcu_read_unlock(_srcu, idx);
> > > > +
> > >
> > > This is incorrect.
> > >
> > > The SRCU cannot be unlocked until the caller of this is done with
> > > the object returned by it, or that object can be freed while it is still 
> > > being
> accessed.
> >
> > Thanks for the comment. Looks like I was not fully understanding your
> > point on
> > v4 discussion. So I will implement 3 APIs by referring
> > wakeup_sources_stats_seq_start/next/stop()
> >
> > > Besides, this patch conflicts with some general wakeup sources
> > > changes in the works, so it needs to be deferred and rebased on top of 
> > > those
> changes.
> >
> > Could you please tell me which is the right code base I should developing 
> > on?
> > I just tried applying v5 patch on latest
> > git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git branch master
> (d1abaeb Linux 5.3-rc5) and no conflict encountered.
> 
> It is better to use the most recent -rc from Linus (5.3-rc5 as of
> today) as the base unless your patches depend on some changes that are not in
> there.

OK, So I need to implement on latest 
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git branch master, 
am I right?

However, I just checked v5.3-rc5 code and found it has the same HEAD (d1abaeb 
Linux 5.3-rc5
on which I did not observe v5 patch apply conflict, did I miss something? 
Thanks.

Regards,
Ran


RE: [PATCH v5 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-08-19 Thread Ran Wang
Hi Rafael,

On Monday, August 05, 2019 17:59, Rafael J. Wysocki wrote:
> 
> On Wednesday, July 24, 2019 9:47:20 AM CEST Ran Wang wrote:
> > Some user might want to go through all registered wakeup sources and
> > doing things accordingly. For example, SoC PM driver might need to do
> > HW programming to prevent powering down specific IP which wakeup
> > source depending on. So add this API to help walk through all
> > registered wakeup source objects on that list and return them one by one.
> >
> > Signed-off-by: Ran Wang 
> > ---
> > Change in v5:
> > - Update commit message, add decription of walk through all wakeup
> > source objects.
> > - Add SCU protection in function wakeup_source_get_next().
> > - Rename wakeup_source member 'attached_dev' to 'dev' and move it
> up
> > (before wakeirq).
> >
> > Change in v4:
> > - None.
> >
> > Change in v3:
> > - Adjust indentation of *attached_dev;.
> >
> > Change in v2:
> > - None.
> >
> >  drivers/base/power/wakeup.c | 24 
> >  include/linux/pm_wakeup.h   |  3 +++
> >  2 files changed, 27 insertions(+)
> >
> > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> > index ee31d4f..2fba891 100644
> > --- a/drivers/base/power/wakeup.c
> > +++ b/drivers/base/power/wakeup.c
> > @@ -14,6 +14,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >
> > @@ -226,6 +227,28 @@ void wakeup_source_unregister(struct
> wakeup_source *ws)
> > }
> >  }
> >  EXPORT_SYMBOL_GPL(wakeup_source_unregister);
> > +/**
> > + * wakeup_source_get_next - Get next wakeup source from the list
> > + * @ws: Previous wakeup source object, null means caller want first one.
> > + */
> > +struct wakeup_source *wakeup_source_get_next(struct wakeup_source
> > +*ws) {
> > +   struct list_head *ws_head = _sources;
> > +   struct wakeup_source *next_ws = NULL;
> > +   int idx;
> > +
> > +   idx = srcu_read_lock(_srcu);
> > +   if (ws)
> > +   next_ws = list_next_or_null_rcu(ws_head, >entry,
> > +   struct wakeup_source, entry);
> > +   else
> > +   next_ws = list_entry_rcu(ws_head->next,
> > +   struct wakeup_source, entry);
> > +   srcu_read_unlock(_srcu, idx);
> > +
> 
> This is incorrect.
> 
> The SRCU cannot be unlocked until the caller of this is done with the object
> returned by it, or that object can be freed while it is still being accessed.

Thanks for the comment. Looks like I was not fully understanding your point on
v4 discussion. So I will implement 3 APIs by referring 
wakeup_sources_stats_seq_start/next/stop()
 
> Besides, this patch conflicts with some general wakeup sources changes in the
> works, so it needs to be deferred and rebased on top of those changes.

Could you please tell me which is the right code base I should developing on?
I just tried applying v5 patch on latest 
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git branch master 
(d1abaeb Linux 5.3-rc5)
and no conflict encountered.

Thanks & Regards,
Ran




[PATCH v5 2/3] Documentation: dt: binding: fsl: Add 'little-endian' and update Chassis define

2019-07-24 Thread Ran Wang
By default, QorIQ SoC's RCPM register block is Big Endian. But
there are some exceptions, such as LS1088A and LS2088A, are Little
Endian. So add this optional property to help identify them.

Actually LS2021A and other Layerscapes won't totally follow Chassis
2.1, so separate them from powerpc SoC.

Signed-off-by: Ran Wang 
Reviewed-by: Rob Herring 
---
Change in v5:
- Add 'Reviewed-by: Rob Herring ' to commit message.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Adjust indectation of 'ls1021a, ls1012a, ls1043a, ls1046a'.

Change in v3:
- None.

Change in v2:
- None.

 Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt 
b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
index e284e4e..5a33619 100644
--- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
+++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt
@@ -5,7 +5,7 @@ and power management.
 
 Required properites:
   - reg : Offset and length of the register set of the RCPM block.
-  - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
+  - #fsl,rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the
fsl,rcpm-wakeup property.
   - compatible : Must contain a chip-specific RCPM block compatible string
and (if applicable) may contain a chassis-version RCPM compatible
@@ -20,6 +20,7 @@ Required properites:
* "fsl,qoriq-rcpm-1.0": for chassis 1.0 rcpm
* "fsl,qoriq-rcpm-2.0": for chassis 2.0 rcpm
* "fsl,qoriq-rcpm-2.1": for chassis 2.1 rcpm
+   * "fsl,qoriq-rcpm-2.1+": for chassis 2.1+ rcpm
 
 All references to "1.0" and "2.0" refer to the QorIQ chassis version to
 which the chip complies.
@@ -27,14 +28,19 @@ Chassis Version Example Chips
 ------
 1.0p4080, p5020, p5040, p2041, p3041
 2.0t4240, b4860, b4420
-2.1t1040, ls1021
+2.1t1040,
+2.1+   ls1021a, ls1012a, ls1043a, ls1046a
+
+Optional properties:
+ - little-endian : RCPM register block is Little Endian. Without it RCPM
+   will be Big Endian (default case).
 
 Example:
 The RCPM node for T4240:
rcpm: global-utilities@e2000 {
compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0";
reg = <0xe2000 0x1000>;
-   fsl,#rcpm-wakeup-cells = <2>;
+   #fsl,rcpm-wakeup-cells = <2>;
};
 
 * Freescale RCPM Wakeup Source Device Tree Bindings
@@ -44,7 +50,7 @@ can be used as a wakeup source.
 
   - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR
register cells. The number of IPPDEXPCR register cells is defined in
-   "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is
+   "#fsl,rcpm-wakeup-cells" in the rcpm node. The first register cell is
the bit mask that should be set in IPPDEXPCR0, and the second register
cell is for IPPDEXPCR1, and so on.
 
-- 
2.7.4



[PATCH v5 3/3] soc: fsl: add RCPM driver

2019-07-24 Thread Ran Wang
The NXP's QorIQ Processors based on ARM Core have RCPM module
(Run Control and Power Management), which performs all device-level
tasks associated with power management such as wakeup source control.

This driver depends on PM wakeup source framework which help to
collect wake information.

Signed-off-by: Ran Wang 
Acked-by: Pavel Machek 
---
Change in v5:
- Fix v4 regression of the return value of wakeup_source_get_next()
didn't pass to ws in while loop.
- Rename wakeup_source member 'attached_dev' to 'dev'.
- Rename property 'fsl,#rcpm-wakeup-cells' to '#fsl,rcpm-wakeup-cells'.
please see https://lore.kernel.org/patchwork/patch/1101022/

Change in v4:
- Remove extra ',' in author line of rcpm.c
- Update usage of wakeup_source_get_next() to be less confusing to the
reader, code logic remain the same.

Change in v3:
- Some whitespace ajdustment.

Change in v2:
- Rebase Kconfig and Makefile update to latest mainline.

 drivers/soc/fsl/Kconfig  |   8 +++
 drivers/soc/fsl/Makefile |   1 +
 drivers/soc/fsl/rcpm.c   | 126 +++
 3 files changed, 135 insertions(+)
 create mode 100644 drivers/soc/fsl/rcpm.c

diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig
index f9ad8ad..4918856 100644
--- a/drivers/soc/fsl/Kconfig
+++ b/drivers/soc/fsl/Kconfig
@@ -40,4 +40,12 @@ config DPAA2_CONSOLE
  /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
  which can be used to dump the Management Complex and AIOP
  firmware logs.
+
+config FSL_RCPM
+   bool "Freescale RCPM support"
+   depends on PM_SLEEP
+   help
+ The NXP QorIQ Processors based on ARM Core have RCPM module
+ (Run Control and Power Management), which performs all device-level
+ tasks associated with power management, such as wakeup source control.
 endmenu
diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile
index 71dee8d..906f1cd 100644
--- a/drivers/soc/fsl/Makefile
+++ b/drivers/soc/fsl/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_FSL_DPAA) += qbman/
 obj-$(CONFIG_QUICC_ENGINE) += qe/
 obj-$(CONFIG_CPM)  += qe/
+obj-$(CONFIG_FSL_RCPM) += rcpm.o
 obj-$(CONFIG_FSL_GUTS) += guts.o
 obj-$(CONFIG_FSL_MC_DPIO)  += dpio/
 obj-$(CONFIG_DPAA2_CONSOLE)+= dpaa2-console.o
diff --git a/drivers/soc/fsl/rcpm.c b/drivers/soc/fsl/rcpm.c
new file mode 100644
index 000..02244a1
--- /dev/null
+++ b/drivers/soc/fsl/rcpm.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rcpm.c - Freescale QorIQ RCPM driver
+//
+// Copyright 2019 NXP
+//
+// Author: Ran Wang 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RCPM_WAKEUP_CELL_MAX_SIZE  7
+
+struct rcpm {
+   unsigned intwakeup_cells;
+   void __iomem*ippdexpcr_base;
+   boollittle_endian;
+};
+
+static int rcpm_pm_prepare(struct device *dev)
+{
+   struct device_node  *np = dev->of_node;
+   struct wakeup_source*ws;
+   struct rcpm *rcpm;
+   u32 value[RCPM_WAKEUP_CELL_MAX_SIZE + 1], tmp;
+   int i, ret;
+
+   rcpm = dev_get_drvdata(dev);
+   if (!rcpm)
+   return -EINVAL;
+
+   /* Begin with first registered wakeup source */
+   ws = NULL;
+   while (ws = wakeup_source_get_next(ws)) {
+   /* skip object which is not attached to device */
+   if (!ws->dev)
+   continue;
+
+   ret = device_property_read_u32_array(ws->dev,
+   "fsl,rcpm-wakeup", value, rcpm->wakeup_cells + 
1);
+
+   /*  Wakeup source should refer to current rcpm device */
+   if (ret || (np->phandle != value[0])) {
+   dev_info(dev, "%s doesn't refer to this rcpm\n",
+   ws->name);
+   continue;
+   }
+
+   for (i = 0; i < rcpm->wakeup_cells; i++) {
+   /* We can only OR related bits */
+   if (value[i + 1]) {
+   if (rcpm->little_endian) {
+   tmp = ioread32(rcpm->ippdexpcr_base + i 
* 4);
+   tmp |= value[i + 1];
+   iowrite32(tmp, rcpm->ippdexpcr_base + i 
* 4);
+   } else {
+   tmp = ioread32be(rcpm->ippdexpcr_base + 
i * 4);
+   tmp |= value[i + 1];
+   iowrite32be(tmp, rcpm->ippdexpcr_base + 
i * 4);
+   }
+   }
+   }
+   }
+
+   return 0;
+}
+
+static const 

[PATCH v5 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-07-24 Thread Ran Wang
Some user might want to go through all registered wakeup sources
and doing things accordingly. For example, SoC PM driver might need to
do HW programming to prevent powering down specific IP which wakeup
source depending on. So add this API to help walk through all registered
wakeup source objects on that list and return them one by one.

Signed-off-by: Ran Wang 
---
Change in v5:
- Update commit message, add decription of walk through all wakeup
source objects.
- Add SCU protection in function wakeup_source_get_next().
- Rename wakeup_source member 'attached_dev' to 'dev' and move it up
(before wakeirq).

Change in v4:
- None.

Change in v3:
- Adjust indentation of *attached_dev;.

Change in v2:
- None.

 drivers/base/power/wakeup.c | 24 
 include/linux/pm_wakeup.h   |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index ee31d4f..2fba891 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -226,6 +227,28 @@ void wakeup_source_unregister(struct wakeup_source *ws)
}
 }
 EXPORT_SYMBOL_GPL(wakeup_source_unregister);
+/**
+ * wakeup_source_get_next - Get next wakeup source from the list
+ * @ws: Previous wakeup source object, null means caller want first one.
+ */
+struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws)
+{
+   struct list_head *ws_head = _sources;
+   struct wakeup_source *next_ws = NULL;
+   int idx;
+
+   idx = srcu_read_lock(_srcu);
+   if (ws)
+   next_ws = list_next_or_null_rcu(ws_head, >entry,
+   struct wakeup_source, entry);
+   else
+   next_ws = list_entry_rcu(ws_head->next,
+   struct wakeup_source, entry);
+   srcu_read_unlock(_srcu, idx);
+
+   return next_ws;
+}
+EXPORT_SYMBOL_GPL(wakeup_source_get_next);
 
 /**
  * device_wakeup_attach - Attach a wakeup source object to a device object.
@@ -242,6 +265,7 @@ static int device_wakeup_attach(struct device *dev, struct 
wakeup_source *ws)
return -EEXIST;
}
dev->power.wakeup = ws;
+   ws->dev = dev;
if (dev->power.wakeirq)
device_wakeup_attach_irq(dev, dev->power.wakeirq);
spin_unlock_irq(>power.lock);
diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 9102760..fc23c1a 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -23,6 +23,7 @@ struct wake_irq;
  * @name: Name of the wakeup source
  * @entry: Wakeup source list entry
  * @lock: Wakeup source lock
+ * @dev: The device it attached to
  * @wakeirq: Optional device specific wakeirq
  * @timer: Wakeup timer list
  * @timer_expires: Wakeup timer expiration
@@ -42,6 +43,7 @@ struct wakeup_source {
const char  *name;
struct list_headentry;
spinlock_t  lock;
+   struct device   *dev;
struct wake_irq *wakeirq;
struct timer_list   timer;
unsigned long   timer_expires;
@@ -88,6 +90,7 @@ extern void wakeup_source_add(struct wakeup_source *ws);
 extern void wakeup_source_remove(struct wakeup_source *ws);
 extern struct wakeup_source *wakeup_source_register(const char *name);
 extern void wakeup_source_unregister(struct wakeup_source *ws);
+extern struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws);
 extern int device_wakeup_enable(struct device *dev);
 extern int device_wakeup_disable(struct device *dev);
 extern void device_set_wakeup_capable(struct device *dev, bool capable);
-- 
2.7.4



RE: [PATCH AUTOSEL 5.1 08/39] arm64: dts: ls1028a: Fix CPU idle fail.

2019-07-10 Thread Ran Wang
Hi Sasha, 

Thanks for helping port this patch to stable.
May I know if I can submit other bug fixes which has been accepted by 
upstream to stable by myself?
If yes, where I can find related process for reference?

Thanks & Regards,
Ran

> -Original Message-
> From: Sasha Levin 
> Sent: Wednesday, July 03, 2019 10:15
> To: linux-kernel@vger.kernel.org; sta...@vger.kernel.org
> Cc: Ran Wang ; Shawn Guo ;
> Sasha Levin ; devicet...@vger.kernel.org
> Subject: [PATCH AUTOSEL 5.1 08/39] arm64: dts: ls1028a: Fix CPU idle fail.
> 
> From: Ran Wang 
> 
> [ Upstream commit 53f2ac9d3aa881ed419054076042898b77c27ee4 ]
> 
> PSCI spec define 1st parameter's bit 16 of function CPU_SUSPEND to indicate
> CPU State Type: 0 for standby, 1 for power down. In this case, we want to 
> select
> standby for CPU idle feature. But current setting wrongly select power down 
> and
> cause CPU SUSPEND fail every time. Need this fix.
> 
> Fixes: 8897f3255c9c ("arm64: dts: Add support for NXP LS1028A SoC")
> Signed-off-by: Ran Wang 
> Signed-off-by: Shawn Guo 
> Signed-off-by: Sasha Levin 
> ---
>  arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
> b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
> index 2896bbcfa3bb..228872549f01 100644
> --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
> +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi
> @@ -28,7 +28,7 @@
>   enable-method = "psci";
>   clocks = < 1 0>;
>   next-level-cache = <>;
> - cpu-idle-states = <_PH20>;
> + cpu-idle-states = <_PW20>;
>   };
> 
>   cpu1: cpu@1 {
> @@ -38,7 +38,7 @@
>   enable-method = "psci";
>   clocks = < 1 0>;
>   next-level-cache = <>;
> - cpu-idle-states = <_PH20>;
> + cpu-idle-states = <_PW20>;
>   };
> 
>   l2: l2-cache {
> @@ -53,13 +53,13 @@
>*/
>   entry-method = "arm,psci";
> 
> - CPU_PH20: cpu-ph20 {
> - compatible = "arm,idle-state";
> - idle-state-name = "PH20";
> - arm,psci-suspend-param = <0x0001>;
> - entry-latency-us = <1000>;
> - exit-latency-us = <1000>;
> - min-residency-us = <3000>;
> + CPU_PW20: cpu-pw20 {
> +   compatible = "arm,idle-state";
> +   idle-state-name = "PW20";
> +   arm,psci-suspend-param = <0x0>;
> +   entry-latency-us = <2000>;
> +   exit-latency-us = <2000>;
> +   min-residency-us = <6000>;
>   };
>   };
> 
> --
> 2.20.1



RE: [PATCH] usb: dwc3: Enable the USB snooping

2019-07-09 Thread Ran Wang
Hi Felipe,

On Monday, June 24, 2019 13:58, Felipe Balbi wrote:
> 
> Hi,
> 
> Ran Wang  writes:
> >> >> > >> >> >  /* Global Debug Queue/FIFO Space Available Register */
> >> >> > >> >> >  #define DWC3_GDBGFIFOSPACE_NUM(n)((n) & 0x1f)
> >> >> > >> >> >  #define DWC3_GDBGFIFOSPACE_TYPE(n)   (((n) << 5) & 0x1e0)
> >> >> > >> >> > @@ -859,6 +867,7 @@ struct dwc3_scratchpad_array {
> >> >> > >> >> >   *   3   - Reserved
> >> >> > >> >> >   * @imod_interval: set the interrupt moderation interval in
> 250ns
> >> >> > >> >> >   * increments or 0 to disable.
> >> >> > >> >> > + * @dma_coherent: set if enable dma-coherent.
> >> >> > >> >>
> >> >> > >> >> you're not enabling dma coherency, you're enabling cache
> snooping.
> >> >> > >> >> And this property should describe that. Also, keep in mind
> >> >> > >> >> that different devices may want different cache types for
> >> >> > >> >> each of those fields, so your property would have to be a
> >> >> > >> >> lot more complex. Something
> >> >> > like:
> >> >> > >> >>
> >> >> > >> >> snps,cache-type = ,  >> >> > >> >> "cacheable">, ...
> >> >> > >> >>
> >> >> > >> >> Then driver would have to parse this properly to setup 
> >> >> > >> >> GSBUSCFG0.
> >> >> > >
> >> >> > > According to the DesignWare Cores SuperSpeed USB 3.0
> >> >> > > Controller Databook (v2.60a), it has described Type Bit
> >> >> > > Assignments for all supported
> >> >> > master bus type:
> >> >> > > AHB, AXI3, AXI4 and Native. I found the bit definition are
> >> >> > > different among
> >> >> > them.
> >> >> > > So, for the example you gave above, feel a little bit confused.
> >> >> > > Did you mean:
> >> >> > > snps,cache-type = ,  >> >> > > "cacheable">, ,  >> >> > > allocate">
> >> >> >
> >> >> > yeah, something like that.
> >> >>
> >> >> I think DATA_RD  should be a macro, right? So, where I can put its 
> >> >> define?
> >> >> Create a dwc3.h in include/dt-bindings/usb/ ?
> >> >
> >> > Could you please give me some advice here? I'd like to prepare next
> >> > version patch after getting this settled.
> >> >
> >> >> Another question about this remain open is: DWC3 data book's Table
> >> >> 6-5 Cache Type Bit Assignments show that bits definition will
> >> >> differ per MBUS_TYPEs as
> >> >> below:
> >> >> 
> >> >>  MBUS_TYPE| bit[3]   |bit[2]   |bit[1] |bit[0]
> >> >>  
> >> >>  AHB  |Cacheable |Bufferable   |Privilegge |Data
> >> >>  AXI3 |Write Allocate|Read Allocate|Cacheable  |Bufferable
> >> >>  AXI4 |Allocate Other|Allocate |Modifiable |Bufferable
> >> >>  AXI4 |Other Allocate|Allocate |Modifiable |Bufferable
> >> >>  Native   |Same as AXI   |Same as AXI  |Same as AXI|Same as AXI
> >> >>  
> >> >>  Note: The AHB, AXI3, AXI4, and PCIe busses use different names
> >> >> for certain  signals, which have the same meaning:
> >> >>Bufferable = Posted
> >> >>Cacheable = Modifiable = Snoop (negation of No Snoop)
> >> >>
> >> >> For Layerscape SoCs, MBUS_TYPE is AXI3. So I am not sure how to
> >> >> use snps,cache-type = , to cover all
> MBUS_TYPE?
> >> >> (you can notice that AHB and AXI3's cacheable are on different
> >> >> bit) Or I just need to handle AXI3 case?
> >> >
> >> > Also on this open. Thank you in advance.
> >>
> >> You could pass two strings and

RE: [PATCH] usb: dwc3: Enable the USB snooping

2019-06-23 Thread Ran Wang
Hi Felipe,

On Monday, June 17, 2019 20:53, Felipe Balbi wrote:
> Hi,
> 
> Ran Wang  writes:
> > Hi Felipe,
> >
> > On Thursday, May 30, 2019 17:09, Ran Wang wrote:
> >>
> >> 
> >> > >> >> >  /* Global Debug Queue/FIFO Space Available Register */
> >> > >> >> >  #define DWC3_GDBGFIFOSPACE_NUM(n)   ((n) & 0x1f)
> >> > >> >> >  #define DWC3_GDBGFIFOSPACE_TYPE(n)  (((n) << 5) & 0x1e0)
> >> > >> >> > @@ -859,6 +867,7 @@ struct dwc3_scratchpad_array {
> >> > >> >> >   *  3   - Reserved
> >> > >> >> >   * @imod_interval: set the interrupt moderation interval in 
> >> > >> >> > 250ns
> >> > >> >> >   * increments or 0 to disable.
> >> > >> >> > + * @dma_coherent: set if enable dma-coherent.
> >> > >> >>
> >> > >> >> you're not enabling dma coherency, you're enabling cache snooping.
> >> > >> >> And this property should describe that. Also, keep in mind
> >> > >> >> that different devices may want different cache types for
> >> > >> >> each of those fields, so your property would have to be a lot
> >> > >> >> more complex. Something
> >> > like:
> >> > >> >>
> >> > >> >>snps,cache-type = , , ...
> >> > >> >>
> >> > >> >> Then driver would have to parse this properly to setup GSBUSCFG0.
> >> > >
> >> > > According to the DesignWare Cores SuperSpeed USB 3.0 Controller
> >> > > Databook (v2.60a), it has described Type Bit Assignments for all
> >> > > supported
> >> > master bus type:
> >> > > AHB, AXI3, AXI4 and Native. I found the bit definition are
> >> > > different among
> >> > them.
> >> > > So, for the example you gave above, feel a little bit confused.
> >> > > Did you mean:
> >> > > snps,cache-type = ,  >> > > "cacheable">, , 
> >> >
> >> > yeah, something like that.
> >>
> >> I think DATA_RD  should be a macro, right? So, where I can put its define?
> >> Create a dwc3.h in include/dt-bindings/usb/ ?
> >
> > Could you please give me some advice here? I'd like to prepare next
> > version patch after getting this settled.
> >
> >> Another question about this remain open is: DWC3 data book's Table
> >> 6-5 Cache Type Bit Assignments show that bits definition will differ
> >> per MBUS_TYPEs as
> >> below:
> >> 
> >>  MBUS_TYPE| bit[3]   |bit[2]   |bit[1] |bit[0]
> >>  
> >>  AHB  |Cacheable |Bufferable   |Privilegge |Data
> >>  AXI3 |Write Allocate|Read Allocate|Cacheable  |Bufferable
> >>  AXI4 |Allocate Other|Allocate |Modifiable |Bufferable
> >>  AXI4 |Other Allocate|Allocate |Modifiable |Bufferable
> >>  Native   |Same as AXI   |Same as AXI  |Same as AXI|Same as AXI
> >>  
> >>  Note: The AHB, AXI3, AXI4, and PCIe busses use different names for
> >> certain  signals, which have the same meaning:
> >>Bufferable = Posted
> >>Cacheable = Modifiable = Snoop (negation of No Snoop)
> >>
> >> For Layerscape SoCs, MBUS_TYPE is AXI3. So I am not sure how to use
> >> snps,cache-type = , to cover all MBUS_TYPE?
> >> (you can notice that AHB and AXI3's cacheable are on different bit)
> >> Or I just need to handle AXI3 case?
> >
> > Also on this open. Thank you in advance.
> 
> You could pass two strings and let the driver process them. Something
> like:
> 
>   snps,cache_type = <"data_wr" "write allocate">, <"desc_rd"
> "cacheable">...
> 
> And so on. The only thing missing is for the mbus_type to be known by the 
> driver.
> Is that something we can figure out on any of the HWPARAMS registers or does
> it have to be told explicitly?

I have checked Layerscape Reference manual, HWPARAMS0~8 doesn't contain 
mbus_type
Info, and I didn't know where have declared it explicitly.

> Another option would be to pass a string followed by one hex digit for the 
> bits:
> 
>   snps,cache_type = <"data_wr" 0x8>, <"desc_rd" 0x2>...;
> 
> Then we don't need to describe mbus_type since the bits are what matters.

Yes, it's also what we prefer to use, it will be more flexible, I can add above 
Table
6-5 Cache Type Bit Assignments in binding to help user decide which value they
would use.

I would submit another version of patch for further review, thank you very much.

Regards,
Ran

> Rob, any comments?
> 
> --
> balbi


RE: [PATCH v4 1/3] PM: wakeup: Add routine to help fetch wakeup source object.

2019-06-19 Thread Ran Wang
Hi Rafael,

On Wednesday, June 19, 2019 06:45, Rafael J. Wysocki wrote:
> 
> On Monday, May 20, 2019 11:52:36 AM CEST Ran Wang wrote:
> > Some user might want to go through all registered wakeup sources and
> > doing things accordingly. For example, SoC PM driver might need to do
> > HW programming to prevent powering down specific IP which wakeup
> > source depending on. And is user's responsibility to identify if this
> > wakeup source he is interested in.
> 
> I guess the idea here is that you need to walk wakeup devices and you noticed
> that there was a wakeup source object for each of them and those wakeup
> source objects were on a list, so you could walk wakeup devices by walking the
> list of wakeup source objects.
> 
> That is fair enough, but the changelog above doesn't even talk about that.

How about this:
"Providing a API for helping walk through all registered wakeup devices on the 
list.
It will be useful for SoC PMU driver to know which device will work as a wakeup
source then do specific HW programming for them."

> > Signed-off-by: Ran Wang 
> > ---
> > Change in v4:
> > - None.
> >
> > Change in v3:
> > - Adjust indentation of *attached_dev;.
> >
> > Change in v2:
> > - None.
> >
> >  drivers/base/power/wakeup.c |   18 ++
> >  include/linux/pm_wakeup.h   |3 +++
> >  2 files changed, 21 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> > index 5b2b6a0..6904485 100644
> > --- a/drivers/base/power/wakeup.c
> > +++ b/drivers/base/power/wakeup.c
> > @@ -14,6 +14,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >
> > @@ -226,6 +227,22 @@ void wakeup_source_unregister(struct
> wakeup_source *ws)
> > }
> >  }
> >  EXPORT_SYMBOL_GPL(wakeup_source_unregister);
> > +/**
> > + * wakeup_source_get_next - Get next wakeup source from the list
> > + * @ws: Previous wakeup source object, null means caller want first one.
> > + */
> > +struct wakeup_source *wakeup_source_get_next(struct wakeup_source
> > +*ws) {
> > +   struct list_head *ws_head = _sources;
> > +
> > +   if (ws)
> > +   return list_next_or_null_rcu(ws_head, >entry,
> > +   struct wakeup_source, entry);
> > +   else
> > +   return list_entry_rcu(ws_head->next,
> > +   struct wakeup_source, entry);
> > +}
> > +EXPORT_SYMBOL_GPL(wakeup_source_get_next);
> 
> This needs to be arranged along the lines of
> wakeup_sources_stats_seq_start/next/stop()
> because of the SRCU protection of the list.

Got it, how about this:
 230 /**
  
 231  * wakeup_source_get_next - Get next wakeup source from the list   
  
 232  * @ws: Previous wakeup source object, null means caller want first one.   
  
 233  */
  
 234 struct wakeup_source *wakeup_source_get_next(struct wakeup_source *ws) 
  
 235 {  
  
 236 struct list_head *ws_head = _sources;   
  
 237 struct wakeup_source *next_ws = NULL;  
  
 238 int idx;   
  
 239
  
 240 idx = srcu_read_lock(_srcu);
  
 241 if (ws)

 242 next_ws = list_next_or_null_rcu(ws_head, >entry,   
  
 243 struct wakeup_source, entry);  
  
 244 else   
  
 245 next_ws = list_entry_rcu(ws_head->next,
  
 246 struct wakeup_source, entry);  
  
 247 srcu_read_unlock(_srcu, idx);   
  
 248
  
 249 return next_ws;
  
 250 }  
  
 251 EXPORT_SYMBOL_GPL(wakeup_source_get_next);   

> >
> >  /**
> >   * device_wakeup_attach - 

RE: [RESEND][PATCH v3 1/2] usb: dwc3: Add avoiding vbus glitch happen during xhci reset

2019-06-06 Thread Ran Wang
Hi Sergei,

On Thursday, June 06, 2019 16:17 Sergei Shtylyov wrote:
> 
> Hello!
> 
> On 06.06.2019 5:54, Ran Wang wrote:
> 
> > When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS
> > (or its control signal) will turn on immediately on related Root Hub
> > ports. Then the VBUS will be de-asserted for a little while during
> > xhci reset (conducted by xhci driver) for a little while and back to normal.
> >
> > This VBUS glitch might cause some USB devices emuration fail if kernel
> 
> Enumeration. :-)

Thanks, will correct it in next version
 
Regards,
Ran

> > boot with them connected. One SW workaround which can fix this is to
> > program all PORTSC[PP] to 0 to turn off VBUS immediately after setting
> > host mode in DWC3 driver(per signal measurement result, it will be too
> > late to do it in xhci-plat.c or xhci.c).
> >
> > Signed-off-by: Ran Wang 
> > Reviewed-by: Rob Herring 
> [...]
> 
> MBR, Sergei


  1   2   3   >