29 #include <linux/module.h>
31 #include <linux/input.h>
35 #include <linux/slab.h>
42 #define PMIC_REG_ID1 0x00
45 #define PMIC_REG_INT 0x04
46 #define PMIC_REG_MINT 0x05
49 #define PMIC_REG_ADCINT 0x5F
50 #define PMIC_REG_MADCINT 0x60
53 #define PMIC_REG_ADCCNTL1 0x61
56 #define PMICADDR0 0xA4
57 #define END_OF_CHANNEL 0x1F
60 #define PMIC_REG_ADCSNS0H 0x64
63 #define MRST_TS_CHAN10 0xA
64 #define MRST_TS_CHAN11 0xB
65 #define MRST_TS_CHAN12 0xC
66 #define MRST_TS_CHAN13 0xD
69 #define MRST_XBIAS 0x20
70 #define MRST_YBIAS 0x40
71 #define MRST_ZBIAS 0x80
75 #define MRST_X_MAX 1024
78 #define MRST_Y_MAX 1024
80 #define MRST_PRESSURE_MIN 0
81 #define MRST_PRESSURE_NOMINAL 50
82 #define MRST_PRESSURE_MAX 100
84 #define WAIT_ADC_COMPLETION 10
87 #define ADC_LOOP_DELAY0 0x0
88 #define ADC_LOOP_DELAY1 0x1
91 #define PMIC_VENDOR_FS 0
92 #define PMIC_VENDOR_MAXIM 1
93 #define PMIC_VENDOR_NEC 2
94 #define MRSTOUCH_MAX_CHANNELS 32
114 static int mrstouch_nec_adc_read_prepare(
struct mrstouch_dev *tsdev)
122 static int mrstouch_nec_adc_read_finish(
struct mrstouch_dev *tsdev)
155 *vp = (res & 0xFF) << 3;
156 *vp |= (res >> 8) & 0x07;
161 *vm = (res & 0xFF) << 3;
162 *vm |= (res >> 8) & 0x07;
172 static int mrstouch_ts_bias_set(
uint offset,
uint bias)
182 for (count = 0; count <= 3; count++) {
191 static int mrstouch_nec_adc_read(
struct mrstouch_dev *tsdev,
236 dev_err(tsdev->
dev,
"ipc error during adc read\n");
243 static int mrstouch_fs_adc_read_prepare(
struct mrstouch_dev *tsdev)
258 for (count = 0; count <= 3; count++) {
272 for (count = 0; count <= 3; count++) {
295 dev_err(tsdev->
dev,
"ipc error during %s\n", __func__);
299 static int mrstouch_fs_adc_read(
struct mrstouch_dev *tsdev,
311 reg[2] = result + 16;
312 reg[3] = result + 17;
327 reg[0] = result + 28;
328 reg[1] = result + 29;
341 dev_err(tsdev->
dev,
"ipc error during %s\n", __func__);
345 static int mrstouch_fs_adc_read_finish(
struct mrstouch_dev *tsdev)
354 for (count = 0; count <= 4; count++) {
362 for (count = 0; count <= 4; count++) {
382 dev_err(tsdev->
dev,
"ipc error during %s\n", __func__);
386 static void mrstouch_report_event(
struct input_dev *
input,
387 unsigned int x,
unsigned int y,
unsigned int z)
392 input_report_abs(input,
ABS_X, x);
393 input_report_abs(input,
ABS_Y, y);
417 if (tsdev->
read(tsdev, &x, &y, &z))
420 mrstouch_report_event(tsdev->
input, x, y, z);
440 *rev = (r >> 3) & 0x7;
467 if (found > MRSTOUCH_MAX_CHANNELS - 18)
470 if (found > MRSTOUCH_MAX_CHANNELS - 4)
488 for (count = 0; count <= 3; count++) {
502 err = mrstouch_read_pmic_id(&tsdev->
vendor, &tsdev->
rev);
504 dev_err(tsdev->
dev,
"Unable to read PMIC id\n");
512 tsdev->
read = mrstouch_nec_adc_read;
518 tsdev->
read = mrstouch_fs_adc_read;
524 "Unsupported touchscreen: %d\n", tsdev->
vendor);
528 start = mrstouch_chan_parse(tsdev);
530 dev_err(tsdev->
dev,
"Unable to parse channels\n");
553 err = mrstouch_ts_chan_set(tsdev->
asr);
574 struct input_dev *
input;
580 dev_err(&pdev->
dev,
"no interrupt assigned\n");
585 input = input_allocate_device();
586 if (!tsdev || !input) {
587 dev_err(&pdev->
dev,
"unable to allocate memory\n");
597 "%s/input0", dev_name(tsdev->
dev));
599 err = mrstouch_adc_init(tsdev);
601 dev_err(&pdev->
dev,
"ADC initialization failed\n");
605 input->name =
"mrst_touchscreen";
606 input->phys = tsdev->
phys;
607 input->dev.parent = tsdev->
dev;
609 input->id.vendor = tsdev->
vendor;
610 input->id.version = tsdev->
rev;
625 dev_err(tsdev->
dev,
"unable to allocate irq\n");
629 err = input_register_device(tsdev->
input);
631 dev_err(tsdev->
dev,
"unable to register input device\n");
635 platform_set_drvdata(pdev, tsdev);
641 input_free_device(input);
648 struct mrstouch_dev *tsdev = platform_get_drvdata(pdev);
651 input_unregister_device(tsdev->
input);
654 platform_set_drvdata(pdev,
NULL);
661 .name =
"pmic_touch",
664 .probe = mrstouch_probe,