2 * Broadcom specific AMBA
5 * Copyright 2014, Broadcom Corporation
6 * Copyright 2014, Rafał Miłecki <zajec5@gmail.com>
8 * Licensed under the GNU/GPL. See COPYING for details.
11 #include "bcma_private.h"
12 #include <linux/bcma/bcma.h>
13 #include <linux/pci.h>
15 /**************************************************
17 **************************************************/
20 static u32
bcma_core_pcie2_cfg_read(struct bcma_drv_pcie2
*pcie2
, u32 addr
)
22 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, addr
);
23 pcie2_read32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
);
24 return pcie2_read32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
);
28 static void bcma_core_pcie2_cfg_write(struct bcma_drv_pcie2
*pcie2
, u32 addr
,
31 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, addr
);
32 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, val
);
35 /**************************************************
37 **************************************************/
39 static u32
bcma_core_pcie2_war_delay_perst_enab(struct bcma_drv_pcie2
*pcie2
,
44 /* restore back to default */
45 val
= pcie2_read32(pcie2
, BCMA_CORE_PCIE2_CLK_CONTROL
);
46 val
|= PCIE2_CLKC_DLYPERST
;
47 val
&= ~PCIE2_CLKC_DISSPROMLD
;
49 val
&= ~PCIE2_CLKC_DLYPERST
;
50 val
|= PCIE2_CLKC_DISSPROMLD
;
52 pcie2_write32(pcie2
, (BCMA_CORE_PCIE2_CLK_CONTROL
), val
);
54 return pcie2_read32(pcie2
, BCMA_CORE_PCIE2_CLK_CONTROL
);
57 static void bcma_core_pcie2_set_ltr_vals(struct bcma_drv_pcie2
*pcie2
)
60 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, 0x844);
61 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, 0x883c883c);
63 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, 0x848);
64 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, 0x88648864);
66 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, 0x84C);
67 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, 0x90039003);
70 static void bcma_core_pcie2_hw_ltr_war(struct bcma_drv_pcie2
*pcie2
)
72 u8 core_rev
= pcie2
->core
->id
.rev
;
75 if (core_rev
< 2 || core_rev
== 10 || core_rev
> 13)
78 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
,
79 PCIE2_CAP_DEVSTSCTRL2_OFFSET
);
80 devstsctr2
= pcie2_read32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
);
81 if (devstsctr2
& PCIE2_CAP_DEVSTSCTRL2_LTRENAB
) {
82 /* force the right LTR values */
83 bcma_core_pcie2_set_ltr_vals(pcie2
);
86 *si_core_wrapperreg(pcie2, 3, 0x60, 0x8080, 0);
90 devstsctr2
|= PCIE2_CAP_DEVSTSCTRL2_LTRENAB
;
91 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
,
92 PCIE2_CAP_DEVSTSCTRL2_OFFSET
);
93 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, devstsctr2
);
95 /* set the LTR state to be active */
96 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_LTR_STATE
,
98 usleep_range(1000, 2000);
100 /* set the LTR state to be sleep */
101 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_LTR_STATE
,
103 usleep_range(1000, 2000);
107 static void pciedev_crwlpciegen2(struct bcma_drv_pcie2
*pcie2
)
109 u8 core_rev
= pcie2
->core
->id
.rev
;
110 bool pciewar160
, pciewar162
;
112 pciewar160
= core_rev
== 7 || core_rev
== 9 || core_rev
== 11;
113 pciewar162
= core_rev
== 5 || core_rev
== 7 || core_rev
== 8 ||
114 core_rev
== 9 || core_rev
== 11;
116 if (!pciewar160
&& !pciewar162
)
121 pcie2_set32(pcie2
, BCMA_CORE_PCIE2_CLK_CONTROL
,
122 PCIE_DISABLE_L1CLK_GATING
);
124 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
,
125 PCIEGEN2_COE_PVT_TL_CTRL_0
);
126 pcie2_mask32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
,
127 ~(1 << COE_PVT_TL_CTRL_0_PM_DIS_L1_REENTRY_BIT
));
132 static void pciedev_crwlpciegen2_180(struct bcma_drv_pcie2
*pcie2
)
134 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, PCIE2_PMCR_REFUP
);
135 pcie2_set32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, 0x1f);
138 static void pciedev_crwlpciegen2_182(struct bcma_drv_pcie2
*pcie2
)
140 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
, PCIE2_SBMBX
);
141 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, 1 << 0);
144 static void pciedev_reg_pm_clk_period(struct bcma_drv_pcie2
*pcie2
)
146 struct bcma_drv_cc
*drv_cc
= &pcie2
->core
->bus
->drv_cc
;
147 u8 core_rev
= pcie2
->core
->id
.rev
;
148 u32 alp_khz
, pm_value
;
150 if (core_rev
<= 13) {
151 alp_khz
= bcma_pmu_get_alp_clock(drv_cc
) / 1000;
152 pm_value
= (1000000 * 2) / alp_khz
;
153 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDADDR
,
154 PCIE2_PVT_REG_PM_CLK_PERIOD
);
155 pcie2_write32(pcie2
, BCMA_CORE_PCIE2_CONFIGINDDATA
, pm_value
);
159 void bcma_core_pcie2_init(struct bcma_drv_pcie2
*pcie2
)
161 struct bcma_bus
*bus
= pcie2
->core
->bus
;
162 struct bcma_chipinfo
*ci
= &bus
->chipinfo
;
165 tmp
= pcie2_read32(pcie2
, BCMA_CORE_PCIE2_SPROM(54));
166 if ((tmp
& 0xe) >> 1 == 2)
167 bcma_core_pcie2_cfg_write(pcie2
, 0x4e0, 0x17);
169 switch (bus
->chipinfo
.id
) {
170 case BCMA_CHIP_ID_BCM4360
:
171 case BCMA_CHIP_ID_BCM4352
:
172 pcie2
->reqsize
= 1024;
175 pcie2
->reqsize
= 128;
179 if (ci
->id
== BCMA_CHIP_ID_BCM4360
&& ci
->rev
> 3)
180 bcma_core_pcie2_war_delay_perst_enab(pcie2
, true);
181 bcma_core_pcie2_hw_ltr_war(pcie2
);
182 pciedev_crwlpciegen2(pcie2
);
183 pciedev_reg_pm_clk_period(pcie2
);
184 pciedev_crwlpciegen2_180(pcie2
);
185 pciedev_crwlpciegen2_182(pcie2
);
188 /**************************************************
190 **************************************************/
192 void bcma_core_pcie2_up(struct bcma_drv_pcie2
*pcie2
)
194 struct bcma_bus
*bus
= pcie2
->core
->bus
;
195 struct pci_dev
*dev
= bus
->host_pci
;
198 err
= pcie_set_readrq(dev
, pcie2
->reqsize
);
200 bcma_err(bus
, "Error setting PCI_EXP_DEVCTL_READRQ: %d\n", err
);