d1: add new target
[openwrt/staging/mans0n.git] / target / linux / d1 / patches-6.1 / 0096-drm-sun4i-dsi-Add-a-variant-structure.patch
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
5
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.
9
10 Series-changes: 2
11 - Add the variant check to the probe error path
12
13 Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
14 Signed-off-by: Samuel Holland <samuel@sholland.org>
15 ---
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(-)
19
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_
23
24 static int sun6i_dsi_probe(struct platform_device *pdev)
25 {
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;
30 void __iomem *base;
31 int ret;
32
33 + variant = device_get_match_data(dev);
34 + if (!variant)
35 + return -EINVAL;
36 +
37 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
38 if (!dsi)
39 return -ENOMEM;
40 @@ -1114,10 +1118,7 @@ static int sun6i_dsi_probe(struct platfo
41 dsi->dev = dev;
42 dsi->host.ops = &sun6i_dsi_host_ops;
43 dsi->host.dev = dev;
44 -
45 - if (of_device_is_compatible(dev->of_node,
46 - "allwinner,sun6i-a31-mipi-dsi"))
47 - bus_clk_name = "bus";
48 + dsi->variant = variant;
49
50 base = devm_platform_ioremap_resource(pdev, 0);
51 if (IS_ERR(base)) {
52 @@ -1142,7 +1143,7 @@ static int sun6i_dsi_probe(struct platfo
53 return PTR_ERR(dsi->regs);
54 }
55
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
62 if (ret)
63 return ret;
64
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);
72 goto err_attach_clk;
73 }
74 - }
75
76 - /*
77 - * In order to operate properly, that clock seems to be always
78 - * set to 297MHz.
79 - */
80 - clk_set_rate_exclusive(dsi->mod_clk, 297000000);
81 + /*
82 + * In order to operate properly, the module clock on the
83 + * A31 variant always seems to be set to 297MHz.
84 + */
85 + if (variant->set_mod_clk)
86 + clk_set_rate_exclusive(dsi->mod_clk, 297000000);
87 + }
88
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
92 err_remove_dsi_host:
93 mipi_dsi_host_unregister(&dsi->host);
94 err_unprotect_clk:
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);
98 err_attach_clk:
99 regmap_mmio_detach_clk(dsi->regs);
100
101 @@ -1205,16 +1207,31 @@ static int sun6i_dsi_remove(struct platf
102
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);
108
109 regmap_mmio_detach_clk(dsi->regs);
110
111 return 0;
112 }
113
114 +static const struct sun6i_dsi_variant sun6i_a31_mipi_dsi_variant = {
115 + .has_mod_clk = true,
116 + .set_mod_clk = true,
117 +};
118 +
119 +static const struct sun6i_dsi_variant sun50i_a64_mipi_dsi_variant = {
120 +};
121 +
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" },
125 + {
126 + .compatible = "allwinner,sun6i-a31-mipi-dsi",
127 + .data = &sun6i_a31_mipi_dsi_variant,
128 + },
129 + {
130 + .compatible = "allwinner,sun50i-a64-mipi-dsi",
131 + .data = &sun50i_a64_mipi_dsi_variant,
132 + },
133 { }
134 };
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
138 @@ -15,6 +15,11 @@
139
140 #define SUN6I_DSI_TCON_DIV 4
141
142 +struct sun6i_dsi_variant {
143 + bool has_mod_clk;
144 + bool set_mod_clk;
145 +};
146 +
147 struct sun6i_dsi {
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;
154 +
155 + const struct sun6i_dsi_variant *variant;
156 };
157
158 static inline struct sun6i_dsi *host_to_sun6i_dsi(struct mipi_dsi_host *host)