From nobody Sat Sep 21 02:49:14 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84B6FC6FD18 for ; Tue, 28 Mar 2023 22:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbjC1WR1 (ORCPT ); Tue, 28 Mar 2023 18:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbjC1WRP (ORCPT ); Tue, 28 Mar 2023 18:17:15 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C7AE271C; Tue, 28 Mar 2023 15:17:00 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1phHcg-0003at-0P; Wed, 29 Mar 2023 00:16:58 +0200 Date: Tue, 28 Mar 2023 23:16:51 +0100 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel Cc: Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: [RFC PATCH net-next v2 1/2] net: dsa: mt7530: split-off MDIO driver Message-ID: <4acd93e451146cee593c1b91b74ee72319c63833.1680041193.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to support the built-in switch of some MediaTek SoCs we need to use MMIO instead of MDIO to access the switch. Prepare this be splitting-off the part of the driver registering an MDIO driver, so we can add another module acting as MMIO/platform driver. Signed-off-by: Daniel Golle --- drivers/net/dsa/Kconfig | 8 +- drivers/net/dsa/Makefile | 3 +- drivers/net/dsa/mt7530-mdio.c | 309 ++++++++++++++++++++++++++++++++++ drivers/net/dsa/mt7530.c | 286 ++++--------------------------- drivers/net/dsa/mt7530.h | 24 +-- 5 files changed, 356 insertions(+), 274 deletions(-) create mode 100644 drivers/net/dsa/mt7530-mdio.c diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig index 6b45fa8b69078..0d9d605b3882c 100644 --- a/drivers/net/dsa/Kconfig +++ b/drivers/net/dsa/Kconfig @@ -35,9 +35,15 @@ config NET_DSA_LANTIQ_GSWIP the xrx200 / VR9 SoC. =20 config NET_DSA_MT7530 - tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + tristate "MediaTek Ethernet switch support" select NET_DSA_TAG_MTK select MEDIATEK_GE_PHY + help + This enables support for the MediaTek Ethernet switch chips. + +config NET_DSA_MT7530_MDIO + tristate "MediaTek MT7530 and MT7531 Ethernet switch support" + select NET_DSA_MT7530 select PCS_MTK_LYNXI help This enables support for the MediaTek MT7530 and MT7531 Ethernet diff --git a/drivers/net/dsa/Makefile b/drivers/net/dsa/Makefile index 16eb879e0cb4d..2b072d574ed02 100644 --- a/drivers/net/dsa/Makefile +++ b/drivers/net/dsa/Makefile @@ -6,7 +6,8 @@ ifdef CONFIG_NET_DSA_LOOP obj-$(CONFIG_FIXED_PHY) +=3D dsa_loop_bdinfo.o endif obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) +=3D lantiq_gswip.o -obj-$(CONFIG_NET_DSA_MT7530) +=3D mt7530.o +obj-$(CONFIG_NET_DSA_MT7530) +=3D mt7530.o +obj-$(CONFIG_NET_DSA_MT7530_MDIO) +=3D mt7530-mdio.o obj-$(CONFIG_NET_DSA_MV88E6060) +=3D mv88e6060.o obj-$(CONFIG_NET_DSA_RZN1_A5PSW) +=3D rzn1_a5psw.o obj-$(CONFIG_NET_DSA_SMSC_LAN9303) +=3D lan9303-core.o diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c new file mode 100644 index 0000000000000..203dc28697204 --- /dev/null +++ b/drivers/net/dsa/mt7530-mdio.c @@ -0,0 +1,309 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mt7530.h" + +static const struct of_device_id mt7530_of_match[] =3D { + { .compatible =3D "mediatek,mt7621", .data =3D &mt753x_table[ID_MT7621], = }, + { .compatible =3D "mediatek,mt7530", .data =3D &mt753x_table[ID_MT7530], = }, + { .compatible =3D "mediatek,mt7531", .data =3D &mt753x_table[ID_MT7531], = }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, mt7530_of_match); + +static int mt7530_regmap_read(void *context, unsigned int reg, unsigned in= t *val) +{ + struct mii_bus *bus =3D context; + u16 page, r, lo, hi; + int ret; + + page =3D (reg >> 6) & 0x3ff; + r =3D (reg >> 2) & 0xf; + + /* MT7530 uses 31 as the pseudo port */ + ret =3D bus->write(bus, 0x1f, 0x1f, page); + if (ret < 0) { + dev_err(&bus->dev, + "failed to read mt7530 register\n"); + return ret; + } + + lo =3D bus->read(bus, 0x1f, r); + hi =3D bus->read(bus, 0x1f, 0x10); + + *val =3D (hi << 16) | (lo & 0xffff); + + return 0; +}; + +static int mt7530_regmap_write(void *context, unsigned int reg, unsigned i= nt val) +{ + struct mii_bus *bus =3D context; + u16 page, r, lo, hi; + int ret; + + page =3D (reg >> 6) & 0x3ff; + r =3D (reg >> 2) & 0xf; + lo =3D val & 0xffff; + hi =3D val >> 16; + + /* MT7530 uses 31 as the pseudo port */ + ret =3D bus->write(bus, 0x1f, 0x1f, page); + if (ret < 0) + goto err; + + ret =3D bus->write(bus, 0x1f, r, lo); + if (ret < 0) + goto err; + + ret =3D bus->write(bus, 0x1f, 0x10, hi); +err: + if (ret < 0) + dev_err(&bus->dev, + "failed to write mt7530 register\n"); + return ret; +}; + +static const struct regmap_bus mt7530_mdio_regmap_bus =3D { + .reg_write =3D mt7530_regmap_write, + .reg_read =3D mt7530_regmap_read, +}; + +static void +mt7530_mdio_regmap_lock(void *mdio_lock) +{ + mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED); +} + +static void +mt7530_mdio_regmap_unlock(void *mdio_lock) +{ + mutex_unlock(mdio_lock); +} + +static int +mt7531_create_sgmii(struct mt7530_priv *priv) +{ + struct regmap_config *mt7531_pcs_config[2]; + struct phylink_pcs *pcs; + struct regmap *regmap; + int i, ret =3D 0; + + for (i =3D 0; i < 2; i++) { + mt7531_pcs_config[i] =3D devm_kzalloc(priv->dev, + sizeof(struct regmap_config), + GFP_KERNEL); + if (!mt7531_pcs_config[i]) { + ret =3D -ENOMEM; + break; + } + + mt7531_pcs_config[i]->name =3D i ? "port6" : "port5"; + mt7531_pcs_config[i]->reg_bits =3D 16; + mt7531_pcs_config[i]->val_bits =3D 32; + mt7531_pcs_config[i]->reg_stride =3D 4; + mt7531_pcs_config[i]->reg_base =3D MT7531_SGMII_REG_BASE(5 + i); + mt7531_pcs_config[i]->max_register =3D 0x17c; + mt7531_pcs_config[i]->lock =3D mt7530_mdio_regmap_lock; + mt7531_pcs_config[i]->unlock =3D mt7530_mdio_regmap_unlock; + mt7531_pcs_config[i]->lock_arg =3D &priv->bus->mdio_lock; + + regmap =3D devm_regmap_init(priv->dev, + &mt7530_mdio_regmap_bus, priv->bus, + mt7531_pcs_config[i]); + if (IS_ERR(regmap)) { + ret =3D PTR_ERR(regmap); + break; + } + pcs =3D mtk_pcs_lynxi_create(priv->dev, regmap, + MT7531_PHYA_CTRL_SIGNAL3, 0); + if (!pcs) { + ret =3D -ENXIO; + break; + } + priv->ports[5 + i].sgmii_pcs =3D pcs; + } + + if (ret && i) + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs); + + return ret; +} + +static int +mt7530_probe(struct mdio_device *mdiodev) +{ + static struct regmap_config *sw_regmap_config; + struct mt7530_priv *priv; + struct device_node *dn; + int ret; + + dn =3D mdiodev->dev.of_node; + + priv =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->ds =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); + if (!priv->ds) + return -ENOMEM; + + priv->ds->dev =3D &mdiodev->dev; + priv->ds->num_ports =3D MT7530_NUM_PORTS; + + /* Use medatek,mcm property to distinguish hardware type that would + * casues a little bit differences on power-on sequence. + */ + priv->mcm =3D of_property_read_bool(dn, "mediatek,mcm"); + if (priv->mcm) { + dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n"); + + priv->rstc =3D devm_reset_control_get(&mdiodev->dev, "mcm"); + if (IS_ERR(priv->rstc)) { + dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); + return PTR_ERR(priv->rstc); + } + } + + /* Get the hardware identifier from the devicetree node. + * We will need it for some of the clock and regulator setup. + */ + priv->info =3D of_device_get_match_data(&mdiodev->dev); + if (!priv->info) + return -EINVAL; + + /* Sanity check if these required device operations are filled + * properly. + */ + if (!priv->info->sw_setup || !priv->info->pad_setup || + !priv->info->phy_read_c22 || !priv->info->phy_write_c22 || + !priv->info->mac_port_get_caps || + !priv->info->mac_port_config) + return -EINVAL; + + priv->id =3D priv->info->id; + + if (priv->id =3D=3D ID_MT7530) { + priv->core_pwr =3D devm_regulator_get(&mdiodev->dev, "core"); + if (IS_ERR(priv->core_pwr)) + return PTR_ERR(priv->core_pwr); + + priv->io_pwr =3D devm_regulator_get(&mdiodev->dev, "io"); + if (IS_ERR(priv->io_pwr)) + return PTR_ERR(priv->io_pwr); + } + + /* Not MCM that indicates switch works as the remote standalone + * integrated circuit so the GPIO pin would be used to complete + * the reset, otherwise memory-mapped register accessing used + * through syscon provides in the case of MCM. + */ + if (!priv->mcm) { + priv->reset =3D devm_gpiod_get_optional(&mdiodev->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(priv->reset)) { + dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); + return PTR_ERR(priv->reset); + } + } + + priv->bus =3D mdiodev->bus; + priv->dev =3D &mdiodev->dev; + priv->ds->priv =3D priv; + priv->ds->ops =3D &mt7530_switch_ops; + mutex_init(&priv->reg_mutex); + dev_set_drvdata(&mdiodev->dev, priv); + + sw_regmap_config =3D devm_kzalloc(&mdiodev->dev, sizeof(*sw_regmap_config= ), GFP_KERNEL); + if (!sw_regmap_config) + return -ENOMEM; + + sw_regmap_config->name =3D "switch"; + sw_regmap_config->reg_bits =3D 16; + sw_regmap_config->val_bits =3D 32; + sw_regmap_config->reg_stride =3D 4; + sw_regmap_config->reg_base =3D 0x0; + sw_regmap_config->max_register =3D 0x7ffc; + sw_regmap_config->disable_locking =3D true; + priv->regmap =3D devm_regmap_init(priv->dev, &mt7530_mdio_regmap_bus, + priv->bus, sw_regmap_config); + if (IS_ERR(priv->regmap)) + return PTR_ERR(priv->regmap); + + if (priv->id =3D=3D ID_MT7531) { + ret =3D mt7531_create_sgmii(priv); + if (ret) + return ret; + } + + return dsa_register_switch(priv->ds); +} + +static void +mt7530_remove(struct mdio_device *mdiodev) +{ + struct mt7530_priv *priv =3D dev_get_drvdata(&mdiodev->dev); + int ret =3D 0, i; + + if (!priv) + return; + + ret =3D regulator_disable(priv->core_pwr); + if (ret < 0) + dev_err(priv->dev, + "Failed to disable core power: %d\n", ret); + + ret =3D regulator_disable(priv->io_pwr); + if (ret < 0) + dev_err(priv->dev, "Failed to disable io pwr: %d\n", + ret); + + if (priv->irq) + mt7530_free_irq(priv); + + dsa_unregister_switch(priv->ds); + + for (i =3D 0; i < 2; ++i) + mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs); + + mutex_destroy(&priv->reg_mutex); +} + +static void mt7530_shutdown(struct mdio_device *mdiodev) +{ + struct mt7530_priv *priv =3D dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static struct mdio_driver mt7530_mdio_driver =3D { + .probe =3D mt7530_probe, + .remove =3D mt7530_remove, + .shutdown =3D mt7530_shutdown, + .mdiodrv.driver =3D { + .name =3D "mt7530", + .of_match_table =3D mt7530_of_match, + }, +}; +mdio_module_driver(mt7530_mdio_driver); + +MODULE_AUTHOR("Sean Wang "); +MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MDIO)"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index a0d99af897ace..ca379f4d3cd32 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -185,54 +184,20 @@ core_clear(struct mt7530_priv *priv, u32 reg, u32 val) static int mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val) { - struct mii_bus *bus =3D priv->bus; - u16 page, r, lo, hi; - int ret; - - page =3D (reg >> 6) & 0x3ff; - r =3D (reg >> 2) & 0xf; - lo =3D val & 0xffff; - hi =3D val >> 16; - - /* MT7530 uses 31 as the pseudo port */ - ret =3D bus->write(bus, 0x1f, 0x1f, page); - if (ret < 0) - goto err; - - ret =3D bus->write(bus, 0x1f, r, lo); - if (ret < 0) - goto err; - - ret =3D bus->write(bus, 0x1f, 0x10, hi); -err: - if (ret < 0) - dev_err(&bus->dev, - "failed to write mt7530 register\n"); - return ret; + return regmap_write(priv->regmap, reg, val); } =20 static u32 mt7530_mii_read(struct mt7530_priv *priv, u32 reg) { - struct mii_bus *bus =3D priv->bus; - u16 page, r, lo, hi; + u32 val; int ret; =20 - page =3D (reg >> 6) & 0x3ff; - r =3D (reg >> 2) & 0xf; - - /* MT7530 uses 31 as the pseudo port */ - ret =3D bus->write(bus, 0x1f, 0x1f, page); - if (ret < 0) { - dev_err(&bus->dev, - "failed to read mt7530 register\n"); + ret =3D regmap_read(priv->regmap, reg, &val); + if (!ret) + return val; + else return ret; - } - - lo =3D bus->read(bus, 0x1f, r); - hi =3D bus->read(bus, 0x1f, 0x10); - - return (hi << 16) | (lo & 0xffff); } =20 static void @@ -282,14 +247,10 @@ mt7530_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { struct mii_bus *bus =3D priv->bus; - u32 val; =20 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); =20 - val =3D mt7530_mii_read(priv, reg); - val &=3D ~mask; - val |=3D set; - mt7530_mii_write(priv, reg, val); + regmap_update_bits(priv->regmap, reg, mask, set); =20 mutex_unlock(&bus->mdio_lock); } @@ -297,7 +258,7 @@ mt7530_rmw(struct mt7530_priv *priv, u32 reg, static void mt7530_set(struct mt7530_priv *priv, u32 reg, u32 val) { - mt7530_rmw(priv, reg, 0, val); + mt7530_rmw(priv, reg, val, val); } =20 static void @@ -921,6 +882,24 @@ mt7530_set_ageing_time(struct dsa_switch *ds, unsigned= int msecs) return 0; } =20 +static const char *p5_intf_modes(unsigned int p5_interface) +{ + switch (p5_interface) { + case P5_DISABLED: + return "DISABLED"; + case P5_INTF_SEL_PHY_P0: + return "PHY P0"; + case P5_INTF_SEL_PHY_P4: + return "PHY P4"; + case P5_INTF_SEL_GMAC5: + return "GMAC5"; + case P5_INTF_SEL_GMAC5_SGMII: + return "GMAC5_SGMII"; + default: + return "unknown"; + } +} + static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t inte= rface) { struct mt7530_priv *priv =3D ds->priv; @@ -2067,12 +2046,13 @@ mt7530_free_irq_common(struct mt7530_priv *priv) irq_domain_remove(priv->irq_domain); } =20 -static void +void mt7530_free_irq(struct mt7530_priv *priv) { mt7530_free_mdio_irq(priv); mt7530_free_irq_common(priv); } +EXPORT_SYMBOL_GPL(mt7530_free_irq); =20 static int mt7530_setup_mdio(struct mt7530_priv *priv) @@ -2895,57 +2875,10 @@ static const struct phylink_pcs_ops mt7530_pcs_ops = =3D { .pcs_an_restart =3D mt7530_pcs_an_restart, }; =20 -static int mt7530_regmap_read(void *context, unsigned int reg, unsigned in= t *val) -{ - struct mt7530_priv *priv =3D context; - - *val =3D mt7530_read(priv, reg); - return 0; -}; - -static int mt7530_regmap_write(void *context, unsigned int reg, unsigned i= nt val) -{ - struct mt7530_priv *priv =3D context; - - mt7530_write(priv, reg, val); - return 0; -}; - -static int mt7530_regmap_update_bits(void *context, unsigned int reg, - unsigned int mask, unsigned int val) -{ - struct mt7530_priv *priv =3D context; - - mt7530_rmw(priv, reg, mask, val); - return 0; -}; - -static const struct regmap_bus mt7531_regmap_bus =3D { - .reg_write =3D mt7530_regmap_write, - .reg_read =3D mt7530_regmap_read, - .reg_update_bits =3D mt7530_regmap_update_bits, -}; - -#define MT7531_PCS_REGMAP_CONFIG(_name, _reg_base) \ - { \ - .name =3D _name, \ - .reg_bits =3D 16, \ - .val_bits =3D 32, \ - .reg_stride =3D 4, \ - .reg_base =3D _reg_base, \ - .max_register =3D 0x17c, \ - } - -static const struct regmap_config mt7531_pcs_config[] =3D { - MT7531_PCS_REGMAP_CONFIG("port5", MT7531_SGMII_REG_BASE(5)), - MT7531_PCS_REGMAP_CONFIG("port6", MT7531_SGMII_REG_BASE(6)), -}; - static int mt753x_setup(struct dsa_switch *ds) { struct mt7530_priv *priv =3D ds->priv; - struct regmap *regmap; int i, ret; =20 /* Initialise the PCS devices */ @@ -2967,16 +2900,6 @@ mt753x_setup(struct dsa_switch *ds) if (ret && priv->irq) mt7530_free_irq_common(priv); =20 - if (priv->id =3D=3D ID_MT7531) - for (i =3D 0; i < 2; i++) { - regmap =3D devm_regmap_init(ds->dev, - &mt7531_regmap_bus, priv, - &mt7531_pcs_config[i]); - priv->ports[5 + i].sgmii_pcs =3D - mtk_pcs_lynxi_create(ds->dev, regmap, - MT7531_PHYA_CTRL_SIGNAL3, 0); - } - return ret; } =20 @@ -3010,7 +2933,7 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, = int port, return 0; } =20 -static const struct dsa_switch_ops mt7530_switch_ops =3D { +const struct dsa_switch_ops mt7530_switch_ops =3D { .get_tag_protocol =3D mtk_get_tag_protocol, .setup =3D mt753x_setup, .get_strings =3D mt7530_get_strings, @@ -3044,8 +2967,9 @@ static const struct dsa_switch_ops mt7530_switch_ops = =3D { .get_mac_eee =3D mt753x_get_mac_eee, .set_mac_eee =3D mt753x_set_mac_eee, }; +EXPORT_SYMBOL_GPL(mt7530_switch_ops); =20 -static const struct mt753x_info mt753x_table[] =3D { +const struct mt753x_info mt753x_table[] =3D { [ID_MT7621] =3D { .id =3D ID_MT7621, .pcs_ops =3D &mt7530_pcs_ops, @@ -3084,153 +3008,7 @@ static const struct mt753x_info mt753x_table[] =3D { .mac_port_config =3D mt7531_mac_config, }, }; - -static const struct of_device_id mt7530_of_match[] =3D { - { .compatible =3D "mediatek,mt7621", .data =3D &mt753x_table[ID_MT7621], = }, - { .compatible =3D "mediatek,mt7530", .data =3D &mt753x_table[ID_MT7530], = }, - { .compatible =3D "mediatek,mt7531", .data =3D &mt753x_table[ID_MT7531], = }, - { /* sentinel */ }, -}; -MODULE_DEVICE_TABLE(of, mt7530_of_match); - -static int -mt7530_probe(struct mdio_device *mdiodev) -{ - struct mt7530_priv *priv; - struct device_node *dn; - - dn =3D mdiodev->dev.of_node; - - priv =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - priv->ds =3D devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL); - if (!priv->ds) - return -ENOMEM; - - priv->ds->dev =3D &mdiodev->dev; - priv->ds->num_ports =3D MT7530_NUM_PORTS; - - /* Use medatek,mcm property to distinguish hardware type that would - * casues a little bit differences on power-on sequence. - */ - priv->mcm =3D of_property_read_bool(dn, "mediatek,mcm"); - if (priv->mcm) { - dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n"); - - priv->rstc =3D devm_reset_control_get(&mdiodev->dev, "mcm"); - if (IS_ERR(priv->rstc)) { - dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); - return PTR_ERR(priv->rstc); - } - } - - /* Get the hardware identifier from the devicetree node. - * We will need it for some of the clock and regulator setup. - */ - priv->info =3D of_device_get_match_data(&mdiodev->dev); - if (!priv->info) - return -EINVAL; - - /* Sanity check if these required device operations are filled - * properly. - */ - if (!priv->info->sw_setup || !priv->info->pad_setup || - !priv->info->phy_read_c22 || !priv->info->phy_write_c22 || - !priv->info->mac_port_get_caps || - !priv->info->mac_port_config) - return -EINVAL; - - priv->id =3D priv->info->id; - - if (priv->id =3D=3D ID_MT7530) { - priv->core_pwr =3D devm_regulator_get(&mdiodev->dev, "core"); - if (IS_ERR(priv->core_pwr)) - return PTR_ERR(priv->core_pwr); - - priv->io_pwr =3D devm_regulator_get(&mdiodev->dev, "io"); - if (IS_ERR(priv->io_pwr)) - return PTR_ERR(priv->io_pwr); - } - - /* Not MCM that indicates switch works as the remote standalone - * integrated circuit so the GPIO pin would be used to complete - * the reset, otherwise memory-mapped register accessing used - * through syscon provides in the case of MCM. - */ - if (!priv->mcm) { - priv->reset =3D devm_gpiod_get_optional(&mdiodev->dev, "reset", - GPIOD_OUT_LOW); - if (IS_ERR(priv->reset)) { - dev_err(&mdiodev->dev, "Couldn't get our reset line\n"); - return PTR_ERR(priv->reset); - } - } - - priv->bus =3D mdiodev->bus; - priv->dev =3D &mdiodev->dev; - priv->ds->priv =3D priv; - priv->ds->ops =3D &mt7530_switch_ops; - mutex_init(&priv->reg_mutex); - dev_set_drvdata(&mdiodev->dev, priv); - - return dsa_register_switch(priv->ds); -} - -static void -mt7530_remove(struct mdio_device *mdiodev) -{ - struct mt7530_priv *priv =3D dev_get_drvdata(&mdiodev->dev); - int ret =3D 0, i; - - if (!priv) - return; - - ret =3D regulator_disable(priv->core_pwr); - if (ret < 0) - dev_err(priv->dev, - "Failed to disable core power: %d\n", ret); - - ret =3D regulator_disable(priv->io_pwr); - if (ret < 0) - dev_err(priv->dev, "Failed to disable io pwr: %d\n", - ret); - - if (priv->irq) - mt7530_free_irq(priv); - - dsa_unregister_switch(priv->ds); - - for (i =3D 0; i < 2; ++i) - mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs); - - mutex_destroy(&priv->reg_mutex); -} - -static void mt7530_shutdown(struct mdio_device *mdiodev) -{ - struct mt7530_priv *priv =3D dev_get_drvdata(&mdiodev->dev); - - if (!priv) - return; - - dsa_switch_shutdown(priv->ds); - - dev_set_drvdata(&mdiodev->dev, NULL); -} - -static struct mdio_driver mt7530_mdio_driver =3D { - .probe =3D mt7530_probe, - .remove =3D mt7530_remove, - .shutdown =3D mt7530_shutdown, - .mdiodrv.driver =3D { - .name =3D "mt7530", - .of_match_table =3D mt7530_of_match, - }, -}; - -mdio_module_driver(mt7530_mdio_driver); +EXPORT_SYMBOL_GPL(mt753x_table); =20 MODULE_AUTHOR("Sean Wang "); MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch"); diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index c5d29f3fc1d80..6ac7f503dce2f 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -682,24 +682,6 @@ enum p5_interface_select { P5_INTF_SEL_GMAC5_SGMII, }; =20 -static const char *p5_intf_modes(unsigned int p5_interface) -{ - switch (p5_interface) { - case P5_DISABLED: - return "DISABLED"; - case P5_INTF_SEL_PHY_P0: - return "PHY P0"; - case P5_INTF_SEL_PHY_P4: - return "PHY P4"; - case P5_INTF_SEL_GMAC5: - return "GMAC5"; - case P5_INTF_SEL_GMAC5_SGMII: - return "GMAC5_SGMII"; - default: - return "unknown"; - } -} - struct mt7530_priv; =20 struct mt753x_pcs { @@ -777,6 +759,7 @@ struct mt7530_priv { struct reset_control *rstc; struct regulator *core_pwr; struct regulator *io_pwr; + struct regmap *regmap; struct gpio_desc *reset; const struct mt753x_info *info; unsigned int id; @@ -830,4 +813,9 @@ static inline void INIT_MT7530_DUMMY_POLL(struct mt7530= _dummy_poll *p, p->reg =3D reg; } =20 +void mt7530_free_irq(struct mt7530_priv *priv); + +extern const struct dsa_switch_ops mt7530_switch_ops; +extern const struct mt753x_info mt753x_table[]; + #endif /* __MT7530_H */ --=20 2.39.2