Sync usage with man page.
[netbsd-mini2440.git] / sys / dev / ic / tea5757.c
blob1ed99e4597cad70f2f701c6d00c3d45eae69eadb
1 /* $NetBSD: tea5757.c,v 1.2.6.4 2005/11/10 14:04:15 skrll Exp $ */
2 /* $OpenBSD: tea5757.c,v 1.3 2002/01/07 18:32:19 mickey Exp $ */
4 /*
5 * Copyright (c) 2001 Vladimir Popov <jumbo@narod.ru>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /* Implementation of most common TEA5757 routines */
32 * Philips TEA5757H Self Tuned Radio
33 * http://www.semiconductors.philips.com/pip/TEA5757H
35 * The TEA5757; TEA5759 is a 44-pin integrated AM/FM stereo radio circuit.
36 * The radio part is based on the TEA5712.
38 * The TEA5757 is used in FM-standards in which the local oscillator
39 * frequency is above the radio frequency (e.g. European and American
40 * standards). The TEA5759 is the version in which the oscillator frequency
41 * is below the radio frequency (e.g. Japanese standard).
43 * The TEA5757; TEA5759 radio has a bus which consists of three wires:
44 * BUS-CLOCK: software driven clock input
45 * DATA: data input/output
46 * WRITE-ENABLE: write/read input
48 * The TEA5757; TEA5759 has a 25-bit shift register.
50 * The chips are used in Radiotrack II, Guillemot Maxi Radio FM 2000,
51 * Gemtek PCI cards and most Mediaforte FM tuners and sound cards with
52 * integrated FM tuners.
55 #include <sys/cdefs.h>
56 __KERNEL_RCSID(0, "$NetBSD: tea5757.c,v 1.2.6.4 2005/11/10 14:04:15 skrll Exp $");
58 #include <sys/param.h>
59 #include <sys/radioio.h>
61 #include <dev/ic/tea5757.h>
64 * Convert frequency to hardware representation
66 u_int32_t
67 tea5757_encode_freq(u_int32_t freq, int tea5759)
69 if (tea5759)
70 freq -= IF_FREQ;
71 else
72 freq += IF_FREQ;
75 * NO FLOATING POINT!
77 freq *= 10;
78 freq /= 125;
80 return freq & TEA5757_FREQ;
84 * Convert frequency from hardware representation
86 u_int32_t
87 tea5757_decode_freq(u_int32_t freq, int tea5759)
89 freq &= TEA5757_FREQ;
90 freq *= 125; /* 12.5 kHz */
91 freq /= 10;
93 if (tea5759)
94 freq += IF_FREQ;
95 else
96 freq -= IF_FREQ;
98 return freq;
102 * Hardware search
104 void
105 tea5757_search(struct tea5757_t *tea, u_int32_t stereo, u_int32_t lock, int dir)
107 u_int32_t reg;
108 u_int co = 0;
110 reg = stereo | lock | TEA5757_SEARCH_START;
111 reg |= dir ? TEA5757_SEARCH_UP : TEA5757_SEARCH_DOWN;
112 tea5757_hardware_write(tea, reg);
114 DELAY(TEA5757_ACQUISITION_DELAY);
116 do {
117 DELAY(TEA5757_WAIT_DELAY);
118 reg = tea->read(tea->iot, tea->ioh, tea->offset);
119 } while ((reg & TEA5757_FREQ) == 0 && ++co < 200);
122 void
123 tea5757_hardware_write(struct tea5757_t *tea, u_int32_t data)
125 int i = TEA5757_REGISTER_LENGTH;
127 tea->init(tea->iot, tea->ioh, tea->offset, 0);
129 while (i--)
130 if (data & (1 << i))
131 tea->write_bit(tea->iot, tea->ioh, tea->offset, 1);
132 else
133 tea->write_bit(tea->iot, tea->ioh, tea->offset, 0);
135 tea->rset(tea->iot, tea->ioh, tea->offset, 0);
138 u_int32_t
139 tea5757_set_freq(struct tea5757_t *tea, u_int32_t stereo, u_int32_t lock, u_int32_t freq)
141 u_int32_t data = 0ul;
143 if (freq < MIN_FM_FREQ)
144 freq = MIN_FM_FREQ;
145 if (freq > MAX_FM_FREQ)
146 freq = MAX_FM_FREQ;
148 data |= tea5757_encode_freq(freq, tea->flags & TEA5757_TEA5759);
149 data |= stereo | lock | TEA5757_SEARCH_END;
150 tea5757_hardware_write(tea, data);
152 return freq;
155 u_int32_t
156 tea5757_encode_lock(u_int8_t lock)
158 if (lock < 8)
159 return TEA5757_S005;
160 if (lock < 15)
161 return TEA5757_S010;
162 if (lock < 51)
163 return TEA5757_S030;
164 return TEA5757_S150;
167 u_int8_t
168 tea5757_decode_lock(u_int32_t lock)
170 switch (lock) {
171 case TEA5757_S005:
172 return 5;
173 case TEA5757_S010:
174 return 10;
175 break;
176 case TEA5757_S030:
177 return 30;
178 case TEA5757_S150:
179 default:
180 return 150;