给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
- 给allwinner a20或者是a31重复制造轮子-----关于获得item以及GPIO设置
- allwinner A20 SPI配置
- 不相信“不要重复制造轮子”的论述!
- Allwinner A33/A31 FrameWare基本配置
- A20 GPIO
- Android Studio 如何导出和导入自己的常用设置,避免重复制造轮子。加快开发速度
- 拒绝重复制造轮子, 一起来让开发一“键”化
- 关于不要重复造轮子的二三事
- 关于不要重复造轮子的二三事
- 关于不要重复造轮子的二三事
- A20 操作GPIO口
- 关于GPIO的设置
- adapt下listview给整个item或者内部控件设置监听器
- 解决fragment中listView或者gridView给item设置监听,点击空指针问题
- 关于A20
- python FIFO算法模拟(又是重复造轮子)
- A20,gpio模拟spi 通信
- 关于重复造轮子的一些延续思考
- 关于用JLINK下载程序到博创UP-TECH2410板子上自动重启的问题__zhusjian
- 状态栏
- 代码优化:使用复合赋值运算符提供性能:a=a+b和a+=b的性能区别
- 字符串相关函数
- linux必学的60个命令
- 给allwinner a20或者是a31重复制造轮子-----关于获得item以及GPIO设置
- MiniGUI源码分析——主窗口诞生的秘密
- jsp,java在桌面生成网站快捷方式
- Uninstall Dropbox with WindowsUninstaller.Org Removal Tips
- Exercise 4.1 E2
- 恢复oracle数据 回闪
- 4.2E2 4.3E2
- poj1830
- exercise 4.2