f_iap2.c

/*

* Gadget Driver for  iAP

*

* Copyright (C) 2016 

* Author: 

*

*/

#include <linux/module.h>

#include <linux/init.h>

#include <linux/poll.h>

#include <linux/delay.h>

#include <linux/wait.h>

#include <linux/err.h>

#include <linux/interrupt.h>

#include <linux/sched.h>

#include <linux/types.h>

#include <linux/device.h>

#include <linux/miscdevice.h>

#define IAP_BULK_BUFFER_SIZE 4096

/* number of tx requests to allocate */

#define TX_REQ_MAX 4

#define IAP_GET_DEVICE_STATE _IOW('z', 1, int)

static const char iap_shortname[] = "zjinnova_iap";

struct iap_dev {

struct usb_function function;

struct usb_composite_dev *cdev;

spinlock_t lock;

struct usb_ep *ep_in;

struct usb_ep *ep_out;

int online;

int error;

atomic_t read_excl;

atomic_t write_excl;

atomic_t open_excl;

struct list_head tx_idle;

wait_queue_head_t read_wq;

wait_queue_head_t write_wq;

struct usb_request *rx_req;

int rx_done;

struct work_struct work;

struct miscdevice *misc_device;

int sw_online;

};

static struct usb_interface_descriptor iap_interface_desc = {

.bLength = USB_DT_INTERFACE_SIZE,

.bDescriptorType = USB_DT_INTERFACE,

.bInterfaceNumber = 0,

.bNumEndpoints = 2,

.bInterfaceClass = 0xFF,

.bInterfaceSubClass = 0xF0,

.bInterfaceProtocol = 0,

};

static struct usb_endpoint_descriptor iap_highspeed_in_desc = {

.bLength = USB_DT_ENDPOINT_SIZE,

.bDescriptorType = USB_DT_ENDPOINT,

.bEndpointAddress = USB_DIR_IN,

.bmAttributes = USB_ENDPOINT_XFER_BULK,

.wMaxPacketSize = __constant_cpu_to_le16(512),

};

static struct usb_endpoint_descriptor iap_highspeed_out_desc = {

.bLength = USB_DT_ENDPOINT_SIZE,

.bDescriptorType = USB_DT_ENDPOINT,

.bEndpointAddress = USB_DIR_OUT,

.bmAttributes = USB_ENDPOINT_XFER_BULK,

.wMaxPacketSize = __constant_cpu_to_le16(512),

};

static struct usb_endpoint_descriptor iap_fullspeed_in_desc = {

.bLength = USB_DT_ENDPOINT_SIZE,

.bDescriptorType = USB_DT_ENDPOINT,

.bEndpointAddress = USB_DIR_IN,

.bmAttributes = USB_ENDPOINT_XFER_BULK,

};

static struct usb_endpoint_descriptor iap_fullspeed_out_desc = {

.bLength = USB_DT_ENDPOINT_SIZE,

.bDescriptorType = USB_DT_ENDPOINT,

.bEndpointAddress = USB_DIR_OUT,

.bmAttributes = USB_ENDPOINT_XFER_BULK,

};

static struct usb_descriptor_header *fs_iap_descs[] = {

(struct usb_descriptor_header *) &iap_interface_desc,

(struct usb_descriptor_header *) &iap_fullspeed_in_desc,

(struct usb_descriptor_header *) &iap_fullspeed_out_desc,

NULL,

};

static struct usb_descriptor_header *hs_iap_descs[] = {

(struct usb_descriptor_header *) &iap_interface_desc,

(struct usb_descriptor_header *) &iap_highspeed_in_desc,

(struct usb_descriptor_header *) &iap_highspeed_out_desc,

NULL,

};

static struct usb_string iap_string_defs[] = {

[0].s = "iAP Interface",

{ } /* end of list */

};

static struct usb_gadget_strings iap_string_table = {

.language = 0x0409, /* en-us */

.strings = iap_string_defs,

};

static struct usb_gadget_strings *iap_strings[] = {

&iap_string_table,

NULL,

};

/* temporary variable used between iap_open() and iap_gadget_bind() */

static struct iap_dev *_iap_dev;

static inline struct iap_dev *func_to_iap(struct usb_function *f)

{

return container_of(f, struct iap_dev, function);

}

static struct usb_request *iap_request_new(struct usb_ep *ep, int buffer_size)

{

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无v邪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值