Skip to contentSkip to conversation

gpiolib, sfi: introduce SFI GPIO helpers

PATCH Superseded Andy Shevchenko 3 participants 6 messages Dec 9, 2013 – Dec 10, 2013 GPIO

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover gpiolib, sfi: introduce SFI GPIO helpers

Here is a fifth [1] version of the SFI GPIO helpers. This series contains SFI GPIO helpers along with the update of GPIO library to lookup for SFI resources.

It has been tested on Medfield device on top of recent linux-gpio/for-next + Mika's ACPI gpio patches [2].

Changes since v4:
- fix one compilation warning

[1] https://lkml.org/lkml/2013/6/5/316
[2] http://www.spinics.net/lists/linux-acpi/msg47572.html

Andy Shevchenko (2):
SFI: store GPIO table and export lookup function
gpiolib: append SFI helpers for GPIO API

 drivers/gpio/Kconfig       |   4 ++
 drivers/gpio/Makefile      |   1 +
 drivers/gpio/gpiolib-sfi.c |  27 ++++++++++
 drivers/gpio/gpiolib.c     |   3 ++
 drivers/gpio/gpiolib.h     |  13 +++++
 drivers/sfi/Makefile       |   2 +-
 drivers/sfi/sfi_core.c     |   6 +++
 drivers/sfi/sfi_core.h     |   3 ++
 drivers/sfi/sfi_gpio.c     | 121 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sfi.h        |  10 ++++
 10 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpio/gpiolib-sfi.c
 create mode 100644 drivers/sfi/sfi_gpio.c
Signature · 1 line
1.8.4.4
#1 lore raw

PATCH v5 1/2 SFI: store GPIO table and export lookup function

We have to provide a mechanism to retrive GPIO information from SFI. For this we store SFI GPIO table and provide the lookup function sfi_gpio_get_entry_by_name() that will be used later in GPIO framework.

---
 drivers/sfi/Makefile   |   2 +-
 drivers/sfi/sfi_core.c |   6 +++
 drivers/sfi/sfi_core.h |   3 ++
 drivers/sfi/sfi_gpio.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sfi.h    |  10 ++++
 5 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 drivers/sfi/sfi_gpio.c
drivers/sfi/Makefile +1 -1
index 2343732..dc011db 100644
@@ -1,3 +1,3 @@
 obj-y	+= sfi_acpi.o
 obj-y	+= sfi_core.o
-
+obj-y	+= sfi_gpio.o
drivers/sfi/sfi_core.c +6 -0
index 296db7a..e9ff6f0 100644
@@ -512,6 +512,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();
 }
 
 /*
drivers/sfi/sfi_core.h +3 -0
index 1d5cfe8..18c663d 100644
@@ -79,3 +79,6 @@ struct sfi_table_header *sfi_get_table(struct sfi_table_key *key);
 extern void sfi_put_table(struct sfi_table_header *table);
 extern struct sfi_table_attr __init *sfi_sysfs_install_table(u64 pa);
 extern void __init sfi_acpi_sysfs_init(void);
+
+/* sfi_gpio.c */
+int sfi_gpio_init(void);
drivers/sfi/sfi_gpio.c new file +121 -0

121 lines not on this page · raw message

include/linux/sfi.h +10 -0
index d9b436f..4a9432f 100644
@@ -61,6 +61,8 @@
 
 #include <linux/init.h>
 #include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/err.h>
 
 /* Table signatures reserved by the SFI specification */
 #define SFI_SIG_SYST		"SYST"
@@ -185,6 +187,8 @@ static inline void disable_sfi(void)
 	sfi_disabled = 1;
 }
 
+struct sfi_gpio_table_entry *sfi_gpio_get_entry_by_name(const char *name);
+
 #else /* !CONFIG_SFI */
 
 static inline void sfi_init(void)
@@ -204,6 +208,12 @@ static inline int sfi_table_parse(char *signature, char *oem_id,
 	return -1;
 }
 
+static inline
+struct sfi_gpio_table_entry *sfi_gpio_get_entry_by_name(const char *name)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 #endif /* !CONFIG_SFI */
 
 #endif /*_LINUX_SFI_H*/
Signature · 1 line
1.8.4.4
#2 lore raw

Re: [PATCH v5 1/2] SFI: store GPIO table and export lookup function

Quoted 72 lines · Andy Shevchenko

We have to provide a mechanism to retrive GPIO information from SFI. For this we store SFI GPIO table and provide the lookup function sfi_gpio_get_entry_by_name() that will be used later in GPIO framework.

---
  drivers/sfi/Makefile   |   2 +-
  drivers/sfi/sfi_core.c |   6 +++
  drivers/sfi/sfi_core.h |   3 ++
  drivers/sfi/sfi_gpio.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++
  include/linux/sfi.h    |  10 ++++
  5 files changed, 141 insertions(+), 1 deletion(-)

create mode 100644 drivers/sfi/sfi_gpio.c

drivers/sfi/Makefile +1 -1
index 2343732..dc011db 100644
@@ -1,3 +1,3 @@
  obj-y	+= sfi_acpi.o
  obj-y	+= sfi_core.o
