m920x.c 26 KB

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