2020-05-30 08:14:37

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 00/17] Clean up "mediatek,larb" after adding device_link

MediaTek IOMMU block diagram always like below:

M4U
|
smi-common
|
-------------
| | ...
| |
larb1 larb2
| |
vdec venc

All the consumer connect with smi-larb, then connect with smi-common.

MediaTek IOMMU don't have its power-domain. When the consumer works,
it should enable the smi-larb's power which also need enable the smi-common's
power firstly.

Thus, Firstly, use the device link connect the consumer and the
smi-larbs. then add device link between the smi-larb and smi-common.

After adding the device_link, then "mediatek,larb" property can be removed.
the iommu consumer don't need call the mtk_smi_larb_get/put to enable
the power and clock of smi-larb and smi-common.

This patchset depends on v5.7-rc1 and several patchset. Mainly venc and MDP
adjust their flow, then this patchset can work successfully.

a) IOMMU depend on [1][2].
b) MDP depend on [3][4][5].
c) VENC depend on [6].

[1] iommu: Move iommu_group setup to IOMMU core code
https://lore.kernel.org/linux-iommu/[email protected]/
[2] iommu/mediatek-v1: Fix a build warning for a unused variable 'data'
https://lore.kernel.org/linux-iommu/[email protected]/
[3] arm64: dts: mt8173: fix mdp aliases property name
https://lore.kernel.org/linux-mediatek/[email protected]/
[4] MTK MDP driver cleanups to prep for futher work
https://lore.kernel.org/linux-mediatek/[email protected]/
[5] Refactor MDP driver and add dummy component driver
https://lore.kernel.org/linux-mediatek/[email protected]/
[6] media: mtk-vcodec: venc: support for MT8183
https://lore.kernel.org/linux-mediatek/[email protected]/

[1][2][3] have already been in lastest linux-next.

Change notes:

v4: base on v5.7-rc1.
1) Move drm PM patch before smi patchs.
2) Change builtin_platform_driver to module_platform_driver since we may need
build as module.
3) Rebase many patchset as above.

v3: https://lore.kernel.org/linux-iommu/[email protected]/
1) rebase on v5.3-rc1 and the latest mt8183 patchset.
2) Use device_is_bound to check whether the driver is ready from Matthias.
3) Add DL_FLAG_STATELESS flag when calling device_link_add and explain the
reason in the commit message[3/14].
4) Add a display patch[12/14] into this series. otherwise it may affect
display HW fastlogo even though it don't happen in mt8183.

v2: http://lists.infradead.org/pipermail/linux-mediatek/2019-June/020440.html
1) rebase on v5.2-rc1.
2) Move adding device_link between the consumer and smi-larb into
iommu_add_device from Robin.
3) add DL_FLAG_AUTOREMOVE_CONSUMER even though the smi is built-in from Evan.
4) Remove the shutdown callback in iommu.

v1: https://lists.linuxfoundation.org/pipermail/iommu/2019-January/032387.html

Irui Wang (1):
arm64: dts: mt8173: Separate mtk-vcodec-enc node

Maoguang Meng (2):
media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.
media: mtk-vcodec: separate mtk-vcodec-enc node.

Yong Wu (13):
dt-binding: mediatek: Get rid of mediatek,larb for multimedia HW
iommu/mediatek: Add probe_defer for smi-larb
iommu/mediatek: Add device_link between the consumer and the larb
devices
memory: mtk-smi: Add device-link between smi-larb and smi-common
media: mtk-jpeg: Get rid of mtk_smi_larb_get/put
media: mtk-mdp: Get rid of mtk_smi_larb_get/put
media: mtk-vcodec: Get rid of mtk_smi_larb_get/put
drm/mediatek: Get rid of mtk_smi_larb_get/put
memory: mtk-smi: Get rid of mtk_smi_larb_get/put
iommu/mediatek: Use module_platform_driver
memory: mtk-smi: Use device_is_bound to check if smi-common is ready
arm: dts: mediatek: Get rid of mediatek,larb for MM nodes
arm64: dts: mediatek: Get rid of mediatek,larb for MM nodes

Yongqiang Niu (1):
drm/mediatek: Add pm runtime support for ovl and rdma

.../bindings/display/mediatek/mediatek,disp.txt | 9 --
.../bindings/media/mediatek-jpeg-decoder.txt | 4 -
.../devicetree/bindings/media/mediatek-mdp.txt | 8 --
.../devicetree/bindings/media/mediatek-vcodec.txt | 58 +++++-----
arch/arm/boot/dts/mt2701.dtsi | 1 -
arch/arm/boot/dts/mt7623.dtsi | 1 -
arch/arm64/boot/dts/mediatek/mt8173.dtsi | 72 +++++-------
drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 9 +-
drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 9 +-
drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 19 +--
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 21 +---
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 2 +-
drivers/iommu/mtk_iommu.c | 44 ++++---
drivers/iommu/mtk_iommu_v1.c | 39 +++++--
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 22 ----
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 2 -
drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 44 +------
drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 -
drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 1 -
.../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 19 ---
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 13 +--
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 24 +++-
.../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 127 +++++++++------------
.../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 56 ---------
.../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 1 -
.../media/platform/mtk-vcodec/venc/venc_vp8_if.c | 4 +-
drivers/memory/mtk-smi.c | 41 +++----
include/soc/mediatek/smi.h | 20 ----
28 files changed, 246 insertions(+), 426 deletions(-)

--
1.9.1


2020-05-30 08:15:02

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 02/17] dt-binding: mediatek: Get rid of mediatek,larb for multimedia HW

After adding device_link between the consumer with the smi-larbs,
if the consumer call its owner pm_runtime_get(_sync), the
pm_runtime_get(_sync) of smi-larb and smi-common will be called
automatically. Thus, the consumer don't need the property.

And IOMMU also know which larb this consumer connects with from
iommu id in the "iommus=" property.

Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Rob Herring <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
.../devicetree/bindings/display/mediatek/mediatek,disp.txt | 9 ---------
.../devicetree/bindings/media/mediatek-jpeg-decoder.txt | 4 ----
Documentation/devicetree/bindings/media/mediatek-mdp.txt | 8 --------
Documentation/devicetree/bindings/media/mediatek-vcodec.txt | 4 ----
4 files changed, 25 deletions(-)

diff --git a/Documentation/devicetree/bindings/display/mediatek/mediatek,disp.txt b/Documentation/devicetree/bindings/display/mediatek/mediatek,disp.txt
index b91e709..c7e2eb8 100644
--- a/Documentation/devicetree/bindings/display/mediatek/mediatek,disp.txt
+++ b/Documentation/devicetree/bindings/display/mediatek/mediatek,disp.txt
@@ -60,8 +60,6 @@ Required properties (DMA function blocks):
"mediatek,<chip>-disp-rdma"
"mediatek,<chip>-disp-wdma"
the supported chips are mt2701 and mt8173.
-- larb: Should contain a phandle pointing to the local arbiter device as defined
- in Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
- iommus: Should point to the respective IOMMU block with master port as
argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
for details.
@@ -82,7 +80,6 @@ ovl0: ovl@1400c000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_OVL0>;
iommus = <&iommu M4U_PORT_DISP_OVL0>;
- mediatek,larb = <&larb0>;
};

ovl1: ovl@1400d000 {
@@ -92,7 +89,6 @@ ovl1: ovl@1400d000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_OVL1>;
iommus = <&iommu M4U_PORT_DISP_OVL1>;
- mediatek,larb = <&larb4>;
};

rdma0: rdma@1400e000 {
@@ -102,7 +98,6 @@ rdma0: rdma@1400e000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA0>;
iommus = <&iommu M4U_PORT_DISP_RDMA0>;
- mediatek,larb = <&larb0>;
};

rdma1: rdma@1400f000 {
@@ -112,7 +107,6 @@ rdma1: rdma@1400f000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA1>;
iommus = <&iommu M4U_PORT_DISP_RDMA1>;
- mediatek,larb = <&larb4>;
};

rdma2: rdma@14010000 {
@@ -122,7 +116,6 @@ rdma2: rdma@14010000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA2>;
iommus = <&iommu M4U_PORT_DISP_RDMA2>;
- mediatek,larb = <&larb4>;
};

wdma0: wdma@14011000 {
@@ -132,7 +125,6 @@ wdma0: wdma@14011000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_WDMA0>;
iommus = <&iommu M4U_PORT_DISP_WDMA0>;
- mediatek,larb = <&larb0>;
};

wdma1: wdma@14012000 {
@@ -142,7 +134,6 @@ wdma1: wdma@14012000 {
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_WDMA1>;
iommus = <&iommu M4U_PORT_DISP_WDMA1>;
- mediatek,larb = <&larb4>;
};

color0: color@14013000 {
diff --git a/Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt b/Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
index 044b119..7978f21 100644
--- a/Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
+++ b/Documentation/devicetree/bindings/media/mediatek-jpeg-decoder.txt
@@ -15,9 +15,6 @@ Required properties:
- clock-names: must contain "jpgdec-smi" and "jpgdec".
- power-domains: a phandle to the power domain, see
Documentation/devicetree/bindings/power/power_domain.txt for details.
-- mediatek,larb: must contain the local arbiters in the current Socs, see
- Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
- for details.
- iommus: should point to the respective IOMMU block with master port as
argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
for details.
@@ -32,7 +29,6 @@ Example:
clock-names = "jpgdec-smi",
"jpgdec";
power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
- mediatek,larb = <&larb2>;
iommus = <&iommu MT2701_M4U_PORT_JPGDEC_WDMA>,
<&iommu MT2701_M4U_PORT_JPGDEC_BSDMA>;
};
diff --git a/Documentation/devicetree/bindings/media/mediatek-mdp.txt b/Documentation/devicetree/bindings/media/mediatek-mdp.txt
index 0d03e3a..df69c5a 100644
--- a/Documentation/devicetree/bindings/media/mediatek-mdp.txt
+++ b/Documentation/devicetree/bindings/media/mediatek-mdp.txt
@@ -27,9 +27,6 @@ Required properties (DMA function blocks, child node):
- iommus: should point to the respective IOMMU block with master port as
argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
for details.
-- mediatek,larb: must contain the local arbiters in the current Socs, see
- Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt
- for details.

Example:
mdp_rdma0: rdma@14001000 {
@@ -40,7 +37,6 @@ Example:
<&mmsys CLK_MM_MUTEX_32K>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_RDMA0>;
- mediatek,larb = <&larb0>;
mediatek,vpu = <&vpu>;
};

@@ -51,7 +47,6 @@ Example:
<&mmsys CLK_MM_MUTEX_32K>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_RDMA1>;
- mediatek,larb = <&larb4>;
};

mdp_rsz0: rsz@14003000 {
@@ -81,7 +76,6 @@ Example:
clocks = <&mmsys CLK_MM_MDP_WDMA>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WDMA>;
- mediatek,larb = <&larb0>;
};

mdp_wrot0: wrot@14007000 {
@@ -90,7 +84,6 @@ Example:
clocks = <&mmsys CLK_MM_MDP_WROT0>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WROT0>;
- mediatek,larb = <&larb0>;
};

mdp_wrot1: wrot@14008000 {
@@ -99,5 +92,4 @@ Example:
clocks = <&mmsys CLK_MM_MDP_WROT1>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WROT1>;
- mediatek,larb = <&larb4>;
};
diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
index 1023740..50a27f2 100644
--- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
+++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
@@ -12,7 +12,6 @@ Required properties:
- reg : Physical base address of the video codec registers and length of
memory mapped region.
- interrupts : interrupt number to the cpu.
-- mediatek,larb : must contain the local arbiters in the current Socs.
- clocks : list of clock specifiers, corresponding to entries in
the clock-names property.
- clock-names:
@@ -45,7 +44,6 @@ vcodec_dec: vcodec@16000000 {
<0 0x16027800 0 0x800>, /*VP8_VL*/
<0 0x16028400 0 0x400>; /*VP9_VD*/
interrupts = <GIC_SPI 204 IRQ_TYPE_LEVEL_LOW>;
- mediatek,larb = <&larb1>;
iommus = <&iommu M4U_PORT_HW_VDEC_MC_EXT>,
<&iommu M4U_PORT_HW_VDEC_PP_EXT>,
<&iommu M4U_PORT_HW_VDEC_AVC_MV_EXT>,
@@ -98,7 +96,6 @@ vcodec_enc: vcodec@18002000 {
<&iommu M4U_PORT_VENC_REF_CHROMA>,
<&iommu M4U_PORT_VENC_NBM_RDMA>,
<&iommu M4U_PORT_VENC_NBM_WDMA>;
- mediatek,larb = <&larb3>;
mediatek,vpu = <&vpu>;
clocks = <&topckgen CLK_TOP_VENC_SEL>;
clock-names = "venc_sel";
@@ -119,7 +116,6 @@ vcodec_enc_lt: vcodec@19002000 {
<&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
<&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
<&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
- mediatek,larb = <&larb5>;
mediatek,vpu = <&vpu>;
clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
clock-names = "venc_lt_sel";
--
1.9.1

2020-05-30 08:15:22

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 03/17] iommu/mediatek: Add probe_defer for smi-larb

The iommu consumer should use device_link to connect with the
smi-larb(supplier). then the smi-larb should run before the iommu
consumer. Here we delay the iommu driver until the smi driver is
ready, then all the iommu consumer always is after the smi driver.

When there is no this patch, if some consumer drivers run before
smi-larb, the supplier link_status is DL_DEV_NO_DRIVER(0) in the
device_link_add, then device_links_driver_bound will use WARN_ON
to complain that the link_status of supplier is not right.

This is a preparing patch for adding device_link.

Signed-off-by: Yong Wu <[email protected]>
---
drivers/iommu/mtk_iommu.c | 8 +++++++-
drivers/iommu/mtk_iommu_v1.c | 7 ++++++-
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 2be96f1..7d8f3d0 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -643,6 +643,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
for (i = 0; i < larb_nr; i++) {
struct device_node *larbnode;
struct platform_device *plarbdev;
+ bool larbdev_is_bound = false;
u32 id;

larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
@@ -659,7 +660,12 @@ static int mtk_iommu_probe(struct platform_device *pdev)
id = i;

plarbdev = of_find_device_by_node(larbnode);
- if (!plarbdev) {
+ if (plarbdev) {
+ device_lock(&plarbdev->dev);
+ larbdev_is_bound = device_is_bound(&plarbdev->dev);
+ device_unlock(&plarbdev->dev);
+ }
+ if (!plarbdev || !larbdev_is_bound) {
of_node_put(larbnode);
return -EPROBE_DEFER;
}
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 1245e0c..02858a0 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -591,10 +591,15 @@ static int mtk_iommu_probe(struct platform_device *pdev)

plarbdev = of_find_device_by_node(larb_spec.np);
if (!plarbdev) {
+ bool larbdev_is_bound;
+
plarbdev = of_platform_device_create(
larb_spec.np, NULL,
platform_bus_type.dev_root);
- if (!plarbdev) {
+ device_lock(&plarbdev->dev);
+ larbdev_is_bound = device_is_bound(&plarbdev->dev);
+ device_unlock(&plarbdev->dev);
+ if (!plarbdev || !larbdev_is_bound) {
of_node_put(larb_spec.np);
return -EPROBE_DEFER;
}
--
1.9.1

2020-05-30 08:15:30

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 04/17] iommu/mediatek: Add device_link between the consumer and the larb devices

MediaTek IOMMU don't have its power-domain. all the consumer connect
with smi-larb, then connect with smi-common.

M4U
|
smi-common
|
-------------
| | ...
| |
larb1 larb2
| |
vdec venc

When the consumer works, it should enable the smi-larb's power which
also need enable the smi-common's power firstly.

Thus, First of all, use the device link connect the consumer and the
smi-larbs. then add device link between the smi-larb and smi-common.

This patch adds device_link between the consumer and the larbs.

When device_link_add, I add the flag DL_FLAG_STATELESS to avoid calling
pm_runtime_xx to keep the original status of clocks. It can avoid two
issues:
1) Display HW show fastlogo abnormally reported in [1]. At the beggining,
all the clocks are enabled before entering kernel, but the clocks for
display HW(always in larb0) will be gated after clk_enable and clk_disable
called from device_link_add(->pm_runtime_resume) and rpm_idle. The clock
operation happened before display driver probe. At that time, the display
HW will be abnormal.

2) A deadlock issue reported in [2]. Use DL_FLAG_STATELESS to skip
pm_runtime_xx to avoid the deadlock.

Corresponding, DL_FLAG_AUTOREMOVE_CONSUMER can't be added, then
device_link_removed should be added explicitly.

[1] http://lists.infradead.org/pipermail/linux-mediatek/2019-July/
021500.html
[2] https://lore.kernel.org/patchwork/patch/1086569/

Suggested-by: Tomasz Figa <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
drivers/iommu/mtk_iommu.c | 18 ++++++++++++++++++
drivers/iommu/mtk_iommu_v1.c | 20 +++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 7d8f3d0..5c3a6ba 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -445,22 +445,40 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct mtk_iommu_data *data;
+ struct device_link *link;
+ struct device *larbdev;
+ unsigned int larbid;

if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return ERR_PTR(-ENODEV); /* Not a iommu client device */

data = dev_iommu_priv_get(dev);

+ /* Link the consumer device with the smi-larb device(supplier) */
+ larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
+ larbdev = data->larb_imu[larbid].dev;
+ link = device_link_add(dev, larbdev,
+ DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+ if (!link)
+ dev_err(dev, "Unable to link %s\n", dev_name(larbdev));
return &data->iommu;
}

static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct mtk_iommu_data *data;
+ struct device *larbdev;
+ unsigned int larbid;

if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;

+ data = dev_iommu_priv_get(dev);
+ larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
+ larbdev = data->larb_imu[larbid].dev;
+ device_link_remove(dev, larbdev);
+
iommu_fwspec_free(dev);
}

diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 02858a0..26b6c79 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -422,7 +422,9 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
struct of_phandle_args iommu_spec;
struct of_phandle_iterator it;
struct mtk_iommu_data *data;
- int err;
+ struct device_link *link;
+ struct device *larbdev;
+ int err, larbid;

of_for_each_phandle(&it, err, dev->of_node, "iommus",
"#iommu-cells", -1) {
@@ -444,6 +446,14 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)

data = dev_iommu_priv_get(dev);

+ /* Link the consumer device with the smi-larb device(supplier) */
+ larbid = mt2701_m4u_to_larb(fwspec->ids[0]);
+ larbdev = data->larb_imu[larbid].dev;
+ link = device_link_add(dev, larbdev,
+ DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+ if (!link)
+ dev_err(dev, "Unable to link %s\n", dev_name(larbdev));
+
return &data->iommu;
}

@@ -465,10 +475,18 @@ static void mtk_iommu_probe_finalize(struct device *dev)
static void mtk_iommu_release_device(struct device *dev)
{
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+ struct mtk_iommu_data *data;
+ struct device *larbdev;
+ unsigned int larbid;

if (!fwspec || fwspec->ops != &mtk_iommu_ops)
return;

+ data = dev_iommu_priv_get(dev);
+ larbid = mt2701_m4u_to_larb(fwspec->ids[0]);
+ larbdev = data->larb_imu[larbid].dev;
+ device_link_remove(dev, larbdev);
+
iommu_fwspec_free(dev);
}

--
1.9.1

2020-05-30 08:15:44

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 05/17] memory: mtk-smi: Add device-link between smi-larb and smi-common

Normally, If the smi-larb HW need work, we should enable the smi-common
HW power and clock firstly.
This patch adds device-link between the smi-larb dev and the smi-common
dev. then If pm_runtime_get_sync(smi-larb-dev), the pm_runtime_get_sync
(smi-common-dev) will be called automatically.

Also, Add DL_FLAG_STATELESS to avoid the smi-common clocks be gated when
probe.

CC: Matthias Brugger <[email protected]>
Suggested-by: Tomasz Figa <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
drivers/memory/mtk-smi.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index a113e81..6cdefda 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -273,6 +273,7 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *smi_node;
struct platform_device *smi_pdev;
+ struct device_link *link;

larb = devm_kzalloc(dev, sizeof(*larb), GFP_KERNEL);
if (!larb)
@@ -312,6 +313,12 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
if (!platform_get_drvdata(smi_pdev))
return -EPROBE_DEFER;
larb->smi_common_dev = &smi_pdev->dev;
+ link = device_link_add(dev, larb->smi_common_dev,
+ DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+ if (!link) {
+ dev_err(dev, "Unable to link smi-common dev\n");
+ return -ENODEV;
+ }
} else {
dev_err(dev, "Failed to get the smi_common device\n");
return -EINVAL;
@@ -324,6 +331,9 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)

static int mtk_smi_larb_remove(struct platform_device *pdev)
{
+ struct mtk_smi_larb *larb = platform_get_drvdata(pdev);
+
+ device_link_remove(&pdev->dev, larb->smi_common_dev);
pm_runtime_disable(&pdev->dev);
component_del(&pdev->dev, &mtk_smi_larb_component_ops);
return 0;
@@ -335,17 +345,9 @@ static int __maybe_unused mtk_smi_larb_resume(struct device *dev)
const struct mtk_smi_larb_gen *larb_gen = larb->larb_gen;
int ret;

- /* Power on smi-common. */
- ret = pm_runtime_get_sync(larb->smi_common_dev);
- if (ret < 0) {
- dev_err(dev, "Failed to pm get for smi-common(%d).\n", ret);
- return ret;
- }
-
ret = mtk_smi_clk_enable(&larb->smi);
if (ret < 0) {
dev_err(dev, "Failed to enable clock(%d).\n", ret);
- pm_runtime_put_sync(larb->smi_common_dev);
return ret;
}

@@ -360,7 +362,6 @@ static int __maybe_unused mtk_smi_larb_suspend(struct device *dev)
struct mtk_smi_larb *larb = dev_get_drvdata(dev);

mtk_smi_clk_disable(&larb->smi);
- pm_runtime_put_sync(larb->smi_common_dev);
return 0;
}

--
1.9.1

2020-05-30 08:16:03

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 06/17] media: mtk-jpeg: Get rid of mtk_smi_larb_get/put

