Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/komeda: Update the chip identify

1. Drop komeda-CORE product id comparison and put it into the d71_identify
2. Update pipeline node DT-binding:
(a). Skip the needless pipeline DT node.
(b). Return fail if the essential pipeline DT node is missing.

With these changes, for chips in same family no need to change the DT.

v2: Rebase
v3: Address Mihail's comments.

Signed-off-by: james qian wang (Arm Technology China) <james.qian.wang@arm.com>
Reviewed-by: Mihail Atanassov <mihail.atanassov@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191210084828.19664-2-james.qian.wang@arm.com

+54 -49
+17 -2
drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c
··· 597 597 const struct komeda_dev_funcs * 598 598 d71_identify(u32 __iomem *reg_base, struct komeda_chip_info *chip) 599 599 { 600 + const struct komeda_dev_funcs *funcs; 601 + u32 product_id; 602 + 603 + chip->core_id = malidp_read32(reg_base, GLB_CORE_ID); 604 + 605 + product_id = MALIDP_CORE_ID_PRODUCT_ID(chip->core_id); 606 + 607 + switch (product_id) { 608 + case MALIDP_D71_PRODUCT_ID: 609 + funcs = &d71_chip_funcs; 610 + break; 611 + default: 612 + DRM_ERROR("Unsupported product: 0x%x\n", product_id); 613 + return NULL; 614 + } 615 + 600 616 chip->arch_id = malidp_read32(reg_base, GLB_ARCH_ID); 601 - chip->core_id = malidp_read32(reg_base, GLB_CORE_ID); 602 617 chip->core_info = malidp_read32(reg_base, GLB_CORE_INFO); 603 618 chip->bus_width = D71_BUS_WIDTH_16_BYTES; 604 619 605 - return &d71_chip_funcs; 620 + return funcs; 606 621 }
+33 -28
drivers/gpu/drm/arm/display/komeda/komeda_dev.c
··· 115 115 .attrs = komeda_sysfs_entries, 116 116 }; 117 117 118 - static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np) 118 + static int komeda_parse_pipe_dt(struct komeda_pipeline *pipe) 119 119 { 120 - struct komeda_pipeline *pipe; 120 + struct device_node *np = pipe->of_node; 121 121 struct clk *clk; 122 - u32 pipe_id; 123 - int ret = 0; 124 - 125 - ret = of_property_read_u32(np, "reg", &pipe_id); 126 - if (ret != 0 || pipe_id >= mdev->n_pipelines) 127 - return -EINVAL; 128 - 129 - pipe = mdev->pipelines[pipe_id]; 130 122 131 123 clk = of_clk_get_by_name(np, "pxclk"); 132 124 if (IS_ERR(clk)) { 133 - DRM_ERROR("get pxclk for pipeline %d failed!\n", pipe_id); 125 + DRM_ERROR("get pxclk for pipeline %d failed!\n", pipe->id); 134 126 return PTR_ERR(clk); 135 127 } 136 128 pipe->pxlclk = clk; ··· 136 144 of_graph_get_port_by_id(np, KOMEDA_OF_PORT_OUTPUT); 137 145 138 146 pipe->dual_link = pipe->of_output_links[0] && pipe->of_output_links[1]; 139 - pipe->of_node = of_node_get(np); 140 147 141 148 return 0; 142 149 } ··· 144 153 { 145 154 struct platform_device *pdev = to_platform_device(dev); 146 155 struct device_node *child, *np = dev->of_node; 147 - int ret; 156 + struct komeda_pipeline *pipe; 157 + u32 pipe_id = U32_MAX; 158 + int ret = -1; 148 159 149 160 mdev->irq = platform_get_irq(pdev, 0); 150 161 if (mdev->irq < 0) { ··· 161 168 ret = 0; 162 169 163 170 for_each_available_child_of_node(np, child) { 164 - if (of_node_cmp(child->name, "pipeline") == 0) { 165 - ret = komeda_parse_pipe_dt(mdev, child); 166 - if (ret) { 167 - DRM_ERROR("parse pipeline dt error!\n"); 168 - of_node_put(child); 169 - break; 171 + if (of_node_name_eq(child, "pipeline")) { 172 + of_property_read_u32(child, "reg", &pipe_id); 173 + if (pipe_id >= mdev->n_pipelines) { 174 + DRM_WARN("Skip the redundant DT node: pipeline-%u.\n", 175 + pipe_id); 176 + continue; 170 177 } 178 + mdev->pipelines[pipe_id]->of_node = of_node_get(child); 171 179 } 172 180 } 173 181 174 - return ret; 182 + for (pipe_id = 0; pipe_id < mdev->n_pipelines; pipe_id++) { 183 + pipe = mdev->pipelines[pipe_id]; 184 + 185 + if (!pipe->of_node) { 186 + DRM_ERROR("Pipeline-%d doesn't have a DT node.\n", 187 + pipe->id); 188 + return -EINVAL; 189 + } 190 + ret = komeda_parse_pipe_dt(pipe); 191 + if (ret) 192 + return ret; 193 + } 194 + 195 + return 0; 175 196 } 176 197 177 198 struct komeda_dev *komeda_dev_create(struct device *dev) 178 199 { 179 200 struct platform_device *pdev = to_platform_device(dev); 180 - const struct komeda_product_data *product; 201 + komeda_identify_func komeda_identify; 181 202 struct komeda_dev *mdev; 182 203 int err = 0; 183 204 184 - product = of_device_get_match_data(dev); 185 - if (!product) 205 + komeda_identify = of_device_get_match_data(dev); 206 + if (!komeda_identify) 186 207 return ERR_PTR(-ENODEV); 187 208 188 209 mdev = devm_kzalloc(dev, sizeof(*mdev), GFP_KERNEL); ··· 224 217 225 218 clk_prepare_enable(mdev->aclk); 226 219 227 - mdev->funcs = product->identify(mdev->reg_base, &mdev->chip); 228 - if (!komeda_product_match(mdev, product->product_id)) { 229 - DRM_ERROR("DT configured %x mismatch with real HW %x.\n", 230 - product->product_id, 231 - MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id)); 220 + mdev->funcs = komeda_identify(mdev->reg_base, &mdev->chip); 221 + if (!mdev->funcs) { 222 + DRM_ERROR("Failed to identify the HW.\n"); 232 223 err = -ENODEV; 233 224 goto disable_clk; 234 225 }
+3 -11
drivers/gpu/drm/arm/display/komeda/komeda_dev.h
··· 58 58 | KOMEDA_EVENT_MODE \ 59 59 ) 60 60 61 - /* malidp device id */ 62 - enum { 63 - MALI_D71 = 0, 64 - }; 65 - 66 61 /* pipeline DT ports */ 67 62 enum { 68 63 KOMEDA_OF_PORT_OUTPUT = 0, ··· 69 74 u32 core_id; 70 75 u32 core_info; 71 76 u32 bus_width; 72 - }; 73 - 74 - struct komeda_product_data { 75 - u32 product_id; 76 - const struct komeda_dev_funcs *(*identify)(u32 __iomem *reg, 77 - struct komeda_chip_info *info); 78 77 }; 79 78 80 79 struct komeda_dev; ··· 222 233 { 223 234 return MALIDP_CORE_ID_PRODUCT_ID(mdev->chip.core_id) == target; 224 235 } 236 + 237 + typedef const struct komeda_dev_funcs * 238 + (*komeda_identify_func)(u32 __iomem *reg, struct komeda_chip_info *chip); 225 239 226 240 const struct komeda_dev_funcs * 227 241 d71_identify(u32 __iomem *reg, struct komeda_chip_info *chip);
+1 -8
drivers/gpu/drm/arm/display/komeda/komeda_drv.c
··· 123 123 return 0; 124 124 } 125 125 126 - static const struct komeda_product_data komeda_products[] = { 127 - [MALI_D71] = { 128 - .product_id = MALIDP_D71_PRODUCT_ID, 129 - .identify = d71_identify, 130 - }, 131 - }; 132 - 133 126 static const struct of_device_id komeda_of_match[] = { 134 - { .compatible = "arm,mali-d71", .data = &komeda_products[MALI_D71], }, 127 + { .compatible = "arm,mali-d71", .data = d71_identify, }, 135 128 {}, 136 129 }; 137 130