aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb
diff options
context:
space:
mode:
authorPatrick Boettcher <pb@linuxtv.org>2006-01-09 12:25:04 -0500
committerMauro Carvalho Chehab <mchehab@brturbo.com.br>2006-01-09 12:25:04 -0500
commitd3707add6158803b6463292178cd1a041857b91b (patch)
tree29fead33cb3cdb3ed5d3819475e717467967f6c9 /drivers/media/dvb/dvb-usb
parente142e5107f1e4103dad16e391a41166e15b66a9c (diff)
DVB (2420): Makes integration of future devices easier
- To make the integration of future devices easier - modified the dvb-usb-part to allow a device-specific firmware download - added an option to specify whether a device reconnects after a firmware download or not. Signed-off-by: Patrick Boettcher <pb@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
Diffstat (limited to 'drivers/media/dvb/dvb-usb')
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-common.h2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-firmware.c151
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c56
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h27
4 files changed, 150 insertions, 86 deletions
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-common.h b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
index 7300489d3e24..a3460bf2d9fa 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-common.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
@@ -24,7 +24,7 @@ extern int dvb_usb_disable_rc_polling;
24#define deb_mem(args...) dprintk(dvb_usb_debug,0x80,args) 24#define deb_mem(args...) dprintk(dvb_usb_debug,0x80,args)
25 25
26/* commonly used methods */ 26/* commonly used methods */
27extern int usb_cypress_load_firmware(struct usb_device *, const char *, int); 27extern int dvb_usb_download_firmware(struct usb_device *, struct dvb_usb_properties *);
28 28
29extern int dvb_usb_urb_submit(struct dvb_usb_device *); 29extern int dvb_usb_urb_submit(struct dvb_usb_device *);
30extern int dvb_usb_urb_kill(struct dvb_usb_device *); 30extern int dvb_usb_urb_kill(struct dvb_usb_device *);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c b/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c
index 5244e39770a0..ab87af99d36f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c
@@ -9,7 +9,6 @@
9 */ 9 */
10#include "dvb-usb-common.h" 10#include "dvb-usb-common.h"
11 11
12#include <linux/firmware.h>
13#include <linux/usb.h> 12#include <linux/usb.h>
14 13
15struct usb_cypress_controller { 14struct usb_cypress_controller {
@@ -19,9 +18,10 @@ struct usb_cypress_controller {
19}; 18};
20 19
21static struct usb_cypress_controller cypress[] = { 20static struct usb_cypress_controller cypress[] = {
22 { .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 }, 21 { .id = DEVICE_SPECIFIC, .name = "Device specific", .cpu_cs_register = 0 },
23 { .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 }, 22 { .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 },
24 { .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 }, 23 { .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 },
24 { .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 },
25}; 25};
26 26
27/* 27/*
@@ -33,68 +33,113 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
33 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ); 33 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ);
34} 34}
35 35
36int usb_cypress_load_firmware(struct usb_device *udev, const char *filename, int type) 36static int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
37{ 37{
38 const struct firmware *fw = NULL; 38 struct hexline hx;
39 u16 addr; 39 u8 reset;
40 u8 *b,*p; 40 int ret,pos=0;
41 int ret = 0,i;
42 41
43 if ((ret = request_firmware(&fw, filename, &udev->dev)) != 0) { 42 /* stop the CPU */
44 err("did not find the firmware file. (%s) " 43 reset = 1;
45 "Please see linux/Documentation/dvb/ for more details on firmware-problems.", 44 if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46 filename); 45 err("could not stop the USB controller CPU.");
46
47 while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
48 deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
49 ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
50
51 if (ret != hx.len) {
52 err("error while transferring firmware "
53 "(transferred size: %d, block size: %d)",
54 ret,hx.len);
55 ret = -EINVAL;
56 break;
57 }
58 }
59 if (ret < 0) {
60 err("firmware download failed at %d with %d",pos,ret);
47 return ret; 61 return ret;
48 } 62 }
49 63
50 info("downloading firmware from file '%s' to the '%s'",filename,cypress[type].name); 64 if (ret == 0) {
51
52 p = kmalloc(fw->size,GFP_KERNEL);
53 if (p != NULL) {
54 u8 reset;
55 /*
56 * you cannot use the fw->data as buffer for
57 * usb_control_msg, a new buffer has to be
58 * created
59 */
60 memcpy(p,fw->data,fw->size);
61
62 /* stop the CPU */
63 reset = 1;
64 if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
65 err("could not stop the USB controller CPU.");
66 for(i = 0; p[i+3] == 0 && i < fw->size; ) {
67 b = (u8 *) &p[i];
68 addr = cpu_to_le16( *((u16 *) &b[1]) );
69
70 deb_fw("writing to address 0x%04x (buffer: 0x%02x%02x)\n",addr,b[1],b[2]);
71
72 ret = usb_cypress_writemem(udev,addr,&b[4],b[0]);
73
74 if (ret != b[0]) {
75 err("error while transferring firmware "
76 "(transferred size: %d, block size: %d)",
77 ret,b[0]);
78 ret = -EINVAL;
79 break;
80 }
81 i += 5 + b[0];
82 }
83 /* length in ret */
84 if (ret > 0)
85 ret = 0;
86 /* restart the CPU */ 65 /* restart the CPU */
87 reset = 0; 66 reset = 0;
88 if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) { 67 if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
89 err("could not restart the USB controller CPU."); 68 err("could not restart the USB controller CPU.");
90 ret = -EINVAL; 69 ret = -EINVAL;
91 } 70 }
71 } else
72 ret = -EIO;
92 73
93 kfree(p); 74 return ret;
94 } else { 75}
95 ret = -ENOMEM; 76
77int dvb_usb_download_firmware(struct usb_device *udev, struct dvb_usb_properties *props)
78{
79 int ret;
80 const struct firmware *fw = NULL;
81
82 if ((ret = request_firmware(&fw, props->firmware, &udev->dev)) != 0) {
83 err("did not find the firmware file. (%s) "
84 "Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)",
85 props->firmware,ret);
86 return ret;
96 } 87 }
97 release_firmware(fw);
98 88
89 info("downloading firmware from file '%s'",props->firmware);
90
91 switch (props->usb_ctrl) {
92 case CYPRESS_AN2135:
93 case CYPRESS_AN2235:
94 case CYPRESS_FX2:
95 ret = usb_cypress_load_firmware(udev, fw, props->usb_ctrl);
96 break;
97 case DEVICE_SPECIFIC:
98 if (props->download_firmware)
99 ret = props->download_firmware(udev,fw);
100 else {
101 err("BUG: driver didn't specified a download_firmware-callback, although it claims to have a DEVICE_SPECIFIC one.");
102 ret = -EINVAL;
103 }
104 break;
105 default:
106 ret = -EINVAL;
107 break;
108 }
109
110 release_firmware(fw);
99 return ret; 111 return ret;
100} 112}
113
114int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos)
115{
116 u8 *b = (u8 *) &fw->data[*pos];
117 int data_offs = 4;
118 if (*pos >= fw->size)
119 return 0;
120
121 memset(hx,0,sizeof(struct hexline));
122
123 hx->len = b[0];
124
125 if ((*pos + hx->len + 4) >= fw->size)
126 return -EINVAL;
127
128 hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
129 hx->type = b[3];
130
131 if (hx->type == 0x04) {
132 /* b[4] and b[5] are the Extended linear address record data field */
133 hx->addr |= (b[4] << 24) | (b[5] << 16);
134/* hx->len -= 2;
135 data_offs += 2; */
136 }
137 memcpy(hx->data,&b[data_offs],hx->len);
138 hx->chk = b[hx->len + data_offs];
139
140 *pos += hx->len + 5;
141
142 return *pos;
143}
144EXPORT_SYMBOL(dvb_usb_get_hexline);
145
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index dd8e0b94edba..2f9c3638adcf 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -145,38 +145,40 @@ int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties
145 145
146 if (cold) { 146 if (cold) {
147 info("found a '%s' in cold state, will try to load a firmware",desc->name); 147 info("found a '%s' in cold state, will try to load a firmware",desc->name);
148 ret = usb_cypress_load_firmware(udev,props->firmware,props->usb_ctrl); 148 ret = dvb_usb_download_firmware(udev,props);
149 } else { 149 if (!props->no_reconnect)
150 info("found a '%s' in warm state.",desc->name);
151 d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
152 if (d == NULL) {
153 err("no memory for 'struct dvb_usb_device'");
154 return ret; 150 return ret;
151 }
152
153 info("found a '%s' in warm state.",desc->name);
154 d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
155 if (d == NULL) {
156 err("no memory for 'struct dvb_usb_device'");
157 return ret;
158 }
159 memset(d,0,sizeof(struct dvb_usb_device));
160
161 d->udev = udev;
162 memcpy(&d->props,props,sizeof(struct dvb_usb_properties));
163 d->desc = desc;
164 d->owner = owner;
165
166 if (d->props.size_of_priv > 0) {
167 d->priv = kmalloc(d->props.size_of_priv,GFP_KERNEL);
168 if (d->priv == NULL) {
169 err("no memory for priv in 'struct dvb_usb_device'");
170 kfree(d);
171 return -ENOMEM;
155 } 172 }
156 memset(d,0,sizeof(struct dvb_usb_device)); 173 memset(d->priv,0,d->props.size_of_priv);
157 174 }
158 d->udev = udev;
159 memcpy(&d->props,props,sizeof(struct dvb_usb_properties));
160 d->desc = desc;
161 d->owner = owner;
162
163 if (d->props.size_of_priv > 0) {
164 d->priv = kmalloc(d->props.size_of_priv,GFP_KERNEL);
165 if (d->priv == NULL) {
166 err("no memory for priv in 'struct dvb_usb_device'");
167 kfree(d);
168 return -ENOMEM;
169 }
170 memset(d->priv,0,d->props.size_of_priv);
171 }
172 175
173 usb_set_intfdata(intf, d); 176 usb_set_intfdata(intf, d);
174 177
175 if (du != NULL) 178 if (du != NULL)
176 *du = d; 179 *du = d;
177 180
178 ret = dvb_usb_init(d); 181 ret = dvb_usb_init(d);
179 }
180 182
181 if (ret == 0) 183 if (ret == 0)
182 info("%s successfully initialized and connected.",desc->name); 184 info("%s successfully initialized and connected.",desc->name);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index b4a1a98006c7..cd510fba60ee 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -12,6 +12,7 @@
12#include <linux/input.h> 12#include <linux/input.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/firmware.h>
15 16
16#include "dvb_frontend.h" 17#include "dvb_frontend.h"
17#include "dvb_demux.h" 18#include "dvb_demux.h"
@@ -94,7 +95,11 @@ struct dvb_usb_device;
94 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware 95 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
95 * download. 96 * download.
96 * @firmware: name of the firmware file. 97 * @firmware: name of the firmware file.
97 * 98 * @download_firmware: called to download the firmware when the usb_ctrl is
99 * DEVICE_SPECIFIC.
100 * @no_reconnect: device doesn't do a reconnect after downloading the firmware,
101 so do the warm initialization right after it
102
98 * @size_of_priv: how many bytes shall be allocated for the private field 103 * @size_of_priv: how many bytes shall be allocated for the private field
99 * of struct dvb_usb_device. 104 * of struct dvb_usb_device.
100 * 105 *
@@ -142,11 +147,14 @@ struct dvb_usb_properties {
142 int caps; 147 int caps;
143 int pid_filter_count; 148 int pid_filter_count;
144 149
145#define CYPRESS_AN2135 0 150#define DEVICE_SPECIFIC 0
146#define CYPRESS_AN2235 1 151#define CYPRESS_AN2135 1
147#define CYPRESS_FX2 2 152#define CYPRESS_AN2235 2
153#define CYPRESS_FX2 3
148 int usb_ctrl; 154 int usb_ctrl;
149 const char *firmware; 155 const char firmware[FIRMWARE_NAME_MAX];
156 int (*download_firmware) (struct usb_device *, const struct firmware *);
157 int no_reconnect;
150 158
151 int size_of_priv; 159 int size_of_priv;
152 160
@@ -326,5 +334,14 @@ extern int dvb_usb_pll_init_i2c(struct dvb_frontend *);
326extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]); 334extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]);
327extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *); 335extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
328 336
337/* commonly used firmware download types and function */
338struct hexline {
339 u8 len;
340 u32 addr;
341 u8 type;
342 u8 data[255];
343 u8 chk;
344};
345extern int dvb_usb_get_hexline(const struct firmware *, struct hexline *, int *);
329 346
330#endif 347#endif