USB设备状态设置-- usb_gadget_set_state()
来源:互联网 发布:淘宝店营销推广技巧 编辑:程序博客网 时间:2024/05/21 03:57
一、USB设备状态
在USB 2.0协议中第 9.1 USB Device States 章节规定了USB设备的6种状态,包括:
Attached/Powered/Default/Address/Configured/Suspended
其状态迁移图如下:
在 Linux Kernel ch9.h 文件中用 enum usb_device_state
来标记这几种状态。
// <kernel_dir>/include/uapi/linux/usb/ch9.henum usb_device_state { /* NOTATTACHED isn't in the USB spec, and this state acts * the same as ATTACHED ... but it's clearer this way. */ USB_STATE_NOTATTACHED = 0, /* chapter 9 and authentication (wireless) device states */ USB_STATE_ATTACHED, USB_STATE_POWERED, /* wired */ USB_STATE_RECONNECTING, /* auth */ USB_STATE_UNAUTHENTICATED, /* auth */ USB_STATE_DEFAULT, /* limited function */ USB_STATE_ADDRESS, USB_STATE_CONFIGURED, /* most functions */ USB_STATE_SUSPENDED /* NOTE: there are actually four different SUSPENDED * states, returning to POWERED, DEFAULT, ADDRESS, or * CONFIGURED respectively when SOF tokens flow again. * At this level there's no difference between L1 and L2 * suspend states. (L2 being original USB 1.1 suspend.) */};
二、状态设置函数usb_gadget_set_state()
// <kernel_dir>/drivers/usb/gadget/udc/udc-core.cvoid usb_gadget_set_state(struct usb_gadget *gadget, enum usb_device_state state){ gadget->state = state; schedule_work(&gadget->work);}EXPORT_SYMBOL_GPL(usb_gadget_set_state);// <kernel_dir>/include/linux/usb/gadget.hextern void usb_gadget_set_state(struct usb_gadget *gadget, enum usb_device_state state);
在 udc-core.c 文件中,会去定义usb_gadget_set_state()
函数,将状态state
的值赋值给gadget->state
。其中struct usb_gadget
是用来标记一个USB设备的信息。此时USB设备的状态就可以确定了。之后启动工作队列schedule_work(&gadget->work);
将状态信息给到sysfs。
在USB的枚举阶段,会根据USB所处的状态调用usb_gadget_set_state()
去设置USB设备的状态。
比如说在USB设备的枚举阶段,在composite_setup()
函数中USB设备接收到了USB Host发过来的USB_REQ_SET_CONFIGURATION
命令后调用set_config()
设置相应的配置,这之后就会调用usb_gadget_set_state()
去设置为USB_STATE_CONFIGURED
状态。
三、usb_gadget_state_work()
// <kernel_dir>/drivers/usb/gadget/udc/udc-core.c* usb_add_gadget_udc_release - adds a new gadget to the udc class driver list * @parent: the parent device to this udc. Usually the controller driver's * device. * @gadget: the gadget to be added to the list. * @release: a gadget release function. * * Returns zero on success, negative errno otherwise. */int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, void (*release)(struct device *dev))
在usb_add_gadget_udc_release()
中会去绑定 gadget->work
到 usb_gadget_state_work()
函数。
static void usb_gadget_state_work(struct work_struct *work){ struct usb_gadget *gadget = work_to_gadget(work); struct usb_udc *udc = gadget->udc; if (udc) sysfs_notify(&udc->dev.kobj, NULL, "state");}
这个函数主要目的就是将当前的 state 信息写入到 sysfs 中去。这个信息可以cat出来。
#cat /sys/devices/platform/xxx_udc/state
路径不完全是这个,但是在 /sys/devices 目录下会有对应udc控制器 xxx_udc 的状态节点。不仅包含状态的节点,还包含其他的信息。
-r--r--r-- 0 0 4096 2017-05-01 16:17 a_alt_hnp_support-r--r--r-- 0 0 4096 2017-05-01 16:17 a_hnp_support-r--r--r-- 0 0 4096 2017-05-01 16:17 b_hnp_enable-r--r--r-- 0 0 4096 2017-05-01 16:17 current_speedlrwxrwxrwx 0 0 2017-05-01 16:17 device -> ../../../panasonic_udc.1-r--r--r-- 0 0 4096 2017-05-01 16:17 is_a_peripheral-r--r--r-- 0 0 4096 2017-05-01 16:17 is_otg-r--r--r-- 0 0 4096 2017-05-01 16:17 maximum_speeddrwxr-xr-x 0 0 2017-05-01 16:17 power--w------- 0 0 4096 2017-05-01 16:17 soft_connect--w------- 0 0 4096 2017-05-01 16:17 srp-r--r--r-- 0 0 4096 2017-05-01 16:17 statelrwxrwxrwx 0 0 2017-05-01 16:17 subsystem -> ../../../../../class/udc-rw-r--r-- 0 0 4096 2017-05-01 16:17 uevent
这里面的信息其实就是一个USB设备的信息,用 struct usb_gadget
来描述。关于USB Gadget的内容将在后续的文章中整理出来。
- USB设备状态设置-- usb_gadget_set_state()
- USB设备状态
- USB设备的驱动状态
- wince下USB设备驱动缓冲区设置
- Ubuntu下usb设备读写权限设置
- USB几种设备状态以及创建过程
- 使用恶意USB设备解锁锁屏状态
- vc检测usb设备的拔插状态
- statusBarOrientation设备状态判断--- 横竖屏设置
- USB设备
- usb设备
- android外接存储设备状态判断-USB和SD卡连接状态
- Linux系统下设置USB设备用户权限的基本方法
- Ubuntu - usb转串口设备的访问权限设置
- 4.12 基于OHCI的USB主机 —— USB设备设置地址
- ros使用usb硬件,调用固定设备名修改设备权限的设置方法
- 设备状态
- 判断iOS设备的PUSH通知设置状态(打开。。。/关闭)
- 2017.07.21
- Spring-(2)Spring IOC
- VC获取网页源码的三种方式
- 【codevs 1073】家族
- 动态规划,背包问题,卡题(CRB and His Birthday,HDU 5410)
- USB设备状态设置-- usb_gadget_set_state()
- HDOJ--1285 确定比赛名次(拓扑排序)
- MPC常用到的线性模型
- popupwindow从下往上滑出:
- Android studio超级好用的快捷键 ALT+J
- Linux设备驱动程序_第七章_时间、延迟及延缓操作
- ci框架基础详解(入门学习)
- Linux那些事(1)-CentOS Linux+Win7双系统安装配置详解
- Dubbo源代码分析七:使用executes属性的一个问题