1 // SPDX-License-Identifier: GPL-2.0-only
3 * Microchip CSI2 Demux Controller (CSI2DC) driver
5 * Copyright (C) 2018 Microchip Technology, Inc.
7 * Author: Eugen Hristev <eugen.hristev@microchip.com>
11 #include <linux/clk.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/module.h>
14 #include <linux/of_graph.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/videodev2.h>
19 #include <media/v4l2-fwnode.h>
20 #include <media/v4l2-subdev.h>
22 /* Global configuration register */
23 #define CSI2DC_GCFG 0x0
25 /* MIPI sensor pixel clock is free running */
26 #define CSI2DC_GCFG_MIPIFRN BIT(0)
27 /* GPIO parallel interface selection */
28 #define CSI2DC_GCFG_GPIOSEL BIT(1)
29 /* Output waveform inter-line minimum delay */
30 #define CSI2DC_GCFG_HLC(v) ((v) << 4)
31 #define CSI2DC_GCFG_HLC_MASK GENMASK(7, 4)
32 /* SAMA7G5 requires a HLC delay of 15 */
33 #define SAMA7G5_HLC (15)
35 /* Global control register */
36 #define CSI2DC_GCTLR 0x04
37 #define CSI2DC_GCTLR_SWRST BIT(0)
39 /* Global status register */
40 #define CSI2DC_GS 0x08
42 /* SSP interrupt status register */
43 #define CSI2DC_SSPIS 0x28
44 /* Pipe update register */
45 #define CSI2DC_PU 0xc0
46 /* Video pipe attributes update */
47 #define CSI2DC_PU_VP BIT(0)
49 /* Pipe update status register */
50 #define CSI2DC_PUS 0xc4
52 /* Video pipeline Interrupt Status Register */
53 #define CSI2DC_VPISR 0xf4
55 /* Video pipeline enable register */
56 #define CSI2DC_VPE 0xf8
57 #define CSI2DC_VPE_ENABLE BIT(0)
59 /* Video pipeline configuration register */
60 #define CSI2DC_VPCFG 0xfc
62 #define CSI2DC_VPCFG_DT(v) ((v) << 0)
63 #define CSI2DC_VPCFG_DT_MASK GENMASK(5, 0)
64 /* Virtual channel identifier */
65 #define CSI2DC_VPCFG_VC(v) ((v) << 6)
66 #define CSI2DC_VPCFG_VC_MASK GENMASK(7, 6)
67 /* Decompression enable */
68 #define CSI2DC_VPCFG_DE BIT(8)
70 #define CSI2DC_VPCFG_DM(v) ((v) << 9)
71 #define CSI2DC_VPCFG_DM_DECODER8TO12 0
72 /* Decoder predictor 2 selection */
73 #define CSI2DC_VPCFG_DP2 BIT(12)
74 /* Recommended memory storage */
75 #define CSI2DC_VPCFG_RMS BIT(13)
77 #define CSI2DC_VPCFG_PA BIT(14)
79 /* Video pipeline column register */
80 #define CSI2DC_VPCOL 0x100
82 #define CSI2DC_VPCOL_COL(v) ((v) << 0)
83 #define CSI2DC_VPCOL_COL_MASK GENMASK(15, 0)
85 /* Video pipeline row register */
86 #define CSI2DC_VPROW 0x104
88 #define CSI2DC_VPROW_ROW(v) ((v) << 0)
89 #define CSI2DC_VPROW_ROW_MASK GENMASK(15, 0)
91 /* Version register */
92 #define CSI2DC_VERSION 0x1fc
94 /* register read/write helpers */
95 #define csi2dc_readl(st, reg) readl_relaxed((st)->base + (reg))
96 #define csi2dc_writel(st, reg, val) writel_relaxed((val), \
99 /* supported RAW data types */
100 #define CSI2DC_DT_RAW6 0x28
101 #define CSI2DC_DT_RAW7 0x29
102 #define CSI2DC_DT_RAW8 0x2a
103 #define CSI2DC_DT_RAW10 0x2b
104 #define CSI2DC_DT_RAW12 0x2c
105 #define CSI2DC_DT_RAW14 0x2d
107 #define CSI2DC_DT_YUV422_8B 0x1e
110 * struct csi2dc_format - CSI2DC format type struct
111 * @mbus_code: Media bus code for the format
112 * @dt: Data type constant for this format
114 struct csi2dc_format
{
119 static const struct csi2dc_format csi2dc_formats
[] = {
121 .mbus_code
= MEDIA_BUS_FMT_SRGGB8_1X8
,
122 .dt
= CSI2DC_DT_RAW8
,
124 .mbus_code
= MEDIA_BUS_FMT_SBGGR8_1X8
,
125 .dt
= CSI2DC_DT_RAW8
,
127 .mbus_code
= MEDIA_BUS_FMT_SGRBG8_1X8
,
128 .dt
= CSI2DC_DT_RAW8
,
130 .mbus_code
= MEDIA_BUS_FMT_SGBRG8_1X8
,
131 .dt
= CSI2DC_DT_RAW8
,
133 .mbus_code
= MEDIA_BUS_FMT_SRGGB10_1X10
,
134 .dt
= CSI2DC_DT_RAW10
,
136 .mbus_code
= MEDIA_BUS_FMT_SBGGR10_1X10
,
137 .dt
= CSI2DC_DT_RAW10
,
139 .mbus_code
= MEDIA_BUS_FMT_SGRBG10_1X10
,
140 .dt
= CSI2DC_DT_RAW10
,
142 .mbus_code
= MEDIA_BUS_FMT_SGBRG10_1X10
,
143 .dt
= CSI2DC_DT_RAW10
,
145 .mbus_code
= MEDIA_BUS_FMT_YUYV8_2X8
,
146 .dt
= CSI2DC_DT_YUV422_8B
,
152 CSI2DC_PAD_SOURCE
= 1,
157 * struct csi2dc_device - CSI2DC device driver data/config struct
158 * @base: Register map base address
159 * @csi2dc_sd: v4l2 subdevice for the csi2dc device
160 * This is the subdevice that the csi2dc device itself
161 * registers in v4l2 subsystem
162 * @dev: struct device for this csi2dc device
163 * @pclk: Peripheral clock reference
164 * Input clock that clocks the hardware block internal
166 * @scck: Sensor Controller clock reference
167 * Input clock that is used to generate the pixel clock
168 * @format: Current saved format used in g/s fmt
169 * @cur_fmt: Current state format
170 * @try_fmt: Try format that is being tried
171 * @pads: Media entity pads for the csi2dc subdevice
172 * @clk_gated: Whether the clock is gated or free running
173 * @video_pipe: Whether video pipeline is configured
174 * @parallel_mode: The underlying subdevice is connected on a parallel bus
175 * @vc: Current set virtual channel
176 * @notifier: Async notifier that is used to bound the underlying
177 * subdevice to the csi2dc subdevice
178 * @input_sd: Reference to the underlying subdevice bound to the
180 * @remote_pad: Pad number of the underlying subdevice that is linked
181 * to the csi2dc subdevice sink pad.
183 struct csi2dc_device
{
185 struct v4l2_subdev csi2dc_sd
;
190 struct v4l2_mbus_framefmt format
;
192 const struct csi2dc_format
*cur_fmt
;
193 const struct csi2dc_format
*try_fmt
;
195 struct media_pad pads
[CSI2DC_PADS_NUM
];
202 struct v4l2_async_notifier notifier
;
204 struct v4l2_subdev
*input_sd
;
209 static inline struct csi2dc_device
*
210 csi2dc_sd_to_csi2dc_device(struct v4l2_subdev
*csi2dc_sd
)
212 return container_of(csi2dc_sd
, struct csi2dc_device
, csi2dc_sd
);
215 static int csi2dc_enum_mbus_code(struct v4l2_subdev
*csi2dc_sd
,
216 struct v4l2_subdev_state
*sd_state
,
217 struct v4l2_subdev_mbus_code_enum
*code
)
219 if (code
->index
>= ARRAY_SIZE(csi2dc_formats
))
222 code
->code
= csi2dc_formats
[code
->index
].mbus_code
;
227 static int csi2dc_get_fmt(struct v4l2_subdev
*csi2dc_sd
,
228 struct v4l2_subdev_state
*sd_state
,
229 struct v4l2_subdev_format
*format
)
231 struct csi2dc_device
*csi2dc
= csi2dc_sd_to_csi2dc_device(csi2dc_sd
);
232 struct v4l2_mbus_framefmt
*v4l2_try_fmt
;
234 if (format
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
235 v4l2_try_fmt
= v4l2_subdev_state_get_format(sd_state
,
237 format
->format
= *v4l2_try_fmt
;
242 format
->format
= csi2dc
->format
;
247 static int csi2dc_set_fmt(struct v4l2_subdev
*csi2dc_sd
,
248 struct v4l2_subdev_state
*sd_state
,
249 struct v4l2_subdev_format
*req_fmt
)
251 struct csi2dc_device
*csi2dc
= csi2dc_sd_to_csi2dc_device(csi2dc_sd
);
252 const struct csi2dc_format
*fmt
, *try_fmt
= NULL
;
253 struct v4l2_mbus_framefmt
*v4l2_try_fmt
;
257 * Setting the source pad is disabled.
258 * The same format is being propagated from the sink to source.
260 if (req_fmt
->pad
== CSI2DC_PAD_SOURCE
)
263 for (i
= 0; i
< ARRAY_SIZE(csi2dc_formats
); i
++) {
264 fmt
= &csi2dc_formats
[i
];
265 if (req_fmt
->format
.code
== fmt
->mbus_code
)
270 /* in case we could not find the desired format, default to something */
272 try_fmt
= &csi2dc_formats
[0];
275 "CSI2DC unsupported format 0x%x, defaulting to 0x%x\n",
276 req_fmt
->format
.code
, csi2dc_formats
[0].mbus_code
);
279 req_fmt
->format
.code
= try_fmt
->mbus_code
;
280 req_fmt
->format
.colorspace
= V4L2_COLORSPACE_SRGB
;
281 req_fmt
->format
.field
= V4L2_FIELD_NONE
;
283 if (req_fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
284 v4l2_try_fmt
= v4l2_subdev_state_get_format(sd_state
,
286 *v4l2_try_fmt
= req_fmt
->format
;
287 /* Trying on the sink pad makes the source pad change too */
288 v4l2_try_fmt
= v4l2_subdev_state_get_format(sd_state
,
290 *v4l2_try_fmt
= req_fmt
->format
;
292 /* if we are just trying, we are done */
296 /* save the format for later requests */
297 csi2dc
->format
= req_fmt
->format
;
300 csi2dc
->cur_fmt
= try_fmt
;
302 dev_dbg(csi2dc
->dev
, "new format set: 0x%x @%dx%d\n",
303 csi2dc
->format
.code
, csi2dc
->format
.width
,
304 csi2dc
->format
.height
);
309 static int csi2dc_power(struct csi2dc_device
*csi2dc
, int on
)
314 ret
= clk_prepare_enable(csi2dc
->pclk
);
316 dev_err(csi2dc
->dev
, "failed to enable pclk:%d\n", ret
);
320 ret
= clk_prepare_enable(csi2dc
->scck
);
322 dev_err(csi2dc
->dev
, "failed to enable scck:%d\n", ret
);
323 clk_disable_unprepare(csi2dc
->pclk
);
327 /* if powering up, deassert reset line */
328 csi2dc_writel(csi2dc
, CSI2DC_GCTLR
, CSI2DC_GCTLR_SWRST
);
330 /* if powering down, assert reset line */
331 csi2dc_writel(csi2dc
, CSI2DC_GCTLR
, 0);
333 clk_disable_unprepare(csi2dc
->scck
);
334 clk_disable_unprepare(csi2dc
->pclk
);
340 static int csi2dc_get_mbus_config(struct csi2dc_device
*csi2dc
)
342 struct v4l2_mbus_config mbus_config
= { 0 };
345 ret
= v4l2_subdev_call(csi2dc
->input_sd
, pad
, get_mbus_config
,
346 csi2dc
->remote_pad
, &mbus_config
);
347 if (ret
== -ENOIOCTLCMD
) {
349 "no remote mbus configuration available\n");
355 "failed to get remote mbus configuration\n");
359 dev_dbg(csi2dc
->dev
, "subdev sending on channel %d\n", csi2dc
->vc
);
361 csi2dc
->clk_gated
= mbus_config
.bus
.parallel
.flags
&
362 V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
;
364 dev_dbg(csi2dc
->dev
, "mbus_config: %s clock\n",
365 csi2dc
->clk_gated
? "gated" : "free running");
370 static void csi2dc_vp_update(struct csi2dc_device
*csi2dc
)
374 if (!csi2dc
->video_pipe
) {
375 dev_err(csi2dc
->dev
, "video pipeline unavailable\n");
379 if (csi2dc
->parallel_mode
) {
380 /* In parallel mode, GPIO parallel interface must be selected */
381 gcfg
= csi2dc_readl(csi2dc
, CSI2DC_GCFG
);
382 gcfg
|= CSI2DC_GCFG_GPIOSEL
;
383 csi2dc_writel(csi2dc
, CSI2DC_GCFG
, gcfg
);
387 /* serial video pipeline */
389 csi2dc_writel(csi2dc
, CSI2DC_GCFG
,
390 (SAMA7G5_HLC
& CSI2DC_GCFG_HLC_MASK
) |
391 (csi2dc
->clk_gated
? 0 : CSI2DC_GCFG_MIPIFRN
));
393 vp
= CSI2DC_VPCFG_DT(csi2dc
->cur_fmt
->dt
) & CSI2DC_VPCFG_DT_MASK
;
394 vp
|= CSI2DC_VPCFG_VC(csi2dc
->vc
) & CSI2DC_VPCFG_VC_MASK
;
395 vp
&= ~CSI2DC_VPCFG_DE
;
396 vp
|= CSI2DC_VPCFG_DM(CSI2DC_VPCFG_DM_DECODER8TO12
);
397 vp
&= ~CSI2DC_VPCFG_DP2
;
398 vp
&= ~CSI2DC_VPCFG_RMS
;
399 vp
|= CSI2DC_VPCFG_PA
;
401 csi2dc_writel(csi2dc
, CSI2DC_VPCFG
, vp
);
402 csi2dc_writel(csi2dc
, CSI2DC_VPE
, CSI2DC_VPE_ENABLE
);
403 csi2dc_writel(csi2dc
, CSI2DC_PU
, CSI2DC_PU_VP
);
406 static int csi2dc_s_stream(struct v4l2_subdev
*csi2dc_sd
, int enable
)
408 struct csi2dc_device
*csi2dc
= csi2dc_sd_to_csi2dc_device(csi2dc_sd
);
412 ret
= pm_runtime_resume_and_get(csi2dc
->dev
);
416 csi2dc_get_mbus_config(csi2dc
);
418 csi2dc_vp_update(csi2dc
);
420 return v4l2_subdev_call(csi2dc
->input_sd
, video
, s_stream
,
425 "Last frame received: VPCOLR = %u, VPROWR= %u, VPISR = %x\n",
426 csi2dc_readl(csi2dc
, CSI2DC_VPCOL
),
427 csi2dc_readl(csi2dc
, CSI2DC_VPROW
),
428 csi2dc_readl(csi2dc
, CSI2DC_VPISR
));
430 /* stop streaming scenario */
431 ret
= v4l2_subdev_call(csi2dc
->input_sd
, video
, s_stream
, false);
433 pm_runtime_put_sync(csi2dc
->dev
);
438 static int csi2dc_init_state(struct v4l2_subdev
*csi2dc_sd
,
439 struct v4l2_subdev_state
*sd_state
)
441 struct v4l2_mbus_framefmt
*v4l2_try_fmt
=
442 v4l2_subdev_state_get_format(sd_state
, 0);
444 v4l2_try_fmt
->height
= 480;
445 v4l2_try_fmt
->width
= 640;
446 v4l2_try_fmt
->code
= csi2dc_formats
[0].mbus_code
;
447 v4l2_try_fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
448 v4l2_try_fmt
->field
= V4L2_FIELD_NONE
;
449 v4l2_try_fmt
->ycbcr_enc
= V4L2_YCBCR_ENC_DEFAULT
;
450 v4l2_try_fmt
->quantization
= V4L2_QUANTIZATION_DEFAULT
;
451 v4l2_try_fmt
->xfer_func
= V4L2_XFER_FUNC_DEFAULT
;
456 static const struct media_entity_operations csi2dc_entity_ops
= {
457 .link_validate
= v4l2_subdev_link_validate
,
460 static const struct v4l2_subdev_pad_ops csi2dc_pad_ops
= {
461 .enum_mbus_code
= csi2dc_enum_mbus_code
,
462 .set_fmt
= csi2dc_set_fmt
,
463 .get_fmt
= csi2dc_get_fmt
,
466 static const struct v4l2_subdev_video_ops csi2dc_video_ops
= {
467 .s_stream
= csi2dc_s_stream
,
470 static const struct v4l2_subdev_ops csi2dc_subdev_ops
= {
471 .pad
= &csi2dc_pad_ops
,
472 .video
= &csi2dc_video_ops
,
475 static const struct v4l2_subdev_internal_ops csi2dc_internal_ops
= {
476 .init_state
= csi2dc_init_state
,
479 static int csi2dc_async_bound(struct v4l2_async_notifier
*notifier
,
480 struct v4l2_subdev
*subdev
,
481 struct v4l2_async_connection
*asd
)
483 struct csi2dc_device
*csi2dc
= container_of(notifier
,
484 struct csi2dc_device
, notifier
);
488 csi2dc
->input_sd
= subdev
;
490 pad
= media_entity_get_fwnode_pad(&subdev
->entity
, asd
->match
.fwnode
,
491 MEDIA_PAD_FL_SOURCE
);
493 dev_err(csi2dc
->dev
, "Failed to find pad for %s\n",
498 csi2dc
->remote_pad
= pad
;
500 ret
= media_create_pad_link(&csi2dc
->input_sd
->entity
,
502 &csi2dc
->csi2dc_sd
.entity
, 0,
503 MEDIA_LNK_FL_ENABLED
);
506 "Failed to create pad link: %s to %s\n",
507 csi2dc
->input_sd
->entity
.name
,
508 csi2dc
->csi2dc_sd
.entity
.name
);
512 dev_dbg(csi2dc
->dev
, "link with %s pad: %d\n",
513 csi2dc
->input_sd
->name
, csi2dc
->remote_pad
);
518 static const struct v4l2_async_notifier_operations csi2dc_async_ops
= {
519 .bound
= csi2dc_async_bound
,
522 static int csi2dc_prepare_notifier(struct csi2dc_device
*csi2dc
,
523 struct fwnode_handle
*input_fwnode
)
525 struct v4l2_async_connection
*asd
;
528 v4l2_async_subdev_nf_init(&csi2dc
->notifier
, &csi2dc
->csi2dc_sd
);
530 asd
= v4l2_async_nf_add_fwnode_remote(&csi2dc
->notifier
,
532 struct v4l2_async_connection
);
534 fwnode_handle_put(input_fwnode
);
539 "failed to add async notifier for node %pOF: %d\n",
540 to_of_node(input_fwnode
), ret
);
541 v4l2_async_nf_cleanup(&csi2dc
->notifier
);
545 csi2dc
->notifier
.ops
= &csi2dc_async_ops
;
547 ret
= v4l2_async_nf_register(&csi2dc
->notifier
);
549 dev_err(csi2dc
->dev
, "fail to register async notifier: %d\n",
551 v4l2_async_nf_cleanup(&csi2dc
->notifier
);
557 static int csi2dc_of_parse(struct csi2dc_device
*csi2dc
,
558 struct device_node
*of_node
)
560 struct fwnode_handle
*input_fwnode
, *output_fwnode
;
561 struct v4l2_fwnode_endpoint input_endpoint
= { 0 },
562 output_endpoint
= { 0 };
565 input_fwnode
= fwnode_graph_get_next_endpoint(of_fwnode_handle(of_node
),
569 "missing port node at %pOF, input node is mandatory.\n",
574 ret
= v4l2_fwnode_endpoint_parse(input_fwnode
, &input_endpoint
);
576 dev_err(csi2dc
->dev
, "endpoint not defined at %pOF\n", of_node
);
577 goto csi2dc_of_parse_err
;
580 if (input_endpoint
.bus_type
== V4L2_MBUS_PARALLEL
||
581 input_endpoint
.bus_type
== V4L2_MBUS_BT656
) {
582 csi2dc
->parallel_mode
= true;
584 "subdevice connected on parallel interface\n");
587 if (input_endpoint
.bus_type
== V4L2_MBUS_CSI2_DPHY
) {
588 csi2dc
->clk_gated
= input_endpoint
.bus
.mipi_csi2
.flags
&
589 V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
;
591 "subdevice connected on serial interface\n");
592 dev_dbg(csi2dc
->dev
, "DT: %s clock\n",
593 csi2dc
->clk_gated
? "gated" : "free running");
596 output_fwnode
= fwnode_graph_get_next_endpoint
597 (of_fwnode_handle(of_node
), input_fwnode
);
600 ret
= v4l2_fwnode_endpoint_parse(output_fwnode
,
603 fwnode_handle_put(output_fwnode
);
605 if (!output_fwnode
|| ret
) {
606 dev_info(csi2dc
->dev
,
607 "missing output node at %pOF, data pipe available only.\n",
610 if (output_endpoint
.bus_type
!= V4L2_MBUS_PARALLEL
&&
611 output_endpoint
.bus_type
!= V4L2_MBUS_BT656
) {
613 "output port must be parallel/bt656.\n");
615 goto csi2dc_of_parse_err
;
618 csi2dc
->video_pipe
= true;
621 "block %pOF [%d.%d]->[%d.%d] video pipeline\n",
622 of_node
, input_endpoint
.base
.port
,
623 input_endpoint
.base
.id
, output_endpoint
.base
.port
,
624 output_endpoint
.base
.id
);
627 /* prepare async notifier for subdevice completion */
628 return csi2dc_prepare_notifier(csi2dc
, input_fwnode
);
631 fwnode_handle_put(input_fwnode
);
635 static void csi2dc_default_format(struct csi2dc_device
*csi2dc
)
637 csi2dc
->cur_fmt
= &csi2dc_formats
[0];
639 csi2dc
->format
.height
= 480;
640 csi2dc
->format
.width
= 640;
641 csi2dc
->format
.code
= csi2dc_formats
[0].mbus_code
;
642 csi2dc
->format
.colorspace
= V4L2_COLORSPACE_SRGB
;
643 csi2dc
->format
.field
= V4L2_FIELD_NONE
;
644 csi2dc
->format
.ycbcr_enc
= V4L2_YCBCR_ENC_DEFAULT
;
645 csi2dc
->format
.quantization
= V4L2_QUANTIZATION_DEFAULT
;
646 csi2dc
->format
.xfer_func
= V4L2_XFER_FUNC_DEFAULT
;
649 static int csi2dc_probe(struct platform_device
*pdev
)
651 struct device
*dev
= &pdev
->dev
;
652 struct csi2dc_device
*csi2dc
;
656 csi2dc
= devm_kzalloc(dev
, sizeof(*csi2dc
), GFP_KERNEL
);
662 csi2dc
->base
= devm_platform_ioremap_resource(pdev
, 0);
663 if (IS_ERR(csi2dc
->base
)) {
664 dev_err(dev
, "base address not set\n");
665 return PTR_ERR(csi2dc
->base
);
668 csi2dc
->pclk
= devm_clk_get(dev
, "pclk");
669 if (IS_ERR(csi2dc
->pclk
)) {
670 ret
= PTR_ERR(csi2dc
->pclk
);
671 dev_err(dev
, "failed to get pclk: %d\n", ret
);
675 csi2dc
->scck
= devm_clk_get(dev
, "scck");
676 if (IS_ERR(csi2dc
->scck
)) {
677 ret
= PTR_ERR(csi2dc
->scck
);
678 dev_err(dev
, "failed to get scck: %d\n", ret
);
682 v4l2_subdev_init(&csi2dc
->csi2dc_sd
, &csi2dc_subdev_ops
);
683 csi2dc
->csi2dc_sd
.internal_ops
= &csi2dc_internal_ops
;
685 csi2dc
->csi2dc_sd
.owner
= THIS_MODULE
;
686 csi2dc
->csi2dc_sd
.dev
= dev
;
687 snprintf(csi2dc
->csi2dc_sd
.name
, sizeof(csi2dc
->csi2dc_sd
.name
),
690 csi2dc
->csi2dc_sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
691 csi2dc
->csi2dc_sd
.entity
.function
= MEDIA_ENT_F_VID_IF_BRIDGE
;
692 csi2dc
->csi2dc_sd
.entity
.ops
= &csi2dc_entity_ops
;
694 platform_set_drvdata(pdev
, csi2dc
);
696 ret
= csi2dc_of_parse(csi2dc
, dev
->of_node
);
698 goto csi2dc_probe_cleanup_entity
;
700 csi2dc
->pads
[CSI2DC_PAD_SINK
].flags
= MEDIA_PAD_FL_SINK
;
701 if (csi2dc
->video_pipe
)
702 csi2dc
->pads
[CSI2DC_PAD_SOURCE
].flags
= MEDIA_PAD_FL_SOURCE
;
704 ret
= media_entity_pads_init(&csi2dc
->csi2dc_sd
.entity
,
705 csi2dc
->video_pipe
? CSI2DC_PADS_NUM
: 1,
708 dev_err(dev
, "media entity init failed\n");
709 goto csi2dc_probe_cleanup_notifier
;
712 csi2dc_default_format(csi2dc
);
714 /* turn power on to validate capabilities */
715 ret
= csi2dc_power(csi2dc
, true);
717 goto csi2dc_probe_cleanup_notifier
;
719 pm_runtime_set_active(dev
);
720 pm_runtime_enable(dev
);
721 ver
= csi2dc_readl(csi2dc
, CSI2DC_VERSION
);
724 * we must register the subdev after PM runtime has been requested,
725 * otherwise we might bound immediately and request pm_runtime_resume
726 * before runtime_enable.
728 ret
= v4l2_async_register_subdev(&csi2dc
->csi2dc_sd
);
730 dev_err(csi2dc
->dev
, "failed to register the subdevice\n");
731 goto csi2dc_probe_cleanup_notifier
;
734 dev_info(dev
, "Microchip CSI2DC version %x\n", ver
);
738 csi2dc_probe_cleanup_notifier
:
739 v4l2_async_nf_cleanup(&csi2dc
->notifier
);
740 csi2dc_probe_cleanup_entity
:
741 media_entity_cleanup(&csi2dc
->csi2dc_sd
.entity
);
746 static void csi2dc_remove(struct platform_device
*pdev
)
748 struct csi2dc_device
*csi2dc
= platform_get_drvdata(pdev
);
750 pm_runtime_disable(&pdev
->dev
);
752 v4l2_async_unregister_subdev(&csi2dc
->csi2dc_sd
);
753 v4l2_async_nf_unregister(&csi2dc
->notifier
);
754 v4l2_async_nf_cleanup(&csi2dc
->notifier
);
755 media_entity_cleanup(&csi2dc
->csi2dc_sd
.entity
);
758 static int __maybe_unused
csi2dc_runtime_suspend(struct device
*dev
)
760 struct csi2dc_device
*csi2dc
= dev_get_drvdata(dev
);
762 return csi2dc_power(csi2dc
, false);
765 static int __maybe_unused
csi2dc_runtime_resume(struct device
*dev
)
767 struct csi2dc_device
*csi2dc
= dev_get_drvdata(dev
);
769 return csi2dc_power(csi2dc
, true);
772 static const struct dev_pm_ops csi2dc_dev_pm_ops
= {
773 SET_RUNTIME_PM_OPS(csi2dc_runtime_suspend
, csi2dc_runtime_resume
, NULL
)
776 static const struct of_device_id csi2dc_of_match
[] = {
777 { .compatible
= "microchip,sama7g5-csi2dc" },
781 MODULE_DEVICE_TABLE(of
, csi2dc_of_match
);
783 static struct platform_driver csi2dc_driver
= {
784 .probe
= csi2dc_probe
,
785 .remove
= csi2dc_remove
,
787 .name
= "microchip-csi2dc",
788 .pm
= &csi2dc_dev_pm_ops
,
789 .of_match_table
= of_match_ptr(csi2dc_of_match
),
793 module_platform_driver(csi2dc_driver
);
795 MODULE_AUTHOR("Eugen Hristev <eugen.hristev@microchip.com>");
796 MODULE_DESCRIPTION("Microchip CSI2 Demux Controller driver");
797 MODULE_LICENSE("GPL v2");