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