MediaTek IOMMU has already added device_link between the consumer
and smi-larb device. If the jpg device call the pm_runtime_get_sync,
the smi-larb's pm_runtime_get_sync also be called automatically.

CC: Rick Chang <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 22 ----------------------
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 2 --
2 files changed, 24 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index f82a81a..21fba6f 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -21,7 +21,6 @@
#include <media/v4l2-ioctl.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
-#include <soc/mediatek/smi.h>

#include "mtk_jpeg_hw.h"
#include "mtk_jpeg_core.h"
@@ -893,11 +892,6 @@ static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq,

static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
{
- int ret;
-
- ret = mtk_smi_larb_get(jpeg->larb);
- if (ret)
- dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
clk_prepare_enable(jpeg->clk_jdec_smi);
clk_prepare_enable(jpeg->clk_jdec);
}
@@ -906,7 +900,6 @@ static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
{
clk_disable_unprepare(jpeg->clk_jdec);
clk_disable_unprepare(jpeg->clk_jdec_smi);
- mtk_smi_larb_put(jpeg->larb);
}

static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
@@ -1051,21 +1044,6 @@ static int mtk_jpeg_release(struct file *file)

static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
{
- struct device_node *node;
- struct platform_device *pdev;
-
- node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
- if (!node)
- return -EINVAL;
- pdev = of_find_device_by_node(node);
- if (WARN_ON(!pdev)) {
- of_node_put(node);
- return -EINVAL;
- }
- of_node_put(node);
-
- jpeg->larb = &pdev->dev;
-
jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
if (IS_ERR(jpeg->clk_jdec))
return PTR_ERR(jpeg->clk_jdec);
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
index 999bd14..8579494 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
@@ -47,7 +47,6 @@ enum mtk_jpeg_ctx_state {
* @dec_reg_base: JPEG registers mapping
* @clk_jdec: JPEG hw working clock
* @clk_jdec_smi: JPEG SMI bus clock
- * @larb: SMI device
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -61,7 +60,6 @@ struct mtk_jpeg_dev {
void __iomem *dec_reg_base;
struct clk *clk_jdec;
struct clk *clk_jdec_smi;
- struct device *larb;
};

/**
--
1.9.1

2020-05-30 08:16:13

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 07/17] media: mtk-mdp: Get rid of mtk_smi_larb_get/put

MediaTek IOMMU has already added the device_link between the consumer
and smi-larb device. If the mdp device call the pm_runtime_get_sync,
the smi-larb's pm_runtime_get_sync also be called automatically.

CC: Minghsiu Tsai <[email protected]>
CC: Houlong Wei <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 44 +--------------------------
drivers/media/platform/mtk-mdp/mtk_mdp_comp.h | 2 --
drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 1 -
3 files changed, 1 insertion(+), 46 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
index 228c58f..388ae67 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
@@ -13,7 +13,6 @@
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_platform.h>
-#include <soc/mediatek/smi.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>

@@ -58,18 +57,6 @@ void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
{
int i, err;

- if (comp->larb_dev) {
- err = mtk_smi_larb_get(comp->larb_dev);
- if (err) {
- enum mtk_mdp_comp_type comp_type =
- (enum mtk_mdp_comp_type)
- of_device_get_match_data(comp->dev);
- dev_err(comp->dev,
- "failed to get larb, err %d. type:%d\n",
- err, comp_type);
- }
- }
-
err = pm_runtime_get_sync(comp->dev);
if (err < 0)
dev_err(comp->dev,
@@ -97,9 +84,6 @@ void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp)
clk_disable_unprepare(comp->clk[i]);
}

- if (comp->larb_dev)
- mtk_smi_larb_put(comp->larb_dev);
-
pm_runtime_put_sync(comp->dev);
}

@@ -132,12 +116,10 @@ static void mtk_mdp_comp_unbind(struct device *dev, struct device *master,

int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev)
{
- struct device_node *larb_node;
- struct platform_device *larb_pdev;
- int i;
struct device_node *node = dev->of_node;
enum mtk_mdp_comp_type comp_type =
(enum mtk_mdp_comp_type)of_device_get_match_data(dev);
+ int i;

INIT_LIST_HEAD(&comp->node);
comp->dev = dev;
@@ -156,30 +138,6 @@ int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev)
break;
}

- /* Only DMA capable components need the LARB property */
- comp->larb_dev = NULL;
- if (comp_type != MTK_MDP_RDMA &&
- comp_type != MTK_MDP_WDMA &&
- comp_type != MTK_MDP_WROT)
- return 0;
-
- larb_node = of_parse_phandle(node, "mediatek,larb", 0);
- if (!larb_node) {
- dev_err(dev,
- "Missing mediadek,larb phandle in %pOF node\n", node);
- return -EINVAL;
- }
-
- larb_pdev = of_find_device_by_node(larb_node);
- if (!larb_pdev) {
- dev_warn(dev, "Waiting for larb device %pOF\n", larb_node);
- of_node_put(larb_node);
- return -EPROBE_DEFER;
- }
- of_node_put(larb_node);
-
- comp->larb_dev = &larb_pdev->dev;
-
return 0;
}

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
index de158d3..355e226 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
@@ -11,13 +11,11 @@
* struct mtk_mdp_comp - the MDP's function component data
* @node: list node to track sibing MDP components
* @clk: clocks required for component
- * @larb_dev: SMI device required for component
* @dev: component's device
*/
struct mtk_mdp_comp {
struct list_head node;
struct clk *clk[2];
- struct device *larb_dev;
struct device *dev;
};

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
index 133d107..bc5472d 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
@@ -18,7 +18,6 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/workqueue.h>
-#include <soc/mediatek/smi.h>

#include "mtk_mdp_comp.h"
#include "mtk_mdp_core.h"
--
1.9.1

2020-05-30 08:16:29

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 08/17] media: mtk-vcodec: separate mtk-vcodec-enc node.

From: Maoguang Meng <[email protected]>

MTK H264 Encoder(VENC_SYS) and VP8 Encoder(VENC_LT_SYS) are two
independent hardware instance. They have their owner interrupt,
register mapping, and special clocks.

This patch seperates the two instance. This is a preparing patch for
adding device_link between the larbs and venc-device. It's mainly for
fixing the problem:
https://lkml.org/lkml/2019/9/3/316

User Call "VIDIOC_QUERYCAP":
H264 Encoder return driver name "mtk-vcodec-enc";
VP8 Encoder return driver name "mtk-venc-vp8.

Signed-off-by: Maoguang Meng <[email protected]>
Signed-off-by: Hsin-Yi Wang <[email protected]>
Signed-off-by: Irui Wang <[email protected]>
---
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 10 +-
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 23 +++-
.../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 127 +++++++++------------
.../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 31 +----
.../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 1 -
.../media/platform/mtk-vcodec/venc/venc_vp8_if.c | 4 +-
6 files changed, 80 insertions(+), 116 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index a2716117..52d1ce1 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -19,6 +19,7 @@
#define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv"
#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
+#define MTK_VENC_VP8_NAME "mtk-venc-vp8"
#define MTK_PLATFORM_STR "platform:mt8173"

#define MTK_VCODEC_MAX_PLANES 3
@@ -193,7 +194,6 @@ struct mtk_vcodec_pm {

struct mtk_vcodec_clk venc_clk;
struct device *larbvenc;
- struct device *larbvenclt;
struct device *dev;
struct mtk_vcodec_dev *mtkdev;
};
@@ -311,25 +311,27 @@ enum mtk_chip {
* @chip: chip this encoder is compatible with
*
* @uses_ext: whether the encoder uses the extended firmware messaging format
- * @has_lt_irq: whether the encoder uses the LT irq
+ * @name: whether the encoder core is vp8
* @min_birate: minimum supported encoding bitrate
* @max_bitrate: maximum supported encoding bitrate
* @capture_formats: array of supported capture formats
* @num_capture_formats: number of entries in capture_formats
* @output_formats: array of supported output formats
* @num_output_formats: number of entries in output_formats
+ * @core_id: stand for h264 or vp8 encode index
*/
struct mtk_vcodec_enc_pdata {
enum mtk_chip chip;

bool uses_ext;
- bool has_lt_irq;
+ const char *name;
unsigned long min_bitrate;
unsigned long max_bitrate;
const struct mtk_video_fmt *capture_formats;
size_t num_capture_formats;
const struct mtk_video_fmt *output_formats;
size_t num_output_formats;
+ int core_id;
};

/**
@@ -359,7 +361,6 @@ struct mtk_vcodec_enc_pdata {
*
* @dec_irq: decoder irq resource
* @enc_irq: h264 encoder irq resource
- * @enc_lt_irq: vp8 encoder irq resource
*
* @dec_mutex: decoder hardware lock
* @enc_mutex: encoder hardware lock.
@@ -395,7 +396,6 @@ struct mtk_vcodec_dev {

int dec_irq;
int enc_irq;
- int enc_lt_irq;

struct mutex dec_mutex;
struct mutex enc_mutex;
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
index f0af78f..5301dca 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
@@ -9,6 +9,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
#include <soc/mediatek/smi.h>
+#include <linux/pm_runtime.h>

#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
@@ -174,7 +175,10 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
static int vidioc_venc_querycap(struct file *file, void *priv,
struct v4l2_capability *cap)
{
- strscpy(cap->driver, MTK_VCODEC_ENC_NAME, sizeof(cap->driver));
+ const struct mtk_vcodec_enc_pdata *pdata =
+ fh_to_ctx(priv)->dev->venc_pdata;
+
+ strscpy(cap->driver, pdata->name, sizeof(cap->driver));
strscpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
strscpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));

@@ -788,7 +792,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
*/
if ((ctx->state == MTK_STATE_ABORT) || (ctx->state == MTK_STATE_FREE)) {
ret = -EIO;
- goto err_set_param;
+ goto err_start_stream;
}

/* Do the initialization when both start_streaming have been called */
@@ -800,6 +804,12 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
return 0;
}

+ ret = pm_runtime_get_sync(&ctx->dev->plat_dev->dev);
+ if (ret < 0) {
+ mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+ goto err_start_stream;
+ }
+
mtk_venc_set_param(ctx, &param);
ret = venc_if_set_param(ctx, VENC_SET_PARAM_ENC, &param);
if (ret) {
@@ -826,6 +836,11 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
return 0;

err_set_param:
+ ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
+ if (ret < 0)
+ mtk_v4l2_err("pm_runtime_put fail %d", ret);
+
+err_start_stream:
for (i = 0; i < q->num_buffers; ++i) {
struct vb2_buffer *buf = vb2_get_buffer(q, i);

@@ -879,6 +894,10 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
if (ret)
mtk_v4l2_err("venc_if_deinit failed=%d", ret);

+ ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
+ if (ret < 0)
+ mtk_v4l2_err("pm_runtime_put fail %d", ret);
+
ctx->state = MTK_STATE_FREE;
}

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index b8fe408..fe17f0c 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -49,12 +49,15 @@
},
};

-static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] = {
+static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_h264[] = {
{
.fourcc = V4L2_PIX_FMT_H264,
.type = MTK_FMT_ENC,
.num_planes = 1,
},
+};
+
+static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_vp8[] = {
{
.fourcc = V4L2_PIX_FMT_VP8,
.type = MTK_FMT_ENC,
@@ -110,35 +113,13 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
ctx = dev->curr_ctx;
spin_unlock_irqrestore(&dev->irqlock, flags);

- mtk_v4l2_debug(1, "id=%d", ctx->id);
- addr = dev->reg_base[VENC_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
-
- ctx->irq_status = readl(dev->reg_base[VENC_SYS] +
- (MTK_VENC_IRQ_STATUS_OFFSET));
-
- clean_irq_status(ctx->irq_status, addr);
-
- wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
- return IRQ_HANDLED;
-}
-
-static irqreturn_t mtk_vcodec_enc_lt_irq_handler(int irq, void *priv)
-{
- struct mtk_vcodec_dev *dev = priv;
- struct mtk_vcodec_ctx *ctx;
- unsigned long flags;
- void __iomem *addr;
-
- spin_lock_irqsave(&dev->irqlock, flags);
- ctx = dev->curr_ctx;
- spin_unlock_irqrestore(&dev->irqlock, flags);
+ mtk_v4l2_debug(1, "id=%d coreid:%d", ctx->id, dev->venc_pdata->core_id);
+ addr = dev->reg_base[dev->venc_pdata->core_id] +
+ MTK_VENC_IRQ_ACK_OFFSET;

- mtk_v4l2_debug(1, "id=%d", ctx->id);
- ctx->irq_status = readl(dev->reg_base[VENC_LT_SYS] +
+ ctx->irq_status = readl(dev->reg_base[dev->venc_pdata->core_id] +
(MTK_VENC_IRQ_STATUS_OFFSET));

- addr = dev->reg_base[VENC_LT_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
-
clean_irq_status(ctx->irq_status, addr);

wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
@@ -265,7 +246,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
struct resource *res;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
- int i, j, ret;
+ int ret;
+ void __iomem *reg_base;

dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
@@ -291,63 +273,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
dev->venc_pdata = of_device_get_match_data(&pdev->dev);
ret = mtk_vcodec_init_enc_pm(dev);
if (ret < 0) {
- dev_err(&pdev->dev, "Failed to get mt vcodec clock source!");
+ dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!");
goto err_enc_pm;
}

- for (i = VENC_SYS, j = 0; i < NUM_MAX_VCODEC_REG_BASE; i++, j++) {
- res = platform_get_resource(pdev, IORESOURCE_MEM, j);
- dev->reg_base[i] = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR((__force void *)dev->reg_base[i])) {
- ret = PTR_ERR((__force void *)dev->reg_base[i]);
- goto err_res;
- }
- mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[i]);
- }
+ pm_runtime_enable(&pdev->dev);
+
+ snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
+ dev->venc_pdata->name);

- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (res == NULL) {
- dev_err(&pdev->dev, "failed to get irq resource");
- ret = -ENOENT;
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ reg_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR((__force void *)reg_base)) {
+ ret = PTR_ERR((__force void *)reg_base);
goto err_res;
}
+ dev->reg_base[dev->venc_pdata->core_id] = reg_base;

dev->enc_irq = platform_get_irq(pdev, 0);
ret = devm_request_irq(&pdev->dev, dev->enc_irq,
mtk_vcodec_enc_irq_handler,
0, pdev->name, dev);
if (ret) {
- dev_err(&pdev->dev, "Failed to install dev->enc_irq %d (%d)",
- dev->enc_irq,
- ret);
+ dev_err(&pdev->dev,
+ "Failed to install dev->enc_irq %d (%d) core_id:%d",
+ dev->enc_irq, ret, dev->venc_pdata->core_id);
ret = -EINVAL;
goto err_res;
}
disable_irq(dev->enc_irq);

- if (dev->venc_pdata->has_lt_irq) {
- dev->enc_lt_irq = platform_get_irq(pdev, 1);
- ret = devm_request_irq(&pdev->dev,
- dev->enc_lt_irq,
- mtk_vcodec_enc_lt_irq_handler,
- 0, pdev->name, dev);
- if (ret) {
- dev_err(&pdev->dev,
- "Failed to install dev->enc_lt_irq %d (%d)",
- dev->enc_lt_irq, ret);
- ret = -EINVAL;
- goto err_res;
- }
- disable_irq(dev->enc_lt_irq); /* VENC_LT */
- }
-
mutex_init(&dev->enc_mutex);
mutex_init(&dev->dev_mutex);
spin_lock_init(&dev->irqlock);
-
- snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
- "[MTK_V4L2_VENC]");
-
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
if (ret) {
mtk_v4l2_err("v4l2_device_register err=%d", ret);
@@ -373,7 +331,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
V4L2_CAP_STREAMING;

snprintf(vfd_enc->name, sizeof(vfd_enc->name), "%s",
- MTK_VCODEC_ENC_NAME);
+ dev->venc_pdata->name);
video_set_drvdata(vfd_enc, dev);
dev->vfd_enc = vfd_enc;
platform_set_drvdata(pdev, dev);
@@ -401,8 +359,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_enc_reg;
}

- mtk_v4l2_debug(0, "encoder registered as /dev/video%d",
- vfd_enc->num);
+ mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d",
+ dev->venc_pdata->core_id, vfd_enc->num);

return 0;

@@ -415,26 +373,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
err_enc_alloc:
v4l2_device_unregister(&dev->v4l2_dev);
err_res:
- mtk_vcodec_release_enc_pm(dev);
+ pm_runtime_disable(&pdev->dev);
err_enc_pm:
mtk_vcodec_fw_release(dev->fw_handler);
return ret;
}

-static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
+static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = {
+ .chip = MTK_MT8173,
+ .name = MTK_VCODEC_ENC_NAME,
+ .capture_formats = mtk_video_formats_capture_mt8173_h264,
+ .num_capture_formats = 1,
+ .output_formats = mtk_video_formats_output_mt8173,
+ .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
+ .min_bitrate = 1,
+ .max_bitrate = 4000000,
+ .core_id = VENC_SYS,
+};
+
+static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = {
.chip = MTK_MT8173,
- .has_lt_irq = true,
- .capture_formats = mtk_video_formats_capture_mt8173,
- .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8173),
+ .name = MTK_VENC_VP8_NAME,
+ .capture_formats = mtk_video_formats_capture_mt8173_vp8,
+ .num_capture_formats = 1,
.output_formats = mtk_video_formats_output_mt8173,
.num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
.min_bitrate = 1,
.max_bitrate = 4000000,
+ .core_id = VENC_LT_SYS,
};

static const struct mtk_vcodec_enc_pdata mt8183_pdata = {
.chip = MTK_MT8183,
- .has_lt_irq = false,
+ .name = MTK_VCODEC_ENC_NAME,
.uses_ext = true,
.capture_formats = mtk_video_formats_capture_mt8183,
.num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8183),
@@ -443,10 +414,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
.num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
.min_bitrate = 64,
.max_bitrate = 40000000,
+ .core_id = VENC_SYS,
};

static const struct of_device_id mtk_vcodec_enc_match[] = {
- {.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_pdata},
+ {.compatible = "mediatek,mt8173-vcodec-avc-enc",
+ .data = &mt8173_avc_pdata},
+ {.compatible = "mediatek,mt8173-vcodec-vp8-enc",
+ .data = &mt8173_vp8_pdata},
{.compatible = "mediatek,mt8183-vcodec-enc", .data = &mt8183_pdata},
{},
};
@@ -466,7 +441,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev)
video_unregister_device(dev->vfd_enc);

