Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2010 Intel Corporation |
| 3 | * Copyright (c) 2006 Dave Airlie <airlied@linux.ie> |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Eric Anholt <eric@anholt.net> |
| 26 | * Dave Airlie <airlied@linux.ie> |
| 27 | * Jesse Barnes <jesse.barnes@intel.com> |
| 28 | * Chris Wilson <chris@chris-wilson.co.uk> |
| 29 | */ |
| 30 | |
Joe Perches | a70491c | 2012-03-18 13:00:11 -0700 | [diff] [blame] | 31 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 32 | |
Javi Merino | f766093 | 2015-04-16 12:43:45 -0700 | [diff] [blame] | 33 | #include <linux/kernel.h> |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 34 | #include <linux/moduleparam.h> |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 35 | #include <linux/pwm.h> |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 36 | #include "intel_drv.h" |
| 37 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 38 | #define CRC_PMIC_PWM_PERIOD_NS 21333 |
| 39 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 40 | void |
Ville Syrjälä | 4c6df4b | 2013-09-02 21:13:39 +0300 | [diff] [blame] | 41 | intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode, |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 42 | struct drm_display_mode *adjusted_mode) |
| 43 | { |
Ville Syrjälä | 4c6df4b | 2013-09-02 21:13:39 +0300 | [diff] [blame] | 44 | drm_mode_copy(adjusted_mode, fixed_mode); |
Imre Deak | a52690e | 2013-08-27 12:24:09 +0300 | [diff] [blame] | 45 | |
| 46 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 49 | /** |
| 50 | * intel_find_panel_downclock - find the reduced downclock for LVDS in EDID |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 51 | * @dev_priv: i915 device instance |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 52 | * @fixed_mode : panel native mode |
| 53 | * @connector: LVDS/eDP connector |
| 54 | * |
| 55 | * Return downclock_avail |
| 56 | * Find the reduced downclock for LVDS/eDP in EDID. |
| 57 | */ |
| 58 | struct drm_display_mode * |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 59 | intel_find_panel_downclock(struct drm_i915_private *dev_priv, |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 60 | struct drm_display_mode *fixed_mode, |
| 61 | struct drm_connector *connector) |
| 62 | { |
| 63 | struct drm_display_mode *scan, *tmp_mode; |
| 64 | int temp_downclock; |
| 65 | |
| 66 | temp_downclock = fixed_mode->clock; |
| 67 | tmp_mode = NULL; |
| 68 | |
| 69 | list_for_each_entry(scan, &connector->probed_modes, head) { |
| 70 | /* |
| 71 | * If one mode has the same resolution with the fixed_panel |
| 72 | * mode while they have the different refresh rate, it means |
| 73 | * that the reduced downclock is found. In such |
| 74 | * case we can set the different FPx0/1 to dynamically select |
| 75 | * between low and high frequency. |
| 76 | */ |
| 77 | if (scan->hdisplay == fixed_mode->hdisplay && |
| 78 | scan->hsync_start == fixed_mode->hsync_start && |
| 79 | scan->hsync_end == fixed_mode->hsync_end && |
| 80 | scan->htotal == fixed_mode->htotal && |
| 81 | scan->vdisplay == fixed_mode->vdisplay && |
| 82 | scan->vsync_start == fixed_mode->vsync_start && |
| 83 | scan->vsync_end == fixed_mode->vsync_end && |
| 84 | scan->vtotal == fixed_mode->vtotal) { |
| 85 | if (scan->clock < temp_downclock) { |
| 86 | /* |
| 87 | * The downclock is already found. But we |
| 88 | * expect to find the lower downclock. |
| 89 | */ |
| 90 | temp_downclock = scan->clock; |
| 91 | tmp_mode = scan; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (temp_downclock < fixed_mode->clock) |
Mika Kahola | a318b4c | 2016-12-13 10:02:48 +0200 | [diff] [blame] | 97 | return drm_mode_duplicate(&dev_priv->drm, tmp_mode); |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 98 | else |
| 99 | return NULL; |
| 100 | } |
| 101 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 102 | /* adjusted_mode has been preset to be the panel's fixed mode */ |
| 103 | void |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 104 | intel_pch_panel_fitting(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 105 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 106 | int fitting_mode) |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 107 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 108 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
| 109 | int x = 0, y = 0, width = 0, height = 0; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 110 | |
| 111 | /* Native modes don't need fitting */ |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 112 | if (adjusted_mode->crtc_hdisplay == pipe_config->pipe_src_w && |
| 113 | adjusted_mode->crtc_vdisplay == pipe_config->pipe_src_h) |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 114 | goto done; |
| 115 | |
| 116 | switch (fitting_mode) { |
| 117 | case DRM_MODE_SCALE_CENTER: |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 118 | width = pipe_config->pipe_src_w; |
| 119 | height = pipe_config->pipe_src_h; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 120 | x = (adjusted_mode->crtc_hdisplay - width + 1)/2; |
| 121 | y = (adjusted_mode->crtc_vdisplay - height + 1)/2; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 122 | break; |
| 123 | |
| 124 | case DRM_MODE_SCALE_ASPECT: |
| 125 | /* Scale but preserve the aspect ratio */ |
| 126 | { |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 127 | u32 scaled_width = adjusted_mode->crtc_hdisplay |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 128 | * pipe_config->pipe_src_h; |
| 129 | u32 scaled_height = pipe_config->pipe_src_w |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 130 | * adjusted_mode->crtc_vdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 131 | if (scaled_width > scaled_height) { /* pillar */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 132 | width = scaled_height / pipe_config->pipe_src_h; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 133 | if (width & 1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 134 | width++; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 135 | x = (adjusted_mode->crtc_hdisplay - width + 1) / 2; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 136 | y = 0; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 137 | height = adjusted_mode->crtc_vdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 138 | } else if (scaled_width < scaled_height) { /* letter */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 139 | height = scaled_width / pipe_config->pipe_src_w; |
Adam Jackson | 302983e | 2011-07-13 16:32:32 -0400 | [diff] [blame] | 140 | if (height & 1) |
| 141 | height++; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 142 | y = (adjusted_mode->crtc_vdisplay - height + 1) / 2; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 143 | x = 0; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 144 | width = adjusted_mode->crtc_hdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 145 | } else { |
| 146 | x = y = 0; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 147 | width = adjusted_mode->crtc_hdisplay; |
| 148 | height = adjusted_mode->crtc_vdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | break; |
| 152 | |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 153 | case DRM_MODE_SCALE_FULLSCREEN: |
| 154 | x = y = 0; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 155 | width = adjusted_mode->crtc_hdisplay; |
| 156 | height = adjusted_mode->crtc_vdisplay; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 157 | break; |
Jesse Barnes | ab3e67f | 2013-04-25 12:55:03 -0700 | [diff] [blame] | 158 | |
| 159 | default: |
| 160 | WARN(1, "bad panel fit mode: %d\n", fitting_mode); |
| 161 | return; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | done: |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 165 | pipe_config->pch_pfit.pos = (x << 16) | y; |
| 166 | pipe_config->pch_pfit.size = (width << 16) | height; |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 167 | pipe_config->pch_pfit.enabled = pipe_config->pch_pfit.size != 0; |
Chris Wilson | 1d8e1c7 | 2010-08-07 11:01:28 +0100 | [diff] [blame] | 168 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 169 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 170 | static void |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 171 | centre_horizontally(struct drm_display_mode *adjusted_mode, |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 172 | int width) |
| 173 | { |
| 174 | u32 border, sync_pos, blank_width, sync_width; |
| 175 | |
| 176 | /* keep the hsync and hblank widths constant */ |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 177 | sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start; |
| 178 | blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 179 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 180 | |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 181 | border = (adjusted_mode->crtc_hdisplay - width + 1) / 2; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 182 | border += border & 1; /* make the border even */ |
| 183 | |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 184 | adjusted_mode->crtc_hdisplay = width; |
| 185 | adjusted_mode->crtc_hblank_start = width + border; |
| 186 | adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 187 | |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 188 | adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos; |
| 189 | adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 193 | centre_vertically(struct drm_display_mode *adjusted_mode, |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 194 | int height) |
| 195 | { |
| 196 | u32 border, sync_pos, blank_width, sync_width; |
| 197 | |
| 198 | /* keep the vsync and vblank widths constant */ |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 199 | sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start; |
| 200 | blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 201 | sync_pos = (blank_width - sync_width + 1) / 2; |
| 202 | |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 203 | border = (adjusted_mode->crtc_vdisplay - height + 1) / 2; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 204 | |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 205 | adjusted_mode->crtc_vdisplay = height; |
| 206 | adjusted_mode->crtc_vblank_start = height + border; |
| 207 | adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 208 | |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 209 | adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos; |
| 210 | adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static inline u32 panel_fitter_scaling(u32 source, u32 target) |
| 214 | { |
| 215 | /* |
| 216 | * Floating point operation is not supported. So the FACTOR |
| 217 | * is defined, which can avoid the floating point computation |
| 218 | * when calculating the panel ratio. |
| 219 | */ |
| 220 | #define ACCURACY 12 |
| 221 | #define FACTOR (1 << ACCURACY) |
| 222 | u32 ratio = source * FACTOR / target; |
| 223 | return (FACTOR * ratio + FACTOR/2) / FACTOR; |
| 224 | } |
| 225 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 226 | static void i965_scale_aspect(struct intel_crtc_state *pipe_config, |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 227 | u32 *pfit_control) |
| 228 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 229 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 230 | u32 scaled_width = adjusted_mode->crtc_hdisplay * |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 231 | pipe_config->pipe_src_h; |
| 232 | u32 scaled_height = pipe_config->pipe_src_w * |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 233 | adjusted_mode->crtc_vdisplay; |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 234 | |
| 235 | /* 965+ is easy, it does everything in hw */ |
| 236 | if (scaled_width > scaled_height) |
| 237 | *pfit_control |= PFIT_ENABLE | |
| 238 | PFIT_SCALING_PILLAR; |
| 239 | else if (scaled_width < scaled_height) |
| 240 | *pfit_control |= PFIT_ENABLE | |
| 241 | PFIT_SCALING_LETTER; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 242 | else if (adjusted_mode->crtc_hdisplay != pipe_config->pipe_src_w) |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 243 | *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO; |
| 244 | } |
| 245 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 246 | static void i9xx_scale_aspect(struct intel_crtc_state *pipe_config, |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 247 | u32 *pfit_control, u32 *pfit_pgm_ratios, |
| 248 | u32 *border) |
| 249 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 250 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 251 | u32 scaled_width = adjusted_mode->crtc_hdisplay * |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 252 | pipe_config->pipe_src_h; |
| 253 | u32 scaled_height = pipe_config->pipe_src_w * |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 254 | adjusted_mode->crtc_vdisplay; |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 255 | u32 bits; |
| 256 | |
| 257 | /* |
| 258 | * For earlier chips we have to calculate the scaling |
| 259 | * ratio by hand and program it into the |
| 260 | * PFIT_PGM_RATIO register |
| 261 | */ |
| 262 | if (scaled_width > scaled_height) { /* pillar */ |
| 263 | centre_horizontally(adjusted_mode, |
| 264 | scaled_height / |
| 265 | pipe_config->pipe_src_h); |
| 266 | |
| 267 | *border = LVDS_BORDER_ENABLE; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 268 | if (pipe_config->pipe_src_h != adjusted_mode->crtc_vdisplay) { |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 269 | bits = panel_fitter_scaling(pipe_config->pipe_src_h, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 270 | adjusted_mode->crtc_vdisplay); |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 271 | |
| 272 | *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 273 | bits << PFIT_VERT_SCALE_SHIFT); |
| 274 | *pfit_control |= (PFIT_ENABLE | |
| 275 | VERT_INTERP_BILINEAR | |
| 276 | HORIZ_INTERP_BILINEAR); |
| 277 | } |
| 278 | } else if (scaled_width < scaled_height) { /* letter */ |
| 279 | centre_vertically(adjusted_mode, |
| 280 | scaled_width / |
| 281 | pipe_config->pipe_src_w); |
| 282 | |
| 283 | *border = LVDS_BORDER_ENABLE; |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 284 | if (pipe_config->pipe_src_w != adjusted_mode->crtc_hdisplay) { |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 285 | bits = panel_fitter_scaling(pipe_config->pipe_src_w, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 286 | adjusted_mode->crtc_hdisplay); |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 287 | |
| 288 | *pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT | |
| 289 | bits << PFIT_VERT_SCALE_SHIFT); |
| 290 | *pfit_control |= (PFIT_ENABLE | |
| 291 | VERT_INTERP_BILINEAR | |
| 292 | HORIZ_INTERP_BILINEAR); |
| 293 | } |
| 294 | } else { |
| 295 | /* Aspects match, Let hw scale both directions */ |
| 296 | *pfit_control |= (PFIT_ENABLE | |
| 297 | VERT_AUTO_SCALE | HORIZ_AUTO_SCALE | |
| 298 | VERT_INTERP_BILINEAR | |
| 299 | HORIZ_INTERP_BILINEAR); |
| 300 | } |
| 301 | } |
| 302 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 303 | void intel_gmch_panel_fitting(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 304 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 305 | int fitting_mode) |
| 306 | { |
Tvrtko Ursulin | 6647847 | 2016-11-16 08:55:40 +0000 | [diff] [blame] | 307 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 308 | u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 309 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 310 | |
| 311 | /* Native modes don't need fitting */ |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 312 | if (adjusted_mode->crtc_hdisplay == pipe_config->pipe_src_w && |
| 313 | adjusted_mode->crtc_vdisplay == pipe_config->pipe_src_h) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 314 | goto out; |
| 315 | |
| 316 | switch (fitting_mode) { |
| 317 | case DRM_MODE_SCALE_CENTER: |
| 318 | /* |
| 319 | * For centered modes, we have to calculate border widths & |
| 320 | * heights and modify the values programmed into the CRTC. |
| 321 | */ |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 322 | centre_horizontally(adjusted_mode, pipe_config->pipe_src_w); |
| 323 | centre_vertically(adjusted_mode, pipe_config->pipe_src_h); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 324 | border = LVDS_BORDER_ENABLE; |
| 325 | break; |
| 326 | case DRM_MODE_SCALE_ASPECT: |
| 327 | /* Scale but preserve the aspect ratio */ |
Tvrtko Ursulin | 6647847 | 2016-11-16 08:55:40 +0000 | [diff] [blame] | 328 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | 9084e7d | 2013-09-16 23:43:45 +0200 | [diff] [blame] | 329 | i965_scale_aspect(pipe_config, &pfit_control); |
| 330 | else |
| 331 | i9xx_scale_aspect(pipe_config, &pfit_control, |
| 332 | &pfit_pgm_ratios, &border); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 333 | break; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 334 | case DRM_MODE_SCALE_FULLSCREEN: |
| 335 | /* |
| 336 | * Full scaling, even if it changes the aspect ratio. |
| 337 | * Fortunately this is all done for us in hw. |
| 338 | */ |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 339 | if (pipe_config->pipe_src_h != adjusted_mode->crtc_vdisplay || |
| 340 | pipe_config->pipe_src_w != adjusted_mode->crtc_hdisplay) { |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 341 | pfit_control |= PFIT_ENABLE; |
Tvrtko Ursulin | 6647847 | 2016-11-16 08:55:40 +0000 | [diff] [blame] | 342 | if (INTEL_GEN(dev_priv) >= 4) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 343 | pfit_control |= PFIT_SCALING_AUTO; |
| 344 | else |
| 345 | pfit_control |= (VERT_AUTO_SCALE | |
| 346 | VERT_INTERP_BILINEAR | |
| 347 | HORIZ_AUTO_SCALE | |
| 348 | HORIZ_INTERP_BILINEAR); |
| 349 | } |
| 350 | break; |
Jesse Barnes | ab3e67f | 2013-04-25 12:55:03 -0700 | [diff] [blame] | 351 | default: |
| 352 | WARN(1, "bad panel fit mode: %d\n", fitting_mode); |
| 353 | return; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* 965+ wants fuzzy fitting */ |
| 357 | /* FIXME: handle multiple panels by failing gracefully */ |
Tvrtko Ursulin | 6647847 | 2016-11-16 08:55:40 +0000 | [diff] [blame] | 358 | if (INTEL_GEN(dev_priv) >= 4) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 359 | pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) | |
| 360 | PFIT_FILTER_FUZZY); |
| 361 | |
| 362 | out: |
| 363 | if ((pfit_control & PFIT_ENABLE) == 0) { |
| 364 | pfit_control = 0; |
| 365 | pfit_pgm_ratios = 0; |
| 366 | } |
| 367 | |
Daniel Vetter | 6b89cdd | 2014-07-09 22:35:53 +0200 | [diff] [blame] | 368 | /* Make sure pre-965 set dither correctly for 18bpp panels. */ |
Tvrtko Ursulin | 6647847 | 2016-11-16 08:55:40 +0000 | [diff] [blame] | 369 | if (INTEL_GEN(dev_priv) < 4 && pipe_config->pipe_bpp == 18) |
Daniel Vetter | 6b89cdd | 2014-07-09 22:35:53 +0200 | [diff] [blame] | 370 | pfit_control |= PANEL_8TO6_DITHER_ENABLE; |
| 371 | |
Daniel Vetter | 2deefda | 2013-04-25 22:52:17 +0200 | [diff] [blame] | 372 | pipe_config->gmch_pfit.control = pfit_control; |
| 373 | pipe_config->gmch_pfit.pgm_ratios = pfit_pgm_ratios; |
Daniel Vetter | 68fc874 | 2013-04-25 22:52:16 +0200 | [diff] [blame] | 374 | pipe_config->gmch_pfit.lvds_border_bits = border; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 377 | enum drm_connector_status |
Mika Kahola | 1650be7 | 2016-12-13 10:02:47 +0200 | [diff] [blame] | 378 | intel_panel_detect(struct drm_i915_private *dev_priv) |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 379 | { |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 380 | /* Assume that the BIOS does not lie through the OpRegion... */ |
| 381 | if (!i915.panel_ignore_lid && dev_priv->opregion.lid_state) { |
Williams, Dan J | 115719f | 2015-10-12 21:12:57 +0000 | [diff] [blame] | 382 | return *dev_priv->opregion.lid_state & 0x1 ? |
Jani Nikula | 525997e | 2014-04-29 23:30:48 +0300 | [diff] [blame] | 383 | connector_status_connected : |
| 384 | connector_status_disconnected; |
| 385 | } |
| 386 | |
| 387 | switch (i915.panel_ignore_lid) { |
| 388 | case -2: |
| 389 | return connector_status_connected; |
| 390 | case -1: |
| 391 | return connector_status_disconnected; |
| 392 | default: |
| 393 | return connector_status_unknown; |
| 394 | } |
| 395 | } |
| 396 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 397 | /** |
| 398 | * scale - scale values from one range to another |
| 399 | * |
| 400 | * @source_val: value in range [@source_min..@source_max] |
| 401 | * |
| 402 | * Return @source_val in range [@source_min..@source_max] scaled to range |
| 403 | * [@target_min..@target_max]. |
| 404 | */ |
| 405 | static uint32_t scale(uint32_t source_val, |
| 406 | uint32_t source_min, uint32_t source_max, |
| 407 | uint32_t target_min, uint32_t target_max) |
| 408 | { |
| 409 | uint64_t target_val; |
| 410 | |
| 411 | WARN_ON(source_min > source_max); |
| 412 | WARN_ON(target_min > target_max); |
| 413 | |
| 414 | /* defensive */ |
| 415 | source_val = clamp(source_val, source_min, source_max); |
| 416 | |
| 417 | /* avoid overflows */ |
U. Artie Eoff | 673e7bb | 2014-09-29 15:49:32 -0700 | [diff] [blame] | 418 | target_val = DIV_ROUND_CLOSEST_ULL((uint64_t)(source_val - source_min) * |
| 419 | (target_max - target_min), source_max - source_min); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 420 | target_val += target_min; |
| 421 | |
| 422 | return target_val; |
| 423 | } |
| 424 | |
| 425 | /* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */ |
| 426 | static inline u32 scale_user_to_hw(struct intel_connector *connector, |
| 427 | u32 user_level, u32 user_max) |
| 428 | { |
| 429 | struct intel_panel *panel = &connector->panel; |
| 430 | |
| 431 | return scale(user_level, 0, user_max, |
| 432 | panel->backlight.min, panel->backlight.max); |
| 433 | } |
| 434 | |
| 435 | /* Scale user_level in range [0..user_max] to [0..hw_max], clamping the result |
| 436 | * to [hw_min..hw_max]. */ |
| 437 | static inline u32 clamp_user_to_hw(struct intel_connector *connector, |
| 438 | u32 user_level, u32 user_max) |
| 439 | { |
| 440 | struct intel_panel *panel = &connector->panel; |
| 441 | u32 hw_level; |
| 442 | |
| 443 | hw_level = scale(user_level, 0, user_max, 0, panel->backlight.max); |
| 444 | hw_level = clamp(hw_level, panel->backlight.min, panel->backlight.max); |
| 445 | |
| 446 | return hw_level; |
| 447 | } |
| 448 | |
| 449 | /* Scale hw_level in range [hw_min..hw_max] to [0..user_max]. */ |
| 450 | static inline u32 scale_hw_to_user(struct intel_connector *connector, |
| 451 | u32 hw_level, u32 user_max) |
| 452 | { |
| 453 | struct intel_panel *panel = &connector->panel; |
| 454 | |
| 455 | return scale(hw_level, panel->backlight.min, panel->backlight.max, |
| 456 | 0, user_max); |
| 457 | } |
| 458 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 459 | static u32 intel_panel_compute_brightness(struct intel_connector *connector, |
| 460 | u32 val) |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 461 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 462 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 463 | struct intel_panel *panel = &connector->panel; |
| 464 | |
| 465 | WARN_ON(panel->backlight.max == 0); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 466 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 467 | if (i915.invert_brightness < 0) |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 468 | return val; |
| 469 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 470 | if (i915.invert_brightness > 0 || |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 471 | dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) { |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 472 | return panel->backlight.max - val; |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 473 | } |
Carsten Emde | 7bd9090 | 2012-03-15 15:56:25 +0100 | [diff] [blame] | 474 | |
| 475 | return val; |
| 476 | } |
| 477 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 478 | static u32 lpt_get_backlight(struct intel_connector *connector) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 479 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 480 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 481 | |
| 482 | return I915_READ(BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 483 | } |
| 484 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 485 | static u32 pch_get_backlight(struct intel_connector *connector) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 486 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 487 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 488 | |
| 489 | return I915_READ(BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 490 | } |
| 491 | |
| 492 | static u32 i9xx_get_backlight(struct intel_connector *connector) |
| 493 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 494 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 495 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 496 | u32 val; |
| 497 | |
| 498 | val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 499 | if (INTEL_INFO(dev_priv)->gen < 4) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 500 | val >>= 1; |
| 501 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 502 | if (panel->backlight.combination_mode) { |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 503 | u8 lbpc; |
| 504 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 505 | pci_read_config_byte(dev_priv->drm.pdev, LBPC, &lbpc); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 506 | val *= lbpc; |
| 507 | } |
| 508 | |
| 509 | return val; |
| 510 | } |
| 511 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 512 | static u32 _vlv_get_backlight(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 513 | { |
Ville Syrjälä | 23ec0a8 | 2014-11-07 11:15:59 +0200 | [diff] [blame] | 514 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 515 | return 0; |
| 516 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 517 | return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK; |
| 518 | } |
| 519 | |
| 520 | static u32 vlv_get_backlight(struct intel_connector *connector) |
| 521 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 522 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 523 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 524 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 525 | return _vlv_get_backlight(dev_priv, pipe); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 528 | static u32 bxt_get_backlight(struct intel_connector *connector) |
| 529 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 530 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 531 | struct intel_panel *panel = &connector->panel; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 532 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 533 | return I915_READ(BXT_BLC_PWM_DUTY(panel->backlight.controller)); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 534 | } |
| 535 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 536 | static u32 pwm_get_backlight(struct intel_connector *connector) |
| 537 | { |
| 538 | struct intel_panel *panel = &connector->panel; |
| 539 | int duty_ns; |
| 540 | |
| 541 | duty_ns = pwm_get_duty_cycle(panel->backlight.pwm); |
| 542 | return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS); |
| 543 | } |
| 544 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 545 | static u32 intel_panel_get_backlight(struct intel_connector *connector) |
| 546 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 547 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Ville Syrjälä | 2d72f6c | 2014-11-07 15:18:45 +0200 | [diff] [blame] | 548 | struct intel_panel *panel = &connector->panel; |
| 549 | u32 val = 0; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 550 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 551 | mutex_lock(&dev_priv->backlight_lock); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 552 | |
Ville Syrjälä | 2d72f6c | 2014-11-07 15:18:45 +0200 | [diff] [blame] | 553 | if (panel->backlight.enabled) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 554 | val = panel->backlight.get(connector); |
Ville Syrjälä | 2d72f6c | 2014-11-07 15:18:45 +0200 | [diff] [blame] | 555 | val = intel_panel_compute_brightness(connector, val); |
| 556 | } |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 557 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 558 | mutex_unlock(&dev_priv->backlight_lock); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 559 | |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 560 | DRM_DEBUG_DRIVER("get backlight PWM = %d\n", val); |
| 561 | return val; |
| 562 | } |
| 563 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 564 | static void lpt_set_backlight(struct intel_connector *connector, u32 level) |
Ben Widawsky | f8e1006 | 2013-11-11 11:12:57 +0200 | [diff] [blame] | 565 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 566 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Ben Widawsky | f8e1006 | 2013-11-11 11:12:57 +0200 | [diff] [blame] | 567 | u32 val = I915_READ(BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 568 | I915_WRITE(BLC_PWM_PCH_CTL2, val | level); |
| 569 | } |
| 570 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 571 | static void pch_set_backlight(struct intel_connector *connector, u32 level) |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 572 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 573 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 574 | u32 tmp; |
| 575 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 576 | tmp = I915_READ(BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 577 | I915_WRITE(BLC_PWM_CPU_CTL, tmp | level); |
| 578 | } |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 579 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 580 | static void i9xx_set_backlight(struct intel_connector *connector, u32 level) |
| 581 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 582 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 583 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 584 | u32 tmp, mask; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 585 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 586 | WARN_ON(panel->backlight.max == 0); |
| 587 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 588 | if (panel->backlight.combination_mode) { |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 589 | u8 lbpc; |
| 590 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 591 | lbpc = level * 0xfe / panel->backlight.max + 1; |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 592 | level /= lbpc; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 593 | pci_write_config_byte(dev_priv->drm.pdev, LBPC, lbpc); |
Takashi Iwai | ba3820a | 2011-03-10 14:02:12 +0100 | [diff] [blame] | 594 | } |
| 595 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 596 | if (IS_GEN4(dev_priv)) { |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 597 | mask = BACKLIGHT_DUTY_CYCLE_MASK; |
| 598 | } else { |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 599 | level <<= 1; |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 600 | mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV; |
| 601 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 602 | |
Jani Nikula | b329b32 | 2013-11-08 16:48:57 +0200 | [diff] [blame] | 603 | tmp = I915_READ(BLC_PWM_CTL) & ~mask; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 604 | I915_WRITE(BLC_PWM_CTL, tmp | level); |
| 605 | } |
| 606 | |
| 607 | static void vlv_set_backlight(struct intel_connector *connector, u32 level) |
| 608 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 609 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 610 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 611 | u32 tmp; |
| 612 | |
Ville Syrjälä | 23ec0a8 | 2014-11-07 11:15:59 +0200 | [diff] [blame] | 613 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 614 | return; |
| 615 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 616 | tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK; |
| 617 | I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level); |
| 618 | } |
| 619 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 620 | static void bxt_set_backlight(struct intel_connector *connector, u32 level) |
| 621 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 622 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 623 | struct intel_panel *panel = &connector->panel; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 624 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 625 | I915_WRITE(BXT_BLC_PWM_DUTY(panel->backlight.controller), level); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 626 | } |
| 627 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 628 | static void pwm_set_backlight(struct intel_connector *connector, u32 level) |
| 629 | { |
| 630 | struct intel_panel *panel = &connector->panel; |
| 631 | int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100); |
| 632 | |
| 633 | pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS); |
| 634 | } |
| 635 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 636 | static void |
| 637 | intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level) |
| 638 | { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 639 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 640 | |
| 641 | DRM_DEBUG_DRIVER("set backlight PWM = %d\n", level); |
| 642 | |
| 643 | level = intel_panel_compute_brightness(connector, level); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 644 | panel->backlight.set(connector, level); |
Chris Wilson | a957355 | 2010-08-22 13:18:16 +0100 | [diff] [blame] | 645 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 646 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 647 | /* set backlight brightness to level in range [0..max], scaling wrt hw min */ |
| 648 | static void intel_panel_set_backlight(struct intel_connector *connector, |
| 649 | u32 user_level, u32 user_max) |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 650 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 651 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 652 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 653 | u32 hw_level; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 654 | |
Ville Syrjälä | 260d8f9 | 2014-11-07 15:20:23 +0200 | [diff] [blame] | 655 | if (!panel->backlight.present) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 656 | return; |
| 657 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 658 | mutex_lock(&dev_priv->backlight_lock); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 659 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 660 | WARN_ON(panel->backlight.max == 0); |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 661 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 662 | hw_level = scale_user_to_hw(connector, user_level, user_max); |
| 663 | panel->backlight.level = hw_level; |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 664 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 665 | if (panel->backlight.enabled) |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 666 | intel_panel_actually_set_backlight(connector, hw_level); |
| 667 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 668 | mutex_unlock(&dev_priv->backlight_lock); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* set backlight brightness to level in range [0..max], assuming hw min is |
| 672 | * respected. |
| 673 | */ |
| 674 | void intel_panel_set_backlight_acpi(struct intel_connector *connector, |
| 675 | u32 user_level, u32 user_max) |
| 676 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 677 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 678 | struct intel_panel *panel = &connector->panel; |
| 679 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 680 | u32 hw_level; |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 681 | |
Ville Syrjälä | 260d8f9 | 2014-11-07 15:20:23 +0200 | [diff] [blame] | 682 | /* |
| 683 | * INVALID_PIPE may occur during driver init because |
| 684 | * connection_mutex isn't held across the entire backlight |
| 685 | * setup + modeset readout, and the BIOS can issue the |
| 686 | * requests at any time. |
| 687 | */ |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 688 | if (!panel->backlight.present || pipe == INVALID_PIPE) |
| 689 | return; |
| 690 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 691 | mutex_lock(&dev_priv->backlight_lock); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 692 | |
| 693 | WARN_ON(panel->backlight.max == 0); |
| 694 | |
| 695 | hw_level = clamp_user_to_hw(connector, user_level, user_max); |
| 696 | panel->backlight.level = hw_level; |
| 697 | |
| 698 | if (panel->backlight.device) |
| 699 | panel->backlight.device->props.brightness = |
| 700 | scale_hw_to_user(connector, |
| 701 | panel->backlight.level, |
| 702 | panel->backlight.device->props.max_brightness); |
| 703 | |
| 704 | if (panel->backlight.enabled) |
| 705 | intel_panel_actually_set_backlight(connector, hw_level); |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 706 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 707 | mutex_unlock(&dev_priv->backlight_lock); |
Takashi Iwai | f52c619 | 2011-10-14 11:45:40 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 710 | static void lpt_disable_backlight(struct intel_connector *connector) |
| 711 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 712 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 713 | u32 tmp; |
| 714 | |
| 715 | intel_panel_actually_set_backlight(connector, 0); |
| 716 | |
Jani Nikula | 6675bce | 2015-10-28 13:57:09 +0200 | [diff] [blame] | 717 | /* |
| 718 | * Although we don't support or enable CPU PWM with LPT/SPT based |
| 719 | * systems, it may have been enabled prior to loading the |
| 720 | * driver. Disable to avoid warnings on LCPLL disable. |
| 721 | * |
| 722 | * This needs rework if we need to add support for CPU PWM on PCH split |
| 723 | * platforms. |
| 724 | */ |
| 725 | tmp = I915_READ(BLC_PWM_CPU_CTL2); |
| 726 | if (tmp & BLM_PWM_ENABLE) { |
| 727 | DRM_DEBUG_KMS("cpu backlight was enabled, disabling\n"); |
| 728 | I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE); |
| 729 | } |
| 730 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 731 | tmp = I915_READ(BLC_PWM_PCH_CTL1); |
| 732 | I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); |
| 733 | } |
| 734 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 735 | static void pch_disable_backlight(struct intel_connector *connector) |
| 736 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 737 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 738 | u32 tmp; |
| 739 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 740 | intel_panel_actually_set_backlight(connector, 0); |
| 741 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 742 | tmp = I915_READ(BLC_PWM_CPU_CTL2); |
| 743 | I915_WRITE(BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE); |
| 744 | |
| 745 | tmp = I915_READ(BLC_PWM_PCH_CTL1); |
| 746 | I915_WRITE(BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); |
| 747 | } |
| 748 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 749 | static void i9xx_disable_backlight(struct intel_connector *connector) |
| 750 | { |
| 751 | intel_panel_actually_set_backlight(connector, 0); |
| 752 | } |
| 753 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 754 | static void i965_disable_backlight(struct intel_connector *connector) |
| 755 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 756 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 757 | u32 tmp; |
| 758 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 759 | intel_panel_actually_set_backlight(connector, 0); |
| 760 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 761 | tmp = I915_READ(BLC_PWM_CTL2); |
| 762 | I915_WRITE(BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE); |
| 763 | } |
| 764 | |
| 765 | static void vlv_disable_backlight(struct intel_connector *connector) |
| 766 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 767 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 768 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 769 | u32 tmp; |
| 770 | |
Ville Syrjälä | 23ec0a8 | 2014-11-07 11:15:59 +0200 | [diff] [blame] | 771 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 772 | return; |
| 773 | |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 774 | intel_panel_actually_set_backlight(connector, 0); |
| 775 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 776 | tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 777 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE); |
| 778 | } |
| 779 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 780 | static void bxt_disable_backlight(struct intel_connector *connector) |
| 781 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 782 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 783 | struct intel_panel *panel = &connector->panel; |
| 784 | u32 tmp, val; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 785 | |
| 786 | intel_panel_actually_set_backlight(connector, 0); |
| 787 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 788 | tmp = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller)); |
| 789 | I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), |
| 790 | tmp & ~BXT_BLC_PWM_ENABLE); |
| 791 | |
| 792 | if (panel->backlight.controller == 1) { |
| 793 | val = I915_READ(UTIL_PIN_CTL); |
| 794 | val &= ~UTIL_PIN_ENABLE; |
| 795 | I915_WRITE(UTIL_PIN_CTL, val); |
| 796 | } |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 797 | } |
| 798 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 799 | static void pwm_disable_backlight(struct intel_connector *connector) |
| 800 | { |
| 801 | struct intel_panel *panel = &connector->panel; |
| 802 | |
| 803 | /* Disable the backlight */ |
| 804 | pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS); |
| 805 | usleep_range(2000, 3000); |
| 806 | pwm_disable(panel->backlight.pwm); |
| 807 | } |
| 808 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 809 | void intel_panel_disable_backlight(struct intel_connector *connector) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 810 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 811 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 812 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 813 | |
Ville Syrjälä | 260d8f9 | 2014-11-07 15:20:23 +0200 | [diff] [blame] | 814 | if (!panel->backlight.present) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 815 | return; |
| 816 | |
Jani Nikula | 3f57757 | 2013-07-25 14:31:30 +0300 | [diff] [blame] | 817 | /* |
Lukas Wunner | 5389e91 | 2015-09-04 21:06:15 +0200 | [diff] [blame] | 818 | * Do not disable backlight on the vga_switcheroo path. When switching |
Jani Nikula | 3f57757 | 2013-07-25 14:31:30 +0300 | [diff] [blame] | 819 | * away from i915, the other client may depend on i915 to handle the |
| 820 | * backlight. This will leave the backlight on unnecessarily when |
| 821 | * another client is not activated. |
| 822 | */ |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 823 | if (dev_priv->drm.switch_power_state == DRM_SWITCH_POWER_CHANGING) { |
Jani Nikula | 3f57757 | 2013-07-25 14:31:30 +0300 | [diff] [blame] | 824 | DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n"); |
| 825 | return; |
| 826 | } |
| 827 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 828 | mutex_lock(&dev_priv->backlight_lock); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 829 | |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 830 | if (panel->backlight.device) |
| 831 | panel->backlight.device->props.power = FB_BLANK_POWERDOWN; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 832 | panel->backlight.enabled = false; |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 833 | panel->backlight.disable(connector); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 834 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 835 | mutex_unlock(&dev_priv->backlight_lock); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 838 | static void lpt_enable_backlight(struct intel_connector *connector) |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 839 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 840 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 841 | struct intel_panel *panel = &connector->panel; |
Shawn Lee | e29aff0 | 2016-09-19 13:35:26 +0300 | [diff] [blame] | 842 | u32 pch_ctl1, pch_ctl2, schicken; |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 843 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 844 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 845 | if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { |
| 846 | DRM_DEBUG_KMS("pch backlight already enabled\n"); |
| 847 | pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; |
| 848 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Shawn Lee | e29aff0 | 2016-09-19 13:35:26 +0300 | [diff] [blame] | 851 | if (HAS_PCH_LPT(dev_priv)) { |
| 852 | schicken = I915_READ(SOUTH_CHICKEN2); |
| 853 | if (panel->backlight.alternate_pwm_increment) |
| 854 | schicken |= LPT_PWM_GRANULARITY; |
| 855 | else |
| 856 | schicken &= ~LPT_PWM_GRANULARITY; |
| 857 | I915_WRITE(SOUTH_CHICKEN2, schicken); |
| 858 | } else { |
| 859 | schicken = I915_READ(SOUTH_CHICKEN1); |
| 860 | if (panel->backlight.alternate_pwm_increment) |
| 861 | schicken |= SPT_PWM_GRANULARITY; |
| 862 | else |
| 863 | schicken &= ~SPT_PWM_GRANULARITY; |
| 864 | I915_WRITE(SOUTH_CHICKEN1, schicken); |
| 865 | } |
| 866 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 867 | pch_ctl2 = panel->backlight.max << 16; |
| 868 | I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2); |
| 869 | |
| 870 | pch_ctl1 = 0; |
| 871 | if (panel->backlight.active_low_pwm) |
| 872 | pch_ctl1 |= BLM_PCH_POLARITY; |
| 873 | |
Jani Nikula | e6b2627 | 2014-10-10 17:53:33 +0300 | [diff] [blame] | 874 | /* After LPT, override is the default. */ |
| 875 | if (HAS_PCH_LPT(dev_priv)) |
| 876 | pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE; |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 877 | |
| 878 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 879 | POSTING_READ(BLC_PWM_PCH_CTL1); |
| 880 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE); |
| 881 | |
| 882 | /* This won't stick until the above enable. */ |
| 883 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
| 884 | } |
| 885 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 886 | static void pch_enable_backlight(struct intel_connector *connector) |
| 887 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 888 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 889 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 890 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 891 | enum transcoder cpu_transcoder = |
| 892 | intel_pipe_to_cpu_transcoder(dev_priv, pipe); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 893 | u32 cpu_ctl2, pch_ctl1, pch_ctl2; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 894 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 895 | cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2); |
| 896 | if (cpu_ctl2 & BLM_PWM_ENABLE) { |
Scot Doyle | 813008c | 2014-08-19 02:07:13 +0000 | [diff] [blame] | 897 | DRM_DEBUG_KMS("cpu backlight already enabled\n"); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 898 | cpu_ctl2 &= ~BLM_PWM_ENABLE; |
| 899 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 900 | } |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 901 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 902 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 903 | if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { |
| 904 | DRM_DEBUG_KMS("pch backlight already enabled\n"); |
| 905 | pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; |
| 906 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 907 | } |
| 908 | |
| 909 | if (cpu_transcoder == TRANSCODER_EDP) |
| 910 | cpu_ctl2 = BLM_TRANSCODER_EDP; |
| 911 | else |
| 912 | cpu_ctl2 = BLM_PIPE(cpu_transcoder); |
| 913 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2); |
| 914 | POSTING_READ(BLC_PWM_CPU_CTL2); |
| 915 | I915_WRITE(BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE); |
| 916 | |
| 917 | /* This won't stick until the above enable. */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 918 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 919 | |
| 920 | pch_ctl2 = panel->backlight.max << 16; |
| 921 | I915_WRITE(BLC_PWM_PCH_CTL2, pch_ctl2); |
| 922 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 923 | pch_ctl1 = 0; |
| 924 | if (panel->backlight.active_low_pwm) |
| 925 | pch_ctl1 |= BLM_PCH_POLARITY; |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 926 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 927 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1); |
| 928 | POSTING_READ(BLC_PWM_PCH_CTL1); |
| 929 | I915_WRITE(BLC_PWM_PCH_CTL1, pch_ctl1 | BLM_PCH_PWM_ENABLE); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | static void i9xx_enable_backlight(struct intel_connector *connector) |
| 933 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 934 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 935 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 936 | u32 ctl, freq; |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 937 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 938 | ctl = I915_READ(BLC_PWM_CTL); |
| 939 | if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) { |
Scot Doyle | 813008c | 2014-08-19 02:07:13 +0000 | [diff] [blame] | 940 | DRM_DEBUG_KMS("backlight already enabled\n"); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 941 | I915_WRITE(BLC_PWM_CTL, 0); |
| 942 | } |
| 943 | |
| 944 | freq = panel->backlight.max; |
| 945 | if (panel->backlight.combination_mode) |
| 946 | freq /= 0xff; |
| 947 | |
| 948 | ctl = freq << 17; |
Jani Nikula | b6ab66a | 2014-02-25 13:11:47 +0200 | [diff] [blame] | 949 | if (panel->backlight.combination_mode) |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 950 | ctl |= BLM_LEGACY_MODE; |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 951 | if (IS_PINEVIEW(dev_priv) && panel->backlight.active_low_pwm) |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 952 | ctl |= BLM_POLARITY_PNV; |
| 953 | |
| 954 | I915_WRITE(BLC_PWM_CTL, ctl); |
| 955 | POSTING_READ(BLC_PWM_CTL); |
| 956 | |
| 957 | /* XXX: combine this into above write? */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 958 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | 2059ac3 | 2015-06-26 14:18:56 +0300 | [diff] [blame] | 959 | |
| 960 | /* |
| 961 | * Needed to enable backlight on some 855gm models. BLC_HIST_CTL is |
| 962 | * 855gm only, but checking for gen2 is safe, as 855gm is the only gen2 |
| 963 | * that has backlight. |
| 964 | */ |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 965 | if (IS_GEN2(dev_priv)) |
Jani Nikula | 2059ac3 | 2015-06-26 14:18:56 +0300 | [diff] [blame] | 966 | I915_WRITE(BLC_HIST_CTL, BLM_HISTOGRAM_ENABLE); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static void i965_enable_backlight(struct intel_connector *connector) |
| 970 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 971 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 972 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 973 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 974 | u32 ctl, ctl2, freq; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 975 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 976 | ctl2 = I915_READ(BLC_PWM_CTL2); |
| 977 | if (ctl2 & BLM_PWM_ENABLE) { |
Scot Doyle | 813008c | 2014-08-19 02:07:13 +0000 | [diff] [blame] | 978 | DRM_DEBUG_KMS("backlight already enabled\n"); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 979 | ctl2 &= ~BLM_PWM_ENABLE; |
| 980 | I915_WRITE(BLC_PWM_CTL2, ctl2); |
| 981 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 982 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 983 | freq = panel->backlight.max; |
| 984 | if (panel->backlight.combination_mode) |
| 985 | freq /= 0xff; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 986 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 987 | ctl = freq << 16; |
| 988 | I915_WRITE(BLC_PWM_CTL, ctl); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 989 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 990 | ctl2 = BLM_PIPE(pipe); |
| 991 | if (panel->backlight.combination_mode) |
| 992 | ctl2 |= BLM_COMBINATION_MODE; |
| 993 | if (panel->backlight.active_low_pwm) |
| 994 | ctl2 |= BLM_POLARITY_I965; |
| 995 | I915_WRITE(BLC_PWM_CTL2, ctl2); |
| 996 | POSTING_READ(BLC_PWM_CTL2); |
| 997 | I915_WRITE(BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE); |
Jani Nikula | 2e7eeeb | 2014-06-09 18:24:34 +0300 | [diff] [blame] | 998 | |
| 999 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static void vlv_enable_backlight(struct intel_connector *connector) |
| 1003 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1004 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 1005 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1006 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1007 | u32 ctl, ctl2; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1008 | |
Ville Syrjälä | 23ec0a8 | 2014-11-07 11:15:59 +0200 | [diff] [blame] | 1009 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 1010 | return; |
| 1011 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1012 | ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 1013 | if (ctl2 & BLM_PWM_ENABLE) { |
Scot Doyle | 813008c | 2014-08-19 02:07:13 +0000 | [diff] [blame] | 1014 | DRM_DEBUG_KMS("backlight already enabled\n"); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1015 | ctl2 &= ~BLM_PWM_ENABLE; |
| 1016 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2); |
| 1017 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1018 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1019 | ctl = panel->backlight.max << 16; |
| 1020 | I915_WRITE(VLV_BLC_PWM_CTL(pipe), ctl); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1021 | |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1022 | /* XXX: combine this into above write? */ |
Jani Nikula | 3bd712e | 2013-11-08 16:48:59 +0200 | [diff] [blame] | 1023 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
Jani Nikula | b35684b | 2013-11-14 12:13:41 +0200 | [diff] [blame] | 1024 | |
| 1025 | ctl2 = 0; |
| 1026 | if (panel->backlight.active_low_pwm) |
| 1027 | ctl2 |= BLM_POLARITY_I965; |
| 1028 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2); |
| 1029 | POSTING_READ(VLV_BLC_PWM_CTL2(pipe)); |
| 1030 | I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1033 | static void bxt_enable_backlight(struct intel_connector *connector) |
| 1034 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1035 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1036 | struct intel_panel *panel = &connector->panel; |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1037 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
| 1038 | u32 pwm_ctl, val; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1039 | |
Vidya Srinivas | add0337 | 2016-12-08 11:26:18 +0200 | [diff] [blame] | 1040 | /* Controller 1 uses the utility pin. */ |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1041 | if (panel->backlight.controller == 1) { |
| 1042 | val = I915_READ(UTIL_PIN_CTL); |
| 1043 | if (val & UTIL_PIN_ENABLE) { |
| 1044 | DRM_DEBUG_KMS("util pin already enabled\n"); |
| 1045 | val &= ~UTIL_PIN_ENABLE; |
| 1046 | I915_WRITE(UTIL_PIN_CTL, val); |
| 1047 | } |
| 1048 | |
| 1049 | val = 0; |
| 1050 | if (panel->backlight.util_pin_active_low) |
| 1051 | val |= UTIL_PIN_POLARITY; |
| 1052 | I915_WRITE(UTIL_PIN_CTL, val | UTIL_PIN_PIPE(pipe) | |
| 1053 | UTIL_PIN_MODE_PWM | UTIL_PIN_ENABLE); |
| 1054 | } |
| 1055 | |
| 1056 | pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller)); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1057 | if (pwm_ctl & BXT_BLC_PWM_ENABLE) { |
| 1058 | DRM_DEBUG_KMS("backlight already enabled\n"); |
| 1059 | pwm_ctl &= ~BXT_BLC_PWM_ENABLE; |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1060 | I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), |
| 1061 | pwm_ctl); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1062 | } |
| 1063 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1064 | I915_WRITE(BXT_BLC_PWM_FREQ(panel->backlight.controller), |
| 1065 | panel->backlight.max); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1066 | |
| 1067 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
| 1068 | |
| 1069 | pwm_ctl = 0; |
| 1070 | if (panel->backlight.active_low_pwm) |
| 1071 | pwm_ctl |= BXT_BLC_PWM_POLARITY; |
| 1072 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1073 | I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), pwm_ctl); |
| 1074 | POSTING_READ(BXT_BLC_PWM_CTL(panel->backlight.controller)); |
| 1075 | I915_WRITE(BXT_BLC_PWM_CTL(panel->backlight.controller), |
| 1076 | pwm_ctl | BXT_BLC_PWM_ENABLE); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1077 | } |
| 1078 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1079 | static void pwm_enable_backlight(struct intel_connector *connector) |
| 1080 | { |
| 1081 | struct intel_panel *panel = &connector->panel; |
| 1082 | |
| 1083 | pwm_enable(panel->backlight.pwm); |
| 1084 | intel_panel_actually_set_backlight(connector, panel->backlight.level); |
| 1085 | } |
| 1086 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1087 | void intel_panel_enable_backlight(struct intel_connector *connector) |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 1088 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1089 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1090 | struct intel_panel *panel = &connector->panel; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1091 | enum pipe pipe = intel_get_pipe_from_connector(connector); |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 1092 | |
Ville Syrjälä | 260d8f9 | 2014-11-07 15:20:23 +0200 | [diff] [blame] | 1093 | if (!panel->backlight.present) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1094 | return; |
| 1095 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 1096 | DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe)); |
Chris Wilson | 540b5d0 | 2013-10-13 12:56:31 +0100 | [diff] [blame] | 1097 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 1098 | mutex_lock(&dev_priv->backlight_lock); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 1099 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 1100 | WARN_ON(panel->backlight.max == 0); |
| 1101 | |
Jeremiah Mahler | 13f3fbe | 2015-01-12 11:01:03 -0800 | [diff] [blame] | 1102 | if (panel->backlight.level <= panel->backlight.min) { |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 1103 | panel->backlight.level = panel->backlight.max; |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1104 | if (panel->backlight.device) |
| 1105 | panel->backlight.device->props.brightness = |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1106 | scale_hw_to_user(connector, |
| 1107 | panel->backlight.level, |
| 1108 | panel->backlight.device->props.max_brightness); |
Jani Nikula | b6b3ba5 | 2013-03-12 11:44:15 +0200 | [diff] [blame] | 1109 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 1110 | |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1111 | panel->backlight.enable(connector); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1112 | panel->backlight.enabled = true; |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 1113 | if (panel->backlight.device) |
| 1114 | panel->backlight.device->props.power = FB_BLANK_UNBLANK; |
Jani Nikula | 8ba2d18 | 2013-04-12 15:18:37 +0300 | [diff] [blame] | 1115 | |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 1116 | mutex_unlock(&dev_priv->backlight_lock); |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Jani Nikula | 912e8b1 | 2013-09-18 17:19:45 +0300 | [diff] [blame] | 1119 | #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1120 | static int intel_backlight_device_update_status(struct backlight_device *bd) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1121 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1122 | struct intel_connector *connector = bl_get_data(bd); |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 1123 | struct intel_panel *panel = &connector->panel; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1124 | struct drm_device *dev = connector->base.dev; |
| 1125 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 1126 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Chris Wilson | 540b5d0 | 2013-10-13 12:56:31 +0100 | [diff] [blame] | 1127 | DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n", |
| 1128 | bd->props.brightness, bd->props.max_brightness); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1129 | intel_panel_set_backlight(connector, bd->props.brightness, |
Jani Nikula | d654063 | 2013-04-12 15:18:36 +0300 | [diff] [blame] | 1130 | bd->props.max_brightness); |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * Allow flipping bl_power as a sub-state of enabled. Sadly the |
| 1134 | * backlight class device does not make it easy to to differentiate |
| 1135 | * between callbacks for brightness and bl_power, so our backlight_power |
| 1136 | * callback needs to take this into account. |
| 1137 | */ |
| 1138 | if (panel->backlight.enabled) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1139 | if (panel->backlight.power) { |
Jani Nikula | e6755fb | 2014-08-12 17:11:42 +0300 | [diff] [blame] | 1140 | bool enable = bd->props.power == FB_BLANK_UNBLANK && |
| 1141 | bd->props.brightness != 0; |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1142 | panel->backlight.power(connector, enable); |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 1143 | } |
| 1144 | } else { |
| 1145 | bd->props.power = FB_BLANK_POWERDOWN; |
| 1146 | } |
| 1147 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 1148 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1149 | return 0; |
| 1150 | } |
| 1151 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1152 | static int intel_backlight_device_get_brightness(struct backlight_device *bd) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1153 | { |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1154 | struct intel_connector *connector = bl_get_data(bd); |
| 1155 | struct drm_device *dev = connector->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1156 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1157 | u32 hw_level; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1158 | int ret; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1159 | |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 1160 | intel_runtime_pm_get(dev_priv); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 1161 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1162 | |
| 1163 | hw_level = intel_panel_get_backlight(connector); |
| 1164 | ret = scale_hw_to_user(connector, hw_level, bd->props.max_brightness); |
| 1165 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 1166 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Paulo Zanoni | c8c8fb3 | 2013-11-27 18:21:54 -0200 | [diff] [blame] | 1167 | intel_runtime_pm_put(dev_priv); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 1168 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1169 | return ret; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1170 | } |
| 1171 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1172 | static const struct backlight_ops intel_backlight_device_ops = { |
| 1173 | .update_status = intel_backlight_device_update_status, |
| 1174 | .get_brightness = intel_backlight_device_get_brightness, |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1175 | }; |
| 1176 | |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 1177 | int intel_backlight_device_register(struct intel_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1178 | { |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1179 | struct intel_panel *panel = &connector->panel; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1180 | struct backlight_properties props; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1181 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1182 | if (WARN_ON(panel->backlight.device)) |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 1183 | return -ENODEV; |
| 1184 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 1185 | if (!panel->backlight.present) |
| 1186 | return 0; |
| 1187 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1188 | WARN_ON(panel->backlight.max == 0); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1189 | |
Corentin Chary | af437cf | 2012-05-22 10:29:46 +0100 | [diff] [blame] | 1190 | memset(&props, 0, sizeof(props)); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1191 | props.type = BACKLIGHT_RAW; |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1192 | |
| 1193 | /* |
| 1194 | * Note: Everything should work even if the backlight device max |
| 1195 | * presented to the userspace is arbitrarily chosen. |
| 1196 | */ |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1197 | props.max_brightness = panel->backlight.max; |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1198 | props.brightness = scale_hw_to_user(connector, |
| 1199 | panel->backlight.level, |
| 1200 | props.max_brightness); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1201 | |
Jani Nikula | ab656bb | 2014-08-13 12:10:12 +0300 | [diff] [blame] | 1202 | if (panel->backlight.enabled) |
| 1203 | props.power = FB_BLANK_UNBLANK; |
| 1204 | else |
| 1205 | props.power = FB_BLANK_POWERDOWN; |
| 1206 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1207 | /* |
| 1208 | * Note: using the same name independent of the connector prevents |
| 1209 | * registration of multiple backlight devices in the driver. |
| 1210 | */ |
| 1211 | panel->backlight.device = |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1212 | backlight_device_register("intel_backlight", |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1213 | connector->base.kdev, |
| 1214 | connector, |
| 1215 | &intel_backlight_device_ops, &props); |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1216 | |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1217 | if (IS_ERR(panel->backlight.device)) { |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1218 | DRM_ERROR("Failed to register backlight: %ld\n", |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1219 | PTR_ERR(panel->backlight.device)); |
| 1220 | panel->backlight.device = NULL; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1221 | return -ENODEV; |
| 1222 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 1223 | |
| 1224 | DRM_DEBUG_KMS("Connector %s backlight sysfs interface registered\n", |
| 1225 | connector->base.name); |
| 1226 | |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1227 | return 0; |
| 1228 | } |
| 1229 | |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 1230 | void intel_backlight_device_unregister(struct intel_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1231 | { |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1232 | struct intel_panel *panel = &connector->panel; |
| 1233 | |
| 1234 | if (panel->backlight.device) { |
| 1235 | backlight_device_unregister(panel->backlight.device); |
| 1236 | panel->backlight.device = NULL; |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 1237 | } |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1238 | } |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1239 | #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ |
| 1240 | |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 1241 | /* |
Jani Nikula | 2dd6982 | 2015-12-01 10:23:50 +0200 | [diff] [blame] | 1242 | * BXT: PWM clock frequency = 19.2 MHz. |
| 1243 | */ |
| 1244 | static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1245 | { |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1246 | return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz); |
Jani Nikula | 2dd6982 | 2015-12-01 10:23:50 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /* |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1250 | * SPT: This value represents the period of the PWM stream in clock periods |
| 1251 | * multiplied by 16 (default increment) or 128 (alternate increment selected in |
| 1252 | * SCHICKEN_1 bit 0). PWM clock is 24 MHz. |
| 1253 | */ |
| 1254 | static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1255 | { |
Jani Nikula | 32b421e | 2016-09-19 13:35:25 +0300 | [diff] [blame] | 1256 | struct intel_panel *panel = &connector->panel; |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1257 | u32 mul; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1258 | |
Jani Nikula | 32b421e | 2016-09-19 13:35:25 +0300 | [diff] [blame] | 1259 | if (panel->backlight.alternate_pwm_increment) |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1260 | mul = 128; |
| 1261 | else |
| 1262 | mul = 16; |
| 1263 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1264 | return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /* |
| 1268 | * LPT: This value represents the period of the PWM stream in clock periods |
| 1269 | * multiplied by 128 (default increment) or 16 (alternate increment, selected in |
| 1270 | * LPT SOUTH_CHICKEN2 register bit 5). |
| 1271 | */ |
| 1272 | static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1273 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1274 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 32b421e | 2016-09-19 13:35:25 +0300 | [diff] [blame] | 1275 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1276 | u32 mul, clock; |
| 1277 | |
Jani Nikula | 32b421e | 2016-09-19 13:35:25 +0300 | [diff] [blame] | 1278 | if (panel->backlight.alternate_pwm_increment) |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1279 | mul = 16; |
| 1280 | else |
| 1281 | mul = 128; |
| 1282 | |
Ville Syrjälä | 56f5f70 | 2015-11-30 16:23:44 +0200 | [diff] [blame] | 1283 | if (HAS_PCH_LPT_H(dev_priv)) |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1284 | clock = MHz(135); /* LPT:H */ |
| 1285 | else |
| 1286 | clock = MHz(24); /* LPT:LP */ |
| 1287 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1288 | return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /* |
| 1292 | * ILK/SNB/IVB: This value represents the period of the PWM stream in PCH |
| 1293 | * display raw clocks multiplied by 128. |
| 1294 | */ |
| 1295 | static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1296 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1297 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1298 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1299 | return DIV_ROUND_CLOSEST(KHz(dev_priv->rawclk_freq), pwm_freq_hz * 128); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * Gen2: This field determines the number of time base events (display core |
| 1304 | * clock frequency/32) in total for a complete cycle of modulated backlight |
| 1305 | * control. |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 1306 | * |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1307 | * Gen3: A time base event equals the display core clock ([DevPNV] HRAW clock) |
| 1308 | * divided by 32. |
| 1309 | */ |
| 1310 | static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1311 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1312 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1313 | int clock; |
| 1314 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1315 | if (IS_PINEVIEW(dev_priv)) |
| 1316 | clock = KHz(dev_priv->rawclk_freq); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1317 | else |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1318 | clock = KHz(dev_priv->cdclk_freq); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1319 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1320 | return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /* |
| 1324 | * Gen4: This value represents the period of the PWM stream in display core |
Ville Syrjälä | 83d8339 | 2015-11-30 16:23:43 +0200 | [diff] [blame] | 1325 | * clocks ([DevCTG] HRAW clocks) multiplied by 128. |
| 1326 | * |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1327 | */ |
| 1328 | static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1329 | { |
Mika Kahola | 3bed7f4 | 2016-12-13 10:02:49 +0200 | [diff] [blame^] | 1330 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Ville Syrjälä | 83d8339 | 2015-11-30 16:23:43 +0200 | [diff] [blame] | 1331 | int clock; |
| 1332 | |
| 1333 | if (IS_G4X(dev_priv)) |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1334 | clock = KHz(dev_priv->rawclk_freq); |
Ville Syrjälä | 83d8339 | 2015-11-30 16:23:43 +0200 | [diff] [blame] | 1335 | else |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1336 | clock = KHz(dev_priv->cdclk_freq); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1337 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1338 | return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * VLV: This value represents the period of the PWM stream in display core |
| 1343 | * clocks ([DevCTG] 200MHz HRAW clocks) multiplied by 128 or 25MHz S0IX clocks |
| 1344 | * multiplied by 16. CHV uses a 19.2MHz S0IX clock. |
| 1345 | */ |
| 1346 | static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) |
| 1347 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1348 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
| 1349 | int mul, clock; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1350 | |
| 1351 | if ((I915_READ(CBR1_VLV) & CBR_PWM_CLOCK_MUX_SELECT) == 0) { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1352 | if (IS_CHERRYVIEW(dev_priv)) |
| 1353 | clock = KHz(19200); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1354 | else |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1355 | clock = MHz(25); |
| 1356 | mul = 16; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1357 | } else { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1358 | clock = KHz(dev_priv->rawclk_freq); |
| 1359 | mul = 128; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1360 | } |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 1361 | |
Ville Syrjälä | 37f2248 | 2016-03-02 17:22:18 +0200 | [diff] [blame] | 1362 | return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static u32 get_backlight_max_vbt(struct intel_connector *connector) |
| 1366 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1367 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1368 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1369 | u16 pwm_freq_hz = dev_priv->vbt.backlight.pwm_freq_hz; |
| 1370 | u32 pwm; |
| 1371 | |
Jani Nikula | 5075222 | 2015-12-01 10:23:51 +0200 | [diff] [blame] | 1372 | if (!panel->backlight.hz_to_pwm) { |
| 1373 | DRM_DEBUG_KMS("backlight frequency conversion not supported\n"); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1374 | return 0; |
| 1375 | } |
| 1376 | |
Jani Nikula | 5075222 | 2015-12-01 10:23:51 +0200 | [diff] [blame] | 1377 | if (pwm_freq_hz) { |
| 1378 | DRM_DEBUG_KMS("VBT defined backlight frequency %u Hz\n", |
| 1379 | pwm_freq_hz); |
| 1380 | } else { |
| 1381 | pwm_freq_hz = 200; |
| 1382 | DRM_DEBUG_KMS("default backlight frequency %u Hz\n", |
| 1383 | pwm_freq_hz); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1384 | } |
| 1385 | |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1386 | pwm = panel->backlight.hz_to_pwm(connector, pwm_freq_hz); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1387 | if (!pwm) { |
| 1388 | DRM_DEBUG_KMS("backlight frequency conversion failed\n"); |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1392 | return pwm; |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Note: The setup hooks can't assume pipe is set! |
Jani Nikula | f91c15e | 2013-11-08 16:49:00 +0200 | [diff] [blame] | 1397 | */ |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1398 | static u32 get_backlight_min_vbt(struct intel_connector *connector) |
| 1399 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1400 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1401 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | e1c412e | 2014-11-05 14:46:31 +0200 | [diff] [blame] | 1402 | int min; |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1403 | |
| 1404 | WARN_ON(panel->backlight.max == 0); |
| 1405 | |
Jani Nikula | e1c412e | 2014-11-05 14:46:31 +0200 | [diff] [blame] | 1406 | /* |
| 1407 | * XXX: If the vbt value is 255, it makes min equal to max, which leads |
| 1408 | * to problems. There are such machines out there. Either our |
| 1409 | * interpretation is wrong or the vbt has bogus data. Or both. Safeguard |
| 1410 | * against this by letting the minimum be at most (arbitrarily chosen) |
| 1411 | * 25% of the max. |
| 1412 | */ |
| 1413 | min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64); |
| 1414 | if (min != dev_priv->vbt.backlight.min_brightness) { |
| 1415 | DRM_DEBUG_KMS("clamping VBT min backlight %d/255 to %d/255\n", |
| 1416 | dev_priv->vbt.backlight.min_brightness, min); |
| 1417 | } |
| 1418 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1419 | /* vbt value is a coefficient in range [0..255] */ |
Jani Nikula | e1c412e | 2014-11-05 14:46:31 +0200 | [diff] [blame] | 1420 | return scale(min, 0, 255, 0, panel->backlight.max); |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1421 | } |
| 1422 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 1423 | static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused) |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1424 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1425 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1426 | struct intel_panel *panel = &connector->panel; |
| 1427 | u32 pch_ctl1, pch_ctl2, val; |
Jani Nikula | 32b421e | 2016-09-19 13:35:25 +0300 | [diff] [blame] | 1428 | bool alt; |
| 1429 | |
| 1430 | if (HAS_PCH_LPT(dev_priv)) |
| 1431 | alt = I915_READ(SOUTH_CHICKEN2) & LPT_PWM_GRANULARITY; |
| 1432 | else |
| 1433 | alt = I915_READ(SOUTH_CHICKEN1) & SPT_PWM_GRANULARITY; |
| 1434 | panel->backlight.alternate_pwm_increment = alt; |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1435 | |
| 1436 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 1437 | panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; |
| 1438 | |
| 1439 | pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2); |
| 1440 | panel->backlight.max = pch_ctl2 >> 16; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1441 | |
| 1442 | if (!panel->backlight.max) |
| 1443 | panel->backlight.max = get_backlight_max_vbt(connector); |
| 1444 | |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1445 | if (!panel->backlight.max) |
| 1446 | return -ENODEV; |
| 1447 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1448 | panel->backlight.min = get_backlight_min_vbt(connector); |
| 1449 | |
Jani Nikula | 437b15b | 2015-09-04 16:55:13 +0300 | [diff] [blame] | 1450 | val = lpt_get_backlight(connector); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1451 | val = intel_panel_compute_brightness(connector, val); |
| 1452 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1453 | panel->backlight.max); |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1454 | |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1455 | panel->backlight.enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE; |
Daniel Vetter | 96ab4c7 | 2013-11-14 15:17:41 +0100 | [diff] [blame] | 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1460 | static int pch_setup_backlight(struct intel_connector *connector, enum pipe unused) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1461 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1462 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1463 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1464 | u32 cpu_ctl2, pch_ctl1, pch_ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1465 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1466 | pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1); |
| 1467 | panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; |
| 1468 | |
| 1469 | pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2); |
| 1470 | panel->backlight.max = pch_ctl2 >> 16; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1471 | |
| 1472 | if (!panel->backlight.max) |
| 1473 | panel->backlight.max = get_backlight_max_vbt(connector); |
| 1474 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1475 | if (!panel->backlight.max) |
| 1476 | return -ENODEV; |
| 1477 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1478 | panel->backlight.min = get_backlight_min_vbt(connector); |
| 1479 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1480 | val = pch_get_backlight(connector); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1481 | val = intel_panel_compute_brightness(connector, val); |
| 1482 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1483 | panel->backlight.max); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1484 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1485 | cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2); |
| 1486 | panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) && |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1487 | (pch_ctl1 & BLM_PCH_PWM_ENABLE); |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1488 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1489 | return 0; |
| 1490 | } |
| 1491 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1492 | static int i9xx_setup_backlight(struct intel_connector *connector, enum pipe unused) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1493 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1494 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1495 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1496 | u32 ctl, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1497 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1498 | ctl = I915_READ(BLC_PWM_CTL); |
| 1499 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1500 | if (IS_GEN2(dev_priv) || IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1501 | panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; |
| 1502 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1503 | if (IS_PINEVIEW(dev_priv)) |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1504 | panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV; |
| 1505 | |
| 1506 | panel->backlight.max = ctl >> 17; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1507 | |
| 1508 | if (!panel->backlight.max) { |
| 1509 | panel->backlight.max = get_backlight_max_vbt(connector); |
| 1510 | panel->backlight.max >>= 1; |
| 1511 | } |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1512 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1513 | if (!panel->backlight.max) |
| 1514 | return -ENODEV; |
| 1515 | |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1516 | if (panel->backlight.combination_mode) |
| 1517 | panel->backlight.max *= 0xff; |
| 1518 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1519 | panel->backlight.min = get_backlight_min_vbt(connector); |
| 1520 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1521 | val = i9xx_get_backlight(connector); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1522 | val = intel_panel_compute_brightness(connector, val); |
| 1523 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1524 | panel->backlight.max); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1525 | |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1526 | panel->backlight.enabled = val != 0; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1527 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1528 | return 0; |
| 1529 | } |
| 1530 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1531 | static int i965_setup_backlight(struct intel_connector *connector, enum pipe unused) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1532 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1533 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1534 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1535 | u32 ctl, ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1536 | |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1537 | ctl2 = I915_READ(BLC_PWM_CTL2); |
| 1538 | panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE; |
| 1539 | panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; |
| 1540 | |
| 1541 | ctl = I915_READ(BLC_PWM_CTL); |
| 1542 | panel->backlight.max = ctl >> 16; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1543 | |
| 1544 | if (!panel->backlight.max) |
| 1545 | panel->backlight.max = get_backlight_max_vbt(connector); |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1546 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1547 | if (!panel->backlight.max) |
| 1548 | return -ENODEV; |
| 1549 | |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1550 | if (panel->backlight.combination_mode) |
| 1551 | panel->backlight.max *= 0xff; |
| 1552 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1553 | panel->backlight.min = get_backlight_min_vbt(connector); |
| 1554 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1555 | val = i9xx_get_backlight(connector); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1556 | val = intel_panel_compute_brightness(connector, val); |
| 1557 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1558 | panel->backlight.max); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1559 | |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1560 | panel->backlight.enabled = ctl2 & BLM_PWM_ENABLE; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1561 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1562 | return 0; |
| 1563 | } |
| 1564 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1565 | static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1566 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1567 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1568 | struct intel_panel *panel = &connector->panel; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1569 | u32 ctl, ctl2, val; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1570 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1571 | if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B)) |
| 1572 | return -ENODEV; |
| 1573 | |
| 1574 | ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe)); |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1575 | panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; |
| 1576 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1577 | ctl = I915_READ(VLV_BLC_PWM_CTL(pipe)); |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1578 | panel->backlight.max = ctl >> 16; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1579 | |
| 1580 | if (!panel->backlight.max) |
| 1581 | panel->backlight.max = get_backlight_max_vbt(connector); |
| 1582 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1583 | if (!panel->backlight.max) |
| 1584 | return -ENODEV; |
| 1585 | |
Jani Nikula | 6dda730 | 2014-06-24 18:27:40 +0300 | [diff] [blame] | 1586 | panel->backlight.min = get_backlight_min_vbt(connector); |
| 1587 | |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1588 | val = _vlv_get_backlight(dev_priv, pipe); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1589 | val = intel_panel_compute_brightness(connector, val); |
| 1590 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1591 | panel->backlight.max); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1592 | |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1593 | panel->backlight.enabled = ctl2 & BLM_PWM_ENABLE; |
Jani Nikula | 636baeb | 2013-11-08 16:49:02 +0200 | [diff] [blame] | 1594 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1595 | return 0; |
| 1596 | } |
| 1597 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1598 | static int |
| 1599 | bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) |
| 1600 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1601 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1602 | struct intel_panel *panel = &connector->panel; |
| 1603 | u32 pwm_ctl, val; |
| 1604 | |
Vidya Srinivas | add0337 | 2016-12-08 11:26:18 +0200 | [diff] [blame] | 1605 | panel->backlight.controller = dev_priv->vbt.backlight.controller; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1606 | |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1607 | pwm_ctl = I915_READ(BXT_BLC_PWM_CTL(panel->backlight.controller)); |
| 1608 | |
Vidya Srinivas | add0337 | 2016-12-08 11:26:18 +0200 | [diff] [blame] | 1609 | /* Controller 1 uses the utility pin. */ |
Sunil Kamath | 022e4e5 | 2015-09-30 22:34:57 +0530 | [diff] [blame] | 1610 | if (panel->backlight.controller == 1) { |
| 1611 | val = I915_READ(UTIL_PIN_CTL); |
| 1612 | panel->backlight.util_pin_active_low = |
| 1613 | val & UTIL_PIN_POLARITY; |
| 1614 | } |
| 1615 | |
| 1616 | panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; |
| 1617 | panel->backlight.max = |
| 1618 | I915_READ(BXT_BLC_PWM_FREQ(panel->backlight.controller)); |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1619 | |
| 1620 | if (!panel->backlight.max) |
| 1621 | panel->backlight.max = get_backlight_max_vbt(connector); |
| 1622 | |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1623 | if (!panel->backlight.max) |
| 1624 | return -ENODEV; |
| 1625 | |
| 1626 | val = bxt_get_backlight(connector); |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1627 | val = intel_panel_compute_brightness(connector, val); |
| 1628 | panel->backlight.level = clamp(val, panel->backlight.min, |
| 1629 | panel->backlight.max); |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1630 | |
Jani Nikula | 46e69f3 | 2016-08-23 10:10:05 +0200 | [diff] [blame] | 1631 | panel->backlight.enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; |
Vandana Kannan | 0fb890c | 2015-05-05 14:51:56 +0530 | [diff] [blame] | 1632 | |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1636 | static int pwm_setup_backlight(struct intel_connector *connector, |
| 1637 | enum pipe pipe) |
| 1638 | { |
| 1639 | struct drm_device *dev = connector->base.dev; |
| 1640 | struct intel_panel *panel = &connector->panel; |
| 1641 | int retval; |
| 1642 | |
| 1643 | /* Get the PWM chip for backlight control */ |
| 1644 | panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight"); |
| 1645 | if (IS_ERR(panel->backlight.pwm)) { |
| 1646 | DRM_ERROR("Failed to own the pwm chip\n"); |
| 1647 | panel->backlight.pwm = NULL; |
| 1648 | return -ENODEV; |
| 1649 | } |
| 1650 | |
Boris Brezillon | 2347aa7 | 2016-04-14 21:17:35 +0200 | [diff] [blame] | 1651 | /* |
| 1652 | * FIXME: pwm_apply_args() should be removed when switching to |
| 1653 | * the atomic PWM API. |
| 1654 | */ |
| 1655 | pwm_apply_args(panel->backlight.pwm); |
| 1656 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1657 | retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS, |
| 1658 | CRC_PMIC_PWM_PERIOD_NS); |
| 1659 | if (retval < 0) { |
| 1660 | DRM_ERROR("Failed to configure the pwm chip\n"); |
| 1661 | pwm_put(panel->backlight.pwm); |
| 1662 | panel->backlight.pwm = NULL; |
| 1663 | return retval; |
| 1664 | } |
| 1665 | |
| 1666 | panel->backlight.min = 0; /* 0% */ |
| 1667 | panel->backlight.max = 100; /* 100% */ |
| 1668 | panel->backlight.level = DIV_ROUND_UP( |
| 1669 | pwm_get_duty_cycle(panel->backlight.pwm) * 100, |
| 1670 | CRC_PMIC_PWM_PERIOD_NS); |
| 1671 | panel->backlight.enabled = panel->backlight.level != 0; |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
Ville Syrjälä | 6517d27 | 2014-11-07 11:16:02 +0200 | [diff] [blame] | 1676 | int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1677 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1678 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1679 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Jani Nikula | 58c6877 | 2013-11-08 16:48:54 +0200 | [diff] [blame] | 1680 | struct intel_panel *panel = &intel_connector->panel; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1681 | int ret; |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1682 | |
Jani Nikula | c675949 | 2014-04-09 11:31:37 +0300 | [diff] [blame] | 1683 | if (!dev_priv->vbt.backlight.present) { |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 1684 | if (dev_priv->quirks & QUIRK_BACKLIGHT_PRESENT) { |
| 1685 | DRM_DEBUG_KMS("no backlight present per VBT, but present per quirk\n"); |
| 1686 | } else { |
| 1687 | DRM_DEBUG_KMS("no backlight present per VBT\n"); |
| 1688 | return 0; |
| 1689 | } |
Jani Nikula | c675949 | 2014-04-09 11:31:37 +0300 | [diff] [blame] | 1690 | } |
| 1691 | |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1692 | /* ensure intel_panel has been initialized first */ |
| 1693 | if (WARN_ON(!panel->backlight.setup)) |
| 1694 | return -ENODEV; |
| 1695 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1696 | /* set level and max in panel struct */ |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 1697 | mutex_lock(&dev_priv->backlight_lock); |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1698 | ret = panel->backlight.setup(intel_connector, pipe); |
Daniel Vetter | 07f11d4 | 2014-09-15 14:35:09 +0200 | [diff] [blame] | 1699 | mutex_unlock(&dev_priv->backlight_lock); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1700 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1701 | if (ret) { |
| 1702 | DRM_DEBUG_KMS("failed to setup backlight for connector %s\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 1703 | connector->name); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1704 | return ret; |
| 1705 | } |
| 1706 | |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1707 | panel->backlight.present = true; |
| 1708 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 1709 | DRM_DEBUG_KMS("Connector %s backlight initialized, %s, brightness %u/%u\n", |
| 1710 | connector->name, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 1711 | enableddisabled(panel->backlight.enabled), |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 1712 | panel->backlight.level, panel->backlight.max); |
Jani Nikula | c445b3b | 2013-11-08 16:49:01 +0200 | [diff] [blame] | 1713 | |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1714 | return 0; |
| 1715 | } |
| 1716 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1717 | void intel_panel_destroy_backlight(struct drm_connector *connector) |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1718 | { |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1719 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1720 | struct intel_panel *panel = &intel_connector->panel; |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 1721 | |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1722 | /* dispose of the pwm */ |
| 1723 | if (panel->backlight.pwm) |
| 1724 | pwm_put(panel->backlight.pwm); |
| 1725 | |
Jani Nikula | c91c9f3 | 2013-11-08 16:48:55 +0200 | [diff] [blame] | 1726 | panel->backlight.present = false; |
Matthew Garrett | aaa6fd2 | 2011-08-12 12:11:33 +0200 | [diff] [blame] | 1727 | } |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1728 | |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1729 | /* Set up chip specific backlight functions */ |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1730 | static void |
| 1731 | intel_panel_init_backlight_funcs(struct intel_panel *panel) |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1732 | { |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1733 | struct intel_connector *connector = |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1734 | container_of(panel, struct intel_connector, panel); |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1735 | struct drm_i915_private *dev_priv = to_i915(connector->base.dev); |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1736 | |
Yetunde Adebisi | e7156c8 | 2016-04-05 15:10:52 +0100 | [diff] [blame] | 1737 | if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP && |
| 1738 | intel_dp_aux_init_backlight_funcs(connector) == 0) |
| 1739 | return; |
| 1740 | |
Jani Nikula | 9019835 | 2016-04-26 16:14:25 +0300 | [diff] [blame] | 1741 | if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI && |
| 1742 | intel_dsi_dcs_init_backlight_funcs(connector) == 0) |
| 1743 | return; |
| 1744 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 1745 | if (IS_GEN9_LP(dev_priv)) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1746 | panel->backlight.setup = bxt_setup_backlight; |
| 1747 | panel->backlight.enable = bxt_enable_backlight; |
| 1748 | panel->backlight.disable = bxt_disable_backlight; |
| 1749 | panel->backlight.set = bxt_set_backlight; |
| 1750 | panel->backlight.get = bxt_get_backlight; |
Jani Nikula | 2dd6982 | 2015-12-01 10:23:50 +0200 | [diff] [blame] | 1751 | panel->backlight.hz_to_pwm = bxt_hz_to_pwm; |
Rodrigo Vivi | 22dea0b | 2016-07-01 17:07:12 -0700 | [diff] [blame] | 1752 | } else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_SPT(dev_priv) || |
| 1753 | HAS_PCH_KBP(dev_priv)) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1754 | panel->backlight.setup = lpt_setup_backlight; |
| 1755 | panel->backlight.enable = lpt_enable_backlight; |
| 1756 | panel->backlight.disable = lpt_disable_backlight; |
| 1757 | panel->backlight.set = lpt_set_backlight; |
| 1758 | panel->backlight.get = lpt_get_backlight; |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1759 | if (HAS_PCH_LPT(dev_priv)) |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1760 | panel->backlight.hz_to_pwm = lpt_hz_to_pwm; |
Jani Nikula | aa17cdb | 2015-09-04 16:55:14 +0300 | [diff] [blame] | 1761 | else |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1762 | panel->backlight.hz_to_pwm = spt_hz_to_pwm; |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1763 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1764 | panel->backlight.setup = pch_setup_backlight; |
| 1765 | panel->backlight.enable = pch_enable_backlight; |
| 1766 | panel->backlight.disable = pch_disable_backlight; |
| 1767 | panel->backlight.set = pch_set_backlight; |
| 1768 | panel->backlight.get = pch_get_backlight; |
| 1769 | panel->backlight.hz_to_pwm = pch_hz_to_pwm; |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1770 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 92c4565 | 2016-03-16 12:43:33 +0200 | [diff] [blame] | 1771 | if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1772 | panel->backlight.setup = pwm_setup_backlight; |
| 1773 | panel->backlight.enable = pwm_enable_backlight; |
| 1774 | panel->backlight.disable = pwm_disable_backlight; |
| 1775 | panel->backlight.set = pwm_set_backlight; |
| 1776 | panel->backlight.get = pwm_get_backlight; |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1777 | } else { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1778 | panel->backlight.setup = vlv_setup_backlight; |
| 1779 | panel->backlight.enable = vlv_enable_backlight; |
| 1780 | panel->backlight.disable = vlv_disable_backlight; |
| 1781 | panel->backlight.set = vlv_set_backlight; |
| 1782 | panel->backlight.get = vlv_get_backlight; |
| 1783 | panel->backlight.hz_to_pwm = vlv_hz_to_pwm; |
Shobhit Kumar | b029e66 | 2015-06-26 14:32:10 +0530 | [diff] [blame] | 1784 | } |
Jani Nikula | e6cb372 | 2015-12-18 10:51:35 +0200 | [diff] [blame] | 1785 | } else if (IS_GEN4(dev_priv)) { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1786 | panel->backlight.setup = i965_setup_backlight; |
| 1787 | panel->backlight.enable = i965_enable_backlight; |
| 1788 | panel->backlight.disable = i965_disable_backlight; |
| 1789 | panel->backlight.set = i9xx_set_backlight; |
| 1790 | panel->backlight.get = i9xx_get_backlight; |
| 1791 | panel->backlight.hz_to_pwm = i965_hz_to_pwm; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1792 | } else { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1793 | panel->backlight.setup = i9xx_setup_backlight; |
| 1794 | panel->backlight.enable = i9xx_enable_backlight; |
| 1795 | panel->backlight.disable = i9xx_disable_backlight; |
| 1796 | panel->backlight.set = i9xx_set_backlight; |
| 1797 | panel->backlight.get = i9xx_get_backlight; |
| 1798 | panel->backlight.hz_to_pwm = i9xx_hz_to_pwm; |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1802 | int intel_panel_init(struct intel_panel *panel, |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1803 | struct drm_display_mode *fixed_mode, |
| 1804 | struct drm_display_mode *downclock_mode) |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1805 | { |
Jani Nikula | 5507fae | 2015-09-14 14:03:48 +0300 | [diff] [blame] | 1806 | intel_panel_init_backlight_funcs(panel); |
| 1807 | |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1808 | panel->fixed_mode = fixed_mode; |
Vandana Kannan | 4b6ed68 | 2014-02-11 14:26:36 +0530 | [diff] [blame] | 1809 | panel->downclock_mode = downclock_mode; |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1810 | |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1811 | return 0; |
| 1812 | } |
| 1813 | |
| 1814 | void intel_panel_fini(struct intel_panel *panel) |
| 1815 | { |
Jani Nikula | dd06f90 | 2012-10-19 14:51:50 +0300 | [diff] [blame] | 1816 | struct intel_connector *intel_connector = |
| 1817 | container_of(panel, struct intel_connector, panel); |
| 1818 | |
| 1819 | if (panel->fixed_mode) |
| 1820 | drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode); |
Vandana Kannan | ec9ed19 | 2013-12-10 13:37:36 +0530 | [diff] [blame] | 1821 | |
| 1822 | if (panel->downclock_mode) |
| 1823 | drm_mode_destroy(intel_connector->base.dev, |
| 1824 | panel->downclock_mode); |
Jani Nikula | 1d50870 | 2012-10-19 14:51:49 +0300 | [diff] [blame] | 1825 | } |