1 // SPDX-License-Identifier: GPL-2.0
5 * Qualcomm MSM Camera Subsystem - Core
7 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
8 * Copyright (C) 2015-2018 Linaro Ltd.
10 #include <linux/clk.h>
11 #include <linux/interconnect.h>
12 #include <linux/media-bus-format.h>
13 #include <linux/media.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 #include <linux/of_device.h>
18 #include <linux/of_graph.h>
19 #include <linux/pm_runtime.h>
20 #include <linux/pm_domain.h>
21 #include <linux/slab.h>
22 #include <linux/videodev2.h>
24 #include <media/media-device.h>
25 #include <media/v4l2-async.h>
26 #include <media/v4l2-device.h>
27 #include <media/v4l2-mc.h>
28 #include <media/v4l2-fwnode.h>
32 #define CAMSS_CLOCK_MARGIN_NUMERATOR 105
33 #define CAMSS_CLOCK_MARGIN_DENOMINATOR 100
35 static const struct parent_dev_ops vfe_parent_dev_ops;
37 static const struct camss_subdev_resources csiphy_res_8x16[] = {
41 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy0_timer" },
42 .clock_rate = { { 0 },
45 { 100000000, 200000000 } },
46 .reg = { "csiphy0", "csiphy0_clk_mux" },
47 .interrupt = { "csiphy0" },
49 .hw_ops = &csiphy_ops_2ph_1_0,
50 .formats = &csiphy_formats_8x16
57 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy1_timer" },
58 .clock_rate = { { 0 },
61 { 100000000, 200000000 } },
62 .reg = { "csiphy1", "csiphy1_clk_mux" },
63 .interrupt = { "csiphy1" },
65 .hw_ops = &csiphy_ops_2ph_1_0,
66 .formats = &csiphy_formats_8x16
71 static const struct camss_subdev_resources csid_res_8x16[] = {
74 .regulators = { "vdda" },
75 .clock = { "top_ahb", "ispif_ahb", "csi0_ahb", "ahb",
76 "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
77 .clock_rate = { { 0 },
81 { 100000000, 200000000 },
86 .interrupt = { "csid0" },
88 .hw_ops = &csid_ops_4_1,
89 .parent_dev_ops = &vfe_parent_dev_ops,
90 .formats = &csid_formats_4_1
96 .regulators = { "vdda" },
97 .clock = { "top_ahb", "ispif_ahb", "csi1_ahb", "ahb",
98 "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
99 .clock_rate = { { 0 },
103 { 100000000, 200000000 },
108 .interrupt = { "csid1" },
110 .hw_ops = &csid_ops_4_1,
111 .parent_dev_ops = &vfe_parent_dev_ops,
112 .formats = &csid_formats_4_1
117 static const struct camss_subdev_resources ispif_res_8x16 = {
119 .clock = { "top_ahb", "ahb", "ispif_ahb",
120 "csi0", "csi0_pix", "csi0_rdi",
121 "csi1", "csi1_pix", "csi1_rdi" },
122 .clock_for_reset = { "vfe0", "csi_vfe0" },
123 .reg = { "ispif", "csi_clk_mux" },
124 .interrupt = { "ispif" },
127 static const struct camss_subdev_resources vfe_res_8x16[] = {
131 .clock = { "top_ahb", "vfe0", "csi_vfe0",
132 "vfe_ahb", "vfe_axi", "ahb" },
133 .clock_rate = { { 0 },
134 { 50000000, 80000000, 100000000, 160000000,
135 177780000, 200000000, 266670000, 320000000,
136 400000000, 465000000 },
145 .interrupt = { "vfe0" },
148 .hw_ops = &vfe_ops_4_1,
149 .formats_rdi = &vfe_formats_rdi_8x16,
150 .formats_pix = &vfe_formats_pix_8x16
155 static const struct camss_subdev_resources csid_res_8x53[] = {
158 .regulators = { "vdda" },
159 .clock = { "top_ahb", "ispif_ahb", "csi0_ahb", "ahb",
160 "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
161 .clock_rate = { { 0 },
165 { 100000000, 200000000, 310000000,
166 400000000, 465000000 },
171 .interrupt = { "csid0" },
173 .hw_ops = &csid_ops_4_7,
174 .parent_dev_ops = &vfe_parent_dev_ops,
175 .formats = &csid_formats_4_7
181 .regulators = { "vdda" },
182 .clock = { "top_ahb", "ispif_ahb", "csi1_ahb", "ahb",
183 "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
184 .clock_rate = { { 0 },
188 { 100000000, 200000000, 310000000,
189 400000000, 465000000 },
194 .interrupt = { "csid1" },
196 .hw_ops = &csid_ops_4_7,
197 .parent_dev_ops = &vfe_parent_dev_ops,
198 .formats = &csid_formats_4_7
204 .regulators = { "vdda" },
205 .clock = { "top_ahb", "ispif_ahb", "csi2_ahb", "ahb",
206 "csi2", "csi2_phy", "csi2_pix", "csi2_rdi" },
207 .clock_rate = { { 0 },
211 { 100000000, 200000000, 310000000,
212 400000000, 465000000 },
217 .interrupt = { "csid2" },
219 .hw_ops = &csid_ops_4_7,
220 .parent_dev_ops = &vfe_parent_dev_ops,
221 .formats = &csid_formats_4_7
226 static const struct camss_subdev_resources ispif_res_8x53 = {
228 .clock = { "top_ahb", "ahb", "ispif_ahb",
229 "csi0", "csi0_pix", "csi0_rdi",
230 "csi1", "csi1_pix", "csi1_rdi",
231 "csi2", "csi2_pix", "csi2_rdi" },
232 .clock_for_reset = { "vfe0", "csi_vfe0", "vfe1", "csi_vfe1" },
233 .reg = { "ispif", "csi_clk_mux" },
234 .interrupt = { "ispif" },
237 static const struct camss_subdev_resources vfe_res_8x53[] = {
241 .clock = { "top_ahb", "ahb", "ispif_ahb",
242 "vfe0", "csi_vfe0", "vfe0_ahb", "vfe0_axi" },
243 .clock_rate = { { 0 },
246 { 50000000, 100000000, 133330000,
247 160000000, 200000000, 266670000,
248 310000000, 400000000, 465000000 },
253 .interrupt = { "vfe0" },
258 .hw_ops = &vfe_ops_4_1,
259 .formats_rdi = &vfe_formats_rdi_8x16,
260 .formats_pix = &vfe_formats_pix_8x16
267 .clock = { "top_ahb", "ahb", "ispif_ahb",
268 "vfe1", "csi_vfe1", "vfe1_ahb", "vfe1_axi" },
269 .clock_rate = { { 0 },
272 { 50000000, 100000000, 133330000,
273 160000000, 200000000, 266670000,
274 310000000, 400000000, 465000000 },
279 .interrupt = { "vfe1" },
284 .hw_ops = &vfe_ops_4_1,
285 .formats_rdi = &vfe_formats_rdi_8x16,
286 .formats_pix = &vfe_formats_pix_8x16
291 static const struct resources_icc icc_res_8x53[] = {
294 .icc_bw_tbl.avg = 38400,
295 .icc_bw_tbl.peak = 76800,
298 .name = "cam_vfe0_mem",
299 .icc_bw_tbl.avg = 939524,
300 .icc_bw_tbl.peak = 1342177,
303 .name = "cam_vfe1_mem",
304 .icc_bw_tbl.avg = 939524,
305 .icc_bw_tbl.peak = 1342177,
309 static const struct camss_subdev_resources csiphy_res_8x96[] = {
313 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy0_timer" },
314 .clock_rate = { { 0 },
317 { 100000000, 200000000, 266666667 } },
318 .reg = { "csiphy0", "csiphy0_clk_mux" },
319 .interrupt = { "csiphy0" },
321 .hw_ops = &csiphy_ops_3ph_1_0,
322 .formats = &csiphy_formats_8x96
329 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy1_timer" },
330 .clock_rate = { { 0 },
333 { 100000000, 200000000, 266666667 } },
334 .reg = { "csiphy1", "csiphy1_clk_mux" },
335 .interrupt = { "csiphy1" },
337 .hw_ops = &csiphy_ops_3ph_1_0,
338 .formats = &csiphy_formats_8x96
345 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy2_timer" },
346 .clock_rate = { { 0 },
349 { 100000000, 200000000, 266666667 } },
350 .reg = { "csiphy2", "csiphy2_clk_mux" },
351 .interrupt = { "csiphy2" },
353 .hw_ops = &csiphy_ops_3ph_1_0,
354 .formats = &csiphy_formats_8x96
359 static const struct camss_subdev_resources csid_res_8x96[] = {
362 .regulators = { "vdda" },
363 .clock = { "top_ahb", "ispif_ahb", "csi0_ahb", "ahb",
364 "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
365 .clock_rate = { { 0 },
369 { 100000000, 200000000, 266666667 },
374 .interrupt = { "csid0" },
376 .hw_ops = &csid_ops_4_7,
377 .parent_dev_ops = &vfe_parent_dev_ops,
378 .formats = &csid_formats_4_7
384 .regulators = { "vdda" },
385 .clock = { "top_ahb", "ispif_ahb", "csi1_ahb", "ahb",
386 "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
387 .clock_rate = { { 0 },
391 { 100000000, 200000000, 266666667 },
396 .interrupt = { "csid1" },
398 .hw_ops = &csid_ops_4_7,
399 .parent_dev_ops = &vfe_parent_dev_ops,
400 .formats = &csid_formats_4_7
406 .regulators = { "vdda" },
407 .clock = { "top_ahb", "ispif_ahb", "csi2_ahb", "ahb",
408 "csi2", "csi2_phy", "csi2_pix", "csi2_rdi" },
409 .clock_rate = { { 0 },
413 { 100000000, 200000000, 266666667 },
418 .interrupt = { "csid2" },
420 .hw_ops = &csid_ops_4_7,
421 .parent_dev_ops = &vfe_parent_dev_ops,
422 .formats = &csid_formats_4_7
428 .regulators = { "vdda" },
429 .clock = { "top_ahb", "ispif_ahb", "csi3_ahb", "ahb",
430 "csi3", "csi3_phy", "csi3_pix", "csi3_rdi" },
431 .clock_rate = { { 0 },
435 { 100000000, 200000000, 266666667 },
440 .interrupt = { "csid3" },
442 .hw_ops = &csid_ops_4_7,
443 .parent_dev_ops = &vfe_parent_dev_ops,
444 .formats = &csid_formats_4_7
449 static const struct camss_subdev_resources ispif_res_8x96 = {
451 .clock = { "top_ahb", "ahb", "ispif_ahb",
452 "csi0", "csi0_pix", "csi0_rdi",
453 "csi1", "csi1_pix", "csi1_rdi",
454 "csi2", "csi2_pix", "csi2_rdi",
455 "csi3", "csi3_pix", "csi3_rdi" },
456 .clock_for_reset = { "vfe0", "csi_vfe0", "vfe1", "csi_vfe1" },
457 .reg = { "ispif", "csi_clk_mux" },
458 .interrupt = { "ispif" },
461 static const struct camss_subdev_resources vfe_res_8x96[] = {
465 .clock = { "top_ahb", "ahb", "vfe0", "csi_vfe0", "vfe_ahb",
466 "vfe0_ahb", "vfe_axi", "vfe0_stream"},
467 .clock_rate = { { 0 },
469 { 75000000, 100000000, 300000000,
470 320000000, 480000000, 600000000 },
477 .interrupt = { "vfe0" },
481 .hw_ops = &vfe_ops_4_7,
482 .formats_rdi = &vfe_formats_rdi_8x96,
483 .formats_pix = &vfe_formats_pix_8x96
490 .clock = { "top_ahb", "ahb", "vfe1", "csi_vfe1", "vfe_ahb",
491 "vfe1_ahb", "vfe_axi", "vfe1_stream"},
492 .clock_rate = { { 0 },
494 { 75000000, 100000000, 300000000,
495 320000000, 480000000, 600000000 },
502 .interrupt = { "vfe1" },
506 .hw_ops = &vfe_ops_4_7,
507 .formats_rdi = &vfe_formats_rdi_8x96,
508 .formats_pix = &vfe_formats_pix_8x96
513 static const struct camss_subdev_resources csiphy_res_660[] = {
517 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy0_timer",
518 "csi0_phy", "csiphy_ahb2crif" },
519 .clock_rate = { { 0 },
522 { 100000000, 200000000, 269333333 },
524 .reg = { "csiphy0", "csiphy0_clk_mux" },
525 .interrupt = { "csiphy0" },
527 .hw_ops = &csiphy_ops_3ph_1_0,
528 .formats = &csiphy_formats_8x96
535 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy1_timer",
536 "csi1_phy", "csiphy_ahb2crif" },
537 .clock_rate = { { 0 },
540 { 100000000, 200000000, 269333333 },
542 .reg = { "csiphy1", "csiphy1_clk_mux" },
543 .interrupt = { "csiphy1" },
545 .hw_ops = &csiphy_ops_3ph_1_0,
546 .formats = &csiphy_formats_8x96
553 .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy2_timer",
554 "csi2_phy", "csiphy_ahb2crif" },
555 .clock_rate = { { 0 },
558 { 100000000, 200000000, 269333333 },
560 .reg = { "csiphy2", "csiphy2_clk_mux" },
561 .interrupt = { "csiphy2" },
563 .hw_ops = &csiphy_ops_3ph_1_0,
564 .formats = &csiphy_formats_8x96
569 static const struct camss_subdev_resources csid_res_660[] = {
572 .regulators = { "vdda", "vdd_sec" },
573 .clock = { "top_ahb", "ispif_ahb", "csi0_ahb", "ahb",
574 "csi0", "csi0_phy", "csi0_pix", "csi0_rdi",
576 .clock_rate = { { 0 },
580 { 100000000, 200000000, 310000000,
581 404000000, 465000000 },
587 .interrupt = { "csid0" },
589 .hw_ops = &csid_ops_4_7,
590 .parent_dev_ops = &vfe_parent_dev_ops,
591 .formats = &csid_formats_4_7
597 .regulators = { "vdda", "vdd_sec" },
598 .clock = { "top_ahb", "ispif_ahb", "csi1_ahb", "ahb",
599 "csi1", "csi1_phy", "csi1_pix", "csi1_rdi",
601 .clock_rate = { { 0 },
605 { 100000000, 200000000, 310000000,
606 404000000, 465000000 },
612 .interrupt = { "csid1" },
614 .hw_ops = &csid_ops_4_7,
615 .parent_dev_ops = &vfe_parent_dev_ops,
616 .formats = &csid_formats_4_7
622 .regulators = { "vdda", "vdd_sec" },
623 .clock = { "top_ahb", "ispif_ahb", "csi2_ahb", "ahb",
624 "csi2", "csi2_phy", "csi2_pix", "csi2_rdi",
626 .clock_rate = { { 0 },
630 { 100000000, 200000000, 310000000,
631 404000000, 465000000 },
637 .interrupt = { "csid2" },
639 .hw_ops = &csid_ops_4_7,
640 .parent_dev_ops = &vfe_parent_dev_ops,
641 .formats = &csid_formats_4_7
647 .regulators = { "vdda", "vdd_sec" },
648 .clock = { "top_ahb", "ispif_ahb", "csi3_ahb", "ahb",
649 "csi3", "csi3_phy", "csi3_pix", "csi3_rdi",
651 .clock_rate = { { 0 },
655 { 100000000, 200000000, 310000000,
656 404000000, 465000000 },
662 .interrupt = { "csid3" },
664 .hw_ops = &csid_ops_4_7,
665 .parent_dev_ops = &vfe_parent_dev_ops,
666 .formats = &csid_formats_4_7
671 static const struct camss_subdev_resources ispif_res_660 = {
673 .clock = { "top_ahb", "ahb", "ispif_ahb",
674 "csi0", "csi0_pix", "csi0_rdi",
675 "csi1", "csi1_pix", "csi1_rdi",
676 "csi2", "csi2_pix", "csi2_rdi",
677 "csi3", "csi3_pix", "csi3_rdi" },
678 .clock_for_reset = { "vfe0", "csi_vfe0", "vfe1", "csi_vfe1" },
679 .reg = { "ispif", "csi_clk_mux" },
680 .interrupt = { "ispif" },
683 static const struct camss_subdev_resources vfe_res_660[] = {
687 .clock = { "throttle_axi", "top_ahb", "ahb", "vfe0",
688 "csi_vfe0", "vfe_ahb", "vfe0_ahb", "vfe_axi",
690 .clock_rate = { { 0 },
693 { 120000000, 200000000, 256000000,
694 300000000, 404000000, 480000000,
695 540000000, 576000000 },
702 .interrupt = { "vfe0" },
706 .hw_ops = &vfe_ops_4_8,
707 .formats_rdi = &vfe_formats_rdi_8x96,
708 .formats_pix = &vfe_formats_pix_8x96
715 .clock = { "throttle_axi", "top_ahb", "ahb", "vfe1",
716 "csi_vfe1", "vfe_ahb", "vfe1_ahb", "vfe_axi",
718 .clock_rate = { { 0 },
721 { 120000000, 200000000, 256000000,
722 300000000, 404000000, 480000000,
723 540000000, 576000000 },
730 .interrupt = { "vfe1" },
734 .hw_ops = &vfe_ops_4_8,
735 .formats_rdi = &vfe_formats_rdi_8x96,
736 .formats_pix = &vfe_formats_pix_8x96
741 static const struct camss_subdev_resources csiphy_res_845[] = {
745 .clock = { "camnoc_axi", "soc_ahb", "slow_ahb_src",
746 "cpas_ahb", "cphy_rx_src", "csiphy0",
747 "csiphy0_timer_src", "csiphy0_timer" },
748 .clock_rate = { { 0 },
755 { 19200000, 240000000, 269333333 } },
756 .reg = { "csiphy0" },
757 .interrupt = { "csiphy0" },
759 .hw_ops = &csiphy_ops_3ph_1_0,
760 .formats = &csiphy_formats_sdm845
767 .clock = { "camnoc_axi", "soc_ahb", "slow_ahb_src",
768 "cpas_ahb", "cphy_rx_src", "csiphy1",
769 "csiphy1_timer_src", "csiphy1_timer" },
770 .clock_rate = { { 0 },
777 { 19200000, 240000000, 269333333 } },
778 .reg = { "csiphy1" },
779 .interrupt = { "csiphy1" },
781 .hw_ops = &csiphy_ops_3ph_1_0,
782 .formats = &csiphy_formats_sdm845
789 .clock = { "camnoc_axi", "soc_ahb", "slow_ahb_src",
790 "cpas_ahb", "cphy_rx_src", "csiphy2",
791 "csiphy2_timer_src", "csiphy2_timer" },
792 .clock_rate = { { 0 },
799 { 19200000, 240000000, 269333333 } },
800 .reg = { "csiphy2" },
801 .interrupt = { "csiphy2" },
803 .hw_ops = &csiphy_ops_3ph_1_0,
804 .formats = &csiphy_formats_sdm845
811 .clock = { "camnoc_axi", "soc_ahb", "slow_ahb_src",
812 "cpas_ahb", "cphy_rx_src", "csiphy3",
813 "csiphy3_timer_src", "csiphy3_timer" },
814 .clock_rate = { { 0 },
821 { 19200000, 240000000, 269333333 } },
822 .reg = { "csiphy3" },
823 .interrupt = { "csiphy3" },
825 .hw_ops = &csiphy_ops_3ph_1_0,
826 .formats = &csiphy_formats_sdm845
831 static const struct camss_subdev_resources csid_res_845[] = {
834 .regulators = { "vdda-phy", "vdda-pll" },
835 .clock = { "cpas_ahb", "cphy_rx_src", "slow_ahb_src",
836 "soc_ahb", "vfe0", "vfe0_src",
837 "vfe0_cphy_rx", "csi0",
839 .clock_rate = { { 0 },
843 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
846 { 19200000, 75000000, 384000000, 538666667 },
849 .interrupt = { "csid0" },
851 .hw_ops = &csid_ops_gen2,
852 .parent_dev_ops = &vfe_parent_dev_ops,
853 .formats = &csid_formats_gen2
859 .regulators = { "vdda-phy", "vdda-pll" },
860 .clock = { "cpas_ahb", "cphy_rx_src", "slow_ahb_src",
861 "soc_ahb", "vfe1", "vfe1_src",
862 "vfe1_cphy_rx", "csi1",
864 .clock_rate = { { 0 },
868 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
871 { 19200000, 75000000, 384000000, 538666667 },
874 .interrupt = { "csid1" },
876 .hw_ops = &csid_ops_gen2,
877 .parent_dev_ops = &vfe_parent_dev_ops,
878 .formats = &csid_formats_gen2
884 .regulators = { "vdda-phy", "vdda-pll" },
885 .clock = { "cpas_ahb", "cphy_rx_src", "slow_ahb_src",
886 "soc_ahb", "vfe_lite", "vfe_lite_src",
887 "vfe_lite_cphy_rx", "csi2",
889 .clock_rate = { { 0 },
893 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
896 { 19200000, 75000000, 384000000, 538666667 },
899 .interrupt = { "csid2" },
902 .hw_ops = &csid_ops_gen2,
903 .parent_dev_ops = &vfe_parent_dev_ops,
904 .formats = &csid_formats_gen2
909 static const struct camss_subdev_resources vfe_res_845[] = {
913 .clock = { "camnoc_axi", "cpas_ahb", "slow_ahb_src",
914 "soc_ahb", "vfe0", "vfe0_axi",
917 .clock_rate = { { 0 },
921 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
924 { 19200000, 75000000, 384000000, 538666667 },
927 .interrupt = { "vfe0" },
931 .hw_ops = &vfe_ops_170,
932 .formats_rdi = &vfe_formats_rdi_845,
933 .formats_pix = &vfe_formats_pix_845
940 .clock = { "camnoc_axi", "cpas_ahb", "slow_ahb_src",
941 "soc_ahb", "vfe1", "vfe1_axi",
944 .clock_rate = { { 0 },
948 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
951 { 19200000, 75000000, 384000000, 538666667 },
954 .interrupt = { "vfe1" },
958 .hw_ops = &vfe_ops_170,
959 .formats_rdi = &vfe_formats_rdi_845,
960 .formats_pix = &vfe_formats_pix_845
967 .clock = { "camnoc_axi", "cpas_ahb", "slow_ahb_src",
968 "soc_ahb", "vfe_lite",
969 "vfe_lite_src", "csi2",
971 .clock_rate = { { 0 },
975 { 19200000, 100000000, 320000000, 404000000, 480000000, 600000000 },
977 { 19200000, 75000000, 384000000, 538666667 },
979 .reg = { "vfe_lite" },
980 .interrupt = { "vfe_lite" },
984 .hw_ops = &vfe_ops_170,
985 .formats_rdi = &vfe_formats_rdi_845,
986 .formats_pix = &vfe_formats_pix_845
991 static const struct camss_subdev_resources csiphy_res_8250[] = {
994 .regulators = { "vdda-phy", "vdda-pll" },
995 .clock = { "csiphy0", "csiphy0_timer" },
996 .clock_rate = { { 400000000 },
998 .reg = { "csiphy0" },
999 .interrupt = { "csiphy0" },
1001 .hw_ops = &csiphy_ops_3ph_1_0,
1002 .formats = &csiphy_formats_sdm845
1007 .regulators = { "vdda-phy", "vdda-pll" },
1008 .clock = { "csiphy1", "csiphy1_timer" },
1009 .clock_rate = { { 400000000 },
1011 .reg = { "csiphy1" },
1012 .interrupt = { "csiphy1" },
1014 .hw_ops = &csiphy_ops_3ph_1_0,
1015 .formats = &csiphy_formats_sdm845
1020 .regulators = { "vdda-phy", "vdda-pll" },
1021 .clock = { "csiphy2", "csiphy2_timer" },
1022 .clock_rate = { { 400000000 },
1024 .reg = { "csiphy2" },
1025 .interrupt = { "csiphy2" },
1027 .hw_ops = &csiphy_ops_3ph_1_0,
1028 .formats = &csiphy_formats_sdm845
1033 .regulators = { "vdda-phy", "vdda-pll" },
1034 .clock = { "csiphy3", "csiphy3_timer" },
1035 .clock_rate = { { 400000000 },
1037 .reg = { "csiphy3" },
1038 .interrupt = { "csiphy3" },
1040 .hw_ops = &csiphy_ops_3ph_1_0,
1041 .formats = &csiphy_formats_sdm845
1046 .regulators = { "vdda-phy", "vdda-pll" },
1047 .clock = { "csiphy4", "csiphy4_timer" },
1048 .clock_rate = { { 400000000 },
1050 .reg = { "csiphy4" },
1051 .interrupt = { "csiphy4" },
1053 .hw_ops = &csiphy_ops_3ph_1_0,
1054 .formats = &csiphy_formats_sdm845
1059 .regulators = { "vdda-phy", "vdda-pll" },
1060 .clock = { "csiphy5", "csiphy5_timer" },
1061 .clock_rate = { { 400000000 },
1063 .reg = { "csiphy5" },
1064 .interrupt = { "csiphy5" },
1066 .hw_ops = &csiphy_ops_3ph_1_0,
1067 .formats = &csiphy_formats_sdm845
1072 static const struct camss_subdev_resources csid_res_8250[] = {
1076 .clock = { "vfe0_csid", "vfe0_cphy_rx", "vfe0", "vfe0_areg", "vfe0_ahb" },
1077 .clock_rate = { { 400000000 },
1079 { 350000000, 475000000, 576000000, 720000000 },
1080 { 100000000, 200000000, 300000000, 400000000 },
1083 .interrupt = { "csid0" },
1085 .hw_ops = &csid_ops_gen2,
1086 .parent_dev_ops = &vfe_parent_dev_ops,
1087 .formats = &csid_formats_gen2
1093 .clock = { "vfe1_csid", "vfe1_cphy_rx", "vfe1", "vfe1_areg", "vfe1_ahb" },
1094 .clock_rate = { { 400000000 },
1096 { 350000000, 475000000, 576000000, 720000000 },
1097 { 100000000, 200000000, 300000000, 400000000 },
1100 .interrupt = { "csid1" },
1102 .hw_ops = &csid_ops_gen2,
1103 .parent_dev_ops = &vfe_parent_dev_ops,
1104 .formats = &csid_formats_gen2
1110 .clock = { "vfe_lite_csid", "vfe_lite_cphy_rx", "vfe_lite", "vfe_lite_ahb" },
1111 .clock_rate = { { 400000000 },
1113 { 400000000, 480000000 },
1116 .interrupt = { "csid2" },
1119 .hw_ops = &csid_ops_gen2,
1120 .parent_dev_ops = &vfe_parent_dev_ops,
1121 .formats = &csid_formats_gen2
1127 .clock = { "vfe_lite_csid", "vfe_lite_cphy_rx", "vfe_lite", "vfe_lite_ahb" },
1128 .clock_rate = { { 400000000 },
1130 { 400000000, 480000000 },
1133 .interrupt = { "csid3" },
1136 .hw_ops = &csid_ops_gen2,
1137 .parent_dev_ops = &vfe_parent_dev_ops,
1138 .formats = &csid_formats_gen2
1143 static const struct camss_subdev_resources vfe_res_8250[] = {
1147 .clock = { "camnoc_axi_src", "slow_ahb_src", "cpas_ahb",
1148 "camnoc_axi", "vfe0_ahb", "vfe0_areg", "vfe0",
1149 "vfe0_axi", "cam_hf_axi" },
1150 .clock_rate = { { 19200000, 300000000, 400000000, 480000000 },
1151 { 19200000, 80000000 },
1155 { 100000000, 200000000, 300000000, 400000000 },
1156 { 350000000, 475000000, 576000000, 720000000 },
1160 .interrupt = { "vfe0" },
1165 .hw_ops = &vfe_ops_480,
1166 .formats_rdi = &vfe_formats_rdi_845,
1167 .formats_pix = &vfe_formats_pix_845
1173 .clock = { "camnoc_axi_src", "slow_ahb_src", "cpas_ahb",
1174 "camnoc_axi", "vfe1_ahb", "vfe1_areg", "vfe1",
1175 "vfe1_axi", "cam_hf_axi" },
1176 .clock_rate = { { 19200000, 300000000, 400000000, 480000000 },
1177 { 19200000, 80000000 },
1181 { 100000000, 200000000, 300000000, 400000000 },
1182 { 350000000, 475000000, 576000000, 720000000 },
1186 .interrupt = { "vfe1" },
1191 .hw_ops = &vfe_ops_480,
1192 .formats_rdi = &vfe_formats_rdi_845,
1193 .formats_pix = &vfe_formats_pix_845
1199 .clock = { "camnoc_axi_src", "slow_ahb_src", "cpas_ahb",
1200 "camnoc_axi", "vfe_lite_ahb", "vfe_lite_axi",
1201 "vfe_lite", "cam_hf_axi" },
1202 .clock_rate = { { 19200000, 300000000, 400000000, 480000000 },
1203 { 19200000, 80000000 },
1208 { 400000000, 480000000 },
1210 .reg = { "vfe_lite0" },
1211 .interrupt = { "vfe_lite0" },
1215 .hw_ops = &vfe_ops_480,
1216 .formats_rdi = &vfe_formats_rdi_845,
1217 .formats_pix = &vfe_formats_pix_845
1223 .clock = { "camnoc_axi_src", "slow_ahb_src", "cpas_ahb",
1224 "camnoc_axi", "vfe_lite_ahb", "vfe_lite_axi",
1225 "vfe_lite", "cam_hf_axi" },
1226 .clock_rate = { { 19200000, 300000000, 400000000, 480000000 },
1227 { 19200000, 80000000 },
1232 { 400000000, 480000000 },
1234 .reg = { "vfe_lite1" },
1235 .interrupt = { "vfe_lite1" },
1239 .hw_ops = &vfe_ops_480,
1240 .formats_rdi = &vfe_formats_rdi_845,
1241 .formats_pix = &vfe_formats_pix_845
1246 static const struct resources_icc icc_res_sm8250[] = {
1249 .icc_bw_tbl.avg = 38400,
1250 .icc_bw_tbl.peak = 76800,
1253 .name = "cam_hf_0_mnoc",
1254 .icc_bw_tbl.avg = 2097152,
1255 .icc_bw_tbl.peak = 2097152,
1258 .name = "cam_sf_0_mnoc",
1259 .icc_bw_tbl.avg = 0,
1260 .icc_bw_tbl.peak = 2097152,
1263 .name = "cam_sf_icp_mnoc",
1264 .icc_bw_tbl.avg = 2097152,
1265 .icc_bw_tbl.peak = 2097152,
1269 static const struct camss_subdev_resources csiphy_res_sc8280xp[] = {
1273 .clock = { "csiphy0", "csiphy0_timer" },
1274 .clock_rate = { { 400000000 },
1276 .reg = { "csiphy0" },
1277 .interrupt = { "csiphy0" },
1279 .hw_ops = &csiphy_ops_3ph_1_0,
1280 .formats = &csiphy_formats_sdm845
1286 .clock = { "csiphy1", "csiphy1_timer" },
1287 .clock_rate = { { 400000000 },
1289 .reg = { "csiphy1" },
1290 .interrupt = { "csiphy1" },
1292 .hw_ops = &csiphy_ops_3ph_1_0,
1293 .formats = &csiphy_formats_sdm845
1299 .clock = { "csiphy2", "csiphy2_timer" },
1300 .clock_rate = { { 400000000 },
1302 .reg = { "csiphy2" },
1303 .interrupt = { "csiphy2" },
1305 .hw_ops = &csiphy_ops_3ph_1_0,
1306 .formats = &csiphy_formats_sdm845
1312 .clock = { "csiphy3", "csiphy3_timer" },
1313 .clock_rate = { { 400000000 },
1315 .reg = { "csiphy3" },
1316 .interrupt = { "csiphy3" },
1318 .hw_ops = &csiphy_ops_3ph_1_0,
1319 .formats = &csiphy_formats_sdm845
1324 static const struct camss_subdev_resources csid_res_sc8280xp[] = {
1327 .regulators = { "vdda-phy", "vdda-pll" },
1328 .clock = { "vfe0_csid", "vfe0_cphy_rx", "vfe0", "vfe0_axi" },
1329 .clock_rate = { { 400000000, 480000000, 600000000 },
1334 .interrupt = { "csid0" },
1336 .hw_ops = &csid_ops_gen2,
1337 .parent_dev_ops = &vfe_parent_dev_ops,
1338 .formats = &csid_formats_gen2
1343 .regulators = { "vdda-phy", "vdda-pll" },
1344 .clock = { "vfe1_csid", "vfe1_cphy_rx", "vfe1", "vfe1_axi" },
1345 .clock_rate = { { 400000000, 480000000, 600000000 },
1350 .interrupt = { "csid1" },
1352 .hw_ops = &csid_ops_gen2,
1353 .parent_dev_ops = &vfe_parent_dev_ops,
1354 .formats = &csid_formats_gen2
1359 .regulators = { "vdda-phy", "vdda-pll" },
1360 .clock = { "vfe2_csid", "vfe2_cphy_rx", "vfe2", "vfe2_axi" },
1361 .clock_rate = { { 400000000, 480000000, 600000000 },
1366 .interrupt = { "csid2" },
1368 .hw_ops = &csid_ops_gen2,
1369 .parent_dev_ops = &vfe_parent_dev_ops,
1370 .formats = &csid_formats_gen2
1375 .regulators = { "vdda-phy", "vdda-pll" },
1376 .clock = { "vfe3_csid", "vfe3_cphy_rx", "vfe3", "vfe3_axi" },
1377 .clock_rate = { { 400000000, 480000000, 600000000 },
1382 .interrupt = { "csid3" },
1384 .hw_ops = &csid_ops_gen2,
1385 .parent_dev_ops = &vfe_parent_dev_ops,
1386 .formats = &csid_formats_gen2
1391 .regulators = { "vdda-phy", "vdda-pll" },
1392 .clock = { "vfe_lite0_csid", "vfe_lite0_cphy_rx", "vfe_lite0" },
1393 .clock_rate = { { 400000000, 480000000, 600000000 },
1396 .reg = { "csid0_lite" },
1397 .interrupt = { "csid0_lite" },
1400 .hw_ops = &csid_ops_gen2,
1401 .parent_dev_ops = &vfe_parent_dev_ops,
1402 .formats = &csid_formats_gen2
1407 .regulators = { "vdda-phy", "vdda-pll" },
1408 .clock = { "vfe_lite1_csid", "vfe_lite1_cphy_rx", "vfe_lite1" },
1409 .clock_rate = { { 400000000, 480000000, 600000000 },
1412 .reg = { "csid1_lite" },
1413 .interrupt = { "csid1_lite" },
1416 .hw_ops = &csid_ops_gen2,
1417 .parent_dev_ops = &vfe_parent_dev_ops,
1418 .formats = &csid_formats_gen2
1423 .regulators = { "vdda-phy", "vdda-pll" },
1424 .clock = { "vfe_lite2_csid", "vfe_lite2_cphy_rx", "vfe_lite2" },
1425 .clock_rate = { { 400000000, 480000000, 600000000 },
1428 .reg = { "csid2_lite" },
1429 .interrupt = { "csid2_lite" },
1432 .hw_ops = &csid_ops_gen2,
1433 .parent_dev_ops = &vfe_parent_dev_ops,
1434 .formats = &csid_formats_gen2
1439 .regulators = { "vdda-phy", "vdda-pll" },
1440 .clock = { "vfe_lite3_csid", "vfe_lite3_cphy_rx", "vfe_lite3" },
1441 .clock_rate = { { 400000000, 480000000, 600000000 },
1444 .reg = { "csid3_lite" },
1445 .interrupt = { "csid3_lite" },
1448 .hw_ops = &csid_ops_gen2,
1449 .parent_dev_ops = &vfe_parent_dev_ops,
1450 .formats = &csid_formats_gen2
1455 static const struct camss_subdev_resources vfe_res_sc8280xp[] = {
1459 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe0", "vfe0_axi" },
1460 .clock_rate = { { 0 },
1462 { 19200000, 80000000},
1463 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1464 { 400000000, 558000000, 637000000, 760000000 },
1467 .interrupt = { "vfe0" },
1471 .hw_ops = &vfe_ops_170,
1472 .formats_rdi = &vfe_formats_rdi_845,
1473 .formats_pix = &vfe_formats_pix_845
1479 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe1", "vfe1_axi" },
1480 .clock_rate = { { 0 },
1482 { 19200000, 80000000},
1483 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1484 { 400000000, 558000000, 637000000, 760000000 },
1487 .interrupt = { "vfe1" },
1491 .hw_ops = &vfe_ops_170,
1492 .formats_rdi = &vfe_formats_rdi_845,
1493 .formats_pix = &vfe_formats_pix_845
1499 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe2", "vfe2_axi" },
1500 .clock_rate = { { 0 },
1502 { 19200000, 80000000},
1503 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1504 { 400000000, 558000000, 637000000, 760000000 },
1507 .interrupt = { "vfe2" },
1511 .hw_ops = &vfe_ops_170,
1512 .formats_rdi = &vfe_formats_rdi_845,
1513 .formats_pix = &vfe_formats_pix_845
1519 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe3", "vfe3_axi" },
1520 .clock_rate = { { 0 },
1522 { 19200000, 80000000},
1523 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1524 { 400000000, 558000000, 637000000, 760000000 },
1527 .interrupt = { "vfe3" },
1531 .hw_ops = &vfe_ops_170,
1532 .formats_rdi = &vfe_formats_rdi_845,
1533 .formats_pix = &vfe_formats_pix_845
1539 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe_lite0" },
1540 .clock_rate = { { 0 },
1542 { 19200000, 80000000},
1543 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1544 { 320000000, 400000000, 480000000, 600000000 }, },
1545 .reg = { "vfe_lite0" },
1546 .interrupt = { "vfe_lite0" },
1550 .hw_ops = &vfe_ops_170,
1551 .formats_rdi = &vfe_formats_rdi_845,
1552 .formats_pix = &vfe_formats_pix_845
1558 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe_lite1" },
1559 .clock_rate = { { 0 },
1561 { 19200000, 80000000},
1562 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1563 { 320000000, 400000000, 480000000, 600000000 }, },
1564 .reg = { "vfe_lite1" },
1565 .interrupt = { "vfe_lite1" },
1569 .hw_ops = &vfe_ops_170,
1570 .formats_rdi = &vfe_formats_rdi_845,
1571 .formats_pix = &vfe_formats_pix_845
1577 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe_lite2" },
1578 .clock_rate = { { 0 },
1580 { 19200000, 80000000},
1581 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1582 { 320000000, 400000000, 480000000, 600000000, }, },
1583 .reg = { "vfe_lite2" },
1584 .interrupt = { "vfe_lite2" },
1588 .hw_ops = &vfe_ops_170,
1589 .formats_rdi = &vfe_formats_rdi_845,
1590 .formats_pix = &vfe_formats_pix_845
1596 .clock = { "gcc_axi_hf", "gcc_axi_sf", "cpas_ahb", "camnoc_axi", "vfe_lite3" },
1597 .clock_rate = { { 0 },
1599 { 19200000, 80000000},
1600 { 19200000, 150000000, 266666667, 320000000, 400000000, 480000000 },
1601 { 320000000, 400000000, 480000000, 600000000 }, },
1602 .reg = { "vfe_lite3" },
1603 .interrupt = { "vfe_lite3" },
1607 .hw_ops = &vfe_ops_170,
1608 .formats_rdi = &vfe_formats_rdi_845,
1609 .formats_pix = &vfe_formats_pix_845
1614 static const struct resources_icc icc_res_sc8280xp[] = {
1617 .icc_bw_tbl.avg = 150000,
1618 .icc_bw_tbl.peak = 300000,
1621 .name = "cam_hf_mnoc",
1622 .icc_bw_tbl.avg = 2097152,
1623 .icc_bw_tbl.peak = 2097152,
1626 .name = "cam_sf_mnoc",
1627 .icc_bw_tbl.avg = 2097152,
1628 .icc_bw_tbl.peak = 2097152,
1631 .name = "cam_sf_icp_mnoc",
1632 .icc_bw_tbl.avg = 2097152,
1633 .icc_bw_tbl.peak = 2097152,
1638 * camss_add_clock_margin - Add margin to clock frequency rate
1639 * @rate: Clock frequency rate
1641 * When making calculations with physical clock frequency values
1642 * some safety margin must be added. Add it.
1644 inline void camss_add_clock_margin(u64 *rate)
1646 *rate *= CAMSS_CLOCK_MARGIN_NUMERATOR;
1647 *rate = div_u64(*rate, CAMSS_CLOCK_MARGIN_DENOMINATOR);
1651 * camss_enable_clocks - Enable multiple clocks
1652 * @nclocks: Number of clocks in clock array
1653 * @clock: Clock array
1656 * Return 0 on success or a negative error code otherwise
1658 int camss_enable_clocks(int nclocks, struct camss_clock *clock,
1664 for (i = 0; i < nclocks; i++) {
1665 ret = clk_prepare_enable(clock[i].clk);
1667 dev_err(dev, "clock enable failed: %d\n", ret);
1675 for (i--; i >= 0; i--)
1676 clk_disable_unprepare(clock[i].clk);
1682 * camss_disable_clocks - Disable multiple clocks
1683 * @nclocks: Number of clocks in clock array
1684 * @clock: Clock array
1686 void camss_disable_clocks(int nclocks, struct camss_clock *clock)
1690 for (i = nclocks - 1; i >= 0; i--)
1691 clk_disable_unprepare(clock[i].clk);
1695 * camss_find_sensor - Find a linked media entity which represents a sensor
1696 * @entity: Media entity to start searching from
1698 * Return a pointer to sensor media entity or NULL if not found
1700 struct media_entity *camss_find_sensor(struct media_entity *entity)
1702 struct media_pad *pad;
1705 pad = &entity->pads[0];
1706 if (!(pad->flags & MEDIA_PAD_FL_SINK))
1709 pad = media_pad_remote_pad_first(pad);
1710 if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
1713 entity = pad->entity;
1715 if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
1721 * camss_get_link_freq - Get link frequency from sensor
1722 * @entity: Media entity in the current pipeline
1723 * @bpp: Number of bits per pixel for the current format
1724 * @lanes: Number of lanes in the link to the sensor
1726 * Return link frequency on success or a negative error code otherwise
1728 s64 camss_get_link_freq(struct media_entity *entity, unsigned int bpp,
1731 struct media_entity *sensor;
1732 struct v4l2_subdev *subdev;
1734 sensor = camss_find_sensor(entity);
1738 subdev = media_entity_to_v4l2_subdev(sensor);
1740 return v4l2_get_link_freq(subdev->ctrl_handler, bpp, 2 * lanes);
1744 * camss_get_pixel_clock - Get pixel clock rate from sensor
1745 * @entity: Media entity in the current pipeline
1746 * @pixel_clock: Received pixel clock value
1748 * Return 0 on success or a negative error code otherwise
1750 int camss_get_pixel_clock(struct media_entity *entity, u64 *pixel_clock)
1752 struct media_entity *sensor;
1753 struct v4l2_subdev *subdev;
1754 struct v4l2_ctrl *ctrl;
1756 sensor = camss_find_sensor(entity);
1760 subdev = media_entity_to_v4l2_subdev(sensor);
1762 ctrl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
1767 *pixel_clock = v4l2_ctrl_g_ctrl_int64(ctrl);
1772 int camss_pm_domain_on(struct camss *camss, int id)
1776 if (id < camss->res->vfe_num) {
1777 struct vfe_device *vfe = &camss->vfe[id];
1779 ret = vfe->res->hw_ops->pm_domain_on(vfe);
1785 void camss_pm_domain_off(struct camss *camss, int id)
1787 if (id < camss->res->vfe_num) {
1788 struct vfe_device *vfe = &camss->vfe[id];
1790 vfe->res->hw_ops->pm_domain_off(vfe);
1794 static int vfe_parent_dev_ops_get(struct camss *camss, int id)
1798 if (id < camss->res->vfe_num) {
1799 struct vfe_device *vfe = &camss->vfe[id];
1807 static int vfe_parent_dev_ops_put(struct camss *camss, int id)
1809 if (id < camss->res->vfe_num) {
1810 struct vfe_device *vfe = &camss->vfe[id];
1819 *vfe_parent_dev_ops_get_base_address(struct camss *camss, int id)
1821 if (id < camss->res->vfe_num) {
1822 struct vfe_device *vfe = &camss->vfe[id];
1830 static const struct parent_dev_ops vfe_parent_dev_ops = {
1831 .get = vfe_parent_dev_ops_get,
1832 .put = vfe_parent_dev_ops_put,
1833 .get_base_address = vfe_parent_dev_ops_get_base_address
1837 * camss_of_parse_endpoint_node - Parse port endpoint node
1839 * @node: Device node to be parsed
1840 * @csd: Parsed data from port endpoint node
1842 * Return 0 on success or a negative error code on failure
1844 static int camss_of_parse_endpoint_node(struct device *dev,
1845 struct device_node *node,
1846 struct camss_async_subdev *csd)
1848 struct csiphy_lanes_cfg *lncfg = &csd->interface.csi2.lane_cfg;
1849 struct v4l2_mbus_config_mipi_csi2 *mipi_csi2;
1850 struct v4l2_fwnode_endpoint vep = { { 0 } };
1854 ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(node), &vep);
1858 csd->interface.csiphy_id = vep.base.port;
1860 mipi_csi2 = &vep.bus.mipi_csi2;
1861 lncfg->clk.pos = mipi_csi2->clock_lane;
1862 lncfg->clk.pol = mipi_csi2->lane_polarities[0];
1863 lncfg->num_data = mipi_csi2->num_data_lanes;
1865 lncfg->data = devm_kcalloc(dev,
1866 lncfg->num_data, sizeof(*lncfg->data),
1871 for (i = 0; i < lncfg->num_data; i++) {
1872 lncfg->data[i].pos = mipi_csi2->data_lanes[i];
1873 lncfg->data[i].pol = mipi_csi2->lane_polarities[i + 1];
1880 * camss_of_parse_ports - Parse ports node
1882 * @notifier: v4l2_device notifier data
1884 * Return number of "port" nodes found in "ports" node
1886 static int camss_of_parse_ports(struct camss *camss)
1888 struct device *dev = camss->dev;
1889 struct device_node *node = NULL;
1890 struct device_node *remote = NULL;
1891 int ret, num_subdevs = 0;
1893 for_each_endpoint_of_node(dev->of_node, node) {
1894 struct camss_async_subdev *csd;
1896 if (!of_device_is_available(node))
1899 remote = of_graph_get_remote_port_parent(node);
1901 dev_err(dev, "Cannot get remote parent\n");
1906 csd = v4l2_async_nf_add_fwnode(&camss->notifier,
1907 of_fwnode_handle(remote),
1908 struct camss_async_subdev);
1909 of_node_put(remote);
1915 ret = camss_of_parse_endpoint_node(dev, node, csd);
1930 * camss_init_subdevices - Initialize subdev structures and resources
1931 * @camss: CAMSS device
1933 * Return 0 on success or a negative error code on failure
1935 static int camss_init_subdevices(struct camss *camss)
1937 struct platform_device *pdev = to_platform_device(camss->dev);
1938 const struct camss_resources *res = camss->res;
1942 for (i = 0; i < camss->res->csiphy_num; i++) {
1943 ret = msm_csiphy_subdev_init(camss, &camss->csiphy[i],
1944 &res->csiphy_res[i], i);
1947 "Failed to init csiphy%d sub-device: %d\n",
1953 /* note: SM8250 requires VFE to be initialized before CSID */
1954 for (i = 0; i < camss->res->vfe_num; i++) {
1955 ret = msm_vfe_subdev_init(camss, &camss->vfe[i],
1956 &res->vfe_res[i], i);
1959 "Fail to init vfe%d sub-device: %d\n", i, ret);
1964 /* Get optional CSID wrapper regs shared between CSID devices */
1965 if (res->csid_wrapper_res) {
1966 char *reg = res->csid_wrapper_res->reg;
1969 base = devm_platform_ioremap_resource_byname(pdev, reg);
1971 return PTR_ERR(base);
1972 camss->csid_wrapper_base = base;
1975 for (i = 0; i < camss->res->csid_num; i++) {
1976 ret = msm_csid_subdev_init(camss, &camss->csid[i],
1977 &res->csid_res[i], i);
1980 "Failed to init csid%d sub-device: %d\n",
1986 ret = msm_ispif_subdev_init(camss, res->ispif_res);
1988 dev_err(camss->dev, "Failed to init ispif sub-device: %d\n",
1997 * camss_link_entities - Register subdev nodes and create links
1998 * @camss: CAMSS device
2000 * Return 0 on success or a negative error code on failure
2002 static int camss_link_entities(struct camss *camss)
2007 for (i = 0; i < camss->res->csiphy_num; i++) {
2008 for (j = 0; j < camss->res->csid_num; j++) {
2009 ret = media_create_pad_link(&camss->csiphy[i].subdev.entity,
2011 &camss->csid[j].subdev.entity,
2016 "Failed to link %s->%s entities: %d\n",
2017 camss->csiphy[i].subdev.entity.name,
2018 camss->csid[j].subdev.entity.name,
2026 for (i = 0; i < camss->res->csid_num; i++) {
2027 for (j = 0; j < camss->ispif->line_num; j++) {
2028 ret = media_create_pad_link(&camss->csid[i].subdev.entity,
2030 &camss->ispif->line[j].subdev.entity,
2035 "Failed to link %s->%s entities: %d\n",
2036 camss->csid[i].subdev.entity.name,
2037 camss->ispif->line[j].subdev.entity.name,
2044 for (i = 0; i < camss->ispif->line_num; i++)
2045 for (k = 0; k < camss->res->vfe_num; k++)
2046 for (j = 0; j < camss->vfe[k].res->line_num; j++) {
2047 struct v4l2_subdev *ispif = &camss->ispif->line[i].subdev;
2048 struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev;
2050 ret = media_create_pad_link(&ispif->entity,
2057 "Failed to link %s->%s entities: %d\n",
2065 for (i = 0; i < camss->res->csid_num; i++)
2066 for (k = 0; k < camss->res->vfe_num; k++)
2067 for (j = 0; j < camss->vfe[k].res->line_num; j++) {
2068 struct v4l2_subdev *csid = &camss->csid[i].subdev;
2069 struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev;
2071 ret = media_create_pad_link(&csid->entity,
2072 MSM_CSID_PAD_FIRST_SRC + j,
2078 "Failed to link %s->%s entities: %d\n",
2091 * camss_register_entities - Register subdev nodes and create links
2092 * @camss: CAMSS device
2094 * Return 0 on success or a negative error code on failure
2096 static int camss_register_entities(struct camss *camss)
2101 for (i = 0; i < camss->res->csiphy_num; i++) {
2102 ret = msm_csiphy_register_entity(&camss->csiphy[i],
2106 "Failed to register csiphy%d entity: %d\n",
2108 goto err_reg_csiphy;
2112 for (i = 0; i < camss->res->csid_num; i++) {
2113 ret = msm_csid_register_entity(&camss->csid[i],
2117 "Failed to register csid%d entity: %d\n",
2123 ret = msm_ispif_register_entities(camss->ispif,
2126 dev_err(camss->dev, "Failed to register ispif entities: %d\n", ret);
2130 for (i = 0; i < camss->res->vfe_num; i++) {
2131 ret = msm_vfe_register_entities(&camss->vfe[i],
2135 "Failed to register vfe%d entities: %d\n",
2144 for (i--; i >= 0; i--)
2145 msm_vfe_unregister_entities(&camss->vfe[i]);
2148 msm_ispif_unregister_entities(camss->ispif);
2150 i = camss->res->csid_num;
2152 for (i--; i >= 0; i--)
2153 msm_csid_unregister_entity(&camss->csid[i]);
2155 i = camss->res->csiphy_num;
2157 for (i--; i >= 0; i--)
2158 msm_csiphy_unregister_entity(&camss->csiphy[i]);
2164 * camss_unregister_entities - Unregister subdev nodes
2165 * @camss: CAMSS device
2167 * Return 0 on success or a negative error code on failure
2169 static void camss_unregister_entities(struct camss *camss)
2173 for (i = 0; i < camss->res->csiphy_num; i++)
2174 msm_csiphy_unregister_entity(&camss->csiphy[i]);
2176 for (i = 0; i < camss->res->csid_num; i++)
2177 msm_csid_unregister_entity(&camss->csid[i]);
2179 msm_ispif_unregister_entities(camss->ispif);
2181 for (i = 0; i < camss->res->vfe_num; i++)
2182 msm_vfe_unregister_entities(&camss->vfe[i]);
2185 static int camss_subdev_notifier_bound(struct v4l2_async_notifier *async,
2186 struct v4l2_subdev *subdev,
2187 struct v4l2_async_connection *asd)
2189 struct camss *camss = container_of(async, struct camss, notifier);
2190 struct camss_async_subdev *csd =
2191 container_of(asd, struct camss_async_subdev, asd);
2192 u8 id = csd->interface.csiphy_id;
2193 struct csiphy_device *csiphy = &camss->csiphy[id];
2195 csiphy->cfg.csi2 = &csd->interface.csi2;
2196 subdev->host_priv = csiphy;
2201 static int camss_subdev_notifier_complete(struct v4l2_async_notifier *async)
2203 struct camss *camss = container_of(async, struct camss, notifier);
2204 struct v4l2_device *v4l2_dev = &camss->v4l2_dev;
2205 struct v4l2_subdev *sd;
2208 list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
2209 if (sd->host_priv) {
2210 struct media_entity *sensor = &sd->entity;
2211 struct csiphy_device *csiphy =
2212 (struct csiphy_device *) sd->host_priv;
2213 struct media_entity *input = &csiphy->subdev.entity;
2216 for (i = 0; i < sensor->num_pads; i++) {
2217 if (sensor->pads[i].flags & MEDIA_PAD_FL_SOURCE)
2220 if (i == sensor->num_pads) {
2222 "No source pad in external entity\n");
2226 ret = media_create_pad_link(sensor, i,
2227 input, MSM_CSIPHY_PAD_SINK,
2228 MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
2231 "Failed to link %s->%s entities: %d\n",
2232 sensor->name, input->name, ret);
2238 ret = v4l2_device_register_subdev_nodes(&camss->v4l2_dev);
2242 return media_device_register(&camss->media_dev);
2245 static const struct v4l2_async_notifier_operations camss_subdev_notifier_ops = {
2246 .bound = camss_subdev_notifier_bound,
2247 .complete = camss_subdev_notifier_complete,
2250 static const struct media_device_ops camss_media_ops = {
2251 .link_notify = v4l2_pipeline_link_notify,
2254 static int camss_configure_pd(struct camss *camss)
2256 const struct camss_resources *res = camss->res;
2257 struct device *dev = camss->dev;
2262 camss->genpd_num = of_count_phandle_with_args(dev->of_node,
2264 "#power-domain-cells");
2265 if (camss->genpd_num < 0) {
2266 dev_err(dev, "Power domains are not defined for camss\n");
2267 return camss->genpd_num;
2271 * If a platform device has just one power domain, then it is attached
2272 * at platform_probe() level, thus there shall be no need and even no
2273 * option to attach it again, this is the case for CAMSS on MSM8916.
2275 if (camss->genpd_num == 1)
2278 /* count the # of VFEs which have flagged power-domain */
2279 for (vfepd_num = i = 0; i < camss->res->vfe_num; i++) {
2280 if (res->vfe_res[i].vfe.has_pd)
2285 * If the number of power-domains is greater than the number of VFEs
2286 * then the additional power-domain is for the entire CAMSS block.
2288 if (!(camss->genpd_num > vfepd_num))
2292 * If a power-domain name is defined try to use it.
2293 * It is possible we are running a new kernel with an old dtb so
2294 * fallback to indexes even if a pd_name is defined but not found.
2296 if (camss->res->pd_name) {
2297 camss->genpd = dev_pm_domain_attach_by_name(camss->dev,
2298 camss->res->pd_name);
2299 if (IS_ERR(camss->genpd))
2300 return PTR_ERR(camss->genpd);
2303 if (!camss->genpd) {
2305 * Legacy magic index. TITAN_TOP GDSC must be the last
2306 * item in the power-domain list.
2308 camss->genpd = dev_pm_domain_attach_by_id(camss->dev,
2309 camss->genpd_num - 1);
2310 if (IS_ERR(camss->genpd))
2311 return PTR_ERR(camss->genpd);
2317 camss->genpd_link = device_link_add(camss->dev, camss->genpd,
2318 DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
2319 DL_FLAG_RPM_ACTIVE);
2320 if (!camss->genpd_link) {
2328 dev_pm_domain_detach(camss->genpd, true);
2333 static int camss_icc_get(struct camss *camss)
2335 const struct resources_icc *icc_res;
2338 icc_res = camss->res->icc_res;
2340 for (i = 0; i < camss->res->icc_path_num; i++) {
2341 camss->icc_path[i] = devm_of_icc_get(camss->dev,
2343 if (IS_ERR(camss->icc_path[i]))
2344 return PTR_ERR(camss->icc_path[i]);
2350 static void camss_genpd_subdevice_cleanup(struct camss *camss)
2354 for (i = 0; i < camss->res->vfe_num; i++)
2355 msm_vfe_genpd_cleanup(&camss->vfe[i]);
2358 static void camss_genpd_cleanup(struct camss *camss)
2360 if (camss->genpd_num == 1)
2363 camss_genpd_subdevice_cleanup(camss);
2365 if (camss->genpd_link)
2366 device_link_del(camss->genpd_link);
2368 dev_pm_domain_detach(camss->genpd, true);
2372 * camss_probe - Probe CAMSS platform device
2373 * @pdev: Pointer to CAMSS platform device
2375 * Return 0 on success or a negative error code on failure
2377 static int camss_probe(struct platform_device *pdev)
2379 struct device *dev = &pdev->dev;
2380 struct camss *camss;
2384 camss = devm_kzalloc(dev, sizeof(*camss), GFP_KERNEL);
2388 camss->res = of_device_get_match_data(dev);
2390 atomic_set(&camss->ref_count, 0);
2392 platform_set_drvdata(pdev, camss);
2394 camss->csiphy = devm_kcalloc(dev, camss->res->csiphy_num,
2395 sizeof(*camss->csiphy), GFP_KERNEL);
2399 camss->csid = devm_kcalloc(dev, camss->res->csid_num, sizeof(*camss->csid),
2404 if (camss->res->version == CAMSS_8x16 ||
2405 camss->res->version == CAMSS_8x53 ||
2406 camss->res->version == CAMSS_8x96) {
2407 camss->ispif = devm_kcalloc(dev, 1, sizeof(*camss->ispif), GFP_KERNEL);
2412 camss->vfe = devm_kcalloc(dev, camss->res->vfe_num,
2413 sizeof(*camss->vfe), GFP_KERNEL);
2417 ret = camss_icc_get(camss);
2421 ret = camss_configure_pd(camss);
2423 dev_err(dev, "Failed to configure power domains: %d\n", ret);
2427 ret = camss_init_subdevices(camss);
2429 goto err_genpd_cleanup;
2431 ret = dma_set_mask_and_coherent(dev, 0xffffffff);
2433 goto err_genpd_cleanup;
2435 camss->media_dev.dev = camss->dev;
2436 strscpy(camss->media_dev.model, "Qualcomm Camera Subsystem",
2437 sizeof(camss->media_dev.model));
2438 camss->media_dev.ops = &camss_media_ops;
2439 media_device_init(&camss->media_dev);
2441 camss->v4l2_dev.mdev = &camss->media_dev;
2442 ret = v4l2_device_register(camss->dev, &camss->v4l2_dev);
2444 dev_err(dev, "Failed to register V4L2 device: %d\n", ret);
2445 goto err_genpd_cleanup;
2448 v4l2_async_nf_init(&camss->notifier, &camss->v4l2_dev);
2450 pm_runtime_enable(dev);
2452 num_subdevs = camss_of_parse_ports(camss);
2453 if (num_subdevs < 0) {
2455 goto err_v4l2_device_unregister;
2458 ret = camss_register_entities(camss);
2460 goto err_v4l2_device_unregister;
2462 ret = camss->res->link_entities(camss);
2464 goto err_register_subdevs;
2467 camss->notifier.ops = &camss_subdev_notifier_ops;
2469 ret = v4l2_async_nf_register(&camss->notifier);
2472 "Failed to register async subdev nodes: %d\n",
2474 goto err_register_subdevs;
2477 ret = v4l2_device_register_subdev_nodes(&camss->v4l2_dev);
2479 dev_err(dev, "Failed to register subdev nodes: %d\n",
2481 goto err_register_subdevs;
2484 ret = media_device_register(&camss->media_dev);
2486 dev_err(dev, "Failed to register media device: %d\n",
2488 goto err_register_subdevs;
2494 err_register_subdevs:
2495 camss_unregister_entities(camss);
2496 err_v4l2_device_unregister:
2497 v4l2_device_unregister(&camss->v4l2_dev);
2498 v4l2_async_nf_cleanup(&camss->notifier);
2499 pm_runtime_disable(dev);
2501 camss_genpd_cleanup(camss);
2506 void camss_delete(struct camss *camss)
2508 v4l2_device_unregister(&camss->v4l2_dev);
2509 media_device_unregister(&camss->media_dev);
2510 media_device_cleanup(&camss->media_dev);
2512 pm_runtime_disable(camss->dev);
2516 * camss_remove - Remove CAMSS platform device
2517 * @pdev: Pointer to CAMSS platform device
2521 static void camss_remove(struct platform_device *pdev)
2523 struct camss *camss = platform_get_drvdata(pdev);
2525 v4l2_async_nf_unregister(&camss->notifier);
2526 v4l2_async_nf_cleanup(&camss->notifier);
2527 camss_unregister_entities(camss);
2529 if (atomic_read(&camss->ref_count) == 0)
2530 camss_delete(camss);
2532 camss_genpd_cleanup(camss);
2535 static const struct camss_resources msm8916_resources = {
2536 .version = CAMSS_8x16,
2537 .csiphy_res = csiphy_res_8x16,
2538 .csid_res = csid_res_8x16,
2539 .ispif_res = &ispif_res_8x16,
2540 .vfe_res = vfe_res_8x16,
2541 .csiphy_num = ARRAY_SIZE(csiphy_res_8x16),
2542 .csid_num = ARRAY_SIZE(csid_res_8x16),
2543 .vfe_num = ARRAY_SIZE(vfe_res_8x16),
2544 .link_entities = camss_link_entities
2547 static const struct camss_resources msm8953_resources = {
2548 .version = CAMSS_8x53,
2549 .icc_res = icc_res_8x53,
2550 .icc_path_num = ARRAY_SIZE(icc_res_8x53),
2551 .csiphy_res = csiphy_res_8x96,
2552 .csid_res = csid_res_8x53,
2553 .ispif_res = &ispif_res_8x53,
2554 .vfe_res = vfe_res_8x53,
2555 .csiphy_num = ARRAY_SIZE(csiphy_res_8x96),
2556 .csid_num = ARRAY_SIZE(csid_res_8x53),
2557 .vfe_num = ARRAY_SIZE(vfe_res_8x53),
2558 .link_entities = camss_link_entities
2561 static const struct camss_resources msm8996_resources = {
2562 .version = CAMSS_8x96,
2563 .csiphy_res = csiphy_res_8x96,
2564 .csid_res = csid_res_8x96,
2565 .ispif_res = &ispif_res_8x96,
2566 .vfe_res = vfe_res_8x96,
2567 .csiphy_num = ARRAY_SIZE(csiphy_res_8x96),
2568 .csid_num = ARRAY_SIZE(csid_res_8x96),
2569 .vfe_num = ARRAY_SIZE(vfe_res_8x96),
2570 .link_entities = camss_link_entities
2573 static const struct camss_resources sdm660_resources = {
2574 .version = CAMSS_660,
2575 .csiphy_res = csiphy_res_660,
2576 .csid_res = csid_res_660,
2577 .ispif_res = &ispif_res_660,
2578 .vfe_res = vfe_res_660,
2579 .csiphy_num = ARRAY_SIZE(csiphy_res_660),
2580 .csid_num = ARRAY_SIZE(csid_res_660),
2581 .vfe_num = ARRAY_SIZE(vfe_res_660),
2582 .link_entities = camss_link_entities
2585 static const struct camss_resources sdm845_resources = {
2586 .version = CAMSS_845,
2587 .csiphy_res = csiphy_res_845,
2588 .csid_res = csid_res_845,
2589 .vfe_res = vfe_res_845,
2590 .csiphy_num = ARRAY_SIZE(csiphy_res_845),
2591 .csid_num = ARRAY_SIZE(csid_res_845),
2592 .vfe_num = ARRAY_SIZE(vfe_res_845),
2593 .link_entities = camss_link_entities
2596 static const struct camss_resources sm8250_resources = {
2597 .version = CAMSS_8250,
2599 .csiphy_res = csiphy_res_8250,
2600 .csid_res = csid_res_8250,
2601 .vfe_res = vfe_res_8250,
2602 .icc_res = icc_res_sm8250,
2603 .icc_path_num = ARRAY_SIZE(icc_res_sm8250),
2604 .csiphy_num = ARRAY_SIZE(csiphy_res_8250),
2605 .csid_num = ARRAY_SIZE(csid_res_8250),
2606 .vfe_num = ARRAY_SIZE(vfe_res_8250),
2607 .link_entities = camss_link_entities
2610 static const struct camss_resources sc8280xp_resources = {
2611 .version = CAMSS_8280XP,
2613 .csiphy_res = csiphy_res_sc8280xp,
2614 .csid_res = csid_res_sc8280xp,
2616 .vfe_res = vfe_res_sc8280xp,
2617 .icc_res = icc_res_sc8280xp,
2618 .icc_path_num = ARRAY_SIZE(icc_res_sc8280xp),
2619 .csiphy_num = ARRAY_SIZE(csiphy_res_sc8280xp),
2620 .csid_num = ARRAY_SIZE(csid_res_sc8280xp),
2621 .vfe_num = ARRAY_SIZE(vfe_res_sc8280xp),
2622 .link_entities = camss_link_entities
2625 static const struct of_device_id camss_dt_match[] = {
2626 { .compatible = "qcom,msm8916-camss", .data = &msm8916_resources },
2627 { .compatible = "qcom,msm8953-camss", .data = &msm8953_resources },
2628 { .compatible = "qcom,msm8996-camss", .data = &msm8996_resources },
2629 { .compatible = "qcom,sdm660-camss", .data = &sdm660_resources },
2630 { .compatible = "qcom,sdm845-camss", .data = &sdm845_resources },
2631 { .compatible = "qcom,sm8250-camss", .data = &sm8250_resources },
2632 { .compatible = "qcom,sc8280xp-camss", .data = &sc8280xp_resources },
2636 MODULE_DEVICE_TABLE(of, camss_dt_match);
2638 static int __maybe_unused camss_runtime_suspend(struct device *dev)
2640 struct camss *camss = dev_get_drvdata(dev);
2644 for (i = 0; i < camss->res->icc_path_num; i++) {
2645 ret = icc_set_bw(camss->icc_path[i], 0, 0);
2653 static int __maybe_unused camss_runtime_resume(struct device *dev)
2655 struct camss *camss = dev_get_drvdata(dev);
2656 const struct resources_icc *icc_res = camss->res->icc_res;
2660 for (i = 0; i < camss->res->icc_path_num; i++) {
2661 ret = icc_set_bw(camss->icc_path[i],
2662 icc_res[i].icc_bw_tbl.avg,
2663 icc_res[i].icc_bw_tbl.peak);
2671 static const struct dev_pm_ops camss_pm_ops = {
2672 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2673 pm_runtime_force_resume)
2674 SET_RUNTIME_PM_OPS(camss_runtime_suspend, camss_runtime_resume, NULL)
2677 static struct platform_driver qcom_camss_driver = {
2678 .probe = camss_probe,
2679 .remove = camss_remove,
2681 .name = "qcom-camss",
2682 .of_match_table = camss_dt_match,
2683 .pm = &camss_pm_ops,
2687 module_platform_driver(qcom_camss_driver);
2689 MODULE_ALIAS("platform:qcom-camss");
2690 MODULE_DESCRIPTION("Qualcomm Camera Subsystem driver");
2692 MODULE_LICENSE("GPL v2");