Skip to content

Commit 346dd34

Browse files
John MadieuMani-Sadhasivam
authored andcommitted
PCI: rzg3s-host: Make SYSC register offsets SoC-specific
In preparation for adding RZ/G3E support, move the RST_RSM_B register offset and mask into a SoC-specific data structure. Compared with RZ/G3S, the RZ/G3E SYSC controls different functionalities for the PCIe controller. Make SYSC operations conditional on the presence of register offset information, allowing the driver to handle SoCs that don't use the RST_RSM_B signal. 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-8-john.madieu.xa@bp.renesas.com
1 parent fabce18 commit 346dd34

1 file changed

Lines changed: 85 additions & 26 deletions

File tree

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

Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@
159159

160160
#define RZG3S_PCI_CFG_PCIEC 0x60
161161

162-
/* System controller registers */
163-
#define RZG3S_SYS_PCIE_RST_RSM_B 0xd74
164-
#define RZG3S_SYS_PCIE_RST_RSM_B_MASK BIT(0)
165-
166162
/* Maximum number of windows */
167163
#define RZG3S_MAX_WINDOWS 8
168164

@@ -174,6 +170,44 @@
174170
/* Timeouts experimentally determined */
175171
#define RZG3S_REQ_ISSUE_TIMEOUT_US 2500
176172

