m920x.c 22 KB

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