Commit 6ed9d560 authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] af9013: 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 109a2990
...@@ -1323,13 +1323,11 @@ static struct dvb_frontend_ops af9013_ops; ...@@ -1323,13 +1323,11 @@ static struct dvb_frontend_ops af9013_ops;
static int af9013_download_firmware(struct af9013_state *state) static int af9013_download_firmware(struct af9013_state *state)
{ {
int i, len, packets, remainder, ret; int i, len, remaining, ret;
const struct firmware *fw; const struct firmware *fw;
u16 addr = 0x5100; /* firmware start address */
u16 checksum = 0; u16 checksum = 0;
u8 val; u8 val;
u8 fw_params[4]; u8 fw_params[4];
u8 *data;
u8 *fw_file = AF9013_DEFAULT_FIRMWARE; u8 *fw_file = AF9013_DEFAULT_FIRMWARE;
msleep(100); msleep(100);
...@@ -1373,21 +1371,18 @@ static int af9013_download_firmware(struct af9013_state *state) ...@@ -1373,21 +1371,18 @@ static int af9013_download_firmware(struct af9013_state *state)
if (ret) if (ret)
goto error_release; goto error_release;
#define FW_PACKET_MAX_DATA 16 #define FW_ADDR 0x5100 /* firmware start address */
#define LEN_MAX 16 /* 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;
data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
ret = af9013_write_ofsm_regs(state, addr, data, len);
addr += FW_PACKET_MAX_DATA;
ret = af9013_write_ofsm_regs(state,
FW_ADDR + fw->size - remaining,
(u8 *) &fw->data[fw->size - remaining], len);
if (ret) { if (ret) {
err("firmware download failed at %d with %d", i, ret); err("firmware download failed:%d", ret);
goto error_release; goto error_release;
} }
} }
......
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