The branch main has been updated by adrian:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=2e9d05fd684803dbba7dd52eb64856c639e4fde2

commit 2e9d05fd684803dbba7dd52eb64856c639e4fde2
Author:     Adrian Chadd <adr...@freebsd.org>
AuthorDate: 2023-02-08 04:06:16 +0000
Commit:     Adrian Chadd <adr...@freebsd.org>
CommitDate: 2023-02-08 04:06:16 +0000

    asmc: Add support for 10 byte light sensor payloads; MacBookAir6,1
    
    The later macbook models use a different packet payload for the light
    sensors:
    
    * There's only one, done in the camera
    * It's a 4 byte sensor value, not a 2 byte value
    * It's in a 10 byte payload.
    
    So, this adds support for that and flips it on for the MacbookAir6,2.
    
    It also adds support for MacBookAir6,1 as that now works fine here.
    
    Tested - MacBookAir6,1 and 6,2
    
    Reviewed by: markj
    Differential Revision: https://reviews.freebsd.org/D38365
---
 sys/dev/asmc/asmc.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)

diff --git a/sys/dev/asmc/asmc.c b/sys/dev/asmc/asmc.c
index 337f641e4513..442463b9f47a 100644
--- a/sys/dev/asmc/asmc.c
+++ b/sys/dev/asmc/asmc.c
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/conf.h>
+#include <sys/endian.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
@@ -106,6 +107,7 @@ 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 int     asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS);
+static int     asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS);
 
 struct asmc_model {
        const char       *smc_model;    /* smbios.system.product env var. */
@@ -151,6 +153,11 @@ static const struct asmc_model *asmc_match(device_t dev);
                         asmc_mbp_sysctl_light_right, \
                         asmc_mbp_sysctl_light_control
 
+#define ASMC_LIGHT_FUNCS_10BYTE \
+                        asmc_mbp_sysctl_light_left_10byte, \
+                        NULL, \
+                        asmc_mbp_sysctl_light_control
+
 #define ASMC_LIGHT_FUNCS_DISABLED NULL, NULL, NULL
 
 static const struct asmc_model asmc_models[] = {
@@ -427,11 +434,18 @@ static const struct asmc_model asmc_models[] = {
          ASMC_LIGHT_FUNCS,
          ASMC_MBA5_TEMPS, ASMC_MBA5_TEMPNAMES, ASMC_MBA5_TEMPDESCS
        },
+       {
+         "MacBookAir6,1", "Apple SMC MacBook Air 11-inch (Early 2013)",
+         ASMC_SMS_FUNCS_DISABLED,
+         ASMC_FAN_FUNCS2,
+         ASMC_LIGHT_FUNCS_10BYTE,
+         ASMC_MBA6_TEMPS, ASMC_MBA6_TEMPNAMES, ASMC_MBA6_TEMPDESCS
+       },
        {
          "MacBookAir6,2", "Apple SMC MacBook Air 13-inch (Early 2013)",
          ASMC_SMS_FUNCS_DISABLED,
          ASMC_FAN_FUNCS2,
-         ASMC_LIGHT_FUNCS,
+         ASMC_LIGHT_FUNCS_10BYTE,
          ASMC_MBA6_TEMPS, ASMC_MBA6_TEMPNAMES, ASMC_MBA6_TEMPDESCS
        },
        {
@@ -1540,3 +1554,33 @@ asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS)
        }
        return (error);
 }
+
+static int
+asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS)
+{
+       device_t dev = (device_t) arg1;
+       uint8_t buf[10];
+       int error;
+       uint32_t v;
+
+       asmc_key_read(dev, ASMC_KEY_LIGHTLEFT, buf, sizeof buf);
+
+       /*
+        * This seems to be a 32 bit big endian value from buf[6] -> buf[9].
+        *
+        * Extract it out manually here, then shift/clamp it.
+        */
+       v = be32dec(&buf[6]);
+
+       /*
+        * Shift out, clamp at 255; that way it looks like the
+        * earlier SMC firmware version responses.
+        */
+       v = v >> 8;
+       if (v > 255)
+               v = 255;
+
+       error = sysctl_handle_int(oidp, &v, 0, req);
+
+       return (error);
+}

Reply via email to