diff mbox

[1/3] drm/i915: Encapsulate the pwm_device in a pwm_info structure

Message ID 1496222871-12996-2-git-send-email-shobhit.kumar@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kumar, Shobhit May 31, 2017, 9:27 a.m. UTC
pwm_info helps in encapsulating the PWM period_ns values and will form
basis of adding new pwm devices which can then be genrically used by
initializing proper pwm_info structure in the backlight setup call.

v2: Rebase on latest code. Add BZ details

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96571
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90075
Cc: cbrookes@gmail.com
Cc: jani.nikula@linux.intel.com
Tested-by: LluĂ­s Batlle i Rossell <viric@viric.name>
Signed-off-by: Shobhit Kumar <shobhit.kumar@intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h   |  8 ++++++-
 drivers/gpu/drm/i915/intel_panel.c | 47 +++++++++++++++++++++++---------------
 2 files changed, 36 insertions(+), 19 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index cc13706..17af59c 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -263,6 +263,12 @@  struct intel_encoder {
 	const struct drm_connector *audio_connector;
 };
 
+struct intel_pwm_info {
+	struct pwm_device *dev;
+	unsigned int period_ns;
+	char *name;
+};
+
 struct intel_panel {
 	struct drm_display_mode *fixed_mode;
 	struct drm_display_mode *downclock_mode;
@@ -282,7 +288,7 @@  struct intel_panel {
 		/* PWM chip */
 		bool util_pin_active_low;	/* bxt+ */
 		u8 controller;		/* bxt+ only */
-		struct pwm_device *pwm;
+		struct intel_pwm_info *pwm;
 
 		struct backlight_device *device;
 
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index c8103f8..d56d1c2 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -37,6 +37,13 @@ 
 
 #define CRC_PMIC_PWM_PERIOD_NS	21333
 
+/* CRC PMIC based PWM Information */
+struct intel_pwm_info crc_pwm_info = {
+	.period_ns = CRC_PMIC_PWM_PERIOD_NS,
+	.name = "pwm_backlight",
+	.dev = NULL,
+};
+
 void
 intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
 		       struct drm_display_mode *adjusted_mode)
@@ -536,10 +543,11 @@  static u32 bxt_get_backlight(struct intel_connector *connector)
 static u32 pwm_get_backlight(struct intel_connector *connector)
 {
 	struct intel_panel *panel = &connector->panel;
+	struct intel_pwm_info *pwm = panel->backlight.pwm;
 	int duty_ns;
 
-	duty_ns = pwm_get_duty_cycle(panel->backlight.pwm);
-	return DIV_ROUND_UP(duty_ns * 100, CRC_PMIC_PWM_PERIOD_NS);
+	duty_ns = pwm_get_duty_cycle(pwm->dev);
+	return DIV_ROUND_UP(duty_ns * 100, pwm->period_ns);
 }
 
 static u32 intel_panel_get_backlight(struct intel_connector *connector)
@@ -628,9 +636,10 @@  static void bxt_set_backlight(struct intel_connector *connector, u32 level)
 static void pwm_set_backlight(struct intel_connector *connector, u32 level)
 {
 	struct intel_panel *panel = &connector->panel;
-	int duty_ns = DIV_ROUND_UP(level * CRC_PMIC_PWM_PERIOD_NS, 100);
+	struct intel_pwm_info *pwm = panel->backlight.pwm;
+	int duty_ns = DIV_ROUND_UP(level * pwm->period_ns, 100);
 
-	pwm_config(panel->backlight.pwm, duty_ns, CRC_PMIC_PWM_PERIOD_NS);
+	pwm_config(pwm->dev, duty_ns, pwm->period_ns);
 }
 
 static void
@@ -799,11 +808,12 @@  static void bxt_disable_backlight(struct intel_connector *connector)
 static void pwm_disable_backlight(struct intel_connector *connector)
 {
 	struct intel_panel *panel = &connector->panel;
+	struct intel_pwm_info *pwm = panel->backlight.pwm;
 
 	/* Disable the backlight */
-	pwm_config(panel->backlight.pwm, 0, CRC_PMIC_PWM_PERIOD_NS);
+	pwm_config(pwm->dev, 0, pwm->period_ns);
 	usleep_range(2000, 3000);
-	pwm_disable(panel->backlight.pwm);
+	pwm_disable(pwm->dev);
 }
 
 void intel_panel_disable_backlight(struct intel_connector *connector)
@@ -1090,7 +1100,7 @@  static void pwm_enable_backlight(struct intel_connector *connector)
 {
 	struct intel_panel *panel = &connector->panel;
 
-	pwm_enable(panel->backlight.pwm);
+	pwm_enable(panel->backlight.pwm->dev);
 	intel_panel_actually_set_backlight(connector, panel->backlight.level);
 }
 
@@ -1649,12 +1659,13 @@  static int pwm_setup_backlight(struct intel_connector *connector,
 {
 	struct drm_device *dev = connector->base.dev;
 	struct intel_panel *panel = &connector->panel;
+	struct intel_pwm_info *pwm = &crc_pwm_info;
 	int retval;
 
 	/* Get the PWM chip for backlight control */
-	panel->backlight.pwm = pwm_get(dev->dev, "pwm_backlight");
-	if (IS_ERR(panel->backlight.pwm)) {
-		DRM_ERROR("Failed to own the pwm chip\n");
+	pwm->dev = pwm_get(dev->dev, pwm->name);
+	if (IS_ERR(pwm->dev)) {
+		DRM_ERROR("Failed to own the pwm chip: %s\n", pwm->name);
 		panel->backlight.pwm = NULL;
 		return -ENODEV;
 	}
@@ -1663,13 +1674,12 @@  static int pwm_setup_backlight(struct intel_connector *connector,
 	 * FIXME: pwm_apply_args() should be removed when switching to
 	 * the atomic PWM API.
 	 */
-	pwm_apply_args(panel->backlight.pwm);
+	pwm_apply_args(pwm->dev);
 
-	retval = pwm_config(panel->backlight.pwm, CRC_PMIC_PWM_PERIOD_NS,
-			    CRC_PMIC_PWM_PERIOD_NS);
+	retval = pwm_config(pwm->dev, pwm->period_ns, pwm->period_ns);
 	if (retval < 0) {
-		DRM_ERROR("Failed to configure the pwm chip\n");
-		pwm_put(panel->backlight.pwm);
+		DRM_ERROR("Failed to configure the pwm chip: %s\n", pwm->name);
+		pwm_put(pwm->dev);
 		panel->backlight.pwm = NULL;
 		return retval;
 	}
@@ -1677,10 +1687,11 @@  static int pwm_setup_backlight(struct intel_connector *connector,
 	panel->backlight.min = 0; /* 0% */
 	panel->backlight.max = 100; /* 100% */
 	panel->backlight.level = DIV_ROUND_UP(
-				 pwm_get_duty_cycle(panel->backlight.pwm) * 100,
-				 CRC_PMIC_PWM_PERIOD_NS);
+				 pwm_get_duty_cycle(pwm->dev) * 100, pwm->period_ns);
 	panel->backlight.enabled = panel->backlight.level != 0;
 
+	panel->backlight.pwm = pwm;
+
 	return 0;
 }
 
@@ -1732,7 +1743,7 @@  void intel_panel_destroy_backlight(struct drm_connector *connector)
 
 	/* dispose of the pwm */
 	if (panel->backlight.pwm)
-		pwm_put(panel->backlight.pwm);
+		pwm_put(panel->backlight.pwm->dev);
 
 	panel->backlight.present = false;
 }