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

Submitted by Shobhit Kumar on Jan. 12, 2016, 3 p.m.

Details

Message ID 1452610852-30149-2-git-send-email-shobhit.kumar@intel.com
State New
Series "LPSS PWM support for devices that support it"
Headers show

Commit Message

Shobhit Kumar Jan. 12, 2016, 3 p.m.
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.

Cc: cbrookes@gmail.com
Cc: jani.nikula@linux.intel.com
Signed-off-by: Shobhit Kumar <shobhit.kumar@intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h   |  8 ++++++-
 drivers/gpu/drm/i915/intel_panel.c | 45 ++++++++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 18 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index bdfe403..6f96769 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -161,6 +161,12 @@  struct intel_encoder {
 	enum hpd_pin hpd_pin;
 };
 
+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;
@@ -179,7 +185,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 21ee647..9e24c59 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)
@@ -538,10 +545,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)
@@ -630,9 +638,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
@@ -801,11 +810,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)
@@ -1069,7 +1079,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);
 }
 
@@ -1630,21 +1640,21 @@  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;
 	}
 
-	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;
 	}
@@ -1652,10 +1662,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;
 }
 
@@ -1707,7 +1718,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;
 }