Subversion Repositories Kolibri OS

Rev

Rev 5097 | Rev 6084 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5097 Rev 5354
Line 417... Line 417...
417
 
417
 
418
	/* defensive */
418
	/* defensive */
Line 419... Line 419...
419
	source_val = clamp(source_val, source_min, source_max);
419
	source_val = clamp(source_val, source_min, source_max);
420
 
420
 
421
	/* avoid overflows */
-
 
422
	target_val = (uint64_t)(source_val - source_min) *
421
	/* avoid overflows */
423
		(target_max - target_min);
422
	target_val = DIV_ROUND_CLOSEST_ULL((uint64_t)(source_val - source_min) *
Line 424... Line 423...
424
	do_div(target_val, source_max - source_min);
423
			(target_max - target_min), source_max - source_min);
425
	target_val += target_min;
424
	target_val += target_min;
Line 520... Line 519...
520
 
519
 
521
static u32 _vlv_get_backlight(struct drm_device *dev, enum pipe pipe)
520
static u32 _vlv_get_backlight(struct drm_device *dev, enum pipe pipe)
522
{
521
{
Line -... Line 522...
-
 
522
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
523
 
-
 
524
	if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
523
	struct drm_i915_private *dev_priv = dev->dev_private;
525
		return 0;
524
 
526
 
Line 525... Line 527...
525
	return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK;
527
	return I915_READ(VLV_BLC_PWM_CTL(pipe)) & BACKLIGHT_DUTY_CYCLE_MASK;
526
}
528
}
Line 535... Line 537...
535
 
537
 
536
static u32 intel_panel_get_backlight(struct intel_connector *connector)
538
static u32 intel_panel_get_backlight(struct intel_connector *connector)
537
{
539
{
538
	struct drm_device *dev = connector->base.dev;
540
	struct drm_device *dev = connector->base.dev;
-
 
541
	struct drm_i915_private *dev_priv = dev->dev_private;
539
	struct drm_i915_private *dev_priv = dev->dev_private;
542
	struct intel_panel *panel = &connector->panel;
540
	u32 val;
-
 
Line 541... Line 543...
541
	unsigned long flags;
543
	u32 val = 0;
Line -... Line 544...
-
 
544
 
542
 
545
	mutex_lock(&dev_priv->backlight_lock);
543
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
546
 
-
 
547
	if (panel->backlight.enabled) {
Line 544... Line 548...
544
 
548
	val = dev_priv->display.get_backlight(connector);
Line 545... Line 549...
545
	val = dev_priv->display.get_backlight(connector);
549
	val = intel_panel_compute_brightness(connector, val);
546
	val = intel_panel_compute_brightness(connector, val);
550
	}
547
 
551
 
Line 602... Line 606...
602
	struct drm_device *dev = connector->base.dev;
606
	struct drm_device *dev = connector->base.dev;
603
	struct drm_i915_private *dev_priv = dev->dev_private;
607
	struct drm_i915_private *dev_priv = dev->dev_private;
604
	enum pipe pipe = intel_get_pipe_from_connector(connector);
608
	enum pipe pipe = intel_get_pipe_from_connector(connector);
605
	u32 tmp;
609
	u32 tmp;
Line -... Line 610...
-
 
610
 
-
 
611
	if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
-
 
612
		return;
606
 
613
 
607
	tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK;
614
	tmp = I915_READ(VLV_BLC_PWM_CTL(pipe)) & ~BACKLIGHT_DUTY_CYCLE_MASK;
608
	I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
615
	I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level);
Line 609... Line 616...
609
}
616
}
Line 625... Line 632...
625
				      u32 user_level, u32 user_max)
632
				      u32 user_level, u32 user_max)
