Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 1 | /* |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 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_PANEL_H_ |
| 16 | #define _DSI_PANEL_H_ |
| 17 | |
| 18 | #include <linux/of_device.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/bitops.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/leds.h> |
| 23 | #include <drm/drm_panel.h> |
| 24 | #include <drm/drm_mipi_dsi.h> |
| 25 | |
| 26 | #include "dsi_defs.h" |
| 27 | #include "dsi_ctrl_hw.h" |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 28 | #include "dsi_clk.h" |
| 29 | #include "dsi_pwr.h" |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 30 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 31 | #define MAX_BL_LEVEL 4096 |
| 32 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 33 | enum dsi_panel_rotation { |
| 34 | DSI_PANEL_ROTATE_NONE = 0, |
| 35 | DSI_PANEL_ROTATE_HV_FLIP, |
| 36 | DSI_PANEL_ROTATE_H_FLIP, |
| 37 | DSI_PANEL_ROTATE_V_FLIP |
| 38 | }; |
| 39 | |
| 40 | enum dsi_cmd_set_type { |
| 41 | DSI_CMD_SET_PRE_ON = 0, |
| 42 | DSI_CMD_SET_ON, |
| 43 | DSI_CMD_SET_POST_ON, |
| 44 | DSI_CMD_SET_PRE_OFF, |
| 45 | DSI_CMD_SET_OFF, |
| 46 | DSI_CMD_SET_POST_OFF, |
| 47 | DSI_CMD_SET_PRE_RES_SWITCH, |
| 48 | DSI_CMD_SET_RES_SWITCH, |
| 49 | DSI_CMD_SET_POST_RES_SWITCH, |
| 50 | DSI_CMD_SET_CMD_TO_VID_SWITCH, |
| 51 | DSI_CMD_SET_POST_CMD_TO_VID_SWITCH, |
| 52 | DSI_CMD_SET_VID_TO_CMD_SWITCH, |
| 53 | DSI_CMD_SET_POST_VID_TO_CMD_SWITCH, |
| 54 | DSI_CMD_SET_PANEL_STATUS, |
| 55 | DSI_CMD_SET_MAX |
| 56 | }; |
| 57 | |
| 58 | enum dsi_cmd_set_state { |
| 59 | DSI_CMD_SET_STATE_LP = 0, |
| 60 | DSI_CMD_SET_STATE_HS, |
| 61 | DSI_CMD_SET_STATE_MAX |
| 62 | }; |
| 63 | |
| 64 | enum dsi_backlight_type { |
| 65 | DSI_BACKLIGHT_PWM = 0, |
| 66 | DSI_BACKLIGHT_WLED, |
| 67 | DSI_BACKLIGHT_DCS, |
| 68 | DSI_BACKLIGHT_UNKNOWN, |
| 69 | DSI_BACKLIGHT_MAX, |
| 70 | }; |
| 71 | |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 72 | enum { |
| 73 | MODE_GPIO_NOT_VALID = 0, |
| 74 | MODE_SEL_DUAL_PORT, |
| 75 | MODE_SEL_SINGLE_PORT, |
| 76 | MODE_GPIO_HIGH, |
| 77 | MODE_GPIO_LOW, |
| 78 | }; |
| 79 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 80 | struct dsi_dfps_capabilities { |
| 81 | bool dfps_support; |
| 82 | enum dsi_dfps_type type; |
| 83 | u32 min_refresh_rate; |
| 84 | u32 max_refresh_rate; |
| 85 | }; |
| 86 | |
| 87 | struct dsi_pinctrl_info { |
| 88 | struct pinctrl *pinctrl; |
| 89 | struct pinctrl_state *active; |
| 90 | struct pinctrl_state *suspend; |
| 91 | }; |
| 92 | |
| 93 | struct dsi_panel_phy_props { |
| 94 | u32 panel_width_mm; |
| 95 | u32 panel_height_mm; |
| 96 | enum dsi_panel_rotation rotation; |
| 97 | }; |
| 98 | |
| 99 | struct dsi_cmd_desc { |
| 100 | struct mipi_dsi_msg msg; |
| 101 | bool last_command; |
| 102 | u32 post_wait_ms; |
| 103 | }; |
| 104 | |
| 105 | struct dsi_panel_cmd_set { |
| 106 | enum dsi_cmd_set_type type; |
| 107 | enum dsi_cmd_set_state state; |
| 108 | u32 count; |
| 109 | struct dsi_cmd_desc *cmds; |
| 110 | }; |
| 111 | |
| 112 | struct dsi_backlight_config { |
| 113 | enum dsi_backlight_type type; |
| 114 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 115 | u32 bl_min_level; |
| 116 | u32 bl_max_level; |
| 117 | u32 brightness_max_level; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 118 | |
| 119 | int en_gpio; |
| 120 | /* PWM params */ |
| 121 | bool pwm_pmi_control; |
| 122 | u32 pwm_pmic_bank; |
| 123 | u32 pwm_period_usecs; |
| 124 | int pwm_gpio; |
| 125 | |
| 126 | /* WLED params */ |
| 127 | struct led_trigger *wled; |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 128 | struct backlight_device *bd; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | struct dsi_reset_seq { |
| 132 | u32 level; |
| 133 | u32 sleep_ms; |
| 134 | }; |
| 135 | |
| 136 | struct dsi_panel_reset_config { |
| 137 | struct dsi_reset_seq *sequence; |
| 138 | u32 count; |
| 139 | |
| 140 | int reset_gpio; |
| 141 | int disp_en_gpio; |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 142 | int lcd_mode_sel_gpio; |
| 143 | u32 mode_sel_state; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | struct dsi_panel { |
| 147 | const char *name; |
| 148 | struct device_node *panel_of_node; |
| 149 | struct mipi_dsi_device mipi_device; |
| 150 | |
| 151 | struct mutex panel_lock; |
| 152 | struct drm_panel drm_panel; |
| 153 | struct mipi_dsi_host *host; |
| 154 | struct device *parent; |
| 155 | |
| 156 | struct dsi_host_common_cfg host_config; |
| 157 | struct dsi_video_engine_cfg video_config; |
| 158 | struct dsi_cmd_engine_cfg cmd_config; |
| 159 | |
| 160 | struct dsi_dfps_capabilities dfps_caps; |
| 161 | |
| 162 | struct dsi_panel_cmd_set cmd_sets[DSI_CMD_SET_MAX]; |
| 163 | struct dsi_panel_phy_props phy_props; |
| 164 | |
Padmanabhan Komanduru | ee89d21 | 2016-12-19 12:51:31 +0530 | [diff] [blame] | 165 | u32 *phy_timing_val; |
| 166 | u32 phy_timing_len; |
| 167 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 168 | struct dsi_regulator_info power_info; |
| 169 | struct dsi_display_mode mode; |
| 170 | |
| 171 | struct dsi_backlight_config bl_config; |
| 172 | struct dsi_panel_reset_config reset_config; |
| 173 | struct dsi_pinctrl_info pinctrl; |
| 174 | |
| 175 | bool lp11_init; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 176 | bool ulps_enabled; |
| 177 | bool allow_phy_power_off; |
| 178 | |
Dhaval Patel | 60e1ff5 | 2017-02-18 21:03:40 -0800 | [diff] [blame^] | 179 | u32 panel_jitter; |
| 180 | u32 panel_prefill_lines; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 181 | bool panel_initialized; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 184 | static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel) |
| 185 | { |
| 186 | return panel->ulps_enabled; |
| 187 | } |
| 188 | |
| 189 | static inline bool dsi_panel_initialized(struct dsi_panel *panel) |
| 190 | { |
| 191 | return panel->panel_initialized; |
| 192 | } |
| 193 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 194 | struct dsi_panel *dsi_panel_get(struct device *parent, |
| 195 | struct device_node *of_node); |
| 196 | void dsi_panel_put(struct dsi_panel *panel); |
| 197 | |
| 198 | int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host); |
| 199 | int dsi_panel_drv_deinit(struct dsi_panel *panel); |
| 200 | |
| 201 | int dsi_panel_get_mode_count(struct dsi_panel *panel, u32 *count); |
| 202 | int dsi_panel_get_mode(struct dsi_panel *panel, |
| 203 | u32 index, |
| 204 | struct dsi_display_mode *mode); |
| 205 | int dsi_panel_validate_mode(struct dsi_panel *panel, |
| 206 | struct dsi_display_mode *mode); |
| 207 | int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel, |
| 208 | struct dsi_display_mode *mode, |
| 209 | struct dsi_host_config *config); |
| 210 | |
| 211 | int dsi_panel_get_phy_props(struct dsi_panel *panel, |
| 212 | struct dsi_panel_phy_props *phy_props); |
Ajay Singh Parmar | 62f795b | 2016-06-10 23:20:23 -0700 | [diff] [blame] | 213 | int dsi_panel_get_dfps_caps(struct dsi_panel *panel, |
| 214 | struct dsi_dfps_capabilities *dfps_caps); |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 215 | |
| 216 | int dsi_panel_pre_prepare(struct dsi_panel *panel); |
| 217 | |
| 218 | int dsi_panel_prepare(struct dsi_panel *panel); |
| 219 | |
| 220 | int dsi_panel_enable(struct dsi_panel *panel); |
| 221 | |
| 222 | int dsi_panel_post_enable(struct dsi_panel *panel); |
| 223 | |
| 224 | int dsi_panel_pre_disable(struct dsi_panel *panel); |
| 225 | |
| 226 | int dsi_panel_disable(struct dsi_panel *panel); |
| 227 | |
| 228 | int dsi_panel_unprepare(struct dsi_panel *panel); |
| 229 | |
| 230 | int dsi_panel_post_unprepare(struct dsi_panel *panel); |
| 231 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 232 | int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl); |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 233 | #endif /* _DSI_PANEL_H_ */ |