173+
/**
174+
* struct rzg3s_sysc_function - System Controller function descriptor
175+
* @offset: Register offset from the System Controller base address
176+
* @mask: Bit mask for the function within the register
177+
*/
178+
struct rzg3s_sysc_function {
179+
u32 offset;
180+
u32 mask;
181+
};
182+
183+
/**
184+
* enum rzg3s_sysc_func_id - System controller function IDs
185+
* @RZG3S_SYSC_FUNC_ID_RST_RSM_B: RST_RSM_B SYSC function ID
186+
* @RZG3S_SYSC_FUNC_ID_MAX: Max SYSC function ID
187+
*/
188+
enum rzg3s_sysc_func_id {
189+
RZG3S_SYSC_FUNC_ID_RST_RSM_B,
190+
RZG3S_SYSC_FUNC_ID_MAX,
191+
};
192+
193+
/**
194+
* struct rzg3s_sysc_info - RZ/G3S System Controller info
195+
* @functions: SYSC function descriptors array
196+
*/
197+
struct rzg3s_sysc_info {
198+
const struct rzg3s_sysc_function functions[RZG3S_SYSC_FUNC_ID_MAX];
199+
};
200+
201+
/**
202+
* struct rzg3s_sysc - RZ/G3S System Controller descriptor
203+
* @regmap: System controller regmap
204+
* @info: System controller info
205+
*/
206+
struct rzg3s_sysc {
207+
struct regmap *regmap;
208+
const struct rzg3s_sysc_info *info;
209+
};
210+
177211
/**
178212
* struct rzg3s_pcie_msi - RZ/G3S PCIe MSI data structure
179213
* @domain: IRQ domain
@@ -203,13 +237,15 @@ struct rzg3s_pcie_host;
203237
* power-on
204238
* @cfg_resets: array with the resets that need to be de-asserted after
205239
* configuration
240+
* @sysc_info: SYSC info
206241
* @num_power_resets: number of power resets
207242
* @num_cfg_resets: number of configuration resets
208243
*/
209244
struct rzg3s_pcie_soc_data {
210245
int (*init_phy)(struct rzg3s_pcie_host *host);
211246
const char * const *power_resets;
212247
const char * const *cfg_resets;
248+
struct rzg3s_sysc_info sysc_info;
213249
u8 num_power_resets;
214250
u8 num_cfg_resets;
215251
};
@@ -233,7 +269,7 @@ struct rzg3s_pcie_port {
233269
* @dev: struct device
234270
* @power_resets: reset control signals that should be set after power up
235271
* @cfg_resets: reset control signals that should be set after configuration
236-
* @sysc: SYSC regmap
272+
* @sysc: SYSC descriptor
237273
* @intx_domain: INTx IRQ domain
238274
* @data: SoC specific data
239275
* @msi: MSI data structure
@@ -248,7 +284,7 @@ struct rzg3s_pcie_host {
248284
struct device *dev;
249285
struct reset_control_bulk_data *power_resets;
250286
struct reset_control_bulk_data *cfg_resets;
251-
struct regmap *sysc;
287+
struct rzg3s_sysc *sysc;
252288
struct irq_domain *intx_domain;
253289
const struct rzg3s_pcie_soc_data *data;
254290
struct rzg3s_pcie_msi msi;
@@ -260,6 +296,23 @@ struct rzg3s_pcie_host {
260296

261297
#define rzg3s_msi_to_host(_msi) container_of(_msi, struct rzg3s_pcie_host, msi)
262298

299+
static int rzg3s_sysc_config_func(struct rzg3s_sysc *sysc,
300+
enum rzg3s_sysc_func_id fid, u32 val)
301+
{
302+
const struct rzg3s_sysc_info *info = sysc->info;
303+
const struct rzg3s_sysc_function *functions = info->functions;
304+
305+
if (fid >= RZG3S_SYSC_FUNC_ID_MAX)
306+
return -EINVAL;
307+
308+
if (!functions[fid].mask)
309+
return 0;
310+
311+
return regmap_update_bits(sysc->regmap, functions[fid].offset,
312+
functions[fid].mask,
313+
field_prep(functions[fid].mask, val));
314+
}
315+
263316
static void rzg3s_pcie_update_bits(void __iomem *base, u32 offset, u32 mask,
264317
u32 val)
265318
{
@@ -1522,6 +1575,7 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
15221575
struct device_node *sysc_np __free(device_node) =
15231576
of_parse_phandle(np, "renesas,sysc", 0);
15241577
struct rzg3s_pcie_host *host;
1578+
struct rzg3s_sysc *sysc;
15251579
int ret;
15261580

15271581
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*host));
@@ -1533,6 +1587,13 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
15331587
host->data = device_get_match_data(dev);
15341588
platform_set_drvdata(pdev, host);
15351589

1590+
host->sysc = devm_kzalloc(dev, sizeof(*host->sysc), GFP_KERNEL);
1591+
if (!host->sysc)
1592+
return -ENOMEM;
1593+
1594+
sysc = host->sysc;
1595+
sysc->info = &host->data->sysc_info;
1596+
15361597
host->axi = devm_platform_ioremap_resource(pdev, 0);
15371598
if (IS_ERR(host->axi))
15381599
return PTR_ERR(host->axi);
@@ -1546,15 +1607,13 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
15461607
if (ret)
15471608
return ret;
15481609

1549-
host->sysc = syscon_node_to_regmap(sysc_np);
1550-
if (IS_ERR(host->sysc)) {
1551-
ret = PTR_ERR(host->sysc);
1610+
sysc->regmap = syscon_node_to_regmap(sysc_np);
1611+
if (IS_ERR(sysc->regmap)) {
1612+
ret = PTR_ERR(sysc->regmap);
15521613
goto port_refclk_put;
15531614
}
15541615

1555-
ret = regmap_update_bits(host->sysc, RZG3S_SYS_PCIE_RST_RSM_B,
1556-
RZG3S_SYS_PCIE_RST_RSM_B_MASK,
1557-
FIELD_PREP(RZG3S_SYS_PCIE_RST_RSM_B_MASK, 1));
1616+
ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 1);
15581617
if (ret)
15591618
goto port_refclk_put;
15601619

@@ -1606,9 +1665,7 @@ static int rzg3s_pcie_probe(struct platform_device *pdev)
16061665
* SYSC RST_RSM_B signal need to be asserted before turning off the
16071666
* power to the PHY.
16081667
*/
1609-
regmap_update_bits(host->sysc, RZG3S_SYS_PCIE_RST_RSM_B,
1610-
RZG3S_SYS_PCIE_RST_RSM_B_MASK,
1611-
FIELD_PREP(RZG3S_SYS_PCIE_RST_RSM_B_MASK, 0));
1668+
rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
16121669
port_refclk_put:
16131670
clk_put(host->port.refclk);
16141671

@@ -1620,7 +1677,7 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
16201677
struct rzg3s_pcie_host *host = dev_get_drvdata(dev);
16211678
const struct rzg3s_pcie_soc_data *data = host->data;
16221679
struct rzg3s_pcie_port *port = &host->port;
1623-
struct regmap *sysc = host->sysc;
1680+
struct rzg3s_sysc *sysc = host->sysc;
16241681
int ret;
16251682

16261683
ret = pm_runtime_put_sync(dev);
@@ -1639,9 +1696,7 @@ static int rzg3s_pcie_suspend_noirq(struct device *dev)
16391696
if (ret)
16401697
goto cfg_resets_restore;
16411698

1642-
ret = regmap_update_bits(sysc, RZG3S_SYS_PCIE_RST_RSM_B,
1643-
RZG3S_SYS_PCIE_RST_RSM_B_MASK,
1644-
FIELD_PREP(RZG3S_SYS_PCIE_RST_RSM_B_MASK, 0));
1699+
ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
16451700
if (ret)
16461701
goto power_resets_restore;
16471702

@@ -1664,12 +1719,10 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
16641719
{
16651720
struct rzg3s_pcie_host *host = dev_get_drvdata(dev);
16661721
const struct rzg3s_pcie_soc_data *data = host->data;
1667-
struct regmap *sysc = host->sysc;
1722+
struct rzg3s_sysc *sysc = host->sysc;
16681723
int ret;
16691724

1670-
ret = regmap_update_bits(sysc, RZG3S_SYS_PCIE_RST_RSM_B,
1671-
RZG3S_SYS_PCIE_RST_RSM_B_MASK,
1672-
FIELD_PREP(RZG3S_SYS_PCIE_RST_RSM_B_MASK, 1));
1725+
ret = rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 1);
16731726
if (ret)
16741727
return ret;
16751728

@@ -1698,9 +1751,7 @@ static int rzg3s_pcie_resume_noirq(struct device *dev)
16981751
reset_control_bulk_assert(data->num_power_resets,
16991752
host->power_resets);
17001753
assert_rst_rsm_b:
1701-
regmap_update_bits(sysc, RZG3S_SYS_PCIE_RST_RSM_B,
1702-
RZG3S_SYS_PCIE_RST_RSM_B_MASK,
1703-
FIELD_PREP(RZG3S_SYS_PCIE_RST_RSM_B_MASK, 0));
1754+
rzg3s_sysc_config_func(sysc, RZG3S_SYSC_FUNC_ID_RST_RSM_B, 0);
17041755
return ret;
17051756
}
17061757

@@ -1723,6 +1774,14 @@ static const struct rzg3s_pcie_soc_data rzg3s_soc_data = {
17231774
.cfg_resets = rzg3s_soc_cfg_resets,
17241775
.num_cfg_resets = ARRAY_SIZE(rzg3s_soc_cfg_resets),
17251776
.init_phy = rzg3s_soc_pcie_init_phy,
1777+
.sysc_info = {
1778+
.functions = {
1779+
[RZG3S_SYSC_FUNC_ID_RST_RSM_B] = {
1780+
.offset = 0xd74,
1781+
.mask = BIT(0),
1782+
},
1783+
},
1784+
},
17261785
};
17271786

17281787
static const struct of_device_id rzg3s_pcie_of_match[] = {

0 commit comments

Comments
 (0)