1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2007, 2008 Rui Paulo <rpaulo@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #define ASMC_MAXFANS 6 31 #define ASMC_MAXVAL 32 /* Maximum SMC value size */ 32 #define ASMC_KEYLEN 4 /* SMC key name length */ 33 #define ASMC_TYPELEN 4 /* SMC type string length */ 34 #define ASMC_MAX_SENSORS 64 /* Max sensors per type */ 35 36 /* Maximum number of auto-detected temperature sensors */ 37 #define ASMC_TEMP_MAX 80 38 39 struct asmc_softc { 40 device_t sc_dev; 41 struct mtx sc_mtx; 42 int sc_nfan; 43 int sc_nkeys; 44 int16_t sms_rest_x; 45 int16_t sms_rest_y; 46 int16_t sms_rest_z; 47 struct sysctl_oid *sc_fan_tree[ASMC_MAXFANS+1]; 48 struct sysctl_oid *sc_temp_tree; 49 struct sysctl_oid *sc_sms_tree; 50 struct sysctl_oid *sc_light_tree; 51 int sc_rid_port; 52 int sc_rid_irq; 53 struct resource *sc_ioport; 54 struct resource *sc_irq; 55 void *sc_cookie; 56 int sc_sms_intrtype; 57 struct taskqueue *sc_sms_tq; 58 struct task sc_sms_task; 59 uint8_t sc_sms_intr_works; 60 struct cdev *sc_kbd_bkl; 61 uint32_t sc_kbd_bkl_level; 62 #ifdef ASMC_DEBUG 63 /* Raw key access */ 64 struct sysctl_oid *sc_raw_tree; 65 char sc_rawkey[ASMC_KEYLEN + 1]; 66 uint8_t sc_rawval[ASMC_MAXVAL]; 67 uint8_t sc_rawlen; 68 char sc_rawtype[ASMC_TYPELEN + 1]; 69 #endif 70 /* Voltage/Current/Power/Light sensors */ 71 char *sc_voltage_sensors[ASMC_MAX_SENSORS]; 72 int sc_voltage_count; 73 char *sc_current_sensors[ASMC_MAX_SENSORS]; 74 int sc_current_count; 75 char *sc_power_sensors[ASMC_MAX_SENSORS]; 76 int sc_power_count; 77 char *sc_light_sensors[ASMC_MAX_SENSORS]; 78 int sc_light_count; 79 /* Auto-detected temperature sensors */ 80 char *sc_temp_sensors[ASMC_TEMP_MAX]; 81 int sc_temp_count; 82 /* Auto-detected capabilities */ 83 int sc_has_sms; 84 int sc_has_light; 85 int sc_light_len; /* ASMC_LIGHT_{SHORT,LONG}LEN */ 86 int sc_has_safespeed; 87 int sc_has_alsl; /* ALSL interrupt source */ 88 }; 89 90 /* 91 * Data port. 92 */ 93 #define ASMC_DATAPORT_READ(sc) bus_read_1(sc->sc_ioport, 0x00) 94 #define ASMC_DATAPORT_WRITE(sc, val) \ 95 bus_write_1(sc->sc_ioport, 0x00, val) 96 #define ASMC_STATUS_MASK 0x0f 97 98 /* 99 * Command port. 100 */ 101 #define ASMC_CMDPORT_READ(sc) bus_read_1(sc->sc_ioport, 0x04) 102 #define ASMC_CMDPORT_WRITE(sc, val) \ 103 bus_write_1(sc->sc_ioport, 0x04, val) 104 #define ASMC_CMDREAD 0x10 105 #define ASMC_CMDWRITE 0x11 106 #define ASMC_CMDGETBYINDEX 0x12 107 #define ASMC_CMDGETINFO 0x13 108 109 #define ASMC_STATUS_AWAIT_DATA 0x04 110 #define ASMC_STATUS_DATA_READY 0x05 111 112 #define ASMC_KEYINFO_RESPLEN 6 /* getinfo: 1 len + 4 type + 1 attr */ 113 #define ASMC_MAXRETRIES 10 114 115 /* 116 * Interrupt port. 117 */ 118 #define ASMC_INTPORT_READ(sc) bus_read_1(sc->sc_ioport, 0x1f) 119 120 /* Number of keys */ 121 #define ASMC_NKEYS "#KEY" /* RO; 4 bytes */ 122 123 /* Query the ASMC revision */ 124 #define ASMC_KEY_REV "REV " /* RO: 6 bytes */ 125 126 /* 127 * Fan control via SMC. 128 */ 129 #define ASMC_KEY_FANCOUNT "FNum" /* RO; 1 byte */ 130 #define ASMC_KEY_FANMANUAL "FS! " /* RW; 2 bytes */ 131 #define ASMC_KEY_FANID "F%dID" /* RO; 16 bytes */ 132 #define ASMC_KEY_FANSPEED "F%dAc" /* RO; 2 bytes */ 133 #define ASMC_KEY_FANMINSPEED "F%dMn" /* RW; 2 bytes */ 134 #define ASMC_KEY_FANMAXSPEED "F%dMx" /* RO; 2 bytes */ 135 #define ASMC_KEY_FANSAFESPEED "F%dSf" /* RO; 2 bytes */ 136 #define ASMC_KEY_FANTARGETSPEED "F%dTg" /* RW; 2 bytes */ 137 138 /* 139 * Sudden Motion Sensor (SMS). 140 */ 141 #define ASMC_SMS_INIT1 0xe0 142 #define ASMC_SMS_INIT2 0xf8 143 #define ASMC_KEY_SMS "MOCN" /* RW; 2 bytes */ 144 #define ASMC_KEY_SMS_X "MO_X" /* RO; 2 bytes */ 145 #define ASMC_KEY_SMS_Y "MO_Y" /* RO; 2 bytes */ 146 #define ASMC_KEY_SMS_Z "MO_Z" /* RO; 2 bytes */ 147 #define ASMC_KEY_SMS_LOW "MOLT" /* RW; 2 bytes */ 148 #define ASMC_KEY_SMS_HIGH "MOHT" /* RW; 2 bytes */ 149 #define ASMC_KEY_SMS_LOW_INT "MOLD" /* RW; 1 byte */ 150 #define ASMC_KEY_SMS_HIGH_INT "MOHD" /* RW; 1 byte */ 151 #define ASMC_KEY_SMS_FLAG "MSDW" /* RW; 1 byte */ 152 #define ASMC_SMS_INTFF 0x60 /* Free fall Interrupt */ 153 #define ASMC_SMS_INTHA 0x6f /* High Acceleration Interrupt */ 154 #define ASMC_SMS_INTSH 0x80 /* Shock Interrupt */ 155 156 /* 157 * Light Sensor. 158 */ 159 #define ASMC_ALSL_INT2A 0x2a /* Ambient Light related Interrupt */ 160 161 /* 162 * Keyboard backlight. 163 */ 164 #define ASMC_LIGHT_SHORTLEN 6 /* ALV0 short format */ 165 #define ASMC_LIGHT_LONGLEN 10 /* ALV0 long format (10-byte) */ 166 #define ASMC_KEY_LIGHTLEFT "ALV0" /* RO; 6 or 10 bytes */ 167 #define ASMC_KEY_LIGHTRIGHT "ALV1" /* RO; 6 bytes */ 168 #define ASMC_KEY_LIGHTVALUE "LKSB" /* WO; 2 bytes */ 169 #define ASMC_KEY_LIGHTSRC "ALSL" /* RO; ambient light source */ 170 #define ASMC_KEY_FANSAFESPEED0 "F0Sf" /* RO; 2 bytes */ 171 172 /* 173 * Clamshell. 174 */ 175 #define ASMC_KEY_CLAMSHELL "MSLD" /* RO; 1 byte */ 176 177 /* 178 * Auto power-on after AC power loss (AUPO). 179 * When set, the machine boots automatically when AC power is restored 180 * after an unclean power loss. This is NOT Wake-on-LAN. 181 */ 182 #define ASMC_KEY_AUPO "AUPO" /* RW; 1 byte */ 183 184 /* 185 * Interrupt keys. 186 */ 187 #define ASMC_KEY_INTOK "NTOK" /* WO; 1 byte */ 188