mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
feat: charge: initialize rx charger stwlc38 driver
CHAMPION-25 Signed-off-by: zhangguoliang <zhangguoliang3@xiaomi.com> Change-Id: Ifa5732ae2160d4bc083f9aaf4e3beb34096b7770
This commit is contained in:
committed by
zhangguoliang3
parent
7df6d25fc3
commit
e6d84fccc9
@@ -383,6 +383,15 @@ config SC8551
|
||||
---help---
|
||||
The SC8551 are battery charger for lithium-ion batteries.
|
||||
|
||||
config STWLC38
|
||||
bool "STWLC38 Battery charger support"
|
||||
default n
|
||||
select I2C
|
||||
select I2C_STWLC38
|
||||
depends on BATTERY_CHARGER
|
||||
---help---
|
||||
The STWLC38 are wireless rx for power supply.
|
||||
|
||||
config MCP73871
|
||||
bool "Microchip MCP73871 Battery charger support"
|
||||
default n
|
||||
@@ -420,6 +429,16 @@ config DEBUG_SC8551
|
||||
|
||||
endif # SC8551
|
||||
|
||||
if STWLC38
|
||||
|
||||
config DEBUG_STWLC38
|
||||
bool "STWLC38 Debug Features"
|
||||
default n
|
||||
---help---
|
||||
Enable STWLC38 wireless rx debug features.
|
||||
|
||||
endif # STWLC38
|
||||
|
||||
config BATTERY_GAUGE
|
||||
bool "Battery Fuel Gauge support"
|
||||
default n
|
||||
@@ -482,6 +501,10 @@ config I2C_SC8551
|
||||
bool
|
||||
default y if SC8551
|
||||
|
||||
config I2C_STWLC38
|
||||
bool
|
||||
default y if STWLC38
|
||||
|
||||
config I2C_MAX1704X
|
||||
bool
|
||||
default y if MAX1704X
|
||||
|
||||
@@ -103,6 +103,10 @@ ifeq ($(CONFIG_I2C_SC8551),y)
|
||||
CSRCS += sc8551.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_I2C_STWLC38),y)
|
||||
CSRCS += polaris.c
|
||||
endif
|
||||
|
||||
# Add the BQ256XX I2C-based battery charger driver
|
||||
|
||||
ifeq ($(CONFIG_I2C_BQ25618),y)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
* drivers/power/polaris.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __POLARIS_H
|
||||
#define __POLARIS_H
|
||||
|
||||
#define NVM_SECTOR_SIZE_BYTES 256 //128
|
||||
#define NVM_PATCH_START_SECTOR_INDEX 0
|
||||
#define NVM_CFG_START_SECTOR_INDEX 126 //93
|
||||
#define I2C_CHUNK_SIZE 256 //128
|
||||
|
||||
#define AFTER_SYS_RESET_SLEEP_MS 50
|
||||
|
||||
/* FW register address */
|
||||
#define FWREG_OP_MODE_ADDR 0x000E
|
||||
#define FWREG_SYS_CMD_ADDR 0x0020
|
||||
#define FWREG_NVM_SECTOR_INDEX_ADDR 0x0024
|
||||
#define FWREG_AUX_DATA_00 0x0180
|
||||
#define FWREG_NVM_PWD_ADDR 0x0022
|
||||
|
||||
/* SYSREG registers */
|
||||
#define HWREG_HW_VER_ADDR 0x2001C002
|
||||
#define HWREG_HW_SYS_RST_ADDR 0x2001F200
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FW_OP_MODE_SA = 1,
|
||||
FW_OP_MODE_RX = 2,
|
||||
FW_OP_MODE_TX = 3
|
||||
}fw_op_mode_t;
|
||||
|
||||
#define WRITE_READ_OPERATION 0x01
|
||||
#define WRITE_OPERATION 0x02
|
||||
|
||||
#define OPCODE_WRITE 0xFA
|
||||
|
||||
#define MIN_WR_BYTE_LENGTH 5
|
||||
#define MIN_W_BYTE_LENGTH 4
|
||||
|
||||
#define CMD_STR_LEN 1024
|
||||
|
||||
#define OK ((int)0x00000000)
|
||||
#define E_BUS_R ((int)0x80000001)
|
||||
#define E_BUS_W ((int)0x80000002)
|
||||
#define E_BUS_WR ((int)0x80000003)
|
||||
#define E_UNEXPECTED_OP_MODE ((int)0x80000004)
|
||||
#define E_NVM_WRITE ((int)0x80000005)
|
||||
#define E_INVALID_INPUT ((int)0x80000006)
|
||||
#define E_MEMORY_ALLOC ((int)0x80000007)
|
||||
#define E_UNEXPECTED_HW_REV ((int)0x80000008)
|
||||
#define E_TIMEOUT ((int)0x80000009)
|
||||
#define E_NVM_DATA_MISMATCH ((int)0x8000000A)
|
||||
|
||||
#define WLC_CHIPID_LOW_REG 0x0000
|
||||
|
||||
#define WLC_DRV_VERSION "1.0.0" /* driver version string format */
|
||||
|
||||
struct polaris_chip_info
|
||||
{
|
||||
uint16_t chip_id;
|
||||
uint8_t chip_revision;
|
||||
uint8_t customer_id;
|
||||
uint16_t project_id;
|
||||
uint16_t nvm_patch_id;
|
||||
uint16_t ram_patch_id;
|
||||
uint16_t config_id;
|
||||
uint16_t pe_id;
|
||||
uint8_t cut_id;
|
||||
};
|
||||
|
||||
#endif /* __POLARIS_H */
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
* drivers/power/polaris_nvm.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* The STWLC38 are Li-Ion Battery management
|
||||
*
|
||||
* This driver requires:
|
||||
*
|
||||
* CONFIG_BATTERY_CHARGER - Upper half battery driver support
|
||||
* CONFIG_I2C - I2C support
|
||||
* CONFIG_I2C_STWLC38 - And the driver must be explicitly selected.
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NVM_DATA_H
|
||||
#define NVM_DATA_H
|
||||
#define NVM_TARGET_CUT_ID 1
|
||||
#define NVM_CFG_SIZE 384
|
||||
#define NVM_CFG_VERSION_ID 0x1001
|
||||
#define NVM_PATCH_SIZE 8
|
||||
#define NVM_PATCH_VERSION_ID 0x1000
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
const uint8_t cfg_data[] =
|
||||
{
|
||||
0x01, 0x10, 0x00, 0x01, 0x77, 0x10, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x14, 0x44,
|
||||
0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x63, 0x00, 0x03, 0x0d, 0x09, 0x06, 0x00, 0xff,
|
||||
0x02, 0x19, 0x0f, 0x3d, 0x14, 0x0a, 0x32, 0x28,
|
||||
0x7d, 0x64, 0x0a, 0x00, 0x82, 0x82, 0x82, 0x82,
|
||||
0x41, 0x02, 0x02, 0x02, 0x02, 0xa5, 0x07, 0x06,
|
||||
0x12, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x40,
|
||||
0x23, 0x37, 0x2c, 0x42, 0x58, 0x6e, 0x84, 0x04,
|
||||
0x04, 0x04, 0x04, 0x04, 0x04, 0x7d, 0x7d, 0x7d,
|
||||
0x7d, 0x7d, 0x7d, 0xc8, 0x13, 0x0f, 0x0a, 0x05,
|
||||
0x26, 0x3c, 0x4b, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x56, 0x5f, 0x85, 0x64,
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x07, 0x19,
|
||||
0x11, 0x00, 0x02, 0x00, 0x16, 0x11, 0x22, 0x33,
|
||||
0x44, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x05, 0x1e, 0x00, 0x12, 0x04, 0x1e, 0x5d,
|
||||
0x5d, 0x54, 0x80, 0x37, 0x9c, 0x14, 0x8e, 0x20,
|
||||
0x08, 0x04, 0x43, 0x11, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xf0, 0x28, 0x0e, 0x05,
|
||||
0xd4, 0x00, 0xa8, 0x00, 0x00, 0x01, 0x00, 0x01,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x00,
|
||||
0x11, 0xc3, 0x05, 0x06, 0x09, 0x0d, 0x03, 0x1e,
|
||||
0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x9a, 0x85, 0x29, 0x37,
|
||||
};
|
||||
|
||||
const uint8_t patch_data[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -338,6 +338,44 @@ FAR struct battery_charger_dev_s *
|
||||
uint32_t frequency, int current);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stwlc38_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the stwlc38 (wireless rx) charger driver and return
|
||||
* an instance of the lower-half interface that may be used with
|
||||
* battery_charger_register().
|
||||
*
|
||||
* This is for:
|
||||
* STWLC38
|
||||
*
|
||||
* This driver requires:
|
||||
*
|
||||
* CONFIG_BATTERY_CHARGER - Upper half battery charger driver support
|
||||
* CONFIG_I2C - I2C support
|
||||
* CONFIG_I2C_STWLC38 - And the driver must be explicitly selected.
|
||||
*
|
||||
* Input Parameters:
|
||||
* i2c - An instance of the I2C interface to use to communicate with
|
||||
* the SC8551
|
||||
* addr - The I2C address of the STWLC38 (Better be 0x61).
|
||||
* frequency - The I2C frequency
|
||||
* current - The input current our power-supply can offer to charger
|
||||
*
|
||||
* Returned Value:
|
||||
* A pointer to the initialized battery driver instance. A NULL pointer
|
||||
* is returned on a failure to initialize the STWLC38 lower half.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_STWLC38)
|
||||
|
||||
struct i2c_master_s;
|
||||
FAR struct battery_charger_dev_s *
|
||||
stwlc38_initialize(FAR struct i2c_master_s *i2c, uint8_t addr,
|
||||
uint32_t frequency, int current);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user