anysee.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. /*
  2. * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
  3. *
  4. * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * TODO:
  21. * - add smart card reader support for Conditional Access (CA)
  22. *
  23. * Card reader in Anysee is nothing more than ISO 7816 card reader.
  24. * There is no hardware CAM in any Anysee device sold.
  25. * In my understanding it should be implemented by making own module
  26. * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
  27. * module registers serial interface that can be used to communicate
  28. * with any ISO 7816 smart card.
  29. *
  30. * Any help according to implement serial smart card reader support
  31. * is highly welcome!
  32. */
  33. #include "anysee.h"
  34. #include "tda1002x.h"
  35. #include "mt352.h"
  36. #include "mt352_priv.h"
  37. #include "zl10353.h"
  38. #include "tda18212.h"
  39. #include "cx24116.h"
  40. #include "stv0900.h"
  41. #include "stv6110.h"
  42. #include "isl6423.h"
  43. /* debug */
  44. static int dvb_usb_anysee_debug;
  45. module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
  46. MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
  47. static int dvb_usb_anysee_delsys;
  48. module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
  49. MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
  50. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  51. static DEFINE_MUTEX(anysee_usb_mutex);
  52. static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
  53. u8 *rbuf, u8 rlen)
  54. {
  55. struct anysee_state *state = d->priv;
  56. int act_len, ret;
  57. u8 buf[64];
  58. memcpy(&buf[0], sbuf, slen);
  59. buf[60] = state->seq++;
  60. if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
  61. return -EAGAIN;
  62. /* We need receive one message more after dvb_usb_generic_rw due
  63. to weird transaction flow, which is 1 x send + 2 x receive. */
  64. ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
  65. if (!ret) {
  66. /* receive 2nd answer */
  67. ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
  68. d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
  69. &act_len, 2000);
  70. if (ret)
  71. err("%s: recv bulk message failed: %d", __func__, ret);
  72. else {
  73. deb_xfer("<<< ");
  74. debug_dump(buf, act_len, deb_xfer);
  75. }
  76. }
  77. /* read request, copy returned data to return buf */
  78. if (!ret && rbuf && rlen)
  79. memcpy(rbuf, buf, rlen);
  80. mutex_unlock(&anysee_usb_mutex);
  81. return ret;
  82. }
  83. static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
  84. {
  85. u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
  86. int ret;
  87. ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
  88. deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
  89. return ret;
  90. }
  91. static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
  92. {
  93. u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
  94. deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
  95. return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
  96. }
  97. /* write single register with mask */
  98. static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
  99. u8 mask)
  100. {
  101. int ret;
  102. u8 tmp;
  103. /* no need for read if whole reg is written */
  104. if (mask != 0xff) {
  105. ret = anysee_read_reg(d, reg, &tmp);
  106. if (ret)
  107. return ret;
  108. val &= mask;
  109. tmp &= ~mask;
  110. val |= tmp;
  111. }
  112. return anysee_write_reg(d, reg, val);
  113. }
  114. static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
  115. {
  116. u8 buf[] = {CMD_GET_HW_INFO};
  117. return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
  118. }
  119. static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
  120. {
  121. u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
  122. deb_info("%s: onoff:%02x\n", __func__, onoff);
  123. return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
  124. }
  125. static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
  126. {
  127. u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
  128. deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
  129. return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
  130. }
  131. static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
  132. {
  133. u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
  134. deb_info("%s: onoff:%02x\n", __func__, onoff);
  135. return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
  136. }
  137. static int anysee_init(struct dvb_usb_device *d)
  138. {
  139. int ret;
  140. /* LED light */
  141. ret = anysee_led_ctrl(d, 0x01, 0x03);
  142. if (ret)
  143. return ret;
  144. /* enable IR */
  145. ret = anysee_ir_ctrl(d, 1);
  146. if (ret)
  147. return ret;
  148. return 0;
  149. }
  150. /* I2C */
  151. static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
  152. int num)
  153. {
  154. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  155. int ret = 0, inc, i = 0;
  156. u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
  157. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  158. return -EAGAIN;
  159. while (i < num) {
  160. if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
  161. if (msg[i].len > 2 || msg[i+1].len > 60) {
  162. ret = -EOPNOTSUPP;
  163. break;
  164. }
  165. buf[0] = CMD_I2C_READ;
  166. buf[1] = (msg[i].addr << 1) | 0x01;
  167. buf[2] = msg[i].buf[0];
  168. buf[3] = msg[i].buf[1];
  169. buf[4] = msg[i].len-1;
  170. buf[5] = msg[i+1].len;
  171. ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
  172. msg[i+1].len);
  173. inc = 2;
  174. } else {
  175. if (msg[i].len > 48) {
  176. ret = -EOPNOTSUPP;
  177. break;
  178. }
  179. buf[0] = CMD_I2C_WRITE;
  180. buf[1] = (msg[i].addr << 1);
  181. buf[2] = msg[i].len;
  182. buf[3] = 0x01;
  183. memcpy(&buf[4], msg[i].buf, msg[i].len);
  184. ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
  185. inc = 1;
  186. }
  187. if (ret)
  188. break;
  189. i += inc;
  190. }
  191. mutex_unlock(&d->i2c_mutex);
  192. return ret ? ret : i;
  193. }
  194. static u32 anysee_i2c_func(struct i2c_adapter *adapter)
  195. {
  196. return I2C_FUNC_I2C;
  197. }
  198. static struct i2c_algorithm anysee_i2c_algo = {
  199. .master_xfer = anysee_master_xfer,
  200. .functionality = anysee_i2c_func,
  201. };
  202. static int anysee_mt352_demod_init(struct dvb_frontend *fe)
  203. {
  204. static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
  205. static u8 reset[] = { RESET, 0x80 };
  206. static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
  207. static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
  208. static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
  209. static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
  210. mt352_write(fe, clock_config, sizeof(clock_config));
  211. udelay(200);
  212. mt352_write(fe, reset, sizeof(reset));
  213. mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
  214. mt352_write(fe, agc_cfg, sizeof(agc_cfg));
  215. mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
  216. mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
  217. return 0;
  218. }
  219. /* Callbacks for DVB USB */
  220. static struct tda10023_config anysee_tda10023_config = {
  221. .demod_address = (0x1a >> 1),
  222. .invert = 0,
  223. .xtal = 16000000,
  224. .pll_m = 11,
  225. .pll_p = 3,
  226. .pll_n = 1,
  227. .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
  228. .deltaf = 0xfeeb,
  229. };
  230. static struct mt352_config anysee_mt352_config = {
  231. .demod_address = (0x1e >> 1),
  232. .demod_init = anysee_mt352_demod_init,
  233. };
  234. static struct zl10353_config anysee_zl10353_config = {
  235. .demod_address = (0x1e >> 1),
  236. .parallel_ts = 1,
  237. };
  238. static struct zl10353_config anysee_zl10353_tda18212_config2 = {
  239. .demod_address = (0x1e >> 1),
  240. .parallel_ts = 1,
  241. .disable_i2c_gate_ctrl = 1,
  242. .no_tuner = 1,
  243. .if2 = 41500,
  244. };
  245. static struct zl10353_config anysee_zl10353_tda18212_config = {
  246. .demod_address = (0x18 >> 1),
  247. .parallel_ts = 1,
  248. .disable_i2c_gate_ctrl = 1,
  249. .no_tuner = 1,
  250. .if2 = 41500,
  251. };
  252. static struct tda10023_config anysee_tda10023_tda18212_config = {
  253. .demod_address = (0x1a >> 1),
  254. .xtal = 16000000,
  255. .pll_m = 12,
  256. .pll_p = 3,
  257. .pll_n = 1,
  258. .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
  259. .deltaf = 0xba02,
  260. };
  261. static struct tda18212_config anysee_tda18212_config = {
  262. .i2c_address = (0xc0 >> 1),
  263. .if_dvbt_6 = 4150,
  264. .if_dvbt_7 = 4150,
  265. .if_dvbt_8 = 4150,
  266. .if_dvbc = 5000,
  267. };
  268. static struct cx24116_config anysee_cx24116_config = {
  269. .demod_address = (0xaa >> 1),
  270. .mpg_clk_pos_pol = 0x00,
  271. .i2c_wr_max = 48,
  272. };
  273. static struct stv0900_config anysee_stv0900_config = {
  274. .demod_address = (0xd0 >> 1),
  275. .demod_mode = 0,
  276. .xtal = 8000000,
  277. .clkmode = 3,
  278. .diseqc_mode = 2,
  279. .tun1_maddress = 0,
  280. .tun1_adc = 1, /* 1 Vpp */
  281. .path1_mode = 3,
  282. };
  283. static struct stv6110_config anysee_stv6110_config = {
  284. .i2c_address = (0xc0 >> 1),
  285. .mclk = 16000000,
  286. .clk_div = 1,
  287. };
  288. static struct isl6423_config anysee_isl6423_config = {
  289. .current_max = SEC_CURRENT_800m,
  290. .curlim = SEC_CURRENT_LIM_OFF,
  291. .mod_extern = 1,
  292. .addr = (0x10 >> 1),
  293. };
  294. /*
  295. * New USB device strings: Mfr=1, Product=2, SerialNumber=0
  296. * Manufacturer: AMT.CO.KR
  297. *
  298. * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
  299. * PCB: ?
  300. * parts: DNOS404ZH102A(MT352, DTT7579(?))
  301. *
  302. * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
  303. * PCB: ?
  304. * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
  305. *
  306. * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
  307. * PCB: 507CD (rev1.1)
  308. * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
  309. * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
  310. * IOA=4f IOB=ff IOC=00 IOD=06 IOF=01
  311. * IOD[0] ZL10353 1=enabled
  312. * IOA[7] TS 0=enabled
  313. * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
  314. *
  315. * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
  316. * PCB: 507DC (rev0.2)
  317. * parts: TDA10023, DTOS403IH102B TM, CST56I01
  318. * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
  319. * IOA=4f IOB=ff IOC=00 IOD=26 IOF=01
  320. * IOD[0] TDA10023 1=enabled
  321. *
  322. * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
  323. * PCB: 507SI (rev2.1)
  324. * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
  325. * OEA=80 OEB=00 OEC=ff OED=ff OEF=fe
  326. * IOA=4d IOB=ff IOC=00 IOD=26 IOF=01
  327. * IOD[0] CX24116 1=enabled
  328. *
  329. * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
  330. * PCB: 507FA (rev0.4)
  331. * parts: TDA10023, DTOS403IH102B TM, TDA8024
  332. * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
  333. * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
  334. * IOD[5] TDA10023 1=enabled
  335. * IOE[0] tuner 1=enabled
  336. *
  337. * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
  338. * PCB: 507FA (rev1.1)
  339. * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
  340. * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
  341. * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
  342. * DVB-C:
  343. * IOD[5] TDA10023 1=enabled
  344. * IOE[0] tuner 1=enabled
  345. * DVB-T:
  346. * IOD[0] ZL10353 1=enabled
  347. * IOE[0] tuner 0=enabled
  348. * tuner is behind ZL10353 I2C-gate
  349. *
  350. * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
  351. * PCB: 508TC (rev0.6)
  352. * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
  353. * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
  354. * IOA=4d IOB=00 IOC=cc IOD=48 IOF=e4
  355. * IOA[7] TS 1=enabled
  356. * IOE[4] TDA18212 1=enabled
  357. * DVB-C:
  358. * IOD[6] ZL10353 0=disabled
  359. * IOD[5] TDA10023 1=enabled
  360. * IOE[0] IF 1=enabled
  361. * DVB-T:
  362. * IOD[5] TDA10023 0=disabled
  363. * IOD[6] ZL10353 1=enabled
  364. * IOE[0] IF 0=enabled
  365. *
  366. * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
  367. * PCB: 508S2 (rev0.7)
  368. * parts: DNBU10512IST(STV0903, STV6110), ISL6423
  369. * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
  370. * IOA=4d IOB=00 IOC=c4 IOD=08 IOF=e4
  371. * IOA[7] TS 1=enabled
  372. * IOE[5] STV0903 1=enabled
  373. *
  374. */
  375. static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
  376. {
  377. int ret;
  378. struct anysee_state *state = adap->dev->priv;
  379. u8 hw_info[3];
  380. u8 tmp;
  381. struct i2c_msg msg[2] = {
  382. {
  383. .addr = anysee_tda18212_config.i2c_address,
  384. .flags = 0,
  385. .len = 1,
  386. .buf = "\x00",
  387. }, {
  388. .addr = anysee_tda18212_config.i2c_address,
  389. .flags = I2C_M_RD,
  390. .len = 1,
  391. .buf = &tmp,
  392. }
  393. };
  394. /* Check which hardware we have.
  395. * We must do this call two times to get reliable values (hw bug).
  396. */
  397. ret = anysee_get_hw_info(adap->dev, hw_info);
  398. if (ret)
  399. goto error;
  400. ret = anysee_get_hw_info(adap->dev, hw_info);
  401. if (ret)
  402. goto error;
  403. /* Meaning of these info bytes are guessed. */
  404. info("firmware version:%d.%d hardware id:%d",
  405. hw_info[1], hw_info[2], hw_info[0]);
  406. state->hw = hw_info[0];
  407. switch (state->hw) {
  408. case ANYSEE_HW_02: /* 2 */
  409. /* E30 */
  410. /* attach demod */
  411. adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
  412. &adap->dev->i2c_adap);
  413. if (adap->fe)
  414. break;
  415. /* attach demod */
  416. adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
  417. &adap->dev->i2c_adap);
  418. break;
  419. case ANYSEE_HW_507CD: /* 6 */
  420. /* E30 Plus */
  421. /* enable DVB-T demod on IOD[0] */
  422. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
  423. if (ret)
  424. goto error;
  425. /* enable transport stream on IOA[7] */
  426. ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
  427. if (ret)
  428. goto error;
  429. /* attach demod */
  430. adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
  431. &adap->dev->i2c_adap);
  432. break;
  433. case ANYSEE_HW_507DC: /* 10 */
  434. /* E30 C Plus */
  435. /* enable DVB-C demod on IOD[0] */
  436. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
  437. if (ret)
  438. goto error;
  439. /* attach demod */
  440. adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
  441. &adap->dev->i2c_adap, 0x48);
  442. break;
  443. case ANYSEE_HW_507SI: /* 11 */
  444. /* E30 S2 Plus */
  445. /* enable DVB-S/S2 demod on IOD[0] */
  446. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
  447. if (ret)
  448. goto error;
  449. /* attach demod */
  450. adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
  451. &adap->dev->i2c_adap);
  452. break;
  453. case ANYSEE_HW_507FA: /* 15 */
  454. /* E30 Combo Plus */
  455. /* E30 C Plus */
  456. /* enable tuner on IOE[4] */
  457. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
  458. if (ret)
  459. goto error;
  460. /* probe TDA18212 */
  461. tmp = 0;
  462. ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
  463. if (ret == 2 && tmp == 0xc7)
  464. deb_info("%s: TDA18212 found\n", __func__);
  465. else
  466. tmp = 0;
  467. /* disable tuner on IOE[4] */
  468. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
  469. if (ret)
  470. goto error;
  471. if (dvb_usb_anysee_delsys) {
  472. /* disable DVB-C demod on IOD[5] */
  473. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
  474. 0x20);
  475. if (ret)
  476. goto error;
  477. /* enable DVB-T demod on IOD[0] */
  478. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
  479. 0x01);
  480. if (ret)
  481. goto error;
  482. /* attach demod */
  483. if (tmp == 0xc7) {
  484. /* TDA18212 config */
  485. adap->fe = dvb_attach(zl10353_attach,
  486. &anysee_zl10353_tda18212_config2,
  487. &adap->dev->i2c_adap);
  488. } else {
  489. /* PLL config */
  490. adap->fe = dvb_attach(zl10353_attach,
  491. &anysee_zl10353_config,
  492. &adap->dev->i2c_adap);
  493. }
  494. } else {
  495. /* disable DVB-T demod on IOD[0] */
  496. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
  497. 0x01);
  498. if (ret)
  499. goto error;
  500. /* enable DVB-C demod on IOD[5] */
  501. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
  502. 0x20);
  503. if (ret)
  504. goto error;
  505. /* attach demod */
  506. if (tmp == 0xc7) {
  507. /* TDA18212 config */
  508. adap->fe = dvb_attach(tda10023_attach,
  509. &anysee_tda10023_tda18212_config,
  510. &adap->dev->i2c_adap, 0x48);
  511. } else {
  512. /* PLL config */
  513. adap->fe = dvb_attach(tda10023_attach,
  514. &anysee_tda10023_config,
  515. &adap->dev->i2c_adap, 0x48);
  516. }
  517. }
  518. break;
  519. case ANYSEE_HW_508TC: /* 18 */
  520. /* E7 TC */
  521. /* enable transport stream on IOA[7] */
  522. ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
  523. if (ret)
  524. goto error;
  525. if (dvb_usb_anysee_delsys) {
  526. /* disable DVB-C demod on IOD[5] */
  527. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
  528. 0x20);
  529. if (ret)
  530. goto error;
  531. /* enable DVB-T demod on IOD[6] */
  532. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
  533. 0x40);
  534. if (ret)
  535. goto error;
  536. /* enable IF route on IOE[0] */
  537. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
  538. 0x01);
  539. if (ret)
  540. goto error;
  541. /* attach demod */
  542. adap->fe = dvb_attach(zl10353_attach,
  543. &anysee_zl10353_tda18212_config,
  544. &adap->dev->i2c_adap);
  545. } else {
  546. /* disable DVB-T demod on IOD[6] */
  547. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
  548. 0x40);
  549. if (ret)
  550. goto error;
  551. /* enable DVB-C demod on IOD[5] */
  552. ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
  553. 0x20);
  554. if (ret)
  555. goto error;
  556. /* enable IF route on IOE[0] */
  557. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
  558. 0x01);
  559. if (ret)
  560. goto error;
  561. /* attach demod */
  562. adap->fe = dvb_attach(tda10023_attach,
  563. &anysee_tda10023_tda18212_config,
  564. &adap->dev->i2c_adap, 0x48);
  565. }
  566. break;
  567. case ANYSEE_HW_508S2: /* 19 */
  568. /* E7 S2 */
  569. /* enable transport stream on IOA[7] */
  570. ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
  571. if (ret)
  572. goto error;
  573. /* enable DVB-S/S2 demod on IOE[5] */
  574. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
  575. if (ret)
  576. goto error;
  577. /* attach demod */
  578. adap->fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
  579. &adap->dev->i2c_adap, 0);
  580. break;
  581. }
  582. if (!adap->fe) {
  583. /* we have no frontend :-( */
  584. ret = -ENODEV;
  585. err("Unsupported Anysee version. " \
  586. "Please report the <linux-media@vger.kernel.org>.");
  587. }
  588. error:
  589. return ret;
  590. }
  591. static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
  592. {
  593. struct anysee_state *state = adap->dev->priv;
  594. struct dvb_frontend *fe;
  595. int ret;
  596. deb_info("%s:\n", __func__);
  597. switch (state->hw) {
  598. case ANYSEE_HW_02: /* 2 */
  599. /* E30 */
  600. /* attach tuner */
  601. fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
  602. NULL, DVB_PLL_THOMSON_DTT7579);
  603. break;
  604. case ANYSEE_HW_507CD: /* 6 */
  605. /* E30 Plus */
  606. /* attach tuner */
  607. fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
  608. &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
  609. break;
  610. case ANYSEE_HW_507DC: /* 10 */
  611. /* E30 C Plus */
  612. /* attach tuner */
  613. fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
  614. &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
  615. break;
  616. case ANYSEE_HW_507SI: /* 11 */
  617. /* E30 S2 Plus */
  618. /* attach LNB controller */
  619. fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,
  620. &anysee_isl6423_config);
  621. break;
  622. case ANYSEE_HW_507FA: /* 15 */
  623. /* E30 Combo Plus */
  624. /* E30 C Plus */
  625. if (dvb_usb_anysee_delsys) {
  626. /* enable DVB-T tuner on IOE[0] */
  627. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
  628. 0x01);
  629. if (ret)
  630. goto error;
  631. } else {
  632. /* enable DVB-C tuner on IOE[0] */
  633. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
  634. 0x01);
  635. if (ret)
  636. goto error;
  637. }
  638. /* Try first attach TDA18212 silicon tuner on IOE[4], if that
  639. * fails attach old simple PLL. */
  640. /* enable tuner on IOE[4] */
  641. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
  642. if (ret)
  643. goto error;
  644. /* attach tuner */
  645. fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
  646. &anysee_tda18212_config);
  647. if (fe)
  648. break;
  649. /* disable tuner on IOE[4] */
  650. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
  651. if (ret)
  652. goto error;
  653. /* attach tuner */
  654. fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
  655. &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
  656. break;
  657. case ANYSEE_HW_508TC: /* 18 */
  658. /* E7 TC */
  659. /* enable tuner on IOE[4] */
  660. ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
  661. if (ret)
  662. goto error;
  663. /* attach tuner */
  664. fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
  665. &anysee_tda18212_config);
  666. break;
  667. case ANYSEE_HW_508S2: /* 19 */
  668. /* E7 S2 */
  669. /* attach tuner */
  670. fe = dvb_attach(stv6110_attach, adap->fe,
  671. &anysee_stv6110_config, &adap->dev->i2c_adap);
  672. if (fe) {
  673. /* attach LNB controller */
  674. fe = dvb_attach(isl6423_attach, adap->fe,
  675. &adap->dev->i2c_adap, &anysee_isl6423_config);
  676. }
  677. break;
  678. default:
  679. fe = NULL;
  680. }
  681. if (fe)
  682. ret = 0;
  683. else
  684. ret = -ENODEV;
  685. error:
  686. return ret;
  687. }
  688. static int anysee_rc_query(struct dvb_usb_device *d)
  689. {
  690. u8 buf[] = {CMD_GET_IR_CODE};
  691. u8 ircode[2];
  692. int ret;
  693. /* Remote controller is basic NEC using address byte 0x08.
  694. Anysee device RC query returns only two bytes, status and code,
  695. address byte is dropped. Also it does not return any value for
  696. NEC RCs having address byte other than 0x08. Due to that, we
  697. cannot use that device as standard NEC receiver.
  698. It could be possible make hack which reads whole code directly
  699. from device memory... */
  700. ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
  701. if (ret)
  702. return ret;
  703. if (ircode[0]) {
  704. deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
  705. rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
  706. }
  707. return 0;
  708. }
  709. /* DVB USB Driver stuff */
  710. static struct dvb_usb_device_properties anysee_properties;
  711. static int anysee_probe(struct usb_interface *intf,
  712. const struct usb_device_id *id)
  713. {
  714. struct dvb_usb_device *d;
  715. struct usb_host_interface *alt;
  716. int ret;
  717. /* There is one interface with two alternate settings.
  718. Alternate setting 0 is for bulk transfer.
  719. Alternate setting 1 is for isochronous transfer.
  720. We use bulk transfer (alternate setting 0). */
  721. if (intf->num_altsetting < 1)
  722. return -ENODEV;
  723. /*
  724. * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
  725. * firmware from eeprom). If dvb_usb_device_init() succeeds that
  726. * means d is a valid pointer.
  727. */
  728. ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
  729. adapter_nr);
  730. if (ret)
  731. return ret;
  732. alt = usb_altnum_to_altsetting(intf, 0);
  733. if (alt == NULL) {
  734. deb_info("%s: no alt found!\n", __func__);
  735. return -ENODEV;
  736. }
  737. ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
  738. alt->desc.bAlternateSetting);
  739. if (ret)
  740. return ret;
  741. return anysee_init(d);
  742. }
  743. static struct usb_device_id anysee_table[] = {
  744. { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
  745. { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
  746. { } /* Terminating entry */
  747. };
  748. MODULE_DEVICE_TABLE(usb, anysee_table);
  749. static struct dvb_usb_device_properties anysee_properties = {
  750. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  751. .usb_ctrl = DEVICE_SPECIFIC,
  752. .size_of_priv = sizeof(struct anysee_state),
  753. .num_adapters = 1,
  754. .adapter = {
  755. {
  756. .streaming_ctrl = anysee_streaming_ctrl,
  757. .frontend_attach = anysee_frontend_attach,
  758. .tuner_attach = anysee_tuner_attach,
  759. .stream = {
  760. .type = USB_BULK,
  761. .count = 8,
  762. .endpoint = 0x82,
  763. .u = {
  764. .bulk = {
  765. .buffersize = (16*512),
  766. }
  767. }
  768. },
  769. }
  770. },
  771. .rc.core = {
  772. .rc_codes = RC_MAP_ANYSEE,
  773. .protocol = RC_TYPE_OTHER,
  774. .module_name = "anysee",
  775. .rc_query = anysee_rc_query,
  776. .rc_interval = 250, /* windows driver uses 500ms */
  777. },
  778. .i2c_algo = &anysee_i2c_algo,
  779. .generic_bulk_ctrl_endpoint = 1,
  780. .num_device_descs = 1,
  781. .devices = {
  782. {
  783. .name = "Anysee DVB USB2.0",
  784. .cold_ids = {NULL},
  785. .warm_ids = {&anysee_table[0],
  786. &anysee_table[1], NULL},
  787. },
  788. }
  789. };
  790. static struct usb_driver anysee_driver = {
  791. .name = "dvb_usb_anysee",
  792. .probe = anysee_probe,
  793. .disconnect = dvb_usb_device_exit,
  794. .id_table = anysee_table,
  795. };
  796. /* module stuff */
  797. static int __init anysee_module_init(void)
  798. {
  799. int ret;
  800. ret = usb_register(&anysee_driver);
  801. if (ret)
  802. err("%s: usb_register failed. Error number %d", __func__, ret);
  803. return ret;
  804. }
  805. static void __exit anysee_module_exit(void)
  806. {
  807. /* deregister this driver from the USB subsystem */
  808. usb_deregister(&anysee_driver);
  809. }
  810. module_init(anysee_module_init);
  811. module_exit(anysee_module_exit);
  812. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  813. MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
  814. MODULE_LICENSE("GPL");