2007-07-16 18:43:43 +02:00
|
|
|
/*
|
|
|
|
* Common CPM code
|
|
|
|
*
|
|
|
|
* Author: Scott Wood <scottwood@freescale.com>
|
|
|
|
*
|
2010-03-26 09:43:46 +01:00
|
|
|
* Copyright 2007-2008,2010 Freescale Semiconductor, Inc.
|
2007-07-16 18:43:43 +02:00
|
|
|
*
|
2007-09-28 21:06:16 +02: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-16 18:43:43 +02: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-28 21:06:16 +02:00
|
|
|
#include <linux/of_device.h>
|
2008-07-28 10:43:22 +02:00
|
|
|
#include <linux/spinlock.h>
|
2011-05-27 16:46:24 +02:00
|
|
|
#include <linux/export.h>
|
2008-07-28 10:43:22 +02:00
|
|
|
#include <linux/of.h>
|
2013-09-26 14:40:04 +02: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 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2007-09-28 21:06:16 +02:00
|
|
|
|
2007-07-16 18:43:43 +02:00
|
|
|
#include <asm/udbg.h>
|
|
|
|
#include <asm/io.h>
|
2007-09-28 21:06:16 +02:00
|
|
|
#include <asm/rheap.h>
|
|
|
|
#include <asm/cpm.h>
|
|
|
|
|
2007-07-16 18:43:43 +02:00
|
|
|
#include <mm/mmu_decl.h>
|
|
|
|
|
2008-07-28 10:43:22 +02:00
|
|
|
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-16 18:43:43 +02:00
|
|
|
#ifdef CONFIG_PPC_EARLY_DEBUG_CPM
|
|
|
|
static u32 __iomem *cpm_udbg_txdesc =
|
|
|
|
(u32 __iomem __force *)CONFIG_PPC_EARLY_DEBUG_CPM_ADDR;
|
|
|
|
|
|
|
|
static void udbg_putc_cpm(char c)
|
|
|
|
{
|
|
|
|
u8 __iomem *txbuf = (u8 __iomem __force *)in_be32(&cpm_udbg_txdesc[1]);
|
|
|
|
|
|
|
|
if (c == '\n')
|
2008-06-27 22:01:00 +02:00
|
|
|
udbg_putc_cpm('\r');
|
2007-07-16 18:43:43 +02:00
|
|
|
|
|
|
|
while (in_be32(&cpm_udbg_txdesc[0]) & 0x80000000)
|
|
|
|
;
|
|
|
|
|
|
|
|
out_8(txbuf, c);
|
|
|
|
out_be32(&cpm_udbg_txdesc[0], 0xa0000001);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init udbg_init_cpm(void)
|
|
|
|
{
|
|
|
|
if (cpm_udbg_txdesc) {
|
|
|
|
#ifdef CONFIG_CPM2
|
2009-03-19 20:34:08 +01:00
|
|
|
setbat(1, 0xf0000000, 0xf0000000, 1024*1024, PAGE_KERNEL_NCG);
|
2007-07-16 18:43:43 +02:00
|
|
|
#endif
|
|
|
|
udbg_putc = udbg_putc_cpm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-28 21:06:16 +02:00
|
|
|
|
|
|
|
static spinlock_t cpm_muram_lock;
|
|
|
|
static rh_block_t cpm_boot_muram_rh_block[16];
|
|
|
|
static rh_info_t cpm_muram_info;
|
|
|
|
static u8 __iomem *muram_vbase;
|
|
|
|
static phys_addr_t muram_pbase;
|
|
|
|
|
|
|
|
/* Max address size we deal with */
|
|
|
|
#define OF_MAX_ADDR_CELLS 4
|
|
|
|
|
2009-09-15 23:43:52 +02:00
|
|
|
int cpm_muram_init(void)
|
2007-09-28 21:06:16 +02:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
struct resource r;
|
|
|
|
u32 zero[OF_MAX_ADDR_CELLS] = {};
|
|
|
|
resource_size_t max = 0;
|
|
|
|
int i = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-09-15 23:43:52 +02:00
|
|
|
if (muram_pbase)
|
|
|
|
return 0;
|
|
|
|
|
2007-09-28 21:06:16 +02:00
|
|
|
spin_lock_init(&cpm_muram_lock);
|
|
|
|
/* initialize the info header */
|
|
|
|
rh_init(&cpm_muram_info, 1,
|
|
|
|
sizeof(cpm_boot_muram_rh_block) /
|
|
|
|
sizeof(cpm_boot_muram_rh_block[0]),
|
|
|
|
cpm_boot_muram_rh_block);
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, "fsl,cpm-muram-data");
|
|
|
|
if (!np) {
|
2008-05-23 18:39:06 +02:00
|
|
|
/* try legacy bindings */
|
|
|
|
np = of_find_node_by_name(NULL, "data-only");
|
|
|
|
if (!np) {
|
|
|
|
printk(KERN_ERR "Cannot find CPM muram data node");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2007-09-28 21:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
muram_pbase = of_translate_address(np, zero);
|
|
|
|
if (muram_pbase == (phys_addr_t)OF_BAD_ADDR) {
|
|
|
|
printk(KERN_ERR "Cannot translate zero through CPM muram node");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (of_address_to_resource(np, i++, &r) == 0) {
|
|
|
|
if (r.end > max)
|
|
|
|
max = r.end;
|
|
|
|
|
|
|
|
rh_attach_region(&cpm_muram_info, r.start - muram_pbase,
|
2011-06-09 18:13:32 +02:00
|
|
|
resource_size(&r));
|
2007-09-28 21:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
muram_vbase = ioremap(muram_pbase, max - muram_pbase + 1);
|
|
|
|
if (!muram_vbase) {
|
|
|
|
printk(KERN_ERR "Cannot map CPM muram");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
of_node_put(np);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cpm_muram_alloc - allocate the requested size worth of multi-user ram
|
|
|
|
* @size: number of bytes to allocate
|
|
|
|
* @align: requested alignment, in bytes
|
|
|
|
*
|
|
|
|
* This function returns an offset into the muram area.
|
|
|
|
* Use cpm_dpram_addr() to get the virtual address of the area.
|
|
|
|
* Use cpm_muram_free() to free the allocation.
|
|
|
|
*/
|
|
|
|
unsigned long cpm_muram_alloc(unsigned long size, unsigned long align)
|
|
|
|
{
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cpm_muram_lock, flags);
|
|
|
|
cpm_muram_info.alignment = align;
|
|
|
|
start = rh_alloc(&cpm_muram_info, size, "commproc");
|
2010-03-26 09:43:46 +01:00
|
|
|
memset(cpm_muram_addr(start), 0, size);
|
2007-09-28 21:06:16 +02:00
|
|
|
spin_unlock_irqrestore(&cpm_muram_lock, flags);
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cpm_muram_free - free a chunk of multi-user ram
|
|
|
|
* @offset: The beginning of the chunk as returned by cpm_muram_alloc().
|
|
|
|
*/
|
|
|
|
int cpm_muram_free(unsigned long offset)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cpm_muram_lock, flags);
|
|
|
|
ret = rh_free(&cpm_muram_info, offset);
|
|
|
|
spin_unlock_irqrestore(&cpm_muram_lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_free);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cpm_muram_alloc_fixed - reserve a specific region of multi-user ram
|
|
|
|
* @offset: the offset into the muram area to reserve
|
|
|
|
* @size: the number of bytes to reserve
|
|
|
|
*
|
|
|
|
* This function returns "start" on success, -ENOMEM on failure.
|
|
|
|
* Use cpm_dpram_addr() to get the virtual address of the area.
|
|
|
|
* Use cpm_muram_free() to free the allocation.
|
|
|
|
*/
|
|
|
|
unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size)
|
|
|
|
{
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cpm_muram_lock, flags);
|
|
|
|
cpm_muram_info.alignment = 1;
|
|
|
|
start = rh_alloc_fixed(&cpm_muram_info, offset, size, "commproc");
|
|
|
|
spin_unlock_irqrestore(&cpm_muram_lock, flags);
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_alloc_fixed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cpm_muram_addr - turn a muram offset into a virtual address
|
|
|
|
* @offset: muram offset to convert
|
|
|
|
*/
|
|
|
|
void __iomem *cpm_muram_addr(unsigned long offset)
|
|
|
|
{
|
|
|
|
return muram_vbase + offset;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_addr);
|
|
|
|
|
2008-05-23 18:39:06 +02:00
|
|
|
unsigned long cpm_muram_offset(void __iomem *addr)
|
|
|
|
{
|
|
|
|
return addr - (void __iomem *)muram_vbase;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_offset);
|
|
|
|
|
2007-09-28 21:06:16 +02:00
|
|
|
/**
|
2007-10-12 22:19:11 +02:00
|
|
|
* cpm_muram_dma - turn a muram virtual address into a DMA address
|
2007-09-28 21:06:16 +02:00
|
|
|
* @offset: virtual address from cpm_muram_addr() to convert
|
|
|
|
*/
|
|
|
|
dma_addr_t cpm_muram_dma(void __iomem *addr)
|
|
|
|
{
|
|
|
|
return muram_pbase + ((u8 __iomem *)addr - muram_vbase);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpm_muram_dma);
|
2008-07-28 10:43:22 +02: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 inline struct cpm2_gpio32_chip *
|
|
|
|
to_cpm2_gpio32_chip(struct of_mm_gpio_chip *mm_gc)
|
|
|
|
{
|
|
|
|
return container_of(mm_gc, struct cpm2_gpio32_chip, mm_gc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpm2_gpio32_save_regs(struct of_mm_gpio_chip *mm_gc)
|
|
|
|
{
|
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
|
|
|
|
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 14:20:23 +02:00
|
|
|
static void __cpm2_gpio32_set(struct of_mm_gpio_chip *mm_gc, u32 pin_mask,
|
|
|
|
int value)
|
2008-07-28 10:43:22 +02:00
|
|
|
{
|
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
|
|
|
|
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 14:20:23 +02: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);
|
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
|
|
|
|
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 10:43:22 +02: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);
|
2008-08-19 14:20:23 +02:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
|
2008-07-28 10:43:22 +02:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
2008-08-19 14:20:23 +02:00
|
|
|
unsigned long flags;
|
|
|
|
u32 pin_mask = 1 << (31 - gpio);
|
2008-07-28 10:43:22 +02:00
|
|
|
|
2008-08-19 14:20:23 +02:00
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
2008-07-28 10:43:22 +02:00
|
|
|
|
|
|
|
setbits32(&iop->dir, pin_mask);
|
2008-08-19 14:20:23 +02:00
|
|
|
__cpm2_gpio32_set(mm_gc, pin_mask, val);
|
2008-07-28 10:43:22 +02:00
|
|
|
|
2008-08-19 14:20:23 +02:00
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
2008-07-28 10:43:22 +02: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);
|
2008-08-19 14:20:23 +02:00
|
|
|
struct cpm2_gpio32_chip *cpm2_gc = to_cpm2_gpio32_chip(mm_gc);
|
2008-07-28 10:43:22 +02:00
|
|
|
struct cpm2_ioports __iomem *iop = mm_gc->regs;
|
2008-08-19 14:20:23 +02:00
|
|
|
unsigned long flags;
|
|
|
|
u32 pin_mask = 1 << (31 - gpio);
|
2008-07-28 10:43:22 +02:00
|
|
|
|
2008-08-19 14:20:23 +02:00
|
|
|
spin_lock_irqsave(&cpm2_gc->lock, flags);
|
2008-07-28 10:43:22 +02:00
|
|
|
|
|
|
|
clrbits32(&iop->dir, pin_mask);
|
|
|
|
|
2008-08-19 14:20:23 +02:00
|
|
|
spin_unlock_irqrestore(&cpm2_gc->lock, flags);
|
|
|
|
|
2008-07-28 10:43:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cpm2_gpiochip_add32(struct device_node *np)
|
|
|
|
{
|
|
|
|
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 15:48:16 +02:00
|
|
|
gc = &mm_gc->gc;
|
2008-07-28 10:43:22 +02: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;
|
|
|
|
|
|
|
|
return of_mm_gpiochip_add(np, mm_gc);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CPM2 || CONFIG_8xx_GPIO */
|