1414#include <linux/delay.h>
1515#include <linux/gpio.h>
1616#include <linux/gpio/consumer.h>
17+ #include <linux/interconnect.h>
1718#include <linux/interrupt.h>
1819#include <linux/iopoll.h>
1920#include <linux/kernel.h>
223224#define EP_STATE_ENABLED 1
224225
225226static const unsigned int pcie_gen_freq [] = {
227+ GEN1_CORE_CLK_FREQ , /* PCI_EXP_LNKSTA_CLS == 0; undefined */
226228 GEN1_CORE_CLK_FREQ ,
227229 GEN2_CORE_CLK_FREQ ,
228230 GEN3_CORE_CLK_FREQ ,
@@ -287,6 +289,7 @@ struct tegra_pcie_dw {
287289 unsigned int pex_rst_irq ;
288290 int ep_state ;
289291 long link_status ;
292+ struct icc_path * icc_path ;
290293};
291294
292295static inline struct tegra_pcie_dw * to_tegra_pcie (struct dw_pcie * pci )
@@ -309,6 +312,27 @@ struct tegra_pcie_soc {
309312 enum dw_pcie_device_mode mode ;
310313};
311314
315+ static void tegra_pcie_icc_set (struct tegra_pcie_dw * pcie )
316+ {
317+ struct dw_pcie * pci = & pcie -> pci ;
318+ u32 val , speed , width ;
319+
320+ val = dw_pcie_readw_dbi (pci , pcie -> pcie_cap_base + PCI_EXP_LNKSTA );
321+
322+ speed = FIELD_GET (PCI_EXP_LNKSTA_CLS , val );
323+ width = FIELD_GET (PCI_EXP_LNKSTA_NLW , val );
324+
325+ val = width * (PCIE_SPEED2MBS_ENC (pcie_link_speed [speed ]) / BITS_PER_BYTE );
326+
327+ if (icc_set_bw (pcie -> icc_path , MBps_to_icc (val ), 0 ))
328+ dev_err (pcie -> dev , "can't set bw[%u]\n" , val );
329+
330+ if (speed >= ARRAY_SIZE (pcie_gen_freq ))
331+ speed = 0 ;
332+
333+ clk_set_rate (pcie -> core_clk , pcie_gen_freq [speed ]);
334+ }
335+
312336static void apply_bad_link_workaround (struct dw_pcie_rp * pp )
313337{
314338 struct dw_pcie * pci = to_dw_pcie_from_pp (pp );
@@ -452,14 +476,12 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
452476 struct tegra_pcie_dw * pcie = arg ;
453477 struct dw_pcie_ep * ep = & pcie -> pci .ep ;
454478 struct dw_pcie * pci = & pcie -> pci ;
455- u32 val , speed ;
479+ u32 val ;
456480
457481 if (test_and_clear_bit (0 , & pcie -> link_status ))
458482 dw_pcie_ep_linkup (ep );
459483
460- speed = dw_pcie_readw_dbi (pci , pcie -> pcie_cap_base + PCI_EXP_LNKSTA ) &
461- PCI_EXP_LNKSTA_CLS ;
462- clk_set_rate (pcie -> core_clk , pcie_gen_freq [speed - 1 ]);
484+ tegra_pcie_icc_set (pcie );
463485
464486 if (pcie -> of_data -> has_ltr_req_fix )
465487 return IRQ_HANDLED ;
@@ -945,9 +967,9 @@ static int tegra_pcie_dw_host_init(struct dw_pcie_rp *pp)
945967
946968static int tegra_pcie_dw_start_link (struct dw_pcie * pci )
947969{
948- u32 val , offset , speed , tmp ;
949970 struct tegra_pcie_dw * pcie = to_tegra_pcie (pci );
950971 struct dw_pcie_rp * pp = & pci -> pp ;
972+ u32 val , offset , tmp ;
951973 bool retry = true;
952974
953975 if (pcie -> of_data -> mode == DW_PCIE_EP_TYPE ) {
@@ -1018,9 +1040,7 @@ static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
10181040 goto retry_link ;
10191041 }
10201042
1021- speed = dw_pcie_readw_dbi (pci , pcie -> pcie_cap_base + PCI_EXP_LNKSTA ) &
1022- PCI_EXP_LNKSTA_CLS ;
1023- clk_set_rate (pcie -> core_clk , pcie_gen_freq [speed - 1 ]);
1043+ tegra_pcie_icc_set (pcie );
10241044
10251045 tegra_pcie_enable_interrupts (pp );
10261046
@@ -2224,6 +2244,14 @@ static int tegra_pcie_dw_probe(struct platform_device *pdev)
22242244
22252245 platform_set_drvdata (pdev , pcie );
22262246
2247+ pcie -> icc_path = devm_of_icc_get (& pdev -> dev , "write" );
2248+ ret = PTR_ERR_OR_ZERO (pcie -> icc_path );
2249+ if (ret ) {
2250+ tegra_bpmp_put (pcie -> bpmp );
2251+ dev_err_probe (& pdev -> dev , ret , "failed to get write interconnect\n" );
2252+ return ret ;
2253+ }
2254+
22272255 switch (pcie -> of_data -> mode ) {
22282256 case DW_PCIE_RC_TYPE :
22292257 ret = devm_request_irq (dev , pp -> irq , tegra_pcie_rp_irq_handler ,
0 commit comments