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