Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30183639
  • 博文数量: 230
  • 博客积分: 2868
  • 博客等级: 少校
  • 技术积分: 2223
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-08 21:48
个人简介

Live & Learn

文章分类

全部博文(230)

文章存档

2022年(2)

2019年(5)

2018年(15)

2017年(42)

2016年(24)

2015年(13)

2014年(1)

2012年(5)

2011年(58)

2010年(56)

2009年(9)

我的朋友

分类: LINUX

2017-05-18 15:22:14

1. dts configuration

./kernel_imx/arch/arm/boot/dts/imx6sl-evk.dts


[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ......  
  2. &iomuxc {  
  3.         pinctrl-names = "default", "sleep";  
  4.         pinctrl-0 = <&pinctrl_hog>;  
  5.         pinctrl-1 = <&pinctrl_hog_sleep>;  
  6.   
  7.         hog {  
  8.                 pinctrl_hog: hoggrp {  
  9.                         fsl,pins = <  
  10.                                 MX6SL_PAD_KEY_ROW7__GPIO4_IO07    0x17059  
  11.                                 MX6SL_PAD_KEY_COL7__GPIO4_IO06    0x17059  
  12.                                 MX6SL_PAD_SD2_DAT7__GPIO5_IO00    0x17059  
  13.                                 MX6SL_PAD_SD2_DAT6__GPIO4_IO29    0x17059  
  14.                                 MX6SL_PAD_REF_CLK_32K__GPIO3_IO22 0x17059  
  15.                                 MX6SL_PAD_FEC_TX_CLK__GPIO4_IO21  0x80000000  
  16.                                 MX6SL_PAD_KEY_ROW5__GPIO4_IO03    0x110b0  
  17.                                 MX6SL_PAD_EPDC_VCOM0__GPIO2_IO03  0x80000000  
  18.                                 MX6SL_PAD_EPDC_PWRSTAT__GPIO2_IO13 0x80000000  
  19.                                 MX6SL_PAD_EPDC_PWRCTRL0__GPIO2_IO07 0x4001b0b0 /*luke modify 20161125*/  
  20.                                 MX6SL_PAD_EPDC_PWRWAKEUP__GPIO2_IO14 0x80000000  
  21.                                 MX6SL_PAD_EPDC_PWRINT__GPIO2_IO12 0x80000000  
  22.                                 MX6SL_PAD_EPDC_PWRCTRL3__GPIO2_IO10 0x170b0  
  23.                                 MX6SL_PAD_EPDC_PWRCTRL2__GPIO2_IO09 0x80000000  
  24.                                 MX6SL_PAD_KEY_COL6__GPIO4_IO04    0x110b0  
  25.                                 MX6SL_PAD_ECSPI2_MISO__GPIO4_IO14 0x17000  
  26.                                 MX6SL_PAD_ECSPI2_MOSI__GPIO4_IO13 0x17000  
  27.                                 MX6SL_PAD_ECSPI2_SS0__GPIO4_IO15  0x17000  
  28.                                 MX6SL_PAD_FEC_RX_ER__GPIO4_IO19   0x1b0b0  
  29.                                 MX6SL_PAD_LCD_RESET__GPIO2_IO19 0x1b0b0  
  30.                                 MX6SL_PAD_KEY_COL4__GPIO4_IO00  0x80000000  
  31.                                 MX6SL_PAD_KEY_COL5__GPIO4_IO02  0x80000000  
  32.                         >;  
  33.                 };  
  34.   
  35.                 pinctrl_hog_sleep: hoggrp_sleep {  
  36.                         fsl,pins = <  
  37.                                 MX6SL_PAD_KEY_ROW5__GPIO4_IO03    0x3080  
  38.                                 MX6SL_PAD_KEY_COL6__GPIO4_IO04    0x3080  
  39.                                 MX6SL_PAD_LCD_RESET__GPIO2_IO19   0x3080  
  40.                         >;  
  41.                 };  
  42.         };  
  43. };  
  44. ......  

./kernel_imx/arch/arm/boot/dts/imx6sl-evk-common.dtsi



[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ......  
  2.       /*luke add hello gpio test 20161125*/  
  3.        hello-led {  
  4.                  compatible = "firefly,hello_led";  
  5.                  led = <&gpio2 7 0>;  
  6.                  status = "okay";  
  7.          };   
  8. ......  

2. kernel module

2.1 add .c file

./kernel_imx/drivers/hello_led_module/hello.c


[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #include   
  2. #include   
  3. #include    
  4. #include   
  5. #include   
  6.   
  7. #ifdef CONFIG_OF  
  8. #include   
  9. #include   
  10. #include   
  11. #endif  
  12.   
  13.   
  14. #define GPIO_LOW 0  
  15. #define GPIO_HIGH 1  
  16.   
  17. static int firefly_hello_probe(struct platform_device *pdev)  
  18. {  
  19.     int ret = -1;  
  20.     int i;  
  21.     int gpio,flag;  
  22.     struct device_node *hello_node = pdev->dev.of_node;  
  23.   
  24.     printk(KERN_INFO "%s() enter line:%d\n",__FUNCTION__,__LINE__);  
  25.   
  26.     gpio = of_get_named_gpio_flags(hello_node,"led", 0,&flag);  
  27.     if (!gpio_is_valid(gpio)){  
  28.         printk(KERN_INFO "hello: invalid gpio : %d\n",gpio);  
  29.         return -1;  
  30.     }   
  31.     ret = gpio_request(gpio, "hello_led");  
  32.     if (ret != 0) {  
  33.         gpio_free(gpio);  
  34.         printk(KERN_INFO "hello: invalid request : %d\n",gpio);  
  35.         return -EIO;  
  36.     }  
  37.   
  38.     gpio_direction_output(gpio, GPIO_HIGH);  
  39.   
  40.     for(i=0; i < 10; i++)  
  41.     {  
  42.         gpio_set_value(gpio,GPIO_LOW);  
  43.         mdelay(500);  
  44.         gpio_set_value(gpio,GPIO_HIGH);  
  45.         mdelay(500);  
  46.     }  
  47.           
  48.     printk(KERN_INFO "%s() exit line:%d\n",__FUNCTION__,__LINE__);  
  49.       
  50.     return 0;  //return Ok  
  51. }  
  52.   
  53.   
  54. static int firefly_hello_remove(struct platform_device *pdev)  
  55. {   
  56.     struct device_node *hello_node = pdev->dev.of_node;  
  57.         int gpio,flag;  
  58.     gpio = of_get_named_gpio_flags(hello_node,"led", 0,&flag);  
  59.     if (!gpio_is_valid(gpio)){  
  60.         printk(KERN_INFO "hello: invalid gpio : %d\n",gpio);  
  61.         return -1;  
  62.     }   
  63.         gpio_free(gpio);  
  64.     return 0;  
  65. }  
  66. #ifdef CONFIG_OF  
  67. static const struct of_device_id of_firefly_hello_match[] = {  
  68.     { .compatible = "firefly,hello_led" },  
  69.     { /* Sentinel */ }  
  70. };  
  71. #endif  
  72.   
  73. static struct platform_driver firefly_hello_driver = {  
  74.     .probe      = firefly_hello_probe,  
  75.     .remove     = firefly_hello_remove,  
  76.     .driver     = {  
  77.         .name   = "firefly_hello",  
  78.         .owner  = THIS_MODULE,  
  79. #ifdef CONFIG_OF  
  80.         .of_match_table = of_match_ptr(of_firefly_hello_match),  
  81. #endif  
  82.     },  
  83.   
  84. };  
  85.   
  86. static int __init hello_init(void)  
  87. {  
  88.     printk(KERN_INFO "Enter %s\n", __FUNCTION__);  
  89.     return platform_driver_register(&firefly_hello_driver);  
  90. }  
  91.   
  92. static void __exit hello_exit(void)  
  93. {  
  94.     platform_driver_unregister(&firefly_hello_driver);  
  95.     printk("Exit Hello world\n");  
  96. }  
  97.   
  98. module_init(hello_init);  
  99. module_exit(hello_exit);  
  100.   
  101. MODULE_AUTHOR("sai <271319925@qq.com>");  
  102. MODULE_DESCRIPTION("Firefly hello driver");  
  103. MODULE_LICENSE("GPL");  

ps: we can also ignore dev_node and of_get_named_gpio_flags() if use 37(GPIO2_IO07=32+7=39) directly.

2.2 add Makefile

./kernel_imx/drivers/hello_led_module/Makefile


[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. PWD = $(shell pwd)  
  2. KERNEL_SRC = /home/xxx/Projects/Android/android4.4.3/kernel_imx/  
  3. CROSS_COMPILE = /home/xxx/Projects/Android/android4.4.3/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-  
  4.   
  5. obj-m := hello.o  
  6. all:  
  7.         make ARCH=arm CFLAGS_MODULE=-fno-pic  CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_SRC) M=$(PWD) modules  
  8. clean:  
  9.         make ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_SRC) M=$(PWD) clean  


2.3 compile


cd ./kernel_imx/driver/hello_module

make

3. result


阅读(1972) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~