[feat] add usb_detect driver
This commit is contained in:
parent
17e5e4107a
commit
0406680173
12
usb/usb_detect/Makefile
Normal file
12
usb/usb_detect/Makefile
Normal 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
|
||||
34
usb/usb_detect/usb_detect.c
Normal file
34
usb/usb_detect/usb_detect.c
Normal 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");
|
||||
Loading…
Reference in New Issue
Block a user