drm: imx: imx-hdmi: split phy configuration to platform driver
[deliverable/linux.git] / drivers / gpu / drm / imx / imx-hdmi_pltfm.c
CommitLineData
3d1b35a3
AY
1/* Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
2 *
3 * derived from imx-hdmi.c
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/component.h>
12#include <linux/mfd/syscon.h>
13#include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
14#include <video/imx-ipu-v3.h>
15#include <linux/regmap.h>
16#include <drm/drm_of.h>
17#include <drm/drmP.h>
18#include <drm/drm_crtc_helper.h>
19#include <drm/drm_edid.h>
20#include <drm/drm_encoder_slave.h>
21
22#include "imx-drm.h"
23#include "imx-hdmi.h"
24
25struct imx_hdmi_priv {
26 struct device *dev;
27 struct drm_encoder encoder;
28 struct regmap *regmap;
29};
30
aaa757a0
AY
31static const struct mpll_config imx_mpll_cfg[] = {
32 {
33 45250000, {
34 { 0x01e0, 0x0000 },
35 { 0x21e1, 0x0000 },
36 { 0x41e2, 0x0000 }
37 },
38 }, {
39 92500000, {
40 { 0x0140, 0x0005 },
41 { 0x2141, 0x0005 },
42 { 0x4142, 0x0005 },
43 },
44 }, {
45 148500000, {
46 { 0x00a0, 0x000a },
47 { 0x20a1, 0x000a },
48 { 0x40a2, 0x000a },
49 },
50 }, {
51 ~0UL, {
52 { 0x00a0, 0x000a },
53 { 0x2001, 0x000f },
54 { 0x4002, 0x000f },
55 },
56 }
57};
58
59static const struct curr_ctrl imx_cur_ctr[] = {
60 /* pixelclk bpp8 bpp10 bpp12 */
61 {
62 54000000, { 0x091c, 0x091c, 0x06dc },
63 }, {
64 58400000, { 0x091c, 0x06dc, 0x06dc },
65 }, {
66 72000000, { 0x06dc, 0x06dc, 0x091c },
67 }, {
68 74250000, { 0x06dc, 0x0b5c, 0x091c },
69 }, {
70 118800000, { 0x091c, 0x091c, 0x06dc },
71 }, {
72 216000000, { 0x06dc, 0x0b5c, 0x091c },
73 }
74};
75
76static const struct sym_term imx_sym_term[] = {
77 /*pixelclk symbol term*/
78 { 148500000, 0x800d, 0x0005 },
79 { ~0UL, 0x0000, 0x0000 }
80};
81
3d1b35a3
AY
82static int imx_hdmi_parse_dt(struct imx_hdmi_priv *hdmi)
83{
84 struct device_node *np = hdmi->dev->of_node;
85
86 hdmi->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
87 if (IS_ERR(hdmi->regmap)) {
88 dev_err(hdmi->dev, "Unable to get gpr\n");
89 return PTR_ERR(hdmi->regmap);
90 }
91
92 return 0;
93}
94
95static void imx_hdmi_encoder_disable(struct drm_encoder *encoder)
96{
97}
98
99static bool imx_hdmi_encoder_mode_fixup(struct drm_encoder *encoder,
100 const struct drm_display_mode *mode,
101 struct drm_display_mode *adj_mode)
102{
103 return true;
104}
105
106static void imx_hdmi_encoder_mode_set(struct drm_encoder *encoder,
107 struct drm_display_mode *mode,
108 struct drm_display_mode *adj_mode)
109{
110}
111
112static void imx_hdmi_encoder_commit(struct drm_encoder *encoder)
113{
114 struct imx_hdmi_priv *hdmi = container_of(encoder,
115 struct imx_hdmi_priv,
116 encoder);
117 int mux = imx_drm_encoder_get_mux_id(hdmi->dev->of_node, encoder);
118
119 regmap_update_bits(hdmi->regmap, IOMUXC_GPR3,
120 IMX6Q_GPR3_HDMI_MUX_CTL_MASK,
121 mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT);
122}
123
124static void imx_hdmi_encoder_prepare(struct drm_encoder *encoder)
125{
126 imx_drm_panel_format(encoder, V4L2_PIX_FMT_RGB24);
127}
128
129static struct drm_encoder_helper_funcs imx_hdmi_encoder_helper_funcs = {
130 .mode_fixup = imx_hdmi_encoder_mode_fixup,
131 .mode_set = imx_hdmi_encoder_mode_set,
132 .prepare = imx_hdmi_encoder_prepare,
133 .commit = imx_hdmi_encoder_commit,
134 .disable = imx_hdmi_encoder_disable,
135};
136
137static struct drm_encoder_funcs imx_hdmi_encoder_funcs = {
138 .destroy = drm_encoder_cleanup,
139};
140
141static struct imx_hdmi_plat_data imx6q_hdmi_drv_data = {
aaa757a0
AY
142 .mpll_cfg = imx_mpll_cfg,
143 .cur_ctr = imx_cur_ctr,
144 .sym_term = imx_sym_term,
3d1b35a3
AY
145 .dev_type = IMX6Q_HDMI,
146};
147
148static struct imx_hdmi_plat_data imx6dl_hdmi_drv_data = {
aaa757a0
AY
149 .mpll_cfg = imx_mpll_cfg,
150 .cur_ctr = imx_cur_ctr,
151 .sym_term = imx_sym_term,
3d1b35a3
AY
152 .dev_type = IMX6DL_HDMI,
153};
154
155static const struct of_device_id imx_hdmi_dt_ids[] = {
156 { .compatible = "fsl,imx6q-hdmi",
157 .data = &imx6q_hdmi_drv_data
158 }, {
159 .compatible = "fsl,imx6dl-hdmi",
160 .data = &imx6dl_hdmi_drv_data
161 },
162 {},
163};
164MODULE_DEVICE_TABLE(of, imx_hdmi_dt_ids);
165
166static int imx_hdmi_pltfm_bind(struct device *dev, struct device *master,
167 void *data)
168{
169 struct platform_device *pdev = to_platform_device(dev);
170 const struct imx_hdmi_plat_data *plat_data;
171 const struct of_device_id *match;
172 struct drm_device *drm = data;
173 struct drm_encoder *encoder;
174 struct imx_hdmi_priv *hdmi;
175 struct resource *iores;
176 int irq;
177 int ret;
178
179 if (!pdev->dev.of_node)
180 return -ENODEV;
181
182 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
183 if (!hdmi)
184 return -ENOMEM;
185
186 match = of_match_node(imx_hdmi_dt_ids, pdev->dev.of_node);
187 plat_data = match->data;
188 hdmi->dev = &pdev->dev;
189 encoder = &hdmi->encoder;
190
191 irq = platform_get_irq(pdev, 0);
192 if (irq < 0)
193 return irq;
194
195 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
196 if (!iores)
197 return -ENXIO;
198
199 platform_set_drvdata(pdev, hdmi);
200
201 encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
202 /*
203 * If we failed to find the CRTC(s) which this encoder is
204 * supposed to be connected to, it's because the CRTC has
205 * not been registered yet. Defer probing, and hope that
206 * the required CRTC is added later.
207 */
208 if (encoder->possible_crtcs == 0)
209 return -EPROBE_DEFER;
210
211 ret = imx_hdmi_parse_dt(hdmi);
212 if (ret < 0)
213 return ret;
214
215 drm_encoder_helper_add(encoder, &imx_hdmi_encoder_helper_funcs);
216 drm_encoder_init(drm, encoder, &imx_hdmi_encoder_funcs,
217 DRM_MODE_ENCODER_TMDS);
218
219 return imx_hdmi_bind(dev, master, data, encoder, iores, irq, plat_data);
220}
221
222static void imx_hdmi_pltfm_unbind(struct device *dev, struct device *master,
223 void *data)
224{
225 return imx_hdmi_unbind(dev, master, data);
226}
227
228static const struct component_ops imx_hdmi_ops = {
229 .bind = imx_hdmi_pltfm_bind,
230 .unbind = imx_hdmi_pltfm_unbind,
231};
232
233static int imx_hdmi_probe(struct platform_device *pdev)
234{
235 return component_add(&pdev->dev, &imx_hdmi_ops);
236}
237
238static int imx_hdmi_remove(struct platform_device *pdev)
239{
240 component_del(&pdev->dev, &imx_hdmi_ops);
241
242 return 0;
243}
244
245static struct platform_driver imx_hdmi_pltfm_driver = {
246 .probe = imx_hdmi_probe,
247 .remove = imx_hdmi_remove,
248 .driver = {
249 .name = "hdmi-imx",
250 .of_match_table = imx_hdmi_dt_ids,
251 },
252};
253
254module_platform_driver(imx_hdmi_pltfm_driver);
255
256MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
257MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
258MODULE_DESCRIPTION("IMX6 Specific DW-HDMI Driver Extension");
259MODULE_LICENSE("GPL");
260MODULE_ALIAS("platform:hdmi-imx");
This page took 0.05558 seconds and 5 git commands to generate.