Skip to content

Commit 5f2c4de

Browse files
John MadieuMani-Sadhasivam
authored andcommitted
PCI: rzg3s-host: Add SoC-specific configuration and initialization callbacks
Add optional cfg_pre_init, cfg_post_init, and cfg_deinit callbacks to handle SoC-specific configuration methods. While RZ/G3S uses the Linux reset framework with dedicated reset lines, other SoC variants like RZ/G3E control configuration resets through PCIe AXI registers. As Linux reset bulk API gracefully handles optional NULL reset lines (num_cfg_resets = 0 for RZ/G3E), the driver continues to use the standard reset framework when reset lines are available, while custom callbacks are only invoked when provided. This provides a balanced pattern where: - RZ/G3S: Uses callbacks that fall back to the reset framework - RZ/G3E: Sets num_cfg_resets=0, provides cfg_pre_init/cfg_post_init/cfg_deinit Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> # RZ/V2N EVK Tested-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Reviewed-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Link: https://patch.msgid.link/20260306143423.19562-10-john.madieu.xa@bp.renesas.com
1 parent 4ec4ccd commit 5f2c4de

1 file changed

Lines changed: 44 additions & 17 deletions

File tree

drivers/pci/controller/pcie-rzg3s-host.c

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ struct rzg3s_pcie_host;
233233
/**
234234
* struct rzg3s_pcie_soc_data - SoC specific data
235235
* @init_phy: PHY initialization function
236+
* @config_pre_init: Optional callback for SoC-specific pre-configuration
237+
* @config_post_init: Callback for SoC-specific post-configuration
238+
* @config_deinit: Callback for SoC-specific de-initialization
236239
* @power_resets: array with the resets that need to be de-asserted after
237240
* power-on
238241
* @cfg_resets: array with the resets that need to be de-asserted after
@@ -243,6 +246,9 @@ struct rzg3s_pcie_host;
243246
*/
244247
struct rzg3s_pcie_soc_data {
245248
int (*init_phy)(struct rzg3s_pcie_host *host);
249+
void (*config_pre_init)(struct rzg3s_pcie_host *host);
250+
int (*config_post_init)(struct rzg3s_pcie_host *host);
251+
int (*config_deinit)(struct rzg3s_pcie_host *host);
246252
const char * const *power_resets;
247253
const char * const *cfg_resets;
248254
struct rzg3s_sysc_info sysc_info;
@@ -1109,6 +1115,18 @@ static int rzg3s_pcie_config_init(struct rzg3s_pcie_host *host)
11091115
return 0;
11101116
}
11111117

