2008-11-13 04:25:38 +07:00
|
|
|
/*
|
2013-06-03 19:31:17 +07:00
|
|
|
* Xilinx gpio driver for xps/axi_gpio IP.
|
2008-11-13 04:25:38 +07:00
|
|
|
*
|
2013-06-03 19:31:17 +07:00
|
|
|
* Copyright 2008 - 2013 Xilinx, Inc.
|
2008-11-13 04:25:38 +07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-06-03 19:31:17 +07:00
|
|
|
#include <linux/bitops.h>
|
2008-11-13 04:25:38 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
2011-07-04 00:38:09 +07:00
|
|
|
#include <linux/module.h>
|
2008-11-13 04:25:38 +07:00
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/gpio.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
/* Register Offset Definitions */
|
|
|
|
#define XGPIO_DATA_OFFSET (0x0) /* Data register */
|
|
|
|
#define XGPIO_TRI_OFFSET (0x4) /* I/O direction register */
|
|
|
|
|
2013-06-03 19:31:17 +07:00
|
|
|
#define XGPIO_CHANNEL_OFFSET 0x8
|
|
|
|
|
|
|
|
/* Read/Write access to the GPIO registers */
|
2013-06-03 19:31:18 +07:00
|
|
|
#ifdef CONFIG_ARCH_ZYNQ
|
|
|
|
# define xgpio_readreg(offset) readl(offset)
|
|
|
|
# define xgpio_writereg(offset, val) writel(val, offset)
|
|
|
|
#else
|
|
|
|
# define xgpio_readreg(offset) __raw_readl(offset)
|
|
|
|
# define xgpio_writereg(offset, val) __raw_writel(val, offset)
|
|
|
|
#endif
|
2013-06-03 19:31:17 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct xgpio_instance - Stores information about GPIO device
|
|
|
|
* struct of_mm_gpio_chip mmchip: OF GPIO chip for memory mapped banks
|
|
|
|
* gpio_state: GPIO state shadow register
|
|
|
|
* gpio_dir: GPIO direction shadow register
|
|
|
|
* offset: GPIO channel offset
|
|
|
|
* gpio_lock: Lock used for synchronization
|
|
|
|
*/
|
2008-11-13 04:25:38 +07:00
|
|
|
struct xgpio_instance {
|
|
|
|
struct of_mm_gpio_chip mmchip;
|
2013-06-03 19:31:17 +07:00
|
|
|
u32 gpio_state;
|
|
|
|
u32 gpio_dir;
|
|
|
|
u32 offset;
|
|
|
|
spinlock_t gpio_lock;
|
2008-11-13 04:25:38 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_get - Read the specified signal of the GPIO device.
|
|
|
|
* @gc: Pointer to gpio_chip device structure.
|
|
|
|
* @gpio: GPIO signal number.
|
|
|
|
*
|
|
|
|
* This function reads the specified signal of the GPIO device. It returns 0 if
|
|
|
|
* the signal clear, 1 if signal is set or negative value on error.
|
|
|
|
*/
|
|
|
|
static int xgpio_get(struct gpio_chip *gc, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
2013-06-03 19:31:17 +07:00
|
|
|
struct xgpio_instance *chip =
|
|
|
|
container_of(mm_gc, struct xgpio_instance, mmchip);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
2013-06-03 19:31:17 +07:00
|
|
|
void __iomem *regs = mm_gc->regs + chip->offset;
|
|
|
|
|
|
|
|
return !!(xgpio_readreg(regs + XGPIO_DATA_OFFSET) & BIT(gpio));
|
2008-11-13 04:25:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_set - Write the specified signal of the GPIO device.
|
|
|
|
* @gc: Pointer to gpio_chip device structure.
|
|
|
|
* @gpio: GPIO signal number.
|
|
|
|
* @val: Value to be written to specified signal.
|
|
|
|
*
|
|
|
|
* This function writes the specified value in to the specified signal of the
|
|
|
|
* GPIO device.
|
|
|
|
*/
|
|
|
|
static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
|
|
struct xgpio_instance *chip =
|
|
|
|
container_of(mm_gc, struct xgpio_instance, mmchip);
|
2013-06-03 19:31:17 +07:00
|
|
|
void __iomem *regs = mm_gc->regs;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&chip->gpio_lock, flags);
|
|
|
|
|
|
|
|
/* Write to GPIO signal and set its direction to output */
|
|
|
|
if (val)
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_state |= BIT(gpio);
|
2008-11-13 04:25:38 +07:00
|
|
|
else
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_state &= ~BIT(gpio);
|
2013-06-03 19:31:17 +07:00
|
|
|
|
|
|
|
xgpio_writereg(regs + chip->offset + XGPIO_DATA_OFFSET,
|
|
|
|
chip->gpio_state);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&chip->gpio_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_dir_in - Set the direction of the specified GPIO signal as input.
|
|
|
|
* @gc: Pointer to gpio_chip device structure.
|
|
|
|
* @gpio: GPIO signal number.
|
|
|
|
*
|
|
|
|
* This function sets the direction of specified GPIO signal as input.
|
|
|
|
* It returns 0 if direction of GPIO signals is set as input otherwise it
|
|
|
|
* returns negative error value.
|
|
|
|
*/
|
|
|
|
static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
|
|
struct xgpio_instance *chip =
|
|
|
|
container_of(mm_gc, struct xgpio_instance, mmchip);
|
2013-06-03 19:31:17 +07:00
|
|
|
void __iomem *regs = mm_gc->regs;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&chip->gpio_lock, flags);
|
|
|
|
|
|
|
|
/* Set the GPIO bit in shadow register and set direction as input */
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_dir |= BIT(gpio);
|
2013-06-03 19:31:17 +07:00
|
|
|
xgpio_writereg(regs + chip->offset + XGPIO_TRI_OFFSET, chip->gpio_dir);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&chip->gpio_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_dir_out - Set the direction of the specified GPIO signal as output.
|
|
|
|
* @gc: Pointer to gpio_chip device structure.
|
|
|
|
* @gpio: GPIO signal number.
|
|
|
|
* @val: Value to be written to specified signal.
|
|
|
|
*
|
|
|
|
* This function sets the direction of specified GPIO signal as output. If all
|
|
|
|
* GPIO signals of GPIO chip is configured as input then it returns
|
|
|
|
* error otherwise it returns 0.
|
|
|
|
*/
|
|
|
|
static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
|
|
struct xgpio_instance *chip =
|
|
|
|
container_of(mm_gc, struct xgpio_instance, mmchip);
|
2013-06-03 19:31:17 +07:00
|
|
|
void __iomem *regs = mm_gc->regs;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&chip->gpio_lock, flags);
|
|
|
|
|
|
|
|
/* Write state of GPIO signal */
|
|
|
|
if (val)
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_state |= BIT(gpio);
|
2008-11-13 04:25:38 +07:00
|
|
|
else
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_state &= ~BIT(gpio);
|
2013-06-03 19:31:17 +07:00
|
|
|
xgpio_writereg(regs + chip->offset + XGPIO_DATA_OFFSET,
|
|
|
|
chip->gpio_state);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
/* Clear the GPIO bit in shadow register and set direction as output */
|
2013-06-03 19:31:19 +07:00
|
|
|
chip->gpio_dir &= ~BIT(gpio);
|
2013-06-03 19:31:17 +07:00
|
|
|
xgpio_writereg(regs + chip->offset + XGPIO_TRI_OFFSET, chip->gpio_dir);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&chip->gpio_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_save_regs - Set initial values of GPIO pins
|
|
|
|
* @mm_gc: pointer to memory mapped GPIO chip structure
|
|
|
|
*/
|
|
|
|
static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)
|
|
|
|
{
|
|
|
|
struct xgpio_instance *chip =
|
|
|
|
container_of(mm_gc, struct xgpio_instance, mmchip);
|
|
|
|
|
2013-06-03 19:31:17 +07:00
|
|
|
xgpio_writereg(mm_gc->regs + chip->offset + XGPIO_DATA_OFFSET,
|
|
|
|
chip->gpio_state);
|
|
|
|
xgpio_writereg(mm_gc->regs + chip->offset + XGPIO_TRI_OFFSET,
|
|
|
|
chip->gpio_dir);
|
2008-11-13 04:25:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xgpio_of_probe - Probe method for the GPIO device.
|
|
|
|
* @np: pointer to device tree node
|
|
|
|
*
|
|
|
|
* This function probes the GPIO device in the device tree. It initializes the
|
|
|
|
* driver data structure. It returns 0, if the driver is bound to the GPIO
|
|
|
|
* device, or a negative value if there is an error.
|
|
|
|
*/
|
2012-11-20 01:22:34 +07:00
|
|
|
static int xgpio_of_probe(struct device_node *np)
|
2008-11-13 04:25:38 +07:00
|
|
|
{
|
|
|
|
struct xgpio_instance *chip;
|
|
|
|
int status = 0;
|
|
|
|
const u32 *tree_info;
|
|
|
|
|
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
|
|
|
if (!chip)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Update GPIO state shadow register with default value */
|
2013-06-03 19:31:16 +07:00
|
|
|
of_property_read_u32(np, "xlnx,dout-default", &chip->gpio_state);
|
|
|
|
|
|
|
|
/* By default, all pins are inputs */
|
|
|
|
chip->gpio_dir = 0xFFFFFFFF;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
/* Update GPIO direction shadow register with default value */
|
2013-06-03 19:31:16 +07:00
|
|
|
of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir);
|
|
|
|
|
|
|
|
/* By default assume full GPIO controller */
|
|
|
|
chip->mmchip.gc.ngpio = 32;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
/* Check device node and parent device node for device width */
|
2013-06-03 19:31:16 +07:00
|
|
|
of_property_read_u32(np, "xlnx,gpio-width",
|
|
|
|
(u32 *)&chip->mmchip.gc.ngpio);
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
spin_lock_init(&chip->gpio_lock);
|
|
|
|
|
2010-06-08 20:48:16 +07:00
|
|
|
chip->mmchip.gc.direction_input = xgpio_dir_in;
|
|
|
|
chip->mmchip.gc.direction_output = xgpio_dir_out;
|
|
|
|
chip->mmchip.gc.get = xgpio_get;
|
|
|
|
chip->mmchip.gc.set = xgpio_set;
|
2008-11-13 04:25:38 +07:00
|
|
|
|
|
|
|
chip->mmchip.save_regs = xgpio_save_regs;
|
|
|
|
|
|
|
|
/* Call the OF gpio helper to setup and register the GPIO device */
|
|
|
|
status = of_mm_gpiochip_add(np, &chip->mmchip);
|
|
|
|
if (status) {
|
|
|
|
kfree(chip);
|
|
|
|
pr_err("%s: error in probe function with status %d\n",
|
|
|
|
np->full_name, status);
|
|
|
|
return status;
|
|
|
|
}
|
2013-06-03 19:31:17 +07:00
|
|
|
|
|
|
|
pr_info("XGpio: %s: registered, base is %d\n", np->full_name,
|
|
|
|
chip->mmchip.gc.base);
|
|
|
|
|
|
|
|
tree_info = of_get_property(np, "xlnx,is-dual", NULL);
|
|
|
|
if (tree_info && be32_to_cpup(tree_info)) {
|
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
|
|
|
if (!chip)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Add dual channel offset */
|
|
|
|
chip->offset = XGPIO_CHANNEL_OFFSET;
|
|
|
|
|
|
|
|
/* Update GPIO state shadow register with default value */
|
|
|
|
of_property_read_u32(np, "xlnx,dout-default-2",
|
|
|
|
&chip->gpio_state);
|
|
|
|
|
|
|
|
/* By default, all pins are inputs */
|
|
|
|
chip->gpio_dir = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
/* Update GPIO direction shadow register with default value */
|
|
|
|
of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir);
|
|
|
|
|
|
|
|
/* By default assume full GPIO controller */
|
|
|
|
chip->mmchip.gc.ngpio = 32;
|
|
|
|
|
|
|
|
/* Check device node and parent device node for device width */
|
|
|
|
of_property_read_u32(np, "xlnx,gpio2-width",
|
|
|
|
(u32 *)&chip->mmchip.gc.ngpio);
|
|
|
|
|
|
|
|
spin_lock_init(&chip->gpio_lock);
|
|
|
|
|
|
|
|
chip->mmchip.gc.direction_input = xgpio_dir_in;
|
|
|
|
chip->mmchip.gc.direction_output = xgpio_dir_out;
|
|
|
|
chip->mmchip.gc.get = xgpio_get;
|
|
|
|
chip->mmchip.gc.set = xgpio_set;
|
|
|
|
|
|
|
|
chip->mmchip.save_regs = xgpio_save_regs;
|
|
|
|
|
|
|
|
/* Call the OF gpio helper to setup and register the GPIO dev */
|
|
|
|
status = of_mm_gpiochip_add(np, &chip->mmchip);
|
|
|
|
if (status) {
|
|
|
|
kfree(chip);
|
|
|
|
pr_err("%s: error in probe function with status %d\n",
|
|
|
|
np->full_name, status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
pr_info("XGpio: %s: dual channel registered, base is %d\n",
|
|
|
|
np->full_name, chip->mmchip.gc.base);
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:25:38 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 16:08:20 +07:00
|
|
|
static const struct of_device_id xgpio_of_match[] = {
|
2008-11-13 04:25:38 +07:00
|
|
|
{ .compatible = "xlnx,xps-gpio-1.00.a", },
|
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init xgpio_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
for_each_matching_node(np, xgpio_of_match)
|
|
|
|
xgpio_of_probe(np);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we get initialized before anyone else tries to use us */
|
|
|
|
subsys_initcall(xgpio_init);
|
|
|
|
/* No exit call at the moment as we cannot unregister of GPIO chips */
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Xilinx, Inc.");
|
|
|
|
MODULE_DESCRIPTION("Xilinx GPIO driver");
|
|
|
|
MODULE_LICENSE("GPL");
|