omapfb.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * linux/drivers/video/omap2/omapfb.h
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
  23. #define __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
  24. #ifdef CONFIG_FB_OMAP2_DEBUG_SUPPORT
  25. #define DEBUG
  26. #endif
  27. #include <linux/rwsem.h>
  28. #include <video/omapdss.h>
  29. #ifdef DEBUG
  30. extern unsigned int omapfb_debug;
  31. #define DBG(format, ...) \
  32. do { \
  33. if (omapfb_debug) \
  34. printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
  35. } while (0)
  36. #else
  37. #define DBG(format, ...)
  38. #endif
  39. #define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
  40. /* max number of overlays to which a framebuffer data can be direct */
  41. #define OMAPFB_MAX_OVL_PER_FB 3
  42. struct omapfb2_mem_region {
  43. int id;
  44. u32 paddr;
  45. void __iomem *vaddr;
  46. struct vrfb vrfb;
  47. unsigned long size;
  48. u8 type; /* OMAPFB_PLANE_MEM_* */
  49. bool alloc; /* allocated by the driver */
  50. bool map; /* kernel mapped by the driver */
  51. atomic_t map_count;
  52. struct rw_semaphore lock;
  53. atomic_t lock_count;
  54. };
  55. /* appended to fb_info */
  56. struct omapfb_info {
  57. int id;
  58. struct omapfb2_mem_region *region;
  59. int num_overlays;
  60. struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
  61. struct omapfb2_device *fbdev;
  62. enum omap_dss_rotation_type rotation_type;
  63. u8 rotation[OMAPFB_MAX_OVL_PER_FB];
  64. bool mirror;
  65. };
  66. struct omapfb_display_data {
  67. struct omap_dss_device *dssdev;
  68. u8 bpp_override;
  69. };
  70. struct omapfb2_device {
  71. struct device *dev;
  72. struct mutex mtx;
  73. u32 pseudo_palette[17];
  74. int state;
  75. unsigned num_fbs;
  76. struct fb_info *fbs[10];
  77. struct omapfb2_mem_region regions[10];
  78. unsigned num_displays;
  79. struct omapfb_display_data displays[10];
  80. unsigned num_overlays;
  81. struct omap_overlay *overlays[10];
  82. unsigned num_managers;
  83. struct omap_overlay_manager *managers[10];
  84. };
  85. struct omapfb_colormode {
  86. enum omap_color_mode dssmode;
  87. u32 bits_per_pixel;
  88. u32 nonstd;
  89. struct fb_bitfield red;
  90. struct fb_bitfield green;
  91. struct fb_bitfield blue;
  92. struct fb_bitfield transp;
  93. };
  94. void set_fb_fix(struct fb_info *fbi);
  95. int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
  96. int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
  97. int omapfb_apply_changes(struct fb_info *fbi, int init);
  98. int omapfb_create_sysfs(struct omapfb2_device *fbdev);
  99. void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
  100. int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
  101. int omapfb_update_window(struct fb_info *fbi,
  102. u32 x, u32 y, u32 w, u32 h);
  103. int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
  104. struct fb_var_screeninfo *var);
  105. int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
  106. u16 posx, u16 posy, u16 outw, u16 outh);
  107. /* find the display connected to this fb, if any */
  108. static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
  109. {
  110. struct omapfb_info *ofbi = FB2OFB(fbi);
  111. int i;
  112. /* XXX: returns the display connected to first attached overlay */
  113. for (i = 0; i < ofbi->num_overlays; i++) {
  114. if (ofbi->overlays[i]->manager)
  115. return ofbi->overlays[i]->manager->device;
  116. }
  117. return NULL;
  118. }
  119. static inline struct omapfb_display_data *get_display_data(
  120. struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
  121. {
  122. int i;
  123. for (i = 0; i < fbdev->num_displays; ++i)
  124. if (fbdev->displays[i].dssdev == dssdev)
  125. return &fbdev->displays[i];
  126. /* This should never happen */
  127. BUG();
  128. }
  129. static inline void omapfb_lock(struct omapfb2_device *fbdev)
  130. {
  131. mutex_lock(&fbdev->mtx);
  132. }
  133. static inline void omapfb_unlock(struct omapfb2_device *fbdev)
  134. {
  135. mutex_unlock(&fbdev->mtx);
  136. }
  137. static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
  138. int enable)
  139. {
  140. struct omap_overlay_info info;
  141. ovl->get_overlay_info(ovl, &info);
  142. if (info.enabled == enable)
  143. return 0;
  144. info.enabled = enable;
  145. return ovl->set_overlay_info(ovl, &info);
  146. }
  147. static inline struct omapfb2_mem_region *
  148. omapfb_get_mem_region(struct omapfb2_mem_region *rg)
  149. {
  150. down_read_nested(&rg->lock, rg->id);
  151. atomic_inc(&rg->lock_count);
  152. return rg;
  153. }
  154. static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
  155. {
  156. atomic_dec(&rg->lock_count);
  157. up_read(&rg->lock);
  158. }
  159. #endif