Commit 35880d6a authored by Stephen Rothwell's avatar Stephen Rothwell

Merge commit 'arm/devel'

parents ee120546 5413eb4c
ARM TCM (Tightly-Coupled Memory) handling in Linux
----
Written by Linus Walleij <linus.walleij@stericsson.com>
Some ARM SoC:s have a so-called TCM (Tightly-Coupled Memory).
This is usually just a few (4-64) KiB of RAM inside the ARM
processor.
Due to being embedded inside the CPU The TCM has a
Harvard-architecture, so there is an ITCM (instruction TCM)
and a DTCM (data TCM). The DTCM can not contain any
instructions, but the ITCM can actually contain data.
The size of DTCM or ITCM is minimum 4KiB so the typical
minimum configuration is 4KiB ITCM and 4KiB DTCM.
ARM CPU:s have special registers to read out status, physical
location and size of TCM memories. arch/arm/include/asm/cputype.h
defines a CPUID_TCM register that you can read out from the
system control coprocessor. Documentation from ARM can be found
at http://infocenter.arm.com, search for "TCM Status Register"
to see documents for all CPUs. Reading this register you can
determine if ITCM (bit 0) and/or DTCM (bit 16) is present in the
machine.
There is further a TCM region register (search for "TCM Region
Registers" at the ARM site) that can report and modify the location
size of TCM memories at runtime. This is used to read out and modify
TCM location and size. Notice that this is not a MMU table: you
actually move the physical location of the TCM around. At the
place you put it, it will mask any underlying RAM from the
CPU so it is usually wise not to overlap any physical RAM with
the TCM. The TCM memory exists totally outside the MMU and will
override any MMU mappings.
Code executing inside the ITCM does not "see" any MMU mappings
and e.g. register accesses must be made to physical addresses.
TCM is used for a few things:
- FIQ and other interrupt handlers that need deterministic
timing and cannot wait for cache misses.
- Idle loops where all external RAM is set to self-refresh
retention mode, so only on-chip RAM is accessible by
the CPU and then we hang inside ITCM waiting for an
interrupt.
- Other operations which implies shutting off or reconfiguring
the external RAM controller.
There is an interface for using TCM on the ARM architecture
in <asm/tcm.h>. Using this interface it is possible to:
- Define the physical address and size of ITCM and DTCM.
- Tag functions to be compiled into ITCM.
- Tag data and constants to be allocated to DTCM and ITCM.
- Have the remaining TCM RAM added to a special
allocation pool with gen_pool_create() and gen_pool_add()
and provice tcm_alloc() and tcm_free() for this
memory. Such a heap is great for things like saving
device state when shutting off device power domains.
A machine that has TCM memory shall select HAVE_TCM in
arch/arm/Kconfig for itself, and then the
rest of the functionality will depend on the physical
location and size of ITCM and DTCM to be defined in
mach/memory.h for the machine. Code that needs to use
TCM shall #include <asm/tcm.h> If the TCM is not located
at the place given in memory.h it will be moved using
the TCM Region registers.
Functions to go into itcm can be tagged like this:
int __tcmfunc foo(int bar);
Variables to go into dtcm can be tagged like this:
int __tcmdata foo;
Constants can be tagged like this:
int __tcmconst foo;
To put assembler into TCM just use
.section ".tcm.text" or .section ".tcm.data"
respectively.
Example code:
#include <asm/tcm.h>
/* Uninitialized data */
static u32 __tcmdata tcmvar;
/* Initialized data */
static u32 __tcmdata tcmassigned = 0x2BADBABEU;
/* Constant */
static const u32 __tcmconst tcmconst = 0xCAFEBABEU;
static void __tcmlocalfunc tcm_to_tcm(void)
{
int i;
for (i = 0; i < 100; i++)
tcmvar ++;
}
static void __tcmfunc hello_tcm(void)
{
/* Some abstract code that runs in ITCM */
int i;
for (i = 0; i < 100; i++) {
tcmvar ++;
}
tcm_to_tcm();
}
static void __init test_tcm(void)
{
u32 *tcmem;
int i;
hello_tcm();
printk("Hello TCM executed from ITCM RAM\n");
printk("TCM variable from testrun: %u @ %p\n", tcmvar, &tcmvar);
tcmvar = 0xDEADBEEFU;
printk("TCM variable: 0x%x @ %p\n", tcmvar, &tcmvar);
printk("TCM assigned variable: 0x%x @ %p\n", tcmassigned, &tcmassigned);
printk("TCM constant: 0x%x @ %p\n", tcmconst, &tcmconst);
/* Allocate some TCM memory from the pool */
tcmem = tcm_alloc(20);
if (tcmem) {
printk("TCM Allocated 20 bytes of TCM @ %p\n", tcmem);
tcmem[0] = 0xDEADBEEFU;
tcmem[1] = 0x2BADBABEU;
tcmem[2] = 0xCAFEBABEU;
tcmem[3] = 0xDEADBEEFU;
tcmem[4] = 0x2BADBABEU;
for (i = 0; i < 5; i++)
printk("TCM tcmem[%d] = %08x\n", i, tcmem[i]);
tcm_free(tcmem, 20);
}
}
...@@ -46,6 +46,10 @@ config GENERIC_CLOCKEVENTS_BROADCAST ...@@ -46,6 +46,10 @@ config GENERIC_CLOCKEVENTS_BROADCAST
depends on GENERIC_CLOCKEVENTS depends on GENERIC_CLOCKEVENTS
default y if SMP && !LOCAL_TIMERS default y if SMP && !LOCAL_TIMERS
config HAVE_TCM
bool
select GENERIC_ALLOCATOR
config NO_IOPORT config NO_IOPORT
bool bool
...@@ -649,6 +653,7 @@ config ARCH_U300 ...@@ -649,6 +653,7 @@ config ARCH_U300
bool "ST-Ericsson U300 Series" bool "ST-Ericsson U300 Series"
depends on MMU depends on MMU
select CPU_ARM926T select CPU_ARM926T
select HAVE_TCM
select ARM_AMBA select ARM_AMBA
select ARM_VIC select ARM_VIC
select GENERIC_TIME select GENERIC_TIME
......
...@@ -63,6 +63,11 @@ static inline unsigned int __attribute_const__ read_cpuid_cachetype(void) ...@@ -63,6 +63,11 @@ static inline unsigned int __attribute_const__ read_cpuid_cachetype(void)
return read_cpuid(CPUID_CACHETYPE); return read_cpuid(CPUID_CACHETYPE);
} }
static inline unsigned int __attribute_const__ read_cpuid_tcmstatus(void)
{
return read_cpuid(CPUID_TCM);
}
/* /*
* Intel's XScale3 core supports some v6 features (supersections, L2) * Intel's XScale3 core supports some v6 features (supersections, L2)
* but advertises itself as v5 as it does not support the v6 ISA. For * but advertises itself as v5 as it does not support the v6 ISA. For
......
/*
*
* Copyright (C) 2008-2009 ST-Ericsson AB
* License terms: GNU General Public License (GPL) version 2
*
* Author: Rickard Andersson <rickard.andersson@stericsson.com>
* Author: Linus Walleij <linus.walleij@stericsson.com>
*
*/
#ifndef __ASMARM_TCM_H
#define __ASMARM_TCM_H
#ifndef CONFIG_HAVE_TCM
#error "You should not be including tcm.h unless you have a TCM!"
#endif
#include <linux/compiler.h>
/* Tag variables with this */
#define __tcmdata __section(.tcm.data)
/* Tag constants with this */
#define __tcmconst __section(.tcm.rodata)
/* Tag functions inside TCM called from outside TCM with this */
#define __tcmfunc __attribute__((long_call)) __section(.tcm.text) noinline
/* Tag function inside TCM called from inside TCM with this */
#define __tcmlocalfunc __section(.tcm.text)
void *tcm_alloc(size_t len);
void tcm_free(void *addr, size_t len);
#endif
...@@ -34,6 +34,7 @@ obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o ...@@ -34,6 +34,7 @@ obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o
obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_ARM_THUMBEE) += thumbee.o
obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KGDB) += kgdb.o
obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_ARM_UNWIND) += unwind.o
obj-$(CONFIG_HAVE_TCM) += tcm.o
obj-$(CONFIG_CRUNCH) += crunch.o crunch-bits.o obj-$(CONFIG_CRUNCH) += crunch.o crunch-bits.o
AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312 AFLAGS_crunch-bits.o := -Wa,-mcpu=ep9312
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "compat.h" #include "compat.h"
#include "atags.h" #include "atags.h"
#include "tcm.h"
#ifndef MEM_SIZE #ifndef MEM_SIZE
#define MEM_SIZE (16*1024*1024) #define MEM_SIZE (16*1024*1024)
...@@ -749,6 +750,7 @@ void __init setup_arch(char **cmdline_p) ...@@ -749,6 +750,7 @@ void __init setup_arch(char **cmdline_p)
#endif #endif
cpu_init(); cpu_init();
tcm_init();
/* /*
* Set up various architecture-specific pointers * Set up various architecture-specific pointers
......
/*
* Copyright (C) 2008-2009 ST-Ericsson AB
* License terms: GNU General Public License (GPL) version 2
* TCM memory handling for ARM systems
*
* Author: Linus Walleij <linus.walleij@stericsson.com>
* Author: Rickard Andersson <rickard.andersson@stericsson.com>
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/stddef.h>
#include <linux/ioport.h>
#include <linux/genalloc.h>
#include <linux/string.h> /* memcpy */
#include <asm/page.h> /* PAGE_SHIFT */
#include <asm/cputype.h>
#include <asm/mach/map.h>
#include <mach/memory.h>
#include "tcm.h"
/* Scream and warn about misuse */
#if !defined(ITCM_OFFSET) || !defined(ITCM_END) || \
!defined(DTCM_OFFSET) || !defined(DTCM_END)
#error "TCM support selected but offsets not defined!"
#endif
static struct gen_pool *tcm_pool;
/* TCM section definitions from the linker */
extern char __itcm_start, __sitcm_text, __eitcm_text;
extern char __dtcm_start, __sdtcm_data, __edtcm_data;
/*
* TCM memory resources
*/
static struct resource dtcm_res = {
.name = "DTCM RAM",
.start = DTCM_OFFSET,
.end = DTCM_END,
.flags = IORESOURCE_MEM
};
static struct resource itcm_res = {
.name = "ITCM RAM",
.start = ITCM_OFFSET,
.end = ITCM_END,
.flags = IORESOURCE_MEM
};
static struct map_desc dtcm_iomap[] __initdata = {
{
.virtual = DTCM_OFFSET,
.pfn = __phys_to_pfn(DTCM_OFFSET),
.length = (DTCM_END - DTCM_OFFSET + 1),
.type = MT_UNCACHED
}
};
static struct map_desc itcm_iomap[] __initdata = {
{
.virtual = ITCM_OFFSET,
.pfn = __phys_to_pfn(ITCM_OFFSET),
.length = (ITCM_END - ITCM_OFFSET + 1),
.type = MT_UNCACHED
}
};
/*
* Allocate a chunk of TCM memory
*/
void *tcm_alloc(size_t len)
{
unsigned long vaddr;
if (!tcm_pool)
return NULL;
vaddr = gen_pool_alloc(tcm_pool, len);
if (!vaddr)
return NULL;
return (void *) vaddr;
}
EXPORT_SYMBOL(tcm_alloc);
/*
* Free a chunk of TCM memory
*/
void tcm_free(void *addr, size_t len)
{
gen_pool_free(tcm_pool, (unsigned long) addr, len);
}
EXPORT_SYMBOL(tcm_free);
static void __init setup_tcm_bank(u8 type, u32 offset, u32 expected_size)
{
const int tcm_sizes[16] = { 0, -1, -1, 4, 8, 16, 32, 64, 128,
256, 512, 1024, -1, -1, -1, -1 };
u32 tcm_region;
int tcm_size;
/* Read the special TCM region register c9, 0 */
if (!type)
asm("mrc p15, 0, %0, c9, c1, 0"
: "=r" (tcm_region));
else
asm("mrc p15, 0, %0, c9, c1, 1"
: "=r" (tcm_region));
tcm_size = tcm_sizes[(tcm_region >> 2) & 0x0f];
if (tcm_size < 0) {
pr_err("CPU: %sTCM of unknown size!\n",
type ? "I" : "D");
} else {
pr_info("CPU: found %sTCM %dk @ %08x, %senabled\n",
type ? "I" : "D",
tcm_size,
(tcm_region & 0xfffff000U),
(tcm_region & 1) ? "" : "not ");
}
if (tcm_size != expected_size) {
pr_crit("CPU: %sTCM was detected %dk but expected %dk!\n",
type ? "I" : "D",
tcm_size,
expected_size);
/* Adjust to the expected size? what can we do... */
}
/* Force move the TCM bank to where we want it, enable */
tcm_region = offset | (tcm_region & 0x00000ffeU) | 1;
if (!type)
asm("mcr p15, 0, %0, c9, c1, 0"
: /* No output operands */
: "r" (tcm_region));
else
asm("mcr p15, 0, %0, c9, c1, 1"
: /* No output operands */
: "r" (tcm_region));
pr_debug("CPU: moved %sTCM %dk to %08x, enabled\n",
type ? "I" : "D",
tcm_size,
(tcm_region & 0xfffff000U));
}
/*
* This initializes the TCM memory
*/
void __init tcm_init(void)
{
u32 tcm_status = read_cpuid_tcmstatus();
char *start;
char *end;
char *ram;
/* Setup DTCM if present */
if (tcm_status & (1 << 16)) {
setup_tcm_bank(0, DTCM_OFFSET,
(DTCM_END - DTCM_OFFSET + 1) >> 10);
request_resource(&iomem_resource, &dtcm_res);
iotable_init(dtcm_iomap, 1);
/* Copy data from RAM to DTCM */
start = &__sdtcm_data;
end = &__edtcm_data;
ram = &__dtcm_start;
memcpy(start, ram, (end-start));
pr_debug("CPU DTCM: copied data from %p - %p\n", start, end);
}
/* Setup ITCM if present */
if (tcm_status & 1) {
setup_tcm_bank(1, ITCM_OFFSET,
(ITCM_END - ITCM_OFFSET + 1) >> 10);
request_resource(&iomem_resource, &itcm_res);
iotable_init(itcm_iomap, 1);
/* Copy code from RAM to ITCM */
start = &__sitcm_text;
end = &__eitcm_text;
ram = &__itcm_start;
memcpy(start, ram, (end-start));
pr_debug("CPU ITCM: copied code from %p - %p\n", start, end);
}
}
/*
* This creates the TCM memory pool and has to be done later,
* during the core_initicalls, since the allocator is not yet
* up and running when the first initialization runs.
*/
static int __init setup_tcm_pool(void)
{
u32 tcm_status = read_cpuid_tcmstatus();
u32 dtcm_pool_start = (u32) &__edtcm_data;
u32 itcm_pool_start = (u32) &__eitcm_text;
int ret;
/*
* Set up malloc pool, 2^2 = 4 bytes granularity since
* the TCM is sometimes just 4 KiB. NB: pages and cache
* line alignments does not matter in TCM!
*/
tcm_pool = gen_pool_create(2, -1);
pr_debug("Setting up TCM memory pool\n");
/* Add the rest of DTCM to the TCM pool */
if (tcm_status & (1 << 16)) {
if (dtcm_pool_start < DTCM_END) {
ret = gen_pool_add(tcm_pool, dtcm_pool_start,
DTCM_END - dtcm_pool_start + 1, -1);
if (ret) {
pr_err("CPU DTCM: could not add DTCM " \
"remainder to pool!\n");
return ret;
}
pr_debug("CPU DTCM: Added %08x bytes @ %08x to " \
"the TCM memory pool\n",
DTCM_END - dtcm_pool_start + 1,
dtcm_pool_start);
}
}
/* Add the rest of ITCM to the TCM pool */
if (tcm_status & 1) {
if (itcm_pool_start < ITCM_END) {
ret = gen_pool_add(tcm_pool, itcm_pool_start,
ITCM_END - itcm_pool_start + 1, -1);
if (ret) {
pr_err("CPU ITCM: could not add ITCM " \
"remainder to pool!\n");
return ret;
}
pr_debug("CPU ITCM: Added %08x bytes @ %08x to " \
"the TCM memory pool\n",
ITCM_END - itcm_pool_start + 1,
itcm_pool_start);
}
}
return 0;
}
core_initcall(setup_tcm_pool);
/*
* Copyright (C) 2008-2009 ST-Ericsson AB
* License terms: GNU General Public License (GPL) version 2
* TCM memory handling for ARM systems
*
* Author: Linus Walleij <linus.walleij@stericsson.com>
* Author: Rickard Andersson <rickard.andersson@stericsson.com>
*/
#ifdef CONFIG_HAVE_TCM
void __init tcm_init(void);
#else
/* No TCM support, just blank inlines to be optimized out */
inline void tcm_init(void)
{
}
#endif
...@@ -199,6 +199,63 @@ SECTIONS ...@@ -199,6 +199,63 @@ SECTIONS
} }
_edata_loc = __data_loc + SIZEOF(.data); _edata_loc = __data_loc + SIZEOF(.data);
#ifdef CONFIG_HAVE_TCM
/*
* We align everything to a page boundary so we can
* free it after init has commenced and TCM contents have
* been copied to its destination.
*/
.tcm_start : {
. = ALIGN(PAGE_SIZE);
__tcm_start = .;
__itcm_start = .;
}
/*
* Link these to the ITCM RAM
* Put VMA to the TCM address and LMA to the common RAM
* and we'll upload the contents from RAM to TCM and free
* the used RAM after that.
*/
.text_itcm ITCM_OFFSET : AT(__itcm_start)
{
__sitcm_text = .;
*(.tcm.text)
*(.tcm.rodata)
. = ALIGN(4);
__eitcm_text = .;
}
/*
* Reset the dot pointer, this is needed to create the
* relative __dtcm_start below (to be used as extern in code).
*/
. = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm);
.dtcm_start : {
__dtcm_start = .;
}
/* TODO: add remainder of ITCM as well, that can be used for data! */
.data_dtcm DTCM_OFFSET : AT(__dtcm_start)
{
. = ALIGN(4);
__sdtcm_data = .;
*(.tcm.data)
. = ALIGN(4);
__edtcm_data = .;
}
/* Reset the dot pointer or the linker gets confused */
. = ADDR(.dtcm_start) + SIZEOF(.data_dtcm);
/* End marker for freeing TCM copy in linked object */
.tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){
. = ALIGN(PAGE_SIZE);
__tcm_end = .;
}
#endif
.bss : { .bss : {
__bss_start = .; /* BSS */ __bss_start = .; /* BSS */
*(.bss) *(.bss)
......
...@@ -24,10 +24,58 @@ ...@@ -24,10 +24,58 @@
#include <mach/at91sam9g45.h> #include <mach/at91sam9g45.h>
#include <mach/at91sam9g45_matrix.h> #include <mach/at91sam9g45_matrix.h>
#include <mach/at91sam9_smc.h> #include <mach/at91sam9_smc.h>
#include <mach/at_hdmac.h>
#include "generic.h" #include "generic.h"
/* --------------------------------------------------------------------
* HDMAC - AHB DMA Controller
* -------------------------------------------------------------------- */
#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
static u64 hdmac_dmamask = DMA_BIT_MASK(32);
static struct at_dma_platform_data atdma_pdata = {
.nr_channels = 8,
};
static struct resource hdmac_resources[] = {
[0] = {
.start = AT91_BASE_SYS + AT91_DMA,
.end = AT91_BASE_SYS + AT91_DMA + SZ_512 - 1,
.flags = IORESOURCE_MEM,
},
[2] = {
.start = AT91SAM9G45_ID_DMA,
.end = AT91SAM9G45_ID_DMA,
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device at_hdmac_device = {
.name = "at_hdmac",
.id = -1,
.dev = {
.dma_mask = &hdmac_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
.platform_data = &atdma_pdata,
},
.resource = hdmac_resources,
.num_resources = ARRAY_SIZE(hdmac_resources),
};
void __init at91_add_device_hdmac(void)
{
dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
dma_cap_set(DMA_SLAVE, atdma_pdata.cap_mask);
platform_device_register(&at_hdmac_device);
}
#else
void __init at91_add_device_hdmac(void) {}
#endif
/* -------------------------------------------------------------------- /* --------------------------------------------------------------------
* USB Host (OHCI) * USB Host (OHCI)
* -------------------------------------------------------------------- */ * -------------------------------------------------------------------- */
...@@ -1220,6 +1268,7 @@ void __init at91_add_device_serial(void) {} ...@@ -1220,6 +1268,7 @@ void __init at91_add_device_serial(void) {}
*/ */
static int __init at91_add_standard_devices(void) static int __init at91_add_standard_devices(void)
{ {
at91_add_device_hdmac();
at91_add_device_rtc(); at91_add_device_rtc();
at91_add_device_rtt(); at91_add_device_rtt();
at91_add_device_watchdog(); at91_add_device_watchdog();
......
...@@ -21,10 +21,56 @@ ...@@ -21,10 +21,56 @@
#include <mach/at91sam9rl.h> #include <mach/at91sam9rl.h>
#include <mach/at91sam9rl_matrix.h> #include <mach/at91sam9rl_matrix.h>
#include <mach/at91sam9_smc.h> #include <mach/at91sam9_smc.h>
#include <mach/at_hdmac.h>
#include "generic.h" #include "generic.h"
/* --------------------------------------------------------------------
* HDMAC - AHB DMA Controller
* -------------------------------------------------------------------- */
#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
static u64 hdmac_dmamask = DMA_BIT_MASK(32);
static struct at_dma_platform_data atdma_pdata = {
.nr_channels = 2,
};
static struct resource hdmac_resources[] = {
[0] = {
.start = AT91_BASE_SYS + AT91_DMA,
.end = AT91_BASE_SYS + AT91_DMA + SZ_512 - 1,
.flags = IORESOURCE_MEM,
},
[2] = {
.start = AT91SAM9RL_ID_DMA,
.end = AT91SAM9RL_ID_DMA,
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device at_hdmac_device = {
.name = "at_hdmac",
.id = -1,
.dev = {
.dma_mask = &hdmac_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
.platform_data = &atdma_pdata,
},
.resource = hdmac_resources,
.num_resources = ARRAY_SIZE(hdmac_resources),
};
void __init at91_add_device_hdmac(void)
{
dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
platform_device_register(&at_hdmac_device);
}
#else
void __init at91_add_device_hdmac(void) {}
#endif
/* -------------------------------------------------------------------- /* --------------------------------------------------------------------
* USB HS Device (Gadget) * USB HS Device (Gadget)
* -------------------------------------------------------------------- */ * -------------------------------------------------------------------- */
...@@ -1103,6 +1149,7 @@ void __init at91_add_device_serial(void) {} ...@@ -1103,6 +1149,7 @@ void __init at91_add_device_serial(void) {}
*/ */
static int __init at91_add_standard_devices(void) static int __init at91_add_standard_devices(void)
{ {
at91_add_device_hdmac();
at91_add_device_rtc(); at91_add_device_rtc();
at91_add_device_rtt(); at91_add_device_rtt();
at91_add_device_watchdog(); at91_add_device_watchdog();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/amba/bus.h> #include <linux/amba/bus.h>
#include <linux/amba/kmi.h> #include <linux/amba/kmi.h>
#include <linux/amba/clcd.h> #include <linux/amba/clcd.h>
#include <linux/amba/mmci.h>
#include <linux/io.h> #include <linux/io.h>
#include <asm/clkdev.h> #include <asm/clkdev.h>
...@@ -35,7 +36,6 @@ ...@@ -35,7 +36,6 @@
#include <asm/mach/arch.h> #include <asm/mach/arch.h>
#include <asm/mach/flash.h> #include <asm/mach/flash.h>
#include <asm/mach/irq.h> #include <asm/mach/irq.h>
#include <asm/mach/mmc.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
#include <asm/mach/time.h> #include <asm/mach/time.h>
...@@ -400,7 +400,7 @@ static unsigned int mmc_status(struct device *dev) ...@@ -400,7 +400,7 @@ static unsigned int mmc_status(struct device *dev)
return status & 8; return status & 8;
} }
static struct mmc_platform_data mmc_data = { static struct mmci_platform_data mmc_data = {
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.status = mmc_status, .status = mmc_status,
.gpio_wp = -1, .gpio_wp = -1,
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/smsc911x.h> #include <linux/smsc911x.h>
#include <linux/ata_platform.h> #include <linux/ata_platform.h>
#include <linux/amba/mmci.h>
#include <asm/clkdev.h> #include <asm/clkdev.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -44,7 +45,6 @@ ...@@ -44,7 +45,6 @@
#include <asm/mach/flash.h> #include <asm/mach/flash.h>
#include <asm/mach/irq.h> #include <asm/mach/irq.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
#include <asm/mach/mmc.h>
#include <asm/hardware/gic.h> #include <asm/hardware/gic.h>
...@@ -237,14 +237,14 @@ static unsigned int realview_mmc_status(struct device *dev) ...@@ -237,14 +237,14 @@ static unsigned int realview_mmc_status(struct device *dev)
return readl(REALVIEW_SYSMCI) & mask; return readl(REALVIEW_SYSMCI) & mask;
} }
struct mmc_platform_data realview_mmc0_plat_data = { struct mmci_platform_data realview_mmc0_plat_data = {
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.status = realview_mmc_status, .status = realview_mmc_status,
.gpio_wp = 17, .gpio_wp = 17,
.gpio_cd = 16, .gpio_cd = 16,
}; };
struct mmc_platform_data realview_mmc1_plat_data = { struct mmci_platform_data realview_mmc1_plat_data = {
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.status = realview_mmc_status, .status = realview_mmc_status,
.gpio_wp = 19, .gpio_wp = 19,
......
...@@ -47,8 +47,8 @@ static struct amba_device name##_device = { \ ...@@ -47,8 +47,8 @@ static struct amba_device name##_device = { \
extern struct platform_device realview_flash_device; extern struct platform_device realview_flash_device;
extern struct platform_device realview_cf_device; extern struct platform_device realview_cf_device;
extern struct platform_device realview_i2c_device; extern struct platform_device realview_i2c_device;
extern struct mmc_platform_data realview_mmc0_plat_data; extern struct mmci_platform_data realview_mmc0_plat_data;
extern struct mmc_platform_data realview_mmc1_plat_data; extern struct mmci_platform_data realview_mmc1_plat_data;
extern struct clcd_board clcd_plat_data; extern struct clcd_board clcd_plat_data;
extern void __iomem *gic_cpu_base_addr; extern void __iomem *gic_cpu_base_addr;
extern void __iomem *timer0_va_base; extern void __iomem *timer0_va_base;
......
...@@ -34,6 +34,14 @@ ...@@ -34,6 +34,14 @@
(CONFIG_MACH_U300_ACCESS_MEM_SIZE & 1))*1024*1024 + 0x100) (CONFIG_MACH_U300_ACCESS_MEM_SIZE & 1))*1024*1024 + 0x100)
#endif #endif
/*
* TCM memory whereabouts
*/
#define ITCM_OFFSET 0xffff2000
#define ITCM_END 0xffff3fff
#define DTCM_OFFSET 0xffff4000
#define DTCM_END 0xffff5fff
/* /*
* We enable a real big DMA buffer if need be. * We enable a real big DMA buffer if need be.
*/ */
......
...@@ -20,14 +20,14 @@ ...@@ -20,14 +20,14 @@
#include <linux/regulator/machine.h> #include <linux/regulator/machine.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <asm/mach/mmc.h> #include <linux/amba/mmci.h>
#include "mmc.h" #include "mmc.h"
struct mmci_card_event { struct mmci_card_event {
struct input_dev *mmc_input; struct input_dev *mmc_input;
int mmc_inserted; int mmc_inserted;
struct work_struct workq; struct work_struct workq;
struct mmc_platform_data mmc0_plat_data; struct mmci_platform_data mmc0_plat_data;
}; };
static unsigned int mmc_status(struct device *dev) static unsigned int mmc_status(struct device *dev)
...@@ -158,6 +158,8 @@ int __devinit mmc_init(struct amba_device *adev) ...@@ -158,6 +158,8 @@ int __devinit mmc_init(struct amba_device *adev)
mmci_card->mmc0_plat_data.status = mmc_status; mmci_card->mmc0_plat_data.status = mmc_status;
mmci_card->mmc0_plat_data.gpio_wp = -1; mmci_card->mmc0_plat_data.gpio_wp = -1;
mmci_card->mmc0_plat_data.gpio_cd = -1; mmci_card->mmc0_plat_data.gpio_cd = -1;
mmci_card->mmc0_plat_data.capabilities = MMC_CAP_MMC_HIGHSPEED |
MMC_CAP_SD_HIGHSPEED | MMC_CAP_4_BIT_DATA;
mmcsd_device->platform_data = (void *) &mmci_card->mmc0_plat_data; mmcsd_device->platform_data = (void *) &mmci_card->mmc0_plat_data;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/amba/bus.h> #include <linux/amba/bus.h>
#include <linux/amba/clcd.h> #include <linux/amba/clcd.h>
#include <linux/amba/pl061.h> #include <linux/amba/pl061.h>
#include <linux/amba/mmci.h>
#include <linux/clocksource.h> #include <linux/clocksource.h>
#include <linux/clockchips.h> #include <linux/clockchips.h>
#include <linux/cnt32_to_63.h> #include <linux/cnt32_to_63.h>
...@@ -47,7 +48,6 @@ ...@@ -47,7 +48,6 @@
#include <asm/mach/irq.h> #include <asm/mach/irq.h>
#include <asm/mach/time.h> #include <asm/mach/time.h>
#include <asm/mach/map.h> #include <asm/mach/map.h>
#include <asm/mach/mmc.h>
#include "core.h" #include "core.h"
#include "clock.h" #include "clock.h"
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/sysdev.h> #include <linux/sysdev.h>
#include <linux/amba/bus.h> #include <linux/amba/bus.h>
#include <linux/amba/pl061.h> #include <linux/amba/pl061.h>
#include <linux/amba/mmci.h>
#include <linux/io.h> #include <linux/io.h>
#include <mach/hardware.h> #include <mach/hardware.h>
...@@ -31,7 +32,6 @@ ...@@ -31,7 +32,6 @@
#include <asm/mach-types.h> #include <asm/mach-types.h>
#include <asm/mach/arch.h> #include <asm/mach/arch.h>
#include <asm/mach/mmc.h>
#include "core.h" #include "core.h"
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define IRQ_MMCI1A IRQ_SIC_MMCI1A #define IRQ_MMCI1A IRQ_SIC_MMCI1A
#endif #endif
static struct mmc_platform_data mmc1_plat_data = { static struct mmci_platform_data mmc1_plat_data = {
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34, .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.status = mmc_status, .status = mmc_status,
.gpio_wp = -1, .gpio_wp = -1,
......
...@@ -613,6 +613,14 @@ void __init mem_init(void) ...@@ -613,6 +613,14 @@ void __init mem_init(void)
void free_initmem(void) void free_initmem(void)
{ {
#ifdef CONFIG_HAVE_TCM
extern char *__tcm_start, *__tcm_end;
totalram_pages += free_area(__phys_to_pfn(__pa(__tcm_start)),
__phys_to_pfn(__pa(__tcm_end)),
"TCM link");
#endif
if (!machine_is_integrator() && !machine_is_cintegrator()) if (!machine_is_integrator() && !machine_is_cintegrator())
totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)), totalram_pages += free_area(__phys_to_pfn(__pa(__init_begin)),
__phys_to_pfn(__pa(__init_end)), __phys_to_pfn(__pa(__init_end)),
......
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/amba/mmci.h>
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/div64.h> #include <asm/div64.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/sizes.h> #include <asm/sizes.h>
#include <asm/mach/mmc.h>
#include "mmci.h" #include "mmci.h"
...@@ -38,6 +38,36 @@ ...@@ -38,6 +38,36 @@
static unsigned int fmax = 515633; static unsigned int fmax = 515633;
/*
* This must be called with host->lock held
*/
static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
{
u32 clk = 0;
if (desired) {
if (desired >= host->mclk) {
clk = MCI_CLK_BYPASS;
host->cclk = host->mclk;
} else {
clk = host->mclk / (2 * desired) - 1;
if (clk >= 256)
clk = 255;
host->cclk = host->mclk / (2 * (clk + 1));
}
if (host->hw_designer == 0x80)
clk |= MCI_FCEN; /* Bug fix in ST IP block */
clk |= MCI_CLK_ENABLE;
/* This hasn't proven to be worthwhile */
/* clk |= MCI_CLK_PWRSAVE; */
}
if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
clk |= MCI_WIDE_BUS;
writel(clk, host->base + MMCICLOCK);
}
static void static void
mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
{ {
...@@ -419,22 +449,8 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq) ...@@ -419,22 +449,8 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
{ {
struct mmci_host *host = mmc_priv(mmc); struct mmci_host *host = mmc_priv(mmc);
u32 clk = 0, pwr = 0; u32 pwr = 0;
unsigned long flags;
if (ios->clock) {
if (ios->clock >= host->mclk) {
clk = MCI_CLK_BYPASS;
host->cclk = host->mclk;
} else {
clk = host->mclk / (2 * ios->clock) - 1;
if (clk >= 256)
clk = 255;
host->cclk = host->mclk / (2 * (clk + 1));
}
if (host->hw_designer == AMBA_VENDOR_ST)
clk |= MCI_FCEN; /* Bug fix in ST IP block */
clk |= MCI_CLK_ENABLE;
}
if (host->plat->translate_vdd) if (host->plat->translate_vdd)
pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd); pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd);
...@@ -465,12 +481,16 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -465,12 +481,16 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
} }
} }
writel(clk, host->base + MMCICLOCK); spin_lock_irqsave(&host->lock, flags);
mmci_set_clkreg(host, ios->clock);
if (host->pwr != pwr) { if (host->pwr != pwr) {
host->pwr = pwr; host->pwr = pwr;
writel(pwr, host->base + MMCIPOWER); writel(pwr, host->base + MMCIPOWER);
} }
spin_unlock_irqrestore(&host->lock, flags);
} }
static int mmci_get_ro(struct mmc_host *mmc) static int mmci_get_ro(struct mmc_host *mmc)
...@@ -517,7 +537,7 @@ static void mmci_check_status(unsigned long data) ...@@ -517,7 +537,7 @@ static void mmci_check_status(unsigned long data)
static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
{ {
struct mmc_platform_data *plat = dev->dev.platform_data; struct mmci_platform_data *plat = dev->dev.platform_data;
struct mmci_host *host; struct mmci_host *host;
struct mmc_host *mmc; struct mmc_host *mmc;
int ret; int ret;
...@@ -584,6 +604,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id) ...@@ -584,6 +604,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
mmc->f_min = (host->mclk + 511) / 512; mmc->f_min = (host->mclk + 511) / 512;
mmc->f_max = min(host->mclk, fmax); mmc->f_max = min(host->mclk, fmax);
mmc->ocr_avail = plat->ocr_mask; mmc->ocr_avail = plat->ocr_mask;
mmc->caps = plat->capabilities;
/* /*
* We can do SGIO * We can do SGIO
......
...@@ -161,7 +161,7 @@ struct mmci_host { ...@@ -161,7 +161,7 @@ struct mmci_host {
unsigned int mclk; unsigned int mclk;
unsigned int cclk; unsigned int cclk;
u32 pwr; u32 pwr;
struct mmc_platform_data *plat; struct mmci_platform_data *plat;
u8 hw_designer; u8 hw_designer;
u8 hw_revision:4; u8 hw_revision:4;
......
/* /*
* arch/arm/include/asm/mach/mmc.h * include/linux/amba/mmci.h
*/ */
#ifndef ASMARM_MACH_MMC_H #ifndef AMBA_MMCI_H
#define ASMARM_MACH_MMC_H #define AMBA_MMCI_H
#include <linux/mmc/host.h> #include <linux/mmc/host.h>
struct mmc_platform_data { struct mmci_platform_data {
unsigned int ocr_mask; /* available voltages */ unsigned int ocr_mask; /* available voltages */
u32 (*translate_vdd)(struct device *, unsigned int); u32 (*translate_vdd)(struct device *, unsigned int);
unsigned int (*status)(struct device *); unsigned int (*status)(struct device *);
int gpio_wp; int gpio_wp;
int gpio_cd; int gpio_cd;
unsigned long capabilities;
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment