1 From 28e64e830ef487b400b3b943fa3bda83dfb2a937 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Tue, 9 Aug 2022 22:03:42 -0500
4 Subject: [PATCH 096/117] drm/sun4i: dsi: Add a variant structure
6 Replace the ad-hoc calls to of_device_is_compatible() with a structure
7 describing the differences between variants. This is in preparation for
8 adding more variants to the driver.
11 - Add the variant check to the probe error path
13 Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
14 Signed-off-by: Samuel Holland <samuel@sholland.org>
16 drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 53 +++++++++++++++++---------
17 drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h | 7 ++++
18 2 files changed, 42 insertions(+), 18 deletions(-)
20 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c
21 +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c
22 @@ -1101,12 +1101,16 @@ static const struct component_ops sun6i_
24 static int sun6i_dsi_probe(struct platform_device *pdev)
26 + const struct sun6i_dsi_variant *variant;
27 struct device *dev = &pdev->dev;
28 - const char *bus_clk_name = NULL;
29 struct sun6i_dsi *dsi;
33 + variant = device_get_match_data(dev);
37 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
40 @@ -1114,10 +1118,7 @@ static int sun6i_dsi_probe(struct platfo
42 dsi->host.ops = &sun6i_dsi_host_ops;
45 - if (of_device_is_compatible(dev->of_node,
46 - "allwinner,sun6i-a31-mipi-dsi"))
47 - bus_clk_name = "bus";
48 + dsi->variant = variant;
50 base = devm_platform_ioremap_resource(pdev, 0);
52 @@ -1142,7 +1143,7 @@ static int sun6i_dsi_probe(struct platfo
53 return PTR_ERR(dsi->regs);
56 - dsi->bus_clk = devm_clk_get(dev, bus_clk_name);
57 + dsi->bus_clk = devm_clk_get(dev, variant->has_mod_clk ? "bus" : NULL);
58 if (IS_ERR(dsi->bus_clk))
59 return dev_err_probe(dev, PTR_ERR(dsi->bus_clk),
60 "Couldn't get the DSI bus clock\n");
61 @@ -1151,21 +1152,21 @@ static int sun6i_dsi_probe(struct platfo
65 - if (of_device_is_compatible(dev->of_node,
66 - "allwinner,sun6i-a31-mipi-dsi")) {
67 + if (variant->has_mod_clk) {
68 dsi->mod_clk = devm_clk_get(dev, "mod");
69 if (IS_ERR(dsi->mod_clk)) {
70 dev_err(dev, "Couldn't get the DSI mod clock\n");
71 ret = PTR_ERR(dsi->mod_clk);
77 - * In order to operate properly, that clock seems to be always
80 - clk_set_rate_exclusive(dsi->mod_clk, 297000000);
82 + * In order to operate properly, the module clock on the
83 + * A31 variant always seems to be set to 297MHz.
85 + if (variant->set_mod_clk)
86 + clk_set_rate_exclusive(dsi->mod_clk, 297000000);
89 dsi->dphy = devm_phy_get(dev, "dphy");
90 if (IS_ERR(dsi->dphy)) {
91 @@ -1191,7 +1192,8 @@ static int sun6i_dsi_probe(struct platfo
93 mipi_dsi_host_unregister(&dsi->host);
95 - clk_rate_exclusive_put(dsi->mod_clk);
96 + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
97 + clk_rate_exclusive_put(dsi->mod_clk);
99 regmap_mmio_detach_clk(dsi->regs);
101 @@ -1205,16 +1207,31 @@ static int sun6i_dsi_remove(struct platf
103 component_del(&pdev->dev, &sun6i_dsi_ops);
104 mipi_dsi_host_unregister(&dsi->host);
105 - clk_rate_exclusive_put(dsi->mod_clk);
106 + if (dsi->variant->has_mod_clk && dsi->variant->set_mod_clk)
107 + clk_rate_exclusive_put(dsi->mod_clk);
109 regmap_mmio_detach_clk(dsi->regs);
114 +static const struct sun6i_dsi_variant sun6i_a31_mipi_dsi_variant = {
115 + .has_mod_clk = true,
116 + .set_mod_clk = true,
119 +static const struct sun6i_dsi_variant sun50i_a64_mipi_dsi_variant = {
122 static const struct of_device_id sun6i_dsi_of_table[] = {
123 - { .compatible = "allwinner,sun6i-a31-mipi-dsi" },
124 - { .compatible = "allwinner,sun50i-a64-mipi-dsi" },
126 + .compatible = "allwinner,sun6i-a31-mipi-dsi",
127 + .data = &sun6i_a31_mipi_dsi_variant,
130 + .compatible = "allwinner,sun50i-a64-mipi-dsi",
131 + .data = &sun50i_a64_mipi_dsi_variant,
135 MODULE_DEVICE_TABLE(of, sun6i_dsi_of_table);
136 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h
137 +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.h
140 #define SUN6I_DSI_TCON_DIV 4
142 +struct sun6i_dsi_variant {
148 struct drm_connector connector;
149 struct drm_encoder encoder;
150 @@ -31,6 +36,8 @@ struct sun6i_dsi {
151 struct mipi_dsi_device *device;
152 struct drm_device *drm;
153 struct drm_panel *panel;
155 + const struct sun6i_dsi_variant *variant;
158 static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host)