626
{
633
{
627
	struct drm_device *dev = connector->base.dev;
634
	struct drm_device *dev = connector->base.dev;
628
	struct drm_i915_private *dev_priv = dev->dev_private;
635
	struct drm_i915_private *dev_priv = dev->dev_private;
629
	struct intel_panel *panel = &connector->panel;
636
	struct intel_panel *panel = &connector->panel;
630
	enum pipe pipe = intel_get_pipe_from_connector(connector);
-
 
631
	u32 hw_level;
637
	u32 hw_level;
632
	unsigned long flags;
-
 
Line 633... Line 638...
633
 
638
 
634
	if (!panel->backlight.present || pipe == INVALID_PIPE)
639
	if (!panel->backlight.present)
Line 635... Line 640...
635
		return;
640
		return;
Line 636... Line 641...
636
 
641
 
Line 637... Line 642...
637
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
642
	mutex_lock(&dev_priv->backlight_lock);
638
 
643
 
Line 639... Line 644...
639
	WARN_ON(panel->backlight.max == 0);
644
	WARN_ON(panel->backlight.max == 0);
640
 
645
 
Line 641... Line 646...
641
	hw_level = scale_user_to_hw(connector, user_level, user_max);
646
	hw_level = scale_user_to_hw(connector, user_level, user_max);
642
	panel->backlight.level = hw_level;
647
	panel->backlight.level = hw_level;
Line 643... Line 648...
643
 
648
 
644
	if (panel->backlight.enabled)
649
	if (panel->backlight.enabled)
645
		intel_panel_actually_set_backlight(connector, hw_level);
650
		intel_panel_actually_set_backlight(connector, hw_level);
Line 656... Line 661...
656
	struct drm_device *dev = connector->base.dev;
661
	struct drm_device *dev = connector->base.dev;
657
	struct drm_i915_private *dev_priv = dev->dev_private;
662
	struct drm_i915_private *dev_priv = dev->dev_private;
658
	struct intel_panel *panel = &connector->panel;
663
	struct intel_panel *panel = &connector->panel;
659
	enum pipe pipe = intel_get_pipe_from_connector(connector);
664
	enum pipe pipe = intel_get_pipe_from_connector(connector);
660
	u32 hw_level;
665
	u32 hw_level;
661
	unsigned long flags;
-
 
Line -... Line 666...
-
 
666
 
-
 
667
	/*
-
 
668
	 * INVALID_PIPE may occur during driver init because
-
 
669
	 * connection_mutex isn't held across the entire backlight
-
 
670
	 * setup + modeset readout, and the BIOS can issue the
-
 
671
	 * requests at any time.
662
 
672
	 */
663
	if (!panel->backlight.present || pipe == INVALID_PIPE)
673
	if (!panel->backlight.present || pipe == INVALID_PIPE)
Line 664... Line 674...
664
		return;
674
		return;
Line 665... Line 675...
665
 
675
 
Line 666... Line 676...
666
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
676
	mutex_lock(&dev_priv->backlight_lock);
667
 
677
 
Line 668... Line 678...
668
	WARN_ON(panel->backlight.max == 0);
678
	WARN_ON(panel->backlight.max == 0);
669
 
679
 
Line 670... Line 680...
670
	hw_level = clamp_user_to_hw(connector, user_level, user_max);
680
	hw_level = clamp_user_to_hw(connector, user_level, user_max);
671
	panel->backlight.level = hw_level;
681
	panel->backlight.level = hw_level;
Line 672... Line 682...
672
 
682
 
673
 
683
 
674
	if (panel->backlight.enabled)
684
	if (panel->backlight.enabled)
Line 714... Line 724...
714
	struct drm_device *dev = connector->base.dev;
724
	struct drm_device *dev = connector->base.dev;
715
	struct drm_i915_private *dev_priv = dev->dev_private;
725
	struct drm_i915_private *dev_priv = dev->dev_private;
716
	enum pipe pipe = intel_get_pipe_from_connector(connector);
726
	enum pipe pipe = intel_get_pipe_from_connector(connector);
717
	u32 tmp;
727
	u32 tmp;
Line -... Line 728...
-
 
728
 
-
 
729
	if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
-
 
730
		return;
718
 
731
 
Line 719... Line 732...
719
	intel_panel_actually_set_backlight(connector, 0);
732
	intel_panel_actually_set_backlight(connector, 0);
720
 
733
 
721
	tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe));
734
	tmp = I915_READ(VLV_BLC_PWM_CTL2(pipe));
