Skip to content

Commit

Permalink
drivers: sensor: npm1300_charger: Startup vbus current limit
Browse files Browse the repository at this point in the history
The vbus current limit is now written to the vbus startup
register. It is now applied at all times and does not need
to be updated on charger insertion.

Signed-off-by: Andy Sinclair <[email protected]>
  • Loading branch information
aasinclair authored and carlescufi committed Jul 5, 2023
1 parent 77c86e8 commit f93da64
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions drivers/sensor/npm1300_charger/npm1300_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ struct npm1300_charger_data {
#define ADC_OFFSET_IBAT_EN 0x24U

/* nPM1300 VBUS register offsets */
#define VBUS_OFFSET_TASK_UPDATE 0x00U
#define VBUS_OFFSET_ILIM 0x01U
#define VBUS_OFFSET_ILIMSTARTUP 0x02U
#define VBUS_OFFSET_STATUS 0x07U

/* Ibat status */
Expand Down Expand Up @@ -198,7 +197,6 @@ int npm1300_charger_sample_fetch(const struct device *dev, enum sensor_channel c
const struct npm1300_charger_config *const config = dev->config;
struct npm1300_charger_data *data = dev->data;
struct adc_results_t results;
bool last_vbus;
int ret;

/* Read charge status and error reason */
Expand Down Expand Up @@ -236,21 +234,12 @@ int npm1300_charger_sample_fetch(const struct device *dev, enum sensor_channel c
return ret;
}

/* Read vbus status, and set SW current limit on new vbus detection */
last_vbus = (data->vbus_stat & 1U) != 0U;
/* Read vbus status */
ret = mfd_npm1300_reg_read(config->mfd, VBUS_BASE, VBUS_OFFSET_STATUS, &data->vbus_stat);
if (ret != 0) {
return ret;
}

if (!last_vbus && ((data->vbus_stat & 1U) != 0U)) {
ret = mfd_npm1300_reg_write(config->mfd, VBUS_BASE, VBUS_OFFSET_TASK_UPDATE, 1U);

if (ret != 0) {
return ret;
}
}

return ret;
}

Expand Down Expand Up @@ -329,7 +318,7 @@ int npm1300_charger_init(const struct device *dev)
if (ret == -EINVAL) {
return ret;
}
ret = mfd_npm1300_reg_write(config->mfd, VBUS_BASE, VBUS_OFFSET_ILIM, idx);
ret = mfd_npm1300_reg_write(config->mfd, VBUS_BASE, VBUS_OFFSET_ILIMSTARTUP, idx);
if (ret != 0) {
return ret;
}
Expand Down

0 comments on commit f93da64

Please sign in to comment.