cxusb.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  1. /* DVB USB compliant linux driver for Conexant USB reference design.
  2. *
  3. * The Conexant reference design I saw on their website was only for analogue
  4. * capturing (using the cx25842). The box I took to write this driver (reverse
  5. * engineered) is the one labeled Medion MD95700. In addition to the cx25842
  6. * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
  7. * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
  8. *
  9. * Maybe it is a little bit premature to call this driver cxusb, but I assume
  10. * the USB protocol is identical or at least inherited from the reference
  11. * design, so it can be reused for the "analogue-only" device (if it will
  12. * appear at all).
  13. *
  14. * TODO: Use the cx25840-driver for the analogue part
  15. *
  16. * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@posteo.de)
  17. * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
  18. * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
  19. *
  20. * This program is free software; you can redistribute it and/or modify it
  21. * under the terms of the GNU General Public License as published by the Free
  22. * Software Foundation, version 2.
  23. *
  24. * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
  25. */
  26. #include <media/tuner.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/slab.h>
  29. #include <linux/kernel.h>
  30. #include "cxusb.h"
  31. #include "cx22702.h"
  32. #include "lgdt330x.h"
  33. #include "mt352.h"
  34. #include "mt352_priv.h"
  35. #include "zl10353.h"
  36. #include "tuner-xc2028.h"
  37. #include "tuner-simple.h"
  38. #include "mxl5005s.h"
  39. #include "max2165.h"
  40. #include "dib7000p.h"
  41. #include "dib0070.h"
  42. #include "lgs8gxx.h"
  43. #include "atbm8830.h"
  44. #include "si2168.h"
  45. #include "si2157.h"
  46. /* debug */
  47. static int dvb_usb_cxusb_debug;
  48. module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
  49. MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
  50. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  51. #define deb_info(args...) dprintk(dvb_usb_cxusb_debug, 0x03, args)
  52. #define deb_i2c(args...) dprintk(dvb_usb_cxusb_debug, 0x02, args)
  53. static int cxusb_ctrl_msg(struct dvb_usb_device *d,
  54. u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  55. {
  56. struct cxusb_state *st = d->priv;
  57. int ret;
  58. if (1 + wlen > MAX_XFER_SIZE) {
  59. warn("i2c wr: len=%d is too big!\n", wlen);
  60. return -EOPNOTSUPP;
  61. }
  62. if (rlen > MAX_XFER_SIZE) {
  63. warn("i2c rd: len=%d is too big!\n", rlen);
  64. return -EOPNOTSUPP;
  65. }
  66. mutex_lock(&d->data_mutex);
  67. st->data[0] = cmd;
  68. memcpy(&st->data[1], wbuf, wlen);
  69. ret = dvb_usb_generic_rw(d, st->data, 1 + wlen, st->data, rlen, 0);
  70. if (!ret && rbuf && rlen)
  71. memcpy(rbuf, st->data, rlen);
  72. mutex_unlock(&d->data_mutex);
  73. return ret;
  74. }
  75. /* GPIO */
  76. static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
  77. {
  78. struct cxusb_state *st = d->priv;
  79. u8 o[2], i;
  80. if (st->gpio_write_state[GPIO_TUNER] == onoff)
  81. return;
  82. o[0] = GPIO_TUNER;
  83. o[1] = onoff;
  84. cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
  85. if (i != 0x01)
  86. deb_info("gpio_write failed.\n");
  87. st->gpio_write_state[GPIO_TUNER] = onoff;
  88. }
  89. static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
  90. u8 newval)
  91. {
  92. u8 o[2], gpio_state;
  93. int rc;
  94. o[0] = 0xff & ~changemask; /* mask of bits to keep */
  95. o[1] = newval & changemask; /* new values for bits */
  96. rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
  97. if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
  98. deb_info("bluebird_gpio_write failed.\n");
  99. return rc < 0 ? rc : gpio_state;
  100. }
  101. static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
  102. {
  103. cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
  104. msleep(5);
  105. cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
  106. }
  107. static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
  108. {
  109. cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
  110. }
  111. static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
  112. u8 addr, int onoff)
  113. {
  114. u8 o[2] = {addr, onoff};
  115. u8 i;
  116. int rc;
  117. rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
  118. if (rc < 0)
  119. return rc;
  120. if (i == 0x01)
  121. return 0;
  122. else {
  123. deb_info("gpio_write failed.\n");
  124. return -EIO;
  125. }
  126. }
  127. /* I2C */
  128. static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  129. int num)
  130. {
  131. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  132. int ret;
  133. int i;
  134. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  135. return -EAGAIN;
  136. for (i = 0; i < num; i++) {
  137. if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_MEDION)
  138. switch (msg[i].addr) {
  139. case 0x63:
  140. cxusb_gpio_tuner(d, 0);
  141. break;
  142. default:
  143. cxusb_gpio_tuner(d, 1);
  144. break;
  145. }
  146. if (msg[i].flags & I2C_M_RD) {
  147. /* read only */
  148. u8 obuf[3], ibuf[MAX_XFER_SIZE];
  149. if (1 + msg[i].len > sizeof(ibuf)) {
  150. warn("i2c rd: len=%d is too big!\n",
  151. msg[i].len);
  152. ret = -EOPNOTSUPP;
  153. goto unlock;
  154. }
  155. obuf[0] = 0;
  156. obuf[1] = msg[i].len;
  157. obuf[2] = msg[i].addr;
  158. if (cxusb_ctrl_msg(d, CMD_I2C_READ,
  159. obuf, 3,
  160. ibuf, 1+msg[i].len) < 0) {
  161. warn("i2c read failed");
  162. break;
  163. }
  164. memcpy(msg[i].buf, &ibuf[1], msg[i].len);
  165. } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
  166. msg[i].addr == msg[i+1].addr) {
  167. /* write to then read from same address */
  168. u8 obuf[MAX_XFER_SIZE], ibuf[MAX_XFER_SIZE];
  169. if (3 + msg[i].len > sizeof(obuf)) {
  170. warn("i2c wr: len=%d is too big!\n",
  171. msg[i].len);
  172. ret = -EOPNOTSUPP;
  173. goto unlock;
  174. }
  175. if (1 + msg[i + 1].len > sizeof(ibuf)) {
  176. warn("i2c rd: len=%d is too big!\n",
  177. msg[i + 1].len);
  178. ret = -EOPNOTSUPP;
  179. goto unlock;
  180. }
  181. obuf[0] = msg[i].len;
  182. obuf[1] = msg[i+1].len;
  183. obuf[2] = msg[i].addr;
  184. memcpy(&obuf[3], msg[i].buf, msg[i].len);
  185. if (cxusb_ctrl_msg(d, CMD_I2C_READ,
  186. obuf, 3+msg[i].len,
  187. ibuf, 1+msg[i+1].len) < 0)
  188. break;
  189. if (ibuf[0] != 0x08)
  190. deb_i2c("i2c read may have failed\n");
  191. memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
  192. i++;
  193. } else {
  194. /* write only */
  195. u8 obuf[MAX_XFER_SIZE], ibuf;
  196. if (2 + msg[i].len > sizeof(obuf)) {
  197. warn("i2c wr: len=%d is too big!\n",
  198. msg[i].len);
  199. ret = -EOPNOTSUPP;
  200. goto unlock;
  201. }
  202. obuf[0] = msg[i].addr;
  203. obuf[1] = msg[i].len;
  204. memcpy(&obuf[2], msg[i].buf, msg[i].len);
  205. if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
  206. 2+msg[i].len, &ibuf,1) < 0)
  207. break;
  208. if (ibuf != 0x08)
  209. deb_i2c("i2c write may have failed\n");
  210. }
  211. }
  212. if (i == num)
  213. ret = num;
  214. else
  215. ret = -EREMOTEIO;
  216. unlock:
  217. mutex_unlock(&d->i2c_mutex);
  218. return ret;
  219. }
  220. static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
  221. {
  222. return I2C_FUNC_I2C;
  223. }
  224. static struct i2c_algorithm cxusb_i2c_algo = {
  225. .master_xfer = cxusb_i2c_xfer,
  226. .functionality = cxusb_i2c_func,
  227. };
  228. static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
  229. {
  230. u8 b = 0;
  231. if (onoff)
  232. return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
  233. else
  234. return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
  235. }
  236. static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
  237. {
  238. int ret;
  239. if (!onoff)
  240. return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
  241. if (d->state == DVB_USB_STATE_INIT &&
  242. usb_set_interface(d->udev, 0, 0) < 0)
  243. err("set interface failed");
  244. do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
  245. !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
  246. !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
  247. if (!ret) {
  248. /* FIXME: We don't know why, but we need to configure the
  249. * lgdt3303 with the register settings below on resume */
  250. int i;
  251. u8 buf;
  252. static const u8 bufs[] = {
  253. 0x0e, 0x2, 0x00, 0x7f,
  254. 0x0e, 0x2, 0x02, 0xfe,
  255. 0x0e, 0x2, 0x02, 0x01,
  256. 0x0e, 0x2, 0x00, 0x03,
  257. 0x0e, 0x2, 0x0d, 0x40,
  258. 0x0e, 0x2, 0x0e, 0x87,
  259. 0x0e, 0x2, 0x0f, 0x8e,
  260. 0x0e, 0x2, 0x10, 0x01,
  261. 0x0e, 0x2, 0x14, 0xd7,
  262. 0x0e, 0x2, 0x47, 0x88,
  263. };
  264. msleep(20);
  265. for (i = 0; i < ARRAY_SIZE(bufs); i += 4 / sizeof(u8)) {
  266. ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
  267. bufs+i, 4, &buf, 1);
  268. if (ret)
  269. break;
  270. if (buf != 0x8)
  271. return -EREMOTEIO;
  272. }
  273. }
  274. return ret;
  275. }
  276. static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
  277. {
  278. u8 b = 0;
  279. if (onoff)
  280. return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
  281. else
  282. return 0;
  283. }
  284. static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
  285. {
  286. int rc = 0;
  287. rc = cxusb_power_ctrl(d, onoff);
  288. if (!onoff)
  289. cxusb_nano2_led(d, 0);
  290. return rc;
  291. }
  292. static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
  293. {
  294. int ret;
  295. u8 b;
  296. ret = cxusb_power_ctrl(d, onoff);
  297. if (!onoff)
  298. return ret;
  299. msleep(128);
  300. cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
  301. msleep(100);
  302. return ret;
  303. }
  304. static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  305. {
  306. u8 buf[2] = { 0x03, 0x00 };
  307. if (onoff)
  308. cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);
  309. else
  310. cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
  311. return 0;
  312. }
  313. static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  314. {
  315. if (onoff)
  316. cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);
  317. else
  318. cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
  319. NULL, 0, NULL, 0);
  320. return 0;
  321. }
  322. static int cxusb_read_status(struct dvb_frontend *fe,
  323. enum fe_status *status)
  324. {
  325. struct dvb_usb_adapter *adap = (struct dvb_usb_adapter *)fe->dvb->priv;
  326. struct cxusb_state *state = (struct cxusb_state *)adap->dev->priv;
  327. int ret;
  328. ret = state->fe_read_status(fe, status);
  329. /* it need resync slave fifo when signal change from unlock to lock.*/
  330. if ((*status & FE_HAS_LOCK) && (!state->last_lock)) {
  331. mutex_lock(&state->stream_mutex);
  332. cxusb_streaming_ctrl(adap, 1);
  333. mutex_unlock(&state->stream_mutex);
  334. }
  335. state->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
  336. return ret;
  337. }
  338. static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
  339. {
  340. int ep = d->props.generic_bulk_ctrl_endpoint;
  341. const int timeout = 100;
  342. const int junk_len = 32;
  343. u8 *junk;
  344. int rd_count;
  345. /* Discard remaining data in video pipe */
  346. junk = kmalloc(junk_len, GFP_KERNEL);
  347. if (!junk)
  348. return;
  349. while (1) {
  350. if (usb_bulk_msg(d->udev,
  351. usb_rcvbulkpipe(d->udev, ep),
  352. junk, junk_len, &rd_count, timeout) < 0)
  353. break;
  354. if (!rd_count)
  355. break;
  356. }
  357. kfree(junk);
  358. }
  359. static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
  360. {
  361. struct usb_data_stream_properties *p = &d->props.adapter[0].fe[0].stream;
  362. const int timeout = 100;
  363. const int junk_len = p->u.bulk.buffersize;
  364. u8 *junk;
  365. int rd_count;
  366. /* Discard remaining data in video pipe */
  367. junk = kmalloc(junk_len, GFP_KERNEL);
  368. if (!junk)
  369. return;
  370. while (1) {
  371. if (usb_bulk_msg(d->udev,
  372. usb_rcvbulkpipe(d->udev, p->endpoint),
  373. junk, junk_len, &rd_count, timeout) < 0)
  374. break;
  375. if (!rd_count)
  376. break;
  377. }
  378. kfree(junk);
  379. }
  380. static int cxusb_d680_dmb_streaming_ctrl(
  381. struct dvb_usb_adapter *adap, int onoff)
  382. {
  383. if (onoff) {
  384. u8 buf[2] = { 0x03, 0x00 };
  385. cxusb_d680_dmb_drain_video(adap->dev);
  386. return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
  387. buf, sizeof(buf), NULL, 0);
  388. } else {
  389. int ret = cxusb_ctrl_msg(adap->dev,
  390. CMD_STREAMING_OFF, NULL, 0, NULL, 0);
  391. return ret;
  392. }
  393. }
  394. static int cxusb_rc_query(struct dvb_usb_device *d)
  395. {
  396. u8 ircode[4];
  397. cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
  398. if (ircode[2] || ircode[3])
  399. rc_keydown(d->rc_dev, RC_PROTO_NEC,
  400. RC_SCANCODE_NEC(~ircode[2] & 0xff, ircode[3]), 0);
  401. return 0;
  402. }
  403. static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d)
  404. {
  405. u8 ircode[4];
  406. struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
  407. .buf = ircode, .len = 4 };
  408. if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
  409. return 0;
  410. if (ircode[1] || ircode[2])
  411. rc_keydown(d->rc_dev, RC_PROTO_NEC,
  412. RC_SCANCODE_NEC(~ircode[1] & 0xff, ircode[2]), 0);
  413. return 0;
  414. }
  415. static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d)
  416. {
  417. u8 ircode[2];
  418. if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
  419. return 0;
  420. if (ircode[0] || ircode[1])
  421. rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN,
  422. RC_SCANCODE_RC5(ircode[0], ircode[1]), 0);
  423. return 0;
  424. }
  425. static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
  426. {
  427. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
  428. static u8 reset [] = { RESET, 0x80 };
  429. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  430. static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
  431. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  432. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  433. mt352_write(fe, clock_config, sizeof(clock_config));
  434. udelay(200);
  435. mt352_write(fe, reset, sizeof(reset));
  436. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  437. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  438. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  439. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  440. return 0;
  441. }
  442. static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
  443. { /* used in both lgz201 and th7579 */
  444. static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x29 };
  445. static u8 reset [] = { RESET, 0x80 };
  446. static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
  447. static u8 agc_cfg [] = { AGC_TARGET, 0x24, 0x20 };
  448. static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
  449. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  450. mt352_write(fe, clock_config, sizeof(clock_config));
  451. udelay(200);
  452. mt352_write(fe, reset, sizeof(reset));
  453. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  454. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  455. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  456. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  457. return 0;
  458. }
  459. static struct cx22702_config cxusb_cx22702_config = {
  460. .demod_address = 0x63,
  461. .output_mode = CX22702_PARALLEL_OUTPUT,
  462. };
  463. static struct lgdt330x_config cxusb_lgdt3303_config = {
  464. .demod_chip = LGDT3303,
  465. };
  466. static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
  467. .demod_chip = LGDT3303,
  468. .clock_polarity_flip = 2,
  469. };
  470. static struct mt352_config cxusb_dee1601_config = {
  471. .demod_address = 0x0f,
  472. .demod_init = cxusb_dee1601_demod_init,
  473. };
  474. static struct zl10353_config cxusb_zl10353_dee1601_config = {
  475. .demod_address = 0x0f,
  476. .parallel_ts = 1,
  477. };
  478. static struct mt352_config cxusb_mt352_config = {
  479. /* used in both lgz201 and th7579 */
  480. .demod_address = 0x0f,
  481. .demod_init = cxusb_mt352_demod_init,
  482. };
  483. static struct zl10353_config cxusb_zl10353_xc3028_config = {
  484. .demod_address = 0x0f,
  485. .if2 = 45600,
  486. .no_tuner = 1,
  487. .parallel_ts = 1,
  488. };
  489. static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
  490. .demod_address = 0x0f,
  491. .if2 = 45600,
  492. .no_tuner = 1,
  493. .parallel_ts = 1,
  494. .disable_i2c_gate_ctrl = 1,
  495. };
  496. static struct mt352_config cxusb_mt352_xc3028_config = {
  497. .demod_address = 0x0f,
  498. .if2 = 4560,
  499. .no_tuner = 1,
  500. .demod_init = cxusb_mt352_demod_init,
  501. };
  502. /* FIXME: needs tweaking */
  503. static struct mxl5005s_config aver_a868r_tuner = {
  504. .i2c_address = 0x63,
  505. .if_freq = 6000000UL,
  506. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  507. .agc_mode = MXL_SINGLE_AGC,
  508. .tracking_filter = MXL_TF_C,
  509. .rssi_enable = MXL_RSSI_ENABLE,
  510. .cap_select = MXL_CAP_SEL_ENABLE,
  511. .div_out = MXL_DIV_OUT_4,
  512. .clock_out = MXL_CLOCK_OUT_DISABLE,
  513. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  514. .top = MXL5005S_TOP_25P2,
  515. .mod_mode = MXL_DIGITAL_MODE,
  516. .if_mode = MXL_ZERO_IF,
  517. .AgcMasterByte = 0x00,
  518. };
  519. /* FIXME: needs tweaking */
  520. static struct mxl5005s_config d680_dmb_tuner = {
  521. .i2c_address = 0x63,
  522. .if_freq = 36125000UL,
  523. .xtal_freq = CRYSTAL_FREQ_16000000HZ,
  524. .agc_mode = MXL_SINGLE_AGC,
  525. .tracking_filter = MXL_TF_C,
  526. .rssi_enable = MXL_RSSI_ENABLE,
  527. .cap_select = MXL_CAP_SEL_ENABLE,
  528. .div_out = MXL_DIV_OUT_4,
  529. .clock_out = MXL_CLOCK_OUT_DISABLE,
  530. .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
  531. .top = MXL5005S_TOP_25P2,
  532. .mod_mode = MXL_DIGITAL_MODE,
  533. .if_mode = MXL_ZERO_IF,
  534. .AgcMasterByte = 0x00,
  535. };
  536. static struct max2165_config mygica_d689_max2165_cfg = {
  537. .i2c_address = 0x60,
  538. .osc_clk = 20
  539. };
  540. /* Callbacks for DVB USB */
  541. static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
  542. {
  543. dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
  544. &adap->dev->i2c_adap, 0x61,
  545. TUNER_PHILIPS_FMD1216ME_MK3);
  546. return 0;
  547. }
  548. static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
  549. {
  550. dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
  551. NULL, DVB_PLL_THOMSON_DTT7579);
  552. return 0;
  553. }
  554. static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
  555. {
  556. dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_LG_Z201);
  557. return 0;
  558. }
  559. static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
  560. {
  561. dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
  562. NULL, DVB_PLL_THOMSON_DTT7579);
  563. return 0;
  564. }
  565. static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
  566. {
  567. dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
  568. &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
  569. return 0;
  570. }
  571. static int dvico_bluebird_xc2028_callback(void *ptr, int component,
  572. int command, int arg)
  573. {
  574. struct dvb_usb_adapter *adap = ptr;
  575. struct dvb_usb_device *d = adap->dev;
  576. switch (command) {
  577. case XC2028_TUNER_RESET:
  578. deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
  579. cxusb_bluebird_gpio_pulse(d, 0x01, 1);
  580. break;
  581. case XC2028_RESET_CLK:
  582. deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
  583. break;
  584. case XC2028_I2C_FLUSH:
  585. break;
  586. default:
  587. deb_info("%s: unknown command %d, arg %d\n", __func__,
  588. command, arg);
  589. return -EINVAL;
  590. }
  591. return 0;
  592. }
  593. static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
  594. {
  595. struct dvb_frontend *fe;
  596. struct xc2028_config cfg = {
  597. .i2c_adap = &adap->dev->i2c_adap,
  598. .i2c_addr = 0x61,
  599. };
  600. static struct xc2028_ctrl ctl = {
  601. .fname = XC2028_DEFAULT_FIRMWARE,
  602. .max_len = 64,
  603. .demod = XC3028_FE_ZARLINK456,
  604. };
  605. /* FIXME: generalize & move to common area */
  606. adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
  607. fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
  608. if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
  609. return -EIO;
  610. fe->ops.tuner_ops.set_config(fe, &ctl);
  611. return 0;
  612. }
  613. static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
  614. {
  615. dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
  616. &adap->dev->i2c_adap, &aver_a868r_tuner);
  617. return 0;
  618. }
  619. static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
  620. {
  621. struct dvb_frontend *fe;
  622. fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
  623. &adap->dev->i2c_adap, &d680_dmb_tuner);
  624. return (fe == NULL) ? -EIO : 0;
  625. }
  626. static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
  627. {
  628. struct dvb_frontend *fe;
  629. fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
  630. &adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
  631. return (fe == NULL) ? -EIO : 0;
  632. }
  633. static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
  634. {
  635. u8 b;
  636. if (usb_set_interface(adap->dev->udev, 0, 6) < 0)
  637. err("set interface failed");
  638. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
  639. adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
  640. &adap->dev->i2c_adap);
  641. if ((adap->fe_adap[0].fe) != NULL)
  642. return 0;
  643. return -EIO;
  644. }
  645. static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
  646. {
  647. if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
  648. err("set interface failed");
  649. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  650. adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
  651. &cxusb_lgdt3303_config,
  652. 0x0e,
  653. &adap->dev->i2c_adap);
  654. if ((adap->fe_adap[0].fe) != NULL)
  655. return 0;
  656. return -EIO;
  657. }
  658. static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
  659. {
  660. adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
  661. &cxusb_aver_lgdt3303_config,
  662. 0x0e,
  663. &adap->dev->i2c_adap);
  664. if (adap->fe_adap[0].fe != NULL)
  665. return 0;
  666. return -EIO;
  667. }
  668. static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
  669. {
  670. /* used in both lgz201 and th7579 */
  671. if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
  672. err("set interface failed");
  673. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  674. adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
  675. &adap->dev->i2c_adap);
  676. if ((adap->fe_adap[0].fe) != NULL)
  677. return 0;
  678. return -EIO;
  679. }
  680. static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
  681. {
  682. if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
  683. err("set interface failed");
  684. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  685. adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
  686. &adap->dev->i2c_adap);
  687. if ((adap->fe_adap[0].fe) != NULL)
  688. return 0;
  689. adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
  690. &cxusb_zl10353_dee1601_config,
  691. &adap->dev->i2c_adap);
  692. if ((adap->fe_adap[0].fe) != NULL)
  693. return 0;
  694. return -EIO;
  695. }
  696. static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
  697. {
  698. u8 ircode[4];
  699. int i;
  700. struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
  701. .buf = ircode, .len = 4 };
  702. if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
  703. err("set interface failed");
  704. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  705. /* reset the tuner and demodulator */
  706. cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
  707. cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
  708. cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
  709. adap->fe_adap[0].fe =
  710. dvb_attach(zl10353_attach,
  711. &cxusb_zl10353_xc3028_config_no_i2c_gate,
  712. &adap->dev->i2c_adap);
  713. if ((adap->fe_adap[0].fe) == NULL)
  714. return -EIO;
  715. /* try to determine if there is no IR decoder on the I2C bus */
  716. for (i = 0; adap->dev->props.rc.core.rc_codes && i < 5; i++) {
  717. msleep(20);
  718. if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
  719. goto no_IR;
  720. if (ircode[0] == 0 && ircode[1] == 0)
  721. continue;
  722. if (ircode[2] + ircode[3] != 0xff) {
  723. no_IR:
  724. adap->dev->props.rc.core.rc_codes = NULL;
  725. info("No IR receiver detected on this device.");
  726. break;
  727. }
  728. }
  729. return 0;
  730. }
  731. static struct dibx000_agc_config dib7070_agc_config = {
  732. .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
  733. /*
  734. * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
  735. * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
  736. * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
  737. */
  738. .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
  739. (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
  740. .inv_gain = 600,
  741. .time_stabiliz = 10,
  742. .alpha_level = 0,
  743. .thlock = 118,
  744. .wbd_inv = 0,
  745. .wbd_ref = 3530,
  746. .wbd_sel = 1,
  747. .wbd_alpha = 5,
  748. .agc1_max = 65535,
  749. .agc1_min = 0,
  750. .agc2_max = 65535,
  751. .agc2_min = 0,
  752. .agc1_pt1 = 0,
  753. .agc1_pt2 = 40,
  754. .agc1_pt3 = 183,
  755. .agc1_slope1 = 206,
  756. .agc1_slope2 = 255,
  757. .agc2_pt1 = 72,
  758. .agc2_pt2 = 152,
  759. .agc2_slope1 = 88,
  760. .agc2_slope2 = 90,
  761. .alpha_mant = 17,
  762. .alpha_exp = 27,
  763. .beta_mant = 23,
  764. .beta_exp = 51,
  765. .perform_agc_softsplit = 0,
  766. };
  767. static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
  768. .internal = 60000,
  769. .sampling = 15000,
  770. .pll_prediv = 1,
  771. .pll_ratio = 20,
  772. .pll_range = 3,
  773. .pll_reset = 1,
  774. .pll_bypass = 0,
  775. .enable_refdiv = 0,
  776. .bypclk_div = 0,
  777. .IO_CLK_en_core = 1,
  778. .ADClkSrc = 1,
  779. .modulo = 2,
  780. /* refsel, sel, freq_15k */
  781. .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
  782. .ifreq = (0 << 25) | 0,
  783. .timf = 20452225,
  784. .xtal_hz = 12000000,
  785. };
  786. static struct dib7000p_config cxusb_dualdig4_rev2_config = {
  787. .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
  788. .output_mpeg2_in_188_bytes = 1,
  789. .agc_config_count = 1,
  790. .agc = &dib7070_agc_config,
  791. .bw = &dib7070_bw_config_12_mhz,
  792. .tuner_is_baseband = 1,
  793. .spur_protect = 1,
  794. .gpio_dir = 0xfcef,
  795. .gpio_val = 0x0110,
  796. .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
  797. .hostbus_diversity = 1,
  798. };
  799. struct dib0700_adapter_state {
  800. int (*set_param_save)(struct dvb_frontend *);
  801. struct dib7000p_ops dib7000p_ops;
  802. };
  803. static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
  804. {
  805. struct dib0700_adapter_state *state = adap->priv;
  806. if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
  807. err("set interface failed");
  808. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  809. cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
  810. if (!dvb_attach(dib7000p_attach, &state->dib7000p_ops))
  811. return -ENODEV;
  812. if (state->dib7000p_ops.i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
  813. &cxusb_dualdig4_rev2_config) < 0) {
  814. printk(KERN_WARNING "Unable to enumerate dib7000p\n");
  815. return -ENODEV;
  816. }
  817. adap->fe_adap[0].fe = state->dib7000p_ops.init(&adap->dev->i2c_adap, 0x80,
  818. &cxusb_dualdig4_rev2_config);
  819. if (adap->fe_adap[0].fe == NULL)
  820. return -EIO;
  821. return 0;
  822. }
  823. static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
  824. {
  825. struct dvb_usb_adapter *adap = fe->dvb->priv;
  826. struct dib0700_adapter_state *state = adap->priv;
  827. return state->dib7000p_ops.set_gpio(fe, 8, 0, !onoff);
  828. }
  829. static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
  830. {
  831. return 0;
  832. }
  833. static struct dib0070_config dib7070p_dib0070_config = {
  834. .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
  835. .reset = dib7070_tuner_reset,
  836. .sleep = dib7070_tuner_sleep,
  837. .clock_khz = 12000,
  838. };
  839. static int dib7070_set_param_override(struct dvb_frontend *fe)
  840. {
  841. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  842. struct dvb_usb_adapter *adap = fe->dvb->priv;
  843. struct dib0700_adapter_state *state = adap->priv;
  844. u16 offset;
  845. u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
  846. switch (band) {
  847. case BAND_VHF: offset = 950; break;
  848. default:
  849. case BAND_UHF: offset = 550; break;
  850. }
  851. state->dib7000p_ops.set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
  852. return state->set_param_save(fe);
  853. }
  854. static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
  855. {
  856. struct dib0700_adapter_state *st = adap->priv;
  857. struct i2c_adapter *tun_i2c;
  858. /*
  859. * No need to call dvb7000p_attach here, as it was called
  860. * already, as frontend_attach method is called first, and
  861. * tuner_attach is only called on sucess.
  862. */
  863. tun_i2c = st->dib7000p_ops.get_i2c_master(adap->fe_adap[0].fe,
  864. DIBX000_I2C_INTERFACE_TUNER, 1);
  865. if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
  866. &dib7070p_dib0070_config) == NULL)
  867. return -ENODEV;
  868. st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
  869. adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
  870. return 0;
  871. }
  872. static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
  873. {
  874. if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
  875. err("set interface failed");
  876. cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
  877. /* reset the tuner and demodulator */
  878. cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
  879. cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
  880. cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
  881. adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
  882. &cxusb_zl10353_xc3028_config,
  883. &adap->dev->i2c_adap);
  884. if ((adap->fe_adap[0].fe) != NULL)
  885. return 0;
  886. adap->fe_adap[0].fe = dvb_attach(mt352_attach,
  887. &cxusb_mt352_xc3028_config,
  888. &adap->dev->i2c_adap);
  889. if ((adap->fe_adap[0].fe) != NULL)
  890. return 0;
  891. return -EIO;
  892. }
  893. static struct lgs8gxx_config d680_lgs8gl5_cfg = {
  894. .prod = LGS8GXX_PROD_LGS8GL5,
  895. .demod_address = 0x19,
  896. .serial_ts = 0,
  897. .ts_clk_pol = 0,
  898. .ts_clk_gated = 1,
  899. .if_clk_freq = 30400, /* 30.4 MHz */
  900. .if_freq = 5725, /* 5.725 MHz */
  901. .if_neg_center = 0,
  902. .ext_adc = 0,
  903. .adc_signed = 0,
  904. .if_neg_edge = 0,
  905. };
  906. static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
  907. {
  908. struct dvb_usb_device *d = adap->dev;
  909. int n;
  910. /* Select required USB configuration */
  911. if (usb_set_interface(d->udev, 0, 0) < 0)
  912. err("set interface failed");
  913. /* Unblock all USB pipes */
  914. usb_clear_halt(d->udev,
  915. usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  916. usb_clear_halt(d->udev,
  917. usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  918. usb_clear_halt(d->udev,
  919. usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
  920. /* Drain USB pipes to avoid hang after reboot */
  921. for (n = 0; n < 5; n++) {
  922. cxusb_d680_dmb_drain_message(d);
  923. cxusb_d680_dmb_drain_video(d);
  924. msleep(200);
  925. }
  926. /* Reset the tuner */
  927. if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
  928. err("clear tuner gpio failed");
  929. return -EIO;
  930. }
  931. msleep(100);
  932. if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
  933. err("set tuner gpio failed");
  934. return -EIO;
  935. }
  936. msleep(100);
  937. /* Attach frontend */
  938. adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
  939. if (adap->fe_adap[0].fe == NULL)
  940. return -EIO;
  941. return 0;
  942. }
  943. static struct atbm8830_config mygica_d689_atbm8830_cfg = {
  944. .prod = ATBM8830_PROD_8830,
  945. .demod_address = 0x40,
  946. .serial_ts = 0,
  947. .ts_sampling_edge = 1,
  948. .ts_clk_gated = 0,
  949. .osc_clk_freq = 30400, /* in kHz */
  950. .if_freq = 0, /* zero IF */
  951. .zif_swap_iq = 1,
  952. .agc_min = 0x2E,
  953. .agc_max = 0x90,
  954. .agc_hold_loop = 0,
  955. };
  956. static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
  957. {
  958. struct dvb_usb_device *d = adap->dev;
  959. /* Select required USB configuration */
  960. if (usb_set_interface(d->udev, 0, 0) < 0)
  961. err("set interface failed");
  962. /* Unblock all USB pipes */
  963. usb_clear_halt(d->udev,
  964. usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  965. usb_clear_halt(d->udev,
  966. usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  967. usb_clear_halt(d->udev,
  968. usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
  969. /* Reset the tuner */
  970. if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
  971. err("clear tuner gpio failed");
  972. return -EIO;
  973. }
  974. msleep(100);
  975. if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
  976. err("set tuner gpio failed");
  977. return -EIO;
  978. }
  979. msleep(100);
  980. /* Attach frontend */
  981. adap->fe_adap[0].fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
  982. &d->i2c_adap);
  983. if (adap->fe_adap[0].fe == NULL)
  984. return -EIO;
  985. return 0;
  986. }
  987. static int cxusb_mygica_t230_frontend_attach(struct dvb_usb_adapter *adap)
  988. {
  989. struct dvb_usb_device *d = adap->dev;
  990. struct cxusb_state *st = d->priv;
  991. struct i2c_adapter *adapter;
  992. struct i2c_client *client_demod;
  993. struct i2c_client *client_tuner;
  994. struct i2c_board_info info;
  995. struct si2168_config si2168_config;
  996. struct si2157_config si2157_config;
  997. /* Select required USB configuration */
  998. if (usb_set_interface(d->udev, 0, 0) < 0)
  999. err("set interface failed");
  1000. /* Unblock all USB pipes */
  1001. usb_clear_halt(d->udev,
  1002. usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  1003. usb_clear_halt(d->udev,
  1004. usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
  1005. usb_clear_halt(d->udev,
  1006. usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
  1007. /* attach frontend */
  1008. si2168_config.i2c_adapter = &adapter;
  1009. si2168_config.fe = &adap->fe_adap[0].fe;
  1010. si2168_config.ts_mode = SI2168_TS_PARALLEL;
  1011. si2168_config.ts_clock_inv = 1;
  1012. memset(&info, 0, sizeof(struct i2c_board_info));
  1013. strlcpy(info.type, "si2168", I2C_NAME_SIZE);
  1014. info.addr = 0x64;
  1015. info.platform_data = &si2168_config;
  1016. request_module(info.type);
  1017. client_demod = i2c_new_device(&d->i2c_adap, &info);
  1018. if (client_demod == NULL || client_demod->dev.driver == NULL)
  1019. return -ENODEV;
  1020. if (!try_module_get(client_demod->dev.driver->owner)) {
  1021. i2c_unregister_device(client_demod);
  1022. return -ENODEV;
  1023. }
  1024. st->i2c_client_demod = client_demod;
  1025. /* attach tuner */
  1026. memset(&si2157_config, 0, sizeof(si2157_config));
  1027. si2157_config.fe = adap->fe_adap[0].fe;
  1028. si2157_config.if_port = 1;
  1029. memset(&info, 0, sizeof(struct i2c_board_info));
  1030. strlcpy(info.type, "si2157", I2C_NAME_SIZE);
  1031. info.addr = 0x60;
  1032. info.platform_data = &si2157_config;
  1033. request_module(info.type);
  1034. client_tuner = i2c_new_device(adapter, &info);
  1035. if (client_tuner == NULL || client_tuner->dev.driver == NULL) {
  1036. module_put(client_demod->dev.driver->owner);
  1037. i2c_unregister_device(client_demod);
  1038. return -ENODEV;
  1039. }
  1040. if (!try_module_get(client_tuner->dev.driver->owner)) {
  1041. i2c_unregister_device(client_tuner);
  1042. module_put(client_demod->dev.driver->owner);
  1043. i2c_unregister_device(client_demod);
  1044. return -ENODEV;
  1045. }
  1046. st->i2c_client_tuner = client_tuner;
  1047. /* hook fe: need to resync the slave fifo when signal locks. */
  1048. mutex_init(&st->stream_mutex);
  1049. st->last_lock = 0;
  1050. st->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
  1051. adap->fe_adap[0].fe->ops.read_status = cxusb_read_status;
  1052. return 0;
  1053. }
  1054. /*
  1055. * DViCO has shipped two devices with the same USB ID, but only one of them
  1056. * needs a firmware download. Check the device class details to see if they
  1057. * have non-default values to decide whether the device is actually cold or
  1058. * not, and forget a match if it turns out we selected the wrong device.
  1059. */
  1060. static int bluebird_fx2_identify_state(struct usb_device *udev,
  1061. struct dvb_usb_device_properties *props,
  1062. struct dvb_usb_device_description **desc,
  1063. int *cold)
  1064. {
  1065. int wascold = *cold;
  1066. *cold = udev->descriptor.bDeviceClass == 0xff &&
  1067. udev->descriptor.bDeviceSubClass == 0xff &&
  1068. udev->descriptor.bDeviceProtocol == 0xff;
  1069. if (*cold && !wascold)
  1070. *desc = NULL;
  1071. return 0;
  1072. }
  1073. /*
  1074. * DViCO bluebird firmware needs the "warm" product ID to be patched into the
  1075. * firmware file before download.
  1076. */
  1077. static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
  1078. static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
  1079. const struct firmware *fw)
  1080. {
  1081. int pos;
  1082. for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
  1083. int idoff = dvico_firmware_id_offsets[pos];
  1084. if (fw->size < idoff + 4)
  1085. continue;
  1086. if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
  1087. fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
  1088. struct firmware new_fw;
  1089. u8 *new_fw_data = vmalloc(fw->size);
  1090. int ret;
  1091. if (!new_fw_data)
  1092. return -ENOMEM;
  1093. memcpy(new_fw_data, fw->data, fw->size);
  1094. new_fw.size = fw->size;
  1095. new_fw.data = new_fw_data;
  1096. new_fw_data[idoff + 2] =
  1097. le16_to_cpu(udev->descriptor.idProduct) + 1;
  1098. new_fw_data[idoff + 3] =
  1099. le16_to_cpu(udev->descriptor.idProduct) >> 8;
  1100. ret = usb_cypress_load_firmware(udev, &new_fw,
  1101. CYPRESS_FX2);
  1102. vfree(new_fw_data);
  1103. return ret;
  1104. }
  1105. }
  1106. return -EINVAL;
  1107. }
  1108. /* DVB USB Driver stuff */
  1109. static struct dvb_usb_device_properties cxusb_medion_properties;
  1110. static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
  1111. static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
  1112. static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
  1113. static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
  1114. static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
  1115. static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
  1116. static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
  1117. static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
  1118. static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
  1119. static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
  1120. static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
  1121. static struct dvb_usb_device_properties cxusb_mygica_t230_properties;
  1122. static int cxusb_probe(struct usb_interface *intf,
  1123. const struct usb_device_id *id)
  1124. {
  1125. if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,
  1126. THIS_MODULE, NULL, adapter_nr) ||
  1127. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,
  1128. THIS_MODULE, NULL, adapter_nr) ||
  1129. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,
  1130. THIS_MODULE, NULL, adapter_nr) ||
  1131. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,
  1132. THIS_MODULE, NULL, adapter_nr) ||
  1133. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,
  1134. THIS_MODULE, NULL, adapter_nr) ||
  1135. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,
  1136. THIS_MODULE, NULL, adapter_nr) ||
  1137. 0 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,
  1138. THIS_MODULE, NULL, adapter_nr) ||
  1139. 0 == dvb_usb_device_init(intf,
  1140. &cxusb_bluebird_nano2_needsfirmware_properties,
  1141. THIS_MODULE, NULL, adapter_nr) ||
  1142. 0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
  1143. THIS_MODULE, NULL, adapter_nr) ||
  1144. 0 == dvb_usb_device_init(intf,
  1145. &cxusb_bluebird_dualdig4_rev2_properties,
  1146. THIS_MODULE, NULL, adapter_nr) ||
  1147. 0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
  1148. THIS_MODULE, NULL, adapter_nr) ||
  1149. 0 == dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
  1150. THIS_MODULE, NULL, adapter_nr) ||
  1151. 0 == dvb_usb_device_init(intf, &cxusb_mygica_t230_properties,
  1152. THIS_MODULE, NULL, adapter_nr) ||
  1153. 0)
  1154. return 0;
  1155. return -EINVAL;
  1156. }
  1157. static void cxusb_disconnect(struct usb_interface *intf)
  1158. {
  1159. struct dvb_usb_device *d = usb_get_intfdata(intf);
  1160. struct cxusb_state *st = d->priv;
  1161. struct i2c_client *client;
  1162. /* remove I2C client for tuner */
  1163. client = st->i2c_client_tuner;
  1164. if (client) {
  1165. module_put(client->dev.driver->owner);
  1166. i2c_unregister_device(client);
  1167. }
  1168. /* remove I2C client for demodulator */
  1169. client = st->i2c_client_demod;
  1170. if (client) {
  1171. module_put(client->dev.driver->owner);
  1172. i2c_unregister_device(client);
  1173. }
  1174. dvb_usb_device_exit(intf);
  1175. }
  1176. enum cxusb_table_index {
  1177. MEDION_MD95700,
  1178. DVICO_BLUEBIRD_LG064F_COLD,
  1179. DVICO_BLUEBIRD_LG064F_WARM,
  1180. DVICO_BLUEBIRD_DUAL_1_COLD,
  1181. DVICO_BLUEBIRD_DUAL_1_WARM,
  1182. DVICO_BLUEBIRD_LGZ201_COLD,
  1183. DVICO_BLUEBIRD_LGZ201_WARM,
  1184. DVICO_BLUEBIRD_TH7579_COLD,
  1185. DVICO_BLUEBIRD_TH7579_WARM,
  1186. DIGITALNOW_BLUEBIRD_DUAL_1_COLD,
  1187. DIGITALNOW_BLUEBIRD_DUAL_1_WARM,
  1188. DVICO_BLUEBIRD_DUAL_2_COLD,
  1189. DVICO_BLUEBIRD_DUAL_2_WARM,
  1190. DVICO_BLUEBIRD_DUAL_4,
  1191. DVICO_BLUEBIRD_DVB_T_NANO_2,
  1192. DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM,
  1193. AVERMEDIA_VOLAR_A868R,
  1194. DVICO_BLUEBIRD_DUAL_4_REV_2,
  1195. CONEXANT_D680_DMB,
  1196. MYGICA_D689,
  1197. MYGICA_T230,
  1198. NR__cxusb_table_index
  1199. };
  1200. static struct usb_device_id cxusb_table[NR__cxusb_table_index + 1] = {
  1201. [MEDION_MD95700] = {
  1202. USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700)
  1203. },
  1204. [DVICO_BLUEBIRD_LG064F_COLD] = {
  1205. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD)
  1206. },
  1207. [DVICO_BLUEBIRD_LG064F_WARM] = {
  1208. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM)
  1209. },
  1210. [DVICO_BLUEBIRD_DUAL_1_COLD] = {
  1211. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD)
  1212. },
  1213. [DVICO_BLUEBIRD_DUAL_1_WARM] = {
  1214. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM)
  1215. },
  1216. [DVICO_BLUEBIRD_LGZ201_COLD] = {
  1217. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD)
  1218. },
  1219. [DVICO_BLUEBIRD_LGZ201_WARM] = {
  1220. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM)
  1221. },
  1222. [DVICO_BLUEBIRD_TH7579_COLD] = {
  1223. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD)
  1224. },
  1225. [DVICO_BLUEBIRD_TH7579_WARM] = {
  1226. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM)
  1227. },
  1228. [DIGITALNOW_BLUEBIRD_DUAL_1_COLD] = {
  1229. USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD)
  1230. },
  1231. [DIGITALNOW_BLUEBIRD_DUAL_1_WARM] = {
  1232. USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM)
  1233. },
  1234. [DVICO_BLUEBIRD_DUAL_2_COLD] = {
  1235. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD)
  1236. },
  1237. [DVICO_BLUEBIRD_DUAL_2_WARM] = {
  1238. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM)
  1239. },
  1240. [DVICO_BLUEBIRD_DUAL_4] = {
  1241. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4)
  1242. },
  1243. [DVICO_BLUEBIRD_DVB_T_NANO_2] = {
  1244. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2)
  1245. },
  1246. [DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM] = {
  1247. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM)
  1248. },
  1249. [AVERMEDIA_VOLAR_A868R] = {
  1250. USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R)
  1251. },
  1252. [DVICO_BLUEBIRD_DUAL_4_REV_2] = {
  1253. USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2)
  1254. },
  1255. [CONEXANT_D680_DMB] = {
  1256. USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB)
  1257. },
  1258. [MYGICA_D689] = {
  1259. USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689)
  1260. },
  1261. [MYGICA_T230] = {
  1262. USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230)
  1263. },
  1264. {} /* Terminating entry */
  1265. };
  1266. MODULE_DEVICE_TABLE (usb, cxusb_table);
  1267. static struct dvb_usb_device_properties cxusb_medion_properties = {
  1268. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1269. .usb_ctrl = CYPRESS_FX2,
  1270. .size_of_priv = sizeof(struct cxusb_state),
  1271. .num_adapters = 1,
  1272. .adapter = {
  1273. {
  1274. .num_frontends = 1,
  1275. .fe = {{
  1276. .streaming_ctrl = cxusb_streaming_ctrl,
  1277. .frontend_attach = cxusb_cx22702_frontend_attach,
  1278. .tuner_attach = cxusb_fmd1216me_tuner_attach,
  1279. /* parameter for the MPEG2-data transfer */
  1280. .stream = {
  1281. .type = USB_BULK,
  1282. .count = 5,
  1283. .endpoint = 0x02,
  1284. .u = {
  1285. .bulk = {
  1286. .buffersize = 8192,
  1287. }
  1288. }
  1289. },
  1290. }},
  1291. },
  1292. },
  1293. .power_ctrl = cxusb_power_ctrl,
  1294. .i2c_algo = &cxusb_i2c_algo,
  1295. .generic_bulk_ctrl_endpoint = 0x01,
  1296. .num_device_descs = 1,
  1297. .devices = {
  1298. { "Medion MD95700 (MDUSBTV-HYBRID)",
  1299. { NULL },
  1300. { &cxusb_table[MEDION_MD95700], NULL },
  1301. },
  1302. }
  1303. };
  1304. static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
  1305. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1306. .usb_ctrl = DEVICE_SPECIFIC,
  1307. .firmware = "dvb-usb-bluebird-01.fw",
  1308. .download_firmware = bluebird_patch_dvico_firmware_download,
  1309. /* use usb alt setting 0 for EP4 transfer (dvb-t),
  1310. use usb alt setting 7 for EP2 transfer (atsc) */
  1311. .size_of_priv = sizeof(struct cxusb_state),
  1312. .num_adapters = 1,
  1313. .adapter = {
  1314. {
  1315. .num_frontends = 1,
  1316. .fe = {{
  1317. .streaming_ctrl = cxusb_streaming_ctrl,
  1318. .frontend_attach = cxusb_lgdt3303_frontend_attach,
  1319. .tuner_attach = cxusb_lgh064f_tuner_attach,
  1320. /* parameter for the MPEG2-data transfer */
  1321. .stream = {
  1322. .type = USB_BULK,
  1323. .count = 5,
  1324. .endpoint = 0x02,
  1325. .u = {
  1326. .bulk = {
  1327. .buffersize = 8192,
  1328. }
  1329. }
  1330. },
  1331. }},
  1332. },
  1333. },
  1334. .power_ctrl = cxusb_bluebird_power_ctrl,
  1335. .i2c_algo = &cxusb_i2c_algo,
  1336. .rc.core = {
  1337. .rc_interval = 100,
  1338. .rc_codes = RC_MAP_DVICO_PORTABLE,
  1339. .module_name = KBUILD_MODNAME,
  1340. .rc_query = cxusb_rc_query,
  1341. .allowed_protos = RC_PROTO_BIT_NEC,
  1342. },
  1343. .generic_bulk_ctrl_endpoint = 0x01,
  1344. .num_device_descs = 1,
  1345. .devices = {
  1346. { "DViCO FusionHDTV5 USB Gold",
  1347. { &cxusb_table[DVICO_BLUEBIRD_LG064F_COLD], NULL },
  1348. { &cxusb_table[DVICO_BLUEBIRD_LG064F_WARM], NULL },
  1349. },
  1350. }
  1351. };
  1352. static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
  1353. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1354. .usb_ctrl = DEVICE_SPECIFIC,
  1355. .firmware = "dvb-usb-bluebird-01.fw",
  1356. .download_firmware = bluebird_patch_dvico_firmware_download,
  1357. /* use usb alt setting 0 for EP4 transfer (dvb-t),
  1358. use usb alt setting 7 for EP2 transfer (atsc) */
  1359. .size_of_priv = sizeof(struct cxusb_state),
  1360. .num_adapters = 1,
  1361. .adapter = {
  1362. {
  1363. .num_frontends = 1,
  1364. .fe = {{
  1365. .streaming_ctrl = cxusb_streaming_ctrl,
  1366. .frontend_attach = cxusb_dee1601_frontend_attach,
  1367. .tuner_attach = cxusb_dee1601_tuner_attach,
  1368. /* parameter for the MPEG2-data transfer */
  1369. .stream = {
  1370. .type = USB_BULK,
  1371. .count = 5,
  1372. .endpoint = 0x04,
  1373. .u = {
  1374. .bulk = {
  1375. .buffersize = 8192,
  1376. }
  1377. }
  1378. },
  1379. }},
  1380. },
  1381. },
  1382. .power_ctrl = cxusb_bluebird_power_ctrl,
  1383. .i2c_algo = &cxusb_i2c_algo,
  1384. .rc.core = {
  1385. .rc_interval = 100,
  1386. .rc_codes = RC_MAP_DVICO_MCE,
  1387. .module_name = KBUILD_MODNAME,
  1388. .rc_query = cxusb_rc_query,
  1389. .allowed_protos = RC_PROTO_BIT_NEC,
  1390. },
  1391. .generic_bulk_ctrl_endpoint = 0x01,
  1392. .num_device_descs = 3,
  1393. .devices = {
  1394. { "DViCO FusionHDTV DVB-T Dual USB",
  1395. { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_COLD], NULL },
  1396. { &cxusb_table[DVICO_BLUEBIRD_DUAL_1_WARM], NULL },
  1397. },
  1398. { "DigitalNow DVB-T Dual USB",
  1399. { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_COLD], NULL },
  1400. { &cxusb_table[DIGITALNOW_BLUEBIRD_DUAL_1_WARM], NULL },
  1401. },
  1402. { "DViCO FusionHDTV DVB-T Dual Digital 2",
  1403. { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_COLD], NULL },
  1404. { &cxusb_table[DVICO_BLUEBIRD_DUAL_2_WARM], NULL },
  1405. },
  1406. }
  1407. };
  1408. static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
  1409. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1410. .usb_ctrl = DEVICE_SPECIFIC,
  1411. .firmware = "dvb-usb-bluebird-01.fw",
  1412. .download_firmware = bluebird_patch_dvico_firmware_download,
  1413. /* use usb alt setting 0 for EP4 transfer (dvb-t),
  1414. use usb alt setting 7 for EP2 transfer (atsc) */
  1415. .size_of_priv = sizeof(struct cxusb_state),
  1416. .num_adapters = 2,
  1417. .adapter = {
  1418. {
  1419. .num_frontends = 1,
  1420. .fe = {{
  1421. .streaming_ctrl = cxusb_streaming_ctrl,
  1422. .frontend_attach = cxusb_mt352_frontend_attach,
  1423. .tuner_attach = cxusb_lgz201_tuner_attach,
  1424. /* parameter for the MPEG2-data transfer */
  1425. .stream = {
  1426. .type = USB_BULK,
  1427. .count = 5,
  1428. .endpoint = 0x04,
  1429. .u = {
  1430. .bulk = {
  1431. .buffersize = 8192,
  1432. }
  1433. }
  1434. },
  1435. }},
  1436. },
  1437. },
  1438. .power_ctrl = cxusb_bluebird_power_ctrl,
  1439. .i2c_algo = &cxusb_i2c_algo,
  1440. .rc.core = {
  1441. .rc_interval = 100,
  1442. .rc_codes = RC_MAP_DVICO_PORTABLE,
  1443. .module_name = KBUILD_MODNAME,
  1444. .rc_query = cxusb_rc_query,
  1445. .allowed_protos = RC_PROTO_BIT_NEC,
  1446. },
  1447. .generic_bulk_ctrl_endpoint = 0x01,
  1448. .num_device_descs = 1,
  1449. .devices = {
  1450. { "DViCO FusionHDTV DVB-T USB (LGZ201)",
  1451. { &cxusb_table[DVICO_BLUEBIRD_LGZ201_COLD], NULL },
  1452. { &cxusb_table[DVICO_BLUEBIRD_LGZ201_WARM], NULL },
  1453. },
  1454. }
  1455. };
  1456. static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
  1457. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1458. .usb_ctrl = DEVICE_SPECIFIC,
  1459. .firmware = "dvb-usb-bluebird-01.fw",
  1460. .download_firmware = bluebird_patch_dvico_firmware_download,
  1461. /* use usb alt setting 0 for EP4 transfer (dvb-t),
  1462. use usb alt setting 7 for EP2 transfer (atsc) */
  1463. .size_of_priv = sizeof(struct cxusb_state),
  1464. .num_adapters = 1,
  1465. .adapter = {
  1466. {
  1467. .num_frontends = 1,
  1468. .fe = {{
  1469. .streaming_ctrl = cxusb_streaming_ctrl,
  1470. .frontend_attach = cxusb_mt352_frontend_attach,
  1471. .tuner_attach = cxusb_dtt7579_tuner_attach,
  1472. /* parameter for the MPEG2-data transfer */
  1473. .stream = {
  1474. .type = USB_BULK,
  1475. .count = 5,
  1476. .endpoint = 0x04,
  1477. .u = {
  1478. .bulk = {
  1479. .buffersize = 8192,
  1480. }
  1481. }
  1482. },
  1483. }},
  1484. },
  1485. },
  1486. .power_ctrl = cxusb_bluebird_power_ctrl,
  1487. .i2c_algo = &cxusb_i2c_algo,
  1488. .rc.core = {
  1489. .rc_interval = 100,
  1490. .rc_codes = RC_MAP_DVICO_PORTABLE,
  1491. .module_name = KBUILD_MODNAME,
  1492. .rc_query = cxusb_rc_query,
  1493. .allowed_protos = RC_PROTO_BIT_NEC,
  1494. },
  1495. .generic_bulk_ctrl_endpoint = 0x01,
  1496. .num_device_descs = 1,
  1497. .devices = {
  1498. { "DViCO FusionHDTV DVB-T USB (TH7579)",
  1499. { &cxusb_table[DVICO_BLUEBIRD_TH7579_COLD], NULL },
  1500. { &cxusb_table[DVICO_BLUEBIRD_TH7579_WARM], NULL },
  1501. },
  1502. }
  1503. };
  1504. static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
  1505. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1506. .usb_ctrl = CYPRESS_FX2,
  1507. .size_of_priv = sizeof(struct cxusb_state),
  1508. .num_adapters = 1,
  1509. .adapter = {
  1510. {
  1511. .num_frontends = 1,
  1512. .fe = {{
  1513. .streaming_ctrl = cxusb_streaming_ctrl,
  1514. .frontend_attach = cxusb_dualdig4_frontend_attach,
  1515. .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
  1516. /* parameter for the MPEG2-data transfer */
  1517. .stream = {
  1518. .type = USB_BULK,
  1519. .count = 5,
  1520. .endpoint = 0x02,
  1521. .u = {
  1522. .bulk = {
  1523. .buffersize = 8192,
  1524. }
  1525. }
  1526. },
  1527. }},
  1528. },
  1529. },
  1530. .power_ctrl = cxusb_power_ctrl,
  1531. .i2c_algo = &cxusb_i2c_algo,
  1532. .generic_bulk_ctrl_endpoint = 0x01,
  1533. .rc.core = {
  1534. .rc_interval = 100,
  1535. .rc_codes = RC_MAP_DVICO_MCE,
  1536. .module_name = KBUILD_MODNAME,
  1537. .rc_query = cxusb_bluebird2_rc_query,
  1538. .allowed_protos = RC_PROTO_BIT_NEC,
  1539. },
  1540. .num_device_descs = 1,
  1541. .devices = {
  1542. { "DViCO FusionHDTV DVB-T Dual Digital 4",
  1543. { NULL },
  1544. { &cxusb_table[DVICO_BLUEBIRD_DUAL_4], NULL },
  1545. },
  1546. }
  1547. };
  1548. static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
  1549. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1550. .usb_ctrl = CYPRESS_FX2,
  1551. .identify_state = bluebird_fx2_identify_state,
  1552. .size_of_priv = sizeof(struct cxusb_state),
  1553. .num_adapters = 1,
  1554. .adapter = {
  1555. {
  1556. .num_frontends = 1,
  1557. .fe = {{
  1558. .streaming_ctrl = cxusb_streaming_ctrl,
  1559. .frontend_attach = cxusb_nano2_frontend_attach,
  1560. .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
  1561. /* parameter for the MPEG2-data transfer */
  1562. .stream = {
  1563. .type = USB_BULK,
  1564. .count = 5,
  1565. .endpoint = 0x02,
  1566. .u = {
  1567. .bulk = {
  1568. .buffersize = 8192,
  1569. }
  1570. }
  1571. },
  1572. }},
  1573. },
  1574. },
  1575. .power_ctrl = cxusb_nano2_power_ctrl,
  1576. .i2c_algo = &cxusb_i2c_algo,
  1577. .generic_bulk_ctrl_endpoint = 0x01,
  1578. .rc.core = {
  1579. .rc_interval = 100,
  1580. .rc_codes = RC_MAP_DVICO_PORTABLE,
  1581. .module_name = KBUILD_MODNAME,
  1582. .rc_query = cxusb_bluebird2_rc_query,
  1583. .allowed_protos = RC_PROTO_BIT_NEC,
  1584. },
  1585. .num_device_descs = 1,
  1586. .devices = {
  1587. { "DViCO FusionHDTV DVB-T NANO2",
  1588. { NULL },
  1589. { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
  1590. },
  1591. }
  1592. };
  1593. static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
  1594. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1595. .usb_ctrl = DEVICE_SPECIFIC,
  1596. .firmware = "dvb-usb-bluebird-02.fw",
  1597. .download_firmware = bluebird_patch_dvico_firmware_download,
  1598. .identify_state = bluebird_fx2_identify_state,
  1599. .size_of_priv = sizeof(struct cxusb_state),
  1600. .num_adapters = 1,
  1601. .adapter = {
  1602. {
  1603. .num_frontends = 1,
  1604. .fe = {{
  1605. .streaming_ctrl = cxusb_streaming_ctrl,
  1606. .frontend_attach = cxusb_nano2_frontend_attach,
  1607. .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
  1608. /* parameter for the MPEG2-data transfer */
  1609. .stream = {
  1610. .type = USB_BULK,
  1611. .count = 5,
  1612. .endpoint = 0x02,
  1613. .u = {
  1614. .bulk = {
  1615. .buffersize = 8192,
  1616. }
  1617. }
  1618. },
  1619. }},
  1620. },
  1621. },
  1622. .power_ctrl = cxusb_nano2_power_ctrl,
  1623. .i2c_algo = &cxusb_i2c_algo,
  1624. .generic_bulk_ctrl_endpoint = 0x01,
  1625. .rc.core = {
  1626. .rc_interval = 100,
  1627. .rc_codes = RC_MAP_DVICO_PORTABLE,
  1628. .module_name = KBUILD_MODNAME,
  1629. .rc_query = cxusb_rc_query,
  1630. .allowed_protos = RC_PROTO_BIT_NEC,
  1631. },
  1632. .num_device_descs = 1,
  1633. .devices = {
  1634. { "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
  1635. { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2], NULL },
  1636. { &cxusb_table[DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM], NULL },
  1637. },
  1638. }
  1639. };
  1640. static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
  1641. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1642. .usb_ctrl = CYPRESS_FX2,
  1643. .size_of_priv = sizeof(struct cxusb_state),
  1644. .num_adapters = 1,
  1645. .adapter = {
  1646. {
  1647. .num_frontends = 1,
  1648. .fe = {{
  1649. .streaming_ctrl = cxusb_aver_streaming_ctrl,
  1650. .frontend_attach = cxusb_aver_lgdt3303_frontend_attach,
  1651. .tuner_attach = cxusb_mxl5003s_tuner_attach,
  1652. /* parameter for the MPEG2-data transfer */
  1653. .stream = {
  1654. .type = USB_BULK,
  1655. .count = 5,
  1656. .endpoint = 0x04,
  1657. .u = {
  1658. .bulk = {
  1659. .buffersize = 8192,
  1660. }
  1661. }
  1662. },
  1663. }},
  1664. },
  1665. },
  1666. .power_ctrl = cxusb_aver_power_ctrl,
  1667. .i2c_algo = &cxusb_i2c_algo,
  1668. .generic_bulk_ctrl_endpoint = 0x01,
  1669. .num_device_descs = 1,
  1670. .devices = {
  1671. { "AVerMedia AVerTVHD Volar (A868R)",
  1672. { NULL },
  1673. { &cxusb_table[AVERMEDIA_VOLAR_A868R], NULL },
  1674. },
  1675. }
  1676. };
  1677. static
  1678. struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
  1679. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1680. .usb_ctrl = CYPRESS_FX2,
  1681. .size_of_priv = sizeof(struct cxusb_state),
  1682. .num_adapters = 1,
  1683. .adapter = {
  1684. {
  1685. .size_of_priv = sizeof(struct dib0700_adapter_state),
  1686. .num_frontends = 1,
  1687. .fe = {{
  1688. .streaming_ctrl = cxusb_streaming_ctrl,
  1689. .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
  1690. .tuner_attach = cxusb_dualdig4_rev2_tuner_attach,
  1691. /* parameter for the MPEG2-data transfer */
  1692. .stream = {
  1693. .type = USB_BULK,
  1694. .count = 7,
  1695. .endpoint = 0x02,
  1696. .u = {
  1697. .bulk = {
  1698. .buffersize = 4096,
  1699. }
  1700. }
  1701. },
  1702. }},
  1703. },
  1704. },
  1705. .power_ctrl = cxusb_bluebird_power_ctrl,
  1706. .i2c_algo = &cxusb_i2c_algo,
  1707. .generic_bulk_ctrl_endpoint = 0x01,
  1708. .rc.core = {
  1709. .rc_interval = 100,
  1710. .rc_codes = RC_MAP_DVICO_MCE,
  1711. .module_name = KBUILD_MODNAME,
  1712. .rc_query = cxusb_rc_query,
  1713. .allowed_protos = RC_PROTO_BIT_NEC,
  1714. },
  1715. .num_device_descs = 1,
  1716. .devices = {
  1717. { "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
  1718. { NULL },
  1719. { &cxusb_table[DVICO_BLUEBIRD_DUAL_4_REV_2], NULL },
  1720. },
  1721. }
  1722. };
  1723. static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
  1724. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1725. .usb_ctrl = CYPRESS_FX2,
  1726. .size_of_priv = sizeof(struct cxusb_state),
  1727. .num_adapters = 1,
  1728. .adapter = {
  1729. {
  1730. .num_frontends = 1,
  1731. .fe = {{
  1732. .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
  1733. .frontend_attach = cxusb_d680_dmb_frontend_attach,
  1734. .tuner_attach = cxusb_d680_dmb_tuner_attach,
  1735. /* parameter for the MPEG2-data transfer */
  1736. .stream = {
  1737. .type = USB_BULK,
  1738. .count = 5,
  1739. .endpoint = 0x02,
  1740. .u = {
  1741. .bulk = {
  1742. .buffersize = 8192,
  1743. }
  1744. }
  1745. },
  1746. }},
  1747. },
  1748. },
  1749. .power_ctrl = cxusb_d680_dmb_power_ctrl,
  1750. .i2c_algo = &cxusb_i2c_algo,
  1751. .generic_bulk_ctrl_endpoint = 0x01,
  1752. .rc.core = {
  1753. .rc_interval = 100,
  1754. .rc_codes = RC_MAP_TOTAL_MEDIA_IN_HAND_02,
  1755. .module_name = KBUILD_MODNAME,
  1756. .rc_query = cxusb_d680_dmb_rc_query,
  1757. .allowed_protos = RC_PROTO_BIT_UNKNOWN,
  1758. },
  1759. .num_device_descs = 1,
  1760. .devices = {
  1761. {
  1762. "Conexant DMB-TH Stick",
  1763. { NULL },
  1764. { &cxusb_table[CONEXANT_D680_DMB], NULL },
  1765. },
  1766. }
  1767. };
  1768. static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
  1769. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1770. .usb_ctrl = CYPRESS_FX2,
  1771. .size_of_priv = sizeof(struct cxusb_state),
  1772. .num_adapters = 1,
  1773. .adapter = {
  1774. {
  1775. .num_frontends = 1,
  1776. .fe = {{
  1777. .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
  1778. .frontend_attach = cxusb_mygica_d689_frontend_attach,
  1779. .tuner_attach = cxusb_mygica_d689_tuner_attach,
  1780. /* parameter for the MPEG2-data transfer */
  1781. .stream = {
  1782. .type = USB_BULK,
  1783. .count = 5,
  1784. .endpoint = 0x02,
  1785. .u = {
  1786. .bulk = {
  1787. .buffersize = 8192,
  1788. }
  1789. }
  1790. },
  1791. }},
  1792. },
  1793. },
  1794. .power_ctrl = cxusb_d680_dmb_power_ctrl,
  1795. .i2c_algo = &cxusb_i2c_algo,
  1796. .generic_bulk_ctrl_endpoint = 0x01,
  1797. .rc.core = {
  1798. .rc_interval = 100,
  1799. .rc_codes = RC_MAP_D680_DMB,
  1800. .module_name = KBUILD_MODNAME,
  1801. .rc_query = cxusb_d680_dmb_rc_query,
  1802. .allowed_protos = RC_PROTO_BIT_UNKNOWN,
  1803. },
  1804. .num_device_descs = 1,
  1805. .devices = {
  1806. {
  1807. "Mygica D689 DMB-TH",
  1808. { NULL },
  1809. { &cxusb_table[MYGICA_D689], NULL },
  1810. },
  1811. }
  1812. };
  1813. static struct dvb_usb_device_properties cxusb_mygica_t230_properties = {
  1814. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  1815. .usb_ctrl = CYPRESS_FX2,
  1816. .size_of_priv = sizeof(struct cxusb_state),
  1817. .num_adapters = 1,
  1818. .adapter = {
  1819. {
  1820. .num_frontends = 1,
  1821. .fe = {{
  1822. .streaming_ctrl = cxusb_streaming_ctrl,
  1823. .frontend_attach = cxusb_mygica_t230_frontend_attach,
  1824. /* parameter for the MPEG2-data transfer */
  1825. .stream = {
  1826. .type = USB_BULK,
  1827. .count = 5,
  1828. .endpoint = 0x02,
  1829. .u = {
  1830. .bulk = {
  1831. .buffersize = 8192,
  1832. }
  1833. }
  1834. },
  1835. } },
  1836. },
  1837. },
  1838. .power_ctrl = cxusb_d680_dmb_power_ctrl,
  1839. .i2c_algo = &cxusb_i2c_algo,
  1840. .generic_bulk_ctrl_endpoint = 0x01,
  1841. .rc.core = {
  1842. .rc_interval = 100,
  1843. .rc_codes = RC_MAP_D680_DMB,
  1844. .module_name = KBUILD_MODNAME,
  1845. .rc_query = cxusb_d680_dmb_rc_query,
  1846. .allowed_protos = RC_PROTO_BIT_UNKNOWN,
  1847. },
  1848. .num_device_descs = 1,
  1849. .devices = {
  1850. {
  1851. "Mygica T230 DVB-T/T2/C",
  1852. { NULL },
  1853. { &cxusb_table[MYGICA_T230], NULL },
  1854. },
  1855. }
  1856. };
  1857. static struct usb_driver cxusb_driver = {
  1858. .name = "dvb_usb_cxusb",
  1859. .probe = cxusb_probe,
  1860. .disconnect = cxusb_disconnect,
  1861. .id_table = cxusb_table,
  1862. };
  1863. module_usb_driver(cxusb_driver);
  1864. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
  1865. MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
  1866. MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
  1867. MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
  1868. MODULE_VERSION("1.0-alpha");
  1869. MODULE_LICENSE("GPL");