fb.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * File: arch/arm/plat-omap/fb.c
  3. *
  4. * Framebuffer device registration for TI OMAP platforms
  5. *
  6. * Copyright (C) 2006 Nokia Corporation
  7. * Author: Imre Deak <imre.deak@nokia.com>
  8. *
  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.
  13. *
  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.
  18. *
  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.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mm.h>
  26. #include <linux/init.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/memblock.h>
  29. #include <linux/io.h>
  30. #include <linux/omapfb.h>
  31. #include <mach/hardware.h>
  32. #include <asm/mach/map.h>
  33. #include <plat/board.h>
  34. #if defined(CONFIG_FB_OMAP) || defined(CONFIG_FB_OMAP_MODULE)
  35. static struct omapfb_platform_data omapfb_config;
  36. static int config_invalid;
  37. static int configured_regions;
  38. static u64 omap_fb_dma_mask = ~(u32)0;
  39. static struct platform_device omap_fb_device = {
  40. .name = "omapfb",
  41. .id = -1,
  42. .dev = {
  43. .dma_mask = &omap_fb_dma_mask,
  44. .coherent_dma_mask = ~(u32)0,
  45. .platform_data = &omapfb_config,
  46. },
  47. .num_resources = 0,
  48. };
  49. void omapfb_set_platform_data(struct omapfb_platform_data *data)
  50. {
  51. }
  52. static inline int ranges_overlap(unsigned long start1, unsigned long size1,
  53. unsigned long start2, unsigned long size2)
  54. {
  55. return (start1 >= start2 && start1 < start2 + size2) ||
  56. (start2 >= start1 && start2 < start1 + size1);
  57. }
  58. static inline int range_included(unsigned long start1, unsigned long size1,
  59. unsigned long start2, unsigned long size2)
  60. {
  61. return start1 >= start2 && start1 + size1 <= start2 + size2;
  62. }
  63. /*
  64. * Get the region_idx`th region from board config/ATAG and convert it to
  65. * our internal format.
  66. */
  67. static int __init get_fbmem_region(int region_idx, struct omapfb_mem_region *rg)
  68. {
  69. const struct omap_fbmem_config *conf;
  70. u32 paddr;
  71. conf = omap_get_nr_config(OMAP_TAG_FBMEM,
  72. struct omap_fbmem_config, region_idx);
  73. if (conf == NULL)
  74. return -ENOENT;
  75. paddr = conf->start;
  76. /*
  77. * Low bits encode the page allocation mode, if high bits
  78. * are zero. Otherwise we need a page aligned fixed
  79. * address.
  80. */
  81. memset(rg, 0, sizeof(*rg));
  82. rg->type = paddr & ~PAGE_MASK;
  83. rg->paddr = paddr & PAGE_MASK;
  84. rg->size = PAGE_ALIGN(conf->size);
  85. return 0;
  86. }
  87. static int valid_sdram(unsigned long addr, unsigned long size)
  88. {
  89. return memblock_is_region_memory(addr, size);
  90. }
  91. static int reserve_sdram(unsigned long addr, unsigned long size)
  92. {
  93. if (memblock_is_region_reserved(addr, size))
  94. return -EBUSY;
  95. if (memblock_reserve(addr, size))
  96. return -ENOMEM;
  97. return 0;
  98. }
  99. /*
  100. * Called from map_io. We need to call to this early enough so that we
  101. * can reserve the fixed SDRAM regions before VM could get hold of them.
  102. */
  103. void __init omapfb_reserve_sdram_memblock(void)
  104. {
  105. unsigned long reserved = 0;
  106. int i;
  107. if (config_invalid)
  108. return;
  109. for (i = 0; ; i++) {
  110. struct omapfb_mem_region rg;
  111. if (get_fbmem_region(i, &rg) < 0)
  112. break;
  113. if (i == OMAPFB_PLANE_NUM) {
  114. pr_err("Extraneous FB mem configuration entries\n");
  115. config_invalid = 1;
  116. return;
  117. }
  118. /* Check if it's our memory type. */
  119. if (rg.type != OMAPFB_MEMTYPE_SDRAM)
  120. continue;
  121. /* Check if the region falls within SDRAM */
  122. if (rg.paddr && !valid_sdram(rg.paddr, rg.size))
  123. continue;
  124. if (rg.size == 0) {
  125. pr_err("Zero size for FB region %d\n", i);
  126. config_invalid = 1;
  127. return;
  128. }
  129. if (rg.paddr) {
  130. if (reserve_sdram(rg.paddr, rg.size)) {
  131. pr_err("Trying to use reserved memory for FB region %d\n",
  132. i);
  133. config_invalid = 1;
  134. return;
  135. }
  136. reserved += rg.size;
  137. }
  138. if (omapfb_config.mem_desc.region[i].size) {
  139. pr_err("FB region %d already set\n", i);
  140. config_invalid = 1;
  141. return;
  142. }
  143. omapfb_config.mem_desc.region[i] = rg;
  144. configured_regions++;
  145. }
  146. omapfb_config.mem_desc.region_cnt = i;
  147. if (reserved)
  148. pr_info("Reserving %lu bytes SDRAM for frame buffer\n",
  149. reserved);
  150. }
  151. static int __init omap_init_fb(void)
  152. {
  153. const struct omap_lcd_config *conf;
  154. if (config_invalid)
  155. return 0;
  156. if (configured_regions != omapfb_config.mem_desc.region_cnt) {
  157. printk(KERN_ERR "Invalid FB mem configuration entries\n");
  158. return 0;
  159. }
  160. conf = omap_get_config(OMAP_TAG_LCD, struct omap_lcd_config);
  161. if (conf == NULL) {
  162. if (configured_regions)
  163. /* FB mem config, but no LCD config? */
  164. printk(KERN_ERR "Missing LCD configuration\n");
  165. return 0;
  166. }
  167. omapfb_config.lcd = *conf;
  168. return platform_device_register(&omap_fb_device);
  169. }
  170. arch_initcall(omap_init_fb);
  171. #elif defined(CONFIG_FB_OMAP2) || defined(CONFIG_FB_OMAP2_MODULE)
  172. static u64 omap_fb_dma_mask = ~(u32)0;
  173. static struct omapfb_platform_data omapfb_config;
  174. static struct platform_device omap_fb_device = {
  175. .name = "omapfb",
  176. .id = -1,
  177. .dev = {
  178. .dma_mask = &omap_fb_dma_mask,
  179. .coherent_dma_mask = ~(u32)0,
  180. .platform_data = &omapfb_config,
  181. },
  182. .num_resources = 0,
  183. };
  184. void omapfb_set_platform_data(struct omapfb_platform_data *data)
  185. {
  186. omapfb_config = *data;
  187. }
  188. static int __init omap_init_fb(void)
  189. {
  190. return platform_device_register(&omap_fb_device);
  191. }
  192. arch_initcall(omap_init_fb);
  193. void omapfb_reserve_sdram_memblock(void)
  194. {
  195. }
  196. #else
  197. void omapfb_set_platform_data(struct omapfb_platform_data *data)
  198. {
  199. }
  200. void omapfb_reserve_sdram_memblock(void)
  201. {
  202. }
  203. #endif