笔记本usb接口为always onn usb 可以连hub 吗

Linux下的USB HUB驱动
第9页_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Linux下的USB HUB驱动
来源:Linux社区&
作者:zhengmeifu
5.2.1:接口驱动的probe过程Hub_probe()的代码如下:static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id){&&& struct usb_host_interface *&&& struct usb_endpoint_descriptor *&&& struct usb_device *&&& struct usb_hub *&&&& desc = intf-&cur_&&& hdev = interface_to_usbdev(intf);&#ifdef& CONFIG_USB_OTG_BLACKLIST_HUB&&& if (hdev-&parent) {&&&&&&& dev_warn(&intf-&dev, "ignoring external hub\n");&&&&&&& return -ENODEV;&&& }#endif&&&& /* Some hubs have a subclass of 1, which AFAICT according to the */&&& /*& specs is not defined, but it works */&&& //spec上规定接口的subclass为0.但为1时,也能工作&&& if ((desc-&desc.bInterfaceSubClass != 0) &&&&&&&&& (desc-&desc.bInterfaceSubClass != 1)) {descriptor_error:&&&&&&& dev_err (&intf-&dev, "bad descriptor, ignoring hub\n");&&&&&&& return -EIO;&&& }&&&& /* Multiple endpoints? What kind of mutant ninja-hub is this? */&&& //spec上规定hub interface的endpoint数目为1,这里的数目没有包括ep0&&& if (desc-&desc.bNumEndpoints != 1)&&&&&&& goto descriptor_&&& //端点描述符&&& endpoint = &desc-&endpoint[0].&&&& /* If it's not an interrupt in endpoint, we'd better punt! */&&& //不是IN方向的中断传输端点,有错误&&& if (!usb_endpoint_is_int_in(endpoint))&&&&&&& goto descriptor_&&&& /* We found a hub */&&& dev_info (&intf-&dev, "USB hub found\n");&&&& //初始化一个struct usb_hub结构&&& hub = kzalloc(sizeof(*hub), GFP_KERNEL);&&& if (!hub) {&&&&&&& dev_dbg (&intf-&dev, "couldn't kmalloc hub struct\n");&&&&&&& return -ENOMEM;&&& }&&& //初始化引用计数&&& kref_init(&hub-&kref);&&& //初始化event_list&&& INIT_LIST_HEAD(&hub-&event_list);&&& //hub-&intfdev:指向接口封装的dev& &&& hub-&intfdev = &intf-&&&& //hub-&hdev:hub所属的usb_dev&&& hub-&hdev =&&& //初始化一个延时工作队列,用来管理hub LED的&&& INIT_DELAYED_WORK(&hub-&leds, led_work);&&& //增加intf-&dev的引用计数&&& usb_get_intf(intf);&&& //intf-&dev的私有结构指和hub&&& usb_set_intfdata (intf, hub);&&& //接口需要远程唤醒&&& intf-&needs_remote_wakeup = 1;&&&& //如果是一个高速设备,增加highspeed_hubs& 计数&&& if (hdev-&speed == USB_SPEED_HIGH)&&&&&&& highspeed_hubs++;&&&& //配置hub&&& if (hub_configure(hub, endpoint) &= 0)&&&&&&& return 0;&&&& hub_disconnect (intf);&&& return -ENODEV;}这个函数前一部份进行一些有效性检查,后半部份分配并初始化一个struct usb_hub结构.然后流程就转入了hub_configure().hub_configure()函数是一个很重要的操作,它的代码如下:static int hub_configure(struct usb_hub *hub,&&& struct usb_endpoint_descriptor *endpoint){&&& struct usb_device *hdev = hub-&&&& struct device *hub_dev = hub-&&&& u16 hubstatus,&&& u16 wHubC&&&&&& int maxp,&&& char *&&&& //为buffer分配空间,DMA分配,其物理地址存放在hub-&buffer_dma中&&& //buffer是一个指向数组的指针&&& hub-&buffer = usb_buffer_alloc(hdev, sizeof(*hub-&buffer), GFP_KERNEL,&&&&&&&&&&& &hub-&buffer_dma);&&& if (!hub-&buffer) {&&&&&&& message = "can't allocate hub irq buffer";&&&&&&& ret = -ENOMEM;&&&&&&&&&& }&&&& //为status分配空间&&& hub-&status = kmalloc(sizeof(*hub-&status), GFP_KERNEL);&&& if (!hub-&status) {&&&&&&& message = "can't kmalloc hub status buffer";&&&&&&& ret = -ENOMEM;&&&&&&&&&& }&&& mutex_init(&hub-&status_mutex);&&&& //为hub-&descriptor分配空间&&& hub-&descriptor = kmalloc(sizeof(*hub-&descriptor), GFP_KERNEL);&&& if (!hub-&descriptor) {&&&&&&& message = "can't kmalloc hub descriptor";&&&&&&& ret = -ENOMEM;&&&&&&&&&& }&&&& /* Request the entire hub descriptor.&&&& * hub-&descriptor can handle USB_MAXCHILDREN ports,&&&& * but the hub can/will return fewer bytes here.&&&& */&&&& //取得hub描述符&&& ret = get_hub_descriptor(hdev, hub-&descriptor,&&&&&&&&&&& sizeof(*hub-&descriptor));&&& //如果Get_Descriptor失败或者hub端口超多&&& if (ret & 0) {&&&&&&& message = "can't read hub descriptor";&&&&&&&&&& }&&& //协议上规定hub最多有255个接口,但Linux认为31个接口已经够多了&&& else if (hub-&descriptor-&bNbrPorts & USB_MAXCHILDREN) {&&&&&&& message = "hub has too many ports!";&&&&&&& ret = -ENODEV;&&&&&&&&&& }&&&& //hdev-&maxchild: hub的端口数目&&& hdev-&maxchild = hub-&descriptor-&bNbrP&&& dev_info (hub_dev, "%d port%s detected\n", hdev-&maxchild,&&&&&&& (hdev-&maxchild == 1) ? "" : "s");&&&& //wHubCharacteristics字段&&& wHubCharacteristics = le16_to_cpu(hub-&descriptor-&wHubCharacteristics);&&&& //是否是一个复合设备&&& if (wHubCharacteristics & HUB_CHAR_COMPOUND) {&&&&&&&&&&&&&& char&&& portstr [USB_MAXCHILDREN + 1];&&&&&&&& for (i = 0; i & hdev-& i++)&&&&&&&&&&& //找到数组中的所在项和数组项中的位置&&&&&&&&&&& portstr[i] = hub-&descriptor-&DeviceRemovable&&&&&&&&&&&&&&&&&&& [((i + 1) / 8)] & (1 && ((i + 1) % 8))&&&&&&&&&&&&&&& ? 'F' : 'R';&&&&&&& //以\0 结尾&&&&&&& portstr[hdev-&maxchild] = 0;&&&&&&& dev_dbg(hub_dev, " port removable status: %s\n", portstr);&&& } else&&&&&&& dev_dbg(hub_dev, "standalone hub\n");&&&& //电源开关模式&&& switch (wHubCharacteristics & HUB_CHAR_LPSM) {&&&&&&& //ganged 电源开关,所有连接端口同时开机&&&&&&& case 0x00:&&&&&&&&&&& dev_dbg(hub_dev, "ganged power switching\n");&&&&&&&&&&&&&&&&&& //端口有单独的电源开关 &&&&&&& case 0x01:&&&&&&&&&&& dev_dbg(hub_dev, "individual port power switching\n");&&&&&&&&&&&&&&&&&& //1X:保留, 表示没有电源开关&&& &&&&&&& case 0x02:&&&&&&& case 0x03:&&&&&&&&&&& dev_dbg(hub_dev, "no power switching (usb 1.0)\n");&&&&&&&&&&&&&& }&&&& //过电流保护模式&&& switch (wHubCharacteristics & HUB_CHAR_OCPM) {&&&&&&& //全部电流保护&&&&&&& case 0x00:&&&&&&&&&&& dev_dbg(hub_dev, "global over-current protection\n");&&&&&&&&&&&&&&&&&& //个别连接端口电源保护 &&&&&&& case 0x08:&&&&&&&&&&& dev_dbg(hub_dev, "individual port over-current protection\n");&&&&&&&&&&&&&&&&&& //没有过电流保护&&&&&&& case 0x10:&&&&&&& case 0x18:&&&&&&&&&&& dev_dbg(hub_dev, "no over-current protection\n");&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&& //初始化TT相关的东西&&& spin_lock_init (&hub-&tt.lock);&&& INIT_LIST_HEAD (&hub-&tt.clear_list);&&& INIT_WORK (&hub-&tt.kevent, hub_tt_kevent);&&& //设备描述符的bDeviceProtocol 字段&&& switch (hdev-&descriptor.bDeviceProtocol) {&&&&&&& //HUB是一个低速/全速设备&&&&&&& case 0:&&&&&&&&&&&&&&&&&& //只有一个TT &&&&&&& case 1:&&&&&&&&&&& dev_dbg(hub_dev, "Single TT\n");&&&&&&&&&&& hub-&tt.hub =&&&&&&&&&&&&&&&&&& //多个TT&&& &&&&&&& case 2:&&&&&&&&&&& //为接口选取1号设置&&&&&&&&&&& ret = usb_set_interface(hdev, 0, 1);&&&&&&&&&&& if (ret == 0) {&&&&&&&&&&&&&&& dev_dbg(hub_dev, "TT per port\n");&&&&&&&&&&&&&&& hub-&tt.multi = 1;&&&&&&&&&&& } else&&&&&&&&&&&&&&& dev_err(hub_dev, "Using single TT (err %d)\n",&&&&&&&&&&&&&&&&&&& ret);&&&&&&&&&&& hub-&tt.hub =&&&&&&&&&&&&&&&&&& default:&&&&&&&&&&& dev_dbg(hub_dev, "Unrecognized hub protocol %d\n",&&&&&&&&&&&&&&& hdev-&descriptor.bDeviceProtocol);&&&&&&&&&&&&&& }&&&& /* Note 8 FS bit times == (8 bits /
bps) ~= 666ns */&&& //TT think time,&&& switch (wHubCharacteristics & HUB_CHAR_TTTT) {&&&&&&& case HUB_TTTT_8_BITS:&&&&&&&&&&& if (hdev-&descriptor.bDeviceProtocol != 0) {&&&&&&&&&&&&&&& hub-&tt.think_time = 666;&&&&&&&&&&&&&&& dev_dbg(hub_dev, "TT requires at most %d "&&&&&&&&&&&&&&&&&&&&&&& "FS bit times (%d ns)\n",&&&&&&&&&&&&&&&&&&& 8, hub-&tt.think_time);&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& case HUB_TTTT_16_BITS:&&&&&&&&&&& hub-&tt.think_time = 666 * 2;&&&&&&&&&&& dev_dbg(hub_dev, "TT requires at most %d "&&&&&&&&&&&&&&&&&&& "FS bit times (%d ns)\n",&&&&&&&&&&&&&&& 16, hub-&tt.think_time);&&&&&&&&&&&&&&&&&& case HUB_TTTT_24_BITS:&&&&&&&&&&& hub-&tt.think_time = 666 * 3;&&&&&&&&&&& dev_dbg(hub_dev, "TT requires at most %d "&&&&&&&&&&&&&&&&&&& "FS bit times (%d ns)\n",&&&&&&&&&&&&&&& 24, hub-&tt.think_time);&&&&&&&&&&&&&&&&&& case HUB_TTTT_32_BITS:&&&&&&&&&&& hub-&tt.think_time = 666 * 4;&&&&&&&&&&& dev_dbg(hub_dev, "TT requires at most %d "&&&&&&&&&&&&&&&&&&& "FS bit times (%d ns)\n",&&&&&&&&&&&&&&& 32, hub-&tt.think_time);&&&&&&&&&&&&&& }&&&& /* probe() zeroes hub-&indicator[] */&&& //是否支持连接端口LED&&& if (wHubCharacteristics & HUB_CHAR_PORTIND) {&&&&&&& hub-&has_indicators = 1;&&&&&&& dev_dbg(hub_dev, "Port indicators are supported\n");&&& }&&& //bPwrOn2PwrGood字段表示连接端口从开机到准备好的时间&&& dev_dbg(hub_dev, "power on to power good time: %dms\n",&&&&&&& hub-&descriptor-&bPwrOn2PwrGood * 2);&&&& /* power budgeting mostly matters with bus-powered hubs,&&&& * and battery-powered root hubs (may provide just 8 mA).&&&& */&&&& //Get_Status 设备&&& ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);&&& //Get_Status失败&&& if (ret & 2) {&&&&&&& message = "can't get hub status";&&&&&&&&&& }&&& //设备的status包含两个部份:bit 0 表示使用自身电源bit 1是远程唤醒字段&&& le16_to_cpus(&hubstatus);&&& //如果是root hub&&& if (hdev == hdev-&bus-&root_hub) {&&&&&&& //如果电流没有限制&&&&&&& if (hdev-&bus_mA == 0 || hdev-&bus_mA &= 500)&&&&&&&&&&& hub-&mA_per_port = 500;&&&&&&& //有限制的情况下&&&&&&& else {&&&&&&&&&&& hub-&mA_per_port = hdev-&bus_mA;&&&&&&&&&&& hub-&limited_power = 1;&&&&&&& }&&& }&&& //如果使用总线电流&&& else if ((hubstatus & (1 && USB_DEVICE_SELF_POWERED)) == 0) {&&&&&&& dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",&&&&&&&&&&& hub-&descriptor-&bHubContrCurrent);&&&&&&& hub-&limited_power = 1;&&&&&&& if (hdev-&maxchild & 0) {&&&&&&&&&&& int remaining = hdev-&bus_mA -&&&&&&&&&&&&&&&&&&& hub-&descriptor-&bHubContrC&&&&&&&&&&&& if (remaining & hdev-&maxchild * 100)&&&&&&&&&&&&&&& dev_warn(hub_dev,&&&&&&&&&&&&&&&&&&& "insufficient power available "&&&&&&&&&&&&&&&&&&& "to use all downstream ports\n");&&&&&&&&&&& hub-&mA_per_port = 100;&&&& /* 7.2.1.1 */&&&&&&& }&&& }&&& // 如果使用本身电流&&& else {& /* Self-powered external hub */&&&&&&& /* FIXME: What about battery-powered external hubs that&&&&&&&& * provide less current per port? */&&&&&&& hub-&mA_per_port = 500;&&& }&&& if (hub-&mA_per_port & 500)&&&&&&& dev_dbg(hub_dev, "%umA bus power budget for each child\n",&&&&&&&&&&&&&&& hub-&mA_per_port);&&& //Get hub status&&& //hub 状态位和改变位&&& ret = hub_hub_status(hub, &hubstatus, &hubchange);&&& if (ret & 0) {&&&&&&& message = "can't get hub status";&&&&&&&&&& }&&&& /* local power status reports aren't always correct */&&& //自身供电&&& if (hdev-&actconfig-&desc.bmAttributes & USB_CONFIG_ATT_SELFPOWER)&&&&&&& dev_dbg(hub_dev, "local power source is %s\n",&&&&&&&&&&& (hubstatus & HUB_STATUS_LOCAL_POWER)&&&&&&&&&&& ? "lost (inactive)" : "good");&&& //不支持过电流保护&&& if ((wHubCharacteristics & HUB_CHAR_OCPM) == 0)&&&&&&& dev_dbg(hub_dev, "%sover-current condition exists\n",&&&&&&&&&&& (hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no ");&&&& /* set up the interrupt endpoint&&&& * We use the EP's maxpacket size instead of (PORTS+1+7)/8&&&& * bytes as USB2.0[11.12.3] says because some hubs are known&&&& * to send more data (and thus cause overflow). For root hubs,&&&& * maxpktsize is defined in hcd.c's fake endpoint descriptors&&&& * to be big enough for at least USB_MAXCHILDREN ports. */&&&& &&&& //设备中断控制传输的urb&&&& //通道和最大包长度&&& pipe = usb_rcvintpipe(hdev, endpoint-&bEndpointAddress);&&& maxp = usb_maxpacket(hdev, pipe, usb_pipeout(pipe));&&&& if (maxp & sizeof(*hub-&buffer))&&&&&&& maxp = sizeof(*hub-&buffer);&&& //分配urb&&& hub-&urb = usb_alloc_urb(0, GFP_KERNEL);&&& if (!hub-&urb) {&&&&&&& message = "couldn't allocate interrupt urb";&&&&&&& ret = -ENOMEM;&&&&&&&&&& }&&& //填充urb&&& usb_fill_int_urb(hub-&urb, hdev, pipe, *hub-&buffer, maxp, hub_irq,&&&&&&& hub, endpoint-&bInterval);&&& hub-&urb-&transfer_dma = hub-&buffer_&&& hub-&urb-&transfer_flags |= URB_NO_TRANSFER_DMA_MAP;&&&& /* maybe cycle the hub leds */&&& if (hub-&has_indicators && blinkenlights)&&&&&&& hub-&indicator [0] = INDICATOR_CYCLE;&&& //驱动hub&&& hub_power_on(hub);&&& //激活hub&&& hub_activate(hub);&&& return 0;&fail:&&& dev_err (hub_dev, "config failed, %s (err %d)\n",&&&&&&&&&&& message, ret);&&& /* hub_disconnect() frees urb and descriptor */&&&}这个函数先初始化struct usb_hub中的几个指针,为之分配空间,然后,取得hub的描述符,再根据取得的描述符信息再初始化和显示一些调试信息.其中的一些成员赋值等我们用到的时候再来进行分析.这个函数的后面关于urb部份和后面调用的两个子函数才是我们要分析的重点.9
相关资讯 & & &
& (11/14/:32)
& (02/20/:43)
& (09月21日)
& (03/16/:57)
& (02/20/:40)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款有没有一种 hub 是蓝牙连接的,然后外接电源 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
已注册用户请 &
这是一个专门讨论 idea 的地方。
每个人的时间,资源是有限的,有的时候你或许能够想到很多 idea,但是由于现实的限制,却并不是所有的 idea 都能够成为现实。
那这个时候,不妨可以把那些 idea 分享出来,启发别人。
有没有一种 hub 是蓝牙连接的,然后外接电源
12:37:49 +08:00 · 3433 次点击
想找一种设备功能大概是这样的:笔记本==蓝牙==&HUB(带USB,3.5MM音频), hub可以用外电源供电,这样的话,只要笔电配置蓝牙, USB跟音频口就可以全部解放了,不用到处插得都是线
13 回复 &| &直到
16:48:44 +08:00
& & 12:43:55 +08:00
蓝牙usb hub不知道,蓝牙3.5音频口貌似有。
& & 12:45:20 +08:00
& & 14:15:31 +08:00
一定要蓝牙么?
我只知道这种无线USB Hub:
& & 15:12:39 +08:00
@ 这个还是不能完全解放掉USB
& & 15:25:41 +08:00
@ 你需要的是:WiGiG
& & 15:31:05 +08:00
具体实现是:
& & 15:34:48 +08:00
视频简介:
& & 15:35:21 +08:00
为什么我Po的视频连接全被吃了? @
& & 15:38:17 +08:00
@ 可以正常显示啊
& & 15:40:08 +08:00
@ 知道原因了,HTTPS...
& & 15:45:02 +08:00
蓝牙传输速度太慢
& & 15:54:18 +08:00 via Android
你知道蓝牙有多快吗?手机党都用wifi传文件,快牙听说过吧!
让我想起以前的视频压缩,压要5小时,看完只要2小时……
& & 16:48:44 +08:00
还是用 wPCIe 吧……
& · & 1206 人在线 & 最高记录 3541 & · &
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.0 · 63ms · UTC 16:42 · PVG 00:42 · LAX 08:42 · JFK 11:42? Do have faith in what you're doing.Hub | eBay
Shop by categoryShop by categoryEnter your search keywordAll CategoriesHi ( to bid or buy)Notification
Hub Accessories -->
Browse RelatedBrowse RelatedAlso shop inAlso shop inAAPL: 112.71
As a 12″ MacBook owner, I’m always looking for new USB-C peripherals to help make my life easier. Aukey’s
is one such device.
The best wireless keyboard for the Mac?
I’ve used lots of USB-C peripherals since I’ve owned my MacBook, and I’ve refrained from covering them all, because some of the devices aren’t even worth bringing to your attention. Aukey’s hub, however, is well worth discussing.
There’s nothing particularly special about this hub, but the bu the USB 3.0 ports work as expected, and the Gigabit Ethernet functions fine without needing any special drivers, even on .
Small details like the rubber feet on the bottom of the device, which helps prevent movement on desk, and the USB-C connector itself, which isn’t wobbly like many of the USB-C-enabled devices that I’ve tested, make this hub a solid choice. The build material, while unapologetically plastic, is well- it actually reminds me of something Nintendo would have made back in its GameCube era.
Hands-on video
I only have a couple of complaints about the Aukey hub: 1). I wish the USB-C cable was a tad longer, and 2). I’m not a big fan of always-on LED light. If there’s going to be any LED light(s) on the hub, it should be used as an Ethernet connection status indicator, and not merely as a sign that the hub is properly connected to your Mac.
Ethernet worked immediately upon connecting
But it’s really hard to complain about . It’s simple, easy to use, well-built, inexpensive, and it just works. Do you own a MacBook? If so, what type of USB Type-C peripherals are you currently enjoying?
Be sure to check out some of our other favorite 12″ MacBook accessories:
After that, have a look at a couple of our 43; MacBook videos:
About the Author
Jeff produces videos, walkthroughs, how-tos, written tutorials and reviews. He takes pride in being able to explain things in a simple, clear and concise manner.
Jeff Benjamin's favorite gear}

我要回帖

更多关于 usb接口为always on 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信