From: "james qian wang (Arm Technology China)" Subject: [PATCH 1/2] drm/komeda: Update the chip identify Date: Tue, 9 Jul 2019 07:57:08 +0000 Message-ID: <20190709075640.22012-2-james.qian.wang@arm.com> References: <20190709075640.22012-1-james.qian.wang@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20190709075640.22012-1-james.qian.wang@arm.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" Cc: "Jonathan Chai (Arm Technology China)" , "Julien Yin (Arm Technology China)" , "thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , Ayan Halder , "Tiannan Zhu (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , nd , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , Ben Davis , "Oscar Zhang (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "james qian wang (Arm Technology China)" List-Id: dri-devel@lists.freedesktop.org 1. Drop komeda-CORE product id comparison and put it into the d71_identify 2. Update pipeline node DT-binding: *. Skip the needless pipeline DT node. *. Return fail if the essential pipeline DT node was missing. With these changes, for one family chips no need to change the DT. Signed-off-by: James Qian Wang (Arm Technology China) --- .../gpu/drm/arm/display/komeda/d71/d71_dev.c | 27 ++++++-- .../gpu/drm/arm/display/komeda/komeda_dev.c | 62 ++++++++++--------- .../gpu/drm/arm/display/komeda/komeda_dev.h | 14 +---- .../gpu/drm/arm/display/komeda/komeda_drv.c | 9 +-- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c b/drivers/gpu= /drm/arm/display/komeda/d71/d71_dev.c index 7e7c9e935eaf..e383a781c9e9 100644 --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c @@ -578,10 +578,27 @@ static const struct komeda_dev_funcs d71_chip_funcs = =3D { const struct komeda_dev_funcs * d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip) { - chip->arch_id =3D malidp_read32(reg_base, GLB_ARCH_ID); - chip->core_id =3D malidp_read32(reg_base, GLB_CORE_ID); - chip->core_info =3D malidp_read32(reg_base, GLB_CORE_INFO); - chip->bus_width =3D D71_BUS_WIDTH_16_BYTES; + const struct komeda_dev_funcs *funcs; + u32 product_id; - return &d71_chip_funcs; + chip->core_id =3D malidp_read32(reg_base, GLB_CORE_ID); + + product_id =3D MALIDP_CORE_ID_PRODUCT_ID(chip->core_id); + + switch (product_id) { + case MALIDP_D71_PRODUCT_ID: + funcs =3D &d71_chip_funcs; + break; + default: + funcs =3D NULL; + DRM_ERROR("Unsupported product: 0x%x\n", product_id); + } + + if (funcs) { + chip->arch_id =3D malidp_read32(reg_base, GLB_ARCH_ID); + chip->core_info =3D malidp_read32(reg_base, GLB_CORE_INFO); + chip->bus_width =3D D71_BUS_WIDTH_16_BYTES; + } + + return funcs; } diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/= drm/arm/display/komeda/komeda_dev.c index 2aee735a683f..dd4a0ba1c37d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c @@ -125,23 +125,16 @@ static int to_color_format(const char *str) return format; } -static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_nod= e *np) +static int komeda_parse_pipe_dt(struct komeda_pipeline *pipe) { - struct komeda_pipeline *pipe; + struct device_node *np =3D pipe->of_node; struct clk *clk; - u32 pipe_id; - int ret =3D 0, color_format; + u32 color_format; const char *str; - ret =3D of_property_read_u32(np, "reg", &pipe_id); - if (ret !=3D 0 || pipe_id >=3D mdev->n_pipelines) - return -EINVAL; - - pipe =3D mdev->pipelines[pipe_id]; - clk =3D of_clk_get_by_name(np, "pxclk"); if (IS_ERR(clk)) { - DRM_ERROR("get pxclk for pipeline %d failed!\n", pipe_id); + DRM_ERROR("get pxclk for pipeline %d failed!\n", pipe->id); return PTR_ERR(clk); } pipe->pxlclk =3D clk; @@ -163,7 +156,6 @@ static int komeda_parse_pipe_dt(struct komeda_dev *mdev= , struct device_node *np) of_graph_get_port_by_id(np, KOMEDA_OF_PORT_OUTPUT); pipe->dual_link =3D pipe->of_output_links[0] && pipe->of_output_links[1]; - pipe->of_node =3D np; return 0; } @@ -172,7 +164,9 @@ static int komeda_parse_dt(struct device *dev, struct k= omeda_dev *mdev) { struct platform_device *pdev =3D to_platform_device(dev); struct device_node *child, *np =3D dev->of_node; - int ret; + struct komeda_pipeline *pipe; + u32 pipe_id =3D U32_MAX; + int ret =3D -1; mdev->irq =3D platform_get_irq(pdev, 0); if (mdev->irq < 0) { @@ -181,32 +175,46 @@ static int komeda_parse_dt(struct device *dev, struct= komeda_dev *mdev) } for_each_available_child_of_node(np, child) { - if (of_node_cmp(child->name, "pipeline") =3D=3D 0) { - ret =3D komeda_parse_pipe_dt(mdev, child); - if (ret) { - DRM_ERROR("parse pipeline dt error!\n"); + if (of_node_name_eq(child, "pipeline")) { + ret =3D of_property_read_u32(child, "reg", &pipe_id); + if (pipe_id >=3D mdev->n_pipelines) { + DRM_WARN("Skip the redandunt DT node: pipeline-%u.\n", + pipe_id); of_node_put(child); - break; + continue; } + mdev->pipelines[pipe_id]->of_node =3D child; + } + } + + for (pipe_id =3D 0; pipe_id < mdev->n_pipelines; pipe_id++) { + pipe =3D mdev->pipelines[pipe_id]; + + if (!pipe->of_node) { + DRM_ERROR("Omit DT node for pipeline-%d.\n", pipe->id); + return -EINVAL; } + ret =3D komeda_parse_pipe_dt(pipe); + if (ret) + return ret; } mdev->side_by_side =3D !of_property_read_u32(np, "side_by_side_master", - &mdev->side_by_side_master); + &mdev->side_by_side_master); - return ret; + return 0; } struct komeda_dev *komeda_dev_create(struct device *dev) { struct platform_device *pdev =3D to_platform_device(dev); - const struct komeda_product_data *product; + komeda_identify_func komeda_identify; struct komeda_dev *mdev; struct resource *io_res; int err =3D 0; - product =3D of_device_get_match_data(dev); - if (!product) + komeda_identify =3D of_device_get_match_data(dev); + if (!komeda_identify) return ERR_PTR(-ENODEV); io_res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -240,11 +248,9 @@ struct komeda_dev *komeda_dev_create(struct device *de= v) clk_prepare_enable(mdev->aclk); - mdev->funcs =3D product->identify(mdev->reg_base, &mdev->chip); - if (!komeda_product_match(mdev, product->product_id)) { - DRM_ERROR("DT configured %x mismatch with real HW %x.\n", - product->product_id, - MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id)); + mdev->funcs =3D komeda_identify(mdev->reg_base, &mdev->chip); + if (!mdev->funcs) { + DRM_ERROR("Failed to identify the HW.\n"); err =3D -ENODEV; goto disable_clk; } diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h b/drivers/gpu/= drm/arm/display/komeda/komeda_dev.h index c70cc25d246f..f91a113b0fde 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.h @@ -51,11 +51,6 @@ #define KOMEDA_WARN_EVENTS KOMEDA_ERR_CSCE -/* malidp device id */ -enum { - MALI_D71 =3D 0, -}; - /* pipeline DT ports */ enum { KOMEDA_OF_PORT_OUTPUT =3D 0, @@ -69,12 +64,6 @@ struct komeda_chip_info { u32 bus_width; }; -struct komeda_product_data { - u32 product_id; - const struct komeda_dev_funcs *(*identify)(u32 __iomem *reg, - struct komeda_chip_info *info); -}; - struct komeda_dev; struct komeda_events { @@ -219,6 +208,9 @@ komeda_product_match(struct komeda_dev *mdev, u32 targe= t) return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) =3D=3D target; } +typedef const struct komeda_dev_funcs * +(*komeda_identify_func)(u32 __iomem *reg, struct komeda_chip_info *chip); + const struct komeda_dev_funcs * d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c b/drivers/gpu/= drm/arm/display/komeda/komeda_drv.c index d6c2222c5d33..b7a1097c45c4 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_drv.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_drv.c @@ -123,15 +123,8 @@ static int komeda_platform_remove(struct platform_devi= ce *pdev) return 0; } -static const struct komeda_product_data komeda_products[] =3D { - [MALI_D71] =3D { - .product_id =3D MALIDP_D71_PRODUCT_ID, - .identify =3D d71_identify, - }, -}; - static const struct of_device_id komeda_of_match[] =3D { - { .compatible =3D "arm,mali-d71", .data =3D &komeda_products[MALI_D71], }= , + { .compatible =3D "arm,mali-d71", .data =3D d71_identify, }, {}, }; -- 2.20.1