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>
This commit is contained in:
Patrick Boettcher 2006-01-09 15:25:04 -02:00 коммит произвёл Mauro Carvalho Chehab
Родитель e142e5107f
Коммит d3707add61
4 изменённых файлов: 155 добавлений и 91 удалений

Просмотреть файл

@ -24,7 +24,7 @@ extern int dvb_usb_disable_rc_polling;
#define deb_mem(args...) dprintk(dvb_usb_debug,0x80,args) #define deb_mem(args...) dprintk(dvb_usb_debug,0x80,args)
/* commonly used methods */ /* commonly used methods */
extern int usb_cypress_load_firmware(struct usb_device *, const char *, int); extern int dvb_usb_download_firmware(struct usb_device *, struct dvb_usb_properties *);
extern int dvb_usb_urb_submit(struct dvb_usb_device *); extern int dvb_usb_urb_submit(struct dvb_usb_device *);
extern int dvb_usb_urb_kill(struct dvb_usb_device *); extern int dvb_usb_urb_kill(struct dvb_usb_device *);

Просмотреть файл

@ -9,7 +9,6 @@
*/ */
#include "dvb-usb-common.h" #include "dvb-usb-common.h"
#include <linux/firmware.h>
#include <linux/usb.h> #include <linux/usb.h>
struct usb_cypress_controller { struct usb_cypress_controller {
@ -19,6 +18,7 @@ struct usb_cypress_controller {
}; };
static struct usb_cypress_controller cypress[] = { static struct usb_cypress_controller cypress[] = {
{ .id = DEVICE_SPECIFIC, .name = "Device specific", .cpu_cs_register = 0 },
{ .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 }, { .id = CYPRESS_AN2135, .name = "Cypress AN2135", .cpu_cs_register = 0x7f92 },
{ .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 }, { .id = CYPRESS_AN2235, .name = "Cypress AN2235", .cpu_cs_register = 0x7f92 },
{ .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 }, { .id = CYPRESS_FX2, .name = "Cypress FX2", .cpu_cs_register = 0xe600 },
@ -33,68 +33,113 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ); 0xa0, USB_TYPE_VENDOR, addr, 0x00, data, len, 5*HZ);
} }
int usb_cypress_load_firmware(struct usb_device *udev, const char *filename, int type) static int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
{ {
const struct firmware *fw = NULL; struct hexline hx;
u16 addr;
u8 *b,*p;
int ret = 0,i;
if ((ret = request_firmware(&fw, filename, &udev->dev)) != 0) {
err("did not find the firmware file. (%s) "
"Please see linux/Documentation/dvb/ for more details on firmware-problems.",
filename);
return ret;
}
info("downloading firmware from file '%s' to the '%s'",filename,cypress[type].name);
p = kmalloc(fw->size,GFP_KERNEL);
if (p != NULL) {
u8 reset; u8 reset;
/* int ret,pos=0;
* you cannot use the fw->data as buffer for
* usb_control_msg, a new buffer has to be
* created
*/
memcpy(p,fw->data,fw->size);
/* stop the CPU */ /* stop the CPU */
reset = 1; reset = 1;
if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1) if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
err("could not stop the USB controller CPU."); err("could not stop the USB controller CPU.");
for(i = 0; p[i+3] == 0 && i < fw->size; ) {
b = (u8 *) &p[i];
addr = cpu_to_le16( *((u16 *) &b[1]) );
deb_fw("writing to address 0x%04x (buffer: 0x%02x%02x)\n",addr,b[1],b[2]); while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
ret = usb_cypress_writemem(udev,addr,&b[4],b[0]); if (ret != hx.len) {
if (ret != b[0]) {
err("error while transferring firmware " err("error while transferring firmware "
"(transferred size: %d, block size: %d)", "(transferred size: %d, block size: %d)",
ret,b[0]); ret,hx.len);
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
i += 5 + b[0];
} }
/* length in ret */ if (ret < 0) {
if (ret > 0) err("firmware download failed at %d with %d",pos,ret);
ret = 0; return ret;
}
if (ret == 0) {
/* restart the CPU */ /* restart the CPU */
reset = 0; reset = 0;
if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) { if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
err("could not restart the USB controller CPU."); err("could not restart the USB controller CPU.");
ret = -EINVAL; ret = -EINVAL;
} }
} else
kfree(p); ret = -EIO;
} else {
ret = -ENOMEM;
}
release_firmware(fw);
return ret; return ret;
} }
int dvb_usb_download_firmware(struct usb_device *udev, struct dvb_usb_properties *props)
{
int ret;
const struct firmware *fw = NULL;
if ((ret = request_firmware(&fw, props->firmware, &udev->dev)) != 0) {
err("did not find the firmware file. (%s) "
"Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)",
props->firmware,ret);
return ret;
}
info("downloading firmware from file '%s'",props->firmware);
switch (props->usb_ctrl) {
case CYPRESS_AN2135:
case CYPRESS_AN2235:
case CYPRESS_FX2:
ret = usb_cypress_load_firmware(udev, fw, props->usb_ctrl);
break;
case DEVICE_SPECIFIC:
if (props->download_firmware)
ret = props->download_firmware(udev,fw);
else {
err("BUG: driver didn't specified a download_firmware-callback, although it claims to have a DEVICE_SPECIFIC one.");
ret = -EINVAL;
}
break;
default:
ret = -EINVAL;
break;
}
release_firmware(fw);
return ret;
}
int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, int *pos)
{
u8 *b = (u8 *) &fw->data[*pos];
int data_offs = 4;
if (*pos >= fw->size)
return 0;
memset(hx,0,sizeof(struct hexline));
hx->len = b[0];
if ((*pos + hx->len + 4) >= fw->size)
return -EINVAL;
hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
hx->type = b[3];
if (hx->type == 0x04) {
/* b[4] and b[5] are the Extended linear address record data field */
hx->addr |= (b[4] << 24) | (b[5] << 16);
/* hx->len -= 2;
data_offs += 2; */
}
memcpy(hx->data,&b[data_offs],hx->len);
hx->chk = b[hx->len + data_offs];
*pos += hx->len + 5;
return *pos;
}
EXPORT_SYMBOL(dvb_usb_get_hexline);

