Skip to content

Commit 3593709

Browse files
shawn1221Lorenzo Pieralisi
authored andcommitted
PCI: rockchip: Split out common function to init controller
Most of the initialization are used for both of RC driver and EP driver; factor the initialization out to a new function, rockchip_pcie_init_port(), in pcie-rockchip.c and rename the original function to rockchip_pcie_host_init_port() to avoid confusion. No functional changed intended. Signed-off-by: Shawn Lin <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Tested-by: Jeffy Chen <[email protected]>
1 parent 964bac9 commit 3593709

File tree

3 files changed

+152
-125
lines changed

3 files changed

+152
-125
lines changed

drivers/pci/host/pcie-rockchip-host.c

Lines changed: 7 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -293,137 +293,20 @@ static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
293293
}
294294

295295
/**
296-
* rockchip_pcie_init_port - Initialize hardware
296+
* rockchip_pcie_host_init_port - Initialize hardware
297297
* @rockchip: PCIe port information
298298
*/
299-
static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
299+
static int rockchip_pcie_host_init_port(struct rockchip_pcie *rockchip)
300300
{
301301
struct device *dev = rockchip->dev;
302-
int err, i;
302+
int err, i = MAX_LANE_NUM;
303303
u32 status;
304304

305305
gpiod_set_value_cansleep(rockchip->ep_gpio, 0);
306306

307-
err = reset_control_assert(rockchip->aclk_rst);
308-
if (err) {
309-
dev_err(dev, "assert aclk_rst err %d\n", err);
310-
return err;
311-
}
312-
313-
err = reset_control_assert(rockchip->pclk_rst);
314-
if (err) {
315-
dev_err(dev, "assert pclk_rst err %d\n", err);
316-
return err;
317-
}
318-
319-
err = reset_control_assert(rockchip->pm_rst);
320-
if (err) {
321-
dev_err(dev, "assert pm_rst err %d\n", err);
307+
err = rockchip_pcie_init_port(rockchip);
308+
if (err)
322309
return err;
323-
}
324-
325-
for (i = 0; i < MAX_LANE_NUM; i++) {
326-
err = phy_init(rockchip->phys[i]);
327-
if (err) {
328-
dev_err(dev, "init phy%d err %d\n", i, err);
329-
goto err_exit_phy;
330-
}
331-
}
332-
333-
err = reset_control_assert(rockchip->core_rst);
334-
if (err) {
335-
dev_err(dev, "assert core_rst err %d\n", err);
336-
goto err_exit_phy;
337-
}
338-
339-
err = reset_control_assert(rockchip->mgmt_rst);
340-
if (err) {
341-
dev_err(dev, "assert mgmt_rst err %d\n", err);
342-
goto err_exit_phy;
343-
}
344-
345-
err = reset_control_assert(rockchip->mgmt_sticky_rst);
346-
if (err) {
347-
dev_err(dev, "assert mgmt_sticky_rst err %d\n", err);
348-
goto err_exit_phy;
349-
}
350-
351-
err = reset_control_assert(rockchip->pipe_rst);
352-
if (err) {
353-
dev_err(dev, "assert pipe_rst err %d\n", err);
354-
goto err_exit_phy;
355-
}
356-
357-
udelay(10);
358-
359-
err = reset_control_deassert(rockchip->pm_rst);
360-
if (err) {
361-
dev_err(dev, "deassert pm_rst err %d\n", err);
362-
goto err_exit_phy;
363-
}
364-
365-
err = reset_control_deassert(rockchip->aclk_rst);
366-
if (err) {
367-
dev_err(dev, "deassert aclk_rst err %d\n", err);
368-
goto err_exit_phy;
369-
}
370-
371-
err = reset_control_deassert(rockchip->pclk_rst);
372-
if (err) {
373-
dev_err(dev, "deassert pclk_rst err %d\n", err);
374-
goto err_exit_phy;
375-
}
376-
377-
if (rockchip->link_gen == 2)
378-
rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_2,
379-
PCIE_CLIENT_CONFIG);
380-
else
381-
rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_1,
382-
PCIE_CLIENT_CONFIG);
383-
384-
rockchip_pcie_write(rockchip,
385-
PCIE_CLIENT_CONF_ENABLE |
386-
PCIE_CLIENT_LINK_TRAIN_ENABLE |
387-
PCIE_CLIENT_ARI_ENABLE |
388-
PCIE_CLIENT_CONF_LANE_NUM(rockchip->lanes) |
389-
PCIE_CLIENT_MODE_RC,
390-
PCIE_CLIENT_CONFIG);
391-
392-
for (i = 0; i < MAX_LANE_NUM; i++) {
393-
err = phy_power_on(rockchip->phys[i]);
394-
if (err) {
395-
dev_err(dev, "power on phy%d err %d\n", i, err);
396-
goto err_power_off_phy;
397-
}
398-
}
399-
400-
/*
401-
* Please don't reorder the deassert sequence of the following
402-
* four reset pins.
403-
*/
404-
err = reset_control_deassert(rockchip->mgmt_sticky_rst);
405-
if (err) {
406-
dev_err(dev, "deassert mgmt_sticky_rst err %d\n", err);
407-
goto err_power_off_phy;
408-
}
409-
410-
err = reset_control_deassert(rockchip->core_rst);
411-
if (err) {
412-
dev_err(dev, "deassert core_rst err %d\n", err);
413-
goto err_power_off_phy;
414-
}
415-
416-
err = reset_control_deassert(rockchip->mgmt_rst);
417-
if (err) {
418-
dev_err(dev, "deassert mgmt_rst err %d\n", err);
419-
goto err_power_off_phy;
420-
}
421-
422-
err = reset_control_deassert(rockchip->pipe_rst);
423-
if (err) {
424-
dev_err(dev, "deassert pipe_rst err %d\n", err);
425-
goto err_power_off_phy;
426-
}
427310

428311
/* Fix the transmitted FTS count desired to exit from L0s. */
429312
status = rockchip_pcie_read(rockchip, PCIE_CORE_CTRL_PLC1);
@@ -517,7 +400,6 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
517400
while (i--)
518401
phy_power_off(rockchip->phys[i]);
519402
i = MAX_LANE_NUM;
520-
err_exit_phy:
521403
while (i--)
522404
phy_exit(rockchip->phys[i]);
523405
return err;
@@ -1036,7 +918,7 @@ static int __maybe_unused rockchip_pcie_resume_noirq(struct device *dev)
1036918
if (err)
1037919
goto err_disable_0v9;
1038920

1039-
err = rockchip_pcie_init_port(rockchip);
921+
err = rockchip_pcie_host_init_port(rockchip);
1040922
if (err)
1041923
goto err_pcie_resume;
1042924

@@ -1101,7 +983,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
1101983
goto err_set_vpcie;
1102984
}
1103985

1104-
err = rockchip_pcie_init_port(rockchip);
986+
err = rockchip_pcie_host_init_port(rockchip);
1105987
if (err)
1106988
goto err_vpcie;
1107989

drivers/pci/host/pcie-rockchip.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include <linux/clk.h>
15+
#include <linux/delay.h>
1516
#include <linux/gpio/consumer.h>
1617
#include <linux/of_pci.h>
1718
#include <linux/phy/phy.h>
@@ -145,6 +146,147 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
145146
}
146147
EXPORT_SYMBOL_GPL(rockchip_pcie_parse_dt);
147148

149+
int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
150+
{
151+
struct device *dev = rockchip->dev;
152+
int err, i;
153+
u32 regs;
154+
155+
err = reset_control_assert(rockchip->aclk_rst);
156+
if (err) {
157+
dev_err(dev, "assert aclk_rst err %d\n", err);
158+
return err;
159+
}
160+
161+
err = reset_control_assert(rockchip->pclk_rst);
162+
if (err) {
163+
dev_err(dev, "assert pclk_rst err %d\n", err);
164+
return err;
165+
}
166+
167+
err = reset_control_assert(rockchip->pm_rst);
168+
if (err) {
169+
dev_err(dev, "assert pm_rst err %d\n", err);
170+
return err;
171+
}
172+
173+
for (i = 0; i < MAX_LANE_NUM; i++) {
174+
err = phy_init(rockchip->phys[i]);
175+
if (err) {
176+
dev_err(dev, "init phy%d err %d\n", i, err);
177+
goto err_exit_phy;
178+
}
179+
}
180+
181+
err = reset_control_assert(rockchip->core_rst);
182+
if (err) {
183+
dev_err(dev, "assert core_rst err %d\n", err);
184+
goto err_exit_phy;
185+
}
186+
187+
err = reset_control_assert(rockchip->mgmt_rst);
188+
if (err) {
189+
dev_err(dev, "assert mgmt_rst err %d\n", err);
190+
goto err_exit_phy;
191+
}
192+
193+
err = reset_control_assert(rockchip->mgmt_sticky_rst);
194+
if (err) {
195+
dev_err(dev, "assert mgmt_sticky_rst err %d\n", err);
196+
goto err_exit_phy;
197+
}
198+
199+
err = reset_control_assert(rockchip->pipe_rst);
200+
if (err) {
201+
dev_err(dev, "assert pipe_rst err %d\n", err);
202+
goto err_exit_phy;
203+
}
204+
205+
udelay(10);
206+
207+
err = reset_control_deassert(rockchip->pm_rst);
208+
if (err) {
209+
dev_err(dev, "deassert pm_rst err %d\n", err);
210+
goto err_exit_phy;
211+
}
212+
213+
err = reset_control_deassert(rockchip->aclk_rst);
214+
if (err) {
215+
dev_err(dev, "deassert aclk_rst err %d\n", err);
216+
goto err_exit_phy;
217+
}
218+
219+
err = reset_control_deassert(rockchip->pclk_rst);
220+
if (err) {
221+
dev_err(dev, "deassert pclk_rst err %d\n", err);
222+
goto err_exit_phy;
223+
}
224+
225+
if (rockchip->link_gen == 2)
226+
rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_2,
227+
PCIE_CLIENT_CONFIG);
228+
else
229+
rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_1,
230+
PCIE_CLIENT_CONFIG);
231+
232+
regs = PCIE_CLIENT_LINK_TRAIN_ENABLE | PCIE_CLIENT_ARI_ENABLE |
233+
PCIE_CLIENT_CONF_LANE_NUM(rockchip->lanes);
234+
235+
if (rockchip->is_rc)
236+
regs |= PCIE_CLIENT_CONF_ENABLE | PCIE_CLIENT_MODE_RC;
237+
else
238+
regs |= PCIE_CLIENT_CONF_DISABLE | PCIE_CLIENT_MODE_EP;
239+
240+
rockchip_pcie_write(rockchip, regs, PCIE_CLIENT_CONFIG);
241+
242+
for (i = 0; i < MAX_LANE_NUM; i++) {
243+
err = phy_power_on(rockchip->phys[i]);
244+
if (err) {
245+
dev_err(dev, "power on phy%d err %d\n", i, err);
246+
goto err_power_off_phy;
247+
}
248+
}
249+
250+
/*
251+
* Please don't reorder the deassert sequence of the following
252+
* four reset pins.
253+
*/
254+
err = reset_control_deassert(rockchip->mgmt_sticky_rst);
255+
if (err) {
256+
dev_err(dev, "deassert mgmt_sticky_rst err %d\n", err);
257+
goto err_power_off_phy;
258+
}
259+
260+
err = reset_control_deassert(rockchip->core_rst);
261+
if (err) {
262+
dev_err(dev, "deassert core_rst err %d\n", err);
263+
goto err_power_off_phy;
264+
}
265+
266+
err = reset_control_deassert(rockchip->mgmt_rst);
267+
if (err) {
268+
dev_err(dev, "deassert mgmt_rst err %d\n", err);
269+
goto err_power_off_phy;
270+
}
271+
272+
err = reset_control_deassert(rockchip->pipe_rst);
273+
if (err) {
274+
dev_err(dev, "deassert pipe_rst err %d\n", err);
275+
goto err_power_off_phy;
276+
}
277+
278+
return 0;
279+
err_power_off_phy:
280+
while (i--)
281+
phy_power_off(rockchip->phys[i]);
282+
i = MAX_LANE_NUM;
283+
err_exit_phy:
284+
while (i--)
285+
phy_exit(rockchip->phys[i]);
286+
return err;
287+
}
288+
EXPORT_SYMBOL_GPL(rockchip_pcie_init_port);
289+
148290
int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip)
149291
{
150292
struct device *dev = rockchip->dev;

drivers/pci/host/pcie-rockchip.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#define PCIE_CLIENT_BASE 0x0
2828
#define PCIE_CLIENT_CONFIG (PCIE_CLIENT_BASE + 0x00)
2929
#define PCIE_CLIENT_CONF_ENABLE HIWORD_UPDATE_BIT(0x0001)
30+
#define PCIE_CLIENT_CONF_DISABLE HIWORD_UPDATE(0x0001, 0)
3031
#define PCIE_CLIENT_LINK_TRAIN_ENABLE HIWORD_UPDATE_BIT(0x0002)
3132
#define PCIE_CLIENT_ARI_ENABLE HIWORD_UPDATE_BIT(0x0008)
3233
#define PCIE_CLIENT_CONF_LANE_NUM(x) HIWORD_UPDATE(0x0030, ENCODE_LANES(x))
3334
#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040)
35+
#define PCIE_CLIENT_MODE_EP HIWORD_UPDATE(0x0040, 0)
3436
#define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0)
3537
#define PCIE_CLIENT_GEN_SEL_2 HIWORD_UPDATE_BIT(0x0080)
3638
#define PCIE_CLIENT_DEBUG_OUT_0 (PCIE_CLIENT_BASE + 0x3c)
@@ -237,6 +239,7 @@ static void rockchip_pcie_write(struct rockchip_pcie *rockchip, u32 val,
237239
}
238240

239241
int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip);
242+
int rockchip_pcie_init_port(struct rockchip_pcie *rockchip);
240243
int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip);
241244
void rockchip_pcie_deinit_phys(struct rockchip_pcie *rockchip);
242245
int rockchip_pcie_enable_clocks(struct rockchip_pcie *rockchip);

0 commit comments

Comments
 (0)