diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2011-03-03 14:21:53 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-05-19 13:11:19 +0200 |
commit | 031e912741746e4350204bb0436590ca0e993a7d (patch) | |
tree | 96cc0f4baa356dda8a7b7d23deb0447a2d7e051f /arch/arm/mach-mx3/mach-mx31moboard.c | |
parent | dca7c0b4293a06d1ed9387e729a4882896abccc2 (diff) | |
download | lwn-031e912741746e4350204bb0436590ca0e993a7d.tar.gz lwn-031e912741746e4350204bb0436590ca0e993a7d.zip |
ARM: mx3/mx31moboard: properly allocate memory for mx3-camera
It's not allowed to create an alias of system RAM for DMA. So the memory
used must not be allocated using dma_alloc_coherent but has to be reserved
before using memblock routines.
There is no need to memzero the buffer because dma_alloc_coherent zeros
the memory for us.
LAKML-Reference: 1299271882-2130-4-git-send-email-u.kleine-koenig@pengutronix.de
Tested-by: Philippe Retornaz <philippe.retornaz@epfl.ch>
Acked-by: Philippe Retornaz <philippe.retornaz@epfl.ch>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-mx3/mach-mx31moboard.c')
-rw-r--r-- | arch/arm/mach-mx3/mach-mx31moboard.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c index 9c163146071d..6c13061b6ac2 100644 --- a/arch/arm/mach-mx3/mach-mx31moboard.c +++ b/arch/arm/mach-mx3/mach-mx31moboard.c @@ -27,6 +27,7 @@ #include <linux/mfd/mc13783.h> #include <linux/spi/spi.h> #include <linux/types.h> +#include <linux/memblock.h> #include <linux/usb/otg.h> #include <linux/usb/ulpi.h> @@ -472,27 +473,17 @@ static struct mx3_camera_pdata camera_pdata = { .mclk_10khz = 4800, }; -#define CAMERA_BUF_SIZE (4*1024*1024) +static phys_addr_t mx3_camera_base __initdata; +#define MX3_CAMERA_BUF_SIZE SZ_4M -static int __init mx31moboard_cam_alloc_dma(const size_t buf_size) +static int __init mx31moboard_cam_alloc_dma(void) { - dma_addr_t dma_handle; - void *buf; int dma; - if (buf_size < 2 * 1024 * 1024) - return -EINVAL; - - buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL); - if (!buf) { - pr_err("%s: cannot allocate camera buffer-memory\n", __func__); - return -ENOMEM; - } - - memset(buf, 0, buf_size); dma = dma_declare_coherent_memory(&mx3_camera.dev, - dma_handle, dma_handle, buf_size, + mx3_camera_base, mx3_camera_base, + MX3_CAMERA_BUF_SIZE, DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); /* The way we call dma_declare_coherent_memory only a malloc can fail */ @@ -529,7 +520,7 @@ static void __init mx31moboard_init(void) imx31_add_mxc_mmc(0, &sdhc1_pdata); mxc_register_device(&mx3_ipu, &mx3_ipu_data); - if (!mx31moboard_cam_alloc_dma(CAMERA_BUF_SIZE)) + if (!mx31moboard_cam_alloc_dma()) mxc_register_device(&mx3_camera, &camera_pdata); usb_xcvr_reset(); @@ -564,9 +555,19 @@ struct sys_timer mx31moboard_timer = { .init = mx31moboard_timer_init, }; +static void __init mx31moboard_reserve(void) +{ + /* reserve 4 MiB for mx3-camera */ + mx3_camera_base = memblock_alloc(MX3_CAMERA_BUF_SIZE, + MX3_CAMERA_BUF_SIZE); + memblock_free(mx3_camera_base, MX3_CAMERA_BUF_SIZE); + memblock_remove(mx3_camera_base, MX3_CAMERA_BUF_SIZE); +} + MACHINE_START(MX31MOBOARD, "EPFL Mobots mx31moboard") /* Maintainer: Valentin Longchamp, EPFL Mobots group */ .boot_params = MX3x_PHYS_OFFSET + 0x100, + .reserve = mx31moboard_reserve, .map_io = mx31_map_io, .init_early = imx31_init_early, .init_irq = mx31_init_irq, |