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