Просмотреть файл

@ -145,8 +145,11 @@ int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties
if (cold) { if (cold) {
info("found a '%s' in cold state, will try to load a firmware",desc->name); info("found a '%s' in cold state, will try to load a firmware",desc->name);
ret = usb_cypress_load_firmware(udev,props->firmware,props->usb_ctrl); ret = dvb_usb_download_firmware(udev,props);
} else { if (!props->no_reconnect)
return ret;
}
info("found a '%s' in warm state.",desc->name); info("found a '%s' in warm state.",desc->name);
d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL); d = kmalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
if (d == NULL) { if (d == NULL) {
@ -176,7 +179,6 @@ int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_properties
*du = d; *du = d;
ret = dvb_usb_init(d); ret = dvb_usb_init(d);
}
if (ret == 0) if (ret == 0)
info("%s successfully initialized and connected.",desc->name); info("%s successfully initialized and connected.",desc->name);

Просмотреть файл

@ -12,6 +12,7 @@
#include <linux/input.h> #include <linux/input.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/firmware.h>
#include "dvb_frontend.h" #include "dvb_frontend.h"
#include "dvb_demux.h" #include "dvb_demux.h"
@ -94,7 +95,11 @@ struct dvb_usb_device;
* @usb_ctrl: which USB device-side controller is in use. Needed for firmware * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
* download. * download.
* @firmware: name of the firmware file. * @firmware: name of the firmware file.
* * @download_firmware: called to download the firmware when the usb_ctrl is
* DEVICE_SPECIFIC.
* @no_reconnect: device doesn't do a reconnect after downloading the firmware,
so do the warm initialization right after it
* @size_of_priv: how many bytes shall be allocated for the private field * @size_of_priv: how many bytes shall be allocated for the private field
* of struct dvb_usb_device. * of struct dvb_usb_device.
* *
@ -142,11 +147,14 @@ struct dvb_usb_properties {
int caps; int caps;
int pid_filter_count; int pid_filter_count;
#define CYPRESS_AN2135 0 #define DEVICE_SPECIFIC 0
#define CYPRESS_AN2235 1 #define CYPRESS_AN2135 1
#define CYPRESS_FX2 2 #define CYPRESS_AN2235 2
#define CYPRESS_FX2 3
int usb_ctrl; int usb_ctrl;
const char *firmware; const char firmware[FIRMWARE_NAME_MAX];
int (*download_firmware) (struct usb_device *, const struct firmware *);
int no_reconnect;
int size_of_priv; int size_of_priv;
@ -326,5 +334,14 @@ extern int dvb_usb_pll_init_i2c(struct dvb_frontend *);
extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]); extern int dvb_usb_pll_set(struct dvb_frontend *, struct dvb_frontend_parameters *, u8[]);
extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *); extern int dvb_usb_pll_set_i2c(struct dvb_frontend *, struct dvb_frontend_parameters *);
/* commonly used firmware download types and function */
struct hexline {
u8 len;
u32 addr;
u8 type;
u8 data[255];
u8 chk;
};
extern int dvb_usb_get_hexline(const struct firmware *, struct hexline *, int *);
#endif #endif