From patchwork Tue Jan 12 15:00:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kumar, Shobhit" X-Patchwork-Id: 8018001 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 969FBBEEE5 for ; Tue, 12 Jan 2016 15:01:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D830203C2 for ; Tue, 12 Jan 2016 15:01:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C0DA8203C4 for ; Tue, 12 Jan 2016 15:01:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43C106E418; Tue, 12 Jan 2016 07:01:00 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 733716E419 for ; Tue, 12 Jan 2016 07:00:59 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 12 Jan 2016 07:00:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,558,1444719600"; d="scan'208";a="858946803" Received: from skumar40-mobl.iind.intel.com ([10.223.182.243]) by orsmga001.jf.intel.com with ESMTP; 12 Jan 2016 07:00:56 -0800 From: Shobhit Kumar To: intel-gfx@lists.freedesktop.org Date: Tue, 12 Jan 2016 20:30:50 +0530 Message-Id: <1452610852-30149-2-git-send-email-shobhit.kumar@intel.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1452610852-30149-1-git-send-email-shobhit.kumar@intel.com> References: <1452610852-30149-1-git-send-email-shobhit.kumar@intel.com> Subject: [Intel-gfx] [PATCH 1/3] drm/i915: Encapsulate the pwm_device in a pwm_info structure X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/gpu/drm/i915/intel_drv.h | 8 ++++++- drivers/gpu/drm/i915/intel_panel.c | 45 ++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 18 deletions(-) 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; }