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

[media] af9013: refactor power control

Move power-up and power-down functionality to init/sleep ops and
get rid of old function.

Fixes and simplifies power-up functionality slightly.
Signed-off-by: default avatarAntti Palosaari <crope@iki.fi>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 96700d24
...@@ -101,59 +101,6 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) ...@@ -101,59 +101,6 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
return ret; return ret;
} }
static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
{
struct i2c_client *client = state->client;
int ret;
unsigned int utmp;
dev_dbg(&client->dev, "onoff %d\n", onoff);
/* enable reset */
ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x10);
if (ret)
goto err;
/* start reset mechanism */
ret = regmap_write(state->regmap, 0xaeff, 0x01);
if (ret)
goto err;
/* wait reset performs */
ret = regmap_read_poll_timeout(state->regmap, 0xd417, utmp,
(utmp >> 1) & 0x01, 5000, 1000000);
if (ret)
goto err;
if (!((utmp >> 1) & 0x01))
return -ETIMEDOUT;
if (onoff) {
/* clear reset */
ret = regmap_update_bits(state->regmap, 0xd417, 0x02, 0x00);
if (ret)
goto err;
/* disable reset */
ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x00);
if (ret)
goto err;
/* power on */
ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x00);
if (ret)
goto err;
} else {
/* power off */
ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x08);
if (ret)
goto err;
}
return 0;
err:
dev_dbg(&client->dev, "failed %d\n", ret);
return ret;
}
static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe) static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe)
{ {
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
...@@ -890,8 +837,18 @@ static int af9013_init(struct dvb_frontend *fe) ...@@ -890,8 +837,18 @@ static int af9013_init(struct dvb_frontend *fe)
dev_dbg(&client->dev, "\n"); dev_dbg(&client->dev, "\n");
/* power on */ /* ADC on */
ret = af9013_power_ctrl(state, 1); ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x00);
if (ret)
goto err;
/* Clear reset */
ret = regmap_update_bits(state->regmap, 0xd417, 0x02, 0x00);
if (ret)
goto err;
/* Disable reset */
ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x00);
if (ret) if (ret)
goto err; goto err;
...@@ -1071,6 +1028,7 @@ static int af9013_sleep(struct dvb_frontend *fe) ...@@ -1071,6 +1028,7 @@ static int af9013_sleep(struct dvb_frontend *fe)
struct af9013_state *state = fe->demodulator_priv; struct af9013_state *state = fe->demodulator_priv;
struct i2c_client *client = state->client; struct i2c_client *client = state->client;
int ret; int ret;
unsigned int utmp;
dev_dbg(&client->dev, "\n"); dev_dbg(&client->dev, "\n");
...@@ -1082,8 +1040,29 @@ static int af9013_sleep(struct dvb_frontend *fe) ...@@ -1082,8 +1040,29 @@ static int af9013_sleep(struct dvb_frontend *fe)
if (ret) if (ret)
goto err; goto err;
/* power off */ /* Enable reset */
ret = af9013_power_ctrl(state, 0); ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x10);
if (ret)
goto err;
/* Start reset execution */
ret = regmap_write(state->regmap, 0xaeff, 0x01);
if (ret)
goto err;
/* Wait reset performs */
ret = regmap_read_poll_timeout(state->regmap, 0xd417, utmp,
(utmp >> 1) & 0x01, 5000, 1000000);
if (ret)
goto err;
if (!((utmp >> 1) & 0x01)) {
ret = -ETIMEDOUT;
goto err;
}
/* ADC off */
ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x08);
if (ret) if (ret)
goto err; goto err;
......
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