Home | History | Annotate | Line # | Download | only in drm
drm_panel.c revision 1.2
      1  1.2  riastrad /*	$NetBSD: drm_panel.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright (C) 2013, NVIDIA Corporation.  All rights reserved.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the
     14  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     15  1.1  riastrad  * of the Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     23  1.1  riastrad  * DEALINGS IN THE SOFTWARE.
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.2  riastrad #include <sys/cdefs.h>
     27  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_panel.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $");
     28  1.2  riastrad 
     29  1.1  riastrad #include <linux/err.h>
     30  1.1  riastrad #include <linux/module.h>
     31  1.1  riastrad 
     32  1.1  riastrad #include <drm/drm_crtc.h>
     33  1.1  riastrad #include <drm/drm_panel.h>
     34  1.1  riastrad 
     35  1.1  riastrad static DEFINE_MUTEX(panel_lock);
     36  1.1  riastrad static LIST_HEAD(panel_list);
     37  1.1  riastrad 
     38  1.1  riastrad void drm_panel_init(struct drm_panel *panel)
     39  1.1  riastrad {
     40  1.1  riastrad 	INIT_LIST_HEAD(&panel->list);
     41  1.1  riastrad }
     42  1.1  riastrad EXPORT_SYMBOL(drm_panel_init);
     43  1.1  riastrad 
     44  1.1  riastrad int drm_panel_add(struct drm_panel *panel)
     45  1.1  riastrad {
     46  1.1  riastrad 	mutex_lock(&panel_lock);
     47  1.1  riastrad 	list_add_tail(&panel->list, &panel_list);
     48  1.1  riastrad 	mutex_unlock(&panel_lock);
     49  1.1  riastrad 
     50  1.1  riastrad 	return 0;
     51  1.1  riastrad }
     52  1.1  riastrad EXPORT_SYMBOL(drm_panel_add);
     53  1.1  riastrad 
     54  1.1  riastrad void drm_panel_remove(struct drm_panel *panel)
     55  1.1  riastrad {
     56  1.1  riastrad 	mutex_lock(&panel_lock);
     57  1.1  riastrad 	list_del_init(&panel->list);
     58  1.1  riastrad 	mutex_unlock(&panel_lock);
     59  1.1  riastrad }
     60  1.1  riastrad EXPORT_SYMBOL(drm_panel_remove);
     61  1.1  riastrad 
     62  1.1  riastrad int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
     63  1.1  riastrad {
     64  1.1  riastrad 	if (panel->connector)
     65  1.1  riastrad 		return -EBUSY;
     66  1.1  riastrad 
     67  1.1  riastrad 	panel->connector = connector;
     68  1.1  riastrad 	panel->drm = connector->dev;
     69  1.1  riastrad 
     70  1.1  riastrad 	return 0;
     71  1.1  riastrad }
     72  1.1  riastrad EXPORT_SYMBOL(drm_panel_attach);
     73  1.1  riastrad 
     74  1.1  riastrad int drm_panel_detach(struct drm_panel *panel)
     75  1.1  riastrad {
     76  1.1  riastrad 	panel->connector = NULL;
     77  1.1  riastrad 	panel->drm = NULL;
     78  1.1  riastrad 
     79  1.1  riastrad 	return 0;
     80  1.1  riastrad }
     81  1.1  riastrad EXPORT_SYMBOL(drm_panel_detach);
     82  1.1  riastrad 
     83  1.1  riastrad #ifdef CONFIG_OF
     84  1.1  riastrad struct drm_panel *of_drm_find_panel(struct device_node *np)
     85  1.1  riastrad {
     86  1.1  riastrad 	struct drm_panel *panel;
     87  1.1  riastrad 
     88  1.1  riastrad 	mutex_lock(&panel_lock);
     89  1.1  riastrad 
     90  1.1  riastrad 	list_for_each_entry(panel, &panel_list, list) {
     91  1.1  riastrad 		if (panel->dev->of_node == np) {
     92  1.1  riastrad 			mutex_unlock(&panel_lock);
     93  1.1  riastrad 			return panel;
     94  1.1  riastrad 		}
     95  1.1  riastrad 	}
     96  1.1  riastrad 
     97  1.1  riastrad 	mutex_unlock(&panel_lock);
     98  1.1  riastrad 	return NULL;
     99  1.1  riastrad }
    100  1.1  riastrad EXPORT_SYMBOL(of_drm_find_panel);
    101  1.1  riastrad #endif
    102  1.1  riastrad 
    103  1.1  riastrad MODULE_AUTHOR("Thierry Reding <treding (at) nvidia.com>");
    104  1.1  riastrad MODULE_DESCRIPTION("DRM panel infrastructure");
    105  1.1  riastrad MODULE_LICENSE("GPL and additional rights");
    106