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/arch/arm/mach-msm/board-msm8960.c b/arch/arm/mach-msm/board-msm8960.c
index 9610e33..47f1592 100644
--- a/arch/arm/mach-msm/board-msm8960.c
+++ b/arch/arm/mach-msm/board-msm8960.c
@@ -38,6 +38,7 @@
#include <linux/leds-pm8xxx.h>
#include <linux/i2c/atmel_mxt_ts.h>
#include <linux/msm_tsens.h>
+#include <linux/ks8851.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
@@ -277,7 +278,7 @@
},
};
-#ifdef CONFIG_KS8851
+#if defined(CONFIG_KS8851) || defined(CONFIG_KS8851_MODULE)
static struct gpiomux_setting gpio_eth_config = {
.pull = GPIOMUX_PULL_NONE,
.drv = GPIOMUX_DRV_8MA,
@@ -292,7 +293,7 @@
};
struct msm_gpiomux_config msm8960_gpiomux_configs[NR_GPIO_IRQS] = {
-#ifdef CONFIG_KS8851
+#if defined(CONFIG_KS8851) || defined(CONFIG_KS8851_MODULE)
{
.gpio = KS8851_IRQ_GPIO,
.settings = {
@@ -3170,6 +3171,10 @@
.msm_apps_ipc_rpm_val = 4,
};
+static struct ks8851_pdata spi_eth_pdata = {
+ .irq_gpio = KS8851_IRQ_GPIO,
+ .rst_gpio = KS8851_RST_GPIO,
+};
static struct spi_board_info spi_board_info[] __initdata = {
{
@@ -3179,6 +3184,7 @@
.bus_num = 0,
.chip_select = 0,
.mode = SPI_MODE_0,
+ .platform_data = &spi_eth_pdata
},
};
@@ -3768,40 +3774,25 @@
},
};
-#ifdef CONFIG_KS8851
-static int ethernet_init(void)
+#if defined(CONFIG_KS8851) || defined(CONFIG_KS8851_MODULE)
+static int fpga_init(void)
{
int ret;
- ret = gpio_request(KS8851_IRQ_GPIO, "ks8851_irq");
- if (ret) {
- pr_err("ks8851 gpio_request failed: %d\n", ret);
- goto fail;
- }
-
- ret = gpio_request(KS8851_RST_GPIO, "ks8851_rst");
- if (ret) {
- pr_err("ks8851 gpio_request failed: %d\n", ret);
- goto fail_rst;
- }
ret = gpio_request(FPGA_CS_GPIO, "fpga_cs");
if (ret) {
- pr_err("ks8851 gpio_request failed: %d\n", ret);
- goto fail_cs;
+ pr_err("FPGA CS gpio_request failed: %d\n", ret);
+ goto fail;
}
gpio_direction_output(FPGA_CS_GPIO, 1);
- gpio_direction_output(KS8851_RST_GPIO, 1);
+
return 0;
-fail_cs:
- gpio_free(KS8851_RST_GPIO);
-fail_rst:
- gpio_free(KS8851_IRQ_GPIO);
fail:
return ret;
}
#else
-static int ethernet_init(void)
+static int fpga_init(void)
{
return 0;
}
@@ -4086,7 +4077,6 @@
msm8960_device_gadget_peripheral.dev.parent = &msm8960_device_otg.dev;
msm_device_hsusb_host.dev.parent = &msm8960_device_otg.dev;
gpiomux_init();
- ethernet_init();
msm8960_i2c_init();
msm_spm_init(msm_spm_data, ARRAY_SIZE(msm_spm_data));
msm_spm_l2_init(msm_spm_l2_data);
@@ -4119,7 +4109,6 @@
platform_device_register(&msm8960_device_rpm_regulator);
msm_clock_init(&msm8960_dummy_clock_init_data);
gpiomux_init();
- ethernet_init();
msm8960_device_ssbi_pm8921.dev.platform_data =
&msm8960_ssbi_pm8921_pdata;
pm8921_platform_data.num_regulators = msm_pm8921_regulator_pdata_len;
@@ -4162,7 +4151,8 @@
msm8960_device_gadget_peripheral.dev.parent = &msm8960_device_otg.dev;
msm_device_hsusb_host.dev.parent = &msm8960_device_otg.dev;
gpiomux_init();
- ethernet_init();
+ if (machine_is_msm8960_cdp())
+ fpga_init();
if (machine_is_msm8960_liquid())
pm8921_platform_data.keypad_pdata = &keypad_data_liquid;
msm8960_device_qup_spi_gsbi1.dev.platform_data =
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;
diff --git a/include/linux/ks8851.h b/include/linux/ks8851.h
new file mode 100644
index 0000000..6970f47
--- /dev/null
+++ b/include/linux/ks8851.h
@@ -0,0 +1,23 @@
+/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+/* struct ks8851_pdata - platform data definition for a KS8851 device
+ * @irq_gpio - GPIO pin number for the KS8851 IRQ line
+ * @rst_gpio - GPIO pin number for the KS8851 Reset line
+ *
+ * Platform data may be omitted (or individual GPIO numbers set to -1) to
+ * avoid doing any GPIO configuration in the driver.
+ */
+struct ks8851_pdata {
+ int irq_gpio;
+ int rst_gpio;
+};