1 1.4 riastrad /* $NetBSD: drm_panel.h,v 1.4 2021/12/18 23:45:46 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.1 riastrad #ifndef __DRM_PANEL_H__ 27 1.1 riastrad #define __DRM_PANEL_H__ 28 1.1 riastrad 29 1.4 riastrad #include <linux/err.h> 30 1.4 riastrad #include <linux/errno.h> 31 1.1 riastrad #include <linux/list.h> 32 1.1 riastrad 33 1.4 riastrad struct backlight_device; 34 1.4 riastrad struct device_node; 35 1.1 riastrad struct drm_connector; 36 1.1 riastrad struct drm_device; 37 1.1 riastrad struct drm_panel; 38 1.2 riastrad struct display_timing; 39 1.1 riastrad 40 1.2 riastrad /** 41 1.2 riastrad * struct drm_panel_funcs - perform operations on a given panel 42 1.2 riastrad * 43 1.2 riastrad * The .prepare() function is typically called before the display controller 44 1.2 riastrad * starts to transmit video data. Panel drivers can use this to turn the panel 45 1.2 riastrad * on and wait for it to become ready. If additional configuration is required 46 1.2 riastrad * (via a control bus such as I2C, SPI or DSI for example) this is a good time 47 1.2 riastrad * to do that. 48 1.2 riastrad * 49 1.2 riastrad * After the display controller has started transmitting video data, it's safe 50 1.2 riastrad * to call the .enable() function. This will typically enable the backlight to 51 1.2 riastrad * make the image on screen visible. Some panels require a certain amount of 52 1.2 riastrad * time or frames before the image is displayed. This function is responsible 53 1.2 riastrad * for taking this into account before enabling the backlight to avoid visual 54 1.2 riastrad * glitches. 55 1.2 riastrad * 56 1.2 riastrad * Before stopping video transmission from the display controller it can be 57 1.2 riastrad * necessary to turn off the panel to avoid visual glitches. This is done in 58 1.2 riastrad * the .disable() function. Analogously to .enable() this typically involves 59 1.2 riastrad * turning off the backlight and waiting for some time to make sure no image 60 1.2 riastrad * is visible on the panel. It is then safe for the display controller to 61 1.2 riastrad * cease transmission of video data. 62 1.2 riastrad * 63 1.2 riastrad * To save power when no video data is transmitted, a driver can power down 64 1.2 riastrad * the panel. This is the job of the .unprepare() function. 65 1.4 riastrad * 66 1.4 riastrad * Backlight can be handled automatically if configured using 67 1.4 riastrad * drm_panel_of_backlight(). Then the driver does not need to implement the 68 1.4 riastrad * functionality to enable/disable backlight. 69 1.2 riastrad */ 70 1.1 riastrad struct drm_panel_funcs { 71 1.4 riastrad /** 72 1.4 riastrad * @prepare: 73 1.4 riastrad * 74 1.4 riastrad * Turn on panel and perform set up. 75 1.4 riastrad * 76 1.4 riastrad * This function is optional. 77 1.4 riastrad */ 78 1.4 riastrad int (*prepare)(struct drm_panel *panel); 79 1.4 riastrad 80 1.4 riastrad /** 81 1.4 riastrad * @enable: 82 1.4 riastrad * 83 1.4 riastrad * Enable panel (turn on back light, etc.). 84 1.4 riastrad * 85 1.4 riastrad * This function is optional. 86 1.4 riastrad */ 87 1.4 riastrad int (*enable)(struct drm_panel *panel); 88 1.4 riastrad 89 1.4 riastrad /** 90 1.4 riastrad * @disable: 91 1.4 riastrad * 92 1.4 riastrad * Disable panel (turn off back light, etc.). 93 1.4 riastrad * 94 1.4 riastrad * This function is optional. 95 1.4 riastrad */ 96 1.1 riastrad int (*disable)(struct drm_panel *panel); 97 1.4 riastrad 98 1.4 riastrad /** 99 1.4 riastrad * @unprepare: 100 1.4 riastrad * 101 1.4 riastrad * Turn off panel. 102 1.4 riastrad * 103 1.4 riastrad * This function is optional. 104 1.4 riastrad */ 105 1.2 riastrad int (*unprepare)(struct drm_panel *panel); 106 1.4 riastrad 107 1.4 riastrad /** 108 1.4 riastrad * @get_modes: 109 1.4 riastrad * 110 1.4 riastrad * Add modes to the connector that the panel is attached to 111 1.4 riastrad * and returns the number of modes added. 112 1.4 riastrad * 113 1.4 riastrad * This function is mandatory. 114 1.4 riastrad */ 115 1.4 riastrad int (*get_modes)(struct drm_panel *panel, 116 1.4 riastrad struct drm_connector *connector); 117 1.4 riastrad 118 1.4 riastrad /** 119 1.4 riastrad * @get_timings: 120 1.4 riastrad * 121 1.4 riastrad * Copy display timings into the provided array and return 122 1.4 riastrad * the number of display timings available. 123 1.4 riastrad * 124 1.4 riastrad * This function is optional. 125 1.4 riastrad */ 126 1.2 riastrad int (*get_timings)(struct drm_panel *panel, unsigned int num_timings, 127 1.2 riastrad struct display_timing *timings); 128 1.1 riastrad }; 129 1.1 riastrad 130 1.4 riastrad /** 131 1.4 riastrad * struct drm_panel - DRM panel object 132 1.4 riastrad */ 133 1.1 riastrad struct drm_panel { 134 1.4 riastrad /** 135 1.4 riastrad * @dev: 136 1.4 riastrad * 137 1.4 riastrad * Parent device of the panel. 138 1.4 riastrad */ 139 1.1 riastrad struct device *dev; 140 1.1 riastrad 141 1.4 riastrad /** 142 1.4 riastrad * @backlight: 143 1.4 riastrad * 144 1.4 riastrad * Backlight device, used to turn on backlight after the call 145 1.4 riastrad * to enable(), and to turn off backlight before the call to 146 1.4 riastrad * disable(). 147 1.4 riastrad * backlight is set by drm_panel_of_backlight() and drivers 148 1.4 riastrad * shall not assign it. 149 1.4 riastrad */ 150 1.4 riastrad struct backlight_device *backlight; 151 1.4 riastrad 152 1.4 riastrad /** 153 1.4 riastrad * @funcs: 154 1.4 riastrad * 155 1.4 riastrad * Operations that can be performed on the panel. 156 1.4 riastrad */ 157 1.1 riastrad const struct drm_panel_funcs *funcs; 158 1.1 riastrad 159 1.4 riastrad /** 160 1.4 riastrad * @connector_type: 161 1.4 riastrad * 162 1.4 riastrad * Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used to 163 1.4 riastrad * initialise the drm_connector corresponding to the panel with the 164 1.4 riastrad * correct connector type. 165 1.4 riastrad */ 166 1.4 riastrad int connector_type; 167 1.4 riastrad 168 1.4 riastrad /** 169 1.4 riastrad * @list: 170 1.4 riastrad * 171 1.4 riastrad * Panel entry in registry. 172 1.4 riastrad */ 173 1.1 riastrad struct list_head list; 174 1.1 riastrad }; 175 1.1 riastrad 176 1.4 riastrad #ifdef __NetBSD__ 177 1.4 riastrad void drm_panel_init_lock(void); 178 1.4 riastrad void drm_panel_fini_lock(void); 179 1.4 riastrad #endif 180 1.2 riastrad 181 1.4 riastrad void drm_panel_init(struct drm_panel *panel, struct device *dev, 182 1.4 riastrad const struct drm_panel_funcs *funcs, 183 1.4 riastrad int connector_type); 184 1.2 riastrad 185 1.4 riastrad int drm_panel_add(struct drm_panel *panel); 186 1.4 riastrad void drm_panel_remove(struct drm_panel *panel); 187 1.1 riastrad 188 1.4 riastrad int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector); 189 1.4 riastrad void drm_panel_detach(struct drm_panel *panel); 190 1.1 riastrad 191 1.4 riastrad int drm_panel_prepare(struct drm_panel *panel); 192 1.4 riastrad int drm_panel_unprepare(struct drm_panel *panel); 193 1.2 riastrad 194 1.4 riastrad int drm_panel_enable(struct drm_panel *panel); 195 1.4 riastrad int drm_panel_disable(struct drm_panel *panel); 196 1.1 riastrad 197 1.4 riastrad int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector); 198 1.1 riastrad 199 1.4 riastrad #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL) 200 1.4 riastrad struct drm_panel *of_drm_find_panel(const struct device_node *np); 201 1.4 riastrad #else 202 1.4 riastrad static inline struct drm_panel *of_drm_find_panel(const struct device_node *np) 203 1.2 riastrad { 204 1.4 riastrad return ERR_PTR(-ENODEV); 205 1.2 riastrad } 206 1.3 jmcneill #endif 207 1.3 jmcneill 208 1.4 riastrad #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE) 209 1.4 riastrad int drm_panel_of_backlight(struct drm_panel *panel); 210 1.1 riastrad #else 211 1.4 riastrad static inline int drm_panel_of_backlight(struct drm_panel *panel) 212 1.1 riastrad { 213 1.4 riastrad return 0; 214 1.1 riastrad } 215 1.1 riastrad #endif 216 1.1 riastrad 217 1.1 riastrad #endif 218