public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
@ 2013-06-05 13:58 Andy Shevchenko
  2013-06-07  7:14 ` Linus Walleij
  2013-11-19  9:24 ` Linus Walleij
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2013-06-05 13:58 UTC (permalink / raw)
  To: Linus Walleij, Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel, David Cohen, Grant Likely
  Cc: Andy Shevchenko

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>
---
Since v1.1:
 - use container_of
 - switch to kmemdup

 drivers/gpio/Kconfig       |  4 +++
 drivers/gpio/Makefile      |  1 +
 drivers/gpio/gpiolib-sfi.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/sfi/sfi_core.c     |  7 +++++
 include/linux/sfi_gpio.h   | 27 ++++++++++++++++
 5 files changed, 116 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 f471fe8..a615d47 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..32e8605
--- /dev/null
+++ b/drivers/gpio/gpiolib-sfi.c
@@ -0,0 +1,77 @@
+/*
+ * Simple Firmware Interface (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 -EINVAL;
+
+	for (i = 0; i < sfi_gpio_num_entry; i++, pentry++) {
+		if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
+			return pentry->pin_no;
+	}
+
+	return -ENODEV;
+}
+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_gpio_table_entry *pentry;
+	int num, i;
+
+	if (sfi_gpio_table)
+		return 0;
+
+	sb = container_of(table, struct sfi_table_simple, header);
+
+	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
+	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
+
+	sfi_gpio_table = kmemdup(pentry, num * sizeof(*pentry), GFP_KERNEL);
+	if (!sfi_gpio_table)
+		return -ENOMEM;
+
+	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..02ae6df
--- /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 sfi_gpio_init(void);
+
+#else /* CONFIG_GPIO_SFI */
+
+static inline int sfi_get_gpio_by_name(const char *name);
+{
+	return -ENODEV;
+}
+
+static inline int 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] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-06-05 13:58 [PATCH v1.2] gpiolib: append SFI helpers for GPIO API Andy Shevchenko
@ 2013-06-07  7:14 ` Linus Walleij
  2013-11-19  9:24   ` Linus Walleij
  2013-11-19  9:24 ` Linus Walleij
  1 sibling, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2013-06-07  7:14 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, David Cohen, Grant Likely

On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> 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>
> ---
> Since v1.1:
>  - use container_of
>  - switch to kmemdup

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-06-05 13:58 [PATCH v1.2] gpiolib: append SFI helpers for GPIO API Andy Shevchenko
  2013-06-07  7:14 ` Linus Walleij
@ 2013-11-19  9:24 ` Linus Walleij
  2013-11-19  9:27   ` Alex Courbot
  1 sibling, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2013-11-19  9:24 UTC (permalink / raw)
  To: Andy Shevchenko, David Cohen, linux-gpio@vger.kernel.org,
	Alexandre Courbot
  Cc: Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, Grant Likely, Mika Westerberg

On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> 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>

So since this patch was ACKed the world has changed a bit and now
I want new changes (or maybe I was tired and not paying enough
attention at the time).

