]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/hwmon/hdaps.c
Linux 2.6.23
[mirror_ubuntu-bionic-kernel.git] / drivers / hwmon / hdaps.c
CommitLineData
860e1d6b
RL
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 *
4c87b74c
RL
7 * The HardDisk Active Protection System (hdaps) is present in IBM ThinkPads
8 * starting with the R40, T41, and X40. It provides a basic two-axis
9 * accelerometer and other data, such as the device's temperature.
860e1d6b 10 *
393ad299 11 * This driver is based on the document by Mark A. Smith available at
860e1d6b
RL
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
29#include <linux/delay.h>
d052d1be 30#include <linux/platform_device.h>
860e1d6b
RL
31#include <linux/input.h>
32#include <linux/kernel.h>
6acc369a 33#include <linux/mutex.h>
860e1d6b
RL
34#include <linux/module.h>
35#include <linux/timer.h>
36#include <linux/dmi.h>
914e2637 37#include <linux/jiffies.h>
6acc369a 38
860e1d6b
RL
39#include <asm/io.h>
40
41#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
393ad299 42#define HDAPS_NR_PORTS 0x30 /* number of ports: 0x1600 - 0x162f */
860e1d6b
RL
43
44#define HDAPS_PORT_STATE 0x1611 /* device state */
45#define HDAPS_PORT_YPOS 0x1612 /* y-axis position */
46#define HDAPS_PORT_XPOS 0x1614 /* x-axis position */
0a704681 47#define HDAPS_PORT_TEMP1 0x1616 /* device temperature, in Celsius */
860e1d6b
RL
48#define HDAPS_PORT_YVAR 0x1617 /* y-axis variance (what is this?) */
49#define HDAPS_PORT_XVAR 0x1619 /* x-axis variance (what is this?) */
50#define HDAPS_PORT_TEMP2 0x161b /* device temperature (again?) */
51#define HDAPS_PORT_UNKNOWN 0x161c /* what is this? */
52#define HDAPS_PORT_KMACT 0x161d /* keyboard or mouse activity */
53
393ad299 54#define STATE_FRESH 0x50 /* accelerometer data is fresh */
860e1d6b
RL
55
56#define KEYBD_MASK 0x20 /* set if keyboard activity */
57#define MOUSE_MASK 0x40 /* set if mouse activity */
58#define KEYBD_ISSET(n) (!! (n & KEYBD_MASK)) /* keyboard used? */
59#define MOUSE_ISSET(n) (!! (n & MOUSE_MASK)) /* mouse used? */
60
61#define INIT_TIMEOUT_MSECS 4000 /* wait up to 4s for device init ... */
62#define INIT_WAIT_MSECS 200 /* ... in 200ms increments */
63
393ad299
RL
64#define HDAPS_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */
65#define HDAPS_INPUT_FUZZ 4 /* input event threshold */
d12eb7e1 66#define HDAPS_INPUT_FLAT 4
393ad299 67
860e1d6b 68static struct timer_list hdaps_timer;
393ad299 69static struct platform_device *pdev;
d12eb7e1 70static struct input_dev *hdaps_idev;
860e1d6b
RL
71static unsigned int hdaps_invert;
72static u8 km_activity;
73static int rest_x;
74static int rest_y;
75
6acc369a 76static DEFINE_MUTEX(hdaps_mtx);
860e1d6b
RL
77
78/*
6acc369a 79 * __get_latch - Get the value from a given port. Callers must hold hdaps_mtx.
860e1d6b
RL
80 */
81static inline u8 __get_latch(u16 port)
82{
393ad299 83 return inb(port) & 0xff;
860e1d6b
RL
84}
85
86/*
393ad299 87 * __check_latch - Check a port latch for a given value. Returns zero if the
6acc369a 88 * port contains the given value. Callers must hold hdaps_mtx.
860e1d6b 89 */
393ad299 90static inline int __check_latch(u16 port, u8 val)
860e1d6b
RL
91{
92 if (__get_latch(port) == val)
93 return 0;
94 return -EINVAL;
95}
96
97/*
98 * __wait_latch - Wait up to 100us for a port latch to get a certain value,
6acc369a 99 * returning zero if the value is obtained. Callers must hold hdaps_mtx.
860e1d6b 100 */
393ad299 101static int __wait_latch(u16 port, u8 val)
860e1d6b
RL
102{
103 unsigned int i;
104
105 for (i = 0; i < 20; i++) {
106 if (!__check_latch(port, val))
107 return 0;
108 udelay(5);
109 }
110
393ad299 111 return -EIO;
860e1d6b
RL
112}
113
114/*
393ad299 115 * __device_refresh - request a refresh from the accelerometer. Does not wait
6acc369a 116 * for refresh to complete. Callers must hold hdaps_mtx.
860e1d6b 117 */
393ad299 118static void __device_refresh(void)
860e1d6b 119{
393ad299
RL
120 udelay(200);
121 if (inb(0x1604) != STATE_FRESH) {
122 outb(0x11, 0x1610);
123 outb(0x01, 0x161f);
124 }
125}
860e1d6b 126
393ad299
RL
127/*
128 * __device_refresh_sync - request a synchronous refresh from the
129 * accelerometer. We wait for the refresh to complete. Returns zero if
6acc369a 130 * successful and nonzero on error. Callers must hold hdaps_mtx.
393ad299
RL
131 */
132static int __device_refresh_sync(void)
133{
134 __device_refresh();
860e1d6b
RL
135 return __wait_latch(0x1604, STATE_FRESH);
136}
137
138/*
393ad299 139 * __device_complete - indicate to the accelerometer that we are done reading
6acc369a 140 * data, and then initiate an async refresh. Callers must hold hdaps_mtx.
860e1d6b
RL
141 */
142static inline void __device_complete(void)
143{
144 inb(0x161f);
145 inb(0x1604);
393ad299 146 __device_refresh();
860e1d6b
RL
147}
148
149/*
150 * hdaps_readb_one - reads a byte from a single I/O port, placing the value in
151 * the given pointer. Returns zero on success or a negative error on failure.
152 * Can sleep.
153 */
154static int hdaps_readb_one(unsigned int port, u8 *val)
155{
156 int ret;
157
6acc369a 158 mutex_lock(&hdaps_mtx);
860e1d6b 159
393ad299
RL
160 /* do a sync refresh -- we need to be sure that we read fresh data */
161 ret = __device_refresh_sync();
162 if (ret)
163 goto out;
164
165 *val = inb(port);
166 __device_complete();
167
168out:
6acc369a 169 mutex_unlock(&hdaps_mtx);
860e1d6b
RL
170 return ret;
171}
172
393ad299 173/* __hdaps_read_pair - internal lockless helper for hdaps_read_pair(). */
860e1d6b
RL
174static int __hdaps_read_pair(unsigned int port1, unsigned int port2,
175 int *x, int *y)
176{
177 /* do a sync refresh -- we need to be sure that we read fresh data */
393ad299 178 if (__device_refresh_sync())
860e1d6b
RL
179 return -EIO;
180
181 *y = inw(port2);
182 *x = inw(port1);
183 km_activity = inb(HDAPS_PORT_KMACT);
184 __device_complete();
185
186 /* if hdaps_invert is set, negate the two values */
187 if (hdaps_invert) {
188 *x = -*x;
189 *y = -*y;
190 }
191
192 return 0;
193}
194
195/*
196 * hdaps_read_pair - reads the values from a pair of ports, placing the values
197 * in the given pointers. Returns zero on success. Can sleep.
198 */
199static int hdaps_read_pair(unsigned int port1, unsigned int port2,
200 int *val1, int *val2)
201{
202 int ret;
203
6acc369a 204 mutex_lock(&hdaps_mtx);
860e1d6b 205 ret = __hdaps_read_pair(port1, port2, val1, val2);
6acc369a 206 mutex_unlock(&hdaps_mtx);
860e1d6b
RL
207
208 return ret;
209}
210
393ad299
RL
211/*
212 * hdaps_device_init - initialize the accelerometer. Returns zero on success
213 * and negative error code on failure. Can sleep.
214 */
860e1d6b
RL
215static int hdaps_device_init(void)
216{
393ad299 217 int total, ret = -ENXIO;
860e1d6b 218
6acc369a 219 mutex_lock(&hdaps_mtx);
860e1d6b
RL
220
221 outb(0x13, 0x1610);
222 outb(0x01, 0x161f);
223 if (__wait_latch(0x161f, 0x00))
224 goto out;
225
226 /*
393ad299
RL
227 * Most ThinkPads return 0x01.
228 *
229 * Others--namely the R50p, T41p, and T42p--return 0x03. These laptops
230 * have "inverted" axises.
860e1d6b
RL
231 *
232 * The 0x02 value occurs when the chip has been previously initialized.
233 */
234 if (__check_latch(0x1611, 0x03) &&
235 __check_latch(0x1611, 0x02) &&
236 __check_latch(0x1611, 0x01))
237 goto out;
238
239 printk(KERN_DEBUG "hdaps: initial latch check good (0x%02x).\n",
240 __get_latch(0x1611));
241
242 outb(0x17, 0x1610);
243 outb(0x81, 0x1611);
244 outb(0x01, 0x161f);
245 if (__wait_latch(0x161f, 0x00))
246 goto out;
247 if (__wait_latch(0x1611, 0x00))
248 goto out;
249 if (__wait_latch(0x1612, 0x60))
250 goto out;
251 if (__wait_latch(0x1613, 0x00))
252 goto out;
253 outb(0x14, 0x1610);
254 outb(0x01, 0x1611);
255 outb(0x01, 0x161f);
256 if (__wait_latch(0x161f, 0x00))
257 goto out;
258 outb(0x10, 0x1610);
259 outb(0xc8, 0x1611);
260 outb(0x00, 0x1612);
261 outb(0x02, 0x1613);
262 outb(0x01, 0x161f);
263 if (__wait_latch(0x161f, 0x00))
264 goto out;
393ad299 265 if (__device_refresh_sync())
860e1d6b
RL
266 goto out;
267 if (__wait_latch(0x1611, 0x00))
268 goto out;
269
270 /* we have done our dance, now let's wait for the applause */
393ad299
RL
271 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
272 int x, y;
860e1d6b
RL
273
274 /* a read of the device helps push it into action */
393ad299 275 __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
860e1d6b
RL
276 if (!__wait_latch(0x1611, 0x02)) {
277 ret = 0;
278 break;
279 }
280
281 msleep(INIT_WAIT_MSECS);
860e1d6b
RL
282 }
283
284out:
6acc369a 285 mutex_unlock(&hdaps_mtx);
860e1d6b
RL
286 return ret;
287}
288
289
860e1d6b
RL
290/* Device model stuff */
291
3ae5eaec 292static int hdaps_probe(struct platform_device *dev)
860e1d6b
RL
293{
294 int ret;
295
296 ret = hdaps_device_init();
297 if (ret)
298 return ret;
299
300 printk(KERN_INFO "hdaps: device successfully initialized.\n");
301 return 0;
302}
303
3ae5eaec 304static int hdaps_resume(struct platform_device *dev)
860e1d6b 305{
9480e307 306 return hdaps_device_init();
860e1d6b
RL
307}
308
3ae5eaec 309static struct platform_driver hdaps_driver = {
860e1d6b 310 .probe = hdaps_probe,
3ae5eaec
RK
311 .resume = hdaps_resume,
312 .driver = {
313 .name = "hdaps",
314 .owner = THIS_MODULE,
315 },
860e1d6b
RL
316};
317
393ad299 318/*
6acc369a 319 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mtx.
393ad299
RL
320 */
321static void hdaps_calibrate(void)
322{
323 __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y);
324}
325
326static void hdaps_mousedev_poll(unsigned long unused)
327{
328 int x, y;
329
330 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
6acc369a 331 if (mutex_trylock(&hdaps_mtx)) {
393ad299
RL
332 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
333 return;
334 }
335
336 if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
337 goto out;
338
d12eb7e1
DT
339 input_report_abs(hdaps_idev, ABS_X, x - rest_x);
340 input_report_abs(hdaps_idev, ABS_Y, y - rest_y);
341 input_sync(hdaps_idev);
393ad299
RL
342
343 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
344
345out:
6acc369a 346 mutex_unlock(&hdaps_mtx);
393ad299
RL
347}
348
860e1d6b
RL
349
350/* Sysfs Files */
351
352static ssize_t hdaps_position_show(struct device *dev,
353 struct device_attribute *attr, char *buf)
354{
355 int ret, x, y;
356
357 ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
358 if (ret)
359 return ret;
360
361 return sprintf(buf, "(%d,%d)\n", x, y);
362}
363
364static ssize_t hdaps_variance_show(struct device *dev,
365 struct device_attribute *attr, char *buf)
366{
367 int ret, x, y;
368
369 ret = hdaps_read_pair(HDAPS_PORT_XVAR, HDAPS_PORT_YVAR, &x, &y);
370 if (ret)
371 return ret;
372
373 return sprintf(buf, "(%d,%d)\n", x, y);
374}
375
376static ssize_t hdaps_temp1_show(struct device *dev,
377 struct device_attribute *attr, char *buf)
378{
379 u8 temp;
380 int ret;
381
382 ret = hdaps_readb_one(HDAPS_PORT_TEMP1, &temp);
383 if (ret < 0)
384 return ret;
385
386 return sprintf(buf, "%u\n", temp);
387}
388
389static ssize_t hdaps_temp2_show(struct device *dev,
390 struct device_attribute *attr, char *buf)
391{
392 u8 temp;
393 int ret;
394
395 ret = hdaps_readb_one(HDAPS_PORT_TEMP2, &temp);
396 if (ret < 0)
397 return ret;
398
399 return sprintf(buf, "%u\n", temp);
400}
401
402static ssize_t hdaps_keyboard_activity_show(struct device *dev,
403 struct device_attribute *attr,
404 char *buf)
405{
406 return sprintf(buf, "%u\n", KEYBD_ISSET(km_activity));
407}
408
409static ssize_t hdaps_mouse_activity_show(struct device *dev,
410 struct device_attribute *attr,
411 char *buf)
412{
413 return sprintf(buf, "%u\n", MOUSE_ISSET(km_activity));
414}
415
416static ssize_t hdaps_calibrate_show(struct device *dev,
417 struct device_attribute *attr, char *buf)
418{
419 return sprintf(buf, "(%d,%d)\n", rest_x, rest_y);
420}
421
422static ssize_t hdaps_calibrate_store(struct device *dev,
423 struct device_attribute *attr,
424 const char *buf, size_t count)
425{
6acc369a 426 mutex_lock(&hdaps_mtx);
860e1d6b 427 hdaps_calibrate();
6acc369a 428 mutex_unlock(&hdaps_mtx);
860e1d6b
RL
429
430 return count;
431}
432
433static ssize_t hdaps_invert_show(struct device *dev,
434 struct device_attribute *attr, char *buf)
435{
436 return sprintf(buf, "%u\n", hdaps_invert);
437}
438
439static ssize_t hdaps_invert_store(struct device *dev,
440 struct device_attribute *attr,
441 const char *buf, size_t count)
442{
443 int invert;
444
445 if (sscanf(buf, "%d", &invert) != 1 || (invert != 1 && invert != 0))
446 return -EINVAL;
447
448 hdaps_invert = invert;
449 hdaps_calibrate();
450
451 return count;
452}
453
860e1d6b
RL
454static DEVICE_ATTR(position, 0444, hdaps_position_show, NULL);
455static DEVICE_ATTR(variance, 0444, hdaps_variance_show, NULL);
456static DEVICE_ATTR(temp1, 0444, hdaps_temp1_show, NULL);
457static DEVICE_ATTR(temp2, 0444, hdaps_temp2_show, NULL);
458static DEVICE_ATTR(keyboard_activity, 0444, hdaps_keyboard_activity_show, NULL);
459static DEVICE_ATTR(mouse_activity, 0444, hdaps_mouse_activity_show, NULL);
460static DEVICE_ATTR(calibrate, 0644, hdaps_calibrate_show,hdaps_calibrate_store);
461static DEVICE_ATTR(invert, 0644, hdaps_invert_show, hdaps_invert_store);
860e1d6b
RL
462
463static struct attribute *hdaps_attributes[] = {
464 &dev_attr_position.attr,
465 &dev_attr_variance.attr,
466 &dev_attr_temp1.attr,
467 &dev_attr_temp2.attr,
468 &dev_attr_keyboard_activity.attr,
469 &dev_attr_mouse_activity.attr,
470 &dev_attr_calibrate.attr,
860e1d6b
RL
471 &dev_attr_invert.attr,
472 NULL,
473};
474
475static struct attribute_group hdaps_attribute_group = {
476 .attrs = hdaps_attributes,
477};
478
479
480/* Module stuff */
481
4c87b74c 482/* hdaps_dmi_match - found a match. return one, short-circuiting the hunt. */
509a5e85 483static int __init hdaps_dmi_match(struct dmi_system_id *id)
860e1d6b
RL
484{
485 printk(KERN_INFO "hdaps: %s detected.\n", id->ident);
4c87b74c 486 return 1;
860e1d6b
RL
487}
488
4c87b74c 489/* hdaps_dmi_match_invert - found an inverted match. */
509a5e85 490static int __init hdaps_dmi_match_invert(struct dmi_system_id *id)
860e1d6b
RL
491{
492 hdaps_invert = 1;
493 printk(KERN_INFO "hdaps: inverting axis readings.\n");
4c87b74c 494 return hdaps_dmi_match(id);
860e1d6b
RL
495}
496
509a5e85
JD
497#define HDAPS_DMI_MATCH_NORMAL(vendor, model) { \
498 .ident = vendor " " model, \
860e1d6b
RL
499 .callback = hdaps_dmi_match, \
500 .matches = { \
509a5e85 501 DMI_MATCH(DMI_BOARD_VENDOR, vendor), \
860e1d6b
RL
502 DMI_MATCH(DMI_PRODUCT_VERSION, model) \
503 } \
504}
505
509a5e85
JD
506#define HDAPS_DMI_MATCH_INVERT(vendor, model) { \
507 .ident = vendor " " model, \
860e1d6b
RL
508 .callback = hdaps_dmi_match_invert, \
509 .matches = { \
509a5e85 510 DMI_MATCH(DMI_BOARD_VENDOR, vendor), \
860e1d6b
RL
511 DMI_MATCH(DMI_PRODUCT_VERSION, model) \
512 } \
513}
514
509a5e85 515/* Note that HDAPS_DMI_MATCH_NORMAL("ThinkPad T42") would match
0f23e50a
SB
516 "ThinkPad T42p", so the order of the entries matters.
517 If your ThinkPad is not recognized, please update to latest
518 BIOS. This is especially the case for some R52 ThinkPads. */
509a5e85 519static struct dmi_system_id __initdata hdaps_whitelist[] = {
509a5e85
JD
520 HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad R50p"),
521 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"),
522 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"),
523 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"),
509a5e85
JD
524 HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"),
525 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"),
526 HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"),
527 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"),
528 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"),
529 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"),
530 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"),
531 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"),
532 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"),
533 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"),
534 { .ident = NULL }
535};
0f6c840d 536
860e1d6b
RL
537static int __init hdaps_init(void)
538{
539 int ret;
540
860e1d6b
RL
541 if (!dmi_check_system(hdaps_whitelist)) {
542 printk(KERN_WARNING "hdaps: supported laptop not found!\n");
b3f28a9a 543 ret = -ENODEV;
860e1d6b
RL
544 goto out;
545 }
546
547 if (!request_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS, "hdaps")) {
548 ret = -ENXIO;
549 goto out;
550 }
551
3ae5eaec 552 ret = platform_driver_register(&hdaps_driver);
860e1d6b
RL
553 if (ret)
554 goto out_region;
555
556 pdev = platform_device_register_simple("hdaps", -1, NULL, 0);
557 if (IS_ERR(pdev)) {
558 ret = PTR_ERR(pdev);
559 goto out_driver;
560 }
561
562 ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group);
563 if (ret)
564 goto out_device;
565
d12eb7e1
DT
566 hdaps_idev = input_allocate_device();
567 if (!hdaps_idev) {
568 ret = -ENOMEM;
569 goto out_group;
570 }
571
393ad299
RL
572 /* initial calibrate for the input device */
573 hdaps_calibrate();
574
575 /* initialize the input class */
d12eb7e1 576 hdaps_idev->name = "hdaps";
c5ddb547 577 hdaps_idev->dev.parent = &pdev->dev;
d12eb7e1
DT
578 hdaps_idev->evbit[0] = BIT(EV_ABS);
579 input_set_abs_params(hdaps_idev, ABS_X,
580 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
657a19eb 581 input_set_abs_params(hdaps_idev, ABS_Y,
d12eb7e1
DT
582 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
583
b25a1063
DT
584 ret = input_register_device(hdaps_idev);
585 if (ret)
586 goto out_idev;
393ad299
RL
587
588 /* start up our timer for the input device */
589 init_timer(&hdaps_timer);
590 hdaps_timer.function = hdaps_mousedev_poll;
591 hdaps_timer.expires = jiffies + HDAPS_POLL_PERIOD;
592 add_timer(&hdaps_timer);
860e1d6b
RL
593
594 printk(KERN_INFO "hdaps: driver successfully loaded.\n");
595 return 0;
596
b25a1063
DT
597out_idev:
598 input_free_device(hdaps_idev);
d12eb7e1
DT
599out_group:
600 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
860e1d6b
RL
601out_device:
602 platform_device_unregister(pdev);
603out_driver:
3ae5eaec 604 platform_driver_unregister(&hdaps_driver);
860e1d6b
RL
605out_region:
606 release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
607out:
608 printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret);
609 return ret;
610}
611
612static void __exit hdaps_exit(void)
613{
393ad299 614 del_timer_sync(&hdaps_timer);
d12eb7e1 615 input_unregister_device(hdaps_idev);
860e1d6b
RL
616 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
617 platform_device_unregister(pdev);
3ae5eaec 618 platform_driver_unregister(&hdaps_driver);
860e1d6b
RL
619 release_region(HDAPS_LOW_PORT, HDAPS_NR_PORTS);
620
621 printk(KERN_INFO "hdaps: driver unloaded.\n");
622}
623
624module_init(hdaps_init);
625module_exit(hdaps_exit);
626
860e1d6b
RL
627module_param_named(invert, hdaps_invert, bool, 0);
628MODULE_PARM_DESC(invert, "invert data along each axis");
629
630MODULE_AUTHOR("Robert Love");
631MODULE_DESCRIPTION("IBM Hard Drive Active Protection System (HDAPS) driver");
632MODULE_LICENSE("GPL v2");