-
+obj-y	+= sfi_gpio.o
drivers/sfi/sfi_core.c +6 -0
index 296db7a..e9ff6f0 100644
@@ -512,6 +512,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();
  }
 
  /*
drivers/sfi/sfi_core.h +3 -0
index 1d5cfe8..18c663d 100644
@@ -79,3 +79,6 @@ struct sfi_table_header *sfi_get_table(struct sfi_table_key *key);
  extern void sfi_put_table(struct sfi_table_header *table);
  extern struct sfi_table_attr __init *sfi_sysfs_install_table(u64 pa);
  extern void __init sfi_acpi_sysfs_init(void);
+
+/* sfi_gpio.c */
+int sfi_gpio_init(void);
drivers/sfi/sfi_gpio.c new file +15 -0
new file mode 100644
index 0000000..22627a1
@@ -0,0 +1,121 @@
+/* sfi_gpio.c Simple Firmware Interface - GPIO extensions */
+
+/*
+
+  This file is provided under a dual BSD/GPLv2 license.  When using or
+  redistributing this file, you may do so under either license.
+
+  GPL LICENSE SUMMARY
+
+  Copyright(c) 2013 Intel Corporation. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of version 2 of the GNU General Public License as
+  published by the Free Software Foundation.
+

drivers/sfi/sfi_gpio.c line 25

Quoted 10 lines
drivers/sfi/sfi_gpio.c new file +10 -0
+  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.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+  The full GNU General Public License is included in this distribution
+  in the file called LICENSE.GPL.

FSF address is still here - please remove the last paragraph in the next version.

#3 lore raw

PATCH v5 2/2 gpiolib: append SFI helpers for GPIO API

In reply to Andy Shevchenko

To support some (legacy) firmwares and platforms let's make life easier for their customers.

This patch provides a function which converts sfi_gpio_table_entry to gpio_desc. The use of it is integrated into GPIO library to enable generic access to the SFI GPIO resources.

---
 drivers/gpio/Kconfig       |  4 ++++
 drivers/gpio/Makefile      |  1 +
 drivers/gpio/gpiolib-sfi.c | 27 +++++++++++++++++++++++++++
 drivers/gpio/gpiolib.c     |  3 +++
 drivers/gpio/gpiolib.h     | 13 +++++++++++++
 5 files changed, 48 insertions(+)
 create mode 100644 drivers/gpio/gpiolib-sfi.c
drivers/gpio/Kconfig +4 -0
index ae3682d..a12752a 100644
@@ -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
drivers/gpio/Makefile +1 -0
index ee95154..5373e3a 100644
@@ -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
drivers/gpio/gpiolib-sfi.c new file +27 -0
new file mode 100644
index 0000000..7531624
@@ -0,0 +1,27 @@
+/*
+ * Simple Firmware Interface (SFI) helpers for GPIO API
+ *
+ * Copyright (C) 2013, Intel Corporation
+ * Author: Andy Shevchenko <[email protected]>
+ *
+ * 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.
+ */
+
+#include <linux/gpio/consumer.h>
+#include <linux/sfi.h>
+#include <linux/err.h>
+
+#include "gpiolib.h"
+
+struct gpio_desc *sfi_get_gpiod_by_name(const char *name)
+{
+	struct sfi_gpio_table_entry *pentry;
+
+	pentry = sfi_gpio_get_entry_by_name(name);
+	if (IS_ERR(pentry))
+		return ERR_CAST(pentry);
+
+	return gpio_to_desc(pentry->pin_no);
+}
drivers/gpio/gpiolib.c +3 -0
index d2ffdfe..7575c51 100644
@@ -2452,6 +2452,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
 	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
 		dev_dbg(dev, "using ACPI for GPIO lookup\n");
 		desc = acpi_find_gpio(dev, con_id, idx, &flags);
+	} else if (IS_ENABLED(CONFIG_SFI)) {
+		dev_dbg(dev, "using SFI for GPIO lookup\n");
+		desc = sfi_get_gpiod_by_name(con_id);
 	}
 
 	/*
drivers/gpio/gpiolib.h +13 -0
index 82be586..ca0615a 100644
@@ -43,4 +43,17 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
 }
 #endif
 
+#ifdef CONFIG_GPIO_SFI
+
+struct gpio_desc *sfi_get_gpiod_by_name(const char *name);
+
+#else /* !CONFIG_GPIO_SFI */
+
+static inline struct gpio_desc *sfi_get_gpiod_by_name(const char *name)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+#endif /* !CONFIG_GPIO_SFI */
+
 #endif /* GPIOLIB_H */
Signature · 1 line
1.8.4.4
Reviewed-by on the v5 series
#4 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

Here is a fifth [1] version of the SFI GPIO helpers. This series contains SFI GPIO helpers along with the update of GPIO library to lookup for SFI resources.

It has been tested on Medfield device on top of recent linux-gpio/for-next + Mika's ACPI gpio patches [2].

Changes since v4:
- fix one compilation warning

Quoted 7 lines

[1] https://lkml.org/lkml/2013/6/5/316
[2] http://www.spinics.net/lists/linux-acpi/msg47572.html

Andy Shevchenko (2):
SFI: store GPIO table and export lookup function
gpiolib: append SFI helpers for GPIO API

Both patches,

#5 lore raw
In reply to Andy Shevchenko
Quoted 11 lines · Andy Shevchenko

Here is a fifth [1] version of the SFI GPIO helpers. This series contains SFI GPIO helpers along with the update of GPIO library to lookup for SFI resources.

It has been tested on Medfield device on top of recent linux-gpio/for-next + Mika's ACPI gpio patches [2].

Changes since v4:
- fix one compilation warning

[1] https://lkml.org/lkml/2013/6/5/316
[2] http://www.spinics.net/lists/linux-acpi/msg47572.html

I commented on the v1 of this series about a potential lookup issue - while I totally agree with the overall idea, I'd like to see this issue solved before I give my ack.