Staging/iio/adc/touchscreen/MXS: provide devicetree adaption
authorJuergen Beisert <jbe@pengutronix.de>
Mon, 23 Sep 2013 14:36:00 +0000 (15:36 +0100)
committerJonathan Cameron <jic23@kernel.org>
Tue, 1 Oct 2013 15:19:17 +0000 (16:19 +0100)
This is an RFC for the new touchscreen properties.

Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
Tested-by: Marek Vasut <marex@denx.de>
Acked-by: Marek Vasut <marex@denx.de>
Tested-by: Lothar Waßmann <LW@KARO-electronics.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-input@vger.kernel.org
CC: devel@driverdev.osuosl.org
CC: Marek Vasut <marex@denx.de>
CC: Fabio Estevam <fabio.estevam@freescale.com>
CC: devicetree@vger.kernel.org
Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
arch/arm/boot/dts/imx28-evk.dts
drivers/staging/iio/adc/mxs-lradc.c

index 46882058b59b54a12e457a72c1ed81ae62c90651..ee05dc3906941a10c5f20546e59b09e77bdf9c7b 100644 (file)
@@ -1,7 +1,8 @@
 * Freescale i.MX28 LRADC device driver
 
 Required properties:
-- compatible: Should be "fsl,imx28-lradc"
+- compatible: Should be "fsl,imx23-lradc" for i.MX23 SoC and "fsl,imx28-lradc"
+              for i.MX28 SoC
 - reg: Address and length of the register set for the device
 - interrupts: Should contain the LRADC interrupts
 
@@ -9,13 +10,38 @@ Optional properties:
 - fsl,lradc-touchscreen-wires: Number of wires used to connect the touchscreen
                                to LRADC. Valid value is either 4 or 5. If this
                                property is not present, then the touchscreen is
-                               disabled.
+                               disabled. 5 wires is valid for i.MX28 SoC only.
+- fsl,ave-ctrl: number of samples per direction to calculate an average value.
+                Allowed value is 1 ... 31, default is 4
+- fsl,ave-delay: delay between consecutive samples. Allowed value is
+                 1 ... 2047. It is used if 'fsl,ave-ctrl' > 1, counts at
+                 2 kHz and its default is 2 (= 1 ms)
+- fsl,settling: delay between plate switch to next sample. Allowed value is
+                1 ... 2047. It counts at 2 kHz and its default is
+                10 (= 5 ms)
 
-Examples:
+Example for i.MX23 SoC:
+
+       lradc@80050000 {
+               compatible = "fsl,imx23-lradc";
+               reg = <0x80050000 0x2000>;
+               interrupts = <36 37 38 39 40 41 42 43 44>;
+               status = "okay";
+               fsl,lradc-touchscreen-wires = <4>;
+               fsl,ave-ctrl = <4>;
+               fsl,ave-delay = <2>;
+               fsl,settling = <10>;
+       };
+
+Example for i.MX28 SoC:
 
        lradc@80050000 {
                compatible = "fsl,imx28-lradc";
                reg = <0x80050000 0x2000>;
-               interrupts = <10 14 15 16 17 18 19
-                               20 21 22 23 24 25>;
+               interrupts = <10 14 15 16 17 18 19 20 21 22 23 24 25>;
+               status = "okay";
+               fsl,lradc-touchscreen-wires = <5>;
+               fsl,ave-ctrl = <4>;
+               fsl,ave-delay = <2>;
+               fsl,settling = <10>;
        };
index 15715d921d14417a5f0e1e8fe76047410239aaa9..aa33393903a87cec3bcef3bb7f5138a779230d96 100644 (file)
 
                        lradc@80050000 {
                                status = "okay";
+                               fsl,lradc-touchscreen-wires = <4>;
+                               fsl,ave-ctrl = <4>;
+                               fsl,ave-delay = <2>;
+                               fsl,settling = <10>;
                        };
 
                        i2c0: i2c@80058000 {
index 18510d1ea5c85153017d09c61e70305c09c21b46..dfd1bc1cc56fcc8c118854e56ff69c11cd58a968 100644 (file)
@@ -1224,10 +1224,45 @@ MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids);
 static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc,
                                                struct device_node *lradc_node)
 {
-       /* TODO retrieve from device tree */
+       int ret;
+       u32 ts_wires = 0, adapt;
+
+       ret = of_property_read_u32(lradc_node, "fsl,lradc-touchscreen-wires",
+                               &ts_wires);
+       if (ret)
+               return -ENODEV; /* touchscreen feature disabled */
+
+       switch (ts_wires) {
+       case 4:
+               lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE;
+               break;
+       case 5:
+               if (lradc->soc == IMX28_LRADC) {
+                       lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE;
+                       break;
+               }
+               /* fall through an error message for i.MX23 */
+       default:
+               dev_err(lradc->dev,
+                       "Unsupported number of touchscreen wires (%d)\n",
+                       ts_wires);
+               return -EINVAL;
+       }
+
        lradc->over_sample_cnt = 4;
+       ret = of_property_read_u32(lradc_node, "fsl,ave-ctrl", &adapt);
+       if (ret == 0)
+               lradc->over_sample_cnt = adapt;
+
        lradc->over_sample_delay = 2;
+       ret = of_property_read_u32(lradc_node, "fsl,ave-delay", &adapt);
+       if (ret == 0)
+               lradc->over_sample_delay = adapt;
+
        lradc->settling_delay = 10;
+       ret = of_property_read_u32(lradc_node, "fsl,settling", &adapt);
+       if (ret == 0)
+               lradc->settling_delay = adapt;
 
        return 0;
 }
@@ -1243,7 +1278,6 @@ static int mxs_lradc_probe(struct platform_device *pdev)
        struct mxs_lradc *lradc;
        struct iio_dev *iio;
        struct resource *iores;
-       uint32_t ts_wires = 0;
        int ret = 0, touch_ret;
        int i;
 
@@ -1277,25 +1311,6 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 
        touch_ret = mxs_lradc_probe_touchscreen(lradc, node);
 
-       /* Check if touchscreen is enabled in DT. */
-       ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires",
-                               &ts_wires);
-       if (ret)
-               dev_info(dev, "Touchscreen not enabled.\n");
-       else if (ts_wires == 4)
-               lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE;
-       else if (ts_wires == 5)
-               lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE;
-       else
-               dev_warn(dev, "Unsupported number of touchscreen wires (%d)\n",
-                               ts_wires);
-
-       if ((lradc->soc == IMX23_LRADC) && (ts_wires == 5)) {
-               dev_warn(dev, "No support for 5 wire touches on i.MX23\n");
-               dev_warn(dev, "Falling back to 4 wire\n");
-               ts_wires = 4;
-       }
-
        /* Grab all IRQ sources */
        for (i = 0; i < of_cfg->irq_count; i++) {
                lradc->irq[i] = platform_get_irq(pdev, i);