v4l2_async_notifier_register

/**
 * struct v4l2_async_notifier - v4l2_device notifier data
 *
 * @num_subdevs: number of subdevices
 * @subdevs:    array of pointers to subdevice descriptors
 * @v4l2_dev:    pointer to struct v4l2_device
 * @waiting:    list of struct v4l2_async_subdev, waiting for their drivers
 * @done:    list of struct v4l2_subdev, already probed
 * @list:    member in a global list of notifiers
 * @bound:    a subdevice driver has successfully probed one of subdevices
 * @complete:    all subdevices have been probed successfully
 * @unbind:    a subdevice is leaving
 */
struct v4l2_async_notifier {
    unsigned int num_subdevs;
    struct v4l2_async_subdev **subdevs;
    struct v4l2_device *v4l2_dev;
    struct list_head waiting;
    struct list_head done;
    struct list_head list;
    int (*bound)(struct v4l2_async_notifier *notifier,
             struct v4l2_subdev *subdev,
             struct v4l2_async_subdev *asd);
    int (*complete)(struct v4l2_async_notifier *notifier);
    void (*unbind)(struct v4l2_async_notifier *notifier,
               struct v4l2_subdev *subdev,
               struct v4l2_async_subdev *asd);
};

预先根据整体数据流经过的硬件(mipi sif isp...)通过dts填充 notifier->subdevs

int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
                 struct v4l2_async_notifier *notifier)
{
    struct v4l2_subdev *sd, *tmp;
    struct v4l2_async_subdev *asd;
    int i;

    if (!v4l2_dev || !notifier->num_subdevs ||
        notifier->num_subdevs > V4L2_MAX_SUBDEVS)
        return -EINVAL;

    notifier->v4l2_dev = v4l2_dev;
    INIT_LIST_HEAD(&notifier->waiting);
    INIT_LIST_HEAD(&notifier->done);

    for (i = 0; i < notifier->num_subdevs; i++) {
        asd = notifier->subdevs[i];

        switch (asd->match_type) {
        case V4L2_ASYNC_MATCH_CUSTOM:
        case V4L2_ASYNC_MATCH_DEVNAME:
        case V4L2_ASYNC_MATCH_I2C:
        case V4L2_ASYNC_MATCH_FWNODE:
            break;
        default:
            dev_err(notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL,
                "Invalid match type %u on %p\n",
                asd->match_type, asd);
            return -EINVAL;
        }
        list_add_tail(&asd->list, &notifier->waiting); // 重点看这里把所有的subdevs放入waiting
    }

    mutex_lock(&list_lock);

    list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
        int ret;

        asd = v4l2_async_belongs(notifier, sd);
        if (!asd)
            continue;

        ret = v4l2_async_test_notify(notifier, sd, asd);
        if (ret < 0) {
            mutex_unlock(&list_lock);
            return ret;
        }
    }

    /* Keep also completed notifiers on the list */
    list_add(&notifier->list, &notifier_list);

    mutex_unlock(&list_lock);

    return 0;
}

static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
                  struct v4l2_subdev *sd,
                  struct v4l2_async_subdev *asd)
{
    int ret;

    if (notifier->bound) {
        ret = notifier->bound(notifier, sd, asd);
        if (ret < 0)
            return ret;
    }

    ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
    if (ret < 0) {
        if (notifier->unbind)
            notifier->unbind(notifier, sd, asd);
        return ret;
    }

    /* Remove from the waiting list */
    list_del(&asd->list);
    sd->asd = asd;
    sd->notifier = notifier;

    /* Move from the global subdevice list to notifier's done */
    list_move(&sd->async_list, &notifier->done);

    if (list_empty(&notifier->waiting) && notifier->complete) //重点看这里,当所有的subdevs都被真正的v4l2_subdev,v4l2_async_register_subdev后调用notifier的complete
        return notifier->complete(notifier);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值