[acme-dev] SF.net SVN: acme-dev:[44] kernel-stuff/adc-driver/at91-adc.c

  • From: claudyus@xxxxxxxxxxxxxxxxxxxxx
  • To: acme-dev@xxxxxxxxxxxxx
  • Date: Tue, 22 Jun 2010 14:06:32 +0000

Revision: 44
          http://acme-dev.svn.sourceforge.net/acme-dev/?rev=44&view=rev
Author:   claudyus
Date:     2010-06-22 14:06:32 +0000 (Tue, 22 Jun 2010)

Log Message:
-----------
[adc] Reimplement the request and free call

Modified Paths:
--------------
    kernel-stuff/adc-driver/at91-adc.c

Modified: kernel-stuff/adc-driver/at91-adc.c
===================================================================
--- kernel-stuff/adc-driver/at91-adc.c  2010-06-22 14:06:13 UTC (rev 43)
+++ kernel-stuff/adc-driver/at91-adc.c  2010-06-22 14:06:32 UTC (rev 44)
@@ -35,12 +35,22 @@
 
 #include "at91_adc.h"
 
-#define DRV_CLASS       "at91_adc"
-#define ADC_REQUEST 1                  //un-used atm
+#define DRV_CLASS      "at91_adc"
+
+#define ADC_REQUEST    1                       //un-used atm
 #define ADC_READ               2
+#define ADC_FREE               3
 
-static void at91_adc_device_release(struct device *dev){}
+/* Device functions */
+#define at91_adc_read(reg)                             ioread32(at91_adc_base 
+ (reg))
+#define at91_adc_write(reg, val)       iowrite32((val), at91_adc_base + (reg))
+#define AT91_DEFAULT_CONFIG                     AT91_ADC_SHTIM  | \
+                                                                               
                                                        AT91_ADC_STARTUP | \
+                                                                               
                                                        AT91_ADC_PRESCAL | \
+                                                                               
                                                        AT91_ADC_SLEEP
 
+static void at91_adc_device_release(struct device *dev) {}
+
 struct platform_device at91_adc_device = {
        .name                                   = "at91_adc",
        .id                                             = -1,
@@ -53,15 +63,6 @@
 static dev_t                            at91_adc_devno = 0;
 static struct class *at91_adc_class = NULL;
 
-
-/* Device functions */
-#define at91_adc_read(reg)                             ioread32(at91_adc_base 
+ (reg))
-#define at91_adc_write(reg, val)       iowrite32((val), at91_adc_base + (reg))
-#define AT91_DEFAULT_CONFIG                     AT91_ADC_SHTIM  | \
-                                                                               
                                                        AT91_ADC_STARTUP | \
-                                                                               
                                                        AT91_ADC_PRESCAL | \
-                                                                               
                                                        AT91_ADC_SLEEP
-
 static int at91_adc_read_chan(int chan){
        int val, sr;
 
@@ -69,16 +70,53 @@
                return -EINVAL;
        }
        at91_adc_write(AT91_ADC_CHER,AT91_ADC_CH(chan));                        
//Enable Channel
-       at91_adc_write(AT91_ADC_CR,AT91_ADC_START);                             
         //Start the ADC
+       at91_adc_write(AT91_ADC_CR,AT91_ADC_START);                             
        //Start the ADC
        
        for(sr=0; !(sr & AT91_ADC_EOC(chan)); sr=at91_adc_read(AT91_ADC_SR))
                cpu_relax();
 
-       val=at91_adc_read(AT91_ADC_CDR(chan)) & AT91_ADC_DATA; //Read up to 10 
bits
+       val=at91_adc_read(AT91_ADC_CHR(chan)) & AT91_ADC_DATA; //Read up to 10 
bits
 
        return val;
 }
 
+/*     PC0 -> AD0
+       PC1 ->  AD1
+       PC2 ->  AD2
+       PC3 ->  AD3 */
+static int mux_chan (int chan, int operation) {
+
+       int pin_chan;
+
+       if(chan<0 || chan>3){
+               return -EINVAL;
+       }
+
+       switch (chan) { 
+               case 0:
+                       pin_chan=AT91_PIN_PC0;
+                       break;
+               case 1:
+                       pin_chan=AT91_PIN_PC1;
+                       break;
+               case 2:
+                       pin_chan=AT91_PIN_PC2;
+                       break;
+               case 3:
+                       pin_chan=AT91_PIN_PC3;
+                       break;
+               default:
+                       return -EINVAL;
+       }
+
+       if (operation = 1)              //request_chan
+               at91_set_A_periph(pin_chan, 0);                         //Mux 
PIN to GPIO
+       else                                    //free_chan
+               at91_set_B_periph(pin_chan, 0);                         //Mux 
PIN to GPIO
+
+       return 0;
+}
+
 static int at91_adc_config(int requested_config){
        int actual_config;
 
@@ -135,10 +173,18 @@
        int retval = 0;
 
        switch (cmd) {
+               case ADC_REQUEST:
+                       return mux_chan ((int)arg, 1);
+                       break;
+
                case ADC_READ:
                        return at91_adc_read_chan((int)arg);
                        break;
 
+               case ADC_FREE:
+                       return mux_chan ((int)arg, 0);
+                       break;
+
                default:
                        retval = -EINVAL;
        }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [acme-dev] SF.net SVN: acme-dev:[44] kernel-stuff/adc-driver/at91-adc.c - claudyus