build/patch/kernel/pine64-default/gmac-gpio-fix-for-orangepiwin-bpim64.patch

91 lines
2.3 KiB
Diff

diff --git a/drivers/net/ethernet/allwinner/sunxi-gmac.c b/drivers/net/ethernet/allwinner/sunxi-gmac.c
index e0cef7b..4aaff55
--- a/drivers/net/ethernet/allwinner/sunxi-gmac.c
+++ b/drivers/net/ethernet/allwinner/sunxi-gmac.c
@@ -30,11 +30,13 @@
#include <linux/regulator/consumer.h>
#include <linux/of_net.h>
#include <linux/io.h>
-
+#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <asm/io.h>
#include "sunxi-gmac.h"
+#define PHY_POWER_ON 1
#ifndef GMAC_CLK
#define GMAC_CLK "gmac"
#endif
@@ -158,6 +160,9 @@ struct geth_priv {
spinlock_t lock;
spinlock_t tx_lock;
+#ifdef PHY_POWER_ON
+ unsigned int power_on_gpio;
+#endif
};
#ifdef CONFIG_GETH_PHY_POWER
@@ -722,6 +727,38 @@ static const struct dev_pm_ops geth_pm_ops;
*
*
****************************************************************************/
+#ifdef PHY_POWER_ON
+void gmac_phy_power_on(struct geth_priv *priv)
+{
+ if (!priv)
+ return;
+
+ if (gpio_is_valid(priv->power_on_gpio)) {
+ printk("GPIO %d valid\n", priv->power_on_gpio);
+ gpio_request(priv->power_on_gpio, NULL);
+ gpio_direction_output(priv->power_on_gpio, 1);
+ __gpio_set_value(priv->power_on_gpio, 1);
+ mdelay(200);
+ } else {
+ printk("Request GPIO %d\n", priv->power_on_gpio);
+ __gpio_set_value(priv->power_on_gpio, 1);
+ mdelay(200);
+ }
+ printk("Current_V is : %d\n", __gpio_get_value(priv->power_on_gpio));
+}
+
+void gmac_phy_power_disable(struct geth_priv *priv)
+{
+ if (!priv)
+ return;
+
+ if (priv->power_on_gpio) {
+ __gpio_set_value(priv->power_on_gpio, 0);
+ }
+ printk("Current_V is : %d\n", __gpio_get_value(priv->power_on_gpio));
+ return;
+}
+#endif
static void geth_check_addr(struct net_device *ndev, unsigned char *mac)
{
int i;
@@ -859,6 +896,10 @@ static int geth_open(struct net_device *ndev)
struct geth_priv *priv = netdev_priv(ndev);
int ret = 0;
+#ifdef PHY_POWER_ON
+ gmac_phy_power_on(priv);
+#endif
+
ret = geth_power_on(priv);
if (ret) {
netdev_err(ndev, "Power on is failed\n");
@@ -1545,6 +1586,11 @@ static int geth_script_parse(struct platform_device *pdev)
if (priv->phy_ext == INT_PHY)
priv->phy_interface = PHY_INTERFACE_MODE_MII;
+
+#ifdef PHY_POWER_ON
+ priv->power_on_gpio = of_get_named_gpio(np, "phy_power_on", 0);
+#endif
+
#endif
if(!of_property_read_u32(np, "tx-delay", &value))
tx_delay = value;