Commit 60701d5f authored by Antti Palosaari's avatar Antti Palosaari Committed by Mauro Carvalho Chehab

[media] m88ds3103: refactor firmware download

* remove some unneeded variable initialization
* rename variables
* use min() macro to calc max i2c xfer len
* change bad firmware error code from EFAULT to EINVAL
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent f5d9b88d
...@@ -621,10 +621,10 @@ static int m88ds3103_init(struct dvb_frontend *fe) ...@@ -621,10 +621,10 @@ static int m88ds3103_init(struct dvb_frontend *fe)
struct m88ds3103_dev *dev = fe->demodulator_priv; struct m88ds3103_dev *dev = fe->demodulator_priv;
struct i2c_client *client = dev->client; struct i2c_client *client = dev->client;
struct dtv_frontend_properties *c = &fe->dtv_property_cache; struct dtv_frontend_properties *c = &fe->dtv_property_cache;
int ret, len, remaining; int ret, len, rem;
unsigned int utmp; unsigned int utmp;
const struct firmware *fw = NULL; const struct firmware *firmware;
u8 *fw_file; const char *name;
dev_dbg(&client->dev, "\n"); dev_dbg(&client->dev, "\n");
...@@ -650,7 +650,7 @@ static int m88ds3103_init(struct dvb_frontend *fe) ...@@ -650,7 +650,7 @@ static int m88ds3103_init(struct dvb_frontend *fe)
dev_dbg(&client->dev, "firmware=%02x\n", utmp); dev_dbg(&client->dev, "firmware=%02x\n", utmp);
if (utmp) if (utmp)
goto skip_fw_download; goto warm;
/* global reset, global diseqc reset, golbal fec reset */ /* global reset, global diseqc reset, golbal fec reset */
ret = regmap_write(dev->regmap, 0x07, 0xe0); ret = regmap_write(dev->regmap, 0x07, 0xe0);
...@@ -665,52 +665,47 @@ static int m88ds3103_init(struct dvb_frontend *fe) ...@@ -665,52 +665,47 @@ static int m88ds3103_init(struct dvb_frontend *fe)
m88ds3103_ops.info.name); m88ds3103_ops.info.name);
if (dev->chip_id == M88RS6000_CHIP_ID) if (dev->chip_id == M88RS6000_CHIP_ID)
fw_file = M88RS6000_FIRMWARE; name = M88RS6000_FIRMWARE;
else else
fw_file = M88DS3103_FIRMWARE; name = M88DS3103_FIRMWARE;
/* request the firmware, this will block and timeout */ /* request the firmware, this will block and timeout */
ret = request_firmware(&fw, fw_file, &client->dev); ret = request_firmware(&firmware, name, &client->dev);
if (ret) { if (ret) {
dev_err(&client->dev, "firmware file '%s' not found\n", fw_file); dev_err(&client->dev, "firmware file '%s' not found\n", name);
goto err; goto err;
} }
dev_info(&client->dev, "downloading firmware from file '%s'\n", dev_info(&client->dev, "downloading firmware from file '%s'\n", name);
fw_file);
ret = regmap_write(dev->regmap, 0xb2, 0x01); ret = regmap_write(dev->regmap, 0xb2, 0x01);
if (ret) if (ret)
goto error_fw_release; goto err_release_firmware;
for (remaining = fw->size; remaining > 0;
remaining -= (dev->cfg->i2c_wr_max - 1)) {
len = remaining;
if (len > (dev->cfg->i2c_wr_max - 1))
len = (dev->cfg->i2c_wr_max - 1);
for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) {
len = min(dev->cfg->i2c_wr_max - 1, rem);
ret = regmap_bulk_write(dev->regmap, 0xb0, ret = regmap_bulk_write(dev->regmap, 0xb0,
&fw->data[fw->size - remaining], len); &firmware->data[firmware->size - rem],
len);
if (ret) { if (ret) {
dev_err(&client->dev, "firmware download failed=%d\n", dev_err(&client->dev, "firmware download failed %d\n",
ret); ret);
goto error_fw_release; goto err_release_firmware;
} }
} }
ret = regmap_write(dev->regmap, 0xb2, 0x00); ret = regmap_write(dev->regmap, 0xb2, 0x00);
if (ret) if (ret)
goto error_fw_release; goto err_release_firmware;
release_firmware(fw); release_firmware(firmware);
fw = NULL;
ret = regmap_read(dev->regmap, 0xb9, &utmp); ret = regmap_read(dev->regmap, 0xb9, &utmp);
if (ret) if (ret)
goto err; goto err;
if (!utmp) { if (!utmp) {
ret = -EINVAL;
dev_info(&client->dev, "firmware did not run\n"); dev_info(&client->dev, "firmware did not run\n");
ret = -EFAULT;
goto err; goto err;
} }
...@@ -719,7 +714,7 @@ static int m88ds3103_init(struct dvb_frontend *fe) ...@@ -719,7 +714,7 @@ static int m88ds3103_init(struct dvb_frontend *fe)
dev_info(&client->dev, "firmware version: %X.%X\n", dev_info(&client->dev, "firmware version: %X.%X\n",
(utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); (utmp >> 4) & 0xf, (utmp >> 0 & 0xf));
skip_fw_download: warm:
/* warm state */ /* warm state */
dev->warm = true; dev->warm = true;
...@@ -732,8 +727,8 @@ static int m88ds3103_init(struct dvb_frontend *fe) ...@@ -732,8 +727,8 @@ static int m88ds3103_init(struct dvb_frontend *fe)
c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
return 0; return 0;
error_fw_release: err_release_firmware:
release_firmware(fw); release_firmware(firmware);
err: err:
dev_dbg(&client->dev, "failed=%d\n", ret); dev_dbg(&client->dev, "failed=%d\n", ret);
return ret; return ret;
......
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