pctv452e.c 25 KB

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