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