Linux 3.14.25
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / arm / plat-samsung / s5p-dev-mfc.c
1 /*
2  * 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
11 #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>
17 #include <linux/of_fdt.h>
18 #include <linux/of.h>
19
20 #include <plat/mfc.h>
21
22 #ifdef CONFIG_SAMSUNG_ATAGS
23 #include <mach/map.h>
24 #include <mach/irqs.h>
25 #include <plat/devs.h>
26
27 static struct resource s5p_mfc_resource[] = {
28         [0] = DEFINE_RES_MEM(S5P_PA_MFC, SZ_64K),
29         [1] = DEFINE_RES_IRQ(IRQ_MFC),
30 };
31
32 struct platform_device s5p_device_mfc = {
33         .name           = "s5p-mfc",
34         .id             = -1,
35         .num_resources  = ARRAY_SIZE(s5p_mfc_resource),
36         .resource       = s5p_mfc_resource,
37 };
38
39 /*
40  * MFC hardware has 2 memory interfaces which are modelled as two separate
41  * platform devices to let dma-mapping distinguish between them.
42  *
43  * MFC parent device (s5p_device_mfc) must be registered before memory
44  * interface specific devices (s5p_device_mfc_l and s5p_device_mfc_r).
45  */
46
47 struct platform_device s5p_device_mfc_l = {
48         .name           = "s5p-mfc-l",
49         .id             = -1,
50         .dev            = {
51                 .parent                 = &s5p_device_mfc.dev,
52                 .dma_mask               = &s5p_device_mfc_l.dev.coherent_dma_mask,
53                 .coherent_dma_mask      = DMA_BIT_MASK(32),
54         },
55 };
56
57 struct platform_device s5p_device_mfc_r = {
58         .name           = "s5p-mfc-r",
59         .id             = -1,
60         .dev            = {
61                 .parent                 = &s5p_device_mfc.dev,
62                 .dma_mask               = &s5p_device_mfc_r.dev.coherent_dma_mask,
63                 .coherent_dma_mask      = DMA_BIT_MASK(32),
64         },
65 };
66 #else
67 static struct platform_device s5p_device_mfc_l;
68 static struct platform_device s5p_device_mfc_r;
69 #endif
70
71 struct s5p_mfc_reserved_mem {
72         phys_addr_t     base;
73         unsigned long   size;
74         struct device   *dev;
75 };
76
77 static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
78
79
80 void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
81                                 phys_addr_t lbase, unsigned int lsize)
82 {
83         int i;
84
85         s5p_mfc_mem[0].dev = &s5p_device_mfc_r.dev;
86         s5p_mfc_mem[0].base = rbase;
87         s5p_mfc_mem[0].size = rsize;
88
89         s5p_mfc_mem[1].dev = &s5p_device_mfc_l.dev;
90         s5p_mfc_mem[1].base = lbase;
91         s5p_mfc_mem[1].size = lsize;
92
93         for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
94                 struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
95                 if (memblock_remove(area->base, area->size)) {
96                         printk(KERN_ERR "Failed to reserve memory for MFC device (%ld bytes at 0x%08lx)\n",
97                                area->size, (unsigned long) area->base);
98                         area->base = 0;
99                 }
100         }
101 }
102
103 #ifdef CONFIG_SAMSUNG_ATAGS
104 static int __init s5p_mfc_memory_init(void)
105 {
106         int i;
107
108         for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
109                 struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
110                 if (!area->base)
111                         continue;
112
113                 if (dma_declare_coherent_memory(area->dev, area->base,
114                                 area->base, area->size,
115                                 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0)
116                         printk(KERN_ERR "Failed to declare coherent memory for MFC device (%ld bytes at 0x%08lx)\n",
117                                area->size, (unsigned long) area->base);
118         }
119         return 0;
120 }
121 device_initcall(s5p_mfc_memory_init);
122 #endif
123
124 #ifdef CONFIG_OF
125 int __init s5p_fdt_find_mfc_mem(unsigned long node, const char *uname,
126                                 int depth, void *data)
127 {
128         __be32 *prop;
129         unsigned long len;
130         struct s5p_mfc_dt_meminfo *mfc_mem = data;
131
132         if (!data)
133                 return 0;
134
135         if (!of_flat_dt_is_compatible(node, mfc_mem->compatible))
136                 return 0;
137
138         prop = of_get_flat_dt_prop(node, "samsung,mfc-l", &len);
139         if (!prop || (len != 2 * sizeof(unsigned long)))
140                 return 0;
141
142         mfc_mem->loff = be32_to_cpu(prop[0]);
143         mfc_mem->lsize = be32_to_cpu(prop[1]);
144
145         prop = of_get_flat_dt_prop(node, "samsung,mfc-r", &len);
146         if (!prop || (len != 2 * sizeof(unsigned long)))
147                 return 0;
148
149         mfc_mem->roff = be32_to_cpu(prop[0]);
150         mfc_mem->rsize = be32_to_cpu(prop[1]);
151
152         return 1;
153 }
154 #endif