Ajay Singh Parmar | 571e301 | 2016-05-16 17:55:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _DSI_DISPLAY_H_ |
| 16 | #define _DSI_DISPLAY_H_ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/bitops.h> |
| 20 | #include <linux/of_device.h> |
| 21 | #include <drm/drmP.h> |
| 22 | #include <drm/drm_crtc.h> |
| 23 | |
| 24 | #include "dsi_defs.h" |
| 25 | #include "dsi_ctrl.h" |
| 26 | #include "dsi_phy.h" |
| 27 | #include "dsi_panel.h" |
| 28 | |
| 29 | #define MAX_DSI_CTRLS_PER_DISPLAY 2 |
| 30 | |
| 31 | /** |
| 32 | * enum dsi_display_type - enumerates DSI display types |
| 33 | * @DSI_DISPLAY_SINGLE: A panel connected on a single DSI interface. |
| 34 | * @DSI_DISPLAY_EXT_BRIDGE: A bridge is connected between panel and DSI host. |
| 35 | * It utilizes a single DSI interface. |
| 36 | * @DSI_DISPLAY_SPLIT: A panel that utilizes more than one DSI |
| 37 | * interfaces. |
| 38 | * @DSI_DISPLAY_SPLIT_EXT_BRIDGE: A bridge is present between panel and DSI |
| 39 | * host. It utilizes more than one DSI interface. |
| 40 | */ |
| 41 | enum dsi_display_type { |
| 42 | DSI_DISPLAY_SINGLE = 0, |
| 43 | DSI_DISPLAY_EXT_BRIDGE, |
| 44 | DSI_DISPLAY_SPLIT, |
| 45 | DSI_DISPLAY_SPLIT_EXT_BRIDGE, |
| 46 | DSI_DISPLAY_MAX, |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * struct dsi_display_info - defines dsi display properties |
| 51 | * @display_type: Display type as defined by device tree. |
| 52 | * @type: Type of panel connected to DSI interface. |
| 53 | * @num_of_h_tiles: In case of split panels, number of h tiles indicates the |
| 54 | * number of dsi interfaces used. For single DSI panels this |
| 55 | * is set to 1. This will be set for horizontally split |
| 56 | * panels. |
| 57 | * @h_tile_ids: The DSI instance ID for each tile. |
| 58 | * @is_hot_pluggable: Can panel be hot plugged. |
| 59 | * @is_connected: Is panel connected. |
| 60 | * @is_edid_supported: Does panel support reading EDID information. |
| 61 | * @width_mm: Physical width of panel in millimeters. |
| 62 | * @height_mm: Physical height of panel in millimeters. |
| 63 | */ |
| 64 | struct dsi_display_info { |
| 65 | char display_type[20]; |
| 66 | enum dsi_display_type type; |
| 67 | |
| 68 | /* Split DSI properties */ |
| 69 | bool h_tiled; |
| 70 | u32 num_of_h_tiles; |
| 71 | u32 h_tile_ids[MAX_DSI_CTRLS_PER_DISPLAY]; |
| 72 | |
| 73 | /* HPD */ |
| 74 | bool is_hot_pluggable; |
| 75 | bool is_connected; |
| 76 | bool is_edid_supported; |
| 77 | |
| 78 | /* Physical properties */ |
| 79 | u32 width_mm; |
| 80 | u32 height_mm; |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * struct dsi_display_ctrl - dsi ctrl/phy information for the display |
| 85 | * @ctrl: Handle to the DSI controller device. |
| 86 | * @ctrl_of_node: pHandle to the DSI controller device. |
| 87 | * @dsi_ctrl_idx: DSI controller instance id. |
| 88 | * @power_state: Current power state of the DSI controller. |
| 89 | * @cmd_engine_enabled: Command engine status. |
| 90 | * @video_engine_enabled: Video engine status. |
| 91 | * @ulps_enabled: ULPS status for the controller. |
| 92 | * @clamps_enabled: Clamps status for the controller. |
| 93 | * @phy: Handle to the DSI PHY device. |
| 94 | * @phy_of_node: pHandle to the DSI PHY device. |
| 95 | * @phy_enabled: PHY power status. |
| 96 | */ |
| 97 | struct dsi_display_ctrl { |
| 98 | /* controller info */ |
| 99 | struct dsi_ctrl *ctrl; |
| 100 | struct device_node *ctrl_of_node; |
| 101 | u32 dsi_ctrl_idx; |
| 102 | |
| 103 | enum dsi_power_state power_state; |
Ajay Singh Parmar | 571e301 | 2016-05-16 17:55:52 -0700 | [diff] [blame] | 104 | |
| 105 | /* phy info */ |
| 106 | struct msm_dsi_phy *phy; |
| 107 | struct device_node *phy_of_node; |
| 108 | |
| 109 | bool phy_enabled; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * struct dsi_display_clk_info - dsi display clock source information |
| 114 | * @src_clks: Source clocks for DSI display. |
| 115 | * @mux_clks: Mux clocks used for DFPS. |
| 116 | * @shadow_clks: Used for DFPS. |
| 117 | */ |
| 118 | struct dsi_display_clk_info { |
| 119 | struct dsi_clk_link_set src_clks; |
| 120 | struct dsi_clk_link_set mux_clks; |
| 121 | struct dsi_clk_link_set shadow_clks; |
| 122 | }; |
| 123 | |
| 124 | /** |
| 125 | * struct dsi_display - dsi display information |
| 126 | * @pdev: Pointer to platform device. |
| 127 | * @drm_dev: DRM device associated with the display. |
| 128 | * @name: Name of the display. |
| 129 | * @display_type: Display type as defined in device tree. |
| 130 | * @list: List pointer. |
| 131 | * @is_active: Is display active. |
| 132 | * @display_lock: Mutex for dsi_display interface. |
| 133 | * @ctrl_count: Number of DSI interfaces required by panel. |
| 134 | * @ctrl: Controller information for DSI display. |
| 135 | * @panel: Handle to DSI panel. |
| 136 | * @panel_of: pHandle to DSI panel. |
| 137 | * @type: DSI display type. |
| 138 | * @clk_master_idx: The master controller for controlling clocks. This is an |
| 139 | * index into the ctrl[MAX_DSI_CTRLS_PER_DISPLAY] array. |
| 140 | * @cmd_master_idx: The master controller for sending DSI commands to panel. |
| 141 | * @video_master_idx: The master controller for enabling video engine. |
| 142 | * @clock_info: Clock sourcing for DSI display. |
| 143 | * @lane_map: Lane mapping between DSI host and Panel. |
| 144 | * @num_of_modes: Number of modes supported by display. |
| 145 | * @is_tpg_enabled: TPG state. |
| 146 | * @host: DRM MIPI DSI Host. |
| 147 | * @connector: Pointer to DRM connector object. |
| 148 | * @bridge: Pointer to DRM bridge object. |
| 149 | */ |
| 150 | struct dsi_display { |
| 151 | struct platform_device *pdev; |
| 152 | struct drm_device *drm_dev; |
| 153 | |
| 154 | const char *name; |
| 155 | const char *display_type; |
| 156 | struct list_head list; |
| 157 | bool is_active; |
| 158 | struct mutex display_lock; |
| 159 | |
| 160 | u32 ctrl_count; |
| 161 | struct dsi_display_ctrl ctrl[MAX_DSI_CTRLS_PER_DISPLAY]; |
| 162 | |
| 163 | /* panel info */ |
| 164 | struct dsi_panel *panel; |
| 165 | struct device_node *panel_of; |
| 166 | |
| 167 | enum dsi_display_type type; |
| 168 | u32 clk_master_idx; |
| 169 | u32 cmd_master_idx; |
| 170 | u32 video_master_idx; |
| 171 | |
| 172 | struct dsi_display_clk_info clock_info; |
| 173 | struct dsi_host_config config; |
| 174 | struct dsi_lane_mapping lane_map; |
| 175 | u32 num_of_modes; |
| 176 | bool is_tpg_enabled; |
| 177 | |
| 178 | struct mipi_dsi_host host; |
| 179 | struct dsi_connector *connector; |
| 180 | struct dsi_bridge *bridge; |
Ajay Singh Parmar | aa9152d | 2016-05-16 18:02:07 -0700 | [diff] [blame^] | 181 | u32 cmd_engine_refcount; |
Ajay Singh Parmar | 571e301 | 2016-05-16 17:55:52 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | int dsi_display_dev_probe(struct platform_device *pdev); |
| 185 | int dsi_display_dev_remove(struct platform_device *pdev); |
| 186 | |
| 187 | /** |
| 188 | * dsi_display_get_num_of_displays() - returns number of display devices |
| 189 | * supported. |
| 190 | * |
| 191 | * Return: number of displays. |
| 192 | */ |
| 193 | u32 dsi_display_get_num_of_displays(void); |
| 194 | |
| 195 | /** |
| 196 | * dsi_display_get_display_by_index()- finds display by index |
| 197 | * @index: index of the display. |
| 198 | * |
| 199 | * Return: handle to the display or error code. |
| 200 | */ |
| 201 | struct dsi_display *dsi_display_get_display_by_index(u32 index); |
| 202 | |
| 203 | /** |
| 204 | * dsi_display_get_display_by_name()- finds display by name |
| 205 | * @index: name of the display. |
| 206 | * |
| 207 | * Return: handle to the display or error code. |
| 208 | */ |
| 209 | struct dsi_display *dsi_display_get_display_by_name(const char *name); |
| 210 | |
| 211 | /** |
| 212 | * dsi_display_set_active_state() - sets the state of the display |
| 213 | * @display: Handle to display. |
| 214 | * @is_active: state |
| 215 | */ |
| 216 | void dsi_display_set_active_state(struct dsi_display *display, bool is_active); |
| 217 | |
| 218 | /** |
| 219 | * dsi_display_is_active() - returns the state of the display |
| 220 | * @display: Handle to the display. |
| 221 | * |
| 222 | * Return: state. |
| 223 | */ |
| 224 | bool dsi_display_is_active(struct dsi_display *display); |
| 225 | |
| 226 | /** |
| 227 | * dsi_display_dev_init() - Initializes the display device |
| 228 | * @display: Handle to the display. |
| 229 | * |
| 230 | * Initialization will acquire references to the resources required for the |
| 231 | * display hardware to function. |
| 232 | * |
| 233 | * Return: error code. |
| 234 | */ |
| 235 | int dsi_display_dev_init(struct dsi_display *display); |
| 236 | |
| 237 | /** |
| 238 | * dsi_display_dev_deinit() - Desinitializes the display device |
| 239 | * @display: Handle to the display. |
| 240 | * |
| 241 | * All the resources acquired during device init will be released. |
| 242 | * |
| 243 | * Return: error code. |
| 244 | */ |
| 245 | int dsi_display_dev_deinit(struct dsi_display *display); |
| 246 | |
| 247 | /** |
| 248 | * dsi_display_bind() - Binds the display device to the DRM device |
| 249 | * @display: Handle to the display. |
| 250 | * @dev: Pointer to the DRM device. |
| 251 | * |
| 252 | * Return: error code. |
| 253 | */ |
| 254 | int dsi_display_bind(struct dsi_display *display, struct drm_device *dev); |
| 255 | |
| 256 | /** |
| 257 | * dsi_display_unbind() - Unbinds the display device from the DRM device |
| 258 | * @display: Handle to the display. |
| 259 | * |
| 260 | * Return: error code. |
| 261 | */ |
| 262 | int dsi_display_unbind(struct dsi_display *display); |
| 263 | |
| 264 | /** |
| 265 | * dsi_display_drm_init() - initializes DRM objects for the display device. |
| 266 | * @display: Handle to the display. |
| 267 | * @encoder: Pointer to the encoder object which is connected to the |
| 268 | * display. |
| 269 | * |
| 270 | * Return: error code. |
| 271 | */ |
| 272 | int dsi_display_drm_init(struct dsi_display *display, struct drm_encoder *enc); |
| 273 | |
| 274 | /** |
| 275 | * dsi_display_drm_deinit() - destroys DRM objects assosciated with the display |
| 276 | * @display: Handle to the display. |
| 277 | * |
| 278 | * Return: error code. |
| 279 | */ |
| 280 | int dsi_display_drm_deinit(struct dsi_display *display); |
| 281 | |
| 282 | /** |
| 283 | * dsi_display_get_info() - returns the display properties |
| 284 | * @display: Handle to the display. |
| 285 | * @info: Pointer to the structure where info is stored. |
| 286 | * |
| 287 | * Return: error code. |
| 288 | */ |
| 289 | int dsi_display_get_info(struct dsi_display *display, |
| 290 | struct dsi_display_info *info); |
| 291 | |
| 292 | /** |
| 293 | * dsi_display_get_modes() - get modes supported by display |
| 294 | * @display: Handle to display. |
| 295 | * @modes; Pointer to array of modes. Memory allocated should be |
| 296 | * big enough to store (count * struct dsi_display_mode) |
| 297 | * elements. If modes pointer is NULL, number of modes will |
| 298 | * be stored in the memory pointed to by count. |
| 299 | * @count: If modes is NULL, number of modes will be stored. If |
| 300 | * not, mode information will be copied (number of modes |
| 301 | * copied will be equal to *count). |
| 302 | * |
| 303 | * Return: error code. |
| 304 | */ |
| 305 | int dsi_display_get_modes(struct dsi_display *display, |
| 306 | struct dsi_display_mode *modes, |
| 307 | u32 *count); |
| 308 | |
| 309 | /** |
| 310 | * dsi_display_validate_mode() - validates if mode is supported by display |
| 311 | * @display: Handle to display. |
| 312 | * @mode: Mode to be validated. |
| 313 | * |
| 314 | * Return: 0 if supported or error code. |
| 315 | */ |
| 316 | int dsi_display_validate_mode(struct dsi_display *display, |
| 317 | struct dsi_display_mode *mode); |
| 318 | |
| 319 | /** |
| 320 | * dsi_display_set_mode() - Set mode on the display. |
| 321 | * @display: Handle to display. |
| 322 | * @mode: mode to be set. |
| 323 | * @flags: Modifier flags. |
| 324 | * |
| 325 | * Return: error code. |
| 326 | */ |
| 327 | int dsi_display_set_mode(struct dsi_display *display, |
| 328 | struct dsi_display_mode *mode, |
| 329 | u32 flags); |
| 330 | |
| 331 | /** |
| 332 | * dsi_display_prepare() - prepare display |
| 333 | * @display: Handle to display. |
| 334 | * |
| 335 | * Prepare will perform power up sequences for the host and panel hardware. |
| 336 | * Power and clock resources might be turned on (depending on the panel mode). |
| 337 | * The video engine is not enabled. |
| 338 | * |
| 339 | * Return: error code. |
| 340 | */ |
| 341 | int dsi_display_prepare(struct dsi_display *display); |
| 342 | |
| 343 | /** |
| 344 | * dsi_display_enable() - enable display |
| 345 | * @display: Handle to display. |
| 346 | * |
| 347 | * Enable will turn on the host engine and the panel. At the end of the enable |
| 348 | * function, Host and panel hardware are ready to accept pixel data from |
| 349 | * upstream. |
| 350 | * |
| 351 | * Return: error code. |
| 352 | */ |
| 353 | int dsi_display_enable(struct dsi_display *display); |
| 354 | |
| 355 | /** |
| 356 | * dsi_display_post_enable() - perform post enable operations. |
| 357 | * @display: Handle to display. |
| 358 | * |
| 359 | * Some panels might require some commands to be sent after pixel data |
| 360 | * transmission has started. Such commands are sent as part of the post_enable |
| 361 | * function. |
| 362 | * |
| 363 | * Return: error code. |
| 364 | */ |
| 365 | int dsi_display_post_enable(struct dsi_display *display); |
| 366 | |
| 367 | /** |
| 368 | * dsi_display_pre_disable() - perform pre disable operations. |
| 369 | * @display: Handle to display. |
| 370 | * |
| 371 | * If a panel requires commands to be sent before pixel data transmission is |
| 372 | * stopped, those can be sent as part of pre_disable. |
| 373 | * |
| 374 | * Return: error code. |
| 375 | */ |
| 376 | int dsi_display_pre_disable(struct dsi_display *display); |
| 377 | |
| 378 | /** |
| 379 | * dsi_display_disable() - disable panel and host hardware. |
| 380 | * @display: Handle to display. |
| 381 | * |
| 382 | * Disable host and panel hardware and pixel data transmission can not continue. |
| 383 | * |
| 384 | * Return: error code. |
| 385 | */ |
| 386 | int dsi_display_disable(struct dsi_display *display); |
| 387 | |
| 388 | /** |
| 389 | * dsi_display_unprepare() - power off display hardware. |
| 390 | * @display: Handle to display. |
| 391 | * |
| 392 | * Host and panel hardware is turned off. Panel will be in reset state at the |
| 393 | * end of the function. |
| 394 | * |
| 395 | * Return: error code. |
| 396 | */ |
| 397 | int dsi_display_unprepare(struct dsi_display *display); |
| 398 | |
| 399 | int dsi_display_set_tpg_state(struct dsi_display *display, bool enable); |
| 400 | |
| 401 | int dsi_display_clock_gate(struct dsi_display *display, bool enable); |
| 402 | int dsi_dispaly_static_frame(struct dsi_display *display, bool enable); |
| 403 | |
| 404 | #endif /* _DSI_DISPLAY_H_ */ |