pctv452e.c 25 KB

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