Skip to content

Commit 46233e9

Browse files
Gnuroumchehab
authored andcommitted
media: mtk-vcodec: move firmware implementations into their own files
mtk-vcodec supports two kinds of firmware, VPU and SCP. Both were supported from the same source files, but this is clearly unclean and makes it more difficult to disable support for one or the other. Move these implementations into their own file, after adding the necessary private interfaces. [hverkuil: smatch fix: mtk_vcodec_fw_vpu_init() error: uninitialized symbol 'rst_id'.] Signed-off-by: Alexandre Courbot <acourbot@chromium.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Fixes: bf1d556 ("media: mtk-vcodec: abstract firmware interface") Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 3cea11c commit 46233e9

8 files changed

Lines changed: 233 additions & 173 deletions

File tree

drivers/media/platform/mtk-vcodec/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ mtk-vcodec-enc-y := venc/venc_vp8_if.o \
2424

2525
mtk-vcodec-common-y := mtk_vcodec_intr.o \
2626
mtk_vcodec_util.o \
27-
mtk_vcodec_fw.o
27+
mtk_vcodec_fw.o \
28+
mtk_vcodec_fw_vpu.o \
29+
mtk_vcodec_fw_scp.o

drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
241241
}
242242
dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
243243

244-
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, VPU_RST_DEC);
244+
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, DECODER);
245245
if (IS_ERR(dev->fw_handler))
246246
return PTR_ERR(dev->fw_handler);
247247

drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
293293
}
294294
dma_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
295295

296-
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, VPU_RST_ENC);
296+
dev->fw_handler = mtk_vcodec_fw_select(dev, fw_type, ENCODER);
297297
if (IS_ERR(dev->fw_handler))
298298
return PTR_ERR(dev->fw_handler);
299299

drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c

Lines changed: 5 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,29 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include "mtk_vcodec_fw.h"
4+
#include "mtk_vcodec_fw_priv.h"
45
#include "mtk_vcodec_util.h"
56
#include "mtk_vcodec_drv.h"
67

