ascot2e.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ascot2e.c
  4. *
  5. * Sony Ascot3E DVB-T/T2/C/C2 tuner driver
  6. *
  7. * Copyright 2012 Sony Corporation
  8. * Copyright (C) 2014 NetUP Inc.
  9. * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
  10. * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/module.h>
  14. #include <linux/dvb/frontend.h>
  15. #include <linux/types.h>
  16. #include "ascot2e.h"
  17. #include <media/dvb_frontend.h>
  18. #define MAX_WRITE_REGSIZE 10
  19. enum ascot2e_state {
  20. STATE_UNKNOWN,
  21. STATE_SLEEP,
  22. STATE_ACTIVE
  23. };
  24. struct ascot2e_priv {
  25. u32 frequency;
  26. u8 i2c_address;
  27. struct i2c_adapter *i2c;
  28. enum ascot2e_state state;
  29. void *set_tuner_data;
  30. int (*set_tuner)(void *, int);
  31. };
  32. enum ascot2e_tv_system_t {
  33. ASCOT2E_DTV_DVBT_5,
  34. ASCOT2E_DTV_DVBT_6,
  35. ASCOT2E_DTV_DVBT_7,
  36. ASCOT2E_DTV_DVBT_8,
  37. ASCOT2E_DTV_DVBT2_1_7,
  38. ASCOT2E_DTV_DVBT2_5,
  39. ASCOT2E_DTV_DVBT2_6,
  40. ASCOT2E_DTV_DVBT2_7,
  41. ASCOT2E_DTV_DVBT2_8,
  42. ASCOT2E_DTV_DVBC_6,
  43. ASCOT2E_DTV_DVBC_8,
  44. ASCOT2E_DTV_DVBC2_6,
  45. ASCOT2E_DTV_DVBC2_8,
  46. ASCOT2E_DTV_UNKNOWN
  47. };
  48. struct ascot2e_band_sett {
  49. u8 if_out_sel;
  50. u8 agc_sel;
  51. u8 mix_oll;
  52. u8 rf_gain;
  53. u8 if_bpf_gc;
  54. u8 fif_offset;
  55. u8 bw_offset;
  56. u8 bw;
  57. u8 rf_oldet;
  58. u8 if_bpf_f0;
  59. };
  60. #define ASCOT2E_AUTO 0xff
  61. #define ASCOT2E_OFFSET(ofs) ((u8)(ofs) & 0x1F)
  62. #define ASCOT2E_BW_6 0x00
  63. #define ASCOT2E_BW_7 0x01
  64. #define ASCOT2E_BW_8 0x02
  65. #define ASCOT2E_BW_1_7 0x03
  66. static struct ascot2e_band_sett ascot2e_sett[] = {
  67. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  68. ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 },
  69. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  70. ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 },
  71. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  72. ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_7, 0x0B, 0x00 },
  73. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  74. ASCOT2E_OFFSET(-4), ASCOT2E_OFFSET(-2), ASCOT2E_BW_8, 0x0B, 0x00 },
  75. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  76. ASCOT2E_OFFSET(-10), ASCOT2E_OFFSET(-16), ASCOT2E_BW_1_7, 0x0B, 0x00 },
  77. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  78. ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 },
  79. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  80. ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 },
  81. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  82. ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_7, 0x0B, 0x00 },
  83. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06,
  84. ASCOT2E_OFFSET(-4), ASCOT2E_OFFSET(-2), ASCOT2E_BW_8, 0x0B, 0x00 },
  85. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x02, ASCOT2E_AUTO, 0x03,
  86. ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-8), ASCOT2E_BW_6, 0x09, 0x00 },
  87. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x02, ASCOT2E_AUTO, 0x03,
  88. ASCOT2E_OFFSET(-2), ASCOT2E_OFFSET(-1), ASCOT2E_BW_8, 0x09, 0x00 },
  89. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x01,
  90. ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_6, 0x09, 0x00 },
  91. { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x01,
  92. ASCOT2E_OFFSET(-2), ASCOT2E_OFFSET(2), ASCOT2E_BW_8, 0x09, 0x00 }
  93. };
  94. static void ascot2e_i2c_debug(struct ascot2e_priv *priv,
  95. u8 reg, u8 write, const u8 *data, u32 len)
  96. {
  97. dev_dbg(&priv->i2c->dev, "ascot2e: I2C %s reg 0x%02x size %d\n",
  98. (write == 0 ? "read" : "write"), reg, len);
  99. print_hex_dump_bytes("ascot2e: I2C data: ",
  100. DUMP_PREFIX_OFFSET, data, len);
  101. }
  102. static int ascot2e_write_regs(struct ascot2e_priv *priv,
  103. u8 reg, const u8 *data, u32 len)
  104. {
  105. int ret;
  106. u8 buf[MAX_WRITE_REGSIZE + 1];
  107. struct i2c_msg msg[1] = {
  108. {
  109. .addr = priv->i2c_address,
  110. .flags = 0,
  111. .len = len + 1,
  112. .buf = buf,
  113. }
  114. };
  115. if (len + 1 > sizeof(buf)) {
  116. dev_warn(&priv->i2c->dev,"wr reg=%04x: len=%d is too big!\n",
  117. reg, len + 1);
  118. return -E2BIG;
  119. }
  120. ascot2e_i2c_debug(priv, reg, 1, data, len);
  121. buf[0] = reg;
  122. memcpy(&buf[1], data, len);
  123. ret = i2c_transfer(priv->i2c, msg, 1);
  124. if (ret >= 0 && ret != 1)
  125. ret = -EREMOTEIO;
  126. if (ret < 0) {
  127. dev_warn(&priv->i2c->dev,
  128. "%s: i2c wr failed=%d reg=%02x len=%d\n",
  129. KBUILD_MODNAME, ret, reg, len);
  130. return ret;
  131. }
  132. return 0;
  133. }
  134. static int ascot2e_write_reg(struct ascot2e_priv *priv, u8 reg, u8 val)
  135. {
  136. u8 tmp = val; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
  137. return ascot2e_write_regs(priv, reg, &tmp, 1);
  138. }
  139. static int ascot2e_read_regs(struct ascot2e_priv *priv,
  140. u8 reg, u8 *val, u32 len)
  141. {
  142. int ret;
  143. struct i2c_msg msg[2] = {
  144. {
  145. .addr = priv->i2c_address,
  146. .flags = 0,
  147. .len = 1,
  148. .buf = &reg,
  149. }, {
  150. .addr = priv->i2c_address,
  151. .flags = I2C_M_RD,
  152. .len = len,
  153. .buf = val,
  154. }
  155. };
  156. ret = i2c_transfer(priv->i2c, &msg[0], 1);
  157. if (ret >= 0 && ret != 1)
  158. ret = -EREMOTEIO;
  159. if (ret < 0) {
  160. dev_warn(&priv->i2c->dev,
  161. "%s: I2C rw failed=%d addr=%02x reg=%02x\n",
  162. KBUILD_MODNAME, ret, priv->i2c_address, reg);
  163. return ret;
  164. }
  165. ret = i2c_transfer(priv->i2c, &msg[1], 1);
  166. if (ret >= 0 && ret != 1)
  167. ret = -EREMOTEIO;
  168. if (ret < 0) {
  169. dev_warn(&priv->i2c->dev,
  170. "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
  171. KBUILD_MODNAME, ret, priv->i2c_address, reg);
  172. return ret;
  173. }
  174. ascot2e_i2c_debug(priv, reg, 0, val, len);
  175. return 0;
  176. }
  177. static int ascot2e_read_reg(struct ascot2e_priv *priv, u8 reg, u8 *val)
  178. {
  179. return ascot2e_read_regs(priv, reg, val, 1);
  180. }
  181. static int ascot2e_set_reg_bits(struct ascot2e_priv *priv,
  182. u8 reg, u8 data, u8 mask)
  183. {
  184. int res;
  185. u8 rdata;
  186. if (mask != 0xff) {
  187. res = ascot2e_read_reg(priv, reg, &rdata);
  188. if (res != 0)
  189. return res;
  190. data = ((data & mask) | (rdata & (mask ^ 0xFF)));
  191. }
  192. return ascot2e_write_reg(priv, reg, data);
  193. }
  194. static int ascot2e_enter_power_save(struct ascot2e_priv *priv)
  195. {
  196. u8 data[2];
  197. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  198. if (priv->state == STATE_SLEEP)
  199. return 0;
  200. data[0] = 0x00;
  201. data[1] = 0x04;
  202. ascot2e_write_regs(priv, 0x14, data, 2);
  203. ascot2e_write_reg(priv, 0x50, 0x01);
  204. priv->state = STATE_SLEEP;
  205. return 0;
  206. }
  207. static int ascot2e_leave_power_save(struct ascot2e_priv *priv)
  208. {
  209. u8 data[2] = { 0xFB, 0x0F };
  210. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  211. if (priv->state == STATE_ACTIVE)
  212. return 0;
  213. ascot2e_write_regs(priv, 0x14, data, 2);
  214. ascot2e_write_reg(priv, 0x50, 0x00);
  215. priv->state = STATE_ACTIVE;
  216. return 0;
  217. }
  218. static int ascot2e_init(struct dvb_frontend *fe)
  219. {
  220. struct ascot2e_priv *priv = fe->tuner_priv;
  221. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  222. return ascot2e_leave_power_save(priv);
  223. }
  224. static void ascot2e_release(struct dvb_frontend *fe)
  225. {
  226. struct ascot2e_priv *priv = fe->tuner_priv;
  227. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  228. kfree(fe->tuner_priv);
  229. fe->tuner_priv = NULL;
  230. }
  231. static int ascot2e_sleep(struct dvb_frontend *fe)
  232. {
  233. struct ascot2e_priv *priv = fe->tuner_priv;
  234. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  235. ascot2e_enter_power_save(priv);
  236. return 0;
  237. }
  238. static enum ascot2e_tv_system_t ascot2e_get_tv_system(struct dvb_frontend *fe)
  239. {
  240. enum ascot2e_tv_system_t system = ASCOT2E_DTV_UNKNOWN;
  241. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  242. struct ascot2e_priv *priv = fe->tuner_priv;
  243. if (p->delivery_system == SYS_DVBT) {
  244. if (p->bandwidth_hz <= 5000000)
  245. system = ASCOT2E_DTV_DVBT_5;
  246. else if (p->bandwidth_hz <= 6000000)
  247. system = ASCOT2E_DTV_DVBT_6;
  248. else if (p->bandwidth_hz <= 7000000)
  249. system = ASCOT2E_DTV_DVBT_7;
  250. else if (p->bandwidth_hz <= 8000000)
  251. system = ASCOT2E_DTV_DVBT_8;
  252. else {
  253. system = ASCOT2E_DTV_DVBT_8;
  254. p->bandwidth_hz = 8000000;
  255. }
  256. } else if (p->delivery_system == SYS_DVBT2) {
  257. if (p->bandwidth_hz <= 5000000)
  258. system = ASCOT2E_DTV_DVBT2_5;
  259. else if (p->bandwidth_hz <= 6000000)
  260. system = ASCOT2E_DTV_DVBT2_6;
  261. else if (p->bandwidth_hz <= 7000000)
  262. system = ASCOT2E_DTV_DVBT2_7;
  263. else if (p->bandwidth_hz <= 8000000)
  264. system = ASCOT2E_DTV_DVBT2_8;
  265. else {
  266. system = ASCOT2E_DTV_DVBT2_8;
  267. p->bandwidth_hz = 8000000;
  268. }
  269. } else if (p->delivery_system == SYS_DVBC_ANNEX_A) {
  270. if (p->bandwidth_hz <= 6000000)
  271. system = ASCOT2E_DTV_DVBC_6;
  272. else if (p->bandwidth_hz <= 8000000)
  273. system = ASCOT2E_DTV_DVBC_8;
  274. }
  275. dev_dbg(&priv->i2c->dev,
  276. "%s(): ASCOT2E DTV system %d (delsys %d, bandwidth %d)\n",
  277. __func__, (int)system, p->delivery_system, p->bandwidth_hz);
  278. return system;
  279. }
  280. static int ascot2e_set_params(struct dvb_frontend *fe)
  281. {
  282. u8 data[10];
  283. u32 frequency;
  284. enum ascot2e_tv_system_t tv_system;
  285. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  286. struct ascot2e_priv *priv = fe->tuner_priv;
  287. dev_dbg(&priv->i2c->dev, "%s(): tune frequency %dkHz\n",
  288. __func__, p->frequency / 1000);
  289. tv_system = ascot2e_get_tv_system(fe);
  290. if (tv_system == ASCOT2E_DTV_UNKNOWN) {
  291. dev_dbg(&priv->i2c->dev, "%s(): unknown DTV system\n",
  292. __func__);
  293. return -EINVAL;
  294. }
  295. if (priv->set_tuner)
  296. priv->set_tuner(priv->set_tuner_data, 1);
  297. frequency = roundup(p->frequency / 1000, 25);
  298. if (priv->state == STATE_SLEEP)
  299. ascot2e_leave_power_save(priv);
  300. /* IF_OUT_SEL / AGC_SEL setting */
  301. data[0] = 0x00;
  302. if (ascot2e_sett[tv_system].agc_sel != ASCOT2E_AUTO) {
  303. /* AGC pin setting from parameter table */
  304. data[0] |= (u8)(
  305. (ascot2e_sett[tv_system].agc_sel & 0x03) << 3);
  306. }
  307. if (ascot2e_sett[tv_system].if_out_sel != ASCOT2E_AUTO) {
  308. /* IFOUT pin setting from parameter table */
  309. data[0] |= (u8)(
  310. (ascot2e_sett[tv_system].if_out_sel & 0x01) << 2);
  311. }
  312. /* Set bit[4:2] only */
  313. ascot2e_set_reg_bits(priv, 0x05, data[0], 0x1c);
  314. /* 0x06 - 0x0F */
  315. /* REF_R setting (0x06) */
  316. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  317. tv_system == ASCOT2E_DTV_DVBC_8) {
  318. /* xtal, xtal*2 */
  319. data[0] = (frequency > 500000) ? 16 : 32;
  320. } else {
  321. /* xtal/8, xtal/4 */
  322. data[0] = (frequency > 500000) ? 2 : 4;
  323. }
  324. /* XOSC_SEL=100uA */
  325. data[1] = 0x04;
  326. /* KBW setting (0x08), KC0 setting (0x09), KC1 setting (0x0A) */
  327. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  328. tv_system == ASCOT2E_DTV_DVBC_8) {
  329. data[2] = 18;
  330. data[3] = 120;
  331. data[4] = 20;
  332. } else {
  333. data[2] = 48;
  334. data[3] = 10;
  335. data[4] = 30;
  336. }
  337. /* ORDER/R2_RANGE/R2_BANK/C2_BANK setting (0x0B) */
  338. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  339. tv_system == ASCOT2E_DTV_DVBC_8)
  340. data[5] = (frequency > 500000) ? 0x08 : 0x0c;
  341. else
  342. data[5] = (frequency > 500000) ? 0x30 : 0x38;
  343. /* Set MIX_OLL (0x0C) value from parameter table */
  344. data[6] = ascot2e_sett[tv_system].mix_oll;
  345. /* Set RF_GAIN (0x0D) setting from parameter table */
  346. if (ascot2e_sett[tv_system].rf_gain == ASCOT2E_AUTO) {
  347. /* RF_GAIN auto control enable */
  348. ascot2e_write_reg(priv, 0x4E, 0x01);
  349. /* RF_GAIN Default value */
  350. data[7] = 0x00;
  351. } else {
  352. /* RF_GAIN auto control disable */
  353. ascot2e_write_reg(priv, 0x4E, 0x00);
  354. data[7] = ascot2e_sett[tv_system].rf_gain;
  355. }
  356. /* Set IF_BPF_GC/FIF_OFFSET (0x0E) value from parameter table */
  357. data[8] = (u8)((ascot2e_sett[tv_system].fif_offset << 3) |
  358. (ascot2e_sett[tv_system].if_bpf_gc & 0x07));
  359. /* Set BW_OFFSET (0x0F) value from parameter table */
  360. data[9] = ascot2e_sett[tv_system].bw_offset;
  361. ascot2e_write_regs(priv, 0x06, data, 10);
  362. /*
  363. * 0x45 - 0x47
  364. * LNA optimization setting
  365. * RF_LNA_DIST1-5, RF_LNA_CM
  366. */
  367. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  368. tv_system == ASCOT2E_DTV_DVBC_8) {
  369. data[0] = 0x0F;
  370. data[1] = 0x00;
  371. data[2] = 0x01;
  372. } else {
  373. data[0] = 0x0F;
  374. data[1] = 0x00;
  375. data[2] = 0x03;
  376. }
  377. ascot2e_write_regs(priv, 0x45, data, 3);
  378. /* 0x49 - 0x4A
  379. Set RF_OLDET_ENX/RF_OLDET_OLL value from parameter table */
  380. data[0] = ascot2e_sett[tv_system].rf_oldet;
  381. /* Set IF_BPF_F0 value from parameter table */
  382. data[1] = ascot2e_sett[tv_system].if_bpf_f0;
  383. ascot2e_write_regs(priv, 0x49, data, 2);
  384. /*
  385. * Tune now
  386. * RFAGC fast mode / RFAGC auto control enable
  387. * (set bit[7], bit[5:4] only)
  388. * vco_cal = 1, set MIX_OL_CPU_EN
  389. */
  390. ascot2e_set_reg_bits(priv, 0x0c, 0x90, 0xb0);
  391. /* Logic wake up, CPU wake up */
  392. data[0] = 0xc4;
  393. data[1] = 0x40;
  394. ascot2e_write_regs(priv, 0x03, data, 2);
  395. /* 0x10 - 0x14 */
  396. data[0] = (u8)(frequency & 0xFF); /* 0x10: FRF_L */
  397. data[1] = (u8)((frequency >> 8) & 0xFF); /* 0x11: FRF_M */
  398. data[2] = (u8)((frequency >> 16) & 0x0F); /* 0x12: FRF_H (bit[3:0]) */
  399. /* 0x12: BW (bit[5:4]) */
  400. data[2] |= (u8)(ascot2e_sett[tv_system].bw << 4);
  401. data[3] = 0xFF; /* 0x13: VCO calibration enable */
  402. data[4] = 0xFF; /* 0x14: Analog block enable */
  403. /* Tune (Burst write) */
  404. ascot2e_write_regs(priv, 0x10, data, 5);
  405. msleep(50);
  406. /* CPU deep sleep */
  407. ascot2e_write_reg(priv, 0x04, 0x00);
  408. /* Logic sleep */
  409. ascot2e_write_reg(priv, 0x03, 0xC0);
  410. /* RFAGC normal mode (set bit[5:4] only) */
  411. ascot2e_set_reg_bits(priv, 0x0C, 0x00, 0x30);
  412. priv->frequency = frequency;
  413. return 0;
  414. }
  415. static int ascot2e_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  416. {
  417. struct ascot2e_priv *priv = fe->tuner_priv;
  418. *frequency = priv->frequency * 1000;
  419. return 0;
  420. }
  421. static const struct dvb_tuner_ops ascot2e_tuner_ops = {
  422. .info = {
  423. .name = "Sony ASCOT2E",
  424. .frequency_min_hz = 1 * MHz,
  425. .frequency_max_hz = 1200 * MHz,
  426. .frequency_step_hz = 25 * kHz,
  427. },
  428. .init = ascot2e_init,
  429. .release = ascot2e_release,
  430. .sleep = ascot2e_sleep,
  431. .set_params = ascot2e_set_params,
  432. .get_frequency = ascot2e_get_frequency,
  433. };
  434. struct dvb_frontend *ascot2e_attach(struct dvb_frontend *fe,
  435. const struct ascot2e_config *config,
  436. struct i2c_adapter *i2c)
  437. {
  438. u8 data[4];
  439. struct ascot2e_priv *priv = NULL;
  440. priv = kzalloc(sizeof(struct ascot2e_priv), GFP_KERNEL);
  441. if (priv == NULL)
  442. return NULL;
  443. priv->i2c_address = (config->i2c_address >> 1);
  444. priv->i2c = i2c;
  445. priv->set_tuner_data = config->set_tuner_priv;
  446. priv->set_tuner = config->set_tuner_callback;
  447. if (fe->ops.i2c_gate_ctrl)
  448. fe->ops.i2c_gate_ctrl(fe, 1);
  449. /* 16 MHz xTal frequency */
  450. data[0] = 16;
  451. /* VCO current setting */
  452. data[1] = 0x06;
  453. /* Logic wake up, CPU boot */
  454. data[2] = 0xC4;
  455. data[3] = 0x40;
  456. ascot2e_write_regs(priv, 0x01, data, 4);
  457. /* RFVGA optimization setting (RF_DIST0 - RF_DIST2) */
  458. data[0] = 0x10;
  459. data[1] = 0x3F;
  460. data[2] = 0x25;
  461. ascot2e_write_regs(priv, 0x22, data, 3);
  462. /* PLL mode setting */
  463. ascot2e_write_reg(priv, 0x28, 0x1e);
  464. /* RSSI setting */
  465. ascot2e_write_reg(priv, 0x59, 0x04);
  466. /* TODO check CPU HW error state here */
  467. msleep(80);
  468. /* Xtal oscillator current control setting */
  469. ascot2e_write_reg(priv, 0x4c, 0x01);
  470. /* XOSC_SEL=100uA */
  471. ascot2e_write_reg(priv, 0x07, 0x04);
  472. /* CPU deep sleep */
  473. ascot2e_write_reg(priv, 0x04, 0x00);
  474. /* Logic sleep */
  475. ascot2e_write_reg(priv, 0x03, 0xc0);
  476. /* Power save setting */
  477. data[0] = 0x00;
  478. data[1] = 0x04;
  479. ascot2e_write_regs(priv, 0x14, data, 2);
  480. ascot2e_write_reg(priv, 0x50, 0x01);
  481. priv->state = STATE_SLEEP;
  482. if (fe->ops.i2c_gate_ctrl)
  483. fe->ops.i2c_gate_ctrl(fe, 0);
  484. memcpy(&fe->ops.tuner_ops, &ascot2e_tuner_ops,
  485. sizeof(struct dvb_tuner_ops));
  486. fe->tuner_priv = priv;
  487. dev_info(&priv->i2c->dev,
  488. "Sony ASCOT2E attached on addr=%x at I2C adapter %p\n",
  489. priv->i2c_address, priv->i2c);
  490. return fe;
  491. }
  492. EXPORT_SYMBOL(ascot2e_attach);
  493. MODULE_DESCRIPTION("Sony ASCOT2E terr/cab tuner driver");
  494. MODULE_AUTHOR("info@netup.ru");
  495. MODULE_LICENSE("GPL");