Date: Mon, 9 Jul 2007 02:12:47 GMT From: Rui Paulo <rpaulo@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123168 for review Message-ID: <200707090212.l692ClZQ011342@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123168 Change 123168 by rpaulo@rpaulo_epsilon on 2007/07/09 02:12:16 Add support for keyboard backlight control (found on MacBook Pros). dev.asmc.N.light.{left,right} sysctl tree is now created. Setting a value on the "right" or "left" nodes sets the keyboard backlight level. Reading those sysctl nodes, gives the each sensor raw data. While there fix the first parameter of DRIVER_MODULE() and change a label so that asmc_sms_calibrate() is not called on Mac Minis. Affected files ... .. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#24 edit .. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#11 edit Differences ... ==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#24 (text+ko) ==== @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#23 $ + * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#24 $ * */ @@ -100,6 +100,8 @@ static int asmc_mb_sysctl_sms_x(SYSCTL_HANDLER_ARGS); static int asmc_mb_sysctl_sms_y(SYSCTL_HANDLER_ARGS); static int asmc_mb_sysctl_sms_z(SYSCTL_HANDLER_ARGS); +static int asmc_mbp_sysctl_light_left(SYSCTL_HANDLER_ARGS); +static int asmc_mbp_sysctl_light_right(SYSCTL_HANDLER_ARGS); static struct asmc_model *asmc_match(device_t dev); @@ -110,53 +112,55 @@ asmc_mb_sysctl_fanminspeed, \ asmc_mb_sysctl_fanmaxspeed, \ asmc_mb_sysctl_fantargetspeed +#define ASMC_LIGHT_FUNCS asmc_mbp_sysctl_light_left, \ + asmc_mbp_sysctl_light_right struct asmc_model asmc_models[] = { { "MacBook1,1", "Apple SMC MacBook Core Duo", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, NULL, NULL, ASMC_MB_TEMPS, ASMC_MB_TEMPNAMES, ASMC_MB_TEMPDESCS }, { "MacBook2,1", "Apple SMC MacBook Core 2 Duo", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, NULL, NULL, ASMC_MB_TEMPS, ASMC_MB_TEMPNAMES, ASMC_MB_TEMPDESCS }, { "MacBookPro1,1", "Apple SMC MacBook Pro Core Duo (15-inch)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, { "MacBookPro1,2", "Apple SMC MacBook Pro Core Duo (17-inch)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, { "MacBookPro2,1", "Apple SMC MacBook Pro Core 2 Duo (17-inch)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, { "MacBookPro2,2", "Apple SMC MacBook Pro Core 2 Duo (15-inch)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, { "MacBookPro3,1", "Apple SMC MacBook Pro Core 2 Duo (15-inch LED)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, { "MacBookPro3,2", "Apple SMC MacBook Pro Core 2 Duo (17-inch HD)", - ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, + ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, ASMC_LIGHT_FUNCS, ASMC_MBP_TEMPS, ASMC_MBP_TEMPNAMES, ASMC_MBP_TEMPDESCS }, @@ -164,6 +168,7 @@ { "Macmini1,1", "Apple SMC Mac Mini", NULL, NULL, NULL, + NULL, NULL, ASMC_FAN_FUNCS, ASMC_MM_TEMPS, ASMC_MM_TEMPNAMES, ASMC_MM_TEMPDESCS }, @@ -173,6 +178,7 @@ #undef ASMC_SMS_FUNCS #undef ASMC_FAN_FUNCS +#undef ASMC_LIGHT_FUNCS /* * Driver methods. @@ -195,7 +201,7 @@ static devclass_t asmc_devclass; -DRIVER_MODULE(ascm, isa, asmc_driver, asmc_devclass, NULL, NULL); +DRIVER_MODULE(asmc, isa, asmc_driver, asmc_devclass, NULL, NULL); static void @@ -367,6 +373,27 @@ "Sudden Motion Sensor Z value"); /* + * dev.asmc.n.light + */ + if (model->smc_light_left) { + sc->sc_light_tree = SYSCTL_ADD_NODE(sysctlctx, + SYSCTL_CHILDREN(sysctlnode), OID_AUTO, "light", + CTLFLAG_RD, 0, "Keyboard backlight sensors"); + + SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(sc->sc_light_tree), + OID_AUTO, "left", CTLTYPE_INT | CTLFLAG_RD, + dev, 0, model->smc_light_left, "I", + "Keyboard backlight left sensor"); + + SYSCTL_ADD_PROC(sysctlctx, + SYSCTL_CHILDREN(sc->sc_light_tree), + OID_AUTO, "right", CTLTYPE_INT | CTLFLAG_RD, + dev, 0, model->smc_light_right, "I", + "Keyboard backlight right sensor"); + } + + /* * Need a taskqueue to send devctl_notify() events * when the SMS interrupt us. * @@ -500,9 +527,9 @@ DELAY(50); } + + asmc_sms_calibrate(dev); out: - asmc_sms_calibrate(dev); - sc->sc_nfan = asmc_fan_count(dev); if (sc->sc_nfan > ASMC_MAXFANS) { device_printf(dev, "more than %d fans were detected. Please " @@ -912,3 +939,59 @@ return (error); } + +static int +asmc_mbp_sysctl_light_left(SYSCTL_HANDLER_ARGS) +{ + device_t dev = (device_t) arg1; + uint8_t buf[6]; + int error; + unsigned int level; + int32_t v; + + asmc_key_read(dev, ASMC_KEY_LIGHTRIGHT, buf, 6); + + v = buf[2]; + error = sysctl_handle_int(oidp, &v, sizeof(v), req); + if (error == 0 && req->newptr != NULL) { + level = *(unsigned int *)req->newptr; + + if (level > 255) + return (EINVAL); + + buf[0] = level; + buf[1] = 0x00; + + asmc_key_write(dev, ASMC_KEY_LIGHTVALUE, buf, 2); + } + + return (error); +} + +static int +asmc_mbp_sysctl_light_right(SYSCTL_HANDLER_ARGS) +{ + device_t dev = (device_t) arg1; + uint8_t buf[6]; + int error; + unsigned int level; + int32_t v; + + asmc_key_read(dev, ASMC_KEY_LIGHTRIGHT, buf, 6); + + v = buf[2]; + error = sysctl_handle_int(oidp, &v, sizeof(v), req); + if (error == 0 && req->newptr != NULL) { + level = *(unsigned int *)req->newptr; + + if (level > 255) + return (EINVAL); + + buf[0] = level; + buf[1] = 0x00; + + asmc_key_write(dev, ASMC_KEY_LIGHTVALUE, buf, 2); + } + + return (error); +} ==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#11 (text+ko) ==== @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#10 $ + * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#11 $ * */ @@ -39,6 +39,7 @@ struct sysctl_oid *sc_fan_tree[ASMC_MAXFANS+1]; struct sysctl_oid *sc_temp_tree; struct sysctl_oid *sc_sms_tree; + struct sysctl_oid *sc_light_tree; struct asmc_model *sc_model; int sc_rid; struct resource *sc_res; @@ -61,6 +62,8 @@ int (*smc_fan_minspeed)(SYSCTL_HANDLER_ARGS); int (*smc_fan_maxspeed)(SYSCTL_HANDLER_ARGS); int (*smc_fan_targetspeed)(SYSCTL_HANDLER_ARGS); + int (*smc_light_left)(SYSCTL_HANDLER_ARGS); + int (*smc_light_right)(SYSCTL_HANDLER_ARGS); const char *smc_temps[8]; const char *smc_tempnames[8]; @@ -130,7 +133,8 @@ * Keyboard backlight. */ #define ASMC_KEY_LIGHTLEFT "ALV0" /* RO; 6 bytes */ -#define ASMC_KEY_RIGHTLEFT "ALV1" /* RO; 6 bytes */ +#define ASMC_KEY_LIGHTRIGHT "ALV1" /* RO; 6 bytes */ +#define ASMC_KEY_LIGHTVALUE "LKSB" /* WO; 2 bytes */ /* * Clamshell.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707090212.l692ClZQ011342>