hdaps.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*
  2. * drivers/hwmon/hdaps.c - driver for IBM's Hard Drive Active Protection System
  3. *
  4. * Copyright (C) 2005 Robert Love <rml@novell.com>
  5. * Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com>
  6. *
  7. * The HardDisk Active Protection System (hdaps) is present in the IBM ThinkPad
  8. * T41, T42, T43, R51, and X40, at least. It provides a basic two-axis
  9. * accelerometer and other data, such as the device's temperature.
  10. *
  11. * Based on the document by Mark A. Smith available at
  12. * http://www.almaden.ibm.com/cs/people/marksmith/tpaps.html and a lot of trial
  13. * and error.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License v2 as published by the
  17. * Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful, but WITHOUT
  20. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  21. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  22. * more details.
  23. *
  24. * You should have received a copy of the GNU General Public License along with
  25. * this program; if not, write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #include <linux/delay.h>
  29. #include <linux/device.h>
  30. #include <linux/input.h>
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/timer.h>
  34. #include <linux/dmi.h>
  35. #include <asm/io.h>
  36. #define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
  37. #define HDAPS_NR_PORTS 0x30 /* 0x1600 - 0x162f */
  38. #define STATE_FRESH 0x50 /* accelerometer data is fresh */
  39. #define REFRESH_ASYNC 0x00 /* do asynchronous refresh */
  40. #define REFRESH_SYNC 0x01 /* do synchronous refresh */
  41. #define HDAPS_PORT_STATE 0x1611 /* device state */
  42. #define HDAPS_PORT_YPOS 0x1612 /* y-axis position */
  43. #define HDAPS_PORT_XPOS 0x1614 /* x-axis position */
  44. #define HDAPS_PORT_TEMP1 0x1616 /* device temperature, in celcius */
  45. #define HDAPS_PORT_YVAR 0x1617 /* y-axis variance (what is this?) */
  46. #define HDAPS_PORT_XVAR 0x1619 /* x-axis variance (what is this?) */
  47. #define HDAPS_PORT_TEMP2 0x161b /* device temperature (again?) */
  48. #define HDAPS_PORT_UNKNOWN 0x161c /* what is this? */
  49. #define HDAPS_PORT_KMACT 0x161d /* keyboard or mouse activity */
  50. #define HDAPS_READ_MASK 0xff /* some reads have the low 8 bits set */
  51. #define KEYBD_MASK 0x20 /* set if keyboard activity */
  52. #define MOUSE_MASK 0x40 /* set if mouse activity */
  53. #define KEYBD_ISSET(n) (!! (n & KEYBD_MASK)) /* keyboard used? */
  54. #define MOUSE_ISSET(n) (!! (n & MOUSE_MASK)) /* mouse used? */
  55. #define INIT_TIMEOUT_MSECS 4000 /* wait up to 4s for device init ... */
  56. #define INIT_WAIT_MSECS 200 /* ... in 200ms increments */
  57. static struct platform_device *pdev;
  58. static struct input_dev hdaps_idev;
  59. static struct timer_list hdaps_timer;
  60. static unsigned int hdaps_mousedev_threshold = 4;
  61. static unsigned long hdaps_poll_ms = 50;
  62. static unsigned int hdaps_mousedev;
  63. static unsigned int hdaps_invert;
  64. static u8 km_activity;
  65. static int rest_x;
  66. static int rest_y;
  67. static DECLARE_MUTEX(hdaps_sem);
  68. /*
  69. * __get_latch - Get the value from a given port. Callers must hold hdaps_sem.
  70. */
  71. static inline u8 __get_latch(u16 port)
  72. {
  73. return inb(port) & HDAPS_READ_MASK;
  74. }
  75. /*
  76. * __check_latch - Check a port latch for a given value. Callers must hold
  77. * hdaps_sem. Returns zero if the port contains the given value.
  78. */
  79. static inline unsigned int __check_latch(u16 port, u8 val)
  80. {
  81. if (__get_latch(port) == val)
  82. return 0;
  83. return -EINVAL;
  84. }
  85. /*
  86. * __wait_latch - Wait up to 100us for a port latch to get a certain value,
  87. * returning zero if the value is obtained. Callers must hold hdaps_sem.
  88. */
  89. static unsigned int __wait_latch(u16 port, u8 val)
  90. {
  91. unsigned int i;
  92. for (i = 0; i < 20; i++) {
  93. if (!__check_latch(port, val))
  94. return 0;
  95. udelay(5);
  96. }
  97. return -EINVAL;
  98. }
  99. /*
  100. * __device_refresh - Request a refresh from the accelerometer.
  101. *
  102. * If sync is REFRESH_SYNC, we perform a synchronous refresh and will wait.
  103. * Returns zero if successful and nonzero on error.
  104. *
  105. * If sync is REFRESH_ASYNC, we merely kick off a new refresh if the device is
  106. * not up-to-date. Always returns zero.
  107. *
  108. * Callers must hold hdaps_sem.
  109. */
  110. static int __device_refresh(unsigned int sync)
  111. {
  112. u8 state;
  113. udelay(100);
  114. state = inb(0x1604);
  115. if (state == STATE_FRESH)
  116. return 0;
  117. outb(0x11, 0x1610);
  118. outb(0x01, 0x161f);
  119. if (sync == REFRESH_ASYNC)
  120. return 0;
  121. return __wait_latch(0x1604, STATE_FRESH);
  122. }
  123. /*
  124. * __device_complete - Indicate to the accelerometer that we are done reading
  125. * data, and then initiate an async refresh. Callers must hold hdaps_sem.
  126. */
  127. static inline void __device_complete(void)
  128. {
  129. inb(0x161f);
  130. inb(0x1604);
  131. __device_refresh(REFRESH_ASYNC);
  132. }
  133. static int __hdaps_readb_one(unsigned int port, u8 *val)
  134. {
  135. /* do a sync refresh -- we need to be sure that we read fresh data */
  136. if (__device_refresh(REFRESH_SYNC))
  137. return -EIO;
  138. *val = inb(port);
  139. __device_complete();
  140. return 0;
  141. }
  142. /*
  143. * hdaps_readb_one - reads a byte from a single I/O port, placing the value in
  144. * the given pointer. Returns zero on success or a negative error on failure.
  145. * Can sleep.
  146. */
  147. static int hdaps_readb_one(unsigned int port, u8 *val)
  148. {
  149. int ret;
  150. down(&hdaps_sem);
  151. ret = __hdaps_readb_one(port, val);
  152. up(&hdaps_sem);
  153. return ret;
  154. }
  155. static int __hdaps_read_pair(unsigned int port1, unsigned int port2,
  156. int *x, int *y)
  157. {
  158. /* do a sync refresh -- we need to be sure that we read fresh data */
  159. if (__device_refresh(REFRESH_SYNC))
  160. return -EIO;
  161. *y = inw(port2);
  162. *x = inw(port1);
  163. km_activity = inb(HDAPS_PORT_KMACT);
  164. __device_complete();
  165. /* if hdaps_invert is set, negate the two values */
  166. if (hdaps_invert) {
  167. *x = -*x;
  168. *y = -*y;
  169. }
  170. return 0;
  171. }
  172. /*
  173. * hdaps_read_pair - reads the values from a pair of ports, placing the values
  174. * in the given pointers. Returns zero on success. Can sleep.
  175. */
  176. static int hdaps_read_pair(unsigned int port1, unsigned int port2,
  177. int *val1, int *val2)
  178. {
  179. int ret;
  180. down(&hdaps_sem);
  181. ret = __hdaps_read_pair(port1, port2, val1, val2);
  182. up(&hdaps_sem);
  183. return ret;
  184. }
  185. /* initialize the accelerometer */
  186. static int hdaps_device_init(void)
  187. {
  188. unsigned int total_msecs = INIT_TIMEOUT_MSECS;
  189. int ret = -ENXIO;
  190. down(&hdaps_sem);
  191. outb(0x13, 0x1610);
  192. outb(0x01, 0x161f);
  193. if (__wait_latch(0x161f, 0x00))
  194. goto out;
  195. /*
  196. * The 0x03 value appears to only work on some thinkpads, such as the
  197. * T42p. Others return 0x01.
  198. *
  199. * The 0x02 value occurs when the chip has been previously initialized.
  200. */
  201. if (__check_latch(0x1611, 0x03) &&
  202. __check_latch(0x1611, 0x02) &&
  203. __check_latch(0x1611, 0x01))
  204. goto out;
  205. printk(KERN_DEBUG "hdaps: initial latch check good (0x%02x).\n",
  206. __get_latch(0x1611));
  207. outb(0x17, 0x1610);
  208. outb(0x81, 0x1611);
  209. outb(0x01, 0x161f);
  210. if (__wait_latch(0x161f, 0x00))
  211. goto out;
  212. if (__wait_latch(0x1611, 0x00))
  213. goto out;
  214. if (__wait_latch(0x1612, 0x60))
  215. goto out;
  216. if (__wait_latch(0x1613, 0x00))
  217. goto out;
  218. outb(0x14, 0x1610);
  219. outb(0x01, 0x1611);
  220. outb(0x01, 0x161f);
  221. if (__wait_latch(0x161f, 0x00))
  222. goto out;
  223. outb(0x10, 0x1610);
  224. outb(0xc8, 0x1611);
  225. outb(0x00, 0x1612);
  226. outb(0x02, 0x1613);
  227. outb(0x01, 0x161f);
  228. if (__wait_latch(0x161f, 0x00))
  229. goto out;
  230. if (__device_refresh(REFRESH_SYNC))
  231. goto out;
  232. if (__wait_latch(0x1611, 0x00))
  233. goto out;
  234. /* we have done our dance, now let's wait for the applause */
  235. while (total_msecs > 0) {
  236. u8 ignored;
  237. /* a read of the device helps push it into action */
  238. __hdaps_readb_one(HDAPS_PORT_UNKNOWN, &ignored);
  239. if (!__wait_latch(0x1611, 0x02)) {
  240. ret = 0;
  241. break;
  242. }
  243. msleep(INIT_WAIT_MSECS);
  244. total_msecs -= INIT_WAIT_MSECS;
  245. }
  246. out:
  247. up(&hdaps_sem);
  248. return ret;
  249. }
  250. /* Input class stuff */
  251. /*
  252. * hdaps_calibrate - Zero out our "resting" values. Callers must hold hdaps_sem.
  253. */
  254. static void hdaps_calibrate(void)
  255. {
  256. int x, y;
  257. if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
  258. return;
  259. rest_x = x;
  260. rest_y = y;
  261. }
  262. static void hdaps_mousedev_poll(unsigned long unused)
  263. {
  264. int x, y;
  265. /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
  266. if (down_trylock(&hdaps_sem)) {
  267. mod_timer(&hdaps_timer,jiffies+msecs_to_jiffies(hdaps_poll_ms));
  268. return;
  269. }
  270. if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
  271. goto out;
  272. x -= rest_x;
  273. y -= rest_y;
  274. if (abs(x) > hdaps_mousedev_threshold)
  275. input_report_rel(&hdaps_idev, REL_X, x);
  276. if (abs(y) > hdaps_mousedev_threshold)
  277. input_report_rel(&hdaps_idev, REL_Y, y);
  278. input_sync(&hdaps_idev);
  279. mod_timer(&hdaps_timer, jiffies + msecs_to_jiffies(hdaps_poll_ms));
  280. out:
  281. up(&hdaps_sem);
  282. }
  283. /*
  284. * hdaps_mousedev_enable - enable the input class device. Can sleep.
  285. */
  286. static void hdaps_mousedev_enable(void)
  287. {
  288. down(&hdaps_sem);
  289. /* calibrate the device before enabling */
  290. hdaps_calibrate();
  291. /* initialize the input class */
  292. init_input_dev(&hdaps_idev);
  293. hdaps_idev.dev = &pdev->dev;
  294. hdaps_idev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
  295. hdaps_idev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
  296. hdaps_idev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT);
  297. input_register_device(&hdaps_idev);
  298. /* start up our timer */
  299. init_timer(&hdaps_timer);
  300. hdaps_timer.function = hdaps_mousedev_poll;
  301. hdaps_timer.expires = jiffies + msecs_to_jiffies(hdaps_poll_ms);
  302. add_timer(&hdaps_timer);
  303. hdaps_mousedev = 1;
  304. up(&hdaps_sem);
  305. printk(KERN_INFO "hdaps: input device enabled.\n");
  306. }
  307. /*
  308. * hdaps_mousedev_disable - disable the input class device. Caller must hold
  309. * hdaps_sem.
  310. */
  311. static void hdaps_mousedev_disable(void)
  312. {
  313. down(&hdaps_sem);
  314. if (hdaps_mousedev) {
  315. hdaps_mousedev = 0;
  316. del_timer_sync(&hdaps_timer);
  317. input_unregister_device(&hdaps_idev);
  318. }
  319. up(&hdaps_sem);
  320. }
  321. /* Device model stuff */
  322. static int hdaps_probe(struct device *dev)
  323. {
  324. int ret;
  325. ret = hdaps_device_init();
  326. if (ret)
  327. return ret;
  328. printk(KERN_INFO "hdaps: device successfully initialized.\n");
  329. return 0;
  330. }
  331. static int hdaps_resume(struct device *dev, u32 level)
  332. {
  333. if (level == RESUME_ENABLE)
  334. return hdaps_device_init();
  335. return 0;
  336. }
  337. static struct device_driver hdaps_driver = {
  338. .name = "hdaps",
  339. .bus = &platform_bus_type,
  340. .owner = THIS_MODULE,
  341. .probe = hdaps_probe,
  342. .resume = hdaps_resume
  343. };
  344. /* Sysfs Files */
  345. static ssize_t hdaps_position_show(struct device *dev,
  346. struct device_attribute *attr, char *buf)
  347. {
  348. int ret, x, y;
  349. ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
  350. if (ret)
  351. return ret;
  352. return sprintf(buf, "(%d,%d)\n", x, y);
  353. }
  354. static ssize_t hdaps_variance_show(struct device *dev,
  355. struct device_attribute *attr, char *buf)
  356. {
  357. int ret, x, y;
  358. ret = hdaps_read_pair(HDAPS_PORT_XVAR, HDAPS_PORT_YVAR, &x, &y);
  359. if (ret)
  360. return ret;
  361. return sprintf(buf, "(%d,%d)\n", x, y);
  362. }
  363. static ssize_t hdaps_temp1_show(struct device *dev,
  364. struct device_attribute *attr, char *buf)
  365. {
  366. u8 temp;
  367. int ret;
  368. ret = hdaps_readb_one(HDAPS_PORT_TEMP1, &temp);
  369. if (ret < 0)
  370. return ret;
  371. return sprintf(buf, "%u\n", temp);
  372. }
  373. static ssize_t hdaps_temp2_show(struct device *dev,
  374. struct device_attribute *attr, char *buf)
  375. {
  376. u8 temp;
  377. int ret;
  378. ret = hdaps_readb_one(HDAPS_PORT_TEMP2, &temp);
  379. if (ret < 0)
  380. return ret;
  381. return sprintf(buf, "%u\n", temp);
  382. }
  383. static ssize_t hdaps_keyboard_activity_show(struct device *dev,
  384. struct device_attribute *attr,
  385. char *buf)
  386. {
  387. return sprintf(buf, "%u\n", KEYBD_ISSET(km_activity));
  388. }
  389. static ssize_t hdaps_mouse_activity_show(struct device *dev,
  390. struct device_attribute *attr,
  391. char *buf)
  392. {
  393. return sprintf(buf, "%u\n", MOUSE_ISSET(km_activity));
  394. }
  395. static ssize_t hdaps_calibrate_show(struct device *dev,
  396. struct device_attribute *attr, char *buf)
  397. {
  398. return sprintf(buf, "(%d,%d)\n", rest_x, rest_y);
  399. }
  400. static ssize_t hdaps_calibrate_store(struct device *dev,
  401. struct device_attribute *attr,
  402. const char *buf, size_t count)
  403. {
  404. down(&hdaps_sem);
  405. hdaps_calibrate();
  406. up(&hdaps_sem);
  407. return count;
  408. }
  409. static ssize_t hdaps_invert_show(struct device *dev,
  410. struct device_attribute *attr, char *buf)
  411. {
  412. return sprintf(buf, "%u\n", hdaps_invert);
  413. }
  414. static ssize_t hdaps_invert_store(struct device *dev,
  415. struct device_attribute *attr,
  416. const char *buf, size_t count)
  417. {
  418. int invert;
  419. if (sscanf(buf, "%d", &invert) != 1 || (invert != 1 && invert != 0))
  420. return -EINVAL;
  421. hdaps_invert = invert;
  422. hdaps_calibrate();
  423. return count;
  424. }
  425. static ssize_t hdaps_mousedev_show(struct device *dev,
  426. struct device_attribute *attr, char *buf)
  427. {
  428. return sprintf(buf, "%d\n", hdaps_mousedev);
  429. }
  430. static ssize_t hdaps_mousedev_store(struct device *dev,
  431. struct device_attribute *attr,
  432. const char *buf, size_t count)
  433. {
  434. int enable;
  435. if (sscanf(buf, "%d", &enable) != 1)
  436. return -EINVAL;
  437. if (enable == 1)
  438. hdaps_mousedev_enable();
  439. else if (enable == 0)
  440. hdaps_mousedev_disable();
  441. else
  442. return -EINVAL;
  443. return count;
  444. }
  445. static ssize_t hdaps_poll_show(struct device *dev,
  446. struct device_attribute *attr, char *buf)
  447. {
  448. return sprintf(buf, "%lu\n", hdaps_poll_ms);
  449. }
  450. static ssize_t hdaps_poll_store(struct device *dev,
  451. struct device_attribute *attr,
  452. const char *buf, size_t count)
  453. {
  454. unsigned int poll;
  455. if (sscanf(buf, "%u", &poll) != 1 || poll == 0)
  456. return -EINVAL;
  457. hdaps_poll_ms = poll;
  458. return count;
  459. }
  460. static ssize_t hdaps_threshold_show(struct device *dev,
  461. struct device_attribute *attr, char *buf)
  462. {
  463. return sprintf(buf, "%u\n", hdaps_mousedev_threshold);
  464. }
  465. static ssize_t hdaps_threshold_store(struct device *dev,
  466. struct device_attribute *attr,
  467. const char *buf, size_t count)
  468. {
  469. unsigned int threshold;
  470. if (sscanf(buf, "%u", &threshold) != 1 || threshold == 0)
  471. return -EINVAL;
  472. hdaps_mousedev_threshold = threshold;
  473. return count;
  474. }
  475. static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
  476. static DEVICE_ATTR(variance, 0444, hdaps_variance_show, NULL);
  477. static DEVICE_ATTR(temp1, 0444, hdaps_temp1_show, NULL);
  478. static DEVICE_ATTR(temp2, 0444, hdaps_temp2_show, NULL);
  479. static DEVICE_ATTR(keyboard_activity, 0444, hdaps_keyboard_activity_show, NULL);
  480. static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
  481. static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
  482. static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
  483. static DEVICE_ATTR(mousedev, 0644, hdaps_mousedev_show, hdaps_mousedev_store);
  484. static DEVICE_ATTR(mousedev_poll_ms, 0644, hdaps_poll_show, hdaps_poll_store);
  485. static DEVICE_ATTR(mousedev_threshold, 0644, hdaps_threshold_show,
  486. hdaps_threshold_store);
  487. static struct attribute *hdaps_attributes[] = {
  488. &dev_attr_position.attr,
  489. &dev_attr_variance.attr,
  490. &dev_attr_temp1.attr,
  491. &dev_attr_temp2.attr,
  492. &dev_attr_keyboard_activity.attr,
  493. &dev_attr_mouse_activity.attr,
  494. &dev_attr_calibrate.attr,
  495. &dev_attr_mousedev.attr,
  496. &dev_attr_mousedev_threshold.attr,
  497. &dev_attr_mousedev_poll_ms.attr,
  498. &dev_attr_invert.attr,
  499. NULL,
  500. };
  501. static struct attribute_group hdaps_attribute_group = {
  502. .attrs = hdaps_attributes,
  503. };
  504. /* Module stuff */
  505. /*
  506. * XXX: We should be able to return nonzero and halt the detection process.
  507. * But there is a bug in dmi_check_system() where a nonzero return from the
  508. * first match will result in a return of failure from dmi_check_system().
  509. * I fixed this; the patch is in 2.6-mm. Once in Linus's tree we can make
  510. * hdaps_dmi_match_invert() return hdaps_dmi_match(), which in turn returns 1.
  511. */
  512. static int hdaps_dmi_match(struct dmi_system_id *id)
  513. {
  514. printk(KERN_INFO "hdaps: %s detected.\n", id->ident);
  515. return 0;
  516. }
  517. static int hdaps_dmi_match_invert(struct dmi_system_id *id)
  518. {
  519. hdaps_invert = 1;
  520. printk(KERN_INFO "hdaps: inverting axis readings.\n");
  521. return 0;
  522. }
  523. #define HDAPS_DMI_MATCH_NORMAL(model) { \
  524. .ident = "IBM " model, \
  525. .callback = hdaps_dmi_match, \
  526. .matches = { \
  527. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \
  528. DMI_MATCH(DMI_PRODUCT_VERSION, model) \
  529. } \
  530. }
  531. #define HDAPS_DMI_MATCH_INVERT(model) { \
  532. .ident = "IBM " model, \
  533. .callback = hdaps_dmi_match_invert, \
  534. .matches = { \
  535. DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), \
  536. DMI_MATCH(DMI_PRODUCT_VERSION, model) \
  537. } \
  538. }
  539. static int __init hdaps_init(void)
  540. {
  541. int ret;
  542. /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */
  543. struct dmi_system_id hdaps_whitelist[] = {
  544. HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"),
  545. HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"),
  546. HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"),
  547. HDAPS_DMI_MATCH_INVERT("ThinkPad T41p"),
  548. HDAPS_DMI_MATCH_NORMAL("ThinkPad T41"),
  549. HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"),
  550. HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
  551. HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
  552. HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
  553. { .ident = NULL }
  554. };
  555. if (!dmi_check_system(hdaps_whitelist)) {
  556. printk(KERN_WARNING "hdaps: supported laptop not found!\n");
  557. ret = -ENXIO;
  558. goto out;
  559. }
  560. if (!request_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS, "hdaps")) {
  561. ret = -ENXIO;
  562. goto out;
  563. }
  564. ret = driver_register(&hdaps_driver);
  565. if (ret)
  566. goto out_region;
  567. pdev = platform_device_register_simple("hdaps", -1, NULL, 0);
  568. if (IS_ERR(pdev)) {
  569. ret = PTR_ERR(pdev);
  570. goto out_driver;
  571. }
  572. ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group);
  573. if (ret)
  574. goto out_device;
  575. if (hdaps_mousedev)
  576. hdaps_mousedev_enable();
  577. printk(KERN_INFO "hdaps: driver successfully loaded.\n");
  578. return 0;
  579. out_device:
  580. platform_device_unregister(pdev);
  581. out_driver:
  582. driver_unregister(&hdaps_driver);
  583. out_region:
  584. release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
  585. out:
  586. printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret);
  587. return ret;
  588. }
  589. static void __exit hdaps_exit(void)
  590. {
  591. hdaps_mousedev_disable();
  592. sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
  593. platform_device_unregister(pdev);
  594. driver_unregister(&hdaps_driver);
  595. release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
  596. printk(KERN_INFO "hdaps: driver unloaded.\n");
  597. }
  598. module_init(hdaps_init);
  599. module_exit(hdaps_exit);
  600. module_param_named(mousedev, hdaps_mousedev, bool, 0);
  601. MODULE_PARM_DESC(mousedev, "enable the input class device");
  602. module_param_named(invert, hdaps_invert, bool, 0);
  603. MODULE_PARM_DESC(invert, "invert data along each axis");
  604. MODULE_AUTHOR("Robert Love");
  605. MODULE_DESCRIPTION("IBM Hard Drive Active Protection System (HDAPS) driver");
  606. MODULE_LICENSE("GPL v2");