2 * MELFAS MIP4 Touchscreen
4 * Copyright (C) 2016 MELFAS Inc.
6 * Author : Sangwon Jee <jeesw@melfas.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/acpi.h>
20 #include <linux/delay.h>
21 #include <linux/firmware.h>
22 #include <linux/gpio/consumer.h>
23 #include <linux/i2c.h>
24 #include <linux/input.h>
25 #include <linux/input/mt.h>
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <asm/unaligned.h>
32 #define MIP4_DEVICE_NAME "mip4_ts"
34 /*****************************************************************
36 * Version : MIP 4.0 Rev 5.4
37 *****************************************************************/
40 #define MIP4_R0_BOOT 0x00
41 #define MIP4_R1_BOOT_MODE 0x01
42 #define MIP4_R1_BOOT_BUF_ADDR 0x10
43 #define MIP4_R1_BOOT_STATUS 0x20
44 #define MIP4_R1_BOOT_CMD 0x30
45 #define MIP4_R1_BOOT_TARGET_ADDR 0x40
46 #define MIP4_R1_BOOT_SIZE 0x44
48 #define MIP4_R0_INFO 0x01
49 #define MIP4_R1_INFO_PRODUCT_NAME 0x00
50 #define MIP4_R1_INFO_RESOLUTION_X 0x10
51 #define MIP4_R1_INFO_RESOLUTION_Y 0x12
52 #define MIP4_R1_INFO_NODE_NUM_X 0x14
53 #define MIP4_R1_INFO_NODE_NUM_Y 0x15
54 #define MIP4_R1_INFO_KEY_NUM 0x16
55 #define MIP4_R1_INFO_PRESSURE_NUM 0x17
56 #define MIP4_R1_INFO_LENGTH_X 0x18
57 #define MIP4_R1_INFO_LENGTH_Y 0x1A
58 #define MIP4_R1_INFO_PPM_X 0x1C
59 #define MIP4_R1_INFO_PPM_Y 0x1D
60 #define MIP4_R1_INFO_VERSION_BOOT 0x20
61 #define MIP4_R1_INFO_VERSION_CORE 0x22
62 #define MIP4_R1_INFO_VERSION_APP 0x24
63 #define MIP4_R1_INFO_VERSION_PARAM 0x26
64 #define MIP4_R1_INFO_SECT_BOOT_START 0x30
65 #define MIP4_R1_INFO_SECT_BOOT_END 0x31
66 #define MIP4_R1_INFO_SECT_CORE_START 0x32
67 #define MIP4_R1_INFO_SECT_CORE_END 0x33
68 #define MIP4_R1_INFO_SECT_APP_START 0x34
69 #define MIP4_R1_INFO_SECT_APP_END 0x35
70 #define MIP4_R1_INFO_SECT_PARAM_START 0x36
71 #define MIP4_R1_INFO_SECT_PARAM_END 0x37
72 #define MIP4_R1_INFO_BUILD_DATE 0x40
73 #define MIP4_R1_INFO_BUILD_TIME 0x44
74 #define MIP4_R1_INFO_CHECKSUM_PRECALC 0x48
75 #define MIP4_R1_INFO_CHECKSUM_REALTIME 0x4A
76 #define MIP4_R1_INFO_PROTOCOL_NAME 0x50
77 #define MIP4_R1_INFO_PROTOCOL_VERSION 0x58
78 #define MIP4_R1_INFO_IC_ID 0x70
79 #define MIP4_R1_INFO_IC_NAME 0x71
80 #define MIP4_R1_INFO_IC_VENDOR_ID 0x75
81 #define MIP4_R1_INFO_IC_HW_CATEGORY 0x77
82 #define MIP4_R1_INFO_CONTACT_THD_SCR 0x78
83 #define MIP4_R1_INFO_CONTACT_THD_KEY 0x7A
84 #define MIP4_R1_INFO_PID 0x7C
85 #define MIP4_R1_INFO_VID 0x7E
86 #define MIP4_R1_INFO_SLAVE_ADDR 0x80
88 #define MIP4_R0_EVENT 0x02
89 #define MIP4_R1_EVENT_SUPPORTED_FUNC 0x00
90 #define MIP4_R1_EVENT_FORMAT 0x04
91 #define MIP4_R1_EVENT_SIZE 0x06
92 #define MIP4_R1_EVENT_PACKET_INFO 0x10
93 #define MIP4_R1_EVENT_PACKET_DATA 0x11
95 #define MIP4_R0_CTRL 0x06
96 #define MIP4_R1_CTRL_READY_STATUS 0x00
97 #define MIP4_R1_CTRL_EVENT_READY 0x01
98 #define MIP4_R1_CTRL_MODE 0x10
99 #define MIP4_R1_CTRL_EVENT_TRIGGER_TYPE 0x11
100 #define MIP4_R1_CTRL_RECALIBRATE 0x12
101 #define MIP4_R1_CTRL_POWER_STATE 0x13
102 #define MIP4_R1_CTRL_GESTURE_TYPE 0x14
103 #define MIP4_R1_CTRL_DISABLE_ESD_ALERT 0x18
104 #define MIP4_R1_CTRL_CHARGER_MODE 0x19
105 #define MIP4_R1_CTRL_HIGH_SENS_MODE 0x1A
106 #define MIP4_R1_CTRL_WINDOW_MODE 0x1B
107 #define MIP4_R1_CTRL_PALM_REJECTION 0x1C
108 #define MIP4_R1_CTRL_EDGE_CORRECTION 0x1D
109 #define MIP4_R1_CTRL_ENTER_GLOVE_MODE 0x1E
110 #define MIP4_R1_CTRL_I2C_ON_LPM 0x1F
111 #define MIP4_R1_CTRL_GESTURE_DEBUG 0x20
112 #define MIP4_R1_CTRL_PALM_EVENT 0x22
113 #define MIP4_R1_CTRL_PROXIMITY_SENSING 0x23
116 #define MIP4_BOOT_MODE_BOOT 0x01
117 #define MIP4_BOOT_MODE_APP 0x02
119 #define MIP4_BOOT_STATUS_BUSY 0x05
120 #define MIP4_BOOT_STATUS_ERROR 0x0E
121 #define MIP4_BOOT_STATUS_DONE 0xA0
123 #define MIP4_BOOT_CMD_MASS_ERASE 0x15
124 #define MIP4_BOOT_CMD_PROGRAM 0x54
125 #define MIP4_BOOT_CMD_ERASE 0x8F
126 #define MIP4_BOOT_CMD_WRITE 0xA5
127 #define MIP4_BOOT_CMD_READ 0xC2
129 #define MIP4_EVENT_INPUT_TYPE_KEY 0
130 #define MIP4_EVENT_INPUT_TYPE_SCREEN 1
131 #define MIP4_EVENT_INPUT_TYPE_PROXIMITY 2
133 #define I2C_RETRY_COUNT 3 /* 2~ */
135 #define MIP4_BUF_SIZE 128
136 #define MIP4_MAX_FINGERS 10
137 #define MIP4_MAX_KEYS 4
139 #define MIP4_TOUCH_MAJOR_MIN 0
140 #define MIP4_TOUCH_MAJOR_MAX 255
141 #define MIP4_TOUCH_MINOR_MIN 0
142 #define MIP4_TOUCH_MINOR_MAX 255
143 #define MIP4_PRESSURE_MIN 0
144 #define MIP4_PRESSURE_MAX 255
146 #define MIP4_FW_NAME "melfas_mip4.fw"
147 #define MIP4_FW_UPDATE_DEBUG 0 /* 0 (default) or 1 */
149 struct mip4_fw_version
{
157 struct i2c_client
*client
;
158 struct input_dev
*input
;
159 struct gpio_desc
*gpio_ce
;
162 char product_name
[16];
175 struct mip4_fw_version fw_version
;
177 unsigned int event_size
;
178 unsigned int event_format
;
180 unsigned int key_num
;
181 unsigned short key_code
[MIP4_MAX_KEYS
];
183 bool wake_irq_enabled
;
185 u8 buf
[MIP4_BUF_SIZE
];
188 static int mip4_i2c_xfer(struct mip4_ts
*ts
,
189 char *write_buf
, unsigned int write_len
,
190 char *read_buf
, unsigned int read_len
)
192 struct i2c_msg msg
[] = {
194 .addr
= ts
->client
->addr
,
199 .addr
= ts
->client
->addr
,
205 int retry
= I2C_RETRY_COUNT
;
210 res
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
211 if (res
== ARRAY_SIZE(msg
))
214 error
= res
< 0 ? res
: -EIO
;
215 dev_err(&ts
->client
->dev
,
216 "%s - i2c_transfer failed: %d (%d)\n",
217 __func__
, error
, res
);
223 static void mip4_parse_fw_version(const u8
*buf
, struct mip4_fw_version
*v
)
225 v
->boot
= get_unaligned_le16(buf
+ 0);
226 v
->core
= get_unaligned_le16(buf
+ 2);
227 v
->app
= get_unaligned_le16(buf
+ 4);
228 v
->param
= get_unaligned_le16(buf
+ 6);
232 * Read chip firmware version
234 static int mip4_get_fw_version(struct mip4_ts
*ts
)
236 u8 cmd
[] = { MIP4_R0_INFO
, MIP4_R1_INFO_VERSION_BOOT
};
237 u8 buf
[sizeof(ts
->fw_version
)];
240 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, sizeof(buf
));
242 memset(&ts
->fw_version
, 0xff, sizeof(ts
->fw_version
));
246 mip4_parse_fw_version(buf
, &ts
->fw_version
);
252 * Fetch device characteristics
254 static int mip4_query_device(struct mip4_ts
*ts
)
256 union i2c_smbus_data dummy
;
262 * Make sure there is something at this address as we do not
263 * consider subsequent failures as fatal.
265 if (i2c_smbus_xfer(ts
->client
->adapter
, ts
->client
->addr
,
266 0, I2C_SMBUS_READ
, 0, I2C_SMBUS_BYTE
, &dummy
) < 0) {
267 dev_err(&ts
->client
->dev
, "nothing at this address\n");
272 cmd
[0] = MIP4_R0_INFO
;
273 cmd
[1] = MIP4_R1_INFO_PRODUCT_NAME
;
274 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
),
275 ts
->product_name
, sizeof(ts
->product_name
));
277 dev_warn(&ts
->client
->dev
,
278 "Failed to retrieve product name: %d\n", error
);
280 dev_dbg(&ts
->client
->dev
, "product name: %.*s\n",
281 (int)sizeof(ts
->product_name
), ts
->product_name
);
284 cmd
[0] = MIP4_R0_INFO
;
285 cmd
[1] = MIP4_R1_INFO_PID
;
286 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 2);
288 dev_warn(&ts
->client
->dev
,
289 "Failed to retrieve product id: %d\n", error
);
291 ts
->product_id
= get_unaligned_le16(&buf
[0]);
292 dev_dbg(&ts
->client
->dev
, "product id: %04X\n", ts
->product_id
);
296 snprintf(ts
->fw_name
, sizeof(ts
->fw_name
),
297 "melfas_mip4_%04X.fw", ts
->product_id
);
298 dev_dbg(&ts
->client
->dev
, "firmware name: %s\n", ts
->fw_name
);
301 cmd
[0] = MIP4_R0_INFO
;
302 cmd
[1] = MIP4_R1_INFO_IC_NAME
;
303 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
),
304 ts
->ic_name
, sizeof(ts
->ic_name
));
306 dev_warn(&ts
->client
->dev
,
307 "Failed to retrieve IC name: %d\n", error
);
309 dev_dbg(&ts
->client
->dev
, "IC name: %.*s\n",
310 (int)sizeof(ts
->ic_name
), ts
->ic_name
);
312 /* Firmware version */
313 error
= mip4_get_fw_version(ts
);
315 dev_warn(&ts
->client
->dev
,
316 "Failed to retrieve FW version: %d\n", error
);
318 dev_dbg(&ts
->client
->dev
, "F/W Version: %04X %04X %04X %04X\n",
319 ts
->fw_version
.boot
, ts
->fw_version
.core
,
320 ts
->fw_version
.app
, ts
->fw_version
.param
);
323 cmd
[0] = MIP4_R0_INFO
;
324 cmd
[1] = MIP4_R1_INFO_RESOLUTION_X
;
325 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 14);
327 dev_warn(&ts
->client
->dev
,
328 "Failed to retrieve touchscreen parameters: %d\n",
331 ts
->max_x
= get_unaligned_le16(&buf
[0]);
332 ts
->max_y
= get_unaligned_le16(&buf
[2]);
333 dev_dbg(&ts
->client
->dev
, "max_x: %d, max_y: %d\n",
334 ts
->max_x
, ts
->max_y
);
338 ts
->node_key
= buf
[6];
339 dev_dbg(&ts
->client
->dev
,
340 "node_x: %d, node_y: %d, node_key: %d\n",
341 ts
->node_x
, ts
->node_y
, ts
->node_key
);
345 dev_dbg(&ts
->client
->dev
, "ppm_x: %d, ppm_y: %d\n",
346 ts
->ppm_x
, ts
->ppm_y
);
349 if (ts
->node_key
> 0)
350 ts
->key_num
= ts
->node_key
;
354 cmd
[0] = MIP4_R0_EVENT
;
355 cmd
[1] = MIP4_R1_EVENT_SUPPORTED_FUNC
;
356 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), buf
, 7);
358 dev_warn(&ts
->client
->dev
,
359 "Failed to retrieve device type: %d\n", error
);
360 ts
->event_format
= 0xff;
362 ts
->event_format
= get_unaligned_le16(&buf
[4]);
363 ts
->event_size
= buf
[6];
364 dev_dbg(&ts
->client
->dev
, "event_format: %d, event_size: %d\n",
365 ts
->event_format
, ts
->event_size
);
367 if (ts
->event_format
== 2 || ts
->event_format
> 3)
368 dev_warn(&ts
->client
->dev
,
369 "Unknown event format %d\n", ts
->event_format
);
375 static int mip4_power_on(struct mip4_ts
*ts
)
378 gpiod_set_value_cansleep(ts
->gpio_ce
, 1);
380 /* Booting delay : 200~300ms */
381 usleep_range(200 * 1000, 300 * 1000);
387 static void mip4_power_off(struct mip4_ts
*ts
)
390 gpiod_set_value_cansleep(ts
->gpio_ce
, 0);
394 * Clear touch input event status
396 static void mip4_clear_input(struct mip4_ts
*ts
)
401 for (i
= 0; i
< MIP4_MAX_FINGERS
; i
++) {
402 input_mt_slot(ts
->input
, i
);
403 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, 0);
407 for (i
= 0; i
< ts
->key_num
; i
++)
408 input_report_key(ts
->input
, ts
->key_code
[i
], 0);
410 input_sync(ts
->input
);
413 static int mip4_enable(struct mip4_ts
*ts
)
417 error
= mip4_power_on(ts
);
421 enable_irq(ts
->client
->irq
);
426 static void mip4_disable(struct mip4_ts
*ts
)
428 disable_irq(ts
->client
->irq
);
432 mip4_clear_input(ts
);
435 /*****************************************************************
437 *****************************************************************/
439 static void mip4_report_keys(struct mip4_ts
*ts
, u8
*packet
)
444 switch (ts
->event_format
) {
447 key
= packet
[0] & 0x0F;
448 down
= packet
[0] & 0x80;
453 key
= packet
[0] & 0x0F;
454 down
= packet
[1] & 0x01;
458 /* Report key event */
459 if (key
>= 1 && key
<= ts
->key_num
) {
460 unsigned short keycode
= ts
->key_code
[key
- 1];
462 dev_dbg(&ts
->client
->dev
,
463 "Key - ID: %d, keycode: %d, state: %d\n",
466 input_event(ts
->input
, EV_MSC
, MSC_SCAN
, keycode
);
467 input_report_key(ts
->input
, keycode
, down
);
470 dev_err(&ts
->client
->dev
, "Unknown key: %d\n", key
);
474 static void mip4_report_touch(struct mip4_ts
*ts
, u8
*packet
)
481 u8 pressure_stage
= 0;
487 switch (ts
->event_format
) {
491 state
= packet
[0] & BIT(7);
492 hover
= packet
[0] & BIT(5);
493 palm
= packet
[0] & BIT(4);
494 id
= (packet
[0] & 0x0F) - 1;
495 x
= ((packet
[1] & 0x0F) << 8) | packet
[2];
496 y
= (((packet
[1] >> 4) & 0x0F) << 8) |
498 pressure
= packet
[4];
500 if (ts
->event_format
== 0) {
501 touch_major
= packet
[5];
502 touch_minor
= packet
[5];
504 touch_major
= packet
[6];
505 touch_minor
= packet
[7];
511 /* Touch + Force(Pressure) */
512 id
= (packet
[0] & 0x0F) - 1;
513 hover
= packet
[1] & BIT(2);
514 palm
= packet
[1] & BIT(1);
515 state
= packet
[1] & BIT(0);
516 x
= ((packet
[2] & 0x0F) << 8) | packet
[3];
517 y
= (((packet
[2] >> 4) & 0x0F) << 8) |
520 pressure_stage
= (packet
[7] & 0xF0) >> 4;
521 pressure
= ((packet
[7] & 0x0F) << 8) |
523 touch_major
= packet
[9];
524 touch_minor
= packet
[10];
528 dev_dbg(&ts
->client
->dev
,
529 "Screen - Slot: %d State: %d X: %04d Y: %04d Z: %d\n",
530 id
, state
, x
, y
, pressure
);
532 if (unlikely(id
< 0 || id
>= MIP4_MAX_FINGERS
)) {
533 dev_err(&ts
->client
->dev
, "Screen - invalid slot ID: %d\n", id
);
535 /* Press or Move event */
536 input_mt_slot(ts
->input
, id
);
537 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, true);
538 input_report_abs(ts
->input
, ABS_MT_POSITION_X
, x
);
539 input_report_abs(ts
->input
, ABS_MT_POSITION_Y
, y
);
540 input_report_abs(ts
->input
, ABS_MT_PRESSURE
, pressure
);
541 input_report_abs(ts
->input
, ABS_MT_TOUCH_MAJOR
, touch_major
);
542 input_report_abs(ts
->input
, ABS_MT_TOUCH_MINOR
, touch_minor
);
545 input_mt_slot(ts
->input
, id
);
546 input_mt_report_slot_state(ts
->input
, MT_TOOL_FINGER
, 0);
549 input_mt_sync_frame(ts
->input
);
552 static int mip4_handle_packet(struct mip4_ts
*ts
, u8
*packet
)
556 switch (ts
->event_format
) {
559 type
= (packet
[0] & 0x40) >> 6;
563 type
= (packet
[0] & 0xF0) >> 4;
567 /* Should not happen unless we have corrupted firmware */
571 dev_dbg(&ts
->client
->dev
, "Type: %d\n", type
);
573 /* Report input event */
575 case MIP4_EVENT_INPUT_TYPE_KEY
:
576 mip4_report_keys(ts
, packet
);
579 case MIP4_EVENT_INPUT_TYPE_SCREEN
:
580 mip4_report_touch(ts
, packet
);
584 dev_err(&ts
->client
->dev
, "Unknown event type: %d\n", type
);
591 static irqreturn_t
mip4_interrupt(int irq
, void *dev_id
)
593 struct mip4_ts
*ts
= dev_id
;
594 struct i2c_client
*client
= ts
->client
;
601 /* Read packet info */
602 cmd
[0] = MIP4_R0_EVENT
;
603 cmd
[1] = MIP4_R1_EVENT_PACKET_INFO
;
604 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), ts
->buf
, 1);
606 dev_err(&client
->dev
,
607 "Failed to read packet info: %d\n", error
);
611 size
= ts
->buf
[0] & 0x7F;
612 alert
= ts
->buf
[0] & BIT(7);
613 dev_dbg(&client
->dev
, "packet size: %d, alert: %d\n", size
, alert
);
617 dev_err(&client
->dev
, "Empty packet\n");
621 /* Read packet data */
622 cmd
[0] = MIP4_R0_EVENT
;
623 cmd
[1] = MIP4_R1_EVENT_PACKET_DATA
;
624 error
= mip4_i2c_xfer(ts
, cmd
, sizeof(cmd
), ts
->buf
, size
);
626 dev_err(&client
->dev
,
627 "Failed to read packet data: %d\n", error
);
632 dev_dbg(&client
->dev
, "Alert: %d\n", ts
->buf
[0]);
634 for (i
= 0; i
< size
; i
+= ts
->event_size
) {
635 error
= mip4_handle_packet(ts
, &ts
->buf
[i
]);
640 input_sync(ts
->input
);
647 static int mip4_input_open(struct input_dev
*dev
)
649 struct mip4_ts
*ts
= input_get_drvdata(dev
);
651 return mip4_enable(ts
);
654 static void mip4_input_close(struct input_dev
*dev
)
656 struct mip4_ts
*ts
= input_get_drvdata(dev
);
661 /*****************************************************************
663 *****************************************************************/
666 #define MIP4_BL_PAGE_SIZE 512 /* 512 */
667 #define MIP4_BL_PACKET_SIZE 512 /* 512, 256, 128, 64, ... */
670 * Firmware binary tail info
673 struct mip4_bin_tail
{
677 __le32 bin_start_addr
;
709 #define MIP4_BIN_TAIL_MARK "MBT\001"
710 #define MIP4_BIN_TAIL_SIZE (sizeof(struct mip4_bin_tail))
713 * Bootloader - Read status
715 static int mip4_bl_read_status(struct mip4_ts
*ts
)
717 u8 cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_STATUS
};
719 struct i2c_msg msg
[] = {
721 .addr
= ts
->client
->addr
,
726 .addr
= ts
->client
->addr
,
729 .len
= sizeof(result
),
737 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
738 if (ret
!= ARRAY_SIZE(msg
)) {
739 error
= ret
< 0 ? ret
: -EIO
;
740 dev_err(&ts
->client
->dev
,
741 "Failed to read bootloader status: %d\n",
747 case MIP4_BOOT_STATUS_DONE
:
748 dev_dbg(&ts
->client
->dev
, "%s - done\n", __func__
);
751 case MIP4_BOOT_STATUS_ERROR
:
752 dev_err(&ts
->client
->dev
, "Bootloader failure\n");
755 case MIP4_BOOT_STATUS_BUSY
:
756 dev_dbg(&ts
->client
->dev
, "%s - Busy\n", __func__
);
761 dev_err(&ts
->client
->dev
,
762 "Unexpected bootloader status: %#02x\n",
768 usleep_range(1000, 2000);
775 * Bootloader - Change mode
777 static int mip4_bl_change_mode(struct mip4_ts
*ts
, u8 mode
)
779 u8 mode_chg_cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_MODE
, mode
};
780 u8 mode_read_cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_MODE
};
782 struct i2c_msg msg
[] = {
784 .addr
= ts
->client
->addr
,
786 .buf
= mode_read_cmd
,
787 .len
= sizeof(mode_read_cmd
),
789 .addr
= ts
->client
->addr
,
792 .len
= sizeof(result
),
800 /* Send mode change command */
801 ret
= i2c_master_send(ts
->client
,
802 mode_chg_cmd
, sizeof(mode_chg_cmd
));
803 if (ret
!= sizeof(mode_chg_cmd
)) {
804 error
= ret
< 0 ? ret
: -EIO
;
805 dev_err(&ts
->client
->dev
,
806 "Failed to send %d mode change: %d (%d)\n",
811 dev_dbg(&ts
->client
->dev
,
812 "Sent mode change request (mode: %d)\n", mode
);
817 /* Verify target mode */
818 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
819 if (ret
!= ARRAY_SIZE(msg
)) {
820 error
= ret
< 0 ? ret
: -EIO
;
821 dev_err(&ts
->client
->dev
,
822 "Failed to read device mode: %d\n", error
);
826 dev_dbg(&ts
->client
->dev
,
827 "Current device mode: %d, want: %d\n", result
, mode
);
838 * Bootloader - Start bootloader mode
840 static int mip4_bl_enter(struct mip4_ts
*ts
)
842 return mip4_bl_change_mode(ts
, MIP4_BOOT_MODE_BOOT
);
846 * Bootloader - Exit bootloader mode
848 static int mip4_bl_exit(struct mip4_ts
*ts
)
850 return mip4_bl_change_mode(ts
, MIP4_BOOT_MODE_APP
);
853 static int mip4_bl_get_address(struct mip4_ts
*ts
, u16
*buf_addr
)
855 u8 cmd
[] = { MIP4_R0_BOOT
, MIP4_R1_BOOT_BUF_ADDR
};
856 u8 result
[sizeof(u16
)];
857 struct i2c_msg msg
[] = {
859 .addr
= ts
->client
->addr
,
864 .addr
= ts
->client
->addr
,
867 .len
= sizeof(result
),
873 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
874 if (ret
!= ARRAY_SIZE(msg
)) {
875 error
= ret
< 0 ? ret
: -EIO
;
876 dev_err(&ts
->client
->dev
,
877 "Failed to retrieve bootloader buffer address: %d\n",
882 *buf_addr
= get_unaligned_le16(result
);
883 dev_dbg(&ts
->client
->dev
,
884 "Bootloader buffer address %#04x\n", *buf_addr
);
889 static int mip4_bl_program_page(struct mip4_ts
*ts
, int offset
,
890 const u8
*data
, int length
, u16 buf_addr
)
898 dev_dbg(&ts
->client
->dev
, "Writing page @%#06x (%d)\n",
901 if (length
> MIP4_BL_PAGE_SIZE
|| length
% MIP4_BL_PACKET_SIZE
) {
902 dev_err(&ts
->client
->dev
,
903 "Invalid page length: %d\n", length
);
907 data_buf
= kmalloc(2 + MIP4_BL_PACKET_SIZE
, GFP_KERNEL
);
912 cmd
[0] = MIP4_R0_BOOT
;
913 cmd
[1] = MIP4_R1_BOOT_TARGET_ADDR
;
914 put_unaligned_le32(offset
, &cmd
[2]);
915 ret
= i2c_master_send(ts
->client
, cmd
, 6);
917 error
= ret
< 0 ? ret
: -EIO
;
918 dev_err(&ts
->client
->dev
,
919 "Failed to send write page address: %d\n", error
);
924 cmd
[0] = MIP4_R0_BOOT
;
925 cmd
[1] = MIP4_R1_BOOT_SIZE
;
926 put_unaligned_le32(length
, &cmd
[2]);
927 ret
= i2c_master_send(ts
->client
, cmd
, 6);
929 error
= ret
< 0 ? ret
: -EIO
;
930 dev_err(&ts
->client
->dev
,
931 "Failed to send write page size: %d\n", error
);
938 buf_offset
+= MIP4_BL_PACKET_SIZE
) {
939 dev_dbg(&ts
->client
->dev
,
940 "writing chunk at %#04x (size %d)\n",
941 buf_offset
, MIP4_BL_PACKET_SIZE
);
942 put_unaligned_be16(buf_addr
+ buf_offset
, data_buf
);
943 memcpy(&data_buf
[2], &data
[buf_offset
], MIP4_BL_PACKET_SIZE
);
944 ret
= i2c_master_send(ts
->client
,
945 data_buf
, 2 + MIP4_BL_PACKET_SIZE
);
946 if (ret
!= 2 + MIP4_BL_PACKET_SIZE
) {
947 error
= ret
< 0 ? ret
: -EIO
;
948 dev_err(&ts
->client
->dev
,
949 "Failed to read chunk at %#04x (size %d): %d\n",
950 buf_offset
, MIP4_BL_PACKET_SIZE
, error
);
956 cmd
[0] = MIP4_R0_BOOT
;
957 cmd
[1] = MIP4_R1_BOOT_CMD
;
958 cmd
[2] = MIP4_BOOT_CMD_PROGRAM
;
959 ret
= i2c_master_send(ts
->client
, cmd
, 3);
961 error
= ret
< 0 ? ret
: -EIO
;
962 dev_err(&ts
->client
->dev
,
963 "Failed to send 'write' command: %d\n", error
);
968 error
= mip4_bl_read_status(ts
);
972 return error
? error
: 0;
975 static int mip4_bl_verify_page(struct mip4_ts
*ts
, int offset
,
976 const u8
*data
, int length
, int buf_addr
)
981 struct i2c_msg msg
[] = {
983 .addr
= ts
->client
->addr
,
988 .addr
= ts
->client
->addr
,
990 .len
= MIP4_BL_PACKET_SIZE
,
996 dev_dbg(&ts
->client
->dev
, "Validating page @%#06x (%d)\n",
1000 cmd
[0] = MIP4_R0_BOOT
;
1001 cmd
[1] = MIP4_R1_BOOT_TARGET_ADDR
;
1002 put_unaligned_le32(offset
, &cmd
[2]);
1003 ret
= i2c_master_send(ts
->client
, cmd
, 6);
1005 error
= ret
< 0 ? ret
: -EIO
;
1006 dev_err(&ts
->client
->dev
,
1007 "Failed to send read page address: %d\n", error
);
1012 cmd
[0] = MIP4_R0_BOOT
;
1013 cmd
[1] = MIP4_R1_BOOT_SIZE
;
1014 put_unaligned_le32(length
, &cmd
[2]);
1015 ret
= i2c_master_send(ts
->client
, cmd
, 6);
1017 error
= ret
< 0 ? ret
: -EIO
;
1018 dev_err(&ts
->client
->dev
,
1019 "Failed to send read page size: %d\n", error
);
1024 cmd
[0] = MIP4_R0_BOOT
;
1025 cmd
[1] = MIP4_R1_BOOT_CMD
;
1026 cmd
[2] = MIP4_BOOT_CMD_READ
;
1027 ret
= i2c_master_send(ts
->client
, cmd
, 3);
1029 error
= ret
< 0 ? ret
: -EIO
;
1030 dev_err(&ts
->client
->dev
,
1031 "Failed to send 'read' command: %d\n", error
);
1036 error
= mip4_bl_read_status(ts
);
1041 msg
[1].buf
= read_buf
= kmalloc(MIP4_BL_PACKET_SIZE
, GFP_KERNEL
);
1045 for (buf_offset
= 0;
1046 buf_offset
< length
;
1047 buf_offset
+= MIP4_BL_PACKET_SIZE
) {
1048 dev_dbg(&ts
->client
->dev
,
1049 "reading chunk at %#04x (size %d)\n",
1050 buf_offset
, MIP4_BL_PACKET_SIZE
);
1051 put_unaligned_be16(buf_addr
+ buf_offset
, cmd
);
1052 ret
= i2c_transfer(ts
->client
->adapter
, msg
, ARRAY_SIZE(msg
));
1053 if (ret
!= ARRAY_SIZE(msg
)) {
1054 error
= ret
< 0 ? ret
: -EIO
;
1055 dev_err(&ts
->client
->dev
,
1056 "Failed to read chunk at %#04x (size %d): %d\n",
1057 buf_offset
, MIP4_BL_PACKET_SIZE
, error
);
1061 if (memcmp(&data
[buf_offset
], read_buf
, MIP4_BL_PACKET_SIZE
)) {
1062 dev_err(&ts
->client
->dev
,
1063 "Failed to validate chunk at %#04x (size %d)\n",
1064 buf_offset
, MIP4_BL_PACKET_SIZE
);
1065 #if MIP4_FW_UPDATE_DEBUG
1066 print_hex_dump(KERN_DEBUG
,
1067 MIP4_DEVICE_NAME
" F/W File: ",
1068 DUMP_PREFIX_OFFSET
, 16, 1,
1069 data
+ offset
, MIP4_BL_PACKET_SIZE
,
1071 print_hex_dump(KERN_DEBUG
,
1072 MIP4_DEVICE_NAME
" F/W Chip: ",
1073 DUMP_PREFIX_OFFSET
, 16, 1,
1074 read_buf
, MIP4_BL_PAGE_SIZE
, false);
1082 return error
? error
: 0;
1086 * Flash chip firmware
1088 static int mip4_flash_fw(struct mip4_ts
*ts
,
1089 const u8
*fw_data
, u32 fw_size
, u32 fw_offset
)
1091 struct i2c_client
*client
= ts
->client
;
1096 /* Enter bootloader mode */
1097 dev_dbg(&client
->dev
, "Entering bootloader mode\n");
1099 error
= mip4_bl_enter(ts
);
1101 dev_err(&client
->dev
,
1102 "Failed to enter bootloader mode: %d\n",
1108 error
= mip4_bl_get_address(ts
, &buf_addr
);
1112 /* Program & Verify */
1113 dev_dbg(&client
->dev
,
1114 "Program & Verify, page size: %d, packet size: %d\n",
1115 MIP4_BL_PAGE_SIZE
, MIP4_BL_PACKET_SIZE
);
1117 for (offset
= fw_offset
;
1118 offset
< fw_offset
+ fw_size
;
1119 offset
+= MIP4_BL_PAGE_SIZE
) {
1121 error
= mip4_bl_program_page(ts
, offset
, fw_data
+ offset
,
1122 MIP4_BL_PAGE_SIZE
, buf_addr
);
1127 error
= mip4_bl_verify_page(ts
, offset
, fw_data
+ offset
,
1128 MIP4_BL_PAGE_SIZE
, buf_addr
);
1134 /* Exit bootloader mode */
1135 dev_dbg(&client
->dev
, "Exiting bootloader mode\n");
1137 error2
= mip4_bl_exit(ts
);
1139 dev_err(&client
->dev
,
1140 "Failed to exit bootloader mode: %d\n", error2
);
1149 mip4_query_device(ts
);
1151 /* Refresh device parameters */
1152 input_set_abs_params(ts
->input
, ABS_MT_POSITION_X
, 0, ts
->max_x
, 0, 0);
1153 input_set_abs_params(ts
->input
, ABS_MT_POSITION_Y
, 0, ts
->max_y
, 0, 0);
1154 input_set_abs_params(ts
->input
, ABS_X
, 0, ts
->max_x
, 0, 0);
1155 input_set_abs_params(ts
->input
, ABS_Y
, 0, ts
->max_y
, 0, 0);
1156 input_abs_set_res(ts
->input
, ABS_MT_POSITION_X
, ts
->ppm_x
);
1157 input_abs_set_res(ts
->input
, ABS_MT_POSITION_Y
, ts
->ppm_y
);
1158 input_abs_set_res(ts
->input
, ABS_X
, ts
->ppm_x
);
1159 input_abs_set_res(ts
->input
, ABS_Y
, ts
->ppm_y
);
1161 return error
? error
: 0;
1164 static int mip4_parse_firmware(struct mip4_ts
*ts
, const struct firmware
*fw
,
1165 u32
*fw_offset_start
, u32
*fw_size
,
1166 const struct mip4_bin_tail
**pfw_info
)
1168 const struct mip4_bin_tail
*fw_info
;
1169 struct mip4_fw_version fw_version
;
1172 if (fw
->size
< MIP4_BIN_TAIL_SIZE
) {
1173 dev_err(&ts
->client
->dev
,
1174 "Invalid firmware, size mismatch (tail %zd vs %zd)\n",
1175 MIP4_BIN_TAIL_SIZE
, fw
->size
);
1179 fw_info
= (const void *)&fw
->data
[fw
->size
- MIP4_BIN_TAIL_SIZE
];
1181 #if MIP4_FW_UPDATE_DEBUG
1182 print_hex_dump(KERN_ERR
, MIP4_DEVICE_NAME
" Bin Info: ",
1183 DUMP_PREFIX_OFFSET
, 16, 1, *fw_info
, tail_size
, false);
1186 tail_size
= get_unaligned_le16(&fw_info
->tail_size
);
1187 if (tail_size
!= MIP4_BIN_TAIL_SIZE
) {
1188 dev_err(&ts
->client
->dev
,
1189 "wrong tail size: %d (expected %zd)\n",
1190 tail_size
, MIP4_BIN_TAIL_SIZE
);
1194 /* Check bin format */
1195 if (memcmp(fw_info
->tail_mark
, MIP4_BIN_TAIL_MARK
,
1196 sizeof(fw_info
->tail_mark
))) {
1197 dev_err(&ts
->client
->dev
,
1198 "unable to locate tail marker (%*ph vs %*ph)\n",
1199 (int)sizeof(fw_info
->tail_mark
), fw_info
->tail_mark
,
1200 (int)sizeof(fw_info
->tail_mark
), MIP4_BIN_TAIL_MARK
);
1204 *fw_offset_start
= get_unaligned_le32(&fw_info
->bin_start_addr
);
1205 *fw_size
= get_unaligned_le32(&fw_info
->bin_length
);
1207 dev_dbg(&ts
->client
->dev
,
1208 "F/W Data offset: %#08x, size: %d\n",
1209 *fw_offset_start
, *fw_size
);
1211 if (*fw_size
% MIP4_BL_PAGE_SIZE
) {
1212 dev_err(&ts
->client
->dev
,
1213 "encoded fw length %d is not multiple of pages (%d)\n",
1214 *fw_size
, MIP4_BL_PAGE_SIZE
);
1218 if (fw
->size
!= *fw_offset_start
+ *fw_size
) {
1219 dev_err(&ts
->client
->dev
,
1220 "Wrong firmware size, expected %d bytes, got %zd\n",
1221 *fw_offset_start
+ *fw_size
, fw
->size
);
1225 mip4_parse_fw_version((const u8
*)&fw_info
->ver_boot
, &fw_version
);
1227 dev_dbg(&ts
->client
->dev
,
1228 "F/W file version %04X %04X %04X %04X\n",
1229 fw_version
.boot
, fw_version
.core
,
1230 fw_version
.app
, fw_version
.param
);
1232 dev_dbg(&ts
->client
->dev
, "F/W chip version: %04X %04X %04X %04X\n",
1233 ts
->fw_version
.boot
, ts
->fw_version
.core
,
1234 ts
->fw_version
.app
, ts
->fw_version
.param
);
1236 /* Check F/W type */
1237 if (fw_version
.boot
!= 0xEEEE && fw_version
.boot
!= 0xFFFF &&
1238 fw_version
.core
== 0xEEEE &&
1239 fw_version
.app
== 0xEEEE &&
1240 fw_version
.param
== 0xEEEE) {
1241 dev_dbg(&ts
->client
->dev
, "F/W type: Bootloader\n");
1242 } else if (fw_version
.boot
== 0xEEEE &&
1243 fw_version
.core
!= 0xEEEE && fw_version
.core
!= 0xFFFF &&
1244 fw_version
.app
!= 0xEEEE && fw_version
.app
!= 0xFFFF &&
1245 fw_version
.param
!= 0xEEEE && fw_version
.param
!= 0xFFFF) {
1246 dev_dbg(&ts
->client
->dev
, "F/W type: Main\n");
1248 dev_err(&ts
->client
->dev
, "Wrong firmware type\n");
1255 static int mip4_execute_fw_update(struct mip4_ts
*ts
, const struct firmware
*fw
)
1257 const struct mip4_bin_tail
*fw_info
;
1258 u32 fw_start_offset
;
1263 error
= mip4_parse_firmware(ts
, fw
,
1264 &fw_start_offset
, &fw_size
, &fw_info
);
1268 if (ts
->input
->users
) {
1269 disable_irq(ts
->client
->irq
);
1271 error
= mip4_power_on(ts
);
1276 /* Update firmware */
1278 error
= mip4_flash_fw(ts
, fw
->data
, fw_size
, fw_start_offset
);
1281 } while (--retires
);
1284 dev_err(&ts
->client
->dev
,
1285 "Failed to flash firmware: %d\n", error
);
1288 if (ts
->input
->users
)
1289 enable_irq(ts
->client
->irq
);
1293 return error
? error
: 0;
1296 static ssize_t
mip4_sysfs_fw_update(struct device
*dev
,
1297 struct device_attribute
*attr
,
1298 const char *buf
, size_t count
)
1300 struct i2c_client
*client
= to_i2c_client(dev
);
1301 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1302 const struct firmware
*fw
;
1305 error
= request_firmware(&fw
, ts
->fw_name
, dev
);
1307 dev_err(&ts
->client
->dev
,
1308 "Failed to retrieve firmware %s: %d\n",
1309 ts
->fw_name
, error
);
1314 * Take input mutex to prevent racing with itself and also with
1315 * userspace opening and closing the device and also suspend/resume
1318 mutex_lock(&ts
->input
->mutex
);
1320 error
= mip4_execute_fw_update(ts
, fw
);
1322 mutex_unlock(&ts
->input
->mutex
);
1324 release_firmware(fw
);
1327 dev_err(&ts
->client
->dev
,
1328 "Firmware update failed: %d\n", error
);
1335 static DEVICE_ATTR(update_fw
, S_IWUSR
, NULL
, mip4_sysfs_fw_update
);
1337 static ssize_t
mip4_sysfs_read_fw_version(struct device
*dev
,
1338 struct device_attribute
*attr
,
1341 struct i2c_client
*client
= to_i2c_client(dev
);
1342 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1345 /* Take lock to prevent racing with firmware update */
1346 mutex_lock(&ts
->input
->mutex
);
1348 count
= snprintf(buf
, PAGE_SIZE
, "%04X %04X %04X %04X\n",
1349 ts
->fw_version
.boot
, ts
->fw_version
.core
,
1350 ts
->fw_version
.app
, ts
->fw_version
.param
);
1352 mutex_unlock(&ts
->input
->mutex
);
1357 static DEVICE_ATTR(fw_version
, S_IRUGO
, mip4_sysfs_read_fw_version
, NULL
);
1359 static ssize_t
mip4_sysfs_read_hw_version(struct device
*dev
,
1360 struct device_attribute
*attr
,
1363 struct i2c_client
*client
= to_i2c_client(dev
);
1364 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1367 /* Take lock to prevent racing with firmware update */
1368 mutex_lock(&ts
->input
->mutex
);
1371 * product_name shows the name or version of the hardware
1372 * paired with current firmware in the chip.
1374 count
= snprintf(buf
, PAGE_SIZE
, "%.*s\n",
1375 (int)sizeof(ts
->product_name
), ts
->product_name
);
1377 mutex_unlock(&ts
->input
->mutex
);
1382 static DEVICE_ATTR(hw_version
, S_IRUGO
, mip4_sysfs_read_hw_version
, NULL
);
1384 static ssize_t
mip4_sysfs_read_product_id(struct device
*dev
,
1385 struct device_attribute
*attr
,
1388 struct i2c_client
*client
= to_i2c_client(dev
);
1389 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1392 mutex_lock(&ts
->input
->mutex
);
1394 count
= snprintf(buf
, PAGE_SIZE
, "%04X\n", ts
->product_id
);
1396 mutex_unlock(&ts
->input
->mutex
);
1401 static DEVICE_ATTR(product_id
, S_IRUGO
, mip4_sysfs_read_product_id
, NULL
);
1403 static ssize_t
mip4_sysfs_read_ic_name(struct device
*dev
,
1404 struct device_attribute
*attr
,
1407 struct i2c_client
*client
= to_i2c_client(dev
);
1408 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1411 mutex_lock(&ts
->input
->mutex
);
1413 count
= snprintf(buf
, PAGE_SIZE
, "%.*s\n",
1414 (int)sizeof(ts
->ic_name
), ts
->ic_name
);
1416 mutex_unlock(&ts
->input
->mutex
);
1421 static DEVICE_ATTR(ic_name
, S_IRUGO
, mip4_sysfs_read_ic_name
, NULL
);
1423 static struct attribute
*mip4_attrs
[] = {
1424 &dev_attr_fw_version
.attr
,
1425 &dev_attr_hw_version
.attr
,
1426 &dev_attr_product_id
.attr
,
1427 &dev_attr_ic_name
.attr
,
1428 &dev_attr_update_fw
.attr
,
1432 static const struct attribute_group mip4_attr_group
= {
1433 .attrs
= mip4_attrs
,
1436 static void mip4_sysfs_remove(void *_data
)
1438 struct mip4_ts
*ts
= _data
;
1440 sysfs_remove_group(&ts
->client
->dev
.kobj
, &mip4_attr_group
);
1443 static int mip4_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
1446 struct input_dev
*input
;
1449 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
)) {
1450 dev_err(&client
->dev
, "Not supported I2C adapter\n");
1454 ts
= devm_kzalloc(&client
->dev
, sizeof(*ts
), GFP_KERNEL
);
1458 input
= devm_input_allocate_device(&client
->dev
);
1462 ts
->client
= client
;
1465 snprintf(ts
->phys
, sizeof(ts
->phys
),
1466 "%s/input0", dev_name(&client
->dev
));
1468 ts
->gpio_ce
= devm_gpiod_get_optional(&client
->dev
,
1469 "ce", GPIOD_OUT_LOW
);
1470 if (IS_ERR(ts
->gpio_ce
)) {
1471 error
= PTR_ERR(ts
->gpio_ce
);
1472 if (error
!= EPROBE_DEFER
)
1473 dev_err(&client
->dev
,
1474 "Failed to get gpio: %d\n", error
);
1478 error
= mip4_power_on(ts
);
1481 error
= mip4_query_device(ts
);
1486 input
->name
= "MELFAS MIP4 Touchscreen";
1487 input
->phys
= ts
->phys
;
1489 input
->id
.bustype
= BUS_I2C
;
1490 input
->id
.vendor
= 0x13c5;
1491 input
->id
.product
= ts
->product_id
;
1493 input
->open
= mip4_input_open
;
1494 input
->close
= mip4_input_close
;
1496 input_set_drvdata(input
, ts
);
1498 input
->keycode
= ts
->key_code
;
1499 input
->keycodesize
= sizeof(*ts
->key_code
);
1500 input
->keycodemax
= ts
->key_num
;
1502 input_set_abs_params(input
, ABS_MT_POSITION_X
, 0, ts
->max_x
, 0, 0);
1503 input_set_abs_params(input
, ABS_MT_POSITION_Y
, 0, ts
->max_y
, 0, 0);
1504 input_set_abs_params(input
, ABS_MT_PRESSURE
,
1505 MIP4_PRESSURE_MIN
, MIP4_PRESSURE_MAX
, 0, 0);
1506 input_set_abs_params(input
, ABS_MT_TOUCH_MAJOR
,
1507 MIP4_TOUCH_MAJOR_MIN
, MIP4_TOUCH_MAJOR_MAX
, 0, 0);
1508 input_set_abs_params(input
, ABS_MT_TOUCH_MINOR
,
1509 MIP4_TOUCH_MINOR_MIN
, MIP4_TOUCH_MINOR_MAX
, 0, 0);
1510 input_abs_set_res(ts
->input
, ABS_MT_POSITION_X
, ts
->ppm_x
);
1511 input_abs_set_res(ts
->input
, ABS_MT_POSITION_Y
, ts
->ppm_y
);
1513 error
= input_mt_init_slots(input
, MIP4_MAX_FINGERS
, INPUT_MT_DIRECT
);
1517 i2c_set_clientdata(client
, ts
);
1519 error
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
1520 NULL
, mip4_interrupt
,
1521 IRQF_ONESHOT
, MIP4_DEVICE_NAME
, ts
);
1523 dev_err(&client
->dev
,
1524 "Failed to request interrupt %d: %d\n",
1525 client
->irq
, error
);
1529 disable_irq(client
->irq
);
1531 error
= input_register_device(input
);
1533 dev_err(&client
->dev
,
1534 "Failed to register input device: %d\n", error
);
1538 error
= sysfs_create_group(&client
->dev
.kobj
, &mip4_attr_group
);
1540 dev_err(&client
->dev
,
1541 "Failed to create sysfs attribute group: %d\n", error
);
1545 error
= devm_add_action(&client
->dev
, mip4_sysfs_remove
, ts
);
1547 mip4_sysfs_remove(ts
);
1548 dev_err(&client
->dev
,
1549 "Failed to install sysfs remoce action: %d\n", error
);
1556 static int __maybe_unused
mip4_suspend(struct device
*dev
)
1558 struct i2c_client
*client
= to_i2c_client(dev
);
1559 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1560 struct input_dev
*input
= ts
->input
;
1562 mutex_lock(&input
->mutex
);
1564 if (device_may_wakeup(dev
))
1565 ts
->wake_irq_enabled
= enable_irq_wake(client
->irq
) == 0;
1566 else if (input
->users
)
1569 mutex_unlock(&input
->mutex
);
1574 static int __maybe_unused
mip4_resume(struct device
*dev
)
1576 struct i2c_client
*client
= to_i2c_client(dev
);
1577 struct mip4_ts
*ts
= i2c_get_clientdata(client
);
1578 struct input_dev
*input
= ts
->input
;
1580 mutex_lock(&input
->mutex
);
1582 if (ts
->wake_irq_enabled
)
1583 disable_irq_wake(client
->irq
);
1584 else if (input
->users
)
1587 mutex_unlock(&input
->mutex
);
1592 static SIMPLE_DEV_PM_OPS(mip4_pm_ops
, mip4_suspend
, mip4_resume
);
1595 static const struct of_device_id mip4_of_match
[] = {
1596 { .compatible
= "melfas,"MIP4_DEVICE_NAME
, },
1599 MODULE_DEVICE_TABLE(of
, mip4_of_match
);
1603 static const struct acpi_device_id mip4_acpi_match
[] = {
1607 MODULE_DEVICE_TABLE(acpi
, mip4_acpi_match
);
1610 static const struct i2c_device_id mip4_i2c_ids
[] = {
1611 { MIP4_DEVICE_NAME
, 0 },
1614 MODULE_DEVICE_TABLE(i2c
, mip4_i2c_ids
);
1616 static struct i2c_driver mip4_driver
= {
1617 .id_table
= mip4_i2c_ids
,
1618 .probe
= mip4_probe
,
1620 .name
= MIP4_DEVICE_NAME
,
1621 .of_match_table
= of_match_ptr(mip4_of_match
),
1622 .acpi_match_table
= ACPI_PTR(mip4_acpi_match
),
1626 module_i2c_driver(mip4_driver
);
1628 MODULE_DESCRIPTION("MELFAS MIP4 Touchscreen");
1629 MODULE_VERSION("2016.10.31");
1630 MODULE_AUTHOR("Sangwon Jee <jeesw@melfas.com>");
1631 MODULE_LICENSE("GPL");