From 1a9027770f3d93b78f7031af79597f9659db5d70 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 12 Dec 2016 14:33:37 -0800 Subject: [PATCH 01/91] Input: i8042 - force synchronous probing of PNP drivers We rely on the result of scanning PNP bus for keyboard and mouse devices to decide whether we should continue initialization of i8042 driver or not, so the probes can not be asynchronous. Also, it is not a good idea to unbind either of the PNP devices while i8042 is running, so let's disable bind/unbind for the PNP drivers through sysfs and rely on i8042 cleaning after itself properly. User can still unbind and rebind entire i8042 and that will take care of PNP drivers as well. Reviewed-by: Luis R. Rodriguez Signed-off-by: Dmitry Torokhov --- drivers/input/serio/i8042-x86ia64io.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h index 21e134798ba3..a4592ebf9a1d 100644 --- a/drivers/input/serio/i8042-x86ia64io.h +++ b/drivers/input/serio/i8042-x86ia64io.h @@ -910,6 +910,10 @@ static struct pnp_driver i8042_pnp_kbd_driver = { .name = "i8042 kbd", .id_table = pnp_kbd_devids, .probe = i8042_pnp_kbd_probe, + .driver = { + .probe_type = PROBE_FORCE_SYNCHRONOUS, + .suppress_bind_attrs = true, + }, }; static struct pnp_device_id pnp_aux_devids[] = { @@ -932,6 +936,10 @@ static struct pnp_driver i8042_pnp_aux_driver = { .name = "i8042 aux", .id_table = pnp_aux_devids, .probe = i8042_pnp_aux_probe, + .driver = { + .probe_type = PROBE_FORCE_SYNCHRONOUS, + .suppress_bind_attrs = true, + }, }; static void i8042_pnp_exit(void) From f63bb4f442d6c7929e58d671d1f46e122c441884 Mon Sep 17 00:00:00 2001 From: Aniroop Mathur Date: Tue, 27 Dec 2016 13:22:42 -0800 Subject: [PATCH 02/91] Input: bma150 - switch to using usleep_range instead of msleep msleep (1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, etc. Thus, change msleep to usleep_range for precise wakeups. Signed-off-by: Aniroop Mathur Acked by: Albert Zhang Signed-off-by: Dmitry Torokhov --- drivers/input/misc/bma150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c index 2124390ec38c..1fa85379f86c 100644 --- a/drivers/input/misc/bma150.c +++ b/drivers/input/misc/bma150.c @@ -207,7 +207,7 @@ static int bma150_set_mode(struct bma150_data *bma150, u8 mode) return error; if (mode == BMA150_MODE_NORMAL) - msleep(2); + usleep_range(2000, 2100); bma150->mode = mode; return 0; @@ -222,7 +222,7 @@ static int bma150_soft_reset(struct bma150_data *bma150) if (error) return error; - msleep(2); + usleep_range(2000, 2100); return 0; } From b29c139a15b627cd3db803332c89f0ea1b94fc7b Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 27 Dec 2016 11:42:28 -0800 Subject: [PATCH 03/91] Input: synaptics-rmi4 - use Kconfig "if" to express dependency There is no need to repeat "depends on RMI4_CORE" on every bit of RMI4 support, we can guard all of them at once with "if RMI4_CORE". Also use tabs for F03 indentation. Reviewed-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/Kconfig | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig index 8993983e3fe4..78a78b99ec31 100644 --- a/drivers/input/rmi4/Kconfig +++ b/drivers/input/rmi4/Kconfig @@ -9,9 +9,11 @@ config RMI4_CORE If unsure, say Y. +if RMI4_CORE + config RMI4_I2C tristate "RMI4 I2C Support" - depends on RMI4_CORE && I2C + depends on I2C help Say Y here if you want to support RMI4 devices connected to an I2C bus. @@ -20,7 +22,7 @@ config RMI4_I2C config RMI4_SPI tristate "RMI4 SPI Support" - depends on RMI4_CORE && SPI + depends on SPI help Say Y here if you want to support RMI4 devices connected to a SPI bus. @@ -29,7 +31,7 @@ config RMI4_SPI config RMI4_SMB tristate "RMI4 SMB Support" - depends on RMI4_CORE && I2C + depends on I2C help Say Y here if you want to support RMI4 devices connected to an SMB bus. @@ -40,23 +42,20 @@ config RMI4_SMB called rmi_smbus. config RMI4_F03 - bool "RMI4 Function 03 (PS2 Guest)" - depends on RMI4_CORE + bool "RMI4 Function 03 (PS2 Guest)" depends on SERIO=y || RMI4_CORE=SERIO - help - Say Y here if you want to add support for RMI4 function 03. + help + Say Y here if you want to add support for RMI4 function 03. - Function 03 provides PS2 guest support for RMI4 devices. This - includes support for TrackPoints on TouchPads. + Function 03 provides PS2 guest support for RMI4 devices. This + includes support for TrackPoints on TouchPads. config RMI4_2D_SENSOR bool - depends on RMI4_CORE config RMI4_F11 bool "RMI4 Function 11 (2D pointing)" select RMI4_2D_SENSOR - depends on RMI4_CORE help Say Y here if you want to add support for RMI4 function 11. @@ -67,7 +66,6 @@ config RMI4_F11 config RMI4_F12 bool "RMI4 Function 12 (2D pointing)" select RMI4_2D_SENSOR - depends on RMI4_CORE help Say Y here if you want to add support for RMI4 function 12. @@ -77,7 +75,6 @@ config RMI4_F12 config RMI4_F30 bool "RMI4 Function 30 (GPIO LED)" - depends on RMI4_CORE help Say Y here if you want to add support for RMI4 function 30. @@ -86,7 +83,6 @@ config RMI4_F30 config RMI4_F34 bool "RMI4 Function 34 (Device reflash)" - depends on RMI4_CORE select FW_LOADER help Say Y here if you want to add support for RMI4 function 34. @@ -97,7 +93,6 @@ config RMI4_F34 config RMI4_F54 bool "RMI4 Function 54 (Analog diagnostics)" - depends on RMI4_CORE depends on VIDEO_V4L2=y || (RMI4_CORE=m && VIDEO_V4L2=m) select VIDEOBUF2_VMALLOC select RMI4_F55 @@ -109,9 +104,10 @@ config RMI4_F54 config RMI4_F55 bool "RMI4 Function 55 (Sensor tuning)" - depends on RMI4_CORE help Say Y here if you want to add support for RMI4 function 55 Function 55 provides access to the RMI4 touch sensor tuning mechanism. + +endif # RMI_CORE From 0c54fe74db73499637315d6b3d83a7adbc6f32aa Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 20 Dec 2016 13:23:30 -0800 Subject: [PATCH 04/91] Input: synaptics-rmi4 - check for non zero version logically dead code version is a u8, the check for version > 0 means that version can only be zero, so the subsequent check for version != 0 is never true and hence is redudant code and can be removed. Signed-off-by: Colin Ian King Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f34.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c index 9774dfbab9bb..c3285cefe9b6 100644 --- a/drivers/input/rmi4/rmi_f34.c +++ b/drivers/input/rmi4/rmi_f34.c @@ -441,8 +441,6 @@ static int rmi_f34_probe(struct rmi_function *fn) /* v5 code only supported version 0, try V7 probe */ if (version > 0) return rmi_f34v7_probe(f34); - else if (version != 0) - return -ENODEV; f34->bl_version = 5; From 3a11c0e1f1394e9d871dd8e68f9ce01d7c96e28d Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Thu, 29 Dec 2016 10:13:43 -0800 Subject: [PATCH 05/91] Input: synaptics-rmi4 - remove redundant null check on rmi_dev rmi_dev is currently being dereferenced before it null checked, however, after deeper inspecting, rmi_dev can never be null, so just remove this redundant check. Fixes CoverityScan CID 1391218 ("Dereference before null check") Signed-off-by: Colin Ian King Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f03.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/input/rmi4/rmi_f03.c b/drivers/input/rmi4/rmi_f03.c index 8a7ca3e2f95e..9a1b099b72e0 100644 --- a/drivers/input/rmi4/rmi_f03.c +++ b/drivers/input/rmi4/rmi_f03.c @@ -175,9 +175,6 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits) int i; int error; - if (!rmi_dev) - return -ENODEV; - if (drvdata->attn_data.data) { /* First grab the data passed by the transport device */ if (drvdata->attn_data.size < ob_len) { From c02fc1d9e5d9f093296e43e13ec7f35f140784bd Mon Sep 17 00:00:00 2001 From: Daniel Tobias Date: Fri, 27 May 2016 16:25:10 -0700 Subject: [PATCH 06/91] Input: xpad - correctly sort vendor id's Signed-off-by: Daniel Tobias Signed-off-by: Pavel Rojtberg Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 6d9499658671..1795f96f1b58 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -320,18 +320,18 @@ static struct usb_device_id xpad_table[] = { XPAD_XBOXONE_VENDOR(0x0738), /* Mad Catz FightStick TE 2 */ XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */ XPAD_XBOXONE_VENDOR(0x0e6f), /* 0x0e6f X-Box One controllers */ + XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */ + XPAD_XBOXONE_VENDOR(0x0f0d), /* Hori Controllers */ XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */ XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */ XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */ - XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */ - XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */ - XPAD_XBOXONE_VENDOR(0x0f0d), /* Hori Controllers */ - XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */ - XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */ - XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA Controllers */ XPAD_XBOX360_VENDOR(0x1532), /* Razer Sabertooth */ XPAD_XBOX360_VENDOR(0x15e4), /* Numark X-Box 360 controllers */ XPAD_XBOX360_VENDOR(0x162e), /* Joytech X-Box 360 controllers */ + XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */ + XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */ + XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */ + XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA Controllers */ { } }; From 4f88476c75429ba9ab71c428b4cd2f67575bc9c1 Mon Sep 17 00:00:00 2001 From: Daniel Tobias Date: Fri, 27 May 2016 16:25:32 -0700 Subject: [PATCH 07/91] Input: xpad - move reporting xbox one home button to common function xbox one was the only device that has a *_process_buttons routine. Signed-off-by: Pavel Rojtberg Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 52 +++++++++++++---------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 1795f96f1b58..9ddd8511c138 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -608,14 +608,28 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha } /* - * xpadone_process_buttons + * xpadone_process_packet * - * Process a button update packet from an Xbox one controller. + * Completes a request by converting the data into events for the + * input subsystem. This version is for the Xbox One controller. + * + * The report format was gleaned from + * https://github.com/kylelemons/xbox/blob/master/xbox.go */ -static void xpadone_process_buttons(struct usb_xpad *xpad, - struct input_dev *dev, - unsigned char *data) +static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) { + struct input_dev *dev = xpad->dev; + + /* the xbox button has its own special report */ + if (data[0] == 0X07) { + input_report_key(dev, BTN_MODE, data[4] & 0x01); + input_sync(dev); + return; + } + /* check invalid packet */ + else if (data[0] != 0X20) + return; + /* menu/view buttons */ input_report_key(dev, BTN_START, data[4] & 0x04); input_report_key(dev, BTN_SELECT, data[4] & 0x08); @@ -678,34 +692,6 @@ static void xpadone_process_buttons(struct usb_xpad *xpad, input_sync(dev); } -/* - * xpadone_process_packet - * - * Completes a request by converting the data into events for the - * input subsystem. This version is for the Xbox One controller. - * - * The report format was gleaned from - * https://github.com/kylelemons/xbox/blob/master/xbox.go - */ - -static void xpadone_process_packet(struct usb_xpad *xpad, - u16 cmd, unsigned char *data) -{ - struct input_dev *dev = xpad->dev; - - switch (data[0]) { - case 0x20: - xpadone_process_buttons(xpad, dev, data); - break; - - case 0x07: - /* the xbox button has its own special report */ - input_report_key(dev, BTN_MODE, data[4] & 0x01); - input_sync(dev); - break; - } -} - static void xpad_irq_in(struct urb *urb) { struct usb_xpad *xpad = urb->context; From a8c34e27fb1ece928ec728bfe596aa6ca0b1928a Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 27 May 2016 16:26:33 -0700 Subject: [PATCH 08/91] Input: xpad - simplify error condition in init_output Replace first goto with simple returns as we really are just returning one error code. Signed-off-by: Pavel Rojtberg Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 9ddd8511c138..3f6130e0f9c1 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -849,17 +849,15 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, GFP_KERNEL, &xpad->odata_dma); - if (!xpad->odata) { - error = -ENOMEM; - goto fail1; - } + if (!xpad->odata) + return -ENOMEM; spin_lock_init(&xpad->odata_lock); xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); if (!xpad->irq_out) { error = -ENOMEM; - goto fail2; + goto err_free_coherent; } /* Xbox One controller has in/out endpoints swapped. */ @@ -875,8 +873,9 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) return 0; - fail2: usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); - fail1: return error; +err_free_coherent: + usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); + return error; } static void xpad_stop_output(struct usb_xpad *xpad) From c01b5e7464f0cf20936d7467c7528163c4e2782d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 3 Jan 2017 22:40:38 -0800 Subject: [PATCH 09/91] Input: xpad - don't depend on endpoint order The order of endpoints is well defined on official Xbox pads, but we have found at least one 3rd-party pad that doesn't follow the standard ("Titanfall 2 Xbox One controller" 0e6f:0165). Fortunately, we get lucky with this specific pad because it uses endpoint addresses that differ only by direction. We know that there are other pads out where this is not true, so let's go ahead and fix this. Signed-off-by: Cameron Gutman Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 3f6130e0f9c1..c06b717139ad 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -836,10 +836,9 @@ static void xpad_irq_out(struct urb *urb) spin_unlock_irqrestore(&xpad->odata_lock, flags); } -static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) +static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, + struct usb_endpoint_descriptor *ep_irq_out) { - struct usb_endpoint_descriptor *ep_irq_out; - int ep_irq_out_idx; int error; if (xpad->xtype == XTYPE_UNKNOWN) @@ -860,10 +859,6 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) goto err_free_coherent; } - /* Xbox One controller has in/out endpoints swapped. */ - ep_irq_out_idx = xpad->xtype == XTYPE_XBOXONE ? 0 : 1; - ep_irq_out = &intf->cur_altsetting->endpoint[ep_irq_out_idx].desc; - usb_fill_int_urb(xpad->irq_out, xpad->udev, usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), xpad->odata, XPAD_PKT_LEN, @@ -1447,8 +1442,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id { struct usb_device *udev = interface_to_usbdev(intf); struct usb_xpad *xpad; - struct usb_endpoint_descriptor *ep_irq_in; - int ep_irq_in_idx; + struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out; int i, error; if (intf->cur_altsetting->desc.bNumEndpoints != 2) @@ -1518,14 +1512,27 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id goto err_free_in_urb; } - error = xpad_init_output(intf, xpad); + ep_irq_in = ep_irq_out = NULL; + + for (i = 0; i < 2; i++) { + struct usb_endpoint_descriptor *ep = + &intf->cur_altsetting->endpoint[i].desc; + + if (usb_endpoint_dir_in(ep)) + ep_irq_in = ep; + else + ep_irq_out = ep; + } + + if (!ep_irq_in || !ep_irq_out) { + error = -ENODEV; + goto err_free_in_urb; + } + + error = xpad_init_output(intf, xpad, ep_irq_out); if (error) goto err_free_in_urb; - /* Xbox One controller has in/out endpoints swapped. */ - ep_irq_in_idx = xpad->xtype == XTYPE_XBOXONE ? 1 : 0; - ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc; - usb_fill_int_urb(xpad->irq_in, udev, usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), xpad->idata, XPAD_PKT_LEN, xpad_irq_in, From 0eeecf60394928b48806b081d4bea1a18db9318c Mon Sep 17 00:00:00 2001 From: Aniroop Mathur Date: Wed, 4 Jan 2017 10:57:51 -0800 Subject: [PATCH 10/91] Input: edt_ft5x06 - change msleep to usleep_range for small msecs msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, retry logic, etc. Thus, change msleep to usleep_range for precise wakeups. Signed-off-by: Aniroop Mathur Acked-by: Simon Budig Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/edt-ft5x06.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c index 28466e358fee..8fc629fb023f 100644 --- a/drivers/input/touchscreen/edt-ft5x06.c +++ b/drivers/input/touchscreen/edt-ft5x06.c @@ -67,7 +67,7 @@ #define EDT_SWITCH_MODE_RETRIES 10 #define EDT_SWITCH_MODE_DELAY 5 /* msec */ #define EDT_RAW_DATA_RETRIES 100 -#define EDT_RAW_DATA_DELAY 1 /* msec */ +#define EDT_RAW_DATA_DELAY 1000 /* usec */ enum edt_ver { M06, @@ -664,7 +664,7 @@ static ssize_t edt_ft5x06_debugfs_raw_data_read(struct file *file, } do { - msleep(EDT_RAW_DATA_DELAY); + usleep_range(EDT_RAW_DATA_DELAY, EDT_RAW_DATA_DELAY + 100); val = edt_ft5x06_register_read(tsdata, 0x08); if (val < 1) break; From aa142ed77099e9a614980022b3f94efc67417775 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 5 Jan 2017 14:19:01 -0800 Subject: [PATCH 11/91] Input: intel-mid-touch - remove driver The Moorestown support was removed by commit 1a8359e411eb ("x86/mid: Remove Intel Moorestown"). Remove this leftover. Signed-off-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/Kconfig | 12 - drivers/input/touchscreen/Makefile | 1 - drivers/input/touchscreen/intel-mid-touch.c | 654 -------------------- 3 files changed, 667 deletions(-) delete mode 100644 drivers/input/touchscreen/intel-mid-touch.c diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index efca0133e266..8650c94e29d0 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -546,18 +546,6 @@ config TOUCHSCREEN_INEXIO To compile this driver as a module, choose M here: the module will be called inexio. -config TOUCHSCREEN_INTEL_MID - tristate "Intel MID platform resistive touchscreen" - depends on INTEL_SCU_IPC - help - Say Y here if you have a Intel MID based touchscreen in - your system. - - If unsure, say N. - - To compile this driver as a module, choose M here: the - module will be called intel_mid_touch. - config TOUCHSCREEN_MK712 tristate "ICS MicroClock MK712 touchscreen" help diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 81b86451782d..e41e3c7aa427 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -42,7 +42,6 @@ obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o obj-$(CONFIG_TOUCHSCREEN_IMX6UL_TSC) += imx6ul_tsc.o obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o -obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o diff --git a/drivers/input/touchscreen/intel-mid-touch.c b/drivers/input/touchscreen/intel-mid-touch.c deleted file mode 100644 index b4f0725a1c3d..000000000000 --- a/drivers/input/touchscreen/intel-mid-touch.c +++ /dev/null @@ -1,654 +0,0 @@ -/* - * Intel MID Resistive Touch Screen Driver - * - * Copyright (C) 2008 Intel Corp - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - * Questions/Comments/Bug fixes to Sreedhara (sreedhara.ds@intel.com) - * Ramesh Agarwal (ramesh.agarwal@intel.com) - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * TODO: - * review conversion of r/m/w sequences - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* PMIC Interrupt registers */ -#define PMIC_REG_ID1 0x00 /* PMIC ID1 register */ - -/* PMIC Interrupt registers */ -#define PMIC_REG_INT 0x04 /* PMIC interrupt register */ -#define PMIC_REG_MINT 0x05 /* PMIC interrupt mask register */ - -/* ADC Interrupt registers */ -#define PMIC_REG_ADCINT 0x5F /* ADC interrupt register */ -#define PMIC_REG_MADCINT 0x60 /* ADC interrupt mask register */ - -/* ADC Control registers */ -#define PMIC_REG_ADCCNTL1 0x61 /* ADC control register */ - -/* ADC Channel Selection registers */ -#define PMICADDR0 0xA4 -#define END_OF_CHANNEL 0x1F - -/* ADC Result register */ -#define PMIC_REG_ADCSNS0H 0x64 - -/* ADC channels for touch screen */ -#define MRST_TS_CHAN10 0xA /* Touch screen X+ connection */ -#define MRST_TS_CHAN11 0xB /* Touch screen X- connection */ -#define MRST_TS_CHAN12 0xC /* Touch screen Y+ connection */ -#define MRST_TS_CHAN13 0xD /* Touch screen Y- connection */ - -/* Touch screen channel BIAS constants */ -#define MRST_XBIAS 0x20 -#define MRST_YBIAS 0x40 -#define MRST_ZBIAS 0x80 - -/* Touch screen coordinates */ -#define MRST_X_MIN 10 -#define MRST_X_MAX 1024 -#define MRST_X_FUZZ 5 -#define MRST_Y_MIN 10 -#define MRST_Y_MAX 1024 -#define MRST_Y_FUZZ 5 -#define MRST_PRESSURE_MIN 0 -#define MRST_PRESSURE_NOMINAL 50 -#define MRST_PRESSURE_MAX 100 - -#define WAIT_ADC_COMPLETION 10 /* msec */ - -/* PMIC ADC round robin delays */ -#define ADC_LOOP_DELAY0 0x0 /* Continuous loop */ -#define ADC_LOOP_DELAY1 0x1 /* 4.5 ms approximate */ - -/* PMIC Vendor Identifiers */ -#define PMIC_VENDOR_FS 0 /* PMIC vendor FreeScale */ -#define PMIC_VENDOR_MAXIM 1 /* PMIC vendor MAXIM */ -#define PMIC_VENDOR_NEC 2 /* PMIC vendor NEC */ -#define MRSTOUCH_MAX_CHANNELS 32 /* Maximum ADC channels */ - -/* Touch screen device structure */ -struct mrstouch_dev { - struct device *dev; /* device associated with touch screen */ - struct input_dev *input; - char phys[32]; - u16 asr; /* Address selection register */ - int irq; - unsigned int vendor; /* PMIC vendor */ - unsigned int rev; /* PMIC revision */ - - int (*read_prepare)(struct mrstouch_dev *tsdev); - int (*read)(struct mrstouch_dev *tsdev, u16 *x, u16 *y, u16 *z); - int (*read_finish)(struct mrstouch_dev *tsdev); -}; - - -/*************************** NEC and Maxim Interface ************************/ - -static int mrstouch_nec_adc_read_prepare(struct mrstouch_dev *tsdev) -{ - return intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0, 0x20); -} - -/* - * Enables PENDET interrupt. - */ -static int mrstouch_nec_adc_read_finish(struct mrstouch_dev *tsdev) -{ - int err; - - err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x20, 0x20); - if (!err) - err = intel_scu_ipc_update_register(PMIC_REG_ADCCNTL1, 0, 0x05); - - return err; -} - -/* - * Reads PMIC ADC touch screen result - * Reads ADC storage registers for higher 7 and lower 3 bits and - * converts the two readings into a single value and turns off gain bit - */ -static int mrstouch_ts_chan_read(u16 offset, u16 chan, u16 *vp, u16 *vm) -{ - int err; - u16 result; - u32 res; - - result = PMIC_REG_ADCSNS0H + offset; - - if (chan == MRST_TS_CHAN12) - result += 4; - - err = intel_scu_ipc_ioread32(result, &res); - if (err) - return err; - - /* Mash the bits up */ - - *vp = (res & 0xFF) << 3; /* Highest 7 bits */ - *vp |= (res >> 8) & 0x07; /* Lower 3 bits */ - *vp &= 0x3FF; - - res >>= 16; - - *vm = (res & 0xFF) << 3; /* Highest 7 bits */ - *vm |= (res >> 8) & 0x07; /* Lower 3 bits */ - *vm &= 0x3FF; - - return 0; -} - -/* - * Enables X, Y and Z bias values - * Enables YPYM for X channels and XPXM for Y channels - */ -static int mrstouch_ts_bias_set(uint offset, uint bias) -{ - int count; - u16 chan, start; - u16 reg[4]; - u8 data[4]; - - chan = PMICADDR0 + offset; - start = MRST_TS_CHAN10; - - for (count = 0; count <= 3; count++) { - reg[count] = chan++; - data[count] = bias | (start + count); - } - - return intel_scu_ipc_writev(reg, data, 4); -} - -/* To read touch screen channel values */ -static int mrstouch_nec_adc_read(struct mrstouch_dev *tsdev, - u16 *x, u16 *y, u16 *z) -{ - int err; - u16 xm, ym, zm; - - /* configure Y bias for X channels */ - err = mrstouch_ts_bias_set(tsdev->asr, MRST_YBIAS); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - /* read x+ and x- channels */ - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, x, &xm); - if (err) - goto ipc_error; - - /* configure x bias for y channels */ - err = mrstouch_ts_bias_set(tsdev->asr, MRST_XBIAS); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - /* read y+ and y- channels */ - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN12, y, &ym); - if (err) - goto ipc_error; - - /* configure z bias for x and y channels */ - err = mrstouch_ts_bias_set(tsdev->asr, MRST_ZBIAS); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - /* read z+ and z- channels */ - err = mrstouch_ts_chan_read(tsdev->asr, MRST_TS_CHAN10, z, &zm); - if (err) - goto ipc_error; - - return 0; - -ipc_error: - dev_err(tsdev->dev, "ipc error during adc read\n"); - return err; -} - - -/*************************** Freescale Interface ************************/ - -static int mrstouch_fs_adc_read_prepare(struct mrstouch_dev *tsdev) -{ - int err, count; - u16 chan; - u16 reg[5]; - u8 data[5]; - - /* Stop the ADC */ - err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x00, 0x02); - if (err) - goto ipc_error; - - chan = PMICADDR0 + tsdev->asr; - - /* Set X BIAS */ - for (count = 0; count <= 3; count++) { - reg[count] = chan++; - data[count] = 0x2A; - } - reg[count] = chan++; /* Dummy */ - data[count] = 0; - - err = intel_scu_ipc_writev(reg, data, 5); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - /* Set Y BIAS */ - for (count = 0; count <= 3; count++) { - reg[count] = chan++; - data[count] = 0x4A; - } - reg[count] = chan++; /* Dummy */ - data[count] = 0; - - err = intel_scu_ipc_writev(reg, data, 5); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - /* Set Z BIAS */ - err = intel_scu_ipc_iowrite32(chan + 2, 0x8A8A8A8A); - if (err) - goto ipc_error; - - msleep(WAIT_ADC_COMPLETION); - - return 0; - -ipc_error: - dev_err(tsdev->dev, "ipc error during %s\n", __func__); - return err; -} - -static int mrstouch_fs_adc_read(struct mrstouch_dev *tsdev, - u16 *x, u16 *y, u16 *z) -{ - int err; - u16 result; - u16 reg[4]; - u8 data[4]; - - result = PMIC_REG_ADCSNS0H + tsdev->asr; - - reg[0] = result + 4; - reg[1] = result + 5; - reg[2] = result + 16; - reg[3] = result + 17; - - err = intel_scu_ipc_readv(reg, data, 4); - if (err) - goto ipc_error; - - *x = data[0] << 3; /* Higher 7 bits */ - *x |= data[1] & 0x7; /* Lower 3 bits */ - *x &= 0x3FF; - - *y = data[2] << 3; /* Higher 7 bits */ - *y |= data[3] & 0x7; /* Lower 3 bits */ - *y &= 0x3FF; - - /* Read Z value */ - reg[0] = result + 28; - reg[1] = result + 29; - - err = intel_scu_ipc_readv(reg, data, 4); - if (err) - goto ipc_error; - - *z = data[0] << 3; /* Higher 7 bits */ - *z |= data[1] & 0x7; /* Lower 3 bits */ - *z &= 0x3FF; - - return 0; - -ipc_error: - dev_err(tsdev->dev, "ipc error during %s\n", __func__); - return err; -} - -static int mrstouch_fs_adc_read_finish(struct mrstouch_dev *tsdev) -{ - int err, count; - u16 chan; - u16 reg[5]; - u8 data[5]; - - /* Clear all TS channels */ - chan = PMICADDR0 + tsdev->asr; - for (count = 0; count <= 4; count++) { - reg[count] = chan++; - data[count] = 0; - } - err = intel_scu_ipc_writev(reg, data, 5); - if (err) - goto ipc_error; - - for (count = 0; count <= 4; count++) { - reg[count] = chan++; - data[count] = 0; - } - err = intel_scu_ipc_writev(reg, data, 5); - if (err) - goto ipc_error; - - err = intel_scu_ipc_iowrite32(chan + 2, 0x00000000); - if (err) - goto ipc_error; - - /* Start ADC */ - err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, 0x02, 0x02); - if (err) - goto ipc_error; - - return 0; - -ipc_error: - dev_err(tsdev->dev, "ipc error during %s\n", __func__); - return err; -} - -static void mrstouch_report_event(struct input_dev *input, - unsigned int x, unsigned int y, unsigned int z) -{ - if (z > MRST_PRESSURE_NOMINAL) { - /* Pen touched, report button touch and coordinates */ - input_report_key(input, BTN_TOUCH, 1); - input_report_abs(input, ABS_X, x); - input_report_abs(input, ABS_Y, y); - } else { - input_report_key(input, BTN_TOUCH, 0); - } - - input_report_abs(input, ABS_PRESSURE, z); - input_sync(input); -} - -/* PENDET interrupt handler */ -static irqreturn_t mrstouch_pendet_irq(int irq, void *dev_id) -{ - struct mrstouch_dev *tsdev = dev_id; - u16 x, y, z; - - /* - * Should we lower thread priority? Probably not, since we are - * not spinning but sleeping... - */ - - if (tsdev->read_prepare(tsdev)) - goto out; - - do { - if (tsdev->read(tsdev, &x, &y, &z)) - break; - - mrstouch_report_event(tsdev->input, x, y, z); - } while (z > MRST_PRESSURE_NOMINAL); - - tsdev->read_finish(tsdev); - -out: - return IRQ_HANDLED; -} - -/* Utility to read PMIC ID */ -static int mrstouch_read_pmic_id(uint *vendor, uint *rev) -{ - int err; - u8 r; - - err = intel_scu_ipc_ioread8(PMIC_REG_ID1, &r); - if (err) - return err; - - *vendor = r & 0x7; - *rev = (r >> 3) & 0x7; - - return 0; -} - -/* - * Parse ADC channels to find end of the channel configured by other ADC user - * NEC and MAXIM requires 4 channels and FreeScale needs 18 channels - */ -static int mrstouch_chan_parse(struct mrstouch_dev *tsdev) -{ - int found = 0; - int err, i; - u8 r8; - - for (i = 0; i < MRSTOUCH_MAX_CHANNELS; i++) { - err = intel_scu_ipc_ioread8(PMICADDR0 + i, &r8); - if (err) - return err; - - if (r8 == END_OF_CHANNEL) { - found = i; - break; - } - } - - if (tsdev->vendor == PMIC_VENDOR_FS) { - if (found > MRSTOUCH_MAX_CHANNELS - 18) - return -ENOSPC; - } else { - if (found > MRSTOUCH_MAX_CHANNELS - 4) - return -ENOSPC; - } - - return found; -} - - -/* - * Writes touch screen channels to ADC address selection registers - */ -static int mrstouch_ts_chan_set(uint offset) -{ - u16 chan; - - int ret, count; - - chan = PMICADDR0 + offset; - for (count = 0; count <= 3; count++) { - ret = intel_scu_ipc_iowrite8(chan++, MRST_TS_CHAN10 + count); - if (ret) - return ret; - } - return intel_scu_ipc_iowrite8(chan++, END_OF_CHANNEL); -} - -/* Initialize ADC */ -static int mrstouch_adc_init(struct mrstouch_dev *tsdev) -{ - int err, start; - u8 ra, rm; - - err = mrstouch_read_pmic_id(&tsdev->vendor, &tsdev->rev); - if (err) { - dev_err(tsdev->dev, "Unable to read PMIC id\n"); - return err; - } - - switch (tsdev->vendor) { - case PMIC_VENDOR_NEC: - case PMIC_VENDOR_MAXIM: - tsdev->read_prepare = mrstouch_nec_adc_read_prepare; - tsdev->read = mrstouch_nec_adc_read; - tsdev->read_finish = mrstouch_nec_adc_read_finish; - break; - - case PMIC_VENDOR_FS: - tsdev->read_prepare = mrstouch_fs_adc_read_prepare; - tsdev->read = mrstouch_fs_adc_read; - tsdev->read_finish = mrstouch_fs_adc_read_finish; - break; - - default: - dev_err(tsdev->dev, - "Unsupported touchscreen: %d\n", tsdev->vendor); - return -ENXIO; - } - - start = mrstouch_chan_parse(tsdev); - if (start < 0) { - dev_err(tsdev->dev, "Unable to parse channels\n"); - return start; - } - - tsdev->asr = start; - - /* - * ADC power on, start, enable PENDET and set loop delay - * ADC loop delay is set to 4.5 ms approximately - * Loop delay more than this results in jitter in adc readings - * Setting loop delay to 0 (continuous loop) in MAXIM stops PENDET - * interrupt generation sometimes. - */ - - if (tsdev->vendor == PMIC_VENDOR_FS) { - ra = 0xE0 | ADC_LOOP_DELAY0; - rm = 0x5; - } else { - /* NEC and MAXIm not consistent with loop delay 0 */ - ra = 0xE0 | ADC_LOOP_DELAY1; - rm = 0x0; - - /* configure touch screen channels */ - err = mrstouch_ts_chan_set(tsdev->asr); - if (err) - return err; - } - - err = intel_scu_ipc_update_register(PMIC_REG_ADCCNTL1, ra, 0xE7); - if (err) - return err; - - err = intel_scu_ipc_update_register(PMIC_REG_MADCINT, rm, 0x03); - if (err) - return err; - - return 0; -} - - -/* Probe function for touch screen driver */ -static int mrstouch_probe(struct platform_device *pdev) -{ - struct mrstouch_dev *tsdev; - struct input_dev *input; - int err; - int irq; - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - dev_err(&pdev->dev, "no interrupt assigned\n"); - return -EINVAL; - } - - tsdev = devm_kzalloc(&pdev->dev, sizeof(struct mrstouch_dev), - GFP_KERNEL); - if (!tsdev) { - dev_err(&pdev->dev, "unable to allocate memory\n"); - return -ENOMEM; - } - - input = devm_input_allocate_device(&pdev->dev); - if (!input) { - dev_err(&pdev->dev, "unable to allocate input device\n"); - return -ENOMEM; - } - - tsdev->dev = &pdev->dev; - tsdev->input = input; - tsdev->irq = irq; - - snprintf(tsdev->phys, sizeof(tsdev->phys), - "%s/input0", dev_name(tsdev->dev)); - - err = mrstouch_adc_init(tsdev); - if (err) { - dev_err(&pdev->dev, "ADC initialization failed\n"); - return err; - } - - input->name = "mrst_touchscreen"; - input->phys = tsdev->phys; - input->dev.parent = tsdev->dev; - - input->id.vendor = tsdev->vendor; - input->id.version = tsdev->rev; - - input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); - input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); - - input_set_abs_params(tsdev->input, ABS_X, - MRST_X_MIN, MRST_X_MAX, MRST_X_FUZZ, 0); - input_set_abs_params(tsdev->input, ABS_Y, - MRST_Y_MIN, MRST_Y_MAX, MRST_Y_FUZZ, 0); - input_set_abs_params(tsdev->input, ABS_PRESSURE, - MRST_PRESSURE_MIN, MRST_PRESSURE_MAX, 0, 0); - - err = devm_request_threaded_irq(&pdev->dev, tsdev->irq, NULL, - mrstouch_pendet_irq, IRQF_ONESHOT, - "mrstouch", tsdev); - if (err) { - dev_err(tsdev->dev, "unable to allocate irq\n"); - return err; - } - - err = input_register_device(tsdev->input); - if (err) { - dev_err(tsdev->dev, "unable to register input device\n"); - return err; - } - - return 0; -} - -static struct platform_driver mrstouch_driver = { - .driver = { - .name = "pmic_touch", - }, - .probe = mrstouch_probe, -}; -module_platform_driver(mrstouch_driver); - -MODULE_AUTHOR("Sreedhara Murthy. D.S, sreedhara.ds@intel.com"); -MODULE_DESCRIPTION("Intel Moorestown Resistive Touch Screen Driver"); -MODULE_LICENSE("GPL"); From 890fa16762c7b43677228014387a817380e6114d Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:43:15 -0800 Subject: [PATCH 12/91] Input: mpr121 - annotate PM methods as __maybe_unused Instead of using #ifdef, let's mark suspend and resume methods as __maybe_unused to provide better compile coverage. Suggested-by: Dmitry Torokhov Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/mpr121_touchkey.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 0fd612dd76ed..a3fd6e5ebfb5 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -266,8 +266,7 @@ static int mpr_touchkey_probe(struct i2c_client *client, return 0; } -#ifdef CONFIG_PM_SLEEP -static int mpr_suspend(struct device *dev) +static int __maybe_unused mpr_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); @@ -279,7 +278,7 @@ static int mpr_suspend(struct device *dev) return 0; } -static int mpr_resume(struct device *dev) +static int __maybe_unused mpr_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client); @@ -292,7 +291,6 @@ static int mpr_resume(struct device *dev) return 0; } -#endif static SIMPLE_DEV_PM_OPS(mpr121_touchkey_pm_ops, mpr_suspend, mpr_resume); From a4b1aeb72662c2a35740bdf2b7e2e19593dd5d48 Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:43:40 -0800 Subject: [PATCH 13/91] Input: mpr121 - remove unused field in struct mpr121_touchkey Remove unused key_val field in struct mpr121_touchkey. Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/mpr121_touchkey.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index a3fd6e5ebfb5..90be99d58c85 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -59,7 +59,6 @@ struct mpr121_touchkey { struct i2c_client *client; struct input_dev *input_dev; - unsigned int key_val; unsigned int statusbits; unsigned int keycount; u16 keycodes[MPR121_MAX_KEY_COUNT]; From 9723ddc8fe0d76ce41fe0dc16afb241ec7d0a29d Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:44:05 -0800 Subject: [PATCH 14/91] Input: mpr121 - set missing event capability This driver reports misc scan input events on the sensor's status register changes. But the event capability for them was not set in the device initialization, so these events were ignored. This change adds the missing event capability. Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/mpr121_touchkey.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 90be99d58c85..2558c602f099 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -230,6 +230,7 @@ static int mpr_touchkey_probe(struct i2c_client *client, input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_dev->keycode = mpr121->keycodes; input_dev->keycodesize = sizeof(mpr121->keycodes[0]); From 08fea55e37f58371bffc5336a59e55d1f155955a Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:44:30 -0800 Subject: [PATCH 15/91] Input: mpr121 - handle multiple bits change of status register This driver reports input events on their interrupts which are triggered by the sensor's status register changes. But only single bit change is reported in the interrupt handler. So if there are multiple bits are changed at almost the same time, other press or release events are ignored. This fixes it by detecting all changed bits in the status register. Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/mpr121_touchkey.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 2558c602f099..83dd5616e470 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -86,7 +86,8 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id) struct mpr121_touchkey *mpr121 = dev_id; struct i2c_client *client = mpr121->client; struct input_dev *input = mpr121->input_dev; - unsigned int key_num, key_val, pressed; + unsigned long bit_changed; + unsigned int key_num; int reg; reg = i2c_smbus_read_byte_data(client, ELE_TOUCH_STATUS_1_ADDR); @@ -104,19 +105,23 @@ static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id) reg &= TOUCH_STATUS_MASK; /* use old press bit to figure out which bit changed */ - key_num = ffs(reg ^ mpr121->statusbits) - 1; - pressed = reg & (1 << key_num); + bit_changed = reg ^ mpr121->statusbits; mpr121->statusbits = reg; + for_each_set_bit(key_num, &bit_changed, mpr121->keycount) { + unsigned int key_val, pressed; - key_val = mpr121->keycodes[key_num]; + pressed = reg & BIT(key_num); + key_val = mpr121->keycodes[key_num]; - input_event(input, EV_MSC, MSC_SCAN, key_num); - input_report_key(input, key_val, pressed); + input_event(input, EV_MSC, MSC_SCAN, key_num); + input_report_key(input, key_val, pressed); + + dev_dbg(&client->dev, "key %d %d %s\n", key_num, key_val, + pressed ? "pressed" : "released"); + + } input_sync(input); - dev_dbg(&client->dev, "key %d %d %s\n", key_num, key_val, - pressed ? "pressed" : "released"); - out: return IRQ_HANDLED; } From de901cc31d151c4c855346c29fb61eaf5ffac3ad Mon Sep 17 00:00:00 2001 From: Akinobu Mita Date: Sun, 15 Jan 2017 14:51:12 -0800 Subject: [PATCH 16/91] Input: mpr121 - switch to device tree probe This driver currently only supports legacy platform data probe. This change adds device tree support and gets rid of platform data probe code since no one is actually using mpr121 platform data in the mainline. The device tree property parsing code is based on the work of atmel_captouch driver. Signed-off-by: Akinobu Mita Signed-off-by: Dmitry Torokhov --- .../bindings/input/mpr121-touchkey.txt | 30 ++++ drivers/input/keyboard/mpr121_touchkey.c | 137 ++++++++++++------ include/linux/i2c/mpr121_touchkey.h | 20 --- 3 files changed, 124 insertions(+), 63 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/mpr121-touchkey.txt delete mode 100644 include/linux/i2c/mpr121_touchkey.h diff --git a/Documentation/devicetree/bindings/input/mpr121-touchkey.txt b/Documentation/devicetree/bindings/input/mpr121-touchkey.txt new file mode 100644 index 000000000000..b7c61ee5841b --- /dev/null +++ b/Documentation/devicetree/bindings/input/mpr121-touchkey.txt @@ -0,0 +1,30 @@ +* Freescale MPR121 Controllor + +Required Properties: +- compatible: Should be "fsl,mpr121-touchkey" +- reg: The I2C slave address of the device. +- interrupts: The interrupt number to the cpu. +- vdd-supply: Phandle to the Vdd power supply. +- linux,keycodes: Specifies an array of numeric keycode values to + be used for reporting button presses. The array can + contain up to 12 entries. + +Optional Properties: +- wakeup-source: Use any event on keypad as wakeup event. +- autorepeat: Enable autorepeat feature. + +Example: + +#include "dt-bindings/input/input.h" + + touchkey: mpr121@5a { + compatible = "fsl,mpr121-touchkey"; + reg = <0x5a>; + interrupt-parent = <&gpio1>; + interrupts = <28 2>; + autorepeat; + vdd-supply = <&ldo4_reg>; + linux,keycodes = , , , , + , , , + , , , ; + }; diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 83dd5616e470..989ca66f63af 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -12,14 +12,16 @@ * */ -#include -#include -#include -#include -#include #include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include /* Register definitions */ #define ELE_TOUCH_STATUS_0_ADDR 0x0 @@ -61,7 +63,7 @@ struct mpr121_touchkey { struct input_dev *input_dev; unsigned int statusbits; unsigned int keycount; - u16 keycodes[MPR121_MAX_KEY_COUNT]; + u32 keycodes[MPR121_MAX_KEY_COUNT]; }; struct mpr121_init_register { @@ -81,6 +83,42 @@ static const struct mpr121_init_register init_reg_table[] = { { AUTO_CONFIG_CTRL_ADDR, 0x0b }, }; +static void mpr121_vdd_supply_disable(void *data) +{ + struct regulator *vdd_supply = data; + + regulator_disable(vdd_supply); +} + +static struct regulator *mpr121_vdd_supply_init(struct device *dev) +{ + struct regulator *vdd_supply; + int err; + + vdd_supply = devm_regulator_get(dev, "vdd"); + if (IS_ERR(vdd_supply)) { + dev_err(dev, "failed to get vdd regulator: %ld\n", + PTR_ERR(vdd_supply)); + return vdd_supply; + } + + err = regulator_enable(vdd_supply); + if (err) { + dev_err(dev, "failed to enable vdd regulator: %d\n", err); + return ERR_PTR(err); + } + + err = devm_add_action(dev, mpr121_vdd_supply_disable, vdd_supply); + if (err) { + regulator_disable(vdd_supply); + dev_err(dev, "failed to add disable regulator action: %d\n", + err); + return ERR_PTR(err); + } + + return vdd_supply; +} + static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id) { struct mpr121_touchkey *mpr121 = dev_id; @@ -126,9 +164,8 @@ out: return IRQ_HANDLED; } -static int mpr121_phys_init(const struct mpr121_platform_data *pdata, - struct mpr121_touchkey *mpr121, - struct i2c_client *client) +static int mpr121_phys_init(struct mpr121_touchkey *mpr121, + struct i2c_client *client, int vdd_uv) { const struct mpr121_init_register *reg; unsigned char usl, lsl, tl, eleconf; @@ -158,9 +195,9 @@ static int mpr121_phys_init(const struct mpr121_platform_data *pdata, /* * Capacitance on sensing input varies and needs to be compensated. * The internal MPR121-auto-configuration can do this if it's - * registers are set properly (based on pdata->vdd_uv). + * registers are set properly (based on vdd_uv). */ - vdd = pdata->vdd_uv / 1000; + vdd = vdd_uv / 1000; usl = ((vdd - 700) * 256) / vdd; lsl = (usl * 65) / 100; tl = (usl * 90) / 100; @@ -191,35 +228,26 @@ err_i2c_write: static int mpr_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { - const struct mpr121_platform_data *pdata = - dev_get_platdata(&client->dev); + struct device *dev = &client->dev; + struct regulator *vdd_supply; + int vdd_uv; struct mpr121_touchkey *mpr121; struct input_dev *input_dev; int error; int i; - if (!pdata) { - dev_err(&client->dev, "no platform data defined\n"); - return -EINVAL; - } - - if (!pdata->keymap || !pdata->keymap_size) { - dev_err(&client->dev, "missing keymap data\n"); - return -EINVAL; - } - - if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) { - dev_err(&client->dev, "too many keys defined\n"); - return -EINVAL; - } - if (!client->irq) { dev_err(&client->dev, "irq number should not be zero\n"); return -EINVAL; } - mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121), - GFP_KERNEL); + vdd_supply = mpr121_vdd_supply_init(dev); + if (IS_ERR(vdd_supply)) + return PTR_ERR(vdd_supply); + + vdd_uv = regulator_get_voltage(vdd_supply); + + mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121), GFP_KERNEL); if (!mpr121) return -ENOMEM; @@ -229,33 +257,46 @@ static int mpr_touchkey_probe(struct i2c_client *client, mpr121->client = client; mpr121->input_dev = input_dev; - mpr121->keycount = pdata->keymap_size; + mpr121->keycount = device_property_read_u32_array(dev, "linux,keycodes", + NULL, 0); + if (mpr121->keycount > MPR121_MAX_KEY_COUNT) { + dev_err(dev, "too many keys defined (%d)\n", mpr121->keycount); + return -EINVAL; + } + + error = device_property_read_u32_array(dev, "linux,keycodes", + mpr121->keycodes, + mpr121->keycount); + if (error) { + dev_err(dev, + "failed to read linux,keycode property: %d\n", error); + return error; + } input_dev->name = "Freescale MPR121 Touchkey"; input_dev->id.bustype = BUS_I2C; input_dev->dev.parent = &client->dev; - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + if (device_property_read_bool(dev, "autorepeat")) + __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_dev->keycode = mpr121->keycodes; input_dev->keycodesize = sizeof(mpr121->keycodes[0]); input_dev->keycodemax = mpr121->keycount; - for (i = 0; i < pdata->keymap_size; i++) { - input_set_capability(input_dev, EV_KEY, pdata->keymap[i]); - mpr121->keycodes[i] = pdata->keymap[i]; - } + for (i = 0; i < mpr121->keycount; i++) + input_set_capability(input_dev, EV_KEY, mpr121->keycodes[i]); - error = mpr121_phys_init(pdata, mpr121, client); + error = mpr121_phys_init(mpr121, client, vdd_uv); if (error) { dev_err(&client->dev, "Failed to init register\n"); return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, NULL, - mpr_touchkey_interrupt, - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - client->dev.driver->name, mpr121); + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, mpr_touchkey_interrupt, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + client->dev.driver->name, mpr121); if (error) { dev_err(&client->dev, "Failed to register interrupt\n"); return error; @@ -266,7 +307,8 @@ static int mpr_touchkey_probe(struct i2c_client *client, return error; i2c_set_clientdata(client, mpr121); - device_init_wakeup(&client->dev, pdata->wakeup); + device_init_wakeup(dev, + device_property_read_bool(dev, "wakeup-source")); return 0; } @@ -305,10 +347,19 @@ static const struct i2c_device_id mpr121_id[] = { }; MODULE_DEVICE_TABLE(i2c, mpr121_id); +#ifdef CONFIG_OF +static const struct of_device_id mpr121_touchkey_dt_match_table[] = { + { .compatible = "fsl,mpr121-touchkey" }, + { }, +}; +MODULE_DEVICE_TABLE(of, mpr121_touchkey_dt_match_table); +#endif + static struct i2c_driver mpr_touchkey_driver = { .driver = { .name = "mpr121", .pm = &mpr121_touchkey_pm_ops, + .of_match_table = of_match_ptr(mpr121_touchkey_dt_match_table), }, .id_table = mpr121_id, .probe = mpr_touchkey_probe, diff --git a/include/linux/i2c/mpr121_touchkey.h b/include/linux/i2c/mpr121_touchkey.h deleted file mode 100644 index f0bcc38bbb97..000000000000 --- a/include/linux/i2c/mpr121_touchkey.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Header file for Freescale MPR121 Capacitive Touch Sensor */ - -#ifndef _MPR121_TOUCHKEY_H -#define _MPR121_TOUCHKEY_H - -/** - * struct mpr121_platform_data - platform data for mpr121 sensor - * @keymap: pointer to array of KEY_* values representing keymap - * @keymap_size: size of the keymap - * @wakeup: configure the button as a wake-up source - * @vdd_uv: VDD voltage in uV - */ -struct mpr121_platform_data { - const unsigned short *keymap; - unsigned int keymap_size; - bool wakeup; - int vdd_uv; -}; - -#endif /* _MPR121_TOUCHKEY_H */ From cd4c1b412d4dd094c2ec02be4f0ee41bcc386170 Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Sun, 15 Jan 2017 15:18:03 -0800 Subject: [PATCH 17/91] Input: cyapa - use time based retry loop Using counter based retry loops for peripherals results in the delay being significantly overrun during high-load situations where delay functions tend to be vary imprecise and overrun there timeouts. So condition the termination on the actual condition of 2s for the re-calibration to have been successful. As this is a very long delay there is no advantage in using high-resolution timers thus switching this to msleep(). Signed-off-by: Nicholas Mc Guire Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cyapa_gen3.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index f9600753eca5..a47b06f4ed51 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -789,7 +789,7 @@ static ssize_t cyapa_gen3_do_calibrate(struct device *dev, const char *buf, size_t count) { struct cyapa *cyapa = dev_get_drvdata(dev); - int tries; + unsigned long timeout; int ret; ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); @@ -812,31 +812,28 @@ static ssize_t cyapa_gen3_do_calibrate(struct device *dev, goto out; } - tries = 20; /* max recalibration timeout 2s. */ + /* max recalibration timeout 2s. */ + timeout = jiffies + 2 * HZ; do { /* * For this recalibration, the max time will not exceed 2s. * The average time is approximately 500 - 700 ms, and we * will check the status every 100 - 200ms. */ - usleep_range(100000, 200000); - + msleep(100); ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); if (ret < 0) { - dev_err(dev, "Error reading dev status: %d\n", - ret); + dev_err(dev, "Error reading dev status: %d\n", ret); goto out; } - if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL) - break; - } while (--tries); + if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL) { + dev_dbg(dev, "Calibration successful.\n"); + goto out; + } + } while (time_is_after_jiffies(timeout)); - if (tries == 0) { - dev_err(dev, "Failed to calibrate. Timeout.\n"); - ret = -ETIMEDOUT; - goto out; - } - dev_dbg(dev, "Calibration successful.\n"); + dev_err(dev, "Failed to calibrate. Timeout.\n"); + ret = -ETIMEDOUT; out: return ret < 0 ? ret : count; From 13e360ac97e2a6386f9e26e02e20bce4b6e83415 Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Sun, 15 Jan 2017 15:19:27 -0800 Subject: [PATCH 18/91] Input: cyapa - use msleep() for long delay ulseep_range() uses hrtimers and provides no advantage over msleep() for larger delays. Fix up the 50ms delays here to use msleep() and reduce the load on the hrtimer subsystem. Signed-off-by: Nicholas Mc Guire Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cyapa_gen3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index a47b06f4ed51..1cbfa4a6e830 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -562,7 +562,7 @@ static int cyapa_gen3_bl_exit(struct cyapa *cyapa) * Wait for bootloader to exit, and operation mode to start. * Normally, this takes at least 50 ms. */ - usleep_range(50000, 100000); + msleep(50); /* * In addition, when a device boots for the first time after being * updated to new firmware, it must first calibrate its sensors, which From 630a7fa0480bec63e0a300b8485642630340efcf Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Sun, 15 Jan 2017 15:23:05 -0800 Subject: [PATCH 19/91] Input: synaptics-rmi4 - correctly swap clip values if axes are swapped The clip values need the same swapping as the maximum values if the sensor axes are swapped. Signed-off-by: Lucas Stach Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_2d_sensor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/input/rmi4/rmi_2d_sensor.c b/drivers/input/rmi4/rmi_2d_sensor.c index 07007ff8e29f..8bb866c7b985 100644 --- a/drivers/input/rmi4/rmi_2d_sensor.c +++ b/drivers/input/rmi4/rmi_2d_sensor.c @@ -144,8 +144,13 @@ static void rmi_2d_sensor_set_input_params(struct rmi_2d_sensor *sensor) int input_flags = 0; if (sensor->report_abs) { - if (sensor->axis_align.swap_axes) + if (sensor->axis_align.swap_axes) { swap(sensor->max_x, sensor->max_y); + swap(sensor->axis_align.clip_x_low, + sensor->axis_align.clip_y_low); + swap(sensor->axis_align.clip_x_high, + sensor->axis_align.clip_y_high); + } sensor->min_x = sensor->axis_align.clip_x_low; if (sensor->axis_align.clip_x_high) From 259b77ef853cc375a5c9198cf81f9b79fc19413c Mon Sep 17 00:00:00 2001 From: Maxime Ripard Date: Tue, 17 Jan 2017 13:24:22 -0800 Subject: [PATCH 20/91] Input: tca8418 - use the interrupt trigger from the device tree The TCA8418 might be used using different interrupt triggers on various boards. This is not working so far because the current code forces a falling edge trigger. The device tree already provides a trigger type, so let's use whatever it sets up, and since we can be loaded without DT, keep the old behaviour for the non-DT case. Signed-off-by: Maxime Ripard Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca8418_keypad.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c index 3048ef3e3e16..11d5c76d9fb4 100644 --- a/drivers/input/keyboard/tca8418_keypad.c +++ b/drivers/input/keyboard/tca8418_keypad.c @@ -277,6 +277,7 @@ static int tca8418_keypad_probe(struct i2c_client *client, bool irq_is_gpio = false; int irq; int error, row_shift, max_keys; + unsigned long trigger = 0; /* Copy the platform data */ if (pdata) { @@ -289,6 +290,7 @@ static int tca8418_keypad_probe(struct i2c_client *client, cols = pdata->cols; rep = pdata->rep; irq_is_gpio = pdata->irq_is_gpio; + trigger = IRQF_TRIGGER_FALLING; } else { struct device_node *np = dev->of_node; int err; @@ -363,9 +365,7 @@ static int tca8418_keypad_probe(struct i2c_client *client, irq = gpio_to_irq(irq); error = devm_request_threaded_irq(dev, irq, NULL, tca8418_irq_handler, - IRQF_TRIGGER_FALLING | - IRQF_SHARED | - IRQF_ONESHOT, + trigger | IRQF_SHARED | IRQF_ONESHOT, client->name, keypad_data); if (error) { dev_err(dev, "Unable to claim irq %d; error %d\n", From 2057e15945a8b5d867c086371a5fb946fd8221da Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 10:37:49 -0800 Subject: [PATCH 21/91] Input: cros_ec_keyb - drop unnecessary call to dev_set_drvdata and other changes There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to dev_set_drvdata(). Other relevant changes: Use existing variable 'dev' instead of dereferencing it several times This conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches - Drop dev_set_drvdata() - Use local variable 'struct device *dev' consistently Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/cros_ec_keyb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index 4b0878f35471..165c722408aa 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -242,7 +242,7 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) struct device_node *np; int err; - np = pdev->dev.of_node; + np = dev->of_node; if (!np) return -ENODEV; @@ -272,7 +272,6 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) ckdev->ec = ec; ckdev->dev = dev; - dev_set_drvdata(dev, ckdev); idev->name = CROS_EC_DEV_NAME; idev->phys = ec->phys_name; From 009af5fdb4fb65e73c5783bf2de64490fcd84910 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:12:00 -0800 Subject: [PATCH 22/91] Input: at32psif - drop unnecessary error messages and other changes Error messages after memory allocation failures are unnecessary and can be dropped, given that they are emitted as dev_dbg() so nobody except person actively debugging the driver would see them. Also replace jump to return 'goto l; ... l: return e;' with 'return e;' Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/serio/at32psif.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/input/serio/at32psif.c b/drivers/input/serio/at32psif.c index 2e4ff5bac754..e420fd781d44 100644 --- a/drivers/input/serio/at32psif.c +++ b/drivers/input/serio/at32psif.c @@ -159,13 +159,12 @@ static int psif_open(struct serio *io) retval = clk_enable(psif->pclk); if (retval) - goto out; + return retval; psif_writel(psif, CR, PSIF_BIT(CR_TXEN) | PSIF_BIT(CR_RXEN)); psif_writel(psif, IER, PSIF_BIT(RXRDY)); psif->open = true; -out: return retval; } @@ -210,16 +209,12 @@ static int __init psif_probe(struct platform_device *pdev) int ret; psif = kzalloc(sizeof(struct psif), GFP_KERNEL); - if (!psif) { - dev_dbg(&pdev->dev, "out of memory\n"); - ret = -ENOMEM; - goto out; - } + if (!psif) + return -ENOMEM; psif->pdev = pdev; io = kzalloc(sizeof(struct serio), GFP_KERNEL); if (!io) { - dev_dbg(&pdev->dev, "out of memory\n"); ret = -ENOMEM; goto out_free_psif; } @@ -297,7 +292,6 @@ out_free_io: kfree(io); out_free_psif: kfree(psif); -out: return ret; } From 32237677fb6a15f08aadfe2bb4129b2de7e7caab Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:16:12 -0800 Subject: [PATCH 23/91] Input: xilinx_ps2 - use 'dev' instead of dereferencing it Use local variable 'dev' instead of dereferencing it several times. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/serio/xilinx_ps2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c index 5223cbf94262..14c40892ed82 100644 --- a/drivers/input/serio/xilinx_ps2.c +++ b/drivers/input/serio/xilinx_ps2.c @@ -243,18 +243,17 @@ static int xps2_of_probe(struct platform_device *ofdev) unsigned int irq; int error; - dev_info(dev, "Device Tree Probing \'%s\'\n", - ofdev->dev.of_node->name); + dev_info(dev, "Device Tree Probing \'%s\'\n", dev->of_node->name); /* Get iospace for the device */ - error = of_address_to_resource(ofdev->dev.of_node, 0, &r_mem); + error = of_address_to_resource(dev->of_node, 0, &r_mem); if (error) { dev_err(dev, "invalid address\n"); return error; } /* Get IRQ for the device */ - irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); + irq = irq_of_parse_and_map(dev->of_node, 0); if (!irq) { dev_err(dev, "no IRQ found\n"); return -ENODEV; From a8e90be161099a6e4d985a7e4a43f9acc8adfcae Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:20:18 -0800 Subject: [PATCH 24/91] Input: ar1021_i2c - drop unnecessary call to i2c_set_clientdata There is no call to i2c_get_clientdata() or dev_get_drvdata(). Drop the unnecessary call to i2c_set_clientdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/ar1021_i2c.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/touchscreen/ar1021_i2c.c b/drivers/input/touchscreen/ar1021_i2c.c index 71b5a634cf6d..6562b17117f7 100644 --- a/drivers/input/touchscreen/ar1021_i2c.c +++ b/drivers/input/touchscreen/ar1021_i2c.c @@ -127,7 +127,6 @@ static int ar1021_i2c_probe(struct i2c_client *client, return error; } - i2c_set_clientdata(client, ar1021); return 0; } From 5d20b927fa17d016e633857c756788516078b94e Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:21:24 -0800 Subject: [PATCH 25/91] Input: atmel-wm97xx - drop unnecessary error messages Error messages after memory allocation failures are unnecessary and can be dropped, especially give that they were emitted as dev_dbg() so noone except person actively debugging the driver would see them. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/atmel-wm97xx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/atmel-wm97xx.c b/drivers/input/touchscreen/atmel-wm97xx.c index 7ec0421c0dd8..8cf0b2be2df4 100644 --- a/drivers/input/touchscreen/atmel-wm97xx.c +++ b/drivers/input/touchscreen/atmel-wm97xx.c @@ -339,10 +339,8 @@ static int __init atmel_wm97xx_probe(struct platform_device *pdev) int ret; atmel_wm97xx = kzalloc(sizeof(struct atmel_wm97xx), GFP_KERNEL); - if (!atmel_wm97xx) { - dev_dbg(&pdev->dev, "out of memory\n"); + if (!atmel_wm97xx) return -ENOMEM; - } atmel_wm97xx->wm = wm; atmel_wm97xx->regs = (void *)ATMEL_WM97XX_AC97C_IOMEM; From ad03ae44baeb82b28024c8c582e18146b96d637e Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:24:06 -0800 Subject: [PATCH 26/91] Input: eeti_ts - drop goto to return statement Replace 'goto l; ... l: return e;' with 'return e;' Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/eeti_ts.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c index 09be6ced7151..fa974579eb41 100644 --- a/drivers/input/touchscreen/eeti_ts.c +++ b/drivers/input/touchscreen/eeti_ts.c @@ -173,12 +173,11 @@ static int eeti_ts_probe(struct i2c_client *client, priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { dev_err(&client->dev, "failed to allocate driver data\n"); - goto err0; + return -ENOMEM; } mutex_init(&priv->mutex); input = input_allocate_device(); - if (!input) { dev_err(&client->dev, "Failed to allocate input device.\n"); goto err1; @@ -243,7 +242,6 @@ err2: err1: input_free_device(input); kfree(priv); -err0: return err; } From 0265c324b8a2bbe502fee3007361d310de3b6d0c Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:36:25 -0800 Subject: [PATCH 27/91] Input: bfin_rotary - switch to using devm_add_action_or_reset() Use local variable 'dev' instead of dereferencing it several times and replace devm_add_action() and manual error handling with devm_add_action_or_reset(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/bfin_rotary.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/input/misc/bfin_rotary.c b/drivers/input/misc/bfin_rotary.c index a0fc18fdfc0c..799ce3d2820e 100644 --- a/drivers/input/misc/bfin_rotary.c +++ b/drivers/input/misc/bfin_rotary.c @@ -147,19 +147,18 @@ static int bfin_rotary_probe(struct platform_device *pdev) if (pdata->pin_list) { error = peripheral_request_list(pdata->pin_list, - dev_name(&pdev->dev)); + dev_name(dev)); if (error) { dev_err(dev, "requesting peripherals failed: %d\n", error); return error; } - error = devm_add_action(dev, bfin_rotary_free_action, - pdata->pin_list); + error = devm_add_action_or_reset(dev, bfin_rotary_free_action, + pdata->pin_list); if (error) { dev_err(dev, "setting cleanup action failed: %d\n", error); - peripheral_free_list(pdata->pin_list); return error; } } @@ -189,7 +188,7 @@ static int bfin_rotary_probe(struct platform_device *pdev) input->name = pdev->name; input->phys = "bfin-rotary/input0"; - input->dev.parent = &pdev->dev; + input->dev.parent = dev; input_set_drvdata(input, rotary); @@ -239,7 +238,7 @@ static int bfin_rotary_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, rotary); - device_init_wakeup(&pdev->dev, 1); + device_init_wakeup(dev, 1); return 0; } From a196b2c9f5f752e139f91d306fcb471e97723253 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:40:04 -0800 Subject: [PATCH 28/91] Input: gpio_decoder - drop unnecessary call to platform_set_drvdata There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to platform_set_drvdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/gpio_decoder.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c index ca7e0bacb2d8..1dca526e6f1a 100644 --- a/drivers/input/misc/gpio_decoder.c +++ b/drivers/input/misc/gpio_decoder.c @@ -110,7 +110,6 @@ static int gpio_decoder_probe(struct platform_device *pdev) dev_err(dev, "failed to register polled device\n"); return err; } - platform_set_drvdata(pdev, decoder); return 0; } From 9e85aa695659407bb7a2b2d5de47be8c335049c0 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:41:01 -0800 Subject: [PATCH 29/91] Input: mma8450 - drop unnecessary call to i2c_set_clientdata There is no call to i2c_get_clientdata() or dev_get_drvdata(). Drop the unnecessary call to i2c_set_clientdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/mma8450.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/input/misc/mma8450.c b/drivers/input/misc/mma8450.c index 19c73574458e..b60cdea73826 100644 --- a/drivers/input/misc/mma8450.c +++ b/drivers/input/misc/mma8450.c @@ -205,8 +205,6 @@ static int mma8450_probe(struct i2c_client *c, return err; } - i2c_set_clientdata(c, m); - return 0; } From aa45590ae8581e25b909f2fed591c3499cd8e352 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:41:51 -0800 Subject: [PATCH 30/91] Input: soc_button_array - use 'dev' instead of dereferencing it Use local variable 'dev' instead of dereferencing it several times. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/soc_button_array.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c index 908b51089dee..fb3219a8d3c0 100644 --- a/drivers/input/misc/soc_button_array.c +++ b/drivers/input/misc/soc_button_array.c @@ -167,12 +167,12 @@ static int soc_button_probe(struct platform_device *pdev) button_info = (struct soc_button_info *)id->driver_data; - if (gpiod_count(&pdev->dev, KBUILD_MODNAME) <= 0) { - dev_dbg(&pdev->dev, "no GPIO attached, ignoring...\n"); + if (gpiod_count(dev, KBUILD_MODNAME) <= 0) { + dev_dbg(dev, "no GPIO attached, ignoring...\n"); return -ENODEV; } - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; From 8ace98df9ade746de229dd75c144a25ec9fe2613 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:42:44 -0800 Subject: [PATCH 31/91] Input: tps65218-pwrbutton - drop unnecessary call to platform_set_drvdata There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to platform_set_drvdata(). Also use existing variable 'dev' instead of dereferencing it several times. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/tps65218-pwrbutton.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/input/misc/tps65218-pwrbutton.c b/drivers/input/misc/tps65218-pwrbutton.c index 3273217ce80c..65384754714d 100644 --- a/drivers/input/misc/tps65218-pwrbutton.c +++ b/drivers/input/misc/tps65218-pwrbutton.c @@ -95,7 +95,7 @@ static int tps6521x_pb_probe(struct platform_device *pdev) int error; int irq; - match = of_match_node(of_tps6521x_pb_match, pdev->dev.of_node); + match = of_match_node(of_tps6521x_pb_match, dev->of_node); if (!match) return -ENXIO; @@ -118,10 +118,9 @@ static int tps6521x_pb_probe(struct platform_device *pdev) input_set_capability(idev, EV_KEY, KEY_POWER); - pwr->regmap = dev_get_regmap(pdev->dev.parent, NULL); + pwr->regmap = dev_get_regmap(dev->parent, NULL); pwr->dev = dev; pwr->idev = idev; - platform_set_drvdata(pdev, pwr); device_init_wakeup(dev, true); irq = platform_get_irq(pdev, 0); @@ -136,8 +135,7 @@ static int tps6521x_pb_probe(struct platform_device *pdev) IRQF_ONESHOT, pwr->data->name, pwr); if (error) { - dev_err(dev, "failed to request IRQ #%d: %d\n", - irq, error); + dev_err(dev, "failed to request IRQ #%d: %d\n", irq, error); return error; } From b8f6a6ad777f14e3ec48d410a840621a45fce98a Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:44:55 -0800 Subject: [PATCH 32/91] Input: ab8500-ponkey - drop unnecessary call to platform_set_drvdata There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to platform_set_drvdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/ab8500-ponkey.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/misc/ab8500-ponkey.c b/drivers/input/misc/ab8500-ponkey.c index 4f5ef5bb535b..a33ed5710b15 100644 --- a/drivers/input/misc/ab8500-ponkey.c +++ b/drivers/input/misc/ab8500-ponkey.c @@ -109,7 +109,6 @@ static int ab8500_ponkey_probe(struct platform_device *pdev) return error; } - platform_set_drvdata(pdev, ponkey); return 0; } From e634d08dec48023394f816cdf17cc9f040b8d56f Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:45:25 -0800 Subject: [PATCH 33/91] Input: twl4030_keypad - drop unnecessary call to platform_set_drvdata There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to platform_set_drvdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/twl4030_keypad.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c index 323a0fb575a4..29396ca69416 100644 --- a/drivers/input/keyboard/twl4030_keypad.c +++ b/drivers/input/keyboard/twl4030_keypad.c @@ -441,7 +441,6 @@ static int twl4030_kp_probe(struct platform_device *pdev) return -EIO; } - platform_set_drvdata(pdev, kp); return 0; } From 8beb7172b428a63634684a8a2bf8754002756056 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 11:48:11 -0800 Subject: [PATCH 34/91] Input: bcm-keypad - drop unnecessary call to platform_set_drvdata There is no call to platform_get_drvdata() or dev_get_drvdata(). Drop the unnecessary call to platform_set_drvdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/bcm-keypad.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/input/keyboard/bcm-keypad.c b/drivers/input/keyboard/bcm-keypad.c index 86a8b723ae15..2b4e63d81e6d 100644 --- a/drivers/input/keyboard/bcm-keypad.c +++ b/drivers/input/keyboard/bcm-keypad.c @@ -352,8 +352,6 @@ static int bcm_kp_probe(struct platform_device *pdev) kp->input_dev = input_dev; - platform_set_drvdata(pdev, kp); - error = bcm_kp_matrix_key_parse_dt(kp); if (error) return error; From aa6f9222218273cc54ec8d3c91ad8207eef21f99 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Wed, 18 Jan 2017 14:26:47 -0800 Subject: [PATCH 35/91] Input: sis_i2c - drop unnecessary call to i2c_set_clientdata There is no call to i2c_get_clientdata() or dev_get_drvdata(). Drop the unnecessary call to i2c_set_clientdata(). Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/sis_i2c.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/touchscreen/sis_i2c.c b/drivers/input/touchscreen/sis_i2c.c index 8d93f8c9a403..67c2563031d6 100644 --- a/drivers/input/touchscreen/sis_i2c.c +++ b/drivers/input/touchscreen/sis_i2c.c @@ -316,7 +316,6 @@ static int sis_ts_probe(struct i2c_client *client, return -ENOMEM; ts->client = client; - i2c_set_clientdata(client, ts); ts->attn_gpio = devm_gpiod_get_optional(&client->dev, "attn", GPIOD_IN); From 72d1f2346ded5b1743d7938f4522550b4da9c82d Mon Sep 17 00:00:00 2001 From: Jaechul Lee Date: Wed, 18 Jan 2017 14:35:42 -0800 Subject: [PATCH 36/91] Input: tm2-touchkey - add touchkey driver support for TM2 This patch adds support for the TM2 touch key and led functionality. The driver interfaces with userspace through an input device and reports KEY_PHONE and KEY_BACK event types. LED brightness can be controlled by "/sys/class/leds/tm2-touchkey/brightness". Signed-off-by: Beomho Seo Signed-off-by: Jaechul Lee Reviewed-by: Javier Martinez Canillas Reviewed-by: Andi Shyti Reviewed-by: Chanwoo Choi Tested-by: Chanwoo Choi Acked-by: Krzysztof Kozlowski Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/cypress,tm2-touchkey.txt | 27 ++ drivers/input/keyboard/Kconfig | 11 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/tm2-touchkey.c | 286 ++++++++++++++++++ 4 files changed, 325 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt create mode 100644 drivers/input/keyboard/tm2-touchkey.c diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt new file mode 100644 index 000000000000..635f62c756ee --- /dev/null +++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt @@ -0,0 +1,27 @@ +Samsung tm2-touchkey + +Required properties: +- compatible: must be "cypress,tm2-touchkey" +- reg: I2C address of the chip. +- interrupt-parent: a phandle for the interrupt controller (see interrupt + binding[0]). +- interrupts: interrupt to which the chip is connected (see interrupt + binding[0]). +- vcc-supply : internal regulator output. 1.8V +- vdd-supply : power supply for IC 3.3V + +[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt + +Example: + &i2c0 { + /* ... */ + + touchkey@20 { + compatible = "cypress,tm2-touchkey"; + reg = <0x20>; + interrupt-parent = <&gpa3>; + interrupts = <2 IRQ_TYPE_EDGE_FALLING>; + vcc-supply=<&ldo32_reg>; + vdd-supply=<&ldo33_reg>; + }; + }; diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index cbd75cf44739..97acd6524ad7 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -666,6 +666,17 @@ config KEYBOARD_TC3589X To compile this driver as a module, choose M here: the module will be called tc3589x-keypad. +config KEYBOARD_TM2_TOUCHKEY + tristate "TM2 touchkey support" + depends on I2C + depends on LEDS_CLASS + help + Say Y here to enable device driver for tm2-touchkey with + LED control for the Exynos5433 TM2 board. + + To compile this driver as a module, choose M here. + module will be called tm2-touchkey. + config KEYBOARD_TWL4030 tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" depends on TWL4030_CORE diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index d9f4cfcf3410..7d9acff819a7 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -61,6 +61,7 @@ obj-$(CONFIG_KEYBOARD_SUN4I_LRADC) += sun4i-lradc-keys.o obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o +obj-$(CONFIG_KEYBOARD_TM2_TOUCHKEY) += tm2-touchkey.o obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c new file mode 100644 index 000000000000..916e2f3a9bbb --- /dev/null +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -0,0 +1,286 @@ +/* + * TM2 touchkey device driver + * + * Copyright 2005 Phil Blundell + * Copyright 2016 Samsung Electronics Co., Ltd. + * + * Author: Beomho Seo + * Author: Jaechul Lee + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey" +#define TM2_TOUCHKEY_KEYCODE_REG 0x03 +#define TM2_TOUCHKEY_BASE_REG 0x00 +#define TM2_TOUCHKEY_CMD_LED_ON 0x10 +#define TM2_TOUCHKEY_CMD_LED_OFF 0x20 +#define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3) +#define TM2_TOUCHKEY_BIT_KEYCODE GENMASK(2, 0) +#define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000 +#define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000 + +enum { + TM2_TOUCHKEY_KEY_MENU = 0x1, + TM2_TOUCHKEY_KEY_BACK, +}; + +struct tm2_touchkey_data { + struct i2c_client *client; + struct input_dev *input_dev; + struct led_classdev led_dev; + struct regulator *vdd; + struct regulator_bulk_data regulators[2]; +}; + +static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev, + enum led_brightness brightness) +{ + struct tm2_touchkey_data *touchkey = + container_of(led_dev, struct tm2_touchkey_data, led_dev); + u32 volt; + u8 data; + + if (brightness == LED_OFF) { + volt = TM2_TOUCHKEY_LED_VOLTAGE_MIN; + data = TM2_TOUCHKEY_CMD_LED_OFF; + } else { + volt = TM2_TOUCHKEY_LED_VOLTAGE_MAX; + data = TM2_TOUCHKEY_CMD_LED_ON; + } + + regulator_set_voltage(touchkey->vdd, volt, volt); + i2c_smbus_write_byte_data(touchkey->client, + TM2_TOUCHKEY_BASE_REG, data); +} + +static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey) +{ + int error; + + error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), + touchkey->regulators); + if (error) + return error; + + /* waiting for device initialization, at least 150ms */ + msleep(150); + + return 0; +} + +static void tm2_touchkey_power_disable(void *data) +{ + struct tm2_touchkey_data *touchkey = data; + + regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators), + touchkey->regulators); +} + +static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) +{ + struct tm2_touchkey_data *touchkey = devid; + int data; + int key; + + data = i2c_smbus_read_byte_data(touchkey->client, + TM2_TOUCHKEY_KEYCODE_REG); + if (data < 0) { + dev_err(&touchkey->client->dev, + "failed to read i2c data: %d\n", data); + goto out; + } + + switch (data & TM2_TOUCHKEY_BIT_KEYCODE) { + case TM2_TOUCHKEY_KEY_MENU: + key = KEY_PHONE; + break; + + case TM2_TOUCHKEY_KEY_BACK: + key = KEY_BACK; + break; + + default: + dev_warn(&touchkey->client->dev, + "unhandled keycode, data %#02x\n", data); + goto out; + } + + if (data & TM2_TOUCHKEY_BIT_PRESS_EV) { + input_report_key(touchkey->input_dev, KEY_PHONE, 0); + input_report_key(touchkey->input_dev, KEY_BACK, 0); + } else { + input_report_key(touchkey->input_dev, key, 1); + } + + input_sync(touchkey->input_dev); + +out: + return IRQ_HANDLED; +} + +static int tm2_touchkey_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct tm2_touchkey_data *touchkey; + int error; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) { + dev_err(&client->dev, "incompatible I2C adapter\n"); + return -EIO; + } + + touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); + if (!touchkey) + return -ENOMEM; + + touchkey->client = client; + i2c_set_clientdata(client, touchkey); + + touchkey->regulators[0].supply = "vcc"; + touchkey->regulators[1].supply = "vdd"; + error = devm_regulator_bulk_get(&client->dev, + ARRAY_SIZE(touchkey->regulators), + touchkey->regulators); + if (error) { + dev_err(&client->dev, "failed to get regulators: %d\n", error); + return error; + } + + /* Save VDD for easy access */ + touchkey->vdd = touchkey->regulators[1].consumer; + + error = tm2_touchkey_power_enable(touchkey); + if (error) { + dev_err(&client->dev, "failed to power up device: %d\n", error); + return error; + } + + error = devm_add_action_or_reset(&client->dev, + tm2_touchkey_power_disable, touchkey); + if (error) { + dev_err(&client->dev, + "failed to install poweroff handler: %d\n", error); + return error; + } + + /* input device */ + touchkey->input_dev = devm_input_allocate_device(&client->dev); + if (!touchkey->input_dev) { + dev_err(&client->dev, "failed to allocate input device\n"); + return -ENOMEM; + } + + touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME; + touchkey->input_dev->id.bustype = BUS_I2C; + + input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE); + input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK); + + input_set_drvdata(touchkey->input_dev, touchkey); + + error = input_register_device(touchkey->input_dev); + if (error) { + dev_err(&client->dev, + "failed to register input device: %d\n", error); + return error; + } + + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, tm2_touchkey_irq_handler, + IRQF_ONESHOT, + TM2_TOUCHKEY_DEV_NAME, touchkey); + if (error) { + dev_err(&client->dev, + "failed to request threaded irq: %d\n", error); + return error; + } + + /* led device */ + touchkey->led_dev.name = TM2_TOUCHKEY_DEV_NAME; + touchkey->led_dev.brightness = LED_FULL; + touchkey->led_dev.max_brightness = LED_FULL; + touchkey->led_dev.brightness_set = tm2_touchkey_led_brightness_set; + + error = devm_led_classdev_register(&client->dev, &touchkey->led_dev); + if (error) { + dev_err(&client->dev, + "failed to register touchkey led: %d\n", error); + return error; + } + + return 0; +} + +static int __maybe_unused tm2_touchkey_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client); + + disable_irq(client->irq); + tm2_touchkey_power_disable(touchkey); + + return 0; +} + +static int __maybe_unused tm2_touchkey_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct tm2_touchkey_data *touchkey = i2c_get_clientdata(client); + int ret; + + enable_irq(client->irq); + + ret = tm2_touchkey_power_enable(touchkey); + if (ret) + dev_err(dev, "failed to enable power: %d\n", ret); + + return ret; +} + +static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops, + tm2_touchkey_suspend, tm2_touchkey_resume); + +static const struct i2c_device_id tm2_touchkey_id_table[] = { + { TM2_TOUCHKEY_DEV_NAME, 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table); + +static const struct of_device_id tm2_touchkey_of_match[] = { + { .compatible = "cypress,tm2-touchkey", }, + { }, +}; +MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match); + +static struct i2c_driver tm2_touchkey_driver = { + .driver = { + .name = TM2_TOUCHKEY_DEV_NAME, + .pm = &tm2_touchkey_pm_ops, + .of_match_table = of_match_ptr(tm2_touchkey_of_match), + }, + .probe = tm2_touchkey_probe, + .id_table = tm2_touchkey_id_table, +}; +module_i2c_driver(tm2_touchkey_driver); + +MODULE_AUTHOR("Beomho Seo "); +MODULE_AUTHOR("Jaechul Lee "); +MODULE_DESCRIPTION("Samsung touchkey driver"); +MODULE_LICENSE("GPL v2"); From 5c4fa2a6da7fbc76290d1cb54a7e35633517a522 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sat, 21 Jan 2017 11:14:14 -0800 Subject: [PATCH 37/91] Input: soc_button_array - debounce the buttons The soc_button_array driver was initializing (kzalloc) the debounce_interval value to 0, leading to no debouncing at all, while the buttons are simple mechanical switches. This commit sets debounce_interval to 50ms to avoid spurious button press reports both on press and release of the button. Note 50ms may seem like a lot but soc_button_array is typically used with cheap tablets, with not so great buttons. I tried 10ms on my tablet and it is not enough, where as 50ms works well. Signed-off-by: Hans de Goede Signed-off-by: Dmitry Torokhov --- drivers/input/misc/soc_button_array.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/input/misc/soc_button_array.c b/drivers/input/misc/soc_button_array.c index fb3219a8d3c0..ddb2f22fca7a 100644 --- a/drivers/input/misc/soc_button_array.c +++ b/drivers/input/misc/soc_button_array.c @@ -102,6 +102,8 @@ soc_button_device_create(struct platform_device *pdev, gpio_keys[n_buttons].active_low = 1; gpio_keys[n_buttons].desc = info->name; gpio_keys[n_buttons].wakeup = info->wakeup; + /* These devices often use cheap buttons, use 50 ms debounce */ + gpio_keys[n_buttons].debounce_interval = 50; n_buttons++; } From 83e4947a569f4d544ef4a1361f51c91d73a9c915 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sat, 21 Jan 2017 11:16:47 -0800 Subject: [PATCH 38/91] Input: gpio-keys - add support for setkeycode gpio-keys input devices created by the soc_button_array driver are configured with key-codes based on ACPI provided information. Unfortunately on some tablets this info is wrong, and we need to have a quirk to fix things up. Add support for input_setkeycode to the gpio-keys driver, so that the existing udev hwdb mechanism can be used to fix things up on these tablets. Signed-off-by: Hans de Goede Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys.c | 40 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 582462d0af75..858bbc16b900 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -36,6 +36,8 @@ struct gpio_button_data { struct input_dev *input; struct gpio_desc *gpiod; + unsigned short *code; + struct timer_list release_timer; unsigned int release_delay; /* in msecs, for IRQ-only buttons */ @@ -52,6 +54,7 @@ struct gpio_keys_drvdata { const struct gpio_keys_platform_data *pdata; struct input_dev *input; struct mutex disable_lock; + unsigned short *keymap; struct gpio_button_data data[0]; }; @@ -203,7 +206,7 @@ static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata, if (only_disabled && !bdata->disabled) continue; - __set_bit(bdata->button->code, bits); + __set_bit(*bdata->code, bits); } ret = scnprintf(buf, PAGE_SIZE - 1, "%*pbl", n_events, bits); @@ -254,7 +257,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, if (bdata->button->type != type) continue; - if (test_bit(bdata->button->code, bits) && + if (test_bit(*bdata->code, bits) && !bdata->button->can_disable) { error = -EINVAL; goto out; @@ -269,7 +272,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, if (bdata->button->type != type) continue; - if (test_bit(bdata->button->code, bits)) + if (test_bit(*bdata->code, bits)) gpio_keys_disable_button(bdata); else gpio_keys_enable_button(bdata); @@ -371,7 +374,7 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) if (state) input_event(input, type, button->code, button->value); } else { - input_event(input, type, button->code, state); + input_event(input, type, *bdata->code, state); } input_sync(input); } @@ -411,7 +414,7 @@ static void gpio_keys_irq_timer(unsigned long _data) spin_lock_irqsave(&bdata->lock, flags); if (bdata->key_pressed) { - input_event(input, EV_KEY, bdata->button->code, 0); + input_event(input, EV_KEY, *bdata->code, 0); input_sync(input); bdata->key_pressed = false; } @@ -421,7 +424,6 @@ static void gpio_keys_irq_timer(unsigned long _data) static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) { struct gpio_button_data *bdata = dev_id; - const struct gpio_keys_button *button = bdata->button; struct input_dev *input = bdata->input; unsigned long flags; @@ -433,11 +435,11 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) if (bdata->button->wakeup) pm_wakeup_event(bdata->input->dev.parent, 0); - input_event(input, EV_KEY, button->code, 1); + input_event(input, EV_KEY, *bdata->code, 1); input_sync(input); if (!bdata->release_delay) { - input_event(input, EV_KEY, button->code, 0); + input_event(input, EV_KEY, *bdata->code, 0); input_sync(input); goto out; } @@ -465,12 +467,14 @@ static void gpio_keys_quiesce_key(void *data) static int gpio_keys_setup_key(struct platform_device *pdev, struct input_dev *input, - struct gpio_button_data *bdata, + struct gpio_keys_drvdata *ddata, const struct gpio_keys_button *button, + int idx, struct fwnode_handle *child) { const char *desc = button->desc ? button->desc : "gpio_keys"; struct device *dev = &pdev->dev; + struct gpio_button_data *bdata = &ddata->data[idx]; irq_handler_t isr; unsigned long irqflags; int irq; @@ -577,7 +581,9 @@ static int gpio_keys_setup_key(struct platform_device *pdev, irqflags = 0; } - input_set_capability(input, button->type ?: EV_KEY, button->code); + bdata->code = &ddata->keymap[idx]; + *bdata->code = button->code; + input_set_capability(input, button->type ?: EV_KEY, *bdata->code); /* * Install custom action to cancel release timer and @@ -750,6 +756,12 @@ static int gpio_keys_probe(struct platform_device *pdev) return -ENOMEM; } + ddata->keymap = devm_kcalloc(dev, + pdata->nbuttons, sizeof(ddata->keymap[0]), + GFP_KERNEL); + if (!ddata->keymap) + return -ENOMEM; + input = devm_input_allocate_device(dev); if (!input) { dev_err(dev, "failed to allocate input device\n"); @@ -774,13 +786,16 @@ static int gpio_keys_probe(struct platform_device *pdev) input->id.product = 0x0001; input->id.version = 0x0100; + input->keycode = ddata->keymap; + input->keycodesize = sizeof(ddata->keymap[0]); + input->keycodemax = pdata->nbuttons; + /* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit); for (i = 0; i < pdata->nbuttons; i++) { const struct gpio_keys_button *button = &pdata->buttons[i]; - struct gpio_button_data *bdata = &ddata->data[i]; if (!dev_get_platdata(dev)) { child = device_get_next_child_node(&pdev->dev, child); @@ -792,7 +807,8 @@ static int gpio_keys_probe(struct platform_device *pdev) } } - error = gpio_keys_setup_key(pdev, input, bdata, button, child); + error = gpio_keys_setup_key(pdev, input, ddata, + button, i, child); if (error) { fwnode_handle_put(child); return error; From 666c0b8366b8d5d44251a3889f6a2c264a38dee9 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:29:36 -0800 Subject: [PATCH 39/91] Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata There is no call to i2c_get_clientdata(), platform_get_drvdata(), or dev_get_drvdata() in any of the drivers in this patch. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/adc-keys.c | 2 -- drivers/input/keyboard/cap11xx.c | 1 - drivers/input/keyboard/gpio_keys_polled.c | 1 - drivers/input/keyboard/jornada680_kbd.c | 2 -- drivers/input/keyboard/max7359_keypad.c | 1 - drivers/input/keyboard/nspire-keypad.c | 2 -- drivers/input/keyboard/opencores-kbd.c | 2 -- drivers/input/keyboard/sun4i-lradc-keys.c | 1 - 8 files changed, 12 deletions(-) diff --git a/drivers/input/keyboard/adc-keys.c b/drivers/input/keyboard/adc-keys.c index f8cf2ccacefd..c255af21e71a 100644 --- a/drivers/input/keyboard/adc-keys.c +++ b/drivers/input/keyboard/adc-keys.c @@ -148,8 +148,6 @@ static int adc_keys_probe(struct platform_device *pdev) if (error) return error; - platform_set_drvdata(pdev, st); - poll_dev = devm_input_allocate_polled_device(dev); if (!poll_dev) { dev_err(dev, "failed to allocate input device\n"); diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index 4401be225d64..1a1eacae3ea1 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -392,7 +392,6 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client, return error; dev_info(dev, "CAP11XX detected, revision 0x%02x\n", rev); - i2c_set_clientdata(i2c_client, priv); node = dev->of_node; if (!of_property_read_u32(node, "microchip,sensor-gain", &gain32)) { diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index bed4f2086158..cc193e665358 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -365,7 +365,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) bdev->poll_dev = poll_dev; bdev->dev = dev; bdev->pdata = pdata; - platform_set_drvdata(pdev, bdev); error = input_register_polled_device(poll_dev); if (error) { diff --git a/drivers/input/keyboard/jornada680_kbd.c b/drivers/input/keyboard/jornada680_kbd.c index 80c81278ad2c..0116ac99f44c 100644 --- a/drivers/input/keyboard/jornada680_kbd.c +++ b/drivers/input/keyboard/jornada680_kbd.c @@ -197,8 +197,6 @@ static int jornada680kbd_probe(struct platform_device *pdev) return -ENOMEM; } - platform_set_drvdata(pdev, jornadakbd); - jornadakbd->poll_dev = poll_dev; memcpy(jornadakbd->keymap, jornada_scancodes, diff --git a/drivers/input/keyboard/max7359_keypad.c b/drivers/input/keyboard/max7359_keypad.c index 5091133b7b8e..cd44d22d8770 100644 --- a/drivers/input/keyboard/max7359_keypad.c +++ b/drivers/input/keyboard/max7359_keypad.c @@ -241,7 +241,6 @@ static int max7359_probe(struct i2c_client *client, /* Initialize MAX7359 */ max7359_initialize(client); - i2c_set_clientdata(client, keypad); device_init_wakeup(&client->dev, 1); return 0; diff --git a/drivers/input/keyboard/nspire-keypad.c b/drivers/input/keyboard/nspire-keypad.c index 7abfd34eb87e..c7f26fa3034c 100644 --- a/drivers/input/keyboard/nspire-keypad.c +++ b/drivers/input/keyboard/nspire-keypad.c @@ -249,8 +249,6 @@ static int nspire_keypad_probe(struct platform_device *pdev) return error; } - platform_set_drvdata(pdev, keypad); - dev_dbg(&pdev->dev, "TI-NSPIRE keypad at %pR (scan_interval=%uus, row_delay=%uus%s)\n", res, keypad->row_delay, keypad->scan_interval, diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c index f8502bb29176..98ea6190f5f5 100644 --- a/drivers/input/keyboard/opencores-kbd.c +++ b/drivers/input/keyboard/opencores-kbd.c @@ -112,8 +112,6 @@ static int opencores_kbd_probe(struct platform_device *pdev) return error; } - platform_set_drvdata(pdev, opencores_kbd); - return 0; } diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c b/drivers/input/keyboard/sun4i-lradc-keys.c index cc8f7ddcee53..a37c172452e6 100644 --- a/drivers/input/keyboard/sun4i-lradc-keys.c +++ b/drivers/input/keyboard/sun4i-lradc-keys.c @@ -261,7 +261,6 @@ static int sun4i_lradc_probe(struct platform_device *pdev) if (error) return error; - platform_set_drvdata(pdev, lradc); return 0; } From 4cd216cbe744f907e7201f1f93f383980b7f931a Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:32:34 -0800 Subject: [PATCH 40/91] Input: misc - drop calls to platform_set_drvdata and i2c_set_clientdata There is no call to i2c_get_clientdata(), platform_get_drvdata(), or dev_get_drvdata() in any of the drivers in this patch. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/arizona-haptics.c | 2 -- drivers/input/misc/atmel_captouch.c | 1 - drivers/input/misc/da9063_onkey.c | 1 - drivers/input/misc/e3x0-button.c | 1 - drivers/input/misc/twl4030-pwrbutton.c | 1 - 5 files changed, 6 deletions(-) diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c index 982936334537..de1b64703c8c 100644 --- a/drivers/input/misc/arizona-haptics.c +++ b/drivers/input/misc/arizona-haptics.c @@ -196,8 +196,6 @@ static int arizona_haptics_probe(struct platform_device *pdev) return ret; } - platform_set_drvdata(pdev, haptics); - return 0; } diff --git a/drivers/input/misc/atmel_captouch.c b/drivers/input/misc/atmel_captouch.c index 941265415a89..c4c0f4bb7627 100644 --- a/drivers/input/misc/atmel_captouch.c +++ b/drivers/input/misc/atmel_captouch.c @@ -191,7 +191,6 @@ static int atmel_captouch_probe(struct i2c_client *client, return -ENOMEM; capdev->client = client; - i2c_set_clientdata(client, capdev); err = atmel_read(capdev, REG_KEY_STATE, &capdev->prev_btn, sizeof(capdev->prev_btn)); diff --git a/drivers/input/misc/da9063_onkey.c b/drivers/input/misc/da9063_onkey.c index b4ff1e86d3d3..3e9c353d82ef 100644 --- a/drivers/input/misc/da9063_onkey.c +++ b/drivers/input/misc/da9063_onkey.c @@ -287,7 +287,6 @@ static int da9063_onkey_probe(struct platform_device *pdev) return error; } - platform_set_drvdata(pdev, onkey); return 0; } diff --git a/drivers/input/misc/e3x0-button.c b/drivers/input/misc/e3x0-button.c index 13bfca8a7b16..b0b374112db3 100644 --- a/drivers/input/misc/e3x0-button.c +++ b/drivers/input/misc/e3x0-button.c @@ -120,7 +120,6 @@ static int e3x0_button_probe(struct platform_device *pdev) return error; } - platform_set_drvdata(pdev, input); device_init_wakeup(&pdev->dev, 1); return 0; } diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c index 603fc2fadf05..54162d2cbcfc 100644 --- a/drivers/input/misc/twl4030-pwrbutton.c +++ b/drivers/input/misc/twl4030-pwrbutton.c @@ -85,7 +85,6 @@ static int twl4030_pwrbutton_probe(struct platform_device *pdev) return err; } - platform_set_drvdata(pdev, pwr); device_init_wakeup(&pdev->dev, true); return 0; From 8300445cc7c14b1532a4891f2d25a649d6437daa Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:33:01 -0800 Subject: [PATCH 41/91] Input: touchscreen - drop calls to platform_set_drvdata and i2c_set_clientdata There is no call to i2c_get_clientdata(), platform_get_drvdata(), or dev_get_drvdata() in any of the drivers in this patch. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/88pm860x-ts.c | 3 --- drivers/input/touchscreen/colibri-vf50-ts.c | 2 -- drivers/input/touchscreen/egalax_ts.c | 1 - drivers/input/touchscreen/max11801_ts.c | 1 - drivers/input/touchscreen/sx8654.c | 1 - 5 files changed, 8 deletions(-) diff --git a/drivers/input/touchscreen/88pm860x-ts.c b/drivers/input/touchscreen/88pm860x-ts.c index 251ff2aa0633..7ed828a51f4c 100644 --- a/drivers/input/touchscreen/88pm860x-ts.c +++ b/drivers/input/touchscreen/88pm860x-ts.c @@ -240,8 +240,6 @@ static int pm860x_touch_probe(struct platform_device *pdev) if (!touch) return -ENOMEM; - platform_set_drvdata(pdev, touch); - touch->idev = devm_input_allocate_device(&pdev->dev); if (!touch->idev) { dev_err(&pdev->dev, "Failed to allocate input device!\n"); @@ -285,7 +283,6 @@ static int pm860x_touch_probe(struct platform_device *pdev) return ret; } - platform_set_drvdata(pdev, touch); return 0; } diff --git a/drivers/input/touchscreen/colibri-vf50-ts.c b/drivers/input/touchscreen/colibri-vf50-ts.c index 69828d015d45..69c08acae264 100644 --- a/drivers/input/touchscreen/colibri-vf50-ts.c +++ b/drivers/input/touchscreen/colibri-vf50-ts.c @@ -311,8 +311,6 @@ static int vf50_ts_probe(struct platform_device *pdev) return -ENOMEM; } - platform_set_drvdata(pdev, touchdev); - input->name = DRIVER_NAME; input->id.bustype = BUS_HOST; input->dev.parent = dev; diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c index 1afc08b08155..3592a946950b 100644 --- a/drivers/input/touchscreen/egalax_ts.c +++ b/drivers/input/touchscreen/egalax_ts.c @@ -229,7 +229,6 @@ static int egalax_ts_probe(struct i2c_client *client, if (error) return error; - i2c_set_clientdata(client, ts); return 0; } diff --git a/drivers/input/touchscreen/max11801_ts.c b/drivers/input/touchscreen/max11801_ts.c index 82079cde849c..d87b89da114e 100644 --- a/drivers/input/touchscreen/max11801_ts.c +++ b/drivers/input/touchscreen/max11801_ts.c @@ -216,7 +216,6 @@ static int max11801_ts_probe(struct i2c_client *client, if (error) return error; - i2c_set_clientdata(client, data); return 0; } diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c index 642f4a53de50..ed29db3ec731 100644 --- a/drivers/input/touchscreen/sx8654.c +++ b/drivers/input/touchscreen/sx8654.c @@ -253,7 +253,6 @@ static int sx8654_probe(struct i2c_client *client, if (error) return error; - i2c_set_clientdata(client, sx8654); return 0; } From b4e66e7d1948e0a54a38102462b016ee1ed489c2 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:40:45 -0800 Subject: [PATCH 42/91] Input: keyboard - use local variables consistently If a function declares a variable to access a structure element, use it consistently. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/davinci_keyscan.c | 4 ++-- drivers/input/keyboard/gpio_keys.c | 24 +++++++++++------------ drivers/input/keyboard/gpio_keys_polled.c | 6 +++--- drivers/input/keyboard/mpr121_touchkey.c | 18 ++++++++--------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/input/keyboard/davinci_keyscan.c b/drivers/input/keyboard/davinci_keyscan.c index f363d1d2907a..b20a5d044caa 100644 --- a/drivers/input/keyboard/davinci_keyscan.c +++ b/drivers/input/keyboard/davinci_keyscan.c @@ -172,7 +172,7 @@ static int __init davinci_ks_probe(struct platform_device *pdev) struct input_dev *key_dev; struct resource *res, *mem; struct device *dev = &pdev->dev; - struct davinci_ks_platform_data *pdata = dev_get_platdata(&pdev->dev); + struct davinci_ks_platform_data *pdata = dev_get_platdata(dev); int error, i; if (pdata->device_enable) { @@ -255,7 +255,7 @@ static int __init davinci_ks_probe(struct platform_device *pdev) key_dev->name = "davinci_keyscan"; key_dev->phys = "davinci_keyscan/input0"; - key_dev->dev.parent = &pdev->dev; + key_dev->dev.parent = dev; key_dev->id.bustype = BUS_HOST; key_dev->id.vendor = 0x0001; key_dev->id.product = 0x0001; diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 858bbc16b900..50b19b952698 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -518,8 +518,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, if (button->active_low) flags |= GPIOF_ACTIVE_LOW; - error = devm_gpio_request_one(&pdev->dev, button->gpio, flags, - desc); + error = devm_gpio_request_one(dev, button->gpio, flags, desc); if (error < 0) { dev_err(dev, "Failed to request GPIO %d, error %d\n", button->gpio, error); @@ -589,10 +588,9 @@ static int gpio_keys_setup_key(struct platform_device *pdev, * Install custom action to cancel release timer and * workqueue item. */ - error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata); + error = devm_add_action(dev, gpio_keys_quiesce_key, bdata); if (error) { - dev_err(&pdev->dev, - "failed to register quiesce action, error: %d\n", + dev_err(dev, "failed to register quiesce action, error: %d\n", error); return error; } @@ -604,8 +602,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, if (!button->can_disable) irqflags |= IRQF_SHARED; - error = devm_request_any_context_irq(&pdev->dev, bdata->irq, - isr, irqflags, desc, bdata); + error = devm_request_any_context_irq(dev, bdata->irq, isr, irqflags, + desc, bdata); if (error < 0) { dev_err(dev, "Unable to claim irq %d; error %d\n", bdata->irq, error); @@ -777,7 +775,7 @@ static int gpio_keys_probe(struct platform_device *pdev) input->name = pdata->name ? : pdev->name; input->phys = "gpio-keys/input0"; - input->dev.parent = &pdev->dev; + input->dev.parent = dev; input->open = gpio_keys_open; input->close = gpio_keys_close; @@ -798,9 +796,9 @@ static int gpio_keys_probe(struct platform_device *pdev) const struct gpio_keys_button *button = &pdata->buttons[i]; if (!dev_get_platdata(dev)) { - child = device_get_next_child_node(&pdev->dev, child); + child = device_get_next_child_node(dev, child); if (!child) { - dev_err(&pdev->dev, + dev_err(dev, "missing child device node for entry %d\n", i); return -EINVAL; @@ -820,7 +818,7 @@ static int gpio_keys_probe(struct platform_device *pdev) fwnode_handle_put(child); - error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group); + error = sysfs_create_group(&dev->kobj, &gpio_keys_attr_group); if (error) { dev_err(dev, "Unable to export keys/switches, error: %d\n", error); @@ -834,12 +832,12 @@ static int gpio_keys_probe(struct platform_device *pdev) goto err_remove_group; } - device_init_wakeup(&pdev->dev, wakeup); + device_init_wakeup(dev, wakeup); return 0; err_remove_group: - sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); + sysfs_remove_group(&dev->kobj, &gpio_keys_attr_group); return error; } diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index cc193e665358..4fce43a6a0e0 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c @@ -252,13 +252,13 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) size = sizeof(struct gpio_keys_polled_dev) + pdata->nbuttons * sizeof(struct gpio_keys_button_data); - bdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); + bdev = devm_kzalloc(dev, size, GFP_KERNEL); if (!bdev) { dev_err(dev, "no memory for private data\n"); return -ENOMEM; } - poll_dev = devm_input_allocate_polled_device(&pdev->dev); + poll_dev = devm_input_allocate_polled_device(dev); if (!poll_dev) { dev_err(dev, "no memory for polled device\n"); return -ENOMEM; @@ -332,7 +332,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) if (button->active_low) flags |= GPIOF_ACTIVE_LOW; - error = devm_gpio_request_one(&pdev->dev, button->gpio, + error = devm_gpio_request_one(dev, button->gpio, flags, button->desc ? : DRV_NAME); if (error) { dev_err(dev, diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 989ca66f63af..884a74d8a7ed 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c @@ -237,7 +237,7 @@ static int mpr_touchkey_probe(struct i2c_client *client, int i; if (!client->irq) { - dev_err(&client->dev, "irq number should not be zero\n"); + dev_err(dev, "irq number should not be zero\n"); return -EINVAL; } @@ -247,11 +247,11 @@ static int mpr_touchkey_probe(struct i2c_client *client, vdd_uv = regulator_get_voltage(vdd_supply); - mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121), GFP_KERNEL); + mpr121 = devm_kzalloc(dev, sizeof(*mpr121), GFP_KERNEL); if (!mpr121) return -ENOMEM; - input_dev = devm_input_allocate_device(&client->dev); + input_dev = devm_input_allocate_device(dev); if (!input_dev) return -ENOMEM; @@ -275,7 +275,7 @@ static int mpr_touchkey_probe(struct i2c_client *client, input_dev->name = "Freescale MPR121 Touchkey"; input_dev->id.bustype = BUS_I2C; - input_dev->dev.parent = &client->dev; + input_dev->dev.parent = dev; if (device_property_read_bool(dev, "autorepeat")) __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); @@ -289,16 +289,16 @@ static int mpr_touchkey_probe(struct i2c_client *client, error = mpr121_phys_init(mpr121, client, vdd_uv); if (error) { - dev_err(&client->dev, "Failed to init register\n"); + dev_err(dev, "Failed to init register\n"); return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, - NULL, mpr_touchkey_interrupt, + error = devm_request_threaded_irq(dev, client->irq, NULL, + mpr_touchkey_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, - client->dev.driver->name, mpr121); + dev->driver->name, mpr121); if (error) { - dev_err(&client->dev, "Failed to register interrupt\n"); + dev_err(dev, "Failed to register interrupt\n"); return error; } From a0d86ecd23a9e8ae36e274191e55068cc4d10129 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:44:18 -0800 Subject: [PATCH 43/91] Input: misc - use local variables consistently If a function declares a variable to access a structure element, use it consistently. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/drv260x.c | 2 +- drivers/input/misc/gpio_tilt_polled.c | 2 +- drivers/input/misc/hisi_powerkey.c | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c index 0a2b865b1000..fb089d36c0d6 100644 --- a/drivers/input/misc/drv260x.c +++ b/drivers/input/misc/drv260x.c @@ -538,7 +538,7 @@ static int drv260x_probe(struct i2c_client *client, haptics->input_dev = devm_input_allocate_device(dev); if (!haptics->input_dev) { - dev_err(&client->dev, "Failed to allocate input device\n"); + dev_err(dev, "Failed to allocate input device\n"); return -ENOMEM; } diff --git a/drivers/input/misc/gpio_tilt_polled.c b/drivers/input/misc/gpio_tilt_polled.c index f103b99d1852..6e217a45e39a 100644 --- a/drivers/input/misc/gpio_tilt_polled.c +++ b/drivers/input/misc/gpio_tilt_polled.c @@ -138,7 +138,7 @@ static int gpio_tilt_polled_probe(struct platform_device *pdev) input->name = pdev->name; input->phys = DRV_NAME"/input0"; - input->dev.parent = &pdev->dev; + input->dev.parent = dev; input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; diff --git a/drivers/input/misc/hisi_powerkey.c b/drivers/input/misc/hisi_powerkey.c index 675539c529ce..c4c42124a059 100644 --- a/drivers/input/misc/hisi_powerkey.c +++ b/drivers/input/misc/hisi_powerkey.c @@ -75,9 +75,9 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) struct input_dev *input; int irq, i, error; - input = devm_input_allocate_device(&pdev->dev); + input = devm_input_allocate_device(dev); if (!input) { - dev_err(&pdev->dev, "failed to allocate input device\n"); + dev_err(dev, "failed to allocate input device\n"); return -ENOMEM; } @@ -111,12 +111,11 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) error = input_register_device(input); if (error) { - dev_err(&pdev->dev, "failed to register input device: %d\n", - error); + dev_err(dev, "failed to register input device: %d\n", error); return error; } - device_init_wakeup(&pdev->dev, 1); + device_init_wakeup(dev, 1); return 0; } From ad56814fccfba3fe3613fa4d9accff3816786f3c Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:44:46 -0800 Subject: [PATCH 44/91] Input: mouse - use local variables consistently If a function declares a variable to access a structure element, use it consistently. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/alps.c | 2 +- drivers/input/mouse/bcm5974.c | 2 +- drivers/input/mouse/cyapa.c | 6 ++-- drivers/input/mouse/cypress_ps2.c | 4 +-- drivers/input/mouse/elan_i2c_core.c | 46 +++++++++++------------------ drivers/input/mouse/elantech.c | 2 +- drivers/input/mouse/hgpk.c | 5 ++-- drivers/input/mouse/logips2pp.c | 2 +- drivers/input/mouse/trackpoint.c | 4 +-- 9 files changed, 31 insertions(+), 42 deletions(-) diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index 328edc8c8786..72b28ebfe360 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -1855,7 +1855,7 @@ static int alps_absolute_mode_v1_v2(struct psmouse *psmouse) * Switch mouse to poll (remote) mode so motion data will not * get in our way */ - return ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETPOLL); + return ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETPOLL); } static int alps_monitor_mode_send_word(struct psmouse *psmouse, u16 word) diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c index 30e3442518f8..d0122134f320 100644 --- a/drivers/input/mouse/bcm5974.c +++ b/drivers/input/mouse/bcm5974.c @@ -665,7 +665,7 @@ static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on) char *data; /* Type 3 does not require a mode switch */ - if (dev->cfg.tp_type == TYPE3) + if (c->tp_type == TYPE3) return 0; data = kmalloc(c->um_size, GFP_KERNEL); diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c index dc2394292088..fd8865c65caf 100644 --- a/drivers/input/mouse/cyapa.c +++ b/drivers/input/mouse/cyapa.c @@ -832,8 +832,8 @@ static int cyapa_prepare_wakeup_controls(struct cyapa *cyapa) int error; if (device_can_wakeup(dev)) { - error = sysfs_merge_group(&client->dev.kobj, - &cyapa_power_wakeup_group); + error = sysfs_merge_group(&dev->kobj, + &cyapa_power_wakeup_group); if (error) { dev_err(dev, "failed to add power wakeup group: %d\n", error); @@ -1312,7 +1312,7 @@ static int cyapa_probe(struct i2c_client *client, return error; } - error = sysfs_create_group(&client->dev.kobj, &cyapa_sysfs_group); + error = sysfs_create_group(&dev->kobj, &cyapa_sysfs_group); if (error) { dev_err(dev, "failed to create sysfs entries: %d\n", error); return error; diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 28dcfc822bf6..faa3a980d4f5 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -107,7 +107,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, enum psmouse_state old_state; int pktsize; - ps2_begin_command(&psmouse->ps2dev); + ps2_begin_command(ps2dev); old_state = psmouse->state; psmouse->state = PSMOUSE_CMD_MODE; @@ -133,7 +133,7 @@ out: psmouse->state = old_state; psmouse->pktcnt = 0; - ps2_end_command(&psmouse->ps2dev); + ps2_end_command(ps2dev); return rc; } diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c index fa598f7f4372..2c7d2872636c 100644 --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c @@ -1041,8 +1041,7 @@ static int elan_probe(struct i2c_client *client, return -EIO; } - data = devm_kzalloc(&client->dev, sizeof(struct elan_tp_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct elan_tp_data), GFP_KERNEL); if (!data) return -ENOMEM; @@ -1053,29 +1052,25 @@ static int elan_probe(struct i2c_client *client, init_completion(&data->fw_completion); mutex_init(&data->sysfs_mutex); - data->vcc = devm_regulator_get(&client->dev, "vcc"); + data->vcc = devm_regulator_get(dev, "vcc"); if (IS_ERR(data->vcc)) { error = PTR_ERR(data->vcc); if (error != -EPROBE_DEFER) - dev_err(&client->dev, - "Failed to get 'vcc' regulator: %d\n", + dev_err(dev, "Failed to get 'vcc' regulator: %d\n", error); return error; } error = regulator_enable(data->vcc); if (error) { - dev_err(&client->dev, - "Failed to enable regulator: %d\n", error); + dev_err(dev, "Failed to enable regulator: %d\n", error); return error; } - error = devm_add_action(&client->dev, - elan_disable_regulator, data); + error = devm_add_action(dev, elan_disable_regulator, data); if (error) { regulator_disable(data->vcc); - dev_err(&client->dev, - "Failed to add disable regulator action: %d\n", + dev_err(dev, "Failed to add disable regulator action: %d\n", error); return error; } @@ -1093,14 +1088,14 @@ static int elan_probe(struct i2c_client *client, if (error) return error; - dev_info(&client->dev, + dev_info(dev, "Elan Touchpad: Module ID: 0x%04x, Firmware: 0x%04x, Sample: 0x%04x, IAP: 0x%04x\n", data->product_id, data->fw_version, data->sm_version, data->iap_version); - dev_dbg(&client->dev, + dev_dbg(dev, "Elan Touchpad Extra Information:\n" " Max ABS X,Y: %d,%d\n" " Width X,Y: %d,%d\n" @@ -1118,38 +1113,33 @@ static int elan_probe(struct i2c_client *client, * Systems using device tree should set up interrupt via DTS, * the rest will use the default falling edge interrupts. */ - irqflags = client->dev.of_node ? 0 : IRQF_TRIGGER_FALLING; + irqflags = dev->of_node ? 0 : IRQF_TRIGGER_FALLING; - error = devm_request_threaded_irq(&client->dev, client->irq, - NULL, elan_isr, + error = devm_request_threaded_irq(dev, client->irq, NULL, elan_isr, irqflags | IRQF_ONESHOT, client->name, data); if (error) { - dev_err(&client->dev, "cannot register irq=%d\n", client->irq); + dev_err(dev, "cannot register irq=%d\n", client->irq); return error; } - error = sysfs_create_groups(&client->dev.kobj, elan_sysfs_groups); + error = sysfs_create_groups(&dev->kobj, elan_sysfs_groups); if (error) { - dev_err(&client->dev, "failed to create sysfs attributes: %d\n", - error); + dev_err(dev, "failed to create sysfs attributes: %d\n", error); return error; } - error = devm_add_action(&client->dev, - elan_remove_sysfs_groups, data); + error = devm_add_action(dev, elan_remove_sysfs_groups, data); if (error) { elan_remove_sysfs_groups(data); - dev_err(&client->dev, - "Failed to add sysfs cleanup action: %d\n", + dev_err(dev, "Failed to add sysfs cleanup action: %d\n", error); return error; } error = input_register_device(data->input); if (error) { - dev_err(&client->dev, "failed to register input device: %d\n", - error); + dev_err(dev, "failed to register input device: %d\n", error); return error; } @@ -1157,8 +1147,8 @@ static int elan_probe(struct i2c_client *client, * Systems using device tree should set up wakeup via DTS, * the rest will configure device as wakeup source by default. */ - if (!client->dev.of_node) - device_init_wakeup(&client->dev, true); + if (!dev->of_node) + device_init_wakeup(dev, true); return 0; } diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index db7d1d666ac1..efc8ec342351 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -1412,7 +1412,7 @@ int elantech_detect(struct psmouse *psmouse, bool set_properties) struct ps2dev *ps2dev = &psmouse->ps2dev; unsigned char param[3]; - ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); + ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_DISABLE) || ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11) || diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c index 62be888e83d0..015509e0b140 100644 --- a/drivers/input/mouse/hgpk.c +++ b/drivers/input/mouse/hgpk.c @@ -713,8 +713,7 @@ static int hgpk_toggle_powersave(struct psmouse *psmouse, int enable) * the upper bound. (in practice, it takes about 3 loops.) */ for (timeo = 20; timeo > 0; timeo--) { - if (!ps2_sendbyte(&psmouse->ps2dev, - PSMOUSE_CMD_DISABLE, 20)) + if (!ps2_sendbyte(ps2dev, PSMOUSE_CMD_DISABLE, 20)) break; msleep(25); } @@ -740,7 +739,7 @@ static int hgpk_toggle_powersave(struct psmouse *psmouse, int enable) psmouse_set_state(psmouse, PSMOUSE_IGNORE); /* probably won't see an ACK, the touchpad will be off */ - ps2_sendbyte(&psmouse->ps2dev, 0xec, 20); + ps2_sendbyte(ps2dev, 0xec, 20); } return 0; diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c index 422da1cd9e76..ef9c97f5e3d7 100644 --- a/drivers/input/mouse/logips2pp.c +++ b/drivers/input/mouse/logips2pp.c @@ -402,7 +402,7 @@ int ps2pp_detect(struct psmouse *psmouse, bool set_properties) psmouse->set_resolution = ps2pp_set_resolution; psmouse->disconnect = ps2pp_disconnect; - error = device_create_file(&psmouse->ps2dev.serio->dev, + error = device_create_file(&ps2dev->serio->dev, &psmouse_attr_smartscroll.dattr); if (error) { psmouse_err(psmouse, diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c index 354d47ecd66a..75ed6df49738 100644 --- a/drivers/input/mouse/trackpoint.c +++ b/drivers/input/mouse/trackpoint.c @@ -379,7 +379,7 @@ int trackpoint_detect(struct psmouse *psmouse, bool set_properties) if (!set_properties) return 0; - if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) { + if (trackpoint_read(ps2dev, TP_EXT_BTN, &button_info)) { psmouse_warn(psmouse, "failed to get extended button data\n"); button_info = 0; } @@ -402,7 +402,7 @@ int trackpoint_detect(struct psmouse *psmouse, bool set_properties) trackpoint_defaults(psmouse->private); - error = trackpoint_power_on_reset(&psmouse->ps2dev); + error = trackpoint_power_on_reset(ps2dev); /* Write defaults to TP only if reset fails. */ if (error) From d7ddf15414dd598b9b875664e6b7aebe6c988f5d Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:46:47 -0800 Subject: [PATCH 45/91] Input: touchscreen - use local variables consistently If a function declares a variable to access a structure element, use it consistently. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/atmel_mxt_ts.c | 2 +- drivers/input/touchscreen/fsl-imx25-tcq.c | 2 +- drivers/input/touchscreen/ili210x.c | 2 +- drivers/input/touchscreen/pixcir_i2c_ts.c | 4 ++-- drivers/input/touchscreen/rohm_bu21023.c | 3 +-- drivers/input/touchscreen/s3c2410_ts.c | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index e5d185fe69b9..2302aef2b2d4 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2509,7 +2509,7 @@ static void mxt_debug_init(struct mxt_data *data) dbg->t37_pages = MXT1386_COLUMNS * MXT1386_PAGES_PER_COLUMN; else dbg->t37_pages = DIV_ROUND_UP(data->xsize * - data->info.matrix_ysize * + info->matrix_ysize * sizeof(u16), sizeof(dbg->t37_buf->data)); diff --git a/drivers/input/touchscreen/fsl-imx25-tcq.c b/drivers/input/touchscreen/fsl-imx25-tcq.c index d50ee490c9cc..47fe1f184bbc 100644 --- a/drivers/input/touchscreen/fsl-imx25-tcq.c +++ b/drivers/input/touchscreen/fsl-imx25-tcq.c @@ -507,7 +507,7 @@ static int mx25_tcq_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct input_dev *idev; struct mx25_tcq_priv *priv; - struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent); + struct mx25_tsadc *tsadc = dev_get_drvdata(dev->parent); struct resource *res; void __iomem *mem; int error; diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index fe4848bd1f4c..91dc5fb34fe1 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -280,7 +280,7 @@ static int ili210x_i2c_probe(struct i2c_client *client, goto err_remove_sysfs; } - device_init_wakeup(&client->dev, 1); + device_init_wakeup(dev, 1); dev_dbg(dev, "ILI210x initialized (IRQ: %d), firmware version %d.%d.%d", diff --git a/drivers/input/touchscreen/pixcir_i2c_ts.c b/drivers/input/touchscreen/pixcir_i2c_ts.c index 3bb0637d832e..37ff672c7802 100644 --- a/drivers/input/touchscreen/pixcir_i2c_ts.c +++ b/drivers/input/touchscreen/pixcir_i2c_ts.c @@ -461,7 +461,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, if (error) return error; } else { - dev_err(&client->dev, "platform data not defined\n"); + dev_err(dev, "platform data not defined\n"); return -EINVAL; } @@ -483,7 +483,7 @@ static int pixcir_i2c_ts_probe(struct i2c_client *client, input->id.bustype = BUS_I2C; input->open = pixcir_input_open; input->close = pixcir_input_close; - input->dev.parent = &client->dev; + input->dev.parent = dev; if (pdata) { input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0); diff --git a/drivers/input/touchscreen/rohm_bu21023.c b/drivers/input/touchscreen/rohm_bu21023.c index 611156a2ef80..eeaf6ff03597 100644 --- a/drivers/input/touchscreen/rohm_bu21023.c +++ b/drivers/input/touchscreen/rohm_bu21023.c @@ -1189,8 +1189,7 @@ static int rohm_bu21023_i2c_probe(struct i2c_client *client, error = devm_add_action(dev, rohm_ts_remove_sysfs_group, dev); if (error) { rohm_ts_remove_sysfs_group(dev); - dev_err(&client->dev, - "Failed to add sysfs cleanup action: %d\n", + dev_err(dev, "Failed to add sysfs cleanup action: %d\n", error); return error; } diff --git a/drivers/input/touchscreen/s3c2410_ts.c b/drivers/input/touchscreen/s3c2410_ts.c index a4a103e1d11b..41d58e88cc8a 100644 --- a/drivers/input/touchscreen/s3c2410_ts.c +++ b/drivers/input/touchscreen/s3c2410_ts.c @@ -250,7 +250,7 @@ static int s3c2410ts_probe(struct platform_device *pdev) ts.dev = dev; - info = dev_get_platdata(&pdev->dev); + info = dev_get_platdata(dev); if (!info) { dev_err(dev, "no platform data, cannot attach\n"); return -EINVAL; From de3a00ef21d6e803ee7c674c76a269016a1b308c Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:47:44 -0800 Subject: [PATCH 46/91] Input: keyboard - drop unnecessary calls to device_init_wakeup Calling device_init_wakeup in the remove function is unnecessary since the device is going away, and thus won't be able to cause any wakeups under any circumstances. Besides, the driver cleanup code already handles the necessary cleanup. Similarly, disabling wakeup in the probe error path is unnecessary, as is disabling wakeup in the probe function in the first place. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/gpio_keys.c | 2 -- drivers/input/keyboard/matrix_keypad.c | 2 -- drivers/input/keyboard/omap4-keypad.c | 3 --- drivers/input/keyboard/samsung-keypad.c | 2 -- drivers/input/keyboard/spear-keyboard.c | 2 -- 5 files changed, 11 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 50b19b952698..9c92cdf196e3 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -845,8 +845,6 @@ static int gpio_keys_remove(struct platform_device *pdev) { sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group); - device_init_wakeup(&pdev->dev, 0); - return 0; } diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 7f12b6579f82..18839cd5f76e 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -545,8 +545,6 @@ static int matrix_keypad_remove(struct platform_device *pdev) { struct matrix_keypad *keypad = platform_get_drvdata(pdev); - device_init_wakeup(&pdev->dev, 0); - matrix_keypad_free_gpio(keypad); input_unregister_device(keypad->input_dev); kfree(keypad); diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index 6639b2b8528a..9ecb16701b13 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -375,7 +375,6 @@ static int omap4_keypad_probe(struct platform_device *pdev) err_pm_disable: pm_runtime_disable(&pdev->dev); - device_init_wakeup(&pdev->dev, false); free_irq(keypad_data->irq, keypad_data); err_free_keymap: kfree(keypad_data->keymap); @@ -401,8 +400,6 @@ static int omap4_keypad_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); - device_init_wakeup(&pdev->dev, false); - input_unregister_device(keypad_data->input); iounmap(keypad_data->base); diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c index 4e319eb9e19d..316414465c77 100644 --- a/drivers/input/keyboard/samsung-keypad.c +++ b/drivers/input/keyboard/samsung-keypad.c @@ -445,7 +445,6 @@ static int samsung_keypad_probe(struct platform_device *pdev) err_disable_runtime_pm: pm_runtime_disable(&pdev->dev); - device_init_wakeup(&pdev->dev, 0); err_unprepare_clk: clk_unprepare(keypad->clk); return error; @@ -456,7 +455,6 @@ static int samsung_keypad_remove(struct platform_device *pdev) struct samsung_keypad *keypad = platform_get_drvdata(pdev); pm_runtime_disable(&pdev->dev); - device_init_wakeup(&pdev->dev, 0); input_unregister_device(keypad->input_dev); diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c index 8083eaa0524a..7d25fa338ab4 100644 --- a/drivers/input/keyboard/spear-keyboard.c +++ b/drivers/input/keyboard/spear-keyboard.c @@ -283,8 +283,6 @@ static int spear_kbd_remove(struct platform_device *pdev) input_unregister_device(kbd->input); clk_unprepare(kbd->clk); - device_init_wakeup(&pdev->dev, 0); - return 0; } From 56580c2cb7d72e2176136b8146bcc6a527d8ac38 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:48:45 -0800 Subject: [PATCH 47/91] Input: misc - drop unnecessary calls to device_init_wakeup Calling device_init_wakeup in the remove function is unnecessary since the device is going away, and thus won't be able to cause any wakeups under any circumstances. Besides, the driver cleanup code already handles the necessary cleanup. Similarly, disabling wakeup in the probe error path is unnecessary, as is disabling wakeup in the probe function in the first place. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/88pm80x_onkey.c | 1 - drivers/input/misc/e3x0-button.c | 1 - drivers/input/misc/gp2ap002a00f.c | 2 -- drivers/input/misc/hisi_powerkey.c | 2 -- drivers/input/misc/pm8941-pwrkey.c | 1 - drivers/input/misc/pmic8xxx-pwrkey.c | 2 -- drivers/input/misc/sirfsoc-onkey.c | 2 -- 7 files changed, 11 deletions(-) diff --git a/drivers/input/misc/88pm80x_onkey.c b/drivers/input/misc/88pm80x_onkey.c index cf9908f1e5d5..45a09497f680 100644 --- a/drivers/input/misc/88pm80x_onkey.c +++ b/drivers/input/misc/88pm80x_onkey.c @@ -143,7 +143,6 @@ static int pm80x_onkey_remove(struct platform_device *pdev) { struct pm80x_onkey_info *info = platform_get_drvdata(pdev); - device_init_wakeup(&pdev->dev, 0); pm80x_free_irq(info->pm80x, info->irq, info); input_unregister_device(info->idev); kfree(info); diff --git a/drivers/input/misc/e3x0-button.c b/drivers/input/misc/e3x0-button.c index b0b374112db3..1e50314db1ab 100644 --- a/drivers/input/misc/e3x0-button.c +++ b/drivers/input/misc/e3x0-button.c @@ -126,7 +126,6 @@ static int e3x0_button_probe(struct platform_device *pdev) static int e3x0_button_remove(struct platform_device *pdev) { - device_init_wakeup(&pdev->dev, 0); return 0; } diff --git a/drivers/input/misc/gp2ap002a00f.c b/drivers/input/misc/gp2ap002a00f.c index 3bfdfcc20485..c6a29e57b5e4 100644 --- a/drivers/input/misc/gp2ap002a00f.c +++ b/drivers/input/misc/gp2ap002a00f.c @@ -210,8 +210,6 @@ static int gp2a_remove(struct i2c_client *client) struct gp2a_data *dt = i2c_get_clientdata(client); const struct gp2a_platform_data *pdata = dt->pdata; - device_init_wakeup(&client->dev, false); - free_irq(client->irq, dt); input_unregister_device(dt->input); diff --git a/drivers/input/misc/hisi_powerkey.c b/drivers/input/misc/hisi_powerkey.c index c4c42124a059..baa81dccfc1f 100644 --- a/drivers/input/misc/hisi_powerkey.c +++ b/drivers/input/misc/hisi_powerkey.c @@ -122,8 +122,6 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) static int hi65xx_powerkey_remove(struct platform_device *pdev) { - device_init_wakeup(&pdev->dev, 0); - return 0; } diff --git a/drivers/input/misc/pm8941-pwrkey.c b/drivers/input/misc/pm8941-pwrkey.c index e317b75357a0..18ad956454f1 100644 --- a/drivers/input/misc/pm8941-pwrkey.c +++ b/drivers/input/misc/pm8941-pwrkey.c @@ -266,7 +266,6 @@ static int pm8941_pwrkey_remove(struct platform_device *pdev) { struct pm8941_pwrkey *pwrkey = platform_get_drvdata(pdev); - device_init_wakeup(&pdev->dev, 0); unregister_reboot_notifier(&pwrkey->reboot_notifier); return 0; diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c index 67aab86048ad..c75be2dd00e7 100644 --- a/drivers/input/misc/pmic8xxx-pwrkey.c +++ b/drivers/input/misc/pmic8xxx-pwrkey.c @@ -440,8 +440,6 @@ static int pmic8xxx_pwrkey_probe(struct platform_device *pdev) static int pmic8xxx_pwrkey_remove(struct platform_device *pdev) { - device_init_wakeup(&pdev->dev, 0); - return 0; } diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c index ed7237f19539..a2ed0e4fcd0b 100644 --- a/drivers/input/misc/sirfsoc-onkey.c +++ b/drivers/input/misc/sirfsoc-onkey.c @@ -174,8 +174,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev) static int sirfsoc_pwrc_remove(struct platform_device *pdev) { - device_init_wakeup(&pdev->dev, 0); - return 0; } From 8e1b4d83cf8b0e62f5a45792d07f027783c1a07c Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:49:13 -0800 Subject: [PATCH 48/91] Input: touchscreen - drop unnecessary calls to device_init_wakeup Calling device_init_wakeup in the remove function is unnecessary since the device is going away, and thus won't be able to cause any wakeups under any circumstances. Besides, the driver cleanup code already handles the necessary cleanup. Similarly, disabling wakeup in the probe error path is unnecessary, as is disabling wakeup in the probe function in the first place. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/ads7846.c | 2 -- drivers/input/touchscreen/bu21013_ts.c | 2 -- drivers/input/touchscreen/eeti_ts.c | 1 - drivers/input/touchscreen/lpc32xx_ts.c | 1 - drivers/input/touchscreen/st1232.c | 1 - 5 files changed, 7 deletions(-) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 1ce3ecbe37f8..f5793e3d945f 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -1462,8 +1462,6 @@ static int ads7846_remove(struct spi_device *spi) { struct ads7846 *ts = spi_get_drvdata(spi); - device_init_wakeup(&spi->dev, false); - sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); ads7846_disable(ts); diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c index 931417eb4f5a..4fa5da8d5fa8 100644 --- a/drivers/input/touchscreen/bu21013_ts.c +++ b/drivers/input/touchscreen/bu21013_ts.c @@ -637,8 +637,6 @@ static int bu21013_remove(struct i2c_client *client) kfree(bu21013_data); - device_init_wakeup(&client->dev, false); - return 0; } diff --git a/drivers/input/touchscreen/eeti_ts.c b/drivers/input/touchscreen/eeti_ts.c index fa974579eb41..16023867b9da 100644 --- a/drivers/input/touchscreen/eeti_ts.c +++ b/drivers/input/touchscreen/eeti_ts.c @@ -231,7 +231,6 @@ static int eeti_ts_probe(struct i2c_client *client, */ eeti_ts_stop(priv); - device_init_wakeup(&client->dev, 0); return 0; err3: diff --git a/drivers/input/touchscreen/lpc32xx_ts.c b/drivers/input/touchscreen/lpc32xx_ts.c index 7fbb3b0c8571..e0baa7de4102 100644 --- a/drivers/input/touchscreen/lpc32xx_ts.c +++ b/drivers/input/touchscreen/lpc32xx_ts.c @@ -313,7 +313,6 @@ static int lpc32xx_ts_remove(struct platform_device *pdev) struct lpc32xx_tsc *tsc = platform_get_drvdata(pdev); struct resource *res; - device_init_wakeup(&pdev->dev, 0); free_irq(tsc->irq, tsc); input_unregister_device(tsc->dev); diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index e943678ce54c..be5615c6bf8f 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -237,7 +237,6 @@ static int st1232_ts_remove(struct i2c_client *client) { struct st1232_ts_data *ts = i2c_get_clientdata(client); - device_init_wakeup(&client->dev, 0); st1232_ts_power(ts, false); return 0; From f20b161f59b73d40043199b3bff362e656a9c673 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:49:38 -0800 Subject: [PATCH 49/91] Input: serio - drop unnecessary calls to device_init_wakeup Calling device_init_wakeup in the remove function is unnecessary since the device is going away, and thus won't be able to cause any wakeups under any circumstances. Besides, the driver cleanup code already handles the necessary cleanup. Similarly, disabling wakeup in the probe error path is unnecessary, as is disabling wakeup in the probe function in the first place. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/serio/hyperv-keyboard.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c index c948866edf87..25151d9214e0 100644 --- a/drivers/input/serio/hyperv-keyboard.c +++ b/drivers/input/serio/hyperv-keyboard.c @@ -402,7 +402,6 @@ static int hv_kbd_remove(struct hv_device *hv_dev) { struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev); - device_init_wakeup(&hv_dev->device, false); serio_unregister_port(kbd_dev->hv_serio); vmbus_close(hv_dev->channel); kfree(kbd_dev); From 8010e0db7071bdcd0fbd47983e88990d6ce979fb Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:50:09 -0800 Subject: [PATCH 50/91] Input: misc - drop empty remove functions Empty remove functions don't serve a useful purpose and can be removed. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/e3x0-button.c | 6 ------ drivers/input/misc/hisi_powerkey.c | 6 ------ drivers/input/misc/pmic8xxx-pwrkey.c | 6 ------ drivers/input/misc/retu-pwrbutton.c | 6 ------ drivers/input/misc/sirfsoc-onkey.c | 6 ------ 5 files changed, 30 deletions(-) diff --git a/drivers/input/misc/e3x0-button.c b/drivers/input/misc/e3x0-button.c index 1e50314db1ab..e956cf1d273f 100644 --- a/drivers/input/misc/e3x0-button.c +++ b/drivers/input/misc/e3x0-button.c @@ -124,11 +124,6 @@ static int e3x0_button_probe(struct platform_device *pdev) return 0; } -static int e3x0_button_remove(struct platform_device *pdev) -{ - return 0; -} - #ifdef CONFIG_OF static const struct of_device_id e3x0_button_match[] = { { .compatible = "ettus,e3x0-button", }, @@ -144,7 +139,6 @@ static struct platform_driver e3x0_button_driver = { .pm = &e3x0_button_pm_ops, }, .probe = e3x0_button_probe, - .remove = e3x0_button_remove, }; module_platform_driver(e3x0_button_driver); diff --git a/drivers/input/misc/hisi_powerkey.c b/drivers/input/misc/hisi_powerkey.c index baa81dccfc1f..dee6245f38d7 100644 --- a/drivers/input/misc/hisi_powerkey.c +++ b/drivers/input/misc/hisi_powerkey.c @@ -120,17 +120,11 @@ static int hi65xx_powerkey_probe(struct platform_device *pdev) return 0; } -static int hi65xx_powerkey_remove(struct platform_device *pdev) -{ - return 0; -} - static struct platform_driver hi65xx_powerkey_driver = { .driver = { .name = "hi65xx-powerkey", }, .probe = hi65xx_powerkey_probe, - .remove = hi65xx_powerkey_remove, }; module_platform_driver(hi65xx_powerkey_driver); diff --git a/drivers/input/misc/pmic8xxx-pwrkey.c b/drivers/input/misc/pmic8xxx-pwrkey.c index c75be2dd00e7..73323b0c72c1 100644 --- a/drivers/input/misc/pmic8xxx-pwrkey.c +++ b/drivers/input/misc/pmic8xxx-pwrkey.c @@ -438,11 +438,6 @@ static int pmic8xxx_pwrkey_probe(struct platform_device *pdev) return 0; } -static int pmic8xxx_pwrkey_remove(struct platform_device *pdev) -{ - return 0; -} - static const struct of_device_id pm8xxx_pwr_key_id_table[] = { { .compatible = "qcom,pm8058-pwrkey", .data = &pm8058_pwrkey_shutdown }, { .compatible = "qcom,pm8921-pwrkey", .data = &pm8921_pwrkey_shutdown }, @@ -452,7 +447,6 @@ MODULE_DEVICE_TABLE(of, pm8xxx_pwr_key_id_table); static struct platform_driver pmic8xxx_pwrkey_driver = { .probe = pmic8xxx_pwrkey_probe, - .remove = pmic8xxx_pwrkey_remove, .shutdown = pmic8xxx_pwrkey_shutdown, .driver = { .name = "pm8xxx-pwrkey", diff --git a/drivers/input/misc/retu-pwrbutton.c b/drivers/input/misc/retu-pwrbutton.c index 30b459b6b344..64023ac08e2b 100644 --- a/drivers/input/misc/retu-pwrbutton.c +++ b/drivers/input/misc/retu-pwrbutton.c @@ -76,14 +76,8 @@ static int retu_pwrbutton_probe(struct platform_device *pdev) return 0; } -static int retu_pwrbutton_remove(struct platform_device *pdev) -{ - return 0; -} - static struct platform_driver retu_pwrbutton_driver = { .probe = retu_pwrbutton_probe, - .remove = retu_pwrbutton_remove, .driver = { .name = "retu-pwrbutton", }, diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c index a2ed0e4fcd0b..4fd038d476a3 100644 --- a/drivers/input/misc/sirfsoc-onkey.c +++ b/drivers/input/misc/sirfsoc-onkey.c @@ -172,11 +172,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev) return 0; } -static int sirfsoc_pwrc_remove(struct platform_device *pdev) -{ - return 0; -} - static int __maybe_unused sirfsoc_pwrc_resume(struct device *dev) { struct sirfsoc_pwrc_drvdata *pwrcdrv = dev_get_drvdata(dev); @@ -198,7 +193,6 @@ static SIMPLE_DEV_PM_OPS(sirfsoc_pwrc_pm_ops, NULL, sirfsoc_pwrc_resume); static struct platform_driver sirfsoc_pwrc_driver = { .probe = sirfsoc_pwrc_probe, - .remove = sirfsoc_pwrc_remove, .driver = { .name = "sirfsoc-pwrc", .pm = &sirfsoc_pwrc_pm_ops, From ed77bdf4e4bea810014cdf68b771bcbe3d47163f Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 21 Jan 2017 23:46:16 -0800 Subject: [PATCH 51/91] Input: synaptics-rmi4 - use local variables consistently If a function declares a variable to access a structure element, use it conssistently. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_bus.c | 4 ++-- drivers/input/rmi4/rmi_driver.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c index df97d8679bad..8f4ca8691a69 100644 --- a/drivers/input/rmi4/rmi_bus.c +++ b/drivers/input/rmi4/rmi_bus.c @@ -262,10 +262,10 @@ int __rmi_register_function_handler(struct rmi_function_handler *handler, driver->probe = rmi_function_probe; driver->remove = rmi_function_remove; - error = driver_register(&handler->driver); + error = driver_register(driver); if (error) { pr_err("driver_register() failed for %s, error: %d\n", - handler->driver.name, error); + driver->name, error); return error; } diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index cb6efe693302..30397cc7283a 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -837,7 +837,7 @@ static int rmi_create_function(struct rmi_device *rmi_dev, void *ctx, const struct pdt_entry *pdt) { struct device *dev = &rmi_dev->dev; - struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); + struct rmi_driver_data *data = dev_get_drvdata(dev); int *current_irq_count = ctx; struct rmi_function *fn; int i; @@ -1041,7 +1041,7 @@ int rmi_probe_interrupts(struct rmi_driver_data *data) } if (data->bootloader_mode) - dev_warn(&rmi_dev->dev, "Device in bootloader mode.\n"); + dev_warn(dev, "Device in bootloader mode.\n"); data->irq_count = irq_count; data->num_of_irq_regs = (data->irq_count + 7) / 8; From 2031717544cab77b9b6fd8c33fd24cbbe2f607b6 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 6 Jan 2017 09:48:20 -0800 Subject: [PATCH 52/91] Input: pwm-beeper - remove calls to legacy pwm_request API There are no more users of pwm-beeper driver in mainline relying on this legacy API, so let's remove it and simplify the driver code. Acked-by: Thierry Reding Tested-by: David Lechner Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 5f9655d49a65..cb87e475bd23 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -95,7 +95,6 @@ static void pwm_beeper_close(struct input_dev *input) static int pwm_beeper_probe(struct platform_device *pdev) { - unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev); struct pwm_beeper *beeper; int error; @@ -104,11 +103,6 @@ static int pwm_beeper_probe(struct platform_device *pdev) return -ENOMEM; beeper->pwm = pwm_get(&pdev->dev, NULL); - if (IS_ERR(beeper->pwm)) { - dev_dbg(&pdev->dev, "unable to request PWM, trying legacy API\n"); - beeper->pwm = pwm_request(pwm_id, "pwm beeper"); - } - if (IS_ERR(beeper->pwm)) { error = PTR_ERR(beeper->pwm); dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error); From bcf4b0460ba558b1e1fcaa7c160076751b560d03 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 6 Jan 2017 09:50:14 -0800 Subject: [PATCH 53/91] Input: pwm-beeper - switch to using managed resources Use of managed resources (devm) simplifies error handling and tear down of the driver. Reviewed-by: Thierry Reding Tested-by: David Lechner Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 44 ++++++++------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index cb87e475bd23..f8b163b0eb43 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -95,18 +95,19 @@ static void pwm_beeper_close(struct input_dev *input) static int pwm_beeper_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct pwm_beeper *beeper; int error; - beeper = kzalloc(sizeof(*beeper), GFP_KERNEL); + beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); if (!beeper) return -ENOMEM; - beeper->pwm = pwm_get(&pdev->dev, NULL); + beeper->pwm = devm_pwm_get(dev, NULL); if (IS_ERR(beeper->pwm)) { error = PTR_ERR(beeper->pwm); - dev_err(&pdev->dev, "Failed to request pwm device: %d\n", error); - goto err_free; + dev_err(dev, "Failed to request PWM device: %d\n", error); + return error; } /* @@ -117,13 +118,11 @@ static int pwm_beeper_probe(struct platform_device *pdev) INIT_WORK(&beeper->work, pwm_beeper_work); - beeper->input = input_allocate_device(); + beeper->input = devm_input_allocate_device(dev); if (!beeper->input) { - dev_err(&pdev->dev, "Failed to allocate input device\n"); - error = -ENOMEM; - goto err_pwm_free; + dev_err(dev, "Failed to allocate input device\n"); + return -ENOMEM; } - beeper->input->dev.parent = &pdev->dev; beeper->input->name = "pwm-beeper"; beeper->input->phys = "pwm/input0"; @@ -142,34 +141,12 @@ static int pwm_beeper_probe(struct platform_device *pdev) error = input_register_device(beeper->input); if (error) { - dev_err(&pdev->dev, "Failed to register input device: %d\n", error); - goto err_input_free; + dev_err(dev, "Failed to register input device: %d\n", error); + return error; } platform_set_drvdata(pdev, beeper); - return 0; - -err_input_free: - input_free_device(beeper->input); -err_pwm_free: - pwm_free(beeper->pwm); -err_free: - kfree(beeper); - - return error; -} - -static int pwm_beeper_remove(struct platform_device *pdev) -{ - struct pwm_beeper *beeper = platform_get_drvdata(pdev); - - input_unregister_device(beeper->input); - - pwm_free(beeper->pwm); - - kfree(beeper); - return 0; } @@ -205,7 +182,6 @@ MODULE_DEVICE_TABLE(of, pwm_beeper_match); static struct platform_driver pwm_beeper_driver = { .probe = pwm_beeper_probe, - .remove = pwm_beeper_remove, .driver = { .name = "pwm-beeper", .pm = &pwm_beeper_pm_ops, From 48a55d7de79f95176f3ab372be66165a60be222f Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 6 Jan 2017 09:54:14 -0800 Subject: [PATCH 54/91] Input: pwm-beeper - use input_set_capability() Instead of manipulating capability bits directly, let's use input_set_capability() API. Reviewed-by: Thierry Reding Tested-by: David Lechner Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index f8b163b0eb43..58a60b42c836 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -131,8 +131,8 @@ static int pwm_beeper_probe(struct platform_device *pdev) beeper->input->id.product = 0x0001; beeper->input->id.version = 0x0100; - beeper->input->evbit[0] = BIT(EV_SND); - beeper->input->sndbit[0] = BIT(SND_TONE) | BIT(SND_BELL); + input_set_capability(beeper->input, EV_SND, SND_TONE); + input_set_capability(beeper->input, EV_SND, SND_BELL); beeper->input->event = pwm_beeper_event; beeper->input->close = pwm_beeper_close; From e9728f0dd7dc06fb0f0d18552ab9599005cd2ab7 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 19 Jan 2017 11:13:37 -0800 Subject: [PATCH 55/91] Input: pwm-beeper - fix race when suspending Usually userspace sends SND_BELL and SND_TONE events, and by the time pwm_beeper_suspend() runs userpsace is already frozen, but theoretically in-kernel users may send these events too, and that may cause pwm_beeper_event() scheduling another work after we canceled it. Let's introduce a "suspended" flag and check it in pwm_beeper_event() to avoid this race. Reviewed-by: Thierry Reding Tested-by: David Lechner Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 58a60b42c836..9d7987d9ba1b 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -27,6 +27,7 @@ struct pwm_beeper { struct pwm_device *pwm; struct work_struct work; unsigned long period; + bool suspended; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) @@ -73,7 +74,8 @@ static int pwm_beeper_event(struct input_dev *input, else beeper->period = HZ_TO_NANOSECONDS(value); - schedule_work(&beeper->work); + if (!beeper->suspended) + schedule_work(&beeper->work); return 0; } @@ -154,6 +156,15 @@ static int __maybe_unused pwm_beeper_suspend(struct device *dev) { struct pwm_beeper *beeper = dev_get_drvdata(dev); + /* + * Spinlock is taken here is not to protect write to + * beeper->suspended, but to ensure that pwm_beeper_event + * does not re-submit work once flag is set. + */ + spin_lock_irq(&beeper->input->event_lock); + beeper->suspended = true; + spin_unlock_irq(&beeper->input->event_lock); + pwm_beeper_stop(beeper); return 0; @@ -163,8 +174,12 @@ static int __maybe_unused pwm_beeper_resume(struct device *dev) { struct pwm_beeper *beeper = dev_get_drvdata(dev); - if (beeper->period) - __pwm_beeper_set(beeper); + spin_lock_irq(&beeper->input->event_lock); + beeper->suspended = false; + spin_unlock_irq(&beeper->input->event_lock); + + /* Let worker figure out if we should resume beeping */ + schedule_work(&beeper->work); return 0; } From 62481881401246859d9bd06b7c7b9a391c78892c Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 6 Jan 2017 10:35:16 -0800 Subject: [PATCH 56/91] Input: pwm-beeper - suppress error message on probe defer This suppress printing an error message when pwm_get returns -EPROBE_DEFER. Otherwise you get a bunch of noise in the kernel log. Signed-off-by: David Lechner Reviewed-by: Thierry Reding Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 9d7987d9ba1b..069d594554bd 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -108,7 +108,9 @@ static int pwm_beeper_probe(struct platform_device *pdev) beeper->pwm = devm_pwm_get(dev, NULL); if (IS_ERR(beeper->pwm)) { error = PTR_ERR(beeper->pwm); - dev_err(dev, "Failed to request PWM device: %d\n", error); + if (error != -EPROBE_DEFER) + dev_err(dev, "Failed to request PWM device: %d\n", + error); return error; } From 9e54924432783bfb21e905e0bf7042556bcb4b90 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 15 Jan 2017 17:09:43 -0800 Subject: [PATCH 57/91] Input: pwm-beeper - add optional amplifier regulator This adds an optional regulator to the pwm-beeper device. This regulator acts as an amplifier. The amplifier is only enabled while beeping in order to reduce power consumption. Tested on LEGO MINDSTORMS EV3, which has a speaker connected to PWM through an amplifier. Signed-off-by: David Lechner Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../devicetree/bindings/input/pwm-beeper.txt | 16 +++++ drivers/input/misc/pwm-beeper.c | 63 +++++++++++++++---- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt index be332ae4f2d6..529408b4431a 100644 --- a/Documentation/devicetree/bindings/input/pwm-beeper.txt +++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt @@ -5,3 +5,19 @@ Registers a PWM device as beeper. Required properties: - compatible: should be "pwm-beeper" - pwms: phandle to the physical PWM device + +Optional properties: +- amp-supply: phandle to a regulator that acts as an amplifier for the beeper + +Example: + +beeper_amp: amplifier { + compatible = "fixed-regulator"; + gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>; +}; + +beeper { + compatible = "pwm-beeper"; + pwms = <&pwm0>; + amp-supply = <&beeper_amp>; +}; diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 069d594554bd..ad9b231e8468 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -25,30 +26,59 @@ struct pwm_beeper { struct input_dev *input; struct pwm_device *pwm; + struct regulator *amplifier; struct work_struct work; unsigned long period; bool suspended; + bool amplifier_on; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) -static void __pwm_beeper_set(struct pwm_beeper *beeper) +static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) { - unsigned long period = beeper->period; + int error; - if (period) { - pwm_config(beeper->pwm, period / 2, period); - pwm_enable(beeper->pwm); - } else - pwm_disable(beeper->pwm); + error = pwm_config(beeper->pwm, period / 2, period); + if (error) + return error; + + error = pwm_enable(beeper->pwm); + if (error) + return error; + + if (!beeper->amplifier_on) { + error = regulator_enable(beeper->amplifier); + if (error) { + pwm_disable(beeper->pwm); + return error; + } + + beeper->amplifier_on = true; + } + + return 0; +} + +static void pwm_beeper_off(struct pwm_beeper *beeper) +{ + if (beeper->amplifier_on) { + regulator_disable(beeper->amplifier); + beeper->amplifier_on = false; + } + + pwm_disable(beeper->pwm); } static void pwm_beeper_work(struct work_struct *work) { - struct pwm_beeper *beeper = - container_of(work, struct pwm_beeper, work); + struct pwm_beeper *beeper = container_of(work, struct pwm_beeper, work); + unsigned long period = READ_ONCE(beeper->period); - __pwm_beeper_set(beeper); + if (period) + pwm_beeper_on(beeper, period); + else + pwm_beeper_off(beeper); } static int pwm_beeper_event(struct input_dev *input, @@ -83,9 +113,7 @@ static int pwm_beeper_event(struct input_dev *input, static void pwm_beeper_stop(struct pwm_beeper *beeper) { cancel_work_sync(&beeper->work); - - if (beeper->period) - pwm_disable(beeper->pwm); + pwm_beeper_off(beeper); } static void pwm_beeper_close(struct input_dev *input) @@ -120,6 +148,15 @@ static int pwm_beeper_probe(struct platform_device *pdev) */ pwm_apply_args(beeper->pwm); + beeper->amplifier = devm_regulator_get(dev, "amp"); + if (IS_ERR(beeper->amplifier)) { + error = PTR_ERR(beeper->amplifier); + if (error != -EPROBE_DEFER) + dev_err(dev, "Failed to get 'amp' regulator: %d\n", + error); + return error; + } + INIT_WORK(&beeper->work, pwm_beeper_work); beeper->input = devm_input_allocate_device(dev); From 2de8b4110c82c243530a68381a1c39a4fe05c14f Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 19 Jan 2017 13:52:49 -0800 Subject: [PATCH 58/91] Input: pwm-beeper - switch to using "atomic" PWM API The "atomic" API allows us to configure PWM period and duty cycle and enable it in one call. Reviewed-by: Thierry Reding Tested-by: David Lechner Signed-off-by: Dmitry Torokhov --- drivers/input/misc/pwm-beeper.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index ad9b231e8468..e53801dbd560 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -37,13 +37,16 @@ struct pwm_beeper { static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) { + struct pwm_state state; int error; - error = pwm_config(beeper->pwm, period / 2, period); - if (error) - return error; + pwm_get_state(beeper->pwm, &state); - error = pwm_enable(beeper->pwm); + state.enabled = true; + state.period = period; + pwm_set_relative_duty_cycle(&state, 50, 100); + + error = pwm_apply_state(beeper->pwm, &state); if (error) return error; @@ -127,6 +130,7 @@ static int pwm_beeper_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct pwm_beeper *beeper; + struct pwm_state state; int error; beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); @@ -142,11 +146,15 @@ static int pwm_beeper_probe(struct platform_device *pdev) return error; } - /* - * FIXME: pwm_apply_args() should be removed when switching to - * the atomic PWM API. - */ - pwm_apply_args(beeper->pwm); + /* Sync up PWM state and ensure it is off. */ + pwm_init_state(beeper->pwm, &state); + state.enabled = false; + error = pwm_apply_state(beeper->pwm, &state); + if (error) { + dev_err(dev, "failed to apply initial PWM state: %d\n", + error); + return error; + } beeper->amplifier = devm_regulator_get(dev, "amp"); if (IS_ERR(beeper->amplifier)) { From a5e5da2b6f129d2a4f7a3f0b73dba2f6f63208ef Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sat, 21 Jan 2017 23:36:05 -0800 Subject: [PATCH 59/91] Input: max11801_ts - drop call to input_set_drvdata() Nobody calls input_get_drvdata() so setting it is not required. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/max11801_ts.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/touchscreen/max11801_ts.c b/drivers/input/touchscreen/max11801_ts.c index d87b89da114e..a595ae5284e3 100644 --- a/drivers/input/touchscreen/max11801_ts.c +++ b/drivers/input/touchscreen/max11801_ts.c @@ -199,7 +199,6 @@ static int max11801_ts_probe(struct i2c_client *client, __set_bit(BTN_TOUCH, input_dev->keybit); input_set_abs_params(input_dev, ABS_X, 0, MAX11801_MAX_X, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, MAX11801_MAX_Y, 0, 0); - input_set_drvdata(input_dev, data); max11801_ts_phy_init(data); From 2ea9c2362b562e227a944e0ae370c9868024884e Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Sun, 22 Jan 2017 14:29:22 -0800 Subject: [PATCH 60/91] Input: i8042 - add dbg msg when a command can't write its parameter This can happen in cases like bug #102951[1], so add a proper debug msg as done in wait_read. Also, change wait_read debug message to differ from wait_write. [1] https://bugzilla.kernel.org/show_bug.cgi?id=102951 Signed-off-by: Marcos Paulo de Souza Signed-off-by: Dmitry Torokhov --- drivers/input/serio/i8042.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index 62685a768913..c52da651269b 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -312,8 +312,10 @@ static int __i8042_command(unsigned char *param, int command) for (i = 0; i < ((command >> 12) & 0xf); i++) { error = i8042_wait_write(); - if (error) + if (error) { + dbg(" -- i8042 (wait write timeout)\n"); return error; + } dbg("%02x -> i8042 (parameter)\n", param[i]); i8042_write_data(param[i]); } @@ -321,7 +323,7 @@ static int __i8042_command(unsigned char *param, int command) for (i = 0; i < ((command >> 8) & 0xf); i++) { error = i8042_wait_read(); if (error) { - dbg(" -- i8042 (timeout)\n"); + dbg(" -- i8042 (wait read timeout)\n"); return error; } From 14fdb924afd9290d43e64eeb2377d51806de1197 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 22 Jan 2017 17:17:40 -0800 Subject: [PATCH 61/91] Input: keyboard - drop unnecessary calls to input_set_drvdata If there is no call to dev_get_drvdata() or input_get_drvdata(), the call to input_set_drvdata() is unnecessary and can be dropped. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/adp5520-keys.c | 2 -- drivers/input/keyboard/bf54x-keys.c | 2 -- drivers/input/keyboard/maple_keyb.c | 1 - drivers/input/keyboard/opencores-kbd.c | 2 -- drivers/input/keyboard/tca8418_keypad.c | 2 -- drivers/input/keyboard/tm2-touchkey.c | 2 -- 6 files changed, 11 deletions(-) diff --git a/drivers/input/keyboard/adp5520-keys.c b/drivers/input/keyboard/adp5520-keys.c index db1004dad108..f0b9b37bde58 100644 --- a/drivers/input/keyboard/adp5520-keys.c +++ b/drivers/input/keyboard/adp5520-keys.c @@ -107,8 +107,6 @@ static int adp5520_keys_probe(struct platform_device *pdev) input->phys = "adp5520-keys/input0"; input->dev.parent = &pdev->dev; - input_set_drvdata(input, dev); - input->id.bustype = BUS_I2C; input->id.vendor = 0x0001; input->id.product = 0x5520; diff --git a/drivers/input/keyboard/bf54x-keys.c b/drivers/input/keyboard/bf54x-keys.c index 81b07dddae86..39bcbc38997f 100644 --- a/drivers/input/keyboard/bf54x-keys.c +++ b/drivers/input/keyboard/bf54x-keys.c @@ -268,8 +268,6 @@ static int bfin_kpad_probe(struct platform_device *pdev) input->phys = "bf54x-keys/input0"; input->dev.parent = &pdev->dev; - input_set_drvdata(input, bf54x_kpad); - input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c index 5aa2361aef95..78e3567ec18c 100644 --- a/drivers/input/keyboard/maple_keyb.c +++ b/drivers/input/keyboard/maple_keyb.c @@ -196,7 +196,6 @@ static int probe_maple_kbd(struct device *dev) __clear_bit(KEY_RESERVED, idev->keybit); input_set_capability(idev, EV_MSC, MSC_SCAN); - input_set_drvdata(idev, kbd); error = input_register_device(idev); if (error) diff --git a/drivers/input/keyboard/opencores-kbd.c b/drivers/input/keyboard/opencores-kbd.c index 98ea6190f5f5..d62b4068c077 100644 --- a/drivers/input/keyboard/opencores-kbd.c +++ b/drivers/input/keyboard/opencores-kbd.c @@ -75,8 +75,6 @@ static int opencores_kbd_probe(struct platform_device *pdev) input->name = pdev->name; input->phys = "opencores-kbd/input0"; - input_set_drvdata(input, opencores_kbd); - input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c index 11d5c76d9fb4..9f6308fac0b4 100644 --- a/drivers/input/keyboard/tca8418_keypad.c +++ b/drivers/input/keyboard/tca8418_keypad.c @@ -358,8 +358,6 @@ static int tca8418_keypad_probe(struct i2c_client *client, __set_bit(EV_REP, input->evbit); input_set_capability(input, EV_MSC, MSC_SCAN); - input_set_drvdata(input, keypad_data); - irq = client->irq; if (irq_is_gpio) irq = gpio_to_irq(irq); diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c index 916e2f3a9bbb..485900f953e0 100644 --- a/drivers/input/keyboard/tm2-touchkey.c +++ b/drivers/input/keyboard/tm2-touchkey.c @@ -193,8 +193,6 @@ static int tm2_touchkey_probe(struct i2c_client *client, input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE); input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK); - input_set_drvdata(touchkey->input_dev, touchkey); - error = input_register_device(touchkey->input_dev); if (error) { dev_err(&client->dev, From 0ff44b0fd35c4bb1c2ec3d94043a465ff15b3099 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 22 Jan 2017 17:18:04 -0800 Subject: [PATCH 62/91] Input: maplecontrol - drop unnecessary call to input_set_drvdata Since there is no call to dev_get_drvdata() or input_get_drvdata(), the call to input_set_drvdata() is unnecessary and can be dropped. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/maplecontrol.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/input/joystick/maplecontrol.c b/drivers/input/joystick/maplecontrol.c index 8aa6e4c497da..ff54e195d42c 100644 --- a/drivers/input/joystick/maplecontrol.c +++ b/drivers/input/joystick/maplecontrol.c @@ -139,7 +139,6 @@ static int probe_maple_controller(struct device *dev) idev->dev.parent = &mdev->dev; idev->name = mdev->product_name; idev->id.bustype = BUS_HOST; - input_set_drvdata(idev, pad); error = input_register_device(idev); if (error) From 555c765b0cc29119f4ff767334c479040587a1d6 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 22 Jan 2017 17:18:24 -0800 Subject: [PATCH 63/91] Input: mouse - drop unnecessary calls to input_set_drvdata Since there is no call to dev_get_drvdata() or input_get_drvdata(), the call to input_set_drvdata() is unnecessary and can be dropped. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 2 -- drivers/input/mouse/maplemouse.c | 1 - 2 files changed, 3 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index faa3a980d4f5..21bad3e75fee 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -414,8 +414,6 @@ static int cypress_set_input_params(struct input_dev *input, __set_bit(BTN_RIGHT, input->keybit); __set_bit(BTN_MIDDLE, input->keybit); - input_set_drvdata(input, cytp); - return 0; } diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c index 0a60717b91c6..25f0ecb90126 100644 --- a/drivers/input/mouse/maplemouse.c +++ b/drivers/input/mouse/maplemouse.c @@ -87,7 +87,6 @@ static int probe_maple_mouse(struct device *dev) mse->dev = input_dev; mse->mdev = mdev; - input_set_drvdata(input_dev, mse); input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); From 86178c8634ff8abe04933839d009c4440213040f Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 22 Jan 2017 17:18:45 -0800 Subject: [PATCH 64/91] Input: dm355evm_keys - drop unnecessary call to input_set_drvdata Since there is no call to dev_get_drvdata() or input_get_drvdata(), the call to input_set_drvdata() is unnecessary and can be dropped. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/misc/dm355evm_keys.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/input/misc/dm355evm_keys.c b/drivers/input/misc/dm355evm_keys.c index b6b7bd4e5462..82e272ebc0ed 100644 --- a/drivers/input/misc/dm355evm_keys.c +++ b/drivers/input/misc/dm355evm_keys.c @@ -195,8 +195,6 @@ static int dm355evm_keys_probe(struct platform_device *pdev) goto fail1; keys->irq = status; - input_set_drvdata(input, keys); - input->name = "DM355 EVM Controls"; input->phys = "dm355evm/input0"; input->dev.parent = &pdev->dev; From cefb26d4b37c329f624eb235a1bdc7b6b8dd9430 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 22 Jan 2017 17:19:12 -0800 Subject: [PATCH 65/91] Input: touchscreen - drop unnecessary calls to input_set_drvdata Since there is no call to dev_get_drvdata() or input_get_drvdata(), the call to input_set_drvdata() is unnecessary and can be dropped. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/edt-ft5x06.c | 1 - drivers/input/touchscreen/egalax_ts.c | 2 -- drivers/input/touchscreen/elants_i2c.c | 2 -- drivers/input/touchscreen/ili210x.c | 1 - drivers/input/touchscreen/mcs5000_ts.c | 1 - drivers/input/touchscreen/raydium_i2c_ts.c | 2 -- 6 files changed, 9 deletions(-) diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c index 8fc629fb023f..8cf8d8d5d4ef 100644 --- a/drivers/input/touchscreen/edt-ft5x06.c +++ b/drivers/input/touchscreen/edt-ft5x06.c @@ -982,7 +982,6 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client, return error; } - input_set_drvdata(input, tsdata); i2c_set_clientdata(client, tsdata); irq_flags = irq_get_trigger_type(client->irq); diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c index 3592a946950b..752ae9cf4514 100644 --- a/drivers/input/touchscreen/egalax_ts.c +++ b/drivers/input/touchscreen/egalax_ts.c @@ -214,8 +214,6 @@ static int egalax_ts_probe(struct i2c_client *client, ABS_MT_POSITION_Y, 0, EGALAX_MAX_Y, 0, 0); input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS, 0); - input_set_drvdata(input_dev, ts); - error = devm_request_threaded_irq(&client->dev, client->irq, NULL, egalax_ts_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT, diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c index 02aec284deca..740e4483f4fd 100644 --- a/drivers/input/touchscreen/elants_i2c.c +++ b/drivers/input/touchscreen/elants_i2c.c @@ -1260,8 +1260,6 @@ static int elants_i2c_probe(struct i2c_client *client, input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->x_res); input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res); - input_set_drvdata(ts->input, ts); - error = input_register_device(ts->input); if (error) { dev_err(&client->dev, diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c index 91dc5fb34fe1..6f76eeedf465 100644 --- a/drivers/input/touchscreen/ili210x.c +++ b/drivers/input/touchscreen/ili210x.c @@ -256,7 +256,6 @@ static int ili210x_i2c_probe(struct i2c_client *client, input_set_abs_params(input, ABS_MT_POSITION_X, 0, xmax, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ymax, 0, 0); - input_set_drvdata(input, priv); i2c_set_clientdata(client, priv); error = request_irq(client->irq, ili210x_irq, pdata->irq_flags, diff --git a/drivers/input/touchscreen/mcs5000_ts.c b/drivers/input/touchscreen/mcs5000_ts.c index 8b47e1fecb25..90fc07dc98a6 100644 --- a/drivers/input/touchscreen/mcs5000_ts.c +++ b/drivers/input/touchscreen/mcs5000_ts.c @@ -221,7 +221,6 @@ static int mcs5000_ts_probe(struct i2c_client *client, input_set_abs_params(input_dev, ABS_X, 0, MCS5000_MAX_XC, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0); - input_set_drvdata(input_dev, data); data->input_dev = input_dev; if (pdata->cfg_pin) diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c index 2658afa016c9..1252e49ccfa1 100644 --- a/drivers/input/touchscreen/raydium_i2c_ts.c +++ b/drivers/input/touchscreen/raydium_i2c_ts.c @@ -1087,8 +1087,6 @@ static int raydium_i2c_probe(struct i2c_client *client, ts->input->name = "Raydium Touchscreen"; ts->input->id.bustype = BUS_I2C; - input_set_drvdata(ts->input, ts); - input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, le16_to_cpu(ts->info.x_max), 0, 0); input_set_abs_params(ts->input, ABS_MT_POSITION_Y, From f719315b52b56c34d31c51c1926cea33a89cc9af Mon Sep 17 00:00:00 2001 From: Bhumika Goyal Date: Tue, 24 Jan 2017 10:33:55 -0800 Subject: [PATCH 66/91] Input: constify device_type structures Declare device_type structures as const as they are only stored in the type field of a device structure. This field is of type const, so add const to declaration of device_type structures. File size before: text data bss dec hex filename 17184 1344 80 18608 48b0 drivers/input/input.o File size after: text data bss dec hex filename 17248 1280 80 18608 48b0 drivers/input/input.o File size before: text data bss dec hex filename 2355 384 8 2747 abb drivers/input/rmi4/rmi_bus.o File size after: text data bss dec hex filename 2483 264 8 2755 ac3 drivers/input/rmi4/rmi_bus.o Signed-off-by: Bhumika Goyal Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 2 +- drivers/input/rmi4/rmi_bus.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index d95c34ee5dc1..6a75bb08b9ff 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -1749,7 +1749,7 @@ static const struct dev_pm_ops input_dev_pm_ops = { }; #endif /* CONFIG_PM */ -static struct device_type input_dev_type = { +static const struct device_type input_dev_type = { .groups = input_dev_attr_groups, .release = input_dev_release, .uevent = input_dev_uevent, diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c index 1c40d94ca506..213e3189f74c 100644 --- a/drivers/input/rmi4/rmi_bus.c +++ b/drivers/input/rmi4/rmi_bus.c @@ -55,7 +55,7 @@ static void rmi_release_device(struct device *dev) kfree(rmi_dev); } -static struct device_type rmi_device_type = { +static const struct device_type rmi_device_type = { .name = "rmi4_sensor", .release = rmi_release_device, }; @@ -134,7 +134,7 @@ static void rmi_release_function(struct device *dev) kfree(fn); } -static struct device_type rmi_function_type = { +static const struct device_type rmi_function_type = { .name = "rmi4_function", .release = rmi_release_function, }; From b1fe0cf06f92ff8ebe77959810ec3ff2555ff56c Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 31 Jan 2017 00:12:21 -0800 Subject: [PATCH 67/91] Input: delete MPU3050 driver The MPU3050 driver in the input subsystem has been superseded by a proper IIO driver found in drivers/iio/gyro/mpu3050*. Patches have been submitted to remove all defconfig and related references to the old driver and replace this input driver with the IIO driver. So delete the input driver. Input was never a good fit for sensors anyway. Signed-off-by: Linus Walleij Reviewed-by: Heikki Krogerus Signed-off-by: Dmitry Torokhov --- drivers/input/misc/Kconfig | 10 - drivers/input/misc/Makefile | 1 - drivers/input/misc/mpu3050.c | 481 ----------------------------------- 3 files changed, 492 deletions(-) delete mode 100644 drivers/input/misc/mpu3050.c diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 1ae4d9617ff8..5b6c52210d20 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -234,16 +234,6 @@ config INPUT_MMA8450 To compile this driver as a module, choose M here: the module will be called mma8450. -config INPUT_MPU3050 - tristate "MPU3050 Triaxial gyroscope sensor" - depends on I2C - help - Say Y here if you want to support InvenSense MPU3050 - connected via an I2C bus. - - To compile this driver as a module, choose M here: the - module will be called mpu3050. - config INPUT_APANEL tristate "Fujitsu Lifebook Application Panel buttons" depends on X86 && I2C && LEDS_CLASS diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 0b6d025f0487..b10523f2878e 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -48,7 +48,6 @@ obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o obj-$(CONFIG_INPUT_MAX8997_HAPTIC) += max8997_haptic.o obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o obj-$(CONFIG_INPUT_MMA8450) += mma8450.o -obj-$(CONFIG_INPUT_MPU3050) += mpu3050.o obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON) += palmas-pwrbutton.o obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o diff --git a/drivers/input/misc/mpu3050.c b/drivers/input/misc/mpu3050.c deleted file mode 100644 index f088db31cfc7..000000000000 --- a/drivers/input/misc/mpu3050.c +++ /dev/null @@ -1,481 +0,0 @@ -/* - * MPU3050 Tri-axis gyroscope driver - * - * Copyright (C) 2011 Wistron Co.Ltd - * Joseph Lai - * - * Trimmed down by Alan Cox to produce this version - * - * This is a 'lite' version of the driver, while we consider the right way - * to present the other features to user space. In particular it requires the - * device has an IRQ, and it only provides an input interface, so is not much - * use for device orientation. A fuller version is available from the Meego - * tree. - * - * This program is based on bma023.c. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MPU3050_CHIP_ID 0x69 - -#define MPU3050_AUTO_DELAY 1000 - -#define MPU3050_MIN_VALUE -32768 -#define MPU3050_MAX_VALUE 32767 - -#define MPU3050_DEFAULT_POLL_INTERVAL 200 -#define MPU3050_DEFAULT_FS_RANGE 3 - -/* Register map */ -#define MPU3050_CHIP_ID_REG 0x00 -#define MPU3050_SMPLRT_DIV 0x15 -#define MPU3050_DLPF_FS_SYNC 0x16 -#define MPU3050_INT_CFG 0x17 -#define MPU3050_XOUT_H 0x1D -#define MPU3050_PWR_MGM 0x3E -#define MPU3050_PWR_MGM_POS 6 - -/* Register bits */ - -/* DLPF_FS_SYNC */ -#define MPU3050_EXT_SYNC_NONE 0x00 -#define MPU3050_EXT_SYNC_TEMP 0x20 -#define MPU3050_EXT_SYNC_GYROX 0x40 -#define MPU3050_EXT_SYNC_GYROY 0x60 -#define MPU3050_EXT_SYNC_GYROZ 0x80 -#define MPU3050_EXT_SYNC_ACCELX 0xA0 -#define MPU3050_EXT_SYNC_ACCELY 0xC0 -#define MPU3050_EXT_SYNC_ACCELZ 0xE0 -#define MPU3050_EXT_SYNC_MASK 0xE0 -#define MPU3050_FS_250DPS 0x00 -#define MPU3050_FS_500DPS 0x08 -#define MPU3050_FS_1000DPS 0x10 -#define MPU3050_FS_2000DPS 0x18 -#define MPU3050_FS_MASK 0x18 -#define MPU3050_DLPF_CFG_256HZ_NOLPF2 0x00 -#define MPU3050_DLPF_CFG_188HZ 0x01 -#define MPU3050_DLPF_CFG_98HZ 0x02 -#define MPU3050_DLPF_CFG_42HZ 0x03 -#define MPU3050_DLPF_CFG_20HZ 0x04 -#define MPU3050_DLPF_CFG_10HZ 0x05 -#define MPU3050_DLPF_CFG_5HZ 0x06 -#define MPU3050_DLPF_CFG_2100HZ_NOLPF 0x07 -#define MPU3050_DLPF_CFG_MASK 0x07 -/* INT_CFG */ -#define MPU3050_RAW_RDY_EN 0x01 -#define MPU3050_MPU_RDY_EN 0x02 -#define MPU3050_LATCH_INT_EN 0x04 -/* PWR_MGM */ -#define MPU3050_PWR_MGM_PLL_X 0x01 -#define MPU3050_PWR_MGM_PLL_Y 0x02 -#define MPU3050_PWR_MGM_PLL_Z 0x03 -#define MPU3050_PWR_MGM_CLKSEL 0x07 -#define MPU3050_PWR_MGM_STBY_ZG 0x08 -#define MPU3050_PWR_MGM_STBY_YG 0x10 -#define MPU3050_PWR_MGM_STBY_XG 0x20 -#define MPU3050_PWR_MGM_SLEEP 0x40 -#define MPU3050_PWR_MGM_RESET 0x80 -#define MPU3050_PWR_MGM_MASK 0x40 - -struct axis_data { - s16 x; - s16 y; - s16 z; -}; - -struct mpu3050_sensor { - struct i2c_client *client; - struct device *dev; - struct input_dev *idev; -}; - -/** - * mpu3050_xyz_read_reg - read the axes values - * @buffer: provide register addr and get register - * @length: length of register - * - * Reads the register values in one transaction or returns a negative - * error code on failure. - */ -static int mpu3050_xyz_read_reg(struct i2c_client *client, - u8 *buffer, int length) -{ - /* - * Annoying we can't make this const because the i2c layer doesn't - * declare input buffers const. - */ - char cmd = MPU3050_XOUT_H; - struct i2c_msg msg[] = { - { - .addr = client->addr, - .flags = 0, - .len = 1, - .buf = &cmd, - }, - { - .addr = client->addr, - .flags = I2C_M_RD, - .len = length, - .buf = buffer, - }, - }; - - return i2c_transfer(client->adapter, msg, 2); -} - -/** - * mpu3050_read_xyz - get co-ordinates from device - * @client: i2c address of sensor - * @coords: co-ordinates to update - * - * Return the converted X Y and Z co-ordinates from the sensor device - */ -static void mpu3050_read_xyz(struct i2c_client *client, - struct axis_data *coords) -{ - u16 buffer[3]; - - mpu3050_xyz_read_reg(client, (u8 *)buffer, 6); - coords->x = be16_to_cpu(buffer[0]); - coords->y = be16_to_cpu(buffer[1]); - coords->z = be16_to_cpu(buffer[2]); - dev_dbg(&client->dev, "%s: x %d, y %d, z %d\n", __func__, - coords->x, coords->y, coords->z); -} - -/** - * mpu3050_set_power_mode - set the power mode - * @client: i2c client for the sensor - * @val: value to switch on/off of power, 1: normal power, 0: low power - * - * Put device to normal-power mode or low-power mode. - */ -static void mpu3050_set_power_mode(struct i2c_client *client, u8 val) -{ - u8 value; - - value = i2c_smbus_read_byte_data(client, MPU3050_PWR_MGM); - value = (value & ~MPU3050_PWR_MGM_MASK) | - (((val << MPU3050_PWR_MGM_POS) & MPU3050_PWR_MGM_MASK) ^ - MPU3050_PWR_MGM_MASK); - i2c_smbus_write_byte_data(client, MPU3050_PWR_MGM, value); -} - -/** - * mpu3050_input_open - called on input event open - * @input: input dev of opened device - * - * The input layer calls this function when input event is opened. The - * function will push the device to resume. Then, the device is ready - * to provide data. - */ -static int mpu3050_input_open(struct input_dev *input) -{ - struct mpu3050_sensor *sensor = input_get_drvdata(input); - int error; - - pm_runtime_get(sensor->dev); - - /* Enable interrupts */ - error = i2c_smbus_write_byte_data(sensor->client, MPU3050_INT_CFG, - MPU3050_LATCH_INT_EN | - MPU3050_RAW_RDY_EN | - MPU3050_MPU_RDY_EN); - if (error < 0) { - pm_runtime_put(sensor->dev); - return error; - } - - return 0; -} - -/** - * mpu3050_input_close - called on input event close - * @input: input dev of closed device - * - * The input layer calls this function when input event is closed. The - * function will push the device to suspend. - */ -static void mpu3050_input_close(struct input_dev *input) -{ - struct mpu3050_sensor *sensor = input_get_drvdata(input); - - pm_runtime_put(sensor->dev); -} - -/** - * mpu3050_interrupt_thread - handle an IRQ - * @irq: interrupt numner - * @data: the sensor - * - * Called by the kernel single threaded after an interrupt occurs. Read - * the sensor data and generate an input event for it. - */ -static irqreturn_t mpu3050_interrupt_thread(int irq, void *data) -{ - struct mpu3050_sensor *sensor = data; - struct axis_data axis; - - mpu3050_read_xyz(sensor->client, &axis); - - input_report_abs(sensor->idev, ABS_X, axis.x); - input_report_abs(sensor->idev, ABS_Y, axis.y); - input_report_abs(sensor->idev, ABS_Z, axis.z); - input_sync(sensor->idev); - - return IRQ_HANDLED; -} - -/** - * mpu3050_hw_init - initialize hardware - * @sensor: the sensor - * - * Called during device probe; configures the sampling method. - */ -static int mpu3050_hw_init(struct mpu3050_sensor *sensor) -{ - struct i2c_client *client = sensor->client; - int ret; - u8 reg; - - /* Reset */ - ret = i2c_smbus_write_byte_data(client, MPU3050_PWR_MGM, - MPU3050_PWR_MGM_RESET); - if (ret < 0) - return ret; - - ret = i2c_smbus_read_byte_data(client, MPU3050_PWR_MGM); - if (ret < 0) - return ret; - - ret &= ~MPU3050_PWR_MGM_CLKSEL; - ret |= MPU3050_PWR_MGM_PLL_Z; - ret = i2c_smbus_write_byte_data(client, MPU3050_PWR_MGM, ret); - if (ret < 0) - return ret; - - /* Output frequency divider. The poll interval */ - ret = i2c_smbus_write_byte_data(client, MPU3050_SMPLRT_DIV, - MPU3050_DEFAULT_POLL_INTERVAL - 1); - if (ret < 0) - return ret; - - /* Set low pass filter and full scale */ - reg = MPU3050_DEFAULT_FS_RANGE; - reg |= MPU3050_DLPF_CFG_42HZ << 3; - reg |= MPU3050_EXT_SYNC_NONE << 5; - ret = i2c_smbus_write_byte_data(client, MPU3050_DLPF_FS_SYNC, reg); - if (ret < 0) - return ret; - - return 0; -} - -/** - * mpu3050_probe - device detection callback - * @client: i2c client of found device - * @id: id match information - * - * The I2C layer calls us when it believes a sensor is present at this - * address. Probe to see if this is correct and to validate the device. - * - * If present install the relevant sysfs interfaces and input device. - */ -static int mpu3050_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct mpu3050_sensor *sensor; - struct input_dev *idev; - int ret; - int error; - - sensor = kzalloc(sizeof(struct mpu3050_sensor), GFP_KERNEL); - idev = input_allocate_device(); - if (!sensor || !idev) { - dev_err(&client->dev, "failed to allocate driver data\n"); - error = -ENOMEM; - goto err_free_mem; - } - - sensor->client = client; - sensor->dev = &client->dev; - sensor->idev = idev; - - mpu3050_set_power_mode(client, 1); - msleep(10); - - ret = i2c_smbus_read_byte_data(client, MPU3050_CHIP_ID_REG); - if (ret < 0) { - dev_err(&client->dev, "failed to detect device\n"); - error = -ENXIO; - goto err_free_mem; - } - - if (ret != MPU3050_CHIP_ID) { - dev_err(&client->dev, "unsupported chip id\n"); - error = -ENXIO; - goto err_free_mem; - } - - idev->name = "MPU3050"; - idev->id.bustype = BUS_I2C; - idev->dev.parent = &client->dev; - - idev->open = mpu3050_input_open; - idev->close = mpu3050_input_close; - - __set_bit(EV_ABS, idev->evbit); - input_set_abs_params(idev, ABS_X, - MPU3050_MIN_VALUE, MPU3050_MAX_VALUE, 0, 0); - input_set_abs_params(idev, ABS_Y, - MPU3050_MIN_VALUE, MPU3050_MAX_VALUE, 0, 0); - input_set_abs_params(idev, ABS_Z, - MPU3050_MIN_VALUE, MPU3050_MAX_VALUE, 0, 0); - - input_set_drvdata(idev, sensor); - - pm_runtime_set_active(&client->dev); - - error = mpu3050_hw_init(sensor); - if (error) - goto err_pm_set_suspended; - - error = request_threaded_irq(client->irq, - NULL, mpu3050_interrupt_thread, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "mpu3050", sensor); - if (error) { - dev_err(&client->dev, - "can't get IRQ %d, error %d\n", client->irq, error); - goto err_pm_set_suspended; - } - - error = input_register_device(idev); - if (error) { - dev_err(&client->dev, "failed to register input device\n"); - goto err_free_irq; - } - - pm_runtime_enable(&client->dev); - pm_runtime_set_autosuspend_delay(&client->dev, MPU3050_AUTO_DELAY); - i2c_set_clientdata(client, sensor); - - return 0; - -err_free_irq: - free_irq(client->irq, sensor); -err_pm_set_suspended: - pm_runtime_set_suspended(&client->dev); -err_free_mem: - input_free_device(idev); - kfree(sensor); - return error; -} - -/** - * mpu3050_remove - remove a sensor - * @client: i2c client of sensor being removed - * - * Our sensor is going away, clean up the resources. - */ -static int mpu3050_remove(struct i2c_client *client) -{ - struct mpu3050_sensor *sensor = i2c_get_clientdata(client); - - pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); - - free_irq(client->irq, sensor); - input_unregister_device(sensor->idev); - kfree(sensor); - - return 0; -} - -#ifdef CONFIG_PM -/** - * mpu3050_suspend - called on device suspend - * @dev: device being suspended - * - * Put the device into sleep mode before we suspend the machine. - */ -static int mpu3050_suspend(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - - mpu3050_set_power_mode(client, 0); - - return 0; -} - -/** - * mpu3050_resume - called on device resume - * @dev: device being resumed - * - * Put the device into powered mode on resume. - */ -static int mpu3050_resume(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - - mpu3050_set_power_mode(client, 1); - msleep(100); /* wait for gyro chip resume */ - - return 0; -} -#endif - -static UNIVERSAL_DEV_PM_OPS(mpu3050_pm, mpu3050_suspend, mpu3050_resume, NULL); - -static const struct i2c_device_id mpu3050_ids[] = { - { "mpu3050", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, mpu3050_ids); - -static const struct of_device_id mpu3050_of_match[] = { - { .compatible = "invn,mpu3050", }, - { }, -}; -MODULE_DEVICE_TABLE(of, mpu3050_of_match); - -static struct i2c_driver mpu3050_i2c_driver = { - .driver = { - .name = "mpu3050", - .pm = &mpu3050_pm, - .of_match_table = mpu3050_of_match, - }, - .probe = mpu3050_probe, - .remove = mpu3050_remove, - .id_table = mpu3050_ids, -}; - -module_i2c_driver(mpu3050_i2c_driver); - -MODULE_AUTHOR("Wistron Corp."); -MODULE_DESCRIPTION("MPU3050 Tri-axis gyroscope driver"); -MODULE_LICENSE("GPL"); From aef01aad89e457e34a60ff6e8fd69ff6740cf201 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 11 Nov 2016 12:43:12 -0800 Subject: [PATCH 68/91] Input: matrix-keypad - switch to using generic device properties Instead of being OF-specific, let's switch to using generic device properties, which will make this code usable on ACPI, device tree and legacy boards that use property sets. As part of the change let's rename matrix_keypad_parse_of_params() to matrix_keypad_parse_properties(). Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/bcm-keypad.c | 2 +- drivers/input/keyboard/cros_ec_keyb.c | 3 +- drivers/input/keyboard/lpc32xx-keys.c | 2 +- drivers/input/keyboard/omap4-keypad.c | 4 +- drivers/input/keyboard/pmic8xxx-keypad.c | 2 +- drivers/input/keyboard/pxa27x_keypad.c | 2 +- drivers/input/keyboard/st-keyscan.c | 4 +- drivers/input/keyboard/stmpe-keypad.c | 2 +- drivers/input/keyboard/tca8418_keypad.c | 2 +- drivers/input/keyboard/twl4030_keypad.c | 4 +- drivers/input/matrix-keymap.c | 113 ++++++++++++----------- include/linux/input/matrix_keypad.h | 21 +---- 12 files changed, 75 insertions(+), 86 deletions(-) diff --git a/drivers/input/keyboard/bcm-keypad.c b/drivers/input/keyboard/bcm-keypad.c index 2b4e63d81e6d..e1cf63ee148f 100644 --- a/drivers/input/keyboard/bcm-keypad.c +++ b/drivers/input/keyboard/bcm-keypad.c @@ -213,7 +213,7 @@ static int bcm_kp_matrix_key_parse_dt(struct bcm_kp *kp) /* Initialize the KPCR Keypad Configuration Register */ kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE; - error = matrix_keypad_parse_of_params(dev, &kp->n_rows, &kp->n_cols); + error = matrix_keypad_parse_properties(dev, &kp->n_rows, &kp->n_cols); if (error) { dev_err(dev, "failed to parse kp params\n"); return error; diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index 87d071ae21da..780977dcf92d 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -229,7 +229,8 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); if (!ckdev) return -ENOMEM; - err = matrix_keypad_parse_of_params(dev, &ckdev->rows, &ckdev->cols); + + err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols); if (err) return err; diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c index 632523d4f5dc..1dd57ac0e7a2 100644 --- a/drivers/input/keyboard/lpc32xx-keys.c +++ b/drivers/input/keyboard/lpc32xx-keys.c @@ -145,7 +145,7 @@ static int lpc32xx_parse_dt(struct device *dev, u32 rows = 0, columns = 0; int err; - err = matrix_keypad_parse_of_params(dev, &rows, &columns); + err = matrix_keypad_parse_properties(dev, &rows, &columns); if (err) return err; if (rows != columns) { diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index 9ecb16701b13..ebc67ba41fe2 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -223,8 +223,8 @@ static int omap4_keypad_parse_dt(struct device *dev, struct device_node *np = dev->of_node; int err; - err = matrix_keypad_parse_of_params(dev, &keypad_data->rows, - &keypad_data->cols); + err = matrix_keypad_parse_properties(dev, &keypad_data->rows, + &keypad_data->cols); if (err) return err; diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c index 5c68e3f096bc..97c5424f49b9 100644 --- a/drivers/input/keyboard/pmic8xxx-keypad.c +++ b/drivers/input/keyboard/pmic8xxx-keypad.c @@ -515,7 +515,7 @@ static int pmic8xxx_kp_probe(struct platform_device *pdev) int rc; unsigned int ctrl_val; - rc = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols); + rc = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols); if (rc) return rc; diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c index e24443376e75..3841fa30db33 100644 --- a/drivers/input/keyboard/pxa27x_keypad.c +++ b/drivers/input/keyboard/pxa27x_keypad.c @@ -126,7 +126,7 @@ static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, u32 rows, cols; int error; - error = matrix_keypad_parse_of_params(dev, &rows, &cols); + error = matrix_keypad_parse_properties(dev, &rows, &cols); if (error) return error; diff --git a/drivers/input/keyboard/st-keyscan.c b/drivers/input/keyboard/st-keyscan.c index de7be4f03d91..babcfb165e4f 100644 --- a/drivers/input/keyboard/st-keyscan.c +++ b/drivers/input/keyboard/st-keyscan.c @@ -106,8 +106,8 @@ static int keypad_matrix_key_parse_dt(struct st_keyscan *keypad_data) struct device_node *np = dev->of_node; int error; - error = matrix_keypad_parse_of_params(dev, &keypad_data->n_rows, - &keypad_data->n_cols); + error = matrix_keypad_parse_properties(dev, &keypad_data->n_rows, + &keypad_data->n_cols); if (error) { dev_err(dev, "failed to parse keypad params\n"); return error; diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c index fe6e3f22eed7..8c6c0b9109c7 100644 --- a/drivers/input/keyboard/stmpe-keypad.c +++ b/drivers/input/keyboard/stmpe-keypad.c @@ -354,7 +354,7 @@ static int stmpe_keypad_probe(struct platform_device *pdev) input->id.bustype = BUS_I2C; input->dev.parent = &pdev->dev; - error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols); + error = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols); if (error) return error; diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c index 9f6308fac0b4..ccff9d1b7135 100644 --- a/drivers/input/keyboard/tca8418_keypad.c +++ b/drivers/input/keyboard/tca8418_keypad.c @@ -295,7 +295,7 @@ static int tca8418_keypad_probe(struct i2c_client *client, struct device_node *np = dev->of_node; int err; - err = matrix_keypad_parse_of_params(dev, &rows, &cols); + err = matrix_keypad_parse_properties(dev, &rows, &cols); if (err) return err; rep = of_property_read_bool(np, "keypad,autorepeat"); diff --git a/drivers/input/keyboard/twl4030_keypad.c b/drivers/input/keyboard/twl4030_keypad.c index 29396ca69416..39e72b3219d8 100644 --- a/drivers/input/keyboard/twl4030_keypad.c +++ b/drivers/input/keyboard/twl4030_keypad.c @@ -374,8 +374,8 @@ static int twl4030_kp_probe(struct platform_device *pdev) kp->autorepeat = pdata->rep; keymap_data = pdata->keymap_data; } else { - error = matrix_keypad_parse_of_params(&pdev->dev, &kp->n_rows, - &kp->n_cols); + error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows, + &kp->n_cols); if (error) return error; diff --git a/drivers/input/matrix-keymap.c b/drivers/input/matrix-keymap.c index 08b61f506db6..8ccefc15c7a4 100644 --- a/drivers/input/matrix-keymap.c +++ b/drivers/input/matrix-keymap.c @@ -14,18 +14,18 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * */ #include -#include -#include -#include -#include -#include #include -#include +#include +#include #include +#include +#include +#include +#include +#include static bool matrix_keypad_map_key(struct input_dev *input_dev, unsigned int rows, unsigned int cols, @@ -49,18 +49,22 @@ static bool matrix_keypad_map_key(struct input_dev *input_dev, return true; } -#ifdef CONFIG_OF -int matrix_keypad_parse_of_params(struct device *dev, - unsigned int *rows, unsigned int *cols) +/** + * matrix_keypad_parse_properties() - Read properties of matrix keypad + * + * @dev: Device containing properties + * @rows: Returns number of matrix rows + * @cols: Returns number of matrix columns + * @return 0 if OK, <0 on error + */ +int matrix_keypad_parse_properties(struct device *dev, + unsigned int *rows, unsigned int *cols) { - struct device_node *np = dev->of_node; + *rows = *cols = 0; + + device_property_read_u32(dev, "keypad,num-rows", rows); + device_property_read_u32(dev, "keypad,num-columns", cols); - if (!np) { - dev_err(dev, "missing DT data"); - return -EINVAL; - } - of_property_read_u32(np, "keypad,num-rows", rows); - of_property_read_u32(np, "keypad,num-columns", cols); if (!*rows || !*cols) { dev_err(dev, "number of keypad rows/columns not specified\n"); return -EINVAL; @@ -68,62 +72,61 @@ int matrix_keypad_parse_of_params(struct device *dev, return 0; } -EXPORT_SYMBOL_GPL(matrix_keypad_parse_of_params); +EXPORT_SYMBOL_GPL(matrix_keypad_parse_properties); -static int matrix_keypad_parse_of_keymap(const char *propname, - unsigned int rows, unsigned int cols, - struct input_dev *input_dev) +static int matrix_keypad_parse_keymap(const char *propname, + unsigned int rows, unsigned int cols, + struct input_dev *input_dev) { struct device *dev = input_dev->dev.parent; - struct device_node *np = dev->of_node; unsigned int row_shift = get_count_order(cols); unsigned int max_keys = rows << row_shift; - unsigned int proplen, i, size; - const __be32 *prop; - - if (!np) - return -ENOENT; + u32 *keys; + int i; + int size; + int retval; if (!propname) propname = "linux,keymap"; - prop = of_get_property(np, propname, &proplen); - if (!prop) { - dev_err(dev, "OF: %s property not defined in %s\n", - propname, np->full_name); - return -ENOENT; + size = device_property_read_u32_array(dev, propname, NULL, 0); + if (size <= 0) { + dev_err(dev, "missing or malformed property %s: %d\n", + propname, size); + return size < 0 ? size : -EINVAL; } - if (proplen % sizeof(u32)) { - dev_err(dev, "OF: Malformed keycode property %s in %s\n", - propname, np->full_name); - return -EINVAL; - } - - size = proplen / sizeof(u32); if (size > max_keys) { - dev_err(dev, "OF: %s size overflow\n", propname); + dev_err(dev, "%s size overflow (%d vs max %u)\n", + propname, size, max_keys); return -EINVAL; } + keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL); + if (!keys) + return -ENOMEM; + + retval = device_property_read_u32_array(dev, propname, keys, size); + if (retval) { + dev_err(dev, "failed to read %s property: %d\n", + propname, retval); + goto out; + } + for (i = 0; i < size; i++) { - unsigned int key = be32_to_cpup(prop + i); - if (!matrix_keypad_map_key(input_dev, rows, cols, - row_shift, key)) - return -EINVAL; + row_shift, keys[i])) { + retval = -EINVAL; + goto out; + } } - return 0; + retval = 0; + +out: + kfree(keys); + return retval; } -#else -static int matrix_keypad_parse_of_keymap(const char *propname, - unsigned int rows, unsigned int cols, - struct input_dev *input_dev) -{ - return -ENOSYS; -} -#endif /** * matrix_keypad_build_keymap - convert platform keymap into matrix keymap @@ -192,8 +195,8 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, return -EINVAL; } } else { - error = matrix_keypad_parse_of_keymap(keymap_name, rows, cols, - input_dev); + error = matrix_keypad_parse_keymap(keymap_name, rows, cols, + input_dev); if (error) return error; } diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h index 27e06acc509a..37b04a0fdea4 100644 --- a/include/linux/input/matrix_keypad.h +++ b/include/linux/input/matrix_keypad.h @@ -80,24 +80,9 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, unsigned int rows, unsigned int cols, unsigned short *keymap, struct input_dev *input_dev); +int matrix_keypad_parse_properties(struct device *dev, + unsigned int *rows, unsigned int *cols); -#ifdef CONFIG_OF -/** - * matrix_keypad_parse_of_params() - Read parameters from matrix-keypad node - * - * @dev: Device containing of_node - * @rows: Returns number of matrix rows - * @cols: Returns number of matrix columns - * @return 0 if OK, <0 on error - */ -int matrix_keypad_parse_of_params(struct device *dev, - unsigned int *rows, unsigned int *cols); -#else -static inline int matrix_keypad_parse_of_params(struct device *dev, - unsigned int *rows, unsigned int *cols) -{ - return -ENOSYS; -} -#endif /* CONFIG_OF */ +#define matrix_keypad_parse_of_params matrix_keypad_parse_properties #endif /* _MATRIX_KEYPAD_H */ From 8b1a315b35a961198336b944635c6936321b4a77 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 17 Jan 2017 14:18:50 -0800 Subject: [PATCH 69/91] Input: tca8418 - switch to using generic device properties Let's drop legacy platform data support (there are no users in mainline) and switch to using generic device properties, which will make the driver simpler (non-OF boards can use property sets to describe hardware). Reviewed-by: Maxime Ripard Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca8418_keypad.c | 90 +++++++------------------ include/linux/input/tca8418_keypad.h | 44 ------------ 2 files changed, 26 insertions(+), 108 deletions(-) delete mode 100644 include/linux/input/tca8418_keypad.h diff --git a/drivers/input/keyboard/tca8418_keypad.c b/drivers/input/keyboard/tca8418_keypad.c index ccff9d1b7135..44dd7689c571 100644 --- a/drivers/input/keyboard/tca8418_keypad.c +++ b/drivers/input/keyboard/tca8418_keypad.c @@ -24,18 +24,17 @@ * alternative licensing inquiries. */ -#include -#include -#include #include -#include -#include -#include -#include #include +#include #include -#include +#include +#include +#include #include +#include +#include +#include /* TCA8418 hardware limits */ #define TCA8418_MAX_ROWS 8 @@ -264,43 +263,25 @@ static int tca8418_configure(struct tca8418_keypad *keypad_data, } static int tca8418_keypad_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct device *dev = &client->dev; - const struct tca8418_keypad_platform_data *pdata = - dev_get_platdata(dev); struct tca8418_keypad *keypad_data; struct input_dev *input; - const struct matrix_keymap_data *keymap_data = NULL; u32 rows = 0, cols = 0; - bool rep = false; - bool irq_is_gpio = false; - int irq; int error, row_shift, max_keys; - unsigned long trigger = 0; - /* Copy the platform data */ - if (pdata) { - if (!pdata->keymap_data) { - dev_err(dev, "no keymap data defined\n"); - return -EINVAL; - } - keymap_data = pdata->keymap_data; - rows = pdata->rows; - cols = pdata->cols; - rep = pdata->rep; - irq_is_gpio = pdata->irq_is_gpio; - trigger = IRQF_TRIGGER_FALLING; - } else { - struct device_node *np = dev->of_node; - int err; - - err = matrix_keypad_parse_properties(dev, &rows, &cols); - if (err) - return err; - rep = of_property_read_bool(np, "keypad,autorepeat"); + /* Check i2c driver capabilities */ + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { + dev_err(dev, "%s adapter not supported\n", + dev_driver_string(&client->adapter->dev)); + return -ENODEV; } + error = matrix_keypad_parse_properties(dev, &rows, &cols); + if (error) + return error; + if (!rows || rows > TCA8418_MAX_ROWS) { dev_err(dev, "invalid rows\n"); return -EINVAL; @@ -311,13 +292,6 @@ static int tca8418_keypad_probe(struct i2c_client *client, return -EINVAL; } - /* Check i2c driver capabilities */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { - dev_err(dev, "%s adapter not supported\n", - dev_driver_string(&client->adapter->dev)); - return -ENODEV; - } - row_shift = get_count_order(cols); max_keys = rows << row_shift; @@ -347,23 +321,20 @@ static int tca8418_keypad_probe(struct i2c_client *client, input->id.product = 0x001; input->id.version = 0x0001; - error = matrix_keypad_build_keymap(keymap_data, NULL, rows, cols, - NULL, input); + error = matrix_keypad_build_keymap(NULL, NULL, rows, cols, NULL, input); if (error) { dev_err(dev, "Failed to build keymap\n"); return error; } - if (rep) + if (device_property_read_bool(dev, "keypad,autorepeat")) __set_bit(EV_REP, input->evbit); + input_set_capability(input, EV_MSC, MSC_SCAN); - irq = client->irq; - if (irq_is_gpio) - irq = gpio_to_irq(irq); - - error = devm_request_threaded_irq(dev, irq, NULL, tca8418_irq_handler, - trigger | IRQF_SHARED | IRQF_ONESHOT, + error = devm_request_threaded_irq(dev, client->irq, + NULL, tca8418_irq_handler, + IRQF_SHARED | IRQF_ONESHOT, client->name, keypad_data); if (error) { dev_err(dev, "Unable to claim irq %d; error %d\n", @@ -382,30 +353,21 @@ static int tca8418_keypad_probe(struct i2c_client *client, } static const struct i2c_device_id tca8418_id[] = { - { TCA8418_NAME, 8418, }, + { "tca8418", 8418, }, { } }; MODULE_DEVICE_TABLE(i2c, tca8418_id); -#ifdef CONFIG_OF static const struct of_device_id tca8418_dt_ids[] = { { .compatible = "ti,tca8418", }, { } }; MODULE_DEVICE_TABLE(of, tca8418_dt_ids); -/* - * The device tree based i2c loader looks for - * "i2c:" + second_component_of(property("compatible")) - * and therefore we need an alias to be found. - */ -MODULE_ALIAS("i2c:tca8418"); -#endif - static struct i2c_driver tca8418_keypad_driver = { .driver = { - .name = TCA8418_NAME, - .of_match_table = of_match_ptr(tca8418_dt_ids), + .name = "tca8418_keypad", + .of_match_table = tca8418_dt_ids, }, .probe = tca8418_keypad_probe, .id_table = tca8418_id, diff --git a/include/linux/input/tca8418_keypad.h b/include/linux/input/tca8418_keypad.h deleted file mode 100644 index e71a85dc2cbd..000000000000 --- a/include/linux/input/tca8418_keypad.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * TCA8418 keypad platform support - * - * Copyright (C) 2011 Fuel7, Inc. All rights reserved. - * - * Author: Kyle Manna - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License v2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - * - * If you can't comply with GPLv2, alternative licensing terms may be - * arranged. Please contact Fuel7, Inc. (http://fuel7.com/) for proprietary - * alternative licensing inquiries. - */ - -#ifndef _TCA8418_KEYPAD_H -#define _TCA8418_KEYPAD_H - -#include -#include - -#define TCA8418_I2C_ADDR 0x34 -#define TCA8418_NAME "tca8418_keypad" - -struct tca8418_keypad_platform_data { - const struct matrix_keymap_data *keymap_data; - unsigned rows; - unsigned cols; - bool rep; - bool irq_is_gpio; -}; - -#endif From 73d8ef76006b649f9c272cb4473039e25fcc9908 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 27 Dec 2016 11:53:45 -0800 Subject: [PATCH 70/91] Input: mousedev - stop offering PS/2 to userspace by default Evdev interface has been available for many years and by now everyone is switched to using it, so let's stop offering /dev/input/mouseN and /dev/psaux by default. Acked-by: Jiri Kosina Acked-by: Peter Hutterer Acked-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/Kconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 6261874c07c9..ff8037798779 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -94,7 +94,6 @@ comment "Userland interfaces" config INPUT_MOUSEDEV tristate "Mouse interface" - default y help Say Y here if you want your mouse to be accessible as char devices 13:32+ - /dev/input/mouseX and 13:63 - /dev/input/mice as an @@ -109,7 +108,6 @@ config INPUT_MOUSEDEV config INPUT_MOUSEDEV_PSAUX bool "Provide legacy /dev/psaux device" - default y depends on INPUT_MOUSEDEV help Say Y here if you want your mouse also be accessible as char device @@ -118,7 +116,6 @@ config INPUT_MOUSEDEV_PSAUX If unsure, say Y. - config INPUT_MOUSEDEV_SCREEN_X int "Horizontal screen resolution" depends on INPUT_MOUSEDEV From 5a89916df2c8d2635b82a457cd4945dd73c1de3c Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Tue, 31 Jan 2017 15:25:56 -0800 Subject: [PATCH 71/91] Input: synaptics-rmi4 - add sysfs attribute update_fw_status The attribute returns the percentage complete. If the firmware update fails, it reports a negative error code. Signed-off-by: Nick Dyer Tested-by: Chris Healy Acked-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f34.c | 92 ++++++++++++++++++++++++---------- drivers/input/rmi4/rmi_f34.h | 4 ++ drivers/input/rmi4/rmi_f34v7.c | 11 ++++ 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c index c3285cefe9b6..902b99007885 100644 --- a/drivers/input/rmi4/rmi_f34.c +++ b/drivers/input/rmi4/rmi_f34.c @@ -157,6 +157,9 @@ static int rmi_f34_write_blocks(struct f34_data *f34, const void *data, i + 1, block_count); data += f34->v5.block_size; + f34->update_progress += f34->v5.block_size; + f34->update_status = (f34->update_progress * 100) / + f34->update_size; } return 0; @@ -174,7 +177,7 @@ static int rmi_f34_write_config(struct f34_data *f34, const void *data) F34_WRITE_CONFIG_BLOCK); } -int rmi_f34_enable_flash(struct f34_data *f34) +static int rmi_f34_enable_flash(struct f34_data *f34) { return rmi_f34_command(f34, F34_ENABLE_FLASH_PROG, F34_ENABLE_WAIT_MS, true); @@ -184,9 +187,14 @@ static int rmi_f34_flash_firmware(struct f34_data *f34, const struct rmi_f34_firmware *syn_fw) { struct rmi_function *fn = f34->fn; + u32 image_size = le32_to_cpu(syn_fw->image_size); + u32 config_size = le32_to_cpu(syn_fw->config_size); int ret; - if (syn_fw->image_size) { + f34->update_progress = 0; + f34->update_size = image_size + config_size; + + if (image_size) { dev_info(&fn->dev, "Erasing firmware...\n"); ret = rmi_f34_command(f34, F34_ERASE_ALL, F34_ERASE_WAIT_MS, true); @@ -194,18 +202,18 @@ static int rmi_f34_flash_firmware(struct f34_data *f34, return ret; dev_info(&fn->dev, "Writing firmware (%d bytes)...\n", - syn_fw->image_size); + image_size); ret = rmi_f34_write_firmware(f34, syn_fw->data); if (ret) return ret; } - if (syn_fw->config_size) { + if (config_size) { /* * We only need to erase config if we haven't updated * firmware. */ - if (!syn_fw->image_size) { + if (!image_size) { dev_info(&fn->dev, "Erasing config...\n"); ret = rmi_f34_command(f34, F34_ERASE_CONFIG, F34_ERASE_WAIT_MS, true); @@ -214,9 +222,8 @@ static int rmi_f34_flash_firmware(struct f34_data *f34, } dev_info(&fn->dev, "Writing config (%d bytes)...\n", - syn_fw->config_size); - ret = rmi_f34_write_config(f34, - &syn_fw->data[syn_fw->image_size]); + config_size); + ret = rmi_f34_write_config(f34, &syn_fw->data[image_size]); if (ret) return ret; } @@ -224,21 +231,23 @@ static int rmi_f34_flash_firmware(struct f34_data *f34, return 0; } -int rmi_f34_update_firmware(struct f34_data *f34, const struct firmware *fw) +static int rmi_f34_update_firmware(struct f34_data *f34, + const struct firmware *fw) { - const struct rmi_f34_firmware *syn_fw; + const struct rmi_f34_firmware *syn_fw = + (const struct rmi_f34_firmware *)fw->data; + u32 image_size = le32_to_cpu(syn_fw->image_size); + u32 config_size = le32_to_cpu(syn_fw->config_size); int ret; - syn_fw = (const struct rmi_f34_firmware *)fw->data; BUILD_BUG_ON(offsetof(struct rmi_f34_firmware, data) != F34_FW_IMAGE_OFFSET); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, - "FW size:%d, checksum:%08x, image_size:%d, config_size:%d\n", - (int)fw->size, + "FW size:%zd, checksum:%08x, image_size:%d, config_size:%d\n", + fw->size, le32_to_cpu(syn_fw->checksum), - le32_to_cpu(syn_fw->image_size), - le32_to_cpu(syn_fw->config_size)); + image_size, config_size); rmi_dbg(RMI_DEBUG_FN, &f34->fn->dev, "FW bootloader_id:%02x, product_id:%.*s, info: %02x%02x\n", @@ -246,27 +255,25 @@ int rmi_f34_update_firmware(struct f34_data *f34, const struct firmware *fw) (int)sizeof(syn_fw->product_id), syn_fw->product_id, syn_fw->product_info[0], syn_fw->product_info[1]); - if (syn_fw->image_size && - syn_fw->image_size != f34->v5.fw_blocks * f34->v5.block_size) { + if (image_size && image_size != f34->v5.fw_blocks * f34->v5.block_size) { dev_err(&f34->fn->dev, "Bad firmware image: fw size %d, expected %d\n", - syn_fw->image_size, - f34->v5.fw_blocks * f34->v5.block_size); + image_size, f34->v5.fw_blocks * f34->v5.block_size); ret = -EILSEQ; goto out; } - if (syn_fw->config_size && - syn_fw->config_size != f34->v5.config_blocks * f34->v5.block_size) { + if (config_size && + config_size != f34->v5.config_blocks * f34->v5.block_size) { dev_err(&f34->fn->dev, "Bad firmware image: config size %d, expected %d\n", - syn_fw->config_size, + config_size, f34->v5.config_blocks * f34->v5.block_size); ret = -EILSEQ; goto out; } - if (syn_fw->image_size && !syn_fw->config_size) { + if (image_size && !config_size) { dev_err(&f34->fn->dev, "Bad firmware image: no config data\n"); ret = -EILSEQ; goto out; @@ -283,6 +290,17 @@ out: return ret; } +static int rmi_f34_status(struct rmi_function *fn) +{ + struct f34_data *f34 = dev_get_drvdata(&fn->dev); + + /* + * The status is the percentage complete, or once complete, + * zero for success or a negative return code. + */ + return f34->update_status; +} + static int rmi_firmware_update(struct rmi_driver_data *data, const struct firmware *fw) { @@ -346,7 +364,13 @@ static int rmi_firmware_update(struct rmi_driver_data *data, else ret = rmi_f34_update_firmware(f34, fw); - dev_info(&f34->fn->dev, "Firmware update complete, status:%d\n", ret); + if (ret) { + f34->update_status = ret; + dev_err(&f34->fn->dev, + "Firmware update failed, status: %d\n", ret); + } else { + dev_info(&f34->fn->dev, "Firmware update complete\n"); + } rmi_disable_irq(rmi_dev, false); @@ -377,9 +401,6 @@ static int rmi_firmware_update(struct rmi_driver_data *data, return ret; } -static int rmi_firmware_update(struct rmi_driver_data *data, - const struct firmware *fw); - static ssize_t rmi_driver_update_fw_store(struct device *dev, struct device_attribute *dattr, const char *buf, size_t count) @@ -414,8 +435,25 @@ static ssize_t rmi_driver_update_fw_store(struct device *dev, static DEVICE_ATTR(update_fw, 0200, NULL, rmi_driver_update_fw_store); +static ssize_t rmi_driver_update_fw_status_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + int update_status = 0; + + if (data->f34_container) + update_status = rmi_f34_status(data->f34_container); + + return scnprintf(buf, PAGE_SIZE, "%d\n", update_status); +} + +static DEVICE_ATTR(update_fw_status, 0444, + rmi_driver_update_fw_status_show, NULL); + static struct attribute *rmi_firmware_attrs[] = { &dev_attr_update_fw.attr, + &dev_attr_update_fw_status.attr, NULL }; diff --git a/drivers/input/rmi4/rmi_f34.h b/drivers/input/rmi4/rmi_f34.h index 2c21056dc375..43a91349b28d 100644 --- a/drivers/input/rmi4/rmi_f34.h +++ b/drivers/input/rmi4/rmi_f34.h @@ -301,6 +301,10 @@ struct f34_data { unsigned char bootloader_id[5]; unsigned char configuration_id[CONFIG_ID_SIZE*2 + 1]; + int update_status; + int update_progress; + int update_size; + union { struct f34v5_data v5; struct f34v7_data v7; diff --git a/drivers/input/rmi4/rmi_f34v7.c b/drivers/input/rmi4/rmi_f34v7.c index ca31f9539d9b..56c6c39ad31e 100644 --- a/drivers/input/rmi4/rmi_f34v7.c +++ b/drivers/input/rmi4/rmi_f34v7.c @@ -588,6 +588,7 @@ static int rmi_f34v7_check_ui_firmware_size(struct f34_data *f34) u16 block_count; block_count = f34->v7.img.ui_firmware.size / f34->v7.block_size; + f34->update_size += block_count; if (block_count != f34->v7.blkcount.ui_firmware) { dev_err(&f34->fn->dev, @@ -604,6 +605,7 @@ static int rmi_f34v7_check_ui_config_size(struct f34_data *f34) u16 block_count; block_count = f34->v7.img.ui_config.size / f34->v7.block_size; + f34->update_size += block_count; if (block_count != f34->v7.blkcount.ui_config) { dev_err(&f34->fn->dev, "UI config size mismatch\n"); @@ -618,6 +620,7 @@ static int rmi_f34v7_check_dp_config_size(struct f34_data *f34) u16 block_count; block_count = f34->v7.img.dp_config.size / f34->v7.block_size; + f34->update_size += block_count; if (block_count != f34->v7.blkcount.dp_config) { dev_err(&f34->fn->dev, "Display config size mismatch\n"); @@ -632,6 +635,8 @@ static int rmi_f34v7_check_guest_code_size(struct f34_data *f34) u16 block_count; block_count = f34->v7.img.guest_code.size / f34->v7.block_size; + f34->update_size += block_count; + if (block_count != f34->v7.blkcount.guest_code) { dev_err(&f34->fn->dev, "Guest code size mismatch\n"); return -EINVAL; @@ -645,6 +650,7 @@ static int rmi_f34v7_check_bl_config_size(struct f34_data *f34) u16 block_count; block_count = f34->v7.img.bl_config.size / f34->v7.block_size; + f34->update_size += block_count; if (block_count != f34->v7.blkcount.bl_config) { dev_err(&f34->fn->dev, "Bootloader config size mismatch\n"); @@ -881,6 +887,9 @@ static int rmi_f34v7_write_f34v7_blocks(struct f34_data *f34, block_ptr += (transfer * f34->v7.block_size); remaining -= transfer; + f34->update_progress += transfer; + f34->update_status = (f34->update_progress * 100) / + f34->update_size; } while (remaining); return 0; @@ -1191,6 +1200,8 @@ int rmi_f34v7_do_reflash(struct f34_data *f34, const struct firmware *fw) rmi_f34v7_read_queries_bl_version(f34); f34->v7.image = fw->data; + f34->update_progress = 0; + f34->update_size = 0; ret = rmi_f34v7_parse_image_info(f34); if (ret < 0) From ce363f0dec73b8ec2209a02a7271a9e67ed61368 Mon Sep 17 00:00:00 2001 From: Nick Dyer Date: Tue, 31 Jan 2017 15:44:49 -0800 Subject: [PATCH 72/91] Input: synaptics-rmi4 - add sysfs interfaces for hardware IDs These attributes provide various bits of information which may be enumerated under the RMI4 protocol to user space. This may be useful for displaying the particular version which is in use, or selecting the correct firmware to flash. Signed-off-by: Nick Dyer Tested-by: Chris Healy Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_driver.c | 2 +- drivers/input/rmi4/rmi_driver.h | 2 +- drivers/input/rmi4/rmi_f01.c | 104 +++++++++++++++++++++++++++++++- drivers/input/rmi4/rmi_f34.c | 48 +++++++++++++++ 4 files changed, 152 insertions(+), 4 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 30397cc7283a..b3985500dd91 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -365,7 +365,7 @@ static void rmi_driver_set_input_name(struct rmi_device *rmi_dev, struct input_dev *input) { struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); - char *device_name = rmi_f01_get_product_ID(data->f01_container); + const char *device_name = rmi_f01_get_product_ID(data->f01_container); char *name; name = devm_kasprintf(&rmi_dev->dev, GFP_KERNEL, diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index 24f8f764d171..a480333a9e1c 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -104,7 +104,7 @@ int rmi_init_functions(struct rmi_driver_data *data); int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, const struct pdt_entry *pdt); -char *rmi_f01_get_product_ID(struct rmi_function *fn); +const char *rmi_f01_get_product_ID(struct rmi_function *fn); #ifdef CONFIG_RMI4_F34 int rmi_f34_create_sysfs(struct rmi_device *rmi_dev); diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c index cae35c6cde31..ed805d21633a 100644 --- a/drivers/input/rmi4/rmi_f01.c +++ b/drivers/input/rmi4/rmi_f01.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "rmi_driver.h" #define RMI_PRODUCT_ID_LENGTH 10 @@ -55,6 +56,7 @@ struct f01_basic_properties { u8 product_id[RMI_PRODUCT_ID_LENGTH + 1]; u16 productinfo; u32 firmware_id; + u32 package_id; }; /* F01 device status bits */ @@ -221,8 +223,19 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev, has_build_id_query = !!(queries[0] & BIT(1)); } - if (has_package_id_query) + if (has_package_id_query) { + ret = rmi_read_block(rmi_dev, prod_info_addr, + queries, sizeof(__le64)); + if (ret) { + dev_err(&rmi_dev->dev, + "Failed to read package info: %d\n", + ret); + return ret; + } + + props->package_id = get_unaligned_le64(queries); prod_info_addr++; + } if (has_build_id_query) { ret = rmi_read_block(rmi_dev, prod_info_addr, queries, @@ -242,13 +255,90 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev, return 0; } -char *rmi_f01_get_product_ID(struct rmi_function *fn) +const char *rmi_f01_get_product_ID(struct rmi_function *fn) { struct f01_data *f01 = dev_get_drvdata(&fn->dev); return f01->properties.product_id; } +static ssize_t rmi_driver_manufacturer_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); + + return scnprintf(buf, PAGE_SIZE, "%d\n", + f01->properties.manufacturer_id); +} + +static DEVICE_ATTR(manufacturer_id, 0444, + rmi_driver_manufacturer_id_show, NULL); + +static ssize_t rmi_driver_dom_show(struct device *dev, + struct device_attribute *dattr, char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); + + return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.dom); +} + +static DEVICE_ATTR(date_of_manufacture, 0444, rmi_driver_dom_show, NULL); + +static ssize_t rmi_driver_product_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); + + return scnprintf(buf, PAGE_SIZE, "%s\n", f01->properties.product_id); +} + +static DEVICE_ATTR(product_id, 0444, rmi_driver_product_id_show, NULL); + +static ssize_t rmi_driver_firmware_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); + + return scnprintf(buf, PAGE_SIZE, "%d\n", f01->properties.firmware_id); +} + +static DEVICE_ATTR(firmware_id, 0444, rmi_driver_firmware_id_show, NULL); + +static ssize_t rmi_driver_package_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct f01_data *f01 = dev_get_drvdata(&data->f01_container->dev); + + u32 package_id = f01->properties.package_id; + + return scnprintf(buf, PAGE_SIZE, "%04x.%04x\n", + package_id & 0xffff, (package_id >> 16) & 0xffff); +} + +static DEVICE_ATTR(package_id, 0444, rmi_driver_package_id_show, NULL); + +static struct attribute *rmi_f01_attrs[] = { + &dev_attr_manufacturer_id.attr, + &dev_attr_date_of_manufacture.attr, + &dev_attr_product_id.attr, + &dev_attr_firmware_id.attr, + &dev_attr_package_id.attr, + NULL +}; + +static struct attribute_group rmi_f01_attr_group = { + .attrs = rmi_f01_attrs, +}; + #ifdef CONFIG_OF static int rmi_f01_of_probe(struct device *dev, struct rmi_device_platform_data *pdata) @@ -481,9 +571,18 @@ static int rmi_f01_probe(struct rmi_function *fn) dev_set_drvdata(&fn->dev, f01); + error = sysfs_create_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group); + if (error) + dev_warn(&fn->dev, "Failed to create sysfs group: %d\n", error); + return 0; } +static void rmi_f01_remove(struct rmi_function *fn) +{ + sysfs_remove_group(&fn->rmi_dev->dev.kobj, &rmi_f01_attr_group); +} + static int rmi_f01_config(struct rmi_function *fn) { struct f01_data *f01 = dev_get_drvdata(&fn->dev); @@ -623,6 +722,7 @@ struct rmi_function_handler rmi_f01_handler = { }, .func = 0x01, .probe = rmi_f01_probe, + .remove = rmi_f01_remove, .config = rmi_f01_config, .attention = rmi_f01_attention, .suspend = rmi_f01_suspend, diff --git a/drivers/input/rmi4/rmi_f34.c b/drivers/input/rmi4/rmi_f34.c index 902b99007885..425fe140e9df 100644 --- a/drivers/input/rmi4/rmi_f34.c +++ b/drivers/input/rmi4/rmi_f34.c @@ -301,6 +301,52 @@ static int rmi_f34_status(struct rmi_function *fn) return f34->update_status; } +static ssize_t rmi_driver_bootloader_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct rmi_function *fn = data->f34_container; + struct f34_data *f34; + + if (fn) { + f34 = dev_get_drvdata(&fn->dev); + + if (f34->bl_version == 5) + return scnprintf(buf, PAGE_SIZE, "%c%c\n", + f34->bootloader_id[0], + f34->bootloader_id[1]); + else + return scnprintf(buf, PAGE_SIZE, "V%d.%d\n", + f34->bootloader_id[1], + f34->bootloader_id[0]); + } + + return 0; +} + +static DEVICE_ATTR(bootloader_id, 0444, rmi_driver_bootloader_id_show, NULL); + +static ssize_t rmi_driver_configuration_id_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + struct rmi_driver_data *data = dev_get_drvdata(dev); + struct rmi_function *fn = data->f34_container; + struct f34_data *f34; + + if (fn) { + f34 = dev_get_drvdata(&fn->dev); + + return scnprintf(buf, PAGE_SIZE, "%s\n", f34->configuration_id); + } + + return 0; +} + +static DEVICE_ATTR(configuration_id, 0444, + rmi_driver_configuration_id_show, NULL); + static int rmi_firmware_update(struct rmi_driver_data *data, const struct firmware *fw) { @@ -452,6 +498,8 @@ static DEVICE_ATTR(update_fw_status, 0444, rmi_driver_update_fw_status_show, NULL); static struct attribute *rmi_firmware_attrs[] = { + &dev_attr_bootloader_id.attr, + &dev_attr_configuration_id.attr, &dev_attr_update_fw.attr, &dev_attr_update_fw_status.attr, NULL From 6ecfe51b4082e7cff12609f97daa052ae04b61fd Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 31 Jan 2017 15:09:08 -0800 Subject: [PATCH 73/91] Input: refuse to register absolute devices without absinfo If device is supposed to send absolute events (i.e. EV_ABS bit is set in dev->evbit) but dev->absinfo is not allocated, then the driver has done something wrong, and we should not register such device. Otherwise we'll crash later, when driver tries to send absolute event. Reviewed-by: Benjamin Tissoires Acked-by: Jiri Kosina Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/input/input.c b/drivers/input/input.c index 6a75bb08b9ff..067d648028a2 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -2091,6 +2091,12 @@ int input_register_device(struct input_dev *dev) const char *path; int error; + if (test_bit(EV_ABS, dev->evbit) && !dev->absinfo) { + dev_err(&dev->dev, + "Absolute device without dev->absinfo, refusing to register\n"); + return -EINVAL; + } + if (dev->devres_managed) { devres = devres_alloc(devm_input_device_unregister, sizeof(struct input_devres), GFP_KERNEL); From 5ec69524d43095752510fdcdadc4a6baf50d7c18 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sat, 28 Jan 2017 11:01:33 -0800 Subject: [PATCH 74/91] Input: joydev - use clamp() macro We have a nice macro ensuring that the value is within certain range, let's use it instead of open-coding. Signed-off-by: Dmitry Torokhov --- drivers/input/joydev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index abd18f31b24f..5298a762b615 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -87,7 +87,7 @@ static int joydev_correct(int value, struct js_corr *corr) return 0; } - return value < -32767 ? -32767 : (value > 32767 ? 32767 : value); + return clamp(value, -32767, 32767); } static void joydev_pass_event(struct joydev_client *client, From 57b8443d3e5bd046a519ff714ca31c64c7f04309 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 6 Feb 2017 13:56:10 -0800 Subject: [PATCH 75/91] Input: xpad - fix stuck mode button on Xbox One S pad The Xbox One S requires an ack to its mode button report, otherwise it continuously retransmits the report. This makes the mode button appear to be stuck down after it is pressed for the first time. Signed-off-by: Cameron Gutman Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 247fd3a6fc03..03e24f56a35b 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -389,6 +389,7 @@ struct usb_xpad { static int xpad_init_input(struct usb_xpad *xpad); static void xpad_deinit_input(struct usb_xpad *xpad); +static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num); /* * xpad_process_packet @@ -622,6 +623,14 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char /* the xbox button has its own special report */ if (data[0] == 0X07) { + /* + * The Xbox One S controller requires these reports to be + * acked otherwise it continues sending them forever and + * won't report further mode button events. + */ + if (data[1] == 0x30) + xpadone_ack_mode_report(xpad, data[2]); + input_report_key(dev, BTN_MODE, data[4] & 0x01); input_sync(dev); return; @@ -954,6 +963,30 @@ static int xpad_start_xbox_one(struct usb_xpad *xpad) return retval; } +static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num) +{ + unsigned long flags; + struct xpad_output_packet *packet = + &xpad->out_packets[XPAD_OUT_CMD_IDX]; + static const u8 mode_report_ack[] = { + 0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + spin_lock_irqsave(&xpad->odata_lock, flags); + + packet->len = sizeof(mode_report_ack); + memcpy(packet->data, mode_report_ack, packet->len); + packet->data[2] = seq_num; + packet->pending = true; + + /* Reset the sequence so we send out the ack now */ + xpad->last_out_packet = -1; + xpad_try_sending_next_out_packet(xpad); + + spin_unlock_irqrestore(&xpad->odata_lock, flags); +} + #ifdef CONFIG_JOYSTICK_XPAD_FF static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) { From f32361b71ae5c81b8fb96f796ab947ba2ad17aa8 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Mon, 6 Feb 2017 09:57:01 -0800 Subject: [PATCH 76/91] Input: synaptics-rmi4 - add rmi_find_function() If a function needs to communicate with an other, it's better to have a way to retrieve this other. Reviewed-by: Andrew Duggan Signed-off-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_driver.c | 13 +++++++++++++ drivers/input/rmi4/rmi_driver.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index b3985500dd91..23d705be39d4 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -266,6 +266,19 @@ static int rmi_irq_init(struct rmi_device *rmi_dev) return 0; } +struct rmi_function *rmi_find_function(struct rmi_device *rmi_dev, u8 number) +{ + struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); + struct rmi_function *entry; + + list_for_each_entry(entry, &data->function_list, node) { + if (entry->fd.function_number == number) + return entry; + } + + return NULL; +} + static int suspend_one_function(struct rmi_function *fn) { struct rmi_function_handler *fh; diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index a480333a9e1c..6e0449cdca68 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -93,6 +93,7 @@ bool rmi_is_physical_driver(struct device_driver *); int rmi_register_physical_driver(void); void rmi_unregister_physical_driver(void); void rmi_free_function_list(struct rmi_device *rmi_dev); +struct rmi_function *rmi_find_function(struct rmi_device *rmi_dev, u8 number); int rmi_enable_sensor(struct rmi_device *rmi_dev); int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx, int (*callback)(struct rmi_device *rmi_dev, void *ctx, From a1fbf5bbef025b4844162b3b8868888003a7ee9c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 6 Feb 2017 17:03:03 -0800 Subject: [PATCH 77/91] Input: xpad - restore LED state after device resume Set the LED_CORE_SUSPENDRESUME flag on our LED device so the LED state will be automatically restored by LED core on resume. Since Xbox One pads stop flashing only when reinitialized, we'll send them the initialization packet so they calm down too. Signed-off-by: Cameron Gutman Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/xpad.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 03e24f56a35b..155fcb3b6230 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -1211,6 +1211,7 @@ static int xpad_led_probe(struct usb_xpad *xpad) led_cdev = &led->led_cdev; led_cdev->name = led->name; led_cdev->brightness_set = xpad_led_set; + led_cdev->flags = LED_CORE_SUSPENDRESUME; error = led_classdev_register(&xpad->udev->dev, led_cdev); if (error) @@ -1687,8 +1688,16 @@ static int xpad_resume(struct usb_interface *intf) retval = xpad360w_start_input(xpad); } else { mutex_lock(&input->mutex); - if (input->users) + if (input->users) { retval = xpad_start_input(xpad); + } else if (xpad->xtype == XTYPE_XBOXONE) { + /* + * Even if there are no users, we'll send Xbox One pads + * the startup sequence so they don't sit there and + * blink until somebody opens the input device again. + */ + retval = xpad_start_xbox_one(xpad); + } mutex_unlock(&input->mutex); } From e78395334ba6034b53e21e09ce8a50c303d130a9 Mon Sep 17 00:00:00 2001 From: Wei Yongjun Date: Tue, 7 Feb 2017 10:00:37 -0800 Subject: [PATCH 78/91] Input: synaptics-rmi4 - fix error return code in rmi_probe_interrupts() Fix to return error code -ENOMEM from the devm_kzalloc() error handling case instead of 0, as done elsewhere in this function. Fixes: 6bd0dcfacf28 ("Input: synaptics-rmi4 - factor out functions from probe") Signed-off-by: Wei Yongjun Reviewed-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 2aa3cd0fe222..746255830b47 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -1062,7 +1062,7 @@ int rmi_probe_interrupts(struct rmi_driver_data *data) data->irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL); if (!data->irq_memory) { dev_err(dev, "Failed to allocate memory for irq masks.\n"); - return retval; + return -ENOMEM; } data->irq_status = data->irq_memory + size * 0; From b44c4d3f1ee77e7947c525d6a907c0057fa238d2 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 20 Jan 2017 11:14:14 +0100 Subject: [PATCH 79/91] mfd: cros-ec: Update cros_ec_commands.h for buttons and switches Add the defines for the new buttons and switches connected to the CrosEC. Signed-off-by: Douglas Anderson Signed-off-by: Enric Balletbo i Serra Signed-off-by: Lee Jones --- include/linux/mfd/cros_ec_commands.h | 73 +++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h index 1683003603f3..004dcf3560fb 100644 --- a/include/linux/mfd/cros_ec_commands.h +++ b/include/linux/mfd/cros_ec_commands.h @@ -1839,18 +1839,69 @@ struct ec_response_tmp006_get_raw { * * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for * expected response size. + * + * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish + * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type + * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. */ #define EC_CMD_MKBP_STATE 0x60 -/* Provide information about the matrix : number of rows and columns */ +/* + * Provide information about various MKBP things. See enum ec_mkbp_info_type. + */ #define EC_CMD_MKBP_INFO 0x61 struct ec_response_mkbp_info { uint32_t rows; uint32_t cols; - uint8_t switches; + /* Formerly "switches", which was 0. */ + uint8_t reserved; } __packed; +struct ec_params_mkbp_info { + uint8_t info_type; + uint8_t event_type; +} __packed; + +enum ec_mkbp_info_type { + /* + * Info about the keyboard matrix: number of rows and columns. + * + * Returns struct ec_response_mkbp_info. + */ + EC_MKBP_INFO_KBD = 0, + + /* + * For buttons and switches, info about which specifically are + * supported. event_type must be set to one of the values in enum + * ec_mkbp_event. + * + * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte + * bitmask indicating which buttons or switches are present. See the + * bit inidices below. + */ + EC_MKBP_INFO_SUPPORTED = 1, + + /* + * Instantaneous state of buttons and switches. + * + * event_type must be set to one of the values in enum ec_mkbp_event. + * + * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] + * indicating the current state of the keyboard matrix. + * + * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw + * event state. + * + * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the + * state of supported buttons. + * + * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the + * state of supported switches. + */ + EC_MKBP_INFO_CURRENT = 2, +}; + /* Simulate key press */ #define EC_CMD_MKBP_SIMULATE_KEY 0x62 @@ -1983,6 +2034,12 @@ enum ec_mkbp_event { /* New Sensor FIFO data. The event data is fifo_info structure. */ EC_MKBP_EVENT_SENSOR_FIFO = 2, + /* The state of the non-matrixed buttons have changed. */ + EC_MKBP_EVENT_BUTTON = 3, + + /* The state of the switches have changed. */ + EC_MKBP_EVENT_SWITCH = 4, + /* Number of MKBP events */ EC_MKBP_EVENT_COUNT, }; @@ -1992,6 +2049,9 @@ union ec_response_get_next_data { /* Unaligned */ uint32_t host_event; + + uint32_t buttons; + uint32_t switches; } __packed; struct ec_response_get_next_event { @@ -2000,6 +2060,15 @@ struct ec_response_get_next_event { union ec_response_get_next_data data; } __packed; +/* Bit indices for buttons and switches.*/ +/* Buttons */ +#define EC_MKBP_POWER_BUTTON 0 +#define EC_MKBP_VOL_UP 1 +#define EC_MKBP_VOL_DOWN 2 + +/* Switches */ +#define EC_MKBP_LID_OPEN 0 + /*****************************************************************************/ /* Temperature sensor commands */ From cdd7950e7aa4a4d0d8ba71e3967aae6d25d09b03 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Fri, 20 Jan 2017 11:14:15 +0100 Subject: [PATCH 80/91] input: cros_ec_keyb: Add non-matrix buttons and switches On some newer boards using mkbp we're hooking up non-matrix buttons and switches to the EC but NOT to the main application processor. Let's add kernel support to handle this. Rather than creating a whole new input driver, we'll continue to use cros_ec_keyb and just report the new keys. Signed-off-by: Douglas Anderson Signed-off-by: Enric Balletbo i Serra Acked-by: Dmitry Torokhov Signed-off-by: Lee Jones --- drivers/input/keyboard/cros_ec_keyb.c | 449 +++++++++++++++++++++++--- 1 file changed, 403 insertions(+), 46 deletions(-) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index 25943e9bc8bf..ad74ebce0cdd 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -34,6 +34,8 @@ #include #include +#include + /* * @rows: Number of rows in the keypad * @cols: Number of columns in the keypad @@ -43,8 +45,9 @@ * @valid_keys: bitmap of existing keys for each matrix column * @old_kb_state: bitmap of keys pressed last scan * @dev: Device pointer - * @idev: Input device * @ec: Top level ChromeOS device to use to talk to EC + * @idev: The input device for the matrix keys. + * @bs_idev: The input device for non-matrix buttons and switches (or NULL). * @notifier: interrupt event notifier for transport devices */ struct cros_ec_keyb { @@ -57,12 +60,59 @@ struct cros_ec_keyb { uint8_t *old_kb_state; struct device *dev; - struct input_dev *idev; struct cros_ec_device *ec; + + struct input_dev *idev; + struct input_dev *bs_idev; struct notifier_block notifier; }; +/** + * cros_ec_bs_map - Struct mapping Linux keycodes to EC button/switch bitmap + * #defines + * + * @ev_type: The type of the input event to generate (e.g., EV_KEY). + * @code: A linux keycode + * @bit: A #define like EC_MKBP_POWER_BUTTON or EC_MKBP_LID_OPEN + * @inverted: If the #define and EV_SW have opposite meanings, this is true. + * Only applicable to switches. + */ +struct cros_ec_bs_map { + unsigned int ev_type; + unsigned int code; + u8 bit; + bool inverted; +}; + +/* cros_ec_keyb_bs - Map EC button/switch #defines into kernel ones */ +static const struct cros_ec_bs_map cros_ec_keyb_bs[] = { + /* Buttons */ + { + .ev_type = EV_KEY, + .code = KEY_POWER, + .bit = EC_MKBP_POWER_BUTTON, + }, + { + .ev_type = EV_KEY, + .code = KEY_VOLUMEUP, + .bit = EC_MKBP_VOL_UP, + }, + { + .ev_type = EV_KEY, + .code = KEY_VOLUMEDOWN, + .bit = EC_MKBP_VOL_DOWN, + }, + + /* Switches */ + { + .ev_type = EV_SW, + .code = SW_LID, + .bit = EC_MKBP_LID_OPEN, + .inverted = true, + }, +}; + /* * Returns true when there is at least one combination of pressed keys that * results in ghosting. @@ -149,20 +199,33 @@ static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev, input_sync(ckdev->idev); } -static int cros_ec_keyb_open(struct input_dev *dev) +/** + * cros_ec_keyb_report_bs - Report non-matrixed buttons or switches + * + * This takes a bitmap of buttons or switches from the EC and reports events, + * syncing at the end. + * + * @ckdev: The keyboard device. + * @ev_type: The input event type (e.g., EV_KEY). + * @mask: A bitmap of buttons from the EC. + */ +static void cros_ec_keyb_report_bs(struct cros_ec_keyb *ckdev, + unsigned int ev_type, u32 mask) + { - struct cros_ec_keyb *ckdev = input_get_drvdata(dev); + struct input_dev *idev = ckdev->bs_idev; + int i; - return blocking_notifier_chain_register(&ckdev->ec->event_notifier, - &ckdev->notifier); -} + for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) { + const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i]; -static void cros_ec_keyb_close(struct input_dev *dev) -{ - struct cros_ec_keyb *ckdev = input_get_drvdata(dev); + if (map->ev_type != ev_type) + continue; - blocking_notifier_chain_unregister(&ckdev->ec->event_notifier, - &ckdev->notifier); + input_event(idev, ev_type, map->code, + !!(mask & BIT(map->bit)) ^ map->inverted); + } + input_sync(idev); } static int cros_ec_keyb_work(struct notifier_block *nb, @@ -170,22 +233,54 @@ static int cros_ec_keyb_work(struct notifier_block *nb, { struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb, notifier); + u32 val; + unsigned int ev_type; - if (ckdev->ec->event_data.event_type != EC_MKBP_EVENT_KEY_MATRIX) + switch (ckdev->ec->event_data.event_type) { + case EC_MKBP_EVENT_KEY_MATRIX: + /* + * If EC is not the wake source, discard key state changes + * during suspend. + */ + if (queued_during_suspend) + return NOTIFY_OK; + + if (ckdev->ec->event_size != ckdev->cols) { + dev_err(ckdev->dev, + "Discarded incomplete key matrix event.\n"); + return NOTIFY_OK; + } + cros_ec_keyb_process(ckdev, + ckdev->ec->event_data.data.key_matrix, + ckdev->ec->event_size); + break; + + case EC_MKBP_EVENT_BUTTON: + case EC_MKBP_EVENT_SWITCH: + /* + * If EC is not the wake source, discard key state + * changes during suspend. Switches will be re-checked in + * cros_ec_keyb_resume() to be sure nothing is lost. + */ + if (queued_during_suspend) + return NOTIFY_OK; + + if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) { + val = get_unaligned_le32( + &ckdev->ec->event_data.data.buttons); + ev_type = EV_KEY; + } else { + val = get_unaligned_le32( + &ckdev->ec->event_data.data.switches); + ev_type = EV_SW; + } + cros_ec_keyb_report_bs(ckdev, ev_type, val); + break; + + default: return NOTIFY_DONE; - /* - * If EC is not the wake source, discard key state changes during - * suspend. - */ - if (queued_during_suspend) - return NOTIFY_OK; - if (ckdev->ec->event_size != ckdev->cols) { - dev_err(ckdev->dev, - "Discarded incomplete key matrix event.\n"); - return NOTIFY_OK; } - cros_ec_keyb_process(ckdev, ckdev->ec->event_data.data.key_matrix, - ckdev->ec->event_size); + return NOTIFY_OK; } @@ -213,22 +308,228 @@ static void cros_ec_keyb_compute_valid_keys(struct cros_ec_keyb *ckdev) } } -static int cros_ec_keyb_probe(struct platform_device *pdev) +/** + * cros_ec_keyb_info - Wrap the EC command EC_CMD_MKBP_INFO + * + * This wraps the EC_CMD_MKBP_INFO, abstracting out all of the marshalling and + * unmarshalling and different version nonsense into something simple. + * + * @ec_dev: The EC device + * @info_type: Either EC_MKBP_INFO_SUPPORTED or EC_MKBP_INFO_CURRENT. + * @event_type: Either EC_MKBP_EVENT_BUTTON or EC_MKBP_EVENT_SWITCH. Actually + * in some cases this could be EC_MKBP_EVENT_KEY_MATRIX or + * EC_MKBP_EVENT_HOST_EVENT too but we don't use in this driver. + * @result: Where we'll store the result; a union + * @result_size: The size of the result. Expected to be the size of one of + * the elements in the union. + * + * Returns 0 if no error or -error upon error. + */ +static int cros_ec_keyb_info(struct cros_ec_device *ec_dev, + enum ec_mkbp_info_type info_type, + enum ec_mkbp_event event_type, + union ec_response_get_next_data *result, + size_t result_size) { - struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); - struct device *dev = &pdev->dev; - struct cros_ec_keyb *ckdev; + struct ec_params_mkbp_info *params; + struct cros_ec_command *msg; + int ret; + + msg = kzalloc(sizeof(*msg) + max_t(size_t, result_size, + sizeof(*params)), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + msg->command = EC_CMD_MKBP_INFO; + msg->version = 1; + msg->outsize = sizeof(*params); + msg->insize = result_size; + params = (struct ec_params_mkbp_info *)msg->data; + params->info_type = info_type; + params->event_type = event_type; + + ret = cros_ec_cmd_xfer(ec_dev, msg); + if (ret < 0) { + dev_warn(ec_dev->dev, "Transfer error %d/%d: %d\n", + (int)info_type, (int)event_type, ret); + } else if (msg->result == EC_RES_INVALID_VERSION) { + /* With older ECs we just return 0 for everything */ + memset(result, 0, result_size); + ret = 0; + } else if (msg->result != EC_RES_SUCCESS) { + dev_warn(ec_dev->dev, "Error getting info %d/%d: %d\n", + (int)info_type, (int)event_type, msg->result); + ret = -EPROTO; + } else if (ret != result_size) { + dev_warn(ec_dev->dev, "Wrong size %d/%d: %d != %zu\n", + (int)info_type, (int)event_type, + ret, result_size); + ret = -EPROTO; + } else { + memcpy(result, msg->data, result_size); + ret = 0; + } + + kfree(msg); + + return ret; +} + +/** + * cros_ec_keyb_query_switches - Query the state of switches and report + * + * This will ask the EC about the current state of switches and report to the + * kernel. Note that we don't query for buttons because they are more + * transitory and we'll get an update on the next release / press. + * + * @ckdev: The keyboard device + * + * Returns 0 if no error or -error upon error. + */ +static int cros_ec_keyb_query_switches(struct cros_ec_keyb *ckdev) +{ + struct cros_ec_device *ec_dev = ckdev->ec; + union ec_response_get_next_data event_data = {}; + int ret; + + ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_CURRENT, + EC_MKBP_EVENT_SWITCH, &event_data, + sizeof(event_data.switches)); + if (ret) + return ret; + + cros_ec_keyb_report_bs(ckdev, EV_SW, + get_unaligned_le32(&event_data.switches)); + + return 0; +} + +/** + * cros_ec_keyb_resume - Resume the keyboard + * + * We use the resume notification as a chance to query the EC for switches. + * + * @dev: The keyboard device + * + * Returns 0 if no error or -error upon error. + */ +static __maybe_unused int cros_ec_keyb_resume(struct device *dev) +{ + struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); + + if (ckdev->bs_idev) + return cros_ec_keyb_query_switches(ckdev); + + return 0; +} + +/** + * cros_ec_keyb_register_bs - Register non-matrix buttons/switches + * + * Handles all the bits of the keyboard driver related to non-matrix buttons + * and switches, including asking the EC about which are present and telling + * the kernel to expect them. + * + * If this device has no support for buttons and switches we'll return no error + * but the ckdev->bs_idev will remain NULL when this function exits. + * + * @ckdev: The keyboard device + * + * Returns 0 if no error or -error upon error. + */ +static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev) +{ + struct cros_ec_device *ec_dev = ckdev->ec; + struct device *dev = ckdev->dev; struct input_dev *idev; - struct device_node *np; + union ec_response_get_next_data event_data = {}; + const char *phys; + u32 buttons; + u32 switches; + int ret; + int i; + + ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED, + EC_MKBP_EVENT_BUTTON, &event_data, + sizeof(event_data.buttons)); + if (ret) + return ret; + buttons = get_unaligned_le32(&event_data.buttons); + + ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED, + EC_MKBP_EVENT_SWITCH, &event_data, + sizeof(event_data.switches)); + if (ret) + return ret; + switches = get_unaligned_le32(&event_data.switches); + + if (!buttons && !switches) + return 0; + + /* + * We call the non-matrix buttons/switches 'input1', if present. + * Allocate phys before input dev, to ensure correct tear-down + * ordering. + */ + phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input1", ec_dev->phys_name); + if (!phys) + return -ENOMEM; + + idev = devm_input_allocate_device(dev); + if (!idev) + return -ENOMEM; + + idev->name = "cros_ec_buttons"; + idev->phys = phys; + __set_bit(EV_REP, idev->evbit); + + idev->id.bustype = BUS_VIRTUAL; + idev->id.version = 1; + idev->id.product = 0; + idev->dev.parent = dev; + + input_set_drvdata(idev, ckdev); + ckdev->bs_idev = idev; + + for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) { + const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i]; + + if (buttons & BIT(map->bit)) + input_set_capability(idev, map->ev_type, map->code); + } + + ret = cros_ec_keyb_query_switches(ckdev); + if (ret) { + dev_err(dev, "cannot query switches\n"); + return ret; + } + + ret = input_register_device(ckdev->bs_idev); + if (ret) { + dev_err(dev, "cannot register input device\n"); + return ret; + } + + return 0; +} + +/** + * cros_ec_keyb_register_bs - Register matrix keys + * + * Handles all the bits of the keyboard driver related to matrix keys. + * + * @ckdev: The keyboard device + * + * Returns 0 if no error or -error upon error. + */ +static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) +{ + struct cros_ec_device *ec_dev = ckdev->ec; + struct device *dev = ckdev->dev; + struct input_dev *idev; + const char *phys; int err; - np = pdev->dev.of_node; - if (!np) - return -ENODEV; - - ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); - if (!ckdev) - return -ENOMEM; err = matrix_keypad_parse_of_params(dev, &ckdev->rows, &ckdev->cols); if (err) return err; @@ -241,27 +542,28 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) if (!ckdev->old_kb_state) return -ENOMEM; + /* + * We call the keyboard matrix 'input0'. Allocate phys before input + * dev, to ensure correct tear-down ordering. + */ + phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", ec_dev->phys_name); + if (!phys) + return -ENOMEM; + idev = devm_input_allocate_device(dev); if (!idev) return -ENOMEM; - ckdev->ec = ec; - ckdev->notifier.notifier_call = cros_ec_keyb_work; - ckdev->dev = dev; - dev_set_drvdata(dev, ckdev); - idev->name = CROS_EC_DEV_NAME; - idev->phys = ec->phys_name; + idev->phys = phys; __set_bit(EV_REP, idev->evbit); idev->id.bustype = BUS_VIRTUAL; idev->id.version = 1; idev->id.product = 0; idev->dev.parent = dev; - idev->open = cros_ec_keyb_open; - idev->close = cros_ec_keyb_close; - ckdev->ghost_filter = of_property_read_bool(np, + ckdev->ghost_filter = of_property_read_bool(dev->of_node, "google,needs-ghost-filter"); err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols, @@ -287,6 +589,57 @@ static int cros_ec_keyb_probe(struct platform_device *pdev) return 0; } +static int cros_ec_keyb_probe(struct platform_device *pdev) +{ + struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct cros_ec_keyb *ckdev; + int err; + + if (!dev->of_node) + return -ENODEV; + + ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL); + if (!ckdev) + return -ENOMEM; + + ckdev->ec = ec; + ckdev->dev = dev; + dev_set_drvdata(dev, ckdev); + + err = cros_ec_keyb_register_matrix(ckdev); + if (err) { + dev_err(dev, "cannot register matrix inputs: %d\n", err); + return err; + } + + err = cros_ec_keyb_register_bs(ckdev); + if (err) { + dev_err(dev, "cannot register non-matrix inputs: %d\n", err); + return err; + } + + ckdev->notifier.notifier_call = cros_ec_keyb_work; + err = blocking_notifier_chain_register(&ckdev->ec->event_notifier, + &ckdev->notifier); + if (err) { + dev_err(dev, "cannot register notifier: %d\n", err); + return err; + } + + return 0; +} + +static int cros_ec_keyb_remove(struct platform_device *pdev) +{ + struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev); + + blocking_notifier_chain_unregister(&ckdev->ec->event_notifier, + &ckdev->notifier); + + return 0; +} + #ifdef CONFIG_OF static const struct of_device_id cros_ec_keyb_of_match[] = { { .compatible = "google,cros-ec-keyb" }, @@ -295,11 +648,15 @@ static const struct of_device_id cros_ec_keyb_of_match[] = { MODULE_DEVICE_TABLE(of, cros_ec_keyb_of_match); #endif +static const SIMPLE_DEV_PM_OPS(cros_ec_keyb_pm_ops, NULL, cros_ec_keyb_resume); + static struct platform_driver cros_ec_keyb_driver = { .probe = cros_ec_keyb_probe, + .remove = cros_ec_keyb_remove, .driver = { .name = "cros-ec-keyb", .of_match_table = of_match_ptr(cros_ec_keyb_of_match), + .pm = &cros_ec_keyb_pm_ops, }, }; From 19ba1eb15a2a9b7298d1d984043025ab9496fbfb Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 7 Feb 2017 23:58:02 -0800 Subject: [PATCH 81/91] Input: psmouse - add a custom serio protocol to send extra information The tracksticks on the Lenovo thinkpads have their buttons connected through the touchpad device. We already fixed that in synaptics.c, but when we switch the device into RMI4 mode to have proper support, the pass-through functionality can't deal with them easily. We add a new PS/2 flag and protocol designed for psmouse. The RMI4 F03 pass-through can then emit a special set of commands to notify psmouse the state of the buttons. This patch implements the protocol in psmouse, while an other will do the same for rmi4-f03. Signed-off-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/psmouse-base.c | 41 +++++++++++++++++++++++++++--- drivers/input/mouse/psmouse.h | 5 ++++ include/uapi/linux/serio.h | 7 ++--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index bee267424972..a598b7223cef 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -127,6 +127,13 @@ struct psmouse_protocol { int (*init)(struct psmouse *); }; +static void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) +{ + input_report_key(dev, BTN_LEFT, buttons & BIT(0)); + input_report_key(dev, BTN_MIDDLE, buttons & BIT(2)); + input_report_key(dev, BTN_RIGHT, buttons & BIT(1)); +} + /* * psmouse_process_byte() analyzes the PS/2 data stream and reports * relevant events to the input module once full packet has arrived. @@ -199,9 +206,8 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) } /* Generic PS/2 Mouse */ - input_report_key(dev, BTN_LEFT, packet[0] & 1); - input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); - input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); + psmouse_report_standard_buttons(dev, + packet[0] | psmouse->extra_buttons); input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); @@ -282,6 +288,30 @@ static int psmouse_handle_byte(struct psmouse *psmouse) return 0; } +static void psmouse_handle_oob_data(struct psmouse *psmouse, u8 data) +{ + switch (psmouse->oob_data_type) { + case PSMOUSE_OOB_NONE: + psmouse->oob_data_type = data; + break; + + case PSMOUSE_OOB_EXTRA_BTNS: + psmouse_report_standard_buttons(psmouse->dev, data); + input_sync(psmouse->dev); + + psmouse->extra_buttons = data; + psmouse->oob_data_type = PSMOUSE_OOB_NONE; + break; + + default: + psmouse_warn(psmouse, + "unknown OOB_DATA type: 0x%02x\n", + psmouse->oob_data_type); + psmouse->oob_data_type = PSMOUSE_OOB_NONE; + break; + } +} + /* * psmouse_interrupt() handles incoming characters, either passing them * for normal processing or gathering them as command response. @@ -306,6 +336,11 @@ static irqreturn_t psmouse_interrupt(struct serio *serio, goto out; } + if (flags & SERIO_OOB_DATA) { + psmouse_handle_oob_data(psmouse, data); + goto out; + } + if (unlikely(psmouse->ps2dev.flags & PS2_FLAG_ACK)) if (ps2_handle_ack(&psmouse->ps2dev, data)) goto out; diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h index e0ca6cda3d16..8c83b8e2505c 100644 --- a/drivers/input/mouse/psmouse.h +++ b/drivers/input/mouse/psmouse.h @@ -1,6 +1,9 @@ #ifndef _PSMOUSE_H #define _PSMOUSE_H +#define PSMOUSE_OOB_NONE 0x00 +#define PSMOUSE_OOB_EXTRA_BTNS 0x01 + #define PSMOUSE_CMD_SETSCALE11 0x00e6 #define PSMOUSE_CMD_SETSCALE21 0x00e7 #define PSMOUSE_CMD_SETRES 0x10e8 @@ -53,6 +56,8 @@ struct psmouse { unsigned char pktcnt; unsigned char pktsize; unsigned char type; + unsigned char oob_data_type; + unsigned char extra_buttons; bool ignore_parity; bool acks_disable_command; unsigned int model; diff --git a/include/uapi/linux/serio.h b/include/uapi/linux/serio.h index f2447a83ac8d..ccd0ccd00f47 100644 --- a/include/uapi/linux/serio.h +++ b/include/uapi/linux/serio.h @@ -17,9 +17,10 @@ /* * bit masks for use in "interrupt" flags (3rd argument) */ -#define SERIO_TIMEOUT 1 -#define SERIO_PARITY 2 -#define SERIO_FRAME 4 +#define SERIO_TIMEOUT BIT(0) +#define SERIO_PARITY BIT(1) +#define SERIO_FRAME BIT(2) +#define SERIO_OOB_DATA BIT(3) /* * Serio types From bf23cfc34317dcc10d5a52f27affb1c4dcc60a98 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 9 Feb 2017 11:34:08 -0800 Subject: [PATCH 82/91] Input: synaptics - use SERIO_OOB_DATA to handle trackstick buttons Instead of using custom method of "passing" extended buttons from the touchpad to trackstick, let's switch to the newly introduced SERIO_OOB_DATA channel. Tested-By: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/synaptics.c | 26 +++++++++++++------------- drivers/input/mouse/synaptics.h | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index a41d8328c064..597ee4b01d9f 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -597,15 +597,13 @@ static int synaptics_is_pt_packet(unsigned char *buf) return (buf[0] & 0xFC) == 0x84 && (buf[3] & 0xCC) == 0xC4; } -static void synaptics_pass_pt_packet(struct psmouse *psmouse, - struct serio *ptport, +static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet) { - struct synaptics_data *priv = psmouse->private; struct psmouse *child = serio_get_drvdata(ptport); if (child && child->state == PSMOUSE_ACTIVATED) { - serio_interrupt(ptport, packet[1] | priv->pt_buttons, 0); + serio_interrupt(ptport, packet[1], 0); serio_interrupt(ptport, packet[4], 0); serio_interrupt(ptport, packet[5], 0); if (child->pktsize == 4) @@ -856,7 +854,6 @@ static void synaptics_report_ext_buttons(struct psmouse *psmouse, struct input_dev *dev = psmouse->dev; struct synaptics_data *priv = psmouse->private; int ext_bits = (SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap) + 1) >> 1; - char buf[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int i; if (!SYN_CAP_MULTI_BUTTON_NO(priv->ext_cap)) @@ -883,15 +880,18 @@ static void synaptics_report_ext_buttons(struct psmouse *psmouse, * physically wired to the touchpad. Re-route them through * the pass-through interface. */ - if (!priv->pt_port) - return; + if (priv->pt_port) { + u8 pt_buttons; - /* The trackstick expects at most 3 buttons */ - priv->pt_buttons = SYN_CAP_EXT_BUTTON_STICK_L(hw->ext_buttons) | - SYN_CAP_EXT_BUTTON_STICK_R(hw->ext_buttons) << 1 | - SYN_CAP_EXT_BUTTON_STICK_M(hw->ext_buttons) << 2; + /* The trackstick expects at most 3 buttons */ + pt_buttons = SYN_CAP_EXT_BUTTON_STICK_L(hw->ext_buttons) | + SYN_CAP_EXT_BUTTON_STICK_R(hw->ext_buttons) << 1 | + SYN_CAP_EXT_BUTTON_STICK_M(hw->ext_buttons) << 2; - synaptics_pass_pt_packet(psmouse, priv->pt_port, buf); + serio_interrupt(priv->pt_port, + PSMOUSE_OOB_EXTRA_BTNS, SERIO_OOB_DATA); + serio_interrupt(priv->pt_port, pt_buttons, SERIO_OOB_DATA); + } } static void synaptics_report_buttons(struct psmouse *psmouse, @@ -1132,7 +1132,7 @@ static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse) if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) { if (priv->pt_port) - synaptics_pass_pt_packet(psmouse, priv->pt_port, + synaptics_pass_pt_packet(priv->pt_port, psmouse->packet); } else synaptics_process_packet(psmouse); diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h index 56faa7ec4434..116ae2546ace 100644 --- a/drivers/input/mouse/synaptics.h +++ b/drivers/input/mouse/synaptics.h @@ -183,7 +183,6 @@ struct synaptics_data { bool disable_gesture; /* disable gestures */ struct serio *pt_port; /* Pass-through serio port */ - unsigned char pt_buttons; /* Pass-through buttons */ /* * Last received Advanced Gesture Mode (AGM) packet. An AGM packet From bf3e8502eefdbb7ac1b8163e5c3acdcb505ae745 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Wed, 8 Feb 2017 12:02:07 -0800 Subject: [PATCH 83/91] Input: synaptics-rmi4 - clean up F30 implementation This patch does several cleanup changes to F30 code - switch to using BIT() macro - use DIV_ROUND_UP() where appropriate - factor out code setting up and reporting buttons - use single loop when reporting buttons: arithmetic is cheap compared to conditionals and associated branch misprediction. Tested-By: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f30.c | 328 ++++++++++++++++------------------- 1 file changed, 145 insertions(+), 183 deletions(-) diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c index f4b491e3e0fd..c5eb4d034e84 100644 --- a/drivers/input/rmi4/rmi_f30.c +++ b/drivers/input/rmi4/rmi_f30.c @@ -16,30 +16,24 @@ /* Defs for Query 0 */ #define RMI_F30_EXTENDED_PATTERNS 0x01 -#define RMI_F30_HAS_MAPPABLE_BUTTONS (1 << 1) -#define RMI_F30_HAS_LED (1 << 2) -#define RMI_F30_HAS_GPIO (1 << 3) -#define RMI_F30_HAS_HAPTIC (1 << 4) -#define RMI_F30_HAS_GPIO_DRV_CTL (1 << 5) -#define RMI_F30_HAS_MECH_MOUSE_BTNS (1 << 6) +#define RMI_F30_HAS_MAPPABLE_BUTTONS BIT(1) +#define RMI_F30_HAS_LED BIT(2) +#define RMI_F30_HAS_GPIO BIT(3) +#define RMI_F30_HAS_HAPTIC BIT(4) +#define RMI_F30_HAS_GPIO_DRV_CTL BIT(5) +#define RMI_F30_HAS_MECH_MOUSE_BTNS BIT(6) /* Defs for Query 1 */ #define RMI_F30_GPIO_LED_COUNT 0x1F /* Defs for Control Registers */ #define RMI_F30_CTRL_1_GPIO_DEBOUNCE 0x01 -#define RMI_F30_CTRL_1_HALT (1 << 4) -#define RMI_F30_CTRL_1_HALTED (1 << 5) +#define RMI_F30_CTRL_1_HALT BIT(4) +#define RMI_F30_CTRL_1_HALTED BIT(5) #define RMI_F30_CTRL_10_NUM_MECH_MOUSE_BTNS 0x03 -struct rmi_f30_ctrl_data { - int address; - int length; - u8 *regs; -}; - #define RMI_F30_CTRL_MAX_REGS 32 -#define RMI_F30_CTRL_MAX_BYTES ((RMI_F30_CTRL_MAX_REGS + 7) >> 3) +#define RMI_F30_CTRL_MAX_BYTES DIV_ROUND_UP(RMI_F30_CTRL_MAX_REGS, 8) #define RMI_F30_CTRL_MAX_REG_BLOCKS 11 #define RMI_F30_CTRL_REGS_MAX_SIZE (RMI_F30_CTRL_MAX_BYTES \ @@ -54,6 +48,12 @@ struct rmi_f30_ctrl_data { + 1 \ + 1) +struct rmi_f30_ctrl_data { + int address; + int length; + u8 *regs; +}; + struct f30_data { /* Query Data */ bool has_extended_pattern; @@ -81,13 +81,13 @@ struct f30_data { static int rmi_f30_read_control_parameters(struct rmi_function *fn, struct f30_data *f30) { - struct rmi_device *rmi_dev = fn->rmi_dev; - int error = 0; + int error; - error = rmi_read_block(rmi_dev, fn->fd.control_base_addr, - f30->ctrl_regs, f30->ctrl_regs_size); + error = rmi_read_block(fn->rmi_dev, fn->fd.control_base_addr, + f30->ctrl_regs, f30->ctrl_regs_size); if (error) { - dev_err(&rmi_dev->dev, "%s : Could not read control registers at 0x%x error (%d)\n", + dev_err(&fn->dev, + "%s: Could not read control registers at 0x%x: %d\n", __func__, fn->fd.control_base_addr, error); return error; } @@ -95,24 +95,32 @@ static int rmi_f30_read_control_parameters(struct rmi_function *fn, return 0; } +static void rmi_f30_report_button(struct rmi_function *fn, + struct f30_data *f30, unsigned int button) +{ + unsigned int reg_num = button >> 3; + unsigned int bit_num = button & 0x07; + bool key_down = !(f30->data_regs[reg_num] & BIT(bit_num)); + + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "%s: call input report key (0x%04x) value (0x%02x)", + __func__, f30->gpioled_key_map[button], key_down); + + input_report_key(f30->input, f30->gpioled_key_map[button], key_down); +} + static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits) { struct f30_data *f30 = dev_get_drvdata(&fn->dev); - struct rmi_device *rmi_dev = fn->rmi_dev; - struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); - int retval; - int gpiled = 0; - int value = 0; + struct rmi_driver_data *drvdata = dev_get_drvdata(&fn->rmi_dev->dev); + int error; int i; - int reg_num; - - if (!f30->input) - return 0; /* Read the gpi led data. */ if (drvdata->attn_data.data) { if (drvdata->attn_data.size < f30->register_count) { - dev_warn(&fn->dev, "F30 interrupted, but data is missing\n"); + dev_warn(&fn->dev, + "F30 interrupted, but data is missing\n"); return 0; } memcpy(f30->data_regs, drvdata->attn_data.data, @@ -120,72 +128,21 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits) drvdata->attn_data.data += f30->register_count; drvdata->attn_data.size -= f30->register_count; } else { - retval = rmi_read_block(rmi_dev, fn->fd.data_base_addr, - f30->data_regs, f30->register_count); - - if (retval) { - dev_err(&fn->dev, "%s: Failed to read F30 data registers.\n", - __func__); - return retval; + error = rmi_read_block(fn->rmi_dev, fn->fd.data_base_addr, + f30->data_regs, f30->register_count); + if (error) { + dev_err(&fn->dev, + "%s: Failed to read F30 data registers: %d\n", + __func__, error); + return error; } } - for (reg_num = 0; reg_num < f30->register_count; ++reg_num) { - for (i = 0; gpiled < f30->gpioled_count && i < 8; ++i, - ++gpiled) { - if (f30->gpioled_key_map[gpiled] != 0) { - /* buttons have pull up resistors */ - value = (((f30->data_regs[reg_num] >> i) & 0x01) - == 0); + if (f30->has_gpio) + for (i = 0; i < f30->gpioled_count; i++) + if (f30->gpioled_key_map[i] != KEY_RESERVED) + rmi_f30_report_button(fn, f30, i); - rmi_dbg(RMI_DEBUG_FN, &fn->dev, - "%s: call input report key (0x%04x) value (0x%02x)", - __func__, - f30->gpioled_key_map[gpiled], value); - input_report_key(f30->input, - f30->gpioled_key_map[gpiled], - value); - } - - } - } - - return 0; -} - -static int rmi_f30_register_device(struct rmi_function *fn) -{ - int i; - struct rmi_device *rmi_dev = fn->rmi_dev; - struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev); - struct f30_data *f30 = dev_get_drvdata(&fn->dev); - struct input_dev *input_dev; - int button_count = 0; - - input_dev = drv_data->input; - if (!input_dev) { - dev_info(&fn->dev, "F30: no input device found, ignoring.\n"); - return -EINVAL; - } - - f30->input = input_dev; - - set_bit(EV_KEY, input_dev->evbit); - - input_dev->keycode = f30->gpioled_key_map; - input_dev->keycodesize = sizeof(u16); - input_dev->keycodemax = f30->gpioled_count; - - for (i = 0; i < f30->gpioled_count; i++) { - if (f30->gpioled_key_map[i] != 0) { - input_set_capability(input_dev, EV_KEY, - f30->gpioled_key_map[i]); - button_count++; - } - } - - if (button_count == 1) - __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); return 0; } @@ -204,19 +161,20 @@ static int rmi_f30_config(struct rmi_function *fn) error = rmi_write_block(fn->rmi_dev, fn->fd.control_base_addr, f30->ctrl_regs, f30->ctrl_regs_size); if (error) { - dev_err(&fn->rmi_dev->dev, - "%s : Could not write control registers at 0x%x error (%d)\n", + dev_err(&fn->dev, + "%s: Could not write control registers at 0x%x: %d\n", __func__, fn->fd.control_base_addr, error); return error; } drv->set_irq_bits(fn->rmi_dev, fn->irq_mask); } + return 0; } -static inline void rmi_f30_set_ctrl_data(struct rmi_f30_ctrl_data *ctrl, - int *ctrl_addr, int len, u8 **reg) +static void rmi_f30_set_ctrl_data(struct rmi_f30_ctrl_data *ctrl, + int *ctrl_addr, int len, u8 **reg) { ctrl->address = *ctrl_addr; ctrl->length = len; @@ -225,8 +183,7 @@ static inline void rmi_f30_set_ctrl_data(struct rmi_f30_ctrl_data *ctrl, *reg += len; } -static inline bool rmi_f30_is_valid_button(int button, - struct rmi_f30_ctrl_data *ctrl) +static bool rmi_f30_is_valid_button(int button, struct rmi_f30_ctrl_data *ctrl) { int byte_position = button >> 3; int bit_position = button & 0x07; @@ -239,32 +196,60 @@ static inline bool rmi_f30_is_valid_button(int button, (ctrl[3].regs[byte_position] & BIT(bit_position)); } -static inline int rmi_f30_initialize(struct rmi_function *fn) +static int rmi_f30_map_gpios(struct rmi_function *fn, + struct f30_data *f30) { - struct f30_data *f30; - struct rmi_device *rmi_dev = fn->rmi_dev; - const struct rmi_device_platform_data *pdata; - int retval = 0; - int control_address; + const struct rmi_device_platform_data *pdata = + rmi_get_platform_data(fn->rmi_dev); + struct input_dev *input = f30->input; + unsigned int button = BTN_LEFT; int i; - int button; - u8 buf[RMI_F30_QUERY_SIZE]; - u8 *ctrl_reg; - u8 *map_memory; - f30 = devm_kzalloc(&fn->dev, sizeof(struct f30_data), - GFP_KERNEL); - if (!f30) + f30->gpioled_key_map = devm_kcalloc(&fn->dev, + f30->gpioled_count, + sizeof(f30->gpioled_key_map[0]), + GFP_KERNEL); + if (!f30->gpioled_key_map) { + dev_err(&fn->dev, "Failed to allocate gpioled map memory.\n"); return -ENOMEM; + } - dev_set_drvdata(&fn->dev, f30); + for (i = 0; i < f30->gpioled_count; i++) { + if (rmi_f30_is_valid_button(i, f30->ctrl)) { + f30->gpioled_key_map[i] = button; + input_set_capability(input, EV_KEY, button++); - retval = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr, buf, - RMI_F30_QUERY_SIZE); + /* + * buttonpad might be given by + * f30->has_mech_mouse_btns, but I am + * not sure, so use only the pdata info + */ + if (pdata->f30_data.buttonpad) { + __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); + break; + } + } + } - if (retval) { - dev_err(&fn->dev, "Failed to read query register.\n"); - return retval; + input->keycode = f30->gpioled_key_map; + input->keycodesize = sizeof(f30->gpioled_key_map[0]); + input->keycodemax = f30->gpioled_count; + + return 0; +} + +static int rmi_f30_initialize(struct rmi_function *fn, struct f30_data *f30) +{ + u8 *ctrl_reg = f30->ctrl_regs; + int control_address = fn->fd.control_base_addr; + u8 buf[RMI_F30_QUERY_SIZE]; + int error; + + error = rmi_read_block(fn->rmi_dev, fn->fd.query_base_addr, + buf, RMI_F30_QUERY_SIZE); + if (error) { + dev_err(&fn->dev, "Failed to read query register\n"); + return error; } f30->has_extended_pattern = buf[0] & RMI_F30_EXTENDED_PATTERNS; @@ -276,101 +261,71 @@ static inline int rmi_f30_initialize(struct rmi_function *fn) f30->has_mech_mouse_btns = buf[0] & RMI_F30_HAS_MECH_MOUSE_BTNS; f30->gpioled_count = buf[1] & RMI_F30_GPIO_LED_COUNT; - f30->register_count = (f30->gpioled_count + 7) >> 3; - - control_address = fn->fd.control_base_addr; - ctrl_reg = f30->ctrl_regs; + f30->register_count = DIV_ROUND_UP(f30->gpioled_count, 8); if (f30->has_gpio && f30->has_led) rmi_f30_set_ctrl_data(&f30->ctrl[0], &control_address, - f30->register_count, &ctrl_reg); + f30->register_count, &ctrl_reg); - rmi_f30_set_ctrl_data(&f30->ctrl[1], &control_address, sizeof(u8), - &ctrl_reg); + rmi_f30_set_ctrl_data(&f30->ctrl[1], &control_address, + sizeof(u8), &ctrl_reg); if (f30->has_gpio) { rmi_f30_set_ctrl_data(&f30->ctrl[2], &control_address, - f30->register_count, &ctrl_reg); + f30->register_count, &ctrl_reg); rmi_f30_set_ctrl_data(&f30->ctrl[3], &control_address, - f30->register_count, &ctrl_reg); + f30->register_count, &ctrl_reg); } if (f30->has_led) { - int ctrl5_len; - rmi_f30_set_ctrl_data(&f30->ctrl[4], &control_address, - f30->register_count, &ctrl_reg); - - if (f30->has_extended_pattern) - ctrl5_len = 6; - else - ctrl5_len = 2; + f30->register_count, &ctrl_reg); rmi_f30_set_ctrl_data(&f30->ctrl[5], &control_address, - ctrl5_len, &ctrl_reg); + f30->has_extended_pattern ? 6 : 2, + &ctrl_reg); } if (f30->has_led || f30->has_gpio_driver_control) { /* control 6 uses a byte per gpio/led */ rmi_f30_set_ctrl_data(&f30->ctrl[6], &control_address, - f30->gpioled_count, &ctrl_reg); + f30->gpioled_count, &ctrl_reg); } if (f30->has_mappable_buttons) { /* control 7 uses a byte per gpio/led */ rmi_f30_set_ctrl_data(&f30->ctrl[7], &control_address, - f30->gpioled_count, &ctrl_reg); + f30->gpioled_count, &ctrl_reg); } if (f30->has_haptic) { rmi_f30_set_ctrl_data(&f30->ctrl[8], &control_address, - f30->register_count, &ctrl_reg); + f30->register_count, &ctrl_reg); rmi_f30_set_ctrl_data(&f30->ctrl[9], &control_address, - sizeof(u8), &ctrl_reg); + sizeof(u8), &ctrl_reg); } if (f30->has_mech_mouse_btns) rmi_f30_set_ctrl_data(&f30->ctrl[10], &control_address, - sizeof(u8), &ctrl_reg); + sizeof(u8), &ctrl_reg); - f30->ctrl_regs_size = ctrl_reg - f30->ctrl_regs - ?: RMI_F30_CTRL_REGS_MAX_SIZE; + f30->ctrl_regs_size = ctrl_reg - + f30->ctrl_regs ?: RMI_F30_CTRL_REGS_MAX_SIZE; - retval = rmi_f30_read_control_parameters(fn, f30); - if (retval < 0) { + error = rmi_f30_read_control_parameters(fn, f30); + if (error) { dev_err(&fn->dev, - "Failed to initialize F19 control params.\n"); - return retval; + "Failed to initialize F30 control params: %d\n", + error); + return error; } - map_memory = devm_kzalloc(&fn->dev, - (f30->gpioled_count * (sizeof(u16))), - GFP_KERNEL); - if (!map_memory) { - dev_err(&fn->dev, "Failed to allocate gpioled map memory.\n"); - return -ENOMEM; - } - - f30->gpioled_key_map = (u16 *)map_memory; - - pdata = rmi_get_platform_data(rmi_dev); if (f30->has_gpio) { - button = BTN_LEFT; - for (i = 0; i < f30->gpioled_count; i++) { - if (rmi_f30_is_valid_button(i, f30->ctrl)) { - f30->gpioled_key_map[i] = button++; - - /* - * buttonpad might be given by - * f30->has_mech_mouse_btns, but I am - * not sure, so use only the pdata info - */ - if (pdata->f30_data.buttonpad) - break; - } - } + error = rmi_f30_map_gpios(fn, f30); + if (error) + return error; } return 0; @@ -378,26 +333,33 @@ static inline int rmi_f30_initialize(struct rmi_function *fn) static int rmi_f30_probe(struct rmi_function *fn) { - int rc; + struct rmi_device *rmi_dev = fn->rmi_dev; const struct rmi_device_platform_data *pdata = - rmi_get_platform_data(fn->rmi_dev); + rmi_get_platform_data(rmi_dev); + struct rmi_driver_data *drv_data = dev_get_drvdata(&rmi_dev->dev); + struct f30_data *f30; + int error; if (pdata->f30_data.disable) return 0; - rc = rmi_f30_initialize(fn); - if (rc < 0) - goto error_exit; + if (!drv_data->input) { + dev_info(&fn->dev, "F30: no input device found, ignoring\n"); + return -ENXIO; + } - rc = rmi_f30_register_device(fn); - if (rc < 0) - goto error_exit; + f30 = devm_kzalloc(&fn->dev, sizeof(*f30), GFP_KERNEL); + if (!f30) + return -ENOMEM; + f30->input = drv_data->input; + + error = rmi_f30_initialize(fn, f30); + if (error) + return error; + + dev_set_drvdata(&fn->dev, f30); return 0; - -error_exit: - return rc; - } struct rmi_function_handler rmi_f30_handler = { From 81dec809aa728798c3ebff18c3d2d678237273aa Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 8 Feb 2017 00:26:45 -0800 Subject: [PATCH 84/91] Input: synaptics-rmi4 - forward upper mechanical buttons to PS/2 guest On the latest series of ThinkPads, the button events for the TrackPoint are reported through the touchpad itself as opposed to the TrackPoint device. In order to report these buttons properly, we need to forward them to the TrackPoint device and notify psmouse to send the button presses/releases. Signed-off-by: Lyude Paul Signed-off-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_driver.h | 13 +++++++ drivers/input/rmi4/rmi_f03.c | 38 +++++++++++++++++++++ drivers/input/rmi4/rmi_f30.c | 60 ++++++++++++++++++++++++--------- 3 files changed, 95 insertions(+), 16 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index 6e0449cdca68..f1a2a2266022 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -107,6 +107,19 @@ int rmi_initial_reset(struct rmi_device *rmi_dev, void *ctx, const char *rmi_f01_get_product_ID(struct rmi_function *fn); +#ifdef CONFIG_RMI4_F03 +int rmi_f03_overwrite_button(struct rmi_function *fn, unsigned int button, + int value); +void rmi_f03_commit_buttons(struct rmi_function *fn); +#else +static inline int rmi_f03_overwrite_button(struct rmi_function *fn, + unsigned int button, int value) +{ + return 0; +} +static inline void rmi_f03_commit_buttons(struct rmi_function *fn) {} +#endif + #ifdef CONFIG_RMI4_F34 int rmi_f34_create_sysfs(struct rmi_device *rmi_dev); void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev); diff --git a/drivers/input/rmi4/rmi_f03.c b/drivers/input/rmi4/rmi_f03.c index 9a1b099b72e0..77dad045a468 100644 --- a/drivers/input/rmi4/rmi_f03.c +++ b/drivers/input/rmi4/rmi_f03.c @@ -26,15 +26,53 @@ #define RMI_F03_BYTES_PER_DEVICE_SHIFT 4 #define RMI_F03_QUEUE_LENGTH 0x0F +#define PSMOUSE_OOB_EXTRA_BTNS 0x01 + struct f03_data { struct rmi_function *fn; struct serio *serio; + unsigned int overwrite_buttons; + u8 device_count; u8 rx_queue_length; }; +int rmi_f03_overwrite_button(struct rmi_function *fn, unsigned int button, + int value) +{ + struct f03_data *f03 = dev_get_drvdata(&fn->dev); + unsigned int bit; + + if (button < BTN_LEFT || button > BTN_MIDDLE) + return -EINVAL; + + bit = BIT(button - BTN_LEFT); + + if (value) + f03->overwrite_buttons |= bit; + else + f03->overwrite_buttons &= ~bit; + + return 0; +} + +void rmi_f03_commit_buttons(struct rmi_function *fn) +{ + struct f03_data *f03 = dev_get_drvdata(&fn->dev); + struct serio *serio = f03->serio; + + serio_pause_rx(serio); + if (serio->drv) { + serio->drv->interrupt(serio, PSMOUSE_OOB_EXTRA_BTNS, + SERIO_OOB_DATA); + serio->drv->interrupt(serio, f03->overwrite_buttons, + SERIO_OOB_DATA); + } + serio_continue_rx(serio); +} + static int rmi_f03_pt_write(struct serio *id, unsigned char val) { struct f03_data *f03 = id->port_data; diff --git a/drivers/input/rmi4/rmi_f30.c b/drivers/input/rmi4/rmi_f30.c index c5eb4d034e84..3422464af229 100644 --- a/drivers/input/rmi4/rmi_f30.c +++ b/drivers/input/rmi4/rmi_f30.c @@ -48,6 +48,9 @@ + 1 \ + 1) +#define TRACKSTICK_RANGE_START 3 +#define TRACKSTICK_RANGE_END 6 + struct rmi_f30_ctrl_data { int address; int length; @@ -76,6 +79,9 @@ struct f30_data { u16 *gpioled_key_map; struct input_dev *input; + + struct rmi_function *f03; + bool trackstick_buttons; }; static int rmi_f30_read_control_parameters(struct rmi_function *fn, @@ -100,13 +106,20 @@ static void rmi_f30_report_button(struct rmi_function *fn, { unsigned int reg_num = button >> 3; unsigned int bit_num = button & 0x07; + u16 key_code = f30->gpioled_key_map[button]; bool key_down = !(f30->data_regs[reg_num] & BIT(bit_num)); - rmi_dbg(RMI_DEBUG_FN, &fn->dev, - "%s: call input report key (0x%04x) value (0x%02x)", - __func__, f30->gpioled_key_map[button], key_down); + if (f30->trackstick_buttons && + button >= TRACKSTICK_RANGE_START && + button <= TRACKSTICK_RANGE_END) { + rmi_f03_overwrite_button(f30->f03, key_code, key_down); + } else { + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "%s: call input report key (0x%04x) value (0x%02x)", + __func__, key_code, key_down); - input_report_key(f30->input, f30->gpioled_key_map[button], key_down); + input_report_key(f30->input, key_code, key_down); + } } static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits) @@ -138,10 +151,13 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits) } } - if (f30->has_gpio) + if (f30->has_gpio) { for (i = 0; i < f30->gpioled_count; i++) if (f30->gpioled_key_map[i] != KEY_RESERVED) rmi_f30_report_button(fn, f30, i); + if (f30->trackstick_buttons) + rmi_f03_commit_buttons(f30->f03); + } return 0; } @@ -154,6 +170,12 @@ static int rmi_f30_config(struct rmi_function *fn) rmi_get_platform_data(fn->rmi_dev); int error; + if (pdata->f30_data.trackstick_buttons) { + /* Try [re-]establish link to F03. */ + f30->f03 = rmi_find_function(fn->rmi_dev, 0x03); + f30->trackstick_buttons = f30->f03 != NULL; + } + if (pdata->f30_data.disable) { drv->clear_irq_bits(fn->rmi_dev, fn->irq_mask); } else { @@ -203,6 +225,8 @@ static int rmi_f30_map_gpios(struct rmi_function *fn, rmi_get_platform_data(fn->rmi_dev); struct input_dev *input = f30->input; unsigned int button = BTN_LEFT; + unsigned int trackstick_button = BTN_LEFT; + bool button_mapped = false; int i; f30->gpioled_key_map = devm_kcalloc(&fn->dev, @@ -215,19 +239,16 @@ static int rmi_f30_map_gpios(struct rmi_function *fn, } for (i = 0; i < f30->gpioled_count; i++) { - if (rmi_f30_is_valid_button(i, f30->ctrl)) { + if (!rmi_f30_is_valid_button(i, f30->ctrl)) + continue; + + if (pdata->f30_data.trackstick_buttons && + i >= TRACKSTICK_RANGE_START && i < TRACKSTICK_RANGE_END) { + f30->gpioled_key_map[i] = trackstick_button++; + } else if (!pdata->f30_data.buttonpad || !button_mapped) { f30->gpioled_key_map[i] = button; input_set_capability(input, EV_KEY, button++); - - /* - * buttonpad might be given by - * f30->has_mech_mouse_btns, but I am - * not sure, so use only the pdata info - */ - if (pdata->f30_data.buttonpad) { - __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); - break; - } + button_mapped = true; } } @@ -235,6 +256,13 @@ static int rmi_f30_map_gpios(struct rmi_function *fn, input->keycodesize = sizeof(f30->gpioled_key_map[0]); input->keycodemax = f30->gpioled_count; + /* + * Buttonpad could be also inferred from f30->has_mech_mouse_btns, + * but I am not sure, so use only the pdata info. + */ + if (pdata->f30_data.buttonpad) + __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); + return 0; } From 45536d373a21d441bd488f618b6e3e9bfae839f3 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Thu, 29 Dec 2016 10:23:09 -0800 Subject: [PATCH 85/91] Input: joydev - do not report stale values on first open Postpone axis initialization to the first open instead of doing it in joydev_connect. This is to make sure the generated startup events are representative of the current joystick state rather than what it was when joydev_connect() was called, potentially much earlier. Once the first user is connected to joydev node we'll be updating joydev->abs[] values and subsequent clients will be getting correct initial states as well. This solves issues with joystick driven menus that start scrolling up each time they are started, until the user moves the joystick to generate events. In emulator menu setups where the menu program is restarted every time the game exits, the repeated need to move the joystick to stop the unintended scrolling gets old rather quickly... Signed-off-by: Raphael Assenat Signed-off-by: Dmitry Torokhov --- drivers/input/joydev.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c index 5298a762b615..065e67bf56dd 100644 --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -187,6 +187,17 @@ static void joydev_detach_client(struct joydev *joydev, synchronize_rcu(); } +static void joydev_refresh_state(struct joydev *joydev) +{ + struct input_dev *dev = joydev->handle.dev; + int i, val; + + for (i = 0; i < joydev->nabs; i++) { + val = input_abs_get_val(dev, joydev->abspam[i]); + joydev->abs[i] = joydev_correct(val, &joydev->corr[i]); + } +} + static int joydev_open_device(struct joydev *joydev) { int retval; @@ -201,6 +212,8 @@ static int joydev_open_device(struct joydev *joydev) retval = input_open_device(&joydev->handle); if (retval) joydev->open--; + else + joydev_refresh_state(joydev); } mutex_unlock(&joydev->mutex); @@ -872,7 +885,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, j = joydev->abspam[i]; if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) { joydev->corr[i].type = JS_CORR_NONE; - joydev->abs[i] = input_abs_get_val(dev, j); continue; } joydev->corr[i].type = JS_CORR_BROKEN; @@ -887,10 +899,6 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev, if (t) { joydev->corr[i].coef[2] = (1 << 29) / t; joydev->corr[i].coef[3] = (1 << 29) / t; - - joydev->abs[i] = - joydev_correct(input_abs_get_val(dev, j), - joydev->corr + i); } } From 83f66a6f08fa4004d6fb9d50c57735067bbbb405 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sat, 14 Jan 2017 10:25:02 -0800 Subject: [PATCH 86/91] Input: add driver for Zeitec ZET6223 This is a basic driver for the Zeitec ZET6223 I2C touchscreen controllers. The driver does not support firmware loading, which is not required for all tablets which contain this chip. Signed-off-by: Jelle van der Waa Acked-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/zet6223.txt | 32 +++ .../devicetree/bindings/vendor-prefixes.txt | 1 + drivers/input/touchscreen/Kconfig | 11 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/zet6223.c | 267 ++++++++++++++++++ 5 files changed, 312 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/zet6223.txt create mode 100644 drivers/input/touchscreen/zet6223.c diff --git a/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt b/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt new file mode 100644 index 000000000000..fe6a1feef703 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/zet6223.txt @@ -0,0 +1,32 @@ +Zeitec ZET6223 I2C touchscreen controller + +Required properties: +- compatible : "zeitec,zet6223" +- reg : I2C slave address of the chip (0x76) +- interrupt-parent : a phandle pointing to the interrupt controller + serving the interrupt for this chip +- interrupts : interrupt specification for the zet6223 interrupt + +Optional properties: + +- vio-supply : Specification for VIO supply (1.8V or 3.3V, + depending on system interface needs). +- vcc-supply : Specification for 3.3V VCC supply. +- touchscreen-size-x : See touchscreen.txt +- touchscreen-size-y : See touchscreen.txt +- touchscreen-inverted-x : See touchscreen.txt +- touchscreen-inverted-y : See touchscreen.txt +- touchscreen-swapped-x-y : See touchscreen.txt + +Example: + +i2c@00000000 { + + zet6223: touchscreen@76 { + compatible = "zeitec,zet6223"; + reg = <0x76>; + interrupt-parent = <&pio>; + interrupts = <6 11 IRQ_TYPE_EDGE_FALLING> + }; + +}; diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 16d3b5e7f5d1..e6f63f4a0d6d 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -329,6 +329,7 @@ xes Extreme Engineering Solutions (X-ES) xillybus Xillybus Ltd. xlnx Xilinx zarlink Zarlink Semiconductor +zeitec ZEITEC Semiconductor Co., LTD. zii Zodiac Inflight Innovations zte ZTE Corp. zyxel ZyXEL Communications Corp. diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 8650c94e29d0..033599777651 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1165,6 +1165,17 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts. +config TOUCHSCREEN_ZET6223 + tristate "Zeitec ZET6223 touchscreen driver" + depends on I2C + help + Say Y here if you have a touchscreen using Zeitec ZET6223 + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called zet6223. + config TOUCHSCREEN_ZFORCE tristate "Neonode zForce infrared touchscreens" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index e41e3c7aa427..b622e5344137 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -95,6 +95,7 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_SX8654) += sx8654.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_ZET6223) += zet6223.o obj-$(CONFIG_TOUCHSCREEN_ZFORCE) += zforce_ts.o obj-$(CONFIG_TOUCHSCREEN_COLIBRI_VF50) += colibri-vf50-ts.o obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023) += rohm_bu21023.o diff --git a/drivers/input/touchscreen/zet6223.c b/drivers/input/touchscreen/zet6223.c new file mode 100644 index 000000000000..e7fb00b511ec --- /dev/null +++ b/drivers/input/touchscreen/zet6223.c @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2016, Jelle van der Waa + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ZET6223_MAX_FINGERS 16 +#define ZET6223_MAX_PKT_SIZE (3 + 4 * ZET6223_MAX_FINGERS) + +#define ZET6223_CMD_INFO 0xB2 +#define ZET6223_CMD_INFO_LENGTH 17 +#define ZET6223_VALID_PACKET 0x3c + +#define ZET6223_POWER_ON_DELAY_MSEC 30 + +struct zet6223_ts { + struct i2c_client *client; + struct input_dev *input; + struct regulator *vcc; + struct regulator *vio; + struct touchscreen_properties prop; + struct regulator_bulk_data supplies[2]; + u16 max_x; + u16 max_y; + u8 fingernum; +}; + +static int zet6223_start(struct input_dev *dev) +{ + struct zet6223_ts *ts = input_get_drvdata(dev); + + enable_irq(ts->client->irq); + + return 0; +} + +static void zet6223_stop(struct input_dev *dev) +{ + struct zet6223_ts *ts = input_get_drvdata(dev); + + disable_irq(ts->client->irq); +} + +static irqreturn_t zet6223_irq(int irq, void *dev_id) +{ + struct zet6223_ts *ts = dev_id; + u16 finger_bits; + + /* + * First 3 bytes are an identifier, two bytes of finger data. + * X, Y data per finger is 4 bytes. + */ + u8 bufsize = 3 + 4 * ts->fingernum; + u8 buf[ZET6223_MAX_PKT_SIZE]; + int i; + int ret; + int error; + + ret = i2c_master_recv(ts->client, buf, bufsize); + if (ret != bufsize) { + error = ret < 0 ? ret : -EIO; + dev_err_ratelimited(&ts->client->dev, + "Error reading input data: %d\n", error); + return IRQ_HANDLED; + } + + if (buf[0] != ZET6223_VALID_PACKET) + return IRQ_HANDLED; + + finger_bits = get_unaligned_be16(buf + 1); + for (i = 0; i < ts->fingernum; i++) { + if (!(finger_bits & BIT(15 - i))) + continue; + + input_mt_slot(ts->input, i); + input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, true); + input_event(ts->input, EV_ABS, ABS_MT_POSITION_X, + ((buf[i + 3] >> 4) << 8) + buf[i + 4]); + input_event(ts->input, EV_ABS, ABS_MT_POSITION_Y, + ((buf[i + 3] & 0xF) << 8) + buf[i + 5]); + } + + input_mt_sync_frame(ts->input); + input_sync(ts->input); + + return IRQ_HANDLED; +} + +static void zet6223_power_off(void *_ts) +{ + struct zet6223_ts *ts = _ts; + + regulator_bulk_disable(ARRAY_SIZE(ts->supplies), ts->supplies); +} + +static int zet6223_power_on(struct zet6223_ts *ts) +{ + struct device *dev = &ts->client->dev; + int error; + + ts->supplies[0].supply = "vio"; + ts->supplies[1].supply = "vcc"; + + error = devm_regulator_bulk_get(dev, ARRAY_SIZE(ts->supplies), + ts->supplies); + if (error) + return error; + + error = regulator_bulk_enable(ARRAY_SIZE(ts->supplies), ts->supplies); + if (error) + return error; + + msleep(ZET6223_POWER_ON_DELAY_MSEC); + + error = devm_add_action_or_reset(dev, zet6223_power_off, ts); + if (error) { + dev_err(dev, "failed to install poweroff action: %d\n", error); + return error; + } + + return 0; +} + +static int zet6223_query_device(struct zet6223_ts *ts) +{ + u8 buf[ZET6223_CMD_INFO_LENGTH]; + u8 cmd = ZET6223_CMD_INFO; + int ret; + int error; + + ret = i2c_master_send(ts->client, &cmd, sizeof(cmd)); + if (ret != sizeof(cmd)) { + error = ret < 0 ? ret : -EIO; + dev_err(&ts->client->dev, + "touchpanel info cmd failed: %d\n", error); + return error; + } + + ret = i2c_master_recv(ts->client, buf, sizeof(buf)); + if (ret != sizeof(buf)) { + error = ret < 0 ? ret : -EIO; + dev_err(&ts->client->dev, + "failed to retrieve touchpanel info: %d\n", error); + return error; + } + + ts->fingernum = buf[15] & 0x7F; + if (ts->fingernum > ZET6223_MAX_FINGERS) { + dev_warn(&ts->client->dev, + "touchpanel reports %d fingers, limiting to %d\n", + ts->fingernum, ZET6223_MAX_FINGERS); + ts->fingernum = ZET6223_MAX_FINGERS; + } + + ts->max_x = get_unaligned_le16(&buf[8]); + ts->max_y = get_unaligned_le16(&buf[10]); + + return 0; +} + +static int zet6223_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct zet6223_ts *ts; + struct input_dev *input; + int error; + + if (!client->irq) { + dev_err(dev, "no irq specified\n"); + return -EINVAL; + } + + ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + if (!ts) + return -ENOMEM; + + ts->client = client; + + error = zet6223_power_on(ts); + if (error) + return error; + + error = zet6223_query_device(ts); + if (error) + return error; + + ts->input = input = devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + input_set_drvdata(input, ts); + + input->name = client->name; + input->id.bustype = BUS_I2C; + input->open = zet6223_start; + input->close = zet6223_stop; + + input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0); + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0); + + touchscreen_parse_properties(input, true, &ts->prop); + + error = input_mt_init_slots(input, ts->fingernum, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (error) + return error; + + error = devm_request_threaded_irq(dev, client->irq, NULL, zet6223_irq, + IRQF_ONESHOT, client->name, ts); + if (error) { + dev_err(dev, "failed to request irq %d: %d\n", + client->irq, error); + return error; + } + + zet6223_stop(input); + + error = input_register_device(input); + if (error) + return error; + + return 0; +} + +static const struct of_device_id zet6223_of_match[] = { + { .compatible = "zeitec,zet6223" }, + { } +}; + +static const struct i2c_device_id zet6223_id[] = { + { "zet6223", 0}, + { } +}; +MODULE_DEVICE_TABLE(i2c, zet6223_id); + +static struct i2c_driver zet6223_driver = { + .driver = { + .name = "zet6223", + .of_match_table = zet6223_of_match, + }, + .probe = zet6223_probe, + .id_table = zet6223_id +}; +module_i2c_driver(zet6223_driver); + +MODULE_AUTHOR("Jelle van der Waa "); +MODULE_DESCRIPTION("ZEITEC zet622x I2C touchscreen driver"); +MODULE_LICENSE("GPL"); From 449aa83e69ff10d77fe088eadacafe1e97937c14 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 10 Feb 2017 15:12:20 -0800 Subject: [PATCH 87/91] Input: tsc2005 - add OF device table To be prepared for SPI module loading using full compatible strings from device tree, let's add OF module device table data. Reviewed-By: Sebastian Reichel Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc2005.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c index f2c5f0e47f77..e02b69f40ad8 100644 --- a/drivers/input/touchscreen/tsc2005.c +++ b/drivers/input/touchscreen/tsc2005.c @@ -18,8 +18,9 @@ * GNU General Public License for more details. */ -#include #include +#include +#include #include #include #include "tsc200x-core.h" @@ -77,9 +78,18 @@ static int tsc2005_remove(struct spi_device *spi) return tsc200x_remove(&spi->dev); } +#ifdef CONFIG_OF +static const struct of_device_id tsc2005_of_match[] = { + { .compatible = "ti,tsc2005" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, tsc2005_of_match); +#endif + static struct spi_driver tsc2005_driver = { .driver = { .name = "tsc2005", + .of_match_table = of_match_ptr(tsc2005_of_match), .pm = &tsc200x_pm_ops, }, .probe = tsc2005_probe, From f7bf6f58675a76c08e6eee7fa5c264884eb5c599 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 10 Feb 2017 15:30:29 -0800 Subject: [PATCH 88/91] Input: tsc2004/5 - fix regulator handling In case of an optional regulator missing, regulator core will return ERR_PTR(-ENOENT) and not NULL, so the check for missing regulator is incorrect. Also, the regulator is not optional, it may simply be missing from platform description, so let's use devm_regulator_get() and rely on regulator core to give us dummy supply when real one is not available. Fixes: d257f2980feb ("Input: tsc2005 - convert to gpiod") Acked-By: Sebastian Reichel Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index b7059ed8872e..1c14a38e3748 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -527,10 +527,10 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - ts->vio = devm_regulator_get_optional(dev, "vio"); + ts->vio = devm_regulator_get(dev, "vio"); if (IS_ERR(ts->vio)) { error = PTR_ERR(ts->vio); - dev_err(dev, "vio regulator missing (%d)", error); + dev_err(dev, "error acquiring vio regulator: %d", error); return error; } @@ -587,12 +587,9 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - /* enable regulator for DT */ - if (ts->vio) { - error = regulator_enable(ts->vio); - if (error) - return error; - } + error = regulator_enable(ts->vio); + if (error) + return error; dev_set_drvdata(dev, ts); error = sysfs_create_group(&dev->kobj, &tsc200x_attr_group); @@ -615,8 +612,7 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, err_remove_sysfs: sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); disable_regulator: - if (ts->vio) - regulator_disable(ts->vio); + regulator_disable(ts->vio); return error; } EXPORT_SYMBOL_GPL(tsc200x_probe); @@ -627,8 +623,7 @@ int tsc200x_remove(struct device *dev) sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); - if (ts->vio) - regulator_disable(ts->vio); + regulator_disable(ts->vio); return 0; } From d0d89493bff8b7c7bf580197a44a1d49c50395b3 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 10 Feb 2017 15:18:07 -0800 Subject: [PATCH 89/91] Input: tsc2004/5 - switch to using generic device properties Instead of supporting legacy platform data (of which we have no mainline users) and OF-based properties, let's switch to generic device properties. This will still allow legacy boards to use the driver (by defining property sets and attaching them to the drivers) and will simplify probe and make driver usable on ACPI-based systems as well. Reviewed-By: Sebastian Reichel Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/tsc200x-core.c | 93 ++++++++---------------- include/linux/spi/tsc2005.h | 34 --------- 2 files changed, 30 insertions(+), 97 deletions(-) delete mode 100644 include/linux/spi/tsc2005.h diff --git a/drivers/input/touchscreen/tsc200x-core.c b/drivers/input/touchscreen/tsc200x-core.c index 1c14a38e3748..88ea5e1b72ae 100644 --- a/drivers/input/touchscreen/tsc200x-core.c +++ b/drivers/input/touchscreen/tsc200x-core.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -114,7 +113,6 @@ struct tsc200x { struct regulator *vio; struct gpio_desc *reset_gpio; - void (*set_reset)(bool enable); int (*tsc200x_cmd)(struct device *dev, u8 cmd); int irq; }; @@ -227,12 +225,13 @@ static void tsc200x_stop_scan(struct tsc200x *ts) ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); } -static void tsc200x_set_reset(struct tsc200x *ts, bool enable) +static void tsc200x_reset(struct tsc200x *ts) { - if (ts->reset_gpio) - gpiod_set_value_cansleep(ts->reset_gpio, enable); - else if (ts->set_reset) - ts->set_reset(enable); + if (ts->reset_gpio) { + gpiod_set_value_cansleep(ts->reset_gpio, 1); + usleep_range(100, 500); /* only 10us required */ + gpiod_set_value_cansleep(ts->reset_gpio, 0); + } } /* must be called with ts->mutex held */ @@ -253,7 +252,7 @@ static void __tsc200x_enable(struct tsc200x *ts) { tsc200x_start_scan(ts); - if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) { + if (ts->esd_timeout && ts->reset_gpio) { ts->last_valid_interrupt = jiffies; schedule_delayed_work(&ts->esd_work, round_jiffies_relative( @@ -310,9 +309,7 @@ static ssize_t tsc200x_selftest_show(struct device *dev, } /* hardware reset */ - tsc200x_set_reset(ts, false); - usleep_range(100, 500); /* only 10us required */ - tsc200x_set_reset(ts, true); + tsc200x_reset(ts); if (!success) goto out; @@ -354,7 +351,7 @@ static umode_t tsc200x_attr_is_visible(struct kobject *kobj, umode_t mode = attr->mode; if (attr == &dev_attr_selftest.attr) { - if (!ts->set_reset && !ts->reset_gpio) + if (!ts->reset_gpio) mode = 0; } @@ -404,9 +401,7 @@ static void tsc200x_esd_work(struct work_struct *work) tsc200x_update_pen_state(ts, 0, 0, 0); - tsc200x_set_reset(ts, false); - usleep_range(100, 500); /* only 10us required */ - tsc200x_set_reset(ts, true); + tsc200x_reset(ts); enable_irq(ts->irq); tsc200x_start_scan(ts); @@ -454,26 +449,12 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, struct regmap *regmap, int (*tsc200x_cmd)(struct device *dev, u8 cmd)) { - const struct tsc2005_platform_data *pdata = dev_get_platdata(dev); - struct device_node *np = dev->of_node; - struct tsc200x *ts; struct input_dev *input_dev; - unsigned int max_x = MAX_12BIT; - unsigned int max_y = MAX_12BIT; - unsigned int max_p = MAX_12BIT; - unsigned int fudge_x = TSC200X_DEF_X_FUZZ; - unsigned int fudge_y = TSC200X_DEF_Y_FUZZ; - unsigned int fudge_p = TSC200X_DEF_P_FUZZ; - unsigned int x_plate_ohm = TSC200X_DEF_RESISTOR; - unsigned int esd_timeout; + u32 x_plate_ohm; + u32 esd_timeout; int error; - if (!np && !pdata) { - dev_err(dev, "no platform data\n"); - return -ENODEV; - } - if (irq <= 0) { dev_err(dev, "no irq\n"); return -ENODEV; @@ -487,23 +468,6 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return -ENODEV; } - if (pdata) { - fudge_x = pdata->ts_x_fudge; - fudge_y = pdata->ts_y_fudge; - fudge_p = pdata->ts_pressure_fudge; - max_x = pdata->ts_x_max; - max_y = pdata->ts_y_max; - max_p = pdata->ts_pressure_max; - x_plate_ohm = pdata->ts_x_plate_ohm; - esd_timeout = pdata->esd_timeout_ms; - } else { - x_plate_ohm = TSC200X_DEF_RESISTOR; - of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm); - esd_timeout = 0; - of_property_read_u32(np, "ti,esd-recovery-timeout-ms", - &esd_timeout); - } - ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); if (!ts) return -ENOMEM; @@ -517,8 +481,13 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, ts->idev = input_dev; ts->regmap = regmap; ts->tsc200x_cmd = tsc200x_cmd; - ts->x_plate_ohm = x_plate_ohm; - ts->esd_timeout = esd_timeout; + + error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm); + ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; + + error = device_property_read_u32(dev, "ti,esd-recovery-timeout-ms", + &esd_timeout); + ts->esd_timeout = error ? 0 : esd_timeout; ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(ts->reset_gpio)) { @@ -534,9 +503,6 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, return error; } - if (!ts->reset_gpio && pdata) - ts->set_reset = pdata->set_reset; - mutex_init(&ts->mutex); spin_lock_init(&ts->lock); @@ -559,22 +525,23 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, input_dev->phys = ts->phys; input_dev->id = *tsc_id; - input_dev->dev.parent = dev; - input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); - - input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0); - input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0); - input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0); - - if (np) - touchscreen_parse_properties(input_dev, false, NULL); input_dev->open = tsc200x_open; input_dev->close = tsc200x_close; input_set_drvdata(input_dev, ts); + input_set_capability(input_dev, EV_KEY, BTN_TOUCH); + + input_set_abs_params(input_dev, ABS_X, + 0, MAX_12BIT, TSC200X_DEF_X_FUZZ, 0); + input_set_abs_params(input_dev, ABS_Y, + 0, MAX_12BIT, TSC200X_DEF_Y_FUZZ, 0); + input_set_abs_params(input_dev, ABS_PRESSURE, + 0, MAX_12BIT, TSC200X_DEF_P_FUZZ, 0); + + touchscreen_parse_properties(input_dev, false, NULL); + /* Ensure the touchscreen is off */ tsc200x_stop_scan(ts); diff --git a/include/linux/spi/tsc2005.h b/include/linux/spi/tsc2005.h deleted file mode 100644 index 563b3b1799a8..000000000000 --- a/include/linux/spi/tsc2005.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of TSC2005 touchscreen driver - * - * Copyright (C) 2009-2010 Nokia Corporation - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef _LINUX_SPI_TSC2005_H -#define _LINUX_SPI_TSC2005_H - -#include - -struct tsc2005_platform_data { - int ts_pressure_max; - int ts_pressure_fudge; - int ts_x_max; - int ts_x_fudge; - int ts_y_max; - int ts_y_fudge; - int ts_x_plate_ohm; - unsigned int esd_timeout_ms; - void (*set_reset)(bool enable); -}; - -#endif From 6ccc3a33810e8ec09936fa990c13370d9f61606f Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 27 Jan 2017 11:52:35 +0100 Subject: [PATCH 90/91] input: cros_ec_keyb: Add Tablet Mode switch Add switch to report tablet mode. Signed-off-by: Gwendal Grignou Signed-off-by: Enric Balletbo Serra Signed-off-by: Lee Jones --- drivers/input/keyboard/cros_ec_keyb.c | 5 +++++ include/linux/mfd/cros_ec_commands.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index ad74ebce0cdd..604c7ade8df2 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -111,6 +111,11 @@ static const struct cros_ec_bs_map cros_ec_keyb_bs[] = { .bit = EC_MKBP_LID_OPEN, .inverted = true, }, + { + .ev_type = EV_SW, + .code = SW_TABLET_MODE, + .bit = EC_MKBP_TABLET_MODE, + }, }; /* diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h index 004dcf3560fb..da1c188562bc 100644 --- a/include/linux/mfd/cros_ec_commands.h +++ b/include/linux/mfd/cros_ec_commands.h @@ -2068,6 +2068,7 @@ struct ec_response_get_next_event { /* Switches */ #define EC_MKBP_LID_OPEN 0 +#define EC_MKBP_TABLET_MODE 1 /*****************************************************************************/ /* Temperature sensor commands */ From a1b5359271e5c77d5ec8a575b379a6ba3e867097 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 20 Feb 2017 15:06:39 -0800 Subject: [PATCH 91/91] Input: zet6223 - export OF device ID as module aliases The I2C core always reports a MODALIAS of the form i2c: even if the device was registered via OF, this means that exporting the OF device ID table device aliases in the module is not needed. But in order to change how the core reports modaliases to user-space, it's better to export it. Before this patch: $ modinfo drivers/input/touchscreen/zet6223.ko | grep alias alias: i2c:zet6223 After this patch: $ modinfo drivers/input/touchscreen/zet6223.ko | grep alias alias: of:N*T*Czeitec,zet6223C* alias: of:N*T*Czeitec,zet6223 alias: i2c:zet6223 Signed-off-by: Javier Martinez Canillas Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/zet6223.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/input/touchscreen/zet6223.c b/drivers/input/touchscreen/zet6223.c index e7fb00b511ec..19ffcc7b886c 100644 --- a/drivers/input/touchscreen/zet6223.c +++ b/drivers/input/touchscreen/zet6223.c @@ -245,6 +245,7 @@ static const struct of_device_id zet6223_of_match[] = { { .compatible = "zeitec,zet6223" }, { } }; +MODULE_DEVICE_TABLE(of, zet6223_of_match); static const struct i2c_device_id zet6223_id[] = { { "zet6223", 0},