dvb-dibusb.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * dvb-dibusb.h
  3. *
  4. * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. *
  10. * for more information see dvb-dibusb-core.c .
  11. */
  12. #ifndef __DVB_DIBUSB_H__
  13. #define __DVB_DIBUSB_H__
  14. #include <linux/input.h>
  15. #include <linux/config.h>
  16. #include <linux/usb.h>
  17. #include "dvb_frontend.h"
  18. #include "dvb_demux.h"
  19. #include "dvb_net.h"
  20. #include "dmxdev.h"
  21. #include "dib3000.h"
  22. #include "mt352.h"
  23. /* debug */
  24. #ifdef CONFIG_DVB_DIBCOM_DEBUG
  25. #define dprintk(level,args...) \
  26. do { if ((dvb_dibusb_debug & level)) { printk(args); } } while (0)
  27. #define debug_dump(b,l) {\
  28. int i; \
  29. for (i = 0; i < l; i++) deb_xfer("%02x ", b[i]); \
  30. deb_xfer("\n");\
  31. }
  32. #else
  33. #define dprintk(args...)
  34. #define debug_dump(b,l)
  35. #endif
  36. extern int dvb_dibusb_debug;
  37. /* Version information */
  38. #define DRIVER_VERSION "0.3"
  39. #define DRIVER_DESC "DiBcom based USB Budget DVB-T device"
  40. #define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
  41. #define deb_info(args...) dprintk(0x01,args)
  42. #define deb_xfer(args...) dprintk(0x02,args)
  43. #define deb_alot(args...) dprintk(0x04,args)
  44. #define deb_ts(args...) dprintk(0x08,args)
  45. #define deb_err(args...) dprintk(0x10,args)
  46. #define deb_rc(args...) dprintk(0x20,args)
  47. /* generic log methods - taken from usb.h */
  48. #undef err
  49. #define err(format, arg...) printk(KERN_ERR "dvb-dibusb: " format "\n" , ## arg)
  50. #undef info
  51. #define info(format, arg...) printk(KERN_INFO "dvb-dibusb: " format "\n" , ## arg)
  52. #undef warn
  53. #define warn(format, arg...) printk(KERN_WARNING "dvb-dibusb: " format "\n" , ## arg)
  54. struct dibusb_usb_controller {
  55. const char *name; /* name of the usb controller */
  56. u16 cpu_cs_register; /* needs to be restarted, when the firmware has been downloaded. */
  57. };
  58. typedef enum {
  59. DIBUSB1_1 = 0,
  60. DIBUSB1_1_AN2235,
  61. DIBUSB2_0,
  62. UMT2_0,
  63. DIBUSB2_0B,
  64. NOVAT_USB2,
  65. DTT200U,
  66. } dibusb_class_t;
  67. typedef enum {
  68. DIBUSB_TUNER_CABLE_THOMSON = 0,
  69. DIBUSB_TUNER_COFDM_PANASONIC_ENV57H1XD5,
  70. DIBUSB_TUNER_CABLE_LG_TDTP_E102P,
  71. DIBUSB_TUNER_COFDM_PANASONIC_ENV77H11D5,
  72. } dibusb_tuner_t;
  73. typedef enum {
  74. DIBUSB_DIB3000MB = 0,
  75. DIBUSB_DIB3000MC,
  76. DIBUSB_MT352,
  77. DTT200U_FE,
  78. } dibusb_demodulator_t;
  79. typedef enum {
  80. DIBUSB_RC_NO = 0,
  81. DIBUSB_RC_NEC_PROTOCOL,
  82. DIBUSB_RC_HAUPPAUGE_PROTO,
  83. } dibusb_remote_t;
  84. struct dibusb_tuner {
  85. dibusb_tuner_t id;
  86. u8 pll_addr; /* tuner i2c address */
  87. };
  88. extern struct dibusb_tuner dibusb_tuner[];
  89. #define DIBUSB_POSSIBLE_I2C_ADDR_NUM 4
  90. struct dibusb_demod {
  91. dibusb_demodulator_t id;
  92. int pid_filter_count; /* counter of the internal pid_filter */
  93. u8 i2c_addrs[DIBUSB_POSSIBLE_I2C_ADDR_NUM]; /* list of possible i2c addresses of the demod */
  94. };
  95. #define DIBUSB_MAX_TUNER_NUM 2
  96. struct dibusb_device_class {
  97. dibusb_class_t id;
  98. const struct dibusb_usb_controller *usb_ctrl; /* usb controller */
  99. const char *firmware; /* valid firmware filenames */
  100. int pipe_cmd; /* command pipe (read/write) */
  101. int pipe_data; /* data pipe */
  102. int urb_count; /* number of data URBs to be submitted */
  103. int urb_buffer_size; /* the size of the buffer for each URB */
  104. dibusb_remote_t remote_type; /* does this device have a ir-receiver */
  105. struct dibusb_demod *demod; /* which demodulator is mount */
  106. struct dibusb_tuner *tuner; /* which tuner can be found here */
  107. };
  108. #define DIBUSB_ID_MAX_NUM 15
  109. struct dibusb_usb_device {
  110. const char *name; /* real name of the box */
  111. struct dibusb_device_class *dev_cl; /* which dibusb_device_class is this device part of */
  112. struct usb_device_id *cold_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at pre firmware state */
  113. struct usb_device_id *warm_ids[DIBUSB_ID_MAX_NUM]; /* list of USB ids when this device is at post firmware state */
  114. };
  115. /* a PID for the pid_filter list, when in use */
  116. struct dibusb_pid
  117. {
  118. int index;
  119. u16 pid;
  120. int active;
  121. };
  122. struct usb_dibusb {
  123. /* usb */
  124. struct usb_device * udev;
  125. struct dibusb_usb_device * dibdev;
  126. #define DIBUSB_STATE_INIT 0x000
  127. #define DIBUSB_STATE_URB_LIST 0x001
  128. #define DIBUSB_STATE_URB_BUF 0x002
  129. #define DIBUSB_STATE_URB_INIT 0x004
  130. #define DIBUSB_STATE_DVB 0x008
  131. #define DIBUSB_STATE_I2C 0x010
  132. #define DIBUSB_STATE_REMOTE 0x020
  133. #define DIBUSB_STATE_URB_SUBMIT 0x040
  134. int init_state;
  135. int feedcount;
  136. struct dib_fe_xfer_ops xfer_ops;
  137. struct dibusb_tuner *tuner;
  138. struct urb **urb_list;
  139. u8 *buffer;
  140. dma_addr_t dma_handle;
  141. /* I2C */
  142. struct i2c_adapter i2c_adap;
  143. /* locking */
  144. struct semaphore usb_sem;
  145. struct semaphore i2c_sem;
  146. /* dvb */
  147. struct dvb_adapter adapter;
  148. struct dmxdev dmxdev;
  149. struct dvb_demux demux;
  150. struct dvb_net dvb_net;
  151. struct dvb_frontend* fe;
  152. int (*fe_sleep) (struct dvb_frontend *);
  153. int (*fe_init) (struct dvb_frontend *);
  154. /* remote control */
  155. struct input_dev rc_input_dev;
  156. struct work_struct rc_query_work;
  157. int last_event;
  158. int last_state; /* for Hauppauge RC protocol */
  159. int repeat_key_count;
  160. int rc_key_repeat_count; /* module parameter */
  161. /* module parameters */
  162. int pid_parse;
  163. int rc_query_interval;
  164. };
  165. /* commonly used functions in the separated files */
  166. /* dvb-dibusb-firmware.c */
  167. int dibusb_loadfirmware(struct usb_device *udev, struct dibusb_usb_device *dibdev);
  168. /* dvb-dibusb-remote.c */
  169. int dibusb_remote_exit(struct usb_dibusb *dib);
  170. int dibusb_remote_init(struct usb_dibusb *dib);
  171. /* dvb-dibusb-fe-i2c.c */
  172. int dibusb_fe_init(struct usb_dibusb* dib);
  173. int dibusb_fe_exit(struct usb_dibusb *dib);
  174. int dibusb_i2c_init(struct usb_dibusb *dib);
  175. int dibusb_i2c_exit(struct usb_dibusb *dib);
  176. /* dvb-dibusb-dvb.c */
  177. void dibusb_urb_complete(struct urb *urb, struct pt_regs *ptregs);
  178. int dibusb_dvb_init(struct usb_dibusb *dib);
  179. int dibusb_dvb_exit(struct usb_dibusb *dib);
  180. /* dvb-dibusb-usb.c */
  181. int dibusb_readwrite_usb(struct usb_dibusb *dib, u8 *wbuf, u16 wlen, u8 *rbuf,
  182. u16 rlen);
  183. int dibusb_write_usb(struct usb_dibusb *dib, u8 *buf, u16 len);
  184. int dibusb_hw_wakeup(struct dvb_frontend *);
  185. int dibusb_hw_sleep(struct dvb_frontend *);
  186. int dibusb_set_streaming_mode(struct usb_dibusb *,u8);
  187. int dibusb_streaming(struct usb_dibusb *,int);
  188. int dibusb_urb_init(struct usb_dibusb *);
  189. int dibusb_urb_exit(struct usb_dibusb *);
  190. /* dvb-fe-dtt200u.c */
  191. struct dvb_frontend* dtt200u_fe_attach(struct usb_dibusb *,struct dib_fe_xfer_ops *);
  192. /* i2c and transfer stuff */
  193. #define DIBUSB_I2C_TIMEOUT 5000
  194. /*
  195. * protocol of all dibusb related devices
  196. */
  197. /*
  198. * bulk msg to/from endpoint 0x01
  199. *
  200. * general structure:
  201. * request_byte parameter_bytes
  202. */
  203. #define DIBUSB_REQ_START_READ 0x00
  204. #define DIBUSB_REQ_START_DEMOD 0x01
  205. /*
  206. * i2c read
  207. * bulk write: 0x02 ((7bit i2c_addr << 1) & 0x01) register_bytes length_word
  208. * bulk read: byte_buffer (length_word bytes)
  209. */
  210. #define DIBUSB_REQ_I2C_READ 0x02
  211. /*
  212. * i2c write
  213. * bulk write: 0x03 (7bit i2c_addr << 1) register_bytes value_bytes
  214. */
  215. #define DIBUSB_REQ_I2C_WRITE 0x03
  216. /*
  217. * polling the value of the remote control
  218. * bulk write: 0x04
  219. * bulk read: byte_buffer (5 bytes)
  220. *
  221. * first byte of byte_buffer shows the status (0x00, 0x01, 0x02)
  222. */
  223. #define DIBUSB_REQ_POLL_REMOTE 0x04
  224. #define DIBUSB_RC_NEC_EMPTY 0x00
  225. #define DIBUSB_RC_NEC_KEY_PRESSED 0x01
  226. #define DIBUSB_RC_NEC_KEY_REPEATED 0x02
  227. /* additional status values for Hauppauge Remote Control Protocol */
  228. #define DIBUSB_RC_HAUPPAUGE_KEY_PRESSED 0x01
  229. #define DIBUSB_RC_HAUPPAUGE_KEY_EMPTY 0x03
  230. /* streaming mode:
  231. * bulk write: 0x05 mode_byte
  232. *
  233. * mode_byte is mostly 0x00
  234. */
  235. #define DIBUSB_REQ_SET_STREAMING_MODE 0x05
  236. /* interrupt the internal read loop, when blocking */
  237. #define DIBUSB_REQ_INTR_READ 0x06
  238. /* io control
  239. * 0x07 cmd_byte param_bytes
  240. *
  241. * param_bytes can be up to 32 bytes
  242. *
  243. * cmd_byte function parameter name
  244. * 0x00 power mode
  245. * 0x00 sleep
  246. * 0x01 wakeup
  247. *
  248. * 0x01 enable streaming
  249. * 0x02 disable streaming
  250. *
  251. *
  252. */
  253. #define DIBUSB_REQ_SET_IOCTL 0x07
  254. /* IOCTL commands */
  255. /* change the power mode in firmware */
  256. #define DIBUSB_IOCTL_CMD_POWER_MODE 0x00
  257. #define DIBUSB_IOCTL_POWER_SLEEP 0x00
  258. #define DIBUSB_IOCTL_POWER_WAKEUP 0x01
  259. /* modify streaming of the FX2 */
  260. #define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
  261. #define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
  262. #endif