(...)
> +int sfi_get_gpio_by_name(const char *name)
> +{
> +       struct sfi_gpio_table_entry *pentry = sfi_gpio_table;
> +       int i;
> +
> +       if (!pentry)
> +               return -EINVAL;
> +
> +       for (i = 0; i < sfi_gpio_num_entry; i++, pentry++) {
> +               if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
> +                       return pentry->pin_no;
> +       }
> +
> +       return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(sfi_get_gpio_by_name);

Last merge window we merged the GPIO descriptor API and this
is now the recommended way to handle GPIOs and it is also
deployed into the ACPI and DT implementations.

So I'd like the signature of this function changed to return
a GPIO descriptor rather than an int so we don't stockpile more
stuff to refactor.

i.e.:
struct gpio_desc *sfi_get_gpio_by_name(const char *name);

 --- /dev/null
> +++ b/include/linux/sfi_gpio.h

Maybe that header could move to <linux/gpio/sfi.h> instead.
Alexandre what do you think?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-06-07  7:14 ` Linus Walleij
@ 2013-11-19  9:24   ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2013-11-19  9:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, David Cohen, Grant Likely

On Fri, Jun 7, 2013 at 9:14 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
>
>> 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>
>> ---
>> Since v1.1:
>>  - use container_of
>>  - switch to kmemdup
>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>

Consider this recalled.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-11-19  9:24 ` Linus Walleij
@ 2013-11-19  9:27   ` Alex Courbot
  2013-11-19 17:32     ` David Cohen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Courbot @ 2013-11-19  9:27 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko, David Cohen,
	linux-gpio@vger.kernel.org
  Cc: Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, Grant Likely, Mika Westerberg

On 11/19/2013 06:24 PM, Linus Walleij wrote:
> On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
>
>> 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>
>
> So since this patch was ACKed the world has changed a bit and now
> I want new changes (or maybe I was tired and not paying enough
> attention at the time).
>
> (...)
>> +int sfi_get_gpio_by_name(const char *name)
>> +{
>> +       struct sfi_gpio_table_entry *pentry = sfi_gpio_table;
>> +       int i;
>> +
>> +       if (!pentry)
>> +               return -EINVAL;
>> +
>> +       for (i = 0; i < sfi_gpio_num_entry; i++, pentry++) {
>> +               if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
>> +                       return pentry->pin_no;
>> +       }
>> +
>> +       return -ENODEV;
>> +}
>> +EXPORT_SYMBOL_GPL(sfi_get_gpio_by_name);
>
> Last merge window we merged the GPIO descriptor API and this
> is now the recommended way to handle GPIOs and it is also
> deployed into the ACPI and DT implementations.
>
> So I'd like the signature of this function changed to return
> a GPIO descriptor rather than an int so we don't stockpile more
> stuff to refactor.
>
> i.e.:
> struct gpio_desc *sfi_get_gpio_by_name(const char *name);
>
>   --- /dev/null
>> +++ b/include/linux/sfi_gpio.h
>
> Maybe that header could move to <linux/gpio/sfi.h> instead.
> Alexandre what do you think?

Agreed - all the GPIO drivers into drivers/gpio, all the headers into 
include/linux/gpio. Logical. :)

Alex.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-11-19  9:27   ` Alex Courbot
@ 2013-11-19 17:32     ` David Cohen
  2013-11-20 12:55       ` Andy Shevchenko
  2013-11-20 14:36       ` Andy Shevchenko
  0 siblings, 2 replies; 8+ messages in thread
From: David Cohen @ 2013-11-19 17:32 UTC (permalink / raw)
  To: Alex Courbot, Andy Shevchenko
  Cc: Linus Walleij, linux-gpio@vger.kernel.org,
	Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, Grant Likely, Mika Westerberg

On 11/19/2013 01:27 AM, Alex Courbot wrote:
> On 11/19/2013 06:24 PM, Linus Walleij wrote:
>> On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
>> <andriy.shevchenko@linux.intel.com> wrote:
>>
>>> 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>
>>
>> So since this patch was ACKed the world has changed a bit and now
>> I want new changes (or maybe I was tired and not paying enough
>> attention at the time).

Agreed. Even my e-mail was outdated :)
Updating from david.a.cohen@intel.com to david.a.cohen@linux.intel.com
to avoid M$ servers.

