diff options
author | Pavel Machek <pavel@suse.cz> | 2009-02-18 17:48:23 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-02-18 18:37:54 -0500 |
commit | ef2cfc790bf5f0ff189b01eabc0f4feb5e8524df (patch) | |
tree | 1e1a4999a6615f66f56ffe19c883e065aa8d3020 /Documentation | |
parent | 3a5093ee6728c8cbe9c039e685fc1fca8f965048 (diff) |
hp accelerometer: add freefall detection
This adds freefall handling to hp_accel driver. According to HP, it
should just work, without us having to set the chip up by hand.
hpfall.c is example .c program that parks the disk when accelerometer
detects free fall. It should work; for now, it uses fixed 20seconds
protection period.
Signed-off-by: Pavel Machek <pavel@suse.cz>
Cc: Thomas Renninger <trenn@suse.de>
Cc: Éric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/hwmon/hpfall.c | 101 | ||||
-rw-r--r-- | Documentation/hwmon/lis3lv02d | 8 |
2 files changed, 109 insertions, 0 deletions
diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c new file mode 100644 index 000000000000..bbea1ccfd46a --- /dev/null +++ b/Documentation/hwmon/hpfall.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* Disk protection for HP machines. | ||
2 | * | ||
3 | * Copyright 2008 Eric Piel | ||
4 | * Copyright 2009 Pavel Machek <pavel@suse.cz> | ||
5 | * | ||
6 | * GPLv2. | ||
7 | */ | ||
8 | |||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <unistd.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <sys/stat.h> | ||
14 | #include <sys/types.h> | ||
15 | #include <string.h> | ||
16 | #include <stdint.h> | ||
17 | #include <errno.h> | ||
18 | #include <signal.h> | ||
19 | |||
20 | void write_int(char *path, int i) | ||
21 | { | ||
22 | char buf[1024]; | ||
23 | int fd = open(path, O_RDWR); | ||
24 | if (fd < 0) { | ||
25 | perror("open"); | ||
26 | exit(1); | ||
27 | } | ||
28 | sprintf(buf, "%d", i); | ||
29 | if (write(fd, buf, strlen(buf)) != strlen(buf)) { | ||
30 | perror("write"); | ||
31 | exit(1); | ||
32 | } | ||
33 | close(fd); | ||
34 | } | ||
35 | |||
36 | void set_led(int on) | ||
37 | { | ||
38 | write_int("/sys/class/leds/hp::hddprotect/brightness", on); | ||
39 | } | ||
40 | |||
41 | void protect(int seconds) | ||
42 | { | ||
43 | write_int("/sys/block/sda/device/unload_heads", seconds*1000); | ||
44 | } | ||
45 | |||
46 | int on_ac(void) | ||
47 | { | ||
48 | // /sys/class/power_supply/AC0/online | ||
49 | } | ||
50 | |||
51 | int lid_open(void) | ||
52 | { | ||
53 | // /proc/acpi/button/lid/LID/state | ||
54 | } | ||
55 | |||
56 | void ignore_me(void) | ||
57 | { | ||
58 | protect(0); | ||
59 | set_led(0); | ||
60 | |||
61 | } | ||
62 | |||
63 | int main(int argc, char* argv[]) | ||
64 | { | ||
65 | int fd, ret; | ||
66 | |||
67 | fd = open("/dev/freefall", O_RDONLY); | ||
68 | if (fd < 0) { | ||
69 | perror("open"); | ||
70 | return EXIT_FAILURE; | ||
71 | } | ||
72 | |||
73 | signal(SIGALRM, ignore_me); | ||
74 | |||
75 | for (;;) { | ||
76 | unsigned char count; | ||
77 | |||
78 | ret = read(fd, &count, sizeof(count)); | ||
79 | alarm(0); | ||
80 | if ((ret == -1) && (errno == EINTR)) { | ||
81 | /* Alarm expired, time to unpark the heads */ | ||
82 | continue; | ||
83 | } | ||
84 | |||
85 | if (ret != sizeof(count)) { | ||
86 | perror("read"); | ||
87 | break; | ||
88 | } | ||
89 | |||
90 | protect(21); | ||
91 | set_led(1); | ||
92 | if (1 || on_ac() || lid_open()) { | ||
93 | alarm(2); | ||
94 | } else { | ||
95 | alarm(20); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | close(fd); | ||
100 | return EXIT_SUCCESS; | ||
101 | } | ||
diff --git a/Documentation/hwmon/lis3lv02d b/Documentation/hwmon/lis3lv02d index 0fcfc4a7ccdc..287f8c902656 100644 --- a/Documentation/hwmon/lis3lv02d +++ b/Documentation/hwmon/lis3lv02d | |||
@@ -33,6 +33,14 @@ rate - reports the sampling rate of the accelerometer device in HZ | |||
33 | This driver also provides an absolute input class device, allowing | 33 | This driver also provides an absolute input class device, allowing |
34 | the laptop to act as a pinball machine-esque joystick. | 34 | the laptop to act as a pinball machine-esque joystick. |
35 | 35 | ||
36 | Another feature of the driver is misc device called "freefall" that | ||
37 | acts similar to /dev/rtc and reacts on free-fall interrupts received | ||
38 | from the device. It supports blocking operations, poll/select and | ||
39 | fasync operation modes. You must read 1 bytes from the device. The | ||
40 | result is number of free-fall interrupts since the last successful | ||
41 | read (or 255 if number of interrupts would not fit). | ||
42 | |||
43 | |||
36 | Axes orientation | 44 | Axes orientation |
37 | ---------------- | 45 | ---------------- |
38 | 46 | ||