1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Tuner "middleware" for Samsung S1A0903X01 chip
11 * Copyright (C) 2003 Linus Nielsen Feltzing
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
27 #include "tuner.h" /* tuner abstraction interface */
28 #include "fmradio.h" /* physical interface driver */
33 #define DEFAULT_IN1 0x100003 /* Mute */
34 #define DEFAULT_IN2 0x140884 /* 5kHz, 7.2MHz crystal */
35 #define PLL_FREQ_STEP 10000
39 static int fm_present
= -1; /* unknown */
41 /* tuner abstraction layer: set something to the tuner */
42 int s1a0903x01_set(int setting
, int value
)
50 { /* wakeup: just unit */
53 fmradio_set(1, fm_in1
);
54 fmradio_set(2, fm_in2
);
56 /* else we have no sleep mode? */
62 #if CONFIG_CODEC == MAS3587F
63 /* Shift the MAS internal clock away for certain frequencies to
64 * avoid interference. */
67 /* 4th harmonic falls in the FM frequency range */
68 int if_freq
= 4 * mas_get_pllfreq();
70 /* shift the mas harmonic >= 300 kHz away using the direction
71 * which needs less shifting. */
74 if (if_freq
- value
< 300000)
75 pitch
= 1003 - (if_freq
- value
) / 100000;
79 if (value
- if_freq
< 300000)
80 pitch
= 997 + (value
- if_freq
) / 100000;
82 sound_set_pitch(pitch
);
84 /* We add the standard Intermediate Frequency 10.7MHz
85 ** before calculating the divisor
86 ** The reference frequency is set to 50kHz, and the VCO
87 ** output is prescaled by 2.
90 pll_cnt
= (value
+ 10700000) / (PLL_FREQ_STEP
/2) / 2;
92 /* 0x100000 == FM mode
93 ** 0x000002 == Microprocessor controlled Mute
95 fm_in1
= (fm_in1
& 0xfff00007) | (pll_cnt
<< 3);
96 fmradio_set(1, fm_in1
);
100 case RADIO_SCAN_FREQUENCY
:
101 /* Tune in and delay */
102 s1a0903x01_set(RADIO_FREQUENCY
, value
);
104 /* Start IF measurement */
106 fmradio_set(1, fm_in1
);
108 val
= s1a0903x01_get(RADIO_TUNED
);
112 fm_in1
= (fm_in1
& 0xfffffffe) | (value
?1:0);
113 fmradio_set(1, fm_in1
);
116 case RADIO_FORCE_MONO
:
117 fm_in2
= (fm_in2
& 0xfffffffb) | (value
?0:4);
118 fmradio_set(2, fm_in2
);
120 /* NOTE: These were only zeroed when starting the tuner from OFF
121 but the default values already set them to 0. */
123 case S1A0903X01_IF_MEASUREMENT
:
124 fm_in1
= (fm_in1
& 0xfffffffb) | (value
?4:0);
125 fmradio_set(1, fm_in1
);
128 case S1A0903X01_SENSITIVITY
:
129 fm_in2
= (fm_in2
& 0xffff9fff) | ((value
& 3) << 13);
130 fmradio_set(2, fm_in2
);
140 /* tuner abstraction layer: read something from the tuner */
141 int s1a0903x01_get(int setting
)
147 if (fm_present
== -1)
149 #ifdef HAVE_TUNER_PWR_CTRL
150 bool fmstatus
= tuner_power(true);
152 /* 5kHz, 7.2MHz crystal, test mode 1 */
153 fmradio_set(2, 0x140885);
154 fm_present
= (fmradio_read(0) == 0x140885);
155 #ifdef HAVE_TUNER_PWR_CTRL
165 val
= fmradio_read(3);
166 val
= abs(10700 - ((val
& 0x7ffff) / 8)) < 50; /* convert to kHz */
170 val
= fmradio_read(3);
171 val
= ((val
& 0x100000) ? true : false);