Guest User

Untitled

a guest
Oct 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. # cat ../linux-patches/ideapad-z570-support.patch
  2. From: Maxim Mikityanskiy <maxtram95@gmail.com>
  3.  
  4. The patch adds support for Lenovo IdeaPad Z570 laptop. It makes all special
  5. keys working, adds possibility to control fan like Windows does, controls
  6. Touchpad Disabled LED, toggles touchpad state via psmouse with previous
  7. patch and corrects touchpad behavior on resume from suspend. It is new,
  8. modified version of patch.
  9.  
  10. Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
  11. --- linux/drivers/platform/x86/ideapad-laptop.c.orig
  12. +++ linux/drivers/platform/x86/ideapad-laptop.c
  13. @@ -36,6 +36,7 @@
  14. #include <linux/fb.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/seq_file.h>
  17. +#include <linux/input/psmouse.h>
  18.  
  19. #define IDEAPAD_RFKILL_DEV_NUM (3)
  20.  
  21. @@ -62,9 +63,12 @@ enum {
  22. VPCCMD_W_CAMERA,
  23. VPCCMD_R_3G,
  24. VPCCMD_W_3G,
  25. - VPCCMD_R_ODD, /* 0x21 */
  26. - VPCCMD_R_RF = 0x23,
  27. - VPCCMD_W_RF,
  28. + VPCCMD_R_ODD,
  29. + VPCCMD_W_FAN,
  30. + VPCCMD_R_RF,
  31. + VPCCMD_W_RF, /* 0x24 */
  32. + VPCCMD_R_FAN = 0x2B,
  33. + VPCCMD_R_SPECIAL_BUTTONS = 0x31,
  34. VPCCMD_W_BL_POWER = 0x33,
  35. };
  36.  
  37. @@ -363,8 +367,47 @@ static ssize_t store_ideapad_cam(struct
  38.  
  39. static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
  40.  
  41. +static ssize_t show_ideapad_fan(struct device *dev,
  42. + struct device_attribute *attr,
  43. + char *buf)
  44. +{
  45. + unsigned long result;
  46. +
  47. + if (read_ec_data(ideapad_handle, VPCCMD_R_FAN, &result))
  48. + return sprintf(buf, "-1\n");
  49. + return sprintf(buf, "%lu\n", result);
  50. +}
  51. +
  52. +static ssize_t store_ideapad_fan(struct device *dev,
  53. + struct device_attribute *attr,
  54. + const char *buf, size_t count)
  55. +{
  56. + int ret, state;
  57. +
  58. + if (!count)
  59. + return 0;
  60. + if (sscanf(buf, "%i", &state) != 1)
  61. + return -EINVAL;
  62. + /* WARNING: these fan states are not speed
  63. + * so it isn't cooling_device interface
  64. + * 0 = super silent mode
  65. + * 1 = standard mode
  66. + * 2 = dust cleaning
  67. + * 4 = efficient thermal dissipation mode
  68. + */
  69. + if (state < 0 || state > 4 || state == 3)
  70. + return -EINVAL;
  71. + ret = write_ec_cmd(ideapad_handle, VPCCMD_W_FAN, state);
  72. + if (ret < 0)
  73. + return ret;
  74. + return count;
  75. +}
  76. +
  77. +static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);
  78. +
  79. static struct attribute *ideapad_attributes[] = {
  80. &dev_attr_camera_power.attr,
  81. + &dev_attr_fan_mode.attr,
  82. NULL
  83. };
  84.  
  85. @@ -379,6 +422,10 @@ static umode_t ideapad_is_visible(struct
  86. if (attr == &dev_attr_camera_power.attr)
  87. supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg));
  88. else
  89. + if (attr == &dev_attr_fan_mode.attr) {
  90. + unsigned long value;
  91. + supported = !read_ec_data(ideapad_handle, VPCCMD_R_FAN, &value);
  92. + } else
  93. supported = true;
  94.  
  95. return supported ? attr->mode : 0;
  96. @@ -519,9 +566,15 @@ static void ideapad_platform_exit(struct
  97. */
  98. static const struct key_entry ideapad_keymap[] = {
  99. { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } },
  100. + { KE_KEY, 7, { KEY_CAMERA } },
  101. + { KE_KEY, 11, { KEY_F16 } },
  102. { KE_KEY, 13, { KEY_WLAN } },
  103. { KE_KEY, 16, { KEY_PROG1 } },
  104. { KE_KEY, 17, { KEY_PROG2 } },
  105. + { KE_KEY, 64, { KEY_PROG3 } },
  106. + { KE_KEY, 65, { KEY_PROG4 } },
  107. + { KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
  108. + { KE_KEY, 67, { KEY_TOUCHPAD_ON } },
  109. { KE_END, 0 },
  110. };
  111.  
  112. @@ -697,6 +750,7 @@ static int __devinit ideapad_acpi_add(st
  113. int ret, i;
  114. unsigned long cfg;
  115. struct ideapad_private *priv;
  116. + unsigned long value;
  117.  
  118. if (read_method_int(adevice->handle, "_CFG", (int *)&cfg))
  119. return -ENODEV;
  120. @@ -729,6 +783,16 @@ static int __devinit ideapad_acpi_add(st
  121. }
  122. ideapad_sync_rfk_state(priv);
  123.  
  124. + /* Sync touchpad state */
  125. + if (!read_ec_data(adevice->handle, VPCCMD_R_TOUCHPAD,
  126. + &value)) {
  127. + if (value) {
  128. + psmouse_enable();
  129. + } else {
  130. + psmouse_disable();
  131. + }
  132. + }
  133. +
  134. if (!acpi_video_backlight_support()) {
  135. ret = ideapad_backlight_init(priv);
  136. if (ret && ret != -ENODEV)
  137. @@ -767,6 +831,26 @@ static int __devexit ideapad_acpi_remove
  138. return 0;
  139. }
  140.  
  141. +static void ideapad_check_special_buttons(struct ideapad_private *priv,
  142. + unsigned long state)
  143. +{
  144. + unsigned long bit;
  145. + for (bit = 0; bit < 16; bit++) {
  146. + if (test_bit(bit, &state)) {
  147. + switch (bit) {
  148. + case 6:
  149. + /* Thermal Management button */
  150. + ideapad_input_report(priv, 65);
  151. + break;
  152. + case 1:
  153. + /* OneKey Theater button */
  154. + ideapad_input_report(priv, 64);
  155. + break;
  156. + }
  157. + }
  158. + }
  159. +}
  160. +
  161. static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
  162. {
  163. struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
  164. @@ -785,6 +869,28 @@ static void ideapad_acpi_notify(struct a
  165. case 9:
  166. ideapad_sync_rfk_state(priv);
  167. break;
  168. + case 5:
  169. + {
  170. + unsigned long value;
  171. + /* DO NOT DELETE: Without reading from EC
  172. + * touchpad LED doesn't switch state */
  173. + if (!read_ec_data(handle, VPCCMD_R_TOUCHPAD,
  174. + &value)) {
  175. + /* Some IdeaPads doesn't really turn
  176. + * off touchpad - they only switch the
  177. + * LED state. We (de)activate psmouse to
  178. + * turn touchpad off and on. We send
  179. + * KEY_TOUCHPAD_OFF and KEY_TOUCHPAD_ON
  180. + * to not to get out of sync with LED */
  181. + if (value)
  182. + psmouse_enable();
  183. + else
  184. + psmouse_disable();
  185. + ideapad_input_report(priv,
  186. + value ? 67 : 66);
  187. + }
  188. + }
  189. + break;
  190. case 4:
  191. ideapad_backlight_notify_brightness(priv);
  192. break;
  193. @@ -794,6 +900,14 @@ static void ideapad_acpi_notify(struct a
  194. case 2:
  195. ideapad_backlight_notify_power(priv);
  196. break;
  197. + case 0:
  198. + {
  199. + unsigned long value;
  200. + read_ec_data(handle, VPCCMD_R_SPECIAL_BUTTONS,
  201. + &value);
  202. + ideapad_check_special_buttons(priv, value);
  203. + }
  204. + break;
  205. default:
  206. ideapad_input_report(priv, vpc_bit);
  207. }
  208. --- linux/Documentation/ABI/testing/sysfs-platform-ideapad-laptop.orig
  209. +++ linux/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
  210. @@ -5,4 +5,14 @@ Contact: "Ike Panhc <ike.pan@canonical.c
  211. Description:
  212. Control the power of camera module. 1 means on, 0 means off.
  213.  
  214. -
  215. +What: /sys/devices/platform/ideapad/fan_mode
  216. +Date: June 2012
  217. +KernelVersion: 3.5
  218. +Contact: "Maxim Mikityanskiy <maxtram95@gmail.com>"
  219. +Description:
  220. + Change fan mode
  221. + There are four available modes:
  222. + * 0 -> Super Silent Mode
  223. + * 1 -> Standard Mode
  224. + * 2 -> Dust Cleaning
  225. + * 4 -> Efficient Thermal Dissipation Mode
  226.  
  227. # cat ../linux-patches/psmouse-toggle.patch
  228. From: Maxim Mikityanskiy <maxtram95@gmail.com>
  229.  
  230. The patch adds interface to enable/disable PS/2 mouse or touchpad from other
  231. kernel modules.
  232. --
  233. As for now, the only correct way for disabling touchpad in software in Linux is
  234. via X server driver xf86-input-synaptics. (I think that unbinding driver from
  235. serio1 is not right way to disable touchpad.) Some laptops have special key to
  236. disable touchpad. This key has very different behavior on different laptops.
  237. Some laptops toggle touchpad in hardware when user presses the key, so these
  238. ones shouldn't have any problems. Other laptops don't toggle touchpad in
  239. hardware at all but expect that software turns it on and off when the key is
  240. pressed. These laptops should send KEY_TOUCHPAD_TOGGLE keycode, so graphical
  241. desktop environment could change touchpad state via xf86-input-synaptics driver.
  242. But there is also third type of laptops. I own one of them, it's Lenovo IdeaPad
  243. Z570. This laptop mixes hardware and software touchpad control. It has special
  244. key for touchpad toggling and LED that should show touchpad state (glows ==
  245. disabled). When user presses the key, touchpad doesn't become disabled in
  246. hardware, but LED state toggles and there is no way to control the LED state
  247. properly. So toggling touchpad state in userspace is a really bad idea, because
  248. there isn't any unified interface to tell userspace touchpad state, so LED state
  249. may become out of sync with real touchpad state, for example, when switching
  250. between X sessions. So we need some low-level way to turn touchpad off directly
  251. from platform driver. In that case ideapad-laptop driver would tell psmouse to
  252. enable/disable touchpad and send KEY_TOUCHPAD_ON/KEY_TOUCHPAD_OFF keycode so
  253. that LED never goes out of sync and GNOME could show graphical notifications
  254. about touchpad state. This patch lets psmouse export functions to control
  255. touchpad state from platform drivers.
  256.  
  257. Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
  258. --- linux/drivers/input/mouse/psmouse-base.c.orig
  259. +++ linux/drivers/input/mouse/psmouse-base.c
  260. @@ -23,6 +23,7 @@
  261. #include <linux/init.h>
  262. #include <linux/libps2.h>
  263. #include <linux/mutex.h>
  264. +#include <linux/device.h>
  265.  
  266. #include "psmouse.h"
  267. #include "synaptics.h"
  268. @@ -1786,6 +1787,48 @@ static int psmouse_get_maxproto(char *bu
  269. return sprintf(buffer, "%s", psmouse_protocol_by_type(type)->name);
  270. }
  271.  
  272. +static int psmouse_match(struct device *dev, void *data)
  273. +{
  274. + return 1;
  275. +}
  276. +
  277. +static struct psmouse *psmouse_get_struct(void)
  278. +{
  279. + struct device *dev;
  280. + struct serio *serio;
  281. + struct psmouse *psmouse;
  282. +
  283. + dev = driver_find_device(&psmouse_drv.driver, NULL, NULL,
  284. + psmouse_match);
  285. + if (dev == NULL)
  286. + return NULL;
  287. +
  288. + serio = to_serio_port(dev);
  289. + psmouse = serio_get_drvdata(serio);
  290. +
  291. + return psmouse;
  292. +}
  293. +
  294. +void psmouse_enable(void)
  295. +{
  296. + struct psmouse *psmouse;
  297. +
  298. + psmouse = psmouse_get_struct();
  299. + if (psmouse != NULL)
  300. + psmouse_activate(psmouse);
  301. +}
  302. +EXPORT_SYMBOL(psmouse_enable);
  303. +
  304. +void psmouse_disable(void)
  305. +{
  306. + struct psmouse *psmouse;
  307. +
  308. + psmouse = psmouse_get_struct();
  309. + if (psmouse != NULL)
  310. + psmouse_deactivate(psmouse);
  311. +}
  312. +EXPORT_SYMBOL(psmouse_disable);
  313. +
  314. static int __init psmouse_init(void)
  315. {
  316. int err;
  317. --- /dev/null
  318. +++ linux/include/linux/input/psmouse.h
  319. @@ -0,0 +1,7 @@
  320. +#ifndef _INPUT_PSMOUSE_H
  321. +#define _INPUT_PSMOUSE_H
  322. +
  323. +void psmouse_enable(void);
  324. +void psmouse_disable(void);
  325. +
  326. +#endif
Add Comment
Please, Sign In to add comment