mb86a20s.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver
  3. *
  4. * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
  5. * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
  6. *
  7. * FIXME: Need to port to DVB v5.2 API
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation version 2.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <asm/div64.h>
  20. #include "dvb_frontend.h"
  21. #include "mb86a20s.h"
  22. static int debug = 1;
  23. module_param(debug, int, 0644);
  24. MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
  25. #define rc(args...) do { \
  26. printk(KERN_ERR "mb86a20s: " args); \
  27. } while (0)
  28. #define dprintk(args...) \
  29. do { \
  30. if (debug) { \
  31. printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \
  32. printk(args); \
  33. } \
  34. } while (0)
  35. struct mb86a20s_state {
  36. struct i2c_adapter *i2c;
  37. const struct mb86a20s_config *config;
  38. struct dvb_frontend frontend;
  39. bool need_init;
  40. };
  41. struct regdata {
  42. u8 reg;
  43. u8 data;
  44. };
  45. /*
  46. * Initialization sequence: Use whatevere default values that PV SBTVD
  47. * does on its initialisation, obtained via USB snoop
  48. */
  49. static struct regdata mb86a20s_init[] = {
  50. { 0x70, 0x0f },
  51. { 0x70, 0xff },
  52. { 0x08, 0x01 },
  53. { 0x09, 0x3e },
  54. { 0x50, 0xd1 }, { 0x51, 0x22 },
  55. { 0x39, 0x01 },
  56. { 0x71, 0x00 },
  57. { 0x28, 0x2a }, { 0x29, 0x00 }, { 0x2a, 0xff }, { 0x2b, 0x80 },
  58. { 0x28, 0x20 }, { 0x29, 0x33 }, { 0x2a, 0xdf }, { 0x2b, 0xa9 },
  59. { 0x28, 0x22 }, { 0x29, 0x00 }, { 0x2a, 0x1f }, { 0x2b, 0xf0 },
  60. { 0x3b, 0x21 },
  61. { 0x3c, 0x3a },
  62. { 0x01, 0x0d },
  63. { 0x04, 0x08 }, { 0x05, 0x05 },
  64. { 0x04, 0x0e }, { 0x05, 0x00 },
  65. { 0x04, 0x0f }, { 0x05, 0x14 },
  66. { 0x04, 0x0b }, { 0x05, 0x8c },
  67. { 0x04, 0x00 }, { 0x05, 0x00 },
  68. { 0x04, 0x01 }, { 0x05, 0x07 },
  69. { 0x04, 0x02 }, { 0x05, 0x0f },
  70. { 0x04, 0x03 }, { 0x05, 0xa0 },
  71. { 0x04, 0x09 }, { 0x05, 0x00 },
  72. { 0x04, 0x0a }, { 0x05, 0xff },
  73. { 0x04, 0x27 }, { 0x05, 0x64 },
  74. { 0x04, 0x28 }, { 0x05, 0x00 },
  75. { 0x04, 0x1e }, { 0x05, 0xff },
  76. { 0x04, 0x29 }, { 0x05, 0x0a },
  77. { 0x04, 0x32 }, { 0x05, 0x0a },
  78. { 0x04, 0x14 }, { 0x05, 0x02 },
  79. { 0x04, 0x04 }, { 0x05, 0x00 },
  80. { 0x04, 0x05 }, { 0x05, 0x22 },
  81. { 0x04, 0x06 }, { 0x05, 0x0e },
  82. { 0x04, 0x07 }, { 0x05, 0xd8 },
  83. { 0x04, 0x12 }, { 0x05, 0x00 },
  84. { 0x04, 0x13 }, { 0x05, 0xff },
  85. { 0x04, 0x15 }, { 0x05, 0x4e },
  86. { 0x04, 0x16 }, { 0x05, 0x20 },
  87. { 0x52, 0x01 },
  88. { 0x50, 0xa7 }, { 0x51, 0xff },
  89. { 0x50, 0xa8 }, { 0x51, 0xff },
  90. { 0x50, 0xa9 }, { 0x51, 0xff },
  91. { 0x50, 0xaa }, { 0x51, 0xff },
  92. { 0x50, 0xab }, { 0x51, 0xff },
  93. { 0x50, 0xac }, { 0x51, 0xff },
  94. { 0x50, 0xad }, { 0x51, 0xff },
  95. { 0x50, 0xae }, { 0x51, 0xff },
  96. { 0x50, 0xaf }, { 0x51, 0xff },
  97. { 0x5e, 0x07 },
  98. { 0x50, 0xdc }, { 0x51, 0x01 },
  99. { 0x50, 0xdd }, { 0x51, 0xf4 },
  100. { 0x50, 0xde }, { 0x51, 0x01 },
  101. { 0x50, 0xdf }, { 0x51, 0xf4 },
  102. { 0x50, 0xe0 }, { 0x51, 0x01 },
  103. { 0x50, 0xe1 }, { 0x51, 0xf4 },
  104. { 0x50, 0xb0 }, { 0x51, 0x07 },
  105. { 0x50, 0xb2 }, { 0x51, 0xff },
  106. { 0x50, 0xb3 }, { 0x51, 0xff },
  107. { 0x50, 0xb4 }, { 0x51, 0xff },
  108. { 0x50, 0xb5 }, { 0x51, 0xff },
  109. { 0x50, 0xb6 }, { 0x51, 0xff },
  110. { 0x50, 0xb7 }, { 0x51, 0xff },
  111. { 0x50, 0x50 }, { 0x51, 0x02 },
  112. { 0x50, 0x51 }, { 0x51, 0x04 },
  113. { 0x45, 0x04 },
  114. { 0x48, 0x04 },
  115. { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */
  116. { 0x50, 0xd6 }, { 0x51, 0x1f },
  117. { 0x50, 0xd2 }, { 0x51, 0x03 },
  118. { 0x50, 0xd7 }, { 0x51, 0x3f },
  119. { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 },
  120. { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c },
  121. { 0x04, 0x40 }, { 0x05, 0x01 },
  122. { 0x28, 0x00 }, { 0x29, 0x10 },
  123. { 0x28, 0x05 }, { 0x29, 0x02 },
  124. { 0x1c, 0x01 },
  125. { 0x28, 0x06 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x03 },
  126. { 0x28, 0x07 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0d },
  127. { 0x28, 0x08 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x02 },
  128. { 0x28, 0x09 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x01 },
  129. { 0x28, 0x0a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x21 },
  130. { 0x28, 0x0b }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x29 },
  131. { 0x28, 0x0c }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x16 },
  132. { 0x28, 0x0d }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x31 },
  133. { 0x28, 0x0e }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0e },
  134. { 0x28, 0x0f }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x4e },
  135. { 0x28, 0x10 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x46 },
  136. { 0x28, 0x11 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0f },
  137. { 0x28, 0x12 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x56 },
  138. { 0x28, 0x13 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x35 },
  139. { 0x28, 0x14 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbe },
  140. { 0x28, 0x15 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0x84 },
  141. { 0x28, 0x16 }, { 0x29, 0x00 }, { 0x2a, 0x03 }, { 0x2b, 0xee },
  142. { 0x28, 0x17 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x98 },
  143. { 0x28, 0x18 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x9f },
  144. { 0x28, 0x19 }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xb2 },
  145. { 0x28, 0x1a }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0xc2 },
  146. { 0x28, 0x1b }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0x4a },
  147. { 0x28, 0x1c }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbc },
  148. { 0x28, 0x1d }, { 0x29, 0x00 }, { 0x2a, 0x04 }, { 0x2b, 0xba },
  149. { 0x28, 0x1e }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0x14 },
  150. { 0x50, 0x1e }, { 0x51, 0x5d },
  151. { 0x50, 0x22 }, { 0x51, 0x00 },
  152. { 0x50, 0x23 }, { 0x51, 0xc8 },
  153. { 0x50, 0x24 }, { 0x51, 0x00 },
  154. { 0x50, 0x25 }, { 0x51, 0xf0 },
  155. { 0x50, 0x26 }, { 0x51, 0x00 },
  156. { 0x50, 0x27 }, { 0x51, 0xc3 },
  157. { 0x50, 0x39 }, { 0x51, 0x02 },
  158. { 0x28, 0x6a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x00 },
  159. { 0xd0, 0x00 },
  160. };
  161. static struct regdata mb86a20s_reset_reception[] = {
  162. { 0x70, 0xf0 },
  163. { 0x70, 0xff },
  164. { 0x08, 0x01 },
  165. { 0x08, 0x00 },
  166. };
  167. static int mb86a20s_i2c_writereg(struct mb86a20s_state *state,
  168. u8 i2c_addr, int reg, int data)
  169. {
  170. u8 buf[] = { reg, data };
  171. struct i2c_msg msg = {
  172. .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
  173. };
  174. int rc;
  175. rc = i2c_transfer(state->i2c, &msg, 1);
  176. if (rc != 1) {
  177. printk("%s: writereg error (rc == %i, reg == 0x%02x,"
  178. " data == 0x%02x)\n", __func__, rc, reg, data);
  179. return rc;
  180. }
  181. return 0;
  182. }
  183. static int mb86a20s_i2c_writeregdata(struct mb86a20s_state *state,
  184. u8 i2c_addr, struct regdata *rd, int size)
  185. {
  186. int i, rc;
  187. for (i = 0; i < size; i++) {
  188. rc = mb86a20s_i2c_writereg(state, i2c_addr, rd[i].reg,
  189. rd[i].data);
  190. if (rc < 0)
  191. return rc;
  192. }
  193. return 0;
  194. }
  195. static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
  196. u8 i2c_addr, u8 reg)
  197. {
  198. u8 val;
  199. int rc;
  200. struct i2c_msg msg[] = {
  201. { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
  202. { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
  203. };
  204. rc = i2c_transfer(state->i2c, msg, 2);
  205. if (rc != 2) {
  206. rc("%s: reg=0x%x (error=%d)\n", __func__, reg, rc);
  207. return rc;
  208. }
  209. return val;
  210. }
  211. #define mb86a20s_readreg(state, reg) \
  212. mb86a20s_i2c_readreg(state, state->config->demod_address, reg)
  213. #define mb86a20s_writereg(state, reg, val) \
  214. mb86a20s_i2c_writereg(state, state->config->demod_address, reg, val)
  215. #define mb86a20s_writeregdata(state, regdata) \
  216. mb86a20s_i2c_writeregdata(state, state->config->demod_address, \
  217. regdata, ARRAY_SIZE(regdata))
  218. static int mb86a20s_initfe(struct dvb_frontend *fe)
  219. {
  220. struct mb86a20s_state *state = fe->demodulator_priv;
  221. int rc;
  222. u8 regD5 = 1;
  223. dprintk("\n");
  224. if (fe->ops.i2c_gate_ctrl)
  225. fe->ops.i2c_gate_ctrl(fe, 0);
  226. /* Initialize the frontend */
  227. rc = mb86a20s_writeregdata(state, mb86a20s_init);
  228. if (rc < 0)
  229. goto err;
  230. if (!state->config->is_serial) {
  231. regD5 &= ~1;
  232. rc = mb86a20s_writereg(state, 0x50, 0xd5);
  233. if (rc < 0)
  234. goto err;
  235. rc = mb86a20s_writereg(state, 0x51, regD5);
  236. if (rc < 0)
  237. goto err;
  238. }
  239. if (fe->ops.i2c_gate_ctrl)
  240. fe->ops.i2c_gate_ctrl(fe, 1);
  241. err:
  242. if (rc < 0) {
  243. state->need_init = true;
  244. printk(KERN_INFO "mb86a20s: Init failed. Will try again later\n");
  245. } else {
  246. state->need_init = false;
  247. dprintk("Initialization succeeded.\n");
  248. }
  249. return rc;
  250. }
  251. static int mb86a20s_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  252. {
  253. struct mb86a20s_state *state = fe->demodulator_priv;
  254. unsigned rf_max, rf_min, rf;
  255. u8 val;
  256. dprintk("\n");
  257. if (fe->ops.i2c_gate_ctrl)
  258. fe->ops.i2c_gate_ctrl(fe, 0);
  259. /* Does a binary search to get RF strength */
  260. rf_max = 0xfff;
  261. rf_min = 0;
  262. do {
  263. rf = (rf_max + rf_min) / 2;
  264. mb86a20s_writereg(state, 0x04, 0x1f);
  265. mb86a20s_writereg(state, 0x05, rf >> 8);
  266. mb86a20s_writereg(state, 0x04, 0x20);
  267. mb86a20s_writereg(state, 0x04, rf);
  268. val = mb86a20s_readreg(state, 0x02);
  269. if (val & 0x08)
  270. rf_min = (rf_max + rf_min) / 2;
  271. else
  272. rf_max = (rf_max + rf_min) / 2;
  273. if (rf_max - rf_min < 4) {
  274. *strength = (((rf_max + rf_min) / 2) * 65535) / 4095;
  275. break;
  276. }
  277. } while (1);
  278. dprintk("signal strength = %d\n", *strength);
  279. if (fe->ops.i2c_gate_ctrl)
  280. fe->ops.i2c_gate_ctrl(fe, 1);
  281. return 0;
  282. }
  283. static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
  284. {
  285. struct mb86a20s_state *state = fe->demodulator_priv;
  286. u8 val;
  287. dprintk("\n");
  288. *status = 0;
  289. if (fe->ops.i2c_gate_ctrl)
  290. fe->ops.i2c_gate_ctrl(fe, 0);
  291. val = mb86a20s_readreg(state, 0x0a) & 0xf;
  292. if (fe->ops.i2c_gate_ctrl)
  293. fe->ops.i2c_gate_ctrl(fe, 1);
  294. if (val >= 2)
  295. *status |= FE_HAS_SIGNAL;
  296. if (val >= 4)
  297. *status |= FE_HAS_CARRIER;
  298. if (val >= 5)
  299. *status |= FE_HAS_VITERBI;
  300. if (val >= 7)
  301. *status |= FE_HAS_SYNC;
  302. if (val >= 8) /* Maybe 9? */
  303. *status |= FE_HAS_LOCK;
  304. dprintk("val = %d, status = 0x%02x\n", val, *status);
  305. return 0;
  306. }
  307. static int mb86a20s_set_frontend(struct dvb_frontend *fe)
  308. {
  309. struct mb86a20s_state *state = fe->demodulator_priv;
  310. int rc;
  311. #if 0
  312. /*
  313. * FIXME: Properly implement the set frontend properties
  314. */
  315. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  316. #endif
  317. dprintk("\n");
  318. if (fe->ops.i2c_gate_ctrl)
  319. fe->ops.i2c_gate_ctrl(fe, 1);
  320. dprintk("Calling tuner set parameters\n");
  321. fe->ops.tuner_ops.set_params(fe);
  322. /*
  323. * Make it more reliable: if, for some reason, the initial
  324. * device initialization doesn't happen, initialize it when
  325. * a SBTVD parameters are adjusted.
  326. *
  327. * Unfortunately, due to a hard to track bug at tda829x/tda18271,
  328. * the agc callback logic is not called during DVB attach time,
  329. * causing mb86a20s to not be initialized with Kworld SBTVD.
  330. * So, this hack is needed, in order to make Kworld SBTVD to work.
  331. */
  332. if (state->need_init)
  333. mb86a20s_initfe(fe);
  334. if (fe->ops.i2c_gate_ctrl)
  335. fe->ops.i2c_gate_ctrl(fe, 0);
  336. rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception);
  337. if (fe->ops.i2c_gate_ctrl)
  338. fe->ops.i2c_gate_ctrl(fe, 1);
  339. return rc;
  340. }
  341. static int mb86a20s_get_modulation(struct mb86a20s_state *state,
  342. unsigned layer)
  343. {
  344. int rc;
  345. static unsigned char reg[] = {
  346. [0] = 0x86, /* Layer A */
  347. [1] = 0x8a, /* Layer B */
  348. [2] = 0x8e, /* Layer C */
  349. };
  350. if (layer >= ARRAY_SIZE(reg))
  351. return -EINVAL;
  352. rc = mb86a20s_writereg(state, 0x6d, reg[layer]);
  353. if (rc < 0)
  354. return rc;
  355. rc = mb86a20s_readreg(state, 0x6e);
  356. if (rc < 0)
  357. return rc;
  358. switch ((rc & 0x70) >> 4) {
  359. case 0:
  360. return DQPSK;
  361. case 1:
  362. return QPSK;
  363. case 2:
  364. return QAM_16;
  365. case 3:
  366. return QAM_64;
  367. default:
  368. return QAM_AUTO;
  369. }
  370. }
  371. static int mb86a20s_get_fec(struct mb86a20s_state *state,
  372. unsigned layer)
  373. {
  374. int rc;
  375. static unsigned char reg[] = {
  376. [0] = 0x87, /* Layer A */
  377. [1] = 0x8b, /* Layer B */
  378. [2] = 0x8f, /* Layer C */
  379. };
  380. if (layer >= ARRAY_SIZE(reg))
  381. return -EINVAL;
  382. rc = mb86a20s_writereg(state, 0x6d, reg[layer]);
  383. if (rc < 0)
  384. return rc;
  385. rc = mb86a20s_readreg(state, 0x6e);
  386. if (rc < 0)
  387. return rc;
  388. switch (rc) {
  389. case 0:
  390. return FEC_1_2;
  391. case 1:
  392. return FEC_2_3;
  393. case 2:
  394. return FEC_3_4;
  395. case 3:
  396. return FEC_5_6;
  397. case 4:
  398. return FEC_7_8;
  399. default:
  400. return FEC_AUTO;
  401. }
  402. }
  403. static int mb86a20s_get_interleaving(struct mb86a20s_state *state,
  404. unsigned layer)
  405. {
  406. int rc;
  407. static unsigned char reg[] = {
  408. [0] = 0x88, /* Layer A */
  409. [1] = 0x8c, /* Layer B */
  410. [2] = 0x90, /* Layer C */
  411. };
  412. if (layer >= ARRAY_SIZE(reg))
  413. return -EINVAL;
  414. rc = mb86a20s_writereg(state, 0x6d, reg[layer]);
  415. if (rc < 0)
  416. return rc;
  417. rc = mb86a20s_readreg(state, 0x6e);
  418. if (rc < 0)
  419. return rc;
  420. if (rc > 3)
  421. return -EINVAL; /* Not used */
  422. return rc;
  423. }
  424. static int mb86a20s_get_segment_count(struct mb86a20s_state *state,
  425. unsigned layer)
  426. {
  427. int rc, count;
  428. static unsigned char reg[] = {
  429. [0] = 0x89, /* Layer A */
  430. [1] = 0x8d, /* Layer B */
  431. [2] = 0x91, /* Layer C */
  432. };
  433. if (layer >= ARRAY_SIZE(reg))
  434. return -EINVAL;
  435. rc = mb86a20s_writereg(state, 0x6d, reg[layer]);
  436. if (rc < 0)
  437. return rc;
  438. rc = mb86a20s_readreg(state, 0x6e);
  439. if (rc < 0)
  440. return rc;
  441. count = (rc >> 4) & 0x0f;
  442. return count;
  443. }
  444. static int mb86a20s_get_frontend(struct dvb_frontend *fe)
  445. {
  446. struct mb86a20s_state *state = fe->demodulator_priv;
  447. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  448. int i, rc;
  449. /* Fixed parameters */
  450. p->delivery_system = SYS_ISDBT;
  451. p->bandwidth_hz = 6000000;
  452. if (fe->ops.i2c_gate_ctrl)
  453. fe->ops.i2c_gate_ctrl(fe, 0);
  454. /* Check for partial reception */
  455. rc = mb86a20s_writereg(state, 0x6d, 0x85);
  456. if (rc >= 0)
  457. rc = mb86a20s_readreg(state, 0x6e);
  458. if (rc >= 0)
  459. p->isdbt_partial_reception = (rc & 0x10) ? 1 : 0;
  460. /* Get per-layer data */
  461. p->isdbt_layer_enabled = 0;
  462. for (i = 0; i < 3; i++) {
  463. rc = mb86a20s_get_segment_count(state, i);
  464. if (rc >= 0 && rc < 14)
  465. p->layer[i].segment_count = rc;
  466. if (rc == 0x0f)
  467. continue;
  468. p->isdbt_layer_enabled |= 1 << i;
  469. rc = mb86a20s_get_modulation(state, i);
  470. if (rc >= 0)
  471. p->layer[i].modulation = rc;
  472. rc = mb86a20s_get_fec(state, i);
  473. if (rc >= 0)
  474. p->layer[i].fec = rc;
  475. rc = mb86a20s_get_interleaving(state, i);
  476. if (rc >= 0)
  477. p->layer[i].interleaving = rc;
  478. }
  479. p->isdbt_sb_mode = 0;
  480. rc = mb86a20s_writereg(state, 0x6d, 0x84);
  481. if ((rc >= 0) && ((rc & 0x60) == 0x20)) {
  482. p->isdbt_sb_mode = 1;
  483. /* At least, one segment should exist */
  484. if (!p->isdbt_sb_segment_count)
  485. p->isdbt_sb_segment_count = 1;
  486. } else
  487. p->isdbt_sb_segment_count = 0;
  488. /* Get transmission mode and guard interval */
  489. p->transmission_mode = TRANSMISSION_MODE_AUTO;
  490. p->guard_interval = GUARD_INTERVAL_AUTO;
  491. rc = mb86a20s_readreg(state, 0x07);
  492. if (rc >= 0) {
  493. if ((rc & 0x60) == 0x20) {
  494. switch (rc & 0x0c >> 2) {
  495. case 0:
  496. p->transmission_mode = TRANSMISSION_MODE_2K;
  497. break;
  498. case 1:
  499. p->transmission_mode = TRANSMISSION_MODE_4K;
  500. break;
  501. case 2:
  502. p->transmission_mode = TRANSMISSION_MODE_8K;
  503. break;
  504. }
  505. }
  506. if (!(rc & 0x10)) {
  507. switch (rc & 0x3) {
  508. case 0:
  509. p->guard_interval = GUARD_INTERVAL_1_4;
  510. break;
  511. case 1:
  512. p->guard_interval = GUARD_INTERVAL_1_8;
  513. break;
  514. case 2:
  515. p->guard_interval = GUARD_INTERVAL_1_16;
  516. break;
  517. }
  518. }
  519. }
  520. if (fe->ops.i2c_gate_ctrl)
  521. fe->ops.i2c_gate_ctrl(fe, 1);
  522. return 0;
  523. }
  524. static int mb86a20s_tune(struct dvb_frontend *fe,
  525. bool re_tune,
  526. unsigned int mode_flags,
  527. unsigned int *delay,
  528. fe_status_t *status)
  529. {
  530. int rc = 0;
  531. dprintk("\n");
  532. if (re_tune)
  533. rc = mb86a20s_set_frontend(fe);
  534. if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
  535. mb86a20s_read_status(fe, status);
  536. return rc;
  537. }
  538. static void mb86a20s_release(struct dvb_frontend *fe)
  539. {
  540. struct mb86a20s_state *state = fe->demodulator_priv;
  541. dprintk("\n");
  542. kfree(state);
  543. }
  544. static struct dvb_frontend_ops mb86a20s_ops;
  545. struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
  546. struct i2c_adapter *i2c)
  547. {
  548. u8 rev;
  549. /* allocate memory for the internal state */
  550. struct mb86a20s_state *state =
  551. kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
  552. dprintk("\n");
  553. if (state == NULL) {
  554. rc("Unable to kzalloc\n");
  555. goto error;
  556. }
  557. /* setup the state */
  558. state->config = config;
  559. state->i2c = i2c;
  560. /* create dvb_frontend */
  561. memcpy(&state->frontend.ops, &mb86a20s_ops,
  562. sizeof(struct dvb_frontend_ops));
  563. state->frontend.demodulator_priv = state;
  564. /* Check if it is a mb86a20s frontend */
  565. rev = mb86a20s_readreg(state, 0);
  566. if (rev == 0x13) {
  567. printk(KERN_INFO "Detected a Fujitsu mb86a20s frontend\n");
  568. } else {
  569. printk(KERN_ERR "Frontend revision %d is unknown - aborting.\n",
  570. rev);
  571. goto error;
  572. }
  573. return &state->frontend;
  574. error:
  575. kfree(state);
  576. return NULL;
  577. }
  578. EXPORT_SYMBOL(mb86a20s_attach);
  579. static struct dvb_frontend_ops mb86a20s_ops = {
  580. .delsys = { SYS_ISDBT },
  581. /* Use dib8000 values per default */
  582. .info = {
  583. .name = "Fujitsu mb86A20s",
  584. .caps = FE_CAN_INVERSION_AUTO | FE_CAN_RECOVER |
  585. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  586. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  587. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
  588. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_QAM_AUTO |
  589. FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO,
  590. /* Actually, those values depend on the used tuner */
  591. .frequency_min = 45000000,
  592. .frequency_max = 864000000,
  593. .frequency_stepsize = 62500,
  594. },
  595. .release = mb86a20s_release,
  596. .init = mb86a20s_initfe,
  597. .set_frontend = mb86a20s_set_frontend,
  598. .get_frontend = mb86a20s_get_frontend,
  599. .read_status = mb86a20s_read_status,
  600. .read_signal_strength = mb86a20s_read_signal_strength,
  601. .tune = mb86a20s_tune,
  602. };
  603. MODULE_DESCRIPTION("DVB Frontend module for Fujitsu mb86A20s hardware");
  604. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  605. MODULE_LICENSE("GPL");