Commit | Line | Data |
---|---|---|
76f9a820 AX |
1 | /* DVB USB compliant Linux driver for the AZUREWAVE DVB-S/S2 USB2.0 (AZ6027) |
2 | * receiver. | |
3 | * | |
4 | * Copyright (C) 2009 Adams.Xu <adams.xu@azwave.com.cn> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the Free | |
8 | * Software Foundation, version 2. | |
9 | * | |
10 | * see Documentation/dvb/README.dvb-usb for more information | |
11 | */ | |
12 | #include "az6027.h" | |
5f0e1cff | 13 | |
76f9a820 AX |
14 | #include "stb0899_drv.h" |
15 | #include "stb0899_reg.h" | |
16 | #include "stb0899_cfg.h" | |
5f0e1cff | 17 | |
76f9a820 AX |
18 | #include "stb6100.h" |
19 | #include "stb6100_cfg.h" | |
20 | #include "dvb_ca_en50221.h" | |
21 | ||
76f9a820 | 22 | int dvb_usb_az6027_debug; |
5f0e1cff | 23 | module_param_named(debug, dvb_usb_az6027_debug, int, 0644); |
76f9a820 AX |
24 | MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); |
25 | ||
26 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | |
27 | ||
28 | struct az6027_device_state { | |
29 | struct dvb_ca_en50221 ca; | |
30 | struct mutex ca_mutex; | |
31 | u8 power_state; | |
32 | }; | |
33 | ||
34 | static const struct stb0899_s1_reg az6027_stb0899_s1_init_1[] = { | |
35 | ||
5f0e1cff | 36 | /* 0x0000000b, SYSREG */ |
76f9a820 AX |
37 | { STB0899_DEV_ID , 0x30 }, |
38 | { STB0899_DISCNTRL1 , 0x32 }, | |
39 | { STB0899_DISCNTRL2 , 0x80 }, | |
40 | { STB0899_DISRX_ST0 , 0x04 }, | |
41 | { STB0899_DISRX_ST1 , 0x00 }, | |
42 | { STB0899_DISPARITY , 0x00 }, | |
76f9a820 AX |
43 | { STB0899_DISSTATUS , 0x20 }, |
44 | { STB0899_DISF22 , 0x99 }, | |
45 | { STB0899_DISF22RX , 0xa8 }, | |
5f0e1cff | 46 | /* SYSREG ? */ |
76f9a820 AX |
47 | { STB0899_ACRPRESC , 0x11 }, |
48 | { STB0899_ACRDIV1 , 0x0a }, | |
49 | { STB0899_ACRDIV2 , 0x05 }, | |
50 | { STB0899_DACR1 , 0x00 }, | |
51 | { STB0899_DACR2 , 0x00 }, | |
52 | { STB0899_OUTCFG , 0x00 }, | |
53 | { STB0899_MODECFG , 0x00 }, | |
54 | { STB0899_IRQSTATUS_3 , 0xfe }, | |
55 | { STB0899_IRQSTATUS_2 , 0x03 }, | |
56 | { STB0899_IRQSTATUS_1 , 0x7c }, | |
57 | { STB0899_IRQSTATUS_0 , 0xf4 }, | |
58 | { STB0899_IRQMSK_3 , 0xf3 }, | |
59 | { STB0899_IRQMSK_2 , 0xfc }, | |
60 | { STB0899_IRQMSK_1 , 0xff }, | |
61 | { STB0899_IRQMSK_0 , 0xff }, | |
62 | { STB0899_IRQCFG , 0x00 }, | |
63 | { STB0899_I2CCFG , 0x88 }, | |
64 | { STB0899_I2CRPT , 0x58 }, | |
65 | { STB0899_IOPVALUE5 , 0x00 }, | |
66 | { STB0899_IOPVALUE4 , 0x33 }, | |
67 | { STB0899_IOPVALUE3 , 0x6d }, | |
68 | { STB0899_IOPVALUE2 , 0x90 }, | |
69 | { STB0899_IOPVALUE1 , 0x60 }, | |
70 | { STB0899_IOPVALUE0 , 0x00 }, | |
71 | { STB0899_GPIO00CFG , 0x82 }, | |
72 | { STB0899_GPIO01CFG , 0x82 }, | |
73 | { STB0899_GPIO02CFG , 0x82 }, | |
74 | { STB0899_GPIO03CFG , 0x82 }, | |
75 | { STB0899_GPIO04CFG , 0x82 }, | |
76 | { STB0899_GPIO05CFG , 0x82 }, | |
77 | { STB0899_GPIO06CFG , 0x82 }, | |
78 | { STB0899_GPIO07CFG , 0x82 }, | |
79 | { STB0899_GPIO08CFG , 0x82 }, | |
80 | { STB0899_GPIO09CFG , 0x82 }, | |
81 | { STB0899_GPIO10CFG , 0x82 }, | |
82 | { STB0899_GPIO11CFG , 0x82 }, | |
83 | { STB0899_GPIO12CFG , 0x82 }, | |
84 | { STB0899_GPIO13CFG , 0x82 }, | |
85 | { STB0899_GPIO14CFG , 0x82 }, | |
86 | { STB0899_GPIO15CFG , 0x82 }, | |
87 | { STB0899_GPIO16CFG , 0x82 }, | |
88 | { STB0899_GPIO17CFG , 0x82 }, | |
89 | { STB0899_GPIO18CFG , 0x82 }, | |
90 | { STB0899_GPIO19CFG , 0x82 }, | |
91 | { STB0899_GPIO20CFG , 0x82 }, | |
92 | { STB0899_SDATCFG , 0xb8 }, | |
93 | { STB0899_SCLTCFG , 0xba }, | |
94 | { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */ | |
95 | { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */ | |
96 | { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */ | |
97 | { STB0899_DIRCLKCFG , 0x82 }, | |
98 | { STB0899_CLKOUT27CFG , 0x7e }, | |
99 | { STB0899_STDBYCFG , 0x82 }, | |
100 | { STB0899_CS0CFG , 0x82 }, | |
101 | { STB0899_CS1CFG , 0x82 }, | |
102 | { STB0899_DISEQCOCFG , 0x20 }, | |
103 | { STB0899_GPIO32CFG , 0x82 }, | |
104 | { STB0899_GPIO33CFG , 0x82 }, | |
105 | { STB0899_GPIO34CFG , 0x82 }, | |
106 | { STB0899_GPIO35CFG , 0x82 }, | |
107 | { STB0899_GPIO36CFG , 0x82 }, | |
108 | { STB0899_GPIO37CFG , 0x82 }, | |
109 | { STB0899_GPIO38CFG , 0x82 }, | |
110 | { STB0899_GPIO39CFG , 0x82 }, | |
111 | { STB0899_NCOARSE , 0x17 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */ | |
112 | { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */ | |
113 | { STB0899_FILTCTRL , 0x00 }, | |
114 | { STB0899_SYSCTRL , 0x01 }, | |
115 | { STB0899_STOPCLK1 , 0x20 }, | |
116 | { STB0899_STOPCLK2 , 0x00 }, | |
117 | { STB0899_INTBUFSTATUS , 0x00 }, | |
118 | { STB0899_INTBUFCTRL , 0x0a }, | |
119 | { 0xffff , 0xff }, | |
120 | }; | |
121 | ||
122 | static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = { | |
123 | { STB0899_DEMOD , 0x00 }, | |
124 | { STB0899_RCOMPC , 0xc9 }, | |
125 | { STB0899_AGC1CN , 0x01 }, | |
126 | { STB0899_AGC1REF , 0x10 }, | |
000f64ef | 127 | { STB0899_RTC , 0x23 }, |
76f9a820 AX |
128 | { STB0899_TMGCFG , 0x4e }, |
129 | { STB0899_AGC2REF , 0x34 }, | |
130 | { STB0899_TLSR , 0x84 }, | |
131 | { STB0899_CFD , 0xf7 }, | |
000f64ef | 132 | { STB0899_ACLC , 0x87 }, |
76f9a820 AX |
133 | { STB0899_BCLC , 0x94 }, |
134 | { STB0899_EQON , 0x41 }, | |
135 | { STB0899_LDT , 0xf1 }, | |
136 | { STB0899_LDT2 , 0xe3 }, | |
137 | { STB0899_EQUALREF , 0xb4 }, | |
138 | { STB0899_TMGRAMP , 0x10 }, | |
139 | { STB0899_TMGTHD , 0x30 }, | |
140 | { STB0899_IDCCOMP , 0xfd }, | |
141 | { STB0899_QDCCOMP , 0xff }, | |
142 | { STB0899_POWERI , 0x0c }, | |
143 | { STB0899_POWERQ , 0x0f }, | |
144 | { STB0899_RCOMP , 0x6c }, | |
145 | { STB0899_AGCIQIN , 0x80 }, | |
146 | { STB0899_AGC2I1 , 0x06 }, | |
147 | { STB0899_AGC2I2 , 0x00 }, | |
148 | { STB0899_TLIR , 0x30 }, | |
149 | { STB0899_RTF , 0x7f }, | |
150 | { STB0899_DSTATUS , 0x00 }, | |
151 | { STB0899_LDI , 0xbc }, | |
152 | { STB0899_CFRM , 0xea }, | |
153 | { STB0899_CFRL , 0x31 }, | |
154 | { STB0899_NIRM , 0x2b }, | |
155 | { STB0899_NIRL , 0x80 }, | |
156 | { STB0899_ISYMB , 0x1d }, | |
157 | { STB0899_QSYMB , 0xa6 }, | |
158 | { STB0899_SFRH , 0x2f }, | |
159 | { STB0899_SFRM , 0x68 }, | |
160 | { STB0899_SFRL , 0x40 }, | |
161 | { STB0899_SFRUPH , 0x2f }, | |
162 | { STB0899_SFRUPM , 0x68 }, | |
163 | { STB0899_SFRUPL , 0x40 }, | |
164 | { STB0899_EQUAI1 , 0x02 }, | |
165 | { STB0899_EQUAQ1 , 0xff }, | |
166 | { STB0899_EQUAI2 , 0x04 }, | |
167 | { STB0899_EQUAQ2 , 0x05 }, | |
168 | { STB0899_EQUAI3 , 0x02 }, | |
169 | { STB0899_EQUAQ3 , 0xfd }, | |
170 | { STB0899_EQUAI4 , 0x03 }, | |
171 | { STB0899_EQUAQ4 , 0x07 }, | |
172 | { STB0899_EQUAI5 , 0x08 }, | |
173 | { STB0899_EQUAQ5 , 0xf5 }, | |
174 | { STB0899_DSTATUS2 , 0x00 }, | |
175 | { STB0899_VSTATUS , 0x00 }, | |
176 | { STB0899_VERROR , 0x86 }, | |
177 | { STB0899_IQSWAP , 0x2a }, | |
178 | { STB0899_ECNT1M , 0x00 }, | |
179 | { STB0899_ECNT1L , 0x00 }, | |
180 | { STB0899_ECNT2M , 0x00 }, | |
181 | { STB0899_ECNT2L , 0x00 }, | |
182 | { STB0899_ECNT3M , 0x0a }, | |
183 | { STB0899_ECNT3L , 0xad }, | |
184 | { STB0899_FECAUTO1 , 0x06 }, | |
000f64ef | 185 | { STB0899_FECM , 0x01 }, |
76f9a820 AX |
186 | { STB0899_VTH12 , 0xb0 }, |
187 | { STB0899_VTH23 , 0x7a }, | |
000f64ef | 188 | { STB0899_VTH34 , 0x58 }, |
76f9a820 AX |
189 | { STB0899_VTH56 , 0x38 }, |
190 | { STB0899_VTH67 , 0x34 }, | |
191 | { STB0899_VTH78 , 0x24 }, | |
192 | { STB0899_PRVIT , 0xff }, | |
193 | { STB0899_VITSYNC , 0x19 }, | |
194 | { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */ | |
195 | { STB0899_TSULC , 0x42 }, | |
196 | { STB0899_RSLLC , 0x41 }, | |
000f64ef | 197 | { STB0899_TSLPL , 0x12 }, |
76f9a820 AX |
198 | { STB0899_TSCFGH , 0x0c }, |
199 | { STB0899_TSCFGM , 0x00 }, | |
200 | { STB0899_TSCFGL , 0x00 }, | |
201 | { STB0899_TSOUT , 0x69 }, /* 0x0d for CAM */ | |
202 | { STB0899_RSSYNCDEL , 0x00 }, | |
203 | { STB0899_TSINHDELH , 0x02 }, | |
204 | { STB0899_TSINHDELM , 0x00 }, | |
205 | { STB0899_TSINHDELL , 0x00 }, | |
206 | { STB0899_TSLLSTKM , 0x1b }, | |
207 | { STB0899_TSLLSTKL , 0xb3 }, | |
208 | { STB0899_TSULSTKM , 0x00 }, | |
209 | { STB0899_TSULSTKL , 0x00 }, | |
210 | { STB0899_PCKLENUL , 0xbc }, | |
211 | { STB0899_PCKLENLL , 0xcc }, | |
212 | { STB0899_RSPCKLEN , 0xbd }, | |
213 | { STB0899_TSSTATUS , 0x90 }, | |
214 | { STB0899_ERRCTRL1 , 0xb6 }, | |
215 | { STB0899_ERRCTRL2 , 0x95 }, | |
216 | { STB0899_ERRCTRL3 , 0x8d }, | |
217 | { STB0899_DMONMSK1 , 0x27 }, | |
218 | { STB0899_DMONMSK0 , 0x03 }, | |
219 | { STB0899_DEMAPVIT , 0x5c }, | |
220 | { STB0899_PLPARM , 0x19 }, | |
221 | { STB0899_PDELCTRL , 0x48 }, | |
222 | { STB0899_PDELCTRL2 , 0x00 }, | |
223 | { STB0899_BBHCTRL1 , 0x00 }, | |
224 | { STB0899_BBHCTRL2 , 0x00 }, | |
225 | { STB0899_HYSTTHRESH , 0x77 }, | |
226 | { STB0899_MATCSTM , 0x00 }, | |
227 | { STB0899_MATCSTL , 0x00 }, | |
228 | { STB0899_UPLCSTM , 0x00 }, | |
229 | { STB0899_UPLCSTL , 0x00 }, | |
230 | { STB0899_DFLCSTM , 0x00 }, | |
231 | { STB0899_DFLCSTL , 0x00 }, | |
232 | { STB0899_SYNCCST , 0x00 }, | |
233 | { STB0899_SYNCDCSTM , 0x00 }, | |
234 | { STB0899_SYNCDCSTL , 0x00 }, | |
235 | { STB0899_ISI_ENTRY , 0x00 }, | |
236 | { STB0899_ISI_BIT_EN , 0x00 }, | |
237 | { STB0899_MATSTRM , 0xf0 }, | |
238 | { STB0899_MATSTRL , 0x02 }, | |
239 | { STB0899_UPLSTRM , 0x45 }, | |
240 | { STB0899_UPLSTRL , 0x60 }, | |
241 | { STB0899_DFLSTRM , 0xe3 }, | |
242 | { STB0899_DFLSTRL , 0x00 }, | |
243 | { STB0899_SYNCSTR , 0x47 }, | |
244 | { STB0899_SYNCDSTRM , 0x05 }, | |
245 | { STB0899_SYNCDSTRL , 0x18 }, | |
246 | { STB0899_CFGPDELSTATUS1 , 0x19 }, | |
247 | { STB0899_CFGPDELSTATUS2 , 0x2b }, | |
248 | { STB0899_BBFERRORM , 0x00 }, | |
249 | { STB0899_BBFERRORL , 0x01 }, | |
250 | { STB0899_UPKTERRORM , 0x00 }, | |
251 | { STB0899_UPKTERRORL , 0x00 }, | |
252 | { 0xffff , 0xff }, | |
253 | }; | |
254 | ||
255 | ||
256 | ||
257 | struct stb0899_config az6027_stb0899_config = { | |
258 | .init_dev = az6027_stb0899_s1_init_1, | |
259 | .init_s2_demod = stb0899_s2_init_2, | |
260 | .init_s1_demod = az6027_stb0899_s1_init_3, | |
261 | .init_s2_fec = stb0899_s2_init_4, | |
262 | .init_tst = stb0899_s1_init_5, | |
263 | ||
5f0e1cff | 264 | .demod_address = 0xd0, /* 0x68, 0xd0 >> 1 */ |
76f9a820 AX |
265 | |
266 | .xtal_freq = 27000000, | |
267 | .inversion = IQ_SWAP_ON, /* 1 */ | |
268 | ||
269 | .lo_clk = 76500000, | |
270 | .hi_clk = 99000000, | |
271 | ||
272 | .esno_ave = STB0899_DVBS2_ESNO_AVE, | |
273 | .esno_quant = STB0899_DVBS2_ESNO_QUANT, | |
274 | .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE, | |
275 | .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE, | |
276 | .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD, | |
277 | .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ, | |
278 | .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK, | |
279 | .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF, | |
280 | .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT, | |
281 | ||
282 | .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS, | |
283 | .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET, | |
284 | .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS, | |
285 | .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER, | |
286 | ||
287 | .tuner_get_frequency = stb6100_get_frequency, | |
288 | .tuner_set_frequency = stb6100_set_frequency, | |
289 | .tuner_set_bandwidth = stb6100_set_bandwidth, | |
290 | .tuner_get_bandwidth = stb6100_get_bandwidth, | |
291 | .tuner_set_rfsiggain = NULL, | |
292 | }; | |
293 | ||
294 | struct stb6100_config az6027_stb6100_config = { | |
295 | .tuner_address = 0xc0, | |
296 | .refclock = 27000000, | |
297 | }; | |
298 | ||
299 | ||
300 | /* check for mutex FIXME */ | |
301 | int az6027_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) | |
302 | { | |
303 | int ret = -1; | |
5f0e1cff | 304 | if (mutex_lock_interruptible(&d->usb_mutex)) |
76f9a820 | 305 | return -EAGAIN; |
5f0e1cff | 306 | |
76f9a820 | 307 | ret = usb_control_msg(d->udev, |
5f0e1cff MA |
308 | usb_rcvctrlpipe(d->udev, 0), |
309 | req, | |
310 | USB_TYPE_VENDOR | USB_DIR_IN, | |
311 | value, | |
312 | index, | |
313 | b, | |
314 | blen, | |
315 | 2000); | |
76f9a820 AX |
316 | |
317 | if (ret < 0) { | |
318 | warn("usb in operation failed. (%d)", ret); | |
319 | ret = -EIO; | |
320 | } else | |
321 | ret = 0; | |
322 | ||
5f0e1cff MA |
323 | deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index); |
324 | debug_dump(b, blen, deb_xfer); | |
76f9a820 | 325 | |
76f9a820 AX |
326 | mutex_unlock(&d->usb_mutex); |
327 | return ret; | |
328 | } | |
329 | ||
5f0e1cff MA |
330 | static int az6027_usb_out_op(struct dvb_usb_device *d, |
331 | u8 req, | |
332 | u16 value, | |
333 | u16 index, | |
334 | u8 *b, | |
335 | int blen) | |
76f9a820 AX |
336 | { |
337 | int ret; | |
5f0e1cff MA |
338 | |
339 | deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index); | |
340 | debug_dump(b, blen, deb_xfer); | |
341 | ||
342 | if (mutex_lock_interruptible(&d->usb_mutex)) | |
76f9a820 | 343 | return -EAGAIN; |
76f9a820 | 344 | |
5f0e1cff MA |
345 | ret = usb_control_msg(d->udev, |
346 | usb_sndctrlpipe(d->udev, 0), | |
347 | req, | |
348 | USB_TYPE_VENDOR | USB_DIR_OUT, | |
349 | value, | |
350 | index, | |
351 | b, | |
352 | blen, | |
353 | 2000); | |
354 | ||
355 | if (ret != blen) { | |
356 | warn("usb out operation failed. (%d)", ret); | |
76f9a820 AX |
357 | mutex_unlock(&d->usb_mutex); |
358 | return -EIO; | |
359 | } else{ | |
360 | mutex_unlock(&d->usb_mutex); | |
361 | return 0; | |
362 | } | |
363 | } | |
364 | ||
365 | static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) | |
366 | { | |
367 | int ret; | |
368 | u8 req; | |
369 | u16 value; | |
370 | u16 index; | |
371 | int blen; | |
5f0e1cff MA |
372 | |
373 | deb_info("%s %d", __func__, onoff); | |
374 | ||
76f9a820 AX |
375 | req = 0xBC; |
376 | value = onoff; | |
377 | index = 0; | |
5f0e1cff MA |
378 | blen = 0; |
379 | ||
380 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
381 | if (ret != 0) | |
382 | warn("usb out operation failed. (%d)", ret); | |
383 | ||
76f9a820 AX |
384 | return ret; |
385 | } | |
386 | ||
387 | /* keys for the enclosed remote control */ | |
2f4f58d6 | 388 | static struct rc_map_table rc_map_az6027_table[] = { |
4105ed5d MA |
389 | { 0x01, KEY_1 }, |
390 | { 0x02, KEY_2 }, | |
76f9a820 AX |
391 | }; |
392 | ||
393 | /* remote control stuff (does not work with my box) */ | |
394 | static int az6027_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | |
395 | { | |
396 | return 0; | |
397 | } | |
398 | ||
399 | /* | |
400 | int az6027_power_ctrl(struct dvb_usb_device *d, int onoff) | |
401 | { | |
402 | u8 v = onoff; | |
403 | return az6027_usb_out_op(d,0xBC,v,3,NULL,1); | |
404 | } | |
405 | */ | |
406 | ||
407 | static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, | |
5f0e1cff MA |
408 | int slot, |
409 | int address) | |
76f9a820 AX |
410 | { |
411 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
412 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
413 | ||
414 | int ret; | |
415 | u8 req; | |
416 | u16 value; | |
417 | u16 index; | |
418 | int blen; | |
32ec4576 | 419 | u8 *b; |
5f0e1cff MA |
420 | |
421 | if (slot != 0) | |
76f9a820 | 422 | return -EINVAL; |
5f0e1cff | 423 | |
32ec4576 DC |
424 | b = kmalloc(12, GFP_KERNEL); |
425 | if (!b) | |
426 | return -ENOMEM; | |
427 | ||
5f0e1cff | 428 | mutex_lock(&state->ca_mutex); |
76f9a820 AX |
429 | |
430 | req = 0xC1; | |
431 | value = address; | |
432 | index = 0; | |
433 | blen = 1; | |
5f0e1cff MA |
434 | |
435 | ret = az6027_usb_in_op(d, req, value, index, b, blen); | |
76f9a820 AX |
436 | if (ret < 0) { |
437 | warn("usb in operation failed. (%d)", ret); | |
438 | ret = -EINVAL; | |
5f0e1cff | 439 | } else { |
76f9a820 | 440 | ret = b[0]; |
76f9a820 | 441 | } |
5f0e1cff MA |
442 | |
443 | mutex_unlock(&state->ca_mutex); | |
32ec4576 | 444 | kfree(b); |
76f9a820 AX |
445 | return ret; |
446 | } | |
447 | ||
448 | static int az6027_ci_write_attribute_mem(struct dvb_ca_en50221 *ca, | |
5f0e1cff MA |
449 | int slot, |
450 | int address, | |
451 | u8 value) | |
76f9a820 AX |
452 | { |
453 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
454 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
5f0e1cff | 455 | |
76f9a820 AX |
456 | int ret; |
457 | u8 req; | |
458 | u16 value1; | |
459 | u16 index; | |
460 | int blen; | |
461 | ||
5f0e1cff MA |
462 | deb_info("%s %d", __func__, slot); |
463 | if (slot != 0) | |
76f9a820 | 464 | return -EINVAL; |
5f0e1cff MA |
465 | |
466 | mutex_lock(&state->ca_mutex); | |
76f9a820 AX |
467 | req = 0xC2; |
468 | value1 = address; | |
469 | index = value; | |
5f0e1cff | 470 | blen = 0; |
76f9a820 | 471 | |
5f0e1cff MA |
472 | ret = az6027_usb_out_op(d, req, value1, index, NULL, blen); |
473 | if (ret != 0) | |
474 | warn("usb out operation failed. (%d)", ret); | |
475 | ||
476 | mutex_unlock(&state->ca_mutex); | |
76f9a820 AX |
477 | return ret; |
478 | } | |
479 | ||
480 | static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca, | |
5f0e1cff MA |
481 | int slot, |
482 | u8 address) | |
76f9a820 AX |
483 | { |
484 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
485 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
486 | ||
487 | int ret; | |
488 | u8 req; | |
489 | u16 value; | |
490 | u16 index; | |
491 | int blen; | |
32ec4576 | 492 | u8 *b; |
5f0e1cff MA |
493 | |
494 | if (slot != 0) | |
76f9a820 | 495 | return -EINVAL; |
5f0e1cff | 496 | |
32ec4576 DC |
497 | b = kmalloc(12, GFP_KERNEL); |
498 | if (!b) | |
499 | return -ENOMEM; | |
500 | ||
5f0e1cff | 501 | mutex_lock(&state->ca_mutex); |
76f9a820 AX |
502 | |
503 | req = 0xC3; | |
504 | value = address; | |
505 | index = 0; | |
506 | blen = 2; | |
5f0e1cff MA |
507 | |
508 | ret = az6027_usb_in_op(d, req, value, index, b, blen); | |
76f9a820 AX |
509 | if (ret < 0) { |
510 | warn("usb in operation failed. (%d)", ret); | |
511 | ret = -EINVAL; | |
5f0e1cff MA |
512 | } else { |
513 | if (b[0] == 0) | |
76f9a820 | 514 | warn("Read CI IO error"); |
5f0e1cff | 515 | |
76f9a820 | 516 | ret = b[1]; |
5f0e1cff | 517 | deb_info("read cam data = %x from 0x%x", b[1], value); |
76f9a820 | 518 | } |
5f0e1cff MA |
519 | |
520 | mutex_unlock(&state->ca_mutex); | |
32ec4576 | 521 | kfree(b); |
76f9a820 AX |
522 | return ret; |
523 | } | |
524 | ||
525 | static int az6027_ci_write_cam_control(struct dvb_ca_en50221 *ca, | |
5f0e1cff MA |
526 | int slot, |
527 | u8 address, | |
528 | u8 value) | |
76f9a820 AX |
529 | { |
530 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
531 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
5f0e1cff | 532 | |
76f9a820 AX |
533 | int ret; |
534 | u8 req; | |
535 | u16 value1; | |
536 | u16 index; | |
537 | int blen; | |
538 | ||
5f0e1cff | 539 | if (slot != 0) |
76f9a820 | 540 | return -EINVAL; |
5f0e1cff MA |
541 | |
542 | mutex_lock(&state->ca_mutex); | |
76f9a820 AX |
543 | req = 0xC4; |
544 | value1 = address; | |
545 | index = value; | |
5f0e1cff MA |
546 | blen = 0; |
547 | ||
548 | ret = az6027_usb_out_op(d, req, value1, index, NULL, blen); | |
549 | if (ret != 0) { | |
550 | warn("usb out operation failed. (%d)", ret); | |
76f9a820 AX |
551 | goto failed; |
552 | } | |
5f0e1cff MA |
553 | |
554 | failed: | |
555 | mutex_unlock(&state->ca_mutex); | |
76f9a820 AX |
556 | return ret; |
557 | } | |
558 | ||
5f0e1cff | 559 | static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot) |
76f9a820 AX |
560 | { |
561 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
5f0e1cff | 562 | |
76f9a820 AX |
563 | int ret; |
564 | u8 req; | |
565 | u16 value; | |
566 | u16 index; | |
567 | int blen; | |
32ec4576 DC |
568 | u8 *b; |
569 | ||
570 | b = kmalloc(12, GFP_KERNEL); | |
571 | if (!b) | |
572 | return -ENOMEM; | |
76f9a820 AX |
573 | |
574 | req = 0xC8; | |
575 | value = 0; | |
576 | index = 0; | |
577 | blen = 1; | |
5f0e1cff MA |
578 | |
579 | ret = az6027_usb_in_op(d, req, value, index, b, blen); | |
76f9a820 AX |
580 | if (ret < 0) { |
581 | warn("usb in operation failed. (%d)", ret); | |
582 | ret = -EIO; | |
583 | } else{ | |
584 | ret = b[0]; | |
585 | } | |
32ec4576 | 586 | kfree(b); |
76f9a820 AX |
587 | return ret; |
588 | } | |
589 | ||
5f0e1cff | 590 | static int az6027_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot) |
76f9a820 AX |
591 | { |
592 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
593 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
5f0e1cff MA |
594 | |
595 | int ret, i; | |
76f9a820 AX |
596 | u8 req; |
597 | u16 value; | |
598 | u16 index; | |
599 | int blen; | |
600 | ||
5f0e1cff MA |
601 | mutex_lock(&state->ca_mutex); |
602 | ||
76f9a820 AX |
603 | req = 0xC6; |
604 | value = 1; | |
605 | index = 0; | |
5f0e1cff MA |
606 | blen = 0; |
607 | ||
608 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); | |
609 | if (ret != 0) { | |
610 | warn("usb out operation failed. (%d)", ret); | |
76f9a820 AX |
611 | goto failed; |
612 | } | |
5f0e1cff MA |
613 | |
614 | msleep(500); | |
76f9a820 AX |
615 | req = 0xC6; |
616 | value = 0; | |
617 | index = 0; | |
5f0e1cff MA |
618 | blen = 0; |
619 | ||
620 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); | |
621 | if (ret != 0) { | |
622 | warn("usb out operation failed. (%d)", ret); | |
76f9a820 AX |
623 | goto failed; |
624 | } | |
625 | ||
5f0e1cff | 626 | for (i = 0; i < 15; i++) { |
76f9a820 | 627 | msleep(100); |
5f0e1cff MA |
628 | |
629 | if (CI_CamReady(ca, slot)) { | |
76f9a820 AX |
630 | deb_info("CAM Ready"); |
631 | break; | |
632 | } | |
633 | } | |
634 | msleep(5000); | |
635 | ||
5f0e1cff MA |
636 | failed: |
637 | mutex_unlock(&state->ca_mutex); | |
76f9a820 AX |
638 | return ret; |
639 | } | |
640 | ||
5f0e1cff | 641 | static int az6027_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) |
76f9a820 | 642 | { |
76f9a820 AX |
643 | return 0; |
644 | } | |
645 | ||
5f0e1cff | 646 | static int az6027_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) |
76f9a820 AX |
647 | { |
648 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
649 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
5f0e1cff | 650 | |
76f9a820 AX |
651 | int ret; |
652 | u8 req; | |
653 | u16 value; | |
654 | u16 index; | |
655 | int blen; | |
5f0e1cff | 656 | |
76f9a820 | 657 | deb_info("%s", __func__); |
5f0e1cff | 658 | mutex_lock(&state->ca_mutex); |
76f9a820 AX |
659 | req = 0xC7; |
660 | value = 1; | |
661 | index = 0; | |
5f0e1cff MA |
662 | blen = 0; |
663 | ||
664 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); | |
665 | if (ret != 0) { | |
666 | warn("usb out operation failed. (%d)", ret); | |
76f9a820 AX |
667 | goto failed; |
668 | } | |
76f9a820 | 669 | |
5f0e1cff MA |
670 | failed: |
671 | mutex_unlock(&state->ca_mutex); | |
76f9a820 AX |
672 | return ret; |
673 | } | |
674 | ||
5f0e1cff | 675 | static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) |
76f9a820 AX |
676 | { |
677 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; | |
678 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
679 | int ret; | |
680 | u8 req; | |
681 | u16 value; | |
682 | u16 index; | |
683 | int blen; | |
32ec4576 | 684 | u8 *b; |
5f0e1cff | 685 | |
32ec4576 DC |
686 | b = kmalloc(12, GFP_KERNEL); |
687 | if (!b) | |
688 | return -ENOMEM; | |
5f0e1cff | 689 | mutex_lock(&state->ca_mutex); |
76f9a820 AX |
690 | |
691 | req = 0xC5; | |
692 | value = 0; | |
693 | index = 0; | |
694 | blen = 1; | |
5f0e1cff MA |
695 | |
696 | ret = az6027_usb_in_op(d, req, value, index, b, blen); | |
76f9a820 AX |
697 | if (ret < 0) { |
698 | warn("usb in operation failed. (%d)", ret); | |
699 | ret = -EIO; | |
700 | } else | |
701 | ret = 0; | |
5f0e1cff | 702 | |
a18e6591 | 703 | if (!ret && b[0] == 1) { |
5f0e1cff MA |
704 | ret = DVB_CA_EN50221_POLL_CAM_PRESENT | |
705 | DVB_CA_EN50221_POLL_CAM_READY; | |
76f9a820 AX |
706 | } |
707 | ||
5f0e1cff | 708 | mutex_unlock(&state->ca_mutex); |
32ec4576 | 709 | kfree(b); |
76f9a820 AX |
710 | return ret; |
711 | } | |
712 | ||
713 | ||
714 | static void az6027_ci_uninit(struct dvb_usb_device *d) | |
715 | { | |
716 | struct az6027_device_state *state; | |
717 | ||
718 | deb_info("%s", __func__); | |
719 | ||
720 | if (NULL == d) | |
721 | return; | |
722 | ||
723 | state = (struct az6027_device_state *)d->priv; | |
724 | if (NULL == state) | |
725 | return; | |
726 | ||
727 | if (NULL == state->ca.data) | |
728 | return; | |
729 | ||
730 | dvb_ca_en50221_release(&state->ca); | |
731 | ||
732 | memset(&state->ca, 0, sizeof(state->ca)); | |
733 | } | |
734 | ||
735 | ||
736 | static int az6027_ci_init(struct dvb_usb_adapter *a) | |
737 | { | |
738 | struct dvb_usb_device *d = a->dev; | |
739 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; | |
740 | int ret; | |
741 | ||
5f0e1cff | 742 | deb_info("%s", __func__); |
76f9a820 AX |
743 | |
744 | mutex_init(&state->ca_mutex); | |
745 | ||
5f0e1cff MA |
746 | state->ca.owner = THIS_MODULE; |
747 | state->ca.read_attribute_mem = az6027_ci_read_attribute_mem; | |
748 | state->ca.write_attribute_mem = az6027_ci_write_attribute_mem; | |
749 | state->ca.read_cam_control = az6027_ci_read_cam_control; | |
750 | state->ca.write_cam_control = az6027_ci_write_cam_control; | |
751 | state->ca.slot_reset = az6027_ci_slot_reset; | |
752 | state->ca.slot_shutdown = az6027_ci_slot_shutdown; | |
753 | state->ca.slot_ts_enable = az6027_ci_slot_ts_enable; | |
754 | state->ca.poll_slot_status = az6027_ci_poll_slot_status; | |
755 | state->ca.data = d; | |
756 | ||
757 | ret = dvb_ca_en50221_init(&a->dvb_adap, | |
758 | &state->ca, | |
759 | 0, /* flags */ | |
760 | 1);/* n_slots */ | |
761 | if (ret != 0) { | |
762 | err("Cannot initialize CI: Error %d.", ret); | |
763 | memset(&state->ca, 0, sizeof(state->ca)); | |
76f9a820 AX |
764 | return ret; |
765 | } | |
766 | ||
5f0e1cff | 767 | deb_info("CI initialized."); |
76f9a820 AX |
768 | |
769 | return 0; | |
770 | } | |
771 | ||
4105ed5d | 772 | /* |
5f0e1cff | 773 | static int az6027_read_mac_addr(struct dvb_usb_device *d, u8 mac[6]) |
76f9a820 AX |
774 | { |
775 | az6027_usb_in_op(d, 0xb7, 6, 0, &mac[0], 6); | |
776 | return 0; | |
777 | } | |
4105ed5d | 778 | */ |
76f9a820 AX |
779 | |
780 | static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) | |
781 | { | |
5f0e1cff | 782 | |
76f9a820 | 783 | u8 buf; |
5f0e1cff MA |
784 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
785 | ||
76f9a820 AX |
786 | struct i2c_msg i2c_msg = { |
787 | .addr = 0x99, | |
788 | .flags = 0, | |
789 | .buf = &buf, | |
790 | .len = 1 | |
791 | }; | |
5f0e1cff MA |
792 | |
793 | /* | |
794 | * 2 --18v | |
795 | * 1 --13v | |
796 | * 0 --off | |
797 | */ | |
76f9a820 AX |
798 | switch (voltage) { |
799 | case SEC_VOLTAGE_13: | |
5f0e1cff | 800 | buf = 1; |
db3ca1d5 | 801 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
76f9a820 | 802 | break; |
5f0e1cff | 803 | |
76f9a820 | 804 | case SEC_VOLTAGE_18: |
5f0e1cff | 805 | buf = 2; |
db3ca1d5 | 806 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
76f9a820 | 807 | break; |
5f0e1cff | 808 | |
76f9a820 | 809 | case SEC_VOLTAGE_OFF: |
5f0e1cff | 810 | buf = 0; |
db3ca1d5 | 811 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
76f9a820 | 812 | break; |
5f0e1cff | 813 | |
76f9a820 AX |
814 | default: |
815 | return -EINVAL; | |
816 | } | |
817 | return 0; | |
818 | } | |
819 | ||
820 | ||
821 | static int az6027_frontend_poweron(struct dvb_usb_adapter *adap) | |
822 | { | |
823 | int ret; | |
824 | u8 req; | |
825 | u16 value; | |
826 | u16 index; | |
827 | int blen; | |
828 | ||
829 | req = 0xBC; | |
5f0e1cff | 830 | value = 1; /* power on */ |
76f9a820 | 831 | index = 3; |
5f0e1cff MA |
832 | blen = 0; |
833 | ||
834 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
835 | if (ret != 0) | |
836 | return -EIO; | |
76f9a820 | 837 | |
76f9a820 AX |
838 | return 0; |
839 | } | |
840 | static int az6027_frontend_reset(struct dvb_usb_adapter *adap) | |
841 | { | |
842 | int ret; | |
843 | u8 req; | |
844 | u16 value; | |
845 | u16 index; | |
846 | int blen; | |
847 | ||
5f0e1cff | 848 | /* reset demodulator */ |
76f9a820 | 849 | req = 0xC0; |
5f0e1cff | 850 | value = 1; /* high */ |
76f9a820 | 851 | index = 3; |
5f0e1cff MA |
852 | blen = 0; |
853 | ||
854 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
855 | if (ret != 0) | |
856 | return -EIO; | |
76f9a820 | 857 | |
76f9a820 | 858 | req = 0xC0; |
5f0e1cff | 859 | value = 0; /* low */ |
76f9a820 | 860 | index = 3; |
5f0e1cff | 861 | blen = 0; |
76f9a820 | 862 | msleep_interruptible(200); |
5f0e1cff MA |
863 | |
864 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
865 | if (ret != 0) | |
866 | return -EIO; | |
867 | ||
76f9a820 | 868 | msleep_interruptible(200); |
5f0e1cff | 869 | |
76f9a820 | 870 | req = 0xC0; |
5f0e1cff | 871 | value = 1; /*high */ |
76f9a820 | 872 | index = 3; |
5f0e1cff MA |
873 | blen = 0; |
874 | ||
875 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
876 | if (ret != 0) | |
877 | return -EIO; | |
76f9a820 | 878 | |
76f9a820 AX |
879 | msleep_interruptible(200); |
880 | return 0; | |
881 | } | |
882 | ||
5f0e1cff | 883 | static int az6027_frontend_tsbypass(struct dvb_usb_adapter *adap, int onoff) |
76f9a820 AX |
884 | { |
885 | int ret; | |
886 | u8 req; | |
887 | u16 value; | |
888 | u16 index; | |
889 | int blen; | |
5f0e1cff MA |
890 | |
891 | /* TS passthrough */ | |
76f9a820 AX |
892 | req = 0xC7; |
893 | value = onoff; | |
894 | index = 0; | |
5f0e1cff MA |
895 | blen = 0; |
896 | ||
897 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); | |
898 | if (ret != 0) | |
899 | return -EIO; | |
76f9a820 | 900 | |
76f9a820 AX |
901 | return 0; |
902 | } | |
903 | ||
904 | static int az6027_frontend_attach(struct dvb_usb_adapter *adap) | |
905 | { | |
906 | ||
907 | az6027_frontend_poweron(adap); | |
908 | az6027_frontend_reset(adap); | |
5f0e1cff MA |
909 | |
910 | deb_info("adap = %p, dev = %p\n", adap, adap->dev); | |
77eed219 | 911 | adap->fe_adap[0].fe = stb0899_attach(&az6027_stb0899_config, &adap->dev->i2c_adap); |
5f0e1cff | 912 | |
77eed219 | 913 | if (adap->fe_adap[0].fe) { |
5f0e1cff | 914 | deb_info("found STB0899 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb0899_config.demod_address); |
77eed219 | 915 | if (stb6100_attach(adap->fe_adap[0].fe, &az6027_stb6100_config, &adap->dev->i2c_adap)) { |
5f0e1cff | 916 | deb_info("found STB6100 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb6100_config.tuner_address); |
77eed219 | 917 | adap->fe_adap[0].fe->ops.set_voltage = az6027_set_voltage; |
76f9a820 AX |
918 | az6027_ci_init(adap); |
919 | } else { | |
77eed219 | 920 | adap->fe_adap[0].fe = NULL; |
76f9a820 | 921 | } |
5f0e1cff | 922 | } else |
76f9a820 AX |
923 | warn("no front-end attached\n"); |
924 | ||
5f0e1cff | 925 | az6027_frontend_tsbypass(adap, 0); |
76f9a820 AX |
926 | |
927 | return 0; | |
928 | } | |
929 | ||
930 | static struct dvb_usb_device_properties az6027_properties; | |
931 | ||
5f0e1cff | 932 | static void az6027_usb_disconnect(struct usb_interface *intf) |
76f9a820 | 933 | { |
5f0e1cff MA |
934 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
935 | az6027_ci_uninit(d); | |
936 | dvb_usb_device_exit(intf); | |
76f9a820 AX |
937 | } |
938 | ||
939 | ||
940 | static int az6027_usb_probe(struct usb_interface *intf, | |
5f0e1cff | 941 | const struct usb_device_id *id) |
76f9a820 | 942 | { |
5f0e1cff MA |
943 | return dvb_usb_device_init(intf, |
944 | &az6027_properties, | |
945 | THIS_MODULE, | |
946 | NULL, | |
947 | adapter_nr); | |
76f9a820 AX |
948 | } |
949 | ||
950 | /* I2C */ | |
5f0e1cff | 951 | static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) |
76f9a820 AX |
952 | { |
953 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | |
5f0e1cff | 954 | int i = 0, j = 0, len = 0; |
76f9a820 AX |
955 | u16 index; |
956 | u16 value; | |
957 | int length; | |
958 | u8 req; | |
32ec4576 DC |
959 | u8 *data; |
960 | ||
961 | data = kmalloc(256, GFP_KERNEL); | |
962 | if (!data) | |
963 | return -ENOMEM; | |
5f0e1cff | 964 | |
32ec4576 DC |
965 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) { |
966 | kfree(data); | |
76f9a820 | 967 | return -EAGAIN; |
32ec4576 | 968 | } |
5f0e1cff | 969 | |
76f9a820 AX |
970 | if (num > 2) |
971 | warn("more than 2 i2c messages at a time is not handled yet. TODO."); | |
972 | ||
973 | for (i = 0; i < num; i++) { | |
5f0e1cff MA |
974 | |
975 | if (msg[i].addr == 0x99) { | |
76f9a820 AX |
976 | req = 0xBE; |
977 | index = 0; | |
978 | value = msg[i].buf[0] & 0x00ff; | |
979 | length = 1; | |
5f0e1cff | 980 | az6027_usb_out_op(d, req, value, index, data, length); |
76f9a820 | 981 | } |
5f0e1cff MA |
982 | |
983 | if (msg[i].addr == 0xd0) { | |
76f9a820 | 984 | /* write/read request */ |
5f0e1cff | 985 | if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) { |
76f9a820 AX |
986 | req = 0xB9; |
987 | index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); | |
988 | value = msg[i].addr + (msg[i].len << 8); | |
5f0e1cff | 989 | length = msg[i + 1].len + 6; |
db3ca1d5 | 990 | az6027_usb_in_op(d, req, value, index, data, length); |
5f0e1cff MA |
991 | len = msg[i + 1].len; |
992 | for (j = 0; j < len; j++) | |
993 | msg[i + 1].buf[j] = data[j + 5]; | |
994 | ||
76f9a820 | 995 | i++; |
5f0e1cff MA |
996 | } else { |
997 | ||
6120792b MN |
998 | /* demod 16bit addr */ |
999 | req = 0xBD; | |
1000 | index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); | |
1001 | value = msg[i].addr + (2 << 8); | |
1002 | length = msg[i].len - 2; | |
1003 | len = msg[i].len - 2; | |
1004 | for (j = 0; j < len; j++) | |
1005 | data[j] = msg[i].buf[j + 2]; | |
5f0e1cff | 1006 | az6027_usb_out_op(d, req, value, index, data, length); |
76f9a820 AX |
1007 | } |
1008 | } | |
5f0e1cff MA |
1009 | |
1010 | if (msg[i].addr == 0xc0) { | |
76f9a820 | 1011 | if (msg[i].flags & I2C_M_RD) { |
5f0e1cff | 1012 | |
76f9a820 AX |
1013 | req = 0xB9; |
1014 | index = 0x0; | |
5f0e1cff | 1015 | value = msg[i].addr; |
76f9a820 | 1016 | length = msg[i].len + 6; |
db3ca1d5 | 1017 | az6027_usb_in_op(d, req, value, index, data, length); |
76f9a820 | 1018 | len = msg[i].len; |
5f0e1cff MA |
1019 | for (j = 0; j < len; j++) |
1020 | msg[i].buf[j] = data[j + 5]; | |
1021 | ||
1022 | } else { | |
1023 | ||
76f9a820 AX |
1024 | req = 0xBD; |
1025 | index = msg[i].buf[0] & 0x00FF; | |
1026 | value = msg[i].addr + (1 << 8); | |
1027 | length = msg[i].len - 1; | |
1028 | len = msg[i].len - 1; | |
5f0e1cff MA |
1029 | |
1030 | for (j = 0; j < len; j++) | |
1031 | data[j] = msg[i].buf[j + 1]; | |
1032 | ||
1033 | az6027_usb_out_op(d, req, value, index, data, length); | |
76f9a820 AX |
1034 | } |
1035 | } | |
5f0e1cff | 1036 | } |
76f9a820 | 1037 | mutex_unlock(&d->i2c_mutex); |
32ec4576 | 1038 | kfree(data); |
5f0e1cff | 1039 | |
76f9a820 AX |
1040 | return i; |
1041 | } | |
1042 | ||
1043 | ||
1044 | static u32 az6027_i2c_func(struct i2c_adapter *adapter) | |
1045 | { | |
1046 | return I2C_FUNC_I2C; | |
1047 | } | |
1048 | ||
1049 | static struct i2c_algorithm az6027_i2c_algo = { | |
1050 | .master_xfer = az6027_i2c_xfer, | |
1051 | .functionality = az6027_i2c_func, | |
1052 | }; | |
1053 | ||
5f0e1cff MA |
1054 | int az6027_identify_state(struct usb_device *udev, |
1055 | struct dvb_usb_device_properties *props, | |
1056 | struct dvb_usb_device_description **desc, | |
1057 | int *cold) | |
76f9a820 | 1058 | { |
32ec4576 DC |
1059 | u8 *b; |
1060 | s16 ret; | |
1061 | ||
1062 | b = kmalloc(16, GFP_KERNEL); | |
1063 | if (!b) | |
1064 | return -ENOMEM; | |
1065 | ||
1066 | ret = usb_control_msg(udev, | |
5f0e1cff MA |
1067 | usb_rcvctrlpipe(udev, 0), |
1068 | 0xb7, | |
1069 | USB_TYPE_VENDOR | USB_DIR_IN, | |
1070 | 6, | |
1071 | 0, | |
1072 | b, | |
1073 | 6, | |
1074 | USB_CTRL_GET_TIMEOUT); | |
76f9a820 AX |
1075 | |
1076 | *cold = ret <= 0; | |
32ec4576 | 1077 | kfree(b); |
76f9a820 AX |
1078 | deb_info("cold: %d\n", *cold); |
1079 | return 0; | |
1080 | } | |
1081 | ||
1082 | ||
5f0e1cff | 1083 | static struct usb_device_id az6027_usb_table[] = { |
3c3233ec | 1084 | { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_AZ6027) }, |
20d2c56d OR |
1085 | { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V1) }, |
1086 | { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) }, | |
823b63b4 OR |
1087 | { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) }, |
1088 | { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) }, | |
10304ca6 | 1089 | { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_SAT) }, |
3c3233ec | 1090 | { }, |
76f9a820 AX |
1091 | }; |
1092 | ||
1093 | MODULE_DEVICE_TABLE(usb, az6027_usb_table); | |
1094 | ||
1095 | static struct dvb_usb_device_properties az6027_properties = { | |
1096 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | |
1097 | .usb_ctrl = CYPRESS_FX2, | |
76f9a820 AX |
1098 | .firmware = "dvb-usb-az6027-03.fw", |
1099 | .no_reconnect = 1, | |
1100 | ||
1101 | .size_of_priv = sizeof(struct az6027_device_state), | |
1102 | .identify_state = az6027_identify_state, | |
1103 | .num_adapters = 1, | |
1104 | .adapter = { | |
1105 | { | |
77eed219 MK |
1106 | .num_frontends = 1, |
1107 | .fe = {{ | |
76f9a820 AX |
1108 | .streaming_ctrl = az6027_streaming_ctrl, |
1109 | .frontend_attach = az6027_frontend_attach, | |
1110 | ||
1111 | /* parameter for the MPEG2-data transfer */ | |
1112 | .stream = { | |
1113 | .type = USB_BULK, | |
1114 | .count = 10, | |
1115 | .endpoint = 0x02, | |
1116 | .u = { | |
1117 | .bulk = { | |
1118 | .buffersize = 4096, | |
1119 | } | |
1120 | } | |
1121 | }, | |
77eed219 | 1122 | }}, |
76f9a820 AX |
1123 | } |
1124 | }, | |
5f0e1cff MA |
1125 | /* |
1126 | .power_ctrl = az6027_power_ctrl, | |
1127 | .read_mac_address = az6027_read_mac_addr, | |
1128 | */ | |
f72a27b8 | 1129 | .rc.legacy = { |
2f4f58d6 MCC |
1130 | .rc_map_table = rc_map_az6027_table, |
1131 | .rc_map_size = ARRAY_SIZE(rc_map_az6027_table), | |
f72a27b8 MCC |
1132 | .rc_interval = 400, |
1133 | .rc_query = az6027_rc_query, | |
1134 | }, | |
1135 | ||
76f9a820 AX |
1136 | .i2c_algo = &az6027_i2c_algo, |
1137 | ||
10304ca6 | 1138 | .num_device_descs = 6, |
76f9a820 | 1139 | .devices = { |
5f0e1cff MA |
1140 | { |
1141 | .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)", | |
1142 | .cold_ids = { &az6027_usb_table[0], NULL }, | |
1143 | .warm_ids = { NULL }, | |
20d2c56d OR |
1144 | }, { |
1145 | .name = "TERRATEC S7", | |
1146 | .cold_ids = { &az6027_usb_table[1], NULL }, | |
1147 | .warm_ids = { NULL }, | |
1148 | }, { | |
1149 | .name = "TERRATEC S7 MKII", | |
1150 | .cold_ids = { &az6027_usb_table[2], NULL }, | |
1151 | .warm_ids = { NULL }, | |
1152 | }, { | |
1153 | .name = "Technisat SkyStar USB 2 HD CI", | |
1154 | .cold_ids = { &az6027_usb_table[3], NULL }, | |
1155 | .warm_ids = { NULL }, | |
1156 | }, { | |
1157 | .name = "Technisat SkyStar USB 2 HD CI", | |
1158 | .cold_ids = { &az6027_usb_table[4], NULL }, | |
1159 | .warm_ids = { NULL }, | |
10304ca6 SD |
1160 | }, { |
1161 | .name = "Elgato EyeTV Sat", | |
1162 | .cold_ids = { &az6027_usb_table[5], NULL }, | |
1163 | .warm_ids = { NULL }, | |
76f9a820 | 1164 | }, |
5f0e1cff | 1165 | { NULL }, |
76f9a820 AX |
1166 | } |
1167 | }; | |
1168 | ||
1169 | /* usb specific object needed to register this driver with the usb subsystem */ | |
1170 | static struct usb_driver az6027_usb_driver = { | |
1171 | .name = "dvb_usb_az6027", | |
1172 | .probe = az6027_usb_probe, | |
76f9a820 AX |
1173 | .disconnect = az6027_usb_disconnect, |
1174 | .id_table = az6027_usb_table, | |
1175 | }; | |
1176 | ||
ecb3b2b3 | 1177 | module_usb_driver(az6027_usb_driver); |
76f9a820 AX |
1178 | |
1179 | MODULE_AUTHOR("Adams Xu <Adams.xu@azwave.com.cn>"); | |
1180 | MODULE_DESCRIPTION("Driver for AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)"); | |
1181 | MODULE_VERSION("1.0"); | |
1182 | MODULE_LICENSE("GPL"); |