Line 725... Line 738...
725
void intel_panel_disable_backlight(struct intel_connector *connector)
738
void intel_panel_disable_backlight(struct intel_connector *connector)
726
{
739
{
727
	struct drm_device *dev = connector->base.dev;
740
	struct drm_device *dev = connector->base.dev;
728
	struct drm_i915_private *dev_priv = dev->dev_private;
741
	struct drm_i915_private *dev_priv = dev->dev_private;
729
	struct intel_panel *panel = &connector->panel;
742
	struct intel_panel *panel = &connector->panel;
730
	enum pipe pipe = intel_get_pipe_from_connector(connector);
-
 
731
	unsigned long flags;
-
 
Line 732... Line 743...
732
 
743
 
733
	if (!panel->backlight.present || pipe == INVALID_PIPE)
744
	if (!panel->backlight.present)
Line 734... Line 745...
734
		return;
745
		return;
735
 
746
 
736
	/*
747
	/*
Line 742... Line 753...
742
	if (dev->switch_power_state == DRM_SWITCH_POWER_CHANGING) {
753
	if (dev->switch_power_state == DRM_SWITCH_POWER_CHANGING) {
743
		DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
754
		DRM_DEBUG_DRIVER("Skipping backlight disable on vga switch\n");
744
		return;
755
		return;
745
	}
756
	}
Line 746... Line 757...
746
 
757
 
Line 747... Line 758...
747
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
758
	mutex_lock(&dev_priv->backlight_lock);
748
 
759
 
Line 749... Line 760...
749
	panel->backlight.enabled = false;
760
	panel->backlight.enabled = false;
750
	dev_priv->display.disable_backlight(connector);
761
	dev_priv->display.disable_backlight(connector);
Line 751... Line 762...
751
 
762
 
752
	spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
763
	mutex_unlock(&dev_priv->backlight_lock);
753
}
764
}
Line 771... Line 782...
771
 
782
 
772
	pch_ctl1 = 0;
783
	pch_ctl1 = 0;
773
	if (panel->backlight.active_low_pwm)
784
	if (panel->backlight.active_low_pwm)
Line 774... Line 785...
774
		pch_ctl1 |= BLM_PCH_POLARITY;
785
		pch_ctl1 |= BLM_PCH_POLARITY;
-
 
786
 
775
 
787
	/* After LPT, override is the default. */
Line 776... Line 788...
776
	/* BDW always uses the pch pwm controls. */
788
	if (HAS_PCH_LPT(dev_priv))
777
	pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE;
789
	pch_ctl1 |= BLM_PCH_OVERRIDE_ENABLE;
778
 
790
 
Line 901... Line 913...
901
	struct drm_i915_private *dev_priv = dev->dev_private;
913
	struct drm_i915_private *dev_priv = dev->dev_private;
902
	struct intel_panel *panel = &connector->panel;
914
	struct intel_panel *panel = &connector->panel;
903
	enum pipe pipe = intel_get_pipe_from_connector(connector);
915
	enum pipe pipe = intel_get_pipe_from_connector(connector);
904
	u32 ctl, ctl2;
916
	u32 ctl, ctl2;
Line -... Line 917...
-
 
917
 
-
 
918
	if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
-
 
919
		return;
905
 
920
 
906
	ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
921
	ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
907
	if (ctl2 & BLM_PWM_ENABLE) {
922
	if (ctl2 & BLM_PWM_ENABLE) {
908
		DRM_DEBUG_KMS("backlight already enabled\n");
923
		DRM_DEBUG_KMS("backlight already enabled\n");
909
		ctl2 &= ~BLM_PWM_ENABLE;
924
		ctl2 &= ~BLM_PWM_ENABLE;
Line 928... Line 943...
928
{
943
{
929
	struct drm_device *dev = connector->base.dev;
944
	struct drm_device *dev = connector->base.dev;
930
	struct drm_i915_private *dev_priv = dev->dev_private;
945
	struct drm_i915_private *dev_priv = dev->dev_private;
931
	struct intel_panel *panel = &connector->panel;
946
	struct intel_panel *panel = &connector->panel;
932
	enum pipe pipe = intel_get_pipe_from_connector(connector);
947
	enum pipe pipe = intel_get_pipe_from_connector(connector);
933
	unsigned long flags;
-
 
Line 934... Line 948...
934
 
948
 
935
	if (!panel->backlight.present || pipe == INVALID_PIPE)
949
	if (!panel->backlight.present)
Line 936... Line 950...
936
		return;
950
		return;
Line 937... Line 951...
937
 
951
 
Line 938... Line 952...
938
	DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
952
	DRM_DEBUG_KMS("pipe %c\n", pipe_name(pipe));
Line 939... Line 953...
939
 
953
 
940
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
954
	mutex_lock(&dev_priv->backlight_lock);
941
 
955
 
Line 942... Line 956...
942
	WARN_ON(panel->backlight.max == 0);
956
	WARN_ON(panel->backlight.max == 0);
943
 
957
 
Line 944... Line 958...
944
	if (panel->backlight.level == 0) {
958
	if (panel->backlight.level == 0) {
945
		panel->backlight.level = panel->backlight.max;
959
		panel->backlight.level = panel->backlight.max;
Line 946... Line 960...
946
	}
960
	}
947
 
961
 
948
	dev_priv->display.enable_backlight(connector);
962
	dev_priv->display.enable_backlight(connector);
949
	panel->backlight.enabled = true;
963
	panel->backlight.enabled = true;
-
 
964
 
950
 
965
	mutex_unlock(&dev_priv->backlight_lock);
Line 951... Line 966...
951
	spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
966
}
952
}
967
 
953
 
968
#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
Line 997... Line 1012...
997
	struct backlight_properties props;
1012
	struct backlight_properties props;
Line 998... Line 1013...
998
 
1013
 
999
	if (WARN_ON(panel->backlight.device))
1014
	if (WARN_ON(panel->backlight.device))
Line -... Line 1015...
-
 
1015
		return -ENODEV;
-
 
1016
 
-
 
1017
	if (!panel->backlight.present)
1000
		return -ENODEV;
1018
		return 0;
Line 1001... Line 1019...
1001
 
1019
 
1002
	WARN_ON(panel->backlight.max == 0);
1020
	WARN_ON(panel->backlight.max == 0);
Line 1011... Line 1029...
1011
	props.max_brightness = panel->backlight.max;
1029
	props.max_brightness = panel->backlight.max;
1012
	props.brightness = scale_hw_to_user(connector,
1030
	props.brightness = scale_hw_to_user(connector,
1013
					    panel->backlight.level,
1031
					    panel->backlight.level,
1014
					    props.max_brightness);
1032
					    props.max_brightness);
Line -... Line 1033...
-
 
1033
 
-
 
1034
	if (panel->backlight.enabled)
-
 
1035
		props.power = FB_BLANK_UNBLANK;
-
 
1036
	else
-
 
1037
		props.power = FB_BLANK_POWERDOWN;
1015
 
1038
 
1016
	/*
1039
	/*
1017
	 * Note: using the same name independent of the connector prevents
1040
	 * Note: using the same name independent of the connector prevents
1018
	 * registration of multiple backlight devices in the driver.
1041
	 * registration of multiple backlight devices in the driver.
1019
	 */
1042
	 */
Line 1027... Line 1050...
1027
		DRM_ERROR("Failed to register backlight: %ld\n",
1050
		DRM_ERROR("Failed to register backlight: %ld\n",
1028
			  PTR_ERR(panel->backlight.device));
1051
			  PTR_ERR(panel->backlight.device));
1029
		panel->backlight.device = NULL;
1052
		panel->backlight.device = NULL;
1030
		return -ENODEV;
1053
		return -ENODEV;
1031
	}
1054
	}
-
 
1055
 
-
 
1056
	DRM_DEBUG_KMS("Connector %s backlight sysfs interface registered\n",
-
 
1057
		      connector->base.name);
-
 
1058
 
1032
	return 0;
1059
	return 0;
1033
}
1060
}
Line 1034... Line 1061...
1034
 
