asmc: code style modernization and minor cleanups
- Allow `ASMC_DEBUG` to be treated as a variadic macro. - Add ellipses around `sizeof(..)` calls. - Reindent some of the lines to better follow style(9) with line wrapping. A number of other clang-format changes were not taken as they are not compatible with style(9). MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55394
This commit is contained in:
+47
-59
@@ -549,9 +549,9 @@ static driver_t asmc_driver = {
|
|||||||
#define _COMPONENT ACPI_OEM
|
#define _COMPONENT ACPI_OEM
|
||||||
ACPI_MODULE_NAME("ASMC")
|
ACPI_MODULE_NAME("ASMC")
|
||||||
#ifdef ASMC_DEBUG
|
#ifdef ASMC_DEBUG
|
||||||
#define ASMC_DPRINTF(str) device_printf(dev, str)
|
#define ASMC_DPRINTF(str, ...) device_printf(dev, str, ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define ASMC_DPRINTF(str)
|
#define ASMC_DPRINTF(str, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* NB: can't be const */
|
/* NB: can't be const */
|
||||||
@@ -645,57 +645,50 @@ asmc_attach(device_t dev)
|
|||||||
name[0] = '0' + j;
|
name[0] = '0' + j;
|
||||||
name[1] = 0;
|
name[1] = 0;
|
||||||
sc->sc_fan_tree[i] = SYSCTL_ADD_NODE(sysctlctx,
|
sc->sc_fan_tree[i] = SYSCTL_ADD_NODE(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[0]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[0]), OID_AUTO, name,
|
||||||
OID_AUTO, name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
|
CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Fan Subtree");
|
||||||
"Fan Subtree");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "id",
|
OID_AUTO, "id",
|
||||||
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_id, "I",
|
model->smc_fan_id, "I", "Fan ID");
|
||||||
"Fan ID");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "speed",
|
OID_AUTO, "speed",
|
||||||
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_speed, "I",
|
model->smc_fan_speed, "I", "Fan speed in RPM");
|
||||||
"Fan speed in RPM");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "safespeed",
|
OID_AUTO, "safespeed",
|
||||||
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_safespeed, "I",
|
model->smc_fan_safespeed, "I", "Fan safe speed in RPM");
|
||||||
"Fan safe speed in RPM");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "minspeed",
|
OID_AUTO, "minspeed",
|
||||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_minspeed, "I",
|
model->smc_fan_minspeed, "I", "Fan minimum speed in RPM");
|
||||||
"Fan minimum speed in RPM");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "maxspeed",
|
OID_AUTO, "maxspeed",
|
||||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_maxspeed, "I",
|
model->smc_fan_maxspeed, "I", "Fan maximum speed in RPM");
|
||||||
"Fan maximum speed in RPM");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "targetspeed",
|
OID_AUTO, "targetspeed",
|
||||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, model->smc_fan_targetspeed, "I",
|
model->smc_fan_targetspeed, "I", "Fan target speed in RPM");
|
||||||
"Fan target speed in RPM");
|
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
|
||||||
OID_AUTO, "manual",
|
OID_AUTO, "manual",
|
||||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, dev, j,
|
||||||
dev, j, asmc_mb_sysctl_fanmanual, "I",
|
asmc_mb_sysctl_fanmanual, "I",
|
||||||
"Fan manual mode (0=auto, 1=manual)");
|
"Fan manual mode (0=auto, 1=manual)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,8 +703,8 @@ asmc_attach(device_t dev)
|
|||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_temp_tree),
|
SYSCTL_CHILDREN(sc->sc_temp_tree),
|
||||||
OID_AUTO, model->smc_tempnames[i],
|
OID_AUTO, model->smc_tempnames[i],
|
||||||
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, i,
|
||||||
dev, i, asmc_temp_sysctl, "I",
|
asmc_temp_sysctl, "I",
|
||||||
model->smc_tempdescs[i]);
|
model->smc_tempdescs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,16 +727,15 @@ asmc_attach(device_t dev)
|
|||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_light_tree),
|
SYSCTL_CHILDREN(sc->sc_light_tree),
|
||||||
OID_AUTO, "right",
|
OID_AUTO, "right",
|
||||||
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
|
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, 0,
|
||||||
dev, 0, model->smc_light_right, "I",
|
model->smc_light_right, "I",
|
||||||
"Keyboard backlight right sensor");
|
"Keyboard backlight right sensor");
|
||||||
|
|
||||||
SYSCTL_ADD_PROC(sysctlctx,
|
SYSCTL_ADD_PROC(sysctlctx,
|
||||||
SYSCTL_CHILDREN(sc->sc_light_tree),
|
SYSCTL_CHILDREN(sc->sc_light_tree),
|
||||||
OID_AUTO, "control",
|
OID_AUTO, "control",
|
||||||
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY |
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE,
|
||||||
CTLFLAG_MPSAFE, dev, 0,
|
dev, 0, model->smc_light_control, "I",
|
||||||
model->smc_light_control, "I",
|
|
||||||
"Keyboard backlight brightness control");
|
"Keyboard backlight brightness control");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,11 +798,8 @@ asmc_attach(device_t dev)
|
|||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bus_setup_intr(dev, sc->sc_irq,
|
ret = bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_MPSAFE,
|
||||||
INTR_TYPE_MISC | INTR_MPSAFE,
|
asmc_sms_intrfast, NULL, dev, &sc->sc_cookie);
|
||||||
asmc_sms_intrfast, NULL,
|
|
||||||
dev, &sc->sc_cookie);
|
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
device_printf(dev, "unable to setup SMS IRQ\n");
|
device_printf(dev, "unable to setup SMS IRQ\n");
|
||||||
goto err1;
|
goto err1;
|
||||||
@@ -858,7 +847,7 @@ asmc_resume(device_t dev)
|
|||||||
|
|
||||||
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 (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -959,8 +948,9 @@ asmc_init(device_t dev)
|
|||||||
nosms:
|
nosms:
|
||||||
sc->sc_nfan = asmc_fan_count(dev);
|
sc->sc_nfan = asmc_fan_count(dev);
|
||||||
if (sc->sc_nfan > ASMC_MAXFANS) {
|
if (sc->sc_nfan > ASMC_MAXFANS) {
|
||||||
device_printf(dev, "more than %d fans were detected. Please "
|
device_printf(dev,
|
||||||
"report this.\n", ASMC_MAXFANS);
|
"more than %d fans were detected. Please report this.\n",
|
||||||
|
ASMC_MAXFANS);
|
||||||
sc->sc_nfan = ASMC_MAXFANS;
|
sc->sc_nfan = ASMC_MAXFANS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1020,12 +1010,9 @@ asmc_wait(device_t dev, uint8_t val)
|
|||||||
|
|
||||||
#ifdef ASMC_DEBUG
|
#ifdef ASMC_DEBUG
|
||||||
sc = device_get_softc(dev);
|
sc = device_get_softc(dev);
|
||||||
#endif
|
|
||||||
val = val & ASMC_STATUS_MASK;
|
|
||||||
|
|
||||||
#ifdef ASMC_DEBUG
|
device_printf(dev, "%s failed: 0x%x, 0x%x\n", __func__,
|
||||||
device_printf(dev, "%s failed: 0x%x, 0x%x\n", __func__, val,
|
val & ASMC_STATUS_MASK, ASMC_CMDPORT_READ(sc));
|
||||||
ASMC_CMDPORT_READ(sc));
|
|
||||||
#endif
|
#endif
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -1166,16 +1153,17 @@ asmc_key_dump(device_t dev, int number)
|
|||||||
type[5] = 0;
|
type[5] = 0;
|
||||||
if (maxlen > sizeof(v)) {
|
if (maxlen > sizeof(v)) {
|
||||||
device_printf(dev,
|
device_printf(dev,
|
||||||
"WARNING: cropping maxlen from %d to %zu\n",
|
"WARNING: cropping maxlen from %d to %zu\n", maxlen,
|
||||||
maxlen, sizeof(v));
|
sizeof(v));
|
||||||
maxlen = sizeof(v);
|
maxlen = sizeof(v);
|
||||||
}
|
}
|
||||||
for (i = 0; i < sizeof(v); i++) {
|
for (i = 0; i < sizeof(v); i++) {
|
||||||
v[i] = 0;
|
v[i] = 0;
|
||||||
}
|
}
|
||||||
asmc_key_read(dev, key, v, maxlen);
|
asmc_key_read(dev, key, v, maxlen);
|
||||||
snprintf(buf, sizeof(buf), "key %d is: %s, type %s "
|
snprintf(buf, sizeof(buf),
|
||||||
"(len %d), data", number, key, type, maxlen);
|
"key %d is: %s, type %s (len %d), data",
|
||||||
|
number, key, type, maxlen);
|
||||||
for (i = 0; i < maxlen; i++) {
|
for (i = 0; i < maxlen; i++) {
|
||||||
snprintf(buf2, sizeof(buf2), " %02x", v[i]);
|
snprintf(buf2, sizeof(buf2), " %02x", v[i]);
|
||||||
strlcat(buf, buf2, sizeof(buf));
|
strlcat(buf, buf2, sizeof(buf));
|
||||||
@@ -1239,7 +1227,7 @@ asmc_fan_count(device_t dev)
|
|||||||
{
|
{
|
||||||
uint8_t buf[1];
|
uint8_t buf[1];
|
||||||
|
|
||||||
if (asmc_key_read(dev, ASMC_KEY_FANCOUNT, buf, sizeof buf) != 0)
|
if (asmc_key_read(dev, ASMC_KEY_FANCOUNT, buf, sizeof(buf)) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (buf[0]);
|
return (buf[0]);
|
||||||
@@ -1253,7 +1241,7 @@ asmc_fan_getvalue(device_t dev, const char *key, int fan)
|
|||||||
char fankey[5];
|
char fankey[5];
|
||||||
|
|
||||||
snprintf(fankey, sizeof(fankey), key, fan);
|
snprintf(fankey, sizeof(fankey), key, fan);
|
||||||
if (asmc_key_read(dev, fankey, buf, sizeof buf) != 0)
|
if (asmc_key_read(dev, fankey, buf, sizeof(buf)) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
speed = (buf[0] << 6) | (buf[1] >> 2);
|
speed = (buf[0] << 6) | (buf[1] >> 2);
|
||||||
|
|
||||||
@@ -1287,7 +1275,7 @@ asmc_fan_setvalue(device_t dev, const char *key, int fan, int speed)
|
|||||||
buf[1] = speed;
|
buf[1] = speed;
|
||||||
|
|
||||||
snprintf(fankey, sizeof(fankey), key, fan);
|
snprintf(fankey, sizeof(fankey), key, fan);
|
||||||
if (asmc_key_write(dev, fankey, buf, sizeof buf) < 0)
|
if (asmc_key_write(dev, fankey, buf, sizeof(buf)) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -1455,7 +1443,7 @@ asmc_temp_getvalue(device_t dev, const char *key)
|
|||||||
/*
|
/*
|
||||||
* Check for invalid temperatures.
|
* Check for invalid temperatures.
|
||||||
*/
|
*/
|
||||||
if (asmc_key_read(dev, key, buf, sizeof buf) != 0)
|
if (asmc_key_read(dev, key, buf, sizeof(buf)) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
return (buf[0]);
|
return (buf[0]);
|
||||||
@@ -1488,12 +1476,12 @@ asmc_sms_read(device_t dev, const char *key, int16_t *val)
|
|||||||
case 'X':
|
case 'X':
|
||||||
case 'Y':
|
case 'Y':
|
||||||
case 'Z':
|
case 'Z':
|
||||||
error = asmc_key_read(dev, key, buf, sizeof buf);
|
error = asmc_key_read(dev, key, buf, sizeof(buf));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
device_printf(dev, "%s called with invalid argument %s\n",
|
device_printf(dev, "%s called with invalid argument %s\n",
|
||||||
__func__, key);
|
__func__, key);
|
||||||
error = 1;
|
error = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
*val = ((int16_t)buf[0] << 8) | buf[1];
|
*val = ((int16_t)buf[0] << 8) | buf[1];
|
||||||
@@ -1638,7 +1626,7 @@ asmc_mbp_sysctl_light_left(SYSCTL_HANDLER_ARGS)
|
|||||||
int error;
|
int error;
|
||||||
int32_t v;
|
int32_t v;
|
||||||
|
|
||||||
asmc_key_read(dev, ASMC_KEY_LIGHTLEFT, buf, sizeof buf);
|
asmc_key_read(dev, ASMC_KEY_LIGHTLEFT, buf, sizeof(buf));
|
||||||
v = buf[2];
|
v = buf[2];
|
||||||
error = sysctl_handle_int(oidp, &v, 0, req);
|
error = sysctl_handle_int(oidp, &v, 0, req);
|
||||||
|
|
||||||
@@ -1653,7 +1641,7 @@ asmc_mbp_sysctl_light_right(SYSCTL_HANDLER_ARGS)
|
|||||||
int error;
|
int error;
|
||||||
int32_t v;
|
int32_t v;
|
||||||
|
|
||||||
asmc_key_read(dev, ASMC_KEY_LIGHTRIGHT, buf, sizeof buf);
|
asmc_key_read(dev, ASMC_KEY_LIGHTRIGHT, buf, sizeof(buf));
|
||||||
v = buf[2];
|
v = buf[2];
|
||||||
error = sysctl_handle_int(oidp, &v, 0, req);
|
error = sysctl_handle_int(oidp, &v, 0, req);
|
||||||
|
|
||||||
@@ -1677,7 +1665,7 @@ asmc_mbp_sysctl_light_control(SYSCTL_HANDLER_ARGS)
|
|||||||
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);
|
return (error);
|
||||||
}
|
}
|
||||||
@@ -1690,7 +1678,7 @@ asmc_mbp_sysctl_light_left_10byte(SYSCTL_HANDLER_ARGS)
|
|||||||
int error;
|
int error;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
|
|
||||||
asmc_key_read(dev, ASMC_KEY_LIGHTLEFT, buf, sizeof buf);
|
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].
|
* This seems to be a 32 bit big endian value from buf[6] -> buf[9].
|
||||||
|
|||||||
Reference in New Issue
Block a user