arm/arm64: mediatek: Fix mmsys device probing
Subsystems (5)
Matthias Brugger
maintainercover arm/arm64: mediatek: Fix mmsys device probing
MMSYS in Mediatek SoCs has some registers to control clock gates (which is used in the clk driver) and some registers to set the routing and enable the differnet blocks of the display subsystem.
Up to now both drivers, clock and drm are probed with the same device tree compatible. But only the first driver get probed, which in effect breaks graphics on mt8173 and mt2701.
This patch set introduces a new mfd device, which binds against the mmsys compatible and takes care of probing the needed devices. It was tested on the bananapi-r2 and the Acer R13 Chromebook.
Matthias Brugger (8):
drm/mediatek: Use regmap for register access
mfd: mtk-mmsys: Add mmsys driver
drm/mediatek: mt2701: switch to mfd probing.
clk: mediatek: mt2701-mm: switch to mfd device
mfd: mtk-mmsys: Add mt8173 nodes
drm/mediatek: Add mfd support for mt8173
clk: mediatek: mt8173-mm: switch to mfd device
MAINTAINERS: update Mediatek Soc entry
MAINTAINERS | 2 + drivers/clk/mediatek/clk-mt2701-mm.c | 13 ++-- drivers/clk/mediatek/clk-mt8173.c | 21 ++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 +- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++---- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 +- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 35 ++++++----- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- drivers/mfd/Kconfig | 9 +++ drivers/mfd/Makefile | 2 + drivers/mfd/mtk-mmsys.c | 105 ++++++++++++++++++++++++++++++++ include/linux/mfd/mmsys.h | 18 ++++++ 12 files changed, 200 insertions(+), 45 deletions(-) create mode 100644 drivers/mfd/mtk-mmsys.c create mode 100644 include/linux/mfd/mmsys.h
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 1/8 drm/mediatek: Use regmap for register access
The mmsys memory space is shared between the drm and the clk driver. Use regmap to access it.
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++++++++++++++------------- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +2 -2
@@ -33,7 +33,7 @@* @enabled: records whether crtc_enable succeeded * @planes: array of 4 drm_plane structures, one for each overlay plane * @pending_planes: whether any plane has pending changes to be applied -* @config_regs: memory mapped mmsys configuration register space +* @config_regs: regmap mapped mmsys configuration register space * @mutex: handle to one of the ten disp_mutex streams * @ddp_comp_nr: number of components in ddp_comp * @ddp_comp: array of pointers the mtk_ddp_comp structures used by this crtc
@@ -48,7 +48,7 @@ struct mtk_drm_crtc {struct drm_plane planes[OVL_LAYER_NR ];bool pending_planes; -void __iomem *config_regs; +struct regmap *config_regs;struct mtk_disp_mutex *mutex;unsigned int ddp_comp_nr;struct mtk_ddp_comp **ddp_comp;
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +17 -13
@@ -185,16 +185,16 @@ static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,return value; } -static void mtk_ddp_sout_sel (void __iomem *config_regs, +static void mtk_ddp_sout_sel (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {if (cur ==DDP_COMPONENT_BLS && next ==DDP_COMPONENT_DSI0 ) -writel_relaxed (BLS_TO_DSI_RDMA1_TO_DPI1 , - config_regs +DISP_REG_CONFIG_OUT_SEL ); +regmap_write (config_regs,DISP_REG_CONFIG_OUT_SEL , +BLS_TO_DSI_RDMA1_TO_DPI1 ); } -void mtk_ddp_add_comp_to_path (void __iomem *config_regs, +void mtk_ddp_add_comp_to_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {
@@ -202,20 +202,22 @@ void mtk_ddp_add_comp_to_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg); }mtk_ddp_sout_sel (config_regs, cur, next); value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg); } } -void mtk_ddp_remove_comp_from_path (void __iomem *config_regs, +void mtk_ddp_remove_comp_from_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {
@@ -223,14 +225,16 @@ void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg); } value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg); } }
drivers/gpu/drm/mediatek/mtk_drm_ddp.h +2 -2
@@ -20,10 +20,10 @@ struct regmap;struct device ;struct mtk_disp_mutex ; -void mtk_ddp_add_comp_to_path (void __iomem *config_regs, +void mtk_ddp_add_comp_to_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next); -void mtk_ddp_remove_comp_from_path (void __iomem *config_regs, +void mtk_ddp_remove_comp_from_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next);
drivers/gpu/drm/mediatek/mtk_drm_drv.c +4 -9
@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> #include <linux/pm_runtime.h>
@@ -393,7 +394,6 @@ static int mtk_drm_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct resource *mem;struct device_node *node;struct component_match *match =NULL ;int ret;
@@ -407,14 +407,9 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - private->config_regs =devm_ioremap_resource (dev, mem); -if (IS_ERR (private->config_regs)) { - ret =PTR_ERR (private->config_regs); -dev_err (dev,"Failed to ioremap mmsys-config resource: %d\n" , - ret); -return ret; - } + private->config_regs =syscon_node_to_regmap (dev->of_node); +if (IS_ERR (private->config_regs)) +return PTR_ERR (private->config_regs);/* Iterate over sibling DISP function blocks */ for_each_child_of_node (dev->of_node->parent, node) {
drivers/gpu/drm/mediatek/mtk_drm_drv.h +1 -1
@@ -44,7 +44,7 @@ struct mtk_drm_private {struct device_node *mutex_node;struct device *mutex_dev; -void __iomem *config_regs; +struct regmap *config_regs;struct device_node *comp_node[DDP_COMPONENT_ID_MAX ];struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX ];const struct mtk_mmsys_driver_data *data;
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 2/8 mfd: mtk-mmsys: Add mmsys driver
In reply to Matthias BruggerThe MMSYS subsystem includes clocks and drm components. This patch adds a MFD device to probe both drivers from the same device tree compatible.
--- drivers/mfd/Kconfig | 9 +++++ drivers/mfd/Makefile | 2 ++ drivers/mfd/mtk-mmsys.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/mmsys.h | 18 ++++++++++ 4 files changed, 120 insertions(+) create mode 100644 drivers/mfd/mtk-mmsys.c create mode 100644 include/linux/mfd/mmsys.h
drivers/mfd/Kconfig +9 -0
@@ -368,6 +368,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MEDIATEK_MMSYS + tristate "Mediatek MMSYS interface" + select MDF_CORE + select REGMAP_MMIO + help + Select this if you have a MMSYS subsystem in your SoC. The + MMSYS subsystem has at least a clock driver part and some + DRM components. + config MFD_MXS_LRADC tristate "Freescale i.MX23/i.MX28 LRADC" depends on ARCH_MXS || COMPILE_TEST
drivers/mfd/Makefile +2 -0
@@ -100,6 +100,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MEDIATEK_MMSYS) += mtk-mmsys.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.o
drivers/mfd/mtk-mmsys.c new file +91 -0
91 lines not on this page · raw message
include/linux/mfd/mmsys.h new file +18 -0
@@ -0,0 +1,18 @@ +/* Header of MMSYS MFD core driver for Mediatek platforms +* +* Copyright (c) 2017 Matthias Brugger <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ + +#ifndef __MEDIATEK_MMSYS__H__ +#define __MEDIATEK_MMSYS__H__ + +struct mmsys_dev { +struct device *dev; +struct device_node *of_node; +}; + +#endif
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 3/8 drm/mediatek: mt2701: switch to mfd probing.
In reply to Matthias BruggerWith the mtk-mmsys MFD device in place, we switch the probing for mt2701 from device-tree to mfd.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +25 -7
@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/mmsys.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h>
@@ -392,9 +393,10 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {static int mtk_drm_probe (struct platform_device *pdev) { +struct mmsys_dev *mmsys_private;struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct device_node *node; +struct device_node *node, *parent_node;struct component_match *match =NULL ;int ret;int i;
@@ -407,12 +409,23 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); +/* Check if called from mfd */ +if (!dev->of_node) { + mmsys_private =dev_get_drvdata (pdev->dev.parent); + private->data = (struct mtk_mmsys_driver_data *) +platform_get_device_id (pdev)->driver_data; + private->config_regs = +syscon_node_to_regmap (mmsys_private->of_node); + parent_node = mmsys_private->of_node->parent; + }else { + private->config_regs =syscon_node_to_regmap (dev->of_node); +if (IS_ERR (private->config_regs)) +return PTR_ERR (private->config_regs); + parent_node = dev->of_node->parent; + }/* Iterate over sibling DISP function blocks */ -for_each_child_of_node (dev->of_node->parent, node) { +for_each_child_of_node (parent_node, node) {const struct of_device_id *of_id;enum mtk_ddp_comp_type comp_type;int comp_id;
@@ -553,13 +566,17 @@ static SIMPLE_DEV_PM_OPS(mtk_drm_pm_ops, mtk_drm_sys_suspend, mtk_drm_sys_resume);static const struct of_device_id mtk_drm_of_ids[] = { - { .compatible ="mediatek,mt2701-mmsys" , - .data = &mt2701_mmsys_driver_data}, { .compatible ="mediatek,mt8173-mmsys" , .data = &mt8173_mmsys_driver_data}, { } }; +static const struct platform_device_id mtk_drm_ids[] = { + {"drm-mt2701-mm" , (kernel_ulong_t)&mt2701_mmsys_driver_data }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (platform, mtk_drm_ids); +static struct platform_driver mtk_drm_platform_driver = { .probe = mtk_drm_probe, .remove = mtk_drm_remove,
@@ -568,6 +585,7 @@ static struct platform_driver mtk_drm_platform_driver = { .of_match_table = mtk_drm_of_ids, .pm = &mtk_drm_pm_ops, }, + .id_table = mtk_drm_ids, }; static struct platform_driver * const mtk_drm_drivers[] = {
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 4/8 clk: mediatek: mt2701-mm: switch to mfd device
In reply to Matthias BruggerAs the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
--- drivers/clk/mediatek/clk-mt2701-mm.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/mediatek/clk-mt2701-mm.c +6 -7
@@ -13,6 +13,7 @@*/ #include <linux/clk-provider.h> +#include <linux/mfd/mmsys.h> #include <linux/platform_device.h> #include "clk-mtk.h"
@@ -87,16 +88,15 @@ static const struct mtk_gate mm_clks[] = { GATE_DISP1(CLK_MM_TVE_FMM, "mm_tve_fmm", "mm_sel", 14), }; -static const struct of_device_id of_match_clk_mt2701_mm[] = { - { .compatible ="mediatek,mt2701-mmsys" , }, - {} -}; -static int clk_mt2701_mm_probe (struct platform_device *pdev) {struct clk_onecell_data *clk_data;int r; -struct device_node *node = pdev->dev.of_node; +struct device_node *node; +struct mmsys_dev *mmsys_private; + + mmsys_private =dev_get_drvdata (pdev->dev.parent); + node = mmsys_private->of_node; clk_data =mtk_alloc_clk_data (CLK_MM_NR );
@@ -116,7 +116,6 @@ static struct platform_driver clk_mt2701_mm_drv = { .probe = clk_mt2701_mm_probe, .driver = { .name = "clk-mt2701-mm", - .of_match_table = of_match_clk_mt2701_mm, }, };
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 5/8 mfd: mtk-mmsys: Add mt8173 nodes
In reply to Matthias BruggerAdd devices for the mt8173 SoC.
--- drivers/mfd/mtk-mmsys.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/mfd/mtk-mmsys.c +14 -0
@@ -21,6 +21,7 @@enum {MMSYS_MT2701 =1 , +MMSYS_MT8173 , };static const struct mfd_cell mmsys_mt2701_devs[] = {
@@ -28,6 +29,12 @@ static const struct mfd_cell mmsys_mt2701_devs[] = { { .name = "drm-mt2701-mm", }, }; +static const struct mfd_cell mmsys_mt8173_devs[] = { + { .name ="clk-mt8173-mm" , }, + { .name ="drm-mt8173-mm" , }, +}; + +static int mmsys_probe (struct platform_device *pdev) {struct mmsys_dev *private;
@@ -47,6 +54,10 @@ static int mmsys_probe(struct platform_device *pdev) mmsys_cells = mmsys_mt2701_devs; nr_cells =ARRAY_SIZE (mmsys_mt2701_devs);break ; +case MMSYS_MT8173 : + mmsys_cells = mmsys_mt8173_devs; + nr_cells =ARRAY_SIZE (mmsys_mt8173_devs); +break ;default :return -ENODEV ; }
@@ -74,6 +85,9 @@ static const struct of_device_id of_match_mmsys[] = { { .compatible = "mediatek,mt2701-mmsys", .data = (void *) MMSYS_MT2701, }, + { .compatible = "mediatek,mt8173-mmsys", + .data = (void *) MMSYS_MT8173, + }, { /* sentinel */ }, };
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 6/8 drm/mediatek: Add mfd support for mt8173
In reply to Matthias BruggerUse the MFD device for SoC mt8173. Probing via devicetree is no longer needed for any SoC, so delete it.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +7 -21
@@ -409,20 +409,12 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); -/* Check if called from mfd */ -if (!dev->of_node) { - mmsys_private =dev_get_drvdata (pdev->dev.parent); - private->data = (struct mtk_mmsys_driver_data *) -platform_get_device_id (pdev)->driver_data; - private->config_regs = -syscon_node_to_regmap (mmsys_private->of_node); - parent_node = mmsys_private->of_node->parent; - }else { - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); - parent_node = dev->of_node->parent; - } + mmsys_private =dev_get_drvdata (pdev->dev.parent); + private->data = (struct mtk_mmsys_driver_data *) +platform_get_device_id (pdev)->driver_data; + private->config_regs = +syscon_node_to_regmap (mmsys_private->of_node); + parent_node = mmsys_private->of_node->parent;/* Iterate over sibling DISP function blocks */ for_each_child_of_node (parent_node, node) {
@@ -565,14 +557,9 @@ static int mtk_drm_sys_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(mtk_drm_pm_ops, mtk_drm_sys_suspend, mtk_drm_sys_resume); -static const struct of_device_id mtk_drm_of_ids[] = { - { .compatible ="mediatek,mt8173-mmsys" , - .data = &mt8173_mmsys_driver_data}, - { } -}; -static const struct platform_device_id mtk_drm_ids[] = { {"drm-mt2701-mm" , (kernel_ulong_t)&mt2701_mmsys_driver_data }, + {"drm-mt8173-mm" , (kernel_ulong_t)&mt8173_mmsys_driver_data }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (platform, mtk_drm_ids);
@@ -582,7 +569,6 @@ static struct platform_driver mtk_drm_platform_driver = { .remove = mtk_drm_remove, .driver = { .name = "mediatek-drm", - .of_match_table = mtk_drm_of_ids, .pm = &mtk_drm_pm_ops, }, .id_table = mtk_drm_ids,
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 7/8 clk: mediatek: mt8173-mm: switch to mfd device
In reply to Matthias BruggerAs the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
--- drivers/clk/mediatek/clk-mt8173.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/clk/mediatek/clk-mt8173.c +19 -2
@@ -13,8 +13,10 @@*/ #include <linux/clk.h> +#include <linux/mfd/mmsys.h> #include <linux/of.h> #include <linux/of_address.h> +#include <linux/platform_device.h> #include "clk-mtk.h" #include "clk-gate.h"
@@ -1152,10 +1154,16 @@ static void __init mtk_imgsys_init(struct device_node *node) }CLK_OF_DECLARE (mtk_imgsys,"mediatek,mt8173-imgsys" , mtk_imgsys_init); -static void __init mtk_mmsys_init (struct device_node *node) +static int mtk_mmsys_probe (struct platform_device *pdev) {struct clk_onecell_data *clk_data;int r; +struct device_node *node; +struct mmsys_dev *mmsys_private; + + mmsys_private =dev_get_drvdata (pdev->dev.parent); + node = mmsys_private->of_node; + clk_data =mtk_alloc_clk_data (CLK_MM_NR_CLK );
@@ -1166,8 +1174,17 @@ static void __init mtk_mmsys_init(struct device_node *node)if (r)pr_err ("%s(): could not register clock provider: %d\n" , __func__, r); + +return r; } -CLK_OF_DECLARE (mtk_mmsys,"mediatek,mt8173-mmsys" , mtk_mmsys_init); + +static struct platform_driver clk_mt8173_mm_drv = { + .probe = mtk_mmsys_probe, + .driver = { + .name ="clk-mt8173-mm" , + }, +}; +builtin_platform_driver (clk_mt8173_mm_drv);static void __init mtk_vdecsys_init (struct device_node *node) {
Signature · 1 line
2.14.2
Matthias Brugger
maintainerPATCH 8/8 MAINTAINERS: update Mediatek Soc entry
In reply to Matthias BruggerMediatek SoCs include several soc specific drivers as well as a mfd device. Add these to the maintainers file.
--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -1606,6 +1606,8 @@ F: arch/arm/boot/dts/mt7* F: arch/arm/boot/dts/mt8* F: arch/arm/mach-mediatek/ F: arch/arm64/boot/dts/mediatek/ +F: drivers/soc/mediatek/ +F: drivers/mfd/mtk-mmsys.c N: mtk K: mediatek
Signature · 1 line
2.14.2
Re: [PATCH 7/8] clk: mediatek: mt8173-mm: switch to mfd device
In reply to Matthias BruggerQuoted 5 lines · Matthias Brugger
As the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
Signed-off-by Matthias Brugger <[email protected]>---
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 4/8] clk: mediatek: mt2701-mm: switch to mfd device
In reply to Matthias BruggerQuoted 5 lines · Matthias Brugger
As the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
Signed-off-by Matthias Brugger <[email protected]>---
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH 1/8] drm/mediatek: Use regmap for register access
In reply to Matthias BruggerHi, Matthias:
Quoted 4 lines · Matthias Brugger
The mmsys memory space is shared between the drm and the clk driver. Use regmap to access it.
Signed-off-by Matthias Brugger <[email protected]>
Quoted 172 lines
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++++++++++++++------------- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +2
-2@@ -33,7 +33,7 @@* @enabled: records whether crtc_enable succeeded * @planes: array of 4 drm_plane structures, one for each overlay plane * @pending_planes: whether any plane has pending changes to be applied -* @config_regs: memory mapped mmsys configuration register space +* @config_regs: regmap mapped mmsys configuration register space * @mutex: handle to one of the ten disp_mutex streams * @ddp_comp_nr: number of components in ddp_comp * @ddp_comp: array of pointers the mtk_ddp_comp structures used by this crtc @@ -48,7 +48,7 @@ struct mtk_drm_crtc {struct drm_plane planes[OVL_LAYER_NR ];bool pending_planes; -void __iomem *config_regs; +struct regmap *config_regs;struct mtk_disp_mutex *mutex;unsigned int ddp_comp_nr;struct mtk_ddp_comp **ddp_comp;drivers/gpu/drm/mediatek/mtk_drm_ddp.c +17
-13@@ -185,16 +185,16 @@ static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,return value; } -static void mtk_ddp_sout_sel (void __iomem *config_regs, +static void mtk_ddp_sout_sel (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {if (cur ==DDP_COMPONENT_BLS && next ==DDP_COMPONENT_DSI0 ) -writel_relaxed (BLS_TO_DSI_RDMA1_TO_DPI1 , - config_regs +DISP_REG_CONFIG_OUT_SEL ); +regmap_write (config_regs,DISP_REG_CONFIG_OUT_SEL , +BLS_TO_DSI_RDMA1_TO_DPI1 ); } -void mtk_ddp_add_comp_to_path (void __iomem *config_regs, +void mtk_ddp_add_comp_to_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {@@ -202,20 +202,22 @@ void mtk_ddp_add_comp_to_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg); }mtk_ddp_sout_sel (config_regs, cur, next); value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg); } } -void mtk_ddp_remove_comp_from_path (void __iomem *config_regs, +void mtk_ddp_remove_comp_from_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {@@ -223,14 +225,16 @@ void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg); } value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg); } }drivers/gpu/drm/mediatek/mtk_drm_ddp.h +2
-2@@ -20,10 +20,10 @@ struct regmap;struct device ;struct mtk_disp_mutex ; -void mtk_ddp_add_comp_to_path (void __iomem *config_regs, +void mtk_ddp_add_comp_to_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next); -void mtk_ddp_remove_comp_from_path (void __iomem *config_regs, +void mtk_ddp_remove_comp_from_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next);drivers/gpu/drm/mediatek/mtk_drm_drv.c +4
-9@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> #include <linux/pm_runtime.h> @@ -393,7 +394,6 @@ static int mtk_drm_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct resource *mem;struct device_node *node;struct component_match *match =NULL ;int ret;@@ -407,14 +407,9 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - private->config_regs =devm_ioremap_resource (dev, mem); -if (IS_ERR (private->config_regs)) { - ret =PTR_ERR (private->config_regs); -dev_err (dev,"Failed to ioremap mmsys-config resource: %d\n" , - ret); -return ret; - } + private->config_regs =syscon_node_to_regmap (dev->of_node); +if (IS_ERR (private->config_regs)) +return PTR_ERR (private->config_regs);/* Iterate over sibling DISP function blocks */ for_each_child_of_node (dev->of_node->parent, node) {drivers/gpu/drm/mediatek/mtk_drm_drv.h +1
-1@@ -44,7 +44,7 @@ struct mtk_drm_private {struct device_node *mutex_node;struct device *mutex_dev; -void __iomem *config_regs; +struct regmap *config_regs;struct device_node *comp_node[DDP_COMPONENT_ID_MAX ];struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX ];const struct mtk_mmsys_driver_data *data;
Re: [PATCH 3/8] drm/mediatek: mt2701: switch to mfd probing.
In reply to Matthias BruggerHi, Matthias:
Quoted 33 lines · Matthias Brugger
With the mtk-mmsys MFD device in place, we switch the probing for mt2701 from device-tree to mfd.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-1@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/mmsys.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -392,9 +393,10 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {static int mtk_drm_probe (struct platform_device *pdev) { +struct mmsys_dev *mmsys_private;struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct device_node *node; +struct device_node *node, *parent_node;struct component_match *match =NULL ;int ret;int i;
drivers/gpu/drm/mediatek/mtk_drm_drv.c static int mtk_drm_probe(struct platform_device *pdev) · line 414
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-3@@ -407,12 +409,23 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); +/* Check if called from mfd */ +if (!dev->of_node) { + mmsys_private =dev_get_drvdata (pdev->dev.parent);
Why do you directly access parent's driver data? You just need the device node of mmsys, maybe you could refer to [1].
[1]
https://elixir.free-electrons.com/linux/latest/source/drivers/reset/reset-berlin.c#L78
Regards,
CK
Quoted 46 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +19
-3+ private->data = (struct mtk_mmsys_driver_data *) +platform_get_device_id (pdev)->driver_data; + private->config_regs = +syscon_node_to_regmap (mmsys_private->of_node); + parent_node = mmsys_private->of_node->parent; + }else { + private->config_regs =syscon_node_to_regmap (dev->of_node); +if (IS_ERR (private->config_regs)) +return PTR_ERR (private->config_regs); + parent_node = dev->of_node->parent; + }/* Iterate over sibling DISP function blocks */ -for_each_child_of_node (dev->of_node->parent, node) { +for_each_child_of_node (parent_node, node) {const struct of_device_id *of_id;enum mtk_ddp_comp_type comp_type;int comp_id;@@ -553,13 +566,17 @@ static SIMPLE_DEV_PM_OPS(mtk_drm_pm_ops, mtk_drm_sys_suspend, mtk_drm_sys_resume);static const struct of_device_id mtk_drm_of_ids[] = { - { .compatible ="mediatek,mt2701-mmsys" , - .data = &mt2701_mmsys_driver_data}, { .compatible ="mediatek,mt8173-mmsys" , .data = &mt8173_mmsys_driver_data}, { } }; +static const struct platform_device_id mtk_drm_ids[] = { + {"drm-mt2701-mm" , (kernel_ulong_t)&mt2701_mmsys_driver_data }, + {/* sentinel */ }, +}; +MODULE_DEVICE_TABLE (platform, mtk_drm_ids); +static struct platform_driver mtk_drm_platform_driver = { .probe = mtk_drm_probe, .remove = mtk_drm_remove,@@ -568,6 +585,7 @@ static struct platform_driver mtk_drm_platform_driver = { .of_match_table = mtk_drm_of_ids, .pm = &mtk_drm_pm_ops, }, + .id_table = mtk_drm_ids, }; static struct platform_driver * const mtk_drm_drivers[] = {
Re: [PATCH 3/8] drm/mediatek: mt2701: switch to mfd probing.
Quoted 49 lines · CK Hu
Hi, Matthias:
Quoted 33 lines · Matthias Brugger
With the mtk-mmsys MFD device in place, we switch the probing for mt2701 from device-tree to mfd.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-1@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/mmsys.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -392,9 +393,10 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {static int mtk_drm_probe (struct platform_device *pdev) { +struct mmsys_dev *mmsys_private;struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct device_node *node; +struct device_node *node, *parent_node;struct component_match *match =NULL ;int ret;int i;drivers/gpu/drm/mediatek/mtk_drm_drv.c static int mtk_drm_probe(struct platform_device *pdev) · line 414
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-3@@ -407,12 +409,23 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); +/* Check if called from mfd */ +if (!dev->of_node) { + mmsys_private =dev_get_drvdata (pdev->dev.parent);Why do you directly access parent's driver data? You just need the device node of mmsys, maybe you could refer to [1].
Quoted 3 lines
[1]
https://elixir.free-electrons.com/linux/latest/source/drivers/reset/reset-berlin.c#L78
The difference is, that the driver you mentioned gets probed via device tree matching, while we get invoked here through the id_table. So there is no device node (the if actually checkes for pdev->dev.of_node to identify exactly this case).
Regards,
Matthias
CK Hu
Acked-byRe: [PATCH 3/8] drm/mediatek: mt2701: switch to mfd probing.
Hi, Matthias:
Quoted 55 lines · Matthias Brugger
Quoted 49 lines · CK Hu
Hi, Matthias:
Quoted 33 lines · Matthias Brugger
With the mtk-mmsys MFD device in place, we switch the probing for mt2701 from device-tree to mfd.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-1@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/mmsys.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -392,9 +393,10 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {static int mtk_drm_probe (struct platform_device *pdev) { +struct mmsys_dev *mmsys_private;struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct device_node *node; +struct device_node *node, *parent_node;struct component_match *match =NULL ;int ret;int i;drivers/gpu/drm/mediatek/mtk_drm_drv.c static int mtk_drm_probe(struct platform_device *pdev) · line 414
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-3@@ -407,12 +409,23 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); +/* Check if called from mfd */ +if (!dev->of_node) { + mmsys_private =dev_get_drvdata (pdev->dev.parent);Why do you directly access parent's driver data? You just need the device node of mmsys, maybe you could refer to [1].
Quoted 6 lines
The difference is, that the driver you mentioned gets probed via device tree matching, while we get invoked here through the
id_table. So there is no device node (the if actually checkes forpdev->dev.of_nodeto identify exactly this case).Regards,
Matthias
Yes, you are right. So
Regards,
CK
Quoted 5 lines
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Re: [PATCH 6/8] drm/mediatek: Add mfd support for mt8173
In reply to Matthias BruggerHi, Matthias:
Quoted 4 lines · Matthias Brugger
Use the MFD device for SoC mt8173. Probing via devicetree is no longer needed for any SoC, so delete it.
Signed-off-by Matthias Brugger <[email protected]>
Quoted 59 lines
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +7
-21@@ -409,20 +409,12 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); -/* Check if called from mfd */ -if (!dev->of_node) { - mmsys_private =dev_get_drvdata (pdev->dev.parent); - private->data = (struct mtk_mmsys_driver_data *) -platform_get_device_id (pdev)->driver_data; - private->config_regs = -syscon_node_to_regmap (mmsys_private->of_node); - parent_node = mmsys_private->of_node->parent; - }else { - private->config_regs =syscon_node_to_regmap (dev->of_node); -if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); - parent_node = dev->of_node->parent; - } + mmsys_private =dev_get_drvdata (pdev->dev.parent); + private->data = (struct mtk_mmsys_driver_data *) +platform_get_device_id (pdev)->driver_data; + private->config_regs = +syscon_node_to_regmap (mmsys_private->of_node); + parent_node = mmsys_private->of_node->parent;/* Iterate over sibling DISP function blocks */ for_each_child_of_node (parent_node, node) {@@ -565,14 +557,9 @@ static int mtk_drm_sys_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(mtk_drm_pm_ops, mtk_drm_sys_suspend, mtk_drm_sys_resume); -static const struct of_device_id mtk_drm_of_ids[] = { - { .compatible ="mediatek,mt8173-mmsys" , - .data = &mt8173_mmsys_driver_data}, - { } -}; -static const struct platform_device_id mtk_drm_ids[] = { {"drm-mt2701-mm" , (kernel_ulong_t)&mt2701_mmsys_driver_data }, + {"drm-mt8173-mm" , (kernel_ulong_t)&mt8173_mmsys_driver_data }, {/* sentinel */ }, };MODULE_DEVICE_TABLE (platform, mtk_drm_ids);@@ -582,7 +569,6 @@ static struct platform_driver mtk_drm_platform_driver = { .remove = mtk_drm_remove, .driver = { .name = "mediatek-drm", - .of_match_table = mtk_drm_of_ids, .pm = &mtk_drm_pm_ops, }, .id_table = mtk_drm_ids,
Re: [PATCH 1/8] drm/mediatek: Use regmap for register access
In reply to Matthias BruggerHi Matthias,
Quoted 11 lines · Matthias Brugger
The mmsys memory space is shared between the drm and the clk driver. Use regmap to access it.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++++++++++++++------------- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-)
[...]
Quoted 26 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +4
-4@@ -185,16 +185,16 @@ static unsigned int mtk_ddp_sel_in(enum mtk_ddp_comp_id cur,return value; } -static void mtk_ddp_sout_sel (void __iomem *config_regs, +static void mtk_ddp_sout_sel (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {if (cur ==DDP_COMPONENT_BLS && next ==DDP_COMPONENT_DSI0 ) -writel_relaxed (BLS_TO_DSI_RDMA1_TO_DPI1 , - config_regs +DISP_REG_CONFIG_OUT_SEL ); +regmap_write (config_regs,DISP_REG_CONFIG_OUT_SEL , +BLS_TO_DSI_RDMA1_TO_DPI1 ); } -void mtk_ddp_add_comp_to_path (void __iomem *config_regs, +void mtk_ddp_add_comp_to_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_add_comp_to_path(void __iomem *config_regs, · line 207
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2@@ -202,20 +202,22 @@ void mtk_ddp_add_comp_to_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg);
You can use
regmap_update_bits(config_regs, addr, value, value);
here and drop the local variable reg.
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_add_comp_to_path(void __iomem *config_regs, · line 216
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2}mtk_ddp_sout_sel (config_regs, cur, next); value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) | value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg |= value; +regmap_write (config_regs, addr, reg);
regmap_update_bits(config_regs, addr, value, value);
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +1
-1} } -void mtk_ddp_remove_comp_from_path (void __iomem *config_regs, +void mtk_ddp_remove_comp_from_path (struct regmap *config_regs,enum mtk_ddp_comp_id cur,enum mtk_ddp_comp_id next) {
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, · line 230
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2@@ -223,14 +225,16 @@ void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, value =mtk_ddp_mout_en (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg);
regmap_update_bits(config_regs, addr, value, 0);
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, · line 237
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2} value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg);
regmap_update_bits(config_regs, addr, value, 0);
regards
Philipp
Re: [PATCH 2/8] mfd: mtk-mmsys: Add mmsys driver
In reply to Matthias BruggerHi, Matthias:
Quoted 117 lines · Matthias Brugger
The MMSYS subsystem includes clocks and drm components. This patch adds a MFD device to probe both drivers from the same device tree compatible.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/mfd/Kconfig | 9 +++++ drivers/mfd/Makefile | 2 ++ drivers/mfd/mtk-mmsys.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/mmsys.h | 18 ++++++++++ 4 files changed, 120 insertions(+) create mode 100644 drivers/mfd/mtk-mmsys.c create mode 100644 include/linux/mfd/mmsys.hdrivers/mfd/Kconfig +9
-0@@ -368,6 +368,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MEDIATEK_MMSYS + tristate "Mediatek MMSYS interface" + select MDF_CORE + select REGMAP_MMIO + help + Select this if you have a MMSYS subsystem in your SoC. The + MMSYS subsystem has at least a clock driver part and some + DRM components. + config MFD_MXS_LRADC tristate "Freescale i.MX23/i.MX28 LRADC" depends on ARCH_MXS || COMPILE_TESTdrivers/mfd/Makefile +2
-0@@ -100,6 +100,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MEDIATEK_MMSYS) += mtk-mmsys.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.odrivers/mfd/mtk-mmsys.c new file +64
-0@@ -0,0 +1,91 @@ +/* +* mtk-mmsys.c -- Mediatek MMSYS multi-function driver +* +* Copyright (c) 2017 Matthias Brugger <[email protected]> +* +* Author: Matthias Brugger <[email protected]> +* +* For licencing details see kernel-base/COPYING +* +*/ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/mfd/core.h> +#include <linux/mfd/mmsys.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +enum { +MMSYS_MT2701 =1 , +}; + +static const struct mfd_cell mmsys_mt2701_devs[] = { + { .name ="clk-mt2701-mm" , }, + { .name ="drm-mt2701-mm" , }, +}; + +static int mmsys_probe (struct platform_device *pdev) +{ +struct mmsys_dev *private; +const struct mfd_cell *mmsys_cells; +int nr_cells; +long id; +int ret; + + id = (long )of_device_get_match_data (&pdev->dev); +if (!id) { +dev_err (&pdev->dev,"of_device_get match_data() failed\n" ); +return -EINVAL ; + } + +switch (id) { +case MMSYS_MT2701 : + mmsys_cells = mmsys_mt2701_devs; + nr_cells =ARRAY_SIZE (mmsys_mt2701_devs); +break ; +default : +return -ENODEV ; + } + + private =devm_kzalloc (&pdev->dev,sizeof (*private),GFP_KERNEL ); +if (!private) +return -ENOMEM ; + + private->dev = &pdev->dev; +dev_set_drvdata (private->dev, private); + + private->of_node = pdev->dev.of_node; + + ret =devm_mfd_add_devices (private->dev,0 , mmsys_cells, nr_cells, +NULL ,0 ,NULL );
drivers/mfd/mtk-mmsys.c line 74
Quoted 10 lines
drivers/mfd/mtk-mmsys.c new file +10
-0+if (ret) { +dev_err (&pdev->dev,"failed to add MFD devices %d\n" , ret); +return ret; + } + +return 0 ; +}; + +static const struct of_device_id of_match_mmsys[] = { + { .compatible ="mediatek,mt2701-mmsys" ,
Because this driver replace the original "mediatek,mt2701-mmsys" driver, could you modify the binding document of "mediatek,mt2701-mmsys" [1]?
[1]
https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
Regards,
CK
Quoted 41 lines
drivers/mfd/mtk-mmsys.c new file +17
-0+ .data = (void *) MMSYS_MT2701, + }, + { /* sentinel */ }, +}; + +static struct platform_driver mmsys_drv = { + .probe = mmsys_probe, + .driver = { + .name ="mediatek-mmysys" , + .of_match_table =of_match_ptr (of_match_mmsys), + }, +}; + +builtin_platform_driver (mmsys_drv); + +MODULE_DESCRIPTION ("Mediatek MMSYS multi-function driver" ); +MODULE_LICENSE ("GPL" );include/linux/mfd/mmsys.h new file +18
-0@@ -0,0 +1,18 @@ +/* Header of MMSYS MFD core driver for Mediatek platforms +* +* Copyright (c) 2017 Matthias Brugger <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ + +#ifndef __MEDIATEK_MMSYS__H__ +#define __MEDIATEK_MMSYS__H__ + +struct mmsys_dev { +struct device *dev; +struct device_node *of_node; +}; + +#endif
Philipp Zabel
maintainerRe: [PATCH 2/8] mfd: mtk-mmsys: Add mmsys driver
In reply to Matthias BruggerHi Matthias,
Quoted 104 lines · Matthias Brugger
The MMSYS subsystem includes clocks and drm components. This patch adds a MFD device to probe both drivers from the same device tree compatible.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/mfd/Kconfig | 9 +++++ drivers/mfd/Makefile | 2 ++ drivers/mfd/mtk-mmsys.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/mmsys.h | 18 ++++++++++ 4 files changed, 120 insertions(+) create mode 100644 drivers/mfd/mtk-mmsys.c create mode 100644 include/linux/mfd/mmsys.hdrivers/mfd/Kconfig +9
-0@@ -368,6 +368,15 @@ config MFD_MC13XXX_I2C help Select this if your MC13xxx is connected via an I2C bus. +config MFD_MEDIATEK_MMSYS + tristate "Mediatek MMSYS interface" + select MDF_CORE + select REGMAP_MMIO + help + Select this if you have a MMSYS subsystem in your SoC. The + MMSYS subsystem has at least a clock driver part and some + DRM components. + config MFD_MXS_LRADC tristate "Freescale i.MX23/i.MX28 LRADC" depends on ARCH_MXS || COMPILE_TESTdrivers/mfd/Makefile +2
-0@@ -100,6 +100,8 @@ obj-$(CONFIG_MFD_MC13XXX) += mc13xxx-core.o obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o +obj-$(CONFIG_MFD_MEDIATEK_MMSYS) += mtk-mmsys.o + obj-$(CONFIG_MFD_CORE) += mfd-core.o obj-$(CONFIG_EZX_PCAP) += ezx-pcap.odrivers/mfd/mtk-mmsys.c new file +51
-0@@ -0,0 +1,91 @@ +/* +* mtk-mmsys.c -- Mediatek MMSYS multi-function driver +* +* Copyright (c) 2017 Matthias Brugger <[email protected]> +* +* Author: Matthias Brugger <[email protected]> +* +* For licencing details see kernel-base/COPYING +* +*/ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/mfd/core.h> +#include <linux/mfd/mmsys.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +enum { +MMSYS_MT2701 =1 , +}; + +static const struct mfd_cell mmsys_mt2701_devs[] = { + { .name ="clk-mt2701-mm" , }, + { .name ="drm-mt2701-mm" , }, +}; + +static int mmsys_probe (struct platform_device *pdev) +{ +struct mmsys_dev *private; +const struct mfd_cell *mmsys_cells; +int nr_cells; +long id; +int ret; + + id = (long )of_device_get_match_data (&pdev->dev); +if (!id) { +dev_err (&pdev->dev,"of_device_get match_data() failed\n" ); +return -EINVAL ; + } + +switch (id) { +case MMSYS_MT2701 : + mmsys_cells = mmsys_mt2701_devs; + nr_cells =ARRAY_SIZE (mmsys_mt2701_devs); +break ; +default : +return -ENODEV ;
drivers/mfd/mtk-mmsys.c line 61
Quoted 10 lines
drivers/mfd/mtk-mmsys.c new file +10
-0+ } + + private =devm_kzalloc (&pdev->dev,sizeof (*private),GFP_KERNEL ); +if (!private) +return -ENOMEM ; + + private->dev = &pdev->dev; +dev_set_drvdata (private->dev, private); + + private->of_node = pdev->dev.of_node;
This seems superfluous to me. The of_node can be obtained from the device, and the device itself is already needed to get to the drvdata.
Instead of
mmsys_private = drv_get_drvdata(pdev->dev.parent); mmsys_dev = mmsys_private.dev; mmsys_of_node = mmsys_private.of_node;
couldn't the mfd children just do
mmsys_dev = pdev->dev.parent; mmsys_of_node = pdev->dev.parent->of_node;
?
Quoted 42 lines
drivers/mfd/mtk-mmsys.c new file +30
-0+ + ret =devm_mfd_add_devices (private->dev,0 , mmsys_cells, nr_cells, +NULL ,0 ,NULL ); +if (ret) { +dev_err (&pdev->dev,"failed to add MFD devices %d\n" , ret); +return ret; + } + +return 0 ; +}; + +static const struct of_device_id of_match_mmsys[] = { + { .compatible ="mediatek,mt2701-mmsys" , + .data = (void *)MMSYS_MT2701 , + }, + {/* sentinel */ }, +}; + +static struct platform_driver mmsys_drv = { + .probe = mmsys_probe, + .driver = { + .name ="mediatek-mmysys" , + .of_match_table =of_match_ptr (of_match_mmsys), + }, +}; + +builtin_platform_driver (mmsys_drv); + +MODULE_DESCRIPTION ("Mediatek MMSYS multi-function driver" ); +MODULE_LICENSE ("GPL" );include/linux/mfd/mmsys.h new file +6
-0@@ -0,0 +1,18 @@ +/* Header of MMSYS MFD core driver for Mediatek platforms +* +* Copyright (c) 2017 Matthias Brugger <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the
include/linux/mfd/mmsys.h line 16
Quoted 10 lines
include/linux/mfd/mmsys.h new file +10
-0+* Free Software Foundation. +*/ + +#ifndef __MEDIATEK_MMSYS__H__ +#define __MEDIATEK_MMSYS__H__ + +struct mmsys_dev { +struct device *dev; +struct device_node *of_node; +};
This wouldn't be needed, then.
regards
Philipp
Philipp Zabel
maintainerRe: [PATCH 3/8] drm/mediatek: mt2701: switch to mfd probing.
In reply to Matthias BruggerQuoted 37 lines · Matthias Brugger
With the mtk-mmsys MFD device in place, we switch the probing for mt2701 from device-tree to mfd.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-2@@ -21,6 +21,7 @@#include <drm/drm_of.h> #include <linux/component.h> #include <linux/iommu.h> +#include <linux/mfd/mmsys.h> #include <linux/mfd/syscon.h> #include <linux/of_address.h> #include <linux/of_platform.h> @@ -392,9 +393,10 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = {static int mtk_drm_probe (struct platform_device *pdev) { +struct mmsys_dev *mmsys_private;struct device *dev = &pdev->dev;struct mtk_drm_private *private; -struct device_node *node; +struct device_node *node, *parent_node;struct component_match *match =NULL ;int ret;int i;@@ -407,12 +409,23 @@ static int mtk_drm_probe(struct platform_device *pdev)INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); - private->config_regs =syscon_node_to_regmap (dev->of_node);
drivers/gpu/drm/mediatek/mtk_drm_drv.c static int mtk_drm_probe(struct platform_device *pdev) · line 419
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +8
-2-if (IS_ERR (private->config_regs)) -return PTR_ERR (private->config_regs); +/* Check if called from mfd */ +if (!dev->of_node) { + mmsys_private =dev_get_drvdata (pdev->dev.parent); + private->data = (struct mtk_mmsys_driver_data *) +platform_get_device_id (pdev)->driver_data; + private->config_regs = +syscon_node_to_regmap (mmsys_private->of_node); + parent_node = mmsys_private->of_node->parent;
I think this could be just:
mmsys_node = pdev->dev.parent->of_node; private->data = (struct mtk_mmsys_driver_data *)> + platform_get_device_id(pdev)->driver_data; private->config_regs = syscon_node_to_regmap(mmsys_node); parent_node = mmsys_node->parent;
regards
Philipp
Re: [PATCH 5/8] mfd: mtk-mmsys: Add mt8173 nodes
In reply to Matthias BruggerQuoted 3 lines · Matthias Brugger
Add devices for the mt8173 SoC.
Signed-off-by Matthias Brugger <[email protected]>
regards
Philipp
Re: [PATCH 6/8] drm/mediatek: Add mfd support for mt8173
In reply to Matthias BruggerQuoted 4 lines · Matthias Brugger
Use the MFD device for SoC mt8173. Probing via devicetree is no longer needed for any SoC, so delete it.
Signed-off-by Matthias Brugger <[email protected]>
Apart from the mmsys_private issue noted in previous patches,
regards
Philipp
Matthias Brugger
maintainerRe: [PATCH 2/8] mfd: mtk-mmsys: Add mmsys driver
In reply to CK HuQuoted 9 lines · CK Hu
drivers/mfd/mtk-mmsys.c line 74
Quoted 2 lines
drivers/mfd/mtk-mmsys.c new file +2
-0+static const struct of_device_id of_match_mmsys[] = { + { .compatible ="mediatek,mt2701-mmsys" ,Because this driver replace the original "mediatek,mt2701-mmsys" driver, could you modify the binding document of "mediatek,mt2701-mmsys" [1]?
[1]
https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
Well we are actually no replacing the compatible but keeping it. But yes, the documentation should be updated.
Apart right now we have the definition twice. The other location is here:Documentation/devicetree/bindings/display/mediatek/mediatek,disp.txt
Regards,
Matthias
Matthias Brugger
maintainerRe: [PATCH 1/8] drm/mediatek: Use regmap for register access
In reply to Philipp ZabelHi Philipp,
Quoted 15 lines · Philipp Zabel
Hi Matthias,
Quoted 11 lines · Matthias Brugger
The mmsys memory space is shared between the drm and the clk driver. Use regmap to access it.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++++++++++++++------------- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-)[...]
[...]
Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, · line 237
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2} value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg);regmap_update_bits(config_regs, addr, value, 0);
Quoted 2 lines
Reviewed-by Philipp Zabel <[email protected]>
Thanks for having a look on that.
I'll update the next version with regmap_update_bits and leave your Reviewed-by, hope that's ok.
Regards,
Matthias
Philipp Zabel
maintainerRe: [PATCH 1/8] drm/mediatek: Use regmap for register access
Hi Matthias,
Quoted 33 lines · Matthias Brugger
Hi Philipp,
Quoted 16 lines · Philipp Zabel
Hi Matthias,
Quoted 11 lines · Matthias Brugger
The mmsys memory space is shared between the drm and the clk driver. Use regmap to access it.
Signed-off-by Matthias Brugger <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_ddp.c | 30 +++++++++++++++++------------- drivers/gpu/drm/mediatek/mtk_drm_ddp.h | 4 ++-- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 2 +- 5 files changed, 26 insertions(+), 27 deletions(-)[...]
[...]
Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c void mtk_ddp_remove_comp_from_path(void __iomem *config_regs, · line 237
Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp.c +3
-2} value =mtk_ddp_sel_in (cur, next, &addr);if (value) { - reg =readl_relaxed (config_regs + addr) & ~value; -writel_relaxed (reg, config_regs + addr); +regmap_read (config_regs, addr, ®); + reg &= ~value; +regmap_write (config_regs, addr, reg);regmap_update_bits(config_regs, addr, value, 0);
Quoted 7 lines
Quoted 2 lines
Reviewed-by Philipp Zabel <[email protected]>Thanks for having a look on that.
I'll update the next version with
regmap_update_bitsand leave your Reviewed-by, hope that's ok.
Yes, that's fine.
regards
Philipp
Matthias Brugger
maintainerRe: [PATCH 4/8] clk: mediatek: mt2701-mm: switch to mfd device
In reply to Stephen BoydHi Stephen,
Quoted 9 lines · Stephen Boyd
Quoted 5 lines · Matthias Brugger
As the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
Signed-off-by Matthias Brugger <[email protected]>---
Acked-by Stephen Boyd <[email protected]>
I did a minor change to this patch and patch 7/8 to get rid of mmsys_private variable. Nevertheless I kept your Acked-by, as it only changes how we get the device tree node.
Hope that's OK with you.
Regards,
Matthias
Matthias Brugger
maintainerRe: [PATCH 4/8] clk: mediatek: mt2701-mm: switch to mfd device
Quoted 10 lines · Matthias Brugger
Hi Stephen,
Quoted 7 lines · Stephen Boyd
Quoted 5 lines · Matthias Brugger
As the new mfd device is in place, switch probing for the MMSYS to support invocation from the mfd device.
Signed-off-by Matthias Brugger <[email protected]>---
Quoted 9 lines
Quoted 2 lines
Acked-by Stephen Boyd <[email protected]>I did a minor change to this patch and patch 7/8 to get rid of
mmsys_privatevariable. Nevertheless I kept your Acked-by, as it only changes how we get the device tree node.Hope that's OK with you.
Sorry, I didn't explain me. I'm talking about v2 of the series, which I'm working on right now.
Regards,
Matthias