1 /* $OpenBSD: lm700x.c,v 1.3 2007/05/22 04:14:03 jsg 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 * 33 * The LM7001J and LM7001JM (used in Aztech/PackardBell cards) are PLL 34 * frequency synthesizer LSIs for tuners. These LSIs are software compatible 35 * with LM7000 (used in Radiotrack, Radioreveal RA300, some Mediaforte cards), 36 * but do not include an IF calculation circuit. 37 * 38 * The FM VCO circuit includes a high-speed programmable divider that can 39 * divide directly. 40 * 41 * Features: 42 * Seven reference frequencies: 1, 5, 9, 10, 25, 50, and 100 kHz; 43 * Band-switching outputs (3 bits); 44 * Controller clock output (400 kHz); 45 * Serial input circuit for data input (using the CE, CL and DATA pins). 46 * 47 * The LM7001J and LM7001JM have a 24-bit shift register. 48 */ 49 50 #include <sys/param.h> 51 #include <sys/radioio.h> 52 53 #include <dev/ic/lm700x.h> 54 55 u_int32_t 56 lm700x_encode_freq(u_int32_t nfreq, u_int32_t rf) 57 { 58 nfreq += IF_FREQ; 59 nfreq /= lm700x_decode_ref(rf); 60 return nfreq; 61 } 62 63 void 64 lm700x_hardware_write(struct lm700x_t *lm, u_int32_t data, u_int32_t addon) 65 { 66 int i; 67 68 lm->init(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon); 69 70 for (i = 0; i < LM700X_REGISTER_LENGTH; i++) 71 if (data & (1 << i)) { 72 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 73 lm->wocl | addon); 74 DELAY(LM700X_WRITE_DELAY); 75 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 76 lm->woch | addon); 77 DELAY(LM700X_WRITE_DELAY); 78 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 79 lm->wocl | addon); 80 } else { 81 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 82 lm->wzcl | addon); 83 DELAY(LM700X_WRITE_DELAY); 84 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 85 lm->wzch | addon); 86 DELAY(LM700X_WRITE_DELAY); 87 bus_space_write_1(lm->iot, lm->ioh, lm->offset, 88 lm->wzcl | addon); 89 } 90 91 lm->rset(lm->iot, lm->ioh, lm->offset, lm->rsetdata | addon); 92 } 93 94 u_int32_t 95 lm700x_encode_ref(u_int8_t rf) 96 { 97 u_int32_t ret; 98 99 if (rf < 36) 100 ret = LM700X_REF_025; 101 else if (rf > 35 && rf < 75) 102 ret = LM700X_REF_050; 103 else 104 ret = LM700X_REF_100; 105 106 return ret; 107 } 108 109 u_int8_t 110 lm700x_decode_ref(u_int32_t rf) 111 { 112 u_int8_t ret; 113 114 switch (rf) { 115 case LM700X_REF_100: 116 ret = 100; 117 break; 118 case LM700X_REF_025: 119 ret = 25; 120 break; 121 case LM700X_REF_050: 122 /* FALLTHROUGH */ 123 default: 124 ret = 50; 125 break; 126 } 127 128 return ret; 129 }