1 /* dvb-usb-firmware.c is part of the DVB USB library.
3 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information.
6 * This file contains functions for downloading the firmware to Cypress FX 1 and 2 based devices.
8 * FIXME: This part does actually not belong to dvb-usb, but to the usb-subsystem.
10 #include "dvb-usb-common.h"
12 #include <linux/firmware.h>
13 #include <linux/usb.h>
15 struct usb_cypress_controller {
17 const char *name; /* name of the usb controller */
18 u16 cpu_cs_register; /* needs to be restarted, when the firmware has been downloaded. */
21 static struct usb_cypress_controller cypress[] = {
22 { .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 },
23 { .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 },
24 { .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 },
28 * load a firmware packet to the device
30 static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 len)
32 return usb_control_msg(udev, usb_sndctrlpipe(udev,0),
33 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ);
36 int usb_cypress_load_firmware(struct usb_device *udev, const char *filename, int type)
38 const struct firmware *fw = NULL;
43 if ((ret = request_firmware(&fw, filename, &udev->dev)) != 0) {
44 err("did not find the firmware file. (%s) "
45 "Please see linux/Documentation/dvb/ for more details on firmware-problems.",
50 info("downloading firmware from file '%s' to the '%s'",filename,cypress[type].name);
52 p = kmalloc(fw->size,GFP_KERNEL);
56 * you cannot use the fw->data as buffer for
57 * usb_control_msg, a new buffer has to be
60 memcpy(p,fw->data,fw->size);
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; ) {
68 addr = cpu_to_le16( *((u16 *) &b[1]) );
70 deb_fw("writing to address 0x%04x (buffer: 0x%02x%02x)\n",addr,b[1],b[2]);
72 ret = usb_cypress_writemem(udev,addr,&b[4],b[0]);
75 err("error while transferring firmware "
76 "(transferred size: %d, block size: %d)",
88 if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
89 err("could not restart the USB controller CPU.");