11
11
* ARM PCI Host generic driver.
12
12
*/
13
13
14
+ #include <linux/bitfield.h>
14
15
#include <linux/bitrev.h>
15
16
#include <linux/clk.h>
16
17
#include <linux/delay.h>
@@ -40,18 +41,18 @@ static void rockchip_pcie_enable_bw_int(struct rockchip_pcie *rockchip)
40
41
{
41
42
u32 status ;
42
43
43
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LCS );
44
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
44
45
status |= (PCI_EXP_LNKCTL_LBMIE | PCI_EXP_LNKCTL_LABIE );
45
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LCS );
46
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
46
47
}
47
48
48
49
static void rockchip_pcie_clr_bw_int (struct rockchip_pcie * rockchip )
49
50
{
50
51
u32 status ;
51
52
52
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LCS );
53
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
53
54
status |= (PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_LABS ) << 16 ;
54
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LCS );
55
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
55
56
}
56
57
57
58
static void rockchip_pcie_update_txcredit_mui (struct rockchip_pcie * rockchip )
@@ -269,7 +270,7 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
269
270
scale = 3 ; /* 0.001x */
270
271
curr = curr / 1000 ; /* convert to mA */
271
272
power = (curr * 3300 ) / 1000 ; /* milliwatt */
272
- while (power > PCIE_RC_CONFIG_DCR_CSPL_LIMIT ) {
273
+ while (power > FIELD_MAX ( PCI_EXP_DEVCAP_PWR_VAL ) ) {
273
274
if (!scale ) {
274
275
dev_warn (rockchip -> dev , "invalid power supply\n" );
275
276
return ;
@@ -278,10 +279,10 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
278
279
power = power / 10 ;
279
280
}
280
281
281
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_DCR );
282
- status |= ( power << PCIE_RC_CONFIG_DCR_CSPL_SHIFT ) |
283
- ( scale << PCIE_RC_CONFIG_DCR_CPLS_SHIFT );
284
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_DCR );
282
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_DEVCAP );
283
+ status |= FIELD_PREP ( PCI_EXP_DEVCAP_PWR_VAL , power );
284
+ status |= FIELD_PREP ( PCI_EXP_DEVCAP_PWR_SCL , scale );
285
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_DEVCAP );
285
286
}
286
287
287
288
/**
@@ -309,14 +310,14 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
309
310
rockchip_pcie_set_power_limit (rockchip );
310
311
311
312
/* Set RC's clock architecture as common clock */
312
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LCS );
313
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
313
314
status |= PCI_EXP_LNKSTA_SLC << 16 ;
314
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LCS );
315
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
315
316
316
317
/* Set RC's RCB to 128 */
317
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LCS );
318
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
318
319
status |= PCI_EXP_LNKCTL_RCB ;
319
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LCS );
320
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
320
321
321
322
/* Enable Gen1 training */
322
323
rockchip_pcie_write (rockchip , PCIE_CLIENT_LINK_TRAIN_ENABLE ,
@@ -341,9 +342,9 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
341
342
* Enable retrain for gen2. This should be configured only after
342
343
* gen1 finished.
343
344
*/
344
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LCS );
345
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
345
346
status |= PCI_EXP_LNKCTL_RL ;
346
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LCS );
347
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCTL );
347
348
348
349
err = readl_poll_timeout (rockchip -> apb_base + PCIE_CORE_CTRL ,
349
350
status , PCIE_LINK_IS_GEN2 (status ), 20 ,
@@ -380,15 +381,15 @@ static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
380
381
381
382
/* Clear L0s from RC's link cap */
382
383
if (of_property_read_bool (dev -> of_node , "aspm-no-l0s" )) {
383
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_LINK_CAP );
384
- status &= ~PCIE_RC_CONFIG_LINK_CAP_L0S ;
385
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_LINK_CAP );
384
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCAP );
385
+ status &= ~PCI_EXP_LNKCAP_ASPM_L0S ;
386
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_LNKCAP );
386
387
}
387
388
388
- status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_DCSR );
389
- status &= ~PCIE_RC_CONFIG_DCSR_MPS_MASK ;
390
- status |= PCIE_RC_CONFIG_DCSR_MPS_256 ;
391
- rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_DCSR );
389
+ status = rockchip_pcie_read (rockchip , PCIE_RC_CONFIG_CR + PCI_EXP_DEVCTL );
390
+ status &= ~PCI_EXP_DEVCTL_PAYLOAD ;
391
+ status |= PCI_EXP_DEVCTL_PAYLOAD_256B ;
392
+ rockchip_pcie_write (rockchip , status , PCIE_RC_CONFIG_CR + PCI_EXP_DEVCTL );
392
393
393
394
return 0 ;
394
395
err_power_off_phy :
0 commit comments