sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / video / fbdev / mmp / core.c
bloba0f496049db7dcae8b2b2fbf833de980297e2ab4
1 /*
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
16 * more details.
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 <video/mmp_disp.h>
28 static struct mmp_overlay *path_get_overlay(struct mmp_path *path,
29 int overlay_id)
31 if (path && overlay_id < path->overlay_num)
32 return &path->overlays[overlay_id];
33 return NULL;
36 static int path_check_status(struct mmp_path *path)
38 int i;
39 for (i = 0; i < path->overlay_num; i++)
40 if (path->overlays[i].status)
41 return 1;
43 return 0;
47 * Get modelist write pointer of modelist.
48 * It also returns modelist number
49 * this function fetches modelist from phy/panel:
50 * for HDMI/parallel or dsi to hdmi cases, get from phy
51 * or get from panel
53 static int path_get_modelist(struct mmp_path *path,
54 struct mmp_mode **modelist)
56 BUG_ON(!path || !modelist);
58 if (path->panel && path->panel->get_modelist)
59 return path->panel->get_modelist(path->panel, modelist);
61 return 0;
65 * panel list is used to pair panel/path when path/panel registered
66 * path list is used for both buffer driver and platdriver
67 * plat driver do path register/unregister
68 * panel driver do panel register/unregister
69 * buffer driver get registered path
71 static LIST_HEAD(panel_list);
72 static LIST_HEAD(path_list);
73 static DEFINE_MUTEX(disp_lock);
76 * mmp_register_panel - register panel to panel_list and connect to path
77 * @p: panel to be registered
79 * this function provides interface for panel drivers to register panel
80 * to panel_list and connect to path which matchs panel->plat_path_name.
81 * no error returns when no matching path is found as path register after
82 * panel register is permitted.
84 void mmp_register_panel(struct mmp_panel *panel)
86 struct mmp_path *path;
88 mutex_lock(&disp_lock);
90 /* add */
91 list_add_tail(&panel->node, &panel_list);
93 /* try to register to path */
94 list_for_each_entry(path, &path_list, node) {
95 if (!strcmp(panel->plat_path_name, path->name)) {
96 dev_info(panel->dev, "connect to path %s\n",
97 path->name);
98 path->panel = panel;
99 break;
103 mutex_unlock(&disp_lock);
105 EXPORT_SYMBOL_GPL(mmp_register_panel);
108 * mmp_unregister_panel - unregister panel from panel_list and disconnect
109 * @p: panel to be unregistered
111 * this function provides interface for panel drivers to unregister panel
112 * from panel_list and disconnect from path.
114 void mmp_unregister_panel(struct mmp_panel *panel)
116 struct mmp_path *path;
118 mutex_lock(&disp_lock);
119 list_del(&panel->node);
121 list_for_each_entry(path, &path_list, node) {
122 if (path->panel && path->panel == panel) {
123 dev_info(panel->dev, "disconnect from path %s\n",
124 path->name);
125 path->panel = NULL;
126 break;
129 mutex_unlock(&disp_lock);
131 EXPORT_SYMBOL_GPL(mmp_unregister_panel);
134 * mmp_get_path - get path by name
135 * @p: path name
137 * this function checks path name in path_list and return matching path
138 * return NULL if no matching path
140 struct mmp_path *mmp_get_path(const char *name)
142 struct mmp_path *path;
143 int found = 0;
145 mutex_lock(&disp_lock);
146 list_for_each_entry(path, &path_list, node) {
147 if (!strcmp(name, path->name)) {
148 found = 1;
149 break;
152 mutex_unlock(&disp_lock);
154 return found ? path : NULL;
156 EXPORT_SYMBOL_GPL(mmp_get_path);
159 * mmp_register_path - init and register path by path_info
160 * @p: path info provided by display controller
162 * this function init by path info and register path to path_list
163 * this function also try to connect path with panel by name
165 struct mmp_path *mmp_register_path(struct mmp_path_info *info)
167 int i;
168 size_t size;
169 struct mmp_path *path = NULL;
170 struct mmp_panel *panel;
172 size = sizeof(struct mmp_path)
173 + sizeof(struct mmp_overlay) * info->overlay_num;
174 path = kzalloc(size, GFP_KERNEL);
175 if (!path)
176 return NULL;
178 /* path set */
179 mutex_init(&path->access_ok);
180 path->dev = info->dev;
181 path->id = info->id;
182 path->name = info->name;
183 path->output_type = info->output_type;
184 path->overlay_num = info->overlay_num;
185 path->plat_data = info->plat_data;
186 path->ops.set_mode = info->set_mode;
188 mutex_lock(&disp_lock);
189 /* get panel */
190 list_for_each_entry(panel, &panel_list, node) {
191 if (!strcmp(info->name, panel->plat_path_name)) {
192 dev_info(path->dev, "get panel %s\n", panel->name);
193 path->panel = panel;
194 break;
198 dev_info(path->dev, "register %s, overlay_num %d\n",
199 path->name, path->overlay_num);
201 /* default op set: if already set by driver, never cover it */
202 if (!path->ops.check_status)
203 path->ops.check_status = path_check_status;
204 if (!path->ops.get_overlay)
205 path->ops.get_overlay = path_get_overlay;
206 if (!path->ops.get_modelist)
207 path->ops.get_modelist = path_get_modelist;
209 /* step3: init overlays */
210 for (i = 0; i < path->overlay_num; i++) {
211 path->overlays[i].path = path;
212 path->overlays[i].id = i;
213 mutex_init(&path->overlays[i].access_ok);
214 path->overlays[i].ops = info->overlay_ops;
217 /* add to pathlist */
218 list_add_tail(&path->node, &path_list);
220 mutex_unlock(&disp_lock);
221 return path;
223 EXPORT_SYMBOL_GPL(mmp_register_path);
226 * mmp_unregister_path - unregister and destroy path
227 * @p: path to be destroyed.
229 * this function registers path and destroys it.
231 void mmp_unregister_path(struct mmp_path *path)
233 int i;
235 if (!path)
236 return;
238 mutex_lock(&disp_lock);
239 /* del from pathlist */
240 list_del(&path->node);
242 /* deinit overlays */
243 for (i = 0; i < path->overlay_num; i++)
244 mutex_destroy(&path->overlays[i].access_ok);
246 mutex_destroy(&path->access_ok);
248 kfree(path);
249 mutex_unlock(&disp_lock);
251 EXPORT_SYMBOL_GPL(mmp_unregister_path);