[RFC PATCH] DRM: Add drm backlight dpms interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The backlight devices have the ability to control their power levels and
it is supported by backlight framework or lcd framework. This helps use
to drm the functions to control power levels of the existing backlight
framework or lcd framework.

Signed-off-by: Joonyoung Shim <jy0922.shim@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
 drivers/gpu/drm/Makefile        |    2 +-
 drivers/gpu/drm/drm_backlight.c |  127 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_backlight.h     |   19 ++++++
 3 files changed, 147 insertions(+), 1 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_backlight.c
 create mode 100644 include/drm/drm_backlight.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 89cf05a..d752618 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -12,7 +12,7 @@ drm-y       :=	drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
 		drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
 		drm_crtc.o drm_modes.o drm_edid.o \
 		drm_info.o drm_debugfs.o drm_encoder_slave.o \
-		drm_trace_points.o drm_global.o drm_usb.o
+		drm_trace_points.o drm_global.o drm_usb.o drm_backlight.o
 
 drm-$(CONFIG_COMPAT) += drm_ioc32.o
 
diff --git a/drivers/gpu/drm/drm_backlight.c b/drivers/gpu/drm/drm_backlight.c
new file mode 100644
index 0000000..83b9e65
--- /dev/null
+++ b/drivers/gpu/drm/drm_backlight.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics Co.Ltd
+ * Author: Joonyoung Shim <jy0922.shim@xxxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ *
+ */
+
+#include <linux/backlight.h>
+#include <linux/lcd.h>
+
+#include "drm_backlight.h"
+#include "drm_mode.h"
+
+static DEFINE_MUTEX(drm_bl_mutex);
+static LIST_HEAD(drm_bl_list);
+
+struct drm_bl_data {
+	struct device *dev;
+	struct list_head list;
+	int type;
+};
+
+/**
+ * drm_bl_register(): register device of backlight or lcd to drm backlight
+ *
+ * @dev: backlight or lcd device
+ * @type: type of the device
+ */
+int drm_bl_register(struct device *dev, int type)
+{
+	struct drm_bl_data *data;
+
+	switch (type) {
+	case BL_BACKLIGHT_CLASS:
+	case BL_LCD_CLASS:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	data = kzalloc(sizeof(struct drm_bl_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->dev = dev;
+	data->type = type;
+
+	mutex_lock(&drm_bl_mutex);
+	list_add(&data->list, &drm_bl_list);
+	mutex_unlock(&drm_bl_mutex);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(drm_bl_register);
+
+/**
+ * drm_bl_unregister(): unregister previously registered device to drm backlight
+ *
+ * @dev: backlight or lcd device
+ */
+void drm_bl_unregister(struct device *dev)
+{
+	struct drm_bl_data *data;
+
+	list_for_each_entry(data, &drm_bl_list, list) {
+		if (data->dev == dev) {
+			mutex_lock(&drm_bl_mutex);
+			list_del(&data->list);
+			mutex_unlock(&drm_bl_mutex);
+			kfree(data);
+			break;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(drm_bl_unregister);
+
+
+/**
+ * drm_bl_dpms(): control power levels of registered drm backlights
+ *
+ * @mode: DPMS mode of DRM
+ *
+ * This function is called from dpms function of CRTC or encoder.
+ */
+void drm_bl_dpms(int mode)
+{
+	struct drm_bl_data *data;
+	struct backlight_device *bd;
+	struct lcd_device *ld;
+	int blank;
+
+	switch (mode) {
+	case DRM_MODE_DPMS_ON:
+		blank = FB_BLANK_UNBLANK;
+		break;
+	case DRM_MODE_DPMS_STANDBY:
+	case DRM_MODE_DPMS_SUSPEND:
+	case DRM_MODE_DPMS_OFF:
+		/* TODO */
+	default:
+		blank = FB_BLANK_POWERDOWN;
+		break;
+	}
+
+	list_for_each_entry(data, &drm_bl_list, list) {
+		switch (data->type) {
+		case BL_BACKLIGHT_CLASS:
+			bd = container_of(data->dev, struct backlight_device,
+					dev);
+			bd->props.power = blank;
+			bd->props.fb_blank = blank;
+			backlight_update_status(bd);
+			break;
+		case BL_LCD_CLASS:
+			ld = container_of(data->dev, struct lcd_device, dev);
+			if (!ld->ops->set_power)
+				break;
+			ld->ops->set_power(ld, blank);
+			break;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(drm_bl_dpms);
diff --git a/include/drm/drm_backlight.h b/include/drm/drm_backlight.h
new file mode 100644
index 0000000..a601095
--- /dev/null
+++ b/include/drm/drm_backlight.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics Co.Ltd
+ * Author: Joonyoung Shim <jy0922.shim@xxxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ *
+ */
+
+enum drm_bl_class_type {
+	BL_BACKLIGHT_CLASS,
+	BL_LCD_CLASS,
+};
+
+extern int drm_bl_register(struct device *dev, int type);
+extern void drm_bl_unregister(struct device *dev);
+extern void drm_bl_dpms(int mode);
-- 
1.7.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux