media: i2c: ds90ub960: Move all RX port init code into ub960_init_rx_ports()
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Mon, 3 Mar 2025 16:02:17 +0000 (21:32 +0530)
committerHans Verkuil <hverkuil@xs4all.nl>
Fri, 25 Apr 2025 08:15:08 +0000 (10:15 +0200)
We have some code in probe() which is related to RX port initialization,
and should be in ub960_init_rx_ports(). Move the code there.

We also move ub960_reset() so that it is accessible from
ub960_init_rx_ports().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Jai Luthra <jai.luthra@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/i2c/ds90ub960.c

index af7ba1c824b12893bd31bed7a88a6e3bf8a62f7e..130bf4cc0a7485e997dd979954a9b6d28b693a5a 100644 (file)
@@ -1225,6 +1225,33 @@ out_unlock:
        return ret;
 }
 
+static int ub960_reset(struct ub960_data *priv, bool reset_regs)
+{
+       struct device *dev = &priv->client->dev;
+       unsigned int v;
+       int ret;
+       u8 bit;
+
+       bit = reset_regs ? UB960_SR_RESET_DIGITAL_RESET1 :
+                          UB960_SR_RESET_DIGITAL_RESET0;
+
+       ret = ub960_write(priv, UB960_SR_RESET, bit, NULL);
+       if (ret)
+               return ret;
+
+       mutex_lock(&priv->reg_lock);
+
+       ret = regmap_read_poll_timeout(priv->regmap, UB960_SR_RESET, v,
+                                      (v & bit) == 0, 2000, 100000);
+
+       mutex_unlock(&priv->reg_lock);
+
+       if (ret)
+               dev_err(dev, "reset failed: %d\n", ret);
+
+       return ret;
+}
+
 /* -----------------------------------------------------------------------------
  * I2C-ATR (address translator)
  */
@@ -2493,6 +2520,11 @@ static int ub960_init_rx_port_ub9702(struct ub960_data *priv,
 
 static int ub960_init_rx_ports(struct ub960_data *priv)
 {
+       struct device *dev = &priv->client->dev;
+       unsigned int port_lock_mask;
+       unsigned int port_mask;
+       int ret;
+
        for_each_active_rxport(priv, it) {
                int ret;
 
@@ -2505,6 +2537,33 @@ static int ub960_init_rx_ports(struct ub960_data *priv)
                        return ret;
        }
 
+       ret = ub960_reset(priv, false);
+       if (ret)
+               return ret;
+
+       port_mask = 0;
+
+       for_each_active_rxport(priv, it)
+               port_mask |= BIT(it.nport);
+
+       ret = ub960_rxport_wait_locks(priv, port_mask, &port_lock_mask);
+       if (ret)
+               return ret;
+
+       if (port_mask != port_lock_mask) {
+               ret = -EIO;
+               dev_err_probe(dev, ret, "Failed to lock all RX ports\n");
+               return ret;
+       }
+
+       /*
+        * Clear any errors caused by switching the RX port settings while
+        * probing.
+        */
+       ret = ub960_clear_rx_errors(priv);
+       if (ret)
+               return ret;
+
        return 0;
 }
 
@@ -4168,33 +4227,6 @@ static const struct regmap_config ub960_regmap_config = {
        .disable_locking = true,
 };
 
-static int ub960_reset(struct ub960_data *priv, bool reset_regs)
-{
-       struct device *dev = &priv->client->dev;
-       unsigned int v;
-       int ret;
-       u8 bit;
-
-       bit = reset_regs ? UB960_SR_RESET_DIGITAL_RESET1 :
-                          UB960_SR_RESET_DIGITAL_RESET0;
-
-       ret = ub960_write(priv, UB960_SR_RESET, bit, NULL);
-       if (ret)
-               return ret;
-
-       mutex_lock(&priv->reg_lock);
-
-       ret = regmap_read_poll_timeout(priv->regmap, UB960_SR_RESET, v,
-                                      (v & bit) == 0, 2000, 100000);
-
-       mutex_unlock(&priv->reg_lock);
-
-       if (ret)
-               dev_err(dev, "reset failed: %d\n", ret);
-
-       return ret;
-}
-
 static int ub960_get_hw_resources(struct ub960_data *priv)
 {
        struct device *dev = &priv->client->dev;
@@ -4319,8 +4351,6 @@ static int ub960_probe(struct i2c_client *client)
 {
        struct device *dev = &client->dev;
        struct ub960_data *priv;
-       unsigned int port_lock_mask;
-       unsigned int port_mask;
        int ret;
 
        priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -4367,33 +4397,6 @@ static int ub960_probe(struct i2c_client *client)
        if (ret)
                goto err_disable_vpocs;
 
-       ret = ub960_reset(priv, false);
-       if (ret)
-               goto err_disable_vpocs;
-
-       port_mask = 0;
-
-       for_each_active_rxport(priv, it)
-               port_mask |= BIT(it.nport);
-
-       ret = ub960_rxport_wait_locks(priv, port_mask, &port_lock_mask);
-       if (ret)
-               goto err_disable_vpocs;
-
-       if (port_mask != port_lock_mask) {
-               ret = -EIO;
-               dev_err_probe(dev, ret, "Failed to lock all RX ports\n");
-               goto err_disable_vpocs;
-       }
-
-       /*
-        * Clear any errors caused by switching the RX port settings while
-        * probing.
-        */
-       ret = ub960_clear_rx_errors(priv);
-       if (ret)
-               goto err_disable_vpocs;
-
        ret = ub960_init_atr(priv);
        if (ret)
                goto err_disable_vpocs;