mcs7780.h 5.8 KB

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