1061
 
1035
static void intel_backlight_device_unregister(struct intel_connector *connector)
1062
static void intel_backlight_device_unregister(struct intel_connector *connector)
Line 1060... Line 1087...
1060
static u32 get_backlight_min_vbt(struct intel_connector *connector)
1087
static u32 get_backlight_min_vbt(struct intel_connector *connector)
1061
{
1088
{
1062
	struct drm_device *dev = connector->base.dev;
1089
	struct drm_device *dev = connector->base.dev;
1063
	struct drm_i915_private *dev_priv = dev->dev_private;
1090
	struct drm_i915_private *dev_priv = dev->dev_private;
1064
	struct intel_panel *panel = &connector->panel;
1091
	struct intel_panel *panel = &connector->panel;
-
 
1092
	int min;
Line 1065... Line 1093...
1065
 
1093
 
Line -... Line 1094...
-
 
1094
	WARN_ON(panel->backlight.max == 0);
-
 
1095
 
-
 
1096
	/*
-
 
1097
	 * XXX: If the vbt value is 255, it makes min equal to max, which leads
-
 
1098
	 * to problems. There are such machines out there. Either our
-
 
1099
	 * interpretation is wrong or the vbt has bogus data. Or both. Safeguard
-
 
1100
	 * against this by letting the minimum be at most (arbitrarily chosen)
-
 
1101
	 * 25% of the max.
-
 
1102
	 */
-
 
1103
	min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64);
-
 
1104
	if (min != dev_priv->vbt.backlight.min_brightness) {
-
 
1105
		DRM_DEBUG_KMS("clamping VBT min backlight %d/255 to %d/255\n",
-
 
1106
			      dev_priv->vbt.backlight.min_brightness, min);
1066
	WARN_ON(panel->backlight.max == 0);
1107
	}
1067
 
-
 
1068
	/* vbt value is a coefficient in range [0..255] */
1108
 
1069
	return scale(dev_priv->vbt.backlight.min_brightness, 0, 255,
1109
	/* vbt value is a coefficient in range [0..255] */
Line 1070... Line 1110...
1070
		     0, panel->backlight.max);
1110
	return scale(min, 0, 255, 0, panel->backlight.max);
1071
}
1111
}
1072
 
