xref: /linux/drivers/media/radio/lm7000.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LM7000_H
3 #define __LM7000_H
4 
5 /* Sanyo LM7000 tuner chip control
6  *
7  * Copyright 2012 Ondrej Zary <linux@rainbow-software.org>
8  * based on radio-aimslab.c by M. Kirkwood
9  * and radio-sf16fmi.c by M. Kirkwood and Petr Vandrovec
10  */
11 
12 #define LM7000_DATA	(1 << 0)
13 #define LM7000_CLK	(1 << 1)
14 #define LM7000_CE	(1 << 2)
15 
16 #define LM7000_FM_100	(0 << 20)
17 #define LM7000_FM_50	(1 << 20)
18 #define LM7000_FM_25	(2 << 20)
19 #define LM7000_BIT_FM	(1 << 23)
20 
lm7000_set_freq(u32 freq,void * handle,void (* set_pins)(void * handle,u8 pins))21 static inline void lm7000_set_freq(u32 freq, void *handle,
22 				void (*set_pins)(void *handle, u8 pins))
23 {
24 	int i;
25 	u8 data;
26 	u32 val;
27 
28 	freq += 171200;		/* Add 10.7 MHz IF */
29 	freq /= 400;		/* Convert to 25 kHz units */
30 	val = freq | LM7000_FM_25 | LM7000_BIT_FM;
31 	/* write the 24-bit register, starting with LSB */
32 	for (i = 0; i < 24; i++) {
33 		data = val & (1 << i) ? LM7000_DATA : 0;
34 		set_pins(handle, data | LM7000_CE);
35 		udelay(2);
36 		set_pins(handle, data | LM7000_CE | LM7000_CLK);
37 		udelay(2);
38 		set_pins(handle, data | LM7000_CE);
39 		udelay(2);
40 	}
41 	set_pins(handle, 0);
42 }
43 
44 #endif /* __LM7000_H */
45