Commit 582e565c authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] af9015: reimplement firmware download

Split FW download packages smarter way and bug free. Implementation is
based of Andrea Merello's example he provided for tda18218 driver.
Count remaining FW bytes down in loop instead of division and modulo
combination used earlier.

Thanks-to: Andrea Merello <andrea.merello@gmail.com>
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Cc: Andrea Merello <andrea.merello@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 04599c2b
...@@ -665,9 +665,8 @@ static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, ...@@ -665,9 +665,8 @@ static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
static int af9015_download_firmware(struct usb_device *udev, static int af9015_download_firmware(struct usb_device *udev,
const struct firmware *fw) const struct firmware *fw)
{ {
int i, len, packets, remainder, ret; int i, len, remaining, ret;
struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
u16 addr = 0x5100; /* firmware start address */
u16 checksum = 0; u16 checksum = 0;
deb_info("%s:\n", __func__); deb_info("%s:\n", __func__);
...@@ -679,24 +678,20 @@ static int af9015_download_firmware(struct usb_device *udev, ...@@ -679,24 +678,20 @@ static int af9015_download_firmware(struct usb_device *udev,
af9015_config.firmware_size = fw->size; af9015_config.firmware_size = fw->size;
af9015_config.firmware_checksum = checksum; af9015_config.firmware_checksum = checksum;
#define FW_PACKET_MAX_DATA 55 #define FW_ADDR 0x5100 /* firmware start address */
#define LEN_MAX 55 /* max packet size */
packets = fw->size / FW_PACKET_MAX_DATA; for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
remainder = fw->size % FW_PACKET_MAX_DATA; len = remaining;
len = FW_PACKET_MAX_DATA; if (len > LEN_MAX)
for (i = 0; i <= packets; i++) { len = LEN_MAX;
if (i == packets) /* set size of the last packet */
len = remainder;
req.data_len = len; req.data_len = len;
req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA); req.data = (u8 *) &fw->data[fw->size - remaining];
req.addr = addr; req.addr = FW_ADDR + fw->size - remaining;
addr += FW_PACKET_MAX_DATA;
ret = af9015_rw_udev(udev, &req); ret = af9015_rw_udev(udev, &req);
if (ret) { if (ret) {
err("firmware download failed at packet %d with " \ err("firmware download failed:%d", ret);
"code %d", i, ret);
goto error; goto error;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment