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

Configure Feed

Select the types of activity you want to include in your feed.

USB: typec: tps6598x: Refactor tps6598x port registration

tps6598x and cd321x use TPS_REG_SYSTEM_CONF to get dr/pr roles
where other similar devices don't have this register such as tps25750.

Move tps6598x port registration to its own function

Signed-off-by: Abdel Alkuor <abdelalkuor@geotab.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20231003155842.57313-5-alkuor@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abdel Alkuor and committed by
Greg Kroah-Hartman
8f999ce6 c5e95ec3

+54 -45
+54 -45
drivers/usb/typec/tipd/core.c
··· 711 711 return PTR_ERR_OR_ZERO(tps->psy); 712 712 } 713 713 714 + static int 715 + tps6598x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) 716 + { 717 + int ret; 718 + u32 conf; 719 + struct typec_capability typec_cap = { }; 720 + 721 + ret = tps6598x_read32(tps, TPS_REG_SYSTEM_CONF, &conf); 722 + if (ret) 723 + return ret; 724 + 725 + typec_cap.revision = USB_TYPEC_REV_1_2; 726 + typec_cap.pd_revision = 0x200; 727 + typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE; 728 + typec_cap.driver_data = tps; 729 + typec_cap.ops = &tps6598x_ops; 730 + typec_cap.fwnode = fwnode; 731 + 732 + switch (TPS_SYSCONF_PORTINFO(conf)) { 733 + case TPS_PORTINFO_SINK_ACCESSORY: 734 + case TPS_PORTINFO_SINK: 735 + typec_cap.type = TYPEC_PORT_SNK; 736 + typec_cap.data = TYPEC_PORT_UFP; 737 + break; 738 + case TPS_PORTINFO_DRP_UFP_DRD: 739 + case TPS_PORTINFO_DRP_DFP_DRD: 740 + typec_cap.type = TYPEC_PORT_DRP; 741 + typec_cap.data = TYPEC_PORT_DRD; 742 + break; 743 + case TPS_PORTINFO_DRP_UFP: 744 + typec_cap.type = TYPEC_PORT_DRP; 745 + typec_cap.data = TYPEC_PORT_UFP; 746 + break; 747 + case TPS_PORTINFO_DRP_DFP: 748 + typec_cap.type = TYPEC_PORT_DRP; 749 + typec_cap.data = TYPEC_PORT_DFP; 750 + break; 751 + case TPS_PORTINFO_SOURCE: 752 + typec_cap.type = TYPEC_PORT_SRC; 753 + typec_cap.data = TYPEC_PORT_DFP; 754 + break; 755 + default: 756 + return -ENODEV; 757 + } 758 + 759 + tps->port = typec_register_port(tps->dev, &typec_cap); 760 + if (IS_ERR(tps->port)) 761 + return PTR_ERR(tps->port); 762 + 763 + return 0; 764 + } 765 + 714 766 static int tps6598x_probe(struct i2c_client *client) 715 767 { 716 768 irq_handler_t irq_handler = tps6598x_interrupt; 717 769 struct device_node *np = client->dev.of_node; 718 - struct typec_capability typec_cap = { }; 719 770 struct tps6598x *tps; 720 771 struct fwnode_handle *fwnode; 721 772 u32 status; 722 - u32 conf; 723 773 u32 vid; 724 774 int ret; 725 775 u64 mask1; ··· 830 780 goto err_clear_mask; 831 781 trace_tps6598x_status(status); 832 782 833 - ret = tps6598x_read32(tps, TPS_REG_SYSTEM_CONF, &conf); 834 - if (ret < 0) 835 - goto err_clear_mask; 836 - 837 783 /* 838 784 * This fwnode has a "compatible" property, but is never populated as a 839 785 * struct device. Instead we simply parse it to read the properties. ··· 847 801 goto err_fwnode_put; 848 802 } 849 803 850 - typec_cap.revision = USB_TYPEC_REV_1_2; 851 - typec_cap.pd_revision = 0x200; 852 - typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE; 853 - typec_cap.driver_data = tps; 854 - typec_cap.ops = &tps6598x_ops; 855 - typec_cap.fwnode = fwnode; 856 - 857 - switch (TPS_SYSCONF_PORTINFO(conf)) { 858 - case TPS_PORTINFO_SINK_ACCESSORY: 859 - case TPS_PORTINFO_SINK: 860 - typec_cap.type = TYPEC_PORT_SNK; 861 - typec_cap.data = TYPEC_PORT_UFP; 862 - break; 863 - case TPS_PORTINFO_DRP_UFP_DRD: 864 - case TPS_PORTINFO_DRP_DFP_DRD: 865 - typec_cap.type = TYPEC_PORT_DRP; 866 - typec_cap.data = TYPEC_PORT_DRD; 867 - break; 868 - case TPS_PORTINFO_DRP_UFP: 869 - typec_cap.type = TYPEC_PORT_DRP; 870 - typec_cap.data = TYPEC_PORT_UFP; 871 - break; 872 - case TPS_PORTINFO_DRP_DFP: 873 - typec_cap.type = TYPEC_PORT_DRP; 874 - typec_cap.data = TYPEC_PORT_DFP; 875 - break; 876 - case TPS_PORTINFO_SOURCE: 877 - typec_cap.type = TYPEC_PORT_SRC; 878 - typec_cap.data = TYPEC_PORT_DFP; 879 - break; 880 - default: 881 - ret = -ENODEV; 882 - goto err_role_put; 883 - } 884 - 885 804 ret = devm_tps6598_psy_register(tps); 886 805 if (ret) 887 806 goto err_role_put; 888 807 889 - tps->port = typec_register_port(&client->dev, &typec_cap); 890 - if (IS_ERR(tps->port)) { 891 - ret = PTR_ERR(tps->port); 808 + ret = tps6598x_register_port(tps, fwnode); 809 + if (ret) 892 810 goto err_role_put; 893 - } 894 811 895 812 if (status & TPS_STATUS_PLUG_PRESENT) { 896 813 ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);