aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mx3/mach-mx31moboard.c
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2011-03-03 08:21:53 -0500
committerSascha Hauer <s.hauer@pengutronix.de>2011-05-19 07:11:19 -0400
commit031e912741746e4350204bb0436590ca0e993a7d (patch)
tree96cc0f4baa356dda8a7b7d23deb0447a2d7e051f /arch/arm/mach-mx3/mach-mx31moboard.c
parentdca7c0b4293a06d1ed9387e729a4882896abccc2 (diff)
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.c33
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 @@
27#include <linux/mfd/mc13783.h> 27#include <linux/mfd/mc13783.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/memblock.h>
30 31
31#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
32#include <linux/usb/ulpi.h> 33#include <linux/usb/ulpi.h>
@@ -472,27 +473,17 @@ static struct mx3_camera_pdata camera_pdata = {
472 .mclk_10khz = 4800, 473 .mclk_10khz = 4800,
473}; 474};
474 475
475#define CAMERA_BUF_SIZE (4*1024*1024) 476static phys_addr_t mx3_camera_base __initdata;
477#define MX3_CAMERA_BUF_SIZE SZ_4M
476 478
477static int __init mx31moboard_cam_alloc_dma(const size_t buf_size) 479static int __init mx31moboard_cam_alloc_dma(void)
478{ 480{
479 dma_addr_t dma_handle;
480 void *buf;
481 int dma; 481 int dma;
482 482
483 if (buf_size < 2 * 1024 * 1024)
484 return -EINVAL;
485
486 buf = dma_alloc_coherent(NULL, buf_size, &dma_handle, GFP_KERNEL);
487 if (!buf) {
488 pr_err("%s: cannot allocate camera buffer-memory\n", __func__);
489 return -ENOMEM;
490 }
491
492 memset(buf, 0, buf_size);
493 483
494 dma = dma_declare_coherent_memory(&mx3_camera.dev, 484 dma = dma_declare_coherent_memory(&mx3_camera.dev,
495 dma_handle, dma_handle, buf_size, 485 mx3_camera_base, mx3_camera_base,
486 MX3_CAMERA_BUF_SIZE,
496 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); 487 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
497 488
498 /* The way we call dma_declare_coherent_memory only a malloc can fail */ 489 /* The way we call dma_declare_coherent_memory only a malloc can fail */
@@ -529,7 +520,7 @@ static void __init mx31moboard_init(void)
529 imx31_add_mxc_mmc(0, &sdhc1_pdata); 520 imx31_add_mxc_mmc(0, &sdhc1_pdata);
530 521
531 mxc_register_device(&mx3_ipu, &mx3_ipu_data); 522 mxc_register_device(&mx3_ipu, &mx3_ipu_data);
532 if (!mx31moboard_cam_alloc_dma(CAMERA_BUF_SIZE)) 523 if (!mx31moboard_cam_alloc_dma())
533 mxc_register_device(&mx3_camera, &camera_pdata); 524 mxc_register_device(&mx3_camera, &camera_pdata);
534 525
535 usb_xcvr_reset(); 526 usb_xcvr_reset();
@@ -564,9 +555,19 @@ struct sys_timer mx31moboard_timer = {
564 .init = mx31moboard_timer_init, 555 .init = mx31moboard_timer_init,
565}; 556};
566 557
558static void __init mx31moboard_reserve(void)
559{
560 /* reserve 4 MiB for mx3-camera */
561 mx3_camera_base = memblock_alloc(MX3_CAMERA_BUF_SIZE,
562 MX3_CAMERA_BUF_SIZE);
563 memblock_free(mx3_camera_base, MX3_CAMERA_BUF_SIZE);
564 memblock_remove(mx3_camera_base, MX3_CAMERA_BUF_SIZE);
565}
566
567MACHINE_START(MX31MOBOARD, "EPFL Mobots mx31moboard") 567MACHINE_START(MX31MOBOARD, "EPFL Mobots mx31moboard")
568 /* Maintainer: Valentin Longchamp, EPFL Mobots group */ 568 /* Maintainer: Valentin Longchamp, EPFL Mobots group */
569 .boot_params = MX3x_PHYS_OFFSET + 0x100, 569 .boot_params = MX3x_PHYS_OFFSET + 0x100,
570 .reserve = mx31moboard_reserve,
570 .map_io = mx31_map_io, 571 .map_io = mx31_map_io,
571 .init_early = imx31_init_early, 572 .init_early = imx31_init_early,
572 .init_irq = mx31_init_irq, 573 .init_irq = mx31_init_irq,