1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
272a770c9SOndrej Zary #ifndef __LM7000_H
372a770c9SOndrej Zary #define __LM7000_H
472a770c9SOndrej Zary
572a770c9SOndrej Zary /* Sanyo LM7000 tuner chip control
672a770c9SOndrej Zary *
772a770c9SOndrej Zary * Copyright 2012 Ondrej Zary <linux@rainbow-software.org>
872a770c9SOndrej Zary * based on radio-aimslab.c by M. Kirkwood
972a770c9SOndrej Zary * and radio-sf16fmi.c by M. Kirkwood and Petr Vandrovec
1072a770c9SOndrej Zary */
1172a770c9SOndrej Zary
1272a770c9SOndrej Zary #define LM7000_DATA (1 << 0)
1372a770c9SOndrej Zary #define LM7000_CLK (1 << 1)
1472a770c9SOndrej Zary #define LM7000_CE (1 << 2)
1572a770c9SOndrej Zary
1672a770c9SOndrej Zary #define LM7000_FM_100 (0 << 20)
1772a770c9SOndrej Zary #define LM7000_FM_50 (1 << 20)
1872a770c9SOndrej Zary #define LM7000_FM_25 (2 << 20)
1972a770c9SOndrej Zary #define LM7000_BIT_FM (1 << 23)
2072a770c9SOndrej Zary
lm7000_set_freq(u32 freq,void * handle,void (* set_pins)(void * handle,u8 pins))2172a770c9SOndrej Zary static inline void lm7000_set_freq(u32 freq, void *handle,
2272a770c9SOndrej Zary void (*set_pins)(void *handle, u8 pins))
2372a770c9SOndrej Zary {
2472a770c9SOndrej Zary int i;
2572a770c9SOndrej Zary u8 data;
2672a770c9SOndrej Zary u32 val;
2772a770c9SOndrej Zary
2872a770c9SOndrej Zary freq += 171200; /* Add 10.7 MHz IF */
2972a770c9SOndrej Zary freq /= 400; /* Convert to 25 kHz units */
3072a770c9SOndrej Zary val = freq | LM7000_FM_25 | LM7000_BIT_FM;
3172a770c9SOndrej Zary /* write the 24-bit register, starting with LSB */
3272a770c9SOndrej Zary for (i = 0; i < 24; i++) {
3372a770c9SOndrej Zary data = val & (1 << i) ? LM7000_DATA : 0;
3472a770c9SOndrej Zary set_pins(handle, data | LM7000_CE);
3572a770c9SOndrej Zary udelay(2);
3672a770c9SOndrej Zary set_pins(handle, data | LM7000_CE | LM7000_CLK);
3772a770c9SOndrej Zary udelay(2);
3872a770c9SOndrej Zary set_pins(handle, data | LM7000_CE);
3972a770c9SOndrej Zary udelay(2);
4072a770c9SOndrej Zary }
4172a770c9SOndrej Zary set_pins(handle, 0);
4272a770c9SOndrej Zary }
4372a770c9SOndrej Zary
4472a770c9SOndrej Zary #endif /* __LM7000_H */
45