>>
>> (...)
>>> +int sfi_get_gpio_by_name(const char *name)
>>> +{
>>> +       struct sfi_gpio_table_entry *pentry = sfi_gpio_table;
>>> +       int i;
>>> +
>>> +       if (!pentry)
>>> +               return -EINVAL;
>>> +
>>> +       for (i = 0; i < sfi_gpio_num_entry; i++, pentry++) {
>>> +               if (!strncmp(name, pentry->pin_name, SFI_NAME_LEN))
>>> +                       return pentry->pin_no;
>>> +       }
>>> +
>>> +       return -ENODEV;
>>> +}
>>> +EXPORT_SYMBOL_GPL(sfi_get_gpio_by_name);
>>
>> Last merge window we merged the GPIO descriptor API and this
>> is now the recommended way to handle GPIOs and it is also
>> deployed into the ACPI and DT implementations.
>>
>> So I'd like the signature of this function changed to return
>> a GPIO descriptor rather than an int so we don't stockpile more
>> stuff to refactor.
>>
>> i.e.:
>> struct gpio_desc *sfi_get_gpio_by_name(const char *name);
>>
>>   --- /dev/null
>>> +++ b/include/linux/sfi_gpio.h
>>
>> Maybe that header could move to <linux/gpio/sfi.h> instead.
>> Alexandre what do you think?
>
> Agreed - all the GPIO drivers into drivers/gpio, all the headers into
> include/linux/gpio. Logical. :)

Sounds nice.
Andy, would you like to update the patch or should I go ahead and
resend it myself?

Br, David Cohen

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-11-19 17:32     ` David Cohen
@ 2013-11-20 12:55       ` Andy Shevchenko
  2013-11-20 14:36       ` Andy Shevchenko
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2013-11-20 12:55 UTC (permalink / raw)
  To: David Cohen
  Cc: Alex Courbot, Linus Walleij, linux-gpio@vger.kernel.org,
	Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, Grant Likely, Mika Westerberg

On Tue, 2013-11-19 at 09:32 -0800, David Cohen wrote:

[]

> >> Maybe that header could move to <linux/gpio/sfi.h> instead.
> >> Alexandre what do you think?
> >
> > Agreed - all the GPIO drivers into drivers/gpio, all the headers into
> > include/linux/gpio. Logical. :)
> 
> Sounds nice.
> Andy, would you like to update the patch or should I go ahead and
> resend it myself?

I already had done this, but I can't check since linux-next is broken
for me. Once I tried it I send it here.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1.2] gpiolib: append SFI helpers for GPIO API
  2013-11-19 17:32     ` David Cohen
  2013-11-20 12:55       ` Andy Shevchenko
@ 2013-11-20 14:36       ` Andy Shevchenko
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2013-11-20 14:36 UTC (permalink / raw)
  To: David Cohen
  Cc: Alex Courbot, Linus Walleij, linux-gpio@vger.kernel.org,
	Sathyanarayanan Kuppuswamy, Len Brown,
	linux-kernel@vger.kernel.org, Grant Likely, Mika Westerberg

On Tue, 2013-11-19 at 09:32 -0800, David Cohen wrote:
> On 11/19/2013 01:27 AM, Alex Courbot wrote:
> > On 11/19/2013 06:24 PM, Linus Walleij wrote:
> >> On Wed, Jun 5, 2013 at 3:58 PM, Andy Shevchenko
> >> <andriy.shevchenko@linux.intel.com> wrote:
> >>
> >>> 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>
> >>
> >> So since this patch was ACKed the world has changed a bit and now
> >> I want new changes (or maybe I was tired and not paying enough
> >> attention at the time).
> 
> Agreed. Even my e-mail was outdated :)
> Updating from david.a.cohen@intel.com to david.a.cohen@linux.intel.com
> to avoid M$ servers.

Just sent a version, though, sorry, I forgot to update your email there.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-11-20 14:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-05 13:58 [PATCH v1.2] gpiolib: append SFI helpers for GPIO API Andy Shevchenko
2013-06-07  7:14 ` Linus Walleij
2013-11-19  9:24   ` Linus Walleij
2013-11-19  9:24 ` Linus Walleij
2013-11-19  9:27   ` Alex Courbot
2013-11-19 17:32     ` David Cohen
2013-11-20 12:55       ` Andy Shevchenko
2013-11-20 14:36       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox