mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
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>
This commit is contained in:
committed by
Dom Cobley
parent
62d5cd41ee
commit
cbc60ec97d
@@ -90,6 +90,11 @@ MODULE_PARM_DESC(debug, "Debug level 0-3");
|
|||||||
#define unicam_err(dev, fmt, arg...) \
|
#define unicam_err(dev, fmt, arg...) \
|
||||||
v4l2_err(&(dev)->v4l2_dev, fmt, ##arg)
|
v4l2_err(&(dev)->v4l2_dev, fmt, ##arg)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unicam must request a minimum of 250Mhz from the VPU clock.
|
||||||
|
* Otherwise the input FIFOs overrun and cause image corruption.
|
||||||
|
*/
|
||||||
|
#define MIN_VPU_CLOCK_RATE (250 * 1000 * 1000)
|
||||||
/*
|
/*
|
||||||
* To protect against a dodgy sensor driver never returning an error from
|
* To protect against a dodgy sensor driver never returning an error from
|
||||||
* enum_mbus_code, set a maximum index value to be used.
|
* enum_mbus_code, set a maximum index value to be used.
|
||||||
@@ -419,8 +424,10 @@ struct unicam_device {
|
|||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
/* clock gating base address */
|
/* clock gating base address */
|
||||||
void __iomem *clk_gate_base;
|
void __iomem *clk_gate_base;
|
||||||
/* clock handle */
|
/* lp clock handle */
|
||||||
struct clk *clock;
|
struct clk *clock;
|
||||||
|
/* vpu clock handle */
|
||||||
|
struct clk *vpu_clock;
|
||||||
/* V4l2 device */
|
/* V4l2 device */
|
||||||
struct v4l2_device v4l2_dev;
|
struct v4l2_device v4l2_dev;
|
||||||
struct media_device mdev;
|
struct media_device mdev;
|
||||||
@@ -1680,16 +1687,28 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
|
|||||||
unicam_dbg(1, dev, "Running with %u data lanes\n",
|
unicam_dbg(1, dev, "Running with %u data lanes\n",
|
||||||
dev->active_data_lanes);
|
dev->active_data_lanes);
|
||||||
|
|
||||||
|
ret = clk_set_min_rate(dev->vpu_clock, MIN_VPU_CLOCK_RATE);
|
||||||
|
if (ret) {
|
||||||
|
unicam_err(dev, "failed to set up VPU clock\n");
|
||||||
|
goto err_pm_put;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = clk_prepare_enable(dev->vpu_clock);
|
||||||
|
if (ret) {
|
||||||
|
unicam_err(dev, "Failed to enable VPU clock: %d\n", ret);
|
||||||
|
goto err_pm_put;
|
||||||
|
}
|
||||||
|
|
||||||
ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
|
ret = clk_set_rate(dev->clock, 100 * 1000 * 1000);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
unicam_err(dev, "failed to set up clock\n");
|
unicam_err(dev, "failed to set up CSI clock\n");
|
||||||
goto err_pm_put;
|
goto err_vpu_clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = clk_prepare_enable(dev->clock);
|
ret = clk_prepare_enable(dev->clock);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
unicam_err(dev, "Failed to enable CSI clock: %d\n", ret);
|
unicam_err(dev, "Failed to enable CSI clock: %d\n", ret);
|
||||||
goto err_pm_put;
|
goto err_vpu_clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(dev->node); i++) {
|
for (i = 0; i < ARRAY_SIZE(dev->node); i++) {
|
||||||
@@ -1723,6 +1742,11 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
|
|||||||
err_disable_unicam:
|
err_disable_unicam:
|
||||||
unicam_disable(dev);
|
unicam_disable(dev);
|
||||||
clk_disable_unprepare(dev->clock);
|
clk_disable_unprepare(dev->clock);
|
||||||
|
err_vpu_clock:
|
||||||
|
ret = clk_set_min_rate(dev->vpu_clock, 0);
|
||||||
|
if (ret)
|
||||||
|
unicam_err(dev, "failed to reset the VPU clock\n");
|
||||||
|
clk_disable_unprepare(dev->vpu_clock);
|
||||||
err_pm_put:
|
err_pm_put:
|
||||||
unicam_runtime_put(dev);
|
unicam_runtime_put(dev);
|
||||||
err_streaming:
|
err_streaming:
|
||||||
@@ -1740,6 +1764,8 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
|
|||||||
node->streaming = false;
|
node->streaming = false;
|
||||||
|
|
||||||
if (node->pad_id == IMAGE_PAD) {
|
if (node->pad_id == IMAGE_PAD) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop streaming the sensor and disable the peripheral.
|
* Stop streaming the sensor and disable the peripheral.
|
||||||
* We cannot continue streaming embedded data with the
|
* We cannot continue streaming embedded data with the
|
||||||
@@ -1749,6 +1775,12 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
|
|||||||
unicam_err(dev, "stream off failed in subdev\n");
|
unicam_err(dev, "stream off failed in subdev\n");
|
||||||
|
|
||||||
unicam_disable(dev);
|
unicam_disable(dev);
|
||||||
|
|
||||||
|
ret = clk_set_min_rate(dev->vpu_clock, 0);
|
||||||
|
if (ret)
|
||||||
|
unicam_err(dev, "failed to reset the min VPU clock\n");
|
||||||
|
|
||||||
|
clk_disable_unprepare(dev->vpu_clock);
|
||||||
clk_disable_unprepare(dev->clock);
|
clk_disable_unprepare(dev->clock);
|
||||||
unicam_runtime_put(dev);
|
unicam_runtime_put(dev);
|
||||||
|
|
||||||
@@ -2752,11 +2784,18 @@ static int unicam_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
unicam->clock = devm_clk_get(&pdev->dev, "lp");
|
unicam->clock = devm_clk_get(&pdev->dev, "lp");
|
||||||
if (IS_ERR(unicam->clock)) {
|
if (IS_ERR(unicam->clock)) {
|
||||||
unicam_err(unicam, "Failed to get clock\n");
|
unicam_err(unicam, "Failed to get lp clock\n");
|
||||||
ret = PTR_ERR(unicam->clock);
|
ret = PTR_ERR(unicam->clock);
|
||||||
goto err_unicam_put;
|
goto err_unicam_put;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unicam->vpu_clock = devm_clk_get(&pdev->dev, "vpu");
|
||||||
|
if (IS_ERR(unicam->vpu_clock)) {
|
||||||
|
unicam_err(unicam, "Failed to get vpu clock\n");
|
||||||
|
ret = PTR_ERR(unicam->vpu_clock);
|
||||||
|
goto err_unicam_put;
|
||||||
|
}
|
||||||
|
|
||||||
ret = platform_get_irq(pdev, 0);
|
ret = platform_get_irq(pdev, 0);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
dev_err(&pdev->dev, "No IRQ resource\n");
|
dev_err(&pdev->dev, "No IRQ resource\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user