2 * Input driver for slidebars on some Lenovo IdeaPad laptops
4 * Copyright (C) 2013 Andrey Moiseev <o2g.org.ru@gmail.com>
6 * Reverse-engineered from Lenovo SlideNav software (SBarHook.dll).
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * Trademarks are the property of their respective owners.
17 * Currently tested and works on:
19 * Lenovo IdeaPad Y550P
21 * Other models can be added easily. To test,
22 * load with 'force' parameter set 'true'.
24 * LEDs blinking and input mode are managed via sysfs,
25 * (hex, unsigned byte value):
26 * /sys/devices/platform/ideapad_slidebar/slidebar_mode
28 * The value is in byte range, however, I only figured out
29 * how bits 0b10011001 work. Some other bits, probably,
30 * are meaningfull too.
34 * STD_INT, ONMOV_INT, OFF_INT, LAST_POLL, OFF_POLL
38 * STD 'heartbeat' lights follow the finger
39 * ONMOV no lights lights follow the finger
40 * LAST at last pos lights follow the finger
41 * OFF no lights no lights
43 * INT all input events are generated, interrupts are used
44 * POLL no input events by default, to get them,
45 * send 0b10000000 (read below)
49 * All | 0b01001 -> STD_INT
50 * possible | 0b10001 -> ONMOV_INT
51 * states | 0b01000 -> OFF_INT
54 * STD_INT or ONMOV_INT |
58 * OFF_INT or OFF_POLL |
61 * Any state | 0b10000000 -> if the slidebar has updated data,
62 * produce one input event (last position),
63 * switch to respective POLL mode
64 * (like 0x0), if not in POLL mode yet.
66 * Get current state: read
68 * masked by 0x11 read value means:
76 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
78 #include <linux/module.h>
79 #include <linux/kernel.h>
80 #include <linux/dmi.h>
81 #include <linux/spinlock.h>
82 #include <linux/platform_device.h>
83 #include <linux/input.h>
85 #include <linux/ioport.h>
86 #include <linux/i8042.h>
87 #include <linux/serio.h>
89 #define IDEAPAD_BASE 0xff29
92 module_param(force
, bool, 0);
93 MODULE_PARM_DESC(force
, "Force driver load, ignore DMI data");
95 static DEFINE_SPINLOCK(io_lock
);
97 static struct input_dev
*slidebar_input_dev
;
98 static struct platform_device
*slidebar_platform_dev
;
100 static u8
slidebar_pos_get(void)
105 spin_lock_irqsave(&io_lock
, flags
);
109 spin_unlock_irqrestore(&io_lock
, flags
);
114 static u8
slidebar_mode_get(void)
119 spin_lock_irqsave(&io_lock
, flags
);
123 spin_unlock_irqrestore(&io_lock
, flags
);
128 static void slidebar_mode_set(u8 mode
)
132 spin_lock_irqsave(&io_lock
, flags
);
136 spin_unlock_irqrestore(&io_lock
, flags
);
139 static bool slidebar_i8042_filter(unsigned char data
, unsigned char str
,
142 static bool extended
= false;
144 /* We are only interested in data coming form KBC port */
145 if (str
& I8042_STR_AUXDATA
)
148 /* Scancodes: e03b on move, e0bb on release. */
159 if (likely((data
& 0x7f) != 0x3b)) {
160 serio_interrupt(port
, 0xe0, 0);
165 input_report_key(slidebar_input_dev
, BTN_TOUCH
, 0);
167 input_report_key(slidebar_input_dev
, BTN_TOUCH
, 1);
168 input_report_abs(slidebar_input_dev
, ABS_X
, slidebar_pos_get());
170 input_sync(slidebar_input_dev
);
175 static ssize_t
show_slidebar_mode(struct device
*dev
,
176 struct device_attribute
*attr
,
179 return sprintf(buf
, "%x\n", slidebar_mode_get());
182 static ssize_t
store_slidebar_mode(struct device
*dev
,
183 struct device_attribute
*attr
,
184 const char *buf
, size_t count
)
189 error
= kstrtou8(buf
, 0, &mode
);
193 slidebar_mode_set(mode
);
198 static DEVICE_ATTR(slidebar_mode
, S_IWUSR
| S_IRUGO
,
199 show_slidebar_mode
, store_slidebar_mode
);
201 static struct attribute
*ideapad_attrs
[] = {
202 &dev_attr_slidebar_mode
.attr
,
206 static struct attribute_group ideapad_attr_group
= {
207 .attrs
= ideapad_attrs
210 static const struct attribute_group
*ideapad_attr_groups
[] = {
215 static int __init
ideapad_probe(struct platform_device
* pdev
)
219 if (!request_region(IDEAPAD_BASE
, 3, "ideapad_slidebar")) {
220 dev_err(&pdev
->dev
, "IO ports are busy\n");
224 slidebar_input_dev
= input_allocate_device();
225 if (!slidebar_input_dev
) {
226 dev_err(&pdev
->dev
, "Failed to allocate input device\n");
228 goto err_release_ports
;
231 slidebar_input_dev
->name
= "IdeaPad Slidebar";
232 slidebar_input_dev
->id
.bustype
= BUS_HOST
;
233 slidebar_input_dev
->dev
.parent
= &pdev
->dev
;
234 input_set_capability(slidebar_input_dev
, EV_KEY
, BTN_TOUCH
);
235 input_set_capability(slidebar_input_dev
, EV_ABS
, ABS_X
);
236 input_set_abs_params(slidebar_input_dev
, ABS_X
, 0, 0xff, 0, 0);
238 err
= i8042_install_filter(slidebar_i8042_filter
);
241 "Failed to install i8042 filter: %d\n", err
);
245 err
= input_register_device(slidebar_input_dev
);
248 "Failed to register input device: %d\n", err
);
249 goto err_remove_filter
;
255 i8042_remove_filter(slidebar_i8042_filter
);
257 input_free_device(slidebar_input_dev
);
259 release_region(IDEAPAD_BASE
, 3);
263 static int ideapad_remove(struct platform_device
*pdev
)
265 i8042_remove_filter(slidebar_i8042_filter
);
266 input_unregister_device(slidebar_input_dev
);
267 release_region(IDEAPAD_BASE
, 3);
272 static struct platform_driver slidebar_drv
= {
274 .name
= "ideapad_slidebar",
276 .remove
= ideapad_remove
,
279 static int __init
ideapad_dmi_check(const struct dmi_system_id
*id
)
281 pr_info("Laptop model '%s'\n", id
->ident
);
285 static const struct dmi_system_id ideapad_dmi
[] __initconst
= {
287 .ident
= "Lenovo IdeaPad Y550",
289 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
290 DMI_MATCH(DMI_PRODUCT_NAME
, "20017"),
291 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo IdeaPad Y550")
293 .callback
= ideapad_dmi_check
296 .ident
= "Lenovo IdeaPad Y550P",
298 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
299 DMI_MATCH(DMI_PRODUCT_NAME
, "20035"),
300 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo IdeaPad Y550P")
302 .callback
= ideapad_dmi_check
306 MODULE_DEVICE_TABLE(dmi
, ideapad_dmi
);
308 static int __init
slidebar_init(void)
312 if (!force
&& !dmi_check_system(ideapad_dmi
)) {
313 pr_err("DMI does not match\n");
317 slidebar_platform_dev
= platform_device_alloc("ideapad_slidebar", -1);
318 if (!slidebar_platform_dev
) {
319 pr_err("Not enough memory\n");
323 slidebar_platform_dev
->dev
.groups
= ideapad_attr_groups
;
325 err
= platform_device_add(slidebar_platform_dev
);
327 pr_err("Failed to register platform device\n");
331 err
= platform_driver_probe(&slidebar_drv
, ideapad_probe
);
333 pr_err("Failed to register platform driver\n");
340 platform_device_del(slidebar_platform_dev
);
342 platform_device_put(slidebar_platform_dev
);
346 static void __exit
slidebar_exit(void)
348 platform_device_unregister(slidebar_platform_dev
);
349 platform_driver_unregister(&slidebar_drv
);
352 module_init(slidebar_init
);
353 module_exit(slidebar_exit
);
355 MODULE_AUTHOR("Andrey Moiseev <o2g.org.ru@gmail.com>");
356 MODULE_DESCRIPTION("Slidebar input support for some Lenovo IdeaPad laptops");
357 MODULE_LICENSE("GPL");