Skip to content

Commit 364ea7c

Browse files
jwrdegoedesre
authored andcommitted
power: supply: Change usb_types from an array into a bitmask
The bit_types array just hold a list of valid enum power_supply_usb_type values which map to 0 - 9. This can easily be represented as a bitmap. This reduces the size of struct power_supply_desc and further reduces the data section size by drivers no longer needing to store the array. This also unifies how usb_types are handled with charge_behaviours, which allows power_supply_show_usb_type() to be removed. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 322900a commit 364ea7c

24 files changed

+102
-237
lines changed

drivers/extcon/extcon-intel-cht-wc.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,6 @@ static int cht_wc_extcon_psy_get_prop(struct power_supply *psy,
461461
return 0;
462462
}
463463

464-
static const enum power_supply_usb_type cht_wc_extcon_psy_usb_types[] = {
465-
POWER_SUPPLY_USB_TYPE_SDP,
466-
POWER_SUPPLY_USB_TYPE_CDP,
467-
POWER_SUPPLY_USB_TYPE_DCP,
468-
POWER_SUPPLY_USB_TYPE_ACA,
469-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
470-
};
471-
472464
static const enum power_supply_property cht_wc_extcon_psy_props[] = {
473465
POWER_SUPPLY_PROP_USB_TYPE,
474466
POWER_SUPPLY_PROP_ONLINE,
@@ -477,8 +469,11 @@ static const enum power_supply_property cht_wc_extcon_psy_props[] = {
477469
static const struct power_supply_desc cht_wc_extcon_psy_desc = {
478470
.name = "cht_wcove_pwrsrc",
479471
.type = POWER_SUPPLY_TYPE_USB,
480-
.usb_types = cht_wc_extcon_psy_usb_types,
481-
.num_usb_types = ARRAY_SIZE(cht_wc_extcon_psy_usb_types),
472+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
473+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
474+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
475+
BIT(POWER_SUPPLY_USB_TYPE_ACA) |
476+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
482477
.properties = cht_wc_extcon_psy_props,
483478
.num_properties = ARRAY_SIZE(cht_wc_extcon_psy_props),
484479
.get_property = cht_wc_extcon_psy_get_prop,

drivers/phy/ti/phy-tusb1210.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,6 @@ static int tusb1210_psy_get_prop(struct power_supply *psy,
411411
return 0;
412412
}
413413

414-
static const enum power_supply_usb_type tusb1210_psy_usb_types[] = {
415-
POWER_SUPPLY_USB_TYPE_SDP,
416-
POWER_SUPPLY_USB_TYPE_DCP,
417-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
418-
};
419-
420414
static const enum power_supply_property tusb1210_psy_props[] = {
421415
POWER_SUPPLY_PROP_ONLINE,
422416
POWER_SUPPLY_PROP_USB_TYPE,
@@ -426,8 +420,9 @@ static const enum power_supply_property tusb1210_psy_props[] = {
426420
static const struct power_supply_desc tusb1210_psy_desc = {
427421
.name = "tusb1211-charger-detect",
428422
.type = POWER_SUPPLY_TYPE_USB,
429-
.usb_types = tusb1210_psy_usb_types,
430-
.num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types),
423+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
424+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
425+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
431426
.properties = tusb1210_psy_props,
432427
.num_properties = ARRAY_SIZE(tusb1210_psy_props),
433428
.get_property = tusb1210_psy_get_prop,

drivers/power/supply/axp20x_usb_power.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,6 @@ static enum power_supply_property axp813_usb_power_properties[] = {
412412
POWER_SUPPLY_PROP_USB_TYPE,
413413
};
414414

415-
static enum power_supply_usb_type axp813_usb_types[] = {
416-
POWER_SUPPLY_USB_TYPE_SDP,
417-
POWER_SUPPLY_USB_TYPE_DCP,
418-
POWER_SUPPLY_USB_TYPE_CDP,
419-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
420-
};
421-
422415
static const struct power_supply_desc axp20x_usb_power_desc = {
423416
.name = "axp20x-usb",
424417
.type = POWER_SUPPLY_TYPE_USB,
@@ -447,8 +440,10 @@ static const struct power_supply_desc axp813_usb_power_desc = {
447440
.property_is_writeable = axp20x_usb_power_prop_writeable,
448441
.get_property = axp20x_usb_power_get_property,
449442
.set_property = axp20x_usb_power_set_property,
450-
.usb_types = axp813_usb_types,
451-
.num_usb_types = ARRAY_SIZE(axp813_usb_types),
443+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
444+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
445+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
446+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
452447
};
453448

454449
static const char * const axp20x_irq_names[] = {

drivers/power/supply/bq256xx_charger.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,6 @@ static const int bq25618_619_ichg_values[] = {
334334
1290000, 1360000, 1430000, 1500000
335335
};
336336

337-
static enum power_supply_usb_type bq256xx_usb_type[] = {
338-
POWER_SUPPLY_USB_TYPE_SDP,
339-
POWER_SUPPLY_USB_TYPE_CDP,
340-
POWER_SUPPLY_USB_TYPE_DCP,
341-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
342-
POWER_SUPPLY_USB_TYPE_ACA,
343-
};
344-
345337
static int bq256xx_array_parse(int array_size, int val, const int array[])
346338
{
347339
int i = 0;
@@ -1252,8 +1244,11 @@ static int bq256xx_property_is_writeable(struct power_supply *psy,
12521244
static const struct power_supply_desc bq256xx_power_supply_desc = {
12531245
.name = "bq256xx-charger",
12541246
.type = POWER_SUPPLY_TYPE_USB,
1255-
.usb_types = bq256xx_usb_type,
1256-
.num_usb_types = ARRAY_SIZE(bq256xx_usb_type),
1247+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
1248+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
1249+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
1250+
BIT(POWER_SUPPLY_USB_TYPE_ACA) |
1251+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
12571252
.properties = bq256xx_power_supply_props,
12581253
.num_properties = ARRAY_SIZE(bq256xx_power_supply_props),
12591254
.get_property = bq256xx_get_charger_property,

drivers/power/supply/cros_usbpd-charger.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ static enum power_supply_property cros_usbpd_dedicated_charger_props[] = {
7373
POWER_SUPPLY_PROP_VOLTAGE_NOW,
7474
};
7575

76-
static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = {
77-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
78-
POWER_SUPPLY_USB_TYPE_SDP,
79-
POWER_SUPPLY_USB_TYPE_DCP,
80-
POWER_SUPPLY_USB_TYPE_CDP,
81-
POWER_SUPPLY_USB_TYPE_C,
82-
POWER_SUPPLY_USB_TYPE_PD,
83-
POWER_SUPPLY_USB_TYPE_PD_DRP,
84-
POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID
85-
};
86-
8776
/* Input voltage/current limit in mV/mA. Default to none. */
8877
static u16 input_voltage_limit = EC_POWER_LIMIT_NONE;
8978
static u16 input_current_limit = EC_POWER_LIMIT_NONE;
@@ -643,9 +632,14 @@ static int cros_usbpd_charger_probe(struct platform_device *pd)
643632
psy_desc->properties = cros_usbpd_charger_props;
644633
psy_desc->num_properties =
645634
ARRAY_SIZE(cros_usbpd_charger_props);
646-
psy_desc->usb_types = cros_usbpd_charger_usb_types;
647-
psy_desc->num_usb_types =
648-
ARRAY_SIZE(cros_usbpd_charger_usb_types);
635+
psy_desc->usb_types = BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) |
636+
BIT(POWER_SUPPLY_USB_TYPE_SDP) |
637+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
638+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
639+
BIT(POWER_SUPPLY_USB_TYPE_C) |
640+
BIT(POWER_SUPPLY_USB_TYPE_PD) |
641+
BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) |
642+
BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID);
649643
}
650644

651645
psy_desc->name = port->name;

drivers/power/supply/lenovo_yoga_c630_battery.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,10 @@ static enum power_supply_property yoga_c630_psy_adpt_properties[] = {
353353
POWER_SUPPLY_PROP_USB_TYPE,
354354
};
355355

356-
static const enum power_supply_usb_type yoga_c630_psy_adpt_usb_type[] = {
357-
POWER_SUPPLY_USB_TYPE_C,
358-
};
359-
360356
static const struct power_supply_desc yoga_c630_psy_adpt_psy_desc = {
361357
.name = "yoga-c630-adapter",
362358
.type = POWER_SUPPLY_TYPE_USB,
363-
.usb_types = yoga_c630_psy_adpt_usb_type,
364-
.num_usb_types = ARRAY_SIZE(yoga_c630_psy_adpt_usb_type),
359+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_C),
365360
.properties = yoga_c630_psy_adpt_properties,
366361
.num_properties = ARRAY_SIZE(yoga_c630_psy_adpt_properties),
367362
.get_property = yoga_c630_psy_adpt_get_property,

drivers/power/supply/mp2629_charger.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ struct mp2629_prop {
9494
int shift;
9595
};
9696

97-
static enum power_supply_usb_type mp2629_usb_types[] = {
98-
POWER_SUPPLY_USB_TYPE_SDP,
99-
POWER_SUPPLY_USB_TYPE_DCP,
100-
POWER_SUPPLY_USB_TYPE_CDP,
101-
POWER_SUPPLY_USB_TYPE_PD_DRP,
102-
POWER_SUPPLY_USB_TYPE_UNKNOWN
103-
};
104-
10597
static enum power_supply_property mp2629_charger_usb_props[] = {
10698
POWER_SUPPLY_PROP_ONLINE,
10799
POWER_SUPPLY_PROP_USB_TYPE,
@@ -487,8 +479,11 @@ static irqreturn_t mp2629_irq_handler(int irq, void *dev_id)
487479
static const struct power_supply_desc mp2629_usb_desc = {
488480
.name = "mp2629_usb",
489481
.type = POWER_SUPPLY_TYPE_USB,
490-
.usb_types = mp2629_usb_types,
491-
.num_usb_types = ARRAY_SIZE(mp2629_usb_types),
482+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
483+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
484+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
485+
BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) |
486+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
492487
.properties = mp2629_charger_usb_props,
493488
.num_properties = ARRAY_SIZE(mp2629_charger_usb_props),
494489
.get_property = mp2629_charger_usb_get_prop,

drivers/power/supply/mt6360_charger.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ enum mt6360_pmu_chg_type {
154154
MT6360_CHG_TYPE_MAX,
155155
};
156156

157-
static enum power_supply_usb_type mt6360_charger_usb_types[] = {
158-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
159-
POWER_SUPPLY_USB_TYPE_SDP,
160-
POWER_SUPPLY_USB_TYPE_DCP,
161-
POWER_SUPPLY_USB_TYPE_CDP,
162-
};
163-
164157
static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci,
165158
bool *pwr_rdy)
166159
{
@@ -574,8 +567,10 @@ static const struct power_supply_desc mt6360_charger_desc = {
574567
.get_property = mt6360_charger_get_property,
575568
.set_property = mt6360_charger_set_property,
576569
.property_is_writeable = mt6360_charger_property_is_writeable,
577-
.usb_types = mt6360_charger_usb_types,
578-
.num_usb_types = ARRAY_SIZE(mt6360_charger_usb_types),
570+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
571+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
572+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
573+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
579574
};
580575

581576
static const struct regulator_ops mt6360_chg_otg_ops = {

drivers/power/supply/mt6370-charger.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,6 @@ static enum power_supply_property mt6370_chg_properties[] = {
624624
POWER_SUPPLY_PROP_USB_TYPE,
625625
};
626626

627-
static enum power_supply_usb_type mt6370_chg_usb_types[] = {
628-
POWER_SUPPLY_USB_TYPE_UNKNOWN,
629-
POWER_SUPPLY_USB_TYPE_SDP,
630-
POWER_SUPPLY_USB_TYPE_CDP,
631-
POWER_SUPPLY_USB_TYPE_DCP,
632-
};
633-
634627
static const struct power_supply_desc mt6370_chg_psy_desc = {
635628
.name = "mt6370-charger",
636629
.type = POWER_SUPPLY_TYPE_USB,
@@ -639,8 +632,10 @@ static const struct power_supply_desc mt6370_chg_psy_desc = {
639632
.get_property = mt6370_chg_get_property,
640633
.set_property = mt6370_chg_set_property,
641634
.property_is_writeable = mt6370_chg_property_is_writeable,
642-
.usb_types = mt6370_chg_usb_types,
643-
.num_usb_types = ARRAY_SIZE(mt6370_chg_usb_types),
635+
.usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) |
636+
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
637+
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
638+
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
644639
};
645640

646641
static const struct regulator_ops mt6370_chg_otg_ops = {

drivers/power/supply/power_supply_core.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,10 +1361,6 @@ __power_supply_register(struct device *parent,
13611361
pr_warn("%s: Expected proper parent device for '%s'\n",
13621362
__func__, desc->name);
13631363

1364-
if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
1365-
(!desc->usb_types || !desc->num_usb_types))
1366-
return ERR_PTR(-EINVAL);
1367-
13681364
psy = kzalloc(sizeof(*psy), GFP_KERNEL);
13691365
if (!psy)
13701366
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)