Compare commits

...

4 Commits

Author SHA1 Message Date
ad4c4c383f [Add] 属性修改:文件忽略、编码格式 2024-07-02 17:16:02 +08:00
1dd7a8d2fb [Mod] 文档更新 2024-07-02 17:15:31 +08:00
672e90c932 [Mod] SPI驱动模板 2024-07-02 17:15:14 +08:00
f8af42c7a1 [Add] 支持模块编译 Duo S环境 2024-07-02 17:13:36 +08:00
6 changed files with 246 additions and 15 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[c]
indent_style = tab
indent_size = 8
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
*.o
*.o.d
*.ko
*.mod
*.mod.c
.*.o.cmd
.*.ko.cmd
.*.mod.cmd
.*.mod.o.cmd
.modules.order.cmd
.Module.symvers.cmd
Module.symvers
modules.order
output/

75
Makefile Normal file
View File

@ -0,0 +1,75 @@
#*******************************************************************************
# HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
# Author :
# Version : V1.0.0 202x.01.01
# Description :
# Note : gaoyang@.com.cn Modified 2020.10.21
#*******************************************************************************
#*******************************************************************************
# Path information
#*******************************************************************************
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../linux_5.10)
# Subdirectory
OUTPUT_DIR := $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/__install
#$(info Output directoty : $(OUTPUT_DIR))
#$(info Install directoty: $(INSTALL_DIR))
#*******************************************************************************
# Variables
#*******************************************************************************
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
SUB_DIRS := spi/
#*******************************************************************************
# Compile configure
#*******************************************************************************
ARCH ?= riscv
CROSS_COMPILE ?= riscv64-unknown-linux-musl-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
export ARCH CROSS_COMPILE
#*******************************************************************************
# Targets
#*******************************************************************************
.PHONY: init all clean distclean install menuconfig
ifeq ($(KERNELRELEASE),)
all: init
@for sub in $(SUB_DIRS); do \
$(MAKE) -C $$sub; \
$(MAKE) install INSTALL_DIR=$(OUTPUT_DIR) -C $$sub || exit "$$?"; \
done;
clean:
@for sub in $(SUB_DIRS); do \
$(MAKE) clean -C $$sub || exit "$$?"; \
done;
# Directory
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
@if [ -d $(LOCAL_DIR)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi;
install:
@mkdir -p $(INSTALL_DIR)
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR)
init:
@mkdir -p $(OUTPUT_DIR);
else
# called from kernel build system: just declare what our modules are
obj-y += $(SUB_DIRS)
#INC_DIRS := $(INCLUDE_DIR)/generated
#subdir-ccflags-y += $(addprefix -I, $(INC_DIRS))
endif # ifeq ($(KERNELRELEASE),)

69
spi/Makefile Normal file
View File

@ -0,0 +1,69 @@
#*******************************************************************************
# HangZhou Hikvision Digital Technology Co., Ltd. All Right Reserved.
# Author :
# Version : V1.0.0 202x.01.01
# Description :
# Note : gaoyang3513@163.com Modified 2020.10.21
#*******************************************************************************
#*******************************************************************************
# Path information
#*******************************************************************************
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../../linux_5.10)
# Subdirectory
OUTPUT_DIR := $(LOCAL_DIR)/output
INSTALL_DIR ?= $(LOCAL_DIR)/__install
#$(info Output directoty : $(OUTPUT_DIR))
#$(info Install directoty: $(INSTALL_DIR))
#*******************************************************************************
# Variables
#*******************************************************************************
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
# Compile configure
#*******************************************************************************
ARCH ?= riscv
CROSS_COMPILE ?= riscv64-unknown-linux-musl-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
STRIP := $(CROSS_COMPILE)strip
export ARCH CROSS_COMPILE
#*******************************************************************************
# Targets
#*******************************************************************************
.PHONY: init all clean distclean install menuconfig
ifeq ($(KERNELRELEASE),)
all: init
@$(MAKE) modules -C $(KERNEL_DIR) M=$(LOCAL_DIR) -j$(MULTI_CORES)
@$(MAKE) modules_install -C $(KERNEL_DIR) M=$(LOCAL_DIR) INSTALL_MOD_PATH=$(KERNEL_DIR)/_install_modules INSTALL_MOD_DIR=private
clean:
# Directory
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
@if [ -d $(LOCAL_DIR)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi;
@if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi;
# File
@for f in {Module.symvers,modules.order}; do \
if [ -e $$f ]; then rm -rf $$f; fi; \
done
install:
@mkdir -p $(INSTALL_DIR)
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR)
init:
@mkdir -p $(OUTPUT_DIR);
else
# called from kernel build system: just declare what our modules are
obj-m += pn5180.o
endif # ifeq ($(KERNELRELEASE),)

View File

@ -159,24 +159,9 @@ SPI设备必须管理以下两种类型内存
...
- `master->transfer_one_message(struct spi_master *master, struct spi_message *mesg)`, 发送一个mesg
### SPI Protocol Driver
```c
static struct spi_driver CHIP_driver = {
.driver = {
.name = "CHIP",
.owner = THIS_MODULE,
.pm = &CHIP_pm_ops,
},
.probe = CHIP_probe,
.remove = CHIP_remove,
};
static int CHIP_probe(struct spi_device *spi)
{
struct CHIP *chip;
@ -196,6 +181,17 @@ SPI设备必须管理以下两种类型内存
... etc
return 0;
}
static struct spi_driver CHIP_driver = {
.driver = {
.name = "CHIP",
.owner = THIS_MODULE,
.pm = &CHIP_pm_ops,
},
.probe = CHIP_probe,
.remove = CHIP_remove,
};
```
spi_setup(),
## 属性

60
spi/pn5180.c Normal file
View File

@ -0,0 +1,60 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
#define IS_USE_STATIC_PLATFORM_DATA 0
struct CHIP {
struct spi_device *spi;
};
#if IS_USE_STATIC_PLATFORM_DATA
struct CHIP_platform_data {
int spi_ch;
};
#endif // IS_USE_STATIC_PLATFORM_DATA
static int CHIP_probe(struct spi_device *spi)
{
struct CHIP *chip;
#if IS_USE_STATIC_PLATFORM_DATA
struct CHIP_platform_data *pdata;
/* assuming the driver requires board-specific data: */
pdata = (struct CHIP_platform_data *)&spi->dev.platform_data;
if (!pdata)
return -ENODEV;
#endif // IS_USE_STATIC_PLATFORM_DATA
/* get memory for driver's per-chip state */
chip = kzalloc(sizeof *chip, GFP_KERNEL);
if (!chip)
return -ENOMEM;
spi_set_drvdata(spi, chip);
return 0;
}
int CHIP_remove(struct spi_device *spi)
{
struct CHIP *chip = NULL;
chip = (struct CHIP *)spi_get_drvdata(spi);
kfree(chip);
return 0;
}
static struct spi_driver CHIP_driver = {
.driver = {
.name = "CHIP",
.owner = THIS_MODULE,
},
.probe = CHIP_probe,
.remove = CHIP_remove,
};
module_spi_driver(CHIP_driver);