imx25 adc and touchscreen driver
Subsystems (7)
v8 cover imx25 adc and touchscreen driver
Hi,
welcome to the next round of the never ending series ;). The last version v7 was sent roughly 8 months ago. The first version at least 1.5 years ago.
This series adds two drivers for ADC and TSC of the imx25 and a MFD driver to connect these.
Due to the larger changes in this version I had to remove some of the acks again.
@Hartmut:
Thanks for your comments. I updated the drivers accordingly.
Changes in v8:
- scale was defined as a shared property of the ADC although the scale can be different for each ADC channel. v8 fixes that.
- Some smaller modifications of the code style in gcq code.
- Redesign of the regulator handling in the gcq code. The driver does now handle regulators "vref-ext", "vref-xp" and "vref-yp" as positive voltage reference. Also the calculation of the scale property based on these voltage reference regulators was fixed. The code now uses regulator_get_optional() to avoid dummy regulators.
- The missing regulator_disable() was added.
Thanks to J?rgen the time behavior of the units is now fixed and within specs:
- Fixed clock rates for the whole unit regarding to the reference manual.
- Fixed clock/time calculations for settling times in the touchscreen driver.
Best Regards,
Markus
Denis Carikli (2):
ARM: dts: imx25: Add TSC and ADC support
ARM: imx_v4_v5_defconfig: Add I.MX25 Touchscreen controller and ADC
support.
Markus Pargmann (6):
ARM: dt: Binding documentation for imx25 ADC/TSC
ARM: dt: Binding documentation for imx25 GCQ
ARM: dt: Binding documentation for imx25 touchscreen controller
mfd: fsl imx25 Touchscreen ADC driver
iio: adc: fsl,imx25-gcq driver
input: touchscreen: imx25 tcq driver
.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 58 ++ .../bindings/input/touchscreen/fsl-mx25-tcq.txt | 29 + .../devicetree/bindings/mfd/fsl-imx25-tsadc.txt | 46 ++ arch/arm/boot/dts/imx25.dtsi | 30 +- arch/arm/configs/imx_v4_v5_defconfig | 4 + drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 415 ++++++++++++++ drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 +++++++++++++++++++++ drivers/mfd/Kconfig | 9 + drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 204 +++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 + include/linux/mfd/imx25-tsadc.h | 140 +++++ 16 files changed, 1567 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt create mode 100644 Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt create mode 100644 Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/dt-bindings/iio/adc/fsl-imx25-gcq.h create mode 100644 include/linux/mfd/imx25-tsadc.h
Signature · 1 line
2.6.1
PATCH v8 1/8 ARM: dt: Binding documentation for imx25 ADC/TSC
This documentation describes the devicetree bindings for the ADC/Touchscreen unit of the i.MX25 SoC.
---
Notes:
Changes in v6:
- Removed adc-ref property and replaced it with refp and refn for positive and negative references. The properties are optional now as the default behaviour is a positive internal reference voltage and ADC GND as negative reference.
.../devicetree/bindings/mfd/fsl-imx25-tsadc.txt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +46 -0
@@ -0,0 +1,46 @@ +Freescale mx25 ADC/TSC multifunction device + +This device combines two general purpose conversion queues one used for general +ADC and the other used for touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device. + - interrupts: Interrupt for this device as described in + interrupts/interrupts.txt + - clocks: An 'ipg' clock defined as described in clocks/clock.txt + - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'. + - ranges + +This device includes two conversion queues which can be added as subnodes. +The first queue is for the touchscreen, the second for general purpose ADC. + +Example: + tscadc: tscadc at 50030000 { + compatible = "fsl,imx25-tsadc"; + reg = <0x50030000 0xc>; + interrupts = <46>; + clocks = <&clks 119>; + clock-names = "ipg"; + interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + ... + }; + + adc: gcq at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + ... + }; + };
Signature · 1 line
2.6.1
Rob Herring
maintainerPATCH v8 1/8 ARM: dt: Binding documentation for imx25 ADC/TSC
Quoted 5 lines · Markus Pargmann
This documentation describes the devicetree bindings for the ADC/Touchscreen unit of the i.MX25 SoC.
Signed-off-by Markus Pargmann <[email protected]>Acked-by Jonathan Cameron <[email protected]>
Quoted 72 lines
---
Notes:
Changes in v6:
- Removed adc-ref property and replaced it with refp and refn for positive and negative references. The properties are optional now as the default behaviour is a positive internal reference voltage and ADC GND as negative reference..../devicetree/bindings/mfd/fsl-imx25-tsadc.txt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txtDocumentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +46
-0@@ -0,0 +1,46 @@ +Freescale mx25 ADC/TSC multifunction device + +This device combines two general purpose conversion queues one used for general +ADC and the other used for touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device. + - interrupts: Interrupt for this device as described in + interrupts/interrupts.txt + - clocks: An 'ipg' clock defined as described in clocks/clock.txt + - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'. + - ranges + +This device includes two conversion queues which can be added as subnodes. +The first queue is for the touchscreen, the second for general purpose ADC. + +Example: + tscadc: tscadc at 50030000 { + compatible = "fsl,imx25-tsadc"; + reg = <0x50030000 0xc>; + interrupts = <46>; + clocks = <&clks 119>; + clock-names = "ipg"; + interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + ... + }; + + adc: gcq at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + ... + }; + };Signature · 6 lines
2.6.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v8 1/8 ARM: dt: Binding documentation for imx25 ADC/TSC
In reply to Markus PargmannQuoted 24 lines · Markus Pargmann
This documentation describes the devicetree bindings for the ADC/Touchscreen unit of the i.MX25 SoC.
Signed-off-by Markus Pargmann <[email protected]>Acked-by Jonathan Cameron <[email protected]>---
Notes:
Changes in v6:
- Removed adc-ref property and replaced it with refp and refn for positive and negative references. The properties are optional now as the default behaviour is a positive internal reference voltage and ADC GND as negative reference..../devicetree/bindings/mfd/fsl-imx25-tsadc.txt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txtDocumentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +0
-0
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 1
Quoted 1 line
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +1
-0@@ -0,0 +1,46 @@ +Freescale mx25 ADC/TSC multifunction device
Prefer "MX25" and "MultiFunction Device (MFD)"
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 8
Quoted 6 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +6
-0+This device combines two general purpose conversion queues one used for general +ADC and the other used for touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device.
Not exactly. More like start location and size.
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 10
Quoted 2 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +2
-0+ - interrupts: Interrupt for this device as described in + interrupts/interrupts.txt
No such file. In any case, I'd prefer:
"(See: ../interrupt-controller/interrupts.txt)".
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +1
-0+ - clocks: An 'ipg' clock defined as described in clocks/clock.txt
Didn't you check any of what you've written?
"(See: ../clock/clock-bindings.txt)"
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 17
Quoted 6 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +6
-0+ - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'. + - ranges
?
Also, don't think think that this looks better/easier to read?
Quoted 11 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +11
-0+Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device. + - interrupts: Interrupt for this device as described in + interrupts/interrupts.txt + - clocks: An 'ipg' clock defined as described in clocks/clock.txt + - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'.
[...]
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 28
Quoted 10 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +10
-0+This device includes two conversion queues which can be added as subnodes. +The first queue is for the touchscreen, the second for general purpose ADC. + +Example: + tscadc: tscadc at 50030000 { + compatible = "fsl,imx25-tsadc"; + reg = <0x50030000 0xc>; + interrupts = <46>; + clocks = <&clks 119>; + clock-names = "ipg";
I don't think this is required, if you only have a single clock.
Quoted 18 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +18
-0+ interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + ... + }; + + adc: gcq at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + ... + }; + };
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v8 1/8 ARM: dt: Binding documentation for imx25 ADC/TSC
Quoted 20 lines · On Monday 23 November 2015 14:59:52 Lee Jones wrote:
Quoted 18 lines · Markus Pargmann
This documentation describes the devicetree bindings for the ADC/Touchscreen unit of the i.MX25 SoC.
Signed-off-by Markus Pargmann <[email protected]>Acked-by Jonathan Cameron <[email protected]>---
Notes:
Changes in v6:
- Removed adc-ref property and replaced it with refp and refn for positive and negative references. The properties are optional now as the default behaviour is a positive internal reference voltage and ADC GND as negative reference..../devicetree/bindings/mfd/fsl-imx25-tsadc.txt | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt
Quoted 9 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 1
Quoted 7 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +1
-0@@ -0,0 +1,46 @@ +Freescale mx25 ADC/TSC multifunction devicePrefer "MX25" and "MultiFunction Device (MFD)"
Fixed.
Quoted 15 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 8
Quoted 7 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +6
-0+This device combines two general purpose conversion queues one used for general +ADC and the other used for touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device.Not exactly. More like start location and size.
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 10
Quoted 2 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +2
-0+ - interrupts: Interrupt for this device as described in + interrupts/interrupts.txtNo such file. In any case, I'd prefer:
Quoted 7 lines
"(See:
../interrupt-controller/interrupts.txt)".Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +1
-0+ - clocks: An 'ipg' clock defined as described in clocks/clock.txtDidn't you check any of what you've written?
"(See:
../clock/clock-bindings.txt)"
Seems I didn't check these, sorry.
Quoted 11 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 17
Quoted 7 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +6
-0+ - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'. + - ranges?
Also, don't think think that this looks better/easier to read?
Yes a bit, changed it.
Quoted 15 lines
Quoted 12 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +11
-0+Required properties: + - compatible: Should be "fsl,imx25-tsadc". + - reg: Memory range of the device. + - interrupts: Interrupt for this device as described in + interrupts/interrupts.txt + - clocks: An 'ipg' clock defined as described in clocks/clock.txt + - interrupt-controller: This device is an interrupt controller. It controls + the interrupts of both conversion queues. + - #interrupt-cells: Should be '<1>'. + - #address-cells: Should be '<1>'. + - #size-cells: Should be '<1>'.[...]
Quoted 12 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt line 28
Quoted 10 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +10
-0+This device includes two conversion queues which can be added as subnodes. +The first queue is for the touchscreen, the second for general purpose ADC. + +Example: + tscadc: tscadc at 50030000 { + compatible = "fsl,imx25-tsadc"; + reg = <0x50030000 0xc>; + interrupts = <46>; + clocks = <&clks 119>; + clock-names = "ipg";I don't think this is required, if you only have a single clock.
I prefer this variation so that you immediately see what the clock is for. The number is not terribly helpful.
Thanks,
Markus
Quoted 21 lines
Quoted 19 lines
Documentation/devicetree/bindings/mfd/fsl-imx25-tsadc.txt new file +18
-0+ interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + ... + }; + + adc: gcq at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + ... + }; + };
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151124/9f3b22a0/attachment.sig>
PATCH v8 2/8 ARM: dt: Binding documentation for imx25 GCQ
In reply to Markus PargmannThe documentation describes the bindings for the imx25 GCQ unit which is essentially a generic conversion queue using the imx25 ADC.
---
Notes:
Changes in v6:
- Changed bindings to use adc-refp and adc-refn. Also a bit of cleanup in the setup routine.
Changes in v5:
- Fixed locking
- Removed module owner
.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +58 -0
@@ -0,0 +1,58 @@ +Freescale i.MX25 ADC GCQ device + +This is a generic conversion queue device that can convert any of the +analog inputs using the ADC unit of the i.MX25. + +Required properties: + - compatible: Should be "fsl,imx25-gcq". + - reg: Should be the register range of the module. + - interrupts: Should be the interrupt number of the module. + Typically this is <1>. + - interrupt-parent: phandle to the tsadc module of the i.MX25. + - #address-cells: Should be <1> (setting for the subnodes) + - #size-cells: Should be <0> (setting for the subnodes) + +Optional properties: + - vref-ext-supply: The regulator supplying the ADC reference voltage. + Required when at least one subnode uses the this reference. + - vref-xp-supply: The regulator supplying the ADC reference voltage on pin XP. + Required when at least one subnode uses this reference. + - vref-yp-supply: The regulator supplying the ADC reference voltage on pin YP. + Required when at least one subnode uses this reference. + +Sub-nodes: +Optionally you can define subnodes which define the reference voltage +for the analog inputs. + +Required properties for subnodes: + - reg: Should be the number of the analog input. + 0: xp + 1: yp + 2: xn + 3: yn + 4: wiper + 5: inaux0 + 6: inaux1 + 7: inaux2 +Optional properties for subnodes: + - fsl,adc-refp: specifies the positive reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h> + - fsl,adc-refn: specifies the negative reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h> + +Example: + + adc: adc at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + interrupt-parent = <&tscadc>; + interrupts = <1>; + #address-cells = <1>; + #size-cells = <0>; + + inaux at 5 { + reg = <5>; + fsl,adc-refp = <MX25_ADC_REFP_INT>; + fsl,adc-refn = <MX25_ADC_REFN_NGND>; + }; + };
Signature · 1 line
2.6.1
Rob Herring
maintainerPATCH v8 2/8 ARM: dt: Binding documentation for imx25 GCQ
Quoted 24 lines · Markus Pargmann
The documentation describes the bindings for the imx25 GCQ unit which is essentially a generic conversion queue using the imx25 ADC.
Signed-off-by Markus Pargmann <[email protected]>---
Notes:
Changes in v6:
- Changed bindings to use adc-refp and adc-refn. Also a bit of cleanup in the setup routine.Changes in v5:
- Fixed locking
- Removed module owner.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txtDocumentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +0
-0
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt line 41
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +5
-0+Optional properties for subnodes: + - fsl,adc-refp: specifies the positive reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h> + - fsl,adc-refn: specifies the negative reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h>
This header should be part of this commit.
Quoted 24 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +17
-0+ +Example: + + adc: adc at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + interrupt-parent = <&tscadc>; + interrupts = <1>; + #address-cells = <1>; + #size-cells = <0>; + + inaux at 5 { + reg = <5>; + fsl,adc-refp = <MX25_ADC_REFP_INT>; + fsl,adc-refn = <MX25_ADC_REFN_NGND>; + }; + };Signature · 6 lines
2.6.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v8 2/8 ARM: dt: Binding documentation for imx25 GCQ
Quoted 27 lines · On Monday 16 November 2015 09:12:55 Rob Herring wrote:
Quoted 24 lines · Markus Pargmann
The documentation describes the bindings for the imx25 GCQ unit which is essentially a generic conversion queue using the imx25 ADC.
Signed-off-by Markus Pargmann <[email protected]>---
Notes:
Changes in v6:
- Changed bindings to use adc-refp and adc-refn. Also a bit of cleanup in the setup routine.Changes in v5:
- Fixed locking
- Removed module owner.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txtDocumentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +0
-0
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt line 41
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +5
-0+Optional properties for subnodes: + - fsl,adc-refp: specifies the positive reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h> + - fsl,adc-refn: specifies the negative reference input as defined in + <dt-bindings/iio/adc/fsl-imx25-gcq.h>This header should be part of this commit.
Thanks, will fix that.
Best Regards,
Markus
Quoted 24 lines
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +7
-0+ +Example: + + adc: adc at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + interrupt-parent = <&tscadc>;Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt line 58
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +10
-0+ interrupts = <1>; + #address-cells = <1>; + #size-cells = <0>; + + inaux at 5 { + reg = <5>; + fsl,adc-refp = <MX25_ADC_REFP_INT>; + fsl,adc-refn = <MX25_ADC_REFN_NGND>; + }; + };_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151117/767fe754/attachment.sig>
PATCH v8 3/8 ARM: dt: Binding documentation for imx25 touchscreen controller
In reply to Markus PargmannThis is the touchscreen conversion queue binding documentation. It uses the shared imx25 ADC.
---
Notes:
Changes in v5:
- Fix signed/unsigned comparison
- Fix unused variable settling_time by putting it in the correct argument list
- Use continous conversion queue with the repeat feature and a proper repeat-wait. Previously the touchscreen caused massive number of interrupts.
.../bindings/input/touchscreen/fsl-mx25-tcq.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +29 -0
@@ -0,0 +1,29 @@ +Freescale mx25 TS conversion queue module + +mx25 touchscreen conversion queue module which controls the ADC unit of the +mx25 for attached touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tcq". + - reg: Memory range of the device. + - interrupts: Should be the interrupt number associated with this module within + the tscadc unit (<0>). + - interrupt-parent: Should be a phandle to the tscadc unit. + - fsl,wires: Should be '<4>' or '<5>' + +Optional properties: + - fsl,pen-debounce: Pen debounce time in nanoseconds. + - fsl,pen-threshold: Pen-down threshold for the touchscreen. + - fsl,settling-time: Settling time in nanoseconds. + +This device includes two conversion queues which can be added as subnodes. +The first queue is for the touchscreen, the second for general purpose ADC. + +Example: + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + interrupt-parent = <&tscadc>; + interrupts = <0>; + fsl,wires = <4>; + };
Signature · 1 line
2.6.1
Rob Herring
maintainerPATCH v8 3/8 ARM: dt: Binding documentation for imx25 touchscreen controller
Quoted 30 lines · Markus Pargmann
This is the touchscreen conversion queue binding documentation. It uses the shared imx25 ADC.
Signed-off-by Markus Pargmann <[email protected]>---
Notes:
Changes in v5:
- Fix signed/unsigned comparison
- Fix unused variablesettling_timeby putting it in the correct argument list
- Use continous conversion queue with the repeat feature and a proper repeat-wait. Previously the touchscreen caused massive number of interrupts..../bindings/input/touchscreen/fsl-mx25-tcq.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txtDocumentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +7
-0@@ -0,0 +1,29 @@ +Freescale mx25 TS conversion queue module + +mx25 touchscreen conversion queue module which controls the ADC unit of the +mx25 for attached touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tcq".
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt line 17
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +10
-0+ - reg: Memory range of the device. + - interrupts: Should be the interrupt number associated with this module within + the tscadc unit (<0>). + - interrupt-parent: Should be a phandle to the tscadc unit. + - fsl,wires: Should be '<4>' or '<5>' + +Optional properties: + - fsl,pen-debounce: Pen debounce time in nanoseconds. + - fsl,pen-threshold: Pen-down threshold for the touchscreen. + - fsl,settling-time: Settling time in nanoseconds.
Don't we have standard properties for these? If not, these should have units.
I don't understand the difference between debounce and settling times. Please make that clear in the doc.
Rob
PATCH v8 3/8 ARM: dt: Binding documentation for imx25 touchscreen controller
Hi,
Quoted 36 lines · On Monday 16 November 2015 08:16:09 Rob Herring wrote:
Quoted 35 lines · Markus Pargmann
This is the touchscreen conversion queue binding documentation. It uses the shared imx25 ADC.
Signed-off-by Markus Pargmann <[email protected]>---
Notes:
Changes in v5:
- Fix signed/unsigned comparison
- Fix unused variablesettling_timeby putting it in the correct argument list
- Use continous conversion queue with the repeat feature and a proper repeat-wait. Previously the touchscreen caused massive number of interrupts..../bindings/input/touchscreen/fsl-mx25-tcq.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txtDocumentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +12
-0@@ -0,0 +1,29 @@ +Freescale mx25 TS conversion queue module + +mx25 touchscreen conversion queue module which controls the ADC unit of the +mx25 for attached touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tcq". + - reg: Memory range of the device. + - interrupts: Should be the interrupt number associated with this module within + the tscadc unit (<0>). + - interrupt-parent: Should be a phandle to the tscadc unit. + - fsl,wires: Should be '<4>' or '<5>'
Quoted 8 lines
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt line 17
Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +5
-0+ +Optional properties: + - fsl,pen-debounce: Pen debounce time in nanoseconds. + - fsl,pen-threshold: Pen-down threshold for the touchscreen. + - fsl,settling-time: Settling time in nanoseconds.Don't we have standard properties for these? If not, these should have units.
I just found properties like 'debounce_timeout' without a vendor prefix but they don't seem to be standard properties:
Documentation/devicetree/bindings/input/touchscreen/brcm,iproc-touchscreen.txt
For fsl,pen-threshold there is no real unit. It is the ratio between the internal voltage reference and the measured voltage after one of the touchscreen plates was precharged. However there are limits, I will add a better description.
Quoted 3 lines
I don't understand the difference between debounce and settling times. Please make that clear in the doc.
The settling time is the time waited after charging the touchscreen plates. The pen-debounce time is a delay after a pen down has been detected.
Best Regards,
Markus
Quoted 9 lines
Rob
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151117/097d61ed/attachment.sig>
Dmitry Torokhov
maintainerPATCH v8 3/8 ARM: dt: Binding documentation for imx25 touchscreen controller
In reply to Rob HerringQuoted 35 lines · Rob Herring
Quoted 34 lines · Markus Pargmann
This is the touchscreen conversion queue binding documentation. It uses the shared imx25 ADC.
Signed-off-by Markus Pargmann <[email protected]>---
Notes:
Changes in v5:
- Fix signed/unsigned comparison
- Fix unused variablesettling_timeby putting it in the correct argument list
- Use continous conversion queue with the repeat feature and a proper repeat-wait. Previously the touchscreen caused massive number of interrupts..../bindings/input/touchscreen/fsl-mx25-tcq.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txtDocumentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +11
-0@@ -0,0 +1,29 @@ +Freescale mx25 TS conversion queue module + +mx25 touchscreen conversion queue module which controls the ADC unit of the +mx25 for attached touchscreens. + +Required properties: + - compatible: Should be "fsl,imx25-tcq". + - reg: Memory range of the device. + - interrupts: Should be the interrupt number associated with this module within + the tscadc unit (<0>). + - interrupt-parent: Should be a phandle to the tscadc unit.
Quoted 8 lines
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt line 17
Quoted 6 lines
Documentation/devicetree/bindings/input/touchscreen/fsl-mx25-tcq.txt new file +6
-0+ - fsl,wires: Should be '<4>' or '<5>' + +Optional properties: + - fsl,pen-debounce: Pen debounce time in nanoseconds. + - fsl,pen-threshold: Pen-down threshold for the touchscreen. + - fsl,settling-time: Settling time in nanoseconds.Don't we have standard properties for these?
These are usually controller-specific so no.
Thanks.
Signature · 1 line
Dmitry
PATCH v8 4/8 mfd: fsl imx25 Touchscreen ADC driver
In reply to Markus PargmannThis is the core driver for imx25 touchscreen/adc driver. The module has one shared ADC and two different conversion queues which use the ADC. The two queues are identical. Both can be used for general purpose ADC but one is meant to be used for touchscreens.
This driver is the core which manages the central components and registers of the TSC/ADC unit. It manages the IRQs and forwards them to the correct components.
---
Notes:
Changes in v7:
- Cleanup bit defines in header files to be more readable
- Fix irq check to return with an error for irq <= 0
- Add COMPILE_TEST in Kconfig file
Changes in v5:
- Remove ifdef CONFIG_OF as this driver is only for DT usage
- Remove module owner
- Add Kconfig dependencies ARCH_MX25 and OF
@Jonathan Cameron:
I left your acked-by on the patch as these were small changes. If it should be removed, please say so. Thanks
drivers/mfd/Kconfig | 9 ++ drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 204 ++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/imx25-tsadc.h | 140 +++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/linux/mfd/imx25-tsadc.h
drivers/mfd/Kconfig +9 -0
@@ -271,6 +271,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MX25_TSADC + tristate "Freescale i.MX25 integrated Touchscreen and ADC unit" + select REGMAP_MMIO + depends on (SOC_IMX25 && OF) || COMPILE_TEST + help + Enable support for the integrated Touchscreen and ADC unit of the + i.MX25 processors. They consist of a conversion queue for general + purpose ADC and a queue for Touchscreens. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OF
drivers/mfd/Makefile +2 -0
@@ -81,6 +81,8 @@ obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o obj-$(CONFIG_TWL6040_CORE) += twl6040.o +obj-$(CONFIG_MFD_MX25_TSADC) += fsl-imx25-tsadc.o + obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o
drivers/mfd/fsl-imx25-tsadc.c new file +204 -0
204 lines not on this page · raw message
include/linux/mfd/imx25-tsadc.h new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.6.1
Jonathan Cameron
maintainerPATCH v8 4/8 mfd: fsl imx25 Touchscreen ADC driver
Quoted 9 lines · Markus Pargmann
This is the core driver for imx25 touchscreen/adc driver. The module has one shared ADC and two different conversion queues which use the ADC. The two queues are identical. Both can be used for general purpose ADC but one is meant to be used for touchscreens.
This driver is the core which manages the central components and registers of the TSC/ADC unit. It manages the IRQs and forwards them to the correct components.
Quoted 5 lines
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[ensure correct ADC clock depending on the IPG clock]Signed-off-by Juergen Borleis <[email protected]>
Looks good to me - one query on meaning of a comment inline.
I'm taking the view this series wants to go through the MFD tree but don't mind if it goes through IIO or input instead if there is a good reason to do so.
Jonathan
Quoted 157 lines
---
Notes:
Changes in v7:
- Cleanup bit defines in header files to be more readable
- Fix irq check to return with an error for irq <= 0
- AddCOMPILE_TESTinKconfigfileChanges in v5:
- Remove ifdefCONFIG_OFas this driver is only for DT usage
- Remove module owner
- AddKconfigdependenciesARCH_MX25and OF@Jonathan Cameron:
I left your acked-by on the patch as these were small changes. If it should be removed, please say so. Thanksdrivers/mfd/Kconfig | 9 ++ drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 204 ++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/imx25-tsadc.h | 140 +++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/linux/mfd/imx25-tsadc.hdrivers/mfd/Kconfig +9
-0@@ -271,6 +271,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MX25_TSADC + tristate "Freescale i.MX25 integrated Touchscreen and ADC unit" + select REGMAP_MMIO + depends on (SOC_IMX25 && OF) || COMPILE_TEST + help + Enable support for the integrated Touchscreen and ADC unit of the + i.MX25 processors. They consist of a conversion queue for general + purpose ADC and a queue for Touchscreens. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OFdrivers/mfd/Makefile +2
-0@@ -81,6 +81,8 @@ obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o obj-$(CONFIG_TWL6040_CORE) += twl6040.o +obj-$(CONFIG_MFD_MX25_TSADC) += fsl-imx25-tsadc.o + obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.odrivers/mfd/fsl-imx25-tsadc.c new file +93
-0@@ -0,0 +1,204 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdesc.h> +#include <linux/irqdomain.h> +#include <linux/irq.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static struct regmap_config mx25_tsadc_regmap_config = { + .fast_io = true, + .max_register =8 , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static void mx25_tsadc_irq_handler (struct irq_desc *desc) +{ +struct mx25_tsadc *tsadc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +u32 status; + +chained_irq_enter (chip, desc); + +regmap_read (tsadc->regs,MX25_TSC_TGSR , &status); + +if (status &MX25_TGSR_GCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,1 )); + +if (status &MX25_TGSR_TCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,0 )); + +chained_irq_exit (chip, desc); +} + +static int mx25_tsadc_domain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct mx25_tsadc *tsadc = d->host_data; + +irq_set_chip_data (irq, tsadc); +irq_set_chip_and_handler (irq, &dummy_irq_chip, + handle_level_irq); +irq_modify_status (irq,IRQ_NOREQUEST ,IRQ_NOPROBE ); + +return 0 ; +} + +static struct irq_domain_ops mx25_tsadc_domain_ops = { + .map = mx25_tsadc_domain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static int mx25_tsadc_setup_irq (struct platform_device *pdev, +struct mx25_tsadc *tsadc) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +int irq; + + irq =platform_get_irq (pdev,0 ); +if (irq <=0 ) { +dev_err (dev,"Failed to get irq\n" ); +return irq; + } + + tsadc->domain =irq_domain_add_simple (np,2 ,0 , &mx25_tsadc_domain_ops, + tsadc); +if (!tsadc->domain) { +dev_err (dev,"Failed to add irq domain\n" ); +return -ENOMEM ; + } + +irq_set_chained_handler (irq, mx25_tsadc_irq_handler); +irq_set_handler_data (irq, tsadc); + +return 0 ; +} + +static void mx25_tsadc_setup_clk(struct platform_device *pdev,
drivers/mfd/fsl-imx25-tsadc.c line 103
Quoted 10 lines
drivers/mfd/fsl-imx25-tsadc.c new file +10
-0+ struct mx25_tsadc *tsadc) +{ +unsigned clk_div; + +/* +* According to the datasheet the ADC clock should never +* exceed 1,75 MHz. Base clock is the IPG and the ADC unit uses +* a funny clock divider. To keep the time constant the ADC needs to do +* one conversion, adapt the ADC internal clock divider to +* the available IPG
I'm not entirely following this explanation...
maybe
...one conversion, then adapt the ADC...
Quoted 248 lines
drivers/mfd/fsl-imx25-tsadc.c new file +101
-0+*/ + +dev_dbg (&pdev->dev,"Found master clock at %lu Hz\n" , +clk_get_rate (tsadc->clk)); + + clk_div =DIV_ROUND_UP (clk_get_rate (tsadc->clk),1750000 ); +dev_dbg (&pdev->dev,"Setting up ADC clock divider to %u\n" , clk_div); + +/* adc clock = IPG clock / (2 * div + 2) */ + clk_div -=2 ; + clk_div /=2 ; + +/* +* the ADC clock divider changes its behaviour when values below 4 +* are used: it is fixed to "/ 10" in this case +*/ + clk_div =max_t (unsigned,4 , clk_div); + +dev_dbg (&pdev->dev,"Resulting ADC conversion clock at %lu Hz\n" , +clk_get_rate (tsadc->clk) / (2 * clk_div +2 )); + +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR , +MX25_TGCR_ADCCLKCFG (0x1f ), +MX25_TGCR_ADCCLKCFG (clk_div)); +} + +static int mx25_tsadc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct mx25_tsadc *tsadc; +struct resource *res; +int ret; +void __iomem *iomem; + + tsadc =devm_kzalloc (dev,sizeof (*tsadc),GFP_KERNEL ); +if (!tsadc) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + iomem =devm_ioremap_resource (dev, res); +if (IS_ERR (iomem)) +return PTR_ERR (iomem); + + tsadc->regs =devm_regmap_init_mmio (dev, iomem, + &mx25_tsadc_regmap_config); +if (IS_ERR (tsadc->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (tsadc->regs); + } + + tsadc->clk =devm_clk_get (dev,"ipg" ); +if (IS_ERR (tsadc->clk)) { +dev_err (dev,"Failed to get ipg clock\n" ); +return PTR_ERR (tsadc->clk); + } + +/* setup clock according to the datasheet */ +mx25_tsadc_setup_clk (pdev, tsadc); + +/* Enable clock and reset the component */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_CLK_EN , +MX25_TGCR_CLK_EN ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_TSC_RST , +MX25_TGCR_TSC_RST ); + +/* Setup powersaving mode, but enable internal reference voltage */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_POWERMODE_MASK , +MX25_TGCR_POWERMODE_SAVE ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_INTREFEN , +MX25_TGCR_INTREFEN ); + + ret =mx25_tsadc_setup_irq (pdev, tsadc); +if (ret) +return ret; + +platform_set_drvdata (pdev, tsadc); + +of_platform_populate (np,NULL ,NULL , dev); + +return 0 ; +} + +static const struct of_device_id mx25_tsadc_ids[] = { + { .compatible ="fsl,imx25-tsadc" }, + {/* Sentinel */ } +}; + +static struct platform_driver mx25_tsadc_driver = { + .driver = { + .name ="mx25-tsadc" , + .of_match_table =of_match_ptr (mx25_tsadc_ids), + }, + .probe = mx25_tsadc_probe, +}; +module_platform_driver (mx25_tsadc_driver); + +MODULE_DESCRIPTION ("MFD for ADC/TSC for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:mx25-tsadc" );include/linux/mfd/imx25-tsadc.h new file +140
-0@@ -0,0 +1,140 @@ +#ifndef _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ +#define _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ + +struct regmap ; +struct clk ; + +struct mx25_tsadc { +struct regmap *regs; +struct irq_domain *domain; +struct clk *clk; +}; + +#define MX25_TSC_TGCR 0x00 +#define MX25_TSC_TGSR 0x04 +#define MX25_TSC_TICR 0x08 + +/* The same register layout for TC and GC queue */ +#define MX25_ADCQ_FIFO 0x00 +#define MX25_ADCQ_CR 0x04 +#define MX25_ADCQ_SR 0x08 +#define MX25_ADCQ_MR 0x0c +#define MX25_ADCQ_ITEM_7_0 0x20 +#define MX25_ADCQ_ITEM_15_8 0x24 +#define MX25_ADCQ_CFG (n) (0x40 + ((n) * 0x4)) + +#define MX25_ADCQ_MR_MASK 0xffffffff + +/* TGCR */ +#define MX25_TGCR_PDBTIME (x) ((x) << 25) +#define MX25_TGCR_PDBTIME_MASK GENMASK(31, 25) +#define MX25_TGCR_PDBEN BIT(24) +#define MX25_TGCR_PDEN BIT(23) +#define MX25_TGCR_ADCCLKCFG (x) ((x) << 16) +#define MX25_TGCR_GET_ADCCLK (x) (((x) >> 16) & 0x1f) +#define MX25_TGCR_INTREFEN BIT(10) +#define MX25_TGCR_POWERMODE_MASK GENMASK(9, 8) +#define MX25_TGCR_POWERMODE_SAVE (1 << 8) +#define MX25_TGCR_POWERMODE_ON (2 << 8) +#define MX25_TGCR_STLC BIT(5) +#define MX25_TGCR_SLPC BIT(4) +#define MX25_TGCR_FUNC_RST BIT(2) +#define MX25_TGCR_TSC_RST BIT(1) +#define MX25_TGCR_CLK_EN BIT(0) + +/* TGSR */ +#define MX25_TGSR_SLP_INT BIT(2) +#define MX25_TGSR_GCQ_INT BIT(1) +#define MX25_TGSR_TCQ_INT BIT(0) + +/* ADCQ_ITEM_* */ +#define _MX25_ADCQ_ITEM (item, x) ((x) << ((item) * 4)) +#define MX25_ADCQ_ITEM (item, x) ((item) >= 8 ? \ + _MX25_ADCQ_ITEM((item) - 8, (x)) : _MX25_ADCQ_ITEM((item), (x))) + +/* ADCQ_FIFO (TCQFIFO and GCQFIFO) */ +#define MX25_ADCQ_FIFO_DATA (x) (((x) >> 4) & 0xfff) +#define MX25_ADCQ_FIFO_ID (x) ((x) & 0xf) + +/* ADCQ_CR (TCQR and GCQR) */ +#define MX25_ADCQ_CR_PDCFG_LEVEL BIT(19) +#define MX25_ADCQ_CR_PDMSK BIT(18) +#define MX25_ADCQ_CR_FRST BIT(17) +#define MX25_ADCQ_CR_QRST BIT(16) +#define MX25_ADCQ_CR_RWAIT_MASK GENMASK(15, 12) +#define MX25_ADCQ_CR_RWAIT (x) ((x) << 12) +#define MX25_ADCQ_CR_WMRK_MASK GENMASK(11, 8) +#define MX25_ADCQ_CR_WMRK (x) ((x) << 8) +#define MX25_ADCQ_CR_LITEMID_MASK (0xf << 4) +#define MX25_ADCQ_CR_LITEMID (x) ((x) << 4) +#define MX25_ADCQ_CR_RPT BIT(3) +#define MX25_ADCQ_CR_FQS BIT(2) +#define MX25_ADCQ_CR_QSM_MASK GENMASK(1, 0) +#define MX25_ADCQ_CR_QSM_PD 0x1 +#define MX25_ADCQ_CR_QSM_FQS 0x2 +#define MX25_ADCQ_CR_QSM_FQS_PD 0x3 + +/* ADCQ_SR (TCQSR and GCQSR) */ +#define MX25_ADCQ_SR_FDRY BIT(15) +#define MX25_ADCQ_SR_FULL BIT(14) +#define MX25_ADCQ_SR_EMPT BIT(13) +#define MX25_ADCQ_SR_FDN (x) (((x) >> 8) & 0x1f) +#define MX25_ADCQ_SR_FRR BIT(6) +#define MX25_ADCQ_SR_FUR BIT(5) +#define MX25_ADCQ_SR_FOR BIT(4) +#define MX25_ADCQ_SR_EOQ BIT(1) +#define MX25_ADCQ_SR_PD BIT(0) + +/* ADCQ_MR (TCQMR and GCQMR) */ +#define MX25_ADCQ_MR_FDRY_DMA BIT(31) +#define MX25_ADCQ_MR_FER_DMA BIT(22) +#define MX25_ADCQ_MR_FUR_DMA BIT(21) +#define MX25_ADCQ_MR_FOR_DMA BIT(20) +#define MX25_ADCQ_MR_EOQ_DMA BIT(17) +#define MX25_ADCQ_MR_PD_DMA BIT(16) +#define MX25_ADCQ_MR_FDRY_IRQ BIT(15) +#define MX25_ADCQ_MR_FER_IRQ BIT(6) +#define MX25_ADCQ_MR_FUR_IRQ BIT(5) +#define MX25_ADCQ_MR_FOR_IRQ BIT(4) +#define MX25_ADCQ_MR_EOQ_IRQ BIT(1) +#define MX25_ADCQ_MR_PD_IRQ BIT(0) + +/* ADCQ_CFG (TICR, TCC0-7,GCC0-7) */ +#define MX25_ADCQ_CFG_SETTLING_TIME (x) ((x) << 24) +#define MX25_ADCQ_CFG_IGS (1 << 20) +#define MX25_ADCQ_CFG_NOS_MASK GENMASK(19, 16) +#define MX25_ADCQ_CFG_NOS (x) (((x) - 1) << 16) +#define MX25_ADCQ_CFG_WIPER (1 << 15) +#define MX25_ADCQ_CFG_YNLR (1 << 14) +#define MX25_ADCQ_CFG_YPLL_HIGH (0 << 12) +#define MX25_ADCQ_CFG_YPLL_OFF (1 << 12) +#define MX25_ADCQ_CFG_YPLL_LOW (3 << 12) +#define MX25_ADCQ_CFG_XNUR_HIGH (0 << 10) +#define MX25_ADCQ_CFG_XNUR_OFF (1 << 10) +#define MX25_ADCQ_CFG_XNUR_LOW (3 << 10) +#define MX25_ADCQ_CFG_XPUL_HIGH (0 << 9) +#define MX25_ADCQ_CFG_XPUL_OFF (1 << 9) +#define MX25_ADCQ_CFG_REFP (sel) ((sel) << 7) +#define MX25_ADCQ_CFG_REFP_YP MX25_ADCQ_CFG_REFP(0) +#define MX25_ADCQ_CFG_REFP_XP MX25_ADCQ_CFG_REFP(1) +#define MX25_ADCQ_CFG_REFP_EXT MX25_ADCQ_CFG_REFP(2) +#define MX25_ADCQ_CFG_REFP_INT MX25_ADCQ_CFG_REFP(3) +#define MX25_ADCQ_CFG_REFP_MASK GENMASK(8, 7) +#define MX25_ADCQ_CFG_IN (sel) ((sel) << 4) +#define MX25_ADCQ_CFG_IN_XP MX25_ADCQ_CFG_IN(0) +#define MX25_ADCQ_CFG_IN_YP MX25_ADCQ_CFG_IN(1) +#define MX25_ADCQ_CFG_IN_XN MX25_ADCQ_CFG_IN(2) +#define MX25_ADCQ_CFG_IN_YN MX25_ADCQ_CFG_IN(3) +#define MX25_ADCQ_CFG_IN_WIPER MX25_ADCQ_CFG_IN(4) +#define MX25_ADCQ_CFG_IN_AUX0 MX25_ADCQ_CFG_IN(5) +#define MX25_ADCQ_CFG_IN_AUX1 MX25_ADCQ_CFG_IN(6) +#define MX25_ADCQ_CFG_IN_AUX2 MX25_ADCQ_CFG_IN(7) +#define MX25_ADCQ_CFG_REFN (sel) ((sel) << 2) +#define MX25_ADCQ_CFG_REFN_XN MX25_ADCQ_CFG_REFN(0) +#define MX25_ADCQ_CFG_REFN_YN MX25_ADCQ_CFG_REFN(1) +#define MX25_ADCQ_CFG_REFN_NGND MX25_ADCQ_CFG_REFN(2) +#define MX25_ADCQ_CFG_REFN_NGND2 MX25_ADCQ_CFG_REFN(3) +#define MX25_ADCQ_CFG_REFN_MASK GENMASK(3, 2) +#define MX25_ADCQ_CFG_PENIACK (1 << 1) + +#endif /* _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ */
Jonathan Cameron
maintainerPATCH v8 4/8 mfd: fsl imx25 Touchscreen ADC driver
Quoted 450 lines · Jonathan Cameron
Quoted 9 lines · Markus Pargmann
This is the core driver for imx25 touchscreen/adc driver. The module has one shared ADC and two different conversion queues which use the ADC. The two queues are identical. Both can be used for general purpose ADC but one is meant to be used for touchscreens.
This driver is the core which manages the central components and registers of the TSC/ADC unit. It manages the IRQs and forwards them to the correct components.
Quoted 5 lines
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[ensure correct ADC clock depending on the IPG clock]Signed-off-by Juergen Borleis <[email protected]>Looks good to me - one query on meaning of a comment inline.
Acked-by Jonathan Cameron <[email protected]>I'm taking the view this series wants to go through the MFD tree but don't mind if it goes through IIO or input instead if there is a good reason to do so.
Jonathan
Quoted 157 lines
---
Notes:
Changes in v7:
- Cleanup bit defines in header files to be more readable
- Fix irq check to return with an error for irq <= 0
- AddCOMPILE_TESTinKconfigfileChanges in v5:
- Remove ifdefCONFIG_OFas this driver is only for DT usage
- Remove module owner
- AddKconfigdependenciesARCH_MX25and OF@Jonathan Cameron:
I left your acked-by on the patch as these were small changes. If it should be removed, please say so. Thanksdrivers/mfd/Kconfig | 9 ++ drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 204 ++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/imx25-tsadc.h | 140 +++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/linux/mfd/imx25-tsadc.hdrivers/mfd/Kconfig +9
-0@@ -271,6 +271,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MX25_TSADC + tristate "Freescale i.MX25 integrated Touchscreen and ADC unit" + select REGMAP_MMIO + depends on (SOC_IMX25 && OF) || COMPILE_TEST + help + Enable support for the integrated Touchscreen and ADC unit of the + i.MX25 processors. They consist of a conversion queue for general + purpose ADC and a queue for Touchscreens. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OFdrivers/mfd/Makefile +2
-0@@ -81,6 +81,8 @@ obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o obj-$(CONFIG_TWL6040_CORE) += twl6040.o +obj-$(CONFIG_MFD_MX25_TSADC) += fsl-imx25-tsadc.o + obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.odrivers/mfd/fsl-imx25-tsadc.c new file +93
-0@@ -0,0 +1,204 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdesc.h> +#include <linux/irqdomain.h> +#include <linux/irq.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static struct regmap_config mx25_tsadc_regmap_config = { + .fast_io = true, + .max_register =8 , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static void mx25_tsadc_irq_handler (struct irq_desc *desc) +{ +struct mx25_tsadc *tsadc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +u32 status; + +chained_irq_enter (chip, desc); + +regmap_read (tsadc->regs,MX25_TSC_TGSR , &status); + +if (status &MX25_TGSR_GCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,1 )); + +if (status &MX25_TGSR_TCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,0 )); + +chained_irq_exit (chip, desc); +} + +static int mx25_tsadc_domain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct mx25_tsadc *tsadc = d->host_data; + +irq_set_chip_data (irq, tsadc); +irq_set_chip_and_handler (irq, &dummy_irq_chip, + handle_level_irq); +irq_modify_status (irq,IRQ_NOREQUEST ,IRQ_NOPROBE ); + +return 0 ; +} + +static struct irq_domain_ops mx25_tsadc_domain_ops = { + .map = mx25_tsadc_domain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static int mx25_tsadc_setup_irq (struct platform_device *pdev, +struct mx25_tsadc *tsadc) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +int irq; + + irq =platform_get_irq (pdev,0 ); +if (irq <=0 ) { +dev_err (dev,"Failed to get irq\n" ); +return irq; + } + + tsadc->domain =irq_domain_add_simple (np,2 ,0 , &mx25_tsadc_domain_ops, + tsadc); +if (!tsadc->domain) { +dev_err (dev,"Failed to add irq domain\n" ); +return -ENOMEM ; + } + +irq_set_chained_handler (irq, mx25_tsadc_irq_handler); +irq_set_handler_data (irq, tsadc); + +return 0 ; +} + +static void mx25_tsadc_setup_clk(struct platform_device *pdev,drivers/mfd/fsl-imx25-tsadc.c line 103
Quoted 10 lines
drivers/mfd/fsl-imx25-tsadc.c new file +10
-0+ struct mx25_tsadc *tsadc) +{ +unsigned clk_div; + +/* +* According to the datasheet the ADC clock should never +* exceed 1,75 MHz. Base clock is the IPG and the ADC unit uses +* a funny clock divider. To keep the time constant the ADC needs to do +* one conversion, adapt the ADC internal clock divider to +* the available IPG I'm not entirely following this explanation...
maybe...one conversion, then adapt the ADC...
Quoted 238 lines
drivers/mfd/fsl-imx25-tsadc.c new file +101
-0+*/ + +dev_dbg (&pdev->dev,"Found master clock at %lu Hz\n" , +clk_get_rate (tsadc->clk)); + + clk_div =DIV_ROUND_UP (clk_get_rate (tsadc->clk),1750000 ); +dev_dbg (&pdev->dev,"Setting up ADC clock divider to %u\n" , clk_div); + +/* adc clock = IPG clock / (2 * div + 2) */ + clk_div -=2 ; + clk_div /=2 ; + +/* +* the ADC clock divider changes its behaviour when values below 4 +* are used: it is fixed to "/ 10" in this case +*/ + clk_div =max_t (unsigned,4 , clk_div); + +dev_dbg (&pdev->dev,"Resulting ADC conversion clock at %lu Hz\n" , +clk_get_rate (tsadc->clk) / (2 * clk_div +2 )); + +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR , +MX25_TGCR_ADCCLKCFG (0x1f ), +MX25_TGCR_ADCCLKCFG (clk_div)); +} + +static int mx25_tsadc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct mx25_tsadc *tsadc; +struct resource *res; +int ret; +void __iomem *iomem; + + tsadc =devm_kzalloc (dev,sizeof (*tsadc),GFP_KERNEL ); +if (!tsadc) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + iomem =devm_ioremap_resource (dev, res); +if (IS_ERR (iomem)) +return PTR_ERR (iomem); + + tsadc->regs =devm_regmap_init_mmio (dev, iomem, + &mx25_tsadc_regmap_config); +if (IS_ERR (tsadc->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (tsadc->regs); + } + + tsadc->clk =devm_clk_get (dev,"ipg" ); +if (IS_ERR (tsadc->clk)) { +dev_err (dev,"Failed to get ipg clock\n" ); +return PTR_ERR (tsadc->clk); + } + +/* setup clock according to the datasheet */ +mx25_tsadc_setup_clk (pdev, tsadc); + +/* Enable clock and reset the component */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_CLK_EN , +MX25_TGCR_CLK_EN ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_TSC_RST , +MX25_TGCR_TSC_RST ); + +/* Setup powersaving mode, but enable internal reference voltage */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_POWERMODE_MASK , +MX25_TGCR_POWERMODE_SAVE ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_INTREFEN , +MX25_TGCR_INTREFEN ); + + ret =mx25_tsadc_setup_irq (pdev, tsadc); +if (ret) +return ret; + +platform_set_drvdata (pdev, tsadc); + +of_platform_populate (np,NULL ,NULL , dev); + +return 0 ; +} + +static const struct of_device_id mx25_tsadc_ids[] = { + { .compatible ="fsl,imx25-tsadc" }, + {/* Sentinel */ } +}; + +static struct platform_driver mx25_tsadc_driver = { + .driver = { + .name ="mx25-tsadc" , + .of_match_table =of_match_ptr (mx25_tsadc_ids), + }, + .probe = mx25_tsadc_probe, +}; +module_platform_driver (mx25_tsadc_driver); + +MODULE_DESCRIPTION ("MFD for ADC/TSC for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:mx25-tsadc" );include/linux/mfd/imx25-tsadc.h new file +130
-0@@ -0,0 +1,140 @@ +#ifndef _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ +#define _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ + +struct regmap ; +struct clk ; + +struct mx25_tsadc { +struct regmap *regs; +struct irq_domain *domain; +struct clk *clk; +}; + +#define MX25_TSC_TGCR 0x00 +#define MX25_TSC_TGSR 0x04 +#define MX25_TSC_TICR 0x08 + +/* The same register layout for TC and GC queue */ +#define MX25_ADCQ_FIFO 0x00 +#define MX25_ADCQ_CR 0x04 +#define MX25_ADCQ_SR 0x08 +#define MX25_ADCQ_MR 0x0c +#define MX25_ADCQ_ITEM_7_0 0x20 +#define MX25_ADCQ_ITEM_15_8 0x24 +#define MX25_ADCQ_CFG (n) (0x40 + ((n) * 0x4)) + +#define MX25_ADCQ_MR_MASK 0xffffffff + +/* TGCR */ +#define MX25_TGCR_PDBTIME (x) ((x) << 25) +#define MX25_TGCR_PDBTIME_MASK GENMASK(31, 25) +#define MX25_TGCR_PDBEN BIT(24) +#define MX25_TGCR_PDEN BIT(23) +#define MX25_TGCR_ADCCLKCFG (x) ((x) << 16) +#define MX25_TGCR_GET_ADCCLK (x) (((x) >> 16) & 0x1f) +#define MX25_TGCR_INTREFEN BIT(10) +#define MX25_TGCR_POWERMODE_MASK GENMASK(9, 8) +#define MX25_TGCR_POWERMODE_SAVE (1 << 8) +#define MX25_TGCR_POWERMODE_ON (2 << 8) +#define MX25_TGCR_STLC BIT(5) +#define MX25_TGCR_SLPC BIT(4) +#define MX25_TGCR_FUNC_RST BIT(2) +#define MX25_TGCR_TSC_RST BIT(1) +#define MX25_TGCR_CLK_EN BIT(0) + +/* TGSR */ +#define MX25_TGSR_SLP_INT BIT(2) +#define MX25_TGSR_GCQ_INT BIT(1) +#define MX25_TGSR_TCQ_INT BIT(0) + +/* ADCQ_ITEM_* */ +#define _MX25_ADCQ_ITEM (item, x) ((x) << ((item) * 4)) +#define MX25_ADCQ_ITEM (item, x) ((item) >= 8 ? \ + _MX25_ADCQ_ITEM((item) - 8, (x)) : _MX25_ADCQ_ITEM((item), (x))) + +/* ADCQ_FIFO (TCQFIFO and GCQFIFO) */ +#define MX25_ADCQ_FIFO_DATA (x) (((x) >> 4) & 0xfff) +#define MX25_ADCQ_FIFO_ID (x) ((x) & 0xf) + +/* ADCQ_CR (TCQR and GCQR) */ +#define MX25_ADCQ_CR_PDCFG_LEVEL BIT(19) +#define MX25_ADCQ_CR_PDMSK BIT(18) +#define MX25_ADCQ_CR_FRST BIT(17) +#define MX25_ADCQ_CR_QRST BIT(16) +#define MX25_ADCQ_CR_RWAIT_MASK GENMASK(15, 12) +#define MX25_ADCQ_CR_RWAIT (x) ((x) << 12) +#define MX25_ADCQ_CR_WMRK_MASK GENMASK(11, 8) +#define MX25_ADCQ_CR_WMRK (x) ((x) << 8) +#define MX25_ADCQ_CR_LITEMID_MASK (0xf << 4) +#define MX25_ADCQ_CR_LITEMID (x) ((x) << 4) +#define MX25_ADCQ_CR_RPT BIT(3) +#define MX25_ADCQ_CR_FQS BIT(2) +#define MX25_ADCQ_CR_QSM_MASK GENMASK(1, 0) +#define MX25_ADCQ_CR_QSM_PD 0x1 +#define MX25_ADCQ_CR_QSM_FQS 0x2 +#define MX25_ADCQ_CR_QSM_FQS_PD 0x3 + +/* ADCQ_SR (TCQSR and GCQSR) */ +#define MX25_ADCQ_SR_FDRY BIT(15) +#define MX25_ADCQ_SR_FULL BIT(14) +#define MX25_ADCQ_SR_EMPT BIT(13) +#define MX25_ADCQ_SR_FDN (x) (((x) >> 8) & 0x1f) +#define MX25_ADCQ_SR_FRR BIT(6) +#define MX25_ADCQ_SR_FUR BIT(5) +#define MX25_ADCQ_SR_FOR BIT(4) +#define MX25_ADCQ_SR_EOQ BIT(1) +#define MX25_ADCQ_SR_PD BIT(0) + +/* ADCQ_MR (TCQMR and GCQMR) */ +#define MX25_ADCQ_MR_FDRY_DMA BIT(31) +#define MX25_ADCQ_MR_FER_DMA BIT(22) +#define MX25_ADCQ_MR_FUR_DMA BIT(21) +#define MX25_ADCQ_MR_FOR_DMA BIT(20) +#define MX25_ADCQ_MR_EOQ_DMA BIT(17) +#define MX25_ADCQ_MR_PD_DMA BIT(16) +#define MX25_ADCQ_MR_FDRY_IRQ BIT(15) +#define MX25_ADCQ_MR_FER_IRQ BIT(6) +#define MX25_ADCQ_MR_FUR_IRQ BIT(5) +#define MX25_ADCQ_MR_FOR_IRQ BIT(4) +#define MX25_ADCQ_MR_EOQ_IRQ BIT(1) +#define MX25_ADCQ_MR_PD_IRQ BIT(0) + +/* ADCQ_CFG (TICR, TCC0-7,GCC0-7) */ +#define MX25_ADCQ_CFG_SETTLING_TIME (x) ((x) << 24) +#define MX25_ADCQ_CFG_IGS (1 << 20) +#define MX25_ADCQ_CFG_NOS_MASK GENMASK(19, 16) +#define MX25_ADCQ_CFG_NOS (x) (((x) - 1) << 16) +#define MX25_ADCQ_CFG_WIPER (1 << 15) +#define MX25_ADCQ_CFG_YNLR (1 << 14) +#define MX25_ADCQ_CFG_YPLL_HIGH (0 << 12) +#define MX25_ADCQ_CFG_YPLL_OFF (1 << 12) +#define MX25_ADCQ_CFG_YPLL_LOW (3 << 12) +#define MX25_ADCQ_CFG_XNUR_HIGH (0 << 10) +#define MX25_ADCQ_CFG_XNUR_OFF (1 << 10) +#define MX25_ADCQ_CFG_XNUR_LOW (3 << 10) +#define MX25_ADCQ_CFG_XPUL_HIGH (0 << 9) +#define MX25_ADCQ_CFG_XPUL_OFF (1 << 9) +#define MX25_ADCQ_CFG_REFP (sel) ((sel) << 7) +#define MX25_ADCQ_CFG_REFP_YP MX25_ADCQ_CFG_REFP(0) +#define MX25_ADCQ_CFG_REFP_XP MX25_ADCQ_CFG_REFP(1) +#define MX25_ADCQ_CFG_REFP_EXT MX25_ADCQ_CFG_REFP(2) +#define MX25_ADCQ_CFG_REFP_INT MX25_ADCQ_CFG_REFP(3) +#define MX25_ADCQ_CFG_REFP_MASK GENMASK(8, 7) +#define MX25_ADCQ_CFG_IN (sel) ((sel) << 4) +#define MX25_ADCQ_CFG_IN_XP MX25_ADCQ_CFG_IN(0) +#define MX25_ADCQ_CFG_IN_YP MX25_ADCQ_CFG_IN(1) +#define MX25_ADCQ_CFG_IN_XN MX25_ADCQ_CFG_IN(2) +#define MX25_ADCQ_CFG_IN_YN MX25_ADCQ_CFG_IN(3) +#define MX25_ADCQ_CFG_IN_WIPER MX25_ADCQ_CFG_IN(4) +#define MX25_ADCQ_CFG_IN_AUX0 MX25_ADCQ_CFG_IN(5) +#define MX25_ADCQ_CFG_IN_AUX1 MX25_ADCQ_CFG_IN(6)include/linux/mfd/imx25-tsadc.h line 140
Quoted 10 lines
include/linux/mfd/imx25-tsadc.h new file +10
-0+#define MX25_ADCQ_CFG_IN_AUX2 MX25_ADCQ_CFG_IN(7) +#define MX25_ADCQ_CFG_REFN (sel) ((sel) << 2) +#define MX25_ADCQ_CFG_REFN_XN MX25_ADCQ_CFG_REFN(0) +#define MX25_ADCQ_CFG_REFN_YN MX25_ADCQ_CFG_REFN(1) +#define MX25_ADCQ_CFG_REFN_NGND MX25_ADCQ_CFG_REFN(2) +#define MX25_ADCQ_CFG_REFN_NGND2 MX25_ADCQ_CFG_REFN(3) +#define MX25_ADCQ_CFG_REFN_MASK GENMASK(3, 2) +#define MX25_ADCQ_CFG_PENIACK (1 << 1) + +#endif /* _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ */ --
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v8 4/8 mfd: fsl imx25 Touchscreen ADC driver
In reply to Jonathan CameronQuoted 10 lines · On Saturday 21 November 2015 17:02:34 Jonathan Cameron wrote:
Quoted 9 lines · Markus Pargmann
This is the core driver for imx25 touchscreen/adc driver. The module has one shared ADC and two different conversion queues which use the ADC. The two queues are identical. Both can be used for general purpose ADC but one is meant to be used for touchscreens.
This driver is the core which manages the central components and registers of the TSC/ADC unit. It manages the IRQs and forwards them to the correct components.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[ensure correct ADC clock depending on the IPG clock]Signed-off-by Juergen Borleis <[email protected]>Looks good to me - one query on meaning of a comment inline.
Acked-by Jonathan Cameron <[email protected]>
Thanks, comment inline.
Quoted 167 lines
I'm taking the view this series wants to go through the MFD tree but don't mind if it goes through IIO or input instead if there is a good reason to do so.
Jonathan
Quoted 161 lines
---
Notes:
Changes in v7:
- Cleanup bit defines in header files to be more readable
- Fix irq check to return with an error for irq <= 0
- AddCOMPILE_TESTinKconfigfileChanges in v5:
- Remove ifdefCONFIG_OFas this driver is only for DT usage
- Remove module owner
- AddKconfigdependenciesARCH_MX25and OF@Jonathan Cameron:
I left your acked-by on the patch as these were small changes. If it should be removed, please say so. Thanksdrivers/mfd/Kconfig | 9 ++ drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 204 ++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/imx25-tsadc.h | 140 +++++++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/linux/mfd/imx25-tsadc.hdrivers/mfd/Kconfig +9
-0@@ -271,6 +271,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MX25_TSADC + tristate "Freescale i.MX25 integrated Touchscreen and ADC unit" + select REGMAP_MMIO + depends on (SOC_IMX25 && OF) || COMPILE_TEST + help + Enable support for the integrated Touchscreen and ADC unit of the + i.MX25 processors. They consist of a conversion queue for general + purpose ADC and a queue for Touchscreens. + config MFD_HI6421_PMIC tristate "HiSilicon Hi6421 PMU/Codec IC" depends on OFdrivers/mfd/Makefile +2
-0@@ -81,6 +81,8 @@ obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o obj-$(CONFIG_MFD_TWL4030_AUDIO) += twl4030-audio.o obj-$(CONFIG_TWL6040_CORE) += twl6040.o +obj-$(CONFIG_MFD_MX25_TSADC) += fsl-imx25-tsadc.o + obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.odrivers/mfd/fsl-imx25-tsadc.c new file +97
-0@@ -0,0 +1,204 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdesc.h> +#include <linux/irqdomain.h> +#include <linux/irq.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static struct regmap_config mx25_tsadc_regmap_config = { + .fast_io = true, + .max_register =8 , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static void mx25_tsadc_irq_handler (struct irq_desc *desc) +{ +struct mx25_tsadc *tsadc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +u32 status; + +chained_irq_enter (chip, desc); + +regmap_read (tsadc->regs,MX25_TSC_TGSR , &status); + +if (status &MX25_TGSR_GCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,1 )); + +if (status &MX25_TGSR_TCQ_INT ) +generic_handle_irq (irq_find_mapping (tsadc->domain,0 )); + +chained_irq_exit (chip, desc); +} + +static int mx25_tsadc_domain_map (struct irq_domain *d,unsigned int irq, +irq_hw_number_t hwirq) +{ +struct mx25_tsadc *tsadc = d->host_data; + +irq_set_chip_data (irq, tsadc); +irq_set_chip_and_handler (irq, &dummy_irq_chip, + handle_level_irq); +irq_modify_status (irq,IRQ_NOREQUEST ,IRQ_NOPROBE ); + +return 0 ; +} + +static struct irq_domain_ops mx25_tsadc_domain_ops = { + .map = mx25_tsadc_domain_map, + .xlate = irq_domain_xlate_onecell, +}; + +static int mx25_tsadc_setup_irq (struct platform_device *pdev, +struct mx25_tsadc *tsadc) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +int irq; + + irq =platform_get_irq (pdev,0 ); +if (irq <=0 ) { +dev_err (dev,"Failed to get irq\n" ); +return irq; + } + + tsadc->domain =irq_domain_add_simple (np,2 ,0 , &mx25_tsadc_domain_ops, + tsadc); +if (!tsadc->domain) { +dev_err (dev,"Failed to add irq domain\n" ); +return -ENOMEM ; + } + +irq_set_chained_handler (irq, mx25_tsadc_irq_handler); +irq_set_handler_data (irq, tsadc); + +return 0 ; +} + +static void mx25_tsadc_setup_clk (struct platform_device *pdev, +struct mx25_tsadc *tsadc) +{ +unsigned clk_div; +
Quoted 8 lines
drivers/mfd/fsl-imx25-tsadc.c line 103
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +6
-0+/* +* According to the datasheet the ADC clock should never +* exceed 1,75 MHz. Base clock is the IPG and the ADC unit uses +* a funny clock divider. To keep the time constant the ADC needs to do +* one conversion, adapt the ADC internal clock divider to +* the available IPG I'm not entirely following this explanation...
maybe
Thanks, this is indeed a bit misleading. It should be something like this:
To keep the ADC conversion time constant adapt the ADC internal clock divider to the IPG clock rate.
Will fix it.
Best Regards,
Markus
Quoted 258 lines
...one conversion, then adapt the ADC...
Quoted 238 lines
drivers/mfd/fsl-imx25-tsadc.c new file +101
-0+*/ + +dev_dbg (&pdev->dev,"Found master clock at %lu Hz\n" , +clk_get_rate (tsadc->clk)); + + clk_div =DIV_ROUND_UP (clk_get_rate (tsadc->clk),1750000 ); +dev_dbg (&pdev->dev,"Setting up ADC clock divider to %u\n" , clk_div); + +/* adc clock = IPG clock / (2 * div + 2) */ + clk_div -=2 ; + clk_div /=2 ; + +/* +* the ADC clock divider changes its behaviour when values below 4 +* are used: it is fixed to "/ 10" in this case +*/ + clk_div =max_t (unsigned,4 , clk_div); + +dev_dbg (&pdev->dev,"Resulting ADC conversion clock at %lu Hz\n" , +clk_get_rate (tsadc->clk) / (2 * clk_div +2 )); + +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR , +MX25_TGCR_ADCCLKCFG (0x1f ), +MX25_TGCR_ADCCLKCFG (clk_div)); +} + +static int mx25_tsadc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct mx25_tsadc *tsadc; +struct resource *res; +int ret; +void __iomem *iomem; + + tsadc =devm_kzalloc (dev,sizeof (*tsadc),GFP_KERNEL ); +if (!tsadc) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + iomem =devm_ioremap_resource (dev, res); +if (IS_ERR (iomem)) +return PTR_ERR (iomem); + + tsadc->regs =devm_regmap_init_mmio (dev, iomem, + &mx25_tsadc_regmap_config); +if (IS_ERR (tsadc->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (tsadc->regs); + } + + tsadc->clk =devm_clk_get (dev,"ipg" ); +if (IS_ERR (tsadc->clk)) { +dev_err (dev,"Failed to get ipg clock\n" ); +return PTR_ERR (tsadc->clk); + } + +/* setup clock according to the datasheet */ +mx25_tsadc_setup_clk (pdev, tsadc); + +/* Enable clock and reset the component */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_CLK_EN , +MX25_TGCR_CLK_EN ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_TSC_RST , +MX25_TGCR_TSC_RST ); + +/* Setup powersaving mode, but enable internal reference voltage */ +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_POWERMODE_MASK , +MX25_TGCR_POWERMODE_SAVE ); +regmap_update_bits (tsadc->regs,MX25_TSC_TGCR ,MX25_TGCR_INTREFEN , +MX25_TGCR_INTREFEN ); + + ret =mx25_tsadc_setup_irq (pdev, tsadc); +if (ret) +return ret; + +platform_set_drvdata (pdev, tsadc); + +of_platform_populate (np,NULL ,NULL , dev); + +return 0 ; +} + +static const struct of_device_id mx25_tsadc_ids[] = { + { .compatible ="fsl,imx25-tsadc" }, + {/* Sentinel */ } +}; + +static struct platform_driver mx25_tsadc_driver = { + .driver = { + .name ="mx25-tsadc" , + .of_match_table =of_match_ptr (mx25_tsadc_ids), + }, + .probe = mx25_tsadc_probe, +}; +module_platform_driver (mx25_tsadc_driver); + +MODULE_DESCRIPTION ("MFD for ADC/TSC for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:mx25-tsadc" );include/linux/mfd/imx25-tsadc.h new file +130
-0@@ -0,0 +1,140 @@ +#ifndef _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ +#define _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ + +struct regmap ; +struct clk ; + +struct mx25_tsadc { +struct regmap *regs; +struct irq_domain *domain; +struct clk *clk; +}; + +#define MX25_TSC_TGCR 0x00 +#define MX25_TSC_TGSR 0x04 +#define MX25_TSC_TICR 0x08 + +/* The same register layout for TC and GC queue */ +#define MX25_ADCQ_FIFO 0x00 +#define MX25_ADCQ_CR 0x04 +#define MX25_ADCQ_SR 0x08 +#define MX25_ADCQ_MR 0x0c +#define MX25_ADCQ_ITEM_7_0 0x20 +#define MX25_ADCQ_ITEM_15_8 0x24 +#define MX25_ADCQ_CFG (n) (0x40 + ((n) * 0x4)) + +#define MX25_ADCQ_MR_MASK 0xffffffff + +/* TGCR */ +#define MX25_TGCR_PDBTIME (x) ((x) << 25) +#define MX25_TGCR_PDBTIME_MASK GENMASK(31, 25) +#define MX25_TGCR_PDBEN BIT(24) +#define MX25_TGCR_PDEN BIT(23) +#define MX25_TGCR_ADCCLKCFG (x) ((x) << 16) +#define MX25_TGCR_GET_ADCCLK (x) (((x) >> 16) & 0x1f) +#define MX25_TGCR_INTREFEN BIT(10) +#define MX25_TGCR_POWERMODE_MASK GENMASK(9, 8) +#define MX25_TGCR_POWERMODE_SAVE (1 << 8) +#define MX25_TGCR_POWERMODE_ON (2 << 8) +#define MX25_TGCR_STLC BIT(5) +#define MX25_TGCR_SLPC BIT(4) +#define MX25_TGCR_FUNC_RST BIT(2) +#define MX25_TGCR_TSC_RST BIT(1) +#define MX25_TGCR_CLK_EN BIT(0) + +/* TGSR */ +#define MX25_TGSR_SLP_INT BIT(2) +#define MX25_TGSR_GCQ_INT BIT(1) +#define MX25_TGSR_TCQ_INT BIT(0) + +/* ADCQ_ITEM_* */ +#define _MX25_ADCQ_ITEM (item, x) ((x) << ((item) * 4)) +#define MX25_ADCQ_ITEM (item, x) ((item) >= 8 ? \ + _MX25_ADCQ_ITEM((item) - 8, (x)) : _MX25_ADCQ_ITEM((item), (x))) + +/* ADCQ_FIFO (TCQFIFO and GCQFIFO) */ +#define MX25_ADCQ_FIFO_DATA (x) (((x) >> 4) & 0xfff) +#define MX25_ADCQ_FIFO_ID (x) ((x) & 0xf) + +/* ADCQ_CR (TCQR and GCQR) */ +#define MX25_ADCQ_CR_PDCFG_LEVEL BIT(19) +#define MX25_ADCQ_CR_PDMSK BIT(18) +#define MX25_ADCQ_CR_FRST BIT(17) +#define MX25_ADCQ_CR_QRST BIT(16) +#define MX25_ADCQ_CR_RWAIT_MASK GENMASK(15, 12) +#define MX25_ADCQ_CR_RWAIT (x) ((x) << 12) +#define MX25_ADCQ_CR_WMRK_MASK GENMASK(11, 8) +#define MX25_ADCQ_CR_WMRK (x) ((x) << 8) +#define MX25_ADCQ_CR_LITEMID_MASK (0xf << 4) +#define MX25_ADCQ_CR_LITEMID (x) ((x) << 4) +#define MX25_ADCQ_CR_RPT BIT(3) +#define MX25_ADCQ_CR_FQS BIT(2) +#define MX25_ADCQ_CR_QSM_MASK GENMASK(1, 0) +#define MX25_ADCQ_CR_QSM_PD 0x1 +#define MX25_ADCQ_CR_QSM_FQS 0x2 +#define MX25_ADCQ_CR_QSM_FQS_PD 0x3 + +/* ADCQ_SR (TCQSR and GCQSR) */ +#define MX25_ADCQ_SR_FDRY BIT(15) +#define MX25_ADCQ_SR_FULL BIT(14) +#define MX25_ADCQ_SR_EMPT BIT(13) +#define MX25_ADCQ_SR_FDN (x) (((x) >> 8) & 0x1f) +#define MX25_ADCQ_SR_FRR BIT(6) +#define MX25_ADCQ_SR_FUR BIT(5) +#define MX25_ADCQ_SR_FOR BIT(4) +#define MX25_ADCQ_SR_EOQ BIT(1) +#define MX25_ADCQ_SR_PD BIT(0) + +/* ADCQ_MR (TCQMR and GCQMR) */ +#define MX25_ADCQ_MR_FDRY_DMA BIT(31) +#define MX25_ADCQ_MR_FER_DMA BIT(22) +#define MX25_ADCQ_MR_FUR_DMA BIT(21) +#define MX25_ADCQ_MR_FOR_DMA BIT(20) +#define MX25_ADCQ_MR_EOQ_DMA BIT(17) +#define MX25_ADCQ_MR_PD_DMA BIT(16) +#define MX25_ADCQ_MR_FDRY_IRQ BIT(15) +#define MX25_ADCQ_MR_FER_IRQ BIT(6) +#define MX25_ADCQ_MR_FUR_IRQ BIT(5) +#define MX25_ADCQ_MR_FOR_IRQ BIT(4) +#define MX25_ADCQ_MR_EOQ_IRQ BIT(1) +#define MX25_ADCQ_MR_PD_IRQ BIT(0) + +/* ADCQ_CFG (TICR, TCC0-7,GCC0-7) */ +#define MX25_ADCQ_CFG_SETTLING_TIME (x) ((x) << 24) +#define MX25_ADCQ_CFG_IGS (1 << 20) +#define MX25_ADCQ_CFG_NOS_MASK GENMASK(19, 16) +#define MX25_ADCQ_CFG_NOS (x) (((x) - 1) << 16) +#define MX25_ADCQ_CFG_WIPER (1 << 15) +#define MX25_ADCQ_CFG_YNLR (1 << 14) +#define MX25_ADCQ_CFG_YPLL_HIGH (0 << 12) +#define MX25_ADCQ_CFG_YPLL_OFF (1 << 12) +#define MX25_ADCQ_CFG_YPLL_LOW (3 << 12) +#define MX25_ADCQ_CFG_XNUR_HIGH (0 << 10) +#define MX25_ADCQ_CFG_XNUR_OFF (1 << 10) +#define MX25_ADCQ_CFG_XNUR_LOW (3 << 10) +#define MX25_ADCQ_CFG_XPUL_HIGH (0 << 9) +#define MX25_ADCQ_CFG_XPUL_OFF (1 << 9) +#define MX25_ADCQ_CFG_REFP (sel) ((sel) << 7) +#define MX25_ADCQ_CFG_REFP_YP MX25_ADCQ_CFG_REFP(0) +#define MX25_ADCQ_CFG_REFP_XP MX25_ADCQ_CFG_REFP(1) +#define MX25_ADCQ_CFG_REFP_EXT MX25_ADCQ_CFG_REFP(2) +#define MX25_ADCQ_CFG_REFP_INT MX25_ADCQ_CFG_REFP(3) +#define MX25_ADCQ_CFG_REFP_MASK GENMASK(8, 7) +#define MX25_ADCQ_CFG_IN (sel) ((sel) << 4) +#define MX25_ADCQ_CFG_IN_XP MX25_ADCQ_CFG_IN(0) +#define MX25_ADCQ_CFG_IN_YP MX25_ADCQ_CFG_IN(1) +#define MX25_ADCQ_CFG_IN_XN MX25_ADCQ_CFG_IN(2) +#define MX25_ADCQ_CFG_IN_YN MX25_ADCQ_CFG_IN(3) +#define MX25_ADCQ_CFG_IN_WIPER MX25_ADCQ_CFG_IN(4) +#define MX25_ADCQ_CFG_IN_AUX0 MX25_ADCQ_CFG_IN(5) +#define MX25_ADCQ_CFG_IN_AUX1 MX25_ADCQ_CFG_IN(6)include/linux/mfd/imx25-tsadc.h line 140
Quoted 10 lines
include/linux/mfd/imx25-tsadc.h new file +10
-0+#define MX25_ADCQ_CFG_IN_AUX2 MX25_ADCQ_CFG_IN(7) +#define MX25_ADCQ_CFG_REFN (sel) ((sel) << 2) +#define MX25_ADCQ_CFG_REFN_XN MX25_ADCQ_CFG_REFN(0) +#define MX25_ADCQ_CFG_REFN_YN MX25_ADCQ_CFG_REFN(1) +#define MX25_ADCQ_CFG_REFN_NGND MX25_ADCQ_CFG_REFN(2) +#define MX25_ADCQ_CFG_REFN_NGND2 MX25_ADCQ_CFG_REFN(3) +#define MX25_ADCQ_CFG_REFN_MASK GENMASK(3, 2) +#define MX25_ADCQ_CFG_PENIACK (1 << 1) + +#endif /* _LINUX_INCLUDE_MFD_IMX25_TSADC_H_ */ _______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151123/4791d005/attachment-0001.sig>
PATCH v8 5/8 iio: adc: fsl,imx25-gcq driver
In reply to Markus PargmannThis is a conversion queue driver for the mx25 SoC. It uses the central ADC which is used by two seperate independent queues. This driver prepares different conversion configurations for each possible input. For a conversion it creates a conversionqueue of one item with the correct configuration for the chosen channel. It then executes the queue once and disables the conversion queue afterwards.
The reference voltages are configurable through devicetree subnodes, depending on the connections of the ADC inputs.
---
Notes:
Changes in v7:
- Remove separate functions mx25_gcq_disable/enable_eoq() as they were used at only one position
- Enforce an external reference regulator if one of the conversions uses it as reference. The devm_regulator_get() call was moved into mx25_gcq_setup_cfgs() to be able to acquire the reference regulator when necessary.
- Store indio_dev as platform driver data instead of the private data. This was changed in probe() and remove().
Changes in v6:
- Added defines for a complete list of references in the dt binding macros
drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 415 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 441 insertions(+) create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c create mode 100644 include/dt-bindings/iio/adc/fsl-imx25-gcq.h
drivers/iio/adc/Kconfig +7 -0
@@ -183,6 +183,13 @@ config EXYNOS_ADC To compile this driver as a module, choose M here: the module will be called exynos_adc. +config FSL_MX25_ADC + tristate "Freescale MX25 ADC driver" + depends on MFD_MX25_TSADC + help + Generic Conversion Queue driver used for general purpose ADC in the + MX25. This driver supports single measurements using the MX25 ADC. + config HI8435 tristate "Holt Integrated Circuits HI-8435 threshold detector" select IIO_TRIGGERED_EVENT
drivers/iio/adc/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o
drivers/iio/adc/fsl-imx25-gcq.c new file +415 -0
415 lines not on this page · raw message
include/dt-bindings/iio/adc/fsl-imx25-gcq.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* This header provides constants for configuring the I.MX25 ADC +*/ + +#ifndef _DT_BINDINGS_IIO_ADC_FS_IMX25_GCQ_H +#define _DT_BINDINGS_IIO_ADC_FS_IMX25_GCQ_H + +#define MX25_ADC_REFP_YP 0/* YP voltage reference */ +#define MX25_ADC_REFP_XP 1/* XP voltage reference */ +#define MX25_ADC_REFP_EXT 2/* External voltage reference */ +#define MX25_ADC_REFP_INT 3/* Internal voltage reference */ + +#define MX25_ADC_REFN_XN 0/* XN ground reference */ +#define MX25_ADC_REFN_YN 1/* YN ground reference */ +#define MX25_ADC_REFN_NGND 2/* Internal ground reference */ +#define MX25_ADC_REFN_NGND2 3/* External ground reference */ + +#endif
Signature · 1 line
2.6.1
PATCH v8 6/8 input: touchscreen: imx25 tcq driver
In reply to Markus PargmannThis is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
---
Notes:
Changes in v7:
- Moved clk_prepare_enable() and mx25_tcq_init() into mx25_tcq_open(). This was done to be able to use devm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removed mx25_tcq_remove(), not necessary now
drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
drivers/input/touchscreen/Kconfig +6 -0
@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. + config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXX
drivers/input/touchscreen/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
drivers/input/touchscreen/fsl-imx25-tcq.c new file +600 -0
600 lines not on this page · raw message
Signature · 1 line
2.6.1
Dmitry Torokhov
maintainerPATCH v8 6/8 input: touchscreen: imx25 tcq driver
Quoted 36 lines · Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[fix clock's period calculation][fix calculation of the 'settling' value]Signed-off-by Juergen Borleis <[email protected]>---
Notes:
Changes in v7:
- Movedclk_prepare_enable()andmx25_tcq_init()intomx25_tcq_open(). This was done to be able to usedevm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removedmx25_tcq_remove(), not necessary nowdrivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.cdrivers/input/touchscreen/Kconfig +0
-0
drivers/input/touchscreen/Kconfig config TOUCHSCREEN_USB_COMPOSITE · line 819
Quoted 9 lines
drivers/input/touchscreen/Kconfig +6
-0@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. +
To compile this driver as a module...
Quoted 250 lines
drivers/input/touchscreen/Kconfig +0
-0config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXXdrivers/input/touchscreen/Makefile +1
-0@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.odrivers/input/touchscreen/fsl-imx25-tcq.c new file +229
-0@@ -0,0 +1,600 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +* +* Based on driver from 2011: +* Juergen Beisert, Pengutronix <[email protected]> +* +* This is the driver for the imx25 TCQ (Touchscreen Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static const char mx25_tcq_name[] ="mx25-tcq" ; + +enum mx25_tcq_mode { +MX25_TS_4WIRE , +}; + +struct mx25_tcq_priv { +struct regmap *regs; +struct regmap *core_regs; +struct input_dev *idev; +enum mx25_tcq_mode mode; +unsigned int pen_threshold; +unsigned int sample_count; +unsigned int expected_samples; +unsigned int pen_debounce; +unsigned int settling_time; +struct clk *clk; +int irq; +}; + +static struct regmap_config mx25_tcq_regconfig = { + .fast_io = true, + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static const struct of_device_id mx25_tcq_ids[] = { + { .compatible ="fsl,imx25-tcq" , }, + {/* Sentinel */ } +}; + +#define TSC_4WIRE_PRE_INDEX 0 +#define TSC_4WIRE_X_INDEX 1 +#define TSC_4WIRE_Y_INDEX 2 +#define TSC_4WIRE_POST_INDEX 3 +#define TSC_4WIRE_LEAVE 4 + +#define MX25_TSC_DEF_THRESHOLD 80 +#define TSC_MAX_SAMPLES 16 + +#define MX25_TSC_REPEAT_WAIT 14 + +enum mx25_adc_configurations { +MX25_CFG_PRECHARGE =0 , +MX25_CFG_TOUCH_DETECT , +MX25_CFG_X_MEASUREMENT , +MX25_CFG_Y_MEASUREMENT , +}; + +#define MX25_PRECHARGE_VALUE (\ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_HIGH | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_IGS) + +#define MX25_TOUCH_DETECT_VALUE (\ + MX25_ADCQ_CFG_YNLR | \ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_OFF | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_PENIACK) + +static void imx25_setup_queue_cfgs (struct mx25_tcq_priv *priv, +unsigned int settling_cnt) +{ +u32 precharge_cfg = +MX25_PRECHARGE_VALUE | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); +u32 touch_detect_cfg = +MX25_TOUCH_DETECT_VALUE | +MX25_ADCQ_CFG_NOS (1 ) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); + +regmap_write (priv->core_regs,MX25_TSC_TICR , precharge_cfg); + +/* PRECHARGE */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_PRECHARGE ), + precharge_cfg); + +/* TOUCH_DETECT */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_TOUCH_DETECT ), + touch_detect_cfg); + +/* X Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_X_MEASUREMENT ), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_LOW | +MX25_ADCQ_CFG_XPUL_HIGH | +MX25_ADCQ_CFG_REFP_XP | +MX25_ADCQ_CFG_IN_YP | +MX25_ADCQ_CFG_REFN_XN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Y Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_Y_MEASUREMENT ), +MX25_ADCQ_CFG_YNLR | +MX25_ADCQ_CFG_YPLL_HIGH | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_YP | +MX25_ADCQ_CFG_IN_XP | +MX25_ADCQ_CFG_REFN_YN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Enable the touch detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , touch_detect_cfg | +MX25_ADCQ_CFG_IGS ); +} + +static int imx25_setup_queue_4wire (struct mx25_tcq_priv *priv, +unsigned settling_cnt,int *items) +{ +imx25_setup_queue_cfgs (priv, settling_cnt); + +/* Setup the conversion queue */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (1 ,MX25_CFG_TOUCH_DETECT ) | +MX25_ADCQ_ITEM (2 ,MX25_CFG_X_MEASUREMENT ) | +MX25_ADCQ_ITEM (3 ,MX25_CFG_Y_MEASUREMENT ) | +MX25_ADCQ_ITEM (4 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (5 ,MX25_CFG_TOUCH_DETECT )); + +/* +* We measure X/Y with 'sample_count' number of samples and execute a +* touch detection twice, with 1 sample each +*/ + priv->expected_samples = priv->sample_count *2 +2 ; + *items =6 ; + +return 0 ; +} + +static void mx25_tcq_disable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK , +MX25_ADCQ_CR_PDMSK ); +} + +static void mx25_tcq_enable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK ,0 ); +} + +static void mx25_tcq_disable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ , +MX25_ADCQ_MR_FDRY_IRQ ); +} + +static void mx25_tcq_enable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ ,0 ); +} + +static void mx25_tcq_force_queue_start (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); +} + +static void mx25_tcq_force_queue_stop (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS ,0 ); +} + +static void mx25_tcq_fifo_reset (struct mx25_tcq_priv *priv) +{ +u32 tcqcr; + +regmap_read (priv->regs,MX25_ADCQ_CR , &tcqcr); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST , +MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST ,0 ); +regmap_write (priv->regs,MX25_ADCQ_CR , tcqcr); +} + +static void mx25_tcq_re_enable_touch_detection (struct mx25_tcq_priv *priv) +{ +/* stop the queue from looping */ +mx25_tcq_force_queue_stop (priv); + +/* for a clean touch detection, preload the X plane */ +regmap_write (priv->core_regs,MX25_TSC_TICR ,MX25_PRECHARGE_VALUE ); + +/* waste some time now to pre-load the X plate to high voltage */ +mx25_tcq_fifo_reset (priv); + +/* re-enable the detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , +MX25_TOUCH_DETECT_VALUE |MX25_ADCQ_CFG_IGS ); + + regmap_update_bits(priv->regs, MX25_ADCQ_SR, MX25_ADCQ_SR_PD,
drivers/input/touchscreen/fsl-imx25-tcq.c line 239
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+ MX25_ADCQ_SR_PD); + +/* enable the pen down event to be a source for the interrupt */ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_PD_IRQ ,0 ); + +/* lets fire the next IRQ if someone touches the touchscreen */ +mx25_tcq_enable_touch_irq (priv); +} + +static int mx25_tcq_create_event_for_4wire(struct mx25_tcq_priv *priv,
Why not void? What callers are supposed to do with the value?
Quoted 24 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +24
-0+ u32 *sample_buf, + unsigned int samples) +{ +unsigned int x_pos =0 ; +unsigned int y_pos =0 ; +unsigned int touch_pre =0 ; +unsigned int touch_post =0 ; +unsigned int i; +int ret =0 ; + +for (i =0 ; i < samples; i++) { +unsigned int index =MX25_ADCQ_FIFO_ID (sample_buf[i]); +unsigned int val =MX25_ADCQ_FIFO_DATA (sample_buf[i]); + +switch (index) { +case 1 : + touch_pre = val; +break ; +case 2 : + x_pos = val; +break ; +case 3 : + y_pos = val; +break ;
drivers/input/touchscreen/fsl-imx25-tcq.c line 273
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+case 5 : + touch_post = val; +break ; +default : + ret = -EINVAL ; +break ; + } + } + +if (ret ==0 && samples !=0 ) {
Where do we set ret to anything other than 0?
Quoted 66 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +66
-0+/* +* only if both touch measures are below a threshold, +* the position is valid +*/ +if (touch_pre < priv->pen_threshold && + touch_post < priv->pen_threshold) { +/* valid samples, generate a report */ + x_pos /= priv->sample_count; + y_pos /= priv->sample_count; +input_report_abs (priv->idev,ABS_X , x_pos); +input_report_abs (priv->idev,ABS_Y , y_pos); +input_report_key (priv->idev,BTN_TOUCH ,1 ); +input_sync (priv->idev); + +/* get next sample */ +mx25_tcq_enable_fifo_irq (priv); + }else if (touch_pre >= priv->pen_threshold && + touch_post >= priv->pen_threshold) { +/* +* if both samples are invalid, +* generate a release report +*/ +input_report_key (priv->idev,BTN_TOUCH ,0 ); +input_sync (priv->idev); +mx25_tcq_re_enable_touch_detection (priv); + }else { +/* +* if only one of both touch measurements are +* below the threshold, still some bouncing +* happens. Take additional samples in this +* case to be sure +*/ +mx25_tcq_enable_fifo_irq (priv); + } + } + +return ret; +} + +static irqreturn_t mx25_tcq_irq_thread (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 sample_buf[TSC_MAX_SAMPLES ]; +unsigned int samples =0 ; + +/* read all samples */ +while (1 ) { +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); +if (stats &MX25_ADCQ_SR_EMPT ) +break ; + +if (samples <TSC_MAX_SAMPLES ) { +regmap_read (priv->regs,MX25_ADCQ_FIFO , + &sample_buf[samples]); + ++samples; + }else { +u32 discarded; +/* discard samples */ +regmap_read (priv->regs,MX25_ADCQ_FIFO , &discarded); + } + } + +mx25_tcq_create_event_for_4wire (priv, sample_buf, samples); +
drivers/input/touchscreen/fsl-imx25-tcq.c line 349
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+return IRQ_HANDLED ; +} + +static irqreturn_t mx25_tcq_irq (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 stat; +int ret =IRQ_HANDLED ; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stat);
Is there any concern that these reads will fail?
Quoted 157 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +157
-0+ +if (stat & (MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR )) +mx25_tcq_fifo_reset (priv); + +if (stat &MX25_ADCQ_SR_PD ) { +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_force_queue_start (priv); +mx25_tcq_enable_fifo_irq (priv); + } + +if (stat &MX25_ADCQ_SR_FDRY ) { +mx25_tcq_disable_fifo_irq (priv); + ret =IRQ_WAKE_THREAD ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_PD |MX25_ADCQ_SR_EOQ , +MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR | +MX25_ADCQ_SR_FOR |MX25_ADCQ_SR_PD | +MX25_ADCQ_SR_EOQ ); + +return ret; +} + +/* configure the statemachine for a 4-wire touchscreen */ +static int mx25_tcq_init (struct mx25_tcq_priv *priv) +{ +u32 tgcr; +unsigned int ipg_div; +unsigned int adc_period; +unsigned int debounce_cnt; +unsigned int settling_cnt; +int itemct; +int ret; + +regmap_read (priv->core_regs,MX25_TSC_TGCR , &tgcr); + ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr)); + adc_period =USEC_PER_SEC * ipg_div *2 +2 ; + adc_period /=clk_get_rate (priv->clk) /1000 +1 ; + debounce_cnt =DIV_ROUND_UP (priv->pen_debounce, adc_period *8 ) -1 ; + settling_cnt =DIV_ROUND_UP (priv->settling_time, adc_period *8 ) -1 ; + +/* Reset */ +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ,0 ); + +/* up to 128 * 8 ADC clocks are possible */ +if (debounce_cnt >127 ) + debounce_cnt =127 ; + +/* up to 255 * 8 ADC clocks are possible */ +if (settling_cnt >255 ) + settling_cnt =255 ; + + ret =imx25_setup_queue_4wire (priv, settling_cnt, &itemct); +if (ret) +return ret; + +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_LITEMID_MASK |MX25_ADCQ_CR_WMRK_MASK , +MX25_ADCQ_CR_LITEMID (itemct -1 ) | +MX25_ADCQ_CR_WMRK (priv->expected_samples -1 )); + +/* setup debounce count */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR , +MX25_TGCR_PDBTIME_MASK , +MX25_TGCR_PDBTIME (debounce_cnt)); + +/* enable debounce */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDBEN , +MX25_TGCR_PDBEN ); +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDEN , +MX25_TGCR_PDEN ); + +/* enable the engine on demand */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_QSM_MASK , +MX25_ADCQ_CR_QSM_FQS ); + +/* Enable repeat and repeat wait */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_RPT |MX25_ADCQ_CR_RWAIT_MASK , +MX25_ADCQ_CR_RPT | +MX25_ADCQ_CR_RWAIT (MX25_TSC_REPEAT_WAIT )); + +mx25_tcq_re_enable_touch_detection (priv); + +return 0 ; +} + +static int mx25_tcq_parse_dt (struct platform_device *pdev, +struct mx25_tcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +u32 wires; +int ret; + +/* Setup defaults */ + priv->pen_threshold =500 ; + priv->sample_count =3 ; + priv->pen_debounce =1000000 ; + priv->settling_time =250000 ; + + ret =of_property_read_u32 (np,"fsl,wires" , &wires); +if (ret) { +dev_err (&pdev->dev,"Failed to find fsl,wires properties\n" ); +return ret; + } + +if (wires ==4 ) { + priv->mode =MX25_TS_4WIRE ; + }else { +dev_err (&pdev->dev,"%u-wire mode not supported\n" , wires); +return -EINVAL ; + } + +/* These are optional, we don't care about the return values */ +of_property_read_u32 (np,"fsl,pen-threshold" , &priv->pen_threshold); +of_property_read_u32 (np,"fsl,settling-time" , &priv->settling_time); +of_property_read_u32 (np,"fsl,pen-debounce" , &priv->pen_debounce); + +return 0 ; +} + +static int mx25_tcq_open (struct input_dev *idev) +{ +struct device *dev = &idev->dev; +struct mx25_tcq_priv *priv =dev_get_drvdata (dev); +int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable ipg clock\n" ); +return ret; + } + + ret =mx25_tcq_init (priv); +if (ret) { +dev_err (dev,"Failed to init tcq\n" ); +clk_disable_unprepare (priv->clk); +return ret; + } + +return 0 ; +} + +static void mx25_tcq_close (struct input_dev *idev) +{ +struct mx25_tcq_priv *priv =input_get_drvdata (idev); + +mx25_tcq_force_queue_stop (priv); +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_disable_fifo_irq (priv); +clk_disable_unprepare (priv->clk); +}
drivers/input/touchscreen/fsl-imx25-tcq.c line 516
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+ +static int mx25_tcq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct input_dev *idev; +struct mx25_tcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct resource *res; +void __iomem *mem; +int ret;
Personal preference: can we call variables that hold error codes and not returned in success path (i.e. when we do explicit "return 0:' for success) be called "error"?
drivers/input/touchscreen/fsl-imx25-tcq.c line 524
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+ + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem)
devm_ioremap_resource() returns ERR_PTR-encoded pointer, you should not test it for NULL bit rather for IS_ERR.
Quoted 17 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +17
-0+return -ENOMEM ; + + ret =mx25_tcq_parse_dt (pdev, priv); +if (ret) +return ret; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_tcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); +return priv->irq; + }
drivers/input/touchscreen/fsl-imx25-tcq.c line 551
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+ + idev =devm_input_allocate_device (dev); +if (!idev) { +dev_err (dev,"Failed to allocate input device\n" ); +return -ENOMEM ; + } + + idev->name = mx25_tcq_name; + idev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); + idev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH );
Replace the 2 lines above with:
input_set_capability(idev, EV_BTN_TOUCH);
Quoted 23 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +23
-0+input_set_abs_params (idev,ABS_X ,0 ,0xfff ,0 ,0 ); +input_set_abs_params (idev,ABS_Y ,0 ,0xfff ,0 ,0 ); + + idev->id.bustype =BUS_HOST ; + idev->open = mx25_tcq_open; + idev->close = mx25_tcq_close; + + priv->idev = idev; +input_set_drvdata (idev, priv); + + priv->core_regs = tsadc->regs; +if (!priv->core_regs) +return -EINVAL ; + + priv->clk = tsadc->clk; +if (!priv->clk) +return -EINVAL ; + +platform_set_drvdata (pdev, priv); + + ret =input_register_device (idev); +if (ret) { +dev_err (dev,"Failed to register input device\n" );
drivers/input/touchscreen/fsl-imx25-tcq.c line 584
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+return ret; + } + + ret =devm_request_threaded_irq (dev, priv->irq, mx25_tcq_irq, + mx25_tcq_irq_thread,IRQF_ONESHOT , + pdev->name, priv); +if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); +return ret; + }
Is it possible that we enable interrupt generation in the controller (in mx25_tcq_open) before we request IRQ and then (if someone touches the screen) we'll get a spurious IRQ? I'd rather we swapped devm_request_threaded_irq() and input_register_device(): it is perfectly safe to use (send events) to allocated but not registered input device.
Quoted 19 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +16
-0+ +return 0 ; +} + +static struct platform_driver mx25_tcq_driver = { + .driver = { + .name ="mx25-tcq" , + .of_match_table = mx25_tcq_ids, + }, + .probe = mx25_tcq_probe, +}; +module_platform_driver (mx25_tcq_driver); + +MODULE_DESCRIPTION ("TS input driver for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.6.1
Thanks.
Signature · 1 line
Dmitry
PATCH v8 6/8 input: touchscreen: imx25 tcq driver
Hi,
Quoted 303 lines · On Tuesday 17 November 2015 10:17:20 Dmitry Torokhov wrote:
Quoted 36 lines · Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[fix clock's period calculation][fix calculation of the 'settling' value]Signed-off-by Juergen Borleis <[email protected]>---
Notes:
Changes in v7:
- Movedclk_prepare_enable()andmx25_tcq_init()intomx25_tcq_open(). This was done to be able to usedevm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removedmx25_tcq_remove(), not necessary nowdrivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.cdrivers/input/touchscreen/Kconfig +0
-0drivers/input/touchscreen/Kconfig config TOUCHSCREEN_USB_COMPOSITE · line 819
Quoted 9 lines
drivers/input/touchscreen/Kconfig +6
-0@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. +To compile this driver as a module...
Quoted 254 lines
drivers/input/touchscreen/Kconfig +0
-0config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXXdrivers/input/touchscreen/Makefile +1
-0@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.odrivers/input/touchscreen/fsl-imx25-tcq.c new file +233
-0@@ -0,0 +1,600 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +* +* Based on driver from 2011: +* Juergen Beisert, Pengutronix <[email protected]> +* +* This is the driver for the imx25 TCQ (Touchscreen Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static const char mx25_tcq_name[] ="mx25-tcq" ; + +enum mx25_tcq_mode { +MX25_TS_4WIRE , +}; + +struct mx25_tcq_priv { +struct regmap *regs; +struct regmap *core_regs; +struct input_dev *idev; +enum mx25_tcq_mode mode; +unsigned int pen_threshold; +unsigned int sample_count; +unsigned int expected_samples; +unsigned int pen_debounce; +unsigned int settling_time; +struct clk *clk; +int irq; +}; + +static struct regmap_config mx25_tcq_regconfig = { + .fast_io = true, + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static const struct of_device_id mx25_tcq_ids[] = { + { .compatible ="fsl,imx25-tcq" , }, + {/* Sentinel */ } +}; + +#define TSC_4WIRE_PRE_INDEX 0 +#define TSC_4WIRE_X_INDEX 1 +#define TSC_4WIRE_Y_INDEX 2 +#define TSC_4WIRE_POST_INDEX 3 +#define TSC_4WIRE_LEAVE 4 + +#define MX25_TSC_DEF_THRESHOLD 80 +#define TSC_MAX_SAMPLES 16 + +#define MX25_TSC_REPEAT_WAIT 14 + +enum mx25_adc_configurations { +MX25_CFG_PRECHARGE =0 , +MX25_CFG_TOUCH_DETECT , +MX25_CFG_X_MEASUREMENT , +MX25_CFG_Y_MEASUREMENT , +}; + +#define MX25_PRECHARGE_VALUE (\ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_HIGH | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_IGS) + +#define MX25_TOUCH_DETECT_VALUE (\ + MX25_ADCQ_CFG_YNLR | \ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_OFF | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_PENIACK) + +static void imx25_setup_queue_cfgs (struct mx25_tcq_priv *priv, +unsigned int settling_cnt) +{ +u32 precharge_cfg = +MX25_PRECHARGE_VALUE | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); +u32 touch_detect_cfg = +MX25_TOUCH_DETECT_VALUE | +MX25_ADCQ_CFG_NOS (1 ) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); + +regmap_write (priv->core_regs,MX25_TSC_TICR , precharge_cfg); + +/* PRECHARGE */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_PRECHARGE ), + precharge_cfg); + +/* TOUCH_DETECT */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_TOUCH_DETECT ), + touch_detect_cfg); + +/* X Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_X_MEASUREMENT ), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_LOW | +MX25_ADCQ_CFG_XPUL_HIGH | +MX25_ADCQ_CFG_REFP_XP | +MX25_ADCQ_CFG_IN_YP | +MX25_ADCQ_CFG_REFN_XN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Y Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_Y_MEASUREMENT ), +MX25_ADCQ_CFG_YNLR | +MX25_ADCQ_CFG_YPLL_HIGH | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_YP | +MX25_ADCQ_CFG_IN_XP | +MX25_ADCQ_CFG_REFN_YN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Enable the touch detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , touch_detect_cfg | +MX25_ADCQ_CFG_IGS ); +} + +static int imx25_setup_queue_4wire (struct mx25_tcq_priv *priv, +unsigned settling_cnt,int *items) +{ +imx25_setup_queue_cfgs (priv, settling_cnt); + +/* Setup the conversion queue */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (1 ,MX25_CFG_TOUCH_DETECT ) | +MX25_ADCQ_ITEM (2 ,MX25_CFG_X_MEASUREMENT ) | +MX25_ADCQ_ITEM (3 ,MX25_CFG_Y_MEASUREMENT ) | +MX25_ADCQ_ITEM (4 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (5 ,MX25_CFG_TOUCH_DETECT )); + +/* +* We measure X/Y with 'sample_count' number of samples and execute a +* touch detection twice, with 1 sample each +*/ + priv->expected_samples = priv->sample_count *2 +2 ; + *items =6 ; + +return 0 ; +} + +static void mx25_tcq_disable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK , +MX25_ADCQ_CR_PDMSK ); +} + +static void mx25_tcq_enable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK ,0 ); +} + +static void mx25_tcq_disable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ , +MX25_ADCQ_MR_FDRY_IRQ ); +} + +static void mx25_tcq_enable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ ,0 ); +} + +static void mx25_tcq_force_queue_start (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); +} + +static void mx25_tcq_force_queue_stop (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS ,0 ); +} + +static void mx25_tcq_fifo_reset (struct mx25_tcq_priv *priv) +{ +u32 tcqcr; + +regmap_read (priv->regs,MX25_ADCQ_CR , &tcqcr); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST , +MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST ,0 ); +regmap_write (priv->regs,MX25_ADCQ_CR , tcqcr); +} + +static void mx25_tcq_re_enable_touch_detection (struct mx25_tcq_priv *priv) +{ +/* stop the queue from looping */ +mx25_tcq_force_queue_stop (priv); + +/* for a clean touch detection, preload the X plane */ +regmap_write (priv->core_regs,MX25_TSC_TICR ,MX25_PRECHARGE_VALUE ); + +/* waste some time now to pre-load the X plate to high voltage */ +mx25_tcq_fifo_reset (priv); + +/* re-enable the detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , +MX25_TOUCH_DETECT_VALUE |MX25_ADCQ_CFG_IGS ); + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_PD , +MX25_ADCQ_SR_PD ); + +/* enable the pen down event to be a source for the interrupt */ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_PD_IRQ ,0 );
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 239
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+ +/* lets fire the next IRQ if someone touches the touchscreen */ +mx25_tcq_enable_touch_irq (priv); +} + +static int mx25_tcq_create_event_for_4wire(struct mx25_tcq_priv *priv,Why not void? What callers are supposed to do with the value?
Good point.
Quoted 29 lines
Quoted 29 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +28
-0+ u32 *sample_buf, + unsigned int samples) +{ +unsigned int x_pos =0 ; +unsigned int y_pos =0 ; +unsigned int touch_pre =0 ; +unsigned int touch_post =0 ; +unsigned int i; +int ret =0 ; + +for (i =0 ; i < samples; i++) { +unsigned int index =MX25_ADCQ_FIFO_ID (sample_buf[i]); +unsigned int val =MX25_ADCQ_FIFO_DATA (sample_buf[i]); + +switch (index) { +case 1 : + touch_pre = val; +break ; +case 2 : + x_pos = val; +break ; +case 3 : + y_pos = val; +break ; +case 5 : + touch_post = val; +break ; +default :
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 273
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+ ret = -EINVAL ; +break ; + } + } + +if (ret ==0 && samples !=0 ) {Where do we set ret to anything other than 0?
In the default case above.
I replaced the return -EINVAL with a debug message. This case shouldn't happen but just in case it does..
Quoted 71 lines
Quoted 71 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +70
-0+/* +* only if both touch measures are below a threshold, +* the position is valid +*/ +if (touch_pre < priv->pen_threshold && + touch_post < priv->pen_threshold) { +/* valid samples, generate a report */ + x_pos /= priv->sample_count; + y_pos /= priv->sample_count; +input_report_abs (priv->idev,ABS_X , x_pos); +input_report_abs (priv->idev,ABS_Y , y_pos); +input_report_key (priv->idev,BTN_TOUCH ,1 ); +input_sync (priv->idev); + +/* get next sample */ +mx25_tcq_enable_fifo_irq (priv); + }else if (touch_pre >= priv->pen_threshold && + touch_post >= priv->pen_threshold) { +/* +* if both samples are invalid, +* generate a release report +*/ +input_report_key (priv->idev,BTN_TOUCH ,0 ); +input_sync (priv->idev); +mx25_tcq_re_enable_touch_detection (priv); + }else { +/* +* if only one of both touch measurements are +* below the threshold, still some bouncing +* happens. Take additional samples in this +* case to be sure +*/ +mx25_tcq_enable_fifo_irq (priv); + } + } + +return ret; +} + +static irqreturn_t mx25_tcq_irq_thread (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 sample_buf[TSC_MAX_SAMPLES ]; +unsigned int samples =0 ; + +/* read all samples */ +while (1 ) { +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); +if (stats &MX25_ADCQ_SR_EMPT ) +break ; + +if (samples <TSC_MAX_SAMPLES ) { +regmap_read (priv->regs,MX25_ADCQ_FIFO , + &sample_buf[samples]); + ++samples; + }else { +u32 discarded; +/* discard samples */ +regmap_read (priv->regs,MX25_ADCQ_FIFO , &discarded); + } + } + +mx25_tcq_create_event_for_4wire (priv, sample_buf, samples); + +return IRQ_HANDLED ; +} + +static irqreturn_t mx25_tcq_irq (int irq,void *dev_id)
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 349
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+{ +struct mx25_tcq_priv *priv = dev_id; +u32 stat; +int ret =IRQ_HANDLED ; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stat);Is there any concern that these reads will fail?
This is always using mmio and we do not use the register clock feature. So it shouldn't fail.
Quoted 164 lines
Quoted 164 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +163
-0+ +if (stat & (MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR )) +mx25_tcq_fifo_reset (priv); + +if (stat &MX25_ADCQ_SR_PD ) { +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_force_queue_start (priv); +mx25_tcq_enable_fifo_irq (priv); + } + +if (stat &MX25_ADCQ_SR_FDRY ) { +mx25_tcq_disable_fifo_irq (priv); + ret =IRQ_WAKE_THREAD ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_PD |MX25_ADCQ_SR_EOQ , +MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR | +MX25_ADCQ_SR_FOR |MX25_ADCQ_SR_PD | +MX25_ADCQ_SR_EOQ ); + +return ret; +} + +/* configure the statemachine for a 4-wire touchscreen */ +static int mx25_tcq_init (struct mx25_tcq_priv *priv) +{ +u32 tgcr; +unsigned int ipg_div; +unsigned int adc_period; +unsigned int debounce_cnt; +unsigned int settling_cnt; +int itemct; +int ret; + +regmap_read (priv->core_regs,MX25_TSC_TGCR , &tgcr); + ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr)); + adc_period =USEC_PER_SEC * ipg_div *2 +2 ; + adc_period /=clk_get_rate (priv->clk) /1000 +1 ; + debounce_cnt =DIV_ROUND_UP (priv->pen_debounce, adc_period *8 ) -1 ; + settling_cnt =DIV_ROUND_UP (priv->settling_time, adc_period *8 ) -1 ; + +/* Reset */ +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ,0 ); + +/* up to 128 * 8 ADC clocks are possible */ +if (debounce_cnt >127 ) + debounce_cnt =127 ; + +/* up to 255 * 8 ADC clocks are possible */ +if (settling_cnt >255 ) + settling_cnt =255 ; + + ret =imx25_setup_queue_4wire (priv, settling_cnt, &itemct); +if (ret) +return ret; + +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_LITEMID_MASK |MX25_ADCQ_CR_WMRK_MASK , +MX25_ADCQ_CR_LITEMID (itemct -1 ) | +MX25_ADCQ_CR_WMRK (priv->expected_samples -1 )); + +/* setup debounce count */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR , +MX25_TGCR_PDBTIME_MASK , +MX25_TGCR_PDBTIME (debounce_cnt)); + +/* enable debounce */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDBEN , +MX25_TGCR_PDBEN ); +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDEN , +MX25_TGCR_PDEN ); + +/* enable the engine on demand */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_QSM_MASK , +MX25_ADCQ_CR_QSM_FQS ); + +/* Enable repeat and repeat wait */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_RPT |MX25_ADCQ_CR_RWAIT_MASK , +MX25_ADCQ_CR_RPT | +MX25_ADCQ_CR_RWAIT (MX25_TSC_REPEAT_WAIT )); + +mx25_tcq_re_enable_touch_detection (priv); + +return 0 ; +} + +static int mx25_tcq_parse_dt (struct platform_device *pdev, +struct mx25_tcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +u32 wires; +int ret; + +/* Setup defaults */ + priv->pen_threshold =500 ; + priv->sample_count =3 ; + priv->pen_debounce =1000000 ; + priv->settling_time =250000 ; + + ret =of_property_read_u32 (np,"fsl,wires" , &wires); +if (ret) { +dev_err (&pdev->dev,"Failed to find fsl,wires properties\n" ); +return ret; + } + +if (wires ==4 ) { + priv->mode =MX25_TS_4WIRE ; + }else { +dev_err (&pdev->dev,"%u-wire mode not supported\n" , wires); +return -EINVAL ; + } + +/* These are optional, we don't care about the return values */ +of_property_read_u32 (np,"fsl,pen-threshold" , &priv->pen_threshold); +of_property_read_u32 (np,"fsl,settling-time" , &priv->settling_time); +of_property_read_u32 (np,"fsl,pen-debounce" , &priv->pen_debounce); + +return 0 ; +} + +static int mx25_tcq_open (struct input_dev *idev) +{ +struct device *dev = &idev->dev; +struct mx25_tcq_priv *priv =dev_get_drvdata (dev); +int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable ipg clock\n" ); +return ret; + } + + ret =mx25_tcq_init (priv); +if (ret) { +dev_err (dev,"Failed to init tcq\n" ); +clk_disable_unprepare (priv->clk); +return ret; + } + +return 0 ; +} + +static void mx25_tcq_close (struct input_dev *idev) +{ +struct mx25_tcq_priv *priv =input_get_drvdata (idev); + +mx25_tcq_force_queue_stop (priv); +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_disable_fifo_irq (priv); +clk_disable_unprepare (priv->clk); +} + +static int mx25_tcq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct input_dev *idev; +struct mx25_tcq_priv *priv;
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 516
Quoted 4 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +4
-0+struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct resource *res; +void __iomem *mem; +int ret;Personal preference: can we call variables that hold error codes and not returned in success path (i.e. when we do explicit "return 0:' for success) be called "error"?
Yes that's fine for me, changed it for most functions in this driver.
Quoted 11 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 524
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+ + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem)
devm_ioremap_resource()returns ERR_PTR-encoded pointer, you should not test it for NULL bit rather forIS_ERR.
Fixed, thanks.
Quoted 31 lines
Quoted 18 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +17
-0+return -ENOMEM ; + + ret =mx25_tcq_parse_dt (pdev, priv); +if (ret) +return ret; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_tcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); +return priv->irq; + }drivers/input/touchscreen/fsl-imx25-tcq.c line 551
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+ + idev =devm_input_allocate_device (dev); +if (!idev) { +dev_err (dev,"Failed to allocate input device\n" ); +return -ENOMEM ; + } + + idev->name = mx25_tcq_name; + idev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); + idev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH );Replace the 2 lines above with:
Quoted 1 line
input_set_capability(idev, EV_BTN_TOUCH);
I assume you meant
input_set_capability(idev, EV_KEY, BTN_TOUCH);
and changed it to that.
Quoted 32 lines
Quoted 32 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +31
-0+input_set_abs_params (idev,ABS_X ,0 ,0xfff ,0 ,0 ); +input_set_abs_params (idev,ABS_Y ,0 ,0xfff ,0 ,0 ); + + idev->id.bustype =BUS_HOST ; + idev->open = mx25_tcq_open; + idev->close = mx25_tcq_close; + + priv->idev = idev; +input_set_drvdata (idev, priv); + + priv->core_regs = tsadc->regs; +if (!priv->core_regs) +return -EINVAL ; + + priv->clk = tsadc->clk; +if (!priv->clk) +return -EINVAL ; + +platform_set_drvdata (pdev, priv); + + ret =input_register_device (idev); +if (ret) { +dev_err (dev,"Failed to register input device\n" ); +return ret; + } + + ret =devm_request_threaded_irq (dev, priv->irq, mx25_tcq_irq, + mx25_tcq_irq_thread,IRQF_ONESHOT , + pdev->name, priv); +if (ret) { +dev_err (dev,"Failed requesting IRQ\n" );
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 584
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+return ret; + }Is it possible that we enable interrupt generation in the controller (in
mx25_tcq_open) before we request IRQ and then (if someone touches the screen) we'll get a spurious IRQ? I'd rather we swappeddevm_request_threaded_irq()andinput_register_device(): it is perfectly safe to use (send events) to allocated but not registered input device.
Ok, if it is safe to send events for an allocated device I can't see why the irq request shouldn't be first. I swapped these.
Thanks,
Markus
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151120/b19006d4/attachment-0001.sig>
Jonathan Cameron
maintainerPATCH v8 6/8 input: touchscreen: imx25 tcq driver
In reply to Markus PargmannQuoted 10 lines · Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
Quoted 6 lines
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[fix clock's period calculation][fix calculation of the 'settling' value]Signed-off-by Juergen Borleis <[email protected]>
I read this out of curiousity to see how you had handled the touchscreen usecase of this hardware differently from the generic version.
Anyhow, a few little bits and pieces inline from me as a result
Jonathan
Quoted 207 lines
---
Notes:
Changes in v7:
- Movedclk_prepare_enable()andmx25_tcq_init()intomx25_tcq_open(). This was done to be able to usedevm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removedmx25_tcq_remove(), not necessary nowdrivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.cdrivers/input/touchscreen/Kconfig +6
-0@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. + config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXXdrivers/input/touchscreen/Makefile +1
-0@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.odrivers/input/touchscreen/fsl-imx25-tcq.c new file +157
-0@@ -0,0 +1,600 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +* +* Based on driver from 2011: +* Juergen Beisert, Pengutronix <[email protected]> +* +* This is the driver for the imx25 TCQ (Touchscreen Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static const char mx25_tcq_name[] ="mx25-tcq" ; + +enum mx25_tcq_mode { +MX25_TS_4WIRE , +}; + +struct mx25_tcq_priv { +struct regmap *regs; +struct regmap *core_regs; +struct input_dev *idev; +enum mx25_tcq_mode mode; +unsigned int pen_threshold; +unsigned int sample_count; +unsigned int expected_samples; +unsigned int pen_debounce; +unsigned int settling_time; +struct clk *clk; +int irq; +}; + +static struct regmap_config mx25_tcq_regconfig = { + .fast_io = true, + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static const struct of_device_id mx25_tcq_ids[] = { + { .compatible ="fsl,imx25-tcq" , }, + {/* Sentinel */ } +}; + +#define TSC_4WIRE_PRE_INDEX 0 +#define TSC_4WIRE_X_INDEX 1 +#define TSC_4WIRE_Y_INDEX 2 +#define TSC_4WIRE_POST_INDEX 3 +#define TSC_4WIRE_LEAVE 4 + +#define MX25_TSC_DEF_THRESHOLD 80 +#define TSC_MAX_SAMPLES 16 + +#define MX25_TSC_REPEAT_WAIT 14 + +enum mx25_adc_configurations { +MX25_CFG_PRECHARGE =0 , +MX25_CFG_TOUCH_DETECT , +MX25_CFG_X_MEASUREMENT , +MX25_CFG_Y_MEASUREMENT , +}; + +#define MX25_PRECHARGE_VALUE (\ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_HIGH | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_IGS) + +#define MX25_TOUCH_DETECT_VALUE (\ + MX25_ADCQ_CFG_YNLR | \ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_OFF | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_PENIACK) + +static void imx25_setup_queue_cfgs (struct mx25_tcq_priv *priv, +unsigned int settling_cnt) +{ +u32 precharge_cfg = +MX25_PRECHARGE_VALUE | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); +u32 touch_detect_cfg = +MX25_TOUCH_DETECT_VALUE | +MX25_ADCQ_CFG_NOS (1 ) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); + +regmap_write (priv->core_regs,MX25_TSC_TICR , precharge_cfg); + +/* PRECHARGE */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_PRECHARGE ), + precharge_cfg); + +/* TOUCH_DETECT */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_TOUCH_DETECT ), + touch_detect_cfg); + +/* X Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_X_MEASUREMENT ), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_LOW | +MX25_ADCQ_CFG_XPUL_HIGH | +MX25_ADCQ_CFG_REFP_XP | +MX25_ADCQ_CFG_IN_YP | +MX25_ADCQ_CFG_REFN_XN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Y Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_Y_MEASUREMENT ), +MX25_ADCQ_CFG_YNLR | +MX25_ADCQ_CFG_YPLL_HIGH | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_YP | +MX25_ADCQ_CFG_IN_XP | +MX25_ADCQ_CFG_REFN_YN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Enable the touch detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , touch_detect_cfg | +MX25_ADCQ_CFG_IGS ); +} + +static int imx25_setup_queue_4wire (struct mx25_tcq_priv *priv, +unsigned settling_cnt,int *items) +{ +imx25_setup_queue_cfgs (priv, settling_cnt); + +/* Setup the conversion queue */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (1 ,MX25_CFG_TOUCH_DETECT ) | +MX25_ADCQ_ITEM (2 ,MX25_CFG_X_MEASUREMENT ) | +MX25_ADCQ_ITEM (3 ,MX25_CFG_Y_MEASUREMENT ) | +MX25_ADCQ_ITEM (4 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (5 ,MX25_CFG_TOUCH_DETECT )); +
drivers/input/touchscreen/fsl-imx25-tcq.c line 167
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+/* +* We measure X/Y with 'sample_count' number of samples and execute a +* touch detection twice, with 1 sample each +*/ + priv->expected_samples = priv->sample_count *2 +2 ; + *items =6 ; + +return 0 ; +} +
Another personal preference. I'd not bother wrapping these single line calls up but rather just make them inline. They don't in of themselves add much to my mind. Still this one is very much up to you as far as I'm concerned.
Quoted 142 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +142
-0+static void mx25_tcq_disable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK , +MX25_ADCQ_CR_PDMSK ); +} + +static void mx25_tcq_enable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK ,0 ); +} + +static void mx25_tcq_disable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ , +MX25_ADCQ_MR_FDRY_IRQ ); +} + +static void mx25_tcq_enable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ ,0 ); +} + +static void mx25_tcq_force_queue_start (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); +} + +static void mx25_tcq_force_queue_stop (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS ,0 ); +} + +static void mx25_tcq_fifo_reset (struct mx25_tcq_priv *priv) +{ +u32 tcqcr; + +regmap_read (priv->regs,MX25_ADCQ_CR , &tcqcr); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST , +MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST ,0 ); +regmap_write (priv->regs,MX25_ADCQ_CR , tcqcr); +} + +static void mx25_tcq_re_enable_touch_detection (struct mx25_tcq_priv *priv) +{ +/* stop the queue from looping */ +mx25_tcq_force_queue_stop (priv); + +/* for a clean touch detection, preload the X plane */ +regmap_write (priv->core_regs,MX25_TSC_TICR ,MX25_PRECHARGE_VALUE ); + +/* waste some time now to pre-load the X plate to high voltage */ +mx25_tcq_fifo_reset (priv); + +/* re-enable the detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , +MX25_TOUCH_DETECT_VALUE |MX25_ADCQ_CFG_IGS ); + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_PD , +MX25_ADCQ_SR_PD ); + +/* enable the pen down event to be a source for the interrupt */ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_PD_IRQ ,0 ); + +/* lets fire the next IRQ if someone touches the touchscreen */ +mx25_tcq_enable_touch_irq (priv); +} + +static int mx25_tcq_create_event_for_4wire (struct mx25_tcq_priv *priv, +u32 *sample_buf, +unsigned int samples) +{ +unsigned int x_pos =0 ; +unsigned int y_pos =0 ; +unsigned int touch_pre =0 ; +unsigned int touch_post =0 ; +unsigned int i; +int ret =0 ; + +for (i =0 ; i < samples; i++) { +unsigned int index =MX25_ADCQ_FIFO_ID (sample_buf[i]); +unsigned int val =MX25_ADCQ_FIFO_DATA (sample_buf[i]); + +switch (index) { +case 1 : + touch_pre = val; +break ; +case 2 : + x_pos = val; +break ; +case 3 : + y_pos = val; +break ; +case 5 : + touch_post = val; +break ; +default : + ret = -EINVAL ; +break ; + } + } + +if (ret ==0 && samples !=0 ) { +/* +* only if both touch measures are below a threshold, +* the position is valid +*/ +if (touch_pre < priv->pen_threshold && + touch_post < priv->pen_threshold) { +/* valid samples, generate a report */ + x_pos /= priv->sample_count; + y_pos /= priv->sample_count; +input_report_abs (priv->idev,ABS_X , x_pos); +input_report_abs (priv->idev,ABS_Y , y_pos); +input_report_key (priv->idev,BTN_TOUCH ,1 ); +input_sync (priv->idev); + +/* get next sample */ +mx25_tcq_enable_fifo_irq (priv); + }else if (touch_pre >= priv->pen_threshold && + touch_post >= priv->pen_threshold) { +/* +* if both samples are invalid, +* generate a release report +*/ +input_report_key (priv->idev,BTN_TOUCH ,0 ); +input_sync (priv->idev); +mx25_tcq_re_enable_touch_detection (priv); + }else { +/* +* if only one of both touch measurements are +* below the threshold, still some bouncing +* happens. Take additional samples in this +* case to be sure +*/ +mx25_tcq_enable_fifo_irq (priv); + } + } +
drivers/input/touchscreen/fsl-imx25-tcq.c line 319
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+return ret; +} + +static irqreturn_t mx25_tcq_irq_thread (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 sample_buf[TSC_MAX_SAMPLES ]; +unsigned int samples =0 ; + +/* read all samples */
It's not a terribly big fifo, so I'm not convinced personally of the merits of having the separate thread for this interrupt...
Quoted 5 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+while (1 ) { +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); +if (stats &MX25_ADCQ_SR_EMPT )
drivers/input/touchscreen/fsl-imx25-tcq.c line 334
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+break ; + +if (samples <TSC_MAX_SAMPLES ) { +regmap_read (priv->regs,MX25_ADCQ_FIFO , + &sample_buf[samples]); + ++samples; + }else { +u32 discarded; +/* discard samples */ +regmap_read (priv->regs,MX25_ADCQ_FIFO , &discarded);
Comment on how this could happen would be good.
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+ } + } + +mx25_tcq_create_event_for_4wire (priv, sample_buf, samples); + +return IRQ_HANDLED ; +} +
drivers/input/touchscreen/fsl-imx25-tcq.c line 352
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+static irqreturn_t mx25_tcq_irq (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 stat; +int ret =IRQ_HANDLED ; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stat); + +if (stat & (MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR )) +mx25_tcq_fifo_reset (priv);
Again, currious cross comparison with the adc driver (hardware is pretty much the same ;) In there you don't reset the fifo if you get one of these. Why not? Now you should never get one as you only ever schedule a single reading, but best to be consistent.
drivers/input/touchscreen/fsl-imx25-tcq.c line 361
Quoted 9 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ +if (stat &MX25_ADCQ_SR_PD ) { +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_force_queue_start (priv); +mx25_tcq_enable_fifo_irq (priv); + } + +if (stat &MX25_ADCQ_SR_FDRY ) { +mx25_tcq_disable_fifo_irq (priv);
I'm missing something I think.. In a oneshot irq the irq will be masked anyway till the thread is done. Why the explicit disable as well?
drivers/input/touchscreen/fsl-imx25-tcq.c line 370
Quoted 9 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ ret =IRQ_WAKE_THREAD ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_PD |MX25_ADCQ_SR_EOQ , +MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR | +MX25_ADCQ_SR_FOR |MX25_ADCQ_SR_PD | +MX25_ADCQ_SR_EOQ );
As with the adc driver you are clearing at least one bit that should not I think ever be set... EOQ. Why?
drivers/input/touchscreen/fsl-imx25-tcq.c line 375
Quoted 5 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+ +return ret; +} + +/* configure the statemachine for a 4-wire touchscreen */
state machine
Quoted 104 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +104
-0+static int mx25_tcq_init (struct mx25_tcq_priv *priv) +{ +u32 tgcr; +unsigned int ipg_div; +unsigned int adc_period; +unsigned int debounce_cnt; +unsigned int settling_cnt; +int itemct; +int ret; + +regmap_read (priv->core_regs,MX25_TSC_TGCR , &tgcr); + ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr)); + adc_period =USEC_PER_SEC * ipg_div *2 +2 ; + adc_period /=clk_get_rate (priv->clk) /1000 +1 ; + debounce_cnt =DIV_ROUND_UP (priv->pen_debounce, adc_period *8 ) -1 ; + settling_cnt =DIV_ROUND_UP (priv->settling_time, adc_period *8 ) -1 ; + +/* Reset */ +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ,0 ); + +/* up to 128 * 8 ADC clocks are possible */ +if (debounce_cnt >127 ) + debounce_cnt =127 ; + +/* up to 255 * 8 ADC clocks are possible */ +if (settling_cnt >255 ) + settling_cnt =255 ; + + ret =imx25_setup_queue_4wire (priv, settling_cnt, &itemct); +if (ret) +return ret; + +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_LITEMID_MASK |MX25_ADCQ_CR_WMRK_MASK , +MX25_ADCQ_CR_LITEMID (itemct -1 ) | +MX25_ADCQ_CR_WMRK (priv->expected_samples -1 )); + +/* setup debounce count */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR , +MX25_TGCR_PDBTIME_MASK , +MX25_TGCR_PDBTIME (debounce_cnt)); + +/* enable debounce */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDBEN , +MX25_TGCR_PDBEN ); +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDEN , +MX25_TGCR_PDEN ); + +/* enable the engine on demand */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_QSM_MASK , +MX25_ADCQ_CR_QSM_FQS ); + +/* Enable repeat and repeat wait */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_RPT |MX25_ADCQ_CR_RWAIT_MASK , +MX25_ADCQ_CR_RPT | +MX25_ADCQ_CR_RWAIT (MX25_TSC_REPEAT_WAIT )); + +mx25_tcq_re_enable_touch_detection (priv); + +return 0 ; +} + +static int mx25_tcq_parse_dt (struct platform_device *pdev, +struct mx25_tcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +u32 wires; +int ret; + +/* Setup defaults */ + priv->pen_threshold =500 ; + priv->sample_count =3 ; + priv->pen_debounce =1000000 ; + priv->settling_time =250000 ; + + ret =of_property_read_u32 (np,"fsl,wires" , &wires); +if (ret) { +dev_err (&pdev->dev,"Failed to find fsl,wires properties\n" ); +return ret; + } + +if (wires ==4 ) { + priv->mode =MX25_TS_4WIRE ; + }else { +dev_err (&pdev->dev,"%u-wire mode not supported\n" , wires); +return -EINVAL ; + } + +/* These are optional, we don't care about the return values */ +of_property_read_u32 (np,"fsl,pen-threshold" , &priv->pen_threshold); +of_property_read_u32 (np,"fsl,settling-time" , &priv->settling_time); +of_property_read_u32 (np,"fsl,pen-debounce" , &priv->pen_debounce); + +return 0 ; +} + +static int mx25_tcq_open (struct input_dev *idev) +{ +struct device *dev = &idev->dev; +struct mx25_tcq_priv *priv =dev_get_drvdata (dev);
drivers/input/touchscreen/fsl-imx25-tcq.c line 489
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable ipg clock\n" ); +return ret; + } + + ret =mx25_tcq_init (priv); +if (ret) {
There is a certain missbalance in naming at least between the open
and the close. I'd be tempted to reorganise the two so that
they obviously balance.. Either split up the init into the various things such as enabling the interrupts and bringing the queue up (so the oposite of the remove) or wrap the remove calls up in an _exit which can easily be compared to the init)
This definitely comes in the category of writing the code so it is 'obviously correct', rather than making review harder!
There is also some stuff in that init - like enabling debounce that isn't undone in the close - to my mind that suggests it doesn't belong in this function, but rather in device startup, but I may well be missing some interactions in the hardware that prevent this.
Quoted 73 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +73
-0+dev_err (dev,"Failed to init tcq\n" ); +clk_disable_unprepare (priv->clk); +return ret; + } + +return 0 ; +} + +static void mx25_tcq_close (struct input_dev *idev) +{ +struct mx25_tcq_priv *priv =input_get_drvdata (idev); + +mx25_tcq_force_queue_stop (priv); +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_disable_fifo_irq (priv); +clk_disable_unprepare (priv->clk); +} + +static int mx25_tcq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct input_dev *idev; +struct mx25_tcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct resource *res; +void __iomem *mem; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + ret =mx25_tcq_parse_dt (pdev, priv); +if (ret) +return ret; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_tcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); +return priv->irq; + } + + idev =devm_input_allocate_device (dev); +if (!idev) { +dev_err (dev,"Failed to allocate input device\n" ); +return -ENOMEM ; + } + + idev->name = mx25_tcq_name; + idev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); + idev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); +input_set_abs_params (idev,ABS_X ,0 ,0xfff ,0 ,0 ); +input_set_abs_params (idev,ABS_Y ,0 ,0xfff ,0 ,0 ); + + idev->id.bustype =BUS_HOST ; + idev->open = mx25_tcq_open; + idev->close = mx25_tcq_close; + + priv->idev = idev; +input_set_drvdata (idev, priv); + + priv->core_regs = tsadc->regs;
drivers/input/touchscreen/fsl-imx25-tcq.c line 572
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+if (!priv->core_regs) +return -EINVAL ; + + priv->clk = tsadc->clk; +if (!priv->clk) +return -EINVAL ; + +platform_set_drvdata (pdev, priv); + + ret =input_register_device (idev);
I'm not 100% sure of whether input works the way I think it does ;) but I'd imagine this just exposed the userspace interface. Hence from here on you can open the device and cause the interrupt to be enabled. It doesn't have a handler until after the request_threaded_irq device below... So nasty if unlikely race condition here.
drivers/input/touchscreen/fsl-imx25-tcq.c line 580
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+if (ret) { +dev_err (dev,"Failed to register input device\n" ); +return ret; + } + + ret =devm_request_threaded_irq (dev, priv->irq, mx25_tcq_irq, + mx25_tcq_irq_thread,IRQF_ONESHOT , + pdev->name, priv);
currious difference in approach here. Why a devm call in this driver and not in the adc one? I assumed general paranoia with devm irq requests and the various obscure ways they can go wrong so didn't mention it there...
Quoted 21 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +20
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); +return ret; + } + +return 0 ; +} + +static struct platform_driver mx25_tcq_driver = { + .driver = { + .name ="mx25-tcq" , + .of_match_table = mx25_tcq_ids, + }, + .probe = mx25_tcq_probe, +}; +module_platform_driver (mx25_tcq_driver); + +MODULE_DESCRIPTION ("TS input driver for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Jonathan Cameron
maintainerPATCH v8 6/8 input: touchscreen: imx25 tcq driver
Quoted 14 lines · Jonathan Cameron
Quoted 13 lines · Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>
Quoted 7 lines
Quoted 3 lines
[fix clock's period calculation][fix calculation of the 'settling' value]Signed-off-by Juergen Borleis <[email protected]>I read this out of curiousity to see how you had handled the touchscreen usecase of this hardware differently from the generic version.
Anyhow, a few little bits and pieces inline from me as a result
Ah, I'd missed Dmitry's review. Looks like he raised the same issue on ordering in the probe so it doesn't work how I thought ;)
Quoted 703 lines
Jonathan
Quoted 207 lines
---
Notes:
Changes in v7:
- Movedclk_prepare_enable()andmx25_tcq_init()intomx25_tcq_open(). This was done to be able to usedevm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removedmx25_tcq_remove(), not necessary nowdrivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.cdrivers/input/touchscreen/Kconfig +6
-0@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. + config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXXdrivers/input/touchscreen/Makefile +1
-0@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.odrivers/input/touchscreen/fsl-imx25-tcq.c new file +157
-0@@ -0,0 +1,600 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +* +* Based on driver from 2011: +* Juergen Beisert, Pengutronix <[email protected]> +* +* This is the driver for the imx25 TCQ (Touchscreen Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static const char mx25_tcq_name[] ="mx25-tcq" ; + +enum mx25_tcq_mode { +MX25_TS_4WIRE , +}; + +struct mx25_tcq_priv { +struct regmap *regs; +struct regmap *core_regs; +struct input_dev *idev; +enum mx25_tcq_mode mode; +unsigned int pen_threshold; +unsigned int sample_count; +unsigned int expected_samples; +unsigned int pen_debounce; +unsigned int settling_time; +struct clk *clk; +int irq; +}; + +static struct regmap_config mx25_tcq_regconfig = { + .fast_io = true, + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static const struct of_device_id mx25_tcq_ids[] = { + { .compatible ="fsl,imx25-tcq" , }, + {/* Sentinel */ } +}; + +#define TSC_4WIRE_PRE_INDEX 0 +#define TSC_4WIRE_X_INDEX 1 +#define TSC_4WIRE_Y_INDEX 2 +#define TSC_4WIRE_POST_INDEX 3 +#define TSC_4WIRE_LEAVE 4 + +#define MX25_TSC_DEF_THRESHOLD 80 +#define TSC_MAX_SAMPLES 16 + +#define MX25_TSC_REPEAT_WAIT 14 + +enum mx25_adc_configurations { +MX25_CFG_PRECHARGE =0 , +MX25_CFG_TOUCH_DETECT , +MX25_CFG_X_MEASUREMENT , +MX25_CFG_Y_MEASUREMENT , +}; + +#define MX25_PRECHARGE_VALUE (\ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_HIGH | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_IGS) + +#define MX25_TOUCH_DETECT_VALUE (\ + MX25_ADCQ_CFG_YNLR | \ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_OFF | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_PENIACK) + +static void imx25_setup_queue_cfgs (struct mx25_tcq_priv *priv, +unsigned int settling_cnt) +{ +u32 precharge_cfg = +MX25_PRECHARGE_VALUE | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); +u32 touch_detect_cfg = +MX25_TOUCH_DETECT_VALUE | +MX25_ADCQ_CFG_NOS (1 ) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); + +regmap_write (priv->core_regs,MX25_TSC_TICR , precharge_cfg); + +/* PRECHARGE */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_PRECHARGE ), + precharge_cfg); + +/* TOUCH_DETECT */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_TOUCH_DETECT ), + touch_detect_cfg); + +/* X Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_X_MEASUREMENT ), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_LOW | +MX25_ADCQ_CFG_XPUL_HIGH | +MX25_ADCQ_CFG_REFP_XP | +MX25_ADCQ_CFG_IN_YP | +MX25_ADCQ_CFG_REFN_XN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Y Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_Y_MEASUREMENT ), +MX25_ADCQ_CFG_YNLR | +MX25_ADCQ_CFG_YPLL_HIGH | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_YP | +MX25_ADCQ_CFG_IN_XP | +MX25_ADCQ_CFG_REFN_YN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Enable the touch detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , touch_detect_cfg | +MX25_ADCQ_CFG_IGS ); +} + +static int imx25_setup_queue_4wire (struct mx25_tcq_priv *priv, +unsigned settling_cnt,int *items) +{ +imx25_setup_queue_cfgs (priv, settling_cnt); + +/* Setup the conversion queue */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (1 ,MX25_CFG_TOUCH_DETECT ) | +MX25_ADCQ_ITEM (2 ,MX25_CFG_X_MEASUREMENT ) | +MX25_ADCQ_ITEM (3 ,MX25_CFG_Y_MEASUREMENT ) | +MX25_ADCQ_ITEM (4 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (5 ,MX25_CFG_TOUCH_DETECT )); +drivers/input/touchscreen/fsl-imx25-tcq.c line 167
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+/* +* We measure X/Y with 'sample_count' number of samples and execute a +* touch detection twice, with 1 sample each +*/ + priv->expected_samples = priv->sample_count *2 +2 ; + *items =6 ; + +return 0 ; +} +Another personal preference. I'd not bother wrapping these single line calls up but rather just make them inline. They don't in of themselves add much to my mind. Still this one is very much up to you as far as I'm concerned.
Quoted 142 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +142
-0+static void mx25_tcq_disable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK , +MX25_ADCQ_CR_PDMSK ); +} + +static void mx25_tcq_enable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK ,0 ); +} + +static void mx25_tcq_disable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ , +MX25_ADCQ_MR_FDRY_IRQ ); +} + +static void mx25_tcq_enable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ ,0 ); +} + +static void mx25_tcq_force_queue_start (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); +} + +static void mx25_tcq_force_queue_stop (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS ,0 ); +} + +static void mx25_tcq_fifo_reset (struct mx25_tcq_priv *priv) +{ +u32 tcqcr; + +regmap_read (priv->regs,MX25_ADCQ_CR , &tcqcr); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST , +MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST ,0 ); +regmap_write (priv->regs,MX25_ADCQ_CR , tcqcr); +} + +static void mx25_tcq_re_enable_touch_detection (struct mx25_tcq_priv *priv) +{ +/* stop the queue from looping */ +mx25_tcq_force_queue_stop (priv); + +/* for a clean touch detection, preload the X plane */ +regmap_write (priv->core_regs,MX25_TSC_TICR ,MX25_PRECHARGE_VALUE ); + +/* waste some time now to pre-load the X plate to high voltage */ +mx25_tcq_fifo_reset (priv); + +/* re-enable the detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , +MX25_TOUCH_DETECT_VALUE |MX25_ADCQ_CFG_IGS ); + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_PD , +MX25_ADCQ_SR_PD ); + +/* enable the pen down event to be a source for the interrupt */ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_PD_IRQ ,0 ); + +/* lets fire the next IRQ if someone touches the touchscreen */ +mx25_tcq_enable_touch_irq (priv); +} + +static int mx25_tcq_create_event_for_4wire (struct mx25_tcq_priv *priv, +u32 *sample_buf, +unsigned int samples) +{ +unsigned int x_pos =0 ; +unsigned int y_pos =0 ; +unsigned int touch_pre =0 ; +unsigned int touch_post =0 ; +unsigned int i; +int ret =0 ; + +for (i =0 ; i < samples; i++) { +unsigned int index =MX25_ADCQ_FIFO_ID (sample_buf[i]); +unsigned int val =MX25_ADCQ_FIFO_DATA (sample_buf[i]); + +switch (index) { +case 1 : + touch_pre = val; +break ; +case 2 : + x_pos = val; +break ; +case 3 : + y_pos = val; +break ; +case 5 : + touch_post = val; +break ; +default : + ret = -EINVAL ; +break ; + } + } + +if (ret ==0 && samples !=0 ) { +/* +* only if both touch measures are below a threshold, +* the position is valid +*/ +if (touch_pre < priv->pen_threshold && + touch_post < priv->pen_threshold) { +/* valid samples, generate a report */ + x_pos /= priv->sample_count; + y_pos /= priv->sample_count; +input_report_abs (priv->idev,ABS_X , x_pos); +input_report_abs (priv->idev,ABS_Y , y_pos); +input_report_key (priv->idev,BTN_TOUCH ,1 ); +input_sync (priv->idev); + +/* get next sample */ +mx25_tcq_enable_fifo_irq (priv); + }else if (touch_pre >= priv->pen_threshold && + touch_post >= priv->pen_threshold) { +/* +* if both samples are invalid, +* generate a release report +*/ +input_report_key (priv->idev,BTN_TOUCH ,0 ); +input_sync (priv->idev); +mx25_tcq_re_enable_touch_detection (priv); + }else { +/* +* if only one of both touch measurements are +* below the threshold, still some bouncing +* happens. Take additional samples in this +* case to be sure +*/ +mx25_tcq_enable_fifo_irq (priv); + } + } +drivers/input/touchscreen/fsl-imx25-tcq.c line 319
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+return ret; +} + +static irqreturn_t mx25_tcq_irq_thread (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 sample_buf[TSC_MAX_SAMPLES ]; +unsigned int samples =0 ; + +/* read all samples */ It's not a terribly big fifo, so I'm not convinced personally of the merits of having the separate thread for this interrupt...
Quoted 5 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+while (1 ) { +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); +if (stats &MX25_ADCQ_SR_EMPT )drivers/input/touchscreen/fsl-imx25-tcq.c line 334
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+break ; + +if (samples <TSC_MAX_SAMPLES ) { +regmap_read (priv->regs,MX25_ADCQ_FIFO , + &sample_buf[samples]); + ++samples; + }else { +u32 discarded; +/* discard samples */ +regmap_read (priv->regs,MX25_ADCQ_FIFO , &discarded);Comment on how this could happen would be good.
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+ } + } + +mx25_tcq_create_event_for_4wire (priv, sample_buf, samples); + +return IRQ_HANDLED ; +} +drivers/input/touchscreen/fsl-imx25-tcq.c line 352
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+static irqreturn_t mx25_tcq_irq (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 stat; +int ret =IRQ_HANDLED ; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stat); + +if (stat & (MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR )) +mx25_tcq_fifo_reset (priv);Again, currious cross comparison with the adc driver (hardware is pretty much the same ;) In there you don't reset the fifo if you get one of these. Why not? Now you should never get one as you only ever schedule a single reading, but best to be consistent.
drivers/input/touchscreen/fsl-imx25-tcq.c line 361
Quoted 9 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ +if (stat &MX25_ADCQ_SR_PD ) { +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_force_queue_start (priv); +mx25_tcq_enable_fifo_irq (priv); + } + +if (stat &MX25_ADCQ_SR_FDRY ) { +mx25_tcq_disable_fifo_irq (priv);I'm missing something I think.. In a oneshot irq the irq will be masked anyway till the thread is done. Why the explicit disable as well?
drivers/input/touchscreen/fsl-imx25-tcq.c line 370
Quoted 9 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ ret =IRQ_WAKE_THREAD ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_PD |MX25_ADCQ_SR_EOQ , +MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR | +MX25_ADCQ_SR_FOR |MX25_ADCQ_SR_PD | +MX25_ADCQ_SR_EOQ );As with the adc driver you are clearing at least one bit that should not I think ever be set... EOQ. Why?
drivers/input/touchscreen/fsl-imx25-tcq.c line 375
Quoted 5 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+ +return ret; +} + +/* configure the statemachine for a 4-wire touchscreen */ state machine
Quoted 104 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +104
-0+static int mx25_tcq_init (struct mx25_tcq_priv *priv) +{ +u32 tgcr; +unsigned int ipg_div; +unsigned int adc_period; +unsigned int debounce_cnt; +unsigned int settling_cnt; +int itemct; +int ret; + +regmap_read (priv->core_regs,MX25_TSC_TGCR , &tgcr); + ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr)); + adc_period =USEC_PER_SEC * ipg_div *2 +2 ; + adc_period /=clk_get_rate (priv->clk) /1000 +1 ; + debounce_cnt =DIV_ROUND_UP (priv->pen_debounce, adc_period *8 ) -1 ; + settling_cnt =DIV_ROUND_UP (priv->settling_time, adc_period *8 ) -1 ; + +/* Reset */ +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ,0 ); + +/* up to 128 * 8 ADC clocks are possible */ +if (debounce_cnt >127 ) + debounce_cnt =127 ; + +/* up to 255 * 8 ADC clocks are possible */ +if (settling_cnt >255 ) + settling_cnt =255 ; + + ret =imx25_setup_queue_4wire (priv, settling_cnt, &itemct); +if (ret) +return ret; + +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_LITEMID_MASK |MX25_ADCQ_CR_WMRK_MASK , +MX25_ADCQ_CR_LITEMID (itemct -1 ) | +MX25_ADCQ_CR_WMRK (priv->expected_samples -1 )); + +/* setup debounce count */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR , +MX25_TGCR_PDBTIME_MASK , +MX25_TGCR_PDBTIME (debounce_cnt)); + +/* enable debounce */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDBEN , +MX25_TGCR_PDBEN ); +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDEN , +MX25_TGCR_PDEN ); + +/* enable the engine on demand */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_QSM_MASK , +MX25_ADCQ_CR_QSM_FQS ); + +/* Enable repeat and repeat wait */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_RPT |MX25_ADCQ_CR_RWAIT_MASK , +MX25_ADCQ_CR_RPT | +MX25_ADCQ_CR_RWAIT (MX25_TSC_REPEAT_WAIT )); + +mx25_tcq_re_enable_touch_detection (priv); + +return 0 ; +} + +static int mx25_tcq_parse_dt (struct platform_device *pdev, +struct mx25_tcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +u32 wires; +int ret; + +/* Setup defaults */ + priv->pen_threshold =500 ; + priv->sample_count =3 ; + priv->pen_debounce =1000000 ; + priv->settling_time =250000 ; + + ret =of_property_read_u32 (np,"fsl,wires" , &wires); +if (ret) { +dev_err (&pdev->dev,"Failed to find fsl,wires properties\n" ); +return ret; + } + +if (wires ==4 ) { + priv->mode =MX25_TS_4WIRE ; + }else { +dev_err (&pdev->dev,"%u-wire mode not supported\n" , wires); +return -EINVAL ; + } + +/* These are optional, we don't care about the return values */ +of_property_read_u32 (np,"fsl,pen-threshold" , &priv->pen_threshold); +of_property_read_u32 (np,"fsl,settling-time" , &priv->settling_time); +of_property_read_u32 (np,"fsl,pen-debounce" , &priv->pen_debounce); + +return 0 ; +} + +static int mx25_tcq_open (struct input_dev *idev) +{ +struct device *dev = &idev->dev; +struct mx25_tcq_priv *priv =dev_get_drvdata (dev);drivers/input/touchscreen/fsl-imx25-tcq.c line 489
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable ipg clock\n" ); +return ret; + } + + ret =mx25_tcq_init (priv); +if (ret) {There is a certain missbalance in naming at least between the open
and the close. I'd be tempted to reorganise the two so that
they obviously balance.. Either split up the init into the various things such as enabling the interrupts and bringing the queue up (so the oposite of the remove) or wrap the remove calls up in an_exitwhich can easily be compared to the init)This definitely comes in the category of writing the code so it is 'obviously correct', rather than making review harder!
There is also some stuff in that init - like enabling debounce that isn't undone in the close - to my mind that suggests it doesn't belong in this function, but rather in device startup, but I may well be missing some interactions in the hardware that prevent this.
Quoted 73 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +73
-0+dev_err (dev,"Failed to init tcq\n" ); +clk_disable_unprepare (priv->clk); +return ret; + } + +return 0 ; +} + +static void mx25_tcq_close (struct input_dev *idev) +{ +struct mx25_tcq_priv *priv =input_get_drvdata (idev); + +mx25_tcq_force_queue_stop (priv); +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_disable_fifo_irq (priv); +clk_disable_unprepare (priv->clk); +} + +static int mx25_tcq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct input_dev *idev; +struct mx25_tcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct resource *res; +void __iomem *mem; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + ret =mx25_tcq_parse_dt (pdev, priv); +if (ret) +return ret; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_tcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); +return priv->irq; + } + + idev =devm_input_allocate_device (dev); +if (!idev) { +dev_err (dev,"Failed to allocate input device\n" ); +return -ENOMEM ; + } + + idev->name = mx25_tcq_name; + idev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); + idev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); +input_set_abs_params (idev,ABS_X ,0 ,0xfff ,0 ,0 ); +input_set_abs_params (idev,ABS_Y ,0 ,0xfff ,0 ,0 ); + + idev->id.bustype =BUS_HOST ; + idev->open = mx25_tcq_open; + idev->close = mx25_tcq_close; + + priv->idev = idev; +input_set_drvdata (idev, priv); + + priv->core_regs = tsadc->regs;drivers/input/touchscreen/fsl-imx25-tcq.c line 572
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+if (!priv->core_regs) +return -EINVAL ; + + priv->clk = tsadc->clk; +if (!priv->clk) +return -EINVAL ; + +platform_set_drvdata (pdev, priv); + + ret =input_register_device (idev);I'm not 100% sure of whether input works the way I think it does ;) but I'd imagine this just exposed the userspace interface. Hence from here on you can open the device and cause the interrupt to be enabled. It doesn't have a handler until after the
request_threaded_irqdevice below... So nasty if unlikely race condition here.drivers/input/touchscreen/fsl-imx25-tcq.c line 580
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+if (ret) { +dev_err (dev,"Failed to register input device\n" ); +return ret; + } + + ret =devm_request_threaded_irq (dev, priv->irq, mx25_tcq_irq, + mx25_tcq_irq_thread,IRQF_ONESHOT , + pdev->name, priv);currious difference in approach here. Why a devm call in this driver and not in the adc one? I assumed general paranoia with devm irq requests and the various obscure ways they can go wrong so didn't mention it there...
Quoted 11 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); +return ret; + } + +return 0 ; +} + +static struct platform_driver mx25_tcq_driver = { + .driver = {drivers/input/touchscreen/fsl-imx25-tcq.c line 600
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+ .name = "mx25-tcq", + .of_match_table = mx25_tcq_ids, + }, + .probe = mx25_tcq_probe, +}; +module_platform_driver (mx25_tcq_driver); + +MODULE_DESCRIPTION ("TS input driver for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v8 6/8 input: touchscreen: imx25 tcq driver
In reply to Jonathan CameronHi Jonathan,
Quoted 5 lines · On Saturday 21 November 2015 18:48:10 Jonathan Cameron wrote:
[...]
Another personal preference. I'd not bother wrapping these single line calls up but rather just make them inline. They don't in of themselves add much to my mind. Still this one is very much up to you as far as I'm concerned.
A matter of taste. Programming bits is more or less hard to understand even if we use macros with useful names. So it is me to prefer self explaining functions by no cost of code because the compiler will optimise it away.
Regards,
Juergen
Signature · 2 lines
Pengutronix e.K. | Juergen Borleis | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH v8 6/8 input: touchscreen: imx25 tcq driver
In reply to Jonathan CameronQuoted 390 lines · On Saturday 21 November 2015 17:48:10 Jonathan Cameron wrote:
Quoted 10 lines · Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the touchscreen conversion queue and creates a touchscreen input device. The driver currently only supports 4 wire touchscreens. The driver uses a simple conversion queue of precharge, touch detection, X measurement, Y measurement, precharge and another touch detection.
This driver uses the regmap from the parent to setup some touch specific settings in the core driver and setup a idle configuration with touch detection.
Quoted 6 lines
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>[fix clock's period calculation][fix calculation of the 'settling' value]Signed-off-by Juergen Borleis <[email protected]>I read this out of curiousity to see how you had handled the touchscreen usecase of this hardware differently from the generic version.
Anyhow, a few little bits and pieces inline from me as a result
Jonathan
Quoted 207 lines
---
Notes:
Changes in v7:
- Movedclk_prepare_enable()andmx25_tcq_init()intomx25_tcq_open(). This was done to be able to usedevm_request_threaded_irq().
- Cleanup of the probe function through above change
- Removedmx25_tcq_remove(), not necessary nowdrivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 600 ++++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.cdrivers/input/touchscreen/Kconfig +6
-0@@ -811,6 +811,12 @@ config TOUCHSCREEN_USB_COMPOSITE To compile this driver as a module, choose M here: the module will be called usbtouchscreen. +config TOUCHSCREEN_MX25 + tristate "Freescale i.MX25 touchscreen input driver" + depends on MFD_MX25_TSADC + help + Enable support for touchscreen connected to your i.MX25. + config TOUCHSCREEN_MC13783 tristate "Freescale MC13783 touchscreen input driver" depends on MFD_MC13XXXdrivers/input/touchscreen/Makefile +1
-0@@ -45,6 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o obj-$(CONFIG_TOUCHSCREEN_IPROC) += bcm_iproc_tsc.o obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o +obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.odrivers/input/touchscreen/fsl-imx25-tcq.c new file +157
-0@@ -0,0 +1,600 @@ +/* +* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +* +* Based on driver from 2011: +* Juergen Beisert, Pengutronix <[email protected]> +* +* This is the driver for the imx25 TCQ (Touchscreen Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <linux/clk.h> +#include <linux/device.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/mfd/imx25-tsadc.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static const char mx25_tcq_name[] ="mx25-tcq" ; + +enum mx25_tcq_mode { +MX25_TS_4WIRE , +}; + +struct mx25_tcq_priv { +struct regmap *regs; +struct regmap *core_regs; +struct input_dev *idev; +enum mx25_tcq_mode mode; +unsigned int pen_threshold; +unsigned int sample_count; +unsigned int expected_samples; +unsigned int pen_debounce; +unsigned int settling_time; +struct clk *clk; +int irq; +}; + +static struct regmap_config mx25_tcq_regconfig = { + .fast_io = true, + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static const struct of_device_id mx25_tcq_ids[] = { + { .compatible ="fsl,imx25-tcq" , }, + {/* Sentinel */ } +}; + +#define TSC_4WIRE_PRE_INDEX 0 +#define TSC_4WIRE_X_INDEX 1 +#define TSC_4WIRE_Y_INDEX 2 +#define TSC_4WIRE_POST_INDEX 3 +#define TSC_4WIRE_LEAVE 4 + +#define MX25_TSC_DEF_THRESHOLD 80 +#define TSC_MAX_SAMPLES 16 + +#define MX25_TSC_REPEAT_WAIT 14 + +enum mx25_adc_configurations { +MX25_CFG_PRECHARGE =0 , +MX25_CFG_TOUCH_DETECT , +MX25_CFG_X_MEASUREMENT , +MX25_CFG_Y_MEASUREMENT , +}; + +#define MX25_PRECHARGE_VALUE (\ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_HIGH | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_IGS) + +#define MX25_TOUCH_DETECT_VALUE (\ + MX25_ADCQ_CFG_YNLR | \ + MX25_ADCQ_CFG_YPLL_OFF | \ + MX25_ADCQ_CFG_XNUR_OFF | \ + MX25_ADCQ_CFG_XPUL_OFF | \ + MX25_ADCQ_CFG_REFP_INT | \ + MX25_ADCQ_CFG_IN_XP | \ + MX25_ADCQ_CFG_REFN_NGND2 | \ + MX25_ADCQ_CFG_PENIACK) + +static void imx25_setup_queue_cfgs (struct mx25_tcq_priv *priv, +unsigned int settling_cnt) +{ +u32 precharge_cfg = +MX25_PRECHARGE_VALUE | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); +u32 touch_detect_cfg = +MX25_TOUCH_DETECT_VALUE | +MX25_ADCQ_CFG_NOS (1 ) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt); + +regmap_write (priv->core_regs,MX25_TSC_TICR , precharge_cfg); + +/* PRECHARGE */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_PRECHARGE ), + precharge_cfg); + +/* TOUCH_DETECT */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_TOUCH_DETECT ), + touch_detect_cfg); + +/* X Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_X_MEASUREMENT ), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_LOW | +MX25_ADCQ_CFG_XPUL_HIGH | +MX25_ADCQ_CFG_REFP_XP | +MX25_ADCQ_CFG_IN_YP | +MX25_ADCQ_CFG_REFN_XN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Y Measurement */ +regmap_write (priv->regs,MX25_ADCQ_CFG (MX25_CFG_Y_MEASUREMENT ), +MX25_ADCQ_CFG_YNLR | +MX25_ADCQ_CFG_YPLL_HIGH | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_YP | +MX25_ADCQ_CFG_IN_XP | +MX25_ADCQ_CFG_REFN_YN | +MX25_ADCQ_CFG_NOS (priv->sample_count) | +MX25_ADCQ_CFG_SETTLING_TIME (settling_cnt)); + +/* Enable the touch detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , touch_detect_cfg | +MX25_ADCQ_CFG_IGS ); +} + +static int imx25_setup_queue_4wire (struct mx25_tcq_priv *priv, +unsigned settling_cnt,int *items) +{ +imx25_setup_queue_cfgs (priv, settling_cnt); + +/* Setup the conversion queue */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (1 ,MX25_CFG_TOUCH_DETECT ) | +MX25_ADCQ_ITEM (2 ,MX25_CFG_X_MEASUREMENT ) | +MX25_ADCQ_ITEM (3 ,MX25_CFG_Y_MEASUREMENT ) | +MX25_ADCQ_ITEM (4 ,MX25_CFG_PRECHARGE ) | +MX25_ADCQ_ITEM (5 ,MX25_CFG_TOUCH_DETECT )); +drivers/input/touchscreen/fsl-imx25-tcq.c line 167
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+/* +* We measure X/Y with 'sample_count' number of samples and execute a +* touch detection twice, with 1 sample each +*/ + priv->expected_samples = priv->sample_count *2 +2 ; + *items =6 ; + +return 0 ; +} +Another personal preference. I'd not bother wrapping these single line calls up but rather just make them inline. They don't in of themselves add much to my mind. Still this one is very much up to you as far as I'm concerned.
Quoted 146 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +146
-0+static void mx25_tcq_disable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK , +MX25_ADCQ_CR_PDMSK ); +} + +static void mx25_tcq_enable_touch_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_PDMSK ,0 ); +} + +static void mx25_tcq_disable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ , +MX25_ADCQ_MR_FDRY_IRQ ); +} + +static void mx25_tcq_enable_fifo_irq (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_FDRY_IRQ ,0 ); +} + +static void mx25_tcq_force_queue_start (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); +} + +static void mx25_tcq_force_queue_stop (struct mx25_tcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FQS ,0 ); +} + +static void mx25_tcq_fifo_reset (struct mx25_tcq_priv *priv) +{ +u32 tcqcr; + +regmap_read (priv->regs,MX25_ADCQ_CR , &tcqcr); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST , +MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FRST ,0 ); +regmap_write (priv->regs,MX25_ADCQ_CR , tcqcr); +} + +static void mx25_tcq_re_enable_touch_detection (struct mx25_tcq_priv *priv) +{ +/* stop the queue from looping */ +mx25_tcq_force_queue_stop (priv); + +/* for a clean touch detection, preload the X plane */ +regmap_write (priv->core_regs,MX25_TSC_TICR ,MX25_PRECHARGE_VALUE ); + +/* waste some time now to pre-load the X plate to high voltage */ +mx25_tcq_fifo_reset (priv); + +/* re-enable the detection right now */ +regmap_write (priv->core_regs,MX25_TSC_TICR , +MX25_TOUCH_DETECT_VALUE |MX25_ADCQ_CFG_IGS ); + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_PD , +MX25_ADCQ_SR_PD ); + +/* enable the pen down event to be a source for the interrupt */ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_PD_IRQ ,0 ); + +/* lets fire the next IRQ if someone touches the touchscreen */ +mx25_tcq_enable_touch_irq (priv); +} + +static int mx25_tcq_create_event_for_4wire (struct mx25_tcq_priv *priv, +u32 *sample_buf, +unsigned int samples) +{ +unsigned int x_pos =0 ; +unsigned int y_pos =0 ; +unsigned int touch_pre =0 ; +unsigned int touch_post =0 ; +unsigned int i; +int ret =0 ; + +for (i =0 ; i < samples; i++) { +unsigned int index =MX25_ADCQ_FIFO_ID (sample_buf[i]); +unsigned int val =MX25_ADCQ_FIFO_DATA (sample_buf[i]); + +switch (index) { +case 1 : + touch_pre = val; +break ; +case 2 : + x_pos = val; +break ; +case 3 : + y_pos = val; +break ; +case 5 : + touch_post = val; +break ; +default : + ret = -EINVAL ; +break ; + } + } + +if (ret ==0 && samples !=0 ) { +/* +* only if both touch measures are below a threshold, +* the position is valid +*/ +if (touch_pre < priv->pen_threshold && + touch_post < priv->pen_threshold) { +/* valid samples, generate a report */ + x_pos /= priv->sample_count; + y_pos /= priv->sample_count; +input_report_abs (priv->idev,ABS_X , x_pos); +input_report_abs (priv->idev,ABS_Y , y_pos); +input_report_key (priv->idev,BTN_TOUCH ,1 ); +input_sync (priv->idev); + +/* get next sample */ +mx25_tcq_enable_fifo_irq (priv); + }else if (touch_pre >= priv->pen_threshold && + touch_post >= priv->pen_threshold) { +/* +* if both samples are invalid, +* generate a release report +*/ +input_report_key (priv->idev,BTN_TOUCH ,0 ); +input_sync (priv->idev); +mx25_tcq_re_enable_touch_detection (priv); + }else { +/* +* if only one of both touch measurements are +* below the threshold, still some bouncing +* happens. Take additional samples in this +* case to be sure +*/ +mx25_tcq_enable_fifo_irq (priv); + } + } + +return ret; +} + +static irqreturn_t mx25_tcq_irq_thread (int irq,void *dev_id)
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 319
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+{ +struct mx25_tcq_priv *priv = dev_id; +u32 sample_buf[TSC_MAX_SAMPLES ]; +unsigned int samples =0 ; + +/* read all samples */ It's not a terribly big fifo, so I'm not convinced personally of the merits of having the separate thread for this interrupt...
Yes that is correct, but it is calling into the input framework as well. I am not sure how much work is done there. Also the thread shouldn't be extremely costy as it is mostly sleeping?
Quoted 17 lines
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+while (1 ) { +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); +if (stats &MX25_ADCQ_SR_EMPT )drivers/input/touchscreen/fsl-imx25-tcq.c line 334
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+break ; + +if (samples <TSC_MAX_SAMPLES ) { +regmap_read (priv->regs,MX25_ADCQ_FIFO , + &sample_buf[samples]); + ++samples; + }else { +u32 discarded; +/* discard samples */ +regmap_read (priv->regs,MX25_ADCQ_FIFO , &discarded);Comment on how this could happen would be good.
This could happen if there are new samples while we read all samples from the fifo.
Thanks to your comment I had a closer look on this handler again. The problem here is that we read x samples while x may be a different number than the number of samples generated by the conversion queue. But only want to read samples that were produced by exactly one conversion queue run.
So I redesigned this handler to first read the number of samples in the fifo and then read as many as we want.
Quoted 15 lines
Quoted 15 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +14
-0+ } + } + +mx25_tcq_create_event_for_4wire (priv, sample_buf, samples); + +return IRQ_HANDLED ; +} + +static irqreturn_t mx25_tcq_irq (int irq,void *dev_id) +{ +struct mx25_tcq_priv *priv = dev_id; +u32 stat; +int ret =IRQ_HANDLED ; +
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 352
Quoted 4 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +4
-0+regmap_read (priv->regs,MX25_ADCQ_SR , &stat); + +if (stat & (MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR )) +mx25_tcq_fifo_reset (priv);Again, currious cross comparison with the adc driver (hardware is pretty much the same ;) In there you don't reset the fifo if you get one of these. Why not? Now you should never get one as you only ever schedule a single reading, but best to be consistent.
Yes, the conversion queue in the touch driver is running continously so that this may happen. Actually a fifo reset is not enough here. For the touch we need to reset the conversion queue as well, thanks. This could be added to the gcq driver but this should never happen.
Quoted 12 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 361
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ +if (stat &MX25_ADCQ_SR_PD ) { +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_force_queue_start (priv); +mx25_tcq_enable_fifo_irq (priv); + } + +if (stat &MX25_ADCQ_SR_FDRY ) { +mx25_tcq_disable_fifo_irq (priv);I'm missing something I think.. In a oneshot irq the irq will be masked anyway till the thread is done. Why the explicit disable as well?
The driver which receives the interrupts for both units GCQ and TCQ has a proper interrupt status register. It uses this register to distribute them to the different units. The problem is that it doesn't have a mask register. The interrupts can only be masked in the TCQ or GCQ unit. So by default the interrupt for both units will be masked.
GCQ currently doesn't use any time-critical interrupts. But waiting for the thread shouldn't block the other unit. So I think it's better to mask the interrupt here explicitly. This of course should not be with IRQF_ONESHOT. That's a mistake, will fix that.
Quoted 12 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 370
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +9
-0+ ret =IRQ_WAKE_THREAD ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_PD |MX25_ADCQ_SR_EOQ , +MX25_ADCQ_SR_FRR |MX25_ADCQ_SR_FUR | +MX25_ADCQ_SR_FOR |MX25_ADCQ_SR_PD | +MX25_ADCQ_SR_EOQ );As with the adc driver you are clearing at least one bit that should not I think ever be set... EOQ. Why?
Indeed, this is always masked. Thanks, removed that.
Quoted 127 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 375
Quoted 5 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +5
-0+ +return ret; +} + +/* configure the statemachine for a 4-wire touchscreen */ state machine
Quoted 104 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +104
-0+static int mx25_tcq_init (struct mx25_tcq_priv *priv) +{ +u32 tgcr; +unsigned int ipg_div; +unsigned int adc_period; +unsigned int debounce_cnt; +unsigned int settling_cnt; +int itemct; +int ret; + +regmap_read (priv->core_regs,MX25_TSC_TGCR , &tgcr); + ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr)); + adc_period =USEC_PER_SEC * ipg_div *2 +2 ; + adc_period /=clk_get_rate (priv->clk) /1000 +1 ; + debounce_cnt =DIV_ROUND_UP (priv->pen_debounce, adc_period *8 ) -1 ; + settling_cnt =DIV_ROUND_UP (priv->settling_time, adc_period *8 ) -1 ; + +/* Reset */ +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ); +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_QRST |MX25_ADCQ_CR_FRST ,0 ); + +/* up to 128 * 8 ADC clocks are possible */ +if (debounce_cnt >127 ) + debounce_cnt =127 ; + +/* up to 255 * 8 ADC clocks are possible */ +if (settling_cnt >255 ) + settling_cnt =255 ; + + ret =imx25_setup_queue_4wire (priv, settling_cnt, &itemct); +if (ret) +return ret; + +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_LITEMID_MASK |MX25_ADCQ_CR_WMRK_MASK , +MX25_ADCQ_CR_LITEMID (itemct -1 ) | +MX25_ADCQ_CR_WMRK (priv->expected_samples -1 )); + +/* setup debounce count */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR , +MX25_TGCR_PDBTIME_MASK , +MX25_TGCR_PDBTIME (debounce_cnt)); + +/* enable debounce */ +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDBEN , +MX25_TGCR_PDBEN ); +regmap_update_bits (priv->core_regs,MX25_TSC_TGCR ,MX25_TGCR_PDEN , +MX25_TGCR_PDEN ); + +/* enable the engine on demand */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_QSM_MASK , +MX25_ADCQ_CR_QSM_FQS ); + +/* Enable repeat and repeat wait */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_RPT |MX25_ADCQ_CR_RWAIT_MASK , +MX25_ADCQ_CR_RPT | +MX25_ADCQ_CR_RWAIT (MX25_TSC_REPEAT_WAIT )); + +mx25_tcq_re_enable_touch_detection (priv); + +return 0 ; +} + +static int mx25_tcq_parse_dt (struct platform_device *pdev, +struct mx25_tcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +u32 wires; +int ret; + +/* Setup defaults */ + priv->pen_threshold =500 ; + priv->sample_count =3 ; + priv->pen_debounce =1000000 ; + priv->settling_time =250000 ; + + ret =of_property_read_u32 (np,"fsl,wires" , &wires); +if (ret) { +dev_err (&pdev->dev,"Failed to find fsl,wires properties\n" ); +return ret; + } + +if (wires ==4 ) { + priv->mode =MX25_TS_4WIRE ; + }else { +dev_err (&pdev->dev,"%u-wire mode not supported\n" , wires); +return -EINVAL ; + } + +/* These are optional, we don't care about the return values */ +of_property_read_u32 (np,"fsl,pen-threshold" , &priv->pen_threshold); +of_property_read_u32 (np,"fsl,settling-time" , &priv->settling_time); +of_property_read_u32 (np,"fsl,pen-debounce" , &priv->pen_debounce); + +return 0 ; +} + +static int mx25_tcq_open (struct input_dev *idev) +{ +struct device *dev = &idev->dev; +struct mx25_tcq_priv *priv =dev_get_drvdata (dev);drivers/input/touchscreen/fsl-imx25-tcq.c line 489
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+int ret; + + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable ipg clock\n" ); +return ret; + } + + ret =mx25_tcq_init (priv); +if (ret) {There is a certain missbalance in naming at least between the open
and the close. I'd be tempted to reorganise the two so that
they obviously balance.. Either split up the init into the various things such as enabling the interrupts and bringing the queue up (so the oposite of the remove) or wrap the remove calls up in an_exitwhich can easily be compared to the init)
Quoted 7 lines
This definitely comes in the category of writing the code so it is 'obviously correct', rather than making review harder!
There is also some stuff in that init - like enabling debounce that isn't undone in the close - to my mind that suggests it doesn't belong in this function, but rather in device startup, but I may well be missing some interactions in the hardware that prevent this.
Yes, init() is more of a reset_configure_and_init() function. I will try to make this more obvious.
Quoted 81 lines
Quoted 81 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +80
-0+dev_err (dev,"Failed to init tcq\n" ); +clk_disable_unprepare (priv->clk); +return ret; + } + +return 0 ; +} + +static void mx25_tcq_close (struct input_dev *idev) +{ +struct mx25_tcq_priv *priv =input_get_drvdata (idev); + +mx25_tcq_force_queue_stop (priv); +mx25_tcq_disable_touch_irq (priv); +mx25_tcq_disable_fifo_irq (priv); +clk_disable_unprepare (priv->clk); +} + +static int mx25_tcq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct input_dev *idev; +struct mx25_tcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct resource *res; +void __iomem *mem; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + ret =mx25_tcq_parse_dt (pdev, priv); +if (ret) +return ret; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_tcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); +return priv->irq; + } + + idev =devm_input_allocate_device (dev); +if (!idev) { +dev_err (dev,"Failed to allocate input device\n" ); +return -ENOMEM ; + } + + idev->name = mx25_tcq_name; + idev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_ABS ); + idev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); +input_set_abs_params (idev,ABS_X ,0 ,0xfff ,0 ,0 ); +input_set_abs_params (idev,ABS_Y ,0 ,0xfff ,0 ,0 ); + + idev->id.bustype =BUS_HOST ; + idev->open = mx25_tcq_open; + idev->close = mx25_tcq_close; + + priv->idev = idev; +input_set_drvdata (idev, priv); + + priv->core_regs = tsadc->regs; +if (!priv->core_regs) +return -EINVAL ; + + priv->clk = tsadc->clk; +if (!priv->clk) +return -EINVAL ; +
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 572
Quoted 3 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +3
-0+platform_set_drvdata (pdev, priv); + + ret =input_register_device (idev);I'm not 100% sure of whether input works the way I think it does ;) but I'd imagine this just exposed the userspace interface. Hence from here on you can open the device and cause the interrupt to be enabled. It doesn't have a handler until after the
request_threaded_irqdevice below... So nasty if unlikely race condition here.
Yes, fixed as Dmitry suggested.
Quoted 12 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 580
Quoted 9 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +8
-0+if (ret) { +dev_err (dev,"Failed to register input device\n" ); +return ret; + } + + ret =devm_request_threaded_irq (dev, priv->irq, mx25_tcq_irq, + mx25_tcq_irq_thread,IRQF_ONESHOT , + pdev->name, priv);currious difference in approach here. Why a devm call in this driver and not in the adc one? I assumed general paranoia with devm irq requests and the various obscure ways they can go wrong so didn't mention it there...
For the gcq driver we have things are a bit different. There is no real open()/close() function. We configure the unit once (including interrupts) and want to be careful when shutting down the driver to do it in the right order of disabling clocks, interrupts and regulators. The interrupts there are actually never masked there.
In this tcq driver the interrupts are masked and clocks are off when the input was closed.
Thanks,
Markus
Quoted 23 lines
Quoted 21 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +20
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); +return ret; + } + +return 0 ; +} + +static struct platform_driver mx25_tcq_driver = { + .driver = { + .name ="mx25-tcq" , + .of_match_table = mx25_tcq_ids, + }, + .probe = mx25_tcq_probe, +}; +module_platform_driver (mx25_tcq_driver); + +MODULE_DESCRIPTION ("TS input driver for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
Signature · 11 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: This is a digitally signed message part. URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151123/ad5c5eaa/attachment-0001.sig>
PATCH v8 7/8 ARM: dts: imx25: Add TSC and ADC support
In reply to Markus PargmannFrom: Denis Carikli <[email protected]>
--- arch/arm/boot/dts/imx25.dtsi | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
arch/arm/boot/dts/imx25.dtsi +27 -3
@@ -265,13 +265,37 @@ status = "disabled"; }; - tsc: tsc at 50030000 { - compatible = "fsl,imx25-adc", "fsl,imx21-tsc"; - reg = <0x50030000 0x4000>; + tscadc: tscadc at 50030000 { + compatible = "fsl,imx25-tsadc"; + reg = <0x50030000 0xc>; interrupts = <46>; clocks = <&clks 119>; clock-names = "ipg"; + interrupt-controller; + #interrupt-cells = <1>; + #address-cells = <1>; + #size-cells = <1>; + ranges; status = "disabled"; + + adc: adc at 50030800 { + compatible = "fsl,imx25-gcq"; + reg = <0x50030800 0x60>; + interrupt-parent = <&tscadc>; + interrupts = <1>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + tsc: tcq at 50030400 { + compatible = "fsl,imx25-tcq"; + reg = <0x50030400 0x60>; + interrupt-parent = <&tscadc>; + interrupts = <0>; + fsl,wires = <4>; + status = "disabled"; + }; }; ssi1: ssi at 50034000 {
Signature · 1 line
2.6.1
PATCH v8 8/8 ARM: imx_v4_v5_defconfig: Add I.MX25 Touchscreen controller and ADC support.
In reply to Markus PargmannFrom: Denis Carikli <[email protected]>
--- arch/arm/configs/imx_v4_v5_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/configs/imx_v4_v5_defconfig +4 -0
@@ -88,6 +88,7 @@ CONFIG_KEYBOARD_IMX=y # CONFIG_INPUT_MOUSE is not set CONFIG_INPUT_TOUCHSCREEN=y CONFIG_TOUCHSCREEN_ADS7846=m +CONFIG_TOUCHSCREEN_MX25=y CONFIG_TOUCHSCREEN_MC13783=y # CONFIG_LEGACY_PTYS is not set CONFIG_SERIAL_8250=m
@@ -107,6 +108,7 @@ CONFIG_HWMON=m CONFIG_SENSORS_MC13783_ADC=m CONFIG_WATCHDOG=y CONFIG_IMX2_WDT=y +CONFIG_MFD_MX25_TSADC=y CONFIG_MFD_MC13XXX_SPI=y CONFIG_REGULATOR=y CONFIG_REGULATOR_FIXED_VOLTAGE=y
@@ -172,6 +174,8 @@ CONFIG_DMADEVICES=y CONFIG_IMX_SDMA=y CONFIG_IMX_DMA=y # CONFIG_IOMMU_SUPPORT is not set +CONFIG_IIO=y +CONFIG_FSL_MX25_ADC=y CONFIG_EXT2_FS=y CONFIG_EXT3_FS=y CONFIG_EXT4_FS=y
Signature · 1 line
2.6.1