[feat] add usb_detect driver

This commit is contained in:
zhji 2026-03-15 21:11:47 +08:00
parent 17e5e4107a
commit 0406680173
2 changed files with 46 additions and 0 deletions

12
usb/usb_detect/Makefile Normal file
View File

@ -0,0 +1,12 @@
ARCH ?= arm
CROSS_COMPILE ?= /home/jzh/work/study/weidongshan/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin/arm-linux-
KERN_DIR ?= /home/jzh/work/study/weidongshan/100ask_stm32mp157_pro-sdk/Linux-5.4
all:
make -C $(KERN_DIR) M=`pwd` ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
make -C $(KERN_DIR) M=`pwd` ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules clean
rm -rf modules.order
obj-m += usb_detect.o

View File

@ -0,0 +1,34 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/can/dev.h>
static struct usb_device_id usb_detect_id_table[] = {
{ USB_DEVICE_AND_INTERFACE_INFO(0xffff, 0xffff, 0xff, 0xff, 0x02), .driver_info = 1 }, // ctrl
{ USB_DEVICE_AND_INTERFACE_INFO(0xffff, 0xffff, 0xff, 0xff, 0x0a), .driver_info = 2 }, // data
{ }
};
static int usb_detect_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
printk("%s %s %d\r\n", __FILE__, __FUNCTION__, __LINE__);
printk("USB device detected: vendor=0x%04X, product=0x%04X, info=%ld\r\n",
id->idVendor, id->idProduct, id->driver_info);
return 0;
}
static void usb_detect_disconnect(struct usb_interface *intf)
{
printk("%s %s %d\r\n", __FILE__, __FUNCTION__, __LINE__);
printk("USB device disconnected\r\n");
}
static struct usb_driver usb_detect_driver = {
.name = "usb_detect_driver",
.probe = usb_detect_probe,
.disconnect = usb_detect_disconnect,
.id_table = usb_detect_id_table,
};
module_usb_driver(usb_detect_driver);
MODULE_LICENSE("GPL");