Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6574f2f authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (11373): v4l2-common: add explicit v4l2_device pointer as first arg to new_(probed)_subdev



The functions v4l2_i2c_new_subdev and v4l2_i2c_new_probed_subdev relied on
i2c_get_adapdata to return the v4l2_device. However, this is not always
possible on embedded platforms. So modify the API to pass the v4l2_device
pointer explicitly.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 868f985c
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -364,14 +364,12 @@ from the remove() callback ensures that this is always done correctly.

The bridge driver also has some helper functions it can use:

struct v4l2_subdev *sd = v4l2_i2c_new_subdev(adapter, "module_foo", "chipid", 0x36);
struct v4l2_subdev *sd = v4l2_i2c_new_subdev(v4l2_dev, adapter,
	       "module_foo", "chipid", 0x36);

This loads the given module (can be NULL if no module needs to be loaded) and
calls i2c_new_device() with the given i2c_adapter and chip/address arguments.
If all goes well, then it registers the subdev with the v4l2_device. It gets
the v4l2_device by calling i2c_get_adapdata(adapter), so you should make sure
to call i2c_set_adapdata(adapter, v4l2_device) when you setup the i2c_adapter
in your driver.
If all goes well, then it registers the subdev with the v4l2_device.

You can also use v4l2_i2c_new_probed_subdev() which is very similar to
v4l2_i2c_new_subdev(), except that it has an array of possible I2C addresses
+4 −4
Original line number Diff line number Diff line
@@ -211,8 +211,8 @@ void au0828_card_setup(struct au0828_dev *dev)
		/* Load the analog demodulator driver (note this would need to
		   be abstracted out if we ever need to support a different
		   demod) */
		sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "au8522", "au8522",
					 0x8e >> 1);
		sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
				"au8522", "au8522", 0x8e >> 1);
		if (sd == NULL)
			printk(KERN_ERR "analog subdev registration failed\n");
	}
@@ -220,8 +220,8 @@ void au0828_card_setup(struct au0828_dev *dev)
	/* Setup tuners */
	if (dev->board.tuner_type != TUNER_ABSENT) {
		/* Load the tuner module, which does the attach */
		sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
					 dev->board.tuner_addr);
		sd = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
				"tuner", "tuner", dev->board.tuner_addr);
		if (sd == NULL)
			printk(KERN_ERR "tuner subdev registration fail\n");

+25 −22
Original line number Diff line number Diff line
@@ -3512,12 +3512,15 @@ void __devinit bttv_init_card2(struct bttv *btv)

		/* Load tuner module before issuing tuner config call! */
		if (bttv_tvcards[btv->c.type].has_radio)
			v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"tuner", "tuner", v4l2_i2c_tuner_addrs(ADDRS_RADIO));
		v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap, "tuner",
				"tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
		v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap, "tuner",
				"tuner", v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD));
			v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
				&btv->c.i2c_adap, "tuner", "tuner",
				v4l2_i2c_tuner_addrs(ADDRS_RADIO));
		v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
				&btv->c.i2c_adap, "tuner", "tuner",
				v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
		v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
				&btv->c.i2c_adap, "tuner", "tuner",
				v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD));

		tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV;
		tun_setup.type = btv->tuner_type;
@@ -3570,8 +3573,8 @@ void __devinit bttv_init_card2(struct bttv *btv)
		};
		struct v4l2_subdev *sd;

		sd = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"saa6588", "saa6588", addrs);
		sd = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
			&btv->c.i2c_adap, "saa6588", "saa6588", addrs);
		btv->has_saa6588 = (sd != NULL);
	}

@@ -3595,8 +3598,8 @@ void __devinit bttv_init_card2(struct bttv *btv)
			I2C_CLIENT_END
		};

		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"msp3400", "msp3400", addrs);
		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
			&btv->c.i2c_adap, "msp3400", "msp3400", addrs);
		if (btv->sd_msp34xx)
			return;
		goto no_audio;
@@ -3609,16 +3612,16 @@ void __devinit bttv_init_card2(struct bttv *btv)
			I2C_CLIENT_END
		};

		if (v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"tda7432", "tda7432", addrs))
		if (v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
				&btv->c.i2c_adap, "tda7432", "tda7432", addrs))
			return;
		goto no_audio;
	}

	case 3: {
		/* The user specified that we should probe for tvaudio */
		btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"tvaudio", "tvaudio", tvaudio_addrs);
		btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
			&btv->c.i2c_adap, "tvaudio", "tvaudio", tvaudio_addrs);
		if (btv->sd_tvaudio)
			return;
		goto no_audio;
@@ -3642,16 +3645,16 @@ void __devinit bttv_init_card2(struct bttv *btv)
			I2C_CLIENT_END
		};

		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"msp3400", "msp3400", addrs);
		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
			&btv->c.i2c_adap, "msp3400", "msp3400", addrs);
	} else if (bttv_tvcards[btv->c.type].msp34xx_alt) {
		static const unsigned short addrs[] = {
			I2C_ADDR_MSP3400_ALT >> 1,
			I2C_CLIENT_END
		};

		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"msp3400", "msp3400", addrs);
		btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
			&btv->c.i2c_adap, "msp3400", "msp3400", addrs);
	}

	/* If we found a msp34xx, then we're done. */
@@ -3665,14 +3668,14 @@ void __devinit bttv_init_card2(struct bttv *btv)
			I2C_CLIENT_END
		};

		if (v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
				"tda7432", "tda7432", addrs))
		if (v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
				&btv->c.i2c_adap, "tda7432", "tda7432", addrs))
			return;
	}

	/* Now see if we can find one of the tvaudio devices. */
	btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
			"tvaudio", "tvaudio", tvaudio_addrs);
	btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.v4l2_dev,
		&btv->c.i2c_adap, "tvaudio", "tvaudio", tvaudio_addrs);
	if (btv->sd_tvaudio)
		return;

+1 −1
Original line number Diff line number Diff line
@@ -1954,7 +1954,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
		goto out_freeirq;

	cam->sensor_addr = 0x42;
	cam->sensor = v4l2_i2c_new_subdev(&cam->i2c_adapter,
	cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, &cam->i2c_adapter,
			"ov7670", "ov7670", cam->sensor_addr);
	if (cam->sensor == NULL) {
		ret = -ENODEV;
+7 −7
Original line number Diff line number Diff line
@@ -100,16 +100,16 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)

	if (hw == CX18_HW_TUNER) {
		/* special tuner group handling */
		sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
						cx->card_i2c->radio);
		sd = v4l2_i2c_new_probed_subdev(&cx->v4l2_dev,
				adap, mod, type, cx->card_i2c->radio);
		if (sd != NULL)
			sd->grp_id = hw;
		sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
						cx->card_i2c->demod);
		sd = v4l2_i2c_new_probed_subdev(&cx->v4l2_dev,
				adap, mod, type, cx->card_i2c->demod);
		if (sd != NULL)
			sd->grp_id = hw;
		sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
						cx->card_i2c->tv);
		sd = v4l2_i2c_new_probed_subdev(&cx->v4l2_dev,
				adap, mod, type, cx->card_i2c->tv);
		if (sd != NULL)
			sd->grp_id = hw;
		return sd != NULL ? 0 : -1;
@@ -120,7 +120,7 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
		return -1;

	/* It's an I2C device other than an analog tuner */
	sd = v4l2_i2c_new_subdev(adap, mod, type, hw_addrs[idx]);
	sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, adap, mod, type, hw_addrs[idx]);
	if (sd != NULL)
		sd->grp_id = hw;
	return sd != NULL ? 0 : -1;
Loading