Skip to content

Commit 1fa734a

Browse files
smaeulmripard
authored andcommitted
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 <[email protected]> Signed-off-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Maxime Ripard <[email protected]>
1 parent c1c7b39 commit 1fa734a

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,23 +1101,24 @@ static const struct component_ops sun6i_dsi_ops = {
11011101

11021102
static int sun6i_dsi_probe(struct platform_device *pdev)
11031103
{
1104+
const struct sun6i_dsi_variant *variant;
11041105
struct device *dev = &pdev->dev;
1105-
const char *bus_clk_name = NULL;
11061106
struct sun6i_dsi *dsi;
11071107
void __iomem *base;
11081108
int ret;
11091109

1110+
variant = device_get_match_data(dev);
1111+
if (!variant)
1112+
return -EINVAL;
1113+
11101114
dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
11111115
if (!dsi)
11121116
return -ENOMEM;
11131117
dev_set_drvdata(dev, dsi);
11141118
dsi->dev = dev;
11151119
dsi->host.ops = &sun6i_dsi_host_ops;
11161120
dsi->host.dev = dev;
1117-
1118-
if (of_device_is_compatible(dev->of_node,
1119-
"allwinner,sun6i-a31-mipi-dsi"))
1120-
bus_clk_name = "bus";
1121+
dsi->variant = variant;
11211122

11221123
base = devm_platform_ioremap_resource(pdev, 0);
11231124
if (IS_ERR(base)) {
@@ -1142,7 +1143,7 @@ static int sun6i_dsi_probe(struct platform_device *pdev)
11421143
return PTR_ERR(dsi->regs);
11431144
}
11441145

1145-
dsi->bus_clk = devm_clk_get(dev, bus_clk_name);
1146+
dsi->bus_clk = devm_clk_get(dev, variant->has_mod_clk ? "bus" : NULL);
11461147
if (IS_ERR(dsi->bus_clk))
11471148
return dev_err_probe(dev, PTR_ERR(dsi->bus_clk),
11481149
"Couldn't get the DSI bus clock\n");
@@ -1151,21 +1152,21 @@ static int sun6i_dsi_probe(struct platform_device *pdev)
11511152
if (ret)
11521153
return ret;
11531154

1154-
if (of_device_is_compatible(dev->of_node,
1155-
"allwinner,sun6i-a31-mipi-dsi")) {
1155+
if (variant->has_mod_clk) {
11561156
dsi->mod_clk = devm_clk_get(dev, "mod");
11571157
if (IS_ERR(dsi->mod_clk)) {
11581158
dev_err(dev, "Couldn't get the DSI mod clock\n");
11591159
ret = PTR_ERR(dsi->mod_clk);
11601160
goto err_attach_clk;
11611161
}
1162-
}
11631162

1164-
/*
1165-
* In order to operate properly, that clock seems to be always
1166-
* set to 297MHz.
1167-
*/
1168-
clk_set_rate_exclusive(dsi->mod_clk, 297000000);
1163+
/*
1164+
* In order to operate properly, the module clock on the
1165+
* A31 variant always seems to be set to 297MHz.
1166+
*/
1167+
if (variant->set_mod_clk)
1168+
clk_set_rate_exclusive(dsi->mod_clk, 297000000);
1169+
}
11691170

11701171
dsi->dphy = devm_phy_get(dev, "dphy");
11711172
if (IS_ERR(dsi->dphy)) {
@@ -1191,7 +1192,8 @@ static int sun6i_dsi_probe(struct platform_device *pdev)
11911192
err_remove_dsi_host:
11921193
mipi_dsi_host_unregister(&dsi->host);
11931194
err_unprotect_clk:
1194-
clk_rate_exclusive_put(dsi->mod_clk);
1195+
if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
1196+
clk_rate_exclusive_put(dsi->mod_clk);
11951197
err_attach_clk:
11961198
regmap_mmio_detach_clk(dsi->regs);
11971199

@@ -1205,16 +1207,31 @@ static int sun6i_dsi_remove(struct platform_device *pdev)
12051207

12061208
component_del(&pdev->dev, &sun6i_dsi_ops);
12071209
mipi_dsi_host_unregister(&dsi->host);
1208-
clk_rate_exclusive_put(dsi->mod_clk);
1210+
if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
1211+
clk_rate_exclusive_put(dsi->mod_clk);
12091212

12101213
regmap_mmio_detach_clk(dsi->regs);
12111214

12121215
return 0;
12131216
}
12141217

1218+
static const struct sun6i_dsi_variant sun6i_a31_mipi_dsi_variant = {
1219+
.has_mod_clk = true,
1220+
.set_mod_clk = true,
1221+
};
1222+
1223+
static const struct sun6i_dsi_variant sun50i_a64_mipi_dsi_variant = {
1224+
};
1225+
12151226
static const struct of_device_id sun6i_dsi_of_table[] = {
1216-
{ .compatible = "allwinner,sun6i-a31-mipi-dsi" },
1217-
{ .compatible = "allwinner,sun50i-a64-mipi-dsi" },
1227+
{
1228+
.compatible = "allwinner,sun6i-a31-mipi-dsi",
1229+
.data = &sun6i_a31_mipi_dsi_variant,
1230+
},
1231+
{
1232+
.compatible = "allwinner,sun50i-a64-mipi-dsi",
1233+
.data = &sun50i_a64_mipi_dsi_variant,
1234+
},
12181235
{ }
12191236
};
12201237
MODULE_DEVICE_TABLE(of, sun6i_dsi_of_table);

drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
#define SUN6I_DSI_TCON_DIV 4
1717

18+
struct sun6i_dsi_variant {
19+
bool has_mod_clk;
20+
bool set_mod_clk;
21+
};
22+
1823
struct sun6i_dsi {
1924
struct drm_connector connector;
2025
struct drm_encoder encoder;
@@ -31,6 +36,8 @@ struct sun6i_dsi {
3136
struct mipi_dsi_device *device;
3237
struct drm_device *drm;
3338
struct drm_panel *panel;
39+
40+
const struct sun6i_dsi_variant *variant;
3441
};
3542

3643
static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host)

0 commit comments

Comments
 (0)