文章目录
- [0. env](#0. env)
- [10. 源码](#10. 源码)
-
- [1. driver](#1. driver)
- [2. device](#2. device)
- [3. usr](#3. usr)
- [4. Makefile](#4. Makefile)
- 90.附件
-
- [1. 源码下载](#1. 源码下载)
0. env
bash
ubuntu 1804
gcc 7.5
10. 源码
1. driver
i2c-dri-2991.c
c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
static int ltc_i2c_probe(struct platform_device *pev)
{
return 0;
}
static int ltc_i2c_remove(struct platform_device *pdev)
{
return 0;
}
static const struct of_device_id ltc_i2c_of_match[] = {
{ .compatible = "ltc,ltc2991-i2c" },
{},
};
MODULE_DEVICE_TABLE(of, ltc_i2c_of_match);
static struct platform_driver ltc_i2c_driver = {
.probe = ltc_i2c_probe,
.remove = ltc_i2c_remove,
.driver = {
.name = "i2c-ltc2991",
.of_match_table = ltc_i2c_of_match,
},
};
module_platform_driver(ltc_i2c_driver);
MODULE_LICENSE("GPL v2");
2. device
i2c-dev-2991.c
c
#include <linux/init.h>
#include <linux/module.h>
static int __init my_mod_init(void)
{
printk("mod init.\n");
return 0;
}
static void __exit my_mod_exit(void)
{
printk("mod exit.\n");
}
module_init(my_mod_init);
module_exit(my_mod_exit);
MODULE_LICENSE("GPL v2");
3. usr
略
4. Makefile
bash
ifneq ($(KERNELRELEASE),)
obj-m += i2c-dri-2991.o
obj-m += i2c-dev-2991.o
#ARCH := x86_64
else
KERN_DIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
#module:
$(MAKE) CROSS_COMPILE= -C $(KERN_DIR) M=$(PWD) modules
#clean:
# $(MAKE) -C $(KERN_DIR) M=$(PWD) modules clean
#modules_install:
# $(MAKE) -C $(KERN_DIR) M=$(PWD) modules_install
endif