/* * si470x_start - switch on radio */ static int si470x_start(struct si470x_device *radio) { int retval; /* powercfg */ radio->registers[POWERCFG] = POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM; retval = si470x_set_register(radio, POWERCFG); if (retval < 0) goto done; /* sysconfig 1 */ radio->registers[SYSCONFIG1] = SYSCONFIG1_DE; retval = si470x_set_register(radio, SYSCONFIG1); if (retval < 0) goto done; /* sysconfig 2 */ radio->registers[SYSCONFIG2] = (0x3f << 8) | /* SEEKTH */ ((band << 6) & SYSCONFIG2_BAND) | /* BAND */ ((space << 4) & SYSCONFIG2_SPACE) | /* SPACE */ 15; /* VOLUME (max) */ retval = si470x_set_register(radio, SYSCONFIG2); if (retval < 0) goto done; /* reset last channel */ retval = si470x_set_chan(radio, radio->registers[CHANNEL] & CHANNEL_CHAN); done: return retval; }
/* * si470x_set_freq - set the frequency */ static int si470x_set_freq(struct si470x_device *radio, unsigned int freq) { unsigned int spacing, band_bottom; unsigned short chan; /* Spacing (kHz) */ switch (space) { /* 0: 200 kHz (USA, Australia) */ case 0 : spacing = 0.200 * FREQ_MUL; break; /* 1: 100 kHz (Europe, Japan) */ case 1 : spacing = 0.100 * FREQ_MUL; break; /* 2: 50 kHz */ default: spacing = 0.050 * FREQ_MUL; break; }; /* Bottom of Band (MHz) */ switch (band) { /* 0: 87.5 - 108 MHz (USA, Europe) */ case 0 : band_bottom = 87.5 * FREQ_MUL; break; /* 1: 76 - 108 MHz (Japan wide band) */ default: band_bottom = 76 * FREQ_MUL; break; /* 2: 76 - 90 MHz (Japan) */ case 2 : band_bottom = 76 * FREQ_MUL; break; }; /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */ chan = (freq - band_bottom) / spacing; return si470x_set_chan(radio, chan); }
/* * si470x_set_freq - set the frequency */ int si470x_set_freq(struct si470x_device *radio, unsigned int freq) { unsigned short chan; freq = clamp(freq, bands[radio->band].rangelow, bands[radio->band].rangehigh); /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */ chan = (freq - bands[radio->band].rangelow) / si470x_get_step(radio); return si470x_set_chan(radio, chan); }