[media] af9013: refactor power control
authorAntti Palosaari <crope@iki.fi>
Wed, 14 Jun 2017 01:58:06 +0000 (22:58 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 20 Jun 2017 13:35:08 +0000 (10:35 -0300)
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: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/dvb-frontends/af9013.c

index 8408e155b6f5d2353af0bed6c33dcfa24aa65842..b8f3ebfc3e272af4979cca68a10f0eb993127785 100644 (file)
@@ -101,59 +101,6 @@ err:
        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)
 {
        struct af9013_state *state = fe->demodulator_priv;
@@ -890,8 +837,18 @@ static int af9013_init(struct dvb_frontend *fe)
 
        dev_dbg(&client->dev, "\n");
 
-       /* power on */
-       ret = af9013_power_ctrl(state, 1);
+       /* ADC on */
+       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)
                goto err;
 
@@ -1071,6 +1028,7 @@ static int af9013_sleep(struct dvb_frontend *fe)
        struct af9013_state *state = fe->demodulator_priv;
        struct i2c_client *client = state->client;
        int ret;
+       unsigned int utmp;
 
        dev_dbg(&client->dev, "\n");
 
@@ -1082,8 +1040,29 @@ static int af9013_sleep(struct dvb_frontend *fe)
        if (ret)
                goto err;
 
-       /* power off */
-       ret = af9013_power_ctrl(state, 0);
+       /* Enable reset */
+       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)
                goto err;