blob: 2b5264475ed410aa9003bd584898e06628ac99c8 [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>
Tomi Valkeinen0049fb22012-11-09 15:52:20 +020031#include <linux/dma-attrs.h>
32#include <linux/dma-mapping.h>
Ville Syrjälä2f642a12010-03-17 20:58:03 +020033
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030034#include <video/omapdss.h>
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030035
36#ifdef DEBUG
Rusty Russell90ab5ee2012-01-13 09:32:20 +103037extern bool omapfb_debug;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030038#define DBG(format, ...) \
Niels de Vos41b21ae2011-05-10 12:07:33 +010039 do { \
40 if (omapfb_debug) \
41 printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
42 } while (0)
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030043#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
52struct omapfb2_mem_region {
Ville Syrjälä078ff542010-03-17 20:36:51 +020053 int id;
Tomi Valkeinen0049fb22012-11-09 15:52:20 +020054 struct dma_attrs attrs;
55 void *token;
56 dma_addr_t dma_handle;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030057 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 */
Ville Syrjälä078ff542010-03-17 20:36:51 +020064 atomic_t map_count;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030065};
66
67/* appended to fb_info */
68struct omapfb_info {
69 int id;
Ville Syrjälä078ff542010-03-17 20:36:51 +020070 struct omapfb2_mem_region *region;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030071 int num_overlays;
72 struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
73 struct omapfb2_device *fbdev;
74 enum omap_dss_rotation_type rotation_type;
75 u8 rotation[OMAPFB_MAX_OVL_PER_FB];
76 bool mirror;
77};
78
Tomi Valkeinen065a40b2011-04-30 12:13:14 +030079struct omapfb_display_data {
Tomi Valkeinen27cc2132011-04-30 16:55:12 +030080 struct omapfb2_device *fbdev;
Tomi Valkeinen065a40b2011-04-30 12:13:14 +030081 struct omap_dss_device *dssdev;
82 u8 bpp_override;
Tomi Valkeinen27cc2132011-04-30 16:55:12 +030083 enum omapfb_update_mode update_mode;
84 bool auto_update_work_enabled;
85 struct delayed_work auto_update_work;
Tomi Valkeinen065a40b2011-04-30 12:13:14 +030086};
87
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030088struct omapfb2_device {
89 struct device *dev;
90 struct mutex mtx;
91
92 u32 pseudo_palette[17];
93
94 int state;
95
96 unsigned num_fbs;
97 struct fb_info *fbs[10];
Ville Syrjälä078ff542010-03-17 20:36:51 +020098 struct omapfb2_mem_region regions[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +030099
100 unsigned num_displays;
Tomi Valkeinen065a40b2011-04-30 12:13:14 +0300101 struct omapfb_display_data displays[10];
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300102 unsigned num_overlays;
103 struct omap_overlay *overlays[10];
104 unsigned num_managers;
105 struct omap_overlay_manager *managers[10];
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300106
107 struct workqueue_struct *auto_update_wq;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300108};
109
110struct omapfb_colormode {
111 enum omap_color_mode dssmode;
112 u32 bits_per_pixel;
113 u32 nonstd;
114 struct fb_bitfield red;
115 struct fb_bitfield green;
116 struct fb_bitfield blue;
117 struct fb_bitfield transp;
118};
119
120void set_fb_fix(struct fb_info *fbi);
121int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
122int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
123int omapfb_apply_changes(struct fb_info *fbi, int init);
124
125int omapfb_create_sysfs(struct omapfb2_device *fbdev);
126void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
127
128int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
129
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300130int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
131 struct fb_var_screeninfo *var);
132
Ville Syrjälä078ff542010-03-17 20:36:51 +0200133int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
134 u16 posx, u16 posy, u16 outw, u16 outh);
135
Tomi Valkeinen27cc2132011-04-30 16:55:12 +0300136void 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
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300143/* 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);
Tomi Valkeinenc7e1eae2012-12-13 12:17:08 +0200147 struct omap_overlay *ovl;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300148
149 /* XXX: returns the display connected to first attached overlay */
Archit Taneja4249e612012-07-20 18:26:56 +0530150
Tomi Valkeinenc7e1eae2012-12-13 12:17:08 +0200151 if (ofbi->num_overlays == 0)
152 return NULL;
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300153
Tomi Valkeinenc7e1eae2012-12-13 12:17:08 +0200154 ovl = ofbi->overlays[0];
155
156 return ovl->get_device(ovl);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300157}
158
Tomi Valkeinen065a40b2011-04-30 12:13:14 +0300159static inline struct omapfb_display_data *get_display_data(
160 struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
161{
162 int i;
163
164 for (i = 0; i < fbdev->num_displays; ++i)
165 if (fbdev->displays[i].dssdev == dssdev)
166 return &fbdev->displays[i];
167
168 /* This should never happen */
169 BUG();
Tomi Valkeinen4a75cb82012-05-18 11:48:28 +0300170 return NULL;
Tomi Valkeinen065a40b2011-04-30 12:13:14 +0300171}
172
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300173static inline void omapfb_lock(struct omapfb2_device *fbdev)
174{
175 mutex_lock(&fbdev->mtx);
176}
177
178static inline void omapfb_unlock(struct omapfb2_device *fbdev)
179{
180 mutex_unlock(&fbdev->mtx);
181}
182
183static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
184 int enable)
185{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200186 if (enable)
187 return ovl->enable(ovl);
188 else
189 return ovl->disable(ovl);
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300190}
191
Tomi Valkeinenb39a982d2009-08-04 16:12:50 +0300192#endif