Add driver for dvfsrc, support for active state of scpsys
Subsystems (3)
RFC PATCH v2 1/1 Add driver for dvfsrc, support for active state of scpsys
The patchsets add support for MediaTek hardware module named DVFSRC (dynamic voltage and frequency scaling resource collector). The DVFSRC is a HW module which is used to collect all the requests from both software and hardware and turn into the decision of minimum operating voltage and minimum DRAM frequency to fulfill those requests.
So, This series is to implement the dvfsrc driver to collect all the requests of operating voltage or DRAM bandwidth from other device drivers likes GPU/Camera through 2 frameworks basically:
1. interconnect framework: to aggregate the bandwidth requirements from different clients
[1] https://patchwork.kernel.org/cover/10766329/
Below is the emi bandwidth map of mt8183. There has a hw module "DRAM scheduler" which used to control the throughput. The DVFSRC will collect forecast data of dram bandwidth from SW consumers(camera/gpu...), and according the forecast to change the DRAM frequency
ICC provider ICC Nodes
---- ----
--------- |CPU | |--->|VPU |
----- | |-----> ---- | ----
|DRAM |--|DRAM | ---- | ----
| |--|scheduler|----->|GPU | |--->|DISP|
| |--|(EMI) | ---- | ----
| |--| | ----- | ----
----- | |----->|MMSYS|--|--->|VDEC|
--------- ----- | ----
/|\ | ----
|change DRAM freq |--->|VENC|
---------- | ----
| DVFSR | |
| | | ----
---------- |--->|IMG |
| ----
| ----
|--->|CAM |
----2. Active state management of power domains[1]: to handle the operating voltage opp requirement from different power domains
[2] https://lwn.net/Articles/744047/
Changes in RFC V2:
* Remove the DT property dram_type. (Rob)
* Used generic dts property 'opp-level' to get the performace state. (Stephen)
* Remove unecessary dependency config on Kconfig. (Stephen)
* Remove unused header file, fixed some coding style issue, typo, error handling on dvfsrc driver. (Nicolas/Stephen)
* Remove irq handler on dvfsrc driver. (Stephen)
* Remove init table on dvfsrc driver, combine hw init on trustzone.
* Add interconnect support of mt8183 to aggregate the emi bandwidth. (Georgi)
RFC V1: https://lore.kernel.org/patchwork/cover/1028535/
Henry Chen (11):
dt-bindings: soc: Add dvfsrc driver bindings
dt-bindings: soc: Add opp table on scpsys bindings
soc: mediatek: add support for the performance state
arm64: dts: mt8183: add performance state support of scpsys
soc: mediatek: add header for mediatek SIP interface
soc: mediatek: add MT8183 dvfsrc support
arm64: dts: mt8183: add dvfsrc related nodes
dt-bindings: interconnect: add MT8183 interconnect dt-bindings
dt-bindings: interconnect: Add header for interconnect node
interconnect: mediatek: Add mt8183 interconnect provider driver
arm64: dts: mt8183: Add interconnect provider DT nodes
.../bindings/interconnect/mtk,mt8183.txt | 24 ++ .../devicetree/bindings/soc/mediatek/dvfsrc.txt | 23 ++ .../devicetree/bindings/soc/mediatek/scpsys.txt | 42 +++ arch/arm64/boot/dts/mediatek/mt8183.dtsi | 33 ++ drivers/interconnect/Kconfig | 1 + drivers/interconnect/Makefile | 1 + drivers/interconnect/mediatek/Kconfig | 13 + drivers/interconnect/mediatek/Makefile | 5 + drivers/interconnect/mediatek/mt8183.c | 223 +++++++++++++ drivers/soc/mediatek/Kconfig | 15 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-dvfsrc.c | 347 +++++++++++++++++++++ drivers/soc/mediatek/mtk-scpsys.c | 53 ++++ drivers/soc/mediatek/mtk-scpsys.h | 22 ++ include/dt-bindings/interconnect/mtk,mt8183.h | 18 ++ include/dt-bindings/soc/mtk,dvfsrc.h | 14 + include/soc/mediatek/mtk_dvfsrc.h | 22 ++ include/soc/mediatek/mtk_sip.h | 17 + 18 files changed, 874 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt create mode 100644 Documentation/devicetree/bindings/soc/mediatek/dvfsrc.txt create mode 100644 drivers/interconnect/mediatek/Kconfig create mode 100644 drivers/interconnect/mediatek/Makefile create mode 100644 drivers/interconnect/mediatek/mt8183.c create mode 100644 drivers/soc/mediatek/mtk-dvfsrc.c create mode 100644 drivers/soc/mediatek/mtk-scpsys.h create mode 100644 include/dt-bindings/interconnect/mtk,mt8183.h create mode 100644 include/dt-bindings/soc/mtk,dvfsrc.h create mode 100644 include/soc/mediatek/mtk_dvfsrc.h create mode 100644 include/soc/mediatek/mtk_sip.h
Signature · 1 line
1.9.1
RFC v2 1/11 dt-bindings: soc: Add dvfsrc driver bindings
Document the binding for enabling dvfsrc on MediaTek SoC.
--- .../devicetree/bindings/soc/mediatek/dvfsrc.txt | 23 ++++++++++++++++++++++ include/dt-bindings/soc/mtk,dvfsrc.h | 14 +++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/dvfsrc.txt create mode 100644 include/dt-bindings/soc/mtk,dvfsrc.h
Documentation/devicetree/bindings/soc/mediatek/dvfsrc.txt new file +23 -0
@@ -0,0 +1,23 @@ +MediaTek DVFSRC + +The Dynamic Voltage and Frequency Scaling Resource Collector (DVFSRC) is a +HW module which is used to collect all the requests from both software and +hardware and turn into the decision of minimum operating voltage and minimum +DRAM frequency to fulfill those requests. + +Required Properties: +- compatible: Should be one of the following + - "mediatek,mt8183-dvfsrc": For MT8183 SoC +- reg: Address range of the DVFSRC unit +- clock-names: Must include the following entries: + "dvfsrc": DVFSRC module clock +- clocks: Must contain an entry for each entry in clock-names. + +Example: + + dvfsrc@10012000 { + compatible = "mediatek,mt8183-dvfsrc"; + reg = <0 0x10012000 0 0x1000>; + clocks = <&infracfg CLK_INFRA_DVFSRC>; + clock-names = "dvfsrc"; + };
include/dt-bindings/soc/mtk,dvfsrc.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ + +#ifndef _DT_BINDINGS_POWER_MTK_DVFSRC_H +#define _DT_BINDINGS_POWER_MTK_DVFSRC_H + +#define MT8183_DVFSRC_LEVEL_1 1 +#define MT8183_DVFSRC_LEVEL_2 2 +#define MT8183_DVFSRC_LEVEL_3 3 +#define MT8183_DVFSRC_LEVEL_4 4 + +#endif /* _DT_BINDINGS_POWER_MTK_DVFSRC_H */
Signature · 1 line
1.9.1
Re: [RFC V2 01/11] dt-bindings: soc: Add dvfsrc driver bindings
Quoted 10 lines · Henry Chen
Document the binding for enabling dvfsrc on MediaTek SoC.
Signed-off-by Henry Chen <[email protected]>--- .../devicetree/bindings/soc/mediatek/dvfsrc.txt | 23 ++++++++++++++++++++++ include/dt-bindings/soc/mtk,dvfsrc.h | 14 +++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/dvfsrc.txt create mode 100644 include/dt-bindings/soc/mtk,dvfsrc.h
RFC v2 2/11 dt-bindings: soc: Add opp table on scpsys bindings
In reply to Henry ChenAdd opp table on scpsys dt-bindings for Mediatek SoC.
--- .../devicetree/bindings/soc/mediatek/scpsys.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
Documentation/devicetree/bindings/soc/mediatek/scpsys.txt +42 -0
@@ -63,6 +63,10 @@ Optional properties: - mfg_2d-supply: Power supply for the mfg_2d power domain - mfg-supply: Power supply for the mfg power domain +- operating-points-v2: Phandle to the OPP table for the Power domain. + Refer to Documentation/devicetree/bindings/power/power_domain.txt + and Documentation/devicetree/bindings/opp/opp.txt for more details + Example: scpsys: scpsys@10006000 {
@@ -75,6 +79,27 @@ Example: <&topckgen CLK_TOP_VENC_SEL>, <&topckgen CLK_TOP_VENC_LT_SEL>; clock-names = "mfg", "mm", "venc", "venc_lt"; + operating-points-v2 = <&dvfsrc_opp_table>; + + dvfsrc_opp_table: opp-table { + compatible = "operating-points-v2-level"; + + dvfsrc_vol_min: opp1 { + opp,level = <MT8183_DVFSRC_LEVEL_1>; + }; + + dvfsrc_freq_medium: opp2 { + opp,level = <MT8183_DVFSRC_LEVEL_2>; + }; + + dvfsrc_freq_max: opp3 { + opp,level = <MT8183_DVFSRC_LEVEL_3>; + }; + + dvfsrc_vol_max: opp4 { + opp,level = <MT8183_DVFSRC_LEVEL_4>; + }; + }; }; Example consumer:
@@ -82,4 +107,21 @@ Example consumer: afe: mt8173-afe-pcm@11220000 { compatible = "mediatek,mt8173-afe-pcm"; power-domains = <&scpsys MT8173_POWER_DOMAIN_AUDIO>; + operating-points-v2 = <&aud_opp_table>; + }; + + aud_opp_table: aud-opp-table { + compatible = "operating-points-v2"; + opp1 { + opp-hz = /bits/ 64 <793000000>; + required-opps = <&dvfsrc_vol_min>; + }; + opp2 { + opp-hz = /bits/ 64 <910000000>; + required-opps = <&dvfsrc_vol_max>; + }; + opp3 { + opp-hz = /bits/ 64 <1014000000>; + required-opps = <&dvfsrc_vol_max>; + }; };
Signature · 1 line
1.9.1
Re: [RFC V2 02/11] dt-bindings: soc: Add opp table on scpsys bindings
Quoted 7 lines · Henry Chen
Add opp table on scpsys dt-bindings for Mediatek SoC.
Signed-off-by Henry Chen <[email protected]>--- .../devicetree/bindings/soc/mediatek/scpsys.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
RFC v2 3/11 soc: mediatek: add support for the performance state
In reply to Henry ChenSupport power domain performance state, add header file for scp event.
--- drivers/soc/mediatek/mtk-scpsys.c | 53 +++++++++++++++++++++++++++++++++++++++ drivers/soc/mediatek/mtk-scpsys.h | 22 ++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-scpsys.h
drivers/soc/mediatek/mtk-scpsys.c +53 -0
@@ -10,7 +10,9 @@#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/pm_domain.h> +#include <linux/pm_opp.h> #include <linux/regulator/consumer.h> +#include <linux/slab.h> #include <linux/soc/mediatek/infracfg.h> #include <linux/soc/mediatek/scpsys-ext.h>
@@ -21,6 +23,7 @@#include <dt-bindings/power/mt7623a-power.h> #include <dt-bindings/power/mt8173-power.h> #include <dt-bindings/power/mt8183-power.h> +#include "mtk-scpsys.h" #define MTK_POLL_DELAY_US 10#define MTK_POLL_TIMEOUT USEC_PER_SEC
@@ -188,6 +191,18 @@ struct scp_soc_data {bool bus_prot_reg_update; }; +static BLOCKING_NOTIFIER_HEAD (scpsys_notifier_list); + +int register_scpsys_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_register (&scpsys_notifier_list, nb); +} + +int unregister_scpsys_notifier (struct notifier_block *nb) +{ +return blocking_notifier_chain_unregister (&scpsys_notifier_list, nb); +} +static int scpsys_domain_is_on (struct scp_domain *scpd) {struct scp *scp = scpd->scp;
@@ -519,6 +534,41 @@ static void init_clks(struct platform_device *pdev, struct clk **clk) clk[i] =devm_clk_get (&pdev->dev, clk_names[i]); } +static int mtk_pd_set_performance (struct generic_pm_domain *genpd, +unsigned int state) +{ +int i; +struct scp_domain *scpd = + container_of(genpd, struct scp_domain, genpd); +struct scp_event_data scpe; +struct scp *scp = scpd->scp; +struct genpd_onecell_data *pd_data = &scp->pd_data; + +for (i =0 ; i < pd_data->num_domains; i++) { +if (genpd == pd_data->domains[i]) { +dev_dbg (scp->dev,"%d. %s = %d\n" , + i, genpd->name, state); +break ; + } + } + +if (i == pd_data->num_domains) +return 0 ; + + scpe.event_type =MTK_SCPSYS_PSTATE ; + scpe.genpd = genpd; + scpe.domain_id = i; +blocking_notifier_call_chain (&scpsys_notifier_list, state, &scpe); + +return 0 ; +} + +static unsigned int mtk_pd_get_performance (struct generic_pm_domain *genpd, +struct dev_pm_opp *opp) +{ +return dev_pm_opp_get_level (opp); +} + static struct scp *init_scp(struct platform_device *pdev, const struct scp_domain_data *scp_domain_data, int num, const struct scp_ctrl_reg *scp_ctrl_reg,
@@ -642,6 +692,9 @@ static struct scp *init_scp(struct platform_device *pdev, genpd->power_on = scpsys_power_on;if (MTK_SCPD_CAPS (scpd,MTK_SCPD_ACTIVE_WAKEUP )) genpd->flags |=GENPD_FLAG_ACTIVE_WAKEUP ; + + genpd->set_performance_state = mtk_pd_set_performance; + genpd->opp_to_performance_state = mtk_pd_get_performance; }return scp;
drivers/soc/mediatek/mtk-scpsys.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ + +#ifndef __MTK_SCPSYS_H__ +#define __MTK_SCPSYS_H__ + +struct scp_event_data { +int event_type; +int domain_id; +struct generic_pm_domain *genpd; +}; + +enum scp_event_type { +MTK_SCPSYS_PSTATE , +}; + +int register_scpsys_notifier (struct notifier_block *nb); +int unregister_scpsys_notifier (struct notifier_block *nb); + +#endif /* __MTK_SCPSYS_H__ */
Signature · 1 line
1.9.1
RFC v2 4/11 arm64: dts: mt8183: add performance state support of scpsys
In reply to Henry ChenAdd support for performance state of scpsys on mt8183 platform.
--- arch/arm64/boot/dts/mediatek/mt8183.dtsi | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +21 -0
@@ -9,6 +9,7 @@ #include <dt-bindings/interrupt-controller/arm-gic.h> #include <dt-bindings/interrupt-controller/irq.h> #include <dt-bindings/power/mt8183-power.h> +#include <dt-bindings/soc/mtk,dvfsrc.h> / { compatible = "mediatek,mt8183";
@@ -251,6 +252,26 @@ "vpu-3", "vpu-4", "vpu-5"; infracfg = <&infracfg>; smi_comm = <&smi_common>; + operating-points-v2 = <&dvfsrc_opp_table>; + dvfsrc_opp_table: opp-table { + compatible = "operating-points-v2-level"; + + dvfsrc_vol_min: opp1 { + opp,level = <MT8183_DVFSRC_LEVEL_1>; + }; + + dvfsrc_freq_medium: opp2 { + opp,level = <MT8183_DVFSRC_LEVEL_2>; + }; + + dvfsrc_freq_max: opp3 { + opp,level = <MT8183_DVFSRC_LEVEL_3>; + }; + + dvfsrc_vol_max: opp4 { + opp,level = <MT8183_DVFSRC_LEVEL_4>; + }; + }; }; apmixedsys: syscon@1000c000 {
Signature · 1 line
1.9.1
RFC v2 5/11 soc: mediatek: add header for mediatek SIP interface
In reply to Henry ChenAdd a header to collect SIPs and add one SIP call to initialize power management hardware for the SIP interface defined to access the SPM handling vcore voltage and ddr rate changes on mt8183 (and most likely later socs).
--- include/soc/mediatek/mtk_sip.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 include/soc/mediatek/mtk_sip.h
include/soc/mediatek/mtk_sip.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ +#ifndef __SOC_MTK_SIP_H +#define __SOC_MTK_SIP_H + +#ifdef CONFIG_ARM64 +#define MTK_SIP_SMC_AARCH_BIT 0x40000000 +#else +#define MTK_SIP_SMC_AARCH_BIT 0x00000000 +#endif + +#define MTK_SIP_SPM (0x82000220 | MTK_SIP_SMC_AARCH_BIT) +#define MTK_SIP_SPM_DVFSRC_INIT 0x00 + +#endif
Signature · 1 line
1.9.1
RFC v2 6/11 soc: mediatek: add MT8183 dvfsrc support
In reply to Henry ChenAdd dvfsrc driver for MT8183
--- drivers/soc/mediatek/Kconfig | 15 ++ drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-dvfsrc.c | 347 ++++++++++++++++++++++++++++++++++++++ include/soc/mediatek/mtk_dvfsrc.h | 22 +++ 4 files changed, 385 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-dvfsrc.c create mode 100644 include/soc/mediatek/mtk_dvfsrc.h
drivers/soc/mediatek/Kconfig +15 -0
@@ -24,6 +24,21 @@ config MTK_INFRACFG INFRACFG controller contains various infrastructure registers not directly associated to any device. +config MTK_DVFSRC + bool "MediaTek DVFSRC Support" + depends on ARCH_MEDIATEK + default ARCH_MEDIATEK + select MTK_INFRACFG + select PM_GENERIC_DOMAINS if PM + depends on MTK_SCPSYS + help + Say yes here to add support for the MediaTek DVFSRC (dynamic voltage + and frequency scaling resource collector) found + on different MediaTek SoCs. The DVFSRC is a proprietary + hardware which is used to collect all the requests from + system and turn into the decision of minimum Vcore voltage + and minimum DRAM frequency to fulfill those requests. + config MTK_PMIC_WRAP tristate "MediaTek PMIC Wrapper Support" depends on RESET_CONTROLLER
drivers/soc/mediatek/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o +obj-$(CONFIG_MTK_DVFSRC) += mtk-dvfsrc.o obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o mtk-scpsys-ext.o obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
drivers/soc/mediatek/mtk-dvfsrc.c new file +347 -0
347 lines not on this page · raw message
include/soc/mediatek/mtk_dvfsrc.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ +#ifndef __SOC_MTK_DVFSRC_H +#define __SOC_MTK_DVFSRC_H + +#define MTK_DVFSRC_CMD_BW_REQUEST 0 +#define MTK_DVFSRC_CMD_OPP_REQUEST 1 + +#if IS_ENABLED (CONFIG_MTK_DVFSRC ) +void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd,u64 data); + +#else + +static inline void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd, +u64 data) +{return -ENODEV ; } + +#endif /* CONFIG_MTK_DVFSRC */ + +#endif
Signature · 1 line
1.9.1
Re: [RFC V2 06/11] soc: mediatek: add MT8183 dvfsrc support
Hi Henry,
Quoted 146 lines · Henry Chen
Add dvfsrc driver for MT8183
Signed-off-by Henry Chen <[email protected]>--- drivers/soc/mediatek/Kconfig | 15 ++ drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-dvfsrc.c | 347 ++++++++++++++++++++++++++++++++++++++ include/soc/mediatek/mtk_dvfsrc.h | 22 +++ 4 files changed, 385 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-dvfsrc.c create mode 100644 include/soc/mediatek/mtk_dvfsrc.hdrivers/soc/mediatek/Kconfig +15
-0@@ -24,6 +24,21 @@ config MTK_INFRACFG INFRACFG controller contains various infrastructure registers not directly associated to any device. +config MTK_DVFSRC + bool "MediaTek DVFSRC Support" + depends on ARCH_MEDIATEK + default ARCH_MEDIATEK + select MTK_INFRACFG + select PM_GENERIC_DOMAINS if PM + depends on MTK_SCPSYS + help + Say yes here to add support for the MediaTek DVFSRC (dynamic voltage + and frequency scaling resource collector) found + on different MediaTek SoCs. The DVFSRC is a proprietary + hardware which is used to collect all the requests from + system and turn into the decision of minimum Vcore voltage + and minimum DRAM frequency to fulfill those requests. + config MTK_PMIC_WRAP tristate "MediaTek PMIC Wrapper Support" depends on RESET_CONTROLLERdrivers/soc/mediatek/Makefile +1
-0@@ -1,4 +1,5 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o +obj-$(CONFIG_MTK_DVFSRC) += mtk-dvfsrc.o obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o mtk-scpsys-ext.o obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.odrivers/soc/mediatek/mtk-dvfsrc.c new file +91
-0@@ -0,0 +1,347 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ +#include <linux/arm-smccc.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <soc/mediatek/mtk_dvfsrc.h> +#include <soc/mediatek/mtk_sip.h> +#include <dt-bindings/power/mt8183-power.h> +#include <dt-bindings/soc/mtk,dvfsrc.h> +#include <dt-bindings/soc/mtk,dvfsrc.h> +#include "mtk-scpsys.h" + +#define DVFSRC_IDLE 0x00 +#define DVFSRC_GET_TARGET_LEVEL (x) (((x) >> 0) & 0x0000ffff) +#define DVFSRC_GET_CURRENT_LEVEL (x) (((x) >> 16) & 0x0000ffff) + +#define MT8183_DVFSRC_OPP_LP4 0 +#define MT8183_DVFSRC_OPP_LP4X 1 +#define MT8183_DVFSRC_OPP_LP3 2 + +struct dvfsrc_opp { +u32 vcore_opp; +u32 dram_opp; +}; + +struct dvfsrc_domain { +u32 id; +u32 state; +}; + +struct mtk_dvfsrc ; +struct dvfsrc_soc_data { +const int *regs; +u32 num_opp; +u32 num_domains; +const struct dvfsrc_opp **opps; +struct dvfsrc_domain *domains; +int (*get_target_level)(struct mtk_dvfsrc *dvfsrc); +int (*get_current_level)(struct mtk_dvfsrc *dvfsrc); +void (*set_dram_bw)(struct mtk_dvfsrc *dvfsrc,u64 bw); +void (*set_opp_level)(struct mtk_dvfsrc *dvfsrc,u32 level); +}; + +struct mtk_dvfsrc { +struct device *dev; +struct clk *clk_dvfsrc; +const struct dvfsrc_soc_data *dvd; +int dram_type; +void __iomem *regs; +struct mutex lock; +struct notifier_block scpsys_notifier; +}; + +static u32 dvfsrc_read (struct mtk_dvfsrc *dvfs,u32 offset) +{ +return readl (dvfs->regs + dvfs->dvd->regs[offset]); +} + +static void dvfsrc_write (struct mtk_dvfsrc *dvfs,u32 offset,u32 val) +{ +writel (val, dvfs->regs + dvfs->dvd->regs[offset]); +} + +enum dvfsrc_regs { +DVFSRC_SW_REQ , +DVFSRC_LEVEL , +DVFSRC_SW_BW_0 , +DVFSRC_LAST , +}; + +static const int mt8183_regs[] = { + [DVFSRC_SW_REQ ] =0x4 , + [DVFSRC_LEVEL ] =0xDC , + [DVFSRC_SW_BW_0 ] =0x160 , + [DVFSRC_LAST ] =0x308 , +}; + +static bool dvfsrc_is_idle (struct mtk_dvfsrc *dvfsrc) +{ +if (!dvfsrc->dvd->get_target_level) +return true; + +return dvfsrc->dvd->get_target_level (dvfsrc) ==DVFSRC_IDLE ; +} +
drivers/soc/mediatek/mtk-dvfsrc.c line 101
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+static int dvfsrc_wait_for_idle (struct mtk_dvfsrc *dvfsrc) +{ +unsigned long timeout; + + timeout = jiffies +usecs_to_jiffies (1000 ); + +do { +if (dvfsrc_is_idle (dvfsrc)) +return 0 ; + }while (!time_after (jiffies, timeout));
This all seems like it would be better handled by readx_poll_timeout rather than rolling your own.
Quoted 67 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +67
-0+ +return -ETIMEDOUT ; +} + +static int mt8183_get_target_level (struct mtk_dvfsrc *dvfsrc) +{ +return DVFSRC_GET_TARGET_LEVEL (dvfsrc_read (dvfsrc,DVFSRC_LEVEL )); +} + +static int mt8183_get_current_level (struct mtk_dvfsrc *dvfsrc) +{ +return ffs (DVFSRC_GET_CURRENT_LEVEL (dvfsrc_read (dvfsrc,DVFSRC_LEVEL ))); +} + +static void mt8183_set_dram_bw (struct mtk_dvfsrc *dvfsrc,u64 bw) +{ +dvfsrc_write (dvfsrc,DVFSRC_SW_BW_0 , bw); +} + +static void mt8183_set_opp_level (struct mtk_dvfsrc *dvfsrc,u32 level) +{ +int vcore_opp, dram_opp; +const struct dvfsrc_opp *opp; + +/* translate pstate to dvfsrc level, and set it to DVFSRC HW */ + opp = &dvfsrc->dvd->opps[dvfsrc->dram_type][level -1 ]; + vcore_opp = opp->vcore_opp; + dram_opp = opp->dram_opp; + +dev_dbg (dvfsrc->dev,"vcore_opp: %d, dram_opp: %d\n" , + vcore_opp, dram_opp); +dvfsrc_write (dvfsrc,DVFSRC_SW_REQ , dram_opp | vcore_opp <<2 ); +} + +void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd,u64 data) +{ +struct mtk_dvfsrc *dvfsrc =dev_get_drvdata (dev); + +dev_dbg (dvfsrc->dev,"cmd: %d, data: %llu\n" , cmd, data); + +mutex_lock (&dvfsrc->lock); + +if (dvfsrc_wait_for_idle (dvfsrc)) { +dev_warn (dvfsrc->dev,"[%s] wait idle, last: %d -> %d\n" , + __func__,dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), +dvfsrc_read (dvfsrc,DVFSRC_LAST )); + goto out; + } + +switch (cmd) { +case MTK_DVFSRC_CMD_BW_REQUEST : + dvfsrc->dvd->set_dram_bw (dvfsrc, data); + goto out; +case MTK_DVFSRC_CMD_OPP_REQUEST : + dvfsrc->dvd->set_opp_level (dvfsrc, data); +break ; +default : +dev_err (dvfsrc->dev,"unknown command: %d\n" , cmd); +break ; + } + +if (dvfsrc_wait_for_idle (dvfsrc)) { +dev_warn (dvfsrc->dev,"[%s] wait idle, last: %d -> %d\n" , + __func__,dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), +dvfsrc_read (dvfsrc,DVFSRC_LAST )); + goto out; + }
drivers/soc/mediatek/mtk-dvfsrc.c line 178
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+ +out: +mutex_unlock (&dvfsrc->lock); +} +EXPORT_SYMBOL (mtk_dvfsrc_send_request); + +static int dvfsrc_set_performance (struct notifier_block *b, +unsigned long l,void *v) +{ +int i, val, highest;
Variable names could be improved. "val" is only ever used to store the current level, would be nice to make the name more specific. Similarly "l" looks like it would be better as something state related.
val and highest at least should be u32.
Quoted 4 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +4
-0+struct mtk_dvfsrc *dvfsrc; +struct scp_event_data *sc = v; +struct dvfsrc_domain *d; +
drivers/soc/mediatek/mtk-dvfsrc.c line 192
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+if (sc->event_type !=MTK_SCPSYS_PSTATE ) +return 0 ; + + dvfsrc = container_of(b, struct mtk_dvfsrc, scpsys_notifier); + + d = dvfsrc->dvd->domains; + +if (l > dvfsrc->dvd->num_opp) { +dev_err (dvfsrc->dev,"pstate out of range = %ld\n" , l); + goto out;
Can just return 0;
drivers/soc/mediatek/mtk-dvfsrc.c line 195
Quoted 3 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +3
-0+ } + +for (i =0 , highest =0 ; i < dvfsrc->dvd->num_domains -1 ; i++, d++) {
It's not immediately clear to me why a domain is skipped (the -1). This is either worth a comment or it may be a bug?
drivers/soc/mediatek/mtk-dvfsrc.c line 203
Quoted 8 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +8
-0+if (sc->domain_id == d->id) + d->state = l; +if (d->state > highest) + highest = d->state; + } + +if (highest ==0 ) { +dev_err (dvfsrc->dev,"domain not match\n" );
This text is incorrect. You're checking whether all domains had a state of zero, not whether you found a domain match. Is this check actually needed?
drivers/soc/mediatek/mtk-dvfsrc.c line 204
Quoted 1 line
drivers/soc/mediatek/mtk-dvfsrc.c new file +1
-0+ goto out;
return 0;
drivers/soc/mediatek/mtk-dvfsrc.c line 214
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+ } + +mtk_dvfsrc_send_request (dvfsrc->dev,MTK_DVFSRC_CMD_OPP_REQUEST , + highest); + + val = dvfsrc->dvd->get_current_level (dvfsrc); + +dev_dbg (dvfsrc->dev,"DVFSRC_LEVEL: %x, val: %x, DVFSRC_SW_REQ: %x\n" , +dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), val, +dvfsrc_read (dvfsrc,DVFSRC_SW_REQ ));
"val:" to "current level:" or something similarly descriptive.
drivers/soc/mediatek/mtk-dvfsrc.c line 218
Quoted 4 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +4
-0+ +if (val < highest) { +dev_err (dvfsrc->dev,"current: %d < highest: %x\n" , + val, highest);
This message isn't clear and should be more explicit. Something like "Current level %d < highest requested %d"
drivers/soc/mediatek/mtk-dvfsrc.c line 219
Quoted 1 line
drivers/soc/mediatek/mtk-dvfsrc.c new file +1
-0+ goto out;
return 0;
drivers/soc/mediatek/mtk-dvfsrc.c line 170
Quoted 3 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +3
-0+ } + +out:
Out label no longer needed.
Quoted 156 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +125
-0+return 0 ; +} + +static void pstate_notifier_register (struct mtk_dvfsrc *dvfsrc) +{ + dvfsrc->scpsys_notifier.notifier_call = dvfsrc_set_performance; +register_scpsys_notifier (&dvfsrc->scpsys_notifier); +} + +static int mtk_dvfsrc_probe (struct platform_device *pdev) +{ +struct arm_smccc_res ares; +struct resource *res; +struct mtk_dvfsrc *dvfsrc; +int ret; + + dvfsrc =devm_kzalloc (&pdev->dev,sizeof (*dvfsrc),GFP_KERNEL ); +if (!dvfsrc) +return -ENOMEM ; + + dvfsrc->dvd =of_device_get_match_data (&pdev->dev); + dvfsrc->dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + dvfsrc->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (dvfsrc->regs)) +return PTR_ERR (dvfsrc->regs); + + dvfsrc->clk_dvfsrc =devm_clk_get (dvfsrc->dev,"dvfsrc" ); +if (IS_ERR (dvfsrc->clk_dvfsrc)) { +dev_err (dvfsrc->dev,"failed to get clock: %ld\n" , +PTR_ERR (dvfsrc->clk_dvfsrc)); +return PTR_ERR (dvfsrc->clk_dvfsrc); + } + + ret =clk_prepare_enable (dvfsrc->clk_dvfsrc); +if (ret) +return ret; + +mutex_init (&dvfsrc->lock); + +arm_smccc_smc (MTK_SIP_SPM ,MTK_SIP_SPM_DVFSRC_INIT ,0 ,0 ,0 ,0 ,0 ,0 , + &ares); + +if (!ares.a0) { + dvfsrc->dram_type = ares.a1; + }else { +dev_err (dvfsrc->dev,"init fails: %lu\n" , ares.a0); +clk_disable_unprepare (dvfsrc->clk_dvfsrc); +return ares.a0; + } + +platform_set_drvdata (pdev, dvfsrc); +pstate_notifier_register (dvfsrc); + +return devm_of_platform_populate (&pdev->dev); +} + +static const struct dvfsrc_opp dvfsrc_opp_mt8183_lp4[] = { + {0 ,0 }, {0 ,1 }, {0 ,2 }, {1 ,2 }, +}; + +static const struct dvfsrc_opp dvfsrc_opp_mt8183_lp3[] = { + {0 ,0 }, {0 ,1 }, {1 ,1 }, {1 ,2 }, +}; + +static const struct dvfsrc_opp *dvfsrc_opp_mt8183[] = { + [MT8183_DVFSRC_OPP_LP4 ] = dvfsrc_opp_mt8183_lp4, + [MT8183_DVFSRC_OPP_LP4X ] = dvfsrc_opp_mt8183_lp3, + [MT8183_DVFSRC_OPP_LP3 ] = dvfsrc_opp_mt8183_lp3, +}; + +static struct dvfsrc_domain dvfsrc_domains_mt8183[] = { + {MT8183_POWER_DOMAIN_MFG_ASYNC ,0 }, + {MT8183_POWER_DOMAIN_MFG ,0 }, + {MT8183_POWER_DOMAIN_CAM ,0 }, + {MT8183_POWER_DOMAIN_DISP ,0 }, + {MT8183_POWER_DOMAIN_ISP ,0 }, + {MT8183_POWER_DOMAIN_VDEC ,0 }, + {MT8183_POWER_DOMAIN_VENC ,0 }, +}; + +static const struct dvfsrc_soc_data mt8183_data = { + .opps = dvfsrc_opp_mt8183, + .num_opp =ARRAY_SIZE (dvfsrc_opp_mt8183_lp4), + .regs = mt8183_regs, + .domains = dvfsrc_domains_mt8183, + .num_domains =ARRAY_SIZE (dvfsrc_domains_mt8183), + .get_target_level = mt8183_get_target_level, + .get_current_level = mt8183_get_current_level, + .set_dram_bw = mt8183_set_dram_bw, + .set_opp_level = mt8183_set_opp_level, +}; + +static int mtk_dvfsrc_remove (struct platform_device *pdev) +{ +struct mtk_dvfsrc *dvfsrc =platform_get_drvdata (pdev); + +clk_disable_unprepare (dvfsrc->clk_dvfsrc); + +return 0 ; +} + +static const struct of_device_id mtk_dvfsrc_of_match[] = { + { + .compatible ="mediatek,mt8183-dvfsrc" , + .data = &mt8183_data, + }, { +/* sentinel */ + }, +}; + +static struct platform_driver mtk_dvfsrc_driver = { + .probe = mtk_dvfsrc_probe, + .remove = mtk_dvfsrc_remove, + .driver = { + .name ="mtk-dvfsrc" , + .of_match_table =of_match_ptr (mtk_dvfsrc_of_match), + }, +}; + +builtin_platform_driver (mtk_dvfsrc_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("MTK DVFSRC driver" );include/soc/mediatek/mtk_dvfsrc.h new file +22
-1@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ +#ifndef __SOC_MTK_DVFSRC_H +#define __SOC_MTK_DVFSRC_H + +#define MTK_DVFSRC_CMD_BW_REQUEST 0 +#define MTK_DVFSRC_CMD_OPP_REQUEST 1 + +#if IS_ENABLED (CONFIG_MTK_DVFSRC ) +void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd,u64 data); + +#else + +static inline void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd, +u64 data) +{return -ENODEV ; } + +#endif /* CONFIG_MTK_DVFSRC */ + +#endif --1.9.1
Re: [RFC V2 06/11] soc: mediatek: add MT8183 dvfsrc support
On Mon, 2019-06-10 at 14:00 -0700, Ryan Case wrote:
Hi Ryan,
Sorry for late reply.
Quoted 154 lines
Hi Henry,
Quoted 151 lines · Henry Chen
Add dvfsrc driver for MT8183
Signed-off-by Henry Chen <[email protected]>--- drivers/soc/mediatek/Kconfig | 15 ++ drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-dvfsrc.c | 347 ++++++++++++++++++++++++++++++++++++++ include/soc/mediatek/mtk_dvfsrc.h | 22 +++ 4 files changed, 385 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-dvfsrc.c create mode 100644 include/soc/mediatek/mtk_dvfsrc.hdrivers/soc/mediatek/Kconfig +15
-0@@ -24,6 +24,21 @@ config MTK_INFRACFG INFRACFG controller contains various infrastructure registers not directly associated to any device. +config MTK_DVFSRC + bool "MediaTek DVFSRC Support" + depends on ARCH_MEDIATEK + default ARCH_MEDIATEK + select MTK_INFRACFG + select PM_GENERIC_DOMAINS if PM + depends on MTK_SCPSYS + help + Say yes here to add support for the MediaTek DVFSRC (dynamic voltage + and frequency scaling resource collector) found + on different MediaTek SoCs. The DVFSRC is a proprietary + hardware which is used to collect all the requests from + system and turn into the decision of minimum Vcore voltage + and minimum DRAM frequency to fulfill those requests. + config MTK_PMIC_WRAP tristate "MediaTek PMIC Wrapper Support" depends on RESET_CONTROLLERdrivers/soc/mediatek/Makefile +1
-0@@ -1,4 +1,5 @@ obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o +obj-$(CONFIG_MTK_DVFSRC) += mtk-dvfsrc.o obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o mtk-scpsys-ext.o obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.odrivers/soc/mediatek/mtk-dvfsrc.c new file +96
-0@@ -0,0 +1,347 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2018 MediaTek Inc. +*/ +#include <linux/arm-smccc.h> +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/notifier.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <soc/mediatek/mtk_dvfsrc.h> +#include <soc/mediatek/mtk_sip.h> +#include <dt-bindings/power/mt8183-power.h> +#include <dt-bindings/soc/mtk,dvfsrc.h> +#include <dt-bindings/soc/mtk,dvfsrc.h> +#include "mtk-scpsys.h" + +#define DVFSRC_IDLE 0x00 +#define DVFSRC_GET_TARGET_LEVEL (x) (((x) >> 0) & 0x0000ffff) +#define DVFSRC_GET_CURRENT_LEVEL (x) (((x) >> 16) & 0x0000ffff) + +#define MT8183_DVFSRC_OPP_LP4 0 +#define MT8183_DVFSRC_OPP_LP4X 1 +#define MT8183_DVFSRC_OPP_LP3 2 + +struct dvfsrc_opp { +u32 vcore_opp; +u32 dram_opp; +}; + +struct dvfsrc_domain { +u32 id; +u32 state; +}; + +struct mtk_dvfsrc ; +struct dvfsrc_soc_data { +const int *regs; +u32 num_opp; +u32 num_domains; +const struct dvfsrc_opp **opps; +struct dvfsrc_domain *domains; +int (*get_target_level)(struct mtk_dvfsrc *dvfsrc); +int (*get_current_level)(struct mtk_dvfsrc *dvfsrc); +void (*set_dram_bw)(struct mtk_dvfsrc *dvfsrc,u64 bw); +void (*set_opp_level)(struct mtk_dvfsrc *dvfsrc,u32 level); +}; + +struct mtk_dvfsrc { +struct device *dev; +struct clk *clk_dvfsrc; +const struct dvfsrc_soc_data *dvd; +int dram_type; +void __iomem *regs; +struct mutex lock; +struct notifier_block scpsys_notifier; +}; + +static u32 dvfsrc_read (struct mtk_dvfsrc *dvfs,u32 offset) +{ +return readl (dvfs->regs + dvfs->dvd->regs[offset]); +} + +static void dvfsrc_write (struct mtk_dvfsrc *dvfs,u32 offset,u32 val) +{ +writel (val, dvfs->regs + dvfs->dvd->regs[offset]); +} + +enum dvfsrc_regs { +DVFSRC_SW_REQ , +DVFSRC_LEVEL , +DVFSRC_SW_BW_0 , +DVFSRC_LAST , +}; + +static const int mt8183_regs[] = { + [DVFSRC_SW_REQ ] =0x4 , + [DVFSRC_LEVEL ] =0xDC , + [DVFSRC_SW_BW_0 ] =0x160 , + [DVFSRC_LAST ] =0x308 , +}; + +static bool dvfsrc_is_idle (struct mtk_dvfsrc *dvfsrc) +{ +if (!dvfsrc->dvd->get_target_level) +return true; + +return dvfsrc->dvd->get_target_level (dvfsrc) ==DVFSRC_IDLE ; +} + +static int dvfsrc_wait_for_idle (struct mtk_dvfsrc *dvfsrc) +{ +unsigned long timeout; + + timeout = jiffies +usecs_to_jiffies (1000 );
Quoted 8 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 101
Quoted 5 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +5
-0+ +do { +if (dvfsrc_is_idle (dvfsrc)) +return 0 ; + }while (!time_after (jiffies, timeout));This all seems like it would be better handled by
readx_poll_timeoutrather than rolling your own.
It's great suggestion, thanks.
Quoted 83 lines
Quoted 68 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +67
-0+ +return -ETIMEDOUT ; +} + +static int mt8183_get_target_level (struct mtk_dvfsrc *dvfsrc) +{ +return DVFSRC_GET_TARGET_LEVEL (dvfsrc_read (dvfsrc,DVFSRC_LEVEL )); +} + +static int mt8183_get_current_level (struct mtk_dvfsrc *dvfsrc) +{ +return ffs (DVFSRC_GET_CURRENT_LEVEL (dvfsrc_read (dvfsrc,DVFSRC_LEVEL ))); +} + +static void mt8183_set_dram_bw (struct mtk_dvfsrc *dvfsrc,u64 bw) +{ +dvfsrc_write (dvfsrc,DVFSRC_SW_BW_0 , bw); +} + +static void mt8183_set_opp_level (struct mtk_dvfsrc *dvfsrc,u32 level) +{ +int vcore_opp, dram_opp; +const struct dvfsrc_opp *opp; + +/* translate pstate to dvfsrc level, and set it to DVFSRC HW */ + opp = &dvfsrc->dvd->opps[dvfsrc->dram_type][level -1 ]; + vcore_opp = opp->vcore_opp; + dram_opp = opp->dram_opp; + +dev_dbg (dvfsrc->dev,"vcore_opp: %d, dram_opp: %d\n" , + vcore_opp, dram_opp); +dvfsrc_write (dvfsrc,DVFSRC_SW_REQ , dram_opp | vcore_opp <<2 ); +} + +void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd,u64 data) +{ +struct mtk_dvfsrc *dvfsrc =dev_get_drvdata (dev); + +dev_dbg (dvfsrc->dev,"cmd: %d, data: %llu\n" , cmd, data); + +mutex_lock (&dvfsrc->lock); + +if (dvfsrc_wait_for_idle (dvfsrc)) { +dev_warn (dvfsrc->dev,"[%s] wait idle, last: %d -> %d\n" , + __func__,dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), +dvfsrc_read (dvfsrc,DVFSRC_LAST )); + goto out; + } + +switch (cmd) { +case MTK_DVFSRC_CMD_BW_REQUEST : + dvfsrc->dvd->set_dram_bw (dvfsrc, data); + goto out; +case MTK_DVFSRC_CMD_OPP_REQUEST : + dvfsrc->dvd->set_opp_level (dvfsrc, data); +break ; +default : +dev_err (dvfsrc->dev,"unknown command: %d\n" , cmd); +break ; + } + +if (dvfsrc_wait_for_idle (dvfsrc)) { +dev_warn (dvfsrc->dev,"[%s] wait idle, last: %d -> %d\n" , + __func__,dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), +dvfsrc_read (dvfsrc,DVFSRC_LAST )); + goto out; + }drivers/soc/mediatek/mtk-dvfsrc.c line 178
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+ +out: +mutex_unlock (&dvfsrc->lock); +} +EXPORT_SYMBOL (mtk_dvfsrc_send_request); + +static int dvfsrc_set_performance (struct notifier_block *b, +unsigned long l,void *v) +{ +int i, val, highest;Variable names could be improved. "val" is only ever used to store the current level, would be nice to make the name more specific. Similarly "l" looks like it would be better as something state related.
Quoted 1 line
val and highest at least should be u32.
ok, about naming, I will correct and make it more clearly.
Quoted 17 lines
Quoted 5 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +4
-0+struct mtk_dvfsrc *dvfsrc; +struct scp_event_data *sc = v; +struct dvfsrc_domain *d; +drivers/soc/mediatek/mtk-dvfsrc.c line 192
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+if (sc->event_type !=MTK_SCPSYS_PSTATE ) +return 0 ; + + dvfsrc = container_of(b, struct mtk_dvfsrc, scpsys_notifier); + + d = dvfsrc->dvd->domains; + +if (l > dvfsrc->dvd->num_opp) { +dev_err (dvfsrc->dev,"pstate out of range = %ld\n" , l); + goto out;Can just return 0;
ok.
Quoted 7 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 195
Quoted 4 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +3
-0+ } + +for (i =0 , highest =0 ; i < dvfsrc->dvd->num_domains -1 ; i++, d++) {It's not immediately clear to me why a domain is skipped (the -1). This is either worth a comment or it may be a bug?
Indeed, it no need, I will check and re-test again, thanks.
Quoted 10 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 203
Quoted 9 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +8
-0+if (sc->domain_id == d->id) + d->state = l; +if (d->state > highest) + highest = d->state; + } + +if (highest ==0 ) { +dev_err (dvfsrc->dev,"domain not match\n" );
Quoted 3 lines
This text is incorrect. You're checking whether all domains had a state of zero, not whether you found a domain match. Is this check actually needed?
I intend to check if the domain match or no. To avoid confusing, I will re-write it and used flag to check it.
Quoted 4 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 204
Quoted 2 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +1
-0+ goto out;return 0;
ok.
Quoted 13 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 214
Quoted 11 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +10
-0+ } + +mtk_dvfsrc_send_request (dvfsrc->dev,MTK_DVFSRC_CMD_OPP_REQUEST , + highest); + + val = dvfsrc->dvd->get_current_level (dvfsrc); + +dev_dbg (dvfsrc->dev,"DVFSRC_LEVEL: %x, val: %x, DVFSRC_SW_REQ: %x\n" , +dvfsrc_read (dvfsrc,DVFSRC_LEVEL ), val, +dvfsrc_read (dvfsrc,DVFSRC_SW_REQ ));"val:" to "current level:" or something similarly descriptive.
ok.
Quoted 6 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 218
Quoted 5 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +4
-0+ +if (val < highest) { +dev_err (dvfsrc->dev,"current: %d < highest: %x\n" , + val, highest);
Quoted 6 lines
This message isn't clear and should be more explicit. Something like "Current level %d < highest requested %d"
drivers/soc/mediatek/mtk-dvfsrc.c line 219
Quoted 1 line
drivers/soc/mediatek/mtk-dvfsrc.c new file +1
-0+ goto out;return 0;
ok.
Quoted 6 lines
drivers/soc/mediatek/mtk-dvfsrc.c line 170
Quoted 4 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +3
-0+ } + +out:Out label no longer needed.
ok.
Quoted 157 lines
Quoted 157 lines
drivers/soc/mediatek/mtk-dvfsrc.c new file +125
-0+return 0 ; +} + +static void pstate_notifier_register (struct mtk_dvfsrc *dvfsrc) +{ + dvfsrc->scpsys_notifier.notifier_call = dvfsrc_set_performance; +register_scpsys_notifier (&dvfsrc->scpsys_notifier); +} + +static int mtk_dvfsrc_probe (struct platform_device *pdev) +{ +struct arm_smccc_res ares; +struct resource *res; +struct mtk_dvfsrc *dvfsrc; +int ret; + + dvfsrc =devm_kzalloc (&pdev->dev,sizeof (*dvfsrc),GFP_KERNEL ); +if (!dvfsrc) +return -ENOMEM ; + + dvfsrc->dvd =of_device_get_match_data (&pdev->dev); + dvfsrc->dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + dvfsrc->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (dvfsrc->regs)) +return PTR_ERR (dvfsrc->regs); + + dvfsrc->clk_dvfsrc =devm_clk_get (dvfsrc->dev,"dvfsrc" ); +if (IS_ERR (dvfsrc->clk_dvfsrc)) { +dev_err (dvfsrc->dev,"failed to get clock: %ld\n" , +PTR_ERR (dvfsrc->clk_dvfsrc)); +return PTR_ERR (dvfsrc->clk_dvfsrc); + } + + ret =clk_prepare_enable (dvfsrc->clk_dvfsrc); +if (ret) +return ret; + +mutex_init (&dvfsrc->lock); + +arm_smccc_smc (MTK_SIP_SPM ,MTK_SIP_SPM_DVFSRC_INIT ,0 ,0 ,0 ,0 ,0 ,0 , + &ares); + +if (!ares.a0) { + dvfsrc->dram_type = ares.a1; + }else { +dev_err (dvfsrc->dev,"init fails: %lu\n" , ares.a0); +clk_disable_unprepare (dvfsrc->clk_dvfsrc); +return ares.a0; + } + +platform_set_drvdata (pdev, dvfsrc); +pstate_notifier_register (dvfsrc); + +return devm_of_platform_populate (&pdev->dev); +} + +static const struct dvfsrc_opp dvfsrc_opp_mt8183_lp4[] = { + {0 ,0 }, {0 ,1 }, {0 ,2 }, {1 ,2 }, +}; + +static const struct dvfsrc_opp dvfsrc_opp_mt8183_lp3[] = { + {0 ,0 }, {0 ,1 }, {1 ,1 }, {1 ,2 }, +}; + +static const struct dvfsrc_opp *dvfsrc_opp_mt8183[] = { + [MT8183_DVFSRC_OPP_LP4 ] = dvfsrc_opp_mt8183_lp4, + [MT8183_DVFSRC_OPP_LP4X ] = dvfsrc_opp_mt8183_lp3, + [MT8183_DVFSRC_OPP_LP3 ] = dvfsrc_opp_mt8183_lp3, +}; + +static struct dvfsrc_domain dvfsrc_domains_mt8183[] = { + {MT8183_POWER_DOMAIN_MFG_ASYNC ,0 }, + {MT8183_POWER_DOMAIN_MFG ,0 }, + {MT8183_POWER_DOMAIN_CAM ,0 }, + {MT8183_POWER_DOMAIN_DISP ,0 }, + {MT8183_POWER_DOMAIN_ISP ,0 }, + {MT8183_POWER_DOMAIN_VDEC ,0 }, + {MT8183_POWER_DOMAIN_VENC ,0 }, +}; + +static const struct dvfsrc_soc_data mt8183_data = { + .opps = dvfsrc_opp_mt8183, + .num_opp =ARRAY_SIZE (dvfsrc_opp_mt8183_lp4), + .regs = mt8183_regs, + .domains = dvfsrc_domains_mt8183, + .num_domains =ARRAY_SIZE (dvfsrc_domains_mt8183), + .get_target_level = mt8183_get_target_level, + .get_current_level = mt8183_get_current_level, + .set_dram_bw = mt8183_set_dram_bw, + .set_opp_level = mt8183_set_opp_level, +}; + +static int mtk_dvfsrc_remove (struct platform_device *pdev) +{ +struct mtk_dvfsrc *dvfsrc =platform_get_drvdata (pdev); + +clk_disable_unprepare (dvfsrc->clk_dvfsrc); + +return 0 ; +} + +static const struct of_device_id mtk_dvfsrc_of_match[] = { + { + .compatible ="mediatek,mt8183-dvfsrc" , + .data = &mt8183_data, + }, { +/* sentinel */ + }, +}; + +static struct platform_driver mtk_dvfsrc_driver = { + .probe = mtk_dvfsrc_probe, + .remove = mtk_dvfsrc_remove, + .driver = { + .name ="mtk-dvfsrc" , + .of_match_table =of_match_ptr (mtk_dvfsrc_of_match), + }, +}; + +builtin_platform_driver (mtk_dvfsrc_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("MTK DVFSRC driver" );include/soc/mediatek/mtk_dvfsrc.h new file +22
-1@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright (c) 2018 MediaTek Inc. +*/ +#ifndef __SOC_MTK_DVFSRC_H +#define __SOC_MTK_DVFSRC_H + +#define MTK_DVFSRC_CMD_BW_REQUEST 0 +#define MTK_DVFSRC_CMD_OPP_REQUEST 1 + +#if IS_ENABLED (CONFIG_MTK_DVFSRC ) +void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd,u64 data); + +#else + +static inline void mtk_dvfsrc_send_request (const struct device *dev,u32 cmd, +u64 data) +{return -ENODEV ; } + +#endif /* CONFIG_MTK_DVFSRC */ + +#endif --1.9.1
RFC v2 7/11 arm64: dts: mt8183: add dvfsrc related nodes
In reply to Henry ChenEnable dvfsrc on mt8183 platform.
--- arch/arm64/boot/dts/mediatek/mt8183.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +7 -0
@@ -134,6 +134,13 @@ clock-output-names = "clk26m"; }; + dvfsrc@10012000 { + compatible = "mediatek,mt8183-dvfsrc"; + reg = <0 0x10012000 0 0x1000>; + clocks = <&infracfg CLK_INFRA_DVFSRC>; + clock-names = "dvfsrc"; + }; + timer { compatible = "arm,armv8-timer"; interrupt-parent = <&gic>;
Signature · 1 line
1.9.1
RFC v2 8/11 dt-bindings: interconnect: add MT8183 interconnect dt-bindings
In reply to Henry ChenAdd interconnect provider dt-bindings for MT8183.
--- .../bindings/interconnect/mtk,mt8183.txt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +24 -0
@@ -0,0 +1,24 @@ +Mediatek MT8183 interconnect binding + +MT8183 interconnect providers support dram bandwidth requirements. The provider +is able to communicate with the DVFSRC and send the dram bandwidth to it. +Provider nodes must reside within an DVFSRC device node. + +Required properties : +- compatible : shall contain only one of the following: + "mediatek,mt8183-emi-icc" +- #interconnect-cells : should contain 1 + +Examples: + +dvfsrc@10012000 { + compatible = "mediatek,mt8183-dvfsrc"; + reg = <0 0x10012000 0 0x1000>; + clocks = <&infracfg CLK_INFRA_DVFSRC>; + clock-names = "dvfsrc"; + ddr_emi: interconnect { + compatible = "mediatek,mt8183-emi-icc"; + #interconnect-cells = <1>; + }; +}; +
Signature · 1 line
1.9.1
Rob Herring
maintainerRe: [RFC V2 08/11] dt-bindings: interconnect: add MT8183 interconnect dt-bindings
Quoted 14 lines · Henry Chen
Add interconnect provider dt-bindings for MT8183.
Signed-off-by Henry Chen <[email protected]>--- .../bindings/interconnect/mtk,mt8183.txt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mtk,mt8183.txtDocumentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +0
-0
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt line 1
Quoted 1 line
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +1
-0@@ -0,0 +1,24 @@ +Mediatek MT8183 interconnect binding
This should be part of the dvfsrc binding.
Quoted 10 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +10
-0+ +MT8183 interconnect providers support dram bandwidth requirements. The provider +is able to communicate with the DVFSRC and send the dram bandwidth to it. +Provider nodes must reside within an DVFSRC device node. + +Required properties : +- compatible : shall contain only one of the following: + "mediatek,mt8183-emi-icc" +- #interconnect-cells : should contain 1 +
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt line 21
Quoted 10 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +10
-0+Examples: + +dvfsrc@10012000 { + compatible = "mediatek,mt8183-dvfsrc"; + reg = <0 0x10012000 0 0x1000>; + clocks = <&infracfg CLK_INFRA_DVFSRC>; + clock-names = "dvfsrc"; + ddr_emi: interconnect { + compatible = "mediatek,mt8183-emi-icc"; + #interconnect-cells = <1>;
No need for a child node here. Just move #interconnect-cells to the parent.
Rob
Re: [RFC V2 08/11] dt-bindings: interconnect: add MT8183 interconnect dt-bindings
Hi Rob,
Sorry for late reply.
Quoted 9 lines · Rob Herring
Quoted 8 lines · Henry Chen
Add interconnect provider dt-bindings for MT8183.
Signed-off-by Henry Chen <[email protected]>--- .../bindings/interconnect/mtk,mt8183.txt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt
Quoted 9 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt line 1
Quoted 7 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +1
-0@@ -0,0 +1,24 @@ +Mediatek MT8183 interconnect bindingThis should be part of the dvfsrc binding.
ok, will add these into dvfsrc binding.
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +15
-0+ +MT8183 interconnect providers support dram bandwidth requirements. The provider +is able to communicate with the DVFSRC and send the dram bandwidth to it. +Provider nodes must reside within an DVFSRC device node. + +Required properties : +- compatible : shall contain only one of the following: + "mediatek,mt8183-emi-icc" +- #interconnect-cells : should contain 1 + +Examples: + +dvfsrc@10012000 { + compatible = "mediatek,mt8183-dvfsrc"; + reg = <0 0x10012000 0 0x1000>;
Quoted 8 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/interconnect/mtk,mt8183.txt new file +5
-0+ clocks = <&infracfg CLK_INFRA_DVFSRC>; + clock-names = "dvfsrc"; + ddr_emi: interconnect { + compatible = "mediatek,mt8183-emi-icc"; + #interconnect-cells = <1>;No need for a child node here. Just move #interconnect-cells to the parent.
Ihave tried and it cannot work if move "#interconnect-cells" to the parent.
The provider nodes must reside within an DVFSRC device node.
Quoted 2 lines
Rob
RFC v2 9/11 dt-bindings: interconnect: Add header for interconnect node
In reply to Henry ChenAdd header file for mt8183 interconnect node that could be shared between the interconeect provider driver and Device Tree source files.
--- include/dt-bindings/interconnect/mtk,mt8183.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/dt-bindings/interconnect/mtk,mt8183.h
include/dt-bindings/interconnect/mtk,mt8183.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __DT_BINDINGS_INTERCONNECT_MTK_MT8183_H +#define __DT_BINDINGS_INTERCONNECT_MTK_MT8183_H + +#define SLAVE_DDR_EMI 0 +#define MASTER_MCUSYS 1 +#define MASTER_GPU 2 +#define MASTER_MMSYS 3 +#define MASTER_MM_VPU 4 +#define MASTER_MM_DISP 5 +#define MASTER_MM_VDEC 6 +#define MASTER_MM_VENC 7 +#define MASTER_MM_CAM 8 +#define MASTER_MM_IMG 9 +#define MASTER_MM_MDP 10 + +#endif
Signature · 1 line
1.9.1
Rob Herring
maintainerRe: [RFC V2 09/11] dt-bindings: interconnect: Add header for interconnect node
Quoted 8 lines · Henry Chen
Add header file for mt8183 interconnect node that could be shared between the interconeect provider driver and Device Tree source files.
Signed-off-by Henry Chen <[email protected]>--- include/dt-bindings/interconnect/mtk,mt8183.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/dt-bindings/interconnect/mtk,mt8183.h
This goes with the binding patch.
Re: [RFC V2 09/11] dt-bindings: interconnect: Add header for interconnect node
Quoted 11 lines · Rob Herring
Quoted 8 lines · Henry Chen
Add header file for mt8183 interconnect node that could be shared between the interconeect provider driver and Device Tree source files.
Signed-off-by Henry Chen <[email protected]>--- include/dt-bindings/interconnect/mtk,mt8183.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 include/dt-bindings/interconnect/mtk,mt8183.hThis goes with the binding patch.
ok, will merged into previous patch 08.
RFC v2 10/11 interconnect: mediatek: Add mt8183 interconnect provider driver
In reply to Henry ChenIntroduce Mediatek MT8183 specific provider driver using the interconnect framework.
--- drivers/interconnect/Kconfig | 1 + drivers/interconnect/Makefile | 1 + drivers/interconnect/mediatek/Kconfig | 13 ++ drivers/interconnect/mediatek/Makefile | 5 + drivers/interconnect/mediatek/mt8183.c | 223 +++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 drivers/interconnect/mediatek/Kconfig create mode 100644 drivers/interconnect/mediatek/Makefile create mode 100644 drivers/interconnect/mediatek/mt8183.c
drivers/interconnect/Kconfig +1 -0
@@ -11,5 +11,6 @@ menuconfig INTERCONNECT if INTERCONNECT source "drivers/interconnect/qcom/Kconfig" +source "drivers/interconnect/mediatek/Kconfig" endif
drivers/interconnect/Makefile +1 -0
@@ -4,3 +4,4 @@ icc-core-objs := core.o obj-$(CONFIG_INTERCONNECT) += icc-core.o obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/ +obj-$(CONFIG_INTERCONNECT_MTK) += mediatek/
drivers/interconnect/mediatek/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +config INTERCONNECT_MTK + bool "Mediatek Network-on-Chip interconnect drivers" + depends on ARCH_MEDIATEK + help + Support for Mediatek's Network-on-Chip interconnect hardware. + +config INTERCONNECT_MTK_MT8183 + tristate "Mediatek MT8183 interconnect driver" + depends on INTERCONNECT_MTK + depends on (MTK_DVFSRC && OF) + help + This is a driver for the Mediatek Network-on-Chip on mt8183-based + platforms.
drivers/interconnect/mediatek/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +mtk-mt8183-objs := mt8183.o + +obj-$(CONFIG_INTERCONNECT_MTK_MT8183) += mtk-mt8183.o
drivers/interconnect/mediatek/mt8183.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [RFC V2 10/11] interconnect: mediatek: Add mt8183 interconnect provider driver
Hi Henry,
Quoted 72 lines · Henry Chen
Introduce Mediatek MT8183 specific provider driver using the interconnect framework.
Signed-off-by Henry Chen <[email protected]>--- drivers/interconnect/Kconfig | 1 + drivers/interconnect/Makefile | 1 + drivers/interconnect/mediatek/Kconfig | 13 ++ drivers/interconnect/mediatek/Makefile | 5 + drivers/interconnect/mediatek/mt8183.c | 223 +++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 drivers/interconnect/mediatek/Kconfig create mode 100644 drivers/interconnect/mediatek/Makefile create mode 100644 drivers/interconnect/mediatek/mt8183.cdrivers/interconnect/Kconfig +1
-0@@ -11,5 +11,6 @@ menuconfig INTERCONNECT if INTERCONNECT source "drivers/interconnect/qcom/Kconfig" +source "drivers/interconnect/mediatek/Kconfig" endifdrivers/interconnect/Makefile +1
-0@@ -4,3 +4,4 @@ icc-core-objs := core.o obj-$(CONFIG_INTERCONNECT) += icc-core.o obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/ +obj-$(CONFIG_INTERCONNECT_MTK) += mediatek/drivers/interconnect/mediatek/Kconfig new file +13
-0@@ -0,0 +1,13 @@ +config INTERCONNECT_MTK + bool "Mediatek Network-on-Chip interconnect drivers" + depends on ARCH_MEDIATEK + help + Support for Mediatek's Network-on-Chip interconnect hardware. + +config INTERCONNECT_MTK_MT8183 + tristate "Mediatek MT8183 interconnect driver" + depends on INTERCONNECT_MTK + depends on (MTK_DVFSRC && OF) + help + This is a driver for the Mediatek Network-on-Chip on mt8183-based + platforms.drivers/interconnect/mediatek/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +mtk-mt8183-objs := mt8183.o + +obj-$(CONFIG_INTERCONNECT_MTK_MT8183) += mtk-mt8183.odrivers/interconnect/mediatek/mt8183.c new file +0
-0
drivers/interconnect/mediatek/mt8183.c line 9
Quoted 9 lines
drivers/interconnect/mediatek/mt8183.c new file +9
-0@@ -0,0 +1,223 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019, The Linux Foundation. All rights reserved. +* +*/ + +#include <dt-bindings/interconnect/mtk,mt8183.h> +#include <linux/device.h> +#include <linux/interconnect.h>
This is not needed.
Quoted 7 lines
drivers/interconnect/mediatek/mt8183.c new file +7
-0+#include <linux/interconnect-provider.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <soc/mediatek/mtk_dvfsrc.h> +
drivers/interconnect/mediatek/mt8183.c line 26
Quoted 10 lines
drivers/interconnect/mediatek/mt8183.c new file +10
-0+#define MT8183_MAX_LINKS 6 + +/** +* struct mtk_icc_node - Mediatek specific interconnect nodes +* @name: the node name used in debugfs +* @ep: true if the node is an end point. +* @id: a unique node identifier +* @links: an array of nodes where we can go next while traversing +* @num_links: the total number of @links +* @buswidth: width of the interconnect between a node and the bus
Maybe mention the units?
drivers/interconnect/mediatek/mt8183.c line 28
Quoted 2 lines
drivers/interconnect/mediatek/mt8183.c new file +2
-0+* @sum_avg: current sum aggregate value of all avg bw requests +* @max_peak: current max aggregate value of all peak bw requests
units?
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c new file +8
-0+*/ +struct mtk_icc_node { +unsigned char *name; +bool ep; +u16 id; +u16 links[MT8183_MAX_LINKS ]; +u16 num_links; +u16 buswidth;
drivers/interconnect/mediatek/mt8183.c line 46
Quoted 10 lines
drivers/interconnect/mediatek/mt8183.c new file +10
-0+u64 sum_avg; +u64 max_peak; +}; + +struct mtk_icc_desc { +struct mtk_icc_node **nodes; +size_t num_nodes; +}; + +#define DEFINE_MNODE (_name, _id, _buswidth, _ep, _numlinks, ...) \
We can drop the _numlinks and..
drivers/interconnect/mediatek/mt8183.c line 52
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+static struct mtk_icc_node _name = { \ + .name = #_name, \ + .id = _id, \ + .buswidth = _buswidth, \ + .ep = _ep, \ + .num_links = _numlinks, \
..just use .num_links = ARRAY_SIZE(((int[]){ __VA_ARGS__ }))
Quoted 120 lines
drivers/interconnect/mediatek/mt8183.c new file +120
-0+ .links = { __VA_ARGS__ }, \ +} + +DEFINE_MNODE (ddr_emi,SLAVE_DDR_EMI ,1024 ,1 ,0 ,0 ); +DEFINE_MNODE (mcusys,MASTER_MCUSYS ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (gpu,MASTER_GPU ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (mmsys,MASTER_MMSYS ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (mm_vpu,MASTER_MM_VPU ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_disp,MASTER_MM_DISP ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_vdec,MASTER_MM_VDEC ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_venc,MASTER_MM_VENC ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_cam,MASTER_MM_CAM ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_img,MASTER_MM_IMG ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_mdp,MASTER_MM_MDP ,128 ,0 ,1 ,MASTER_MMSYS ); + +static struct mtk_icc_node *mt8183_icc_nodes[] = { + &ddr_emi, + &mcusys, + &gpu, + &mmsys, + &mm_vpu, + &mm_disp, + &mm_vdec, + &mm_venc, + &mm_cam, + &mm_img, + &mm_mdp, +}; + +static struct mtk_icc_desc mt8183_icc = { + .nodes = mt8183_icc_nodes, + .num_nodes =ARRAY_SIZE (mt8183_icc_nodes), +}; + +static int mt8183_icc_aggregate (struct icc_node *node,u32 avg_bw, +u32 peak_bw,u32 *agg_avg,u32 *agg_peak) +{ +struct mtk_icc_node *in; + + in = node->data; + + *agg_avg += avg_bw; + *agg_peak =max_t (u32, *agg_peak, peak_bw); + + in->sum_avg = *agg_avg; + in->max_peak = *agg_peak; + +return 0 ; +} + +static int mt8183_icc_set (struct icc_node *src,struct icc_node *dst) +{ +int ret =0 ; +struct mtk_icc_node *node; + + node = dst->data; +if (node->ep) { +pr_debug ("sum_avg (%llu), max_peak (%llu)\n" , + node->sum_avg, node->max_peak); +mtk_dvfsrc_send_request (src->provider->dev->parent, +MTK_DVFSRC_CMD_BW_REQUEST , + node->max_peak); + } + +return ret; +} + +static int mt8183_icc_probe (struct platform_device *pdev) +{ +int ret; +const struct mtk_icc_desc *desc; +struct icc_node *node; +struct icc_onecell_data *data; +struct icc_provider *provider; +struct mtk_icc_node **mnodes; +size_t num_nodes, i, j; + + desc =of_device_get_match_data (&pdev->dev); +if (!desc) +return -EINVAL ; + + mnodes = desc->nodes; + num_nodes = desc->num_nodes; + + provider =devm_kzalloc (&pdev->dev,sizeof (*provider),GFP_KERNEL ); +if (!provider) +return -ENOMEM ; + + data =devm_kcalloc (&pdev->dev, num_nodes,sizeof (*node),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + provider->dev = &pdev->dev; + provider->set = mt8183_icc_set; + provider->aggregate = mt8183_icc_aggregate; + provider->xlate = of_icc_xlate_onecell; +INIT_LIST_HEAD (&provider->nodes); + provider->data = data; + + ret =icc_provider_add (provider); +if (ret) { +dev_err (&pdev->dev,"error adding interconnect provider\n" ); +return ret; + } + +for (i =0 ; i < num_nodes; i++) { + node =icc_node_create (mnodes[i]->id); +if (IS_ERR (node)) { + ret =PTR_ERR (node); + goto err; + } + + node->name = mnodes[i]->name; + node->data = mnodes[i]; +icc_node_add (node, provider); + +dev_dbg (&pdev->dev,"registered node %s, num link: %d\n" , + mnodes[i]->name, mnodes[i]->num_links); + +/* populate links */
drivers/interconnect/mediatek/mt8183.c line 182
Quoted 10 lines
drivers/interconnect/mediatek/mt8183.c new file +10
-0+for (j =0 ; j < mnodes[i]->num_links; j++) +icc_link_create (node, mnodes[i]->links[j]); + + data->nodes[i] = node; + } + data->num_nodes = num_nodes; + +platform_set_drvdata (pdev, provider); + +return ret;
just return 0;
Quoted 15 lines
drivers/interconnect/mediatek/mt8183.c new file +15
-0+err: +list_for_each_entry (node, &provider->nodes, node_list) { +icc_node_del (node); +icc_node_destroy (node->id); + } + +icc_provider_del (provider); +return ret; +} + +static int mt8183_icc_remove (struct platform_device *pdev) +{ +struct icc_provider *provider =platform_get_drvdata (pdev); +struct icc_node *n; +
drivers/interconnect/mediatek/mt8183.c line 207
Quoted 10 lines
drivers/interconnect/mediatek/mt8183.c new file +10
-0+list_for_each_entry (n, &provider->nodes, node_list) { +icc_node_del (n); +icc_node_destroy (n->id); + } + +return icc_provider_del (provider); +} + +static const struct of_device_id mt8183_icc_of_match[] = { + { .compatible ="mediatek,mt8183-emi-icc" , .data = &mt8183_icc },
A separate -icc compatible should not be needed.
Thanks,
Georgi
Re: [RFC V2 10/11] interconnect: mediatek: Add mt8183 interconnect provider driver
Hi Georgi,
Sorry for late reply.
Quoted 78 lines · Georgi Djakov
Hi Henry,
Quoted 75 lines · Henry Chen
Introduce Mediatek MT8183 specific provider driver using the interconnect framework.
Signed-off-by Henry Chen <[email protected]>--- drivers/interconnect/Kconfig | 1 + drivers/interconnect/Makefile | 1 + drivers/interconnect/mediatek/Kconfig | 13 ++ drivers/interconnect/mediatek/Makefile | 5 + drivers/interconnect/mediatek/mt8183.c | 223 +++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 drivers/interconnect/mediatek/Kconfig create mode 100644 drivers/interconnect/mediatek/Makefile create mode 100644 drivers/interconnect/mediatek/mt8183.cdrivers/interconnect/Kconfig +1
-0@@ -11,5 +11,6 @@ menuconfig INTERCONNECT if INTERCONNECT source "drivers/interconnect/qcom/Kconfig" +source "drivers/interconnect/mediatek/Kconfig" endifdrivers/interconnect/Makefile +1
-0@@ -4,3 +4,4 @@ icc-core-objs := core.o obj-$(CONFIG_INTERCONNECT) += icc-core.o obj-$(CONFIG_INTERCONNECT_QCOM) += qcom/ +obj-$(CONFIG_INTERCONNECT_MTK) += mediatek/drivers/interconnect/mediatek/Kconfig new file +13
-0@@ -0,0 +1,13 @@ +config INTERCONNECT_MTK + bool "Mediatek Network-on-Chip interconnect drivers" + depends on ARCH_MEDIATEK + help + Support for Mediatek's Network-on-Chip interconnect hardware. + +config INTERCONNECT_MTK_MT8183 + tristate "Mediatek MT8183 interconnect driver" + depends on INTERCONNECT_MTK + depends on (MTK_DVFSRC && OF) + help + This is a driver for the Mediatek Network-on-Chip on mt8183-based + platforms.drivers/interconnect/mediatek/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +mtk-mt8183-objs := mt8183.o + +obj-$(CONFIG_INTERCONNECT_MTK_MT8183) += mtk-mt8183.odrivers/interconnect/mediatek/mt8183.c new file +3
-0@@ -0,0 +1,223 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019, The Linux Foundation. All rights reserved.
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c line 9
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+* +*/ + +#include <dt-bindings/interconnect/mtk,mt8183.h> +#include <linux/device.h> +#include <linux/interconnect.h> This is not needed.
ok, thanks.
Quoted 12 lines
Quoted 12 lines
drivers/interconnect/mediatek/mt8183.c new file +11
-0+#include <linux/interconnect-provider.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <soc/mediatek/mtk_dvfsrc.h> + +#define MT8183_MAX_LINKS 6 + +/** +* struct mtk_icc_node - Mediatek specific interconnect nodes
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c line 26
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+* @name: the node name used in debugfs +* @ep: true if the node is an end point. +* @id: a unique node identifier +* @links: an array of nodes where we can go next while traversing +* @num_links: the total number of @links +* @buswidth: width of the interconnect between a node and the bus Maybe mention the units?
ok, I will add it.
Quoted 18 lines
drivers/interconnect/mediatek/mt8183.c line 28
Quoted 3 lines
drivers/interconnect/mediatek/mt8183.c new file +2
-0+* @sum_avg: current sum aggregate value of all avg bw requests +* @max_peak: current max aggregate value of all peak bw requests units?
Quoted 12 lines
drivers/interconnect/mediatek/mt8183.c new file +12
-0+*/ +struct mtk_icc_node { +unsigned char *name; +bool ep; +u16 id; +u16 links[MT8183_MAX_LINKS ]; +u16 num_links; +u16 buswidth; +u64 sum_avg; +u64 max_peak; +}; +
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c line 46
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+struct mtk_icc_desc { +struct mtk_icc_node **nodes; +size_t num_nodes; +}; + +#define DEFINE_MNODE (_name, _id, _buswidth, _ep, _numlinks, ...) \We can drop the
_numlinksand..
ok, thank you for the advice.
Quoted 134 lines
drivers/interconnect/mediatek/mt8183.c line 52
Quoted 7 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+static struct mtk_icc_node _name = { \ + .name = #_name, \ + .id = _id, \ + .buswidth = _buswidth, \ + .ep = _ep, \ + .num_links = _numlinks, \..just use .num_links =
ARRAY_SIZE(((int[]){ __VA_ARGS__ }))Quoted 124 lines
drivers/interconnect/mediatek/mt8183.c new file +124
-0+ .links = { __VA_ARGS__ }, \ +} + +DEFINE_MNODE (ddr_emi,SLAVE_DDR_EMI ,1024 ,1 ,0 ,0 ); +DEFINE_MNODE (mcusys,MASTER_MCUSYS ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (gpu,MASTER_GPU ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (mmsys,MASTER_MMSYS ,256 ,0 ,1 ,SLAVE_DDR_EMI ); +DEFINE_MNODE (mm_vpu,MASTER_MM_VPU ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_disp,MASTER_MM_DISP ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_vdec,MASTER_MM_VDEC ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_venc,MASTER_MM_VENC ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_cam,MASTER_MM_CAM ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_img,MASTER_MM_IMG ,128 ,0 ,1 ,MASTER_MMSYS ); +DEFINE_MNODE (mm_mdp,MASTER_MM_MDP ,128 ,0 ,1 ,MASTER_MMSYS ); + +static struct mtk_icc_node *mt8183_icc_nodes[] = { + &ddr_emi, + &mcusys, + &gpu, + &mmsys, + &mm_vpu, + &mm_disp, + &mm_vdec, + &mm_venc, + &mm_cam, + &mm_img, + &mm_mdp, +}; + +static struct mtk_icc_desc mt8183_icc = { + .nodes = mt8183_icc_nodes, + .num_nodes =ARRAY_SIZE (mt8183_icc_nodes), +}; + +static int mt8183_icc_aggregate (struct icc_node *node,u32 avg_bw, +u32 peak_bw,u32 *agg_avg,u32 *agg_peak) +{ +struct mtk_icc_node *in; + + in = node->data; + + *agg_avg += avg_bw; + *agg_peak =max_t (u32, *agg_peak, peak_bw); + + in->sum_avg = *agg_avg; + in->max_peak = *agg_peak; + +return 0 ; +} + +static int mt8183_icc_set (struct icc_node *src,struct icc_node *dst) +{ +int ret =0 ; +struct mtk_icc_node *node; + + node = dst->data; +if (node->ep) { +pr_debug ("sum_avg (%llu), max_peak (%llu)\n" , + node->sum_avg, node->max_peak); +mtk_dvfsrc_send_request (src->provider->dev->parent, +MTK_DVFSRC_CMD_BW_REQUEST , + node->max_peak); + } + +return ret; +} + +static int mt8183_icc_probe (struct platform_device *pdev) +{ +int ret; +const struct mtk_icc_desc *desc; +struct icc_node *node; +struct icc_onecell_data *data; +struct icc_provider *provider; +struct mtk_icc_node **mnodes; +size_t num_nodes, i, j; + + desc =of_device_get_match_data (&pdev->dev); +if (!desc) +return -EINVAL ; + + mnodes = desc->nodes; + num_nodes = desc->num_nodes; + + provider =devm_kzalloc (&pdev->dev,sizeof (*provider),GFP_KERNEL ); +if (!provider) +return -ENOMEM ; + + data =devm_kcalloc (&pdev->dev, num_nodes,sizeof (*node),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + provider->dev = &pdev->dev; + provider->set = mt8183_icc_set; + provider->aggregate = mt8183_icc_aggregate; + provider->xlate = of_icc_xlate_onecell; +INIT_LIST_HEAD (&provider->nodes); + provider->data = data; + + ret =icc_provider_add (provider); +if (ret) { +dev_err (&pdev->dev,"error adding interconnect provider\n" ); +return ret; + } + +for (i =0 ; i < num_nodes; i++) { + node =icc_node_create (mnodes[i]->id); +if (IS_ERR (node)) { + ret =PTR_ERR (node); + goto err; + } + + node->name = mnodes[i]->name; + node->data = mnodes[i]; +icc_node_add (node, provider); + +dev_dbg (&pdev->dev,"registered node %s, num link: %d\n" , + mnodes[i]->name, mnodes[i]->num_links); + +/* populate links */ +for (j =0 ; j < mnodes[i]->num_links; j++) +icc_link_create (node, mnodes[i]->links[j]); + + data->nodes[i] = node;
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c line 182
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+ } + data->num_nodes = num_nodes; + +platform_set_drvdata (pdev, provider); + +return ret;just return 0;
ok.
Quoted 20 lines
Quoted 20 lines
drivers/interconnect/mediatek/mt8183.c new file +19
-0+err: +list_for_each_entry (node, &provider->nodes, node_list) { +icc_node_del (node); +icc_node_destroy (node->id); + } + +icc_provider_del (provider); +return ret; +} + +static int mt8183_icc_remove (struct platform_device *pdev) +{ +struct icc_provider *provider =platform_get_drvdata (pdev); +struct icc_node *n; + +list_for_each_entry (n, &provider->nodes, node_list) { +icc_node_del (n); +icc_node_destroy (n->id); + }
Quoted 8 lines
drivers/interconnect/mediatek/mt8183.c line 207
Quoted 6 lines
drivers/interconnect/mediatek/mt8183.c new file +6
-0+ +return icc_provider_del (provider); +} + +static const struct of_device_id mt8183_icc_of_match[] = { + { .compatible ="mediatek,mt8183-emi-icc" , .data = &mt8183_icc },A separate -icc compatible should not be needed.
ok.
Quoted 3 lines
Thanks,
Georgi
RFC v2 11/11 arm64: dts: mt8183: Add interconnect provider DT nodes
In reply to Henry ChenAdd DDR EMI provider dictating dram interconnect bus performance found on MT8183-based platforms
--- arch/arm64/boot/dts/mediatek/mt8183.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183.dtsi +5 -0
@@ -10,6 +10,7 @@ #include <dt-bindings/interrupt-controller/irq.h> #include <dt-bindings/power/mt8183-power.h> #include <dt-bindings/soc/mtk,dvfsrc.h> +#include <dt-bindings/interconnect/mtk,mt8183.h> / { compatible = "mediatek,mt8183";
@@ -139,6 +140,10 @@ reg = <0 0x10012000 0 0x1000>; clocks = <&infracfg CLK_INFRA_DVFSRC>; clock-names = "dvfsrc"; + ddr_emi: interconnect { + compatible = "mediatek,mt8183-emi-icc"; + #interconnect-cells = <1>; + }; }; timer {
Signature · 1 line
1.9.1