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

PCI: of: Add of_pci_get_equalization_presets() API

PCIe equalization presets are predefined settings used to optimize
signal integrity by compensating for signal loss and distortion in
high-speed data transmission.

As per PCIe spec 6.0.1 revision section 8.3.3.3 & 4.2.4 for data rates
of 8.0 GT/s, 16.0 GT/s, 32.0 GT/s, and 64.0 GT/s, there is a way to
configure lane equalization presets for each lane to enhance the PCIe
link reliability. Each preset value represents a different combination
of pre-shoot and de-emphasis values. For each data rate, different
registers are defined: for 8.0 GT/s, registers are defined in section
7.7.3.4; for 16.0 GT/s, in section 7.7.5.9, etc. The 8.0 GT/s rate has
an extra receiver preset hint, requiring 16 bits per lane, while the
remaining data rates use 8 bits per lane.

Based on the number of lanes and the supported data rate,
of_pci_get_equalization_presets() reads the device tree property and
stores in the presets structure.

Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://patch.msgid.link/20250328-preset_v6-v9-2-22cfa0490518@oss.qualcomm.com

authored by

Krishna Chaitanya Chundru and committed by
Manivannan Sadhasivam
57a4591d 0af2f6be

+75 -1
+44
drivers/pci/of.c
··· 966 966 return slot_power_limit_mw; 967 967 } 968 968 EXPORT_SYMBOL_GPL(of_pci_get_slot_power_limit); 969 + 970 + /** 971 + * of_pci_get_equalization_presets - Parses the "eq-presets-Ngts" property. 972 + * 973 + * @dev: Device containing the properties. 974 + * @presets: Pointer to store the parsed data. 975 + * @num_lanes: Maximum number of lanes supported. 976 + * 977 + * If the property is present, read and store the data in the @presets structure. 978 + * Else, assign a default value of PCI_EQ_RESV. 979 + * 980 + * Return: 0 if the property is not available or successfully parsed else 981 + * errno otherwise. 982 + */ 983 + int of_pci_get_equalization_presets(struct device *dev, 984 + struct pci_eq_presets *presets, 985 + int num_lanes) 986 + { 987 + char name[20]; 988 + int ret; 989 + 990 + presets->eq_presets_8gts[0] = PCI_EQ_RESV; 991 + ret = of_property_read_u16_array(dev->of_node, "eq-presets-8gts", 992 + presets->eq_presets_8gts, num_lanes); 993 + if (ret && ret != -EINVAL) { 994 + dev_err(dev, "Error reading eq-presets-8gts: %d\n", ret); 995 + return ret; 996 + } 997 + 998 + for (int i = 0; i < EQ_PRESET_TYPE_MAX - 1; i++) { 999 + presets->eq_presets_Ngts[i][0] = PCI_EQ_RESV; 1000 + snprintf(name, sizeof(name), "eq-presets-%dgts", 8 << (i + 1)); 1001 + ret = of_property_read_u8_array(dev->of_node, name, 1002 + presets->eq_presets_Ngts[i], 1003 + num_lanes); 1004 + if (ret && ret != -EINVAL) { 1005 + dev_err(dev, "Error reading %s: %d\n", name, ret); 1006 + return ret; 1007 + } 1008 + } 1009 + 1010 + return 0; 1011 + } 1012 + EXPORT_SYMBOL_GPL(of_pci_get_equalization_presets);
+31 -1
drivers/pci/pci.h
··· 9 9 /* Number of possible devfns: 0.0 to 1f.7 inclusive */ 10 10 #define MAX_NR_DEVFNS 256 11 11 12 + #define MAX_NR_LANES 16 13 + 12 14 #define PCI_FIND_CAP_TTL 48 13 15 14 16 #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ ··· 878 876 879 877 struct device_node; 880 878 879 + #define PCI_EQ_RESV 0xff 880 + 881 + enum equalization_preset_type { 882 + EQ_PRESET_TYPE_8GTS, 883 + EQ_PRESET_TYPE_16GTS, 884 + EQ_PRESET_TYPE_32GTS, 885 + EQ_PRESET_TYPE_64GTS, 886 + EQ_PRESET_TYPE_MAX 887 + }; 888 + 889 + struct pci_eq_presets { 890 + u16 eq_presets_8gts[MAX_NR_LANES]; 891 + u8 eq_presets_Ngts[EQ_PRESET_TYPE_MAX - 1][MAX_NR_LANES]; 892 + }; 893 + 881 894 #ifdef CONFIG_OF 882 895 int of_get_pci_domain_nr(struct device_node *node); 883 896 int of_pci_get_max_link_speed(struct device_node *node); ··· 907 890 908 891 int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); 909 892 bool of_pci_supply_present(struct device_node *np); 910 - 893 + int of_pci_get_equalization_presets(struct device *dev, 894 + struct pci_eq_presets *presets, 895 + int num_lanes); 911 896 #else 912 897 static inline int 913 898 of_get_pci_domain_nr(struct device_node *node) ··· 953 934 static inline bool of_pci_supply_present(struct device_node *np) 954 935 { 955 936 return false; 937 + } 938 + 939 + static inline int of_pci_get_equalization_presets(struct device *dev, 940 + struct pci_eq_presets *presets, 941 + int num_lanes) 942 + { 943 + presets->eq_presets_8gts[0] = PCI_EQ_RESV; 944 + for (int i = 0; i < EQ_PRESET_TYPE_MAX - 1; i++) 945 + presets->eq_presets_Ngts[i][0] = PCI_EQ_RESV; 946 + 947 + return 0; 956 948 } 957 949 #endif /* CONFIG_OF */ 958 950