ascot2e.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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. u8 tmp = val; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
  146. return ascot2e_write_regs(priv, reg, &tmp, 1);
  147. }
  148. static int ascot2e_read_regs(struct ascot2e_priv *priv,
  149. u8 reg, u8 *val, u32 len)
  150. {
  151. int ret;
  152. struct i2c_msg msg[2] = {
  153. {
  154. .addr = priv->i2c_address,
  155. .flags = 0,
  156. .len = 1,
  157. .buf = &reg,
  158. }, {
  159. .addr = priv->i2c_address,
  160. .flags = I2C_M_RD,
  161. .len = len,
  162. .buf = val,
  163. }
  164. };
  165. ret = i2c_transfer(priv->i2c, &msg[0], 1);
  166. if (ret >= 0 && ret != 1)
  167. ret = -EREMOTEIO;
  168. if (ret < 0) {
  169. dev_warn(&priv->i2c->dev,
  170. "%s: I2C rw failed=%d addr=%02x reg=%02x\n",
  171. KBUILD_MODNAME, ret, priv->i2c_address, reg);
  172. return ret;
  173. }
  174. ret = i2c_transfer(priv->i2c, &msg[1], 1);
  175. if (ret >= 0 && ret != 1)
  176. ret = -EREMOTEIO;
  177. if (ret < 0) {
  178. dev_warn(&priv->i2c->dev,
  179. "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
  180. KBUILD_MODNAME, ret, priv->i2c_address, reg);
  181. return ret;
  182. }
  183. ascot2e_i2c_debug(priv, reg, 0, val, len);
  184. return 0;
  185. }
  186. static int ascot2e_read_reg(struct ascot2e_priv *priv, u8 reg, u8 *val)
  187. {
  188. return ascot2e_read_regs(priv, reg, val, 1);
  189. }
  190. static int ascot2e_set_reg_bits(struct ascot2e_priv *priv,
  191. u8 reg, u8 data, u8 mask)
  192. {
  193. int res;
  194. u8 rdata;
  195. if (mask != 0xff) {
  196. res = ascot2e_read_reg(priv, reg, &rdata);
  197. if (res != 0)
  198. return res;
  199. data = ((data & mask) | (rdata & (mask ^ 0xFF)));
  200. }
  201. return ascot2e_write_reg(priv, reg, data);
  202. }
  203. static int ascot2e_enter_power_save(struct ascot2e_priv *priv)
  204. {
  205. u8 data[2];
  206. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  207. if (priv->state == STATE_SLEEP)
  208. return 0;
  209. data[0] = 0x00;
  210. data[1] = 0x04;
  211. ascot2e_write_regs(priv, 0x14, data, 2);
  212. ascot2e_write_reg(priv, 0x50, 0x01);
  213. priv->state = STATE_SLEEP;
  214. return 0;
  215. }
  216. static int ascot2e_leave_power_save(struct ascot2e_priv *priv)
  217. {
  218. u8 data[2] = { 0xFB, 0x0F };
  219. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  220. if (priv->state == STATE_ACTIVE)
  221. return 0;
  222. ascot2e_write_regs(priv, 0x14, data, 2);
  223. ascot2e_write_reg(priv, 0x50, 0x00);
  224. priv->state = STATE_ACTIVE;
  225. return 0;
  226. }
  227. static int ascot2e_init(struct dvb_frontend *fe)
  228. {
  229. struct ascot2e_priv *priv = fe->tuner_priv;
  230. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  231. return ascot2e_leave_power_save(priv);
  232. }
  233. static int ascot2e_release(struct dvb_frontend *fe)
  234. {
  235. struct ascot2e_priv *priv = fe->tuner_priv;
  236. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  237. kfree(fe->tuner_priv);
  238. fe->tuner_priv = NULL;
  239. return 0;
  240. }
  241. static int ascot2e_sleep(struct dvb_frontend *fe)
  242. {
  243. struct ascot2e_priv *priv = fe->tuner_priv;
  244. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  245. ascot2e_enter_power_save(priv);
  246. return 0;
  247. }
  248. static enum ascot2e_tv_system_t ascot2e_get_tv_system(struct dvb_frontend *fe)
  249. {
  250. enum ascot2e_tv_system_t system = ASCOT2E_DTV_UNKNOWN;
  251. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  252. struct ascot2e_priv *priv = fe->tuner_priv;
  253. if (p->delivery_system == SYS_DVBT) {
  254. if (p->bandwidth_hz <= 5000000)
  255. system = ASCOT2E_DTV_DVBT_5;
  256. else if (p->bandwidth_hz <= 6000000)
  257. system = ASCOT2E_DTV_DVBT_6;
  258. else if (p->bandwidth_hz <= 7000000)
  259. system = ASCOT2E_DTV_DVBT_7;
  260. else if (p->bandwidth_hz <= 8000000)
  261. system = ASCOT2E_DTV_DVBT_8;
  262. else {
  263. system = ASCOT2E_DTV_DVBT_8;
  264. p->bandwidth_hz = 8000000;
  265. }
  266. } else if (p->delivery_system == SYS_DVBT2) {
  267. if (p->bandwidth_hz <= 5000000)
  268. system = ASCOT2E_DTV_DVBT2_5;
  269. else if (p->bandwidth_hz <= 6000000)
  270. system = ASCOT2E_DTV_DVBT2_6;
  271. else if (p->bandwidth_hz <= 7000000)
  272. system = ASCOT2E_DTV_DVBT2_7;
  273. else if (p->bandwidth_hz <= 8000000)
  274. system = ASCOT2E_DTV_DVBT2_8;
  275. else {
  276. system = ASCOT2E_DTV_DVBT2_8;
  277. p->bandwidth_hz = 8000000;
  278. }
  279. } else if (p->delivery_system == SYS_DVBC_ANNEX_A) {
  280. if (p->bandwidth_hz <= 6000000)
  281. system = ASCOT2E_DTV_DVBC_6;
  282. else if (p->bandwidth_hz <= 8000000)
  283. system = ASCOT2E_DTV_DVBC_8;
  284. }
  285. dev_dbg(&priv->i2c->dev,
  286. "%s(): ASCOT2E DTV system %d (delsys %d, bandwidth %d)\n",
  287. __func__, (int)system, p->delivery_system, p->bandwidth_hz);
  288. return system;
  289. }
  290. static int ascot2e_set_params(struct dvb_frontend *fe)
  291. {
  292. u8 data[10];
  293. u32 frequency;
  294. enum ascot2e_tv_system_t tv_system;
  295. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  296. struct ascot2e_priv *priv = fe->tuner_priv;
  297. dev_dbg(&priv->i2c->dev, "%s(): tune frequency %dkHz\n",
  298. __func__, p->frequency / 1000);
  299. tv_system = ascot2e_get_tv_system(fe);
  300. if (tv_system == ASCOT2E_DTV_UNKNOWN) {
  301. dev_dbg(&priv->i2c->dev, "%s(): unknown DTV system\n",
  302. __func__);
  303. return -EINVAL;
  304. }
  305. if (priv->set_tuner)
  306. priv->set_tuner(priv->set_tuner_data, 1);
  307. frequency = roundup(p->frequency / 1000, 25);
  308. if (priv->state == STATE_SLEEP)
  309. ascot2e_leave_power_save(priv);
  310. /* IF_OUT_SEL / AGC_SEL setting */
  311. data[0] = 0x00;
  312. if (ascot2e_sett[tv_system].agc_sel != ASCOT2E_AUTO) {
  313. /* AGC pin setting from parameter table */
  314. data[0] |= (u8)(
  315. (ascot2e_sett[tv_system].agc_sel & 0x03) << 3);
  316. }
  317. if (ascot2e_sett[tv_system].if_out_sel != ASCOT2E_AUTO) {
  318. /* IFOUT pin setting from parameter table */
  319. data[0] |= (u8)(
  320. (ascot2e_sett[tv_system].if_out_sel & 0x01) << 2);
  321. }
  322. /* Set bit[4:2] only */
  323. ascot2e_set_reg_bits(priv, 0x05, data[0], 0x1c);
  324. /* 0x06 - 0x0F */
  325. /* REF_R setting (0x06) */
  326. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  327. tv_system == ASCOT2E_DTV_DVBC_8) {
  328. /* xtal, xtal*2 */
  329. data[0] = (frequency > 500000) ? 16 : 32;
  330. } else {
  331. /* xtal/8, xtal/4 */
  332. data[0] = (frequency > 500000) ? 2 : 4;
  333. }
  334. /* XOSC_SEL=100uA */
  335. data[1] = 0x04;
  336. /* KBW setting (0x08), KC0 setting (0x09), KC1 setting (0x0A) */
  337. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  338. tv_system == ASCOT2E_DTV_DVBC_8) {
  339. data[2] = 18;
  340. data[3] = 120;
  341. data[4] = 20;
  342. } else {
  343. data[2] = 48;
  344. data[3] = 10;
  345. data[4] = 30;
  346. }
  347. /* ORDER/R2_RANGE/R2_BANK/C2_BANK setting (0x0B) */
  348. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  349. tv_system == ASCOT2E_DTV_DVBC_8)
  350. data[5] = (frequency > 500000) ? 0x08 : 0x0c;
  351. else
  352. data[5] = (frequency > 500000) ? 0x30 : 0x38;
  353. /* Set MIX_OLL (0x0C) value from parameter table */
  354. data[6] = ascot2e_sett[tv_system].mix_oll;
  355. /* Set RF_GAIN (0x0D) setting from parameter table */
  356. if (ascot2e_sett[tv_system].rf_gain == ASCOT2E_AUTO) {
  357. /* RF_GAIN auto control enable */
  358. ascot2e_write_reg(priv, 0x4E, 0x01);
  359. /* RF_GAIN Default value */
  360. data[7] = 0x00;
  361. } else {
  362. /* RF_GAIN auto control disable */
  363. ascot2e_write_reg(priv, 0x4E, 0x00);
  364. data[7] = ascot2e_sett[tv_system].rf_gain;
  365. }
  366. /* Set IF_BPF_GC/FIF_OFFSET (0x0E) value from parameter table */
  367. data[8] = (u8)((ascot2e_sett[tv_system].fif_offset << 3) |
  368. (ascot2e_sett[tv_system].if_bpf_gc & 0x07));
  369. /* Set BW_OFFSET (0x0F) value from parameter table */
  370. data[9] = ascot2e_sett[tv_system].bw_offset;
  371. ascot2e_write_regs(priv, 0x06, data, 10);
  372. /*
  373. * 0x45 - 0x47
  374. * LNA optimization setting
  375. * RF_LNA_DIST1-5, RF_LNA_CM
  376. */
  377. if (tv_system == ASCOT2E_DTV_DVBC_6 ||
  378. tv_system == ASCOT2E_DTV_DVBC_8) {
  379. data[0] = 0x0F;
  380. data[1] = 0x00;
  381. data[2] = 0x01;
  382. } else {
  383. data[0] = 0x0F;
  384. data[1] = 0x00;
  385. data[2] = 0x03;
  386. }
  387. ascot2e_write_regs(priv, 0x45, data, 3);
  388. /* 0x49 - 0x4A
  389. Set RF_OLDET_ENX/RF_OLDET_OLL value from parameter table */
  390. data[0] = ascot2e_sett[tv_system].rf_oldet;
  391. /* Set IF_BPF_F0 value from parameter table */
  392. data[1] = ascot2e_sett[tv_system].if_bpf_f0;
  393. ascot2e_write_regs(priv, 0x49, data, 2);
  394. /*
  395. * Tune now
  396. * RFAGC fast mode / RFAGC auto control enable
  397. * (set bit[7], bit[5:4] only)
  398. * vco_cal = 1, set MIX_OL_CPU_EN
  399. */
  400. ascot2e_set_reg_bits(priv, 0x0c, 0x90, 0xb0);
  401. /* Logic wake up, CPU wake up */
  402. data[0] = 0xc4;
  403. data[1] = 0x40;
  404. ascot2e_write_regs(priv, 0x03, data, 2);
  405. /* 0x10 - 0x14 */
  406. data[0] = (u8)(frequency & 0xFF); /* 0x10: FRF_L */
  407. data[1] = (u8)((frequency >> 8) & 0xFF); /* 0x11: FRF_M */
  408. data[2] = (u8)((frequency >> 16) & 0x0F); /* 0x12: FRF_H (bit[3:0]) */
  409. /* 0x12: BW (bit[5:4]) */
  410. data[2] |= (u8)(ascot2e_sett[tv_system].bw << 4);
  411. data[3] = 0xFF; /* 0x13: VCO calibration enable */
  412. data[4] = 0xFF; /* 0x14: Analog block enable */
  413. /* Tune (Burst write) */
  414. ascot2e_write_regs(priv, 0x10, data, 5);
  415. msleep(50);
  416. /* CPU deep sleep */
  417. ascot2e_write_reg(priv, 0x04, 0x00);
  418. /* Logic sleep */
  419. ascot2e_write_reg(priv, 0x03, 0xC0);
  420. /* RFAGC normal mode (set bit[5:4] only) */
  421. ascot2e_set_reg_bits(priv, 0x0C, 0x00, 0x30);
  422. priv->frequency = frequency;
  423. return 0;
  424. }
  425. static int ascot2e_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  426. {
  427. struct ascot2e_priv *priv = fe->tuner_priv;
  428. *frequency = priv->frequency * 1000;
  429. return 0;
  430. }
  431. static struct dvb_tuner_ops ascot2e_tuner_ops = {
  432. .info = {
  433. .name = "Sony ASCOT2E",
  434. .frequency_min = 1000000,
  435. .frequency_max = 1200000000,
  436. .frequency_step = 25000,
  437. },
  438. .init = ascot2e_init,
  439. .release = ascot2e_release,
  440. .sleep = ascot2e_sleep,
  441. .set_params = ascot2e_set_params,
  442. .get_frequency = ascot2e_get_frequency,
  443. };
  444. struct dvb_frontend *ascot2e_attach(struct dvb_frontend *fe,
  445. const struct ascot2e_config *config,
  446. struct i2c_adapter *i2c)
  447. {
  448. u8 data[4];
  449. struct ascot2e_priv *priv = NULL;
  450. priv = kzalloc(sizeof(struct ascot2e_priv), GFP_KERNEL);
  451. if (priv == NULL)
  452. return NULL;
  453. priv->i2c_address = (config->i2c_address >> 1);
  454. priv->i2c = i2c;
  455. priv->set_tuner_data = config->set_tuner_priv;
  456. priv->set_tuner = config->set_tuner_callback;
  457. if (fe->ops.i2c_gate_ctrl)
  458. fe->ops.i2c_gate_ctrl(fe, 1);
  459. /* 16 MHz xTal frequency */
  460. data[0] = 16;
  461. /* VCO current setting */
  462. data[1] = 0x06;
  463. /* Logic wake up, CPU boot */
  464. data[2] = 0xC4;
  465. data[3] = 0x40;
  466. ascot2e_write_regs(priv, 0x01, data, 4);
  467. /* RFVGA optimization setting (RF_DIST0 - RF_DIST2) */
  468. data[0] = 0x10;
  469. data[1] = 0x3F;
  470. data[2] = 0x25;
  471. ascot2e_write_regs(priv, 0x22, data, 3);
  472. /* PLL mode setting */
  473. ascot2e_write_reg(priv, 0x28, 0x1e);
  474. /* RSSI setting */
  475. ascot2e_write_reg(priv, 0x59, 0x04);
  476. /* TODO check CPU HW error state here */
  477. msleep(80);
  478. /* Xtal oscillator current control setting */
  479. ascot2e_write_reg(priv, 0x4c, 0x01);
  480. /* XOSC_SEL=100uA */
  481. ascot2e_write_reg(priv, 0x07, 0x04);
  482. /* CPU deep sleep */
  483. ascot2e_write_reg(priv, 0x04, 0x00);
  484. /* Logic sleep */
  485. ascot2e_write_reg(priv, 0x03, 0xc0);
  486. /* Power save setting */
  487. data[0] = 0x00;
  488. data[1] = 0x04;
  489. ascot2e_write_regs(priv, 0x14, data, 2);
  490. ascot2e_write_reg(priv, 0x50, 0x01);
  491. priv->state = STATE_SLEEP;
  492. if (fe->ops.i2c_gate_ctrl)
  493. fe->ops.i2c_gate_ctrl(fe, 0);
  494. memcpy(&fe->ops.tuner_ops, &ascot2e_tuner_ops,
  495. sizeof(struct dvb_tuner_ops));
  496. fe->tuner_priv = priv;
  497. dev_info(&priv->i2c->dev,
  498. "Sony ASCOT2E attached on addr=%x at I2C adapter %p\n",
  499. priv->i2c_address, priv->i2c);
  500. return fe;
  501. }
  502. EXPORT_SYMBOL(ascot2e_attach);
  503. MODULE_DESCRIPTION("Sony ASCOT2E terr/cab tuner driver");
  504. MODULE_AUTHOR("info@netup.ru");
  505. MODULE_LICENSE("GPL");