aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-06-13 06:14:59 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-06-13 06:14:59 -0400
commitd8c5d658f425bd25bbfb137f2617f59ed4fdee7d (patch)
treeba1607f9cc0fb8c3ac246a78490d3e5b8438f44e
parenta1ace0aac5a83b859c2ddeb5dfb032b9b6dcd9cf (diff)
parent1460c152c53335b5403045d056502eda1204c33a (diff)
Merge tag 'am335x_tsc-adc' of git://breakpoint.cc/bigeasy/linux
A complete refurbished series inclunding: - DT support for the MFD, TSC and ADC driver & platform device support, which has no users, has been killed. - iio_map from last series is gone and replaced by proper nodes in the device tree. - suspend fixes which means correct data structs are taken and no interrupt storm - fifo split which should problem with TSC & ADC beeing used at the same time - The ADC channels are now checked before blindly applied. That means the touch part reads X, Y and Z coordinates and does not mix them up. Same goes for the IIO ADC driver. - The IIO ADC driver now creates files named in_voltageX_raw where X represents the ADC line instead of a number starting at 0. A read from this file can return -EBUSY in case touch is busy and the ADC didn't collect a value.
-rw-r--r--Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt44
-rw-r--r--arch/arm/boot/dts/am335x-evm.dts14
-rw-r--r--arch/arm/boot/dts/am33xx.dtsi18
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c132
-rw-r--r--drivers/input/touchscreen/ti_am335x_tsc.c288
-rw-r--r--drivers/mfd/ti_am335x_tscadc.c112
-rw-r--r--include/linux/input/ti_am335x_tsc.h23
-rw-r--r--include/linux/mfd/ti_am335x_tscadc.h35
-rw-r--r--include/linux/platform_data/ti_am335x_adc.h14
9 files changed, 486 insertions, 194 deletions
diff --git a/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt b/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
new file mode 100644
index 000000000000..491c97b78384
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
@@ -0,0 +1,44 @@
1* TI - TSC ADC (Touschscreen and analog digital converter)
2~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
4Required properties:
5- child "tsc"
6 ti,wires: Wires refer to application modes i.e. 4/5/8 wire touchscreen
7 support on the platform.
8 ti,x-plate-resistance: X plate resistance
9 ti,coordiante-readouts: The sequencer supports a total of 16
10 programmable steps each step is used to
11 read a single coordinate. A single
12 readout is enough but multiple reads can
13 increase the quality.
14 A value of 5 means, 5 reads for X, 5 for
15 Y and 2 for Z (always). This utilises 12
16 of the 16 software steps available. The
17 remaining 4 can be used by the ADC.
18 ti,wire-config: Different boards could have a different order for
19 connecting wires on touchscreen. We need to provide an
20 8 bit number where in the 1st four bits represent the
21 analog lines and the next 4 bits represent positive/
22 negative terminal on that input line. Notations to
23 represent the input lines and terminals resoectively
24 is as follows:
25 AIN0 = 0, AIN1 = 1 and so on till AIN7 = 7.
26 XP = 0, XN = 1, YP = 2, YN = 3.
27- child "adc"
28 ti,adc-channels: List of analog inputs available for ADC.
29 AIN0 = 0, AIN1 = 1 and so on till AIN7 = 7.
30
31Example:
32 tscadc: tscadc@44e0d000 {
33 compatible = "ti,am3359-tscadc";
34 tsc {
35 ti,wires = <4>;
36 ti,x-plate-resistance = <200>;
37 ti,coordiante-readouts = <5>;
38 ti,wire-config = <0x00 0x11 0x22 0x33>;
39 };
40
41 adc {
42 ti,adc-channels = <4 5 6 7>;
43 };
44 }
diff --git a/arch/arm/boot/dts/am335x-evm.dts b/arch/arm/boot/dts/am335x-evm.dts
index 0423298a26fe..0fa4c7f9539f 100644
--- a/arch/arm/boot/dts/am335x-evm.dts
+++ b/arch/arm/boot/dts/am335x-evm.dts
@@ -244,3 +244,17 @@
244&cpsw_emac1 { 244&cpsw_emac1 {
245 phy_id = <&davinci_mdio>, <1>; 245 phy_id = <&davinci_mdio>, <1>;
246}; 246};
247
248&tscadc {
249 status = "okay";
250 tsc {
251 ti,wires = <4>;
252 ti,x-plate-resistance = <200>;
253 ti,coordiante-readouts = <5>;
254 ti,wire-config = <0x00 0x11 0x22 0x33>;
255 };
256
257 adc {
258 ti,adc-channels = <4 5 6 7>;
259 };
260};
diff --git a/arch/arm/boot/dts/am33xx.dtsi b/arch/arm/boot/dts/am33xx.dtsi
index 1460d9b88adf..4ad7797b97b6 100644
--- a/arch/arm/boot/dts/am33xx.dtsi
+++ b/arch/arm/boot/dts/am33xx.dtsi
@@ -404,6 +404,24 @@
404 ti,hwmods = "wkup_m3"; 404 ti,hwmods = "wkup_m3";
405 }; 405 };
406 406
407 tscadc: tscadc@44e0d000 {
408 compatible = "ti,am3359-tscadc";
409 reg = <0x44e0d000 0x1000>;
410 interrupt-parent = <&intc>;
411 interrupts = <16>;
412 ti,hwmods = "adc_tsc";
413 status = "disabled";
414
415 tsc {
416 compatible = "ti,am3359-tsc";
417 };
418 am335x_adc: adc {
419 #io-channel-cells = <1>;
420 compatible = "ti,am3359-adc";
421 };
422
423 };
424
407 gpmc: gpmc@50000000 { 425 gpmc: gpmc@50000000 {
408 compatible = "ti,am3352-gpmc"; 426 compatible = "ti,am3352-gpmc";
409 ti,hwmods = "gpmc"; 427 ti,hwmods = "gpmc";
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 5f9a7e7d3135..4427e8e46a7f 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -22,13 +22,18 @@
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/iio/iio.h> 24#include <linux/iio/iio.h>
25#include <linux/of.h>
26#include <linux/of_device.h>
27#include <linux/iio/machine.h>
28#include <linux/iio/driver.h>
25 29
26#include <linux/mfd/ti_am335x_tscadc.h> 30#include <linux/mfd/ti_am335x_tscadc.h>
27#include <linux/platform_data/ti_am335x_adc.h>
28 31
29struct tiadc_device { 32struct tiadc_device {
30 struct ti_tscadc_dev *mfd_tscadc; 33 struct ti_tscadc_dev *mfd_tscadc;
31 int channels; 34 int channels;
35 u8 channel_line[8];
36 u8 channel_step[8];
32}; 37};
33 38
34static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg) 39static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg)
@@ -42,10 +47,20 @@ static void tiadc_writel(struct tiadc_device *adc, unsigned int reg,
42 writel(val, adc->mfd_tscadc->tscadc_base + reg); 47 writel(val, adc->mfd_tscadc->tscadc_base + reg);
43} 48}
44 49
50static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
51{
52 u32 step_en;
53
54 step_en = ((1 << adc_dev->channels) - 1);
55 step_en <<= TOTAL_STEPS - adc_dev->channels + 1;
56 return step_en;
57}
58
45static void tiadc_step_config(struct tiadc_device *adc_dev) 59static void tiadc_step_config(struct tiadc_device *adc_dev)
46{ 60{
47 unsigned int stepconfig; 61 unsigned int stepconfig;
48 int i, channels = 0, steps; 62 int i, steps;
63 u32 step_en;
49 64
50 /* 65 /*
51 * There are 16 configurable steps and 8 analog input 66 * There are 16 configurable steps and 8 analog input
@@ -58,43 +73,63 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
58 */ 73 */
59 74
60 steps = TOTAL_STEPS - adc_dev->channels; 75 steps = TOTAL_STEPS - adc_dev->channels;
61 channels = TOTAL_CHANNELS - adc_dev->channels;
62
63 stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1; 76 stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
64 77
65 for (i = (steps + 1); i <= TOTAL_STEPS; i++) { 78 for (i = 0; i < adc_dev->channels; i++) {
66 tiadc_writel(adc_dev, REG_STEPCONFIG(i), 79 int chan;
67 stepconfig | STEPCONFIG_INP(channels)); 80
68 tiadc_writel(adc_dev, REG_STEPDELAY(i), 81 chan = adc_dev->channel_line[i];
82 tiadc_writel(adc_dev, REG_STEPCONFIG(steps),
83 stepconfig | STEPCONFIG_INP(chan));
84 tiadc_writel(adc_dev, REG_STEPDELAY(steps),
69 STEPCONFIG_OPENDLY); 85 STEPCONFIG_OPENDLY);
70 channels++; 86 adc_dev->channel_step[i] = steps;
87 steps++;
71 } 88 }
72 tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); 89 step_en = get_adc_step_mask(adc_dev);
90 am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
73} 91}
74 92
93static const char * const chan_name_ain[] = {
94 "AIN0",
95 "AIN1",
96 "AIN2",
97 "AIN3",
98 "AIN4",
99 "AIN5",
100 "AIN6",
101 "AIN7",
102};
103
75static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) 104static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
76{ 105{
106 struct tiadc_device *adc_dev = iio_priv(indio_dev);
77 struct iio_chan_spec *chan_array; 107 struct iio_chan_spec *chan_array;
108 struct iio_chan_spec *chan;
78 int i; 109 int i;
79 110
80 indio_dev->num_channels = channels; 111 indio_dev->num_channels = channels;
81 chan_array = kcalloc(indio_dev->num_channels, 112 chan_array = kcalloc(channels,
82 sizeof(struct iio_chan_spec), GFP_KERNEL); 113 sizeof(struct iio_chan_spec), GFP_KERNEL);
83
84 if (chan_array == NULL) 114 if (chan_array == NULL)
85 return -ENOMEM; 115 return -ENOMEM;
86 116
87 for (i = 0; i < (indio_dev->num_channels); i++) { 117 chan = chan_array;
88 struct iio_chan_spec *chan = chan_array + i; 118 for (i = 0; i < channels; i++, chan++) {
119
89 chan->type = IIO_VOLTAGE; 120 chan->type = IIO_VOLTAGE;
90 chan->indexed = 1; 121 chan->indexed = 1;
91 chan->channel = i; 122 chan->channel = adc_dev->channel_line[i];
92 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); 123 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
124 chan->datasheet_name = chan_name_ain[chan->channel];
125 chan->scan_type.sign = 'u';
126 chan->scan_type.realbits = 12;
127 chan->scan_type.storagebits = 32;
93 } 128 }
94 129
95 indio_dev->channels = chan_array; 130 indio_dev->channels = chan_array;
96 131
97 return indio_dev->num_channels; 132 return 0;
98} 133}
99 134
100static void tiadc_channels_remove(struct iio_dev *indio_dev) 135static void tiadc_channels_remove(struct iio_dev *indio_dev)
@@ -108,7 +143,9 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
108{ 143{
109 struct tiadc_device *adc_dev = iio_priv(indio_dev); 144 struct tiadc_device *adc_dev = iio_priv(indio_dev);
110 int i; 145 int i;
111 unsigned int fifo1count, readx1; 146 unsigned int fifo1count, read;
147 u32 step = UINT_MAX;
148 bool found = false;
112 149
113 /* 150 /*
114 * When the sub-system is first enabled, 151 * When the sub-system is first enabled,
@@ -121,14 +158,26 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
121 * Hence we need to flush out this data. 158 * Hence we need to flush out this data.
122 */ 159 */
123 160
161 for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) {
162 if (chan->channel == adc_dev->channel_line[i]) {
163 step = adc_dev->channel_step[i];
164 break;
165 }
166 }
167 if (WARN_ON_ONCE(step == UINT_MAX))
168 return -EINVAL;
169
124 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); 170 fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
125 for (i = 0; i < fifo1count; i++) { 171 for (i = 0; i < fifo1count; i++) {
126 readx1 = tiadc_readl(adc_dev, REG_FIFO1); 172 read = tiadc_readl(adc_dev, REG_FIFO1);
127 if (i == chan->channel) 173 if (read >> 16 == step) {
128 *val = readx1 & 0xfff; 174 *val = read & 0xfff;
175 found = true;
176 }
129 } 177 }
130 tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); 178 am335x_tsc_se_update(adc_dev->mfd_tscadc);
131 179 if (found == false)
180 return -EBUSY;
132 return IIO_VAL_INT; 181 return IIO_VAL_INT;
133} 182}
134 183
@@ -140,13 +189,15 @@ static int tiadc_probe(struct platform_device *pdev)
140{ 189{
141 struct iio_dev *indio_dev; 190 struct iio_dev *indio_dev;
142 struct tiadc_device *adc_dev; 191 struct tiadc_device *adc_dev;
143 struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; 192 struct device_node *node = pdev->dev.of_node;
144 struct mfd_tscadc_board *pdata; 193 struct property *prop;
194 const __be32 *cur;
145 int err; 195 int err;
196 u32 val;
197 int channels = 0;
146 198
147 pdata = tscadc_dev->dev->platform_data; 199 if (!node) {
148 if (!pdata || !pdata->adc_init) { 200 dev_err(&pdev->dev, "Could not find valid DT data.\n");
149 dev_err(&pdev->dev, "Could not find platform data\n");
150 return -EINVAL; 201 return -EINVAL;
151 } 202 }
152 203
@@ -158,8 +209,13 @@ static int tiadc_probe(struct platform_device *pdev)
158 } 209 }
159 adc_dev = iio_priv(indio_dev); 210 adc_dev = iio_priv(indio_dev);
160 211
161 adc_dev->mfd_tscadc = tscadc_dev; 212 adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
162 adc_dev->channels = pdata->adc_init->adc_channels; 213
214 of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
215 adc_dev->channel_line[channels] = val;
216 channels++;
217 }
218 adc_dev->channels = channels;
163 219
164 indio_dev->dev.parent = &pdev->dev; 220 indio_dev->dev.parent = &pdev->dev;
165 indio_dev->name = dev_name(&pdev->dev); 221 indio_dev->name = dev_name(&pdev->dev);
@@ -191,10 +247,15 @@ err_ret:
191static int tiadc_remove(struct platform_device *pdev) 247static int tiadc_remove(struct platform_device *pdev)
192{ 248{
193 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 249 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
250 struct tiadc_device *adc_dev = iio_priv(indio_dev);
251 u32 step_en;
194 252
195 iio_device_unregister(indio_dev); 253 iio_device_unregister(indio_dev);
196 tiadc_channels_remove(indio_dev); 254 tiadc_channels_remove(indio_dev);
197 255
256 step_en = get_adc_step_mask(adc_dev);
257 am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);
258
198 iio_device_free(indio_dev); 259 iio_device_free(indio_dev);
199 260
200 return 0; 261 return 0;
@@ -205,9 +266,10 @@ static int tiadc_suspend(struct device *dev)
205{ 266{
206 struct iio_dev *indio_dev = dev_get_drvdata(dev); 267 struct iio_dev *indio_dev = dev_get_drvdata(dev);
207 struct tiadc_device *adc_dev = iio_priv(indio_dev); 268 struct tiadc_device *adc_dev = iio_priv(indio_dev);
208 struct ti_tscadc_dev *tscadc_dev = dev->platform_data; 269 struct ti_tscadc_dev *tscadc_dev;
209 unsigned int idle; 270 unsigned int idle;
210 271
272 tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev));
211 if (!device_may_wakeup(tscadc_dev->dev)) { 273 if (!device_may_wakeup(tscadc_dev->dev)) {
212 idle = tiadc_readl(adc_dev, REG_CTRL); 274 idle = tiadc_readl(adc_dev, REG_CTRL);
213 idle &= ~(CNTRLREG_TSCSSENB); 275 idle &= ~(CNTRLREG_TSCSSENB);
@@ -243,16 +305,22 @@ static const struct dev_pm_ops tiadc_pm_ops = {
243#define TIADC_PM_OPS NULL 305#define TIADC_PM_OPS NULL
244#endif 306#endif
245 307
308static const struct of_device_id ti_adc_dt_ids[] = {
309 { .compatible = "ti,am3359-adc", },
310 { }
311};
312MODULE_DEVICE_TABLE(of, ti_adc_dt_ids);
313
246static struct platform_driver tiadc_driver = { 314static struct platform_driver tiadc_driver = {
247 .driver = { 315 .driver = {
248 .name = "tiadc", 316 .name = "TI-am335x-adc",
249 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
250 .pm = TIADC_PM_OPS, 318 .pm = TIADC_PM_OPS,
319 .of_match_table = of_match_ptr(ti_adc_dt_ids),
251 }, 320 },
252 .probe = tiadc_probe, 321 .probe = tiadc_probe,
253 .remove = tiadc_remove, 322 .remove = tiadc_remove,
254}; 323};
255
256module_platform_driver(tiadc_driver); 324module_platform_driver(tiadc_driver);
257 325
258MODULE_DESCRIPTION("TI ADC controller driver"); 326MODULE_DESCRIPTION("TI ADC controller driver");
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index 51e7b87827a4..0e9f02aeae6b 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -24,8 +24,9 @@
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/input/ti_am335x_tsc.h>
28#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/of.h>
29#include <linux/of_device.h>
29 30
30#include <linux/mfd/ti_am335x_tscadc.h> 31#include <linux/mfd/ti_am335x_tscadc.h>
31 32
@@ -33,6 +34,13 @@
33#define SEQ_SETTLE 275 34#define SEQ_SETTLE 275
34#define MAX_12BIT ((1 << 12) - 1) 35#define MAX_12BIT ((1 << 12) - 1)
35 36
37static const int config_pins[] = {
38 STEPCONFIG_XPP,
39 STEPCONFIG_XNN,
40 STEPCONFIG_YPP,
41 STEPCONFIG_YNN,
42};
43
36struct titsc { 44struct titsc {
37 struct input_dev *input; 45 struct input_dev *input;
38 struct ti_tscadc_dev *mfd_tscadc; 46 struct ti_tscadc_dev *mfd_tscadc;
@@ -40,7 +48,10 @@ struct titsc {
40 unsigned int wires; 48 unsigned int wires;
41 unsigned int x_plate_resistance; 49 unsigned int x_plate_resistance;
42 bool pen_down; 50 bool pen_down;
43 int steps_to_configure; 51 int coordinate_readouts;
52 u32 config_inp[4];
53 u32 bit_xp, bit_xn, bit_yp, bit_yn;
54 u32 inp_xp, inp_xn, inp_yp, inp_yn;
44}; 55};
45 56
46static unsigned int titsc_readl(struct titsc *ts, unsigned int reg) 57static unsigned int titsc_readl(struct titsc *ts, unsigned int reg)
@@ -54,92 +65,153 @@ static void titsc_writel(struct titsc *tsc, unsigned int reg,
54 writel(val, tsc->mfd_tscadc->tscadc_base + reg); 65 writel(val, tsc->mfd_tscadc->tscadc_base + reg);
55} 66}
56 67
68static int titsc_config_wires(struct titsc *ts_dev)
69{
70 u32 analog_line[4];
71 u32 wire_order[4];
72 int i, bit_cfg;
73
74 for (i = 0; i < 4; i++) {
75 /*
76 * Get the order in which TSC wires are attached
77 * w.r.t. each of the analog input lines on the EVM.
78 */
79 analog_line[i] = (ts_dev->config_inp[i] & 0xF0) >> 4;
80 wire_order[i] = ts_dev->config_inp[i] & 0x0F;
81 if (WARN_ON(analog_line[i] > 7))
82 return -EINVAL;
83 if (WARN_ON(wire_order[i] > ARRAY_SIZE(config_pins)))
84 return -EINVAL;
85 }
86
87 for (i = 0; i < 4; i++) {
88 int an_line;
89 int wi_order;
90
91 an_line = analog_line[i];
92 wi_order = wire_order[i];
93 bit_cfg = config_pins[wi_order];
94 if (bit_cfg == 0)
95 return -EINVAL;
96 switch (wi_order) {
97 case 0:
98 ts_dev->bit_xp = bit_cfg;
99 ts_dev->inp_xp = an_line;
100 break;
101
102 case 1:
103 ts_dev->bit_xn = bit_cfg;
104 ts_dev->inp_xn = an_line;
105 break;
106
107 case 2:
108 ts_dev->bit_yp = bit_cfg;
109 ts_dev->inp_yp = an_line;
110 break;
111 case 3:
112 ts_dev->bit_yn = bit_cfg;
113 ts_dev->inp_yn = an_line;
114 break;
115 }
116 }
117 return 0;
118}
119
57static void titsc_step_config(struct titsc *ts_dev) 120static void titsc_step_config(struct titsc *ts_dev)
58{ 121{
59 unsigned int config; 122 unsigned int config;
60 int i, total_steps; 123 int i;
61 124 int end_step;
62 /* Configure the Step registers */ 125 u32 stepenable;
63 total_steps = 2 * ts_dev->steps_to_configure;
64 126
65 config = STEPCONFIG_MODE_HWSYNC | 127 config = STEPCONFIG_MODE_HWSYNC |
66 STEPCONFIG_AVG_16 | STEPCONFIG_XPP; 128 STEPCONFIG_AVG_16 | ts_dev->bit_xp;
67 switch (ts_dev->wires) { 129 switch (ts_dev->wires) {
68 case 4: 130 case 4:
69 config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN; 131 config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
70 break; 132 break;
71 case 5: 133 case 5:
72 config |= STEPCONFIG_YNN | 134 config |= ts_dev->bit_yn |
73 STEPCONFIG_INP_AN4 | STEPCONFIG_XNN | 135 STEPCONFIG_INP_AN4 | ts_dev->bit_xn |
74 STEPCONFIG_YPP; 136 ts_dev->bit_yp;
75 break; 137 break;
76 case 8: 138 case 8:
77 config |= STEPCONFIG_INP_AN2 | STEPCONFIG_XNN; 139 config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn;
78 break; 140 break;
79 } 141 }
80 142
81 for (i = 1; i <= ts_dev->steps_to_configure; i++) { 143 /* 1 … coordinate_readouts is for X */
144 end_step = ts_dev->coordinate_readouts;
145 for (i = 0; i < end_step; i++) {
82 titsc_writel(ts_dev, REG_STEPCONFIG(i), config); 146 titsc_writel(ts_dev, REG_STEPCONFIG(i), config);
83 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY); 147 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
84 } 148 }
85 149
86 config = 0; 150 config = 0;
87 config = STEPCONFIG_MODE_HWSYNC | 151 config = STEPCONFIG_MODE_HWSYNC |
88 STEPCONFIG_AVG_16 | STEPCONFIG_YNN | 152 STEPCONFIG_AVG_16 | ts_dev->bit_yn |
89 STEPCONFIG_INM_ADCREFM | STEPCONFIG_FIFO1; 153 STEPCONFIG_INM_ADCREFM;
90 switch (ts_dev->wires) { 154 switch (ts_dev->wires) {
91 case 4: 155 case 4:
92 config |= STEPCONFIG_YPP; 156 config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
93 break; 157 break;
94 case 5: 158 case 5:
95 config |= STEPCONFIG_XPP | STEPCONFIG_INP_AN4 | 159 config |= ts_dev->bit_xp | STEPCONFIG_INP_AN4 |
96 STEPCONFIG_XNP | STEPCONFIG_YPN; 160 ts_dev->bit_xn | ts_dev->bit_yp;
97 break; 161 break;
98 case 8: 162 case 8:
99 config |= STEPCONFIG_YPP; 163 config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp);
100 break; 164 break;
101 } 165 }
102 166
103 for (i = (ts_dev->steps_to_configure + 1); i <= total_steps; i++) { 167 /* coordinate_readouts … coordinate_readouts * 2 is for Y */
168 end_step = ts_dev->coordinate_readouts * 2;
169 for (i = ts_dev->coordinate_readouts; i < end_step; i++) {
104 titsc_writel(ts_dev, REG_STEPCONFIG(i), config); 170 titsc_writel(ts_dev, REG_STEPCONFIG(i), config);
105 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY); 171 titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY);
106 } 172 }
107 173
108 config = 0;
109 /* Charge step configuration */ 174 /* Charge step configuration */
110 config = STEPCONFIG_XPP | STEPCONFIG_YNN | 175 config = ts_dev->bit_xp | ts_dev->bit_yn |
111 STEPCHARGE_RFP_XPUL | STEPCHARGE_RFM_XNUR | 176 STEPCHARGE_RFP_XPUL | STEPCHARGE_RFM_XNUR |
112 STEPCHARGE_INM_AN1 | STEPCHARGE_INP_AN1; 177 STEPCHARGE_INM_AN1 | STEPCHARGE_INP(ts_dev->inp_yp);
113 178
114 titsc_writel(ts_dev, REG_CHARGECONFIG, config); 179 titsc_writel(ts_dev, REG_CHARGECONFIG, config);
115 titsc_writel(ts_dev, REG_CHARGEDELAY, CHARGEDLY_OPENDLY); 180 titsc_writel(ts_dev, REG_CHARGEDELAY, CHARGEDLY_OPENDLY);
116 181
117 config = 0; 182 /* coordinate_readouts * 2 … coordinate_readouts * 2 + 2 is for Z */
118 /* Configure to calculate pressure */
119 config = STEPCONFIG_MODE_HWSYNC | 183 config = STEPCONFIG_MODE_HWSYNC |
120 STEPCONFIG_AVG_16 | STEPCONFIG_YPP | 184 STEPCONFIG_AVG_16 | ts_dev->bit_yp |
121 STEPCONFIG_XNN | STEPCONFIG_INM_ADCREFM; 185 ts_dev->bit_xn | STEPCONFIG_INM_ADCREFM |
122 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 1), config); 186 STEPCONFIG_INP(ts_dev->inp_xp);
123 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 1), 187 titsc_writel(ts_dev, REG_STEPCONFIG(end_step), config);
188 titsc_writel(ts_dev, REG_STEPDELAY(end_step),
124 STEPCONFIG_OPENDLY); 189 STEPCONFIG_OPENDLY);
125 190
126 config |= STEPCONFIG_INP_AN3 | STEPCONFIG_FIFO1; 191 end_step++;
127 titsc_writel(ts_dev, REG_STEPCONFIG(total_steps + 2), config); 192 config |= STEPCONFIG_INP(ts_dev->inp_yn);
128 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2), 193 titsc_writel(ts_dev, REG_STEPCONFIG(end_step), config);
194 titsc_writel(ts_dev, REG_STEPDELAY(end_step),
129 STEPCONFIG_OPENDLY); 195 STEPCONFIG_OPENDLY);
130 196
131 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC); 197 /* The steps1 … end and bit 0 for TS_Charge */
198 stepenable = (1 << (end_step + 2)) - 1;
199 am335x_tsc_se_set(ts_dev->mfd_tscadc, stepenable);
132} 200}
133 201
134static void titsc_read_coordinates(struct titsc *ts_dev, 202static void titsc_read_coordinates(struct titsc *ts_dev,
135 unsigned int *x, unsigned int *y) 203 u32 *x, u32 *y, u32 *z1, u32 *z2)
136{ 204{
137 unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT); 205 unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT);
138 unsigned int prev_val_x = ~0, prev_val_y = ~0; 206 unsigned int prev_val_x = ~0, prev_val_y = ~0;
139 unsigned int prev_diff_x = ~0, prev_diff_y = ~0; 207 unsigned int prev_diff_x = ~0, prev_diff_y = ~0;
140 unsigned int read, diff; 208 unsigned int read, diff;
141 unsigned int i, channel; 209 unsigned int i, channel;
210 unsigned int creads = ts_dev->coordinate_readouts;
142 211
212 *z1 = *z2 = 0;
213 if (fifocount % (creads * 2 + 2))
214 fifocount -= fifocount % (creads * 2 + 2);
143 /* 215 /*
144 * Delta filter is used to remove large variations in sampled 216 * Delta filter is used to remove large variations in sampled
145 * values from ADC. The filter tries to predict where the next 217 * values from ADC. The filter tries to predict where the next
@@ -148,32 +220,32 @@ static void titsc_read_coordinates(struct titsc *ts_dev,
148 * algorithm compares the difference with that of a present value, 220 * algorithm compares the difference with that of a present value,
149 * if true the value is reported to the sub system. 221 * if true the value is reported to the sub system.
150 */ 222 */
151 for (i = 0; i < fifocount - 1; i++) { 223 for (i = 0; i < fifocount; i++) {
152 read = titsc_readl(ts_dev, REG_FIFO0); 224 read = titsc_readl(ts_dev, REG_FIFO0);
153 channel = read & 0xf0000; 225
154 channel = channel >> 0x10; 226 channel = (read & 0xf0000) >> 16;
155 if ((channel >= 0) && (channel < ts_dev->steps_to_configure)) { 227 read &= 0xfff;
156 read &= 0xfff; 228 if (channel < creads) {
157 diff = abs(read - prev_val_x); 229 diff = abs(read - prev_val_x);
158 if (diff < prev_diff_x) { 230 if (diff < prev_diff_x) {
159 prev_diff_x = diff; 231 prev_diff_x = diff;
160 *x = read; 232 *x = read;
161 } 233 }
162 prev_val_x = read; 234 prev_val_x = read;
163 }
164 235
165 read = titsc_readl(ts_dev, REG_FIFO1); 236 } else if (channel < creads * 2) {
166 channel = read & 0xf0000;
167 channel = channel >> 0x10;
168 if ((channel >= ts_dev->steps_to_configure) &&
169 (channel < (2 * ts_dev->steps_to_configure - 1))) {
170 read &= 0xfff;
171 diff = abs(read - prev_val_y); 237 diff = abs(read - prev_val_y);
172 if (diff < prev_diff_y) { 238 if (diff < prev_diff_y) {
173 prev_diff_y = diff; 239 prev_diff_y = diff;
174 *y = read; 240 *y = read;
175 } 241 }
176 prev_val_y = read; 242 prev_val_y = read;
243
244 } else if (channel < creads * 2 + 1) {
245 *z1 = read;
246
247 } else if (channel < creads * 2 + 2) {
248 *z2 = read;
177 } 249 }
178 } 250 }
179} 251}
@@ -186,23 +258,11 @@ static irqreturn_t titsc_irq(int irq, void *dev)
186 unsigned int x = 0, y = 0; 258 unsigned int x = 0, y = 0;
187 unsigned int z1, z2, z; 259 unsigned int z1, z2, z;
188 unsigned int fsm; 260 unsigned int fsm;
189 unsigned int fifo1count, fifo0count;
190 int i;
191 261
192 status = titsc_readl(ts_dev, REG_IRQSTATUS); 262 status = titsc_readl(ts_dev, REG_IRQSTATUS);
193 if (status & IRQENB_FIFO0THRES) { 263 if (status & IRQENB_FIFO0THRES) {
194 titsc_read_coordinates(ts_dev, &x, &y);
195 264
196 z1 = titsc_readl(ts_dev, REG_FIFO0) & 0xfff; 265 titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2);
197 z2 = titsc_readl(ts_dev, REG_FIFO1) & 0xfff;
198
199 fifo1count = titsc_readl(ts_dev, REG_FIFO1CNT);
200 for (i = 0; i < fifo1count; i++)
201 titsc_readl(ts_dev, REG_FIFO1);
202
203 fifo0count = titsc_readl(ts_dev, REG_FIFO0CNT);
204 for (i = 0; i < fifo0count; i++)
205 titsc_readl(ts_dev, REG_FIFO0);
206 266
207 if (ts_dev->pen_down && z1 != 0 && z2 != 0) { 267 if (ts_dev->pen_down && z1 != 0 && z2 != 0) {
208 /* 268 /*
@@ -210,10 +270,10 @@ static irqreturn_t titsc_irq(int irq, void *dev)
210 * Resistance(touch) = x plate resistance * 270 * Resistance(touch) = x plate resistance *
211 * x postion/4096 * ((z2 / z1) - 1) 271 * x postion/4096 * ((z2 / z1) - 1)
212 */ 272 */
213 z = z2 - z1; 273 z = z1 - z2;
214 z *= x; 274 z *= x;
215 z *= ts_dev->x_plate_resistance; 275 z *= ts_dev->x_plate_resistance;
216 z /= z1; 276 z /= z2;
217 z = (z + 2047) >> 12; 277 z = (z + 2047) >> 12;
218 278
219 if (z <= MAX_12BIT) { 279 if (z <= MAX_12BIT) {
@@ -248,10 +308,53 @@ static irqreturn_t titsc_irq(int irq, void *dev)
248 irqclr |= IRQENB_PENUP; 308 irqclr |= IRQENB_PENUP;
249 } 309 }
250 310
251 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr); 311 if (status & IRQENB_HW_PEN) {
312
313 titsc_writel(ts_dev, REG_IRQWAKEUP, 0x00);
314 titsc_writel(ts_dev, REG_IRQCLR, IRQENB_HW_PEN);
315 }
252 316
253 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC); 317 if (irqclr) {
254 return IRQ_HANDLED; 318 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
319 am335x_tsc_se_update(ts_dev->mfd_tscadc);
320 return IRQ_HANDLED;
321 }
322 return IRQ_NONE;
323}
324
325static int titsc_parse_dt(struct platform_device *pdev,
326 struct titsc *ts_dev)
327{
328 struct device_node *node = pdev->dev.of_node;
329 int err;
330
331 if (!node)
332 return -EINVAL;
333
334 err = of_property_read_u32(node, "ti,wires", &ts_dev->wires);
335 if (err < 0)
336 return err;
337 switch (ts_dev->wires) {
338 case 4:
339 case 5:
340 case 8:
341 break;
342 default:
343 return -EINVAL;
344 }
345
346 err = of_property_read_u32(node, "ti,x-plate-resistance",
347 &ts_dev->x_plate_resistance);
348 if (err < 0)
349 return err;
350
351 err = of_property_read_u32(node, "ti,coordiante-readouts",
352 &ts_dev->coordinate_readouts);
353 if (err < 0)
354 return err;
355
356 return of_property_read_u32_array(node, "ti,wire-config",
357 ts_dev->config_inp, ARRAY_SIZE(ts_dev->config_inp));
255} 358}
256 359
257/* 360/*
@@ -262,17 +365,9 @@ static int titsc_probe(struct platform_device *pdev)
262{ 365{
263 struct titsc *ts_dev; 366 struct titsc *ts_dev;
264 struct input_dev *input_dev; 367 struct input_dev *input_dev;
265 struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; 368 struct ti_tscadc_dev *tscadc_dev = ti_tscadc_dev_get(pdev);
266 struct mfd_tscadc_board *pdata;
267 int err; 369 int err;
268 370
269 pdata = tscadc_dev->dev->platform_data;
270
271 if (!pdata) {
272 dev_err(&pdev->dev, "Could not find platform data\n");
273 return -EINVAL;
274 }
275
276 /* Allocate memory for device */ 371 /* Allocate memory for device */
277 ts_dev = kzalloc(sizeof(struct titsc), GFP_KERNEL); 372 ts_dev = kzalloc(sizeof(struct titsc), GFP_KERNEL);
278 input_dev = input_allocate_device(); 373 input_dev = input_allocate_device();
@@ -286,9 +381,12 @@ static int titsc_probe(struct platform_device *pdev)
286 ts_dev->mfd_tscadc = tscadc_dev; 381 ts_dev->mfd_tscadc = tscadc_dev;
287 ts_dev->input = input_dev; 382 ts_dev->input = input_dev;
288 ts_dev->irq = tscadc_dev->irq; 383 ts_dev->irq = tscadc_dev->irq;
289 ts_dev->wires = pdata->tsc_init->wires; 384
290 ts_dev->x_plate_resistance = pdata->tsc_init->x_plate_resistance; 385 err = titsc_parse_dt(pdev, ts_dev);
291 ts_dev->steps_to_configure = pdata->tsc_init->steps_to_configure; 386 if (err) {
387 dev_err(&pdev->dev, "Could not find valid DT data.\n");
388 goto err_free_mem;
389 }
292 390
293 err = request_irq(ts_dev->irq, titsc_irq, 391 err = request_irq(ts_dev->irq, titsc_irq,
294 0, pdev->dev.driver->name, ts_dev); 392 0, pdev->dev.driver->name, ts_dev);
@@ -298,8 +396,14 @@ static int titsc_probe(struct platform_device *pdev)
298 } 396 }
299 397
300 titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES); 398 titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
399 err = titsc_config_wires(ts_dev);
400 if (err) {
401 dev_err(&pdev->dev, "wrong i/p wire configuration\n");
402 goto err_free_irq;
403 }
301 titsc_step_config(ts_dev); 404 titsc_step_config(ts_dev);
302 titsc_writel(ts_dev, REG_FIFO0THR, ts_dev->steps_to_configure); 405 titsc_writel(ts_dev, REG_FIFO0THR,
406 ts_dev->coordinate_readouts * 2 + 2 - 1);
303 407
304 input_dev->name = "ti-tsc"; 408 input_dev->name = "ti-tsc";
305 input_dev->dev.parent = &pdev->dev; 409 input_dev->dev.parent = &pdev->dev;
@@ -329,11 +433,16 @@ err_free_mem:
329 433
330static int titsc_remove(struct platform_device *pdev) 434static int titsc_remove(struct platform_device *pdev)
331{ 435{
332 struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; 436 struct titsc *ts_dev = platform_get_drvdata(pdev);
333 struct titsc *ts_dev = tscadc_dev->tsc; 437 u32 steps;
334 438
335 free_irq(ts_dev->irq, ts_dev); 439 free_irq(ts_dev->irq, ts_dev);
336 440
441 /* total steps followed by the enable mask */
442 steps = 2 * ts_dev->coordinate_readouts + 2;
443 steps = (1 << steps) - 1;
444 am335x_tsc_se_clr(ts_dev->mfd_tscadc, steps);
445
337 input_unregister_device(ts_dev->input); 446 input_unregister_device(ts_dev->input);
338 447
339 platform_set_drvdata(pdev, NULL); 448 platform_set_drvdata(pdev, NULL);
@@ -344,10 +453,11 @@ static int titsc_remove(struct platform_device *pdev)
344#ifdef CONFIG_PM 453#ifdef CONFIG_PM
345static int titsc_suspend(struct device *dev) 454static int titsc_suspend(struct device *dev)
346{ 455{
347 struct ti_tscadc_dev *tscadc_dev = dev->platform_data; 456 struct titsc *ts_dev = dev_get_drvdata(dev);
348 struct titsc *ts_dev = tscadc_dev->tsc; 457 struct ti_tscadc_dev *tscadc_dev;
349 unsigned int idle; 458 unsigned int idle;
350 459
460 tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev));
351 if (device_may_wakeup(tscadc_dev->dev)) { 461 if (device_may_wakeup(tscadc_dev->dev)) {
352 idle = titsc_readl(ts_dev, REG_IRQENABLE); 462 idle = titsc_readl(ts_dev, REG_IRQENABLE);
353 titsc_writel(ts_dev, REG_IRQENABLE, 463 titsc_writel(ts_dev, REG_IRQENABLE,
@@ -359,9 +469,10 @@ static int titsc_suspend(struct device *dev)
359 469
360static int titsc_resume(struct device *dev) 470static int titsc_resume(struct device *dev)
361{ 471{
362 struct ti_tscadc_dev *tscadc_dev = dev->platform_data; 472 struct titsc *ts_dev = dev_get_drvdata(dev);
363 struct titsc *ts_dev = tscadc_dev->tsc; 473 struct ti_tscadc_dev *tscadc_dev;
364 474
475 tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev));
365 if (device_may_wakeup(tscadc_dev->dev)) { 476 if (device_may_wakeup(tscadc_dev->dev)) {
366 titsc_writel(ts_dev, REG_IRQWAKEUP, 477 titsc_writel(ts_dev, REG_IRQWAKEUP,
367 0x00); 478 0x00);
@@ -369,7 +480,7 @@ static int titsc_resume(struct device *dev)
369 } 480 }
370 titsc_step_config(ts_dev); 481 titsc_step_config(ts_dev);
371 titsc_writel(ts_dev, REG_FIFO0THR, 482 titsc_writel(ts_dev, REG_FIFO0THR,
372 ts_dev->steps_to_configure); 483 ts_dev->coordinate_readouts * 2 + 2 - 1);
373 return 0; 484 return 0;
374} 485}
375 486
@@ -382,13 +493,20 @@ static const struct dev_pm_ops titsc_pm_ops = {
382#define TITSC_PM_OPS NULL 493#define TITSC_PM_OPS NULL
383#endif 494#endif
384 495
496static const struct of_device_id ti_tsc_dt_ids[] = {
497 { .compatible = "ti,am3359-tsc", },
498 { }
499};
500MODULE_DEVICE_TABLE(of, ti_tsc_dt_ids);
501
385static struct platform_driver ti_tsc_driver = { 502static struct platform_driver ti_tsc_driver = {
386 .probe = titsc_probe, 503 .probe = titsc_probe,
387 .remove = titsc_remove, 504 .remove = titsc_remove,
388 .driver = { 505 .driver = {
389 .name = "tsc", 506 .name = "TI-am335x-tsc",
390 .owner = THIS_MODULE, 507 .owner = THIS_MODULE,
391 .pm = TITSC_PM_OPS, 508 .pm = TITSC_PM_OPS,
509 .of_match_table = of_match_ptr(ti_tsc_dt_ids),
392 }, 510 },
393}; 511};
394module_platform_driver(ti_tsc_driver); 512module_platform_driver(ti_tsc_driver);
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index e9f3fb510b44..b003a16ba227 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -22,10 +22,10 @@
22#include <linux/regmap.h> 22#include <linux/regmap.h>
23#include <linux/mfd/core.h> 23#include <linux/mfd/core.h>
24#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
25#include <linux/of.h>
26#include <linux/of_device.h>
25 27
26#include <linux/mfd/ti_am335x_tscadc.h> 28#include <linux/mfd/ti_am335x_tscadc.h>
27#include <linux/input/ti_am335x_tsc.h>
28#include <linux/platform_data/ti_am335x_adc.h>
29 29
30static unsigned int tscadc_readl(struct ti_tscadc_dev *tsadc, unsigned int reg) 30static unsigned int tscadc_readl(struct ti_tscadc_dev *tsadc, unsigned int reg)
31{ 31{
@@ -48,6 +48,32 @@ static const struct regmap_config tscadc_regmap_config = {
48 .val_bits = 32, 48 .val_bits = 32,
49}; 49};
50 50
51void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc)
52{
53 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
54}
55EXPORT_SYMBOL_GPL(am335x_tsc_se_update);
56
57void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val)
58{
59 spin_lock(&tsadc->reg_lock);
60 tsadc->reg_se_cache |= val;
61 spin_unlock(&tsadc->reg_lock);
62
63 am335x_tsc_se_update(tsadc);
64}
65EXPORT_SYMBOL_GPL(am335x_tsc_se_set);
66
67void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
68{
69 spin_lock(&tsadc->reg_lock);
70 tsadc->reg_se_cache &= ~val;
71 spin_unlock(&tsadc->reg_lock);
72
73 am335x_tsc_se_update(tsadc);
74}
75EXPORT_SYMBOL_GPL(am335x_tsc_se_clr);
76
51static void tscadc_idle_config(struct ti_tscadc_dev *config) 77static void tscadc_idle_config(struct ti_tscadc_dev *config)
52{ 78{
53 unsigned int idleconfig; 79 unsigned int idleconfig;
@@ -63,27 +89,48 @@ static int ti_tscadc_probe(struct platform_device *pdev)
63 struct ti_tscadc_dev *tscadc; 89 struct ti_tscadc_dev *tscadc;
64 struct resource *res; 90 struct resource *res;
65 struct clk *clk; 91 struct clk *clk;
66 struct mfd_tscadc_board *pdata = pdev->dev.platform_data; 92 struct device_node *node = pdev->dev.of_node;
67 struct mfd_cell *cell; 93 struct mfd_cell *cell;
94 struct property *prop;
95 const __be32 *cur;
96 u32 val;
68 int err, ctrl; 97 int err, ctrl;
69 int clk_value, clock_rate; 98 int clk_value, clock_rate;
70 int tsc_wires, adc_channels = 0, total_channels; 99 int tsc_wires = 0, adc_channels = 0, total_channels;
100 int readouts = 0;
71 101
72 if (!pdata) { 102 if (!pdev->dev.of_node) {
73 dev_err(&pdev->dev, "Could not find platform data\n"); 103 dev_err(&pdev->dev, "Could not find valid DT data.\n");
74 return -EINVAL; 104 return -EINVAL;
75 } 105 }
76 106
77 if (pdata->adc_init) 107 node = of_get_child_by_name(pdev->dev.of_node, "tsc");
78 adc_channels = pdata->adc_init->adc_channels; 108 of_property_read_u32(node, "ti,wires", &tsc_wires);
79 109 of_property_read_u32(node, "ti,coordiante-readouts", &readouts);
80 tsc_wires = pdata->tsc_init->wires; 110
111 node = of_get_child_by_name(pdev->dev.of_node, "adc");
112 of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
113 adc_channels++;
114 if (val > 7) {
115 dev_err(&pdev->dev, " PIN numbers are 0..7 (not %d)\n",
116 val);
117 return -EINVAL;
118 }
119 }
81 total_channels = tsc_wires + adc_channels; 120 total_channels = tsc_wires + adc_channels;
82
83 if (total_channels > 8) { 121 if (total_channels > 8) {
84 dev_err(&pdev->dev, "Number of i/p channels more than 8\n"); 122 dev_err(&pdev->dev, "Number of i/p channels more than 8\n");
85 return -EINVAL; 123 return -EINVAL;
86 } 124 }
125 if (total_channels == 0) {
126 dev_err(&pdev->dev, "Need atleast one channel.\n");
127 return -EINVAL;
128 }
129
130 if (readouts * 2 + 2 + adc_channels > 16) {
131 dev_err(&pdev->dev, "Too many step configurations requested\n");
132 return -EINVAL;
133 }
87 134
88 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
89 if (!res) { 136 if (!res) {
@@ -129,6 +176,7 @@ static int ti_tscadc_probe(struct platform_device *pdev)
129 goto ret; 176 goto ret;
130 } 177 }
131 178
179 spin_lock_init(&tscadc->reg_lock);
132 pm_runtime_enable(&pdev->dev); 180 pm_runtime_enable(&pdev->dev);
133 pm_runtime_get_sync(&pdev->dev); 181 pm_runtime_get_sync(&pdev->dev);
134 182
@@ -173,26 +221,37 @@ static int ti_tscadc_probe(struct platform_device *pdev)
173 ctrl |= CNTRLREG_TSCSSENB; 221 ctrl |= CNTRLREG_TSCSSENB;
174 tscadc_writel(tscadc, REG_CTRL, ctrl); 222 tscadc_writel(tscadc, REG_CTRL, ctrl);
175 223
224 tscadc->used_cells = 0;
225 tscadc->tsc_cell = -1;
226 tscadc->adc_cell = -1;
227
176 /* TSC Cell */ 228 /* TSC Cell */
177 cell = &tscadc->cells[TSC_CELL]; 229 if (tsc_wires > 0) {
178 cell->name = "tsc"; 230 tscadc->tsc_cell = tscadc->used_cells;
179 cell->platform_data = tscadc; 231 cell = &tscadc->cells[tscadc->used_cells++];
180 cell->pdata_size = sizeof(*tscadc); 232 cell->name = "TI-am335x-tsc";
233 cell->of_compatible = "ti,am3359-tsc";
234 cell->platform_data = &tscadc;
235 cell->pdata_size = sizeof(tscadc);
236 }
181 237
182 /* ADC Cell */ 238 /* ADC Cell */
183 cell = &tscadc->cells[ADC_CELL]; 239 if (adc_channels > 0) {
184 cell->name = "tiadc"; 240 tscadc->adc_cell = tscadc->used_cells;
185 cell->platform_data = tscadc; 241 cell = &tscadc->cells[tscadc->used_cells++];
186 cell->pdata_size = sizeof(*tscadc); 242 cell->name = "TI-am335x-adc";
243 cell->of_compatible = "ti,am3359-adc";
244 cell->platform_data = &tscadc;
245 cell->pdata_size = sizeof(tscadc);
246 }
187 247
188 err = mfd_add_devices(&pdev->dev, pdev->id, tscadc->cells, 248 err = mfd_add_devices(&pdev->dev, pdev->id, tscadc->cells,
189 TSCADC_CELLS, NULL, 0, NULL); 249 tscadc->used_cells, NULL, 0, NULL);
190 if (err < 0) 250 if (err < 0)
191 goto err_disable_clk; 251 goto err_disable_clk;
192 252
193 device_init_wakeup(&pdev->dev, true); 253 device_init_wakeup(&pdev->dev, true);
194 platform_set_drvdata(pdev, tscadc); 254 platform_set_drvdata(pdev, tscadc);
195
196 return 0; 255 return 0;
197 256
198err_disable_clk: 257err_disable_clk:
@@ -239,7 +298,7 @@ static int tscadc_resume(struct device *dev)
239 CNTRLREG_STEPID | CNTRLREG_4WIRE; 298 CNTRLREG_STEPID | CNTRLREG_4WIRE;
240 tscadc_writel(tscadc_dev, REG_CTRL, ctrl); 299 tscadc_writel(tscadc_dev, REG_CTRL, ctrl);
241 tscadc_idle_config(tscadc_dev); 300 tscadc_idle_config(tscadc_dev);
242 tscadc_writel(tscadc_dev, REG_SE, STPENB_STEPENB); 301 am335x_tsc_se_update(tscadc_dev);
243 restore = tscadc_readl(tscadc_dev, REG_CTRL); 302 restore = tscadc_readl(tscadc_dev, REG_CTRL);
244 tscadc_writel(tscadc_dev, REG_CTRL, 303 tscadc_writel(tscadc_dev, REG_CTRL,
245 (restore | CNTRLREG_TSCSSENB)); 304 (restore | CNTRLREG_TSCSSENB));
@@ -256,11 +315,18 @@ static const struct dev_pm_ops tscadc_pm_ops = {
256#define TSCADC_PM_OPS NULL 315#define TSCADC_PM_OPS NULL
257#endif 316#endif
258 317
318static const struct of_device_id ti_tscadc_dt_ids[] = {
319 { .compatible = "ti,am3359-tscadc", },
320 { }
321};
322MODULE_DEVICE_TABLE(of, ti_tscadc_dt_ids);
323
259static struct platform_driver ti_tscadc_driver = { 324static struct platform_driver ti_tscadc_driver = {
260 .driver = { 325 .driver = {
261 .name = "ti_tscadc", 326 .name = "ti_am3359-tscadc",
262 .owner = THIS_MODULE, 327 .owner = THIS_MODULE,
263 .pm = TSCADC_PM_OPS, 328 .pm = TSCADC_PM_OPS,
329 .of_match_table = of_match_ptr(ti_tscadc_dt_ids),
264 }, 330 },
265 .probe = ti_tscadc_probe, 331 .probe = ti_tscadc_probe,
266 .remove = ti_tscadc_remove, 332 .remove = ti_tscadc_remove,
diff --git a/include/linux/input/ti_am335x_tsc.h b/include/linux/input/ti_am335x_tsc.h
deleted file mode 100644
index 49269a2aa329..000000000000
--- a/include/linux/input/ti_am335x_tsc.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef __LINUX_TI_AM335X_TSC_H
2#define __LINUX_TI_AM335X_TSC_H
3
4/**
5 * struct tsc_data Touchscreen wire configuration
6 * @wires: Wires refer to application modes
7 * i.e. 4/5/8 wire touchscreen support
8 * on the platform.
9 * @x_plate_resistance: X plate resistance.
10 * @steps_to_configure: The sequencer supports a total of
11 * 16 programmable steps.
12 * A step configured to read a single
13 * co-ordinate value, can be applied
14 * more number of times for better results.
15 */
16
17struct tsc_data {
18 int wires;
19 int x_plate_resistance;
20 int steps_to_configure;
21};
22
23#endif
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index c79ad5d2f271..8d73fe29796a 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -30,8 +30,8 @@
30#define REG_IDLECONFIG 0x058 30#define REG_IDLECONFIG 0x058
31#define REG_CHARGECONFIG 0x05C 31#define REG_CHARGECONFIG 0x05C
32#define REG_CHARGEDELAY 0x060 32#define REG_CHARGEDELAY 0x060
33#define REG_STEPCONFIG(n) (0x64 + ((n - 1) * 8)) 33#define REG_STEPCONFIG(n) (0x64 + ((n) * 8))
34#define REG_STEPDELAY(n) (0x68 + ((n - 1) * 8)) 34#define REG_STEPDELAY(n) (0x68 + ((n) * 8))
35#define REG_FIFO0CNT 0xE4 35#define REG_FIFO0CNT 0xE4
36#define REG_FIFO0THR 0xE8 36#define REG_FIFO0THR 0xE8
37#define REG_FIFO1CNT 0xF0 37#define REG_FIFO1CNT 0xF0
@@ -46,8 +46,6 @@
46/* Step Enable */ 46/* Step Enable */
47#define STEPENB_MASK (0x1FFFF << 0) 47#define STEPENB_MASK (0x1FFFF << 0)
48#define STEPENB(val) ((val) << 0) 48#define STEPENB(val) ((val) << 0)
49#define STPENB_STEPENB STEPENB(0x1FFFF)
50#define STPENB_STEPENB_TC STEPENB(0x1FFF)
51 49
52/* IRQ enable */ 50/* IRQ enable */
53#define IRQENB_HW_PEN BIT(0) 51#define IRQENB_HW_PEN BIT(0)
@@ -73,8 +71,6 @@
73#define STEPCONFIG_INM_ADCREFM STEPCONFIG_INM(8) 71#define STEPCONFIG_INM_ADCREFM STEPCONFIG_INM(8)
74#define STEPCONFIG_INP_MASK (0xF << 19) 72#define STEPCONFIG_INP_MASK (0xF << 19)
75#define STEPCONFIG_INP(val) ((val) << 19) 73#define STEPCONFIG_INP(val) ((val) << 19)
76#define STEPCONFIG_INP_AN2 STEPCONFIG_INP(2)
77#define STEPCONFIG_INP_AN3 STEPCONFIG_INP(3)
78#define STEPCONFIG_INP_AN4 STEPCONFIG_INP(4) 74#define STEPCONFIG_INP_AN4 STEPCONFIG_INP(4)
79#define STEPCONFIG_INP_ADCREFM STEPCONFIG_INP(8) 75#define STEPCONFIG_INP_ADCREFM STEPCONFIG_INP(8)
80#define STEPCONFIG_FIFO1 BIT(26) 76#define STEPCONFIG_FIFO1 BIT(26)
@@ -96,7 +92,6 @@
96#define STEPCHARGE_INM_AN1 STEPCHARGE_INM(1) 92#define STEPCHARGE_INM_AN1 STEPCHARGE_INM(1)
97#define STEPCHARGE_INP_MASK (0xF << 19) 93#define STEPCHARGE_INP_MASK (0xF << 19)
98#define STEPCHARGE_INP(val) ((val) << 19) 94#define STEPCHARGE_INP(val) ((val) << 19)
99#define STEPCHARGE_INP_AN1 STEPCHARGE_INP(1)
100#define STEPCHARGE_RFM_MASK (3 << 23) 95#define STEPCHARGE_RFM_MASK (3 << 23)
101#define STEPCHARGE_RFM(val) ((val) << 23) 96#define STEPCHARGE_RFM(val) ((val) << 23)
102#define STEPCHARGE_RFM_XNUR STEPCHARGE_RFM(1) 97#define STEPCHARGE_RFM_XNUR STEPCHARGE_RFM(1)
@@ -125,22 +120,17 @@
125 120
126#define TSCADC_CELLS 2 121#define TSCADC_CELLS 2
127 122
128enum tscadc_cells {
129 TSC_CELL,
130 ADC_CELL,
131};
132
133struct mfd_tscadc_board {
134 struct tsc_data *tsc_init;
135 struct adc_data *adc_init;
136};
137
138struct ti_tscadc_dev { 123struct ti_tscadc_dev {
139 struct device *dev; 124 struct device *dev;
140 struct regmap *regmap_tscadc; 125 struct regmap *regmap_tscadc;
141 void __iomem *tscadc_base; 126 void __iomem *tscadc_base;
142 int irq; 127 int irq;
128 int used_cells; /* 1-2 */
129 int tsc_cell; /* -1 if not used */
130 int adc_cell; /* -1 if not used */
143 struct mfd_cell cells[TSCADC_CELLS]; 131 struct mfd_cell cells[TSCADC_CELLS];
132 u32 reg_se_cache;
133 spinlock_t reg_lock;
144 134
145 /* tsc device */ 135 /* tsc device */
146 struct titsc *tsc; 136 struct titsc *tsc;
@@ -149,4 +139,15 @@ struct ti_tscadc_dev {
149 struct adc_device *adc; 139 struct adc_device *adc;
150}; 140};
151 141
142static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
143{
144 struct ti_tscadc_dev **tscadc_dev = p->dev.platform_data;
145
146 return *tscadc_dev;
147}
148
149void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc);
150void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
151void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
152
152#endif 153#endif
diff --git a/include/linux/platform_data/ti_am335x_adc.h b/include/linux/platform_data/ti_am335x_adc.h
deleted file mode 100644
index e41d5834cb84..000000000000
--- a/include/linux/platform_data/ti_am335x_adc.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef __LINUX_TI_AM335X_ADC_H
2#define __LINUX_TI_AM335X_ADC_H
3
4/**
5 * struct adc_data ADC Input information
6 * @adc_channels: Number of analog inputs
7 * available for ADC.
8 */
9
10struct adc_data {
11 unsigned int adc_channels;
12};
13
14#endif