v4l2_device_unregister(&dev->v4l2_dev);
- mtk_vcodec_release_enc_pm(dev);
+ pm_runtime_disable(&pdev->dev);
mtk_vcodec_fw_release(dev->fw_handler);
return 0;
}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
index ee22902..01c6a55 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
@@ -43,21 +43,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
return -ENODEV;
}
pm->larbvenc = &pdev->dev;
-
- node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
- if (!node) {
- mtk_v4l2_err("no mediatek,larb found");
- return -ENODEV;
- }
-
- pdev = of_find_device_by_node(node);
- of_node_put(node);
- if (!pdev) {
- mtk_v4l2_err("no mediatek,larb device found");
- return -ENODEV;
- }
-
- pm->larbvenclt = &pdev->dev;
pdev = mtkdev->plat_dev;
pm->dev = &pdev->dev;

@@ -94,11 +79,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
return ret;
}

-void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
-{
-}
-
-
void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
{
struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
@@ -116,18 +96,10 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
ret = mtk_smi_larb_get(pm->larbvenc);
if (ret) {
mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
- goto larbvencerr;
- }
- ret = mtk_smi_larb_get(pm->larbvenclt);
- if (ret) {
- mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
- goto larbvenclterr;
+ goto clkerr;
}
return;

-larbvenclterr:
- mtk_smi_larb_put(pm->larbvenc);
-larbvencerr:
clkerr:
for (i -= 1; i >= 0; i--)
clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
@@ -139,7 +111,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
int i = 0;

mtk_smi_larb_put(pm->larbvenc);
- mtk_smi_larb_put(pm->larbvenclt);
for (i = enc_clk->clk_num - 1; i >= 0; i--)
clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
index b7ecdfd..c1b5986 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
@@ -10,7 +10,6 @@
#include "mtk_vcodec_drv.h"

int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *dev);
-void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *dev);

void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
index 11abb19..8267a9c 100644
--- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
+++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
@@ -367,7 +367,7 @@ static int vp8_enc_encode(void *handle,

mtk_vcodec_debug_enter(inst);

- enable_irq(ctx->dev->enc_lt_irq);
+ enable_irq(ctx->dev->enc_irq);

switch (opt) {
case VENC_START_OPT_ENCODE_FRAME:
@@ -386,7 +386,7 @@ static int vp8_enc_encode(void *handle,

encode_err:

- disable_irq(ctx->dev->enc_lt_irq);
+ disable_irq(ctx->dev->enc_irq);
mtk_vcodec_debug_leave(inst);

return ret;
--
1.9.1

2020-05-30 08:16:36

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 09/17] media: mtk-vcodec: Get rid of mtk_smi_larb_get/put

MediaTek IOMMU has already added the device_link between the consumer
and smi-larb device. If the vcodec device call the pm_runtime_get_sync,
the smi-larb's pm_runtime_get_sync also be called automatically.

CC: Tiffany Lin <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
.../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 19 ---------------
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 3 ---
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 1 -
.../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 27 ----------------------
4 files changed, 50 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index 36dfe3f..1d7d14d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -8,14 +8,12 @@
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>
-#include <soc/mediatek/smi.h>

#include "mtk_vcodec_dec_pm.h"
#include "mtk_vcodec_util.h"

int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
{
- struct device_node *node;
struct platform_device *pdev;
struct mtk_vcodec_pm *pm;
struct mtk_vcodec_clk *dec_clk;
@@ -26,18 +24,7 @@ int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
pm = &mtkdev->pm;
pm->mtkdev = mtkdev;
dec_clk = &pm->vdec_clk;
- node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
- if (!node) {
- mtk_v4l2_err("of_parse_phandle mediatek,larb fail!");
- return -1;
- }

- pdev = of_find_device_by_node(node);
- of_node_put(node);
- if (WARN_ON(!pdev)) {
- return -1;
- }
- pm->larbvdec = &pdev->dev;
pdev = mtkdev->plat_dev;
pm->dev = &pdev->dev;

@@ -113,11 +100,6 @@ void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm)
}
}

- ret = mtk_smi_larb_get(pm->larbvdec);
- if (ret) {
- mtk_v4l2_err("mtk_smi_larb_get larbvdec fail %d", ret);
- goto error;
- }
return;

error:
@@ -130,7 +112,6 @@ void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
struct mtk_vcodec_clk *dec_clk = &pm->vdec_clk;
int i = 0;

- mtk_smi_larb_put(pm->larbvdec);
for (i = dec_clk->clk_num - 1; i >= 0; i--)
clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 52d1ce1..7d3966a 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -190,10 +190,7 @@ struct mtk_vcodec_clk {
*/
struct mtk_vcodec_pm {
struct mtk_vcodec_clk vdec_clk;
- struct device *larbvdec;
-
struct mtk_vcodec_clk venc_clk;
- struct device *larbvenc;
struct device *dev;
struct mtk_vcodec_dev *mtkdev;
};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
index 5301dca..18025f7 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
@@ -8,7 +8,6 @@
#include <media/v4l2-event.h>
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>
-#include <soc/mediatek/smi.h>
#include <linux/pm_runtime.h>

#include "mtk_vcodec_drv.h"
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
index 01c6a55..047919e 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
@@ -8,44 +8,25 @@
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>
-#include <soc/mediatek/smi.h>

#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_util.h"

int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
{
- struct device_node *node;
struct platform_device *pdev;
struct mtk_vcodec_pm *pm;
struct mtk_vcodec_clk *enc_clk;
struct mtk_vcodec_clk_info *clk_info;
int ret = 0, i = 0;
- struct device *dev;

pdev = mtkdev->plat_dev;
pm = &mtkdev->pm;
memset(pm, 0, sizeof(struct mtk_vcodec_pm));
pm->mtkdev = mtkdev;
pm->dev = &pdev->dev;
- dev = &pdev->dev;
enc_clk = &pm->venc_clk;

- node = of_parse_phandle(dev->of_node, "mediatek,larb", 0);
- if (!node) {
- mtk_v4l2_err("no mediatek,larb found");
- return -ENODEV;
- }
- pdev = of_find_device_by_node(node);
- of_node_put(node);
- if (!pdev) {
- mtk_v4l2_err("no mediatek,larb device found");
- return -ENODEV;
- }
- pm->larbvenc = &pdev->dev;
- pdev = mtkdev->plat_dev;
- pm->dev = &pdev->dev;
-
enc_clk->clk_num = of_property_count_strings(pdev->dev.of_node,
"clock-names");
if (enc_clk->clk_num > 0) {
@@ -93,13 +74,6 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
}
}

- ret = mtk_smi_larb_get(pm->larbvenc);
- if (ret) {
- mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
- goto clkerr;
- }
- return;
-
clkerr:
for (i -= 1; i >= 0; i--)
clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
@@ -110,7 +84,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
int i = 0;

- mtk_smi_larb_put(pm->larbvenc);
for (i = enc_clk->clk_num - 1; i >= 0; i--)
clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
}
--
1.9.1

2020-05-30 08:16:39

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 01/17] media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.

From: Maoguang Meng <[email protected]>

Update binding document since the avc and vp8 hardware encoder in
mt8173 are now separated. Separate "mediatek,mt8173-vcodec-enc" to
"mediatek,mt8173-vcodec-vp8-enc" and "mediatek,mt8173-vcodec-avc-enc".

This is a preparing patch for smi cleaning up "mediatek,larb".

Signed-off-by: Maoguang Meng <[email protected]>
Signed-off-by: Hsin-Yi Wang <[email protected]>
Signed-off-by: Irui Wang <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
.../devicetree/bindings/media/mediatek-vcodec.txt | 58 ++++++++++++----------
1 file changed, 31 insertions(+), 27 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
index 8093335..1023740 100644
--- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
+++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
@@ -4,7 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
supports high resolution encoding and decoding functionalities.

Required properties:
-- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
+- compatible : must be one of the following string:
+ "mediatek,mt8173-vcodec-vp8-enc" for mt8173 vp8 encoder.
+ "mediatek,mt8173-vcodec-avc-enc" for mt8173 avc encoder.
"mediatek,mt8183-vcodec-enc" for MT8183 encoder.
"mediatek,mt8173-vcodec-dec" for MT8173 decoder.
- reg : Physical base address of the video codec registers and length of
@@ -13,10 +15,11 @@ Required properties:
- mediatek,larb : must contain the local arbiters in the current Socs.
- clocks : list of clock specifiers, corresponding to entries in
the clock-names property.
-- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
- "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
- "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
- "venc_lt_sel", "vdec_bus_clk_src".
+- clock-names:
+ avc venc must contain "venc_sel";
+ vp8 venc must contain "venc_lt_sel";
+ decoder must contain "vcodecpll", "univpll_d2", "clk_cci400_sel",
+ "vdec_sel", "vdecpll", "vencpll", "venc_lt_sel", "vdec_bus_clk_src".
- iommus : should point to the respective IOMMU block with master port as
argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
for details.
@@ -80,14 +83,10 @@ vcodec_dec: vcodec@16000000 {
assigned-clock-rates = <0>, <0>, <0>, <1482000000>, <800000000>;
};

- vcodec_enc: vcodec@18002000 {
- compatible = "mediatek,mt8173-vcodec-enc";
- reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/
- <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
- interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
- <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
- mediatek,larb = <&larb3>,
- <&larb5>;
+vcodec_enc: vcodec@18002000 {
+ compatible = "mediatek,mt8173-vcodec-avc-enc";
+ reg = <0 0x18002000 0 0x1000>;
+ interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
iommus = <&iommu M4U_PORT_VENC_RCPU>,
<&iommu M4U_PORT_VENC_REC>,
<&iommu M4U_PORT_VENC_BSDMA>,
@@ -98,8 +97,20 @@ vcodec_dec: vcodec@16000000 {
<&iommu M4U_PORT_VENC_REF_LUMA>,
<&iommu M4U_PORT_VENC_REF_CHROMA>,
<&iommu M4U_PORT_VENC_NBM_RDMA>,
- <&iommu M4U_PORT_VENC_NBM_WDMA>,
- <&iommu M4U_PORT_VENC_RCPU_SET2>,
+ <&iommu M4U_PORT_VENC_NBM_WDMA>;
+ mediatek,larb = <&larb3>;
+ mediatek,vpu = <&vpu>;
+ clocks = <&topckgen CLK_TOP_VENC_SEL>;
+ clock-names = "venc_sel";
+ assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
+ assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
+ };
+
+vcodec_enc_lt: vcodec@19002000 {
+ compatible = "mediatek,mt8173-vcodec-vp8-enc";
+ reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
+ interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
+ iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
<&iommu M4U_PORT_VENC_REC_FRM_SET2>,
<&iommu M4U_PORT_VENC_BSDMA_SET2>,
<&iommu M4U_PORT_VENC_SV_COMA_SET2>,
@@ -108,17 +119,10 @@ vcodec_dec: vcodec@16000000 {
<&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
<&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
<&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
+ mediatek,larb = <&larb5>;
mediatek,vpu = <&vpu>;
- clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
- <&topckgen CLK_TOP_VENC_SEL>,
- <&topckgen CLK_TOP_UNIVPLL1_D2>,
- <&topckgen CLK_TOP_VENC_LT_SEL>;
- clock-names = "venc_sel_src",
- "venc_sel",
- "venc_lt_sel_src",
- "venc_lt_sel";
- assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
- <&topckgen CLK_TOP_VENC_LT_SEL>;
- assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
- <&topckgen CLK_TOP_UNIVPLL1_D2>;
+ clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
+ clock-names = "venc_lt_sel";
+ assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
+ assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL_370P5>;
};
--
1.9.1

2020-05-30 08:16:48

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 10/17] drm/mediatek: Add pm runtime support for ovl and rdma

From: Yongqiang Niu <[email protected]>

Display use the dispsys device to call pm_rumtime_get_sync before.
This patch add pm_runtime_xx with ovl and rdma device whose nodes has
"iommus" property, then display could help pm_runtime_get for smi via
ovl or rdma device.

This is a preparing patch that smi cleaning up "mediatek,larb".

CC: CK Hu <[email protected]>
Signed-off-by: Yongqiang Niu <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 9 ++++++++-
drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 9 ++++++++-
drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 12 +++++++++++-
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 2 ++
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 1 +
5 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
index 891d80c..17c9baa 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
@@ -11,6 +11,7 @@
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/soc/mediatek/mtk-cmdq.h>

#include "mtk_drm_crtc.h"
@@ -399,9 +400,13 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
return ret;
}

+ pm_runtime_enable(dev);
+
ret = component_add(dev, &mtk_disp_ovl_component_ops);
- if (ret)
+ if (ret) {
+ pm_runtime_disable(dev);
dev_err(dev, "Failed to add component: %d\n", ret);
+ }

return ret;
}
@@ -410,6 +415,8 @@ static int mtk_disp_ovl_remove(struct platform_device *pdev)
{
component_del(&pdev->dev, &mtk_disp_ovl_component_ops);

+ pm_runtime_disable(&pdev->dev);
+
return 0;
}

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
index 0cb848d..5ea8fb6 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
@@ -9,6 +9,7 @@
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/soc/mediatek/mtk-cmdq.h>

#include "mtk_drm_crtc.h"
@@ -313,9 +314,13 @@ static int mtk_disp_rdma_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, priv);

+ pm_runtime_enable(dev);
+
ret = component_add(dev, &mtk_disp_rdma_component_ops);
- if (ret)
+ if (ret) {
+ pm_runtime_disable(dev);
dev_err(dev, "Failed to add component: %d\n", ret);
+ }

return ret;
}
@@ -324,6 +329,8 @@ static int mtk_disp_rdma_remove(struct platform_device *pdev)
{
component_del(&pdev->dev, &mtk_disp_rdma_component_ops);

+ pm_runtime_disable(&pdev->dev);
+
return 0;
}

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index fe85e48..c9bc844 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -538,9 +538,15 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
return;
}

+ ret = pm_runtime_get_sync(comp->dev);
+ if (ret < 0)
+ DRM_DEV_ERROR(comp->dev, "Failed to enable power domain: %d\n",
+ ret);
+
ret = mtk_crtc_ddp_hw_init(mtk_crtc);
if (ret) {
mtk_smi_larb_put(comp->larb_dev);
+ pm_runtime_put(comp->dev);
return;
}

@@ -553,7 +559,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
{
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
- int i;
+ int i, ret;

DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
if (!mtk_crtc->enabled)
@@ -577,6 +583,10 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
drm_crtc_vblank_off(crtc);
mtk_crtc_ddp_hw_fini(mtk_crtc);
mtk_smi_larb_put(comp->larb_dev);
+ ret = pm_runtime_put(comp->dev);
+ if (ret < 0)
+ DRM_DEV_ERROR(comp->dev, "Failed to disable power domain: %d\n",
+ ret);

mtk_crtc->enabled = false;
}
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 57c88de..593027a 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -493,6 +493,8 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,

comp->larb_dev = &larb_pdev->dev;

+ comp->dev = dev;
+
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
if (of_address_to_resource(node, 0, &res) != 0) {
dev_err(dev, "Missing reg in %s node\n", node->full_name);
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
index debe363..4c063e0 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
@@ -99,6 +99,7 @@ struct mtk_ddp_comp {
void __iomem *regs;
int irq;
struct device *larb_dev;
+ struct device *dev;
enum mtk_ddp_comp_id id;
const struct mtk_ddp_comp_funcs *funcs;
resource_size_t regs_pa;
--
1.9.1

2020-05-30 08:17:04

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 11/17] drm/mediatek: Get rid of mtk_smi_larb_get/put

MediaTek IOMMU has already added the device_link between the consumer
and smi-larb device. If the drm device call the pm_runtime_get_sync,
the smi-larb's pm_runtime_get_sync also be called automatically.

CC: CK Hu <[email protected]>
CC: Philipp Zabel <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 9 ---------
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 21 ---------------------
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 1 -
3 files changed, 31 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index c9bc844..d4c4078 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -8,7 +8,6 @@
#include <linux/soc/mediatek/mtk-cmdq.h>

#include <asm/barrier.h>
-#include <soc/mediatek/smi.h>

#include <drm/drm_atomic_helper.h>
#include <drm/drm_plane_helper.h>
@@ -532,12 +531,6 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,

DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);

- ret = mtk_smi_larb_get(comp->larb_dev);
- if (ret) {
- DRM_ERROR("Failed to get larb: %d\n", ret);
- return;
- }
-
ret = pm_runtime_get_sync(comp->dev);
if (ret < 0)
DRM_DEV_ERROR(comp->dev, "Failed to enable power domain: %d\n",
@@ -545,7 +538,6 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,

ret = mtk_crtc_ddp_hw_init(mtk_crtc);
if (ret) {
- mtk_smi_larb_put(comp->larb_dev);
pm_runtime_put(comp->dev);
return;
}
@@ -582,7 +574,6 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,

drm_crtc_vblank_off(crtc);
mtk_crtc_ddp_hw_fini(mtk_crtc);
- mtk_smi_larb_put(comp->larb_dev);
ret = pm_runtime_put(comp->dev);
if (ret < 0)
DRM_DEV_ERROR(comp->dev, "Failed to disable power domain: %d\n",
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 593027a..a6e7f3a 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -432,8 +432,6 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
const struct mtk_ddp_comp_funcs *funcs)
{
enum mtk_ddp_comp_type type;
- struct device_node *larb_node;
- struct platform_device *larb_pdev;
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
struct resource res;
struct cmdq_client_reg cmdq_reg;
@@ -468,31 +466,12 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
if (IS_ERR(comp->clk))
return PTR_ERR(comp->clk);

- /* Only DMA capable components need the LARB property */
- comp->larb_dev = NULL;
if (type != MTK_DISP_OVL &&
type != MTK_DISP_OVL_2L &&
type != MTK_DISP_RDMA &&
type != MTK_DISP_WDMA)
return 0;

- larb_node = of_parse_phandle(node, "mediatek,larb", 0);
- if (!larb_node) {
- dev_err(dev,
- "Missing mediadek,larb phandle in %pOF node\n", node);
- return -EINVAL;
- }
-
- larb_pdev = of_find_device_by_node(larb_node);
- if (!larb_pdev) {
- dev_warn(dev, "Waiting for larb device %pOF\n", larb_node);
- of_node_put(larb_node);
- return -EPROBE_DEFER;
- }
- of_node_put(larb_node);
-
- comp->larb_dev = &larb_pdev->dev;
-
comp->dev = dev;

#if IS_REACHABLE(CONFIG_MTK_CMDQ)
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
index 4c063e0..11c7120 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
@@ -98,7 +98,6 @@ struct mtk_ddp_comp {
struct clk *clk;
void __iomem *regs;
int irq;
- struct device *larb_dev;
struct device *dev;
enum mtk_ddp_comp_id id;
const struct mtk_ddp_comp_funcs *funcs;
--
1.9.1

2020-05-30 08:17:12

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 12/17] memory: mtk-smi: Get rid of mtk_smi_larb_get/put

After adding device_link between the iommu consumer and smi-larb,
the pm_runtime_get(_sync) of smi-larb and smi-common will be called
automatically. we can get rid of mtk_smi_larb_get/put.

CC: Matthias Brugger <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
drivers/memory/mtk-smi.c | 14 --------------
include/soc/mediatek/smi.h | 20 --------------------
2 files changed, 34 deletions(-)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 6cdefda..19c3949 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -125,20 +125,6 @@ static void mtk_smi_clk_disable(const struct mtk_smi *smi)
clk_disable_unprepare(smi->clk_apb);
}

-int mtk_smi_larb_get(struct device *larbdev)
-{
- int ret = pm_runtime_get_sync(larbdev);
-
- return (ret < 0) ? ret : 0;
-}
-EXPORT_SYMBOL_GPL(mtk_smi_larb_get);
-
-void mtk_smi_larb_put(struct device *larbdev)
-{
- pm_runtime_put_sync(larbdev);
-}
-EXPORT_SYMBOL_GPL(mtk_smi_larb_put);
-
static int
mtk_smi_larb_bind(struct device *dev, struct device *master, void *data)
{
diff --git a/include/soc/mediatek/smi.h b/include/soc/mediatek/smi.h
index 5a34b87..f8bf595 100644
--- a/include/soc/mediatek/smi.h
+++ b/include/soc/mediatek/smi.h
@@ -20,26 +20,6 @@ struct mtk_smi_larb_iommu {
unsigned int mmu;
};

-/*
- * mtk_smi_larb_get: Enable the power domain and clocks for this local arbiter.
- * It also initialize some basic setting(like iommu).
- * mtk_smi_larb_put: Disable the power domain and clocks for this local arbiter.
- * Both should be called in non-atomic context.
- *
- * Returns 0 if successful, negative on failure.
- */
-int mtk_smi_larb_get(struct device *larbdev);
-void mtk_smi_larb_put(struct device *larbdev);
-
-#else
-
-static inline int mtk_smi_larb_get(struct device *larbdev)
-{
- return 0;
-}
-
-static inline void mtk_smi_larb_put(struct device *larbdev) { }
-
#endif

#endif
--
1.9.1

2020-05-30 08:18:27

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 17/17] arm64: dts: mediatek: Get rid of mediatek,larb for MM nodes

After adding device_link between the IOMMU consumer and smi,
the mediatek,larb is unnecessary now.

CC: Matthias Brugger <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
arch/arm64/boot/dts/mediatek/mt8173.dtsi | 16 ----------------
1 file changed, 16 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 9fccbec..7eed8c8 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -926,7 +926,6 @@
<&mmsys CLK_MM_MUTEX_32K>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_RDMA0>;
- mediatek,larb = <&larb0>;
mediatek,vpu = <&vpu>;
};

