blob: 195a760eef542b4adcd30a2678c5fc9fe7273a69 [file] [log] [blame]
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +03001/*
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
Ville Syrjälä2f642a12010-03-17 20:58:03 +020030#include <linux/rwsem.h>
31
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030032#include <plat/display.h>
33
34#ifdef DEBUG
35extern unsigned int omapfb_debug;
36#define DBG(format, ...) \
37 if (omapfb_debug) \
38 printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__)
39#else
40#define DBG(format, ...)
41#endif
42
43#define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
44
45/* max number of overlays to which a framebuffer data can be direct */
46#define OMAPFB_MAX_OVL_PER_FB 3
47
48struct omapfb2_mem_region {
Ville Syrjälä078ff542010-03-17 20:36:51 +020049 int id;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030050 u32 paddr;
51 void __iomem *vaddr;
52 struct vrfb vrfb;
53 unsigned long size;
54 u8 type; /* OMAPFB_PLANE_MEM_* */
55 bool alloc; /* allocated by the driver */
56 bool map; /* kernel mapped by the driver */
Ville Syrjälä078ff542010-03-17 20:36:51 +020057 atomic_t map_count;
Ville Syrjälä2f642a12010-03-17 20:58:03 +020058 struct rw_semaphore lock;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030059};
60
61/* appended to fb_info */
62struct omapfb_info {
63 int id;
Ville Syrjälä078ff542010-03-17 20:36:51 +020064 struct omapfb2_mem_region *region;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030065 int num_overlays;
66 struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
67 struct omapfb2_device *fbdev;
68 enum omap_dss_rotation_type rotation_type;
69 u8 rotation[OMAPFB_MAX_OVL_PER_FB];
70 bool mirror;
71};
72
73struct omapfb2_device {
74 struct device *dev;
75 struct mutex mtx;
76
77 u32 pseudo_palette[17];
78
79 int state;
80
81 unsigned num_fbs;
82 struct fb_info *fbs[10];
Ville Syrjälä078ff542010-03-17 20:36:51 +020083 struct omapfb2_mem_region regions[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030084
85 unsigned num_displays;
86 struct omap_dss_device *displays[10];
87 unsigned num_overlays;
88 struct omap_overlay *overlays[10];
89 unsigned num_managers;
90 struct omap_overlay_manager *managers[10];
Tomi Valkeinena2699502010-01-11 14:33:40 +020091
92 unsigned num_bpp_overrides;
93 struct {
94 struct omap_dss_device *dssdev;
95 u8 bpp;
96 } bpp_overrides[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030097};
98
99struct omapfb_colormode {
100 enum omap_color_mode dssmode;
101 u32 bits_per_pixel;
102 u32 nonstd;
103 struct fb_bitfield red;
104 struct fb_bitfield green;
105 struct fb_bitfield blue;
106 struct fb_bitfield transp;
107};
108
109void set_fb_fix(struct fb_info *fbi);
110int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
111int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
112int omapfb_apply_changes(struct fb_info *fbi, int init);
113
114int omapfb_create_sysfs(struct omapfb2_device *fbdev);
115void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
116
117int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
118
Tomi Valkeinenb63c97f2010-02-05 14:46:19 +0200119int omapfb_update_window(struct fb_info *fbi,
120 u32 x, u32 y, u32 w, u32 h);
121
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300122int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
123 struct fb_var_screeninfo *var);
124
Ville Syrjälä078ff542010-03-17 20:36:51 +0200125int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
126 u16 posx, u16 posy, u16 outw, u16 outh);
127
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300128/* find the display connected to this fb, if any */
129static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
130{
131 struct omapfb_info *ofbi = FB2OFB(fbi);
132 int i;
133
134 /* XXX: returns the display connected to first attached overlay */
135 for (i = 0; i < ofbi->num_overlays; i++) {
136 if (ofbi->overlays[i]->manager)
137 return ofbi->overlays[i]->manager->device;
138 }
139
140 return NULL;
141}
142
143static inline void omapfb_lock(struct omapfb2_device *fbdev)
144{
145 mutex_lock(&fbdev->mtx);
146}
147
148static inline void omapfb_unlock(struct omapfb2_device *fbdev)
149{
150 mutex_unlock(&fbdev->mtx);
151}
152
153static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
154 int enable)
155{
156 struct omap_overlay_info info;
157
158 ovl->get_overlay_info(ovl, &info);
Ville Syrjälä2ad0c502010-03-17 20:13:44 +0200159 if (info.enabled == enable)
160 return 0;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300161 info.enabled = enable;
162 return ovl->set_overlay_info(ovl, &info);
163}
164
Ville Syrjälä430571d2010-03-17 20:43:23 +0200165static inline struct omapfb2_mem_region *
166omapfb_get_mem_region(struct omapfb2_mem_region *rg)
167{
Ville Syrjälä2f642a12010-03-17 20:58:03 +0200168 down_read(&rg->lock);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200169 return rg;
170}
171
172static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
173{
Ville Syrjälä2f642a12010-03-17 20:58:03 +0200174 up_read(&rg->lock);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200175}
176
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300177#endif