Lines Matching +full:0 +full:- +full:inch

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
186 "MacBookPro1,1", "Apple SMC MacBook Pro Core Duo (15-inch)",
192 "MacBookPro1,2", "Apple SMC MacBook Pro Core Duo (17-inch)",
198 "MacBookPro2,1", "Apple SMC MacBook Pro Core 2 Duo (17-inch)",
204 "MacBookPro2,2", "Apple SMC MacBook Pro Core 2 Duo (15-inch)",
210 "MacBookPro3,1", "Apple SMC MacBook Pro Core 2 Duo (15-inch LED)",
216 "MacBookPro3,2", "Apple SMC MacBook Pro Core 2 Duo (17-inch HD)",
240 "MacBookPro6,2", "Apple SMC MacBook Pro (Mid 2010, 15-inch)",
246 "MacBookPro8,1", "Apple SMC MacBook Pro (early 2011, 13-inch)",
258 "MacBookPro9,1", "Apple SMC MacBook Pro (mid 2012, 15-inch)",
264 "MacBookPro9,2", "Apple SMC MacBook Pro (mid 2012, 13-inch)",
282 "MacBookPro11,4", "Apple SMC MacBook Pro Retina Core i7 (mid 2015, 15-inch)",
314 /* The Mac Mini 4,1 (Mid-2010) has no SMS */
316 "Macmini4,1", "Apple SMC Mac mini 4,1 (Mid-2010)",
324 /* - same sensors as Mac Mini 5,2 */
343 /* - same sensors as Mac Mini 5,2 */
370 /* Idem for the Mac Pro (8-core) */
372 "MacPro2", "Apple SMC Mac Pro (8-core)",
410 "MacBookAir4,1", "Apple SMC Macbook Air 11-inch (Mid 2011)",
418 "MacBookAir4,2", "Apple SMC Macbook Air 13-inch (Mid 2011)",
426 "MacBookAir5,1", "Apple SMC MacBook Air 11-inch (Mid 2012)",
434 "MacBookAir5,2", "Apple SMC MacBook Air 13-inch (Mid 2012)",
441 "MacBookAir6,1", "Apple SMC MacBook Air 11-inch (Early 2013)",
448 "MacBookAir6,2", "Apple SMC MacBook Air 13-inch (Early 2013)",
455 "MacBookAir7,1", "Apple SMC MacBook Air 11-inch (Early 2015)",
462 "MacBookAir7,2", "Apple SMC MacBook Air 13-inch (Early 2015)",
485 { 0, 0 }
508 static unsigned int light_control = 0;
523 for (i = 0; asmc_models[i].smc_model; i++) {
540 if (resource_disabled("asmc", 0))
543 if (rv > 0)
551 device_set_desc(dev, model->smc_desc);
567 sc->sc_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
568 &sc->sc_rid_port, RF_ACTIVE);
569 if (sc->sc_ioport == NULL) {
579 mtx_init(&sc->sc_mtx, "asmc", NULL, MTX_SPIN);
581 sc->sc_model = model;
587 sc->sc_fan_tree[0] = SYSCTL_ADD_NODE(sysctlctx,
589 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Fan Root Tree");
591 for (i = 1; i <= sc->sc_nfan; i++) {
592 j = i - 1;
593 name[0] = '0' + j;
594 name[1] = 0;
595 sc->sc_fan_tree[i] = SYSCTL_ADD_NODE(sysctlctx,
596 SYSCTL_CHILDREN(sc->sc_fan_tree[0]),
597 OID_AUTO, name, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
601 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
604 dev, j, model->smc_fan_id, "I",
608 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
611 dev, j, model->smc_fan_speed, "I",
615 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
618 dev, j, model->smc_fan_safespeed, "I",
622 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
625 dev, j, model->smc_fan_minspeed, "I",
629 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
632 dev, j, model->smc_fan_maxspeed, "I",
636 SYSCTL_CHILDREN(sc->sc_fan_tree[i]),
639 dev, j, model->smc_fan_targetspeed, "I",
646 sc->sc_temp_tree = SYSCTL_ADD_NODE(sysctlctx,
648 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Temperature sensors");
650 for (i = 0; model->smc_temps[i]; i++) {
652 SYSCTL_CHILDREN(sc->sc_temp_tree),
653 OID_AUTO, model->smc_tempnames[i],
656 model->smc_tempdescs[i]);
662 if (model->smc_light_left) {
663 sc->sc_light_tree = SYSCTL_ADD_NODE(sysctlctx,
665 CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
669 SYSCTL_CHILDREN(sc->sc_light_tree),
672 dev, 0, model->smc_light_left, "I",
676 SYSCTL_CHILDREN(sc->sc_light_tree),
679 dev, 0, model->smc_light_right, "I",
683 SYSCTL_CHILDREN(sc->sc_light_tree),
686 CTLFLAG_NEEDGIANT, dev, 0,
687 model->smc_light_control, "I",
691 if (model->smc_sms_x == NULL)
697 sc->sc_sms_tree = SYSCTL_ADD_NODE(sysctlctx,
699 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Sudden Motion Sensor");
702 SYSCTL_CHILDREN(sc->sc_sms_tree),
705 dev, 0, model->smc_sms_x, "I",
709 SYSCTL_CHILDREN(sc->sc_sms_tree),
712 dev, 0, model->smc_sms_y, "I",
716 SYSCTL_CHILDREN(sc->sc_sms_tree),
719 dev, 0, model->smc_sms_z, "I",
732 sc->sc_sms_tq = NULL;
733 TASK_INIT(&sc->sc_sms_task, 0, asmc_sms_task, sc);
734 sc->sc_sms_tq = taskqueue_create_fast("asmc_taskq", M_WAITOK,
735 taskqueue_thread_enqueue, &sc->sc_sms_tq);
736 taskqueue_start_threads(&sc->sc_sms_tq, 1, PI_REALTIME, "%s sms taskq",
741 sc->sc_rid_irq = 0;
742 sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
743 &sc->sc_rid_irq, RF_ACTIVE);
744 if (sc->sc_irq == NULL) {
750 ret = bus_setup_intr(dev, sc->sc_irq,
753 dev, &sc->sc_cookie);
760 return (0);
762 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid_irq, sc->sc_irq);
764 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_rid_port,
765 sc->sc_ioport);
766 mtx_destroy(&sc->sc_mtx);
767 if (sc->sc_sms_tq)
768 taskqueue_free(sc->sc_sms_tq);
778 if (sc->sc_sms_tq) {
779 taskqueue_drain(sc->sc_sms_tq, &sc->sc_sms_task);
780 taskqueue_free(sc->sc_sms_tq);
782 if (sc->sc_cookie)
783 bus_teardown_intr(dev, sc->sc_irq, sc->sc_cookie);
784 if (sc->sc_irq)
785 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid_irq,
786 sc->sc_irq);
787 if (sc->sc_ioport)
788 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_rid_port,
789 sc->sc_ioport);
790 mtx_destroy(&sc->sc_mtx);
792 return (0);
799 buf[0] = light_control;
800 buf[1] = 0x00;
802 return (0);
811 for (i=0; i < 0x100; i++)
823 if (sc->sc_model->smc_sms_x == NULL)
829 buf[0] = 0x01;
837 buf[0] = 20; /* msecs */
842 buf[0] = 20; /* msecs */
847 buf[0] = 0x00;
848 buf[1] = 0x60;
853 buf[0] = 0x01;
854 buf[1] = 0xc0;
863 buf[0] = 0x01;
868 sc->sc_sms_intr_works = 0;
874 for (i = 0; i < 1000; i++) {
875 if (asmc_key_read(dev, ASMC_KEY_SMS, buf, 2) == 0 &&
876 (buf[0] == ASMC_SMS_INIT1 && buf[1] == ASMC_SMS_INIT2)) {
877 error = 0;
878 sc->sc_sms_intr_works = 1;
881 buf[0] = ASMC_SMS_INIT1;
892 sc->sc_nfan = asmc_fan_count(dev);
893 if (sc->sc_nfan > ASMC_MAXFANS) {
896 sc->sc_nfan = ASMC_MAXFANS;
926 for (i = 0; i < amount; i++) {
928 return (0);
946 if (asmc_wait_ack(dev, val, 1000) == 0)
947 return (0);
955 device_printf(dev, "%s failed: 0x%x, 0x%x\n", __func__, val,
970 for (i=0; i < 10; i++) {
972 if (asmc_wait_ack(dev, 0x0c, 100) == 0) {
973 return (0);
978 device_printf(dev, "%s failed: 0x%x, 0x%x\n", __func__, command,
987 int i, error = 1, try = 0;
990 mtx_lock_spin(&sc->sc_mtx);
996 for (i = 0; i < 4; i++) {
998 if (asmc_wait(dev, 0x04))
1004 for (i = 0; i < len; i++) {
1005 if (asmc_wait(dev, 0x05))
1010 error = 0;
1018 mtx_unlock_spin(&sc->sc_mtx);
1028 char key[5] = { 0 };
1029 char type[7] = { 0 };
1033 int i, error = 1, try = 0;
1035 mtx_lock_spin(&sc->sc_mtx);
1037 index[0] = (number >> 24) & 0xff;
1038 index[1] = (number >> 16) & 0xff;
1039 index[2] = (number >> 8) & 0xff;
1040 index[3] = (number) & 0xff;
1043 if (asmc_command(dev, 0x12))
1046 for (i = 0; i < 4; i++) {
1048 if (asmc_wait(dev, 0x04))
1054 for (i = 0; i < 4; i++) {
1055 if (asmc_wait(dev, 0x05))
1061 if (asmc_command(dev, 0x13))
1064 for (i = 0; i < 4; i++) {
1066 if (asmc_wait(dev, 0x04))
1072 for (i = 0; i < 6; i++) {
1073 if (asmc_wait(dev, 0x05))
1078 error = 0;
1084 mtx_unlock_spin(&sc->sc_mtx);
1089 mtx_unlock_spin(&sc->sc_mtx);
1090 maxlen = type[0];
1091 type[0] = ' ';
1092 type[5] = 0;
1099 for (i = 0; i < sizeof(v); i++) {
1100 v[i] = 0;
1105 for (i = 0; i < maxlen; i++) {
1120 int i, error = -1, try = 0;
1123 mtx_lock_spin(&sc->sc_mtx);
1131 for (i = 0; i < 4; i++) {
1133 if (asmc_wait(dev, 0x04))
1140 for (i = 0; i < len; i++) {
1141 if (asmc_wait(dev, 0x04))
1146 error = 0;
1154 mtx_unlock_spin(&sc->sc_mtx);
1168 if (asmc_key_read(dev, ASMC_KEY_FANCOUNT, buf, sizeof buf) != 0)
1169 return (-1);
1171 return (buf[0]);
1182 if (asmc_key_read(dev, fankey, buf, sizeof buf) != 0)
1183 return (-1);
1184 speed = (buf[0] << 6) | (buf[1] >> 2);
1196 if (asmc_key_read(dev, fankey, buf, buflen) != 0)
1211 buf[0] = speed>>8;
1215 if (asmc_key_write(dev, fankey, buf, sizeof buf) < 0)
1216 return (-1);
1218 return (0);
1230 error = sysctl_handle_int(oidp, &v, 0, req);
1247 error = sysctl_handle_string(oidp, desc, 0, req);
1261 error = sysctl_handle_int(oidp, &v, 0, req);
1275 error = sysctl_handle_int(oidp, &v, 0, req);
1277 if (error == 0 && req->newptr != NULL) {
1294 error = sysctl_handle_int(oidp, &v, 0, req);
1296 if (error == 0 && req->newptr != NULL) {
1313 error = sysctl_handle_int(oidp, &v, 0, req);
1315 if (error == 0 && req->newptr != NULL) {
1334 if (asmc_key_read(dev, key, buf, sizeof buf) != 0)
1335 return (-1);
1337 return (buf[0]);
1347 val = asmc_temp_getvalue(dev, sc->sc_model->smc_temps[arg2]);
1348 error = sysctl_handle_int(oidp, &val, 0, req);
1375 *val = ((int16_t)buf[0] << 8) | buf[1];
1385 asmc_sms_read(dev, ASMC_KEY_SMS_X, &sc->sms_rest_x);
1386 asmc_sms_read(dev, ASMC_KEY_SMS_Y, &sc->sms_rest_y);
1387 asmc_sms_read(dev, ASMC_KEY_SMS_Z, &sc->sms_rest_z);
1396 if (!sc->sc_sms_intr_works)
1399 mtx_lock_spin(&sc->sc_mtx);
1401 mtx_unlock_spin(&sc->sc_mtx);
1403 sc->sc_sms_intrtype = type;
1406 taskqueue_enqueue(sc->sc_sms_tq, &sc->sc_sms_task);
1430 if (strcmp(sc->sc_model->smc_model, "MacBookPro5,5") == 0 ||
1431 strcmp(sc->sc_model->smc_model, "MacBookPro6,2") == 0)
1435 device_printf(dev, "unknown interrupt: 0x%x\n", type);
1446 switch (sc->sc_sms_intrtype) {
1454 type = 0;
1460 snprintf(notify, sizeof(notify), " notify=0x%x", type);
1474 error = sysctl_handle_int(oidp, &v, 0, req);
1489 error = sysctl_handle_int(oidp, &v, 0, req);
1504 error = sysctl_handle_int(oidp, &v, 0, req);
1519 error = sysctl_handle_int(oidp, &v, 0, req);
1534 error = sysctl_handle_int(oidp, &v, 0, req);
1548 error = sysctl_handle_int(oidp, &v, 0, req);
1550 if (error == 0 && req->newptr != NULL) {
1551 if (v < 0 || v > 255)
1554 buf[0] = light_control;
1555 buf[1] = 0x00;
1572 * This seems to be a 32 bit big endian value from buf[6] -> buf[9].
1586 error = sysctl_handle_int(oidp, &v, 0, req);