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

power: supply: pmi8998_charger: rename to qcom_smbx

Prepare to add smb5 support by making variables and the file name more
generic. Also take the opportunity to remove the "_charger" suffix since
smb2 always refers to a charger.

Signed-off-by: Casey Connolly <casey.connolly@linaro.org>
Link: https://lore.kernel.org/r/20250619-smb2-smb5-support-v1-4-ac5dec51b6e1@linaro.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Casey Connolly and committed by
Sebastian Reichel
5ec53bcc 6c539377

+75 -75
+1 -1
drivers/power/supply/Makefile
··· 120 120 obj-$(CONFIG_BATTERY_SURFACE) += surface_battery.o 121 121 obj-$(CONFIG_CHARGER_SURFACE) += surface_charger.o 122 122 obj-$(CONFIG_BATTERY_UG3105) += ug3105_battery.o 123 - obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_pmi8998_charger.o 123 + obj-$(CONFIG_CHARGER_QCOM_SMB2) += qcom_smbx.o 124 124 obj-$(CONFIG_FUEL_GAUGE_MM8013) += mm8013.o
+74 -74
drivers/power/supply/qcom_pmi8998_charger.c drivers/power/supply/qcom_smbx.c
··· 362 362 DISABLE_CHARGE, 363 363 }; 364 364 365 - struct smb2_register { 365 + struct smb_init_register { 366 366 u16 addr; 367 367 u8 mask; 368 368 u8 val; 369 369 }; 370 370 371 371 /** 372 - * struct smb2_chip - smb2 chip structure 372 + * struct smb_chip - smb chip structure 373 373 * @dev: Device reference for power_supply 374 374 * @name: The platform device name 375 - * @base: Base address for smb2 registers 375 + * @base: Base address for smb registers 376 376 * @regmap: Register map 377 377 * @batt_info: Battery data from DT 378 378 * @status_change_work: Worker to handle plug/unplug events ··· 382 382 * @usb_in_v_chan: USB_IN voltage measurement channel 383 383 * @chg_psy: Charger power supply instance 384 384 */ 385 - struct smb2_chip { 385 + struct smb_chip { 386 386 struct device *dev; 387 387 const char *name; 388 388 unsigned int base; ··· 399 399 struct power_supply *chg_psy; 400 400 }; 401 401 402 - static enum power_supply_property smb2_properties[] = { 402 + static enum power_supply_property smb_properties[] = { 403 403 POWER_SUPPLY_PROP_MANUFACTURER, 404 404 POWER_SUPPLY_PROP_MODEL_NAME, 405 405 POWER_SUPPLY_PROP_CURRENT_MAX, ··· 411 411 POWER_SUPPLY_PROP_USB_TYPE, 412 412 }; 413 413 414 - static int smb2_get_prop_usb_online(struct smb2_chip *chip, int *val) 414 + static int smb_get_prop_usb_online(struct smb_chip *chip, int *val) 415 415 { 416 416 unsigned int stat; 417 417 int rc; ··· 431 431 * Qualcomm "automatic power source detection" aka APSD 432 432 * tells us what type of charger we're connected to. 433 433 */ 434 - static int smb2_apsd_get_charger_type(struct smb2_chip *chip, int *val) 434 + static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val) 435 435 { 436 436 unsigned int apsd_stat, stat; 437 437 int usb_online = 0; 438 438 int rc; 439 439 440 - rc = smb2_get_prop_usb_online(chip, &usb_online); 440 + rc = smb_get_prop_usb_online(chip, &usb_online); 441 441 if (!usb_online) { 442 442 *val = POWER_SUPPLY_USB_TYPE_UNKNOWN; 443 443 return rc; ··· 471 471 return 0; 472 472 } 473 473 474 - static int smb2_get_prop_status(struct smb2_chip *chip, int *val) 474 + static int smb_get_prop_status(struct smb_chip *chip, int *val) 475 475 { 476 476 unsigned char stat[2]; 477 477 int usb_online = 0; 478 478 int rc; 479 479 480 - rc = smb2_get_prop_usb_online(chip, &usb_online); 480 + rc = smb_get_prop_usb_online(chip, &usb_online); 481 481 if (!usb_online) { 482 482 *val = POWER_SUPPLY_STATUS_DISCHARGING; 483 483 return rc; ··· 519 519 } 520 520 } 521 521 522 - static inline int smb2_get_current_limit(struct smb2_chip *chip, 522 + static inline int smb_get_current_limit(struct smb_chip *chip, 523 523 unsigned int *val) 524 524 { 525 525 int rc = regmap_read(chip->regmap, chip->base + ICL_STATUS, val); ··· 529 529 return rc; 530 530 } 531 531 532 - static int smb2_set_current_limit(struct smb2_chip *chip, unsigned int val) 532 + static int smb_set_current_limit(struct smb_chip *chip, unsigned int val) 533 533 { 534 534 unsigned char val_raw; 535 535 ··· 544 544 val_raw); 545 545 } 546 546 547 - static void smb2_status_change_work(struct work_struct *work) 547 + static void smb_status_change_work(struct work_struct *work) 548 548 { 549 549 unsigned int charger_type, current_ua; 550 550 int usb_online = 0; 551 551 int count, rc; 552 - struct smb2_chip *chip; 552 + struct smb_chip *chip; 553 553 554 - chip = container_of(work, struct smb2_chip, status_change_work.work); 554 + chip = container_of(work, struct smb_chip, status_change_work.work); 555 555 556 - smb2_get_prop_usb_online(chip, &usb_online); 556 + smb_get_prop_usb_online(chip, &usb_online); 557 557 if (!usb_online) 558 558 return; 559 559 560 560 for (count = 0; count < 3; count++) { 561 561 dev_dbg(chip->dev, "get charger type retry %d\n", count); 562 - rc = smb2_apsd_get_charger_type(chip, &charger_type); 562 + rc = smb_apsd_get_charger_type(chip, &charger_type); 563 563 if (rc != -EAGAIN) 564 564 break; 565 565 msleep(100); ··· 592 592 break; 593 593 } 594 594 595 - smb2_set_current_limit(chip, current_ua); 595 + smb_set_current_limit(chip, current_ua); 596 596 power_supply_changed(chip->chg_psy); 597 597 } 598 598 599 - static int smb2_get_iio_chan(struct smb2_chip *chip, struct iio_channel *chan, 599 + static int smb_get_iio_chan(struct smb_chip *chip, struct iio_channel *chan, 600 600 int *val) 601 601 { 602 602 int rc; ··· 617 617 return iio_read_channel_processed(chan, val); 618 618 } 619 619 620 - static int smb2_get_prop_health(struct smb2_chip *chip, int *val) 620 + static int smb_get_prop_health(struct smb_chip *chip, int *val) 621 621 { 622 622 int rc; 623 623 unsigned int stat; ··· 651 651 } 652 652 } 653 653 654 - static int smb2_get_property(struct power_supply *psy, 654 + static int smb_get_property(struct power_supply *psy, 655 655 enum power_supply_property psp, 656 656 union power_supply_propval *val) 657 657 { 658 - struct smb2_chip *chip = power_supply_get_drvdata(psy); 658 + struct smb_chip *chip = power_supply_get_drvdata(psy); 659 659 660 660 switch (psp) { 661 661 case POWER_SUPPLY_PROP_MANUFACTURER: ··· 665 665 val->strval = chip->name; 666 666 return 0; 667 667 case POWER_SUPPLY_PROP_CURRENT_MAX: 668 - return smb2_get_current_limit(chip, &val->intval); 668 + return smb_get_current_limit(chip, &val->intval); 669 669 case POWER_SUPPLY_PROP_CURRENT_NOW: 670 - return smb2_get_iio_chan(chip, chip->usb_in_i_chan, 670 + return smb_get_iio_chan(chip, chip->usb_in_i_chan, 671 671 &val->intval); 672 672 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 673 - return smb2_get_iio_chan(chip, chip->usb_in_v_chan, 673 + return smb_get_iio_chan(chip, chip->usb_in_v_chan, 674 674 &val->intval); 675 675 case POWER_SUPPLY_PROP_ONLINE: 676 - return smb2_get_prop_usb_online(chip, &val->intval); 676 + return smb_get_prop_usb_online(chip, &val->intval); 677 677 case POWER_SUPPLY_PROP_STATUS: 678 - return smb2_get_prop_status(chip, &val->intval); 678 + return smb_get_prop_status(chip, &val->intval); 679 679 case POWER_SUPPLY_PROP_HEALTH: 680 - return smb2_get_prop_health(chip, &val->intval); 680 + return smb_get_prop_health(chip, &val->intval); 681 681 case POWER_SUPPLY_PROP_USB_TYPE: 682 - return smb2_apsd_get_charger_type(chip, &val->intval); 682 + return smb_apsd_get_charger_type(chip, &val->intval); 683 683 default: 684 684 dev_err(chip->dev, "invalid property: %d\n", psp); 685 685 return -EINVAL; 686 686 } 687 687 } 688 688 689 - static int smb2_set_property(struct power_supply *psy, 689 + static int smb_set_property(struct power_supply *psy, 690 690 enum power_supply_property psp, 691 691 const union power_supply_propval *val) 692 692 { 693 - struct smb2_chip *chip = power_supply_get_drvdata(psy); 693 + struct smb_chip *chip = power_supply_get_drvdata(psy); 694 694 695 695 switch (psp) { 696 696 case POWER_SUPPLY_PROP_CURRENT_MAX: 697 - return smb2_set_current_limit(chip, val->intval); 697 + return smb_set_current_limit(chip, val->intval); 698 698 default: 699 699 dev_err(chip->dev, "No setter for property: %d\n", psp); 700 700 return -EINVAL; 701 701 } 702 702 } 703 703 704 - static int smb2_property_is_writable(struct power_supply *psy, 704 + static int smb_property_is_writable(struct power_supply *psy, 705 705 enum power_supply_property psp) 706 706 { 707 707 switch (psp) { ··· 712 712 } 713 713 } 714 714 715 - static irqreturn_t smb2_handle_batt_overvoltage(int irq, void *data) 715 + static irqreturn_t smb_handle_batt_overvoltage(int irq, void *data) 716 716 { 717 - struct smb2_chip *chip = data; 717 + struct smb_chip *chip = data; 718 718 unsigned int status; 719 719 720 720 regmap_read(chip->regmap, chip->base + BATTERY_CHARGER_STATUS_2, ··· 729 729 return IRQ_HANDLED; 730 730 } 731 731 732 - static irqreturn_t smb2_handle_usb_plugin(int irq, void *data) 732 + static irqreturn_t smb_handle_usb_plugin(int irq, void *data) 733 733 { 734 - struct smb2_chip *chip = data; 734 + struct smb_chip *chip = data; 735 735 736 736 power_supply_changed(chip->chg_psy); 737 737 ··· 741 741 return IRQ_HANDLED; 742 742 } 743 743 744 - static irqreturn_t smb2_handle_usb_icl_change(int irq, void *data) 744 + static irqreturn_t smb_handle_usb_icl_change(int irq, void *data) 745 745 { 746 - struct smb2_chip *chip = data; 746 + struct smb_chip *chip = data; 747 747 748 748 power_supply_changed(chip->chg_psy); 749 749 750 750 return IRQ_HANDLED; 751 751 } 752 752 753 - static irqreturn_t smb2_handle_wdog_bark(int irq, void *data) 753 + static irqreturn_t smb_handle_wdog_bark(int irq, void *data) 754 754 { 755 - struct smb2_chip *chip = data; 755 + struct smb_chip *chip = data; 756 756 int rc; 757 757 758 758 power_supply_changed(chip->chg_psy); ··· 765 765 return IRQ_HANDLED; 766 766 } 767 767 768 - static const struct power_supply_desc smb2_psy_desc = { 768 + static const struct power_supply_desc smb_psy_desc = { 769 769 .name = "pmi8998_charger", 770 770 .type = POWER_SUPPLY_TYPE_USB, 771 771 .usb_types = BIT(POWER_SUPPLY_USB_TYPE_SDP) | 772 772 BIT(POWER_SUPPLY_USB_TYPE_CDP) | 773 773 BIT(POWER_SUPPLY_USB_TYPE_DCP) | 774 774 BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN), 775 - .properties = smb2_properties, 776 - .num_properties = ARRAY_SIZE(smb2_properties), 777 - .get_property = smb2_get_property, 778 - .set_property = smb2_set_property, 779 - .property_is_writeable = smb2_property_is_writable, 775 + .properties = smb_properties, 776 + .num_properties = ARRAY_SIZE(smb_properties), 777 + .get_property = smb_get_property, 778 + .set_property = smb_set_property, 779 + .property_is_writeable = smb_property_is_writable, 780 780 }; 781 781 782 782 /* Init sequence derived from vendor downstream driver */ 783 - static const struct smb2_register smb2_init_seq[] = { 783 + static const struct smb_init_register smb_init_seq[] = { 784 784 { .addr = AICL_RERUN_TIME_CFG, .mask = AICL_RERUN_TIME_MASK, .val = 0 }, 785 785 /* 786 786 * By default configure us as an upstream facing port ··· 882 882 .val = 1000000 / CURRENT_SCALE_FACTOR }, 883 883 }; 884 884 885 - static int smb2_init_hw(struct smb2_chip *chip) 885 + static int smb_init_hw(struct smb_chip *chip) 886 886 { 887 887 int rc, i; 888 888 889 - for (i = 0; i < ARRAY_SIZE(smb2_init_seq); i++) { 889 + for (i = 0; i < ARRAY_SIZE(smb_init_seq); i++) { 890 890 dev_dbg(chip->dev, "%d: Writing 0x%02x to 0x%02x\n", i, 891 - smb2_init_seq[i].val, smb2_init_seq[i].addr); 891 + smb_init_seq[i].val, smb_init_seq[i].addr); 892 892 rc = regmap_update_bits(chip->regmap, 893 - chip->base + smb2_init_seq[i].addr, 894 - smb2_init_seq[i].mask, 895 - smb2_init_seq[i].val); 893 + chip->base + smb_init_seq[i].addr, 894 + smb_init_seq[i].mask, 895 + smb_init_seq[i].val); 896 896 if (rc < 0) 897 897 return dev_err_probe(chip->dev, rc, 898 898 "%s: init command %d failed\n", ··· 902 902 return 0; 903 903 } 904 904 905 - static int smb2_init_irq(struct smb2_chip *chip, int *irq, const char *name, 905 + static int smb_init_irq(struct smb_chip *chip, int *irq, const char *name, 906 906 irqreturn_t (*handler)(int irq, void *data)) 907 907 { 908 908 int irqnum; ··· 924 924 return 0; 925 925 } 926 926 927 - static int smb2_probe(struct platform_device *pdev) 927 + static int smb_probe(struct platform_device *pdev) 928 928 { 929 929 struct power_supply_config supply_config = {}; 930 930 struct power_supply_desc *desc; 931 - struct smb2_chip *chip; 931 + struct smb_chip *chip; 932 932 int rc, irq; 933 933 934 934 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); ··· 959 959 "Couldn't get usbin_i IIO channel\n"); 960 960 } 961 961 962 - rc = smb2_init_hw(chip); 962 + rc = smb_init_hw(chip); 963 963 if (rc < 0) 964 964 return rc; 965 965 966 966 supply_config.drv_data = chip; 967 967 supply_config.fwnode = dev_fwnode(&pdev->dev); 968 968 969 - desc = devm_kzalloc(chip->dev, sizeof(smb2_psy_desc), GFP_KERNEL); 969 + desc = devm_kzalloc(chip->dev, sizeof(smb_psy_desc), GFP_KERNEL); 970 970 if (!desc) 971 971 return -ENOMEM; 972 - memcpy(desc, &smb2_psy_desc, sizeof(smb2_psy_desc)); 972 + memcpy(desc, &smb_psy_desc, sizeof(smb_psy_desc)); 973 973 desc->name = 974 974 devm_kasprintf(chip->dev, GFP_KERNEL, "%s-charger", 975 975 (const char *)device_get_match_data(chip->dev)); ··· 988 988 "Failed to get battery info\n"); 989 989 990 990 rc = devm_delayed_work_autocancel(chip->dev, &chip->status_change_work, 991 - smb2_status_change_work); 991 + smb_status_change_work); 992 992 if (rc) 993 993 return dev_err_probe(chip->dev, rc, 994 994 "Failed to init status change work\n"); ··· 999 999 if (rc < 0) 1000 1000 return dev_err_probe(chip->dev, rc, "Couldn't set vbat max\n"); 1001 1001 1002 - rc = smb2_init_irq(chip, &irq, "bat-ov", smb2_handle_batt_overvoltage); 1002 + rc = smb_init_irq(chip, &irq, "bat-ov", smb_handle_batt_overvoltage); 1003 1003 if (rc < 0) 1004 1004 return rc; 1005 1005 1006 - rc = smb2_init_irq(chip, &chip->cable_irq, "usb-plugin", 1007 - smb2_handle_usb_plugin); 1006 + rc = smb_init_irq(chip, &chip->cable_irq, "usb-plugin", 1007 + smb_handle_usb_plugin); 1008 1008 if (rc < 0) 1009 1009 return rc; 1010 1010 1011 - rc = smb2_init_irq(chip, &irq, "usbin-icl-change", 1012 - smb2_handle_usb_icl_change); 1011 + rc = smb_init_irq(chip, &irq, "usbin-icl-change", 1012 + smb_handle_usb_icl_change); 1013 1013 if (rc < 0) 1014 1014 return rc; 1015 - rc = smb2_init_irq(chip, &irq, "wdog-bark", smb2_handle_wdog_bark); 1015 + rc = smb_init_irq(chip, &irq, "wdog-bark", smb_handle_wdog_bark); 1016 1016 if (rc < 0) 1017 1017 return rc; 1018 1018 ··· 1030 1030 return 0; 1031 1031 } 1032 1032 1033 - static const struct of_device_id smb2_match_id_table[] = { 1033 + static const struct of_device_id smb_match_id_table[] = { 1034 1034 { .compatible = "qcom,pmi8998-charger", .data = "pmi8998" }, 1035 1035 { .compatible = "qcom,pm660-charger", .data = "pm660" }, 1036 1036 { /* sentinal */ } 1037 1037 }; 1038 - MODULE_DEVICE_TABLE(of, smb2_match_id_table); 1038 + MODULE_DEVICE_TABLE(of, smb_match_id_table); 1039 1039 1040 - static struct platform_driver qcom_spmi_smb2 = { 1041 - .probe = smb2_probe, 1040 + static struct platform_driver qcom_spmi_smb = { 1041 + .probe = smb_probe, 1042 1042 .driver = { 1043 - .name = "qcom-pmi8998/pm660-charger", 1044 - .of_match_table = smb2_match_id_table, 1043 + .name = "qcom-smbx-charger", 1044 + .of_match_table = smb_match_id_table, 1045 1045 }, 1046 1046 }; 1047 1047 1048 - module_platform_driver(qcom_spmi_smb2); 1048 + module_platform_driver(qcom_spmi_smb); 1049 1049 1050 1050 MODULE_AUTHOR("Casey Connolly <casey.connolly@linaro.org>"); 1051 1051 MODULE_DESCRIPTION("Qualcomm SMB2 Charger Driver");