Commit 8f7cc5c0 authored by Corentin Labbe's avatar Corentin Labbe Committed by Mauro Carvalho Chehab
Browse files

media: staging: media: zoran: introduce zoran_i2c_init



Reduces the size of the probe function by adding zoran_i2c_init and
zoran_i2c_exit functions.

Signed-off-by: default avatarCorentin Labbe <clabbe@baylibre.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 3b70b0ec
Loading
Loading
Loading
Loading
+54 −19
Original line number Diff line number Diff line
@@ -931,6 +931,53 @@ static int zoran_init_video_devices(struct zoran *zr)
	return err;
}

/*
 * v4l2_device_unregister() will care about removing zr->encoder/zr->decoder
 * via v4l2_i2c_subdev_unregister()
 */
static int zoran_i2c_init(struct zoran *zr)
{
	int err;

	pci_info(zr->pci_dev, "Initializing i2c bus...\n");

	err = zoran_register_i2c(zr);
	if (err) {
		pci_err(zr->pci_dev, "%s - cannot initialize i2c bus\n", __func__);
		return err;
	}

	zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
					  zr->card.i2c_decoder, 0,
					  zr->card.addrs_decoder);
	if (!zr->decoder) {
		pci_err(zr->pci_dev, "Fail to get decoder %s\n", zr->card.i2c_decoder);
		err = -EINVAL;
		goto error_decoder;
	}

	if (zr->card.i2c_encoder) {
		zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
						  zr->card.i2c_encoder, 0,
						  zr->card.addrs_encoder);
		if (!zr->encoder) {
			pci_err(zr->pci_dev, "Fail to get encoder %s\n", zr->card.i2c_encoder);
			err = -EINVAL;
			goto error_decoder;
		}
	}
	return 0;

error_decoder:
	zoran_unregister_i2c(zr);
	return err;
}

static void zoran_i2c_exit(struct zoran *zr)
{
	zoran_unregister_i2c(zr);
}

void zoran_open_init_params(struct zoran *zr)
{
	int i;
@@ -1059,7 +1106,7 @@ static void zoran_remove(struct pci_dev *pdev)
	videocodec_exit(zr);

	/* unregister i2c bus */
	zoran_unregister_i2c(zr);
	zoran_i2c_exit(zr);
	/* disable PCI bus-mastering */
	zoran_set_pci_master(zr, 0);
	/* put chip into reset */
@@ -1340,22 +1387,10 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
	}

	zr36057_restart(zr);
	/* i2c */
	pci_info(zr->pci_dev, "Initializing i2c bus...\n");

	if (zoran_register_i2c(zr) < 0) {
		pci_err(pdev, "%s - can't initialize i2c bus\n", __func__);
	err = zoran_i2c_init(zr);
	if (err)
		goto zr_free_irq;
	}

	zr->decoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
					  zr->card.i2c_decoder, 0,
					  zr->card.addrs_decoder);

	if (zr->card.i2c_encoder)
		zr->encoder = v4l2_i2c_new_subdev(&zr->v4l2_dev, &zr->i2c_adapter,
						  zr->card.i2c_encoder, 0,
						  zr->card.addrs_encoder);

	pci_info(zr->pci_dev, "Initializing videocodec bus...\n");
	err = videocodec_init(zr);
@@ -1370,15 +1405,15 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
	if (zr->card.video_codec != 0) {
		master_codec = zoran_setup_videocodec(zr, zr->card.video_codec);
		if (!master_codec)
			goto zr_unreg_i2c;
			goto zr_unreg_videocodec;
		zr->codec = videocodec_attach(master_codec);
		if (!zr->codec) {
			pci_err(pdev, "%s - no codec found\n", __func__);
			goto zr_unreg_i2c;
			goto zr_unreg_videocodec;
		}
		if (zr->codec->type != zr->card.video_codec) {
			pci_err(pdev, "%s - wrong codec\n", __func__);
			goto zr_detach_codec;
			goto zr_unreg_videocodec;
		}
	}
	if (zr->card.video_vfe != 0) {
@@ -1417,7 +1452,7 @@ static int zoran_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
zr_unreg_videocodec:
	videocodec_exit(zr);
zr_unreg_i2c:
	zoran_unregister_i2c(zr);
	zoran_i2c_exit(zr);
zr_free_irq:
	btwrite(0, ZR36057_SPGPPCR);
	pci_free_irq(zr->pci_dev, 0, zr);