本帖最后由 wuQAQ 于 2017-7-11 21:03 编辑
1、下载内核源码并编译
// 下载内核
git clone https://TeeFirefly@gitlab.com/TeeFirefly/linux-kernel.git
// 下载工具链
git clone https://TeeFirefly@gitlab.com/TeeFirefly/prebuilts.git
// 上面两个文件夹要放在同一个目录下
//编译
make ARCH=arm64 firefly_linux_defconfig
make ARCH=arm64 rk3399-firefly-linux.img -j8
2、修改DTS文件
DTS是Device Tree Source的缩写,用来描述设备的硬件细节。在firefly RK3399的内核源码中,使用的DTS路径是~/linuxkernel/arch/arm64/boot/dts/rockchip,使用的dts文件是rk3399-firefly-linux.dts
在这个文件下添加如下代码:
gpio_demo: gpio_demo {
status = "okay";
compatible = "firefly,rk3399-gpio";
firefly-gpio = <&gpio0 12 GPIO_ACTIVE_HIGH>; /* GPIO1_B4 */
};
对应的引脚为下图中红色画圈的引脚:
3、增加驱动源码
在~/linux-kernel/drivers/目录下增加自己的驱动文件夹wu_led
cd ~/linux-kernel/drivers/
mkdir wu_led
修改~/linux-kernel/drivers/目录下的Kconfig和Makefile文件
在Kconfig文件的endmenu前添加下面这行代码:
source "drivers/wu_led/Kconfig"
在Makefile文件最后添加下面这行代码:
obj-y += wu_led/
在新建的wu_led.c文件内添加自己的驱动代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define GPIO_LOW 0
#define GPIO_HIGH 1
static int firefly_hello_probe(struct platform_device *pdev)
{
int i;
int gpio;
enum of_gpio_flags flag;
struct firefly_gpio_info *gpio_info;
struct device_node *firefly_gpio_node = pdev->dev.of_node;
printk(KERN_INFO "Firefly GPIO Test Program Probe\n");
gpio_info = devm_kzalloc(&pdev->dev,sizeof(struct firefly_gpio_info *), GFP_KERNEL);
if (!gpio_info) {
return -ENOMEM;
}
gpio = of_get_named_gpio_flags(firefly_gpio_node, "firefly-gpio", 0, &flag);
if (!gpio_is_valid(gpio)) {
printk("firefly-gpio: %d is invalid\n", gpio);
return -ENODEV;
}
while (gpio_request(gpio, "firefly-gpio")) {
printk("gpio %d request failed!\n", gpio);
gpio_free(gpio);
return -ENODEV;
}
gpio_direction_output(gpio, GPIO_HIGH);
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,rk3399-gpio" },
{ /* Sentinel */ }
};
#endif
static struct platform_driver firefly_hello_driver = {
.probe = firefly_hello_probe,
.remove = firefly_hello_remove,
.driver = {
.name = "wu_led",
.owner = THIS_MODULE,
.of_match_table = of_firefly_hello_match,
},
};
static int __init hello_init(void)
{
int a;
printk(KERN_INFO "Enter %s\n", __FUNCTION__);
a = platform_driver_register(&firefly_hello_driver);
printk(KERN_INFO "Info %d\n", a);
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("wuQAQ");
MODULE_DESCRIPTION("Firefly gpio driver");
MODULE_LICENSE("GPL");
在wu_led文件夹内增加Kconfig文件:
config WU_LED
tristate "Firefly wu led support"
depends on GPIOLIB
default y
help
Select this option if your Firefly board needs to run LED demo.
在wu_led文件夹内增加Makefile文件:
obj-$(CONFIG_WU_LED) += wu_led.o
4、再次编译
//重新编译
make ARCH=arm64 firefly_linux_defconfig
make ARCH=arm64 rk3399-firefly-linux.img -j8
//然后将生成的Kernel.img和resource.img文件一同烧录到板子中
5、效果显示:
代码包:
本帖最后由 wuQAQ 于 2017-7-11 21:03 编辑
1、下载内核源码并编译
// 下载内核
git clone https://TeeFirefly@gitlab.com/TeeFirefly/linux-kernel.git
// 下载工具链
git clone https://TeeFirefly@gitlab.com/TeeFirefly/prebuilts.git
// 上面两个文件夹要放在同一个目录下
//编译
make ARCH=arm64 firefly_linux_defconfig
make ARCH=arm64 rk3399-firefly-linux.img -j8
2、修改DTS文件
DTS是Device Tree Source的缩写,用来描述设备的硬件细节。在firefly RK3399的内核源码中,使用的DTS路径是~/linuxkernel/arch/arm64/boot/dts/rockchip,使用的dts文件是rk3399-firefly-linux.dts
在这个文件下添加如下代码:
gpio_demo: gpio_demo {
status = "okay";
compatible = "firefly,rk3399-gpio";
firefly-gpio = <&gpio0 12 GPIO_ACTIVE_HIGH>; /* GPIO1_B4 */
};
对应的引脚为下图中红色画圈的引脚:
3、增加驱动源码
在~/linux-kernel/drivers/目录下增加自己的驱动文件夹wu_led
cd ~/linux-kernel/drivers/
mkdir wu_led
修改~/linux-kernel/drivers/目录下的Kconfig和Makefile文件
在Kconfig文件的endmenu前添加下面这行代码:
source "drivers/wu_led/Kconfig"
在Makefile文件最后添加下面这行代码:
obj-y += wu_led/
在新建的wu_led.c文件内添加自己的驱动代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define GPIO_LOW 0
#define GPIO_HIGH 1
static int firefly_hello_probe(struct platform_device *pdev)
{
int i;
int gpio;
enum of_gpio_flags flag;
struct firefly_gpio_info *gpio_info;
struct device_node *firefly_gpio_node = pdev->dev.of_node;
printk(KERN_INFO "Firefly GPIO Test Program Probe\n");
gpio_info = devm_kzalloc(&pdev->dev,sizeof(struct firefly_gpio_info *), GFP_KERNEL);
if (!gpio_info) {
return -ENOMEM;
}
gpio = of_get_named_gpio_flags(firefly_gpio_node, "firefly-gpio", 0, &flag);
if (!gpio_is_valid(gpio)) {
printk("firefly-gpio: %d is invalid\n", gpio);
return -ENODEV;
}
while (gpio_request(gpio, "firefly-gpio")) {
printk("gpio %d request failed!\n", gpio);
gpio_free(gpio);
return -ENODEV;
}
gpio_direction_output(gpio, GPIO_HIGH);
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,rk3399-gpio" },
{ /* Sentinel */ }
};
#endif
static struct platform_driver firefly_hello_driver = {
.probe = firefly_hello_probe,
.remove = firefly_hello_remove,
.driver = {
.name = "wu_led",
.owner = THIS_MODULE,
.of_match_table = of_firefly_hello_match,
},
};
static int __init hello_init(void)
{
int a;
printk(KERN_INFO "Enter %s\n", __FUNCTION__);
a = platform_driver_register(&firefly_hello_driver);
printk(KERN_INFO "Info %d\n", a);
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("wuQAQ");
MODULE_DESCRIPTION("Firefly gpio driver");
MODULE_LICENSE("GPL");
在wu_led文件夹内增加Kconfig文件:
config WU_LED
tristate "Firefly wu led support"
depends on GPIOLIB
default y
help
Select this option if your Firefly board needs to run LED demo.
在wu_led文件夹内增加Makefile文件:
obj-$(CONFIG_WU_LED) += wu_led.o
4、再次编译
//重新编译
make ARCH=arm64 firefly_linux_defconfig
make ARCH=arm64 rk3399-firefly-linux.img -j8
//然后将生成的Kernel.img和resource.img文件一同烧录到板子中
5、效果显示:
代码包: