xc4000.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  1. /*
  2. * Driver for Xceive XC4000 "QAM/8VSB single chip tuner"
  3. *
  4. * Copyright (c) 2007 Xceive Corporation
  5. * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
  6. * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
  7. * Copyright (c) 2009 Davide Ferri <d.ferri@zero11.it>
  8. * Copyright (c) 2010 Istvan Varga <istvan_v@mailbox.hu>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/videodev2.h>
  23. #include <linux/delay.h>
  24. #include <linux/dvb/frontend.h>
  25. #include <linux/i2c.h>
  26. #include <linux/mutex.h>
  27. #include <asm/unaligned.h>
  28. #include <media/dvb_frontend.h>
  29. #include "xc4000.h"
  30. #include "tuner-i2c.h"
  31. #include "tuner-xc2028-types.h"
  32. static int debug;
  33. module_param(debug, int, 0644);
  34. MODULE_PARM_DESC(debug, "Debugging level (0 to 2, default: 0 (off)).");
  35. static int no_poweroff;
  36. module_param(no_poweroff, int, 0644);
  37. MODULE_PARM_DESC(no_poweroff, "Power management (1: disabled, 2: enabled, 0 (default): use device-specific default mode).");
  38. static int audio_std;
  39. module_param(audio_std, int, 0644);
  40. MODULE_PARM_DESC(audio_std, "Audio standard. XC4000 audio decoder explicitly needs to know what audio standard is needed for some video standards with audio A2 or NICAM. The valid settings are a sum of:\n"
  41. " 1: use NICAM/B or A2/B instead of NICAM/A or A2/A\n"
  42. " 2: use A2 instead of NICAM or BTSC\n"
  43. " 4: use SECAM/K3 instead of K1\n"
  44. " 8: use PAL-D/K audio for SECAM-D/K\n"
  45. "16: use FM radio input 1 instead of input 2\n"
  46. "32: use mono audio (the lower three bits are ignored)");
  47. static char firmware_name[30];
  48. module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0);
  49. MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the default firmware name.");
  50. static DEFINE_MUTEX(xc4000_list_mutex);
  51. static LIST_HEAD(hybrid_tuner_instance_list);
  52. #define dprintk(level, fmt, arg...) if (debug >= level) \
  53. printk(KERN_INFO "%s: " fmt, "xc4000", ## arg)
  54. /* struct for storing firmware table */
  55. struct firmware_description {
  56. unsigned int type;
  57. v4l2_std_id id;
  58. __u16 int_freq;
  59. unsigned char *ptr;
  60. unsigned int size;
  61. };
  62. struct firmware_properties {
  63. unsigned int type;
  64. v4l2_std_id id;
  65. v4l2_std_id std_req;
  66. __u16 int_freq;
  67. unsigned int scode_table;
  68. int scode_nr;
  69. };
  70. struct xc4000_priv {
  71. struct tuner_i2c_props i2c_props;
  72. struct list_head hybrid_tuner_instance_list;
  73. struct firmware_description *firm;
  74. int firm_size;
  75. u32 if_khz;
  76. u32 freq_hz, freq_offset;
  77. u32 bandwidth;
  78. u8 video_standard;
  79. u8 rf_mode;
  80. u8 default_pm;
  81. u8 dvb_amplitude;
  82. u8 set_smoothedcvbs;
  83. u8 ignore_i2c_write_errors;
  84. __u16 firm_version;
  85. struct firmware_properties cur_fw;
  86. __u16 hwmodel;
  87. __u16 hwvers;
  88. struct mutex lock;
  89. };
  90. #define XC4000_AUDIO_STD_B 1
  91. #define XC4000_AUDIO_STD_A2 2
  92. #define XC4000_AUDIO_STD_K3 4
  93. #define XC4000_AUDIO_STD_L 8
  94. #define XC4000_AUDIO_STD_INPUT1 16
  95. #define XC4000_AUDIO_STD_MONO 32
  96. #define XC4000_DEFAULT_FIRMWARE "dvb-fe-xc4000-1.4.fw"
  97. #define XC4000_DEFAULT_FIRMWARE_NEW "dvb-fe-xc4000-1.4.1.fw"
  98. /* Misc Defines */
  99. #define MAX_TV_STANDARD 24
  100. #define XC_MAX_I2C_WRITE_LENGTH 64
  101. #define XC_POWERED_DOWN 0x80000000U
  102. /* Signal Types */
  103. #define XC_RF_MODE_AIR 0
  104. #define XC_RF_MODE_CABLE 1
  105. /* Product id */
  106. #define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
  107. #define XC_PRODUCT_ID_XC4000 0x0FA0
  108. #define XC_PRODUCT_ID_XC4100 0x1004
  109. /* Registers (Write-only) */
  110. #define XREG_INIT 0x00
  111. #define XREG_VIDEO_MODE 0x01
  112. #define XREG_AUDIO_MODE 0x02
  113. #define XREG_RF_FREQ 0x03
  114. #define XREG_D_CODE 0x04
  115. #define XREG_DIRECTSITTING_MODE 0x05
  116. #define XREG_SEEK_MODE 0x06
  117. #define XREG_POWER_DOWN 0x08
  118. #define XREG_SIGNALSOURCE 0x0A
  119. #define XREG_SMOOTHEDCVBS 0x0E
  120. #define XREG_AMPLITUDE 0x10
  121. /* Registers (Read-only) */
  122. #define XREG_ADC_ENV 0x00
  123. #define XREG_QUALITY 0x01
  124. #define XREG_FRAME_LINES 0x02
  125. #define XREG_HSYNC_FREQ 0x03
  126. #define XREG_LOCK 0x04
  127. #define XREG_FREQ_ERROR 0x05
  128. #define XREG_SNR 0x06
  129. #define XREG_VERSION 0x07
  130. #define XREG_PRODUCT_ID 0x08
  131. #define XREG_SIGNAL_LEVEL 0x0A
  132. #define XREG_NOISE_LEVEL 0x0B
  133. /*
  134. Basic firmware description. This will remain with
  135. the driver for documentation purposes.
  136. This represents an I2C firmware file encoded as a
  137. string of unsigned char. Format is as follows:
  138. char[0 ]=len0_MSB -> len = len_MSB * 256 + len_LSB
  139. char[1 ]=len0_LSB -> length of first write transaction
  140. char[2 ]=data0 -> first byte to be sent
  141. char[3 ]=data1
  142. char[4 ]=data2
  143. char[ ]=...
  144. char[M ]=dataN -> last byte to be sent
  145. char[M+1]=len1_MSB -> len = len_MSB * 256 + len_LSB
  146. char[M+2]=len1_LSB -> length of second write transaction
  147. char[M+3]=data0
  148. char[M+4]=data1
  149. ...
  150. etc.
  151. The [len] value should be interpreted as follows:
  152. len= len_MSB _ len_LSB
  153. len=1111_1111_1111_1111 : End of I2C_SEQUENCE
  154. len=0000_0000_0000_0000 : Reset command: Do hardware reset
  155. len=0NNN_NNNN_NNNN_NNNN : Normal transaction: number of bytes = {1:32767)
  156. len=1WWW_WWWW_WWWW_WWWW : Wait command: wait for {1:32767} ms
  157. For the RESET and WAIT commands, the two following bytes will contain
  158. immediately the length of the following transaction.
  159. */
  160. struct XC_TV_STANDARD {
  161. const char *Name;
  162. u16 audio_mode;
  163. u16 video_mode;
  164. u16 int_freq;
  165. };
  166. /* Tuner standards */
  167. #define XC4000_MN_NTSC_PAL_BTSC 0
  168. #define XC4000_MN_NTSC_PAL_A2 1
  169. #define XC4000_MN_NTSC_PAL_EIAJ 2
  170. #define XC4000_MN_NTSC_PAL_Mono 3
  171. #define XC4000_BG_PAL_A2 4
  172. #define XC4000_BG_PAL_NICAM 5
  173. #define XC4000_BG_PAL_MONO 6
  174. #define XC4000_I_PAL_NICAM 7
  175. #define XC4000_I_PAL_NICAM_MONO 8
  176. #define XC4000_DK_PAL_A2 9
  177. #define XC4000_DK_PAL_NICAM 10
  178. #define XC4000_DK_PAL_MONO 11
  179. #define XC4000_DK_SECAM_A2DK1 12
  180. #define XC4000_DK_SECAM_A2LDK3 13
  181. #define XC4000_DK_SECAM_A2MONO 14
  182. #define XC4000_DK_SECAM_NICAM 15
  183. #define XC4000_L_SECAM_NICAM 16
  184. #define XC4000_LC_SECAM_NICAM 17
  185. #define XC4000_DTV6 18
  186. #define XC4000_DTV8 19
  187. #define XC4000_DTV7_8 20
  188. #define XC4000_DTV7 21
  189. #define XC4000_FM_Radio_INPUT2 22
  190. #define XC4000_FM_Radio_INPUT1 23
  191. static struct XC_TV_STANDARD xc4000_standard[MAX_TV_STANDARD] = {
  192. {"M/N-NTSC/PAL-BTSC", 0x0000, 0x80A0, 4500},
  193. {"M/N-NTSC/PAL-A2", 0x0000, 0x80A0, 4600},
  194. {"M/N-NTSC/PAL-EIAJ", 0x0040, 0x80A0, 4500},
  195. {"M/N-NTSC/PAL-Mono", 0x0078, 0x80A0, 4500},
  196. {"B/G-PAL-A2", 0x0000, 0x8159, 5640},
  197. {"B/G-PAL-NICAM", 0x0004, 0x8159, 5740},
  198. {"B/G-PAL-MONO", 0x0078, 0x8159, 5500},
  199. {"I-PAL-NICAM", 0x0080, 0x8049, 6240},
  200. {"I-PAL-NICAM-MONO", 0x0078, 0x8049, 6000},
  201. {"D/K-PAL-A2", 0x0000, 0x8049, 6380},
  202. {"D/K-PAL-NICAM", 0x0080, 0x8049, 6200},
  203. {"D/K-PAL-MONO", 0x0078, 0x8049, 6500},
  204. {"D/K-SECAM-A2 DK1", 0x0000, 0x8049, 6340},
  205. {"D/K-SECAM-A2 L/DK3", 0x0000, 0x8049, 6000},
  206. {"D/K-SECAM-A2 MONO", 0x0078, 0x8049, 6500},
  207. {"D/K-SECAM-NICAM", 0x0080, 0x8049, 6200},
  208. {"L-SECAM-NICAM", 0x8080, 0x0009, 6200},
  209. {"L'-SECAM-NICAM", 0x8080, 0x4009, 6200},
  210. {"DTV6", 0x00C0, 0x8002, 0},
  211. {"DTV8", 0x00C0, 0x800B, 0},
  212. {"DTV7/8", 0x00C0, 0x801B, 0},
  213. {"DTV7", 0x00C0, 0x8007, 0},
  214. {"FM Radio-INPUT2", 0x0008, 0x9800, 10700},
  215. {"FM Radio-INPUT1", 0x0008, 0x9000, 10700}
  216. };
  217. static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val);
  218. static int xc4000_tuner_reset(struct dvb_frontend *fe);
  219. static void xc_debug_dump(struct xc4000_priv *priv);
  220. static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
  221. {
  222. struct i2c_msg msg = { .addr = priv->i2c_props.addr,
  223. .flags = 0, .buf = buf, .len = len };
  224. if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
  225. if (priv->ignore_i2c_write_errors == 0) {
  226. printk(KERN_ERR "xc4000: I2C write failed (len=%i)\n",
  227. len);
  228. if (len == 4) {
  229. printk(KERN_ERR "bytes %*ph\n", 4, buf);
  230. }
  231. return -EREMOTEIO;
  232. }
  233. }
  234. return 0;
  235. }
  236. static int xc4000_tuner_reset(struct dvb_frontend *fe)
  237. {
  238. struct xc4000_priv *priv = fe->tuner_priv;
  239. int ret;
  240. dprintk(1, "%s()\n", __func__);
  241. if (fe->callback) {
  242. ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
  243. fe->dvb->priv :
  244. priv->i2c_props.adap->algo_data,
  245. DVB_FRONTEND_COMPONENT_TUNER,
  246. XC4000_TUNER_RESET, 0);
  247. if (ret) {
  248. printk(KERN_ERR "xc4000: reset failed\n");
  249. return -EREMOTEIO;
  250. }
  251. } else {
  252. printk(KERN_ERR "xc4000: no tuner reset callback function, fatal\n");
  253. return -EINVAL;
  254. }
  255. return 0;
  256. }
  257. static int xc_write_reg(struct xc4000_priv *priv, u16 regAddr, u16 i2cData)
  258. {
  259. u8 buf[4];
  260. int result;
  261. buf[0] = (regAddr >> 8) & 0xFF;
  262. buf[1] = regAddr & 0xFF;
  263. buf[2] = (i2cData >> 8) & 0xFF;
  264. buf[3] = i2cData & 0xFF;
  265. result = xc_send_i2c_data(priv, buf, 4);
  266. return result;
  267. }
  268. static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
  269. {
  270. struct xc4000_priv *priv = fe->tuner_priv;
  271. int i, nbytes_to_send, result;
  272. unsigned int len, pos, index;
  273. u8 buf[XC_MAX_I2C_WRITE_LENGTH];
  274. index = 0;
  275. while ((i2c_sequence[index] != 0xFF) ||
  276. (i2c_sequence[index + 1] != 0xFF)) {
  277. len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
  278. if (len == 0x0000) {
  279. /* RESET command */
  280. /* NOTE: this is ignored, as the reset callback was */
  281. /* already called by check_firmware() */
  282. index += 2;
  283. } else if (len & 0x8000) {
  284. /* WAIT command */
  285. msleep(len & 0x7FFF);
  286. index += 2;
  287. } else {
  288. /* Send i2c data whilst ensuring individual transactions
  289. * do not exceed XC_MAX_I2C_WRITE_LENGTH bytes.
  290. */
  291. index += 2;
  292. buf[0] = i2c_sequence[index];
  293. buf[1] = i2c_sequence[index + 1];
  294. pos = 2;
  295. while (pos < len) {
  296. if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2)
  297. nbytes_to_send =
  298. XC_MAX_I2C_WRITE_LENGTH;
  299. else
  300. nbytes_to_send = (len - pos + 2);
  301. for (i = 2; i < nbytes_to_send; i++) {
  302. buf[i] = i2c_sequence[index + pos +
  303. i - 2];
  304. }
  305. result = xc_send_i2c_data(priv, buf,
  306. nbytes_to_send);
  307. if (result != 0)
  308. return result;
  309. pos += nbytes_to_send - 2;
  310. }
  311. index += len;
  312. }
  313. }
  314. return 0;
  315. }
  316. static int xc_set_tv_standard(struct xc4000_priv *priv,
  317. u16 video_mode, u16 audio_mode)
  318. {
  319. int ret;
  320. dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode);
  321. dprintk(1, "%s() Standard = %s\n",
  322. __func__,
  323. xc4000_standard[priv->video_standard].Name);
  324. /* Don't complain when the request fails because of i2c stretching */
  325. priv->ignore_i2c_write_errors = 1;
  326. ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode);
  327. if (ret == 0)
  328. ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode);
  329. priv->ignore_i2c_write_errors = 0;
  330. return ret;
  331. }
  332. static int xc_set_signal_source(struct xc4000_priv *priv, u16 rf_mode)
  333. {
  334. dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
  335. rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
  336. if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) {
  337. rf_mode = XC_RF_MODE_CABLE;
  338. printk(KERN_ERR
  339. "%s(), Invalid mode, defaulting to CABLE",
  340. __func__);
  341. }
  342. return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
  343. }
  344. static const struct dvb_tuner_ops xc4000_tuner_ops;
  345. static int xc_set_rf_frequency(struct xc4000_priv *priv, u32 freq_hz)
  346. {
  347. u16 freq_code;
  348. dprintk(1, "%s(%u)\n", __func__, freq_hz);
  349. if ((freq_hz > xc4000_tuner_ops.info.frequency_max_hz) ||
  350. (freq_hz < xc4000_tuner_ops.info.frequency_min_hz))
  351. return -EINVAL;
  352. freq_code = (u16)(freq_hz / 15625);
  353. /* WAS: Starting in firmware version 1.1.44, Xceive recommends using the
  354. FINERFREQ for all normal tuning (the doc indicates reg 0x03 should
  355. only be used for fast scanning for channel lock) */
  356. /* WAS: XREG_FINERFREQ */
  357. return xc_write_reg(priv, XREG_RF_FREQ, freq_code);
  358. }
  359. static int xc_get_adc_envelope(struct xc4000_priv *priv, u16 *adc_envelope)
  360. {
  361. return xc4000_readreg(priv, XREG_ADC_ENV, adc_envelope);
  362. }
  363. static int xc_get_frequency_error(struct xc4000_priv *priv, u32 *freq_error_hz)
  364. {
  365. int result;
  366. u16 regData;
  367. u32 tmp;
  368. result = xc4000_readreg(priv, XREG_FREQ_ERROR, &regData);
  369. if (result != 0)
  370. return result;
  371. tmp = (u32)regData & 0xFFFFU;
  372. tmp = (tmp < 0x8000U ? tmp : 0x10000U - tmp);
  373. (*freq_error_hz) = tmp * 15625;
  374. return result;
  375. }
  376. static int xc_get_lock_status(struct xc4000_priv *priv, u16 *lock_status)
  377. {
  378. return xc4000_readreg(priv, XREG_LOCK, lock_status);
  379. }
  380. static int xc_get_version(struct xc4000_priv *priv,
  381. u8 *hw_majorversion, u8 *hw_minorversion,
  382. u8 *fw_majorversion, u8 *fw_minorversion)
  383. {
  384. u16 data;
  385. int result;
  386. result = xc4000_readreg(priv, XREG_VERSION, &data);
  387. if (result != 0)
  388. return result;
  389. (*hw_majorversion) = (data >> 12) & 0x0F;
  390. (*hw_minorversion) = (data >> 8) & 0x0F;
  391. (*fw_majorversion) = (data >> 4) & 0x0F;
  392. (*fw_minorversion) = data & 0x0F;
  393. return 0;
  394. }
  395. static int xc_get_hsync_freq(struct xc4000_priv *priv, u32 *hsync_freq_hz)
  396. {
  397. u16 regData;
  398. int result;
  399. result = xc4000_readreg(priv, XREG_HSYNC_FREQ, &regData);
  400. if (result != 0)
  401. return result;
  402. (*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
  403. return result;
  404. }
  405. static int xc_get_frame_lines(struct xc4000_priv *priv, u16 *frame_lines)
  406. {
  407. return xc4000_readreg(priv, XREG_FRAME_LINES, frame_lines);
  408. }
  409. static int xc_get_quality(struct xc4000_priv *priv, u16 *quality)
  410. {
  411. return xc4000_readreg(priv, XREG_QUALITY, quality);
  412. }
  413. static int xc_get_signal_level(struct xc4000_priv *priv, u16 *signal)
  414. {
  415. return xc4000_readreg(priv, XREG_SIGNAL_LEVEL, signal);
  416. }
  417. static int xc_get_noise_level(struct xc4000_priv *priv, u16 *noise)
  418. {
  419. return xc4000_readreg(priv, XREG_NOISE_LEVEL, noise);
  420. }
  421. static u16 xc_wait_for_lock(struct xc4000_priv *priv)
  422. {
  423. u16 lock_state = 0;
  424. int watchdog_count = 40;
  425. while ((lock_state == 0) && (watchdog_count > 0)) {
  426. xc_get_lock_status(priv, &lock_state);
  427. if (lock_state != 1) {
  428. msleep(5);
  429. watchdog_count--;
  430. }
  431. }
  432. return lock_state;
  433. }
  434. static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz)
  435. {
  436. int found = 1;
  437. int result;
  438. dprintk(1, "%s(%u)\n", __func__, freq_hz);
  439. /* Don't complain when the request fails because of i2c stretching */
  440. priv->ignore_i2c_write_errors = 1;
  441. result = xc_set_rf_frequency(priv, freq_hz);
  442. priv->ignore_i2c_write_errors = 0;
  443. if (result != 0)
  444. return 0;
  445. /* wait for lock only in analog TV mode */
  446. if ((priv->cur_fw.type & (FM | DTV6 | DTV7 | DTV78 | DTV8)) == 0) {
  447. if (xc_wait_for_lock(priv) != 1)
  448. found = 0;
  449. }
  450. /* Wait for stats to stabilize.
  451. * Frame Lines needs two frame times after initial lock
  452. * before it is valid.
  453. */
  454. msleep(debug ? 100 : 10);
  455. if (debug)
  456. xc_debug_dump(priv);
  457. return found;
  458. }
  459. static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val)
  460. {
  461. u8 buf[2] = { reg >> 8, reg & 0xff };
  462. u8 bval[2] = { 0, 0 };
  463. struct i2c_msg msg[2] = {
  464. { .addr = priv->i2c_props.addr,
  465. .flags = 0, .buf = &buf[0], .len = 2 },
  466. { .addr = priv->i2c_props.addr,
  467. .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
  468. };
  469. if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
  470. printk(KERN_ERR "xc4000: I2C read failed\n");
  471. return -EREMOTEIO;
  472. }
  473. *val = (bval[0] << 8) | bval[1];
  474. return 0;
  475. }
  476. #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
  477. static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq)
  478. {
  479. if (type & BASE)
  480. printk(KERN_CONT "BASE ");
  481. if (type & INIT1)
  482. printk(KERN_CONT "INIT1 ");
  483. if (type & F8MHZ)
  484. printk(KERN_CONT "F8MHZ ");
  485. if (type & MTS)
  486. printk(KERN_CONT "MTS ");
  487. if (type & D2620)
  488. printk(KERN_CONT "D2620 ");
  489. if (type & D2633)
  490. printk(KERN_CONT "D2633 ");
  491. if (type & DTV6)
  492. printk(KERN_CONT "DTV6 ");
  493. if (type & QAM)
  494. printk(KERN_CONT "QAM ");
  495. if (type & DTV7)
  496. printk(KERN_CONT "DTV7 ");
  497. if (type & DTV78)
  498. printk(KERN_CONT "DTV78 ");
  499. if (type & DTV8)
  500. printk(KERN_CONT "DTV8 ");
  501. if (type & FM)
  502. printk(KERN_CONT "FM ");
  503. if (type & INPUT1)
  504. printk(KERN_CONT "INPUT1 ");
  505. if (type & LCD)
  506. printk(KERN_CONT "LCD ");
  507. if (type & NOGD)
  508. printk(KERN_CONT "NOGD ");
  509. if (type & MONO)
  510. printk(KERN_CONT "MONO ");
  511. if (type & ATSC)
  512. printk(KERN_CONT "ATSC ");
  513. if (type & IF)
  514. printk(KERN_CONT "IF ");
  515. if (type & LG60)
  516. printk(KERN_CONT "LG60 ");
  517. if (type & ATI638)
  518. printk(KERN_CONT "ATI638 ");
  519. if (type & OREN538)
  520. printk(KERN_CONT "OREN538 ");
  521. if (type & OREN36)
  522. printk(KERN_CONT "OREN36 ");
  523. if (type & TOYOTA388)
  524. printk(KERN_CONT "TOYOTA388 ");
  525. if (type & TOYOTA794)
  526. printk(KERN_CONT "TOYOTA794 ");
  527. if (type & DIBCOM52)
  528. printk(KERN_CONT "DIBCOM52 ");
  529. if (type & ZARLINK456)
  530. printk(KERN_CONT "ZARLINK456 ");
  531. if (type & CHINA)
  532. printk(KERN_CONT "CHINA ");
  533. if (type & F6MHZ)
  534. printk(KERN_CONT "F6MHZ ");
  535. if (type & INPUT2)
  536. printk(KERN_CONT "INPUT2 ");
  537. if (type & SCODE)
  538. printk(KERN_CONT "SCODE ");
  539. if (type & HAS_IF)
  540. printk(KERN_CONT "HAS_IF_%d ", int_freq);
  541. }
  542. static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
  543. v4l2_std_id *id)
  544. {
  545. struct xc4000_priv *priv = fe->tuner_priv;
  546. int i, best_i = -1;
  547. unsigned int best_nr_diffs = 255U;
  548. if (!priv->firm) {
  549. printk(KERN_ERR "Error! firmware not loaded\n");
  550. return -EINVAL;
  551. }
  552. if (((type & ~SCODE) == 0) && (*id == 0))
  553. *id = V4L2_STD_PAL;
  554. /* Seek for generic video standard match */
  555. for (i = 0; i < priv->firm_size; i++) {
  556. v4l2_std_id id_diff_mask =
  557. (priv->firm[i].id ^ (*id)) & (*id);
  558. unsigned int type_diff_mask =
  559. (priv->firm[i].type ^ type)
  560. & (BASE_TYPES | DTV_TYPES | LCD | NOGD | MONO | SCODE);
  561. unsigned int nr_diffs;
  562. if (type_diff_mask
  563. & (BASE | INIT1 | FM | DTV6 | DTV7 | DTV78 | DTV8 | SCODE))
  564. continue;
  565. nr_diffs = hweight64(id_diff_mask) + hweight32(type_diff_mask);
  566. if (!nr_diffs) /* Supports all the requested standards */
  567. goto found;
  568. if (nr_diffs < best_nr_diffs) {
  569. best_nr_diffs = nr_diffs;
  570. best_i = i;
  571. }
  572. }
  573. /* FIXME: Would make sense to seek for type "hint" match ? */
  574. if (best_i < 0) {
  575. i = -ENOENT;
  576. goto ret;
  577. }
  578. if (best_nr_diffs > 0U) {
  579. printk(KERN_WARNING
  580. "Selecting best matching firmware (%u bits differ) for type=(%x), id %016llx:\n",
  581. best_nr_diffs, type, (unsigned long long)*id);
  582. i = best_i;
  583. }
  584. found:
  585. *id = priv->firm[i].id;
  586. ret:
  587. if (debug) {
  588. printk(KERN_DEBUG "%s firmware for type=",
  589. (i < 0) ? "Can't find" : "Found");
  590. dump_firm_type(type);
  591. printk(KERN_DEBUG "(%x), id %016llx.\n", type, (unsigned long long)*id);
  592. }
  593. return i;
  594. }
  595. static int load_firmware(struct dvb_frontend *fe, unsigned int type,
  596. v4l2_std_id *id)
  597. {
  598. struct xc4000_priv *priv = fe->tuner_priv;
  599. int pos, rc;
  600. unsigned char *p;
  601. pos = seek_firmware(fe, type, id);
  602. if (pos < 0)
  603. return pos;
  604. p = priv->firm[pos].ptr;
  605. /* Don't complain when the request fails because of i2c stretching */
  606. priv->ignore_i2c_write_errors = 1;
  607. rc = xc_load_i2c_sequence(fe, p);
  608. priv->ignore_i2c_write_errors = 0;
  609. return rc;
  610. }
  611. static int xc4000_fwupload(struct dvb_frontend *fe)
  612. {
  613. struct xc4000_priv *priv = fe->tuner_priv;
  614. const struct firmware *fw = NULL;
  615. const unsigned char *p, *endp;
  616. int rc = 0;
  617. int n, n_array;
  618. char name[33];
  619. const char *fname;
  620. if (firmware_name[0] != '\0') {
  621. fname = firmware_name;
  622. dprintk(1, "Reading custom firmware %s\n", fname);
  623. rc = request_firmware(&fw, fname,
  624. priv->i2c_props.adap->dev.parent);
  625. } else {
  626. fname = XC4000_DEFAULT_FIRMWARE_NEW;
  627. dprintk(1, "Trying to read firmware %s\n", fname);
  628. rc = request_firmware(&fw, fname,
  629. priv->i2c_props.adap->dev.parent);
  630. if (rc == -ENOENT) {
  631. fname = XC4000_DEFAULT_FIRMWARE;
  632. dprintk(1, "Trying to read firmware %s\n", fname);
  633. rc = request_firmware(&fw, fname,
  634. priv->i2c_props.adap->dev.parent);
  635. }
  636. }
  637. if (rc < 0) {
  638. if (rc == -ENOENT)
  639. printk(KERN_ERR "Error: firmware %s not found.\n", fname);
  640. else
  641. printk(KERN_ERR "Error %d while requesting firmware %s\n",
  642. rc, fname);
  643. return rc;
  644. }
  645. dprintk(1, "Loading Firmware: %s\n", fname);
  646. p = fw->data;
  647. endp = p + fw->size;
  648. if (fw->size < sizeof(name) - 1 + 2 + 2) {
  649. printk(KERN_ERR "Error: firmware file %s has invalid size!\n",
  650. fname);
  651. goto corrupt;
  652. }
  653. memcpy(name, p, sizeof(name) - 1);
  654. name[sizeof(name) - 1] = '\0';
  655. p += sizeof(name) - 1;
  656. priv->firm_version = get_unaligned_le16(p);
  657. p += 2;
  658. n_array = get_unaligned_le16(p);
  659. p += 2;
  660. dprintk(1, "Loading %d firmware images from %s, type: %s, ver %d.%d\n",
  661. n_array, fname, name,
  662. priv->firm_version >> 8, priv->firm_version & 0xff);
  663. priv->firm = kcalloc(n_array, sizeof(*priv->firm), GFP_KERNEL);
  664. if (priv->firm == NULL) {
  665. printk(KERN_ERR "Not enough memory to load firmware file.\n");
  666. rc = -ENOMEM;
  667. goto done;
  668. }
  669. priv->firm_size = n_array;
  670. n = -1;
  671. while (p < endp) {
  672. __u32 type, size;
  673. v4l2_std_id id;
  674. __u16 int_freq = 0;
  675. n++;
  676. if (n >= n_array) {
  677. printk(KERN_ERR "More firmware images in file than were expected!\n");
  678. goto corrupt;
  679. }
  680. /* Checks if there's enough bytes to read */
  681. if (endp - p < sizeof(type) + sizeof(id) + sizeof(size))
  682. goto header;
  683. type = get_unaligned_le32(p);
  684. p += sizeof(type);
  685. id = get_unaligned_le64(p);
  686. p += sizeof(id);
  687. if (type & HAS_IF) {
  688. int_freq = get_unaligned_le16(p);
  689. p += sizeof(int_freq);
  690. if (endp - p < sizeof(size))
  691. goto header;
  692. }
  693. size = get_unaligned_le32(p);
  694. p += sizeof(size);
  695. if (!size || size > endp - p) {
  696. printk(KERN_ERR "Firmware type (%x), id %llx is corrupted (size=%zd, expected %d)\n",
  697. type, (unsigned long long)id,
  698. endp - p, size);
  699. goto corrupt;
  700. }
  701. priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
  702. if (priv->firm[n].ptr == NULL) {
  703. printk(KERN_ERR "Not enough memory to load firmware file.\n");
  704. rc = -ENOMEM;
  705. goto done;
  706. }
  707. if (debug) {
  708. printk(KERN_DEBUG "Reading firmware type ");
  709. dump_firm_type_and_int_freq(type, int_freq);
  710. printk(KERN_DEBUG "(%x), id %llx, size=%d.\n",
  711. type, (unsigned long long)id, size);
  712. }
  713. memcpy(priv->firm[n].ptr, p, size);
  714. priv->firm[n].type = type;
  715. priv->firm[n].id = id;
  716. priv->firm[n].size = size;
  717. priv->firm[n].int_freq = int_freq;
  718. p += size;
  719. }
  720. if (n + 1 != priv->firm_size) {
  721. printk(KERN_ERR "Firmware file is incomplete!\n");
  722. goto corrupt;
  723. }
  724. goto done;
  725. header:
  726. printk(KERN_ERR "Firmware header is incomplete!\n");
  727. corrupt:
  728. rc = -EINVAL;
  729. printk(KERN_ERR "Error: firmware file is corrupted!\n");
  730. done:
  731. release_firmware(fw);
  732. if (rc == 0)
  733. dprintk(1, "Firmware files loaded.\n");
  734. return rc;
  735. }
  736. static int load_scode(struct dvb_frontend *fe, unsigned int type,
  737. v4l2_std_id *id, __u16 int_freq, int scode)
  738. {
  739. struct xc4000_priv *priv = fe->tuner_priv;
  740. int pos, rc;
  741. unsigned char *p;
  742. u8 scode_buf[13];
  743. u8 indirect_mode[5];
  744. dprintk(1, "%s called int_freq=%d\n", __func__, int_freq);
  745. if (!int_freq) {
  746. pos = seek_firmware(fe, type, id);
  747. if (pos < 0)
  748. return pos;
  749. } else {
  750. for (pos = 0; pos < priv->firm_size; pos++) {
  751. if ((priv->firm[pos].int_freq == int_freq) &&
  752. (priv->firm[pos].type & HAS_IF))
  753. break;
  754. }
  755. if (pos == priv->firm_size)
  756. return -ENOENT;
  757. }
  758. p = priv->firm[pos].ptr;
  759. if (priv->firm[pos].size != 12 * 16 || scode >= 16)
  760. return -EINVAL;
  761. p += 12 * scode;
  762. if (debug) {
  763. tuner_info("Loading SCODE for type=");
  764. dump_firm_type_and_int_freq(priv->firm[pos].type,
  765. priv->firm[pos].int_freq);
  766. printk(KERN_CONT "(%x), id %016llx.\n", priv->firm[pos].type,
  767. (unsigned long long)*id);
  768. }
  769. scode_buf[0] = 0x00;
  770. memcpy(&scode_buf[1], p, 12);
  771. /* Enter direct-mode */
  772. rc = xc_write_reg(priv, XREG_DIRECTSITTING_MODE, 0);
  773. if (rc < 0) {
  774. printk(KERN_ERR "failed to put device into direct mode!\n");
  775. return -EIO;
  776. }
  777. rc = xc_send_i2c_data(priv, scode_buf, 13);
  778. if (rc != 0) {
  779. /* Even if the send failed, make sure we set back to indirect
  780. mode */
  781. printk(KERN_ERR "Failed to set scode %d\n", rc);
  782. }
  783. /* Switch back to indirect-mode */
  784. memset(indirect_mode, 0, sizeof(indirect_mode));
  785. indirect_mode[4] = 0x88;
  786. xc_send_i2c_data(priv, indirect_mode, sizeof(indirect_mode));
  787. msleep(10);
  788. return 0;
  789. }
  790. static int check_firmware(struct dvb_frontend *fe, unsigned int type,
  791. v4l2_std_id std, __u16 int_freq)
  792. {
  793. struct xc4000_priv *priv = fe->tuner_priv;
  794. struct firmware_properties new_fw;
  795. int rc = 0, is_retry = 0;
  796. u16 hwmodel;
  797. v4l2_std_id std0;
  798. u8 hw_major = 0, hw_minor = 0, fw_major = 0, fw_minor = 0;
  799. dprintk(1, "%s called\n", __func__);
  800. if (!priv->firm) {
  801. rc = xc4000_fwupload(fe);
  802. if (rc < 0)
  803. return rc;
  804. }
  805. retry:
  806. new_fw.type = type;
  807. new_fw.id = std;
  808. new_fw.std_req = std;
  809. new_fw.scode_table = SCODE;
  810. new_fw.scode_nr = 0;
  811. new_fw.int_freq = int_freq;
  812. dprintk(1, "checking firmware, user requested type=");
  813. if (debug) {
  814. dump_firm_type(new_fw.type);
  815. printk(KERN_CONT "(%x), id %016llx, ", new_fw.type,
  816. (unsigned long long)new_fw.std_req);
  817. if (!int_freq)
  818. printk(KERN_CONT "scode_tbl ");
  819. else
  820. printk(KERN_CONT "int_freq %d, ", new_fw.int_freq);
  821. printk(KERN_CONT "scode_nr %d\n", new_fw.scode_nr);
  822. }
  823. /* No need to reload base firmware if it matches */
  824. if (priv->cur_fw.type & BASE) {
  825. dprintk(1, "BASE firmware not changed.\n");
  826. goto skip_base;
  827. }
  828. /* Updating BASE - forget about all currently loaded firmware */
  829. memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
  830. /* Reset is needed before loading firmware */
  831. rc = xc4000_tuner_reset(fe);
  832. if (rc < 0)
  833. goto fail;
  834. /* BASE firmwares are all std0 */
  835. std0 = 0;
  836. rc = load_firmware(fe, BASE, &std0);
  837. if (rc < 0) {
  838. printk(KERN_ERR "Error %d while loading base firmware\n", rc);
  839. goto fail;
  840. }
  841. /* Load INIT1, if needed */
  842. dprintk(1, "Load init1 firmware, if exists\n");
  843. rc = load_firmware(fe, BASE | INIT1, &std0);
  844. if (rc == -ENOENT)
  845. rc = load_firmware(fe, BASE | INIT1, &std0);
  846. if (rc < 0 && rc != -ENOENT) {
  847. tuner_err("Error %d while loading init1 firmware\n",
  848. rc);
  849. goto fail;
  850. }
  851. skip_base:
  852. /*
  853. * No need to reload standard specific firmware if base firmware
  854. * was not reloaded and requested video standards have not changed.
  855. */
  856. if (priv->cur_fw.type == (BASE | new_fw.type) &&
  857. priv->cur_fw.std_req == std) {
  858. dprintk(1, "Std-specific firmware already loaded.\n");
  859. goto skip_std_specific;
  860. }
  861. /* Reloading std-specific firmware forces a SCODE update */
  862. priv->cur_fw.scode_table = 0;
  863. /* Load the standard firmware */
  864. rc = load_firmware(fe, new_fw.type, &new_fw.id);
  865. if (rc < 0)
  866. goto fail;
  867. skip_std_specific:
  868. if (priv->cur_fw.scode_table == new_fw.scode_table &&
  869. priv->cur_fw.scode_nr == new_fw.scode_nr) {
  870. dprintk(1, "SCODE firmware already loaded.\n");
  871. goto check_device;
  872. }
  873. /* Load SCODE firmware, if exists */
  874. rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
  875. new_fw.int_freq, new_fw.scode_nr);
  876. if (rc != 0)
  877. dprintk(1, "load scode failed %d\n", rc);
  878. check_device:
  879. if (xc4000_readreg(priv, XREG_PRODUCT_ID, &hwmodel) < 0) {
  880. printk(KERN_ERR "Unable to read tuner registers.\n");
  881. goto fail;
  882. }
  883. if (xc_get_version(priv, &hw_major, &hw_minor, &fw_major,
  884. &fw_minor) != 0) {
  885. printk(KERN_ERR "Unable to read tuner registers.\n");
  886. goto fail;
  887. }
  888. dprintk(1, "Device is Xceive %d version %d.%d, firmware version %d.%d\n",
  889. hwmodel, hw_major, hw_minor, fw_major, fw_minor);
  890. /* Check firmware version against what we downloaded. */
  891. if (priv->firm_version != ((fw_major << 8) | fw_minor)) {
  892. printk(KERN_WARNING
  893. "Incorrect readback of firmware version %d.%d.\n",
  894. fw_major, fw_minor);
  895. goto fail;
  896. }
  897. /* Check that the tuner hardware model remains consistent over time. */
  898. if (priv->hwmodel == 0 &&
  899. (hwmodel == XC_PRODUCT_ID_XC4000 ||
  900. hwmodel == XC_PRODUCT_ID_XC4100)) {
  901. priv->hwmodel = hwmodel;
  902. priv->hwvers = (hw_major << 8) | hw_minor;
  903. } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel ||
  904. priv->hwvers != ((hw_major << 8) | hw_minor)) {
  905. printk(KERN_WARNING
  906. "Read invalid device hardware information - tuner hung?\n");
  907. goto fail;
  908. }
  909. priv->cur_fw = new_fw;
  910. /*
  911. * By setting BASE in cur_fw.type only after successfully loading all
  912. * firmwares, we can:
  913. * 1. Identify that BASE firmware with type=0 has been loaded;
  914. * 2. Tell whether BASE firmware was just changed the next time through.
  915. */
  916. priv->cur_fw.type |= BASE;
  917. return 0;
  918. fail:
  919. memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
  920. if (!is_retry) {
  921. msleep(50);
  922. is_retry = 1;
  923. dprintk(1, "Retrying firmware load\n");
  924. goto retry;
  925. }
  926. if (rc == -ENOENT)
  927. rc = -EINVAL;
  928. return rc;
  929. }
  930. static void xc_debug_dump(struct xc4000_priv *priv)
  931. {
  932. u16 adc_envelope;
  933. u32 freq_error_hz = 0;
  934. u16 lock_status;
  935. u32 hsync_freq_hz = 0;
  936. u16 frame_lines;
  937. u16 quality;
  938. u16 signal = 0;
  939. u16 noise = 0;
  940. u8 hw_majorversion = 0, hw_minorversion = 0;
  941. u8 fw_majorversion = 0, fw_minorversion = 0;
  942. xc_get_adc_envelope(priv, &adc_envelope);
  943. dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
  944. xc_get_frequency_error(priv, &freq_error_hz);
  945. dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);
  946. xc_get_lock_status(priv, &lock_status);
  947. dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",
  948. lock_status);
  949. xc_get_version(priv, &hw_majorversion, &hw_minorversion,
  950. &fw_majorversion, &fw_minorversion);
  951. dprintk(1, "*** HW: V%02x.%02x, FW: V%02x.%02x\n",
  952. hw_majorversion, hw_minorversion,
  953. fw_majorversion, fw_minorversion);
  954. if (priv->video_standard < XC4000_DTV6) {
  955. xc_get_hsync_freq(priv, &hsync_freq_hz);
  956. dprintk(1, "*** Horizontal sync frequency = %d Hz\n",
  957. hsync_freq_hz);
  958. xc_get_frame_lines(priv, &frame_lines);
  959. dprintk(1, "*** Frame lines = %d\n", frame_lines);
  960. }
  961. xc_get_quality(priv, &quality);
  962. dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality);
  963. xc_get_signal_level(priv, &signal);
  964. dprintk(1, "*** Signal level = -%ddB (%d)\n", signal >> 8, signal);
  965. xc_get_noise_level(priv, &noise);
  966. dprintk(1, "*** Noise level = %ddB (%d)\n", noise >> 8, noise);
  967. }
  968. static int xc4000_set_params(struct dvb_frontend *fe)
  969. {
  970. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  971. u32 delsys = c->delivery_system;
  972. u32 bw = c->bandwidth_hz;
  973. struct xc4000_priv *priv = fe->tuner_priv;
  974. unsigned int type;
  975. int ret = -EREMOTEIO;
  976. dprintk(1, "%s() frequency=%d (Hz)\n", __func__, c->frequency);
  977. mutex_lock(&priv->lock);
  978. switch (delsys) {
  979. case SYS_ATSC:
  980. dprintk(1, "%s() VSB modulation\n", __func__);
  981. priv->rf_mode = XC_RF_MODE_AIR;
  982. priv->freq_offset = 1750000;
  983. priv->video_standard = XC4000_DTV6;
  984. type = DTV6;
  985. break;
  986. case SYS_DVBC_ANNEX_B:
  987. dprintk(1, "%s() QAM modulation\n", __func__);
  988. priv->rf_mode = XC_RF_MODE_CABLE;
  989. priv->freq_offset = 1750000;
  990. priv->video_standard = XC4000_DTV6;
  991. type = DTV6;
  992. break;
  993. case SYS_DVBT:
  994. case SYS_DVBT2:
  995. dprintk(1, "%s() OFDM\n", __func__);
  996. if (bw == 0) {
  997. if (c->frequency < 400000000) {
  998. priv->freq_offset = 2250000;
  999. } else {
  1000. priv->freq_offset = 2750000;
  1001. }
  1002. priv->video_standard = XC4000_DTV7_8;
  1003. type = DTV78;
  1004. } else if (bw <= 6000000) {
  1005. priv->video_standard = XC4000_DTV6;
  1006. priv->freq_offset = 1750000;
  1007. type = DTV6;
  1008. } else if (bw <= 7000000) {
  1009. priv->video_standard = XC4000_DTV7;
  1010. priv->freq_offset = 2250000;
  1011. type = DTV7;
  1012. } else {
  1013. priv->video_standard = XC4000_DTV8;
  1014. priv->freq_offset = 2750000;
  1015. type = DTV8;
  1016. }
  1017. priv->rf_mode = XC_RF_MODE_AIR;
  1018. break;
  1019. default:
  1020. printk(KERN_ERR "xc4000 delivery system not supported!\n");
  1021. ret = -EINVAL;
  1022. goto fail;
  1023. }
  1024. priv->freq_hz = c->frequency - priv->freq_offset;
  1025. dprintk(1, "%s() frequency=%d (compensated)\n",
  1026. __func__, priv->freq_hz);
  1027. /* Make sure the correct firmware type is loaded */
  1028. if (check_firmware(fe, type, 0, priv->if_khz) != 0)
  1029. goto fail;
  1030. priv->bandwidth = c->bandwidth_hz;
  1031. ret = xc_set_signal_source(priv, priv->rf_mode);
  1032. if (ret != 0) {
  1033. printk(KERN_ERR "xc4000: xc_set_signal_source(%d) failed\n",
  1034. priv->rf_mode);
  1035. goto fail;
  1036. } else {
  1037. u16 video_mode, audio_mode;
  1038. video_mode = xc4000_standard[priv->video_standard].video_mode;
  1039. audio_mode = xc4000_standard[priv->video_standard].audio_mode;
  1040. if (type == DTV6 && priv->firm_version != 0x0102)
  1041. video_mode |= 0x0001;
  1042. ret = xc_set_tv_standard(priv, video_mode, audio_mode);
  1043. if (ret != 0) {
  1044. printk(KERN_ERR "xc4000: xc_set_tv_standard failed\n");
  1045. /* DJH - do not return when it fails... */
  1046. /* goto fail; */
  1047. }
  1048. }
  1049. if (xc_write_reg(priv, XREG_D_CODE, 0) == 0)
  1050. ret = 0;
  1051. if (priv->dvb_amplitude != 0) {
  1052. if (xc_write_reg(priv, XREG_AMPLITUDE,
  1053. (priv->firm_version != 0x0102 ||
  1054. priv->dvb_amplitude != 134 ?
  1055. priv->dvb_amplitude : 132)) != 0)
  1056. ret = -EREMOTEIO;
  1057. }
  1058. if (priv->set_smoothedcvbs != 0) {
  1059. if (xc_write_reg(priv, XREG_SMOOTHEDCVBS, 1) != 0)
  1060. ret = -EREMOTEIO;
  1061. }
  1062. if (ret != 0) {
  1063. printk(KERN_ERR "xc4000: setting registers failed\n");
  1064. /* goto fail; */
  1065. }
  1066. xc_tune_channel(priv, priv->freq_hz);
  1067. ret = 0;
  1068. fail:
  1069. mutex_unlock(&priv->lock);
  1070. return ret;
  1071. }
  1072. static int xc4000_set_analog_params(struct dvb_frontend *fe,
  1073. struct analog_parameters *params)
  1074. {
  1075. struct xc4000_priv *priv = fe->tuner_priv;
  1076. unsigned int type = 0;
  1077. int ret = -EREMOTEIO;
  1078. if (params->mode == V4L2_TUNER_RADIO) {
  1079. dprintk(1, "%s() frequency=%d (in units of 62.5Hz)\n",
  1080. __func__, params->frequency);
  1081. mutex_lock(&priv->lock);
  1082. params->std = 0;
  1083. priv->freq_hz = params->frequency * 125L / 2;
  1084. if (audio_std & XC4000_AUDIO_STD_INPUT1) {
  1085. priv->video_standard = XC4000_FM_Radio_INPUT1;
  1086. type = FM | INPUT1;
  1087. } else {
  1088. priv->video_standard = XC4000_FM_Radio_INPUT2;
  1089. type = FM | INPUT2;
  1090. }
  1091. goto tune_channel;
  1092. }
  1093. dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
  1094. __func__, params->frequency);
  1095. mutex_lock(&priv->lock);
  1096. /* params->frequency is in units of 62.5khz */
  1097. priv->freq_hz = params->frequency * 62500;
  1098. params->std &= V4L2_STD_ALL;
  1099. /* if std is not defined, choose one */
  1100. if (!params->std)
  1101. params->std = V4L2_STD_PAL_BG;
  1102. if (audio_std & XC4000_AUDIO_STD_MONO)
  1103. type = MONO;
  1104. if (params->std & V4L2_STD_MN) {
  1105. params->std = V4L2_STD_MN;
  1106. if (audio_std & XC4000_AUDIO_STD_MONO) {
  1107. priv->video_standard = XC4000_MN_NTSC_PAL_Mono;
  1108. } else if (audio_std & XC4000_AUDIO_STD_A2) {
  1109. params->std |= V4L2_STD_A2;
  1110. priv->video_standard = XC4000_MN_NTSC_PAL_A2;
  1111. } else {
  1112. params->std |= V4L2_STD_BTSC;
  1113. priv->video_standard = XC4000_MN_NTSC_PAL_BTSC;
  1114. }
  1115. goto tune_channel;
  1116. }
  1117. if (params->std & V4L2_STD_PAL_BG) {
  1118. params->std = V4L2_STD_PAL_BG;
  1119. if (audio_std & XC4000_AUDIO_STD_MONO) {
  1120. priv->video_standard = XC4000_BG_PAL_MONO;
  1121. } else if (!(audio_std & XC4000_AUDIO_STD_A2)) {
  1122. if (!(audio_std & XC4000_AUDIO_STD_B)) {
  1123. params->std |= V4L2_STD_NICAM_A;
  1124. priv->video_standard = XC4000_BG_PAL_NICAM;
  1125. } else {
  1126. params->std |= V4L2_STD_NICAM_B;
  1127. priv->video_standard = XC4000_BG_PAL_NICAM;
  1128. }
  1129. } else {
  1130. if (!(audio_std & XC4000_AUDIO_STD_B)) {
  1131. params->std |= V4L2_STD_A2_A;
  1132. priv->video_standard = XC4000_BG_PAL_A2;
  1133. } else {
  1134. params->std |= V4L2_STD_A2_B;
  1135. priv->video_standard = XC4000_BG_PAL_A2;
  1136. }
  1137. }
  1138. goto tune_channel;
  1139. }
  1140. if (params->std & V4L2_STD_PAL_I) {
  1141. /* default to NICAM audio standard */
  1142. params->std = V4L2_STD_PAL_I | V4L2_STD_NICAM;
  1143. if (audio_std & XC4000_AUDIO_STD_MONO)
  1144. priv->video_standard = XC4000_I_PAL_NICAM_MONO;
  1145. else
  1146. priv->video_standard = XC4000_I_PAL_NICAM;
  1147. goto tune_channel;
  1148. }
  1149. if (params->std & V4L2_STD_PAL_DK) {
  1150. params->std = V4L2_STD_PAL_DK;
  1151. if (audio_std & XC4000_AUDIO_STD_MONO) {
  1152. priv->video_standard = XC4000_DK_PAL_MONO;
  1153. } else if (audio_std & XC4000_AUDIO_STD_A2) {
  1154. params->std |= V4L2_STD_A2;
  1155. priv->video_standard = XC4000_DK_PAL_A2;
  1156. } else {
  1157. params->std |= V4L2_STD_NICAM;
  1158. priv->video_standard = XC4000_DK_PAL_NICAM;
  1159. }
  1160. goto tune_channel;
  1161. }
  1162. if (params->std & V4L2_STD_SECAM_DK) {
  1163. /* default to A2 audio standard */
  1164. params->std = V4L2_STD_SECAM_DK | V4L2_STD_A2;
  1165. if (audio_std & XC4000_AUDIO_STD_L) {
  1166. type = 0;
  1167. priv->video_standard = XC4000_DK_SECAM_NICAM;
  1168. } else if (audio_std & XC4000_AUDIO_STD_MONO) {
  1169. priv->video_standard = XC4000_DK_SECAM_A2MONO;
  1170. } else if (audio_std & XC4000_AUDIO_STD_K3) {
  1171. params->std |= V4L2_STD_SECAM_K3;
  1172. priv->video_standard = XC4000_DK_SECAM_A2LDK3;
  1173. } else {
  1174. priv->video_standard = XC4000_DK_SECAM_A2DK1;
  1175. }
  1176. goto tune_channel;
  1177. }
  1178. if (params->std & V4L2_STD_SECAM_L) {
  1179. /* default to NICAM audio standard */
  1180. type = 0;
  1181. params->std = V4L2_STD_SECAM_L | V4L2_STD_NICAM;
  1182. priv->video_standard = XC4000_L_SECAM_NICAM;
  1183. goto tune_channel;
  1184. }
  1185. if (params->std & V4L2_STD_SECAM_LC) {
  1186. /* default to NICAM audio standard */
  1187. type = 0;
  1188. params->std = V4L2_STD_SECAM_LC | V4L2_STD_NICAM;
  1189. priv->video_standard = XC4000_LC_SECAM_NICAM;
  1190. goto tune_channel;
  1191. }
  1192. tune_channel:
  1193. /* FIXME: it could be air. */
  1194. priv->rf_mode = XC_RF_MODE_CABLE;
  1195. if (check_firmware(fe, type, params->std,
  1196. xc4000_standard[priv->video_standard].int_freq) != 0)
  1197. goto fail;
  1198. ret = xc_set_signal_source(priv, priv->rf_mode);
  1199. if (ret != 0) {
  1200. printk(KERN_ERR
  1201. "xc4000: xc_set_signal_source(%d) failed\n",
  1202. priv->rf_mode);
  1203. goto fail;
  1204. } else {
  1205. u16 video_mode, audio_mode;
  1206. video_mode = xc4000_standard[priv->video_standard].video_mode;
  1207. audio_mode = xc4000_standard[priv->video_standard].audio_mode;
  1208. if (priv->video_standard < XC4000_BG_PAL_A2) {
  1209. if (type & NOGD)
  1210. video_mode &= 0xFF7F;
  1211. } else if (priv->video_standard < XC4000_I_PAL_NICAM) {
  1212. if (priv->firm_version == 0x0102)
  1213. video_mode &= 0xFEFF;
  1214. if (audio_std & XC4000_AUDIO_STD_B)
  1215. video_mode |= 0x0080;
  1216. }
  1217. ret = xc_set_tv_standard(priv, video_mode, audio_mode);
  1218. if (ret != 0) {
  1219. printk(KERN_ERR "xc4000: xc_set_tv_standard failed\n");
  1220. goto fail;
  1221. }
  1222. }
  1223. if (xc_write_reg(priv, XREG_D_CODE, 0) == 0)
  1224. ret = 0;
  1225. if (xc_write_reg(priv, XREG_AMPLITUDE, 1) != 0)
  1226. ret = -EREMOTEIO;
  1227. if (priv->set_smoothedcvbs != 0) {
  1228. if (xc_write_reg(priv, XREG_SMOOTHEDCVBS, 1) != 0)
  1229. ret = -EREMOTEIO;
  1230. }
  1231. if (ret != 0) {
  1232. printk(KERN_ERR "xc4000: setting registers failed\n");
  1233. goto fail;
  1234. }
  1235. xc_tune_channel(priv, priv->freq_hz);
  1236. ret = 0;
  1237. fail:
  1238. mutex_unlock(&priv->lock);
  1239. return ret;
  1240. }
  1241. static int xc4000_get_signal(struct dvb_frontend *fe, u16 *strength)
  1242. {
  1243. struct xc4000_priv *priv = fe->tuner_priv;
  1244. u16 value = 0;
  1245. int rc;
  1246. mutex_lock(&priv->lock);
  1247. rc = xc4000_readreg(priv, XREG_SIGNAL_LEVEL, &value);
  1248. mutex_unlock(&priv->lock);
  1249. if (rc < 0)
  1250. goto ret;
  1251. /* Informations from real testing of DVB-T and radio part,
  1252. coeficient for one dB is 0xff.
  1253. */
  1254. tuner_dbg("Signal strength: -%ddB (%05d)\n", value >> 8, value);
  1255. /* all known digital modes */
  1256. if ((priv->video_standard == XC4000_DTV6) ||
  1257. (priv->video_standard == XC4000_DTV7) ||
  1258. (priv->video_standard == XC4000_DTV7_8) ||
  1259. (priv->video_standard == XC4000_DTV8))
  1260. goto digital;
  1261. /* Analog mode has NOISE LEVEL important, signal
  1262. depends only on gain of antenna and amplifiers,
  1263. but it doesn't tell anything about real quality
  1264. of reception.
  1265. */
  1266. mutex_lock(&priv->lock);
  1267. rc = xc4000_readreg(priv, XREG_NOISE_LEVEL, &value);
  1268. mutex_unlock(&priv->lock);
  1269. tuner_dbg("Noise level: %ddB (%05d)\n", value >> 8, value);
  1270. /* highest noise level: 32dB */
  1271. if (value >= 0x2000) {
  1272. value = 0;
  1273. } else {
  1274. value = (~value << 3) & 0xffff;
  1275. }
  1276. goto ret;
  1277. /* Digital mode has SIGNAL LEVEL important and real
  1278. noise level is stored in demodulator registers.
  1279. */
  1280. digital:
  1281. /* best signal: -50dB */
  1282. if (value <= 0x3200) {
  1283. value = 0xffff;
  1284. /* minimum: -114dB - should be 0x7200 but real zero is 0x713A */
  1285. } else if (value >= 0x713A) {
  1286. value = 0;
  1287. } else {
  1288. value = ~(value - 0x3200) << 2;
  1289. }
  1290. ret:
  1291. *strength = value;
  1292. return rc;
  1293. }
  1294. static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
  1295. {
  1296. struct xc4000_priv *priv = fe->tuner_priv;
  1297. *freq = priv->freq_hz + priv->freq_offset;
  1298. if (debug) {
  1299. mutex_lock(&priv->lock);
  1300. if ((priv->cur_fw.type
  1301. & (BASE | FM | DTV6 | DTV7 | DTV78 | DTV8)) == BASE) {
  1302. u16 snr = 0;
  1303. if (xc4000_readreg(priv, XREG_SNR, &snr) == 0) {
  1304. mutex_unlock(&priv->lock);
  1305. dprintk(1, "%s() freq = %u, SNR = %d\n",
  1306. __func__, *freq, snr);
  1307. return 0;
  1308. }
  1309. }
  1310. mutex_unlock(&priv->lock);
  1311. }
  1312. dprintk(1, "%s()\n", __func__);
  1313. return 0;
  1314. }
  1315. static int xc4000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
  1316. {
  1317. struct xc4000_priv *priv = fe->tuner_priv;
  1318. dprintk(1, "%s()\n", __func__);
  1319. *bw = priv->bandwidth;
  1320. return 0;
  1321. }
  1322. static int xc4000_get_status(struct dvb_frontend *fe, u32 *status)
  1323. {
  1324. struct xc4000_priv *priv = fe->tuner_priv;
  1325. u16 lock_status = 0;
  1326. mutex_lock(&priv->lock);
  1327. if (priv->cur_fw.type & BASE)
  1328. xc_get_lock_status(priv, &lock_status);
  1329. *status = (lock_status == 1 ?
  1330. TUNER_STATUS_LOCKED | TUNER_STATUS_STEREO : 0);
  1331. if (priv->cur_fw.type & (DTV6 | DTV7 | DTV78 | DTV8))
  1332. *status &= (~TUNER_STATUS_STEREO);
  1333. mutex_unlock(&priv->lock);
  1334. dprintk(2, "%s() lock_status = %d\n", __func__, lock_status);
  1335. return 0;
  1336. }
  1337. static int xc4000_sleep(struct dvb_frontend *fe)
  1338. {
  1339. struct xc4000_priv *priv = fe->tuner_priv;
  1340. int ret = 0;
  1341. dprintk(1, "%s()\n", __func__);
  1342. mutex_lock(&priv->lock);
  1343. /* Avoid firmware reload on slow devices */
  1344. if ((no_poweroff == 2 ||
  1345. (no_poweroff == 0 && priv->default_pm != 0)) &&
  1346. (priv->cur_fw.type & BASE) != 0) {
  1347. /* force reset and firmware reload */
  1348. priv->cur_fw.type = XC_POWERED_DOWN;
  1349. if (xc_write_reg(priv, XREG_POWER_DOWN, 0) != 0) {
  1350. printk(KERN_ERR
  1351. "xc4000: %s() unable to shutdown tuner\n",
  1352. __func__);
  1353. ret = -EREMOTEIO;
  1354. }
  1355. msleep(20);
  1356. }
  1357. mutex_unlock(&priv->lock);
  1358. return ret;
  1359. }
  1360. static int xc4000_init(struct dvb_frontend *fe)
  1361. {
  1362. dprintk(1, "%s()\n", __func__);
  1363. return 0;
  1364. }
  1365. static void xc4000_release(struct dvb_frontend *fe)
  1366. {
  1367. struct xc4000_priv *priv = fe->tuner_priv;
  1368. dprintk(1, "%s()\n", __func__);
  1369. mutex_lock(&xc4000_list_mutex);
  1370. if (priv)
  1371. hybrid_tuner_release_state(priv);
  1372. mutex_unlock(&xc4000_list_mutex);
  1373. fe->tuner_priv = NULL;
  1374. }
  1375. static const struct dvb_tuner_ops xc4000_tuner_ops = {
  1376. .info = {
  1377. .name = "Xceive XC4000",
  1378. .frequency_min_hz = 1 * MHz,
  1379. .frequency_max_hz = 1023 * MHz,
  1380. .frequency_step_hz = 50 * kHz,
  1381. },
  1382. .release = xc4000_release,
  1383. .init = xc4000_init,
  1384. .sleep = xc4000_sleep,
  1385. .set_params = xc4000_set_params,
  1386. .set_analog_params = xc4000_set_analog_params,
  1387. .get_frequency = xc4000_get_frequency,
  1388. .get_rf_strength = xc4000_get_signal,
  1389. .get_bandwidth = xc4000_get_bandwidth,
  1390. .get_status = xc4000_get_status
  1391. };
  1392. struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe,
  1393. struct i2c_adapter *i2c,
  1394. struct xc4000_config *cfg)
  1395. {
  1396. struct xc4000_priv *priv = NULL;
  1397. int instance;
  1398. u16 id = 0;
  1399. dprintk(1, "%s(%d-%04x)\n", __func__,
  1400. i2c ? i2c_adapter_id(i2c) : -1,
  1401. cfg ? cfg->i2c_address : -1);
  1402. mutex_lock(&xc4000_list_mutex);
  1403. instance = hybrid_tuner_request_state(struct xc4000_priv, priv,
  1404. hybrid_tuner_instance_list,
  1405. i2c, cfg->i2c_address, "xc4000");
  1406. switch (instance) {
  1407. case 0:
  1408. goto fail;
  1409. case 1:
  1410. /* new tuner instance */
  1411. priv->bandwidth = 6000000;
  1412. /* set default configuration */
  1413. priv->if_khz = 4560;
  1414. priv->default_pm = 0;
  1415. priv->dvb_amplitude = 134;
  1416. priv->set_smoothedcvbs = 1;
  1417. mutex_init(&priv->lock);
  1418. fe->tuner_priv = priv;
  1419. break;
  1420. default:
  1421. /* existing tuner instance */
  1422. fe->tuner_priv = priv;
  1423. break;
  1424. }
  1425. if (cfg->if_khz != 0) {
  1426. /* copy configuration if provided by the caller */
  1427. priv->if_khz = cfg->if_khz;
  1428. priv->default_pm = cfg->default_pm;
  1429. priv->dvb_amplitude = cfg->dvb_amplitude;
  1430. priv->set_smoothedcvbs = cfg->set_smoothedcvbs;
  1431. }
  1432. /* Check if firmware has been loaded. It is possible that another
  1433. instance of the driver has loaded the firmware.
  1434. */
  1435. if (instance == 1) {
  1436. if (xc4000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
  1437. goto fail;
  1438. } else {
  1439. id = ((priv->cur_fw.type & BASE) != 0 ?
  1440. priv->hwmodel : XC_PRODUCT_ID_FW_NOT_LOADED);
  1441. }
  1442. switch (id) {
  1443. case XC_PRODUCT_ID_XC4000:
  1444. case XC_PRODUCT_ID_XC4100:
  1445. printk(KERN_INFO
  1446. "xc4000: Successfully identified at address 0x%02x\n",
  1447. cfg->i2c_address);
  1448. printk(KERN_INFO
  1449. "xc4000: Firmware has been loaded previously\n");
  1450. break;
  1451. case XC_PRODUCT_ID_FW_NOT_LOADED:
  1452. printk(KERN_INFO
  1453. "xc4000: Successfully identified at address 0x%02x\n",
  1454. cfg->i2c_address);
  1455. printk(KERN_INFO
  1456. "xc4000: Firmware has not been loaded previously\n");
  1457. break;
  1458. default:
  1459. printk(KERN_ERR
  1460. "xc4000: Device not found at addr 0x%02x (0x%x)\n",
  1461. cfg->i2c_address, id);
  1462. goto fail;
  1463. }
  1464. mutex_unlock(&xc4000_list_mutex);
  1465. memcpy(&fe->ops.tuner_ops, &xc4000_tuner_ops,
  1466. sizeof(struct dvb_tuner_ops));
  1467. if (instance == 1) {
  1468. int ret;
  1469. mutex_lock(&priv->lock);
  1470. ret = xc4000_fwupload(fe);
  1471. mutex_unlock(&priv->lock);
  1472. if (ret != 0)
  1473. goto fail2;
  1474. }
  1475. return fe;
  1476. fail:
  1477. mutex_unlock(&xc4000_list_mutex);
  1478. fail2:
  1479. xc4000_release(fe);
  1480. return NULL;
  1481. }
  1482. EXPORT_SYMBOL(xc4000_attach);
  1483. MODULE_AUTHOR("Steven Toth, Davide Ferri");
  1484. MODULE_DESCRIPTION("Xceive xc4000 silicon tuner driver");
  1485. MODULE_LICENSE("GPL");
  1486. MODULE_FIRMWARE(XC4000_DEFAULT_FIRMWARE_NEW);
  1487. MODULE_FIRMWARE(XC4000_DEFAULT_FIRMWARE);