Home | History | Annotate | Line # | Download | only in drm
drm_panel.c revision 1.3
      1  1.3  jakllsch /*	$NetBSD: drm_panel.c,v 1.3 2019/12/09 15:36:16 jakllsch 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.3  jakllsch __KERNEL_RCSID(0, "$NetBSD: drm_panel.c,v 1.3 2019/12/09 15:36:16 jakllsch 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.1  riastrad void drm_panel_init(struct drm_panel *panel)
     44  1.1  riastrad {
     45  1.1  riastrad 	INIT_LIST_HEAD(&panel->list);
     46  1.1  riastrad }
     47  1.1  riastrad EXPORT_SYMBOL(drm_panel_init);
     48  1.1  riastrad 
     49  1.1  riastrad int drm_panel_add(struct drm_panel *panel)
     50  1.1  riastrad {
     51  1.1  riastrad 	mutex_lock(&panel_lock);
     52  1.1  riastrad 	list_add_tail(&panel->list, &panel_list);
     53  1.1  riastrad 	mutex_unlock(&panel_lock);
     54  1.1  riastrad 
     55  1.1  riastrad 	return 0;
     56  1.1  riastrad }
     57  1.1  riastrad EXPORT_SYMBOL(drm_panel_add);
     58  1.1  riastrad 
     59  1.1  riastrad void drm_panel_remove(struct drm_panel *panel)
     60  1.1  riastrad {
     61  1.1  riastrad 	mutex_lock(&panel_lock);
     62  1.1  riastrad 	list_del_init(&panel->list);
     63  1.1  riastrad 	mutex_unlock(&panel_lock);
     64  1.1  riastrad }
     65  1.1  riastrad EXPORT_SYMBOL(drm_panel_remove);
     66  1.1  riastrad 
     67  1.1  riastrad int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
     68  1.1  riastrad {
     69  1.1  riastrad 	if (panel->connector)
     70  1.1  riastrad 		return -EBUSY;
     71  1.1  riastrad 
     72  1.1  riastrad 	panel->connector = connector;
     73  1.1  riastrad 	panel->drm = connector->dev;
     74  1.1  riastrad 
     75  1.1  riastrad 	return 0;
     76  1.1  riastrad }
     77  1.1  riastrad EXPORT_SYMBOL(drm_panel_attach);
     78  1.1  riastrad 
     79  1.1  riastrad int drm_panel_detach(struct drm_panel *panel)
     80  1.1  riastrad {
     81  1.1  riastrad 	panel->connector = NULL;
     82  1.1  riastrad 	panel->drm = NULL;
     83  1.1  riastrad 
     84  1.1  riastrad 	return 0;
     85  1.1  riastrad }
     86  1.1  riastrad EXPORT_SYMBOL(drm_panel_detach);
     87  1.1  riastrad 
     88  1.1  riastrad #ifdef CONFIG_OF
     89  1.1  riastrad struct drm_panel *of_drm_find_panel(struct device_node *np)
     90  1.1  riastrad {
     91  1.1  riastrad 	struct drm_panel *panel;
     92  1.1  riastrad 
     93  1.1  riastrad 	mutex_lock(&panel_lock);
     94  1.1  riastrad 
     95  1.1  riastrad 	list_for_each_entry(panel, &panel_list, list) {
     96  1.1  riastrad 		if (panel->dev->of_node == np) {
     97  1.1  riastrad 			mutex_unlock(&panel_lock);
     98  1.1  riastrad 			return panel;
     99  1.1  riastrad 		}
    100  1.1  riastrad 	}
    101  1.1  riastrad 
    102  1.1  riastrad 	mutex_unlock(&panel_lock);
    103  1.1  riastrad 	return NULL;
    104  1.1  riastrad }
    105  1.1  riastrad EXPORT_SYMBOL(of_drm_find_panel);
    106  1.1  riastrad #endif
    107  1.1  riastrad 
    108  1.1  riastrad MODULE_AUTHOR("Thierry Reding <treding (at) nvidia.com>");
    109  1.1  riastrad MODULE_DESCRIPTION("DRM panel infrastructure");
    110  1.1  riastrad MODULE_LICENSE("GPL and additional rights");
    111