1*95e1ffb1Schristos /* $NetBSD: lm700x.c,v 1.3 2005/12/11 12:21:27 christos Exp $ */
21c06f6a4Saugustss /* $OpenBSD: lm700x.c,v 1.2 2001/12/06 16:28:18 mickey Exp $ */
31c06f6a4Saugustss
41c06f6a4Saugustss /*
51c06f6a4Saugustss * Copyright (c) 2001 Vladimir Popov <jumbo@narod.ru>
61c06f6a4Saugustss * All rights reserved.
71c06f6a4Saugustss *
81c06f6a4Saugustss * Redistribution and use in source and binary forms, with or without
91c06f6a4Saugustss * modification, are permitted provided that the following conditions
101c06f6a4Saugustss * are met:
111c06f6a4Saugustss * 1. Redistributions of source code must retain the above copyright
121c06f6a4Saugustss * notice, this list of conditions and the following disclaimer.
131c06f6a4Saugustss * 2. Redistributions in binary form must reproduce the above copyright
141c06f6a4Saugustss * notice, this list of conditions and the following disclaimer in the
151c06f6a4Saugustss * documentation and/or other materials provided with the distribution.
161c06f6a4Saugustss *
171c06f6a4Saugustss * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181c06f6a4Saugustss * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191c06f6a4Saugustss * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201c06f6a4Saugustss * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211c06f6a4Saugustss * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
221c06f6a4Saugustss * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
231c06f6a4Saugustss * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
241c06f6a4Saugustss * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
251c06f6a4Saugustss * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
261c06f6a4Saugustss * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271c06f6a4Saugustss */
281c06f6a4Saugustss
291c06f6a4Saugustss /* Implementation of most common lm700x routines */
301c06f6a4Saugustss
311c06f6a4Saugustss /*
321c06f6a4Saugustss * Sanyo LM7001 Direct PLL Frequency Synthesizer
331c06f6a4Saugustss * ??? See http://www.redsword.com/tjacobs/geeb/fmcard.htm
341c06f6a4Saugustss *
351c06f6a4Saugustss * The LM7001J and LM7001JM (used in Aztech/PackardBell cards) are PLL
361c06f6a4Saugustss * frequency synthesizer LSIs for tuners. These LSIs are software compatible
371c06f6a4Saugustss * with LM7000 (used in Radiotrack, Radioreveal RA300, some Mediaforte cards),
381c06f6a4Saugustss * but do not include an IF calculation circuit.
391c06f6a4Saugustss *
401c06f6a4Saugustss * The FM VCO circuit includes a high-speed programmable divider that can
411c06f6a4Saugustss * divide directly.
421c06f6a4Saugustss *
431c06f6a4Saugustss * Features:
441c06f6a4Saugustss * Seven reference frequencies: 1, 5, 9, 10, 25, 50, and 100 kHz;
451c06f6a4Saugustss * Band-switching outputs (3 bits);
461c06f6a4Saugustss * Controller clock output (400 kHz);
471c06f6a4Saugustss * Serial input circuit for data input (using the CE, CL and DATA pins).
481c06f6a4Saugustss *
491c06f6a4Saugustss * The LM7001J and LM7001JM have a 24-bit shift register.
501c06f6a4Saugustss */
511c06f6a4Saugustss
52365cbd94Slukem #include <sys/cdefs.h>
53*95e1ffb1Schristos __KERNEL_RCSID(0, "$NetBSD: lm700x.c,v 1.3 2005/12/11 12:21:27 christos Exp $");
54365cbd94Slukem
551c06f6a4Saugustss #include <sys/param.h>
561c06f6a4Saugustss #include <sys/radioio.h>
571c06f6a4Saugustss
581c06f6a4Saugustss #include <dev/ic/lm700x.h>
591c06f6a4Saugustss
601c06f6a4Saugustss u_int32_t
lm700x_encode_freq(u_int32_t nfreq,u_int32_t rf)611c06f6a4Saugustss lm700x_encode_freq(u_int32_t nfreq, u_int32_t rf)
621c06f6a4Saugustss {
631c06f6a4Saugustss nfreq += IF_FREQ;
641c06f6a4Saugustss nfreq /= lm700x_decode_ref(rf);
651c06f6a4Saugustss return nfreq;
661c06f6a4Saugustss }
671c06f6a4Saugustss
681c06f6a4Saugustss void
lm700x_hardware_write(struct lm700x_t * lm,u_int32_t data,u_int32_t addon)691c06f6a4Saugustss lm700x_hardware_write(struct lm700x_t *lm, u_int32_t data, u_int32_t addon)
701c06f6a4Saugustss {
711c06f6a4Saugustss int i;
721c06f6a4Saugustss
731c06f6a4Saugustss lm->init(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
741c06f6a4Saugustss
751c06f6a4Saugustss for (i = 0; i < LM700X_REGISTER_LENGTH; i++)
761c06f6a4Saugustss if (data & (1 << i)) {
771c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
781c06f6a4Saugustss lm->wocl | addon);
791c06f6a4Saugustss DELAY(LM700X_WRITE_DELAY);
801c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
811c06f6a4Saugustss lm->woch | addon);
821c06f6a4Saugustss DELAY(LM700X_WRITE_DELAY);
831c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
841c06f6a4Saugustss lm->wocl | addon);
851c06f6a4Saugustss } else {
861c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
871c06f6a4Saugustss lm->wzcl | addon);
881c06f6a4Saugustss DELAY(LM700X_WRITE_DELAY);
891c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
901c06f6a4Saugustss lm->wzch | addon);
911c06f6a4Saugustss DELAY(LM700X_WRITE_DELAY);
921c06f6a4Saugustss bus_space_write_1(lm->iot, lm->ioh, lm->offset,
931c06f6a4Saugustss lm->wzcl | addon);
941c06f6a4Saugustss }
951c06f6a4Saugustss
961c06f6a4Saugustss lm->rset(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon);
971c06f6a4Saugustss }
981c06f6a4Saugustss
991c06f6a4Saugustss u_int32_t
lm700x_encode_ref(u_int8_t rf)1001c06f6a4Saugustss lm700x_encode_ref(u_int8_t rf)
1011c06f6a4Saugustss {
1021c06f6a4Saugustss u_int32_t ret;
1031c06f6a4Saugustss
1041c06f6a4Saugustss if (rf < 36)
1051c06f6a4Saugustss ret = LM700X_REF_025;
1061c06f6a4Saugustss else if (rf > 35 && rf < 75)
1071c06f6a4Saugustss ret = LM700X_REF_050;
1081c06f6a4Saugustss else
1091c06f6a4Saugustss ret = LM700X_REF_100;
1101c06f6a4Saugustss
1111c06f6a4Saugustss return ret;
1121c06f6a4Saugustss }
1131c06f6a4Saugustss
1141c06f6a4Saugustss u_int8_t
lm700x_decode_ref(u_int32_t rf)1151c06f6a4Saugustss lm700x_decode_ref(u_int32_t rf)
1161c06f6a4Saugustss {
1171c06f6a4Saugustss u_int8_t ret;
1181c06f6a4Saugustss
1191c06f6a4Saugustss switch (rf) {
1201c06f6a4Saugustss case LM700X_REF_100:
1211c06f6a4Saugustss ret = 100;
1221c06f6a4Saugustss break;
1231c06f6a4Saugustss case LM700X_REF_025:
1241c06f6a4Saugustss ret = 25;
1251c06f6a4Saugustss break;
1261c06f6a4Saugustss case LM700X_REF_050:
1271c06f6a4Saugustss /* FALLTHROUGH */
1281c06f6a4Saugustss default:
1291c06f6a4Saugustss ret = 50;
1301c06f6a4Saugustss break;
1311c06f6a4Saugustss }
1321c06f6a4Saugustss
1331c06f6a4Saugustss return ret;
1341c06f6a4Saugustss }
135