KVM: SVM: Rename vmplX_ssp -> plX_ssp
[linux-2.6-block.git] / drivers / media / platform / rockchip / rkisp1 / rkisp1-dev.c
1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2 /*
3  * Rockchip ISP1 Driver - Base driver
4  *
5  * Copyright (C) 2019 Collabora, Ltd.
6  *
7  * Based on Rockchip ISP1 driver by Rockchip Electronics Co., Ltd.
8  * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
9  */
10
11 #include <linux/clk.h>
12 #include <linux/interrupt.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/of_graph.h>
16 #include <linux/platform_device.h>
17 #include <linux/pinctrl/consumer.h>
18 #include <linux/pm_runtime.h>
19 #include <media/v4l2-fwnode.h>
20 #include <media/v4l2-mc.h>
21
22 #include "rkisp1-common.h"
23 #include "rkisp1-csi.h"
24
25 /*
26  * ISP Details
27  * -----------
28  *
29  * ISP Comprises with:
30  *      MIPI serial camera interface
31  *      Image Signal Processing
32  *      Many Image Enhancement Blocks
33  *      Crop
34  *      Resizer
35  *      RBG display ready image
36  *      Image Rotation
37  *
38  * ISP Block Diagram
39  * -----------------
40  *                                                             rkisp1-resizer.c          rkisp1-capture.c
41  *                                                          |====================|  |=======================|
42  *                                rkisp1-isp.c                              Main Picture Path
43  *                        |==========================|      |===============================================|
44  *                        +-----------+  +--+--+--+--+      +--------+  +--------+              +-----------+
45  *                        |           |  |  |  |  |  |      |        |  |        |              |           |
46  * +--------+    |\       |           |  |  |  |  |  |   -->|  Crop  |->|  RSZ   |------------->|           |
47  * |  MIPI  |--->|  \     |           |  |  |  |  |  |   |  |        |  |        |              |           |
48  * +--------+    |   |    |           |  |IE|IE|IE|IE|   |  +--------+  +--------+              |  Memory   |
49  *               |MUX|--->|    ISP    |->|0 |1 |2 |3 |---+                                      | Interface |
50  * +--------+    |   |    |           |  |  |  |  |  |   |  +--------+  +--------+  +--------+  |           |
51  * |Parallel|--->|  /     |           |  |  |  |  |  |   |  |        |  |        |  |        |  |           |
52  * +--------+    |/       |           |  |  |  |  |  |   -->|  Crop  |->|  RSZ   |->|  RGB   |->|           |
53  *                        |           |  |  |  |  |  |      |        |  |        |  | Rotate |  |           |
54  *                        +-----------+  +--+--+--+--+      +--------+  +--------+  +--------+  +-----------+
55  *                                               ^
56  * +--------+                                    |          |===============================================|
57  * |  DMA   |------------------------------------+                          Self Picture Path
58  * +--------+
59  *
60  *         rkisp1-stats.c        rkisp1-params.c
61  *       |===============|      |===============|
62  *       +---------------+      +---------------+
63  *       |               |      |               |
64  *       |      ISP      |      |      ISP      |
65  *       |               |      |               |
66  *       +---------------+      +---------------+
67  *
68  *
69  * Media Topology
70  * --------------
71  *
72  *          +----------+       +----------+
73  *          | Sensor 1 |       | Sensor X |
74  *          ------------  ...  ------------
75  *          |    0     |       |    0     |
76  *          +----------+       +----------+
77  *               |                  |
78  *                \----\       /----/
79  *                     |       |
80  *                     v       v
81  *                  +-------------+
82  *                  |      0      |
83  *                  ---------------
84  *                  |  CSI-2 RX   |
85  *                  ---------------         +-----------+
86  *                  |      1      |         |  params   |
87  *                  +-------------+         | (output)  |
88  *                         |               +-----------+
89  *                         v                     |
90  *                      +------+------+          |
91  *                      |  0   |  1   |<---------+
92  *                      |------+------|
93  *                      |     ISP     |
94  *                      |------+------|
95  *        +-------------|  2   |  3   |----------+
96  *        |             +------+------+          |
97  *        |                |                     |
98  *        v                v                     v
99  *  +- ---------+    +-----------+         +-----------+
100  *  |     0     |    |     0     |         |   stats   |
101  *  -------------    -------------         | (capture) |
102  *  |  Resizer  |    |  Resizer  |         +-----------+
103  *  ------------|    ------------|
104  *  |     1     |    |     1     |
105  *  +-----------+    +-----------+
106  *        |                |
107  *        v                v
108  *  +-----------+    +-----------+
109  *  | selfpath  |    | mainpath  |
110  *  | (capture) |    | (capture) |
111  *  +-----------+    +-----------+
112  */
113
114 struct rkisp1_isr_data {
115         const char *name;
116         irqreturn_t (*isr)(int irq, void *ctx);
117         u32 line_mask;
118 };
119
120 /* ----------------------------------------------------------------------------
121  * Sensor DT bindings
122  */
123
124 static int rkisp1_subdev_notifier_bound(struct v4l2_async_notifier *notifier,
125                                         struct v4l2_subdev *sd,
126                                         struct v4l2_async_connection *asc)
127 {
128         struct rkisp1_device *rkisp1 =
129                 container_of(notifier, struct rkisp1_device, notifier);
130         struct rkisp1_sensor_async *s_asd =
131                 container_of(asc, struct rkisp1_sensor_async, asd);
132         int source_pad;
133         int ret;
134
135         s_asd->sd = sd;
136
137         source_pad = media_entity_get_fwnode_pad(&sd->entity, s_asd->source_ep,
138                                                  MEDIA_PAD_FL_SOURCE);
139         if (source_pad < 0) {
140                 dev_err(rkisp1->dev, "failed to find source pad for %s\n",
141                         sd->name);
142                 return source_pad;
143         }
144
145         if (s_asd->port == 0)
146                 return rkisp1_csi_link_sensor(rkisp1, sd, s_asd, source_pad);
147
148         ret = media_create_pad_link(&sd->entity, source_pad,
149                                     &rkisp1->isp.sd.entity,
150                                     RKISP1_ISP_PAD_SINK_VIDEO,
151                                     !s_asd->index ? MEDIA_LNK_FL_ENABLED : 0);
152         if (ret) {
153                 dev_err(rkisp1->dev, "failed to link source pad of %s\n",
154                         sd->name);
155                 return ret;
156         }
157
158         return 0;
159 }
160
161 static int rkisp1_subdev_notifier_complete(struct v4l2_async_notifier *notifier)
162 {
163         struct rkisp1_device *rkisp1 =
164                 container_of(notifier, struct rkisp1_device, notifier);
165
166         return v4l2_device_register_subdev_nodes(&rkisp1->v4l2_dev);
167 }
168
169 static void rkisp1_subdev_notifier_destroy(struct v4l2_async_connection *asc)
170 {
171         struct rkisp1_sensor_async *rk_asd =
172                 container_of(asc, struct rkisp1_sensor_async, asd);
173
174         fwnode_handle_put(rk_asd->source_ep);
175 }
176
177 static const struct v4l2_async_notifier_operations rkisp1_subdev_notifier_ops = {
178         .bound = rkisp1_subdev_notifier_bound,
179         .complete = rkisp1_subdev_notifier_complete,
180         .destroy = rkisp1_subdev_notifier_destroy,
181 };
182
183 static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
184 {
185         struct v4l2_async_notifier *ntf = &rkisp1->notifier;
186         struct fwnode_handle *fwnode = dev_fwnode(rkisp1->dev);
187         struct fwnode_handle *ep;
188         unsigned int index = 0;
189         int ret = 0;
190
191         v4l2_async_nf_init(ntf, &rkisp1->v4l2_dev);
192
193         ntf->ops = &rkisp1_subdev_notifier_ops;
194
195         fwnode_graph_for_each_endpoint(fwnode, ep) {
196                 struct fwnode_handle *port;
197                 struct v4l2_fwnode_endpoint vep = { };
198                 struct rkisp1_sensor_async *rk_asd;
199                 struct fwnode_handle *source;
200                 u32 reg = 0;
201
202                 /* Select the bus type based on the port. */
203                 port = fwnode_get_parent(ep);
204                 fwnode_property_read_u32(port, "reg", &reg);
205                 fwnode_handle_put(port);
206
207                 switch (reg) {
208                 case 0:
209                         /* MIPI CSI-2 port */
210                         if (!(rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)) {
211                                 dev_err(rkisp1->dev,
212                                         "internal CSI must be available for port 0\n");
213                                 ret = -EINVAL;
214                                 break;
215                         }
216
217                         vep.bus_type = V4L2_MBUS_CSI2_DPHY;
218                         break;
219
220                 case 1:
221                         /*
222                          * Parallel port. The bus-type property in DT is
223                          * mandatory for port 1, it will be used to determine if
224                          * it's PARALLEL or BT656.
225                          */
226                         vep.bus_type = V4L2_MBUS_UNKNOWN;
227                         break;
228                 }
229
230                 /* Parse the endpoint and validate the bus type. */
231                 ret = v4l2_fwnode_endpoint_parse(ep, &vep);
232                 if (ret) {
233                         dev_err(rkisp1->dev, "failed to parse endpoint %pfw\n",
234                                 ep);
235                         break;
236                 }
237
238                 if (vep.base.port == 1) {
239                         if (vep.bus_type != V4L2_MBUS_PARALLEL &&
240                             vep.bus_type != V4L2_MBUS_BT656) {
241                                 dev_err(rkisp1->dev,
242                                         "port 1 must be parallel or BT656\n");
243                                 ret = -EINVAL;
244                                 break;
245                         }
246                 }
247
248                 /* Add the async subdev to the notifier. */
249                 source = fwnode_graph_get_remote_endpoint(ep);
250                 if (!source) {
251                         dev_err(rkisp1->dev,
252                                 "endpoint %pfw has no remote endpoint\n",
253                                 ep);
254                         ret = -ENODEV;
255                         break;
256                 }
257
258                 rk_asd = v4l2_async_nf_add_fwnode(ntf, source,
259                                                   struct rkisp1_sensor_async);
260                 if (IS_ERR(rk_asd)) {
261                         fwnode_handle_put(source);
262                         ret = PTR_ERR(rk_asd);
263                         break;
264                 }
265
266                 rk_asd->index = index++;
267                 rk_asd->source_ep = source;
268                 rk_asd->mbus_type = vep.bus_type;
269                 rk_asd->port = vep.base.port;
270
271                 if (vep.bus_type == V4L2_MBUS_CSI2_DPHY) {
272                         rk_asd->mbus_flags = vep.bus.mipi_csi2.flags;
273                         rk_asd->lanes = vep.bus.mipi_csi2.num_data_lanes;
274                 } else {
275                         rk_asd->mbus_flags = vep.bus.parallel.flags;
276                 }
277
278                 dev_dbg(rkisp1->dev, "registered ep id %d, bus type %u, %u lanes\n",
279                         vep.base.id, rk_asd->mbus_type, rk_asd->lanes);
280         }
281
282         if (ret) {
283                 fwnode_handle_put(ep);
284                 v4l2_async_nf_cleanup(ntf);
285                 return ret;
286         }
287
288         if (!index)
289                 dev_dbg(rkisp1->dev, "no remote subdevice found\n");
290
291         ret = v4l2_async_nf_register(ntf);
292         if (ret) {
293                 v4l2_async_nf_cleanup(ntf);
294                 return ret;
295         }
296
297         return 0;
298 }
299
300 /* ----------------------------------------------------------------------------
301  * Power
302  */
303
304 static int __maybe_unused rkisp1_runtime_suspend(struct device *dev)
305 {
306         struct rkisp1_device *rkisp1 = dev_get_drvdata(dev);
307
308         clk_bulk_disable_unprepare(rkisp1->clk_size, rkisp1->clks);
309         return pinctrl_pm_select_sleep_state(dev);
310 }
311
312 static int __maybe_unused rkisp1_runtime_resume(struct device *dev)
313 {
314         struct rkisp1_device *rkisp1 = dev_get_drvdata(dev);
315         int ret;
316
317         ret = pinctrl_pm_select_default_state(dev);
318         if (ret)
319                 return ret;
320         ret = clk_bulk_prepare_enable(rkisp1->clk_size, rkisp1->clks);
321         if (ret)
322                 return ret;
323
324         return 0;
325 }
326
327 static const struct dev_pm_ops rkisp1_pm_ops = {
328         SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
329                                 pm_runtime_force_resume)
330         SET_RUNTIME_PM_OPS(rkisp1_runtime_suspend, rkisp1_runtime_resume, NULL)
331 };
332
333 /* ----------------------------------------------------------------------------
334  * Core
335  */
336
337 static int rkisp1_create_links(struct rkisp1_device *rkisp1)
338 {
339         unsigned int i;
340         int ret;
341
342         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
343                 /* Link the CSI receiver to the ISP. */
344                 ret = media_create_pad_link(&rkisp1->csi.sd.entity,
345                                             RKISP1_CSI_PAD_SRC,
346                                             &rkisp1->isp.sd.entity,
347                                             RKISP1_ISP_PAD_SINK_VIDEO,
348                                             MEDIA_LNK_FL_ENABLED);
349                 if (ret)
350                         return ret;
351         }
352
353         /* create ISP->RSZ->CAP links */
354         for (i = 0; i < 2; i++) {
355                 struct media_entity *resizer =
356                         &rkisp1->resizer_devs[i].sd.entity;
357                 struct media_entity *capture =
358                         &rkisp1->capture_devs[i].vnode.vdev.entity;
359
360                 ret = media_create_pad_link(&rkisp1->isp.sd.entity,
361                                             RKISP1_ISP_PAD_SOURCE_VIDEO,
362                                             resizer, RKISP1_RSZ_PAD_SINK,
363                                             MEDIA_LNK_FL_ENABLED);
364                 if (ret)
365                         return ret;
366
367                 ret = media_create_pad_link(resizer, RKISP1_RSZ_PAD_SRC,
368                                             capture, 0,
369                                             MEDIA_LNK_FL_ENABLED |
370                                             MEDIA_LNK_FL_IMMUTABLE);
371                 if (ret)
372                         return ret;
373         }
374
375         /* params links */
376         ret = media_create_pad_link(&rkisp1->params.vnode.vdev.entity, 0,
377                                     &rkisp1->isp.sd.entity,
378                                     RKISP1_ISP_PAD_SINK_PARAMS,
379                                     MEDIA_LNK_FL_ENABLED |
380                                     MEDIA_LNK_FL_IMMUTABLE);
381         if (ret)
382                 return ret;
383
384         /* 3A stats links */
385         return media_create_pad_link(&rkisp1->isp.sd.entity,
386                                      RKISP1_ISP_PAD_SOURCE_STATS,
387                                      &rkisp1->stats.vnode.vdev.entity, 0,
388                                      MEDIA_LNK_FL_ENABLED |
389                                      MEDIA_LNK_FL_IMMUTABLE);
390 }
391
392 static void rkisp1_entities_unregister(struct rkisp1_device *rkisp1)
393 {
394         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
395                 rkisp1_csi_unregister(rkisp1);
396         rkisp1_params_unregister(rkisp1);
397         rkisp1_stats_unregister(rkisp1);
398         rkisp1_capture_devs_unregister(rkisp1);
399         rkisp1_resizer_devs_unregister(rkisp1);
400         rkisp1_isp_unregister(rkisp1);
401 }
402
403 static int rkisp1_entities_register(struct rkisp1_device *rkisp1)
404 {
405         int ret;
406
407         ret = rkisp1_isp_register(rkisp1);
408         if (ret)
409                 goto error;
410
411         ret = rkisp1_resizer_devs_register(rkisp1);
412         if (ret)
413                 goto error;
414
415         ret = rkisp1_capture_devs_register(rkisp1);
416         if (ret)
417                 goto error;
418
419         ret = rkisp1_stats_register(rkisp1);
420         if (ret)
421                 goto error;
422
423         ret = rkisp1_params_register(rkisp1);
424         if (ret)
425                 goto error;
426
427         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
428                 ret = rkisp1_csi_register(rkisp1);
429                 if (ret)
430                         goto error;
431         }
432
433         ret = rkisp1_create_links(rkisp1);
434         if (ret)
435                 goto error;
436
437         return 0;
438
439 error:
440         rkisp1_entities_unregister(rkisp1);
441         return ret;
442 }
443
444 static irqreturn_t rkisp1_isr(int irq, void *ctx)
445 {
446         irqreturn_t ret = IRQ_NONE;
447
448         /*
449          * Call rkisp1_capture_isr() first to handle the frame that
450          * potentially completed using the current frame_sequence number before
451          * it is potentially incremented by rkisp1_isp_isr() in the vertical
452          * sync.
453          */
454
455         if (rkisp1_capture_isr(irq, ctx) == IRQ_HANDLED)
456                 ret = IRQ_HANDLED;
457
458         if (rkisp1_isp_isr(irq, ctx) == IRQ_HANDLED)
459                 ret = IRQ_HANDLED;
460
461         if (rkisp1_csi_isr(irq, ctx) == IRQ_HANDLED)
462                 ret = IRQ_HANDLED;
463
464         return ret;
465 }
466
467 static const char * const px30_isp_clks[] = {
468         "isp",
469         "aclk",
470         "hclk",
471         "pclk",
472 };
473
474 static const struct rkisp1_isr_data px30_isp_isrs[] = {
475         { "isp", rkisp1_isp_isr, BIT(RKISP1_IRQ_ISP) },
476         { "mi", rkisp1_capture_isr, BIT(RKISP1_IRQ_MI) },
477         { "mipi", rkisp1_csi_isr, BIT(RKISP1_IRQ_MIPI) },
478 };
479
480 static const struct rkisp1_info px30_isp_info = {
481         .clks = px30_isp_clks,
482         .clk_size = ARRAY_SIZE(px30_isp_clks),
483         .isrs = px30_isp_isrs,
484         .isr_size = ARRAY_SIZE(px30_isp_isrs),
485         .isp_ver = RKISP1_V12,
486         .features = RKISP1_FEATURE_MIPI_CSI2,
487 };
488
489 static const char * const rk3399_isp_clks[] = {
490         "isp",
491         "aclk",
492         "hclk",
493 };
494
495 static const struct rkisp1_isr_data rk3399_isp_isrs[] = {
496         { NULL, rkisp1_isr, BIT(RKISP1_IRQ_ISP) | BIT(RKISP1_IRQ_MI) | BIT(RKISP1_IRQ_MIPI) },
497 };
498
499 static const struct rkisp1_info rk3399_isp_info = {
500         .clks = rk3399_isp_clks,
501         .clk_size = ARRAY_SIZE(rk3399_isp_clks),
502         .isrs = rk3399_isp_isrs,
503         .isr_size = ARRAY_SIZE(rk3399_isp_isrs),
504         .isp_ver = RKISP1_V10,
505         .features = RKISP1_FEATURE_MIPI_CSI2,
506 };
507
508 static const struct of_device_id rkisp1_of_match[] = {
509         {
510                 .compatible = "rockchip,px30-cif-isp",
511                 .data = &px30_isp_info,
512         },
513         {
514                 .compatible = "rockchip,rk3399-cif-isp",
515                 .data = &rk3399_isp_info,
516         },
517         {},
518 };
519 MODULE_DEVICE_TABLE(of, rkisp1_of_match);
520
521 static int rkisp1_probe(struct platform_device *pdev)
522 {
523         const struct rkisp1_info *info;
524         struct device *dev = &pdev->dev;
525         struct rkisp1_device *rkisp1;
526         struct v4l2_device *v4l2_dev;
527         unsigned int i;
528         int ret, irq;
529         u32 cif_id;
530
531         rkisp1 = devm_kzalloc(dev, sizeof(*rkisp1), GFP_KERNEL);
532         if (!rkisp1)
533                 return -ENOMEM;
534
535         info = of_device_get_match_data(dev);
536         rkisp1->info = info;
537
538         dev_set_drvdata(dev, rkisp1);
539         rkisp1->dev = dev;
540
541         mutex_init(&rkisp1->stream_lock);
542
543         rkisp1->base_addr = devm_platform_ioremap_resource(pdev, 0);
544         if (IS_ERR(rkisp1->base_addr))
545                 return PTR_ERR(rkisp1->base_addr);
546
547         for (unsigned int il = 0; il < ARRAY_SIZE(rkisp1->irqs); ++il)
548                 rkisp1->irqs[il] = -1;
549
550         for (i = 0; i < info->isr_size; i++) {
551                 irq = info->isrs[i].name
552                     ? platform_get_irq_byname(pdev, info->isrs[i].name)
553                     : platform_get_irq(pdev, i);
554                 if (irq < 0)
555                         return irq;
556
557                 for (unsigned int il = 0; il < ARRAY_SIZE(rkisp1->irqs); ++il) {
558                         if (info->isrs[i].line_mask & BIT(il))
559                                 rkisp1->irqs[il] = irq;
560                 }
561
562                 ret = devm_request_irq(dev, irq, info->isrs[i].isr, 0,
563                                        dev_driver_string(dev), dev);
564                 if (ret) {
565                         dev_err(dev, "request irq failed: %d\n", ret);
566                         return ret;
567                 }
568         }
569
570         for (i = 0; i < info->clk_size; i++)
571                 rkisp1->clks[i].id = info->clks[i];
572         ret = devm_clk_bulk_get(dev, info->clk_size, rkisp1->clks);
573         if (ret)
574                 return ret;
575         rkisp1->clk_size = info->clk_size;
576
577         pm_runtime_enable(&pdev->dev);
578
579         ret = pm_runtime_resume_and_get(&pdev->dev);
580         if (ret)
581                 goto err_pm_runtime_disable;
582
583         cif_id = rkisp1_read(rkisp1, RKISP1_CIF_VI_ID);
584         dev_dbg(rkisp1->dev, "CIF_ID 0x%08x\n", cif_id);
585
586         pm_runtime_put(&pdev->dev);
587
588         rkisp1->media_dev.hw_revision = info->isp_ver;
589         strscpy(rkisp1->media_dev.model, RKISP1_DRIVER_NAME,
590                 sizeof(rkisp1->media_dev.model));
591         rkisp1->media_dev.dev = &pdev->dev;
592         strscpy(rkisp1->media_dev.bus_info, RKISP1_BUS_INFO,
593                 sizeof(rkisp1->media_dev.bus_info));
594         media_device_init(&rkisp1->media_dev);
595
596         v4l2_dev = &rkisp1->v4l2_dev;
597         v4l2_dev->mdev = &rkisp1->media_dev;
598         strscpy(v4l2_dev->name, RKISP1_DRIVER_NAME, sizeof(v4l2_dev->name));
599
600         ret = v4l2_device_register(rkisp1->dev, &rkisp1->v4l2_dev);
601         if (ret)
602                 goto err_media_dev_cleanup;
603
604         ret = media_device_register(&rkisp1->media_dev);
605         if (ret) {
606                 dev_err(dev, "Failed to register media device: %d\n", ret);
607                 goto err_unreg_v4l2_dev;
608         }
609
610         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
611                 ret = rkisp1_csi_init(rkisp1);
612                 if (ret)
613                         goto err_unreg_media_dev;
614         }
615
616         ret = rkisp1_entities_register(rkisp1);
617         if (ret)
618                 goto err_cleanup_csi;
619
620         ret = rkisp1_subdev_notifier_register(rkisp1);
621         if (ret)
622                 goto err_unreg_entities;
623
624         rkisp1_debug_init(rkisp1);
625
626         return 0;
627
628 err_unreg_entities:
629         rkisp1_entities_unregister(rkisp1);
630 err_cleanup_csi:
631         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
632                 rkisp1_csi_cleanup(rkisp1);
633 err_unreg_media_dev:
634         media_device_unregister(&rkisp1->media_dev);
635 err_unreg_v4l2_dev:
636         v4l2_device_unregister(&rkisp1->v4l2_dev);
637 err_media_dev_cleanup:
638         media_device_cleanup(&rkisp1->media_dev);
639 err_pm_runtime_disable:
640         pm_runtime_disable(&pdev->dev);
641         return ret;
642 }
643
644 static void rkisp1_remove(struct platform_device *pdev)
645 {
646         struct rkisp1_device *rkisp1 = platform_get_drvdata(pdev);
647
648         v4l2_async_nf_unregister(&rkisp1->notifier);
649         v4l2_async_nf_cleanup(&rkisp1->notifier);
650
651         rkisp1_entities_unregister(rkisp1);
652         if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
653                 rkisp1_csi_cleanup(rkisp1);
654         rkisp1_debug_cleanup(rkisp1);
655
656         media_device_unregister(&rkisp1->media_dev);
657         v4l2_device_unregister(&rkisp1->v4l2_dev);
658
659         media_device_cleanup(&rkisp1->media_dev);
660
661         pm_runtime_disable(&pdev->dev);
662 }
663
664 static struct platform_driver rkisp1_drv = {
665         .driver = {
666                 .name = RKISP1_DRIVER_NAME,
667                 .of_match_table = of_match_ptr(rkisp1_of_match),
668                 .pm = &rkisp1_pm_ops,
669         },
670         .probe = rkisp1_probe,
671         .remove_new = rkisp1_remove,
672 };
673
674 module_platform_driver(rkisp1_drv);
675 MODULE_DESCRIPTION("Rockchip ISP1 platform driver");
676 MODULE_LICENSE("Dual MIT/GPL");