给allwinner a20或者是a31重复制造轮子-----关于获得item以及GPIO设置

来源:互联网 发布:马克思cms 编辑:程序博客网 时间:2024/05/15 01:54

最近把在A10上的游戏项目往A20上移植发现GPIO的API变化好大,看了很多原来的函数其实也没什么差别的,但发现TP啊或者usb的VBUS拉电啊等等用到对GPIO设置的比较乱,看得非常郁闷,于是就下定决心制造一个轮子,让以后大家统一使用。


git show d7eb72208e5a046d8524d0c98346184d77cd92d7 > api.txt


diff --git a/arch/arm/mach-sun7i/Makefile b/arch/arm/mach-sun7i/Makefile
index d69fb31..724d74e 100755
--- a/arch/arm/mach-sun7i/Makefile
+++ b/arch/arm/mach-sun7i/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_PM) += pm/
 obj-$(CONFIG_NET) += rf/
 obj-$(CONFIG_AW_TIME_DELAY) += delay.o
 obj-$(CONFIG_SW_POWERNOW) += powernow.o
+obj-y += a20_config/a20_config.o 
 
 ifeq ($(CONFIG_SMP),y)
 obj-y += platsmp.o headsmp.o
diff --git a/arch/arm/mach-sun7i/a20_config/a20_config.c b/arch/arm/mach-sun7i/a20_config/a20_config.c
new file mode 100644
index 0000000..98d00d1
--- /dev/null
+++ b/arch/arm/mach-sun7i/a20_config/a20_config.c
@@ -0,0 +1,169 @@
+#include <mach/sys_config.h>
+#include <mach/gpio.h>
+#include <linux/gpio.h>
+#include <linux/types.h>
+#include <mach/system.h>
+#include <linux/errno.h>
+#include <mach/a20_config.h>
+#include <linux/string.h>
+
+int a20_Getsys_configData(char *main_name, char *sub_name, int value[], int count)
+{
+    script_item_u   val;
+    script_item_value_type_e  type;
+    int ret = -1;
+
+    if(count == 1)
+    {
+        type = script_get_item(main_name, sub_name, &val);
+        if(SCIRPT_ITEM_VALUE_TYPE_INT == type)
+        {
+            ret = 0;
+            *value = val.val;
+            printk("%s.%s=%d\n", main_name, sub_name, *value);
+        }
+        else
+        {
+            ret = -1;
+            printk("fetch script data %s.%s fail\n", main_name, sub_name);
+        }
+    }
+    else if(count == sizeof(a20_gpio_set_t)/sizeof(int))
+    {
+        type = script_get_item(main_name, sub_name, &val);
+        if(SCIRPT_ITEM_VALUE_TYPE_PIO == type)
+        {
+            a20_gpio_set_t *gpio_info = (a20_gpio_set_t *)value;
+
+            ret = 0;
+            gpio_info->gpio = val.gpio.gpio;
+            gpio_info->mul_sel = val.gpio.mul_sel;
+            gpio_info->pull = val.gpio.pull;
+            gpio_info->drv_level = val.gpio.drv_level;
+            gpio_info->data = val.gpio.data;
+            memcpy(gpio_info->gpio_name, sub_name, strlen(sub_name)+1);
+            printk("------%s.%s gpio=%d,mul_sel=%d,data:%d\n",main_name, sub_name, gpio_info->gpio, gpio_info->mul_sel, gpio_info->data);
+        }
+        else
+        {
+            ret = -1;
+            printk("fetch script data %s.%s fail\n", main_name, sub_name);
+        }
+    }
+
+    return ret;
+}
+
+EXPORT_SYMBOL(a20_Getsys_configData);
+
+u32 a20_GPIO_Request(a20_gpio_set_t *gpio_list, __u32 group_count_max)
+{    
+    int ret = 0;
+    struct gpio_config pcfg;
+
+    if(gpio_list == NULL)
+        return 0;
+
+    pcfg.gpio = gpio_list->gpio;
+    pcfg.mul_sel = gpio_list->mul_sel;
+    pcfg.pull = gpio_list->pull;
+    pcfg.drv_level = gpio_list->drv_level;
+    pcfg.data = gpio_list->data;
+    if(0 != gpio_request(pcfg.gpio, NULL))
+    {
+        printk("a20_GPIO_Request failed, gpio_name=%s, gpio=%d\n", gpio_list->gpio_name, gpio_list->gpio);
+        return ret;
+    }
+
+    if(0 != sw_gpio_setall_range(&pcfg, group_count_max))
+    {
+        printk("---:setall_range fail,gpio_name=%s,gpio=%d,mul_sel=%d\n", gpio_list->gpio_name, gpio_list->gpio, gpio_list->mul_sel);
+    }
+    else
+    {
+        printk("--a20_GPIO_Request ok,gpio_name=%s,gpio=%d,mul_sel=%d,gpio_data=%d\n", gpio_list->gpio_name, gpio_list->gpio, gpio_list->mul_sel,gpio_list->data);
+        ret = pcfg.gpio;
+    }
+
+    return ret;
+}
+
+EXPORT_SYMBOL(a20_GPIO_Request);
+
+
+__s32 a20_GPIO_Release(u32 p_handler, __s32 if_release_to_default_status)
+{
+    if(p_handler)
+    {
+        gpio_free(p_handler);
+    }
+    else
+    {
+        printk("a20_GPIO_Release, hdl is NULL\n");
+    }
+    return 0;
+}
+
+EXPORT_SYMBOL(a20_GPIO_Release);
+
+
+__s32 a20_GPIO_DevSetONEPIN_IO_STATUS(u32 p_handler, __u32 if_set_to_output_status, const char *gpio_name)
+{
+    int ret = -1;
+
+    if(p_handler)
+    {
+        if(if_set_to_output_status)
+        {
+            ret = gpio_direction_output(p_handler, 0);
+            if(ret != 0)
+            {
+                printk("gpio_direction_output fail!\n");
+            }
+        }
+        else
+        {
+            ret = gpio_direction_input(p_handler);
+            if(ret != 0)
+            {
+                printk("gpio_direction_input fail!\n");
+            }
+        }
+    }
+    else
+    {
+        printk("a20_GPIO_DevSetONEPIN_IO_STATUS, hdl is NULL\n");
+        ret = -1;
+    }
+    return ret;
+}
+EXPORT_SYMBOL(a20_GPIO_DevSetONEPIN_IO_STATUS);
+
+
+__s32 a20_GPIO_DevREAD_ONEPIN_DATA(u32 p_handler, const char *gpio_name)
+{
+    if(p_handler)
+    {
+        return __gpio_get_value(p_handler);
+    }
+    printk("a20_GPIO_DevREAD_ONEPIN_DATA, hdl is NULL\n");
+    return -1;
+}
+EXPORT_SYMBOL(a20_GPIO_DevREAD_ONEPIN_DATA);
+
+
+__s32 a20_GPIO_DevWRITE_ONEPIN_DATA(u32 p_handler, __u32 value_to_gpio, const char *gpio_name)
+{
+    if(p_handler)
+    {
+        __gpio_set_value(p_handler, value_to_gpio);
+    }
+    else
+    {
+        printk("a20_GPIO_DevWRITE_ONEPIN_DATA, hdl is NULL\n");
+    }
+
+    return 0;
+}
+EXPORT_SYMBOL(a20_GPIO_DevWRITE_ONEPIN_DATA);
+
diff --git a/arch/arm/mach-sun7i/include/mach/a20_config.h b/arch/arm/mach-sun7i/include/mach/a20_config.h
new file mode 100644
index 0000000..3058e48
--- /dev/null
+++ b/arch/arm/mach-sun7i/include/mach/a20_config.h
@@ -0,0 +1,48 @@
+#ifndef  __A20_CONFIG_SW__
+#define  __A20_CONFIG_SW__
+
+
+typedef struct
+{        
+    char    gpio_name[32];
+    int     port; 
+    int     port_num;
+    int     mul_sel;
+    int     pull;
+    int     drv_level;
+    int     data;
+    int     gpio;
+} a20_gpio_set_t;           
+
+
+//-------------------------------------------------------------
+extern int a20_Getsys_configData(char *main_name, char *sub_name, int value[], int count);
+
+extern unsigned a20_GPIO_Request(a20_gpio_set_t *gpio_list, __u32 group_count_max);
+
+extern int a20_GPIO_Release(u32 p_handler, __s32 if_release_to_default_status);
+
+extern int a20_GPIO_DevSetONEPIN_IO_STATUS(u32 p_handler, __u32 if_set_to_output_status, const char *gpio_name);
+
+extern int  a20_GPIO_DevREAD_ONEPIN_DATA(u32 p_handler, const char *gpio_name);
+
+extern int a20_GPIO_DevWRITE_ONEPIN_DATA(u32 p_handler, __u32 value_to_gpio, const char *gpio_name);
+
+
+#endif

原创粉丝点击