m920x.c 22 KB

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