Skip to contentSkip to conversation

staging:iio:adc: Add SPEAr ADC driver

PATCH Superseded Stefan Roese 2 participants 2 messages Apr 12, 2012 1 message not in the archive

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging:iio:adc: Add SPEAr ADC driver

This patch implements the basic single data conversion support for the SPEAr600 SoC ADC. The register layout of SPEAr600 differs a bit from other SPEAr SoC variants (e.g. SPEAr3xx). These differences are handled via DT compatible testing. Resulting in a multi-arch binary.

This driver is currently tested only on SPEAr600. Future patches may add support for other SoC variants (SPEAr3xx) and features like software buffer or DMA.

---
v2:
- Minor spelling fixes pointed out by Jonathan
- Renamed scale_uv to scale_mv
- Used defines for constants (CLK_MIN, CLK_MAX)
- Used of_iomap() instead of ioremap() and platform_get_resource()
- Added clk_prepare()
- Added error checking to clk_enable()

 .../bindings/staging/iio/adc/spear-adc.txt         |   26 ++
 drivers/staging/iio/adc/Kconfig                    |    7 +
 drivers/staging/iio/adc/Makefile                   |    1 +
 drivers/staging/iio/adc/spear_adc.c                |  444 ++++++++++++++++++++
 4 files changed, 478 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt
 create mode 100644 drivers/staging/iio/adc/spear_adc.c
Documentation/devicetree/bindings/staging/iio/adc/spear-adc.txt new file +26 -0
new file mode 100644
index 0000000..02ea23a
@@ -0,0 +1,26 @@
+* ST SPEAr ADC device driver
+
+Required properties:
+- compatible: Should be "st,spear600-adc"
+- reg: Address and length of the register set for the device
+- interrupt-parent: Should be the phandle for the interrupt controller
+  that services interrupts for this device
+- interrupts: Should contain the ADC interrupt
+- sampling-frequency: Default sampling frequency
+
+Optional properties:
+- vref-external: External voltage reference in milli-volts. If omitted
+  the internal voltage reference will be used.
+- average-samples: Number of samples to generate an average value. If
+  omitted, single data conversion will be used.
+
+Examples:
+
+	adc: adc@d8200000 {
+		compatible = "st,spear600-adc";
+		reg = <0xd8200000 0x1000>;
+		interrupt-parent = <&vic1>;
+		interrupts = <6>;
+		sampling-frequency = <5000000>;
+		vref-external = <2500>;	/* 2.5V VRef */
+	};
drivers/staging/iio/adc/Kconfig +7 -0
index 592eabd..ec006e7 100644
@@ -202,4 +202,11 @@ config LPC32XX_ADC
 	  touchscreen driver, so you can only select one of the two drivers
 	  (lpc32xx_adc or lpc32xx_ts). Provides direct access via sysfs.
 
+config SPEAR_ADC
+	tristate "ST SPEAr ADC"
+	depends on PLAT_SPEAR
+	help
+	  Say yes here to build support for the integrated ADC inside the
+	  ST SPEAr SoC. Provides direct access via sysfs.
+
 endmenu
drivers/staging/iio/adc/Makefile +1 -0
index f83ab95..14e98b6 100644
@@ -38,3 +38,4 @@ obj-$(CONFIG_ADT7310) += adt7310.o
 obj-$(CONFIG_ADT7410) += adt7410.o
 obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
drivers/staging/iio/adc/spear_adc.c new file +444 -0

444 lines not on this page · raw message

Signature · 1 line
1.7.10
Acked-by
#2 lore raw
In reply to a message not in the archive
Quoted 48 lines · Stefan Roese
drivers/staging/iio/adc/spear_adc.c new file +48 -0
+static int __devinit spear_adc_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct spear_adc_info *info;
+       struct iio_dev *iodev = NULL;
+       int ret = -ENODEV;
+       int irq;
+
+       iodev = iio_allocate_device(sizeof(struct spear_adc_info));
+       if (!iodev) {
+               dev_err(&pdev->dev, "failed allocating iio device\n");
+               ret = -ENOMEM;
+               goto errout1;
+       }
+
+       info = iio_priv(iodev);
+       info->np = np;
+
+       /*
+        * SPEAr600 has a different register layout than other SPEAr SoC's
+        * (e.g. SPEAr3xx). Let's provide two register base addresses
+        * to support multi-arch kernels.
+        */
+       info->adc_base_spear6xx = of_iomap(np, 0);
+       if (!info->adc_base_spear6xx) {
+               dev_err(&pdev->dev, "failed mapping memory\n");
+               ret = -ENOMEM;
+               goto errout2;
+       }
+       info->adc_base_spear3xx =
+               (struct adc_regs_spear3xx *)info->adc_base_spear6xx;
+
+       info->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(info->clk)) {
+               dev_err(&pdev->dev, "failed getting clock\n");
+               goto errout3;
+       }
+
+       ret = clk_prepare(info->clk);
+       if (ret) {
+               dev_err(&pdev->dev, "failed preparing clock\n");
+               goto errout3;
+       }
+
+       ret = clk_enable(info->clk);
+       if (ret) {
+               dev_err(&pdev->dev, "failed enabling clock\n");
+               goto errout3;

drivers/staging/iio/adc/spear_adc.c line 350

Quoted 10 lines
drivers/staging/iio/adc/spear_adc.c new file +10 -0
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if ((irq < 0) || (irq >= NR_IRQS)) {
+               dev_err(&pdev->dev, "failed getting interrupt resource\n");
+               ret = -EINVAL;
+               goto errout4;
+       }
+
+       ret = request_irq(irq, spear_adc_isr, 0, MOD_NAME, info);

devm_ ??

Otherwise: