2010-01-30 02:20:30 +08:00
|
|
|
/*
|
2011-06-05 08:38:28 +08:00
|
|
|
* gpiolib support for Wolfson WM8994
|
2010-01-30 02:20:30 +08:00
|
|
|
*
|
|
|
|
* Copyright 2009 Wolfson Microelectronics PLC.
|
|
|
|
*
|
|
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-01-30 02:20:30 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/mfd/core.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/seq_file.h>
|
2012-06-03 20:40:19 +08:00
|
|
|
#include <linux/regmap.h>
|
2010-01-30 02:20:30 +08:00
|
|
|
|
|
|
|
#include <linux/mfd/wm8994/core.h>
|
|
|
|
#include <linux/mfd/wm8994/pdata.h>
|
|
|
|
#include <linux/mfd/wm8994/gpio.h>
|
|
|
|
#include <linux/mfd/wm8994/registers.h>
|
|
|
|
|
|
|
|
struct wm8994_gpio {
|
|
|
|
struct wm8994 *wm8994;
|
|
|
|
struct gpio_chip gpio_chip;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct wm8994_gpio *to_wm8994_gpio(struct gpio_chip *chip)
|
|
|
|
{
|
|
|
|
return container_of(chip, struct wm8994_gpio, gpio_chip);
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:47:16 +08:00
|
|
|
static int wm8994_gpio_request(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
|
|
|
|
switch (wm8994->type) {
|
|
|
|
case WM8958:
|
|
|
|
switch (offset) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-30 02:20:30 +08:00
|
|
|
static int wm8994_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
|
|
|
|
return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
|
|
|
|
WM8994_GPN_DIR, WM8994_GPN_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wm8994_gpio_get(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = wm8994_reg_read(wm8994, WM8994_GPIO_1 + offset);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (ret & WM8994_GPN_LVL)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wm8994_gpio_direction_out(struct gpio_chip *chip,
|
|
|
|
unsigned offset, int value)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
|
2012-06-09 11:07:56 +08:00
|
|
|
if (value)
|
|
|
|
value = WM8994_GPN_LVL;
|
|
|
|
|
2010-01-30 02:20:30 +08:00
|
|
|
return wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset,
|
2012-06-09 11:07:56 +08:00
|
|
|
WM8994_GPN_DIR | WM8994_GPN_LVL, value);
|
2010-01-30 02:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
value = WM8994_GPN_LVL;
|
|
|
|
|
|
|
|
wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, WM8994_GPN_LVL, value);
|
|
|
|
}
|
|
|
|
|
2010-04-02 21:51:59 +08:00
|
|
|
static int wm8994_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
|
2012-06-03 20:40:19 +08:00
|
|
|
return regmap_irq_get_virq(wm8994->irq_data, offset);
|
2010-04-02 21:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 02:20:30 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
2011-12-08 00:24:01 +08:00
|
|
|
static const char *wm8994_gpio_fn(u16 fn)
|
|
|
|
{
|
|
|
|
switch (fn) {
|
|
|
|
case WM8994_GP_FN_PIN_SPECIFIC:
|
|
|
|
return "pin-specific";
|
|
|
|
case WM8994_GP_FN_GPIO:
|
|
|
|
return "GPIO";
|
|
|
|
case WM8994_GP_FN_SDOUT:
|
|
|
|
return "SDOUT";
|
|
|
|
case WM8994_GP_FN_IRQ:
|
|
|
|
return "IRQ";
|
|
|
|
case WM8994_GP_FN_TEMPERATURE:
|
|
|
|
return "Temperature";
|
|
|
|
case WM8994_GP_FN_MICBIAS1_DET:
|
|
|
|
return "MICBIAS1 detect";
|
|
|
|
case WM8994_GP_FN_MICBIAS1_SHORT:
|
|
|
|
return "MICBIAS1 short";
|
|
|
|
case WM8994_GP_FN_MICBIAS2_DET:
|
|
|
|
return "MICBIAS2 detect";
|
|
|
|
case WM8994_GP_FN_MICBIAS2_SHORT:
|
|
|
|
return "MICBIAS2 short";
|
|
|
|
case WM8994_GP_FN_FLL1_LOCK:
|
|
|
|
return "FLL1 lock";
|
|
|
|
case WM8994_GP_FN_FLL2_LOCK:
|
|
|
|
return "FLL2 lock";
|
|
|
|
case WM8994_GP_FN_SRC1_LOCK:
|
|
|
|
return "SRC1 lock";
|
|
|
|
case WM8994_GP_FN_SRC2_LOCK:
|
|
|
|
return "SRC2 lock";
|
|
|
|
case WM8994_GP_FN_DRC1_ACT:
|
|
|
|
return "DRC1 activity";
|
|
|
|
case WM8994_GP_FN_DRC2_ACT:
|
|
|
|
return "DRC2 activity";
|
|
|
|
case WM8994_GP_FN_DRC3_ACT:
|
|
|
|
return "DRC3 activity";
|
|
|
|
case WM8994_GP_FN_WSEQ_STATUS:
|
|
|
|
return "Write sequencer";
|
|
|
|
case WM8994_GP_FN_FIFO_ERROR:
|
|
|
|
return "FIFO error";
|
|
|
|
case WM8994_GP_FN_OPCLK:
|
|
|
|
return "OPCLK";
|
|
|
|
case WM8994_GP_FN_THW:
|
|
|
|
return "Thermal warning";
|
|
|
|
case WM8994_GP_FN_DCS_DONE:
|
|
|
|
return "DC servo";
|
|
|
|
case WM8994_GP_FN_FLL1_OUT:
|
|
|
|
return "FLL1 output";
|
|
|
|
case WM8994_GP_FN_FLL2_OUT:
|
|
|
|
return "FLL1 output";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-30 02:20:30 +08:00
|
|
|
static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
|
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
|
|
|
|
struct wm8994 *wm8994 = wm8994_gpio->wm8994;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < chip->ngpio; i++) {
|
|
|
|
int gpio = i + chip->base;
|
|
|
|
int reg;
|
|
|
|
const char *label;
|
|
|
|
|
|
|
|
/* We report the GPIO even if it's not requested since
|
|
|
|
* we're also reporting things like alternate
|
|
|
|
* functions which apply even when the GPIO is not in
|
|
|
|
* use as a GPIO.
|
|
|
|
*/
|
|
|
|
label = gpiochip_is_requested(chip, i);
|
|
|
|
if (!label)
|
|
|
|
label = "Unrequested";
|
|
|
|
|
|
|
|
seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label);
|
|
|
|
|
|
|
|
reg = wm8994_reg_read(wm8994, WM8994_GPIO_1 + i);
|
|
|
|
if (reg < 0) {
|
|
|
|
dev_err(wm8994->dev,
|
|
|
|
"GPIO control %d read failed: %d\n",
|
|
|
|
gpio, reg);
|
|
|
|
seq_printf(s, "\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-12-08 00:24:01 +08:00
|
|
|
if (reg & WM8994_GPN_DIR)
|
|
|
|
seq_printf(s, "in ");
|
|
|
|
else
|
|
|
|
seq_printf(s, "out ");
|
|
|
|
|
|
|
|
if (reg & WM8994_GPN_PU)
|
|
|
|
seq_printf(s, "pull up ");
|
|
|
|
|
|
|
|
if (reg & WM8994_GPN_PD)
|
|
|
|
seq_printf(s, "pull down ");
|
|
|
|
|
|
|
|
if (reg & WM8994_GPN_POL)
|
|
|
|
seq_printf(s, "inverted ");
|
|
|
|
else
|
|
|
|
seq_printf(s, "noninverted ");
|
|
|
|
|
|
|
|
if (reg & WM8994_GPN_OP_CFG)
|
|
|
|
seq_printf(s, "open drain ");
|
|
|
|
else
|
|
|
|
seq_printf(s, "CMOS ");
|
|
|
|
|
|
|
|
seq_printf(s, "%s (%x)\n",
|
|
|
|
wm8994_gpio_fn(reg & WM8994_GPN_FN_MASK), reg);
|
2010-01-30 02:20:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define wm8994_gpio_dbg_show NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct gpio_chip template_chip = {
|
|
|
|
.label = "wm8994",
|
|
|
|
.owner = THIS_MODULE,
|
2010-09-01 17:47:16 +08:00
|
|
|
.request = wm8994_gpio_request,
|
2010-01-30 02:20:30 +08:00
|
|
|
.direction_input = wm8994_gpio_direction_in,
|
|
|
|
.get = wm8994_gpio_get,
|
|
|
|
.direction_output = wm8994_gpio_direction_out,
|
|
|
|
.set = wm8994_gpio_set,
|
2010-08-17 20:13:37 +08:00
|
|
|
.to_irq = wm8994_gpio_to_irq,
|
2010-01-30 02:20:30 +08:00
|
|
|
.dbg_show = wm8994_gpio_dbg_show,
|
2013-12-04 21:42:46 +08:00
|
|
|
.can_sleep = true,
|
2010-01-30 02:20:30 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:22:34 +08:00
|
|
|
static int wm8994_gpio_probe(struct platform_device *pdev)
|
2010-01-30 02:20:30 +08:00
|
|
|
{
|
|
|
|
struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
|
2013-07-30 16:08:05 +08:00
|
|
|
struct wm8994_pdata *pdata = dev_get_platdata(wm8994->dev);
|
2010-01-30 02:20:30 +08:00
|
|
|
struct wm8994_gpio *wm8994_gpio;
|
|
|
|
int ret;
|
|
|
|
|
2012-06-06 00:22:09 +08:00
|
|
|
wm8994_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8994_gpio),
|
|
|
|
GFP_KERNEL);
|
2010-01-30 02:20:30 +08:00
|
|
|
if (wm8994_gpio == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
wm8994_gpio->wm8994 = wm8994;
|
|
|
|
wm8994_gpio->gpio_chip = template_chip;
|
|
|
|
wm8994_gpio->gpio_chip.ngpio = WM8994_GPIO_MAX;
|
|
|
|
wm8994_gpio->gpio_chip.dev = &pdev->dev;
|
|
|
|
if (pdata && pdata->gpio_base)
|
|
|
|
wm8994_gpio->gpio_chip.base = pdata->gpio_base;
|
|
|
|
else
|
|
|
|
wm8994_gpio->gpio_chip.base = -1;
|
|
|
|
|
|
|
|
ret = gpiochip_add(&wm8994_gpio->gpio_chip);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev, "Could not register gpiochip, %d\n",
|
|
|
|
ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, wm8994_gpio);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:25:50 +08:00
|
|
|
static int wm8994_gpio_remove(struct platform_device *pdev)
|
2010-01-30 02:20:30 +08:00
|
|
|
{
|
|
|
|
struct wm8994_gpio *wm8994_gpio = platform_get_drvdata(pdev);
|
|
|
|
|
2014-07-13 04:30:12 +08:00
|
|
|
gpiochip_remove(&wm8994_gpio->gpio_chip);
|
|
|
|
return 0;
|
2010-01-30 02:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver wm8994_gpio_driver = {
|
|
|
|
.driver.name = "wm8994-gpio",
|
|
|
|
.driver.owner = THIS_MODULE,
|
|
|
|
.probe = wm8994_gpio_probe,
|
2012-11-20 02:20:08 +08:00
|
|
|
.remove = wm8994_gpio_remove,
|
2010-01-30 02:20:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init wm8994_gpio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&wm8994_gpio_driver);
|
|
|
|
}
|
|
|
|
subsys_initcall(wm8994_gpio_init);
|
|
|
|
|
|
|
|
static void __exit wm8994_gpio_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&wm8994_gpio_driver);
|
|
|
|
}
|
|
|
|
module_exit(wm8994_gpio_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|
|
|
|
MODULE_DESCRIPTION("GPIO interface for WM8994");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:wm8994-gpio");
|