ascot2e.c 15 KB

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