Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915/backlight: extract backlight code to a separate file

In a long overdue refactoring, split out backlight code to new
intel_backlight.[ch]. Simple code movement, leave renames for follow-up
work. No functional changes.

Cc: Lyude Paul <lyude@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/97d310848f03061473b9b2328e2c5c4dcf263cfa.1629888677.git.jani.nikula@intel.com

+1843 -1805
+1
drivers/gpu/drm/i915/Makefile
··· 249 249 display/g4x_dp.o \ 250 250 display/g4x_hdmi.o \ 251 251 display/icl_dsi.o \ 252 + display/intel_backlight.o \ 252 253 display/intel_crt.o \ 253 254 display/intel_ddi.o \ 254 255 display/intel_ddi_buf_trans.o \
+1 -1
drivers/gpu/drm/i915/display/g4x_dp.c
··· 7 7 8 8 #include "g4x_dp.h" 9 9 #include "intel_audio.h" 10 + #include "intel_backlight.h" 10 11 #include "intel_connector.h" 11 12 #include "intel_de.h" 12 13 #include "intel_display_types.h" ··· 17 16 #include "intel_fifo_underrun.h" 18 17 #include "intel_hdmi.h" 19 18 #include "intel_hotplug.h" 20 - #include "intel_panel.h" 21 19 #include "intel_pps.h" 22 20 #include "intel_sideband.h" 23 21
+1
drivers/gpu/drm/i915/display/icl_dsi.c
··· 29 29 #include <drm/drm_mipi_dsi.h> 30 30 31 31 #include "intel_atomic.h" 32 + #include "intel_backlight.h" 32 33 #include "intel_combo_phy.h" 33 34 #include "intel_connector.h" 34 35 #include "intel_crtc.h"
+1778
drivers/gpu/drm/i915/display/intel_backlight.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2021 Intel Corporation 4 + */ 5 + 6 + #include <linux/kernel.h> 7 + #include <linux/pwm.h> 8 + 9 + #include "intel_backlight.h" 10 + #include "intel_connector.h" 11 + #include "intel_de.h" 12 + #include "intel_display_types.h" 13 + #include "intel_dp_aux_backlight.h" 14 + #include "intel_dsi_dcs_backlight.h" 15 + #include "intel_panel.h" 16 + 17 + /** 18 + * scale - scale values from one range to another 19 + * @source_val: value in range [@source_min..@source_max] 20 + * @source_min: minimum legal value for @source_val 21 + * @source_max: maximum legal value for @source_val 22 + * @target_min: corresponding target value for @source_min 23 + * @target_max: corresponding target value for @source_max 24 + * 25 + * Return @source_val in range [@source_min..@source_max] scaled to range 26 + * [@target_min..@target_max]. 27 + */ 28 + static u32 scale(u32 source_val, 29 + u32 source_min, u32 source_max, 30 + u32 target_min, u32 target_max) 31 + { 32 + u64 target_val; 33 + 34 + WARN_ON(source_min > source_max); 35 + WARN_ON(target_min > target_max); 36 + 37 + /* defensive */ 38 + source_val = clamp(source_val, source_min, source_max); 39 + 40 + /* avoid overflows */ 41 + target_val = mul_u32_u32(source_val - source_min, 42 + target_max - target_min); 43 + target_val = DIV_ROUND_CLOSEST_ULL(target_val, source_max - source_min); 44 + target_val += target_min; 45 + 46 + return target_val; 47 + } 48 + 49 + /* 50 + * Scale user_level in range [0..user_max] to [0..hw_max], clamping the result 51 + * to [hw_min..hw_max]. 52 + */ 53 + static u32 clamp_user_to_hw(struct intel_connector *connector, 54 + u32 user_level, u32 user_max) 55 + { 56 + struct intel_panel *panel = &connector->panel; 57 + u32 hw_level; 58 + 59 + hw_level = scale(user_level, 0, user_max, 0, panel->backlight.max); 60 + hw_level = clamp(hw_level, panel->backlight.min, panel->backlight.max); 61 + 62 + return hw_level; 63 + } 64 + 65 + /* Scale hw_level in range [hw_min..hw_max] to [0..user_max]. */ 66 + static u32 scale_hw_to_user(struct intel_connector *connector, 67 + u32 hw_level, u32 user_max) 68 + { 69 + struct intel_panel *panel = &connector->panel; 70 + 71 + return scale(hw_level, panel->backlight.min, panel->backlight.max, 72 + 0, user_max); 73 + } 74 + 75 + u32 intel_panel_invert_pwm_level(struct intel_connector *connector, u32 val) 76 + { 77 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 78 + struct intel_panel *panel = &connector->panel; 79 + 80 + drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 81 + 82 + if (dev_priv->params.invert_brightness < 0) 83 + return val; 84 + 85 + if (dev_priv->params.invert_brightness > 0 || 86 + dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) { 87 + return panel->backlight.pwm_level_max - val + panel->backlight.pwm_level_min; 88 + } 89 + 90 + return val; 91 + } 92 + 93 + void intel_panel_set_pwm_level(const struct drm_connector_state *conn_state, u32 val) 94 + { 95 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 96 + struct drm_i915_private *i915 = to_i915(connector->base.dev); 97 + struct intel_panel *panel = &connector->panel; 98 + 99 + drm_dbg_kms(&i915->drm, "set backlight PWM = %d\n", val); 100 + panel->backlight.pwm_funcs->set(conn_state, val); 101 + } 102 + 103 + u32 intel_panel_backlight_level_to_pwm(struct intel_connector *connector, u32 val) 104 + { 105 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 106 + struct intel_panel *panel = &connector->panel; 107 + 108 + drm_WARN_ON_ONCE(&dev_priv->drm, 109 + panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); 110 + 111 + val = scale(val, panel->backlight.min, panel->backlight.max, 112 + panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); 113 + 114 + return intel_panel_invert_pwm_level(connector, val); 115 + } 116 + 117 + u32 intel_panel_backlight_level_from_pwm(struct intel_connector *connector, u32 val) 118 + { 119 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 120 + struct intel_panel *panel = &connector->panel; 121 + 122 + drm_WARN_ON_ONCE(&dev_priv->drm, 123 + panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); 124 + 125 + if (dev_priv->params.invert_brightness > 0 || 126 + (dev_priv->params.invert_brightness == 0 && dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS)) 127 + val = panel->backlight.pwm_level_max - (val - panel->backlight.pwm_level_min); 128 + 129 + return scale(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max, 130 + panel->backlight.min, panel->backlight.max); 131 + } 132 + 133 + static u32 lpt_get_backlight(struct intel_connector *connector, enum pipe unused) 134 + { 135 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 136 + 137 + return intel_de_read(dev_priv, BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK; 138 + } 139 + 140 + static u32 pch_get_backlight(struct intel_connector *connector, enum pipe unused) 141 + { 142 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 143 + 144 + return intel_de_read(dev_priv, BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; 145 + } 146 + 147 + static u32 i9xx_get_backlight(struct intel_connector *connector, enum pipe unused) 148 + { 149 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 150 + struct intel_panel *panel = &connector->panel; 151 + u32 val; 152 + 153 + val = intel_de_read(dev_priv, BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; 154 + if (DISPLAY_VER(dev_priv) < 4) 155 + val >>= 1; 156 + 157 + if (panel->backlight.combination_mode) { 158 + u8 lbpc; 159 + 160 + pci_read_config_byte(to_pci_dev(dev_priv->drm.dev), LBPC, &lbpc); 161 + val *= lbpc; 162 + } 163 + 164 + return val; 165 + } 166 + 167 + static u32 vlv_get_backlight(struct intel_connector *connector, enum pipe pipe) 168 + { 169 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 170 + 171 + if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B)) 172 + return 0; 173 + 174 + return intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK; 175 + } 176 + 177 + static u32 bxt_get_backlight(struct intel_connector *connector, enum pipe unused) 178 + { 179 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 180 + struct intel_panel *panel = &connector->panel; 181 + 182 + return intel_de_read(dev_priv, 183 + BXT_BLC_PWM_DUTY(panel->backlight.controller)); 184 + } 185 + 186 + static u32 ext_pwm_get_backlight(struct intel_connector *connector, enum pipe unused) 187 + { 188 + struct intel_panel *panel = &connector->panel; 189 + struct pwm_state state; 190 + 191 + pwm_get_state(panel->backlight.pwm, &state); 192 + return pwm_get_relative_duty_cycle(&state, 100); 193 + } 194 + 195 + static void lpt_set_backlight(const struct drm_connector_state *conn_state, u32 level) 196 + { 197 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 198 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 199 + 200 + u32 val = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK; 201 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, val | level); 202 + } 203 + 204 + static void pch_set_backlight(const struct drm_connector_state *conn_state, u32 level) 205 + { 206 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 207 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 208 + u32 tmp; 209 + 210 + tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; 211 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL, tmp | level); 212 + } 213 + 214 + static void i9xx_set_backlight(const struct drm_connector_state *conn_state, u32 level) 215 + { 216 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 217 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 218 + struct intel_panel *panel = &connector->panel; 219 + u32 tmp, mask; 220 + 221 + drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 222 + 223 + if (panel->backlight.combination_mode) { 224 + u8 lbpc; 225 + 226 + lbpc = level * 0xfe / panel->backlight.pwm_level_max + 1; 227 + level /= lbpc; 228 + pci_write_config_byte(to_pci_dev(dev_priv->drm.dev), LBPC, lbpc); 229 + } 230 + 231 + if (DISPLAY_VER(dev_priv) == 4) { 232 + mask = BACKLIGHT_DUTY_CYCLE_MASK; 233 + } else { 234 + level <<= 1; 235 + mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV; 236 + } 237 + 238 + tmp = intel_de_read(dev_priv, BLC_PWM_CTL) & ~mask; 239 + intel_de_write(dev_priv, BLC_PWM_CTL, tmp | level); 240 + } 241 + 242 + static void vlv_set_backlight(const struct drm_connector_state *conn_state, u32 level) 243 + { 244 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 245 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 246 + enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; 247 + u32 tmp; 248 + 249 + tmp = intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK; 250 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL(pipe), tmp | level); 251 + } 252 + 253 + static void bxt_set_backlight(const struct drm_connector_state *conn_state, u32 level) 254 + { 255 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 256 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 257 + struct intel_panel *panel = &connector->panel; 258 + 259 + intel_de_write(dev_priv, 260 + BXT_BLC_PWM_DUTY(panel->backlight.controller), level); 261 + } 262 + 263 + static void ext_pwm_set_backlight(const struct drm_connector_state *conn_state, u32 level) 264 + { 265 + struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel; 266 + 267 + pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); 268 + pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 269 + } 270 + 271 + static void 272 + intel_panel_actually_set_backlight(const struct drm_connector_state *conn_state, u32 level) 273 + { 274 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 275 + struct drm_i915_private *i915 = to_i915(connector->base.dev); 276 + struct intel_panel *panel = &connector->panel; 277 + 278 + drm_dbg_kms(&i915->drm, "set backlight level = %d\n", level); 279 + 280 + panel->backlight.funcs->set(conn_state, level); 281 + } 282 + 283 + /* set backlight brightness to level in range [0..max], assuming hw min is 284 + * respected. 285 + */ 286 + void intel_panel_set_backlight_acpi(const struct drm_connector_state *conn_state, 287 + u32 user_level, u32 user_max) 288 + { 289 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 290 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 291 + struct intel_panel *panel = &connector->panel; 292 + u32 hw_level; 293 + 294 + /* 295 + * Lack of crtc may occur during driver init because 296 + * connection_mutex isn't held across the entire backlight 297 + * setup + modeset readout, and the BIOS can issue the 298 + * requests at any time. 299 + */ 300 + if (!panel->backlight.present || !conn_state->crtc) 301 + return; 302 + 303 + mutex_lock(&dev_priv->backlight_lock); 304 + 305 + drm_WARN_ON(&dev_priv->drm, panel->backlight.max == 0); 306 + 307 + hw_level = clamp_user_to_hw(connector, user_level, user_max); 308 + panel->backlight.level = hw_level; 309 + 310 + if (panel->backlight.device) 311 + panel->backlight.device->props.brightness = 312 + scale_hw_to_user(connector, 313 + panel->backlight.level, 314 + panel->backlight.device->props.max_brightness); 315 + 316 + if (panel->backlight.enabled) 317 + intel_panel_actually_set_backlight(conn_state, hw_level); 318 + 319 + mutex_unlock(&dev_priv->backlight_lock); 320 + } 321 + 322 + static void lpt_disable_backlight(const struct drm_connector_state *old_conn_state, u32 level) 323 + { 324 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 325 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 326 + u32 tmp; 327 + 328 + intel_panel_set_pwm_level(old_conn_state, level); 329 + 330 + /* 331 + * Although we don't support or enable CPU PWM with LPT/SPT based 332 + * systems, it may have been enabled prior to loading the 333 + * driver. Disable to avoid warnings on LCPLL disable. 334 + * 335 + * This needs rework if we need to add support for CPU PWM on PCH split 336 + * platforms. 337 + */ 338 + tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 339 + if (tmp & BLM_PWM_ENABLE) { 340 + drm_dbg_kms(&dev_priv->drm, 341 + "cpu backlight was enabled, disabling\n"); 342 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, 343 + tmp & ~BLM_PWM_ENABLE); 344 + } 345 + 346 + tmp = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 347 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); 348 + } 349 + 350 + static void pch_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 351 + { 352 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 353 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 354 + u32 tmp; 355 + 356 + intel_panel_set_pwm_level(old_conn_state, val); 357 + 358 + tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 359 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE); 360 + 361 + tmp = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 362 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); 363 + } 364 + 365 + static void i9xx_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 366 + { 367 + intel_panel_set_pwm_level(old_conn_state, val); 368 + } 369 + 370 + static void i965_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 371 + { 372 + struct drm_i915_private *dev_priv = to_i915(old_conn_state->connector->dev); 373 + u32 tmp; 374 + 375 + intel_panel_set_pwm_level(old_conn_state, val); 376 + 377 + tmp = intel_de_read(dev_priv, BLC_PWM_CTL2); 378 + intel_de_write(dev_priv, BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE); 379 + } 380 + 381 + static void vlv_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 382 + { 383 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 384 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 385 + enum pipe pipe = to_intel_crtc(old_conn_state->crtc)->pipe; 386 + u32 tmp; 387 + 388 + intel_panel_set_pwm_level(old_conn_state, val); 389 + 390 + tmp = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 391 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), 392 + tmp & ~BLM_PWM_ENABLE); 393 + } 394 + 395 + static void bxt_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 396 + { 397 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 398 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 399 + struct intel_panel *panel = &connector->panel; 400 + u32 tmp; 401 + 402 + intel_panel_set_pwm_level(old_conn_state, val); 403 + 404 + tmp = intel_de_read(dev_priv, 405 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 406 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 407 + tmp & ~BXT_BLC_PWM_ENABLE); 408 + 409 + if (panel->backlight.controller == 1) { 410 + val = intel_de_read(dev_priv, UTIL_PIN_CTL); 411 + val &= ~UTIL_PIN_ENABLE; 412 + intel_de_write(dev_priv, UTIL_PIN_CTL, val); 413 + } 414 + } 415 + 416 + static void cnp_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 417 + { 418 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 419 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 420 + struct intel_panel *panel = &connector->panel; 421 + u32 tmp; 422 + 423 + intel_panel_set_pwm_level(old_conn_state, val); 424 + 425 + tmp = intel_de_read(dev_priv, 426 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 427 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 428 + tmp & ~BXT_BLC_PWM_ENABLE); 429 + } 430 + 431 + static void ext_pwm_disable_backlight(const struct drm_connector_state *old_conn_state, u32 level) 432 + { 433 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 434 + struct intel_panel *panel = &connector->panel; 435 + 436 + panel->backlight.pwm_state.enabled = false; 437 + pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 438 + } 439 + 440 + void intel_panel_disable_backlight(const struct drm_connector_state *old_conn_state) 441 + { 442 + struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 443 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 444 + struct intel_panel *panel = &connector->panel; 445 + 446 + if (!panel->backlight.present) 447 + return; 448 + 449 + /* 450 + * Do not disable backlight on the vga_switcheroo path. When switching 451 + * away from i915, the other client may depend on i915 to handle the 452 + * backlight. This will leave the backlight on unnecessarily when 453 + * another client is not activated. 454 + */ 455 + if (dev_priv->drm.switch_power_state == DRM_SWITCH_POWER_CHANGING) { 456 + drm_dbg_kms(&dev_priv->drm, 457 + "Skipping backlight disable on vga switch\n"); 458 + return; 459 + } 460 + 461 + mutex_lock(&dev_priv->backlight_lock); 462 + 463 + if (panel->backlight.device) 464 + panel->backlight.device->props.power = FB_BLANK_POWERDOWN; 465 + panel->backlight.enabled = false; 466 + panel->backlight.funcs->disable(old_conn_state, 0); 467 + 468 + mutex_unlock(&dev_priv->backlight_lock); 469 + } 470 + 471 + static void lpt_enable_backlight(const struct intel_crtc_state *crtc_state, 472 + const struct drm_connector_state *conn_state, u32 level) 473 + { 474 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 475 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 476 + struct intel_panel *panel = &connector->panel; 477 + u32 pch_ctl1, pch_ctl2, schicken; 478 + 479 + pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 480 + if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { 481 + drm_dbg_kms(&dev_priv->drm, "pch backlight already enabled\n"); 482 + pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; 483 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 484 + } 485 + 486 + if (HAS_PCH_LPT(dev_priv)) { 487 + schicken = intel_de_read(dev_priv, SOUTH_CHICKEN2); 488 + if (panel->backlight.alternate_pwm_increment) 489 + schicken |= LPT_PWM_GRANULARITY; 490 + else 491 + schicken &= ~LPT_PWM_GRANULARITY; 492 + intel_de_write(dev_priv, SOUTH_CHICKEN2, schicken); 493 + } else { 494 + schicken = intel_de_read(dev_priv, SOUTH_CHICKEN1); 495 + if (panel->backlight.alternate_pwm_increment) 496 + schicken |= SPT_PWM_GRANULARITY; 497 + else 498 + schicken &= ~SPT_PWM_GRANULARITY; 499 + intel_de_write(dev_priv, SOUTH_CHICKEN1, schicken); 500 + } 501 + 502 + pch_ctl2 = panel->backlight.pwm_level_max << 16; 503 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, pch_ctl2); 504 + 505 + pch_ctl1 = 0; 506 + if (panel->backlight.active_low_pwm) 507 + pch_ctl1 |= BLM_PCH_POLARITY; 508 + 509 + /* After LPT, override is the default. */ 510 + if (HAS_PCH_LPT(dev_priv)) 511 + pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE; 512 + 513 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 514 + intel_de_posting_read(dev_priv, BLC_PWM_PCH_CTL1); 515 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 516 + pch_ctl1 | BLM_PCH_PWM_ENABLE); 517 + 518 + /* This won't stick until the above enable. */ 519 + intel_panel_set_pwm_level(conn_state, level); 520 + } 521 + 522 + static void pch_enable_backlight(const struct intel_crtc_state *crtc_state, 523 + const struct drm_connector_state *conn_state, u32 level) 524 + { 525 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 526 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 527 + struct intel_panel *panel = &connector->panel; 528 + enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 529 + u32 cpu_ctl2, pch_ctl1, pch_ctl2; 530 + 531 + cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 532 + if (cpu_ctl2 & BLM_PWM_ENABLE) { 533 + drm_dbg_kms(&dev_priv->drm, "cpu backlight already enabled\n"); 534 + cpu_ctl2 &= ~BLM_PWM_ENABLE; 535 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2); 536 + } 537 + 538 + pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 539 + if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { 540 + drm_dbg_kms(&dev_priv->drm, "pch backlight already enabled\n"); 541 + pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; 542 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 543 + } 544 + 545 + if (cpu_transcoder == TRANSCODER_EDP) 546 + cpu_ctl2 = BLM_TRANSCODER_EDP; 547 + else 548 + cpu_ctl2 = BLM_PIPE(cpu_transcoder); 549 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2); 550 + intel_de_posting_read(dev_priv, BLC_PWM_CPU_CTL2); 551 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE); 552 + 553 + /* This won't stick until the above enable. */ 554 + intel_panel_set_pwm_level(conn_state, level); 555 + 556 + pch_ctl2 = panel->backlight.pwm_level_max << 16; 557 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, pch_ctl2); 558 + 559 + pch_ctl1 = 0; 560 + if (panel->backlight.active_low_pwm) 561 + pch_ctl1 |= BLM_PCH_POLARITY; 562 + 563 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 564 + intel_de_posting_read(dev_priv, BLC_PWM_PCH_CTL1); 565 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 566 + pch_ctl1 | BLM_PCH_PWM_ENABLE); 567 + } 568 + 569 + static void i9xx_enable_backlight(const struct intel_crtc_state *crtc_state, 570 + const struct drm_connector_state *conn_state, u32 level) 571 + { 572 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 573 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 574 + struct intel_panel *panel = &connector->panel; 575 + u32 ctl, freq; 576 + 577 + ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 578 + if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) { 579 + drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 580 + intel_de_write(dev_priv, BLC_PWM_CTL, 0); 581 + } 582 + 583 + freq = panel->backlight.pwm_level_max; 584 + if (panel->backlight.combination_mode) 585 + freq /= 0xff; 586 + 587 + ctl = freq << 17; 588 + if (panel->backlight.combination_mode) 589 + ctl |= BLM_LEGACY_MODE; 590 + if (IS_PINEVIEW(dev_priv) && panel->backlight.active_low_pwm) 591 + ctl |= BLM_POLARITY_PNV; 592 + 593 + intel_de_write(dev_priv, BLC_PWM_CTL, ctl); 594 + intel_de_posting_read(dev_priv, BLC_PWM_CTL); 595 + 596 + /* XXX: combine this into above write? */ 597 + intel_panel_set_pwm_level(conn_state, level); 598 + 599 + /* 600 + * Needed to enable backlight on some 855gm models. BLC_HIST_CTL is 601 + * 855gm only, but checking for gen2 is safe, as 855gm is the only gen2 602 + * that has backlight. 603 + */ 604 + if (DISPLAY_VER(dev_priv) == 2) 605 + intel_de_write(dev_priv, BLC_HIST_CTL, BLM_HISTOGRAM_ENABLE); 606 + } 607 + 608 + static void i965_enable_backlight(const struct intel_crtc_state *crtc_state, 609 + const struct drm_connector_state *conn_state, u32 level) 610 + { 611 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 612 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 613 + struct intel_panel *panel = &connector->panel; 614 + enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; 615 + u32 ctl, ctl2, freq; 616 + 617 + ctl2 = intel_de_read(dev_priv, BLC_PWM_CTL2); 618 + if (ctl2 & BLM_PWM_ENABLE) { 619 + drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 620 + ctl2 &= ~BLM_PWM_ENABLE; 621 + intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2); 622 + } 623 + 624 + freq = panel->backlight.pwm_level_max; 625 + if (panel->backlight.combination_mode) 626 + freq /= 0xff; 627 + 628 + ctl = freq << 16; 629 + intel_de_write(dev_priv, BLC_PWM_CTL, ctl); 630 + 631 + ctl2 = BLM_PIPE(pipe); 632 + if (panel->backlight.combination_mode) 633 + ctl2 |= BLM_COMBINATION_MODE; 634 + if (panel->backlight.active_low_pwm) 635 + ctl2 |= BLM_POLARITY_I965; 636 + intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2); 637 + intel_de_posting_read(dev_priv, BLC_PWM_CTL2); 638 + intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE); 639 + 640 + intel_panel_set_pwm_level(conn_state, level); 641 + } 642 + 643 + static void vlv_enable_backlight(const struct intel_crtc_state *crtc_state, 644 + const struct drm_connector_state *conn_state, u32 level) 645 + { 646 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 647 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 648 + struct intel_panel *panel = &connector->panel; 649 + enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 650 + u32 ctl, ctl2; 651 + 652 + ctl2 = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 653 + if (ctl2 & BLM_PWM_ENABLE) { 654 + drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 655 + ctl2 &= ~BLM_PWM_ENABLE; 656 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), ctl2); 657 + } 658 + 659 + ctl = panel->backlight.pwm_level_max << 16; 660 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL(pipe), ctl); 661 + 662 + /* XXX: combine this into above write? */ 663 + intel_panel_set_pwm_level(conn_state, level); 664 + 665 + ctl2 = 0; 666 + if (panel->backlight.active_low_pwm) 667 + ctl2 |= BLM_POLARITY_I965; 668 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), ctl2); 669 + intel_de_posting_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 670 + intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), 671 + ctl2 | BLM_PWM_ENABLE); 672 + } 673 + 674 + static void bxt_enable_backlight(const struct intel_crtc_state *crtc_state, 675 + const struct drm_connector_state *conn_state, u32 level) 676 + { 677 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 678 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 679 + struct intel_panel *panel = &connector->panel; 680 + enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 681 + u32 pwm_ctl, val; 682 + 683 + /* Controller 1 uses the utility pin. */ 684 + if (panel->backlight.controller == 1) { 685 + val = intel_de_read(dev_priv, UTIL_PIN_CTL); 686 + if (val & UTIL_PIN_ENABLE) { 687 + drm_dbg_kms(&dev_priv->drm, 688 + "util pin already enabled\n"); 689 + val &= ~UTIL_PIN_ENABLE; 690 + intel_de_write(dev_priv, UTIL_PIN_CTL, val); 691 + } 692 + 693 + val = 0; 694 + if (panel->backlight.util_pin_active_low) 695 + val |= UTIL_PIN_POLARITY; 696 + intel_de_write(dev_priv, UTIL_PIN_CTL, 697 + val | UTIL_PIN_PIPE(pipe) | UTIL_PIN_MODE_PWM | UTIL_PIN_ENABLE); 698 + } 699 + 700 + pwm_ctl = intel_de_read(dev_priv, 701 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 702 + if (pwm_ctl & BXT_BLC_PWM_ENABLE) { 703 + drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 704 + pwm_ctl &= ~BXT_BLC_PWM_ENABLE; 705 + intel_de_write(dev_priv, 706 + BXT_BLC_PWM_CTL(panel->backlight.controller), 707 + pwm_ctl); 708 + } 709 + 710 + intel_de_write(dev_priv, 711 + BXT_BLC_PWM_FREQ(panel->backlight.controller), 712 + panel->backlight.pwm_level_max); 713 + 714 + intel_panel_set_pwm_level(conn_state, level); 715 + 716 + pwm_ctl = 0; 717 + if (panel->backlight.active_low_pwm) 718 + pwm_ctl |= BXT_BLC_PWM_POLARITY; 719 + 720 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 721 + pwm_ctl); 722 + intel_de_posting_read(dev_priv, 723 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 724 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 725 + pwm_ctl | BXT_BLC_PWM_ENABLE); 726 + } 727 + 728 + static void cnp_enable_backlight(const struct intel_crtc_state *crtc_state, 729 + const struct drm_connector_state *conn_state, u32 level) 730 + { 731 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 732 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 733 + struct intel_panel *panel = &connector->panel; 734 + u32 pwm_ctl; 735 + 736 + pwm_ctl = intel_de_read(dev_priv, 737 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 738 + if (pwm_ctl & BXT_BLC_PWM_ENABLE) { 739 + drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 740 + pwm_ctl &= ~BXT_BLC_PWM_ENABLE; 741 + intel_de_write(dev_priv, 742 + BXT_BLC_PWM_CTL(panel->backlight.controller), 743 + pwm_ctl); 744 + } 745 + 746 + intel_de_write(dev_priv, 747 + BXT_BLC_PWM_FREQ(panel->backlight.controller), 748 + panel->backlight.pwm_level_max); 749 + 750 + intel_panel_set_pwm_level(conn_state, level); 751 + 752 + pwm_ctl = 0; 753 + if (panel->backlight.active_low_pwm) 754 + pwm_ctl |= BXT_BLC_PWM_POLARITY; 755 + 756 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 757 + pwm_ctl); 758 + intel_de_posting_read(dev_priv, 759 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 760 + intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 761 + pwm_ctl | BXT_BLC_PWM_ENABLE); 762 + } 763 + 764 + static void ext_pwm_enable_backlight(const struct intel_crtc_state *crtc_state, 765 + const struct drm_connector_state *conn_state, u32 level) 766 + { 767 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 768 + struct intel_panel *panel = &connector->panel; 769 + 770 + pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); 771 + panel->backlight.pwm_state.enabled = true; 772 + pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 773 + } 774 + 775 + static void __intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 776 + const struct drm_connector_state *conn_state) 777 + { 778 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 779 + struct intel_panel *panel = &connector->panel; 780 + 781 + WARN_ON(panel->backlight.max == 0); 782 + 783 + if (panel->backlight.level <= panel->backlight.min) { 784 + panel->backlight.level = panel->backlight.max; 785 + if (panel->backlight.device) 786 + panel->backlight.device->props.brightness = 787 + scale_hw_to_user(connector, 788 + panel->backlight.level, 789 + panel->backlight.device->props.max_brightness); 790 + } 791 + 792 + panel->backlight.funcs->enable(crtc_state, conn_state, panel->backlight.level); 793 + panel->backlight.enabled = true; 794 + if (panel->backlight.device) 795 + panel->backlight.device->props.power = FB_BLANK_UNBLANK; 796 + } 797 + 798 + void intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 799 + const struct drm_connector_state *conn_state) 800 + { 801 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 802 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 803 + struct intel_panel *panel = &connector->panel; 804 + enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 805 + 806 + if (!panel->backlight.present) 807 + return; 808 + 809 + drm_dbg_kms(&dev_priv->drm, "pipe %c\n", pipe_name(pipe)); 810 + 811 + mutex_lock(&dev_priv->backlight_lock); 812 + 813 + __intel_panel_enable_backlight(crtc_state, conn_state); 814 + 815 + mutex_unlock(&dev_priv->backlight_lock); 816 + } 817 + 818 + #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) 819 + static u32 intel_panel_get_backlight(struct intel_connector *connector) 820 + { 821 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 822 + struct intel_panel *panel = &connector->panel; 823 + u32 val = 0; 824 + 825 + mutex_lock(&dev_priv->backlight_lock); 826 + 827 + if (panel->backlight.enabled) 828 + val = panel->backlight.funcs->get(connector, intel_connector_get_pipe(connector)); 829 + 830 + mutex_unlock(&dev_priv->backlight_lock); 831 + 832 + drm_dbg_kms(&dev_priv->drm, "get backlight PWM = %d\n", val); 833 + return val; 834 + } 835 + 836 + /* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */ 837 + static u32 scale_user_to_hw(struct intel_connector *connector, 838 + u32 user_level, u32 user_max) 839 + { 840 + struct intel_panel *panel = &connector->panel; 841 + 842 + return scale(user_level, 0, user_max, 843 + panel->backlight.min, panel->backlight.max); 844 + } 845 + 846 + /* set backlight brightness to level in range [0..max], scaling wrt hw min */ 847 + static void intel_panel_set_backlight(const struct drm_connector_state *conn_state, 848 + u32 user_level, u32 user_max) 849 + { 850 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 851 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 852 + struct intel_panel *panel = &connector->panel; 853 + u32 hw_level; 854 + 855 + if (!panel->backlight.present) 856 + return; 857 + 858 + mutex_lock(&dev_priv->backlight_lock); 859 + 860 + drm_WARN_ON(&dev_priv->drm, panel->backlight.max == 0); 861 + 862 + hw_level = scale_user_to_hw(connector, user_level, user_max); 863 + panel->backlight.level = hw_level; 864 + 865 + if (panel->backlight.enabled) 866 + intel_panel_actually_set_backlight(conn_state, hw_level); 867 + 868 + mutex_unlock(&dev_priv->backlight_lock); 869 + } 870 + 871 + static int intel_backlight_device_update_status(struct backlight_device *bd) 872 + { 873 + struct intel_connector *connector = bl_get_data(bd); 874 + struct intel_panel *panel = &connector->panel; 875 + struct drm_device *dev = connector->base.dev; 876 + 877 + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 878 + DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n", 879 + bd->props.brightness, bd->props.max_brightness); 880 + intel_panel_set_backlight(connector->base.state, bd->props.brightness, 881 + bd->props.max_brightness); 882 + 883 + /* 884 + * Allow flipping bl_power as a sub-state of enabled. Sadly the 885 + * backlight class device does not make it easy to differentiate 886 + * between callbacks for brightness and bl_power, so our backlight_power 887 + * callback needs to take this into account. 888 + */ 889 + if (panel->backlight.enabled) { 890 + if (panel->backlight.power) { 891 + bool enable = bd->props.power == FB_BLANK_UNBLANK && 892 + bd->props.brightness != 0; 893 + panel->backlight.power(connector, enable); 894 + } 895 + } else { 896 + bd->props.power = FB_BLANK_POWERDOWN; 897 + } 898 + 899 + drm_modeset_unlock(&dev->mode_config.connection_mutex); 900 + return 0; 901 + } 902 + 903 + static int intel_backlight_device_get_brightness(struct backlight_device *bd) 904 + { 905 + struct intel_connector *connector = bl_get_data(bd); 906 + struct drm_device *dev = connector->base.dev; 907 + struct drm_i915_private *dev_priv = to_i915(dev); 908 + intel_wakeref_t wakeref; 909 + int ret = 0; 910 + 911 + with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { 912 + u32 hw_level; 913 + 914 + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 915 + 916 + hw_level = intel_panel_get_backlight(connector); 917 + ret = scale_hw_to_user(connector, 918 + hw_level, bd->props.max_brightness); 919 + 920 + drm_modeset_unlock(&dev->mode_config.connection_mutex); 921 + } 922 + 923 + return ret; 924 + } 925 + 926 + static const struct backlight_ops intel_backlight_device_ops = { 927 + .update_status = intel_backlight_device_update_status, 928 + .get_brightness = intel_backlight_device_get_brightness, 929 + }; 930 + 931 + int intel_backlight_device_register(struct intel_connector *connector) 932 + { 933 + struct drm_i915_private *i915 = to_i915(connector->base.dev); 934 + struct intel_panel *panel = &connector->panel; 935 + struct backlight_properties props; 936 + struct backlight_device *bd; 937 + const char *name; 938 + int ret = 0; 939 + 940 + if (WARN_ON(panel->backlight.device)) 941 + return -ENODEV; 942 + 943 + if (!panel->backlight.present) 944 + return 0; 945 + 946 + WARN_ON(panel->backlight.max == 0); 947 + 948 + memset(&props, 0, sizeof(props)); 949 + props.type = BACKLIGHT_RAW; 950 + 951 + /* 952 + * Note: Everything should work even if the backlight device max 953 + * presented to the userspace is arbitrarily chosen. 954 + */ 955 + props.max_brightness = panel->backlight.max; 956 + props.brightness = scale_hw_to_user(connector, 957 + panel->backlight.level, 958 + props.max_brightness); 959 + 960 + if (panel->backlight.enabled) 961 + props.power = FB_BLANK_UNBLANK; 962 + else 963 + props.power = FB_BLANK_POWERDOWN; 964 + 965 + name = kstrdup("intel_backlight", GFP_KERNEL); 966 + if (!name) 967 + return -ENOMEM; 968 + 969 + bd = backlight_device_register(name, connector->base.kdev, connector, 970 + &intel_backlight_device_ops, &props); 971 + 972 + /* 973 + * Using the same name independent of the drm device or connector 974 + * prevents registration of multiple backlight devices in the 975 + * driver. However, we need to use the default name for backward 976 + * compatibility. Use unique names for subsequent backlight devices as a 977 + * fallback when the default name already exists. 978 + */ 979 + if (IS_ERR(bd) && PTR_ERR(bd) == -EEXIST) { 980 + kfree(name); 981 + name = kasprintf(GFP_KERNEL, "card%d-%s-backlight", 982 + i915->drm.primary->index, connector->base.name); 983 + if (!name) 984 + return -ENOMEM; 985 + 986 + bd = backlight_device_register(name, connector->base.kdev, connector, 987 + &intel_backlight_device_ops, &props); 988 + } 989 + 990 + if (IS_ERR(bd)) { 991 + drm_err(&i915->drm, 992 + "[CONNECTOR:%d:%s] backlight device %s register failed: %ld\n", 993 + connector->base.base.id, connector->base.name, name, PTR_ERR(bd)); 994 + ret = PTR_ERR(bd); 995 + goto out; 996 + } 997 + 998 + panel->backlight.device = bd; 999 + 1000 + drm_dbg_kms(&i915->drm, 1001 + "[CONNECTOR:%d:%s] backlight device %s registered\n", 1002 + connector->base.base.id, connector->base.name, name); 1003 + 1004 + out: 1005 + kfree(name); 1006 + 1007 + return ret; 1008 + } 1009 + 1010 + void intel_backlight_device_unregister(struct intel_connector *connector) 1011 + { 1012 + struct intel_panel *panel = &connector->panel; 1013 + 1014 + if (panel->backlight.device) { 1015 + backlight_device_unregister(panel->backlight.device); 1016 + panel->backlight.device = NULL; 1017 + } 1018 + } 1019 + #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 1020 + 1021 + /* 1022 + * CNP: PWM clock frequency is 19.2 MHz or 24 MHz. 1023 + * PWM increment = 1 1024 + */ 1025 + static u32 cnp_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1026 + { 1027 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1028 + 1029 + return DIV_ROUND_CLOSEST(KHz(RUNTIME_INFO(dev_priv)->rawclk_freq), 1030 + pwm_freq_hz); 1031 + } 1032 + 1033 + /* 1034 + * BXT: PWM clock frequency = 19.2 MHz. 1035 + */ 1036 + static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1037 + { 1038 + return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz); 1039 + } 1040 + 1041 + /* 1042 + * SPT: This value represents the period of the PWM stream in clock periods 1043 + * multiplied by 16 (default increment) or 128 (alternate increment selected in 1044 + * SCHICKEN_1 bit 0). PWM clock is 24 MHz. 1045 + */ 1046 + static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1047 + { 1048 + struct intel_panel *panel = &connector->panel; 1049 + u32 mul; 1050 + 1051 + if (panel->backlight.alternate_pwm_increment) 1052 + mul = 128; 1053 + else 1054 + mul = 16; 1055 + 1056 + return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul); 1057 + } 1058 + 1059 + /* 1060 + * LPT: This value represents the period of the PWM stream in clock periods 1061 + * multiplied by 128 (default increment) or 16 (alternate increment, selected in 1062 + * LPT SOUTH_CHICKEN2 register bit 5). 1063 + */ 1064 + static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1065 + { 1066 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1067 + struct intel_panel *panel = &connector->panel; 1068 + u32 mul, clock; 1069 + 1070 + if (panel->backlight.alternate_pwm_increment) 1071 + mul = 16; 1072 + else 1073 + mul = 128; 1074 + 1075 + if (HAS_PCH_LPT_H(dev_priv)) 1076 + clock = MHz(135); /* LPT:H */ 1077 + else 1078 + clock = MHz(24); /* LPT:LP */ 1079 + 1080 + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); 1081 + } 1082 + 1083 + /* 1084 + * ILK/SNB/IVB: This value represents the period of the PWM stream in PCH 1085 + * display raw clocks multiplied by 128. 1086 + */ 1087 + static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1088 + { 1089 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1090 + 1091 + return DIV_ROUND_CLOSEST(KHz(RUNTIME_INFO(dev_priv)->rawclk_freq), 1092 + pwm_freq_hz * 128); 1093 + } 1094 + 1095 + /* 1096 + * Gen2: This field determines the number of time base events (display core 1097 + * clock frequency/32) in total for a complete cycle of modulated backlight 1098 + * control. 1099 + * 1100 + * Gen3: A time base event equals the display core clock ([DevPNV] HRAW clock) 1101 + * divided by 32. 1102 + */ 1103 + static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1104 + { 1105 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1106 + int clock; 1107 + 1108 + if (IS_PINEVIEW(dev_priv)) 1109 + clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1110 + else 1111 + clock = KHz(dev_priv->cdclk.hw.cdclk); 1112 + 1113 + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32); 1114 + } 1115 + 1116 + /* 1117 + * Gen4: This value represents the period of the PWM stream in display core 1118 + * clocks ([DevCTG] HRAW clocks) multiplied by 128. 1119 + * 1120 + */ 1121 + static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1122 + { 1123 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1124 + int clock; 1125 + 1126 + if (IS_G4X(dev_priv)) 1127 + clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1128 + else 1129 + clock = KHz(dev_priv->cdclk.hw.cdclk); 1130 + 1131 + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128); 1132 + } 1133 + 1134 + /* 1135 + * VLV: This value represents the period of the PWM stream in display core 1136 + * clocks ([DevCTG] 200MHz HRAW clocks) multiplied by 128 or 25MHz S0IX clocks 1137 + * multiplied by 16. CHV uses a 19.2MHz S0IX clock. 1138 + */ 1139 + static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1140 + { 1141 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1142 + int mul, clock; 1143 + 1144 + if ((intel_de_read(dev_priv, CBR1_VLV) & CBR_PWM_CLOCK_MUX_SELECT) == 0) { 1145 + if (IS_CHERRYVIEW(dev_priv)) 1146 + clock = KHz(19200); 1147 + else 1148 + clock = MHz(25); 1149 + mul = 16; 1150 + } else { 1151 + clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1152 + mul = 128; 1153 + } 1154 + 1155 + return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); 1156 + } 1157 + 1158 + static u16 get_vbt_pwm_freq(struct drm_i915_private *dev_priv) 1159 + { 1160 + u16 pwm_freq_hz = dev_priv->vbt.backlight.pwm_freq_hz; 1161 + 1162 + if (pwm_freq_hz) { 1163 + drm_dbg_kms(&dev_priv->drm, 1164 + "VBT defined backlight frequency %u Hz\n", 1165 + pwm_freq_hz); 1166 + } else { 1167 + pwm_freq_hz = 200; 1168 + drm_dbg_kms(&dev_priv->drm, 1169 + "default backlight frequency %u Hz\n", 1170 + pwm_freq_hz); 1171 + } 1172 + 1173 + return pwm_freq_hz; 1174 + } 1175 + 1176 + static u32 get_backlight_max_vbt(struct intel_connector *connector) 1177 + { 1178 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1179 + struct intel_panel *panel = &connector->panel; 1180 + u16 pwm_freq_hz = get_vbt_pwm_freq(dev_priv); 1181 + u32 pwm; 1182 + 1183 + if (!panel->backlight.pwm_funcs->hz_to_pwm) { 1184 + drm_dbg_kms(&dev_priv->drm, 1185 + "backlight frequency conversion not supported\n"); 1186 + return 0; 1187 + } 1188 + 1189 + pwm = panel->backlight.pwm_funcs->hz_to_pwm(connector, pwm_freq_hz); 1190 + if (!pwm) { 1191 + drm_dbg_kms(&dev_priv->drm, 1192 + "backlight frequency conversion failed\n"); 1193 + return 0; 1194 + } 1195 + 1196 + return pwm; 1197 + } 1198 + 1199 + /* 1200 + * Note: The setup hooks can't assume pipe is set! 1201 + */ 1202 + static u32 get_backlight_min_vbt(struct intel_connector *connector) 1203 + { 1204 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1205 + struct intel_panel *panel = &connector->panel; 1206 + int min; 1207 + 1208 + drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 1209 + 1210 + /* 1211 + * XXX: If the vbt value is 255, it makes min equal to max, which leads 1212 + * to problems. There are such machines out there. Either our 1213 + * interpretation is wrong or the vbt has bogus data. Or both. Safeguard 1214 + * against this by letting the minimum be at most (arbitrarily chosen) 1215 + * 25% of the max. 1216 + */ 1217 + min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64); 1218 + if (min != dev_priv->vbt.backlight.min_brightness) { 1219 + drm_dbg_kms(&dev_priv->drm, 1220 + "clamping VBT min backlight %d/255 to %d/255\n", 1221 + dev_priv->vbt.backlight.min_brightness, min); 1222 + } 1223 + 1224 + /* vbt value is a coefficient in range [0..255] */ 1225 + return scale(min, 0, 255, 0, panel->backlight.pwm_level_max); 1226 + } 1227 + 1228 + static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused) 1229 + { 1230 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1231 + struct intel_panel *panel = &connector->panel; 1232 + u32 cpu_ctl2, pch_ctl1, pch_ctl2, val; 1233 + bool alt, cpu_mode; 1234 + 1235 + if (HAS_PCH_LPT(dev_priv)) 1236 + alt = intel_de_read(dev_priv, SOUTH_CHICKEN2) & LPT_PWM_GRANULARITY; 1237 + else 1238 + alt = intel_de_read(dev_priv, SOUTH_CHICKEN1) & SPT_PWM_GRANULARITY; 1239 + panel->backlight.alternate_pwm_increment = alt; 1240 + 1241 + pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 1242 + panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; 1243 + 1244 + pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2); 1245 + panel->backlight.pwm_level_max = pch_ctl2 >> 16; 1246 + 1247 + cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 1248 + 1249 + if (!panel->backlight.pwm_level_max) 1250 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1251 + 1252 + if (!panel->backlight.pwm_level_max) 1253 + return -ENODEV; 1254 + 1255 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1256 + 1257 + panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE; 1258 + 1259 + cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(dev_priv) && 1260 + !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) && 1261 + (cpu_ctl2 & BLM_PWM_ENABLE); 1262 + 1263 + if (cpu_mode) { 1264 + val = pch_get_backlight(connector, unused); 1265 + 1266 + drm_dbg_kms(&dev_priv->drm, 1267 + "CPU backlight register was enabled, switching to PCH override\n"); 1268 + 1269 + /* Write converted CPU PWM value to PCH override register */ 1270 + lpt_set_backlight(connector->base.state, val); 1271 + intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 1272 + pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE); 1273 + 1274 + intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, 1275 + cpu_ctl2 & ~BLM_PWM_ENABLE); 1276 + } 1277 + 1278 + return 0; 1279 + } 1280 + 1281 + static int pch_setup_backlight(struct intel_connector *connector, enum pipe unused) 1282 + { 1283 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1284 + struct intel_panel *panel = &connector->panel; 1285 + u32 cpu_ctl2, pch_ctl1, pch_ctl2; 1286 + 1287 + pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 1288 + panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; 1289 + 1290 + pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2); 1291 + panel->backlight.pwm_level_max = pch_ctl2 >> 16; 1292 + 1293 + if (!panel->backlight.pwm_level_max) 1294 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1295 + 1296 + if (!panel->backlight.pwm_level_max) 1297 + return -ENODEV; 1298 + 1299 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1300 + 1301 + cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 1302 + panel->backlight.pwm_enabled = (cpu_ctl2 & BLM_PWM_ENABLE) && 1303 + (pch_ctl1 & BLM_PCH_PWM_ENABLE); 1304 + 1305 + return 0; 1306 + } 1307 + 1308 + static int i9xx_setup_backlight(struct intel_connector *connector, enum pipe unused) 1309 + { 1310 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1311 + struct intel_panel *panel = &connector->panel; 1312 + u32 ctl, val; 1313 + 1314 + ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 1315 + 1316 + if (DISPLAY_VER(dev_priv) == 2 || IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) 1317 + panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; 1318 + 1319 + if (IS_PINEVIEW(dev_priv)) 1320 + panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV; 1321 + 1322 + panel->backlight.pwm_level_max = ctl >> 17; 1323 + 1324 + if (!panel->backlight.pwm_level_max) { 1325 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1326 + panel->backlight.pwm_level_max >>= 1; 1327 + } 1328 + 1329 + if (!panel->backlight.pwm_level_max) 1330 + return -ENODEV; 1331 + 1332 + if (panel->backlight.combination_mode) 1333 + panel->backlight.pwm_level_max *= 0xff; 1334 + 1335 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1336 + 1337 + val = i9xx_get_backlight(connector, unused); 1338 + val = intel_panel_invert_pwm_level(connector, val); 1339 + val = clamp(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); 1340 + 1341 + panel->backlight.pwm_enabled = val != 0; 1342 + 1343 + return 0; 1344 + } 1345 + 1346 + static int i965_setup_backlight(struct intel_connector *connector, enum pipe unused) 1347 + { 1348 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1349 + struct intel_panel *panel = &connector->panel; 1350 + u32 ctl, ctl2; 1351 + 1352 + ctl2 = intel_de_read(dev_priv, BLC_PWM_CTL2); 1353 + panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE; 1354 + panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; 1355 + 1356 + ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 1357 + panel->backlight.pwm_level_max = ctl >> 16; 1358 + 1359 + if (!panel->backlight.pwm_level_max) 1360 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1361 + 1362 + if (!panel->backlight.pwm_level_max) 1363 + return -ENODEV; 1364 + 1365 + if (panel->backlight.combination_mode) 1366 + panel->backlight.pwm_level_max *= 0xff; 1367 + 1368 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1369 + 1370 + panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; 1371 + 1372 + return 0; 1373 + } 1374 + 1375 + static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe) 1376 + { 1377 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1378 + struct intel_panel *panel = &connector->panel; 1379 + u32 ctl, ctl2; 1380 + 1381 + if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B)) 1382 + return -ENODEV; 1383 + 1384 + ctl2 = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 1385 + panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; 1386 + 1387 + ctl = intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)); 1388 + panel->backlight.pwm_level_max = ctl >> 16; 1389 + 1390 + if (!panel->backlight.pwm_level_max) 1391 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1392 + 1393 + if (!panel->backlight.pwm_level_max) 1394 + return -ENODEV; 1395 + 1396 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1397 + 1398 + panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; 1399 + 1400 + return 0; 1401 + } 1402 + 1403 + static int 1404 + bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) 1405 + { 1406 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1407 + struct intel_panel *panel = &connector->panel; 1408 + u32 pwm_ctl, val; 1409 + 1410 + panel->backlight.controller = dev_priv->vbt.backlight.controller; 1411 + 1412 + pwm_ctl = intel_de_read(dev_priv, 1413 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 1414 + 1415 + /* Controller 1 uses the utility pin. */ 1416 + if (panel->backlight.controller == 1) { 1417 + val = intel_de_read(dev_priv, UTIL_PIN_CTL); 1418 + panel->backlight.util_pin_active_low = 1419 + val & UTIL_PIN_POLARITY; 1420 + } 1421 + 1422 + panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; 1423 + panel->backlight.pwm_level_max = 1424 + intel_de_read(dev_priv, BXT_BLC_PWM_FREQ(panel->backlight.controller)); 1425 + 1426 + if (!panel->backlight.pwm_level_max) 1427 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1428 + 1429 + if (!panel->backlight.pwm_level_max) 1430 + return -ENODEV; 1431 + 1432 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1433 + 1434 + panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; 1435 + 1436 + return 0; 1437 + } 1438 + 1439 + static int 1440 + cnp_setup_backlight(struct intel_connector *connector, enum pipe unused) 1441 + { 1442 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1443 + struct intel_panel *panel = &connector->panel; 1444 + u32 pwm_ctl; 1445 + 1446 + /* 1447 + * CNP has the BXT implementation of backlight, but with only one 1448 + * controller. TODO: ICP has multiple controllers but we only use 1449 + * controller 0 for now. 1450 + */ 1451 + panel->backlight.controller = 0; 1452 + 1453 + pwm_ctl = intel_de_read(dev_priv, 1454 + BXT_BLC_PWM_CTL(panel->backlight.controller)); 1455 + 1456 + panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; 1457 + panel->backlight.pwm_level_max = 1458 + intel_de_read(dev_priv, BXT_BLC_PWM_FREQ(panel->backlight.controller)); 1459 + 1460 + if (!panel->backlight.pwm_level_max) 1461 + panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1462 + 1463 + if (!panel->backlight.pwm_level_max) 1464 + return -ENODEV; 1465 + 1466 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1467 + 1468 + panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; 1469 + 1470 + return 0; 1471 + } 1472 + 1473 + static int ext_pwm_setup_backlight(struct intel_connector *connector, 1474 + enum pipe pipe) 1475 + { 1476 + struct drm_device *dev = connector->base.dev; 1477 + struct drm_i915_private *dev_priv = to_i915(dev); 1478 + struct intel_panel *panel = &connector->panel; 1479 + const char *desc; 1480 + u32 level; 1481 + 1482 + /* Get the right PWM chip for DSI backlight according to VBT */ 1483 + if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) { 1484 + panel->backlight.pwm = pwm_get(dev->dev, "pwm_pmic_backlight"); 1485 + desc = "PMIC"; 1486 + } else { 1487 + panel->backlight.pwm = pwm_get(dev->dev, "pwm_soc_backlight"); 1488 + desc = "SoC"; 1489 + } 1490 + 1491 + if (IS_ERR(panel->backlight.pwm)) { 1492 + drm_err(&dev_priv->drm, "Failed to get the %s PWM chip\n", 1493 + desc); 1494 + panel->backlight.pwm = NULL; 1495 + return -ENODEV; 1496 + } 1497 + 1498 + panel->backlight.pwm_level_max = 100; /* 100% */ 1499 + panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1500 + 1501 + if (pwm_is_enabled(panel->backlight.pwm)) { 1502 + /* PWM is already enabled, use existing settings */ 1503 + pwm_get_state(panel->backlight.pwm, &panel->backlight.pwm_state); 1504 + 1505 + level = pwm_get_relative_duty_cycle(&panel->backlight.pwm_state, 1506 + 100); 1507 + level = intel_panel_invert_pwm_level(connector, level); 1508 + panel->backlight.pwm_enabled = true; 1509 + 1510 + drm_dbg_kms(&dev_priv->drm, "PWM already enabled at freq %ld, VBT freq %d, level %d\n", 1511 + NSEC_PER_SEC / (unsigned long)panel->backlight.pwm_state.period, 1512 + get_vbt_pwm_freq(dev_priv), level); 1513 + } else { 1514 + /* Set period from VBT frequency, leave other settings at 0. */ 1515 + panel->backlight.pwm_state.period = 1516 + NSEC_PER_SEC / get_vbt_pwm_freq(dev_priv); 1517 + } 1518 + 1519 + drm_info(&dev_priv->drm, "Using %s PWM for LCD backlight control\n", 1520 + desc); 1521 + return 0; 1522 + } 1523 + 1524 + static void intel_pwm_set_backlight(const struct drm_connector_state *conn_state, u32 level) 1525 + { 1526 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 1527 + struct intel_panel *panel = &connector->panel; 1528 + 1529 + panel->backlight.pwm_funcs->set(conn_state, 1530 + intel_panel_invert_pwm_level(connector, level)); 1531 + } 1532 + 1533 + static u32 intel_pwm_get_backlight(struct intel_connector *connector, enum pipe pipe) 1534 + { 1535 + struct intel_panel *panel = &connector->panel; 1536 + 1537 + return intel_panel_invert_pwm_level(connector, 1538 + panel->backlight.pwm_funcs->get(connector, pipe)); 1539 + } 1540 + 1541 + static void intel_pwm_enable_backlight(const struct intel_crtc_state *crtc_state, 1542 + const struct drm_connector_state *conn_state, u32 level) 1543 + { 1544 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 1545 + struct intel_panel *panel = &connector->panel; 1546 + 1547 + panel->backlight.pwm_funcs->enable(crtc_state, conn_state, 1548 + intel_panel_invert_pwm_level(connector, level)); 1549 + } 1550 + 1551 + static void intel_pwm_disable_backlight(const struct drm_connector_state *conn_state, u32 level) 1552 + { 1553 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 1554 + struct intel_panel *panel = &connector->panel; 1555 + 1556 + panel->backlight.pwm_funcs->disable(conn_state, 1557 + intel_panel_invert_pwm_level(connector, level)); 1558 + } 1559 + 1560 + static int intel_pwm_setup_backlight(struct intel_connector *connector, enum pipe pipe) 1561 + { 1562 + struct intel_panel *panel = &connector->panel; 1563 + int ret = panel->backlight.pwm_funcs->setup(connector, pipe); 1564 + 1565 + if (ret < 0) 1566 + return ret; 1567 + 1568 + panel->backlight.min = panel->backlight.pwm_level_min; 1569 + panel->backlight.max = panel->backlight.pwm_level_max; 1570 + panel->backlight.level = intel_pwm_get_backlight(connector, pipe); 1571 + panel->backlight.enabled = panel->backlight.pwm_enabled; 1572 + 1573 + return 0; 1574 + } 1575 + 1576 + void intel_panel_update_backlight(struct intel_atomic_state *state, 1577 + struct intel_encoder *encoder, 1578 + const struct intel_crtc_state *crtc_state, 1579 + const struct drm_connector_state *conn_state) 1580 + { 1581 + struct intel_connector *connector = to_intel_connector(conn_state->connector); 1582 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1583 + struct intel_panel *panel = &connector->panel; 1584 + 1585 + if (!panel->backlight.present) 1586 + return; 1587 + 1588 + mutex_lock(&dev_priv->backlight_lock); 1589 + if (!panel->backlight.enabled) 1590 + __intel_panel_enable_backlight(crtc_state, conn_state); 1591 + 1592 + mutex_unlock(&dev_priv->backlight_lock); 1593 + } 1594 + 1595 + int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe) 1596 + { 1597 + struct drm_i915_private *dev_priv = to_i915(connector->dev); 1598 + struct intel_connector *intel_connector = to_intel_connector(connector); 1599 + struct intel_panel *panel = &intel_connector->panel; 1600 + int ret; 1601 + 1602 + if (!dev_priv->vbt.backlight.present) { 1603 + if (dev_priv->quirks & QUIRK_BACKLIGHT_PRESENT) { 1604 + drm_dbg_kms(&dev_priv->drm, 1605 + "no backlight present per VBT, but present per quirk\n"); 1606 + } else { 1607 + drm_dbg_kms(&dev_priv->drm, 1608 + "no backlight present per VBT\n"); 1609 + return 0; 1610 + } 1611 + } 1612 + 1613 + /* ensure intel_panel has been initialized first */ 1614 + if (drm_WARN_ON(&dev_priv->drm, !panel->backlight.funcs)) 1615 + return -ENODEV; 1616 + 1617 + /* set level and max in panel struct */ 1618 + mutex_lock(&dev_priv->backlight_lock); 1619 + ret = panel->backlight.funcs->setup(intel_connector, pipe); 1620 + mutex_unlock(&dev_priv->backlight_lock); 1621 + 1622 + if (ret) { 1623 + drm_dbg_kms(&dev_priv->drm, 1624 + "failed to setup backlight for connector %s\n", 1625 + connector->name); 1626 + return ret; 1627 + } 1628 + 1629 + panel->backlight.present = true; 1630 + 1631 + drm_dbg_kms(&dev_priv->drm, 1632 + "Connector %s backlight initialized, %s, brightness %u/%u\n", 1633 + connector->name, 1634 + enableddisabled(panel->backlight.enabled), 1635 + panel->backlight.level, panel->backlight.max); 1636 + 1637 + return 0; 1638 + } 1639 + 1640 + void intel_panel_destroy_backlight(struct intel_panel *panel) 1641 + { 1642 + /* dispose of the pwm */ 1643 + if (panel->backlight.pwm) 1644 + pwm_put(panel->backlight.pwm); 1645 + 1646 + panel->backlight.present = false; 1647 + } 1648 + 1649 + static const struct intel_panel_bl_funcs bxt_pwm_funcs = { 1650 + .setup = bxt_setup_backlight, 1651 + .enable = bxt_enable_backlight, 1652 + .disable = bxt_disable_backlight, 1653 + .set = bxt_set_backlight, 1654 + .get = bxt_get_backlight, 1655 + .hz_to_pwm = bxt_hz_to_pwm, 1656 + }; 1657 + 1658 + static const struct intel_panel_bl_funcs cnp_pwm_funcs = { 1659 + .setup = cnp_setup_backlight, 1660 + .enable = cnp_enable_backlight, 1661 + .disable = cnp_disable_backlight, 1662 + .set = bxt_set_backlight, 1663 + .get = bxt_get_backlight, 1664 + .hz_to_pwm = cnp_hz_to_pwm, 1665 + }; 1666 + 1667 + static const struct intel_panel_bl_funcs lpt_pwm_funcs = { 1668 + .setup = lpt_setup_backlight, 1669 + .enable = lpt_enable_backlight, 1670 + .disable = lpt_disable_backlight, 1671 + .set = lpt_set_backlight, 1672 + .get = lpt_get_backlight, 1673 + .hz_to_pwm = lpt_hz_to_pwm, 1674 + }; 1675 + 1676 + static const struct intel_panel_bl_funcs spt_pwm_funcs = { 1677 + .setup = lpt_setup_backlight, 1678 + .enable = lpt_enable_backlight, 1679 + .disable = lpt_disable_backlight, 1680 + .set = lpt_set_backlight, 1681 + .get = lpt_get_backlight, 1682 + .hz_to_pwm = spt_hz_to_pwm, 1683 + }; 1684 + 1685 + static const struct intel_panel_bl_funcs pch_pwm_funcs = { 1686 + .setup = pch_setup_backlight, 1687 + .enable = pch_enable_backlight, 1688 + .disable = pch_disable_backlight, 1689 + .set = pch_set_backlight, 1690 + .get = pch_get_backlight, 1691 + .hz_to_pwm = pch_hz_to_pwm, 1692 + }; 1693 + 1694 + static const struct intel_panel_bl_funcs ext_pwm_funcs = { 1695 + .setup = ext_pwm_setup_backlight, 1696 + .enable = ext_pwm_enable_backlight, 1697 + .disable = ext_pwm_disable_backlight, 1698 + .set = ext_pwm_set_backlight, 1699 + .get = ext_pwm_get_backlight, 1700 + }; 1701 + 1702 + static const struct intel_panel_bl_funcs vlv_pwm_funcs = { 1703 + .setup = vlv_setup_backlight, 1704 + .enable = vlv_enable_backlight, 1705 + .disable = vlv_disable_backlight, 1706 + .set = vlv_set_backlight, 1707 + .get = vlv_get_backlight, 1708 + .hz_to_pwm = vlv_hz_to_pwm, 1709 + }; 1710 + 1711 + static const struct intel_panel_bl_funcs i965_pwm_funcs = { 1712 + .setup = i965_setup_backlight, 1713 + .enable = i965_enable_backlight, 1714 + .disable = i965_disable_backlight, 1715 + .set = i9xx_set_backlight, 1716 + .get = i9xx_get_backlight, 1717 + .hz_to_pwm = i965_hz_to_pwm, 1718 + }; 1719 + 1720 + static const struct intel_panel_bl_funcs i9xx_pwm_funcs = { 1721 + .setup = i9xx_setup_backlight, 1722 + .enable = i9xx_enable_backlight, 1723 + .disable = i9xx_disable_backlight, 1724 + .set = i9xx_set_backlight, 1725 + .get = i9xx_get_backlight, 1726 + .hz_to_pwm = i9xx_hz_to_pwm, 1727 + }; 1728 + 1729 + static const struct intel_panel_bl_funcs pwm_bl_funcs = { 1730 + .setup = intel_pwm_setup_backlight, 1731 + .enable = intel_pwm_enable_backlight, 1732 + .disable = intel_pwm_disable_backlight, 1733 + .set = intel_pwm_set_backlight, 1734 + .get = intel_pwm_get_backlight, 1735 + }; 1736 + 1737 + /* Set up chip specific backlight functions */ 1738 + void 1739 + intel_panel_init_backlight_funcs(struct intel_panel *panel) 1740 + { 1741 + struct intel_connector *connector = 1742 + container_of(panel, struct intel_connector, panel); 1743 + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1744 + 1745 + if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI && 1746 + intel_dsi_dcs_init_backlight_funcs(connector) == 0) 1747 + return; 1748 + 1749 + if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) { 1750 + panel->backlight.pwm_funcs = &bxt_pwm_funcs; 1751 + } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP) { 1752 + panel->backlight.pwm_funcs = &cnp_pwm_funcs; 1753 + } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_LPT) { 1754 + if (HAS_PCH_LPT(dev_priv)) 1755 + panel->backlight.pwm_funcs = &lpt_pwm_funcs; 1756 + else 1757 + panel->backlight.pwm_funcs = &spt_pwm_funcs; 1758 + } else if (HAS_PCH_SPLIT(dev_priv)) { 1759 + panel->backlight.pwm_funcs = &pch_pwm_funcs; 1760 + } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 1761 + if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI) { 1762 + panel->backlight.pwm_funcs = &ext_pwm_funcs; 1763 + } else { 1764 + panel->backlight.pwm_funcs = &vlv_pwm_funcs; 1765 + } 1766 + } else if (DISPLAY_VER(dev_priv) == 4) { 1767 + panel->backlight.pwm_funcs = &i965_pwm_funcs; 1768 + } else { 1769 + panel->backlight.pwm_funcs = &i9xx_pwm_funcs; 1770 + } 1771 + 1772 + if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP && 1773 + intel_dp_aux_init_backlight_funcs(connector) == 0) 1774 + return; 1775 + 1776 + /* We're using a standard PWM backlight interface */ 1777 + panel->backlight.funcs = &pwm_bl_funcs; 1778 + }
+51
drivers/gpu/drm/i915/display/intel_backlight.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2021 Intel Corporation 4 + */ 5 + 6 + #ifndef __INTEL_BACKLIGHT_H__ 7 + #define __INTEL_BACKLIGHT_H__ 8 + 9 + #include <linux/types.h> 10 + 11 + struct drm_connector; 12 + struct drm_connector_state; 13 + struct intel_atomic_state; 14 + struct intel_connector; 15 + struct intel_crtc_state; 16 + struct intel_encoder; 17 + struct intel_panel; 18 + enum pipe; 19 + 20 + void intel_panel_init_backlight_funcs(struct intel_panel *panel); 21 + void intel_panel_destroy_backlight(struct intel_panel *panel); 22 + void intel_panel_set_backlight_acpi(const struct drm_connector_state *conn_state, 23 + u32 level, u32 max); 24 + int intel_panel_setup_backlight(struct drm_connector *connector, 25 + enum pipe pipe); 26 + void intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 27 + const struct drm_connector_state *conn_state); 28 + void intel_panel_update_backlight(struct intel_atomic_state *state, 29 + struct intel_encoder *encoder, 30 + const struct intel_crtc_state *crtc_state, 31 + const struct drm_connector_state *conn_state); 32 + void intel_panel_disable_backlight(const struct drm_connector_state *old_conn_state); 33 + void intel_panel_set_pwm_level(const struct drm_connector_state *conn_state, u32 level); 34 + u32 intel_panel_invert_pwm_level(struct intel_connector *connector, u32 level); 35 + u32 intel_panel_backlight_level_to_pwm(struct intel_connector *connector, u32 level); 36 + u32 intel_panel_backlight_level_from_pwm(struct intel_connector *connector, u32 val); 37 + 38 + #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) 39 + int intel_backlight_device_register(struct intel_connector *connector); 40 + void intel_backlight_device_unregister(struct intel_connector *connector); 41 + #else /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 42 + static inline int intel_backlight_device_register(struct intel_connector *connector) 43 + { 44 + return 0; 45 + } 46 + static inline void intel_backlight_device_unregister(struct intel_connector *connector) 47 + { 48 + } 49 + #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 50 + 51 + #endif /* __INTEL_BACKLIGHT_H__ */
+2 -2
drivers/gpu/drm/i915/display/intel_connector.c
··· 29 29 #include <drm/drm_atomic_helper.h> 30 30 #include <drm/drm_edid.h> 31 31 32 - #include "display/intel_panel.h" 33 - 34 32 #include "i915_drv.h" 33 + #include "intel_backlight.h" 35 34 #include "intel_connector.h" 36 35 #include "intel_display_debugfs.h" 37 36 #include "intel_display_types.h" 38 37 #include "intel_hdcp.h" 38 + #include "intel_panel.h" 39 39 40 40 int intel_connector_init(struct intel_connector *connector) 41 41 {
+1 -1
drivers/gpu/drm/i915/display/intel_ddi.c
··· 29 29 30 30 #include "i915_drv.h" 31 31 #include "intel_audio.h" 32 + #include "intel_backlight.h" 32 33 #include "intel_combo_phy.h" 33 34 #include "intel_connector.h" 34 35 #include "intel_crtc.h" ··· 49 48 #include "intel_hdmi.h" 50 49 #include "intel_hotplug.h" 51 50 #include "intel_lspcon.h" 52 - #include "intel_panel.h" 53 51 #include "intel_pps.h" 54 52 #include "intel_psr.h" 55 53 #include "intel_snps_phy.h"
+1
drivers/gpu/drm/i915/display/intel_dp.c
··· 44 44 #include "i915_drv.h" 45 45 #include "intel_atomic.h" 46 46 #include "intel_audio.h" 47 + #include "intel_backlight.h" 47 48 #include "intel_connector.h" 48 49 #include "intel_ddi.h" 49 50 #include "intel_de.h"
+1 -1
drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
··· 34 34 * for some reason. 35 35 */ 36 36 37 + #include "intel_backlight.h" 37 38 #include "intel_display_types.h" 38 39 #include "intel_dp_aux_backlight.h" 39 - #include "intel_panel.h" 40 40 41 41 /* TODO: 42 42 * Implement HDR, right now we just implement the bare minimum to bring us back into SDR mode so we
+1
drivers/gpu/drm/i915/display/intel_lvds.c
··· 40 40 41 41 #include "i915_drv.h" 42 42 #include "intel_atomic.h" 43 + #include "intel_backlight.h" 43 44 #include "intel_connector.h" 44 45 #include "intel_de.h" 45 46 #include "intel_display_types.h"
+1 -2
drivers/gpu/drm/i915/display/intel_opregion.c
··· 30 30 #include <linux/firmware.h> 31 31 #include <acpi/video.h> 32 32 33 - #include "display/intel_panel.h" 34 - 35 33 #include "i915_drv.h" 36 34 #include "intel_acpi.h" 35 + #include "intel_backlight.h" 37 36 #include "intel_display_types.h" 38 37 #include "intel_opregion.h" 39 38
+1 -1766
drivers/gpu/drm/i915/display/intel_panel.c
··· 28 28 * Chris Wilson <chris@chris-wilson.co.uk> 29 29 */ 30 30 31 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 - 33 31 #include <linux/kernel.h> 34 - #include <linux/moduleparam.h> 35 32 #include <linux/pwm.h> 36 33 34 + #include "intel_backlight.h" 37 35 #include "intel_connector.h" 38 36 #include "intel_de.h" 39 37 #include "intel_display_types.h" 40 - #include "intel_dp_aux_backlight.h" 41 - #include "intel_dsi_dcs_backlight.h" 42 38 #include "intel_panel.h" 43 39 44 40 bool intel_panel_use_ssc(struct drm_i915_private *i915) ··· 458 462 crtc_state->gmch_pfit.lvds_border_bits = border; 459 463 460 464 return 0; 461 - } 462 - 463 - /** 464 - * scale - scale values from one range to another 465 - * @source_val: value in range [@source_min..@source_max] 466 - * @source_min: minimum legal value for @source_val 467 - * @source_max: maximum legal value for @source_val 468 - * @target_min: corresponding target value for @source_min 469 - * @target_max: corresponding target value for @source_max 470 - * 471 - * Return @source_val in range [@source_min..@source_max] scaled to range 472 - * [@target_min..@target_max]. 473 - */ 474 - static u32 scale(u32 source_val, 475 - u32 source_min, u32 source_max, 476 - u32 target_min, u32 target_max) 477 - { 478 - u64 target_val; 479 - 480 - WARN_ON(source_min > source_max); 481 - WARN_ON(target_min > target_max); 482 - 483 - /* defensive */ 484 - source_val = clamp(source_val, source_min, source_max); 485 - 486 - /* avoid overflows */ 487 - target_val = mul_u32_u32(source_val - source_min, 488 - target_max - target_min); 489 - target_val = DIV_ROUND_CLOSEST_ULL(target_val, source_max - source_min); 490 - target_val += target_min; 491 - 492 - return target_val; 493 - } 494 - 495 - /* Scale user_level in range [0..user_max] to [0..hw_max], clamping the result 496 - * to [hw_min..hw_max]. */ 497 - static u32 clamp_user_to_hw(struct intel_connector *connector, 498 - u32 user_level, u32 user_max) 499 - { 500 - struct intel_panel *panel = &connector->panel; 501 - u32 hw_level; 502 - 503 - hw_level = scale(user_level, 0, user_max, 0, panel->backlight.max); 504 - hw_level = clamp(hw_level, panel->backlight.min, panel->backlight.max); 505 - 506 - return hw_level; 507 - } 508 - 509 - /* Scale hw_level in range [hw_min..hw_max] to [0..user_max]. */ 510 - static u32 scale_hw_to_user(struct intel_connector *connector, 511 - u32 hw_level, u32 user_max) 512 - { 513 - struct intel_panel *panel = &connector->panel; 514 - 515 - return scale(hw_level, panel->backlight.min, panel->backlight.max, 516 - 0, user_max); 517 - } 518 - 519 - u32 intel_panel_invert_pwm_level(struct intel_connector *connector, u32 val) 520 - { 521 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 522 - struct intel_panel *panel = &connector->panel; 523 - 524 - drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 525 - 526 - if (dev_priv->params.invert_brightness < 0) 527 - return val; 528 - 529 - if (dev_priv->params.invert_brightness > 0 || 530 - dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS) { 531 - return panel->backlight.pwm_level_max - val + panel->backlight.pwm_level_min; 532 - } 533 - 534 - return val; 535 - } 536 - 537 - void intel_panel_set_pwm_level(const struct drm_connector_state *conn_state, u32 val) 538 - { 539 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 540 - struct drm_i915_private *i915 = to_i915(connector->base.dev); 541 - struct intel_panel *panel = &connector->panel; 542 - 543 - drm_dbg_kms(&i915->drm, "set backlight PWM = %d\n", val); 544 - panel->backlight.pwm_funcs->set(conn_state, val); 545 - } 546 - 547 - u32 intel_panel_backlight_level_to_pwm(struct intel_connector *connector, u32 val) 548 - { 549 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 550 - struct intel_panel *panel = &connector->panel; 551 - 552 - drm_WARN_ON_ONCE(&dev_priv->drm, 553 - panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); 554 - 555 - val = scale(val, panel->backlight.min, panel->backlight.max, 556 - panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); 557 - 558 - return intel_panel_invert_pwm_level(connector, val); 559 - } 560 - 561 - u32 intel_panel_backlight_level_from_pwm(struct intel_connector *connector, u32 val) 562 - { 563 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 564 - struct intel_panel *panel = &connector->panel; 565 - 566 - drm_WARN_ON_ONCE(&dev_priv->drm, 567 - panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); 568 - 569 - if (dev_priv->params.invert_brightness > 0 || 570 - (dev_priv->params.invert_brightness == 0 && dev_priv->quirks & QUIRK_INVERT_BRIGHTNESS)) 571 - val = panel->backlight.pwm_level_max - (val - panel->backlight.pwm_level_min); 572 - 573 - return scale(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max, 574 - panel->backlight.min, panel->backlight.max); 575 - } 576 - 577 - static u32 lpt_get_backlight(struct intel_connector *connector, enum pipe unused) 578 - { 579 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 580 - 581 - return intel_de_read(dev_priv, BLC_PWM_PCH_CTL2) & BACKLIGHT_DUTY_CYCLE_MASK; 582 - } 583 - 584 - static u32 pch_get_backlight(struct intel_connector *connector, enum pipe unused) 585 - { 586 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 587 - 588 - return intel_de_read(dev_priv, BLC_PWM_CPU_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; 589 - } 590 - 591 - static u32 i9xx_get_backlight(struct intel_connector *connector, enum pipe unused) 592 - { 593 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 594 - struct intel_panel *panel = &connector->panel; 595 - u32 val; 596 - 597 - val = intel_de_read(dev_priv, BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK; 598 - if (DISPLAY_VER(dev_priv) < 4) 599 - val >>= 1; 600 - 601 - if (panel->backlight.combination_mode) { 602 - u8 lbpc; 603 - 604 - pci_read_config_byte(to_pci_dev(dev_priv->drm.dev), LBPC, &lbpc); 605 - val *= lbpc; 606 - } 607 - 608 - return val; 609 - } 610 - 611 - static u32 vlv_get_backlight(struct intel_connector *connector, enum pipe pipe) 612 - { 613 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 614 - 615 - if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B)) 616 - return 0; 617 - 618 - return intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK; 619 - } 620 - 621 - static u32 bxt_get_backlight(struct intel_connector *connector, enum pipe unused) 622 - { 623 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 624 - struct intel_panel *panel = &connector->panel; 625 - 626 - return intel_de_read(dev_priv, 627 - BXT_BLC_PWM_DUTY(panel->backlight.controller)); 628 - } 629 - 630 - static u32 ext_pwm_get_backlight(struct intel_connector *connector, enum pipe unused) 631 - { 632 - struct intel_panel *panel = &connector->panel; 633 - struct pwm_state state; 634 - 635 - pwm_get_state(panel->backlight.pwm, &state); 636 - return pwm_get_relative_duty_cycle(&state, 100); 637 - } 638 - 639 - static void lpt_set_backlight(const struct drm_connector_state *conn_state, u32 level) 640 - { 641 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 642 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 643 - 644 - u32 val = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2) & ~BACKLIGHT_DUTY_CYCLE_MASK; 645 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, val | level); 646 - } 647 - 648 - static void pch_set_backlight(const struct drm_connector_state *conn_state, u32 level) 649 - { 650 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 651 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 652 - u32 tmp; 653 - 654 - tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; 655 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL, tmp | level); 656 - } 657 - 658 - static void i9xx_set_backlight(const struct drm_connector_state *conn_state, u32 level) 659 - { 660 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 661 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 662 - struct intel_panel *panel = &connector->panel; 663 - u32 tmp, mask; 664 - 665 - drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 666 - 667 - if (panel->backlight.combination_mode) { 668 - u8 lbpc; 669 - 670 - lbpc = level * 0xfe / panel->backlight.pwm_level_max + 1; 671 - level /= lbpc; 672 - pci_write_config_byte(to_pci_dev(dev_priv->drm.dev), LBPC, lbpc); 673 - } 674 - 675 - if (DISPLAY_VER(dev_priv) == 4) { 676 - mask = BACKLIGHT_DUTY_CYCLE_MASK; 677 - } else { 678 - level <<= 1; 679 - mask = BACKLIGHT_DUTY_CYCLE_MASK_PNV; 680 - } 681 - 682 - tmp = intel_de_read(dev_priv, BLC_PWM_CTL) & ~mask; 683 - intel_de_write(dev_priv, BLC_PWM_CTL, tmp | level); 684 - } 685 - 686 - static void vlv_set_backlight(const struct drm_connector_state *conn_state, u32 level) 687 - { 688 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 689 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 690 - enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; 691 - u32 tmp; 692 - 693 - tmp = intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK; 694 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL(pipe), tmp | level); 695 - } 696 - 697 - static void bxt_set_backlight(const struct drm_connector_state *conn_state, u32 level) 698 - { 699 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 700 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 701 - struct intel_panel *panel = &connector->panel; 702 - 703 - intel_de_write(dev_priv, 704 - BXT_BLC_PWM_DUTY(panel->backlight.controller), level); 705 - } 706 - 707 - static void ext_pwm_set_backlight(const struct drm_connector_state *conn_state, u32 level) 708 - { 709 - struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel; 710 - 711 - pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); 712 - pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 713 - } 714 - 715 - static void 716 - intel_panel_actually_set_backlight(const struct drm_connector_state *conn_state, u32 level) 717 - { 718 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 719 - struct drm_i915_private *i915 = to_i915(connector->base.dev); 720 - struct intel_panel *panel = &connector->panel; 721 - 722 - drm_dbg_kms(&i915->drm, "set backlight level = %d\n", level); 723 - 724 - panel->backlight.funcs->set(conn_state, level); 725 - } 726 - 727 - /* set backlight brightness to level in range [0..max], assuming hw min is 728 - * respected. 729 - */ 730 - void intel_panel_set_backlight_acpi(const struct drm_connector_state *conn_state, 731 - u32 user_level, u32 user_max) 732 - { 733 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 734 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 735 - struct intel_panel *panel = &connector->panel; 736 - u32 hw_level; 737 - 738 - /* 739 - * Lack of crtc may occur during driver init because 740 - * connection_mutex isn't held across the entire backlight 741 - * setup + modeset readout, and the BIOS can issue the 742 - * requests at any time. 743 - */ 744 - if (!panel->backlight.present || !conn_state->crtc) 745 - return; 746 - 747 - mutex_lock(&dev_priv->backlight_lock); 748 - 749 - drm_WARN_ON(&dev_priv->drm, panel->backlight.max == 0); 750 - 751 - hw_level = clamp_user_to_hw(connector, user_level, user_max); 752 - panel->backlight.level = hw_level; 753 - 754 - if (panel->backlight.device) 755 - panel->backlight.device->props.brightness = 756 - scale_hw_to_user(connector, 757 - panel->backlight.level, 758 - panel->backlight.device->props.max_brightness); 759 - 760 - if (panel->backlight.enabled) 761 - intel_panel_actually_set_backlight(conn_state, hw_level); 762 - 763 - mutex_unlock(&dev_priv->backlight_lock); 764 - } 765 - 766 - static void lpt_disable_backlight(const struct drm_connector_state *old_conn_state, u32 level) 767 - { 768 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 769 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 770 - u32 tmp; 771 - 772 - intel_panel_set_pwm_level(old_conn_state, level); 773 - 774 - /* 775 - * Although we don't support or enable CPU PWM with LPT/SPT based 776 - * systems, it may have been enabled prior to loading the 777 - * driver. Disable to avoid warnings on LCPLL disable. 778 - * 779 - * This needs rework if we need to add support for CPU PWM on PCH split 780 - * platforms. 781 - */ 782 - tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 783 - if (tmp & BLM_PWM_ENABLE) { 784 - drm_dbg_kms(&dev_priv->drm, 785 - "cpu backlight was enabled, disabling\n"); 786 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, 787 - tmp & ~BLM_PWM_ENABLE); 788 - } 789 - 790 - tmp = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 791 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); 792 - } 793 - 794 - static void pch_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 795 - { 796 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 797 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 798 - u32 tmp; 799 - 800 - intel_panel_set_pwm_level(old_conn_state, val); 801 - 802 - tmp = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 803 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, tmp & ~BLM_PWM_ENABLE); 804 - 805 - tmp = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 806 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, tmp & ~BLM_PCH_PWM_ENABLE); 807 - } 808 - 809 - static void i9xx_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 810 - { 811 - intel_panel_set_pwm_level(old_conn_state, val); 812 - } 813 - 814 - static void i965_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 815 - { 816 - struct drm_i915_private *dev_priv = to_i915(old_conn_state->connector->dev); 817 - u32 tmp; 818 - 819 - intel_panel_set_pwm_level(old_conn_state, val); 820 - 821 - tmp = intel_de_read(dev_priv, BLC_PWM_CTL2); 822 - intel_de_write(dev_priv, BLC_PWM_CTL2, tmp & ~BLM_PWM_ENABLE); 823 - } 824 - 825 - static void vlv_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 826 - { 827 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 828 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 829 - enum pipe pipe = to_intel_crtc(old_conn_state->crtc)->pipe; 830 - u32 tmp; 831 - 832 - intel_panel_set_pwm_level(old_conn_state, val); 833 - 834 - tmp = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 835 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), 836 - tmp & ~BLM_PWM_ENABLE); 837 - } 838 - 839 - static void bxt_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 840 - { 841 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 842 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 843 - struct intel_panel *panel = &connector->panel; 844 - u32 tmp; 845 - 846 - intel_panel_set_pwm_level(old_conn_state, val); 847 - 848 - tmp = intel_de_read(dev_priv, 849 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 850 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 851 - tmp & ~BXT_BLC_PWM_ENABLE); 852 - 853 - if (panel->backlight.controller == 1) { 854 - val = intel_de_read(dev_priv, UTIL_PIN_CTL); 855 - val &= ~UTIL_PIN_ENABLE; 856 - intel_de_write(dev_priv, UTIL_PIN_CTL, val); 857 - } 858 - } 859 - 860 - static void cnp_disable_backlight(const struct drm_connector_state *old_conn_state, u32 val) 861 - { 862 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 863 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 864 - struct intel_panel *panel = &connector->panel; 865 - u32 tmp; 866 - 867 - intel_panel_set_pwm_level(old_conn_state, val); 868 - 869 - tmp = intel_de_read(dev_priv, 870 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 871 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 872 - tmp & ~BXT_BLC_PWM_ENABLE); 873 - } 874 - 875 - static void ext_pwm_disable_backlight(const struct drm_connector_state *old_conn_state, u32 level) 876 - { 877 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 878 - struct intel_panel *panel = &connector->panel; 879 - 880 - panel->backlight.pwm_state.enabled = false; 881 - pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 882 - } 883 - 884 - void intel_panel_disable_backlight(const struct drm_connector_state *old_conn_state) 885 - { 886 - struct intel_connector *connector = to_intel_connector(old_conn_state->connector); 887 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 888 - struct intel_panel *panel = &connector->panel; 889 - 890 - if (!panel->backlight.present) 891 - return; 892 - 893 - /* 894 - * Do not disable backlight on the vga_switcheroo path. When switching 895 - * away from i915, the other client may depend on i915 to handle the 896 - * backlight. This will leave the backlight on unnecessarily when 897 - * another client is not activated. 898 - */ 899 - if (dev_priv->drm.switch_power_state == DRM_SWITCH_POWER_CHANGING) { 900 - drm_dbg_kms(&dev_priv->drm, 901 - "Skipping backlight disable on vga switch\n"); 902 - return; 903 - } 904 - 905 - mutex_lock(&dev_priv->backlight_lock); 906 - 907 - if (panel->backlight.device) 908 - panel->backlight.device->props.power = FB_BLANK_POWERDOWN; 909 - panel->backlight.enabled = false; 910 - panel->backlight.funcs->disable(old_conn_state, 0); 911 - 912 - mutex_unlock(&dev_priv->backlight_lock); 913 - } 914 - 915 - static void lpt_enable_backlight(const struct intel_crtc_state *crtc_state, 916 - const struct drm_connector_state *conn_state, u32 level) 917 - { 918 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 919 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 920 - struct intel_panel *panel = &connector->panel; 921 - u32 pch_ctl1, pch_ctl2, schicken; 922 - 923 - pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 924 - if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { 925 - drm_dbg_kms(&dev_priv->drm, "pch backlight already enabled\n"); 926 - pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; 927 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 928 - } 929 - 930 - if (HAS_PCH_LPT(dev_priv)) { 931 - schicken = intel_de_read(dev_priv, SOUTH_CHICKEN2); 932 - if (panel->backlight.alternate_pwm_increment) 933 - schicken |= LPT_PWM_GRANULARITY; 934 - else 935 - schicken &= ~LPT_PWM_GRANULARITY; 936 - intel_de_write(dev_priv, SOUTH_CHICKEN2, schicken); 937 - } else { 938 - schicken = intel_de_read(dev_priv, SOUTH_CHICKEN1); 939 - if (panel->backlight.alternate_pwm_increment) 940 - schicken |= SPT_PWM_GRANULARITY; 941 - else 942 - schicken &= ~SPT_PWM_GRANULARITY; 943 - intel_de_write(dev_priv, SOUTH_CHICKEN1, schicken); 944 - } 945 - 946 - pch_ctl2 = panel->backlight.pwm_level_max << 16; 947 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, pch_ctl2); 948 - 949 - pch_ctl1 = 0; 950 - if (panel->backlight.active_low_pwm) 951 - pch_ctl1 |= BLM_PCH_POLARITY; 952 - 953 - /* After LPT, override is the default. */ 954 - if (HAS_PCH_LPT(dev_priv)) 955 - pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE; 956 - 957 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 958 - intel_de_posting_read(dev_priv, BLC_PWM_PCH_CTL1); 959 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 960 - pch_ctl1 | BLM_PCH_PWM_ENABLE); 961 - 962 - /* This won't stick until the above enable. */ 963 - intel_panel_set_pwm_level(conn_state, level); 964 - } 965 - 966 - static void pch_enable_backlight(const struct intel_crtc_state *crtc_state, 967 - const struct drm_connector_state *conn_state, u32 level) 968 - { 969 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 970 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 971 - struct intel_panel *panel = &connector->panel; 972 - enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 973 - u32 cpu_ctl2, pch_ctl1, pch_ctl2; 974 - 975 - cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 976 - if (cpu_ctl2 & BLM_PWM_ENABLE) { 977 - drm_dbg_kms(&dev_priv->drm, "cpu backlight already enabled\n"); 978 - cpu_ctl2 &= ~BLM_PWM_ENABLE; 979 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2); 980 - } 981 - 982 - pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 983 - if (pch_ctl1 & BLM_PCH_PWM_ENABLE) { 984 - drm_dbg_kms(&dev_priv->drm, "pch backlight already enabled\n"); 985 - pch_ctl1 &= ~BLM_PCH_PWM_ENABLE; 986 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 987 - } 988 - 989 - if (cpu_transcoder == TRANSCODER_EDP) 990 - cpu_ctl2 = BLM_TRANSCODER_EDP; 991 - else 992 - cpu_ctl2 = BLM_PIPE(cpu_transcoder); 993 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2); 994 - intel_de_posting_read(dev_priv, BLC_PWM_CPU_CTL2); 995 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, cpu_ctl2 | BLM_PWM_ENABLE); 996 - 997 - /* This won't stick until the above enable. */ 998 - intel_panel_set_pwm_level(conn_state, level); 999 - 1000 - pch_ctl2 = panel->backlight.pwm_level_max << 16; 1001 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL2, pch_ctl2); 1002 - 1003 - pch_ctl1 = 0; 1004 - if (panel->backlight.active_low_pwm) 1005 - pch_ctl1 |= BLM_PCH_POLARITY; 1006 - 1007 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, pch_ctl1); 1008 - intel_de_posting_read(dev_priv, BLC_PWM_PCH_CTL1); 1009 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 1010 - pch_ctl1 | BLM_PCH_PWM_ENABLE); 1011 - } 1012 - 1013 - static void i9xx_enable_backlight(const struct intel_crtc_state *crtc_state, 1014 - const struct drm_connector_state *conn_state, u32 level) 1015 - { 1016 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1017 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1018 - struct intel_panel *panel = &connector->panel; 1019 - u32 ctl, freq; 1020 - 1021 - ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 1022 - if (ctl & BACKLIGHT_DUTY_CYCLE_MASK_PNV) { 1023 - drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 1024 - intel_de_write(dev_priv, BLC_PWM_CTL, 0); 1025 - } 1026 - 1027 - freq = panel->backlight.pwm_level_max; 1028 - if (panel->backlight.combination_mode) 1029 - freq /= 0xff; 1030 - 1031 - ctl = freq << 17; 1032 - if (panel->backlight.combination_mode) 1033 - ctl |= BLM_LEGACY_MODE; 1034 - if (IS_PINEVIEW(dev_priv) && panel->backlight.active_low_pwm) 1035 - ctl |= BLM_POLARITY_PNV; 1036 - 1037 - intel_de_write(dev_priv, BLC_PWM_CTL, ctl); 1038 - intel_de_posting_read(dev_priv, BLC_PWM_CTL); 1039 - 1040 - /* XXX: combine this into above write? */ 1041 - intel_panel_set_pwm_level(conn_state, level); 1042 - 1043 - /* 1044 - * Needed to enable backlight on some 855gm models. BLC_HIST_CTL is 1045 - * 855gm only, but checking for gen2 is safe, as 855gm is the only gen2 1046 - * that has backlight. 1047 - */ 1048 - if (DISPLAY_VER(dev_priv) == 2) 1049 - intel_de_write(dev_priv, BLC_HIST_CTL, BLM_HISTOGRAM_ENABLE); 1050 - } 1051 - 1052 - static void i965_enable_backlight(const struct intel_crtc_state *crtc_state, 1053 - const struct drm_connector_state *conn_state, u32 level) 1054 - { 1055 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1056 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1057 - struct intel_panel *panel = &connector->panel; 1058 - enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; 1059 - u32 ctl, ctl2, freq; 1060 - 1061 - ctl2 = intel_de_read(dev_priv, BLC_PWM_CTL2); 1062 - if (ctl2 & BLM_PWM_ENABLE) { 1063 - drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 1064 - ctl2 &= ~BLM_PWM_ENABLE; 1065 - intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2); 1066 - } 1067 - 1068 - freq = panel->backlight.pwm_level_max; 1069 - if (panel->backlight.combination_mode) 1070 - freq /= 0xff; 1071 - 1072 - ctl = freq << 16; 1073 - intel_de_write(dev_priv, BLC_PWM_CTL, ctl); 1074 - 1075 - ctl2 = BLM_PIPE(pipe); 1076 - if (panel->backlight.combination_mode) 1077 - ctl2 |= BLM_COMBINATION_MODE; 1078 - if (panel->backlight.active_low_pwm) 1079 - ctl2 |= BLM_POLARITY_I965; 1080 - intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2); 1081 - intel_de_posting_read(dev_priv, BLC_PWM_CTL2); 1082 - intel_de_write(dev_priv, BLC_PWM_CTL2, ctl2 | BLM_PWM_ENABLE); 1083 - 1084 - intel_panel_set_pwm_level(conn_state, level); 1085 - } 1086 - 1087 - static void vlv_enable_backlight(const struct intel_crtc_state *crtc_state, 1088 - const struct drm_connector_state *conn_state, u32 level) 1089 - { 1090 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1091 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1092 - struct intel_panel *panel = &connector->panel; 1093 - enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 1094 - u32 ctl, ctl2; 1095 - 1096 - ctl2 = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 1097 - if (ctl2 & BLM_PWM_ENABLE) { 1098 - drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 1099 - ctl2 &= ~BLM_PWM_ENABLE; 1100 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), ctl2); 1101 - } 1102 - 1103 - ctl = panel->backlight.pwm_level_max << 16; 1104 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL(pipe), ctl); 1105 - 1106 - /* XXX: combine this into above write? */ 1107 - intel_panel_set_pwm_level(conn_state, level); 1108 - 1109 - ctl2 = 0; 1110 - if (panel->backlight.active_low_pwm) 1111 - ctl2 |= BLM_POLARITY_I965; 1112 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), ctl2); 1113 - intel_de_posting_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 1114 - intel_de_write(dev_priv, VLV_BLC_PWM_CTL2(pipe), 1115 - ctl2 | BLM_PWM_ENABLE); 1116 - } 1117 - 1118 - static void bxt_enable_backlight(const struct intel_crtc_state *crtc_state, 1119 - const struct drm_connector_state *conn_state, u32 level) 1120 - { 1121 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1122 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1123 - struct intel_panel *panel = &connector->panel; 1124 - enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 1125 - u32 pwm_ctl, val; 1126 - 1127 - /* Controller 1 uses the utility pin. */ 1128 - if (panel->backlight.controller == 1) { 1129 - val = intel_de_read(dev_priv, UTIL_PIN_CTL); 1130 - if (val & UTIL_PIN_ENABLE) { 1131 - drm_dbg_kms(&dev_priv->drm, 1132 - "util pin already enabled\n"); 1133 - val &= ~UTIL_PIN_ENABLE; 1134 - intel_de_write(dev_priv, UTIL_PIN_CTL, val); 1135 - } 1136 - 1137 - val = 0; 1138 - if (panel->backlight.util_pin_active_low) 1139 - val |= UTIL_PIN_POLARITY; 1140 - intel_de_write(dev_priv, UTIL_PIN_CTL, 1141 - val | UTIL_PIN_PIPE(pipe) | UTIL_PIN_MODE_PWM | UTIL_PIN_ENABLE); 1142 - } 1143 - 1144 - pwm_ctl = intel_de_read(dev_priv, 1145 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1146 - if (pwm_ctl & BXT_BLC_PWM_ENABLE) { 1147 - drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 1148 - pwm_ctl &= ~BXT_BLC_PWM_ENABLE; 1149 - intel_de_write(dev_priv, 1150 - BXT_BLC_PWM_CTL(panel->backlight.controller), 1151 - pwm_ctl); 1152 - } 1153 - 1154 - intel_de_write(dev_priv, 1155 - BXT_BLC_PWM_FREQ(panel->backlight.controller), 1156 - panel->backlight.pwm_level_max); 1157 - 1158 - intel_panel_set_pwm_level(conn_state, level); 1159 - 1160 - pwm_ctl = 0; 1161 - if (panel->backlight.active_low_pwm) 1162 - pwm_ctl |= BXT_BLC_PWM_POLARITY; 1163 - 1164 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 1165 - pwm_ctl); 1166 - intel_de_posting_read(dev_priv, 1167 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1168 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 1169 - pwm_ctl | BXT_BLC_PWM_ENABLE); 1170 - } 1171 - 1172 - static void cnp_enable_backlight(const struct intel_crtc_state *crtc_state, 1173 - const struct drm_connector_state *conn_state, u32 level) 1174 - { 1175 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1176 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1177 - struct intel_panel *panel = &connector->panel; 1178 - u32 pwm_ctl; 1179 - 1180 - pwm_ctl = intel_de_read(dev_priv, 1181 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1182 - if (pwm_ctl & BXT_BLC_PWM_ENABLE) { 1183 - drm_dbg_kms(&dev_priv->drm, "backlight already enabled\n"); 1184 - pwm_ctl &= ~BXT_BLC_PWM_ENABLE; 1185 - intel_de_write(dev_priv, 1186 - BXT_BLC_PWM_CTL(panel->backlight.controller), 1187 - pwm_ctl); 1188 - } 1189 - 1190 - intel_de_write(dev_priv, 1191 - BXT_BLC_PWM_FREQ(panel->backlight.controller), 1192 - panel->backlight.pwm_level_max); 1193 - 1194 - intel_panel_set_pwm_level(conn_state, level); 1195 - 1196 - pwm_ctl = 0; 1197 - if (panel->backlight.active_low_pwm) 1198 - pwm_ctl |= BXT_BLC_PWM_POLARITY; 1199 - 1200 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 1201 - pwm_ctl); 1202 - intel_de_posting_read(dev_priv, 1203 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1204 - intel_de_write(dev_priv, BXT_BLC_PWM_CTL(panel->backlight.controller), 1205 - pwm_ctl | BXT_BLC_PWM_ENABLE); 1206 - } 1207 - 1208 - static void ext_pwm_enable_backlight(const struct intel_crtc_state *crtc_state, 1209 - const struct drm_connector_state *conn_state, u32 level) 1210 - { 1211 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1212 - struct intel_panel *panel = &connector->panel; 1213 - 1214 - pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); 1215 - panel->backlight.pwm_state.enabled = true; 1216 - pwm_apply_state(panel->backlight.pwm, &panel->backlight.pwm_state); 1217 - } 1218 - 1219 - static void __intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 1220 - const struct drm_connector_state *conn_state) 1221 - { 1222 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1223 - struct intel_panel *panel = &connector->panel; 1224 - 1225 - WARN_ON(panel->backlight.max == 0); 1226 - 1227 - if (panel->backlight.level <= panel->backlight.min) { 1228 - panel->backlight.level = panel->backlight.max; 1229 - if (panel->backlight.device) 1230 - panel->backlight.device->props.brightness = 1231 - scale_hw_to_user(connector, 1232 - panel->backlight.level, 1233 - panel->backlight.device->props.max_brightness); 1234 - } 1235 - 1236 - panel->backlight.funcs->enable(crtc_state, conn_state, panel->backlight.level); 1237 - panel->backlight.enabled = true; 1238 - if (panel->backlight.device) 1239 - panel->backlight.device->props.power = FB_BLANK_UNBLANK; 1240 - } 1241 - 1242 - void intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 1243 - const struct drm_connector_state *conn_state) 1244 - { 1245 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1246 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1247 - struct intel_panel *panel = &connector->panel; 1248 - enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; 1249 - 1250 - if (!panel->backlight.present) 1251 - return; 1252 - 1253 - drm_dbg_kms(&dev_priv->drm, "pipe %c\n", pipe_name(pipe)); 1254 - 1255 - mutex_lock(&dev_priv->backlight_lock); 1256 - 1257 - __intel_panel_enable_backlight(crtc_state, conn_state); 1258 - 1259 - mutex_unlock(&dev_priv->backlight_lock); 1260 - } 1261 - 1262 - #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) 1263 - static u32 intel_panel_get_backlight(struct intel_connector *connector) 1264 - { 1265 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1266 - struct intel_panel *panel = &connector->panel; 1267 - u32 val = 0; 1268 - 1269 - mutex_lock(&dev_priv->backlight_lock); 1270 - 1271 - if (panel->backlight.enabled) 1272 - val = panel->backlight.funcs->get(connector, intel_connector_get_pipe(connector)); 1273 - 1274 - mutex_unlock(&dev_priv->backlight_lock); 1275 - 1276 - drm_dbg_kms(&dev_priv->drm, "get backlight PWM = %d\n", val); 1277 - return val; 1278 - } 1279 - 1280 - /* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */ 1281 - static u32 scale_user_to_hw(struct intel_connector *connector, 1282 - u32 user_level, u32 user_max) 1283 - { 1284 - struct intel_panel *panel = &connector->panel; 1285 - 1286 - return scale(user_level, 0, user_max, 1287 - panel->backlight.min, panel->backlight.max); 1288 - } 1289 - 1290 - /* set backlight brightness to level in range [0..max], scaling wrt hw min */ 1291 - static void intel_panel_set_backlight(const struct drm_connector_state *conn_state, 1292 - u32 user_level, u32 user_max) 1293 - { 1294 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1295 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1296 - struct intel_panel *panel = &connector->panel; 1297 - u32 hw_level; 1298 - 1299 - if (!panel->backlight.present) 1300 - return; 1301 - 1302 - mutex_lock(&dev_priv->backlight_lock); 1303 - 1304 - drm_WARN_ON(&dev_priv->drm, panel->backlight.max == 0); 1305 - 1306 - hw_level = scale_user_to_hw(connector, user_level, user_max); 1307 - panel->backlight.level = hw_level; 1308 - 1309 - if (panel->backlight.enabled) 1310 - intel_panel_actually_set_backlight(conn_state, hw_level); 1311 - 1312 - mutex_unlock(&dev_priv->backlight_lock); 1313 - } 1314 - 1315 - static int intel_backlight_device_update_status(struct backlight_device *bd) 1316 - { 1317 - struct intel_connector *connector = bl_get_data(bd); 1318 - struct intel_panel *panel = &connector->panel; 1319 - struct drm_device *dev = connector->base.dev; 1320 - 1321 - drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 1322 - DRM_DEBUG_KMS("updating intel_backlight, brightness=%d/%d\n", 1323 - bd->props.brightness, bd->props.max_brightness); 1324 - intel_panel_set_backlight(connector->base.state, bd->props.brightness, 1325 - bd->props.max_brightness); 1326 - 1327 - /* 1328 - * Allow flipping bl_power as a sub-state of enabled. Sadly the 1329 - * backlight class device does not make it easy to to differentiate 1330 - * between callbacks for brightness and bl_power, so our backlight_power 1331 - * callback needs to take this into account. 1332 - */ 1333 - if (panel->backlight.enabled) { 1334 - if (panel->backlight.power) { 1335 - bool enable = bd->props.power == FB_BLANK_UNBLANK && 1336 - bd->props.brightness != 0; 1337 - panel->backlight.power(connector, enable); 1338 - } 1339 - } else { 1340 - bd->props.power = FB_BLANK_POWERDOWN; 1341 - } 1342 - 1343 - drm_modeset_unlock(&dev->mode_config.connection_mutex); 1344 - return 0; 1345 - } 1346 - 1347 - static int intel_backlight_device_get_brightness(struct backlight_device *bd) 1348 - { 1349 - struct intel_connector *connector = bl_get_data(bd); 1350 - struct drm_device *dev = connector->base.dev; 1351 - struct drm_i915_private *dev_priv = to_i915(dev); 1352 - intel_wakeref_t wakeref; 1353 - int ret = 0; 1354 - 1355 - with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) { 1356 - u32 hw_level; 1357 - 1358 - drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 1359 - 1360 - hw_level = intel_panel_get_backlight(connector); 1361 - ret = scale_hw_to_user(connector, 1362 - hw_level, bd->props.max_brightness); 1363 - 1364 - drm_modeset_unlock(&dev->mode_config.connection_mutex); 1365 - } 1366 - 1367 - return ret; 1368 - } 1369 - 1370 - static const struct backlight_ops intel_backlight_device_ops = { 1371 - .update_status = intel_backlight_device_update_status, 1372 - .get_brightness = intel_backlight_device_get_brightness, 1373 - }; 1374 - 1375 - int intel_backlight_device_register(struct intel_connector *connector) 1376 - { 1377 - struct drm_i915_private *i915 = to_i915(connector->base.dev); 1378 - struct intel_panel *panel = &connector->panel; 1379 - struct backlight_properties props; 1380 - struct backlight_device *bd; 1381 - const char *name; 1382 - int ret = 0; 1383 - 1384 - if (WARN_ON(panel->backlight.device)) 1385 - return -ENODEV; 1386 - 1387 - if (!panel->backlight.present) 1388 - return 0; 1389 - 1390 - WARN_ON(panel->backlight.max == 0); 1391 - 1392 - memset(&props, 0, sizeof(props)); 1393 - props.type = BACKLIGHT_RAW; 1394 - 1395 - /* 1396 - * Note: Everything should work even if the backlight device max 1397 - * presented to the userspace is arbitrarily chosen. 1398 - */ 1399 - props.max_brightness = panel->backlight.max; 1400 - props.brightness = scale_hw_to_user(connector, 1401 - panel->backlight.level, 1402 - props.max_brightness); 1403 - 1404 - if (panel->backlight.enabled) 1405 - props.power = FB_BLANK_UNBLANK; 1406 - else 1407 - props.power = FB_BLANK_POWERDOWN; 1408 - 1409 - name = kstrdup("intel_backlight", GFP_KERNEL); 1410 - if (!name) 1411 - return -ENOMEM; 1412 - 1413 - bd = backlight_device_register(name, connector->base.kdev, connector, 1414 - &intel_backlight_device_ops, &props); 1415 - 1416 - /* 1417 - * Using the same name independent of the drm device or connector 1418 - * prevents registration of multiple backlight devices in the 1419 - * driver. However, we need to use the default name for backward 1420 - * compatibility. Use unique names for subsequent backlight devices as a 1421 - * fallback when the default name already exists. 1422 - */ 1423 - if (IS_ERR(bd) && PTR_ERR(bd) == -EEXIST) { 1424 - kfree(name); 1425 - name = kasprintf(GFP_KERNEL, "card%d-%s-backlight", 1426 - i915->drm.primary->index, connector->base.name); 1427 - if (!name) 1428 - return -ENOMEM; 1429 - 1430 - bd = backlight_device_register(name, connector->base.kdev, connector, 1431 - &intel_backlight_device_ops, &props); 1432 - } 1433 - 1434 - if (IS_ERR(bd)) { 1435 - drm_err(&i915->drm, 1436 - "[CONNECTOR:%d:%s] backlight device %s register failed: %ld\n", 1437 - connector->base.base.id, connector->base.name, name, PTR_ERR(bd)); 1438 - ret = PTR_ERR(bd); 1439 - goto out; 1440 - } 1441 - 1442 - panel->backlight.device = bd; 1443 - 1444 - drm_dbg_kms(&i915->drm, 1445 - "[CONNECTOR:%d:%s] backlight device %s registered\n", 1446 - connector->base.base.id, connector->base.name, name); 1447 - 1448 - out: 1449 - kfree(name); 1450 - 1451 - return ret; 1452 - } 1453 - 1454 - void intel_backlight_device_unregister(struct intel_connector *connector) 1455 - { 1456 - struct intel_panel *panel = &connector->panel; 1457 - 1458 - if (panel->backlight.device) { 1459 - backlight_device_unregister(panel->backlight.device); 1460 - panel->backlight.device = NULL; 1461 - } 1462 - } 1463 - #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 1464 - 1465 - /* 1466 - * CNP: PWM clock frequency is 19.2 MHz or 24 MHz. 1467 - * PWM increment = 1 1468 - */ 1469 - static u32 cnp_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1470 - { 1471 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1472 - 1473 - return DIV_ROUND_CLOSEST(KHz(RUNTIME_INFO(dev_priv)->rawclk_freq), 1474 - pwm_freq_hz); 1475 - } 1476 - 1477 - /* 1478 - * BXT: PWM clock frequency = 19.2 MHz. 1479 - */ 1480 - static u32 bxt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1481 - { 1482 - return DIV_ROUND_CLOSEST(KHz(19200), pwm_freq_hz); 1483 - } 1484 - 1485 - /* 1486 - * SPT: This value represents the period of the PWM stream in clock periods 1487 - * multiplied by 16 (default increment) or 128 (alternate increment selected in 1488 - * SCHICKEN_1 bit 0). PWM clock is 24 MHz. 1489 - */ 1490 - static u32 spt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1491 - { 1492 - struct intel_panel *panel = &connector->panel; 1493 - u32 mul; 1494 - 1495 - if (panel->backlight.alternate_pwm_increment) 1496 - mul = 128; 1497 - else 1498 - mul = 16; 1499 - 1500 - return DIV_ROUND_CLOSEST(MHz(24), pwm_freq_hz * mul); 1501 - } 1502 - 1503 - /* 1504 - * LPT: This value represents the period of the PWM stream in clock periods 1505 - * multiplied by 128 (default increment) or 16 (alternate increment, selected in 1506 - * LPT SOUTH_CHICKEN2 register bit 5). 1507 - */ 1508 - static u32 lpt_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1509 - { 1510 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1511 - struct intel_panel *panel = &connector->panel; 1512 - u32 mul, clock; 1513 - 1514 - if (panel->backlight.alternate_pwm_increment) 1515 - mul = 16; 1516 - else 1517 - mul = 128; 1518 - 1519 - if (HAS_PCH_LPT_H(dev_priv)) 1520 - clock = MHz(135); /* LPT:H */ 1521 - else 1522 - clock = MHz(24); /* LPT:LP */ 1523 - 1524 - return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); 1525 - } 1526 - 1527 - /* 1528 - * ILK/SNB/IVB: This value represents the period of the PWM stream in PCH 1529 - * display raw clocks multiplied by 128. 1530 - */ 1531 - static u32 pch_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1532 - { 1533 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1534 - 1535 - return DIV_ROUND_CLOSEST(KHz(RUNTIME_INFO(dev_priv)->rawclk_freq), 1536 - pwm_freq_hz * 128); 1537 - } 1538 - 1539 - /* 1540 - * Gen2: This field determines the number of time base events (display core 1541 - * clock frequency/32) in total for a complete cycle of modulated backlight 1542 - * control. 1543 - * 1544 - * Gen3: A time base event equals the display core clock ([DevPNV] HRAW clock) 1545 - * divided by 32. 1546 - */ 1547 - static u32 i9xx_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1548 - { 1549 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1550 - int clock; 1551 - 1552 - if (IS_PINEVIEW(dev_priv)) 1553 - clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1554 - else 1555 - clock = KHz(dev_priv->cdclk.hw.cdclk); 1556 - 1557 - return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 32); 1558 - } 1559 - 1560 - /* 1561 - * Gen4: This value represents the period of the PWM stream in display core 1562 - * clocks ([DevCTG] HRAW clocks) multiplied by 128. 1563 - * 1564 - */ 1565 - static u32 i965_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1566 - { 1567 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1568 - int clock; 1569 - 1570 - if (IS_G4X(dev_priv)) 1571 - clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1572 - else 1573 - clock = KHz(dev_priv->cdclk.hw.cdclk); 1574 - 1575 - return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * 128); 1576 - } 1577 - 1578 - /* 1579 - * VLV: This value represents the period of the PWM stream in display core 1580 - * clocks ([DevCTG] 200MHz HRAW clocks) multiplied by 128 or 25MHz S0IX clocks 1581 - * multiplied by 16. CHV uses a 19.2MHz S0IX clock. 1582 - */ 1583 - static u32 vlv_hz_to_pwm(struct intel_connector *connector, u32 pwm_freq_hz) 1584 - { 1585 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1586 - int mul, clock; 1587 - 1588 - if ((intel_de_read(dev_priv, CBR1_VLV) & CBR_PWM_CLOCK_MUX_SELECT) == 0) { 1589 - if (IS_CHERRYVIEW(dev_priv)) 1590 - clock = KHz(19200); 1591 - else 1592 - clock = MHz(25); 1593 - mul = 16; 1594 - } else { 1595 - clock = KHz(RUNTIME_INFO(dev_priv)->rawclk_freq); 1596 - mul = 128; 1597 - } 1598 - 1599 - return DIV_ROUND_CLOSEST(clock, pwm_freq_hz * mul); 1600 - } 1601 - 1602 - static u16 get_vbt_pwm_freq(struct drm_i915_private *dev_priv) 1603 - { 1604 - u16 pwm_freq_hz = dev_priv->vbt.backlight.pwm_freq_hz; 1605 - 1606 - if (pwm_freq_hz) { 1607 - drm_dbg_kms(&dev_priv->drm, 1608 - "VBT defined backlight frequency %u Hz\n", 1609 - pwm_freq_hz); 1610 - } else { 1611 - pwm_freq_hz = 200; 1612 - drm_dbg_kms(&dev_priv->drm, 1613 - "default backlight frequency %u Hz\n", 1614 - pwm_freq_hz); 1615 - } 1616 - 1617 - return pwm_freq_hz; 1618 - } 1619 - 1620 - static u32 get_backlight_max_vbt(struct intel_connector *connector) 1621 - { 1622 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1623 - struct intel_panel *panel = &connector->panel; 1624 - u16 pwm_freq_hz = get_vbt_pwm_freq(dev_priv); 1625 - u32 pwm; 1626 - 1627 - if (!panel->backlight.pwm_funcs->hz_to_pwm) { 1628 - drm_dbg_kms(&dev_priv->drm, 1629 - "backlight frequency conversion not supported\n"); 1630 - return 0; 1631 - } 1632 - 1633 - pwm = panel->backlight.pwm_funcs->hz_to_pwm(connector, pwm_freq_hz); 1634 - if (!pwm) { 1635 - drm_dbg_kms(&dev_priv->drm, 1636 - "backlight frequency conversion failed\n"); 1637 - return 0; 1638 - } 1639 - 1640 - return pwm; 1641 - } 1642 - 1643 - /* 1644 - * Note: The setup hooks can't assume pipe is set! 1645 - */ 1646 - static u32 get_backlight_min_vbt(struct intel_connector *connector) 1647 - { 1648 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1649 - struct intel_panel *panel = &connector->panel; 1650 - int min; 1651 - 1652 - drm_WARN_ON(&dev_priv->drm, panel->backlight.pwm_level_max == 0); 1653 - 1654 - /* 1655 - * XXX: If the vbt value is 255, it makes min equal to max, which leads 1656 - * to problems. There are such machines out there. Either our 1657 - * interpretation is wrong or the vbt has bogus data. Or both. Safeguard 1658 - * against this by letting the minimum be at most (arbitrarily chosen) 1659 - * 25% of the max. 1660 - */ 1661 - min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64); 1662 - if (min != dev_priv->vbt.backlight.min_brightness) { 1663 - drm_dbg_kms(&dev_priv->drm, 1664 - "clamping VBT min backlight %d/255 to %d/255\n", 1665 - dev_priv->vbt.backlight.min_brightness, min); 1666 - } 1667 - 1668 - /* vbt value is a coefficient in range [0..255] */ 1669 - return scale(min, 0, 255, 0, panel->backlight.pwm_level_max); 1670 - } 1671 - 1672 - static int lpt_setup_backlight(struct intel_connector *connector, enum pipe unused) 1673 - { 1674 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1675 - struct intel_panel *panel = &connector->panel; 1676 - u32 cpu_ctl2, pch_ctl1, pch_ctl2, val; 1677 - bool alt, cpu_mode; 1678 - 1679 - if (HAS_PCH_LPT(dev_priv)) 1680 - alt = intel_de_read(dev_priv, SOUTH_CHICKEN2) & LPT_PWM_GRANULARITY; 1681 - else 1682 - alt = intel_de_read(dev_priv, SOUTH_CHICKEN1) & SPT_PWM_GRANULARITY; 1683 - panel->backlight.alternate_pwm_increment = alt; 1684 - 1685 - pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 1686 - panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; 1687 - 1688 - pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2); 1689 - panel->backlight.pwm_level_max = pch_ctl2 >> 16; 1690 - 1691 - cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 1692 - 1693 - if (!panel->backlight.pwm_level_max) 1694 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1695 - 1696 - if (!panel->backlight.pwm_level_max) 1697 - return -ENODEV; 1698 - 1699 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1700 - 1701 - panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE; 1702 - 1703 - cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(dev_priv) && 1704 - !(pch_ctl1 & BLM_PCH_OVERRIDE_ENABLE) && 1705 - (cpu_ctl2 & BLM_PWM_ENABLE); 1706 - 1707 - if (cpu_mode) { 1708 - val = pch_get_backlight(connector, unused); 1709 - 1710 - drm_dbg_kms(&dev_priv->drm, 1711 - "CPU backlight register was enabled, switching to PCH override\n"); 1712 - 1713 - /* Write converted CPU PWM value to PCH override register */ 1714 - lpt_set_backlight(connector->base.state, val); 1715 - intel_de_write(dev_priv, BLC_PWM_PCH_CTL1, 1716 - pch_ctl1 | BLM_PCH_OVERRIDE_ENABLE); 1717 - 1718 - intel_de_write(dev_priv, BLC_PWM_CPU_CTL2, 1719 - cpu_ctl2 & ~BLM_PWM_ENABLE); 1720 - } 1721 - 1722 - return 0; 1723 - } 1724 - 1725 - static int pch_setup_backlight(struct intel_connector *connector, enum pipe unused) 1726 - { 1727 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1728 - struct intel_panel *panel = &connector->panel; 1729 - u32 cpu_ctl2, pch_ctl1, pch_ctl2; 1730 - 1731 - pch_ctl1 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL1); 1732 - panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; 1733 - 1734 - pch_ctl2 = intel_de_read(dev_priv, BLC_PWM_PCH_CTL2); 1735 - panel->backlight.pwm_level_max = pch_ctl2 >> 16; 1736 - 1737 - if (!panel->backlight.pwm_level_max) 1738 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1739 - 1740 - if (!panel->backlight.pwm_level_max) 1741 - return -ENODEV; 1742 - 1743 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1744 - 1745 - cpu_ctl2 = intel_de_read(dev_priv, BLC_PWM_CPU_CTL2); 1746 - panel->backlight.pwm_enabled = (cpu_ctl2 & BLM_PWM_ENABLE) && 1747 - (pch_ctl1 & BLM_PCH_PWM_ENABLE); 1748 - 1749 - return 0; 1750 - } 1751 - 1752 - static int i9xx_setup_backlight(struct intel_connector *connector, enum pipe unused) 1753 - { 1754 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1755 - struct intel_panel *panel = &connector->panel; 1756 - u32 ctl, val; 1757 - 1758 - ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 1759 - 1760 - if (DISPLAY_VER(dev_priv) == 2 || IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) 1761 - panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; 1762 - 1763 - if (IS_PINEVIEW(dev_priv)) 1764 - panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV; 1765 - 1766 - panel->backlight.pwm_level_max = ctl >> 17; 1767 - 1768 - if (!panel->backlight.pwm_level_max) { 1769 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1770 - panel->backlight.pwm_level_max >>= 1; 1771 - } 1772 - 1773 - if (!panel->backlight.pwm_level_max) 1774 - return -ENODEV; 1775 - 1776 - if (panel->backlight.combination_mode) 1777 - panel->backlight.pwm_level_max *= 0xff; 1778 - 1779 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1780 - 1781 - val = i9xx_get_backlight(connector, unused); 1782 - val = intel_panel_invert_pwm_level(connector, val); 1783 - val = clamp(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); 1784 - 1785 - panel->backlight.pwm_enabled = val != 0; 1786 - 1787 - return 0; 1788 - } 1789 - 1790 - static int i965_setup_backlight(struct intel_connector *connector, enum pipe unused) 1791 - { 1792 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1793 - struct intel_panel *panel = &connector->panel; 1794 - u32 ctl, ctl2; 1795 - 1796 - ctl2 = intel_de_read(dev_priv, BLC_PWM_CTL2); 1797 - panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE; 1798 - panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; 1799 - 1800 - ctl = intel_de_read(dev_priv, BLC_PWM_CTL); 1801 - panel->backlight.pwm_level_max = ctl >> 16; 1802 - 1803 - if (!panel->backlight.pwm_level_max) 1804 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1805 - 1806 - if (!panel->backlight.pwm_level_max) 1807 - return -ENODEV; 1808 - 1809 - if (panel->backlight.combination_mode) 1810 - panel->backlight.pwm_level_max *= 0xff; 1811 - 1812 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1813 - 1814 - panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; 1815 - 1816 - return 0; 1817 - } 1818 - 1819 - static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe) 1820 - { 1821 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1822 - struct intel_panel *panel = &connector->panel; 1823 - u32 ctl, ctl2; 1824 - 1825 - if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B)) 1826 - return -ENODEV; 1827 - 1828 - ctl2 = intel_de_read(dev_priv, VLV_BLC_PWM_CTL2(pipe)); 1829 - panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; 1830 - 1831 - ctl = intel_de_read(dev_priv, VLV_BLC_PWM_CTL(pipe)); 1832 - panel->backlight.pwm_level_max = ctl >> 16; 1833 - 1834 - if (!panel->backlight.pwm_level_max) 1835 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1836 - 1837 - if (!panel->backlight.pwm_level_max) 1838 - return -ENODEV; 1839 - 1840 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1841 - 1842 - panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; 1843 - 1844 - return 0; 1845 - } 1846 - 1847 - static int 1848 - bxt_setup_backlight(struct intel_connector *connector, enum pipe unused) 1849 - { 1850 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1851 - struct intel_panel *panel = &connector->panel; 1852 - u32 pwm_ctl, val; 1853 - 1854 - panel->backlight.controller = dev_priv->vbt.backlight.controller; 1855 - 1856 - pwm_ctl = intel_de_read(dev_priv, 1857 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1858 - 1859 - /* Controller 1 uses the utility pin. */ 1860 - if (panel->backlight.controller == 1) { 1861 - val = intel_de_read(dev_priv, UTIL_PIN_CTL); 1862 - panel->backlight.util_pin_active_low = 1863 - val & UTIL_PIN_POLARITY; 1864 - } 1865 - 1866 - panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; 1867 - panel->backlight.pwm_level_max = 1868 - intel_de_read(dev_priv, BXT_BLC_PWM_FREQ(panel->backlight.controller)); 1869 - 1870 - if (!panel->backlight.pwm_level_max) 1871 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1872 - 1873 - if (!panel->backlight.pwm_level_max) 1874 - return -ENODEV; 1875 - 1876 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1877 - 1878 - panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; 1879 - 1880 - return 0; 1881 - } 1882 - 1883 - static int 1884 - cnp_setup_backlight(struct intel_connector *connector, enum pipe unused) 1885 - { 1886 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1887 - struct intel_panel *panel = &connector->panel; 1888 - u32 pwm_ctl; 1889 - 1890 - /* 1891 - * CNP has the BXT implementation of backlight, but with only one 1892 - * controller. TODO: ICP has multiple controllers but we only use 1893 - * controller 0 for now. 1894 - */ 1895 - panel->backlight.controller = 0; 1896 - 1897 - pwm_ctl = intel_de_read(dev_priv, 1898 - BXT_BLC_PWM_CTL(panel->backlight.controller)); 1899 - 1900 - panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; 1901 - panel->backlight.pwm_level_max = 1902 - intel_de_read(dev_priv, BXT_BLC_PWM_FREQ(panel->backlight.controller)); 1903 - 1904 - if (!panel->backlight.pwm_level_max) 1905 - panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); 1906 - 1907 - if (!panel->backlight.pwm_level_max) 1908 - return -ENODEV; 1909 - 1910 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1911 - 1912 - panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; 1913 - 1914 - return 0; 1915 - } 1916 - 1917 - static int ext_pwm_setup_backlight(struct intel_connector *connector, 1918 - enum pipe pipe) 1919 - { 1920 - struct drm_device *dev = connector->base.dev; 1921 - struct drm_i915_private *dev_priv = to_i915(dev); 1922 - struct intel_panel *panel = &connector->panel; 1923 - const char *desc; 1924 - u32 level; 1925 - 1926 - /* Get the right PWM chip for DSI backlight according to VBT */ 1927 - if (dev_priv->vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) { 1928 - panel->backlight.pwm = pwm_get(dev->dev, "pwm_pmic_backlight"); 1929 - desc = "PMIC"; 1930 - } else { 1931 - panel->backlight.pwm = pwm_get(dev->dev, "pwm_soc_backlight"); 1932 - desc = "SoC"; 1933 - } 1934 - 1935 - if (IS_ERR(panel->backlight.pwm)) { 1936 - drm_err(&dev_priv->drm, "Failed to get the %s PWM chip\n", 1937 - desc); 1938 - panel->backlight.pwm = NULL; 1939 - return -ENODEV; 1940 - } 1941 - 1942 - panel->backlight.pwm_level_max = 100; /* 100% */ 1943 - panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); 1944 - 1945 - if (pwm_is_enabled(panel->backlight.pwm)) { 1946 - /* PWM is already enabled, use existing settings */ 1947 - pwm_get_state(panel->backlight.pwm, &panel->backlight.pwm_state); 1948 - 1949 - level = pwm_get_relative_duty_cycle(&panel->backlight.pwm_state, 1950 - 100); 1951 - level = intel_panel_invert_pwm_level(connector, level); 1952 - panel->backlight.pwm_enabled = true; 1953 - 1954 - drm_dbg_kms(&dev_priv->drm, "PWM already enabled at freq %ld, VBT freq %d, level %d\n", 1955 - NSEC_PER_SEC / (unsigned long)panel->backlight.pwm_state.period, 1956 - get_vbt_pwm_freq(dev_priv), level); 1957 - } else { 1958 - /* Set period from VBT frequency, leave other settings at 0. */ 1959 - panel->backlight.pwm_state.period = 1960 - NSEC_PER_SEC / get_vbt_pwm_freq(dev_priv); 1961 - } 1962 - 1963 - drm_info(&dev_priv->drm, "Using %s PWM for LCD backlight control\n", 1964 - desc); 1965 - return 0; 1966 - } 1967 - 1968 - static void intel_pwm_set_backlight(const struct drm_connector_state *conn_state, u32 level) 1969 - { 1970 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1971 - struct intel_panel *panel = &connector->panel; 1972 - 1973 - panel->backlight.pwm_funcs->set(conn_state, 1974 - intel_panel_invert_pwm_level(connector, level)); 1975 - } 1976 - 1977 - static u32 intel_pwm_get_backlight(struct intel_connector *connector, enum pipe pipe) 1978 - { 1979 - struct intel_panel *panel = &connector->panel; 1980 - 1981 - return intel_panel_invert_pwm_level(connector, 1982 - panel->backlight.pwm_funcs->get(connector, pipe)); 1983 - } 1984 - 1985 - static void intel_pwm_enable_backlight(const struct intel_crtc_state *crtc_state, 1986 - const struct drm_connector_state *conn_state, u32 level) 1987 - { 1988 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1989 - struct intel_panel *panel = &connector->panel; 1990 - 1991 - panel->backlight.pwm_funcs->enable(crtc_state, conn_state, 1992 - intel_panel_invert_pwm_level(connector, level)); 1993 - } 1994 - 1995 - static void intel_pwm_disable_backlight(const struct drm_connector_state *conn_state, u32 level) 1996 - { 1997 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 1998 - struct intel_panel *panel = &connector->panel; 1999 - 2000 - panel->backlight.pwm_funcs->disable(conn_state, 2001 - intel_panel_invert_pwm_level(connector, level)); 2002 - } 2003 - 2004 - static int intel_pwm_setup_backlight(struct intel_connector *connector, enum pipe pipe) 2005 - { 2006 - struct intel_panel *panel = &connector->panel; 2007 - int ret = panel->backlight.pwm_funcs->setup(connector, pipe); 2008 - 2009 - if (ret < 0) 2010 - return ret; 2011 - 2012 - panel->backlight.min = panel->backlight.pwm_level_min; 2013 - panel->backlight.max = panel->backlight.pwm_level_max; 2014 - panel->backlight.level = intel_pwm_get_backlight(connector, pipe); 2015 - panel->backlight.enabled = panel->backlight.pwm_enabled; 2016 - 2017 - return 0; 2018 - } 2019 - 2020 - void intel_panel_update_backlight(struct intel_atomic_state *state, 2021 - struct intel_encoder *encoder, 2022 - const struct intel_crtc_state *crtc_state, 2023 - const struct drm_connector_state *conn_state) 2024 - { 2025 - struct intel_connector *connector = to_intel_connector(conn_state->connector); 2026 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 2027 - struct intel_panel *panel = &connector->panel; 2028 - 2029 - if (!panel->backlight.present) 2030 - return; 2031 - 2032 - mutex_lock(&dev_priv->backlight_lock); 2033 - if (!panel->backlight.enabled) 2034 - __intel_panel_enable_backlight(crtc_state, conn_state); 2035 - 2036 - mutex_unlock(&dev_priv->backlight_lock); 2037 - } 2038 - 2039 - int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe) 2040 - { 2041 - struct drm_i915_private *dev_priv = to_i915(connector->dev); 2042 - struct intel_connector *intel_connector = to_intel_connector(connector); 2043 - struct intel_panel *panel = &intel_connector->panel; 2044 - int ret; 2045 - 2046 - if (!dev_priv->vbt.backlight.present) { 2047 - if (dev_priv->quirks & QUIRK_BACKLIGHT_PRESENT) { 2048 - drm_dbg_kms(&dev_priv->drm, 2049 - "no backlight present per VBT, but present per quirk\n"); 2050 - } else { 2051 - drm_dbg_kms(&dev_priv->drm, 2052 - "no backlight present per VBT\n"); 2053 - return 0; 2054 - } 2055 - } 2056 - 2057 - /* ensure intel_panel has been initialized first */ 2058 - if (drm_WARN_ON(&dev_priv->drm, !panel->backlight.funcs)) 2059 - return -ENODEV; 2060 - 2061 - /* set level and max in panel struct */ 2062 - mutex_lock(&dev_priv->backlight_lock); 2063 - ret = panel->backlight.funcs->setup(intel_connector, pipe); 2064 - mutex_unlock(&dev_priv->backlight_lock); 2065 - 2066 - if (ret) { 2067 - drm_dbg_kms(&dev_priv->drm, 2068 - "failed to setup backlight for connector %s\n", 2069 - connector->name); 2070 - return ret; 2071 - } 2072 - 2073 - panel->backlight.present = true; 2074 - 2075 - drm_dbg_kms(&dev_priv->drm, 2076 - "Connector %s backlight initialized, %s, brightness %u/%u\n", 2077 - connector->name, 2078 - enableddisabled(panel->backlight.enabled), 2079 - panel->backlight.level, panel->backlight.max); 2080 - 2081 - return 0; 2082 - } 2083 - 2084 - static void intel_panel_destroy_backlight(struct intel_panel *panel) 2085 - { 2086 - /* dispose of the pwm */ 2087 - if (panel->backlight.pwm) 2088 - pwm_put(panel->backlight.pwm); 2089 - 2090 - panel->backlight.present = false; 2091 - } 2092 - 2093 - static const struct intel_panel_bl_funcs bxt_pwm_funcs = { 2094 - .setup = bxt_setup_backlight, 2095 - .enable = bxt_enable_backlight, 2096 - .disable = bxt_disable_backlight, 2097 - .set = bxt_set_backlight, 2098 - .get = bxt_get_backlight, 2099 - .hz_to_pwm = bxt_hz_to_pwm, 2100 - }; 2101 - 2102 - static const struct intel_panel_bl_funcs cnp_pwm_funcs = { 2103 - .setup = cnp_setup_backlight, 2104 - .enable = cnp_enable_backlight, 2105 - .disable = cnp_disable_backlight, 2106 - .set = bxt_set_backlight, 2107 - .get = bxt_get_backlight, 2108 - .hz_to_pwm = cnp_hz_to_pwm, 2109 - }; 2110 - 2111 - static const struct intel_panel_bl_funcs lpt_pwm_funcs = { 2112 - .setup = lpt_setup_backlight, 2113 - .enable = lpt_enable_backlight, 2114 - .disable = lpt_disable_backlight, 2115 - .set = lpt_set_backlight, 2116 - .get = lpt_get_backlight, 2117 - .hz_to_pwm = lpt_hz_to_pwm, 2118 - }; 2119 - 2120 - static const struct intel_panel_bl_funcs spt_pwm_funcs = { 2121 - .setup = lpt_setup_backlight, 2122 - .enable = lpt_enable_backlight, 2123 - .disable = lpt_disable_backlight, 2124 - .set = lpt_set_backlight, 2125 - .get = lpt_get_backlight, 2126 - .hz_to_pwm = spt_hz_to_pwm, 2127 - }; 2128 - 2129 - static const struct intel_panel_bl_funcs pch_pwm_funcs = { 2130 - .setup = pch_setup_backlight, 2131 - .enable = pch_enable_backlight, 2132 - .disable = pch_disable_backlight, 2133 - .set = pch_set_backlight, 2134 - .get = pch_get_backlight, 2135 - .hz_to_pwm = pch_hz_to_pwm, 2136 - }; 2137 - 2138 - static const struct intel_panel_bl_funcs ext_pwm_funcs = { 2139 - .setup = ext_pwm_setup_backlight, 2140 - .enable = ext_pwm_enable_backlight, 2141 - .disable = ext_pwm_disable_backlight, 2142 - .set = ext_pwm_set_backlight, 2143 - .get = ext_pwm_get_backlight, 2144 - }; 2145 - 2146 - static const struct intel_panel_bl_funcs vlv_pwm_funcs = { 2147 - .setup = vlv_setup_backlight, 2148 - .enable = vlv_enable_backlight, 2149 - .disable = vlv_disable_backlight, 2150 - .set = vlv_set_backlight, 2151 - .get = vlv_get_backlight, 2152 - .hz_to_pwm = vlv_hz_to_pwm, 2153 - }; 2154 - 2155 - static const struct intel_panel_bl_funcs i965_pwm_funcs = { 2156 - .setup = i965_setup_backlight, 2157 - .enable = i965_enable_backlight, 2158 - .disable = i965_disable_backlight, 2159 - .set = i9xx_set_backlight, 2160 - .get = i9xx_get_backlight, 2161 - .hz_to_pwm = i965_hz_to_pwm, 2162 - }; 2163 - 2164 - static const struct intel_panel_bl_funcs i9xx_pwm_funcs = { 2165 - .setup = i9xx_setup_backlight, 2166 - .enable = i9xx_enable_backlight, 2167 - .disable = i9xx_disable_backlight, 2168 - .set = i9xx_set_backlight, 2169 - .get = i9xx_get_backlight, 2170 - .hz_to_pwm = i9xx_hz_to_pwm, 2171 - }; 2172 - 2173 - static const struct intel_panel_bl_funcs pwm_bl_funcs = { 2174 - .setup = intel_pwm_setup_backlight, 2175 - .enable = intel_pwm_enable_backlight, 2176 - .disable = intel_pwm_disable_backlight, 2177 - .set = intel_pwm_set_backlight, 2178 - .get = intel_pwm_get_backlight, 2179 - }; 2180 - 2181 - /* Set up chip specific backlight functions */ 2182 - static void 2183 - intel_panel_init_backlight_funcs(struct intel_panel *panel) 2184 - { 2185 - struct intel_connector *connector = 2186 - container_of(panel, struct intel_connector, panel); 2187 - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 2188 - 2189 - if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI && 2190 - intel_dsi_dcs_init_backlight_funcs(connector) == 0) 2191 - return; 2192 - 2193 - if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) { 2194 - panel->backlight.pwm_funcs = &bxt_pwm_funcs; 2195 - } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP) { 2196 - panel->backlight.pwm_funcs = &cnp_pwm_funcs; 2197 - } else if (INTEL_PCH_TYPE(dev_priv) >= PCH_LPT) { 2198 - if (HAS_PCH_LPT(dev_priv)) 2199 - panel->backlight.pwm_funcs = &lpt_pwm_funcs; 2200 - else 2201 - panel->backlight.pwm_funcs = &spt_pwm_funcs; 2202 - } else if (HAS_PCH_SPLIT(dev_priv)) { 2203 - panel->backlight.pwm_funcs = &pch_pwm_funcs; 2204 - } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 2205 - if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI) { 2206 - panel->backlight.pwm_funcs = &ext_pwm_funcs; 2207 - } else { 2208 - panel->backlight.pwm_funcs = &vlv_pwm_funcs; 2209 - } 2210 - } else if (DISPLAY_VER(dev_priv) == 4) { 2211 - panel->backlight.pwm_funcs = &i965_pwm_funcs; 2212 - } else { 2213 - panel->backlight.pwm_funcs = &i9xx_pwm_funcs; 2214 - } 2215 - 2216 - if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP && 2217 - intel_dp_aux_init_backlight_funcs(connector) == 0) 2218 - return; 2219 - 2220 - /* We're using a standard PWM backlight interface */ 2221 - panel->backlight.funcs = &pwm_bl_funcs; 2222 465 } 2223 466 2224 467 enum drm_connector_status
+2 -32
drivers/gpu/drm/i915/display/intel_panel.h
··· 8 8 9 9 #include <linux/types.h> 10 10 11 - #include "intel_display.h" 12 - 11 + enum drm_connector_status; 13 12 struct drm_connector; 14 13 struct drm_connector_state; 15 14 struct drm_display_mode; 15 + struct drm_i915_private; 16 16 struct intel_connector; 17 - struct intel_crtc; 18 17 struct intel_crtc_state; 19 - struct intel_encoder; 20 18 struct intel_panel; 21 19 22 20 int intel_panel_init(struct intel_panel *panel, ··· 30 32 const struct drm_connector_state *conn_state); 31 33 int intel_gmch_panel_fitting(struct intel_crtc_state *crtc_state, 32 34 const struct drm_connector_state *conn_state); 33 - void intel_panel_set_backlight_acpi(const struct drm_connector_state *conn_state, 34 - u32 level, u32 max); 35 - int intel_panel_setup_backlight(struct drm_connector *connector, 36 - enum pipe pipe); 37 - void intel_panel_enable_backlight(const struct intel_crtc_state *crtc_state, 38 - const struct drm_connector_state *conn_state); 39 - void intel_panel_update_backlight(struct intel_atomic_state *state, 40 - struct intel_encoder *encoder, 41 - const struct intel_crtc_state *crtc_state, 42 - const struct drm_connector_state *conn_state); 43 - void intel_panel_disable_backlight(const struct drm_connector_state *old_conn_state); 44 35 struct drm_display_mode * 45 36 intel_panel_edid_downclock_mode(struct intel_connector *connector, 46 37 const struct drm_display_mode *fixed_mode); ··· 37 50 intel_panel_edid_fixed_mode(struct intel_connector *connector); 38 51 struct drm_display_mode * 39 52 intel_panel_vbt_fixed_mode(struct intel_connector *connector); 40 - void intel_panel_set_pwm_level(const struct drm_connector_state *conn_state, u32 level); 41 - u32 intel_panel_invert_pwm_level(struct intel_connector *connector, u32 level); 42 - u32 intel_panel_backlight_level_to_pwm(struct intel_connector *connector, u32 level); 43 - u32 intel_panel_backlight_level_from_pwm(struct intel_connector *connector, u32 val); 44 - 45 - #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) 46 - int intel_backlight_device_register(struct intel_connector *connector); 47 - void intel_backlight_device_unregister(struct intel_connector *connector); 48 - #else /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 49 - static inline int intel_backlight_device_register(struct intel_connector *connector) 50 - { 51 - return 0; 52 - } 53 - static inline void intel_backlight_device_unregister(struct intel_connector *connector) 54 - { 55 - } 56 - #endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 57 53 58 54 #endif /* __INTEL_PANEL_H__ */
+1
drivers/gpu/drm/i915/display/vlv_dsi.c
··· 32 32 33 33 #include "i915_drv.h" 34 34 #include "intel_atomic.h" 35 + #include "intel_backlight.h" 35 36 #include "intel_connector.h" 36 37 #include "intel_crtc.h" 37 38 #include "intel_de.h"