@@ -937,7 +936,6 @@
<&mmsys CLK_MM_MUTEX_32K>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_RDMA1>;
- mediatek,larb = <&larb4>;
};

mdp_rsz0: rsz@14003000 {
@@ -967,7 +965,6 @@
clocks = <&mmsys CLK_MM_MDP_WDMA>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WDMA>;
- mediatek,larb = <&larb0>;
};

mdp_wrot0: wrot@14007000 {
@@ -976,7 +973,6 @@
clocks = <&mmsys CLK_MM_MDP_WROT0>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WROT0>;
- mediatek,larb = <&larb0>;
};

mdp_wrot1: wrot@14008000 {
@@ -985,7 +981,6 @@
clocks = <&mmsys CLK_MM_MDP_WROT1>;
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
iommus = <&iommu M4U_PORT_MDP_WROT1>;
- mediatek,larb = <&larb4>;
};

ovl0: ovl@1400c000 {
@@ -995,7 +990,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_OVL0>;
iommus = <&iommu M4U_PORT_DISP_OVL0>;
- mediatek,larb = <&larb0>;
};

ovl1: ovl@1400d000 {
@@ -1005,7 +999,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_OVL1>;
iommus = <&iommu M4U_PORT_DISP_OVL1>;
- mediatek,larb = <&larb4>;
};

rdma0: rdma@1400e000 {
@@ -1015,7 +1008,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA0>;
iommus = <&iommu M4U_PORT_DISP_RDMA0>;
- mediatek,larb = <&larb0>;
};

rdma1: rdma@1400f000 {
@@ -1025,7 +1017,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA1>;
iommus = <&iommu M4U_PORT_DISP_RDMA1>;
- mediatek,larb = <&larb4>;
};

rdma2: rdma@14010000 {
@@ -1035,7 +1026,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_RDMA2>;
iommus = <&iommu M4U_PORT_DISP_RDMA2>;
- mediatek,larb = <&larb4>;
};

wdma0: wdma@14011000 {
@@ -1045,7 +1035,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_WDMA0>;
iommus = <&iommu M4U_PORT_DISP_WDMA0>;
- mediatek,larb = <&larb0>;
};

wdma1: wdma@14012000 {
@@ -1055,7 +1044,6 @@
power-domains = <&scpsys MT8173_POWER_DOMAIN_MM>;
clocks = <&mmsys CLK_MM_DISP_WDMA1>;
iommus = <&iommu M4U_PORT_DISP_WDMA1>;
- mediatek,larb = <&larb4>;
};

color0: color@14013000 {
@@ -1299,7 +1287,6 @@
<0 0x16027800 0 0x800>, /* VDEC_HWB */
<0 0x16028400 0 0x400>; /* VDEC_HWG */
interrupts = <GIC_SPI 204 IRQ_TYPE_LEVEL_LOW>;
- mediatek,larb = <&larb1>;
iommus = <&iommu M4U_PORT_HW_VDEC_MC_EXT>,
<&iommu M4U_PORT_HW_VDEC_PP_EXT>,
<&iommu M4U_PORT_HW_VDEC_AVC_MV_EXT>,
@@ -1367,7 +1354,6 @@
compatible = "mediatek,mt8173-vcodec-avc-enc";
reg = <0 0x18002000 0 0x1000>; /* VENC_SYS */
interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
- mediatek,larb = <&larb3>;
iommus = <&iommu M4U_PORT_VENC_RCPU>,
<&iommu M4U_PORT_VENC_REC>,
<&iommu M4U_PORT_VENC_BSDMA>,
@@ -1395,7 +1381,6 @@
clock-names = "jpgdec-smi",
"jpgdec";
power-domains = <&scpsys MT8173_POWER_DOMAIN_VENC>;
- mediatek,larb = <&larb3>;
iommus = <&iommu M4U_PORT_JPGDEC_WDMA>,
<&iommu M4U_PORT_JPGDEC_BSDMA>;
};
@@ -1429,7 +1414,6 @@
<&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
<&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
<&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
- mediatek,larb = <&larb5>;
mediatek,vpu = <&vpu>;
clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
clock-names = "venc_lt_sel";
--
1.9.1

2020-05-30 08:18:57

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 16/17] arm64: dts: mt8173: Separate mtk-vcodec-enc node

From: Irui Wang <[email protected]>

There are two separate hardware encoder blocks inside MT8173. Split
the current mtk-vcodec-enc node to match the hardware architecture.

Signed-off-by: Irui Wang <[email protected]>
Signed-off-by: Hsin-Yi Wang <[email protected]>
---
arch/arm64/boot/dts/mediatek/mt8173.dtsi | 60 +++++++++++++++++---------------
1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index fb21a6b..9fccbec 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -1364,13 +1364,10 @@
};

vcodec_enc: vcodec@18002000 {
- compatible = "mediatek,mt8173-vcodec-enc";
- reg = <0 0x18002000 0 0x1000>, /* VENC_SYS */
- <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
- interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
- <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
- mediatek,larb = <&larb3>,
- <&larb5>;
+ compatible = "mediatek,mt8173-vcodec-avc-enc";
+ reg = <0 0x18002000 0 0x1000>; /* VENC_SYS */
+ interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
+ mediatek,larb = <&larb3>;
iommus = <&iommu M4U_PORT_VENC_RCPU>,
<&iommu M4U_PORT_VENC_REC>,
<&iommu M4U_PORT_VENC_BSDMA>,
@@ -1381,29 +1378,12 @@
<&iommu M4U_PORT_VENC_REF_LUMA>,
<&iommu M4U_PORT_VENC_REF_CHROMA>,
<&iommu M4U_PORT_VENC_NBM_RDMA>,
- <&iommu M4U_PORT_VENC_NBM_WDMA>,
- <&iommu M4U_PORT_VENC_RCPU_SET2>,
- <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
- <&iommu M4U_PORT_VENC_BSDMA_SET2>,
- <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
- <&iommu M4U_PORT_VENC_RD_COMA_SET2>,
- <&iommu M4U_PORT_VENC_CUR_LUMA_SET2>,
- <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
- <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
- <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
+ <&iommu M4U_PORT_VENC_NBM_WDMA>;
mediatek,vpu = <&vpu>;
- clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
- <&topckgen CLK_TOP_VENC_SEL>,
- <&topckgen CLK_TOP_UNIVPLL1_D2>,
- <&topckgen CLK_TOP_VENC_LT_SEL>;
- clock-names = "venc_sel_src",
- "venc_sel",
- "venc_lt_sel_src",
- "venc_lt_sel";
- assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
- <&topckgen CLK_TOP_VENC_LT_SEL>;
- assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
- <&topckgen CLK_TOP_UNIVPLL1_D2>;
+ clocks = <&topckgen CLK_TOP_VENC_SEL>;
+ clock-names = "venc_sel";
+ assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
+ assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
};

jpegdec: jpegdec@18004000 {
@@ -1435,6 +1415,28 @@
<&vencltsys CLK_VENCLT_CKE0>;
clock-names = "apb", "smi";
};
+
+ vcodec_enc_lt: vcodec@19002000 {
+ compatible = "mediatek,mt8173-vcodec-vp8-enc";
+ reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
+ interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
+ iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
+ <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
+ <&iommu M4U_PORT_VENC_BSDMA_SET2>,
+ <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
+ <&iommu M4U_PORT_VENC_RD_COMA_SET2>,
+ <&iommu M4U_PORT_VENC_CUR_LUMA_SET2>,
+ <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
+ <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
+ <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
+ mediatek,larb = <&larb5>;
+ mediatek,vpu = <&vpu>;
+ clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
+ clock-names = "venc_lt_sel";
+ assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
+ assigned-clock-parents = <&topckgen
+ CLK_TOP_VCODECPLL_370P5>;
+ };
};
};

--
1.9.1

2020-05-30 08:19:22

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 13/17] iommu/mediatek: Use module_platform_driver

MediaTek IOMMU should wait for smi larb which need wait for the
power domain(mtk-scpsys.c) and the multimedia ccf, both are module
init. Thus, subsys_initcall for MediaTek IOMMU is not helpful.
Switch to module_platform_driver.

Correspondingly, add the module license information.

Signed-off-by: Yong Wu <[email protected]>
---
for iommu v1: honghui's mail address is not valid now. I will be
responsible for that file too, So I add myself in it.
---
drivers/iommu/mtk_iommu.c | 18 ++++++------------
drivers/iommu/mtk_iommu_v1.c | 12 +++++++-----
2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 5c3a6ba..0740ca9 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -15,6 +15,7 @@
#include <linux/iommu.h>
#include <linux/iopoll.h>
#include <linux/list.h>
+#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_iommu.h>
#include <linux/of_irq.h>
@@ -823,16 +824,9 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)
.pm = &mtk_iommu_pm_ops,
}
};
+module_platform_driver(mtk_iommu_driver);

-static int __init mtk_iommu_init(void)
-{
- int ret;
-
- ret = platform_driver_register(&mtk_iommu_driver);
- if (ret != 0)
- pr_err("Failed to register MTK IOMMU driver\n");
-
- return ret;
-}
-
-subsys_initcall(mtk_iommu_init)
+MODULE_DESCRIPTION("IOMMU API for MediaTek M4U implementations");
+MODULE_AUTHOR("Yong Wu <[email protected]>");
+MODULE_ALIAS("platform:MediaTek-M4U");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c
index 26b6c79..0852cb3 100644
--- a/drivers/iommu/mtk_iommu_v1.c
+++ b/drivers/iommu/mtk_iommu_v1.c
@@ -20,6 +20,7 @@
#include <linux/iommu.h>
#include <linux/iopoll.h>
#include <linux/list.h>
+#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_iommu.h>
#include <linux/of_irq.h>
@@ -711,9 +712,10 @@ static int __maybe_unused mtk_iommu_resume(struct device *dev)
.pm = &mtk_iommu_pm_ops,
}
};
+module_platform_driver(mtk_iommu_driver);

-static int __init m4u_init(void)
-{
- return platform_driver_register(&mtk_iommu_driver);
-}
-subsys_initcall(m4u_init);
+MODULE_DESCRIPTION("IOMMU API for MediaTek M4U v1 implementations");
+MODULE_AUTHOR("Yong Wu <[email protected]>");
+MODULE_AUTHOR("Honghui Zhang <[email protected]>");
+MODULE_ALIAS("platform:MediaTek-M4U-v1");
+MODULE_LICENSE("GPL v2");
--
1.9.1

2020-05-30 08:19:29

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 14/17] memory: mtk-smi: Use device_is_bound to check if smi-common is ready

smi-larb driver should run after smi-common, Use device_is_bound to confirm
whether smicommon driver is ready.

CC: Matthias Brugger <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
---
drivers/memory/mtk-smi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c
index 19c3949..0f8cd50 100644
--- a/drivers/memory/mtk-smi.c
+++ b/drivers/memory/mtk-smi.c
@@ -296,8 +296,14 @@ static int mtk_smi_larb_probe(struct platform_device *pdev)
smi_pdev = of_find_device_by_node(smi_node);
of_node_put(smi_node);
if (smi_pdev) {
- if (!platform_get_drvdata(smi_pdev))
+ bool smicommon_is_bound;
+
+ device_lock(&smi_pdev->dev);
+ smicommon_is_bound = device_is_bound(&smi_pdev->dev);
+ device_unlock(&smi_pdev->dev);
+ if (!smicommon_is_bound)
return -EPROBE_DEFER;
+
larb->smi_common_dev = &smi_pdev->dev;
link = device_link_add(dev, larb->smi_common_dev,
DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
--
1.9.1

2020-05-30 08:19:37

by Yong Wu (吴勇)

[permalink] [raw]
Subject: [PATCH v4 15/17] arm: dts: mediatek: Get rid of mediatek,larb for MM nodes

After adding device_link between the IOMMU consumer and smi,
the mediatek,larb is unnecessary now.

CC: Matthias Brugger <[email protected]>
Signed-off-by: Yong Wu <[email protected]>
Reviewed-by: Evan Green <[email protected]>
---
arch/arm/boot/dts/mt2701.dtsi | 1 -
arch/arm/boot/dts/mt7623.dtsi | 1 -
2 files changed, 2 deletions(-)

diff --git a/arch/arm/boot/dts/mt2701.dtsi b/arch/arm/boot/dts/mt2701.dtsi
index 2093b38..79da94c 100644
--- a/arch/arm/boot/dts/mt2701.dtsi
+++ b/arch/arm/boot/dts/mt2701.dtsi
@@ -564,7 +564,6 @@
clock-names = "jpgdec-smi",
"jpgdec";
power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
- mediatek,larb = <&larb2>;
iommus = <&iommu MT2701_M4U_PORT_JPGDEC_WDMA>,
<&iommu MT2701_M4U_PORT_JPGDEC_BSDMA>;
};
diff --git a/arch/arm/boot/dts/mt7623.dtsi b/arch/arm/boot/dts/mt7623.dtsi
index f76b4a3..f334039 100644
--- a/arch/arm/boot/dts/mt7623.dtsi
+++ b/arch/arm/boot/dts/mt7623.dtsi
@@ -783,7 +783,6 @@
clock-names = "jpgdec-smi",
"jpgdec";
power-domains = <&scpsys MT2701_POWER_DOMAIN_ISP>;
- mediatek,larb = <&larb2>;
iommus = <&iommu MT2701_M4U_PORT_JPGDEC_WDMA>,
<&iommu MT2701_M4U_PORT_JPGDEC_BSDMA>;
};
--
1.9.1

2020-05-30 11:10:19

by Chun-Kuang Hu

[permalink] [raw]
Subject: Re: [PATCH v4 10/17] drm/mediatek: Add pm runtime support for ovl and rdma

Hi, Yong:

Yong Wu <[email protected]> 於 2020年5月30日 週六 下午4:26寫道:
>
> From: Yongqiang Niu <[email protected]>
>
> Display use the dispsys device to call pm_rumtime_get_sync before.
> This patch add pm_runtime_xx with ovl and rdma device whose nodes has
> "iommus" property, then display could help pm_runtime_get for smi via
> ovl or rdma device.
>
> This is a preparing patch that smi cleaning up "mediatek,larb".
>

Acked-by: Chun-Kuang Hu <[email protected]>

