[Add] 新增CMT2301 驱动模板
This commit is contained in:
70
spi/01-NFC_PN5180/Makefile
Normal file
70
spi/01-NFC_PN5180/Makefile
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# All Right Reserved.
|
||||||
|
# Author :
|
||||||
|
# Version : V1.0.0 202x.01.01
|
||||||
|
# Description :
|
||||||
|
# Note : gaoyang3513@163.com Modified 202x.01.01
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Path information
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Top directories
|
||||||
|
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
|
KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../../../linux_5.10/build/kernel_output)
|
||||||
|
|
||||||
|
# Subdirectories
|
||||||
|
|
||||||
|
# Output directories
|
||||||
|
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
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
export ARCH ?= riscv
|
||||||
|
export CROSS_COMPILE ?= riscv64-unknown-linux-musl-
|
||||||
|
|
||||||
|
CC := $(CROSS_COMPILE)gcc
|
||||||
|
LD := $(CROSS_COMPILE)ld
|
||||||
|
AR := $(CROSS_COMPILE)ar
|
||||||
|
STRIP := $(CROSS_COMPILE)strip
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Targets
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
ifneq ($(KERNELRELEASE),)
|
||||||
|
# called from kernel build system: just declare what our modules are
|
||||||
|
obj-m += pn5180.o
|
||||||
|
|
||||||
|
else
|
||||||
|
.PHONY: init all clean distclean install menuconfig
|
||||||
|
|
||||||
|
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:
|
||||||
|
# File
|
||||||
|
@for n in *.o *.ko *.mod.c *.mod *.cmd *.symvers *.order; do \
|
||||||
|
find $(LOCAL_DIR) -type f -name $$n -exec rm {} \;;\
|
||||||
|
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;
|
||||||
|
@if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi;
|
||||||
|
|
||||||
|
install:
|
||||||
|
@mkdir -p $(INSTALL_DIR)
|
||||||
|
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR)
|
||||||
|
|
||||||
|
init:
|
||||||
|
@mkdir -p $(OUTPUT_DIR);
|
||||||
|
endif # ifeq ($(KERNELRELEASE),)
|
||||||
70
spi/02-Sub1G_CMT2301/Makefile
Normal file
70
spi/02-Sub1G_CMT2301/Makefile
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# All Right Reserved.
|
||||||
|
# Author :
|
||||||
|
# Version : V1.0.0 202x.01.01
|
||||||
|
# Description :
|
||||||
|
# Note : gaoyang3513@163.com Modified 202x.01.01
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Path information
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Top directories
|
||||||
|
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
|
KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../../../linux_5.10/build/kernel_output)
|
||||||
|
|
||||||
|
# Subdirectories
|
||||||
|
|
||||||
|
# Output directories
|
||||||
|
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
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
export ARCH ?= riscv
|
||||||
|
export CROSS_COMPILE ?= riscv64-unknown-linux-musl-
|
||||||
|
|
||||||
|
CC := $(CROSS_COMPILE)gcc
|
||||||
|
LD := $(CROSS_COMPILE)ld
|
||||||
|
AR := $(CROSS_COMPILE)ar
|
||||||
|
STRIP := $(CROSS_COMPILE)strip
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
# Targets
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
ifneq ($(KERNELRELEASE),)
|
||||||
|
# called from kernel build system: just declare what our modules are
|
||||||
|
obj-m += cmt2301.o
|
||||||
|
|
||||||
|
else
|
||||||
|
.PHONY: init all clean distclean install menuconfig
|
||||||
|
|
||||||
|
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:
|
||||||
|
# File
|
||||||
|
@for n in *.o *.ko *.mod.c *.mod *.cmd *.symvers *.order; do \
|
||||||
|
find $(LOCAL_DIR) -type f -name $$n -exec rm {} \;;\
|
||||||
|
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;
|
||||||
|
@if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi;
|
||||||
|
|
||||||
|
install:
|
||||||
|
@mkdir -p $(INSTALL_DIR)
|
||||||
|
@cp -arf $(OUTPUT_DIR)/. $(INSTALL_DIR)
|
||||||
|
|
||||||
|
init:
|
||||||
|
@mkdir -p $(OUTPUT_DIR);
|
||||||
|
endif # ifeq ($(KERNELRELEASE),)
|
||||||
75
spi/02-Sub1G_CMT2301/cmt2301.c
Normal file
75
spi/02-Sub1G_CMT2301/cmt2301.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_OF
|
||||||
|
static const struct of_device_id CHIP_of_match[] = {
|
||||||
|
{ .compatible = "nxp,pn5180", },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
|
MODULE_DEVICE_TABLE(of, CHIP_of_match); // Used by file2alias, which indicated what devices are support with this drive.
|
||||||
|
#endif // CONFIG_OF
|
||||||
|
|
||||||
|
static struct spi_driver CHIP_driver = {
|
||||||
|
.driver = {
|
||||||
|
.name = "CHIP",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
#ifdef CONFIG_OF
|
||||||
|
.of_match_table = CHIP_of_match,
|
||||||
|
#endif // CONFIG_OF
|
||||||
|
},
|
||||||
|
.probe = CHIP_probe,
|
||||||
|
.remove = CHIP_remove,
|
||||||
|
};
|
||||||
|
|
||||||
|
module_spi_driver(CHIP_driver);
|
||||||
|
|
||||||
|
MODULE_AUTHOR("Gao yang <gaoyang3513@163.com>");
|
||||||
|
MODULE_DESCRIPTION("NXP PN5180 NFC driver");
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
52
spi/Makefile
52
spi/Makefile
@ -1,21 +1,20 @@
|
|||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
# All Right Reserved.
|
# All Right Reserved.
|
||||||
# Author :
|
# Author :
|
||||||
# Version : V1.0.0 202x.01.01
|
# Version : V1.0.0 202x.01.01
|
||||||
# Description :
|
# Description :
|
||||||
# Note : gaoyang3513@163.com Modified 202x.01.01
|
# Note : gaoyang3513@163.com Modified 202x.01.01
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
|
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
# Path information
|
# Path information
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
# Top directories
|
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
|
||||||
KERNEL_DIR ?= $(realpath $(LOCAL_DIR)/../../../../linux_5.10/build/kernel_output)
|
|
||||||
|
|
||||||
# Subdirectories
|
# Subdirectory
|
||||||
|
PN5180_DIR := 01-NFC_PN5180
|
||||||
|
CMT2301_DIR := 02-Sub1G_CMT2301
|
||||||
|
|
||||||
# Output directories
|
|
||||||
OUTPUT_DIR := $(LOCAL_DIR)/output
|
OUTPUT_DIR := $(LOCAL_DIR)/output
|
||||||
INSTALL_DIR ?= $(LOCAL_DIR)/__install
|
INSTALL_DIR ?= $(LOCAL_DIR)/__install
|
||||||
#$(info Output directoty : $(OUTPUT_DIR))
|
#$(info Output directoty : $(OUTPUT_DIR))
|
||||||
@ -26,40 +25,47 @@ INSTALL_DIR ?= $(LOCAL_DIR)/__install
|
|||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
||||||
|
|
||||||
|
SUB_DIRS := $(CMT2301_DIR) $(PN5180_DIR)
|
||||||
|
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
# Compile configure
|
# Compile configure
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
export ARCH ?= riscv
|
ARCH ?= riscv
|
||||||
export CROSS_COMPILE ?= riscv64-unknown-linux-musl-
|
CROSS_COMPILE ?= riscv64-unknown-linux-musl-
|
||||||
|
|
||||||
CC := $(CROSS_COMPILE)gcc
|
CC := $(CROSS_COMPILE)gcc
|
||||||
LD := $(CROSS_COMPILE)ld
|
LD := $(CROSS_COMPILE)ld
|
||||||
AR := $(CROSS_COMPILE)ar
|
AR := $(CROSS_COMPILE)ar
|
||||||
STRIP := $(CROSS_COMPILE)strip
|
STRIP := $(CROSS_COMPILE)strip
|
||||||
|
|
||||||
|
export ARCH CROSS_COMPILE
|
||||||
|
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
# Targets
|
# Targets
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
ifneq ($(KERNELRELEASE),)
|
ifneq ($(KERNELRELEASE),)
|
||||||
# called from kernel build system: just declare what our modules are
|
# called from kernel build system: just declare what our modules are
|
||||||
obj-m += pn5180.o
|
obj-y += $(SUB_DIRS)
|
||||||
|
|
||||||
else
|
#INC_DIRS := $(INCLUDE_DIR)/generated
|
||||||
|
#subdir-ccflags-y += $(addprefix -I, $(INC_DIRS))
|
||||||
|
|
||||||
|
else # !KERNELRELEASE
|
||||||
.PHONY: init all clean distclean install menuconfig
|
.PHONY: init all clean distclean install menuconfig
|
||||||
|
|
||||||
all: init
|
all: init
|
||||||
@$(MAKE) modules -C $(KERNEL_DIR) M=$(LOCAL_DIR) -j$(MULTI_CORES)
|
@for sub in $(SUB_DIRS); do \
|
||||||
@$(MAKE) modules_install -C $(KERNEL_DIR) M=$(LOCAL_DIR) INSTALL_MOD_PATH=$(KERNEL_DIR)/_install_modules INSTALL_MOD_DIR=private
|
$(MAKE) -C $$sub; \
|
||||||
|
$(MAKE) install INSTALL_DIR=$(OUTPUT_DIR) -C $$sub || exit "$$?"; \
|
||||||
|
done;
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
# File
|
@for sub in $(SUB_DIRS); do \
|
||||||
@for n in *.o *.ko *.mod.c *.mod *.cmd *.symvers *.order; do \
|
$(MAKE) clean -C $$sub || exit "$$?"; \
|
||||||
find $(LOCAL_DIR) -type f -name $$n -exec rm {} \;;\
|
done;
|
||||||
done
|
|
||||||
# Directory
|
# Directory
|
||||||
@if [ -d $(LOCAL_DIR)/output ]; then rm -rf $(LOCAL_DIR)/output; fi;
|
@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)/__install ]; then rm -rf $(LOCAL_DIR)/__install; fi;
|
||||||
@if [ -d $(LOCAL_DIR)/.tmp_versions ]; then rm -rf $(LOCAL_DIR)/.tmp_versions; fi;
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@mkdir -p $(INSTALL_DIR)
|
@mkdir -p $(INSTALL_DIR)
|
||||||
@ -67,4 +73,4 @@ install:
|
|||||||
|
|
||||||
init:
|
init:
|
||||||
@mkdir -p $(OUTPUT_DIR);
|
@mkdir -p $(OUTPUT_DIR);
|
||||||
endif # ifeq ($(KERNELRELEASE),)
|
endif # !KERNELRELEASE
|
||||||
|
|||||||
Reference in New Issue
Block a user