1112
 
1073
static int bdw_setup_backlight(struct intel_connector *connector)
1113
static int bdw_setup_backlight(struct intel_connector *connector, enum pipe unused)
1074
{
1114
{
1075
	struct drm_device *dev = connector->base.dev;
1115
	struct drm_device *dev = connector->base.dev;
Line 1094... Line 1134...
1094
		panel->backlight.level != 0;
1134
		panel->backlight.level != 0;
Line 1095... Line 1135...
1095
 
1135
 
1096
	return 0;
1136
	return 0;
Line 1097... Line 1137...
1097
}
1137
}
1098
 
1138
 
1099
static int pch_setup_backlight(struct intel_connector *connector)
1139
static int pch_setup_backlight(struct intel_connector *connector, enum pipe unused)
1100
{
1140
{
1101
	struct drm_device *dev = connector->base.dev;
1141
	struct drm_device *dev = connector->base.dev;
1102
	struct drm_i915_private *dev_priv = dev->dev_private;
1142
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 1121... Line 1161...
1121
		(pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0;
1161
		(pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0;
Line 1122... Line 1162...
1122
 
1162
 
1123
	return 0;
1163
	return 0;
Line 1124... Line 1164...
1124
}
1164
}
1125
 
1165
 
1126
static int i9xx_setup_backlight(struct intel_connector *connector)
1166
static int i9xx_setup_backlight(struct intel_connector *connector, enum pipe unused)
1127
{
1167
{
1128
	struct drm_device *dev = connector->base.dev;
1168
	struct drm_device *dev = connector->base.dev;
1129
	struct drm_i915_private *dev_priv = dev->dev_private;
1169
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 1153... Line 1193...
1153
	panel->backlight.enabled = panel->backlight.level != 0;
1193
	panel->backlight.enabled = panel->backlight.level != 0;
Line 1154... Line 1194...
1154
 
1194
 
1155
	return 0;
1195
	return 0;
Line 1156... Line 1196...
1156
}
1196
}
1157
 
1197
 
1158
static int i965_setup_backlight(struct intel_connector *connector)
1198
static int i965_setup_backlight(struct intel_connector *connector, enum pipe unused)
1159
{
1199
{
1160
	struct drm_device *dev = connector->base.dev;
1200
	struct drm_device *dev = connector->base.dev;
1161
	struct drm_i915_private *dev_priv = dev->dev_private;
1201
	struct drm_i915_private *dev_priv = dev->dev_private;
Line 1183... Line 1223...
1183
		panel->backlight.level != 0;
1223
		panel->backlight.level != 0;
Line 1184... Line 1224...
1184
 
1224
 
1185
	return 0;
1225
	return 0;
Line 1186... Line 1226...
1186
}
1226
}
1187
 
1227
 
1188
static int vlv_setup_backlight(struct intel_connector *connector)
1228
static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe)
1189
{
1229
{
1190
	struct drm_device *dev = connector->base.dev;
1230
	struct drm_device *dev = connector->base.dev;
1191
	struct drm_i915_private *dev_priv = dev->dev_private;
1231
	struct drm_i915_private *dev_priv = dev->dev_private;
1192
	struct intel_panel *panel = &connector->panel;
1232
	struct intel_panel *panel = &connector->panel;
Line 1193... Line 1233...
1193
	enum pipe pipe;
1233
	enum pipe p;
1194
	u32 ctl, ctl2, val;
1234
	u32 ctl, ctl2, val;
Line 1195... Line 1235...
1195
 
1235
 
1196
	for_each_pipe(pipe) {
1236
	for_each_pipe(dev_priv, p) {
1197
		u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(pipe));
1237
		u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(p));
Line 1198... Line 1238...
1198
 
1238
 
1199
		/* Skip if the modulation freq is already set */
1239
		/* Skip if the modulation freq is already set */
1200
		if (cur_val & ~BACKLIGHT_DUTY_CYCLE_MASK)
1240
		if (cur_val & ~BACKLIGHT_DUTY_CYCLE_MASK)
1201
			continue;
1241
			continue;
Line -... Line 1242...
-
 
1242
 
-
 
1243
		cur_val &= BACKLIGHT_DUTY_CYCLE_MASK;
-
 
1244
		I915_WRITE(VLV_BLC_PWM_CTL(p), (0xf42 << 16) |
1202
 
1245
			   cur_val);
1203
		cur_val &= BACKLIGHT_DUTY_CYCLE_MASK;
1246
	}
Line 1204... Line 1247...
1204
		I915_WRITE(VLV_BLC_PWM_CTL(pipe), (0xf42 << 16) |
1247
 
1205
			   cur_val);
1248
	if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
1206
	}
1249
		return -ENODEV;
1207
 
1250
 
Line 1208... Line 1251...
1208
	ctl2 = I915_READ(VLV_BLC_PWM_CTL2(PIPE_A));
1251
	ctl2 = I915_READ(VLV_BLC_PWM_CTL2(pipe));
Line 1209... Line 1252...
1209
	panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1252
	panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
1210
 
1253
 
Line 1211... Line 1254...
1211
	ctl = I915_READ(VLV_BLC_PWM_CTL(PIPE_A));
1254
	ctl = I915_READ(VLV_BLC_PWM_CTL(pipe));
1212
	panel->backlight.max = ctl >> 16;
1255
	panel->backlight.max = ctl >> 16;
Line 1213... Line 1256...
1213
	if (!panel->backlight.max)
1256
	if (!panel->backlight.max)
1214
		return -ENODEV;
1257
		return -ENODEV;
Line 1215... Line 1258...
1215
 
1258
 
1216
	panel->backlight.min = get_backlight_min_vbt(connector);
1259
	panel->backlight.min = get_backlight_min_vbt(connector);
1217
 
1260
 
1218
	val = _vlv_get_backlight(dev, PIPE_A);
1261
	val = _vlv_get_backlight(dev, pipe);
1219
	panel->backlight.level = intel_panel_compute_brightness(connector, val);
1262
	panel->backlight.level = intel_panel_compute_brightness(connector, val);
1220
 
1263
 
1221
	panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
-
 
1222
		panel->backlight.level != 0;
1264
	panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
Line 1223... Line 1265...
1223
 
1265
		panel->backlight.level != 0;
1224
	return 0;
1266
 
1225
}
1267
	return 0;
