[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-ppc
Subject:    [Diff] Keyboard backlight support for late powerbooks
From:       jon () elytron ! openbsd ! amsterdam
Date:       2022-08-26 9:19:21
Message-ID: 6d533cc2089851dd () pg4
[Download RAW message or body]

Hello. The following diff adds support for setting the keyboard
backlight through wsconsctl on powerbooks 5,8 and 5,9. These models
control the keyboard backlight through the PMU directly, rather
than through a iic channel.

I was looking to add support for the fn (f8 toggles on/off, f9 turns
down backlight, f10 turns up backlight) keys but as far as I can
tell it would be necessary to add new keycodes, hook things up in
/sys/dev/wscons/wskbd.c like with the display brightness keys, and
add translations to ukbd_apple_munge in /sys/dev/usb/ukbdmap.c. I
was wondering if this is the ideal approach, would appreciate any
hints.

Index: arch/macppc/dev/adb.c
===================================================================
RCS file: /cvs/src/sys/arch/macppc/dev/adb.c,v
retrieving revision 1.46
diff -u -p -r1.46 adb.c
--- arch/macppc/dev/adb.c	2 Jul 2022 08:50:41 -0000	1.46
+++ arch/macppc/dev/adb.c	26 Aug 2022 09:01:30 -0000
@@ -101,6 +101,8 @@
 #include <macppc/dev/pm_direct.h>
 #include <macppc/dev/viareg.h>
 
+#include <dev/wscons/wsconsio.h>
+
 #include "apm.h"
 
 #define printf_intr printf
@@ -241,6 +243,12 @@ void	setsoftadb(void);
 int	adb_intr(void *arg);
 void	adb_cuda_autopoll(void);
 void 	adb_cuda_fileserver_mode(void);
+uint8_t	 pmu_backlight;	/* keyboard backlight value */
+int	pmu_get_backlight(struct wskbd_backlight *);
+int	pmu_set_backlight(struct wskbd_backlight *);
+extern int (*wskbd_get_backlight)(struct wskbd_backlight *);
+extern int (*wskbd_set_backlight)(struct wskbd_backlight *);
+
 
 #ifdef ADB_DEBUG
 /*
@@ -1652,8 +1660,11 @@ adbattach(struct device *parent, struct 
 
 	if (adbHardware == ADB_HW_CUDA)
 		adb_cuda_fileserver_mode();
-	if (adbHardware == ADB_HW_PMU)
+	if (adbHardware == ADB_HW_PMU) {
+		wskbd_get_backlight = pmu_get_backlight;
+		wskbd_set_backlight = pmu_set_backlight;
 		pmu_fileserver_mode(1);
+	}
 
 	/*
 	 * XXX If the machine doesn't have an ADB bus (PowerBook5,6+)
@@ -1679,4 +1690,20 @@ adbattach(struct device *parent, struct 
 	if (adbHardware == ADB_HW_CUDA)
 		adb_cuda_autopoll();
 	adb_polling = 0;
+}
+
+int
+pmu_get_backlight(struct wskbd_backlight *kbl)
+{
+	kbl->min = 0;
+	kbl->max = 0xff;
+	kbl->curval = pmu_backlight;
+	return 0;
+}
+
+int
+pmu_set_backlight(struct wskbd_backlight *kbl)
+{
+	pmu_backlight = kbl->curval;
+	return pmu_set_kbl(pmu_backlight);
 }
Index: arch/macppc/dev/pm_direct.c
===================================================================
RCS file: /cvs/src/sys/arch/macppc/dev/pm_direct.c,v
retrieving revision 1.30
diff -u -p -r1.30 pm_direct.c
--- arch/macppc/dev/pm_direct.c	3 Sep 2019 17:51:52 -0000	1.30
+++ arch/macppc/dev/pm_direct.c	26 Aug 2022 09:01:32 -0000
@@ -804,3 +804,22 @@ pmu_fileserver_mode(int on)
 	}
 	pmgrop(&p);
 }
+
+int
+pmu_set_kbl(int level)
+{
+	if (level > 0xff)
+		return EINVAL;
+
+	PMData p;
+
+	p.command = 0x4F;
+	p.num_data = 3;
+	p.s_buf = p.r_buf = p.data;
+	p.data[0] = 0;
+	p.data[1] = 0;
+	p.data[2] = level;
+	pmgrop(&p);
+	return 0;
+}
+
Index: arch/macppc/dev/pm_direct.h
===================================================================
RCS file: /cvs/src/sys/arch/macppc/dev/pm_direct.h,v
retrieving revision 1.13
diff -u -p -r1.13 pm_direct.h
--- arch/macppc/dev/pm_direct.h	2 Sep 2012 08:16:40 -0000	1.13
+++ arch/macppc/dev/pm_direct.h	26 Aug 2022 09:01:32 -0000
@@ -66,6 +66,7 @@ struct pmu_battery_info
 };
 
 int pm_battery_info(int, struct pmu_battery_info *);
+int pmu_set_kbl(int);
 
 void pm_eject_pcmcia(int);
 void pmu_fileserver_mode(int);

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic