1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MELFAS MIP4 Touchscreen
5 * Copyright (C) 2016 MELFAS Inc.
7 * Author : Sangwon Jee <jeesw@melfas.com>
10 #include <linux/acpi.h>
11 #include <linux/delay.h>
12 #include <linux/firmware.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/i2c.h>
15 #include <linux/input.h>
16 #include <linux/input/mt.h>
17 #include <linux/interrupt.h>
18 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <asm/unaligned.h>
23 #define MIP4_DEVICE_NAME "mip4_ts"
25 /*****************************************************************
27 * Version : MIP 4.0 Rev 5.4
28 *****************************************************************/
31 #define MIP4_R0_BOOT 0x00
32 #define MIP4_R1_BOOT_MODE 0x01
33 #define MIP4_R1_BOOT_BUF_ADDR 0x10
34 #define MIP4_R1_BOOT_STATUS 0x20
35 #define MIP4_R1_BOOT_CMD 0x30
36 #define MIP4_R1_BOOT_TARGET_ADDR 0x40
37 #define MIP4_R1_BOOT_SIZE 0x44
39 #define MIP4_R0_INFO 0x01
40 #define MIP4_R1_INFO_PRODUCT_NAME 0x00
41 #define MIP4_R1_INFO_RESOLUTION_X 0x10
42 #define MIP4_R1_INFO_RESOLUTION_Y 0x12
43 #define MIP4_R1_INFO_NODE_NUM_X 0x14
44 #define MIP4_R1_INFO_NODE_NUM_Y 0x15
45 #define MIP4_R1_INFO_KEY_NUM 0x16
46 #define MIP4_R1_INFO_PRESSURE_NUM 0x17
47 #define MIP4_R1_INFO_LENGTH_X 0x18
48 #define MIP4_R1_INFO_LENGTH_Y 0x1A
49 #define MIP4_R1_INFO_PPM_X 0x1C
50 #define MIP4_R1_INFO_PPM_Y 0x1D
51 #define MIP4_R1_INFO_VERSION_BOOT 0x20
52 #define MIP4_R1_INFO_VERSION_CORE 0x22
53 #define MIP4_R1_INFO_VERSION_APP 0x24
54 #define MIP4_R1_INFO_VERSION_PARAM 0x26
55 #define MIP4_R1_INFO_SECT_BOOT_START 0x30
56 #define MIP4_R1_INFO_SECT_BOOT_END 0x31
57 #define MIP4_R1_INFO_SECT_CORE_START 0x32
58 #define MIP4_R1_INFO_SECT_CORE_END 0x33
59 #define MIP4_R1_INFO_SECT_APP_START 0x34
60 #define MIP4_R1_INFO_SECT_APP_END 0x35
61 #define MIP4_R1_INFO_SECT_PARAM_START 0x36
62 #define MIP4_R1_INFO_SECT_PARAM_END 0x37
63 #define MIP4_R1_INFO_BUILD_DATE 0x40
64 #define MIP4_R1_INFO_BUILD_TIME 0x44
65 #define MIP4_R1_INFO_CHECKSUM_PRECALC 0x48
66 #define MIP4_R1_INFO_CHECKSUM_REALTIME 0x4A
67 #define MIP4_R1_INFO_PROTOCOL_NAME 0x50
68 #define MIP4_R1_INFO_PROTOCOL_VERSION 0x58
69 #define MIP4_R1_INFO_IC_ID 0x70
70 #define MIP4_R1_INFO_IC_NAME 0x71
71 #define MIP4_R1_INFO_IC_VENDOR_ID 0x75
72 #define MIP4_R1_INFO_IC_HW_CATEGORY 0x77
73 #define MIP4_R1_INFO_CONTACT_THD_SCR 0x78
74 #define MIP4_R1_INFO_CONTACT_THD_KEY 0x7A
75 #define MIP4_R1_INFO_PID 0x7C
76 #define MIP4_R1_INFO_VID 0x7E
77 #define MIP4_R1_INFO_SLAVE_ADDR 0x80
79 #define MIP4_R0_EVENT 0x02
80 #define MIP4_R1_EVENT_SUPPORTED_FUNC 0x00
81 #define MIP4_R1_EVENT_FORMAT 0x04
82 #define MIP4_R1_EVENT_SIZE 0x06
83 #define MIP4_R1_EVENT_PACKET_INFO 0x10
84 #define MIP4_R1_EVENT_PACKET_DATA 0x11
86 #define MIP4_R0_CTRL 0x06
87 #define MIP4_R1_CTRL_READY_STATUS 0x00
88 #define MIP4_R1_CTRL_EVENT_READY 0x01
89 #define MIP4_R1_CTRL_MODE 0x10
90 #define MIP4_R1_CTRL_EVENT_TRIGGER_TYPE 0x11
91 #define MIP4_R1_CTRL_RECALIBRATE 0x12
92 #define MIP4_R1_CTRL_POWER_STATE 0x13
93 #define MIP4_R1_CTRL_GESTURE_TYPE 0x14
94 #define MIP4_R1_CTRL_DISABLE_ESD_ALERT 0x18
95 #define MIP4_R1_CTRL_CHARGER_MODE 0x19
96 #define MIP4_R1_CTRL_HIGH_SENS_MODE 0x1A
97 #define MIP4_R1_CTRL_WINDOW_MODE 0x1B
98 #define MIP4_R1_CTRL_PALM_REJECTION 0x1C
99 #define MIP4_R1_CTRL_EDGE_CORRECTION 0x1D
100 #define MIP4_R1_CTRL_ENTER_GLOVE_MODE 0x1E
101 #define MIP4_R1_CTRL_I2C_ON_LPM 0x1F
102 #define MIP4_R1_CTRL_GESTURE_DEBUG 0x20
103 #define MIP4_R1_CTRL_PALM_EVENT 0x22
104 #define MIP4_R1_CTRL_PROXIMITY_SENSING 0x23
107 #define MIP4_BOOT_MODE_BOOT 0x01
108 #define MIP4_BOOT_MODE_APP 0x02
110 #define MIP4_BOOT_STATUS_BUSY 0x05
111 #define MIP4_BOOT_STATUS_ERROR 0x0E
112 #define MIP4_BOOT_STATUS_DONE 0xA0
114 #define MIP4_BOOT_CMD_MASS_ERASE 0x15
115 #define MIP4_BOOT_CMD_PROGRAM 0x54
116 #define MIP4_BOOT_CMD_ERASE 0x8F
117 #define MIP4_BOOT_CMD_WRITE 0xA5
118 #define MIP4_BOOT_CMD_READ 0xC2
120 #define MIP4_EVENT_INPUT_TYPE_KEY 0
121 #define MIP4_EVENT_INPUT_TYPE_SCREEN 1
122 #define MIP4_EVENT_INPUT_TYPE_PROXIMITY 2
124 #define I2C_RETRY_COUNT 3 /* 2~ */
126 #define MIP4_BUF_SIZE 128
127 #define MIP4_MAX_FINGERS 10
128 #define MIP4_MAX_KEYS 4
130 #define MIP4_TOUCH_MAJOR_MIN 0
131 #define MIP4_TOUCH_MAJOR_MAX 255
132 #define MIP4_TOUCH_MINOR_MIN 0
133 #define MIP4_TOUCH_MINOR_MAX 255
134 #define MIP4_PRESSURE_MIN 0
135 #define MIP4_PRESSURE_MAX 255
137 #define MIP4_FW_NAME "melfas_mip4.fw"
138 #define MIP4_FW_UPDATE_DEBUG 0 /* 0 (default) or 1 */
140 struct mip4_fw_version
{
148 struct i2c_client
*client
;
149 struct input_dev
*input
;
150 struct gpio_desc
*gpio_ce
;
153 char product_name
[16];
166 struct mip4_fw_version fw_version
;
168 unsigned int event_size
;
169 unsigned int event_format
;
171 unsigned int key_num
;
172 unsigned short key_code
[MIP4_MAX_KEYS
];
174 bool wake_irq_enabled
;
176 u8 buf
[MIP4_BUF_SIZE
];
179 static int mip4_i2c_xfer(struct mip4_ts
*ts
,
180 char *write_buf
, unsigned int write_len
,
181 char *read_buf
, unsigned int read_len
)
183 struct i2c_msg msg
[] = {
185 .addr
= ts
->client
->addr
,
190 .addr
= ts
->client
->addr
,
196 int retry
= I2C_RETRY_COUNT
;
201 res
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
202 if (res
== ARRAY_SIZE(msg
))
205 error
= res
< 0 ? res
: -EIO
;
206 dev_err(&ts
->client
->dev
,
207 "%s - i2c_transfer failed: %d (%d)\n",
208 __func__
, error
, res
);
214 static void mip4_parse_fw_version(const u8
*buf
, struct mip4_fw_version
*v
)
216 v
->boot
= get_unaligned_le16(buf
+ 0);
217 v
->core
= get_unaligned_le16(buf
+ 2);
218 v
->app
= get_unaligned_le16(buf
+ 4);
219 v
->param
= get_unaligned_le16(buf
+ 6);
223 * Read chip firmware version
225 static int mip4_get_fw_version(struct mip4_ts
*ts
)
227 u8 cmd
[] = { MIP4_R0_INFO
, MIP4_R1_INFO_VERSION_BOOT
};
228 u8 buf
[sizeof(ts
->fw_version
)];
231 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, sizeof(buf
));
233 memset(&ts
->fw_version
, 0xff, sizeof(ts
->fw_version
));
237 mip4_parse_fw_version(buf
, &ts
->fw_version
);
243 * Fetch device characteristics
245 static int mip4_query_device(struct mip4_ts
*ts
)
247 union i2c_smbus_data dummy
;
253 * Make sure there is something at this address as we do not
254 * consider subsequent failures as fatal.
256 if (i2c_smbus_xfer(ts
->client
->adapter
, ts
->client
->addr
,
257 0, I2C_SMBUS_READ
, 0, I2C_SMBUS_BYTE
, &dummy
) < 0) {
258 dev_err(&ts
->client
->dev
, "nothing at this address\n");
263 cmd
[0] = MIP4_R0_INFO
;
264 cmd
[1] = MIP4_R1_INFO_PRODUCT_NAME
;
265 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
),
266 ts
->product_name
, sizeof(ts
->product_name
));
268 dev_warn(&ts
->client
->dev
,
269 "Failed to retrieve product name: %d\n", error
);
271 dev_dbg(&ts
->client
->dev
, "product name: %.*s\n",
272 (int)sizeof(ts
->product_name
), ts
->product_name
);
275 cmd
[0] = MIP4_R0_INFO
;
276 cmd
[1] = MIP4_R1_INFO_PID
;
277 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 2);
279 dev_warn(&ts
->client
->dev
,
280 "Failed to retrieve product id: %d\n", error
);
282 ts
->product_id
= get_unaligned_le16(&buf
[0]);
283 dev_dbg(&ts
->client
->dev
, "product id: %04X\n", ts
->product_id
);
287 snprintf(ts
->fw_name
, sizeof(ts
->fw_name
),
288 "melfas_mip4_%04X.fw", ts
->product_id
);
289 dev_dbg(&ts
->client
->dev
, "firmware name: %s\n", ts
->fw_name
);
292 cmd
[0] = MIP4_R0_INFO
;
293 cmd
[1] = MIP4_R1_INFO_IC_NAME
;
294 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
),
295 ts
->ic_name
, sizeof(ts
->ic_name
));
297 dev_warn(&ts
->client
->dev
,
298 "Failed to retrieve IC name: %d\n", error
);
300 dev_dbg(&ts
->client
->dev
, "IC name: %.*s\n",
301 (int)sizeof(ts
->ic_name
), ts
->ic_name
);
303 /* Firmware version */
304 error
= mip4_get_fw_version(ts
);
306 dev_warn(&ts
->client
->dev
,
307 "Failed to retrieve FW version: %d\n", error
);
309 dev_dbg(&ts
->client
->dev
, "F/W Version: %04X %04X %04X %04X\n",
310 ts
->fw_version
.boot
, ts
->fw_version
.core
,
311 ts
->fw_version
.app
, ts
->fw_version
.param
);
314 cmd
[0] = MIP4_R0_INFO
;
315 cmd
[1] = MIP4_R1_INFO_RESOLUTION_X
;
316 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 14);
318 dev_warn(&ts
->client
->dev
,
319 "Failed to retrieve touchscreen parameters: %d\n",
322 ts
->max_x
= get_unaligned_le16(&buf
[0]);
323 ts
->max_y
= get_unaligned_le16(&buf
[2]);
324 dev_dbg(&ts
->client
->dev
, "max_x: %d, max_y: %d\n",
325 ts
->max_x
, ts
->max_y
);
329 ts
->node_key
= buf
[6];
330 dev_dbg(&ts
->client
->dev
,
331 "node_x: %d, node_y: %d, node_key: %d\n",
332 ts
->node_x
, ts
->node_y
, ts
->node_key
);
336 dev_dbg(&ts
->client
->dev
, "ppm_x: %d, ppm_y: %d\n",
337 ts
->ppm_x
, ts
->ppm_y
);
340 if (ts
->node_key
> 0)
341 ts
->key_num
= ts
->node_key
;
345 cmd
[0] = MIP4_R0_EVENT
;
346 cmd
[1] = MIP4_R1_EVENT_SUPPORTED_FUNC
;
347 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 7);
349 dev_warn(&ts
->client
->dev
,
350 "Failed to retrieve device type: %d\n", error
);
351 ts
->event_format
= 0xff;
353 ts
->event_format
= get_unaligned_le16(&buf
[4]);
354 ts
->event_size
= buf
[6];
355 dev_dbg(&ts
->client
->dev
, "event_format: %d, event_size: %d\n",
356 ts
->event_format
, ts
->event_size
);
358 if (ts
->event_format
== 2 || ts
->event_format
> 3)
359 dev_warn(&ts
->client
->dev
,
360 "Unknown event format %d\n", ts
->event_format
);
366 static int mip4_power_on(struct mip4_ts
*ts
)
369 gpiod_set_value_cansleep(ts
->gpio_ce
, 1);
371 /* Booting delay : 200~300ms */
372 usleep_range(200 * 1000, 300 * 1000);
378 static void mip4_power_off(struct mip4_ts
*ts
)
381 gpiod_set_value_cansleep(ts
->gpio_ce
, 0);
385 * Clear touch input event status
387 static void mip4_clear_input(struct mip4_ts
*ts
)
392 for (i
= 0; i
< MIP4_MAX_FINGERS
; i
++) {
393 input_mt_slot(ts
->input
, i
);
394 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, 0);
398 for (i
= 0; i
< ts
->key_num
; i
++)
399 input_report_key(ts
->input
, ts
->key_code
[i
], 0);
401 input_sync(ts
->input
);
404 static int mip4_enable(struct mip4_ts
*ts
)
408 error
= mip4_power_on(ts
);
412 enable_irq(ts
->client
->irq
);
417 static void mip4_disable(struct mip4_ts
*ts
)
419 disable_irq(ts
->client
->irq
);
423 mip4_clear_input(ts
);
426 /*****************************************************************
428 *****************************************************************/
430 static void mip4_report_keys(struct mip4_ts
*ts
, u8
*packet
)
435 switch (ts
->event_format
) {
438 key
= packet
[0] & 0x0F;
439 down
= packet
[0] & 0x80;
444 key
= packet
[0] & 0x0F;
445 down
= packet
[1] & 0x01;
449 /* Report key event */
450 if (key
>= 1 && key
<= ts
->key_num
) {
451 unsigned short keycode
= ts
->key_code
[key
- 1];
453 dev_dbg(&ts
->client
->dev
,
454 "Key - ID: %d, keycode: %d, state: %d\n",
457 input_event(ts
->input
, EV_MSC
, MSC_SCAN
, keycode
);
458 input_report_key(ts
->input
, keycode
, down
);
461 dev_err(&ts
->client
->dev
, "Unknown key: %d\n", key
);
465 static void mip4_report_touch(struct mip4_ts
*ts
, u8
*packet
)
472 u8 pressure_stage
= 0;
478 switch (ts
->event_format
) {
482 state
= packet
[0] & BIT(7);
483 hover
= packet
[0] & BIT(5);
484 palm
= packet
[0] & BIT(4);
485 id
= (packet
[0] & 0x0F) - 1;
486 x
= ((packet
[1] & 0x0F) << 8) | packet
[2];
487 y
= (((packet
[1] >> 4) & 0x0F) << 8) |
489 pressure
= packet
[4];
491 if (ts
->event_format
== 0) {
492 touch_major
= packet
[5];
493 touch_minor
= packet
[5];
495 touch_major
= packet
[6];
496 touch_minor
= packet
[7];
502 /* Touch + Force(Pressure) */
503 id
= (packet
[0] & 0x0F) - 1;
504 hover
= packet
[1] & BIT(2);
505 palm
= packet
[1] & BIT(1);
506 state
= packet
[1] & BIT(0);
507 x
= ((packet
[2] & 0x0F) << 8) | packet
[3];
508 y
= (((packet
[2] >> 4) & 0x0F) << 8) |
511 pressure_stage
= (packet
[7] & 0xF0) >> 4;
512 pressure
= ((packet
[7] & 0x0F) << 8) |
514 touch_major
= packet
[9];
515 touch_minor
= packet
[10];
519 dev_dbg(&ts
->client
->dev
,
520 "Screen - Slot: %d State: %d X: %04d Y: %04d Z: %d\n",
521 id
, state
, x
, y
, pressure
);
523 if (unlikely(id
< 0 || id
>= MIP4_MAX_FINGERS
)) {
524 dev_err(&ts
->client
->dev
, "Screen - invalid slot ID: %d\n", id
);
526 /* Press or Move event */
527 input_mt_slot(ts
->input
, id
);
528 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, true);
529 input_report_abs(ts
->input
, ABS_MT_POSITION_X
, x
);
530 input_report_abs(ts
->input
, ABS_MT_POSITION_Y
, y
);
531 input_report_abs(ts
->input
, ABS_MT_PRESSURE
, pressure
);
532 input_report_abs(ts
->input
, ABS_MT_TOUCH_MAJOR
, touch_major
);
533 input_report_abs(ts
->input
, ABS_MT_TOUCH_MINOR
, touch_minor
);
536 input_mt_slot(ts
->input
, id
);
537 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, 0);
540 input_mt_sync_frame(ts
->input
);
543 static int mip4_handle_packet(struct mip4_ts
*ts
, u8
*packet
)
547 switch (ts
->event_format
) {
550 type
= (packet
[0] & 0x40) >> 6;
554 type
= (packet
[0] & 0xF0) >> 4;
558 /* Should not happen unless we have corrupted firmware */
562 dev_dbg(&ts
->client
->dev
, "Type: %d\n", type
);
564 /* Report input event */
566 case MIP4_EVENT_INPUT_TYPE_KEY
:
567 mip4_report_keys(ts
, packet
);
570 case MIP4_EVENT_INPUT_TYPE_SCREEN
:
571 mip4_report_touch(ts
, packet
);
575 dev_err(&ts
->client
->dev
, "Unknown event type: %d\n", type
);
582 static irqreturn_t
mip4_interrupt(int irq
, void *dev_id
)
584 struct mip4_ts
*ts
= dev_id
;
585 struct i2c_client
*client
= ts
->client
;
592 /* Read packet info */
593 cmd
[0] = MIP4_R0_EVENT
;
594 cmd
[1] = MIP4_R1_EVENT_PACKET_INFO
;
595 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), ts
->buf
, 1);
597 dev_err(&client
->dev
,
598 "Failed to read packet info: %d\n", error
);
602 size
= ts
->buf
[0] & 0x7F;
603 alert
= ts
->buf
[0] & BIT(7);
604 dev_dbg(&client
->dev
, "packet size: %d, alert: %d\n", size
, alert
);
608 dev_err(&client
->dev
, "Empty packet\n");
612 /* Read packet data */
613 cmd
[0] = MIP4_R0_EVENT
;
614 cmd
[1] = MIP4_R1_EVENT_PACKET_DATA
;
615 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), ts
->buf
, size
);
617 dev_err(&client
->dev
,
618 "Failed to read packet data: %d\n", error
);
623 dev_dbg(&client
->dev
, "Alert: %d\n", ts
->buf
[0]);
625 for (i
= 0; i
< size
; i
+= ts
->event_size
) {
626 error
= mip4_handle_packet(ts
, &ts
->buf
[i
]);
631 input_sync(ts
->input
);
638 static int mip4_input_open(struct input_dev
*dev
)
640 struct mip4_ts
*ts
= input_get_drvdata(dev
);
642 return mip4_enable(ts
);
645 static void mip4_input_close(struct input_dev
*dev
)
647 struct mip4_ts
*ts
= input_get_drvdata(dev
);
652 /*****************************************************************
654 *****************************************************************/
657 #define MIP4_BL_PAGE_SIZE 512 /* 512 */
658 #define MIP4_BL_PACKET_SIZE 512 /* 512, 256, 128, 64, ... */
661 * Firmware binary tail info
664 struct mip4_bin_tail
{
668 __le32 bin_start_addr
;
700 #define MIP4_BIN_TAIL_MARK "MBT\001"
701 #define MIP4_BIN_TAIL_SIZE (sizeof(struct mip4_bin_tail))
704 * Bootloader - Read status
706 static int mip4_bl_read_status(struct mip4_ts
*ts
)
708 u8 cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_STATUS
};
710 struct i2c_msg msg
[] = {
712 .addr
= ts
->client
->addr
,
717 .addr
= ts
->client
->addr
,
720 .len
= sizeof(result
),
728 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
729 if (ret
!= ARRAY_SIZE(msg
)) {
730 error
= ret
< 0 ? ret
: -EIO
;
731 dev_err(&ts
->client
->dev
,
732 "Failed to read bootloader status: %d\n",
738 case MIP4_BOOT_STATUS_DONE
:
739 dev_dbg(&ts
->client
->dev
, "%s - done\n", __func__
);
742 case MIP4_BOOT_STATUS_ERROR
:
743 dev_err(&ts
->client
->dev
, "Bootloader failure\n");
746 case MIP4_BOOT_STATUS_BUSY
:
747 dev_dbg(&ts
->client
->dev
, "%s - Busy\n", __func__
);
752 dev_err(&ts
->client
->dev
,
753 "Unexpected bootloader status: %#02x\n",
759 usleep_range(1000, 2000);
766 * Bootloader - Change mode
768 static int mip4_bl_change_mode(struct mip4_ts
*ts
, u8 mode
)
770 u8 mode_chg_cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_MODE
, mode
};
771 u8 mode_read_cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_MODE
};
773 struct i2c_msg msg
[] = {
775 .addr
= ts
->client
->addr
,
777 .buf
= mode_read_cmd
,
778 .len
= sizeof(mode_read_cmd
),
780 .addr
= ts
->client
->addr
,
783 .len
= sizeof(result
),
791 /* Send mode change command */
792 ret
= i2c_master_send(ts
->client
,
793 mode_chg_cmd
, sizeof(mode_chg_cmd
));
794 if (ret
!= sizeof(mode_chg_cmd
)) {
795 error
= ret
< 0 ? ret
: -EIO
;
796 dev_err(&ts
->client
->dev
,
797 "Failed to send %d mode change: %d (%d)\n",
802 dev_dbg(&ts
->client
->dev
,
803 "Sent mode change request (mode: %d)\n", mode
);
808 /* Verify target mode */
809 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
810 if (ret
!= ARRAY_SIZE(msg
)) {
811 error
= ret
< 0 ? ret
: -EIO
;
812 dev_err(&ts
->client
->dev
,
813 "Failed to read device mode: %d\n", error
);
817 dev_dbg(&ts
->client
->dev
,
818 "Current device mode: %d, want: %d\n", result
, mode
);
829 * Bootloader - Start bootloader mode
831 static int mip4_bl_enter(struct mip4_ts
*ts
)
833 return mip4_bl_change_mode(ts
, MIP4_BOOT_MODE_BOOT
);
837 * Bootloader - Exit bootloader mode
839 static int mip4_bl_exit(struct mip4_ts
*ts
)
841 return mip4_bl_change_mode(ts
, MIP4_BOOT_MODE_APP
);
844 static int mip4_bl_get_address(struct mip4_ts
*ts
, u16
*buf_addr
)
846 u8 cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_BUF_ADDR
};
847 u8 result
[sizeof(u16
)];
848 struct i2c_msg msg
[] = {
850 .addr
= ts
->client
->addr
,
855 .addr
= ts
->client
->addr
,
858 .len
= sizeof(result
),
864 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
865 if (ret
!= ARRAY_SIZE(msg
)) {
866 error
= ret
< 0 ? ret
: -EIO
;
867 dev_err(&ts
->client
->dev
,
868 "Failed to retrieve bootloader buffer address: %d\n",
873 *buf_addr
= get_unaligned_le16(result
);
874 dev_dbg(&ts
->client
->dev
,
875 "Bootloader buffer address %#04x\n", *buf_addr
);
880 static int mip4_bl_program_page(struct mip4_ts
*ts
, int offset
,
881 const u8
*data
, int length
, u16 buf_addr
)
889 dev_dbg(&ts
->client
->dev
, "Writing page @%#06x (%d)\n",
892 if (length
> MIP4_BL_PAGE_SIZE
|| length
% MIP4_BL_PACKET_SIZE
) {
893 dev_err(&ts
->client
->dev
,
894 "Invalid page length: %d\n", length
);
898 data_buf
= kmalloc(2 + MIP4_BL_PACKET_SIZE
, GFP_KERNEL
);
903 cmd
[0] = MIP4_R0_BOOT
;
904 cmd
[1] = MIP4_R1_BOOT_TARGET_ADDR
;
905 put_unaligned_le32(offset
, &cmd
[2]);
906 ret
= i2c_master_send(ts
->client
, cmd
, 6);
908 error
= ret
< 0 ? ret
: -EIO
;
909 dev_err(&ts
->client
->dev
,
910 "Failed to send write page address: %d\n", error
);
915 cmd
[0] = MIP4_R0_BOOT
;
916 cmd
[1] = MIP4_R1_BOOT_SIZE
;
917 put_unaligned_le32(length
, &cmd
[2]);
918 ret
= i2c_master_send(ts
->client
, cmd
, 6);
920 error
= ret
< 0 ? ret
: -EIO
;
921 dev_err(&ts
->client
->dev
,
922 "Failed to send write page size: %d\n", error
);
929 buf_offset
+= MIP4_BL_PACKET_SIZE
) {
930 dev_dbg(&ts
->client
->dev
,
931 "writing chunk at %#04x (size %d)\n",
932 buf_offset
, MIP4_BL_PACKET_SIZE
);
933 put_unaligned_be16(buf_addr
+ buf_offset
, data_buf
);
934 memcpy(&data_buf
[2], &data
[buf_offset
], MIP4_BL_PACKET_SIZE
);
935 ret
= i2c_master_send(ts
->client
,
936 data_buf
, 2 + MIP4_BL_PACKET_SIZE
);
937 if (ret
!= 2 + MIP4_BL_PACKET_SIZE
) {
938 error
= ret
< 0 ? ret
: -EIO
;
939 dev_err(&ts
->client
->dev
,
940 "Failed to read chunk at %#04x (size %d): %d\n",
941 buf_offset
, MIP4_BL_PACKET_SIZE
, error
);
947 cmd
[0] = MIP4_R0_BOOT
;
948 cmd
[1] = MIP4_R1_BOOT_CMD
;
949 cmd
[2] = MIP4_BOOT_CMD_PROGRAM
;
950 ret
= i2c_master_send(ts
->client
, cmd
, 3);
952 error
= ret
< 0 ? ret
: -EIO
;
953 dev_err(&ts
->client
->dev
,
954 "Failed to send 'write' command: %d\n", error
);
959 error
= mip4_bl_read_status(ts
);
963 return error
? error
: 0;
966 static int mip4_bl_verify_page(struct mip4_ts
*ts
, int offset
,
967 const u8
*data
, int length
, int buf_addr
)
972 struct i2c_msg msg
[] = {
974 .addr
= ts
->client
->addr
,
979 .addr
= ts
->client
->addr
,
981 .len
= MIP4_BL_PACKET_SIZE
,
987 dev_dbg(&ts
->client
->dev
, "Validating page @%#06x (%d)\n",
991 cmd
[0] = MIP4_R0_BOOT
;
992 cmd
[1] = MIP4_R1_BOOT_TARGET_ADDR
;
993 put_unaligned_le32(offset
, &cmd
[2]);
994 ret
= i2c_master_send(ts
->client
, cmd
, 6);
996 error
= ret
< 0 ? ret
: -EIO
;
997 dev_err(&ts
->client
->dev
,
998 "Failed to send read page address: %d\n", error
);
1003 cmd
[0] = MIP4_R0_BOOT
;
1004 cmd
[1] = MIP4_R1_BOOT_SIZE
;
1005 put_unaligned_le32(length
, &cmd
[2]);
1006 ret
= i2c_master_send(ts
->client
, cmd
, 6);
1008 error
= ret
< 0 ? ret
: -EIO
;
1009 dev_err(&ts
->client
->dev
,
1010 "Failed to send read page size: %d\n", error
);
1015 cmd
[0] = MIP4_R0_BOOT
;
1016 cmd
[1] = MIP4_R1_BOOT_CMD
;
1017 cmd
[2] = MIP4_BOOT_CMD_READ
;
1018 ret
= i2c_master_send(ts
->client
, cmd
, 3);
1020 error
= ret
< 0 ? ret
: -EIO
;
1021 dev_err(&ts
->client
->dev
,
1022 "Failed to send 'read' command: %d\n", error
);
1027 error
= mip4_bl_read_status(ts
);
1032 msg
[1].buf
= read_buf
= kmalloc(MIP4_BL_PACKET_SIZE
, GFP_KERNEL
);
1036 for (buf_offset
= 0;
1037 buf_offset
< length
;
1038 buf_offset
+= MIP4_BL_PACKET_SIZE
) {
1039 dev_dbg(&ts
->client
->dev
,
1040 "reading chunk at %#04x (size %d)\n",
1041 buf_offset
, MIP4_BL_PACKET_SIZE
);
1042 put_unaligned_be16(buf_addr
+ buf_offset
, cmd
);
1043 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
1044 if (ret
!= ARRAY_SIZE(msg
)) {
1045 error
= ret
< 0 ? ret
: -EIO
;
1046 dev_err(&ts
->client
->dev
,
1047 "Failed to read chunk at %#04x (size %d): %d\n",
1048 buf_offset
, MIP4_BL_PACKET_SIZE
, error
);
1052 if (memcmp(&data
[buf_offset
], read_buf
, MIP4_BL_PACKET_SIZE
)) {
1053 dev_err(&ts
->client
->dev
,
1054 "Failed to validate chunk at %#04x (size %d)\n",
1055 buf_offset
, MIP4_BL_PACKET_SIZE
);
1056 #if MIP4_FW_UPDATE_DEBUG
1057 print_hex_dump(KERN_DEBUG
,
1058 MIP4_DEVICE_NAME
" F/W File: ",
1059 DUMP_PREFIX_OFFSET
, 16, 1,
1060 data
+ offset
, MIP4_BL_PACKET_SIZE
,
1062 print_hex_dump(KERN_DEBUG
,
1063 MIP4_DEVICE_NAME
" F/W Chip: ",
1064 DUMP_PREFIX_OFFSET
, 16, 1,
1065 read_buf
, MIP4_BL_PAGE_SIZE
, false);
1073 return error
? error
: 0;
1077 * Flash chip firmware
1079 static int mip4_flash_fw(struct mip4_ts
*ts
,
1080 const u8
*fw_data
, u32 fw_size
, u32 fw_offset
)
1082 struct i2c_client
*client
= ts
->client
;
1087 /* Enter bootloader mode */
1088 dev_dbg(&client
->dev
, "Entering bootloader mode\n");
1090 error
= mip4_bl_enter(ts
);
1092 dev_err(&client
->dev
,
1093 "Failed to enter bootloader mode: %d\n",
1099 error
= mip4_bl_get_address(ts
, &buf_addr
);
1103 /* Program & Verify */
1104 dev_dbg(&client
->dev
,
1105 "Program & Verify, page size: %d, packet size: %d\n",
1106 MIP4_BL_PAGE_SIZE
, MIP4_BL_PACKET_SIZE
);
1108 for (offset
= fw_offset
;
1109 offset
< fw_offset
+ fw_size
;
1110 offset
+= MIP4_BL_PAGE_SIZE
) {
1112 error
= mip4_bl_program_page(ts
, offset
, fw_data
+ offset
,
1113 MIP4_BL_PAGE_SIZE
, buf_addr
);
1118 error
= mip4_bl_verify_page(ts
, offset
, fw_data
+ offset
,
1119 MIP4_BL_PAGE_SIZE
, buf_addr
);
1125 /* Exit bootloader mode */
1126 dev_dbg(&client
->dev
, "Exiting bootloader mode\n");
1128 error2
= mip4_bl_exit(ts
);
1130 dev_err(&client
->dev
,
1131 "Failed to exit bootloader mode: %d\n", error2
);
1140 mip4_query_device(ts
);
1142 /* Refresh device parameters */
1143 input_set_abs_params(ts
->input
, ABS_MT_POSITION_X
, 0, ts
->max_x
, 0, 0);
1144 input_set_abs_params(ts
->input
, ABS_MT_POSITION_Y
, 0, ts
->max_y
, 0, 0);
1145 input_set_abs_params(ts
->input
, ABS_X
, 0, ts
->max_x
, 0, 0);
1146 input_set_abs_params(ts
->input
, ABS_Y
, 0, ts
->max_y
, 0, 0);
1147 input_abs_set_res(ts
->input
, ABS_MT_POSITION_X
, ts
->ppm_x
);
1148 input_abs_set_res(ts
->input
, ABS_MT_POSITION_Y
, ts
->ppm_y
);
1149 input_abs_set_res(ts
->input
, ABS_X
, ts
->ppm_x
);
1150 input_abs_set_res(ts
->input
, ABS_Y
, ts
->ppm_y
);
1152 return error
? error
: 0;
1155 static int mip4_parse_firmware(struct mip4_ts
*ts
, const struct firmware
*fw
,
1156 u32
*fw_offset_start
, u32
*fw_size
,
1157 const struct mip4_bin_tail
**pfw_info
)
1159 const struct mip4_bin_tail
*fw_info
;
1160 struct mip4_fw_version fw_version
;
1163 if (fw
->size
< MIP4_BIN_TAIL_SIZE
) {
1164 dev_err(&ts
->client
->dev
,
1165 "Invalid firmware, size mismatch (tail %zd vs %zd)\n",
1166 MIP4_BIN_TAIL_SIZE
, fw
->size
);
1170 fw_info
= (const void *)&fw
->data
[fw
->size
- MIP4_BIN_TAIL_SIZE
];
1172 #if MIP4_FW_UPDATE_DEBUG
1173 print_hex_dump(KERN_ERR
, MIP4_DEVICE_NAME
" Bin Info: ",
1174 DUMP_PREFIX_OFFSET
, 16, 1, *fw_info
, tail_size
, false);
1177 tail_size
= get_unaligned_le16(&fw_info
->tail_size
);
1178 if (tail_size
!= MIP4_BIN_TAIL_SIZE
) {
1179 dev_err(&ts
->client
->dev
,
1180 "wrong tail size: %d (expected %zd)\n",
1181 tail_size
, MIP4_BIN_TAIL_SIZE
);
1185 /* Check bin format */
1186 if (memcmp(fw_info
->tail_mark
, MIP4_BIN_TAIL_MARK
,
1187 sizeof(fw_info
->tail_mark
))) {
1188 dev_err(&ts
->client
->dev
,
1189 "unable to locate tail marker (%*ph vs %*ph)\n",
1190 (int)sizeof(fw_info
->tail_mark
), fw_info
->tail_mark
,
1191 (int)sizeof(fw_info
->tail_mark
), MIP4_BIN_TAIL_MARK
);
1195 *fw_offset_start
= get_unaligned_le32(&fw_info
->bin_start_addr
);
1196 *fw_size
= get_unaligned_le32(&fw_info
->bin_length
);
1198 dev_dbg(&ts
->client
->dev
,
1199 "F/W Data offset: %#08x, size: %d\n",
1200 *fw_offset_start
, *fw_size
);
1202 if (*fw_size
% MIP4_BL_PAGE_SIZE
) {
1203 dev_err(&ts
->client
->dev
,
1204 "encoded fw length %d is not multiple of pages (%d)\n",
1205 *fw_size
, MIP4_BL_PAGE_SIZE
);
1209 if (fw
->size
!= *fw_offset_start
+ *fw_size
) {
1210 dev_err(&ts
->client
->dev
,
1211 "Wrong firmware size, expected %d bytes, got %zd\n",
1212 *fw_offset_start
+ *fw_size
, fw
->size
);
1216 mip4_parse_fw_version((const u8
*)&fw_info
->ver_boot
, &fw_version
);
1218 dev_dbg(&ts
->client
->dev
,
1219 "F/W file version %04X %04X %04X %04X\n",
1220 fw_version
.boot
, fw_version
.core
,
1221 fw_version
.app
, fw_version
.param
);
1223 dev_dbg(&ts
->client
->dev
, "F/W chip version: %04X %04X %04X %04X\n",
1224 ts
->fw_version
.boot
, ts
->fw_version
.core
,
1225 ts
->fw_version
.app
, ts
->fw_version
.param
);
1227 /* Check F/W type */
1228 if (fw_version
.boot
!= 0xEEEE && fw_version
.boot
!= 0xFFFF &&
1229 fw_version
.core
== 0xEEEE &&
1230 fw_version
.app
== 0xEEEE &&
1231 fw_version
.param
== 0xEEEE) {
1232 dev_dbg(&ts
->client
->dev
, "F/W type: Bootloader\n");
1233 } else if (fw_version
.boot
== 0xEEEE &&
1234 fw_version
.core
!= 0xEEEE && fw_version
.core
!= 0xFFFF &&
1235 fw_version
.app
!= 0xEEEE && fw_version
.app
!= 0xFFFF &&
1236 fw_version
.param
!= 0xEEEE && fw_version
.param
!= 0xFFFF) {
1237 dev_dbg(&ts
->client
->dev
, "F/W type: Main\n");
1239 dev_err(&ts
->client
->dev
, "Wrong firmware type\n");
1246 static int mip4_execute_fw_update(struct mip4_ts
*ts
, const struct firmware
*fw
)
1248 const struct mip4_bin_tail
*fw_info
;
1249 u32 fw_start_offset
;
1254 error
= mip4_parse_firmware(ts
, fw
,
1255 &fw_start_offset
, &fw_size
, &fw_info
);
1259 if (ts
->input
->users
) {
1260 disable_irq(ts
->client
->irq
);
1262 error
= mip4_power_on(ts
);
1267 /* Update firmware */
1269 error
= mip4_flash_fw(ts
, fw
->data
, fw_size
, fw_start_offset
);
1272 } while (--retires
);
1275 dev_err(&ts
->client
->dev
,
1276 "Failed to flash firmware: %d\n", error
);
1279 if (ts
->input
->users
)
1280 enable_irq(ts
->client
->irq
);
1284 return error
? error
: 0;
1287 static ssize_t
mip4_sysfs_fw_update(struct device
*dev
,
1288 struct device_attribute
*attr
,
1289 const char *buf
, size_t count
)
1291 struct i2c_client
*client
= to_i2c_client(dev
);
1292 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1293 const struct firmware
*fw
;
1296 error
= request_firmware(&fw
, ts
->fw_name
, dev
);
1298 dev_err(&ts
->client
->dev
,
1299 "Failed to retrieve firmware %s: %d\n",
1300 ts
->fw_name
, error
);
1305 * Take input mutex to prevent racing with itself and also with
1306 * userspace opening and closing the device and also suspend/resume
1309 mutex_lock(&ts
->input
->mutex
);
1311 error
= mip4_execute_fw_update(ts
, fw
);
1313 mutex_unlock(&ts
->input
->mutex
);
1315 release_firmware(fw
);
1318 dev_err(&ts
->client
->dev
,
1319 "Firmware update failed: %d\n", error
);
1326 static DEVICE_ATTR(update_fw
, S_IWUSR
, NULL
, mip4_sysfs_fw_update
);
1328 static ssize_t
mip4_sysfs_read_fw_version(struct device
*dev
,
1329 struct device_attribute
*attr
,
1332 struct i2c_client
*client
= to_i2c_client(dev
);
1333 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1336 /* Take lock to prevent racing with firmware update */
1337 mutex_lock(&ts
->input
->mutex
);
1339 count
= snprintf(buf
, PAGE_SIZE
, "%04X %04X %04X %04X\n",
1340 ts
->fw_version
.boot
, ts
->fw_version
.core
,
1341 ts
->fw_version
.app
, ts
->fw_version
.param
);
1343 mutex_unlock(&ts
->input
->mutex
);
1348 static DEVICE_ATTR(fw_version
, S_IRUGO
, mip4_sysfs_read_fw_version
, NULL
);
1350 static ssize_t
mip4_sysfs_read_hw_version(struct device
*dev
,
1351 struct device_attribute
*attr
,
1354 struct i2c_client
*client
= to_i2c_client(dev
);
1355 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1358 /* Take lock to prevent racing with firmware update */
1359 mutex_lock(&ts
->input
->mutex
);
1362 * product_name shows the name or version of the hardware
1363 * paired with current firmware in the chip.
1365 count
= snprintf(buf
, PAGE_SIZE
, "%.*s\n",
1366 (int)sizeof(ts
->product_name
), ts
->product_name
);
1368 mutex_unlock(&ts
->input
->mutex
);
1373 static DEVICE_ATTR(hw_version
, S_IRUGO
, mip4_sysfs_read_hw_version
, NULL
);
1375 static ssize_t
mip4_sysfs_read_product_id(struct device
*dev
,
1376 struct device_attribute
*attr
,
1379 struct i2c_client
*client
= to_i2c_client(dev
);
1380 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1383 mutex_lock(&ts
->input
->mutex
);
1385 count
= snprintf(buf
, PAGE_SIZE
, "%04X\n", ts
->product_id
);
1387 mutex_unlock(&ts
->input
->mutex
);
1392 static DEVICE_ATTR(product_id
, S_IRUGO
, mip4_sysfs_read_product_id
, NULL
);
1394 static ssize_t
mip4_sysfs_read_ic_name(struct device
*dev
,
1395 struct device_attribute
*attr
,
1398 struct i2c_client
*client
= to_i2c_client(dev
);
1399 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1402 mutex_lock(&ts
->input
->mutex
);
1404 count
= snprintf(buf
, PAGE_SIZE
, "%.*s\n",
1405 (int)sizeof(ts
->ic_name
), ts
->ic_name
);
1407 mutex_unlock(&ts
->input
->mutex
);
1412 static DEVICE_ATTR(ic_name
, S_IRUGO
, mip4_sysfs_read_ic_name
, NULL
);
1414 static struct attribute
*mip4_attrs
[] = {
1415 &dev_attr_fw_version
.attr
,
1416 &dev_attr_hw_version
.attr
,
1417 &dev_attr_product_id
.attr
,
1418 &dev_attr_ic_name
.attr
,
1419 &dev_attr_update_fw
.attr
,
1423 static const struct attribute_group mip4_attr_group
= {
1424 .attrs
= mip4_attrs
,
1427 static int mip4_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
1430 struct input_dev
*input
;
1433 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
)) {
1434 dev_err(&client
->dev
, "Not supported I2C adapter\n");
1438 ts
= devm_kzalloc(&client
->dev
, sizeof(*ts
), GFP_KERNEL
);
1442 input
= devm_input_allocate_device(&client
->dev
);
1446 ts
->client
= client
;
1449 snprintf(ts
->phys
, sizeof(ts
->phys
),
1450 "%s/input0", dev_name(&client
->dev
));
1452 ts
->gpio_ce
= devm_gpiod_get_optional(&client
->dev
,
1453 "ce", GPIOD_OUT_LOW
);
1454 if (IS_ERR(ts
->gpio_ce
)) {
1455 error
= PTR_ERR(ts
->gpio_ce
);
1456 if (error
!= EPROBE_DEFER
)
1457 dev_err(&client
->dev
,
1458 "Failed to get gpio: %d\n", error
);
1462 error
= mip4_power_on(ts
);
1465 error
= mip4_query_device(ts
);
1470 input
->name
= "MELFAS MIP4 Touchscreen";
1471 input
->phys
= ts
->phys
;
1473 input
->id
.bustype
= BUS_I2C
;
1474 input
->id
.vendor
= 0x13c5;
1475 input
->id
.product
= ts
->product_id
;
1477 input
->open
= mip4_input_open
;
1478 input
->close
= mip4_input_close
;
1480 input_set_drvdata(input
, ts
);
1482 input
->keycode
= ts
->key_code
;
1483 input
->keycodesize
= sizeof(*ts
->key_code
);
1484 input
->keycodemax
= ts
->key_num
;
1486 input_set_abs_params(input
, ABS_MT_POSITION_X
, 0, ts
->max_x
, 0, 0);
1487 input_set_abs_params(input
, ABS_MT_POSITION_Y
, 0, ts
->max_y
, 0, 0);
1488 input_set_abs_params(input
, ABS_MT_PRESSURE
,
1489 MIP4_PRESSURE_MIN
, MIP4_PRESSURE_MAX
, 0, 0);
1490 input_set_abs_params(input
, ABS_MT_TOUCH_MAJOR
,
1491 MIP4_TOUCH_MAJOR_MIN
, MIP4_TOUCH_MAJOR_MAX
, 0, 0);
1492 input_set_abs_params(input
, ABS_MT_TOUCH_MINOR
,
1493 MIP4_TOUCH_MINOR_MIN
, MIP4_TOUCH_MINOR_MAX
, 0, 0);
1494 input_abs_set_res(ts
->input
, ABS_MT_POSITION_X
, ts
->ppm_x
);
1495 input_abs_set_res(ts
->input
, ABS_MT_POSITION_Y
, ts
->ppm_y
);
1497 error
= input_mt_init_slots(input
, MIP4_MAX_FINGERS
, INPUT_MT_DIRECT
);
1501 i2c_set_clientdata(client
, ts
);
1503 error
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
1504 NULL
, mip4_interrupt
,
1505 IRQF_ONESHOT
, MIP4_DEVICE_NAME
, ts
);
1507 dev_err(&client
->dev
,
1508 "Failed to request interrupt %d: %d\n",
1509 client
->irq
, error
);
1513 disable_irq(client
->irq
);
1515 error
= input_register_device(input
);
1517 dev_err(&client
->dev
,
1518 "Failed to register input device: %d\n", error
);
1522 error
= devm_device_add_group(&client
->dev
, &mip4_attr_group
);
1524 dev_err(&client
->dev
,
1525 "Failed to create sysfs attribute group: %d\n", error
);
1532 static int __maybe_unused
mip4_suspend(struct device
*dev
)
1534 struct i2c_client
*client
= to_i2c_client(dev
);
1535 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1536 struct input_dev
*input
= ts
->input
;
1538 mutex_lock(&input
->mutex
);
1540 if (device_may_wakeup(dev
))
1541 ts
->wake_irq_enabled
= enable_irq_wake(client
->irq
) == 0;
1542 else if (input
->users
)
1545 mutex_unlock(&input
->mutex
);
1550 static int __maybe_unused
mip4_resume(struct device
*dev
)
1552 struct i2c_client
*client
= to_i2c_client(dev
);
1553 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1554 struct input_dev
*input
= ts
->input
;
1556 mutex_lock(&input
->mutex
);
1558 if (ts
->wake_irq_enabled
)
1559 disable_irq_wake(client
->irq
);
1560 else if (input
->users
)
1563 mutex_unlock(&input
->mutex
);
1568 static SIMPLE_DEV_PM_OPS(mip4_pm_ops
, mip4_suspend
, mip4_resume
);
1571 static const struct of_device_id mip4_of_match
[] = {
1572 { .compatible
= "melfas,"MIP4_DEVICE_NAME
, },
1575 MODULE_DEVICE_TABLE(of
, mip4_of_match
);
1579 static const struct acpi_device_id mip4_acpi_match
[] = {
1583 MODULE_DEVICE_TABLE(acpi
, mip4_acpi_match
);
1586 static const struct i2c_device_id mip4_i2c_ids
[] = {
1587 { MIP4_DEVICE_NAME
, 0 },
1590 MODULE_DEVICE_TABLE(i2c
, mip4_i2c_ids
);
1592 static struct i2c_driver mip4_driver
= {
1593 .id_table
= mip4_i2c_ids
,
1594 .probe
= mip4_probe
,
1596 .name
= MIP4_DEVICE_NAME
,
1597 .of_match_table
= of_match_ptr(mip4_of_match
),
1598 .acpi_match_table
= ACPI_PTR(mip4_acpi_match
),
1602 module_i2c_driver(mip4_driver
);
1604 MODULE_DESCRIPTION("MELFAS MIP4 Touchscreen");
1605 MODULE_AUTHOR("Sangwon Jee <jeesw@melfas.com>");
1606 MODULE_LICENSE("GPL");