mb86a20s.c 18 KB

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