2 * dvb-dibusb-firmware.c is part of the driver for mobile USB Budget DVB-T devices
3 * based on reference design made by DiBcom (http://www.dibcom.fr/)
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
7 * see dvb-dibusb-core.c for more copyright details.
9 * This file contains functions for downloading the firmware to the device.
11 #include "dvb-dibusb.h"
13 #include <linux/firmware.h>
14 #include <linux/usb.h>
17 * load a firmware packet to the device
19 static int dibusb_writemem(struct usb_device
*udev
,u16 addr
,u8
*data
, u8 len
)
21 return usb_control_msg(udev
, usb_sndctrlpipe(udev
,0),
22 0xa0, USB_TYPE_VENDOR
, addr
, 0x00, data
, len
, 5000);
25 int dibusb_loadfirmware(struct usb_device
*udev
, struct dibusb_usb_device
*dibdev
)
27 const struct firmware
*fw
= NULL
;
32 if ((ret
= request_firmware(&fw
, dibdev
->dev_cl
->firmware
, &udev
->dev
)) != 0) {
33 err("did not find the firmware file. (%s) "
34 "Please see linux/Documentation/dvb/ for more details on firmware-problems.",
35 dibdev
->dev_cl
->firmware
);
39 info("downloading firmware from file '%s'.",dibdev
->dev_cl
->firmware
);
41 p
= kmalloc(fw
->size
,GFP_KERNEL
);
45 * you cannot use the fw->data as buffer for
46 * usb_control_msg, a new buffer has to be
49 memcpy(p
,fw
->data
,fw
->size
);
53 if ((ret
= dibusb_writemem(udev
,dibdev
->dev_cl
->usb_ctrl
->cpu_cs_register
,&reset
,1)) != 1)
54 err("could not stop the USB controller CPU.");
55 for(i
= 0; p
[i
+3] == 0 && i
< fw
->size
; ) {
57 addr
= *((u16
*) &b
[1]);
59 ret
= dibusb_writemem(udev
,addr
,&b
[4],b
[0]);
62 err("error while transferring firmware "
63 "(transferred size: %d, block size: %d)",
75 if (ret
|| dibusb_writemem(udev
,dibdev
->dev_cl
->usb_ctrl
->cpu_cs_register
,&reset
,1) != 1) {
76 err("could not restart the USB controller CPU.");