Skip to content

Commit 861e506

Browse files
naushirpopcornmix
authored andcommitted
media: bcm2835: unicam: Set VPU min clock freq to 250Mhz.
When streaming with Unicam, the VPU must have a clock frequency of at least 250Mhz. Otherwise, the input fifos could overrun, causing image corruption. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent d7f56d3 commit 861e506

2 files changed

Lines changed: 50 additions & 9 deletions

File tree

‎arch/arm/boot/dts/bcm270x.dtsi‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@
8888
reg = <0x7e800000 0x800>,
8989
<0x7e802000 0x4>;
9090
interrupts = <2 6>;
91-
clocks = <&clocks BCM2835_CLOCK_CAM0>;
92-
clock-names = "lp";
91+
clocks = <&clocks BCM2835_CLOCK_CAM0>,
92+
<&firmware_clocks 4>;
93+
clock-names = "lp", "vpu";
9394
power-domains = <&power RPI_POWER_DOMAIN_UNICAM0>;
9495
#address-cells = <1>;
9596
#size-cells = <0>;
@@ -102,8 +103,9 @@
102103
reg = <0x7e801000 0x800>,
103104
<0x7e802004 0x4>;
104105
interrupts = <2 7>;
105-
clocks = <&clocks BCM2835_CLOCK_CAM1>;
106-
clock-names = "lp";
106+
clocks = <&clocks BCM2835_CLOCK_CAM1>,
107+
<&firmware_clocks 4>;
108+
clock-names = "lp", "vpu";
107109
power-domains = <&power RPI_POWER_DOMAIN_UNICAM1>;
108110
#address-cells = <1>;
109111
#size-cells = <0>;

‎drivers/media/platform/bcm2835/bcm2835-unicam.c‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ MODULE_PARM_DESC(debug, "Debug level 0-3");
8888
#define unicam_err(dev, fmt, arg...) \
8989
v4l2_err(&(dev)->v4l2_dev, fmt, ##arg)
9090

91+
/*
92+
* Unicam must request a minimum of 250Mhz from the VPU clock.
93+
* Otherwise the input FIFOs overrun and cause image corruption.
94+
*/
95+
#define MIN_VPU_CLOCK_RATE (250 * 1000 * 1000)
9196
/*
9297
* To protect against a dodgy sensor driver never returning an error from
9398
* enum_mbus_code, set a maximum index value to be used.
@@ -417,8 +422,10 @@ struct unicam_device {
417422
void __iomem *base;
418423
/* clock gating base address */
419424
void __iomem *clk_gate_base;
420-
/* clock handle */
425+
/* lp clock handle */
421426
struct clk *clock;
427+
/* vpu clock handle */
428+
struct clk *vpu_clock;
422429
/* V4l2 device */
423430
struct v4l2_device v4l2_dev;
424431
struct media_device mdev;
@@ -1678,16 +1685,28 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
16781685
unicam_dbg(1, dev, "Running with %u data lanes\n",
16791686
dev->active_data_lanes);
16801687

1681-
ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
1688+
ret = clk_set_min_rate(dev->vpu_clock, MIN_VPU_CLOCK_RATE);
1689+
if (ret) {
1690+
unicam_err(dev, "failed to set up VPU clock\n");
1691+
goto err_pm_put;
1692+
}
1693+
1694+
ret = clk_prepare_enable(dev->vpu_clock);
16821695
if (ret) {
1683-
unicam_err(dev, "failed to set up clock\n");
1696+
unicam_err(dev, "Failed to enable VPU clock: %d\n", ret);
16841697
goto err_pm_put;
16851698
}
16861699

1700+
ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
1701+
if (ret) {
1702+
unicam_err(dev, "failed to set up CSI clock\n");
1703+
goto err_vpu_clock;
1704+
}
1705+
16871706
ret = clk_prepare_enable(dev->clock);
16881707
if (ret) {
16891708
unicam_err(dev, "Failed to enable CSI clock: %d\n", ret);
1690-
goto err_pm_put;
1709+
goto err_vpu_clock;
16911710
}
16921711

16931712
for (i = 0; i < ARRAY_SIZE(dev->node); i++) {
@@ -1721,6 +1740,11 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
17211740
err_disable_unicam:
17221741
unicam_disable(dev);
17231742
clk_disable_unprepare(dev->clock);
1743+
err_vpu_clock:
1744+
ret = clk_set_min_rate(dev->vpu_clock, 0);
1745+
if (ret)
1746+
unicam_err(dev, "failed to reset the VPU clock\n");
1747+
clk_disable_unprepare(dev->vpu_clock);
17241748
err_pm_put:
17251749
unicam_runtime_put(dev);
17261750
err_streaming:
@@ -1738,6 +1762,8 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
17381762
node->streaming = false;
17391763

17401764
if (node->pad_id == IMAGE_PAD) {
1765+
int ret;
1766+
17411767
/*
17421768
* Stop streaming the sensor and disable the peripheral.
17431769
* We cannot continue streaming embedded data with the
@@ -1747,6 +1773,12 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
17471773
unicam_err(dev, "stream off failed in subdev\n");
17481774

17491775
unicam_disable(dev);
1776+
1777+
ret = clk_set_min_rate(dev->vpu_clock, 0);
1778+
if (ret)
1779+
unicam_err(dev, "failed to reset the min VPU clock\n");
1780+
1781+
clk_disable_unprepare(dev->vpu_clock);
17501782
clk_disable_unprepare(dev->clock);
17511783
unicam_runtime_put(dev);
17521784

@@ -2750,11 +2782,18 @@ static int unicam_probe(struct platform_device *pdev)
27502782

27512783
unicam->clock = devm_clk_get(&pdev->dev, "lp");
27522784
if (IS_ERR(unicam->clock)) {
2753-
unicam_err(unicam, "Failed to get clock\n");
2785+
unicam_err(unicam, "Failed to get lp clock\n");
27542786
ret = PTR_ERR(unicam->clock);
27552787
goto err_unicam_put;
27562788
}
27572789

2790+
unicam->vpu_clock = devm_clk_get(&pdev->dev, "vpu");
2791+
if (IS_ERR(unicam->vpu_clock)) {
2792+
unicam_err(unicam, "Failed to get vpu clock\n");
2793+
ret = PTR_ERR(unicam->vpu_clock);
2794+
goto err_unicam_put;
2795+
}
2796+
27582797
ret = platform_get_irq(pdev, 0);
27592798
if (ret <= 0) {
27602799
dev_err(&pdev->dev, "No IRQ resource\n");

0 commit comments

Comments
 (0)