2 * File: arch/arm/plat-omap/fb.c
4 * Framebuffer device registration for TI OMAP platforms
6 * Copyright (C) 2006 Nokia Corporation
7 * Author: Imre Deak <imre.deak@nokia.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/platform_device.h>
28 #include <linux/bootmem.h>
30 #include <asm/hardware.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/map.h>
35 #include <asm/arch/board.h>
36 #include <asm/arch/sram.h>
37 #include <asm/arch/omapfb.h>
39 #if defined(CONFIG_FB_OMAP) || defined(CONFIG_FB_OMAP_MODULE)
41 static struct omapfb_platform_data omapfb_config
;
42 static int config_invalid
;
43 static int configured_regions
;
45 static u64 omap_fb_dma_mask
= ~(u32
)0;
47 static struct platform_device omap_fb_device
= {
51 .dma_mask
= &omap_fb_dma_mask
,
52 .coherent_dma_mask
= ~(u32
)0,
53 .platform_data
= &omapfb_config
,
58 static inline int ranges_overlap(unsigned long start1
, unsigned long size1
,
59 unsigned long start2
, unsigned long size2
)
61 return (start1
>= start2
&& start1
< start2
+ size2
) ||
62 (start2
>= start1
&& start2
< start1
+ size1
);
65 static inline int range_included(unsigned long start1
, unsigned long size1
,
66 unsigned long start2
, unsigned long size2
)
68 return start1
>= start2
&& start1
+ size1
<= start2
+ size2
;
72 /* Check if there is an overlapping region. */
73 static int fbmem_region_reserved(unsigned long start
, size_t size
)
75 struct omapfb_mem_region
*rg
;
78 rg
= &omapfb_config
.mem_desc
.region
[0];
79 for (i
= 0; i
< OMAPFB_PLANE_NUM
; i
++, rg
++) {
83 if (ranges_overlap(start
, size
, rg
->paddr
, rg
->size
))
90 * Get the region_idx`th region from board config/ATAG and convert it to
91 * our internal format.
93 static int get_fbmem_region(int region_idx
, struct omapfb_mem_region
*rg
)
95 const struct omap_fbmem_config
*conf
;
98 conf
= omap_get_nr_config(OMAP_TAG_FBMEM
,
99 struct omap_fbmem_config
, region_idx
);
105 * Low bits encode the page allocation mode, if high bits
106 * are zero. Otherwise we need a page aligned fixed
109 memset(rg
, 0, sizeof(*rg
));
110 rg
->type
= paddr
& ~PAGE_MASK
;
111 rg
->paddr
= paddr
& PAGE_MASK
;
112 rg
->size
= PAGE_ALIGN(conf
->size
);
116 static int set_fbmem_region_type(struct omapfb_mem_region
*rg
, int mem_type
,
117 unsigned long mem_start
,
118 unsigned long mem_size
)
121 * Check if the configuration specifies the type explicitly.
122 * type = 0 && paddr = 0, a default don't care case maps to
125 if (rg
->type
|| (!rg
->type
&& !rg
->paddr
))
127 if (ranges_overlap(rg
->paddr
, rg
->size
, mem_start
, mem_size
)) {
131 /* Can't determine it. */
135 static int check_fbmem_region(int region_idx
, struct omapfb_mem_region
*rg
,
136 unsigned long start_avail
, unsigned size_avail
)
138 unsigned long paddr
= rg
->paddr
;
139 size_t size
= rg
->size
;
141 if (rg
->type
> OMAPFB_MEMTYPE_MAX
) {
143 "Invalid start address for FB region %d\n", region_idx
);
148 printk(KERN_ERR
"Zero size for FB region %d\n", region_idx
);
153 /* Allocate this dynamically, leave paddr 0 for now. */
157 * Fixed region for the given RAM range. Check if it's already
158 * reserved by the FB code or someone else.
160 if (fbmem_region_reserved(paddr
, size
) ||
161 !range_included(paddr
, size
, start_avail
, size_avail
)) {
162 printk(KERN_ERR
"Trying to use reserved memory "
163 "for FB region %d\n", region_idx
);
171 * Called from map_io. We need to call to this early enough so that we
172 * can reserve the fixed SDRAM regions before VM could get hold of them.
174 void __init
omapfb_reserve_sdram(void)
176 struct bootmem_data
*bdata
;
177 unsigned long sdram_start
, sdram_size
;
178 unsigned long reserved
;
184 bdata
= NODE_DATA(0)->bdata
;
185 sdram_start
= bdata
->node_boot_start
;
186 sdram_size
= (bdata
->node_low_pfn
<< PAGE_SHIFT
) - sdram_start
;
189 struct omapfb_mem_region rg
;
191 if (get_fbmem_region(i
, &rg
) < 0)
193 if (i
== OMAPFB_PLANE_NUM
) {
195 "Extraneous FB mem configuration entries\n");
199 /* Check if it's our memory type. */
200 if (set_fbmem_region_type(&rg
, OMAPFB_MEMTYPE_SDRAM
,
201 sdram_start
, sdram_size
) < 0 ||
202 (rg
.type
!= OMAPFB_MEMTYPE_SDRAM
))
204 BUG_ON(omapfb_config
.mem_desc
.region
[i
].size
);
205 if (check_fbmem_region(i
, &rg
, sdram_start
, sdram_size
) < 0) {
210 reserve_bootmem(rg
.paddr
, rg
.size
, BOOTMEM_DEFAULT
);
212 omapfb_config
.mem_desc
.region
[i
] = rg
;
213 configured_regions
++;
215 omapfb_config
.mem_desc
.region_cnt
= i
;
217 pr_info("Reserving %lu bytes SDRAM for frame buffer\n",
222 * Called at sram init time, before anything is pushed to the SRAM stack.
223 * Because of the stack scheme, we will allocate everything from the
224 * start of the lowest address region to the end of SRAM. This will also
225 * include padding for page alignment and possible holes between regions.
227 * As opposed to the SDRAM case, we'll also do any dynamic allocations at
228 * this point, since the driver built as a module would have problem with
229 * freeing / reallocating the regions.
231 unsigned long omapfb_reserve_sram(unsigned long sram_pstart
,
232 unsigned long sram_vstart
,
233 unsigned long sram_size
,
234 unsigned long pstart_avail
,
235 unsigned long size_avail
)
237 struct omapfb_mem_region rg
;
238 unsigned long pend_avail
;
239 unsigned long reserved
;
246 pend_avail
= pstart_avail
+ size_avail
;
248 if (get_fbmem_region(i
, &rg
) < 0)
250 if (i
== OMAPFB_PLANE_NUM
) {
252 "Extraneous FB mem configuration entries\n");
257 /* Check if it's our memory type. */
258 if (set_fbmem_region_type(&rg
, OMAPFB_MEMTYPE_SRAM
,
259 sram_pstart
, sram_size
) < 0 ||
260 (rg
.type
!= OMAPFB_MEMTYPE_SRAM
))
262 BUG_ON(omapfb_config
.mem_desc
.region
[i
].size
);
264 if (check_fbmem_region(i
, &rg
, pstart_avail
, size_avail
) < 0) {
270 /* Dynamic allocation */
271 if ((size_avail
& PAGE_MASK
) < rg
.size
) {
272 printk("Not enough SRAM for FB region %d\n",
277 size_avail
= (size_avail
- rg
.size
) & PAGE_MASK
;
278 rg
.paddr
= pstart_avail
+ size_avail
;
280 /* Reserve everything above the start of the region. */
281 if (pend_avail
- rg
.paddr
> reserved
)
282 reserved
= pend_avail
- rg
.paddr
;
283 size_avail
= pend_avail
- reserved
- pstart_avail
;
286 * We have a kernel mapping for this already, so the
287 * driver won't have to make one.
289 rg
.vaddr
= (void *)(sram_vstart
+ rg
.paddr
- sram_pstart
);
290 omapfb_config
.mem_desc
.region
[i
] = rg
;
291 configured_regions
++;
293 omapfb_config
.mem_desc
.region_cnt
= i
;
295 pr_info("Reserving %lu bytes SRAM for frame buffer\n",
300 void omapfb_set_ctrl_platform_data(void *data
)
302 omapfb_config
.ctrl_platform_data
= data
;
305 static inline int omap_init_fb(void)
307 const struct omap_lcd_config
*conf
;
311 if (configured_regions
!= omapfb_config
.mem_desc
.region_cnt
) {
312 printk(KERN_ERR
"Invalid FB mem configuration entries\n");
315 conf
= omap_get_config(OMAP_TAG_LCD
, struct omap_lcd_config
);
317 if (configured_regions
)
318 /* FB mem config, but no LCD config? */
319 printk(KERN_ERR
"Missing LCD configuration\n");
322 omapfb_config
.lcd
= *conf
;
324 return platform_device_register(&omap_fb_device
);
327 arch_initcall(omap_init_fb
);
331 void omapfb_reserve_sdram(void) {}
332 unsigned long omapfb_reserve_sram(unsigned long sram_pstart
,
333 unsigned long sram_vstart
,
334 unsigned long sram_size
,
335 unsigned long start_avail
,
336 unsigned long size_avail
)