|
发表于 2013-1-20 16:22:34
|
显示全部楼层
控制GPIO好像很容易呀。这里有个例子
------------------
1. 修改配置文件增加gpio配置
pack/chips/sun4i/configs/linux/cubieboard/sys_config1.fex
;----------------------------------------------------------------------------------
;gpio configuration
;----------------------------------------------------------------------------------
[gpio_para]
gpio_pin_1 = portG03<1><default><default><1>
gpio_pin_2 = portB19<1><default><default><1>
gpio_pin_3 = portB13<1><default><default><1>
gpio_pin_4 = portG06<1><default><default><1>
gpio_pin_5 = portG05<1><default><default><1>
gpio_pin_6 = portG04<1><default><default><1>
gpio_pin_7 = portG01<1><default><default><1>
gpio_pin_8 = portG02<1><default><default><1>
gpio_pin_9 = portG00<1><default><default><1>
gpio_pin_10 = portH14<1><default><default><1>
gpio_pin_11 = port:PH15<1><default><default><1>
gpio_pin_12 = port:PI06<1><default><default><1>
gpio_pin_13 = port:PI05<1><default><default><1>
gpio_pin_14 = port:PI04<1><default><default><1>
gpio_pin_15 = port:PG11<1><default><default><1>
gpio_pin_16 = port:PG10<1><default><default><1>
gpio_pin_17 = port:PG09<1><default><default><1>
gpio_pin_18 = port:PG08<1><default><default><1>
gpio_pin_19 = port:PG07<1><default><default><1>
gpio_pin_20 = port:PE08<1><default><default><1>
gpio_pin_21 = port:PE07<1><default><default><1>
gpio_pin_22 = port:PE06<1><default><default><1>
gpio_pin_23 = port:PE05<1><default><default><1>
gpio_pin_24 = port:PE04<1><default><default><1>
gpio_pin_25 = port:PI09<1><default><default><1>
gpio_pin_26 = port:PI08<1><default><default><1>
gpio_pin_27 = port:PI07<1><default><default><1>
gpio_pin_28 = port:PD04<1><default><default><1>
gpio_pin_29 = port:PD03<1><default><default><1>
gpio_pin_30 = port:PD02<1><default><default><1>
gpio_pin_31 = port:PD01<1><default><default><1>
gpio_pin_32 = port:PD00<1><default><default><1>
gpio_pin_33 = port:PE11<1><default><default><1>
gpio_pin_34 = port:PE10<1><default><default><1>
gpio_pin_35 = port:PE09<1><default><default><1>
gpio_pin_36 = port:PD12<1><default><default><1>
gpio_pin_37 = port:PD11<1><default><default><1>
gpio_pin_38 = port:PD10<1><default><default><1>
gpio_pin_39 = port:PD09<1><default><default><1>
gpio_pin_40 = port:PD08<1><default><default><1>
gpio_pin_41 = port:PD07<1><default><default><1>
gpio_pin_42 = port:PD06<1><default><default><1>
gpio_pin_43 = port:PD05<1><default><default><1>
gpio_pin_44 = port:PD20<1><default><default><1>
gpio_pin_45 = port:PD19<1><default><default><1>
gpio_pin_46 = port:PD18<1><default><default><1>
gpio_pin_47 = port:PD17<1><default><default><1>
gpio_pin_48 = port:PD16<1><default><default><1>
gpio_pin_49 = port:PD15<1><default><default><1>
gpio_pin_50 = port:PD14<1><default><default><1>
gpio_pin_51 = port:PD13<1><default><default><1>
gpio_pin_52 = port:PB02<1><default><default><1>
gpio_pin_53 = port:PD25<1><default><default><1>
gpio_pin_54 = port:PD24<1><default><default><1>
gpio_pin_55 = port:PD26<1><default><default><1>
gpio_pin_56 = port:PD27<1><default><default><1>
gpio_pin_57 = port:PD23<1><default><default><1>
gpio_pin_58 = port:PD22<1><default><default><1>
gpio_pin_59 = port:PD21<1><default><default><1>
gpio_pin_60 = port:PI11<1><default><default><1>
gpio_pin_61 = port:PI13<1><default><default><1>
gpio_pin_62 = port:PI10<1><default><default><1>
gpio_pin_63 = port:PI12<1><default><default><1>
gpio_pin_64 = port:PB13<1><default><default><1>
gpio_pin_65 = port:PB11<1><default><default><1>
gpio_pin_66 = port:PB10<1><default><default><1>
gpio_pin_67 = port:PH07<1><default><default><1>
2. 增加简单gpio控制驱动
diff --git a/arch/arm/configs/cubieboard_defconfig b/arch/arm/configs/cubieboard_defconfig
index 99aabde..7aadbe7 100644
--- a/arch/arm/configs/cubieboard_defconfig
+++ b/arch/arm/configs/cubieboard_defconfig
@@ -667,6 +667,7 @@ CONFIG_SUNXI_NAND=y
# Misc devices
#
# CONFIG_SENSORS_LIS3LV02D is not set
+CONFIG_SUNXI_GPIO_TEST=m
# CONFIG_AD525X_DPOT is not set
# CONFIG_SUN4I_VIBRATOR is not set
# CONFIG_SUN4I_GPIO_UGLY is not set
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f16c278..caea49f 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -10,6 +10,11 @@ config SENSORS_LIS3LV02D
select INPUT_POLLDEV
default n
+config SUNXI_GPIO_TEST
+ tristate "cubieboard gpio test"
+ help
+ Tiny program to fire cubieboard's gpio small test board
+
config AD525X_DPOT
tristate "Analog Devices Digital Potentiometers"
depends on (I2C || SPI) && SYSFS
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index f49d878..562f7ca 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o
obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o
obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o
obj-$(CONFIG_INTEL_MID_PTI) += pti.o
+obj-$(CONFIG_SUNXI_GPIO_TEST) += gpio-test.o
obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
diff --git a/drivers/misc/gpio-test.c b/drivers/misc/gpio-test.c
new file mode 100644
index 0000000..35e6165
--- /dev/null
+++ b/drivers/misc/gpio-test.c
@@ -0,0 +1,58 @@
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <plat/sys_config.h>
+
+static u32 pio_hdle = 0;
+static const char *gpio_para = "gpio_para";
+static int nr_gpio_cnt = 68;
+
+void gpio_set_all(int v)
+{
+ int count = 0;
+ char buf[32];
+
+ memset(buf, 0, sizeof(buf));
+
+ for (count=1; count<68; count++) {
+ sprintf(buf, "gpio_pin_%d", count);
+ gpio_write_one_pin_value(pio_hdle, v, buf);
+ }
+}
+
+
+static int __init gpio_test_init(void)
+{
+
+ pr_info("gpio test init\n");
+ pio_hdle = gpio_request_ex(gpio_para, NULL);
+ pr_info("pio_hdle: %u\n", pio_hdle);
+
+ if(SCRIPT_PARSER_OK != script_parser_fetch("gpio_para", "gpio_num",
+ &nr_gpio_cnt, sizeof(nr_gpio_cnt)/sizeof(__u32))) {
+ printk("fetch gpio_num error\n");
+ nr_gpio_cnt = 67;
+ }
+
+ printk("gpio count: %d\n", nr_gpio_cnt);
+
+ gpio_set_all(0);
+ gpio_set_all(1);
+
+ return 0;
+}
+module_init(gpio_test_init);
+
+static void __exit gpio_test_exit(void)
+{
+ pr_info("gpio_test exit\n");
+
+ gpio_set_all(0);
+
+ gpio_release(pio_hdle, 1);
+}
+module_exit(gpio_test_exit);
+
+MODULE_LICENSE("GPL");
|
|