Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

stfm1000 patch for rockbox
Saturday, May 26th, 2012 at 3:55:20am MDT 

  1. diff --git a/apps/debug_menu.c b/apps/debug_menu.c
  2. index e611694..bf37b3a 100644
  3. --- a/apps/debug_menu.c
  4. +++ b/apps/debug_menu.c
  5. @@ -1873,6 +1873,11 @@ static int radio_callback(int btn, struct gui_synclist *lists)
  6.          struct stfm1000_dbg_info nfo;
  7.          stfm1000_dbg_info(&nfo);
  8.          simplelist_addline(SIMPLELIST_ADD_LINE, "STFM1000 regs:");
  9. +        simplelist_addline(SIMPLELIST_ADD_LINE,"tune1: 0x%x", nfo.tune1);
  10. +        simplelist_addline(SIMPLELIST_ADD_LINE,"sdnominal: 0x%x", nfo.sdnominal);
  11. +        simplelist_addline(SIMPLELIST_ADD_LINE,"pilottracking: 0x%x", nfo.pilottracking);
  12. +        simplelist_addline(SIMPLELIST_ADD_LINE,"rssi_tone: 0x%x", nfo.rssi_tone);
  13. +        simplelist_addline(SIMPLELIST_ADD_LINE,"pilotcorrection: 0x%x", nfo.pilotcorrection);
  14.          simplelist_addline(SIMPLELIST_ADD_LINE,"chipid: 0x%x", nfo.chipid);
  15.      }
  16.  #endif /* STFM1000 */
  17. diff --git a/firmware/drivers/tuner/stfm1000-regs.h b/firmware/drivers/tuner/stfm1000-regs.h
  18. new file mode 100644
  19. index 0000000..eab0035
  20. --- /dev/null
  21. +++ b/firmware/drivers/tuner/stfm1000-regs.h
  22. @@ -0,0 +1,165 @@
  23. +/*
  24. + * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
  25. + */
  26. +
  27. +/*
  28. + * The code contained herein is licensed under the GNU General Public
  29. + * License. You may obtain a copy of the GNU General Public License
  30. + * Version 2 or later at the following locations:
  31. + *
  32. + * http://www.opensource.org/licenses/gpl-license.html
  33. + * http://www.gnu.org/copyleft/gpl.html
  34. + */
  35. +#ifndef STFM1000_REGS_H
  36. +#define STFM1000_REGS_H
  37. +
  38. +/* registers */
  39. +#define STFM1000_TUNE1              0x00
  40. +#define STFM1000_SDNOMINAL          0x04
  41. +#define STFM1000_PILOTTRACKING            0x08
  42. +#define STFM1000_INITIALIZATION1    0x10
  43. +#define STFM1000_INITIALIZATION2    0x14
  44. +#define STFM1000_INITIALIZATION3    0x18
  45. +#define STFM1000_INITIALIZATION4    0x1C
  46. +#define STFM1000_INITIALIZATION5    0x20
  47. +#define STFM1000_INITIALIZATION6    0x24
  48. +#define STFM1000_REF                0x28
  49. +#define STFM1000_LNA                0x2C
  50. +#define STFM1000_MIXFILT            0x30
  51. +#define STFM1000_CLK1               0x34
  52. +#define STFM1000_CLK2               0x38
  53. +#define STFM1000_ADC                0x3C
  54. +#define STFM1000_AGC_CONTROL1       0x44
  55. +#define STFM1000_AGC_CONTROL2       0x48
  56. +#define STFM1000_DATAPATH           0x5C
  57. +#define STFM1000_RMS                0x60
  58. +#define STFM1000_AGC_STAT           0x64
  59. +#define STFM1000_SIGNALQUALITY            0x68
  60. +#define STFM1000_DCEST              0x6C
  61. +#define STFM1000_RSSI_TONE          0x70
  62. +#define STFM1000_PILOTCORRECTION    0x74
  63. +#define STFM1000_ATTENTION          0x78
  64. +#define STFM1000_CLK3               0x7C
  65. +#define STFM1000_CHIPID             0x80
  66. +
  67. +/* number of registers */
  68. +#define STFM1000_NUM_REGS           ((0x80 + 4) / 4)
  69. +
  70. +#define STFM1000_FREQUENCY_100KHZ_MIN     758
  71. +#define STFM1000_FREQUENCY_100KHZ_RANGE   325
  72. +#define STFM1000_FREQUENCY_100KHZ_MAX     (STFM1000_FREQUENCY_100KHZ_MIN + \
  73. +                              STFM1000_FREQUENCY_100KHZ_RANGE)
  74. +
  75. +#define STFM1000_TUNE1_B2_MIX       0x001C0000
  76. +#define STFM1000_TUNE1_CICOSR       0x00007E00
  77. +#define STFM1000_TUNE1_PLL_DIV            0x000001FF
  78. +
  79. +#define STFM1000_CHIP_REV_TA1       0x00000001
  80. +#define STFM1000_CHIP_REV_TA2       0x00000002
  81. +#define STFM1000_CHIP_REV_TB1       0x00000011
  82. +#define STFM1000_CHIP_REV_TB2       0x00000012
  83. +
  84. +/* DATAPATH bits we use */
  85. +#define STFM1000_DP_EN              0x01000000
  86. +#define STFM1000_DB_ACCEPT          0x00010000
  87. +#define STFM1000_SAI_CLK_DIV_MASK   0x7c
  88. +#define STFM1000_SAI_CLK_DIV_SHIFT  2
  89. +#define STFM1000_SAI_CLK_DIV(x) \
  90. +      (((x) << STFM1000_SAI_CLK_DIV_SHIFT) & STFM1000_SAI_CLK_DIV_MASK)
  91. +#define STFM1000_SAI_EN             0x00000001
  92. +
  93. +/* AGC_CONTROL1 bits we use */
  94. +#define STFM1000_B2_BYPASS_AGC_CTL  0x00004000
  95. +#define STFM1000_B2_BYPASS_FILT_MASK      0x0000000C
  96. +#define STFM1000_B2_BYPASS_FILT_SHIFT     2
  97. +#define STFM1000_B2_BYPASS_FILT(x) \
  98. +      (((x) << STFM1000_B2_BYPASS_FILT_SHIFT) & STFM1000_B2_BYPASS_FILT_MASK)
  99. +#define STFM1000_B2_LNATH_MASK            0x001F0000
  100. +#define STFM1000_B2_LNATH_SHIFT           16
  101. +#define STFM1000_B2_LNATH(x) \
  102. +      (((x) << STFM1000_B2_LNATH_SHIFT) & STFM1000_B2_LNATH_MASK)
  103. +
  104. +/* AGC_STAT bits we use */
  105. +#define STFM1000_AGCOUT_STAT_MASK   0x1F000000
  106. +#define STFM1000_AGCOUT_STAT_SHIFT  24
  107. +#define STFM1000_LNA_RMS_MASK       0x00001F00
  108. +#define STFM1000_LNA_RMS_SHIFT            8
  109. +
  110. +/* PILOTTRACKING bits we use */
  111. +#define STFM1000_B2_PILOTTRACKING_EN            0x00008000
  112. +#define STFM1000_B2_PILOTLPF_TIMECONSTANT_MASK  0x00000f00
  113. +#define STFM1000_B2_PILOTLPF_TIMECONSTANT_SHIFT 8
  114. +#define STFM1000_B2_PILOTLPF_TIMECONSTANT(x)    \
  115. +      (((x) << STFM1000_B2_PILOTLPF_TIMECONSTANT_SHIFT) & \
  116. +            STFM1000_B2_PILOTLPF_TIMECONSTANT_MASK)
  117. +#define STFM1000_B2_PFDSCALE_MASK         0x000000f0
  118. +#define STFM1000_B2_PFDSCALE_SHIFT        4
  119. +#define STFM1000_B2_PFDSCALE(x)     \
  120. +      (((x) << STFM1000_B2_PFDSCALE_SHIFT) & STFM1000_B2_PFDSCALE_MASK)
  121. +#define STFM1000_B2_PFDFILTER_SPEEDUP_MASK      0x0000000f
  122. +#define STFM1000_B2_PFDFILTER_SPEEDUP_SHIFT     0
  123. +#define STFM1000_B2_PFDFILTER_SPEEDUP(x)  \
  124. +      (((x) << STFM1000_B2_PFDFILTER_SPEEDUP_SHIFT) & \
  125. +            STFM1000_B2_PFDFILTER_SPEEDUP_MASK)
  126. +
  127. +/* PILOTCORRECTION bits we use */
  128. +#define STFM1000_PILOTEST_TA2_MASK  0xff000000
  129. +#define STFM1000_PILOTEST_TA2_SHIFT 24
  130. +#define STFM1000_PILOTEST_TB2_MASK  0xfe000000
  131. +#define STFM1000_PILOTEST_TB2_SHIFT 25
  132. +
  133. +/* INITIALIZATION1 bits we use */
  134. +#define STFM1000_B2_BYPASS_FILT_MASK      0x0000000C
  135. +#define STFM1000_B2_BYPASS_FILT_SHIFT     2
  136. +#define STFM1000_B2_BYPASS_FILT(x)  \
  137. +      (((x) << STFM1000_B2_BYPASS_FILT_SHIFT) & STFM1000_B2_BYPASS_FILT_MASK)
  138. +
  139. +/* INITIALIZATION2 bits we use */
  140. +#define STFM1000_DRI_CLK_EN         0x80000000
  141. +#define STFM1000_DEEMPH_50_75B            0x00000100
  142. +#define STFM1000_RDS_ENABLE         0x00100000
  143. +#define STFM1000_RDS_MIXOFFSET            0x00200000
  144. +
  145. +/* INITIALIZATION3 bits we use */
  146. +#define STFM1000_B2_NEAR_CHAN_MIX_MASK    0x1c000000
  147. +#define STFM1000_B2_NEAR_CHAN_MIX_SHIFT   26
  148. +#define STFM1000_B2_NEAR_CHAN_MIX(x)      \
  149. +      (((x) << STFM1000_B2_NEAR_CHAN_MIX_SHIFT) & \
  150. +            STFM1000_B2_NEAR_CHAN_MIX_MASK)
  151. +
  152. +/* CLK1 bits we use */
  153. +#define STFM1000_ENABLE_TAPDELAYFIX 0x00000020
  154. +
  155. +/* REF bits we use */
  156. +#define STFM1000_LNA_AMP1_IMPROVE_DISTORTION 0x08000000
  157. +
  158. +/* LNA bits we use */
  159. +#define STFM1000_AMP2_IMPROVE_DISTORTION 0x08000000
  160. +#define STFM1000_ANTENNA_TUNECAP_MASK     0x001F0000
  161. +#define STFM1000_ANTENNA_TUNECAP_SHIFT    16
  162. +#define STFM1000_ANTENNA_TUNECAP(x) \
  163. +      (((x) << STFM1000_ANTENNA_TUNECAP_SHIFT) & \
  164. +            STFM1000_ANTENNA_TUNECAP_MASK)
  165. +#define STFM1000_IBIAS2_UP          0x00000008
  166. +#define STFM1000_IBIAS2_DN          0x00000004
  167. +#define STFM1000_IBIAS1_UP          0x00000002
  168. +#define STFM1000_IBIAS1_DN          0x00000001
  169. +#define STFM1000_USEATTEN_MASK            0x00600000
  170. +#define STFM1000_USEATTEN_SHIFT           21
  171. +#define STFM1000_USEATTEN(x)  \
  172. +      (((x) << STFM1000_USEATTEN_SHIFT) & STFM1000_USEATTEN_MASK)
  173. +
  174. +/* SIGNALQUALITY bits we use */
  175. +#define STFM1000_NEAR_CHAN_AMPLITUDE_MASK 0x0000007F
  176. +#define STFM1000_NEAR_CHAN_AMPLITUDE_SHIFT      0
  177. +#define STFM1000_NEAR_CHAN_AMPLITUDE(x)   \
  178. +      (((x) << STFM1000_NEAR_CHAN_AMPLITUDE_SHIFT) & \
  179. +            STFM1000_NEAR_CHAN_AMPLITUDE_MASK)
  180. +
  181. +/* precalc tables elements */
  182. +struct stfm1000_tune1 {
  183. +      unsigned int tune1;     /* at least 32 bit */
  184. +      unsigned int sdnom;
  185. +};
  186. +
  187. +#endif
  188. diff --git a/firmware/drivers/tuner/stfm1000-tunetable.c b/firmware/drivers/tuner/stfm1000-tunetable.c
  189. new file mode 100644
  190. index 0000000..6cedf97
  191. --- /dev/null
  192. +++ b/firmware/drivers/tuner/stfm1000-tunetable.c
  193. @@ -0,0 +1,330 @@
  194. +#include "stfm1000-regs.h"
  195. +
  196. +const struct stfm1000_tune1
  197. +stfm1000_tune1_table[STFM1000_FREQUENCY_100KHZ_RANGE] = {
  198. +       [758 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004038, .sdnom = 0x1bb465cd },
  199. +       [759 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004039, .sdnom = 0x1bbdc11f },
  200. +       [760 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000403a, .sdnom = 0x1bc71c71 },
  201. +       [761 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000403b, .sdnom = 0x1bd077c4 },
  202. +       [762 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000403c, .sdnom = 0x1bd9d316 },
  203. +       [763 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000403d, .sdnom = 0x1be32e68 },
  204. +       [764 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000403e, .sdnom = 0x1bec89bb },
  205. +       [765 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004030, .sdnom = 0x1bf5e50d },
  206. +       [766 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004041, .sdnom = 0x1bff405f },
  207. +       [767 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004042, .sdnom = 0x1c089bb2 },
  208. +       [768 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004043, .sdnom = 0x1c11f704 },
  209. +       [769 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004044, .sdnom = 0x1c1b5256 },
  210. +       [770 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004045, .sdnom = 0x1c24ada9 },
  211. +       [771 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004046, .sdnom = 0x1c2e08fb },
  212. +       [772 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004047, .sdnom = 0x1c37644d },
  213. +       [773 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004048, .sdnom = 0x1c40bfa0 },
  214. +       [774 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004049, .sdnom = 0x1c4a1af2 },
  215. +       [775 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000404a, .sdnom = 0x1c537644 },
  216. +       [776 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000404b, .sdnom = 0x1c5cd197 },
  217. +       [777 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000404c, .sdnom = 0x1c662ce9 },
  218. +       [778 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000404d, .sdnom = 0x1c6f883b },
  219. +       [779 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000404e, .sdnom = 0x1c78e38e },
  220. +       [780 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004240, .sdnom = 0x1ba5162f },
  221. +       [781 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004251, .sdnom = 0x1bae28eb },
  222. +       [782 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004252, .sdnom = 0x1bb73ba7 },
  223. +       [783 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004253, .sdnom = 0x1bc04e64 },
  224. +       [784 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004254, .sdnom = 0x1bc96120 },
  225. +       [785 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004255, .sdnom = 0x1bd273dd },
  226. +       [786 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004256, .sdnom = 0x1bdb8699 },
  227. +       [787 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004257, .sdnom = 0x1be49956 },
  228. +       [788 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004258, .sdnom = 0x1bedac12 },
  229. +       [789 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004259, .sdnom = 0x1bf6becf },
  230. +       [790 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000425a, .sdnom = 0x1bffd18b },
  231. +       [791 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000425b, .sdnom = 0x1c08e448 },
  232. +       [792 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000425c, .sdnom = 0x1c11f704 },
  233. +       [793 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000425d, .sdnom = 0x1c1b09c0 },
  234. +       [794 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000425e, .sdnom = 0x1c241c7d },
  235. +       [795 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004250, .sdnom = 0x1c2d2f39 },
  236. +       [796 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004261, .sdnom = 0x1c3641f6 },
  237. +       [797 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004262, .sdnom = 0x1c3f54b2 },
  238. +       [798 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004263, .sdnom = 0x1c48676f },
  239. +       [799 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004264, .sdnom = 0x1c517a2b },
  240. +       [800 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004265, .sdnom = 0x1c5a8ce8 },
  241. +       [801 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004266, .sdnom = 0x1c639fa4 },
  242. +       [802 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004267, .sdnom = 0x1c6cb260 },
  243. +       [803 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004268, .sdnom = 0x1c75c51d },
  244. +       [804 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004469, .sdnom = 0x1ba849f9 },
  245. +       [805 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000446a, .sdnom = 0x1bb11864 },
  246. +       [806 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000446b, .sdnom = 0x1bb9e6d0 },
  247. +       [807 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000446c, .sdnom = 0x1bc2b53b },
  248. +       [808 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000446d, .sdnom = 0x1bcb83a7 },
  249. +       [809 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000446e, .sdnom = 0x1bd45213 },
  250. +       [810 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004460, .sdnom = 0x1bdd207e },
  251. +       [811 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004471, .sdnom = 0x1be5eeea },
  252. +       [812 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004472, .sdnom = 0x1beebd56 },
  253. +       [813 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004473, .sdnom = 0x1bf78bc1 },
  254. +       [814 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004474, .sdnom = 0x1c005a2d },
  255. +       [815 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004475, .sdnom = 0x1c092898 },
  256. +       [816 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004476, .sdnom = 0x1c11f704 },
  257. +       [817 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004477, .sdnom = 0x1c1ac570 },
  258. +       [818 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004478, .sdnom = 0x1c2393db },
  259. +       [819 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004479, .sdnom = 0x1c2c6247 },
  260. +       [820 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000447a, .sdnom = 0x1c3530b2 },
  261. +       [821 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000447b, .sdnom = 0x1c3dff1e },
  262. +       [822 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000447c, .sdnom = 0x1c46cd8a },
  263. +       [823 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000447d, .sdnom = 0x1c4f9bf5 },
  264. +       [824 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000447e, .sdnom = 0x1c586a61 },
  265. +       [825 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004470, .sdnom = 0x1c6138cd },
  266. +       [826 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004481, .sdnom = 0x1c6a0738 },
  267. +       [827 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004482, .sdnom = 0x1c72d5a4 },
  268. +       [828 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004683, .sdnom = 0x1bab4eea },
  269. +       [829 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004684, .sdnom = 0x1bb3dcec },
  270. +       [830 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004685, .sdnom = 0x1bbc6aef },
  271. +       [831 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004686, .sdnom = 0x1bc4f8f1 },
  272. +       [832 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004687, .sdnom = 0x1bcd86f3 },
  273. +       [833 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004688, .sdnom = 0x1bd614f5 },
  274. +       [834 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004689, .sdnom = 0x1bdea2f7 },
  275. +       [835 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000468a, .sdnom = 0x1be730f9 },
  276. +       [836 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000468b, .sdnom = 0x1befbefb },
  277. +       [837 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000468c, .sdnom = 0x1bf84cfe },
  278. +       [838 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000468d, .sdnom = 0x1c00db00 },
  279. +       [839 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000468e, .sdnom = 0x1c096902 },
  280. +       [840 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004680, .sdnom = 0x1c11f704 },
  281. +       [841 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004691, .sdnom = 0x1c1a8506 },
  282. +       [842 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004692, .sdnom = 0x1c231308 },
  283. +       [843 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004693, .sdnom = 0x1c2ba10a },
  284. +       [844 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004694, .sdnom = 0x1c342f0d },
  285. +       [845 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004695, .sdnom = 0x1c3cbd0f },
  286. +       [846 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004696, .sdnom = 0x1c454b11 },
  287. +       [847 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004697, .sdnom = 0x1c4dd913 },
  288. +       [848 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004698, .sdnom = 0x1c566715 },
  289. +       [849 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004699, .sdnom = 0x1c5ef517 },
  290. +       [850 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000469a, .sdnom = 0x1c678319 },
  291. +       [851 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000469b, .sdnom = 0x1c70111c },
  292. +       [852 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000489c, .sdnom = 0x1bae28eb },
  293. +       [853 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000489d, .sdnom = 0x1bb67a18 },
  294. +       [854 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000489e, .sdnom = 0x1bbecb45 },
  295. +       [855 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004890, .sdnom = 0x1bc71c71 },
  296. +       [856 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a1, .sdnom = 0x1bcf6d9e },
  297. +       [857 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a2, .sdnom = 0x1bd7becb },
  298. +       [858 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a3, .sdnom = 0x1be00ff8 },
  299. +       [859 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a4, .sdnom = 0x1be86124 },
  300. +       [860 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a5, .sdnom = 0x1bf0b251 },
  301. +       [861 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a6, .sdnom = 0x1bf9037e },
  302. +       [862 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a7, .sdnom = 0x1c0154aa },
  303. +       [863 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a8, .sdnom = 0x1c09a5d7 },
  304. +       [864 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a9, .sdnom = 0x1c11f704 },
  305. +       [865 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048aa, .sdnom = 0x1c1a4831 },
  306. +       [866 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048ab, .sdnom = 0x1c22995d },
  307. +       [867 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048ac, .sdnom = 0x1c2aea8a },
  308. +       [868 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048ad, .sdnom = 0x1c333bb7 },
  309. +       [869 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048ae, .sdnom = 0x1c3b8ce4 },
  310. +       [870 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048a0, .sdnom = 0x1c43de10 },
  311. +       [871 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048b1, .sdnom = 0x1c4c2f3d },
  312. +       [872 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048b2, .sdnom = 0x1c54806a },
  313. +       [873 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048b3, .sdnom = 0x1c5cd197 },
  314. +       [874 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048b4, .sdnom = 0x1c6522c3 },
  315. +       [875 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x000048b5, .sdnom = 0x1c6d73f0 },
  316. +       [876 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ab6, .sdnom = 0x1bb0db76 },
  317. +       [877 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ab7, .sdnom = 0x1bb8f317 },
  318. +       [878 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ab8, .sdnom = 0x1bc10ab8 },
  319. +       [879 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ab9, .sdnom = 0x1bc9225a },
  320. +       [880 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004aba, .sdnom = 0x1bd139fb },
  321. +       [881 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004abb, .sdnom = 0x1bd9519c },
  322. +       [882 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004abc, .sdnom = 0x1be1693d },
  323. +       [883 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004abd, .sdnom = 0x1be980de },
  324. +       [884 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004abe, .sdnom = 0x1bf1987f },
  325. +       [885 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ab0, .sdnom = 0x1bf9b021 },
  326. +       [886 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac1, .sdnom = 0x1c01c7c2 },
  327. +       [887 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac2, .sdnom = 0x1c09df63 },
  328. +       [888 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac3, .sdnom = 0x1c11f704 },
  329. +       [889 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac4, .sdnom = 0x1c1a0ea5 },
  330. +       [890 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac5, .sdnom = 0x1c222646 },
  331. +       [891 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac6, .sdnom = 0x1c2a3de7 },
  332. +       [892 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac7, .sdnom = 0x1c325589 },
  333. +       [893 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac8, .sdnom = 0x1c3a6d2a },
  334. +       [894 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ac9, .sdnom = 0x1c4284cb },
  335. +       [895 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004aca, .sdnom = 0x1c4a9c6c },
  336. +       [896 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004acb, .sdnom = 0x1c52b40d },
  337. +       [897 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004acc, .sdnom = 0x1c5acbae },
  338. +       [898 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004acd, .sdnom = 0x1c62e350 },
  339. +       [899 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ace, .sdnom = 0x1c6afaf1 },
  340. +       [900 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cc0, .sdnom = 0x1bb369a9 },
  341. +       [901 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd1, .sdnom = 0x1bbb4ac6 },
  342. +       [902 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd2, .sdnom = 0x1bc32be3 },
  343. +       [903 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd3, .sdnom = 0x1bcb0d00 },
  344. +       [904 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd4, .sdnom = 0x1bd2ee1d },
  345. +       [905 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd5, .sdnom = 0x1bdacf3a },
  346. +       [906 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd6, .sdnom = 0x1be2b056 },
  347. +       [907 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd7, .sdnom = 0x1bea9173 },
  348. +       [908 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd8, .sdnom = 0x1bf27290 },
  349. +       [909 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd9, .sdnom = 0x1bfa53ad },
  350. +       [910 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cda, .sdnom = 0x1c0234ca },
  351. +       [911 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cdb, .sdnom = 0x1c0a15e7 },
  352. +       [912 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cdc, .sdnom = 0x1c11f704 },
  353. +       [913 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cdd, .sdnom = 0x1c19d821 },
  354. +       [914 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cde, .sdnom = 0x1c21b93e },
  355. +       [915 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004cd0, .sdnom = 0x1c299a5b },
  356. +       [916 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce1, .sdnom = 0x1c317b78 },
  357. +       [917 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce2, .sdnom = 0x1c395c95 },
  358. +       [918 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce3, .sdnom = 0x1c413db1 },
  359. +       [919 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce4, .sdnom = 0x1c491ece },
  360. +       [920 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce5, .sdnom = 0x1c50ffeb },
  361. +       [921 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce6, .sdnom = 0x1c58e108 },
  362. +       [922 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce7, .sdnom = 0x1c60c225 },
  363. +       [923 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ce8, .sdnom = 0x1c68a342 },
  364. +       [924 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ee9, .sdnom = 0x1bb5d64f },
  365. +       [925 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004eea, .sdnom = 0x1bbd83b4 },
  366. +       [926 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004eeb, .sdnom = 0x1bc53118 },
  367. +       [927 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004eec, .sdnom = 0x1bccde7d },
  368. +       [928 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004eed, .sdnom = 0x1bd48be1 },
  369. +       [929 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004eee, .sdnom = 0x1bdc3945 },
  370. +       [930 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ee0, .sdnom = 0x1be3e6aa },
  371. +       [931 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef1, .sdnom = 0x1beb940e },
  372. +       [932 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef2, .sdnom = 0x1bf34172 },
  373. +       [933 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef3, .sdnom = 0x1bfaeed7 },
  374. +       [934 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef4, .sdnom = 0x1c029c3b },
  375. +       [935 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef5, .sdnom = 0x1c0a49a0 },
  376. +       [936 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef6, .sdnom = 0x1c11f704 },
  377. +       [937 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef7, .sdnom = 0x1c19a468 },
  378. +       [938 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef8, .sdnom = 0x1c2151cd },
  379. +       [939 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef9, .sdnom = 0x1c28ff31 },
  380. +       [940 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004efa, .sdnom = 0x1c30ac96 },
  381. +       [941 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004efb, .sdnom = 0x1c3859fa },
  382. +       [942 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004efc, .sdnom = 0x1c40075e },
  383. +       [943 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004efd, .sdnom = 0x1c47b4c3 },
  384. +       [944 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004efe, .sdnom = 0x1c4f6227 },
  385. +       [945 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004ef0, .sdnom = 0x1c570f8b },
  386. +       [946 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004f01, .sdnom = 0x1c5ebcf0 },
  387. +       [947 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00004f02, .sdnom = 0x1c666a54 },
  388. +       [948 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005103, .sdnom = 0x1bb823ee },
  389. +       [949 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005104, .sdnom = 0x1bbfa02f },
  390. +       [950 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005105, .sdnom = 0x1bc71c71 },
  391. +       [951 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005106, .sdnom = 0x1bce98b3 },
  392. +       [952 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005107, .sdnom = 0x1bd614f5 },
  393. +       [953 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005108, .sdnom = 0x1bdd9137 },
  394. +       [954 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005109, .sdnom = 0x1be50d79 },
  395. +       [955 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000510a, .sdnom = 0x1bec89bb },
  396. +       [956 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000510b, .sdnom = 0x1bf405fd },
  397. +       [957 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000510c, .sdnom = 0x1bfb823e },
  398. +       [958 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000510d, .sdnom = 0x1c02fe80 },
  399. +       [959 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000510e, .sdnom = 0x1c0a7ac2 },
  400. +       [960 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005100, .sdnom = 0x1c11f704 },
  401. +       [961 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005111, .sdnom = 0x1c197346 },
  402. +       [962 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005112, .sdnom = 0x1c20ef88 },
  403. +       [963 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005113, .sdnom = 0x1c286bca },
  404. +       [964 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005114, .sdnom = 0x1c2fe80b },
  405. +       [965 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005115, .sdnom = 0x1c37644d },
  406. +       [966 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005116, .sdnom = 0x1c3ee08f },
  407. +       [967 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005117, .sdnom = 0x1c465cd1 },
  408. +       [968 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005118, .sdnom = 0x1c4dd913 },
  409. +       [969 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005119, .sdnom = 0x1c555555 },
  410. +       [970 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000511a, .sdnom = 0x1c5cd197 },
  411. +       [971 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000511b, .sdnom = 0x1c644dd9 },
  412. +       [972 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000531c, .sdnom = 0x1bba54c9 },
  413. +       [973 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000531d, .sdnom = 0x1bc1a24e },
  414. +       [974 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000531e, .sdnom = 0x1bc8efd3 },
  415. +       [975 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005310, .sdnom = 0x1bd03d57 },
  416. +       [976 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005321, .sdnom = 0x1bd78adc },
  417. +       [977 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005322, .sdnom = 0x1bded861 },
  418. +       [978 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005323, .sdnom = 0x1be625e6 },
  419. +       [979 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005324, .sdnom = 0x1bed736b },
  420. +       [980 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005325, .sdnom = 0x1bf4c0f0 },
  421. +       [981 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005326, .sdnom = 0x1bfc0e75 },
  422. +       [982 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005327, .sdnom = 0x1c035bfa },
  423. +       [983 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005328, .sdnom = 0x1c0aa97f },
  424. +       [984 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005329, .sdnom = 0x1c11f704 },
  425. +       [985 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000532a, .sdnom = 0x1c194489 },
  426. +       [986 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000532b, .sdnom = 0x1c20920e },
  427. +       [987 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000532c, .sdnom = 0x1c27df93 },
  428. +       [988 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000532d, .sdnom = 0x1c2f2d18 },
  429. +       [989 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000532e, .sdnom = 0x1c367a9d },
  430. +       [990 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005320, .sdnom = 0x1c3dc822 },
  431. +       [991 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005331, .sdnom = 0x1c4515a7 },
  432. +       [992 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005332, .sdnom = 0x1c4c632c },
  433. +       [993 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005333, .sdnom = 0x1c53b0b1 },
  434. +       [994 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005334, .sdnom = 0x1c5afe35 },
  435. +       [995 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005335, .sdnom = 0x1c624bba },
  436. +       [996 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005536, .sdnom = 0x1bbc6aef },
  437. +       [997 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005537, .sdnom = 0x1bc38bf0 },
  438. +       [998 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005538, .sdnom = 0x1bcaacf2 },
  439. +       [999 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005539, .sdnom = 0x1bd1cdf4 },
  440. +       [1000 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000553a, .sdnom = 0x1bd8eef6 },
  441. +       [1001 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000553b, .sdnom = 0x1be00ff8 },
  442. +       [1002 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000553c, .sdnom = 0x1be730f9 },
  443. +       [1003 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000553d, .sdnom = 0x1bee51fb },
  444. +       [1004 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000553e, .sdnom = 0x1bf572fd },
  445. +       [1005 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005530, .sdnom = 0x1bfc93ff },
  446. +       [1006 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005541, .sdnom = 0x1c03b500 },
  447. +       [1007 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005542, .sdnom = 0x1c0ad602 },
  448. +       [1008 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005543, .sdnom = 0x1c11f704 },
  449. +       [1009 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005544, .sdnom = 0x1c191806 },
  450. +       [1010 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005545, .sdnom = 0x1c203908 },
  451. +       [1011 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005546, .sdnom = 0x1c275a09 },
  452. +       [1012 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005547, .sdnom = 0x1c2e7b0b },
  453. +       [1013 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005548, .sdnom = 0x1c359c0d },
  454. +       [1014 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005549, .sdnom = 0x1c3cbd0f },
  455. +       [1015 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000554a, .sdnom = 0x1c43de10 },
  456. +       [1016 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000554b, .sdnom = 0x1c4aff12 },
  457. +       [1017 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000554c, .sdnom = 0x1c522014 },
  458. +       [1018 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000554d, .sdnom = 0x1c594116 },
  459. +       [1019 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000554e, .sdnom = 0x1c606218 },
  460. +       [1020 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005740, .sdnom = 0x1bbe683c },
  461. +       [1021 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005751, .sdnom = 0x1bc55ecd },
  462. +       [1022 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005752, .sdnom = 0x1bcc555e },
  463. +       [1023 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005753, .sdnom = 0x1bd34bee },
  464. +       [1024 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005754, .sdnom = 0x1bda427f },
  465. +       [1025 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005755, .sdnom = 0x1be13910 },
  466. +       [1026 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005756, .sdnom = 0x1be82fa0 },
  467. +       [1027 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005757, .sdnom = 0x1bef2631 },
  468. +       [1028 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005758, .sdnom = 0x1bf61cc1 },
  469. +       [1029 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005759, .sdnom = 0x1bfd1352 },
  470. +       [1030 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000575a, .sdnom = 0x1c0409e3 },
  471. +       [1031 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000575b, .sdnom = 0x1c0b0073 },
  472. +       [1032 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000575c, .sdnom = 0x1c11f704 },
  473. +       [1033 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000575d, .sdnom = 0x1c18ed95 },
  474. +       [1034 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000575e, .sdnom = 0x1c1fe425 },
  475. +       [1035 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005750, .sdnom = 0x1c26dab6 },
  476. +       [1036 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005761, .sdnom = 0x1c2dd146 },
  477. +       [1037 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005762, .sdnom = 0x1c34c7d7 },
  478. +       [1038 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005763, .sdnom = 0x1c3bbe68 },
  479. +       [1039 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005764, .sdnom = 0x1c42b4f8 },
  480. +       [1040 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005765, .sdnom = 0x1c49ab89 },
  481. +       [1041 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005766, .sdnom = 0x1c50a21a },
  482. +       [1042 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005767, .sdnom = 0x1c5798aa },
  483. +       [1043 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005768, .sdnom = 0x1c5e8f3b },
  484. +       [1044 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005969, .sdnom = 0x1bc04e64 },
  485. +       [1045 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000596a, .sdnom = 0x1bc71c71 },
  486. +       [1046 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000596b, .sdnom = 0x1bcdea7f },
  487. +       [1047 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000596c, .sdnom = 0x1bd4b88c },
  488. +       [1048 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000596d, .sdnom = 0x1bdb8699 },
  489. +       [1049 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000596e, .sdnom = 0x1be254a7 },
  490. +       [1050 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005960, .sdnom = 0x1be922b4 },
  491. +       [1051 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005971, .sdnom = 0x1beff0c1 },
  492. +       [1052 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005972, .sdnom = 0x1bf6becf },
  493. +       [1053 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005973, .sdnom = 0x1bfd8cdc },
  494. +       [1054 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005974, .sdnom = 0x1c045ae9 },
  495. +       [1055 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005975, .sdnom = 0x1c0b28f7 },
  496. +       [1056 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005976, .sdnom = 0x1c11f704 },
  497. +       [1057 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005977, .sdnom = 0x1c18c511 },
  498. +       [1058 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005978, .sdnom = 0x1c1f931f },
  499. +       [1059 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005979, .sdnom = 0x1c26612c },
  500. +       [1060 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000597a, .sdnom = 0x1c2d2f39 },
  501. +       [1061 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000597b, .sdnom = 0x1c33fd47 },
  502. +       [1062 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000597c, .sdnom = 0x1c3acb54 },
  503. +       [1063 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000597d, .sdnom = 0x1c419961 },
  504. +       [1064 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x0000597e, .sdnom = 0x1c48676f },
  505. +       [1065 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005970, .sdnom = 0x1c4f357c },
  506. +       [1066 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005981, .sdnom = 0x1c560389 },
  507. +       [1067 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005982, .sdnom = 0x1c5cd197 },
  508. +       [1068 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b83, .sdnom = 0x1bc21ef0 },
  509. +       [1069 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b84, .sdnom = 0x1bc8c647 },
  510. +       [1070 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b85, .sdnom = 0x1bcf6d9e },
  511. +       [1071 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b86, .sdnom = 0x1bd614f5 },
  512. +       [1072 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b87, .sdnom = 0x1bdcbc4c },
  513. +       [1073 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b88, .sdnom = 0x1be363a3 },
  514. +       [1074 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b89, .sdnom = 0x1bea0afa },
  515. +       [1075 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b8a, .sdnom = 0x1bf0b251 },
  516. +       [1076 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b8b, .sdnom = 0x1bf759a8 },
  517. +       [1077 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b8c, .sdnom = 0x1bfe00ff },
  518. +       [1078 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b8d, .sdnom = 0x1c04a856 },
  519. +       [1079 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b8e, .sdnom = 0x1c0b4fad },
  520. +       [1080 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b80, .sdnom = 0x1c11f704 },
  521. +       [1081 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b91, .sdnom = 0x1c189e5b },
  522. +       [1082 - STFM1000_FREQUENCY_100KHZ_MIN] = { .tune1 = 0x00005b92, .sdnom = 0x1c1f45b2 },
  523. +};
  524. diff --git a/firmware/drivers/tuner/stfm1000.c b/firmware/drivers/tuner/stfm1000.c
  525. index 8626d4e..9c6c81c 100644
  526. --- a/firmware/drivers/tuner/stfm1000.c
  527. +++ b/firmware/drivers/tuner/stfm1000.c
  528. @@ -30,12 +30,17 @@
  529.  #include "fmradio.h"
  530.  #include "fmradio_i2c.h" /* physical interface driver */
  531.  #include "stfm1000.h"
  532. +#include "stfm1000-regs.h"
  533.  
  534. -#define STFM100_I2C_ADDR    0xc0
  535. +#include "stfm1000-tunetable.c"
  536. +
  537. +static int rev_id;
  538. +static int sdnominal_pivot;
  539. +static bool tuner_present = false;
  540.  
  541. -#define CHIPID  0x80
  542. +#define STFM100_I2C_ADDR    0xc0
  543.  
  544. -static int stfm1000_read_reg(uint8_t reg, uint32_t *val)
  545. +static int stfm1000_read(uint8_t reg, uint32_t *val)
  546.  {
  547.      uint8_t buf[4];
  548.      buf[0] = reg;
  549. @@ -46,7 +51,7 @@ static int stfm1000_read_reg(uint8_t reg, uint32_t *val)
  550.      return ret;
  551.  }
  552.  
  553. -static int stfm1000_write_reg(uint8_t reg, uint32_t val)
  554. +static int stfm1000_write(uint8_t reg, uint32_t val)
  555.  {
  556.      uint8_t buf[5];
  557.      buf[0] = reg;
  558. @@ -55,25 +60,466 @@ static int stfm1000_write_reg(uint8_t reg, uint32_t val)
  559.      return fmradio_i2c_write(STFM100_I2C_ADDR, buf, 5);
  560.  }
  561.  
  562. +static int stfm1000_write_masked(int reg, int val, int mask)
  563. +{
  564. +    uint32_t tmp;
  565. +
  566. +    stfm1000_read(reg, &tmp);
  567. +    stfm1000_write(reg, (val & mask) | (tmp & ~mask));
  568. +    return 0;
  569. +}
  570. +
  571. +static int stfm1000_set_bits(int reg, uint32_t value)
  572. +{
  573. +      return stfm1000_write_masked(reg, value, value);
  574. +}
  575. +
  576. +static int stfm1000_clear_bits(int reg, uint32_t value)
  577. +{
  578. +      return stfm1000_write_masked(reg, ~value, value);
  579. +}
  580. +
  581. +static void stfm1000_set_region(int region)
  582. +{
  583. +    const struct fm_region_data *rd = &fm_region_data[region];
  584. +
  585. +    if (rd->deemphasis == 50) {
  586. +        stfm1000_set_bits(STFM1000_INITIALIZATION2, STFM1000_DEEMPH_50_75B);
  587. +    } else {
  588. +        stfm1000_clear_bits(STFM1000_INITIALIZATION2, STFM1000_DEEMPH_50_75B);
  589. +    }
  590. +}
  591. +
  592. +
  593. +static int stfm1000_set_frequency(int freq)
  594. +{
  595. +    uint32_t freq100 = freq / 100;
  596. +    int tune_cap;
  597. +    int i2s_clock;
  598. +    int mix_reg;
  599. +    int if_freq, fe_freq;
  600. +    uint32_t tune1, sdnom, agc1;
  601. +    const struct stfm1000_tune1 *tp;
  602. +    int ret;
  603. +
  604. +    if_freq = 0;
  605. +    mix_reg = 1;
  606. +    switch (mix_reg) {
  607. +    case 0: if_freq = -2; break;
  608. +    case 1: if_freq = -1; break;
  609. +    case 2: if_freq =  0; break;
  610. +    case 3: if_freq =  1; break;
  611. +    case 4: if_freq =  2; break;
  612. +    }
  613. +
  614. +    fe_freq = freq100 + if_freq;
  615. +
  616. +    /* clamp into range */
  617. +    if (fe_freq < STFM1000_FREQUENCY_100KHZ_MIN)
  618. +        fe_freq = STFM1000_FREQUENCY_100KHZ_MIN;
  619. +    else if (fe_freq > STFM1000_FREQUENCY_100KHZ_MAX)
  620. +        fe_freq = STFM1000_FREQUENCY_100KHZ_MAX;
  621. +
  622. +    tp = &stfm1000_tune1_table[fe_freq - STFM1000_FREQUENCY_100KHZ_MIN];
  623. +
  624. +    /* bits [14:0], [20:18] */
  625. +    tune1 = (tp->tune1 & 0x7fff) | (mix_reg << 18);
  626. +    sdnom = tp->sdnom;
  627. +
  628. +    agc1 = (rev_id == STFM1000_CHIP_REV_TA2) ? 0x0400 : 0x2200;
  629. +
  630. +    ret = stfm1000_write_masked(STFM1000_AGC_CONTROL1, agc1, 0x3f00);
  631. +    if (ret != 0)
  632. +        goto err;
  633. +
  634. +    ret = stfm1000_write_masked(STFM1000_TUNE1, tune1, 0xFFFF7FFF);      /* do not set bit-15 */
  635. +    if (ret != 0)
  636. +        goto err;
  637. +
  638. +    /* keep this around */
  639. +    sdnominal_pivot = sdnom;
  640. +
  641. +    ret = stfm1000_write(STFM1000_SDNOMINAL, sdnom);
  642. +    if (ret != 0)
  643. +        goto err;
  644. +
  645. +    /* fix for seek-not-stopping on alternate tunings */
  646. +    ret = stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  647. +    if (ret != 0)
  648. +        goto err;
  649. +
  650. +    ret = stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  651. +    if (ret != 0)
  652. +        goto err;
  653. +
  654. +    ret = stfm1000_set_bits(STFM1000_INITIALIZATION2, STFM1000_DRI_CLK_EN);
  655. +    if (ret != 0)
  656. +        goto err;
  657. +
  658. +    /* 6MHz spur fix */
  659. +    if ((freq100 >=  778 && freq100 <=  782) ||
  660. +        (freq100 >=  838 && freq100 <=  842) ||
  661. +        (freq100 >=  898 && freq100 <=  902) ||
  662. +        (freq100 >=  958 && freq100 <=  962) ||
  663. +        (freq100 >= 1018 && freq100 <= 1022) ||
  664. +        (freq100 >= 1078 && freq100 <= 1080))
  665. +        i2s_clock = 5;  /* 4.8MHz */
  666. +    else
  667. +        i2s_clock = 4;
  668. +
  669. +    ret = stfm1000_write_masked(STFM1000_DATAPATH,
  670. +        STFM1000_SAI_CLK_DIV(i2s_clock), STFM1000_SAI_CLK_DIV_MASK);
  671. +    if (ret != 0)
  672. +        goto err;
  673. +
  674. +    ret = stfm1000_set_bits(STFM1000_INITIALIZATION2, STFM1000_DRI_CLK_EN);
  675. +    if (ret != 0)
  676. +        goto err;
  677. +
  678. +    if (tune1 & 0xf)
  679. +        ret = stfm1000_set_bits(STFM1000_CLK1, STFM1000_ENABLE_TAPDELAYFIX);
  680. +    else
  681. +        ret = stfm1000_clear_bits(STFM1000_CLK1, STFM1000_ENABLE_TAPDELAYFIX);
  682. +
  683. +    if (ret != 0)
  684. +        goto err;
  685. +
  686. +    tune_cap = 4744806 - (4587 * freq100);
  687. +    if (tune_cap < 4)
  688. +        tune_cap = 4;
  689. +    ret = stfm1000_write_masked(STFM1000_LNA, STFM1000_ANTENNA_TUNECAP(tune_cap),
  690. +        STFM1000_ANTENNA_TUNECAP_MASK);
  691. +    if (ret != 0)
  692. +        goto err;
  693. +
  694. +    return 0;
  695. +err:
  696. +    return -1;
  697. +}
  698. +
  699.  void stfm1000_dbg_info(struct stfm1000_dbg_info *nfo)
  700.  {
  701.      memset(nfo, 0, sizeof(struct stfm1000_dbg_info));
  702. -    stfm1000_read_reg(CHIPID, &nfo->chipid);
  703. +    stfm1000_read(STFM1000_TUNE1, &nfo->tune1);
  704. +    stfm1000_read(STFM1000_SDNOMINAL, &nfo->sdnominal);
  705. +    stfm1000_read(STFM1000_PILOTTRACKING, &nfo->pilottracking);
  706. +    stfm1000_read(STFM1000_RSSI_TONE, &nfo->rssi_tone);
  707. +    stfm1000_read(STFM1000_PILOTCORRECTION, &nfo->pilotcorrection);
  708. +    stfm1000_read(STFM1000_CHIPID, &nfo->chipid);
  709. +}
  710. +
  711. +static void stfm1000_dp_enable(bool enable)
  712. +{
  713. +    if (enable) {
  714. +        stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_DP_EN);
  715. +        sleep(1);
  716. +        stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  717. +        stfm1000_clear_bits(STFM1000_AGC_CONTROL1, STFM1000_B2_BYPASS_AGC_CTL);
  718. +        stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  719. +    } else {
  720. +        stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  721. +        stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_DP_EN);
  722. +        stfm1000_set_bits(STFM1000_AGC_CONTROL1, STFM1000_B2_BYPASS_AGC_CTL);
  723. +        stfm1000_clear_bits(STFM1000_PILOTTRACKING, STFM1000_B2_PILOTTRACKING_EN);
  724. +        stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  725. +    }
  726. +}
  727. +
  728. +static void stfm_dri_enable(bool enable)
  729. +{
  730. +    if (enable) {
  731. +        stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_SAI_EN);
  732. +    } else {
  733. +        stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_SAI_EN);
  734. +    }
  735. +}
  736. +
  737. +static int stfm1000_set_channel_filter(void)
  738. +{
  739. +    int ret;
  740. +    int bypass_setting;
  741. +
  742. +      /* get near channel amplitude */
  743. +      ret = stfm1000_write_masked(STFM1000_INITIALIZATION3,
  744. +            STFM1000_B2_NEAR_CHAN_MIX(0x01),
  745. +            STFM1000_B2_NEAR_CHAN_MIX_MASK);
  746. +      if (ret != 0)
  747. +            return ret;
  748. +
  749. +      sleep(10 * HZ / 1000); /* wait for the signal quality to settle */
  750. +
  751. +      bypass_setting = 0;
  752. +
  753. +#if 0
  754. +      ret = stfm1000_read(STFM1000_SIGNALQUALITY, &tmp);
  755. +      if (ret != 0)
  756. +            return ret;
  757. +
  758. +      sig_qual = (tmp & STFM1000_NEAR_CHAN_AMPLITUDE_MASK) >>
  759. +            STFM1000_NEAR_CHAN_AMPLITUDE_SHIFT;
  760. +
  761. +      /* check near channel amplitude vs threshold */
  762. +      if (sig_qual < stfm1000->adj_chan_th) {
  763. +            /* get near channel amplitude again */
  764. +            ret = stfm1000_write_masked(stfm1000, STFM1000_INITIALIZATION3,
  765. +                  STFM1000_B2_NEAR_CHAN_MIX(0x05),
  766. +                  STFM1000_B2_NEAR_CHAN_MIX_MASK);
  767. +            if (ret != 0)
  768. +                  return ret;
  769. +
  770. +            msleep(10); /* wait for the signal quality to settle */
  771. +
  772. +            ret = stfm1000_read(stfm1000, STFM1000_SIGNALQUALITY, &tmp);
  773. +            if (ret != 0)
  774. +                  return ret;
  775. +
  776. +            sig_qual = (tmp & STFM1000_NEAR_CHAN_AMPLITUDE_MASK) >>
  777. +                  STFM1000_NEAR_CHAN_AMPLITUDE_SHIFT;
  778. +
  779. +            if (sig_qual < stfm1000->adj_chan_th)
  780. +                  bypass_setting = 2;
  781. +      }
  782. +#endif
  783. +      /* set filter settings */
  784. +      ret = stfm1000_write_masked(STFM1000_INITIALIZATION1,
  785. +            STFM1000_B2_BYPASS_FILT(bypass_setting),
  786. +            STFM1000_B2_BYPASS_FILT_MASK);
  787. +      if (ret != 0)
  788. +            return ret;
  789. +
  790. +      return 0;
  791. +}
  792. +
  793. +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*(x)))
  794. +
  795. +static int stfm1000_track_pilot(void)
  796. +{
  797. +    static const struct {
  798. +        int delay;
  799. +        uint32_t value;
  800. +    } track_table[] = {
  801. +        { .delay = 10, .value = 0x81b6 },
  802. +        { .delay =  6, .value = 0x82a5 },
  803. +        { .delay =  6, .value = 0x8395 },
  804. +        { .delay =  8, .value = 0x8474 },
  805. +        { .delay = 20, .value = 0x8535 },
  806. +        { .delay = 50, .value = 0x8632 },
  807. +        { .delay =  0, .value = 0x8810 },
  808. +    };
  809. +    int i;
  810. +    int ret;
  811. +
  812. +    for (i = 0; i < ARRAY_SIZE(track_table); i++) {
  813. +        ret = stfm1000_write(STFM1000_PILOTTRACKING, track_table[i].value);
  814. +        if (ret != 0)
  815. +            return ret;
  816. +
  817. +        if (i < ARRAY_SIZE(track_table) - 1)      /* last one no delay */
  818. +            sleep(track_table[i].delay * HZ / 1000);
  819. +    }
  820. +
  821. +    return 0;
  822. +}
  823. +
  824. +static int stfm1000_optimise_channel(void)
  825. +{
  826. +    int ret;
  827. +
  828. +      ret = stfm1000_set_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  829. +      if (ret != 0)
  830. +            return ret;
  831. +
  832. +      ret = stfm1000_write(STFM1000_PILOTTRACKING,
  833. +            STFM1000_B2_PILOTTRACKING_EN |
  834. +            STFM1000_B2_PILOTLPF_TIMECONSTANT(0x01) |
  835. +            STFM1000_B2_PFDSCALE(0x0B) |
  836. +            STFM1000_B2_PFDFILTER_SPEEDUP(0x06));     /* 0x000081B6 */
  837. +      if (ret != 0)
  838. +            return ret;
  839. +
  840. +      ret = stfm1000_set_channel_filter();
  841. +      if (ret != 0)
  842. +            return ret;
  843. +#if 0
  844. +      ret = SD_Look_For_Pilot(stfm1000);
  845. +      if (ret != 0)
  846. +            return ret;
  847. +#endif
  848. +//      if (stfm1000->pilot_present) {
  849. +            ret = stfm1000_track_pilot();
  850. +            if (ret != 0)
  851. +                  return ret;
  852. +//      }
  853. +
  854. +      ret = stfm1000_clear_bits(STFM1000_DATAPATH, STFM1000_DB_ACCEPT);
  855. +      if (ret != 0)
  856. +            return ret;
  857. +
  858. +      return 0;
  859.  }
  860.  
  861.  void stfm1000_init(void)
  862.  {
  863. +    uint32_t val;
  864. +
  865. +    /* get revision id */
  866. +    stfm1000_read(STFM1000_CHIPID, &val);
  867. +    rev_id = val & 0xFF;
  868. +   
  869. +    /* send TB2 init sequence */
  870. +    stfm1000_write(STFM1000_REF, 0x00200000);
  871. +    sleep(20 * HZ / 1000);
  872. +    stfm1000_write(STFM1000_DATAPATH, 0x00010210);
  873. +    stfm1000_write(STFM1000_TUNE1, 0x0004CF01);
  874. +    stfm1000_write(STFM1000_SDNOMINAL, 0x1C5EBCF0);
  875. +    stfm1000_write(STFM1000_PILOTTRACKING, 0x000001B6);
  876. +    stfm1000_write(STFM1000_INITIALIZATION1, 0x9fb80008);
  877. +    stfm1000_write(STFM1000_INITIALIZATION2, 0x8516e444 | STFM1000_DEEMPH_50_75B);
  878. +    stfm1000_write(STFM1000_INITIALIZATION3, 0x1402190b);
  879. +    stfm1000_write(STFM1000_INITIALIZATION4, 0x525bf052);
  880. +    stfm1000_write(STFM1000_INITIALIZATION5, 0x1000d106);
  881. +    stfm1000_write(STFM1000_INITIALIZATION6, 0x000062cb);
  882. +    stfm1000_write(STFM1000_AGC_CONTROL1, 0x1BCB2202);
  883. +    stfm1000_write(STFM1000_AGC_CONTROL2, 0x000020F0);
  884. +    stfm1000_write(STFM1000_CLK1, 0x10000000);
  885. +    stfm1000_write(STFM1000_CLK1, 0x20000000);
  886. +    stfm1000_write(STFM1000_CLK1, 0x00000000);
  887. +    stfm1000_write(STFM1000_CLK2, 0x7f000000);
  888. +    stfm1000_write(STFM1000_REF, 0x00B8222D);
  889. +    stfm1000_write(STFM1000_CLK1, 0x30000000);
  890. +    stfm1000_write(STFM1000_CLK1, 0x30002000);
  891. +    stfm1000_write(STFM1000_CLK1, 0x10002000);
  892. +    stfm1000_write(STFM1000_LNA, 0x0D080009);
  893. +    sleep(10 * HZ / 1000);
  894. +    stfm1000_write(STFM1000_MIXFILT, 0x00008000);
  895. +    stfm1000_write(STFM1000_MIXFILT, 0x00000000);
  896. +    stfm1000_write(STFM1000_MIXFILT, 0x00007205);
  897. +    stfm1000_write(STFM1000_ADC, 0x001B3282);
  898. +    stfm1000_write(STFM1000_ATTENTION, 0x0000003F);
  899. +   
  900. +    stfm1000_dp_enable(true);
  901. +    stfm_dri_enable(true);
  902. +}
  903. +
  904. +static void stfm1000_sleep(bool sleep)
  905. +{
  906. +    (void)sleep;
  907. +    /* no implementation yet */
  908. +}
  909. +
  910. +static int stfm1000_rssi(void)
  911. +{
  912. +    uint32_t rssi_dc_est;
  913. +    int rssi_mantissa, rssi_exponent, rssi_decoded;
  914. +    int prssi;
  915. +    int rssi_log;
  916. +
  917. +    stfm1000_read(STFM1000_RSSI_TONE, &rssi_dc_est);
  918. +
  919. +    rssi_mantissa = (rssi_dc_est & 0xffe0) >> 5;    /* 11Msb */
  920. +    rssi_exponent = rssi_dc_est & 0x001f;     /* 5 lsb */
  921. +    rssi_decoded = (uint32_t)rssi_mantissa << rssi_exponent;
  922. +
  923. +    /* Convert Rsst to 10log(Rssi) */
  924. +    for (prssi = 20; prssi > 0; prssi--)
  925. +        if (rssi_decoded >= (1 << prssi))
  926. +            break;
  927. +
  928. +    rssi_log = (3 * rssi_decoded >> prssi) + (3 * prssi - 3);
  929. +
  930. +    /* clamp to positive */
  931. +    if (rssi_log < 0)
  932. +        rssi_log = 0;
  933. +
  934. +    /* Compensate for errors in truncation/approximation by adding 1 */
  935. +    rssi_log++;
  936. +
  937. +    return rssi_log;
  938. +}
  939. +
  940. +static bool stfm1000_tuned(void)
  941. +{
  942. +    uint32_t tmp;
  943. +    int pilot;
  944. +
  945. +    /* get pilot */
  946. +    stfm1000_read(STFM1000_PILOTCORRECTION, &tmp);
  947. +    pilot = (tmp & STFM1000_PILOTEST_TB2_MASK) >> STFM1000_PILOTEST_TB2_SHIFT;
  948. +
  949. +    /* check pilot and signal strength */
  950. +    return (pilot >= 0x1E) && (pilot < 0x80) && (stfm1000_rssi() > 28);
  951.  }
  952.  
  953.  int stfm1000_set(int setting, int value)
  954.  {
  955. -    (void) setting;
  956. -    (void) value;
  957. -    return -1;
  958. +    int val = 0;
  959. +
  960. +    switch (setting) {
  961. +    case RADIO_SLEEP:
  962. +        stfm1000_sleep(value);
  963. +        break;
  964. +
  965. +    case RADIO_FREQUENCY:
  966. +        stfm1000_set_frequency(value / 1000);
  967. +        stfm1000_optimise_channel();
  968. +        break;
  969. +
  970. +    case RADIO_SCAN_FREQUENCY:
  971. +        stfm1000_set_frequency(value / 1000);
  972. +        val = stfm1000_tuned();
  973. +        break;
  974. +
  975. +    case RADIO_MUTE:
  976. +        /* no implementation yet */
  977. +        break;
  978. +
  979. +    case RADIO_REGION:
  980. +        stfm1000_set_region(value);
  981. +        break;
  982. +
  983. +    case RADIO_FORCE_MONO:
  984. +        /* no implementation yet */
  985. +        break;
  986. +       
  987. +    default:
  988. +        val = -1;
  989. +        break;
  990. +    }
  991. +
  992. +    return val;
  993.  }
  994.  
  995.  int stfm1000_get(int setting)
  996.  {
  997. -    (void) setting;
  998. -    return -1;
  999. -}
  1000. \ No newline at end of file
  1001. +    int val = -1; /* default for unsupported query */
  1002. +
  1003. +    switch (setting) {
  1004. +
  1005. +    case RADIO_PRESENT:
  1006. +        val = true;
  1007. +        break;
  1008. +
  1009. +    case RADIO_TUNED:
  1010. +        val = stfm1000_tuned();
  1011. +        break;
  1012. +
  1013. +    case RADIO_STEREO:
  1014. +        val = 0;
  1015. +        break;
  1016. +#if 1
  1017. +    case RADIO_RSSI:
  1018. +        val = stfm1000_rssi();
  1019. +        break;
  1020. +
  1021. +    case RADIO_RSSI_MIN:
  1022. +        val = 0;
  1023. +        break;
  1024. +
  1025. +    case RADIO_RSSI_MAX:
  1026. +        val = 70;
  1027. +        break;
  1028. +#endif
  1029. +    }
  1030. +
  1031. +    return val;
  1032. +}
  1033. diff --git a/firmware/export/stfm1000.h b/firmware/export/stfm1000.h
  1034. index 6c01d63..62a1dd9 100644
  1035. --- a/firmware/export/stfm1000.h
  1036. +++ b/firmware/export/stfm1000.h
  1037. @@ -31,6 +31,11 @@
  1038.  
  1039.  struct stfm1000_dbg_info
  1040.  {
  1041. +    uint32_t tune1;
  1042. +    uint32_t sdnominal;
  1043. +    uint32_t pilottracking;
  1044. +    uint32_t rssi_tone;
  1045. +    uint32_t pilotcorrection;
  1046.      uint32_t chipid;
  1047.  };
  1048.  

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right