+static int rkcif_plat_probe(struct platform_device *pdev)
+{
+ const struct of_device_id *match;
+ struct device_node *node = pdev->dev.of_node;
+ struct device *dev = &pdev->dev;
+ struct v4l2_device *v4l2_dev;
+ struct rkcif_device *cif_dev;
+ const struct cif_match_data *data;
+ struct resource *res;
+ int i, ret, irq;
+
+ match = of_match_node(rkcif_plat_of_match, node);
+ if (IS_ERR(match))
+ return PTR_ERR(match);
+
+ cif_dev = devm_kzalloc(dev, sizeof(*cif_dev), GFP_KERNEL);
+ if (!cif_dev)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, cif_dev);
+ cif_dev->dev = dev;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ret = devm_request_irq(dev, irq, rkcif_irq_handler, IRQF_SHARED,
+ dev_driver_string(dev), dev);
+ if (ret < 0) {
+ dev_err(dev, "request irq failed: %d\n", ret);
+ return ret;
+ }
+
+ cif_dev->irq = irq;
+ data = match->data;
+ cif_dev->chip_id = data->chip_id;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ cif_dev->base_addr = devm_ioremap_resource(dev, res);
+
+ if (IS_ERR(cif_dev->base_addr))
+ return PTR_ERR(cif_dev->base_addr);
+
+ if (data->clks_num > RKCIF_MAX_BUS_CLK ||
+ data->rsts_num > RKCIF_MAX_RESET) {
+ dev_err(dev, "out of range: clks(%d %d) rsts(%d %d)\n",
+ data->clks_num, RKCIF_MAX_BUS_CLK,
+ data->rsts_num, RKCIF_MAX_RESET);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < data->clks_num; i++) {
+ struct clk *clk = devm_clk_get(dev, data->clks[i]);
+
+ if (IS_ERR(clk)) {
+ dev_err(dev, "failed to get %s\n", data->clks[i]);
+ return PTR_ERR(clk);
+ }
+
+ cif_dev->clks[i] = clk;
+ }
+
+ cif_dev->clk_size = data->clks_num;
+
+ for (i = 0; i < data->rsts_num; i++) {
+ struct reset_control *rst =
+ devm_reset_control_get(dev, data->rsts[i]);
+ if (IS_ERR(rst)) {
+ dev_err(dev, "failed to get %s\n", data->rsts[i]);
+ return PTR_ERR(rst);
+ }
+ cif_dev->cif_rst[i] = rst;
+ }
+
+ /* Initialize the stream */
+ rkcif_stream_init(cif_dev);
+
+ strlcpy(cif_dev->media_dev.model, "rkcif",
+ sizeof(cif_dev->media_dev.model));
+ cif_dev->media_dev.dev = &pdev->dev;
+ v4l2_dev = &cif_dev->v4l2_dev;
+ v4l2_dev->mdev = &cif_dev->media_dev;
+ strlcpy(v4l2_dev->name, "rkcif", sizeof(v4l2_dev->name));
+ v4l2_ctrl_handler_init(&cif_dev->ctrl_handler, 8);
+ v4l2_dev->ctrl_handler = &cif_dev->ctrl_handler;
+
+ ret = v4l2_device_register(cif_dev->dev, &cif_dev->v4l2_dev);
+ if (ret < 0)
+ return ret;
+
+ media_device_init(&cif_dev->media_dev);
+
+ ret = media_device_register(&cif_dev->media_dev);
+ if (ret < 0) {
+ v4l2_err(v4l2_dev, "Failed to register media device: %d\n",
+ ret);
+ goto err_unreg_v4l2_dev;
+ }
+
+ /* create & register platefom subdev (from of_node) */
+ ret = rkcif_register_platform_subdevs(cif_dev);
+ if (ret < 0)
+ goto err_unreg_media_dev;
+
+ ret = of_reserved_mem_device_init(dev);
+ if (ret)
+ v4l2_warn(v4l2_dev, "No reserved memory region assign to CIF\n");
+
+ pm_runtime_enable(&pdev->dev);
+
+ return 0;
+
+err_unreg_media_dev:
+ media_device_unregister(&cif_dev->media_dev);
+err_unreg_v4l2_dev:
+ v4l2_device_unregister(&cif_dev->v4l2_dev);
+ return ret;
+}