Re: [PATCH 1/2] power: pmic: rk8xx: Support sysreset shutdown method

2022-05-26 Thread Kever Yang

Hi Chris,


On 2022/5/24 03:30, Chris Morgan wrote:

From: Chris Morgan 

Add support for sysreset shutdown for this PMIC. The values were pulled
from the various datasheets, but for now it has only been tested on
the rk817 (for an Odroid Go Advance).

Signed-off-by: Chris Morgan 


Reviewed-by: Kever Yang 


Thanks,

- Kever


---
  drivers/power/pmic/rk8xx.c | 50 +-
  1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c
index 5f442fea68..1ffbecc02a 100644
--- a/drivers/power/pmic/rk8xx.c
+++ b/drivers/power/pmic/rk8xx.c
@@ -6,10 +6,50 @@
  
  #include 

  #include 
+#include 
  #include 
  #include 
  #include 
  #include 
+#include 
+
+static int rk8xx_sysreset_request(struct udevice *dev, enum sysreset_t type)
+{
+   struct rk8xx_priv *priv = dev_get_priv(dev->parent);
+
+   if (type != SYSRESET_POWER_OFF)
+   return -EPROTONOSUPPORT;
+
+   switch (priv->variant) {
+   case RK805_ID:
+   case RK808_ID:
+   case RK816_ID:
+   case RK818_ID:
+   pmic_clrsetbits(dev->parent, REG_DEVCTRL, 0, BIT(0));
+   break;
+   case RK809_ID:
+   case RK817_ID:
+   pmic_clrsetbits(dev->parent, RK817_REG_SYS_CFG3, 0,
+   BIT(0));
+   break;
+   default:
+   printf("Unknown PMIC RK%x: Cannot shutdown\n",
+  priv->variant);
+   return -EPROTONOSUPPORT;
+   };
+
+   return -EINPROGRESS;
+}
+
+static struct sysreset_ops rk8xx_sysreset_ops = {
+   .request= rk8xx_sysreset_request,
+};
+
+U_BOOT_DRIVER(rk8xx_sysreset) = {
+   .name   = "rk8xx_sysreset",
+   .id = UCLASS_SYSRESET,
+   .ops= _sysreset_ops,
+};
  
  static struct reg_data rk817_init_reg[] = {

  /* enable the under-voltage protection,
@@ -61,7 +101,7 @@ static int rk8xx_read(struct udevice *dev, uint reg, uint8_t 
*buff, int len)
  static int rk8xx_bind(struct udevice *dev)
  {
ofnode regulators_node;
-   int children;
+   int children, ret;
  
  	regulators_node = dev_read_subnode(dev, "regulators");

if (!ofnode_valid(regulators_node)) {
@@ -72,6 +112,14 @@ static int rk8xx_bind(struct udevice *dev)
  
  	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
  
+	if (CONFIG_IS_ENABLED(SYSRESET)) {

+   ret = device_bind_driver_to_node(dev, "rk8xx_sysreset",
+"rk8xx_sysreset",
+dev_ofnode(dev), NULL);
+   if (ret)
+   return ret;
+   }
+
children = pmic_bind_children(dev, regulators_node, pmic_children_info);
if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);


Re: [PATCH 1/2] power: pmic: rk8xx: Support sysreset shutdown method

2022-05-25 Thread Jaehoon Chung
On 5/24/22 04:30, Chris Morgan wrote:
> From: Chris Morgan 
> 
> Add support for sysreset shutdown for this PMIC. The values were pulled
> from the various datasheets, but for now it has only been tested on
> the rk817 (for an Odroid Go Advance).
> 
> Signed-off-by: Chris Morgan 

Reviewed-by: Jaehoon Chung 

Best Regards,
Jaehoon Chung

> ---
>  drivers/power/pmic/rk8xx.c | 50 +-
>  1 file changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c
> index 5f442fea68..1ffbecc02a 100644
> --- a/drivers/power/pmic/rk8xx.c
> +++ b/drivers/power/pmic/rk8xx.c
> @@ -6,10 +6,50 @@
>  
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
> +
> +static int rk8xx_sysreset_request(struct udevice *dev, enum sysreset_t type)
> +{
> + struct rk8xx_priv *priv = dev_get_priv(dev->parent);
> +
> + if (type != SYSRESET_POWER_OFF)
> + return -EPROTONOSUPPORT;
> +
> + switch (priv->variant) {
> + case RK805_ID:
> + case RK808_ID:
> + case RK816_ID:
> + case RK818_ID:
> + pmic_clrsetbits(dev->parent, REG_DEVCTRL, 0, BIT(0));
> + break;
> + case RK809_ID:
> + case RK817_ID:
> + pmic_clrsetbits(dev->parent, RK817_REG_SYS_CFG3, 0,
> + BIT(0));
> + break;
> + default:
> + printf("Unknown PMIC RK%x: Cannot shutdown\n",
> +priv->variant);
> + return -EPROTONOSUPPORT;
> + };
> +
> + return -EINPROGRESS;
> +}
> +
> +static struct sysreset_ops rk8xx_sysreset_ops = {
> + .request= rk8xx_sysreset_request,
> +};
> +
> +U_BOOT_DRIVER(rk8xx_sysreset) = {
> + .name   = "rk8xx_sysreset",
> + .id = UCLASS_SYSRESET,
> + .ops= _sysreset_ops,
> +};
>  
>  static struct reg_data rk817_init_reg[] = {
>  /* enable the under-voltage protection,
> @@ -61,7 +101,7 @@ static int rk8xx_read(struct udevice *dev, uint reg, 
> uint8_t *buff, int len)
>  static int rk8xx_bind(struct udevice *dev)
>  {
>   ofnode regulators_node;
> - int children;
> + int children, ret;
>  
>   regulators_node = dev_read_subnode(dev, "regulators");
>   if (!ofnode_valid(regulators_node)) {
> @@ -72,6 +112,14 @@ static int rk8xx_bind(struct udevice *dev)
>  
>   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
>  
> + if (CONFIG_IS_ENABLED(SYSRESET)) {
> + ret = device_bind_driver_to_node(dev, "rk8xx_sysreset",
> +  "rk8xx_sysreset",
> +  dev_ofnode(dev), NULL);
> + if (ret)
> + return ret;
> + }
> +
>   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
>   if (!children)
>   debug("%s: %s - no child found\n", __func__, dev->name);



[PATCH 1/2] power: pmic: rk8xx: Support sysreset shutdown method

2022-05-23 Thread Chris Morgan
From: Chris Morgan 

Add support for sysreset shutdown for this PMIC. The values were pulled
from the various datasheets, but for now it has only been tested on
the rk817 (for an Odroid Go Advance).

Signed-off-by: Chris Morgan 
---
 drivers/power/pmic/rk8xx.c | 50 +-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c
index 5f442fea68..1ffbecc02a 100644
--- a/drivers/power/pmic/rk8xx.c
+++ b/drivers/power/pmic/rk8xx.c
@@ -6,10 +6,50 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+
+static int rk8xx_sysreset_request(struct udevice *dev, enum sysreset_t type)
+{
+   struct rk8xx_priv *priv = dev_get_priv(dev->parent);
+
+   if (type != SYSRESET_POWER_OFF)
+   return -EPROTONOSUPPORT;
+
+   switch (priv->variant) {
+   case RK805_ID:
+   case RK808_ID:
+   case RK816_ID:
+   case RK818_ID:
+   pmic_clrsetbits(dev->parent, REG_DEVCTRL, 0, BIT(0));
+   break;
+   case RK809_ID:
+   case RK817_ID:
+   pmic_clrsetbits(dev->parent, RK817_REG_SYS_CFG3, 0,
+   BIT(0));
+   break;
+   default:
+   printf("Unknown PMIC RK%x: Cannot shutdown\n",
+  priv->variant);
+   return -EPROTONOSUPPORT;
+   };
+
+   return -EINPROGRESS;
+}
+
+static struct sysreset_ops rk8xx_sysreset_ops = {
+   .request= rk8xx_sysreset_request,
+};
+
+U_BOOT_DRIVER(rk8xx_sysreset) = {
+   .name   = "rk8xx_sysreset",
+   .id = UCLASS_SYSRESET,
+   .ops= _sysreset_ops,
+};
 
 static struct reg_data rk817_init_reg[] = {
 /* enable the under-voltage protection,
@@ -61,7 +101,7 @@ static int rk8xx_read(struct udevice *dev, uint reg, uint8_t 
*buff, int len)
 static int rk8xx_bind(struct udevice *dev)
 {
ofnode regulators_node;
-   int children;
+   int children, ret;
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
@@ -72,6 +112,14 @@ static int rk8xx_bind(struct udevice *dev)
 
debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
 
+   if (CONFIG_IS_ENABLED(SYSRESET)) {
+   ret = device_bind_driver_to_node(dev, "rk8xx_sysreset",
+"rk8xx_sysreset",
+dev_ofnode(dev), NULL);
+   if (ret)
+   return ret;
+   }
+
children = pmic_bind_children(dev, regulators_node, pmic_children_info);
if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
-- 
2.25.1