pctv452e.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * PCTV 452e DVB driver
  4. *
  5. * Copyright (c) 2006-2008 Dominik Kuhlen <[email protected]>
  6. *
  7. * TT connect S2-3650-CI Common Interface support, MAC readout
  8. * Copyright (C) 2008 Michael H. Schimek <[email protected]>
  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. static int debug;
  26. module_param(debug, int, 0644);
  27. MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
  28. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  29. #define ISOC_INTERFACE_ALTERNATIVE 3
  30. #define SYNC_BYTE_OUT 0xaa
  31. #define SYNC_BYTE_IN 0x55
  32. /* guessed: (copied from ttusb-budget) */
  33. #define PCTV_CMD_RESET 0x15
  34. /* command to poll IR receiver */
  35. #define PCTV_CMD_IR 0x1b
  36. /* command to send I2C */
  37. #define PCTV_CMD_I2C 0x31
  38. #define I2C_ADDR_STB0899 (0xd0 >> 1)
  39. #define I2C_ADDR_STB6100 (0xc0 >> 1)
  40. #define I2C_ADDR_LNBP22 (0x10 >> 1)
  41. #define I2C_ADDR_24C16 (0xa0 >> 1)
  42. #define I2C_ADDR_24C64 (0xa2 >> 1)
  43. /* pctv452e sends us this amount of data for each issued usb-command */
  44. #define PCTV_ANSWER_LEN 64
  45. /* Wait up to 1000ms for device */
  46. #define PCTV_TIMEOUT 1000
  47. #define PCTV_LED_GPIO STB0899_GPIO01
  48. #define PCTV_LED_GREEN 0x82
  49. #define PCTV_LED_ORANGE 0x02
  50. #define ci_dbg(format, arg...) \
  51. do { \
  52. if (0) \
  53. printk(KERN_DEBUG DVB_USB_LOG_PREFIX \
  54. ": " format "\n" , ## arg); \
  55. } while (0)
  56. enum {
  57. TT3650_CMD_CI_TEST = 0x40,
  58. TT3650_CMD_CI_RD_CTRL,
  59. TT3650_CMD_CI_WR_CTRL,
  60. TT3650_CMD_CI_RD_ATTR,
  61. TT3650_CMD_CI_WR_ATTR,
  62. TT3650_CMD_CI_RESET,
  63. TT3650_CMD_CI_SET_VIDEO_PORT
  64. };
  65. static struct stb0899_postproc pctv45e_postproc[] = {
  66. { PCTV_LED_GPIO, STB0899_GPIOPULLUP },
  67. { 0, 0 }
  68. };
  69. static struct isl6423_config pctv452e_isl6423_config = {
  70. .current_max = SEC_CURRENT_515m,
  71. .curlim = SEC_CURRENT_LIM_ON,
  72. .mod_extern = 1,
  73. .addr = 0x08,
  74. };
  75. /*
  76. * stores all private variables for communication with the PCTV452e DVB-S2
  77. */
  78. struct pctv452e_state {
  79. struct dvb_ca_en50221 ca;
  80. struct mutex ca_mutex;
  81. u8 c; /* transaction counter, wraps around... */
  82. u8 initialized; /* set to 1 if 0x15 has been sent */
  83. u16 last_rc_key;
  84. };
  85. static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
  86. unsigned int write_len, unsigned int read_len)
  87. {
  88. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  89. u8 *buf;
  90. u8 id;
  91. unsigned int rlen;
  92. int ret;
  93. if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
  94. err("%s: transfer data invalid", __func__);
  95. return -EIO;
  96. }
  97. buf = kmalloc(64, GFP_KERNEL);
  98. if (!buf)
  99. return -ENOMEM;
  100. id = state->c++;
  101. buf[0] = SYNC_BYTE_OUT;
  102. buf[1] = id;
  103. buf[2] = cmd;
  104. buf[3] = write_len;
  105. memcpy(buf + 4, data, write_len);
  106. rlen = (read_len > 0) ? 64 : 0;
  107. ret = dvb_usb_generic_rw(d, buf, 4 + write_len,
  108. buf, rlen, /* delay_ms */ 0);
  109. if (0 != ret)
  110. goto failed;
  111. ret = -EIO;
  112. if (SYNC_BYTE_IN != buf[0] || id != buf[1])
  113. goto failed;
  114. memcpy(data, buf + 4, read_len);
  115. kfree(buf);
  116. return 0;
  117. failed:
  118. err("CI error %d; %02X %02X %02X -> %*ph.",
  119. ret, SYNC_BYTE_OUT, id, cmd, 3, buf);
  120. kfree(buf);
  121. return ret;
  122. }
  123. static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca,
  124. u8 cmd, u8 *data, unsigned int write_len,
  125. unsigned int read_len)
  126. {
  127. struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
  128. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  129. int ret;
  130. mutex_lock(&state->ca_mutex);
  131. ret = tt3650_ci_msg(d, cmd, data, write_len, read_len);
  132. mutex_unlock(&state->ca_mutex);
  133. return ret;
  134. }
  135. static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
  136. int slot, int address)
  137. {
  138. u8 buf[3];
  139. int ret;
  140. if (0 != slot)
  141. return -EINVAL;
  142. buf[0] = (address >> 8) & 0x0F;
  143. buf[1] = address;
  144. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3);
  145. ci_dbg("%s %04x -> %d 0x%02x",
  146. __func__, address, ret, buf[2]);
  147. if (ret < 0)
  148. return ret;
  149. return buf[2];
  150. }
  151. static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
  152. int slot, int address, u8 value)
  153. {
  154. u8 buf[3];
  155. ci_dbg("%s %d 0x%04x 0x%02x",
  156. __func__, slot, address, value);
  157. if (0 != slot)
  158. return -EINVAL;
  159. buf[0] = (address >> 8) & 0x0F;
  160. buf[1] = address;
  161. buf[2] = value;
  162. return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3);
  163. }
  164. static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca,
  165. int slot,
  166. u8 address)
  167. {
  168. u8 buf[2];
  169. int ret;
  170. if (0 != slot)
  171. return -EINVAL;
  172. buf[0] = address & 3;
  173. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2);
  174. ci_dbg("%s 0x%02x -> %d 0x%02x",
  175. __func__, address, ret, buf[1]);
  176. if (ret < 0)
  177. return ret;
  178. return buf[1];
  179. }
  180. static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca,
  181. int slot,
  182. u8 address,
  183. u8 value)
  184. {
  185. u8 buf[2];
  186. ci_dbg("%s %d 0x%02x 0x%02x",
  187. __func__, slot, address, value);
  188. if (0 != slot)
  189. return -EINVAL;
  190. buf[0] = address;
  191. buf[1] = value;
  192. return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2);
  193. }
  194. static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca,
  195. int slot,
  196. int enable)
  197. {
  198. u8 buf[1];
  199. int ret;
  200. ci_dbg("%s %d %d", __func__, slot, enable);
  201. if (0 != slot)
  202. return -EINVAL;
  203. enable = !!enable;
  204. buf[0] = enable;
  205. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
  206. if (ret < 0)
  207. return ret;
  208. if (enable != buf[0]) {
  209. err("CI not %sabled.", enable ? "en" : "dis");
  210. return -EIO;
  211. }
  212. return 0;
  213. }
  214. static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
  215. {
  216. return tt3650_ci_set_video_port(ca, slot, /* enable */ 0);
  217. }
  218. static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
  219. {
  220. return tt3650_ci_set_video_port(ca, slot, /* enable */ 1);
  221. }
  222. static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
  223. {
  224. struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
  225. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  226. u8 buf[1];
  227. int ret;
  228. ci_dbg("%s %d", __func__, slot);
  229. if (0 != slot)
  230. return -EINVAL;
  231. buf[0] = 0;
  232. mutex_lock(&state->ca_mutex);
  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] = 1;
  238. ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1);
  239. if (0 != ret)
  240. goto failed;
  241. msleep(500);
  242. buf[0] = 0; /* FTA */
  243. ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1);
  244. failed:
  245. mutex_unlock(&state->ca_mutex);
  246. return ret;
  247. }
  248. static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca,
  249. int slot,
  250. int open)
  251. {
  252. u8 buf[1];
  253. int ret;
  254. if (0 != slot)
  255. return -EINVAL;
  256. ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1);
  257. if (0 != ret)
  258. return ret;
  259. if (1 == buf[0])
  260. return DVB_CA_EN50221_POLL_CAM_PRESENT |
  261. DVB_CA_EN50221_POLL_CAM_READY;
  262. return 0;
  263. }
  264. static void tt3650_ci_uninit(struct dvb_usb_device *d)
  265. {
  266. struct pctv452e_state *state;
  267. ci_dbg("%s", __func__);
  268. if (NULL == d)
  269. return;
  270. state = (struct pctv452e_state *)d->priv;
  271. if (NULL == state)
  272. return;
  273. if (NULL == state->ca.data)
  274. return;
  275. /* Error ignored. */
  276. tt3650_ci_set_video_port(&state->ca, /* slot */ 0, /* enable */ 0);
  277. dvb_ca_en50221_release(&state->ca);
  278. memset(&state->ca, 0, sizeof(state->ca));
  279. }
  280. static int tt3650_ci_init(struct dvb_usb_adapter *a)
  281. {
  282. struct dvb_usb_device *d = a->dev;
  283. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  284. int ret;
  285. ci_dbg("%s", __func__);
  286. mutex_init(&state->ca_mutex);
  287. state->ca.owner = THIS_MODULE;
  288. state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem;
  289. state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem;
  290. state->ca.read_cam_control = tt3650_ci_read_cam_control;
  291. state->ca.write_cam_control = tt3650_ci_write_cam_control;
  292. state->ca.slot_reset = tt3650_ci_slot_reset;
  293. state->ca.slot_shutdown = tt3650_ci_slot_shutdown;
  294. state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable;
  295. state->ca.poll_slot_status = tt3650_ci_poll_slot_status;
  296. state->ca.data = d;
  297. ret = dvb_ca_en50221_init(&a->dvb_adap,
  298. &state->ca,
  299. /* flags */ 0,
  300. /* n_slots */ 1);
  301. if (0 != ret) {
  302. err("Cannot initialize CI: Error %d.", ret);
  303. memset(&state->ca, 0, sizeof(state->ca));
  304. return ret;
  305. }
  306. info("CI initialized.");
  307. return 0;
  308. }
  309. #define CMD_BUFFER_SIZE 0x28
  310. static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 addr,
  311. const u8 *snd_buf, u8 snd_len,
  312. u8 *rcv_buf, u8 rcv_len)
  313. {
  314. struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
  315. u8 *buf;
  316. u8 id;
  317. int ret;
  318. buf = kmalloc(64, GFP_KERNEL);
  319. if (!buf)
  320. return -ENOMEM;
  321. id = state->c++;
  322. ret = -EINVAL;
  323. if (snd_len > 64 - 7 || rcv_len > 64 - 7)
  324. goto failed;
  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 = (struct pctv452e_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 = (struct pctv452e_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 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. 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 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 <[email protected]>");
  907. MODULE_AUTHOR("Andre Weidemann <[email protected]>");
  908. MODULE_AUTHOR("Michael H. Schimek <[email protected]>");
  909. MODULE_DESCRIPTION("Pinnacle PCTV HDTV USB DVB / TT connect S2-3600 Driver");
  910. MODULE_LICENSE("GPL");