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

Merge tag 'ib-psy-usb-types-signed' into psy-next

Changing usb_types type from array to bitmap in the power_supply_desc
struct requires updating power-supply drivers living in different
subsystem, so it is handled via an immutable branch.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

+132 -254
+6 -1
Documentation/ABI/testing/sysfs-class-power
··· 608 608 the supply, for example it can show if USB-PD capable source 609 609 is attached. 610 610 611 - Access: Read-Only 611 + Access: For power-supplies which consume USB power such 612 + as battery charger chips, this indicates the type of 613 + the connected USB power source and is Read-Only. 614 + 615 + For power-supplies which act as a USB power-source such as 616 + e.g. the UCS1002 USB Port Power Controller this is writable. 612 617 613 618 Valid values: 614 619 "Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD",
+5 -10
drivers/extcon/extcon-intel-cht-wc.c
··· 461 461 return 0; 462 462 } 463 463 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 - 472 464 static const enum power_supply_property cht_wc_extcon_psy_props[] = { 473 465 POWER_SUPPLY_PROP_USB_TYPE, 474 466 POWER_SUPPLY_PROP_ONLINE, ··· 469 477 static const struct power_supply_desc cht_wc_extcon_psy_desc = { 470 478 .name = "cht_wcove_pwrsrc", 471 479 .type = POWER_SUPPLY_TYPE_USB, 472 - .usb_types = cht_wc_extcon_psy_usb_types, 473 - .num_usb_types = ARRAY_SIZE(cht_wc_extcon_psy_usb_types), 480 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 481 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 482 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 483 + BIT(POWER_SUPPLY_USB_TYPE_ACA) | 484 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 474 485 .properties = cht_wc_extcon_psy_props, 475 486 .num_properties = ARRAY_SIZE(cht_wc_extcon_psy_props), 476 487 .get_property = cht_wc_extcon_psy_get_prop,
+3 -8
drivers/phy/ti/phy-tusb1210.c
··· 411 411 return 0; 412 412 } 413 413 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 - 420 414 static const enum power_supply_property tusb1210_psy_props[] = { 421 415 POWER_SUPPLY_PROP_ONLINE, 422 416 POWER_SUPPLY_PROP_USB_TYPE, ··· 420 426 static const struct power_supply_desc tusb1210_psy_desc = { 421 427 .name = "tusb1211-charger-detect", 422 428 .type = POWER_SUPPLY_TYPE_USB, 423 - .usb_types = tusb1210_psy_usb_types, 424 - .num_usb_types = ARRAY_SIZE(tusb1210_psy_usb_types), 429 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 430 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 431 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 425 432 .properties = tusb1210_psy_props, 426 433 .num_properties = ARRAY_SIZE(tusb1210_psy_props), 427 434 .get_property = tusb1210_psy_get_prop,
+4 -9
drivers/power/supply/axp20x_usb_power.c
··· 456 456 POWER_SUPPLY_PROP_USB_TYPE, 457 457 }; 458 458 459 - static enum power_supply_usb_type axp813_usb_types[] = { 460 - POWER_SUPPLY_USB_TYPE_SDP, 461 - POWER_SUPPLY_USB_TYPE_DCP, 462 - POWER_SUPPLY_USB_TYPE_CDP, 463 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 464 - }; 465 - 466 459 static const struct power_supply_desc axp20x_usb_power_desc = { 467 460 .name = "axp20x-usb", 468 461 .type = POWER_SUPPLY_TYPE_USB, ··· 484 491 .property_is_writeable = axp20x_usb_power_prop_writeable, 485 492 .get_property = axp20x_usb_power_get_property, 486 493 .set_property = axp20x_usb_power_set_property, 487 - .usb_types = axp813_usb_types, 488 - .num_usb_types = ARRAY_SIZE(axp813_usb_types), 494 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 495 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 496 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 497 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 489 498 }; 490 499 491 500 static const char * const axp20x_irq_names[] = {
+5 -10
drivers/power/supply/bq256xx_charger.c
··· 334 334 1290000, 1360000, 1430000, 1500000 335 335 }; 336 336 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 - 345 337 static int bq256xx_array_parse(int array_size, int val, const int array[]) 346 338 { 347 339 int i = 0; ··· 1244 1252 static const struct power_supply_desc bq256xx_power_supply_desc = { 1245 1253 .name = "bq256xx-charger", 1246 1254 .type = POWER_SUPPLY_TYPE_USB, 1247 - .usb_types = bq256xx_usb_type, 1248 - .num_usb_types = ARRAY_SIZE(bq256xx_usb_type), 1255 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 1256 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 1257 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 1258 + BIT(POWER_SUPPLY_USB_TYPE_ACA) | 1259 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 1249 1260 .properties = bq256xx_power_supply_props, 1250 1261 .num_properties = ARRAY_SIZE(bq256xx_power_supply_props), 1251 1262 .get_property = bq256xx_get_charger_property,
+8 -14
drivers/power/supply/cros_usbpd-charger.c
··· 73 73 POWER_SUPPLY_PROP_VOLTAGE_NOW, 74 74 }; 75 75 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 - 87 76 /* Input voltage/current limit in mV/mA. Default to none. */ 88 77 static u16 input_voltage_limit = EC_POWER_LIMIT_NONE; 89 78 static u16 input_current_limit = EC_POWER_LIMIT_NONE; ··· 632 643 psy_desc->properties = cros_usbpd_charger_props; 633 644 psy_desc->num_properties = 634 645 ARRAY_SIZE(cros_usbpd_charger_props); 635 - psy_desc->usb_types = cros_usbpd_charger_usb_types; 636 - psy_desc->num_usb_types = 637 - ARRAY_SIZE(cros_usbpd_charger_usb_types); 646 + psy_desc->usb_types = BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | 647 + BIT(POWER_SUPPLY_USB_TYPE_SDP) | 648 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 649 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 650 + BIT(POWER_SUPPLY_USB_TYPE_C) | 651 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 652 + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | 653 + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID); 638 654 } 639 655 640 656 psy_desc->name = port->name;
+1 -6
drivers/power/supply/lenovo_yoga_c630_battery.c
··· 353 353 POWER_SUPPLY_PROP_USB_TYPE, 354 354 }; 355 355 356 - static const enum power_supply_usb_type yoga_c630_psy_adpt_usb_type[] = { 357 - POWER_SUPPLY_USB_TYPE_C, 358 - }; 359 - 360 356 static const struct power_supply_desc yoga_c630_psy_adpt_psy_desc = { 361 357 .name = "yoga-c630-adapter", 362 358 .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), 365 360 .properties = yoga_c630_psy_adpt_properties, 366 361 .num_properties = ARRAY_SIZE(yoga_c630_psy_adpt_properties), 367 362 .get_property = yoga_c630_psy_adpt_get_property,
+5 -10
drivers/power/supply/mp2629_charger.c
··· 94 94 int shift; 95 95 }; 96 96 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 - 105 97 static enum power_supply_property mp2629_charger_usb_props[] = { 106 98 POWER_SUPPLY_PROP_ONLINE, 107 99 POWER_SUPPLY_PROP_USB_TYPE, ··· 479 487 static const struct power_supply_desc mp2629_usb_desc = { 480 488 .name = "mp2629_usb", 481 489 .type = POWER_SUPPLY_TYPE_USB, 482 - .usb_types = mp2629_usb_types, 483 - .num_usb_types = ARRAY_SIZE(mp2629_usb_types), 490 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 491 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 492 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 493 + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | 494 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 484 495 .properties = mp2629_charger_usb_props, 485 496 .num_properties = ARRAY_SIZE(mp2629_charger_usb_props), 486 497 .get_property = mp2629_charger_usb_get_prop,
+4 -9
drivers/power/supply/mt6360_charger.c
··· 154 154 MT6360_CHG_TYPE_MAX, 155 155 }; 156 156 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 - 164 157 static int mt6360_get_chrdet_ext_stat(struct mt6360_chg_info *mci, 165 158 bool *pwr_rdy) 166 159 { ··· 567 574 .get_property = mt6360_charger_get_property, 568 575 .set_property = mt6360_charger_set_property, 569 576 .property_is_writeable = mt6360_charger_property_is_writeable, 570 - .usb_types = mt6360_charger_usb_types, 571 - .num_usb_types = ARRAY_SIZE(mt6360_charger_usb_types), 577 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 578 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 579 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 580 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 572 581 }; 573 582 574 583 static const struct regulator_ops mt6360_chg_otg_ops = {
+4 -9
drivers/power/supply/mt6370-charger.c
··· 624 624 POWER_SUPPLY_PROP_USB_TYPE, 625 625 }; 626 626 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 - 634 627 static const struct power_supply_desc mt6370_chg_psy_desc = { 635 628 .name = "mt6370-charger", 636 629 .type = POWER_SUPPLY_TYPE_USB, ··· 632 639 .get_property = mt6370_chg_get_property, 633 640 .set_property = mt6370_chg_set_property, 634 641 .property_is_writeable = mt6370_chg_property_is_writeable, 635 - .usb_types = mt6370_chg_usb_types, 636 - .num_usb_types = ARRAY_SIZE(mt6370_chg_usb_types), 642 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 643 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 644 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 645 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 637 646 }; 638 647 639 648 static const struct regulator_ops mt6370_chg_otg_ops = {
-4
drivers/power/supply/power_supply_core.c
··· 1360 1360 pr_warn("%s: Expected proper parent device for '%s'\n", 1361 1361 __func__, desc->name); 1362 1362 1363 - if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) && 1364 - (!desc->usb_types || !desc->num_usb_types)) 1365 - return ERR_PTR(-EINVAL); 1366 - 1367 1363 psy = kzalloc(sizeof(*psy), GFP_KERNEL); 1368 1364 if (!psy) 1369 1365 return ERR_PTR(-ENOMEM);
+21 -45
drivers/power/supply/power_supply_sysfs.c
··· 209 209 POWER_SUPPLY_ATTR(TIME_TO_FULL_NOW), 210 210 POWER_SUPPLY_ATTR(TIME_TO_FULL_AVG), 211 211 POWER_SUPPLY_ENUM_ATTR(TYPE), 212 - POWER_SUPPLY_ATTR(USB_TYPE), 212 + POWER_SUPPLY_ENUM_ATTR(USB_TYPE), 213 213 POWER_SUPPLY_ENUM_ATTR(SCOPE), 214 214 POWER_SUPPLY_ATTR(PRECHARGE_CURRENT), 215 215 POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT), ··· 237 237 return to_ps_attr(attr) - power_supply_attrs; 238 238 } 239 239 240 - static ssize_t power_supply_show_usb_type(struct device *dev, 241 - const struct power_supply_desc *desc, 242 - union power_supply_propval *value, 243 - char *buf) 240 + static ssize_t power_supply_show_enum_with_available( 241 + struct device *dev, const char * const labels[], int label_count, 242 + unsigned int available_values, int value, char *buf) 244 243 { 245 - enum power_supply_usb_type usb_type; 244 + bool match = false, available, active; 246 245 ssize_t count = 0; 247 - bool match = false; 248 246 int i; 249 247 250 - for (i = 0; i < desc->num_usb_types; ++i) { 251 - usb_type = desc->usb_types[i]; 248 + for (i = 0; i < label_count; i++) { 249 + available = available_values & BIT(i); 250 + active = i == value; 252 251 253 - if (value->intval == usb_type) { 254 - count += sysfs_emit_at(buf, count, "[%s] ", 255 - POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); 252 + if (available && active) { 253 + count += sysfs_emit_at(buf, count, "[%s] ", labels[i]); 256 254 match = true; 257 - } else { 258 - count += sysfs_emit_at(buf, count, "%s ", 259 - POWER_SUPPLY_USB_TYPE_TEXT[usb_type]); 255 + } else if (available) { 256 + count += sysfs_emit_at(buf, count, "%s ", labels[i]); 260 257 } 261 258 } 262 259 263 260 if (!match) { 264 - dev_warn(dev, "driver reporting unsupported connected type\n"); 261 + dev_warn(dev, "driver reporting unavailable enum value %d\n", value); 265 262 return -EINVAL; 266 263 } 267 264 ··· 297 300 298 301 switch (psp) { 299 302 case POWER_SUPPLY_PROP_USB_TYPE: 300 - ret = power_supply_show_usb_type(dev, psy->desc, 301 - &value, buf); 303 + ret = power_supply_show_enum_with_available( 304 + dev, POWER_SUPPLY_USB_TYPE_TEXT, 305 + ARRAY_SIZE(POWER_SUPPLY_USB_TYPE_TEXT), 306 + psy->desc->usb_types, value.intval, buf); 302 307 break; 303 308 case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR: 304 309 ret = power_supply_charge_behaviour_show(dev, psy->desc->charge_behaviours, ··· 522 523 enum power_supply_charge_behaviour current_behaviour, 523 524 char *buf) 524 525 { 525 - bool match = false, available, active; 526 - ssize_t count = 0; 527 - int i; 528 - 529 - for (i = 0; i < ARRAY_SIZE(POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT); i++) { 530 - available = available_behaviours & BIT(i); 531 - active = i == current_behaviour; 532 - 533 - if (available && active) { 534 - count += sysfs_emit_at(buf, count, "[%s] ", 535 - POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[i]); 536 - match = true; 537 - } else if (available) { 538 - count += sysfs_emit_at(buf, count, "%s ", 539 - POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[i]); 540 - } 541 - } 542 - 543 - if (!match) { 544 - dev_warn(dev, "driver reporting unsupported charge behaviour\n"); 545 - return -EINVAL; 546 - } 547 - 548 - if (count) 549 - buf[count - 1] = '\n'; 550 - 551 - return count; 526 + return power_supply_show_enum_with_available( 527 + dev, POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT, 528 + ARRAY_SIZE(POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT), 529 + available_behaviours, current_behaviour, buf); 552 530 } 553 531 EXPORT_SYMBOL_GPL(power_supply_charge_behaviour_show); 554 532
+20 -17
drivers/power/supply/qcom_battmgr.c
··· 786 786 return 0; 787 787 } 788 788 789 - static const enum power_supply_usb_type usb_psy_supported_types[] = { 790 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 791 - POWER_SUPPLY_USB_TYPE_SDP, 792 - POWER_SUPPLY_USB_TYPE_DCP, 793 - POWER_SUPPLY_USB_TYPE_CDP, 794 - POWER_SUPPLY_USB_TYPE_ACA, 795 - POWER_SUPPLY_USB_TYPE_C, 796 - POWER_SUPPLY_USB_TYPE_PD, 797 - POWER_SUPPLY_USB_TYPE_PD_DRP, 798 - POWER_SUPPLY_USB_TYPE_PD_PPS, 799 - POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, 800 - }; 801 - 802 789 static const enum power_supply_property sc8280xp_usb_props[] = { 803 790 POWER_SUPPLY_PROP_ONLINE, 804 791 }; ··· 796 809 .properties = sc8280xp_usb_props, 797 810 .num_properties = ARRAY_SIZE(sc8280xp_usb_props), 798 811 .get_property = qcom_battmgr_usb_get_property, 799 - .usb_types = usb_psy_supported_types, 800 - .num_usb_types = ARRAY_SIZE(usb_psy_supported_types), 812 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | 813 + BIT(POWER_SUPPLY_USB_TYPE_SDP) | 814 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 815 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 816 + BIT(POWER_SUPPLY_USB_TYPE_ACA) | 817 + BIT(POWER_SUPPLY_USB_TYPE_C) | 818 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 819 + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | 820 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS) | 821 + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), 801 822 }; 802 823 803 824 static const enum power_supply_property sm8350_usb_props[] = { ··· 824 829 .properties = sm8350_usb_props, 825 830 .num_properties = ARRAY_SIZE(sm8350_usb_props), 826 831 .get_property = qcom_battmgr_usb_get_property, 827 - .usb_types = usb_psy_supported_types, 828 - .num_usb_types = ARRAY_SIZE(usb_psy_supported_types), 832 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN) | 833 + BIT(POWER_SUPPLY_USB_TYPE_SDP) | 834 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 835 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 836 + BIT(POWER_SUPPLY_USB_TYPE_ACA) | 837 + BIT(POWER_SUPPLY_USB_TYPE_C) | 838 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 839 + BIT(POWER_SUPPLY_USB_TYPE_PD_DRP) | 840 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS) | 841 + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID), 829 842 }; 830 843 831 844 static const u8 sm8350_wls_prop_map[] = {
+4 -9
drivers/power/supply/qcom_pmi8998_charger.c
··· 411 411 POWER_SUPPLY_PROP_USB_TYPE, 412 412 }; 413 413 414 - static enum power_supply_usb_type smb2_usb_types[] = { 415 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 416 - POWER_SUPPLY_USB_TYPE_SDP, 417 - POWER_SUPPLY_USB_TYPE_DCP, 418 - POWER_SUPPLY_USB_TYPE_CDP, 419 - }; 420 - 421 414 static int smb2_get_prop_usb_online(struct smb2_chip *chip, int *val) 422 415 { 423 416 unsigned int stat; ··· 768 775 static const struct power_supply_desc smb2_psy_desc = { 769 776 .name = "pmi8998_charger", 770 777 .type = POWER_SUPPLY_TYPE_USB, 771 - .usb_types = smb2_usb_types, 772 - .num_usb_types = ARRAY_SIZE(smb2_usb_types), 778 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 779 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 780 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 781 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 773 782 .properties = smb2_properties, 774 783 .num_properties = ARRAY_SIZE(smb2_properties), 775 784 .get_property = smb2_get_property,
+2 -7
drivers/power/supply/rk817_charger.c
··· 673 673 POWER_SUPPLY_PROP_VOLTAGE_AVG, 674 674 }; 675 675 676 - static enum power_supply_usb_type rk817_usb_type[] = { 677 - POWER_SUPPLY_USB_TYPE_DCP, 678 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 679 - }; 680 - 681 676 static const struct power_supply_desc rk817_bat_desc = { 682 677 .name = "rk817-battery", 683 678 .type = POWER_SUPPLY_TYPE_BATTERY, ··· 684 689 static const struct power_supply_desc rk817_chg_desc = { 685 690 .name = "rk817-charger", 686 691 .type = POWER_SUPPLY_TYPE_USB, 687 - .usb_types = rk817_usb_type, 688 - .num_usb_types = ARRAY_SIZE(rk817_usb_type), 692 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_DCP) | 693 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 689 694 .properties = rk817_chg_props, 690 695 .num_properties = ARRAY_SIZE(rk817_chg_props), 691 696 .get_property = rk817_chg_get_prop,
+4 -9
drivers/power/supply/rn5t618_power.c
··· 70 70 int irq; 71 71 }; 72 72 73 - static enum power_supply_usb_type rn5t618_usb_types[] = { 74 - POWER_SUPPLY_USB_TYPE_SDP, 75 - POWER_SUPPLY_USB_TYPE_DCP, 76 - POWER_SUPPLY_USB_TYPE_CDP, 77 - POWER_SUPPLY_USB_TYPE_UNKNOWN 78 - }; 79 - 80 73 static enum power_supply_property rn5t618_usb_props[] = { 81 74 /* input current limit is not very accurate */ 82 75 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, ··· 674 681 static const struct power_supply_desc rn5t618_usb_desc = { 675 682 .name = "rn5t618-usb", 676 683 .type = POWER_SUPPLY_TYPE_USB, 677 - .usb_types = rn5t618_usb_types, 678 - .num_usb_types = ARRAY_SIZE(rn5t618_usb_types), 684 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 685 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 686 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 687 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 679 688 .properties = rn5t618_usb_props, 680 689 .num_properties = ARRAY_SIZE(rn5t618_usb_props), 681 690 .get_property = rn5t618_usb_get_property,
+4 -12
drivers/power/supply/rt9467-charger.c
··· 630 630 return ret; 631 631 } 632 632 633 - static const enum power_supply_usb_type rt9467_chg_usb_types[] = { 634 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 635 - POWER_SUPPLY_USB_TYPE_SDP, 636 - POWER_SUPPLY_USB_TYPE_DCP, 637 - POWER_SUPPLY_USB_TYPE_CDP, 638 - }; 639 - 640 633 static const enum power_supply_property rt9467_chg_properties[] = { 641 634 POWER_SUPPLY_PROP_STATUS, 642 635 POWER_SUPPLY_PROP_ONLINE, ··· 738 745 RT9467_RANGE_IPREC, val->intval); 739 746 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: 740 747 return rt9467_psy_set_ieoc(data, val->intval); 741 - case POWER_SUPPLY_PROP_USB_TYPE: 742 - return regmap_field_write(data->rm_field[F_USBCHGEN], val->intval); 743 748 default: 744 749 return -EINVAL; 745 750 } ··· 755 764 case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: 756 765 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: 757 766 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: 758 - case POWER_SUPPLY_PROP_USB_TYPE: 759 767 return 1; 760 768 default: 761 769 return 0; ··· 764 774 static const struct power_supply_desc rt9467_chg_psy_desc = { 765 775 .name = "rt9467-charger", 766 776 .type = POWER_SUPPLY_TYPE_USB, 767 - .usb_types = rt9467_chg_usb_types, 768 - .num_usb_types = ARRAY_SIZE(rt9467_chg_usb_types), 777 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 778 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 779 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 780 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 769 781 .properties = rt9467_chg_properties, 770 782 .num_properties = ARRAY_SIZE(rt9467_chg_properties), 771 783 .property_is_writeable = rt9467_chg_prop_is_writeable,
+5 -10
drivers/power/supply/rt9471.c
··· 333 333 POWER_SUPPLY_PROP_MANUFACTURER, 334 334 }; 335 335 336 - static enum power_supply_usb_type rt9471_charger_usb_types[] = { 337 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 338 - POWER_SUPPLY_USB_TYPE_SDP, 339 - POWER_SUPPLY_USB_TYPE_DCP, 340 - POWER_SUPPLY_USB_TYPE_CDP, 341 - POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID, 342 - }; 343 - 344 336 static int rt9471_charger_property_is_writeable(struct power_supply *psy, 345 337 enum power_supply_property psp) 346 338 { ··· 718 726 719 727 desc->name = psy_name; 720 728 desc->type = POWER_SUPPLY_TYPE_USB; 721 - desc->usb_types = rt9471_charger_usb_types; 722 - desc->num_usb_types = ARRAY_SIZE(rt9471_charger_usb_types); 729 + desc->usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 730 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 731 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 732 + BIT(POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID) | 733 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN); 723 734 desc->properties = rt9471_charger_properties; 724 735 desc->num_properties = ARRAY_SIZE(rt9471_charger_properties); 725 736 desc->get_property = rt9471_charger_get_property;
+12 -14
drivers/power/supply/ucs1002_power.c
··· 296 296 return 0; 297 297 } 298 298 299 - static enum power_supply_usb_type ucs1002_usb_types[] = { 300 - POWER_SUPPLY_USB_TYPE_PD, 301 - POWER_SUPPLY_USB_TYPE_SDP, 302 - POWER_SUPPLY_USB_TYPE_DCP, 303 - POWER_SUPPLY_USB_TYPE_CDP, 304 - POWER_SUPPLY_USB_TYPE_UNKNOWN, 305 - }; 306 - 307 299 static int ucs1002_set_usb_type(struct ucs1002_info *info, int val) 308 300 { 309 301 unsigned int mode; 310 302 311 - if (val < 0 || val >= ARRAY_SIZE(ucs1002_usb_types)) 312 - return -EINVAL; 313 - 314 - switch (ucs1002_usb_types[val]) { 303 + switch (val) { 304 + /* 305 + * POWER_SUPPLY_USB_TYPE_UNKNOWN == 0, map this to dedicated for 306 + * userspace API compatibility with older versions of this driver 307 + * which mapped 0 to dedicated. 308 + */ 309 + case POWER_SUPPLY_USB_TYPE_UNKNOWN: 315 310 case POWER_SUPPLY_USB_TYPE_PD: 316 311 mode = V_SET_ACTIVE_MODE_DEDICATED; 317 312 break; ··· 423 428 static const struct power_supply_desc ucs1002_charger_desc = { 424 429 .name = "ucs1002", 425 430 .type = POWER_SUPPLY_TYPE_USB, 426 - .usb_types = ucs1002_usb_types, 427 - .num_usb_types = ARRAY_SIZE(ucs1002_usb_types), 431 + .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 432 + BIT(POWER_SUPPLY_USB_TYPE_CDP) | 433 + BIT(POWER_SUPPLY_USB_TYPE_DCP) | 434 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 435 + BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 428 436 .get_property = ucs1002_get_property, 429 437 .set_property = ucs1002_set_property, 430 438 .property_is_writeable = ucs1002_property_is_writeable,
+3 -8
drivers/usb/typec/anx7411.c
··· 1339 1339 dev_err(dev, "failed to get GPIO IRQ\n"); 1340 1340 } 1341 1341 1342 - static enum power_supply_usb_type anx7411_psy_usb_types[] = { 1343 - POWER_SUPPLY_USB_TYPE_C, 1344 - POWER_SUPPLY_USB_TYPE_PD, 1345 - POWER_SUPPLY_USB_TYPE_PD_PPS, 1346 - }; 1347 - 1348 1342 static enum power_supply_property anx7411_psy_props[] = { 1349 1343 POWER_SUPPLY_PROP_USB_TYPE, 1350 1344 POWER_SUPPLY_PROP_ONLINE, ··· 1416 1422 1417 1423 psy_desc->name = psy_name; 1418 1424 psy_desc->type = POWER_SUPPLY_TYPE_USB; 1419 - psy_desc->usb_types = anx7411_psy_usb_types; 1420 - psy_desc->num_usb_types = ARRAY_SIZE(anx7411_psy_usb_types); 1425 + psy_desc->usb_types = BIT(POWER_SUPPLY_USB_TYPE_C) | 1426 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 1427 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); 1421 1428 psy_desc->properties = anx7411_psy_props; 1422 1429 psy_desc->num_properties = ARRAY_SIZE(anx7411_psy_props); 1423 1430
+3 -8
drivers/usb/typec/rt1719.c
··· 109 109 u16 conn_stat; 110 110 }; 111 111 112 - static const enum power_supply_usb_type rt1719_psy_usb_types[] = { 113 - POWER_SUPPLY_USB_TYPE_C, 114 - POWER_SUPPLY_USB_TYPE_PD, 115 - POWER_SUPPLY_USB_TYPE_PD_PPS 116 - }; 117 - 118 112 static const enum power_supply_property rt1719_psy_properties[] = { 119 113 POWER_SUPPLY_PROP_ONLINE, 120 114 POWER_SUPPLY_PROP_USB_TYPE, ··· 566 572 567 573 data->psy_desc.name = psy_name; 568 574 data->psy_desc.type = POWER_SUPPLY_TYPE_USB; 569 - data->psy_desc.usb_types = rt1719_psy_usb_types; 570 - data->psy_desc.num_usb_types = ARRAY_SIZE(rt1719_psy_usb_types); 575 + data->psy_desc.usb_types = BIT(POWER_SUPPLY_USB_TYPE_C) | 576 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 577 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); 571 578 data->psy_desc.properties = rt1719_psy_properties; 572 579 data->psy_desc.num_properties = ARRAY_SIZE(rt1719_psy_properties); 573 580 data->psy_desc.get_property = rt1719_psy_get_property;
+3 -8
drivers/usb/typec/tcpm/tcpm.c
··· 7484 7484 } 7485 7485 } 7486 7486 7487 - static enum power_supply_usb_type tcpm_psy_usb_types[] = { 7488 - POWER_SUPPLY_USB_TYPE_C, 7489 - POWER_SUPPLY_USB_TYPE_PD, 7490 - POWER_SUPPLY_USB_TYPE_PD_PPS, 7491 - }; 7492 - 7493 7487 static const char *tcpm_psy_name_prefix = "tcpm-source-psy-"; 7494 7488 7495 7489 static int devm_tcpm_psy_register(struct tcpm_port *port) ··· 7504 7510 port_dev_name); 7505 7511 port->psy_desc.name = psy_name; 7506 7512 port->psy_desc.type = POWER_SUPPLY_TYPE_USB; 7507 - port->psy_desc.usb_types = tcpm_psy_usb_types; 7508 - port->psy_desc.num_usb_types = ARRAY_SIZE(tcpm_psy_usb_types); 7513 + port->psy_desc.usb_types = BIT(POWER_SUPPLY_USB_TYPE_C) | 7514 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 7515 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); 7509 7516 port->psy_desc.properties = tcpm_psy_props; 7510 7517 port->psy_desc.num_properties = ARRAY_SIZE(tcpm_psy_props); 7511 7518 port->psy_desc.get_property = tcpm_psy_get_prop;
+2 -7
drivers/usb/typec/tipd/core.c
··· 150 150 POWER_SUPPLY_PROP_ONLINE, 151 151 }; 152 152 153 - static enum power_supply_usb_type tps6598x_psy_usb_types[] = { 154 - POWER_SUPPLY_USB_TYPE_C, 155 - POWER_SUPPLY_USB_TYPE_PD, 156 - }; 157 - 158 153 static const char *tps6598x_psy_name_prefix = "tps6598x-source-psy-"; 159 154 160 155 /* ··· 822 827 823 828 tps->psy_desc.name = psy_name; 824 829 tps->psy_desc.type = POWER_SUPPLY_TYPE_USB; 825 - tps->psy_desc.usb_types = tps6598x_psy_usb_types; 826 - tps->psy_desc.num_usb_types = ARRAY_SIZE(tps6598x_psy_usb_types); 830 + tps->psy_desc.usb_types = BIT(POWER_SUPPLY_USB_TYPE_C) | 831 + BIT(POWER_SUPPLY_USB_TYPE_PD); 827 832 tps->psy_desc.properties = tps6598x_psy_props; 828 833 tps->psy_desc.num_properties = ARRAY_SIZE(tps6598x_psy_props); 829 834 tps->psy_desc.get_property = tps6598x_psy_get_prop;
+3 -8
drivers/usb/typec/ucsi/psy.c
··· 254 254 } 255 255 } 256 256 257 - static enum power_supply_usb_type ucsi_psy_usb_types[] = { 258 - POWER_SUPPLY_USB_TYPE_C, 259 - POWER_SUPPLY_USB_TYPE_PD, 260 - POWER_SUPPLY_USB_TYPE_PD_PPS, 261 - }; 262 - 263 257 int ucsi_register_port_psy(struct ucsi_connector *con) 264 258 { 265 259 struct power_supply_config psy_cfg = {}; ··· 270 276 271 277 con->psy_desc.name = psy_name; 272 278 con->psy_desc.type = POWER_SUPPLY_TYPE_USB; 273 - con->psy_desc.usb_types = ucsi_psy_usb_types; 274 - con->psy_desc.num_usb_types = ARRAY_SIZE(ucsi_psy_usb_types); 279 + con->psy_desc.usb_types = BIT(POWER_SUPPLY_USB_TYPE_C) | 280 + BIT(POWER_SUPPLY_USB_TYPE_PD) | 281 + BIT(POWER_SUPPLY_USB_TYPE_PD_PPS); 275 282 con->psy_desc.properties = ucsi_psy_props; 276 283 con->psy_desc.num_properties = ARRAY_SIZE(ucsi_psy_props); 277 284 con->psy_desc.get_property = ucsi_psy_get_prop;
+1 -2
include/linux/power_supply.h
··· 243 243 const char *name; 244 244 enum power_supply_type type; 245 245 u8 charge_behaviours; 246 - const enum power_supply_usb_type *usb_types; 247 - size_t num_usb_types; 246 + u32 usb_types; 248 247 const enum power_supply_property *properties; 249 248 size_t num_properties; 250 249