Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Aren Moynihan <aren@peacevolution.org>
Link: https://lore.kernel.org/r/20240130203714.3020464-3-aren@peacevolution.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Aren Moynihan and committed by
Sebastian Reichel
b02fbd83 bec924d2

+18 -4
+18 -4
drivers/power/supply/axp20x_usb_power.c
··· 50 50 const char * const *irq_names; 51 51 unsigned int num_irq_names; 52 52 const int *curr_lim_table; 53 + int curr_lim_table_size; 53 54 struct reg_field curr_lim_fld; 54 55 struct reg_field vbus_valid_bit; 55 56 struct reg_field vbus_mon_bit; ··· 167 166 if (ret) 168 167 return ret; 169 168 170 - val->intval = power->axp_data->curr_lim_table[v]; 169 + if (v < power->axp_data->curr_lim_table_size) 170 + val->intval = power->axp_data->curr_lim_table[v]; 171 + else 172 + val->intval = power->axp_data->curr_lim_table[ 173 + power->axp_data->curr_lim_table_size - 1]; 171 174 return 0; 172 175 case POWER_SUPPLY_PROP_CURRENT_NOW: 173 176 if (IS_ENABLED(CONFIG_AXP20X_ADC)) { ··· 266 261 int intval) 267 262 { 268 263 unsigned int reg; 269 - const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, 270 - power->axp_data->curr_lim_fld.lsb); 264 + const unsigned int max = power->axp_data->curr_lim_table_size; 271 265 272 266 if (intval == -1) 273 267 return -EINVAL; ··· 398 394 }; 399 395 400 396 static int axp813_usb_curr_lim_table[] = { 397 + 100000, 398 + 500000, 401 399 900000, 402 400 1500000, 403 401 2000000, 404 402 2500000, 403 + 3000000, 404 + 3500000, 405 + 4000000, 405 406 }; 406 407 407 408 static const struct axp_data axp192_data = { ··· 414 405 .irq_names = axp20x_irq_names, 415 406 .num_irq_names = ARRAY_SIZE(axp20x_irq_names), 416 407 .curr_lim_table = axp192_usb_curr_lim_table, 408 + .curr_lim_table_size = ARRAY_SIZE(axp192_usb_curr_lim_table), 417 409 .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), 418 410 .vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2), 419 411 .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), ··· 425 415 .irq_names = axp20x_irq_names, 426 416 .num_irq_names = ARRAY_SIZE(axp20x_irq_names), 427 417 .curr_lim_table = axp20x_usb_curr_lim_table, 418 + .curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table), 428 419 .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), 429 420 .vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2), 430 421 .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), ··· 436 425 .irq_names = axp22x_irq_names, 437 426 .num_irq_names = ARRAY_SIZE(axp22x_irq_names), 438 427 .curr_lim_table = axp221_usb_curr_lim_table, 428 + .curr_lim_table_size = ARRAY_SIZE(axp221_usb_curr_lim_table), 439 429 .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), 440 430 .vbus_needs_polling = true, 441 431 }; ··· 446 434 .irq_names = axp22x_irq_names, 447 435 .num_irq_names = ARRAY_SIZE(axp22x_irq_names), 448 436 .curr_lim_table = axp20x_usb_curr_lim_table, 437 + .curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table), 449 438 .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), 450 439 .vbus_needs_polling = true, 451 440 }; ··· 456 443 .irq_names = axp22x_irq_names, 457 444 .num_irq_names = ARRAY_SIZE(axp22x_irq_names), 458 445 .curr_lim_table = axp813_usb_curr_lim_table, 459 - .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), 446 + .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), 447 + .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), 460 448 .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), 461 449 .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), 462 450 .vbus_needs_polling = true,