pctv452e.c 25 KB

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