[go: nahoru, domu]

1c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/*****************************************************************************
2c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
3c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz* Filename:      mcs7780.h
4c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz* Version:       0.2-alpha
5c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz* Description:   Irda MosChip USB Dongle
6c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz* Status:        Experimental
7c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz* Authors:       Lukasz Stelmach <stlman@poczta.fm>
8c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*		 Brian Pugh <bpugh@cs.pdx.edu>
9c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
10c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       Copyright (C) 2005, Lukasz Stelmach <stlman@poczta.fm>
11c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       Copyright (C) 2005, Brian Pugh <bpugh@cs.pdx.edu>
12c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
13c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       This program is free software; you can redistribute it and/or modify
14c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       it under the terms of the GNU General Public License as published by
15c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       the Free Software Foundation; either version 2 of the License, or
16c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       (at your option) any later version.
17c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
18c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       This program is distributed in the hope that it will be useful,
19c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       but WITHOUT ANY WARRANTY; without even the implied warranty of
20c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       GNU General Public License for more details.
22c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
23c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       You should have received a copy of the GNU General Public License
24c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       along with this program; if not, write to the Free Software
25c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*
27c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz*****************************************************************************/
28c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#ifndef _MCS7780_H
29c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define _MCS7780_H
30c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
31c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE_SIR		0
32c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE_MIR		1
33c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE_FIR		2
34c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
35c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_CTRL_TIMEOUT	500
36c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_XMIT_TIMEOUT	500
37c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* Possible transceiver types */
38c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TSC_VISHAY		0	/* Vishay TFD, default choice */
39c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TSC_AGILENT		1	/* Agilent 3602/3600 */
40c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TSC_SHARP		2	/* Sharp GP2W1000YP */
41c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
42c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* Requests */
43c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_RD_RTYPE 0xC0
44c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_WR_RTYPE 0x40
45c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_RDREQ    0x0F
46c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_WRREQ    0x0E
47c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
48c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* Register 0x00 */
49c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE_REG	0
50c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_FIR		((__u16)0x0001)
51c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SIR16US	((__u16)0x0002)
52c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_BBTG	((__u16)0x0004)
53c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_ASK		((__u16)0x0008)
54c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_PARITY	((__u16)0x0010)
55c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
56c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* SIR/MIR speed constants */
57c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_SHIFT	    5
58c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_MASK	    ((__u16)0x00E0)
59c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED(x)	    ((x & MCS_SPEED_MASK) >> MCS_SPEED_SHIFT)
60c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_2400	    ((0 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
61c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_9600	    ((1 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
62c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_19200	    ((2 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
63c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_38400	    ((3 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
64c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_57600	    ((4 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
65c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_115200    ((5 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
66c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_576000    ((6 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
67c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SPEED_1152000   ((7 << MCS_SPEED_SHIFT) & MCS_SPEED_MASK)
68c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
69c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_PLLPWDN	((__u16)0x0100)
70c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_DRIVER	((__u16)0x0200)
71c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_DTD		((__u16)0x0400)
72c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_DIR		((__u16)0x0800)
73c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SIPEN	((__u16)0x1000)
74c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SENDSIP	((__u16)0x2000)
75c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_CHGDIR	((__u16)0x4000)
76c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_RESET	((__u16)0x8000)
77c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
78c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* Register 0x02 */
79c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_XCVR_REG	2
80c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE0	((__u16)0x0001)
81c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_STFIR	((__u16)0x0002)
82c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_XCVR_CONF	((__u16)0x0004)
83c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_RXFAST	((__u16)0x0008)
84c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz/* TXCUR [6:4] */
85c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TXCUR_SHIFT	4
86c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TXCUR_MASK	((__u16)0x0070)
87c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_TXCUR(x)	((x & MCS_TXCUR_MASK) >> MCS_TXCUR_SHIFT)
88c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SETTXCUR(x,y) \
89c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	((x & ~MCS_TXCUR_MASK) | (y << MCS_TXCUR_SHIFT) & MCS_TXCUR_MASK)
90c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
91c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MODE1	((__u16)0x0080)
92c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SMODE0	((__u16)0x0100)
93c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_SMODE1	((__u16)0x0200)
94c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_INVTX	((__u16)0x0400)
95c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_INVRX	((__u16)0x0800)
96c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
97c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_MINRXPW_REG	4
98c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
99c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_RESV_REG 7
100c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_IRINTX	((__u16)0x0001)
101c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#define MCS_IRINRX	((__u16)0x0002)
102c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
103c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstruct mcs_cb {
104c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct usb_device *usbdev;	/* init: probe_irda */
105c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct net_device *netdev;	/* network layer */
106c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct irlap_cb *irlap;	/* The link layer we are binded to */
107c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct qos_info qos;
108c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	unsigned int speed;	/* Current speed */
109c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	unsigned int new_speed;	/* new speed */
110c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
111c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct work_struct work; /* Change speed work */
112c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
113c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct sk_buff *tx_pending;
114c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	char in_buf[4096];	/* transmit/receive buffer */
115c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	char out_buf[4096];	/* transmit/receive buffer */
116c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	__u8 *fifo_status;
117c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
118c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	iobuff_t rx_buff;	/* receive unwrap state machine */
119c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct timeval rx_time;
120c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	spinlock_t lock;
121c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	int receiving;
122c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
123c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	__u8 ep_in;
124c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	__u8 ep_out;
125c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
126c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct urb *rx_urb;
127c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	struct urb *tx_urb;
128c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
129c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	int transceiver_type;
130c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	int sir_tweak;
131c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz	int receive_mode;
132c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz};
133c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
134c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_set_reg(struct mcs_cb *mcs, __u16 reg, __u16 val);
135c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_get_reg(struct mcs_cb *mcs, __u16 reg, __u16 * val);
136c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
137c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_setup_transceiver_vishay(struct mcs_cb *mcs);
138c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_setup_transceiver_agilent(struct mcs_cb *mcs);
139c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_setup_transceiver_sharp(struct mcs_cb *mcs);
140c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_setup_transceiver(struct mcs_cb *mcs);
141c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_wrap_sir_skb(struct sk_buff *skb, __u8 * buf);
142c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic unsigned mcs_wrap_fir_skb(const struct sk_buff *skb, __u8 *buf);
143c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic unsigned mcs_wrap_mir_skb(const struct sk_buff *skb, __u8 *buf);
144c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic void mcs_unwrap_mir(struct mcs_cb *mcs, __u8 *buf, int len);
145c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic void mcs_unwrap_fir(struct mcs_cb *mcs, __u8 *buf, int len);
146c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_setup_urbs(struct mcs_cb *mcs);
147c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_receive_start(struct mcs_cb *mcs);
148c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic inline int mcs_find_endpoints(struct mcs_cb *mcs,
149c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz				     struct usb_host_endpoint *ep, int epnum);
150c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
151c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_speed_change(struct mcs_cb *mcs);
152c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
153c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd);
154c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_net_close(struct net_device *netdev);
155c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_net_open(struct net_device *netdev);
156c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
1577d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsstatic void mcs_receive_irq(struct urb *urb);
1587d12e780e003f93433d49ce78cfedf4b4c52adc5David Howellsstatic void mcs_send_irq(struct urb *urb);
1596518bbb803fe02b15a3211c8db2afdff0ac4f808Stephen Hemmingerstatic netdev_tx_t mcs_hard_xmit(struct sk_buff *skb,
1606518bbb803fe02b15a3211c8db2afdff0ac4f808Stephen Hemminger				       struct net_device *netdev);
161c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
162c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic int mcs_probe(struct usb_interface *intf,
163c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz		     const struct usb_device_id *id);
164c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortizstatic void mcs_disconnect(struct usb_interface *intf);
165c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz
166c6ae522e3a50fc1ec483d7f03ece9c7a25e6de95Samuel Ortiz#endif				/* _MCS7780_H */
167