1 /* $OpenBSD: lm700x.c,v 1.2 2001/12/06 16:28:18 mickey Exp $ */
2
3 /*
4 * Copyright (c) 2001 Vladimir Popov <jumbo@narod.ru>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /* Implementation of most common lm700x routines */
29
30 /*
31 * Sanyo LM7001 Direct PLL Frequency Synthesizer
32 * ??? See http://www.redsword.com/tjacobs/geeb/fmcard.htm
33 *
34 * The LM7001J and LM7001JM (used in Aztech/PackardBell cards) are PLL
35 * frequency synthesizer LSIs for tuners. These LSIs are software compatible
36 * with LM7000 (used in Radiotrack, Radioreveal RA300, some Mediaforte cards),
37 * but do not include an IF calculation circuit.
38 *
39 * The FM VCO circuit includes a high-speed programmable divider that can
40 * divide directly.
41 *
42 * Features:
43 * Seven reference frequencies: 1, 5, 9, 10, 25, 50, and 100 kHz;
44 * Band-switching outputs (3 bits);
45 * Controller clock output (400 kHz);
46 * Serial input circuit for data input (using the CE, CL and DATA pins).
47 *
48 * The LM7001J and LM7001JM have a 24-bit shift register.
49 */
50
51 #include <sys/param.h>
52 #include <sys/radioio.h>
53
54 #include <dev/ic/lm700x.h>
55
56 u_int32_t
lm700x_encode_freq(u_int32_t nfreq,u_int32_t rf)57 lm700x_encode_freq(u_int32_t nfreq, u_int32_t rf)
58 {
59 nfreq += IF_FREQ;
60 nfreq /= lm700x_decode_ref(rf);
61 return nfreq;
62 }
63
64 void
lm700x_hardware_write(struct lm700x_t * lm,u_int32_t data,u_int32_t addon)65 lm700x_hardware_write(struct lm700x_t *lm, u_int32_t data, u_int32_t addon)
66 {
67 int i;
68
69 lm->init(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
70
71 for (i = 0; i < LM700X_REGISTER_LENGTH; i++)
72 if (data & (1 << i)) {
73 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
74 lm->wocl | addon);
75 DELAY(LM700X_WRITE_DELAY);
76 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
77 lm->woch | addon);
78 DELAY(LM700X_WRITE_DELAY);
79 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
80 lm->wocl | addon);
81 } else {
82 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
83 lm->wzcl | addon);
84 DELAY(LM700X_WRITE_DELAY);
85 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
86 lm->wzch | addon);
87 DELAY(LM700X_WRITE_DELAY);
88 bus_space_write_1(lm->iot, lm->ioh, lm->offset,
89 lm->wzcl | addon);
90 }
91
92 lm->rset(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
93 }
94
95 u_int32_t
lm700x_encode_ref(u_int8_t rf)96 lm700x_encode_ref(u_int8_t rf)
97 {
98 u_int32_t ret;
99
100 if (rf < 36)
101 ret = LM700X_REF_025;
102 else if (rf > 35 && rf < 75)
103 ret = LM700X_REF_050;
104 else
105 ret = LM700X_REF_100;
106
107 return ret;
108 }
109
110 u_int8_t
lm700x_decode_ref(u_int32_t rf)111 lm700x_decode_ref(u_int32_t rf)
112 {
113 u_int8_t ret;
114
115 switch (rf) {
116 case LM700X_REF_100:
117 ret = 100;
118 break;
119 case LM700X_REF_025:
120 ret = 25;
121 break;
122 case LM700X_REF_050:
123 /* FALLTHROUGH */
124 default:
125 ret = 50;
126 break;
127 }
128
129 return ret;
130 }
131