diff options
Diffstat (limited to 'drivers/input/touchscreen/ads7846.c')
-rw-r--r-- | drivers/input/touchscreen/ads7846.c | 94 |
1 files changed, 55 insertions, 39 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 8583c766d565..b9b7fc6ff1eb 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
@@ -69,6 +69,17 @@ struct ts_event { | |||
69 | int ignore; | 69 | int ignore; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | /* | ||
73 | * We allocate this separately to avoid cache line sharing issues when | ||
74 | * driver is used with DMA-based SPI controllers (like atmel_spi) on | ||
75 | * systems where main memory is not DMA-coherent (most non-x86 boards). | ||
76 | */ | ||
77 | struct ads7846_packet { | ||
78 | u8 read_x, read_y, read_z1, read_z2, pwrdown; | ||
79 | u16 dummy; /* for the pwrdown read */ | ||
80 | struct ts_event tc; | ||
81 | }; | ||
82 | |||
72 | struct ads7846 { | 83 | struct ads7846 { |
73 | struct input_dev *input; | 84 | struct input_dev *input; |
74 | char phys[32]; | 85 | char phys[32]; |
@@ -86,9 +97,7 @@ struct ads7846 { | |||
86 | u16 x_plate_ohms; | 97 | u16 x_plate_ohms; |
87 | u16 pressure_max; | 98 | u16 pressure_max; |
88 | 99 | ||
89 | u8 read_x, read_y, read_z1, read_z2, pwrdown; | 100 | struct ads7846_packet *packet; |
90 | u16 dummy; /* for the pwrdown read */ | ||
91 | struct ts_event tc; | ||
92 | 101 | ||
93 | struct spi_transfer xfer[18]; | 102 | struct spi_transfer xfer[18]; |
94 | struct spi_message msg[5]; | 103 | struct spi_message msg[5]; |
@@ -463,10 +472,11 @@ static ssize_t ads7846_disable_store(struct device *dev, | |||
463 | const char *buf, size_t count) | 472 | const char *buf, size_t count) |
464 | { | 473 | { |
465 | struct ads7846 *ts = dev_get_drvdata(dev); | 474 | struct ads7846 *ts = dev_get_drvdata(dev); |
466 | char *endp; | 475 | long i; |
467 | int i; | 476 | |
477 | if (strict_strtoul(buf, 10, &i)) | ||
478 | return -EINVAL; | ||
468 | 479 | ||
469 | i = simple_strtoul(buf, &endp, 10); | ||
470 | spin_lock_irq(&ts->lock); | 480 | spin_lock_irq(&ts->lock); |
471 | 481 | ||
472 | if (i) | 482 | if (i) |
@@ -512,16 +522,17 @@ static int get_pendown_state(struct ads7846 *ts) | |||
512 | static void ads7846_rx(void *ads) | 522 | static void ads7846_rx(void *ads) |
513 | { | 523 | { |
514 | struct ads7846 *ts = ads; | 524 | struct ads7846 *ts = ads; |
525 | struct ads7846_packet *packet = ts->packet; | ||
515 | unsigned Rt; | 526 | unsigned Rt; |
516 | u16 x, y, z1, z2; | 527 | u16 x, y, z1, z2; |
517 | 528 | ||
518 | /* ads7846_rx_val() did in-place conversion (including byteswap) from | 529 | /* ads7846_rx_val() did in-place conversion (including byteswap) from |
519 | * on-the-wire format as part of debouncing to get stable readings. | 530 | * on-the-wire format as part of debouncing to get stable readings. |
520 | */ | 531 | */ |
521 | x = ts->tc.x; | 532 | x = packet->tc.x; |
522 | y = ts->tc.y; | 533 | y = packet->tc.y; |
523 | z1 = ts->tc.z1; | 534 | z1 = packet->tc.z1; |
524 | z2 = ts->tc.z2; | 535 | z2 = packet->tc.z2; |
525 | 536 | ||
526 | /* range filtering */ | 537 | /* range filtering */ |
527 | if (x == MAX_12BIT) | 538 | if (x == MAX_12BIT) |
@@ -545,10 +556,10 @@ static void ads7846_rx(void *ads) | |||
545 | * the maximum. Don't report it to user space, repeat at least | 556 | * the maximum. Don't report it to user space, repeat at least |
546 | * once more the measurement | 557 | * once more the measurement |
547 | */ | 558 | */ |
548 | if (ts->tc.ignore || Rt > ts->pressure_max) { | 559 | if (packet->tc.ignore || Rt > ts->pressure_max) { |
549 | #ifdef VERBOSE | 560 | #ifdef VERBOSE |
550 | pr_debug("%s: ignored %d pressure %d\n", | 561 | pr_debug("%s: ignored %d pressure %d\n", |
551 | ts->spi->dev.bus_id, ts->tc.ignore, Rt); | 562 | ts->spi->dev.bus_id, packet->tc.ignore, Rt); |
552 | #endif | 563 | #endif |
553 | hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), | 564 | hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), |
554 | HRTIMER_MODE_REL); | 565 | HRTIMER_MODE_REL); |
@@ -641,6 +652,7 @@ static int ads7846_no_filter(void *ads, int data_idx, int *val) | |||
641 | static void ads7846_rx_val(void *ads) | 652 | static void ads7846_rx_val(void *ads) |
642 | { | 653 | { |
643 | struct ads7846 *ts = ads; | 654 | struct ads7846 *ts = ads; |
655 | struct ads7846_packet *packet = ts->packet; | ||
644 | struct spi_message *m; | 656 | struct spi_message *m; |
645 | struct spi_transfer *t; | 657 | struct spi_transfer *t; |
646 | int val; | 658 | int val; |
@@ -660,7 +672,7 @@ static void ads7846_rx_val(void *ads) | |||
660 | case ADS7846_FILTER_REPEAT: | 672 | case ADS7846_FILTER_REPEAT: |
661 | break; | 673 | break; |
662 | case ADS7846_FILTER_IGNORE: | 674 | case ADS7846_FILTER_IGNORE: |
663 | ts->tc.ignore = 1; | 675 | packet->tc.ignore = 1; |
664 | /* Last message will contain ads7846_rx() as the | 676 | /* Last message will contain ads7846_rx() as the |
665 | * completion function. | 677 | * completion function. |
666 | */ | 678 | */ |
@@ -668,7 +680,7 @@ static void ads7846_rx_val(void *ads) | |||
668 | break; | 680 | break; |
669 | case ADS7846_FILTER_OK: | 681 | case ADS7846_FILTER_OK: |
670 | *(u16 *)t->rx_buf = val; | 682 | *(u16 *)t->rx_buf = val; |
671 | ts->tc.ignore = 0; | 683 | packet->tc.ignore = 0; |
672 | m = &ts->msg[++ts->msg_idx]; | 684 | m = &ts->msg[++ts->msg_idx]; |
673 | break; | 685 | break; |
674 | default: | 686 | default: |
@@ -773,7 +785,6 @@ static void ads7846_disable(struct ads7846 *ts) | |||
773 | /* we know the chip's in lowpower mode since we always | 785 | /* we know the chip's in lowpower mode since we always |
774 | * leave it that way after every request | 786 | * leave it that way after every request |
775 | */ | 787 | */ |
776 | |||
777 | } | 788 | } |
778 | 789 | ||
779 | /* Must be called with ts->lock held */ | 790 | /* Must be called with ts->lock held */ |
@@ -849,6 +860,7 @@ static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts) | |||
849 | static int __devinit ads7846_probe(struct spi_device *spi) | 860 | static int __devinit ads7846_probe(struct spi_device *spi) |
850 | { | 861 | { |
851 | struct ads7846 *ts; | 862 | struct ads7846 *ts; |
863 | struct ads7846_packet *packet; | ||
852 | struct input_dev *input_dev; | 864 | struct input_dev *input_dev; |
853 | struct ads7846_platform_data *pdata = spi->dev.platform_data; | 865 | struct ads7846_platform_data *pdata = spi->dev.platform_data; |
854 | struct spi_message *m; | 866 | struct spi_message *m; |
@@ -884,14 +896,16 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
884 | return err; | 896 | return err; |
885 | 897 | ||
886 | ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); | 898 | ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); |
899 | packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL); | ||
887 | input_dev = input_allocate_device(); | 900 | input_dev = input_allocate_device(); |
888 | if (!ts || !input_dev) { | 901 | if (!ts || !packet || !input_dev) { |
889 | err = -ENOMEM; | 902 | err = -ENOMEM; |
890 | goto err_free_mem; | 903 | goto err_free_mem; |
891 | } | 904 | } |
892 | 905 | ||
893 | dev_set_drvdata(&spi->dev, ts); | 906 | dev_set_drvdata(&spi->dev, ts); |
894 | 907 | ||
908 | ts->packet = packet; | ||
895 | ts->spi = spi; | 909 | ts->spi = spi; |
896 | ts->input = input_dev; | 910 | ts->input = input_dev; |
897 | ts->vref_mv = pdata->vref_mv; | 911 | ts->vref_mv = pdata->vref_mv; |
@@ -963,13 +977,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
963 | spi_message_init(m); | 977 | spi_message_init(m); |
964 | 978 | ||
965 | /* y- still on; turn on only y+ (and ADC) */ | 979 | /* y- still on; turn on only y+ (and ADC) */ |
966 | ts->read_y = READ_Y(vref); | 980 | packet->read_y = READ_Y(vref); |
967 | x->tx_buf = &ts->read_y; | 981 | x->tx_buf = &packet->read_y; |
968 | x->len = 1; | 982 | x->len = 1; |
969 | spi_message_add_tail(x, m); | 983 | spi_message_add_tail(x, m); |
970 | 984 | ||
971 | x++; | 985 | x++; |
972 | x->rx_buf = &ts->tc.y; | 986 | x->rx_buf = &packet->tc.y; |
973 | x->len = 2; | 987 | x->len = 2; |
974 | spi_message_add_tail(x, m); | 988 | spi_message_add_tail(x, m); |
975 | 989 | ||
@@ -981,12 +995,12 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
981 | x->delay_usecs = pdata->settle_delay_usecs; | 995 | x->delay_usecs = pdata->settle_delay_usecs; |
982 | 996 | ||
983 | x++; | 997 | x++; |
984 | x->tx_buf = &ts->read_y; | 998 | x->tx_buf = &packet->read_y; |
985 | x->len = 1; | 999 | x->len = 1; |
986 | spi_message_add_tail(x, m); | 1000 | spi_message_add_tail(x, m); |
987 | 1001 | ||
988 | x++; | 1002 | x++; |
989 | x->rx_buf = &ts->tc.y; | 1003 | x->rx_buf = &packet->tc.y; |
990 | x->len = 2; | 1004 | x->len = 2; |
991 | spi_message_add_tail(x, m); | 1005 | spi_message_add_tail(x, m); |
992 | } | 1006 | } |
@@ -999,13 +1013,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
999 | 1013 | ||
1000 | /* turn y- off, x+ on, then leave in lowpower */ | 1014 | /* turn y- off, x+ on, then leave in lowpower */ |
1001 | x++; | 1015 | x++; |
1002 | ts->read_x = READ_X(vref); | 1016 | packet->read_x = READ_X(vref); |
1003 | x->tx_buf = &ts->read_x; | 1017 | x->tx_buf = &packet->read_x; |
1004 | x->len = 1; | 1018 | x->len = 1; |
1005 | spi_message_add_tail(x, m); | 1019 | spi_message_add_tail(x, m); |
1006 | 1020 | ||
1007 | x++; | 1021 | x++; |
1008 | x->rx_buf = &ts->tc.x; | 1022 | x->rx_buf = &packet->tc.x; |
1009 | x->len = 2; | 1023 | x->len = 2; |
1010 | spi_message_add_tail(x, m); | 1024 | spi_message_add_tail(x, m); |
1011 | 1025 | ||
@@ -1014,12 +1028,12 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1014 | x->delay_usecs = pdata->settle_delay_usecs; | 1028 | x->delay_usecs = pdata->settle_delay_usecs; |
1015 | 1029 | ||
1016 | x++; | 1030 | x++; |
1017 | x->tx_buf = &ts->read_x; | 1031 | x->tx_buf = &packet->read_x; |
1018 | x->len = 1; | 1032 | x->len = 1; |
1019 | spi_message_add_tail(x, m); | 1033 | spi_message_add_tail(x, m); |
1020 | 1034 | ||
1021 | x++; | 1035 | x++; |
1022 | x->rx_buf = &ts->tc.x; | 1036 | x->rx_buf = &packet->tc.x; |
1023 | x->len = 2; | 1037 | x->len = 2; |
1024 | spi_message_add_tail(x, m); | 1038 | spi_message_add_tail(x, m); |
1025 | } | 1039 | } |
@@ -1033,13 +1047,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1033 | spi_message_init(m); | 1047 | spi_message_init(m); |
1034 | 1048 | ||
1035 | x++; | 1049 | x++; |
1036 | ts->read_z1 = READ_Z1(vref); | 1050 | packet->read_z1 = READ_Z1(vref); |
1037 | x->tx_buf = &ts->read_z1; | 1051 | x->tx_buf = &packet->read_z1; |
1038 | x->len = 1; | 1052 | x->len = 1; |
1039 | spi_message_add_tail(x, m); | 1053 | spi_message_add_tail(x, m); |
1040 | 1054 | ||
1041 | x++; | 1055 | x++; |
1042 | x->rx_buf = &ts->tc.z1; | 1056 | x->rx_buf = &packet->tc.z1; |
1043 | x->len = 2; | 1057 | x->len = 2; |
1044 | spi_message_add_tail(x, m); | 1058 | spi_message_add_tail(x, m); |
1045 | 1059 | ||
@@ -1048,12 +1062,12 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1048 | x->delay_usecs = pdata->settle_delay_usecs; | 1062 | x->delay_usecs = pdata->settle_delay_usecs; |
1049 | 1063 | ||
1050 | x++; | 1064 | x++; |
1051 | x->tx_buf = &ts->read_z1; | 1065 | x->tx_buf = &packet->read_z1; |
1052 | x->len = 1; | 1066 | x->len = 1; |
1053 | spi_message_add_tail(x, m); | 1067 | spi_message_add_tail(x, m); |
1054 | 1068 | ||
1055 | x++; | 1069 | x++; |
1056 | x->rx_buf = &ts->tc.z1; | 1070 | x->rx_buf = &packet->tc.z1; |
1057 | x->len = 2; | 1071 | x->len = 2; |
1058 | spi_message_add_tail(x, m); | 1072 | spi_message_add_tail(x, m); |
1059 | } | 1073 | } |
@@ -1065,13 +1079,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1065 | spi_message_init(m); | 1079 | spi_message_init(m); |
1066 | 1080 | ||
1067 | x++; | 1081 | x++; |
1068 | ts->read_z2 = READ_Z2(vref); | 1082 | packet->read_z2 = READ_Z2(vref); |
1069 | x->tx_buf = &ts->read_z2; | 1083 | x->tx_buf = &packet->read_z2; |
1070 | x->len = 1; | 1084 | x->len = 1; |
1071 | spi_message_add_tail(x, m); | 1085 | spi_message_add_tail(x, m); |
1072 | 1086 | ||
1073 | x++; | 1087 | x++; |
1074 | x->rx_buf = &ts->tc.z2; | 1088 | x->rx_buf = &packet->tc.z2; |
1075 | x->len = 2; | 1089 | x->len = 2; |
1076 | spi_message_add_tail(x, m); | 1090 | spi_message_add_tail(x, m); |
1077 | 1091 | ||
@@ -1080,12 +1094,12 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1080 | x->delay_usecs = pdata->settle_delay_usecs; | 1094 | x->delay_usecs = pdata->settle_delay_usecs; |
1081 | 1095 | ||
1082 | x++; | 1096 | x++; |
1083 | x->tx_buf = &ts->read_z2; | 1097 | x->tx_buf = &packet->read_z2; |
1084 | x->len = 1; | 1098 | x->len = 1; |
1085 | spi_message_add_tail(x, m); | 1099 | spi_message_add_tail(x, m); |
1086 | 1100 | ||
1087 | x++; | 1101 | x++; |
1088 | x->rx_buf = &ts->tc.z2; | 1102 | x->rx_buf = &packet->tc.z2; |
1089 | x->len = 2; | 1103 | x->len = 2; |
1090 | spi_message_add_tail(x, m); | 1104 | spi_message_add_tail(x, m); |
1091 | } | 1105 | } |
@@ -1099,13 +1113,13 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1099 | spi_message_init(m); | 1113 | spi_message_init(m); |
1100 | 1114 | ||
1101 | x++; | 1115 | x++; |
1102 | ts->pwrdown = PWRDOWN; | 1116 | packet->pwrdown = PWRDOWN; |
1103 | x->tx_buf = &ts->pwrdown; | 1117 | x->tx_buf = &packet->pwrdown; |
1104 | x->len = 1; | 1118 | x->len = 1; |
1105 | spi_message_add_tail(x, m); | 1119 | spi_message_add_tail(x, m); |
1106 | 1120 | ||
1107 | x++; | 1121 | x++; |
1108 | x->rx_buf = &ts->dummy; | 1122 | x->rx_buf = &packet->dummy; |
1109 | x->len = 2; | 1123 | x->len = 2; |
1110 | CS_CHANGE(*x); | 1124 | CS_CHANGE(*x); |
1111 | spi_message_add_tail(x, m); | 1125 | spi_message_add_tail(x, m); |
@@ -1158,6 +1172,7 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
1158 | ts->filter_cleanup(ts->filter_data); | 1172 | ts->filter_cleanup(ts->filter_data); |
1159 | err_free_mem: | 1173 | err_free_mem: |
1160 | input_free_device(input_dev); | 1174 | input_free_device(input_dev); |
1175 | kfree(packet); | ||
1161 | kfree(ts); | 1176 | kfree(ts); |
1162 | return err; | 1177 | return err; |
1163 | } | 1178 | } |
@@ -1183,6 +1198,7 @@ static int __devexit ads7846_remove(struct spi_device *spi) | |||
1183 | if (ts->filter_cleanup) | 1198 | if (ts->filter_cleanup) |
1184 | ts->filter_cleanup(ts->filter_data); | 1199 | ts->filter_cleanup(ts->filter_data); |
1185 | 1200 | ||
1201 | kfree(ts->packet); | ||
1186 | kfree(ts); | 1202 | kfree(ts); |
1187 | 1203 | ||
1188 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); | 1204 | dev_dbg(&spi->dev, "unregistered touchscreen\n"); |