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

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

[media] cec: pass parent device in register(), not allocate()



The cec_allocate_adapter function doesn't need the parent device, only the
cec_register_adapter function needs it.

Drop the cec_devnode parent field, since devnode.dev.parent can be used
instead.

This change makes the framework consistent with other frameworks where the
parent device is not used until the device is registered.

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent cf2113ca
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -37,9 +37,8 @@ The struct cec_adapter represents the CEC adapter hardware. It is created by
calling cec_allocate_adapter() and deleted by calling cec_delete_adapter():

.. c:function::
   struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
	       void *priv, const char *name, u32 caps, u8 available_las,
	       struct device *parent);
   struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, void *priv,
   const char *name, u32 caps, u8 available_las);

.. c:function::
   void cec_delete_adapter(struct cec_adapter *adap);
@@ -66,20 +65,19 @@ available_las:
	the number of simultaneous logical addresses that this
	adapter can handle. Must be 1 <= available_las <= CEC_MAX_LOG_ADDRS.

parent:
	the parent device.


To register the /dev/cecX device node and the remote control device (if
CEC_CAP_RC is set) you call:

.. c:function::
	int cec_register_adapter(struct cec_adapter \*adap);
	int cec_register_adapter(struct cec_adapter *adap, struct device *parent);

where parent is the parent device.

To unregister the devices call:

.. c:function::
	void cec_unregister_adapter(struct cec_adapter \*adap);
	void cec_unregister_adapter(struct cec_adapter *adap);

Note: if cec_register_adapter() fails, then call cec_delete_adapter() to
clean up. But if cec_register_adapter() succeeded, then only call
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ static long cec_adap_g_caps(struct cec_adapter *adap,
{
	struct cec_caps caps = {};

	strlcpy(caps.driver, adap->devnode.parent->driver->name,
	strlcpy(caps.driver, adap->devnode.dev.parent->driver->name,
		sizeof(caps.driver));
	strlcpy(caps.name, adap->name, sizeof(caps.name));
	caps.available_log_addrs = adap->available_log_addrs;
+10 −8
Original line number Diff line number Diff line
@@ -132,7 +132,6 @@ static int __must_check cec_devnode_register(struct cec_devnode *devnode,
	devnode->dev.bus = &cec_bus_type;
	devnode->dev.devt = MKDEV(MAJOR(cec_dev_t), minor);
	devnode->dev.release = cec_devnode_release;
	devnode->dev.parent = devnode->parent;
	dev_set_name(&devnode->dev, "cec%d", devnode->minor);
	device_initialize(&devnode->dev);

@@ -198,13 +197,11 @@ static void cec_devnode_unregister(struct cec_devnode *devnode)

struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
					 void *priv, const char *name, u32 caps,
					 u8 available_las, struct device *parent)
					 u8 available_las)
{
	struct cec_adapter *adap;
	int res;

	if (WARN_ON(!parent))
		return ERR_PTR(-EINVAL);
	if (WARN_ON(!caps))
		return ERR_PTR(-EINVAL);
	if (WARN_ON(!ops))
@@ -214,8 +211,6 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
	adap = kzalloc(sizeof(*adap), GFP_KERNEL);
	if (!adap)
		return ERR_PTR(-ENOMEM);
	adap->owner = parent->driver->owner;
	adap->devnode.parent = parent;
	strlcpy(adap->name, name, sizeof(adap->name));
	adap->phys_addr = CEC_PHYS_ADDR_INVALID;
	adap->log_addrs.cec_version = CEC_OP_CEC_VERSION_2_0;
@@ -264,7 +259,6 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
	adap->rc->input_id.vendor = 0;
	adap->rc->input_id.product = 0;
	adap->rc->input_id.version = 1;
	adap->rc->dev.parent = parent;
	adap->rc->driver_type = RC_DRIVER_SCANCODE;
	adap->rc->driver_name = CEC_NAME;
	adap->rc->allowed_protocols = RC_BIT_CEC;
@@ -278,14 +272,22 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
}
EXPORT_SYMBOL_GPL(cec_allocate_adapter);

int cec_register_adapter(struct cec_adapter *adap)
int cec_register_adapter(struct cec_adapter *adap,
			 struct device *parent)
{
	int res;

	if (IS_ERR_OR_NULL(adap))
		return 0;

	if (WARN_ON(!parent))
		return -EINVAL;

	adap->owner = parent->driver->owner;
	adap->devnode.dev.parent = parent;

#if IS_REACHABLE(CONFIG_RC_CORE)
	adap->rc->dev.parent = parent;
	if (adap->capabilities & CEC_CAP_RC) {
		res = rc_register_device(adap->rc);

+3 −2
Original line number Diff line number Diff line
@@ -1732,9 +1732,10 @@ static bool adv7511_check_edid_status(struct v4l2_subdev *sd)
static int adv7511_registered(struct v4l2_subdev *sd)
{
	struct adv7511_state *state = get_adv7511_state(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	int err;

	err = cec_register_adapter(state->cec_adap);
	err = cec_register_adapter(state->cec_adap, &client->dev);
	if (err)
		cec_delete_adapter(state->cec_adap);
	return err;
@@ -1928,7 +1929,7 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
	state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops,
		state, dev_name(&client->dev), CEC_CAP_TRANSMIT |
		CEC_CAP_LOG_ADDRS | CEC_CAP_PASSTHROUGH | CEC_CAP_RC,
		ADV7511_MAX_ADDRS, &client->dev);
		ADV7511_MAX_ADDRS);
	err = PTR_ERR_OR_ZERO(state->cec_adap);
	if (err) {
		destroy_workqueue(state->work_queue);
+3 −3
Original line number Diff line number Diff line
@@ -2631,9 +2631,10 @@ static int adv76xx_subscribe_event(struct v4l2_subdev *sd,
static int adv76xx_registered(struct v4l2_subdev *sd)
{
	struct adv76xx_state *state = to_state(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	int err;

	err = cec_register_adapter(state->cec_adap);
	err = cec_register_adapter(state->cec_adap, &client->dev);
	if (err)
		cec_delete_adapter(state->cec_adap);
	return err;
@@ -3511,8 +3512,7 @@ static int adv76xx_probe(struct i2c_client *client,
	state->cec_adap = cec_allocate_adapter(&adv76xx_cec_adap_ops,
		state, dev_name(&client->dev),
		CEC_CAP_TRANSMIT | CEC_CAP_LOG_ADDRS |
		CEC_CAP_PASSTHROUGH | CEC_CAP_RC, ADV76XX_MAX_ADDRS,
		&client->dev);
		CEC_CAP_PASSTHROUGH | CEC_CAP_RC, ADV76XX_MAX_ADDRS);
	err = PTR_ERR_OR_ZERO(state->cec_adap);
	if (err)
		goto err_entity;
Loading