3131
3232#define AXP20X_USB_STATUS_VBUS_VALID BIT(2)
3333
34- #define AXP20X_VBUS_PATH_SEL BIT(7)
35- #define AXP20X_VBUS_PATH_SEL_OFFSET 7
36-
3734#define AXP20X_VBUS_VHOLD_uV (b ) (4000000 + (((b) >> 3) & 7) * 100000)
3835#define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3)
3936#define AXP20X_VBUS_VHOLD_OFFSET 3
@@ -57,6 +54,7 @@ struct axp_data {
5754 struct reg_field vbus_valid_bit ;
5855 struct reg_field vbus_mon_bit ;
5956 struct reg_field usb_bc_en_bit ;
57+ struct reg_field vbus_disable_bit ;
6058};
6159
6260struct axp20x_usb_power {
@@ -65,6 +63,7 @@ struct axp20x_usb_power {
6563 struct regmap_field * vbus_valid_bit ;
6664 struct regmap_field * vbus_mon_bit ;
6765 struct regmap_field * usb_bc_en_bit ;
66+ struct regmap_field * vbus_disable_bit ;
6867 struct power_supply * supply ;
6968 enum axp20x_variants axp20x_id ;
7069 const struct axp_data * axp_data ;
@@ -231,16 +230,6 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
231230 return 0 ;
232231}
233232
234- static int axp813_usb_power_set_online (struct axp20x_usb_power * power ,
235- int intval )
236- {
237- int val = !intval << AXP20X_VBUS_PATH_SEL_OFFSET ;
238-
239- return regmap_update_bits (power -> regmap ,
240- AXP20X_VBUS_IPSOUT_MGMT ,
241- AXP20X_VBUS_PATH_SEL , val );
242- }
243-
244233static int axp20x_usb_power_set_voltage_min (struct axp20x_usb_power * power ,
245234 int intval )
246235{
@@ -290,9 +279,10 @@ static int axp20x_usb_power_set_property(struct power_supply *psy,
290279
291280 switch (psp ) {
292281 case POWER_SUPPLY_PROP_ONLINE :
293- if (power -> axp20x_id != AXP813_ID )
282+ if (! power -> vbus_disable_bit )
294283 return - EINVAL ;
295- return axp813_usb_power_set_online (power , val -> intval );
284+
285+ return regmap_field_write (power -> vbus_disable_bit , !val -> intval );
296286
297287 case POWER_SUPPLY_PROP_VOLTAGE_MIN :
298288 return axp20x_usb_power_set_voltage_min (power , val -> intval );
@@ -320,7 +310,7 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy,
320310 * the VBUS input offline.
321311 */
322312 if (psp == POWER_SUPPLY_PROP_ONLINE )
323- return power -> axp20x_id == AXP813_ID ;
313+ return power -> vbus_disable_bit != NULL ;
324314
325315 return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
326316 psp == POWER_SUPPLY_PROP_CURRENT_MAX ;
@@ -434,6 +424,7 @@ static const struct axp_data axp813_data = {
434424 .curr_lim_table = axp813_usb_curr_lim_table ,
435425 .curr_lim_fld = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 0 , 1 ),
436426 .usb_bc_en_bit = REG_FIELD (AXP288_BC_GLOBAL , 0 , 0 ),
427+ .vbus_disable_bit = REG_FIELD (AXP20X_VBUS_IPSOUT_MGMT , 7 , 7 ),
437428};
438429
439430#ifdef CONFIG_PM_SLEEP
@@ -579,6 +570,12 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
579570 if (ret )
580571 return ret ;
581572
573+ ret = axp20x_regmap_field_alloc_optional (& pdev -> dev , power -> regmap ,
574+ axp_data -> vbus_disable_bit ,
575+ & power -> vbus_disable_bit );
576+ if (ret )
577+ return ret ;
578+
582579 ret = devm_delayed_work_autocancel (& pdev -> dev , & power -> vbus_detect ,
583580 axp20x_usb_power_poll_vbus );
584581 if (ret )
0 commit comments