2007-07-17 00:43:43 +08:00
|
|
|
/*
|
|
|
|
* Common CPM code
|
|
|
|
*
|
|
|
|
* Author: Scott Wood <scottwood@freescale.com>
|
|
|
|
*
|
2010-03-26 16:43:46 +08:00
|
|
|
* Copyright 2007-2008,2010 Freescale Semiconductor, Inc.
|
2007-07-17 00:43:43 +08:00
|
|
|
*
|
2007-09-29 03:06:16 +08:00
|
|
|
* Some parts derived from commproc.c/cpm2_common.c, which is:
|
|
|
|
* Copyright (c) 1997 Dan error_act (dmalek@jlc.net)
|
|
|
|
* Copyright (c) 1999-2001 Dan Malek <dan@embeddedalley.com>
|
|
|
|
* Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com)
|
|
|
|
* 2006 (c) MontaVista Software, Inc.
|
|
|
|
* Vitaly Bordug <vbordug@ru.mvista.com>
|
|
|
|
*
|
2007-07-17 00:43:43 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2007-09-29 03:06:16 +08:00
|
|
|
#include <linux/of_device.h>
|
2008-07-28 16:43:22 +08:00
|
|
|
#include <linux/spinlock.h>
|
2011-05-27 22:46:24 +08:00
|
|
|
#include <linux/export.h>
|
2008-07-28 16:43:22 +08:00
|
|
|
#include <linux/of.h>
|
2013-09-26 20:40:04 +08:00
|
|
|
#include <linux/of_address.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>
|
2007-09-29 03:06:16 +08:00
|
|
|
|
2007-07-17 00:43:43 +08:00
|
|
|
#include <asm/udbg.h>
|
|
|
|
#include <asm/io.h>
|
2007-09-29 03:06:16 +08:00
|
|
|
#include <asm/cpm.h>
|
powerpc/8xx: Fix vaddr for IMMR early remap
Memory: 124428K/131072K available (3748K kernel code, 188K rwdata,
648K rodata, 508K init, 290K bss, 6644K reserved)
Kernel virtual memory layout:
* 0xfffdf000..0xfffff000 : fixmap
* 0xfde00000..0xfe000000 : consistent mem
* 0xfddf6000..0xfde00000 : early ioremap
* 0xc9000000..0xfddf6000 : vmalloc & ioremap
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Today, IMMR is mapped 1:1 at startup
Mapping IMMR 1:1 is just wrong because it may overlap with another
area. On most mpc8xx boards it is OK as IMMR is set to 0xff000000
but for instance on EP88xC board, IMMR is at 0xfa200000 which
overlaps with VM ioremap area
This patch fixes the virtual address for remapping IMMR with the fixmap
regardless of the value of IMMR.
The size of IMMR area is 256kbytes (CPM at offset 0, security engine
at offset 128k) so a 512k page is enough
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-05-17 15:02:43 +08:00
|
|
|
#include <asm/fixmap.h>
|
2015-11-30 10:48:57 +08:00
|
|
|
#include <soc/fsl/qe/qe.h>
|
2007-09-29 03:06:16 +08:00
|
|
|
|
2007-07-17 00:43:43 +08:00
|
|
|
#include <mm/mmu_decl.h>
|
|
|
|
|
2008-07-28 16:43:22 +08:00
|
|
|
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#endif
|
|
|
|
|
2016-08-16 14:26:20 +08:00
|
|
|
static int __init cpm_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,cpm1");
|
|
|
|
if (!np)
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,cpm2");
|
|
|
|
if (!np)
|
|
|
|
return -ENODEV;
|
|
|
|
cpm_muram_init();
|
|
|
|
of_node_put(np);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(cpm_init);
|
|
|
|
|
2007-07-17 00:43:43 +08:00
|
|
|
#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
|
powerpc/8xx: Fix vaddr for IMMR early remap
Memory: 124428K/131072K available (3748K kernel code, 188K rwdata,
648K rodata, 508K init, 290K bss, 6644K reserved)
Kernel virtual memory layout:
* 0xfffdf000..0xfffff000 : fixmap
* 0xfde00000..0xfe000000 : consistent mem
* 0xfddf6000..0xfde00000 : early ioremap
* 0xc9000000..0xfddf6000 : vmalloc & ioremap
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Today, IMMR is mapped 1:1 at startup
Mapping IMMR 1:1 is just wrong because it may overlap with another
area. On most mpc8xx boards it is OK as IMMR is set to 0xff000000
but for instance on EP88xC board, IMMR is at 0xfa200000 which
overlaps with VM ioremap area
This patch fixes the virtual address for remapping IMMR with the fixmap
regardless of the value of IMMR.
The size of IMMR area is 256kbytes (CPM at offset 0, security engine
at offset 128k) so a 512k page is enough
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-05-17 15:02:43 +08:00
|
|
|
static u32 __iomem *cpm_udbg_txdesc;
|
|
|
|
static u8 __iomem *cpm_udbg_txbuf;
|
2007-07-17 00:43:43 +08:00
|
|
|
|
|
|
|
static void udbg_putc_cpm(char c)
|
|
|
|
{
|
|
|
|
if (c == '\n')
|
2008-06-28 04:01:00 +08:00
|
|
|
udbg_putc_cpm('\r');
|
2007-07-17 00:43:43 +08:00
|
|
|
|
|
|
|
while (in_be32(&cpm_udbg_txdesc[0]) & 0x80000000)
|
|
|
|
;
|
|
|
|
|
powerpc/8xx: Fix vaddr for IMMR early remap
Memory: 124428K/131072K available (3748K kernel code, 188K rwdata,
648K rodata, 508K init, 290K bss, 6644K reserved)
Kernel virtual memory layout:
* 0xfffdf000..0xfffff000 : fixmap
* 0xfde00000..0xfe000000 : consistent mem
* 0xfddf6000..0xfde00000 : early ioremap
* 0xc9000000..0xfddf6000 : vmalloc & ioremap
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Today, IMMR is mapped 1:1 at startup
Mapping IMMR 1:1 is just wrong because it may overlap with another
area. On most mpc8xx boards it is OK as IMMR is set to 0xff000000
but for instance on EP88xC board, IMMR is at 0xfa200000 which
overlaps with VM ioremap area
This patch fixes the virtual address for remapping IMMR with the fixmap
regardless of the value of IMMR.
The size of IMMR area is 256kbytes (CPM at offset 0, security engine
at offset 128k) so a 512k page is enough
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-05-17 15:02:43 +08:00
|
|
|
out_8(cpm_udbg_txbuf, c);
|
2007-07-17 00:43:43 +08:00
|
|
|
out_be32(&cpm_udbg_txdesc[0], 0xa0000001);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init udbg_init_cpm(void)
|
|
|
|
{
|
powerpc/8xx: Fix vaddr for IMMR early remap
Memory: 124428K/131072K available (3748K kernel code, 188K rwdata,
648K rodata, 508K init, 290K bss, 6644K reserved)
Kernel virtual memory layout:
* 0xfffdf000..0xfffff000 : fixmap
* 0xfde00000..0xfe000000 : consistent mem
* 0xfddf6000..0xfde00000 : early ioremap
* 0xc9000000..0xfddf6000 : vmalloc & ioremap
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Today, IMMR is mapped 1:1 at startup
Mapping IMMR 1:1 is just wrong because it may overlap with another
area. On most mpc8xx boards it is OK as IMMR is set to 0xff000000
but for instance on EP88xC board, IMMR is at 0xfa200000 which
overlaps with VM ioremap area
This patch fixes the virtual address for remapping IMMR with the fixmap
regardless of the value of IMMR.
The size of IMMR area is 256kbytes (CPM at offset 0, security engine
at offset 128k) so a 512k page is enough
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <oss@buserror.net>
2016-05-17 15:02:43 +08:00
|
|
|
#ifdef CONFIG_PPC_8xx
|
|
|
|
cpm_udbg_txdesc = (u32 __iomem __force *)
|
|
|
|
(CONFIG_PPC_EARLY_DEBUG_CPM_ADDR - PHYS_IMMR_BASE +
|
|
|
|
VIRT_IMMR_BASE);
|
|
|
|
cpm_udbg_txbuf = (u8 __iomem __force *)
|
|
|
|
(in_be32(&cpm_udbg_txdesc[1]) - PHYS_IMMR_BASE +
|
|
|
|
VIRT_IMMR_BASE);
|
|
|
|
#else
|
|
|
|
cpm_udbg_txdesc = (u32 __iomem __force *)
|
|
|
|
CONFIG_PPC_EARLY_DEBUG_CPM_ADDR;
|
|
|
|
cpm_udbg_txbuf = (u8 __iomem __force *)in_be32(&cpm_udbg_txdesc[1]);
|
|
|
|
#endif
|
|
|
|
|
2007-07-17 00:43:43 +08:00
|
|
|
if (cpm_udbg_txdesc) {
|
|
|
|
#ifdef CONFIG_CPM2
|
2009-03-20 03:34:08 +08:00
|
|
|
setbat(1, 0xf0000000, 0xf0000000, 1024*1024, PAGE_KERNEL_NCG);
|
2007-07-17 00:43:43 +08:00
|
|
|
#endif
|
|
|
|
udbg_putc = udbg_putc_cpm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-29 03:06:16 +08:00
|
|
|
|
2008-07-28 16:43:22 +08:00
|
|
|
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
|
|
|
|
|
|
|
struct cpm2_ioports {
|
|
|
|
u32 dir, par, sor, odr, dat;
|
|
|
|
u32 res[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cpm2_gpio32_chip {
|
|
|
|
struct of_mm_gpio_chip mm_gc;
|
|
|
|
spinlock_t lock;
|
|
|
|
|
|
|
|
/* shadowed data register to clear/set bits safely */
|
|
|
|
u32 cpdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc)
|
|
|
|
{
|
2016-08-11 16:50:40 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc =
|
|
|
|
container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc);
|
2008-07-28 16:43:22 +08:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
|
|
|
|
|
|
cpm2_gc->cpdata = in_be32(&iop->dat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpm2_gpio32_get(struct gpio_chip *gc, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
|
|
u32 pin_mask;
|
|
|
|
|
|
|
|
pin_mask = 1 << (31 - gpio);
|
|
|
|
|
|
|
|
return !!(in_be32(&iop->dat) & pin_mask);
|
|
|
|
}
|
|
|
|
|
2008-08-19 20:20:23 +08:00
|
|
|
static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask,
|
|
|
|
int value)
|
2008-07-28 16:43:22 +08:00
|
|
|
{
|
2015-12-08 22:05:43 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(&mm_gc->gc);
|
2008-07-28 16:43:22 +08:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
cpm2_gc->cpdata |= pin_mask;
|
|
|
|
else
|
|
|
|
cpm2_gc->cpdata &= ~pin_mask;
|
|
|
|
|
|
|
|
out_be32(&iop->dat, cpm2_gc->cpdata);
|
2008-08-19 20:20:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cpm2_gpio32_set(struct gpio_chip *gc, unsigned int gpio, int value)
|
|
|
|
{
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
2015-12-08 22:05:43 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
2008-08-19 20:20:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 pin_mask = 1 << (31 - gpio);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
|
|
|
|
|
|
|
__cpm2_gpio32_set(mm_gc, pin_mask, value);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpm2_gpio32_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
|
|
|
|
{
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
2015-12-08 22:05:43 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
2008-07-28 16:43:22 +08:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
2008-08-19 20:20:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 pin_mask = 1 << (31 - gpio);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
2008-08-19 20:20:23 +08:00
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
|
|
|
setbits32(&iop->dir, pin_mask);
|
2008-08-19 20:20:23 +08:00
|
|
|
__cpm2_gpio32_set(mm_gc, pin_mask, val);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
2008-08-19 20:20:23 +08:00
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpm2_gpio32_dir_in(struct gpio_chip *gc, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
|
2015-12-08 22:05:43 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = gpiochip_get_data(gc);
|
2008-07-28 16:43:22 +08:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
2008-08-19 20:20:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 pin_mask = 1 << (31 - gpio);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
2008-08-19 20:20:23 +08:00
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
2008-07-28 16:43:22 +08:00
|
|
|
|
|
|
|
clrbits32(&iop->dir, pin_mask);
|
|
|
|
|
2008-08-19 20:20:23 +08:00
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
|
|
|
2008-07-28 16:43:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-13 19:26:23 +08:00
|
|
|
int cpm2_gpiochip_add32(struct device *dev)
|
2008-07-28 16:43:22 +08:00
|
|
|
{
|
2017-12-13 19:26:23 +08:00
|
|
|
struct device_node *np = dev->of_node;
|
2008-07-28 16:43:22 +08:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc;
|
|
|
|
struct of_mm_gpio_chip *mm_gc;
|
|
|
|
struct gpio_chip *gc;
|
|
|
|
|
|
|
|
cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
|
|
|
|
if (!cpm2_gc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spin_lock_init(&cpm2_gc->lock);
|
|
|
|
|
|
|
|
mm_gc = &cpm2_gc->mm_gc;
|
2010-06-08 21:48:16 +08:00
|
|
|
gc = &mm_gc->gc;
|
2008-07-28 16:43:22 +08:00
|
|
|
|
|
|
|
mm_gc->save_regs = cpm2_gpio32_save_regs;
|
|
|
|
gc->ngpio = 32;
|
|
|
|
gc->direction_input = cpm2_gpio32_dir_in;
|
|
|
|
gc->direction_output = cpm2_gpio32_dir_out;
|
|
|
|
gc->get = cpm2_gpio32_get;
|
|
|
|
gc->set = cpm2_gpio32_set;
|
2017-12-13 19:26:23 +08:00
|
|
|
gc->parent = dev;
|
|
|
|
gc->owner = THIS_MODULE;
|
2008-07-28 16:43:22 +08:00
|
|
|
|
2015-12-08 22:05:43 +08:00
|
|
|
return of_mm_gpiochip_add_data(np, mm_gc, cpm2_gc);
|
2008-07-28 16:43:22 +08:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */
|