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 Reviewed-by: Andrew Lunn Tested-by: Wolfram Sang --- v2->v3: - Moved reset handling from probe to a separate function miic_reset_control_init() to avoid checkpatch warnings. - Restored Reviewed-by and Tested-by tags. v1->v2: - No change. --- drivers/net/pcs/pcs-rzn1-miic.c | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index f6d9c03d10f0..75009b30084a 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; }; /** @@ -523,6 +533,48 @@ 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_reset_control_init(struct miic *miic) +{ + const struct miic_of_data *of_data = miic->of_data; + struct device *dev = miic->dev; + int ret; + u8 i; + + if (!of_data->reset_count) + return 0; + + for (i = 0; i < of_data->reset_count; i++) + miic->rsts[i].id = of_data->reset_ids[i]; + + ret = devm_reset_control_bulk_get_exclusive(dev, of_data->reset_count, + miic->rsts); + if (ret) + return dev_err_probe(dev, ret, + "failed to get bulk reset lines\n"); + + ret = reset_control_bulk_deassert(of_data->reset_count, miic->rsts); + if (ret) + return dev_err_probe(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(dev, ret, "failed to add reset action\n"); + + return 0; +} + static int miic_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -546,6 +598,10 @@ static int miic_probe(struct platform_device *pdev) if (IS_ERR(miic->base)) return PTR_ERR(miic->base); + ret = miic_reset_control_init(miic); + if (ret) + return ret; + ret = devm_pm_runtime_enable(dev); if (ret < 0) return ret; -- 2.51.0