[Add] 新增I2C驱动目录
This commit is contained in:
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,14 +1,17 @@
|
|||||||
|
# Files
|
||||||
*.o
|
*.o
|
||||||
*.mod
|
*.ko
|
||||||
|
|
||||||
*.cmd
|
*.cmd
|
||||||
|
*.mod
|
||||||
|
*.mod.c
|
||||||
|
*.mod.o
|
||||||
|
|
||||||
Module.symvers
|
Module.symvers
|
||||||
modules.order
|
modules.order
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|
||||||
|
# Directories
|
||||||
.cache/
|
.cache/
|
||||||
|
|
||||||
output/
|
output/
|
||||||
_install/
|
_install/
|
||||||
|
.tmp_versions/
|
||||||
|
|||||||
54
02-I2C/Makefile
Normal file
54
02-I2C/Makefile
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# All Right Reserved.
|
||||||
|
# Author : gaoyang3513@outlook.com
|
||||||
|
# Version : V1.0.0 202x.01.01
|
||||||
|
# Description :
|
||||||
|
# Note :
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Path information
|
||||||
|
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
# Subdirectory
|
||||||
|
|
||||||
|
# Output directories
|
||||||
|
OUTPUT_DIR ?= $(LOCAL_DIR)/output
|
||||||
|
INSTALL_DIR ?= $(LOCAL_DIR)/_install
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Variables
|
||||||
|
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Compile configure
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Source and oject files
|
||||||
|
ifneq ($(KERNELRELEASE),)
|
||||||
|
|
||||||
|
obj-m := i2c_static.o
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Targets
|
||||||
|
else # KERNELRELEASE
|
||||||
|
|
||||||
|
ifneq ($(filter $(BOARD),mikv-Duo),)
|
||||||
|
KERNELDIR := ${HOME}/Source/10-CV1800/01-MilkDuo/02-Project/SDK_CV1800_BR2/linux_5.10/build/cv1800b_milkv_duo_sd
|
||||||
|
ROOTFS := ${HOME}/nfs/rootfs
|
||||||
|
else
|
||||||
|
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: all clean init
|
||||||
|
|
||||||
|
all:
|
||||||
|
@$(MAKE) -C $(KERNELDIR) M=$(LOCAL_DIR) modules -j$(MULTI_CORES);
|
||||||
|
|
||||||
|
install:
|
||||||
|
@$(MAKE) -C $(KERNELDIR) M=$(LOCAL_DIR) modules_install INSTALL_MOD_PATH=$(INSTALL_DIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf *.o *.ko .*.cmd *.mod* modules.order Module.symvers .tmp_versions
|
||||||
|
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
|
||||||
|
@if [ -d $(LOCAL_DIR)/_install ]; then rm -rf $(LOCAL_DIR)/_install; fi;
|
||||||
|
|
||||||
|
endif # KERNELRELEASE
|
||||||
28
02-I2C/ReadMe.md
Normal file
28
02-I2C/ReadMe.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
|
||||||
|
## 调试命令
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# ~/.bash_aliases
|
||||||
|
# alias source_env_MilkV-Duo='export BOARD=mikv-Duo; export ARCH=riscv; export CROSS_COMPILE=riscv64-unknown-linux-gnu-'
|
||||||
|
|
||||||
|
source_env_MilkV-Duo
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
scp gaoyang3513@192.168.3.120:Source/12-Demo/Linux_Drivers/02-I2C/i2c_static.ko ./
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# cat /proc/devices
|
||||||
|
Character devices:
|
||||||
|
...
|
||||||
|
256 GBox
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mknod -m 0755 /dev/GBox c 256 0
|
||||||
|
```
|
||||||
|
|
||||||
39
02-I2C/i2c_static.c
Executable file
39
02-I2C/i2c_static.c
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#include <linux/init.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/module.h>
|
||||||
|
|
||||||
|
#include <linux/fs.h>
|
||||||
|
|
||||||
|
#define VSER_MAJOR 256
|
||||||
|
#define VSER_MINOR 0
|
||||||
|
#define VSER_DEV_CNT 1
|
||||||
|
#define VSER_DEV_NAME "GBox"
|
||||||
|
|
||||||
|
static int __init vser_init(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
dev_t dev;
|
||||||
|
|
||||||
|
dev = MKDEV(VSER_MAJOR, VSER_MINOR);
|
||||||
|
ret = register_chrdev_region(dev, VSER_DEV_CNT, VSER_DEV_NAME);
|
||||||
|
if (ret)
|
||||||
|
goto reg_err;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
reg_err:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit vser_exit(void)
|
||||||
|
{
|
||||||
|
dev_t dev;
|
||||||
|
|
||||||
|
dev = MKDEV(VSER_MAJOR, VSER_MINOR);
|
||||||
|
unregister_chrdev_region(dev, VSER_DEV_CNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init(vser_init);
|
||||||
|
module_exit(vser_exit);
|
||||||
|
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
|
MODULE_AUTHOR("gaoyang3513 <gaoyang3513@163.com>");
|
||||||
3
Makefile
3
Makefile
@ -19,7 +19,8 @@ INSTALL_DIR ?= $(LOCAL_DIR)/_install
|
|||||||
# Variables
|
# Variables
|
||||||
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
||||||
|
|
||||||
SUB_DIRS := 01-Char/
|
SUB_DIRS := 01-Char/ \
|
||||||
|
02-I2C/
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Compile configure
|
# Compile configure
|
||||||
|
|||||||
Reference in New Issue
Block a user