Line 1241... Line 1283...
1241
		return 0;
1283
		return 0;
1242
	}
1284
	}
1243
	}
1285
	}
Line 1244... Line 1286...
1244
 
1286
 
1245
	/* set level and max in panel struct */
1287
	/* set level and max in panel struct */
1246
	spin_lock_irqsave(&dev_priv->backlight_lock, flags);
1288
	mutex_lock(&dev_priv->backlight_lock);
1247
	ret = dev_priv->display.setup_backlight(intel_connector);
1289
	ret = dev_priv->display.setup_backlight(intel_connector, pipe);
Line 1248... Line 1290...
1248
	spin_unlock_irqrestore(&dev_priv->backlight_lock, flags);
1290
	mutex_unlock(&dev_priv->backlight_lock);
1249
 
1291
 
1250
	if (ret) {
1292
	if (ret) {
1251
		DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
1293
		DRM_DEBUG_KMS("failed to setup backlight for connector %s\n",
1252
			      connector->name);
1294
			      connector->name);
Line 1253... Line -...
1253
		return ret;
-
 
1254
	}
-
 
1255
 
1295
		return ret;
Line 1256... Line 1296...
1256
	intel_backlight_device_register(intel_connector);
1296
	}
1257
 
1297
 
1258
	panel->backlight.present = true;
