ks8851: Add GPIO configuration platform data

Add platform data for the KS8851 SPI Ethernet device to
enable proper GPIO configuration for the reset and
interrupt pins.

Change-Id: I79adae4628f38a2ca5bc17825258c41ab5e1623d
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
diff --git a/drivers/net/ks8851.c b/drivers/net/ks8851.c
index 8e4f4ff..74b6ac2 100644
--- a/drivers/net/ks8851.c
+++ b/drivers/net/ks8851.c
@@ -23,6 +23,8 @@
 #include <linux/mii.h>
 #include <linux/regulator/consumer.h>
 #include <linux/spi/spi.h>
+#include <linux/ks8851.h>
+#include <linux/gpio.h>
 
 #include "ks8851.h"
 
@@ -1587,6 +1589,7 @@
 
 static int __devinit ks8851_probe(struct spi_device *spi)
 {
+	struct ks8851_pdata *pdata = spi->dev.platform_data;
 	struct net_device *ndev;
 	struct ks8851_net *ks;
 	int ret;
@@ -1610,6 +1613,23 @@
 	if (!IS_ERR(ks->vdd_phy))
 		regulator_enable(ks->vdd_phy);
 
+	if (pdata && gpio_is_valid(pdata->irq_gpio)) {
+		ret = gpio_request(pdata->irq_gpio, "ks8851_irq");
+		if (ret) {
+			pr_err("ks8851 gpio_request failed: %d\n", ret);
+			goto err_irq_gpio;
+		}
+	}
+
+	if (pdata && gpio_is_valid(pdata->rst_gpio)) {
+		ret = gpio_request(pdata->rst_gpio, "ks8851_rst");
+		if (ret) {
+			pr_err("ks8851 gpio_request failed: %d\n", ret);
+			goto err_rst_gpio;
+		}
+		gpio_direction_output(pdata->rst_gpio, 1);
+	}
+
 	ks->netdev = ndev;
 	ks->spidev = spi;
 	ks->tx_space = 6144;
@@ -1714,12 +1734,22 @@
 		regulator_disable(ks->vdd_phy);
 		regulator_put(ks->vdd_phy);
 	}
+
+	if (pdata && gpio_is_valid(pdata->rst_gpio))
+		gpio_free(pdata->rst_gpio);
+
+err_rst_gpio:
+	if (pdata && gpio_is_valid(pdata->irq_gpio))
+		gpio_free(pdata->irq_gpio);
+
+err_irq_gpio:
 	return ret;
 }
 
 static int __devexit ks8851_remove(struct spi_device *spi)
 {
 	struct ks8851_net *priv = dev_get_drvdata(&spi->dev);
+	struct ks8851_pdata *pdata = spi->dev.platform_data;
 
 	if (netif_msg_drv(priv))
 		dev_info(&spi->dev, "remove\n");
@@ -1736,6 +1766,13 @@
 
 	unregister_netdev(priv->netdev);
 	free_irq(spi->irq, priv);
+
+	if (pdata && gpio_is_valid(pdata->irq_gpio))
+		gpio_free(pdata->irq_gpio);
+
+	if (pdata && gpio_is_valid(pdata->rst_gpio))
+		gpio_free(pdata->rst_gpio);
+
 	free_netdev(priv->netdev);
 
 	return 0;