iio: at91_adc: add sleep mode support
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Fri, 29 Mar 2013 14:54:00 +0000 (14:54 +0000)
committerJonathan Cameron <jic23@kernel.org>
Tue, 2 Apr 2013 18:17:39 +0000 (19:17 +0100)
The sleep mode will allow to put the adc in sleep between conversion.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Documentation/devicetree/bindings/arm/atmel-adc.txt
drivers/iio/adc/at91_adc.c

index fd2d69ee2876bd958ccd88748d8717cf9fd8eb6b..3a05492acdafb5736862a6a43a100d17cd2cb5ab 100644 (file)
@@ -25,6 +25,7 @@ Optional properties:
   - atmel,adc-use-res: String corresponding to an identifier from
                       atmel,adc-res-names property. If not specified, the highest
                       resolution will be used.
+  - atmel,adc-sleep-mode: Boolean to enable sleep mode when no conversion
  
 Optional trigger Nodes:
   - Required properties:
index 3fb3fe48a98c7dc45dfaa2a4f91cf07276a8648c..7295bc5280bd9fe8a7884fb1ace177d86c430e4c 100644 (file)
@@ -52,6 +52,7 @@ struct at91_adc_state {
        void __iomem            *reg_base;
        struct at91_adc_reg_desc *registers;
        u8                      startup_time;
+       bool                    sleep_mode;
        struct iio_trigger      **trig;
        struct at91_adc_trigger *trigger_list;
        u32                     trigger_number;
@@ -455,6 +456,8 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
        }
        st->num_channels = prop;
 
+       st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode");
+
        if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) {
                dev_err(&idev->dev, "Missing adc-startup-time property in the DT.\n");
                ret = -EINVAL;
@@ -580,6 +583,7 @@ static int at91_adc_probe(struct platform_device *pdev)
        struct iio_dev *idev;
        struct at91_adc_state *st;
        struct resource *res;
+       u32 reg;
 
        idev = iio_device_alloc(sizeof(struct at91_adc_state));
        if (idev == NULL) {
@@ -687,16 +691,13 @@ static int at91_adc_probe(struct platform_device *pdev)
         */
        ticks = round_up((st->startup_time * adc_clk /
                          1000000) - 1, 8) / 8;
-
+       reg = AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL;
+       reg |= AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP;
        if (st->low_res)
-               at91_adc_writel(st, AT91_ADC_MR,
-                               AT91_ADC_LOWRES |
-                               (AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL) |
-                               (AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP));
-       else
-               at91_adc_writel(st, AT91_ADC_MR,
-                               (AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL) |
-                               (AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP));
+               reg |= AT91_ADC_LOWRES;
+       if (st->sleep_mode)
+               reg |= AT91_ADC_SLEEP;
+       at91_adc_writel(st, AT91_ADC_MR, reg);
 
        /* Setup the ADC channels available on the board */
        ret = at91_adc_channel_init(idev);