7-
struct mtk_vcodec_fw_ops {
8-
int (*load_firmware)(struct mtk_vcodec_fw *fw);
9-
unsigned int (*get_vdec_capa)(struct mtk_vcodec_fw *fw);
10-
unsigned int (*get_venc_capa)(struct mtk_vcodec_fw *fw);
11-
void * (*map_dm_addr)(struct mtk_vcodec_fw *fw, u32 dtcm_dmem_addr);
12-
int (*ipi_register)(struct mtk_vcodec_fw *fw, int id,
13-
mtk_vcodec_ipi_handler handler, const char *name, void *priv);
14-
int (*ipi_send)(struct mtk_vcodec_fw *fw, int id, void *buf,
15-
unsigned int len, unsigned int wait);
16-
};
17-
18-
struct mtk_vcodec_fw {
19-
enum mtk_vcodec_fw_type type;
20-
const struct mtk_vcodec_fw_ops *ops;
21-
struct platform_device *pdev;
22-
struct mtk_scp *scp;
23-
};
24-
25-
static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw)
26-
{
27-
return vpu_load_firmware(fw->pdev);
28-
}
29-
30-
static unsigned int mtk_vcodec_vpu_get_vdec_capa(struct mtk_vcodec_fw *fw)
31-
{
32-
return vpu_get_vdec_hw_capa(fw->pdev);
33-
}
34-
35-
static unsigned int mtk_vcodec_vpu_get_venc_capa(struct mtk_vcodec_fw *fw)
36-
{
37-
return vpu_get_venc_hw_capa(fw->pdev);
38-
}
39-
40-
static void *mtk_vcodec_vpu_map_dm_addr(struct mtk_vcodec_fw *fw,
41-
u32 dtcm_dmem_addr)
42-
{
43-
return vpu_mapping_dm_addr(fw->pdev, dtcm_dmem_addr);
44-
}
45-
46-
static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
47-
mtk_vcodec_ipi_handler handler,
48-
const char *name, void *priv)
49-
{
50-
/*
51-
* The handler we receive takes a void * as its first argument. We
52-
* cannot change this because it needs to be passed down to the rproc
53-
* subsystem when SCP is used. VPU takes a const argument, which is
54-
* more constrained, so the conversion below is safe.
55-
*/
56-
ipi_handler_t handler_const = (ipi_handler_t)handler;
57-
58-
return vpu_ipi_register(fw->pdev, id, handler_const, name, priv);
59-
}
60-
61-
static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
62-
unsigned int len, unsigned int wait)
63-
{
64-
return vpu_ipi_send(fw->pdev, id, buf, len);
65-
}
66-
67-
static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
68-
.load_firmware = mtk_vcodec_vpu_load_firmware,
69-
.get_vdec_capa = mtk_vcodec_vpu_get_vdec_capa,
70-
.get_venc_capa = mtk_vcodec_vpu_get_venc_capa,
71-
.map_dm_addr = mtk_vcodec_vpu_map_dm_addr,
72-
.ipi_register = mtk_vcodec_vpu_set_ipi_register,
73-
.ipi_send = mtk_vcodec_vpu_ipi_send,
74-
};
75-
76-
static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw)
77-
{
78-
return rproc_boot(scp_get_rproc(fw->scp));
79-
}
80-
81-
static unsigned int mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw *fw)
82-
{
83-
return scp_get_vdec_hw_capa(fw->scp);
84-
}
85-
86-
static unsigned int mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw *fw)
87-
{
88-
return scp_get_venc_hw_capa(fw->scp);
89-
}
90-
91-
static void *mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw *fw,
92-
u32 dtcm_dmem_addr)
93-
{
94-
return scp_mapping_dm_addr(fw->scp, dtcm_dmem_addr);
95-
}
96-
97-
static int mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
98-
mtk_vcodec_ipi_handler handler,
99-
const char *name, void *priv)
100-
{
101-
return scp_ipi_register(fw->scp, id, handler, priv);
102-
}
103-
104-
static int mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
105-
unsigned int len, unsigned int wait)
106-
{
107-
return scp_ipi_send(fw->scp, id, buf, len, wait);
108-
}
109-
110-
static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = {
111-
.load_firmware = mtk_vcodec_scp_load_firmware,
112-
.get_vdec_capa = mtk_vcodec_scp_get_vdec_capa,
113-
.get_venc_capa = mtk_vcodec_scp_get_venc_capa,
114-
.map_dm_addr = mtk_vcodec_vpu_scp_dm_addr,
115-
.ipi_register = mtk_vcodec_scp_set_ipi_register,
116-
.ipi_send = mtk_vcodec_scp_ipi_send,
117-
};
118-
119-
static void mtk_vcodec_reset_handler(void *priv)
120-
{
121-
struct mtk_vcodec_dev *dev = priv;
122-
struct mtk_vcodec_ctx *ctx;
123-
124-
mtk_v4l2_err("Watchdog timeout!!");
125-
126-
mutex_lock(&dev->dev_mutex);
127-
list_for_each_entry(ctx, &dev->ctx_list, list) {
128-
ctx->state = MTK_STATE_ABORT;
129-
mtk_v4l2_debug(0, "[%d] Change to state MTK_STATE_ABORT",
130-
ctx->id);
131-
}
132-
mutex_unlock(&dev->dev_mutex);
133-
}
134-
1358
struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev,
1369
enum mtk_vcodec_fw_type type,
137-
enum rst_id rst_id)
10+
enum mtk_vcodec_fw_use fw_use)
13811
{
139-
const struct mtk_vcodec_fw_ops *ops;
140-
struct mtk_vcodec_fw *fw;
141-
struct platform_device *fw_pdev = NULL;
142-
struct mtk_scp *scp = NULL;
143-
14412
switch (type) {
14513
case VPU:
146-
ops = &mtk_vcodec_vpu_msg;
147-
fw_pdev = vpu_get_plat_device(dev->plat_dev);
148-
if (!fw_pdev) {
149-
mtk_v4l2_err("firmware device is not ready");
150-
return ERR_PTR(-EINVAL);
151-
}
152-
vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_reset_handler,
153-
dev, rst_id);
154-
break;
14+
return mtk_vcodec_fw_vpu_init(dev, fw_use);
15515
case SCP:
156-
ops = &mtk_vcodec_rproc_msg;
157-
scp = scp_get(dev->plat_dev);
158-
if (!scp) {
159-
mtk_v4l2_err("could not get vdec scp handle");
160-
return ERR_PTR(-EPROBE_DEFER);
161-
}
162-
break;
16+
return mtk_vcodec_fw_scp_init(dev);
16317
default:
16418
mtk_v4l2_err("invalid vcodec fw type");
16519
return ERR_PTR(-EINVAL);
16620
}
167-
168-
fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL);
169-
if (!fw)
170-
return ERR_PTR(-EINVAL);
171-
172-
fw->type = type;
173-
fw->ops = ops;
174-
fw->pdev = fw_pdev;
175-
fw->scp = scp;
176-
177-
return fw;
17821
}
17922
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_select);
18023

18124
void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw)
18225
{
183-
switch (fw->type) {
184-
case VPU:
185-
put_device(&fw->pdev->dev);
186-
break;
187-
case SCP:
188-
scp_put(fw->scp);
189-
break;
190-
}
26+
fw->ops->release(fw);
19127
}
19228
EXPORT_SYMBOL_GPL(mtk_vcodec_fw_release);
19329

drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ enum mtk_vcodec_fw_type {
1515
SCP,
1616
};
1717

