xref: /openbmc/linux/drivers/net/phy/ax88796b.c (revision a9520543)
1a9520543SMichael Schmitz // SPDX-License-Identifier: GPL-2.0+
2a9520543SMichael Schmitz /* Driver for Asix PHYs
3a9520543SMichael Schmitz  *
4a9520543SMichael Schmitz  * Author: Michael Schmitz <schmitzmic@gmail.com>
5a9520543SMichael Schmitz  */
6a9520543SMichael Schmitz #include <linux/kernel.h>
7a9520543SMichael Schmitz #include <linux/errno.h>
8a9520543SMichael Schmitz #include <linux/init.h>
9a9520543SMichael Schmitz #include <linux/module.h>
10a9520543SMichael Schmitz #include <linux/mii.h>
11a9520543SMichael Schmitz #include <linux/phy.h>
12a9520543SMichael Schmitz 
13a9520543SMichael Schmitz #define PHY_ID_ASIX_AX88796B		0x003b1841
14a9520543SMichael Schmitz 
15a9520543SMichael Schmitz MODULE_DESCRIPTION("Asix PHY driver");
16a9520543SMichael Schmitz MODULE_AUTHOR("Michael Schmitz <schmitzmic@gmail.com>");
17a9520543SMichael Schmitz MODULE_LICENSE("GPL");
18a9520543SMichael Schmitz 
19a9520543SMichael Schmitz /**
20a9520543SMichael Schmitz  * asix_soft_reset - software reset the PHY via BMCR_RESET bit
21a9520543SMichael Schmitz  * @phydev: target phy_device struct
22a9520543SMichael Schmitz  *
23a9520543SMichael Schmitz  * Description: Perform a software PHY reset using the standard
24a9520543SMichael Schmitz  * BMCR_RESET bit and poll for the reset bit to be cleared.
25a9520543SMichael Schmitz  * Toggle BMCR_RESET bit off to accommodate broken AX8796B PHY implementation
26a9520543SMichael Schmitz  * such as used on the Individual Computers' X-Surf 100 Zorro card.
27a9520543SMichael Schmitz  *
28a9520543SMichael Schmitz  * Returns: 0 on success, < 0 on failure
29a9520543SMichael Schmitz  */
30a9520543SMichael Schmitz static int asix_soft_reset(struct phy_device *phydev)
31a9520543SMichael Schmitz {
32a9520543SMichael Schmitz 	int ret;
33a9520543SMichael Schmitz 
34a9520543SMichael Schmitz 	/* Asix PHY won't reset unless reset bit toggles */
35a9520543SMichael Schmitz 	ret = phy_write(phydev, MII_BMCR, 0);
36a9520543SMichael Schmitz 	if (ret < 0)
37a9520543SMichael Schmitz 		return ret;
38a9520543SMichael Schmitz 
39a9520543SMichael Schmitz 	return genphy_soft_reset(phydev);
40a9520543SMichael Schmitz }
41a9520543SMichael Schmitz 
42a9520543SMichael Schmitz static struct phy_driver asix_driver[] = { {
43a9520543SMichael Schmitz 	.phy_id		= PHY_ID_ASIX_AX88796B,
44a9520543SMichael Schmitz 	.name		= "Asix Electronics AX88796B",
45a9520543SMichael Schmitz 	.phy_id_mask	= 0xfffffff0,
46a9520543SMichael Schmitz 	/* PHY_BASIC_FEATURES */
47a9520543SMichael Schmitz 	.soft_reset	= asix_soft_reset,
48a9520543SMichael Schmitz } };
49a9520543SMichael Schmitz 
50a9520543SMichael Schmitz module_phy_driver(asix_driver);
51a9520543SMichael Schmitz 
52a9520543SMichael Schmitz static struct mdio_device_id __maybe_unused asix_tbl[] = {
53a9520543SMichael Schmitz 	{ PHY_ID_ASIX_AX88796B, 0xfffffff0 },
54a9520543SMichael Schmitz 	{ }
55a9520543SMichael Schmitz };
56a9520543SMichael Schmitz 
57a9520543SMichael Schmitz MODULE_DEVICE_TABLE(mdio, asix_tbl);
58