From: Ryan Mallon <rmallon@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>,
Grant Likely <grant.likely@secretlab.ca>,
Len Brown <lenb@kernel.org>,
linux-kernel@vger.kernel.org,
David Cohen <david.a.cohen@intel.com>,
Grant Likely <grant.likely@linaro.org>
Subject: Re: [PATCH v1.1] gpiolib: append SFI helpers for GPIO API
Date: Mon, 03 Jun 2013 11:59:21 +1000 [thread overview]
Message-ID: <51ABF879.1090509@gmail.com> (raw)
In-Reply-To: <1369992439-5421-1-git-send-email-andriy.shevchenko@linux.intel.com>
On 31/05/13 19:27, Andy Shevchenko 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:
> - address Linus' comments: self-descriptive error codes, removal of __init in
> header, better title in c-file.
Hi Andy,
Some trivial coding style comment below.
~Ryan
>
> 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 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..cccdc0f
> --- /dev/null
> +++ b/drivers/gpio/gpiolib-sfi.c
> @@ -0,0 +1,76 @@
> +/*
> + * 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;
> + }
Nitpick - Don't need the braces on the for loop.
> +
> + 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_table_simple *)table;
Using container_of is preferable to casting:
sb = container_of(table, struct sfi_table_simple, header);
> + 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);
Use kcalloc when you have a size and a count.
> + 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);
Why "%16.16s" here? "%16s" will right justify with leading spaces, or
"%-16s" will left justify with trailing spaces.
> +
> + 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_ */
>
next prev parent reply other threads:[~2013-06-03 1:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-30 2:45 [PATCH v1 00/13] mrst refactoring patches Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 01/13] mrst: Fixed printk/pr_* related issues Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 02/13] mrst: Fixed indentation issues Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 03/13] mrst: Fixed checkpatch warnings Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 04/13] intel_mid: Renamed *mrst* to *intel_mid* Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 05/13] " Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 06/13] intel_mid: Refactored sfi_parse_devs() function Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 07/13] intel_mid: Added custom device_handler support Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 08/13] intel_mid: Added custom handler for ipc devices Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 09/13] intel_mid: Moved board related code to a new file Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 10/13] intel_mid: Moved SFI related code to intel_mid_sfi.c Sathyanarayanan Kuppuswamy
2013-05-30 2:45 ` [PATCH v1 11/13] sfi: fix compiler warnings Sathyanarayanan Kuppuswamy
2013-05-31 8:24 ` Andy Shevchenko
2013-05-30 2:45 ` [PATCH v1 12/13] gpiolib: append SFI helpers for GPIO API Sathyanarayanan Kuppuswamy
2013-05-30 18:44 ` Linus Walleij
2013-05-31 9:27 ` [PATCH v1.1] " Andy Shevchenko
2013-06-03 1:59 ` Ryan Mallon [this message]
2013-06-03 2:06 ` Joe Perches
2013-06-03 8:16 ` Andy Shevchenko
2013-06-03 12:26 ` Joe Perches
2013-06-05 13:41 ` Andy Shevchenko
2013-06-03 7:03 ` Linus Walleij
2013-05-30 2:45 ` [PATCH v1 13/13] x86: mrst: move to generic SFI " Sathyanarayanan Kuppuswamy
2013-05-31 8:39 ` [PATCH v1 00/13] mrst refactoring patches Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51ABF879.1090509@gmail.com \
--to=rmallon@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=david.a.cohen@intel.com \
--cc=grant.likely@linaro.org \
--cc=grant.likely@secretlab.ca \
--cc=lenb@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sathyanarayanan.kuppuswamy@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.