/* $NetBSD: tea5767.c,v 1.2 2019/12/23 20:49:09 thorpej Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Karuna Grewal.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
struct tea5767_tune {
int mute;
uint32_t freq;
int stereo;
bool is_pll_set;
bool is_xtal_set;
bool is_force_srch;
int fm_band; /* Set = JAPAN. */
int lock;
int adc_stop_level;
};
if (tea5767_flags & TEA5767_PLL_FLAG)
sc->tune.is_pll_set = true;
if (tea5767_flags & TEA5767_XTAL_FLAG)
sc->tune.is_xtal_set = true;
if (tea5767_flags & TEA5767_JAPAN_FM_FLAG)
sc->tune.fm_band = 1;
if (tea5767_flags & TEA5767_FORCE_SRCH_FLAG)
sc->tune.is_force_srch = true;
sc->caps = tea5767_common_caps;
/*
* Check the quality of crystal and disable hardware search if
* necessary.
*/
if (!tea5767_if_check(sc) && !(sc->tune.is_force_srch))
sc->caps &= ~RADIO_CAPS_HW_SEARCH;
radio_attach_mi(&tea5767_hw_if, sc, self);
}
static int
tea5767_write(struct tea5767_softc *sc, uint8_t *reg)
{
int exec_result;
/*
* Calculate the PLL word.
* TODO: Extend this calculation to do high side injection as well
* (add fields to tea5767_tune).
*/
static void
tea5767_freq_to_pll(struct tea5767_tune tune, uint8_t *buf)
{
uint16_t pll_word = 0;
static int
tea5767_search(void *v, int dir)
{
struct tea5767_softc *sc = v;
uint8_t reg[5];
/* Increment frequency to search for the next frequency. */
sc->tune.freq = sc->tune.freq >= 107500 ? 87500 : sc->tune.freq + 100;
tea5767_set_properties(sc, reg);