用的是S5PV210的SOC
1.设备树支持设备树
设备树默认是支持USB驱动的。
如下:
usbphy: usbphy@ec100000 {
compatible = "samsung,s5pv210-usb2-phy";
reg = <0xec100000 0x100>;
samsung,pmureg-phandle = <&pmu_syscon>;
clocks = <&clocks CLK_USB_OTG>, <&xusbxti>;
clock-names = "phy", "ref";
#phy-cells = <1>;
status = "disabled";
};
ehci: ehci@ec200000 {
compatible = "samsung,exynos4210-ehci";
reg = <0xec200000 0x100>;
interrupts = <23>;
interrupt-parent = <&vic1>;
clocks = <&clocks CLK_USB_HOST>;
clock-names = "usbhost";
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
port@0 {
reg = <0>;
phys = <&usbphy 1>;
};
};
ohci: ohci@ec300000 {
compatible = "samsung,exynos4210-ohci";
reg = <0xec300000 0x100>;
interrupts = <23>;
interrupt-parent = <&vic1>;
clocks = <&clocks CLK_USB_HOST>;
clock-names = "usbhost";
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
port@0 {
reg = <0>;
phys = <&usbphy 1>;
};
};
当然,默认是disbale的。我们只需要把状态改为ok,就可以使用了。
&usbphy {
status = "okay";
};
&ohci {
status = "okay";
};
&ehci {
status = "okay";
};
配置内核支持usb驱动
Device Drivers --->
[*] USB support --->
<*> Support for Host-side USB
<*> EHCI HCD (USB 2.0) support
[*] Improved Transaction Translator scheduling
<*> EHCI support for Samsung S5P/EXYNOS SoC Series
<*> OHCI HCD (USB 1.1) support
<*> OHCI support for Samsung S5P/EXYNOS SoC Series
配置支持2.0和1.1和USB驱动
我这边是一个USB鼠标,可以看一下。接上后的打印信息。
USB其实也也是支持多打印一些调试信息的。
Device Drivers --->
[*] USB support --->
<*> Support for Host-side USB
[*] USB announce new devices
<*> EHCI HCD (USB 2.0) support
[*] Improved Transaction Translator scheduling
<*> EHCI support for Samsung S5P/EXYNOS SoC Series
<*> OHCI HCD (USB 1.1) support
<*> OHCI support for Samsung S5P/EXYNOS SoC Series
要选上这条信息
[*] USB announce new devices
可以看到,选上之后,接上设备后,就会打印出设备的VID,PID,usb版本。字符串信息,产品信息等。
这里在上一节的基础上,继续加一点,在程序中打印出VID,PID,版本。
在这之前,要先去掉内核自带的usb的hid驱动。
Device Drivers --->
HID support --->
<*> HID bus support
<*> Generic HID driver //去掉这个
USB HID support --->
<*> USB HID transport layer //去掉这个
[*] USB support --->
<*> Support for Host-side USB
[*] USB announce new devices
<*> EHCI HCD (USB 2.0) support
[*] Improved Transaction Translator scheduling
<*> EHCI support for Samsung S5P/EXYNOS SoC Series
<*> OHCI HCD (USB 1.1) support
<*> OHCI support for Samsung S5P/EXYNOS SoC Series
因为如果不去掉,会默认把内核自带的鼠标驱动匹配上。
去掉后,才能匹配我们自己写的驱动。
#include
#include
#include
#include
#include
#include
static int usb_simple_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev(intf);
printk(KERN_INFO"usb_simple_probe\n");
printk(KERN_INFO"bcdUSB = 0x%x\n",dev->descriptor.bcdUSB);
printk(KERN_INFO"VID = 0x%x\n",dev->descriptor.idVendor);
printk(KERN_INFO"PID = 0x%x\n",dev->descriptor.idProduct);
return 0;
}
static void usb_simple_disconnect(struct usb_interface *intf)
{
printk(KERN_INFO"usb_mouse_disconnect\n");
}
tatic const struct usb_device_id usb_simple_id_table[] = {
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_MOUSE) },
{} /* Terminating entry */
};
static struct usb_driver usb_simple_driver = {
.name = "usb_simple",
.probe = usb_simple_probe,
.disconnect = usb_simple_disconnect,
.id_table = usb_simple_id_table,
};
module_usb_driver(usb_simple_driver);
MODULE_LICENSE("GPL");
这里可以看到,内核自己打印的版本是1.00版本,而我们打印的是1.10版本。这个可能是一个内核在usb或者打印这里的一个小bug。