diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-09 16:03:58 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-09 16:03:58 -0500 |
commit | f17578decc40df8fceff82b106582e30bdfb3189 (patch) | |
tree | 911a435a2094ac03ae649f020237674224e4124a /drivers/media/dvb/dvb-usb/dvb-usb-firmware.c | |
parent | 682e852e2638ed0aff84aa51181c9e5d2f939562 (diff) | |
parent | cec418346e5a411e907293aba7cc21ac53c95834 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb
Diffstat (limited to 'drivers/media/dvb/dvb-usb/dvb-usb-firmware.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/dvb-usb-firmware.c | 154 |
1 files changed, 100 insertions, 54 deletions
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c b/drivers/media/dvb/dvb-usb/dvb-usb-firmware.c index 5244e39770a0..8535895819fb 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 | ||
15 | struct usb_cypress_controller { | 14 | struct usb_cypress_controller { |
@@ -19,9 +18,10 @@ struct usb_cypress_controller { | |||
19 | }; | 18 | }; |
20 | 19 | ||
21 | static struct usb_cypress_controller cypress[] = { | 20 | static 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 | /* |
@@ -30,71 +30,117 @@ static struct usb_cypress_controller cypress[] = { | |||
30 | static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 len) | 30 | static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 len) |
31 | { | 31 | { |
32 | return usb_control_msg(udev, usb_sndctrlpipe(udev,0), | 32 | return usb_control_msg(udev, usb_sndctrlpipe(udev,0), |
33 | 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ); | 33 | 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5000); |
34 | } | 34 | } |
35 | 35 | ||
36 | int usb_cypress_load_firmware(struct usb_device *udev, const char *filename, int type) | 36 | 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 | EXPORT_SYMBOL(usb_cypress_load_firmware); |
77 | |||
78 | int dvb_usb_download_firmware(struct usb_device *udev, struct dvb_usb_properties *props) | ||
79 | { | ||
80 | int ret; | ||
81 | const struct firmware *fw = NULL; | ||
82 | |||
83 | if ((ret = request_firmware(&fw, props->firmware, &udev->dev)) != 0) { | ||
84 | err("did not find the firmware file. (%s) " | ||
85 | "Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)", | ||
86 | props->firmware,ret); | ||
87 | return ret; | ||
96 | } | 88 | } |
97 | release_firmware(fw); | ||
98 | 89 | ||
90 | info("downloading firmware from file '%s'",props->firmware); | ||
91 | |||
92 | switch (props->usb_ctrl) { | ||
93 | case CYPRESS_AN2135: | ||
94 | case CYPRESS_AN2235: | ||
95 | case CYPRESS_FX2: | ||
96 | ret = usb_cypress_load_firmware(udev, fw, props->usb_ctrl); | ||
97 | break; | ||
98 | case DEVICE_SPECIFIC: | ||
99 | if (props->download_firmware) | ||
100 | ret = props->download_firmware(udev,fw); | ||
101 | else { | ||
102 | err("BUG: driver didn't specified a download_firmware-callback, although it claims to have a DEVICE_SPECIFIC one."); | ||
103 | ret = -EINVAL; | ||
104 | } | ||
105 | break; | ||
106 | default: | ||
107 | ret = -EINVAL; | ||
108 | break; | ||
109 | } | ||
110 | |||
111 | release_firmware(fw); | ||
99 | return ret; | 112 | return ret; |
100 | } | 113 | } |
114 | |||
115 | int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos) | ||
116 | { | ||
117 | u8 *b = (u8 *) &fw->data[*pos]; | ||
118 | int data_offs = 4; | ||
119 | if (*pos >= fw->size) | ||
120 | return 0; | ||
121 | |||
122 | memset(hx,0,sizeof(struct hexline)); | ||
123 | |||
124 | hx->len = b[0]; | ||
125 | |||
126 | if ((*pos + hx->len + 4) >= fw->size) | ||
127 | return -EINVAL; | ||
128 | |||
129 | hx->addr = le16_to_cpu( *((u16 *) &b[1]) ); | ||
130 | hx->type = b[3]; | ||
131 | |||
132 | if (hx->type == 0x04) { | ||
133 | /* b[4] and b[5] are the Extended linear address record data field */ | ||
134 | hx->addr |= (b[4] << 24) | (b[5] << 16); | ||
135 | /* hx->len -= 2; | ||
136 | data_offs += 2; */ | ||
137 | } | ||
138 | memcpy(hx->data,&b[data_offs],hx->len); | ||
139 | hx->chk = b[hx->len + data_offs]; | ||
140 | |||
141 | *pos += hx->len + 5; | ||
142 | |||
143 | return *pos; | ||
144 | } | ||
145 | EXPORT_SYMBOL(dvb_usb_get_hexline); | ||
146 | |||