RK3368 GPU version: Rogue L 0.18
[firefly-linux-kernel-4.4.55.git] / drivers / adc / core.c
index ed8a4f78cd9ad5309e07fd222eb39d78d18e1b9e..91344386fedaf5d631181d5b84fc49a7cad2f999 100755 (executable)
@@ -7,7 +7,8 @@
 #include <linux/adc.h>
 #include "adc_priv.h"
 
-struct list_head adc_host_head;
+struct adc_host *g_adc = NULL;
+static LIST_HEAD(adc_host_head);
 
 struct adc_host *adc_alloc_host(struct device *dev, int extra, enum host_chn_mask mask)
 {
@@ -117,6 +118,7 @@ adc_sync_read_callback(struct adc_client *client, void *param, int result)
 {
         client->result = result;
 }
+
 static void adc_callback(struct adc_host *adc)
 {
         struct adc_request *req = NULL, *n = NULL;
@@ -135,6 +137,7 @@ static void adc_callback(struct adc_host *adc)
                 kfree(req);
         }
 }
+
 void adc_finished(struct adc_host *adc, int result)
 {
        unsigned long flags;
@@ -156,6 +159,7 @@ void adc_finished(struct adc_host *adc, int result)
 
         adc_callback(adc);
 }
+
 void adc_core_irq_handle(struct adc_host *adc)
 {
         int result = 0;
@@ -240,17 +244,29 @@ int adc_async_read(struct adc_client *client)
 
 EXPORT_SYMBOL(adc_async_read);
 
-static int __init adc_core_init(void)
+int adc_get_def_ref_volt(void)
 {
-        INIT_LIST_HEAD(&adc_host_head);
-        return 0;
+        return g_adc->pdata->ref_volt;
 }
-subsys_initcall(adc_core_init);
+EXPORT_SYMBOL(adc_get_def_ref_volt);
 
-static void __exit adc_core_exit(void)
+int adc_get_curr_ref_volt(void)
 {
-        return;
+        int v = 0, volt = 0;
+
+        if(!g_adc)
+                return -EINVAL;
+        if(!g_adc->base_client)
+                return g_adc->pdata->ref_volt;
+
+        volt = g_adc->pdata->get_base_volt();
+        if(volt < 0)
+                return g_adc->pdata->ref_volt;
+        
+        v = adc_sync_read(g_adc->base_client);
+        if(v < 0)
+                return v;
+
+        return volt * 1024 / v;
 }
-module_exit(adc_core_exit);  
-
-
+EXPORT_SYMBOL(adc_get_curr_ref_volt);