1118+
static int rzg3s_pcie_config_post_init(struct rzg3s_pcie_host *host)
1119+
{
1120+
return reset_control_bulk_deassert(host->data->num_cfg_resets,
1121+
host->cfg_resets);
1122+
}
1123+
1124+
static int rzg3s_pcie_config_deinit(struct rzg3s_pcie_host *host)
1125+
{
1126+
return reset_control_bulk_assert(host->data->num_cfg_resets,
1127+
host->cfg_resets);
1128+
}
1129+
11121130
static void rzg3s_pcie_irq_init(struct rzg3s_pcie_host *host)
11131131
{
11141132
/*
@@ -1257,22 +1275,26 @@ static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
12571275
u32 val;
12581276
int ret;
12591277

1278+
/* SoC-specific pre-configuration */
1279+
if (host->data->config_pre_init)
1280+
host->data->config_pre_init(host);
1281+
12601282
/* Initialize the PCIe related registers */
12611283
ret = rzg3s_pcie_config_init(host);
12621284
if (ret)
1263-
return ret;
1285+
goto config_deinit;
12641286

12651287
ret = rzg3s_pcie_host_init_port(host);
12661288
if (ret)
1267-
return ret;
1289+
goto config_deinit;
12681290

12691291
/* Initialize the interrupts */
12701292
rzg3s_pcie_irq_init(host);
12711293

1272-
ret = reset_control_bulk_deassert(host->data->num_cfg_resets,
1273-
host->cfg_resets);
1294+
/* SoC-specific post-configuration */
1295+
ret = host->data->config_post_init(host);
12741296
if (ret)
1275-
goto disable_port_refclk;
1297+
goto config_deinit_and_refclk;
12761298

12771299
/* Wait for link up */
12781300
ret = readl_poll_timeout(host->axi + RZG3S_PCI_PCSTAT1, val,
@@ -1281,18 +1303,20 @@ static int rzg3s_pcie_host_init(struct rzg3s_pcie_host *host)
12811303
PCIE_LINK_WAIT_SLEEP_MS * MILLI *
12821304
PCIE_LINK_WAIT_MAX_RETRIES);
12831305
if (ret)
1284-
goto cfg_resets_deassert;
1306+
goto config_deinit_post;
12851307

12861308
val = readl_relaxed(host->axi + RZG3S_PCI_PCSTAT2);
12871309
dev_info(host->dev, "PCIe link status [0x%x]\n", val);
12881310

12891311
return 0;
12901312

1291-
cfg_resets_deassert:
1292-
reset_control_bulk_assert(host->data->num_cfg_resets,
1293-
host->cfg_resets);
1294-
disable_port_refclk:
1313+
config_deinit_post:
1314+
host->data->config_deinit(host);
1315+
config_deinit_and_refclk:
12951316
clk_disable_unprepare(host->port.refclk);
1317+
config_deinit:
1318+
if (host->data->config_pre_init)
1319+
host->data->config_deinit(host);
12961320
return ret;
12971321
}
12981322

@@ -1653,7 +1677,7 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
16531677

16541678
host_probe_teardown:
16551679
rzg3s_pcie_teardown_irqdomain(host);
1656-
reset_control_bulk_assert(host->data->num_cfg_resets, host->cfg_resets);
1680+
host->data->config_deinit(host);
16571681
rpm_put:
16581682
pm_runtime_put_sync(dev);
16591683
rpm_disable:
@@ -1686,15 +1710,15 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
16861710

16871711
clk_disable_unprepare(port->refclk);
16881712

1689-
ret = reset_control_bulk_assert(data->num_cfg_resets,
1690-
host->cfg_resets);
1713+
/* SoC-specific de-initialization */
1714+
ret = data->config_deinit(host);
16911715
if (ret)
16921716
goto refclk_restore;
16931717

16941718
ret = reset_control_bulk_assert(data->num_power_resets,
16951719
host->power_resets);
16961720
if (ret)
1697-
goto cfg_resets_restore;
1721+
goto config_reinit;
16981722

16991723
ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
17001724
if (ret)
@@ -1706,9 +1730,10 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
17061730
power_resets_restore:
17071731
reset_control_bulk_deassert(data->num_power_resets,
17081732
host->power_resets);
1709-
cfg_resets_restore:
1710-
reset_control_bulk_deassert(data->num_cfg_resets,
1711-
host->cfg_resets);
1733+
config_reinit:
1734+
if (data->config_pre_init)
1735+
data->config_pre_init(host);
1736+
data->config_post_init(host);
17121737
refclk_restore:
17131738
clk_prepare_enable(port->refclk);
17141739
pm_runtime_resume_and_get(dev);
@@ -1773,6 +1798,8 @@ static const struct rzg3s_pcie_soc_data rzg3s_soc_data = {
17731798
.num_power_resets = ARRAY_SIZE(rzg3s_soc_power_resets),
17741799
.cfg_resets = rzg3s_soc_cfg_resets,
17751800
.num_cfg_resets = ARRAY_SIZE(rzg3s_soc_cfg_resets),
1801+
.config_post_init = rzg3s_pcie_config_post_init,
1802+
.config_deinit = rzg3s_pcie_config_deinit,
17761803
.init_phy = rzg3s_soc_pcie_init_phy,
17771804
.sysc_info = {
17781805
.functions = {

0 commit comments

Comments
 (0)