applesmc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /*
  2. * drivers/hwmon/applesmc.c - driver for Apple's SMC (accelerometer, temperature
  3. * sensors, fan control, keyboard backlight control) used in Intel-based Apple
  4. * computers.
  5. *
  6. * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
  7. * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
  8. *
  9. * Based on hdaps.c driver:
  10. * Copyright (C) 2005 Robert Love <rml@novell.com>
  11. * Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com>
  12. *
  13. * Fan control based on smcFanControl:
  14. * Copyright (C) 2006 Hendrik Holtmann <holtmann@mac.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License v2 as published by the
  18. * Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful, but WITHOUT
  21. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  22. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  23. * more details.
  24. *
  25. * You should have received a copy of the GNU General Public License along with
  26. * this program; if not, write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/delay.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/input-polldev.h>
  33. #include <linux/kernel.h>
  34. #include <linux/slab.h>
  35. #include <linux/module.h>
  36. #include <linux/timer.h>
  37. #include <linux/dmi.h>
  38. #include <linux/mutex.h>
  39. #include <linux/hwmon-sysfs.h>
  40. #include <linux/io.h>
  41. #include <linux/leds.h>
  42. #include <linux/hwmon.h>
  43. #include <linux/workqueue.h>
  44. /* data port used by Apple SMC */
  45. #define APPLESMC_DATA_PORT 0x300
  46. /* command/status port used by Apple SMC */
  47. #define APPLESMC_CMD_PORT 0x304
  48. #define APPLESMC_NR_PORTS 32 /* 0x300-0x31f */
  49. #define APPLESMC_MAX_DATA_LENGTH 32
  50. /* wait up to 32 ms for a status change. */
  51. #define APPLESMC_MIN_WAIT 0x0040
  52. #define APPLESMC_MAX_WAIT 0x8000
  53. #define APPLESMC_STATUS_MASK 0x0f
  54. #define APPLESMC_READ_CMD 0x10
  55. #define APPLESMC_WRITE_CMD 0x11
  56. #define APPLESMC_GET_KEY_BY_INDEX_CMD 0x12
  57. #define APPLESMC_GET_KEY_TYPE_CMD 0x13
  58. #define KEY_COUNT_KEY "#KEY" /* r-o ui32 */
  59. #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6-10 bytes) */
  60. #define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6-10 bytes) */
  61. #define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */
  62. #define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */
  63. #define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */
  64. #define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */
  65. #define MOTION_SENSOR_Z_KEY "MO_Z" /* r-o sp78 (2 bytes) */
  66. #define MOTION_SENSOR_KEY "MOCN" /* r/w ui16 */
  67. #define FANS_COUNT "FNum" /* r-o ui8 */
  68. #define FANS_MANUAL "FS! " /* r-w ui16 */
  69. #define FAN_ID_FMT "F%dID" /* r-o char[16] */
  70. /* List of keys used to read/write fan speeds */
  71. static const char *const fan_speed_fmt[] = {
  72. "F%dAc", /* actual speed */
  73. "F%dMn", /* minimum speed (rw) */
  74. "F%dMx", /* maximum speed */
  75. "F%dSf", /* safe speed - not all models */
  76. "F%dTg", /* target speed (manual: rw) */
  77. };
  78. #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */
  79. #define INIT_WAIT_MSECS 50 /* ... in 50ms increments */
  80. #define APPLESMC_POLL_INTERVAL 50 /* msecs */
  81. #define APPLESMC_INPUT_FUZZ 4 /* input event threshold */
  82. #define APPLESMC_INPUT_FLAT 4
  83. #define SENSOR_X 0
  84. #define SENSOR_Y 1
  85. #define SENSOR_Z 2
  86. #define to_index(attr) (to_sensor_dev_attr(attr)->index & 0xffff)
  87. #define to_option(attr) (to_sensor_dev_attr(attr)->index >> 16)
  88. /* Dynamic device node attributes */
  89. struct applesmc_dev_attr {
  90. struct sensor_device_attribute sda; /* hwmon attributes */
  91. char name[32]; /* room for node file name */
  92. };
  93. /* Dynamic device node group */
  94. struct applesmc_node_group {
  95. char *format; /* format string */
  96. void *show; /* show function */
  97. void *store; /* store function */
  98. int option; /* function argument */
  99. struct applesmc_dev_attr *nodes; /* dynamic node array */
  100. };
  101. /* AppleSMC entry - cached register information */
  102. struct applesmc_entry {
  103. char key[5]; /* four-letter key code */
  104. u8 valid; /* set when entry is successfully read once */
  105. u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */
  106. char type[5]; /* four-letter type code */
  107. u8 flags; /* 0x10: func; 0x40: write; 0x80: read */
  108. };
  109. /* Register lookup and registers common to all SMCs */
  110. static struct applesmc_registers {
  111. struct mutex mutex; /* register read/write mutex */
  112. unsigned int key_count; /* number of SMC registers */
  113. unsigned int fan_count; /* number of fans */
  114. unsigned int temp_count; /* number of temperature registers */
  115. unsigned int temp_begin; /* temperature lower index bound */
  116. unsigned int temp_end; /* temperature upper index bound */
  117. int num_light_sensors; /* number of light sensors */
  118. bool has_accelerometer; /* has motion sensor */
  119. bool has_key_backlight; /* has keyboard backlight */
  120. bool init_complete; /* true when fully initialized */
  121. struct applesmc_entry *cache; /* cached key entries */
  122. } smcreg = {
  123. .mutex = __MUTEX_INITIALIZER(smcreg.mutex),
  124. };
  125. static const int debug;
  126. static struct platform_device *pdev;
  127. static s16 rest_x;
  128. static s16 rest_y;
  129. static u8 backlight_state[2];
  130. static struct device *hwmon_dev;
  131. static struct input_polled_dev *applesmc_idev;
  132. /*
  133. * Last index written to key_at_index sysfs file, and value to use for all other
  134. * key_at_index_* sysfs files.
  135. */
  136. static unsigned int key_at_index;
  137. static struct workqueue_struct *applesmc_led_wq;
  138. /*
  139. * __wait_status - Wait up to 32ms for the status port to get a certain value
  140. * (masked with 0x0f), returning zero if the value is obtained. Callers must
  141. * hold applesmc_lock.
  142. */
  143. static int __wait_status(u8 val)
  144. {
  145. int us;
  146. val = val & APPLESMC_STATUS_MASK;
  147. for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
  148. udelay(us);
  149. if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) {
  150. return 0;
  151. }
  152. }
  153. return -EIO;
  154. }
  155. /*
  156. * special treatment of command port - on newer macbooks, it seems necessary
  157. * to resend the command byte before polling the status again. Callers must
  158. * hold applesmc_lock.
  159. */
  160. static int send_command(u8 cmd)
  161. {
  162. int us;
  163. for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
  164. outb(cmd, APPLESMC_CMD_PORT);
  165. udelay(us);
  166. if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c)
  167. return 0;
  168. }
  169. return -EIO;
  170. }
  171. static int send_argument(const char *key)
  172. {
  173. int i;
  174. for (i = 0; i < 4; i++) {
  175. outb(key[i], APPLESMC_DATA_PORT);
  176. if (__wait_status(0x04))
  177. return -EIO;
  178. }
  179. return 0;
  180. }
  181. static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
  182. {
  183. int i;
  184. if (send_command(cmd) || send_argument(key)) {
  185. pr_warn("%s: read arg fail\n", key);
  186. return -EIO;
  187. }
  188. outb(len, APPLESMC_DATA_PORT);
  189. for (i = 0; i < len; i++) {
  190. if (__wait_status(0x05)) {
  191. pr_warn("%s: read data fail\n", key);
  192. return -EIO;
  193. }
  194. buffer[i] = inb(APPLESMC_DATA_PORT);
  195. }
  196. return 0;
  197. }
  198. static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
  199. {
  200. int i;
  201. if (send_command(cmd) || send_argument(key)) {
  202. pr_warn("%s: write arg fail\n", key);
  203. return -EIO;
  204. }
  205. outb(len, APPLESMC_DATA_PORT);
  206. for (i = 0; i < len; i++) {
  207. if (__wait_status(0x04)) {
  208. pr_warn("%s: write data fail\n", key);
  209. return -EIO;
  210. }
  211. outb(buffer[i], APPLESMC_DATA_PORT);
  212. }
  213. return 0;
  214. }
  215. static int read_register_count(unsigned int *count)
  216. {
  217. __be32 be;
  218. int ret;
  219. ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, (u8 *)&be, 4);
  220. if (ret)
  221. return ret;
  222. *count = be32_to_cpu(be);
  223. return 0;
  224. }
  225. /*
  226. * Serialized I/O
  227. *
  228. * Returns zero on success or a negative error on failure.
  229. * All functions below are concurrency safe - callers should NOT hold lock.
  230. */
  231. static int applesmc_read_entry(const struct applesmc_entry *entry,
  232. u8 *buf, u8 len)
  233. {
  234. int ret;
  235. if (entry->len != len)
  236. return -EINVAL;
  237. mutex_lock(&smcreg.mutex);
  238. ret = read_smc(APPLESMC_READ_CMD, entry->key, buf, len);
  239. mutex_unlock(&smcreg.mutex);
  240. return ret;
  241. }
  242. static int applesmc_write_entry(const struct applesmc_entry *entry,
  243. const u8 *buf, u8 len)
  244. {
  245. int ret;
  246. if (entry->len != len)
  247. return -EINVAL;
  248. mutex_lock(&smcreg.mutex);
  249. ret = write_smc(APPLESMC_WRITE_CMD, entry->key, buf, len);
  250. mutex_unlock(&smcreg.mutex);
  251. return ret;
  252. }
  253. static const struct applesmc_entry *applesmc_get_entry_by_index(int index)
  254. {
  255. struct applesmc_entry *cache = &smcreg.cache[index];
  256. u8 key[4], info[6];
  257. __be32 be;
  258. int ret = 0;
  259. if (cache->valid)
  260. return cache;
  261. mutex_lock(&smcreg.mutex);
  262. if (cache->valid)
  263. goto out;
  264. be = cpu_to_be32(index);
  265. ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4);
  266. if (ret)
  267. goto out;
  268. ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6);
  269. if (ret)
  270. goto out;
  271. memcpy(cache->key, key, 4);
  272. cache->len = info[0];
  273. memcpy(cache->type, &info[1], 4);
  274. cache->flags = info[5];
  275. cache->valid = 1;
  276. out:
  277. mutex_unlock(&smcreg.mutex);
  278. if (ret)
  279. return ERR_PTR(ret);
  280. return cache;
  281. }
  282. static int applesmc_get_lower_bound(unsigned int *lo, const char *key)
  283. {
  284. int begin = 0, end = smcreg.key_count;
  285. const struct applesmc_entry *entry;
  286. while (begin != end) {
  287. int middle = begin + (end - begin) / 2;
  288. entry = applesmc_get_entry_by_index(middle);
  289. if (IS_ERR(entry))
  290. return PTR_ERR(entry);
  291. if (strcmp(entry->key, key) < 0)
  292. begin = middle + 1;
  293. else
  294. end = middle;
  295. }
  296. *lo = begin;
  297. return 0;
  298. }
  299. static int applesmc_get_upper_bound(unsigned int *hi, const char *key)
  300. {
  301. int begin = 0, end = smcreg.key_count;
  302. const struct applesmc_entry *entry;
  303. while (begin != end) {
  304. int middle = begin + (end - begin) / 2;
  305. entry = applesmc_get_entry_by_index(middle);
  306. if (IS_ERR(entry))
  307. return PTR_ERR(entry);
  308. if (strcmp(key, entry->key) < 0)
  309. end = middle;
  310. else
  311. begin = middle + 1;
  312. }
  313. *hi = begin;
  314. return 0;
  315. }
  316. static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key)
  317. {
  318. int begin, end;
  319. int ret;
  320. ret = applesmc_get_lower_bound(&begin, key);
  321. if (ret)
  322. return ERR_PTR(ret);
  323. ret = applesmc_get_upper_bound(&end, key);
  324. if (ret)
  325. return ERR_PTR(ret);
  326. if (end - begin != 1)
  327. return ERR_PTR(-EINVAL);
  328. return applesmc_get_entry_by_index(begin);
  329. }
  330. static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
  331. {
  332. const struct applesmc_entry *entry;
  333. entry = applesmc_get_entry_by_key(key);
  334. if (IS_ERR(entry))
  335. return PTR_ERR(entry);
  336. return applesmc_read_entry(entry, buffer, len);
  337. }
  338. static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
  339. {
  340. const struct applesmc_entry *entry;
  341. entry = applesmc_get_entry_by_key(key);
  342. if (IS_ERR(entry))
  343. return PTR_ERR(entry);
  344. return applesmc_write_entry(entry, buffer, len);
  345. }
  346. static int applesmc_has_key(const char *key, bool *value)
  347. {
  348. const struct applesmc_entry *entry;
  349. entry = applesmc_get_entry_by_key(key);
  350. if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL)
  351. return PTR_ERR(entry);
  352. *value = !IS_ERR(entry);
  353. return 0;
  354. }
  355. /*
  356. * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z).
  357. */
  358. static int applesmc_read_motion_sensor(int index, s16* value)
  359. {
  360. u8 buffer[2];
  361. int ret;
  362. switch (index) {
  363. case SENSOR_X:
  364. ret = applesmc_read_key(MOTION_SENSOR_X_KEY, buffer, 2);
  365. break;
  366. case SENSOR_Y:
  367. ret = applesmc_read_key(MOTION_SENSOR_Y_KEY, buffer, 2);
  368. break;
  369. case SENSOR_Z:
  370. ret = applesmc_read_key(MOTION_SENSOR_Z_KEY, buffer, 2);
  371. break;
  372. default:
  373. ret = -EINVAL;
  374. }
  375. *value = ((s16)buffer[0] << 8) | buffer[1];
  376. return ret;
  377. }
  378. /*
  379. * applesmc_device_init - initialize the accelerometer. Can sleep.
  380. */
  381. static void applesmc_device_init(void)
  382. {
  383. int total;
  384. u8 buffer[2];
  385. if (!smcreg.has_accelerometer)
  386. return;
  387. for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
  388. if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) &&
  389. (buffer[0] != 0x00 || buffer[1] != 0x00))
  390. return;
  391. buffer[0] = 0xe0;
  392. buffer[1] = 0x00;
  393. applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2);
  394. msleep(INIT_WAIT_MSECS);
  395. }
  396. pr_warn("failed to init the device\n");
  397. }
  398. /*
  399. * applesmc_init_smcreg_try - Try to initialize register cache. Idempotent.
  400. */
  401. static int applesmc_init_smcreg_try(void)
  402. {
  403. struct applesmc_registers *s = &smcreg;
  404. bool left_light_sensor, right_light_sensor;
  405. u8 tmp[1];
  406. int ret;
  407. if (s->init_complete)
  408. return 0;
  409. ret = read_register_count(&s->key_count);
  410. if (ret)
  411. return ret;
  412. if (!s->cache)
  413. s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
  414. if (!s->cache)
  415. return -ENOMEM;
  416. ret = applesmc_read_key(FANS_COUNT, tmp, 1);
  417. if (ret)
  418. return ret;
  419. s->fan_count = tmp[0];
  420. ret = applesmc_get_lower_bound(&s->temp_begin, "T");
  421. if (ret)
  422. return ret;
  423. ret = applesmc_get_lower_bound(&s->temp_end, "U");
  424. if (ret)
  425. return ret;
  426. s->temp_count = s->temp_end - s->temp_begin;
  427. ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor);
  428. if (ret)
  429. return ret;
  430. ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor);
  431. if (ret)
  432. return ret;
  433. ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer);
  434. if (ret)
  435. return ret;
  436. ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight);
  437. if (ret)
  438. return ret;
  439. s->num_light_sensors = left_light_sensor + right_light_sensor;
  440. s->init_complete = true;
  441. pr_info("key=%d fan=%d temp=%d acc=%d lux=%d kbd=%d\n",
  442. s->key_count, s->fan_count, s->temp_count,
  443. s->has_accelerometer,
  444. s->num_light_sensors,
  445. s->has_key_backlight);
  446. return 0;
  447. }
  448. /*
  449. * applesmc_init_smcreg - Initialize register cache.
  450. *
  451. * Retries until initialization is successful, or the operation times out.
  452. *
  453. */
  454. static int applesmc_init_smcreg(void)
  455. {
  456. int ms, ret;
  457. for (ms = 0; ms < INIT_TIMEOUT_MSECS; ms += INIT_WAIT_MSECS) {
  458. ret = applesmc_init_smcreg_try();
  459. if (!ret) {
  460. if (ms)
  461. pr_info("init_smcreg() took %d ms\n", ms);
  462. return 0;
  463. }
  464. msleep(INIT_WAIT_MSECS);
  465. }
  466. kfree(smcreg.cache);
  467. smcreg.cache = NULL;
  468. return ret;
  469. }
  470. static void applesmc_destroy_smcreg(void)
  471. {
  472. kfree(smcreg.cache);
  473. smcreg.cache = NULL;
  474. smcreg.init_complete = false;
  475. }
  476. /* Device model stuff */
  477. static int applesmc_probe(struct platform_device *dev)
  478. {
  479. int ret;
  480. ret = applesmc_init_smcreg();
  481. if (ret)
  482. return ret;
  483. applesmc_device_init();
  484. return 0;
  485. }
  486. /* Synchronize device with memorized backlight state */
  487. static int applesmc_pm_resume(struct device *dev)
  488. {
  489. if (smcreg.has_key_backlight)
  490. applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
  491. return 0;
  492. }
  493. /* Reinitialize device on resume from hibernation */
  494. static int applesmc_pm_restore(struct device *dev)
  495. {
  496. applesmc_device_init();
  497. return applesmc_pm_resume(dev);
  498. }
  499. static const struct dev_pm_ops applesmc_pm_ops = {
  500. .resume = applesmc_pm_resume,
  501. .restore = applesmc_pm_restore,
  502. };
  503. static struct platform_driver applesmc_driver = {
  504. .probe = applesmc_probe,
  505. .driver = {
  506. .name = "applesmc",
  507. .owner = THIS_MODULE,
  508. .pm = &applesmc_pm_ops,
  509. },
  510. };
  511. /*
  512. * applesmc_calibrate - Set our "resting" values. Callers must
  513. * hold applesmc_lock.
  514. */
  515. static void applesmc_calibrate(void)
  516. {
  517. applesmc_read_motion_sensor(SENSOR_X, &rest_x);
  518. applesmc_read_motion_sensor(SENSOR_Y, &rest_y);
  519. rest_x = -rest_x;
  520. }
  521. static void applesmc_idev_poll(struct input_polled_dev *dev)
  522. {
  523. struct input_dev *idev = dev->input;
  524. s16 x, y;
  525. if (applesmc_read_motion_sensor(SENSOR_X, &x))
  526. return;
  527. if (applesmc_read_motion_sensor(SENSOR_Y, &y))
  528. return;
  529. x = -x;
  530. input_report_abs(idev, ABS_X, x - rest_x);
  531. input_report_abs(idev, ABS_Y, y - rest_y);
  532. input_sync(idev);
  533. }
  534. /* Sysfs Files */
  535. static ssize_t applesmc_name_show(struct device *dev,
  536. struct device_attribute *attr, char *buf)
  537. {
  538. return snprintf(buf, PAGE_SIZE, "applesmc\n");
  539. }
  540. static ssize_t applesmc_position_show(struct device *dev,
  541. struct device_attribute *attr, char *buf)
  542. {
  543. int ret;
  544. s16 x, y, z;
  545. ret = applesmc_read_motion_sensor(SENSOR_X, &x);
  546. if (ret)
  547. goto out;
  548. ret = applesmc_read_motion_sensor(SENSOR_Y, &y);
  549. if (ret)
  550. goto out;
  551. ret = applesmc_read_motion_sensor(SENSOR_Z, &z);
  552. if (ret)
  553. goto out;
  554. out:
  555. if (ret)
  556. return ret;
  557. else
  558. return snprintf(buf, PAGE_SIZE, "(%d,%d,%d)\n", x, y, z);
  559. }
  560. static ssize_t applesmc_light_show(struct device *dev,
  561. struct device_attribute *attr, char *sysfsbuf)
  562. {
  563. const struct applesmc_entry *entry;
  564. static int data_length;
  565. int ret;
  566. u8 left = 0, right = 0;
  567. u8 buffer[10];
  568. if (!data_length) {
  569. entry = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY);
  570. if (IS_ERR(entry))
  571. return PTR_ERR(entry);
  572. if (entry->len > 10)
  573. return -ENXIO;
  574. data_length = entry->len;
  575. pr_info("light sensor data length set to %d\n", data_length);
  576. }
  577. ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length);
  578. /* newer macbooks report a single 10-bit bigendian value */
  579. if (data_length == 10) {
  580. left = be16_to_cpu(*(__be16 *)(buffer + 6)) >> 2;
  581. goto out;
  582. }
  583. left = buffer[2];
  584. if (ret)
  585. goto out;
  586. ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length);
  587. right = buffer[2];
  588. out:
  589. if (ret)
  590. return ret;
  591. else
  592. return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
  593. }
  594. /* Displays sensor key as label */
  595. static ssize_t applesmc_show_sensor_label(struct device *dev,
  596. struct device_attribute *devattr, char *sysfsbuf)
  597. {
  598. int index = smcreg.temp_begin + to_index(devattr);
  599. const struct applesmc_entry *entry;
  600. entry = applesmc_get_entry_by_index(index);
  601. if (IS_ERR(entry))
  602. return PTR_ERR(entry);
  603. return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
  604. }
  605. /* Displays degree Celsius * 1000 */
  606. static ssize_t applesmc_show_temperature(struct device *dev,
  607. struct device_attribute *devattr, char *sysfsbuf)
  608. {
  609. int index = smcreg.temp_begin + to_index(devattr);
  610. const struct applesmc_entry *entry;
  611. int ret;
  612. u8 buffer[2];
  613. unsigned int temp;
  614. entry = applesmc_get_entry_by_index(index);
  615. if (IS_ERR(entry))
  616. return PTR_ERR(entry);
  617. if (entry->len > 2)
  618. return -EINVAL;
  619. ret = applesmc_read_entry(entry, buffer, entry->len);
  620. if (ret)
  621. return ret;
  622. if (entry->len == 2) {
  623. temp = buffer[0] * 1000;
  624. temp += (buffer[1] >> 6) * 250;
  625. } else {
  626. temp = buffer[0] * 4000;
  627. }
  628. return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp);
  629. }
  630. static ssize_t applesmc_show_fan_speed(struct device *dev,
  631. struct device_attribute *attr, char *sysfsbuf)
  632. {
  633. int ret;
  634. unsigned int speed = 0;
  635. char newkey[5];
  636. u8 buffer[2];
  637. sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
  638. ret = applesmc_read_key(newkey, buffer, 2);
  639. speed = ((buffer[0] << 8 | buffer[1]) >> 2);
  640. if (ret)
  641. return ret;
  642. else
  643. return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed);
  644. }
  645. static ssize_t applesmc_store_fan_speed(struct device *dev,
  646. struct device_attribute *attr,
  647. const char *sysfsbuf, size_t count)
  648. {
  649. int ret;
  650. u32 speed;
  651. char newkey[5];
  652. u8 buffer[2];
  653. speed = simple_strtoul(sysfsbuf, NULL, 10);
  654. if (speed > 0x4000) /* Bigger than a 14-bit value */
  655. return -EINVAL;
  656. sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
  657. buffer[0] = (speed >> 6) & 0xff;
  658. buffer[1] = (speed << 2) & 0xff;
  659. ret = applesmc_write_key(newkey, buffer, 2);
  660. if (ret)
  661. return ret;
  662. else
  663. return count;
  664. }
  665. static ssize_t applesmc_show_fan_manual(struct device *dev,
  666. struct device_attribute *attr, char *sysfsbuf)
  667. {
  668. int ret;
  669. u16 manual = 0;
  670. u8 buffer[2];
  671. ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
  672. manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01;
  673. if (ret)
  674. return ret;
  675. else
  676. return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual);
  677. }
  678. static ssize_t applesmc_store_fan_manual(struct device *dev,
  679. struct device_attribute *attr,
  680. const char *sysfsbuf, size_t count)
  681. {
  682. int ret;
  683. u8 buffer[2];
  684. u32 input;
  685. u16 val;
  686. input = simple_strtoul(sysfsbuf, NULL, 10);
  687. ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
  688. val = (buffer[0] << 8 | buffer[1]);
  689. if (ret)
  690. goto out;
  691. if (input)
  692. val = val | (0x01 << to_index(attr));
  693. else
  694. val = val & ~(0x01 << to_index(attr));
  695. buffer[0] = (val >> 8) & 0xFF;
  696. buffer[1] = val & 0xFF;
  697. ret = applesmc_write_key(FANS_MANUAL, buffer, 2);
  698. out:
  699. if (ret)
  700. return ret;
  701. else
  702. return count;
  703. }
  704. static ssize_t applesmc_show_fan_position(struct device *dev,
  705. struct device_attribute *attr, char *sysfsbuf)
  706. {
  707. int ret;
  708. char newkey[5];
  709. u8 buffer[17];
  710. sprintf(newkey, FAN_ID_FMT, to_index(attr));
  711. ret = applesmc_read_key(newkey, buffer, 16);
  712. buffer[16] = 0;
  713. if (ret)
  714. return ret;
  715. else
  716. return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", buffer+4);
  717. }
  718. static ssize_t applesmc_calibrate_show(struct device *dev,
  719. struct device_attribute *attr, char *sysfsbuf)
  720. {
  721. return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", rest_x, rest_y);
  722. }
  723. static ssize_t applesmc_calibrate_store(struct device *dev,
  724. struct device_attribute *attr, const char *sysfsbuf, size_t count)
  725. {
  726. applesmc_calibrate();
  727. return count;
  728. }
  729. static void applesmc_backlight_set(struct work_struct *work)
  730. {
  731. applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
  732. }
  733. static DECLARE_WORK(backlight_work, &applesmc_backlight_set);
  734. static void applesmc_brightness_set(struct led_classdev *led_cdev,
  735. enum led_brightness value)
  736. {
  737. int ret;
  738. backlight_state[0] = value;
  739. ret = queue_work(applesmc_led_wq, &backlight_work);
  740. if (debug && (!ret))
  741. printk(KERN_DEBUG "applesmc: work was already on the queue.\n");
  742. }
  743. static ssize_t applesmc_key_count_show(struct device *dev,
  744. struct device_attribute *attr, char *sysfsbuf)
  745. {
  746. int ret;
  747. u8 buffer[4];
  748. u32 count;
  749. ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4);
  750. count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
  751. ((u32)buffer[2]<<8) + buffer[3];
  752. if (ret)
  753. return ret;
  754. else
  755. return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count);
  756. }
  757. static ssize_t applesmc_key_at_index_read_show(struct device *dev,
  758. struct device_attribute *attr, char *sysfsbuf)
  759. {
  760. const struct applesmc_entry *entry;
  761. int ret;
  762. entry = applesmc_get_entry_by_index(key_at_index);
  763. if (IS_ERR(entry))
  764. return PTR_ERR(entry);
  765. ret = applesmc_read_entry(entry, sysfsbuf, entry->len);
  766. if (ret)
  767. return ret;
  768. return entry->len;
  769. }
  770. static ssize_t applesmc_key_at_index_data_length_show(struct device *dev,
  771. struct device_attribute *attr, char *sysfsbuf)
  772. {
  773. const struct applesmc_entry *entry;
  774. entry = applesmc_get_entry_by_index(key_at_index);
  775. if (IS_ERR(entry))
  776. return PTR_ERR(entry);
  777. return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry->len);
  778. }
  779. static ssize_t applesmc_key_at_index_type_show(struct device *dev,
  780. struct device_attribute *attr, char *sysfsbuf)
  781. {
  782. const struct applesmc_entry *entry;
  783. entry = applesmc_get_entry_by_index(key_at_index);
  784. if (IS_ERR(entry))
  785. return PTR_ERR(entry);
  786. return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->type);
  787. }
  788. static ssize_t applesmc_key_at_index_name_show(struct device *dev,
  789. struct device_attribute *attr, char *sysfsbuf)
  790. {
  791. const struct applesmc_entry *entry;
  792. entry = applesmc_get_entry_by_index(key_at_index);
  793. if (IS_ERR(entry))
  794. return PTR_ERR(entry);
  795. return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
  796. }
  797. static ssize_t applesmc_key_at_index_show(struct device *dev,
  798. struct device_attribute *attr, char *sysfsbuf)
  799. {
  800. return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", key_at_index);
  801. }
  802. static ssize_t applesmc_key_at_index_store(struct device *dev,
  803. struct device_attribute *attr, const char *sysfsbuf, size_t count)
  804. {
  805. unsigned long newkey;
  806. if (strict_strtoul(sysfsbuf, 10, &newkey) < 0
  807. || newkey >= smcreg.key_count)
  808. return -EINVAL;
  809. key_at_index = newkey;
  810. return count;
  811. }
  812. static struct led_classdev applesmc_backlight = {
  813. .name = "smc::kbd_backlight",
  814. .default_trigger = "nand-disk",
  815. .brightness_set = applesmc_brightness_set,
  816. };
  817. static struct applesmc_node_group info_group[] = {
  818. { "name", applesmc_name_show },
  819. { "key_count", applesmc_key_count_show },
  820. { "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store },
  821. { "key_at_index_name", applesmc_key_at_index_name_show },
  822. { "key_at_index_type", applesmc_key_at_index_type_show },
  823. { "key_at_index_data_length", applesmc_key_at_index_data_length_show },
  824. { "key_at_index_data", applesmc_key_at_index_read_show },
  825. { }
  826. };
  827. static struct applesmc_node_group accelerometer_group[] = {
  828. { "position", applesmc_position_show },
  829. { "calibrate", applesmc_calibrate_show, applesmc_calibrate_store },
  830. { }
  831. };
  832. static struct applesmc_node_group light_sensor_group[] = {
  833. { "light", applesmc_light_show },
  834. { }
  835. };
  836. static struct applesmc_node_group fan_group[] = {
  837. { "fan%d_label", applesmc_show_fan_position },
  838. { "fan%d_input", applesmc_show_fan_speed, NULL, 0 },
  839. { "fan%d_min", applesmc_show_fan_speed, applesmc_store_fan_speed, 1 },
  840. { "fan%d_max", applesmc_show_fan_speed, NULL, 2 },
  841. { "fan%d_safe", applesmc_show_fan_speed, NULL, 3 },
  842. { "fan%d_output", applesmc_show_fan_speed, applesmc_store_fan_speed, 4 },
  843. { "fan%d_manual", applesmc_show_fan_manual, applesmc_store_fan_manual },
  844. { }
  845. };
  846. static struct applesmc_node_group temp_group[] = {
  847. { "temp%d_label", applesmc_show_sensor_label },
  848. { "temp%d_input", applesmc_show_temperature },
  849. { }
  850. };
  851. /* Module stuff */
  852. /*
  853. * applesmc_destroy_nodes - remove files and free associated memory
  854. */
  855. static void applesmc_destroy_nodes(struct applesmc_node_group *groups)
  856. {
  857. struct applesmc_node_group *grp;
  858. struct applesmc_dev_attr *node;
  859. for (grp = groups; grp->nodes; grp++) {
  860. for (node = grp->nodes; node->sda.dev_attr.attr.name; node++)
  861. sysfs_remove_file(&pdev->dev.kobj,
  862. &node->sda.dev_attr.attr);
  863. kfree(grp->nodes);
  864. grp->nodes = NULL;
  865. }
  866. }
  867. /*
  868. * applesmc_create_nodes - create a two-dimensional group of sysfs files
  869. */
  870. static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
  871. {
  872. struct applesmc_node_group *grp;
  873. struct applesmc_dev_attr *node;
  874. struct attribute *attr;
  875. int ret, i;
  876. for (grp = groups; grp->format; grp++) {
  877. grp->nodes = kcalloc(num + 1, sizeof(*node), GFP_KERNEL);
  878. if (!grp->nodes) {
  879. ret = -ENOMEM;
  880. goto out;
  881. }
  882. for (i = 0; i < num; i++) {
  883. node = &grp->nodes[i];
  884. sprintf(node->name, grp->format, i + 1);
  885. node->sda.index = (grp->option << 16) | (i & 0xffff);
  886. node->sda.dev_attr.show = grp->show;
  887. node->sda.dev_attr.store = grp->store;
  888. attr = &node->sda.dev_attr.attr;
  889. attr->name = node->name;
  890. attr->mode = S_IRUGO | (grp->store ? S_IWUSR : 0);
  891. ret = sysfs_create_file(&pdev->dev.kobj, attr);
  892. if (ret) {
  893. attr->name = NULL;
  894. goto out;
  895. }
  896. }
  897. }
  898. return 0;
  899. out:
  900. applesmc_destroy_nodes(groups);
  901. return ret;
  902. }
  903. /* Create accelerometer ressources */
  904. static int applesmc_create_accelerometer(void)
  905. {
  906. struct input_dev *idev;
  907. int ret;
  908. if (!smcreg.has_accelerometer)
  909. return 0;
  910. ret = applesmc_create_nodes(accelerometer_group, 1);
  911. if (ret)
  912. goto out;
  913. applesmc_idev = input_allocate_polled_device();
  914. if (!applesmc_idev) {
  915. ret = -ENOMEM;
  916. goto out_sysfs;
  917. }
  918. applesmc_idev->poll = applesmc_idev_poll;
  919. applesmc_idev->poll_interval = APPLESMC_POLL_INTERVAL;
  920. /* initial calibrate for the input device */
  921. applesmc_calibrate();
  922. /* initialize the input device */
  923. idev = applesmc_idev->input;
  924. idev->name = "applesmc";
  925. idev->id.bustype = BUS_HOST;
  926. idev->dev.parent = &pdev->dev;
  927. idev->evbit[0] = BIT_MASK(EV_ABS);
  928. input_set_abs_params(idev, ABS_X,
  929. -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
  930. input_set_abs_params(idev, ABS_Y,
  931. -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
  932. ret = input_register_polled_device(applesmc_idev);
  933. if (ret)
  934. goto out_idev;
  935. return 0;
  936. out_idev:
  937. input_free_polled_device(applesmc_idev);
  938. out_sysfs:
  939. applesmc_destroy_nodes(accelerometer_group);
  940. out:
  941. pr_warn("driver init failed (ret=%d)!\n", ret);
  942. return ret;
  943. }
  944. /* Release all ressources used by the accelerometer */
  945. static void applesmc_release_accelerometer(void)
  946. {
  947. if (!smcreg.has_accelerometer)
  948. return;
  949. input_unregister_polled_device(applesmc_idev);
  950. input_free_polled_device(applesmc_idev);
  951. applesmc_destroy_nodes(accelerometer_group);
  952. }
  953. static int applesmc_create_light_sensor(void)
  954. {
  955. if (!smcreg.num_light_sensors)
  956. return 0;
  957. return applesmc_create_nodes(light_sensor_group, 1);
  958. }
  959. static void applesmc_release_light_sensor(void)
  960. {
  961. if (!smcreg.num_light_sensors)
  962. return;
  963. applesmc_destroy_nodes(light_sensor_group);
  964. }
  965. static int applesmc_create_key_backlight(void)
  966. {
  967. if (!smcreg.has_key_backlight)
  968. return 0;
  969. applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
  970. if (!applesmc_led_wq)
  971. return -ENOMEM;
  972. return led_classdev_register(&pdev->dev, &applesmc_backlight);
  973. }
  974. static void applesmc_release_key_backlight(void)
  975. {
  976. if (!smcreg.has_key_backlight)
  977. return;
  978. led_classdev_unregister(&applesmc_backlight);
  979. destroy_workqueue(applesmc_led_wq);
  980. }
  981. static int applesmc_dmi_match(const struct dmi_system_id *id)
  982. {
  983. return 1;
  984. }
  985. /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
  986. * So we need to put "Apple MacBook Pro" before "Apple MacBook". */
  987. static __initdata struct dmi_system_id applesmc_whitelist[] = {
  988. { applesmc_dmi_match, "Apple MacBook Air", {
  989. DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
  990. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") },
  991. },
  992. { applesmc_dmi_match, "Apple MacBook Pro", {
  993. DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
  994. DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") },
  995. },
  996. { applesmc_dmi_match, "Apple MacBook", {
  997. DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
  998. DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") },
  999. },
  1000. { applesmc_dmi_match, "Apple Macmini", {
  1001. DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
  1002. DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") },
  1003. },
  1004. { applesmc_dmi_match, "Apple MacPro", {
  1005. DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
  1006. DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") },
  1007. },
  1008. { applesmc_dmi_match, "Apple iMac", {
  1009. DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
  1010. DMI_MATCH(DMI_PRODUCT_NAME,"iMac") },
  1011. },
  1012. { .ident = NULL }
  1013. };
  1014. static int __init applesmc_init(void)
  1015. {
  1016. int ret;
  1017. if (!dmi_check_system(applesmc_whitelist)) {
  1018. pr_warn("supported laptop not found!\n");
  1019. ret = -ENODEV;
  1020. goto out;
  1021. }
  1022. if (!request_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS,
  1023. "applesmc")) {
  1024. ret = -ENXIO;
  1025. goto out;
  1026. }
  1027. ret = platform_driver_register(&applesmc_driver);
  1028. if (ret)
  1029. goto out_region;
  1030. pdev = platform_device_register_simple("applesmc", APPLESMC_DATA_PORT,
  1031. NULL, 0);
  1032. if (IS_ERR(pdev)) {
  1033. ret = PTR_ERR(pdev);
  1034. goto out_driver;
  1035. }
  1036. /* create register cache */
  1037. ret = applesmc_init_smcreg();
  1038. if (ret)
  1039. goto out_device;
  1040. ret = applesmc_create_nodes(info_group, 1);
  1041. if (ret)
  1042. goto out_smcreg;
  1043. ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
  1044. if (ret)
  1045. goto out_info;
  1046. ret = applesmc_create_nodes(temp_group, smcreg.temp_count);
  1047. if (ret)
  1048. goto out_fans;
  1049. ret = applesmc_create_accelerometer();
  1050. if (ret)
  1051. goto out_temperature;
  1052. ret = applesmc_create_light_sensor();
  1053. if (ret)
  1054. goto out_accelerometer;
  1055. ret = applesmc_create_key_backlight();
  1056. if (ret)
  1057. goto out_light_sysfs;
  1058. hwmon_dev = hwmon_device_register(&pdev->dev);
  1059. if (IS_ERR(hwmon_dev)) {
  1060. ret = PTR_ERR(hwmon_dev);
  1061. goto out_light_ledclass;
  1062. }
  1063. return 0;
  1064. out_light_ledclass:
  1065. applesmc_release_key_backlight();
  1066. out_light_sysfs:
  1067. applesmc_release_light_sensor();
  1068. out_accelerometer:
  1069. applesmc_release_accelerometer();
  1070. out_temperature:
  1071. applesmc_destroy_nodes(temp_group);
  1072. out_fans:
  1073. applesmc_destroy_nodes(fan_group);
  1074. out_info:
  1075. applesmc_destroy_nodes(info_group);
  1076. out_smcreg:
  1077. applesmc_destroy_smcreg();
  1078. out_device:
  1079. platform_device_unregister(pdev);
  1080. out_driver:
  1081. platform_driver_unregister(&applesmc_driver);
  1082. out_region:
  1083. release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
  1084. out:
  1085. pr_warn("driver init failed (ret=%d)!\n", ret);
  1086. return ret;
  1087. }
  1088. static void __exit applesmc_exit(void)
  1089. {
  1090. hwmon_device_unregister(hwmon_dev);
  1091. applesmc_release_key_backlight();
  1092. applesmc_release_light_sensor();
  1093. applesmc_release_accelerometer();
  1094. applesmc_destroy_nodes(temp_group);
  1095. applesmc_destroy_nodes(fan_group);
  1096. applesmc_destroy_nodes(info_group);
  1097. applesmc_destroy_smcreg();
  1098. platform_device_unregister(pdev);
  1099. platform_driver_unregister(&applesmc_driver);
  1100. release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
  1101. }
  1102. module_init(applesmc_init);
  1103. module_exit(applesmc_exit);
  1104. MODULE_AUTHOR("Nicolas Boichat");
  1105. MODULE_DESCRIPTION("Apple SMC");
  1106. MODULE_LICENSE("GPL v2");
  1107. MODULE_DEVICE_TABLE(dmi, applesmc_whitelist);