From: Lad Prabhakar 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 --- v1->v2: - No change. --- drivers/net/pcs/pcs-rzn1-miic.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index c0aa93fd7274..d97554e203f0 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include @@ -52,6 +54,8 @@ #define MIIC_MODCTRL_CONF_CONV_MAX 6 #define MIIC_MODCTRL_CONF_NONE -1 +#define MIIC_MAX_NUM_RSTS 2 + /** * struct modctrl_match - Matching table entry for convctrl configuration * See section 8.2.1 of manual. @@ -126,12 +130,14 @@ static const char * const index_to_string[] = { * @base: base address of the MII converter * @dev: Device associated to the MII converter * @lock: Lock used for read-modify-write access + * @rsts: Reset controls for the MII converter * @of_data: Pointer to OF data */ struct miic { void __iomem *base; struct device *dev; spinlock_t lock; + struct reset_control_bulk_data rsts[MIIC_MAX_NUM_RSTS]; const struct miic_of_data *of_data; }; @@ -147,6 +153,8 @@ struct miic { * @miic_port_start: MIIC port start number * @miic_port_max: Maximum MIIC supported * @sw_mode_mask: Switch mode mask + * @reset_ids: Reset names array + * @reset_count: Number of entries in the reset_ids array */ struct miic_of_data { struct modctrl_match *match_table; @@ -159,6 +167,8 @@ struct miic_of_data { u8 miic_port_start; u8 miic_port_max; u8 sw_mode_mask; + const char * const *reset_ids; + u8 reset_count; }; /** @@ -518,6 +528,16 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg) return ret; } +static void miic_reset_control_bulk_assert(void *data) +{ + struct miic *miic = data; + int ret; + + ret = reset_control_bulk_assert(miic->of_data->reset_count, miic->rsts); + if (ret) + dev_err(miic->dev, "failed to assert reset lines\n"); +} + static int miic_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -541,6 +561,27 @@ static int miic_probe(struct platform_device *pdev) if (IS_ERR(miic->base)) return PTR_ERR(miic->base); + if (miic->of_data->reset_count) { + u8 i; + + for (i = 0; i < miic->of_data->reset_count; i++) + miic->rsts[i].id = miic->of_data->reset_ids[i]; + + ret = devm_reset_control_bulk_get_exclusive(miic->dev, + miic->of_data->reset_count, + miic->rsts); + if (ret) + return dev_err_probe(miic->dev, ret, "failed to get bulk reset lines\n"); + + ret = reset_control_bulk_deassert(miic->of_data->reset_count, miic->rsts); + if (ret) + return dev_err_probe(miic->dev, ret, "failed to deassert reset lines\n"); + + ret = devm_add_action_or_reset(dev, miic_reset_control_bulk_assert, miic); + if (ret) + return dev_err_probe(miic->dev, ret, "failed to add reset action\n"); + } + ret = devm_pm_runtime_enable(dev); if (ret < 0) return ret; -- 2.51.0