当前位置:   article > 正文

rk3288 Android5.1添加自己的驱动-kernel 篇 test_rk3588怎么在sdk中添加自己的驱动

rk3588怎么在sdk中添加自己的驱动
  1. 给自己要添加驱动建立个总文件夹:test gpio
  2. ~/rk3288/kernel/drivers$ vim Kconfig
    追加
source "drivers/test/Kconfig"
  • 1
  1. ~/rk3288/kernel/drivers$ vim Makefile
    追加
obj-$(CONFIG_TESTHX)            += test/
  • 1
  1. 进入test 文件夹 添加 Kconfig Makefile
    (1): Kconfig
#
# Test HX
#

menuconfig TESTHX
	default y 
	bool "My TEST"
	---help---
		Yon can say N if don't want test.


if TESTHX
	
	source "drivers/test/gpio/Kconfig"

endif #TESTHX
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

(2) Makefile

#
#
#

obj-y += gpio/


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  1. gpio 下 添加驱动程序
    (1) Kconfig
#
# gpio contrl
#

config GPIO_CTRL
	tristate "GPIO CTRL"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

(2)Makefile

#
#
#

obj-$(CONFIG_GPIO_CTRL) += gpio-ctrl.o


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

ps:
Makefile文件的内容

    obj-$(CONFIG_TESTDEV) +=gpio-ctrl.o
    编译目标定义,定义gpio-ctrl.o这个目标是要编译进内核,还是作为模块编译:
    obj-y +=gpio-ctrl.o //编译进内核
    obj-m+= gpio-ctrl.o //作为模块编译
      obj-n += gpio-ctrl.o //不编译
  取值有$(CONFIG_GPIO_CTRL)决定,而它的只在内核模块编译配置时,有用户设置
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

(3)gpio-ctrl.c

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h> 
#include <linux/delay.h>
#define CONFIG_OF 1
#include <linux/gpio.h>
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/of_platform.h>
#endif


#define GPIO_LOW 0
#define GPIO_HIGH 1

static int firefly_hello_probe(struct platform_device *pdev)
{
    int ret = -1;
	int i;
    int gpio;
	enum of_gpio_flags flag;
	struct device_node *hello_node = pdev->dev.of_node;
	printk("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

	printk("%s-%d: enter\n",__FUNCTION__,__LINE__);

	gpio = of_get_named_gpio_flags(hello_node,"led", 0,&flag);
	if (!gpio_is_valid(gpio)){
		printk("hello: invalid gpio : %d\n",gpio);
		return -1;
	} 
    ret = gpio_request(gpio, "hello_led");
	if (ret != 0) {
		gpio_free(gpio);
		return -EIO;
	}
	printk("!!!flag:%d\n", flag);
	gpio_direction_output(gpio, GPIO_HIGH);
	printk("~~gpio:%d, value:%d\n",gpio,gpio_get_value(gpio));
//        gpio_set_value(gpio, 1);
	gpio = of_get_named_gpio_flags(hello_node,"led1", 0,&flag);
	if (!gpio_is_valid(gpio)){
		printk("hello: invalid gpio : %d\n",gpio);
		return -1;
	} 
    ret = gpio_request(gpio, "hello_led");
	if (ret != 0) {
		gpio_free(gpio);
		return -EIO;
	}

	gpio_direction_output(gpio, GPIO_HIGH);
	printk("~~gpio:%d, value:%d\n",gpio,gpio_get_value(gpio));
//        gpio_set_value(gpio, 1);
	gpio = of_get_named_gpio_flags(hello_node,"led2", 0,&flag);
	if (!gpio_is_valid(gpio)){
		printk("hello: invalid gpio : %d\n",gpio);
		return -1;
	} 
    ret = gpio_request(gpio, "hello_led");
	if (ret != 0) {
		gpio_free(gpio);
		return -EIO;
	}

	gpio_direction_output(gpio, GPIO_HIGH);
	printk("~~gpio:%d, value:%d\n",gpio,gpio_get_value(gpio));
        //gpio_set_value(gpio, 1);
	gpio = of_get_named_gpio_flags(hello_node,"led3", 0,&flag);
	if (!gpio_is_valid(gpio)){
		printk("hello: invalid gpio : %d\n",gpio);
		return -1;
	} 
    ret = gpio_request(gpio, "hello_led");
	if (ret != 0) {
		gpio_free(gpio);
		return -EIO;
	}

	gpio_direction_output(gpio, GPIO_HIGH);
	printk("~~gpio:%d, value:%d\n",gpio,gpio_get_value(gpio));
        //gpio_set_value(gpio, 1);

/*	for(i=0; i < 10; i++)
	{
		gpio_set_value(gpio,GPIO_LOW);
		mdelay(500);
		gpio_set_value(gpio,GPIO_HIGH);
		mdelay(500);
	}
*/    	
	printk("%s-%d: exit\n",__FUNCTION__,__LINE__);
	
	return 0;  //return Ok
}


static int firefly_hello_remove(struct platform_device *pdev)
{ 
    return 0;
}
#ifdef CONFIG_OF
static const struct of_device_id of_firefly_hello_match[] = {
	{ .compatible = "firefly,hello_led" },
	{ /* Sentinel */ }
};
#endif

static struct platform_driver firefly_hello_driver = {
	.probe		= firefly_hello_probe,
	.remove		= firefly_hello_remove,
	.driver		= {
		.name	= "firefly_hello",
		.owner	= THIS_MODULE,
#ifdef CONFIG_OF
		.of_match_table	= of_firefly_hello_match,
#endif
	},

};

static int __init hello_init(void)
{
    printk(KERN_INFO "Enter %s\n", __FUNCTION__);
    return platform_driver_register(&firefly_hello_driver);
    return 0;
}

static void __exit hello_exit(void)
{
	platform_driver_unregister(&firefly_hello_driver);
    printk("Exit Hello world\n");
}

subsys_initcall(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("sai <271319925@qq.com>");
MODULE_DESCRIPTION("Firefly hello driver");
MODULE_LICENSE("GPL");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141

Ps:工程文件
在这里插入图片描述
make menuconfig
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/134425
推荐阅读
相关标签
  

闽ICP备14008679号