phy: fixed_phy: Add gpio to determine link up/down.
An SFP module may have a link up/down status pin which can be connection to a GPIO line of the host. Add support for reading such an GPIO in the fixed_phy driver. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
8b59d19e74
commit
a5597008db
@ -17,6 +17,8 @@ properties:
|
|||||||
enabled.
|
enabled.
|
||||||
* 'asym-pause' (boolean, optional), to indicate that asym_pause should
|
* 'asym-pause' (boolean, optional), to indicate that asym_pause should
|
||||||
be enabled.
|
be enabled.
|
||||||
|
* 'link-gpios' ('gpio-list', optional), to indicate if a gpio can be read
|
||||||
|
to determine if the link is up.
|
||||||
|
|
||||||
Old, deprecated 'fixed-link' binding:
|
Old, deprecated 'fixed-link' binding:
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ Old, deprecated 'fixed-link' binding:
|
|||||||
- e: asymmetric pause configuration: 0 for no asymmetric pause, 1 for
|
- e: asymmetric pause configuration: 0 for no asymmetric pause, 1 for
|
||||||
asymmetric pause
|
asymmetric pause
|
||||||
|
|
||||||
Example:
|
Examples:
|
||||||
|
|
||||||
ethernet@0 {
|
ethernet@0 {
|
||||||
...
|
...
|
||||||
@ -40,3 +42,13 @@ ethernet@0 {
|
|||||||
};
|
};
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ethernet@1 {
|
||||||
|
...
|
||||||
|
fixed-link {
|
||||||
|
speed = <1000>;
|
||||||
|
pause;
|
||||||
|
link-gpios = <&gpio0 12 GPIO_ACTIVE_HIGH>;
|
||||||
|
};
|
||||||
|
...
|
||||||
|
};
|
||||||
|
@ -254,7 +254,7 @@ static struct fixed_phy_status stmmac0_fixed_phy_status = {
|
|||||||
|
|
||||||
During the board's device_init we can configure the first
|
During the board's device_init we can configure the first
|
||||||
MAC for fixed_link by calling:
|
MAC for fixed_link by calling:
|
||||||
fixed_phy_add(PHY_POLL, 1, &stmmac0_fixed_phy_status));)
|
fixed_phy_add(PHY_POLL, 1, &stmmac0_fixed_phy_status, -1);
|
||||||
and the second one, with a real PHY device attached to the bus,
|
and the second one, with a real PHY device attached to the bus,
|
||||||
by using the stmmac_mdio_bus_data structure (to provide the id, the
|
by using the stmmac_mdio_bus_data structure (to provide the id, the
|
||||||
reset procedure etc).
|
reset procedure etc).
|
||||||
|
@ -126,7 +126,7 @@ static struct fixed_phy_status nettel_fixed_phy_status __initdata = {
|
|||||||
static int __init init_BSP(void)
|
static int __init init_BSP(void)
|
||||||
{
|
{
|
||||||
m5272_uarts_init();
|
m5272_uarts_init();
|
||||||
fixed_phy_add(PHY_POLL, 0, &nettel_fixed_phy_status);
|
fixed_phy_add(PHY_POLL, 0, &nettel_fixed_phy_status, -1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,7 +679,8 @@ static int __init ar7_register_devices(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ar7_has_high_cpmac()) {
|
if (ar7_has_high_cpmac()) {
|
||||||
res = fixed_phy_add(PHY_POLL, cpmac_high.id, &fixed_phy_status);
|
res = fixed_phy_add(PHY_POLL, cpmac_high.id,
|
||||||
|
&fixed_phy_status, -1);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
cpmac_get_mac(1, cpmac_high_data.dev_addr);
|
cpmac_get_mac(1, cpmac_high_data.dev_addr);
|
||||||
|
|
||||||
@ -692,7 +693,7 @@ static int __init ar7_register_devices(void)
|
|||||||
} else
|
} else
|
||||||
cpmac_low_data.phy_mask = 0xffffffff;
|
cpmac_low_data.phy_mask = 0xffffffff;
|
||||||
|
|
||||||
res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status);
|
res = fixed_phy_add(PHY_POLL, cpmac_low.id, &fixed_phy_status, -1);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
cpmac_get_mac(0, cpmac_low_data.dev_addr);
|
cpmac_get_mac(0, cpmac_low_data.dev_addr);
|
||||||
res = platform_device_register(&cpmac_low);
|
res = platform_device_register(&cpmac_low);
|
||||||
|
@ -263,7 +263,7 @@ static int __init bcm47xx_register_bus_complete(void)
|
|||||||
bcm47xx_leds_register();
|
bcm47xx_leds_register();
|
||||||
bcm47xx_workarounds();
|
bcm47xx_workarounds();
|
||||||
|
|
||||||
fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
|
fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
device_initcall(bcm47xx_register_bus_complete);
|
device_initcall(bcm47xx_register_bus_complete);
|
||||||
|
@ -585,7 +585,7 @@ static int bcmgenet_mii_pd_init(struct bcmgenet_priv *priv)
|
|||||||
.asym_pause = 0,
|
.asym_pause = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL);
|
phydev = fixed_phy_register(PHY_POLL, &fphy_status, -1, NULL);
|
||||||
if (!phydev || IS_ERR(phydev)) {
|
if (!phydev || IS_ERR(phydev)) {
|
||||||
dev_err(kdev, "failed to register fixed PHY device\n");
|
dev_err(kdev, "failed to register fixed PHY device\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
|
||||||
#define MII_REGS_NUM 29
|
#define MII_REGS_NUM 29
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ struct fixed_phy {
|
|||||||
struct fixed_phy_status status;
|
struct fixed_phy_status status;
|
||||||
int (*link_update)(struct net_device *, struct fixed_phy_status *);
|
int (*link_update)(struct net_device *, struct fixed_phy_status *);
|
||||||
struct list_head node;
|
struct list_head node;
|
||||||
|
int link_gpio;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct platform_device *pdev;
|
static struct platform_device *pdev;
|
||||||
@ -52,6 +54,9 @@ static int fixed_phy_update_regs(struct fixed_phy *fp)
|
|||||||
u16 lpagb = 0;
|
u16 lpagb = 0;
|
||||||
u16 lpa = 0;
|
u16 lpa = 0;
|
||||||
|
|
||||||
|
if (gpio_is_valid(fp->link_gpio))
|
||||||
|
fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
|
||||||
|
|
||||||
if (!fp->status.link)
|
if (!fp->status.link)
|
||||||
goto done;
|
goto done;
|
||||||
bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
|
bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
|
||||||
@ -215,7 +220,8 @@ int fixed_phy_update_state(struct phy_device *phydev,
|
|||||||
EXPORT_SYMBOL(fixed_phy_update_state);
|
EXPORT_SYMBOL(fixed_phy_update_state);
|
||||||
|
|
||||||
int fixed_phy_add(unsigned int irq, int phy_addr,
|
int fixed_phy_add(unsigned int irq, int phy_addr,
|
||||||
struct fixed_phy_status *status)
|
struct fixed_phy_status *status,
|
||||||
|
int link_gpio)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct fixed_mdio_bus *fmb = &platform_fmb;
|
struct fixed_mdio_bus *fmb = &platform_fmb;
|
||||||
@ -231,15 +237,26 @@ int fixed_phy_add(unsigned int irq, int phy_addr,
|
|||||||
|
|
||||||
fp->addr = phy_addr;
|
fp->addr = phy_addr;
|
||||||
fp->status = *status;
|
fp->status = *status;
|
||||||
|
fp->link_gpio = link_gpio;
|
||||||
|
|
||||||
|
if (gpio_is_valid(fp->link_gpio)) {
|
||||||
|
ret = gpio_request_one(fp->link_gpio, GPIOF_DIR_IN,
|
||||||
|
"fixed-link-gpio-link");
|
||||||
|
if (ret)
|
||||||
|
goto err_regs;
|
||||||
|
}
|
||||||
|
|
||||||
ret = fixed_phy_update_regs(fp);
|
ret = fixed_phy_update_regs(fp);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_regs;
|
goto err_gpio;
|
||||||
|
|
||||||
list_add_tail(&fp->node, &fmb->phys);
|
list_add_tail(&fp->node, &fmb->phys);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_gpio:
|
||||||
|
if (gpio_is_valid(fp->link_gpio))
|
||||||
|
gpio_free(fp->link_gpio);
|
||||||
err_regs:
|
err_regs:
|
||||||
kfree(fp);
|
kfree(fp);
|
||||||
return ret;
|
return ret;
|
||||||
@ -254,6 +271,8 @@ void fixed_phy_del(int phy_addr)
|
|||||||
list_for_each_entry_safe(fp, tmp, &fmb->phys, node) {
|
list_for_each_entry_safe(fp, tmp, &fmb->phys, node) {
|
||||||
if (fp->addr == phy_addr) {
|
if (fp->addr == phy_addr) {
|
||||||
list_del(&fp->node);
|
list_del(&fp->node);
|
||||||
|
if (gpio_is_valid(fp->link_gpio))
|
||||||
|
gpio_free(fp->link_gpio);
|
||||||
kfree(fp);
|
kfree(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -266,6 +285,7 @@ static DEFINE_SPINLOCK(phy_fixed_addr_lock);
|
|||||||
|
|
||||||
struct phy_device *fixed_phy_register(unsigned int irq,
|
struct phy_device *fixed_phy_register(unsigned int irq,
|
||||||
struct fixed_phy_status *status,
|
struct fixed_phy_status *status,
|
||||||
|
int link_gpio,
|
||||||
struct device_node *np)
|
struct device_node *np)
|
||||||
{
|
{
|
||||||
struct fixed_mdio_bus *fmb = &platform_fmb;
|
struct fixed_mdio_bus *fmb = &platform_fmb;
|
||||||
@ -282,7 +302,7 @@ struct phy_device *fixed_phy_register(unsigned int irq,
|
|||||||
phy_addr = phy_fixed_addr++;
|
phy_addr = phy_fixed_addr++;
|
||||||
spin_unlock(&phy_fixed_addr_lock);
|
spin_unlock(&phy_fixed_addr_lock);
|
||||||
|
|
||||||
ret = fixed_phy_add(PHY_POLL, phy_addr, status);
|
ret = fixed_phy_add(PHY_POLL, phy_addr, status, link_gpio);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <linux/phy.h>
|
#include <linux/phy.h>
|
||||||
#include <linux/phy_fixed.h>
|
#include <linux/phy_fixed.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
#include <linux/of_irq.h>
|
#include <linux/of_irq.h>
|
||||||
#include <linux/of_mdio.h>
|
#include <linux/of_mdio.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
@ -294,6 +295,7 @@ int of_phy_register_fixed_link(struct device_node *np)
|
|||||||
struct fixed_phy_status status = {};
|
struct fixed_phy_status status = {};
|
||||||
struct device_node *fixed_link_node;
|
struct device_node *fixed_link_node;
|
||||||
const __be32 *fixed_link_prop;
|
const __be32 *fixed_link_prop;
|
||||||
|
int link_gpio;
|
||||||
int len, err;
|
int len, err;
|
||||||
struct phy_device *phy;
|
struct phy_device *phy;
|
||||||
const char *managed;
|
const char *managed;
|
||||||
@ -302,7 +304,7 @@ int of_phy_register_fixed_link(struct device_node *np)
|
|||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
if (strcmp(managed, "in-band-status") == 0) {
|
if (strcmp(managed, "in-band-status") == 0) {
|
||||||
/* status is zeroed, namely its .link member */
|
/* status is zeroed, namely its .link member */
|
||||||
phy = fixed_phy_register(PHY_POLL, &status, np);
|
phy = fixed_phy_register(PHY_POLL, &status, -1, np);
|
||||||
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,8 +320,13 @@ int of_phy_register_fixed_link(struct device_node *np)
|
|||||||
status.pause = of_property_read_bool(fixed_link_node, "pause");
|
status.pause = of_property_read_bool(fixed_link_node, "pause");
|
||||||
status.asym_pause = of_property_read_bool(fixed_link_node,
|
status.asym_pause = of_property_read_bool(fixed_link_node,
|
||||||
"asym-pause");
|
"asym-pause");
|
||||||
|
link_gpio = of_get_named_gpio_flags(fixed_link_node,
|
||||||
|
"link-gpios", 0, NULL);
|
||||||
of_node_put(fixed_link_node);
|
of_node_put(fixed_link_node);
|
||||||
phy = fixed_phy_register(PHY_POLL, &status, np);
|
if (link_gpio == -EPROBE_DEFER)
|
||||||
|
return -EPROBE_DEFER;
|
||||||
|
|
||||||
|
phy = fixed_phy_register(PHY_POLL, &status, link_gpio, np);
|
||||||
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +338,7 @@ int of_phy_register_fixed_link(struct device_node *np)
|
|||||||
status.speed = be32_to_cpu(fixed_link_prop[2]);
|
status.speed = be32_to_cpu(fixed_link_prop[2]);
|
||||||
status.pause = be32_to_cpu(fixed_link_prop[3]);
|
status.pause = be32_to_cpu(fixed_link_prop[3]);
|
||||||
status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
|
status.asym_pause = be32_to_cpu(fixed_link_prop[4]);
|
||||||
phy = fixed_phy_register(PHY_POLL, &status, np);
|
phy = fixed_phy_register(PHY_POLL, &status, -1, np);
|
||||||
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
return IS_ERR(phy) ? PTR_ERR(phy) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,11 @@ struct device_node;
|
|||||||
|
|
||||||
#if IS_ENABLED(CONFIG_FIXED_PHY)
|
#if IS_ENABLED(CONFIG_FIXED_PHY)
|
||||||
extern int fixed_phy_add(unsigned int irq, int phy_id,
|
extern int fixed_phy_add(unsigned int irq, int phy_id,
|
||||||
struct fixed_phy_status *status);
|
struct fixed_phy_status *status,
|
||||||
|
int link_gpio);
|
||||||
extern struct phy_device *fixed_phy_register(unsigned int irq,
|
extern struct phy_device *fixed_phy_register(unsigned int irq,
|
||||||
struct fixed_phy_status *status,
|
struct fixed_phy_status *status,
|
||||||
|
int link_gpio,
|
||||||
struct device_node *np);
|
struct device_node *np);
|
||||||
extern void fixed_phy_del(int phy_addr);
|
extern void fixed_phy_del(int phy_addr);
|
||||||
extern int fixed_phy_set_link_update(struct phy_device *phydev,
|
extern int fixed_phy_set_link_update(struct phy_device *phydev,
|
||||||
@ -26,12 +28,14 @@ extern int fixed_phy_update_state(struct phy_device *phydev,
|
|||||||
const struct fixed_phy_status *changed);
|
const struct fixed_phy_status *changed);
|
||||||
#else
|
#else
|
||||||
static inline int fixed_phy_add(unsigned int irq, int phy_id,
|
static inline int fixed_phy_add(unsigned int irq, int phy_id,
|
||||||
struct fixed_phy_status *status)
|
struct fixed_phy_status *status,
|
||||||
|
int link_gpio)
|
||||||
{
|
{
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
static inline struct phy_device *fixed_phy_register(unsigned int irq,
|
static inline struct phy_device *fixed_phy_register(unsigned int irq,
|
||||||
struct fixed_phy_status *status,
|
struct fixed_phy_status *status,
|
||||||
|
int gpio_link,
|
||||||
struct device_node *np)
|
struct device_node *np)
|
||||||
{
|
{
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user