Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 259676
b: refs/heads/master
c: 6a7afe3
h: refs/heads/master
v: v3
  • Loading branch information
Alan Cox authored and Greg Kroah-Hartman committed Jul 5, 2011
1 parent 0c3a4c1 commit 3a0d601
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 320 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 92367fe1bca91efa7f689127ba45080d4303d609
refs/heads/master: 6a7afe3acc4bfa54b1433b7f6b5b467ec05ee15b
2 changes: 1 addition & 1 deletion trunk/drivers/staging/gma500/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
ccflags-y += -Iinclude/drm

psb_gfx-y += gem_glue.o \
backlight.o \
power.o \
psb_bl.o \
psb_drv.o \
psb_gem.o \
psb_fb.o \
Expand Down
46 changes: 46 additions & 0 deletions trunk/drivers/staging/gma500/backlight.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* GMA500 Backlight Interface
*
* Copyright (c) 2009-2011, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Authors: Eric Knopp
*
*/

#include "psb_drv.h"
#include "psb_intel_reg.h"
#include "psb_intel_drv.h"
#include "psb_intel_bios.h"
#include "psb_powermgmt.h"

int gma_backlight_init(struct drm_device *dev)
{
#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
struct drm_psb_private *dev_priv = dev->dev_private;
return dev_priv->ops->backlight_init(dev);
#endif
}

void gma_backlight_exit(struct drm_device *dev)
{
#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
struct drm_psb_private *dev_priv = dev->dev_private;
dev_priv->backlight_device->props.brightness = 0;
backlight_update_status(dev_priv->backlight_device);
if (dev_priv->backlight_device)
backlight_device_unregister(dev_priv->backlight_device);
#endif
}
94 changes: 93 additions & 1 deletion trunk/drivers/staging/gma500/mdfld_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
**************************************************************************/

#include <linux/backlight.h>
#include <drm/drmP.h>
#include <drm/drm.h>
#include "psb_reg.h"
Expand All @@ -27,7 +28,93 @@
#include "mdfld_dsi_output.h"

/*
* Provide the Medfield specific chip logic and low level methods
* Provide the Medfield specific backlight management
*/

#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE

static int mdfld_brightness;
struct backlight_device *mdfld_backlight_device;

static int mfld_set_brightness(struct backlight_device *bd)
{
struct drm_device *dev = bl_get_data(mdfld_backlight_device);
struct drm_psb_private *dev_priv = dev->dev_private;
int level = bd->props.brightness;

/* Percentage 1-100% being valid */
if (level < 1)
level = 1;

if (gma_power_begin(dev, 0)) {
/* Calculate and set the brightness value */
u32 adjusted_level;

/* Adjust the backlight level with the percent in
* dev_priv->blc_adj2;
*/
adjusted_level = level * dev_priv->blc_adj2;
adjusted_level = adjusted_level / 100;
#if 0
#ifndef CONFIG_MDFLD_DSI_DPU
if(!(dev_priv->dsr_fb_update & MDFLD_DSR_MIPI_CONTROL) &&
(dev_priv->dbi_panel_on || dev_priv->dbi_panel_on2)){
mdfld_dsi_dbi_exit_dsr(dev,MDFLD_DSR_MIPI_CONTROL, 0, 0);
dev_dbg(dev->dev, "Out of DSR before set brightness to %d.\n",adjusted_level);
}
#endif
mdfld_dsi_brightness_control(dev, 0, adjusted_level);

if ((dev_priv->dbi_panel_on2) || (dev_priv->dpi_panel_on2))
mdfld_dsi_brightness_control(dev, 2, adjusted_level);
#endif
gma_power_end(dev);
}
mdfld_brightness = level;
return 0;
}

int psb_get_brightness(struct backlight_device *bd)
{
/* return locally cached var instead of HW read (due to DPST etc.) */
/* FIXME: ideally return actual value in case firmware fiddled with
it */
return mdfld_brightness;
}

static const struct backlight_ops mfld_ops = {
.get_brightness = psb_get_brightness,
.update_status = mfld_set_brightness,
};

