m920x.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
  2. *
  3. * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, version 2.
  8. *
  9. * see Documentation/dvb/README.dvb-usb for more information
  10. */
  11. #include "m920x.h"
  12. #include "mt352.h"
  13. #include "mt352_priv.h"
  14. #include "qt1010.h"
  15. #include "tda1004x.h"
  16. #include "tda827x.h"
  17. /* debug */
  18. static int dvb_usb_m920x_debug;
  19. module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
  20. MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
  21. static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid);
  22. static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
  23. u16 index, void *data, int size)
  24. {
  25. int ret;
  26. ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  27. request, USB_TYPE_VENDOR | USB_DIR_IN,
  28. value, index, data, size, 2000);
  29. if (ret < 0) {
  30. printk(KERN_INFO "m920x_read = error: %d\n", ret);
  31. return ret;
  32. }
  33. if (ret != size) {
  34. deb("m920x_read = no data\n");
  35. return -EIO;
  36. }
  37. return 0;
  38. }
  39. static inline int m920x_write(struct usb_device *udev, u8 request,
  40. u16 value, u16 index)
  41. {
  42. int ret;
  43. ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  44. request, USB_TYPE_VENDOR | USB_DIR_OUT,
  45. value, index, NULL, 0, 2000);
  46. return ret;
  47. }
  48. static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
  49. {
  50. int ret = 0, i, epi, flags = 0;
  51. int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
  52. /* Remote controller init. */
  53. if (d->props.rc_query) {
  54. deb("Initialising remote control\n");
  55. while (rc_seq->address) {
  56. if ((ret = m920x_write(d->udev, M9206_CORE,
  57. rc_seq->data,
  58. rc_seq->address)) != 0) {
  59. deb("Initialising remote control failed\n");
  60. return ret;
  61. }
  62. rc_seq++;
  63. }
  64. deb("Initialising remote control success\n");
  65. }
  66. for (i = 0; i < d->props.num_adapters; i++)
  67. flags |= d->adapter[i].props.caps;
  68. /* Some devices(Dposh) might crash if we attempt touch at all. */
  69. if (flags & DVB_USB_ADAP_HAS_PID_FILTER) {
  70. for (i = 0; i < d->props.num_adapters; i++) {
  71. epi = d->adapter[i].props.stream.endpoint - 0x81;
  72. if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
  73. printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
  74. return -EINVAL;
  75. }
  76. adap_enabled[epi] = 1;
  77. }
  78. for (i = 0; i < M9206_MAX_ADAPTERS; i++) {
  79. if (adap_enabled[i])
  80. continue;
  81. if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0)
  82. return ret;
  83. if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0)
  84. return ret;
  85. }
  86. }
  87. return ret;
  88. }
  89. static int m920x_init_ep(struct usb_interface *intf)
  90. {
  91. struct usb_device *udev = interface_to_usbdev(intf);
  92. struct usb_host_interface *alt;
  93. if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) {
  94. deb("No alt found!\n");
  95. return -ENODEV;
  96. }
  97. return usb_set_interface(udev, alt->desc.bInterfaceNumber,
  98. alt->desc.bAlternateSetting);
  99. }
  100. static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  101. {
  102. struct m920x_state *m = d->priv;
  103. int i, ret = 0;
  104. u8 rc_state[2];
  105. if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
  106. goto unlock;
  107. if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
  108. goto unlock;
  109. for (i = 0; i < d->props.rc_key_map_size; i++)
  110. if (d->props.rc_key_map[i].data == rc_state[1]) {
  111. *event = d->props.rc_key_map[i].event;
  112. switch(rc_state[0]) {
  113. case 0x80:
  114. *state = REMOTE_NO_KEY_PRESSED;
  115. goto unlock;
  116. case 0x88: /* framing error or "invalid code" */
  117. case 0x99:
  118. case 0xc0:
  119. case 0xd8:
  120. *state = REMOTE_NO_KEY_PRESSED;
  121. m->rep_count = 0;
  122. goto unlock;
  123. case 0x93:
  124. case 0x92:
  125. m->rep_count = 0;
  126. *state = REMOTE_KEY_PRESSED;
  127. goto unlock;
  128. case 0x91:
  129. /* prevent immediate auto-repeat */
  130. if (++m->rep_count > 2)
  131. *state = REMOTE_KEY_REPEAT;
  132. else
  133. *state = REMOTE_NO_KEY_PRESSED;
  134. goto unlock;
  135. default:
  136. deb("Unexpected rc state %02x\n", rc_state[0]);
  137. *state = REMOTE_NO_KEY_PRESSED;
  138. goto unlock;
  139. }
  140. }
  141. if (rc_state[1] != 0)
  142. deb("Unknown rc key %02x\n", rc_state[1]);
  143. *state = REMOTE_NO_KEY_PRESSED;
  144. unlock:
  145. return ret;
  146. }
  147. /* I2C */
  148. static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
  149. {
  150. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  151. int i, j;
  152. int ret = 0;
  153. if (!num)
  154. return -EINVAL;
  155. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  156. return -EAGAIN;
  157. for (i = 0; i < num; i++) {
  158. if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) {
  159. /* For a 0 byte message, I think sending the address
  160. * to index 0x80|0x40 would be the correct thing to
  161. * do. However, zero byte messages are only used for
  162. * probing, and since we don't know how to get the
  163. * slave's ack, we can't probe. */
  164. ret = -ENOTSUPP;
  165. goto unlock;
  166. }
  167. /* Send START & address/RW bit */
  168. if (!(msg[i].flags & I2C_M_NOSTART)) {
  169. if ((ret = m920x_write(d->udev, M9206_I2C,
  170. (msg[i].addr << 1) |
  171. (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
  172. goto unlock;
  173. /* Should check for ack here, if we knew how. */
  174. }
  175. if (msg[i].flags & I2C_M_RD) {
  176. for (j = 0; j < msg[i].len; j++) {
  177. /* Last byte of transaction?
  178. * Send STOP, otherwise send ACK. */
  179. int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
  180. if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
  181. 0x20 | stop,
  182. &msg[i].buf[j], 1)) != 0)
  183. goto unlock;
  184. }
  185. } else {
  186. for (j = 0; j < msg[i].len; j++) {
  187. /* Last byte of transaction? Then send STOP. */
  188. int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
  189. if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
  190. goto unlock;
  191. /* Should check for ack here too. */
  192. }
  193. }
  194. }
  195. ret = num;
  196. unlock:
  197. mutex_unlock(&d->i2c_mutex);
  198. return ret;
  199. }
  200. static u32 m920x_i2c_func(struct i2c_adapter *adapter)
  201. {
  202. return I2C_FUNC_I2C;
  203. }
  204. static struct i2c_algorithm m920x_i2c_algo = {
  205. .master_xfer = m920x_i2c_xfer,
  206. .functionality = m920x_i2c_func,
  207. };
  208. /* pid filter */
  209. static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
  210. {
  211. int ret = 0;
  212. if (pid >= 0x8000)
  213. return -EINVAL;
  214. pid |= 0x8000;
  215. if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
  216. return ret;
  217. if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
  218. return ret;
  219. return ret;
  220. }
  221. static int m920x_update_filters(struct dvb_usb_adapter *adap)
  222. {
  223. struct m920x_state *m = adap->dev->priv;
  224. int enabled = m->filtering_enabled[adap->id];
  225. int i, ret = 0, filter = 0;
  226. int ep = adap->props.stream.endpoint;
  227. for (i = 0; i < M9206_MAX_FILTERS; i++)
  228. if (m->filters[adap->id][i] == 8192)
  229. enabled = 0;
  230. /* Disable all filters */
  231. if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
  232. return ret;
  233. for (i = 0; i < M9206_MAX_FILTERS; i++)
  234. if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
  235. return ret;
  236. /* Set */
  237. if (enabled) {
  238. for (i = 0; i < M9206_MAX_FILTERS; i++) {
  239. if (m->filters[adap->id][i] == 0)
  240. continue;
  241. if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
  242. return ret;
  243. filter++;
  244. }
  245. }
  246. return ret;
  247. }
  248. static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
  249. {
  250. struct m920x_state *m = adap->dev->priv;
  251. m->filtering_enabled[adap->id] = onoff ? 1 : 0;
  252. return m920x_update_filters(adap);
  253. }
  254. static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
  255. {
  256. struct m920x_state *m = adap->dev->priv;
  257. m->filters[adap->id][index] = onoff ? pid : 0;
  258. return m920x_update_filters(adap);
  259. }
  260. static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
  261. {
  262. u16 value, index, size;
  263. u8 read[4], *buff;
  264. int i, pass, ret = 0;
  265. buff = kmalloc(65536, GFP_KERNEL);
  266. if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
  267. goto done;
  268. deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
  269. if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
  270. goto done;
  271. deb("%x\n", read[0]);
  272. for (pass = 0; pass < 2; pass++) {
  273. for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
  274. value = le16_to_cpu(*(u16 *)(fw->data + i));
  275. i += sizeof(u16);
  276. index = le16_to_cpu(*(u16 *)(fw->data + i));
  277. i += sizeof(u16);
  278. size = le16_to_cpu(*(u16 *)(fw->data + i));
  279. i += sizeof(u16);
  280. if (pass == 1) {
  281. /* Will stall if using fw->data ... */
  282. memcpy(buff, fw->data + i, size);
  283. ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
  284. M9206_FW,
  285. USB_TYPE_VENDOR | USB_DIR_OUT,
  286. value, index, buff, size, 20);
  287. if (ret != size) {
  288. deb("error while uploading fw!\n");
  289. ret = -EIO;
  290. goto done;
  291. }
  292. msleep(3);
  293. }
  294. i += size;
  295. }
  296. if (i != fw->size) {
  297. deb("bad firmware file!\n");
  298. ret = -EINVAL;
  299. goto done;
  300. }
  301. }
  302. msleep(36);
  303. /* m920x will disconnect itself from the bus after this. */
  304. (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
  305. deb("firmware uploaded!\n");
  306. done:
  307. kfree(buff);
  308. return ret;
  309. }
  310. /* Callbacks for DVB USB */
  311. static int m920x_identify_state(struct usb_device *udev,
  312. struct dvb_usb_device_properties *props,
  313. struct dvb_usb_device_description **desc,
  314. int *cold)
  315. {
  316. struct usb_host_interface *alt;
  317. alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
  318. *cold = (alt == NULL) ? 1 : 0;
  319. return 0;
  320. }
  321. /* demod configurations */
  322. static int m920x_mt352_demod_init(struct dvb_frontend *fe)
  323. {
  324. int ret;
  325. u8 config[] = { CONFIG, 0x3d };
  326. u8 clock[] = { CLOCK_CTL, 0x30 };
  327. u8 reset[] = { RESET, 0x80 };
  328. u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
  329. u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
  330. u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
  331. u8 unk1[] = { 0x93, 0x1a };
  332. u8 unk2[] = { 0xb5, 0x7a };
  333. deb("Demod init!\n");
  334. if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
  335. return ret;
  336. if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
  337. return ret;
  338. if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
  339. return ret;
  340. if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
  341. return ret;
  342. if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
  343. return ret;
  344. if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
  345. return ret;
  346. if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
  347. return ret;
  348. if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
  349. return ret;
  350. return 0;
  351. }
  352. static struct mt352_config m920x_mt352_config = {
  353. .demod_address = 0x0f,
  354. .no_tuner = 1,
  355. .demod_init = m920x_mt352_demod_init,
  356. };
  357. static struct tda1004x_config m920x_tda10046_08_config = {
  358. .demod_address = 0x08,
  359. .invert = 0,
  360. .invert_oclk = 0,
  361. .ts_mode = TDA10046_TS_SERIAL,
  362. .xtal_freq = TDA10046_XTAL_16M,
  363. .if_freq = TDA10046_FREQ_045,
  364. .agc_config = TDA10046_AGC_TDA827X,
  365. .gpio_config = TDA10046_GPTRI,
  366. .request_firmware = NULL,
  367. };
  368. static struct tda1004x_config m920x_tda10046_0b_config = {
  369. .demod_address = 0x0b,
  370. .invert = 0,
  371. .invert_oclk = 0,
  372. .ts_mode = TDA10046_TS_SERIAL,
  373. .xtal_freq = TDA10046_XTAL_16M,
  374. .if_freq = TDA10046_FREQ_045,
  375. .agc_config = TDA10046_AGC_TDA827X,
  376. .gpio_config = TDA10046_GPTRI,
  377. .request_firmware = NULL, /* uses firmware EEPROM */
  378. };
  379. /* tuner configurations */
  380. static struct qt1010_config m920x_qt1010_config = {
  381. .i2c_address = 0x62
  382. };
  383. /* Callbacks for DVB USB */
  384. static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
  385. {
  386. deb("%s\n",__FUNCTION__);
  387. if ((adap->fe = dvb_attach(mt352_attach,
  388. &m920x_mt352_config,
  389. &adap->dev->i2c_adap)) == NULL)
  390. return -EIO;
  391. return 0;
  392. }
  393. static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
  394. {
  395. deb("%s\n",__FUNCTION__);
  396. if ((adap->fe = dvb_attach(tda10046_attach,
  397. &m920x_tda10046_08_config,
  398. &adap->dev->i2c_adap)) == NULL)
  399. return -EIO;
  400. return 0;
  401. }
  402. static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
  403. {
  404. deb("%s\n",__FUNCTION__);
  405. if ((adap->fe = dvb_attach(tda10046_attach,
  406. &m920x_tda10046_0b_config,
  407. &adap->dev->i2c_adap)) == NULL)
  408. return -EIO;
  409. return 0;
  410. }
  411. static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
  412. {
  413. deb("%s\n",__FUNCTION__);
  414. if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
  415. return -ENODEV;
  416. return 0;
  417. }
  418. static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
  419. {
  420. deb("%s\n",__FUNCTION__);
  421. if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
  422. return -ENODEV;
  423. return 0;
  424. }
  425. static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
  426. {
  427. deb("%s\n",__FUNCTION__);
  428. if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
  429. return -ENODEV;
  430. return 0;
  431. }
  432. /* device-specific initialization */
  433. static struct m920x_inits megasky_rc_init [] = {
  434. { M9206_RC_INIT2, 0xa8 },
  435. { M9206_RC_INIT1, 0x51 },
  436. { } /* terminating entry */
  437. };
  438. static struct m920x_inits tvwalkertwin_rc_init [] = {
  439. { M9206_RC_INIT2, 0x00 },
  440. { M9206_RC_INIT1, 0xef },
  441. { 0xff28, 0x00 },
  442. { 0xff23, 0x00 },
  443. { 0xff21, 0x30 },
  444. { } /* terminating entry */
  445. };
  446. /* ir keymaps */
  447. static struct dvb_usb_rc_key megasky_rc_keys [] = {
  448. { 0x0, 0x12, KEY_POWER },
  449. { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
  450. { 0x0, 0x02, KEY_CHANNELUP },
  451. { 0x0, 0x05, KEY_CHANNELDOWN },
  452. { 0x0, 0x03, KEY_VOLUMEUP },
  453. { 0x0, 0x06, KEY_VOLUMEDOWN },
  454. { 0x0, 0x04, KEY_MUTE },
  455. { 0x0, 0x07, KEY_OK }, /* TS */
  456. { 0x0, 0x08, KEY_STOP },
  457. { 0x0, 0x09, KEY_MENU }, /* swap */
  458. { 0x0, 0x0a, KEY_REWIND },
  459. { 0x0, 0x1b, KEY_PAUSE },
  460. { 0x0, 0x1f, KEY_FASTFORWARD },
  461. { 0x0, 0x0c, KEY_RECORD },
  462. { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
  463. { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
  464. };
  465. static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
  466. { 0x0, 0x01, KEY_ZOOM }, /* Full Screen */
  467. { 0x0, 0x02, KEY_CAMERA }, /* snapshot */
  468. { 0x0, 0x03, KEY_MUTE },
  469. { 0x0, 0x04, KEY_REWIND },
  470. { 0x0, 0x05, KEY_PLAYPAUSE }, /* Play/Pause */
  471. { 0x0, 0x06, KEY_FASTFORWARD },
  472. { 0x0, 0x07, KEY_RECORD },
  473. { 0x0, 0x08, KEY_STOP },
  474. { 0x0, 0x09, KEY_TIME }, /* Timeshift */
  475. { 0x0, 0x0c, KEY_COFFEE }, /* Recall */
  476. { 0x0, 0x0e, KEY_CHANNELUP },
  477. { 0x0, 0x12, KEY_POWER },
  478. { 0x0, 0x15, KEY_MENU }, /* source */
  479. { 0x0, 0x18, KEY_CYCLEWINDOWS }, /* TWIN PIP */
  480. { 0x0, 0x1a, KEY_CHANNELDOWN },
  481. { 0x0, 0x1b, KEY_VOLUMEDOWN },
  482. { 0x0, 0x1e, KEY_VOLUMEUP },
  483. };
  484. /* DVB USB Driver stuff */
  485. static struct dvb_usb_device_properties megasky_properties;
  486. static struct dvb_usb_device_properties digivox_mini_ii_properties;
  487. static struct dvb_usb_device_properties tvwalkertwin_properties;
  488. static struct dvb_usb_device_properties dposh_properties;
  489. static int m920x_probe(struct usb_interface *intf,
  490. const struct usb_device_id *id)
  491. {
  492. struct dvb_usb_device *d = NULL;
  493. int ret;
  494. struct m920x_inits *rc_init_seq = NULL;
  495. int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
  496. deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
  497. if (bInterfaceNumber == 0) {
  498. /* Single-tuner device, or first interface on
  499. * multi-tuner device
  500. */
  501. if ((ret = dvb_usb_device_init(intf, &megasky_properties,
  502. THIS_MODULE, &d)) == 0) {
  503. rc_init_seq = megasky_rc_init;
  504. goto found;
  505. }
  506. if ((ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
  507. THIS_MODULE, &d)) == 0) {
  508. /* No remote control, so no rc_init_seq */
  509. goto found;
  510. }
  511. /* This configures both tuners on the TV Walker Twin */
  512. if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
  513. THIS_MODULE, &d)) == 0) {
  514. rc_init_seq = tvwalkertwin_rc_init;
  515. goto found;
  516. }
  517. if ((ret = dvb_usb_device_init(intf, &dposh_properties,
  518. THIS_MODULE, &d)) == 0) {
  519. /* Remote controller not supported yet. */
  520. goto found;
  521. }
  522. return ret;
  523. } else {
  524. /* Another interface on a multi-tuner device */
  525. /* The LifeView TV Walker Twin gets here, but struct
  526. * tvwalkertwin_properties already configured both
  527. * tuners, so there is nothing for us to do here
  528. */
  529. }
  530. found:
  531. if ((ret = m920x_init_ep(intf)) < 0)
  532. return ret;
  533. if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
  534. return ret;
  535. return ret;
  536. }
  537. static struct usb_device_id m920x_table [] = {
  538. { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
  539. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  540. USB_PID_MSI_DIGI_VOX_MINI_II) },
  541. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  542. USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
  543. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  544. USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
  545. { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
  546. { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
  547. { } /* Terminating entry */
  548. };
  549. MODULE_DEVICE_TABLE (usb, m920x_table);
  550. static struct dvb_usb_device_properties megasky_properties = {
  551. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  552. .usb_ctrl = DEVICE_SPECIFIC,
  553. .firmware = "dvb-usb-megasky-02.fw",
  554. .download_firmware = m920x_firmware_download,
  555. .rc_interval = 100,
  556. .rc_key_map = megasky_rc_keys,
  557. .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
  558. .rc_query = m920x_rc_query,
  559. .size_of_priv = sizeof(struct m920x_state),
  560. .identify_state = m920x_identify_state,
  561. .num_adapters = 1,
  562. .adapter = {{
  563. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  564. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  565. .pid_filter_count = 8,
  566. .pid_filter = m920x_pid_filter,
  567. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  568. .frontend_attach = m920x_mt352_frontend_attach,
  569. .tuner_attach = m920x_qt1010_tuner_attach,
  570. .stream = {
  571. .type = USB_BULK,
  572. .count = 8,
  573. .endpoint = 0x81,
  574. .u = {
  575. .bulk = {
  576. .buffersize = 512,
  577. }
  578. }
  579. },
  580. }},
  581. .i2c_algo = &m920x_i2c_algo,
  582. .num_device_descs = 1,
  583. .devices = {
  584. { "MSI Mega Sky 580 DVB-T USB2.0",
  585. { &m920x_table[0], NULL },
  586. { NULL },
  587. }
  588. }
  589. };
  590. static struct dvb_usb_device_properties digivox_mini_ii_properties = {
  591. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  592. .usb_ctrl = DEVICE_SPECIFIC,
  593. .firmware = "dvb-usb-digivox-02.fw",
  594. .download_firmware = m920x_firmware_download,
  595. .size_of_priv = sizeof(struct m920x_state),
  596. .identify_state = m920x_identify_state,
  597. .num_adapters = 1,
  598. .adapter = {{
  599. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  600. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  601. .pid_filter_count = 8,
  602. .pid_filter = m920x_pid_filter,
  603. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  604. .frontend_attach = m920x_tda10046_08_frontend_attach,
  605. .tuner_attach = m920x_tda8275_60_tuner_attach,
  606. .stream = {
  607. .type = USB_BULK,
  608. .count = 8,
  609. .endpoint = 0x81,
  610. .u = {
  611. .bulk = {
  612. .buffersize = 0x4000,
  613. }
  614. }
  615. },
  616. }},
  617. .i2c_algo = &m920x_i2c_algo,
  618. .num_device_descs = 1,
  619. .devices = {
  620. { "MSI DIGI VOX mini II DVB-T USB2.0",
  621. { &m920x_table[1], NULL },
  622. { NULL },
  623. },
  624. }
  625. };
  626. /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
  627. *
  628. * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
  629. * TDA10046 #0 is located at i2c address 0x08
  630. * TDA10046 #1 is located at i2c address 0x0b
  631. * TDA8275A #0 is located at i2c address 0x60
  632. * TDA8275A #1 is located at i2c address 0x61
  633. */
  634. static struct dvb_usb_device_properties tvwalkertwin_properties = {
  635. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  636. .usb_ctrl = DEVICE_SPECIFIC,
  637. .firmware = "dvb-usb-tvwalkert.fw",
  638. .download_firmware = m920x_firmware_download,
  639. .rc_interval = 100,
  640. .rc_key_map = tvwalkertwin_rc_keys,
  641. .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys),
  642. .rc_query = m920x_rc_query,
  643. .size_of_priv = sizeof(struct m920x_state),
  644. .identify_state = m920x_identify_state,
  645. .num_adapters = 2,
  646. .adapter = {{
  647. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  648. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  649. .pid_filter_count = 8,
  650. .pid_filter = m920x_pid_filter,
  651. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  652. .frontend_attach = m920x_tda10046_08_frontend_attach,
  653. .tuner_attach = m920x_tda8275_60_tuner_attach,
  654. .stream = {
  655. .type = USB_BULK,
  656. .count = 8,
  657. .endpoint = 0x81,
  658. .u = {
  659. .bulk = {
  660. .buffersize = 512,
  661. }
  662. }
  663. }},{
  664. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  665. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  666. .pid_filter_count = 8,
  667. .pid_filter = m920x_pid_filter,
  668. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  669. .frontend_attach = m920x_tda10046_0b_frontend_attach,
  670. .tuner_attach = m920x_tda8275_61_tuner_attach,
  671. .stream = {
  672. .type = USB_BULK,
  673. .count = 8,
  674. .endpoint = 0x82,
  675. .u = {
  676. .bulk = {
  677. .buffersize = 512,
  678. }
  679. }
  680. },
  681. }},
  682. .i2c_algo = &m920x_i2c_algo,
  683. .num_device_descs = 1,
  684. .devices = {
  685. { .name = "LifeView TV Walker Twin DVB-T USB2.0",
  686. .cold_ids = { &m920x_table[2], NULL },
  687. .warm_ids = { &m920x_table[3], NULL },
  688. },
  689. }
  690. };
  691. static struct dvb_usb_device_properties dposh_properties = {
  692. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  693. .usb_ctrl = DEVICE_SPECIFIC,
  694. .firmware = "dvb-usb-dposh-01.fw",
  695. .download_firmware = m920x_firmware_download,
  696. .size_of_priv = sizeof(struct m920x_state),
  697. .identify_state = m920x_identify_state,
  698. .num_adapters = 1,
  699. .adapter = {{
  700. /* Hardware pid filters don't work with this device/firmware */
  701. .frontend_attach = m920x_mt352_frontend_attach,
  702. .tuner_attach = m920x_qt1010_tuner_attach,
  703. .stream = {
  704. .type = USB_BULK,
  705. .count = 8,
  706. .endpoint = 0x81,
  707. .u = {
  708. .bulk = {
  709. .buffersize = 512,
  710. }
  711. }
  712. },
  713. }},
  714. .i2c_algo = &m920x_i2c_algo,
  715. .num_device_descs = 1,
  716. .devices = {
  717. { .name = "Dposh DVB-T USB2.0",
  718. .cold_ids = { &m920x_table[4], NULL },
  719. .warm_ids = { &m920x_table[5], NULL },
  720. },
  721. }
  722. };
  723. static struct usb_driver m920x_driver = {
  724. .name = "dvb_usb_m920x",
  725. .probe = m920x_probe,
  726. .disconnect = dvb_usb_device_exit,
  727. .id_table = m920x_table,
  728. };
  729. /* module stuff */
  730. static int __init m920x_module_init(void)
  731. {
  732. int ret;
  733. if ((ret = usb_register(&m920x_driver))) {
  734. err("usb_register failed. Error number %d", ret);
  735. return ret;
  736. }
  737. return 0;
  738. }
  739. static void __exit m920x_module_exit(void)
  740. {
  741. /* deregister this driver from the USB subsystem */
  742. usb_deregister(&m920x_driver);
  743. }
  744. module_init (m920x_module_init);
  745. module_exit (m920x_module_exit);
  746. MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
  747. MODULE_DESCRIPTION("DVB Driver for ULI M920x");
  748. MODULE_VERSION("0.1");
  749. MODULE_LICENSE("GPL");
  750. /*
  751. * Local variables:
  752. * c-basic-offset: 8
  753. */