From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-input@vger.kernel.org, linux-iio@vger.kernel.org
Cc: Samuel Ortiz <sameo@linux.intel.com>,
Jonathan Cameron <jic23@cam.ac.uk>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Felipe Balbi <balbi@ti.com>, "Patil, Rachna" <rachna@ti.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 02/19] input: touchscreen: am335x: Order of TSC wires, made configurable
Date: Mon, 27 May 2013 21:11:49 +0200 [thread overview]
Message-ID: <1369681926-22185-3-git-send-email-bigeasy@linutronix.de> (raw)
In-Reply-To: <1369681926-22185-1-git-send-email-bigeasy@linutronix.de>
From: "Patil, Rachna" <rachna@ti.com>
The current driver expected touchscreen input
wires(XP,XN,YP,YN) to be connected in a particular order.
Making changes to accept this as platform data.
Signed-off-by: Patil, Rachna <rachna@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
drivers/input/touchscreen/ti_am335x_tsc.c | 156 ++++++++++++++++++++++++++---
include/linux/input/ti_am335x_tsc.h | 12 +++
include/linux/mfd/ti_am335x_tscadc.h | 10 +-
3 files changed, 159 insertions(+), 19 deletions(-)
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index da652e0..0c460f9 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -33,6 +33,17 @@
#define SEQ_SETTLE 275
#define MAX_12BIT ((1 << 12) - 1)
+/*
+ * Refer to function regbit_map() to
+ * map the values in the matrix.
+ */
+static int config[4][4] = {
+ {1, 0, 1, 0},
+ {2, 3, 2, 3},
+ {4, 5, 4, 5},
+ {0, 6, 0, 6}
+};
+
struct titsc {
struct input_dev *input;
struct ti_tscadc_dev *mfd_tscadc;
@@ -42,6 +53,9 @@ struct titsc {
unsigned int enable_bits;
bool pen_down;
int steps_to_configure;
+ int config_inp[20];
+ int bit_xp, bit_xn, bit_yp, bit_yn;
+ int inp_xp, inp_xn, inp_yp, inp_yn;
};
static unsigned int titsc_readl(struct titsc *ts, unsigned int reg)
@@ -55,6 +69,107 @@ static void titsc_writel(struct titsc *tsc, unsigned int reg,
writel(val, tsc->mfd_tscadc->tscadc_base + reg);
}
+/*
+ * Each of the analog lines are mapped
+ * with one or two register bits,
+ * which can be either pulled high/low
+ * depending on the value to be read.
+ */
+static int regbit_map(int val)
+{
+ int map_bits = 0;
+
+ switch (val) {
+ case 1:
+ map_bits = XPP;
+ break;
+ case 2:
+ map_bits = XNP;
+ break;
+ case 3:
+ map_bits = XNN;
+ break;
+ case 4:
+ map_bits = YPP;
+ break;
+ case 5:
+ map_bits = YPN;
+ break;
+ case 6:
+ map_bits = YNN;
+ break;
+ }
+
+ return map_bits;
+}
+
+static int titsc_config_wires(struct titsc *ts_dev)
+{
+ int analog_line[10], wire_order[10];
+ int i, temp_bits, err;
+
+ for (i = 0; i < 4; i++) {
+ /*
+ * Get the order in which TSC wires are attached
+ * w.r.t. each of the analog input lines on the EVM.
+ */
+ analog_line[i] = ts_dev->config_inp[i] & 0xF0;
+ analog_line[i] = analog_line[i] >> 4;
+
+ wire_order[i] = ts_dev->config_inp[i] & 0x0F;
+ }
+
+ for (i = 0; i < 4; i++) {
+ switch (wire_order[i]) {
+ case 0:
+ temp_bits = config[analog_line[i]][0];
+ if (temp_bits == 0) {
+ err = -EINVAL;
+ goto ret;
+ } else {
+ ts_dev->bit_xp = regbit_map(temp_bits);
+ ts_dev->inp_xp = analog_line[i];
+ break;
+ }
+ case 1:
+ temp_bits = config[analog_line[i]][1];
+ if (temp_bits == 0) {
+ err = -EINVAL;
+ goto ret;
+ } else {
+ ts_dev->bit_xn = regbit_map(temp_bits);
+ ts_dev->inp_xn = analog_line[i];
+ break;
+ }
+ case 2:
+ temp_bits = config[analog_line[i]][2];
+ if (temp_bits == 0) {
+ err = -EINVAL;
+ goto ret;
+ } else {
+ ts_dev->bit_yp = regbit_map(temp_bits);
+ ts_dev->inp_yp = analog_line[i];
+ break;
+ }
+ case 3:
+ temp_bits = config[analog_line[i]][3];
+ if (temp_bits == 0) {
+ err = -EINVAL;
+ goto ret;
+ } else {
+ ts_dev->bit_yn = regbit_map(temp_bits);
+ ts_dev->inp_yn = analog_line[i];
+ break;
+ }
+ }
+ }
+
+ return 0;
+
+ret:
+ return err;
+}
+
static void titsc_step_config(struct titsc *ts_dev)
{
unsigned int config;
@@ -65,18 +180,18 @@ static void titsc_step_config(struct titsc *ts_dev)
total_steps = 2 * ts_dev->steps_to_configure;
config = STEPCONFIG_MODE_HWSYNC |
- STEPCONFIG_AVG_16 | STEPCONFIG_XPP;
+ STEPCONFIG_AVG_16 | ts_dev->bit_xp;
switch (ts_dev->wires) {
case 4:
- config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
+ config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
break;
case 5:
- config |= STEPCONFIG_YNN |
- STEPCONFIG_INP_AN4 | STEPCONFIG_XNN |
- STEPCONFIG_YPP;
+ config |= ts_dev->bit_yn |
+ STEPCONFIG_INP_AN4 | ts_dev->bit_xn |
+ ts_dev->bit_yp;
break;
case 8:
- config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
+ config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
break;
}
@@ -87,18 +202,18 @@ static void titsc_step_config(struct titsc *ts_dev)
config = 0;
config = STEPCONFIG_MODE_HWSYNC |
- STEPCONFIG_AVG_16 | STEPCONFIG_YNN |
+ STEPCONFIG_AVG_16 | ts_dev->bit_yn |
STEPCONFIG_INM_ADCREFM | STEPCONFIG_FIFO1;
switch (ts_dev->wires) {
case 4:
- config |= STEPCONFIG_YPP;
+ config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
break;
case 5:
- config |= STEPCONFIG_XPP | STEPCONFIG_INP_AN4 |
- STEPCONFIG_XNP | STEPCONFIG_YPN;
+ config |= ts_dev->bit_xp | STEPCONFIG_INP_AN4 |
+ ts_dev->bit_xn | ts_dev->bit_yp;
break;
case 8:
- config |= STEPCONFIG_YPP;
+ config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
break;
}
@@ -109,9 +224,9 @@ static void titsc_step_config(struct titsc *ts_dev)
config = 0;
/* Charge step configuration */
- config = STEPCONFIG_XPP | STEPCONFIG_YNN |
+ config = ts_dev->bit_xp | ts_dev->bit_yn |
STEPCHARGE_RFP_XPUL | STEPCHARGE_RFM_XNUR |
- STEPCHARGE_INM_AN1 | STEPCHARGE_INP_AN1;
+ STEPCHARGE_INM_AN1 | STEPCHARGE_INP(ts_dev->inp_yp);
titsc_writel(ts_dev, REG_CHARGECONFIG, config);
titsc_writel(ts_dev, REG_CHARGEDELAY, CHARGEDLY_OPENDLY);
@@ -119,13 +234,14 @@ static void titsc_step_config(struct titsc *ts_dev)
config = 0;
/* Configure to calculate pressure */
config = STEPCONFIG_MODE_HWSYNC |
- STEPCONFIG_AVG_16 | STEPCONFIG_YPP |
- STEPCONFIG_XNN | STEPCONFIG_INM_ADCREFM;
+ STEPCONFIG_AVG_16 | ts_dev->bit_yp |
+ ts_dev->bit_xn | STEPCONFIG_INM_ADCREFM |
+ STEPCONFIG_INP(ts_dev->inp_xp);
titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 1), config);
titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 1),
STEPCONFIG_OPENDLY);
- config |= STEPCONFIG_INP_AN3 | STEPCONFIG_FIFO1;
+ config |= STEPCONFIG_INP(ts_dev->inp_yn) | STEPCONFIG_FIFO1;
titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 2), config);
titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2),
STEPCONFIG_OPENDLY);
@@ -295,6 +411,8 @@ static int titsc_probe(struct platform_device *pdev)
ts_dev->wires = pdata->tsc_init->wires;
ts_dev->x_plate_resistance = pdata->tsc_init->x_plate_resistance;
ts_dev->steps_to_configure = pdata->tsc_init->steps_to_configure;
+ memcpy(ts_dev->config_inp, pdata->tsc_init->wire_config,
+ sizeof(pdata->tsc_init->wire_config));
err = request_irq(ts_dev->irq, titsc_irq,
0, pdev->dev.driver->name, ts_dev);
@@ -304,6 +422,11 @@ static int titsc_probe(struct platform_device *pdev)
}
titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
+ err = titsc_config_wires(ts_dev);
+ if (err) {
+ dev_err(&pdev->dev, "wrong i/p wire configuration\n");
+ goto err_free_irq;
+ }
titsc_step_config(ts_dev);
titsc_writel(ts_dev, REG_FIFO0THR, ts_dev->steps_to_configure);
@@ -373,6 +496,7 @@ static int titsc_resume(struct device *dev)
0x00);
titsc_writel(ts_dev, REG_IRQCLR, IRQENB_HW_PEN);
}
+ titsc_config_wires(ts_dev);
titsc_step_config(ts_dev);
titsc_writel(ts_dev, REG_FIFO0THR,
ts_dev->steps_to_configure);
diff --git a/include/linux/input/ti_am335x_tsc.h b/include/linux/input/ti_am335x_tsc.h
index 49269a2..6a66b4d 100644
--- a/include/linux/input/ti_am335x_tsc.h
+++ b/include/linux/input/ti_am335x_tsc.h
@@ -12,12 +12,24 @@
* A step configured to read a single
* co-ordinate value, can be applied
* more number of times for better results.
+ * @wire_config: Different EVM's could have a different order
+ * for connecting wires on touchscreen.
+ * We need to provide an 8 bit number where in
+ * the 1st four bits represent the analog lines
+ * and the next 4 bits represent positive/
+ * negative terminal on that input line.
+ * Notations to represent the input lines and
+ * terminals resoectively is as follows:
+ * AIN0 = 0, AIN1 = 1 and so on till AIN7 = 7.
+ * XP = 0, XN = 1, YP = 2, YN = 3.
+ *
*/
struct tsc_data {
int wires;
int x_plate_resistance;
int steps_to_configure;
+ int wire_config[10];
};
#endif
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index 23e4f33..9624fea 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -72,8 +72,6 @@
#define STEPCONFIG_INM_ADCREFM STEPCONFIG_INM(8)
#define STEPCONFIG_INP_MASK (0xF << 19)
#define STEPCONFIG_INP(val) ((val) << 19)
-#define STEPCONFIG_INP_AN2 STEPCONFIG_INP(2)
-#define STEPCONFIG_INP_AN3 STEPCONFIG_INP(3)
#define STEPCONFIG_INP_AN4 STEPCONFIG_INP(4)
#define STEPCONFIG_INP_ADCREFM STEPCONFIG_INP(8)
#define STEPCONFIG_FIFO1 BIT(26)
@@ -95,7 +93,6 @@
#define STEPCHARGE_INM_AN1 STEPCHARGE_INM(1)
#define STEPCHARGE_INP_MASK (0xF << 19)
#define STEPCHARGE_INP(val) ((val) << 19)
-#define STEPCHARGE_INP_AN1 STEPCHARGE_INP(1)
#define STEPCHARGE_RFM_MASK (3 << 23)
#define STEPCHARGE_RFM(val) ((val) << 23)
#define STEPCHARGE_RFM_XNUR STEPCHARGE_RFM(1)
@@ -117,6 +114,13 @@
#define CNTRLREG_8WIRE CNTRLREG_AFE_CTRL(3)
#define CNTRLREG_TSCENB BIT(7)
+#define XPP STEPCONFIG_XPP
+#define XNP STEPCONFIG_XNP
+#define XNN STEPCONFIG_XNN
+#define YPP STEPCONFIG_YPP
+#define YPN STEPCONFIG_YPN
+#define YNN STEPCONFIG_YNN
+
#define ADC_CLK 3000000
#define MAX_CLK_DIV 7
#define TOTAL_STEPS 16
--
1.7.10.4
next prev parent reply other threads:[~2013-05-27 19:12 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-27 19:11 am335x: touch & adc patches Sebastian Andrzej Siewior
2013-05-27 19:11 ` Sebastian Andrzej Siewior [this message]
[not found] ` <1369681926-22185-1-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-05-27 19:11 ` [PATCH 01/19] input: touchscreen: am335x: Step enable bits made configurable Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 03/19] input: touchscreen: am335x: remove unwanted fifo flush Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 04/19] input: touchscreen: am335x: Add DT support Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 05/19] input: ti_am335x_tsc: Add variance filters Sebastian Andrzej Siewior
2013-06-04 16:43 ` Dmitry Torokhov
2013-06-04 16:54 ` Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 08/19] iio/ti_am335x_adc: remove platform_data support Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-9-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-02 17:22 ` Jonathan Cameron
2013-05-27 19:11 ` [PATCH 09/19] mfd: ti_am335x_tscadc: Add DT support Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 10/19] mfd/ti_am335x_tscadc: remove platform_data support Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 11/19] iio & mfd: ti_tscadc: Update with IIO map interface & deal with partial activation Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-12-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-02 17:40 ` Jonathan Cameron
[not found] ` <51AB838B.5060602-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-04 10:19 ` Sebastian Andrzej Siewior
2013-05-27 19:12 ` [PATCH 14/19] Documentation/DT bindings: add info for TI TSC ADC Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-15-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-02 17:48 ` Jonathan Cameron
[not found] ` <51AB8568.9050104-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-04 10:24 ` Sebastian Andrzej Siewior
2013-05-27 19:12 ` [PATCH 15/19] input/ti_am335x_tsc: tiny cleanup Sebastian Andrzej Siewior
2013-06-02 17:49 ` Jonathan Cameron
2013-06-04 10:27 ` Sebastian Andrzej Siewior
2013-06-04 16:49 ` Dmitry Torokhov
2013-05-27 19:12 ` [PATCH 18/19] mfd/ti_am335x_tscadc: add a module alias for modprobe Sebastian Andrzej Siewior
2013-05-27 19:11 ` [PATCH 06/19] input/ti_am33x_tsc: remove platform_data support Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-7-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 16:44 ` Dmitry Torokhov
2013-05-27 19:11 ` [PATCH 07/19] iio: adc: am335x: Add DT support Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-8-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-02 16:58 ` Jonathan Cameron
[not found] ` <51AB79CE.2000001-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-04 10:12 ` Sebastian Andrzej Siewior
[not found] ` <20130604101202.GA1151-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 16:57 ` Dmitry Torokhov
2013-05-27 19:11 ` [PATCH 12/19] iio & mfd & input: ti_tscadc: Match mfd sub devices to regmap interface Sebastian Andrzej Siewior
2013-06-02 17:46 ` Jonathan Cameron
[not found] ` <51AB84F5.2030405-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-04 10:23 ` Sebastian Andrzej Siewior
[not found] ` <20130604102318.GC1151-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 10:25 ` Pantelis Antoniou
[not found] ` <F58DCC19-20B7-4385-B323-C1A2E5F22641-wVdstyuyKrO8r51toPun2/C9HSW9iNxf@public.gmane.org>
2013-06-04 10:52 ` Sebastian Andrzej Siewior
[not found] ` <20130604105210.GI1151-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 10:54 ` Pantelis Antoniou
2013-06-04 11:05 ` Sebastian Andrzej Siewior
[not found] ` <20130604110532.GJ1151-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 11:10 ` Pantelis Antoniou
2013-05-27 19:12 ` [PATCH 13/19] arm: dts: am33xx: add TSC/ADC mfd device support Sebastian Andrzej Siewior
2013-05-27 19:12 ` [PATCH 16/19] mfd / input: ti_am335x_tsc: rename device from tsc to TI-tsc Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-17-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-04 16:50 ` Dmitry Torokhov
[not found] ` <20130604165035.GE26400-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2013-06-04 17:29 ` Sebastian Andrzej Siewior
2013-05-27 19:12 ` [PATCH 17/19] mfd / iio: ti_am335x_adc: rename device from tiadc to TI-adc Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-18-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-06-02 17:50 ` Jonathan Cameron
[not found] ` <51AB85DB.2000305-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-06-04 10:28 ` Sebastian Andrzej Siewior
2013-05-27 19:12 ` [PATCH 19/19] mfd/ti_am335x_tscadc: add private lock/unlock function for regmap read/write Sebastian Andrzej Siewior
[not found] ` <1369681926-22185-20-git-send-email-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-05-29 8:46 ` [PATCH 19/19 v2] " Sebastian Andrzej Siewior
[not found] ` <20130529084642.GA18273-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2013-05-29 11:12 ` Mark Brown
[not found] ` <20130529111253.GR3660-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-05-29 11:25 ` Lars-Peter Clausen
[not found] ` <51A5E5B3.80201-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-05-29 14:31 ` Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1369681926-22185-3-git-send-email-bigeasy@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=balbi@ti.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jic23@cam.ac.uk \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=rachna@ti.com \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).