Skip to content

Commit

Permalink
Merge pull request zephyrproject-rtos#6 from Cirrus-Logic-Software/dr…
Browse files Browse the repository at this point in the history
…v-6801

CP9314 v0.1.1
  • Loading branch information
cirrus-kor-lion authored and GitHub Enterprise committed Sep 19, 2023
2 parents a38cb6d + 22d081d commit a78fbb4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
57 changes: 35 additions & 22 deletions drivers/regulator/regulator_cp9314.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ static int regulator_cp9314_enable(const struct device *dev)
return ret;
}

ret = i2c_reg_read_byte_dt(&config->i2c, CP9314_FAULT1_STS, &value);
if (ret < 0) {
return ret;
}

ret = i2c_reg_read_byte_dt(&config->i2c, CP9314_SYS_STS, &value);
if (ret < 0) {
return ret;
}

if (config->en_pin.port != NULL) {
return gpio_pin_set_dt(&config->en_pin, 1);
}
Expand Down Expand Up @@ -288,6 +278,36 @@ static int cp9314_do_soft_reset(const struct device *dev)
return 0;
}

static int regulator_cp9314_cfg_en(const struct device *dev)
{
const struct regulator_cp9314_config *config = dev->config;
uint8_t value = CP9314_KEY_ACTIVE_LOW;
int ret;

ret = i2c_reg_write_byte_dt(&config->i2c, CP9314_REG_CRUS_CTRL, CP9314_CRUS_KEY_UNLOCK);
if (ret < 0) {
return ret;
}

if (config->en_pin.dt_flags == GPIO_ACTIVE_HIGH) {
value = CP9314_KEY_ACTIVE_HIGH;
}

ret = i2c_reg_update_byte_dt(&config->i2c, CP9314_REG_TRIM_9, CP9314_TM_KEY_POLARITY,
value);
if (ret < 0) {
return ret;
}

ret = i2c_reg_update_byte_dt(&config->i2c, CP9314_REG_TRIM_9, CP9314_FORCE_KEY_POLARITY,
CP9314_FORCE_KEY_POLARITY);
if (ret < 0) {
return ret;
}

return i2c_reg_write_byte_dt(&config->i2c, CP9314_REG_CRUS_CTRL, CP9314_CRUS_KEY_LOCK);
}

static int regulator_cp9314_init(const struct device *dev)
{
const struct regulator_cp9314_config *config = dev->config;
Expand Down Expand Up @@ -350,23 +370,16 @@ static int regulator_cp9314_init(const struct device *dev)
}
}

ret = regulator_cp9314_cfg_en(dev);
if (ret < 0) {
return ret;
}

if (config->en_pin.port != NULL) {
if (!gpio_is_ready_dt(&config->en_pin)) {
return -ENODEV;
}

if (config->en_pin.dt_flags == GPIO_ACTIVE_HIGH) {
value = CP9314_EN_PIN_ACTIVE_HIGH;
} else {
value = CP9314_EN_PIN_ACTIVE_LOW;
}

ret = i2c_reg_update_byte_dt(&config->i2c, CP9314_REG_TRIM_3,
CP9314_EN_PIN_POLARITY, value);
if (ret < 0) {
return ret;
}

ret = gpio_pin_configure_dt(&config->en_pin, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
return ret;
Expand Down
12 changes: 5 additions & 7 deletions drivers/regulator/regulator_cp9314.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,17 @@
#define CP9314_CRUS_KEY_UNLOCK 0xAA
#define CP9314_CRUS_KEY_SOFT_RESET 0xC6

#define CP9314_REG_TRIM_3 0x44
#define CP9314_EN_PIN_POLARITY BIT(6)
#define CP9314_EN_PIN_ACTIVE_LOW 0
#define CP9314_EN_PIN_ACTIVE_HIGH CP9314_EN_PIN_POLARITY

#define CP9314_REG_TRIM_5 0x46
#define CP9314_CSI_CHOP_EN BIT(2)

#define CP9314_REG_TRIM_8 0x49
#define CP9314_MODE_CTRL_UPDATE_BW_0 GENMASK(2, 0)

#define CP9314_REG_TRIM_9 0x4A
#define CP9314_MODE_CTRL_MIN_FREQ_1 GENMASK(2, 0)
#define CP9314_REG_TRIM_9 0x4A
#define CP9314_FORCE_KEY_POLARITY BIT(2)
#define CP9314_TM_KEY_POLARITY BIT(1)
#define CP9314_KEY_ACTIVE_LOW 0
#define CP9314_KEY_ACTIVE_HIGH CP9314_TM_KEY_POLARITY

#define CP9314_REG_BST_CP_PD_CFG 0x58
#define CP9314_LB1_BLANK_CFG BIT(5)
Expand Down

0 comments on commit a78fbb4

Please sign in to comment.