static int mdfld_backlight_init(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct backlight_properties props;
memset(&props, 0, sizeof(struct backlight_properties));
props.max_brightness = 100;
props.type = BACKLIGHT_PLATFORM;

mdfld_backlight_device = backlight_device_register("mfld-bl",
NULL, (void *)dev, &mfld_ops, &props);

if (IS_ERR(mdfld_backlight_device))
return PTR_ERR(mdfld_backlight_device);

dev_priv->blc_adj1 = 100;
dev_priv->blc_adj2 = 100;
mdfld_backlight_device->props.brightness = 100;
mdfld_backlight_device->props.max_brightness = 100;
backlight_update_status(mdfld_backlight_device);
dev_priv->backlight_device = mdfld_backlight_device;
return 0;
}

#endif

/*
* Provide the Medfield specific chip logic and low level methods for
* power management.
*/

static void mdfld_init_pm(struct drm_device *dev)
Expand Down Expand Up @@ -601,6 +688,11 @@ static int mdfld_power_up(struct drm_device *dev)

const struct psb_ops mdfld_chip_ops = {
.output_init = mdfld_output_init,

#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
.backlight_init = mdfld_backlight_init,
#endif

.init_pm = mdfld_init_pm,
.save_regs = mdfld_save_registers,
.restore_regs = mdfld_restore_registers,
Expand Down
11 changes: 7 additions & 4 deletions trunk/drivers/staging/gma500/mdfld_dsi_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ static int mdfld_dsi_connector_set_property(struct drm_connector * connector,
{
struct drm_encoder * encoder = connector->encoder;
struct backlight_device * psb_bd;
struct drm_psb_private * dev_priv = encoder->dev->dev_private;

if (!strcmp(property->name, "scaling mode") && encoder) {
struct psb_intel_crtc * psb_crtc = to_psb_intel_crtc(encoder->crtc);
Expand Down Expand Up @@ -512,27 +513,29 @@ static int mdfld_dsi_connector_set_property(struct drm_connector * connector,
&psb_crtc->saved_adjusted_mode);
}
}
#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
} else if (!strcmp(property->name, "backlight") && encoder) {
dev_dbg(encoder->dev->dev, "backlight level = %d\n", (int)value);
if (drm_connector_property_set_value(connector, property, value))
goto set_prop_error;
else {
dev_dbg(encoder->dev->dev,
"set brightness to %d", (int)value);
psb_bd = psb_get_backlight_device();
if(psb_bd) {
psb_bd = dev_priv->backlight_device;
if (psb_bd) {
psb_bd->props.brightness = value;
psb_set_brightness(psb_bd);
backlight_update_status(psb_bd);
}
}
}
#endif
set_prop_done:
return 0;
set_prop_error:
return -1;
}

static void mdfld_dsi_connector_destroy(struct drm_connector * connector)
static void mdfld_dsi_connector_destroy(struct drm_connector *connector)
{
struct psb_intel_output * psb_output = to_psb_intel_output(connector);
struct mdfld_dsi_connector * dsi_connector = MDFLD_DSI_CONNECTOR(psb_output);
Expand Down
137 changes: 137 additions & 0 deletions trunk/drivers/staging/gma500/mrst_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
**************************************************************************/

#include <linux/backlight.h>
#include <drm/drmP.h>
#include <drm/drm.h>
#include "psb_drm.h"
Expand All @@ -41,8 +42,139 @@ static int mrst_output_init(struct drm_device *dev)
return -ENODEV;
}

/*
* Provide the low level interfaces for the Moorestown backlight
*/

#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE

#define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF
#define BLC_PWM_PRECISION_FACTOR 100 /* 10000000 */
#define BLC_PWM_FREQ_CALC_CONSTANT 32
#define MHz 1000000
#define BLC_ADJUSTMENT_MAX 100

static struct backlight_device *mrst_backlight_device;
static int mrst_brightness;

static int mrst_set_brightness(struct backlight_device *bd)
{
struct drm_device *dev = bl_get_data(mrst_backlight_device);
struct drm_psb_private *dev_priv = dev->dev_private;
int level = bd->props.brightness;
u32 blc_pwm_ctl;
u32 max_pwm_blc;

/* Percentage 1-100% being valid */
if (level < 1)
level = 1;

if (gma_power_begin(dev, 0)) {
/* Calculate and set the brightness value */
max_pwm_blc = REG_READ(BLC_PWM_CTL) >> 16;
blc_pwm_ctl = level * max_pwm_blc / 100;

/* Adjust the backlight level with the percent in
* dev_priv->blc_adj1;
*/
blc_pwm_ctl = blc_pwm_ctl * dev_priv->blc_adj1;
blc_pwm_ctl = blc_pwm_ctl / 100;

/* Adjust the backlight level with the percent in
* dev_priv->blc_adj2;
*/
blc_pwm_ctl = blc_pwm_ctl * dev_priv->blc_adj2;
blc_pwm_ctl = blc_pwm_ctl / 100;

/* force PWM bit on */
REG_WRITE(BLC_PWM_CTL2, (0x80000000 | REG_READ(BLC_PWM_CTL2)));
REG_WRITE(BLC_PWM_CTL, (max_pwm_blc << 16) | blc_pwm_ctl);
gma_power_end(dev);
}
mrst_brightness = level;
return 0;
}

static int mrst_get_brightness(struct backlight_device *bd)
{
/* return locally cached var instead of HW read (due to DPST etc.) */
/* FIXME: ideally return actual value in case firmware fiddled with
it */
return mrst_brightness;
}

static int device_backlight_init(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
unsigned long core_clock;
u16 bl_max_freq;
uint32_t value;
uint32_t blc_pwm_precision_factor;

dev_priv->blc_adj1 = BLC_ADJUSTMENT_MAX;
dev_priv->blc_adj2 = BLC_ADJUSTMENT_MAX;
bl_max_freq = 256;
/* this needs to be set elsewhere */
blc_pwm_precision_factor = BLC_PWM_PRECISION_FACTOR;

core_clock = dev_priv->core_freq;

value = (core_clock * MHz) / BLC_PWM_FREQ_CALC_CONSTANT;
value *= blc_pwm_precision_factor;
value /= bl_max_freq;
value /= blc_pwm_precision_factor;

if (gma_power_begin(dev, false)) {
if (value > (unsigned long long)MRST_BLC_MAX_PWM_REG_FREQ)
return -ERANGE;
else {
REG_WRITE(BLC_PWM_CTL2,
(0x80000000 | REG_READ(BLC_PWM_CTL2)));
REG_WRITE(BLC_PWM_CTL, value | (value << 16));
}
gma_power_end(dev);
}
return 0;
}

static const struct backlight_ops mrst_ops = {
.get_brightness = mrst_get_brightness,
.update_status = mrst_set_brightness,
};

int mrst_backlight_init(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
int ret;
struct backlight_properties props;

memset(&props, 0, sizeof(struct backlight_properties));
props.max_brightness = 100;
props.type = BACKLIGHT_PLATFORM;

mrst_backlight_device = backlight_device_register("mrst-bl",
NULL, (void *)dev, &mrst_ops, &props);

if (IS_ERR(mrst_backlight_device))
return PTR_ERR(mrst_backlight_device);

ret = device_backlight_init(dev);
if (ret < 0) {
backlight_device_unregister(mrst_backlight_device);
return ret;
}
mrst_backlight_device->props.brightness = 100;
mrst_backlight_device->props.max_brightness = 100;
backlight_update_status(mrst_backlight_device);
dev_priv->backlight_device = mrst_backlight_device;
return 0;
}

#endif

/*
* Provide the Moorestown specific chip logic and low level methods
* for power management
*/

static void mrst_init_pm(struct drm_device *dev)
Expand Down Expand Up @@ -221,6 +353,11 @@ static int mrst_power_up(struct drm_device *dev)

const struct psb_ops mrst_chip_ops = {
.output_init = mrst_output_init,

#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
.backlight_init = mrst_backlight_init,
#endif

.init_pm = mrst_init_pm,
.save_regs = mrst_save_display_registers,
.restore_regs = mrst_restore_display_registers,
Expand Down
Loading

0 comments on commit 3a0d601

Please sign in to comment.