Re: [PATCH net-next 2/4] net: dsa: mt7530: add interrupt support

From: Florian Fainelli
Date: Thu Apr 29 2021 - 19:40:11 EST




On 4/28/2021 11:21 PM, DENG Qingfang wrote:
> Add support for MT7530 interrupt controller to handle internal PHYs.
> In order to assign an IRQ number to each PHY, the registration of MDIO bus
> is also done in this driver.
>
> Signed-off-by: DENG Qingfang <dqfext@xxxxxxxxx>
> ---

[snip]

> +static int
> +mt7530_setup_irq(struct mt7530_priv *priv)
> +{
> + struct device *dev = priv->dev;
> + struct device_node *np = dev->of_node;
> + int ret;
> +
> + if (!of_property_read_bool(np, "interrupt-controller")) {
> + dev_info(dev, "no interrupt support\n");
> + return 0;
> + }
> +
> + priv->irq = of_irq_get(np, 0);

Using platform_get_irq() may be a bit nicer to avoid using too many
OF-centric APIs, but this does not have to be changed right now.
Likewise for the interrupt-controller above.

> + if (priv->irq <= 0) {
> + dev_err(dev, "failed to get parent IRQ: %d\n", priv->irq);
> + return priv->irq ? : -EINVAL;
> + }
> +
> + priv->irq_domain = irq_domain_add_linear(np, MT7530_NUM_PHYS,
> + &mt7530_irq_domain_ops, priv);
> + if (!priv->irq_domain) {
> + dev_err(dev, "failed to create IRQ domain\n");
> + return -ENOMEM;
> + }
> +
> + /* This register must be set for MT7530 to properly fire interrupts */
> + if (priv->id != ID_MT7531)
> + mt7530_set(priv, MT7530_TOP_SIG_CTRL, TOP_SIG_CTRL_NORMAL);
> +
> + ret = request_threaded_irq(priv->irq, NULL, mt7530_irq_thread_fn,
> + IRQF_ONESHOT, KBUILD_MODNAME, priv);

Maybe dev_name() would be more unique in case a system happens to have
more switches in the future so you can easily differentiate them.

> + if (ret) {

Can you call mt7530_free_irq() to avoid the error repetition?

> + irq_domain_remove(priv->irq_domain);
> + dev_err(dev, "failed to request IRQ: %d\n", ret);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static void
> +mt7530_free_mdio_irq(struct mt7530_priv *priv)
> +{
> + int p;
> +
> + for (p = 0; p < MT7530_NUM_PHYS; p++) {
> + if (BIT(p) & priv->ds->phys_mii_mask) {
> + unsigned int irq;
> +
> + irq = irq_find_mapping(priv->irq_domain, p);
> + irq_dispose_mapping(irq);
> + }
> + }
> +}
> +
> +static void
> +mt7530_free_irq_common(struct mt7530_priv *priv)
> +{
> + free_irq(priv->irq, priv);
> + irq_domain_remove(priv->irq_domain);
> +}
> +
> +static void
> +mt7530_free_irq(struct mt7530_priv *priv)
> +{
> + mt7530_free_mdio_irq(priv);
> + mt7530_free_irq_common(priv);
> +}
> +
> +static int
> +mt7530_setup_mdio(struct mt7530_priv *priv)
> +{
> + struct dsa_switch *ds = priv->ds;
> + struct device *dev = priv->dev;
> + struct mii_bus *bus;
> + static int idx;
> + int ret;
> +
> + bus = devm_mdiobus_alloc(dev);
> + if (!bus)
> + return -ENOMEM;
> +
> + ds->slave_mii_bus = bus;
> + bus->priv = priv;
> + bus->name = KBUILD_MODNAME "-mii";
> + snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++);

Likewise using dev_name() here would provide an unique name in case you
have multiple switches.

Feel free to address my comments later, they do not seem to be blocking:

Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
--
Florian