> CC: CK Hu <[email protected]>
> Signed-off-by: Yongqiang Niu <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> ---
> drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 9 ++++++++-
> drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 9 ++++++++-
> drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 12 +++++++++++-
> drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 2 ++
> drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 1 +
> 5 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> index 891d80c..17c9baa 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
> @@ -11,6 +11,7 @@
> #include <linux/of_device.h>
> #include <linux/of_irq.h>
> #include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
> #include <linux/soc/mediatek/mtk-cmdq.h>
>
> #include "mtk_drm_crtc.h"
> @@ -399,9 +400,13 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
> return ret;
> }
>
> + pm_runtime_enable(dev);
> +
> ret = component_add(dev, &mtk_disp_ovl_component_ops);
> - if (ret)
> + if (ret) {
> + pm_runtime_disable(dev);
> dev_err(dev, "Failed to add component: %d\n", ret);
> + }
>
> return ret;
> }
> @@ -410,6 +415,8 @@ static int mtk_disp_ovl_remove(struct platform_device *pdev)
> {
> component_del(&pdev->dev, &mtk_disp_ovl_component_ops);
>
> + pm_runtime_disable(&pdev->dev);
> +
> return 0;
> }
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> index 0cb848d..5ea8fb6 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> @@ -9,6 +9,7 @@
> #include <linux/of_device.h>
> #include <linux/of_irq.h>
> #include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
> #include <linux/soc/mediatek/mtk-cmdq.h>
>
> #include "mtk_drm_crtc.h"
> @@ -313,9 +314,13 @@ static int mtk_disp_rdma_probe(struct platform_device *pdev)
>
> platform_set_drvdata(pdev, priv);
>
> + pm_runtime_enable(dev);
> +
> ret = component_add(dev, &mtk_disp_rdma_component_ops);
> - if (ret)
> + if (ret) {
> + pm_runtime_disable(dev);
> dev_err(dev, "Failed to add component: %d\n", ret);
> + }
>
> return ret;
> }
> @@ -324,6 +329,8 @@ static int mtk_disp_rdma_remove(struct platform_device *pdev)
> {
> component_del(&pdev->dev, &mtk_disp_rdma_component_ops);
>
> + pm_runtime_disable(&pdev->dev);
> +
> return 0;
> }
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index fe85e48..c9bc844 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -538,9 +538,15 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
> return;
> }
>
> + ret = pm_runtime_get_sync(comp->dev);
> + if (ret < 0)
> + DRM_DEV_ERROR(comp->dev, "Failed to enable power domain: %d\n",
> + ret);
> +
> ret = mtk_crtc_ddp_hw_init(mtk_crtc);
> if (ret) {
> mtk_smi_larb_put(comp->larb_dev);
> + pm_runtime_put(comp->dev);
> return;
> }
>
> @@ -553,7 +559,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
> {
> struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
> struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
> - int i;
> + int i, ret;
>
> DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
> if (!mtk_crtc->enabled)
> @@ -577,6 +583,10 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
> drm_crtc_vblank_off(crtc);
> mtk_crtc_ddp_hw_fini(mtk_crtc);
> mtk_smi_larb_put(comp->larb_dev);
> + ret = pm_runtime_put(comp->dev);
> + if (ret < 0)
> + DRM_DEV_ERROR(comp->dev, "Failed to disable power domain: %d\n",
> + ret);
>
> mtk_crtc->enabled = false;
> }
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 57c88de..593027a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -493,6 +493,8 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
>
> comp->larb_dev = &larb_pdev->dev;
>
> + comp->dev = dev;
> +
> #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> if (of_address_to_resource(node, 0, &res) != 0) {
> dev_err(dev, "Missing reg in %s node\n", node->full_name);
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> index debe363..4c063e0 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> @@ -99,6 +99,7 @@ struct mtk_ddp_comp {
> void __iomem *regs;
> int irq;
> struct device *larb_dev;
> + struct device *dev;
> enum mtk_ddp_comp_id id;
> const struct mtk_ddp_comp_funcs *funcs;
> resource_size_t regs_pa;
> --
> 1.9.1
> _______________________________________________
> Linux-mediatek mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-mediatek

2020-05-30 11:10:56

by Chun-Kuang Hu

[permalink] [raw]
Subject: Re: [PATCH v4 11/17] drm/mediatek: Get rid of mtk_smi_larb_get/put

Hi, Yong:

Yong Wu <[email protected]> 於 2020年5月30日 週六 下午4:27寫道:
>
> MediaTek IOMMU has already added the device_link between the consumer
> and smi-larb device. If the drm device call the pm_runtime_get_sync,
> the smi-larb's pm_runtime_get_sync also be called automatically.
>

Acked-by: Chun-Kuang Hu <[email protected]>

> CC: CK Hu <[email protected]>
> CC: Philipp Zabel <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> Reviewed-by: Evan Green <[email protected]>
> ---
> drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 9 ---------
> drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 21 ---------------------
> drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 1 -
> 3 files changed, 31 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index c9bc844..d4c4078 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -8,7 +8,6 @@
> #include <linux/soc/mediatek/mtk-cmdq.h>
>
> #include <asm/barrier.h>
> -#include <soc/mediatek/smi.h>
>
> #include <drm/drm_atomic_helper.h>
> #include <drm/drm_plane_helper.h>
> @@ -532,12 +531,6 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
>
> DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
>
> - ret = mtk_smi_larb_get(comp->larb_dev);
> - if (ret) {
> - DRM_ERROR("Failed to get larb: %d\n", ret);
> - return;
> - }
> -
> ret = pm_runtime_get_sync(comp->dev);
> if (ret < 0)
> DRM_DEV_ERROR(comp->dev, "Failed to enable power domain: %d\n",
> @@ -545,7 +538,6 @@ static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
>
> ret = mtk_crtc_ddp_hw_init(mtk_crtc);
> if (ret) {
> - mtk_smi_larb_put(comp->larb_dev);
> pm_runtime_put(comp->dev);
> return;
> }
> @@ -582,7 +574,6 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
>
> drm_crtc_vblank_off(crtc);
> mtk_crtc_ddp_hw_fini(mtk_crtc);
> - mtk_smi_larb_put(comp->larb_dev);
> ret = pm_runtime_put(comp->dev);
> if (ret < 0)
> DRM_DEV_ERROR(comp->dev, "Failed to disable power domain: %d\n",
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 593027a..a6e7f3a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -432,8 +432,6 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
> const struct mtk_ddp_comp_funcs *funcs)
> {
> enum mtk_ddp_comp_type type;
> - struct device_node *larb_node;
> - struct platform_device *larb_pdev;
> #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> struct resource res;
> struct cmdq_client_reg cmdq_reg;
> @@ -468,31 +466,12 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
> if (IS_ERR(comp->clk))
> return PTR_ERR(comp->clk);
>
> - /* Only DMA capable components need the LARB property */
> - comp->larb_dev = NULL;
> if (type != MTK_DISP_OVL &&
> type != MTK_DISP_OVL_2L &&
> type != MTK_DISP_RDMA &&
> type != MTK_DISP_WDMA)
> return 0;
>
> - larb_node = of_parse_phandle(node, "mediatek,larb", 0);
> - if (!larb_node) {
> - dev_err(dev,
> - "Missing mediadek,larb phandle in %pOF node\n", node);
> - return -EINVAL;
> - }
> -
> - larb_pdev = of_find_device_by_node(larb_node);
> - if (!larb_pdev) {
> - dev_warn(dev, "Waiting for larb device %pOF\n", larb_node);
> - of_node_put(larb_node);
> - return -EPROBE_DEFER;
> - }
> - of_node_put(larb_node);
> -
> - comp->larb_dev = &larb_pdev->dev;
> -
> comp->dev = dev;
>
> #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> index 4c063e0..11c7120 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> @@ -98,7 +98,6 @@ struct mtk_ddp_comp {
> struct clk *clk;
> void __iomem *regs;
> int irq;
> - struct device *larb_dev;
> struct device *dev;
> enum mtk_ddp_comp_id id;
> const struct mtk_ddp_comp_funcs *funcs;
> --
> 1.9.1
> _______________________________________________
> Linux-mediatek mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-mediatek

2020-06-09 21:23:42

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v4 01/17] media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.

On Sat, May 30, 2020 at 04:10:02PM +0800, Yong Wu wrote:
> From: Maoguang Meng <[email protected]>
>
> Update binding document since the avc and vp8 hardware encoder in
> mt8173 are now separated. Separate "mediatek,mt8173-vcodec-enc" to
> "mediatek,mt8173-vcodec-vp8-enc" and "mediatek,mt8173-vcodec-avc-enc".

The h/w suddenly split in 2? You are breaking compatibility. Up to the
Mediatek maintainers to decide if that's okay, but you need to state you
are breaking compatibility (here and in the driver) and why that is
okay.

>
> This is a preparing patch for smi cleaning up "mediatek,larb".
>
> Signed-off-by: Maoguang Meng <[email protected]>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Signed-off-by: Irui Wang <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> ---
> .../devicetree/bindings/media/mediatek-vcodec.txt | 58 ++++++++++++----------
> 1 file changed, 31 insertions(+), 27 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> index 8093335..1023740 100644
> --- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> +++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> @@ -4,7 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
> supports high resolution encoding and decoding functionalities.
>
> Required properties:
> -- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
> +- compatible : must be one of the following string:
> + "mediatek,mt8173-vcodec-vp8-enc" for mt8173 vp8 encoder.
> + "mediatek,mt8173-vcodec-avc-enc" for mt8173 avc encoder.
> "mediatek,mt8183-vcodec-enc" for MT8183 encoder.
> "mediatek,mt8173-vcodec-dec" for MT8173 decoder.
> - reg : Physical base address of the video codec registers and length of
> @@ -13,10 +15,11 @@ Required properties:
> - mediatek,larb : must contain the local arbiters in the current Socs.
> - clocks : list of clock specifiers, corresponding to entries in
> the clock-names property.
> -- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
> - "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
> - "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
> - "venc_lt_sel", "vdec_bus_clk_src".
> +- clock-names:
> + avc venc must contain "venc_sel";
> + vp8 venc must contain "venc_lt_sel";
> + decoder must contain "vcodecpll", "univpll_d2", "clk_cci400_sel",
> + "vdec_sel", "vdecpll", "vencpll", "venc_lt_sel", "vdec_bus_clk_src".
> - iommus : should point to the respective IOMMU block with master port as
> argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
> for details.
> @@ -80,14 +83,10 @@ vcodec_dec: vcodec@16000000 {
> assigned-clock-rates = <0>, <0>, <0>, <1482000000>, <800000000>;
> };
>
> - vcodec_enc: vcodec@18002000 {
> - compatible = "mediatek,mt8173-vcodec-enc";
> - reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/
> - <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
> - interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
> - <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> - mediatek,larb = <&larb3>,
> - <&larb5>;
> +vcodec_enc: vcodec@18002000 {
> + compatible = "mediatek,mt8173-vcodec-avc-enc";
> + reg = <0 0x18002000 0 0x1000>;
> + interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
> iommus = <&iommu M4U_PORT_VENC_RCPU>,
> <&iommu M4U_PORT_VENC_REC>,
> <&iommu M4U_PORT_VENC_BSDMA>,
> @@ -98,8 +97,20 @@ vcodec_dec: vcodec@16000000 {
> <&iommu M4U_PORT_VENC_REF_LUMA>,
> <&iommu M4U_PORT_VENC_REF_CHROMA>,
> <&iommu M4U_PORT_VENC_NBM_RDMA>,
> - <&iommu M4U_PORT_VENC_NBM_WDMA>,
> - <&iommu M4U_PORT_VENC_RCPU_SET2>,
> + <&iommu M4U_PORT_VENC_NBM_WDMA>;
> + mediatek,larb = <&larb3>;
> + mediatek,vpu = <&vpu>;
> + clocks = <&topckgen CLK_TOP_VENC_SEL>;
> + clock-names = "venc_sel";
> + assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
> + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
> + };
> +
> +vcodec_enc_lt: vcodec@19002000 {
> + compatible = "mediatek,mt8173-vcodec-vp8-enc";
> + reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
> + interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> + iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
> <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
> <&iommu M4U_PORT_VENC_BSDMA_SET2>,
> <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
> @@ -108,17 +119,10 @@ vcodec_dec: vcodec@16000000 {
> <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
> <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
> <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
> + mediatek,larb = <&larb5>;
> mediatek,vpu = <&vpu>;
> - clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
> - <&topckgen CLK_TOP_VENC_SEL>,
> - <&topckgen CLK_TOP_UNIVPLL1_D2>,
> - <&topckgen CLK_TOP_VENC_LT_SEL>;
> - clock-names = "venc_sel_src",
> - "venc_sel",
> - "venc_lt_sel_src",
> - "venc_lt_sel";
> - assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
> - <&topckgen CLK_TOP_VENC_LT_SEL>;
> - assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
> - <&topckgen CLK_TOP_UNIVPLL1_D2>;
> + clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> + clock-names = "venc_lt_sel";
> + assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL_370P5>;
> };
> --
> 1.9.1

2020-06-10 05:47:47

by CK Hu (胡俊光)

[permalink] [raw]
Subject: Re: [PATCH v4 08/17] media: mtk-vcodec: separate mtk-vcodec-enc node.

+ Tiffany & Maoguang.


On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> From: Maoguang Meng <[email protected]>
>
> MTK H264 Encoder(VENC_SYS) and VP8 Encoder(VENC_LT_SYS) are two
> independent hardware instance. They have their owner interrupt,
> register mapping, and special clocks.
>
> This patch seperates the two instance. This is a preparing patch for
> adding device_link between the larbs and venc-device. It's mainly for
> fixing the problem:
> https://lkml.org/lkml/2019/9/3/316
>
> User Call "VIDIOC_QUERYCAP":
> H264 Encoder return driver name "mtk-vcodec-enc";
> VP8 Encoder return driver name "mtk-venc-vp8.
>
> Signed-off-by: Maoguang Meng <[email protected]>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Signed-off-by: Irui Wang <[email protected]>
> ---
> drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 10 +-
> drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 23 +++-
> .../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 127 +++++++++------------
> .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 31 +----
> .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 1 -
> .../media/platform/mtk-vcodec/venc/venc_vp8_if.c | 4 +-
> 6 files changed, 80 insertions(+), 116 deletions(-)
>
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> index a2716117..52d1ce1 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> @@ -19,6 +19,7 @@
> #define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv"
> #define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
> #define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
> +#define MTK_VENC_VP8_NAME "mtk-venc-vp8"
> #define MTK_PLATFORM_STR "platform:mt8173"
>
> #define MTK_VCODEC_MAX_PLANES 3
> @@ -193,7 +194,6 @@ struct mtk_vcodec_pm {
>
> struct mtk_vcodec_clk venc_clk;
> struct device *larbvenc;
> - struct device *larbvenclt;
> struct device *dev;
> struct mtk_vcodec_dev *mtkdev;
> };
> @@ -311,25 +311,27 @@ enum mtk_chip {
> * @chip: chip this encoder is compatible with
> *
> * @uses_ext: whether the encoder uses the extended firmware messaging format
> - * @has_lt_irq: whether the encoder uses the LT irq
> + * @name: whether the encoder core is vp8
> * @min_birate: minimum supported encoding bitrate
> * @max_bitrate: maximum supported encoding bitrate
> * @capture_formats: array of supported capture formats
> * @num_capture_formats: number of entries in capture_formats
> * @output_formats: array of supported output formats
> * @num_output_formats: number of entries in output_formats
> + * @core_id: stand for h264 or vp8 encode index
> */
> struct mtk_vcodec_enc_pdata {
> enum mtk_chip chip;
>
> bool uses_ext;
> - bool has_lt_irq;
> + const char *name;
> unsigned long min_bitrate;
> unsigned long max_bitrate;
> const struct mtk_video_fmt *capture_formats;
> size_t num_capture_formats;
> const struct mtk_video_fmt *output_formats;
> size_t num_output_formats;
> + int core_id;
> };
>
> /**
> @@ -359,7 +361,6 @@ struct mtk_vcodec_enc_pdata {
> *
> * @dec_irq: decoder irq resource
> * @enc_irq: h264 encoder irq resource
> - * @enc_lt_irq: vp8 encoder irq resource
> *
> * @dec_mutex: decoder hardware lock
> * @enc_mutex: encoder hardware lock.
> @@ -395,7 +396,6 @@ struct mtk_vcodec_dev {
>
> int dec_irq;
> int enc_irq;
> - int enc_lt_irq;
>
> struct mutex dec_mutex;
> struct mutex enc_mutex;
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index f0af78f..5301dca 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -9,6 +9,7 @@
> #include <media/v4l2-mem2mem.h>
> #include <media/videobuf2-dma-contig.h>
> #include <soc/mediatek/smi.h>
> +#include <linux/pm_runtime.h>
>
> #include "mtk_vcodec_drv.h"
> #include "mtk_vcodec_enc.h"
> @@ -174,7 +175,10 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
> static int vidioc_venc_querycap(struct file *file, void *priv,
> struct v4l2_capability *cap)
> {
> - strscpy(cap->driver, MTK_VCODEC_ENC_NAME, sizeof(cap->driver));
> + const struct mtk_vcodec_enc_pdata *pdata =
> + fh_to_ctx(priv)->dev->venc_pdata;
> +
> + strscpy(cap->driver, pdata->name, sizeof(cap->driver));
> strscpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
> strscpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));
>
> @@ -788,7 +792,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> */
> if ((ctx->state == MTK_STATE_ABORT) || (ctx->state == MTK_STATE_FREE)) {
> ret = -EIO;
> - goto err_set_param;
> + goto err_start_stream;
> }
>
> /* Do the initialization when both start_streaming have been called */
> @@ -800,6 +804,12 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> return 0;
> }
>
> + ret = pm_runtime_get_sync(&ctx->dev->plat_dev->dev);
> + if (ret < 0) {
> + mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
> + goto err_start_stream;
> + }
> +
> mtk_venc_set_param(ctx, &param);
> ret = venc_if_set_param(ctx, VENC_SET_PARAM_ENC, &param);
> if (ret) {
> @@ -826,6 +836,11 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> return 0;
>
> err_set_param:
> + ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> + if (ret < 0)
> + mtk_v4l2_err("pm_runtime_put fail %d", ret);
> +
> +err_start_stream:
> for (i = 0; i < q->num_buffers; ++i) {
> struct vb2_buffer *buf = vb2_get_buffer(q, i);
>
> @@ -879,6 +894,10 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
> if (ret)
> mtk_v4l2_err("venc_if_deinit failed=%d", ret);
>
> + ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> + if (ret < 0)
> + mtk_v4l2_err("pm_runtime_put fail %d", ret);
> +
> ctx->state = MTK_STATE_FREE;
> }
>
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> index b8fe408..fe17f0c 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> @@ -49,12 +49,15 @@
> },
> };
>
> -static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] = {
> +static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_h264[] = {
> {
> .fourcc = V4L2_PIX_FMT_H264,
> .type = MTK_FMT_ENC,
> .num_planes = 1,
> },
> +};
> +
> +static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_vp8[] = {
> {
> .fourcc = V4L2_PIX_FMT_VP8,
> .type = MTK_FMT_ENC,
> @@ -110,35 +113,13 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
> ctx = dev->curr_ctx;
> spin_unlock_irqrestore(&dev->irqlock, flags);
>
> - mtk_v4l2_debug(1, "id=%d", ctx->id);
> - addr = dev->reg_base[VENC_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
> -
> - ctx->irq_status = readl(dev->reg_base[VENC_SYS] +
> - (MTK_VENC_IRQ_STATUS_OFFSET));
> -
> - clean_irq_status(ctx->irq_status, addr);
> -
> - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
> - return IRQ_HANDLED;
> -}
> -
> -static irqreturn_t mtk_vcodec_enc_lt_irq_handler(int irq, void *priv)
> -{
> - struct mtk_vcodec_dev *dev = priv;
> - struct mtk_vcodec_ctx *ctx;
> - unsigned long flags;
> - void __iomem *addr;
> -
> - spin_lock_irqsave(&dev->irqlock, flags);
> - ctx = dev->curr_ctx;
> - spin_unlock_irqrestore(&dev->irqlock, flags);
> + mtk_v4l2_debug(1, "id=%d coreid:%d", ctx->id, dev->venc_pdata->core_id);
> + addr = dev->reg_base[dev->venc_pdata->core_id] +
> + MTK_VENC_IRQ_ACK_OFFSET;
>
> - mtk_v4l2_debug(1, "id=%d", ctx->id);
> - ctx->irq_status = readl(dev->reg_base[VENC_LT_SYS] +
> + ctx->irq_status = readl(dev->reg_base[dev->venc_pdata->core_id] +
> (MTK_VENC_IRQ_STATUS_OFFSET));
>
> - addr = dev->reg_base[VENC_LT_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
> -
> clean_irq_status(ctx->irq_status, addr);
>
> wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
> @@ -265,7 +246,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> struct resource *res;
> phandle rproc_phandle;
> enum mtk_vcodec_fw_type fw_type;
> - int i, j, ret;
> + int ret;
> + void __iomem *reg_base;
>
> dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> if (!dev)
> @@ -291,63 +273,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> dev->venc_pdata = of_device_get_match_data(&pdev->dev);
> ret = mtk_vcodec_init_enc_pm(dev);
> if (ret < 0) {
> - dev_err(&pdev->dev, "Failed to get mt vcodec clock source!");
> + dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!");
> goto err_enc_pm;
> }
>
> - for (i = VENC_SYS, j = 0; i < NUM_MAX_VCODEC_REG_BASE; i++, j++) {
> - res = platform_get_resource(pdev, IORESOURCE_MEM, j);
> - dev->reg_base[i] = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR((__force void *)dev->reg_base[i])) {
> - ret = PTR_ERR((__force void *)dev->reg_base[i]);
> - goto err_res;
> - }
> - mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[i]);
> - }
> + pm_runtime_enable(&pdev->dev);
> +
> + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
> + dev->venc_pdata->name);
>
> - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> - if (res == NULL) {
> - dev_err(&pdev->dev, "failed to get irq resource");
> - ret = -ENOENT;
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR((__force void *)reg_base)) {
> + ret = PTR_ERR((__force void *)reg_base);
> goto err_res;
> }
> + dev->reg_base[dev->venc_pdata->core_id] = reg_base;
>
> dev->enc_irq = platform_get_irq(pdev, 0);
> ret = devm_request_irq(&pdev->dev, dev->enc_irq,
> mtk_vcodec_enc_irq_handler,
> 0, pdev->name, dev);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to install dev->enc_irq %d (%d)",
> - dev->enc_irq,
> - ret);
> + dev_err(&pdev->dev,
> + "Failed to install dev->enc_irq %d (%d) core_id:%d",
> + dev->enc_irq, ret, dev->venc_pdata->core_id);
> ret = -EINVAL;
> goto err_res;
> }
> disable_irq(dev->enc_irq);
>
> - if (dev->venc_pdata->has_lt_irq) {
> - dev->enc_lt_irq = platform_get_irq(pdev, 1);
> - ret = devm_request_irq(&pdev->dev,
> - dev->enc_lt_irq,
> - mtk_vcodec_enc_lt_irq_handler,
> - 0, pdev->name, dev);
> - if (ret) {
> - dev_err(&pdev->dev,
> - "Failed to install dev->enc_lt_irq %d (%d)",
> - dev->enc_lt_irq, ret);
> - ret = -EINVAL;
> - goto err_res;
> - }
> - disable_irq(dev->enc_lt_irq); /* VENC_LT */
> - }
> -
> mutex_init(&dev->enc_mutex);
> mutex_init(&dev->dev_mutex);
> spin_lock_init(&dev->irqlock);
> -
> - snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
> - "[MTK_V4L2_VENC]");
> -
> ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
> if (ret) {
> mtk_v4l2_err("v4l2_device_register err=%d", ret);
> @@ -373,7 +331,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> V4L2_CAP_STREAMING;
>
> snprintf(vfd_enc->name, sizeof(vfd_enc->name), "%s",
> - MTK_VCODEC_ENC_NAME);
> + dev->venc_pdata->name);
> video_set_drvdata(vfd_enc, dev);
> dev->vfd_enc = vfd_enc;
> platform_set_drvdata(pdev, dev);
> @@ -401,8 +359,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> goto err_enc_reg;
> }
>
> - mtk_v4l2_debug(0, "encoder registered as /dev/video%d",
> - vfd_enc->num);
> + mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d",
> + dev->venc_pdata->core_id, vfd_enc->num);
>
> return 0;
>
> @@ -415,26 +373,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> err_enc_alloc:
> v4l2_device_unregister(&dev->v4l2_dev);
> err_res:
> - mtk_vcodec_release_enc_pm(dev);
> + pm_runtime_disable(&pdev->dev);
> err_enc_pm:
> mtk_vcodec_fw_release(dev->fw_handler);
> return ret;
> }
>
> -static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
> +static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = {
> + .chip = MTK_MT8173,
> + .name = MTK_VCODEC_ENC_NAME,
> + .capture_formats = mtk_video_formats_capture_mt8173_h264,
> + .num_capture_formats = 1,
> + .output_formats = mtk_video_formats_output_mt8173,
> + .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> + .min_bitrate = 1,
> + .max_bitrate = 4000000,
> + .core_id = VENC_SYS,
> +};
> +
> +static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = {
> .chip = MTK_MT8173,
> - .has_lt_irq = true,
> - .capture_formats = mtk_video_formats_capture_mt8173,
> - .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8173),
> + .name = MTK_VENC_VP8_NAME,
> + .capture_formats = mtk_video_formats_capture_mt8173_vp8,
> + .num_capture_formats = 1,
> .output_formats = mtk_video_formats_output_mt8173,
> .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> .min_bitrate = 1,
> .max_bitrate = 4000000,
> + .core_id = VENC_LT_SYS,
> };
>
> static const struct mtk_vcodec_enc_pdata mt8183_pdata = {
> .chip = MTK_MT8183,
> - .has_lt_irq = false,
> + .name = MTK_VCODEC_ENC_NAME,
> .uses_ext = true,
> .capture_formats = mtk_video_formats_capture_mt8183,
> .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8183),
> @@ -443,10 +414,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> .min_bitrate = 64,
> .max_bitrate = 40000000,
> + .core_id = VENC_SYS,
> };
>
> static const struct of_device_id mtk_vcodec_enc_match[] = {
> - {.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_pdata},
> + {.compatible = "mediatek,mt8173-vcodec-avc-enc",
> + .data = &mt8173_avc_pdata},
> + {.compatible = "mediatek,mt8173-vcodec-vp8-enc",
> + .data = &mt8173_vp8_pdata},
> {.compatible = "mediatek,mt8183-vcodec-enc", .data = &mt8183_pdata},
> {},
> };
> @@ -466,7 +441,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev)
> video_unregister_device(dev->vfd_enc);
>
> v4l2_device_unregister(&dev->v4l2_dev);
> - mtk_vcodec_release_enc_pm(dev);
> + pm_runtime_disable(&pdev->dev);
> mtk_vcodec_fw_release(dev->fw_handler);
> return 0;
> }
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> index ee22902..01c6a55 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> @@ -43,21 +43,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> return -ENODEV;
> }
> pm->larbvenc = &pdev->dev;
> -
> - node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
> - if (!node) {
> - mtk_v4l2_err("no mediatek,larb found");
> - return -ENODEV;
> - }
> -
> - pdev = of_find_device_by_node(node);
> - of_node_put(node);
> - if (!pdev) {
> - mtk_v4l2_err("no mediatek,larb device found");
> - return -ENODEV;
> - }
> -
> - pm->larbvenclt = &pdev->dev;
> pdev = mtkdev->plat_dev;
> pm->dev = &pdev->dev;
>
> @@ -94,11 +79,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> return ret;
> }
>
> -void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
> -{
> -}
> -
> -
> void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> {
> struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
> @@ -116,18 +96,10 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> ret = mtk_smi_larb_get(pm->larbvenc);
> if (ret) {
> mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
> - goto larbvencerr;
> - }
> - ret = mtk_smi_larb_get(pm->larbvenclt);
> - if (ret) {
> - mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
> - goto larbvenclterr;
> + goto clkerr;
> }
> return;
>
> -larbvenclterr:
> - mtk_smi_larb_put(pm->larbvenc);
> -larbvencerr:
> clkerr:
> for (i -= 1; i >= 0; i--)
> clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> @@ -139,7 +111,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
> int i = 0;
>
> mtk_smi_larb_put(pm->larbvenc);
> - mtk_smi_larb_put(pm->larbvenclt);
> for (i = enc_clk->clk_num - 1; i >= 0; i--)
> clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> }
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> index b7ecdfd..c1b5986 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> @@ -10,7 +10,6 @@
> #include "mtk_vcodec_drv.h"
>
> int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *dev);
> -void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *dev);
>
> void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
> void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
> diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> index 11abb19..8267a9c 100644
> --- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> +++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> @@ -367,7 +367,7 @@ static int vp8_enc_encode(void *handle,
>
> mtk_vcodec_debug_enter(inst);
>
> - enable_irq(ctx->dev->enc_lt_irq);
> + enable_irq(ctx->dev->enc_irq);
>
> switch (opt) {
> case VENC_START_OPT_ENCODE_FRAME:
> @@ -386,7 +386,7 @@ static int vp8_enc_encode(void *handle,
>
> encode_err:
>
> - disable_irq(ctx->dev->enc_lt_irq);
> + disable_irq(ctx->dev->enc_irq);
> mtk_vcodec_debug_leave(inst);
>
> return ret;

2020-06-10 05:49:35

by CK Hu (胡俊光)

[permalink] [raw]
Subject: Re: [PATCH v4 09/17] media: mtk-vcodec: Get rid of mtk_smi_larb_get/put

+ Tiffany & Maoguang.

On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> MediaTek IOMMU has already added the device_link between the consumer
> and smi-larb device. If the vcodec device call the pm_runtime_get_sync,
> the smi-larb's pm_runtime_get_sync also be called automatically.
>
> CC: Tiffany Lin <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> Reviewed-by: Evan Green <[email protected]>
> ---
> .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 19 ---------------
> drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 3 ---
> drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 1 -
> .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 27 ----------------------
> 4 files changed, 50 deletions(-)
>
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> index 36dfe3f..1d7d14d 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> @@ -8,14 +8,12 @@
> #include <linux/of_address.h>
> #include <linux/of_platform.h>
> #include <linux/pm_runtime.h>
> -#include <soc/mediatek/smi.h>
>
> #include "mtk_vcodec_dec_pm.h"
> #include "mtk_vcodec_util.h"
>
> int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
> {
> - struct device_node *node;
> struct platform_device *pdev;
> struct mtk_vcodec_pm *pm;
> struct mtk_vcodec_clk *dec_clk;
> @@ -26,18 +24,7 @@ int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
> pm = &mtkdev->pm;
> pm->mtkdev = mtkdev;
> dec_clk = &pm->vdec_clk;
> - node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
> - if (!node) {
> - mtk_v4l2_err("of_parse_phandle mediatek,larb fail!");
> - return -1;
> - }
>
> - pdev = of_find_device_by_node(node);
> - of_node_put(node);
> - if (WARN_ON(!pdev)) {
> - return -1;
> - }
> - pm->larbvdec = &pdev->dev;
> pdev = mtkdev->plat_dev;
> pm->dev = &pdev->dev;
>
> @@ -113,11 +100,6 @@ void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm)
> }
> }
>
> - ret = mtk_smi_larb_get(pm->larbvdec);
> - if (ret) {
> - mtk_v4l2_err("mtk_smi_larb_get larbvdec fail %d", ret);
> - goto error;
> - }
> return;
>
> error:
> @@ -130,7 +112,6 @@ void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
> struct mtk_vcodec_clk *dec_clk = &pm->vdec_clk;
> int i = 0;
>
> - mtk_smi_larb_put(pm->larbvdec);
> for (i = dec_clk->clk_num - 1; i >= 0; i--)
> clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
> }
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> index 52d1ce1..7d3966a 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> @@ -190,10 +190,7 @@ struct mtk_vcodec_clk {
> */
> struct mtk_vcodec_pm {
> struct mtk_vcodec_clk vdec_clk;
> - struct device *larbvdec;
> -
> struct mtk_vcodec_clk venc_clk;
> - struct device *larbvenc;
> struct device *dev;
> struct mtk_vcodec_dev *mtkdev;
> };
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 5301dca..18025f7 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -8,7 +8,6 @@
> #include <media/v4l2-event.h>
> #include <media/v4l2-mem2mem.h>
> #include <media/videobuf2-dma-contig.h>
> -#include <soc/mediatek/smi.h>
> #include <linux/pm_runtime.h>
>
> #include "mtk_vcodec_drv.h"
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> index 01c6a55..047919e 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> @@ -8,44 +8,25 @@
> #include <linux/of_address.h>
> #include <linux/of_platform.h>
> #include <linux/pm_runtime.h>
> -#include <soc/mediatek/smi.h>
>
> #include "mtk_vcodec_enc_pm.h"
> #include "mtk_vcodec_util.h"
>
> int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> {
> - struct device_node *node;
> struct platform_device *pdev;
> struct mtk_vcodec_pm *pm;
> struct mtk_vcodec_clk *enc_clk;
> struct mtk_vcodec_clk_info *clk_info;
> int ret = 0, i = 0;
> - struct device *dev;
>
> pdev = mtkdev->plat_dev;
> pm = &mtkdev->pm;
> memset(pm, 0, sizeof(struct mtk_vcodec_pm));
> pm->mtkdev = mtkdev;
> pm->dev = &pdev->dev;
> - dev = &pdev->dev;
> enc_clk = &pm->venc_clk;
>
> - node = of_parse_phandle(dev->of_node, "mediatek,larb", 0);
> - if (!node) {
> - mtk_v4l2_err("no mediatek,larb found");
> - return -ENODEV;
> - }
> - pdev = of_find_device_by_node(node);
> - of_node_put(node);
> - if (!pdev) {
> - mtk_v4l2_err("no mediatek,larb device found");
> - return -ENODEV;
> - }
> - pm->larbvenc = &pdev->dev;
> - pdev = mtkdev->plat_dev;
> - pm->dev = &pdev->dev;
> -
> enc_clk->clk_num = of_property_count_strings(pdev->dev.of_node,
> "clock-names");
> if (enc_clk->clk_num > 0) {
> @@ -93,13 +74,6 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> }
> }
>
> - ret = mtk_smi_larb_get(pm->larbvenc);
> - if (ret) {
> - mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
> - goto clkerr;
> - }
> - return;
> -
> clkerr:
> for (i -= 1; i >= 0; i--)
> clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> @@ -110,7 +84,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
> struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
> int i = 0;
>
> - mtk_smi_larb_put(pm->larbvenc);
> for (i = enc_clk->clk_num - 1; i >= 0; i--)
> clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> }

