m920x.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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 (rc5_data(&d->props.rc_key_map[i]) == 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 (buff == NULL)
  269. return -ENOMEM;
  270. if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
  271. goto done;
  272. deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
  273. if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
  274. goto done;
  275. deb("%x\n", read[0]);
  276. for (pass = 0; pass < 2; pass++) {
  277. for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
  278. value = get_unaligned_le16(fw->data + i);
  279. i += sizeof(u16);
  280. index = get_unaligned_le16(fw->data + i);
  281. i += sizeof(u16);
  282. size = get_unaligned_le16(fw->data + i);
  283. i += sizeof(u16);
  284. if (pass == 1) {
  285. /* Will stall if using fw->data ... */
  286. memcpy(buff, fw->data + i, size);
  287. ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
  288. M9206_FW,
  289. USB_TYPE_VENDOR | USB_DIR_OUT,
  290. value, index, buff, size, 20);
  291. if (ret != size) {
  292. deb("error while uploading fw!\n");
  293. ret = -EIO;
  294. goto done;
  295. }
  296. msleep(3);
  297. }
  298. i += size;
  299. }
  300. if (i != fw->size) {
  301. deb("bad firmware file!\n");
  302. ret = -EINVAL;
  303. goto done;
  304. }
  305. }
  306. msleep(36);
  307. /* m920x will disconnect itself from the bus after this. */
  308. (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
  309. deb("firmware uploaded!\n");
  310. done:
  311. kfree(buff);
  312. return ret;
  313. }
  314. /* Callbacks for DVB USB */
  315. static int m920x_identify_state(struct usb_device *udev,
  316. struct dvb_usb_device_properties *props,
  317. struct dvb_usb_device_description **desc,
  318. int *cold)
  319. {
  320. struct usb_host_interface *alt;
  321. alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
  322. *cold = (alt == NULL) ? 1 : 0;
  323. return 0;
  324. }
  325. /* demod configurations */
  326. static int m920x_mt352_demod_init(struct dvb_frontend *fe)
  327. {
  328. int ret;
  329. u8 config[] = { CONFIG, 0x3d };
  330. u8 clock[] = { CLOCK_CTL, 0x30 };
  331. u8 reset[] = { RESET, 0x80 };
  332. u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
  333. u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
  334. u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
  335. u8 unk1[] = { 0x93, 0x1a };
  336. u8 unk2[] = { 0xb5, 0x7a };
  337. deb("Demod init!\n");
  338. if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
  339. return ret;
  340. if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
  341. return ret;
  342. if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
  343. return ret;
  344. if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
  345. return ret;
  346. if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
  347. return ret;
  348. if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
  349. return ret;
  350. if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
  351. return ret;
  352. if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
  353. return ret;
  354. return 0;
  355. }
  356. static struct mt352_config m920x_mt352_config = {
  357. .demod_address = 0x0f,
  358. .no_tuner = 1,
  359. .demod_init = m920x_mt352_demod_init,
  360. };
  361. static struct tda1004x_config m920x_tda10046_08_config = {
  362. .demod_address = 0x08,
  363. .invert = 0,
  364. .invert_oclk = 0,
  365. .ts_mode = TDA10046_TS_SERIAL,
  366. .xtal_freq = TDA10046_XTAL_16M,
  367. .if_freq = TDA10046_FREQ_045,
  368. .agc_config = TDA10046_AGC_TDA827X,
  369. .gpio_config = TDA10046_GPTRI,
  370. .request_firmware = NULL,
  371. };
  372. static struct tda1004x_config m920x_tda10046_0b_config = {
  373. .demod_address = 0x0b,
  374. .invert = 0,
  375. .invert_oclk = 0,
  376. .ts_mode = TDA10046_TS_SERIAL,
  377. .xtal_freq = TDA10046_XTAL_16M,
  378. .if_freq = TDA10046_FREQ_045,
  379. .agc_config = TDA10046_AGC_TDA827X,
  380. .gpio_config = TDA10046_GPTRI,
  381. .request_firmware = NULL, /* uses firmware EEPROM */
  382. };
  383. /* tuner configurations */
  384. static struct qt1010_config m920x_qt1010_config = {
  385. .i2c_address = 0x62
  386. };
  387. /* Callbacks for DVB USB */
  388. static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
  389. {
  390. deb("%s\n",__func__);
  391. if ((adap->fe = dvb_attach(mt352_attach,
  392. &m920x_mt352_config,
  393. &adap->dev->i2c_adap)) == NULL)
  394. return -EIO;
  395. return 0;
  396. }
  397. static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
  398. {
  399. deb("%s\n",__func__);
  400. if ((adap->fe = dvb_attach(tda10046_attach,
  401. &m920x_tda10046_08_config,
  402. &adap->dev->i2c_adap)) == NULL)
  403. return -EIO;
  404. return 0;
  405. }
  406. static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
  407. {
  408. deb("%s\n",__func__);
  409. if ((adap->fe = dvb_attach(tda10046_attach,
  410. &m920x_tda10046_0b_config,
  411. &adap->dev->i2c_adap)) == NULL)
  412. return -EIO;
  413. return 0;
  414. }
  415. static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
  416. {
  417. deb("%s\n",__func__);
  418. if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
  419. return -ENODEV;
  420. return 0;
  421. }
  422. static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
  423. {
  424. deb("%s\n",__func__);
  425. if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
  426. return -ENODEV;
  427. return 0;
  428. }
  429. static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
  430. {
  431. deb("%s\n",__func__);
  432. if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
  433. return -ENODEV;
  434. return 0;
  435. }
  436. /* device-specific initialization */
  437. static struct m920x_inits megasky_rc_init [] = {
  438. { M9206_RC_INIT2, 0xa8 },
  439. { M9206_RC_INIT1, 0x51 },
  440. { } /* terminating entry */
  441. };
  442. static struct m920x_inits tvwalkertwin_rc_init [] = {
  443. { M9206_RC_INIT2, 0x00 },
  444. { M9206_RC_INIT1, 0xef },
  445. { 0xff28, 0x00 },
  446. { 0xff23, 0x00 },
  447. { 0xff21, 0x30 },
  448. { } /* terminating entry */
  449. };
  450. /* ir keymaps */
  451. static struct dvb_usb_rc_key megasky_rc_keys [] = {
  452. { 0x0012, KEY_POWER },
  453. { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
  454. { 0x0002, KEY_CHANNELUP },
  455. { 0x0005, KEY_CHANNELDOWN },
  456. { 0x0003, KEY_VOLUMEUP },
  457. { 0x0006, KEY_VOLUMEDOWN },
  458. { 0x0004, KEY_MUTE },
  459. { 0x0007, KEY_OK }, /* TS */
  460. { 0x0008, KEY_STOP },
  461. { 0x0009, KEY_MENU }, /* swap */
  462. { 0x000a, KEY_REWIND },
  463. { 0x001b, KEY_PAUSE },
  464. { 0x001f, KEY_FASTFORWARD },
  465. { 0x000c, KEY_RECORD },
  466. { 0x000d, KEY_CAMERA }, /* screenshot */
  467. { 0x000e, KEY_COFFEE }, /* "MTS" */
  468. };
  469. static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
  470. { 0x0001, KEY_ZOOM }, /* Full Screen */
  471. { 0x0002, KEY_CAMERA }, /* snapshot */
  472. { 0x0003, KEY_MUTE },
  473. { 0x0004, KEY_REWIND },
  474. { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
  475. { 0x0006, KEY_FASTFORWARD },
  476. { 0x0007, KEY_RECORD },
  477. { 0x0008, KEY_STOP },
  478. { 0x0009, KEY_TIME }, /* Timeshift */
  479. { 0x000c, KEY_COFFEE }, /* Recall */
  480. { 0x000e, KEY_CHANNELUP },
  481. { 0x0012, KEY_POWER },
  482. { 0x0015, KEY_MENU }, /* source */
  483. { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
  484. { 0x001a, KEY_CHANNELDOWN },
  485. { 0x001b, KEY_VOLUMEDOWN },
  486. { 0x001e, KEY_VOLUMEUP },
  487. };
  488. /* DVB USB Driver stuff */
  489. static struct dvb_usb_device_properties megasky_properties;
  490. static struct dvb_usb_device_properties digivox_mini_ii_properties;
  491. static struct dvb_usb_device_properties tvwalkertwin_properties;
  492. static struct dvb_usb_device_properties dposh_properties;
  493. static int m920x_probe(struct usb_interface *intf,
  494. const struct usb_device_id *id)
  495. {
  496. struct dvb_usb_device *d = NULL;
  497. int ret;
  498. struct m920x_inits *rc_init_seq = NULL;
  499. int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
  500. deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
  501. if (bInterfaceNumber == 0) {
  502. /* Single-tuner device, or first interface on
  503. * multi-tuner device
  504. */
  505. ret = dvb_usb_device_init(intf, &megasky_properties,
  506. THIS_MODULE, &d, adapter_nr);
  507. if (ret == 0) {
  508. rc_init_seq = megasky_rc_init;
  509. goto found;
  510. }
  511. ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
  512. THIS_MODULE, &d, adapter_nr);
  513. if (ret == 0) {
  514. /* No remote control, so no rc_init_seq */
  515. goto found;
  516. }
  517. /* This configures both tuners on the TV Walker Twin */
  518. ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
  519. THIS_MODULE, &d, adapter_nr);
  520. if (ret == 0) {
  521. rc_init_seq = tvwalkertwin_rc_init;
  522. goto found;
  523. }
  524. ret = dvb_usb_device_init(intf, &dposh_properties,
  525. THIS_MODULE, &d, adapter_nr);
  526. if (ret == 0) {
  527. /* Remote controller not supported yet. */
  528. goto found;
  529. }
  530. return ret;
  531. } else {
  532. /* Another interface on a multi-tuner device */
  533. /* The LifeView TV Walker Twin gets here, but struct
  534. * tvwalkertwin_properties already configured both
  535. * tuners, so there is nothing for us to do here
  536. */
  537. }
  538. found:
  539. if ((ret = m920x_init_ep(intf)) < 0)
  540. return ret;
  541. if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
  542. return ret;
  543. return ret;
  544. }
  545. static struct usb_device_id m920x_table [] = {
  546. { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
  547. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  548. USB_PID_MSI_DIGI_VOX_MINI_II) },
  549. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  550. USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
  551. { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
  552. USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
  553. { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
  554. { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
  555. { } /* Terminating entry */
  556. };
  557. MODULE_DEVICE_TABLE (usb, m920x_table);
  558. static struct dvb_usb_device_properties megasky_properties = {
  559. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  560. .usb_ctrl = DEVICE_SPECIFIC,
  561. .firmware = "dvb-usb-megasky-02.fw",
  562. .download_firmware = m920x_firmware_download,
  563. .rc_interval = 100,
  564. .rc_key_map = megasky_rc_keys,
  565. .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
  566. .rc_query = m920x_rc_query,
  567. .size_of_priv = sizeof(struct m920x_state),
  568. .identify_state = m920x_identify_state,
  569. .num_adapters = 1,
  570. .adapter = {{
  571. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  572. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  573. .pid_filter_count = 8,
  574. .pid_filter = m920x_pid_filter,
  575. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  576. .frontend_attach = m920x_mt352_frontend_attach,
  577. .tuner_attach = m920x_qt1010_tuner_attach,
  578. .stream = {
  579. .type = USB_BULK,
  580. .count = 8,
  581. .endpoint = 0x81,
  582. .u = {
  583. .bulk = {
  584. .buffersize = 512,
  585. }
  586. }
  587. },
  588. }},
  589. .i2c_algo = &m920x_i2c_algo,
  590. .num_device_descs = 1,
  591. .devices = {
  592. { "MSI Mega Sky 580 DVB-T USB2.0",
  593. { &m920x_table[0], NULL },
  594. { NULL },
  595. }
  596. }
  597. };
  598. static struct dvb_usb_device_properties digivox_mini_ii_properties = {
  599. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  600. .usb_ctrl = DEVICE_SPECIFIC,
  601. .firmware = "dvb-usb-digivox-02.fw",
  602. .download_firmware = m920x_firmware_download,
  603. .size_of_priv = sizeof(struct m920x_state),
  604. .identify_state = m920x_identify_state,
  605. .num_adapters = 1,
  606. .adapter = {{
  607. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  608. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  609. .pid_filter_count = 8,
  610. .pid_filter = m920x_pid_filter,
  611. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  612. .frontend_attach = m920x_tda10046_08_frontend_attach,
  613. .tuner_attach = m920x_tda8275_60_tuner_attach,
  614. .stream = {
  615. .type = USB_BULK,
  616. .count = 8,
  617. .endpoint = 0x81,
  618. .u = {
  619. .bulk = {
  620. .buffersize = 0x4000,
  621. }
  622. }
  623. },
  624. }},
  625. .i2c_algo = &m920x_i2c_algo,
  626. .num_device_descs = 1,
  627. .devices = {
  628. { "MSI DIGI VOX mini II DVB-T USB2.0",
  629. { &m920x_table[1], NULL },
  630. { NULL },
  631. },
  632. }
  633. };
  634. /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
  635. *
  636. * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
  637. * TDA10046 #0 is located at i2c address 0x08
  638. * TDA10046 #1 is located at i2c address 0x0b
  639. * TDA8275A #0 is located at i2c address 0x60
  640. * TDA8275A #1 is located at i2c address 0x61
  641. */
  642. static struct dvb_usb_device_properties tvwalkertwin_properties = {
  643. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  644. .usb_ctrl = DEVICE_SPECIFIC,
  645. .firmware = "dvb-usb-tvwalkert.fw",
  646. .download_firmware = m920x_firmware_download,
  647. .rc_interval = 100,
  648. .rc_key_map = tvwalkertwin_rc_keys,
  649. .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys),
  650. .rc_query = m920x_rc_query,
  651. .size_of_priv = sizeof(struct m920x_state),
  652. .identify_state = m920x_identify_state,
  653. .num_adapters = 2,
  654. .adapter = {{
  655. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  656. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  657. .pid_filter_count = 8,
  658. .pid_filter = m920x_pid_filter,
  659. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  660. .frontend_attach = m920x_tda10046_08_frontend_attach,
  661. .tuner_attach = m920x_tda8275_60_tuner_attach,
  662. .stream = {
  663. .type = USB_BULK,
  664. .count = 8,
  665. .endpoint = 0x81,
  666. .u = {
  667. .bulk = {
  668. .buffersize = 512,
  669. }
  670. }
  671. }},{
  672. .caps = DVB_USB_ADAP_HAS_PID_FILTER |
  673. DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  674. .pid_filter_count = 8,
  675. .pid_filter = m920x_pid_filter,
  676. .pid_filter_ctrl = m920x_pid_filter_ctrl,
  677. .frontend_attach = m920x_tda10046_0b_frontend_attach,
  678. .tuner_attach = m920x_tda8275_61_tuner_attach,
  679. .stream = {
  680. .type = USB_BULK,
  681. .count = 8,
  682. .endpoint = 0x82,
  683. .u = {
  684. .bulk = {
  685. .buffersize = 512,
  686. }
  687. }
  688. },
  689. }},
  690. .i2c_algo = &m920x_i2c_algo,
  691. .num_device_descs = 1,
  692. .devices = {
  693. { .name = "LifeView TV Walker Twin DVB-T USB2.0",
  694. .cold_ids = { &m920x_table[2], NULL },
  695. .warm_ids = { &m920x_table[3], NULL },
  696. },
  697. }
  698. };
  699. static struct dvb_usb_device_properties dposh_properties = {
  700. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  701. .usb_ctrl = DEVICE_SPECIFIC,
  702. .firmware = "dvb-usb-dposh-01.fw",
  703. .download_firmware = m920x_firmware_download,
  704. .size_of_priv = sizeof(struct m920x_state),
  705. .identify_state = m920x_identify_state,
  706. .num_adapters = 1,
  707. .adapter = {{
  708. /* Hardware pid filters don't work with this device/firmware */
  709. .frontend_attach = m920x_mt352_frontend_attach,
  710. .tuner_attach = m920x_qt1010_tuner_attach,
  711. .stream = {
  712. .type = USB_BULK,
  713. .count = 8,
  714. .endpoint = 0x81,
  715. .u = {
  716. .bulk = {
  717. .buffersize = 512,
  718. }
  719. }
  720. },
  721. }},
  722. .i2c_algo = &m920x_i2c_algo,
  723. .num_device_descs = 1,
  724. .devices = {
  725. { .name = "Dposh DVB-T USB2.0",
  726. .cold_ids = { &m920x_table[4], NULL },
  727. .warm_ids = { &m920x_table[5], NULL },
  728. },
  729. }
  730. };
  731. static struct usb_driver m920x_driver = {
  732. .name = "dvb_usb_m920x",
  733. .probe = m920x_probe,
  734. .disconnect = dvb_usb_device_exit,
  735. .id_table = m920x_table,
  736. };
  737. /* module stuff */
  738. static int __init m920x_module_init(void)
  739. {
  740. int ret;
  741. if ((ret = usb_register(&m920x_driver))) {
  742. err("usb_register failed. Error number %d", ret);
  743. return ret;
  744. }
  745. return 0;
  746. }
  747. static void __exit m920x_module_exit(void)
  748. {
  749. /* deregister this driver from the USB subsystem */
  750. usb_deregister(&m920x_driver);
  751. }
  752. module_init (m920x_module_init);
  753. module_exit (m920x_module_exit);
  754. MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
  755. MODULE_DESCRIPTION("DVB Driver for ULI M920x");
  756. MODULE_VERSION("0.1");
  757. MODULE_LICENSE("GPL");
  758. /*
  759. * Local variables:
  760. * c-basic-offset: 8
  761. */