x4412 基于设备树的 hello_world驱动

本文详细介绍了如何在Exynos4412平台上创建并实现一个简单的HelloWorld驱动模块,包括在dts文件中添加节点、编写C源代码、定义驱动函数、设置设备匹配以及构建Makefile进行编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先在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 <linux/module.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/of.h>

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值