From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Machek Subject: [RFD] mv88e6060: Allow the driver to be probed from device tree Date: Thu, 6 Dec 2018 14:02:46 +0100 Message-ID: <20181206130246.GC22343@amd> References: <20181115195111.GA9946@amd> <20181206130051.GA22343@amd> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0lnxQi9hkpPO77W3" Cc: buytenh@marvell.com, buytenh@wantstofly.org, nico@marvell.com To: andrew@lunn.ch, vivien.didelot@savoirfairelinux.com, netdev@vger.kernel.org, f.fainelli@gmail.com Return-path: Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:34147 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728482AbeLFNCu (ORCPT ); Thu, 6 Dec 2018 08:02:50 -0500 Content-Disposition: inline In-Reply-To: <20181206130051.GA22343@amd> Sender: netdev-owner@vger.kernel.org List-ID: --0lnxQi9hkpPO77W3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable mv88e6060: Allow the driver to be probed from device tree =20 This is NOT ready for merge. Hardcoding an address is a bad idea, and obvio= usly it would be good to allow module removal, too. =20 Signed-off-by: Pavel Machek (not ready) diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index f43104f48dbb..9e3901f18518 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c @@ -77,26 +77,40 @@ static const char *mv88e6060_get_name(struct mii_bus *b= us, int sw_addr) static enum dsa_tag_protocol mv88e6060_get_tag_protocol(struct dsa_switch = *ds, int port) { + //return DSA_TAG_PROTO_QCA; + //return DSA_TAG_PROTO_TRAILER; return DSA_TAG_PROTO_TRAILER; } =20 +static struct mv88e6060_priv * +alloc_priv(struct device *dsa_dev, struct mii_bus *bus, int sw_addr) +{ + struct mv88e6060_priv *priv; + + priv =3D devm_kzalloc(dsa_dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return NULL; + + priv->bus =3D bus; + priv->sw_addr =3D sw_addr; + return priv; +} + static const char *mv88e6060_drv_probe(struct device *dsa_dev, struct device *host_dev, int sw_addr, void **_priv) { struct mii_bus *bus =3D dsa_host_dev_to_mii_bus(host_dev); - struct mv88e6060_priv *priv; const char *name; =20 name =3D mv88e6060_get_name(bus, sw_addr); - if (name) { - priv =3D devm_kzalloc(dsa_dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return NULL; - *_priv =3D priv; - priv->bus =3D bus; - priv->sw_addr =3D sw_addr; - } +=09 + if (!name) + return NULL; + + *_priv =3D alloc_priv(dsa_dev, bus, sw_addr); + if (!*_priv) + return NULL; =20 return name; } @@ -132,9 +146,12 @@ static int mv88e6060_switch_reset(struct dsa_switch *d= s) =20 usleep_range(1000, 2000); } - if (time_after(jiffies, timeout)) + if (time_after(jiffies, timeout)) { + printk("e6060: reset timed out!\n"); return -ETIMEDOUT; + } =20 + printk("e6060: reset ok\n");=09 return 0; } =20 @@ -284,15 +301,94 @@ static struct dsa_switch_driver mv88e6060_switch_drv = =3D { .ops =3D &mv88e6060_switch_ops, }; =20 +static int mv88e6060_probe(struct mdio_device *mdiodev) +{ + struct device *dev =3D &mdiodev->dev; + struct device_node *np =3D dev->of_node; + const struct mv88e6060_info *compat_info; + struct mv88e6060_priv *chip; + u32 eeprom_len; + int err; + + int addr =3D 0x10 /* mdiodev->addr */ ; + + chip =3D alloc_priv(dev, mdiodev->bus, addr); + if (!chip) + return -ENOMEM; + + { + char *name =3D mv88e6060_get_name(mdiodev->bus, addr); + printk("e6060: got name %s @ %lx %lx\n", name, mdiodev->bus, addr); + } + { + struct dsa_switch *ds; + + ds =3D dsa_switch_alloc(dev, 6); + if (!ds) + return -ENOMEM; + + ds->priv =3D chip; + ds->dev =3D dev; + ds->ops =3D &mv88e6060_switch_ops; + ds->ageing_time_min =3D 15000; + ds->ageing_time_max =3D 15000 * U8_MAX; + + dev_set_drvdata(dev, ds); + + return dsa_register_switch(ds); + } + + printk("e6060: probe ok\n"); + return 0; +} + +static void mv88e6060_remove(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds =3D dev_get_drvdata(&mdiodev->dev); + struct mv88e6060_chip *chip =3D ds->priv; + + printk("e6060: remove.\n"); + BUG(); +#if 0 + mv88e6060_phy_destroy(chip); + mv88e6060_unregister_switch(chip); + mv88e6060_mdio_unregister(chip); +#endif +} + +static const struct of_device_id mv88e6060_of_match[] =3D { + { + .compatible =3D "marvell,mv88e6060", + }, + { /* sentinel */ }, +}; + +MODULE_DEVICE_TABLE(of, mv88e6060_of_match); + +static struct mdio_driver mv88e6060_driver =3D { + .probe =3D mv88e6060_probe, + .remove =3D mv88e6060_remove, + .mdiodrv.driver =3D { + .name =3D "mv88e6060", + .of_match_table =3D mv88e6060_of_match, + }, +}; + static int __init mv88e6060_init(void) { + int r; + printk("e6060: init\n"); register_switch_driver(&mv88e6060_switch_drv); - return 0; + r =3D mdio_driver_register(&mv88e6060_driver); + printk("e6060: init %d\n", r); + return r; } + module_init(mv88e6060_init); =20 static void __exit mv88e6060_cleanup(void) { + mdio_driver_unregister(&mv88e6060_driver); unregister_switch_driver(&mv88e6060_switch_drv); } module_exit(mv88e6060_cleanup); --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --0lnxQi9hkpPO77W3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlwJHfYACgkQMOfwapXb+vJO5wCfR8/gaIAtgztfP09nFmrtDoQ0 MMIAnRhvT9eadsqZ7C2FxqOHqsm7o+jm =Bfw5 -----END PGP SIGNATURE----- --0lnxQi9hkpPO77W3--