Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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" |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 13 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 14 | #include "stb0899_drv.h" |
| 15 | #include "stb0899_reg.h" |
| 16 | #include "stb0899_cfg.h" |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 17 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 18 | #include "stb6100.h" |
| 19 | #include "stb6100_cfg.h" |
| 20 | #include "dvb_ca_en50221.h" |
| 21 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 22 | int dvb_usb_az6027_debug; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 23 | module_param_named(debug, dvb_usb_az6027_debug, int, 0644); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 36 | /* 0x0000000b, SYSREG */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 43 | { STB0899_DISSTATUS , 0x20 }, |
| 44 | { STB0899_DISF22 , 0x99 }, |
| 45 | { STB0899_DISF22RX , 0xa8 }, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 46 | /* SYSREG ? */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 }, |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 127 | { STB0899_RTC , 0x23 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 128 | { STB0899_TMGCFG , 0x4e }, |
| 129 | { STB0899_AGC2REF , 0x34 }, |
| 130 | { STB0899_TLSR , 0x84 }, |
| 131 | { STB0899_CFD , 0xf7 }, |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 132 | { STB0899_ACLC , 0x87 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 }, |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 185 | { STB0899_FECM , 0x01 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 186 | { STB0899_VTH12 , 0xb0 }, |
| 187 | { STB0899_VTH23 , 0x7a }, |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 188 | { STB0899_VTH34 , 0x58 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 }, |
Mauro Carvalho Chehab | 000f64e | 2010-03-11 01:58:12 -0300 | [diff] [blame] | 197 | { STB0899_TSLPL , 0x12 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 264 | .demod_address = 0xd0, /* 0x68, 0xd0 >> 1 */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 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 */ |
Mauro Carvalho Chehab | 64592d0 | 2012-10-27 14:05:59 -0300 | [diff] [blame] | 301 | static int az6027_usb_in_op(struct dvb_usb_device *d, u8 req, |
| 302 | u16 value, u16 index, u8 *b, int blen) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 303 | { |
| 304 | int ret = -1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 305 | if (mutex_lock_interruptible(&d->usb_mutex)) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 306 | return -EAGAIN; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 307 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 308 | ret = usb_control_msg(d->udev, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 309 | usb_rcvctrlpipe(d->udev, 0), |
| 310 | req, |
| 311 | USB_TYPE_VENDOR | USB_DIR_IN, |
| 312 | value, |
| 313 | index, |
| 314 | b, |
| 315 | blen, |
| 316 | 2000); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 317 | |
| 318 | if (ret < 0) { |
| 319 | warn("usb in operation failed. (%d)", ret); |
| 320 | ret = -EIO; |
| 321 | } else |
| 322 | ret = 0; |
| 323 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 324 | deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index); |
| 325 | debug_dump(b, blen, deb_xfer); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 326 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 327 | mutex_unlock(&d->usb_mutex); |
| 328 | return ret; |
| 329 | } |
| 330 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 331 | static int az6027_usb_out_op(struct dvb_usb_device *d, |
| 332 | u8 req, |
| 333 | u16 value, |
| 334 | u16 index, |
| 335 | u8 *b, |
| 336 | int blen) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 337 | { |
| 338 | int ret; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 339 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 340 | deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index); |
| 341 | debug_dump(b, blen, deb_xfer); |
| 342 | |
| 343 | if (mutex_lock_interruptible(&d->usb_mutex)) |
| 344 | return -EAGAIN; |
| 345 | |
| 346 | ret = usb_control_msg(d->udev, |
| 347 | usb_sndctrlpipe(d->udev, 0), |
| 348 | req, |
| 349 | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 350 | value, |
| 351 | index, |
| 352 | b, |
| 353 | blen, |
| 354 | 2000); |
| 355 | |
| 356 | if (ret != blen) { |
| 357 | warn("usb out operation failed. (%d)", ret); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 358 | mutex_unlock(&d->usb_mutex); |
| 359 | return -EIO; |
| 360 | } else{ |
| 361 | mutex_unlock(&d->usb_mutex); |
| 362 | return 0; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 367 | { |
| 368 | int ret; |
| 369 | u8 req; |
| 370 | u16 value; |
| 371 | u16 index; |
| 372 | int blen; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 373 | |
| 374 | deb_info("%s %d", __func__, onoff); |
| 375 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 376 | req = 0xBC; |
| 377 | value = onoff; |
| 378 | index = 0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 379 | blen = 0; |
| 380 | |
| 381 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 382 | if (ret != 0) |
| 383 | warn("usb out operation failed. (%d)", ret); |
| 384 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | /* keys for the enclosed remote control */ |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 389 | static struct rc_map_table rc_map_az6027_table[] = { |
Manu Abraham | 4105ed5 | 2010-02-14 17:07:28 -0300 | [diff] [blame] | 390 | { 0x01, KEY_1 }, |
| 391 | { 0x02, KEY_2 }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 392 | }; |
| 393 | |
| 394 | /* remote control stuff (does not work with my box) */ |
| 395 | static int az6027_rc_query(struct dvb_usb_device *d, u32 *event, int *state) |
| 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | int az6027_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 402 | { |
| 403 | u8 v = onoff; |
| 404 | return az6027_usb_out_op(d,0xBC,v,3,NULL,1); |
| 405 | } |
| 406 | */ |
| 407 | |
| 408 | static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 409 | int slot, |
| 410 | int address) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 411 | { |
| 412 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 413 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
| 414 | |
| 415 | int ret; |
| 416 | u8 req; |
| 417 | u16 value; |
| 418 | u16 index; |
| 419 | int blen; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 420 | u8 *b; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 421 | |
| 422 | if (slot != 0) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 423 | return -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 424 | |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 425 | b = kmalloc(12, GFP_KERNEL); |
| 426 | if (!b) |
| 427 | return -ENOMEM; |
| 428 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 429 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 430 | |
| 431 | req = 0xC1; |
| 432 | value = address; |
| 433 | index = 0; |
| 434 | blen = 1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 435 | |
| 436 | ret = az6027_usb_in_op(d, req, value, index, b, blen); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 437 | if (ret < 0) { |
| 438 | warn("usb in operation failed. (%d)", ret); |
| 439 | ret = -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 440 | } else { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 441 | ret = b[0]; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 442 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 443 | |
| 444 | mutex_unlock(&state->ca_mutex); |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 445 | kfree(b); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static int az6027_ci_write_attribute_mem(struct dvb_ca_en50221 *ca, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 450 | int slot, |
| 451 | int address, |
| 452 | u8 value) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 453 | { |
| 454 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 455 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 456 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 457 | int ret; |
| 458 | u8 req; |
| 459 | u16 value1; |
| 460 | u16 index; |
| 461 | int blen; |
| 462 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 463 | deb_info("%s %d", __func__, slot); |
| 464 | if (slot != 0) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 465 | return -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 466 | |
| 467 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 468 | req = 0xC2; |
| 469 | value1 = address; |
| 470 | index = value; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 471 | blen = 0; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 472 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 473 | ret = az6027_usb_out_op(d, req, value1, index, NULL, blen); |
| 474 | if (ret != 0) |
| 475 | warn("usb out operation failed. (%d)", ret); |
| 476 | |
| 477 | mutex_unlock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 482 | int slot, |
| 483 | u8 address) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 484 | { |
| 485 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 486 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
| 487 | |
| 488 | int ret; |
| 489 | u8 req; |
| 490 | u16 value; |
| 491 | u16 index; |
| 492 | int blen; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 493 | u8 *b; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 494 | |
| 495 | if (slot != 0) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 496 | return -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 497 | |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 498 | b = kmalloc(12, GFP_KERNEL); |
| 499 | if (!b) |
| 500 | return -ENOMEM; |
| 501 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 502 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 503 | |
| 504 | req = 0xC3; |
| 505 | value = address; |
| 506 | index = 0; |
| 507 | blen = 2; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 508 | |
| 509 | ret = az6027_usb_in_op(d, req, value, index, b, blen); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 510 | if (ret < 0) { |
| 511 | warn("usb in operation failed. (%d)", ret); |
| 512 | ret = -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 513 | } else { |
| 514 | if (b[0] == 0) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 515 | warn("Read CI IO error"); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 516 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 517 | ret = b[1]; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 518 | deb_info("read cam data = %x from 0x%x", b[1], value); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 519 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 520 | |
| 521 | mutex_unlock(&state->ca_mutex); |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 522 | kfree(b); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 523 | return ret; |
| 524 | } |
| 525 | |
| 526 | static int az6027_ci_write_cam_control(struct dvb_ca_en50221 *ca, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 527 | int slot, |
| 528 | u8 address, |
| 529 | u8 value) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 530 | { |
| 531 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 532 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 533 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 534 | int ret; |
| 535 | u8 req; |
| 536 | u16 value1; |
| 537 | u16 index; |
| 538 | int blen; |
| 539 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 540 | if (slot != 0) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 541 | return -EINVAL; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 542 | |
| 543 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 544 | req = 0xC4; |
| 545 | value1 = address; |
| 546 | index = value; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 547 | blen = 0; |
| 548 | |
| 549 | ret = az6027_usb_out_op(d, req, value1, index, NULL, blen); |
| 550 | if (ret != 0) { |
| 551 | warn("usb out operation failed. (%d)", ret); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 552 | goto failed; |
| 553 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 554 | |
| 555 | failed: |
| 556 | mutex_unlock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 557 | return ret; |
| 558 | } |
| 559 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 560 | static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 561 | { |
| 562 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 563 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 564 | int ret; |
| 565 | u8 req; |
| 566 | u16 value; |
| 567 | u16 index; |
| 568 | int blen; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 569 | u8 *b; |
| 570 | |
| 571 | b = kmalloc(12, GFP_KERNEL); |
| 572 | if (!b) |
| 573 | return -ENOMEM; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 574 | |
| 575 | req = 0xC8; |
| 576 | value = 0; |
| 577 | index = 0; |
| 578 | blen = 1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 579 | |
| 580 | ret = az6027_usb_in_op(d, req, value, index, b, blen); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 581 | if (ret < 0) { |
| 582 | warn("usb in operation failed. (%d)", ret); |
| 583 | ret = -EIO; |
| 584 | } else{ |
| 585 | ret = b[0]; |
| 586 | } |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 587 | kfree(b); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 591 | static int az6027_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 592 | { |
| 593 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 594 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 595 | |
| 596 | int ret, i; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 597 | u8 req; |
| 598 | u16 value; |
| 599 | u16 index; |
| 600 | int blen; |
| 601 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 602 | mutex_lock(&state->ca_mutex); |
| 603 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 604 | req = 0xC6; |
| 605 | value = 1; |
| 606 | index = 0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 607 | blen = 0; |
| 608 | |
| 609 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); |
| 610 | if (ret != 0) { |
| 611 | warn("usb out operation failed. (%d)", ret); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 612 | goto failed; |
| 613 | } |
| 614 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 615 | msleep(500); |
| 616 | req = 0xC6; |
| 617 | value = 0; |
| 618 | index = 0; |
| 619 | blen = 0; |
| 620 | |
| 621 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); |
| 622 | if (ret != 0) { |
| 623 | warn("usb out operation failed. (%d)", ret); |
| 624 | goto failed; |
| 625 | } |
| 626 | |
| 627 | for (i = 0; i < 15; i++) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 628 | msleep(100); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 629 | |
| 630 | if (CI_CamReady(ca, slot)) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 631 | deb_info("CAM Ready"); |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | msleep(5000); |
| 636 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 637 | failed: |
| 638 | mutex_unlock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 642 | static int az6027_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 643 | { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 644 | return 0; |
| 645 | } |
| 646 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 647 | static int az6027_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 648 | { |
| 649 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 650 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 651 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 652 | int ret; |
| 653 | u8 req; |
| 654 | u16 value; |
| 655 | u16 index; |
| 656 | int blen; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 657 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 658 | deb_info("%s", __func__); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 659 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 660 | req = 0xC7; |
| 661 | value = 1; |
| 662 | index = 0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 663 | blen = 0; |
| 664 | |
| 665 | ret = az6027_usb_out_op(d, req, value, index, NULL, blen); |
| 666 | if (ret != 0) { |
| 667 | warn("usb out operation failed. (%d)", ret); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 668 | goto failed; |
| 669 | } |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 670 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 671 | failed: |
| 672 | mutex_unlock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 673 | return ret; |
| 674 | } |
| 675 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 676 | static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 677 | { |
| 678 | struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data; |
| 679 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
| 680 | int ret; |
| 681 | u8 req; |
| 682 | u16 value; |
| 683 | u16 index; |
| 684 | int blen; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 685 | u8 *b; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 686 | |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 687 | b = kmalloc(12, GFP_KERNEL); |
| 688 | if (!b) |
| 689 | return -ENOMEM; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 690 | mutex_lock(&state->ca_mutex); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 691 | |
| 692 | req = 0xC5; |
| 693 | value = 0; |
| 694 | index = 0; |
| 695 | blen = 1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 696 | |
| 697 | ret = az6027_usb_in_op(d, req, value, index, b, blen); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 698 | if (ret < 0) { |
| 699 | warn("usb in operation failed. (%d)", ret); |
| 700 | ret = -EIO; |
| 701 | } else |
| 702 | ret = 0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 703 | |
Dan Carpenter | a18e659 | 2010-05-04 09:31:13 -0300 | [diff] [blame] | 704 | if (!ret && b[0] == 1) { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 705 | ret = DVB_CA_EN50221_POLL_CAM_PRESENT | |
| 706 | DVB_CA_EN50221_POLL_CAM_READY; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 707 | } |
| 708 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 709 | mutex_unlock(&state->ca_mutex); |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 710 | kfree(b); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | |
| 715 | static void az6027_ci_uninit(struct dvb_usb_device *d) |
| 716 | { |
| 717 | struct az6027_device_state *state; |
| 718 | |
| 719 | deb_info("%s", __func__); |
| 720 | |
| 721 | if (NULL == d) |
| 722 | return; |
| 723 | |
| 724 | state = (struct az6027_device_state *)d->priv; |
| 725 | if (NULL == state) |
| 726 | return; |
| 727 | |
| 728 | if (NULL == state->ca.data) |
| 729 | return; |
| 730 | |
| 731 | dvb_ca_en50221_release(&state->ca); |
| 732 | |
| 733 | memset(&state->ca, 0, sizeof(state->ca)); |
| 734 | } |
| 735 | |
| 736 | |
| 737 | static int az6027_ci_init(struct dvb_usb_adapter *a) |
| 738 | { |
| 739 | struct dvb_usb_device *d = a->dev; |
| 740 | struct az6027_device_state *state = (struct az6027_device_state *)d->priv; |
| 741 | int ret; |
| 742 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 743 | deb_info("%s", __func__); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 744 | |
| 745 | mutex_init(&state->ca_mutex); |
| 746 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 747 | state->ca.owner = THIS_MODULE; |
| 748 | state->ca.read_attribute_mem = az6027_ci_read_attribute_mem; |
| 749 | state->ca.write_attribute_mem = az6027_ci_write_attribute_mem; |
| 750 | state->ca.read_cam_control = az6027_ci_read_cam_control; |
| 751 | state->ca.write_cam_control = az6027_ci_write_cam_control; |
| 752 | state->ca.slot_reset = az6027_ci_slot_reset; |
| 753 | state->ca.slot_shutdown = az6027_ci_slot_shutdown; |
| 754 | state->ca.slot_ts_enable = az6027_ci_slot_ts_enable; |
| 755 | state->ca.poll_slot_status = az6027_ci_poll_slot_status; |
| 756 | state->ca.data = d; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 757 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 758 | ret = dvb_ca_en50221_init(&a->dvb_adap, |
| 759 | &state->ca, |
| 760 | 0, /* flags */ |
| 761 | 1);/* n_slots */ |
| 762 | if (ret != 0) { |
| 763 | err("Cannot initialize CI: Error %d.", ret); |
| 764 | memset(&state->ca, 0, sizeof(state->ca)); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 765 | return ret; |
| 766 | } |
| 767 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 768 | deb_info("CI initialized."); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
Manu Abraham | 4105ed5 | 2010-02-14 17:07:28 -0300 | [diff] [blame] | 773 | /* |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 774 | static int az6027_read_mac_addr(struct dvb_usb_device *d, u8 mac[6]) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 775 | { |
| 776 | az6027_usb_in_op(d, 0xb7, 6, 0, &mac[0], 6); |
| 777 | return 0; |
| 778 | } |
Manu Abraham | 4105ed5 | 2010-02-14 17:07:28 -0300 | [diff] [blame] | 779 | */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 780 | |
| 781 | static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) |
| 782 | { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 783 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 784 | u8 buf; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 785 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 786 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 787 | struct i2c_msg i2c_msg = { |
| 788 | .addr = 0x99, |
| 789 | .flags = 0, |
| 790 | .buf = &buf, |
| 791 | .len = 1 |
| 792 | }; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 793 | |
| 794 | /* |
| 795 | * 2 --18v |
| 796 | * 1 --13v |
| 797 | * 0 --off |
| 798 | */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 799 | switch (voltage) { |
| 800 | case SEC_VOLTAGE_13: |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 801 | buf = 1; |
Hans Verkuil | db3ca1d | 2011-08-25 10:36:59 -0300 | [diff] [blame] | 802 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 803 | break; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 804 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 805 | case SEC_VOLTAGE_18: |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 806 | buf = 2; |
Hans Verkuil | db3ca1d | 2011-08-25 10:36:59 -0300 | [diff] [blame] | 807 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 808 | break; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 809 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 810 | case SEC_VOLTAGE_OFF: |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 811 | buf = 0; |
Hans Verkuil | db3ca1d | 2011-08-25 10:36:59 -0300 | [diff] [blame] | 812 | i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 813 | break; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 814 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 815 | default: |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | static int az6027_frontend_poweron(struct dvb_usb_adapter *adap) |
| 823 | { |
| 824 | int ret; |
| 825 | u8 req; |
| 826 | u16 value; |
| 827 | u16 index; |
| 828 | int blen; |
| 829 | |
| 830 | req = 0xBC; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 831 | value = 1; /* power on */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 832 | index = 3; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 833 | blen = 0; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 834 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 835 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 836 | if (ret != 0) |
| 837 | return -EIO; |
| 838 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 839 | return 0; |
| 840 | } |
| 841 | static int az6027_frontend_reset(struct dvb_usb_adapter *adap) |
| 842 | { |
| 843 | int ret; |
| 844 | u8 req; |
| 845 | u16 value; |
| 846 | u16 index; |
| 847 | int blen; |
| 848 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 849 | /* reset demodulator */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 850 | req = 0xC0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 851 | value = 1; /* high */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 852 | index = 3; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 853 | blen = 0; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 854 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 855 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 856 | if (ret != 0) |
| 857 | return -EIO; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 858 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 859 | req = 0xC0; |
| 860 | value = 0; /* low */ |
| 861 | index = 3; |
| 862 | blen = 0; |
| 863 | msleep_interruptible(200); |
| 864 | |
| 865 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 866 | if (ret != 0) |
| 867 | return -EIO; |
| 868 | |
| 869 | msleep_interruptible(200); |
| 870 | |
| 871 | req = 0xC0; |
| 872 | value = 1; /*high */ |
| 873 | index = 3; |
| 874 | blen = 0; |
| 875 | |
| 876 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 877 | if (ret != 0) |
| 878 | return -EIO; |
| 879 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 880 | msleep_interruptible(200); |
| 881 | return 0; |
| 882 | } |
| 883 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 884 | static int az6027_frontend_tsbypass(struct dvb_usb_adapter *adap, int onoff) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 885 | { |
| 886 | int ret; |
| 887 | u8 req; |
| 888 | u16 value; |
| 889 | u16 index; |
| 890 | int blen; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 891 | |
| 892 | /* TS passthrough */ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 893 | req = 0xC7; |
| 894 | value = onoff; |
| 895 | index = 0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 896 | blen = 0; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 897 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 898 | ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen); |
| 899 | if (ret != 0) |
| 900 | return -EIO; |
| 901 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static int az6027_frontend_attach(struct dvb_usb_adapter *adap) |
| 906 | { |
| 907 | |
| 908 | az6027_frontend_poweron(adap); |
| 909 | az6027_frontend_reset(adap); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 910 | |
| 911 | deb_info("adap = %p, dev = %p\n", adap, adap->dev); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 912 | adap->fe_adap[0].fe = stb0899_attach(&az6027_stb0899_config, &adap->dev->i2c_adap); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 913 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 914 | if (adap->fe_adap[0].fe) { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 915 | deb_info("found STB0899 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb0899_config.demod_address); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 916 | if (stb6100_attach(adap->fe_adap[0].fe, &az6027_stb6100_config, &adap->dev->i2c_adap)) { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 917 | deb_info("found STB6100 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb6100_config.tuner_address); |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 918 | adap->fe_adap[0].fe->ops.set_voltage = az6027_set_voltage; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 919 | az6027_ci_init(adap); |
| 920 | } else { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 921 | adap->fe_adap[0].fe = NULL; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 922 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 923 | } else |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 924 | warn("no front-end attached\n"); |
| 925 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 926 | az6027_frontend_tsbypass(adap, 0); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 927 | |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | static struct dvb_usb_device_properties az6027_properties; |
| 932 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 933 | static void az6027_usb_disconnect(struct usb_interface *intf) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 934 | { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 935 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
| 936 | az6027_ci_uninit(d); |
| 937 | dvb_usb_device_exit(intf); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | |
| 941 | static int az6027_usb_probe(struct usb_interface *intf, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 942 | const struct usb_device_id *id) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 943 | { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 944 | return dvb_usb_device_init(intf, |
| 945 | &az6027_properties, |
| 946 | THIS_MODULE, |
| 947 | NULL, |
| 948 | adapter_nr); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /* I2C */ |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 952 | static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 953 | { |
| 954 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 955 | int i = 0, j = 0, len = 0; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 956 | u16 index; |
| 957 | u16 value; |
| 958 | int length; |
| 959 | u8 req; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 960 | u8 *data; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 961 | |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 962 | data = kmalloc(256, GFP_KERNEL); |
| 963 | if (!data) |
| 964 | return -ENOMEM; |
| 965 | |
| 966 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) { |
| 967 | kfree(data); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 968 | return -EAGAIN; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 969 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 970 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 971 | if (num > 2) |
| 972 | warn("more than 2 i2c messages at a time is not handled yet. TODO."); |
| 973 | |
| 974 | for (i = 0; i < num; i++) { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 975 | |
| 976 | if (msg[i].addr == 0x99) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 977 | req = 0xBE; |
| 978 | index = 0; |
| 979 | value = msg[i].buf[0] & 0x00ff; |
| 980 | length = 1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 981 | az6027_usb_out_op(d, req, value, index, data, length); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 982 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 983 | |
| 984 | if (msg[i].addr == 0xd0) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 985 | /* write/read request */ |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 986 | if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 987 | req = 0xB9; |
| 988 | index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); |
| 989 | value = msg[i].addr + (msg[i].len << 8); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 990 | length = msg[i + 1].len + 6; |
Hans Verkuil | db3ca1d | 2011-08-25 10:36:59 -0300 | [diff] [blame] | 991 | az6027_usb_in_op(d, req, value, index, data, length); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 992 | len = msg[i + 1].len; |
| 993 | for (j = 0; j < len; j++) |
| 994 | msg[i + 1].buf[j] = data[j + 5]; |
| 995 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 996 | i++; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 997 | } else { |
| 998 | |
Márton Németh | 6120792 | 2010-03-01 04:10:52 -0300 | [diff] [blame] | 999 | /* demod 16bit addr */ |
| 1000 | req = 0xBD; |
| 1001 | index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); |
| 1002 | value = msg[i].addr + (2 << 8); |
| 1003 | length = msg[i].len - 2; |
| 1004 | len = msg[i].len - 2; |
| 1005 | for (j = 0; j < len; j++) |
| 1006 | data[j] = msg[i].buf[j + 2]; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1007 | az6027_usb_out_op(d, req, value, index, data, length); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1008 | } |
| 1009 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1010 | |
| 1011 | if (msg[i].addr == 0xc0) { |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1012 | if (msg[i].flags & I2C_M_RD) { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1013 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1014 | req = 0xB9; |
| 1015 | index = 0x0; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1016 | value = msg[i].addr; |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1017 | length = msg[i].len + 6; |
Hans Verkuil | db3ca1d | 2011-08-25 10:36:59 -0300 | [diff] [blame] | 1018 | az6027_usb_in_op(d, req, value, index, data, length); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1019 | len = msg[i].len; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1020 | for (j = 0; j < len; j++) |
| 1021 | msg[i].buf[j] = data[j + 5]; |
| 1022 | |
| 1023 | } else { |
| 1024 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1025 | req = 0xBD; |
| 1026 | index = msg[i].buf[0] & 0x00FF; |
| 1027 | value = msg[i].addr + (1 << 8); |
| 1028 | length = msg[i].len - 1; |
| 1029 | len = msg[i].len - 1; |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1030 | |
| 1031 | for (j = 0; j < len; j++) |
| 1032 | data[j] = msg[i].buf[j + 1]; |
| 1033 | |
| 1034 | az6027_usb_out_op(d, req, value, index, data, length); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1035 | } |
| 1036 | } |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1037 | } |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1038 | mutex_unlock(&d->i2c_mutex); |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 1039 | kfree(data); |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1040 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1041 | return i; |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | static u32 az6027_i2c_func(struct i2c_adapter *adapter) |
| 1046 | { |
| 1047 | return I2C_FUNC_I2C; |
| 1048 | } |
| 1049 | |
| 1050 | static struct i2c_algorithm az6027_i2c_algo = { |
| 1051 | .master_xfer = az6027_i2c_xfer, |
| 1052 | .functionality = az6027_i2c_func, |
| 1053 | }; |
| 1054 | |
Mauro Carvalho Chehab | 64592d0 | 2012-10-27 14:05:59 -0300 | [diff] [blame] | 1055 | static int az6027_identify_state(struct usb_device *udev, |
| 1056 | struct dvb_usb_device_properties *props, |
| 1057 | struct dvb_usb_device_description **desc, |
| 1058 | int *cold) |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1059 | { |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 1060 | u8 *b; |
| 1061 | s16 ret; |
| 1062 | |
| 1063 | b = kmalloc(16, GFP_KERNEL); |
| 1064 | if (!b) |
| 1065 | return -ENOMEM; |
| 1066 | |
| 1067 | ret = usb_control_msg(udev, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1068 | usb_rcvctrlpipe(udev, 0), |
| 1069 | 0xb7, |
| 1070 | USB_TYPE_VENDOR | USB_DIR_IN, |
| 1071 | 6, |
| 1072 | 0, |
| 1073 | b, |
| 1074 | 6, |
| 1075 | USB_CTRL_GET_TIMEOUT); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1076 | |
| 1077 | *cold = ret <= 0; |
Dan Carpenter | 32ec457 | 2010-05-04 09:14:29 -0300 | [diff] [blame] | 1078 | kfree(b); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1079 | deb_info("cold: %d\n", *cold); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1084 | static struct usb_device_id az6027_usb_table[] = { |
Manu Abraham | 3c3233e | 2010-02-14 15:10:54 -0300 | [diff] [blame] | 1085 | { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_AZ6027) }, |
Oleg Roitburd | 20d2c56 | 2010-02-26 09:47:16 -0300 | [diff] [blame] | 1086 | { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V1) }, |
| 1087 | { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) }, |
Oleg Roitburd | 823b63b | 2010-02-25 17:19:31 -0300 | [diff] [blame] | 1088 | { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) }, |
| 1089 | { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) }, |
Sam Doshi | 10304ca | 2010-12-18 12:58:54 -0300 | [diff] [blame] | 1090 | { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_SAT) }, |
Manu Abraham | 3c3233e | 2010-02-14 15:10:54 -0300 | [diff] [blame] | 1091 | { }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1092 | }; |
| 1093 | |
| 1094 | MODULE_DEVICE_TABLE(usb, az6027_usb_table); |
| 1095 | |
| 1096 | static struct dvb_usb_device_properties az6027_properties = { |
| 1097 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1098 | .usb_ctrl = CYPRESS_FX2, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1099 | .firmware = "dvb-usb-az6027-03.fw", |
| 1100 | .no_reconnect = 1, |
| 1101 | |
| 1102 | .size_of_priv = sizeof(struct az6027_device_state), |
| 1103 | .identify_state = az6027_identify_state, |
| 1104 | .num_adapters = 1, |
| 1105 | .adapter = { |
| 1106 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1107 | .num_frontends = 1, |
| 1108 | .fe = {{ |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1109 | .streaming_ctrl = az6027_streaming_ctrl, |
| 1110 | .frontend_attach = az6027_frontend_attach, |
| 1111 | |
| 1112 | /* parameter for the MPEG2-data transfer */ |
| 1113 | .stream = { |
| 1114 | .type = USB_BULK, |
| 1115 | .count = 10, |
| 1116 | .endpoint = 0x02, |
| 1117 | .u = { |
| 1118 | .bulk = { |
| 1119 | .buffersize = 4096, |
| 1120 | } |
| 1121 | } |
| 1122 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1123 | }}, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1124 | } |
| 1125 | }, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1126 | /* |
| 1127 | .power_ctrl = az6027_power_ctrl, |
| 1128 | .read_mac_address = az6027_read_mac_addr, |
| 1129 | */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 1130 | .rc.legacy = { |
Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 1131 | .rc_map_table = rc_map_az6027_table, |
| 1132 | .rc_map_size = ARRAY_SIZE(rc_map_az6027_table), |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 1133 | .rc_interval = 400, |
| 1134 | .rc_query = az6027_rc_query, |
| 1135 | }, |
| 1136 | |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1137 | .i2c_algo = &az6027_i2c_algo, |
| 1138 | |
Sam Doshi | 10304ca | 2010-12-18 12:58:54 -0300 | [diff] [blame] | 1139 | .num_device_descs = 6, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1140 | .devices = { |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1141 | { |
| 1142 | .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)", |
| 1143 | .cold_ids = { &az6027_usb_table[0], NULL }, |
| 1144 | .warm_ids = { NULL }, |
Oleg Roitburd | 20d2c56 | 2010-02-26 09:47:16 -0300 | [diff] [blame] | 1145 | }, { |
| 1146 | .name = "TERRATEC S7", |
| 1147 | .cold_ids = { &az6027_usb_table[1], NULL }, |
| 1148 | .warm_ids = { NULL }, |
| 1149 | }, { |
| 1150 | .name = "TERRATEC S7 MKII", |
| 1151 | .cold_ids = { &az6027_usb_table[2], NULL }, |
| 1152 | .warm_ids = { NULL }, |
| 1153 | }, { |
| 1154 | .name = "Technisat SkyStar USB 2 HD CI", |
| 1155 | .cold_ids = { &az6027_usb_table[3], NULL }, |
| 1156 | .warm_ids = { NULL }, |
| 1157 | }, { |
| 1158 | .name = "Technisat SkyStar USB 2 HD CI", |
| 1159 | .cold_ids = { &az6027_usb_table[4], NULL }, |
| 1160 | .warm_ids = { NULL }, |
Sam Doshi | 10304ca | 2010-12-18 12:58:54 -0300 | [diff] [blame] | 1161 | }, { |
| 1162 | .name = "Elgato EyeTV Sat", |
| 1163 | .cold_ids = { &az6027_usb_table[5], NULL }, |
| 1164 | .warm_ids = { NULL }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1165 | }, |
Manu Abraham | 5f0e1cf | 2010-02-14 16:58:10 -0300 | [diff] [blame] | 1166 | { NULL }, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1167 | } |
| 1168 | }; |
| 1169 | |
| 1170 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 1171 | static struct usb_driver az6027_usb_driver = { |
| 1172 | .name = "dvb_usb_az6027", |
| 1173 | .probe = az6027_usb_probe, |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1174 | .disconnect = az6027_usb_disconnect, |
| 1175 | .id_table = az6027_usb_table, |
| 1176 | }; |
| 1177 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1178 | module_usb_driver(az6027_usb_driver); |
Adams Xu | 76f9a82 | 2010-02-14 14:34:07 -0300 | [diff] [blame] | 1179 | |
| 1180 | MODULE_AUTHOR("Adams Xu <Adams.xu@azwave.com.cn>"); |
| 1181 | MODULE_DESCRIPTION("Driver for AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)"); |
| 1182 | MODULE_VERSION("1.0"); |
| 1183 | MODULE_LICENSE("GPL"); |