2 * linux/drivers/video/mmp/common.c
3 * This driver is a common framework for Marvell Display Controller
5 * Copyright (C) 2012 Marvell Technology Group Ltd.
6 * Authors: Zhou Zhu <zzhu3@marvell.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <linux/slab.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/export.h>
26 #include <linux/module.h>
27 #include <video/mmp_disp.h>
29 static struct mmp_overlay
*path_get_overlay(struct mmp_path
*path
,
32 if (path
&& overlay_id
< path
->overlay_num
)
33 return &path
->overlays
[overlay_id
];
37 static int path_check_status(struct mmp_path
*path
)
40 for (i
= 0; i
< path
->overlay_num
; i
++)
41 if (path
->overlays
[i
].status
)
48 * Get modelist write pointer of modelist.
49 * It also returns modelist number
50 * this function fetches modelist from phy/panel:
51 * for HDMI/parallel or dsi to hdmi cases, get from phy
54 static int path_get_modelist(struct mmp_path
*path
,
55 struct mmp_mode
**modelist
)
57 BUG_ON(!path
|| !modelist
);
59 if (path
->panel
&& path
->panel
->get_modelist
)
60 return path
->panel
->get_modelist(path
->panel
, modelist
);
66 * panel list is used to pair panel/path when path/panel registered
67 * path list is used for both buffer driver and platdriver
68 * plat driver do path register/unregister
69 * panel driver do panel register/unregister
70 * buffer driver get registered path
72 static LIST_HEAD(panel_list
);
73 static LIST_HEAD(path_list
);
74 static DEFINE_MUTEX(disp_lock
);
77 * mmp_register_panel - register panel to panel_list and connect to path
78 * @p: panel to be registered
80 * this function provides interface for panel drivers to register panel
81 * to panel_list and connect to path which matchs panel->plat_path_name.
82 * no error returns when no matching path is found as path register after
83 * panel register is permitted.
85 void mmp_register_panel(struct mmp_panel
*panel
)
87 struct mmp_path
*path
;
89 mutex_lock(&disp_lock
);
92 list_add_tail(&panel
->node
, &panel_list
);
94 /* try to register to path */
95 list_for_each_entry(path
, &path_list
, node
) {
96 if (!strcmp(panel
->plat_path_name
, path
->name
)) {
97 dev_info(panel
->dev
, "connect to path %s\n",
104 mutex_unlock(&disp_lock
);
106 EXPORT_SYMBOL_GPL(mmp_register_panel
);
109 * mmp_unregister_panel - unregister panel from panel_list and disconnect
110 * @p: panel to be unregistered
112 * this function provides interface for panel drivers to unregister panel
113 * from panel_list and disconnect from path.
115 void mmp_unregister_panel(struct mmp_panel
*panel
)
117 struct mmp_path
*path
;
119 mutex_lock(&disp_lock
);
120 list_del(&panel
->node
);
122 list_for_each_entry(path
, &path_list
, node
) {
123 if (path
->panel
&& path
->panel
== panel
) {
124 dev_info(panel
->dev
, "disconnect from path %s\n",
130 mutex_unlock(&disp_lock
);
132 EXPORT_SYMBOL_GPL(mmp_unregister_panel
);
135 * mmp_get_path - get path by name
138 * this function checks path name in path_list and return matching path
139 * return NULL if no matching path
141 struct mmp_path
*mmp_get_path(const char *name
)
143 struct mmp_path
*path
;
146 mutex_lock(&disp_lock
);
147 list_for_each_entry(path
, &path_list
, node
) {
148 if (!strcmp(name
, path
->name
)) {
153 mutex_unlock(&disp_lock
);
155 return found
? path
: NULL
;
157 EXPORT_SYMBOL_GPL(mmp_get_path
);
160 * mmp_register_path - init and register path by path_info
161 * @p: path info provided by display controller
163 * this function init by path info and register path to path_list
164 * this function also try to connect path with panel by name
166 struct mmp_path
*mmp_register_path(struct mmp_path_info
*info
)
170 struct mmp_path
*path
= NULL
;
171 struct mmp_panel
*panel
;
173 size
= sizeof(struct mmp_path
)
174 + sizeof(struct mmp_overlay
) * info
->overlay_num
;
175 path
= kzalloc(size
, GFP_KERNEL
);
180 mutex_init(&path
->access_ok
);
181 path
->dev
= info
->dev
;
183 path
->name
= info
->name
;
184 path
->output_type
= info
->output_type
;
185 path
->overlay_num
= info
->overlay_num
;
186 path
->plat_data
= info
->plat_data
;
187 path
->ops
.set_mode
= info
->set_mode
;
189 mutex_lock(&disp_lock
);
191 list_for_each_entry(panel
, &panel_list
, node
) {
192 if (!strcmp(info
->name
, panel
->plat_path_name
)) {
193 dev_info(path
->dev
, "get panel %s\n", panel
->name
);
199 dev_info(path
->dev
, "register %s, overlay_num %d\n",
200 path
->name
, path
->overlay_num
);
202 /* default op set: if already set by driver, never cover it */
203 if (!path
->ops
.check_status
)
204 path
->ops
.check_status
= path_check_status
;
205 if (!path
->ops
.get_overlay
)
206 path
->ops
.get_overlay
= path_get_overlay
;
207 if (!path
->ops
.get_modelist
)
208 path
->ops
.get_modelist
= path_get_modelist
;
210 /* step3: init overlays */
211 for (i
= 0; i
< path
->overlay_num
; i
++) {
212 path
->overlays
[i
].path
= path
;
213 path
->overlays
[i
].id
= i
;
214 mutex_init(&path
->overlays
[i
].access_ok
);
215 path
->overlays
[i
].ops
= info
->overlay_ops
;
218 /* add to pathlist */
219 list_add_tail(&path
->node
, &path_list
);
221 mutex_unlock(&disp_lock
);
224 EXPORT_SYMBOL_GPL(mmp_register_path
);
227 * mmp_unregister_path - unregister and destroy path
228 * @p: path to be destroyed.
230 * this function registers path and destroys it.
232 void mmp_unregister_path(struct mmp_path
*path
)
239 mutex_lock(&disp_lock
);
240 /* del from pathlist */
241 list_del(&path
->node
);
243 /* deinit overlays */
244 for (i
= 0; i
< path
->overlay_num
; i
++)
245 mutex_destroy(&path
->overlays
[i
].access_ok
);
247 mutex_destroy(&path
->access_ok
);
250 mutex_unlock(&disp_lock
);
252 EXPORT_SYMBOL_GPL(mmp_unregister_path
);
254 MODULE_AUTHOR("Zhou Zhu <zzhu3@marvell.com>");
255 MODULE_DESCRIPTION("Marvell MMP display framework");
256 MODULE_LICENSE("GPL");