Skip to contentSkip to conversation

Add in-kernel backlight control support

PATCH In review Matthew Garrett 1 participant 2 messages Feb 18, 2009 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add in-kernel backlight control support

Several nvidia-based systems don't support backlight control via the standard ACPI control mechanisms. Instead, it's necessary for the driver to modify the backlight control registers directly. This patch adds support for determining whether the registers appear to be in use, and if so registers a kernel backlight device to control them. The backlight can then be controlled via existing userspace tools.

linux-core/Makefile.kernel +1 -0
index 1e03347..0bea35d 100644
@@ -22,6 +22,7 @@ i810-objs   := i810_drv.o i810_dma.o
 nouveau-objs := nouveau_drv.o nouveau_state.o nouveau_fifo.o nouveau_mem.o \
 		nouveau_object.o nouveau_irq.o nouveau_notifier.o nouveau_swmthd.o \
 		nouveau_sgdma.o nouveau_dma.o nouveau_bo.o nouveau_fence.o \
+		nouveau_backlight.o \
 		nv04_timer.o \
 		nv04_mc.o nv40_mc.o nv50_mc.o \
 		nv04_fb.o nv10_fb.o nv40_fb.o \
linux-core/nouveau_backlight.c new file +156 -0

156 lines not on this page · raw message

shared-core/nouveau_drv.h +5 -0
index 158d6fd..1cd10bf 100644
@@ -318,6 +318,7 @@ struct drm_nouveau_private {
 		uint32_t *ramin_copy;
 		uint64_t ramin_size;
 	} susres;
+	struct backlight_device *backlight;
 };
 
 #define NOUVEAU_CHECK_INITIALISED_WITH_RETURN do {         \
@@ -468,6 +469,10 @@ extern int  nouveau_dma_channel_init(struct drm_device *);
 extern void nouveau_dma_channel_takedown(struct drm_device *);
 extern int  nouveau_dma_wait(struct drm_device *, int size);
 
+/* nouveau_backlight.c */
+extern int nouveau_backlight_init(struct drm_device *);
+extern void nouveau_backlight_exit(struct drm_device *);
+
 /* nv04_fb.c */
 extern int  nv04_fb_init(struct drm_device *);
 extern void nv04_fb_takedown(struct drm_device *);
shared-core/nouveau_reg.h +6 -0
index 1ae0177..060abe0 100644
@@ -99,6 +99,8 @@
  * the card will hang early on in the X init process.
  */
 #    define NV_PMC_ENABLE_UNK13                               (1<<13)
+#define NV40_PMC_BACKLIGHT				   0x000015f0
+#	define NV40_PMC_BACKLIGHT_MASK			   0x001f0000
 #define NV40_PMC_1700                                      0x00001700
 #define NV40_PMC_1704                                      0x00001704
 #define NV40_PMC_1708                                      0x00001708
@@ -542,6 +544,9 @@
 /* This name is a partial guess. */
 #define NV50_DISPLAY_SUPERVISOR                     0x00610024
 
+#define NV50_PDISPLAY_BACKLIGHT				0x0061c084
+#	define NV50_PDISPLAY_BACKLIGHT_ENABLE		0x80000000
+
 /* Fifo commands. These are not regs, neither masks */
 #define NV03_FIFO_CMD_JUMP                                 0x20000000
 #define NV03_FIFO_CMD_JUMP_OFFSET_MASK                     0x1ffffffc
@@ -591,3 +596,4 @@
 #define NV40_RAMFC_UNK_48                                        0x48
 #define NV40_RAMFC_UNK_4C                                        0x4C
 #define NV40_RAMFC_UNK_50                                        0x50
+
shared-core/nouveau_state.c +7 -0
index 0b6002c..c9f4329 100644
@@ -363,6 +363,11 @@ nouveau_card_init(struct drm_device *dev)
 	ret = nouveau_dma_channel_init(dev);
 	if (ret) return ret;
 
+	ret = nouveau_backlight_init(dev);
+	if (ret)
+		DRM_ERROR("Error code %d when trying to register backlight\n",
+			  ret);
+
 	dev_priv->init_state = NOUVEAU_CARD_INIT_DONE;
 	return 0;
 }
@@ -375,6 +380,8 @@ static void nouveau_card_takedown(struct drm_device *dev)
 	DRM_DEBUG("prev state = %d\n", dev_priv->init_state);
 
 	if (dev_priv->init_state != NOUVEAU_CARD_INIT_DOWN) {
+		nouveau_backlight_exit(dev);
+
 		nouveau_dma_channel_takedown(dev);
 
 		engine->fifo.takedown(dev);
Signature · 1 line
Matthew Garrett | [email protected]
#2 lore raw
In reply to a message not in the archive

Sorry, that broke compiles on <2.6.29. Here's a patch.

linux-core/nouveau_backlight.c +4 -0
index dc75c44..32bb3e5 100644
@@ -60,7 +60,9 @@ static int nv40_set_intensity(struct backlight_device *bd)
 }
 
 static struct backlight_ops nv40_bl_ops = {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
 	.options = BL_CORE_SUSPENDRESUME,
+#endif
 	.get_brightness = nv40_get_intensity,
 	.update_status = nv40_set_intensity,
 };
@@ -85,7 +87,9 @@ static int nv50_set_intensity(struct backlight_device *bd)
 }
 
 static struct backlight_ops nv50_bl_ops = {
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
 	.options = BL_CORE_SUSPENDRESUME,
+#endif
 	.get_brightness = nv50_get_intensity,
 	.update_status = nv50_set_intensity,
 };
Signature · 1 line
Matthew Garrett | [email protected]