1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * linux/drivers/video/omap2/omapfb.h
4  *
5  * Copyright (C) 2008 Nokia Corporation
6  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7  *
8  * Some code and ideas taken from drivers/video/omap/ driver
9  * by Imre Deak.
10  */
11 
12 #ifndef __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
13 #define __DRIVERS_VIDEO_OMAP2_OMAPFB_H__
14 
15 #ifdef CONFIG_FB_OMAP2_DEBUG_SUPPORT
16 #define DEBUG
17 #endif
18 
19 #include <linux/rwsem.h>
20 #include <linux/dma-mapping.h>
21 
22 #include <video/omapfb_dss.h>
23 
24 #ifdef DEBUG
25 extern bool omapfb_debug;
26 #define DBG(format, ...) \
27 	do { \
28 		if (omapfb_debug) \
29 			printk(KERN_DEBUG "OMAPFB: " format, ## __VA_ARGS__); \
30 	} while (0)
31 #else
32 #define DBG(format, ...) no_printk(format, ## __VA_ARGS__)
33 #endif
34 
35 #define FB2OFB(fb_info) ((struct omapfb_info *)(fb_info->par))
36 
37 /* max number of overlays to which a framebuffer data can be direct */
38 #define OMAPFB_MAX_OVL_PER_FB 3
39 
40 struct omapfb2_mem_region {
41 	int             id;
42 	unsigned long	attrs;
43 	void		*token;
44 	dma_addr_t	dma_handle;
45 	u32		paddr;
46 	void __iomem	*vaddr;
47 	struct vrfb	vrfb;
48 	unsigned long	size;
49 	u8		type;		/* OMAPFB_PLANE_MEM_* */
50 	bool		alloc;		/* allocated by the driver */
51 	bool		map;		/* kernel mapped by the driver */
52 	atomic_t	map_count;
53 	struct rw_semaphore lock;
54 	atomic_t	lock_count;
55 };
56 
57 /* appended to fb_info */
58 struct omapfb_info {
59 	int id;
60 	struct omapfb2_mem_region *region;
61 	int num_overlays;
62 	struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
63 	struct omapfb2_device *fbdev;
64 	enum omap_dss_rotation_type rotation_type;
65 	u8 rotation[OMAPFB_MAX_OVL_PER_FB];
66 	bool mirror;
67 };
68 
69 struct omapfb_display_data {
70 	struct omapfb2_device *fbdev;
71 	struct omap_dss_device *dssdev;
72 	u8 bpp_override;
73 	enum omapfb_update_mode update_mode;
74 	bool auto_update_work_enabled;
75 	struct delayed_work auto_update_work;
76 };
77 
78 struct omapfb2_device {
79 	struct device *dev;
80 	struct mutex  mtx;
81 
82 	u32 pseudo_palette[17];
83 
84 	int state;
85 
86 	unsigned num_fbs;
87 	struct fb_info *fbs[10];
88 	struct omapfb2_mem_region regions[10];
89 
90 	unsigned num_displays;
91 	struct omapfb_display_data displays[10];
92 	unsigned num_overlays;
93 	struct omap_overlay *overlays[10];
94 	unsigned num_managers;
95 	struct omap_overlay_manager *managers[10];
96 
97 	struct workqueue_struct *auto_update_wq;
98 };
99 
100 struct omapfb_colormode {
101 	enum omap_color_mode dssmode;
102 	u32 bits_per_pixel;
103 	u32 nonstd;
104 	struct fb_bitfield red;
105 	struct fb_bitfield green;
106 	struct fb_bitfield blue;
107 	struct fb_bitfield transp;
108 };
109 
110 void set_fb_fix(struct fb_info *fbi);
111 int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var);
112 int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type);
113 int omapfb_apply_changes(struct fb_info *fbi, int init);
114 
115 int omapfb_create_sysfs(struct omapfb2_device *fbdev);
116 void omapfb_remove_sysfs(struct omapfb2_device *fbdev);
117 
118 int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg);
119 
120 int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
121 			struct fb_var_screeninfo *var);
122 
123 int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
124 		u16 posx, u16 posy, u16 outw, u16 outh);
125 
126 void omapfb_start_auto_update(struct omapfb2_device *fbdev,
127 		struct omap_dss_device *display);
128 void omapfb_stop_auto_update(struct omapfb2_device *fbdev,
129 		struct omap_dss_device *display);
130 int omapfb_get_update_mode(struct fb_info *fbi, enum omapfb_update_mode *mode);
131 int omapfb_set_update_mode(struct fb_info *fbi, enum omapfb_update_mode mode);
132 
133 /* find the display connected to this fb, if any */
fb2display(struct fb_info * fbi)134 static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
135 {
136 	struct omapfb_info *ofbi = FB2OFB(fbi);
137 	struct omap_overlay *ovl;
138 
139 	/* XXX: returns the display connected to first attached overlay */
140 
141 	if (ofbi->num_overlays == 0)
142 		return NULL;
143 
144 	ovl = ofbi->overlays[0];
145 
146 	return ovl->get_device(ovl);
147 }
148 
get_display_data(struct omapfb2_device * fbdev,struct omap_dss_device * dssdev)149 static inline struct omapfb_display_data *get_display_data(
150 		struct omapfb2_device *fbdev, struct omap_dss_device *dssdev)
151 {
152 	int i;
153 
154 	for (i = 0; i < fbdev->num_displays; ++i)
155 		if (fbdev->displays[i].dssdev == dssdev)
156 			return &fbdev->displays[i];
157 
158 	/* This should never happen */
159 	BUG();
160 	return NULL;
161 }
162 
omapfb_lock(struct omapfb2_device * fbdev)163 static inline void omapfb_lock(struct omapfb2_device *fbdev)
164 {
165 	mutex_lock(&fbdev->mtx);
166 }
167 
omapfb_unlock(struct omapfb2_device * fbdev)168 static inline void omapfb_unlock(struct omapfb2_device *fbdev)
169 {
170 	mutex_unlock(&fbdev->mtx);
171 }
172 
omapfb_overlay_enable(struct omap_overlay * ovl,int enable)173 static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
174 		int enable)
175 {
176 	if (enable)
177 		return ovl->enable(ovl);
178 	else
179 		return ovl->disable(ovl);
180 }
181 
182 static inline struct omapfb2_mem_region *
omapfb_get_mem_region(struct omapfb2_mem_region * rg)183 omapfb_get_mem_region(struct omapfb2_mem_region *rg)
184 {
185 	down_read_nested(&rg->lock, rg->id);
186 	atomic_inc(&rg->lock_count);
187 	return rg;
188 }
189 
omapfb_put_mem_region(struct omapfb2_mem_region * rg)190 static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
191 {
192 	atomic_dec(&rg->lock_count);
193 	up_read(&rg->lock);
194 }
195 
196 #endif
197