.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
---|
2 | 2 | /* Copyright (c) 2018 Jernej Skrabec <jernej.skrabec@siol.net> */ |
---|
3 | 3 | |
---|
4 | | -#include <drm/drmP.h> |
---|
5 | | - |
---|
6 | | -#include <dt-bindings/clock/sun8i-tcon-top.h> |
---|
7 | 4 | |
---|
8 | 5 | #include <linux/bitfield.h> |
---|
9 | 6 | #include <linux/component.h> |
---|
10 | 7 | #include <linux/device.h> |
---|
| 8 | +#include <linux/io.h> |
---|
11 | 9 | #include <linux/module.h> |
---|
| 10 | +#include <linux/of_device.h> |
---|
12 | 11 | #include <linux/of_graph.h> |
---|
13 | 12 | #include <linux/platform_device.h> |
---|
14 | 13 | |
---|
| 14 | +#include <dt-bindings/clock/sun8i-tcon-top.h> |
---|
| 15 | + |
---|
15 | 16 | #include "sun8i_tcon_top.h" |
---|
| 17 | + |
---|
| 18 | +struct sun8i_tcon_top_quirks { |
---|
| 19 | + bool has_tcon_tv1; |
---|
| 20 | + bool has_dsi; |
---|
| 21 | +}; |
---|
16 | 22 | |
---|
17 | 23 | static bool sun8i_tcon_top_node_is_tcon_top(struct device_node *node) |
---|
18 | 24 | { |
---|
.. | .. |
---|
121 | 127 | struct platform_device *pdev = to_platform_device(dev); |
---|
122 | 128 | struct clk_hw_onecell_data *clk_data; |
---|
123 | 129 | struct sun8i_tcon_top *tcon_top; |
---|
| 130 | + const struct sun8i_tcon_top_quirks *quirks; |
---|
124 | 131 | struct resource *res; |
---|
125 | 132 | void __iomem *regs; |
---|
126 | 133 | int ret, i; |
---|
| 134 | + |
---|
| 135 | + quirks = of_device_get_match_data(&pdev->dev); |
---|
127 | 136 | |
---|
128 | 137 | tcon_top = devm_kzalloc(dev, sizeof(*tcon_top), GFP_KERNEL); |
---|
129 | 138 | if (!tcon_top) |
---|
130 | 139 | return -ENOMEM; |
---|
131 | 140 | |
---|
132 | | - clk_data = devm_kzalloc(dev, sizeof(*clk_data) + |
---|
133 | | - sizeof(*clk_data->hws) * CLK_NUM, |
---|
| 141 | + clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, CLK_NUM), |
---|
134 | 142 | GFP_KERNEL); |
---|
135 | 143 | if (!clk_data) |
---|
136 | 144 | return -ENOMEM; |
---|
.. | .. |
---|
188 | 196 | &tcon_top->reg_lock, |
---|
189 | 197 | TCON_TOP_TCON_TV0_GATE, 0); |
---|
190 | 198 | |
---|
191 | | - clk_data->hws[CLK_TCON_TOP_TV1] = |
---|
192 | | - sun8i_tcon_top_register_gate(dev, "tcon-tv1", regs, |
---|
193 | | - &tcon_top->reg_lock, |
---|
194 | | - TCON_TOP_TCON_TV1_GATE, 1); |
---|
| 199 | + if (quirks->has_tcon_tv1) |
---|
| 200 | + clk_data->hws[CLK_TCON_TOP_TV1] = |
---|
| 201 | + sun8i_tcon_top_register_gate(dev, "tcon-tv1", regs, |
---|
| 202 | + &tcon_top->reg_lock, |
---|
| 203 | + TCON_TOP_TCON_TV1_GATE, 1); |
---|
195 | 204 | |
---|
196 | | - clk_data->hws[CLK_TCON_TOP_DSI] = |
---|
197 | | - sun8i_tcon_top_register_gate(dev, "dsi", regs, |
---|
198 | | - &tcon_top->reg_lock, |
---|
199 | | - TCON_TOP_TCON_DSI_GATE, 2); |
---|
| 205 | + if (quirks->has_dsi) |
---|
| 206 | + clk_data->hws[CLK_TCON_TOP_DSI] = |
---|
| 207 | + sun8i_tcon_top_register_gate(dev, "dsi", regs, |
---|
| 208 | + &tcon_top->reg_lock, |
---|
| 209 | + TCON_TOP_TCON_DSI_GATE, 2); |
---|
200 | 210 | |
---|
201 | 211 | for (i = 0; i < CLK_NUM; i++) |
---|
202 | 212 | if (IS_ERR(clk_data->hws[i])) { |
---|
.. | .. |
---|
259 | 269 | return 0; |
---|
260 | 270 | } |
---|
261 | 271 | |
---|
| 272 | +static const struct sun8i_tcon_top_quirks sun8i_r40_tcon_top_quirks = { |
---|
| 273 | + .has_tcon_tv1 = true, |
---|
| 274 | + .has_dsi = true, |
---|
| 275 | +}; |
---|
| 276 | + |
---|
| 277 | +static const struct sun8i_tcon_top_quirks sun50i_h6_tcon_top_quirks = { |
---|
| 278 | + /* Nothing special */ |
---|
| 279 | +}; |
---|
| 280 | + |
---|
262 | 281 | /* sun4i_drv uses this list to check if a device node is a TCON TOP */ |
---|
263 | 282 | const struct of_device_id sun8i_tcon_top_of_table[] = { |
---|
| 283 | + { |
---|
| 284 | + .compatible = "allwinner,sun8i-r40-tcon-top", |
---|
| 285 | + .data = &sun8i_r40_tcon_top_quirks |
---|
| 286 | + }, |
---|
| 287 | + { |
---|
| 288 | + .compatible = "allwinner,sun50i-h6-tcon-top", |
---|
| 289 | + .data = &sun50i_h6_tcon_top_quirks |
---|
| 290 | + }, |
---|
264 | 291 | { /* sentinel */ } |
---|
265 | 292 | }; |
---|
266 | 293 | MODULE_DEVICE_TABLE(of, sun8i_tcon_top_of_table); |
---|