From: tobhe Date: Wed, 22 Nov 2023 18:14:35 +0000 (+0000) Subject: Add support for keyboard backlight on Apple Powerbooks. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6784ab1f2e2b4b5a219a701f671d71ad89752052;p=openbsd Add support for keyboard backlight on Apple Powerbooks. From jon (at) elytron (dot) openbsd (dot) amsterdam ok gkoehler@ --- diff --git a/sys/arch/macppc/dev/adb.c b/sys/arch/macppc/dev/adb.c index 72939e8db3d..8d1e309b4b6 100644 --- a/sys/arch/macppc/dev/adb.c +++ b/sys/arch/macppc/dev/adb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adb.c,v 1.50 2023/04/11 00:45:07 jsg Exp $ */ +/* $OpenBSD: adb.c,v 1.51 2023/11/22 18:14:35 tobhe Exp $ */ /* $NetBSD: adb.c,v 1.6 1999/08/16 06:28:09 tsubai Exp $ */ /* $NetBSD: adb_direct.c,v 1.14 2000/06/08 22:10:45 tsubai Exp $ */ @@ -96,6 +96,7 @@ #include #include #include +#include #include #include @@ -242,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 *); + #ifndef SMALL_KERNEL void adb_shutdown(void *); @@ -1730,8 +1737,11 @@ adbattach(struct device *parent, struct device *self, void *aux) 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+) @@ -1758,3 +1768,19 @@ adbattach(struct device *parent, struct device *self, void *aux) 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); +} diff --git a/sys/arch/macppc/dev/pm_direct.c b/sys/arch/macppc/dev/pm_direct.c index 18c4fd17fbd..bf71c2c4fc7 100644 --- a/sys/arch/macppc/dev/pm_direct.c +++ b/sys/arch/macppc/dev/pm_direct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.c,v 1.34 2022/12/28 07:40:23 jca Exp $ */ +/* $OpenBSD: pm_direct.c,v 1.35 2023/11/22 18:14:35 tobhe Exp $ */ /* $NetBSD: pm_direct.c,v 1.9 2000/06/08 22:10:46 tsubai Exp $ */ /* @@ -853,3 +853,22 @@ pmu_fileserver_mode(int on) } pmgrop(&p); } + +int +pmu_set_kbl(unsigned 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); +} + diff --git a/sys/arch/macppc/dev/pm_direct.h b/sys/arch/macppc/dev/pm_direct.h index 6caae0ab599..21563fc71fc 100644 --- a/sys/arch/macppc/dev/pm_direct.h +++ b/sys/arch/macppc/dev/pm_direct.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pm_direct.h,v 1.15 2022/10/21 22:42:36 gkoehler Exp $ */ +/* $OpenBSD: pm_direct.h,v 1.16 2023/11/22 18:14:35 tobhe Exp $ */ /* $NetBSD: pm_direct.h,v 1.7 2005/01/07 04:59:58 briggs Exp $ */ /* @@ -67,6 +67,7 @@ struct pmu_battery_info }; int pm_battery_info(int, struct pmu_battery_info *); +int pmu_set_kbl(unsigned int); void pm_eject_pcmcia(int); void pmu_fileserver_mode(int);