OMAP3: SR: Remove redundant defines
[linux-ginger.git] / drivers / staging / otus / wrap_usb.c
blob70fd410bc894c8b80da92a16fd9128b34cef29d0
1 /*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 /* */
17 /* Module Name : wrap_usb.c */
18 /* */
19 /* Abstract */
20 /* This module contains wrapper functions for USB management */
21 /* */
22 /* NOTES */
23 /* Platform dependent. */
24 /* */
25 /************************************************************************/
27 #include "oal_dt.h"
28 #include "usbdrv.h"
30 #include <linux/netlink.h>
31 #include <net/iw_handler.h>
33 extern void zfLnxInitUsbTxQ(zdev_t* dev);
34 extern void zfLnxInitUsbRxQ(zdev_t* dev);
35 extern u32_t zfLnxSubmitRegInUrb(zdev_t *dev);
36 u32_t zfLnxUsbOut(zdev_t* dev, u8_t *hdr, u16_t hdrlen, u8_t *snap, u16_t snapLen,
37 u8_t *tail, u16_t tailLen, zbuf_t *buf, u16_t offset);
38 u32_t zfLnxUsbWriteReg(zdev_t* dev, u32_t* cmd, u16_t cmdLen);
40 void zfwUsbRegisterCallBack(zdev_t* dev, struct zfCbUsbFuncTbl *zfUsbFunc) {
41 struct usbdrv_private *macp = dev->ml_priv;
43 macp->usbCbFunctions.zfcbUsbRecv = zfUsbFunc->zfcbUsbRecv;
44 macp->usbCbFunctions.zfcbUsbRegIn = zfUsbFunc->zfcbUsbRegIn;
45 macp->usbCbFunctions.zfcbUsbOutComplete = zfUsbFunc->zfcbUsbOutComplete;
47 return;
50 u32_t zfwUsbGetFreeTxQSize(zdev_t* dev)
52 struct usbdrv_private *macp = dev->ml_priv;
53 u32_t freeTxQSize;
54 unsigned long irqFlag;
55 //zmw_declare_for_critical_section();
57 //zmw_enter_critical_section(dev);
58 spin_lock_irqsave(&macp->cs_lock, irqFlag);
60 freeTxQSize = ZM_MAX_TX_BUF_NUM - macp->TxBufCnt;
62 //zmw_leave_critical_section(dev);
63 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
65 return freeTxQSize;
68 u32_t zfwUsbGetMaxTxQSize(zdev_t* dev)
70 return ZM_MAX_TX_BUF_NUM;
73 u32_t zfwUsbEnableIntEpt(zdev_t *dev, u8_t endpt)
75 /* Initialize USB TxQ */
76 zfLnxInitUsbTxQ(dev);
78 /* Initialize USB RxQ */
79 zfLnxInitUsbRxQ(dev);
81 /* Initialize USB Register In URB */
82 //zfwUsbSubmitRegIn(dev);
83 /* Initialize USB Register In URB */
84 zfLnxSubmitRegInUrb(dev);
86 return 0;
89 int zfwUsbEnableRxEpt(zdev_t* dev, u8_t endpt)
91 return 0;
94 u32_t zfwUsbSubmitControl(zdev_t* dev, u8_t req, u16_t value, u16_t index, void *data, u32_t size)
96 int result = 0;
97 u32_t ret = 0;
98 struct usbdrv_private *macp = dev->ml_priv;
99 u8_t* buf;
101 if (size > 0)
103 buf = kmalloc(size, GFP_KERNEL);
104 memcpy(buf, (u8_t*)data, size);
106 else
108 buf = NULL;
111 #if 0
112 printk(KERN_ERR "req = 0x%02x\n", req);
113 printk(KERN_ERR "value = 0x%04x\n", value);
114 printk(KERN_ERR "index = 0x%04x\n", index);
115 printk(KERN_ERR "data = 0x%lx\n", (u32_t) data);
116 printk(KERN_ERR "size = %ld\n", size);
117 #endif
119 result = usb_control_msg(macp->udev, usb_sndctrlpipe(macp->udev, 0),
120 req, USB_DIR_OUT | 0x40, value, index, buf, size, HZ);
122 if (result < 0)
124 printk("zfwUsbSubmitControl() failed, result=0x%x\n", result);
125 ret = 1;
127 kfree(buf);
129 return ret;
132 void zfwUsbCmd(zdev_t* dev, u8_t endpt, u32_t* cmd, u16_t cmdLen)
134 struct usbdrv_private *macp = dev->ml_priv;
135 u32_t ret;
137 //MPUsbCommand(dev, endpt, cmd, cmdLen);
138 ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);
140 /* if zfLnxUsbWriteReg() return error, free and allocate urb, resend again */
141 if (ret != 0)
143 usb_free_urb(macp->RegOutUrb);
144 macp->RegOutUrb = usb_alloc_urb(0, GFP_ATOMIC);
145 ret = zfLnxUsbWriteReg(dev, cmd, cmdLen);
149 u32_t zfwUsbSend(zdev_t* dev, u8_t endpt, u8_t *hdr, u16_t hdrlen, u8_t *snap, u16_t snapLen,
150 u8_t *tail, u16_t tailLen, zbuf_t *buf, u16_t offset)
152 u32_t status;
154 #ifdef ZM_CONFIG_BIG_ENDIAN
155 u32_t ii = 0;
156 u16_t *pc = NULL;
158 pc = (u16_t *)hdr;
159 for(ii=0; ii<(hdrlen>>1); ii++)
161 pc[ii] = cpu_to_le16(pc[ii]);
164 pc = (u16_t *)snap;
165 for(ii=0; ii<(snapLen>>1); ii++)
167 pc[ii] = cpu_to_le16(pc[ii]);
170 pc = (u16_t *)tail;
171 for(ii=0; ii<(tailLen>>1); ii++)
173 pc[ii] = cpu_to_le16(pc[ii]);
175 #endif
177 status = zfLnxUsbOut(dev, hdr, hdrlen, snap, snapLen, tail, tailLen, buf, offset);
178 if ( status == 0 )
180 return 0;
182 else
184 return 1;
188 /* Leave an empty line below to remove warning message on some compiler */