* [PATCH, resend 2/3] gpiolib: append SFI helpers for GPIO API
2013-05-28 8:16 [PATCH, resend 1/3] sfi: fix compiler warnings Andy Shevchenko
@ 2013-05-28 8:16 ` Andy Shevchenko
2013-05-30 10:23 ` Andy Shevchenko
2013-05-28 8:16 ` [PATCH, resend 3/3] x86: mrst: move to generic SFI " Andy Shevchenko
2013-05-31 8:25 ` [PATCH, resend 1/3] sfi: fix compiler warnings Andy Shevchenko
2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2013-05-28 8:16 UTC (permalink / raw)
To: sfi-devel, Len Brown, linux-kernel
Cc: Andy Shevchenko, Grant Likely, Linus Walleij
To support some (legacy) firmwares and platforms let's make life easier for
their customers.
This patch extracts SFI GPIO API from arch/x86/platform/mrst/mrst.c.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Len Brown <len.brown@intel.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
---
drivers/gpio/Kconfig | 4 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpiolib-sfi.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/sfi/sfi_core.c | 7 +++++
include/linux/sfi_gpio.h | 27 ++++++++++++++++
5 files changed, 115 insertions(+)
create mode 100644 drivers/gpio/gpiolib-sfi.c
create mode 100644 include/linux/sfi_gpio.h
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 573c449..8e4b0b8 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -51,6 +51,10 @@ config OF_GPIO
def_bool y
depends on OF
+config GPIO_SFI
+ def_bool y
+ depends on SFI
+
config GPIO_ACPI
def_bool y
depends on ACPI
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 0cb2d65..63d2abd 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -5,6 +5,7 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
obj-$(CONFIG_GPIO_DEVRES) += devres.o
obj-$(CONFIG_GPIOLIB) += gpiolib.o
obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
+obj-$(CONFIG_GPIO_SFI) += gpiolib-sfi.o
obj-$(CONFIG_GPIO_ACPI) += gpiolib-acpi.o
# Device drivers. Generally keep list sorted alphabetically
diff --git a/drivers/gpio/gpiolib-sfi.c b/drivers/gpio/gpiolib-sfi.c
new file mode 100644
index 0000000..2f15a81
--- /dev/null
+++ b/drivers/gpio/gpiolib-sfi.c
@@ -0,0 +1,76 @@
+/*
+ * SFI helpers for GPIO API
+ *
+ * Copyright (C) 2013, Intel Corporation
+ * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
+ *
+ * Based on work done for Intel MID platforms (mrst.c)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#define pr_fmt(fmt) "SFI: GPIO: " fmt
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/export.h>
+#include <linux/sfi_gpio.h>
+#include <linux/sfi.h>
+
+static struct sfi_gpio_table_entry *sfi_gpio_table;
+static int sfi_gpio_num_entry;
+
+int sfi_get_gpio_by_name(const char *name)
+{
+ struct sfi_gpio_table_entry *pentry = sfi_gpio_table;
+ int i;
+
+ if (!pentry)
+ return -1;
+
+ for (i = 0; i < sfi_gpio_num_entry; i++, pentry++) {
+ if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
+ return pentry->pin_no;
+ }
+
+ return -1;
+}
+EXPORT_SYMBOL_GPL(sfi_get_gpio_by_name);
+
+static int __init sfi_gpio_parse(struct sfi_table_header *table)
+{
+ struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
+ struct sfi_gpio_table_entry *pentry;
+ int num, i;
+
+ if (sfi_gpio_table)
+ return 0;
+
+ num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
+ pentry = (struct sfi_gpio_table_entry *)sb->pentry;
+
+ sfi_gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
+ if (!sfi_gpio_table)
+ return -ENOMEM;
+
+ memcpy(sfi_gpio_table, pentry, num * sizeof(*pentry));
+ sfi_gpio_num_entry = num;
+
+ pr_debug("Pin info:\n");
+ for (i = 0; i < num; i++, pentry++)
+ pr_debug("[%2d] chip = %16.16s, name = %16.16s, pin=%d\n", i,
+ pentry->controller_name, pentry->pin_name,
+ pentry->pin_no);
+
+ return 0;
+}
+
+int __init sfi_gpio_init(void)
+{
+ return sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_gpio_parse);
+}
diff --git a/drivers/sfi/sfi_core.c b/drivers/sfi/sfi_core.c
index 296db7a..2828da0 100644
--- a/drivers/sfi/sfi_core.c
+++ b/drivers/sfi/sfi_core.c
@@ -67,6 +67,7 @@
#include <linux/acpi.h>
#include <linux/init.h>
#include <linux/sfi.h>
+#include <linux/sfi_gpio.h>
#include <linux/slab.h>
#include "sfi_core.h"
@@ -512,6 +513,12 @@ void __init sfi_init_late(void)
syst_va = sfi_map_memory(syst_pa, length);
sfi_acpi_init();
+
+ /*
+ * Parsing GPIO table first, since the DEVS table will need this table
+ * to map the pin name to the actual pin.
+ */
+ sfi_gpio_init();
}
/*
diff --git a/include/linux/sfi_gpio.h b/include/linux/sfi_gpio.h
new file mode 100644
index 0000000..ef7e497
--- /dev/null
+++ b/include/linux/sfi_gpio.h
@@ -0,0 +1,27 @@
+#ifndef _LINUX_SFI_GPIO_H_
+#define _LINUX_SFI_GPIO_H_
+
+#include <linux/errno.h>
+#include <linux/gpio.h>
+#include <linux/sfi.h>
+
+#ifdef CONFIG_GPIO_SFI
+
+int sfi_get_gpio_by_name(const char *name);
+int __init sfi_gpio_init(void);
+
+#else /* CONFIG_GPIO_SFI */
+
+static inline int sfi_get_gpio_by_name(const char *name);
+{
+ return -1;
+}
+
+static inline int __init sfi_gpio_init(void)
+{
+ return -ENODEV;
+}
+
+#endif /* CONFIG_GPIO_SFI */
+
+#endif /* _LINUX_SFI_GPIO_H_ */
--
1.8.2.rc0.22.gb3600c3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH, resend 3/3] x86: mrst: move to generic SFI GPIO API
2013-05-28 8:16 [PATCH, resend 1/3] sfi: fix compiler warnings Andy Shevchenko
2013-05-28 8:16 ` [PATCH, resend 2/3] gpiolib: append SFI helpers for GPIO API Andy Shevchenko
@ 2013-05-28 8:16 ` Andy Shevchenko
2013-05-30 10:23 ` Andy Shevchenko
2013-05-31 8:25 ` [PATCH, resend 1/3] sfi: fix compiler warnings Andy Shevchenko
2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2013-05-28 8:16 UTC (permalink / raw)
To: sfi-devel, Len Brown, linux-kernel; +Cc: Andy Shevchenko, H. Peter Anvin, x86
Let's use the common SFI helpers for GPIO API.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Len Brown <len.brown@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: x86@kernel.org
---
arch/x86/platform/mrst/mrst.c | 94 ++++++++++---------------------------------
1 file changed, 22 insertions(+), 72 deletions(-)
diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
index a0a0a43..9ba13d8 100644
--- a/arch/x86/platform/mrst/mrst.c
+++ b/arch/x86/platform/mrst/mrst.c
@@ -17,6 +17,7 @@
#include <linux/interrupt.h>
#include <linux/scatterlist.h>
#include <linux/sfi.h>
+#include <linux/sfi_gpio.h>
#include <linux/intel_pmic_gpio.h>
#include <linux/spi/spi.h>
#include <linux/i2c.h>
@@ -28,7 +29,6 @@
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/mfd/intel_msic.h>
-#include <linux/gpio.h>
#include <linux/i2c/tc35876x.h>
#include <asm/setup.h>
@@ -219,7 +219,7 @@ static unsigned long __init mrst_calibrate_tsc(void)
lapic_timer_frequency = fsb * 1000 / HZ;
/* mark tsc clocksource as reliable */
set_cpu_cap(&boot_cpu_data, X86_FEATURE_TSC_RELIABLE);
-
+
if (fast_calibrate)
return fast_calibrate;
@@ -338,55 +338,6 @@ static inline int __init setup_x86_mrst_timer(char *arg)
__setup("x86_mrst_timer=", setup_x86_mrst_timer);
/*
- * Parsing GPIO table first, since the DEVS table will need this table
- * to map the pin name to the actual pin.
- */
-static struct sfi_gpio_table_entry *gpio_table;
-static int gpio_num_entry;
-
-static int __init sfi_parse_gpio(struct sfi_table_header *table)
-{
- struct sfi_table_simple *sb;
- struct sfi_gpio_table_entry *pentry;
- int num, i;
-
- if (gpio_table)
- return 0;
- sb = (struct sfi_table_simple *)table;
- num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
- pentry = (struct sfi_gpio_table_entry *)sb->pentry;
-
- gpio_table = kmalloc(num * sizeof(*pentry), GFP_KERNEL);
- if (!gpio_table)
- return -1;
- memcpy(gpio_table, pentry, num * sizeof(*pentry));
- gpio_num_entry = num;
-
- pr_debug("GPIO pin info:\n");
- for (i = 0; i < num; i++, pentry++)
- pr_debug("info[%2d]: controller = %16.16s, pin_name = %16.16s,"
- " pin = %d\n", i,
- pentry->controller_name,
- pentry->pin_name,
- pentry->pin_no);
- return 0;
-}
-
-static int get_gpio_by_name(const char *name)
-{
- struct sfi_gpio_table_entry *pentry = gpio_table;
- int i;
-
- if (!pentry)
- return -1;
- for (i = 0; i < gpio_num_entry; i++, pentry++) {
- if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
- return pentry->pin_no;
- }
- return -1;
-}
-
-/*
* Here defines the array of devices platform data that IAFW would export
* through SFI "DEVS" table, we use name and type to match the device and
* its platform data.
@@ -404,7 +355,7 @@ struct devs_id {
static void __init *pmic_gpio_platform_data(void *info)
{
static struct intel_pmic_gpio_platform_data pmic_gpio_pdata;
- int gpio_base = get_gpio_by_name("pmic_gpio_base");
+ int gpio_base = sfi_get_gpio_by_name("pmic_gpio_base");
if (gpio_base == -1)
gpio_base = 64;
@@ -418,7 +369,7 @@ static void __init *pmic_gpio_platform_data(void *info)
static void __init *max3111_platform_data(void *info)
{
struct spi_board_info *spi_info = info;
- int intr = get_gpio_by_name("max3111_int");
+ int intr = sfi_get_gpio_by_name("max3111_int");
spi_info->mode = SPI_MODE_0;
if (intr == -1)
@@ -456,8 +407,8 @@ static void __init *max7315_platform_data(void *info)
strcpy(intr_pin_name, "max7315_int");
}
- gpio_base = get_gpio_by_name(base_pin_name);
- intr = get_gpio_by_name(intr_pin_name);
+ gpio_base = sfi_get_gpio_by_name(base_pin_name);
+ intr = sfi_get_gpio_by_name(intr_pin_name);
if (gpio_base == -1)
return NULL;
@@ -484,8 +435,8 @@ static void *tca6416_platform_data(void *info)
strcpy(base_pin_name, "tca6416_base");
strcpy(intr_pin_name, "tca6416_int");
- gpio_base = get_gpio_by_name(base_pin_name);
- intr = get_gpio_by_name(intr_pin_name);
+ gpio_base = sfi_get_gpio_by_name(base_pin_name);
+ intr = sfi_get_gpio_by_name(intr_pin_name);
if (gpio_base == -1)
return NULL;
@@ -503,7 +454,7 @@ static void *tca6416_platform_data(void *info)
static void *mpu3050_platform_data(void *info)
{
struct i2c_board_info *i2c_info = info;
- int intr = get_gpio_by_name("mpu3050_int");
+ int intr = sfi_get_gpio_by_name("mpu3050_int");
if (intr == -1)
return NULL;
@@ -516,8 +467,8 @@ static void __init *emc1403_platform_data(void *info)
{
static short intr2nd_pdata;
struct i2c_board_info *i2c_info = info;
- int intr = get_gpio_by_name("thermal_int");
- int intr2nd = get_gpio_by_name("thermal_alert");
+ int intr = sfi_get_gpio_by_name("thermal_int");
+ int intr2nd = sfi_get_gpio_by_name("thermal_alert");
if (intr == -1 || intr2nd == -1)
return NULL;
@@ -532,8 +483,8 @@ static void __init *lis331dl_platform_data(void *info)
{
static short intr2nd_pdata;
struct i2c_board_info *i2c_info = info;
- int intr = get_gpio_by_name("accel_int");
- int intr2nd = get_gpio_by_name("accel_2");
+ int intr = sfi_get_gpio_by_name("accel_int");
+ int intr2nd = sfi_get_gpio_by_name("accel_2");
if (intr == -1 || intr2nd == -1)
return NULL;
@@ -628,7 +579,7 @@ static void *msic_battery_platform_data(void *info)
static void *msic_gpio_platform_data(void *info)
{
static struct intel_msic_gpio_pdata pdata;
- int gpio = get_gpio_by_name("msic_gpio_base");
+ int gpio = sfi_get_gpio_by_name("msic_gpio_base");
if (gpio < 0)
return NULL;
@@ -660,7 +611,7 @@ static void *msic_power_btn_platform_data(void *info)
static void *msic_ocd_platform_data(void *info)
{
static struct intel_msic_ocd_pdata pdata;
- int gpio = get_gpio_by_name("ocd_gpio");
+ int gpio = sfi_get_gpio_by_name("ocd_gpio");
if (gpio < 0)
return NULL;
@@ -679,14 +630,14 @@ static void *msic_thermal_platform_data(void *info)
/* tc35876x DSI-LVDS bridge chip and panel platform data */
static void *tc35876x_platform_data(void *data)
{
- static struct tc35876x_platform_data pdata;
+ static struct tc35876x_platform_data pdata;
- /* gpio pins set to -1 will not be used by the driver */
- pdata.gpio_bridge_reset = get_gpio_by_name("LCMB_RXEN");
- pdata.gpio_panel_bl_en = get_gpio_by_name("6S6P_BL_EN");
- pdata.gpio_panel_vadd = get_gpio_by_name("EN_VREG_LCD_V3P3");
+ /* gpio pins set to -1 will not be used by the driver */
+ pdata.gpio_bridge_reset = sfi_get_gpio_by_name("LCMB_RXEN");
+ pdata.gpio_panel_bl_en = sfi_get_gpio_by_name("6S6P_BL_EN");
+ pdata.gpio_panel_vadd = sfi_get_gpio_by_name("EN_VREG_LCD_V3P3");
- return &pdata;
+ return &pdata;
}
static const struct devs_id __initconst device_ids[] = {
@@ -984,7 +935,6 @@ static int __init sfi_parse_devs(struct sfi_table_header *table)
static int __init mrst_platform_init(void)
{
- sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
sfi_table_parse(SFI_SIG_DEVS, NULL, NULL, sfi_parse_devs);
return 0;
}
@@ -1033,7 +983,7 @@ static int __init pb_keys_init(void)
num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
for (i = 0; i < num; i++) {
- gb[i].gpio = get_gpio_by_name(gb[i].desc);
+ gb[i].gpio = sfi_get_gpio_by_name(gb[i].desc);
pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc, gb[i].gpio);
if (gb[i].gpio == -1)
continue;
--
1.8.2.rc0.22.gb3600c3
^ permalink raw reply related [flat|nested] 6+ messages in thread