Commit b02fbd83 authored by Aren Moynihan's avatar Aren Moynihan Committed by Sebastian Reichel

power: supply: axp20x_usb_power: use correct register for input current limit

On the axp803 and axp813 chips register 0x30 bits 0-1 is the default
current limit that gets applied after the pmic detects a CDP or DCP
port. The correct field to set is 0x35 bits 4-7.

This field only has nine values (out of the 16 possible if it used all
the bits), so introduce a field size variable to take that into account.
Signed-off-by: default avatarAren Moynihan <aren@peacevolution.org>
Link: https://lore.kernel.org/r/20240130203714.3020464-3-aren@peacevolution.orgSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent bec924d2
...@@ -50,6 +50,7 @@ struct axp_data { ...@@ -50,6 +50,7 @@ struct axp_data {
const char * const *irq_names; const char * const *irq_names;
unsigned int num_irq_names; unsigned int num_irq_names;
const int *curr_lim_table; const int *curr_lim_table;
int curr_lim_table_size;
struct reg_field curr_lim_fld; struct reg_field curr_lim_fld;
struct reg_field vbus_valid_bit; struct reg_field vbus_valid_bit;
struct reg_field vbus_mon_bit; struct reg_field vbus_mon_bit;
...@@ -166,7 +167,11 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, ...@@ -166,7 +167,11 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
if (ret) if (ret)
return ret; return ret;
val->intval = power->axp_data->curr_lim_table[v]; if (v < power->axp_data->curr_lim_table_size)
val->intval = power->axp_data->curr_lim_table[v];
else
val->intval = power->axp_data->curr_lim_table[
power->axp_data->curr_lim_table_size - 1];
return 0; return 0;
case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW:
if (IS_ENABLED(CONFIG_AXP20X_ADC)) { if (IS_ENABLED(CONFIG_AXP20X_ADC)) {
...@@ -261,8 +266,7 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow ...@@ -261,8 +266,7 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow
int intval) int intval)
{ {
unsigned int reg; unsigned int reg;
const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, const unsigned int max = power->axp_data->curr_lim_table_size;
power->axp_data->curr_lim_fld.lsb);
if (intval == -1) if (intval == -1)
return -EINVAL; return -EINVAL;
...@@ -394,10 +398,15 @@ static int axp221_usb_curr_lim_table[] = { ...@@ -394,10 +398,15 @@ static int axp221_usb_curr_lim_table[] = {
}; };
static int axp813_usb_curr_lim_table[] = { static int axp813_usb_curr_lim_table[] = {
100000,
500000,
900000, 900000,
1500000, 1500000,
2000000, 2000000,
2500000, 2500000,
3000000,
3500000,
4000000,
}; };
static const struct axp_data axp192_data = { static const struct axp_data axp192_data = {
...@@ -405,6 +414,7 @@ static const struct axp_data axp192_data = { ...@@ -405,6 +414,7 @@ static const struct axp_data axp192_data = {
.irq_names = axp20x_irq_names, .irq_names = axp20x_irq_names,
.num_irq_names = ARRAY_SIZE(axp20x_irq_names), .num_irq_names = ARRAY_SIZE(axp20x_irq_names),
.curr_lim_table = axp192_usb_curr_lim_table, .curr_lim_table = axp192_usb_curr_lim_table,
.curr_lim_table_size = ARRAY_SIZE(axp192_usb_curr_lim_table),
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
.vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2), .vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2),
.vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3),
...@@ -415,6 +425,7 @@ static const struct axp_data axp202_data = { ...@@ -415,6 +425,7 @@ static const struct axp_data axp202_data = {
.irq_names = axp20x_irq_names, .irq_names = axp20x_irq_names,
.num_irq_names = ARRAY_SIZE(axp20x_irq_names), .num_irq_names = ARRAY_SIZE(axp20x_irq_names),
.curr_lim_table = axp20x_usb_curr_lim_table, .curr_lim_table = axp20x_usb_curr_lim_table,
.curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table),
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
.vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2), .vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2),
.vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3),
...@@ -425,6 +436,7 @@ static const struct axp_data axp221_data = { ...@@ -425,6 +436,7 @@ static const struct axp_data axp221_data = {
.irq_names = axp22x_irq_names, .irq_names = axp22x_irq_names,
.num_irq_names = ARRAY_SIZE(axp22x_irq_names), .num_irq_names = ARRAY_SIZE(axp22x_irq_names),
.curr_lim_table = axp221_usb_curr_lim_table, .curr_lim_table = axp221_usb_curr_lim_table,
.curr_lim_table_size = ARRAY_SIZE(axp221_usb_curr_lim_table),
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
.vbus_needs_polling = true, .vbus_needs_polling = true,
}; };
...@@ -434,6 +446,7 @@ static const struct axp_data axp223_data = { ...@@ -434,6 +446,7 @@ static const struct axp_data axp223_data = {
.irq_names = axp22x_irq_names, .irq_names = axp22x_irq_names,
.num_irq_names = ARRAY_SIZE(axp22x_irq_names), .num_irq_names = ARRAY_SIZE(axp22x_irq_names),
.curr_lim_table = axp20x_usb_curr_lim_table, .curr_lim_table = axp20x_usb_curr_lim_table,
.curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table),
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1),
.vbus_needs_polling = true, .vbus_needs_polling = true,
}; };
...@@ -443,7 +456,8 @@ static const struct axp_data axp813_data = { ...@@ -443,7 +456,8 @@ static const struct axp_data axp813_data = {
.irq_names = axp22x_irq_names, .irq_names = axp22x_irq_names,
.num_irq_names = ARRAY_SIZE(axp22x_irq_names), .num_irq_names = ARRAY_SIZE(axp22x_irq_names),
.curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_table = axp813_usb_curr_lim_table,
.curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table),
.curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7),
.usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0),
.vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7),
.vbus_needs_polling = true, .vbus_needs_polling = true,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment