diff options
author | Antti Palosaari <crope@iki.fi> | 2011-03-19 15:51:43 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 03:54:58 -0400 |
commit | 582e565caeaccf145e2256b84d4fde827fede72e (patch) | |
tree | 73e9ae6fcb6d40e15860b6352fa1f2f4dd4c8965 /drivers/media/dvb/dvb-usb | |
parent | 04599c2b1ff1eece19b7abaacd97266b8a6b79f2 (diff) |
[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: Antti Palosaari <crope@iki.fi>
Cc: Andrea Merello <andrea.merello@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/dvb-usb')
-rw-r--r-- | drivers/media/dvb/dvb-usb/af9015.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c index 0bbc91f50381..100ebc37e99e 100644 --- a/drivers/media/dvb/dvb-usb/af9015.c +++ b/drivers/media/dvb/dvb-usb/af9015.c | |||
@@ -665,9 +665,8 @@ error: | |||
665 | static int af9015_download_firmware(struct usb_device *udev, | 665 | static int af9015_download_firmware(struct usb_device *udev, |
666 | const struct firmware *fw) | 666 | const struct firmware *fw) |
667 | { | 667 | { |
668 | int i, len, packets, remainder, ret; | 668 | int i, len, remaining, ret; |
669 | struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; | 669 | struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; |
670 | u16 addr = 0x5100; /* firmware start address */ | ||
671 | u16 checksum = 0; | 670 | u16 checksum = 0; |
672 | 671 | ||
673 | deb_info("%s:\n", __func__); | 672 | deb_info("%s:\n", __func__); |
@@ -679,24 +678,20 @@ static int af9015_download_firmware(struct usb_device *udev, | |||
679 | af9015_config.firmware_size = fw->size; | 678 | af9015_config.firmware_size = fw->size; |
680 | af9015_config.firmware_checksum = checksum; | 679 | af9015_config.firmware_checksum = checksum; |
681 | 680 | ||
682 | #define FW_PACKET_MAX_DATA 55 | 681 | #define FW_ADDR 0x5100 /* firmware start address */ |
683 | 682 | #define LEN_MAX 55 /* max packet size */ | |
684 | packets = fw->size / FW_PACKET_MAX_DATA; | 683 | for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) { |
685 | remainder = fw->size % FW_PACKET_MAX_DATA; | 684 | len = remaining; |
686 | len = FW_PACKET_MAX_DATA; | 685 | if (len > LEN_MAX) |
687 | for (i = 0; i <= packets; i++) { | 686 | len = LEN_MAX; |
688 | if (i == packets) /* set size of the last packet */ | ||
689 | len = remainder; | ||
690 | 687 | ||
691 | req.data_len = len; | 688 | req.data_len = len; |
692 | req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA); | 689 | req.data = (u8 *) &fw->data[fw->size - remaining]; |
693 | req.addr = addr; | 690 | req.addr = FW_ADDR + fw->size - remaining; |
694 | addr += FW_PACKET_MAX_DATA; | ||
695 | 691 | ||
696 | ret = af9015_rw_udev(udev, &req); | 692 | ret = af9015_rw_udev(udev, &req); |
697 | if (ret) { | 693 | if (ret) { |
698 | err("firmware download failed at packet %d with " \ | 694 | err("firmware download failed:%d", ret); |
699 | "code %d", i, ret); | ||
700 | goto error; | 695 | goto error; |
701 | } | 696 | } |
702 | } | 697 | } |