blob: 5ec104b5408b37d58e25efa202439110150a21c2 [file] [log] [blame]
Kukjin Kimd9c452f2012-04-17 20:21:30 -07001/*
Kamil Debski0f75a962011-07-21 16:42:30 +09002 * Copyright (C) 2010-2011 Samsung Electronics Co.Ltd
3 *
4 * Base S5P MFC resource and device definitions
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Kamil Debski0f75a962011-07-21 16:42:30 +090011#include <linux/kernel.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/dma-mapping.h>
15#include <linux/memblock.h>
16#include <linux/ioport.h>
Arun Kumar K2eae6132012-10-23 22:51:33 +090017#include <linux/of_fdt.h>
18#include <linux/of.h>
Kamil Debski0f75a962011-07-21 16:42:30 +090019
20#include <mach/map.h>
21#include <plat/devs.h>
22#include <plat/irqs.h>
23#include <plat/mfc.h>
24
Kamil Debski0f75a962011-07-21 16:42:30 +090025struct s5p_mfc_reserved_mem {
26 phys_addr_t base;
27 unsigned long size;
28 struct device *dev;
29};
30
31static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
32
33void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
34 phys_addr_t lbase, unsigned int lsize)
35{
36 int i;
37
38 s5p_mfc_mem[0].dev = &s5p_device_mfc_r.dev;
39 s5p_mfc_mem[0].base = rbase;
40 s5p_mfc_mem[0].size = rsize;
41
42 s5p_mfc_mem[1].dev = &s5p_device_mfc_l.dev;
43 s5p_mfc_mem[1].base = lbase;
44 s5p_mfc_mem[1].size = lsize;
45
46 for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
47 struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
48 if (memblock_remove(area->base, area->size)) {
49 printk(KERN_ERR "Failed to reserve memory for MFC device (%ld bytes at 0x%08lx)\n",
50 area->size, (unsigned long) area->base);
51 area->base = 0;
52 }
53 }
54}
55
56static int __init s5p_mfc_memory_init(void)
57{
58 int i;
59
60 for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
61 struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
62 if (!area->base)
63 continue;
64
65 if (dma_declare_coherent_memory(area->dev, area->base,
66 area->base, area->size,
67 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0)
68 printk(KERN_ERR "Failed to declare coherent memory for MFC device (%ld bytes at 0x%08lx)\n",
69 area->size, (unsigned long) area->base);
70 }
71 return 0;
72}
73device_initcall(s5p_mfc_memory_init);
Arun Kumar K2eae6132012-10-23 22:51:33 +090074
75#ifdef CONFIG_OF
76int __init s5p_fdt_find_mfc_mem(unsigned long node, const char *uname,
77 int depth, void *data)
78{
79 __be32 *prop;
80 unsigned long len;
81 struct s5p_mfc_dt_meminfo *mfc_mem = data;
82
83 if (!data)
84 return 0;
85
86 if (!of_flat_dt_is_compatible(node, mfc_mem->compatible))
87 return 0;
88
89 prop = of_get_flat_dt_prop(node, "samsung,mfc-l", &len);
90 if (!prop || (len != 2 * sizeof(unsigned long)))
91 return 0;
92
93 mfc_mem->loff = be32_to_cpu(prop[0]);
94 mfc_mem->lsize = be32_to_cpu(prop[1]);
95
96 prop = of_get_flat_dt_prop(node, "samsung,mfc-r", &len);
97 if (!prop || (len != 2 * sizeof(unsigned long)))
98 return 0;
99
100 mfc_mem->roff = be32_to_cpu(prop[0]);
101 mfc_mem->rsize = be32_to_cpu(prop[1]);
102
103 return 1;
104}
105#endif