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