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

drm/sun4i: dsi: Add a variant structure

Replace the ad-hoc calls to of_device_is_compatible() with a structure
describing the differences between variants. This is in preparation for
adding more variants to the driver.

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Samuel Holland <samuel@sholland.org>
Link: https://lore.kernel.org/r/20221107053552.2330-4-samuel@sholland.org
Signed-off-by: Maxime Ripard <maxime@cerno.tech>

authored by

Samuel Holland and committed by
Maxime Ripard
1fa734a8 c1c7b394

+42 -18
+35 -18
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c
··· 1101 1101 1102 1102 static int sun6i_dsi_probe(struct platform_device *pdev) 1103 1103 { 1104 + const struct sun6i_dsi_variant *variant; 1104 1105 struct device *dev = &pdev->dev; 1105 - const char *bus_clk_name = NULL; 1106 1106 struct sun6i_dsi *dsi; 1107 1107 void __iomem *base; 1108 1108 int ret; 1109 + 1110 + variant = device_get_match_data(dev); 1111 + if (!variant) 1112 + return -EINVAL; 1109 1113 1110 1114 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); 1111 1115 if (!dsi) ··· 1118 1114 dsi->dev = dev; 1119 1115 dsi->host.ops = &sun6i_dsi_host_ops; 1120 1116 dsi->host.dev = dev; 1121 - 1122 - if (of_device_is_compatible(dev->of_node, 1123 - "allwinner,sun6i-a31-mipi-dsi")) 1124 - bus_clk_name = "bus"; 1117 + dsi->variant = variant; 1125 1118 1126 1119 base = devm_platform_ioremap_resource(pdev, 0); 1127 1120 if (IS_ERR(base)) { ··· 1143 1142 return PTR_ERR(dsi->regs); 1144 1143 } 1145 1144 1146 - dsi->bus_clk = devm_clk_get(dev, bus_clk_name); 1145 + dsi->bus_clk = devm_clk_get(dev, variant->has_mod_clk ? "bus" : NULL); 1147 1146 if (IS_ERR(dsi->bus_clk)) 1148 1147 return dev_err_probe(dev, PTR_ERR(dsi->bus_clk), 1149 1148 "Couldn't get the DSI bus clock\n"); ··· 1152 1151 if (ret) 1153 1152 return ret; 1154 1153 1155 - if (of_device_is_compatible(dev->of_node, 1156 - "allwinner,sun6i-a31-mipi-dsi")) { 1154 + if (variant->has_mod_clk) { 1157 1155 dsi->mod_clk = devm_clk_get(dev, "mod"); 1158 1156 if (IS_ERR(dsi->mod_clk)) { 1159 1157 dev_err(dev, "Couldn't get the DSI mod clock\n"); 1160 1158 ret = PTR_ERR(dsi->mod_clk); 1161 1159 goto err_attach_clk; 1162 1160 } 1163 - } 1164 1161 1165 - /* 1166 - * In order to operate properly, that clock seems to be always 1167 - * set to 297MHz. 1168 - */ 1169 - clk_set_rate_exclusive(dsi->mod_clk, 297000000); 1162 + /* 1163 + * In order to operate properly, the module clock on the 1164 + * A31 variant always seems to be set to 297MHz. 1165 + */ 1166 + if (variant->set_mod_clk) 1167 + clk_set_rate_exclusive(dsi->mod_clk, 297000000); 1168 + } 1170 1169 1171 1170 dsi->dphy = devm_phy_get(dev, "dphy"); 1172 1171 if (IS_ERR(dsi->dphy)) { ··· 1192 1191 err_remove_dsi_host: 1193 1192 mipi_dsi_host_unregister(&dsi->host); 1194 1193 err_unprotect_clk: 1195 - clk_rate_exclusive_put(dsi->mod_clk); 1194 + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk) 1195 + clk_rate_exclusive_put(dsi->mod_clk); 1196 1196 err_attach_clk: 1197 1197 regmap_mmio_detach_clk(dsi->regs); 1198 1198 ··· 1207 1205 1208 1206 component_del(&pdev->dev, &sun6i_dsi_ops); 1209 1207 mipi_dsi_host_unregister(&dsi->host); 1210 - clk_rate_exclusive_put(dsi->mod_clk); 1208 + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk) 1209 + clk_rate_exclusive_put(dsi->mod_clk); 1211 1210 1212 1211 regmap_mmio_detach_clk(dsi->regs); 1213 1212 1214 1213 return 0; 1215 1214 } 1216 1215 1216 + static const struct sun6i_dsi_variant sun6i_a31_mipi_dsi_variant = { 1217 + .has_mod_clk = true, 1218 + .set_mod_clk = true, 1219 + }; 1220 + 1221 + static const struct sun6i_dsi_variant sun50i_a64_mipi_dsi_variant = { 1222 + }; 1223 + 1217 1224 static const struct of_device_id sun6i_dsi_of_table[] = { 1218 - { .compatible = "allwinner,sun6i-a31-mipi-dsi" }, 1219 - { .compatible = "allwinner,sun50i-a64-mipi-dsi" }, 1225 + { 1226 + .compatible = "allwinner,sun6i-a31-mipi-dsi", 1227 + .data = &sun6i_a31_mipi_dsi_variant, 1228 + }, 1229 + { 1230 + .compatible = "allwinner,sun50i-a64-mipi-dsi", 1231 + .data = &sun50i_a64_mipi_dsi_variant, 1232 + }, 1220 1233 { } 1221 1234 }; 1222 1235 MODULE_DEVICE_TABLE(of, sun6i_dsi_of_table);
+7
drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h
··· 15 15 16 16 #define SUN6I_DSI_TCON_DIV 4 17 17 18 + struct sun6i_dsi_variant { 19 + bool has_mod_clk; 20 + bool set_mod_clk; 21 + }; 22 + 18 23 struct sun6i_dsi { 19 24 struct drm_connector connector; 20 25 struct drm_encoder encoder; ··· 36 31 struct mipi_dsi_device *device; 37 32 struct drm_device *drm; 38 33 struct drm_panel *panel; 34 + 35 + const struct sun6i_dsi_variant *variant; 39 36 }; 40 37 41 38 static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host)