aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb/vp702x.c
diff options
context:
space:
mode:
authorPatrick Boettcher <pb@linuxtv.org>2006-09-19 11:51:43 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-10-03 14:12:40 -0400
commit0540c4961fcc6d69b8a3314c330c376890715eee (patch)
tree8babf9a7a6d10f4ebc5990009ad64328daf044a5 /drivers/media/dvb/dvb-usb/vp702x.c
parent6958effedb0dc709966c22e7fd0e8210b5401b84 (diff)
V4L/DVB (4649): Merged VP702x support to dvb-usb multi input
The fixed support for the VP70x (supports only StarBox2) is now in sync with latest changes in the dvb-usb framework. Signed-off-by: Patrick Boettcher <pb@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/dvb-usb/vp702x.c')
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c173
1 files changed, 113 insertions, 60 deletions
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index fdab2562bf5d..02bd61aaac66 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -22,50 +22,54 @@ module_param_named(debug,dvb_usb_vp702x_debug, int, 0644);
22MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); 22MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
23 23
24struct vp702x_state { 24struct vp702x_state {
25 u8 pid_table[17]; /* [16] controls the pid_table state */ 25 int pid_filter_count;
26 int pid_filter_can_bypass;
27 u8 pid_filter_state;
28};
29
30struct vp702x_device_state {
31 u8 power_state;
26}; 32};
27 33
28/* check for mutex FIXME */ 34/* check for mutex FIXME */
29int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) 35int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
30{ 36{
31 int ret = 0,try = 0; 37 int ret = -1;
32 38
33 while (ret >= 0 && ret != blen && try < 3) {
34 ret = usb_control_msg(d->udev, 39 ret = usb_control_msg(d->udev,
35 usb_rcvctrlpipe(d->udev,0), 40 usb_rcvctrlpipe(d->udev,0),
36 req, 41 req,
37 USB_TYPE_VENDOR | USB_DIR_IN, 42 USB_TYPE_VENDOR | USB_DIR_IN,
38 value,index,b,blen, 43 value,index,b,blen,
39 2000); 44 2000);
40 deb_info("reading number %d (ret: %d)\n",try,ret);
41 try++;
42 }
43 45
44 if (ret < 0 || ret != blen) { 46 if (ret < 0) {
45 warn("usb in operation failed."); 47 warn("usb in operation failed. (%d)", ret);
46 ret = -EIO; 48 ret = -EIO;
47 } else 49 } else
48 ret = 0; 50 ret = 0;
49 51
50 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index); 52
53 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
51 debug_dump(b,blen,deb_xfer); 54 debug_dump(b,blen,deb_xfer);
52 55
53 return ret; 56 return ret;
54} 57}
55 58
56static int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 59int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
57 u16 index, u8 *b, int blen) 60 u16 index, u8 *b, int blen)
58{ 61{
59 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index); 62 int ret;
63 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
60 debug_dump(b,blen,deb_xfer); 64 debug_dump(b,blen,deb_xfer);
61 65
62 if (usb_control_msg(d->udev, 66 if ((ret = usb_control_msg(d->udev,
63 usb_sndctrlpipe(d->udev,0), 67 usb_sndctrlpipe(d->udev,0),
64 req, 68 req,
65 USB_TYPE_VENDOR | USB_DIR_OUT, 69 USB_TYPE_VENDOR | USB_DIR_OUT,
66 value,index,b,blen, 70 value,index,b,blen,
67 2000) != blen) { 71 2000)) != blen) {
68 warn("usb out operation failed."); 72 warn("usb out operation failed. (%d)",ret);
69 return -EIO; 73 return -EIO;
70 } else 74 } else
71 return 0; 75 return 0;
@@ -78,12 +82,10 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il
78 if ((ret = mutex_lock_interruptible(&d->usb_mutex))) 82 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
79 return ret; 83 return ret;
80 84
81 if ((ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen)) < 0) 85 ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen);
82 goto unlock;
83 msleep(msec); 86 msleep(msec);
84 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen); 87 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen);
85 88
86unlock:
87 mutex_unlock(&d->usb_mutex); 89 mutex_unlock(&d->usb_mutex);
88 90
89 return ret; 91 return ret;
@@ -108,29 +110,65 @@ static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
108 return ret; 110 return ret;
109} 111}
110 112
111static int vp702x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff) 113static int vp702x_set_pld_mode(struct dvb_usb_adapter *adap, u8 bypass)
114{
115 u8 buf[16] = { 0 };
116 return vp702x_usb_in_op(adap->dev, 0xe0, (bypass << 8) | 0x0e, 0, buf, 16);
117}
118
119static int vp702x_set_pld_state(struct dvb_usb_adapter *adap, u8 state)
120{
121 u8 buf[16] = { 0 };
122 return vp702x_usb_in_op(adap->dev, 0xe0, (state << 8) | 0x0f, 0, buf, 16);
123}
124
125static int vp702x_set_pid(struct dvb_usb_adapter *adap, u16 pid, u8 id, int onoff)
112{ 126{
113 struct vp702x_state *st = adap->priv; 127 struct vp702x_state *st = adap->priv;
114 u8 buf[9]; 128 u8 buf[16] = { 0 };
115 129
116 if (onoff) { 130 if (onoff)
117 st->pid_table[16] |= 1 << index; 131 st->pid_filter_state |= (1 << id);
118 st->pid_table[index*2] = (pid >> 8) & 0xff; 132 else {
119 st->pid_table[index*2+1] = pid & 0xff; 133 st->pid_filter_state &= ~(1 << id);
120 } else { 134 pid = 0xffff;
121 st->pid_table[16] &= ~(1 << index);
122 st->pid_table[index*2] = st->pid_table[index*2+1] = 0;
123 } 135 }
124 136
125 return vp702x_usb_inout_cmd(adap->dev,SET_PID_FILTER,st->pid_table,17,buf,9,10); 137 id = 0x10 + id*2;
138
139 vp702x_set_pld_state(adap, st->pid_filter_state);
140 vp702x_usb_in_op(adap->dev, 0xe0, (((pid >> 8) & 0xff) << 8) | (id), 0, buf, 16);
141 vp702x_usb_in_op(adap->dev, 0xe0, (((pid ) & 0xff) << 8) | (id+1), 0, buf, 16);
142 return 0;
126} 143}
127 144
128static int vp702x_power_ctrl(struct dvb_usb_device *d, int onoff) 145
146static int vp702x_init_pid_filter(struct dvb_usb_adapter *adap)
129{ 147{
130 vp702x_usb_in_op(d,RESET_TUNER,0,0,NULL,0); 148 struct vp702x_state *st = adap->priv;
149 int i;
150 u8 b[10] = { 0 };
131 151
132 vp702x_usb_in_op(d,SET_TUNER_POWER_REQ,0,onoff,NULL,0); 152 st->pid_filter_count = 8;
133 return vp702x_usb_in_op(d,SET_TUNER_POWER_REQ,0,onoff,NULL,0); 153 st->pid_filter_can_bypass = 1;
154 st->pid_filter_state = 0x00;
155
156 vp702x_set_pld_mode(adap, 1); // bypass
157
158 for (i = 0; i < st->pid_filter_count; i++)
159 vp702x_set_pid(adap, 0xffff, i, 1);
160
161 vp702x_usb_in_op(adap->dev, 0xb5, 3, 0, b, 10);
162 vp702x_usb_in_op(adap->dev, 0xb5, 0, 0, b, 10);
163 vp702x_usb_in_op(adap->dev, 0xb5, 1, 0, b, 10);
164
165 //vp702x_set_pld_mode(d, 0); // filter
166 return 0;
167}
168
169static int vp702x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
170{
171 return 0;
134} 172}
135 173
136/* keys for the enclosed remote control */ 174/* keys for the enclosed remote control */
@@ -166,26 +204,45 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
166 return 0; 204 return 0;
167} 205}
168 206
207int vp702x_power_ctrl(struct dvb_usb_device *d, int onoff)
208{
209 struct vp702x_device_state *st = d->priv;
210
211 if (st->power_state == 0 && onoff)
212 vp702x_usb_out_op(d, SET_TUNER_POWER_REQ, 1, 7, NULL, 0);
213 else if (st->power_state == 1 && onoff == 0)
214 vp702x_usb_out_op(d, SET_TUNER_POWER_REQ, 0, 7, NULL, 0);
215
216 st->power_state = onoff;
217
218 return 0;
219}
220
169static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6]) 221static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
170{ 222{
171 u8 macb[9]; 223 u8 i;
172 if (vp702x_usb_inout_cmd(d, GET_MAC_ADDRESS, NULL, 0, macb, 9, 10)) 224 for (i = 6; i < 12; i++)
173 return -EIO; 225 vp702x_usb_in_op(d, READ_EEPROM_REQ, i, 1, &mac[i - 6], 1);
174 memcpy(mac,&macb[3],6);
175 return 0; 226 return 0;
176} 227}
177 228
178static int vp702x_frontend_attach(struct dvb_usb_adapter *adap) 229static int vp702x_frontend_attach(struct dvb_usb_adapter *adap)
179{ 230{
180 u8 buf[9] = { 0 }; 231 u8 buf[10] = { 0 };
232
233 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 0, 7, NULL, 0);
181 234
182 if (vp702x_usb_inout_cmd(adap->dev, GET_SYSTEM_STRING, NULL, 0, buf, 9, 10)) 235 if (vp702x_usb_inout_cmd(adap->dev, GET_SYSTEM_STRING, NULL, 0, buf, 10, 10))
183 return -EIO; 236 return -EIO;
184 237
185 buf[8] = '\0'; 238 buf[9] = '\0';
186 info("system string: %s",&buf[1]); 239 info("system string: %s",&buf[1]);
187 240
241 vp702x_init_pid_filter(adap);
242
188 adap->fe = vp702x_fe_attach(adap->dev); 243 adap->fe = vp702x_fe_attach(adap->dev);
244 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 1, 7, NULL, 0);
245
189 return 0; 246 return 0;
190} 247}
191 248
@@ -194,39 +251,36 @@ static struct dvb_usb_device_properties vp702x_properties;
194static int vp702x_usb_probe(struct usb_interface *intf, 251static int vp702x_usb_probe(struct usb_interface *intf,
195 const struct usb_device_id *id) 252 const struct usb_device_id *id)
196{ 253{
197 struct usb_device *udev = interface_to_usbdev(intf);
198
199 usb_clear_halt(udev,usb_sndctrlpipe(udev,0));
200 usb_clear_halt(udev,usb_rcvctrlpipe(udev,0));
201
202 return dvb_usb_device_init(intf,&vp702x_properties,THIS_MODULE,NULL); 254 return dvb_usb_device_init(intf,&vp702x_properties,THIS_MODULE,NULL);
203} 255}
204 256
205static struct usb_device_id vp702x_usb_table [] = { 257static struct usb_device_id vp702x_usb_table [] = {
206 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_COLD) }, 258 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_COLD) },
207 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7021_WARM) }, 259// { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_COLD) },
208 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_COLD) }, 260// { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_WARM) },
209 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7020_WARM) },
210 { 0 }, 261 { 0 },
211}; 262};
212MODULE_DEVICE_TABLE(usb, vp702x_usb_table); 263MODULE_DEVICE_TABLE(usb, vp702x_usb_table);
213 264
214static struct dvb_usb_device_properties vp702x_properties = { 265static struct dvb_usb_device_properties vp702x_properties = {
215 .usb_ctrl = CYPRESS_FX2, 266 .usb_ctrl = CYPRESS_FX2,
216 .firmware = "dvb-usb-vp702x-01.fw", 267 .firmware = "dvb-usb-vp702x-02.fw",
268 .no_reconnect = 1,
269
270 .size_of_priv = sizeof(struct vp702x_device_state),
217 271
218 .num_adapters = 1, 272 .num_adapters = 1,
219 .adapter = { 273 .adapter = {
220 { 274 {
221 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING, 275 .caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
222 .pid_filter_count = 8, /* !!! */
223 276
224 .pid_filter = vp702x_pid_filter, 277 .streaming_ctrl = vp702x_streaming_ctrl,
225 .frontend_attach = vp702x_frontend_attach, 278 .frontend_attach = vp702x_frontend_attach,
279
226 /* parameter for the MPEG2-data transfer */ 280 /* parameter for the MPEG2-data transfer */
227 .stream = { 281 .stream = {
228 .type = USB_BULK, 282 .type = USB_BULK,
229 .count = 7, 283 .count = 10,
230 .endpoint = 0x02, 284 .endpoint = 0x02,
231 .u = { 285 .u = {
232 .bulk = { 286 .bulk = {
@@ -235,9 +289,8 @@ static struct dvb_usb_device_properties vp702x_properties = {
235 } 289 }
236 }, 290 },
237 .size_of_priv = sizeof(struct vp702x_state), 291 .size_of_priv = sizeof(struct vp702x_state),
292 }
238 }, 293 },
239 },
240 .power_ctrl = vp702x_power_ctrl,
241 .read_mac_address = vp702x_read_mac_addr, 294 .read_mac_address = vp702x_read_mac_addr,
242 295
243 .rc_key_map = vp702x_rc_keys, 296 .rc_key_map = vp702x_rc_keys,
@@ -245,23 +298,23 @@ static struct dvb_usb_device_properties vp702x_properties = {
245 .rc_interval = 400, 298 .rc_interval = 400,
246 .rc_query = vp702x_rc_query, 299 .rc_query = vp702x_rc_query,
247 300
248 .num_device_descs = 2, 301 .num_device_descs = 1,
249 .devices = { 302 .devices = {
250 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7021)", 303 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7021)",
251 .cold_ids = { &vp702x_usb_table[0], NULL }, 304 .cold_ids = { &vp702x_usb_table[0], NULL },
252 .warm_ids = { &vp702x_usb_table[1], NULL }, 305 .warm_ids = { NULL },
253 }, 306 },
254 { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7020)", 307/* { .name = "TwinhanDTV StarBox DVB-S USB2.0 (VP7020)",
255 .cold_ids = { &vp702x_usb_table[2], NULL }, 308 .cold_ids = { &vp702x_usb_table[2], NULL },
256 .warm_ids = { &vp702x_usb_table[3], NULL }, 309 .warm_ids = { &vp702x_usb_table[3], NULL },
257 }, 310 },
258 { 0 }, 311*/ { NULL },
259 } 312 }
260}; 313};
261 314
262/* usb specific object needed to register this driver with the usb subsystem */ 315/* usb specific object needed to register this driver with the usb subsystem */
263static struct usb_driver vp702x_usb_driver = { 316static struct usb_driver vp702x_usb_driver = {
264 .name = "dvb-usb-vp702x", 317 .name = "dvb_usb_vp702x",
265 .probe = vp702x_usb_probe, 318 .probe = vp702x_usb_probe,
266 .disconnect = dvb_usb_device_exit, 319 .disconnect = dvb_usb_device_exit,
267 .id_table = vp702x_usb_table, 320 .id_table = vp702x_usb_table,
@@ -290,5 +343,5 @@ module_exit(vp702x_usb_module_exit);
290 343
291MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 344MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
292MODULE_DESCRIPTION("Driver for Twinhan StarBox DVB-S USB2.0 and clones"); 345MODULE_DESCRIPTION("Driver for Twinhan StarBox DVB-S USB2.0 and clones");
293MODULE_VERSION("1.0-alpha"); 346MODULE_VERSION("1.0");
294MODULE_LICENSE("GPL"); 347MODULE_LICENSE("GPL");