imx25 adc and touchscreen driver
Subsystems (7)
v6 cover imx25 adc and touchscreen driver
This series adds a driver for the Freescale i.MX25 SoC internal ADC unit which is used for touchscreen and ADC. The driver consists of three parts, the MFD driver which handles interrupts and some central configuration registers, the ADC driver and the touchscreen driver.
v6 splits the remaining DT binding documentation out into seperate patches. I reworked the dt bindings for the gcq unit and made some code improvements from comments.
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 | 54 ++ .../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 | 361 +++++++++++++ drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 +++++++++++++++++++++ drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 167 ++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 + include/linux/mfd/imx25-tsadc.h | 143 +++++ 16 files changed, 1463 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.1.4
PATCH v6 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.1.4
PATCH v6 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:
- Moved the raw_read code out to a different function to cleanup the code
- Changed bindings to use adc-refp and adc-refn. Also a bit of cleanup in the setup routine.
- Added defines for a complete list of references in the dt binding macros
Changes in v5:
- Fixed locking
- Removed module owner
.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +54 -0
@@ -0,0 +1,54 @@ +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-supply: The regulator supplying the ADC reference voltage. + Required when at least one subnode uses the external 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_REF_INT>; + fsl,adc-refn = <MX25_ADC_REF_NGND>; + }; + };
Signature · 1 line
2.1.4
Jonathan Cameron
maintainerPATCH v6 2/8 ARM: dt: Binding documentation for imx25 GCQ
Quoted 9 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:
- Moved theraw_readcode out to a different function to cleanup the code
To be picky, that's in a later patch rather than this one...
Quoted 25 lines
- Changed bindings to use adc-refp and adc-refn. Also a bit of cleanup in the setup routine.
- Added defines for a complete list of references in the dt binding macrosChanges in v5:
- Fixed locking
- Removed module owner.../devicetree/bindings/iio/adc/fsl,imx25-gcq.txt | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txtDocumentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +7
-0@@ -0,0 +1,54 @@ +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".
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt line 17
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +10
-0+ - 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-supply: The regulator supplying the ADC reference voltage. + Required when at least one subnode uses the external reference.
Note, as commented on next patch, the regulator request should reflect this dependency.
Quoted 38 lines
Documentation/devicetree/bindings/iio/adc/fsl,imx25-gcq.txt new file +37
-0+ +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_REF_INT>; + fsl,adc-refn = <MX25_ADC_REF_NGND>; + }; + };
PATCH v6 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. + - 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.1.4
PATCH v6 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 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 | 10 +++ drivers/mfd/Makefile | 2 + drivers/mfd/fsl-imx25-tsadc.c | 167 ++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/imx25-tsadc.h | 143 ++++++++++++++++++++++++++++++++++ 4 files changed, 322 insertions(+) create mode 100644 drivers/mfd/fsl-imx25-tsadc.c create mode 100644 include/linux/mfd/imx25-tsadc.h
drivers/mfd/Kconfig +10 -0
@@ -232,6 +232,16 @@ 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 + depends on OF + 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
@@ -78,6 +78,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 +167 -0
167 lines not on this page · raw message
include/linux/mfd/imx25-tsadc.h new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v6 4/8 mfd: fsl imx25 Touchscreen ADC driver
Hi,
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 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +0
-0@@ -0,0 +1,167 @@
[...]
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_TGCR_POWERMODE_MASK (3 << 8) +#define MX25_TGCR_POWERMODE_SAVE BIT(8) +#define MX25_TGCR_POWERMODE_ON (2 << 8)
This looks a bit weird and conceals the fact, that MX25_TGCR_POWERMODE_SAVE is in fact one of the possible settings of a two bit bitfield. For consistency I would write:
#define MX25_TGCR_POWERMODE_MASK (3 << 8)
#define MX25_TGCR_POWERMODE_SAVE (1 << 8)
#define MX25_TGCR_POWERMODE_ON (2 << 8)
[...]
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_ADCQ_CFG_YPLL_HIGH 0 +#define MX25_ADCQ_CFG_YPLL_OFF BIT(12) +#define MX25_ADCQ_CFG_YPLL_LOW (3 << 12)
dto.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_ADCQ_CFG_XNUR_HIGH 0 +#define MX25_ADCQ_CFG_XNUR_OFF BIT(10) +#define MX25_ADCQ_CFG_XNUR_LOW (3 << 10)
dto.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 3 lines
drivers/mfd/fsl-imx25-tsadc.c new file +2
-0+#define MX25_ADCQ_CFG_XPUL_OFF BIT(9) +#define MX25_ADCQ_CFG_XPUL_HIGH 0
|#define MX25_ADCQ_CFG_XPUL_OFF (1 << 9)
|#define MX25_ADCQ_CFG_XPUL_HIGH (0 << 9)
would make it more clear, that these refer to the two states of the same bit.
Quoted 2 lines
+#define
MX25_ADCQ_CFG_REFP(sel)(sel << 7)
missing () around macro argument
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_REFP_YP 0 +#define MX25_ADCQ_CFG_REFP_XP (1 << 7) +#define MX25_ADCQ_CFG_REFP_EXT (2 << 7) +#define MX25_ADCQ_CFG_REFP_INT (3 << 7) +#define MX25_ADCQ_CFG_REFP_MASK (3 << 7)
see my previous comment.
Quoted 2 lines
+#define
MX25_ADCQ_CFG_IN(sel)(sel << 4)
missing () around macro argument
drivers/mfd/fsl-imx25-tsadc.c
Quoted 5 lines
drivers/mfd/fsl-imx25-tsadc.c new file +4
-0+#define MX25_ADCQ_CFG_IN_XP 0 +#define MX25_ADCQ_CFG_IN_YP (1 << 4) +#define MX25_ADCQ_CFG_IN_XN (2 << 4) +#define MX25_ADCQ_CFG_IN_YN (3 << 4)
see my previous comment.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_IN_WIPER (4 << 4) +#define MX25_ADCQ_CFG_IN_AUX0 (5 << 4) +#define MX25_ADCQ_CFG_IN_AUX1 (6 << 4) +#define MX25_ADCQ_CFG_IN_AUX2 (7 << 4) +#define MX25_ADCQ_CFG_REFN (sel) (sel << 2)
missing () around macro argument
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_REFN_XN 0 +#define MX25_ADCQ_CFG_REFN_YN (1 << 2) +#define MX25_ADCQ_CFG_REFN_NGND (2 << 2) +#define MX25_ADCQ_CFG_REFN_NGND2 (3 << 2) +#define MX25_ADCQ_CFG_REFN_MASK (3 << 2)
see my previous comment.
Lothar Wa?mann
Signature · 9 lines
___________________________________________________________ Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10 Gesch?ftsf?hrer: Matthias Kaussen Handelsregistereintrag: Amtsgericht Aachen, HRB 4996 www.karo-electronics.de | info at karo-electronics.de ___________________________________________________________
PATCH v6 4/8 mfd: fsl imx25 Touchscreen ADC driver
Hi,
Quoted 83 lines · Lothar Wa?mann
Hi,
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 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +0
-0@@ -0,0 +1,167 @@[...]
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_TGCR_POWERMODE_MASK (3 << 8) +#define MX25_TGCR_POWERMODE_SAVE BIT(8) +#define MX25_TGCR_POWERMODE_ON (2 << 8)This looks a bit weird and conceals the fact, that
MX25_TGCR_POWERMODE_SAVEis in fact one of the possible settings of a two bit bitfield. For consistency I would write:
#defineMX25_TGCR_POWERMODE_MASK(3 << 8)
#defineMX25_TGCR_POWERMODE_SAVE(1 << 8)
#defineMX25_TGCR_POWERMODE_ON(2 << 8)[...]
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_ADCQ_CFG_YPLL_HIGH 0 +#define MX25_ADCQ_CFG_YPLL_OFF BIT(12) +#define MX25_ADCQ_CFG_YPLL_LOW (3 << 12)dto.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 4 lines
drivers/mfd/fsl-imx25-tsadc.c new file +3
-0+#define MX25_ADCQ_CFG_XNUR_HIGH 0 +#define MX25_ADCQ_CFG_XNUR_OFF BIT(10) +#define MX25_ADCQ_CFG_XNUR_LOW (3 << 10)dto.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 3 lines
drivers/mfd/fsl-imx25-tsadc.c new file +2
-0+#define MX25_ADCQ_CFG_XPUL_OFF BIT(9) +#define MX25_ADCQ_CFG_XPUL_HIGH 0|#define
MX25_ADCQ_CFG_XPUL_OFF(1 << 9)
|#defineMX25_ADCQ_CFG_XPUL_HIGH(0 << 9)
would make it more clear, that these refer to the two states of the same bit.Quoted 2 lines
+#define
MX25_ADCQ_CFG_REFP(sel)(sel << 7)missing () around macro argument
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_REFP_YP 0 +#define MX25_ADCQ_CFG_REFP_XP (1 << 7) +#define MX25_ADCQ_CFG_REFP_EXT (2 << 7) +#define MX25_ADCQ_CFG_REFP_INT (3 << 7) +#define MX25_ADCQ_CFG_REFP_MASK (3 << 7)see my previous comment.
Quoted 2 lines
+#define
MX25_ADCQ_CFG_IN(sel)(sel << 4)missing () around macro argument
drivers/mfd/fsl-imx25-tsadc.c
Quoted 5 lines
drivers/mfd/fsl-imx25-tsadc.c new file +4
-0+#define MX25_ADCQ_CFG_IN_XP 0 +#define MX25_ADCQ_CFG_IN_YP (1 << 4) +#define MX25_ADCQ_CFG_IN_XN (2 << 4) +#define MX25_ADCQ_CFG_IN_YN (3 << 4)see my previous comment.
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_IN_WIPER (4 << 4) +#define MX25_ADCQ_CFG_IN_AUX0 (5 << 4) +#define MX25_ADCQ_CFG_IN_AUX1 (6 << 4) +#define MX25_ADCQ_CFG_IN_AUX2 (7 << 4) +#define MX25_ADCQ_CFG_REFN (sel) (sel << 2)missing () around macro argument
Quoted 7 lines
drivers/mfd/fsl-imx25-tsadc.c
Quoted 6 lines
drivers/mfd/fsl-imx25-tsadc.c new file +5
-0+#define MX25_ADCQ_CFG_REFN_XN 0 +#define MX25_ADCQ_CFG_REFN_YN (1 << 2) +#define MX25_ADCQ_CFG_REFN_NGND (2 << 2) +#define MX25_ADCQ_CFG_REFN_NGND2 (3 << 2) +#define MX25_ADCQ_CFG_REFN_MASK (3 << 2)see my previous comment.
Thanks, I fixed all of the comments.
Best regards,
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: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150130/9b1c6708/attachment-0001.sig>
PATCH v6 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.
--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 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
@@ -143,6 +143,13 @@ config EXYNOS_ADC of SoCs for drivers such as the touchscreen and hwmon to use to share this resource. +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 LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788
drivers/iio/adc/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_AD799X) += ad799x.o obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_AXP288_ADC) += axp288_adc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX1363) += max1363.o
drivers/iio/adc/fsl-imx25-gcq.c new file +361 -0
361 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_INT 2/* Internal voltage reference */ +#define MX25_ADC_REFP_EXT 3/* External voltage reference */ + +#define MX25_ADC_REFN_XN 0 +#define MX25_ADC_REFN_YN 1 +#define MX25_ADC_REFN_NGND 2 +#define MX25_ADC_REFN_NGND2 3 + +#endif
Signature · 1 line
2.1.4
PATCH v6 5/8 iio: adc: fsl,imx25-gcq driver
Hi,
Quoted 22 lines · Markus Pargmann
This 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.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 insertions(+)create mode 100644
drivers/iio/adc/fsl-imx25-gcq.ccreate mode 100644include/dt-bindings/iio/adc/fsl-imx25-gcq.h
(...)
Quoted 46 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +46
-0+static int mx25_gcq_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct mx25_gcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct resource *res; +void __iomem *mem; +int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_gcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + +init_completion (&priv->completed); + +/* Optional external regulator */ + priv->ext_vref =devm_regulator_get (&pdev->dev,"vref" ); +if (!IS_ERR_OR_NULL (priv->ext_vref)) { + ret =regulator_enable (priv->ext_vref); +if (ret) +return ret; + } + + ret =mx25_gcq_setup_cfgs (pdev, priv); +if (ret) +return ret; + + priv->clk = tsadc->clk; + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret;
drivers/iio/adc/fsl-imx25-gcq.c line 304
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+ } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); + ret = priv->irq; + goto err_clk_unprepare; + } + + ret =request_irq (priv->irq, mx25_gcq_irq,0 , pdev->name, priv);
Use of devm_* API
Quoted 12 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +12
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + indio_dev->dev.parent = &pdev->dev; + indio_dev->channels = mx25_gcq_channels; + indio_dev->num_channels =ARRAY_SIZE (mx25_gcq_channels); + indio_dev->info = &mx25_gcq_iio_info; + + ret =iio_device_register (indio_dev); +if (ret) {
drivers/iio/adc/fsl-imx25-gcq.c line 326
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+dev_err (dev,"Failed to register iio device\n" ); + goto err_irq_free; + } + +platform_set_drvdata (pdev, priv); + +return 0 ; + +err_irq_free: +free_irq (priv->irq, (void *)priv);
This is not required if use devm_*
drivers/iio/adc/fsl-imx25-gcq.c line 338
Quoted 12 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +12
-0+err_clk_unprepare: +clk_disable_unprepare (priv->clk); +return ret; +} + +static int mx25_gcq_remove (struct platform_device *pdev) +{ +struct mx25_gcq_priv *priv =platform_get_drvdata (pdev); +struct iio_dev *indio_dev =iio_priv_to_dev (pdev); + +iio_device_unregister (indio_dev); +free_irq (priv->irq, priv);
Dto...
Quoted 1 line
Signature · 2 lines
Thanks, Varka Bhadram.
PATCH v6 5/8 iio: adc: fsl,imx25-gcq driver
Hi,
Quoted 77 lines · Varka Bhadram
Hi,
Quoted 22 lines · Markus Pargmann
This 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.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 insertions(+) create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c create mode 100644 include/dt-bindings/iio/adc/fsl-imx25-gcq.h(...)
Quoted 50 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +50
-0+static int mx25_gcq_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct mx25_gcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct resource *res; +void __iomem *mem; +int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_gcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + +init_completion (&priv->completed); + +/* Optional external regulator */ + priv->ext_vref =devm_regulator_get (&pdev->dev,"vref" ); +if (!IS_ERR_OR_NULL (priv->ext_vref)) { + ret =regulator_enable (priv->ext_vref); +if (ret) +return ret; + } + + ret =mx25_gcq_setup_cfgs (pdev, priv); +if (ret) +return ret; + + priv->clk = tsadc->clk; + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) {
Quoted 8 lines
drivers/iio/adc/fsl-imx25-gcq.c line 304
Quoted 6 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +6
-0+dev_err (dev,"Failed to get IRQ\n" ); + ret = priv->irq; + goto err_clk_unprepare; + } + + ret =request_irq (priv->irq, mx25_gcq_irq,0 , pdev->name, priv);Use of devm_* API
It seems to be save to use it here, as the interrupt handler only uses memory allocated for this driver and not the iio framework. So I will probably change it to devm_*.
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: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150130/4824a8ec/attachment.sig>
Jonathan Cameron
maintainerPATCH v6 5/8 iio: adc: fsl,imx25-gcq driver
In reply to Varka BhadramQuoted 77 lines · Varka Bhadram
Hi,
Quoted 22 lines · Markus Pargmann
This 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.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 insertions(+)create mode 100644
drivers/iio/adc/fsl-imx25-gcq.ccreate mode 100644include/dt-bindings/iio/adc/fsl-imx25-gcq.h(...)
Quoted 50 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +50
-0+static int mx25_gcq_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct mx25_gcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct resource *res; +void __iomem *mem; +int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_gcq_regconfig); +if (IS_ERR (priv->regs)) { +dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + +init_completion (&priv->completed); + +/* Optional external regulator */ + priv->ext_vref =devm_regulator_get (&pdev->dev,"vref" ); +if (!IS_ERR_OR_NULL (priv->ext_vref)) { + ret =regulator_enable (priv->ext_vref); +if (ret) +return ret; + } + + ret =mx25_gcq_setup_cfgs (pdev, priv); +if (ret) +return ret; + + priv->clk = tsadc->clk; + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) {
Quoted 8 lines
drivers/iio/adc/fsl-imx25-gcq.c line 304
Quoted 6 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +6
-0+dev_err (dev,"Failed to get IRQ\n" ); + ret = priv->irq; + goto err_clk_unprepare; + } + + ret =request_irq (priv->irq, mx25_gcq_irq,0 , pdev->name, priv);Use of devm_* API
Changes the ordering wrt to the clk prepare / unprepare so don't use devm (or change the order if appropriate! (I haven't thought about it!)
Quoted 43 lines
Quoted 13 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +12
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + indio_dev->dev.parent = &pdev->dev; + indio_dev->channels = mx25_gcq_channels; + indio_dev->num_channels =ARRAY_SIZE (mx25_gcq_channels); + indio_dev->info = &mx25_gcq_iio_info; + + ret =iio_device_register (indio_dev); +if (ret) {drivers/iio/adc/fsl-imx25-gcq.c line 326
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+dev_err (dev,"Failed to register iio device\n" ); + goto err_irq_free; + } + +platform_set_drvdata (pdev, priv); + +return 0 ; + +err_irq_free: +free_irq (priv->irq, (void *)priv);This is not required if use devm_*
drivers/iio/adc/fsl-imx25-gcq.c line 338
Quoted 12 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +12
-0+err_clk_unprepare: +clk_disable_unprepare (priv->clk); +return ret; +} + +static int mx25_gcq_remove (struct platform_device *pdev) +{ +struct mx25_gcq_priv *priv =platform_get_drvdata (pdev); +struct iio_dev *indio_dev =iio_priv_to_dev (pdev); + +iio_device_unregister (indio_dev); +free_irq (priv->irq, priv);Dto...
Quoted 1 line
Jonathan Cameron
maintainerPATCH v6 5/8 iio: adc: fsl,imx25-gcq driver
In reply to Markus PargmannQuoted 7 lines · Markus Pargmann
This 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.
Quoted 6 lines
The reference voltages are configurable through devicetree subnodes, depending on the connections of the ADC inputs.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>Signed-off-by Markus Pargmann <[email protected]>
Some really small bits and bobs inline...
Only non trivial one is that I'd prefer that the need for a regulator in the event of an external reference being specified was explicitly enforced.
Quoted 104 lines
--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 insertions(+) create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c create mode 100644 include/dt-bindings/iio/adc/fsl-imx25-gcq.hdrivers/iio/adc/Kconfig +7
-0@@ -143,6 +143,13 @@ config EXYNOS_ADC of SoCs for drivers such as the touchscreen and hwmon to use to share this resource. +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 LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788drivers/iio/adc/Makefile +1
-0@@ -16,6 +16,7 @@ obj-$(CONFIG_AD799X) += ad799x.o obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_AXP288_ADC) += axp288_adc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX1363) += max1363.odrivers/iio/adc/fsl-imx25-gcq.c new file +59
-0@@ -0,0 +1,361 @@ +/* +* Copyright 2014 Markus Pargmann, Pengutronix <[email protected]> +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +* +* This is the driver for the imx25 GCQ (Generic Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <dt-bindings/iio/adc/fsl-imx25-gcq.h> +#include <linux/clk.h> +#include <linux/iio/iio.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> +#include <linux/regulator/consumer.h> + +#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000)) + +enum mx25_gcq_cfgs { +MX25_CFG_XP =0 , +MX25_CFG_YP , +MX25_CFG_XN , +MX25_CFG_YN , +MX25_CFG_WIPER , +MX25_CFG_INAUX0 , +MX25_CFG_INAUX1 , +MX25_CFG_INAUX2 , +MX25_NUM_CFGS , +}; + +struct mx25_gcq_priv { +struct regmap *regs; +struct completion completed; +unsigned int settling_time; +struct clk *clk; +int irq; +struct regulator *ext_vref; +u32 channel_vref_mv[MX25_NUM_CFGS ]; +}; + +#define MX25_CQG_CHAN (chan, id) {\ + .type = IIO_VOLTAGE,\ + .indexed = 1,\ + .channel = chan,\ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),\ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\ + .datasheet_name = id,\ +} + +static const struct iio_chan_spec mx25_gcq_channels[MX25_NUM_CFGS ] = {
drivers/iio/adc/fsl-imx25-gcq.c line 69
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+MX25_CQG_CHAN (0 ,"xp" ), +MX25_CQG_CHAN (1 ,"yp" ), +MX25_CQG_CHAN (2 ,"xn" ), +MX25_CQG_CHAN (3 ,"yn" ), +MX25_CQG_CHAN (4 ,"wiper" ), +MX25_CQG_CHAN (5 ,"inaux0" ), +MX25_CQG_CHAN (6 ,"inaux1" ), + MX25_CQG_CHAN(7, "inaux2"), +}; +
I'd be tempted to not bother separating out the next two given they are only used in one place each..
Quoted 165 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +165
-0+static void mx25_gcq_disable_eoq (struct mx25_gcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_EOQ_IRQ , +MX25_ADCQ_MR_EOQ_IRQ ); +} + +static void mx25_gcq_enable_eoq (struct mx25_gcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR , +MX25_ADCQ_MR_EOQ_IRQ ,0 ); +} + +static irqreturn_t mx25_gcq_irq (int irq,void *data) +{ +struct mx25_gcq_priv *priv = data; +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); + +if (stats &MX25_ADCQ_SR_EOQ ) { +mx25_gcq_disable_eoq (priv); +complete (&priv->completed); + } + +/* Disable conversion queue run */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FQS ,0 ); + +/* Acknowledge all possible irqs */ +regmap_write (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_EOQ |MX25_ADCQ_SR_PD ); + +return IRQ_HANDLED ; +} + +static int mx25_gcq_get_raw_value (struct device *dev, +struct iio_chan_spec const *chan, +struct mx25_gcq_priv *priv, +int *val) +{ +long timeout; +u32 data; + +/* Setup the configuration we want to use */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 , chan->channel)); + +mx25_gcq_enable_eoq (priv); + +/* Trigger queue for one run */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); + + timeout =wait_for_completion_interruptible_timeout ( + &priv->completed,MX25_GCQ_TIMEOUT ); +if (timeout <0 ) { +dev_err (dev, +"ADC wait for measurement failed\n" ); +return timeout; + }else if (timeout ==0 ) { +dev_err (dev,"ADC timed out\n" ); +return -ETIMEDOUT ; + } + +regmap_read (priv->regs,MX25_ADCQ_FIFO , &data); + + *val =MX25_ADCQ_FIFO_DATA (data); + +return IIO_VAL_INT ; +} + +static int mx25_gcq_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct mx25_gcq_priv *priv =iio_priv (indio_dev); +int ret =0 ; + +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&indio_dev->mlock); + ret =mx25_gcq_get_raw_value (&indio_dev->dev, chan, priv, val); +mutex_unlock (&indio_dev->mlock); +return ret; + +case IIO_CHAN_INFO_SCALE : + *val = priv->channel_vref_mv[chan->channel]; + *val2 =12 ; +return IIO_VAL_FRACTIONAL_LOG2 ; + +default : +return -EINVAL ; + } +} + +static const struct iio_info mx25_gcq_iio_info = { + .read_raw = mx25_gcq_read_raw, +}; + +static const struct regmap_config mx25_gcq_regconfig = { + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static int mx25_gcq_setup_cfgs (struct platform_device *pdev, +struct mx25_gcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +struct device_node *child; +struct device *dev = &pdev->dev; +int ret, i; + +/* +* Setup all configurations registers with a default conversion +* configuration for each input +*/ +for (i =0 ; i <MX25_NUM_CFGS ; ++i) +regmap_write (priv->regs,MX25_ADCQ_CFG (i), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_INT | +MX25_ADCQ_CFG_IN (i) | +MX25_ADCQ_CFG_REFN_NGND2 ); + +for_each_child_of_node (np, child) { +u32 reg; +u32 refp =MX25_ADCQ_CFG_REFP_INT ; +u32 refn =MX25_ADCQ_CFG_REFN_NGND2 ; + + ret =of_property_read_u32 (child,"reg" , ®); +if (ret) { +dev_err (dev,"Failed to get reg property\n" ); +return ret; + } + +if (reg >=MX25_NUM_CFGS ) { +dev_err (dev, +"reg value is greater than the number of available configuration registers\n" ); +return -EINVAL ; + } + +of_property_read_u32 (child,"fsl,adc-refp" , &refp); +of_property_read_u32 (child,"fsl,adc-refn" , &refn); + +/* +* Shift the read values to the correct positions within the +* register. +*/ + refp =MX25_ADCQ_CFG_REFP (refp); + refn =MX25_ADCQ_CFG_REFN (refn); + +if ((refp &MX25_ADCQ_CFG_REFP_MASK ) != refp) { +dev_err (dev,"Invalid fsl,adc-refp property value\n" ); +return -EINVAL ; + } +if ((refn &MX25_ADCQ_CFG_REFN_MASK ) != refn) { +dev_err (dev,"Invalid fsl,adc-refn property value" ); +return -EINVAL ; + } + + regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg), + MX25_ADCQ_CFG_REFP_MASK |
drivers/iio/adc/fsl-imx25-gcq.c line 244
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+MX25_ADCQ_CFG_REFN_MASK , + refp | refn); + } +regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FRST |MX25_ADCQ_CR_QRST , +MX25_ADCQ_CR_FRST |MX25_ADCQ_CR_QRST ); + +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_PDMSK | +MX25_ADCQ_CR_QSM_FQS );
Odd line breaking. I certainly wouldn't break the last two lines.
Quoted 27 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +27
-0+ +return 0 ; +} + +static int mx25_gcq_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct mx25_gcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct resource *res; +void __iomem *mem; +int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_gcq_regconfig); +if (IS_ERR (priv->regs)) {
drivers/iio/adc/fsl-imx25-gcq.c line 281
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + +init_completion (&priv->completed); + +/* Optional external regulator */ + priv->ext_vref =devm_regulator_get (&pdev->dev,"vref" ); +if (!IS_ERR_OR_NULL (priv->ext_vref)) { + ret =regulator_enable (priv->ext_vref);
This is documented in the bindings as being only optional in the sense that there may or may not be channels using it. I'd be inclined to have it as non optional, but only request it if in use.
If truely optional then should be using the get_optional form as otherwise IIRC the regulator framework will feed you a dummy regulator under some circumstances.
Quoted 30 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +30
-0+if (ret) +return ret; + } + + ret =mx25_gcq_setup_cfgs (pdev, priv); +if (ret) +return ret; + + priv->clk = tsadc->clk; + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); + ret = priv->irq; + goto err_clk_unprepare; + } + + ret =request_irq (priv->irq, mx25_gcq_irq,0 , pdev->name, priv); +if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + indio_dev->dev.parent = &pdev->dev; + indio_dev->channels = mx25_gcq_channels;
drivers/iio/adc/fsl-imx25-gcq.c line 321
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+ indio_dev->num_channels =ARRAY_SIZE (mx25_gcq_channels); + indio_dev->info = &mx25_gcq_iio_info; + + ret =iio_device_register (indio_dev); +if (ret) { +dev_err (dev,"Failed to register iio device\n" ); + goto err_irq_free; + } + +platform_set_drvdata (pdev, priv);
I'd normally prefer slightly if this used the indio_dev (just a case of logically what contains what...) Doesn't really matter though.
Quoted 65 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +40
-0+ +return 0 ; + +err_irq_free: +free_irq (priv->irq, (void *)priv); +err_clk_unprepare: +clk_disable_unprepare (priv->clk); +return ret; +} + +static int mx25_gcq_remove (struct platform_device *pdev) +{ +struct mx25_gcq_priv *priv =platform_get_drvdata (pdev); +struct iio_dev *indio_dev =iio_priv_to_dev (pdev); + +iio_device_unregister (indio_dev); +free_irq (priv->irq, priv); +clk_disable_unprepare (priv->clk); + +return 0 ; +} + +static struct of_device_id mx25_gcq_ids[] = { + { .compatible ="fsl,imx25-gcq" , }, + {/* Sentinel */ } +}; + +static struct platform_driver mx25_gcq_driver = { + .driver = { + .name ="mx25-gcq" , + .of_match_table = mx25_gcq_ids, + }, + .probe = mx25_gcq_probe, + .remove = mx25_gcq_remove, +}; +module_platform_driver (mx25_gcq_driver); + +MODULE_DESCRIPTION ("ADC driver for Freescale mx25" ); +MODULE_AUTHOR ("Markus Pargmann <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );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_INT 2/* Internal voltage reference */ +#define MX25_ADC_REFP_EXT 3/* External voltage reference */ + +#define MX25_ADC_REFN_XN 0 +#define MX25_ADC_REFN_YN 1 +#define MX25_ADC_REFN_NGND 2 +#define MX25_ADC_REFN_NGND2 3 + +#endif
PATCH v6 5/8 iio: adc: fsl,imx25-gcq driver
Hi,
Quoted 125 lines · Jonathan Cameron
Quoted 7 lines · Markus Pargmann
This 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.
Quoted 6 lines
The reference voltages are configurable through devicetree subnodes, depending on the connections of the ADC inputs.
Signed-off-by Markus Pargmann <[email protected]>Signed-off-by Denis Carikli <[email protected]>Signed-off-by Markus Pargmann <[email protected]>Some really small bits and bobs inline...
Only non trivial one is that I'd prefer that the need for a regulator in the event of an external reference being specified was explicitly enforced.Quoted 108 lines
--- drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/fsl-imx25-gcq.c | 361 ++++++++++++++++++++++++++++ include/dt-bindings/iio/adc/fsl-imx25-gcq.h | 18 ++ 4 files changed, 387 insertions(+) create mode 100644 drivers/iio/adc/fsl-imx25-gcq.c create mode 100644 include/dt-bindings/iio/adc/fsl-imx25-gcq.hdrivers/iio/adc/Kconfig +7
-0@@ -143,6 +143,13 @@ config EXYNOS_ADC of SoCs for drivers such as the touchscreen and hwmon to use to share this resource. +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 LP8788_ADC tristate "LP8788 ADC driver" depends on MFD_LP8788drivers/iio/adc/Makefile +1
-0@@ -16,6 +16,7 @@ obj-$(CONFIG_AD799X) += ad799x.o obj-$(CONFIG_AT91_ADC) += at91_adc.o obj-$(CONFIG_AXP288_ADC) += axp288_adc.o obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o +obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_MAX1027) += max1027.o obj-$(CONFIG_MAX1363) += max1363.odrivers/iio/adc/fsl-imx25-gcq.c new file +63
-0@@ -0,0 +1,361 @@ +/* +* Copyright 2014 Markus Pargmann, Pengutronix <[email protected]> +* +* The code contained herein is licensed under the GNU General Public +* License. You may obtain a copy of the GNU General Public License +* Version 2 or later at the following locations: +* +* http://www.opensource.org/licenses/gpl-license.html +* http://www.gnu.org/copyleft/gpl.html +* +* This is the driver for the imx25 GCQ (Generic Conversion Queue) +* connected to the imx25 ADC. +*/ + +#include <dt-bindings/iio/adc/fsl-imx25-gcq.h> +#include <linux/clk.h> +#include <linux/iio/iio.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> +#include <linux/regulator/consumer.h> + +#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000)) + +enum mx25_gcq_cfgs { +MX25_CFG_XP =0 , +MX25_CFG_YP , +MX25_CFG_XN , +MX25_CFG_YN , +MX25_CFG_WIPER , +MX25_CFG_INAUX0 , +MX25_CFG_INAUX1 , +MX25_CFG_INAUX2 , +MX25_NUM_CFGS , +}; + +struct mx25_gcq_priv { +struct regmap *regs; +struct completion completed; +unsigned int settling_time; +struct clk *clk; +int irq; +struct regulator *ext_vref; +u32 channel_vref_mv[MX25_NUM_CFGS ]; +}; + +#define MX25_CQG_CHAN (chan, id) {\ + .type = IIO_VOLTAGE,\ + .indexed = 1,\ + .channel = chan,\ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),\ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\ + .datasheet_name = id,\ +} + +static const struct iio_chan_spec mx25_gcq_channels[MX25_NUM_CFGS ] = { +MX25_CQG_CHAN (0 ,"xp" ), +MX25_CQG_CHAN (1 ,"yp" ), +MX25_CQG_CHAN (2 ,"xn" ), +MX25_CQG_CHAN (3 ,"yn" ),
Quoted 8 lines
drivers/iio/adc/fsl-imx25-gcq.c line 69
Quoted 6 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +6
-0+MX25_CQG_CHAN (4 ,"wiper" ), +MX25_CQG_CHAN (5 ,"inaux0" ), +MX25_CQG_CHAN (6 ,"inaux1" ), + MX25_CQG_CHAN(7, "inaux2"), +}; +I'd be tempted to not bother separating out the next two given they are only used in one place each..
I removed the wrapping functions.
Quoted 168 lines
Quoted 168 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +168
-0+static void mx25_gcq_disable_eoq (struct mx25_gcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR ,MX25_ADCQ_MR_EOQ_IRQ , +MX25_ADCQ_MR_EOQ_IRQ ); +} + +static void mx25_gcq_enable_eoq (struct mx25_gcq_priv *priv) +{ +regmap_update_bits (priv->regs,MX25_ADCQ_MR , +MX25_ADCQ_MR_EOQ_IRQ ,0 ); +} + +static irqreturn_t mx25_gcq_irq (int irq,void *data) +{ +struct mx25_gcq_priv *priv = data; +u32 stats; + +regmap_read (priv->regs,MX25_ADCQ_SR , &stats); + +if (stats &MX25_ADCQ_SR_EOQ ) { +mx25_gcq_disable_eoq (priv); +complete (&priv->completed); + } + +/* Disable conversion queue run */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FQS ,0 ); + +/* Acknowledge all possible irqs */ +regmap_write (priv->regs,MX25_ADCQ_SR ,MX25_ADCQ_SR_FRR | +MX25_ADCQ_SR_FUR |MX25_ADCQ_SR_FOR | +MX25_ADCQ_SR_EOQ |MX25_ADCQ_SR_PD ); + +return IRQ_HANDLED ; +} + +static int mx25_gcq_get_raw_value (struct device *dev, +struct iio_chan_spec const *chan, +struct mx25_gcq_priv *priv, +int *val) +{ +long timeout; +u32 data; + +/* Setup the configuration we want to use */ +regmap_write (priv->regs,MX25_ADCQ_ITEM_7_0 , +MX25_ADCQ_ITEM (0 , chan->channel)); + +mx25_gcq_enable_eoq (priv); + +/* Trigger queue for one run */ +regmap_update_bits (priv->regs,MX25_ADCQ_CR ,MX25_ADCQ_CR_FQS , +MX25_ADCQ_CR_FQS ); + + timeout =wait_for_completion_interruptible_timeout ( + &priv->completed,MX25_GCQ_TIMEOUT ); +if (timeout <0 ) { +dev_err (dev, +"ADC wait for measurement failed\n" ); +return timeout; + }else if (timeout ==0 ) { +dev_err (dev,"ADC timed out\n" ); +return -ETIMEDOUT ; + } + +regmap_read (priv->regs,MX25_ADCQ_FIFO , &data); + + *val =MX25_ADCQ_FIFO_DATA (data); + +return IIO_VAL_INT ; +} + +static int mx25_gcq_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct mx25_gcq_priv *priv =iio_priv (indio_dev); +int ret =0 ; + +switch (mask) { +case IIO_CHAN_INFO_RAW : +mutex_lock (&indio_dev->mlock); + ret =mx25_gcq_get_raw_value (&indio_dev->dev, chan, priv, val); +mutex_unlock (&indio_dev->mlock); +return ret; + +case IIO_CHAN_INFO_SCALE : + *val = priv->channel_vref_mv[chan->channel]; + *val2 =12 ; +return IIO_VAL_FRACTIONAL_LOG2 ; + +default : +return -EINVAL ; + } +} + +static const struct iio_info mx25_gcq_iio_info = { + .read_raw = mx25_gcq_read_raw, +}; + +static const struct regmap_config mx25_gcq_regconfig = { + .max_register =0x5c , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static int mx25_gcq_setup_cfgs (struct platform_device *pdev, +struct mx25_gcq_priv *priv) +{ +struct device_node *np = pdev->dev.of_node; +struct device_node *child; +struct device *dev = &pdev->dev; +int ret, i; + +/* +* Setup all configurations registers with a default conversion +* configuration for each input +*/ +for (i =0 ; i <MX25_NUM_CFGS ; ++i) +regmap_write (priv->regs,MX25_ADCQ_CFG (i), +MX25_ADCQ_CFG_YPLL_OFF | +MX25_ADCQ_CFG_XNUR_OFF | +MX25_ADCQ_CFG_XPUL_OFF | +MX25_ADCQ_CFG_REFP_INT | +MX25_ADCQ_CFG_IN (i) | +MX25_ADCQ_CFG_REFN_NGND2 ); + +for_each_child_of_node (np, child) { +u32 reg; +u32 refp =MX25_ADCQ_CFG_REFP_INT ; +u32 refn =MX25_ADCQ_CFG_REFN_NGND2 ; + + ret =of_property_read_u32 (child,"reg" , ®); +if (ret) { +dev_err (dev,"Failed to get reg property\n" ); +return ret; + } + +if (reg >=MX25_NUM_CFGS ) { +dev_err (dev, +"reg value is greater than the number of available configuration registers\n" ); +return -EINVAL ; + } + +of_property_read_u32 (child,"fsl,adc-refp" , &refp); +of_property_read_u32 (child,"fsl,adc-refn" , &refn); + +/* +* Shift the read values to the correct positions within the +* register. +*/ + refp =MX25_ADCQ_CFG_REFP (refp); + refn =MX25_ADCQ_CFG_REFN (refn); + +if ((refp &MX25_ADCQ_CFG_REFP_MASK ) != refp) { +dev_err (dev,"Invalid fsl,adc-refp property value\n" ); +return -EINVAL ; + } +if ((refn &MX25_ADCQ_CFG_REFN_MASK ) != refn) { +dev_err (dev,"Invalid fsl,adc-refn property value" ); +return -EINVAL ; + } + +regmap_update_bits (priv->regs,MX25_ADCQ_CFG (reg), +MX25_ADCQ_CFG_REFP_MASK | +MX25_ADCQ_CFG_REFN_MASK , + refp | refn); + }
Quoted 8 lines
drivers/iio/adc/fsl-imx25-gcq.c line 244
Quoted 7 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +7
-0+regmap_update_bits (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_FRST |MX25_ADCQ_CR_QRST , +MX25_ADCQ_CR_FRST |MX25_ADCQ_CR_QRST ); + +regmap_write (priv->regs,MX25_ADCQ_CR , +MX25_ADCQ_CR_PDMSK | +MX25_ADCQ_CR_QSM_FQS );Odd line breaking. I certainly wouldn't break the last two lines.
Fixed
Quoted 41 lines
Quoted 27 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +27
-0+ +return 0 ; +} + +static int mx25_gcq_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct mx25_gcq_priv *priv; +struct mx25_tsadc *tsadc =dev_get_drvdata (pdev->dev.parent); +struct device *dev = &pdev->dev; +struct resource *res; +void __iomem *mem; +int ret; + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mem =devm_ioremap_resource (dev, res); +if (!mem) +return -ENOMEM ; + + priv->regs =devm_regmap_init_mmio (dev, mem, &mx25_gcq_regconfig); +if (IS_ERR (priv->regs)) {drivers/iio/adc/fsl-imx25-gcq.c line 281
Quoted 10 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +10
-0+dev_err (dev,"Failed to initialize regmap\n" ); +return PTR_ERR (priv->regs); + } + +init_completion (&priv->completed); + +/* Optional external regulator */ + priv->ext_vref =devm_regulator_get (&pdev->dev,"vref" ); +if (!IS_ERR_OR_NULL (priv->ext_vref)) { + ret =regulator_enable (priv->ext_vref);This is documented in the bindings as being only optional in the sense that there may or may not be channels using it. I'd be inclined to have it as non optional, but only request it if in use.
Quoted 3 lines
If truely optional then should be using the
get_optionalform as otherwise IIRC the regulator framework will feed you a dummy regulator under some circumstances.
I now moved the devm_regulator_get() function into mx25_gcq_setup_cfgs(). After all configs are setup and parsed we know if the regulator is necessary. So it is still optional and only required and checked if REFP_EXT is used in the devicetree.
Quoted 35 lines
Quoted 35 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +35
-0+if (ret) +return ret; + } + + ret =mx25_gcq_setup_cfgs (pdev, priv); +if (ret) +return ret; + + priv->clk = tsadc->clk; + ret =clk_prepare_enable (priv->clk); +if (ret) { +dev_err (dev,"Failed to enable clock\n" ); +return ret; + } + + priv->irq =platform_get_irq (pdev,0 ); +if (priv->irq <=0 ) { +dev_err (dev,"Failed to get IRQ\n" ); + ret = priv->irq; + goto err_clk_unprepare; + } + + ret =request_irq (priv->irq, mx25_gcq_irq,0 , pdev->name, priv); +if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + indio_dev->dev.parent = &pdev->dev; + indio_dev->channels = mx25_gcq_channels; + indio_dev->num_channels =ARRAY_SIZE (mx25_gcq_channels); + indio_dev->info = &mx25_gcq_iio_info; + + ret =iio_device_register (indio_dev); +if (ret) {
Quoted 8 lines
drivers/iio/adc/fsl-imx25-gcq.c line 321
Quoted 5 lines
drivers/iio/adc/fsl-imx25-gcq.c new file +5
-0+dev_err (dev,"Failed to register iio device\n" ); + goto err_irq_free; + } + +platform_set_drvdata (pdev, priv);I'd normally prefer slightly if this used the
indio_dev(just a case of logically what contains what...) Doesn't really matter though.
Changed it to store indio_dev.
Thank you,
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: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150226/10d89c9b/attachment.sig>
PATCH v6 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.
--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
drivers/input/touchscreen/Kconfig +6 -0
@@ -748,6 +748,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
@@ -41,6 +41,7 @@ obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.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 +587 -0
587 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v6 6/8 input: touchscreen: imx25 tcq driver
Hi,
Quoted 21 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]>Acked-by Dmitry Torokhov <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+)create mode 100644
drivers/input/touchscreen/fsl-imx25-tcq.c
(...)
drivers/input/touchscreen/fsl-imx25-tcq.c line 542
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+ ret =request_threaded_irq (priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread, +IRQF_ONESHOT , pdev->name, priv);
We can use devres API for request_thread_irq()...
Quoted 7 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +7
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + ret =mx25_tcq_init (priv); +if (ret) {
drivers/input/touchscreen/fsl-imx25-tcq.c line 559
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+dev_err (dev,"Failed to init tcq\n" ); + goto error_free_irq; + } + +platform_set_drvdata (pdev, priv); + +return 0 ; + +error_free_irq: +free_irq (priv->irq, priv);
This is not required if we use devres API
drivers/input/touchscreen/fsl-imx25-tcq.c line 569
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+err_clk_unprepare: +clk_disable_unprepare (priv->clk); +return ret; +} + +static int mx25_tcq_remove (struct platform_device *pdev) +{ +struct mx25_tcq_priv *priv =platform_get_drvdata (pdev); + +free_irq (priv->irq, priv);
This also..
Signature · 2 lines
Regards, Varka Bhadram.
Dmitry Torokhov
maintainerPATCH v6 6/8 input: touchscreen: imx25 tcq driver
Quoted 42 lines · Varka Bhadram
Hi,
Quoted 21 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]>Acked-by Dmitry Torokhov <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c(...)
drivers/input/touchscreen/fsl-imx25-tcq.c line 542
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+ ret =request_threaded_irq (priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread, +IRQF_ONESHOT , pdev->name, priv);We can use devres API for
request_thread_irq()...Quoted 11 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +11
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + ret =mx25_tcq_init (priv); +if (ret) { +dev_err (dev,"Failed to init tcq\n" ); + goto error_free_irq; + } +
Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 559
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+platform_set_drvdata (pdev, priv); + +return 0 ; + +error_free_irq: +free_irq (priv->irq, priv);This is not required if we use devres API
Yes it does - you do not really want to stop clocks in the middle of servicing interrupt.
Thanks.
Signature · 1 line
Dmitry
PATCH v6 6/8 input: touchscreen: imx25 tcq driver
Hi,
Quoted 52 lines · Dmitry Torokhov
Quoted 42 lines · Varka Bhadram
Hi,
Quoted 21 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]>Acked-by Dmitry Torokhov <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c(...)
drivers/input/touchscreen/fsl-imx25-tcq.c line 542
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+ ret =request_threaded_irq (priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread, +IRQF_ONESHOT , pdev->name, priv);We can use devres API for
request_thread_irq()...Quoted 11 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +11
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + ret =mx25_tcq_init (priv); +if (ret) { +dev_err (dev,"Failed to init tcq\n" ); + goto error_free_irq; + } +Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 559
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+platform_set_drvdata (pdev, priv); + +return 0 ; + +error_free_irq: +free_irq (priv->irq, priv);This is not required if we use devres API
Quoted 2 lines
Yes it does - you do not really want to stop clocks in the middle of servicing interrupt.
Thanks, I missed the clocks. I will not use devm here then.
For the gcq (ADC) driver, it would still works to use devm_request_irq as the interrupt can only trigger when the user requested an ADC conversion. So as soon as the device is unregistered from the IIO subsystem, there should not be any interrupts. However I would like to keep free_irq in the gcq driver as well. Unexpected interrupts wouldn't be a problem and especially if the driver is extended for continous conversion in the future, this may be better.
Best regards,
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: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150202/af3b8aeb/attachment.sig>
Dmitry Torokhov
maintainerPATCH v6 6/8 input: touchscreen: imx25 tcq driver
Quoted 55 lines · Markus Pargmann
Hi,
Quoted 52 lines · Dmitry Torokhov
Quoted 50 lines · Varka Bhadram
Hi,
Quoted 21 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]>Acked-by Dmitry Torokhov <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c(...)
drivers/input/touchscreen/fsl-imx25-tcq.c line 542
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+ ret =request_threaded_irq (priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread, +IRQF_ONESHOT , pdev->name, priv);We can use devres API for
request_thread_irq()...Quoted 7 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +7
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + ret =mx25_tcq_init (priv); +if (ret) {drivers/input/touchscreen/fsl-imx25-tcq.c line 559
Quoted 10 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +10
-0+dev_err (dev,"Failed to init tcq\n" ); + goto error_free_irq; + } + +platform_set_drvdata (pdev, priv); + +return 0 ; + +error_free_irq: +free_irq (priv->irq, priv);This is not required if we use devres API
Quoted 4 lines
Quoted 2 lines
Yes it does - you do not really want to stop clocks in the middle of servicing interrupt.
Thanks, I missed the clocks. I will not use devm here then.
Actually, you still can if you move clock enabling/disabling and mx25_tcq_init() into input_dev->open() and ->close() callbacks. Close will be called during input device un-registration which happens (given your current sequence) after freeing irq by devm.
By the way, I used my old @vmware address by accident. Can you please replace the original acked by with:
Thanks.
Signature · 1 line
Dmitry
PATCH v6 6/8 input: touchscreen: imx25 tcq driver
Hi,
Quoted 59 lines · Dmitry Torokhov
Quoted 58 lines · Markus Pargmann
Hi,
Quoted 54 lines · Dmitry Torokhov
Quoted 42 lines · Varka Bhadram
Hi,
Quoted 21 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]>Acked-by Dmitry Torokhov <[email protected]>Signed-off-by Markus Pargmann <[email protected]>--- drivers/input/touchscreen/Kconfig | 6 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c(...)
drivers/input/touchscreen/fsl-imx25-tcq.c line 542
Quoted 2 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +2
-0+ ret =request_threaded_irq (priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread, +IRQF_ONESHOT , pdev->name, priv);We can use devres API for
request_thread_irq()...Quoted 11 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +11
-0+if (ret) { +dev_err (dev,"Failed requesting IRQ\n" ); + goto err_clk_unprepare; + } + + ret =mx25_tcq_init (priv); +if (ret) { +dev_err (dev,"Failed to init tcq\n" ); + goto error_free_irq; + } +Quoted 8 lines
drivers/input/touchscreen/fsl-imx25-tcq.c line 559
Quoted 6 lines
drivers/input/touchscreen/fsl-imx25-tcq.c new file +6
-0+platform_set_drvdata (pdev, priv); + +return 0 ; + +error_free_irq: +free_irq (priv->irq, priv);This is not required if we use devres API
Yes it does - you do not really want to stop clocks in the middle of servicing interrupt.
Quoted 6 lines
Quoted 1 line
Thanks, I missed the clocks. I will not use devm here then.
Actually, you still can if you move clock enabling/disabling and
mx25_tcq_init()intoinput_dev->open()and ->close() callbacks. Close will be called during input device un-registration which happens (given your current sequence) after freeing irq by devm.
Thank you. I now moved that code into open() and close(), replaced the irq_request() with devm_irq_request. mx25_tcq_remove() is gone now.
Quoted 5 lines
By the way, I used my old @vmware address by accident. Can you please replace the original acked by with:
Acked-by Dmitry Torokhov <[email protected]>
Replaced it.
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: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150226/38528ef2/attachment.sig>
PATCH v6 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.1.4
PATCH v6 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
@@ -89,6 +89,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
@@ -108,6 +109,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
@@ -173,6 +175,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.1.4