Home | History | Annotate | Line # | Download | only in drm
drm_panel.c revision 1.4
      1  1.4  jmcneill /*	$NetBSD: drm_panel.c,v 1.4 2020/01/03 21:01:16 jmcneill 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.4  jmcneill __KERNEL_RCSID(0, "$NetBSD: drm_panel.c,v 1.4 2020/01/03 21:01:16 jmcneill 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.3  jakllsch #ifdef __NetBSD__
     36  1.3  jakllsch static struct mutex panel_lock;
     37  1.3  jakllsch static struct list_head panel_list = LIST_HEAD_INIT(panel_list);
     38  1.3  jakllsch #else
     39  1.1  riastrad static DEFINE_MUTEX(panel_lock);
     40  1.1  riastrad static LIST_HEAD(panel_list);
     41  1.3  jakllsch #endif
     42  1.1  riastrad 
     43  1.4  jmcneill #ifdef __NetBSD__
     44  1.4  jmcneill void drm_panel_init_lock(void)
     45  1.4  jmcneill {
     46  1.4  jmcneill 	linux_mutex_init(&panel_lock);
     47  1.4  jmcneill }
     48  1.4  jmcneill void drm_panel_fini_lock(void)
     49  1.4  jmcneill {
     50  1.4  jmcneill 	linux_mutex_destroy(&panel_lock);
     51  1.4  jmcneill }
     52  1.4  jmcneill #endif
     53  1.4  jmcneill 
     54  1.1  riastrad void drm_panel_init(struct drm_panel *panel)
     55  1.1  riastrad {
     56  1.1  riastrad 	INIT_LIST_HEAD(&panel->list);
     57  1.1  riastrad }
     58  1.1  riastrad EXPORT_SYMBOL(drm_panel_init);
     59  1.1  riastrad 
     60  1.1  riastrad int drm_panel_add(struct drm_panel *panel)
     61  1.1  riastrad {
     62  1.1  riastrad 	mutex_lock(&panel_lock);
     63  1.1  riastrad 	list_add_tail(&panel->list, &panel_list);
     64  1.1  riastrad 	mutex_unlock(&panel_lock);
     65  1.1  riastrad 
     66  1.1  riastrad 	return 0;
     67  1.1  riastrad }
     68  1.1  riastrad EXPORT_SYMBOL(drm_panel_add);
     69  1.1  riastrad 
     70  1.1  riastrad void drm_panel_remove(struct drm_panel *panel)
     71  1.1  riastrad {
     72  1.1  riastrad 	mutex_lock(&panel_lock);
     73  1.1  riastrad 	list_del_init(&panel->list);
     74  1.1  riastrad 	mutex_unlock(&panel_lock);
     75  1.1  riastrad }
     76  1.1  riastrad EXPORT_SYMBOL(drm_panel_remove);
     77  1.1  riastrad 
     78  1.1  riastrad int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
     79  1.1  riastrad {
     80  1.1  riastrad 	if (panel->connector)
     81  1.1  riastrad 		return -EBUSY;
     82  1.1  riastrad 
     83  1.1  riastrad 	panel->connector = connector;
     84  1.1  riastrad 	panel->drm = connector->dev;
     85  1.1  riastrad 
     86  1.1  riastrad 	return 0;
     87  1.1  riastrad }
     88  1.1  riastrad EXPORT_SYMBOL(drm_panel_attach);
     89  1.1  riastrad 
     90  1.1  riastrad int drm_panel_detach(struct drm_panel *panel)
     91  1.1  riastrad {
     92  1.1  riastrad 	panel->connector = NULL;
     93  1.1  riastrad 	panel->drm = NULL;
     94  1.1  riastrad 
     95  1.1  riastrad 	return 0;
     96  1.1  riastrad }
     97  1.1  riastrad EXPORT_SYMBOL(drm_panel_detach);
     98  1.1  riastrad 
     99  1.1  riastrad #ifdef CONFIG_OF
    100  1.1  riastrad struct drm_panel *of_drm_find_panel(struct device_node *np)
    101  1.1  riastrad {
    102  1.1  riastrad 	struct drm_panel *panel;
    103  1.1  riastrad 
    104  1.1  riastrad 	mutex_lock(&panel_lock);
    105  1.1  riastrad 
    106  1.1  riastrad 	list_for_each_entry(panel, &panel_list, list) {
    107  1.1  riastrad 		if (panel->dev->of_node == np) {
    108  1.1  riastrad 			mutex_unlock(&panel_lock);
    109  1.1  riastrad 			return panel;
    110  1.1  riastrad 		}
    111  1.1  riastrad 	}
    112  1.1  riastrad 
    113  1.1  riastrad 	mutex_unlock(&panel_lock);
    114  1.1  riastrad 	return NULL;
    115  1.1  riastrad }
    116  1.1  riastrad EXPORT_SYMBOL(of_drm_find_panel);
    117  1.1  riastrad #endif
    118  1.1  riastrad 
    119  1.1  riastrad MODULE_AUTHOR("Thierry Reding <treding (at) nvidia.com>");
    120  1.1  riastrad MODULE_DESCRIPTION("DRM panel infrastructure");
    121  1.1  riastrad MODULE_LICENSE("GPL and additional rights");
    122