From 97bdb69e04541c5395853011cfd58f660e3b0093 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 8 Feb 2015 01:07:08 +0100 Subject: [PATCH] Adding baytrail backlight pmic hack --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_params.c | 5 +++++ drivers/gpu/drm/i915/intel_dsi.c | 10 ++++++++++ drivers/gpu/drm/i915/intel_panel.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- drivers/mfd/intel_soc_pmic_core.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/mfd/intel_soc_pmic.h | 4 ++++ 6 files changed, 112 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index f2a825e..b4ccb20 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2527,6 +2527,7 @@ struct i915_params { bool mmio_debug; bool verbose_state_checks; bool nuclear_pageflip; + bool force_backlight_pmic; }; extern struct i915_params i915 __read_mostly; diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c index 44f2262..0bcfdf4 100644 --- a/drivers/gpu/drm/i915/i915_params.c +++ b/drivers/gpu/drm/i915/i915_params.c @@ -53,6 +53,7 @@ struct i915_params i915 __read_mostly = { .mmio_debug = 0, .verbose_state_checks = 1, .nuclear_pageflip = 0, + .force_backlight_pmic = 0, }; module_param_named(modeset, i915.modeset, int, 0400); @@ -183,3 +184,7 @@ MODULE_PARM_DESC(verbose_state_checks, module_param_named_unsafe(nuclear_pageflip, i915.nuclear_pageflip, bool, 0600); MODULE_PARM_DESC(nuclear_pageflip, "Force atomic modeset functionality; only planes work for now (default: false)."); + +module_param_named(force_backlight_pmic, i915.force_backlight_pmic, bool, 0600); +MODULE_PARM_DESC(force_backlight_pmic, + "Force backlight adjusting through pmic (default: false)."); diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c index 10ab684..006b88c 100644 --- a/drivers/gpu/drm/i915/intel_dsi.c +++ b/drivers/gpu/drm/i915/intel_dsi.c @@ -381,6 +381,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder) struct drm_device *dev = encoder->base.dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); + struct intel_connector *intel_connector = + &intel_dsi->attached_connector->base; enum port port; DRM_DEBUG_KMS("\n"); @@ -401,6 +403,8 @@ static void intel_dsi_enable(struct intel_encoder *encoder) intel_dsi_port_enable(encoder); } + + intel_panel_enable_backlight(intel_connector); } static void intel_dsi_pre_enable(struct intel_encoder *encoder) @@ -474,6 +478,8 @@ static void intel_dsi_disable(struct intel_encoder *encoder) struct drm_device *dev = encoder->base.dev; struct drm_i915_private *dev_priv = dev->dev_private; struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); + struct intel_connector *intel_connector = + &intel_dsi->attached_connector->base; enum port port; u32 temp; @@ -487,6 +493,8 @@ static void intel_dsi_disable(struct intel_encoder *encoder) msleep(2); } + intel_panel_disable_backlight(intel_connector); + for_each_dsi_port(port, intel_dsi->ports) { /* Panel commands can be sent when clock is in LP11 */ I915_WRITE(MIPI_DEVICE_READY(port), 0x0); @@ -942,6 +950,7 @@ static void intel_dsi_connector_destroy(struct drm_connector *connector) DRM_DEBUG_KMS("\n"); intel_panel_fini(&intel_connector->panel); + intel_panel_destroy_backlight(connector); drm_connector_cleanup(connector); kfree(connector); } @@ -1103,6 +1112,7 @@ void intel_dsi_init(struct drm_device *dev) } intel_panel_init(&intel_connector->panel, fixed_mode, NULL); + intel_panel_setup_backlight(connector, INVALID_PIPE); return; diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c index dfb783a..e76d3f2 100644 --- a/drivers/gpu/drm/i915/intel_panel.c +++ b/drivers/gpu/drm/i915/intel_panel.c @@ -31,6 +31,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include "intel_drv.h" void @@ -535,6 +536,11 @@ static u32 vlv_get_backlight(struct intel_connector *connector) return _vlv_get_backlight(dev, pipe); } +static u32 vlv_pmic_get_backlight(struct intel_connector *connector) +{ + return intel_soc_pmic_readb(0x4E); +} + static u32 intel_panel_get_backlight(struct intel_connector *connector) { struct drm_device *dev = connector->base.dev; @@ -615,6 +621,11 @@ static void vlv_set_backlight(struct intel_connector *connector, u32 level) I915_WRITE(VLV_BLC_PWM_CTL(pipe), tmp | level); } +static void vlv_pmic_set_backlight(struct intel_connector *connector, u32 level) +{ + intel_soc_pmic_writeb(0x4E, level); +} + static void intel_panel_actually_set_backlight(struct intel_connector *connector, u32 level) { @@ -740,6 +751,14 @@ static void vlv_disable_backlight(struct intel_connector *connector) I915_WRITE(VLV_BLC_PWM_CTL2(pipe), tmp & ~BLM_PWM_ENABLE); } +static void vlv_pmic_disable_backlight(struct intel_connector *connector) +{ + intel_panel_actually_set_backlight(connector, 0); + + intel_soc_pmic_writeb(0x51, 0x00); + intel_soc_pmic_writeb(0x4B, 0x7F); +} + void intel_panel_disable_backlight(struct intel_connector *connector) { struct drm_device *dev = connector->base.dev; @@ -946,6 +965,17 @@ static void vlv_enable_backlight(struct intel_connector *connector) I915_WRITE(VLV_BLC_PWM_CTL2(pipe), ctl2 | BLM_PWM_ENABLE); } +static void vlv_pmic_enable_backlight(struct intel_connector *connector) +{ + struct intel_panel *panel = &connector->panel; + + intel_soc_pmic_writeb(0x4B, 0xFF); + intel_soc_pmic_writeb(0x4E, 0xFF); + intel_soc_pmic_writeb(0x51, 0x01); + + intel_panel_actually_set_backlight(connector, panel->backlight.level); +} + void intel_panel_enable_backlight(struct intel_connector *connector) { struct drm_device *dev = connector->base.dev; @@ -1298,6 +1328,20 @@ static int vlv_setup_backlight(struct intel_connector *connector, enum pipe pipe return 0; } +static int vlv_pmic_setup_backlight(struct intel_connector *connector, enum pipe unused) +{ + struct intel_panel *panel = &connector->panel; + + printk("vlv_pmic_setup_backlight\n"); + panel->backlight.present = 1; + panel->backlight.min = 0x00; + panel->backlight.max = 0xFF; + panel->backlight.level = 20; + panel->backlight.enabled = 1; + + return 0; +} + int intel_panel_setup_backlight(struct drm_connector *connector, enum pipe pipe) { struct drm_device *dev = connector->dev; @@ -1362,11 +1406,19 @@ void intel_panel_init_backlight_funcs(struct drm_device *dev) dev_priv->display.set_backlight = pch_set_backlight; dev_priv->display.get_backlight = pch_get_backlight; } else if (IS_VALLEYVIEW(dev)) { - dev_priv->display.setup_backlight = vlv_setup_backlight; - dev_priv->display.enable_backlight = vlv_enable_backlight; - dev_priv->display.disable_backlight = vlv_disable_backlight; - dev_priv->display.set_backlight = vlv_set_backlight; - dev_priv->display.get_backlight = vlv_get_backlight; + if (i915.force_backlight_pmic) { + dev_priv->display.setup_backlight = vlv_pmic_setup_backlight; + dev_priv->display.enable_backlight = vlv_pmic_enable_backlight; + dev_priv->display.disable_backlight = vlv_pmic_disable_backlight; + dev_priv->display.set_backlight = vlv_pmic_set_backlight; + dev_priv->display.get_backlight = vlv_pmic_get_backlight; + } else { + dev_priv->display.setup_backlight = vlv_setup_backlight; + dev_priv->display.enable_backlight = vlv_enable_backlight; + dev_priv->display.disable_backlight = vlv_disable_backlight; + dev_priv->display.set_backlight = vlv_set_backlight; + dev_priv->display.get_backlight = vlv_get_backlight; + } } else if (IS_GEN4(dev)) { dev_priv->display.setup_backlight = i965_setup_backlight; dev_priv->display.enable_backlight = i965_enable_backlight; diff --git a/drivers/mfd/intel_soc_pmic_core.c b/drivers/mfd/intel_soc_pmic_core.c index 80cef04..3fad0e7 100644 --- a/drivers/mfd/intel_soc_pmic_core.c +++ b/drivers/mfd/intel_soc_pmic_core.c @@ -26,6 +26,8 @@ #include #include "intel_soc_pmic_core.h" +static struct intel_soc_pmic *pmic_hack = NULL; + /* * On some boards the PMIC interrupt may come from a GPIO line. * Try to lookup the ACPI table and see if such connection exists. If not, @@ -66,6 +68,7 @@ static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c, pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); if (!pmic) return -ENOMEM; + pmic_hack = pmic; dev_set_drvdata(dev, pmic); @@ -138,6 +141,38 @@ static int intel_soc_pmic_resume(struct device *dev) } #endif +int intel_soc_pmic_readb(int reg) +{ + int ret; + unsigned int val; + + if (!pmic_hack) { + ret = -EIO; + } else { + ret = regmap_read(pmic_hack->regmap, reg, &val); + if (!ret) { + ret = val; + } + } + + return ret; +} +EXPORT_SYMBOL(intel_soc_pmic_readb); + +int intel_soc_pmic_writeb(int reg, u8 val) +{ + int ret; + + if (!pmic_hack) { + ret = -EIO; + } else { + ret = regmap_write(pmic_hack->regmap, reg, val); + } + return ret; +} +EXPORT_SYMBOL(intel_soc_pmic_writeb); + + static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend, intel_soc_pmic_resume); diff --git a/include/linux/mfd/intel_soc_pmic.h b/include/linux/mfd/intel_soc_pmic.h index abcbfcf..56b3e71 100644 --- a/include/linux/mfd/intel_soc_pmic.h +++ b/include/linux/mfd/intel_soc_pmic.h @@ -27,4 +27,8 @@ struct intel_soc_pmic { struct regmap_irq_chip_data *irq_chip_data; }; +int intel_soc_pmic_readb(int reg); +int intel_soc_pmic_writeb(int reg, u8 val); + + #endif /* __INTEL_SOC_PMIC_H__ */ -- libgit2 0.21.0