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