1298
	panel->backlight.present = true;
1259
 
1299
 
1260
	DRM_DEBUG_KMS("backlight initialized, %s, brightness %u/%u, "
-
 
Line 1261... Line 1300...
1261
		      "sysfs interface %sregistered\n",
1300
	DRM_DEBUG_KMS("Connector %s backlight initialized, %s, brightness %u/%u\n",
1262
		      panel->backlight.enabled ? "enabled" : "disabled",
1301
		      connector->name,
Line 1263... Line 1302...
1263
		      panel->backlight.level, panel->backlight.max,
1302
		      panel->backlight.enabled ? "enabled" : "disabled",
1264
		      panel->backlight.device ? "" : "not ");
1303
		      panel->backlight.level, panel->backlight.max);
1265
 
1304
 
1266
	return 0;
1305
	return 0;
Line 1267... Line 1306...
1267
}
1306
}
1268
 
-
 
1269
void intel_panel_destroy_backlight(struct drm_connector *connector)
1307
 
Line 1270... Line 1308...
1270
{
1308
void intel_panel_destroy_backlight(struct drm_connector *connector)
1271
	struct intel_connector *intel_connector = to_intel_connector(connector);
1309
{
1272
	struct intel_panel *panel = &intel_connector->panel;
1310
	struct intel_connector *intel_connector = to_intel_connector(connector);
1273
 
1311
	struct intel_panel *panel = &intel_connector->panel;
Line 1274... Line 1312...
1274
	panel->backlight.present = false;
1312
 
1275
	intel_backlight_device_unregister(intel_connector);
1313
	panel->backlight.present = false;
1276
}
1314
}
1277
 
1315
 
1278
/* Set up chip specific backlight functions */
1316
/* Set up chip specific backlight functions */
1279
void intel_panel_init_backlight_funcs(struct drm_device *dev)
1317
void intel_panel_init_backlight_funcs(struct drm_device *dev)
Line 1333... Line 1371...
1333
 
1371
 
1334
	if (panel->downclock_mode)
1372
	if (panel->downclock_mode)
1335
		drm_mode_destroy(intel_connector->base.dev,
1373
		drm_mode_destroy(intel_connector->base.dev,
1336
				panel->downclock_mode);
1374
				panel->downclock_mode);
-
 
1375
}
-
 
1376
 
-
 
1377
void intel_backlight_register(struct drm_device *dev)
-
 
1378
{
-
 
1379
	struct intel_connector *connector;
-
 
1380
 
-
 
1381
	list_for_each_entry(connector, &dev->mode_config.connector_list, base.head)
-
 
1382
		intel_backlight_device_register(connector);
-
 
1383
}
-
 
1384
 
-
 
1385
void intel_backlight_unregister(struct drm_device *dev)
-
 
1386
{
-
 
1387
	struct intel_connector *connector;
-
 
1388
 
-
 
1389
	list_for_each_entry(connector, &dev->mode_config.connector_list, base.head)
-
 
1390
		intel_backlight_device_unregister(connector);