diff options
author | Vivien Didelot <vivien.didelot@savoirfairelinux.com> | 2016-06-20 13:14:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-06-21 03:58:29 -0400 |
commit | 469d729f2a701e78d12b936bf0df63b8acae73c9 (patch) | |
tree | 1e120b446b4693b5b2e7240c99e6e97a131b3d86 /drivers/net/dsa | |
parent | 9f8b3ee1b5be49f5757fd60c22c921ad3ef58585 (diff) |
net: dsa: mv88e6xxx: add chip allocation helper
Add an helper function to allocate the chip structure at the beginning
of the probe functions. It will be used to initialize the SMI access.
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.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c index 2c8617275d25..113092a64d6b 100644 --- a/drivers/net/dsa/mv88e6xxx.c +++ b/drivers/net/dsa/mv88e6xxx.c | |||
@@ -3601,6 +3601,21 @@ static const struct mv88e6xxx_info *mv88e6xxx_lookup_info(unsigned int prod_num) | |||
3601 | return NULL; | 3601 | return NULL; |
3602 | } | 3602 | } |
3603 | 3603 | ||
3604 | static struct mv88e6xxx_priv_state *mv88e6xxx_alloc_chip(struct device *dev) | ||
3605 | { | ||
3606 | struct mv88e6xxx_priv_state *ps; | ||
3607 | |||
3608 | ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL); | ||
3609 | if (!ps) | ||
3610 | return NULL; | ||
3611 | |||
3612 | ps->dev = dev; | ||
3613 | |||
3614 | mutex_init(&ps->reg_lock); | ||
3615 | |||
3616 | return ps; | ||
3617 | } | ||
3618 | |||
3604 | static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, | 3619 | static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, |
3605 | struct device *host_dev, int sw_addr, | 3620 | struct device *host_dev, int sw_addr, |
3606 | void **priv) | 3621 | void **priv) |
@@ -3616,32 +3631,30 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, | |||
3616 | if (!bus) | 3631 | if (!bus) |
3617 | return NULL; | 3632 | return NULL; |
3618 | 3633 | ||
3634 | ps = mv88e6xxx_alloc_chip(dsa_dev); | ||
3635 | if (!ps) | ||
3636 | return NULL; | ||
3637 | |||
3619 | id = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID); | 3638 | id = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID); |
3620 | if (id < 0) | 3639 | if (id < 0) |
3621 | return NULL; | 3640 | goto free; |
3622 | 3641 | ||
3623 | prod_num = (id & 0xfff0) >> 4; | 3642 | prod_num = (id & 0xfff0) >> 4; |
3624 | rev = id & 0x000f; | 3643 | rev = id & 0x000f; |
3625 | 3644 | ||
3626 | info = mv88e6xxx_lookup_info(prod_num); | 3645 | info = mv88e6xxx_lookup_info(prod_num); |
3627 | if (!info) | 3646 | if (!info) |
3628 | return NULL; | 3647 | goto free; |
3629 | 3648 | ||
3630 | name = info->name; | 3649 | name = info->name; |
3631 | 3650 | ||
3632 | ps = devm_kzalloc(dsa_dev, sizeof(*ps), GFP_KERNEL); | ||
3633 | if (!ps) | ||
3634 | return NULL; | ||
3635 | |||
3636 | ps->bus = bus; | 3651 | ps->bus = bus; |
3637 | ps->sw_addr = sw_addr; | 3652 | ps->sw_addr = sw_addr; |
3638 | ps->info = info; | 3653 | ps->info = info; |
3639 | ps->dev = dsa_dev; | ||
3640 | mutex_init(&ps->reg_lock); | ||
3641 | 3654 | ||
3642 | err = mv88e6xxx_mdio_register(ps, NULL); | 3655 | err = mv88e6xxx_mdio_register(ps, NULL); |
3643 | if (err) | 3656 | if (err) |
3644 | return NULL; | 3657 | goto free; |
3645 | 3658 | ||
3646 | *priv = ps; | 3659 | *priv = ps; |
3647 | 3660 | ||
@@ -3649,6 +3662,10 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev, | |||
3649 | prod_num, name, rev); | 3662 | prod_num, name, rev); |
3650 | 3663 | ||
3651 | return name; | 3664 | return name; |
3665 | free: | ||
3666 | devm_kfree(dsa_dev, ps); | ||
3667 | |||
3668 | return NULL; | ||
3652 | } | 3669 | } |
3653 | 3670 | ||
3654 | static struct dsa_switch_driver mv88e6xxx_switch_driver = { | 3671 | static struct dsa_switch_driver mv88e6xxx_switch_driver = { |
@@ -3720,14 +3737,12 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) | |||
3720 | u32 eeprom_len; | 3737 | u32 eeprom_len; |
3721 | int err; | 3738 | int err; |
3722 | 3739 | ||
3723 | ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL); | 3740 | ps = mv88e6xxx_alloc_chip(dev); |
3724 | if (!ps) | 3741 | if (!ps) |
3725 | return -ENOMEM; | 3742 | return -ENOMEM; |
3726 | 3743 | ||
3727 | ps->dev = dev; | ||
3728 | ps->bus = mdiodev->bus; | 3744 | ps->bus = mdiodev->bus; |
3729 | ps->sw_addr = mdiodev->addr; | 3745 | ps->sw_addr = mdiodev->addr; |
3730 | mutex_init(&ps->reg_lock); | ||
3731 | 3746 | ||
3732 | id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); | 3747 | id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID); |
3733 | if (id < 0) | 3748 | if (id < 0) |