2 * DVB USB library - provides a generic interface for a DVB USB device driver.
6 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation, version 2.
12 * see Documentation/dvb/README.dvb-usb for more information
14 #include "dvb-usb-common.h"
18 module_param_named(debug,dvb_usb_debug, int, 0644);
19 MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." DVB_USB_DEBUG_STATUS);
21 /* general initialization functions */
22 int dvb_usb_exit(struct dvb_usb_device *d)
24 deb_info("state before exiting everything: %x\n",d->state);
25 dvb_usb_remote_exit(d);
30 deb_info("state should be zero now: %x\n",d->state);
31 d->state = DVB_USB_STATE_INIT;
37 static int dvb_usb_init(struct dvb_usb_device *d)
41 sema_init(&d->usb_sem, 1);
42 sema_init(&d->i2c_sem, 1);
44 d->state = DVB_USB_STATE_INIT;
46 /* check the capabilites and set appropriate variables */
48 /* speed - when running at FULL speed we need a HW PID filter */
49 if (d->udev->speed == USB_SPEED_FULL && !(d->props.caps & DVB_USB_HAS_PID_FILTER)) {
50 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a HW PID filter)");
54 if ((d->udev->speed == USB_SPEED_FULL && d->props.caps & DVB_USB_HAS_PID_FILTER) ||
55 (d->props.caps & DVB_USB_NEED_PID_FILTERING)) {
56 info("will use the device's hw PID filter.");
58 d->max_feed_count = d->props.pid_filter_count;
60 info("will pass the complete MPEG2 transport stream to the demuxer.");
62 d->max_feed_count = 255;
65 if (d->props.power_ctrl)
66 d->props.power_ctrl(d,1);
68 if ((ret = dvb_usb_urb_init(d)) ||
69 (ret = dvb_usb_dvb_init(d)) ||
70 (ret = dvb_usb_i2c_init(d)) ||
71 (ret = dvb_usb_fe_init(d))) {
76 if ((ret = dvb_usb_remote_init(d)))
77 err("could not initialize remote control.");
79 if (d->props.power_ctrl)
80 d->props.power_ctrl(d,0);
85 /* determine the name and the state of the just found USB device */
86 static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device *udev,struct dvb_usb_properties *props, int *cold)
89 struct dvb_usb_device_description *desc = NULL;
92 for (i = 0; i < props->num_device_descs; i++) {
94 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) {
95 deb_info("check for cold %x %x\n",props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct);
96 if (props->devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
97 props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
99 desc = &props->devices[i];
107 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) {
108 deb_info("check for warm %x %x\n",props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct);
109 if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
110 props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
112 desc = &props->devices[i];
118 if (desc != NULL && props->identify_state != NULL)
119 props->identify_state(udev,props,&desc,cold);
127 int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties *props, struct module *owner)
129 struct usb_device *udev = interface_to_usbdev(intf);
130 struct dvb_usb_device *d = NULL;
131 struct dvb_usb_device_description *desc = NULL;
133 int ret = -ENOMEM,cold=0;
135 if ((desc = dvb_usb_find_device(udev,props,&cold)) == NULL) {
136 deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
141 info("found a '%s' in cold state, will try to load a firmware",desc->name);
142 ret = usb_cypress_load_firmware(udev,props->firmware,props->usb_ctrl);
144 info("found a '%s' in warm state.",desc->name);
145 d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
147 err("no memory for 'struct dvb_usb_device'");
150 memset(d,0,sizeof(struct dvb_usb_device));
153 memcpy(&d->props,props,sizeof(struct dvb_usb_properties));
157 if (d->props.size_of_priv > 0) {
158 d->priv = kmalloc(d->props.size_of_priv,GFP_KERNEL);
159 if (d->priv == NULL) {
160 err("no memory for priv in 'struct dvb_usb_device'");
164 memset(d->priv,0,d->props.size_of_priv);
167 usb_set_intfdata(intf, d);
169 ret = dvb_usb_init(d);
173 info("%s successfully initialized and connected.",desc->name);
175 info("%s error while loading driver (%d)",desc->name,ret);
178 EXPORT_SYMBOL(dvb_usb_device_init);
180 void dvb_usb_device_exit(struct usb_interface *intf)
182 struct dvb_usb_device *d = usb_get_intfdata(intf);
183 const char *name = "generic DVB-USB module";
185 usb_set_intfdata(intf,NULL);
186 if (d != NULL && d->desc != NULL) {
187 name = d->desc->name;
190 info("%s successfully deinitialized and disconnected.",name);
193 EXPORT_SYMBOL(dvb_usb_device_exit);
196 static int __init dvb_usb_module_init(void)
201 static void __exit dvb_usb_module_exit(void)
205 module_init (dvb_usb_module_init);
206 module_exit (dvb_usb_module_exit);
208 MODULE_VERSION("0.3");
209 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
210 MODULE_DESCRIPTION("A library module containing commonly used USB and DVB function USB DVB devices");
211 MODULE_LICENSE("GPL");