aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-01-16 01:00:17 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-16 01:00:17 -0500
commit57d737c5e21cd26f63272aa4b0e34680788e12ed (patch)
treec59d439d0f3e8927101966c50bb78517c8cb0b78
parentf812116b174e59a350acc8e4856213a166a91222 (diff)
parentde3900833ee635d5658415fea9c8c4e13507d777 (diff)
Merge branch 'davinci_emac'
Tony Lindgren says: ==================== Fixes for davinci_emac Here's a repost of the fixes for davinci_emac with patches updated for comments and acks collected. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/devicetree/bindings/net/davinci_emac.txt3
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c96
2 files changed, 77 insertions, 22 deletions
diff --git a/Documentation/devicetree/bindings/net/davinci_emac.txt b/Documentation/devicetree/bindings/net/davinci_emac.txt
index 032808843f90..24c5cdaba8d2 100644
--- a/Documentation/devicetree/bindings/net/davinci_emac.txt
+++ b/Documentation/devicetree/bindings/net/davinci_emac.txt
@@ -4,7 +4,8 @@ This file provides information, what the device node
4for the davinci_emac interface contains. 4for the davinci_emac interface contains.
5 5
6Required properties: 6Required properties:
7- compatible: "ti,davinci-dm6467-emac" or "ti,am3517-emac" 7- compatible: "ti,davinci-dm6467-emac", "ti,am3517-emac" or
8 "ti,dm816-emac"
8- reg: Offset and length of the register set for the device 9- reg: Offset and length of the register set for the device
9- ti,davinci-ctrl-reg-offset: offset to control register 10- ti,davinci-ctrl-reg-offset: offset to control register
10- ti,davinci-ctrl-mod-reg-offset: offset to control module register 11- ti,davinci-ctrl-mod-reg-offset: offset to control module register
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index ea712512c7d1..5fae4354722c 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -62,6 +62,7 @@
62#include <linux/of.h> 62#include <linux/of.h>
63#include <linux/of_address.h> 63#include <linux/of_address.h>
64#include <linux/of_device.h> 64#include <linux/of_device.h>
65#include <linux/of_mdio.h>
65#include <linux/of_irq.h> 66#include <linux/of_irq.h>
66#include <linux/of_net.h> 67#include <linux/of_net.h>
67 68
@@ -343,9 +344,7 @@ struct emac_priv {
343 u32 multicast_hash_cnt[EMAC_NUM_MULTICAST_BITS]; 344 u32 multicast_hash_cnt[EMAC_NUM_MULTICAST_BITS];
344 u32 rx_addr_type; 345 u32 rx_addr_type;
345 const char *phy_id; 346 const char *phy_id;
346#ifdef CONFIG_OF
347 struct device_node *phy_node; 347 struct device_node *phy_node;
348#endif
349 struct phy_device *phydev; 348 struct phy_device *phydev;
350 spinlock_t lock; 349 spinlock_t lock;
351 /*platform specific members*/ 350 /*platform specific members*/
@@ -922,6 +921,16 @@ static void emac_int_disable(struct emac_priv *priv)
922 if (priv->int_disable) 921 if (priv->int_disable)
923 priv->int_disable(); 922 priv->int_disable();
924 923
924 /* NOTE: Rx Threshold and Misc interrupts are not enabled */
925
926 /* ack rxen only then a new pulse will be generated */
927 emac_write(EMAC_DM646X_MACEOIVECTOR,
928 EMAC_DM646X_MAC_EOI_C0_RXEN);
929
930 /* ack txen- only then a new pulse will be generated */
931 emac_write(EMAC_DM646X_MACEOIVECTOR,
932 EMAC_DM646X_MAC_EOI_C0_TXEN);
933
925 local_irq_restore(flags); 934 local_irq_restore(flags);
926 935
927 } else { 936 } else {
@@ -951,15 +960,6 @@ static void emac_int_enable(struct emac_priv *priv)
951 * register */ 960 * register */
952 961
953 /* NOTE: Rx Threshold and Misc interrupts are not enabled */ 962 /* NOTE: Rx Threshold and Misc interrupts are not enabled */
954
955 /* ack rxen only then a new pulse will be generated */
956 emac_write(EMAC_DM646X_MACEOIVECTOR,
957 EMAC_DM646X_MAC_EOI_C0_RXEN);
958
959 /* ack txen- only then a new pulse will be generated */
960 emac_write(EMAC_DM646X_MACEOIVECTOR,
961 EMAC_DM646X_MAC_EOI_C0_TXEN);
962
963 } else { 963 } else {
964 /* Set DM644x control registers for interrupt control */ 964 /* Set DM644x control registers for interrupt control */
965 emac_ctrl_write(EMAC_CTRL_EWCTL, 0x1); 965 emac_ctrl_write(EMAC_CTRL_EWCTL, 0x1);
@@ -1537,7 +1537,13 @@ static int emac_dev_open(struct net_device *ndev)
1537 int i = 0; 1537 int i = 0;
1538 struct emac_priv *priv = netdev_priv(ndev); 1538 struct emac_priv *priv = netdev_priv(ndev);
1539 1539
1540 pm_runtime_get(&priv->pdev->dev); 1540 ret = pm_runtime_get_sync(&priv->pdev->dev);
1541 if (ret < 0) {
1542 pm_runtime_put_noidle(&priv->pdev->dev);
1543 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n",
1544 __func__, ret);
1545 return ret;
1546 }
1541 1547
1542 netif_carrier_off(ndev); 1548 netif_carrier_off(ndev);
1543 for (cnt = 0; cnt < ETH_ALEN; cnt++) 1549 for (cnt = 0; cnt < ETH_ALEN; cnt++)
@@ -1596,8 +1602,20 @@ static int emac_dev_open(struct net_device *ndev)
1596 cpdma_ctlr_start(priv->dma); 1602 cpdma_ctlr_start(priv->dma);
1597 1603
1598 priv->phydev = NULL; 1604 priv->phydev = NULL;
1605
1606 if (priv->phy_node) {
1607 priv->phydev = of_phy_connect(ndev, priv->phy_node,
1608 &emac_adjust_link, 0, 0);
1609 if (!priv->phydev) {
1610 dev_err(emac_dev, "could not connect to phy %s\n",
1611 priv->phy_node->full_name);
1612 ret = -ENODEV;
1613 goto err;
1614 }
1615 }
1616
1599 /* use the first phy on the bus if pdata did not give us a phy id */ 1617 /* use the first phy on the bus if pdata did not give us a phy id */
1600 if (!priv->phy_id) { 1618 if (!priv->phydev && !priv->phy_id) {
1601 struct device *phy; 1619 struct device *phy;
1602 1620
1603 phy = bus_find_device(&mdio_bus_type, NULL, NULL, 1621 phy = bus_find_device(&mdio_bus_type, NULL, NULL,
@@ -1606,7 +1624,7 @@ static int emac_dev_open(struct net_device *ndev)
1606 priv->phy_id = dev_name(phy); 1624 priv->phy_id = dev_name(phy);
1607 } 1625 }
1608 1626
1609 if (priv->phy_id && *priv->phy_id) { 1627 if (!priv->phydev && priv->phy_id && *priv->phy_id) {
1610 priv->phydev = phy_connect(ndev, priv->phy_id, 1628 priv->phydev = phy_connect(ndev, priv->phy_id,
1611 &emac_adjust_link, 1629 &emac_adjust_link,
1612 PHY_INTERFACE_MODE_MII); 1630 PHY_INTERFACE_MODE_MII);
@@ -1627,7 +1645,9 @@ static int emac_dev_open(struct net_device *ndev)
1627 "(mii_bus:phy_addr=%s, id=%x)\n", 1645 "(mii_bus:phy_addr=%s, id=%x)\n",
1628 priv->phydev->drv->name, dev_name(&priv->phydev->dev), 1646 priv->phydev->drv->name, dev_name(&priv->phydev->dev),
1629 priv->phydev->phy_id); 1647 priv->phydev->phy_id);
1630 } else { 1648 }
1649
1650 if (!priv->phydev) {
1631 /* No PHY , fix the link, speed and duplex settings */ 1651 /* No PHY , fix the link, speed and duplex settings */
1632 dev_notice(emac_dev, "no phy, defaulting to 100/full\n"); 1652 dev_notice(emac_dev, "no phy, defaulting to 100/full\n");
1633 priv->link = 1; 1653 priv->link = 1;
@@ -1724,6 +1744,15 @@ static struct net_device_stats *emac_dev_getnetstats(struct net_device *ndev)
1724 struct emac_priv *priv = netdev_priv(ndev); 1744 struct emac_priv *priv = netdev_priv(ndev);
1725 u32 mac_control; 1745 u32 mac_control;
1726 u32 stats_clear_mask; 1746 u32 stats_clear_mask;
1747 int err;
1748
1749 err = pm_runtime_get_sync(&priv->pdev->dev);
1750 if (err < 0) {
1751 pm_runtime_put_noidle(&priv->pdev->dev);
1752 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n",
1753 __func__, err);
1754 return &ndev->stats;
1755 }
1727 1756
1728 /* update emac hardware stats and reset the registers*/ 1757 /* update emac hardware stats and reset the registers*/
1729 1758
@@ -1766,6 +1795,8 @@ static struct net_device_stats *emac_dev_getnetstats(struct net_device *ndev)
1766 ndev->stats.tx_fifo_errors += emac_read(EMAC_TXUNDERRUN); 1795 ndev->stats.tx_fifo_errors += emac_read(EMAC_TXUNDERRUN);
1767 emac_write(EMAC_TXUNDERRUN, stats_clear_mask); 1796 emac_write(EMAC_TXUNDERRUN, stats_clear_mask);
1768 1797
1798 pm_runtime_put(&priv->pdev->dev);
1799
1769 return &ndev->stats; 1800 return &ndev->stats;
1770} 1801}
1771 1802
@@ -1859,7 +1890,7 @@ davinci_emac_of_get_pdata(struct platform_device *pdev, struct emac_priv *priv)
1859static int davinci_emac_probe(struct platform_device *pdev) 1890static int davinci_emac_probe(struct platform_device *pdev)
1860{ 1891{
1861 int rc = 0; 1892 int rc = 0;
1862 struct resource *res; 1893 struct resource *res, *res_ctrl;
1863 struct net_device *ndev; 1894 struct net_device *ndev;
1864 struct emac_priv *priv; 1895 struct emac_priv *priv;
1865 unsigned long hw_ram_addr; 1896 unsigned long hw_ram_addr;
@@ -1876,6 +1907,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
1876 return -EBUSY; 1907 return -EBUSY;
1877 } 1908 }
1878 emac_bus_frequency = clk_get_rate(emac_clk); 1909 emac_bus_frequency = clk_get_rate(emac_clk);
1910 devm_clk_put(&pdev->dev, emac_clk);
1879 1911
1880 /* TODO: Probe PHY here if possible */ 1912 /* TODO: Probe PHY here if possible */
1881 1913
@@ -1917,11 +1949,20 @@ static int davinci_emac_probe(struct platform_device *pdev)
1917 rc = PTR_ERR(priv->remap_addr); 1949 rc = PTR_ERR(priv->remap_addr);
1918 goto no_pdata; 1950 goto no_pdata;
1919 } 1951 }
1952
1953 res_ctrl = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1954 if (res_ctrl) {
1955 priv->ctrl_base =
1956 devm_ioremap_resource(&pdev->dev, res_ctrl);
1957 if (IS_ERR(priv->ctrl_base))
1958 goto no_pdata;
1959 } else {
1960 priv->ctrl_base = priv->remap_addr + pdata->ctrl_mod_reg_offset;
1961 }
1962
1920 priv->emac_base = priv->remap_addr + pdata->ctrl_reg_offset; 1963 priv->emac_base = priv->remap_addr + pdata->ctrl_reg_offset;
1921 ndev->base_addr = (unsigned long)priv->remap_addr; 1964 ndev->base_addr = (unsigned long)priv->remap_addr;
1922 1965
1923 priv->ctrl_base = priv->remap_addr + pdata->ctrl_mod_reg_offset;
1924
1925 hw_ram_addr = pdata->hw_ram_addr; 1966 hw_ram_addr = pdata->hw_ram_addr;
1926 if (!hw_ram_addr) 1967 if (!hw_ram_addr)
1927 hw_ram_addr = (u32 __force)res->start + pdata->ctrl_ram_offset; 1968 hw_ram_addr = (u32 __force)res->start + pdata->ctrl_ram_offset;
@@ -1980,12 +2021,22 @@ static int davinci_emac_probe(struct platform_device *pdev)
1980 ndev->ethtool_ops = &ethtool_ops; 2021 ndev->ethtool_ops = &ethtool_ops;
1981 netif_napi_add(ndev, &priv->napi, emac_poll, EMAC_POLL_WEIGHT); 2022 netif_napi_add(ndev, &priv->napi, emac_poll, EMAC_POLL_WEIGHT);
1982 2023
2024 pm_runtime_enable(&pdev->dev);
2025 rc = pm_runtime_get_sync(&pdev->dev);
2026 if (rc < 0) {
2027 pm_runtime_put_noidle(&pdev->dev);
2028 dev_err(&pdev->dev, "%s: failed to get_sync(%d)\n",
2029 __func__, rc);
2030 goto no_cpdma_chan;
2031 }
2032
1983 /* register the network device */ 2033 /* register the network device */
1984 SET_NETDEV_DEV(ndev, &pdev->dev); 2034 SET_NETDEV_DEV(ndev, &pdev->dev);
1985 rc = register_netdev(ndev); 2035 rc = register_netdev(ndev);
1986 if (rc) { 2036 if (rc) {
1987 dev_err(&pdev->dev, "error in register_netdev\n"); 2037 dev_err(&pdev->dev, "error in register_netdev\n");
1988 rc = -ENODEV; 2038 rc = -ENODEV;
2039 pm_runtime_put(&pdev->dev);
1989 goto no_cpdma_chan; 2040 goto no_cpdma_chan;
1990 } 2041 }
1991 2042
@@ -1995,9 +2046,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
1995 "(regs: %p, irq: %d)\n", 2046 "(regs: %p, irq: %d)\n",
1996 (void *)priv->emac_base_phys, ndev->irq); 2047 (void *)priv->emac_base_phys, ndev->irq);
1997 } 2048 }
1998 2049 pm_runtime_put(&pdev->dev);
1999 pm_runtime_enable(&pdev->dev);
2000 pm_runtime_resume(&pdev->dev);
2001 2050
2002 return 0; 2051 return 0;
2003 2052
@@ -2071,9 +2120,14 @@ static const struct emac_platform_data am3517_emac_data = {
2071 .hw_ram_addr = 0x01e20000, 2120 .hw_ram_addr = 0x01e20000,
2072}; 2121};
2073 2122
2123static const struct emac_platform_data dm816_emac_data = {
2124 .version = EMAC_VERSION_2,
2125};
2126
2074static const struct of_device_id davinci_emac_of_match[] = { 2127static const struct of_device_id davinci_emac_of_match[] = {
2075 {.compatible = "ti,davinci-dm6467-emac", }, 2128 {.compatible = "ti,davinci-dm6467-emac", },
2076 {.compatible = "ti,am3517-emac", .data = &am3517_emac_data, }, 2129 {.compatible = "ti,am3517-emac", .data = &am3517_emac_data, },
2130 {.compatible = "ti,dm816-emac", .data = &dm816_emac_data, },
2077 {}, 2131 {},
2078}; 2132};
2079MODULE_DEVICE_TABLE(of, davinci_emac_of_match); 2133MODULE_DEVICE_TABLE(of, davinci_emac_of_match);