applesmc.c 31 KB

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