History

input: ti_am33x_tsc: Order of TSC wires, made configurable

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. Sebastian reworked the original patch and removed a lot of the not required pieces.

Patil, Rachna committed 13 years ago

Commit bb76dc01 parent abeccee3 files · +98 −19Browse files

Unified · Split

3 files
  1. drivers/input/touchscreen/ti_am335x_tsc.c +86 −16
  2. include/linux/input/ti_am335x_tsc.h +12 −0
  3. include/linux/mfd/ti_am335x_tscadc.h +0 −3
drivers/input/touchscreen/ti_am335x_tsc.c+86−16
@@ -33,6 +33,13 @@ · 32 unmodified lines
3333 #define SEQ_SETTLE 275
3434 #define MAX_12BIT ((1 << 12) - 1)
3535
36+static const int config_pins[] = {
37+ STEPCONFIG_XPP,
38+ STEPCONFIG_XNN,
39+ STEPCONFIG_YPP,
40+ STEPCONFIG_YNN,
41+};
42+
3643 struct titsc {
3744 struct input_dev *input;
3845 struct ti_tscadc_dev *mfd_tscadc;
@@ -41,6 +48,9 @@ struct titsc { · 2 unmodified lines
4148 unsigned int x_plate_resistance;
4249 bool pen_down;
4350 int steps_to_configure;
51+ u32 config_inp[4];
52+ u32 bit_xp, bit_xn, bit_yp, bit_yn;
53+ u32 inp_xp, inp_xn, inp_yp, inp_yn;
4454 };
4555
4656 static unsigned int titsc_readl(struct titsc *ts, unsigned int reg)
@@ -54,6 +64,58 @@ static void titsc_writel(struct titsc *tsc, unsigned int reg, · 7 unmodified lines
5464 writel(val, tsc->mfd_tscadc->tscadc_base + reg);
5565 }
5666
67+static int titsc_config_wires(struct titsc *ts_dev)
68+{
69+ u32 analog_line[4];
70+ u32 wire_order[4];
71+ int i, bit_cfg;
72+
73+ for (i = 0; i < 4; i++) {
74+ /*
75+ * Get the order in which TSC wires are attached
76+ * w.r.t. each of the analog input lines on the EVM.
77+ */
78+ analog_line[i] = (ts_dev->config_inp[i] & 0xF0) >> 4;
79+ wire_order[i] = ts_dev->config_inp[i] & 0x0F;
80+ if (WARN_ON(analog_line[i] > 7))
81+ return -EINVAL;
82+ if (WARN_ON(wire_order[i] > ARRAY_SIZE(config_pins)))
83+ return -EINVAL;
84+ }
85+
86+ for (i = 0; i < 4; i++) {
87+ int an_line;
88+ int wi_order;
89+
90+ an_line = analog_line[i];
91+ wi_order = wire_order[i];
92+ bit_cfg = config_pins[wi_order];
93+ if (bit_cfg == 0)
94+ return -EINVAL;
95+ switch (wi_order) {
96+ case 0:
97+ ts_dev->bit_xp = bit_cfg;
98+ ts_dev->inp_xp = an_line;
99+ break;
100+
101+ case 1:
102+ ts_dev->bit_xn = bit_cfg;
103+ ts_dev->inp_xn = an_line;
104+ break;
105+
106+ case 2:
107+ ts_dev->bit_yp = bit_cfg;
108+ ts_dev->inp_yp = an_line;
109+ break;
110+ case 3:
111+ ts_dev->bit_yn = bit_cfg;
112+ ts_dev->inp_yn = an_line;
113+ break;
114+ }
115+ }
116+ return 0;
117+}
118+
57119 static void titsc_step_config(struct titsc *ts_dev)
58120 {
59121 unsigned int config;
@@ -64,18 +126,18 @@ static void titsc_step_config(struct titsc *ts_dev) · 4 unmodified lines
64126 total_steps = 2 * ts_dev->steps_to_configure;
65127
66128 config = STEPCONFIG_MODE_HWSYNC |
67− STEPCONFIG_AVG_16 | STEPCONFIG_XPP;
129+ STEPCONFIG_AVG_16 | ts_dev->bit_xp;
68130 switch (ts_dev->wires) {
69131 case 4:
70− config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
132+ config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
71133 break;
72134 case 5:
73− config |= STEPCONFIG_YNN |
74− STEPCONFIG_INP_AN4 | STEPCONFIG_XNN |
75− STEPCONFIG_YPP;
135+ config |= ts_dev->bit_yn |
136+ STEPCONFIG_INP_AN4 | ts_dev->bit_xn |
137+ ts_dev->bit_yp;
76138 break;
77139 case 8:
78− config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN;
140+ config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
79141 break;
80142 }
81143
@@ -86,18 +148,18 @@ static void titsc_step_config(struct titsc *ts_dev) · 4 unmodified lines
86148
87149 config = 0;
88150 config = STEPCONFIG_MODE_HWSYNC |
89− STEPCONFIG_AVG_16 | STEPCONFIG_YNN |
151+ STEPCONFIG_AVG_16 | ts_dev->bit_yn |
90152 STEPCONFIG_INM_ADCREFM | STEPCONFIG_FIFO1;
91153 switch (ts_dev->wires) {
92154 case 4:
93− config |= STEPCONFIG_YPP;
155+ config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
94156 break;
95157 case 5:
96− config |= STEPCONFIG_XPP | STEPCONFIG_INP_AN4 |
97− STEPCONFIG_XNP | STEPCONFIG_YPN;
158+ config |= ts_dev->bit_xp | STEPCONFIG_INP_AN4 |
159+ ts_dev->bit_xn | ts_dev->bit_yp;
98160 break;
99161 case 8:
100− config |= STEPCONFIG_YPP;
162+ config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
101163 break;
102164 }
103165
@@ -108,9 +170,9 @@ static void titsc_step_config(struct titsc *ts_dev) · 4 unmodified lines
108170
109171 config = 0;
110172 /* Charge step configuration */
111− config = STEPCONFIG_XPP | STEPCONFIG_YNN |
173+ config = ts_dev->bit_xp | ts_dev->bit_yn |
112174 STEPCHARGE_RFP_XPUL | STEPCHARGE_RFM_XNUR |
113− STEPCHARGE_INM_AN1 | STEPCHARGE_INP_AN1;
175+ STEPCHARGE_INM_AN1 | STEPCHARGE_INP(ts_dev->inp_yp);
114176
115177 titsc_writel(ts_dev, REG_CHARGECONFIG, config);
116178 titsc_writel(ts_dev, REG_CHARGEDELAY, CHARGEDLY_OPENDLY);
@@ -118,13 +180,14 @@ static void titsc_step_config(struct titsc *ts_dev) · 1 unmodified line
118180 config = 0;
119181 /* Configure to calculate pressure */
120182 config = STEPCONFIG_MODE_HWSYNC |
121− STEPCONFIG_AVG_16 | STEPCONFIG_YPP |
122− STEPCONFIG_XNN | STEPCONFIG_INM_ADCREFM;
183+ STEPCONFIG_AVG_16 | ts_dev->bit_yp |
184+ ts_dev->bit_xn | STEPCONFIG_INM_ADCREFM |
185+ STEPCONFIG_INP(ts_dev->inp_xp);
123186 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 1), config);
124187 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 1),
125188 STEPCONFIG_OPENDLY);
126189
127− config |= STEPCONFIG_INP_AN3 | STEPCONFIG_FIFO1;
190+ config |= STEPCONFIG_INP(ts_dev->inp_yn) | STEPCONFIG_FIFO1;
128191 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 2), config);
129192 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2),
130193 STEPCONFIG_OPENDLY);
@@ -292,6 +355,8 @@ static int titsc_probe(struct platform_device *pdev) · 161 unmodified lines
292355 ts_dev->wires = pdata->tsc_init->wires;
293356 ts_dev->x_plate_resistance = pdata->tsc_init->x_plate_resistance;
294357 ts_dev->steps_to_configure = pdata->tsc_init->steps_to_configure;
358+ memcpy(ts_dev->config_inp, pdata->tsc_init->wire_config,
359+ sizeof(pdata->tsc_init->wire_config));
295360
296361 err = request_irq(ts_dev->irq, titsc_irq,
297362 0, pdev->dev.driver->name, ts_dev);
@@ -301,6 +366,11 @@ static int titsc_probe(struct platform_device *pdev) · 3 unmodified lines
301366 }
302367
303368 titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
369+ err = titsc_config_wires(ts_dev);
370+ if (err) {
371+ dev_err(&pdev->dev, "wrong i/p wire configuration\n");
372+ goto err_free_irq;
373+ }
304374 titsc_step_config(ts_dev);
305375 titsc_writel(ts_dev, REG_FIFO0THR, ts_dev->steps_to_configure);
306376
include/linux/input/ti_am335x_tsc.h+12−0
@@ -12,12 +12,24 @@ · 11 unmodified lines
1212 * A step configured to read a single
1313 * co-ordinate value, can be applied
1414 * more number of times for better results.
15+ * @wire_config: Different EVM's could have a different order
16+ * for connecting wires on touchscreen.
17+ * We need to provide an 8 bit number where in
18+ * the 1st four bits represent the analog lines
19+ * and the next 4 bits represent positive/
20+ * negative terminal on that input line.
21+ * Notations to represent the input lines and
22+ * terminals resoectively is as follows:
23+ * AIN0 = 0, AIN1 = 1 and so on till AIN7 = 7.
24+ * XP = 0, XN = 1, YP = 2, YN = 3.
25+ *
1526 */
1627
1728 struct tsc_data {
1829 int wires;
1930 int x_plate_resistance;
2031 int steps_to_configure;
32+ int wire_config[10];
2133 };
2234
2335 #endif
include/linux/mfd/ti_am335x_tscadc.h+0−3
@@ -71,8 +71,6 @@ · 70 unmodified lines
7171 #define STEPCONFIG_INM_ADCREFM STEPCONFIG_INM(8)
7272 #define STEPCONFIG_INP_MASK (0xF << 19)
7373 #define STEPCONFIG_INP(val) ((val) << 19)
74−#define STEPCONFIG_INP_AN2 STEPCONFIG_INP(2)
75−#define STEPCONFIG_INP_AN3 STEPCONFIG_INP(3)
7674 #define STEPCONFIG_INP_AN4 STEPCONFIG_INP(4)
7775 #define STEPCONFIG_INP_ADCREFM STEPCONFIG_INP(8)
7876 #define STEPCONFIG_FIFO1 BIT(26)
@@ -94,7 +92,6 @@ · 15 unmodified lines
9492 #define STEPCHARGE_INM_AN1 STEPCHARGE_INM(1)
9593 #define STEPCHARGE_INP_MASK (0xF << 19)
9694 #define STEPCHARGE_INP(val) ((val) << 19)
97−#define STEPCHARGE_INP_AN1 STEPCHARGE_INP(1)
9895 #define STEPCHARGE_RFM_MASK (3 << 23)
9996 #define STEPCHARGE_RFM(val) ((val) << 23)
10097 #define STEPCHARGE_RFM_XNUR STEPCHARGE_RFM(1)