mxl5xx.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for the MaxLinear MxL5xx family of tuners/demods
  4. *
  5. * Copyright (C) 2014-2015 Ralph Metzler <rjkm@metzlerbros.de>
  6. * Marcus Metzler <mocm@metzlerbros.de>
  7. * developed for Digital Devices GmbH
  8. *
  9. * based on code:
  10. * Copyright (c) 2011-2013 MaxLinear, Inc. All rights reserved
  11. * which was released under GPL V2
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/firmware.h>
  19. #include <linux/i2c.h>
  20. #include <linux/mutex.h>
  21. #include <linux/vmalloc.h>
  22. #include <asm/div64.h>
  23. #include <linux/unaligned.h>
  24. #include <media/dvb_frontend.h>
  25. #include "mxl5xx.h"
  26. #include "mxl5xx_regs.h"
  27. #include "mxl5xx_defs.h"
  28. #define BYTE0(v) ((v >> 0) & 0xff)
  29. #define BYTE1(v) ((v >> 8) & 0xff)
  30. #define BYTE2(v) ((v >> 16) & 0xff)
  31. #define BYTE3(v) ((v >> 24) & 0xff)
  32. static LIST_HEAD(mxllist);
  33. struct mxl_base {
  34. struct list_head mxllist;
  35. struct list_head mxls;
  36. u8 adr;
  37. struct i2c_adapter *i2c;
  38. u32 count;
  39. u32 type;
  40. u32 sku_type;
  41. u32 chipversion;
  42. u32 clock;
  43. u32 fwversion;
  44. u8 *ts_map;
  45. u8 can_clkout;
  46. u8 chan_bond;
  47. u8 demod_num;
  48. u8 tuner_num;
  49. unsigned long next_tune;
  50. struct mutex i2c_lock;
  51. struct mutex status_lock;
  52. struct mutex tune_lock;
  53. u8 buf[MXL_HYDRA_OEM_MAX_CMD_BUFF_LEN];
  54. u32 cmd_size;
  55. u8 cmd_data[MAX_CMD_DATA];
  56. };
  57. struct mxl {
  58. struct list_head mxl;
  59. struct mxl_base *base;
  60. struct dvb_frontend fe;
  61. struct device *i2cdev;
  62. u32 demod;
  63. u32 tuner;
  64. u32 tuner_in_use;
  65. u8 xbar[3];
  66. unsigned long tune_time;
  67. };
  68. static void convert_endian(u8 flag, u32 size, u8 *d)
  69. {
  70. u32 i;
  71. if (!flag)
  72. return;
  73. for (i = 0; i < (size & ~3); i += 4) {
  74. d[i + 0] ^= d[i + 3];
  75. d[i + 3] ^= d[i + 0];
  76. d[i + 0] ^= d[i + 3];
  77. d[i + 1] ^= d[i + 2];
  78. d[i + 2] ^= d[i + 1];
  79. d[i + 1] ^= d[i + 2];
  80. }
  81. switch (size & 3) {
  82. case 0:
  83. case 1:
  84. /* do nothing */
  85. break;
  86. case 2:
  87. d[i + 0] ^= d[i + 1];
  88. d[i + 1] ^= d[i + 0];
  89. d[i + 0] ^= d[i + 1];
  90. break;
  91. case 3:
  92. d[i + 0] ^= d[i + 2];
  93. d[i + 2] ^= d[i + 0];
  94. d[i + 0] ^= d[i + 2];
  95. break;
  96. }
  97. }
  98. static int i2c_write(struct i2c_adapter *adap, u8 adr,
  99. u8 *data, u32 len)
  100. {
  101. struct i2c_msg msg = {.addr = adr, .flags = 0,
  102. .buf = data, .len = len};
  103. return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
  104. }
  105. static int i2c_read(struct i2c_adapter *adap, u8 adr,
  106. u8 *data, u32 len)
  107. {
  108. struct i2c_msg msg = {.addr = adr, .flags = I2C_M_RD,
  109. .buf = data, .len = len};
  110. return (i2c_transfer(adap, &msg, 1) == 1) ? 0 : -1;
  111. }
  112. static int i2cread(struct mxl *state, u8 *data, int len)
  113. {
  114. return i2c_read(state->base->i2c, state->base->adr, data, len);
  115. }
  116. static int i2cwrite(struct mxl *state, u8 *data, int len)
  117. {
  118. return i2c_write(state->base->i2c, state->base->adr, data, len);
  119. }
  120. static int read_register_unlocked(struct mxl *state, u32 reg, u32 *val)
  121. {
  122. int stat;
  123. u8 data[MXL_HYDRA_REG_SIZE_IN_BYTES + MXL_HYDRA_I2C_HDR_SIZE] = {
  124. MXL_HYDRA_PLID_REG_READ, 0x04,
  125. GET_BYTE(reg, 0), GET_BYTE(reg, 1),
  126. GET_BYTE(reg, 2), GET_BYTE(reg, 3),
  127. };
  128. stat = i2cwrite(state, data,
  129. MXL_HYDRA_REG_SIZE_IN_BYTES + MXL_HYDRA_I2C_HDR_SIZE);
  130. if (stat)
  131. dev_err(state->i2cdev, "i2c read error 1\n");
  132. if (!stat)
  133. stat = i2cread(state, (u8 *) val,
  134. MXL_HYDRA_REG_SIZE_IN_BYTES);
  135. le32_to_cpus(val);
  136. if (stat)
  137. dev_err(state->i2cdev, "i2c read error 2\n");
  138. return stat;
  139. }
  140. #define DMA_I2C_INTERRUPT_ADDR 0x8000011C
  141. #define DMA_INTR_PROT_WR_CMP 0x08
  142. static int send_command(struct mxl *state, u32 size, u8 *buf)
  143. {
  144. int stat;
  145. u32 val, count = 10;
  146. mutex_lock(&state->base->i2c_lock);
  147. if (state->base->fwversion > 0x02010109) {
  148. read_register_unlocked(state, DMA_I2C_INTERRUPT_ADDR, &val);
  149. if (DMA_INTR_PROT_WR_CMP & val)
  150. dev_info(state->i2cdev, "%s busy\n", __func__);
  151. while ((DMA_INTR_PROT_WR_CMP & val) && --count) {
  152. mutex_unlock(&state->base->i2c_lock);
  153. usleep_range(1000, 2000);
  154. mutex_lock(&state->base->i2c_lock);
  155. read_register_unlocked(state, DMA_I2C_INTERRUPT_ADDR,
  156. &val);
  157. }
  158. if (!count) {
  159. dev_info(state->i2cdev, "%s busy\n", __func__);
  160. mutex_unlock(&state->base->i2c_lock);
  161. return -EBUSY;
  162. }
  163. }
  164. stat = i2cwrite(state, buf, size);
  165. mutex_unlock(&state->base->i2c_lock);
  166. return stat;
  167. }
  168. static int write_register(struct mxl *state, u32 reg, u32 val)
  169. {
  170. int stat;
  171. u8 data[MXL_HYDRA_REG_WRITE_LEN] = {
  172. MXL_HYDRA_PLID_REG_WRITE, 0x08,
  173. BYTE0(reg), BYTE1(reg), BYTE2(reg), BYTE3(reg),
  174. BYTE0(val), BYTE1(val), BYTE2(val), BYTE3(val),
  175. };
  176. mutex_lock(&state->base->i2c_lock);
  177. stat = i2cwrite(state, data, sizeof(data));
  178. mutex_unlock(&state->base->i2c_lock);
  179. if (stat)
  180. dev_err(state->i2cdev, "i2c write error\n");
  181. return stat;
  182. }
  183. static int write_firmware_block(struct mxl *state,
  184. u32 reg, u32 size, u8 *reg_data_ptr)
  185. {
  186. int stat;
  187. u8 *buf = state->base->buf;
  188. mutex_lock(&state->base->i2c_lock);
  189. buf[0] = MXL_HYDRA_PLID_REG_WRITE;
  190. buf[1] = size + 4;
  191. buf[2] = GET_BYTE(reg, 0);
  192. buf[3] = GET_BYTE(reg, 1);
  193. buf[4] = GET_BYTE(reg, 2);
  194. buf[5] = GET_BYTE(reg, 3);
  195. memcpy(&buf[6], reg_data_ptr, size);
  196. stat = i2cwrite(state, buf,
  197. MXL_HYDRA_I2C_HDR_SIZE +
  198. MXL_HYDRA_REG_SIZE_IN_BYTES + size);
  199. mutex_unlock(&state->base->i2c_lock);
  200. if (stat)
  201. dev_err(state->i2cdev, "fw block write failed\n");
  202. return stat;
  203. }
  204. static int read_register(struct mxl *state, u32 reg, u32 *val)
  205. {
  206. int stat;
  207. u8 data[MXL_HYDRA_REG_SIZE_IN_BYTES + MXL_HYDRA_I2C_HDR_SIZE] = {
  208. MXL_HYDRA_PLID_REG_READ, 0x04,
  209. GET_BYTE(reg, 0), GET_BYTE(reg, 1),
  210. GET_BYTE(reg, 2), GET_BYTE(reg, 3),
  211. };
  212. mutex_lock(&state->base->i2c_lock);
  213. stat = i2cwrite(state, data,
  214. MXL_HYDRA_REG_SIZE_IN_BYTES + MXL_HYDRA_I2C_HDR_SIZE);
  215. if (stat)
  216. dev_err(state->i2cdev, "i2c read error 1\n");
  217. if (!stat)
  218. stat = i2cread(state, (u8 *) val,
  219. MXL_HYDRA_REG_SIZE_IN_BYTES);
  220. mutex_unlock(&state->base->i2c_lock);
  221. le32_to_cpus(val);
  222. if (stat)
  223. dev_err(state->i2cdev, "i2c read error 2\n");
  224. return stat;
  225. }
  226. static int read_register_block(struct mxl *state, u32 reg, u32 size, u8 *data)
  227. {
  228. int stat;
  229. u8 *buf = state->base->buf;
  230. mutex_lock(&state->base->i2c_lock);
  231. buf[0] = MXL_HYDRA_PLID_REG_READ;
  232. buf[1] = size + 4;
  233. buf[2] = GET_BYTE(reg, 0);
  234. buf[3] = GET_BYTE(reg, 1);
  235. buf[4] = GET_BYTE(reg, 2);
  236. buf[5] = GET_BYTE(reg, 3);
  237. stat = i2cwrite(state, buf,
  238. MXL_HYDRA_I2C_HDR_SIZE + MXL_HYDRA_REG_SIZE_IN_BYTES);
  239. if (!stat) {
  240. stat = i2cread(state, data, size);
  241. convert_endian(MXL_ENABLE_BIG_ENDIAN, size, data);
  242. }
  243. mutex_unlock(&state->base->i2c_lock);
  244. return stat;
  245. }
  246. static int read_by_mnemonic(struct mxl *state,
  247. u32 reg, u8 lsbloc, u8 numofbits, u32 *val)
  248. {
  249. u32 data = 0, mask = 0;
  250. int stat;
  251. stat = read_register(state, reg, &data);
  252. if (stat)
  253. return stat;
  254. mask = MXL_GET_REG_MASK_32(lsbloc, numofbits);
  255. data &= mask;
  256. data >>= lsbloc;
  257. *val = data;
  258. return 0;
  259. }
  260. static int update_by_mnemonic(struct mxl *state,
  261. u32 reg, u8 lsbloc, u8 numofbits, u32 val)
  262. {
  263. u32 data, mask;
  264. int stat;
  265. stat = read_register(state, reg, &data);
  266. if (stat)
  267. return stat;
  268. mask = MXL_GET_REG_MASK_32(lsbloc, numofbits);
  269. data = (data & ~mask) | ((val << lsbloc) & mask);
  270. stat = write_register(state, reg, data);
  271. return stat;
  272. }
  273. static int firmware_is_alive(struct mxl *state)
  274. {
  275. u32 hb0, hb1;
  276. if (read_register(state, HYDRA_HEAR_BEAT, &hb0))
  277. return 0;
  278. msleep(20);
  279. if (read_register(state, HYDRA_HEAR_BEAT, &hb1))
  280. return 0;
  281. if (hb1 == hb0)
  282. return 0;
  283. return 1;
  284. }
  285. static int init(struct dvb_frontend *fe)
  286. {
  287. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  288. /* init fe stats */
  289. p->strength.len = 1;
  290. p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  291. p->cnr.len = 1;
  292. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  293. p->pre_bit_error.len = 1;
  294. p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  295. p->pre_bit_count.len = 1;
  296. p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  297. p->post_bit_error.len = 1;
  298. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  299. p->post_bit_count.len = 1;
  300. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  301. return 0;
  302. }
  303. static void release(struct dvb_frontend *fe)
  304. {
  305. struct mxl *state = fe->demodulator_priv;
  306. list_del(&state->mxl);
  307. /* Release one frontend, two more shall take its place! */
  308. state->base->count--;
  309. if (state->base->count == 0) {
  310. list_del(&state->base->mxllist);
  311. kfree(state->base);
  312. }
  313. kfree(state);
  314. }
  315. static enum dvbfe_algo get_algo(struct dvb_frontend *fe)
  316. {
  317. return DVBFE_ALGO_HW;
  318. }
  319. static u32 gold2root(u32 gold)
  320. {
  321. u32 x, g, tmp = gold;
  322. if (tmp >= 0x3ffff)
  323. tmp = 0;
  324. for (g = 0, x = 1; g < tmp; g++)
  325. x = (((x ^ (x >> 7)) & 1) << 17) | (x >> 1);
  326. return x;
  327. }
  328. static int cfg_scrambler(struct mxl *state, u32 gold)
  329. {
  330. u32 root;
  331. u8 buf[26] = {
  332. MXL_HYDRA_PLID_CMD_WRITE, 24,
  333. 0, MXL_HYDRA_DEMOD_SCRAMBLE_CODE_CMD, 0, 0,
  334. state->demod, 0, 0, 0,
  335. 0, 0, 0, 0, 0, 0, 0, 0,
  336. 0, 0, 0, 0, 1, 0, 0, 0,
  337. };
  338. root = gold2root(gold);
  339. buf[25] = (root >> 24) & 0xff;
  340. buf[24] = (root >> 16) & 0xff;
  341. buf[23] = (root >> 8) & 0xff;
  342. buf[22] = root & 0xff;
  343. return send_command(state, sizeof(buf), buf);
  344. }
  345. static int cfg_demod_abort_tune(struct mxl *state)
  346. {
  347. struct MXL_HYDRA_DEMOD_ABORT_TUNE_T abort_tune_cmd;
  348. u8 cmd_size = sizeof(abort_tune_cmd);
  349. u8 cmd_buff[MXL_HYDRA_OEM_MAX_CMD_BUFF_LEN];
  350. abort_tune_cmd.demod_id = state->demod;
  351. BUILD_HYDRA_CMD(MXL_HYDRA_ABORT_TUNE_CMD, MXL_CMD_WRITE,
  352. cmd_size, &abort_tune_cmd, cmd_buff);
  353. return send_command(state, cmd_size + MXL_HYDRA_CMD_HEADER_SIZE,
  354. &cmd_buff[0]);
  355. }
  356. static int send_master_cmd(struct dvb_frontend *fe,
  357. struct dvb_diseqc_master_cmd *cmd)
  358. {
  359. /*struct mxl *state = fe->demodulator_priv;*/
  360. return 0; /*CfgDemodAbortTune(state);*/
  361. }
  362. static int set_parameters(struct dvb_frontend *fe)
  363. {
  364. struct mxl *state = fe->demodulator_priv;
  365. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  366. struct MXL_HYDRA_DEMOD_PARAM_T demod_chan_cfg;
  367. u8 cmd_size = sizeof(demod_chan_cfg);
  368. u8 cmd_buff[MXL_HYDRA_OEM_MAX_CMD_BUFF_LEN];
  369. u32 srange = 10;
  370. int stat;
  371. if (p->frequency < 950000 || p->frequency > 2150000)
  372. return -EINVAL;
  373. if (p->symbol_rate < 1000000 || p->symbol_rate > 45000000)
  374. return -EINVAL;
  375. /* CfgDemodAbortTune(state); */
  376. switch (p->delivery_system) {
  377. case SYS_DSS:
  378. demod_chan_cfg.standard = MXL_HYDRA_DSS;
  379. demod_chan_cfg.roll_off = MXL_HYDRA_ROLLOFF_AUTO;
  380. break;
  381. case SYS_DVBS:
  382. srange = p->symbol_rate / 1000000;
  383. if (srange > 10)
  384. srange = 10;
  385. demod_chan_cfg.standard = MXL_HYDRA_DVBS;
  386. demod_chan_cfg.roll_off = MXL_HYDRA_ROLLOFF_0_35;
  387. demod_chan_cfg.modulation_scheme = MXL_HYDRA_MOD_QPSK;
  388. demod_chan_cfg.pilots = MXL_HYDRA_PILOTS_OFF;
  389. break;
  390. case SYS_DVBS2:
  391. demod_chan_cfg.standard = MXL_HYDRA_DVBS2;
  392. demod_chan_cfg.roll_off = MXL_HYDRA_ROLLOFF_AUTO;
  393. demod_chan_cfg.modulation_scheme = MXL_HYDRA_MOD_AUTO;
  394. demod_chan_cfg.pilots = MXL_HYDRA_PILOTS_AUTO;
  395. cfg_scrambler(state, p->scrambling_sequence_index);
  396. break;
  397. default:
  398. return -EINVAL;
  399. }
  400. demod_chan_cfg.tuner_index = state->tuner;
  401. demod_chan_cfg.demod_index = state->demod;
  402. demod_chan_cfg.frequency_in_hz = p->frequency * 1000;
  403. demod_chan_cfg.symbol_rate_in_hz = p->symbol_rate;
  404. demod_chan_cfg.max_carrier_offset_in_mhz = srange;
  405. demod_chan_cfg.spectrum_inversion = MXL_HYDRA_SPECTRUM_AUTO;
  406. demod_chan_cfg.fec_code_rate = MXL_HYDRA_FEC_AUTO;
  407. mutex_lock(&state->base->tune_lock);
  408. if (time_after(jiffies + msecs_to_jiffies(200),
  409. state->base->next_tune))
  410. while (time_before(jiffies, state->base->next_tune))
  411. usleep_range(10000, 11000);
  412. state->base->next_tune = jiffies + msecs_to_jiffies(100);
  413. state->tuner_in_use = state->tuner;
  414. BUILD_HYDRA_CMD(MXL_HYDRA_DEMOD_SET_PARAM_CMD, MXL_CMD_WRITE,
  415. cmd_size, &demod_chan_cfg, cmd_buff);
  416. stat = send_command(state, cmd_size + MXL_HYDRA_CMD_HEADER_SIZE,
  417. &cmd_buff[0]);
  418. mutex_unlock(&state->base->tune_lock);
  419. return stat;
  420. }
  421. static int enable_tuner(struct mxl *state, u32 tuner, u32 enable);
  422. static int sleep(struct dvb_frontend *fe)
  423. {
  424. struct mxl *state = fe->demodulator_priv;
  425. struct mxl *p;
  426. cfg_demod_abort_tune(state);
  427. if (state->tuner_in_use != 0xffffffff) {
  428. mutex_lock(&state->base->tune_lock);
  429. state->tuner_in_use = 0xffffffff;
  430. list_for_each_entry(p, &state->base->mxls, mxl) {
  431. if (p->tuner_in_use == state->tuner)
  432. break;
  433. }
  434. if (&p->mxl == &state->base->mxls)
  435. enable_tuner(state, state->tuner, 0);
  436. mutex_unlock(&state->base->tune_lock);
  437. }
  438. return 0;
  439. }
  440. static int read_snr(struct dvb_frontend *fe)
  441. {
  442. struct mxl *state = fe->demodulator_priv;
  443. int stat;
  444. u32 reg_data = 0;
  445. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  446. mutex_lock(&state->base->status_lock);
  447. HYDRA_DEMOD_STATUS_LOCK(state, state->demod);
  448. stat = read_register(state, (HYDRA_DMD_SNR_ADDR_OFFSET +
  449. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  450. &reg_data);
  451. HYDRA_DEMOD_STATUS_UNLOCK(state, state->demod);
  452. mutex_unlock(&state->base->status_lock);
  453. p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  454. p->cnr.stat[0].svalue = (s16)reg_data * 10;
  455. return stat;
  456. }
  457. static int read_ber(struct dvb_frontend *fe)
  458. {
  459. struct mxl *state = fe->demodulator_priv;
  460. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  461. u32 reg[8];
  462. mutex_lock(&state->base->status_lock);
  463. HYDRA_DEMOD_STATUS_LOCK(state, state->demod);
  464. read_register_block(state,
  465. (HYDRA_DMD_DVBS_1ST_CORR_RS_ERRORS_ADDR_OFFSET +
  466. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  467. (4 * sizeof(u32)),
  468. (u8 *) &reg[0]);
  469. HYDRA_DEMOD_STATUS_UNLOCK(state, state->demod);
  470. switch (p->delivery_system) {
  471. case SYS_DSS:
  472. case SYS_DVBS:
  473. p->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  474. p->pre_bit_error.stat[0].uvalue = reg[2];
  475. p->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  476. p->pre_bit_count.stat[0].uvalue = reg[3];
  477. break;
  478. default:
  479. break;
  480. }
  481. read_register_block(state,
  482. (HYDRA_DMD_DVBS2_CRC_ERRORS_ADDR_OFFSET +
  483. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  484. (7 * sizeof(u32)),
  485. (u8 *) &reg[0]);
  486. switch (p->delivery_system) {
  487. case SYS_DSS:
  488. case SYS_DVBS:
  489. p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  490. p->post_bit_error.stat[0].uvalue = reg[5];
  491. p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  492. p->post_bit_count.stat[0].uvalue = reg[6];
  493. break;
  494. case SYS_DVBS2:
  495. p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  496. p->post_bit_error.stat[0].uvalue = reg[1];
  497. p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  498. p->post_bit_count.stat[0].uvalue = reg[2];
  499. break;
  500. default:
  501. break;
  502. }
  503. mutex_unlock(&state->base->status_lock);
  504. return 0;
  505. }
  506. static int read_signal_strength(struct dvb_frontend *fe)
  507. {
  508. struct mxl *state = fe->demodulator_priv;
  509. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  510. int stat;
  511. u32 reg_data = 0;
  512. mutex_lock(&state->base->status_lock);
  513. HYDRA_DEMOD_STATUS_LOCK(state, state->demod);
  514. stat = read_register(state, (HYDRA_DMD_STATUS_INPUT_POWER_ADDR +
  515. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  516. &reg_data);
  517. HYDRA_DEMOD_STATUS_UNLOCK(state, state->demod);
  518. mutex_unlock(&state->base->status_lock);
  519. p->strength.stat[0].scale = FE_SCALE_DECIBEL;
  520. p->strength.stat[0].svalue = (s16) reg_data * 10; /* fix scale */
  521. return stat;
  522. }
  523. static int read_status(struct dvb_frontend *fe, enum fe_status *status)
  524. {
  525. struct mxl *state = fe->demodulator_priv;
  526. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  527. u32 reg_data = 0;
  528. mutex_lock(&state->base->status_lock);
  529. HYDRA_DEMOD_STATUS_LOCK(state, state->demod);
  530. read_register(state, (HYDRA_DMD_LOCK_STATUS_ADDR_OFFSET +
  531. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  532. &reg_data);
  533. HYDRA_DEMOD_STATUS_UNLOCK(state, state->demod);
  534. mutex_unlock(&state->base->status_lock);
  535. *status = (reg_data == 1) ? 0x1f : 0;
  536. /* signal statistics */
  537. /* signal strength is always available */
  538. read_signal_strength(fe);
  539. if (*status & FE_HAS_CARRIER)
  540. read_snr(fe);
  541. else
  542. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  543. if (*status & FE_HAS_SYNC)
  544. read_ber(fe);
  545. else {
  546. p->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  547. p->pre_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  548. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  549. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  550. }
  551. return 0;
  552. }
  553. static int tune(struct dvb_frontend *fe, bool re_tune,
  554. unsigned int mode_flags,
  555. unsigned int *delay, enum fe_status *status)
  556. {
  557. struct mxl *state = fe->demodulator_priv;
  558. int r = 0;
  559. *delay = HZ / 2;
  560. if (re_tune) {
  561. r = set_parameters(fe);
  562. if (r)
  563. return r;
  564. state->tune_time = jiffies;
  565. }
  566. return read_status(fe, status);
  567. }
  568. static enum fe_code_rate conv_fec(enum MXL_HYDRA_FEC_E fec)
  569. {
  570. enum fe_code_rate fec2fec[11] = {
  571. FEC_NONE, FEC_1_2, FEC_3_5, FEC_2_3,
  572. FEC_3_4, FEC_4_5, FEC_5_6, FEC_6_7,
  573. FEC_7_8, FEC_8_9, FEC_9_10
  574. };
  575. if (fec > MXL_HYDRA_FEC_9_10)
  576. return FEC_NONE;
  577. return fec2fec[fec];
  578. }
  579. static int get_frontend(struct dvb_frontend *fe,
  580. struct dtv_frontend_properties *p)
  581. {
  582. struct mxl *state = fe->demodulator_priv;
  583. u32 reg_data[MXL_DEMOD_CHAN_PARAMS_BUFF_SIZE];
  584. u32 freq;
  585. mutex_lock(&state->base->status_lock);
  586. HYDRA_DEMOD_STATUS_LOCK(state, state->demod);
  587. read_register_block(state,
  588. (HYDRA_DMD_STANDARD_ADDR_OFFSET +
  589. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  590. (MXL_DEMOD_CHAN_PARAMS_BUFF_SIZE * 4), /* 25 * 4 bytes */
  591. (u8 *) &reg_data[0]);
  592. /* read demod channel parameters */
  593. read_register_block(state,
  594. (HYDRA_DMD_STATUS_CENTER_FREQ_IN_KHZ_ADDR +
  595. HYDRA_DMD_STATUS_OFFSET(state->demod)),
  596. (4), /* 4 bytes */
  597. (u8 *) &freq);
  598. HYDRA_DEMOD_STATUS_UNLOCK(state, state->demod);
  599. mutex_unlock(&state->base->status_lock);
  600. dev_dbg(state->i2cdev, "freq=%u delsys=%u srate=%u\n",
  601. freq * 1000, reg_data[DMD_STANDARD_ADDR],
  602. reg_data[DMD_SYMBOL_RATE_ADDR]);
  603. p->symbol_rate = reg_data[DMD_SYMBOL_RATE_ADDR];
  604. p->frequency = freq;
  605. /*
  606. * p->delivery_system =
  607. * (MXL_HYDRA_BCAST_STD_E) regData[DMD_STANDARD_ADDR];
  608. * p->inversion =
  609. * (MXL_HYDRA_SPECTRUM_E) regData[DMD_SPECTRUM_INVERSION_ADDR];
  610. * freqSearchRangeKHz =
  611. * (regData[DMD_FREQ_SEARCH_RANGE_IN_KHZ_ADDR]);
  612. */
  613. p->fec_inner = conv_fec(reg_data[DMD_FEC_CODE_RATE_ADDR]);
  614. switch (p->delivery_system) {
  615. case SYS_DSS:
  616. break;
  617. case SYS_DVBS2:
  618. switch ((enum MXL_HYDRA_PILOTS_E)
  619. reg_data[DMD_DVBS2_PILOT_ON_OFF_ADDR]) {
  620. case MXL_HYDRA_PILOTS_OFF:
  621. p->pilot = PILOT_OFF;
  622. break;
  623. case MXL_HYDRA_PILOTS_ON:
  624. p->pilot = PILOT_ON;
  625. break;
  626. default:
  627. break;
  628. }
  629. fallthrough;
  630. case SYS_DVBS:
  631. switch ((enum MXL_HYDRA_MODULATION_E)
  632. reg_data[DMD_MODULATION_SCHEME_ADDR]) {
  633. case MXL_HYDRA_MOD_QPSK:
  634. p->modulation = QPSK;
  635. break;
  636. case MXL_HYDRA_MOD_8PSK:
  637. p->modulation = PSK_8;
  638. break;
  639. default:
  640. break;
  641. }
  642. switch ((enum MXL_HYDRA_ROLLOFF_E)
  643. reg_data[DMD_SPECTRUM_ROLL_OFF_ADDR]) {
  644. case MXL_HYDRA_ROLLOFF_0_20:
  645. p->rolloff = ROLLOFF_20;
  646. break;
  647. case MXL_HYDRA_ROLLOFF_0_35:
  648. p->rolloff = ROLLOFF_35;
  649. break;
  650. case MXL_HYDRA_ROLLOFF_0_25:
  651. p->rolloff = ROLLOFF_25;
  652. break;
  653. default:
  654. break;
  655. }
  656. break;
  657. default:
  658. return -EINVAL;
  659. }
  660. return 0;
  661. }
  662. static int set_input(struct dvb_frontend *fe, int input)
  663. {
  664. struct mxl *state = fe->demodulator_priv;
  665. state->tuner = input;
  666. return 0;
  667. }
  668. static const struct dvb_frontend_ops mxl_ops = {
  669. .delsys = { SYS_DVBS, SYS_DVBS2, SYS_DSS },
  670. .info = {
  671. .name = "MaxLinear MxL5xx DVB-S/S2 tuner-demodulator",
  672. .frequency_min_hz = 300 * MHz,
  673. .frequency_max_hz = 2350 * MHz,
  674. .symbol_rate_min = 1000000,
  675. .symbol_rate_max = 45000000,
  676. .caps = FE_CAN_INVERSION_AUTO |
  677. FE_CAN_FEC_AUTO |
  678. FE_CAN_QPSK |
  679. FE_CAN_2G_MODULATION
  680. },
  681. .init = init,
  682. .release = release,
  683. .get_frontend_algo = get_algo,
  684. .tune = tune,
  685. .read_status = read_status,
  686. .sleep = sleep,
  687. .get_frontend = get_frontend,
  688. .diseqc_send_master_cmd = send_master_cmd,
  689. };
  690. static struct mxl_base *match_base(struct i2c_adapter *i2c, u8 adr)
  691. {
  692. struct mxl_base *p;
  693. list_for_each_entry(p, &mxllist, mxllist)
  694. if (p->i2c == i2c && p->adr == adr)
  695. return p;
  696. return NULL;
  697. }
  698. static void cfg_dev_xtal(struct mxl *state, u32 freq, u32 cap, u32 enable)
  699. {
  700. if (state->base->can_clkout || !enable)
  701. update_by_mnemonic(state, 0x90200054, 23, 1, enable);
  702. if (freq == 24000000)
  703. write_register(state, HYDRA_CRYSTAL_SETTING, 0);
  704. else
  705. write_register(state, HYDRA_CRYSTAL_SETTING, 1);
  706. write_register(state, HYDRA_CRYSTAL_CAP, cap);
  707. }
  708. static u32 get_big_endian(u8 num_of_bits, const u8 buf[])
  709. {
  710. u32 ret_value = 0;
  711. switch (num_of_bits) {
  712. case 24:
  713. ret_value = (((u32) buf[0]) << 16) |
  714. (((u32) buf[1]) << 8) | buf[2];
  715. break;
  716. case 32:
  717. ret_value = (((u32) buf[0]) << 24) |
  718. (((u32) buf[1]) << 16) |
  719. (((u32) buf[2]) << 8) | buf[3];
  720. break;
  721. default:
  722. break;
  723. }
  724. return ret_value;
  725. }
  726. static int write_fw_segment(struct mxl *state,
  727. u32 mem_addr, u32 total_size, u8 *data_ptr)
  728. {
  729. int status;
  730. u32 data_count = 0;
  731. u32 size = 0;
  732. u32 orig_size = 0;
  733. u8 *w_buf_ptr = NULL;
  734. u32 block_size = ((MXL_HYDRA_OEM_MAX_BLOCK_WRITE_LENGTH -
  735. (MXL_HYDRA_I2C_HDR_SIZE +
  736. MXL_HYDRA_REG_SIZE_IN_BYTES)) / 4) * 4;
  737. u8 w_msg_buffer[MXL_HYDRA_OEM_MAX_BLOCK_WRITE_LENGTH -
  738. (MXL_HYDRA_I2C_HDR_SIZE + MXL_HYDRA_REG_SIZE_IN_BYTES)];
  739. do {
  740. size = orig_size = (((u32)(data_count + block_size)) > total_size) ?
  741. (total_size - data_count) : block_size;
  742. if (orig_size & 3)
  743. size = (orig_size + 4) & ~3;
  744. w_buf_ptr = &w_msg_buffer[0];
  745. memset((void *) w_buf_ptr, 0, size);
  746. memcpy((void *) w_buf_ptr, (void *) data_ptr, orig_size);
  747. convert_endian(1, size, w_buf_ptr);
  748. status = write_firmware_block(state, mem_addr, size, w_buf_ptr);
  749. if (status)
  750. return status;
  751. data_count += size;
  752. mem_addr += size;
  753. data_ptr += size;
  754. } while (data_count < total_size);
  755. return status;
  756. }
  757. static int do_firmware_download(struct mxl *state, u8 *mbin_buffer_ptr,
  758. u32 mbin_buffer_size)
  759. {
  760. int status;
  761. u32 index = 0;
  762. u32 seg_length = 0;
  763. u32 seg_address = 0;
  764. struct MBIN_FILE_T *mbin_ptr = (struct MBIN_FILE_T *)mbin_buffer_ptr;
  765. struct MBIN_SEGMENT_T *segment_ptr;
  766. enum MXL_BOOL_E xcpu_fw_flag = MXL_FALSE;
  767. if (mbin_ptr->header.id != MBIN_FILE_HEADER_ID) {
  768. dev_err(state->i2cdev, "%s: Invalid file header ID (%c)\n",
  769. __func__, mbin_ptr->header.id);
  770. return -EINVAL;
  771. }
  772. status = write_register(state, FW_DL_SIGN_ADDR, 0);
  773. if (status)
  774. return status;
  775. segment_ptr = (struct MBIN_SEGMENT_T *) (&mbin_ptr->data[0]);
  776. for (index = 0; index < mbin_ptr->header.num_segments; index++) {
  777. if (segment_ptr->header.id != MBIN_SEGMENT_HEADER_ID) {
  778. dev_err(state->i2cdev, "%s: Invalid segment header ID (%c)\n",
  779. __func__, segment_ptr->header.id);
  780. return -EINVAL;
  781. }
  782. seg_length = get_big_endian(24,
  783. &(segment_ptr->header.len24[0]));
  784. seg_address = get_big_endian(32,
  785. &(segment_ptr->header.address[0]));
  786. if (state->base->type == MXL_HYDRA_DEVICE_568) {
  787. if ((((seg_address & 0x90760000) == 0x90760000) ||
  788. ((seg_address & 0x90740000) == 0x90740000)) &&
  789. (xcpu_fw_flag == MXL_FALSE)) {
  790. update_by_mnemonic(state, 0x8003003C, 0, 1, 1);
  791. msleep(200);
  792. write_register(state, 0x90720000, 0);
  793. usleep_range(10000, 11000);
  794. xcpu_fw_flag = MXL_TRUE;
  795. }
  796. status = write_fw_segment(state, seg_address,
  797. seg_length,
  798. (u8 *) segment_ptr->data);
  799. } else {
  800. if (((seg_address & 0x90760000) != 0x90760000) &&
  801. ((seg_address & 0x90740000) != 0x90740000))
  802. status = write_fw_segment(state, seg_address,
  803. seg_length, (u8 *) segment_ptr->data);
  804. }
  805. if (status)
  806. return status;
  807. segment_ptr = (struct MBIN_SEGMENT_T *)
  808. &(segment_ptr->data[((seg_length + 3) / 4) * 4]);
  809. }
  810. return status;
  811. }
  812. static int check_fw(struct mxl *state, u8 *mbin, u32 mbin_len)
  813. {
  814. struct MBIN_FILE_HEADER_T *fh = (struct MBIN_FILE_HEADER_T *) mbin;
  815. u32 flen = (fh->image_size24[0] << 16) |
  816. (fh->image_size24[1] << 8) | fh->image_size24[2];
  817. u8 *fw, cs = 0;
  818. u32 i;
  819. if (fh->id != 'M' || fh->fmt_version != '1' || flen > 0x3FFF0) {
  820. dev_info(state->i2cdev, "Invalid FW Header\n");
  821. return -1;
  822. }
  823. fw = mbin + sizeof(struct MBIN_FILE_HEADER_T);
  824. for (i = 0; i < flen; i += 1)
  825. cs += fw[i];
  826. if (cs != fh->image_checksum) {
  827. dev_info(state->i2cdev, "Invalid FW Checksum\n");
  828. return -1;
  829. }
  830. return 0;
  831. }
  832. static int firmware_download(struct mxl *state, u8 *mbin, u32 mbin_len)
  833. {
  834. int status;
  835. u32 reg_data = 0;
  836. struct MXL_HYDRA_SKU_COMMAND_T dev_sku_cfg;
  837. u8 cmd_size = sizeof(struct MXL_HYDRA_SKU_COMMAND_T);
  838. u8 cmd_buff[sizeof(struct MXL_HYDRA_SKU_COMMAND_T) + 6];
  839. if (check_fw(state, mbin, mbin_len))
  840. return -1;
  841. /* put CPU into reset */
  842. status = update_by_mnemonic(state, 0x8003003C, 0, 1, 0);
  843. if (status)
  844. return status;
  845. usleep_range(1000, 2000);
  846. /* Reset TX FIFO's, BBAND, XBAR */
  847. status = write_register(state, HYDRA_RESET_TRANSPORT_FIFO_REG,
  848. HYDRA_RESET_TRANSPORT_FIFO_DATA);
  849. if (status)
  850. return status;
  851. status = write_register(state, HYDRA_RESET_BBAND_REG,
  852. HYDRA_RESET_BBAND_DATA);
  853. if (status)
  854. return status;
  855. status = write_register(state, HYDRA_RESET_XBAR_REG,
  856. HYDRA_RESET_XBAR_DATA);
  857. if (status)
  858. return status;
  859. /* Disable clock to Baseband, Wideband, SerDes,
  860. * Alias ext & Transport modules
  861. */
  862. status = write_register(state, HYDRA_MODULES_CLK_2_REG,
  863. HYDRA_DISABLE_CLK_2);
  864. if (status)
  865. return status;
  866. /* Clear Software & Host interrupt status - (Clear on read) */
  867. status = read_register(state, HYDRA_PRCM_ROOT_CLK_REG, &reg_data);
  868. if (status)
  869. return status;
  870. status = do_firmware_download(state, mbin, mbin_len);
  871. if (status)
  872. return status;
  873. if (state->base->type == MXL_HYDRA_DEVICE_568) {
  874. usleep_range(10000, 11000);
  875. /* bring XCPU out of reset */
  876. status = write_register(state, 0x90720000, 1);
  877. if (status)
  878. return status;
  879. msleep(500);
  880. /* Enable XCPU UART message processing in MCPU */
  881. status = write_register(state, 0x9076B510, 1);
  882. if (status)
  883. return status;
  884. } else {
  885. /* Bring CPU out of reset */
  886. status = update_by_mnemonic(state, 0x8003003C, 0, 1, 1);
  887. if (status)
  888. return status;
  889. /* Wait until FW boots */
  890. msleep(150);
  891. }
  892. /* Initialize XPT XBAR */
  893. status = write_register(state, XPT_DMD0_BASEADDR, 0x76543210);
  894. if (status)
  895. return status;
  896. if (!firmware_is_alive(state))
  897. return -1;
  898. dev_info(state->i2cdev, "Hydra FW alive. Hail!\n");
  899. /* sometimes register values are wrong shortly
  900. * after first heart beats
  901. */
  902. msleep(50);
  903. dev_sku_cfg.sku_type = state->base->sku_type;
  904. BUILD_HYDRA_CMD(MXL_HYDRA_DEV_CFG_SKU_CMD, MXL_CMD_WRITE,
  905. cmd_size, &dev_sku_cfg, cmd_buff);
  906. status = send_command(state, cmd_size + MXL_HYDRA_CMD_HEADER_SIZE,
  907. &cmd_buff[0]);
  908. return status;
  909. }
  910. static int cfg_ts_pad_mux(struct mxl *state, enum MXL_BOOL_E enable_serial_ts)
  911. {
  912. int status = 0;
  913. u32 pad_mux_value = 0;
  914. if (enable_serial_ts == MXL_TRUE) {
  915. pad_mux_value = 0;
  916. if ((state->base->type == MXL_HYDRA_DEVICE_541) ||
  917. (state->base->type == MXL_HYDRA_DEVICE_541S))
  918. pad_mux_value = 2;
  919. } else {
  920. if ((state->base->type == MXL_HYDRA_DEVICE_581) ||
  921. (state->base->type == MXL_HYDRA_DEVICE_581S))
  922. pad_mux_value = 2;
  923. else
  924. pad_mux_value = 3;
  925. }
  926. switch (state->base->type) {
  927. case MXL_HYDRA_DEVICE_561:
  928. case MXL_HYDRA_DEVICE_581:
  929. case MXL_HYDRA_DEVICE_541:
  930. case MXL_HYDRA_DEVICE_541S:
  931. case MXL_HYDRA_DEVICE_561S:
  932. case MXL_HYDRA_DEVICE_581S:
  933. status |= update_by_mnemonic(state, 0x90000170, 24, 3,
  934. pad_mux_value);
  935. status |= update_by_mnemonic(state, 0x90000170, 28, 3,
  936. pad_mux_value);
  937. status |= update_by_mnemonic(state, 0x90000174, 0, 3,
  938. pad_mux_value);
  939. status |= update_by_mnemonic(state, 0x90000174, 4, 3,
  940. pad_mux_value);
  941. status |= update_by_mnemonic(state, 0x90000174, 8, 3,
  942. pad_mux_value);
  943. status |= update_by_mnemonic(state, 0x90000174, 12, 3,
  944. pad_mux_value);
  945. status |= update_by_mnemonic(state, 0x90000174, 16, 3,
  946. pad_mux_value);
  947. status |= update_by_mnemonic(state, 0x90000174, 20, 3,
  948. pad_mux_value);
  949. status |= update_by_mnemonic(state, 0x90000174, 24, 3,
  950. pad_mux_value);
  951. status |= update_by_mnemonic(state, 0x90000174, 28, 3,
  952. pad_mux_value);
  953. status |= update_by_mnemonic(state, 0x90000178, 0, 3,
  954. pad_mux_value);
  955. status |= update_by_mnemonic(state, 0x90000178, 4, 3,
  956. pad_mux_value);
  957. status |= update_by_mnemonic(state, 0x90000178, 8, 3,
  958. pad_mux_value);
  959. break;
  960. case MXL_HYDRA_DEVICE_544:
  961. case MXL_HYDRA_DEVICE_542:
  962. status |= update_by_mnemonic(state, 0x9000016C, 4, 3, 1);
  963. status |= update_by_mnemonic(state, 0x9000016C, 8, 3, 0);
  964. status |= update_by_mnemonic(state, 0x9000016C, 12, 3, 0);
  965. status |= update_by_mnemonic(state, 0x9000016C, 16, 3, 0);
  966. status |= update_by_mnemonic(state, 0x90000170, 0, 3, 0);
  967. status |= update_by_mnemonic(state, 0x90000178, 12, 3, 1);
  968. status |= update_by_mnemonic(state, 0x90000178, 16, 3, 1);
  969. status |= update_by_mnemonic(state, 0x90000178, 20, 3, 1);
  970. status |= update_by_mnemonic(state, 0x90000178, 24, 3, 1);
  971. status |= update_by_mnemonic(state, 0x9000017C, 0, 3, 1);
  972. status |= update_by_mnemonic(state, 0x9000017C, 4, 3, 1);
  973. if (enable_serial_ts == MXL_ENABLE) {
  974. status |= update_by_mnemonic(state,
  975. 0x90000170, 4, 3, 0);
  976. status |= update_by_mnemonic(state,
  977. 0x90000170, 8, 3, 0);
  978. status |= update_by_mnemonic(state,
  979. 0x90000170, 12, 3, 0);
  980. status |= update_by_mnemonic(state,
  981. 0x90000170, 16, 3, 0);
  982. status |= update_by_mnemonic(state,
  983. 0x90000170, 20, 3, 1);
  984. status |= update_by_mnemonic(state,
  985. 0x90000170, 24, 3, 1);
  986. status |= update_by_mnemonic(state,
  987. 0x90000170, 28, 3, 2);
  988. status |= update_by_mnemonic(state,
  989. 0x90000174, 0, 3, 2);
  990. status |= update_by_mnemonic(state,
  991. 0x90000174, 4, 3, 2);
  992. status |= update_by_mnemonic(state,
  993. 0x90000174, 8, 3, 2);
  994. status |= update_by_mnemonic(state,
  995. 0x90000174, 12, 3, 2);
  996. status |= update_by_mnemonic(state,
  997. 0x90000174, 16, 3, 2);
  998. status |= update_by_mnemonic(state,
  999. 0x90000174, 20, 3, 2);
  1000. status |= update_by_mnemonic(state,
  1001. 0x90000174, 24, 3, 2);
  1002. status |= update_by_mnemonic(state,
  1003. 0x90000174, 28, 3, 2);
  1004. status |= update_by_mnemonic(state,
  1005. 0x90000178, 0, 3, 2);
  1006. status |= update_by_mnemonic(state,
  1007. 0x90000178, 4, 3, 2);
  1008. status |= update_by_mnemonic(state,
  1009. 0x90000178, 8, 3, 2);
  1010. } else {
  1011. status |= update_by_mnemonic(state,
  1012. 0x90000170, 4, 3, 3);
  1013. status |= update_by_mnemonic(state,
  1014. 0x90000170, 8, 3, 3);
  1015. status |= update_by_mnemonic(state,
  1016. 0x90000170, 12, 3, 3);
  1017. status |= update_by_mnemonic(state,
  1018. 0x90000170, 16, 3, 3);
  1019. status |= update_by_mnemonic(state,
  1020. 0x90000170, 20, 3, 3);
  1021. status |= update_by_mnemonic(state,
  1022. 0x90000170, 24, 3, 3);
  1023. status |= update_by_mnemonic(state,
  1024. 0x90000170, 28, 3, 3);
  1025. status |= update_by_mnemonic(state,
  1026. 0x90000174, 0, 3, 3);
  1027. status |= update_by_mnemonic(state,
  1028. 0x90000174, 4, 3, 3);
  1029. status |= update_by_mnemonic(state,
  1030. 0x90000174, 8, 3, 3);
  1031. status |= update_by_mnemonic(state,
  1032. 0x90000174, 12, 3, 3);
  1033. status |= update_by_mnemonic(state,
  1034. 0x90000174, 16, 3, 3);
  1035. status |= update_by_mnemonic(state,
  1036. 0x90000174, 20, 3, 1);
  1037. status |= update_by_mnemonic(state,
  1038. 0x90000174, 24, 3, 1);
  1039. status |= update_by_mnemonic(state,
  1040. 0x90000174, 28, 3, 1);
  1041. status |= update_by_mnemonic(state,
  1042. 0x90000178, 0, 3, 1);
  1043. status |= update_by_mnemonic(state,
  1044. 0x90000178, 4, 3, 1);
  1045. status |= update_by_mnemonic(state,
  1046. 0x90000178, 8, 3, 1);
  1047. }
  1048. break;
  1049. case MXL_HYDRA_DEVICE_568:
  1050. if (enable_serial_ts == MXL_FALSE) {
  1051. status |= update_by_mnemonic(state,
  1052. 0x9000016C, 8, 3, 5);
  1053. status |= update_by_mnemonic(state,
  1054. 0x9000016C, 12, 3, 5);
  1055. status |= update_by_mnemonic(state,
  1056. 0x9000016C, 16, 3, 5);
  1057. status |= update_by_mnemonic(state,
  1058. 0x9000016C, 20, 3, 5);
  1059. status |= update_by_mnemonic(state,
  1060. 0x9000016C, 24, 3, 5);
  1061. status |= update_by_mnemonic(state,
  1062. 0x9000016C, 28, 3, 5);
  1063. status |= update_by_mnemonic(state,
  1064. 0x90000170, 0, 3, 5);
  1065. status |= update_by_mnemonic(state,
  1066. 0x90000170, 4, 3, 5);
  1067. status |= update_by_mnemonic(state,
  1068. 0x90000170, 8, 3, 5);
  1069. status |= update_by_mnemonic(state,
  1070. 0x90000170, 12, 3, 5);
  1071. status |= update_by_mnemonic(state,
  1072. 0x90000170, 16, 3, 5);
  1073. status |= update_by_mnemonic(state,
  1074. 0x90000170, 20, 3, 5);
  1075. status |= update_by_mnemonic(state,
  1076. 0x90000170, 24, 3, pad_mux_value);
  1077. status |= update_by_mnemonic(state,
  1078. 0x90000174, 0, 3, pad_mux_value);
  1079. status |= update_by_mnemonic(state,
  1080. 0x90000174, 4, 3, pad_mux_value);
  1081. status |= update_by_mnemonic(state,
  1082. 0x90000174, 8, 3, pad_mux_value);
  1083. status |= update_by_mnemonic(state,
  1084. 0x90000174, 12, 3, pad_mux_value);
  1085. status |= update_by_mnemonic(state,
  1086. 0x90000174, 16, 3, pad_mux_value);
  1087. status |= update_by_mnemonic(state,
  1088. 0x90000174, 20, 3, pad_mux_value);
  1089. status |= update_by_mnemonic(state,
  1090. 0x90000174, 24, 3, pad_mux_value);
  1091. status |= update_by_mnemonic(state,
  1092. 0x90000174, 28, 3, pad_mux_value);
  1093. status |= update_by_mnemonic(state,
  1094. 0x90000178, 0, 3, pad_mux_value);
  1095. status |= update_by_mnemonic(state,
  1096. 0x90000178, 4, 3, pad_mux_value);
  1097. status |= update_by_mnemonic(state,
  1098. 0x90000178, 8, 3, 5);
  1099. status |= update_by_mnemonic(state,
  1100. 0x90000178, 12, 3, 5);
  1101. status |= update_by_mnemonic(state,
  1102. 0x90000178, 16, 3, 5);
  1103. status |= update_by_mnemonic(state,
  1104. 0x90000178, 20, 3, 5);
  1105. status |= update_by_mnemonic(state,
  1106. 0x90000178, 24, 3, 5);
  1107. status |= update_by_mnemonic(state,
  1108. 0x90000178, 28, 3, 5);
  1109. status |= update_by_mnemonic(state,
  1110. 0x9000017C, 0, 3, 5);
  1111. status |= update_by_mnemonic(state,
  1112. 0x9000017C, 4, 3, 5);
  1113. } else {
  1114. status |= update_by_mnemonic(state,
  1115. 0x90000170, 4, 3, pad_mux_value);
  1116. status |= update_by_mnemonic(state,
  1117. 0x90000170, 8, 3, pad_mux_value);
  1118. status |= update_by_mnemonic(state,
  1119. 0x90000170, 12, 3, pad_mux_value);
  1120. status |= update_by_mnemonic(state,
  1121. 0x90000170, 16, 3, pad_mux_value);
  1122. status |= update_by_mnemonic(state,
  1123. 0x90000170, 20, 3, pad_mux_value);
  1124. status |= update_by_mnemonic(state,
  1125. 0x90000170, 24, 3, pad_mux_value);
  1126. status |= update_by_mnemonic(state,
  1127. 0x90000170, 28, 3, pad_mux_value);
  1128. status |= update_by_mnemonic(state,
  1129. 0x90000174, 0, 3, pad_mux_value);
  1130. status |= update_by_mnemonic(state,
  1131. 0x90000174, 4, 3, pad_mux_value);
  1132. status |= update_by_mnemonic(state,
  1133. 0x90000174, 8, 3, pad_mux_value);
  1134. status |= update_by_mnemonic(state,
  1135. 0x90000174, 12, 3, pad_mux_value);
  1136. }
  1137. break;
  1138. case MXL_HYDRA_DEVICE_584:
  1139. default:
  1140. status |= update_by_mnemonic(state,
  1141. 0x90000170, 4, 3, pad_mux_value);
  1142. status |= update_by_mnemonic(state,
  1143. 0x90000170, 8, 3, pad_mux_value);
  1144. status |= update_by_mnemonic(state,
  1145. 0x90000170, 12, 3, pad_mux_value);
  1146. status |= update_by_mnemonic(state,
  1147. 0x90000170, 16, 3, pad_mux_value);
  1148. status |= update_by_mnemonic(state,
  1149. 0x90000170, 20, 3, pad_mux_value);
  1150. status |= update_by_mnemonic(state,
  1151. 0x90000170, 24, 3, pad_mux_value);
  1152. status |= update_by_mnemonic(state,
  1153. 0x90000170, 28, 3, pad_mux_value);
  1154. status |= update_by_mnemonic(state,
  1155. 0x90000174, 0, 3, pad_mux_value);
  1156. status |= update_by_mnemonic(state,
  1157. 0x90000174, 4, 3, pad_mux_value);
  1158. status |= update_by_mnemonic(state,
  1159. 0x90000174, 8, 3, pad_mux_value);
  1160. status |= update_by_mnemonic(state,
  1161. 0x90000174, 12, 3, pad_mux_value);
  1162. break;
  1163. }
  1164. return status;
  1165. }
  1166. static int set_drive_strength(struct mxl *state,
  1167. enum MXL_HYDRA_TS_DRIVE_STRENGTH_E ts_drive_strength)
  1168. {
  1169. int stat = 0;
  1170. u32 val;
  1171. read_register(state, 0x90000194, &val);
  1172. dev_info(state->i2cdev, "DIGIO = %08x\n", val);
  1173. dev_info(state->i2cdev, "set drive_strength = %u\n", ts_drive_strength);
  1174. stat |= update_by_mnemonic(state, 0x90000194, 0, 3, ts_drive_strength);
  1175. stat |= update_by_mnemonic(state, 0x90000194, 20, 3, ts_drive_strength);
  1176. stat |= update_by_mnemonic(state, 0x90000194, 24, 3, ts_drive_strength);
  1177. stat |= update_by_mnemonic(state, 0x90000198, 12, 3, ts_drive_strength);
  1178. stat |= update_by_mnemonic(state, 0x90000198, 16, 3, ts_drive_strength);
  1179. stat |= update_by_mnemonic(state, 0x90000198, 20, 3, ts_drive_strength);
  1180. stat |= update_by_mnemonic(state, 0x90000198, 24, 3, ts_drive_strength);
  1181. stat |= update_by_mnemonic(state, 0x9000019C, 0, 3, ts_drive_strength);
  1182. stat |= update_by_mnemonic(state, 0x9000019C, 4, 3, ts_drive_strength);
  1183. stat |= update_by_mnemonic(state, 0x9000019C, 8, 3, ts_drive_strength);
  1184. stat |= update_by_mnemonic(state, 0x9000019C, 24, 3, ts_drive_strength);
  1185. stat |= update_by_mnemonic(state, 0x9000019C, 28, 3, ts_drive_strength);
  1186. stat |= update_by_mnemonic(state, 0x900001A0, 0, 3, ts_drive_strength);
  1187. stat |= update_by_mnemonic(state, 0x900001A0, 4, 3, ts_drive_strength);
  1188. stat |= update_by_mnemonic(state, 0x900001A0, 20, 3, ts_drive_strength);
  1189. stat |= update_by_mnemonic(state, 0x900001A0, 24, 3, ts_drive_strength);
  1190. stat |= update_by_mnemonic(state, 0x900001A0, 28, 3, ts_drive_strength);
  1191. return stat;
  1192. }
  1193. static int enable_tuner(struct mxl *state, u32 tuner, u32 enable)
  1194. {
  1195. int stat = 0;
  1196. struct MXL_HYDRA_TUNER_CMD ctrl_tuner_cmd;
  1197. u8 cmd_size = sizeof(ctrl_tuner_cmd);
  1198. u8 cmd_buff[MXL_HYDRA_OEM_MAX_CMD_BUFF_LEN];
  1199. u32 val, count = 10;
  1200. ctrl_tuner_cmd.tuner_id = tuner;
  1201. ctrl_tuner_cmd.enable = enable;
  1202. BUILD_HYDRA_CMD(MXL_HYDRA_TUNER_ACTIVATE_CMD, MXL_CMD_WRITE,
  1203. cmd_size, &ctrl_tuner_cmd, cmd_buff);
  1204. stat = send_command(state, cmd_size + MXL_HYDRA_CMD_HEADER_SIZE,
  1205. &cmd_buff[0]);
  1206. if (stat)
  1207. return stat;
  1208. read_register(state, HYDRA_TUNER_ENABLE_COMPLETE, &val);
  1209. while (--count && ((val >> tuner) & 1) != enable) {
  1210. msleep(20);
  1211. read_register(state, HYDRA_TUNER_ENABLE_COMPLETE, &val);
  1212. }
  1213. if (!count)
  1214. return -1;
  1215. read_register(state, HYDRA_TUNER_ENABLE_COMPLETE, &val);
  1216. dev_dbg(state->i2cdev, "tuner %u ready = %u\n",
  1217. tuner, (val >> tuner) & 1);
  1218. return 0;
  1219. }
  1220. static int config_ts(struct mxl *state, enum MXL_HYDRA_DEMOD_ID_E demod_id,
  1221. struct MXL_HYDRA_MPEGOUT_PARAM_T *mpeg_out_param_ptr)
  1222. {
  1223. int status = 0;
  1224. u32 nco_count_min = 0;
  1225. u32 clk_type = 0;
  1226. static const struct MXL_REG_FIELD_T xpt_sync_polarity[MXL_HYDRA_DEMOD_MAX] = {
  1227. {0x90700010, 8, 1}, {0x90700010, 9, 1},
  1228. {0x90700010, 10, 1}, {0x90700010, 11, 1},
  1229. {0x90700010, 12, 1}, {0x90700010, 13, 1},
  1230. {0x90700010, 14, 1}, {0x90700010, 15, 1} };
  1231. static const struct MXL_REG_FIELD_T xpt_clock_polarity[MXL_HYDRA_DEMOD_MAX] = {
  1232. {0x90700010, 16, 1}, {0x90700010, 17, 1},
  1233. {0x90700010, 18, 1}, {0x90700010, 19, 1},
  1234. {0x90700010, 20, 1}, {0x90700010, 21, 1},
  1235. {0x90700010, 22, 1}, {0x90700010, 23, 1} };
  1236. static const struct MXL_REG_FIELD_T xpt_valid_polarity[MXL_HYDRA_DEMOD_MAX] = {
  1237. {0x90700014, 0, 1}, {0x90700014, 1, 1},
  1238. {0x90700014, 2, 1}, {0x90700014, 3, 1},
  1239. {0x90700014, 4, 1}, {0x90700014, 5, 1},
  1240. {0x90700014, 6, 1}, {0x90700014, 7, 1} };
  1241. static const struct MXL_REG_FIELD_T xpt_ts_clock_phase[MXL_HYDRA_DEMOD_MAX] = {
  1242. {0x90700018, 0, 3}, {0x90700018, 4, 3},
  1243. {0x90700018, 8, 3}, {0x90700018, 12, 3},
  1244. {0x90700018, 16, 3}, {0x90700018, 20, 3},
  1245. {0x90700018, 24, 3}, {0x90700018, 28, 3} };
  1246. static const struct MXL_REG_FIELD_T xpt_lsb_first[MXL_HYDRA_DEMOD_MAX] = {
  1247. {0x9070000C, 16, 1}, {0x9070000C, 17, 1},
  1248. {0x9070000C, 18, 1}, {0x9070000C, 19, 1},
  1249. {0x9070000C, 20, 1}, {0x9070000C, 21, 1},
  1250. {0x9070000C, 22, 1}, {0x9070000C, 23, 1} };
  1251. static const struct MXL_REG_FIELD_T xpt_sync_byte[MXL_HYDRA_DEMOD_MAX] = {
  1252. {0x90700010, 0, 1}, {0x90700010, 1, 1},
  1253. {0x90700010, 2, 1}, {0x90700010, 3, 1},
  1254. {0x90700010, 4, 1}, {0x90700010, 5, 1},
  1255. {0x90700010, 6, 1}, {0x90700010, 7, 1} };
  1256. static const struct MXL_REG_FIELD_T xpt_enable_output[MXL_HYDRA_DEMOD_MAX] = {
  1257. {0x9070000C, 0, 1}, {0x9070000C, 1, 1},
  1258. {0x9070000C, 2, 1}, {0x9070000C, 3, 1},
  1259. {0x9070000C, 4, 1}, {0x9070000C, 5, 1},
  1260. {0x9070000C, 6, 1}, {0x9070000C, 7, 1} };
  1261. static const struct MXL_REG_FIELD_T xpt_err_replace_sync[MXL_HYDRA_DEMOD_MAX] = {
  1262. {0x9070000C, 24, 1}, {0x9070000C, 25, 1},
  1263. {0x9070000C, 26, 1}, {0x9070000C, 27, 1},
  1264. {0x9070000C, 28, 1}, {0x9070000C, 29, 1},
  1265. {0x9070000C, 30, 1}, {0x9070000C, 31, 1} };
  1266. static const struct MXL_REG_FIELD_T xpt_err_replace_valid[MXL_HYDRA_DEMOD_MAX] = {
  1267. {0x90700014, 8, 1}, {0x90700014, 9, 1},
  1268. {0x90700014, 10, 1}, {0x90700014, 11, 1},
  1269. {0x90700014, 12, 1}, {0x90700014, 13, 1},
  1270. {0x90700014, 14, 1}, {0x90700014, 15, 1} };
  1271. static const struct MXL_REG_FIELD_T xpt_continuous_clock[MXL_HYDRA_DEMOD_MAX] = {
  1272. {0x907001D4, 0, 1}, {0x907001D4, 1, 1},
  1273. {0x907001D4, 2, 1}, {0x907001D4, 3, 1},
  1274. {0x907001D4, 4, 1}, {0x907001D4, 5, 1},
  1275. {0x907001D4, 6, 1}, {0x907001D4, 7, 1} };
  1276. static const struct MXL_REG_FIELD_T xpt_nco_clock_rate[MXL_HYDRA_DEMOD_MAX] = {
  1277. {0x90700044, 16, 80}, {0x90700044, 16, 81},
  1278. {0x90700044, 16, 82}, {0x90700044, 16, 83},
  1279. {0x90700044, 16, 84}, {0x90700044, 16, 85},
  1280. {0x90700044, 16, 86}, {0x90700044, 16, 87} };
  1281. demod_id = state->base->ts_map[demod_id];
  1282. if (mpeg_out_param_ptr->enable == MXL_ENABLE) {
  1283. if (mpeg_out_param_ptr->mpeg_mode ==
  1284. MXL_HYDRA_MPEG_MODE_PARALLEL) {
  1285. } else {
  1286. cfg_ts_pad_mux(state, MXL_TRUE);
  1287. update_by_mnemonic(state,
  1288. 0x90700010, 27, 1, MXL_FALSE);
  1289. }
  1290. }
  1291. nco_count_min =
  1292. (u32)(MXL_HYDRA_NCO_CLK / mpeg_out_param_ptr->max_mpeg_clk_rate);
  1293. if (state->base->chipversion >= 2) {
  1294. status |= update_by_mnemonic(state,
  1295. xpt_nco_clock_rate[demod_id].reg_addr, /* Reg Addr */
  1296. xpt_nco_clock_rate[demod_id].lsb_pos, /* LSB pos */
  1297. xpt_nco_clock_rate[demod_id].num_of_bits, /* Num of bits */
  1298. nco_count_min); /* Data */
  1299. } else
  1300. update_by_mnemonic(state, 0x90700044, 16, 8, nco_count_min);
  1301. if (mpeg_out_param_ptr->mpeg_clk_type == MXL_HYDRA_MPEG_CLK_CONTINUOUS)
  1302. clk_type = 1;
  1303. if (mpeg_out_param_ptr->mpeg_mode < MXL_HYDRA_MPEG_MODE_PARALLEL) {
  1304. status |= update_by_mnemonic(state,
  1305. xpt_continuous_clock[demod_id].reg_addr,
  1306. xpt_continuous_clock[demod_id].lsb_pos,
  1307. xpt_continuous_clock[demod_id].num_of_bits,
  1308. clk_type);
  1309. } else
  1310. update_by_mnemonic(state, 0x907001D4, 8, 1, clk_type);
  1311. status |= update_by_mnemonic(state,
  1312. xpt_sync_polarity[demod_id].reg_addr,
  1313. xpt_sync_polarity[demod_id].lsb_pos,
  1314. xpt_sync_polarity[demod_id].num_of_bits,
  1315. mpeg_out_param_ptr->mpeg_sync_pol);
  1316. status |= update_by_mnemonic(state,
  1317. xpt_valid_polarity[demod_id].reg_addr,
  1318. xpt_valid_polarity[demod_id].lsb_pos,
  1319. xpt_valid_polarity[demod_id].num_of_bits,
  1320. mpeg_out_param_ptr->mpeg_valid_pol);
  1321. status |= update_by_mnemonic(state,
  1322. xpt_clock_polarity[demod_id].reg_addr,
  1323. xpt_clock_polarity[demod_id].lsb_pos,
  1324. xpt_clock_polarity[demod_id].num_of_bits,
  1325. mpeg_out_param_ptr->mpeg_clk_pol);
  1326. status |= update_by_mnemonic(state,
  1327. xpt_sync_byte[demod_id].reg_addr,
  1328. xpt_sync_byte[demod_id].lsb_pos,
  1329. xpt_sync_byte[demod_id].num_of_bits,
  1330. mpeg_out_param_ptr->mpeg_sync_pulse_width);
  1331. status |= update_by_mnemonic(state,
  1332. xpt_ts_clock_phase[demod_id].reg_addr,
  1333. xpt_ts_clock_phase[demod_id].lsb_pos,
  1334. xpt_ts_clock_phase[demod_id].num_of_bits,
  1335. mpeg_out_param_ptr->mpeg_clk_phase);
  1336. status |= update_by_mnemonic(state,
  1337. xpt_lsb_first[demod_id].reg_addr,
  1338. xpt_lsb_first[demod_id].lsb_pos,
  1339. xpt_lsb_first[demod_id].num_of_bits,
  1340. mpeg_out_param_ptr->lsb_or_msb_first);
  1341. switch (mpeg_out_param_ptr->mpeg_error_indication) {
  1342. case MXL_HYDRA_MPEG_ERR_REPLACE_SYNC:
  1343. status |= update_by_mnemonic(state,
  1344. xpt_err_replace_sync[demod_id].reg_addr,
  1345. xpt_err_replace_sync[demod_id].lsb_pos,
  1346. xpt_err_replace_sync[demod_id].num_of_bits,
  1347. MXL_TRUE);
  1348. status |= update_by_mnemonic(state,
  1349. xpt_err_replace_valid[demod_id].reg_addr,
  1350. xpt_err_replace_valid[demod_id].lsb_pos,
  1351. xpt_err_replace_valid[demod_id].num_of_bits,
  1352. MXL_FALSE);
  1353. break;
  1354. case MXL_HYDRA_MPEG_ERR_REPLACE_VALID:
  1355. status |= update_by_mnemonic(state,
  1356. xpt_err_replace_sync[demod_id].reg_addr,
  1357. xpt_err_replace_sync[demod_id].lsb_pos,
  1358. xpt_err_replace_sync[demod_id].num_of_bits,
  1359. MXL_FALSE);
  1360. status |= update_by_mnemonic(state,
  1361. xpt_err_replace_valid[demod_id].reg_addr,
  1362. xpt_err_replace_valid[demod_id].lsb_pos,
  1363. xpt_err_replace_valid[demod_id].num_of_bits,
  1364. MXL_TRUE);
  1365. break;
  1366. case MXL_HYDRA_MPEG_ERR_INDICATION_DISABLED:
  1367. default:
  1368. status |= update_by_mnemonic(state,
  1369. xpt_err_replace_sync[demod_id].reg_addr,
  1370. xpt_err_replace_sync[demod_id].lsb_pos,
  1371. xpt_err_replace_sync[demod_id].num_of_bits,
  1372. MXL_FALSE);
  1373. status |= update_by_mnemonic(state,
  1374. xpt_err_replace_valid[demod_id].reg_addr,
  1375. xpt_err_replace_valid[demod_id].lsb_pos,
  1376. xpt_err_replace_valid[demod_id].num_of_bits,
  1377. MXL_FALSE);
  1378. break;
  1379. }
  1380. if (mpeg_out_param_ptr->mpeg_mode != MXL_HYDRA_MPEG_MODE_PARALLEL) {
  1381. status |= update_by_mnemonic(state,
  1382. xpt_enable_output[demod_id].reg_addr,
  1383. xpt_enable_output[demod_id].lsb_pos,
  1384. xpt_enable_output[demod_id].num_of_bits,
  1385. mpeg_out_param_ptr->enable);
  1386. }
  1387. return status;
  1388. }
  1389. static int config_mux(struct mxl *state)
  1390. {
  1391. update_by_mnemonic(state, 0x9070000C, 0, 1, 0);
  1392. update_by_mnemonic(state, 0x9070000C, 1, 1, 0);
  1393. update_by_mnemonic(state, 0x9070000C, 2, 1, 0);
  1394. update_by_mnemonic(state, 0x9070000C, 3, 1, 0);
  1395. update_by_mnemonic(state, 0x9070000C, 4, 1, 0);
  1396. update_by_mnemonic(state, 0x9070000C, 5, 1, 0);
  1397. update_by_mnemonic(state, 0x9070000C, 6, 1, 0);
  1398. update_by_mnemonic(state, 0x9070000C, 7, 1, 0);
  1399. update_by_mnemonic(state, 0x90700008, 0, 2, 1);
  1400. update_by_mnemonic(state, 0x90700008, 2, 2, 1);
  1401. return 0;
  1402. }
  1403. static int load_fw(struct mxl *state, struct mxl5xx_cfg *cfg)
  1404. {
  1405. int stat = 0;
  1406. u8 *buf;
  1407. if (cfg->fw)
  1408. return firmware_download(state, cfg->fw, cfg->fw_len);
  1409. if (!cfg->fw_read)
  1410. return -1;
  1411. buf = vmalloc(0x40000);
  1412. if (!buf)
  1413. return -ENOMEM;
  1414. cfg->fw_read(cfg->fw_priv, buf, 0x40000);
  1415. stat = firmware_download(state, buf, 0x40000);
  1416. vfree(buf);
  1417. return stat;
  1418. }
  1419. static int validate_sku(struct mxl *state)
  1420. {
  1421. u32 pad_mux_bond = 0, prcm_chip_id = 0, prcm_so_cid = 0;
  1422. int status;
  1423. u32 type = state->base->type;
  1424. status = read_by_mnemonic(state, 0x90000190, 0, 3, &pad_mux_bond);
  1425. status |= read_by_mnemonic(state, 0x80030000, 0, 12, &prcm_chip_id);
  1426. status |= read_by_mnemonic(state, 0x80030004, 24, 8, &prcm_so_cid);
  1427. if (status)
  1428. return -1;
  1429. dev_info(state->i2cdev, "padMuxBond=%08x, prcmChipId=%08x, prcmSoCId=%08x\n",
  1430. pad_mux_bond, prcm_chip_id, prcm_so_cid);
  1431. if (prcm_chip_id != 0x560) {
  1432. switch (pad_mux_bond) {
  1433. case MXL_HYDRA_SKU_ID_581:
  1434. if (type == MXL_HYDRA_DEVICE_581)
  1435. return 0;
  1436. if (type == MXL_HYDRA_DEVICE_581S) {
  1437. state->base->type = MXL_HYDRA_DEVICE_581;
  1438. return 0;
  1439. }
  1440. break;
  1441. case MXL_HYDRA_SKU_ID_584:
  1442. if (type == MXL_HYDRA_DEVICE_584)
  1443. return 0;
  1444. break;
  1445. case MXL_HYDRA_SKU_ID_544:
  1446. if (type == MXL_HYDRA_DEVICE_544)
  1447. return 0;
  1448. if (type == MXL_HYDRA_DEVICE_542)
  1449. return 0;
  1450. break;
  1451. case MXL_HYDRA_SKU_ID_582:
  1452. if (type == MXL_HYDRA_DEVICE_582)
  1453. return 0;
  1454. break;
  1455. default:
  1456. return -1;
  1457. }
  1458. }
  1459. return -1;
  1460. }
  1461. static int get_fwinfo(struct mxl *state)
  1462. {
  1463. int status;
  1464. u32 val = 0;
  1465. status = read_by_mnemonic(state, 0x90000190, 0, 3, &val);
  1466. if (status)
  1467. return status;
  1468. dev_info(state->i2cdev, "chipID=%08x\n", val);
  1469. status = read_by_mnemonic(state, 0x80030004, 8, 8, &val);
  1470. if (status)
  1471. return status;
  1472. dev_info(state->i2cdev, "chipVer=%08x\n", val);
  1473. status = read_register(state, HYDRA_FIRMWARE_VERSION, &val);
  1474. if (status)
  1475. return status;
  1476. dev_info(state->i2cdev, "FWVer=%08x\n", val);
  1477. state->base->fwversion = val;
  1478. return status;
  1479. }
  1480. static u8 ts_map1_to_1[MXL_HYDRA_DEMOD_MAX] = {
  1481. MXL_HYDRA_DEMOD_ID_0,
  1482. MXL_HYDRA_DEMOD_ID_1,
  1483. MXL_HYDRA_DEMOD_ID_2,
  1484. MXL_HYDRA_DEMOD_ID_3,
  1485. MXL_HYDRA_DEMOD_ID_4,
  1486. MXL_HYDRA_DEMOD_ID_5,
  1487. MXL_HYDRA_DEMOD_ID_6,
  1488. MXL_HYDRA_DEMOD_ID_7,
  1489. };
  1490. static u8 ts_map54x[MXL_HYDRA_DEMOD_MAX] = {
  1491. MXL_HYDRA_DEMOD_ID_2,
  1492. MXL_HYDRA_DEMOD_ID_3,
  1493. MXL_HYDRA_DEMOD_ID_4,
  1494. MXL_HYDRA_DEMOD_ID_5,
  1495. MXL_HYDRA_DEMOD_MAX,
  1496. MXL_HYDRA_DEMOD_MAX,
  1497. MXL_HYDRA_DEMOD_MAX,
  1498. MXL_HYDRA_DEMOD_MAX,
  1499. };
  1500. static int probe(struct mxl *state, struct mxl5xx_cfg *cfg)
  1501. {
  1502. u32 chipver;
  1503. int fw, status, j;
  1504. struct MXL_HYDRA_MPEGOUT_PARAM_T mpeg_interface_cfg;
  1505. state->base->ts_map = ts_map1_to_1;
  1506. switch (state->base->type) {
  1507. case MXL_HYDRA_DEVICE_581:
  1508. case MXL_HYDRA_DEVICE_581S:
  1509. state->base->can_clkout = 1;
  1510. state->base->demod_num = 8;
  1511. state->base->tuner_num = 1;
  1512. state->base->sku_type = MXL_HYDRA_SKU_TYPE_581;
  1513. break;
  1514. case MXL_HYDRA_DEVICE_582:
  1515. state->base->can_clkout = 1;
  1516. state->base->demod_num = 8;
  1517. state->base->tuner_num = 3;
  1518. state->base->sku_type = MXL_HYDRA_SKU_TYPE_582;
  1519. break;
  1520. case MXL_HYDRA_DEVICE_585:
  1521. state->base->can_clkout = 0;
  1522. state->base->demod_num = 8;
  1523. state->base->tuner_num = 4;
  1524. state->base->sku_type = MXL_HYDRA_SKU_TYPE_585;
  1525. break;
  1526. case MXL_HYDRA_DEVICE_544:
  1527. state->base->can_clkout = 0;
  1528. state->base->demod_num = 4;
  1529. state->base->tuner_num = 4;
  1530. state->base->sku_type = MXL_HYDRA_SKU_TYPE_544;
  1531. state->base->ts_map = ts_map54x;
  1532. break;
  1533. case MXL_HYDRA_DEVICE_541:
  1534. case MXL_HYDRA_DEVICE_541S:
  1535. state->base->can_clkout = 0;
  1536. state->base->demod_num = 4;
  1537. state->base->tuner_num = 1;
  1538. state->base->sku_type = MXL_HYDRA_SKU_TYPE_541;
  1539. state->base->ts_map = ts_map54x;
  1540. break;
  1541. case MXL_HYDRA_DEVICE_561:
  1542. case MXL_HYDRA_DEVICE_561S:
  1543. state->base->can_clkout = 0;
  1544. state->base->demod_num = 6;
  1545. state->base->tuner_num = 1;
  1546. state->base->sku_type = MXL_HYDRA_SKU_TYPE_561;
  1547. break;
  1548. case MXL_HYDRA_DEVICE_568:
  1549. state->base->can_clkout = 0;
  1550. state->base->demod_num = 8;
  1551. state->base->tuner_num = 1;
  1552. state->base->chan_bond = 1;
  1553. state->base->sku_type = MXL_HYDRA_SKU_TYPE_568;
  1554. break;
  1555. case MXL_HYDRA_DEVICE_542:
  1556. state->base->can_clkout = 1;
  1557. state->base->demod_num = 4;
  1558. state->base->tuner_num = 3;
  1559. state->base->sku_type = MXL_HYDRA_SKU_TYPE_542;
  1560. state->base->ts_map = ts_map54x;
  1561. break;
  1562. case MXL_HYDRA_DEVICE_TEST:
  1563. case MXL_HYDRA_DEVICE_584:
  1564. default:
  1565. state->base->can_clkout = 0;
  1566. state->base->demod_num = 8;
  1567. state->base->tuner_num = 4;
  1568. state->base->sku_type = MXL_HYDRA_SKU_TYPE_584;
  1569. break;
  1570. }
  1571. status = validate_sku(state);
  1572. if (status)
  1573. return status;
  1574. update_by_mnemonic(state, 0x80030014, 9, 1, 1);
  1575. update_by_mnemonic(state, 0x8003003C, 12, 1, 1);
  1576. status = read_by_mnemonic(state, 0x80030000, 12, 4, &chipver);
  1577. if (status)
  1578. state->base->chipversion = 0;
  1579. else
  1580. state->base->chipversion = (chipver == 2) ? 2 : 1;
  1581. dev_info(state->i2cdev, "Hydra chip version %u\n",
  1582. state->base->chipversion);
  1583. cfg_dev_xtal(state, cfg->clk, cfg->cap, 0);
  1584. fw = firmware_is_alive(state);
  1585. if (!fw) {
  1586. status = load_fw(state, cfg);
  1587. if (status)
  1588. return status;
  1589. }
  1590. get_fwinfo(state);
  1591. config_mux(state);
  1592. mpeg_interface_cfg.enable = MXL_ENABLE;
  1593. mpeg_interface_cfg.lsb_or_msb_first = MXL_HYDRA_MPEG_SERIAL_MSB_1ST;
  1594. /* supports only (0-104&139)MHz */
  1595. if (cfg->ts_clk)
  1596. mpeg_interface_cfg.max_mpeg_clk_rate = cfg->ts_clk;
  1597. else
  1598. mpeg_interface_cfg.max_mpeg_clk_rate = 69; /* 139; */
  1599. mpeg_interface_cfg.mpeg_clk_phase = MXL_HYDRA_MPEG_CLK_PHASE_SHIFT_0_DEG;
  1600. mpeg_interface_cfg.mpeg_clk_pol = MXL_HYDRA_MPEG_CLK_IN_PHASE;
  1601. /* MXL_HYDRA_MPEG_CLK_GAPPED; */
  1602. mpeg_interface_cfg.mpeg_clk_type = MXL_HYDRA_MPEG_CLK_CONTINUOUS;
  1603. mpeg_interface_cfg.mpeg_error_indication =
  1604. MXL_HYDRA_MPEG_ERR_INDICATION_DISABLED;
  1605. mpeg_interface_cfg.mpeg_mode = MXL_HYDRA_MPEG_MODE_SERIAL_3_WIRE;
  1606. mpeg_interface_cfg.mpeg_sync_pol = MXL_HYDRA_MPEG_ACTIVE_HIGH;
  1607. mpeg_interface_cfg.mpeg_sync_pulse_width = MXL_HYDRA_MPEG_SYNC_WIDTH_BIT;
  1608. mpeg_interface_cfg.mpeg_valid_pol = MXL_HYDRA_MPEG_ACTIVE_HIGH;
  1609. for (j = 0; j < state->base->demod_num; j++) {
  1610. status = config_ts(state, (enum MXL_HYDRA_DEMOD_ID_E) j,
  1611. &mpeg_interface_cfg);
  1612. if (status)
  1613. return status;
  1614. }
  1615. set_drive_strength(state, 1);
  1616. return 0;
  1617. }
  1618. struct dvb_frontend *mxl5xx_attach(struct i2c_adapter *i2c,
  1619. struct mxl5xx_cfg *cfg, u32 demod, u32 tuner,
  1620. int (**fn_set_input)(struct dvb_frontend *, int))
  1621. {
  1622. struct mxl *state;
  1623. struct mxl_base *base;
  1624. state = kzalloc_obj(struct mxl);
  1625. if (!state)
  1626. return NULL;
  1627. state->demod = demod;
  1628. state->tuner = tuner;
  1629. state->tuner_in_use = 0xffffffff;
  1630. state->i2cdev = &i2c->dev;
  1631. base = match_base(i2c, cfg->adr);
  1632. if (base) {
  1633. base->count++;
  1634. if (base->count > base->demod_num)
  1635. goto fail;
  1636. state->base = base;
  1637. } else {
  1638. base = kzalloc_obj(struct mxl_base);
  1639. if (!base)
  1640. goto fail;
  1641. base->i2c = i2c;
  1642. base->adr = cfg->adr;
  1643. base->type = cfg->type;
  1644. base->count = 1;
  1645. mutex_init(&base->i2c_lock);
  1646. mutex_init(&base->status_lock);
  1647. mutex_init(&base->tune_lock);
  1648. INIT_LIST_HEAD(&base->mxls);
  1649. state->base = base;
  1650. if (probe(state, cfg) < 0) {
  1651. kfree(base);
  1652. goto fail;
  1653. }
  1654. list_add(&base->mxllist, &mxllist);
  1655. }
  1656. state->fe.ops = mxl_ops;
  1657. state->xbar[0] = 4;
  1658. state->xbar[1] = demod;
  1659. state->xbar[2] = 8;
  1660. state->fe.demodulator_priv = state;
  1661. *fn_set_input = set_input;
  1662. list_add(&state->mxl, &base->mxls);
  1663. return &state->fe;
  1664. fail:
  1665. kfree(state);
  1666. return NULL;
  1667. }
  1668. EXPORT_SYMBOL_GPL(mxl5xx_attach);
  1669. MODULE_DESCRIPTION("MaxLinear MxL5xx DVB-S/S2 tuner-demodulator driver");
  1670. MODULE_AUTHOR("Ralph and Marcus Metzler, Metzler Brothers Systementwicklung GbR");
  1671. MODULE_LICENSE("GPL v2");