Commit 22b88deb authored by Kory Maincent (TI.com)'s avatar Kory Maincent (TI.com) Committed by Luca Ceresoli
Browse files

drm/bridge: tda998x: Move tda998x_create/destroy into probe and remove



Now that tda998x_create and tda998x_destroy are called only in the probe
function, there is no need for separate functions.
Move the code into the tda998x_probe and tda998x_remove functions.
Rewrite the cleanup path using goto calls in probe and reorder it in the
remove function.

Reviewed-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: default avatarKory Maincent (TI.com) <kory.maincent@bootlin.com>
Link: https://patch.msgid.link/20260123-feature_tilcdc-v5-22-5a44d2aa3f6f@bootlin.com


Signed-off-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
parent d700fd0f
Loading
Loading
Loading
Loading
+51 −48
Original line number Diff line number Diff line
@@ -1748,38 +1748,20 @@ static int tda998x_get_audio_ports(struct tda998x_priv *priv,
	return 0;
}

static void tda998x_destroy(struct device *dev)
{
	struct tda998x_priv *priv = dev_get_drvdata(dev);

	drm_bridge_remove(&priv->bridge);

	/* disable all IRQs and free the IRQ handler */
	cec_write(priv, REG_CEC_RXSHPDINTENA, 0);
	reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);

	if (priv->audio_pdev)
		platform_device_unregister(priv->audio_pdev);

	if (priv->hdmi->irq)
		free_irq(priv->hdmi->irq, priv);

	timer_delete_sync(&priv->edid_delay_timer);
	cancel_work_sync(&priv->detect_work);

	i2c_unregister_device(priv->cec);

	cec_notifier_conn_unregister(priv->cec_notify);
}

static int tda998x_create(struct device *dev)
static int
tda998x_probe(struct i2c_client *client)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct device_node *np = client->dev.of_node;
	struct device *dev = &client->dev;
	struct i2c_board_info cec_info;
	struct tda998x_priv *priv;
	u32 video;
	int rev_lo, rev_hi, ret;
	u32 video;

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_warn(&client->dev, "adapter does not support I2C\n");
		return -EIO;
	}

	priv = devm_drm_bridge_alloc(dev, struct tda998x_priv, bridge, &tda998x_bridge_funcs);
	if (IS_ERR(priv))
@@ -1814,13 +1796,15 @@ static int tda998x_create(struct device *dev)
	rev_lo = reg_read(priv, REG_VERSION_LSB);
	if (rev_lo < 0) {
		dev_err(dev, "failed to read version: %d\n", rev_lo);
		return rev_lo;
		ret = rev_lo;
		goto cancel_work;
	}

	rev_hi = reg_read(priv, REG_VERSION_MSB);
	if (rev_hi < 0) {
		dev_err(dev, "failed to read version: %d\n", rev_hi);
		return rev_hi;
		ret = rev_hi;
		goto cancel_work;
	}

	priv->rev = rev_lo | rev_hi << 8;
@@ -1843,7 +1827,8 @@ static int tda998x_create(struct device *dev)
		break;
	default:
		dev_err(dev, "found unsupported device: %04x\n", priv->rev);
		return -ENXIO;
		ret = -ENXIO;
		goto cancel_work;
	}

	/* after reset, enable DDC: */
@@ -1887,7 +1872,7 @@ static int tda998x_create(struct device *dev)
		if (ret) {
			dev_err(dev, "failed to request IRQ#%u: %d\n",
				client->irq, ret);
			goto err_irq;
			goto cancel_work;
		}

		/* enable HPD irq */
@@ -1897,7 +1882,7 @@ static int tda998x_create(struct device *dev)
	priv->cec_notify = cec_notifier_conn_register(dev, NULL, NULL);
	if (!priv->cec_notify) {
		ret = -ENOMEM;
		goto fail;
		goto free_irq;
	}

	priv->cec_glue.parent = dev;
@@ -1924,7 +1909,7 @@ static int tda998x_create(struct device *dev)
	priv->cec = i2c_new_client_device(client->adapter, &cec_info);
	if (IS_ERR(priv->cec)) {
		ret = PTR_ERR(priv->cec);
		goto fail;
		goto notifier_conn_unregister;
	}

	/* enable EDID read irq: */
@@ -1941,7 +1926,7 @@ static int tda998x_create(struct device *dev)

		ret = tda998x_get_audio_ports(priv, np);
		if (ret)
			goto fail;
			goto unregister_dev;

		if (priv->audio_port_enable[AUDIO_ROUTE_I2S] ||
		    priv->audio_port_enable[AUDIO_ROUTE_SPDIF])
@@ -1956,26 +1941,44 @@ static int tda998x_create(struct device *dev)

	return 0;

fail:
	tda998x_destroy(dev);
err_irq:
unregister_dev:
	i2c_unregister_device(priv->cec);
notifier_conn_unregister:
	cec_notifier_conn_unregister(priv->cec_notify);
free_irq:
	if (client->irq) {
		cec_write(priv, REG_CEC_RXSHPDINTENA, 0);
		reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);
		free_irq(client->irq, priv);
	}
cancel_work:
	timer_delete_sync(&priv->edid_delay_timer);
	cancel_work_sync(&priv->detect_work);
	return ret;
}

static int
tda998x_probe(struct i2c_client *client)
static void tda998x_remove(struct i2c_client *client)
{
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		dev_warn(&client->dev, "adapter does not support I2C\n");
		return -EIO;
	}
	struct tda998x_priv *priv = dev_get_drvdata(&client->dev);

	drm_bridge_remove(&priv->bridge);

	return tda998x_create(&client->dev);
	if (priv->audio_pdev)
		platform_device_unregister(priv->audio_pdev);

	i2c_unregister_device(priv->cec);

	cec_notifier_conn_unregister(priv->cec_notify);

	/* disable all IRQs and free the IRQ handler */
	if (client->irq) {
		cec_write(priv, REG_CEC_RXSHPDINTENA, 0);
		reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);
		free_irq(priv->hdmi->irq, priv);
	}

static void tda998x_remove(struct i2c_client *client)
{
	tda998x_destroy(&client->dev);
	timer_delete_sync(&priv->edid_delay_timer);
	cancel_work_sync(&priv->detect_work);
}

#ifdef CONFIG_OF