Lines Matching +full:pwm +full:- +full:backlight
1 // SPDX-License-Identifier: MIT
6 #include <linux/backlight.h>
8 #include <linux/pwm.h>
27 * scale - scale values from one range to another
50 target_val = mul_u32_u32(source_val - source_min, in scale()
51 target_max - target_min); in scale()
52 target_val = DIV_ROUND_CLOSEST_ULL(target_val, source_max - source_min); in scale()
65 struct intel_panel *panel = &connector->panel; in clamp_user_to_hw()
68 hw_level = scale(user_level, 0, user_max, 0, panel->backlight.max); in clamp_user_to_hw()
69 hw_level = clamp(hw_level, panel->backlight.min, panel->backlight.max); in clamp_user_to_hw()
78 struct intel_panel *panel = &connector->panel; in scale_hw_to_user()
80 return scale(hw_level, panel->backlight.min, panel->backlight.max, in scale_hw_to_user()
87 struct intel_panel *panel = &connector->panel; in intel_backlight_invert_pwm_level()
89 drm_WARN_ON(display->drm, panel->backlight.pwm_level_max == 0); in intel_backlight_invert_pwm_level()
91 if (display->params.invert_brightness < 0) in intel_backlight_invert_pwm_level()
94 if (display->params.invert_brightness > 0 || in intel_backlight_invert_pwm_level()
96 return panel->backlight.pwm_level_max - val + panel->backlight.pwm_level_min; in intel_backlight_invert_pwm_level()
104 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_backlight_set_pwm_level()
105 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_set_pwm_level()
106 struct intel_panel *panel = &connector->panel; in intel_backlight_set_pwm_level()
108 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] set backlight PWM = %d\n", in intel_backlight_set_pwm_level()
109 connector->base.base.id, connector->base.name, val); in intel_backlight_set_pwm_level()
110 panel->backlight.pwm_funcs->set(conn_state, val); in intel_backlight_set_pwm_level()
115 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_level_to_pwm()
116 struct intel_panel *panel = &connector->panel; in intel_backlight_level_to_pwm()
118 drm_WARN_ON_ONCE(&i915->drm, in intel_backlight_level_to_pwm()
119 panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); in intel_backlight_level_to_pwm()
121 val = scale(val, panel->backlight.min, panel->backlight.max, in intel_backlight_level_to_pwm()
122 panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); in intel_backlight_level_to_pwm()
130 struct intel_panel *panel = &connector->panel; in intel_backlight_level_from_pwm()
132 drm_WARN_ON_ONCE(display->drm, in intel_backlight_level_from_pwm()
133 panel->backlight.max == 0 || panel->backlight.pwm_level_max == 0); in intel_backlight_level_from_pwm()
135 if (display->params.invert_brightness > 0 || in intel_backlight_level_from_pwm()
136 (display->params.invert_brightness == 0 && in intel_backlight_level_from_pwm()
138 val = panel->backlight.pwm_level_max - (val - panel->backlight.pwm_level_min); in intel_backlight_level_from_pwm()
140 return scale(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max, in intel_backlight_level_from_pwm()
141 panel->backlight.min, panel->backlight.max); in intel_backlight_level_from_pwm()
146 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_get_backlight()
153 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_get_backlight()
160 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i9xx_get_backlight()
161 struct intel_panel *panel = &connector->panel; in i9xx_get_backlight()
168 if (panel->backlight.combination_mode) { in i9xx_get_backlight()
171 pci_read_config_byte(to_pci_dev(i915->drm.dev), LBPC, &lbpc); in i9xx_get_backlight()
180 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_get_backlight()
182 if (drm_WARN_ON(&i915->drm, pipe != PIPE_A && pipe != PIPE_B)) in vlv_get_backlight()
190 struct drm_i915_private *i915 = to_i915(connector->base.dev); in bxt_get_backlight()
191 struct intel_panel *panel = &connector->panel; in bxt_get_backlight()
193 return intel_de_read(i915, BXT_BLC_PWM_DUTY(panel->backlight.controller)); in bxt_get_backlight()
198 struct intel_panel *panel = &connector->panel; in ext_pwm_get_backlight()
201 pwm_get_state(panel->backlight.pwm, &state); in ext_pwm_get_backlight()
207 struct intel_connector *connector = to_intel_connector(conn_state->connector); in lpt_set_backlight()
208 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_set_backlight()
217 struct intel_connector *connector = to_intel_connector(conn_state->connector); in pch_set_backlight()
218 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_set_backlight()
227 struct intel_connector *connector = to_intel_connector(conn_state->connector); in i9xx_set_backlight()
228 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i9xx_set_backlight()
229 struct intel_panel *panel = &connector->panel; in i9xx_set_backlight()
232 drm_WARN_ON(&i915->drm, panel->backlight.pwm_level_max == 0); in i9xx_set_backlight()
234 if (panel->backlight.combination_mode) { in i9xx_set_backlight()
237 lbpc = level * 0xfe / panel->backlight.pwm_level_max + 1; in i9xx_set_backlight()
239 pci_write_config_byte(to_pci_dev(i915->drm.dev), LBPC, lbpc); in i9xx_set_backlight()
255 struct intel_connector *connector = to_intel_connector(conn_state->connector); in vlv_set_backlight()
256 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_set_backlight()
257 enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; in vlv_set_backlight()
266 struct intel_connector *connector = to_intel_connector(conn_state->connector); in bxt_set_backlight()
267 struct drm_i915_private *i915 = to_i915(connector->base.dev); in bxt_set_backlight()
268 struct intel_panel *panel = &connector->panel; in bxt_set_backlight()
270 intel_de_write(i915, BXT_BLC_PWM_DUTY(panel->backlight.controller), level); in bxt_set_backlight()
275 struct intel_panel *panel = &to_intel_connector(conn_state->connector)->panel; in ext_pwm_set_backlight()
277 pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); in ext_pwm_set_backlight()
278 pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state); in ext_pwm_set_backlight()
284 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_panel_actually_set_backlight()
285 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_panel_actually_set_backlight()
286 struct intel_panel *panel = &connector->panel; in intel_panel_actually_set_backlight()
288 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] set backlight level = %d\n", in intel_panel_actually_set_backlight()
289 connector->base.base.id, connector->base.name, level); in intel_panel_actually_set_backlight()
291 panel->backlight.funcs->set(conn_state, level); in intel_panel_actually_set_backlight()
294 /* set backlight brightness to level in range [0..max], assuming hw min is
300 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_backlight_set_acpi()
301 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_set_acpi()
302 struct intel_panel *panel = &connector->panel; in intel_backlight_set_acpi()
307 * connection_mutex isn't held across the entire backlight in intel_backlight_set_acpi()
311 if (!panel->backlight.present || !conn_state->crtc) in intel_backlight_set_acpi()
314 mutex_lock(&i915->display.backlight.lock); in intel_backlight_set_acpi()
316 drm_WARN_ON(&i915->drm, panel->backlight.max == 0); in intel_backlight_set_acpi()
319 panel->backlight.level = hw_level; in intel_backlight_set_acpi()
321 if (panel->backlight.device) in intel_backlight_set_acpi()
322 panel->backlight.device->props.brightness = in intel_backlight_set_acpi()
324 panel->backlight.level, in intel_backlight_set_acpi()
325 panel->backlight.device->props.max_brightness); in intel_backlight_set_acpi()
327 if (panel->backlight.enabled) in intel_backlight_set_acpi()
330 mutex_unlock(&i915->display.backlight.lock); in intel_backlight_set_acpi()
335 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in lpt_disable_backlight()
336 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_disable_backlight()
342 * Although we don't support or enable CPU PWM with LPT/SPT based in lpt_disable_backlight()
346 * This needs rework if we need to add support for CPU PWM on PCH split in lpt_disable_backlight()
351 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] CPU backlight was enabled, disabling\n", in lpt_disable_backlight()
352 connector->base.base.id, connector->base.name); in lpt_disable_backlight()
361 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in pch_disable_backlight()
362 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_disable_backlight()
378 struct drm_i915_private *i915 = to_i915(old_conn_state->connector->dev); in i965_disable_backlight()
387 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in vlv_disable_backlight()
388 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_disable_backlight()
389 enum pipe pipe = to_intel_crtc(old_conn_state->crtc)->pipe; in vlv_disable_backlight()
398 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in bxt_disable_backlight()
399 struct drm_i915_private *i915 = to_i915(connector->base.dev); in bxt_disable_backlight()
400 struct intel_panel *panel = &connector->panel; in bxt_disable_backlight()
404 intel_de_rmw(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in bxt_disable_backlight()
407 if (panel->backlight.controller == 1) in bxt_disable_backlight()
413 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in cnp_disable_backlight()
414 struct drm_i915_private *i915 = to_i915(connector->base.dev); in cnp_disable_backlight()
415 struct intel_panel *panel = &connector->panel; in cnp_disable_backlight()
419 intel_de_rmw(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in cnp_disable_backlight()
425 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in ext_pwm_disable_backlight()
426 struct intel_panel *panel = &connector->panel; in ext_pwm_disable_backlight()
430 panel->backlight.pwm_state.enabled = false; in ext_pwm_disable_backlight()
431 pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state); in ext_pwm_disable_backlight()
436 struct intel_connector *connector = to_intel_connector(old_conn_state->connector); in intel_backlight_disable()
437 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_disable()
438 struct intel_panel *panel = &connector->panel; in intel_backlight_disable()
440 if (!panel->backlight.present) in intel_backlight_disable()
444 * Do not disable backlight on the vga_switcheroo path. When switching in intel_backlight_disable()
446 * backlight. This will leave the backlight on unnecessarily when in intel_backlight_disable()
449 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_CHANGING) { in intel_backlight_disable()
450 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] Skipping backlight disable on vga switch\n", in intel_backlight_disable()
451 connector->base.base.id, connector->base.name); in intel_backlight_disable()
455 mutex_lock(&i915->display.backlight.lock); in intel_backlight_disable()
457 if (panel->backlight.device) in intel_backlight_disable()
458 panel->backlight.device->props.power = BACKLIGHT_POWER_OFF; in intel_backlight_disable()
459 panel->backlight.enabled = false; in intel_backlight_disable()
460 panel->backlight.funcs->disable(old_conn_state, 0); in intel_backlight_disable()
462 mutex_unlock(&i915->display.backlight.lock); in intel_backlight_disable()
468 struct intel_connector *connector = to_intel_connector(conn_state->connector); in lpt_enable_backlight()
469 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_enable_backlight()
470 struct intel_panel *panel = &connector->panel; in lpt_enable_backlight()
475 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] PCH backlight already enabled\n", in lpt_enable_backlight()
476 connector->base.base.id, connector->base.name); in lpt_enable_backlight()
483 panel->backlight.alternate_pwm_increment ? in lpt_enable_backlight()
487 panel->backlight.alternate_pwm_increment ? in lpt_enable_backlight()
490 pch_ctl2 = panel->backlight.pwm_level_max << 16; in lpt_enable_backlight()
494 if (panel->backlight.active_low_pwm) in lpt_enable_backlight()
512 struct intel_connector *connector = to_intel_connector(conn_state->connector); in pch_enable_backlight()
513 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_enable_backlight()
514 struct intel_panel *panel = &connector->panel; in pch_enable_backlight()
515 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; in pch_enable_backlight()
520 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] CPU backlight already enabled\n", in pch_enable_backlight()
521 connector->base.base.id, connector->base.name); in pch_enable_backlight()
528 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] PCH backlight already enabled\n", in pch_enable_backlight()
529 connector->base.base.id, connector->base.name); in pch_enable_backlight()
545 pch_ctl2 = panel->backlight.pwm_level_max << 16; in pch_enable_backlight()
549 if (panel->backlight.active_low_pwm) in pch_enable_backlight()
560 struct intel_connector *connector = to_intel_connector(conn_state->connector); in i9xx_enable_backlight()
561 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i9xx_enable_backlight()
562 struct intel_panel *panel = &connector->panel; in i9xx_enable_backlight()
567 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] backlight already enabled\n", in i9xx_enable_backlight()
568 connector->base.base.id, connector->base.name); in i9xx_enable_backlight()
572 freq = panel->backlight.pwm_level_max; in i9xx_enable_backlight()
573 if (panel->backlight.combination_mode) in i9xx_enable_backlight()
577 if (panel->backlight.combination_mode) in i9xx_enable_backlight()
579 if (IS_PINEVIEW(i915) && panel->backlight.active_low_pwm) in i9xx_enable_backlight()
589 * Needed to enable backlight on some 855gm models. BLC_HIST_CTL is in i9xx_enable_backlight()
591 * that has backlight. in i9xx_enable_backlight()
600 struct intel_connector *connector = to_intel_connector(conn_state->connector); in i965_enable_backlight()
601 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i965_enable_backlight()
602 struct intel_panel *panel = &connector->panel; in i965_enable_backlight()
603 enum pipe pipe = to_intel_crtc(conn_state->crtc)->pipe; in i965_enable_backlight()
608 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] backlight already enabled\n", in i965_enable_backlight()
609 connector->base.base.id, connector->base.name); in i965_enable_backlight()
614 freq = panel->backlight.pwm_level_max; in i965_enable_backlight()
615 if (panel->backlight.combination_mode) in i965_enable_backlight()
622 if (panel->backlight.combination_mode) in i965_enable_backlight()
624 if (panel->backlight.active_low_pwm) in i965_enable_backlight()
636 struct intel_connector *connector = to_intel_connector(conn_state->connector); in vlv_enable_backlight()
637 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_enable_backlight()
638 struct intel_panel *panel = &connector->panel; in vlv_enable_backlight()
639 enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; in vlv_enable_backlight()
644 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] backlight already enabled\n", in vlv_enable_backlight()
645 connector->base.base.id, connector->base.name); in vlv_enable_backlight()
650 ctl = panel->backlight.pwm_level_max << 16; in vlv_enable_backlight()
657 if (panel->backlight.active_low_pwm) in vlv_enable_backlight()
667 struct intel_connector *connector = to_intel_connector(conn_state->connector); in bxt_enable_backlight()
668 struct drm_i915_private *i915 = to_i915(connector->base.dev); in bxt_enable_backlight()
669 struct intel_panel *panel = &connector->panel; in bxt_enable_backlight()
670 enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; in bxt_enable_backlight()
674 if (panel->backlight.controller == 1) { in bxt_enable_backlight()
677 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] utility pin already enabled\n", in bxt_enable_backlight()
678 connector->base.base.id, connector->base.name); in bxt_enable_backlight()
684 if (panel->backlight.util_pin_active_low) in bxt_enable_backlight()
690 pwm_ctl = intel_de_read(i915, BXT_BLC_PWM_CTL(panel->backlight.controller)); in bxt_enable_backlight()
692 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] backlight already enabled\n", in bxt_enable_backlight()
693 connector->base.base.id, connector->base.name); in bxt_enable_backlight()
695 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in bxt_enable_backlight()
699 intel_de_write(i915, BXT_BLC_PWM_FREQ(panel->backlight.controller), in bxt_enable_backlight()
700 panel->backlight.pwm_level_max); in bxt_enable_backlight()
705 if (panel->backlight.active_low_pwm) in bxt_enable_backlight()
708 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), pwm_ctl); in bxt_enable_backlight()
709 intel_de_posting_read(i915, BXT_BLC_PWM_CTL(panel->backlight.controller)); in bxt_enable_backlight()
710 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in bxt_enable_backlight()
717 struct intel_connector *connector = to_intel_connector(conn_state->connector); in cnp_enable_backlight()
718 struct drm_i915_private *i915 = to_i915(connector->base.dev); in cnp_enable_backlight()
719 struct intel_panel *panel = &connector->panel; in cnp_enable_backlight()
722 pwm_ctl = intel_de_read(i915, BXT_BLC_PWM_CTL(panel->backlight.controller)); in cnp_enable_backlight()
724 drm_dbg_kms(&i915->drm, "backlight already enabled\n"); in cnp_enable_backlight()
726 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in cnp_enable_backlight()
730 intel_de_write(i915, BXT_BLC_PWM_FREQ(panel->backlight.controller), in cnp_enable_backlight()
731 panel->backlight.pwm_level_max); in cnp_enable_backlight()
736 if (panel->backlight.active_low_pwm) in cnp_enable_backlight()
739 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), pwm_ctl); in cnp_enable_backlight()
740 intel_de_posting_read(i915, BXT_BLC_PWM_CTL(panel->backlight.controller)); in cnp_enable_backlight()
741 intel_de_write(i915, BXT_BLC_PWM_CTL(panel->backlight.controller), in cnp_enable_backlight()
748 struct intel_connector *connector = to_intel_connector(conn_state->connector); in ext_pwm_enable_backlight()
749 struct intel_panel *panel = &connector->panel; in ext_pwm_enable_backlight()
751 pwm_set_relative_duty_cycle(&panel->backlight.pwm_state, level, 100); in ext_pwm_enable_backlight()
752 panel->backlight.pwm_state.enabled = true; in ext_pwm_enable_backlight()
753 pwm_apply_might_sleep(panel->backlight.pwm, &panel->backlight.pwm_state); in ext_pwm_enable_backlight()
759 struct intel_connector *connector = to_intel_connector(conn_state->connector); in __intel_backlight_enable()
760 struct intel_panel *panel = &connector->panel; in __intel_backlight_enable()
762 WARN_ON(panel->backlight.max == 0); in __intel_backlight_enable()
764 if (panel->backlight.level < panel->backlight.min) { in __intel_backlight_enable()
765 panel->backlight.level = panel->backlight.min; in __intel_backlight_enable()
766 if (panel->backlight.device) in __intel_backlight_enable()
767 panel->backlight.device->props.brightness = in __intel_backlight_enable()
769 panel->backlight.level, in __intel_backlight_enable()
770 panel->backlight.device->props.max_brightness); in __intel_backlight_enable()
773 panel->backlight.funcs->enable(crtc_state, conn_state, panel->backlight.level); in __intel_backlight_enable()
774 panel->backlight.enabled = true; in __intel_backlight_enable()
775 if (panel->backlight.device) in __intel_backlight_enable()
776 panel->backlight.device->props.power = BACKLIGHT_POWER_ON; in __intel_backlight_enable()
782 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_backlight_enable()
783 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_enable()
784 struct intel_panel *panel = &connector->panel; in intel_backlight_enable()
785 enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe; in intel_backlight_enable()
787 if (!panel->backlight.present) in intel_backlight_enable()
790 drm_dbg_kms(&i915->drm, "pipe %c\n", pipe_name(pipe)); in intel_backlight_enable()
792 mutex_lock(&i915->display.backlight.lock); in intel_backlight_enable()
796 mutex_unlock(&i915->display.backlight.lock); in intel_backlight_enable()
802 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_panel_get_backlight()
803 struct intel_panel *panel = &connector->panel; in intel_panel_get_backlight()
806 mutex_lock(&i915->display.backlight.lock); in intel_panel_get_backlight()
808 if (panel->backlight.enabled) in intel_panel_get_backlight()
809 val = panel->backlight.funcs->get(connector, intel_connector_get_pipe(connector)); in intel_panel_get_backlight()
811 mutex_unlock(&i915->display.backlight.lock); in intel_panel_get_backlight()
813 drm_dbg_kms(&i915->drm, "get backlight PWM = %d\n", val); in intel_panel_get_backlight()
821 struct intel_panel *panel = &connector->panel; in scale_user_to_hw()
824 panel->backlight.min, panel->backlight.max); in scale_user_to_hw()
827 /* set backlight brightness to level in range [0..max], scaling wrt hw min */
831 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_panel_set_backlight()
832 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_panel_set_backlight()
833 struct intel_panel *panel = &connector->panel; in intel_panel_set_backlight()
836 if (!panel->backlight.present) in intel_panel_set_backlight()
839 mutex_lock(&i915->display.backlight.lock); in intel_panel_set_backlight()
841 drm_WARN_ON(&i915->drm, panel->backlight.max == 0); in intel_panel_set_backlight()
844 panel->backlight.level = hw_level; in intel_panel_set_backlight()
846 if (panel->backlight.enabled) in intel_panel_set_backlight()
849 mutex_unlock(&i915->display.backlight.lock); in intel_panel_set_backlight()
855 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_device_update_status()
856 struct intel_panel *panel = &connector->panel; in intel_backlight_device_update_status()
858 drm_modeset_lock(&i915->drm.mode_config.connection_mutex, NULL); in intel_backlight_device_update_status()
860 drm_dbg_kms(&i915->drm, "updating intel_backlight, brightness=%d/%d\n", in intel_backlight_device_update_status()
861 bd->props.brightness, bd->props.max_brightness); in intel_backlight_device_update_status()
862 intel_panel_set_backlight(connector->base.state, bd->props.brightness, in intel_backlight_device_update_status()
863 bd->props.max_brightness); in intel_backlight_device_update_status()
866 * Allow flipping bl_power as a sub-state of enabled. Sadly the in intel_backlight_device_update_status()
867 * backlight class device does not make it easy to differentiate in intel_backlight_device_update_status()
871 if (panel->backlight.enabled) { in intel_backlight_device_update_status()
872 if (panel->backlight.power) { in intel_backlight_device_update_status()
873 bool enable = bd->props.power == BACKLIGHT_POWER_ON && in intel_backlight_device_update_status()
874 bd->props.brightness != 0; in intel_backlight_device_update_status()
875 panel->backlight.power(connector, enable); in intel_backlight_device_update_status()
878 bd->props.power = BACKLIGHT_POWER_OFF; in intel_backlight_device_update_status()
881 drm_modeset_unlock(&i915->drm.mode_config.connection_mutex); in intel_backlight_device_update_status()
889 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_device_get_brightness()
893 with_intel_runtime_pm(&i915->runtime_pm, wakeref) { in intel_backlight_device_get_brightness()
896 drm_modeset_lock(&i915->drm.mode_config.connection_mutex, NULL); in intel_backlight_device_get_brightness()
900 hw_level, bd->props.max_brightness); in intel_backlight_device_get_brightness()
902 drm_modeset_unlock(&i915->drm.mode_config.connection_mutex); in intel_backlight_device_get_brightness()
915 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_device_register()
916 struct intel_panel *panel = &connector->panel; in intel_backlight_device_register()
922 if (WARN_ON(panel->backlight.device)) in intel_backlight_device_register()
923 return -ENODEV; in intel_backlight_device_register()
925 if (!panel->backlight.present) in intel_backlight_device_register()
928 WARN_ON(panel->backlight.max == 0); in intel_backlight_device_register()
931 drm_info(&i915->drm, "Skipping intel_backlight registration\n"); in intel_backlight_device_register()
939 * Note: Everything should work even if the backlight device max in intel_backlight_device_register()
942 props.max_brightness = panel->backlight.max; in intel_backlight_device_register()
944 panel->backlight.level, in intel_backlight_device_register()
947 if (panel->backlight.enabled) in intel_backlight_device_register()
954 return -ENOMEM; in intel_backlight_device_register()
958 put_device(&bd->dev); in intel_backlight_device_register()
961 * prevents registration of multiple backlight devices in the in intel_backlight_device_register()
963 * compatibility. Use unique names for subsequent backlight devices as a in intel_backlight_device_register()
967 name = kasprintf(GFP_KERNEL, "card%d-%s-backlight", in intel_backlight_device_register()
968 i915->drm.primary->index, connector->base.name); in intel_backlight_device_register()
970 return -ENOMEM; in intel_backlight_device_register()
972 bd = backlight_device_register(name, connector->base.kdev, connector, in intel_backlight_device_register()
976 drm_err(&i915->drm, in intel_backlight_device_register()
977 "[CONNECTOR:%d:%s] backlight device %s register failed: %ld\n", in intel_backlight_device_register()
978 connector->base.base.id, connector->base.name, name, PTR_ERR(bd)); in intel_backlight_device_register()
983 panel->backlight.device = bd; in intel_backlight_device_register()
985 drm_dbg_kms(&i915->drm, in intel_backlight_device_register()
986 "[CONNECTOR:%d:%s] backlight device %s registered\n", in intel_backlight_device_register()
987 connector->base.base.id, connector->base.name, name); in intel_backlight_device_register()
997 struct intel_panel *panel = &connector->panel; in intel_backlight_device_unregister()
999 if (panel->backlight.device) { in intel_backlight_device_unregister()
1000 backlight_device_unregister(panel->backlight.device); in intel_backlight_device_unregister()
1001 panel->backlight.device = NULL; in intel_backlight_device_unregister()
1007 * CNP: PWM clock frequency is 19.2 MHz or 24 MHz.
1008 * PWM increment = 1
1012 struct drm_i915_private *i915 = to_i915(connector->base.dev); in cnp_hz_to_pwm()
1014 return DIV_ROUND_CLOSEST(KHz(DISPLAY_RUNTIME_INFO(i915)->rawclk_freq), in cnp_hz_to_pwm()
1019 * BXT: PWM clock frequency = 19.2 MHz.
1027 * SPT: This value represents the period of the PWM stream in clock periods
1029 * SCHICKEN_1 bit 0). PWM clock is 24 MHz.
1033 struct intel_panel *panel = &connector->panel; in spt_hz_to_pwm()
1036 if (panel->backlight.alternate_pwm_increment) in spt_hz_to_pwm()
1045 * LPT: This value represents the period of the PWM stream in clock periods
1051 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_hz_to_pwm()
1052 struct intel_panel *panel = &connector->panel; in lpt_hz_to_pwm()
1055 if (panel->backlight.alternate_pwm_increment) in lpt_hz_to_pwm()
1069 * ILK/SNB/IVB: This value represents the period of the PWM stream in PCH
1074 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_hz_to_pwm()
1076 return DIV_ROUND_CLOSEST(KHz(DISPLAY_RUNTIME_INFO(i915)->rawclk_freq), in pch_hz_to_pwm()
1082 * clock frequency/32) in total for a complete cycle of modulated backlight
1090 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i9xx_hz_to_pwm()
1094 clock = KHz(DISPLAY_RUNTIME_INFO(i915)->rawclk_freq); in i9xx_hz_to_pwm()
1096 clock = KHz(i915->display.cdclk.hw.cdclk); in i9xx_hz_to_pwm()
1102 * Gen4: This value represents the period of the PWM stream in display core
1108 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i965_hz_to_pwm()
1112 clock = KHz(DISPLAY_RUNTIME_INFO(i915)->rawclk_freq); in i965_hz_to_pwm()
1114 clock = KHz(i915->display.cdclk.hw.cdclk); in i965_hz_to_pwm()
1120 * VLV: This value represents the period of the PWM stream in display core
1126 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_hz_to_pwm()
1136 clock = KHz(DISPLAY_RUNTIME_INFO(i915)->rawclk_freq); in vlv_hz_to_pwm()
1145 struct drm_i915_private *i915 = to_i915(connector->base.dev); in get_vbt_pwm_freq()
1146 u16 pwm_freq_hz = connector->panel.vbt.backlight.pwm_freq_hz; in get_vbt_pwm_freq()
1149 drm_dbg_kms(&i915->drm, in get_vbt_pwm_freq()
1150 "VBT defined backlight frequency %u Hz\n", in get_vbt_pwm_freq()
1154 drm_dbg_kms(&i915->drm, in get_vbt_pwm_freq()
1155 "default backlight frequency %u Hz\n", in get_vbt_pwm_freq()
1164 struct drm_i915_private *i915 = to_i915(connector->base.dev); in get_backlight_max_vbt()
1165 struct intel_panel *panel = &connector->panel; in get_backlight_max_vbt()
1167 u32 pwm; in get_backlight_max_vbt() local
1169 if (!panel->backlight.pwm_funcs->hz_to_pwm) { in get_backlight_max_vbt()
1170 drm_dbg_kms(&i915->drm, in get_backlight_max_vbt()
1171 "backlight frequency conversion not supported\n"); in get_backlight_max_vbt()
1175 pwm = panel->backlight.pwm_funcs->hz_to_pwm(connector, pwm_freq_hz); in get_backlight_max_vbt()
1176 if (!pwm) { in get_backlight_max_vbt()
1177 drm_dbg_kms(&i915->drm, in get_backlight_max_vbt()
1178 "backlight frequency conversion failed\n"); in get_backlight_max_vbt()
1182 return pwm; in get_backlight_max_vbt()
1190 struct drm_i915_private *i915 = to_i915(connector->base.dev); in get_backlight_min_vbt()
1191 struct intel_panel *panel = &connector->panel; in get_backlight_min_vbt()
1194 drm_WARN_ON(&i915->drm, panel->backlight.pwm_level_max == 0); in get_backlight_min_vbt()
1203 min = clamp_t(int, connector->panel.vbt.backlight.min_brightness, 0, 64); in get_backlight_min_vbt()
1204 if (min != connector->panel.vbt.backlight.min_brightness) { in get_backlight_min_vbt()
1205 drm_dbg_kms(&i915->drm, in get_backlight_min_vbt()
1206 "clamping VBT min backlight %d/255 to %d/255\n", in get_backlight_min_vbt()
1207 connector->panel.vbt.backlight.min_brightness, min); in get_backlight_min_vbt()
1211 return scale(min, 0, 255, 0, panel->backlight.pwm_level_max); in get_backlight_min_vbt()
1216 struct drm_i915_private *i915 = to_i915(connector->base.dev); in lpt_setup_backlight()
1217 struct intel_panel *panel = &connector->panel; in lpt_setup_backlight()
1225 panel->backlight.alternate_pwm_increment = alt; in lpt_setup_backlight()
1228 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; in lpt_setup_backlight()
1231 panel->backlight.pwm_level_max = pch_ctl2 >> 16; in lpt_setup_backlight()
1235 if (!panel->backlight.pwm_level_max) in lpt_setup_backlight()
1236 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in lpt_setup_backlight()
1238 if (!panel->backlight.pwm_level_max) in lpt_setup_backlight()
1239 return -ENODEV; in lpt_setup_backlight()
1241 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in lpt_setup_backlight()
1243 panel->backlight.pwm_enabled = pch_ctl1 & BLM_PCH_PWM_ENABLE; in lpt_setup_backlight()
1245 cpu_mode = panel->backlight.pwm_enabled && HAS_PCH_LPT(i915) && in lpt_setup_backlight()
1252 drm_dbg_kms(&i915->drm, in lpt_setup_backlight()
1253 "CPU backlight register was enabled, switching to PCH override\n"); in lpt_setup_backlight()
1255 /* Write converted CPU PWM value to PCH override register */ in lpt_setup_backlight()
1256 lpt_set_backlight(connector->base.state, val); in lpt_setup_backlight()
1264 drm_dbg_kms(&i915->drm, in lpt_setup_backlight()
1265 "[CONNECTOR:%d:%s] Using native PCH PWM for backlight control\n", in lpt_setup_backlight()
1266 connector->base.base.id, connector->base.name); in lpt_setup_backlight()
1273 struct drm_i915_private *i915 = to_i915(connector->base.dev); in pch_setup_backlight()
1274 struct intel_panel *panel = &connector->panel; in pch_setup_backlight()
1278 panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY; in pch_setup_backlight()
1281 panel->backlight.pwm_level_max = pch_ctl2 >> 16; in pch_setup_backlight()
1283 if (!panel->backlight.pwm_level_max) in pch_setup_backlight()
1284 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in pch_setup_backlight()
1286 if (!panel->backlight.pwm_level_max) in pch_setup_backlight()
1287 return -ENODEV; in pch_setup_backlight()
1289 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in pch_setup_backlight()
1292 panel->backlight.pwm_enabled = (cpu_ctl2 & BLM_PWM_ENABLE) && in pch_setup_backlight()
1295 drm_dbg_kms(&i915->drm, in pch_setup_backlight()
1296 "[CONNECTOR:%d:%s] Using native PCH PWM for backlight control\n", in pch_setup_backlight()
1297 connector->base.base.id, connector->base.name); in pch_setup_backlight()
1304 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i9xx_setup_backlight()
1305 struct intel_panel *panel = &connector->panel; in i9xx_setup_backlight()
1311 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; in i9xx_setup_backlight()
1314 panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV; in i9xx_setup_backlight()
1316 panel->backlight.pwm_level_max = ctl >> 17; in i9xx_setup_backlight()
1318 if (!panel->backlight.pwm_level_max) { in i9xx_setup_backlight()
1319 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in i9xx_setup_backlight()
1320 panel->backlight.pwm_level_max >>= 1; in i9xx_setup_backlight()
1323 if (!panel->backlight.pwm_level_max) in i9xx_setup_backlight()
1324 return -ENODEV; in i9xx_setup_backlight()
1326 if (panel->backlight.combination_mode) in i9xx_setup_backlight()
1327 panel->backlight.pwm_level_max *= 0xff; in i9xx_setup_backlight()
1329 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in i9xx_setup_backlight()
1333 val = clamp(val, panel->backlight.pwm_level_min, panel->backlight.pwm_level_max); in i9xx_setup_backlight()
1335 panel->backlight.pwm_enabled = val != 0; in i9xx_setup_backlight()
1337 drm_dbg_kms(&i915->drm, in i9xx_setup_backlight()
1338 "[CONNECTOR:%d:%s] Using native PWM for backlight control\n", in i9xx_setup_backlight()
1339 connector->base.base.id, connector->base.name); in i9xx_setup_backlight()
1346 struct drm_i915_private *i915 = to_i915(connector->base.dev); in i965_setup_backlight()
1347 struct intel_panel *panel = &connector->panel; in i965_setup_backlight()
1351 panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE; in i965_setup_backlight()
1352 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; in i965_setup_backlight()
1355 panel->backlight.pwm_level_max = ctl >> 16; in i965_setup_backlight()
1357 if (!panel->backlight.pwm_level_max) in i965_setup_backlight()
1358 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in i965_setup_backlight()
1360 if (!panel->backlight.pwm_level_max) in i965_setup_backlight()
1361 return -ENODEV; in i965_setup_backlight()
1363 if (panel->backlight.combination_mode) in i965_setup_backlight()
1364 panel->backlight.pwm_level_max *= 0xff; in i965_setup_backlight()
1366 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in i965_setup_backlight()
1368 panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; in i965_setup_backlight()
1370 drm_dbg_kms(&i915->drm, in i965_setup_backlight()
1371 "[CONNECTOR:%d:%s] Using native PWM for backlight control\n", in i965_setup_backlight()
1372 connector->base.base.id, connector->base.name); in i965_setup_backlight()
1379 struct drm_i915_private *i915 = to_i915(connector->base.dev); in vlv_setup_backlight()
1380 struct intel_panel *panel = &connector->panel; in vlv_setup_backlight()
1383 if (drm_WARN_ON(&i915->drm, pipe != PIPE_A && pipe != PIPE_B)) in vlv_setup_backlight()
1384 return -ENODEV; in vlv_setup_backlight()
1387 panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965; in vlv_setup_backlight()
1390 panel->backlight.pwm_level_max = ctl >> 16; in vlv_setup_backlight()
1392 if (!panel->backlight.pwm_level_max) in vlv_setup_backlight()
1393 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in vlv_setup_backlight()
1395 if (!panel->backlight.pwm_level_max) in vlv_setup_backlight()
1396 return -ENODEV; in vlv_setup_backlight()
1398 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in vlv_setup_backlight()
1400 panel->backlight.pwm_enabled = ctl2 & BLM_PWM_ENABLE; in vlv_setup_backlight()
1402 drm_dbg_kms(&i915->drm, in vlv_setup_backlight()
1403 "[CONNECTOR:%d:%s] Using native PWM for backlight control (on pipe %c)\n", in vlv_setup_backlight()
1404 connector->base.base.id, connector->base.name, pipe_name(pipe)); in vlv_setup_backlight()
1412 struct drm_i915_private *i915 = to_i915(connector->base.dev); in bxt_setup_backlight()
1413 struct intel_panel *panel = &connector->panel; in bxt_setup_backlight()
1416 panel->backlight.controller = connector->panel.vbt.backlight.controller; in bxt_setup_backlight()
1419 BXT_BLC_PWM_CTL(panel->backlight.controller)); in bxt_setup_backlight()
1422 if (panel->backlight.controller == 1) { in bxt_setup_backlight()
1424 panel->backlight.util_pin_active_low = in bxt_setup_backlight()
1428 panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; in bxt_setup_backlight()
1429 panel->backlight.pwm_level_max = in bxt_setup_backlight()
1430 intel_de_read(i915, BXT_BLC_PWM_FREQ(panel->backlight.controller)); in bxt_setup_backlight()
1432 if (!panel->backlight.pwm_level_max) in bxt_setup_backlight()
1433 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in bxt_setup_backlight()
1435 if (!panel->backlight.pwm_level_max) in bxt_setup_backlight()
1436 return -ENODEV; in bxt_setup_backlight()
1438 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in bxt_setup_backlight()
1440 panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; in bxt_setup_backlight()
1442 drm_dbg_kms(&i915->drm, in bxt_setup_backlight()
1443 "[CONNECTOR:%d:%s] Using native PWM for backlight control (controller=%d)\n", in bxt_setup_backlight()
1444 connector->base.base.id, connector->base.name, in bxt_setup_backlight()
1445 panel->backlight.controller); in bxt_setup_backlight()
1480 struct drm_i915_private *i915 = to_i915(connector->base.dev); in cnp_setup_backlight()
1481 struct intel_panel *panel = &connector->panel; in cnp_setup_backlight()
1485 * CNP has the BXT implementation of backlight, but with only one in cnp_setup_backlight()
1488 panel->backlight.controller = connector->panel.vbt.backlight.controller; in cnp_setup_backlight()
1489 if (!cnp_backlight_controller_is_valid(i915, panel->backlight.controller)) { in cnp_setup_backlight()
1490 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] Invalid backlight controller %d, assuming 0\n", in cnp_setup_backlight()
1491 connector->base.base.id, connector->base.name, in cnp_setup_backlight()
1492 panel->backlight.controller); in cnp_setup_backlight()
1493 panel->backlight.controller = 0; in cnp_setup_backlight()
1497 BXT_BLC_PWM_CTL(panel->backlight.controller)); in cnp_setup_backlight()
1499 panel->backlight.active_low_pwm = pwm_ctl & BXT_BLC_PWM_POLARITY; in cnp_setup_backlight()
1500 panel->backlight.pwm_level_max = in cnp_setup_backlight()
1501 intel_de_read(i915, BXT_BLC_PWM_FREQ(panel->backlight.controller)); in cnp_setup_backlight()
1503 if (!panel->backlight.pwm_level_max) in cnp_setup_backlight()
1504 panel->backlight.pwm_level_max = get_backlight_max_vbt(connector); in cnp_setup_backlight()
1506 if (!panel->backlight.pwm_level_max) in cnp_setup_backlight()
1507 return -ENODEV; in cnp_setup_backlight()
1509 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in cnp_setup_backlight()
1511 panel->backlight.pwm_enabled = pwm_ctl & BXT_BLC_PWM_ENABLE; in cnp_setup_backlight()
1513 drm_dbg_kms(&i915->drm, in cnp_setup_backlight()
1514 "[CONNECTOR:%d:%s] Using native PCH PWM for backlight control (controller=%d)\n", in cnp_setup_backlight()
1515 connector->base.base.id, connector->base.name, in cnp_setup_backlight()
1516 panel->backlight.controller); in cnp_setup_backlight()
1524 struct drm_i915_private *i915 = to_i915(connector->base.dev); in ext_pwm_setup_backlight()
1525 struct intel_panel *panel = &connector->panel; in ext_pwm_setup_backlight()
1529 /* Get the right PWM chip for DSI backlight according to VBT */ in ext_pwm_setup_backlight()
1530 if (connector->panel.vbt.dsi.config->pwm_blc == PPS_BLC_PMIC) { in ext_pwm_setup_backlight()
1531 panel->backlight.pwm = pwm_get(i915->drm.dev, "pwm_pmic_backlight"); in ext_pwm_setup_backlight()
1534 panel->backlight.pwm = pwm_get(i915->drm.dev, "pwm_soc_backlight"); in ext_pwm_setup_backlight()
1538 if (IS_ERR(panel->backlight.pwm)) { in ext_pwm_setup_backlight()
1539 drm_err(&i915->drm, "[CONNECTOR:%d:%s] Failed to get the %s PWM chip\n", in ext_pwm_setup_backlight()
1540 connector->base.base.id, connector->base.name, desc); in ext_pwm_setup_backlight()
1541 panel->backlight.pwm = NULL; in ext_pwm_setup_backlight()
1542 return -ENODEV; in ext_pwm_setup_backlight()
1545 panel->backlight.pwm_level_max = 100; /* 100% */ in ext_pwm_setup_backlight()
1546 panel->backlight.pwm_level_min = get_backlight_min_vbt(connector); in ext_pwm_setup_backlight()
1548 if (pwm_is_enabled(panel->backlight.pwm)) { in ext_pwm_setup_backlight()
1549 /* PWM is already enabled, use existing settings */ in ext_pwm_setup_backlight()
1550 pwm_get_state(panel->backlight.pwm, &panel->backlight.pwm_state); in ext_pwm_setup_backlight()
1552 level = pwm_get_relative_duty_cycle(&panel->backlight.pwm_state, in ext_pwm_setup_backlight()
1555 panel->backlight.pwm_enabled = true; in ext_pwm_setup_backlight()
1557 …drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] PWM already enabled at freq %ld, VBT freq %d, level %d\… in ext_pwm_setup_backlight()
1558 connector->base.base.id, connector->base.name, in ext_pwm_setup_backlight()
1559 NSEC_PER_SEC / (unsigned long)panel->backlight.pwm_state.period, in ext_pwm_setup_backlight()
1563 panel->backlight.pwm_state.period = in ext_pwm_setup_backlight()
1567 drm_dbg_kms(&i915->drm, in ext_pwm_setup_backlight()
1568 "[CONNECTOR:%d:%s] Using %s PWM for backlight control\n", in ext_pwm_setup_backlight()
1569 connector->base.base.id, connector->base.name, desc); in ext_pwm_setup_backlight()
1576 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_pwm_set_backlight()
1577 struct intel_panel *panel = &connector->panel; in intel_pwm_set_backlight()
1579 panel->backlight.pwm_funcs->set(conn_state, in intel_pwm_set_backlight()
1585 struct intel_panel *panel = &connector->panel; in intel_pwm_get_backlight()
1588 panel->backlight.pwm_funcs->get(connector, pipe)); in intel_pwm_get_backlight()
1594 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_pwm_enable_backlight()
1595 struct intel_panel *panel = &connector->panel; in intel_pwm_enable_backlight()
1597 panel->backlight.pwm_funcs->enable(crtc_state, conn_state, in intel_pwm_enable_backlight()
1603 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_pwm_disable_backlight()
1604 struct intel_panel *panel = &connector->panel; in intel_pwm_disable_backlight()
1606 panel->backlight.pwm_funcs->disable(conn_state, in intel_pwm_disable_backlight()
1612 struct intel_panel *panel = &connector->panel; in intel_pwm_setup_backlight()
1615 ret = panel->backlight.pwm_funcs->setup(connector, pipe); in intel_pwm_setup_backlight()
1619 panel->backlight.min = panel->backlight.pwm_level_min; in intel_pwm_setup_backlight()
1620 panel->backlight.max = panel->backlight.pwm_level_max; in intel_pwm_setup_backlight()
1621 panel->backlight.level = intel_pwm_get_backlight(connector, pipe); in intel_pwm_setup_backlight()
1622 panel->backlight.enabled = panel->backlight.pwm_enabled; in intel_pwm_setup_backlight()
1632 struct intel_connector *connector = to_intel_connector(conn_state->connector); in intel_backlight_update()
1633 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_update()
1634 struct intel_panel *panel = &connector->panel; in intel_backlight_update()
1636 if (!panel->backlight.present) in intel_backlight_update()
1639 mutex_lock(&i915->display.backlight.lock); in intel_backlight_update()
1640 if (!panel->backlight.enabled) in intel_backlight_update()
1643 mutex_unlock(&i915->display.backlight.lock); in intel_backlight_update()
1649 struct intel_panel *panel = &connector->panel; in intel_backlight_setup()
1652 if (!connector->panel.vbt.backlight.present) { in intel_backlight_setup()
1654 drm_dbg_kms(display->drm, in intel_backlight_setup()
1655 "[CONNECTOR:%d:%s] no backlight present per VBT, but present per quirk\n", in intel_backlight_setup()
1656 connector->base.base.id, connector->base.name); in intel_backlight_setup()
1658 drm_dbg_kms(display->drm, in intel_backlight_setup()
1659 "[CONNECTOR:%d:%s] no backlight present per VBT\n", in intel_backlight_setup()
1660 connector->base.base.id, connector->base.name); in intel_backlight_setup()
1666 if (drm_WARN_ON(display->drm, !panel->backlight.funcs)) in intel_backlight_setup()
1667 return -ENODEV; in intel_backlight_setup()
1670 mutex_lock(&display->backlight.lock); in intel_backlight_setup()
1671 ret = panel->backlight.funcs->setup(connector, pipe); in intel_backlight_setup()
1672 mutex_unlock(&display->backlight.lock); in intel_backlight_setup()
1675 drm_dbg_kms(display->drm, in intel_backlight_setup()
1676 "[CONNECTOR:%d:%s] failed to setup backlight\n", in intel_backlight_setup()
1677 connector->base.base.id, connector->base.name); in intel_backlight_setup()
1681 panel->backlight.present = true; in intel_backlight_setup()
1683 drm_dbg_kms(display->drm, in intel_backlight_setup()
1684 "[CONNECTOR:%d:%s] backlight initialized, %s, brightness %u/%u\n", in intel_backlight_setup()
1685 connector->base.base.id, connector->base.name, in intel_backlight_setup()
1686 str_enabled_disabled(panel->backlight.enabled), in intel_backlight_setup()
1687 panel->backlight.level, panel->backlight.max); in intel_backlight_setup()
1694 /* dispose of the pwm */ in intel_backlight_destroy()
1695 if (panel->backlight.pwm) in intel_backlight_destroy()
1696 pwm_put(panel->backlight.pwm); in intel_backlight_destroy()
1698 panel->backlight.present = false; in intel_backlight_destroy()
1789 /* Set up chip specific backlight functions */
1794 struct drm_i915_private *i915 = to_i915(connector->base.dev); in intel_backlight_init_funcs()
1796 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI && in intel_backlight_init_funcs()
1801 panel->backlight.pwm_funcs = &bxt_pwm_funcs; in intel_backlight_init_funcs()
1803 panel->backlight.pwm_funcs = &cnp_pwm_funcs; in intel_backlight_init_funcs()
1806 panel->backlight.pwm_funcs = &lpt_pwm_funcs; in intel_backlight_init_funcs()
1808 panel->backlight.pwm_funcs = &spt_pwm_funcs; in intel_backlight_init_funcs()
1810 panel->backlight.pwm_funcs = &pch_pwm_funcs; in intel_backlight_init_funcs()
1812 if (connector->base.connector_type == DRM_MODE_CONNECTOR_DSI) { in intel_backlight_init_funcs()
1813 panel->backlight.pwm_funcs = &ext_pwm_funcs; in intel_backlight_init_funcs()
1815 panel->backlight.pwm_funcs = &vlv_pwm_funcs; in intel_backlight_init_funcs()
1818 panel->backlight.pwm_funcs = &i965_pwm_funcs; in intel_backlight_init_funcs()
1820 panel->backlight.pwm_funcs = &i9xx_pwm_funcs; in intel_backlight_init_funcs()
1823 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP) { in intel_backlight_init_funcs()
1827 if (!intel_has_quirk(&i915->display, QUIRK_NO_PPS_BACKLIGHT_POWER_HOOK)) in intel_backlight_init_funcs()
1828 connector->panel.backlight.power = intel_pps_backlight_power; in intel_backlight_init_funcs()
1831 /* We're using a standard PWM backlight interface */ in intel_backlight_init_funcs()
1832 panel->backlight.funcs = &pwm_bl_funcs; in intel_backlight_init_funcs()