You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/07/26 09:07:57 UTC

[incubator-nuttx] 01/02: driver/power: add charge protocol get

This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 4ef7cf068bb7a75d5d93e4d1acf4917a284c3d4f
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jul 21 14:48:29 2022 +0000

    driver/power: add charge protocol get
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 drivers/power/battery_charger.c       | 10 ++++++++++
 include/nuttx/power/battery_charger.h |  6 +++++-
 include/nuttx/power/battery_ioctl.h   |  9 +++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/power/battery_charger.c b/drivers/power/battery_charger.c
index a4965a5527..1cd4565e89 100644
--- a/drivers/power/battery_charger.c
+++ b/drivers/power/battery_charger.c
@@ -388,6 +388,16 @@ static int bat_charger_ioctl(FAR struct file *filep, int cmd,
         }
         break;
 
+      case BATIOC_GET_PROTOCOL:
+        {
+          FAR int *ptr = (FAR int *)(uintptr_t)arg;
+          if (ptr)
+            {
+              ret = dev->ops->get_protocol(dev, ptr);
+            }
+        }
+        break;
+
       default:
         _err("ERROR: Unrecognized cmd: %d\n", cmd);
         ret = -ENOTTY;
diff --git a/include/nuttx/power/battery_charger.h b/include/nuttx/power/battery_charger.h
index eee63486ca..ba948a8616 100644
--- a/include/nuttx/power/battery_charger.h
+++ b/include/nuttx/power/battery_charger.h
@@ -125,7 +125,11 @@ struct battery_charger_operations_s
 
   /* Get the actual output voltage for charging */
 
-  int (*get_voltage)(struct battery_charger_dev_s *dev, int *value);
+  int (*get_voltage)(struct battery_charger_dev_s *dev, FAR int *value);
+
+  /* Get charge protocol */
+
+  int (*get_protocol)(struct battery_charger_dev_s *dev, FAR int *value);
 };
 
 /* This structure defines the battery driver state structure */
diff --git a/include/nuttx/power/battery_ioctl.h b/include/nuttx/power/battery_ioctl.h
index 90be4614e6..d7f8abddad 100644
--- a/include/nuttx/power/battery_ioctl.h
+++ b/include/nuttx/power/battery_ioctl.h
@@ -56,6 +56,7 @@
 #define BATIOC_COULOMBS      _BATIOC(0x0010)
 #define BATIOC_CHIPID        _BATIOC(0x0011)
 #define BATIOC_GET_VOLTAGE   _BATIOC(0x0012)
+#define BATIOC_GET_PROTOCOL  _BATIOC(0x0013)
 
 /* Special input values for BATIOC_INPUT_CURRENT that may optionally
  * be supported by lower-half driver:
@@ -110,6 +111,14 @@ enum battery_health_e
   BATTERY_HEALTH_DISCONNECTED   /* Battery is not connected */
 };
 
+/* battery charge protocol type */
+
+enum battery_protocol_e
+{
+  BATTERY_PROTOCOL_QC3P0 = 1 << 0,      /* Battery charge protocol of adapter is QC 3.0 */
+  BATTERY_PROTOCOL_TX_XIAOMI = 1 << 1,  /* Battery charge protocol of TX is xiaomi standard */
+};
+
 /* Battery operation message */
 
 struct batio_operate_msg_s