第16章 USB主机、设备与Gadget驱动之USB UDC与Gadget驱动(二)

16.4.2 Chipidea(公司) USB UDC(USB设备控制器)驱动

    Chipidea USB UDC驱动的主体代码路径:drivers/usb/chipidea/udc.c,代码清单16.33列出其初始化流程部分,并定义了usb_ep_ops、usb_gadget_ops,在最终进行usb_add_gadget_udc()之前填充好了UDC的端点列表。

代码清单16.33 Chipidea USB UDC驱动实例

/**
 * Endpoint-specific part of the API to the USB controller hardware
 * Check "usb_gadget.h" for details
 */
static const struct usb_ep_ops usb_ep_ops = {
.enable        = ep_enable,
.disable       = ep_disable,
.alloc_request = ep_alloc_request,
.free_request  = ep_free_request,
.queue        = ep_queue,
.dequeue       = ep_dequeue,
.set_halt      = ep_set_halt,
.set_wedge     = ep_set_wedge,
.fifo_flush    = ep_fifo_flush,

};

/**
 * Device operations part of the API to the USB controller hardware,
 * which don't involve endpoints (or i/o)
 * Check  "usb_gadget.h" for details
 */
static const struct usb_gadget_ops usb_gadget_ops = {
.vbus_session = ci_udc_vbus_session,
.wakeup = ci_udc_wakeup,
.pullup = ci_udc_pullup,
.vbus_draw = ci_udc_vbus_draw,
.udc_start = ci_udc_start,
.udc_stop = ci_udc_stop,

};

static int init_eps(struct ci_hdrc *ci)
{
int retval = 0, i, j;

for (i = 0; i < ci->hw_ep_max/2; i++)
for (j = RX; j <= TX; j++) {
int k = i + j * ci->hw_ep_max/2;
struct ci_hw_ep *hwep = &ci->ci_hw_ep[k];

scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i, (j == TX)  ? "in" : "out");
hwep->ci          = ci;
hwep->lock         = &ci->lock;
hwep->td_pool      = ci->td_pool;
hwep->ep.name      = hwep->name;
hwep->ep.ops       = &usb_ep_ops;
/*
* for ep0: maxP defined in desc, for other
* eps, maxP is set by epautoconfig() called
* by gadget layer
*/
usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0);
INIT_LIST_HEAD(&hwep->qh.queue);
hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL, &hwep->qh.dma);
if (hwep->qh.ptr == NULL)
retval = -ENOMEM;
else
memset(hwep->qh.ptr, 0, sizeof(*hwep->qh.ptr));

/*
* set up shorthands for ep0 out and in endpoints,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值