FreeBSD/Linux Kernel Cross Reference
sys/dev/ic/lm700x.c
1 /* $NetBSD: lm700x.c,v 1.2 2003/07/14 15:47:11 lukem Exp $ */
2 /* $OpenBSD: lm700x.c,v 1.2 2001/12/06 16:28:18 mickey Exp $ */
3
4 /*
5 * Copyright (c) 2001 Vladimir Popov <jumbo@narod.ru>
6 * All rights reserved.
7 *
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.
16 *
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.
27 */
28
29 /* Implementation of most common lm700x routines */
30
31 /*
32 * Sanyo LM7001 Direct PLL Frequency Synthesizer
33 * ??? See http://www.redsword.com/tjacobs/geeb/fmcard.htm
34 *
35 * The LM7001J and LM7001JM (used in Aztech/PackardBell cards) are PLL
36 * frequency synthesizer LSIs for tuners. These LSIs are software compatible
37 * with LM7000 (used in Radiotrack, Radioreveal RA300, some Mediaforte cards),
38 * but do not include an IF calculation circuit.
39 *
40 * The FM VCO circuit includes a high-speed programmable divider that can
41 * divide directly.
42 *
43 * Features:
44 * Seven reference frequencies: 1, 5, 9, 10, 25, 50, and 100 kHz;
45 * Band-switching outputs (3 bits);
46 * Controller clock output (400 kHz);
47 * Serial input circuit for data input (using the CE, CL and DATA pins).
48 *
49 * The LM7001J and LM7001JM have a 24-bit shift register.
50 */
51
52 #include <sys/cdefs.h>
53 __KERNEL_RCSID(0, "$NetBSD: lm700x.c,v 1.2 2003/07/14 15:47:11 lukem Exp $");
54
55 #include <sys/param.h>
56 #include <sys/radioio.h>
57
58 #include <dev/ic/lm700x.h>
59
60 u_int32_t
61 lm700x_encode_freq(u_int32_t nfreq, u_int32_t rf)
62 {
63 nfreq += IF_FREQ;
64 nfreq /= lm700x_decode_ref(rf);
65 return nfreq;
66 }
67
68 void
69 lm700x_hardware_write(struct lm700x_t *lm, u_int32_t data, u_int32_t addon)
70 {
71 int i;
72
73 lm->init(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
74
75 for (i = 0; i < LM700X_REGISTER_LENGTH; i++)
76 if (data & (1 << i)) {
77 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
78 lm->wocl | addon);
79 DELAY(LM700X_WRITE_DELAY);
80 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
81 lm->woch | addon);
82 DELAY(LM700X_WRITE_DELAY);
83 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
84 lm->wocl | addon);
85 } else {
86 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
87 lm->wzcl | addon);
88 DELAY(LM700X_WRITE_DELAY);
89 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
90 lm->wzch | addon);
91 DELAY(LM700X_WRITE_DELAY);
92 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
93 lm->wzcl | addon);
94 }
95
96 lm->rset(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
97 }
98
99 u_int32_t
100 lm700x_encode_ref(u_int8_t rf)
101 {
102 u_int32_t ret;
103
104 if (rf < 36)
105 ret = LM700X_REF_025;
106 else if (rf > 35 && rf < 75)
107 ret = LM700X_REF_050;
108 else
109 ret = LM700X_REF_100;
110
111 return ret;
112 }
113
114 u_int8_t
115 lm700x_decode_ref(u_int32_t rf)
116 {
117 u_int8_t ret;
118
119 switch (rf) {
120 case LM700X_REF_100:
121 ret = 100;
122 break;
123 case LM700X_REF_025:
124 ret = 25;
125 break;
126 case LM700X_REF_050:
127 /* FALLTHROUGH */
128 default:
129 ret = 50;
130 break;
131 }
132
133 return ret;
134 }
Cache object: e82f0e2530d2c3f1435eb6d6e3d577d3
|