Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: pcs: rzn1-miic: Add support to handle resets

Add reset-line handling to the RZN1 MIIC driver and move reset
configuration into the SoC/OF data. Introduce MIIC_MAX_NUM_RSTS (= 2),
add storage for reset_control_bulk_data in struct miic and add
reset_ids and reset_count fields to miic_of_data.

When reset_ids are present in the OF data, the driver obtains the reset
lines with devm_reset_control_bulk_get_exclusive(), deasserts them during
probe and registers a devres action to assert them on remove or on error.

This change is preparatory work to support the RZ/T2H SoC, which exposes
two reset lines for the ETHSS IP. The driver remains backward compatible
for platforms that do not provide reset lines.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://patch.msgid.link/20250910204132.319975-8-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Lad Prabhakar and committed by
Jakub Kicinski
882a8bb0 6245237a

+56
+56
drivers/net/pcs/pcs-rzn1-miic.c
··· 10 10 #include <linux/bitops.h> 11 11 #include <linux/clk.h> 12 12 #include <linux/device.h> 13 + #include <linux/device/devres.h> 13 14 #include <linux/mdio.h> 14 15 #include <linux/of.h> 15 16 #include <linux/of_platform.h> ··· 18 17 #include <linux/phylink.h> 19 18 #include <linux/platform_device.h> 20 19 #include <linux/pm_runtime.h> 20 + #include <linux/reset.h> 21 21 #include <linux/slab.h> 22 22 #include <dt-bindings/net/pcs-rzn1-miic.h> 23 23 ··· 53 51 54 52 #define MIIC_MODCTRL_CONF_CONV_MAX 6 55 53 #define MIIC_MODCTRL_CONF_NONE -1 54 + 55 + #define MIIC_MAX_NUM_RSTS 2 56 56 57 57 /** 58 58 * struct modctrl_match - Matching table entry for convctrl configuration ··· 130 126 * @base: base address of the MII converter 131 127 * @dev: Device associated to the MII converter 132 128 * @lock: Lock used for read-modify-write access 129 + * @rsts: Reset controls for the MII converter 133 130 * @of_data: Pointer to OF data 134 131 */ 135 132 struct miic { 136 133 void __iomem *base; 137 134 struct device *dev; 138 135 spinlock_t lock; 136 + struct reset_control_bulk_data rsts[MIIC_MAX_NUM_RSTS]; 139 137 const struct miic_of_data *of_data; 140 138 }; 141 139 ··· 153 147 * @miic_port_start: MIIC port start number 154 148 * @miic_port_max: Maximum MIIC supported 155 149 * @sw_mode_mask: Switch mode mask 150 + * @reset_ids: Reset names array 151 + * @reset_count: Number of entries in the reset_ids array 156 152 */ 157 153 struct miic_of_data { 158 154 struct modctrl_match *match_table; ··· 167 159 u8 miic_port_start; 168 160 u8 miic_port_max; 169 161 u8 sw_mode_mask; 162 + const char * const *reset_ids; 163 + u8 reset_count; 170 164 }; 171 165 172 166 /** ··· 533 523 return ret; 534 524 } 535 525 526 + static void miic_reset_control_bulk_assert(void *data) 527 + { 528 + struct miic *miic = data; 529 + int ret; 530 + 531 + ret = reset_control_bulk_assert(miic->of_data->reset_count, miic->rsts); 532 + if (ret) 533 + dev_err(miic->dev, "failed to assert reset lines\n"); 534 + } 535 + 536 + static int miic_reset_control_init(struct miic *miic) 537 + { 538 + const struct miic_of_data *of_data = miic->of_data; 539 + struct device *dev = miic->dev; 540 + int ret; 541 + u8 i; 542 + 543 + if (!of_data->reset_count) 544 + return 0; 545 + 546 + for (i = 0; i < of_data->reset_count; i++) 547 + miic->rsts[i].id = of_data->reset_ids[i]; 548 + 549 + ret = devm_reset_control_bulk_get_exclusive(dev, of_data->reset_count, 550 + miic->rsts); 551 + if (ret) 552 + return dev_err_probe(dev, ret, 553 + "failed to get bulk reset lines\n"); 554 + 555 + ret = reset_control_bulk_deassert(of_data->reset_count, miic->rsts); 556 + if (ret) 557 + return dev_err_probe(dev, ret, 558 + "failed to deassert reset lines\n"); 559 + 560 + ret = devm_add_action_or_reset(dev, miic_reset_control_bulk_assert, 561 + miic); 562 + if (ret) 563 + return dev_err_probe(dev, ret, "failed to add reset action\n"); 564 + 565 + return 0; 566 + } 567 + 536 568 static int miic_probe(struct platform_device *pdev) 537 569 { 538 570 struct device *dev = &pdev->dev; ··· 597 545 miic->base = devm_platform_ioremap_resource(pdev, 0); 598 546 if (IS_ERR(miic->base)) 599 547 return PTR_ERR(miic->base); 548 + 549 + ret = miic_reset_control_init(miic); 550 + if (ret) 551 + return ret; 600 552 601 553 ret = devm_pm_runtime_enable(dev); 602 554 if (ret < 0)