18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __LM7000_H
38c2ecf20Sopenharmony_ci#define __LM7000_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/* Sanyo LM7000 tuner chip control
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright 2012 Ondrej Zary <linux@rainbow-software.org>
88c2ecf20Sopenharmony_ci * based on radio-aimslab.c by M. Kirkwood
98c2ecf20Sopenharmony_ci * and radio-sf16fmi.c by M. Kirkwood and Petr Vandrovec
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define LM7000_DATA	(1 << 0)
138c2ecf20Sopenharmony_ci#define LM7000_CLK	(1 << 1)
148c2ecf20Sopenharmony_ci#define LM7000_CE	(1 << 2)
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define LM7000_FM_100	(0 << 20)
178c2ecf20Sopenharmony_ci#define LM7000_FM_50	(1 << 20)
188c2ecf20Sopenharmony_ci#define LM7000_FM_25	(2 << 20)
198c2ecf20Sopenharmony_ci#define LM7000_BIT_FM	(1 << 23)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline void lm7000_set_freq(u32 freq, void *handle,
228c2ecf20Sopenharmony_ci				void (*set_pins)(void *handle, u8 pins))
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	int i;
258c2ecf20Sopenharmony_ci	u8 data;
268c2ecf20Sopenharmony_ci	u32 val;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	freq += 171200;		/* Add 10.7 MHz IF */
298c2ecf20Sopenharmony_ci	freq /= 400;		/* Convert to 25 kHz units */
308c2ecf20Sopenharmony_ci	val = freq | LM7000_FM_25 | LM7000_BIT_FM;
318c2ecf20Sopenharmony_ci	/* write the 24-bit register, starting with LSB */
328c2ecf20Sopenharmony_ci	for (i = 0; i < 24; i++) {
338c2ecf20Sopenharmony_ci		data = val & (1 << i) ? LM7000_DATA : 0;
348c2ecf20Sopenharmony_ci		set_pins(handle, data | LM7000_CE);
358c2ecf20Sopenharmony_ci		udelay(2);
368c2ecf20Sopenharmony_ci		set_pins(handle, data | LM7000_CE | LM7000_CLK);
378c2ecf20Sopenharmony_ci		udelay(2);
388c2ecf20Sopenharmony_ci		set_pins(handle, data | LM7000_CE);
398c2ecf20Sopenharmony_ci		udelay(2);
408c2ecf20Sopenharmony_ci	}
418c2ecf20Sopenharmony_ci	set_pins(handle, 0);
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#endif /* __LM7000_H */
45