1
2
3
4
5
6
7
8
9
10
11
12 #define DRIVER_NAME "radio-si470x"
13
14
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/input.h>
22 #include <linux/videodev2.h>
23 #include <linux/mutex.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ioctl.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-device.h>
29 #include <asm/unaligned.h>
30
31
32
33
34
35
36 #define RADIO_REGISTER_SIZE 2
37 #define RADIO_REGISTER_NUM 16
38 #define RDS_REGISTER_NUM 6
39
40 #define DEVICEID 0
41 #define DEVICEID_PN 0xf000
42 #define DEVICEID_MFGID 0x0fff
43
44 #define SI_CHIPID 1
45 #define SI_CHIPID_REV 0xfc00
46 #define SI_CHIPID_DEV 0x0200
47 #define SI_CHIPID_FIRMWARE 0x01ff
48
49 #define POWERCFG 2
50 #define POWERCFG_DSMUTE 0x8000
51 #define POWERCFG_DMUTE 0x4000
52 #define POWERCFG_MONO 0x2000
53 #define POWERCFG_RDSM 0x0800
54 #define POWERCFG_SKMODE 0x0400
55 #define POWERCFG_SEEKUP 0x0200
56 #define POWERCFG_SEEK 0x0100
57 #define POWERCFG_DISABLE 0x0040
58 #define POWERCFG_ENABLE 0x0001
59
60 #define CHANNEL 3
61 #define CHANNEL_TUNE 0x8000
62 #define CHANNEL_CHAN 0x03ff
63
64 #define SYSCONFIG1 4
65 #define SYSCONFIG1_RDSIEN 0x8000
66 #define SYSCONFIG1_STCIEN 0x4000
67 #define SYSCONFIG1_RDS 0x1000
68 #define SYSCONFIG1_DE 0x0800
69 #define SYSCONFIG1_AGCD 0x0400
70 #define SYSCONFIG1_BLNDADJ 0x00c0
71 #define SYSCONFIG1_GPIO3 0x0030
72 #define SYSCONFIG1_GPIO2 0x000c
73 #define SYSCONFIG1_GPIO2_DIS 0x0000
74 #define SYSCONFIG1_GPIO2_INT 0x0004
75 #define SYSCONFIG1_GPIO1 0x0003
76
77 #define SYSCONFIG2 5
78 #define SYSCONFIG2_SEEKTH 0xff00
79 #define SYSCONFIG2_BAND 0x00c0
80 #define SYSCONFIG2_SPACE 0x0030
81 #define SYSCONFIG2_VOLUME 0x000f
82
83 #define SYSCONFIG3 6
84 #define SYSCONFIG3_SMUTER 0xc000
85 #define SYSCONFIG3_SMUTEA 0x3000
86 #define SYSCONFIG3_SKSNR 0x00f0
87 #define SYSCONFIG3_SKCNT 0x000f
88
89 #define TEST1 7
90 #define TEST1_AHIZEN 0x4000
91
92 #define TEST2 8
93
94
95 #define BOOTCONFIG 9
96
97
98 #define STATUSRSSI 10
99 #define STATUSRSSI_RDSR 0x8000
100 #define STATUSRSSI_STC 0x4000
101 #define STATUSRSSI_SF 0x2000
102 #define STATUSRSSI_AFCRL 0x1000
103 #define STATUSRSSI_RDSS 0x0800
104 #define STATUSRSSI_BLERA 0x0600
105 #define STATUSRSSI_ST 0x0100
106 #define STATUSRSSI_RSSI 0x00ff
107
108 #define READCHAN 11
109 #define READCHAN_BLERB 0xc000
110 #define READCHAN_BLERC 0x3000
111 #define READCHAN_BLERD 0x0c00
112 #define READCHAN_READCHAN 0x03ff
113
114 #define RDSA 12
115 #define RDSA_RDSA 0xffff
116
117 #define RDSB 13
118 #define RDSB_RDSB 0xffff
119
120 #define RDSC 14
121 #define RDSC_RDSC 0xffff
122
123 #define RDSD 15
124 #define RDSD_RDSD 0xffff
125
126
127
128
129
130
131
132
133
134
135 struct si470x_device {
136 struct v4l2_device v4l2_dev;
137 struct video_device videodev;
138 struct v4l2_ctrl_handler hdl;
139 int band;
140
141
142 unsigned short registers[RADIO_REGISTER_NUM];
143
144
145 wait_queue_head_t read_queue;
146 struct mutex lock;
147 unsigned char *buffer;
148 unsigned int buf_size;
149 unsigned int rd_index;
150 unsigned int wr_index;
151
152 struct completion completion;
153 bool status_rssi_auto_update;
154
155
156
157 int (*get_register)(struct si470x_device *radio, int regnr);
158 int (*set_register)(struct si470x_device *radio, int regnr);
159 int (*fops_open)(struct file *file);
160 int (*fops_release)(struct file *file);
161 int (*vidioc_querycap)(struct file *file, void *priv,
162 struct v4l2_capability *capability);
163
164 #if IS_ENABLED(CONFIG_USB_SI470X)
165
166 struct usb_device *usbdev;
167 struct usb_interface *intf;
168 char *usb_buf;
169
170
171 char *int_in_buffer;
172 struct usb_endpoint_descriptor *int_in_endpoint;
173 struct urb *int_in_urb;
174 int int_in_running;
175
176
177 unsigned char software_version;
178 unsigned char hardware_version;
179 #endif
180
181 #if IS_ENABLED(CONFIG_I2C_SI470X)
182 struct i2c_client *client;
183 struct gpio_desc *gpio_reset;
184 #endif
185 };
186
187
188
189
190
191
192
193 #define RADIO_FW_VERSION 12
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 #define FREQ_MUL (1000000 / 62.5)
209
210
211
212
213
214
215 extern const struct video_device si470x_viddev_template;
216 extern const struct v4l2_ctrl_ops si470x_ctrl_ops;
217 int si470x_disconnect_check(struct si470x_device *radio);
218 int si470x_set_freq(struct si470x_device *radio, unsigned int freq);
219 int si470x_start(struct si470x_device *radio);
220 int si470x_stop(struct si470x_device *radio);