Fix remote screen check in graphic equalizer, so that it can be used on logf-enabled...
[Rockbox.git] / firmware / tuner_samsung.c
blobb0887d0d7a256b9c746c8e5fd524363ea1416cc2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include <stdbool.h>
22 #include <stdlib.h>
23 #include "config.h"
24 #include "tuner.h" /* tuner abstraction interface */
25 #include "fmradio.h" /* physical interface driver */
26 #include "mpeg.h"
27 #include "sound.h"
29 #define DEFAULT_IN1 0x100003 /* Mute */
30 #define DEFAULT_IN2 0x140884 /* 5kHz, 7.2MHz crystal */
31 #define PLL_FREQ_STEP 10000
33 static int fm_in1;
34 static int fm_in2;
36 /* tuner abstraction layer: set something to the tuner */
37 void samsung_set(int setting, int value)
39 switch(setting)
41 case RADIO_SLEEP:
42 if (!value)
43 { /* wakeup: just unit */
44 fm_in1 = DEFAULT_IN1;
45 fm_in2 = DEFAULT_IN2;
46 fmradio_set(1, fm_in1);
47 fmradio_set(2, fm_in2);
49 /* else we have no sleep mode? */
50 break;
52 case RADIO_FREQUENCY:
54 int pll_cnt;
55 #if CONFIG_CODEC == MAS3587F
56 /* Shift the MAS internal clock away for certain frequencies to
57 * avoid interference. */
58 int pitch = 1000;
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. */
65 if (value < if_freq)
67 if (if_freq - value < 300000)
68 pitch = 1003 - (if_freq - value) / 100000;
70 else
72 if (value - if_freq < 300000)
73 pitch = 997 + (value - if_freq) / 100000;
75 sound_set_pitch(pitch);
76 #endif
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);
90 break;
93 case RADIO_MUTE:
94 fm_in1 = (fm_in1 & 0xfffffffe) | (value?1:0);
95 fmradio_set(1, fm_in1);
96 break;
98 case RADIO_IF_MEASUREMENT:
99 fm_in1 = (fm_in1 & 0xfffffffb) | (value?4:0);
100 fmradio_set(1, fm_in1);
101 break;
103 case RADIO_SENSITIVITY:
104 fm_in2 = (fm_in2 & 0xffff9fff) | ((value & 3) << 13);
105 fmradio_set(2, fm_in2);
106 break;
108 case RADIO_FORCE_MONO:
109 fm_in2 = (fm_in2 & 0xfffffffb) | (value?0:4);
110 fmradio_set(2, fm_in2);
111 break;
115 /* tuner abstraction layer: read something from the tuner */
116 int samsung_get(int setting)
118 int val = -1;
119 switch(setting)
121 case RADIO_PRESENT:
122 fmradio_set(2, 0x140885); /* 5kHz, 7.2MHz crystal, test mode 1 */
123 val = (fmradio_read(0) == 0x140885);
124 break;
126 case RADIO_TUNED:
127 val = fmradio_read(3);
128 val = abs(10700 - ((val & 0x7ffff) / 8)) < 50; /* convert to kHz */
129 break;
131 case RADIO_STEREO:
132 val = fmradio_read(3);
133 val = ((val & 0x100000) ? true : false);
135 return val;