Skip to content

Commit 657eee7

Browse files
pH5torvalds
authored andcommitted
media: coda: use genalloc API
This patch depends on "genalloc: add devres support, allow to find a managed pool by device", which provides the of_get_named_gen_pool and dev_get_gen_pool functions. Signed-off-by: Philipp Zabel <[email protected]> Acked-by: Javier Martin <[email protected]> Acked-by: Grant Likely <[email protected]> Cc: Michal Simek <[email protected]> Cc: Dong Aisheng <[email protected]> Cc: Fabio Estevam <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Huang Shijie <[email protected]> Cc: Matt Porter <[email protected]> Cc: Paul Gortmaker <[email protected]> Cc: Rob Herring <[email protected]> Cc: Shawn Guo <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4984c6f commit 657eee7

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Chips&Media Coda multi-standard codec IP
2+
========================================
3+
4+
Coda codec IPs are present in i.MX SoCs in various versions,
5+
called VPU (Video Processing Unit).
6+
7+
Required properties:
8+
- compatible : should be "fsl,<chip>-src" for i.MX SoCs:
9+
(a) "fsl,imx27-vpu" for CodaDx6 present in i.MX27
10+
(b) "fsl,imx53-vpu" for CODA7541 present in i.MX53
11+
(c) "fsl,imx6q-vpu" for CODA960 present in i.MX6q
12+
- reg: should be register base and length as documented in the
13+
SoC reference manual
14+
- interrupts : Should contain the VPU interrupt. For CODA960,
15+
a second interrupt is needed for the MJPEG unit.
16+
- clocks : Should contain the ahb and per clocks, in the order
17+
determined by the clock-names property.
18+
- clock-names : Should be "ahb", "per"
19+
- iram : phandle pointing to the SRAM device node
20+
21+
Example:
22+
23+
vpu: vpu@63ff4000 {
24+
compatible = "fsl,imx53-vpu";
25+
reg = <0x63ff4000 0x1000>;
26+
interrupts = <9>;
27+
clocks = <&clks 63>, <&clks 63>;
28+
clock-names = "ahb", "per";
29+
iram = <&ocram>;
30+
};

drivers/media/platform/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ config VIDEO_CODA
145145
depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC
146146
select VIDEOBUF2_DMA_CONTIG
147147
select V4L2_MEM2MEM_DEV
148-
select IRAM_ALLOC if SOC_IMX53
149148
---help---
150149
Coda is a range of video codec IPs that supports
151150
H.264, MPEG-4, and other video formats.

drivers/media/platform/coda.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/clk.h>
1515
#include <linux/delay.h>
1616
#include <linux/firmware.h>
17+
#include <linux/genalloc.h>
1718
#include <linux/interrupt.h>
1819
#include <linux/io.h>
1920
#include <linux/irq.h>
@@ -23,7 +24,7 @@
2324
#include <linux/slab.h>
2425
#include <linux/videodev2.h>
2526
#include <linux/of.h>
26-
#include <linux/platform_data/imx-iram.h>
27+
#include <linux/platform_data/coda.h>
2728

2829
#include <media/v4l2-ctrls.h>
2930
#include <media/v4l2-device.h>
@@ -43,6 +44,7 @@
4344
#define CODA7_WORK_BUF_SIZE (512 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024)
4445
#define CODA_PARA_BUF_SIZE (10 * 1024)
4546
#define CODA_ISRAM_SIZE (2048 * 2)
47+
#define CODADX6_IRAM_SIZE 0xb000
4648
#define CODA7_IRAM_SIZE 0x14000 /* 81920 bytes */
4749

4850
#define CODA_MAX_FRAMEBUFFERS 2
@@ -128,7 +130,10 @@ struct coda_dev {
128130

129131
struct coda_aux_buf codebuf;
130132
struct coda_aux_buf workbuf;
133+
struct gen_pool *iram_pool;
134+
long unsigned int iram_vaddr;
131135
long unsigned int iram_paddr;
136+
unsigned long iram_size;
132137

133138
spinlock_t irqlock;
134139
struct mutex dev_mutex;
@@ -1926,6 +1931,9 @@ static int coda_probe(struct platform_device *pdev)
19261931
const struct of_device_id *of_id =
19271932
of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev);
19281933
const struct platform_device_id *pdev_id;
1934+
struct coda_platform_data *pdata = pdev->dev.platform_data;
1935+
struct device_node *np = pdev->dev.of_node;
1936+
struct gen_pool *pool;
19291937
struct coda_dev *dev;
19301938
struct resource *res;
19311939
int ret, irq;
@@ -1988,6 +1996,16 @@ static int coda_probe(struct platform_device *pdev)
19881996
return -ENOENT;
19891997
}
19901998

1999+
/* Get IRAM pool from device tree or platform data */
2000+
pool = of_get_named_gen_pool(np, "iram", 0);
2001+
if (!pool && pdata)
2002+
pool = dev_get_gen_pool(pdata->iram_dev);
2003+
if (!pool) {
2004+
dev_err(&pdev->dev, "iram pool not available\n");
2005+
return -ENOMEM;
2006+
}
2007+
dev->iram_pool = pool;
2008+
19912009
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
19922010
if (ret)
19932011
return ret;
@@ -2022,18 +2040,17 @@ static int coda_probe(struct platform_device *pdev)
20222040
return -ENOMEM;
20232041
}
20242042

2025-
if (dev->devtype->product == CODA_DX6) {
2026-
dev->iram_paddr = 0xffff4c00;
2027-
} else {
2028-
void __iomem *iram_vaddr;
2029-
2030-
iram_vaddr = iram_alloc(CODA7_IRAM_SIZE,
2031-
&dev->iram_paddr);
2032-
if (!iram_vaddr) {
2033-
dev_err(&pdev->dev, "unable to alloc iram\n");
2034-
return -ENOMEM;
2035-
}
2043+
if (dev->devtype->product == CODA_DX6)
2044+
dev->iram_size = CODADX6_IRAM_SIZE;
2045+
else
2046+
dev->iram_size = CODA7_IRAM_SIZE;
2047+
dev->iram_vaddr = gen_pool_alloc(dev->iram_pool, dev->iram_size);
2048+
if (!dev->iram_vaddr) {
2049+
dev_err(&pdev->dev, "unable to alloc iram\n");
2050+
return -ENOMEM;
20362051
}
2052+
dev->iram_paddr = gen_pool_virt_to_phys(dev->iram_pool,
2053+
dev->iram_vaddr);
20372054

20382055
platform_set_drvdata(pdev, dev);
20392056

@@ -2050,8 +2067,8 @@ static int coda_remove(struct platform_device *pdev)
20502067
if (dev->alloc_ctx)
20512068
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
20522069
v4l2_device_unregister(&dev->v4l2_dev);
2053-
if (dev->iram_paddr)
2054-
iram_free(dev->iram_paddr, CODA7_IRAM_SIZE);
2070+
if (dev->iram_vaddr)
2071+
gen_pool_free(dev->iram_pool, dev->iram_vaddr, dev->iram_size);
20552072
if (dev->codebuf.vaddr)
20562073
dma_free_coherent(&pdev->dev, dev->codebuf.size,
20572074
&dev->codebuf.vaddr, dev->codebuf.paddr);

include/linux/platform_data/coda.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2013 Philipp Zabel, Pengutronix
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*/
9+
#ifndef PLATFORM_CODA_H
10+
#define PLATFORM_CODA_H
11+
12+
struct device;
13+
14+
struct coda_platform_data {
15+
struct device *iram_dev;
16+
};
17+
18+
#endif

0 commit comments

Comments
 (0)