18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/errno.h>
24 #include <linux/slab.h>
28 #include <linux/netdevice.h>
32 #include <linux/module.h>
33 #include <linux/mii.h>
34 #include <linux/ethtool.h>
39 #include <asm/uaccess.h>
51 static void phy_device_release(
struct device *
dev)
138 if (phy_needs_fixup(phydev, fixup)) {
141 err = fixup->
run(phydev);
167 dev->
dev.release = phy_device_release;
249 *phy_id = 0xffffffff;
255 for (i = 1; i < num_ids; i++) {
291 static int get_phy_id(
struct mii_bus *bus,
int addr,
u32 *phy_id,
297 return get_phy_c45_ids(bus, addr, phy_id, c45_ids);
306 *phy_id = (phy_reg & 0xffff) << 16;
314 *phy_id |= (phy_reg & 0xffff);
335 r = get_phy_id(bus, addr, &phy_id, is_c45, &c45_ids);
340 if ((phy_id & 0x1fffffff) == 0x1fffffff)
359 if (phydev->
bus->phy_map[phydev->
addr])
361 phydev->
bus->phy_map[phydev->
addr] = phydev;
368 pr_err(
"phy %d failed to register\n", phydev->
addr);
408 static void phy_prepare_link(
struct phy_device *phydev,
428 rc = phy_attach_direct(dev, phydev, flags, interface);
432 phy_prepare_link(phydev,
handler);
469 pr_err(
"PHY %s not found\n", bus_id);
503 if (!phydev->
drv || !phydev->
drv->config_init)
510 return phydev->
drv->config_init(phydev);
541 d->
driver = &genphy_driver.driver;
543 err = d->
driver->probe(d);
597 pr_err(
"PHY %s not found\n", bus_id);
602 rc = phy_attach_direct(dev, phydev, flags, interface);
623 if (phydev->
dev.driver == &genphy_driver.driver)
640 static int genphy_config_advert(
struct phy_device *phydev)
659 adv |= ethtool_adv_to_mii_adv_t(advertise);
678 adv |= ethtool_adv_to_mii_ctrl1000_t(advertise);
700 static int genphy_setup_forced(
struct phy_device *phydev)
759 return genphy_setup_forced(phydev);
761 result = genphy_config_advert(phydev);
916 static int genphy_config_init(
struct phy_device *phydev)
1000 static int phy_probe(
struct device *dev)
1009 drv = phydev->
dev.driver;
1011 phydev->
drv = phydrv;
1028 if (phydev->
drv->probe)
1029 err = phydev->
drv->probe(phydev);
1037 static int phy_remove(
struct device *dev)
1047 if (phydev->
drv->remove)
1048 phydev->
drv->remove(phydev);
1064 new_driver->
driver.probe = phy_probe;
1065 new_driver->
driver.remove = phy_remove;
1070 pr_err(
"%s: Error %d in registering driver\n",
1071 new_driver->
name, retval);
1076 pr_debug(
"%s: Registered new driver\n", new_driver->
name);
1086 for (i = 0; i <
n; i++) {
1107 for (i = 0; i <
n; i++) {
1114 .phy_id = 0xffffffff,
1115 .phy_id_mask = 0xffffffff,
1116 .name =
"Generic PHY",
1117 .config_init = genphy_config_init,
1126 static int __init phy_init(
void)
1141 static void __exit phy_exit(
void)