Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/asmc/asmc.c
Show All 34 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/conf.h> | #include <sys/conf.h> | ||||
#include <sys/endian.h> | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/taskqueue.h> | #include <sys/taskqueue.h> | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
static int asmc_mb_sysctl_fantargetspeed(SYSCTL_HANDLER_ARGS); | static int asmc_mb_sysctl_fantargetspeed(SYSCTL_HANDLER_ARGS); | ||||
static int asmc_temp_sysctl(SYSCTL_HANDLER_ARGS); | static int asmc_temp_sysctl(SYSCTL_HANDLER_ARGS); | ||||
static int asmc_mb_sysctl_sms_x(SYSCTL_HANDLER_ARGS); | 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_y(SYSCTL_HANDLER_ARGS); | ||||
static int asmc_mb_sysctl_sms_z(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_left(SYSCTL_HANDLER_ARGS); | ||||
static int asmc_mbp_sysctl_light_right(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_control(SYSCTL_HANDLER_ARGS); | ||||
static int asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS); | |||||
struct asmc_model { | struct asmc_model { | ||||
const char *smc_model; /* smbios.system.product env var. */ | const char *smc_model; /* smbios.system.product env var. */ | ||||
const char *smc_desc; /* driver description */ | const char *smc_desc; /* driver description */ | ||||
/* Helper functions */ | /* Helper functions */ | ||||
int (*smc_sms_x)(SYSCTL_HANDLER_ARGS); | int (*smc_sms_x)(SYSCTL_HANDLER_ARGS); | ||||
int (*smc_sms_y)(SYSCTL_HANDLER_ARGS); | int (*smc_sms_y)(SYSCTL_HANDLER_ARGS); | ||||
Show All 29 Lines | #define ASMC_FAN_FUNCS2 asmc_mb_sysctl_fanid, asmc_mb_sysctl_fanspeed, NULL, \ | ||||
asmc_mb_sysctl_fanminspeed, \ | asmc_mb_sysctl_fanminspeed, \ | ||||
asmc_mb_sysctl_fanmaxspeed, \ | asmc_mb_sysctl_fanmaxspeed, \ | ||||
asmc_mb_sysctl_fantargetspeed | asmc_mb_sysctl_fantargetspeed | ||||
#define ASMC_LIGHT_FUNCS asmc_mbp_sysctl_light_left, \ | #define ASMC_LIGHT_FUNCS asmc_mbp_sysctl_light_left, \ | ||||
asmc_mbp_sysctl_light_right, \ | asmc_mbp_sysctl_light_right, \ | ||||
asmc_mbp_sysctl_light_control | asmc_mbp_sysctl_light_control | ||||
#define ASMC_LIGHT_FUNCS_10BYTE \ | |||||
asmc_mbp_sysctl_light_left_10byte, \ | |||||
NULL, \ | |||||
asmc_mbp_sysctl_light_control | |||||
markj: Extra newline. | |||||
#define ASMC_LIGHT_FUNCS_DISABLED NULL, NULL, NULL | #define ASMC_LIGHT_FUNCS_DISABLED NULL, NULL, NULL | ||||
static const struct asmc_model asmc_models[] = { | static const struct asmc_model asmc_models[] = { | ||||
{ | { | ||||
"MacBook1,1", "Apple SMC MacBook Core Duo", | "MacBook1,1", "Apple SMC MacBook Core Duo", | ||||
ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, NULL, NULL, NULL, | ASMC_SMS_FUNCS, ASMC_FAN_FUNCS, NULL, NULL, NULL, | ||||
ASMC_MB_TEMPS, ASMC_MB_TEMPNAMES, ASMC_MB_TEMPDESCS | ASMC_MB_TEMPS, ASMC_MB_TEMPNAMES, ASMC_MB_TEMPDESCS | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | static const struct asmc_model asmc_models[] = { | ||||
{ | { | ||||
"MacBookAir5,2", "Apple SMC MacBook Air 13-inch (Mid 2012)", | "MacBookAir5,2", "Apple SMC MacBook Air 13-inch (Mid 2012)", | ||||
ASMC_SMS_FUNCS_DISABLED, | ASMC_SMS_FUNCS_DISABLED, | ||||
ASMC_FAN_FUNCS2, | ASMC_FAN_FUNCS2, | ||||
ASMC_LIGHT_FUNCS, | ASMC_LIGHT_FUNCS, | ||||
ASMC_MBA5_TEMPS, ASMC_MBA5_TEMPNAMES, ASMC_MBA5_TEMPDESCS | 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)", | "MacBookAir6,2", "Apple SMC MacBook Air 13-inch (Early 2013)", | ||||
ASMC_SMS_FUNCS_DISABLED, | ASMC_SMS_FUNCS_DISABLED, | ||||
ASMC_FAN_FUNCS2, | ASMC_FAN_FUNCS2, | ||||
ASMC_LIGHT_FUNCS, | ASMC_LIGHT_FUNCS_10BYTE, | ||||
ASMC_MBA6_TEMPS, ASMC_MBA6_TEMPNAMES, ASMC_MBA6_TEMPDESCS | ASMC_MBA6_TEMPS, ASMC_MBA6_TEMPNAMES, ASMC_MBA6_TEMPDESCS | ||||
}, | }, | ||||
{ | { | ||||
"MacBookAir7,1", "Apple SMC MacBook Air 11-inch (Early 2015)", | "MacBookAir7,1", "Apple SMC MacBook Air 11-inch (Early 2015)", | ||||
ASMC_SMS_FUNCS_DISABLED, | ASMC_SMS_FUNCS_DISABLED, | ||||
ASMC_FAN_FUNCS2, | ASMC_FAN_FUNCS2, | ||||
ASMC_LIGHT_FUNCS, | ASMC_LIGHT_FUNCS, | ||||
ASMC_MBA7_TEMPS, ASMC_MBA7_TEMPNAMES, ASMC_MBA7_TEMPDESCS | ASMC_MBA7_TEMPS, ASMC_MBA7_TEMPNAMES, ASMC_MBA7_TEMPDESCS | ||||
▲ Show 20 Lines • Show All 1,090 Lines • ▼ Show 20 Lines | asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS) | ||||
if (error == 0 && req->newptr != NULL) { | if (error == 0 && req->newptr != NULL) { | ||||
if (v < 0 || v > 255) | if (v < 0 || v > 255) | ||||
return (EINVAL); | return (EINVAL); | ||||
light_control = v; | light_control = v; | ||||
buf[0] = light_control; | buf[0] = light_control; | ||||
buf[1] = 0x00; | buf[1] = 0x00; | ||||
asmc_key_write(dev, ASMC_KEY_LIGHTVALUE, buf, sizeof buf); | asmc_key_write(dev, ASMC_KEY_LIGHTVALUE, buf, sizeof buf); | ||||
} | } | ||||
return (error); | |||||
} | |||||
static int | |||||
asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS) | |||||
Done Inline Actions10 byte? markj: 10 byte? | |||||
{ | |||||
device_t dev = (device_t) arg1; | |||||
uint8_t buf[10]; | |||||
int error; | |||||
uint32_t v; | |||||
Done Inline Actionsv should probably be unsigned? markj: `v` should probably be unsigned? | |||||
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 | |||||
Done Inline ActionsThis can just be v = be32dec(&buf[6]);. markj: This can just be `v = be32dec(&buf[6]);`. | |||||
* earlier SMC firmware version responses. | |||||
*/ | |||||
v = v >> 8; | |||||
if (v > 255) | |||||
v = 255; | |||||
error = sysctl_handle_int(oidp, &v, 0, req); | |||||
return (error); | return (error); | ||||
} | } |
Extra newline.