TimJTi commented on code in PR #8088:
URL: https://github.com/apache/nuttx/pull/8088#discussion_r1126387513


##########
drivers/power/supply/act8945a.c:
##########
@@ -0,0 +1,1081 @@
+/****************************************************************************
+ * drivers/power/supply/act8945a.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <string.h>
+#include <debug.h>
+#include <poll.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/spinlock.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/power/regulator.h>
+#include <nuttx/power/act8945a.h>
+
+#if defined(CONFIG_I2C) && defined(CONFIG_REGULATOR_ACT8945A)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+#define ACT8945A_BUS_SPEED                        300000
+#define ACT8945A_SLAVE_ADDRESS                    0x5b
+
+#ifdef CONFIG_DEBUG_POWER_ERROR
+#  define act8945a_err(x, ...)        _err(x, ##__VA_ARGS__)
+#else
+#  define act8945a_err(x, ...)        uerr(x, ##__VA_ARGS__)
+#endif
+#ifdef CONFIG_DEBUG_POWER_WARN
+#  define act8945a_warn(x, ...)       _warn(x, ##__VA_ARGS__)
+#else
+#  define act8945a_warn(x, ...)       uwarn(x, ##__VA_ARGS__)
+#endif
+#ifdef CONFIG_DEBUG_POWER_INFO
+#  define act8945a_info(x, ...)       _info(x, ##__VA_ARGS__)
+#else
+#  define act8945a_info(x, ...)       uinfo(x, ##__VA_ARGS__)
+#endif
+
+#define ACT8945A_NUM_VOLTAGES                     64
+
+#define ACT8945A_SYS0                             (0x00)
+#define ACT8945A_SYS1                             (0x01)
+
+#define ACT8945A_DCDC1_VSET0                      (0x20)
+#define ACT8945A_DCDC1_VSET1                      (0x21)
+#define ACT8945A_DCDC1_CONTROL                    (0x22)
+#define ACT8945A_DCDC2_VSET0                      (0x30)
+#define ACT8945A_DCDC2_VSET1                      (0x31)
+#define ACT8945A_DCDC2_CONTROL                    (0x32)
+#define ACT8945A_DCDC3_VSET0                      (0x40)
+#define ACT8945A_DCDC3_VSET1                      (0x41)
+#define ACT8945A_DCDC3_CONTROL                    (0x42)
+#define ACT8945A_LDO1_VSET                        (0x50)
+#define ACT8945A_LDO1_CONTROL                     (0x51)
+#define ACT8945A_LDO2_VSET                        (0x54)
+#define ACT8945A_LDO2_CONTROL                     (0x55)
+#define ACT8945A_LDO3_VSET                        (0x60)
+#define ACT8945A_LDO3_CONTROL                     (0x61)
+#define ACT8945A_LDO4_VSET                        (0x64)
+#define ACT8945A_LDO4_CONTROL                     (0x65)
+
+#define ACT8945A_SYSTRST_MASK                     (0x80)
+#define ACT8945A_SYSMODE_MASK                     (0x40)
+#define ACT8945A_SYSLEV_MASK                      (0x0f)
+
+#define ACT8945A_VSET_MASK                        (0x3f)
+#define ACT8945A_EN_MASK                          (0x80)
+
+#define ACT8945A_SCRATCH_MASK                     (0x0f)
+#define SCRATCH_TEST_VAL                          (0x05)
+
+#define ACT8945A_PULLDOWN_MASK                    (0x40)
+
+#ifdef CONFIG_ACT8945A_TRST_64
+#  define ACT8945A_TRST                           (0x80) /* 64ms*/
+#else
+#  define ACT8945A_TRST                           (0)    /* 260ms */
+#endif
+
+#ifdef CONFIG_ACT8945A_SYSLEV_MODE_INTERRUPT
+#  define ACT8945A_SYSLEV_MODE                    (0x40) /* Interrupt */
+#else
+#  define ACT8945A_SYSLEV_MODE                    (0)    /* Shutdown */
+#endif
+
+#if defined(CONFIG_ACT8945A_SYSLEV_2300)
+#  define ACT8945A_SYSLEV 0
+#elif defined(CONFIG_ACT8945A_SYSLEV_2400)
+#  define ACT8945A_SYSLEV 1
+#elif defined(CONFIG_ACT8945A_SYSLEV_2500)
+#  define ACT8945A_SYSLEV 2
+#elif defined(CONFIG_ACT8945A_SYSLEV_2600)
+#  define ACT8945A_SYSLEV 3
+#elif defined(CONFIG_ACT8945A_SYSLEV_2700)
+#  define ACT8945A_SYSLEV 4
+#elif defined(CONFIG_ACT8945A_SYSLEV_2800)
+#  define ACT8945A_SYSLEV 5
+#elif defined(CONFIG_ACT8945A_SYSLEV_2900)
+#  define ACT8945A_SYSLEV 6
+#elif defined(CONFIG_ACT8945A_SYSLEV_3000)
+#  define ACT8945A_SYSLEV 7
+#elif defined(CONFIG_ACT8945A_SYSLEV_3100)
+#  define ACT8945A_SYSLEV 8
+#elif defined(CONFIG_ACT8945A_SYSLEV_3200)
+#  define ACT8945A_SYSLEV 9
+#elif defined(CONFIG_ACT8945A_SYSLEV_3300)
+#  define ACT8945A_SYSLEV 10
+#elif defined(CONFIG_ACT8945A_SYSLEV_3400)
+#  define ACT8945A_SYSLEV 11
+#elif defined(CONFIG_ACT8945A_SYSLEV_3500)
+#  define ACT8945A_SYSLEV 12
+#elif defined(CONFIG_ACT8945A_SYSLEV_3600)
+#  define ACT8945A_SYSLEV 13
+#elif defined(CONFIG_ACT8945A_SYSLEV_3700)
+#  define ACT8945A_SYSLEV 14
+#elif defined(CONFIG_ACT8945A_SYSLEV_3800)
+#  define ACT8945A_SYSLEV 15
+#else
+#  error No act8945a sys level detect threshold defined
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC1_BOOT_ON
+#  define ACT8945A_DCDC1_BOOT_ON 1
+#else
+#  define ACT8945A_DCDC1_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC2_BOOT_ON
+#  define ACT8945A_DCDC2_BOOT_ON 1
+#else
+#  define ACT8945A_DCDC2_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC3_BOOT_ON
+#  define ACT8945A_DCDC3_BOOT_ON 1
+#else
+#  define ACT8945A_DCDC3_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO1_BOOT_ON
+#  define ACT8945A_LDO1_BOOT_ON 1
+#else
+#  define ACT8945A_LDO1_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO2_BOOT_ON
+#  define ACT8945A_LDO2_BOOT_ON 1
+#else
+#  define ACT8945A_LDO2_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO3_BOOT_ON
+#  define ACT8945A_LDO3_BOOT_ON 1
+#else
+#  define ACT8945A_LDO3_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO4_BOOT_ON
+#  define ACT8945A_LDO4_BOOT_ON 1
+#else
+#  define ACT8945A_LDO4_BOOT_ON 0
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC1_APPLY_UV
+#  define ACT8945A_DCDC1_APPLY_UV 1
+#else
+#  define ACT8945A_DCDC1_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC2_APPLY_UV
+#  define ACT8945A_DCDC2_APPLY_UV 1
+#else
+#  define ACT8945A_DCDC2_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_DCDC3_APPLY_UV
+#  define ACT8945A_DCDC3_APPLY_UV 1
+#else
+#  define ACT8945A_DCDC3_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO1_APPLY_UV
+#  define ACT8945A_LDO1_APPLY_UV 1
+#else
+#  define ACT8945A_LDO1_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO2_APPLY_UV
+#  define ACT8945A_LDO2_APPLY_UV 1
+#else
+#  define ACT8945A_LDO2_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO3_APPLY_UV
+#  define ACT8945A_LDO3_APPLY_UV 1
+#else
+#  define ACT8945A_LDO3_APPLY_UV 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO4_APPLY_UV
+#  define ACT8945A_LDO4_APPLY_UV 1
+#else
+#  define ACT8945A_LDO4_APPLY_UV 0
+#endif
+
+#define ACT8945A_DCDC1_PULLDOWN 0
+#define ACT8945A_DCDC2_PULLDOWN 0
+#define ACT8945A_DCDC3_PULLDOWN 0
+
+#ifdef CONFIG_ACT8945A_LDO1_PULLDOWN
+#  define ACT8945A_LDO1_PULLDOWN 1
+#else
+#  define ACT8945A_LDO1_PULLDOWN 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO2_PULLDOWN
+#  define ACT8945A_LDO2_PULLDOWN 1
+#else
+#  define ACT8945A_LDO2_PULLDOWN 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO3_PULLDOWN
+#  define ACT8945A_LDO3_PULLDOWN 1
+#else
+#  define ACT8945A_LDO3_PULLDOWN 0
+#endif
+
+#ifdef CONFIG_ACT8945A_LDO4_PULLDOWN
+#  define ACT8945A_LDO4_PULLDOWN 1
+#else
+#  define ACT8945A_LDO4_PULLDOWN 0
+#endif
+
+#define ACT8945A_REG(_id, _vsel)                      \
+  [ACT8945A_##_id] =                                  \
+  {                                                   \
+    .name          = CONFIG_ACT8945A_##_id##_NAME,    \
+    .id            = ACT8945A_##_id,                  \
+    .n_voltages    = ACT8945A_NUM_VOLTAGES,           \
+    .vsel_reg      = ACT8945A_##_id##_##_vsel,        \
+    .vsel_mask     = ACT8945A_VSET_MASK,              \
+    .enable_reg    = ACT8945A_##_id##_CONTROL,        \
+    .enable_mask   = ACT8945A_EN_MASK,                \
+    .boot_on       = ACT8945A_##_id##_BOOT_ON,        \
+    .min_uv        = CONFIG_ACT8945A_##_id##_MIN_UV,  \
+    .max_uv        = CONFIG_ACT8945A_##_id##_MAX_UV,  \
+    .apply_uv      = ACT8945A_##_id##_APPLY_UV,       \
+    .pulldown      = ACT8945A_##_id##_PULLDOWN,       \
+    .pulldown_reg  = ACT8945A_##_id##_CONTROL,        \
+    .pulldown_mask = ACT8945A_PULLDOWN_MASK,          \
+  }

Review Comment:
   See #8742 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to