{"id":46,"date":"2026-03-31T19:27:14","date_gmt":"2026-03-31T11:27:14","guid":{"rendered":"https:\/\/monykate.com\/?p=46"},"modified":"2026-03-31T19:27:14","modified_gmt":"2026-03-31T11:27:14","slug":"linux%e5%86%85%e6%a0%b8%e4%b8%adusb%e5%ad%90%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/monykate.com\/index.php\/2026\/03\/31\/linux%e5%86%85%e6%a0%b8%e4%b8%adusb%e5%ad%90%e7%b3%bb%e7%bb%9f\/","title":{"rendered":"Linux\u5185\u6838\u4e2dUSB\u5b50\u7cfb\u7edf"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u68b3\u7406Linux\u7cfb\u7edf\u4e0bUSB\u5b50\u7cfb\u7edf\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0cUSB\u603b\u7ebf\u6ce8\u518c\u3001HCD\u6ce8\u518c\u4e24\u4e2a\u5207\u5165\u70b9\uff0c\u5185\u5bb9\u6839\u636e\u5b98\u65b9\u8d44\u6599\u3001\u5185\u6838\u6e90\u7801\u53ca\u4e2a\u4eba\u7406\u89e3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u3001USB&nbsp;\u603b\u7ebf\u6ce8\u518c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u731c\u6d4b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SoC\u4f5c\u4e3ahost\uff0c\u5e94\u8be5\u8981\u521b\u5efa\u4e00\u6761USB\u603b\u7ebf\uff0c\u642d\u5efa\u4e00\u4e2aUSB\u7cfb\u7edf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SoC\u4f5c\u4e3ahost\uff0c\u5e94\u8be5\u80fd\u591f\u7ba1\u7406USB\u8bbe\u5907\uff0c\u5305\u62ec\u8bbe\u5907\u7684\u63a5\u5165\u548c\u79fb\u9664\u7b49<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u9a8c\u8bc1\u731c\u6d4b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u5206\u6790\u5185\u6838\u6e90\u7801\uff0c\u5f53\u5185\u6838\u542f\u52a8\u540e\uff0c\u4f1a\u8c03\u7528subsys_initcall()\uff0c\u6267\u884c\u5230usb_init(void)\uff0cusb_init\u51fd\u6570\u5728\u5b9a\u4e49\u65f6\u7528\u4e86__init\u4fee\u9970\uff0c\u4e8e\u662f\u8fde\u63a5\u811a\u672c\u4f1a\u5c06\u8be5\u51fd\u6570\u653e\u5230_init\u6bb5\u4e2d\uff0c\u800csubsys_initcall\u4f1a\u4ece\u8be5\u6bb5\u4e2d\u6267\u884c\u521d\u59cb\u5316\u51fd\u6570\u3002\u7814\u7a76USB\u5230\u8fd9\u91cc\u5373\u53ef\uff0c\u5177\u4f53\u5185\u6838\u5982\u4f55\u8c03\u7528\uff0c\u5e94\u8be5\u5355\u72ec\u653e\u5230\u5185\u6838\u7bc7\u4e2d\uff0c\u8fd9\u91cc\u5c31\u4e0d\u6df1\u7a76\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u4e48usb_init(void)\u505a\u4e86\u54ea\u4e9b\u4e8b\u60c5\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u6ce8\u518c\u4e00\u6761\u603b\u7ebf\u7c7b\u578b\uff1abus_register(&amp;usb_bus_type)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u603b\u7ebf\u7c7b\u578b\u5305\u542b\u6709\u4e24\u4e2a\u94fe\u8868\uff0c\u4e00\u4e2a\u662fdevice\u94fe\u8868\uff0c\u4e00\u4e2a\u662fdriver\u94fe\u8868\uff0c\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2amatch\u51fd\u6570\uff0c\u4f5c\u7528\u662f\u5f53\u65b0\u8bbe\u5907\u63d2\u5165\u65f6\u4e3a\u8be5\u65b0\u8bbe\u5907\u5339\u914d\u9a71\u52a8\uff0c\u5f53\u6709\u65b0\u9a71\u52a8\u65f6\u4e3a\u65b0\u9a71\u52a8\u5339\u914d\u8bbe\u5907<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">usb_bus_type\u5b9a\u4e49<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">struct&nbsp;bus_type&nbsp;usb_bus_type&nbsp;=&nbsp;{<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.name&nbsp;=&nbsp;&#8220;usb&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.match&nbsp;=&nbsp;usb_device_match,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.uevent&nbsp;=&nbsp;usb_uevent,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.need_parent_lock&nbsp;=&nbsp;true,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">};<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e3aUSB\u603b\u7ebf\u6ce8\u518c\u4e00\u4e2a\u5185\u6838\u901a\u77e5\u94fe<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53USB\u603b\u7ebf\u4e0a\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5c31\u4f1a\u6267\u884c\u901a\u77e5\u94fe\u4e2d\u7684\u51fd\u6570\uff0c\u5177\u4f53\u600e\u4e48\u5b9e\u73b0\u4e0d\u9700\u8981\u5173\u5fc3\uff0c\u7531\u5185\u6838\u63a7\u5236\uff1bbus_register_notifier(&amp;usb_bus_type,&nbsp;&amp;usb_bus_nb)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u7533\u8bf7\u4e00\u4e2aUSB\u8bbe\u5907\u53f7\uff0c\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\uff1a usb_major_init()-&gt;register_chrdev(USB_MAJOR,&nbsp;&#8220;usb&#8221;,&nbsp;&amp;usb_fops)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u524d\u9762\u7684\u64cd\u4f5c\u90fd\u662f\u9488\u5bf9USB\u603b\u7ebf\u7684\uff0c\u800c\u8fd9\u91cc\u7684\u8bbe\u5907\u53f7\u662f\u7ed9host\u8bbe\u5907\u81ea\u8eab\u7684\u6ce8\u518c\u7684\u662f\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\uff0c\u5e26\u7684\u53c2\u6570usb_fops\u662f\u5b57\u7b26\u8bbe\u5907\u7684\u64cd\u4f5c\u51fd\u6570\u96c6\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\uff08host\uff09\u9a71\u52a8usb_register(&amp;usbfs_driver)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4.\u521b\u5efa\u4e00\u4e2a\u865a\u62dfhub\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">usb_hub_init();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\uff08hub\uff09\u9a71\u52a8\uff1ausb_register(&amp;hub_driver),\u542f\u52a8hub\u76d1\u6d4b\u7684\u5de5\u4f5c\u961f\u5217workqueue\uff1a alloc_workqueue(&#8220;usb_hub_wq&#8221;,&nbsp;WQ_FREEZABLE,&nbsp;0);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5.\u4e3a\u603b\u7ebf\u7c7b\u578b\u6ce8\u518c\u4e00\u4e2a\u901a\u7528USB\u8bbe\u5907\uff08device\uff09\u9a71\u52a8\uff1a usb_register_device_driver(&amp;usb_generic_driver,&nbsp;THIS_MODULE);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5411\u5185\u548c\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\uff08device\uff09\u9a71\u52a8\uff1adriver_register()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5c0f\u7ed3\u4e00\u4e0b<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u518c\u4e00\u6761<strong>\u603b\u7ebf<\/strong><strong>\u7c7b\u578b<\/strong>\uff0c\u5e76\u4e3a\u603b\u7ebf\u6ce8\u518c\u5185\u6838\u901a\u77e5\u94fe<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u518c\u4e00\u4e2a\u5b57\u7b26<strong>host\u8bbe\u5907<\/strong>\uff0c\u9a71\u52a8\u4e3ausbfs_driver\uff0c\u53ef\u4ee5\u5ffd\u7565<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u518c\u4e00\u4e2a\u865a\u62df<strong>hub\u8bbe\u5907<\/strong>\uff0c\u9a71\u52a8\u4e3ahub_driver<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u603b\u7ebf\u6ce8\u518c\u4e00\u4e2a\u901a\u7528<strong>usb\u9a71\u52a8<\/strong>\uff0cusb_generic_driver<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8c\u3001HCD\u521d\u59cb\u5316<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u7591\u60d1\u548c\u7b54\u6848<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u70b9USB\u7684\u521d\u59cb\u5316\u4e2d\uff0c\u5e94\u8be5\u8bf4\u5927\u90e8\u5206\u7684\u5de5\u4f5c\uff0c\u8fd8\u662f\u7ed9\u5185\u6838\u7684\uff0c\u6bd4\u5982\u521b\u5efa\u603b\u7ebf\u7c7b\u578b\u3001\u901a\u77e5\u94fe\u3001\u5de5\u4f5c\u961f\u5217\u3001\u865a\u62dfhub\u7b49\u3002\u800cHCD\u7684\u5927\u90e8\u5206\u5de5\u4f5c\u662f\u7ed9\u4e3b\u673a\u63a7\u5236\u5668\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u4e2a\u524d\u63d0\uff0cHCD\u662f\u4ee5\u201c\u8bbe\u5907-\u603b\u7ebf\u5e73\u53f0-\u9a71\u52a8\u201d\u6a21\u578b\u5b58\u5728\u7684\uff0c\u4e8e\u662f\u5f15\u51fa\u4e09\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.platform_device\u8bbe\u5907\u4ece\u54ea\u91cc\u6765\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.platform_bus\u5e73\u53f0\u603b\u7ebf\u4ece\u54ea\u91cc\u6765\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u5982\u4f55\u5de5\u4f5c\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e8c\u4e2a\u95ee\u9898\u597d\u89e3\u7b54\uff0c\u5f53\u5185\u6838\u542f\u52a8\u65f6\uff0c\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2aplatform_bus\u3002\u7b2c\u4e00\u4e2a\u95ee\u9898\uff0c\u5185\u6838\u542f\u52a8\u540e\uff0c\u4f1a\u52a0\u8f7d\u8bbe\u5907\u6811\u6587\u4ef6\uff0c\u89e3\u6790\u5176\u4e2d\u7684\u8bbe\u5907\u6811\u8282\u70b9\uff0c\u5c06\u6ee1\u8db3\u5e73\u53f0\u8bbe\u5907\u8981\u6c42\u7684\u8bbe\u5907\u6811\u8282\u70b9\uff0c\u521b\u5efa\u6210\u5e73\u53f0\u8bbe\u5907platform_device\u3002\u6240\u4ee5\uff0c\u8981\u5de5\u4f5c\u8d77\u6765\uff0c\u9996\u5148\u9700\u8981\u5728\u8bbe\u5907\u6811\u4e2d\u5b9a\u4e49\u6ee1\u8db3\u5e73\u53f0\u8981\u6c42\u7684\u8282\u70b9\uff0c\u5305\u542bcompatible\u5c5e\u6027\u3001\u5b50\u8282\u70b9\u5305\u542bcompatible\u5c5e\u6027\u4e14\u503c\u4e3a&#8221;simple-bus&#8221;\uff0c&#8221;simple-mfd&#8221;,&#8221;isa&#8221;\uff0c&#8221;arm,amba-bus&#8221;\uff0c\u4f1a\u88ab\u8f6c\u6210platform_device\uff0c\u5f53\u89e3\u6790\u5b8c\u8bbe\u5907\u6811\u4e4b\u540e\uff0c\u5f97\u5230\u4e86platform_device\u5e76\u5411\u5185\u6838\u6ce8\u518c\uff0c\u5f53\u5185\u6838\u53d1\u73b0\u4e86\u8fd9\u4e2a\u5e73\u53f0\u8bbe\u5907\uff0c\u5c31\u4f1a\u53bb\u8c03\u7528\u603b\u7ebf\u94fe\u8868\u4e0a\u7684match\u51fd\u6570\uff0c\u6765\u67e5\u627e\u603b\u7ebf\u4e0a\u7684driver\u94fe\u8868\u4e3a\u8be5\u8bbe\u5907\u5339\u914d\u5bf9\u5e94\u7684platform_driver\uff0c\u5f53platform_driver\u548cplatform_device\u5339\u914d\u4e00\u81f4\uff0c\u5219\u6267\u884cplatform_driver\u91cc\u9762\u7684probe\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u63d0\u7b2c\u4e00\u4e2a\u95ee\u9898\uff1aplatform_bus\u4e0a\u7684driver\u600e\u4e48\u6765\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7f16\u5199\u5e73\u53f0\u9a71\u52a8\u7684\u65f6\u5019\uff0c\u9700\u8981\u7528module_init\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u6a21\u5757\u9a71\u52a8\uff0c\u8fd9\u65f6\u5019\u5185\u6838\u5c31\u5c06\u8fd9\u4e9b\u6a21\u5757\u9a71\u52a8\u653e\u5230\u4e00\u8d77\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u63d0\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a\u5185\u6838\u5982\u4f55platform_driver\u5bf9\u5e94\u5230\u8fd9\u4e2aplatform_device\uff1f\u6bcf\u4e00\u6761\u603b\u7ebf\u90fd\u6709\u4e00\u4e2amatch\u51fd\u6570\uff0c\u5728device\u4e2d\u6709compatible\u5c5e\u6027\u4fe1\u606f\u3001\u8bbe\u5907\u540d\u79f0\u3001ID\u4fe1\u606f\uff0c\u9a71\u52a8\u4e2d\u4e5f\u6709\u4e00\u4e2aofmatch_table\u8868\uff0c\u4e5f\u5305\u542b\u4e86\u5c5e\u6027\u3001\u540d\u79f0\u7b49\u4fe1\u606f\uff0c\u90a3match\u51fd\u6570\u4e00\u6bd4\u8f83\u5c31\u77e5\u9053\u4e86<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.HCD\u6ce8\u518c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5dwc2\u4e3a\u4f8b\uff0cplatform\u9a71\u52a8\u5b58\u653e\u5728driver\/usb\/dwc2\u76ee\u5f55\u4e0b\uff0c\u5165\u53e3\u5728platform.c\u4e2d\uff0cmodule_platform_driver(dwc2_platform_driver)\uff0c\u5176\u4e2ddwc2_platform_driver\u4e3adwc2\u6a21\u5757\u9a71\u52a8\u7684\u7ed3\u6784\u4f53\uff0c\u5f53\u5185\u6838\u89e3\u6790\u8bbe\u5907\u6811\u751f\u6210dwc2\u7684\u5e73\u53f0\u8bbe\u5907\u540e\uff0c\u5185\u6838\u6839\u636e\u8bbe\u5907of_match_table\u4fe1\u606f\u67e5\u627e\u5bf9\u5e94\u7684\u9a71\u52a8\uff0c\u5339\u914d\u6210\u529f\u627e\u5230\u9a71\u52a8\u540e\u8c03\u7528\u9a71\u52a8\u7684probe\u63a5\u53e3\uff1adwc2_driver_probe(struct&nbsp;platform_device&nbsp;*dev)\uff0c\u505a\u4ee5\u4e0b\u51e0\u4ef6\u4e8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1.\u5b9a\u4e49\u8bbe\u5907\u7ed3\u6784\u4f53\uff0c\u5e76\u7533\u8bf7\u5185\u5b58<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u83b7\u53d6IORESOURCE_MEM&nbsp;\u8d44\u6e90\uff0c\u5373\u786c\u4ef6\u6a21\u5757\u7684\u7269\u7406\u5730\u5740\uff0c\u901a\u8fc7ioremap\u5c06\u7269\u7406\u5730\u5740\u8f6c\u6362\u6210\u865a\u62df\u5730\u5740\uff1adevm_ioremap_resource;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u914d\u7f6e\u6a21\u5757\u5bc4\u5b58\u5668<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f8\u5173\u7684host\u914d\u7f6e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3.\u83b7\u53d6\u8bbe\u5907\u4e2d\u65ad\u53f7\uff0c\u5e76\u5411\u5185\u6838\u7533\u8bf7\u4e2d\u65ad\uff0c\u548c\u5904\u7406\u51fd\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4.\u5224\u65ad\u8bbe\u5907\u89d2\u8272<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89d2\u8272\u4e3ahost\u6a21\u5f0f\u5219\u6267\u884cdwc2_hcd_init\uff0c\u4e3aperipheral\u5219\u6267\u884cdwc2_gadget_init\uff0c\u4ec5\u5206\u6790host<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521b\u5efa\u4e00\u4e2aHCD<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">hcd&nbsp;=&nbsp;usb_create_hcd(&amp;dwc2_hc_driver,&nbsp;dev,&nbsp;name)\uff0c\u521b\u5efa\u4e00\u4e2a\u4e3b\u673a\u63a7\u5236\u5668hcd\u3002\u521b\u5efa\u4e3b\u673a\u63a7\u5236\u5668\uff0c\u7533\u8bf7\u5185\u5b58\uff0c\u4e3b\u673a\u63a7\u5236\u5668\u5bf9\u5e94\u6709\u4e00\u6761usb\u603b\u7ebf\uff0c\u521d\u59cb\u5316\u8be5usb\u603b\u7ebf\uff0c\u5c06hc_driver\u6302\u5230hcd\u4e0a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6dfb\u52a0HCD<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">usb_add_hcd(hcd)\uff0chcd\u4e2d\u7684usb\u603b\u7ebf\u5411\u5185\u6838\u6ce8\u518c\u3002\u5f53hcd\u6ce8\u518c\u5b8c\u4e4b\u540e\uff0c\u9700\u8981\u4e3ahcd\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u8bbe\u5907roothub\uff1aregister_root_hub(hcd)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">roothub\u867d\u7136\u662f\u865a\u62df\u8bbe\u5907\u4f46\u662f\u4e5f\u662f\u8bbe\u5907\uff0c\u8c03\u7528usb_new_device(usb_dev) \u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u8bbe\u5907\u5e76\u6dfb\u52a0\u5230USB\u603b\u7ebf\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u6dfb\u52a0roothub\u5e73\u53f0\u8bbe\u5907\uff0c\u5185\u6838\u5c31\u4f1a\u53bb\u5339\u914d\u5bf9\u5e94\u7684\u5e73\u53f0\u9a71\u52a8\uff0c\u6700\u540e\u5339\u914d\u5230\u524d\u9762usb&nbsp;core\u4e2d\u6ce8\u518c\u7684usb_generic_driver\uff0c\u6267\u884c\u5b83\u7684probe\u51fd\u6570\u3002generic_driver\u7684probe\u51fd\u6570\uff0c\u5411\u5185\u6838\u6dfb\u52a0\u4e00\u4e2aroothub<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">7.\u5c0f\u7ed3\u4e00\u4e0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. \u6ce8\u518c\u4e00\u4e2a\u4e3b\u673a\u63a7\u5236\u5668\u7684\u5e73\u53f0\u8bbe\u5907hcd\uff0c\u4e00\u4e2ahcd\u5bf9\u5e94\u4e00\u6761usb\u603b\u7ebf\uff0c\u4e00\u4e2ahcd\u6709\u4e00\u4e2aroothub\u7684usb\u8bbe\u5907\u3002\u5f53\u5f80hcd\u4e0a\u6dfb\u52a0\u4e00\u4e2aroothub\u7684usb\u8bbe\u5907\u65f6\uff0c\u4f1a\u5339\u914d\u5230\u901a\u7528\u9a71\u52a8generic_driver\uff0c\u5e76\u6267\u884c\u8be5\u9a71\u52a8\u7684probe\u63a5\u53e3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. roothub\u4e3b\u8981\u529f\u80fd\u662f\u76d1\u63a7hcd\u5bf9\u5e94\u7684usb\u603b\u7ebf\u662f\u5426\u6709\u8bbe\u5907\u63d2\u5165\uff0c\u5c06roothub\u7684\u4e2d\u65ad\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e\u4e3ahub_event\uff0c\u540e\u7eed\u518d\u6709\u65b0\u8bbe\u5907\u63d2\u5165\u65f6\uff0c\u90fd\u4f1a\u5728hub_event\u4e2d\u88ab\u68c0\u6d4b\u5230\uff0c\u68c0\u6d4b\u5230\u4e4b\u540e\u5219\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684usb\u8bbe\u5907\uff0c\u5bf9\u5e94\u7684generic_driver\u7684probe\u63a5\u53e3\u518d\u6b21\u88ab\u8c03\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u3001\u603b\u7ed3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u6bb5\u63cf\u8ff0\u4e86\u603b\u7ebf\u5728\u4e0a\u7535\u65f6\u521b\u5efa\u4e86\u4e00\u6761USB\u603b\u7ebf\u7c7b\u578b\uff0c\u5e76\u5728\u603b\u7ebf\u4e0a\u6ce8\u518c\u4e86\u4e00\u4e2ausb\u7684\u901a\u7528\u9a71\u52a8\uff0c&nbsp;usb_generic_driver\uff1b\u7b2c\u4e8c\u6bb5\u63cf\u8ff0\u4e86\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u4e3b\u673a\u63a7\u5236\u8bbe\u5907HSD\uff0c&nbsp;HCD\u81ea\u5df1\u6709\u4e00\u6761\u603b\u7ebfself\uff0c\u7136\u540e\u518dself\u4e0a\u518d\u6302\u4e0a\u4e00\u4e2aroothub\u7684device\uff0c\u4e8e\u662f\u5185\u6838\u5f00\u59cb\u8c03\u7528usb_generic_driver\u7684probe\u51fd\u6570\uff0c\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">hcd\u7684self\u548c\u524d\u9762\u6ce8\u518c\u7684usb_bus_type\uff0c\u8fd9\u4e24\u6761\u603b\u7ebf\u662f\u540c\u4e00\u6761\u5417\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e0d\u662f\u540c\u4e00\u6761\uff0c\u4e3a\u4ec0\u4e48hcd\u7684roothub\uff0c\u4f1a\u8c03\u7528usb\u603b\u7ebf\u4e0a\u7684\u901a\u7528\u9a71\u52a8\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u662f\u540c\u4e00\u6761\uff0c\u8fd9\u4e24\u8005\u662f\u5355\u72ec\u521b\u5efa\u7684\uff0c\u5728\u54ea\u91cc\u7edf\u4e00\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e26\u7740\u95ee\u9898\u53c8\u68b3\u7406\u4e86\u4e0b\uff0c\u6211\u662f\u8fd9\u6837\u7406\u89e3\u7684\uff0cusb_bus_type\u662f\u4e00\u4e2a\u603b\u7ebf\u7c7b\u578b\uff0cbus_register\u662f\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2a\u603b\u7ebf\u7c7b\u578b\uff0c\u800c\u540e\u9762\u7684usb_bus_register\u662f\u6ce8\u518c\u8be5\u603b\u7ebf\u7c7b\u578b\u7684\u4e00\u6761\u603b\u7ebf\uff0c\u8be5\u7c7b\u578b\u7684\u603b\u7ebf\u4e5f\u62e5\u6709\u8be5\u7c7b\u578b\u7684\u9a71\u52a8\u548c\u5339\u914d\u51fd\u6570\uff0c\u6240\u4ee5\u521b\u5efahcd\u91cc\u9762\u7684usb\u603b\u7ebf\uff0c\u628aroothub\u6302\u4e0a\u53bb\u65f6\u5c31\u80fd\u8c03\u7528\u8be5\u7c7b\u578b\u7684\u9a71\u52a8\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7406\u89e3\u6c47\u603b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7cfb\u7edf\u542f\u52a8\u65f6\u8c03\u7528usb_init\uff0c\u5411\u5185\u6838\u6ce8\u518c\u4e00\u4e2aUSB\u7684\u603b\u7ebf\u7c7b\u578b\uff0c\u5e76\u4e3a\u5b83\u6dfb\u52a0\u4e86\u901a\u7528\u9a71\u52a8\u3001\u5339\u914d\u51fd\u6570\u4ee5\u53ca\u5206\u914d\u4e00\u4e2a\u5185\u6838\u901a\u77e5\u94fe\uff1b<\/li>\n\n\n\n<li>\u7cfb\u7edf\u89e3\u6790\u8bbe\u5907\u6811\u4e4b\u540e\u5f97\u5230\u4e86\u4e00\u4e2a\u5e73\u53f0\u8bbe\u5907\uff0c\u4f1a\u6839\u636ematch\u00a0table\u53bb\u67e5\u627e\u5e73\u53f0\u9a71\u52a8\uff1b<\/li>\n\n\n\n<li>\u5e73\u53f0\u9a71\u52a8\u4e2d\u5bf9USB\u6a21\u5757\u8fdb\u884c\u521d\u59cb\u5316\u5e76\u521b\u5efa\u4e00\u4e2ausb\u4e3b\u673a\u63a7\u5236\u8bbe\u5907HCD\uff0c\u5e76\u4e3aHCD\u521b\u5efa\u4e00\u6761USB\u603b\u7ebf;<\/li>\n\n\n\n<li>HCD\u9700\u8981\u4e00\u4e2aroothub\u7684\u865a\u62dfUSB\u8bbe\u5907\uff0c\u4e8e\u662f\u521b\u5efa\u7b2c\u4e00\u4e2aUSBdevice\u5e76\u6dfb\u52a0\u5230USBbus\u4e0a\uff0c\u5f53\u603b\u7ebf\u88ab\u6dfb\u52a0\u4e86\u8bbe\u5907\uff0c\u5c31\u4f1a\u8c03\u7528usb_generic_driver\u7684probe\u63a5\u53e3\uff0c\u5269\u4e0b\u7684\u5de5\u4f5c\u4ea4\u7ed9roothub\uff0croothub\u4f1a\u76d1\u63a7\u603b\u7ebf\u4e0a\u7684\u72b6\u6001\u53d8\u5316\uff0c\u5f53\u6709\u8bbe\u5907\u63d2\u5165\u65f6\uff0chub\u4f1a\u542f\u52a8\u679a\u4e3e\u6d41\u7a0b\uff0c\u679a\u4e3e\u5b8c\u6210\u4e4b\u540e\uff0c\u5c06\u65b0\u8bbe\u5907\u6dfb\u52a0\u5230USB\u603b\u7ebf\uff0c\u518d\u6b21\u8c03\u7528generic_driver\u7684probe\u63a5\u53e3\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u68b3\u7406Linux\u7cfb\u7edf\u4e0bUSB\u5b50\u7cfb\u7edf\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0cUSB\u603b\u7ebf\u6ce8\u518c\u3001HCD\u6ce8\u518c\u4e24\u4e2a\u5207\u5165\u70b9\uff0c\u5185\u5bb9\u6839\u636e\u5b98\u65b9\u8d44\u6599\u3001\u5185\u6838\u6e90\u7801\u53ca [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_gspb_post_css":"","footnotes":""},"categories":[1,30],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-30"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":4,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monykate.com\/index.php\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}