1 /*
2  * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  */
13 
14 #ifndef _GDM_MUX_H_
15 #define _GDM_MUX_H_
16 
17 #include <linux/types.h>
18 #include <linux/usb.h>
19 #include <linux/list.h>
20 
21 #include "gdm_tty.h"
22 
23 #define PM_NORMAL 0
24 #define PM_SUSPEND 1
25 
26 #define USB_RT_ACM          (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
27 
28 #define START_FLAG 0xA512485A
29 #define MUX_HEADER_SIZE 14
30 #define MUX_TX_MAX_SIZE (1024*10)
31 #define MUX_RX_MAX_SIZE (1024*30)
32 #define AT_PKT_TYPE 0xF011
33 #define DM_PKT_TYPE 0xF010
34 
35 #define RETRY_TIMER 30 /* msec */
36 
37 struct mux_pkt_header {
38 	__le32 start_flag;
39 	__le32 seq_num;
40 	__le32 payload_size;
41 	__le16 packet_type;
42 	unsigned char data[0];
43 };
44 
45 struct mux_tx {
46 	struct urb *urb;
47 	u8 *buf;
48 	int  len;
49 	void (*callback)(void *cb_data);
50 	void *cb_data;
51 };
52 
53 struct mux_rx {
54 	struct list_head free_list;
55 	struct list_head rx_submit_list;
56 	struct list_head to_host_list;
57 	struct urb *urb;
58 	u8 *buf;
59 	void *mux_dev;
60 	u32 offset;
61 	u32 len;
62 	int (*callback)(void *data,
63 			int len,
64 			int tty_index,
65 			struct tty_dev *tty_dev,
66 			int complete);
67 };
68 
69 struct rx_cxt {
70 	struct list_head to_host_list;
71 	struct list_head rx_submit_list;
72 	struct list_head rx_free_list;
73 	spinlock_t to_host_lock;
74 	spinlock_t submit_list_lock;
75 	spinlock_t free_list_lock;
76 };
77 
78 struct mux_dev {
79 	struct usb_device *usbdev;
80 	struct usb_interface *control_intf;
81 	struct usb_interface *data_intf;
82 	struct rx_cxt	rx;
83 	struct delayed_work work_rx;
84 	struct usb_interface *intf;
85 	int usb_state;
86 	int (*rx_cb)(void *data,
87 		     int len,
88 		     int tty_index,
89 		     struct tty_dev *tty_dev,
90 		     int complete);
91 	spinlock_t write_lock;
92 	struct tty_dev *tty_dev;
93 };
94 
95 #endif /* _GDM_MUX_H_ */
96