Commit bc46a3d5 authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: mv88e6xxx: add detection helper

Extract the common detection code which assigns the info structure to
the chip given the read switch ID.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4a70c4ab
...@@ -3601,6 +3601,30 @@ static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num) ...@@ -3601,6 +3601,30 @@ static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
return NULL; return NULL;
} }
static int mv88e6xxx_detect(struct mv88e6xxx_priv_state *ps)
{
const struct mv88e6xxx_info *info;
int id, prod_num, rev;
id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID);
if (id < 0)
return id;
prod_num = (id & 0xfff0) >> 4;
rev = id & 0x000f;
info = mv88e6xxx_lookup_info(prod_num);
if (!info)
return -ENODEV;
ps->info = info;
dev_info(ps->dev, "switch 0x%x detected: %s, revision %u\n",
ps->info->prod_num, ps->info->name, rev);
return 0;
}
static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev) static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev)
{ {
struct mv88e6xxx_priv_state *ps; struct mv88e6xxx_priv_state *ps;
...@@ -3633,11 +3657,8 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, ...@@ -3633,11 +3657,8 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
struct device *host_dev, int sw_addr, struct device *host_dev, int sw_addr,
void **priv) void **priv)
{ {
const struct mv88e6xxx_info *info;
struct mv88e6xxx_priv_state *ps; struct mv88e6xxx_priv_state *ps;
struct mii_bus *bus; struct mii_bus *bus;
const char *name;
int id, prod_num, rev;
int err; int err;
bus = dsa_host_dev_to_mii_bus(host_dev); bus = dsa_host_dev_to_mii_bus(host_dev);
...@@ -3652,31 +3673,17 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, ...@@ -3652,31 +3673,17 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
if (err) if (err)
goto free; goto free;
id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); err = mv88e6xxx_detect(ps);
if (id < 0) if (err)
goto free;
prod_num = (id & 0xfff0) >> 4;
rev = id & 0x000f;
info = mv88e6xxx_lookup_info(prod_num);
if (!info)
goto free; goto free;
name = info->name;
ps->info = info;
err = mv88e6xxx_mdio_register(ps, NULL); err = mv88e6xxx_mdio_register(ps, NULL);
if (err) if (err)
goto free; goto free;
*priv = ps; *priv = ps;
dev_info(&ps->bus->dev, "switch 0x%x probed: %s, revision %u\n", return ps->info->name;
prod_num, name, rev);
return name;
free: free:
devm_kfree(dsa_dev, ps); devm_kfree(dsa_dev, ps);
...@@ -3748,7 +3755,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) ...@@ -3748,7 +3755,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
struct device *dev = &mdiodev->dev; struct device *dev = &mdiodev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct mv88e6xxx_priv_state *ps; struct mv88e6xxx_priv_state *ps;
int id, prod_num, rev;
u32 eeprom_len; u32 eeprom_len;
int err; int err;
...@@ -3760,16 +3766,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) ...@@ -3760,16 +3766,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
if (err) if (err)
return err; return err;
id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); err = mv88e6xxx_detect(ps);
if (id < 0) if (err)
return id; return err;
prod_num = (id & 0xfff0) >> 4;
rev = id & 0x000f;
ps->info = mv88e6xxx_lookup_info(prod_num);
if (!ps->info)
return -ENODEV;
ps->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS); ps->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
if (IS_ERR(ps->reset)) if (IS_ERR(ps->reset))
...@@ -3789,9 +3788,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) ...@@ -3789,9 +3788,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
return err; return err;
} }
dev_info(dev, "switch 0x%x probed: %s, revision %u\n",
prod_num, ps->info->name, rev);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment