aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/dsa
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>2016-06-20 13:14:08 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-21 03:58:29 -0400
commitbc46a3d57cf7715d76eef8ea822c763cd271aacf (patch)
treee9961a546b268cc000d81ebbe6cabb89c7fc7c0a /drivers/net/dsa
parent4a70c4ab4fa49c07cbec519dfb9f9f90d2fec8d5 (diff)
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: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa')
-rw-r--r--drivers/net/dsa/mv88e6xxx.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 4e24ac556ae2..de92add7f9a6 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -3601,6 +3601,30 @@ static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num)
3601 return NULL; 3601 return NULL;
3602} 3602}
3603 3603
3604static int mv88e6xxx_detect(struct mv88e6xxx_priv_state *ps)
3605{
3606 const struct mv88e6xxx_info *info;
3607 int id, prod_num, rev;
3608
3609 id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID);
3610 if (id < 0)
3611 return id;
3612
3613 prod_num = (id & 0xfff0) >> 4;
3614 rev = id & 0x000f;
3615
3616 info = mv88e6xxx_lookup_info(prod_num);
3617 if (!info)
3618 return -ENODEV;
3619
3620 ps->info = info;
3621
3622 dev_info(ps->dev, "switch 0x%x detected: %s, revision %u\n",
3623 ps->info->prod_num, ps->info->name, rev);
3624
3625 return 0;
3626}
3627
3604static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev) 3628static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev)
3605{ 3629{
3606 struct mv88e6xxx_priv_state *ps; 3630 struct mv88e6xxx_priv_state *ps;
@@ -3633,11 +3657,8 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3633 struct device *host_dev, int sw_addr, 3657 struct device *host_dev, int sw_addr,
3634 void **priv) 3658 void **priv)
3635{ 3659{
3636 const struct mv88e6xxx_info *info;
3637 struct mv88e6xxx_priv_state *ps; 3660 struct mv88e6xxx_priv_state *ps;
3638 struct mii_bus *bus; 3661 struct mii_bus *bus;
3639 const char *name;
3640 int id, prod_num, rev;
3641 int err; 3662 int err;
3642 3663
3643 bus = dsa_host_dev_to_mii_bus(host_dev); 3664 bus = dsa_host_dev_to_mii_bus(host_dev);
@@ -3652,31 +3673,17 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
3652 if (err) 3673 if (err)
3653 goto free; 3674 goto free;
3654 3675
3655 id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); 3676 err = mv88e6xxx_detect(ps);
3656 if (id < 0) 3677 if (err)
3657 goto free;
3658
3659 prod_num = (id & 0xfff0) >> 4;
3660 rev = id & 0x000f;
3661
3662 info = mv88e6xxx_lookup_info(prod_num);
3663 if (!info)
3664 goto free; 3678 goto free;
3665 3679
3666 name = info->name;
3667
3668 ps->info = info;
3669
3670 err = mv88e6xxx_mdio_register(ps, NULL); 3680 err = mv88e6xxx_mdio_register(ps, NULL);
3671 if (err) 3681 if (err)
3672 goto free; 3682 goto free;
3673 3683
3674 *priv = ps; 3684 *priv = ps;
3675 3685
3676 dev_info(&ps->bus->dev, "switch 0x%x probed: %s, revision %u\n", 3686 return ps->info->name;
3677 prod_num, name, rev);
3678
3679 return name;
3680free: 3687free:
3681 devm_kfree(dsa_dev, ps); 3688 devm_kfree(dsa_dev, ps);
3682 3689
@@ -3748,7 +3755,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
3748 struct device *dev = &mdiodev->dev; 3755 struct device *dev = &mdiodev->dev;
3749 struct device_node *np = dev->of_node; 3756 struct device_node *np = dev->of_node;
3750 struct mv88e6xxx_priv_state *ps; 3757 struct mv88e6xxx_priv_state *ps;
3751 int id, prod_num, rev;
3752 u32 eeprom_len; 3758 u32 eeprom_len;
3753 int err; 3759 int err;
3754 3760
@@ -3760,16 +3766,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
3760 if (err) 3766 if (err)
3761 return err; 3767 return err;
3762 3768
3763 id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); 3769 err = mv88e6xxx_detect(ps);
3764 if (id < 0) 3770 if (err)
3765 return id; 3771 return err;
3766
3767 prod_num = (id & 0xfff0) >> 4;
3768 rev = id & 0x000f;
3769
3770 ps->info = mv88e6xxx_lookup_info(prod_num);
3771 if (!ps->info)
3772 return -ENODEV;
3773 3772
3774 ps->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS); 3773 ps->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
3775 if (IS_ERR(ps->reset)) 3774 if (IS_ERR(ps->reset))
@@ -3789,9 +3788,6 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
3789 return err; 3788 return err;
3790 } 3789 }
3791 3790
3792 dev_info(dev, "switch 0x%x probed: %s, revision %u\n",
3793 prod_num, ps->info->name, rev);
3794
3795 return 0; 3791 return 0;
3796} 3792}
3797 3793