2020-06-10 06:16:14

by Tiffany Lin

[permalink] [raw]
Subject: Re: [PATCH v4 08/17] media: mtk-vcodec: separate mtk-vcodec-enc node.

On Wed, 2020-06-10 at 13:45 +0800, CK Hu wrote:
> + Tiffany & Maoguang.
>
>
> On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> > From: Maoguang Meng <[email protected]>
> >
> > MTK H264 Encoder(VENC_SYS) and VP8 Encoder(VENC_LT_SYS) are two
> > independent hardware instance. They have their owner interrupt,
> > register mapping, and special clocks.
> >
> > This patch seperates the two instance. This is a preparing patch for
> > adding device_link between the larbs and venc-device. It's mainly for
> > fixing the problem:
> > https://lkml.org/lkml/2019/9/3/316
> >
> > User Call "VIDIOC_QUERYCAP":
> > H264 Encoder return driver name "mtk-vcodec-enc";
> > VP8 Encoder return driver name "mtk-venc-vp8.
> >

Acked-by: Tiffany Lin <[email protected]>


> > Signed-off-by: Maoguang Meng <[email protected]>
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > Signed-off-by: Irui Wang <[email protected]>
> > ---
> > drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 10 +-
> > drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 23 +++-
> > .../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 127 +++++++++------------
> > .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 31 +----
> > .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 1 -
> > .../media/platform/mtk-vcodec/venc/venc_vp8_if.c | 4 +-
> > 6 files changed, 80 insertions(+), 116 deletions(-)
> >
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > index a2716117..52d1ce1 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > @@ -19,6 +19,7 @@
> > #define MTK_VCODEC_DRV_NAME "mtk_vcodec_drv"
> > #define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
> > #define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
> > +#define MTK_VENC_VP8_NAME "mtk-venc-vp8"
> > #define MTK_PLATFORM_STR "platform:mt8173"
> >
> > #define MTK_VCODEC_MAX_PLANES 3
> > @@ -193,7 +194,6 @@ struct mtk_vcodec_pm {
> >
> > struct mtk_vcodec_clk venc_clk;
> > struct device *larbvenc;
> > - struct device *larbvenclt;
> > struct device *dev;
> > struct mtk_vcodec_dev *mtkdev;
> > };
> > @@ -311,25 +311,27 @@ enum mtk_chip {
> > * @chip: chip this encoder is compatible with
> > *
> > * @uses_ext: whether the encoder uses the extended firmware messaging format
> > - * @has_lt_irq: whether the encoder uses the LT irq
> > + * @name: whether the encoder core is vp8
> > * @min_birate: minimum supported encoding bitrate
> > * @max_bitrate: maximum supported encoding bitrate
> > * @capture_formats: array of supported capture formats
> > * @num_capture_formats: number of entries in capture_formats
> > * @output_formats: array of supported output formats
> > * @num_output_formats: number of entries in output_formats
> > + * @core_id: stand for h264 or vp8 encode index
> > */
> > struct mtk_vcodec_enc_pdata {
> > enum mtk_chip chip;
> >
> > bool uses_ext;
> > - bool has_lt_irq;
> > + const char *name;
> > unsigned long min_bitrate;
> > unsigned long max_bitrate;
> > const struct mtk_video_fmt *capture_formats;
> > size_t num_capture_formats;
> > const struct mtk_video_fmt *output_formats;
> > size_t num_output_formats;
> > + int core_id;
> > };
> >
> > /**
> > @@ -359,7 +361,6 @@ struct mtk_vcodec_enc_pdata {
> > *
> > * @dec_irq: decoder irq resource
> > * @enc_irq: h264 encoder irq resource
> > - * @enc_lt_irq: vp8 encoder irq resource
> > *
> > * @dec_mutex: decoder hardware lock
> > * @enc_mutex: encoder hardware lock.
> > @@ -395,7 +396,6 @@ struct mtk_vcodec_dev {
> >
> > int dec_irq;
> > int enc_irq;
> > - int enc_lt_irq;
> >
> > struct mutex dec_mutex;
> > struct mutex enc_mutex;
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > index f0af78f..5301dca 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > @@ -9,6 +9,7 @@
> > #include <media/v4l2-mem2mem.h>
> > #include <media/videobuf2-dma-contig.h>
> > #include <soc/mediatek/smi.h>
> > +#include <linux/pm_runtime.h>
> >
> > #include "mtk_vcodec_drv.h"
> > #include "mtk_vcodec_enc.h"
> > @@ -174,7 +175,10 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
> > static int vidioc_venc_querycap(struct file *file, void *priv,
> > struct v4l2_capability *cap)
> > {
> > - strscpy(cap->driver, MTK_VCODEC_ENC_NAME, sizeof(cap->driver));
> > + const struct mtk_vcodec_enc_pdata *pdata =
> > + fh_to_ctx(priv)->dev->venc_pdata;
> > +
> > + strscpy(cap->driver, pdata->name, sizeof(cap->driver));
> > strscpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
> > strscpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));
> >
> > @@ -788,7 +792,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> > */
> > if ((ctx->state == MTK_STATE_ABORT) || (ctx->state == MTK_STATE_FREE)) {
> > ret = -EIO;
> > - goto err_set_param;
> > + goto err_start_stream;
> > }
> >
> > /* Do the initialization when both start_streaming have been called */
> > @@ -800,6 +804,12 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> > return 0;
> > }
> >
> > + ret = pm_runtime_get_sync(&ctx->dev->plat_dev->dev);
> > + if (ret < 0) {
> > + mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
> > + goto err_start_stream;
> > + }
> > +
> > mtk_venc_set_param(ctx, &param);
> > ret = venc_if_set_param(ctx, VENC_SET_PARAM_ENC, &param);
> > if (ret) {
> > @@ -826,6 +836,11 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
> > return 0;
> >
> > err_set_param:
> > + ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> > + if (ret < 0)
> > + mtk_v4l2_err("pm_runtime_put fail %d", ret);
> > +
> > +err_start_stream:
> > for (i = 0; i < q->num_buffers; ++i) {
> > struct vb2_buffer *buf = vb2_get_buffer(q, i);
> >
> > @@ -879,6 +894,10 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
> > if (ret)
> > mtk_v4l2_err("venc_if_deinit failed=%d", ret);
> >
> > + ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> > + if (ret < 0)
> > + mtk_v4l2_err("pm_runtime_put fail %d", ret);
> > +
> > ctx->state = MTK_STATE_FREE;
> > }
> >
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> > index b8fe408..fe17f0c 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
> > @@ -49,12 +49,15 @@
> > },
> > };
> >
> > -static const struct mtk_video_fmt mtk_video_formats_capture_mt8173[] = {
> > +static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_h264[] = {
> > {
> > .fourcc = V4L2_PIX_FMT_H264,
> > .type = MTK_FMT_ENC,
> > .num_planes = 1,
> > },
> > +};
> > +
> > +static const struct mtk_video_fmt mtk_video_formats_capture_mt8173_vp8[] = {
> > {
> > .fourcc = V4L2_PIX_FMT_VP8,
> > .type = MTK_FMT_ENC,
> > @@ -110,35 +113,13 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
> > ctx = dev->curr_ctx;
> > spin_unlock_irqrestore(&dev->irqlock, flags);
> >
> > - mtk_v4l2_debug(1, "id=%d", ctx->id);
> > - addr = dev->reg_base[VENC_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
> > -
> > - ctx->irq_status = readl(dev->reg_base[VENC_SYS] +
> > - (MTK_VENC_IRQ_STATUS_OFFSET));
> > -
> > - clean_irq_status(ctx->irq_status, addr);
> > -
> > - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
> > - return IRQ_HANDLED;
> > -}
> > -
> > -static irqreturn_t mtk_vcodec_enc_lt_irq_handler(int irq, void *priv)
> > -{
> > - struct mtk_vcodec_dev *dev = priv;
> > - struct mtk_vcodec_ctx *ctx;
> > - unsigned long flags;
> > - void __iomem *addr;
> > -
> > - spin_lock_irqsave(&dev->irqlock, flags);
> > - ctx = dev->curr_ctx;
> > - spin_unlock_irqrestore(&dev->irqlock, flags);
> > + mtk_v4l2_debug(1, "id=%d coreid:%d", ctx->id, dev->venc_pdata->core_id);
> > + addr = dev->reg_base[dev->venc_pdata->core_id] +
> > + MTK_VENC_IRQ_ACK_OFFSET;
> >
> > - mtk_v4l2_debug(1, "id=%d", ctx->id);
> > - ctx->irq_status = readl(dev->reg_base[VENC_LT_SYS] +
> > + ctx->irq_status = readl(dev->reg_base[dev->venc_pdata->core_id] +
> > (MTK_VENC_IRQ_STATUS_OFFSET));
> >
> > - addr = dev->reg_base[VENC_LT_SYS] + MTK_VENC_IRQ_ACK_OFFSET;
> > -
> > clean_irq_status(ctx->irq_status, addr);
> >
> > wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED);
> > @@ -265,7 +246,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > struct resource *res;
> > phandle rproc_phandle;
> > enum mtk_vcodec_fw_type fw_type;
> > - int i, j, ret;
> > + int ret;
> > + void __iomem *reg_base;
> >
> > dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> > if (!dev)
> > @@ -291,63 +273,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > dev->venc_pdata = of_device_get_match_data(&pdev->dev);
> > ret = mtk_vcodec_init_enc_pm(dev);
> > if (ret < 0) {
> > - dev_err(&pdev->dev, "Failed to get mt vcodec clock source!");
> > + dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!");
> > goto err_enc_pm;
> > }
> >
> > - for (i = VENC_SYS, j = 0; i < NUM_MAX_VCODEC_REG_BASE; i++, j++) {
> > - res = platform_get_resource(pdev, IORESOURCE_MEM, j);
> > - dev->reg_base[i] = devm_ioremap_resource(&pdev->dev, res);
> > - if (IS_ERR((__force void *)dev->reg_base[i])) {
> > - ret = PTR_ERR((__force void *)dev->reg_base[i]);
> > - goto err_res;
> > - }
> > - mtk_v4l2_debug(2, "reg[%d] base=0x%p", i, dev->reg_base[i]);
> > - }
> > + pm_runtime_enable(&pdev->dev);
> > +
> > + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
> > + dev->venc_pdata->name);
> >
> > - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > - if (res == NULL) {
> > - dev_err(&pdev->dev, "failed to get irq resource");
> > - ret = -ENOENT;
> > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + reg_base = devm_ioremap_resource(&pdev->dev, res);
> > + if (IS_ERR((__force void *)reg_base)) {
> > + ret = PTR_ERR((__force void *)reg_base);
> > goto err_res;
> > }
> > + dev->reg_base[dev->venc_pdata->core_id] = reg_base;
> >
> > dev->enc_irq = platform_get_irq(pdev, 0);
> > ret = devm_request_irq(&pdev->dev, dev->enc_irq,
> > mtk_vcodec_enc_irq_handler,
> > 0, pdev->name, dev);
> > if (ret) {
> > - dev_err(&pdev->dev, "Failed to install dev->enc_irq %d (%d)",
> > - dev->enc_irq,
> > - ret);
> > + dev_err(&pdev->dev,
> > + "Failed to install dev->enc_irq %d (%d) core_id:%d",
> > + dev->enc_irq, ret, dev->venc_pdata->core_id);
> > ret = -EINVAL;
> > goto err_res;
> > }
> > disable_irq(dev->enc_irq);
> >
> > - if (dev->venc_pdata->has_lt_irq) {
> > - dev->enc_lt_irq = platform_get_irq(pdev, 1);
> > - ret = devm_request_irq(&pdev->dev,
> > - dev->enc_lt_irq,
> > - mtk_vcodec_enc_lt_irq_handler,
> > - 0, pdev->name, dev);
> > - if (ret) {
> > - dev_err(&pdev->dev,
> > - "Failed to install dev->enc_lt_irq %d (%d)",
> > - dev->enc_lt_irq, ret);
> > - ret = -EINVAL;
> > - goto err_res;
> > - }
> > - disable_irq(dev->enc_lt_irq); /* VENC_LT */
> > - }
> > -
> > mutex_init(&dev->enc_mutex);
> > mutex_init(&dev->dev_mutex);
> > spin_lock_init(&dev->irqlock);
> > -
> > - snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s",
> > - "[MTK_V4L2_VENC]");
> > -
> > ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
> > if (ret) {
> > mtk_v4l2_err("v4l2_device_register err=%d", ret);
> > @@ -373,7 +331,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > V4L2_CAP_STREAMING;
> >
> > snprintf(vfd_enc->name, sizeof(vfd_enc->name), "%s",
> > - MTK_VCODEC_ENC_NAME);
> > + dev->venc_pdata->name);
> > video_set_drvdata(vfd_enc, dev);
> > dev->vfd_enc = vfd_enc;
> > platform_set_drvdata(pdev, dev);
> > @@ -401,8 +359,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > goto err_enc_reg;
> > }
> >
> > - mtk_v4l2_debug(0, "encoder registered as /dev/video%d",
> > - vfd_enc->num);
> > + mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d",
> > + dev->venc_pdata->core_id, vfd_enc->num);
> >
> > return 0;
> >
> > @@ -415,26 +373,39 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > err_enc_alloc:
> > v4l2_device_unregister(&dev->v4l2_dev);
> > err_res:
> > - mtk_vcodec_release_enc_pm(dev);
> > + pm_runtime_disable(&pdev->dev);
> > err_enc_pm:
> > mtk_vcodec_fw_release(dev->fw_handler);
> > return ret;
> > }
> >
> > -static const struct mtk_vcodec_enc_pdata mt8173_pdata = {
> > +static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = {
> > + .chip = MTK_MT8173,
> > + .name = MTK_VCODEC_ENC_NAME,
> > + .capture_formats = mtk_video_formats_capture_mt8173_h264,
> > + .num_capture_formats = 1,
> > + .output_formats = mtk_video_formats_output_mt8173,
> > + .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> > + .min_bitrate = 1,
> > + .max_bitrate = 4000000,
> > + .core_id = VENC_SYS,
> > +};
> > +
> > +static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = {
> > .chip = MTK_MT8173,
> > - .has_lt_irq = true,
> > - .capture_formats = mtk_video_formats_capture_mt8173,
> > - .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8173),
> > + .name = MTK_VENC_VP8_NAME,
> > + .capture_formats = mtk_video_formats_capture_mt8173_vp8,
> > + .num_capture_formats = 1,
> > .output_formats = mtk_video_formats_output_mt8173,
> > .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> > .min_bitrate = 1,
> > .max_bitrate = 4000000,
> > + .core_id = VENC_LT_SYS,
> > };
> >
> > static const struct mtk_vcodec_enc_pdata mt8183_pdata = {
> > .chip = MTK_MT8183,
> > - .has_lt_irq = false,
> > + .name = MTK_VCODEC_ENC_NAME,
> > .uses_ext = true,
> > .capture_formats = mtk_video_formats_capture_mt8183,
> > .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_mt8183),
> > @@ -443,10 +414,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> > .num_output_formats = ARRAY_SIZE(mtk_video_formats_output_mt8173),
> > .min_bitrate = 64,
> > .max_bitrate = 40000000,
> > + .core_id = VENC_SYS,
> > };
> >
> > static const struct of_device_id mtk_vcodec_enc_match[] = {
> > - {.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_pdata},
> > + {.compatible = "mediatek,mt8173-vcodec-avc-enc",
> > + .data = &mt8173_avc_pdata},
> > + {.compatible = "mediatek,mt8173-vcodec-vp8-enc",
> > + .data = &mt8173_vp8_pdata},
> > {.compatible = "mediatek,mt8183-vcodec-enc", .data = &mt8183_pdata},
> > {},
> > };
> > @@ -466,7 +441,7 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev)
> > video_unregister_device(dev->vfd_enc);
> >
> > v4l2_device_unregister(&dev->v4l2_dev);
> > - mtk_vcodec_release_enc_pm(dev);
> > + pm_runtime_disable(&pdev->dev);
> > mtk_vcodec_fw_release(dev->fw_handler);
> > return 0;
> > }
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > index ee22902..01c6a55 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > @@ -43,21 +43,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> > return -ENODEV;
> > }
> > pm->larbvenc = &pdev->dev;
> > -
> > - node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
> > - if (!node) {
> > - mtk_v4l2_err("no mediatek,larb found");
> > - return -ENODEV;
> > - }
> > -
> > - pdev = of_find_device_by_node(node);
> > - of_node_put(node);
> > - if (!pdev) {
> > - mtk_v4l2_err("no mediatek,larb device found");
> > - return -ENODEV;
> > - }
> > -
> > - pm->larbvenclt = &pdev->dev;
> > pdev = mtkdev->plat_dev;
> > pm->dev = &pdev->dev;
> >
> > @@ -94,11 +79,6 @@ int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> > return ret;
> > }
> >
> > -void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
> > -{
> > -}
> > -
> > -
> > void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> > {
> > struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
> > @@ -116,18 +96,10 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> > ret = mtk_smi_larb_get(pm->larbvenc);
> > if (ret) {
> > mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
> > - goto larbvencerr;
> > - }
> > - ret = mtk_smi_larb_get(pm->larbvenclt);
> > - if (ret) {
> > - mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
> > - goto larbvenclterr;
> > + goto clkerr;
> > }
> > return;
> >
> > -larbvenclterr:
> > - mtk_smi_larb_put(pm->larbvenc);
> > -larbvencerr:
> > clkerr:
> > for (i -= 1; i >= 0; i--)
> > clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> > @@ -139,7 +111,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
> > int i = 0;
> >
> > mtk_smi_larb_put(pm->larbvenc);
> > - mtk_smi_larb_put(pm->larbvenclt);
> > for (i = enc_clk->clk_num - 1; i >= 0; i--)
> > clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> > }
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> > index b7ecdfd..c1b5986 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
> > @@ -10,7 +10,6 @@
> > #include "mtk_vcodec_drv.h"
> >
> > int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *dev);
> > -void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *dev);
> >
> > void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
> > void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
> > diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> > index 11abb19..8267a9c 100644
> > --- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> > +++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
> > @@ -367,7 +367,7 @@ static int vp8_enc_encode(void *handle,
> >
> > mtk_vcodec_debug_enter(inst);
> >
> > - enable_irq(ctx->dev->enc_lt_irq);
> > + enable_irq(ctx->dev->enc_irq);
> >
> > switch (opt) {
> > case VENC_START_OPT_ENCODE_FRAME:
> > @@ -386,7 +386,7 @@ static int vp8_enc_encode(void *handle,
> >
> > encode_err:
> >
> > - disable_irq(ctx->dev->enc_lt_irq);
> > + disable_irq(ctx->dev->enc_irq);
> > mtk_vcodec_debug_leave(inst);
> >
> > return ret;
>
>

2020-06-10 06:23:02

by Tiffany Lin

[permalink] [raw]
Subject: Re: [PATCH v4 09/17] media: mtk-vcodec: Get rid of mtk_smi_larb_get/put

On Wed, 2020-06-10 at 13:47 +0800, CK Hu wrote:
> + Tiffany & Maoguang.
>
> On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> > MediaTek IOMMU has already added the device_link between the consumer
> > and smi-larb device. If the vcodec device call the pm_runtime_get_sync,
> > the smi-larb's pm_runtime_get_sync also be called automatically.
> >

Acked-by: Tiffany Lin <[email protected]>

> > CC: Tiffany Lin <[email protected]>
> > Signed-off-by: Yong Wu <[email protected]>
> > Reviewed-by: Evan Green <[email protected]>
> > ---
> > .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 19 ---------------
> > drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 3 ---
> > drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 1 -
> > .../media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 27 ----------------------
> > 4 files changed, 50 deletions(-)
> >
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> > index 36dfe3f..1d7d14d 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> > @@ -8,14 +8,12 @@
> > #include <linux/of_address.h>
> > #include <linux/of_platform.h>
> > #include <linux/pm_runtime.h>
> > -#include <soc/mediatek/smi.h>
> >
> > #include "mtk_vcodec_dec_pm.h"
> > #include "mtk_vcodec_util.h"
> >
> > int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
> > {
> > - struct device_node *node;
> > struct platform_device *pdev;
> > struct mtk_vcodec_pm *pm;
> > struct mtk_vcodec_clk *dec_clk;
> > @@ -26,18 +24,7 @@ int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *mtkdev)
> > pm = &mtkdev->pm;
> > pm->mtkdev = mtkdev;
> > dec_clk = &pm->vdec_clk;
> > - node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0);
> > - if (!node) {
> > - mtk_v4l2_err("of_parse_phandle mediatek,larb fail!");
> > - return -1;
> > - }
> >
> > - pdev = of_find_device_by_node(node);
> > - of_node_put(node);
> > - if (WARN_ON(!pdev)) {
> > - return -1;
> > - }
> > - pm->larbvdec = &pdev->dev;
> > pdev = mtkdev->plat_dev;
> > pm->dev = &pdev->dev;
> >
> > @@ -113,11 +100,6 @@ void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm)
> > }
> > }
> >
> > - ret = mtk_smi_larb_get(pm->larbvdec);
> > - if (ret) {
> > - mtk_v4l2_err("mtk_smi_larb_get larbvdec fail %d", ret);
> > - goto error;
> > - }
> > return;
> >
> > error:
> > @@ -130,7 +112,6 @@ void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
> > struct mtk_vcodec_clk *dec_clk = &pm->vdec_clk;
> > int i = 0;
> >
> > - mtk_smi_larb_put(pm->larbvdec);
> > for (i = dec_clk->clk_num - 1; i >= 0; i--)
> > clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
> > }
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > index 52d1ce1..7d3966a 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> > @@ -190,10 +190,7 @@ struct mtk_vcodec_clk {
> > */
> > struct mtk_vcodec_pm {
> > struct mtk_vcodec_clk vdec_clk;
> > - struct device *larbvdec;
> > -
> > struct mtk_vcodec_clk venc_clk;
> > - struct device *larbvenc;
> > struct device *dev;
> > struct mtk_vcodec_dev *mtkdev;
> > };
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > index 5301dca..18025f7 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> > @@ -8,7 +8,6 @@
> > #include <media/v4l2-event.h>
> > #include <media/v4l2-mem2mem.h>
> > #include <media/videobuf2-dma-contig.h>
> > -#include <soc/mediatek/smi.h>
> > #include <linux/pm_runtime.h>
> >
> > #include "mtk_vcodec_drv.h"
> > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > index 01c6a55..047919e 100644
> > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
> > @@ -8,44 +8,25 @@
> > #include <linux/of_address.h>
> > #include <linux/of_platform.h>
> > #include <linux/pm_runtime.h>
> > -#include <soc/mediatek/smi.h>
> >
> > #include "mtk_vcodec_enc_pm.h"
> > #include "mtk_vcodec_util.h"
> >
> > int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
> > {
> > - struct device_node *node;
> > struct platform_device *pdev;
> > struct mtk_vcodec_pm *pm;
> > struct mtk_vcodec_clk *enc_clk;
> > struct mtk_vcodec_clk_info *clk_info;
> > int ret = 0, i = 0;
> > - struct device *dev;
> >
> > pdev = mtkdev->plat_dev;
> > pm = &mtkdev->pm;
> > memset(pm, 0, sizeof(struct mtk_vcodec_pm));
> > pm->mtkdev = mtkdev;
> > pm->dev = &pdev->dev;
> > - dev = &pdev->dev;
> > enc_clk = &pm->venc_clk;
> >
> > - node = of_parse_phandle(dev->of_node, "mediatek,larb", 0);
> > - if (!node) {
> > - mtk_v4l2_err("no mediatek,larb found");
> > - return -ENODEV;
> > - }
> > - pdev = of_find_device_by_node(node);
> > - of_node_put(node);
> > - if (!pdev) {
> > - mtk_v4l2_err("no mediatek,larb device found");
> > - return -ENODEV;
> > - }
> > - pm->larbvenc = &pdev->dev;
> > - pdev = mtkdev->plat_dev;
> > - pm->dev = &pdev->dev;
> > -
> > enc_clk->clk_num = of_property_count_strings(pdev->dev.of_node,
> > "clock-names");
> > if (enc_clk->clk_num > 0) {
> > @@ -93,13 +74,6 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
> > }
> > }
> >
> > - ret = mtk_smi_larb_get(pm->larbvenc);
> > - if (ret) {
> > - mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
> > - goto clkerr;
> > - }
> > - return;
> > -
> > clkerr:
> > for (i -= 1; i >= 0; i--)
> > clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> > @@ -110,7 +84,6 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
> > struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
> > int i = 0;
> >
> > - mtk_smi_larb_put(pm->larbvenc);
> > for (i = enc_clk->clk_num - 1; i >= 0; i--)
> > clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
> > }
>
>

2020-06-10 06:50:54

by Alexandre Courbot

[permalink] [raw]
Subject: Re: [PATCH v4 01/17] media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.

On Wed, Jun 10, 2020 at 6:21 AM Rob Herring <[email protected]> wrote:
>
> On Sat, May 30, 2020 at 04:10:02PM +0800, Yong Wu wrote:
> > From: Maoguang Meng <[email protected]>
> >
> > Update binding document since the avc and vp8 hardware encoder in
> > mt8173 are now separated. Separate "mediatek,mt8173-vcodec-enc" to
> > "mediatek,mt8173-vcodec-vp8-enc" and "mediatek,mt8173-vcodec-avc-enc".
>
> The h/w suddenly split in 2? You are breaking compatibility. Up to the
> Mediatek maintainers to decide if that's okay, but you need to state you
> are breaking compatibility (here and in the driver) and why that is
> okay.

In my understanding there is no real hardware using the old bindings
at the moment, and the split is indeed a reflection of the actual
hardware layout. Tiffany, can you give your acked-by if this change is
ok with you?

>
> >
> > This is a preparing patch for smi cleaning up "mediatek,larb".
> >
> > Signed-off-by: Maoguang Meng <[email protected]>
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > Signed-off-by: Irui Wang <[email protected]>
> > Signed-off-by: Yong Wu <[email protected]>
> > ---
> > .../devicetree/bindings/media/mediatek-vcodec.txt | 58 ++++++++++++----------
> > 1 file changed, 31 insertions(+), 27 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > index 8093335..1023740 100644
> > --- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > +++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > @@ -4,7 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
> > supports high resolution encoding and decoding functionalities.
> >
> > Required properties:
> > -- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
> > +- compatible : must be one of the following string:
> > + "mediatek,mt8173-vcodec-vp8-enc" for mt8173 vp8 encoder.
> > + "mediatek,mt8173-vcodec-avc-enc" for mt8173 avc encoder.
> > "mediatek,mt8183-vcodec-enc" for MT8183 encoder.
> > "mediatek,mt8173-vcodec-dec" for MT8173 decoder.
> > - reg : Physical base address of the video codec registers and length of
> > @@ -13,10 +15,11 @@ Required properties:
> > - mediatek,larb : must contain the local arbiters in the current Socs.
> > - clocks : list of clock specifiers, corresponding to entries in
> > the clock-names property.
> > -- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
> > - "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
> > - "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
> > - "venc_lt_sel", "vdec_bus_clk_src".
> > +- clock-names:
> > + avc venc must contain "venc_sel";
> > + vp8 venc must contain "venc_lt_sel";
> > + decoder must contain "vcodecpll", "univpll_d2", "clk_cci400_sel",
> > + "vdec_sel", "vdecpll", "vencpll", "venc_lt_sel", "vdec_bus_clk_src".
> > - iommus : should point to the respective IOMMU block with master port as
> > argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
> > for details.
> > @@ -80,14 +83,10 @@ vcodec_dec: vcodec@16000000 {
> > assigned-clock-rates = <0>, <0>, <0>, <1482000000>, <800000000>;
> > };
> >
> > - vcodec_enc: vcodec@18002000 {
> > - compatible = "mediatek,mt8173-vcodec-enc";
> > - reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/
> > - <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
> > - interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
> > - <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > - mediatek,larb = <&larb3>,
> > - <&larb5>;
> > +vcodec_enc: vcodec@18002000 {
> > + compatible = "mediatek,mt8173-vcodec-avc-enc";
> > + reg = <0 0x18002000 0 0x1000>;
> > + interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
> > iommus = <&iommu M4U_PORT_VENC_RCPU>,
> > <&iommu M4U_PORT_VENC_REC>,
> > <&iommu M4U_PORT_VENC_BSDMA>,
> > @@ -98,8 +97,20 @@ vcodec_dec: vcodec@16000000 {
> > <&iommu M4U_PORT_VENC_REF_LUMA>,
> > <&iommu M4U_PORT_VENC_REF_CHROMA>,
> > <&iommu M4U_PORT_VENC_NBM_RDMA>,
> > - <&iommu M4U_PORT_VENC_NBM_WDMA>,
> > - <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > + <&iommu M4U_PORT_VENC_NBM_WDMA>;
> > + mediatek,larb = <&larb3>;
> > + mediatek,vpu = <&vpu>;
> > + clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > + clock-names = "venc_sel";
> > + assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
> > + };
> > +
> > +vcodec_enc_lt: vcodec@19002000 {
> > + compatible = "mediatek,mt8173-vcodec-vp8-enc";
> > + reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
> > + interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > + iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
> > <&iommu M4U_PORT_VENC_BSDMA_SET2>,
> > <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
> > @@ -108,17 +119,10 @@ vcodec_dec: vcodec@16000000 {
> > <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
> > <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
> > <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
> > + mediatek,larb = <&larb5>;
> > mediatek,vpu = <&vpu>;
> > - clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
> > - <&topckgen CLK_TOP_VENC_SEL>,
> > - <&topckgen CLK_TOP_UNIVPLL1_D2>,
> > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > - clock-names = "venc_sel_src",
> > - "venc_sel",
> > - "venc_lt_sel_src",
> > - "venc_lt_sel";
> > - assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
> > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > - assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
> > - <&topckgen CLK_TOP_UNIVPLL1_D2>;
> > + clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > + clock-names = "venc_lt_sel";
> > + assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL_370P5>;
> > };
> > --
> > 1.9.1

2020-06-10 07:44:49

by Tiffany Lin

[permalink] [raw]
Subject: Re: [PATCH v4 01/17] media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.

On Wed, 2020-06-10 at 15:46 +0900, Alexandre Courbot wrote:
> On Wed, Jun 10, 2020 at 6:21 AM Rob Herring <[email protected]> wrote:
> >
> > On Sat, May 30, 2020 at 04:10:02PM +0800, Yong Wu wrote:
> > > From: Maoguang Meng <[email protected]>
> > >
> > > Update binding document since the avc and vp8 hardware encoder in
> > > mt8173 are now separated. Separate "mediatek,mt8173-vcodec-enc" to
> > > "mediatek,mt8173-vcodec-vp8-enc" and "mediatek,mt8173-vcodec-avc-enc".
> >
> > The h/w suddenly split in 2? You are breaking compatibility. Up to the
> > Mediatek maintainers to decide if that's okay, but you need to state you
> > are breaking compatibility (here and in the driver) and why that is
> > okay.
>
> In my understanding there is no real hardware using the old bindings
> at the moment, and the split is indeed a reflection of the actual
> hardware layout. Tiffany, can you give your acked-by if this change is
> ok with you?
>

In my opinion, there is no need to change mt8173 dts for driver to
support mt8183.
I saw another patch that already make change to have encoder driver
support both mt8173 and mt8183.
But they done a lot to prove h264 and vp8 encoder could work
independently and parallel.
In this case, I am ok with it because dts should be a reflection of the
actual hardware.



> >
> > >
> > > This is a preparing patch for smi cleaning up "mediatek,larb".
> > >
> > > Signed-off-by: Maoguang Meng <[email protected]>
> > > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > > Signed-off-by: Irui Wang <[email protected]>
> > > Signed-off-by: Yong Wu <[email protected]>
> > > ---
> > > .../devicetree/bindings/media/mediatek-vcodec.txt | 58 ++++++++++++----------
> > > 1 file changed, 31 insertions(+), 27 deletions(-)
> > >
> > > diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > index 8093335..1023740 100644
> > > --- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > +++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > @@ -4,7 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
> > > supports high resolution encoding and decoding functionalities.
> > >
> > > Required properties:
> > > -- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
> > > +- compatible : must be one of the following string:
> > > + "mediatek,mt8173-vcodec-vp8-enc" for mt8173 vp8 encoder.
> > > + "mediatek,mt8173-vcodec-avc-enc" for mt8173 avc encoder.
> > > "mediatek,mt8183-vcodec-enc" for MT8183 encoder.
> > > "mediatek,mt8173-vcodec-dec" for MT8173 decoder.
> > > - reg : Physical base address of the video codec registers and length of
> > > @@ -13,10 +15,11 @@ Required properties:
> > > - mediatek,larb : must contain the local arbiters in the current Socs.
> > > - clocks : list of clock specifiers, corresponding to entries in
> > > the clock-names property.
> > > -- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
> > > - "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
> > > - "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
> > > - "venc_lt_sel", "vdec_bus_clk_src".
> > > +- clock-names:
> > > + avc venc must contain "venc_sel";
> > > + vp8 venc must contain "venc_lt_sel";
> > > + decoder must contain "vcodecpll", "univpll_d2", "clk_cci400_sel",
> > > + "vdec_sel", "vdecpll", "vencpll", "venc_lt_sel", "vdec_bus_clk_src".
> > > - iommus : should point to the respective IOMMU block with master port as
> > > argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
> > > for details.
> > > @@ -80,14 +83,10 @@ vcodec_dec: vcodec@16000000 {
> > > assigned-clock-rates = <0>, <0>, <0>, <1482000000>, <800000000>;
> > > };
> > >
> > > - vcodec_enc: vcodec@18002000 {
> > > - compatible = "mediatek,mt8173-vcodec-enc";
> > > - reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/
> > > - <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
> > > - interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
> > > - <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > > - mediatek,larb = <&larb3>,
> > > - <&larb5>;
> > > +vcodec_enc: vcodec@18002000 {
> > > + compatible = "mediatek,mt8173-vcodec-avc-enc";
> > > + reg = <0 0x18002000 0 0x1000>;
> > > + interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
> > > iommus = <&iommu M4U_PORT_VENC_RCPU>,
> > > <&iommu M4U_PORT_VENC_REC>,
> > > <&iommu M4U_PORT_VENC_BSDMA>,
> > > @@ -98,8 +97,20 @@ vcodec_dec: vcodec@16000000 {
> > > <&iommu M4U_PORT_VENC_REF_LUMA>,
> > > <&iommu M4U_PORT_VENC_REF_CHROMA>,
> > > <&iommu M4U_PORT_VENC_NBM_RDMA>,
> > > - <&iommu M4U_PORT_VENC_NBM_WDMA>,
> > > - <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > > + <&iommu M4U_PORT_VENC_NBM_WDMA>;
> > > + mediatek,larb = <&larb3>;
> > > + mediatek,vpu = <&vpu>;
> > > + clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > > + clock-names = "venc_sel";
> > > + assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
> > > + };
> > > +
> > > +vcodec_enc_lt: vcodec@19002000 {
> > > + compatible = "mediatek,mt8173-vcodec-vp8-enc";
> > > + reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
> > > + interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > > + iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > > <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
> > > <&iommu M4U_PORT_VENC_BSDMA_SET2>,
> > > <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
> > > @@ -108,17 +119,10 @@ vcodec_dec: vcodec@16000000 {
> > > <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
> > > <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
> > > <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
> > > + mediatek,larb = <&larb5>;
> > > mediatek,vpu = <&vpu>;
> > > - clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
> > > - <&topckgen CLK_TOP_VENC_SEL>,
> > > - <&topckgen CLK_TOP_UNIVPLL1_D2>,
> > > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > - clock-names = "venc_sel_src",
> > > - "venc_sel",
> > > - "venc_lt_sel_src",
> > > - "venc_lt_sel";
> > > - assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
> > > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > - assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
> > > - <&topckgen CLK_TOP_UNIVPLL1_D2>;
> > > + clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > + clock-names = "venc_lt_sel";
> > > + assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL_370P5>;
> > > };
> > > --
> > > 1.9.1

2020-06-17 05:56:24

by Tiffany Lin

[permalink] [raw]
Subject: Re: [PATCH v4 01/17] media: dt-binding: mtk-vcodec: Separating mtk-vcodec encode node.

On Wed, 2020-06-10 at 15:38 +0800, Tiffany Lin wrote:
> On Wed, 2020-06-10 at 15:46 +0900, Alexandre Courbot wrote:
> > On Wed, Jun 10, 2020 at 6:21 AM Rob Herring <[email protected]> wrote:
> > >
> > > On Sat, May 30, 2020 at 04:10:02PM +0800, Yong Wu wrote:
> > > > From: Maoguang Meng <[email protected]>
> > > >
> > > > Update binding document since the avc and vp8 hardware encoder in
> > > > mt8173 are now separated. Separate "mediatek,mt8173-vcodec-enc" to
> > > > "mediatek,mt8173-vcodec-vp8-enc" and "mediatek,mt8173-vcodec-avc-enc".
> > >
> > > The h/w suddenly split in 2? You are breaking compatibility. Up to the
> > > Mediatek maintainers to decide if that's okay, but you need to state you
> > > are breaking compatibility (here and in the driver) and why that is
> > > okay.
> >
> > In my understanding there is no real hardware using the old bindings
> > at the moment, and the split is indeed a reflection of the actual
> > hardware layout. Tiffany, can you give your acked-by if this change is
> > ok with you?
> >
>
> In my opinion, there is no need to change mt8173 dts for driver to
> support mt8183.
> I saw another patch that already make change to have encoder driver
> support both mt8173 and mt8183.
> But they done a lot to prove h264 and vp8 encoder could work
> independently and parallel.
> In this case, I am ok with it because dts should be a reflection of the
> actual hardware.
>
>
>
> > >
> > > >
> > > > This is a preparing patch for smi cleaning up "mediatek,larb".
> > > >
Acked-by: Tiffany Lin <[email protected]>


> > > > Signed-off-by: Maoguang Meng <[email protected]>
> > > > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > > > Signed-off-by: Irui Wang <[email protected]>
> > > > Signed-off-by: Yong Wu <[email protected]>
> > > > ---
> > > > .../devicetree/bindings/media/mediatek-vcodec.txt | 58 ++++++++++++----------
> > > > 1 file changed, 31 insertions(+), 27 deletions(-)
> > > >
> > > > diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > > index 8093335..1023740 100644
> > > > --- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > > +++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
> > > > @@ -4,7 +4,9 @@ Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
> > > > supports high resolution encoding and decoding functionalities.
> > > >
> > > > Required properties:
> > > > -- compatible : "mediatek,mt8173-vcodec-enc" for MT8173 encoder
> > > > +- compatible : must be one of the following string:
> > > > + "mediatek,mt8173-vcodec-vp8-enc" for mt8173 vp8 encoder.
> > > > + "mediatek,mt8173-vcodec-avc-enc" for mt8173 avc encoder.
> > > > "mediatek,mt8183-vcodec-enc" for MT8183 encoder.
> > > > "mediatek,mt8173-vcodec-dec" for MT8173 decoder.
> > > > - reg : Physical base address of the video codec registers and length of
> > > > @@ -13,10 +15,11 @@ Required properties:
> > > > - mediatek,larb : must contain the local arbiters in the current Socs.
> > > > - clocks : list of clock specifiers, corresponding to entries in
> > > > the clock-names property.
> > > > -- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
> > > > - "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
> > > > - "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
> > > > - "venc_lt_sel", "vdec_bus_clk_src".
> > > > +- clock-names:
> > > > + avc venc must contain "venc_sel";
> > > > + vp8 venc must contain "venc_lt_sel";
> > > > + decoder must contain "vcodecpll", "univpll_d2", "clk_cci400_sel",
> > > > + "vdec_sel", "vdecpll", "vencpll", "venc_lt_sel", "vdec_bus_clk_src".
> > > > - iommus : should point to the respective IOMMU block with master port as
> > > > argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
> > > > for details.
> > > > @@ -80,14 +83,10 @@ vcodec_dec: vcodec@16000000 {
> > > > assigned-clock-rates = <0>, <0>, <0>, <1482000000>, <800000000>;
> > > > };
> > > >
> > > > - vcodec_enc: vcodec@18002000 {
> > > > - compatible = "mediatek,mt8173-vcodec-enc";
> > > > - reg = <0 0x18002000 0 0x1000>, /*VENC_SYS*/
> > > > - <0 0x19002000 0 0x1000>; /*VENC_LT_SYS*/
> > > > - interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>,
> > > > - <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > > > - mediatek,larb = <&larb3>,
> > > > - <&larb5>;
> > > > +vcodec_enc: vcodec@18002000 {
> > > > + compatible = "mediatek,mt8173-vcodec-avc-enc";
> > > > + reg = <0 0x18002000 0 0x1000>;
> > > > + interrupts = <GIC_SPI 198 IRQ_TYPE_LEVEL_LOW>;
> > > > iommus = <&iommu M4U_PORT_VENC_RCPU>,
> > > > <&iommu M4U_PORT_VENC_REC>,
> > > > <&iommu M4U_PORT_VENC_BSDMA>,
> > > > @@ -98,8 +97,20 @@ vcodec_dec: vcodec@16000000 {
> > > > <&iommu M4U_PORT_VENC_REF_LUMA>,
> > > > <&iommu M4U_PORT_VENC_REF_CHROMA>,
> > > > <&iommu M4U_PORT_VENC_NBM_RDMA>,
> > > > - <&iommu M4U_PORT_VENC_NBM_WDMA>,
> > > > - <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > > > + <&iommu M4U_PORT_VENC_NBM_WDMA>;
> > > > + mediatek,larb = <&larb3>;
> > > > + mediatek,vpu = <&vpu>;
> > > > + clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > > > + clock-names = "venc_sel";
> > > > + assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>;
> > > > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL>;
> > > > + };
> > > > +
> > > > +vcodec_enc_lt: vcodec@19002000 {
> > > > + compatible = "mediatek,mt8173-vcodec-vp8-enc";
> > > > + reg = <0 0x19002000 0 0x1000>; /* VENC_LT_SYS */
> > > > + interrupts = <GIC_SPI 202 IRQ_TYPE_LEVEL_LOW>;
> > > > + iommus = <&iommu M4U_PORT_VENC_RCPU_SET2>,
> > > > <&iommu M4U_PORT_VENC_REC_FRM_SET2>,
> > > > <&iommu M4U_PORT_VENC_BSDMA_SET2>,
> > > > <&iommu M4U_PORT_VENC_SV_COMA_SET2>,
> > > > @@ -108,17 +119,10 @@ vcodec_dec: vcodec@16000000 {
> > > > <&iommu M4U_PORT_VENC_CUR_CHROMA_SET2>,
> > > > <&iommu M4U_PORT_VENC_REF_LUMA_SET2>,
> > > > <&iommu M4U_PORT_VENC_REC_CHROMA_SET2>;
> > > > + mediatek,larb = <&larb5>;
> > > > mediatek,vpu = <&vpu>;
> > > > - clocks = <&topckgen CLK_TOP_VENCPLL_D2>,
> > > > - <&topckgen CLK_TOP_VENC_SEL>,
> > > > - <&topckgen CLK_TOP_UNIVPLL1_D2>,
> > > > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > > - clock-names = "venc_sel_src",
> > > > - "venc_sel",
> > > > - "venc_lt_sel_src",
> > > > - "venc_lt_sel";
> > > > - assigned-clocks = <&topckgen CLK_TOP_VENC_SEL>,
> > > > - <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > > - assigned-clock-parents = <&topckgen CLK_TOP_VENCPLL_D2>,
> > > > - <&topckgen CLK_TOP_UNIVPLL1_D2>;
> > > > + clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > > + clock-names = "venc_lt_sel";
> > > > + assigned-clocks = <&topckgen CLK_TOP_VENC_LT_SEL>;
> > > > + assigned-clock-parents = <&topckgen CLK_TOP_VCODECPLL_370P5>;
> > > > };
> > > > --
> > > > 1.9.1
>

2020-06-18 09:37:47

by Yong Wu (吴勇)

[permalink] [raw]
Subject: Re: [PATCH v4 06/17] media: mtk-jpeg: Get rid of mtk_smi_larb_get/put

+ Rick

On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> MediaTek IOMMU has already added device_link between the consumer
> and smi-larb device. If the jpg device call the pm_runtime_get_sync,
> the smi-larb's pm_runtime_get_sync also be called automatically.
>
> CC: Rick Chang <[email protected]>
> Signed-off-by: Yong Wu <[email protected]>
> Reviewed-by: Evan Green <[email protected]>
> ---
> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 22 ----------------------
> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 2 --
> 2 files changed, 24 deletions(-)
>
> diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> index f82a81a..21fba6f 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> @@ -21,7 +21,6 @@
> #include <media/v4l2-ioctl.h>
> #include <media/videobuf2-core.h>
> #include <media/videobuf2-dma-contig.h>
> -#include <soc/mediatek/smi.h>
>
> #include "mtk_jpeg_hw.h"
> #include "mtk_jpeg_core.h"
> @@ -893,11 +892,6 @@ static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq,
>
> static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
> {
> - int ret;
> -
> - ret = mtk_smi_larb_get(jpeg->larb);
> - if (ret)
> - dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
> clk_prepare_enable(jpeg->clk_jdec_smi);
> clk_prepare_enable(jpeg->clk_jdec);
> }
> @@ -906,7 +900,6 @@ static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
> {
> clk_disable_unprepare(jpeg->clk_jdec);
> clk_disable_unprepare(jpeg->clk_jdec_smi);
> - mtk_smi_larb_put(jpeg->larb);
> }
>
> static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> @@ -1051,21 +1044,6 @@ static int mtk_jpeg_release(struct file *file)
>
> static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
> {
> - struct device_node *node;
> - struct platform_device *pdev;
> -
> - node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
> - if (!node)
> - return -EINVAL;
> - pdev = of_find_device_by_node(node);
> - if (WARN_ON(!pdev)) {
> - of_node_put(node);
> - return -EINVAL;
> - }
> - of_node_put(node);
> -
> - jpeg->larb = &pdev->dev;
> -
> jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
> if (IS_ERR(jpeg->clk_jdec))
> return PTR_ERR(jpeg->clk_jdec);
> diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> index 999bd14..8579494 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> @@ -47,7 +47,6 @@ enum mtk_jpeg_ctx_state {
> * @dec_reg_base: JPEG registers mapping
> * @clk_jdec: JPEG hw working clock
> * @clk_jdec_smi: JPEG SMI bus clock
> - * @larb: SMI device
> */
> struct mtk_jpeg_dev {
> struct mutex lock;
> @@ -61,7 +60,6 @@ struct mtk_jpeg_dev {
> void __iomem *dec_reg_base;
> struct clk *clk_jdec;
> struct clk *clk_jdec_smi;
> - struct device *larb;
> };
>
> /**

2020-06-18 17:31:46

by Rick Chang

[permalink] [raw]
Subject: Re: [PATCH v4 06/17] media: mtk-jpeg: Get rid of mtk_smi_larb_get/put

Hi Yong,

On Thu, 2020-06-18 at 17:32 +0800, Yong Wu wrote:
> + Rick
>
> On Sat, 2020-05-30 at 16:10 +0800, Yong Wu wrote:
> >
> > MediaTek IOMMU has already added device_link between the consumer
> > and smi-larb device. If the jpg device call the
> > pm_runtime_get_sync,
> > the smi-larb's pm_runtime_get_sync also be called automatically.
> >

Acked-by: Rick Chang <[email protected]>

> > CC: Rick Chang <[email protected]>
> > Signed-off-by: Yong Wu <[email protected]>
> > Reviewed-by: Evan Green <[email protected]>
> > ---
> >  drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 22 -----------
> > -----------
> >  drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h |  2 --
> >  2 files changed, 24 deletions(-)
> >
> > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> > b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> > index f82a81a..21fba6f 100644
> > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> > @@ -21,7 +21,6 @@
> >  #include <media/v4l2-ioctl.h>
> >  #include <media/videobuf2-core.h>
> >  #include <media/videobuf2-dma-contig.h>
> > -#include <soc/mediatek/smi.h>
> >  
> >  #include "mtk_jpeg_hw.h"
> >  #include "mtk_jpeg_core.h"
> > @@ -893,11 +892,6 @@ static int mtk_jpeg_queue_init(void *priv,
> > struct vb2_queue *src_vq,
> >  
> >  static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
> >  {
> > - int ret;
> > -
> > - ret = mtk_smi_larb_get(jpeg->larb);
> > - if (ret)
> > - dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail
> > %d\n", ret);
> >   clk_prepare_enable(jpeg->clk_jdec_smi);
> >   clk_prepare_enable(jpeg->clk_jdec);
> >  }
> > @@ -906,7 +900,6 @@ static void mtk_jpeg_clk_off(struct
> > mtk_jpeg_dev *jpeg)
> >  {
> >   clk_disable_unprepare(jpeg->clk_jdec);
> >   clk_disable_unprepare(jpeg->clk_jdec_smi);
> > - mtk_smi_larb_put(jpeg->larb);
> >  }
> >  
> >  static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> > @@ -1051,21 +1044,6 @@ static int mtk_jpeg_release(struct file
> > *file)
> >  
> >  static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
> >  {
> > - struct device_node *node;
> > - struct platform_device *pdev;
> > -
> > - node = of_parse_phandle(jpeg->dev->of_node,
> > "mediatek,larb", 0);
> > - if (!node)
> > - return -EINVAL;
> > - pdev = of_find_device_by_node(node);
> > - if (WARN_ON(!pdev)) {
> > - of_node_put(node);
> > - return -EINVAL;
> > - }
> > - of_node_put(node);
> > -
> > - jpeg->larb = &pdev->dev;
> > -
> >   jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
> >   if (IS_ERR(jpeg->clk_jdec))
> >   return PTR_ERR(jpeg->clk_jdec);
> > diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> > b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> > index 999bd14..8579494 100644
> > --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> > +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
> > @@ -47,7 +47,6 @@ enum mtk_jpeg_ctx_state {
> >   * @dec_reg_base: JPEG registers mapping
> >   * @clk_jdec: JPEG hw working clock
> >   * @clk_jdec_smi: JPEG SMI bus clock
> > - * @larb: SMI device
> >   */
> >  struct mtk_jpeg_dev {
> >   struct mutex lock;
> > @@ -61,7 +60,6 @@ struct mtk_jpeg_dev {
> >   void __iomem *dec_reg_base;
> >   struct clk *clk_jdec;
> >   struct clk *clk_jdec_smi;
> > - struct device *larb;
> >  };
> >  
> >  /**
>