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