14 #include <linux/module.h>
15 #include <linux/kernel.h>
17 #include <asm/byteorder.h>
29 #define TX_BUF_SIZE 2048
30 #if defined(CONFIG_WIMAX_GDM72XX_WIMAX2)
31 #define RX_BUF_SIZE (128*1024)
33 #define RX_BUF_SIZE 2048
36 #define GDM7205_PADDING 256
38 #define H2B(x) __cpu_to_be16(x)
39 #define B2H(x) __be16_to_cpu(x)
40 #define DB2H(x) __be32_to_cpu(x)
42 #define DOWNLOAD_CONF_VALUE 0x21
44 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
49 static int k_mode_stop;
51 #define K_WAIT_TIME (2 * HZ / 100)
60 static void hexdump(
char *title,
u8 *
data,
int len)
65 for (i = 0; i < len; i++) {
95 static void free_tx_struct(
struct usb_tx *t)
124 static void free_rx_struct(
struct usb_rx *r)
134 static struct usb_tx *get_tx_struct(
struct tx_cxt *tx,
int *no_spc)
146 *no_spc = list_empty(&tx->
free_list) ? 1 : 0;
152 static void put_tx_struct(
struct tx_cxt *tx,
struct usb_tx *t)
163 r = alloc_rx_struct(rx);
177 static void put_rx_struct(
struct rx_cxt *rx,
struct usb_rx *r)
193 #if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
194 INIT_LIST_HEAD(&tx->pending_list);
204 t = alloc_tx_struct(tx);
212 r = alloc_rx_struct(rx);
226 static void release_usb(
struct usbwm_dev *udev)
259 static void __gdm_usb_send_complete(
struct urb *
urb)
261 struct usb_tx *t = urb->context;
276 cmd_evt = (pkt[0] << 8) | pkt[1];
278 put_tx_struct(tx, t);
283 static void gdm_usb_send_complete(
struct urb *urb)
285 struct usb_tx *t = urb->context;
290 __gdm_usb_send_complete(urb);
291 spin_unlock_irqrestore(&tx->
lock, flags);
294 static int gdm_usb_send(
void *priv_dev,
void *data,
int len,
298 struct usb_device *usbdev = udev->
usbdev;
316 cmd_evt = (pkt[0] << 8) | pkt[1];
318 t = get_tx_struct(tx, &no_spc);
321 spin_unlock_irqrestore(&tx->
lock, flags);
326 t = alloc_tx_struct(tx);
328 spin_unlock_irqrestore(&tx->
lock, flags);
342 if ((len % 512) == 0)
345 usb_fill_bulk_urb(t->
urb,
347 usb_sndbulkpipe(usbdev, 1),
350 gdm_usb_send_complete,
354 hexdump(
"usb_send", t->
buf, len + padding);
356 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
364 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
365 if (udev->bw_switch) {
380 spin_unlock(&k_lock);
390 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
391 usb_mark_last_busy(usbdev);
394 #if defined(CONFIG_WIMAX_GDM72XX_USB_PM) || defined(CONFIG_WIMAX_GDM72XX_K_MODE)
397 spin_unlock_irqrestore(&tx->
lock, flags);
406 __gdm_usb_send_complete(t->
urb);
407 spin_unlock_irqrestore(&tx->
lock, flags);
411 static void gdm_usb_rcv_complete(
struct urb *urb)
413 struct usb_rx *r = urb->context;
421 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
422 struct usb_device *
dev = urb->dev;
432 cmd_evt = (r->
buf[0] << 8) | (r->
buf[1]);
434 hexdump(
"usb_receive", r->
buf, urb->actual_length);
437 if (r->
buf[4] == 0) {
457 urb->actual_length = 0;
465 spin_lock(&rx->
lock);
466 put_rx_struct(rx, r);
467 spin_unlock(&rx->
lock);
469 spin_unlock_irqrestore(&tx->
lock, flags);
471 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
472 usb_mark_last_busy(dev);
476 static int gdm_usb_receive(
void *priv_dev,
477 void (*
cb)(
void *cb_data,
void *data,
int len),
481 struct usb_device *usbdev = udev->
usbdev;
492 r = get_rx_struct(rx);
493 spin_unlock_irqrestore(&rx->
lock, flags);
501 usb_fill_bulk_urb(r->
urb,
503 usb_rcvbulkpipe(usbdev, 0x82),
506 gdm_usb_rcv_complete,
512 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
520 ret = usb_autopm_get_interface(udev->intf);
522 usb_autopm_put_interface(udev->intf);
535 __gdm_usb_send_complete(t->
urb);
539 spin_unlock_irqrestore(&tx->
lock, flags);
552 struct usb_device *usbdev = interface_to_usbdev(intf);
555 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
558 idVendor =
L2H(usbdev->descriptor.idVendor);
559 idProduct =
L2H(usbdev->descriptor.idProduct);
560 bcdDevice =
L2H(usbdev->descriptor.bcdDevice);
563 idVendor, idProduct);
579 phy_dev = kzalloc(
sizeof(*phy_dev),
GFP_KERNEL);
580 if (phy_dev ==
NULL) {
590 if (idProduct == 0x7205 || idProduct == 0x7206)
597 phy_dev->
rcv_func = gdm_usb_receive;
599 ret = init_usb(udev);
605 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
608 intf->needs_remote_wakeup = 1;
623 usb_set_intfdata(intf, phy_dev);
630 struct phy_dev *phy_dev;
633 struct usb_device *usbdev = interface_to_usbdev(intf);
635 bConfigurationValue = usbdev->actconfig->desc.bConfigurationValue;
636 phy_dev = usb_get_intfdata(intf);
639 idProduct =
L2H(usbdev->descriptor.idProduct);
643 (idProduct & B_DOWNLOAD) == 0) {
656 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
659 struct phy_dev *phy_dev;
664 phy_dev = usb_get_intfdata(intf);
676 struct phy_dev *phy_dev;
681 phy_dev = usb_get_intfdata(intf);
693 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
694 static int k_mode_thread(
void *
arg)
706 while (!k_mode_stop) {
709 while (!list_empty(&k_list)) {
716 spin_unlock_irqrestore(&k_lock, flags2);
718 expire =
jiffies + K_WAIT_TIME;
719 while (jiffies < expire)
734 __gdm_usb_send_complete(t->urb);
739 spin_unlock_irqrestore(&tx->
lock, flags);
743 spin_unlock_irqrestore(&k_lock, flags2);
751 static struct usb_driver gdm_usb_driver = {
753 .probe = gdm_usb_probe,
754 .disconnect = gdm_usb_disconnect,
755 .id_table = id_table,
756 #ifdef CONFIG_WIMAX_GDM72XX_USB_PM
757 .supports_autosuspend = 1,
758 .suspend = gdm_suspend,
759 .resume = gdm_resume,
760 .reset_resume = gdm_resume,
764 static int __init usb_gdm_wimax_init(
void)
766 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE
769 return usb_register(&gdm_usb_driver);
772 static void __exit usb_gdm_wimax_exit(
void)
774 #ifdef CONFIG_WIMAX_GDM72XX_K_MODE