86a1208fa6f29f2476109c619d5ec29fd5adafed
[openwrt/staging/blogic.git] /
1 From bf30883473f0d25fa7614d53022c20330d840aa0 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Mon, 11 May 2020 13:02:22 +0100
4 Subject: [PATCH] media: bcm2835: unicam: Set VPU min clock freq to
5 250Mhz.
6
7 When streaming with Unicam, the VPU must have a clock frequency of at
8 least 250Mhz. Otherwise, the input fifos could overrun, causing
9 image corruption.
10
11 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
12 ---
13 .../media/platform/bcm2835/bcm2835-unicam.c | 49 +++++++++++++++++--
14 1 file changed, 44 insertions(+), 5 deletions(-)
15
16 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
17 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
18 @@ -89,6 +89,11 @@ MODULE_PARM_DESC(debug, "Debug level 0-3
19 v4l2_err(&(dev)->v4l2_dev, fmt, ##arg)
20
21 /*
22 + * Unicam must request a minimum of 250Mhz from the VPU clock.
23 + * Otherwise the input FIFOs overrun and cause image corruption.
24 + */
25 +#define MIN_VPU_CLOCK_RATE (250 * 1000 * 1000)
26 +/*
27 * To protect against a dodgy sensor driver never returning an error from
28 * enum_mbus_code, set a maximum index value to be used.
29 */
30 @@ -417,8 +422,10 @@ struct unicam_device {
31 void __iomem *base;
32 /* clock gating base address */
33 void __iomem *clk_gate_base;
34 - /* clock handle */
35 + /* lp clock handle */
36 struct clk *clock;
37 + /* vpu clock handle */
38 + struct clk *vpu_clock;
39 /* V4l2 device */
40 struct v4l2_device v4l2_dev;
41 struct media_device mdev;
42 @@ -1678,16 +1685,28 @@ static int unicam_start_streaming(struct
43 unicam_dbg(1, dev, "Running with %u data lanes\n",
44 dev->active_data_lanes);
45
46 - ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
47 + ret = clk_set_min_rate(dev->vpu_clock, MIN_VPU_CLOCK_RATE);
48 + if (ret) {
49 + unicam_err(dev, "failed to set up VPU clock\n");
50 + goto err_pm_put;
51 + }
52 +
53 + ret = clk_prepare_enable(dev->vpu_clock);
54 if (ret) {
55 - unicam_err(dev, "failed to set up clock\n");
56 + unicam_err(dev, "Failed to enable VPU clock: %d\n", ret);
57 goto err_pm_put;
58 }
59
60 + ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
61 + if (ret) {
62 + unicam_err(dev, "failed to set up CSI clock\n");
63 + goto err_vpu_clock;
64 + }
65 +
66 ret = clk_prepare_enable(dev->clock);
67 if (ret) {
68 unicam_err(dev, "Failed to enable CSI clock: %d\n", ret);
69 - goto err_pm_put;
70 + goto err_vpu_clock;
71 }
72
73 for (i = 0; i < ARRAY_SIZE(dev->node); i++) {
74 @@ -1721,6 +1740,11 @@ static int unicam_start_streaming(struct
75 err_disable_unicam:
76 unicam_disable(dev);
77 clk_disable_unprepare(dev->clock);
78 +err_vpu_clock:
79 + ret = clk_set_min_rate(dev->vpu_clock, 0);
80 + if (ret)
81 + unicam_err(dev, "failed to reset the VPU clock\n");
82 + clk_disable_unprepare(dev->vpu_clock);
83 err_pm_put:
84 unicam_runtime_put(dev);
85 err_streaming:
86 @@ -1738,6 +1762,8 @@ static void unicam_stop_streaming(struct
87 node->streaming = false;
88
89 if (node->pad_id == IMAGE_PAD) {
90 + int ret;
91 +
92 /*
93 * Stop streaming the sensor and disable the peripheral.
94 * We cannot continue streaming embedded data with the
95 @@ -1747,6 +1773,12 @@ static void unicam_stop_streaming(struct
96 unicam_err(dev, "stream off failed in subdev\n");
97
98 unicam_disable(dev);
99 +
100 + ret = clk_set_min_rate(dev->vpu_clock, 0);
101 + if (ret)
102 + unicam_err(dev, "failed to reset the min VPU clock\n");
103 +
104 + clk_disable_unprepare(dev->vpu_clock);
105 clk_disable_unprepare(dev->clock);
106 unicam_runtime_put(dev);
107
108 @@ -2750,11 +2782,18 @@ static int unicam_probe(struct platform_
109
110 unicam->clock = devm_clk_get(&pdev->dev, "lp");
111 if (IS_ERR(unicam->clock)) {
112 - unicam_err(unicam, "Failed to get clock\n");
113 + unicam_err(unicam, "Failed to get lp clock\n");
114 ret = PTR_ERR(unicam->clock);
115 goto err_unicam_put;
116 }
117
118 + unicam->vpu_clock = devm_clk_get(&pdev->dev, "vpu");
119 + if (IS_ERR(unicam->vpu_clock)) {
120 + unicam_err(unicam, "Failed to get vpu clock\n");
121 + ret = PTR_ERR(unicam->vpu_clock);
122 + goto err_unicam_put;
123 + }
124 +
125 ret = platform_get_irq(pdev, 0);
126 if (ret <= 0) {
127 dev_err(&pdev->dev, "No IRQ resource\n");