1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Tuner "middleware" for Samsung S1A0903X01 chip
11 * Copyright (C) 2003 Linus Nielsen Feltzing
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
24 #include "tuner.h" /* tuner abstraction interface */
25 #include "fmradio.h" /* physical interface driver */
29 #define DEFAULT_IN1 0x100003 /* Mute */
30 #define DEFAULT_IN2 0x140884 /* 5kHz, 7.2MHz crystal */
31 #define PLL_FREQ_STEP 10000
36 /* tuner abstraction layer: set something to the tuner */
37 void samsung_set(int setting
, int value
)
43 { /* wakeup: just unit */
46 fmradio_set(1, fm_in1
);
47 fmradio_set(2, fm_in2
);
49 /* else we have no sleep mode? */
55 #if CONFIG_CODEC == MAS3587F
56 /* Shift the MAS internal clock away for certain frequencies to
57 * avoid interference. */
60 /* 4th harmonic falls in the FM frequency range */
61 int if_freq
= 4 * mpeg_get_mas_pllfreq();
63 /* shift the mas harmonic >= 300 kHz away using the direction
64 * which needs less shifting. */
67 if (if_freq
- value
< 300000)
68 pitch
= 1003 - (if_freq
- value
) / 100000;
72 if (value
- if_freq
< 300000)
73 pitch
= 997 + (value
- if_freq
) / 100000;
75 sound_set_pitch(pitch
);
77 /* We add the standard Intermediate Frequency 10.7MHz
78 ** before calculating the divisor
79 ** The reference frequency is set to 50kHz, and the VCO
80 ** output is prescaled by 2.
83 pll_cnt
= (value
+ 10700000) / (PLL_FREQ_STEP
/2) / 2;
85 /* 0x100000 == FM mode
86 ** 0x000002 == Microprocessor controlled Mute
88 fm_in1
= (fm_in1
& 0xfff00007) | (pll_cnt
<< 3);
89 fmradio_set(1, fm_in1
);
94 fm_in1
= (fm_in1
& 0xfffffffe) | (value
?1:0);
95 fmradio_set(1, fm_in1
);
98 case RADIO_IF_MEASUREMENT
:
99 fm_in1
= (fm_in1
& 0xfffffffb) | (value
?4:0);
100 fmradio_set(1, fm_in1
);
103 case RADIO_SENSITIVITY
:
104 fm_in2
= (fm_in2
& 0xffff9fff) | ((value
& 3) << 13);
105 fmradio_set(2, fm_in2
);
108 case RADIO_FORCE_MONO
:
109 fm_in2
= (fm_in2
& 0xfffffffb) | (value
?0:4);
110 fmradio_set(2, fm_in2
);
115 /* tuner abstraction layer: read something from the tuner */
116 int samsung_get(int setting
)
122 fmradio_set(2, 0x140885); /* 5kHz, 7.2MHz crystal, test mode 1 */
123 val
= (fmradio_read(0) == 0x140885);
127 val
= fmradio_read(3);
128 val
= abs(10700 - ((val
& 0x7ffff) / 8)) < 50; /* convert to kHz */
132 val
= fmradio_read(3);
133 val
= ((val
& 0x100000) ? true : false);