drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / rockchip / dw_hdmi-rockchip.c
bloba6d4a0236e8f6c96ee9c5dafdcbd73591dc4e7f9
1 /*
2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/regmap.h>
14 #include <drm/drm_of.h>
15 #include <drm/drmP.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_edid.h>
18 #include <drm/bridge/dw_hdmi.h>
20 #include "rockchip_drm_drv.h"
21 #include "rockchip_drm_vop.h"
23 #define GRF_SOC_CON6 0x025c
24 #define HDMI_SEL_VOP_LIT (1 << 4)
26 struct rockchip_hdmi {
27 struct device *dev;
28 struct regmap *regmap;
29 struct drm_encoder encoder;
32 #define to_rockchip_hdmi(x) container_of(x, struct rockchip_hdmi, x)
34 static const struct dw_hdmi_mpll_config rockchip_mpll_cfg[] = {
36 27000000, {
37 { 0x00b3, 0x0000},
38 { 0x2153, 0x0000},
39 { 0x40f3, 0x0000}
41 }, {
42 36000000, {
43 { 0x00b3, 0x0000},
44 { 0x2153, 0x0000},
45 { 0x40f3, 0x0000}
47 }, {
48 40000000, {
49 { 0x00b3, 0x0000},
50 { 0x2153, 0x0000},
51 { 0x40f3, 0x0000}
53 }, {
54 54000000, {
55 { 0x0072, 0x0001},
56 { 0x2142, 0x0001},
57 { 0x40a2, 0x0001},
59 }, {
60 65000000, {
61 { 0x0072, 0x0001},
62 { 0x2142, 0x0001},
63 { 0x40a2, 0x0001},
65 }, {
66 66000000, {
67 { 0x013e, 0x0003},
68 { 0x217e, 0x0002},
69 { 0x4061, 0x0002}
71 }, {
72 74250000, {
73 { 0x0072, 0x0001},
74 { 0x2145, 0x0002},
75 { 0x4061, 0x0002}
77 }, {
78 83500000, {
79 { 0x0072, 0x0001},
81 }, {
82 108000000, {
83 { 0x0051, 0x0002},
84 { 0x2145, 0x0002},
85 { 0x4061, 0x0002}
87 }, {
88 106500000, {
89 { 0x0051, 0x0002},
90 { 0x2145, 0x0002},
91 { 0x4061, 0x0002}
93 }, {
94 146250000, {
95 { 0x0051, 0x0002},
96 { 0x2145, 0x0002},
97 { 0x4061, 0x0002}
99 }, {
100 148500000, {
101 { 0x0051, 0x0003},
102 { 0x214c, 0x0003},
103 { 0x4064, 0x0003}
105 }, {
106 ~0UL, {
107 { 0x00a0, 0x000a },
108 { 0x2001, 0x000f },
109 { 0x4002, 0x000f },
114 static const struct dw_hdmi_curr_ctrl rockchip_cur_ctr[] = {
115 /* pixelclk bpp8 bpp10 bpp12 */
117 40000000, { 0x0018, 0x0018, 0x0018 },
118 }, {
119 65000000, { 0x0028, 0x0028, 0x0028 },
120 }, {
121 66000000, { 0x0038, 0x0038, 0x0038 },
122 }, {
123 74250000, { 0x0028, 0x0038, 0x0038 },
124 }, {
125 83500000, { 0x0028, 0x0038, 0x0038 },
126 }, {
127 146250000, { 0x0038, 0x0038, 0x0038 },
128 }, {
129 148500000, { 0x0000, 0x0038, 0x0038 },
130 }, {
131 ~0UL, { 0x0000, 0x0000, 0x0000},
135 static const struct dw_hdmi_phy_config rockchip_phy_config[] = {
136 /*pixelclk symbol term vlev*/
137 { 74250000, 0x8009, 0x0004, 0x0272},
138 { 148500000, 0x802b, 0x0004, 0x028d},
139 { 297000000, 0x8039, 0x0005, 0x028d},
140 { ~0UL, 0x0000, 0x0000, 0x0000}
143 static int rockchip_hdmi_parse_dt(struct rockchip_hdmi *hdmi)
145 struct device_node *np = hdmi->dev->of_node;
147 hdmi->regmap = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
148 if (IS_ERR(hdmi->regmap)) {
149 dev_err(hdmi->dev, "Unable to get rockchip,grf\n");
150 return PTR_ERR(hdmi->regmap);
153 return 0;
156 static enum drm_mode_status
157 dw_hdmi_rockchip_mode_valid(struct drm_connector *connector,
158 struct drm_display_mode *mode)
160 const struct dw_hdmi_mpll_config *mpll_cfg = rockchip_mpll_cfg;
161 int pclk = mode->clock * 1000;
162 bool valid = false;
163 int i;
165 for (i = 0; mpll_cfg[i].mpixelclock != (~0UL); i++) {
166 if (pclk == mpll_cfg[i].mpixelclock) {
167 valid = true;
168 break;
172 return (valid) ? MODE_OK : MODE_BAD;
175 static const struct drm_encoder_funcs dw_hdmi_rockchip_encoder_funcs = {
176 .destroy = drm_encoder_cleanup,
179 static void dw_hdmi_rockchip_encoder_disable(struct drm_encoder *encoder)
183 static bool
184 dw_hdmi_rockchip_encoder_mode_fixup(struct drm_encoder *encoder,
185 const struct drm_display_mode *mode,
186 struct drm_display_mode *adj_mode)
188 return true;
191 static void dw_hdmi_rockchip_encoder_mode_set(struct drm_encoder *encoder,
192 struct drm_display_mode *mode,
193 struct drm_display_mode *adj_mode)
197 static void dw_hdmi_rockchip_encoder_enable(struct drm_encoder *encoder)
199 struct rockchip_hdmi *hdmi = to_rockchip_hdmi(encoder);
200 u32 val;
201 int mux;
203 mux = drm_of_encoder_active_endpoint_id(hdmi->dev->of_node, encoder);
204 if (mux)
205 val = HDMI_SEL_VOP_LIT | (HDMI_SEL_VOP_LIT << 16);
206 else
207 val = HDMI_SEL_VOP_LIT << 16;
209 regmap_write(hdmi->regmap, GRF_SOC_CON6, val);
210 dev_dbg(hdmi->dev, "vop %s output to hdmi\n",
211 (mux) ? "LIT" : "BIG");
214 static int
215 dw_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder,
216 struct drm_crtc_state *crtc_state,
217 struct drm_connector_state *conn_state)
219 struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
221 s->output_mode = ROCKCHIP_OUT_MODE_AAAA;
222 s->output_type = DRM_MODE_CONNECTOR_HDMIA;
224 return 0;
227 static const struct drm_encoder_helper_funcs dw_hdmi_rockchip_encoder_helper_funcs = {
228 .mode_fixup = dw_hdmi_rockchip_encoder_mode_fixup,
229 .mode_set = dw_hdmi_rockchip_encoder_mode_set,
230 .enable = dw_hdmi_rockchip_encoder_enable,
231 .disable = dw_hdmi_rockchip_encoder_disable,
232 .atomic_check = dw_hdmi_rockchip_encoder_atomic_check,
235 static const struct dw_hdmi_plat_data rockchip_hdmi_drv_data = {
236 .mode_valid = dw_hdmi_rockchip_mode_valid,
237 .mpll_cfg = rockchip_mpll_cfg,
238 .cur_ctr = rockchip_cur_ctr,
239 .phy_config = rockchip_phy_config,
240 .dev_type = RK3288_HDMI,
243 static const struct of_device_id dw_hdmi_rockchip_dt_ids[] = {
244 { .compatible = "rockchip,rk3288-dw-hdmi",
245 .data = &rockchip_hdmi_drv_data
249 MODULE_DEVICE_TABLE(of, dw_hdmi_rockchip_dt_ids);
251 static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
252 void *data)
254 struct platform_device *pdev = to_platform_device(dev);
255 const struct dw_hdmi_plat_data *plat_data;
256 const struct of_device_id *match;
257 struct drm_device *drm = data;
258 struct drm_encoder *encoder;
259 struct rockchip_hdmi *hdmi;
260 int ret;
262 if (!pdev->dev.of_node)
263 return -ENODEV;
265 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
266 if (!hdmi)
267 return -ENOMEM;
269 match = of_match_node(dw_hdmi_rockchip_dt_ids, pdev->dev.of_node);
270 plat_data = match->data;
271 hdmi->dev = &pdev->dev;
272 encoder = &hdmi->encoder;
274 encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
276 * If we failed to find the CRTC(s) which this encoder is
277 * supposed to be connected to, it's because the CRTC has
278 * not been registered yet. Defer probing, and hope that
279 * the required CRTC is added later.
281 if (encoder->possible_crtcs == 0)
282 return -EPROBE_DEFER;
284 ret = rockchip_hdmi_parse_dt(hdmi);
285 if (ret) {
286 dev_err(hdmi->dev, "Unable to parse OF data\n");
287 return ret;
290 drm_encoder_helper_add(encoder, &dw_hdmi_rockchip_encoder_helper_funcs);
291 drm_encoder_init(drm, encoder, &dw_hdmi_rockchip_encoder_funcs,
292 DRM_MODE_ENCODER_TMDS, NULL);
294 ret = dw_hdmi_bind(pdev, encoder, plat_data);
297 * If dw_hdmi_bind() fails we'll never call dw_hdmi_unbind(),
298 * which would have called the encoder cleanup. Do it manually.
300 if (ret)
301 drm_encoder_cleanup(encoder);
303 return ret;
306 static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
307 void *data)
309 return dw_hdmi_unbind(dev);
312 static const struct component_ops dw_hdmi_rockchip_ops = {
313 .bind = dw_hdmi_rockchip_bind,
314 .unbind = dw_hdmi_rockchip_unbind,
317 static int dw_hdmi_rockchip_probe(struct platform_device *pdev)
319 return component_add(&pdev->dev, &dw_hdmi_rockchip_ops);
322 static int dw_hdmi_rockchip_remove(struct platform_device *pdev)
324 component_del(&pdev->dev, &dw_hdmi_rockchip_ops);
326 return 0;
329 static struct platform_driver dw_hdmi_rockchip_pltfm_driver = {
330 .probe = dw_hdmi_rockchip_probe,
331 .remove = dw_hdmi_rockchip_remove,
332 .driver = {
333 .name = "dwhdmi-rockchip",
334 .of_match_table = dw_hdmi_rockchip_dt_ids,
338 module_platform_driver(dw_hdmi_rockchip_pltfm_driver);
340 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
341 MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
342 MODULE_DESCRIPTION("Rockchip Specific DW-HDMI Driver Extension");
343 MODULE_LICENSE("GPL");
344 MODULE_ALIAS("platform:dwhdmi-rockchip");