18+
enum mtk_vcodec_fw_use {
19+
DECODER,
20+
ENCODER,
21+
};
22+
1823
struct mtk_vcodec_fw;
1924

2025
typedef void (*mtk_vcodec_ipi_handler) (void *data,
2126
unsigned int len, void *priv);
2227

2328
struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev,
2429
enum mtk_vcodec_fw_type type,
25-
enum rst_id rst_id);
30+
enum mtk_vcodec_fw_use fw_use);
2631
void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw);
2732

2833
int mtk_vcodec_fw_load_firmware(struct mtk_vcodec_fw *fw);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef _MTK_VCODEC_FW_PRIV_H_
4+
#define _MTK_VCODEC_FW_PRIV_H_
5+
6+
#include "mtk_vcodec_fw.h"
7+
8+
struct mtk_vcodec_dev;
9+
10+
struct mtk_vcodec_fw {
11+
enum mtk_vcodec_fw_type type;
12+
const struct mtk_vcodec_fw_ops *ops;
13+
struct platform_device *pdev;
14+
struct mtk_scp *scp;
15+
};
16+
17+
struct mtk_vcodec_fw_ops {
18+
int (*load_firmware)(struct mtk_vcodec_fw *fw);
19+
unsigned int (*get_vdec_capa)(struct mtk_vcodec_fw *fw);
20+
unsigned int (*get_venc_capa)(struct mtk_vcodec_fw *fw);
21+
void *(*map_dm_addr)(struct mtk_vcodec_fw *fw, u32 dtcm_dmem_addr);
22+
int (*ipi_register)(struct mtk_vcodec_fw *fw, int id,
23+
mtk_vcodec_ipi_handler handler, const char *name,
24+
void *priv);
25+
int (*ipi_send)(struct mtk_vcodec_fw *fw, int id, void *buf,
26+
unsigned int len, unsigned int wait);
27+
void (*release)(struct mtk_vcodec_fw *fw);
28+
};
29+
30+
struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(struct mtk_vcodec_dev *dev,
31+
enum mtk_vcodec_fw_use fw_use);
32+
struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(struct mtk_vcodec_dev *dev);
33+
34+
#endif /* _MTK_VCODEC_FW_PRIV_H_ */
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "mtk_vcodec_fw_priv.h"
4+
#include "mtk_vcodec_util.h"
5+
#include "mtk_vcodec_drv.h"
6+
7+
static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw)
8+
{
9+
return rproc_boot(scp_get_rproc(fw->scp));
10+
}
11+
12+
static unsigned int mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw *fw)
13+
{
14+
return scp_get_vdec_hw_capa(fw->scp);
15+
}
16+
17+
static unsigned int mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw *fw)
18+
{
19+
return scp_get_venc_hw_capa(fw->scp);
20+
}
21+
22+
static void *mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw *fw,
23+
u32 dtcm_dmem_addr)
24+
{
25+
return scp_mapping_dm_addr(fw->scp, dtcm_dmem_addr);
26+
}
27+
28+
static int mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
29+
mtk_vcodec_ipi_handler handler,
30+
const char *name, void *priv)
31+
{
32+
return scp_ipi_register(fw->scp, id, handler, priv);
33+
}
34+
35+
static int mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
36+
unsigned int len, unsigned int wait)
37+
{
38+
return scp_ipi_send(fw->scp, id, buf, len, wait);
39+
}
40+
41+
static void mtk_vcodec_scp_release(struct mtk_vcodec_fw *fw)
42+
{
43+
scp_put(fw->scp);
44+
}
45+
46+
static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = {
47+
.load_firmware = mtk_vcodec_scp_load_firmware,
48+
.get_vdec_capa = mtk_vcodec_scp_get_vdec_capa,
49+
.get_venc_capa = mtk_vcodec_scp_get_venc_capa,
50+
.map_dm_addr = mtk_vcodec_vpu_scp_dm_addr,
51+
.ipi_register = mtk_vcodec_scp_set_ipi_register,
52+
.ipi_send = mtk_vcodec_scp_ipi_send,
53+
.release = mtk_vcodec_scp_release,
54+
};
55+
56+
struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(struct mtk_vcodec_dev *dev)
57+
{
58+
struct mtk_vcodec_fw *fw;
59+
struct mtk_scp *scp;
60+
61+
scp = scp_get(dev->plat_dev);
62+
if (!scp) {
63+
mtk_v4l2_err("could not get vdec scp handle");
64+
return ERR_PTR(-EPROBE_DEFER);
65+
}
66+
67+
fw = devm_kzalloc(&dev->plat_dev->dev, sizeof(*fw), GFP_KERNEL);
68+
fw->type = SCP;
69+
fw->ops = &mtk_vcodec_rproc_msg;
70+
fw->scp = scp;
71+
72+
return fw;
73+
}

0 commit comments

Comments
 (0)