diff options
author | Madalin Bucur <madalin.bucur@freescale.com> | 2016-05-16 09:57:14 -0400 |
---|---|---|
committer | Madalin Bucur <madalin.bucur@nxp.com> | 2016-10-04 02:26:07 -0400 |
commit | 537a31658f8a01d635eb628eff5895672ac03981 (patch) | |
tree | d85a7c4448f407b6e0b1374241f50490a65f60ef /drivers/net | |
parent | 6fa8519274db638fff104fffeadbffc089499244 (diff) |
fsl/fman: simplify device tree reads
Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/ethernet/freescale/fman/fman.c | 30 | ||||
-rw-r--r-- | drivers/net/ethernet/freescale/fman/fman_port.c | 24 | ||||
-rw-r--r-- | drivers/net/ethernet/freescale/fman/mac.c | 24 |
3 files changed, 30 insertions, 48 deletions
diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c index fb2574878958..2278bbd6bdfe 100644 --- a/drivers/net/ethernet/freescale/fman/fman.c +++ b/drivers/net/ethernet/freescale/fman/fman.c | |||
@@ -2737,8 +2737,8 @@ static struct fman *read_dts_node(struct platform_device *of_dev) | |||
2737 | struct fman *fman; | 2737 | struct fman *fman; |
2738 | struct device_node *fm_node, *muram_node; | 2738 | struct device_node *fm_node, *muram_node; |
2739 | struct resource *res; | 2739 | struct resource *res; |
2740 | const u32 *u32_prop; | 2740 | u32 val, range[2]; |
2741 | int lenp, err, irq; | 2741 | int err, irq; |
2742 | struct clk *clk; | 2742 | struct clk *clk; |
2743 | u32 clk_rate; | 2743 | u32 clk_rate; |
2744 | phys_addr_t phys_base_addr; | 2744 | phys_addr_t phys_base_addr; |
@@ -2750,16 +2750,13 @@ static struct fman *read_dts_node(struct platform_device *of_dev) | |||
2750 | 2750 | ||
2751 | fm_node = of_node_get(of_dev->dev.of_node); | 2751 | fm_node = of_node_get(of_dev->dev.of_node); |
2752 | 2752 | ||
2753 | u32_prop = (const u32 *)of_get_property(fm_node, "cell-index", &lenp); | 2753 | err = of_property_read_u32(fm_node, "cell-index", &val); |
2754 | if (!u32_prop) { | 2754 | if (err) { |
2755 | dev_err(&of_dev->dev, "%s: of_get_property(%s, cell-index) failed\n", | 2755 | dev_err(&of_dev->dev, "%s: failed to read cell-index for %s\n", |
2756 | __func__, fm_node->full_name); | 2756 | __func__, fm_node->full_name); |
2757 | goto fman_node_put; | 2757 | goto fman_node_put; |
2758 | } | 2758 | } |
2759 | if (WARN_ON(lenp != sizeof(u32))) | 2759 | fman->dts_params.id = (u8)val; |
2760 | goto fman_node_put; | ||
2761 | |||
2762 | fman->dts_params.id = (u8)fdt32_to_cpu(u32_prop[0]); | ||
2763 | 2760 | ||
2764 | /* Get the FM interrupt */ | 2761 | /* Get the FM interrupt */ |
2765 | res = platform_get_resource(of_dev, IORESOURCE_IRQ, 0); | 2762 | res = platform_get_resource(of_dev, IORESOURCE_IRQ, 0); |
@@ -2806,18 +2803,15 @@ static struct fman *read_dts_node(struct platform_device *of_dev) | |||
2806 | /* Rounding to MHz */ | 2803 | /* Rounding to MHz */ |
2807 | fman->dts_params.clk_freq = DIV_ROUND_UP(clk_rate, 1000000); | 2804 | fman->dts_params.clk_freq = DIV_ROUND_UP(clk_rate, 1000000); |
2808 | 2805 | ||
2809 | u32_prop = (const u32 *)of_get_property(fm_node, | 2806 | err = of_property_read_u32_array(fm_node, "fsl,qman-channel-range", |
2810 | "fsl,qman-channel-range", | 2807 | &range[0], 2); |
2811 | &lenp); | 2808 | if (err) { |
2812 | if (!u32_prop) { | 2809 | dev_err(&of_dev->dev, "%s: failed to read fsl,qman-channel-range for %s\n", |
2813 | dev_err(&of_dev->dev, "%s: of_get_property(%s, fsl,qman-channel-range) failed\n", | ||
2814 | __func__, fm_node->full_name); | 2810 | __func__, fm_node->full_name); |
2815 | goto fman_node_put; | 2811 | goto fman_node_put; |
2816 | } | 2812 | } |
2817 | if (WARN_ON(lenp != sizeof(u32) * 2)) | 2813 | fman->dts_params.qman_channel_base = range[0]; |
2818 | goto fman_node_put; | 2814 | fman->dts_params.num_of_qman_channels = range[1]; |
2819 | fman->dts_params.qman_channel_base = fdt32_to_cpu(u32_prop[0]); | ||
2820 | fman->dts_params.num_of_qman_channels = fdt32_to_cpu(u32_prop[1]); | ||
2821 | 2815 | ||
2822 | /* Get the MURAM base address and size */ | 2816 | /* Get the MURAM base address and size */ |
2823 | muram_node = of_find_matching_node(fm_node, fman_muram_match); | 2817 | muram_node = of_find_matching_node(fm_node, fman_muram_match); |
diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c index 8b043e7b070b..9f3bb50a2365 100644 --- a/drivers/net/ethernet/freescale/fman/fman_port.c +++ b/drivers/net/ethernet/freescale/fman/fman_port.c | |||
@@ -1625,7 +1625,7 @@ static int fman_port_probe(struct platform_device *of_dev) | |||
1625 | struct device_node *fm_node, *port_node; | 1625 | struct device_node *fm_node, *port_node; |
1626 | struct resource res; | 1626 | struct resource res; |
1627 | struct resource *dev_res; | 1627 | struct resource *dev_res; |
1628 | const u32 *u32_prop; | 1628 | u32 val; |
1629 | int err = 0, lenp; | 1629 | int err = 0, lenp; |
1630 | enum fman_port_type port_type; | 1630 | enum fman_port_type port_type; |
1631 | u16 port_speed; | 1631 | u16 port_speed; |
@@ -1654,28 +1654,20 @@ static int fman_port_probe(struct platform_device *of_dev) | |||
1654 | goto return_err; | 1654 | goto return_err; |
1655 | } | 1655 | } |
1656 | 1656 | ||
1657 | u32_prop = (const u32 *)of_get_property(port_node, "cell-index", &lenp); | 1657 | err = of_property_read_u32(port_node, "cell-index", &val); |
1658 | if (!u32_prop) { | 1658 | if (err) { |
1659 | dev_err(port->dev, "%s: of_get_property(%s, cell-index) failed\n", | 1659 | dev_err(port->dev, "%s: reading cell-index for %s failed\n", |
1660 | __func__, port_node->full_name); | 1660 | __func__, port_node->full_name); |
1661 | err = -EINVAL; | 1661 | err = -EINVAL; |
1662 | goto return_err; | 1662 | goto return_err; |
1663 | } | 1663 | } |
1664 | if (WARN_ON(lenp != sizeof(u32))) { | 1664 | port_id = (u8)val; |
1665 | err = -EINVAL; | ||
1666 | goto return_err; | ||
1667 | } | ||
1668 | port_id = (u8)fdt32_to_cpu(u32_prop[0]); | ||
1669 | |||
1670 | port->dts_params.id = port_id; | 1665 | port->dts_params.id = port_id; |
1671 | 1666 | ||
1672 | if (of_device_is_compatible(port_node, "fsl,fman-v3-port-tx")) { | 1667 | if (of_device_is_compatible(port_node, "fsl,fman-v3-port-tx")) { |
1673 | port_type = FMAN_PORT_TYPE_TX; | 1668 | port_type = FMAN_PORT_TYPE_TX; |
1674 | port_speed = 1000; | 1669 | port_speed = 1000; |
1675 | u32_prop = (const u32 *)of_get_property(port_node, | 1670 | if (of_find_property(port_node, "fsl,fman-10g-port", &lenp)) |
1676 | "fsl,fman-10g-port", | ||
1677 | &lenp); | ||
1678 | if (u32_prop) | ||
1679 | port_speed = 10000; | 1671 | port_speed = 10000; |
1680 | 1672 | ||
1681 | } else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-tx")) { | 1673 | } else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-tx")) { |
@@ -1688,9 +1680,7 @@ static int fman_port_probe(struct platform_device *of_dev) | |||
1688 | } else if (of_device_is_compatible(port_node, "fsl,fman-v3-port-rx")) { | 1680 | } else if (of_device_is_compatible(port_node, "fsl,fman-v3-port-rx")) { |
1689 | port_type = FMAN_PORT_TYPE_RX; | 1681 | port_type = FMAN_PORT_TYPE_RX; |
1690 | port_speed = 1000; | 1682 | port_speed = 1000; |
1691 | u32_prop = (const u32 *)of_get_property(port_node, | 1683 | if (of_find_property(port_node, "fsl,fman-10g-port", &lenp)) |
1692 | "fsl,fman-10g-port", &lenp); | ||
1693 | if (u32_prop) | ||
1694 | port_speed = 10000; | 1684 | port_speed = 10000; |
1695 | 1685 | ||
1696 | } else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-rx")) { | 1686 | } else if (of_device_is_compatible(port_node, "fsl,fman-v2-port-rx")) { |
diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c index f94fad7884df..dc04e617af8d 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c | |||
@@ -653,7 +653,7 @@ MODULE_DEVICE_TABLE(of, mac_match); | |||
653 | 653 | ||
654 | static int mac_probe(struct platform_device *_of_dev) | 654 | static int mac_probe(struct platform_device *_of_dev) |
655 | { | 655 | { |
656 | int err, i, lenp, nph; | 656 | int err, i, nph; |
657 | struct device *dev; | 657 | struct device *dev; |
658 | struct device_node *mac_node, *dev_node; | 658 | struct device_node *mac_node, *dev_node; |
659 | struct mac_device *mac_dev; | 659 | struct mac_device *mac_dev; |
@@ -661,7 +661,7 @@ static int mac_probe(struct platform_device *_of_dev) | |||
661 | struct resource res; | 661 | struct resource res; |
662 | struct mac_priv_s *priv; | 662 | struct mac_priv_s *priv; |
663 | const u8 *mac_addr; | 663 | const u8 *mac_addr; |
664 | const u32 *u32_prop; | 664 | u32 val; |
665 | u8 fman_id; | 665 | u8 fman_id; |
666 | 666 | ||
667 | dev = &_of_dev->dev; | 667 | dev = &_of_dev->dev; |
@@ -723,16 +723,15 @@ static int mac_probe(struct platform_device *_of_dev) | |||
723 | } | 723 | } |
724 | 724 | ||
725 | /* Get the FMan cell-index */ | 725 | /* Get the FMan cell-index */ |
726 | u32_prop = of_get_property(dev_node, "cell-index", &lenp); | 726 | err = of_property_read_u32(dev_node, "cell-index", &val); |
727 | if (!u32_prop) { | 727 | if (err) { |
728 | dev_err(dev, "of_get_property(%s, cell-index) failed\n", | 728 | dev_err(dev, "failed to read cell-index for %s\n", |
729 | dev_node->full_name); | 729 | dev_node->full_name); |
730 | err = -EINVAL; | 730 | err = -EINVAL; |
731 | goto _return_of_node_put; | 731 | goto _return_of_node_put; |
732 | } | 732 | } |
733 | WARN_ON(lenp != sizeof(u32)); | ||
734 | /* cell-index 0 => FMan id 1 */ | 733 | /* cell-index 0 => FMan id 1 */ |
735 | fman_id = (u8)(fdt32_to_cpu(u32_prop[0]) + 1); | 734 | fman_id = (u8)(val + 1); |
736 | 735 | ||
737 | priv->fman = fman_bind(&of_dev->dev); | 736 | priv->fman = fman_bind(&of_dev->dev); |
738 | if (!priv->fman) { | 737 | if (!priv->fman) { |
@@ -779,15 +778,14 @@ static int mac_probe(struct platform_device *_of_dev) | |||
779 | } | 778 | } |
780 | 779 | ||
781 | /* Get the cell-index */ | 780 | /* Get the cell-index */ |
782 | u32_prop = of_get_property(mac_node, "cell-index", &lenp); | 781 | err = of_property_read_u32(mac_node, "cell-index", &val); |
783 | if (!u32_prop) { | 782 | if (err) { |
784 | dev_err(dev, "of_get_property(%s, cell-index) failed\n", | 783 | dev_err(dev, "failed to read cell-index for %s\n", |
785 | mac_node->full_name); | 784 | mac_node->full_name); |
786 | err = -EINVAL; | 785 | err = -EINVAL; |
787 | goto _return_dev_set_drvdata; | 786 | goto _return_dev_set_drvdata; |
788 | } | 787 | } |
789 | WARN_ON(lenp != sizeof(u32)); | 788 | priv->cell_index = (u8)val; |
790 | priv->cell_index = (u8)fdt32_to_cpu(u32_prop[0]); | ||
791 | 789 | ||
792 | /* Get the MAC address */ | 790 | /* Get the MAC address */ |
793 | mac_addr = of_get_mac_address(mac_node); | 791 | mac_addr = of_get_mac_address(mac_node); |
@@ -847,7 +845,7 @@ static int mac_probe(struct platform_device *_of_dev) | |||
847 | priv->phy_if = of_get_phy_mode(mac_node); | 845 | priv->phy_if = of_get_phy_mode(mac_node); |
848 | if (priv->phy_if < 0) { | 846 | if (priv->phy_if < 0) { |
849 | dev_warn(dev, | 847 | dev_warn(dev, |
850 | "of_get_property(%s, phy-connection-type) failed. Defaulting to MII\n", | 848 | "of_get_phy_mode() for %s failed. Defaulting to MII\n", |
851 | mac_node->full_name); | 849 | mac_node->full_name); |
852 | priv->phy_if = PHY_INTERFACE_MODE_MII; | 850 | priv->phy_if = PHY_INTERFACE_MODE_MII; |
853 | } | 851 | } |