mirror of
https://github.com/torvalds/linux.git
synced 2024-11-15 00:21:59 +00:00
5a0e3ad6af
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>
219 lines
5.3 KiB
C
219 lines
5.3 KiB
C
/*
|
|
* PPC4xx gpio driver
|
|
*
|
|
* Copyright (c) 2008 Harris Corporation
|
|
* Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
|
* Copyright (c) MontaVista Software, Inc. 2008.
|
|
*
|
|
* Author: Steve Falco <sfalco@harris.com>
|
|
*
|
|
* 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.
|
|
*
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/io.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_gpio.h>
|
|
#include <linux/gpio.h>
|
|
#include <linux/types.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define GPIO_MASK(gpio) (0x80000000 >> (gpio))
|
|
#define GPIO_MASK2(gpio) (0xc0000000 >> ((gpio) * 2))
|
|
|
|
/* Physical GPIO register layout */
|
|
struct ppc4xx_gpio {
|
|
__be32 or;
|
|
__be32 tcr;
|
|
__be32 osrl;
|
|
__be32 osrh;
|
|
__be32 tsrl;
|
|
__be32 tsrh;
|
|
__be32 odr;
|
|
__be32 ir;
|
|
__be32 rr1;
|
|
__be32 rr2;
|
|
__be32 rr3;
|
|
__be32 reserved1;
|
|
__be32 isr1l;
|
|
__be32 isr1h;
|
|
__be32 isr2l;
|
|
__be32 isr2h;
|
|
__be32 isr3l;
|
|
__be32 isr3h;
|
|
};
|
|
|
|
struct ppc4xx_gpio_chip {
|
|
struct of_mm_gpio_chip mm_gc;
|
|
spinlock_t lock;
|
|
};
|
|
|
|
/*
|
|
* GPIO LIB API implementation for GPIOs
|
|
*
|
|
* There are a maximum of 32 gpios in each gpio controller.
|
|
*/
|
|
|
|
static inline struct ppc4xx_gpio_chip *
|
|
to_ppc4xx_gpiochip(struct of_mm_gpio_chip *mm_gc)
|
|
{
|
|
return container_of(mm_gc, struct ppc4xx_gpio_chip, mm_gc);
|
|
}
|
|
|
|
static int ppc4xx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
|
|
|
|
return in_be32(®s->ir) & GPIO_MASK(gpio);
|
|
}
|
|
|
|
static inline void
|
|
__ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
|
|
|
|
if (val)
|
|
setbits32(®s->or, GPIO_MASK(gpio));
|
|
else
|
|
clrbits32(®s->or, GPIO_MASK(gpio));
|
|
}
|
|
|
|
static void
|
|
ppc4xx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct ppc4xx_gpio_chip *chip = to_ppc4xx_gpiochip(mm_gc);
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
|
|
__ppc4xx_gpio_set(gc, gpio, val);
|
|
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
|
|
pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
|
|
}
|
|
|
|
static int ppc4xx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct ppc4xx_gpio_chip *chip = to_ppc4xx_gpiochip(mm_gc);
|
|
struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
|
|
/* Disable open-drain function */
|
|
clrbits32(®s->odr, GPIO_MASK(gpio));
|
|
|
|
/* Float the pin */
|
|
clrbits32(®s->tcr, GPIO_MASK(gpio));
|
|
|
|
/* Bits 0-15 use TSRL/OSRL, bits 16-31 use TSRH/OSRH */
|
|
if (gpio < 16) {
|
|
clrbits32(®s->osrl, GPIO_MASK2(gpio));
|
|
clrbits32(®s->tsrl, GPIO_MASK2(gpio));
|
|
} else {
|
|
clrbits32(®s->osrh, GPIO_MASK2(gpio));
|
|
clrbits32(®s->tsrh, GPIO_MASK2(gpio));
|
|
}
|
|
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
ppc4xx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
{
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
struct ppc4xx_gpio_chip *chip = to_ppc4xx_gpiochip(mm_gc);
|
|
struct ppc4xx_gpio __iomem *regs = mm_gc->regs;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->lock, flags);
|
|
|
|
/* First set initial value */
|
|
__ppc4xx_gpio_set(gc, gpio, val);
|
|
|
|
/* Disable open-drain function */
|
|
clrbits32(®s->odr, GPIO_MASK(gpio));
|
|
|
|
/* Drive the pin */
|
|
setbits32(®s->tcr, GPIO_MASK(gpio));
|
|
|
|
/* Bits 0-15 use TSRL, bits 16-31 use TSRH */
|
|
if (gpio < 16) {
|
|
clrbits32(®s->osrl, GPIO_MASK2(gpio));
|
|
clrbits32(®s->tsrl, GPIO_MASK2(gpio));
|
|
} else {
|
|
clrbits32(®s->osrh, GPIO_MASK2(gpio));
|
|
clrbits32(®s->tsrh, GPIO_MASK2(gpio));
|
|
}
|
|
|
|
spin_unlock_irqrestore(&chip->lock, flags);
|
|
|
|
pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __init ppc4xx_add_gpiochips(void)
|
|
{
|
|
struct device_node *np;
|
|
|
|
for_each_compatible_node(np, NULL, "ibm,ppc4xx-gpio") {
|
|
int ret;
|
|
struct ppc4xx_gpio_chip *ppc4xx_gc;
|
|
struct of_mm_gpio_chip *mm_gc;
|
|
struct of_gpio_chip *of_gc;
|
|
struct gpio_chip *gc;
|
|
|
|
ppc4xx_gc = kzalloc(sizeof(*ppc4xx_gc), GFP_KERNEL);
|
|
if (!ppc4xx_gc) {
|
|
ret = -ENOMEM;
|
|
goto err;
|
|
}
|
|
|
|
spin_lock_init(&ppc4xx_gc->lock);
|
|
|
|
mm_gc = &ppc4xx_gc->mm_gc;
|
|
of_gc = &mm_gc->of_gc;
|
|
gc = &of_gc->gc;
|
|
|
|
of_gc->gpio_cells = 2;
|
|
gc->ngpio = 32;
|
|
gc->direction_input = ppc4xx_gpio_dir_in;
|
|
gc->direction_output = ppc4xx_gpio_dir_out;
|
|
gc->get = ppc4xx_gpio_get;
|
|
gc->set = ppc4xx_gpio_set;
|
|
|
|
ret = of_mm_gpiochip_add(np, mm_gc);
|
|
if (ret)
|
|
goto err;
|
|
continue;
|
|
err:
|
|
pr_err("%s: registration failed with status %d\n",
|
|
np->full_name, ret);
|
|
kfree(ppc4xx_gc);
|
|
/* try others anyway */
|
|
}
|
|
return 0;
|
|
}
|
|
arch_initcall(ppc4xx_add_gpiochips);
|