1 // SPDX-License-Identifier: GPL-2.0-only
3 * ROHM BU21023/24 Dual touch support resistive touch screen driver
4 * Copyright (C) 2012 ROHM CO.,LTD.
6 #include <linux/delay.h>
7 #include <linux/firmware.h>
9 #include <linux/input.h>
10 #include <linux/input/mt.h>
11 #include <linux/interrupt.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
15 #define BU21023_NAME "bu21023_ts"
16 #define BU21023_FIRMWARE_NAME "bu21023.bin"
18 #define MAX_CONTACTS 2
23 #define FIRMWARE_BLOCK_SIZE 32U
24 #define FIRMWARE_RETRY_MAX 4
26 #define SAMPLING_DELAY 12 /* msec */
28 #define CALIBRATION_RETRY_MAX 6
30 #define ROHM_TS_ABS_X_MIN 40
31 #define ROHM_TS_ABS_X_MAX 990
32 #define ROHM_TS_ABS_Y_MIN 160
33 #define ROHM_TS_ABS_Y_MAX 920
34 #define ROHM_TS_DISPLACEMENT_MAX 0 /* zero for infinite */
37 * BU21023GUL/BU21023MUV/BU21024FV-M registers map
39 #define VADOUT_YP_H 0x00
40 #define VADOUT_YP_L 0x01
41 #define VADOUT_XP_H 0x02
42 #define VADOUT_XP_L 0x03
43 #define VADOUT_YN_H 0x04
44 #define VADOUT_YN_L 0x05
45 #define VADOUT_XN_H 0x06
46 #define VADOUT_XN_L 0x07
57 #define MLT_PRM_MONI_X 0x10
58 #define MLT_PRM_MONI_Y 0x11
60 #define DEBUG_MONI_1 0x12
61 #define DEBUG_MONI_2 0x13
63 #define VADOUT_ZX_H 0x14
64 #define VADOUT_ZX_L 0x15
65 #define VADOUT_ZY_H 0x16
66 #define VADOUT_ZY_L 0x17
68 #define Z_PARAM_H 0x18
69 #define Z_PARAM_L 0x19
72 * Value for VADOUT_*_L
74 #define VADOUT_L_MASK 0x01
79 #define PRM_L_MASK 0x01
93 #define POS_L_MASK 0x01
96 #define TOUCH_DETECT 0x01
98 #define TOUCH_GESTURE 0x29
99 #define SINGLE_TOUCH 0x01
100 #define DUAL_TOUCH 0x03
101 #define TOUCH_MASK 0x03
102 #define CALIBRATION_REQUEST 0x04
103 #define CALIBRATION_STATUS 0x08
104 #define CALIBRATION_MASK 0x0c
105 #define GESTURE_SPREAD 0x10
106 #define GESTURE_PINCH 0x20
107 #define GESTURE_ROTATE_R 0x40
108 #define GESTURE_ROTATE_L 0x80
110 #define INT_STATUS 0x2a
111 #define INT_MASK 0x3d
112 #define INT_CLEAR 0x3e
117 #define COORD_UPDATE 0x01
118 #define CALIBRATION_DONE 0x02
119 #define SLEEP_IN 0x04
120 #define SLEEP_OUT 0x08
121 #define PROGRAM_LOAD_DONE 0x10
125 #define ERR_STATUS 0x2b
126 #define ERR_MASK 0x3f
131 #define ADC_TIMEOUT 0x01
132 #define CPU_TIMEOUT 0x02
133 #define CALIBRATION_ERR 0x04
134 #define PROGRAM_LOAD_ERR 0x10
136 #define COMMON_SETUP1 0x30
137 #define PROGRAM_LOAD_HOST 0x02
138 #define PROGRAM_LOAD_EEPROM 0x03
139 #define CENSOR_4PORT 0x04
140 #define CENSOR_8PORT 0x00 /* Not supported by BU21023 */
141 #define CALIBRATION_TYPE_DEFAULT 0x08
142 #define CALIBRATION_TYPE_SPECIAL 0x00
143 #define INT_ACTIVE_HIGH 0x10
144 #define INT_ACTIVE_LOW 0x00
145 #define AUTO_CALIBRATION 0x40
146 #define MANUAL_CALIBRATION 0x00
147 #define COMMON_SETUP1_DEFAULT 0x4e
149 #define COMMON_SETUP2 0x31
150 #define MAF_NONE 0x00
151 #define MAF_1SAMPLE 0x01
152 #define MAF_3SAMPLES 0x02
153 #define MAF_5SAMPLES 0x03
158 #define COMMON_SETUP3 0x32
159 #define EN_SLEEP 0x01
160 #define EN_MULTI 0x02
161 #define EN_GESTURE 0x04
162 #define EN_INTVL 0x08
163 #define SEL_STEP 0x10
164 #define SEL_MULTI 0x20
165 #define SEL_TBL_DEFAULT 0x40
167 #define INTERVAL_TIME 0x33
168 #define INTERVAL_TIME_DEFAULT 0x10
171 #define STEP_X_DEFAULT 0x41
174 #define STEP_Y_DEFAULT 0x8d
176 #define OFFSET_X 0x38
177 #define OFFSET_X_DEFAULT 0x0c
179 #define OFFSET_Y 0x39
180 #define OFFSET_Y_DEFAULT 0x0c
182 #define THRESHOLD_TOUCH 0x3a
183 #define THRESHOLD_TOUCH_DEFAULT 0xa0
185 #define THRESHOLD_GESTURE 0x3b
186 #define THRESHOLD_GESTURE_DEFAULT 0x17
189 #define ANALOG_POWER_ON 0x01
190 #define ANALOG_POWER_OFF 0x00
191 #define CPU_POWER_ON 0x02
192 #define CPU_POWER_OFF 0x00
194 #define FORCE_CALIBRATION 0x42
195 #define FORCE_CALIBRATION_ON 0x01
196 #define FORCE_CALIBRATION_OFF 0x00
198 #define CPU_FREQ 0x50 /* 10 / (reg + 1) MHz */
199 #define CPU_FREQ_10MHZ 0x00
200 #define CPU_FREQ_5MHZ 0x01
201 #define CPU_FREQ_1MHZ 0x09
203 #define EEPROM_ADDR 0x51
205 #define CALIBRATION_ADJUST 0x52
206 #define CALIBRATION_ADJUST_DEFAULT 0x00
208 #define THRESHOLD_SLEEP_IN 0x53
211 #define EVR_XY_DEFAULT 0x10
213 #define PRM_SWOFF_TIME 0x57
214 #define PRM_SWOFF_TIME_DEFAULT 0x04
216 #define PROGRAM_VERSION 0x5f
218 #define ADC_CTRL 0x60
219 #define ADC_DIV_MASK 0x1f /* The minimum value is 4 */
220 #define ADC_DIV_DEFAULT 0x08
222 #define ADC_WAIT 0x61
223 #define ADC_WAIT_DEFAULT 0x0a
226 #define SWCONT_DEFAULT 0x0f
229 #define EVR_X_DEFAULT 0x86
232 #define EVR_Y_DEFAULT 0x64
235 #define DUALTOUCH_STABILIZE_ON 0x01
236 #define DUALTOUCH_STABILIZE_OFF 0x00
237 #define DUALTOUCH_REG_ON 0x20
238 #define DUALTOUCH_REG_OFF 0x00
240 #define CALIBRATION_REG1 0x68
241 #define CALIBRATION_REG1_DEFAULT 0xd9
243 #define CALIBRATION_REG2 0x69
244 #define CALIBRATION_REG2_DEFAULT 0x36
246 #define CALIBRATION_REG3 0x6a
247 #define CALIBRATION_REG3_DEFAULT 0x32
249 #define EX_ADDR_H 0x70
250 #define EX_ADDR_L 0x71
253 #define EX_CHK_SUM1 0x74
254 #define EX_CHK_SUM2 0x75
255 #define EX_CHK_SUM3 0x76
257 struct rohm_ts_data
{
258 struct i2c_client
*client
;
259 struct input_dev
*input
;
263 unsigned int contact_count
[MAX_CONTACTS
+ 1];
270 * rohm_i2c_burst_read - execute combined I2C message for ROHM BU21023/24
271 * @client: Handle to ROHM BU21023/24
272 * @start: Where to start read address from ROHM BU21023/24
273 * @buf: Where to store read data from ROHM BU21023/24
274 * @len: How many bytes to read
276 * Returns negative errno, else zero on success.
279 * In BU21023/24 burst read, stop condition is needed after "address write".
280 * Therefore, transmission is performed in 2 steps.
282 static int rohm_i2c_burst_read(struct i2c_client
*client
, u8 start
, void *buf
,
285 struct i2c_adapter
*adap
= client
->adapter
;
286 struct i2c_msg msg
[2];
289 msg
[0].addr
= client
->addr
;
294 msg
[1].addr
= client
->addr
;
295 msg
[1].flags
= I2C_M_RD
;
299 i2c_lock_bus(adap
, I2C_LOCK_SEGMENT
);
301 for (i
= 0; i
< 2; i
++) {
302 if (__i2c_transfer(adap
, &msg
[i
], 1) < 0) {
308 i2c_unlock_bus(adap
, I2C_LOCK_SEGMENT
);
313 static int rohm_ts_manual_calibration(struct rohm_ts_data
*ts
)
315 struct i2c_client
*client
= ts
->client
;
316 struct device
*dev
= &client
->dev
;
317 u8 buf
[33]; /* for PRM1_X_H(0x08)-TOUCH(0x28) */
320 bool success
= false;
321 bool first_time
= true;
322 bool calibration_done
;
325 s32 reg1_orig
, reg2_orig
, reg3_orig
;
328 int calib_x
= 0, calib_y
= 0;
335 reg1_orig
= i2c_smbus_read_byte_data(client
, CALIBRATION_REG1
);
339 reg2_orig
= i2c_smbus_read_byte_data(client
, CALIBRATION_REG2
);
343 reg3_orig
= i2c_smbus_read_byte_data(client
, CALIBRATION_REG3
);
347 error
= i2c_smbus_write_byte_data(client
, INT_MASK
,
348 COORD_UPDATE
| SLEEP_IN
| SLEEP_OUT
|
353 error
= i2c_smbus_write_byte_data(client
, TEST1
,
354 DUALTOUCH_STABILIZE_ON
);
358 for (retry
= 0; retry
< CALIBRATION_RETRY_MAX
; retry
++) {
359 /* wait 2 sampling for update */
360 mdelay(2 * SAMPLING_DELAY
);
362 #define READ_CALIB_BUF(reg) buf[((reg) - PRM1_X_H)]
364 error
= rohm_i2c_burst_read(client
, PRM1_X_H
, buf
, sizeof(buf
));
368 if (READ_CALIB_BUF(TOUCH
) & TOUCH_DETECT
)
372 /* generate calibration parameter */
373 calib_x
= ((int)READ_CALIB_BUF(PRM1_X_H
) << 2 |
374 READ_CALIB_BUF(PRM1_X_L
)) - AXIS_OFFSET
;
375 calib_y
= ((int)READ_CALIB_BUF(PRM1_Y_H
) << 2 |
376 READ_CALIB_BUF(PRM1_Y_L
)) - AXIS_OFFSET
;
378 error
= i2c_smbus_write_byte_data(client
, TEST1
,
379 DUALTOUCH_STABILIZE_ON
| DUALTOUCH_REG_ON
);
385 /* generate adjustment parameter */
386 err_x
= (int)READ_CALIB_BUF(PRM1_X_H
) << 2 |
387 READ_CALIB_BUF(PRM1_X_L
);
388 err_y
= (int)READ_CALIB_BUF(PRM1_Y_H
) << 2 |
389 READ_CALIB_BUF(PRM1_Y_L
);
393 calib_x
-= AXIS_ADJUST
;
394 else if (err_x
>= 60)
395 calib_x
+= AXIS_ADJUST
;
399 calib_y
-= AXIS_ADJUST
;
400 else if (err_y
>= 60)
401 calib_y
+= AXIS_ADJUST
;
404 /* generate calibration setting value */
405 reg_x
= calib_x
+ ((calib_x
& 0x200) << 1);
406 reg_y
= calib_y
+ ((calib_y
& 0x200) << 1);
408 /* convert for register format */
410 reg2
= (reg_y
& 0x7) << 4 | (reg_x
& 0x7);
413 error
= i2c_smbus_write_byte_data(client
,
414 CALIBRATION_REG1
, reg1
);
418 error
= i2c_smbus_write_byte_data(client
,
419 CALIBRATION_REG2
, reg2
);
423 error
= i2c_smbus_write_byte_data(client
,
424 CALIBRATION_REG3
, reg3
);
429 * force calibration sequcence
431 error
= i2c_smbus_write_byte_data(client
, FORCE_CALIBRATION
,
432 FORCE_CALIBRATION_OFF
);
436 error
= i2c_smbus_write_byte_data(client
, FORCE_CALIBRATION
,
437 FORCE_CALIBRATION_ON
);
441 /* clear all interrupts */
442 error
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
447 * Wait for the status change of calibration, max 10 sampling
449 calibration_done
= false;
451 for (i
= 0; i
< 10; i
++) {
452 mdelay(SAMPLING_DELAY
);
454 val
= i2c_smbus_read_byte_data(client
, TOUCH_GESTURE
);
455 if (!(val
& CALIBRATION_MASK
)) {
456 calibration_done
= true;
458 } else if (val
< 0) {
464 if (calibration_done
) {
465 val
= i2c_smbus_read_byte_data(client
, INT_STATUS
);
466 if (val
== CALIBRATION_DONE
) {
469 } else if (val
< 0) {
474 dev_warn(dev
, "calibration timeout\n");
479 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG1
,
484 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG2
,
489 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG3
,
494 /* calibration data enable */
495 error
= i2c_smbus_write_byte_data(client
, TEST1
,
496 DUALTOUCH_STABILIZE_ON
|
501 /* wait 10 sampling */
502 mdelay(10 * SAMPLING_DELAY
);
508 error2
= i2c_smbus_write_byte_data(client
, INT_MASK
, INT_ALL
);
510 /* Clear all interrupts */
511 error2
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
513 return error
? error
: error2
;
516 static const unsigned int untouch_threshold
[3] = { 0, 1, 5 };
517 static const unsigned int single_touch_threshold
[3] = { 0, 0, 4 };
518 static const unsigned int dual_touch_threshold
[3] = { 10, 8, 0 };
520 static irqreturn_t
rohm_ts_soft_irq(int irq
, void *dev_id
)
522 struct rohm_ts_data
*ts
= dev_id
;
523 struct i2c_client
*client
= ts
->client
;
524 struct input_dev
*input_dev
= ts
->input
;
525 struct device
*dev
= &client
->dev
;
527 u8 buf
[10]; /* for POS_X1_H(0x20)-TOUCH_GESTURE(0x29) */
529 struct input_mt_pos pos
[MAX_CONTACTS
];
530 int slots
[MAX_CONTACTS
];
532 unsigned int threshold
;
533 int finger_count
= -1;
534 int prev_finger_count
= ts
->finger_count
;
539 error
= i2c_smbus_write_byte_data(client
, INT_MASK
, INT_ALL
);
543 /* Clear all interrupts */
544 error
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
548 #define READ_POS_BUF(reg) buf[((reg) - POS_X1_H)]
550 error
= rohm_i2c_burst_read(client
, POS_X1_H
, buf
, sizeof(buf
));
554 touch_flags
= READ_POS_BUF(TOUCH_GESTURE
) & TOUCH_MASK
;
556 /* generate coordinates */
557 pos
[0].x
= ((s16
)READ_POS_BUF(POS_X1_H
) << 2) |
558 READ_POS_BUF(POS_X1_L
);
559 pos
[0].y
= ((s16
)READ_POS_BUF(POS_Y1_H
) << 2) |
560 READ_POS_BUF(POS_Y1_L
);
561 pos
[1].x
= ((s16
)READ_POS_BUF(POS_X2_H
) << 2) |
562 READ_POS_BUF(POS_X2_L
);
563 pos
[1].y
= ((s16
)READ_POS_BUF(POS_Y2_H
) << 2) |
564 READ_POS_BUF(POS_Y2_L
);
567 switch (touch_flags
) {
569 threshold
= untouch_threshold
[prev_finger_count
];
570 if (++ts
->contact_count
[0] >= threshold
)
575 threshold
= single_touch_threshold
[prev_finger_count
];
576 if (++ts
->contact_count
[1] >= threshold
)
579 if (finger_count
== 1) {
580 if (pos
[1].x
!= 0 && pos
[1].y
!= 0) {
590 threshold
= dual_touch_threshold
[prev_finger_count
];
591 if (++ts
->contact_count
[2] >= threshold
)
597 "Three or more touches are not supported\n");
601 if (finger_count
>= 0) {
602 if (prev_finger_count
!= finger_count
) {
603 count
= ts
->contact_count
[finger_count
];
604 memset(ts
->contact_count
, 0, sizeof(ts
->contact_count
));
605 ts
->contact_count
[finger_count
] = count
;
608 input_mt_assign_slots(input_dev
, slots
, pos
,
609 finger_count
, ROHM_TS_DISPLACEMENT_MAX
);
611 for (i
= 0; i
< finger_count
; i
++) {
612 input_mt_slot(input_dev
, slots
[i
]);
613 input_mt_report_slot_state(input_dev
,
614 MT_TOOL_FINGER
, true);
615 input_report_abs(input_dev
,
616 ABS_MT_POSITION_X
, pos
[i
].x
);
617 input_report_abs(input_dev
,
618 ABS_MT_POSITION_Y
, pos
[i
].y
);
621 input_mt_sync_frame(input_dev
);
622 input_mt_report_pointer_emulation(input_dev
, true);
623 input_sync(input_dev
);
625 ts
->finger_count
= finger_count
;
628 if (READ_POS_BUF(TOUCH_GESTURE
) & CALIBRATION_REQUEST
) {
629 error
= rohm_ts_manual_calibration(ts
);
631 dev_warn(dev
, "manual calibration failed: %d\n",
635 i2c_smbus_write_byte_data(client
, INT_MASK
,
636 CALIBRATION_DONE
| SLEEP_OUT
| SLEEP_IN
|
642 static int rohm_ts_load_firmware(struct i2c_client
*client
,
643 const char *firmware_name
)
645 struct device
*dev
= &client
->dev
;
647 unsigned int offset
, len
, xfer_len
;
648 unsigned int retry
= 0;
651 const struct firmware
*fw
__free(firmware
) = NULL
;
652 error
= request_firmware(&fw
, firmware_name
, dev
);
654 dev_err(dev
, "unable to retrieve firmware %s: %d\n",
655 firmware_name
, error
);
659 error
= i2c_smbus_write_byte_data(client
, INT_MASK
,
660 COORD_UPDATE
| CALIBRATION_DONE
|
661 SLEEP_IN
| SLEEP_OUT
);
667 dev_warn(dev
, "retrying firmware load\n");
669 /* settings for retry */
670 error
= i2c_smbus_write_byte_data(client
, EX_WDAT
, 0);
675 error
= i2c_smbus_write_byte_data(client
, EX_ADDR_H
, 0);
679 error
= i2c_smbus_write_byte_data(client
, EX_ADDR_L
, 0);
683 error
= i2c_smbus_write_byte_data(client
, COMMON_SETUP1
,
684 COMMON_SETUP1_DEFAULT
);
688 /* firmware load to the device */
693 xfer_len
= min(FIRMWARE_BLOCK_SIZE
, len
);
695 error
= i2c_smbus_write_i2c_block_data(client
, EX_WDAT
,
696 xfer_len
, &fw
->data
[offset
]);
704 /* check firmware load result */
705 status
= i2c_smbus_read_byte_data(client
, INT_STATUS
);
711 /* clear all interrupts */
712 error
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
716 if (status
== PROGRAM_LOAD_DONE
)
720 } while (++retry
<= FIRMWARE_RETRY_MAX
);
723 error2
= i2c_smbus_write_byte_data(client
, INT_MASK
, INT_ALL
);
725 return error
? error
: error2
;
728 static int rohm_ts_update_setting(struct rohm_ts_data
*ts
,
729 unsigned int setting_bit
, bool on
)
733 scoped_cond_guard(mutex_intr
, return -EINTR
, &ts
->input
->mutex
) {
735 ts
->setup2
|= setting_bit
;
737 ts
->setup2
&= ~setting_bit
;
739 if (ts
->initialized
) {
740 error
= i2c_smbus_write_byte_data(ts
->client
,
751 static ssize_t
swap_xy_show(struct device
*dev
, struct device_attribute
*attr
,
754 struct i2c_client
*client
= to_i2c_client(dev
);
755 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
757 return sysfs_emit(buf
, "%d\n", !!(ts
->setup2
& SWAP_XY
));
760 static ssize_t
swap_xy_store(struct device
*dev
, struct device_attribute
*attr
,
761 const char *buf
, size_t count
)
763 struct i2c_client
*client
= to_i2c_client(dev
);
764 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
768 error
= kstrtouint(buf
, 0, &val
);
772 error
= rohm_ts_update_setting(ts
, SWAP_XY
, val
);
773 return error
?: count
;
776 static ssize_t
inv_x_show(struct device
*dev
, struct device_attribute
*attr
,
779 struct i2c_client
*client
= to_i2c_client(dev
);
780 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
782 return sysfs_emit(buf
, "%d\n", !!(ts
->setup2
& INV_X
));
785 static ssize_t
inv_x_store(struct device
*dev
, struct device_attribute
*attr
,
786 const char *buf
, size_t count
)
788 struct i2c_client
*client
= to_i2c_client(dev
);
789 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
793 error
= kstrtouint(buf
, 0, &val
);
797 error
= rohm_ts_update_setting(ts
, INV_X
, val
);
798 return error
?: count
;
801 static ssize_t
inv_y_show(struct device
*dev
, struct device_attribute
*attr
,
804 struct i2c_client
*client
= to_i2c_client(dev
);
805 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
807 return sysfs_emit(buf
, "%d\n", !!(ts
->setup2
& INV_Y
));
810 static ssize_t
inv_y_store(struct device
*dev
, struct device_attribute
*attr
,
811 const char *buf
, size_t count
)
813 struct i2c_client
*client
= to_i2c_client(dev
);
814 struct rohm_ts_data
*ts
= i2c_get_clientdata(client
);
818 error
= kstrtouint(buf
, 0, &val
);
822 error
= rohm_ts_update_setting(ts
, INV_Y
, val
);
823 return error
?: count
;
826 static DEVICE_ATTR_RW(swap_xy
);
827 static DEVICE_ATTR_RW(inv_x
);
828 static DEVICE_ATTR_RW(inv_y
);
830 static struct attribute
*rohm_ts_attrs
[] = {
831 &dev_attr_swap_xy
.attr
,
832 &dev_attr_inv_x
.attr
,
833 &dev_attr_inv_y
.attr
,
836 ATTRIBUTE_GROUPS(rohm_ts
);
838 static int rohm_ts_device_init(struct i2c_client
*client
, u8 setup2
)
840 struct device
*dev
= &client
->dev
;
843 guard(disable_irq
)(&client
->irq
);
846 * Wait 200usec for reset
850 /* Release analog reset */
851 error
= i2c_smbus_write_byte_data(client
, SYSTEM
,
852 ANALOG_POWER_ON
| CPU_POWER_OFF
);
856 /* Waiting for the analog warm-up, max. 200usec */
859 /* clear all interrupts */
860 error
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
864 error
= i2c_smbus_write_byte_data(client
, EX_WDAT
, 0);
868 error
= i2c_smbus_write_byte_data(client
, COMMON_SETUP1
, 0);
872 error
= i2c_smbus_write_byte_data(client
, COMMON_SETUP2
, setup2
);
876 error
= i2c_smbus_write_byte_data(client
, COMMON_SETUP3
,
877 SEL_TBL_DEFAULT
| EN_MULTI
);
881 error
= i2c_smbus_write_byte_data(client
, THRESHOLD_GESTURE
,
882 THRESHOLD_GESTURE_DEFAULT
);
886 error
= i2c_smbus_write_byte_data(client
, INTERVAL_TIME
,
887 INTERVAL_TIME_DEFAULT
);
891 error
= i2c_smbus_write_byte_data(client
, CPU_FREQ
, CPU_FREQ_10MHZ
);
895 error
= i2c_smbus_write_byte_data(client
, PRM_SWOFF_TIME
,
896 PRM_SWOFF_TIME_DEFAULT
);
900 error
= i2c_smbus_write_byte_data(client
, ADC_CTRL
, ADC_DIV_DEFAULT
);
904 error
= i2c_smbus_write_byte_data(client
, ADC_WAIT
, ADC_WAIT_DEFAULT
);
909 * Panel setup, these values change with the panel.
911 error
= i2c_smbus_write_byte_data(client
, STEP_X
, STEP_X_DEFAULT
);
915 error
= i2c_smbus_write_byte_data(client
, STEP_Y
, STEP_Y_DEFAULT
);
919 error
= i2c_smbus_write_byte_data(client
, OFFSET_X
, OFFSET_X_DEFAULT
);
923 error
= i2c_smbus_write_byte_data(client
, OFFSET_Y
, OFFSET_Y_DEFAULT
);
927 error
= i2c_smbus_write_byte_data(client
, THRESHOLD_TOUCH
,
928 THRESHOLD_TOUCH_DEFAULT
);
932 error
= i2c_smbus_write_byte_data(client
, EVR_XY
, EVR_XY_DEFAULT
);
936 error
= i2c_smbus_write_byte_data(client
, EVR_X
, EVR_X_DEFAULT
);
940 error
= i2c_smbus_write_byte_data(client
, EVR_Y
, EVR_Y_DEFAULT
);
944 /* Fixed value settings */
945 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_ADJUST
,
946 CALIBRATION_ADJUST_DEFAULT
);
950 error
= i2c_smbus_write_byte_data(client
, SWCONT
, SWCONT_DEFAULT
);
954 error
= i2c_smbus_write_byte_data(client
, TEST1
,
955 DUALTOUCH_STABILIZE_ON
|
960 error
= rohm_ts_load_firmware(client
, BU21023_FIRMWARE_NAME
);
962 dev_err(dev
, "failed to load firmware: %d\n", error
);
967 * Manual calibration results are not changed in same environment.
968 * If the force calibration is performed,
969 * the controller will not require calibration request interrupt
970 * when the typical values are set to the calibration registers.
972 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG1
,
973 CALIBRATION_REG1_DEFAULT
);
977 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG2
,
978 CALIBRATION_REG2_DEFAULT
);
982 error
= i2c_smbus_write_byte_data(client
, CALIBRATION_REG3
,
983 CALIBRATION_REG3_DEFAULT
);
987 error
= i2c_smbus_write_byte_data(client
, FORCE_CALIBRATION
,
988 FORCE_CALIBRATION_OFF
);
992 error
= i2c_smbus_write_byte_data(client
, FORCE_CALIBRATION
,
993 FORCE_CALIBRATION_ON
);
997 /* Clear all interrupts */
998 error
= i2c_smbus_write_byte_data(client
, INT_CLEAR
, 0xff);
1002 /* Enable coordinates update interrupt */
1003 error
= i2c_smbus_write_byte_data(client
, INT_MASK
,
1004 CALIBRATION_DONE
| SLEEP_OUT
|
1005 SLEEP_IN
| PROGRAM_LOAD_DONE
);
1009 error
= i2c_smbus_write_byte_data(client
, ERR_MASK
,
1010 PROGRAM_LOAD_ERR
| CPU_TIMEOUT
|
1015 /* controller CPU power on */
1016 error
= i2c_smbus_write_byte_data(client
, SYSTEM
,
1017 ANALOG_POWER_ON
| CPU_POWER_ON
);
1024 static int rohm_ts_power_off(struct i2c_client
*client
)
1028 error
= i2c_smbus_write_byte_data(client
, SYSTEM
,
1029 ANALOG_POWER_ON
| CPU_POWER_OFF
);
1031 dev_err(&client
->dev
,
1032 "failed to power off device CPU: %d\n", error
);
1036 error
= i2c_smbus_write_byte_data(client
, SYSTEM
,
1037 ANALOG_POWER_OFF
| CPU_POWER_OFF
);
1039 dev_err(&client
->dev
,
1040 "failed to power off the device: %d\n", error
);
1045 static int rohm_ts_open(struct input_dev
*input_dev
)
1047 struct rohm_ts_data
*ts
= input_get_drvdata(input_dev
);
1048 struct i2c_client
*client
= ts
->client
;
1051 if (!ts
->initialized
) {
1052 error
= rohm_ts_device_init(client
, ts
->setup2
);
1054 dev_err(&client
->dev
,
1055 "device initialization failed: %d\n", error
);
1059 ts
->initialized
= true;
1065 static void rohm_ts_close(struct input_dev
*input_dev
)
1067 struct rohm_ts_data
*ts
= input_get_drvdata(input_dev
);
1069 rohm_ts_power_off(ts
->client
);
1071 ts
->initialized
= false;
1074 static int rohm_bu21023_i2c_probe(struct i2c_client
*client
)
1076 struct device
*dev
= &client
->dev
;
1077 struct rohm_ts_data
*ts
;
1078 struct input_dev
*input
;
1082 dev_err(dev
, "IRQ is not assigned\n");
1086 if (!client
->adapter
->algo
->master_xfer
) {
1087 dev_err(dev
, "I2C level transfers not supported\n");
1091 /* Turn off CPU just in case */
1092 error
= rohm_ts_power_off(client
);
1096 ts
= devm_kzalloc(dev
, sizeof(struct rohm_ts_data
), GFP_KERNEL
);
1100 ts
->client
= client
;
1101 ts
->setup2
= MAF_1SAMPLE
;
1102 i2c_set_clientdata(client
, ts
);
1104 input
= devm_input_allocate_device(dev
);
1108 input
->name
= BU21023_NAME
;
1109 input
->id
.bustype
= BUS_I2C
;
1110 input
->open
= rohm_ts_open
;
1111 input
->close
= rohm_ts_close
;
1114 input_set_drvdata(input
, ts
);
1116 input_set_abs_params(input
, ABS_MT_POSITION_X
,
1117 ROHM_TS_ABS_X_MIN
, ROHM_TS_ABS_X_MAX
, 0, 0);
1118 input_set_abs_params(input
, ABS_MT_POSITION_Y
,
1119 ROHM_TS_ABS_Y_MIN
, ROHM_TS_ABS_Y_MAX
, 0, 0);
1121 error
= input_mt_init_slots(input
, MAX_CONTACTS
,
1122 INPUT_MT_DIRECT
| INPUT_MT_TRACK
|
1123 INPUT_MT_DROP_UNUSED
);
1125 dev_err(dev
, "failed to multi touch slots initialization\n");
1129 error
= devm_request_threaded_irq(dev
, client
->irq
,
1130 NULL
, rohm_ts_soft_irq
,
1131 IRQF_ONESHOT
, client
->name
, ts
);
1133 dev_err(dev
, "failed to request IRQ: %d\n", error
);
1137 error
= input_register_device(input
);
1139 dev_err(dev
, "failed to register input device: %d\n", error
);
1146 static const struct i2c_device_id rohm_bu21023_i2c_id
[] = {
1150 MODULE_DEVICE_TABLE(i2c
, rohm_bu21023_i2c_id
);
1152 static struct i2c_driver rohm_bu21023_i2c_driver
= {
1154 .name
= BU21023_NAME
,
1155 .dev_groups
= rohm_ts_groups
,
1157 .probe
= rohm_bu21023_i2c_probe
,
1158 .id_table
= rohm_bu21023_i2c_id
,
1160 module_i2c_driver(rohm_bu21023_i2c_driver
);
1162 MODULE_DESCRIPTION("ROHM BU21023/24 Touchscreen driver");
1163 MODULE_LICENSE("GPL v2");
1164 MODULE_AUTHOR("ROHM Co., Ltd.");