omapfb.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <linux/dma-attrs.h>
  29. #include <linux/dma-mapping.h>
  30. #include <video/omapdss.h>
  31. #ifdef DEBUG
  32. extern bool omapfb_debug;
  33. #define DBG(format, ...) \
  34. do { \
  35. if (omapfb_debug) \
  36. printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
  37. } while (0)
  38. #else
  39. #define DBG(format, ...)
  40. #endif
  41. #define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
  42. /* max number of overlays to which a framebuffer data can be direct */
  43. #define OMAPFB_MAX_OVL_PER_FB 3
  44. struct omapfb2_mem_region {
  45. int id;
  46. struct dma_attrs attrs;
  47. void *token;
  48. dma_addr_t dma_handle;
  49. u32 paddr;
  50. void __iomem *vaddr;
  51. struct vrfb vrfb;
  52. unsigned long size;
  53. u8 type; /* OMAPFB_PLANE_MEM_* */
  54. bool alloc; /* allocated by the driver */
  55. bool map; /* kernel mapped by the driver */
  56. atomic_t map_count;
  57. struct rw_semaphore lock;
  58. atomic_t lock_count;
  59. };
  60. /* appended to fb_info */
  61. struct omapfb_info {
  62. int id;
  63. struct omapfb2_mem_region *region;
  64. int num_overlays;
  65. struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
  66. struct omapfb2_device *fbdev;
  67. enum omap_dss_rotation_type rotation_type;
  68. u8 rotation[OMAPFB_MAX_OVL_PER_FB];
  69. bool mirror;
  70. };
  71. struct omapfb_display_data {
  72. struct omapfb2_device *fbdev;
  73. struct omap_dss_device *dssdev;
  74. u8 bpp_override;
  75. enum omapfb_update_mode update_mode;
  76. bool auto_update_work_enabled;
  77. struct delayed_work auto_update_work;
  78. };
  79. struct omapfb2_device {
  80. struct device *dev;
  81. struct mutex mtx;
  82. u32 pseudo_palette[17];
  83. int state;
  84. unsigned num_fbs;
  85. struct fb_info *fbs[10];
  86. struct omapfb2_mem_region regions[10];
  87. unsigned num_displays;
  88. struct omapfb_display_data displays[10];
  89. unsigned num_overlays;
  90. struct omap_overlay *overlays[10];
  91. unsigned num_managers;
  92. struct omap_overlay_manager *managers[10];
  93. struct workqueue_struct *auto_update_wq;
  94. };
  95. struct omapfb_colormode {
  96. enum omap_color_mode dssmode;
  97. u32 bits_per_pixel;
  98. u32 nonstd;
  99. struct fb_bitfield red;
  100. struct fb_bitfield green;
  101. struct fb_bitfield blue;
  102. struct fb_bitfield transp;
  103. };
  104. void set_fb_fix(struct fb_info *fbi);
  105. int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
  106. int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
  107. int omapfb_apply_changes(struct fb_info *fbi, int init);
  108. int omapfb_create_sysfs(struct omapfb2_device *fbdev);
  109. void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
  110. int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
  111. int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
  112. struct fb_var_screeninfo *var);
  113. int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
  114. u16 posx, u16 posy, u16 outw, u16 outh);
  115. void omapfb_start_auto_update(struct omapfb2_device *fbdev,
  116. struct omap_dss_device *display);
  117. void omapfb_stop_auto_update(struct omapfb2_device *fbdev,
  118. struct omap_dss_device *display);
  119. int omapfb_get_update_mode(struct fb_info *fbi, enum omapfb_update_mode *mode);
  120. int omapfb_set_update_mode(struct fb_info *fbi, enum omapfb_update_mode mode);
  121. /* find the display connected to this fb, if any */
  122. static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
  123. {
  124. struct omapfb_info *ofbi = FB2OFB(fbi);
  125. struct omap_overlay *ovl;
  126. /* XXX: returns the display connected to first attached overlay */
  127. if (ofbi->num_overlays == 0)
  128. return NULL;
  129. ovl = ofbi->overlays[0];
  130. return ovl->get_device(ovl);
  131. }
  132. static inline struct omapfb_display_data *get_display_data(
  133. struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
  134. {
  135. int i;
  136. for (i = 0; i < fbdev->num_displays; ++i)
  137. if (fbdev->displays[i].dssdev == dssdev)
  138. return &fbdev->displays[i];
  139. /* This should never happen */
  140. BUG();
  141. return NULL;
  142. }
  143. static inline void omapfb_lock(struct omapfb2_device *fbdev)
  144. {
  145. mutex_lock(&fbdev->mtx);
  146. }
  147. static inline void omapfb_unlock(struct omapfb2_device *fbdev)
  148. {
  149. mutex_unlock(&fbdev->mtx);
  150. }
  151. static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
  152. int enable)
  153. {
  154. if (enable)
  155. return ovl->enable(ovl);
  156. else
  157. return ovl->disable(ovl);
  158. }
  159. static inline struct omapfb2_mem_region *
  160. omapfb_get_mem_region(struct omapfb2_mem_region *rg)
  161. {
  162. down_read_nested(&rg->lock, rg->id);
  163. atomic_inc(&rg->lock_count);
  164. return rg;
  165. }
  166. static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
  167. {
  168. atomic_dec(&rg->lock_count);
  169. up_read(&rg->lock);
  170. }
  171. #endif