pctv452e.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /*
  2. * PCTV 452e DVB driver
  3. *
  4. * Copyright (c) 2006-2008 Dominik Kuhlen <dkuhlen@gmx.net>
  5. *
  6. * TT connect S2-3650-CI Common Interface support, MAC readout
  7. * Copyright (C) 2008 Michael H. Schimek <mschimek@gmx.at>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. */
  14. /* dvb usb framework */
  15. #define DVB_USB_LOG_PREFIX "pctv452e"
  16. #include "dvb-usb.h"
  17. /* Demodulator */
  18. #include "stb0899_drv.h"
  19. #include "stb0899_reg.h"
  20. #include "stb0899_cfg.h"
  21. /* Tuner */
  22. #include "stb6100.h"
  23. #include "stb6100_cfg.h"
  24. /* FE Power */
  25. #include "lnbp22.h"
  26. #include "dvb_ca_en50221.h"
  27. #include "ttpci-eeprom.h"
  28. static int debug;
  29. module_param(debug, int, 0644);
  30. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  31. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  32. #define ISOC_INTERFACE_ALTERNATIVE 3
  33. #define SYNC_BYTE_OUT 0xaa
  34. #define SYNC_BYTE_IN 0x55
  35. /* guessed: (copied from ttusb-budget) */
  36. #define PCTV_CMD_RESET 0x15
  37. /* command to poll IR receiver */
  38. #define PCTV_CMD_IR 0x1b
  39. /* command to send I2C */
  40. #define PCTV_CMD_I2C 0x31
  41. #define I2C_ADDR_STB0899 (0xd0 >> 1)
  42. #define I2C_ADDR_STB6100 (0xc0 >> 1)
  43. #define I2C_ADDR_LNBP22 (0x10 >> 1)
  44. #define I2C_ADDR_24C16 (0xa0 >> 1)
  45. #define I2C_ADDR_24C64 (0xa2 >> 1)
  46. /* pctv452e sends us this amount of data for each issued usb-command */
  47. #define PCTV_ANSWER_LEN 64
  48. /* Wait up to 1000ms for device */
  49. #define PCTV_TIMEOUT 1000
  50. #define PCTV_LED_GPIO STB0899_GPIO01
  51. #define PCTV_LED_GREEN 0x82
  52. #define PCTV_LED_ORANGE 0x02
  53. #define ci_dbg(format, arg...) \
  54. do { \
  55. if (0) \
  56. printk(KERN_DEBUG DVB_USB_LOG_PREFIX \
  57. ": " format "\n" , ## arg); \
  58. } while (0)
  59. enum {
  60. TT3650_CMD_CI_TEST = 0x40,
  61. TT3650_CMD_CI_RD_CTRL,
  62. TT3650_CMD_CI_WR_CTRL,
  63. TT3650_CMD_CI_RD_ATTR,
  64. TT3650_CMD_CI_WR_ATTR,
  65. TT3650_CMD_CI_RESET,
  66. TT3650_CMD_CI_SET_VIDEO_PORT
  67. };
  68. static struct stb0899_postproc pctv45e_postproc[] = {
  69. { PCTV_LED_GPIO, STB0899_GPIOPULLUP },
  70. { 0, 0 }
  71. };
  72. /*
  73. * stores all private variables for communication with the PCTV452e DVB-S2
  74. */
  75. struct pctv452e_state {
  76. struct dvb_ca_en50221 ca;
  77. struct mutex ca_mutex;
  78. u8 c; /* transaction counter, wraps around... */
  79. u8 initialized; /* set to 1 if 0x15 has been sent */
  80. u16 last_rc_key;
  81. };
  82. static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
  83. unsigned int write_len, unsigned int read_len)
  84. {
  85. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  86. u8 buf[64];
  87. u8 id;
  88. unsigned int rlen;
  89. int ret;
  90. BUG_ON(NULL == data && 0 != (write_len | read_len));
  91. BUG_ON(write_len > 64 - 4);
  92. BUG_ON(read_len > 64 - 4);
  93. id = state->c++;
  94. buf[0] = SYNC_BYTE_OUT;
  95. buf[1] = id;
  96. buf[2] = cmd;
  97. buf[3] = write_len;
  98. memcpy(buf + 4, data, write_len);
  99. rlen = (read_len > 0) ? 64 : 0;
  100. ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
  101. buf, rlen, /* delay_ms */ 0);
  102. if (0 != ret)
  103. goto failed;
  104. ret = -EIO;
  105. if (SYNC_BYTE_IN != buf[0] || id != buf[1])
  106. goto failed;
  107. memcpy(data, buf + 4, read_len);
  108. return 0;
  109. failed:
  110. err("CI error %d; %02X %02X %02X -> %*ph.",
  111. ret, SYNC_BYTE_OUT, id, cmd, 3, buf);
  112. return ret;
  113. }
  114. static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca,
  115. u8 cmd, u8 *data, unsigned int write_len,
  116. unsigned int read_len)
  117. {
  118. struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
  119. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  120. int ret;
  121. mutex_lock(&state->ca_mutex);
  122. ret = tt3650_ci_msg(d, cmd, data, write_len, read_len);
  123. mutex_unlock(&state->ca_mutex);
  124. return ret;
  125. }
  126. static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
  127. int slot, int address)
  128. {
  129. u8 buf[3];
  130. int ret;
  131. if (0 != slot)
  132. return -EINVAL;
  133. buf[0] = (address >> 8) & 0x0F;
  134. buf[1] = address;
  135. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3);
  136. ci_dbg("%s %04x -> %d 0x%02x",
  137. __func__, address, ret, buf[2]);
  138. if (ret < 0)
  139. return ret;
  140. return buf[2];
  141. }
  142. static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
  143. int slot, int address, u8 value)
  144. {
  145. u8 buf[3];
  146. ci_dbg("%s %d 0x%04x 0x%02x",
  147. __func__, slot, address, value);
  148. if (0 != slot)
  149. return -EINVAL;
  150. buf[0] = (address >> 8) & 0x0F;
  151. buf[1] = address;
  152. buf[2] = value;
  153. return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3);
  154. }
  155. static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca,
  156. int slot,
  157. u8 address)
  158. {
  159. u8 buf[2];
  160. int ret;
  161. if (0 != slot)
  162. return -EINVAL;
  163. buf[0] = address & 3;
  164. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2);
  165. ci_dbg("%s 0x%02x -> %d 0x%02x",
  166. __func__, address, ret, buf[1]);
  167. if (ret < 0)
  168. return ret;
  169. return buf[1];
  170. }
  171. static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca,
  172. int slot,
  173. u8 address,
  174. u8 value)
  175. {
  176. u8 buf[2];
  177. ci_dbg("%s %d 0x%02x 0x%02x",
  178. __func__, slot, address, value);
  179. if (0 != slot)
  180. return -EINVAL;
  181. buf[0] = address;
  182. buf[1] = value;
  183. return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2);
  184. }
  185. static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca,
  186. int slot,
  187. int enable)
  188. {
  189. u8 buf[1];
  190. int ret;
  191. ci_dbg("%s %d %d", __func__, slot, enable);
  192. if (0 != slot)
  193. return -EINVAL;
  194. enable = !!enable;
  195. buf[0] = enable;
  196. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
  197. if (ret < 0)
  198. return ret;
  199. if (enable != buf[0]) {
  200. err("CI not %sabled.", enable ? "en" : "dis");
  201. return -EIO;
  202. }
  203. return 0;
  204. }
  205. static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  206. {
  207. return tt3650_ci_set_video_port(ca, slot, /* enable */ 0);
  208. }
  209. static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  210. {
  211. return tt3650_ci_set_video_port(ca, slot, /* enable */ 1);
  212. }
  213. static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  214. {
  215. struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
  216. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  217. u8 buf[1];
  218. int ret;
  219. ci_dbg("%s %d", __func__, slot);
  220. if (0 != slot)
  221. return -EINVAL;
  222. buf[0] = 0;
  223. mutex_lock(&state->ca_mutex);
  224. ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
  225. if (0 != ret)
  226. goto failed;
  227. msleep(500);
  228. buf[0] = 1;
  229. ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
  230. if (0 != ret)
  231. goto failed;
  232. msleep(500);
  233. buf[0] = 0; /* FTA */
  234. ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
  235. failed:
  236. mutex_unlock(&state->ca_mutex);
  237. return ret;
  238. }
  239. static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca,
  240. int slot,
  241. int open)
  242. {
  243. u8 buf[1];
  244. int ret;
  245. if (0 != slot)
  246. return -EINVAL;
  247. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1);
  248. if (0 != ret)
  249. return ret;
  250. if (1 == buf[0])
  251. return DVB_CA_EN50221_POLL_CAM_PRESENT |
  252. DVB_CA_EN50221_POLL_CAM_READY;
  253. return 0;
  254. }
  255. static void tt3650_ci_uninit(struct dvb_usb_device *d)
  256. {
  257. struct pctv452e_state *state;
  258. ci_dbg("%s", __func__);
  259. if (NULL == d)
  260. return;
  261. state = (struct pctv452e_state *)d->priv;
  262. if (NULL == state)
  263. return;
  264. if (NULL == state->ca.data)
  265. return;
  266. /* Error ignored. */
  267. tt3650_ci_set_video_port(&state->ca, /* slot */ 0, /* enable */ 0);
  268. dvb_ca_en50221_release(&state->ca);
  269. memset(&state->ca, 0, sizeof(state->ca));
  270. }
  271. static int tt3650_ci_init(struct dvb_usb_adapter *a)
  272. {
  273. struct dvb_usb_device *d = a->dev;
  274. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  275. int ret;
  276. ci_dbg("%s", __func__);
  277. mutex_init(&state->ca_mutex);
  278. state->ca.owner = THIS_MODULE;
  279. state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem;
  280. state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem;
  281. state->ca.read_cam_control = tt3650_ci_read_cam_control;
  282. state->ca.write_cam_control = tt3650_ci_write_cam_control;
  283. state->ca.slot_reset = tt3650_ci_slot_reset;
  284. state->ca.slot_shutdown = tt3650_ci_slot_shutdown;
  285. state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable;
  286. state->ca.poll_slot_status = tt3650_ci_poll_slot_status;
  287. state->ca.data = d;
  288. ret = dvb_ca_en50221_init(&a->dvb_adap,
  289. &state->ca,
  290. /* flags */ 0,
  291. /* n_slots */ 1);
  292. if (0 != ret) {
  293. err("Cannot initialize CI: Error %d.", ret);
  294. memset(&state->ca, 0, sizeof(state->ca));
  295. return ret;
  296. }
  297. info("CI initialized.");
  298. return 0;
  299. }
  300. #define CMD_BUFFER_SIZE 0x28
  301. static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 addr,
  302. const u8 *snd_buf, u8 snd_len,
  303. u8 *rcv_buf, u8 rcv_len)
  304. {
  305. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  306. u8 buf[64];
  307. u8 id;
  308. int ret;
  309. id = state->c++;
  310. ret = -EINVAL;
  311. if (snd_len > 64 - 7 || rcv_len > 64 - 7)
  312. goto failed;
  313. buf[0] = SYNC_BYTE_OUT;
  314. buf[1] = id;
  315. buf[2] = PCTV_CMD_I2C;
  316. buf[3] = snd_len + 3;
  317. buf[4] = addr << 1;
  318. buf[5] = snd_len;
  319. buf[6] = rcv_len;
  320. memcpy(buf + 7, snd_buf, snd_len);
  321. ret = dvb_usb_generic_rw(d, buf, 7 + snd_len,
  322. buf, /* rcv_len */ 64,
  323. /* delay_ms */ 0);
  324. if (ret < 0)
  325. goto failed;
  326. /* TT USB protocol error. */
  327. ret = -EIO;
  328. if (SYNC_BYTE_IN != buf[0] || id != buf[1])
  329. goto failed;
  330. /* I2C device didn't respond as expected. */
  331. ret = -EREMOTEIO;
  332. if (buf[5] < snd_len || buf[6] < rcv_len)
  333. goto failed;
  334. memcpy(rcv_buf, buf + 7, rcv_len);
  335. return rcv_len;
  336. failed:
  337. err("I2C error %d; %02X %02X %02X %02X %02X -> "
  338. "%02X %02X %02X %02X %02X.",
  339. ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len,
  340. buf[0], buf[1], buf[4], buf[5], buf[6]);
  341. return ret;
  342. }
  343. static int pctv452e_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msg,
  344. int num)
  345. {
  346. struct dvb_usb_device *d = i2c_get_adapdata(adapter);
  347. int i;
  348. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  349. return -EAGAIN;
  350. for (i = 0; i < num; i++) {
  351. u8 addr, snd_len, rcv_len, *snd_buf, *rcv_buf;
  352. int ret;
  353. if (msg[i].flags & I2C_M_RD) {
  354. addr = msg[i].addr;
  355. snd_buf = NULL;
  356. snd_len = 0;
  357. rcv_buf = msg[i].buf;
  358. rcv_len = msg[i].len;
  359. } else {
  360. addr = msg[i].addr;
  361. snd_buf = msg[i].buf;
  362. snd_len = msg[i].len;
  363. rcv_buf = NULL;
  364. rcv_len = 0;
  365. }
  366. ret = pctv452e_i2c_msg(d, addr, snd_buf, snd_len, rcv_buf,
  367. rcv_len);
  368. if (ret < rcv_len)
  369. break;
  370. }
  371. mutex_unlock(&d->i2c_mutex);
  372. return i;
  373. }
  374. static u32 pctv452e_i2c_func(struct i2c_adapter *adapter)
  375. {
  376. return I2C_FUNC_I2C;
  377. }
  378. static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
  379. {
  380. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  381. u8 b0[] = { 0xaa, 0, PCTV_CMD_RESET, 1, 0 };
  382. u8 rx[PCTV_ANSWER_LEN];
  383. int ret;
  384. info("%s: %d\n", __func__, i);
  385. if (!i)
  386. return 0;
  387. if (state->initialized)
  388. return 0;
  389. /* hmm where shoud this should go? */
  390. ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE);
  391. if (ret != 0)
  392. info("%s: Warning set interface returned: %d\n",
  393. __func__, ret);
  394. /* this is a one-time initialization, dont know where to put */
  395. b0[1] = state->c++;
  396. /* reset board */
  397. ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0);
  398. if (ret)
  399. return ret;
  400. b0[1] = state->c++;
  401. b0[4] = 1;
  402. /* reset board (again?) */
  403. ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0);
  404. if (ret)
  405. return ret;
  406. state->initialized = 1;
  407. return 0;
  408. }
  409. static int pctv452e_rc_query(struct dvb_usb_device *d)
  410. {
  411. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  412. u8 b[CMD_BUFFER_SIZE];
  413. u8 rx[PCTV_ANSWER_LEN];
  414. int ret, i;
  415. u8 id = state->c++;
  416. /* prepare command header */
  417. b[0] = SYNC_BYTE_OUT;
  418. b[1] = id;
  419. b[2] = PCTV_CMD_IR;
  420. b[3] = 0;
  421. /* send ir request */
  422. ret = dvb_usb_generic_rw(d, b, 4, rx, PCTV_ANSWER_LEN, 0);
  423. if (ret != 0)
  424. return ret;
  425. if (debug > 3) {
  426. info("%s: read: %2d: %*ph: ", __func__, ret, 3, rx);
  427. for (i = 0; (i < rx[3]) && ((i+3) < PCTV_ANSWER_LEN); i++)
  428. info(" %02x", rx[i+3]);
  429. info("\n");
  430. }
  431. if ((rx[3] == 9) && (rx[12] & 0x01)) {
  432. /* got a "press" event */
  433. state->last_rc_key = RC_SCANCODE_RC5(rx[7], rx[6]);
  434. if (debug > 2)
  435. info("%s: cmd=0x%02x sys=0x%02x\n",
  436. __func__, rx[6], rx[7]);
  437. rc_keydown(d->rc_dev, RC_TYPE_RC5, state->last_rc_key, 0);
  438. } else if (state->last_rc_key) {
  439. rc_keyup(d->rc_dev);
  440. state->last_rc_key = 0;
  441. }
  442. return 0;
  443. }
  444. static int pctv452e_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
  445. {
  446. const u8 mem_addr[] = { 0x1f, 0xcc };
  447. u8 encoded_mac[20];
  448. int ret;
  449. ret = -EAGAIN;
  450. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  451. goto failed;
  452. ret = pctv452e_i2c_msg(d, I2C_ADDR_24C16,
  453. mem_addr + 1, /* snd_len */ 1,
  454. encoded_mac, /* rcv_len */ 20);
  455. if (-EREMOTEIO == ret)
  456. /* Caution! A 24C16 interprets 0xA2 0x1F 0xCC as a
  457. byte write if /WC is low. */
  458. ret = pctv452e_i2c_msg(d, I2C_ADDR_24C64,
  459. mem_addr, 2,
  460. encoded_mac, 20);
  461. mutex_unlock(&d->i2c_mutex);
  462. if (20 != ret)
  463. goto failed;
  464. ret = ttpci_eeprom_decode_mac(mac, encoded_mac);
  465. if (0 != ret)
  466. goto failed;
  467. return 0;
  468. failed:
  469. eth_zero_addr(mac);
  470. return ret;
  471. }
  472. static const struct stb0899_s1_reg pctv452e_init_dev[] = {
  473. { STB0899_DISCNTRL1, 0x26 },
  474. { STB0899_DISCNTRL2, 0x80 },
  475. { STB0899_DISRX_ST0, 0x04 },
  476. { STB0899_DISRX_ST1, 0x20 },
  477. { STB0899_DISPARITY, 0x00 },
  478. { STB0899_DISFIFO, 0x00 },
  479. { STB0899_DISF22, 0x99 },
  480. { STB0899_DISF22RX, 0x85 }, /* 0xa8 */
  481. { STB0899_ACRPRESC, 0x11 },
  482. { STB0899_ACRDIV1, 0x0a },
  483. { STB0899_ACRDIV2, 0x05 },
  484. { STB0899_DACR1 , 0x00 },
  485. { STB0899_DACR2 , 0x00 },
  486. { STB0899_OUTCFG, 0x00 },
  487. { STB0899_MODECFG, 0x00 }, /* Inversion */
  488. { STB0899_IRQMSK_3, 0xf3 },
  489. { STB0899_IRQMSK_2, 0xfc },
  490. { STB0899_IRQMSK_1, 0xff },
  491. { STB0899_IRQMSK_0, 0xff },
  492. { STB0899_I2CCFG, 0x88 },
  493. { STB0899_I2CRPT, 0x58 },
  494. { STB0899_GPIO00CFG, 0x82 },
  495. { STB0899_GPIO01CFG, 0x82 }, /* LED: 0x02 green, 0x82 orange */
  496. { STB0899_GPIO02CFG, 0x82 },
  497. { STB0899_GPIO03CFG, 0x82 },
  498. { STB0899_GPIO04CFG, 0x82 },
  499. { STB0899_GPIO05CFG, 0x82 },
  500. { STB0899_GPIO06CFG, 0x82 },
  501. { STB0899_GPIO07CFG, 0x82 },
  502. { STB0899_GPIO08CFG, 0x82 },
  503. { STB0899_GPIO09CFG, 0x82 },
  504. { STB0899_GPIO10CFG, 0x82 },
  505. { STB0899_GPIO11CFG, 0x82 },
  506. { STB0899_GPIO12CFG, 0x82 },
  507. { STB0899_GPIO13CFG, 0x82 },
  508. { STB0899_GPIO14CFG, 0x82 },
  509. { STB0899_GPIO15CFG, 0x82 },
  510. { STB0899_GPIO16CFG, 0x82 },
  511. { STB0899_GPIO17CFG, 0x82 },
  512. { STB0899_GPIO18CFG, 0x82 },
  513. { STB0899_GPIO19CFG, 0x82 },
  514. { STB0899_GPIO20CFG, 0x82 },
  515. { STB0899_SDATCFG, 0xb8 },
  516. { STB0899_SCLTCFG, 0xba },
  517. { STB0899_AGCRFCFG, 0x1c }, /* 0x11 DVB-S; 0x1c DVB-S2 (1c, rjkm) */
  518. { STB0899_GPIO22, 0x82 },
  519. { STB0899_GPIO21, 0x91 },
  520. { STB0899_DIRCLKCFG, 0x82 },
  521. { STB0899_CLKOUT27CFG, 0x7e },
  522. { STB0899_STDBYCFG, 0x82 },
  523. { STB0899_CS0CFG, 0x82 },
  524. { STB0899_CS1CFG, 0x82 },
  525. { STB0899_DISEQCOCFG, 0x20 },
  526. { STB0899_NCOARSE, 0x15 }, /* 0x15 27Mhz, F/3 198MHz, F/6 108MHz */
  527. { STB0899_SYNTCTRL, 0x00 }, /* 0x00 CLKI, 0x02 XTALI */
  528. { STB0899_FILTCTRL, 0x00 },
  529. { STB0899_SYSCTRL, 0x00 },
  530. { STB0899_STOPCLK1, 0x20 }, /* orig: 0x00 budget-ci: 0x20 */
  531. { STB0899_STOPCLK2, 0x00 },
  532. { STB0899_INTBUFCTRL, 0x0a },
  533. { STB0899_AGC2I1, 0x00 },
  534. { STB0899_AGC2I2, 0x00 },
  535. { STB0899_AGCIQIN, 0x00 },
  536. { STB0899_TSTRES, 0x40 }, /* rjkm */
  537. { 0xffff, 0xff },
  538. };
  539. static const struct stb0899_s1_reg pctv452e_init_s1_demod[] = {
  540. { STB0899_DEMOD, 0x00 },
  541. { STB0899_RCOMPC, 0xc9 },
  542. { STB0899_AGC1CN, 0x01 },
  543. { STB0899_AGC1REF, 0x10 },
  544. { STB0899_RTC, 0x23 },
  545. { STB0899_TMGCFG, 0x4e },
  546. { STB0899_AGC2REF, 0x34 },
  547. { STB0899_TLSR, 0x84 },
  548. { STB0899_CFD, 0xf7 },
  549. { STB0899_ACLC, 0x87 },
  550. { STB0899_BCLC, 0x94 },
  551. { STB0899_EQON, 0x41 },
  552. { STB0899_LDT, 0xf1 },
  553. { STB0899_LDT2, 0xe3 },
  554. { STB0899_EQUALREF, 0xb4 },
  555. { STB0899_TMGRAMP, 0x10 },
  556. { STB0899_TMGTHD, 0x30 },
  557. { STB0899_IDCCOMP, 0xfd },
  558. { STB0899_QDCCOMP, 0xff },
  559. { STB0899_POWERI, 0x0c },
  560. { STB0899_POWERQ, 0x0f },
  561. { STB0899_RCOMP, 0x6c },
  562. { STB0899_AGCIQIN, 0x80 },
  563. { STB0899_AGC2I1, 0x06 },
  564. { STB0899_AGC2I2, 0x00 },
  565. { STB0899_TLIR, 0x30 },
  566. { STB0899_RTF, 0x7f },
  567. { STB0899_DSTATUS, 0x00 },
  568. { STB0899_LDI, 0xbc },
  569. { STB0899_CFRM, 0xea },
  570. { STB0899_CFRL, 0x31 },
  571. { STB0899_NIRM, 0x2b },
  572. { STB0899_NIRL, 0x80 },
  573. { STB0899_ISYMB, 0x1d },
  574. { STB0899_QSYMB, 0xa6 },
  575. { STB0899_SFRH, 0x2f },
  576. { STB0899_SFRM, 0x68 },
  577. { STB0899_SFRL, 0x40 },
  578. { STB0899_SFRUPH, 0x2f },
  579. { STB0899_SFRUPM, 0x68 },
  580. { STB0899_SFRUPL, 0x40 },
  581. { STB0899_EQUAI1, 0x02 },
  582. { STB0899_EQUAQ1, 0xff },
  583. { STB0899_EQUAI2, 0x04 },
  584. { STB0899_EQUAQ2, 0x05 },
  585. { STB0899_EQUAI3, 0x02 },
  586. { STB0899_EQUAQ3, 0xfd },
  587. { STB0899_EQUAI4, 0x03 },
  588. { STB0899_EQUAQ4, 0x07 },
  589. { STB0899_EQUAI5, 0x08 },
  590. { STB0899_EQUAQ5, 0xf5 },
  591. { STB0899_DSTATUS2, 0x00 },
  592. { STB0899_VSTATUS, 0x00 },
  593. { STB0899_VERROR, 0x86 },
  594. { STB0899_IQSWAP, 0x2a },
  595. { STB0899_ECNT1M, 0x00 },
  596. { STB0899_ECNT1L, 0x00 },
  597. { STB0899_ECNT2M, 0x00 },
  598. { STB0899_ECNT2L, 0x00 },
  599. { STB0899_ECNT3M, 0x0a },
  600. { STB0899_ECNT3L, 0xad },
  601. { STB0899_FECAUTO1, 0x06 },
  602. { STB0899_FECM, 0x01 },
  603. { STB0899_VTH12, 0xb0 },
  604. { STB0899_VTH23, 0x7a },
  605. { STB0899_VTH34, 0x58 },
  606. { STB0899_VTH56, 0x38 },
  607. { STB0899_VTH67, 0x34 },
  608. { STB0899_VTH78, 0x24 },
  609. { STB0899_PRVIT, 0xff },
  610. { STB0899_VITSYNC, 0x19 },
  611. { STB0899_RSULC, 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
  612. { STB0899_TSULC, 0x42 },
  613. { STB0899_RSLLC, 0x41 },
  614. { STB0899_TSLPL, 0x12 },
  615. { STB0899_TSCFGH, 0x0c },
  616. { STB0899_TSCFGM, 0x00 },
  617. { STB0899_TSCFGL, 0x00 },
  618. { STB0899_TSOUT, 0x69 }, /* 0x0d for CAM */
  619. { STB0899_RSSYNCDEL, 0x00 },
  620. { STB0899_TSINHDELH, 0x02 },
  621. { STB0899_TSINHDELM, 0x00 },
  622. { STB0899_TSINHDELL, 0x00 },
  623. { STB0899_TSLLSTKM, 0x1b },
  624. { STB0899_TSLLSTKL, 0xb3 },
  625. { STB0899_TSULSTKM, 0x00 },
  626. { STB0899_TSULSTKL, 0x00 },
  627. { STB0899_PCKLENUL, 0xbc },
  628. { STB0899_PCKLENLL, 0xcc },
  629. { STB0899_RSPCKLEN, 0xbd },
  630. { STB0899_TSSTATUS, 0x90 },
  631. { STB0899_ERRCTRL1, 0xb6 },
  632. { STB0899_ERRCTRL2, 0x95 },
  633. { STB0899_ERRCTRL3, 0x8d },
  634. { STB0899_DMONMSK1, 0x27 },
  635. { STB0899_DMONMSK0, 0x03 },
  636. { STB0899_DEMAPVIT, 0x5c },
  637. { STB0899_PLPARM, 0x19 },
  638. { STB0899_PDELCTRL, 0x48 },
  639. { STB0899_PDELCTRL2, 0x00 },
  640. { STB0899_BBHCTRL1, 0x00 },
  641. { STB0899_BBHCTRL2, 0x00 },
  642. { STB0899_HYSTTHRESH, 0x77 },
  643. { STB0899_MATCSTM, 0x00 },
  644. { STB0899_MATCSTL, 0x00 },
  645. { STB0899_UPLCSTM, 0x00 },
  646. { STB0899_UPLCSTL, 0x00 },
  647. { STB0899_DFLCSTM, 0x00 },
  648. { STB0899_DFLCSTL, 0x00 },
  649. { STB0899_SYNCCST, 0x00 },
  650. { STB0899_SYNCDCSTM, 0x00 },
  651. { STB0899_SYNCDCSTL, 0x00 },
  652. { STB0899_ISI_ENTRY, 0x00 },
  653. { STB0899_ISI_BIT_EN, 0x00 },
  654. { STB0899_MATSTRM, 0xf0 },
  655. { STB0899_MATSTRL, 0x02 },
  656. { STB0899_UPLSTRM, 0x45 },
  657. { STB0899_UPLSTRL, 0x60 },
  658. { STB0899_DFLSTRM, 0xe3 },
  659. { STB0899_DFLSTRL, 0x00 },
  660. { STB0899_SYNCSTR, 0x47 },
  661. { STB0899_SYNCDSTRM, 0x05 },
  662. { STB0899_SYNCDSTRL, 0x18 },
  663. { STB0899_CFGPDELSTATUS1, 0x19 },
  664. { STB0899_CFGPDELSTATUS2, 0x2b },
  665. { STB0899_BBFERRORM, 0x00 },
  666. { STB0899_BBFERRORL, 0x01 },
  667. { STB0899_UPKTERRORM, 0x00 },
  668. { STB0899_UPKTERRORL, 0x00 },
  669. { 0xffff, 0xff },
  670. };
  671. static struct stb0899_config stb0899_config = {
  672. .init_dev = pctv452e_init_dev,
  673. .init_s2_demod = stb0899_s2_init_2,
  674. .init_s1_demod = pctv452e_init_s1_demod,
  675. .init_s2_fec = stb0899_s2_init_4,
  676. .init_tst = stb0899_s1_init_5,
  677. .demod_address = I2C_ADDR_STB0899, /* I2C Address */
  678. .block_sync_mode = STB0899_SYNC_FORCED, /* ? */
  679. .xtal_freq = 27000000, /* Assume Hz ? */
  680. .inversion = IQ_SWAP_ON,
  681. .lo_clk = 76500000,
  682. .hi_clk = 99000000,
  683. .ts_output_mode = 0, /* Use parallel mode */
  684. .clock_polarity = 0,
  685. .data_clk_parity = 0,
  686. .fec_mode = 0,
  687. .esno_ave = STB0899_DVBS2_ESNO_AVE,
  688. .esno_quant = STB0899_DVBS2_ESNO_QUANT,
  689. .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
  690. .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
  691. .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
  692. .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
  693. .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
  694. .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
  695. .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
  696. .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
  697. .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
  698. .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
  699. .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
  700. .tuner_get_frequency = stb6100_get_frequency,
  701. .tuner_set_frequency = stb6100_set_frequency,
  702. .tuner_set_bandwidth = stb6100_set_bandwidth,
  703. .tuner_get_bandwidth = stb6100_get_bandwidth,
  704. .tuner_set_rfsiggain = NULL,
  705. /* helper for switching LED green/orange */
  706. .postproc = pctv45e_postproc
  707. };
  708. static struct stb6100_config stb6100_config = {
  709. .tuner_address = I2C_ADDR_STB6100,
  710. .refclock = 27000000
  711. };
  712. static struct i2c_algorithm pctv452e_i2c_algo = {
  713. .master_xfer = pctv452e_i2c_xfer,
  714. .functionality = pctv452e_i2c_func
  715. };
  716. static int pctv452e_frontend_attach(struct dvb_usb_adapter *a)
  717. {
  718. struct usb_device_id *id;
  719. a->fe_adap[0].fe = dvb_attach(stb0899_attach, &stb0899_config,
  720. &a->dev->i2c_adap);
  721. if (!a->fe_adap[0].fe)
  722. return -ENODEV;
  723. if ((dvb_attach(lnbp22_attach, a->fe_adap[0].fe,
  724. &a->dev->i2c_adap)) == NULL)
  725. err("Cannot attach lnbp22\n");
  726. id = a->dev->desc->warm_ids[0];
  727. if (USB_VID_TECHNOTREND == id->idVendor
  728. && USB_PID_TECHNOTREND_CONNECT_S2_3650_CI == id->idProduct)
  729. /* Error ignored. */
  730. tt3650_ci_init(a);
  731. return 0;
  732. }
  733. static int pctv452e_tuner_attach(struct dvb_usb_adapter *a)
  734. {
  735. if (!a->fe_adap[0].fe)
  736. return -ENODEV;
  737. if (dvb_attach(stb6100_attach, a->fe_adap[0].fe, &stb6100_config,
  738. &a->dev->i2c_adap) == NULL) {
  739. err("%s failed\n", __func__);
  740. return -ENODEV;
  741. }
  742. return 0;
  743. }
  744. static struct usb_device_id pctv452e_usb_table[] = {
  745. {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_452E)},
  746. {USB_DEVICE(USB_VID_TECHNOTREND, USB_PID_TECHNOTREND_CONNECT_S2_3600)},
  747. {USB_DEVICE(USB_VID_TECHNOTREND,
  748. USB_PID_TECHNOTREND_CONNECT_S2_3650_CI)},
  749. {}
  750. };
  751. MODULE_DEVICE_TABLE(usb, pctv452e_usb_table);
  752. static struct dvb_usb_device_properties pctv452e_properties = {
  753. .caps = DVB_USB_IS_AN_I2C_ADAPTER, /* more ? */
  754. .usb_ctrl = DEVICE_SPECIFIC,
  755. .size_of_priv = sizeof(struct pctv452e_state),
  756. .power_ctrl = pctv452e_power_ctrl,
  757. .rc.core = {
  758. .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
  759. .allowed_protos = RC_BIT_RC5,
  760. .rc_query = pctv452e_rc_query,
  761. .rc_interval = 100,
  762. },
  763. .num_adapters = 1,
  764. .adapter = {{
  765. .num_frontends = 1,
  766. .fe = {{
  767. .frontend_attach = pctv452e_frontend_attach,
  768. .tuner_attach = pctv452e_tuner_attach,
  769. /* parameter for the MPEG2-data transfer */
  770. .stream = {
  771. .type = USB_ISOC,
  772. .count = 4,
  773. .endpoint = 0x02,
  774. .u = {
  775. .isoc = {
  776. .framesperurb = 4,
  777. .framesize = 940,
  778. .interval = 1
  779. }
  780. }
  781. },
  782. } },
  783. } },
  784. .i2c_algo = &pctv452e_i2c_algo,
  785. .generic_bulk_ctrl_endpoint = 1, /* allow generice rw function */
  786. .num_device_descs = 1,
  787. .devices = {
  788. { .name = "PCTV HDTV USB",
  789. .cold_ids = { NULL, NULL }, /* this is a warm only device */
  790. .warm_ids = { &pctv452e_usb_table[0], NULL }
  791. },
  792. { NULL },
  793. }
  794. };
  795. static struct dvb_usb_device_properties tt_connect_s2_3600_properties = {
  796. .caps = DVB_USB_IS_AN_I2C_ADAPTER, /* more ? */
  797. .usb_ctrl = DEVICE_SPECIFIC,
  798. .size_of_priv = sizeof(struct pctv452e_state),
  799. .power_ctrl = pctv452e_power_ctrl,
  800. .read_mac_address = pctv452e_read_mac_address,
  801. .rc.core = {
  802. .rc_codes = RC_MAP_TT_1500,
  803. .allowed_protos = RC_BIT_RC5,
  804. .rc_query = pctv452e_rc_query,
  805. .rc_interval = 100,
  806. },
  807. .num_adapters = 1,
  808. .adapter = {{
  809. .num_frontends = 1,
  810. .fe = {{
  811. .frontend_attach = pctv452e_frontend_attach,
  812. .tuner_attach = pctv452e_tuner_attach,
  813. /* parameter for the MPEG2-data transfer */
  814. .stream = {
  815. .type = USB_ISOC,
  816. .count = 7,
  817. .endpoint = 0x02,
  818. .u = {
  819. .isoc = {
  820. .framesperurb = 4,
  821. .framesize = 940,
  822. .interval = 1
  823. }
  824. }
  825. },
  826. } },
  827. } },
  828. .i2c_algo = &pctv452e_i2c_algo,
  829. .generic_bulk_ctrl_endpoint = 1, /* allow generic rw function*/
  830. .num_device_descs = 2,
  831. .devices = {
  832. { .name = "Technotrend TT Connect S2-3600",
  833. .cold_ids = { NULL, NULL }, /* this is a warm only device */
  834. .warm_ids = { &pctv452e_usb_table[1], NULL }
  835. },
  836. { .name = "Technotrend TT Connect S2-3650-CI",
  837. .cold_ids = { NULL, NULL },
  838. .warm_ids = { &pctv452e_usb_table[2], NULL }
  839. },
  840. { NULL },
  841. }
  842. };
  843. static void pctv452e_usb_disconnect(struct usb_interface *intf)
  844. {
  845. struct dvb_usb_device *d = usb_get_intfdata(intf);
  846. tt3650_ci_uninit(d);
  847. dvb_usb_device_exit(intf);
  848. }
  849. static int pctv452e_usb_probe(struct usb_interface *intf,
  850. const struct usb_device_id *id)
  851. {
  852. if (0 == dvb_usb_device_init(intf, &pctv452e_properties,
  853. THIS_MODULE, NULL, adapter_nr) ||
  854. 0 == dvb_usb_device_init(intf, &tt_connect_s2_3600_properties,
  855. THIS_MODULE, NULL, adapter_nr))
  856. return 0;
  857. return -ENODEV;
  858. }
  859. static struct usb_driver pctv452e_usb_driver = {
  860. .name = "pctv452e",
  861. .probe = pctv452e_usb_probe,
  862. .disconnect = pctv452e_usb_disconnect,
  863. .id_table = pctv452e_usb_table,
  864. };
  865. module_usb_driver(pctv452e_usb_driver);
  866. MODULE_AUTHOR("Dominik Kuhlen <dkuhlen@gmx.net>");
  867. MODULE_AUTHOR("Andre Weidemann <Andre.Weidemann@web.de>");
  868. MODULE_AUTHOR("Michael H. Schimek <mschimek@gmx.at>");
  869. MODULE_DESCRIPTION("Pinnacle PCTV HDTV USB DVB / TT connect S2-3600 Driver");
  870. MODULE_LICENSE("GPL");