diff options
Diffstat (limited to 'drivers/media/dvb/dvb-usb/dvb-usb-init.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/dvb-usb-init.c | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c new file mode 100644 index 00000000000..3aadec974cf --- /dev/null +++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c | |||
@@ -0,0 +1,211 @@ | |||
1 | /* | ||
2 | * DVB USB library - provides a generic interface for a DVB USB device driver. | ||
3 | * | ||
4 | * dvb-usb-init.c | ||
5 | * | ||
6 | * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) | ||
7 | * | ||
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. | ||
11 | * | ||
12 | * see Documentation/dvb/README.dvb-usb for more information | ||
13 | */ | ||
14 | #include "dvb-usb-common.h" | ||
15 | |||
16 | /* debug */ | ||
17 | int dvb_usb_debug; | ||
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); | ||
20 | |||
21 | /* general initialization functions */ | ||
22 | int dvb_usb_exit(struct dvb_usb_device *d) | ||
23 | { | ||
24 | deb_info("state before exiting everything: %x\n",d->state); | ||
25 | dvb_usb_remote_exit(d); | ||
26 | dvb_usb_fe_exit(d); | ||
27 | dvb_usb_i2c_exit(d); | ||
28 | dvb_usb_dvb_exit(d); | ||
29 | dvb_usb_urb_exit(d); | ||
30 | deb_info("state should be zero now: %x\n",d->state); | ||
31 | d->state = DVB_USB_STATE_INIT; | ||
32 | kfree(d->priv); | ||
33 | kfree(d); | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | static int dvb_usb_init(struct dvb_usb_device *d) | ||
38 | { | ||
39 | int ret = 0; | ||
40 | |||
41 | sema_init(&d->usb_sem, 1); | ||
42 | sema_init(&d->i2c_sem, 1); | ||
43 | |||
44 | d->state = DVB_USB_STATE_INIT; | ||
45 | |||
46 | /* check the capabilites and set appropriate variables */ | ||
47 | |||
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)"); | ||
51 | return -ENODEV; | ||
52 | } | ||
53 | |||
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."); | ||
57 | d->pid_filtering = 1; | ||
58 | d->max_feed_count = d->props.pid_filter_count; | ||
59 | } else { | ||
60 | info("will pass the complete MPEG2 transport stream to the demuxer."); | ||
61 | d->pid_filtering = 0; | ||
62 | d->max_feed_count = 255; | ||
63 | } | ||
64 | |||
65 | if (d->props.power_ctrl) | ||
66 | d->props.power_ctrl(d,1); | ||
67 | |||
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))) { | ||
72 | dvb_usb_exit(d); | ||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | if ((ret = dvb_usb_remote_init(d))) | ||
77 | err("could not initialize remote control."); | ||
78 | |||
79 | if (d->props.power_ctrl) | ||
80 | d->props.power_ctrl(d,0); | ||
81 | |||
82 | return 0; | ||
83 | } | ||
84 | |||
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) | ||
87 | { | ||
88 | int i,j; | ||
89 | struct dvb_usb_device_description *desc = NULL; | ||
90 | *cold = -1; | ||
91 | |||
92 | for (i = 0; i < props->num_device_descs; i++) { | ||
93 | |||
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)) { | ||
98 | *cold = 1; | ||
99 | desc = &props->devices[i]; | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | if (desc != NULL) | ||
105 | break; | ||
106 | |||
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)) { | ||
111 | *cold = 0; | ||
112 | desc = &props->devices[i]; | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | if (desc != NULL && props->identify_state != NULL) | ||
119 | props->identify_state(udev,props,&desc,cold); | ||
120 | |||
121 | return desc; | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * USB | ||
126 | */ | ||
127 | int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties *props, struct module *owner) | ||
128 | { | ||
129 | struct usb_device *udev = interface_to_usbdev(intf); | ||
130 | struct dvb_usb_device *d = NULL; | ||
131 | struct dvb_usb_device_description *desc = NULL; | ||
132 | |||
133 | int ret = -ENOMEM,cold=0; | ||
134 | |||
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"); | ||
137 | return -ENODEV; | ||
138 | } | ||
139 | |||
140 | if (cold) { | ||
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); | ||
143 | } else { | ||
144 | info("found a '%s' in warm state.",desc->name); | ||
145 | d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL); | ||
146 | if (d == NULL) { | ||
147 | err("no memory for 'struct dvb_usb_device'"); | ||
148 | return ret; | ||
149 | } | ||
150 | memset(d,0,sizeof(struct dvb_usb_device)); | ||
151 | |||
152 | d->udev = udev; | ||
153 | memcpy(&d->props,props,sizeof(struct dvb_usb_properties)); | ||
154 | d->desc = desc; | ||
155 | d->owner = owner; | ||
156 | |||
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'"); | ||
161 | kfree(d); | ||
162 | return -ENOMEM; | ||
163 | } | ||
164 | memset(d->priv,0,d->props.size_of_priv); | ||
165 | } | ||
166 | |||
167 | usb_set_intfdata(intf, d); | ||
168 | |||
169 | ret = dvb_usb_init(d); | ||
170 | } | ||
171 | |||
172 | if (ret == 0) | ||
173 | info("%s successfully initialized and connected.",desc->name); | ||
174 | else | ||
175 | info("%s error while loading driver (%d)",desc->name,ret); | ||
176 | return ret; | ||
177 | } | ||
178 | EXPORT_SYMBOL(dvb_usb_device_init); | ||
179 | |||
180 | void dvb_usb_device_exit(struct usb_interface *intf) | ||
181 | { | ||
182 | struct dvb_usb_device *d = usb_get_intfdata(intf); | ||
183 | const char *name = "generic DVB-USB module"; | ||
184 | |||
185 | usb_set_intfdata(intf,NULL); | ||
186 | if (d != NULL && d->desc != NULL) { | ||
187 | name = d->desc->name; | ||
188 | dvb_usb_exit(d); | ||
189 | } | ||
190 | info("%s successfully deinitialized and disconnected.",name); | ||
191 | |||
192 | } | ||
193 | EXPORT_SYMBOL(dvb_usb_device_exit); | ||
194 | |||
195 | /* module stuff */ | ||
196 | static int __init dvb_usb_module_init(void) | ||
197 | { | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | static void __exit dvb_usb_module_exit(void) | ||
202 | { | ||
203 | } | ||
204 | |||
205 | module_init (dvb_usb_module_init); | ||
206 | module_exit (dvb_usb_module_exit); | ||
207 | |||
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"); | ||