diff options
Diffstat (limited to 'Documentation/laptops')
-rw-r--r-- | Documentation/laptops/hpfall.c | 146 | ||||
-rw-r--r-- | Documentation/laptops/sony-laptop.txt | 37 |
2 files changed, 176 insertions, 7 deletions
diff --git a/Documentation/laptops/hpfall.c b/Documentation/laptops/hpfall.c new file mode 100644 index 000000000000..a4a8fc5d05d4 --- /dev/null +++ b/Documentation/laptops/hpfall.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* Disk protection for HP machines. | ||
2 | * | ||
3 | * Copyright 2008 Eric Piel | ||
4 | * Copyright 2009 Pavel Machek <pavel@ucw.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 | #include <sys/mman.h> | ||
20 | #include <sched.h> | ||
21 | |||
22 | char unload_heads_path[64]; | ||
23 | |||
24 | int set_unload_heads_path(char *device) | ||
25 | { | ||
26 | char devname[64]; | ||
27 | |||
28 | if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0) | ||
29 | return -EINVAL; | ||
30 | strncpy(devname, device + 5, sizeof(devname)); | ||
31 | |||
32 | snprintf(unload_heads_path, sizeof(unload_heads_path), | ||
33 | "/sys/block/%s/device/unload_heads", devname); | ||
34 | return 0; | ||
35 | } | ||
36 | int valid_disk(void) | ||
37 | { | ||
38 | int fd = open(unload_heads_path, O_RDONLY); | ||
39 | if (fd < 0) { | ||
40 | perror(unload_heads_path); | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | close(fd); | ||
45 | return 1; | ||
46 | } | ||
47 | |||
48 | void write_int(char *path, int i) | ||
49 | { | ||
50 | char buf[1024]; | ||
51 | int fd = open(path, O_RDWR); | ||
52 | if (fd < 0) { | ||
53 | perror("open"); | ||
54 | exit(1); | ||
55 | } | ||
56 | sprintf(buf, "%d", i); | ||
57 | if (write(fd, buf, strlen(buf)) != strlen(buf)) { | ||
58 | perror("write"); | ||
59 | exit(1); | ||
60 | } | ||
61 | close(fd); | ||
62 | } | ||
63 | |||
64 | void set_led(int on) | ||
65 | { | ||
66 | write_int("/sys/class/leds/hp::hddprotect/brightness", on); | ||
67 | } | ||
68 | |||
69 | void protect(int seconds) | ||
70 | { | ||
71 | write_int(unload_heads_path, seconds*1000); | ||
72 | } | ||
73 | |||
74 | int on_ac(void) | ||
75 | { | ||
76 | // /sys/class/power_supply/AC0/online | ||
77 | } | ||
78 | |||
79 | int lid_open(void) | ||
80 | { | ||
81 | // /proc/acpi/button/lid/LID/state | ||
82 | } | ||
83 | |||
84 | void ignore_me(void) | ||
85 | { | ||
86 | protect(0); | ||
87 | set_led(0); | ||
88 | } | ||
89 | |||
90 | int main(int argc, char **argv) | ||
91 | { | ||
92 | int fd, ret; | ||
93 | struct sched_param param; | ||
94 | |||
95 | if (argc == 1) | ||
96 | ret = set_unload_heads_path("/dev/sda"); | ||
97 | else if (argc == 2) | ||
98 | ret = set_unload_heads_path(argv[1]); | ||
99 | else | ||
100 | ret = -EINVAL; | ||
101 | |||
102 | if (ret || !valid_disk()) { | ||
103 | fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n", | ||
104 | argv[0]); | ||
105 | exit(1); | ||
106 | } | ||
107 | |||
108 | fd = open("/dev/freefall", O_RDONLY); | ||
109 | if (fd < 0) { | ||
110 | perror("/dev/freefall"); | ||
111 | return EXIT_FAILURE; | ||
112 | } | ||
113 | |||
114 | daemon(0, 0); | ||
115 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); | ||
116 | sched_setscheduler(0, SCHED_FIFO, ¶m); | ||
117 | mlockall(MCL_CURRENT|MCL_FUTURE); | ||
118 | |||
119 | signal(SIGALRM, ignore_me); | ||
120 | |||
121 | for (;;) { | ||
122 | unsigned char count; | ||
123 | |||
124 | ret = read(fd, &count, sizeof(count)); | ||
125 | alarm(0); | ||
126 | if ((ret == -1) && (errno == EINTR)) { | ||
127 | /* Alarm expired, time to unpark the heads */ | ||
128 | continue; | ||
129 | } | ||
130 | |||
131 | if (ret != sizeof(count)) { | ||
132 | perror("read"); | ||
133 | break; | ||
134 | } | ||
135 | |||
136 | protect(21); | ||
137 | set_led(1); | ||
138 | if (1 || on_ac() || lid_open()) | ||
139 | alarm(2); | ||
140 | else | ||
141 | alarm(20); | ||
142 | } | ||
143 | |||
144 | close(fd); | ||
145 | return EXIT_SUCCESS; | ||
146 | } | ||
diff --git a/Documentation/laptops/sony-laptop.txt b/Documentation/laptops/sony-laptop.txt index 23ce7d350d1a..2bd4e82e5d9f 100644 --- a/Documentation/laptops/sony-laptop.txt +++ b/Documentation/laptops/sony-laptop.txt | |||
@@ -14,7 +14,8 @@ Some models report hotkeys through the SNC or SPIC devices, such events are | |||
14 | reported both through the ACPI subsystem as acpi events and through the INPUT | 14 | reported both through the ACPI subsystem as acpi events and through the INPUT |
15 | subsystem. See the logs of acpid or /proc/acpi/event and | 15 | subsystem. See the logs of acpid or /proc/acpi/event and |
16 | /proc/bus/input/devices to find out what those events are and which input | 16 | /proc/bus/input/devices to find out what those events are and which input |
17 | devices are created by the driver. | 17 | devices are created by the driver. Additionally, loading the driver with the |
18 | debug option will report all events in the kernel log. | ||
18 | 19 | ||
19 | Backlight control: | 20 | Backlight control: |
20 | ------------------ | 21 | ------------------ |
@@ -64,6 +65,16 @@ powers off the sound card, | |||
64 | # echo "1" > /sys/devices/platform/sony-laptop/audiopower | 65 | # echo "1" > /sys/devices/platform/sony-laptop/audiopower |
65 | powers on the sound card. | 66 | powers on the sound card. |
66 | 67 | ||
68 | |||
69 | RFkill control: | ||
70 | --------------- | ||
71 | More recent Vaio models expose a consistent set of ACPI methods to | ||
72 | control radio frequency emitting devices. If you are a lucky owner of | ||
73 | such a laptop you will find the necessary rfkill devices under | ||
74 | /sys/class/rfkill. Check those starting with sony-* in | ||
75 | # grep . /sys/class/rfkill/*/{state,name} | ||
76 | |||
77 | |||
67 | Development: | 78 | Development: |
68 | ------------ | 79 | ------------ |
69 | 80 | ||
@@ -75,8 +86,21 @@ pass the option 'debug=1'. | |||
75 | REPEAT: DON'T DO THIS IF YOU DON'T LIKE RISKY BUSINESS. | 86 | REPEAT: DON'T DO THIS IF YOU DON'T LIKE RISKY BUSINESS. |
76 | 87 | ||
77 | In your kernel logs you will find the list of all ACPI methods | 88 | In your kernel logs you will find the list of all ACPI methods |
78 | the SNC device has on your laptop. You can see the GCDP/GCDP methods | 89 | the SNC device has on your laptop. |
79 | used to pwer on/off the CD drive, but there are others. | 90 | |
91 | * For new models you will see a long list of meaningless method names, | ||
92 | reading the DSDT table source should reveal that: | ||
93 | (1) the SNC device uses an internal capability lookup table | ||
94 | (2) SN00 is used to find values in the lookup table | ||
95 | (3) SN06 and SN07 are used to call into the real methods based on | ||
96 | offsets you can obtain iterating the table using SN00 | ||
97 | (4) SN02 used to enable events. | ||
98 | Some values in the capability lookup table are more or less known, see | ||
99 | the code for all sony_call_snc_handle calls, others are more obscure. | ||
100 | |||
101 | * For old models you can see the GCDP/GCDP methods used to pwer on/off | ||
102 | the CD drive, but there are others and they are usually different from | ||
103 | model to model. | ||
80 | 104 | ||
81 | I HAVE NO IDEA WHAT THOSE METHODS DO. | 105 | I HAVE NO IDEA WHAT THOSE METHODS DO. |
82 | 106 | ||
@@ -108,9 +132,8 @@ Bugs/Limitations: | |||
108 | laptop, including permanent damage. | 132 | laptop, including permanent damage. |
109 | 133 | ||
110 | * The sony-laptop and sonypi drivers do not interact at all. In the | 134 | * The sony-laptop and sonypi drivers do not interact at all. In the |
111 | future, sonypi could use sony-laptop to do (part of) its business. | 135 | future, sonypi will be removed and replaced by sony-laptop. |
112 | 136 | ||
113 | * spicctrl, which is the userspace tool used to communicate with the | 137 | * spicctrl, which is the userspace tool used to communicate with the |
114 | sonypi driver (through /dev/sonypi) does not try to use the | 138 | sonypi driver (through /dev/sonypi) is deprecated as well since all |
115 | sony-laptop driver. In the future, spicctrl could try sonypi first, | 139 | its features are now available under the sysfs tree via sony-laptop. |
116 | and if it isn't present, try sony-laptop instead. | ||