blob: f07dbbb08db19b116ce7c8f1a8aa5e1182e5824a [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 Valkeinena0b38cc2011-05-11 14:05:07 +030032#include <video/omapdss.h>
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030033
34#ifdef DEBUG
35extern unsigned int omapfb_debug;
36#define DBG(format, ...) \
Niels de Vos41b21ae2011-05-10 12:07:33 +010037 do { \
38 if (omapfb_debug) \
39 printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
40 } while (0)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030041#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 {
Ville Syrjälä078ff542010-03-17 20:36:51 +020051 int id;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030052 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 */
Ville Syrjälä078ff542010-03-17 20:36:51 +020059 atomic_t map_count;
Ville Syrjälä2f642a12010-03-17 20:58:03 +020060 struct rw_semaphore lock;
Ville Syrjälä1ceafc02010-03-17 21:28:50 +020061 atomic_t lock_count;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030062};
63
64/* appended to fb_info */
65struct omapfb_info {
66 int id;
Ville Syrjälä078ff542010-03-17 20:36:51 +020067 struct omapfb2_mem_region *region;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030068 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
Tomi Valkeinen065a40b2011-04-30 12:13:14 +030076struct omapfb_display_data {
77 struct omap_dss_device *dssdev;
78 u8 bpp_override;
79};
80
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030081struct omapfb2_device {
82 struct device *dev;
83 struct mutex mtx;
84
85 u32 pseudo_palette[17];
86
87 int state;
88
89 unsigned num_fbs;
90 struct fb_info *fbs[10];
Ville Syrjälä078ff542010-03-17 20:36:51 +020091 struct omapfb2_mem_region regions[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030092
93 unsigned num_displays;
Tomi Valkeinen065a40b2011-04-30 12:13:14 +030094 struct omapfb_display_data displays[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030095 unsigned num_overlays;
96 struct omap_overlay *overlays[10];
97 unsigned num_managers;
98 struct omap_overlay_manager *managers[10];
99};
100
101struct omapfb_colormode {
102 enum omap_color_mode dssmode;
103 u32 bits_per_pixel;
104 u32 nonstd;
105 struct fb_bitfield red;
106 struct fb_bitfield green;
107 struct fb_bitfield blue;
108 struct fb_bitfield transp;
109};
110
111void set_fb_fix(struct fb_info *fbi);
112int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
113int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
114int omapfb_apply_changes(struct fb_info *fbi, int init);
115
116int omapfb_create_sysfs(struct omapfb2_device *fbdev);
117void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
118
119int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
120
Tomi Valkeinenb63c97f2010-02-05 14:46:19 +0200121int omapfb_update_window(struct fb_info *fbi,
122 u32 x, u32 y, u32 w, u32 h);
123
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300124int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
125 struct fb_var_screeninfo *var);
126
Ville Syrjälä078ff542010-03-17 20:36:51 +0200127int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
128 u16 posx, u16 posy, u16 outw, u16 outh);
129
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300130/* find the display connected to this fb, if any */
131static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
132{
133 struct omapfb_info *ofbi = FB2OFB(fbi);
134 int i;
135
136 /* XXX: returns the display connected to first attached overlay */
137 for (i = 0; i < ofbi->num_overlays; i++) {
138 if (ofbi->overlays[i]->manager)
139 return ofbi->overlays[i]->manager->device;
140 }
141
142 return NULL;
143}
144
Tomi Valkeinen065a40b2011-04-30 12:13:14 +0300145static inline struct omapfb_display_data *get_display_data(
146 struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
147{
148 int i;
149
150 for (i = 0; i < fbdev->num_displays; ++i)
151 if (fbdev->displays[i].dssdev == dssdev)
152 return &fbdev->displays[i];
153
154 /* This should never happen */
155 BUG();
156}
157
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300158static inline void omapfb_lock(struct omapfb2_device *fbdev)
159{
160 mutex_lock(&fbdev->mtx);
161}
162
163static inline void omapfb_unlock(struct omapfb2_device *fbdev)
164{
165 mutex_unlock(&fbdev->mtx);
166}
167
168static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
169 int enable)
170{
171 struct omap_overlay_info info;
172
173 ovl->get_overlay_info(ovl, &info);
Ville Syrjälä2ad0c502010-03-17 20:13:44 +0200174 if (info.enabled == enable)
175 return 0;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300176 info.enabled = enable;
177 return ovl->set_overlay_info(ovl, &info);
178}
179
Ville Syrjälä430571d2010-03-17 20:43:23 +0200180static inline struct omapfb2_mem_region *
181omapfb_get_mem_region(struct omapfb2_mem_region *rg)
182{
Ville Syrjälä3d84b652010-03-17 21:42:06 +0200183 down_read_nested(&rg->lock, rg->id);
Ville Syrjälä1ceafc02010-03-17 21:28:50 +0200184 atomic_inc(&rg->lock_count);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200185 return rg;
186}
187
188static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
189{
Ville Syrjälä1ceafc02010-03-17 21:28:50 +0200190 atomic_dec(&rg->lock_count);
Ville Syrjälä2f642a12010-03-17 20:58:03 +0200191 up_read(&rg->lock);
Ville Syrjälä430571d2010-03-17 20:43:23 +0200192}
193
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300194#endif