x4412 基于设备树的 hello_world驱动

首先在exynos4412-x4412.dts文件中添加HelloWorld节点,如下:

HelloWorld {
         compatible = "x4412, hello_world";
         status = "okay";
};

然后新建一个 hello_world.c 源文件,具体源码如下:

/*
* Hello World Driver for X4412
*
* Copyright (c) 2018
* Author: YYH
* This is a simple module driver example for x4412 base on dts
*
*/

#include 
#include 
#include 
#include 

static int hello_world_probe(struct platform_device *pdev)
{
    pr_notice("Driver probe : %s\n", __func__);
    return 0;
}

static int hello_world_remove(struct platform_device *pdev)
{
    pr_notice("Driver remove :  %s\n", __func__);
    return 0;
}

static void hello_world_shutdown(struct platform_device *pdev)
{
    pr_notice("Driver shutdown :  %s\n", __func__);
    return ;
}

static int hello_world_suspend(struct platform_device *pdev, pm_message_t state)
{
    pr_notice("Driver suspend :  %s\n", __func__);
    return 0;
}

static int hello_world_resume(struct platform_device *pdev)
{
    pr_notice("Driver resume :  %s\n", __func__);
    return 0;
}

static const struct of_device_id tiny4412_hello_world_dt_match[] = {
{ 
    .compatible = "x4412,hello_world" },
    {},
};

static struct platform_driver x4412_hello_world_driver = {
    .probe = hello_world_probe,
    .remove = hello_world_remove,
    .shutdown = hello_world_shutdown,
    .suspend = hello_world_suspend,
    .resume = hello_world_resume,
    .driver = {
        .name = "hello world",
        .of_match_table = tiny4412_hello_world_dt_match,
    },

};

module_platform_driver(x4412_hello_world_driver);
MODULE_AUTHOR("YYH");
MODULE_LICENSE("GPL v2");

最后新建一个Makefile文件用来编译生成hello_world.ko文件。具体内容如下

obj-m := hello_world.o

PWD := $(shell pwd)
KDIR := /home/yyh/Desktop/farsight/linux-4.9.123

all:
    make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/home/yyh/Desktop/farsight/gcc4.6/gcc-4.6.4/bin/arm-none-linux-gnueabi-

clean:
    rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions

 

 

你可能感兴趣的:(linux)