aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2018-09-06 21:03:24 -0400
committerDave Airlie <airlied@redhat.com>2018-09-06 21:03:29 -0400
commit1f3eb3461f58a4c48da67af4a8c4deb4d3c97214 (patch)
tree8f968176cf7117657b436a76bf52aec83bbc1cff /drivers/gpu/drm
parentf5169a17af4ee5170587fd76d76aaa72ae4b864a (diff)
parent6ea48430952323091194100d48c5610b9cd286b4 (diff)
Merge tag 'omapdrm-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux into drm-next
omapdrm changes for v4.20 Big amount of changes from Laurent, reworking the driver towards the model used by the other DRM drivers by reverting the direction of many of the operations on the display pipeline. The aim of this work is to allow omapdrm to use the common DRM panels and bridges. Not all of the operations are dealt in these patches, so more work needs to be done. The only change visible to the user should be the change in module dependencies: e.g. earlier a panel module depended on an encoder module, but now the encoder module depends on the panel module, which affects the order in which to unload the modules. Signed-off-by: Dave Airlie <airlied@redhat.com> From: Tomi Valkeinen <tomi.valkeinen@ti.com> Link: https://patchwork.freedesktop.org/patch/msgid/9bb1a01b-a632-ce0c-f249-7b5470967e3a@ti.com
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r--drivers/gpu/drm/omapdrm/displays/connector-analog-tv.c139
-rw-r--r--drivers/gpu/drm/omapdrm/displays/connector-dvi.c175
-rw-r--r--drivers/gpu/drm/omapdrm/displays/connector-hdmi.c277
-rw-r--r--drivers/gpu/drm/omapdrm/displays/encoder-opa362.c132
-rw-r--r--drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c187
-rw-r--r--drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c197
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-dpi.c88
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c247
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-lgphilips-lb035q02.c103
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c146
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-sharp-ls037v7dw01.c101
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-sony-acx565akm.c165
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-tpo-td028ttec1.c102
-rw-r--r--drivers/gpu/drm/omapdrm/displays/panel-tpo-td043mtea1.c192
-rw-r--r--drivers/gpu/drm/omapdrm/dss/base.c217
-rw-r--r--drivers/gpu/drm/omapdrm/dss/core.c26
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dispc.c26
-rw-r--r--drivers/gpu/drm/omapdrm/dss/display.c134
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dpi.c192
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dsi.c569
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dss-of.c47
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dss.c45
-rw-r--r--drivers/gpu/drm/omapdrm/dss/dss.h11
-rw-r--r--drivers/gpu/drm/omapdrm/dss/hdmi.h8
-rw-r--r--drivers/gpu/drm/omapdrm/dss/hdmi4.c351
-rw-r--r--drivers/gpu/drm/omapdrm/dss/hdmi5.c334
-rw-r--r--drivers/gpu/drm/omapdrm/dss/hdmi5_core.c6
-rw-r--r--drivers/gpu/drm/omapdrm/dss/hdmi_wp.c8
-rw-r--r--drivers/gpu/drm/omapdrm/dss/omapdss.h306
-rw-r--r--drivers/gpu/drm/omapdrm/dss/output.c208
-rw-r--r--drivers/gpu/drm/omapdrm/dss/sdi.c149
-rw-r--r--drivers/gpu/drm/omapdrm/dss/venc.c291
-rw-r--r--drivers/gpu/drm/omapdrm/omap_connector.c371
-rw-r--r--drivers/gpu/drm/omapdrm/omap_connector.h7
-rw-r--r--drivers/gpu/drm/omapdrm/omap_crtc.c111
-rw-r--r--drivers/gpu/drm/omapdrm/omap_crtc.h6
-rw-r--r--drivers/gpu/drm/omapdrm/omap_drv.c302
-rw-r--r--drivers/gpu/drm/omapdrm/omap_drv.h19
-rw-r--r--drivers/gpu/drm/omapdrm/omap_encoder.c159
-rw-r--r--drivers/gpu/drm/omapdrm/omap_encoder.h6
-rw-r--r--drivers/gpu/drm/omapdrm/omap_fbdev.c4
-rw-r--r--drivers/gpu/drm/omapdrm/omap_irq.c4
42 files changed, 2295 insertions, 3873 deletions
diff --git a/drivers/gpu/drm/omapdrm/displays/connector-analog-tv.c b/drivers/gpu/drm/omapdrm/displays/connector-analog-tv.c
index 9eabd7201a12..28a3ce8f88d2 100644
--- a/drivers/gpu/drm/omapdrm/displays/connector-analog-tv.c
+++ b/drivers/gpu/drm/omapdrm/displays/connector-analog-tv.c
@@ -18,77 +18,27 @@
18 18
19struct panel_drv_data { 19struct panel_drv_data {
20 struct omap_dss_device dssdev; 20 struct omap_dss_device dssdev;
21 struct omap_dss_device *in;
22 21
23 struct device *dev; 22 struct device *dev;
24
25 struct videomode vm;
26};
27
28static const struct videomode tvc_pal_vm = {
29 .hactive = 720,
30 .vactive = 574,
31 .pixelclock = 13500000,
32 .hsync_len = 64,
33 .hfront_porch = 12,
34 .hback_porch = 68,
35 .vsync_len = 5,
36 .vfront_porch = 5,
37 .vback_porch = 41,
38
39 .flags = DISPLAY_FLAGS_INTERLACED | DISPLAY_FLAGS_HSYNC_LOW |
40 DISPLAY_FLAGS_VSYNC_LOW,
41}; 23};
42 24
43#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 25#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
44 26
45static int tvc_connect(struct omap_dss_device *dssdev) 27static int tvc_connect(struct omap_dss_device *src,
28 struct omap_dss_device *dst)
46{ 29{
47 struct panel_drv_data *ddata = to_panel_data(dssdev);
48 struct omap_dss_device *in;
49 int r;
50
51 dev_dbg(ddata->dev, "connect\n");
52
53 if (omapdss_device_is_connected(dssdev))
54 return 0;
55
56 in = omapdss_of_find_source_for_first_ep(ddata->dev->of_node);
57 if (IS_ERR(in)) {
58 dev_err(ddata->dev, "failed to find video source\n");
59 return PTR_ERR(in);
60 }
61
62 r = in->ops.atv->connect(in, dssdev);
63 if (r) {
64 omap_dss_put_device(in);
65 return r;
66 }
67
68 ddata->in = in;
69 return 0; 30 return 0;
70} 31}
71 32
72static void tvc_disconnect(struct omap_dss_device *dssdev) 33static void tvc_disconnect(struct omap_dss_device *src,
34 struct omap_dss_device *dst)
73{ 35{
74 struct panel_drv_data *ddata = to_panel_data(dssdev);
75 struct omap_dss_device *in = ddata->in;
76
77 dev_dbg(ddata->dev, "disconnect\n");
78
79 if (!omapdss_device_is_connected(dssdev))
80 return;
81
82 in->ops.atv->disconnect(in, dssdev);
83
84 omap_dss_put_device(in);
85 ddata->in = NULL;
86} 36}
87 37
88static int tvc_enable(struct omap_dss_device *dssdev) 38static int tvc_enable(struct omap_dss_device *dssdev)
89{ 39{
90 struct panel_drv_data *ddata = to_panel_data(dssdev); 40 struct panel_drv_data *ddata = to_panel_data(dssdev);
91 struct omap_dss_device *in = ddata->in; 41 struct omap_dss_device *src = dssdev->src;
92 int r; 42 int r;
93 43
94 dev_dbg(ddata->dev, "enable\n"); 44 dev_dbg(ddata->dev, "enable\n");
@@ -99,9 +49,7 @@ static int tvc_enable(struct omap_dss_device *dssdev)
99 if (omapdss_device_is_enabled(dssdev)) 49 if (omapdss_device_is_enabled(dssdev))
100 return 0; 50 return 0;
101 51
102 in->ops.atv->set_timings(in, &ddata->vm); 52 r = src->ops->enable(src);
103
104 r = in->ops.atv->enable(in);
105 if (r) 53 if (r)
106 return r; 54 return r;
107 55
@@ -113,83 +61,30 @@ static int tvc_enable(struct omap_dss_device *dssdev)
113static void tvc_disable(struct omap_dss_device *dssdev) 61static void tvc_disable(struct omap_dss_device *dssdev)
114{ 62{
115 struct panel_drv_data *ddata = to_panel_data(dssdev); 63 struct panel_drv_data *ddata = to_panel_data(dssdev);
116 struct omap_dss_device *in = ddata->in; 64 struct omap_dss_device *src = dssdev->src;
117 65
118 dev_dbg(ddata->dev, "disable\n"); 66 dev_dbg(ddata->dev, "disable\n");
119 67
120 if (!omapdss_device_is_enabled(dssdev)) 68 if (!omapdss_device_is_enabled(dssdev))
121 return; 69 return;
122 70
123 in->ops.atv->disable(in); 71 src->ops->disable(src);
124 72
125 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 73 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
126} 74}
127 75
128static void tvc_set_timings(struct omap_dss_device *dssdev, 76static const struct omap_dss_device_ops tvc_ops = {
129 struct videomode *vm)
130{
131 struct panel_drv_data *ddata = to_panel_data(dssdev);
132 struct omap_dss_device *in = ddata->in;
133
134 ddata->vm = *vm;
135 dssdev->panel.vm = *vm;
136
137 in->ops.atv->set_timings(in, vm);
138}
139
140static void tvc_get_timings(struct omap_dss_device *dssdev,
141 struct videomode *vm)
142{
143 struct panel_drv_data *ddata = to_panel_data(dssdev);
144
145 *vm = ddata->vm;
146}
147
148static int tvc_check_timings(struct omap_dss_device *dssdev,
149 struct videomode *vm)
150{
151 struct panel_drv_data *ddata = to_panel_data(dssdev);
152 struct omap_dss_device *in = ddata->in;
153
154 return in->ops.atv->check_timings(in, vm);
155}
156
157static u32 tvc_get_wss(struct omap_dss_device *dssdev)
158{
159 struct panel_drv_data *ddata = to_panel_data(dssdev);
160 struct omap_dss_device *in = ddata->in;
161
162 return in->ops.atv->get_wss(in);
163}
164
165static int tvc_set_wss(struct omap_dss_device *dssdev, u32 wss)
166{
167 struct panel_drv_data *ddata = to_panel_data(dssdev);
168 struct omap_dss_device *in = ddata->in;
169
170 return in->ops.atv->set_wss(in, wss);
171}
172
173static struct omap_dss_driver tvc_driver = {
174 .connect = tvc_connect, 77 .connect = tvc_connect,
175 .disconnect = tvc_disconnect, 78 .disconnect = tvc_disconnect,
176 79
177 .enable = tvc_enable, 80 .enable = tvc_enable,
178 .disable = tvc_disable, 81 .disable = tvc_disable,
179
180 .set_timings = tvc_set_timings,
181 .get_timings = tvc_get_timings,
182 .check_timings = tvc_check_timings,
183
184 .get_wss = tvc_get_wss,
185 .set_wss = tvc_set_wss,
186}; 82};
187 83
188static int tvc_probe(struct platform_device *pdev) 84static int tvc_probe(struct platform_device *pdev)
189{ 85{
190 struct panel_drv_data *ddata; 86 struct panel_drv_data *ddata;
191 struct omap_dss_device *dssdev; 87 struct omap_dss_device *dssdev;
192 int r;
193 88
194 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 89 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
195 if (!ddata) 90 if (!ddata)
@@ -198,20 +93,15 @@ static int tvc_probe(struct platform_device *pdev)
198 platform_set_drvdata(pdev, ddata); 93 platform_set_drvdata(pdev, ddata);
199 ddata->dev = &pdev->dev; 94 ddata->dev = &pdev->dev;
200 95
201 ddata->vm = tvc_pal_vm;
202
203 dssdev = &ddata->dssdev; 96 dssdev = &ddata->dssdev;
204 dssdev->driver = &tvc_driver; 97 dssdev->ops = &tvc_ops;
205 dssdev->dev = &pdev->dev; 98 dssdev->dev = &pdev->dev;
206 dssdev->type = OMAP_DISPLAY_TYPE_VENC; 99 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
207 dssdev->owner = THIS_MODULE; 100 dssdev->owner = THIS_MODULE;
208 dssdev->panel.vm = tvc_pal_vm; 101 dssdev->of_ports = BIT(0);
209 102
210 r = omapdss_register_display(dssdev); 103 omapdss_display_init(dssdev);
211 if (r) { 104 omapdss_device_register(dssdev);
212 dev_err(&pdev->dev, "Failed to register panel\n");
213 return r;
214 }
215 105
216 return 0; 106 return 0;
217} 107}
@@ -221,10 +111,9 @@ static int __exit tvc_remove(struct platform_device *pdev)
221 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 111 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
222 struct omap_dss_device *dssdev = &ddata->dssdev; 112 struct omap_dss_device *dssdev = &ddata->dssdev;
223 113
224 omapdss_unregister_display(&ddata->dssdev); 114 omapdss_device_unregister(&ddata->dssdev);
225 115
226 tvc_disable(dssdev); 116 tvc_disable(dssdev);
227 tvc_disconnect(dssdev);
228 117
229 return 0; 118 return 0;
230} 119}
diff --git a/drivers/gpu/drm/omapdrm/displays/connector-dvi.c b/drivers/gpu/drm/omapdrm/displays/connector-dvi.c
index 6d8cbd9e2110..24b14f44248e 100644
--- a/drivers/gpu/drm/omapdrm/displays/connector-dvi.c
+++ b/drivers/gpu/drm/omapdrm/displays/connector-dvi.c
@@ -19,30 +19,8 @@
19 19
20#include "../dss/omapdss.h" 20#include "../dss/omapdss.h"
21 21
22static const struct videomode dvic_default_vm = {
23 .hactive = 640,
24 .vactive = 480,
25
26 .pixelclock = 23500000,
27
28 .hfront_porch = 48,
29 .hsync_len = 32,
30 .hback_porch = 80,
31
32 .vfront_porch = 3,
33 .vsync_len = 4,
34 .vback_porch = 7,
35
36 .flags = DISPLAY_FLAGS_HSYNC_HIGH | DISPLAY_FLAGS_VSYNC_HIGH |
37 DISPLAY_FLAGS_SYNC_NEGEDGE | DISPLAY_FLAGS_DE_HIGH |
38 DISPLAY_FLAGS_PIXDATA_POSEDGE,
39};
40
41struct panel_drv_data { 22struct panel_drv_data {
42 struct omap_dss_device dssdev; 23 struct omap_dss_device dssdev;
43 struct omap_dss_device *in;
44
45 struct videomode vm;
46 24
47 struct i2c_adapter *i2c_adapter; 25 struct i2c_adapter *i2c_adapter;
48 26
@@ -57,49 +35,20 @@ struct panel_drv_data {
57 35
58#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 36#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
59 37
60static int dvic_connect(struct omap_dss_device *dssdev) 38static int dvic_connect(struct omap_dss_device *src,
39 struct omap_dss_device *dst)
61{ 40{
62 struct panel_drv_data *ddata = to_panel_data(dssdev);
63 struct omap_dss_device *in;
64 int r;
65
66 if (omapdss_device_is_connected(dssdev))
67 return 0;
68
69 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
70 if (IS_ERR(in)) {
71 dev_err(dssdev->dev, "failed to find video source\n");
72 return PTR_ERR(in);
73 }
74
75 r = in->ops.dvi->connect(in, dssdev);
76 if (r) {
77 omap_dss_put_device(in);
78 return r;
79 }
80
81 ddata->in = in;
82 return 0; 41 return 0;
83} 42}
84 43
85static void dvic_disconnect(struct omap_dss_device *dssdev) 44static void dvic_disconnect(struct omap_dss_device *src,
45 struct omap_dss_device *dst)
86{ 46{
87 struct panel_drv_data *ddata = to_panel_data(dssdev);
88 struct omap_dss_device *in = ddata->in;
89
90 if (!omapdss_device_is_connected(dssdev))
91 return;
92
93 in->ops.dvi->disconnect(in, dssdev);
94
95 omap_dss_put_device(in);
96 ddata->in = NULL;
97} 47}
98 48
99static int dvic_enable(struct omap_dss_device *dssdev) 49static int dvic_enable(struct omap_dss_device *dssdev)
100{ 50{
101 struct panel_drv_data *ddata = to_panel_data(dssdev); 51 struct omap_dss_device *src = dssdev->src;
102 struct omap_dss_device *in = ddata->in;
103 int r; 52 int r;
104 53
105 if (!omapdss_device_is_connected(dssdev)) 54 if (!omapdss_device_is_connected(dssdev))
@@ -108,9 +57,7 @@ static int dvic_enable(struct omap_dss_device *dssdev)
108 if (omapdss_device_is_enabled(dssdev)) 57 if (omapdss_device_is_enabled(dssdev))
109 return 0; 58 return 0;
110 59
111 in->ops.dvi->set_timings(in, &ddata->vm); 60 r = src->ops->enable(src);
112
113 r = in->ops.dvi->enable(in);
114 if (r) 61 if (r)
115 return r; 62 return r;
116 63
@@ -121,46 +68,16 @@ static int dvic_enable(struct omap_dss_device *dssdev)
121 68
122static void dvic_disable(struct omap_dss_device *dssdev) 69static void dvic_disable(struct omap_dss_device *dssdev)
123{ 70{
124 struct panel_drv_data *ddata = to_panel_data(dssdev); 71 struct omap_dss_device *src = dssdev->src;
125 struct omap_dss_device *in = ddata->in;
126 72
127 if (!omapdss_device_is_enabled(dssdev)) 73 if (!omapdss_device_is_enabled(dssdev))
128 return; 74 return;
129 75
130 in->ops.dvi->disable(in); 76 src->ops->disable(src);
131 77
132 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 78 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
133} 79}
134 80
135static void dvic_set_timings(struct omap_dss_device *dssdev,
136 struct videomode *vm)
137{
138 struct panel_drv_data *ddata = to_panel_data(dssdev);
139 struct omap_dss_device *in = ddata->in;
140
141 ddata->vm = *vm;
142 dssdev->panel.vm = *vm;
143
144 in->ops.dvi->set_timings(in, vm);
145}
146
147static void dvic_get_timings(struct omap_dss_device *dssdev,
148 struct videomode *vm)
149{
150 struct panel_drv_data *ddata = to_panel_data(dssdev);
151
152 *vm = ddata->vm;
153}
154
155static int dvic_check_timings(struct omap_dss_device *dssdev,
156 struct videomode *vm)
157{
158 struct panel_drv_data *ddata = to_panel_data(dssdev);
159 struct omap_dss_device *in = ddata->in;
160
161 return in->ops.dvi->check_timings(in, vm);
162}
163
164static int dvic_ddc_read(struct i2c_adapter *adapter, 81static int dvic_ddc_read(struct i2c_adapter *adapter,
165 unsigned char *buf, u16 count, u8 offset) 82 unsigned char *buf, u16 count, u8 offset)
166{ 83{
@@ -198,12 +115,6 @@ static int dvic_read_edid(struct omap_dss_device *dssdev,
198 struct panel_drv_data *ddata = to_panel_data(dssdev); 115 struct panel_drv_data *ddata = to_panel_data(dssdev);
199 int r, l, bytes_read; 116 int r, l, bytes_read;
200 117
201 if (ddata->hpd_gpio && !gpiod_get_value_cansleep(ddata->hpd_gpio))
202 return -ENODEV;
203
204 if (!ddata->i2c_adapter)
205 return -ENODEV;
206
207 l = min(EDID_LENGTH, len); 118 l = min(EDID_LENGTH, len);
208 r = dvic_ddc_read(ddata->i2c_adapter, edid, l, 0); 119 r = dvic_ddc_read(ddata->i2c_adapter, edid, l, 0);
209 if (r) 120 if (r)
@@ -243,78 +154,41 @@ static bool dvic_detect(struct omap_dss_device *dssdev)
243 return r == 0; 154 return r == 0;
244} 155}
245 156
246static int dvic_register_hpd_cb(struct omap_dss_device *dssdev, 157static void dvic_register_hpd_cb(struct omap_dss_device *dssdev,
247 void (*cb)(void *cb_data, 158 void (*cb)(void *cb_data,
248 enum drm_connector_status status), 159 enum drm_connector_status status),
249 void *cb_data) 160 void *cb_data)
250{ 161{
251 struct panel_drv_data *ddata = to_panel_data(dssdev); 162 struct panel_drv_data *ddata = to_panel_data(dssdev);
252 163
253 if (!ddata->hpd_gpio)
254 return -ENOTSUPP;
255
256 mutex_lock(&ddata->hpd_lock); 164 mutex_lock(&ddata->hpd_lock);
257 ddata->hpd_cb = cb; 165 ddata->hpd_cb = cb;
258 ddata->hpd_cb_data = cb_data; 166 ddata->hpd_cb_data = cb_data;
259 mutex_unlock(&ddata->hpd_lock); 167 mutex_unlock(&ddata->hpd_lock);
260 return 0;
261} 168}
262 169
263static void dvic_unregister_hpd_cb(struct omap_dss_device *dssdev) 170static void dvic_unregister_hpd_cb(struct omap_dss_device *dssdev)
264{ 171{
265 struct panel_drv_data *ddata = to_panel_data(dssdev); 172 struct panel_drv_data *ddata = to_panel_data(dssdev);
266 173
267 if (!ddata->hpd_gpio)
268 return;
269
270 mutex_lock(&ddata->hpd_lock); 174 mutex_lock(&ddata->hpd_lock);
271 ddata->hpd_cb = NULL; 175 ddata->hpd_cb = NULL;
272 ddata->hpd_cb_data = NULL; 176 ddata->hpd_cb_data = NULL;
273 mutex_unlock(&ddata->hpd_lock); 177 mutex_unlock(&ddata->hpd_lock);
274} 178}
275 179
276static void dvic_enable_hpd(struct omap_dss_device *dssdev) 180static const struct omap_dss_device_ops dvic_ops = {
277{
278 struct panel_drv_data *ddata = to_panel_data(dssdev);
279
280 if (!ddata->hpd_gpio)
281 return;
282
283 mutex_lock(&ddata->hpd_lock);
284 ddata->hpd_enabled = true;
285 mutex_unlock(&ddata->hpd_lock);
286}
287
288static void dvic_disable_hpd(struct omap_dss_device *dssdev)
289{
290 struct panel_drv_data *ddata = to_panel_data(dssdev);
291
292 if (!ddata->hpd_gpio)
293 return;
294
295 mutex_lock(&ddata->hpd_lock);
296 ddata->hpd_enabled = false;
297 mutex_unlock(&ddata->hpd_lock);
298}
299
300static struct omap_dss_driver dvic_driver = {
301 .connect = dvic_connect, 181 .connect = dvic_connect,
302 .disconnect = dvic_disconnect, 182 .disconnect = dvic_disconnect,
303 183
304 .enable = dvic_enable, 184 .enable = dvic_enable,
305 .disable = dvic_disable, 185 .disable = dvic_disable,
306 186
307 .set_timings = dvic_set_timings,
308 .get_timings = dvic_get_timings,
309 .check_timings = dvic_check_timings,
310
311 .read_edid = dvic_read_edid, 187 .read_edid = dvic_read_edid,
312 .detect = dvic_detect, 188 .detect = dvic_detect,
313 189
314 .register_hpd_cb = dvic_register_hpd_cb, 190 .register_hpd_cb = dvic_register_hpd_cb,
315 .unregister_hpd_cb = dvic_unregister_hpd_cb, 191 .unregister_hpd_cb = dvic_unregister_hpd_cb,
316 .enable_hpd = dvic_enable_hpd,
317 .disable_hpd = dvic_disable_hpd,
318}; 192};
319 193
320static irqreturn_t dvic_hpd_isr(int irq, void *data) 194static irqreturn_t dvic_hpd_isr(int irq, void *data)
@@ -396,28 +270,24 @@ static int dvic_probe(struct platform_device *pdev)
396 if (r) 270 if (r)
397 return r; 271 return r;
398 272
399 ddata->vm = dvic_default_vm;
400
401 dssdev = &ddata->dssdev; 273 dssdev = &ddata->dssdev;
402 dssdev->driver = &dvic_driver; 274 dssdev->ops = &dvic_ops;
403 dssdev->dev = &pdev->dev; 275 dssdev->dev = &pdev->dev;
404 dssdev->type = OMAP_DISPLAY_TYPE_DVI; 276 dssdev->type = OMAP_DISPLAY_TYPE_DVI;
405 dssdev->owner = THIS_MODULE; 277 dssdev->owner = THIS_MODULE;
406 dssdev->panel.vm = dvic_default_vm; 278 dssdev->of_ports = BIT(0);
407 279
408 r = omapdss_register_display(dssdev); 280 if (ddata->hpd_gpio)
409 if (r) { 281 dssdev->ops_flags |= OMAP_DSS_DEVICE_OP_DETECT
410 dev_err(&pdev->dev, "Failed to register panel\n"); 282 | OMAP_DSS_DEVICE_OP_HPD;
411 goto err_reg; 283 if (ddata->i2c_adapter)
412 } 284 dssdev->ops_flags |= OMAP_DSS_DEVICE_OP_DETECT
413 285 | OMAP_DSS_DEVICE_OP_EDID;
414 return 0;
415 286
416err_reg: 287 omapdss_display_init(dssdev);
417 i2c_put_adapter(ddata->i2c_adapter); 288 omapdss_device_register(dssdev);
418 mutex_destroy(&ddata->hpd_lock);
419 289
420 return r; 290 return 0;
421} 291}
422 292
423static int __exit dvic_remove(struct platform_device *pdev) 293static int __exit dvic_remove(struct platform_device *pdev)
@@ -425,10 +295,9 @@ static int __exit dvic_remove(struct platform_device *pdev)
425 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 295 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
426 struct omap_dss_device *dssdev = &ddata->dssdev; 296 struct omap_dss_device *dssdev = &ddata->dssdev;
427 297
428 omapdss_unregister_display(&ddata->dssdev); 298 omapdss_device_unregister(&ddata->dssdev);
429 299
430 dvic_disable(dssdev); 300 dvic_disable(dssdev);
431 dvic_disconnect(dssdev);
432 301
433 i2c_put_adapter(ddata->i2c_adapter); 302 i2c_put_adapter(ddata->i2c_adapter);
434 303
diff --git a/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c b/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
index ca30ed9da7eb..e602fa4a50a4 100644
--- a/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
+++ b/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
@@ -10,95 +10,41 @@
10 */ 10 */
11 11
12#include <linux/gpio/consumer.h> 12#include <linux/gpio/consumer.h>
13#include <linux/slab.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/of.h>
17#include <linux/of_gpio.h>
18#include <linux/mutex.h> 14#include <linux/mutex.h>
19 15#include <linux/platform_device.h>
20#include <drm/drm_edid.h> 16#include <linux/slab.h>
21 17
22#include "../dss/omapdss.h" 18#include "../dss/omapdss.h"
23 19
24static const struct videomode hdmic_default_vm = {
25 .hactive = 640,
26 .vactive = 480,
27 .pixelclock = 25175000,
28 .hsync_len = 96,
29 .hfront_porch = 16,
30 .hback_porch = 48,
31 .vsync_len = 2,
32 .vfront_porch = 11,
33 .vback_porch = 31,
34
35 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
36};
37
38struct panel_drv_data { 20struct panel_drv_data {
39 struct omap_dss_device dssdev; 21 struct omap_dss_device dssdev;
40 struct omap_dss_device *in;
41 void (*hpd_cb)(void *cb_data, enum drm_connector_status status); 22 void (*hpd_cb)(void *cb_data, enum drm_connector_status status);
42 void *hpd_cb_data; 23 void *hpd_cb_data;
43 bool hpd_enabled;
44 struct mutex hpd_lock; 24 struct mutex hpd_lock;
45 25
46 struct device *dev; 26 struct device *dev;
47 27
48 struct videomode vm; 28 struct gpio_desc *hpd_gpio;
49
50 int hpd_gpio;
51}; 29};
52 30
53#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 31#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
54 32
55static int hdmic_connect(struct omap_dss_device *dssdev) 33static int hdmic_connect(struct omap_dss_device *src,
34 struct omap_dss_device *dst)
56{ 35{
57 struct panel_drv_data *ddata = to_panel_data(dssdev);
58 struct omap_dss_device *in;
59 int r;
60
61 dev_dbg(ddata->dev, "connect\n");
62
63 if (omapdss_device_is_connected(dssdev))
64 return 0;
65
66 in = omapdss_of_find_source_for_first_ep(ddata->dev->of_node);
67 if (IS_ERR(in)) {
68 dev_err(ddata->dev, "failed to find video source\n");
69 return PTR_ERR(in);
70 }
71
72 r = in->ops.hdmi->connect(in, dssdev);
73 if (r) {
74 omap_dss_put_device(in);
75 return r;
76 }
77
78 ddata->in = in;
79 return 0; 36 return 0;
80} 37}
81 38
82static void hdmic_disconnect(struct omap_dss_device *dssdev) 39static void hdmic_disconnect(struct omap_dss_device *src,
40 struct omap_dss_device *dst)
83{ 41{
84 struct panel_drv_data *ddata = to_panel_data(dssdev);
85 struct omap_dss_device *in = ddata->in;
86
87 dev_dbg(ddata->dev, "disconnect\n");
88
89 if (!omapdss_device_is_connected(dssdev))
90 return;
91
92 in->ops.hdmi->disconnect(in, dssdev);
93
94 omap_dss_put_device(in);
95 ddata->in = NULL;
96} 42}
97 43
98static int hdmic_enable(struct omap_dss_device *dssdev) 44static int hdmic_enable(struct omap_dss_device *dssdev)
99{ 45{
100 struct panel_drv_data *ddata = to_panel_data(dssdev); 46 struct panel_drv_data *ddata = to_panel_data(dssdev);
101 struct omap_dss_device *in = ddata->in; 47 struct omap_dss_device *src = dssdev->src;
102 int r; 48 int r;
103 49
104 dev_dbg(ddata->dev, "enable\n"); 50 dev_dbg(ddata->dev, "enable\n");
@@ -109,9 +55,7 @@ static int hdmic_enable(struct omap_dss_device *dssdev)
109 if (omapdss_device_is_enabled(dssdev)) 55 if (omapdss_device_is_enabled(dssdev))
110 return 0; 56 return 0;
111 57
112 in->ops.hdmi->set_timings(in, &ddata->vm); 58 r = src->ops->enable(src);
113
114 r = in->ops.hdmi->enable(in);
115 if (r) 59 if (r)
116 return r; 60 return r;
117 61
@@ -123,171 +67,58 @@ static int hdmic_enable(struct omap_dss_device *dssdev)
123static void hdmic_disable(struct omap_dss_device *dssdev) 67static void hdmic_disable(struct omap_dss_device *dssdev)
124{ 68{
125 struct panel_drv_data *ddata = to_panel_data(dssdev); 69 struct panel_drv_data *ddata = to_panel_data(dssdev);
126 struct omap_dss_device *in = ddata->in; 70 struct omap_dss_device *src = dssdev->src;
127 71
128 dev_dbg(ddata->dev, "disable\n"); 72 dev_dbg(ddata->dev, "disable\n");
129 73
130 if (!omapdss_device_is_enabled(dssdev)) 74 if (!omapdss_device_is_enabled(dssdev))
131 return; 75 return;
132 76
133 in->ops.hdmi->disable(in); 77 src->ops->disable(src);
134 78
135 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 79 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
136} 80}
137 81
138static void hdmic_set_timings(struct omap_dss_device *dssdev,
139 struct videomode *vm)
140{
141 struct panel_drv_data *ddata = to_panel_data(dssdev);
142 struct omap_dss_device *in = ddata->in;
143
144 ddata->vm = *vm;
145 dssdev->panel.vm = *vm;
146
147 in->ops.hdmi->set_timings(in, vm);
148}
149
150static void hdmic_get_timings(struct omap_dss_device *dssdev,
151 struct videomode *vm)
152{
153 struct panel_drv_data *ddata = to_panel_data(dssdev);
154
155 *vm = ddata->vm;
156}
157
158static int hdmic_check_timings(struct omap_dss_device *dssdev,
159 struct videomode *vm)
160{
161 struct panel_drv_data *ddata = to_panel_data(dssdev);
162 struct omap_dss_device *in = ddata->in;
163
164 return in->ops.hdmi->check_timings(in, vm);
165}
166
167static int hdmic_read_edid(struct omap_dss_device *dssdev,
168 u8 *edid, int len)
169{
170 struct panel_drv_data *ddata = to_panel_data(dssdev);
171 struct omap_dss_device *in = ddata->in;
172
173 return in->ops.hdmi->read_edid(in, edid, len);
174}
175
176static bool hdmic_detect(struct omap_dss_device *dssdev) 82static bool hdmic_detect(struct omap_dss_device *dssdev)
177{ 83{
178 struct panel_drv_data *ddata = to_panel_data(dssdev); 84 struct panel_drv_data *ddata = to_panel_data(dssdev);
179 struct omap_dss_device *in = ddata->in; 85
180 bool connected; 86 return gpiod_get_value_cansleep(ddata->hpd_gpio);
181
182 if (gpio_is_valid(ddata->hpd_gpio))
183 connected = gpio_get_value_cansleep(ddata->hpd_gpio);
184 else
185 connected = in->ops.hdmi->detect(in);
186 if (!connected && in->ops.hdmi->lost_hotplug)
187 in->ops.hdmi->lost_hotplug(in);
188 return connected;
189} 87}
190 88
191static int hdmic_register_hpd_cb(struct omap_dss_device *dssdev, 89static void hdmic_register_hpd_cb(struct omap_dss_device *dssdev,
192 void (*cb)(void *cb_data, 90 void (*cb)(void *cb_data,
193 enum drm_connector_status status), 91 enum drm_connector_status status),
194 void *cb_data) 92 void *cb_data)
195{ 93{
196 struct panel_drv_data *ddata = to_panel_data(dssdev); 94 struct panel_drv_data *ddata = to_panel_data(dssdev);
197 struct omap_dss_device *in = ddata->in;
198
199 if (gpio_is_valid(ddata->hpd_gpio)) {
200 mutex_lock(&ddata->hpd_lock);
201 ddata->hpd_cb = cb;
202 ddata->hpd_cb_data = cb_data;
203 mutex_unlock(&ddata->hpd_lock);
204 return 0;
205 } else if (in->ops.hdmi->register_hpd_cb) {
206 return in->ops.hdmi->register_hpd_cb(in, cb, cb_data);
207 }
208 95
209 return -ENOTSUPP; 96 mutex_lock(&ddata->hpd_lock);
97 ddata->hpd_cb = cb;
98 ddata->hpd_cb_data = cb_data;
99 mutex_unlock(&ddata->hpd_lock);
210} 100}
211 101
212static void hdmic_unregister_hpd_cb(struct omap_dss_device *dssdev) 102static void hdmic_unregister_hpd_cb(struct omap_dss_device *dssdev)
213{ 103{
214 struct panel_drv_data *ddata = to_panel_data(dssdev); 104 struct panel_drv_data *ddata = to_panel_data(dssdev);
215 struct omap_dss_device *in = ddata->in;
216
217 if (gpio_is_valid(ddata->hpd_gpio)) {
218 mutex_lock(&ddata->hpd_lock);
219 ddata->hpd_cb = NULL;
220 ddata->hpd_cb_data = NULL;
221 mutex_unlock(&ddata->hpd_lock);
222 } else if (in->ops.hdmi->unregister_hpd_cb) {
223 in->ops.hdmi->unregister_hpd_cb(in);
224 }
225}
226
227static void hdmic_enable_hpd(struct omap_dss_device *dssdev)
228{
229 struct panel_drv_data *ddata = to_panel_data(dssdev);
230 struct omap_dss_device *in = ddata->in;
231
232 if (gpio_is_valid(ddata->hpd_gpio)) {
233 mutex_lock(&ddata->hpd_lock);
234 ddata->hpd_enabled = true;
235 mutex_unlock(&ddata->hpd_lock);
236 } else if (in->ops.hdmi->enable_hpd) {
237 in->ops.hdmi->enable_hpd(in);
238 }
239}
240
241static void hdmic_disable_hpd(struct omap_dss_device *dssdev)
242{
243 struct panel_drv_data *ddata = to_panel_data(dssdev);
244 struct omap_dss_device *in = ddata->in;
245
246 if (gpio_is_valid(ddata->hpd_gpio)) {
247 mutex_lock(&ddata->hpd_lock);
248 ddata->hpd_enabled = false;
249 mutex_unlock(&ddata->hpd_lock);
250 } else if (in->ops.hdmi->disable_hpd) {
251 in->ops.hdmi->disable_hpd(in);
252 }
253}
254
255static int hdmic_set_hdmi_mode(struct omap_dss_device *dssdev, bool hdmi_mode)
256{
257 struct panel_drv_data *ddata = to_panel_data(dssdev);
258 struct omap_dss_device *in = ddata->in;
259
260 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
261}
262
263static int hdmic_set_infoframe(struct omap_dss_device *dssdev,
264 const struct hdmi_avi_infoframe *avi)
265{
266 struct panel_drv_data *ddata = to_panel_data(dssdev);
267 struct omap_dss_device *in = ddata->in;
268 105
269 return in->ops.hdmi->set_infoframe(in, avi); 106 mutex_lock(&ddata->hpd_lock);
107 ddata->hpd_cb = NULL;
108 ddata->hpd_cb_data = NULL;
109 mutex_unlock(&ddata->hpd_lock);
270} 110}
271 111
272static struct omap_dss_driver hdmic_driver = { 112static const struct omap_dss_device_ops hdmic_ops = {
273 .connect = hdmic_connect, 113 .connect = hdmic_connect,
274 .disconnect = hdmic_disconnect, 114 .disconnect = hdmic_disconnect,
275 115
276 .enable = hdmic_enable, 116 .enable = hdmic_enable,
277 .disable = hdmic_disable, 117 .disable = hdmic_disable,
278 118
279 .set_timings = hdmic_set_timings,
280 .get_timings = hdmic_get_timings,
281 .check_timings = hdmic_check_timings,
282
283 .read_edid = hdmic_read_edid,
284 .detect = hdmic_detect, 119 .detect = hdmic_detect,
285 .register_hpd_cb = hdmic_register_hpd_cb, 120 .register_hpd_cb = hdmic_register_hpd_cb,
286 .unregister_hpd_cb = hdmic_unregister_hpd_cb, 121 .unregister_hpd_cb = hdmic_unregister_hpd_cb,
287 .enable_hpd = hdmic_enable_hpd,
288 .disable_hpd = hdmic_disable_hpd,
289 .set_hdmi_mode = hdmic_set_hdmi_mode,
290 .set_hdmi_infoframe = hdmic_set_infoframe,
291}; 122};
292 123
293static irqreturn_t hdmic_hpd_isr(int irq, void *data) 124static irqreturn_t hdmic_hpd_isr(int irq, void *data)
@@ -295,7 +126,7 @@ static irqreturn_t hdmic_hpd_isr(int irq, void *data)
295 struct panel_drv_data *ddata = data; 126 struct panel_drv_data *ddata = data;
296 127
297 mutex_lock(&ddata->hpd_lock); 128 mutex_lock(&ddata->hpd_lock);
298 if (ddata->hpd_enabled && ddata->hpd_cb) { 129 if (ddata->hpd_cb) {
299 enum drm_connector_status status; 130 enum drm_connector_status status;
300 131
301 if (hdmic_detect(&ddata->dssdev)) 132 if (hdmic_detect(&ddata->dssdev))
@@ -310,26 +141,11 @@ static irqreturn_t hdmic_hpd_isr(int irq, void *data)
310 return IRQ_HANDLED; 141 return IRQ_HANDLED;
311} 142}
312 143
313static int hdmic_probe_of(struct platform_device *pdev)
314{
315 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
316 struct device_node *node = pdev->dev.of_node;
317 int gpio;
318
319 /* HPD GPIO */
320 gpio = of_get_named_gpio(node, "hpd-gpios", 0);
321 if (gpio_is_valid(gpio))
322 ddata->hpd_gpio = gpio;
323 else
324 ddata->hpd_gpio = -ENODEV;
325
326 return 0;
327}
328
329static int hdmic_probe(struct platform_device *pdev) 144static int hdmic_probe(struct platform_device *pdev)
330{ 145{
331 struct panel_drv_data *ddata; 146 struct panel_drv_data *ddata;
332 struct omap_dss_device *dssdev; 147 struct omap_dss_device *dssdev;
148 struct gpio_desc *gpio;
333 int r; 149 int r;
334 150
335 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 151 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
@@ -339,20 +155,20 @@ static int hdmic_probe(struct platform_device *pdev)
339 platform_set_drvdata(pdev, ddata); 155 platform_set_drvdata(pdev, ddata);
340 ddata->dev = &pdev->dev; 156 ddata->dev = &pdev->dev;
341 157
342 r = hdmic_probe_of(pdev);
343 if (r)
344 return r;
345
346 mutex_init(&ddata->hpd_lock); 158 mutex_init(&ddata->hpd_lock);
347 159
348 if (gpio_is_valid(ddata->hpd_gpio)) { 160 /* HPD GPIO */
349 r = devm_gpio_request_one(&pdev->dev, ddata->hpd_gpio, 161 gpio = devm_gpiod_get_optional(&pdev->dev, "hpd", GPIOD_IN);
350 GPIOF_DIR_IN, "hdmi_hpd"); 162 if (IS_ERR(gpio)) {
351 if (r) 163 dev_err(&pdev->dev, "failed to parse HPD gpio\n");
352 return r; 164 return PTR_ERR(gpio);
165 }
166
167 ddata->hpd_gpio = gpio;
353 168
169 if (ddata->hpd_gpio) {
354 r = devm_request_threaded_irq(&pdev->dev, 170 r = devm_request_threaded_irq(&pdev->dev,
355 gpio_to_irq(ddata->hpd_gpio), 171 gpiod_to_irq(ddata->hpd_gpio),
356 NULL, hdmic_hpd_isr, 172 NULL, hdmic_hpd_isr,
357 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | 173 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
358 IRQF_ONESHOT, 174 IRQF_ONESHOT,
@@ -361,20 +177,18 @@ static int hdmic_probe(struct platform_device *pdev)
361 return r; 177 return r;
362 } 178 }
363 179
364 ddata->vm = hdmic_default_vm;
365
366 dssdev = &ddata->dssdev; 180 dssdev = &ddata->dssdev;
367 dssdev->driver = &hdmic_driver; 181 dssdev->ops = &hdmic_ops;
368 dssdev->dev = &pdev->dev; 182 dssdev->dev = &pdev->dev;
369 dssdev->type = OMAP_DISPLAY_TYPE_HDMI; 183 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
370 dssdev->owner = THIS_MODULE; 184 dssdev->owner = THIS_MODULE;
371 dssdev->panel.vm = hdmic_default_vm; 185 dssdev->of_ports = BIT(0);
186 dssdev->ops_flags = ddata->hpd_gpio
187 ? OMAP_DSS_DEVICE_OP_DETECT | OMAP_DSS_DEVICE_OP_HPD
188 : 0;
372 189
373 r = omapdss_register_display(dssdev); 190 omapdss_display_init(dssdev);
374 if (r) { 191 omapdss_device_register(dssdev);
375 dev_err(&pdev->dev, "Failed to register panel\n");
376 return r;
377 }
378 192
379 return 0; 193 return 0;
380} 194}
@@ -384,10 +198,9 @@ static int __exit hdmic_remove(struct platform_device *pdev)
384 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 198 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
385 struct omap_dss_device *dssdev = &ddata->dssdev; 199 struct omap_dss_device *dssdev = &ddata->dssdev;
386 200
387 omapdss_unregister_display(&ddata->dssdev); 201 omapdss_device_unregister(&ddata->dssdev);
388 202
389 hdmic_disable(dssdev); 203 hdmic_disable(dssdev);
390 hdmic_disconnect(dssdev);
391 204
392 return 0; 205 return 0;
393} 206}
diff --git a/drivers/gpu/drm/omapdrm/displays/encoder-opa362.c b/drivers/gpu/drm/omapdrm/displays/encoder-opa362.c
index afee1b8b457a..4fefd80f53bb 100644
--- a/drivers/gpu/drm/omapdrm/displays/encoder-opa362.c
+++ b/drivers/gpu/drm/omapdrm/displays/encoder-opa362.c
@@ -23,75 +23,28 @@
23 23
24struct panel_drv_data { 24struct panel_drv_data {
25 struct omap_dss_device dssdev; 25 struct omap_dss_device dssdev;
26 struct omap_dss_device *in;
27 26
28 struct gpio_desc *enable_gpio; 27 struct gpio_desc *enable_gpio;
29
30 struct videomode vm;
31}; 28};
32 29
33#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 30#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
34 31
35static int opa362_connect(struct omap_dss_device *dssdev, 32static int opa362_connect(struct omap_dss_device *src,
36 struct omap_dss_device *dst) 33 struct omap_dss_device *dst)
37{ 34{
38 struct panel_drv_data *ddata = to_panel_data(dssdev); 35 return omapdss_device_connect(dst->dss, dst, dst->next);
39 struct omap_dss_device *in;
40 int r;
41
42 dev_dbg(dssdev->dev, "connect\n");
43
44 if (omapdss_device_is_connected(dssdev))
45 return -EBUSY;
46
47 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
48 if (IS_ERR(in)) {
49 dev_err(dssdev->dev, "failed to find video source\n");
50 return PTR_ERR(in);
51 }
52
53 r = in->ops.atv->connect(in, dssdev);
54 if (r) {
55 omap_dss_put_device(in);
56 return r;
57 }
58
59 dst->src = dssdev;
60 dssdev->dst = dst;
61
62 ddata->in = in;
63 return 0;
64} 36}
65 37
66static void opa362_disconnect(struct omap_dss_device *dssdev, 38static void opa362_disconnect(struct omap_dss_device *src,
67 struct omap_dss_device *dst) 39 struct omap_dss_device *dst)
68{ 40{
69 struct panel_drv_data *ddata = to_panel_data(dssdev); 41 omapdss_device_disconnect(dst, dst->next);
70 struct omap_dss_device *in = ddata->in;
71
72 dev_dbg(dssdev->dev, "disconnect\n");
73
74 WARN_ON(!omapdss_device_is_connected(dssdev));
75 if (!omapdss_device_is_connected(dssdev))
76 return;
77
78 WARN_ON(dst != dssdev->dst);
79 if (dst != dssdev->dst)
80 return;
81
82 dst->src = NULL;
83 dssdev->dst = NULL;
84
85 in->ops.atv->disconnect(in, &ddata->dssdev);
86
87 omap_dss_put_device(in);
88 ddata->in = NULL;
89} 42}
90 43
91static int opa362_enable(struct omap_dss_device *dssdev) 44static int opa362_enable(struct omap_dss_device *dssdev)
92{ 45{
93 struct panel_drv_data *ddata = to_panel_data(dssdev); 46 struct panel_drv_data *ddata = to_panel_data(dssdev);
94 struct omap_dss_device *in = ddata->in; 47 struct omap_dss_device *src = dssdev->src;
95 int r; 48 int r;
96 49
97 dev_dbg(dssdev->dev, "enable\n"); 50 dev_dbg(dssdev->dev, "enable\n");
@@ -102,9 +55,7 @@ static int opa362_enable(struct omap_dss_device *dssdev)
102 if (omapdss_device_is_enabled(dssdev)) 55 if (omapdss_device_is_enabled(dssdev))
103 return 0; 56 return 0;
104 57
105 in->ops.atv->set_timings(in, &ddata->vm); 58 r = src->ops->enable(src);
106
107 r = in->ops.atv->enable(in);
108 if (r) 59 if (r)
109 return r; 60 return r;
110 61
@@ -119,7 +70,7 @@ static int opa362_enable(struct omap_dss_device *dssdev)
119static void opa362_disable(struct omap_dss_device *dssdev) 70static void opa362_disable(struct omap_dss_device *dssdev)
120{ 71{
121 struct panel_drv_data *ddata = to_panel_data(dssdev); 72 struct panel_drv_data *ddata = to_panel_data(dssdev);
122 struct omap_dss_device *in = ddata->in; 73 struct omap_dss_device *src = dssdev->src;
123 74
124 dev_dbg(dssdev->dev, "disable\n"); 75 dev_dbg(dssdev->dev, "disable\n");
125 76
@@ -129,56 +80,16 @@ static void opa362_disable(struct omap_dss_device *dssdev)
129 if (ddata->enable_gpio) 80 if (ddata->enable_gpio)
130 gpiod_set_value_cansleep(ddata->enable_gpio, 0); 81 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
131 82
132 in->ops.atv->disable(in); 83 src->ops->disable(src);
133 84
134 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 85 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
135} 86}
136 87
137static void opa362_set_timings(struct omap_dss_device *dssdev, 88static const struct omap_dss_device_ops opa362_ops = {
138 struct videomode *vm)
139{
140 struct panel_drv_data *ddata = to_panel_data(dssdev);
141 struct omap_dss_device *in = ddata->in;
142
143 dev_dbg(dssdev->dev, "set_timings\n");
144
145 ddata->vm = *vm;
146 dssdev->panel.vm = *vm;
147
148 in->ops.atv->set_timings(in, vm);
149}
150
151static void opa362_get_timings(struct omap_dss_device *dssdev,
152 struct videomode *vm)
153{
154 struct panel_drv_data *ddata = to_panel_data(dssdev);
155
156 dev_dbg(dssdev->dev, "get_timings\n");
157
158 *vm = ddata->vm;
159}
160
161static int opa362_check_timings(struct omap_dss_device *dssdev,
162 struct videomode *vm)
163{
164 struct panel_drv_data *ddata = to_panel_data(dssdev);
165 struct omap_dss_device *in = ddata->in;
166
167 dev_dbg(dssdev->dev, "check_timings\n");
168
169 return in->ops.atv->check_timings(in, vm);
170}
171
172static const struct omapdss_atv_ops opa362_atv_ops = {
173 .connect = opa362_connect, 89 .connect = opa362_connect,
174 .disconnect = opa362_disconnect, 90 .disconnect = opa362_disconnect,
175
176 .enable = opa362_enable, 91 .enable = opa362_enable,
177 .disable = opa362_disable, 92 .disable = opa362_disable,
178
179 .check_timings = opa362_check_timings,
180 .set_timings = opa362_set_timings,
181 .get_timings = opa362_get_timings,
182}; 93};
183 94
184static int opa362_probe(struct platform_device *pdev) 95static int opa362_probe(struct platform_device *pdev)
@@ -186,7 +97,6 @@ static int opa362_probe(struct platform_device *pdev)
186 struct panel_drv_data *ddata; 97 struct panel_drv_data *ddata;
187 struct omap_dss_device *dssdev; 98 struct omap_dss_device *dssdev;
188 struct gpio_desc *gpio; 99 struct gpio_desc *gpio;
189 int r;
190 100
191 dev_dbg(&pdev->dev, "probe\n"); 101 dev_dbg(&pdev->dev, "probe\n");
192 102
@@ -203,18 +113,22 @@ static int opa362_probe(struct platform_device *pdev)
203 ddata->enable_gpio = gpio; 113 ddata->enable_gpio = gpio;
204 114
205 dssdev = &ddata->dssdev; 115 dssdev = &ddata->dssdev;
206 dssdev->ops.atv = &opa362_atv_ops; 116 dssdev->ops = &opa362_ops;
207 dssdev->dev = &pdev->dev; 117 dssdev->dev = &pdev->dev;
208 dssdev->type = OMAP_DISPLAY_TYPE_VENC; 118 dssdev->type = OMAP_DISPLAY_TYPE_VENC;
209 dssdev->output_type = OMAP_DISPLAY_TYPE_VENC; 119 dssdev->output_type = OMAP_DISPLAY_TYPE_VENC;
210 dssdev->owner = THIS_MODULE; 120 dssdev->owner = THIS_MODULE;
121 dssdev->of_ports = BIT(1) | BIT(0);
211 122
212 r = omapdss_register_output(dssdev); 123 dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
213 if (r) { 124 if (IS_ERR(dssdev->next)) {
214 dev_err(&pdev->dev, "Failed to register output\n"); 125 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
215 return r; 126 dev_err(&pdev->dev, "failed to find video sink\n");
127 return PTR_ERR(dssdev->next);
216 } 128 }
217 129
130 omapdss_device_register(dssdev);
131
218 return 0; 132 return 0;
219} 133}
220 134
@@ -223,7 +137,9 @@ static int __exit opa362_remove(struct platform_device *pdev)
223 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 137 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
224 struct omap_dss_device *dssdev = &ddata->dssdev; 138 struct omap_dss_device *dssdev = &ddata->dssdev;
225 139
226 omapdss_unregister_output(&ddata->dssdev); 140 if (dssdev->next)
141 omapdss_device_put(dssdev->next);
142 omapdss_device_unregister(&ddata->dssdev);
227 143
228 WARN_ON(omapdss_device_is_enabled(dssdev)); 144 WARN_ON(omapdss_device_is_enabled(dssdev));
229 if (omapdss_device_is_enabled(dssdev)) 145 if (omapdss_device_is_enabled(dssdev))
@@ -231,7 +147,7 @@ static int __exit opa362_remove(struct platform_device *pdev)
231 147
232 WARN_ON(omapdss_device_is_connected(dssdev)); 148 WARN_ON(omapdss_device_is_connected(dssdev));
233 if (omapdss_device_is_connected(dssdev)) 149 if (omapdss_device_is_connected(dssdev))
234 opa362_disconnect(dssdev, dssdev->dst); 150 omapdss_device_disconnect(NULL, dssdev);
235 151
236 return 0; 152 return 0;
237} 153}
diff --git a/drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c b/drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
index ed7ae384c3ed..f1a748353279 100644
--- a/drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
+++ b/drivers/gpu/drm/omapdrm/displays/encoder-tfp410.c
@@ -13,77 +13,33 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/of_gpio.h>
17 16
18#include "../dss/omapdss.h" 17#include "../dss/omapdss.h"
19 18
20struct panel_drv_data { 19struct panel_drv_data {
21 struct omap_dss_device dssdev; 20 struct omap_dss_device dssdev;
22 struct omap_dss_device *in;
23 21
24 int pd_gpio; 22 struct gpio_desc *pd_gpio;
25
26 struct videomode vm;
27}; 23};
28 24
29#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 25#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
30 26
31static int tfp410_connect(struct omap_dss_device *dssdev, 27static int tfp410_connect(struct omap_dss_device *src,
32 struct omap_dss_device *dst) 28 struct omap_dss_device *dst)
33{ 29{
34 struct panel_drv_data *ddata = to_panel_data(dssdev); 30 return omapdss_device_connect(dst->dss, dst, dst->next);
35 struct omap_dss_device *in;
36 int r;
37
38 if (omapdss_device_is_connected(dssdev))
39 return -EBUSY;
40
41 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
42 if (IS_ERR(in)) {
43 dev_err(dssdev->dev, "failed to find video source\n");
44 return PTR_ERR(in);
45 }
46
47 r = in->ops.dpi->connect(in, dssdev);
48 if (r) {
49 omap_dss_put_device(in);
50 return r;
51 }
52
53 dst->src = dssdev;
54 dssdev->dst = dst;
55
56 ddata->in = in;
57 return 0;
58} 31}
59 32
60static void tfp410_disconnect(struct omap_dss_device *dssdev, 33static void tfp410_disconnect(struct omap_dss_device *src,
61 struct omap_dss_device *dst) 34 struct omap_dss_device *dst)
62{ 35{
63 struct panel_drv_data *ddata = to_panel_data(dssdev); 36 omapdss_device_disconnect(dst, dst->next);
64 struct omap_dss_device *in = ddata->in;
65
66 WARN_ON(!omapdss_device_is_connected(dssdev));
67 if (!omapdss_device_is_connected(dssdev))
68 return;
69
70 WARN_ON(dst != dssdev->dst);
71 if (dst != dssdev->dst)
72 return;
73
74 dst->src = NULL;
75 dssdev->dst = NULL;
76
77 in->ops.dpi->disconnect(in, &ddata->dssdev);
78
79 omap_dss_put_device(in);
80 ddata->in = NULL;
81} 37}
82 38
83static int tfp410_enable(struct omap_dss_device *dssdev) 39static int tfp410_enable(struct omap_dss_device *dssdev)
84{ 40{
85 struct panel_drv_data *ddata = to_panel_data(dssdev); 41 struct panel_drv_data *ddata = to_panel_data(dssdev);
86 struct omap_dss_device *in = ddata->in; 42 struct omap_dss_device *src = dssdev->src;
87 int r; 43 int r;
88 44
89 if (!omapdss_device_is_connected(dssdev)) 45 if (!omapdss_device_is_connected(dssdev))
@@ -92,14 +48,12 @@ static int tfp410_enable(struct omap_dss_device *dssdev)
92 if (omapdss_device_is_enabled(dssdev)) 48 if (omapdss_device_is_enabled(dssdev))
93 return 0; 49 return 0;
94 50
95 in->ops.dpi->set_timings(in, &ddata->vm); 51 r = src->ops->enable(src);
96
97 r = in->ops.dpi->enable(in);
98 if (r) 52 if (r)
99 return r; 53 return r;
100 54
101 if (gpio_is_valid(ddata->pd_gpio)) 55 if (ddata->pd_gpio)
102 gpio_set_value_cansleep(ddata->pd_gpio, 1); 56 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
103 57
104 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 58 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
105 59
@@ -109,94 +63,31 @@ static int tfp410_enable(struct omap_dss_device *dssdev)
109static void tfp410_disable(struct omap_dss_device *dssdev) 63static void tfp410_disable(struct omap_dss_device *dssdev)
110{ 64{
111 struct panel_drv_data *ddata = to_panel_data(dssdev); 65 struct panel_drv_data *ddata = to_panel_data(dssdev);
112 struct omap_dss_device *in = ddata->in; 66 struct omap_dss_device *src = dssdev->src;
113 67
114 if (!omapdss_device_is_enabled(dssdev)) 68 if (!omapdss_device_is_enabled(dssdev))
115 return; 69 return;
116 70
117 if (gpio_is_valid(ddata->pd_gpio)) 71 if (ddata->pd_gpio)
118 gpio_set_value_cansleep(ddata->pd_gpio, 0); 72 gpiod_set_value_cansleep(ddata->pd_gpio, 0);
119 73
120 in->ops.dpi->disable(in); 74 src->ops->disable(src);
121 75
122 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 76 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
123} 77}
124 78
125static void tfp410_fix_timings(struct videomode *vm) 79static const struct omap_dss_device_ops tfp410_ops = {
126{
127 vm->flags |= DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE |
128 DISPLAY_FLAGS_SYNC_POSEDGE;
129}
130
131static void tfp410_set_timings(struct omap_dss_device *dssdev,
132 struct videomode *vm)
133{
134 struct panel_drv_data *ddata = to_panel_data(dssdev);
135 struct omap_dss_device *in = ddata->in;
136
137 tfp410_fix_timings(vm);
138
139 ddata->vm = *vm;
140 dssdev->panel.vm = *vm;
141
142 in->ops.dpi->set_timings(in, vm);
143}
144
145static void tfp410_get_timings(struct omap_dss_device *dssdev,
146 struct videomode *vm)
147{
148 struct panel_drv_data *ddata = to_panel_data(dssdev);
149
150 *vm = ddata->vm;
151}
152
153static int tfp410_check_timings(struct omap_dss_device *dssdev,
154 struct videomode *vm)
155{
156 struct panel_drv_data *ddata = to_panel_data(dssdev);
157 struct omap_dss_device *in = ddata->in;
158
159 tfp410_fix_timings(vm);
160
161 return in->ops.dpi->check_timings(in, vm);
162}
163
164static const struct omapdss_dvi_ops tfp410_dvi_ops = {
165 .connect = tfp410_connect, 80 .connect = tfp410_connect,
166 .disconnect = tfp410_disconnect, 81 .disconnect = tfp410_disconnect,
167
168 .enable = tfp410_enable, 82 .enable = tfp410_enable,
169 .disable = tfp410_disable, 83 .disable = tfp410_disable,
170
171 .check_timings = tfp410_check_timings,
172 .set_timings = tfp410_set_timings,
173 .get_timings = tfp410_get_timings,
174}; 84};
175 85
176static int tfp410_probe_of(struct platform_device *pdev)
177{
178 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
179 struct device_node *node = pdev->dev.of_node;
180 int gpio;
181
182 gpio = of_get_named_gpio(node, "powerdown-gpios", 0);
183
184 if (gpio_is_valid(gpio) || gpio == -ENOENT) {
185 ddata->pd_gpio = gpio;
186 } else {
187 if (gpio != -EPROBE_DEFER)
188 dev_err(&pdev->dev, "failed to parse PD gpio\n");
189 return gpio;
190 }
191
192 return 0;
193}
194
195static int tfp410_probe(struct platform_device *pdev) 86static int tfp410_probe(struct platform_device *pdev)
196{ 87{
197 struct panel_drv_data *ddata; 88 struct panel_drv_data *ddata;
198 struct omap_dss_device *dssdev; 89 struct omap_dss_device *dssdev;
199 int r; 90 struct gpio_desc *gpio;
200 91
201 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL); 92 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
202 if (!ddata) 93 if (!ddata)
@@ -204,34 +95,34 @@ static int tfp410_probe(struct platform_device *pdev)
204 95
205 platform_set_drvdata(pdev, ddata); 96 platform_set_drvdata(pdev, ddata);
206 97
207 r = tfp410_probe_of(pdev); 98 /* Powerdown GPIO */
208 if (r) 99 gpio = devm_gpiod_get_optional(&pdev->dev, "powerdown", GPIOD_OUT_HIGH);
209 return r; 100 if (IS_ERR(gpio)) {
210 101 dev_err(&pdev->dev, "failed to parse powerdown gpio\n");
211 if (gpio_is_valid(ddata->pd_gpio)) { 102 return PTR_ERR(gpio);
212 r = devm_gpio_request_one(&pdev->dev, ddata->pd_gpio,
213 GPIOF_OUT_INIT_LOW, "tfp410 PD");
214 if (r) {
215 dev_err(&pdev->dev, "Failed to request PD GPIO %d\n",
216 ddata->pd_gpio);
217 return r;
218 }
219 } 103 }
220 104
105 ddata->pd_gpio = gpio;
106
221 dssdev = &ddata->dssdev; 107 dssdev = &ddata->dssdev;
222 dssdev->ops.dvi = &tfp410_dvi_ops; 108 dssdev->ops = &tfp410_ops;
223 dssdev->dev = &pdev->dev; 109 dssdev->dev = &pdev->dev;
224 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 110 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
225 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI; 111 dssdev->output_type = OMAP_DISPLAY_TYPE_DVI;
226 dssdev->owner = THIS_MODULE; 112 dssdev->owner = THIS_MODULE;
227 dssdev->port_num = 1; 113 dssdev->of_ports = BIT(1) | BIT(0);
228 114 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
229 r = omapdss_register_output(dssdev); 115 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
230 if (r) { 116
231 dev_err(&pdev->dev, "Failed to register output\n"); 117 dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
232 return r; 118 if (IS_ERR(dssdev->next)) {
119 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
120 dev_err(&pdev->dev, "failed to find video sink\n");
121 return PTR_ERR(dssdev->next);
233 } 122 }
234 123
124 omapdss_device_register(dssdev);
125
235 return 0; 126 return 0;
236} 127}
237 128
@@ -240,7 +131,9 @@ static int __exit tfp410_remove(struct platform_device *pdev)
240 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 131 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
241 struct omap_dss_device *dssdev = &ddata->dssdev; 132 struct omap_dss_device *dssdev = &ddata->dssdev;
242 133
243 omapdss_unregister_output(&ddata->dssdev); 134 if (dssdev->next)
135 omapdss_device_put(dssdev->next);
136 omapdss_device_unregister(&ddata->dssdev);
244 137
245 WARN_ON(omapdss_device_is_enabled(dssdev)); 138 WARN_ON(omapdss_device_is_enabled(dssdev));
246 if (omapdss_device_is_enabled(dssdev)) 139 if (omapdss_device_is_enabled(dssdev))
@@ -248,7 +141,7 @@ static int __exit tfp410_remove(struct platform_device *pdev)
248 141
249 WARN_ON(omapdss_device_is_connected(dssdev)); 142 WARN_ON(omapdss_device_is_connected(dssdev));
250 if (omapdss_device_is_connected(dssdev)) 143 if (omapdss_device_is_connected(dssdev))
251 tfp410_disconnect(dssdev, dssdev->dst); 144 omapdss_device_disconnect(NULL, dssdev);
252 145
253 return 0; 146 return 0;
254} 147}
diff --git a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
index d275bf152da5..94de55fd8884 100644
--- a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
+++ b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
@@ -21,42 +21,26 @@
21 21
22struct panel_drv_data { 22struct panel_drv_data {
23 struct omap_dss_device dssdev; 23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
25 void (*hpd_cb)(void *cb_data, enum drm_connector_status status); 24 void (*hpd_cb)(void *cb_data, enum drm_connector_status status);
26 void *hpd_cb_data; 25 void *hpd_cb_data;
27 bool hpd_enabled;
28 struct mutex hpd_lock; 26 struct mutex hpd_lock;
29 27
30 struct gpio_desc *ct_cp_hpd_gpio; 28 struct gpio_desc *ct_cp_hpd_gpio;
31 struct gpio_desc *ls_oe_gpio; 29 struct gpio_desc *ls_oe_gpio;
32 struct gpio_desc *hpd_gpio; 30 struct gpio_desc *hpd_gpio;
33
34 struct videomode vm;
35}; 31};
36 32
37#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev) 33#define to_panel_data(x) container_of(x, struct panel_drv_data, dssdev)
38 34
39static int tpd_connect(struct omap_dss_device *dssdev, 35static int tpd_connect(struct omap_dss_device *src,
40 struct omap_dss_device *dst) 36 struct omap_dss_device *dst)
41{ 37{
42 struct panel_drv_data *ddata = to_panel_data(dssdev); 38 struct panel_drv_data *ddata = to_panel_data(dst);
43 struct omap_dss_device *in;
44 int r; 39 int r;
45 40
46 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node); 41 r = omapdss_device_connect(dst->dss, dst, dst->next);
47 if (IS_ERR(in)) { 42 if (r)
48 dev_err(dssdev->dev, "failed to find video source\n");
49 return PTR_ERR(in);
50 }
51
52 r = in->ops.hdmi->connect(in, dssdev);
53 if (r) {
54 omap_dss_put_device(in);
55 return r; 43 return r;
56 }
57
58 dst->src = dssdev;
59 dssdev->dst = dst;
60 44
61 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1); 45 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1);
62 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1); 46 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1);
@@ -64,45 +48,29 @@ static int tpd_connect(struct omap_dss_device *dssdev,
64 /* DC-DC converter needs at max 300us to get to 90% of 5V */ 48 /* DC-DC converter needs at max 300us to get to 90% of 5V */
65 udelay(300); 49 udelay(300);
66 50
67 ddata->in = in;
68 return 0; 51 return 0;
69} 52}
70 53
71static void tpd_disconnect(struct omap_dss_device *dssdev, 54static void tpd_disconnect(struct omap_dss_device *src,
72 struct omap_dss_device *dst) 55 struct omap_dss_device *dst)
73{ 56{
74 struct panel_drv_data *ddata = to_panel_data(dssdev); 57 struct panel_drv_data *ddata = to_panel_data(dst);
75 struct omap_dss_device *in = ddata->in;
76
77 WARN_ON(dst != dssdev->dst);
78
79 if (dst != dssdev->dst)
80 return;
81 58
82 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0); 59 gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
83 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0); 60 gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0);
84 61
85 dst->src = NULL; 62 omapdss_device_disconnect(dst, dst->next);
86 dssdev->dst = NULL;
87
88 in->ops.hdmi->disconnect(in, &ddata->dssdev);
89
90 omap_dss_put_device(in);
91 ddata->in = NULL;
92} 63}
93 64
94static int tpd_enable(struct omap_dss_device *dssdev) 65static int tpd_enable(struct omap_dss_device *dssdev)
95{ 66{
96 struct panel_drv_data *ddata = to_panel_data(dssdev); 67 struct omap_dss_device *src = dssdev->src;
97 struct omap_dss_device *in = ddata->in;
98 int r; 68 int r;
99 69
100 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) 70 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
101 return 0; 71 return 0;
102 72
103 in->ops.hdmi->set_timings(in, &ddata->vm); 73 r = src->ops->enable(src);
104
105 r = in->ops.hdmi->enable(in);
106 if (r) 74 if (r)
107 return r; 75 return r;
108 76
@@ -113,76 +81,27 @@ static int tpd_enable(struct omap_dss_device *dssdev)
113 81
114static void tpd_disable(struct omap_dss_device *dssdev) 82static void tpd_disable(struct omap_dss_device *dssdev)
115{ 83{
116 struct panel_drv_data *ddata = to_panel_data(dssdev); 84 struct omap_dss_device *src = dssdev->src;
117 struct omap_dss_device *in = ddata->in;
118 85
119 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) 86 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
120 return; 87 return;
121 88
122 in->ops.hdmi->disable(in); 89 src->ops->disable(src);
123 90
124 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 91 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
125} 92}
126 93
127static void tpd_set_timings(struct omap_dss_device *dssdev,
128 struct videomode *vm)
129{
130 struct panel_drv_data *ddata = to_panel_data(dssdev);
131 struct omap_dss_device *in = ddata->in;
132
133 ddata->vm = *vm;
134 dssdev->panel.vm = *vm;
135
136 in->ops.hdmi->set_timings(in, vm);
137}
138
139static void tpd_get_timings(struct omap_dss_device *dssdev,
140 struct videomode *vm)
141{
142 struct panel_drv_data *ddata = to_panel_data(dssdev);
143
144 *vm = ddata->vm;
145}
146
147static int tpd_check_timings(struct omap_dss_device *dssdev,
148 struct videomode *vm)
149{
150 struct panel_drv_data *ddata = to_panel_data(dssdev);
151 struct omap_dss_device *in = ddata->in;
152 int r;
153
154 r = in->ops.hdmi->check_timings(in, vm);
155
156 return r;
157}
158
159static int tpd_read_edid(struct omap_dss_device *dssdev,
160 u8 *edid, int len)
161{
162 struct panel_drv_data *ddata = to_panel_data(dssdev);
163 struct omap_dss_device *in = ddata->in;
164
165 if (!gpiod_get_value_cansleep(ddata->hpd_gpio))
166 return -ENODEV;
167
168 return in->ops.hdmi->read_edid(in, edid, len);
169}
170
171static bool tpd_detect(struct omap_dss_device *dssdev) 94static bool tpd_detect(struct omap_dss_device *dssdev)
172{ 95{
173 struct panel_drv_data *ddata = to_panel_data(dssdev); 96 struct panel_drv_data *ddata = to_panel_data(dssdev);
174 struct omap_dss_device *in = ddata->in;
175 bool connected = gpiod_get_value_cansleep(ddata->hpd_gpio);
176 97
177 if (!connected && in->ops.hdmi->lost_hotplug) 98 return gpiod_get_value_cansleep(ddata->hpd_gpio);
178 in->ops.hdmi->lost_hotplug(in);
179 return connected;
180} 99}
181 100
182static int tpd_register_hpd_cb(struct omap_dss_device *dssdev, 101static void tpd_register_hpd_cb(struct omap_dss_device *dssdev,
183 void (*cb)(void *cb_data, 102 void (*cb)(void *cb_data,
184 enum drm_connector_status status), 103 enum drm_connector_status status),
185 void *cb_data) 104 void *cb_data)
186{ 105{
187 struct panel_drv_data *ddata = to_panel_data(dssdev); 106 struct panel_drv_data *ddata = to_panel_data(dssdev);
188 107
@@ -190,8 +109,6 @@ static int tpd_register_hpd_cb(struct omap_dss_device *dssdev,
190 ddata->hpd_cb = cb; 109 ddata->hpd_cb = cb;
191 ddata->hpd_cb_data = cb_data; 110 ddata->hpd_cb_data = cb_data;
192 mutex_unlock(&ddata->hpd_lock); 111 mutex_unlock(&ddata->hpd_lock);
193
194 return 0;
195} 112}
196 113
197static void tpd_unregister_hpd_cb(struct omap_dss_device *dssdev) 114static void tpd_unregister_hpd_cb(struct omap_dss_device *dssdev)
@@ -204,61 +121,14 @@ static void tpd_unregister_hpd_cb(struct omap_dss_device *dssdev)
204 mutex_unlock(&ddata->hpd_lock); 121 mutex_unlock(&ddata->hpd_lock);
205} 122}
206 123
207static void tpd_enable_hpd(struct omap_dss_device *dssdev) 124static const struct omap_dss_device_ops tpd_ops = {
208{
209 struct panel_drv_data *ddata = to_panel_data(dssdev);
210
211 mutex_lock(&ddata->hpd_lock);
212 ddata->hpd_enabled = true;
213 mutex_unlock(&ddata->hpd_lock);
214}
215
216static void tpd_disable_hpd(struct omap_dss_device *dssdev)
217{
218 struct panel_drv_data *ddata = to_panel_data(dssdev);
219
220 mutex_lock(&ddata->hpd_lock);
221 ddata->hpd_enabled = false;
222 mutex_unlock(&ddata->hpd_lock);
223}
224
225static int tpd_set_infoframe(struct omap_dss_device *dssdev,
226 const struct hdmi_avi_infoframe *avi)
227{
228 struct panel_drv_data *ddata = to_panel_data(dssdev);
229 struct omap_dss_device *in = ddata->in;
230
231 return in->ops.hdmi->set_infoframe(in, avi);
232}
233
234static int tpd_set_hdmi_mode(struct omap_dss_device *dssdev,
235 bool hdmi_mode)
236{
237 struct panel_drv_data *ddata = to_panel_data(dssdev);
238 struct omap_dss_device *in = ddata->in;
239
240 return in->ops.hdmi->set_hdmi_mode(in, hdmi_mode);
241}
242
243static const struct omapdss_hdmi_ops tpd_hdmi_ops = {
244 .connect = tpd_connect, 125 .connect = tpd_connect,
245 .disconnect = tpd_disconnect, 126 .disconnect = tpd_disconnect,
246
247 .enable = tpd_enable, 127 .enable = tpd_enable,
248 .disable = tpd_disable, 128 .disable = tpd_disable,
249
250 .check_timings = tpd_check_timings,
251 .set_timings = tpd_set_timings,
252 .get_timings = tpd_get_timings,
253
254 .read_edid = tpd_read_edid,
255 .detect = tpd_detect, 129 .detect = tpd_detect,
256 .register_hpd_cb = tpd_register_hpd_cb, 130 .register_hpd_cb = tpd_register_hpd_cb,
257 .unregister_hpd_cb = tpd_unregister_hpd_cb, 131 .unregister_hpd_cb = tpd_unregister_hpd_cb,
258 .enable_hpd = tpd_enable_hpd,
259 .disable_hpd = tpd_disable_hpd,
260 .set_infoframe = tpd_set_infoframe,
261 .set_hdmi_mode = tpd_set_hdmi_mode,
262}; 132};
263 133
264static irqreturn_t tpd_hpd_isr(int irq, void *data) 134static irqreturn_t tpd_hpd_isr(int irq, void *data)
@@ -266,7 +136,7 @@ static irqreturn_t tpd_hpd_isr(int irq, void *data)
266 struct panel_drv_data *ddata = data; 136 struct panel_drv_data *ddata = data;
267 137
268 mutex_lock(&ddata->hpd_lock); 138 mutex_lock(&ddata->hpd_lock);
269 if (ddata->hpd_enabled && ddata->hpd_cb) { 139 if (ddata->hpd_cb) {
270 enum drm_connector_status status; 140 enum drm_connector_status status;
271 141
272 if (tpd_detect(&ddata->dssdev)) 142 if (tpd_detect(&ddata->dssdev))
@@ -283,7 +153,7 @@ static irqreturn_t tpd_hpd_isr(int irq, void *data)
283 153
284static int tpd_probe(struct platform_device *pdev) 154static int tpd_probe(struct platform_device *pdev)
285{ 155{
286 struct omap_dss_device *in, *dssdev; 156 struct omap_dss_device *dssdev;
287 struct panel_drv_data *ddata; 157 struct panel_drv_data *ddata;
288 int r; 158 int r;
289 struct gpio_desc *gpio; 159 struct gpio_desc *gpio;
@@ -325,21 +195,24 @@ static int tpd_probe(struct platform_device *pdev)
325 return r; 195 return r;
326 196
327 dssdev = &ddata->dssdev; 197 dssdev = &ddata->dssdev;
328 dssdev->ops.hdmi = &tpd_hdmi_ops; 198 dssdev->ops = &tpd_ops;
329 dssdev->dev = &pdev->dev; 199 dssdev->dev = &pdev->dev;
330 dssdev->type = OMAP_DISPLAY_TYPE_HDMI; 200 dssdev->type = OMAP_DISPLAY_TYPE_HDMI;
331 dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI; 201 dssdev->output_type = OMAP_DISPLAY_TYPE_HDMI;
332 dssdev->owner = THIS_MODULE; 202 dssdev->owner = THIS_MODULE;
333 dssdev->port_num = 1; 203 dssdev->of_ports = BIT(1) | BIT(0);
334 204 dssdev->ops_flags = OMAP_DSS_DEVICE_OP_DETECT
335 in = ddata->in; 205 | OMAP_DSS_DEVICE_OP_HPD;
336 206
337 r = omapdss_register_output(dssdev); 207 dssdev->next = omapdss_of_find_connected_device(pdev->dev.of_node, 1);
338 if (r) { 208 if (IS_ERR(dssdev->next)) {
339 dev_err(&pdev->dev, "Failed to register output\n"); 209 if (PTR_ERR(dssdev->next) != -EPROBE_DEFER)
340 return r; 210 dev_err(&pdev->dev, "failed to find video sink\n");
211 return PTR_ERR(dssdev->next);
341 } 212 }
342 213
214 omapdss_device_register(dssdev);
215
343 return 0; 216 return 0;
344} 217}
345 218
@@ -348,7 +221,9 @@ static int __exit tpd_remove(struct platform_device *pdev)
348 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 221 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
349 struct omap_dss_device *dssdev = &ddata->dssdev; 222 struct omap_dss_device *dssdev = &ddata->dssdev;
350 223
351 omapdss_unregister_output(&ddata->dssdev); 224 if (dssdev->next)
225 omapdss_device_put(dssdev->next);
226 omapdss_device_unregister(&ddata->dssdev);
352 227
353 WARN_ON(omapdss_device_is_enabled(dssdev)); 228 WARN_ON(omapdss_device_is_enabled(dssdev));
354 if (omapdss_device_is_enabled(dssdev)) 229 if (omapdss_device_is_enabled(dssdev))
@@ -356,7 +231,7 @@ static int __exit tpd_remove(struct platform_device *pdev)
356 231
357 WARN_ON(omapdss_device_is_connected(dssdev)); 232 WARN_ON(omapdss_device_is_connected(dssdev));
358 if (omapdss_device_is_connected(dssdev)) 233 if (omapdss_device_is_connected(dssdev))
359 tpd_disconnect(dssdev, dssdev->dst); 234 omapdss_device_disconnect(NULL, dssdev);
360 235
361 return 0; 236 return 0;
362} 237}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-dpi.c b/drivers/gpu/drm/omapdrm/displays/panel-dpi.c
index 6cbf570d6727..1f8161b041be 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-dpi.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-dpi.c
@@ -23,7 +23,6 @@
23 23
24struct panel_drv_data { 24struct panel_drv_data {
25 struct omap_dss_device dssdev; 25 struct omap_dss_device dssdev;
26 struct omap_dss_device *in;
27 26
28 struct videomode vm; 27 struct videomode vm;
29 28
@@ -35,49 +34,21 @@ struct panel_drv_data {
35 34
36#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 35#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
37 36
38static int panel_dpi_connect(struct omap_dss_device *dssdev) 37static int panel_dpi_connect(struct omap_dss_device *src,
38 struct omap_dss_device *dst)
39{ 39{
40 struct panel_drv_data *ddata = to_panel_data(dssdev);
41 struct omap_dss_device *in;
42 int r;
43
44 if (omapdss_device_is_connected(dssdev))
45 return 0;
46
47 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
48 if (IS_ERR(in)) {
49 dev_err(dssdev->dev, "failed to find video source\n");
50 return PTR_ERR(in);
51 }
52
53 r = in->ops.dpi->connect(in, dssdev);
54 if (r) {
55 omap_dss_put_device(in);
56 return r;
57 }
58
59 ddata->in = in;
60 return 0; 40 return 0;
61} 41}
62 42
63static void panel_dpi_disconnect(struct omap_dss_device *dssdev) 43static void panel_dpi_disconnect(struct omap_dss_device *src,
44 struct omap_dss_device *dst)
64{ 45{
65 struct panel_drv_data *ddata = to_panel_data(dssdev);
66 struct omap_dss_device *in = ddata->in;
67
68 if (!omapdss_device_is_connected(dssdev))
69 return;
70
71 in->ops.dpi->disconnect(in, dssdev);
72
73 omap_dss_put_device(in);
74 ddata->in = NULL;
75} 46}
76 47
77static int panel_dpi_enable(struct omap_dss_device *dssdev) 48static int panel_dpi_enable(struct omap_dss_device *dssdev)
78{ 49{
79 struct panel_drv_data *ddata = to_panel_data(dssdev); 50 struct panel_drv_data *ddata = to_panel_data(dssdev);
80 struct omap_dss_device *in = ddata->in; 51 struct omap_dss_device *src = dssdev->src;
81 int r; 52 int r;
82 53
83 if (!omapdss_device_is_connected(dssdev)) 54 if (!omapdss_device_is_connected(dssdev))
@@ -86,15 +57,13 @@ static int panel_dpi_enable(struct omap_dss_device *dssdev)
86 if (omapdss_device_is_enabled(dssdev)) 57 if (omapdss_device_is_enabled(dssdev))
87 return 0; 58 return 0;
88 59
89 in->ops.dpi->set_timings(in, &ddata->vm); 60 r = src->ops->enable(src);
90
91 r = in->ops.dpi->enable(in);
92 if (r) 61 if (r)
93 return r; 62 return r;
94 63
95 r = regulator_enable(ddata->vcc_supply); 64 r = regulator_enable(ddata->vcc_supply);
96 if (r) { 65 if (r) {
97 in->ops.dpi->disable(in); 66 src->ops->disable(src);
98 return r; 67 return r;
99 } 68 }
100 69
@@ -109,7 +78,7 @@ static int panel_dpi_enable(struct omap_dss_device *dssdev)
109static void panel_dpi_disable(struct omap_dss_device *dssdev) 78static void panel_dpi_disable(struct omap_dss_device *dssdev)
110{ 79{
111 struct panel_drv_data *ddata = to_panel_data(dssdev); 80 struct panel_drv_data *ddata = to_panel_data(dssdev);
112 struct omap_dss_device *in = ddata->in; 81 struct omap_dss_device *src = dssdev->src;
113 82
114 if (!omapdss_device_is_enabled(dssdev)) 83 if (!omapdss_device_is_enabled(dssdev))
115 return; 84 return;
@@ -119,23 +88,11 @@ static void panel_dpi_disable(struct omap_dss_device *dssdev)
119 gpiod_set_value_cansleep(ddata->enable_gpio, 0); 88 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
120 regulator_disable(ddata->vcc_supply); 89 regulator_disable(ddata->vcc_supply);
121 90
122 in->ops.dpi->disable(in); 91 src->ops->disable(src);
123 92
124 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 93 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
125} 94}
126 95
127static void panel_dpi_set_timings(struct omap_dss_device *dssdev,
128 struct videomode *vm)
129{
130 struct panel_drv_data *ddata = to_panel_data(dssdev);
131 struct omap_dss_device *in = ddata->in;
132
133 ddata->vm = *vm;
134 dssdev->panel.vm = *vm;
135
136 in->ops.dpi->set_timings(in, vm);
137}
138
139static void panel_dpi_get_timings(struct omap_dss_device *dssdev, 96static void panel_dpi_get_timings(struct omap_dss_device *dssdev,
140 struct videomode *vm) 97 struct videomode *vm)
141{ 98{
@@ -144,25 +101,14 @@ static void panel_dpi_get_timings(struct omap_dss_device *dssdev,
144 *vm = ddata->vm; 101 *vm = ddata->vm;
145} 102}
146 103
147static int panel_dpi_check_timings(struct omap_dss_device *dssdev, 104static const struct omap_dss_device_ops panel_dpi_ops = {
148 struct videomode *vm)
149{
150 struct panel_drv_data *ddata = to_panel_data(dssdev);
151 struct omap_dss_device *in = ddata->in;
152
153 return in->ops.dpi->check_timings(in, vm);
154}
155
156static struct omap_dss_driver panel_dpi_ops = {
157 .connect = panel_dpi_connect, 105 .connect = panel_dpi_connect,
158 .disconnect = panel_dpi_disconnect, 106 .disconnect = panel_dpi_disconnect,
159 107
160 .enable = panel_dpi_enable, 108 .enable = panel_dpi_enable,
161 .disable = panel_dpi_disable, 109 .disable = panel_dpi_disable,
162 110
163 .set_timings = panel_dpi_set_timings,
164 .get_timings = panel_dpi_get_timings, 111 .get_timings = panel_dpi_get_timings,
165 .check_timings = panel_dpi_check_timings,
166}; 112};
167 113
168static int panel_dpi_probe_of(struct platform_device *pdev) 114static int panel_dpi_probe_of(struct platform_device *pdev)
@@ -227,16 +173,13 @@ static int panel_dpi_probe(struct platform_device *pdev)
227 173
228 dssdev = &ddata->dssdev; 174 dssdev = &ddata->dssdev;
229 dssdev->dev = &pdev->dev; 175 dssdev->dev = &pdev->dev;
230 dssdev->driver = &panel_dpi_ops; 176 dssdev->ops = &panel_dpi_ops;
231 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 177 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
232 dssdev->owner = THIS_MODULE; 178 dssdev->owner = THIS_MODULE;
233 dssdev->panel.vm = ddata->vm; 179 dssdev->of_ports = BIT(0);
234 180
235 r = omapdss_register_display(dssdev); 181 omapdss_display_init(dssdev);
236 if (r) { 182 omapdss_device_register(dssdev);
237 dev_err(&pdev->dev, "Failed to register panel\n");
238 return r;
239 }
240 183
241 return 0; 184 return 0;
242} 185}
@@ -246,10 +189,9 @@ static int __exit panel_dpi_remove(struct platform_device *pdev)
246 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 189 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
247 struct omap_dss_device *dssdev = &ddata->dssdev; 190 struct omap_dss_device *dssdev = &ddata->dssdev;
248 191
249 omapdss_unregister_display(dssdev); 192 omapdss_device_unregister(dssdev);
250 193
251 panel_dpi_disable(dssdev); 194 panel_dpi_disable(dssdev);
252 panel_dpi_disconnect(dssdev);
253 195
254 return 0; 196 return 0;
255} 197}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
index 428de90fced1..29692a5217c5 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c
@@ -41,7 +41,6 @@
41 41
42struct panel_drv_data { 42struct panel_drv_data {
43 struct omap_dss_device dssdev; 43 struct omap_dss_device dssdev;
44 struct omap_dss_device *in;
45 44
46 struct videomode vm; 45 struct videomode vm;
47 46
@@ -142,11 +141,11 @@ static void hw_guard_wait(struct panel_drv_data *ddata)
142 141
143static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data) 142static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data)
144{ 143{
145 struct omap_dss_device *in = ddata->in; 144 struct omap_dss_device *src = ddata->dssdev.src;
146 int r; 145 int r;
147 u8 buf[1]; 146 u8 buf[1];
148 147
149 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd, buf, 1); 148 r = src->ops->dsi.dcs_read(src, ddata->channel, dcs_cmd, buf, 1);
150 149
151 if (r < 0) 150 if (r < 0)
152 return r; 151 return r;
@@ -158,29 +157,30 @@ static int dsicm_dcs_read_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 *data)
158 157
159static int dsicm_dcs_write_0(struct panel_drv_data *ddata, u8 dcs_cmd) 158static int dsicm_dcs_write_0(struct panel_drv_data *ddata, u8 dcs_cmd)
160{ 159{
161 struct omap_dss_device *in = ddata->in; 160 struct omap_dss_device *src = ddata->dssdev.src;
162 return in->ops.dsi->dcs_write(in, ddata->channel, &dcs_cmd, 1); 161
162 return src->ops->dsi.dcs_write(src, ddata->channel, &dcs_cmd, 1);
163} 163}
164 164
165static int dsicm_dcs_write_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 param) 165static int dsicm_dcs_write_1(struct panel_drv_data *ddata, u8 dcs_cmd, u8 param)
166{ 166{
167 struct omap_dss_device *in = ddata->in; 167 struct omap_dss_device *src = ddata->dssdev.src;
168 u8 buf[2] = { dcs_cmd, param }; 168 u8 buf[2] = { dcs_cmd, param };
169 169
170 return in->ops.dsi->dcs_write(in, ddata->channel, buf, 2); 170 return src->ops->dsi.dcs_write(src, ddata->channel, buf, 2);
171} 171}
172 172
173static int dsicm_sleep_in(struct panel_drv_data *ddata) 173static int dsicm_sleep_in(struct panel_drv_data *ddata)
174 174
175{ 175{
176 struct omap_dss_device *in = ddata->in; 176 struct omap_dss_device *src = ddata->dssdev.src;
177 u8 cmd; 177 u8 cmd;
178 int r; 178 int r;
179 179
180 hw_guard_wait(ddata); 180 hw_guard_wait(ddata);
181 181
182 cmd = MIPI_DCS_ENTER_SLEEP_MODE; 182 cmd = MIPI_DCS_ENTER_SLEEP_MODE;
183 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, &cmd, 1); 183 r = src->ops->dsi.dcs_write_nosync(src, ddata->channel, &cmd, 1);
184 if (r) 184 if (r)
185 return r; 185 return r;
186 186
@@ -228,7 +228,7 @@ static int dsicm_get_id(struct panel_drv_data *ddata, u8 *id1, u8 *id2, u8 *id3)
228static int dsicm_set_update_window(struct panel_drv_data *ddata, 228static int dsicm_set_update_window(struct panel_drv_data *ddata,
229 u16 x, u16 y, u16 w, u16 h) 229 u16 x, u16 y, u16 w, u16 h)
230{ 230{
231 struct omap_dss_device *in = ddata->in; 231 struct omap_dss_device *src = ddata->dssdev.src;
232 int r; 232 int r;
233 u16 x1 = x; 233 u16 x1 = x;
234 u16 x2 = x + w - 1; 234 u16 x2 = x + w - 1;
@@ -242,7 +242,7 @@ static int dsicm_set_update_window(struct panel_drv_data *ddata,
242 buf[3] = (x2 >> 8) & 0xff; 242 buf[3] = (x2 >> 8) & 0xff;
243 buf[4] = (x2 >> 0) & 0xff; 243 buf[4] = (x2 >> 0) & 0xff;
244 244
245 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf)); 245 r = src->ops->dsi.dcs_write_nosync(src, ddata->channel, buf, sizeof(buf));
246 if (r) 246 if (r)
247 return r; 247 return r;
248 248
@@ -252,11 +252,11 @@ static int dsicm_set_update_window(struct panel_drv_data *ddata,
252 buf[3] = (y2 >> 8) & 0xff; 252 buf[3] = (y2 >> 8) & 0xff;
253 buf[4] = (y2 >> 0) & 0xff; 253 buf[4] = (y2 >> 0) & 0xff;
254 254
255 r = in->ops.dsi->dcs_write_nosync(in, ddata->channel, buf, sizeof(buf)); 255 r = src->ops->dsi.dcs_write_nosync(src, ddata->channel, buf, sizeof(buf));
256 if (r) 256 if (r)
257 return r; 257 return r;
258 258
259 in->ops.dsi->bta_sync(in, ddata->channel); 259 src->ops->dsi.bta_sync(src, ddata->channel);
260 260
261 return r; 261 return r;
262} 262}
@@ -275,7 +275,7 @@ static void dsicm_cancel_ulps_work(struct panel_drv_data *ddata)
275 275
276static int dsicm_enter_ulps(struct panel_drv_data *ddata) 276static int dsicm_enter_ulps(struct panel_drv_data *ddata)
277{ 277{
278 struct omap_dss_device *in = ddata->in; 278 struct omap_dss_device *src = ddata->dssdev.src;
279 int r; 279 int r;
280 280
281 if (ddata->ulps_enabled) 281 if (ddata->ulps_enabled)
@@ -290,7 +290,7 @@ static int dsicm_enter_ulps(struct panel_drv_data *ddata)
290 if (ddata->ext_te_gpio) 290 if (ddata->ext_te_gpio)
291 disable_irq(gpiod_to_irq(ddata->ext_te_gpio)); 291 disable_irq(gpiod_to_irq(ddata->ext_te_gpio));
292 292
293 in->ops.dsi->disable(in, false, true); 293 src->ops->dsi.disable(src, false, true);
294 294
295 ddata->ulps_enabled = true; 295 ddata->ulps_enabled = true;
296 296
@@ -309,19 +309,19 @@ err:
309 309
310static int dsicm_exit_ulps(struct panel_drv_data *ddata) 310static int dsicm_exit_ulps(struct panel_drv_data *ddata)
311{ 311{
312 struct omap_dss_device *in = ddata->in; 312 struct omap_dss_device *src = ddata->dssdev.src;
313 int r; 313 int r;
314 314
315 if (!ddata->ulps_enabled) 315 if (!ddata->ulps_enabled)
316 return 0; 316 return 0;
317 317
318 r = in->ops.dsi->enable(in); 318 r = src->ops->enable(src);
319 if (r) { 319 if (r) {
320 dev_err(&ddata->pdev->dev, "failed to enable DSI\n"); 320 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
321 goto err1; 321 goto err1;
322 } 322 }
323 323
324 in->ops.dsi->enable_hs(in, ddata->channel, true); 324 src->ops->dsi.enable_hs(src, ddata->channel, true);
325 325
326 r = _dsicm_enable_te(ddata, true); 326 r = _dsicm_enable_te(ddata, true);
327 if (r) { 327 if (r) {
@@ -366,7 +366,7 @@ static int dsicm_wake_up(struct panel_drv_data *ddata)
366static int dsicm_bl_update_status(struct backlight_device *dev) 366static int dsicm_bl_update_status(struct backlight_device *dev)
367{ 367{
368 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev); 368 struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
369 struct omap_dss_device *in = ddata->in; 369 struct omap_dss_device *src = ddata->dssdev.src;
370 int r = 0; 370 int r = 0;
371 int level; 371 int level;
372 372
@@ -381,13 +381,13 @@ static int dsicm_bl_update_status(struct backlight_device *dev)
381 mutex_lock(&ddata->lock); 381 mutex_lock(&ddata->lock);
382 382
383 if (ddata->enabled) { 383 if (ddata->enabled) {
384 in->ops.dsi->bus_lock(in); 384 src->ops->dsi.bus_lock(src);
385 385
386 r = dsicm_wake_up(ddata); 386 r = dsicm_wake_up(ddata);
387 if (!r) 387 if (!r)
388 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, level); 388 r = dsicm_dcs_write_1(ddata, DCS_BRIGHTNESS, level);
389 389
390 in->ops.dsi->bus_unlock(in); 390 src->ops->dsi.bus_unlock(src);
391 } 391 }
392 392
393 mutex_unlock(&ddata->lock); 393 mutex_unlock(&ddata->lock);
@@ -414,21 +414,21 @@ static ssize_t dsicm_num_errors_show(struct device *dev,
414{ 414{
415 struct platform_device *pdev = to_platform_device(dev); 415 struct platform_device *pdev = to_platform_device(dev);
416 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 416 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
417 struct omap_dss_device *in = ddata->in; 417 struct omap_dss_device *src = ddata->dssdev.src;
418 u8 errors = 0; 418 u8 errors = 0;
419 int r; 419 int r;
420 420
421 mutex_lock(&ddata->lock); 421 mutex_lock(&ddata->lock);
422 422
423 if (ddata->enabled) { 423 if (ddata->enabled) {
424 in->ops.dsi->bus_lock(in); 424 src->ops->dsi.bus_lock(src);
425 425
426 r = dsicm_wake_up(ddata); 426 r = dsicm_wake_up(ddata);
427 if (!r) 427 if (!r)
428 r = dsicm_dcs_read_1(ddata, DCS_READ_NUM_ERRORS, 428 r = dsicm_dcs_read_1(ddata, DCS_READ_NUM_ERRORS,
429 &errors); 429 &errors);
430 430
431 in->ops.dsi->bus_unlock(in); 431 src->ops->dsi.bus_unlock(src);
432 } else { 432 } else {
433 r = -ENODEV; 433 r = -ENODEV;
434 } 434 }
@@ -446,20 +446,20 @@ static ssize_t dsicm_hw_revision_show(struct device *dev,
446{ 446{
447 struct platform_device *pdev = to_platform_device(dev); 447 struct platform_device *pdev = to_platform_device(dev);
448 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 448 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
449 struct omap_dss_device *in = ddata->in; 449 struct omap_dss_device *src = ddata->dssdev.src;
450 u8 id1, id2, id3; 450 u8 id1, id2, id3;
451 int r; 451 int r;
452 452
453 mutex_lock(&ddata->lock); 453 mutex_lock(&ddata->lock);
454 454
455 if (ddata->enabled) { 455 if (ddata->enabled) {
456 in->ops.dsi->bus_lock(in); 456 src->ops->dsi.bus_lock(src);
457 457
458 r = dsicm_wake_up(ddata); 458 r = dsicm_wake_up(ddata);
459 if (!r) 459 if (!r)
460 r = dsicm_get_id(ddata, &id1, &id2, &id3); 460 r = dsicm_get_id(ddata, &id1, &id2, &id3);
461 461
462 in->ops.dsi->bus_unlock(in); 462 src->ops->dsi.bus_unlock(src);
463 } else { 463 } else {
464 r = -ENODEV; 464 r = -ENODEV;
465 } 465 }
@@ -478,7 +478,7 @@ static ssize_t dsicm_store_ulps(struct device *dev,
478{ 478{
479 struct platform_device *pdev = to_platform_device(dev); 479 struct platform_device *pdev = to_platform_device(dev);
480 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 480 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
481 struct omap_dss_device *in = ddata->in; 481 struct omap_dss_device *src = ddata->dssdev.src;
482 unsigned long t; 482 unsigned long t;
483 int r; 483 int r;
484 484
@@ -489,14 +489,14 @@ static ssize_t dsicm_store_ulps(struct device *dev,
489 mutex_lock(&ddata->lock); 489 mutex_lock(&ddata->lock);
490 490
491 if (ddata->enabled) { 491 if (ddata->enabled) {
492 in->ops.dsi->bus_lock(in); 492 src->ops->dsi.bus_lock(src);
493 493
494 if (t) 494 if (t)
495 r = dsicm_enter_ulps(ddata); 495 r = dsicm_enter_ulps(ddata);
496 else 496 else
497 r = dsicm_wake_up(ddata); 497 r = dsicm_wake_up(ddata);
498 498
499 in->ops.dsi->bus_unlock(in); 499 src->ops->dsi.bus_unlock(src);
500 } 500 }
501 501
502 mutex_unlock(&ddata->lock); 502 mutex_unlock(&ddata->lock);
@@ -528,7 +528,7 @@ static ssize_t dsicm_store_ulps_timeout(struct device *dev,
528{ 528{
529 struct platform_device *pdev = to_platform_device(dev); 529 struct platform_device *pdev = to_platform_device(dev);
530 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 530 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
531 struct omap_dss_device *in = ddata->in; 531 struct omap_dss_device *src = ddata->dssdev.src;
532 unsigned long t; 532 unsigned long t;
533 int r; 533 int r;
534 534
@@ -541,9 +541,9 @@ static ssize_t dsicm_store_ulps_timeout(struct device *dev,
541 541
542 if (ddata->enabled) { 542 if (ddata->enabled) {
543 /* dsicm_wake_up will restart the timer */ 543 /* dsicm_wake_up will restart the timer */
544 in->ops.dsi->bus_lock(in); 544 src->ops->dsi.bus_lock(src);
545 r = dsicm_wake_up(ddata); 545 r = dsicm_wake_up(ddata);
546 in->ops.dsi->bus_unlock(in); 546 src->ops->dsi.bus_unlock(src);
547 } 547 }
548 548
549 mutex_unlock(&ddata->lock); 549 mutex_unlock(&ddata->lock);
@@ -603,7 +603,7 @@ static void dsicm_hw_reset(struct panel_drv_data *ddata)
603 603
604static int dsicm_power_on(struct panel_drv_data *ddata) 604static int dsicm_power_on(struct panel_drv_data *ddata)
605{ 605{
606 struct omap_dss_device *in = ddata->in; 606 struct omap_dss_device *src = ddata->dssdev.src;
607 u8 id1, id2, id3; 607 u8 id1, id2, id3;
608 int r; 608 int r;
609 struct omap_dss_dsi_config dsi_config = { 609 struct omap_dss_dsi_config dsi_config = {
@@ -635,7 +635,7 @@ static int dsicm_power_on(struct panel_drv_data *ddata)
635 } 635 }
636 636
637 if (ddata->pin_config.num_pins > 0) { 637 if (ddata->pin_config.num_pins > 0) {
638 r = in->ops.dsi->configure_pins(in, &ddata->pin_config); 638 r = src->ops->dsi.configure_pins(src, &ddata->pin_config);
639 if (r) { 639 if (r) {
640 dev_err(&ddata->pdev->dev, 640 dev_err(&ddata->pdev->dev,
641 "failed to configure DSI pins\n"); 641 "failed to configure DSI pins\n");
@@ -643,13 +643,13 @@ static int dsicm_power_on(struct panel_drv_data *ddata)
643 } 643 }
644 } 644 }
645 645
646 r = in->ops.dsi->set_config(in, &dsi_config); 646 r = src->ops->dsi.set_config(src, &dsi_config);
647 if (r) { 647 if (r) {
648 dev_err(&ddata->pdev->dev, "failed to configure DSI\n"); 648 dev_err(&ddata->pdev->dev, "failed to configure DSI\n");
649 goto err_vddi; 649 goto err_vddi;
650 } 650 }
651 651
652 r = in->ops.dsi->enable(in); 652 r = src->ops->enable(src);
653 if (r) { 653 if (r) {
654 dev_err(&ddata->pdev->dev, "failed to enable DSI\n"); 654 dev_err(&ddata->pdev->dev, "failed to enable DSI\n");
655 goto err_vddi; 655 goto err_vddi;
@@ -657,7 +657,7 @@ static int dsicm_power_on(struct panel_drv_data *ddata)
657 657
658 dsicm_hw_reset(ddata); 658 dsicm_hw_reset(ddata);
659 659
660 in->ops.dsi->enable_hs(in, ddata->channel, false); 660 src->ops->dsi.enable_hs(src, ddata->channel, false);
661 661
662 r = dsicm_sleep_out(ddata); 662 r = dsicm_sleep_out(ddata);
663 if (r) 663 if (r)
@@ -689,7 +689,7 @@ static int dsicm_power_on(struct panel_drv_data *ddata)
689 if (r) 689 if (r)
690 goto err; 690 goto err;
691 691
692 r = in->ops.dsi->enable_video_output(in, ddata->channel); 692 r = src->ops->dsi.enable_video_output(src, ddata->channel);
693 if (r) 693 if (r)
694 goto err; 694 goto err;
695 695
@@ -701,7 +701,7 @@ static int dsicm_power_on(struct panel_drv_data *ddata)
701 ddata->intro_printed = true; 701 ddata->intro_printed = true;
702 } 702 }
703 703
704 in->ops.dsi->enable_hs(in, ddata->channel, true); 704 src->ops->dsi.enable_hs(src, ddata->channel, true);
705 705
706 return 0; 706 return 0;
707err: 707err:
@@ -709,7 +709,7 @@ err:
709 709
710 dsicm_hw_reset(ddata); 710 dsicm_hw_reset(ddata);
711 711
712 in->ops.dsi->disable(in, true, false); 712 src->ops->dsi.disable(src, true, false);
713err_vddi: 713err_vddi:
714 if (ddata->vddi) 714 if (ddata->vddi)
715 regulator_disable(ddata->vddi); 715 regulator_disable(ddata->vddi);
@@ -722,10 +722,10 @@ err_vpnl:
722 722
723static void dsicm_power_off(struct panel_drv_data *ddata) 723static void dsicm_power_off(struct panel_drv_data *ddata)
724{ 724{
725 struct omap_dss_device *in = ddata->in; 725 struct omap_dss_device *src = ddata->dssdev.src;
726 int r; 726 int r;
727 727
728 in->ops.dsi->disable_video_output(in, ddata->channel); 728 src->ops->dsi.disable_video_output(src, ddata->channel);
729 729
730 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_OFF); 730 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_DISPLAY_OFF);
731 if (!r) 731 if (!r)
@@ -737,7 +737,7 @@ static void dsicm_power_off(struct panel_drv_data *ddata)
737 dsicm_hw_reset(ddata); 737 dsicm_hw_reset(ddata);
738 } 738 }
739 739
740 in->ops.dsi->disable(in, true, false); 740 src->ops->dsi.disable(src, true, false);
741 741
742 if (ddata->vddi) 742 if (ddata->vddi)
743 regulator_disable(ddata->vddi); 743 regulator_disable(ddata->vddi);
@@ -756,71 +756,41 @@ static int dsicm_panel_reset(struct panel_drv_data *ddata)
756 return dsicm_power_on(ddata); 756 return dsicm_power_on(ddata);
757} 757}
758 758
759static int dsicm_connect(struct omap_dss_device *dssdev) 759static int dsicm_connect(struct omap_dss_device *src,
760 struct omap_dss_device *dst)
760{ 761{
761 struct panel_drv_data *ddata = to_panel_data(dssdev); 762 struct panel_drv_data *ddata = to_panel_data(dst);
762 struct device *dev = &ddata->pdev->dev; 763 struct device *dev = &ddata->pdev->dev;
763 struct omap_dss_device *in;
764 int r; 764 int r;
765 765
766 if (omapdss_device_is_connected(dssdev)) 766 r = src->ops->dsi.request_vc(src, &ddata->channel);
767 return 0;
768
769 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
770 if (IS_ERR(in)) {
771 dev_err(dssdev->dev, "failed to find video source\n");
772 return PTR_ERR(in);
773 }
774
775 r = in->ops.dsi->connect(in, dssdev);
776 if (r) {
777 dev_err(dev, "Failed to connect to video source\n");
778 goto err_connect;
779 }
780
781 r = in->ops.dsi->request_vc(in, &ddata->channel);
782 if (r) { 767 if (r) {
783 dev_err(dev, "failed to get virtual channel\n"); 768 dev_err(dev, "failed to get virtual channel\n");
784 goto err_req_vc; 769 return r;
785 } 770 }
786 771
787 r = in->ops.dsi->set_vc_id(in, ddata->channel, TCH); 772 r = src->ops->dsi.set_vc_id(src, ddata->channel, TCH);
788 if (r) { 773 if (r) {
789 dev_err(dev, "failed to set VC_ID\n"); 774 dev_err(dev, "failed to set VC_ID\n");
790 goto err_vc_id; 775 src->ops->dsi.release_vc(src, ddata->channel);
776 return r;
791 } 777 }
792 778
793 ddata->in = in;
794 return 0; 779 return 0;
795
796err_vc_id:
797 in->ops.dsi->release_vc(in, ddata->channel);
798err_req_vc:
799 in->ops.dsi->disconnect(in, dssdev);
800err_connect:
801 omap_dss_put_device(in);
802 return r;
803} 780}
804 781
805static void dsicm_disconnect(struct omap_dss_device *dssdev) 782static void dsicm_disconnect(struct omap_dss_device *src,
783 struct omap_dss_device *dst)
806{ 784{
807 struct panel_drv_data *ddata = to_panel_data(dssdev); 785 struct panel_drv_data *ddata = to_panel_data(dst);
808 struct omap_dss_device *in = ddata->in;
809
810 if (!omapdss_device_is_connected(dssdev))
811 return;
812
813 in->ops.dsi->release_vc(in, ddata->channel);
814 in->ops.dsi->disconnect(in, dssdev);
815 786
816 omap_dss_put_device(in); 787 src->ops->dsi.release_vc(src, ddata->channel);
817 ddata->in = NULL;
818} 788}
819 789
820static int dsicm_enable(struct omap_dss_device *dssdev) 790static int dsicm_enable(struct omap_dss_device *dssdev)
821{ 791{
822 struct panel_drv_data *ddata = to_panel_data(dssdev); 792 struct panel_drv_data *ddata = to_panel_data(dssdev);
823 struct omap_dss_device *in = ddata->in; 793 struct omap_dss_device *src = dssdev->src;
824 int r; 794 int r;
825 795
826 dev_dbg(&ddata->pdev->dev, "enable\n"); 796 dev_dbg(&ddata->pdev->dev, "enable\n");
@@ -837,11 +807,11 @@ static int dsicm_enable(struct omap_dss_device *dssdev)
837 goto err; 807 goto err;
838 } 808 }
839 809
840 in->ops.dsi->bus_lock(in); 810 src->ops->dsi.bus_lock(src);
841 811
842 r = dsicm_power_on(ddata); 812 r = dsicm_power_on(ddata);
843 813
844 in->ops.dsi->bus_unlock(in); 814 src->ops->dsi.bus_unlock(src);
845 815
846 if (r) 816 if (r)
847 goto err; 817 goto err;
@@ -862,7 +832,7 @@ err:
862static void dsicm_disable(struct omap_dss_device *dssdev) 832static void dsicm_disable(struct omap_dss_device *dssdev)
863{ 833{
864 struct panel_drv_data *ddata = to_panel_data(dssdev); 834 struct panel_drv_data *ddata = to_panel_data(dssdev);
865 struct omap_dss_device *in = ddata->in; 835 struct omap_dss_device *src = dssdev->src;
866 int r; 836 int r;
867 837
868 dev_dbg(&ddata->pdev->dev, "disable\n"); 838 dev_dbg(&ddata->pdev->dev, "disable\n");
@@ -873,7 +843,7 @@ static void dsicm_disable(struct omap_dss_device *dssdev)
873 843
874 dsicm_cancel_ulps_work(ddata); 844 dsicm_cancel_ulps_work(ddata);
875 845
876 in->ops.dsi->bus_lock(in); 846 src->ops->dsi.bus_lock(src);
877 847
878 if (omapdss_device_is_enabled(dssdev)) { 848 if (omapdss_device_is_enabled(dssdev)) {
879 r = dsicm_wake_up(ddata); 849 r = dsicm_wake_up(ddata);
@@ -881,7 +851,7 @@ static void dsicm_disable(struct omap_dss_device *dssdev)
881 dsicm_power_off(ddata); 851 dsicm_power_off(ddata);
882 } 852 }
883 853
884 in->ops.dsi->bus_unlock(in); 854 src->ops->dsi.bus_unlock(src);
885 855
886 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 856 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
887 857
@@ -891,16 +861,16 @@ static void dsicm_disable(struct omap_dss_device *dssdev)
891static void dsicm_framedone_cb(int err, void *data) 861static void dsicm_framedone_cb(int err, void *data)
892{ 862{
893 struct panel_drv_data *ddata = data; 863 struct panel_drv_data *ddata = data;
894 struct omap_dss_device *in = ddata->in; 864 struct omap_dss_device *src = ddata->dssdev.src;
895 865
896 dev_dbg(&ddata->pdev->dev, "framedone, err %d\n", err); 866 dev_dbg(&ddata->pdev->dev, "framedone, err %d\n", err);
897 in->ops.dsi->bus_unlock(ddata->in); 867 src->ops->dsi.bus_unlock(src);
898} 868}
899 869
900static irqreturn_t dsicm_te_isr(int irq, void *data) 870static irqreturn_t dsicm_te_isr(int irq, void *data)
901{ 871{
902 struct panel_drv_data *ddata = data; 872 struct panel_drv_data *ddata = data;
903 struct omap_dss_device *in = ddata->in; 873 struct omap_dss_device *src = ddata->dssdev.src;
904 int old; 874 int old;
905 int r; 875 int r;
906 876
@@ -909,7 +879,7 @@ static irqreturn_t dsicm_te_isr(int irq, void *data)
909 if (old) { 879 if (old) {
910 cancel_delayed_work(&ddata->te_timeout_work); 880 cancel_delayed_work(&ddata->te_timeout_work);
911 881
912 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb, 882 r = src->ops->dsi.update(src, ddata->channel, dsicm_framedone_cb,
913 ddata); 883 ddata);
914 if (r) 884 if (r)
915 goto err; 885 goto err;
@@ -918,7 +888,7 @@ static irqreturn_t dsicm_te_isr(int irq, void *data)
918 return IRQ_HANDLED; 888 return IRQ_HANDLED;
919err: 889err:
920 dev_err(&ddata->pdev->dev, "start update failed\n"); 890 dev_err(&ddata->pdev->dev, "start update failed\n");
921 in->ops.dsi->bus_unlock(in); 891 src->ops->dsi.bus_unlock(src);
922 return IRQ_HANDLED; 892 return IRQ_HANDLED;
923} 893}
924 894
@@ -926,25 +896,25 @@ static void dsicm_te_timeout_work_callback(struct work_struct *work)
926{ 896{
927 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data, 897 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
928 te_timeout_work.work); 898 te_timeout_work.work);
929 struct omap_dss_device *in = ddata->in; 899 struct omap_dss_device *src = ddata->dssdev.src;
930 900
931 dev_err(&ddata->pdev->dev, "TE not received for 250ms!\n"); 901 dev_err(&ddata->pdev->dev, "TE not received for 250ms!\n");
932 902
933 atomic_set(&ddata->do_update, 0); 903 atomic_set(&ddata->do_update, 0);
934 in->ops.dsi->bus_unlock(in); 904 src->ops->dsi.bus_unlock(src);
935} 905}
936 906
937static int dsicm_update(struct omap_dss_device *dssdev, 907static int dsicm_update(struct omap_dss_device *dssdev,
938 u16 x, u16 y, u16 w, u16 h) 908 u16 x, u16 y, u16 w, u16 h)
939{ 909{
940 struct panel_drv_data *ddata = to_panel_data(dssdev); 910 struct panel_drv_data *ddata = to_panel_data(dssdev);
941 struct omap_dss_device *in = ddata->in; 911 struct omap_dss_device *src = dssdev->src;
942 int r; 912 int r;
943 913
944 dev_dbg(&ddata->pdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); 914 dev_dbg(&ddata->pdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
945 915
946 mutex_lock(&ddata->lock); 916 mutex_lock(&ddata->lock);
947 in->ops.dsi->bus_lock(in); 917 src->ops->dsi.bus_lock(src);
948 918
949 r = dsicm_wake_up(ddata); 919 r = dsicm_wake_up(ddata);
950 if (r) 920 if (r)
@@ -956,9 +926,8 @@ static int dsicm_update(struct omap_dss_device *dssdev,
956 } 926 }
957 927
958 /* XXX no need to send this every frame, but dsi break if not done */ 928 /* XXX no need to send this every frame, but dsi break if not done */
959 r = dsicm_set_update_window(ddata, 0, 0, 929 r = dsicm_set_update_window(ddata, 0, 0, ddata->vm.hactive,
960 dssdev->panel.vm.hactive, 930 ddata->vm.vactive);
961 dssdev->panel.vm.vactive);
962 if (r) 931 if (r)
963 goto err; 932 goto err;
964 933
@@ -967,17 +936,17 @@ static int dsicm_update(struct omap_dss_device *dssdev,
967 msecs_to_jiffies(250)); 936 msecs_to_jiffies(250));
968 atomic_set(&ddata->do_update, 1); 937 atomic_set(&ddata->do_update, 1);
969 } else { 938 } else {
970 r = in->ops.dsi->update(in, ddata->channel, dsicm_framedone_cb, 939 r = src->ops->dsi.update(src, ddata->channel, dsicm_framedone_cb,
971 ddata); 940 ddata);
972 if (r) 941 if (r)
973 goto err; 942 goto err;
974 } 943 }
975 944
976 /* note: no bus_unlock here. unlock is in framedone_cb */ 945 /* note: no bus_unlock here. unlock is src framedone_cb */
977 mutex_unlock(&ddata->lock); 946 mutex_unlock(&ddata->lock);
978 return 0; 947 return 0;
979err: 948err:
980 in->ops.dsi->bus_unlock(in); 949 src->ops->dsi.bus_unlock(src);
981 mutex_unlock(&ddata->lock); 950 mutex_unlock(&ddata->lock);
982 return r; 951 return r;
983} 952}
@@ -985,13 +954,13 @@ err:
985static int dsicm_sync(struct omap_dss_device *dssdev) 954static int dsicm_sync(struct omap_dss_device *dssdev)
986{ 955{
987 struct panel_drv_data *ddata = to_panel_data(dssdev); 956 struct panel_drv_data *ddata = to_panel_data(dssdev);
988 struct omap_dss_device *in = ddata->in; 957 struct omap_dss_device *src = dssdev->src;
989 958
990 dev_dbg(&ddata->pdev->dev, "sync\n"); 959 dev_dbg(&ddata->pdev->dev, "sync\n");
991 960
992 mutex_lock(&ddata->lock); 961 mutex_lock(&ddata->lock);
993 in->ops.dsi->bus_lock(in); 962 src->ops->dsi.bus_lock(src);
994 in->ops.dsi->bus_unlock(in); 963 src->ops->dsi.bus_unlock(src);
995 mutex_unlock(&ddata->lock); 964 mutex_unlock(&ddata->lock);
996 965
997 dev_dbg(&ddata->pdev->dev, "sync done\n"); 966 dev_dbg(&ddata->pdev->dev, "sync done\n");
@@ -1001,7 +970,7 @@ static int dsicm_sync(struct omap_dss_device *dssdev)
1001 970
1002static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable) 971static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable)
1003{ 972{
1004 struct omap_dss_device *in = ddata->in; 973 struct omap_dss_device *src = ddata->dssdev.src;
1005 int r; 974 int r;
1006 975
1007 if (enable) 976 if (enable)
@@ -1010,7 +979,7 @@ static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable)
1010 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_TEAR_OFF); 979 r = dsicm_dcs_write_0(ddata, MIPI_DCS_SET_TEAR_OFF);
1011 980
1012 if (!ddata->ext_te_gpio) 981 if (!ddata->ext_te_gpio)
1013 in->ops.dsi->enable_te(in, enable); 982 src->ops->dsi.enable_te(src, enable);
1014 983
1015 /* possible panel bug */ 984 /* possible panel bug */
1016 msleep(100); 985 msleep(100);
@@ -1021,7 +990,7 @@ static int _dsicm_enable_te(struct panel_drv_data *ddata, bool enable)
1021static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable) 990static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable)
1022{ 991{
1023 struct panel_drv_data *ddata = to_panel_data(dssdev); 992 struct panel_drv_data *ddata = to_panel_data(dssdev);
1024 struct omap_dss_device *in = ddata->in; 993 struct omap_dss_device *src = dssdev->src;
1025 int r; 994 int r;
1026 995
1027 mutex_lock(&ddata->lock); 996 mutex_lock(&ddata->lock);
@@ -1029,7 +998,7 @@ static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable)
1029 if (ddata->te_enabled == enable) 998 if (ddata->te_enabled == enable)
1030 goto end; 999 goto end;
1031 1000
1032 in->ops.dsi->bus_lock(in); 1001 src->ops->dsi.bus_lock(src);
1033 1002
1034 if (ddata->enabled) { 1003 if (ddata->enabled) {
1035 r = dsicm_wake_up(ddata); 1004 r = dsicm_wake_up(ddata);
@@ -1043,13 +1012,13 @@ static int dsicm_enable_te(struct omap_dss_device *dssdev, bool enable)
1043 1012
1044 ddata->te_enabled = enable; 1013 ddata->te_enabled = enable;
1045 1014
1046 in->ops.dsi->bus_unlock(in); 1015 src->ops->dsi.bus_unlock(src);
1047end: 1016end:
1048 mutex_unlock(&ddata->lock); 1017 mutex_unlock(&ddata->lock);
1049 1018
1050 return 0; 1019 return 0;
1051err: 1020err:
1052 in->ops.dsi->bus_unlock(in); 1021 src->ops->dsi.bus_unlock(src);
1053 mutex_unlock(&ddata->lock); 1022 mutex_unlock(&ddata->lock);
1054 1023
1055 return r; 1024 return r;
@@ -1072,7 +1041,7 @@ static int dsicm_memory_read(struct omap_dss_device *dssdev,
1072 u16 x, u16 y, u16 w, u16 h) 1041 u16 x, u16 y, u16 w, u16 h)
1073{ 1042{
1074 struct panel_drv_data *ddata = to_panel_data(dssdev); 1043 struct panel_drv_data *ddata = to_panel_data(dssdev);
1075 struct omap_dss_device *in = ddata->in; 1044 struct omap_dss_device *src = dssdev->src;
1076 int r; 1045 int r;
1077 int first = 1; 1046 int first = 1;
1078 int plen; 1047 int plen;
@@ -1089,9 +1058,9 @@ static int dsicm_memory_read(struct omap_dss_device *dssdev,
1089 } 1058 }
1090 1059
1091 size = min((u32)w * h * 3, 1060 size = min((u32)w * h * 3,
1092 dssdev->panel.vm.hactive * dssdev->panel.vm.vactive * 3); 1061 ddata->vm.hactive * ddata->vm.vactive * 3);
1093 1062
1094 in->ops.dsi->bus_lock(in); 1063 src->ops->dsi.bus_lock(src);
1095 1064
1096 r = dsicm_wake_up(ddata); 1065 r = dsicm_wake_up(ddata);
1097 if (r) 1066 if (r)
@@ -1107,7 +1076,7 @@ static int dsicm_memory_read(struct omap_dss_device *dssdev,
1107 1076
1108 dsicm_set_update_window(ddata, x, y, w, h); 1077 dsicm_set_update_window(ddata, x, y, w, h);
1109 1078
1110 r = in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, plen); 1079 r = src->ops->dsi.set_max_rx_packet_size(src, ddata->channel, plen);
1111 if (r) 1080 if (r)
1112 goto err2; 1081 goto err2;
1113 1082
@@ -1115,7 +1084,7 @@ static int dsicm_memory_read(struct omap_dss_device *dssdev,
1115 u8 dcs_cmd = first ? 0x2e : 0x3e; 1084 u8 dcs_cmd = first ? 0x2e : 0x3e;
1116 first = 0; 1085 first = 0;
1117 1086
1118 r = in->ops.dsi->dcs_read(in, ddata->channel, dcs_cmd, 1087 r = src->ops->dsi.dcs_read(src, ddata->channel, dcs_cmd,
1119 buf + buf_used, size - buf_used); 1088 buf + buf_used, size - buf_used);
1120 1089
1121 if (r < 0) { 1090 if (r < 0) {
@@ -1141,9 +1110,9 @@ static int dsicm_memory_read(struct omap_dss_device *dssdev,
1141 r = buf_used; 1110 r = buf_used;
1142 1111
1143err3: 1112err3:
1144 in->ops.dsi->set_max_rx_packet_size(in, ddata->channel, 1); 1113 src->ops->dsi.set_max_rx_packet_size(src, ddata->channel, 1);
1145err2: 1114err2:
1146 in->ops.dsi->bus_unlock(in); 1115 src->ops->dsi.bus_unlock(src);
1147err1: 1116err1:
1148 mutex_unlock(&ddata->lock); 1117 mutex_unlock(&ddata->lock);
1149 return r; 1118 return r;
@@ -1154,7 +1123,7 @@ static void dsicm_ulps_work(struct work_struct *work)
1154 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data, 1123 struct panel_drv_data *ddata = container_of(work, struct panel_drv_data,
1155 ulps_work.work); 1124 ulps_work.work);
1156 struct omap_dss_device *dssdev = &ddata->dssdev; 1125 struct omap_dss_device *dssdev = &ddata->dssdev;
1157 struct omap_dss_device *in = ddata->in; 1126 struct omap_dss_device *src = dssdev->src;
1158 1127
1159 mutex_lock(&ddata->lock); 1128 mutex_lock(&ddata->lock);
1160 1129
@@ -1163,11 +1132,11 @@ static void dsicm_ulps_work(struct work_struct *work)
1163 return; 1132 return;
1164 } 1133 }
1165 1134
1166 in->ops.dsi->bus_lock(in); 1135 src->ops->dsi.bus_lock(src);
1167 1136
1168 dsicm_enter_ulps(ddata); 1137 dsicm_enter_ulps(ddata);
1169 1138
1170 in->ops.dsi->bus_unlock(in); 1139 src->ops->dsi.bus_unlock(src);
1171 mutex_unlock(&ddata->lock); 1140 mutex_unlock(&ddata->lock);
1172} 1141}
1173 1142
@@ -1210,18 +1179,21 @@ static void dsicm_get_size(struct omap_dss_device *dssdev,
1210 *height = ddata->height_mm; 1179 *height = ddata->height_mm;
1211} 1180}
1212 1181
1213static struct omap_dss_driver dsicm_ops = { 1182static const struct omap_dss_device_ops dsicm_ops = {
1214 .connect = dsicm_connect, 1183 .connect = dsicm_connect,
1215 .disconnect = dsicm_disconnect, 1184 .disconnect = dsicm_disconnect,
1216 1185
1217 .enable = dsicm_enable, 1186 .enable = dsicm_enable,
1218 .disable = dsicm_disable, 1187 .disable = dsicm_disable,
1219 1188
1189 .get_timings = dsicm_get_timings,
1190 .check_timings = dsicm_check_timings,
1191};
1192
1193static const struct omap_dss_driver dsicm_dss_driver = {
1220 .update = dsicm_update, 1194 .update = dsicm_update,
1221 .sync = dsicm_sync, 1195 .sync = dsicm_sync,
1222 1196
1223 .get_timings = dsicm_get_timings,
1224 .check_timings = dsicm_check_timings,
1225 .get_size = dsicm_get_size, 1197 .get_size = dsicm_get_size,
1226 1198
1227 .enable_te = dsicm_enable_te, 1199 .enable_te = dsicm_enable_te,
@@ -1330,20 +1302,17 @@ static int dsicm_probe(struct platform_device *pdev)
1330 1302
1331 dssdev = &ddata->dssdev; 1303 dssdev = &ddata->dssdev;
1332 dssdev->dev = dev; 1304 dssdev->dev = dev;
1333 dssdev->driver = &dsicm_ops; 1305 dssdev->ops = &dsicm_ops;
1334 dssdev->panel.vm = ddata->vm; 1306 dssdev->driver = &dsicm_dss_driver;
1335 dssdev->type = OMAP_DISPLAY_TYPE_DSI; 1307 dssdev->type = OMAP_DISPLAY_TYPE_DSI;
1336 dssdev->owner = THIS_MODULE; 1308 dssdev->owner = THIS_MODULE;
1309 dssdev->of_ports = BIT(0);
1337 1310
1338 dssdev->panel.dsi_pix_fmt = OMAP_DSS_DSI_FMT_RGB888;
1339 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE | 1311 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
1340 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM; 1312 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
1341 1313
1342 r = omapdss_register_display(dssdev); 1314 omapdss_display_init(dssdev);
1343 if (r) { 1315 omapdss_device_register(dssdev);
1344 dev_err(dev, "Failed to register panel\n");
1345 goto err_reg;
1346 }
1347 1316
1348 mutex_init(&ddata->lock); 1317 mutex_init(&ddata->lock);
1349 1318
@@ -1414,10 +1383,10 @@ static int __exit dsicm_remove(struct platform_device *pdev)
1414 1383
1415 dev_dbg(&pdev->dev, "remove\n"); 1384 dev_dbg(&pdev->dev, "remove\n");
1416 1385
1417 omapdss_unregister_display(dssdev); 1386 omapdss_device_unregister(dssdev);
1418 1387
1419 dsicm_disable(dssdev); 1388 dsicm_disable(dssdev);
1420 dsicm_disconnect(dssdev); 1389 omapdss_device_disconnect(dssdev->src, dssdev);
1421 1390
1422 sysfs_remove_group(&pdev->dev.kobj, &dsicm_attr_group); 1391 sysfs_remove_group(&pdev->dev.kobj, &dsicm_attr_group);
1423 1392
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-lgphilips-lb035q02.c b/drivers/gpu/drm/omapdrm/displays/panel-lgphilips-lb035q02.c
index 754197099440..f6ef8ff964dd 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-lgphilips-lb035q02.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-lgphilips-lb035q02.c
@@ -33,19 +33,11 @@ static const struct videomode lb035q02_vm = {
33 .vfront_porch = 4, 33 .vfront_porch = 4,
34 .vback_porch = 18, 34 .vback_porch = 18,
35 35
36 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 36 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
37 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
38 DISPLAY_FLAGS_PIXDATA_POSEDGE,
39 /*
40 * Note: According to the panel documentation:
41 * DE is active LOW
42 * DATA needs to be driven on the FALLING edge
43 */
44}; 37};
45 38
46struct panel_drv_data { 39struct panel_drv_data {
47 struct omap_dss_device dssdev; 40 struct omap_dss_device dssdev;
48 struct omap_dss_device *in;
49 41
50 struct spi_device *spi; 42 struct spi_device *spi;
51 43
@@ -116,51 +108,25 @@ static void init_lb035q02_panel(struct spi_device *spi)
116 lb035q02_write_reg(spi, 0x3b, 0x0806); 108 lb035q02_write_reg(spi, 0x3b, 0x0806);
117} 109}
118 110
119static int lb035q02_connect(struct omap_dss_device *dssdev) 111static int lb035q02_connect(struct omap_dss_device *src,
112 struct omap_dss_device *dst)
120{ 113{
121 struct panel_drv_data *ddata = to_panel_data(dssdev); 114 struct panel_drv_data *ddata = to_panel_data(dst);
122 struct omap_dss_device *in;
123 int r;
124
125 if (omapdss_device_is_connected(dssdev))
126 return 0;
127
128 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
129 if (IS_ERR(in)) {
130 dev_err(dssdev->dev, "failed to find video source\n");
131 return PTR_ERR(in);
132 }
133
134 r = in->ops.dpi->connect(in, dssdev);
135 if (r) {
136 omap_dss_put_device(in);
137 return r;
138 }
139 115
140 init_lb035q02_panel(ddata->spi); 116 init_lb035q02_panel(ddata->spi);
141 117
142 ddata->in = in;
143 return 0; 118 return 0;
144} 119}
145 120
146static void lb035q02_disconnect(struct omap_dss_device *dssdev) 121static void lb035q02_disconnect(struct omap_dss_device *src,
122 struct omap_dss_device *dst)
147{ 123{
148 struct panel_drv_data *ddata = to_panel_data(dssdev);
149 struct omap_dss_device *in = ddata->in;
150
151 if (!omapdss_device_is_connected(dssdev))
152 return;
153
154 in->ops.dpi->disconnect(in, dssdev);
155
156 omap_dss_put_device(in);
157 ddata->in = NULL;
158} 124}
159 125
160static int lb035q02_enable(struct omap_dss_device *dssdev) 126static int lb035q02_enable(struct omap_dss_device *dssdev)
161{ 127{
162 struct panel_drv_data *ddata = to_panel_data(dssdev); 128 struct panel_drv_data *ddata = to_panel_data(dssdev);
163 struct omap_dss_device *in = ddata->in; 129 struct omap_dss_device *src = dssdev->src;
164 int r; 130 int r;
165 131
166 if (!omapdss_device_is_connected(dssdev)) 132 if (!omapdss_device_is_connected(dssdev))
@@ -169,9 +135,7 @@ static int lb035q02_enable(struct omap_dss_device *dssdev)
169 if (omapdss_device_is_enabled(dssdev)) 135 if (omapdss_device_is_enabled(dssdev))
170 return 0; 136 return 0;
171 137
172 in->ops.dpi->set_timings(in, &ddata->vm); 138 r = src->ops->enable(src);
173
174 r = in->ops.dpi->enable(in);
175 if (r) 139 if (r)
176 return r; 140 return r;
177 141
@@ -186,7 +150,7 @@ static int lb035q02_enable(struct omap_dss_device *dssdev)
186static void lb035q02_disable(struct omap_dss_device *dssdev) 150static void lb035q02_disable(struct omap_dss_device *dssdev)
187{ 151{
188 struct panel_drv_data *ddata = to_panel_data(dssdev); 152 struct panel_drv_data *ddata = to_panel_data(dssdev);
189 struct omap_dss_device *in = ddata->in; 153 struct omap_dss_device *src = dssdev->src;
190 154
191 if (!omapdss_device_is_enabled(dssdev)) 155 if (!omapdss_device_is_enabled(dssdev))
192 return; 156 return;
@@ -194,23 +158,11 @@ static void lb035q02_disable(struct omap_dss_device *dssdev)
194 if (ddata->enable_gpio) 158 if (ddata->enable_gpio)
195 gpiod_set_value_cansleep(ddata->enable_gpio, 0); 159 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
196 160
197 in->ops.dpi->disable(in); 161 src->ops->disable(src);
198 162
199 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 163 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
200} 164}
201 165
202static void lb035q02_set_timings(struct omap_dss_device *dssdev,
203 struct videomode *vm)
204{
205 struct panel_drv_data *ddata = to_panel_data(dssdev);
206 struct omap_dss_device *in = ddata->in;
207
208 ddata->vm = *vm;
209 dssdev->panel.vm = *vm;
210
211 in->ops.dpi->set_timings(in, vm);
212}
213
214static void lb035q02_get_timings(struct omap_dss_device *dssdev, 166static void lb035q02_get_timings(struct omap_dss_device *dssdev,
215 struct videomode *vm) 167 struct videomode *vm)
216{ 168{
@@ -219,25 +171,14 @@ static void lb035q02_get_timings(struct omap_dss_device *dssdev,
219 *vm = ddata->vm; 171 *vm = ddata->vm;
220} 172}
221 173
222static int lb035q02_check_timings(struct omap_dss_device *dssdev, 174static const struct omap_dss_device_ops lb035q02_ops = {
223 struct videomode *vm)
224{
225 struct panel_drv_data *ddata = to_panel_data(dssdev);
226 struct omap_dss_device *in = ddata->in;
227
228 return in->ops.dpi->check_timings(in, vm);
229}
230
231static struct omap_dss_driver lb035q02_ops = {
232 .connect = lb035q02_connect, 175 .connect = lb035q02_connect,
233 .disconnect = lb035q02_disconnect, 176 .disconnect = lb035q02_disconnect,
234 177
235 .enable = lb035q02_enable, 178 .enable = lb035q02_enable,
236 .disable = lb035q02_disable, 179 .disable = lb035q02_disable,
237 180
238 .set_timings = lb035q02_set_timings,
239 .get_timings = lb035q02_get_timings, 181 .get_timings = lb035q02_get_timings,
240 .check_timings = lb035q02_check_timings,
241}; 182};
242 183
243static int lb035q02_probe_of(struct spi_device *spi) 184static int lb035q02_probe_of(struct spi_device *spi)
@@ -278,16 +219,21 @@ static int lb035q02_panel_spi_probe(struct spi_device *spi)
278 219
279 dssdev = &ddata->dssdev; 220 dssdev = &ddata->dssdev;
280 dssdev->dev = &spi->dev; 221 dssdev->dev = &spi->dev;
281 dssdev->driver = &lb035q02_ops; 222 dssdev->ops = &lb035q02_ops;
282 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 223 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
283 dssdev->owner = THIS_MODULE; 224 dssdev->owner = THIS_MODULE;
284 dssdev->panel.vm = ddata->vm; 225 dssdev->of_ports = BIT(0);
285 226
286 r = omapdss_register_display(dssdev); 227 /*
287 if (r) { 228 * Note: According to the panel documentation:
288 dev_err(&spi->dev, "Failed to register panel\n"); 229 * DE is active LOW
289 return r; 230 * DATA needs to be driven on the FALLING edge
290 } 231 */
232 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_NEGEDGE
233 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
234
235 omapdss_display_init(dssdev);
236 omapdss_device_register(dssdev);
291 237
292 return 0; 238 return 0;
293} 239}
@@ -297,10 +243,9 @@ static int lb035q02_panel_spi_remove(struct spi_device *spi)
297 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev); 243 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
298 struct omap_dss_device *dssdev = &ddata->dssdev; 244 struct omap_dss_device *dssdev = &ddata->dssdev;
299 245
300 omapdss_unregister_display(dssdev); 246 omapdss_device_unregister(dssdev);
301 247
302 lb035q02_disable(dssdev); 248 lb035q02_disable(dssdev);
303 lb035q02_disconnect(dssdev);
304 249
305 return 0; 250 return 0;
306} 251}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c b/drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c
index 9a3b27fa5cb5..f445de6369f7 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c
@@ -11,22 +11,19 @@
11 * (at your option) any later version. 11 * (at your option) any later version.
12 */ 12 */
13 13
14#include <linux/module.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/spi/spi.h>
17#include <linux/gpio/consumer.h> 15#include <linux/gpio/consumer.h>
18#include <linux/of_gpio.h> 16#include <linux/module.h>
17#include <linux/spi/spi.h>
19 18
20#include "../dss/omapdss.h" 19#include "../dss/omapdss.h"
21 20
22struct panel_drv_data { 21struct panel_drv_data {
23 struct omap_dss_device dssdev; 22 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
25 23
26 struct videomode vm; 24 struct videomode vm;
27 25
28 int res_gpio; 26 struct gpio_desc *res_gpio;
29 int qvga_gpio;
30 27
31 struct spi_device *spi; 28 struct spi_device *spi;
32}; 29};
@@ -74,9 +71,7 @@ static const struct videomode nec_8048_panel_vm = {
74 .vsync_len = 1, 71 .vsync_len = 1,
75 .vback_porch = 4, 72 .vback_porch = 4,
76 73
77 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 74 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
78 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
79 DISPLAY_FLAGS_PIXDATA_POSEDGE,
80}; 75};
81 76
82#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 77#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
@@ -112,49 +107,21 @@ static int init_nec_8048_wvga_lcd(struct spi_device *spi)
112 return 0; 107 return 0;
113} 108}
114 109
115static int nec_8048_connect(struct omap_dss_device *dssdev) 110static int nec_8048_connect(struct omap_dss_device *src,
111 struct omap_dss_device *dst)
116{ 112{
117 struct panel_drv_data *ddata = to_panel_data(dssdev);
118 struct omap_dss_device *in;
119 int r;
120
121 if (omapdss_device_is_connected(dssdev))
122 return 0;
123
124 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
125 if (IS_ERR(in)) {
126 dev_err(dssdev->dev, "failed to find video source\n");
127 return PTR_ERR(in);
128 }
129
130 r = in->ops.dpi->connect(in, dssdev);
131 if (r) {
132 omap_dss_put_device(in);
133 return r;
134 }
135
136 ddata->in = in;
137 return 0; 113 return 0;
138} 114}
139 115
140static void nec_8048_disconnect(struct omap_dss_device *dssdev) 116static void nec_8048_disconnect(struct omap_dss_device *src,
117 struct omap_dss_device *dst)
141{ 118{
142 struct panel_drv_data *ddata = to_panel_data(dssdev);
143 struct omap_dss_device *in = ddata->in;
144
145 if (!omapdss_device_is_connected(dssdev))
146 return;
147
148 in->ops.dpi->disconnect(in, dssdev);
149
150 omap_dss_put_device(in);
151 ddata->in = NULL;
152} 119}
153 120
154static int nec_8048_enable(struct omap_dss_device *dssdev) 121static int nec_8048_enable(struct omap_dss_device *dssdev)
155{ 122{
156 struct panel_drv_data *ddata = to_panel_data(dssdev); 123 struct panel_drv_data *ddata = to_panel_data(dssdev);
157 struct omap_dss_device *in = ddata->in; 124 struct omap_dss_device *src = dssdev->src;
158 int r; 125 int r;
159 126
160 if (!omapdss_device_is_connected(dssdev)) 127 if (!omapdss_device_is_connected(dssdev))
@@ -163,14 +130,11 @@ static int nec_8048_enable(struct omap_dss_device *dssdev)
163 if (omapdss_device_is_enabled(dssdev)) 130 if (omapdss_device_is_enabled(dssdev))
164 return 0; 131 return 0;
165 132
166 in->ops.dpi->set_timings(in, &ddata->vm); 133 r = src->ops->enable(src);
167
168 r = in->ops.dpi->enable(in);
169 if (r) 134 if (r)
170 return r; 135 return r;
171 136
172 if (gpio_is_valid(ddata->res_gpio)) 137 gpiod_set_value_cansleep(ddata->res_gpio, 1);
173 gpio_set_value_cansleep(ddata->res_gpio, 1);
174 138
175 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 139 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
176 140
@@ -180,31 +144,18 @@ static int nec_8048_enable(struct omap_dss_device *dssdev)
180static void nec_8048_disable(struct omap_dss_device *dssdev) 144static void nec_8048_disable(struct omap_dss_device *dssdev)
181{ 145{
182 struct panel_drv_data *ddata = to_panel_data(dssdev); 146 struct panel_drv_data *ddata = to_panel_data(dssdev);
183 struct omap_dss_device *in = ddata->in; 147 struct omap_dss_device *src = dssdev->src;
184 148
185 if (!omapdss_device_is_enabled(dssdev)) 149 if (!omapdss_device_is_enabled(dssdev))
186 return; 150 return;
187 151
188 if (gpio_is_valid(ddata->res_gpio)) 152 gpiod_set_value_cansleep(ddata->res_gpio, 0);
189 gpio_set_value_cansleep(ddata->res_gpio, 0);
190 153
191 in->ops.dpi->disable(in); 154 src->ops->disable(src);
192 155
193 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 156 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
194} 157}
195 158
196static void nec_8048_set_timings(struct omap_dss_device *dssdev,
197 struct videomode *vm)
198{
199 struct panel_drv_data *ddata = to_panel_data(dssdev);
200 struct omap_dss_device *in = ddata->in;
201
202 ddata->vm = *vm;
203 dssdev->panel.vm = *vm;
204
205 in->ops.dpi->set_timings(in, vm);
206}
207
208static void nec_8048_get_timings(struct omap_dss_device *dssdev, 159static void nec_8048_get_timings(struct omap_dss_device *dssdev,
209 struct videomode *vm) 160 struct videomode *vm)
210{ 161{
@@ -213,50 +164,21 @@ static void nec_8048_get_timings(struct omap_dss_device *dssdev,
213 *vm = ddata->vm; 164 *vm = ddata->vm;
214} 165}
215 166
216static int nec_8048_check_timings(struct omap_dss_device *dssdev, 167static const struct omap_dss_device_ops nec_8048_ops = {
217 struct videomode *vm)
218{
219 struct panel_drv_data *ddata = to_panel_data(dssdev);
220 struct omap_dss_device *in = ddata->in;
221
222 return in->ops.dpi->check_timings(in, vm);
223}
224
225static struct omap_dss_driver nec_8048_ops = {
226 .connect = nec_8048_connect, 168 .connect = nec_8048_connect,
227 .disconnect = nec_8048_disconnect, 169 .disconnect = nec_8048_disconnect,
228 170
229 .enable = nec_8048_enable, 171 .enable = nec_8048_enable,
230 .disable = nec_8048_disable, 172 .disable = nec_8048_disable,
231 173
232 .set_timings = nec_8048_set_timings,
233 .get_timings = nec_8048_get_timings, 174 .get_timings = nec_8048_get_timings,
234 .check_timings = nec_8048_check_timings,
235}; 175};
236 176
237static int nec_8048_probe_of(struct spi_device *spi)
238{
239 struct device_node *node = spi->dev.of_node;
240 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
241 int gpio;
242
243 gpio = of_get_named_gpio(node, "reset-gpios", 0);
244 if (!gpio_is_valid(gpio)) {
245 dev_err(&spi->dev, "failed to parse enable gpio\n");
246 return gpio;
247 }
248 ddata->res_gpio = gpio;
249
250 /* XXX the panel spec doesn't mention any QVGA pin?? */
251 ddata->qvga_gpio = -ENOENT;
252
253 return 0;
254}
255
256static int nec_8048_probe(struct spi_device *spi) 177static int nec_8048_probe(struct spi_device *spi)
257{ 178{
258 struct panel_drv_data *ddata; 179 struct panel_drv_data *ddata;
259 struct omap_dss_device *dssdev; 180 struct omap_dss_device *dssdev;
181 struct gpio_desc *gpio;
260 int r; 182 int r;
261 183
262 dev_dbg(&spi->dev, "%s\n", __func__); 184 dev_dbg(&spi->dev, "%s\n", __func__);
@@ -280,38 +202,27 @@ static int nec_8048_probe(struct spi_device *spi)
280 202
281 ddata->spi = spi; 203 ddata->spi = spi;
282 204
283 r = nec_8048_probe_of(spi); 205 gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW);
284 if (r) 206 if (IS_ERR(gpio)) {
285 return r; 207 dev_err(&spi->dev, "failed to get reset gpio\n");
286 208 return PTR_ERR(gpio);
287 if (gpio_is_valid(ddata->qvga_gpio)) {
288 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
289 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
290 if (r)
291 return r;
292 } 209 }
293 210
294 if (gpio_is_valid(ddata->res_gpio)) { 211 ddata->res_gpio = gpio;
295 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
296 GPIOF_OUT_INIT_LOW, "lcd RES");
297 if (r)
298 return r;
299 }
300 212
301 ddata->vm = nec_8048_panel_vm; 213 ddata->vm = nec_8048_panel_vm;
302 214
303 dssdev = &ddata->dssdev; 215 dssdev = &ddata->dssdev;
304 dssdev->dev = &spi->dev; 216 dssdev->dev = &spi->dev;
305 dssdev->driver = &nec_8048_ops; 217 dssdev->ops = &nec_8048_ops;
306 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 218 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
307 dssdev->owner = THIS_MODULE; 219 dssdev->owner = THIS_MODULE;
308 dssdev->panel.vm = ddata->vm; 220 dssdev->of_ports = BIT(0);
221 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
222 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
309 223
310 r = omapdss_register_display(dssdev); 224 omapdss_display_init(dssdev);
311 if (r) { 225 omapdss_device_register(dssdev);
312 dev_err(&spi->dev, "Failed to register panel\n");
313 return r;
314 }
315 226
316 return 0; 227 return 0;
317} 228}
@@ -323,10 +234,9 @@ static int nec_8048_remove(struct spi_device *spi)
323 234
324 dev_dbg(&ddata->spi->dev, "%s\n", __func__); 235 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
325 236
326 omapdss_unregister_display(dssdev); 237 omapdss_device_unregister(dssdev);
327 238
328 nec_8048_disable(dssdev); 239 nec_8048_disable(dssdev);
329 nec_8048_disconnect(dssdev);
330 240
331 return 0; 241 return 0;
332} 242}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-sharp-ls037v7dw01.c b/drivers/gpu/drm/omapdrm/displays/panel-sharp-ls037v7dw01.c
index bb5b680cabfe..64b1369cb274 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-sharp-ls037v7dw01.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-sharp-ls037v7dw01.c
@@ -21,7 +21,6 @@
21 21
22struct panel_drv_data { 22struct panel_drv_data {
23 struct omap_dss_device dssdev; 23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
25 struct regulator *vcc; 24 struct regulator *vcc;
26 25
27 struct videomode vm; 26 struct videomode vm;
@@ -47,60 +46,26 @@ static const struct videomode sharp_ls_vm = {
47 .vfront_porch = 1, 46 .vfront_porch = 1,
48 .vback_porch = 1, 47 .vback_porch = 1,
49 48
50 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 49 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
51 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
52 DISPLAY_FLAGS_PIXDATA_POSEDGE,
53 /*
54 * Note: According to the panel documentation:
55 * DATA needs to be driven on the FALLING edge
56 */
57}; 50};
58 51
59#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 52#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
60 53
61static int sharp_ls_connect(struct omap_dss_device *dssdev) 54static int sharp_ls_connect(struct omap_dss_device *src,
55 struct omap_dss_device *dst)
62{ 56{
63 struct panel_drv_data *ddata = to_panel_data(dssdev);
64 struct omap_dss_device *in;
65 int r;
66
67 if (omapdss_device_is_connected(dssdev))
68 return 0;
69
70 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
71 if (IS_ERR(in)) {
72 dev_err(dssdev->dev, "failed to find video source\n");
73 return PTR_ERR(in);
74 }
75
76 r = in->ops.dpi->connect(in, dssdev);
77 if (r) {
78 omap_dss_put_device(in);
79 return r;
80 }
81
82 ddata->in = in;
83 return 0; 57 return 0;
84} 58}
85 59
86static void sharp_ls_disconnect(struct omap_dss_device *dssdev) 60static void sharp_ls_disconnect(struct omap_dss_device *src,
61 struct omap_dss_device *dst)
87{ 62{
88 struct panel_drv_data *ddata = to_panel_data(dssdev);
89 struct omap_dss_device *in = ddata->in;
90
91 if (!omapdss_device_is_connected(dssdev))
92 return;
93
94 in->ops.dpi->disconnect(in, dssdev);
95
96 omap_dss_put_device(in);
97 ddata->in = NULL;
98} 63}
99 64
100static int sharp_ls_enable(struct omap_dss_device *dssdev) 65static int sharp_ls_enable(struct omap_dss_device *dssdev)
101{ 66{
102 struct panel_drv_data *ddata = to_panel_data(dssdev); 67 struct panel_drv_data *ddata = to_panel_data(dssdev);
103 struct omap_dss_device *in = ddata->in; 68 struct omap_dss_device *src = dssdev->src;
104 int r; 69 int r;
105 70
106 if (!omapdss_device_is_connected(dssdev)) 71 if (!omapdss_device_is_connected(dssdev))
@@ -109,15 +74,13 @@ static int sharp_ls_enable(struct omap_dss_device *dssdev)
109 if (omapdss_device_is_enabled(dssdev)) 74 if (omapdss_device_is_enabled(dssdev))
110 return 0; 75 return 0;
111 76
112 in->ops.dpi->set_timings(in, &ddata->vm);
113
114 if (ddata->vcc) { 77 if (ddata->vcc) {
115 r = regulator_enable(ddata->vcc); 78 r = regulator_enable(ddata->vcc);
116 if (r != 0) 79 if (r != 0)
117 return r; 80 return r;
118 } 81 }
119 82
120 r = in->ops.dpi->enable(in); 83 r = src->ops->enable(src);
121 if (r) { 84 if (r) {
122 regulator_disable(ddata->vcc); 85 regulator_disable(ddata->vcc);
123 return r; 86 return r;
@@ -140,7 +103,7 @@ static int sharp_ls_enable(struct omap_dss_device *dssdev)
140static void sharp_ls_disable(struct omap_dss_device *dssdev) 103static void sharp_ls_disable(struct omap_dss_device *dssdev)
141{ 104{
142 struct panel_drv_data *ddata = to_panel_data(dssdev); 105 struct panel_drv_data *ddata = to_panel_data(dssdev);
143 struct omap_dss_device *in = ddata->in; 106 struct omap_dss_device *src = dssdev->src;
144 107
145 if (!omapdss_device_is_enabled(dssdev)) 108 if (!omapdss_device_is_enabled(dssdev))
146 return; 109 return;
@@ -155,7 +118,7 @@ static void sharp_ls_disable(struct omap_dss_device *dssdev)
155 118
156 msleep(100); 119 msleep(100);
157 120
158 in->ops.dpi->disable(in); 121 src->ops->disable(src);
159 122
160 if (ddata->vcc) 123 if (ddata->vcc)
161 regulator_disable(ddata->vcc); 124 regulator_disable(ddata->vcc);
@@ -163,18 +126,6 @@ static void sharp_ls_disable(struct omap_dss_device *dssdev)
163 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 126 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
164} 127}
165 128
166static void sharp_ls_set_timings(struct omap_dss_device *dssdev,
167 struct videomode *vm)
168{
169 struct panel_drv_data *ddata = to_panel_data(dssdev);
170 struct omap_dss_device *in = ddata->in;
171
172 ddata->vm = *vm;
173 dssdev->panel.vm = *vm;
174
175 in->ops.dpi->set_timings(in, vm);
176}
177
178static void sharp_ls_get_timings(struct omap_dss_device *dssdev, 129static void sharp_ls_get_timings(struct omap_dss_device *dssdev,
179 struct videomode *vm) 130 struct videomode *vm)
180{ 131{
@@ -183,25 +134,14 @@ static void sharp_ls_get_timings(struct omap_dss_device *dssdev,
183 *vm = ddata->vm; 134 *vm = ddata->vm;
184} 135}
185 136
186static int sharp_ls_check_timings(struct omap_dss_device *dssdev, 137static const struct omap_dss_device_ops sharp_ls_ops = {
187 struct videomode *vm)
188{
189 struct panel_drv_data *ddata = to_panel_data(dssdev);
190 struct omap_dss_device *in = ddata->in;
191
192 return in->ops.dpi->check_timings(in, vm);
193}
194
195static struct omap_dss_driver sharp_ls_ops = {
196 .connect = sharp_ls_connect, 138 .connect = sharp_ls_connect,
197 .disconnect = sharp_ls_disconnect, 139 .disconnect = sharp_ls_disconnect,
198 140
199 .enable = sharp_ls_enable, 141 .enable = sharp_ls_enable,
200 .disable = sharp_ls_disable, 142 .disable = sharp_ls_disable,
201 143
202 .set_timings = sharp_ls_set_timings,
203 .get_timings = sharp_ls_get_timings, 144 .get_timings = sharp_ls_get_timings,
204 .check_timings = sharp_ls_check_timings,
205}; 145};
206 146
207static int sharp_ls_get_gpio_of(struct device *dev, int index, int val, 147static int sharp_ls_get_gpio_of(struct device *dev, int index, int val,
@@ -278,16 +218,20 @@ static int sharp_ls_probe(struct platform_device *pdev)
278 218
279 dssdev = &ddata->dssdev; 219 dssdev = &ddata->dssdev;
280 dssdev->dev = &pdev->dev; 220 dssdev->dev = &pdev->dev;
281 dssdev->driver = &sharp_ls_ops; 221 dssdev->ops = &sharp_ls_ops;
282 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 222 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
283 dssdev->owner = THIS_MODULE; 223 dssdev->owner = THIS_MODULE;
284 dssdev->panel.vm = ddata->vm; 224 dssdev->of_ports = BIT(0);
285 225
286 r = omapdss_register_display(dssdev); 226 /*
287 if (r) { 227 * Note: According to the panel documentation:
288 dev_err(&pdev->dev, "Failed to register panel\n"); 228 * DATA needs to be driven on the FALLING edge
289 return r; 229 */
290 } 230 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_NEGEDGE
231 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
232
233 omapdss_display_init(dssdev);
234 omapdss_device_register(dssdev);
291 235
292 return 0; 236 return 0;
293} 237}
@@ -297,10 +241,9 @@ static int __exit sharp_ls_remove(struct platform_device *pdev)
297 struct panel_drv_data *ddata = platform_get_drvdata(pdev); 241 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
298 struct omap_dss_device *dssdev = &ddata->dssdev; 242 struct omap_dss_device *dssdev = &ddata->dssdev;
299 243
300 omapdss_unregister_display(dssdev); 244 omapdss_device_unregister(dssdev);
301 245
302 sharp_ls_disable(dssdev); 246 sharp_ls_disable(dssdev);
303 sharp_ls_disconnect(dssdev);
304 247
305 return 0; 248 return 0;
306} 249}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-sony-acx565akm.c b/drivers/gpu/drm/omapdrm/displays/panel-sony-acx565akm.c
index f34c06bb5bd7..e04663856b31 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-sony-acx565akm.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-sony-acx565akm.c
@@ -20,17 +20,15 @@
20 * this program. If not, see <http://www.gnu.org/licenses/>. 20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */ 21 */
22 22
23#include <linux/backlight.h>
24#include <linux/delay.h>
25#include <linux/gpio/consumer.h>
26#include <linux/jiffies.h>
23#include <linux/kernel.h> 27#include <linux/kernel.h>
24#include <linux/module.h> 28#include <linux/module.h>
25#include <linux/platform_device.h> 29#include <linux/platform_device.h>
26#include <linux/delay.h>
27#include <linux/spi/spi.h>
28#include <linux/jiffies.h>
29#include <linux/sched.h> 30#include <linux/sched.h>
30#include <linux/backlight.h> 31#include <linux/spi/spi.h>
31#include <linux/gpio/consumer.h>
32#include <linux/of.h>
33#include <linux/of_gpio.h>
34 32
35#include "../dss/omapdss.h" 33#include "../dss/omapdss.h"
36 34
@@ -64,9 +62,8 @@
64 62
65struct panel_drv_data { 63struct panel_drv_data {
66 struct omap_dss_device dssdev; 64 struct omap_dss_device dssdev;
67 struct omap_dss_device *in;
68 65
69 int reset_gpio; 66 struct gpio_desc *reset_gpio;
70 67
71 struct videomode vm; 68 struct videomode vm;
72 69
@@ -100,9 +97,7 @@ static const struct videomode acx565akm_panel_vm = {
100 .vsync_len = 3, 97 .vsync_len = 3,
101 .vback_porch = 4, 98 .vback_porch = 4,
102 99
103 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 100 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
104 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
105 DISPLAY_FLAGS_PIXDATA_POSEDGE,
106}; 101};
107 102
108#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 103#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
@@ -507,56 +502,26 @@ static const struct attribute_group bldev_attr_group = {
507 .attrs = bldev_attrs, 502 .attrs = bldev_attrs,
508}; 503};
509 504
510static int acx565akm_connect(struct omap_dss_device *dssdev) 505static int acx565akm_connect(struct omap_dss_device *src,
506 struct omap_dss_device *dst)
511{ 507{
512 struct panel_drv_data *ddata = to_panel_data(dssdev);
513 struct omap_dss_device *in;
514 int r;
515
516 if (omapdss_device_is_connected(dssdev))
517 return 0;
518
519 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
520 if (IS_ERR(in)) {
521 dev_err(dssdev->dev, "failed to find video source\n");
522 return PTR_ERR(in);
523 }
524
525 r = in->ops.sdi->connect(in, dssdev);
526 if (r) {
527 omap_dss_put_device(in);
528 return r;
529 }
530
531 ddata->in = in;
532 return 0; 508 return 0;
533} 509}
534 510
535static void acx565akm_disconnect(struct omap_dss_device *dssdev) 511static void acx565akm_disconnect(struct omap_dss_device *src,
512 struct omap_dss_device *dst)
536{ 513{
537 struct panel_drv_data *ddata = to_panel_data(dssdev);
538 struct omap_dss_device *in = ddata->in;
539
540 if (!omapdss_device_is_connected(dssdev))
541 return;
542
543 in->ops.sdi->disconnect(in, dssdev);
544
545 omap_dss_put_device(in);
546 ddata->in = NULL;
547} 514}
548 515
549static int acx565akm_panel_power_on(struct omap_dss_device *dssdev) 516static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
550{ 517{
551 struct panel_drv_data *ddata = to_panel_data(dssdev); 518 struct panel_drv_data *ddata = to_panel_data(dssdev);
552 struct omap_dss_device *in = ddata->in; 519 struct omap_dss_device *src = dssdev->src;
553 int r; 520 int r;
554 521
555 dev_dbg(&ddata->spi->dev, "%s\n", __func__); 522 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
556 523
557 in->ops.sdi->set_timings(in, &ddata->vm); 524 r = src->ops->enable(src);
558
559 r = in->ops.sdi->enable(in);
560 if (r) { 525 if (r) {
561 pr_err("%s sdi enable failed\n", __func__); 526 pr_err("%s sdi enable failed\n", __func__);
562 return r; 527 return r;
@@ -565,8 +530,8 @@ static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
565 /*FIXME tweak me */ 530 /*FIXME tweak me */
566 msleep(50); 531 msleep(50);
567 532
568 if (gpio_is_valid(ddata->reset_gpio)) 533 if (ddata->reset_gpio)
569 gpio_set_value(ddata->reset_gpio, 1); 534 gpiod_set_value(ddata->reset_gpio, 1);
570 535
571 if (ddata->enabled) { 536 if (ddata->enabled) {
572 dev_dbg(&ddata->spi->dev, "panel already enabled\n"); 537 dev_dbg(&ddata->spi->dev, "panel already enabled\n");
@@ -597,7 +562,7 @@ static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
597static void acx565akm_panel_power_off(struct omap_dss_device *dssdev) 562static void acx565akm_panel_power_off(struct omap_dss_device *dssdev)
598{ 563{
599 struct panel_drv_data *ddata = to_panel_data(dssdev); 564 struct panel_drv_data *ddata = to_panel_data(dssdev);
600 struct omap_dss_device *in = ddata->in; 565 struct omap_dss_device *src = dssdev->src;
601 566
602 dev_dbg(dssdev->dev, "%s\n", __func__); 567 dev_dbg(dssdev->dev, "%s\n", __func__);
603 568
@@ -615,13 +580,13 @@ static void acx565akm_panel_power_off(struct omap_dss_device *dssdev)
615 */ 580 */
616 msleep(50); 581 msleep(50);
617 582
618 if (gpio_is_valid(ddata->reset_gpio)) 583 if (ddata->reset_gpio)
619 gpio_set_value(ddata->reset_gpio, 0); 584 gpiod_set_value(ddata->reset_gpio, 0);
620 585
621 /* FIXME need to tweak this delay */ 586 /* FIXME need to tweak this delay */
622 msleep(100); 587 msleep(100);
623 588
624 in->ops.sdi->disable(in); 589 src->ops->disable(src);
625} 590}
626 591
627static int acx565akm_enable(struct omap_dss_device *dssdev) 592static int acx565akm_enable(struct omap_dss_device *dssdev)
@@ -664,18 +629,6 @@ static void acx565akm_disable(struct omap_dss_device *dssdev)
664 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 629 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
665} 630}
666 631
667static void acx565akm_set_timings(struct omap_dss_device *dssdev,
668 struct videomode *vm)
669{
670 struct panel_drv_data *ddata = to_panel_data(dssdev);
671 struct omap_dss_device *in = ddata->in;
672
673 ddata->vm = *vm;
674 dssdev->panel.vm = *vm;
675
676 in->ops.sdi->set_timings(in, vm);
677}
678
679static void acx565akm_get_timings(struct omap_dss_device *dssdev, 632static void acx565akm_get_timings(struct omap_dss_device *dssdev,
680 struct videomode *vm) 633 struct videomode *vm)
681{ 634{
@@ -684,37 +637,16 @@ static void acx565akm_get_timings(struct omap_dss_device *dssdev,
684 *vm = ddata->vm; 637 *vm = ddata->vm;
685} 638}
686 639
687static int acx565akm_check_timings(struct omap_dss_device *dssdev, 640static const struct omap_dss_device_ops acx565akm_ops = {
688 struct videomode *vm)
689{
690 struct panel_drv_data *ddata = to_panel_data(dssdev);
691 struct omap_dss_device *in = ddata->in;
692
693 return in->ops.sdi->check_timings(in, vm);
694}
695
696static struct omap_dss_driver acx565akm_ops = {
697 .connect = acx565akm_connect, 641 .connect = acx565akm_connect,
698 .disconnect = acx565akm_disconnect, 642 .disconnect = acx565akm_disconnect,
699 643
700 .enable = acx565akm_enable, 644 .enable = acx565akm_enable,
701 .disable = acx565akm_disable, 645 .disable = acx565akm_disable,
702 646
703 .set_timings = acx565akm_set_timings,
704 .get_timings = acx565akm_get_timings, 647 .get_timings = acx565akm_get_timings,
705 .check_timings = acx565akm_check_timings,
706}; 648};
707 649
708static int acx565akm_probe_of(struct spi_device *spi)
709{
710 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
711 struct device_node *np = spi->dev.of_node;
712
713 ddata->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0);
714
715 return 0;
716}
717
718static int acx565akm_probe(struct spi_device *spi) 650static int acx565akm_probe(struct spi_device *spi)
719{ 651{
720 struct panel_drv_data *ddata; 652 struct panel_drv_data *ddata;
@@ -722,6 +654,7 @@ static int acx565akm_probe(struct spi_device *spi)
722 struct backlight_device *bldev; 654 struct backlight_device *bldev;
723 int max_brightness, brightness; 655 int max_brightness, brightness;
724 struct backlight_properties props; 656 struct backlight_properties props;
657 struct gpio_desc *gpio;
725 int r; 658 int r;
726 659
727 dev_dbg(&spi->dev, "%s\n", __func__); 660 dev_dbg(&spi->dev, "%s\n", __func__);
@@ -738,19 +671,16 @@ static int acx565akm_probe(struct spi_device *spi)
738 671
739 mutex_init(&ddata->mutex); 672 mutex_init(&ddata->mutex);
740 673
741 r = acx565akm_probe_of(spi); 674 gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
742 if (r) 675 if (IS_ERR(gpio)) {
743 return r; 676 dev_err(&spi->dev, "failed to parse reset gpio\n");
744 677 return PTR_ERR(gpio);
745 if (gpio_is_valid(ddata->reset_gpio)) {
746 r = devm_gpio_request_one(&spi->dev, ddata->reset_gpio,
747 GPIOF_OUT_INIT_LOW, "lcd reset");
748 if (r)
749 goto err_gpio;
750 } 678 }
751 679
752 if (gpio_is_valid(ddata->reset_gpio)) 680 ddata->reset_gpio = gpio;
753 gpio_set_value(ddata->reset_gpio, 1); 681
682 if (ddata->reset_gpio)
683 gpiod_set_value(ddata->reset_gpio, 1);
754 684
755 /* 685 /*
756 * After reset we have to wait 5 msec before the first 686 * After reset we have to wait 5 msec before the first
@@ -762,12 +692,12 @@ static int acx565akm_probe(struct spi_device *spi)
762 692
763 r = panel_detect(ddata); 693 r = panel_detect(ddata);
764 694
765 if (!ddata->enabled && gpio_is_valid(ddata->reset_gpio)) 695 if (!ddata->enabled && ddata->reset_gpio)
766 gpio_set_value(ddata->reset_gpio, 0); 696 gpiod_set_value(ddata->reset_gpio, 0);
767 697
768 if (r) { 698 if (r) {
769 dev_err(&spi->dev, "%s panel detect error\n", __func__); 699 dev_err(&spi->dev, "%s panel detect error\n", __func__);
770 goto err_detect; 700 return r;
771 } 701 }
772 702
773 memset(&props, 0, sizeof(props)); 703 memset(&props, 0, sizeof(props));
@@ -777,17 +707,15 @@ static int acx565akm_probe(struct spi_device *spi)
777 707
778 bldev = backlight_device_register("acx565akm", &ddata->spi->dev, 708 bldev = backlight_device_register("acx565akm", &ddata->spi->dev,
779 ddata, &acx565akm_bl_ops, &props); 709 ddata, &acx565akm_bl_ops, &props);
780 if (IS_ERR(bldev)) { 710 if (IS_ERR(bldev))
781 r = PTR_ERR(bldev); 711 return PTR_ERR(bldev);
782 goto err_reg_bl;
783 }
784 ddata->bl_dev = bldev; 712 ddata->bl_dev = bldev;
785 if (ddata->has_cabc) { 713 if (ddata->has_cabc) {
786 r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group); 714 r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
787 if (r) { 715 if (r) {
788 dev_err(&bldev->dev, 716 dev_err(&bldev->dev,
789 "%s failed to create sysfs files\n", __func__); 717 "%s failed to create sysfs files\n", __func__);
790 goto err_sysfs; 718 goto err_backlight_unregister;
791 } 719 }
792 ddata->cabc_mode = get_hw_cabc_mode(ddata); 720 ddata->cabc_mode = get_hw_cabc_mode(ddata);
793 } 721 }
@@ -809,26 +737,20 @@ static int acx565akm_probe(struct spi_device *spi)
809 737
810 dssdev = &ddata->dssdev; 738 dssdev = &ddata->dssdev;
811 dssdev->dev = &spi->dev; 739 dssdev->dev = &spi->dev;
812 dssdev->driver = &acx565akm_ops; 740 dssdev->ops = &acx565akm_ops;
813 dssdev->type = OMAP_DISPLAY_TYPE_SDI; 741 dssdev->type = OMAP_DISPLAY_TYPE_SDI;
814 dssdev->owner = THIS_MODULE; 742 dssdev->owner = THIS_MODULE;
815 dssdev->panel.vm = ddata->vm; 743 dssdev->of_ports = BIT(0);
744 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_NEGEDGE
745 | DRM_BUS_FLAG_PIXDATA_POSEDGE;
816 746
817 r = omapdss_register_display(dssdev); 747 omapdss_display_init(dssdev);
818 if (r) { 748 omapdss_device_register(dssdev);
819 dev_err(&spi->dev, "Failed to register panel\n");
820 goto err_reg;
821 }
822 749
823 return 0; 750 return 0;
824 751
825err_reg: 752err_backlight_unregister:
826 sysfs_remove_group(&bldev->dev.kobj, &bldev_attr_group);
827err_sysfs:
828 backlight_device_unregister(bldev); 753 backlight_device_unregister(bldev);
829err_reg_bl:
830err_detect:
831err_gpio:
832 return r; 754 return r;
833} 755}
834 756
@@ -842,10 +764,9 @@ static int acx565akm_remove(struct spi_device *spi)
842 sysfs_remove_group(&ddata->bl_dev->dev.kobj, &bldev_attr_group); 764 sysfs_remove_group(&ddata->bl_dev->dev.kobj, &bldev_attr_group);
843 backlight_device_unregister(ddata->bl_dev); 765 backlight_device_unregister(ddata->bl_dev);
844 766
845 omapdss_unregister_display(dssdev); 767 omapdss_device_unregister(dssdev);
846 768
847 acx565akm_disable(dssdev); 769 acx565akm_disable(dssdev);
848 acx565akm_disconnect(dssdev);
849 770
850 return 0; 771 return 0;
851} 772}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-tpo-td028ttec1.c b/drivers/gpu/drm/omapdrm/displays/panel-tpo-td028ttec1.c
index a1f1dc18407a..7ddc8c574a61 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-tpo-td028ttec1.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-tpo-td028ttec1.c
@@ -27,13 +27,11 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/gpio.h>
31 30
32#include "../dss/omapdss.h" 31#include "../dss/omapdss.h"
33 32
34struct panel_drv_data { 33struct panel_drv_data {
35 struct omap_dss_device dssdev; 34 struct omap_dss_device dssdev;
36 struct omap_dss_device *in;
37 35
38 struct videomode vm; 36 struct videomode vm;
39 37
@@ -51,13 +49,7 @@ static const struct videomode td028ttec1_panel_vm = {
51 .vsync_len = 2, 49 .vsync_len = 2,
52 .vback_porch = 2, 50 .vback_porch = 2,
53 51
54 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 52 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
55 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
56 DISPLAY_FLAGS_PIXDATA_NEGEDGE,
57 /*
58 * Note: According to the panel documentation:
59 * SYNC needs to be driven on the FALLING edge
60 */
61}; 53};
62 54
63#define JBT_COMMAND 0x000 55#define JBT_COMMAND 0x000
@@ -166,49 +158,21 @@ enum jbt_register {
166 158
167#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 159#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
168 160
169static int td028ttec1_panel_connect(struct omap_dss_device *dssdev) 161static int td028ttec1_panel_connect(struct omap_dss_device *src,
162 struct omap_dss_device *dst)
170{ 163{
171 struct panel_drv_data *ddata = to_panel_data(dssdev);
172 struct omap_dss_device *in;
173 int r;
174
175 if (omapdss_device_is_connected(dssdev))
176 return 0;
177
178 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
179 if (IS_ERR(in)) {
180 dev_err(dssdev->dev, "failed to find video source\n");
181 return PTR_ERR(in);
182 }
183
184 r = in->ops.dpi->connect(in, dssdev);
185 if (r) {
186 omap_dss_put_device(in);
187 return r;
188 }
189
190 ddata->in = in;
191 return 0; 164 return 0;
192} 165}
193 166
194static void td028ttec1_panel_disconnect(struct omap_dss_device *dssdev) 167static void td028ttec1_panel_disconnect(struct omap_dss_device *src,
168 struct omap_dss_device *dst)
195{ 169{
196 struct panel_drv_data *ddata = to_panel_data(dssdev);
197 struct omap_dss_device *in = ddata->in;
198
199 if (!omapdss_device_is_connected(dssdev))
200 return;
201
202 in->ops.dpi->disconnect(in, dssdev);
203
204 omap_dss_put_device(in);
205 ddata->in = NULL;
206} 170}
207 171
208static int td028ttec1_panel_enable(struct omap_dss_device *dssdev) 172static int td028ttec1_panel_enable(struct omap_dss_device *dssdev)
209{ 173{
210 struct panel_drv_data *ddata = to_panel_data(dssdev); 174 struct panel_drv_data *ddata = to_panel_data(dssdev);
211 struct omap_dss_device *in = ddata->in; 175 struct omap_dss_device *src = dssdev->src;
212 int r; 176 int r;
213 177
214 if (!omapdss_device_is_connected(dssdev)) 178 if (!omapdss_device_is_connected(dssdev))
@@ -217,9 +181,7 @@ static int td028ttec1_panel_enable(struct omap_dss_device *dssdev)
217 if (omapdss_device_is_enabled(dssdev)) 181 if (omapdss_device_is_enabled(dssdev))
218 return 0; 182 return 0;
219 183
220 in->ops.dpi->set_timings(in, &ddata->vm); 184 r = src->ops->enable(src);
221
222 r = in->ops.dpi->enable(in);
223 if (r) 185 if (r)
224 return r; 186 return r;
225 187
@@ -316,7 +278,7 @@ transfer_err:
316static void td028ttec1_panel_disable(struct omap_dss_device *dssdev) 278static void td028ttec1_panel_disable(struct omap_dss_device *dssdev)
317{ 279{
318 struct panel_drv_data *ddata = to_panel_data(dssdev); 280 struct panel_drv_data *ddata = to_panel_data(dssdev);
319 struct omap_dss_device *in = ddata->in; 281 struct omap_dss_device *src = dssdev->src;
320 282
321 if (!omapdss_device_is_enabled(dssdev)) 283 if (!omapdss_device_is_enabled(dssdev))
322 return; 284 return;
@@ -328,23 +290,11 @@ static void td028ttec1_panel_disable(struct omap_dss_device *dssdev)
328 jbt_ret_write_0(ddata, JBT_REG_SLEEP_IN); 290 jbt_ret_write_0(ddata, JBT_REG_SLEEP_IN);
329 jbt_reg_write_1(ddata, JBT_REG_POWER_ON_OFF, 0x00); 291 jbt_reg_write_1(ddata, JBT_REG_POWER_ON_OFF, 0x00);
330 292
331 in->ops.dpi->disable(in); 293 src->ops->disable(src);
332 294
333 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 295 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
334} 296}
335 297
336static void td028ttec1_panel_set_timings(struct omap_dss_device *dssdev,
337 struct videomode *vm)
338{
339 struct panel_drv_data *ddata = to_panel_data(dssdev);
340 struct omap_dss_device *in = ddata->in;
341
342 ddata->vm = *vm;
343 dssdev->panel.vm = *vm;
344
345 in->ops.dpi->set_timings(in, vm);
346}
347
348static void td028ttec1_panel_get_timings(struct omap_dss_device *dssdev, 298static void td028ttec1_panel_get_timings(struct omap_dss_device *dssdev,
349 struct videomode *vm) 299 struct videomode *vm)
350{ 300{
@@ -353,25 +303,14 @@ static void td028ttec1_panel_get_timings(struct omap_dss_device *dssdev,
353 *vm = ddata->vm; 303 *vm = ddata->vm;
354} 304}
355 305
356static int td028ttec1_panel_check_timings(struct omap_dss_device *dssdev, 306static const struct omap_dss_device_ops td028ttec1_ops = {
357 struct videomode *vm)
358{
359 struct panel_drv_data *ddata = to_panel_data(dssdev);
360 struct omap_dss_device *in = ddata->in;
361
362 return in->ops.dpi->check_timings(in, vm);
363}
364
365static struct omap_dss_driver td028ttec1_ops = {
366 .connect = td028ttec1_panel_connect, 307 .connect = td028ttec1_panel_connect,
367 .disconnect = td028ttec1_panel_disconnect, 308 .disconnect = td028ttec1_panel_disconnect,
368 309
369 .enable = td028ttec1_panel_enable, 310 .enable = td028ttec1_panel_enable,
370 .disable = td028ttec1_panel_disable, 311 .disable = td028ttec1_panel_disable,
371 312
372 .set_timings = td028ttec1_panel_set_timings,
373 .get_timings = td028ttec1_panel_get_timings, 313 .get_timings = td028ttec1_panel_get_timings,
374 .check_timings = td028ttec1_panel_check_timings,
375}; 314};
376 315
377static int td028ttec1_panel_probe(struct spi_device *spi) 316static int td028ttec1_panel_probe(struct spi_device *spi)
@@ -403,16 +342,20 @@ static int td028ttec1_panel_probe(struct spi_device *spi)
403 342
404 dssdev = &ddata->dssdev; 343 dssdev = &ddata->dssdev;
405 dssdev->dev = &spi->dev; 344 dssdev->dev = &spi->dev;
406 dssdev->driver = &td028ttec1_ops; 345 dssdev->ops = &td028ttec1_ops;
407 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 346 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
408 dssdev->owner = THIS_MODULE; 347 dssdev->owner = THIS_MODULE;
409 dssdev->panel.vm = ddata->vm; 348 dssdev->of_ports = BIT(0);
410 349
411 r = omapdss_register_display(dssdev); 350 /*
412 if (r) { 351 * Note: According to the panel documentation:
413 dev_err(&spi->dev, "Failed to register panel\n"); 352 * SYNC needs to be driven on the FALLING edge
414 return r; 353 */
415 } 354 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
355 | DRM_BUS_FLAG_PIXDATA_NEGEDGE;
356
357 omapdss_display_init(dssdev);
358 omapdss_device_register(dssdev);
416 359
417 return 0; 360 return 0;
418} 361}
@@ -424,10 +367,9 @@ static int td028ttec1_panel_remove(struct spi_device *spi)
424 367
425 dev_dbg(&ddata->spi_dev->dev, "%s\n", __func__); 368 dev_dbg(&ddata->spi_dev->dev, "%s\n", __func__);
426 369
427 omapdss_unregister_display(dssdev); 370 omapdss_device_unregister(dssdev);
428 371
429 td028ttec1_panel_disable(dssdev); 372 td028ttec1_panel_disable(dssdev);
430 td028ttec1_panel_disconnect(dssdev);
431 373
432 return 0; 374 return 0;
433} 375}
diff --git a/drivers/gpu/drm/omapdrm/displays/panel-tpo-td043mtea1.c b/drivers/gpu/drm/omapdrm/displays/panel-tpo-td043mtea1.c
index c08e22b43447..8440fcb744d9 100644
--- a/drivers/gpu/drm/omapdrm/displays/panel-tpo-td043mtea1.c
+++ b/drivers/gpu/drm/omapdrm/displays/panel-tpo-td043mtea1.c
@@ -10,14 +10,13 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/delay.h> 13#include <linux/delay.h>
15#include <linux/spi/spi.h>
16#include <linux/regulator/consumer.h>
17#include <linux/gpio/consumer.h>
18#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/gpio/consumer.h>
16#include <linux/module.h>
17#include <linux/regulator/consumer.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/of_gpio.h> 19#include <linux/spi/spi.h>
21 20
22#include "../dss/omapdss.h" 21#include "../dss/omapdss.h"
23 22
@@ -54,16 +53,14 @@ static const u16 tpo_td043_def_gamma[12] = {
54 53
55struct panel_drv_data { 54struct panel_drv_data {
56 struct omap_dss_device dssdev; 55 struct omap_dss_device dssdev;
57 struct omap_dss_device *in;
58 56
59 struct videomode vm; 57 struct videomode vm;
60 58
61 struct spi_device *spi; 59 struct spi_device *spi;
62 struct regulator *vcc_reg; 60 struct regulator *vcc_reg;
63 int nreset_gpio; 61 struct gpio_desc *reset_gpio;
64 u16 gamma[12]; 62 u16 gamma[12];
65 u32 mode; 63 u32 mode;
66 u32 hmirror:1;
67 u32 vmirror:1; 64 u32 vmirror:1;
68 u32 powered_on:1; 65 u32 powered_on:1;
69 u32 spi_suspended:1; 66 u32 spi_suspended:1;
@@ -84,13 +81,7 @@ static const struct videomode tpo_td043_vm = {
84 .vfront_porch = 39, 81 .vfront_porch = 39,
85 .vback_porch = 34, 82 .vback_porch = 34,
86 83
87 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | 84 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
88 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
89 DISPLAY_FLAGS_PIXDATA_NEGEDGE,
90 /*
91 * Note: According to the panel documentation:
92 * SYNC needs to be driven on the FALLING edge
93 */
94}; 85};
95 86
96#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev) 87#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
@@ -152,22 +143,6 @@ static int tpo_td043_write_mirror(struct spi_device *spi, bool h, bool v)
152 return tpo_td043_write(spi, 4, reg4); 143 return tpo_td043_write(spi, 4, reg4);
153} 144}
154 145
155static int tpo_td043_set_hmirror(struct omap_dss_device *dssdev, bool enable)
156{
157 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
158
159 ddata->hmirror = enable;
160 return tpo_td043_write_mirror(ddata->spi, ddata->hmirror,
161 ddata->vmirror);
162}
163
164static bool tpo_td043_get_hmirror(struct omap_dss_device *dssdev)
165{
166 struct panel_drv_data *ddata = dev_get_drvdata(dssdev->dev);
167
168 return ddata->hmirror;
169}
170
171static ssize_t tpo_td043_vmirror_show(struct device *dev, 146static ssize_t tpo_td043_vmirror_show(struct device *dev,
172 struct device_attribute *attr, char *buf) 147 struct device_attribute *attr, char *buf)
173{ 148{
@@ -189,7 +164,7 @@ static ssize_t tpo_td043_vmirror_store(struct device *dev,
189 164
190 val = !!val; 165 val = !!val;
191 166
192 ret = tpo_td043_write_mirror(ddata->spi, ddata->hmirror, val); 167 ret = tpo_td043_write_mirror(ddata->spi, false, val);
193 if (ret < 0) 168 if (ret < 0)
194 return ret; 169 return ret;
195 170
@@ -300,16 +275,14 @@ static int tpo_td043_power_on(struct panel_drv_data *ddata)
300 /* wait for panel to stabilize */ 275 /* wait for panel to stabilize */
301 msleep(160); 276 msleep(160);
302 277
303 if (gpio_is_valid(ddata->nreset_gpio)) 278 gpiod_set_value(ddata->reset_gpio, 0);
304 gpio_set_value(ddata->nreset_gpio, 1);
305 279
306 tpo_td043_write(ddata->spi, 2, 280 tpo_td043_write(ddata->spi, 2,
307 TPO_R02_MODE(ddata->mode) | TPO_R02_NCLK_RISING); 281 TPO_R02_MODE(ddata->mode) | TPO_R02_NCLK_RISING);
308 tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_NORMAL); 282 tpo_td043_write(ddata->spi, 3, TPO_R03_VAL_NORMAL);
309 tpo_td043_write(ddata->spi, 0x20, 0xf0); 283 tpo_td043_write(ddata->spi, 0x20, 0xf0);
310 tpo_td043_write(ddata->spi, 0x21, 0xf0); 284 tpo_td043_write(ddata->spi, 0x21, 0xf0);
311 tpo_td043_write_mirror(ddata->spi, ddata->hmirror, 285 tpo_td043_write_mirror(ddata->spi, false, ddata->vmirror);
312 ddata->vmirror);
313 tpo_td043_write_gamma(ddata->spi, ddata->gamma); 286 tpo_td043_write_gamma(ddata->spi, ddata->gamma);
314 287
315 ddata->powered_on = 1; 288 ddata->powered_on = 1;
@@ -324,8 +297,7 @@ static void tpo_td043_power_off(struct panel_drv_data *ddata)
324 tpo_td043_write(ddata->spi, 3, 297 tpo_td043_write(ddata->spi, 3,
325 TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM); 298 TPO_R03_VAL_STANDBY | TPO_R03_EN_PWM);
326 299
327 if (gpio_is_valid(ddata->nreset_gpio)) 300 gpiod_set_value(ddata->reset_gpio, 1);
328 gpio_set_value(ddata->nreset_gpio, 0);
329 301
330 /* wait for at least 2 vsyncs before cutting off power */ 302 /* wait for at least 2 vsyncs before cutting off power */
331 msleep(50); 303 msleep(50);
@@ -337,49 +309,21 @@ static void tpo_td043_power_off(struct panel_drv_data *ddata)
337 ddata->powered_on = 0; 309 ddata->powered_on = 0;
338} 310}
339 311
340static int tpo_td043_connect(struct omap_dss_device *dssdev) 312static int tpo_td043_connect(struct omap_dss_device *src,
313 struct omap_dss_device *dst)
341{ 314{
342 struct panel_drv_data *ddata = to_panel_data(dssdev);
343 struct omap_dss_device *in;
344 int r;
345
346 if (omapdss_device_is_connected(dssdev))
347 return 0;
348
349 in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
350 if (IS_ERR(in)) {
351 dev_err(dssdev->dev, "failed to find video source\n");
352 return PTR_ERR(in);
353 }
354
355 r = in->ops.dpi->connect(in, dssdev);
356 if (r) {
357 omap_dss_put_device(in);
358 return r;
359 }
360
361 ddata->in = in;
362 return 0; 315 return 0;
363} 316}
364 317
365static void tpo_td043_disconnect(struct omap_dss_device *dssdev) 318static void tpo_td043_disconnect(struct omap_dss_device *src,
319 struct omap_dss_device *dst)
366{ 320{
367 struct panel_drv_data *ddata = to_panel_data(dssdev);
368 struct omap_dss_device *in = ddata->in;
369
370 if (!omapdss_device_is_connected(dssdev))
371 return;
372
373 in->ops.dpi->disconnect(in, dssdev);
374
375 omap_dss_put_device(in);
376 ddata->in = NULL;
377} 321}
378 322
379static int tpo_td043_enable(struct omap_dss_device *dssdev) 323static int tpo_td043_enable(struct omap_dss_device *dssdev)
380{ 324{
381 struct panel_drv_data *ddata = to_panel_data(dssdev); 325 struct panel_drv_data *ddata = to_panel_data(dssdev);
382 struct omap_dss_device *in = ddata->in; 326 struct omap_dss_device *src = dssdev->src;
383 int r; 327 int r;
384 328
385 if (!omapdss_device_is_connected(dssdev)) 329 if (!omapdss_device_is_connected(dssdev))
@@ -388,9 +332,7 @@ static int tpo_td043_enable(struct omap_dss_device *dssdev)
388 if (omapdss_device_is_enabled(dssdev)) 332 if (omapdss_device_is_enabled(dssdev))
389 return 0; 333 return 0;
390 334
391 in->ops.dpi->set_timings(in, &ddata->vm); 335 r = src->ops->enable(src);
392
393 r = in->ops.dpi->enable(in);
394 if (r) 336 if (r)
395 return r; 337 return r;
396 338
@@ -401,7 +343,7 @@ static int tpo_td043_enable(struct omap_dss_device *dssdev)
401 if (!ddata->spi_suspended) { 343 if (!ddata->spi_suspended) {
402 r = tpo_td043_power_on(ddata); 344 r = tpo_td043_power_on(ddata);
403 if (r) { 345 if (r) {
404 in->ops.dpi->disable(in); 346 src->ops->disable(src);
405 return r; 347 return r;
406 } 348 }
407 } 349 }
@@ -414,12 +356,12 @@ static int tpo_td043_enable(struct omap_dss_device *dssdev)
414static void tpo_td043_disable(struct omap_dss_device *dssdev) 356static void tpo_td043_disable(struct omap_dss_device *dssdev)
415{ 357{
416 struct panel_drv_data *ddata = to_panel_data(dssdev); 358 struct panel_drv_data *ddata = to_panel_data(dssdev);
417 struct omap_dss_device *in = ddata->in; 359 struct omap_dss_device *src = dssdev->src;
418 360
419 if (!omapdss_device_is_enabled(dssdev)) 361 if (!omapdss_device_is_enabled(dssdev))
420 return; 362 return;
421 363
422 in->ops.dpi->disable(in); 364 src->ops->disable(src);
423 365
424 if (!ddata->spi_suspended) 366 if (!ddata->spi_suspended)
425 tpo_td043_power_off(ddata); 367 tpo_td043_power_off(ddata);
@@ -427,18 +369,6 @@ static void tpo_td043_disable(struct omap_dss_device *dssdev)
427 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 369 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
428} 370}
429 371
430static void tpo_td043_set_timings(struct omap_dss_device *dssdev,
431 struct videomode *vm)
432{
433 struct panel_drv_data *ddata = to_panel_data(dssdev);
434 struct omap_dss_device *in = ddata->in;
435
436 ddata->vm = *vm;
437 dssdev->panel.vm = *vm;
438
439 in->ops.dpi->set_timings(in, vm);
440}
441
442static void tpo_td043_get_timings(struct omap_dss_device *dssdev, 372static void tpo_td043_get_timings(struct omap_dss_device *dssdev,
443 struct videomode *vm) 373 struct videomode *vm)
444{ 374{
@@ -447,50 +377,21 @@ static void tpo_td043_get_timings(struct omap_dss_device *dssdev,
447 *vm = ddata->vm; 377 *vm = ddata->vm;
448} 378}
449 379
450static int tpo_td043_check_timings(struct omap_dss_device *dssdev, 380static const struct omap_dss_device_ops tpo_td043_ops = {
451 struct videomode *vm)
452{
453 struct panel_drv_data *ddata = to_panel_data(dssdev);
454 struct omap_dss_device *in = ddata->in;
455
456 return in->ops.dpi->check_timings(in, vm);
457}
458
459static struct omap_dss_driver tpo_td043_ops = {
460 .connect = tpo_td043_connect, 381 .connect = tpo_td043_connect,
461 .disconnect = tpo_td043_disconnect, 382 .disconnect = tpo_td043_disconnect,
462 383
463 .enable = tpo_td043_enable, 384 .enable = tpo_td043_enable,
464 .disable = tpo_td043_disable, 385 .disable = tpo_td043_disable,
465 386
466 .set_timings = tpo_td043_set_timings,
467 .get_timings = tpo_td043_get_timings, 387 .get_timings = tpo_td043_get_timings,
468 .check_timings = tpo_td043_check_timings,
469
470 .set_mirror = tpo_td043_set_hmirror,
471 .get_mirror = tpo_td043_get_hmirror,
472}; 388};
473 389
474static int tpo_td043_probe_of(struct spi_device *spi)
475{
476 struct device_node *node = spi->dev.of_node;
477 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
478 int gpio;
479
480 gpio = of_get_named_gpio(node, "reset-gpios", 0);
481 if (!gpio_is_valid(gpio)) {
482 dev_err(&spi->dev, "failed to parse enable gpio\n");
483 return gpio;
484 }
485 ddata->nreset_gpio = gpio;
486
487 return 0;
488}
489
490static int tpo_td043_probe(struct spi_device *spi) 390static int tpo_td043_probe(struct spi_device *spi)
491{ 391{
492 struct panel_drv_data *ddata; 392 struct panel_drv_data *ddata;
493 struct omap_dss_device *dssdev; 393 struct omap_dss_device *dssdev;
394 struct gpio_desc *gpio;
494 int r; 395 int r;
495 396
496 dev_dbg(&spi->dev, "%s\n", __func__); 397 dev_dbg(&spi->dev, "%s\n", __func__);
@@ -512,59 +413,49 @@ static int tpo_td043_probe(struct spi_device *spi)
512 413
513 ddata->spi = spi; 414 ddata->spi = spi;
514 415
515 r = tpo_td043_probe_of(spi);
516 if (r)
517 return r;
518
519 ddata->mode = TPO_R02_MODE_800x480; 416 ddata->mode = TPO_R02_MODE_800x480;
520 memcpy(ddata->gamma, tpo_td043_def_gamma, sizeof(ddata->gamma)); 417 memcpy(ddata->gamma, tpo_td043_def_gamma, sizeof(ddata->gamma));
521 418
522 ddata->vcc_reg = devm_regulator_get(&spi->dev, "vcc"); 419 ddata->vcc_reg = devm_regulator_get(&spi->dev, "vcc");
523 if (IS_ERR(ddata->vcc_reg)) { 420 if (IS_ERR(ddata->vcc_reg)) {
524 dev_err(&spi->dev, "failed to get LCD VCC regulator\n"); 421 dev_err(&spi->dev, "failed to get LCD VCC regulator\n");
525 r = PTR_ERR(ddata->vcc_reg); 422 return PTR_ERR(ddata->vcc_reg);
526 goto err_regulator;
527 } 423 }
528 424
529 if (gpio_is_valid(ddata->nreset_gpio)) { 425 gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_HIGH);
530 r = devm_gpio_request_one(&spi->dev, 426 if (IS_ERR(gpio)) {
531 ddata->nreset_gpio, GPIOF_OUT_INIT_LOW, 427 dev_err(&spi->dev, "failed to get reset gpio\n");
532 "lcd reset"); 428 return PTR_ERR(gpio);
533 if (r < 0) {
534 dev_err(&spi->dev, "couldn't request reset GPIO\n");
535 goto err_gpio_req;
536 }
537 } 429 }
538 430
431 ddata->reset_gpio = gpio;
432
539 r = sysfs_create_group(&spi->dev.kobj, &tpo_td043_attr_group); 433 r = sysfs_create_group(&spi->dev.kobj, &tpo_td043_attr_group);
540 if (r) { 434 if (r) {
541 dev_err(&spi->dev, "failed to create sysfs files\n"); 435 dev_err(&spi->dev, "failed to create sysfs files\n");
542 goto err_sysfs; 436 return r;
543 } 437 }
544 438
545 ddata->vm = tpo_td043_vm; 439 ddata->vm = tpo_td043_vm;
546 440
547 dssdev = &ddata->dssdev; 441 dssdev = &ddata->dssdev;
548 dssdev->dev = &spi->dev; 442 dssdev->dev = &spi->dev;
549 dssdev->driver = &tpo_td043_ops; 443 dssdev->ops = &tpo_td043_ops;
550 dssdev->type = OMAP_DISPLAY_TYPE_DPI; 444 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
551 dssdev->owner = THIS_MODULE; 445 dssdev->owner = THIS_MODULE;
552 dssdev->panel.vm = ddata->vm; 446 dssdev->of_ports = BIT(0);
553 447
554 r = omapdss_register_display(dssdev); 448 /*
555 if (r) { 449 * Note: According to the panel documentation:
556 dev_err(&spi->dev, "Failed to register panel\n"); 450 * SYNC needs to be driven on the FALLING edge
557 goto err_reg; 451 */
558 } 452 dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
453 | DRM_BUS_FLAG_PIXDATA_NEGEDGE;
559 454
560 return 0; 455 omapdss_display_init(dssdev);
456 omapdss_device_register(dssdev);
561 457
562err_reg: 458 return 0;
563 sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group);
564err_sysfs:
565err_gpio_req:
566err_regulator:
567 return r;
568} 459}
569 460
570static int tpo_td043_remove(struct spi_device *spi) 461static int tpo_td043_remove(struct spi_device *spi)
@@ -574,10 +465,9 @@ static int tpo_td043_remove(struct spi_device *spi)
574 465
575 dev_dbg(&ddata->spi->dev, "%s\n", __func__); 466 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
576 467
577 omapdss_unregister_display(dssdev); 468 omapdss_device_unregister(dssdev);
578 469
579 tpo_td043_disable(dssdev); 470 tpo_td043_disable(dssdev);
580 tpo_td043_disconnect(dssdev);
581 471
582 sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group); 472 sysfs_remove_group(&spi->dev.kobj, &tpo_td043_attr_group);
583 473
diff --git a/drivers/gpu/drm/omapdrm/dss/base.c b/drivers/gpu/drm/omapdrm/dss/base.c
index 99e8cb8dc65b..472f56e3de70 100644
--- a/drivers/gpu/drm/omapdrm/dss/base.c
+++ b/drivers/gpu/drm/omapdrm/dss/base.c
@@ -14,24 +14,17 @@
14 */ 14 */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/list.h>
17#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/mutex.h>
18#include <linux/of.h> 20#include <linux/of.h>
19#include <linux/of_graph.h> 21#include <linux/of_graph.h>
20#include <linux/list.h>
21 22
22#include "dss.h" 23#include "dss.h"
23#include "omapdss.h" 24#include "omapdss.h"
24 25
25static struct dss_device *dss_device; 26static struct dss_device *dss_device;
26 27
27static struct list_head omapdss_comp_list;
28
29struct omapdss_comp_node {
30 struct list_head list;
31 struct device_node *node;
32 bool dss_core_component;
33};
34
35struct dss_device *omapdss_get_dss(void) 28struct dss_device *omapdss_get_dss(void)
36{ 29{
37 return dss_device; 30 return dss_device;
@@ -56,6 +49,208 @@ const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
56} 49}
57EXPORT_SYMBOL(dispc_get_ops); 50EXPORT_SYMBOL(dispc_get_ops);
58 51
52
53/* -----------------------------------------------------------------------------
54 * OMAP DSS Devices Handling
55 */
56
57static LIST_HEAD(omapdss_devices_list);
58static DEFINE_MUTEX(omapdss_devices_lock);
59
60void omapdss_device_register(struct omap_dss_device *dssdev)
61{
62 mutex_lock(&omapdss_devices_lock);
63 list_add_tail(&dssdev->list, &omapdss_devices_list);
64 mutex_unlock(&omapdss_devices_lock);
65}
66EXPORT_SYMBOL_GPL(omapdss_device_register);
67
68void omapdss_device_unregister(struct omap_dss_device *dssdev)
69{
70 mutex_lock(&omapdss_devices_lock);
71 list_del(&dssdev->list);
72 mutex_unlock(&omapdss_devices_lock);
73}
74EXPORT_SYMBOL_GPL(omapdss_device_unregister);
75
76static bool omapdss_device_is_registered(struct device_node *node)
77{
78 struct omap_dss_device *dssdev;
79 bool found = false;
80
81 mutex_lock(&omapdss_devices_lock);
82
83 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
84 if (dssdev->dev->of_node == node) {
85 found = true;
86 break;
87 }
88 }
89
90 mutex_unlock(&omapdss_devices_lock);
91 return found;
92}
93
94struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev)
95{
96 if (!try_module_get(dssdev->owner))
97 return NULL;
98
99 if (get_device(dssdev->dev) == NULL) {
100 module_put(dssdev->owner);
101 return NULL;
102 }
103
104 return dssdev;
105}
106EXPORT_SYMBOL(omapdss_device_get);
107
108void omapdss_device_put(struct omap_dss_device *dssdev)
109{
110 put_device(dssdev->dev);
111 module_put(dssdev->owner);
112}
113EXPORT_SYMBOL(omapdss_device_put);
114
115struct omap_dss_device *omapdss_find_device_by_port(struct device_node *src,
116 unsigned int port)
117{
118 struct omap_dss_device *dssdev;
119
120 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
121 if (dssdev->dev->of_node == src && dssdev->of_ports & BIT(port))
122 return omapdss_device_get(dssdev);
123 }
124
125 return NULL;
126}
127
128/*
129 * Search for the next device starting at @from. The type argument specfies
130 * which device types to consider when searching. Searching for multiple types
131 * is supported by and'ing their type flags. Release the reference to the @from
132 * device, and acquire a reference to the returned device if found.
133 */
134struct omap_dss_device *omapdss_device_get_next(struct omap_dss_device *from,
135 enum omap_dss_device_type type)
136{
137 struct omap_dss_device *dssdev;
138 struct list_head *list;
139
140 mutex_lock(&omapdss_devices_lock);
141
142 if (list_empty(&omapdss_devices_list)) {
143 dssdev = NULL;
144 goto done;
145 }
146
147 /*
148 * Start from the from entry if given or from omapdss_devices_list
149 * otherwise.
150 */
151 list = from ? &from->list : &omapdss_devices_list;
152
153 list_for_each_entry(dssdev, list, list) {
154 /*
155 * Stop if we reach the omapdss_devices_list, that's the end of
156 * the list.
157 */
158 if (&dssdev->list == &omapdss_devices_list) {
159 dssdev = NULL;
160 goto done;
161 }
162
163 /*
164 * Accept display entities if the display type is requested,
165 * and output entities if the output type is requested.
166 */
167 if ((type & OMAP_DSS_DEVICE_TYPE_DISPLAY) &&
168 !dssdev->output_type)
169 goto done;
170 if ((type & OMAP_DSS_DEVICE_TYPE_OUTPUT) && dssdev->id &&
171 dssdev->next)
172 goto done;
173 }
174
175 dssdev = NULL;
176
177done:
178 if (from)
179 omapdss_device_put(from);
180 if (dssdev)
181 omapdss_device_get(dssdev);
182
183 mutex_unlock(&omapdss_devices_lock);
184 return dssdev;
185}
186EXPORT_SYMBOL(omapdss_device_get_next);
187
188int omapdss_device_connect(struct dss_device *dss,
189 struct omap_dss_device *src,
190 struct omap_dss_device *dst)
191{
192 int ret;
193
194 dev_dbg(dst->dev, "connect\n");
195
196 if (omapdss_device_is_connected(dst))
197 return -EBUSY;
198
199 dst->dss = dss;
200
201 ret = dst->ops->connect(src, dst);
202 if (ret < 0) {
203 dst->dss = NULL;
204 return ret;
205 }
206
207 if (src) {
208 WARN_ON(src->dst);
209 dst->src = src;
210 src->dst = dst;
211 }
212
213 return 0;
214}
215EXPORT_SYMBOL_GPL(omapdss_device_connect);
216
217void omapdss_device_disconnect(struct omap_dss_device *src,
218 struct omap_dss_device *dst)
219{
220 dev_dbg(dst->dev, "disconnect\n");
221
222 if (!dst->id && !omapdss_device_is_connected(dst)) {
223 WARN_ON(dst->output_type);
224 return;
225 }
226
227 if (src) {
228 if (WARN_ON(dst != src->dst))
229 return;
230
231 dst->src = NULL;
232 src->dst = NULL;
233 }
234
235 WARN_ON(dst->state != OMAP_DSS_DISPLAY_DISABLED);
236
237 dst->ops->disconnect(src, dst);
238 dst->dss = NULL;
239}
240EXPORT_SYMBOL_GPL(omapdss_device_disconnect);
241
242/* -----------------------------------------------------------------------------
243 * Components Handling
244 */
245
246static struct list_head omapdss_comp_list;
247
248struct omapdss_comp_node {
249 struct list_head list;
250 struct device_node *node;
251 bool dss_core_component;
252};
253
59static bool omapdss_list_contains(const struct device_node *node) 254static bool omapdss_list_contains(const struct device_node *node)
60{ 255{
61 struct omapdss_comp_node *comp; 256 struct omapdss_comp_node *comp;
@@ -130,9 +325,7 @@ static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
130{ 325{
131 if (comp->dss_core_component) 326 if (comp->dss_core_component)
132 return true; 327 return true;
133 if (omapdss_component_is_display(comp->node)) 328 if (omapdss_device_is_registered(comp->node))
134 return true;
135 if (omapdss_component_is_output(comp->node))
136 return true; 329 return true;
137 330
138 return false; 331 return false;
diff --git a/drivers/gpu/drm/omapdrm/dss/core.c b/drivers/gpu/drm/omapdrm/dss/core.c
index 07d00a186f15..a2edabc9f6b3 100644
--- a/drivers/gpu/drm/omapdrm/dss/core.c
+++ b/drivers/gpu/drm/omapdrm/dss/core.c
@@ -45,36 +45,14 @@ static struct platform_driver * const omap_dss_drivers[] = {
45#endif 45#endif
46}; 46};
47 47
48static struct platform_device *omap_drm_device;
49
50static int __init omap_dss_init(void) 48static int __init omap_dss_init(void)
51{ 49{
52 int r; 50 return platform_register_drivers(omap_dss_drivers,
53 51 ARRAY_SIZE(omap_dss_drivers));
54 r = platform_register_drivers(omap_dss_drivers,
55 ARRAY_SIZE(omap_dss_drivers));
56 if (r)
57 goto err_reg;
58
59 omap_drm_device = platform_device_register_simple("omapdrm", 0, NULL, 0);
60 if (IS_ERR(omap_drm_device)) {
61 r = PTR_ERR(omap_drm_device);
62 goto err_reg;
63 }
64
65 return 0;
66
67err_reg:
68 platform_unregister_drivers(omap_dss_drivers,
69 ARRAY_SIZE(omap_dss_drivers));
70
71 return r;
72} 52}
73 53
74static void __exit omap_dss_exit(void) 54static void __exit omap_dss_exit(void)
75{ 55{
76 platform_device_unregister(omap_drm_device);
77
78 platform_unregister_drivers(omap_dss_drivers, 56 platform_unregister_drivers(omap_dss_drivers,
79 ARRAY_SIZE(omap_dss_drivers)); 57 ARRAY_SIZE(omap_dss_drivers));
80} 58}
diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c
index 84f274c4a4cb..e61a9592a650 100644
--- a/drivers/gpu/drm/omapdrm/dss/dispc.c
+++ b/drivers/gpu/drm/omapdrm/dss/dispc.c
@@ -2904,13 +2904,6 @@ static int dispc_ovl_enable(struct dispc_device *dispc,
2904 return 0; 2904 return 0;
2905} 2905}
2906 2906
2907static enum omap_dss_output_id
2908dispc_mgr_get_supported_outputs(struct dispc_device *dispc,
2909 enum omap_channel channel)
2910{
2911 return dss_get_supported_outputs(dispc->dss, channel);
2912}
2913
2914static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc, 2907static void dispc_lcd_enable_signal_polarity(struct dispc_device *dispc,
2915 bool act_high) 2908 bool act_high)
2916{ 2909{
@@ -3120,28 +3113,29 @@ static bool _dispc_mgr_pclk_ok(struct dispc_device *dispc,
3120 return pclk <= dispc->feat->max_tv_pclk; 3113 return pclk <= dispc->feat->max_tv_pclk;
3121} 3114}
3122 3115
3123bool dispc_mgr_timings_ok(struct dispc_device *dispc, enum omap_channel channel, 3116static int dispc_mgr_check_timings(struct dispc_device *dispc,
3124 const struct videomode *vm) 3117 enum omap_channel channel,
3118 const struct videomode *vm)
3125{ 3119{
3126 if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive)) 3120 if (!_dispc_mgr_size_ok(dispc, vm->hactive, vm->vactive))
3127 return false; 3121 return MODE_BAD;
3128 3122
3129 if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock)) 3123 if (!_dispc_mgr_pclk_ok(dispc, channel, vm->pixelclock))
3130 return false; 3124 return MODE_BAD;
3131 3125
3132 if (dss_mgr_is_lcd(channel)) { 3126 if (dss_mgr_is_lcd(channel)) {
3133 /* TODO: OMAP4+ supports interlace for LCD outputs */ 3127 /* TODO: OMAP4+ supports interlace for LCD outputs */
3134 if (vm->flags & DISPLAY_FLAGS_INTERLACED) 3128 if (vm->flags & DISPLAY_FLAGS_INTERLACED)
3135 return false; 3129 return MODE_BAD;
3136 3130
3137 if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len, 3131 if (!_dispc_lcd_timings_ok(dispc, vm->hsync_len,
3138 vm->hfront_porch, vm->hback_porch, 3132 vm->hfront_porch, vm->hback_porch,
3139 vm->vsync_len, vm->vfront_porch, 3133 vm->vsync_len, vm->vfront_porch,
3140 vm->vback_porch)) 3134 vm->vback_porch))
3141 return false; 3135 return MODE_BAD;
3142 } 3136 }
3143 3137
3144 return true; 3138 return MODE_OK;
3145} 3139}
3146 3140
3147static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc, 3141static void _dispc_mgr_set_lcd_timings(struct dispc_device *dispc,
@@ -3243,7 +3237,7 @@ static void dispc_mgr_set_timings(struct dispc_device *dispc,
3243 3237
3244 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive); 3238 DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive);
3245 3239
3246 if (!dispc_mgr_timings_ok(dispc, channel, &t)) { 3240 if (dispc_mgr_check_timings(dispc, channel, &t)) {
3247 BUG(); 3241 BUG();
3248 return; 3242 return;
3249 } 3243 }
@@ -4740,9 +4734,9 @@ static const struct dispc_ops dispc_ops = {
4740 .mgr_go_busy = dispc_mgr_go_busy, 4734 .mgr_go_busy = dispc_mgr_go_busy,
4741 .mgr_go = dispc_mgr_go, 4735 .mgr_go = dispc_mgr_go,
4742 .mgr_set_lcd_config = dispc_mgr_set_lcd_config, 4736 .mgr_set_lcd_config = dispc_mgr_set_lcd_config,
4737 .mgr_check_timings = dispc_mgr_check_timings,
4743 .mgr_set_timings = dispc_mgr_set_timings, 4738 .mgr_set_timings = dispc_mgr_set_timings,
4744 .mgr_setup = dispc_mgr_setup, 4739 .mgr_setup = dispc_mgr_setup,
4745 .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs,
4746 .mgr_gamma_size = dispc_mgr_gamma_size, 4740 .mgr_gamma_size = dispc_mgr_gamma_size,
4747 .mgr_set_gamma = dispc_mgr_set_gamma, 4741 .mgr_set_gamma = dispc_mgr_set_gamma,
4748 4742
diff --git a/drivers/gpu/drm/omapdrm/dss/display.c b/drivers/gpu/drm/omapdrm/dss/display.c
index 9e7fcbd57e52..34b2a4ef63a4 100644
--- a/drivers/gpu/drm/omapdrm/dss/display.c
+++ b/drivers/gpu/drm/omapdrm/dss/display.c
@@ -21,27 +21,14 @@
21#define DSS_SUBSYS_NAME "DISPLAY" 21#define DSS_SUBSYS_NAME "DISPLAY"
22 22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/jiffies.h>
26#include <linux/platform_device.h>
27#include <linux/of.h> 24#include <linux/of.h>
28 25
29#include "omapdss.h" 26#include "omapdss.h"
30 27
31static void omapdss_default_get_timings(struct omap_dss_device *dssdev,
32 struct videomode *vm)
33{
34 *vm = dssdev->panel.vm;
35}
36
37static LIST_HEAD(panel_list);
38static DEFINE_MUTEX(panel_list_mutex);
39static int disp_num_counter; 28static int disp_num_counter;
40 29
41int omapdss_register_display(struct omap_dss_device *dssdev) 30void omapdss_display_init(struct omap_dss_device *dssdev)
42{ 31{
43 struct omap_dss_driver *drv = dssdev->driver;
44 struct list_head *cur;
45 int id; 32 int id;
46 33
47 /* 34 /*
@@ -52,123 +39,22 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52 if (id < 0) 39 if (id < 0)
53 id = disp_num_counter++; 40 id = disp_num_counter++;
54 41
55 snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id); 42 dssdev->alias_id = id;
56 43
57 /* Use 'label' property for name, if it exists */ 44 /* Use 'label' property for name, if it exists */
58 of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name); 45 of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
59 46
60 if (dssdev->name == NULL) 47 if (dssdev->name == NULL)
61 dssdev->name = dssdev->alias; 48 dssdev->name = devm_kasprintf(dssdev->dev, GFP_KERNEL,
62 49 "display%u", id);
63 if (drv && drv->get_timings == NULL)
64 drv->get_timings = omapdss_default_get_timings;
65
66 mutex_lock(&panel_list_mutex);
67 list_for_each(cur, &panel_list) {
68 struct omap_dss_device *ldev = list_entry(cur,
69 struct omap_dss_device,
70 panel_list);
71 if (strcmp(ldev->alias, dssdev->alias) > 0)
72 break;
73 }
74 list_add_tail(&dssdev->panel_list, cur);
75 mutex_unlock(&panel_list_mutex);
76 return 0;
77}
78EXPORT_SYMBOL(omapdss_register_display);
79
80void omapdss_unregister_display(struct omap_dss_device *dssdev)
81{
82 mutex_lock(&panel_list_mutex);
83 list_del(&dssdev->panel_list);
84 mutex_unlock(&panel_list_mutex);
85} 50}
86EXPORT_SYMBOL(omapdss_unregister_display); 51EXPORT_SYMBOL_GPL(omapdss_display_init);
87 52
88bool omapdss_component_is_display(struct device_node *node) 53struct omap_dss_device *omapdss_display_get(struct omap_dss_device *output)
89{ 54{
90 struct omap_dss_device *dssdev; 55 while (output->next)
91 bool found = false; 56 output = output->next;
92
93 mutex_lock(&panel_list_mutex);
94 list_for_each_entry(dssdev, &panel_list, panel_list) {
95 if (dssdev->dev->of_node == node) {
96 found = true;
97 goto out;
98 }
99 }
100out:
101 mutex_unlock(&panel_list_mutex);
102 return found;
103}
104EXPORT_SYMBOL(omapdss_component_is_display);
105
106struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
107{
108 if (!try_module_get(dssdev->owner))
109 return NULL;
110
111 if (get_device(dssdev->dev) == NULL) {
112 module_put(dssdev->owner);
113 return NULL;
114 }
115
116 return dssdev;
117}
118EXPORT_SYMBOL(omap_dss_get_device);
119
120void omap_dss_put_device(struct omap_dss_device *dssdev)
121{
122 put_device(dssdev->dev);
123 module_put(dssdev->owner);
124}
125EXPORT_SYMBOL(omap_dss_put_device);
126
127/*
128 * ref count of the found device is incremented.
129 * ref count of from-device is decremented.
130 */
131struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
132{
133 struct list_head *l;
134 struct omap_dss_device *dssdev;
135
136 mutex_lock(&panel_list_mutex);
137
138 if (list_empty(&panel_list)) {
139 dssdev = NULL;
140 goto out;
141 }
142
143 if (from == NULL) {
144 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
145 panel_list);
146 omap_dss_get_device(dssdev);
147 goto out;
148 }
149
150 omap_dss_put_device(from);
151
152 list_for_each(l, &panel_list) {
153 dssdev = list_entry(l, struct omap_dss_device, panel_list);
154 if (dssdev == from) {
155 if (list_is_last(l, &panel_list)) {
156 dssdev = NULL;
157 goto out;
158 }
159
160 dssdev = list_entry(l->next, struct omap_dss_device,
161 panel_list);
162 omap_dss_get_device(dssdev);
163 goto out;
164 }
165 }
166
167 WARN(1, "'from' dssdev not found\n");
168 57
169 dssdev = NULL; 58 return omapdss_device_get(output);
170out:
171 mutex_unlock(&panel_list_mutex);
172 return dssdev;
173} 59}
174EXPORT_SYMBOL(omap_dss_get_next_device); 60EXPORT_SYMBOL_GPL(omapdss_display_get);
diff --git a/drivers/gpu/drm/omapdrm/dss/dpi.c b/drivers/gpu/drm/omapdrm/dss/dpi.c
index 9fcc50217133..ca4f3c4c6318 100644
--- a/drivers/gpu/drm/omapdrm/dss/dpi.c
+++ b/drivers/gpu/drm/omapdrm/dss/dpi.c
@@ -39,6 +39,7 @@ struct dpi_data {
39 struct platform_device *pdev; 39 struct platform_device *pdev;
40 enum dss_model dss_model; 40 enum dss_model dss_model;
41 struct dss_device *dss; 41 struct dss_device *dss;
42 unsigned int id;
42 43
43 struct regulator *vdds_dsi_reg; 44 struct regulator *vdds_dsi_reg;
44 enum dss_clk_source clk_src; 45 enum dss_clk_source clk_src;
@@ -346,10 +347,9 @@ static int dpi_set_dispc_clk(struct dpi_data *dpi, unsigned long pck_req,
346 347
347static int dpi_set_mode(struct dpi_data *dpi) 348static int dpi_set_mode(struct dpi_data *dpi)
348{ 349{
349 struct videomode *vm = &dpi->vm; 350 const struct videomode *vm = &dpi->vm;
350 int lck_div = 0, pck_div = 0; 351 int lck_div = 0, pck_div = 0;
351 unsigned long fck = 0; 352 unsigned long fck = 0;
352 unsigned long pck;
353 int r = 0; 353 int r = 0;
354 354
355 if (dpi->pll) 355 if (dpi->pll)
@@ -361,17 +361,6 @@ static int dpi_set_mode(struct dpi_data *dpi)
361 if (r) 361 if (r)
362 return r; 362 return r;
363 363
364 pck = fck / lck_div / pck_div;
365
366 if (pck != vm->pixelclock) {
367 DSSWARN("Could not find exact pixel clock. Requested %lu Hz, got %lu Hz\n",
368 vm->pixelclock, pck);
369
370 vm->pixelclock = pck;
371 }
372
373 dss_mgr_set_timings(&dpi->output, vm);
374
375 return 0; 364 return 0;
376} 365}
377 366
@@ -413,7 +402,7 @@ static int dpi_display_enable(struct omap_dss_device *dssdev)
413 if (r) 402 if (r)
414 goto err_get_dispc; 403 goto err_get_dispc;
415 404
416 r = dss_dpi_select_source(dpi->dss, out->port_num, out->dispc_channel); 405 r = dss_dpi_select_source(dpi->dss, dpi->id, out->dispc_channel);
417 if (r) 406 if (r)
418 goto err_src_sel; 407 goto err_src_sel;
419 408
@@ -478,7 +467,7 @@ static void dpi_display_disable(struct omap_dss_device *dssdev)
478} 467}
479 468
480static void dpi_set_timings(struct omap_dss_device *dssdev, 469static void dpi_set_timings(struct omap_dss_device *dssdev,
481 struct videomode *vm) 470 const struct videomode *vm)
482{ 471{
483 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev); 472 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
484 473
@@ -491,23 +480,10 @@ static void dpi_set_timings(struct omap_dss_device *dssdev,
491 mutex_unlock(&dpi->lock); 480 mutex_unlock(&dpi->lock);
492} 481}
493 482
494static void dpi_get_timings(struct omap_dss_device *dssdev,
495 struct videomode *vm)
496{
497 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
498
499 mutex_lock(&dpi->lock);
500
501 *vm = dpi->vm;
502
503 mutex_unlock(&dpi->lock);
504}
505
506static int dpi_check_timings(struct omap_dss_device *dssdev, 483static int dpi_check_timings(struct omap_dss_device *dssdev,
507 struct videomode *vm) 484 struct videomode *vm)
508{ 485{
509 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev); 486 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
510 enum omap_channel channel = dpi->output.dispc_channel;
511 int lck_div, pck_div; 487 int lck_div, pck_div;
512 unsigned long fck; 488 unsigned long fck;
513 unsigned long pck; 489 unsigned long pck;
@@ -517,9 +493,6 @@ static int dpi_check_timings(struct omap_dss_device *dssdev,
517 if (vm->hactive % 8 != 0) 493 if (vm->hactive % 8 != 0)
518 return -EINVAL; 494 return -EINVAL;
519 495
520 if (!dispc_mgr_timings_ok(dpi->dss->dispc, channel, vm))
521 return -EINVAL;
522
523 if (vm->pixelclock == 0) 496 if (vm->pixelclock == 0)
524 return -EINVAL; 497 return -EINVAL;
525 498
@@ -562,38 +535,6 @@ static int dpi_verify_pll(struct dss_pll *pll)
562 return 0; 535 return 0;
563} 536}
564 537
565static const struct soc_device_attribute dpi_soc_devices[] = {
566 { .machine = "OMAP3[456]*" },
567 { .machine = "[AD]M37*" },
568 { /* sentinel */ }
569};
570
571static int dpi_init_regulator(struct dpi_data *dpi)
572{
573 struct regulator *vdds_dsi;
574
575 /*
576 * The DPI uses the DSI VDDS on OMAP34xx, OMAP35xx, OMAP36xx, AM37xx and
577 * DM37xx only.
578 */
579 if (!soc_device_match(dpi_soc_devices))
580 return 0;
581
582 if (dpi->vdds_dsi_reg)
583 return 0;
584
585 vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
586 if (IS_ERR(vdds_dsi)) {
587 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
588 DSSERR("can't get VDDS_DSI regulator\n");
589 return PTR_ERR(vdds_dsi);
590 }
591
592 dpi->vdds_dsi_reg = vdds_dsi;
593
594 return 0;
595}
596
597static void dpi_init_pll(struct dpi_data *dpi) 538static void dpi_init_pll(struct dpi_data *dpi)
598{ 539{
599 struct dss_pll *pll; 540 struct dss_pll *pll;
@@ -621,7 +562,7 @@ static void dpi_init_pll(struct dpi_data *dpi)
621 * the channel in some more dynamic manner, or get the channel as a user 562 * the channel in some more dynamic manner, or get the channel as a user
622 * parameter. 563 * parameter.
623 */ 564 */
624static enum omap_channel dpi_get_channel(struct dpi_data *dpi, int port_num) 565static enum omap_channel dpi_get_channel(struct dpi_data *dpi)
625{ 566{
626 switch (dpi->dss_model) { 567 switch (dpi->dss_model) {
627 case DSS_MODEL_OMAP2: 568 case DSS_MODEL_OMAP2:
@@ -629,7 +570,7 @@ static enum omap_channel dpi_get_channel(struct dpi_data *dpi, int port_num)
629 return OMAP_DSS_CHANNEL_LCD; 570 return OMAP_DSS_CHANNEL_LCD;
630 571
631 case DSS_MODEL_DRA7: 572 case DSS_MODEL_DRA7:
632 switch (port_num) { 573 switch (dpi->id) {
633 case 2: 574 case 2:
634 return OMAP_DSS_CHANNEL_LCD3; 575 return OMAP_DSS_CHANNEL_LCD3;
635 case 1: 576 case 1:
@@ -651,49 +592,31 @@ static enum omap_channel dpi_get_channel(struct dpi_data *dpi, int port_num)
651 } 592 }
652} 593}
653 594
654static int dpi_connect(struct omap_dss_device *dssdev, 595static int dpi_connect(struct omap_dss_device *src,
655 struct omap_dss_device *dst) 596 struct omap_dss_device *dst)
656{ 597{
657 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev); 598 struct dpi_data *dpi = dpi_get_data_from_dssdev(dst);
658 int r; 599 int r;
659 600
660 r = dpi_init_regulator(dpi);
661 if (r)
662 return r;
663
664 dpi_init_pll(dpi); 601 dpi_init_pll(dpi);
665 602
666 r = dss_mgr_connect(&dpi->output, dssdev); 603 r = omapdss_device_connect(dst->dss, dst, dst->next);
667 if (r) 604 if (r)
668 return r; 605 return r;
669 606
670 r = omapdss_output_set_device(dssdev, dst); 607 dst->dispc_channel_connected = true;
671 if (r) {
672 DSSERR("failed to connect output to new device: %s\n",
673 dst->name);
674 dss_mgr_disconnect(&dpi->output, dssdev);
675 return r;
676 }
677
678 return 0; 608 return 0;
679} 609}
680 610
681static void dpi_disconnect(struct omap_dss_device *dssdev, 611static void dpi_disconnect(struct omap_dss_device *src,
682 struct omap_dss_device *dst) 612 struct omap_dss_device *dst)
683{ 613{
684 struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev); 614 dst->dispc_channel_connected = false;
685
686 WARN_ON(dst != dssdev->dst);
687 615
688 if (dst != dssdev->dst) 616 omapdss_device_disconnect(dst, dst->next);
689 return;
690
691 omapdss_output_unset_device(dssdev);
692
693 dss_mgr_disconnect(&dpi->output, dssdev);
694} 617}
695 618
696static const struct omapdss_dpi_ops dpi_ops = { 619static const struct omap_dss_device_ops dpi_ops = {
697 .connect = dpi_connect, 620 .connect = dpi_connect,
698 .disconnect = dpi_disconnect, 621 .disconnect = dpi_disconnect,
699 622
@@ -702,18 +625,16 @@ static const struct omapdss_dpi_ops dpi_ops = {
702 625
703 .check_timings = dpi_check_timings, 626 .check_timings = dpi_check_timings,
704 .set_timings = dpi_set_timings, 627 .set_timings = dpi_set_timings,
705 .get_timings = dpi_get_timings,
706}; 628};
707 629
708static void dpi_init_output_port(struct dpi_data *dpi, struct device_node *port) 630static int dpi_init_output_port(struct dpi_data *dpi, struct device_node *port)
709{ 631{
710 struct omap_dss_device *out = &dpi->output; 632 struct omap_dss_device *out = &dpi->output;
633 u32 port_num = 0;
711 int r; 634 int r;
712 u32 port_num;
713 635
714 r = of_property_read_u32(port, "reg", &port_num); 636 of_property_read_u32(port, "reg", &port_num);
715 if (r) 637 dpi->id = port_num <= 2 ? port_num : 0;
716 port_num = 0;
717 638
718 switch (port_num) { 639 switch (port_num) {
719 case 2: 640 case 2:
@@ -731,12 +652,28 @@ static void dpi_init_output_port(struct dpi_data *dpi, struct device_node *port)
731 out->dev = &dpi->pdev->dev; 652 out->dev = &dpi->pdev->dev;
732 out->id = OMAP_DSS_OUTPUT_DPI; 653 out->id = OMAP_DSS_OUTPUT_DPI;
733 out->output_type = OMAP_DISPLAY_TYPE_DPI; 654 out->output_type = OMAP_DISPLAY_TYPE_DPI;
734 out->dispc_channel = dpi_get_channel(dpi, port_num); 655 out->dispc_channel = dpi_get_channel(dpi);
735 out->port_num = port_num; 656 out->of_ports = BIT(port_num);
736 out->ops.dpi = &dpi_ops; 657 out->ops = &dpi_ops;
737 out->owner = THIS_MODULE; 658 out->owner = THIS_MODULE;
738 659
739 omapdss_register_output(out); 660 out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
661 if (IS_ERR(out->next)) {
662 if (PTR_ERR(out->next) != -EPROBE_DEFER)
663 dev_err(out->dev, "failed to find video sink\n");
664 return PTR_ERR(out->next);
665 }
666
667 r = omapdss_output_validate(out);
668 if (r) {
669 omapdss_device_put(out->next);
670 out->next = NULL;
671 return r;
672 }
673
674 omapdss_device_register(out);
675
676 return 0;
740} 677}
741 678
742static void dpi_uninit_output_port(struct device_node *port) 679static void dpi_uninit_output_port(struct device_node *port)
@@ -744,7 +681,38 @@ static void dpi_uninit_output_port(struct device_node *port)
744 struct dpi_data *dpi = port->data; 681 struct dpi_data *dpi = port->data;
745 struct omap_dss_device *out = &dpi->output; 682 struct omap_dss_device *out = &dpi->output;
746 683
747 omapdss_unregister_output(out); 684 if (out->next)
685 omapdss_device_put(out->next);
686 omapdss_device_unregister(out);
687}
688
689static const struct soc_device_attribute dpi_soc_devices[] = {
690 { .machine = "OMAP3[456]*" },
691 { .machine = "[AD]M37*" },
692 { /* sentinel */ }
693};
694
695static int dpi_init_regulator(struct dpi_data *dpi)
696{
697 struct regulator *vdds_dsi;
698
699 /*
700 * The DPI uses the DSI VDDS on OMAP34xx, OMAP35xx, OMAP36xx, AM37xx and
701 * DM37xx only.
702 */
703 if (!soc_device_match(dpi_soc_devices))
704 return 0;
705
706 vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
707 if (IS_ERR(vdds_dsi)) {
708 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
709 DSSERR("can't get VDDS_DSI regulator\n");
710 return PTR_ERR(vdds_dsi);
711 }
712
713 dpi->vdds_dsi_reg = vdds_dsi;
714
715 return 0;
748} 716}
749 717
750int dpi_init_port(struct dss_device *dss, struct platform_device *pdev, 718int dpi_init_port(struct dss_device *dss, struct platform_device *pdev,
@@ -764,15 +732,14 @@ int dpi_init_port(struct dss_device *dss, struct platform_device *pdev,
764 return 0; 732 return 0;
765 733
766 r = of_property_read_u32(ep, "data-lines", &datalines); 734 r = of_property_read_u32(ep, "data-lines", &datalines);
735 of_node_put(ep);
767 if (r) { 736 if (r) {
768 DSSERR("failed to parse datalines\n"); 737 DSSERR("failed to parse datalines\n");
769 goto err_datalines; 738 return r;
770 } 739 }
771 740
772 dpi->data_lines = datalines; 741 dpi->data_lines = datalines;
773 742
774 of_node_put(ep);
775
776 dpi->pdev = pdev; 743 dpi->pdev = pdev;
777 dpi->dss_model = dss_model; 744 dpi->dss_model = dss_model;
778 dpi->dss = dss; 745 dpi->dss = dss;
@@ -780,14 +747,11 @@ int dpi_init_port(struct dss_device *dss, struct platform_device *pdev,
780 747
781 mutex_init(&dpi->lock); 748 mutex_init(&dpi->lock);
782 749
783 dpi_init_output_port(dpi, port); 750 r = dpi_init_regulator(dpi);
784 751 if (r)
785 return 0; 752 return r;
786
787err_datalines:
788 of_node_put(ep);
789 753
790 return r; 754 return dpi_init_output_port(dpi, port);
791} 755}
792 756
793void dpi_uninit_port(struct device_node *port) 757void dpi_uninit_port(struct device_node *port)
diff --git a/drivers/gpu/drm/omapdrm/dss/dsi.c b/drivers/gpu/drm/omapdrm/dss/dsi.c
index 74467b308721..394c129cfb3b 100644
--- a/drivers/gpu/drm/omapdrm/dss/dsi.c
+++ b/drivers/gpu/drm/omapdrm/dss/dsi.c
@@ -403,6 +403,7 @@ struct dsi_data {
403 struct { 403 struct {
404 struct dss_debugfs_entry *irqs; 404 struct dss_debugfs_entry *irqs;
405 struct dss_debugfs_entry *regs; 405 struct dss_debugfs_entry *regs;
406 struct dss_debugfs_entry *clks;
406 } debugfs; 407 } debugfs;
407 408
408#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS 409#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
@@ -442,27 +443,6 @@ static inline struct dsi_data *to_dsi_data(struct omap_dss_device *dssdev)
442 return dev_get_drvdata(dssdev->dev); 443 return dev_get_drvdata(dssdev->dev);
443} 444}
444 445
445static struct dsi_data *dsi_get_dsi_from_id(int module)
446{
447 struct omap_dss_device *out;
448 enum omap_dss_output_id id;
449
450 switch (module) {
451 case 0:
452 id = OMAP_DSS_OUTPUT_DSI1;
453 break;
454 case 1:
455 id = OMAP_DSS_OUTPUT_DSI2;
456 break;
457 default:
458 return NULL;
459 }
460
461 out = omap_dss_get_output(id);
462
463 return out ? to_dsi_data(out) : NULL;
464}
465
466static inline void dsi_write_reg(struct dsi_data *dsi, 446static inline void dsi_write_reg(struct dsi_data *dsi,
467 const struct dsi_reg idx, u32 val) 447 const struct dsi_reg idx, u32 val)
468{ 448{
@@ -1157,26 +1137,6 @@ static void dsi_runtime_put(struct dsi_data *dsi)
1157 WARN_ON(r < 0 && r != -ENOSYS); 1137 WARN_ON(r < 0 && r != -ENOSYS);
1158} 1138}
1159 1139
1160static int dsi_regulator_init(struct dsi_data *dsi)
1161{
1162 struct regulator *vdds_dsi;
1163
1164 if (dsi->vdds_dsi_reg != NULL)
1165 return 0;
1166
1167 vdds_dsi = devm_regulator_get(dsi->dev, "vdd");
1168
1169 if (IS_ERR(vdds_dsi)) {
1170 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
1171 DSSERR("can't get DSI VDD regulator\n");
1172 return PTR_ERR(vdds_dsi);
1173 }
1174
1175 dsi->vdds_dsi_reg = vdds_dsi;
1176
1177 return 0;
1178}
1179
1180static void _dsi_print_reset_status(struct dsi_data *dsi) 1140static void _dsi_print_reset_status(struct dsi_data *dsi)
1181{ 1141{
1182 u32 l; 1142 u32 l;
@@ -1373,10 +1333,6 @@ static int dsi_pll_enable(struct dss_pll *pll)
1373 1333
1374 DSSDBG("PLL init\n"); 1334 DSSDBG("PLL init\n");
1375 1335
1376 r = dsi_regulator_init(dsi);
1377 if (r)
1378 return r;
1379
1380 r = dsi_runtime_get(dsi); 1336 r = dsi_runtime_get(dsi);
1381 if (r) 1337 if (r)
1382 return r; 1338 return r;
@@ -1448,8 +1404,9 @@ static void dsi_pll_disable(struct dss_pll *pll)
1448 dsi_pll_uninit(dsi, true); 1404 dsi_pll_uninit(dsi, true);
1449} 1405}
1450 1406
1451static void dsi_dump_dsi_clocks(struct dsi_data *dsi, struct seq_file *s) 1407static int dsi_dump_dsi_clocks(struct seq_file *s, void *p)
1452{ 1408{
1409 struct dsi_data *dsi = p;
1453 struct dss_pll_clock_info *cinfo = &dsi->pll.cinfo; 1410 struct dss_pll_clock_info *cinfo = &dsi->pll.cinfo;
1454 enum dss_clk_source dispc_clk_src, dsi_clk_src; 1411 enum dss_clk_source dispc_clk_src, dsi_clk_src;
1455 int dsi_module = dsi->module_id; 1412 int dsi_module = dsi->module_id;
@@ -1459,7 +1416,7 @@ static void dsi_dump_dsi_clocks(struct dsi_data *dsi, struct seq_file *s)
1459 dsi_clk_src = dss_get_dsi_clk_source(dsi->dss, dsi_module); 1416 dsi_clk_src = dss_get_dsi_clk_source(dsi->dss, dsi_module);
1460 1417
1461 if (dsi_runtime_get(dsi)) 1418 if (dsi_runtime_get(dsi))
1462 return; 1419 return 0;
1463 1420
1464 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); 1421 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
1465 1422
@@ -1503,23 +1460,14 @@ static void dsi_dump_dsi_clocks(struct dsi_data *dsi, struct seq_file *s)
1503 seq_printf(s, "LP_CLK\t\t%lu\n", dsi->current_lp_cinfo.lp_clk); 1460 seq_printf(s, "LP_CLK\t\t%lu\n", dsi->current_lp_cinfo.lp_clk);
1504 1461
1505 dsi_runtime_put(dsi); 1462 dsi_runtime_put(dsi);
1506}
1507
1508void dsi_dump_clocks(struct seq_file *s)
1509{
1510 struct dsi_data *dsi;
1511 int i;
1512 1463
1513 for (i = 0; i < MAX_NUM_DSI; i++) { 1464 return 0;
1514 dsi = dsi_get_dsi_from_id(i);
1515 if (dsi)
1516 dsi_dump_dsi_clocks(dsi, s);
1517 }
1518} 1465}
1519 1466
1520#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS 1467#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1521static void dsi_dump_dsi_irqs(struct dsi_data *dsi, struct seq_file *s) 1468static int dsi_dump_dsi_irqs(struct seq_file *s, void *p)
1522{ 1469{
1470 struct dsi_data *dsi = p;
1523 unsigned long flags; 1471 unsigned long flags;
1524 struct dsi_irq_stats stats; 1472 struct dsi_irq_stats stats;
1525 1473
@@ -1603,33 +1551,20 @@ static void dsi_dump_dsi_irqs(struct dsi_data *dsi, struct seq_file *s)
1603 PIS(ULPSACTIVENOT_ALL0); 1551 PIS(ULPSACTIVENOT_ALL0);
1604 PIS(ULPSACTIVENOT_ALL1); 1552 PIS(ULPSACTIVENOT_ALL1);
1605#undef PIS 1553#undef PIS
1606}
1607 1554
1608static int dsi1_dump_irqs(struct seq_file *s, void *p)
1609{
1610 struct dsi_data *dsi = dsi_get_dsi_from_id(0);
1611
1612 dsi_dump_dsi_irqs(dsi, s);
1613 return 0;
1614}
1615
1616static int dsi2_dump_irqs(struct seq_file *s, void *p)
1617{
1618 struct dsi_data *dsi = dsi_get_dsi_from_id(1);
1619
1620 dsi_dump_dsi_irqs(dsi, s);
1621 return 0; 1555 return 0;
1622} 1556}
1623#endif 1557#endif
1624 1558
1625static void dsi_dump_dsi_regs(struct dsi_data *dsi, struct seq_file *s) 1559static int dsi_dump_dsi_regs(struct seq_file *s, void *p)
1626{ 1560{
1627#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsi, r)) 1561 struct dsi_data *dsi = p;
1628 1562
1629 if (dsi_runtime_get(dsi)) 1563 if (dsi_runtime_get(dsi))
1630 return; 1564 return 0;
1631 dsi_enable_scp_clk(dsi); 1565 dsi_enable_scp_clk(dsi);
1632 1566
1567#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsi, r))
1633 DUMPREG(DSI_REVISION); 1568 DUMPREG(DSI_REVISION);
1634 DUMPREG(DSI_SYSCONFIG); 1569 DUMPREG(DSI_SYSCONFIG);
1635 DUMPREG(DSI_SYSSTATUS); 1570 DUMPREG(DSI_SYSSTATUS);
@@ -1699,25 +1634,11 @@ static void dsi_dump_dsi_regs(struct dsi_data *dsi, struct seq_file *s)
1699 DUMPREG(DSI_PLL_GO); 1634 DUMPREG(DSI_PLL_GO);
1700 DUMPREG(DSI_PLL_CONFIGURATION1); 1635 DUMPREG(DSI_PLL_CONFIGURATION1);
1701 DUMPREG(DSI_PLL_CONFIGURATION2); 1636 DUMPREG(DSI_PLL_CONFIGURATION2);
1637#undef DUMPREG
1702 1638
1703 dsi_disable_scp_clk(dsi); 1639 dsi_disable_scp_clk(dsi);
1704 dsi_runtime_put(dsi); 1640 dsi_runtime_put(dsi);
1705#undef DUMPREG
1706}
1707
1708static int dsi1_dump_regs(struct seq_file *s, void *p)
1709{
1710 struct dsi_data *dsi = dsi_get_dsi_from_id(0);
1711
1712 dsi_dump_dsi_regs(dsi, s);
1713 return 0;
1714}
1715
1716static int dsi2_dump_regs(struct seq_file *s, void *p)
1717{
1718 struct dsi_data *dsi = dsi_get_dsi_from_id(1);
1719 1641
1720 dsi_dump_dsi_regs(dsi, s);
1721 return 0; 1642 return 0;
1722} 1643}
1723 1644
@@ -3344,7 +3265,7 @@ static void dsi_config_vp_num_line_buffers(struct dsi_data *dsi)
3344 3265
3345 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) { 3266 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
3346 int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3267 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
3347 struct videomode *vm = &dsi->vm; 3268 const struct videomode *vm = &dsi->vm;
3348 /* 3269 /*
3349 * Don't use line buffers if width is greater than the video 3270 * Don't use line buffers if width is greater than the video
3350 * port's line buffer size 3271 * port's line buffer size
@@ -3473,7 +3394,7 @@ static void dsi_config_cmd_mode_interleaving(struct dsi_data *dsi)
3473 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat; 3394 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3474 int tclk_trail, ths_exit, exiths_clk; 3395 int tclk_trail, ths_exit, exiths_clk;
3475 bool ddr_alwon; 3396 bool ddr_alwon;
3476 struct videomode *vm = &dsi->vm; 3397 const struct videomode *vm = &dsi->vm;
3477 int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3398 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
3478 int ndl = dsi->num_lanes_used - 1; 3399 int ndl = dsi->num_lanes_used - 1;
3479 int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.mX[HSDIV_DSI] + 1; 3400 int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.mX[HSDIV_DSI] + 1;
@@ -3723,7 +3644,7 @@ static void dsi_proto_timings(struct dsi_data *dsi)
3723 int vbp = dsi->vm_timings.vbp; 3644 int vbp = dsi->vm_timings.vbp;
3724 int window_sync = dsi->vm_timings.window_sync; 3645 int window_sync = dsi->vm_timings.window_sync;
3725 bool hsync_end; 3646 bool hsync_end;
3726 struct videomode *vm = &dsi->vm; 3647 const struct videomode *vm = &dsi->vm;
3727 int bpp = dsi_get_pixel_size(dsi->pix_fmt); 3648 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
3728 int tl, t_he, width_bytes; 3649 int tl, t_he, width_bytes;
3729 3650
@@ -3980,8 +3901,6 @@ static void dsi_update_screen_dispc(struct dsi_data *dsi)
3980 msecs_to_jiffies(250)); 3901 msecs_to_jiffies(250));
3981 BUG_ON(r == 0); 3902 BUG_ON(r == 0);
3982 3903
3983 dss_mgr_set_timings(&dsi->output, &dsi->vm);
3984
3985 dss_mgr_start_update(&dsi->output); 3904 dss_mgr_start_update(&dsi->output);
3986 3905
3987 if (dsi->te_enabled) { 3906 if (dsi->te_enabled) {
@@ -4123,24 +4042,6 @@ static int dsi_display_init_dispc(struct dsi_data *dsi)
4123 dsi->mgr_config.fifohandcheck = false; 4042 dsi->mgr_config.fifohandcheck = false;
4124 } 4043 }
4125 4044
4126 /*
4127 * override interlace, logic level and edge related parameters in
4128 * videomode with default values
4129 */
4130 dsi->vm.flags &= ~DISPLAY_FLAGS_INTERLACED;
4131 dsi->vm.flags &= ~DISPLAY_FLAGS_HSYNC_LOW;
4132 dsi->vm.flags |= DISPLAY_FLAGS_HSYNC_HIGH;
4133 dsi->vm.flags &= ~DISPLAY_FLAGS_VSYNC_LOW;
4134 dsi->vm.flags |= DISPLAY_FLAGS_VSYNC_HIGH;
4135 dsi->vm.flags &= ~DISPLAY_FLAGS_PIXDATA_NEGEDGE;
4136 dsi->vm.flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
4137 dsi->vm.flags &= ~DISPLAY_FLAGS_DE_LOW;
4138 dsi->vm.flags |= DISPLAY_FLAGS_DE_HIGH;
4139 dsi->vm.flags &= ~DISPLAY_FLAGS_SYNC_POSEDGE;
4140 dsi->vm.flags |= DISPLAY_FLAGS_SYNC_NEGEDGE;
4141
4142 dss_mgr_set_timings(&dsi->output, &dsi->vm);
4143
4144 r = dsi_configure_dispc_clocks(dsi); 4045 r = dsi_configure_dispc_clocks(dsi);
4145 if (r) 4046 if (r)
4146 goto err1; 4047 goto err1;
@@ -4840,6 +4741,19 @@ static int dsi_set_config(struct omap_dss_device *dssdev,
4840 dsi->user_dispc_cinfo = ctx.dispc_cinfo; 4741 dsi->user_dispc_cinfo = ctx.dispc_cinfo;
4841 4742
4842 dsi->vm = ctx.vm; 4743 dsi->vm = ctx.vm;
4744
4745 /*
4746 * override interlace, logic level and edge related parameters in
4747 * videomode with default values
4748 */
4749 dsi->vm.flags &= ~DISPLAY_FLAGS_INTERLACED;
4750 dsi->vm.flags &= ~DISPLAY_FLAGS_HSYNC_LOW;
4751 dsi->vm.flags |= DISPLAY_FLAGS_HSYNC_HIGH;
4752 dsi->vm.flags &= ~DISPLAY_FLAGS_VSYNC_LOW;
4753 dsi->vm.flags |= DISPLAY_FLAGS_VSYNC_HIGH;
4754
4755 dss_mgr_set_timings(&dsi->output, &dsi->vm);
4756
4843 dsi->vm_timings = ctx.dsi_vm; 4757 dsi->vm_timings = ctx.dsi_vm;
4844 4758
4845 mutex_unlock(&dsi->lock); 4759 mutex_unlock(&dsi->lock);
@@ -4960,163 +4874,71 @@ static int dsi_get_clocks(struct dsi_data *dsi)
4960 return 0; 4874 return 0;
4961} 4875}
4962 4876
4963static int dsi_connect(struct omap_dss_device *dssdev, 4877static int dsi_connect(struct omap_dss_device *src,
4964 struct omap_dss_device *dst) 4878 struct omap_dss_device *dst)
4965{ 4879{
4966 struct dsi_data *dsi = to_dsi_data(dssdev);
4967 int r; 4880 int r;
4968 4881
4969 r = dsi_regulator_init(dsi); 4882 r = omapdss_device_connect(dst->dss, dst, dst->next);
4970 if (r)
4971 return r;
4972
4973 r = dss_mgr_connect(&dsi->output, dssdev);
4974 if (r) 4883 if (r)
4975 return r; 4884 return r;
4976 4885
4977 r = omapdss_output_set_device(dssdev, dst); 4886 dst->dispc_channel_connected = true;
4978 if (r) {
4979 DSSERR("failed to connect output to new device: %s\n",
4980 dssdev->name);
4981 dss_mgr_disconnect(&dsi->output, dssdev);
4982 return r;
4983 }
4984
4985 return 0; 4887 return 0;
4986} 4888}
4987 4889
4988static void dsi_disconnect(struct omap_dss_device *dssdev, 4890static void dsi_disconnect(struct omap_dss_device *src,
4989 struct omap_dss_device *dst) 4891 struct omap_dss_device *dst)
4990{ 4892{
4991 struct dsi_data *dsi = to_dsi_data(dssdev); 4893 dst->dispc_channel_connected = false;
4992 4894
4993 WARN_ON(dst != dssdev->dst); 4895 omapdss_device_disconnect(dst, dst->next);
4994
4995 if (dst != dssdev->dst)
4996 return;
4997
4998 omapdss_output_unset_device(dssdev);
4999
5000 dss_mgr_disconnect(&dsi->output, dssdev);
5001} 4896}
5002 4897
5003static const struct omapdss_dsi_ops dsi_ops = { 4898static const struct omap_dss_device_ops dsi_ops = {
5004 .connect = dsi_connect, 4899 .connect = dsi_connect,
5005 .disconnect = dsi_disconnect, 4900 .disconnect = dsi_disconnect,
5006
5007 .bus_lock = dsi_bus_lock,
5008 .bus_unlock = dsi_bus_unlock,
5009
5010 .enable = dsi_display_enable, 4901 .enable = dsi_display_enable,
5011 .disable = dsi_display_disable,
5012
5013 .enable_hs = dsi_vc_enable_hs,
5014
5015 .configure_pins = dsi_configure_pins,
5016 .set_config = dsi_set_config,
5017
5018 .enable_video_output = dsi_enable_video_output,
5019 .disable_video_output = dsi_disable_video_output,
5020
5021 .update = dsi_update,
5022
5023 .enable_te = dsi_enable_te,
5024
5025 .request_vc = dsi_request_vc,
5026 .set_vc_id = dsi_set_vc_id,
5027 .release_vc = dsi_release_vc,
5028
5029 .dcs_write = dsi_vc_dcs_write,
5030 .dcs_write_nosync = dsi_vc_dcs_write_nosync,
5031 .dcs_read = dsi_vc_dcs_read,
5032
5033 .gen_write = dsi_vc_generic_write,
5034 .gen_write_nosync = dsi_vc_generic_write_nosync,
5035 .gen_read = dsi_vc_generic_read,
5036
5037 .bta_sync = dsi_vc_send_bta_sync,
5038
5039 .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size,
5040};
5041
5042static void dsi_init_output(struct dsi_data *dsi)
5043{
5044 struct omap_dss_device *out = &dsi->output;
5045
5046 out->dev = dsi->dev;
5047 out->id = dsi->module_id == 0 ?
5048 OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5049
5050 out->output_type = OMAP_DISPLAY_TYPE_DSI;
5051 out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
5052 out->dispc_channel = dsi_get_channel(dsi);
5053 out->ops.dsi = &dsi_ops;
5054 out->owner = THIS_MODULE;
5055 4902
5056 omapdss_register_output(out); 4903 .dsi = {
5057} 4904 .bus_lock = dsi_bus_lock,
4905 .bus_unlock = dsi_bus_unlock,
5058 4906
5059static void dsi_uninit_output(struct dsi_data *dsi) 4907 .disable = dsi_display_disable,
5060{
5061 struct omap_dss_device *out = &dsi->output;
5062 4908
5063 omapdss_unregister_output(out); 4909 .enable_hs = dsi_vc_enable_hs,
5064}
5065 4910
5066static int dsi_probe_of(struct dsi_data *dsi) 4911 .configure_pins = dsi_configure_pins,
5067{ 4912 .set_config = dsi_set_config,
5068 struct device_node *node = dsi->dev->of_node;
5069 struct property *prop;
5070 u32 lane_arr[10];
5071 int len, num_pins;
5072 int r, i;
5073 struct device_node *ep;
5074 struct omap_dsi_pin_config pin_cfg;
5075
5076 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
5077 if (!ep)
5078 return 0;
5079 4913
5080 prop = of_find_property(ep, "lanes", &len); 4914 .enable_video_output = dsi_enable_video_output,
5081 if (prop == NULL) { 4915 .disable_video_output = dsi_disable_video_output,
5082 dev_err(dsi->dev, "failed to find lane data\n");
5083 r = -EINVAL;
5084 goto err;
5085 }
5086 4916
5087 num_pins = len / sizeof(u32); 4917 .update = dsi_update,
5088 4918
5089 if (num_pins < 4 || num_pins % 2 != 0 || 4919 .enable_te = dsi_enable_te,
5090 num_pins > dsi->num_lanes_supported * 2) {
5091 dev_err(dsi->dev, "bad number of lanes\n");
5092 r = -EINVAL;
5093 goto err;
5094 }
5095 4920
5096 r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins); 4921 .request_vc = dsi_request_vc,
5097 if (r) { 4922 .set_vc_id = dsi_set_vc_id,
5098 dev_err(dsi->dev, "failed to read lane data\n"); 4923 .release_vc = dsi_release_vc,
5099 goto err;
5100 }
5101 4924
5102 pin_cfg.num_pins = num_pins; 4925 .dcs_write = dsi_vc_dcs_write,
5103 for (i = 0; i < num_pins; ++i) 4926 .dcs_write_nosync = dsi_vc_dcs_write_nosync,
5104 pin_cfg.pins[i] = (int)lane_arr[i]; 4927 .dcs_read = dsi_vc_dcs_read,
5105 4928
5106 r = dsi_configure_pins(&dsi->output, &pin_cfg); 4929 .gen_write = dsi_vc_generic_write,
5107 if (r) { 4930 .gen_write_nosync = dsi_vc_generic_write_nosync,
5108 dev_err(dsi->dev, "failed to configure pins"); 4931 .gen_read = dsi_vc_generic_read,
5109 goto err;
5110 }
5111 4932
5112 of_node_put(ep); 4933 .bta_sync = dsi_vc_send_bta_sync,
5113 4934
5114 return 0; 4935 .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size,
4936 },
4937};
5115 4938
5116err: 4939/* -----------------------------------------------------------------------------
5117 of_node_put(ep); 4940 * PLL
5118 return r; 4941 */
5119}
5120 4942
5121static const struct dss_pll_ops dsi_pll_ops = { 4943static const struct dss_pll_ops dsi_pll_ops = {
5122 .enable = dsi_pll_enable, 4944 .enable = dsi_pll_enable,
@@ -5231,7 +5053,175 @@ static int dsi_init_pll_data(struct dss_device *dss, struct dsi_data *dsi)
5231 return 0; 5053 return 0;
5232} 5054}
5233 5055
5234/* DSI1 HW IP initialisation */ 5056/* -----------------------------------------------------------------------------
5057 * Component Bind & Unbind
5058 */
5059
5060static int dsi_bind(struct device *dev, struct device *master, void *data)
5061{
5062 struct dss_device *dss = dss_get_device(master);
5063 struct dsi_data *dsi = dev_get_drvdata(dev);
5064 char name[10];
5065 u32 rev;
5066 int r;
5067
5068 dsi->dss = dss;
5069
5070 dsi_init_pll_data(dss, dsi);
5071
5072 r = dsi_runtime_get(dsi);
5073 if (r)
5074 return r;
5075
5076 rev = dsi_read_reg(dsi, DSI_REVISION);
5077 dev_dbg(dev, "OMAP DSI rev %d.%d\n",
5078 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5079
5080 dsi->line_buffer_size = dsi_get_line_buf_size(dsi);
5081
5082 dsi_runtime_put(dsi);
5083
5084 snprintf(name, sizeof(name), "dsi%u_regs", dsi->module_id + 1);
5085 dsi->debugfs.regs = dss_debugfs_create_file(dss, name,
5086 dsi_dump_dsi_regs, &dsi);
5087#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
5088 snprintf(name, sizeof(name), "dsi%u_irqs", dsi->module_id + 1);
5089 dsi->debugfs.irqs = dss_debugfs_create_file(dss, name,
5090 dsi_dump_dsi_irqs, &dsi);
5091#endif
5092 snprintf(name, sizeof(name), "dsi%u_clks", dsi->module_id + 1);
5093 dsi->debugfs.clks = dss_debugfs_create_file(dss, name,
5094 dsi_dump_dsi_clocks, &dsi);
5095
5096 return 0;
5097}
5098
5099static void dsi_unbind(struct device *dev, struct device *master, void *data)
5100{
5101 struct dsi_data *dsi = dev_get_drvdata(dev);
5102
5103 dss_debugfs_remove_file(dsi->debugfs.clks);
5104 dss_debugfs_remove_file(dsi->debugfs.irqs);
5105 dss_debugfs_remove_file(dsi->debugfs.regs);
5106
5107 of_platform_depopulate(dev);
5108
5109 WARN_ON(dsi->scp_clk_refcount > 0);
5110
5111 dss_pll_unregister(&dsi->pll);
5112}
5113
5114static const struct component_ops dsi_component_ops = {
5115 .bind = dsi_bind,
5116 .unbind = dsi_unbind,
5117};
5118
5119/* -----------------------------------------------------------------------------
5120 * Probe & Remove, Suspend & Resume
5121 */
5122
5123static int dsi_init_output(struct dsi_data *dsi)
5124{
5125 struct omap_dss_device *out = &dsi->output;
5126 int r;
5127
5128 out->dev = dsi->dev;
5129 out->id = dsi->module_id == 0 ?
5130 OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5131
5132 out->output_type = OMAP_DISPLAY_TYPE_DSI;
5133 out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
5134 out->dispc_channel = dsi_get_channel(dsi);
5135 out->ops = &dsi_ops;
5136 out->owner = THIS_MODULE;
5137 out->of_ports = BIT(0);
5138 out->bus_flags = DRM_BUS_FLAG_PIXDATA_POSEDGE
5139 | DRM_BUS_FLAG_DE_HIGH
5140 | DRM_BUS_FLAG_SYNC_NEGEDGE;
5141
5142 out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
5143 if (IS_ERR(out->next)) {
5144 if (PTR_ERR(out->next) != -EPROBE_DEFER)
5145 dev_err(out->dev, "failed to find video sink\n");
5146 return PTR_ERR(out->next);
5147 }
5148
5149 r = omapdss_output_validate(out);
5150 if (r) {
5151 omapdss_device_put(out->next);
5152 out->next = NULL;
5153 return r;
5154 }
5155
5156 omapdss_device_register(out);
5157
5158 return 0;
5159}
5160
5161static void dsi_uninit_output(struct dsi_data *dsi)
5162{
5163 struct omap_dss_device *out = &dsi->output;
5164
5165 if (out->next)
5166 omapdss_device_put(out->next);
5167 omapdss_device_unregister(out);
5168}
5169
5170static int dsi_probe_of(struct dsi_data *dsi)
5171{
5172 struct device_node *node = dsi->dev->of_node;
5173 struct property *prop;
5174 u32 lane_arr[10];
5175 int len, num_pins;
5176 int r, i;
5177 struct device_node *ep;
5178 struct omap_dsi_pin_config pin_cfg;
5179
5180 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
5181 if (!ep)
5182 return 0;
5183
5184 prop = of_find_property(ep, "lanes", &len);
5185 if (prop == NULL) {
5186 dev_err(dsi->dev, "failed to find lane data\n");
5187 r = -EINVAL;
5188 goto err;
5189 }
5190
5191 num_pins = len / sizeof(u32);
5192
5193 if (num_pins < 4 || num_pins % 2 != 0 ||
5194 num_pins > dsi->num_lanes_supported * 2) {
5195 dev_err(dsi->dev, "bad number of lanes\n");
5196 r = -EINVAL;
5197 goto err;
5198 }
5199
5200 r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins);
5201 if (r) {
5202 dev_err(dsi->dev, "failed to read lane data\n");
5203 goto err;
5204 }
5205
5206 pin_cfg.num_pins = num_pins;
5207 for (i = 0; i < num_pins; ++i)
5208 pin_cfg.pins[i] = (int)lane_arr[i];
5209
5210 r = dsi_configure_pins(&dsi->output, &pin_cfg);
5211 if (r) {
5212 dev_err(dsi->dev, "failed to configure pins");
5213 goto err;
5214 }
5215
5216 of_node_put(ep);
5217
5218 return 0;
5219
5220err:
5221 of_node_put(ep);
5222 return r;
5223}
5224
5235static const struct dsi_of_data dsi_of_data_omap34xx = { 5225static const struct dsi_of_data dsi_of_data_omap34xx = {
5236 .model = DSI_MODEL_OMAP3, 5226 .model = DSI_MODEL_OMAP3,
5237 .pll_hw = &dss_omap3_dsi_pll_hw, 5227 .pll_hw = &dss_omap3_dsi_pll_hw,
@@ -5297,23 +5287,21 @@ static const struct soc_device_attribute dsi_soc_devices[] = {
5297 { /* sentinel */ } 5287 { /* sentinel */ }
5298}; 5288};
5299 5289
5300static int dsi_bind(struct device *dev, struct device *master, void *data) 5290static int dsi_probe(struct platform_device *pdev)
5301{ 5291{
5302 struct platform_device *pdev = to_platform_device(dev);
5303 struct dss_device *dss = dss_get_device(master);
5304 const struct soc_device_attribute *soc; 5292 const struct soc_device_attribute *soc;
5305 const struct dsi_module_id_data *d; 5293 const struct dsi_module_id_data *d;
5306 u32 rev; 5294 struct device *dev = &pdev->dev;
5307 int r, i;
5308 struct dsi_data *dsi; 5295 struct dsi_data *dsi;
5309 struct resource *dsi_mem; 5296 struct resource *dsi_mem;
5310 struct resource *res; 5297 struct resource *res;
5298 unsigned int i;
5299 int r;
5311 5300
5312 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); 5301 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
5313 if (!dsi) 5302 if (!dsi)
5314 return -ENOMEM; 5303 return -ENOMEM;
5315 5304
5316 dsi->dss = dss;
5317 dsi->dev = dev; 5305 dsi->dev = dev;
5318 dev_set_drvdata(dev, dsi); 5306 dev_set_drvdata(dev, dsi);
5319 5307
@@ -5364,6 +5352,13 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
5364 return r; 5352 return r;
5365 } 5353 }
5366 5354
5355 dsi->vdds_dsi_reg = devm_regulator_get(dev, "vdd");
5356 if (IS_ERR(dsi->vdds_dsi_reg)) {
5357 if (PTR_ERR(dsi->vdds_dsi_reg) != -EPROBE_DEFER)
5358 DSSERR("can't get DSI VDD regulator\n");
5359 return PTR_ERR(dsi->vdds_dsi_reg);
5360 }
5361
5367 soc = soc_device_match(dsi_soc_devices); 5362 soc = soc_device_match(dsi_soc_devices);
5368 if (soc) 5363 if (soc)
5369 dsi->data = soc->data; 5364 dsi->data = soc->data;
@@ -5410,18 +5405,8 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
5410 if (r) 5405 if (r)
5411 return r; 5406 return r;
5412 5407
5413 dsi_init_pll_data(dss, dsi);
5414
5415 pm_runtime_enable(dev); 5408 pm_runtime_enable(dev);
5416 5409
5417 r = dsi_runtime_get(dsi);
5418 if (r)
5419 goto err_runtime_get;
5420
5421 rev = dsi_read_reg(dsi, DSI_REVISION);
5422 dev_dbg(dev, "OMAP DSI rev %d.%d\n",
5423 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5424
5425 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number 5410 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5426 * of data to 3 by default */ 5411 * of data to 3 by default */
5427 if (dsi->data->quirks & DSI_QUIRK_GNQ) 5412 if (dsi->data->quirks & DSI_QUIRK_GNQ)
@@ -5430,88 +5415,48 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
5430 else 5415 else
5431 dsi->num_lanes_supported = 3; 5416 dsi->num_lanes_supported = 3;
5432 5417
5433 dsi->line_buffer_size = dsi_get_line_buf_size(dsi); 5418 r = dsi_init_output(dsi);
5434 5419 if (r)
5435 dsi_init_output(dsi); 5420 goto err_pm_disable;
5436 5421
5437 r = dsi_probe_of(dsi); 5422 r = dsi_probe_of(dsi);
5438 if (r) { 5423 if (r) {
5439 DSSERR("Invalid DSI DT data\n"); 5424 DSSERR("Invalid DSI DT data\n");
5440 goto err_probe_of; 5425 goto err_uninit_output;
5441 } 5426 }
5442 5427
5443 r = of_platform_populate(dev->of_node, NULL, NULL, dev); 5428 r = of_platform_populate(dev->of_node, NULL, NULL, dev);
5444 if (r) 5429 if (r)
5445 DSSERR("Failed to populate DSI child devices: %d\n", r); 5430 DSSERR("Failed to populate DSI child devices: %d\n", r);
5446 5431
5447 dsi_runtime_put(dsi); 5432 r = component_add(&pdev->dev, &dsi_component_ops);
5448 5433 if (r)
5449 if (dsi->module_id == 0) 5434 goto err_uninit_output;
5450 dsi->debugfs.regs = dss_debugfs_create_file(dss, "dsi1_regs",
5451 dsi1_dump_regs,
5452 &dsi);
5453 else
5454 dsi->debugfs.regs = dss_debugfs_create_file(dss, "dsi2_regs",
5455 dsi2_dump_regs,
5456 &dsi);
5457#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
5458 if (dsi->module_id == 0)
5459 dsi->debugfs.irqs = dss_debugfs_create_file(dss, "dsi1_irqs",
5460 dsi1_dump_irqs,
5461 &dsi);
5462 else
5463 dsi->debugfs.irqs = dss_debugfs_create_file(dss, "dsi2_irqs",
5464 dsi2_dump_irqs,
5465 &dsi);
5466#endif
5467 5435
5468 return 0; 5436 return 0;
5469 5437
5470err_probe_of: 5438err_uninit_output:
5471 dsi_uninit_output(dsi); 5439 dsi_uninit_output(dsi);
5472 dsi_runtime_put(dsi); 5440err_pm_disable:
5473
5474err_runtime_get:
5475 pm_runtime_disable(dev); 5441 pm_runtime_disable(dev);
5476 return r; 5442 return r;
5477} 5443}
5478 5444
5479static void dsi_unbind(struct device *dev, struct device *master, void *data) 5445static int dsi_remove(struct platform_device *pdev)
5480{ 5446{
5481 struct dsi_data *dsi = dev_get_drvdata(dev); 5447 struct dsi_data *dsi = platform_get_drvdata(pdev);
5482 5448
5483 dss_debugfs_remove_file(dsi->debugfs.irqs); 5449 component_del(&pdev->dev, &dsi_component_ops);
5484 dss_debugfs_remove_file(dsi->debugfs.regs);
5485
5486 of_platform_depopulate(dev);
5487
5488 WARN_ON(dsi->scp_clk_refcount > 0);
5489
5490 dss_pll_unregister(&dsi->pll);
5491 5450
5492 dsi_uninit_output(dsi); 5451 dsi_uninit_output(dsi);
5493 5452
5494 pm_runtime_disable(dev); 5453 pm_runtime_disable(&pdev->dev);
5495 5454
5496 if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) { 5455 if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) {
5497 regulator_disable(dsi->vdds_dsi_reg); 5456 regulator_disable(dsi->vdds_dsi_reg);
5498 dsi->vdds_dsi_enabled = false; 5457 dsi->vdds_dsi_enabled = false;
5499 } 5458 }
5500}
5501 5459
5502static const struct component_ops dsi_component_ops = {
5503 .bind = dsi_bind,
5504 .unbind = dsi_unbind,
5505};
5506
5507static int dsi_probe(struct platform_device *pdev)
5508{
5509 return component_add(&pdev->dev, &dsi_component_ops);
5510}
5511
5512static int dsi_remove(struct platform_device *pdev)
5513{
5514 component_del(&pdev->dev, &dsi_component_ops);
5515 return 0; 5460 return 0;
5516} 5461}
5517 5462
diff --git a/drivers/gpu/drm/omapdrm/dss/dss-of.c b/drivers/gpu/drm/omapdrm/dss/dss-of.c
index 4602a79c6c44..0422597ac6b0 100644
--- a/drivers/gpu/drm/omapdrm/dss/dss-of.c
+++ b/drivers/gpu/drm/omapdrm/dss/dss-of.c
@@ -21,7 +21,8 @@
21 21
22#include "omapdss.h" 22#include "omapdss.h"
23 23
24struct device_node *dss_of_port_get_parent_device(struct device_node *port) 24static struct device_node *
25dss_of_port_get_parent_device(struct device_node *port)
25{ 26{
26 struct device_node *np; 27 struct device_node *np;
27 int i; 28 int i;
@@ -45,41 +46,37 @@ struct device_node *dss_of_port_get_parent_device(struct device_node *port)
45 return NULL; 46 return NULL;
46} 47}
47 48
48u32 dss_of_port_get_port_number(struct device_node *port)
49{
50 int r;
51 u32 reg;
52
53 r = of_property_read_u32(port, "reg", &reg);
54 if (r)
55 reg = 0;
56
57 return reg;
58}
59
60struct omap_dss_device * 49struct omap_dss_device *
61omapdss_of_find_source_for_first_ep(struct device_node *node) 50omapdss_of_find_connected_device(struct device_node *node, unsigned int port)
62{ 51{
63 struct device_node *ep; 52 struct device_node *src_node;
64 struct device_node *src_port; 53 struct device_node *src_port;
54 struct device_node *ep;
65 struct omap_dss_device *src; 55 struct omap_dss_device *src;
56 u32 port_number = 0;
66 57
67 ep = of_graph_get_endpoint_by_regs(node, 0, 0); 58 /* Get the endpoint... */
59 ep = of_graph_get_endpoint_by_regs(node, port, 0);
68 if (!ep) 60 if (!ep)
69 return ERR_PTR(-EINVAL); 61 return NULL;
70 62
63 /* ... and its remote port... */
71 src_port = of_graph_get_remote_port(ep); 64 src_port = of_graph_get_remote_port(ep);
72 if (!src_port) {
73 of_node_put(ep);
74 return ERR_PTR(-EINVAL);
75 }
76
77 of_node_put(ep); 65 of_node_put(ep);
66 if (!src_port)
67 return NULL;
78 68
79 src = omap_dss_find_output_by_port_node(src_port); 69 /* ... and the remote port's number and parent... */
80 70 of_property_read_u32(src_port, "reg", &port_number);
71 src_node = dss_of_port_get_parent_device(src_port);
81 of_node_put(src_port); 72 of_node_put(src_port);
73 if (!src_node)
74 return ERR_PTR(-EINVAL);
75
76 /* ... and finally the connected device. */
77 src = omapdss_find_device_by_port(src_node, port_number);
78 of_node_put(src_node);
82 79
83 return src ? src : ERR_PTR(-EPROBE_DEFER); 80 return src ? src : ERR_PTR(-EPROBE_DEFER);
84} 81}
85EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep); 82EXPORT_SYMBOL_GPL(omapdss_of_find_connected_device);
diff --git a/drivers/gpu/drm/omapdrm/dss/dss.c b/drivers/gpu/drm/omapdrm/dss/dss.c
index cb80ddaa19d2..19fc4dfc429e 100644
--- a/drivers/gpu/drm/omapdrm/dss/dss.c
+++ b/drivers/gpu/drm/omapdrm/dss/dss.c
@@ -394,9 +394,6 @@ static int dss_debug_dump_clocks(struct seq_file *s, void *p)
394 394
395 dss_dump_clocks(dss, s); 395 dss_dump_clocks(dss, s);
396 dispc_dump_clocks(dss->dispc, s); 396 dispc_dump_clocks(dss->dispc, s);
397#ifdef CONFIG_OMAP2_DSS_DSI
398 dsi_dump_clocks(s);
399#endif
400 return 0; 397 return 0;
401} 398}
402 399
@@ -681,12 +678,6 @@ unsigned long dss_get_max_fck_rate(struct dss_device *dss)
681 return dss->feat->fck_freq_max; 678 return dss->feat->fck_freq_max;
682} 679}
683 680
684enum omap_dss_output_id dss_get_supported_outputs(struct dss_device *dss,
685 enum omap_channel channel)
686{
687 return dss->feat->outputs[channel];
688}
689
690static int dss_setup_default_clock(struct dss_device *dss) 681static int dss_setup_default_clock(struct dss_device *dss)
691{ 682{
692 unsigned long max_dss_fck, prate; 683 unsigned long max_dss_fck, prate;
@@ -1183,7 +1174,8 @@ static int dss_init_ports(struct dss_device *dss)
1183 struct platform_device *pdev = dss->pdev; 1174 struct platform_device *pdev = dss->pdev;
1184 struct device_node *parent = pdev->dev.of_node; 1175 struct device_node *parent = pdev->dev.of_node;
1185 struct device_node *port; 1176 struct device_node *port;
1186 int i; 1177 unsigned int i;
1178 int r;
1187 1179
1188 for (i = 0; i < dss->feat->num_ports; i++) { 1180 for (i = 0; i < dss->feat->num_ports; i++) {
1189 port = of_graph_get_port_by_id(parent, i); 1181 port = of_graph_get_port_by_id(parent, i);
@@ -1192,11 +1184,17 @@ static int dss_init_ports(struct dss_device *dss)
1192 1184
1193 switch (dss->feat->ports[i]) { 1185 switch (dss->feat->ports[i]) {
1194 case OMAP_DISPLAY_TYPE_DPI: 1186 case OMAP_DISPLAY_TYPE_DPI:
1195 dpi_init_port(dss, pdev, port, dss->feat->model); 1187 r = dpi_init_port(dss, pdev, port, dss->feat->model);
1188 if (r)
1189 return r;
1196 break; 1190 break;
1191
1197 case OMAP_DISPLAY_TYPE_SDI: 1192 case OMAP_DISPLAY_TYPE_SDI:
1198 sdi_init_port(dss, pdev, port); 1193 r = sdi_init_port(dss, pdev, port);
1194 if (r)
1195 return r;
1199 break; 1196 break;
1197
1200 default: 1198 default:
1201 break; 1199 break;
1202 } 1200 }
@@ -1315,6 +1313,7 @@ static const struct soc_device_attribute dss_soc_devices[] = {
1315static int dss_bind(struct device *dev) 1313static int dss_bind(struct device *dev)
1316{ 1314{
1317 struct dss_device *dss = dev_get_drvdata(dev); 1315 struct dss_device *dss = dev_get_drvdata(dev);
1316 struct platform_device *drm_pdev;
1318 int r; 1317 int r;
1319 1318
1320 r = component_bind_all(dev, NULL); 1319 r = component_bind_all(dev, NULL);
@@ -1323,14 +1322,25 @@ static int dss_bind(struct device *dev)
1323 1322
1324 pm_set_vt_switch(0); 1323 pm_set_vt_switch(0);
1325 1324
1326 omapdss_gather_components(dev);
1327 omapdss_set_dss(dss); 1325 omapdss_set_dss(dss);
1328 1326
1327 drm_pdev = platform_device_register_simple("omapdrm", 0, NULL, 0);
1328 if (IS_ERR(drm_pdev)) {
1329 component_unbind_all(dev, NULL);
1330 return PTR_ERR(drm_pdev);
1331 }
1332
1333 dss->drm_pdev = drm_pdev;
1334
1329 return 0; 1335 return 0;
1330} 1336}
1331 1337
1332static void dss_unbind(struct device *dev) 1338static void dss_unbind(struct device *dev)
1333{ 1339{
1340 struct dss_device *dss = dev_get_drvdata(dev);
1341
1342 platform_device_unregister(dss->drm_pdev);
1343
1334 omapdss_set_dss(NULL); 1344 omapdss_set_dss(NULL);
1335 1345
1336 component_unbind_all(dev, NULL); 1346 component_unbind_all(dev, NULL);
@@ -1474,6 +1484,8 @@ static int dss_probe(struct platform_device *pdev)
1474 dss); 1484 dss);
1475 1485
1476 /* Add all the child devices as components. */ 1486 /* Add all the child devices as components. */
1487 omapdss_gather_components(&pdev->dev);
1488
1477 device_for_each_child(&pdev->dev, &match, dss_add_child_component); 1489 device_for_each_child(&pdev->dev, &match, dss_add_child_component);
1478 1490
1479 r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match); 1491 r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match);
@@ -1539,12 +1551,9 @@ static void dss_shutdown(struct platform_device *pdev)
1539 1551
1540 DSSDBG("shutdown\n"); 1552 DSSDBG("shutdown\n");
1541 1553
1542 for_each_dss_dev(dssdev) { 1554 for_each_dss_display(dssdev) {
1543 if (!dssdev->driver)
1544 continue;
1545
1546 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) 1555 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
1547 dssdev->driver->disable(dssdev); 1556 dssdev->ops->disable(dssdev);
1548 } 1557 }
1549} 1558}
1550 1559
diff --git a/drivers/gpu/drm/omapdrm/dss/dss.h b/drivers/gpu/drm/omapdrm/dss/dss.h
index 38302631b64b..37790c363128 100644
--- a/drivers/gpu/drm/omapdrm/dss/dss.h
+++ b/drivers/gpu/drm/omapdrm/dss/dss.h
@@ -238,6 +238,8 @@ struct dss_device {
238 struct regmap *syscon_pll_ctrl; 238 struct regmap *syscon_pll_ctrl;
239 u32 syscon_pll_ctrl_offset; 239 u32 syscon_pll_ctrl_offset;
240 240
241 struct platform_device *drm_pdev;
242
241 struct clk *parent_clk; 243 struct clk *parent_clk;
242 struct clk *dss_clk; 244 struct clk *dss_clk;
243 unsigned long dss_clk_rate; 245 unsigned long dss_clk_rate;
@@ -267,6 +269,8 @@ struct dss_device {
267 269
268 struct dispc_device *dispc; 270 struct dispc_device *dispc;
269 const struct dispc_ops *dispc_ops; 271 const struct dispc_ops *dispc_ops;
272 const struct dss_mgr_ops *mgr_ops;
273 struct omap_drm_private *mgr_ops_priv;
270}; 274};
271 275
272/* core */ 276/* core */
@@ -313,8 +317,6 @@ void dss_runtime_put(struct dss_device *dss);
313 317
314unsigned long dss_get_dispc_clk_rate(struct dss_device *dss); 318unsigned long dss_get_dispc_clk_rate(struct dss_device *dss);
315unsigned long dss_get_max_fck_rate(struct dss_device *dss); 319unsigned long dss_get_max_fck_rate(struct dss_device *dss);
316enum omap_dss_output_id dss_get_supported_outputs(struct dss_device *dss,
317 enum omap_channel channel);
318int dss_dpi_select_source(struct dss_device *dss, int port, 320int dss_dpi_select_source(struct dss_device *dss, int port,
319 enum omap_channel channel); 321 enum omap_channel channel);
320void dss_select_hdmi_venc_clk_source(struct dss_device *dss, 322void dss_select_hdmi_venc_clk_source(struct dss_device *dss,
@@ -374,8 +376,6 @@ static inline void sdi_uninit_port(struct device_node *port)
374 376
375#ifdef CONFIG_OMAP2_DSS_DSI 377#ifdef CONFIG_OMAP2_DSS_DSI
376 378
377void dsi_dump_clocks(struct seq_file *s);
378
379void dsi_irq_handler(void); 379void dsi_irq_handler(void);
380 380
381#endif 381#endif
@@ -417,9 +417,6 @@ bool dispc_div_calc(struct dispc_device *dispc, unsigned long dispc_freq,
417 unsigned long pck_min, unsigned long pck_max, 417 unsigned long pck_min, unsigned long pck_max,
418 dispc_div_calc_func func, void *data); 418 dispc_div_calc_func func, void *data);
419 419
420bool dispc_mgr_timings_ok(struct dispc_device *dispc,
421 enum omap_channel channel,
422 const struct videomode *vm);
423int dispc_calc_clock_rates(struct dispc_device *dispc, 420int dispc_calc_clock_rates(struct dispc_device *dispc,
424 unsigned long dispc_fclk_rate, 421 unsigned long dispc_fclk_rate,
425 struct dispc_clock_info *cinfo); 422 struct dispc_clock_info *cinfo);
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi.h b/drivers/gpu/drm/omapdrm/dss/hdmi.h
index 3aeb4cabd59f..7f0dc490a31d 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi.h
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi.h
@@ -313,13 +313,13 @@ void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask);
313int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val); 313int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val);
314int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val); 314int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val);
315void hdmi_wp_video_config_format(struct hdmi_wp_data *wp, 315void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
316 struct hdmi_video_format *video_fmt); 316 const struct hdmi_video_format *video_fmt);
317void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp, 317void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
318 struct videomode *vm); 318 const struct videomode *vm);
319void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp, 319void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
320 struct videomode *vm); 320 const struct videomode *vm);
321void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt, 321void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
322 struct videomode *vm, struct hdmi_config *param); 322 struct videomode *vm, const struct hdmi_config *param);
323int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp, 323int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp,
324 unsigned int version); 324 unsigned int version);
325phys_addr_t hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data *wp); 325phys_addr_t hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data *wp);
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index 5879f45f6fc9..cf6230eac31a 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -108,26 +108,6 @@ static irqreturn_t hdmi_irq_handler(int irq, void *data)
108 return IRQ_HANDLED; 108 return IRQ_HANDLED;
109} 109}
110 110
111static int hdmi_init_regulator(struct omap_hdmi *hdmi)
112{
113 struct regulator *reg;
114
115 if (hdmi->vdda_reg != NULL)
116 return 0;
117
118 reg = devm_regulator_get(&hdmi->pdev->dev, "vdda");
119
120 if (IS_ERR(reg)) {
121 if (PTR_ERR(reg) != -EPROBE_DEFER)
122 DSSERR("can't get VDDA regulator\n");
123 return PTR_ERR(reg);
124 }
125
126 hdmi->vdda_reg = reg;
127
128 return 0;
129}
130
131static int hdmi_power_on_core(struct omap_hdmi *hdmi) 111static int hdmi_power_on_core(struct omap_hdmi *hdmi)
132{ 112{
133 int r; 113 int r;
@@ -174,7 +154,7 @@ static void hdmi_power_off_core(struct omap_hdmi *hdmi)
174static int hdmi_power_on_full(struct omap_hdmi *hdmi) 154static int hdmi_power_on_full(struct omap_hdmi *hdmi)
175{ 155{
176 int r; 156 int r;
177 struct videomode *vm; 157 const struct videomode *vm;
178 struct hdmi_wp_data *wp = &hdmi->wp; 158 struct hdmi_wp_data *wp = &hdmi->wp;
179 struct dss_pll_clock_info hdmi_cinfo = { 0 }; 159 struct dss_pll_clock_info hdmi_cinfo = { 0 };
180 unsigned int pc; 160 unsigned int pc;
@@ -227,9 +207,6 @@ static int hdmi_power_on_full(struct omap_hdmi *hdmi)
227 207
228 hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg); 208 hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
229 209
230 /* tv size */
231 dss_mgr_set_timings(&hdmi->output, vm);
232
233 r = dss_mgr_enable(&hdmi->output); 210 r = dss_mgr_enable(&hdmi->output);
234 if (r) 211 if (r)
235 goto err_mgr_enable; 212 goto err_mgr_enable;
@@ -271,19 +248,8 @@ static void hdmi_power_off_full(struct omap_hdmi *hdmi)
271 hdmi_power_off_core(hdmi); 248 hdmi_power_off_core(hdmi);
272} 249}
273 250
274static int hdmi_display_check_timing(struct omap_dss_device *dssdev, 251static void hdmi_display_set_timings(struct omap_dss_device *dssdev,
275 struct videomode *vm) 252 const struct videomode *vm)
276{
277 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
278
279 if (!dispc_mgr_timings_ok(hdmi->dss->dispc, dssdev->dispc_channel, vm))
280 return -EINVAL;
281
282 return 0;
283}
284
285static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
286 struct videomode *vm)
287{ 253{
288 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); 254 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
289 255
@@ -296,14 +262,6 @@ static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
296 mutex_unlock(&hdmi->lock); 262 mutex_unlock(&hdmi->lock);
297} 263}
298 264
299static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
300 struct videomode *vm)
301{
302 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
303
304 *vm = hdmi->cfg.vm;
305}
306
307static int hdmi_dump_regs(struct seq_file *s, void *p) 265static int hdmi_dump_regs(struct seq_file *s, void *p)
308{ 266{
309 struct omap_hdmi *hdmi = s->private; 267 struct omap_hdmi *hdmi = s->private;
@@ -456,44 +414,25 @@ void hdmi4_core_disable(struct hdmi_core_data *core)
456 mutex_unlock(&hdmi->lock); 414 mutex_unlock(&hdmi->lock);
457} 415}
458 416
459static int hdmi_connect(struct omap_dss_device *dssdev, 417static int hdmi_connect(struct omap_dss_device *src,
460 struct omap_dss_device *dst) 418 struct omap_dss_device *dst)
461{ 419{
462 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
463 int r; 420 int r;
464 421
465 r = hdmi_init_regulator(hdmi); 422 r = omapdss_device_connect(dst->dss, dst, dst->next);
466 if (r) 423 if (r)
467 return r; 424 return r;
468 425
469 r = dss_mgr_connect(&hdmi->output, dssdev); 426 dst->dispc_channel_connected = true;
470 if (r)
471 return r;
472
473 r = omapdss_output_set_device(dssdev, dst);
474 if (r) {
475 DSSERR("failed to connect output to new device: %s\n",
476 dst->name);
477 dss_mgr_disconnect(&hdmi->output, dssdev);
478 return r;
479 }
480
481 return 0; 427 return 0;
482} 428}
483 429
484static void hdmi_disconnect(struct omap_dss_device *dssdev, 430static void hdmi_disconnect(struct omap_dss_device *src,
485 struct omap_dss_device *dst) 431 struct omap_dss_device *dst)
486{ 432{
487 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); 433 dst->dispc_channel_connected = false;
488
489 WARN_ON(dst != dssdev->dst);
490 434
491 if (dst != dssdev->dst) 435 omapdss_device_disconnect(dst, dst->next);
492 return;
493
494 omapdss_output_unset_device(dssdev);
495
496 dss_mgr_disconnect(&hdmi->output, dssdev);
497} 436}
498 437
499static int hdmi_read_edid(struct omap_dss_device *dssdev, 438static int hdmi_read_edid(struct omap_dss_device *dssdev,
@@ -548,69 +487,28 @@ static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
548 return 0; 487 return 0;
549} 488}
550 489
551static const struct omapdss_hdmi_ops hdmi_ops = { 490static const struct omap_dss_device_ops hdmi_ops = {
552 .connect = hdmi_connect, 491 .connect = hdmi_connect,
553 .disconnect = hdmi_disconnect, 492 .disconnect = hdmi_disconnect,
554 493
555 .enable = hdmi_display_enable, 494 .enable = hdmi_display_enable,
556 .disable = hdmi_display_disable, 495 .disable = hdmi_display_disable,
557 496
558 .check_timings = hdmi_display_check_timing, 497 .set_timings = hdmi_display_set_timings,
559 .set_timings = hdmi_display_set_timing,
560 .get_timings = hdmi_display_get_timings,
561 498
562 .read_edid = hdmi_read_edid, 499 .read_edid = hdmi_read_edid,
563 .lost_hotplug = hdmi_lost_hotplug,
564 .set_infoframe = hdmi_set_infoframe,
565 .set_hdmi_mode = hdmi_set_hdmi_mode,
566};
567
568static void hdmi_init_output(struct omap_hdmi *hdmi)
569{
570 struct omap_dss_device *out = &hdmi->output;
571
572 out->dev = &hdmi->pdev->dev;
573 out->id = OMAP_DSS_OUTPUT_HDMI;
574 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
575 out->name = "hdmi.0";
576 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
577 out->ops.hdmi = &hdmi_ops;
578 out->owner = THIS_MODULE;
579
580 omapdss_register_output(out);
581}
582
583static void hdmi_uninit_output(struct omap_hdmi *hdmi)
584{
585 struct omap_dss_device *out = &hdmi->output;
586
587 omapdss_unregister_output(out);
588}
589
590static int hdmi_probe_of(struct omap_hdmi *hdmi)
591{
592 struct platform_device *pdev = hdmi->pdev;
593 struct device_node *node = pdev->dev.of_node;
594 struct device_node *ep;
595 int r;
596
597 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
598 if (!ep)
599 return 0;
600
601 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
602 if (r)
603 goto err;
604 500
605 of_node_put(ep); 501 .hdmi = {
606 return 0; 502 .lost_hotplug = hdmi_lost_hotplug,
503 .set_infoframe = hdmi_set_infoframe,
504 .set_hdmi_mode = hdmi_set_hdmi_mode,
505 },
506};
607 507
608err: 508/* -----------------------------------------------------------------------------
609 of_node_put(ep); 509 * Audio Callbacks
610 return r; 510 */
611}
612 511
613/* Audio callbacks */
614static int hdmi_audio_startup(struct device *dev, 512static int hdmi_audio_startup(struct device *dev,
615 void (*abort_cb)(struct device *dev)) 513 void (*abort_cb)(struct device *dev))
616{ 514{
@@ -725,27 +623,143 @@ static int hdmi_audio_register(struct omap_hdmi *hdmi)
725 return 0; 623 return 0;
726} 624}
727 625
728/* HDMI HW IP initialisation */ 626/* -----------------------------------------------------------------------------
627 * Component Bind & Unbind
628 */
629
729static int hdmi4_bind(struct device *dev, struct device *master, void *data) 630static int hdmi4_bind(struct device *dev, struct device *master, void *data)
730{ 631{
731 struct platform_device *pdev = to_platform_device(dev);
732 struct dss_device *dss = dss_get_device(master); 632 struct dss_device *dss = dss_get_device(master);
733 struct omap_hdmi *hdmi; 633 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
634 int r;
635
636 hdmi->dss = dss;
637
638 r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
639 if (r)
640 return r;
641
642 r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp);
643 if (r)
644 goto err_pll_uninit;
645
646 r = hdmi_audio_register(hdmi);
647 if (r) {
648 DSSERR("Registering HDMI audio failed\n");
649 goto err_cec_uninit;
650 }
651
652 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
653 hdmi);
654
655 return 0;
656
657err_cec_uninit:
658 hdmi4_cec_uninit(&hdmi->core);
659err_pll_uninit:
660 hdmi_pll_uninit(&hdmi->pll);
661 return r;
662}
663
664static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
665{
666 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
667
668 dss_debugfs_remove_file(hdmi->debugfs);
669
670 if (hdmi->audio_pdev)
671 platform_device_unregister(hdmi->audio_pdev);
672
673 hdmi4_cec_uninit(&hdmi->core);
674 hdmi_pll_uninit(&hdmi->pll);
675}
676
677static const struct component_ops hdmi4_component_ops = {
678 .bind = hdmi4_bind,
679 .unbind = hdmi4_unbind,
680};
681
682/* -----------------------------------------------------------------------------
683 * Probe & Remove, Suspend & Resume
684 */
685
686static int hdmi4_init_output(struct omap_hdmi *hdmi)
687{
688 struct omap_dss_device *out = &hdmi->output;
734 int r; 689 int r;
690
691 out->dev = &hdmi->pdev->dev;
692 out->id = OMAP_DSS_OUTPUT_HDMI;
693 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
694 out->name = "hdmi.0";
695 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
696 out->ops = &hdmi_ops;
697 out->owner = THIS_MODULE;
698 out->of_ports = BIT(0);
699 out->ops_flags = OMAP_DSS_DEVICE_OP_EDID;
700
701 out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
702 if (IS_ERR(out->next)) {
703 if (PTR_ERR(out->next) != -EPROBE_DEFER)
704 dev_err(out->dev, "failed to find video sink\n");
705 return PTR_ERR(out->next);
706 }
707
708 r = omapdss_output_validate(out);
709 if (r) {
710 omapdss_device_put(out->next);
711 out->next = NULL;
712 return r;
713 }
714
715 omapdss_device_register(out);
716
717 return 0;
718}
719
720static void hdmi4_uninit_output(struct omap_hdmi *hdmi)
721{
722 struct omap_dss_device *out = &hdmi->output;
723
724 if (out->next)
725 omapdss_device_put(out->next);
726 omapdss_device_unregister(out);
727}
728
729static int hdmi4_probe_of(struct omap_hdmi *hdmi)
730{
731 struct platform_device *pdev = hdmi->pdev;
732 struct device_node *node = pdev->dev.of_node;
733 struct device_node *ep;
734 int r;
735
736 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
737 if (!ep)
738 return 0;
739
740 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
741 of_node_put(ep);
742 return r;
743}
744
745static int hdmi4_probe(struct platform_device *pdev)
746{
747 struct omap_hdmi *hdmi;
735 int irq; 748 int irq;
749 int r;
736 750
737 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL); 751 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
738 if (!hdmi) 752 if (!hdmi)
739 return -ENOMEM; 753 return -ENOMEM;
740 754
741 hdmi->pdev = pdev; 755 hdmi->pdev = pdev;
742 hdmi->dss = dss; 756
743 dev_set_drvdata(&pdev->dev, hdmi); 757 dev_set_drvdata(&pdev->dev, hdmi);
744 758
745 mutex_init(&hdmi->lock); 759 mutex_init(&hdmi->lock);
746 spin_lock_init(&hdmi->audio_playing_lock); 760 spin_lock_init(&hdmi->audio_playing_lock);
747 761
748 r = hdmi_probe_of(hdmi); 762 r = hdmi4_probe_of(hdmi);
749 if (r) 763 if (r)
750 goto err_free; 764 goto err_free;
751 765
@@ -753,27 +767,19 @@ static int hdmi4_bind(struct device *dev, struct device *master, void *data)
753 if (r) 767 if (r)
754 goto err_free; 768 goto err_free;
755 769
756 r = hdmi_pll_init(dss, pdev, &hdmi->pll, &hdmi->wp);
757 if (r)
758 goto err_free;
759
760 r = hdmi_phy_init(pdev, &hdmi->phy, 4); 770 r = hdmi_phy_init(pdev, &hdmi->phy, 4);
761 if (r) 771 if (r)
762 goto err_pll; 772 goto err_free;
763 773
764 r = hdmi4_core_init(pdev, &hdmi->core); 774 r = hdmi4_core_init(pdev, &hdmi->core);
765 if (r) 775 if (r)
766 goto err_pll; 776 goto err_free;
767
768 r = hdmi4_cec_init(pdev, &hdmi->core, &hdmi->wp);
769 if (r)
770 goto err_pll;
771 777
772 irq = platform_get_irq(pdev, 0); 778 irq = platform_get_irq(pdev, 0);
773 if (irq < 0) { 779 if (irq < 0) {
774 DSSERR("platform_get_irq failed\n"); 780 DSSERR("platform_get_irq failed\n");
775 r = -ENODEV; 781 r = -ENODEV;
776 goto err_pll; 782 goto err_free;
777 } 783 }
778 784
779 r = devm_request_threaded_irq(&pdev->dev, irq, 785 r = devm_request_threaded_irq(&pdev->dev, irq,
@@ -781,66 +787,49 @@ static int hdmi4_bind(struct device *dev, struct device *master, void *data)
781 IRQF_ONESHOT, "OMAP HDMI", hdmi); 787 IRQF_ONESHOT, "OMAP HDMI", hdmi);
782 if (r) { 788 if (r) {
783 DSSERR("HDMI IRQ request failed\n"); 789 DSSERR("HDMI IRQ request failed\n");
784 goto err_pll; 790 goto err_free;
785 } 791 }
786 792
787 pm_runtime_enable(&pdev->dev); 793 hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda");
794 if (IS_ERR(hdmi->vdda_reg)) {
795 r = PTR_ERR(hdmi->vdda_reg);
796 if (r != -EPROBE_DEFER)
797 DSSERR("can't get VDDA regulator\n");
798 goto err_free;
799 }
788 800
789 hdmi_init_output(hdmi); 801 pm_runtime_enable(&pdev->dev);
790 802
791 r = hdmi_audio_register(hdmi); 803 r = hdmi4_init_output(hdmi);
792 if (r) { 804 if (r)
793 DSSERR("Registering HDMI audio failed\n"); 805 goto err_pm_disable;
794 hdmi_uninit_output(hdmi);
795 pm_runtime_disable(&pdev->dev);
796 return r;
797 }
798 806
799 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs, 807 r = component_add(&pdev->dev, &hdmi4_component_ops);
800 hdmi); 808 if (r)
809 goto err_uninit_output;
801 810
802 return 0; 811 return 0;
803 812
804err_pll: 813err_uninit_output:
805 hdmi_pll_uninit(&hdmi->pll); 814 hdmi4_uninit_output(hdmi);
815err_pm_disable:
816 pm_runtime_disable(&pdev->dev);
806err_free: 817err_free:
807 kfree(hdmi); 818 kfree(hdmi);
808 return r; 819 return r;
809} 820}
810 821
811static void hdmi4_unbind(struct device *dev, struct device *master, void *data) 822static int hdmi4_remove(struct platform_device *pdev)
812{ 823{
813 struct omap_hdmi *hdmi = dev_get_drvdata(dev); 824 struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
814
815 dss_debugfs_remove_file(hdmi->debugfs);
816
817 if (hdmi->audio_pdev)
818 platform_device_unregister(hdmi->audio_pdev);
819 825
820 hdmi_uninit_output(hdmi); 826 component_del(&pdev->dev, &hdmi4_component_ops);
821
822 hdmi4_cec_uninit(&hdmi->core);
823 827
824 hdmi_pll_uninit(&hdmi->pll); 828 hdmi4_uninit_output(hdmi);
825 829
826 pm_runtime_disable(dev); 830 pm_runtime_disable(&pdev->dev);
827 831
828 kfree(hdmi); 832 kfree(hdmi);
829}
830
831static const struct component_ops hdmi4_component_ops = {
832 .bind = hdmi4_bind,
833 .unbind = hdmi4_unbind,
834};
835
836static int hdmi4_probe(struct platform_device *pdev)
837{
838 return component_add(&pdev->dev, &hdmi4_component_ops);
839}
840
841static int hdmi4_remove(struct platform_device *pdev)
842{
843 component_del(&pdev->dev, &hdmi4_component_ops);
844 return 0; 833 return 0;
845} 834}
846 835
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi5.c b/drivers/gpu/drm/omapdrm/dss/hdmi5.c
index ae1a001d1b83..b0e4a7463f8c 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi5.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi5.c
@@ -117,24 +117,6 @@ static irqreturn_t hdmi_irq_handler(int irq, void *data)
117 return IRQ_HANDLED; 117 return IRQ_HANDLED;
118} 118}
119 119
120static int hdmi_init_regulator(struct omap_hdmi *hdmi)
121{
122 struct regulator *reg;
123
124 if (hdmi->vdda_reg != NULL)
125 return 0;
126
127 reg = devm_regulator_get(&hdmi->pdev->dev, "vdda");
128 if (IS_ERR(reg)) {
129 DSSERR("can't get VDDA regulator\n");
130 return PTR_ERR(reg);
131 }
132
133 hdmi->vdda_reg = reg;
134
135 return 0;
136}
137
138static int hdmi_power_on_core(struct omap_hdmi *hdmi) 120static int hdmi_power_on_core(struct omap_hdmi *hdmi)
139{ 121{
140 int r; 122 int r;
@@ -171,7 +153,7 @@ static void hdmi_power_off_core(struct omap_hdmi *hdmi)
171static int hdmi_power_on_full(struct omap_hdmi *hdmi) 153static int hdmi_power_on_full(struct omap_hdmi *hdmi)
172{ 154{
173 int r; 155 int r;
174 struct videomode *vm; 156 const struct videomode *vm;
175 struct dss_pll_clock_info hdmi_cinfo = { 0 }; 157 struct dss_pll_clock_info hdmi_cinfo = { 0 };
176 unsigned int pc; 158 unsigned int pc;
177 159
@@ -224,9 +206,6 @@ static int hdmi_power_on_full(struct omap_hdmi *hdmi)
224 206
225 hdmi5_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg); 207 hdmi5_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
226 208
227 /* tv size */
228 dss_mgr_set_timings(&hdmi->output, vm);
229
230 r = dss_mgr_enable(&hdmi->output); 209 r = dss_mgr_enable(&hdmi->output);
231 if (r) 210 if (r)
232 goto err_mgr_enable; 211 goto err_mgr_enable;
@@ -268,19 +247,8 @@ static void hdmi_power_off_full(struct omap_hdmi *hdmi)
268 hdmi_power_off_core(hdmi); 247 hdmi_power_off_core(hdmi);
269} 248}
270 249
271static int hdmi_display_check_timing(struct omap_dss_device *dssdev, 250static void hdmi_display_set_timings(struct omap_dss_device *dssdev,
272 struct videomode *vm) 251 const struct videomode *vm)
273{
274 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
275
276 if (!dispc_mgr_timings_ok(hdmi->dss->dispc, dssdev->dispc_channel, vm))
277 return -EINVAL;
278
279 return 0;
280}
281
282static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
283 struct videomode *vm)
284{ 252{
285 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); 253 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
286 254
@@ -293,14 +261,6 @@ static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
293 mutex_unlock(&hdmi->lock); 261 mutex_unlock(&hdmi->lock);
294} 262}
295 263
296static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
297 struct videomode *vm)
298{
299 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
300
301 *vm = hdmi->cfg.vm;
302}
303
304static int hdmi_dump_regs(struct seq_file *s, void *p) 264static int hdmi_dump_regs(struct seq_file *s, void *p)
305{ 265{
306 struct omap_hdmi *hdmi = s->private; 266 struct omap_hdmi *hdmi = s->private;
@@ -459,44 +419,25 @@ static void hdmi_core_disable(struct omap_hdmi *hdmi)
459 mutex_unlock(&hdmi->lock); 419 mutex_unlock(&hdmi->lock);
460} 420}
461 421
462static int hdmi_connect(struct omap_dss_device *dssdev, 422static int hdmi_connect(struct omap_dss_device *src,
463 struct omap_dss_device *dst) 423 struct omap_dss_device *dst)
464{ 424{
465 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
466 int r; 425 int r;
467 426
468 r = hdmi_init_regulator(hdmi); 427 r = omapdss_device_connect(dst->dss, dst, dst->next);
469 if (r)
470 return r;
471
472 r = dss_mgr_connect(&hdmi->output, dssdev);
473 if (r) 428 if (r)
474 return r; 429 return r;
475 430
476 r = omapdss_output_set_device(dssdev, dst); 431 dst->dispc_channel_connected = true;
477 if (r) {
478 DSSERR("failed to connect output to new device: %s\n",
479 dst->name);
480 dss_mgr_disconnect(&hdmi->output, dssdev);
481 return r;
482 }
483
484 return 0; 432 return 0;
485} 433}
486 434
487static void hdmi_disconnect(struct omap_dss_device *dssdev, 435static void hdmi_disconnect(struct omap_dss_device *src,
488 struct omap_dss_device *dst) 436 struct omap_dss_device *dst)
489{ 437{
490 struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); 438 dst->dispc_channel_connected = false;
491
492 WARN_ON(dst != dssdev->dst);
493 439
494 if (dst != dssdev->dst) 440 omapdss_device_disconnect(dst, dst->next);
495 return;
496
497 omapdss_output_unset_device(dssdev);
498
499 dss_mgr_disconnect(&hdmi->output, dssdev);
500} 441}
501 442
502static int hdmi_read_edid(struct omap_dss_device *dssdev, 443static int hdmi_read_edid(struct omap_dss_device *dssdev,
@@ -540,68 +481,27 @@ static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
540 return 0; 481 return 0;
541} 482}
542 483
543static const struct omapdss_hdmi_ops hdmi_ops = { 484static const struct omap_dss_device_ops hdmi_ops = {
544 .connect = hdmi_connect, 485 .connect = hdmi_connect,
545 .disconnect = hdmi_disconnect, 486 .disconnect = hdmi_disconnect,
546 487
547 .enable = hdmi_display_enable, 488 .enable = hdmi_display_enable,
548 .disable = hdmi_display_disable, 489 .disable = hdmi_display_disable,
549 490
550 .check_timings = hdmi_display_check_timing, 491 .set_timings = hdmi_display_set_timings,
551 .set_timings = hdmi_display_set_timing,
552 .get_timings = hdmi_display_get_timings,
553 492
554 .read_edid = hdmi_read_edid, 493 .read_edid = hdmi_read_edid,
555 .set_infoframe = hdmi_set_infoframe,
556 .set_hdmi_mode = hdmi_set_hdmi_mode,
557};
558
559static void hdmi_init_output(struct omap_hdmi *hdmi)
560{
561 struct omap_dss_device *out = &hdmi->output;
562
563 out->dev = &hdmi->pdev->dev;
564 out->id = OMAP_DSS_OUTPUT_HDMI;
565 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
566 out->name = "hdmi.0";
567 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
568 out->ops.hdmi = &hdmi_ops;
569 out->owner = THIS_MODULE;
570
571 omapdss_register_output(out);
572}
573
574static void hdmi_uninit_output(struct omap_hdmi *hdmi)
575{
576 struct omap_dss_device *out = &hdmi->output;
577
578 omapdss_unregister_output(out);
579}
580
581static int hdmi_probe_of(struct omap_hdmi *hdmi)
582{
583 struct platform_device *pdev = hdmi->pdev;
584 struct device_node *node = pdev->dev.of_node;
585 struct device_node *ep;
586 int r;
587
588 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
589 if (!ep)
590 return 0;
591
592 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
593 if (r)
594 goto err;
595 494
596 of_node_put(ep); 495 .hdmi = {
597 return 0; 496 .set_infoframe = hdmi_set_infoframe,
497 .set_hdmi_mode = hdmi_set_hdmi_mode,
498 },
499};
598 500
599err: 501/* -----------------------------------------------------------------------------
600 of_node_put(ep); 502 * Audio Callbacks
601 return r; 503 */
602}
603 504
604/* Audio callbacks */
605static int hdmi_audio_startup(struct device *dev, 505static int hdmi_audio_startup(struct device *dev,
606 void (*abort_cb)(struct device *dev)) 506 void (*abort_cb)(struct device *dev))
607{ 507{
@@ -722,27 +622,136 @@ static int hdmi_audio_register(struct omap_hdmi *hdmi)
722 return 0; 622 return 0;
723} 623}
724 624
725/* HDMI HW IP initialisation */ 625/* -----------------------------------------------------------------------------
626 * Component Bind & Unbind
627 */
628
726static int hdmi5_bind(struct device *dev, struct device *master, void *data) 629static int hdmi5_bind(struct device *dev, struct device *master, void *data)
727{ 630{
728 struct platform_device *pdev = to_platform_device(dev);
729 struct dss_device *dss = dss_get_device(master); 631 struct dss_device *dss = dss_get_device(master);
730 struct omap_hdmi *hdmi; 632 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
633 int r;
634
635 hdmi->dss = dss;
636
637 r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
638 if (r)
639 return r;
640
641 r = hdmi_audio_register(hdmi);
642 if (r) {
643 DSSERR("Registering HDMI audio failed %d\n", r);
644 goto err_pll_uninit;
645 }
646
647 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
648 hdmi);
649
650 return 0;
651
652err_pll_uninit:
653 hdmi_pll_uninit(&hdmi->pll);
654 return r;
655}
656
657static void hdmi5_unbind(struct device *dev, struct device *master, void *data)
658{
659 struct omap_hdmi *hdmi = dev_get_drvdata(dev);
660
661 dss_debugfs_remove_file(hdmi->debugfs);
662
663 if (hdmi->audio_pdev)
664 platform_device_unregister(hdmi->audio_pdev);
665
666 hdmi_pll_uninit(&hdmi->pll);
667}
668
669static const struct component_ops hdmi5_component_ops = {
670 .bind = hdmi5_bind,
671 .unbind = hdmi5_unbind,
672};
673
674/* -----------------------------------------------------------------------------
675 * Probe & Remove, Suspend & Resume
676 */
677
678static int hdmi5_init_output(struct omap_hdmi *hdmi)
679{
680 struct omap_dss_device *out = &hdmi->output;
681 int r;
682
683 out->dev = &hdmi->pdev->dev;
684 out->id = OMAP_DSS_OUTPUT_HDMI;
685 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
686 out->name = "hdmi.0";
687 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
688 out->ops = &hdmi_ops;
689 out->owner = THIS_MODULE;
690 out->of_ports = BIT(0);
691 out->ops_flags = OMAP_DSS_DEVICE_OP_EDID;
692
693 out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
694 if (IS_ERR(out->next)) {
695 if (PTR_ERR(out->next) != -EPROBE_DEFER)
696 dev_err(out->dev, "failed to find video sink\n");
697 return PTR_ERR(out->next);
698 }
699
700 r = omapdss_output_validate(out);
701 if (r) {
702 omapdss_device_put(out->next);
703 out->next = NULL;
704 return r;
705 }
706
707 omapdss_device_register(out);
708
709 return 0;
710}
711
712static void hdmi5_uninit_output(struct omap_hdmi *hdmi)
713{
714 struct omap_dss_device *out = &hdmi->output;
715
716 if (out->next)
717 omapdss_device_put(out->next);
718 omapdss_device_unregister(out);
719}
720
721static int hdmi5_probe_of(struct omap_hdmi *hdmi)
722{
723 struct platform_device *pdev = hdmi->pdev;
724 struct device_node *node = pdev->dev.of_node;
725 struct device_node *ep;
731 int r; 726 int r;
727
728 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
729 if (!ep)
730 return 0;
731
732 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
733 of_node_put(ep);
734 return r;
735}
736
737static int hdmi5_probe(struct platform_device *pdev)
738{
739 struct omap_hdmi *hdmi;
732 int irq; 740 int irq;
741 int r;
733 742
734 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL); 743 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
735 if (!hdmi) 744 if (!hdmi)
736 return -ENOMEM; 745 return -ENOMEM;
737 746
738 hdmi->pdev = pdev; 747 hdmi->pdev = pdev;
739 hdmi->dss = dss; 748
740 dev_set_drvdata(&pdev->dev, hdmi); 749 dev_set_drvdata(&pdev->dev, hdmi);
741 750
742 mutex_init(&hdmi->lock); 751 mutex_init(&hdmi->lock);
743 spin_lock_init(&hdmi->audio_playing_lock); 752 spin_lock_init(&hdmi->audio_playing_lock);
744 753
745 r = hdmi_probe_of(hdmi); 754 r = hdmi5_probe_of(hdmi);
746 if (r) 755 if (r)
747 goto err_free; 756 goto err_free;
748 757
@@ -750,23 +759,19 @@ static int hdmi5_bind(struct device *dev, struct device *master, void *data)
750 if (r) 759 if (r)
751 goto err_free; 760 goto err_free;
752 761
753 r = hdmi_pll_init(dss, pdev, &hdmi->pll, &hdmi->wp);
754 if (r)
755 goto err_free;
756
757 r = hdmi_phy_init(pdev, &hdmi->phy, 5); 762 r = hdmi_phy_init(pdev, &hdmi->phy, 5);
758 if (r) 763 if (r)
759 goto err_pll; 764 goto err_free;
760 765
761 r = hdmi5_core_init(pdev, &hdmi->core); 766 r = hdmi5_core_init(pdev, &hdmi->core);
762 if (r) 767 if (r)
763 goto err_pll; 768 goto err_free;
764 769
765 irq = platform_get_irq(pdev, 0); 770 irq = platform_get_irq(pdev, 0);
766 if (irq < 0) { 771 if (irq < 0) {
767 DSSERR("platform_get_irq failed\n"); 772 DSSERR("platform_get_irq failed\n");
768 r = -ENODEV; 773 r = -ENODEV;
769 goto err_pll; 774 goto err_free;
770 } 775 }
771 776
772 r = devm_request_threaded_irq(&pdev->dev, irq, 777 r = devm_request_threaded_irq(&pdev->dev, irq,
@@ -774,64 +779,49 @@ static int hdmi5_bind(struct device *dev, struct device *master, void *data)
774 IRQF_ONESHOT, "OMAP HDMI", hdmi); 779 IRQF_ONESHOT, "OMAP HDMI", hdmi);
775 if (r) { 780 if (r) {
776 DSSERR("HDMI IRQ request failed\n"); 781 DSSERR("HDMI IRQ request failed\n");
777 goto err_pll; 782 goto err_free;
778 } 783 }
779 784
780 pm_runtime_enable(&pdev->dev); 785 hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda");
786 if (IS_ERR(hdmi->vdda_reg)) {
787 r = PTR_ERR(hdmi->vdda_reg);
788 if (r != -EPROBE_DEFER)
789 DSSERR("can't get VDDA regulator\n");
790 goto err_free;
791 }
781 792
782 hdmi_init_output(hdmi); 793 pm_runtime_enable(&pdev->dev);
783 794
784 r = hdmi_audio_register(hdmi); 795 r = hdmi5_init_output(hdmi);
785 if (r) { 796 if (r)
786 DSSERR("Registering HDMI audio failed %d\n", r); 797 goto err_pm_disable;
787 hdmi_uninit_output(hdmi);
788 pm_runtime_disable(&pdev->dev);
789 return r;
790 }
791 798
792 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs, 799 r = component_add(&pdev->dev, &hdmi5_component_ops);
793 hdmi); 800 if (r)
801 goto err_uninit_output;
794 802
795 return 0; 803 return 0;
796 804
797err_pll: 805err_uninit_output:
798 hdmi_pll_uninit(&hdmi->pll); 806 hdmi5_uninit_output(hdmi);
807err_pm_disable:
808 pm_runtime_disable(&pdev->dev);
799err_free: 809err_free:
800 kfree(hdmi); 810 kfree(hdmi);
801 return r; 811 return r;
802} 812}
803 813
804static void hdmi5_unbind(struct device *dev, struct device *master, void *data) 814static int hdmi5_remove(struct platform_device *pdev)
805{ 815{
806 struct omap_hdmi *hdmi = dev_get_drvdata(dev); 816 struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
807
808 dss_debugfs_remove_file(hdmi->debugfs);
809 817
810 if (hdmi->audio_pdev) 818 component_del(&pdev->dev, &hdmi5_component_ops);
811 platform_device_unregister(hdmi->audio_pdev);
812
813 hdmi_uninit_output(hdmi);
814 819
815 hdmi_pll_uninit(&hdmi->pll); 820 hdmi5_uninit_output(hdmi);
816 821
817 pm_runtime_disable(dev); 822 pm_runtime_disable(&pdev->dev);
818 823
819 kfree(hdmi); 824 kfree(hdmi);
820}
821
822static const struct component_ops hdmi5_component_ops = {
823 .bind = hdmi5_bind,
824 .unbind = hdmi5_unbind,
825};
826
827static int hdmi5_probe(struct platform_device *pdev)
828{
829 return component_add(&pdev->dev, &hdmi5_component_ops);
830}
831
832static int hdmi5_remove(struct platform_device *pdev)
833{
834 component_del(&pdev->dev, &hdmi5_component_ops);
835 return 0; 825 return 0;
836} 826}
837 827
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi5_core.c b/drivers/gpu/drm/omapdrm/dss/hdmi5_core.c
index 2282e48574c6..02efabc7ed76 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi5_core.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi5_core.c
@@ -287,7 +287,7 @@ void hdmi5_core_dump(struct hdmi_core_data *core, struct seq_file *s)
287} 287}
288 288
289static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg, 289static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg,
290 struct hdmi_config *cfg) 290 const struct hdmi_config *cfg)
291{ 291{
292 DSSDBG("hdmi_core_init\n"); 292 DSSDBG("hdmi_core_init\n");
293 293
@@ -325,10 +325,10 @@ static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg,
325 325
326/* DSS_HDMI_CORE_VIDEO_CONFIG */ 326/* DSS_HDMI_CORE_VIDEO_CONFIG */
327static void hdmi_core_video_config(struct hdmi_core_data *core, 327static void hdmi_core_video_config(struct hdmi_core_data *core,
328 struct hdmi_core_vid_config *cfg) 328 const struct hdmi_core_vid_config *cfg)
329{ 329{
330 void __iomem *base = core->base; 330 void __iomem *base = core->base;
331 struct videomode *vm = &cfg->v_fc_config.vm; 331 const struct videomode *vm = &cfg->v_fc_config.vm;
332 unsigned char r = 0; 332 unsigned char r = 0;
333 bool vsync_pol, hsync_pol; 333 bool vsync_pol, hsync_pol;
334 334
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi_wp.c b/drivers/gpu/drm/omapdrm/dss/hdmi_wp.c
index 53bc5f78050c..100efb9f08c6 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi_wp.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi_wp.c
@@ -131,7 +131,7 @@ void hdmi_wp_video_stop(struct hdmi_wp_data *wp)
131} 131}
132 132
133void hdmi_wp_video_config_format(struct hdmi_wp_data *wp, 133void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
134 struct hdmi_video_format *video_fmt) 134 const struct hdmi_video_format *video_fmt)
135{ 135{
136 u32 l = 0; 136 u32 l = 0;
137 137
@@ -144,7 +144,7 @@ void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
144} 144}
145 145
146void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp, 146void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
147 struct videomode *vm) 147 const struct videomode *vm)
148{ 148{
149 u32 r; 149 u32 r;
150 bool vsync_inv, hsync_inv; 150 bool vsync_inv, hsync_inv;
@@ -164,7 +164,7 @@ void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
164} 164}
165 165
166void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp, 166void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
167 struct videomode *vm) 167 const struct videomode *vm)
168{ 168{
169 u32 timing_h = 0; 169 u32 timing_h = 0;
170 u32 timing_v = 0; 170 u32 timing_v = 0;
@@ -193,7 +193,7 @@ void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
193} 193}
194 194
195void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt, 195void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
196 struct videomode *vm, struct hdmi_config *param) 196 struct videomode *vm, const struct hdmi_config *param)
197{ 197{
198 DSSDBG("Enter hdmi_wp_video_init_format\n"); 198 DSSDBG("Enter hdmi_wp_video_init_format\n");
199 199
diff --git a/drivers/gpu/drm/omapdrm/dss/omapdss.h b/drivers/gpu/drm/omapdrm/dss/omapdss.h
index 14d74adb13fb..1f698a95a94a 100644
--- a/drivers/gpu/drm/omapdrm/dss/omapdss.h
+++ b/drivers/gpu/drm/omapdrm/dss/omapdss.h
@@ -296,117 +296,14 @@ struct omap_dss_writeback_info {
296 u8 pre_mult_alpha; 296 u8 pre_mult_alpha;
297}; 297};
298 298
299struct omapdss_dpi_ops {
300 int (*connect)(struct omap_dss_device *dssdev,
301 struct omap_dss_device *dst);
302 void (*disconnect)(struct omap_dss_device *dssdev,
303 struct omap_dss_device *dst);
304
305 int (*enable)(struct omap_dss_device *dssdev);
306 void (*disable)(struct omap_dss_device *dssdev);
307
308 int (*check_timings)(struct omap_dss_device *dssdev,
309 struct videomode *vm);
310 void (*set_timings)(struct omap_dss_device *dssdev,
311 struct videomode *vm);
312 void (*get_timings)(struct omap_dss_device *dssdev,
313 struct videomode *vm);
314};
315
316struct omapdss_sdi_ops {
317 int (*connect)(struct omap_dss_device *dssdev,
318 struct omap_dss_device *dst);
319 void (*disconnect)(struct omap_dss_device *dssdev,
320 struct omap_dss_device *dst);
321
322 int (*enable)(struct omap_dss_device *dssdev);
323 void (*disable)(struct omap_dss_device *dssdev);
324
325 int (*check_timings)(struct omap_dss_device *dssdev,
326 struct videomode *vm);
327 void (*set_timings)(struct omap_dss_device *dssdev,
328 struct videomode *vm);
329 void (*get_timings)(struct omap_dss_device *dssdev,
330 struct videomode *vm);
331};
332
333struct omapdss_dvi_ops {
334 int (*connect)(struct omap_dss_device *dssdev,
335 struct omap_dss_device *dst);
336 void (*disconnect)(struct omap_dss_device *dssdev,
337 struct omap_dss_device *dst);
338
339 int (*enable)(struct omap_dss_device *dssdev);
340 void (*disable)(struct omap_dss_device *dssdev);
341
342 int (*check_timings)(struct omap_dss_device *dssdev,
343 struct videomode *vm);
344 void (*set_timings)(struct omap_dss_device *dssdev,
345 struct videomode *vm);
346 void (*get_timings)(struct omap_dss_device *dssdev,
347 struct videomode *vm);
348};
349
350struct omapdss_atv_ops {
351 int (*connect)(struct omap_dss_device *dssdev,
352 struct omap_dss_device *dst);
353 void (*disconnect)(struct omap_dss_device *dssdev,
354 struct omap_dss_device *dst);
355
356 int (*enable)(struct omap_dss_device *dssdev);
357 void (*disable)(struct omap_dss_device *dssdev);
358
359 int (*check_timings)(struct omap_dss_device *dssdev,
360 struct videomode *vm);
361 void (*set_timings)(struct omap_dss_device *dssdev,
362 struct videomode *vm);
363 void (*get_timings)(struct omap_dss_device *dssdev,
364 struct videomode *vm);
365
366 int (*set_wss)(struct omap_dss_device *dssdev, u32 wss);
367 u32 (*get_wss)(struct omap_dss_device *dssdev);
368};
369
370struct omapdss_hdmi_ops { 299struct omapdss_hdmi_ops {
371 int (*connect)(struct omap_dss_device *dssdev,
372 struct omap_dss_device *dst);
373 void (*disconnect)(struct omap_dss_device *dssdev,
374 struct omap_dss_device *dst);
375
376 int (*enable)(struct omap_dss_device *dssdev);
377 void (*disable)(struct omap_dss_device *dssdev);
378
379 int (*check_timings)(struct omap_dss_device *dssdev,
380 struct videomode *vm);
381 void (*set_timings)(struct omap_dss_device *dssdev,
382 struct videomode *vm);
383 void (*get_timings)(struct omap_dss_device *dssdev,
384 struct videomode *vm);
385
386 int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
387 void (*lost_hotplug)(struct omap_dss_device *dssdev); 300 void (*lost_hotplug)(struct omap_dss_device *dssdev);
388 bool (*detect)(struct omap_dss_device *dssdev);
389
390 int (*register_hpd_cb)(struct omap_dss_device *dssdev,
391 void (*cb)(void *cb_data,
392 enum drm_connector_status status),
393 void *cb_data);
394 void (*unregister_hpd_cb)(struct omap_dss_device *dssdev);
395 void (*enable_hpd)(struct omap_dss_device *dssdev);
396 void (*disable_hpd)(struct omap_dss_device *dssdev);
397
398 int (*set_hdmi_mode)(struct omap_dss_device *dssdev, bool hdmi_mode); 301 int (*set_hdmi_mode)(struct omap_dss_device *dssdev, bool hdmi_mode);
399 int (*set_infoframe)(struct omap_dss_device *dssdev, 302 int (*set_infoframe)(struct omap_dss_device *dssdev,
400 const struct hdmi_avi_infoframe *avi); 303 const struct hdmi_avi_infoframe *avi);
401}; 304};
402 305
403struct omapdss_dsi_ops { 306struct omapdss_dsi_ops {
404 int (*connect)(struct omap_dss_device *dssdev,
405 struct omap_dss_device *dst);
406 void (*disconnect)(struct omap_dss_device *dssdev,
407 struct omap_dss_device *dst);
408
409 int (*enable)(struct omap_dss_device *dssdev);
410 void (*disable)(struct omap_dss_device *dssdev, bool disconnect_lanes, 307 void (*disable)(struct omap_dss_device *dssdev, bool disconnect_lanes,
411 bool enter_ulps); 308 bool enter_ulps);
412 309
@@ -457,53 +354,95 @@ struct omapdss_dsi_ops {
457 int channel, u16 plen); 354 int channel, u16 plen);
458}; 355};
459 356
357struct omap_dss_device_ops {
358 int (*connect)(struct omap_dss_device *dssdev,
359 struct omap_dss_device *dst);
360 void (*disconnect)(struct omap_dss_device *dssdev,
361 struct omap_dss_device *dst);
362
363 int (*enable)(struct omap_dss_device *dssdev);
364 void (*disable)(struct omap_dss_device *dssdev);
365
366 int (*check_timings)(struct omap_dss_device *dssdev,
367 struct videomode *vm);
368 void (*get_timings)(struct omap_dss_device *dssdev,
369 struct videomode *vm);
370 void (*set_timings)(struct omap_dss_device *dssdev,
371 const struct videomode *vm);
372
373 bool (*detect)(struct omap_dss_device *dssdev);
374
375 void (*register_hpd_cb)(struct omap_dss_device *dssdev,
376 void (*cb)(void *cb_data,
377 enum drm_connector_status status),
378 void *cb_data);
379 void (*unregister_hpd_cb)(struct omap_dss_device *dssdev);
380
381 int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
382
383 union {
384 const struct omapdss_hdmi_ops hdmi;
385 const struct omapdss_dsi_ops dsi;
386 };
387};
388
389/**
390 * enum omap_dss_device_ops_flag - Indicates which device ops are supported
391 * @OMAP_DSS_DEVICE_OP_DETECT: The device supports output connection detection
392 * @OMAP_DSS_DEVICE_OP_HPD: The device supports all hot-plug-related operations
393 * @OMAP_DSS_DEVICE_OP_EDID: The device supports readind EDID
394 */
395enum omap_dss_device_ops_flag {
396 OMAP_DSS_DEVICE_OP_DETECT = BIT(0),
397 OMAP_DSS_DEVICE_OP_HPD = BIT(1),
398 OMAP_DSS_DEVICE_OP_EDID = BIT(2),
399};
400
401enum omap_dss_device_type {
402 OMAP_DSS_DEVICE_TYPE_OUTPUT = (1 << 0),
403 OMAP_DSS_DEVICE_TYPE_DISPLAY = (1 << 1),
404};
405
460struct omap_dss_device { 406struct omap_dss_device {
461 struct kobject kobj; 407 struct kobject kobj;
462 struct device *dev; 408 struct device *dev;
463 409
464 struct module *owner; 410 struct module *owner;
465 411
466 struct list_head panel_list; 412 struct dss_device *dss;
413 struct omap_dss_device *src;
414 struct omap_dss_device *dst;
415 struct omap_dss_device *next;
416
417 struct list_head list;
467 418
468 /* alias in the form of "display%d" */ 419 unsigned int alias_id;
469 char alias[16];
470 420
471 enum omap_display_type type; 421 enum omap_display_type type;
422 /*
423 * DSS output type that this device generates (for DSS internal devices)
424 * or requires (for external encoders). Must be OMAP_DISPLAY_TYPE_NONE
425 * for display devices (connectors and panels) and to non-zero value for
426 * all other devices.
427 */
472 enum omap_display_type output_type; 428 enum omap_display_type output_type;
473 429
474 struct {
475 struct videomode vm;
476
477 enum omap_dss_dsi_pixel_format dsi_pix_fmt;
478 enum omap_dss_dsi_mode dsi_mode;
479 } panel;
480
481 const char *name; 430 const char *name;
482 431
483 struct omap_dss_driver *driver; 432 const struct omap_dss_driver *driver;
484 433 const struct omap_dss_device_ops *ops;
485 union { 434 unsigned long ops_flags;
486 const struct omapdss_dpi_ops *dpi; 435 unsigned long bus_flags;
487 const struct omapdss_sdi_ops *sdi;
488 const struct omapdss_dvi_ops *dvi;
489 const struct omapdss_hdmi_ops *hdmi;
490 const struct omapdss_atv_ops *atv;
491 const struct omapdss_dsi_ops *dsi;
492 } ops;
493 436
494 /* helper variable for driver suspend/resume */ 437 /* helper variable for driver suspend/resume */
495 bool activate_after_resume; 438 bool activate_after_resume;
496 439
497 enum omap_display_caps caps; 440 enum omap_display_caps caps;
498 441
499 struct omap_dss_device *src;
500
501 enum omap_dss_display_state state; 442 enum omap_dss_display_state state;
502 443
503 /* OMAP DSS output specific fields */ 444 /* OMAP DSS output specific fields */
504 445
505 struct list_head list;
506
507 /* DISPC channel for this output */ 446 /* DISPC channel for this output */
508 enum omap_channel dispc_channel; 447 enum omap_channel dispc_channel;
509 bool dispc_channel_connected; 448 bool dispc_channel_connected;
@@ -511,24 +450,11 @@ struct omap_dss_device {
511 /* output instance */ 450 /* output instance */
512 enum omap_dss_output_id id; 451 enum omap_dss_output_id id;
513 452
514 /* the port number in the DT node */ 453 /* bitmask of port numbers in DT */
515 int port_num; 454 unsigned int of_ports;
516
517 /* dynamic fields */
518 struct omap_dss_device *dst;
519}; 455};
520 456
521struct omap_dss_driver { 457struct omap_dss_driver {
522 int (*probe)(struct omap_dss_device *);
523 void (*remove)(struct omap_dss_device *);
524
525 int (*connect)(struct omap_dss_device *dssdev);
526 void (*disconnect)(struct omap_dss_device *dssdev);
527
528 int (*enable)(struct omap_dss_device *display);
529 void (*disable)(struct omap_dss_device *display);
530 int (*run_test)(struct omap_dss_device *display, int test);
531
532 int (*update)(struct omap_dss_device *dssdev, 458 int (*update)(struct omap_dss_device *dssdev,
533 u16 x, u16 y, u16 w, u16 h); 459 u16 x, u16 y, u16 w, u16 h);
534 int (*sync)(struct omap_dss_device *dssdev); 460 int (*sync)(struct omap_dss_device *dssdev);
@@ -536,42 +462,12 @@ struct omap_dss_driver {
536 int (*enable_te)(struct omap_dss_device *dssdev, bool enable); 462 int (*enable_te)(struct omap_dss_device *dssdev, bool enable);
537 int (*get_te)(struct omap_dss_device *dssdev); 463 int (*get_te)(struct omap_dss_device *dssdev);
538 464
539 u8 (*get_rotate)(struct omap_dss_device *dssdev);
540 int (*set_rotate)(struct omap_dss_device *dssdev, u8 rotate);
541
542 bool (*get_mirror)(struct omap_dss_device *dssdev);
543 int (*set_mirror)(struct omap_dss_device *dssdev, bool enable);
544
545 int (*memory_read)(struct omap_dss_device *dssdev, 465 int (*memory_read)(struct omap_dss_device *dssdev,
546 void *buf, size_t size, 466 void *buf, size_t size,
547 u16 x, u16 y, u16 w, u16 h); 467 u16 x, u16 y, u16 w, u16 h);
548 468
549 int (*check_timings)(struct omap_dss_device *dssdev,
550 struct videomode *vm);
551 void (*set_timings)(struct omap_dss_device *dssdev,
552 struct videomode *vm);
553 void (*get_timings)(struct omap_dss_device *dssdev,
554 struct videomode *vm);
555 void (*get_size)(struct omap_dss_device *dssdev, 469 void (*get_size)(struct omap_dss_device *dssdev,
556 unsigned int *width, unsigned int *height); 470 unsigned int *width, unsigned int *height);
557
558 int (*set_wss)(struct omap_dss_device *dssdev, u32 wss);
559 u32 (*get_wss)(struct omap_dss_device *dssdev);
560
561 int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
562 bool (*detect)(struct omap_dss_device *dssdev);
563
564 int (*register_hpd_cb)(struct omap_dss_device *dssdev,
565 void (*cb)(void *cb_data,
566 enum drm_connector_status status),
567 void *cb_data);
568 void (*unregister_hpd_cb)(struct omap_dss_device *dssdev);
569 void (*enable_hpd)(struct omap_dss_device *dssdev);
570 void (*disable_hpd)(struct omap_dss_device *dssdev);
571
572 int (*set_hdmi_mode)(struct omap_dss_device *dssdev, bool hdmi_mode);
573 int (*set_hdmi_infoframe)(struct omap_dss_device *dssdev,
574 const struct hdmi_avi_infoframe *avi);
575}; 471};
576 472
577struct dss_device *omapdss_get_dss(void); 473struct dss_device *omapdss_get_dss(void);
@@ -581,27 +477,32 @@ static inline bool omapdss_is_initialized(void)
581 return !!omapdss_get_dss(); 477 return !!omapdss_get_dss();
582} 478}
583 479
584int omapdss_register_display(struct omap_dss_device *dssdev); 480#define for_each_dss_display(d) \
585void omapdss_unregister_display(struct omap_dss_device *dssdev); 481 while ((d = omapdss_device_get_next(d, OMAP_DSS_DEVICE_TYPE_DISPLAY)) != NULL)
586 482void omapdss_display_init(struct omap_dss_device *dssdev);
587struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev); 483struct omap_dss_device *omapdss_display_get(struct omap_dss_device *output);
588void omap_dss_put_device(struct omap_dss_device *dssdev); 484
589#define for_each_dss_dev(d) while ((d = omap_dss_get_next_device(d)) != NULL) 485void omapdss_device_register(struct omap_dss_device *dssdev);
590struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from); 486void omapdss_device_unregister(struct omap_dss_device *dssdev);
487struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev);
488void omapdss_device_put(struct omap_dss_device *dssdev);
489struct omap_dss_device *omapdss_find_device_by_port(struct device_node *src,
490 unsigned int port);
491struct omap_dss_device *omapdss_device_get_next(struct omap_dss_device *from,
492 enum omap_dss_device_type type);
493int omapdss_device_connect(struct dss_device *dss,
494 struct omap_dss_device *src,
495 struct omap_dss_device *dst);
496void omapdss_device_disconnect(struct omap_dss_device *src,
497 struct omap_dss_device *dst);
591 498
592int omap_dss_get_num_overlay_managers(void); 499int omap_dss_get_num_overlay_managers(void);
593 500
594int omap_dss_get_num_overlays(void); 501int omap_dss_get_num_overlays(void);
595 502
596int omapdss_register_output(struct omap_dss_device *output); 503#define for_each_dss_output(d) \
597void omapdss_unregister_output(struct omap_dss_device *output); 504 while ((d = omapdss_device_get_next(d, OMAP_DSS_DEVICE_TYPE_OUTPUT)) != NULL)
598struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id); 505int omapdss_output_validate(struct omap_dss_device *out);
599struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port);
600int omapdss_output_set_device(struct omap_dss_device *out,
601 struct omap_dss_device *dssdev);
602int omapdss_output_unset_device(struct omap_dss_device *out);
603
604struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev);
605 506
606typedef void (*omap_dispc_isr_t) (void *arg, u32 mask); 507typedef void (*omap_dispc_isr_t) (void *arg, u32 mask);
607int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask); 508int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask);
@@ -621,10 +522,7 @@ static inline bool omapdss_device_is_enabled(struct omap_dss_device *dssdev)
621} 522}
622 523
623struct omap_dss_device * 524struct omap_dss_device *
624omapdss_of_find_source_for_first_ep(struct device_node *node); 525omapdss_of_find_connected_device(struct device_node *node, unsigned int port);
625
626struct device_node *dss_of_port_get_parent_device(struct device_node *port);
627u32 dss_of_port_get_port_number(struct device_node *port);
628 526
629enum dss_writeback_channel { 527enum dss_writeback_channel {
630 DSS_WB_LCD1_MGR = 0, 528 DSS_WB_LCD1_MGR = 0,
@@ -638,13 +536,6 @@ enum dss_writeback_channel {
638}; 536};
639 537
640struct dss_mgr_ops { 538struct dss_mgr_ops {
641 int (*connect)(struct omap_drm_private *priv,
642 enum omap_channel channel,
643 struct omap_dss_device *dst);
644 void (*disconnect)(struct omap_drm_private *priv,
645 enum omap_channel channel,
646 struct omap_dss_device *dst);
647
648 void (*start_update)(struct omap_drm_private *priv, 539 void (*start_update)(struct omap_drm_private *priv,
649 enum omap_channel channel); 540 enum omap_channel channel);
650 int (*enable)(struct omap_drm_private *priv, 541 int (*enable)(struct omap_drm_private *priv,
@@ -665,14 +556,11 @@ struct dss_mgr_ops {
665 void (*handler)(void *), void *data); 556 void (*handler)(void *), void *data);
666}; 557};
667 558
668int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops, 559int dss_install_mgr_ops(struct dss_device *dss,
560 const struct dss_mgr_ops *mgr_ops,
669 struct omap_drm_private *priv); 561 struct omap_drm_private *priv);
670void dss_uninstall_mgr_ops(void); 562void dss_uninstall_mgr_ops(struct dss_device *dss);
671 563
672int dss_mgr_connect(struct omap_dss_device *dssdev,
673 struct omap_dss_device *dst);
674void dss_mgr_disconnect(struct omap_dss_device *dssdev,
675 struct omap_dss_device *dst);
676void dss_mgr_set_timings(struct omap_dss_device *dssdev, 564void dss_mgr_set_timings(struct omap_dss_device *dssdev,
677 const struct videomode *vm); 565 const struct videomode *vm);
678void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev, 566void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev,
@@ -720,13 +608,14 @@ struct dispc_ops {
720 void (*mgr_set_lcd_config)(struct dispc_device *dispc, 608 void (*mgr_set_lcd_config)(struct dispc_device *dispc,
721 enum omap_channel channel, 609 enum omap_channel channel,
722 const struct dss_lcd_mgr_config *config); 610 const struct dss_lcd_mgr_config *config);
611 int (*mgr_check_timings)(struct dispc_device *dispc,
612 enum omap_channel channel,
613 const struct videomode *vm);
723 void (*mgr_set_timings)(struct dispc_device *dispc, 614 void (*mgr_set_timings)(struct dispc_device *dispc,
724 enum omap_channel channel, 615 enum omap_channel channel,
725 const struct videomode *vm); 616 const struct videomode *vm);
726 void (*mgr_setup)(struct dispc_device *dispc, enum omap_channel channel, 617 void (*mgr_setup)(struct dispc_device *dispc, enum omap_channel channel,
727 const struct omap_overlay_manager_info *info); 618 const struct omap_overlay_manager_info *info);
728 enum omap_dss_output_id (*mgr_get_supported_outputs)(
729 struct dispc_device *dispc, enum omap_channel channel);
730 u32 (*mgr_gamma_size)(struct dispc_device *dispc, 619 u32 (*mgr_gamma_size)(struct dispc_device *dispc,
731 enum omap_channel channel); 620 enum omap_channel channel);
732 void (*mgr_set_gamma)(struct dispc_device *dispc, 621 void (*mgr_set_gamma)(struct dispc_device *dispc,
@@ -757,9 +646,6 @@ struct dispc_ops {
757struct dispc_device *dispc_get_dispc(struct dss_device *dss); 646struct dispc_device *dispc_get_dispc(struct dss_device *dss);
758const struct dispc_ops *dispc_get_ops(struct dss_device *dss); 647const struct dispc_ops *dispc_get_ops(struct dss_device *dss);
759 648
760bool omapdss_component_is_display(struct device_node *node);
761bool omapdss_component_is_output(struct device_node *node);
762
763bool omapdss_stack_is_ready(void); 649bool omapdss_stack_is_ready(void);
764void omapdss_gather_components(struct device *dev); 650void omapdss_gather_components(struct device *dev);
765 651
diff --git a/drivers/gpu/drm/omapdrm/dss/output.c b/drivers/gpu/drm/omapdrm/dss/output.c
index 96b9d4cd505f..18505bc70f7e 100644
--- a/drivers/gpu/drm/omapdrm/dss/output.c
+++ b/drivers/gpu/drm/omapdrm/dss/output.c
@@ -21,238 +21,96 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/of.h> 22#include <linux/of.h>
23 23
24#include "dss.h"
24#include "omapdss.h" 25#include "omapdss.h"
25 26
26static LIST_HEAD(output_list); 27int omapdss_output_validate(struct omap_dss_device *out)
27static DEFINE_MUTEX(output_lock);
28
29int omapdss_output_set_device(struct omap_dss_device *out,
30 struct omap_dss_device *dssdev)
31{ 28{
32 int r; 29 if (out->next && out->output_type != out->next->type) {
33
34 mutex_lock(&output_lock);
35
36 if (out->dst) {
37 dev_err(out->dev,
38 "output already has device %s connected to it\n",
39 out->dst->name);
40 r = -EINVAL;
41 goto err;
42 }
43
44 if (out->output_type != dssdev->type) {
45 dev_err(out->dev, "output type and display type don't match\n"); 30 dev_err(out->dev, "output type and display type don't match\n");
46 r = -EINVAL; 31 return -EINVAL;
47 goto err;
48 }
49
50 out->dst = dssdev;
51 dssdev->src = out;
52
53 mutex_unlock(&output_lock);
54
55 return 0;
56err:
57 mutex_unlock(&output_lock);
58
59 return r;
60}
61EXPORT_SYMBOL(omapdss_output_set_device);
62
63int omapdss_output_unset_device(struct omap_dss_device *out)
64{
65 int r;
66
67 mutex_lock(&output_lock);
68
69 if (!out->dst) {
70 dev_err(out->dev,
71 "output doesn't have a device connected to it\n");
72 r = -EINVAL;
73 goto err;
74 } 32 }
75 33
76 if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
77 dev_err(out->dev,
78 "device %s is not disabled, cannot unset device\n",
79 out->dst->name);
80 r = -EINVAL;
81 goto err;
82 }
83
84 out->dst->src = NULL;
85 out->dst = NULL;
86
87 mutex_unlock(&output_lock);
88
89 return 0;
90err:
91 mutex_unlock(&output_lock);
92
93 return r;
94}
95EXPORT_SYMBOL(omapdss_output_unset_device);
96
97int omapdss_register_output(struct omap_dss_device *out)
98{
99 list_add_tail(&out->list, &output_list);
100 return 0; 34 return 0;
101} 35}
102EXPORT_SYMBOL(omapdss_register_output); 36EXPORT_SYMBOL(omapdss_output_validate);
103
104void omapdss_unregister_output(struct omap_dss_device *out)
105{
106 list_del(&out->list);
107}
108EXPORT_SYMBOL(omapdss_unregister_output);
109
110bool omapdss_component_is_output(struct device_node *node)
111{
112 struct omap_dss_device *out;
113
114 list_for_each_entry(out, &output_list, list) {
115 if (out->dev->of_node == node)
116 return true;
117 }
118 37
119 return false; 38int dss_install_mgr_ops(struct dss_device *dss,
120} 39 const struct dss_mgr_ops *mgr_ops,
121EXPORT_SYMBOL(omapdss_component_is_output);
122
123struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
124{
125 struct omap_dss_device *out;
126
127 list_for_each_entry(out, &output_list, list) {
128 if (out->id == id)
129 return out;
130 }
131
132 return NULL;
133}
134EXPORT_SYMBOL(omap_dss_get_output);
135
136struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
137{
138 struct device_node *src_node;
139 struct omap_dss_device *out;
140 u32 reg;
141
142 src_node = dss_of_port_get_parent_device(port);
143 if (!src_node)
144 return NULL;
145
146 reg = dss_of_port_get_port_number(port);
147
148 list_for_each_entry(out, &output_list, list) {
149 if (out->dev->of_node == src_node && out->port_num == reg) {
150 of_node_put(src_node);
151 return omap_dss_get_device(out);
152 }
153 }
154
155 of_node_put(src_node);
156
157 return NULL;
158}
159
160struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
161{
162 while (dssdev->src)
163 dssdev = dssdev->src;
164
165 if (dssdev->id != 0)
166 return omap_dss_get_device(dssdev);
167
168 return NULL;
169}
170EXPORT_SYMBOL(omapdss_find_output_from_display);
171
172static const struct dss_mgr_ops *dss_mgr_ops;
173static struct omap_drm_private *dss_mgr_ops_priv;
174
175int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops,
176 struct omap_drm_private *priv) 40 struct omap_drm_private *priv)
177{ 41{
178 if (dss_mgr_ops) 42 if (dss->mgr_ops)
179 return -EBUSY; 43 return -EBUSY;
180 44
181 dss_mgr_ops = mgr_ops; 45 dss->mgr_ops = mgr_ops;
182 dss_mgr_ops_priv = priv; 46 dss->mgr_ops_priv = priv;
183 47
184 return 0; 48 return 0;
185} 49}
186EXPORT_SYMBOL(dss_install_mgr_ops); 50EXPORT_SYMBOL(dss_install_mgr_ops);
187 51
188void dss_uninstall_mgr_ops(void) 52void dss_uninstall_mgr_ops(struct dss_device *dss)
189{ 53{
190 dss_mgr_ops = NULL; 54 dss->mgr_ops = NULL;
191 dss_mgr_ops_priv = NULL; 55 dss->mgr_ops_priv = NULL;
192} 56}
193EXPORT_SYMBOL(dss_uninstall_mgr_ops); 57EXPORT_SYMBOL(dss_uninstall_mgr_ops);
194 58
195int dss_mgr_connect(struct omap_dss_device *dssdev, struct omap_dss_device *dst)
196{
197 return dss_mgr_ops->connect(dss_mgr_ops_priv,
198 dssdev->dispc_channel, dst);
199}
200EXPORT_SYMBOL(dss_mgr_connect);
201
202void dss_mgr_disconnect(struct omap_dss_device *dssdev,
203 struct omap_dss_device *dst)
204{
205 dss_mgr_ops->disconnect(dss_mgr_ops_priv, dssdev->dispc_channel, dst);
206}
207EXPORT_SYMBOL(dss_mgr_disconnect);
208
209void dss_mgr_set_timings(struct omap_dss_device *dssdev, 59void dss_mgr_set_timings(struct omap_dss_device *dssdev,
210 const struct videomode *vm) 60 const struct videomode *vm)
211{ 61{
212 dss_mgr_ops->set_timings(dss_mgr_ops_priv, dssdev->dispc_channel, vm); 62 dssdev->dss->mgr_ops->set_timings(dssdev->dss->mgr_ops_priv,
63 dssdev->dispc_channel, vm);
213} 64}
214EXPORT_SYMBOL(dss_mgr_set_timings); 65EXPORT_SYMBOL(dss_mgr_set_timings);
215 66
216void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev, 67void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev,
217 const struct dss_lcd_mgr_config *config) 68 const struct dss_lcd_mgr_config *config)
218{ 69{
219 dss_mgr_ops->set_lcd_config(dss_mgr_ops_priv, 70 dssdev->dss->mgr_ops->set_lcd_config(dssdev->dss->mgr_ops_priv,
220 dssdev->dispc_channel, config); 71 dssdev->dispc_channel, config);
221} 72}
222EXPORT_SYMBOL(dss_mgr_set_lcd_config); 73EXPORT_SYMBOL(dss_mgr_set_lcd_config);
223 74
224int dss_mgr_enable(struct omap_dss_device *dssdev) 75int dss_mgr_enable(struct omap_dss_device *dssdev)
225{ 76{
226 return dss_mgr_ops->enable(dss_mgr_ops_priv, dssdev->dispc_channel); 77 return dssdev->dss->mgr_ops->enable(dssdev->dss->mgr_ops_priv,
78 dssdev->dispc_channel);
227} 79}
228EXPORT_SYMBOL(dss_mgr_enable); 80EXPORT_SYMBOL(dss_mgr_enable);
229 81
230void dss_mgr_disable(struct omap_dss_device *dssdev) 82void dss_mgr_disable(struct omap_dss_device *dssdev)
231{ 83{
232 dss_mgr_ops->disable(dss_mgr_ops_priv, dssdev->dispc_channel); 84 dssdev->dss->mgr_ops->disable(dssdev->dss->mgr_ops_priv,
85 dssdev->dispc_channel);
233} 86}
234EXPORT_SYMBOL(dss_mgr_disable); 87EXPORT_SYMBOL(dss_mgr_disable);
235 88
236void dss_mgr_start_update(struct omap_dss_device *dssdev) 89void dss_mgr_start_update(struct omap_dss_device *dssdev)
237{ 90{
238 dss_mgr_ops->start_update(dss_mgr_ops_priv, dssdev->dispc_channel); 91 dssdev->dss->mgr_ops->start_update(dssdev->dss->mgr_ops_priv,
92 dssdev->dispc_channel);
239} 93}
240EXPORT_SYMBOL(dss_mgr_start_update); 94EXPORT_SYMBOL(dss_mgr_start_update);
241 95
242int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev, 96int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev,
243 void (*handler)(void *), void *data) 97 void (*handler)(void *), void *data)
244{ 98{
245 return dss_mgr_ops->register_framedone_handler(dss_mgr_ops_priv, 99 struct dss_device *dss = dssdev->dss;
246 dssdev->dispc_channel, 100
247 handler, data); 101 return dss->mgr_ops->register_framedone_handler(dss->mgr_ops_priv,
102 dssdev->dispc_channel,
103 handler, data);
248} 104}
249EXPORT_SYMBOL(dss_mgr_register_framedone_handler); 105EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
250 106
251void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev, 107void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev,
252 void (*handler)(void *), void *data) 108 void (*handler)(void *), void *data)
253{ 109{
254 dss_mgr_ops->unregister_framedone_handler(dss_mgr_ops_priv, 110 struct dss_device *dss = dssdev->dss;
255 dssdev->dispc_channel, 111
256 handler, data); 112 dss->mgr_ops->unregister_framedone_handler(dss->mgr_ops_priv,
113 dssdev->dispc_channel,
114 handler, data);
257} 115}
258EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler); 116EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);
diff --git a/drivers/gpu/drm/omapdrm/dss/sdi.c b/drivers/gpu/drm/omapdrm/dss/sdi.c
index 69c3b7a3d5c7..b2fe2387037a 100644
--- a/drivers/gpu/drm/omapdrm/dss/sdi.c
+++ b/drivers/gpu/drm/omapdrm/dss/sdi.c
@@ -132,10 +132,8 @@ static void sdi_config_lcd_manager(struct sdi_device *sdi)
132static int sdi_display_enable(struct omap_dss_device *dssdev) 132static int sdi_display_enable(struct omap_dss_device *dssdev)
133{ 133{
134 struct sdi_device *sdi = dssdev_to_sdi(dssdev); 134 struct sdi_device *sdi = dssdev_to_sdi(dssdev);
135 struct videomode *vm = &sdi->vm;
136 unsigned long fck;
137 struct dispc_clock_info dispc_cinfo; 135 struct dispc_clock_info dispc_cinfo;
138 unsigned long pck; 136 unsigned long fck;
139 int r; 137 int r;
140 138
141 if (!sdi->output.dispc_channel_connected) { 139 if (!sdi->output.dispc_channel_connected) {
@@ -151,27 +149,12 @@ static int sdi_display_enable(struct omap_dss_device *dssdev)
151 if (r) 149 if (r)
152 goto err_get_dispc; 150 goto err_get_dispc;
153 151
154 /* 15.5.9.1.2 */ 152 r = sdi_calc_clock_div(sdi, sdi->vm.pixelclock, &fck, &dispc_cinfo);
155 vm->flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE | DISPLAY_FLAGS_SYNC_POSEDGE;
156
157 r = sdi_calc_clock_div(sdi, vm->pixelclock, &fck, &dispc_cinfo);
158 if (r) 153 if (r)
159 goto err_calc_clock_div; 154 goto err_calc_clock_div;
160 155
161 sdi->mgr_config.clock_info = dispc_cinfo; 156 sdi->mgr_config.clock_info = dispc_cinfo;
162 157
163 pck = fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div;
164
165 if (pck != vm->pixelclock) {
166 DSSWARN("Could not find exact pixel clock. Requested %lu Hz, got %lu Hz\n",
167 vm->pixelclock, pck);
168
169 vm->pixelclock = pck;
170 }
171
172
173 dss_mgr_set_timings(&sdi->output, vm);
174
175 r = dss_set_fck_rate(sdi->dss, fck); 158 r = dss_set_fck_rate(sdi->dss, fck);
176 if (r) 159 if (r)
177 goto err_set_dss_clock_div; 160 goto err_set_dss_clock_div;
@@ -230,96 +213,63 @@ static void sdi_display_disable(struct omap_dss_device *dssdev)
230} 213}
231 214
232static void sdi_set_timings(struct omap_dss_device *dssdev, 215static void sdi_set_timings(struct omap_dss_device *dssdev,
233 struct videomode *vm) 216 const struct videomode *vm)
234{ 217{
235 struct sdi_device *sdi = dssdev_to_sdi(dssdev); 218 struct sdi_device *sdi = dssdev_to_sdi(dssdev);
236 219
237 sdi->vm = *vm; 220 sdi->vm = *vm;
238} 221}
239 222
240static void sdi_get_timings(struct omap_dss_device *dssdev,
241 struct videomode *vm)
242{
243 struct sdi_device *sdi = dssdev_to_sdi(dssdev);
244
245 *vm = sdi->vm;
246}
247
248static int sdi_check_timings(struct omap_dss_device *dssdev, 223static int sdi_check_timings(struct omap_dss_device *dssdev,
249 struct videomode *vm) 224 struct videomode *vm)
250{ 225{
251 struct sdi_device *sdi = dssdev_to_sdi(dssdev); 226 struct sdi_device *sdi = dssdev_to_sdi(dssdev);
252 enum omap_channel channel = dssdev->dispc_channel; 227 struct dispc_clock_info dispc_cinfo;
253 228 unsigned long fck;
254 if (!dispc_mgr_timings_ok(sdi->dss->dispc, channel, vm)) 229 unsigned long pck;
255 return -EINVAL; 230 int r;
256 231
257 if (vm->pixelclock == 0) 232 if (vm->pixelclock == 0)
258 return -EINVAL; 233 return -EINVAL;
259 234
260 return 0; 235 r = sdi_calc_clock_div(sdi, vm->pixelclock, &fck, &dispc_cinfo);
261} 236 if (r)
237 return r;
262 238
263static int sdi_init_regulator(struct sdi_device *sdi) 239 pck = fck / dispc_cinfo.lck_div / dispc_cinfo.pck_div;
264{
265 struct regulator *vdds_sdi;
266 240
267 if (sdi->vdds_sdi_reg) 241 if (pck != vm->pixelclock) {
268 return 0; 242 DSSWARN("Pixel clock adjusted from %lu Hz to %lu Hz\n",
243 vm->pixelclock, pck);
269 244
270 vdds_sdi = devm_regulator_get(&sdi->pdev->dev, "vdds_sdi"); 245 vm->pixelclock = pck;
271 if (IS_ERR(vdds_sdi)) {
272 if (PTR_ERR(vdds_sdi) != -EPROBE_DEFER)
273 DSSERR("can't get VDDS_SDI regulator\n");
274 return PTR_ERR(vdds_sdi);
275 } 246 }
276 247
277 sdi->vdds_sdi_reg = vdds_sdi;
278
279 return 0; 248 return 0;
280} 249}
281 250
282static int sdi_connect(struct omap_dss_device *dssdev, 251static int sdi_connect(struct omap_dss_device *src,
283 struct omap_dss_device *dst) 252 struct omap_dss_device *dst)
284{ 253{
285 struct sdi_device *sdi = dssdev_to_sdi(dssdev);
286 int r; 254 int r;
287 255
288 r = sdi_init_regulator(sdi); 256 r = omapdss_device_connect(dst->dss, dst, dst->next);
289 if (r) 257 if (r)
290 return r; 258 return r;
291 259
292 r = dss_mgr_connect(&sdi->output, dssdev); 260 dst->dispc_channel_connected = true;
293 if (r)
294 return r;
295
296 r = omapdss_output_set_device(dssdev, dst);
297 if (r) {
298 DSSERR("failed to connect output to new device: %s\n",
299 dst->name);
300 dss_mgr_disconnect(&sdi->output, dssdev);
301 return r;
302 }
303
304 return 0; 261 return 0;
305} 262}
306 263
307static void sdi_disconnect(struct omap_dss_device *dssdev, 264static void sdi_disconnect(struct omap_dss_device *src,
308 struct omap_dss_device *dst) 265 struct omap_dss_device *dst)
309{ 266{
310 struct sdi_device *sdi = dssdev_to_sdi(dssdev); 267 dst->dispc_channel_connected = false;
311 268
312 WARN_ON(dst != dssdev->dst); 269 omapdss_device_disconnect(dst, dst->next);
313
314 if (dst != dssdev->dst)
315 return;
316
317 omapdss_output_unset_device(dssdev);
318
319 dss_mgr_disconnect(&sdi->output, dssdev);
320} 270}
321 271
322static const struct omapdss_sdi_ops sdi_ops = { 272static const struct omap_dss_device_ops sdi_ops = {
323 .connect = sdi_connect, 273 .connect = sdi_connect,
324 .disconnect = sdi_disconnect, 274 .disconnect = sdi_disconnect,
325 275
@@ -328,12 +278,12 @@ static const struct omapdss_sdi_ops sdi_ops = {
328 278
329 .check_timings = sdi_check_timings, 279 .check_timings = sdi_check_timings,
330 .set_timings = sdi_set_timings, 280 .set_timings = sdi_set_timings,
331 .get_timings = sdi_get_timings,
332}; 281};
333 282
334static void sdi_init_output(struct sdi_device *sdi) 283static int sdi_init_output(struct sdi_device *sdi)
335{ 284{
336 struct omap_dss_device *out = &sdi->output; 285 struct omap_dss_device *out = &sdi->output;
286 int r;
337 287
338 out->dev = &sdi->pdev->dev; 288 out->dev = &sdi->pdev->dev;
339 out->id = OMAP_DSS_OUTPUT_SDI; 289 out->id = OMAP_DSS_OUTPUT_SDI;
@@ -341,16 +291,36 @@ static void sdi_init_output(struct sdi_device *sdi)
341 out->name = "sdi.0"; 291 out->name = "sdi.0";
342 out->dispc_channel = OMAP_DSS_CHANNEL_LCD; 292 out->dispc_channel = OMAP_DSS_CHANNEL_LCD;
343 /* We have SDI only on OMAP3, where it's on port 1 */ 293 /* We have SDI only on OMAP3, where it's on port 1 */
344 out->port_num = 1; 294 out->of_ports = BIT(1);
345 out->ops.sdi = &sdi_ops; 295 out->ops = &sdi_ops;
346 out->owner = THIS_MODULE; 296 out->owner = THIS_MODULE;
297 out->bus_flags = DRM_BUS_FLAG_PIXDATA_POSEDGE /* 15.5.9.1.2 */
298 | DRM_BUS_FLAG_SYNC_POSEDGE;
299
300 out->next = omapdss_of_find_connected_device(out->dev->of_node, 1);
301 if (IS_ERR(out->next)) {
302 if (PTR_ERR(out->next) != -EPROBE_DEFER)
303 dev_err(out->dev, "failed to find video sink\n");
304 return PTR_ERR(out->next);
305 }
347 306
348 omapdss_register_output(out); 307 r = omapdss_output_validate(out);
308 if (r) {
309 omapdss_device_put(out->next);
310 out->next = NULL;
311 return r;
312 }
313
314 omapdss_device_register(out);
315
316 return 0;
349} 317}
350 318
351static void sdi_uninit_output(struct sdi_device *sdi) 319static void sdi_uninit_output(struct sdi_device *sdi)
352{ 320{
353 omapdss_unregister_output(&sdi->output); 321 if (sdi->output.next)
322 omapdss_device_put(sdi->output.next);
323 omapdss_device_unregister(&sdi->output);
354} 324}
355 325
356int sdi_init_port(struct dss_device *dss, struct platform_device *pdev, 326int sdi_init_port(struct dss_device *dss, struct platform_device *pdev,
@@ -372,25 +342,32 @@ int sdi_init_port(struct dss_device *dss, struct platform_device *pdev,
372 } 342 }
373 343
374 r = of_property_read_u32(ep, "datapairs", &datapairs); 344 r = of_property_read_u32(ep, "datapairs", &datapairs);
345 of_node_put(ep);
375 if (r) { 346 if (r) {
376 DSSERR("failed to parse datapairs\n"); 347 DSSERR("failed to parse datapairs\n");
377 goto err_datapairs; 348 goto err_free;
378 } 349 }
379 350
380 sdi->datapairs = datapairs; 351 sdi->datapairs = datapairs;
381 sdi->dss = dss; 352 sdi->dss = dss;
382 353
383 of_node_put(ep);
384
385 sdi->pdev = pdev; 354 sdi->pdev = pdev;
386 port->data = sdi; 355 port->data = sdi;
387 356
388 sdi_init_output(sdi); 357 sdi->vdds_sdi_reg = devm_regulator_get(&pdev->dev, "vdds_sdi");
358 if (IS_ERR(sdi->vdds_sdi_reg)) {
359 r = PTR_ERR(sdi->vdds_sdi_reg);
360 if (r != -EPROBE_DEFER)
361 DSSERR("can't get VDDS_SDI regulator\n");
362 goto err_free;
363 }
364
365 r = sdi_init_output(sdi);
366 if (r)
367 goto err_free;
389 368
390 return 0; 369 return 0;
391 370
392err_datapairs:
393 of_node_put(ep);
394err_free: 371err_free:
395 kfree(sdi); 372 kfree(sdi);
396 373
diff --git a/drivers/gpu/drm/omapdrm/dss/venc.c b/drivers/gpu/drm/omapdrm/dss/venc.c
index ac01907dcc34..ff0b18c8e4ac 100644
--- a/drivers/gpu/drm/omapdrm/dss/venc.c
+++ b/drivers/gpu/drm/omapdrm/dss/venc.c
@@ -452,7 +452,7 @@ static void venc_runtime_put(struct venc_device *venc)
452 WARN_ON(r < 0 && r != -ENOSYS); 452 WARN_ON(r < 0 && r != -ENOSYS);
453} 453}
454 454
455static const struct venc_config *venc_timings_to_config(struct videomode *vm) 455static const struct venc_config *venc_timings_to_config(const struct videomode *vm)
456{ 456{
457 switch (venc_get_videomode(vm)) { 457 switch (venc_get_videomode(vm)) {
458 default: 458 default:
@@ -491,8 +491,6 @@ static int venc_power_on(struct venc_device *venc)
491 491
492 venc_write_reg(venc, VENC_OUTPUT_CONTROL, l); 492 venc_write_reg(venc, VENC_OUTPUT_CONTROL, l);
493 493
494 dss_mgr_set_timings(&venc->output, &venc->vm);
495
496 r = regulator_enable(venc->vdda_dac_reg); 494 r = regulator_enable(venc->vdda_dac_reg);
497 if (r) 495 if (r)
498 goto err1; 496 goto err1;
@@ -568,32 +566,30 @@ static void venc_display_disable(struct omap_dss_device *dssdev)
568 mutex_unlock(&venc->venc_lock); 566 mutex_unlock(&venc->venc_lock);
569} 567}
570 568
571static void venc_set_timings(struct omap_dss_device *dssdev, 569static void venc_get_timings(struct omap_dss_device *dssdev,
572 struct videomode *vm) 570 struct videomode *vm)
573{ 571{
574 struct venc_device *venc = dssdev_to_venc(dssdev); 572 struct venc_device *venc = dssdev_to_venc(dssdev);
575 struct videomode actual_vm; 573
574 mutex_lock(&venc->venc_lock);
575 *vm = venc->vm;
576 mutex_unlock(&venc->venc_lock);
577}
578
579static void venc_set_timings(struct omap_dss_device *dssdev,
580 const struct videomode *vm)
581{
582 struct venc_device *venc = dssdev_to_venc(dssdev);
576 583
577 DSSDBG("venc_set_timings\n"); 584 DSSDBG("venc_set_timings\n");
578 585
579 mutex_lock(&venc->venc_lock); 586 mutex_lock(&venc->venc_lock);
580 587
581 switch (venc_get_videomode(vm)) {
582 default:
583 WARN_ON_ONCE(1);
584 case VENC_MODE_PAL:
585 actual_vm = omap_dss_pal_vm;
586 break;
587 case VENC_MODE_NTSC:
588 actual_vm = omap_dss_ntsc_vm;
589 break;
590 }
591
592 /* Reset WSS data when the TV standard changes. */ 588 /* Reset WSS data when the TV standard changes. */
593 if (memcmp(&venc->vm, &actual_vm, sizeof(actual_vm))) 589 if (memcmp(&venc->vm, vm, sizeof(*vm)))
594 venc->wss_data = 0; 590 venc->wss_data = 0;
595 591
596 venc->vm = actual_vm; 592 venc->vm = *vm;
597 593
598 dispc_set_tv_pclk(venc->dss->dispc, 13500000); 594 dispc_set_tv_pclk(venc->dss->dispc, 13500000);
599 595
@@ -607,80 +603,16 @@ static int venc_check_timings(struct omap_dss_device *dssdev,
607 603
608 switch (venc_get_videomode(vm)) { 604 switch (venc_get_videomode(vm)) {
609 case VENC_MODE_PAL: 605 case VENC_MODE_PAL:
610 case VENC_MODE_NTSC: 606 *vm = omap_dss_pal_vm;
611 return 0; 607 return 0;
612 default:
613 return -EINVAL;
614 }
615}
616
617static void venc_get_timings(struct omap_dss_device *dssdev,
618 struct videomode *vm)
619{
620 struct venc_device *venc = dssdev_to_venc(dssdev);
621
622 mutex_lock(&venc->venc_lock);
623
624 *vm = venc->vm;
625
626 mutex_unlock(&venc->venc_lock);
627}
628
629static u32 venc_get_wss(struct omap_dss_device *dssdev)
630{
631 struct venc_device *venc = dssdev_to_venc(dssdev);
632
633 /* Invert due to VENC_L21_WC_CTL:INV=1 */
634 return (venc->wss_data >> 8) ^ 0xfffff;
635}
636
637static int venc_set_wss(struct omap_dss_device *dssdev, u32 wss)
638{
639 struct venc_device *venc = dssdev_to_venc(dssdev);
640 const struct venc_config *config;
641 int r;
642 608
643 DSSDBG("venc_set_wss\n"); 609 case VENC_MODE_NTSC:
644 610 *vm = omap_dss_ntsc_vm;
645 mutex_lock(&venc->venc_lock);
646
647 config = venc_timings_to_config(&venc->vm);
648
649 /* Invert due to VENC_L21_WC_CTL:INV=1 */
650 venc->wss_data = (wss ^ 0xfffff) << 8;
651
652 r = venc_runtime_get(venc);
653 if (r)
654 goto err;
655
656 venc_write_reg(venc, VENC_BSTAMP_WSS_DATA, config->bstamp_wss_data |
657 venc->wss_data);
658
659 venc_runtime_put(venc);
660
661err:
662 mutex_unlock(&venc->venc_lock);
663
664 return r;
665}
666
667static int venc_init_regulator(struct venc_device *venc)
668{
669 struct regulator *vdda_dac;
670
671 if (venc->vdda_dac_reg != NULL)
672 return 0; 611 return 0;
673 612
674 vdda_dac = devm_regulator_get(&venc->pdev->dev, "vdda"); 613 default:
675 if (IS_ERR(vdda_dac)) { 614 return -EINVAL;
676 if (PTR_ERR(vdda_dac) != -EPROBE_DEFER)
677 DSSERR("can't get VDDA_DAC regulator\n");
678 return PTR_ERR(vdda_dac);
679 } 615 }
680
681 venc->vdda_dac_reg = vdda_dac;
682
683 return 0;
684} 616}
685 617
686static int venc_dump_regs(struct seq_file *s, void *p) 618static int venc_dump_regs(struct seq_file *s, void *p)
@@ -760,47 +692,28 @@ static int venc_get_clocks(struct venc_device *venc)
760 return 0; 692 return 0;
761} 693}
762 694
763static int venc_connect(struct omap_dss_device *dssdev, 695static int venc_connect(struct omap_dss_device *src,
764 struct omap_dss_device *dst) 696 struct omap_dss_device *dst)
765{ 697{
766 struct venc_device *venc = dssdev_to_venc(dssdev);
767 int r; 698 int r;
768 699
769 r = venc_init_regulator(venc); 700 r = omapdss_device_connect(dst->dss, dst, dst->next);
770 if (r)
771 return r;
772
773 r = dss_mgr_connect(&venc->output, dssdev);
774 if (r) 701 if (r)
775 return r; 702 return r;
776 703
777 r = omapdss_output_set_device(dssdev, dst); 704 dst->dispc_channel_connected = true;
778 if (r) {
779 DSSERR("failed to connect output to new device: %s\n",
780 dst->name);
781 dss_mgr_disconnect(&venc->output, dssdev);
782 return r;
783 }
784
785 return 0; 705 return 0;
786} 706}
787 707
788static void venc_disconnect(struct omap_dss_device *dssdev, 708static void venc_disconnect(struct omap_dss_device *src,
789 struct omap_dss_device *dst) 709 struct omap_dss_device *dst)
790{ 710{
791 struct venc_device *venc = dssdev_to_venc(dssdev); 711 dst->dispc_channel_connected = false;
792
793 WARN_ON(dst != dssdev->dst);
794
795 if (dst != dssdev->dst)
796 return;
797
798 omapdss_output_unset_device(dssdev);
799 712
800 dss_mgr_disconnect(&venc->output, dssdev); 713 omapdss_device_disconnect(dst, dst->next);
801} 714}
802 715
803static const struct omapdss_atv_ops venc_ops = { 716static const struct omap_dss_device_ops venc_ops = {
804 .connect = venc_connect, 717 .connect = venc_connect,
805 .disconnect = venc_disconnect, 718 .disconnect = venc_disconnect,
806 719
@@ -808,31 +721,92 @@ static const struct omapdss_atv_ops venc_ops = {
808 .disable = venc_display_disable, 721 .disable = venc_display_disable,
809 722
810 .check_timings = venc_check_timings, 723 .check_timings = venc_check_timings,
811 .set_timings = venc_set_timings,
812 .get_timings = venc_get_timings, 724 .get_timings = venc_get_timings,
725 .set_timings = venc_set_timings,
726};
727
728/* -----------------------------------------------------------------------------
729 * Component Bind & Unbind
730 */
813 731
814 .set_wss = venc_set_wss, 732static int venc_bind(struct device *dev, struct device *master, void *data)
815 .get_wss = venc_get_wss, 733{
734 struct dss_device *dss = dss_get_device(master);
735 struct venc_device *venc = dev_get_drvdata(dev);
736 u8 rev_id;
737 int r;
738
739 venc->dss = dss;
740
741 r = venc_runtime_get(venc);
742 if (r)
743 return r;
744
745 rev_id = (u8)(venc_read_reg(venc, VENC_REV_ID) & 0xff);
746 dev_dbg(dev, "OMAP VENC rev %d\n", rev_id);
747
748 venc_runtime_put(venc);
749
750 venc->debugfs = dss_debugfs_create_file(dss, "venc", venc_dump_regs,
751 venc);
752
753 return 0;
754}
755
756static void venc_unbind(struct device *dev, struct device *master, void *data)
757{
758 struct venc_device *venc = dev_get_drvdata(dev);
759
760 dss_debugfs_remove_file(venc->debugfs);
761}
762
763static const struct component_ops venc_component_ops = {
764 .bind = venc_bind,
765 .unbind = venc_unbind,
816}; 766};
817 767
818static void venc_init_output(struct venc_device *venc) 768/* -----------------------------------------------------------------------------
769 * Probe & Remove, Suspend & Resume
770 */
771
772static int venc_init_output(struct venc_device *venc)
819{ 773{
820 struct omap_dss_device *out = &venc->output; 774 struct omap_dss_device *out = &venc->output;
775 int r;
821 776
822 out->dev = &venc->pdev->dev; 777 out->dev = &venc->pdev->dev;
823 out->id = OMAP_DSS_OUTPUT_VENC; 778 out->id = OMAP_DSS_OUTPUT_VENC;
824 out->output_type = OMAP_DISPLAY_TYPE_VENC; 779 out->output_type = OMAP_DISPLAY_TYPE_VENC;
825 out->name = "venc.0"; 780 out->name = "venc.0";
826 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT; 781 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
827 out->ops.atv = &venc_ops; 782 out->ops = &venc_ops;
828 out->owner = THIS_MODULE; 783 out->owner = THIS_MODULE;
784 out->of_ports = BIT(0);
785
786 out->next = omapdss_of_find_connected_device(out->dev->of_node, 0);
787 if (IS_ERR(out->next)) {
788 if (PTR_ERR(out->next) != -EPROBE_DEFER)
789 dev_err(out->dev, "failed to find video sink\n");
790 return PTR_ERR(out->next);
791 }
829 792
830 omapdss_register_output(out); 793 r = omapdss_output_validate(out);
794 if (r) {
795 omapdss_device_put(out->next);
796 out->next = NULL;
797 return r;
798 }
799
800 omapdss_device_register(out);
801
802 return 0;
831} 803}
832 804
833static void venc_uninit_output(struct venc_device *venc) 805static void venc_uninit_output(struct venc_device *venc)
834{ 806{
835 omapdss_unregister_output(&venc->output); 807 if (venc->output.next)
808 omapdss_device_put(venc->output.next);
809 omapdss_device_unregister(&venc->output);
836} 810}
837 811
838static int venc_probe_of(struct venc_device *venc) 812static int venc_probe_of(struct venc_device *venc)
@@ -878,19 +852,15 @@ err:
878 return r; 852 return r;
879} 853}
880 854
881/* VENC HW IP initialisation */
882static const struct soc_device_attribute venc_soc_devices[] = { 855static const struct soc_device_attribute venc_soc_devices[] = {
883 { .machine = "OMAP3[45]*" }, 856 { .machine = "OMAP3[45]*" },
884 { .machine = "AM35*" }, 857 { .machine = "AM35*" },
885 { /* sentinel */ } 858 { /* sentinel */ }
886}; 859};
887 860
888static int venc_bind(struct device *dev, struct device *master, void *data) 861static int venc_probe(struct platform_device *pdev)
889{ 862{
890 struct platform_device *pdev = to_platform_device(dev);
891 struct dss_device *dss = dss_get_device(master);
892 struct venc_device *venc; 863 struct venc_device *venc;
893 u8 rev_id;
894 struct resource *venc_mem; 864 struct resource *venc_mem;
895 int r; 865 int r;
896 866
@@ -899,8 +869,8 @@ static int venc_bind(struct device *dev, struct device *master, void *data)
899 return -ENOMEM; 869 return -ENOMEM;
900 870
901 venc->pdev = pdev; 871 venc->pdev = pdev;
902 venc->dss = dss; 872
903 dev_set_drvdata(dev, venc); 873 platform_set_drvdata(pdev, venc);
904 874
905 /* The OMAP34xx, OMAP35xx and AM35xx VENC require the TV DAC clock. */ 875 /* The OMAP34xx, OMAP35xx and AM35xx VENC require the TV DAC clock. */
906 if (soc_device_match(venc_soc_devices)) 876 if (soc_device_match(venc_soc_devices))
@@ -909,6 +879,7 @@ static int venc_bind(struct device *dev, struct device *master, void *data)
909 mutex_init(&venc->venc_lock); 879 mutex_init(&venc->venc_lock);
910 880
911 venc->wss_data = 0; 881 venc->wss_data = 0;
882 venc->vm = omap_dss_pal_vm;
912 883
913 venc_mem = platform_get_resource(venc->pdev, IORESOURCE_MEM, 0); 884 venc_mem = platform_get_resource(venc->pdev, IORESOURCE_MEM, 0);
914 venc->base = devm_ioremap_resource(&pdev->dev, venc_mem); 885 venc->base = devm_ioremap_resource(&pdev->dev, venc_mem);
@@ -917,68 +888,54 @@ static int venc_bind(struct device *dev, struct device *master, void *data)
917 goto err_free; 888 goto err_free;
918 } 889 }
919 890
891 venc->vdda_dac_reg = devm_regulator_get(&pdev->dev, "vdda");
892 if (IS_ERR(venc->vdda_dac_reg)) {
893 r = PTR_ERR(venc->vdda_dac_reg);
894 if (r != -EPROBE_DEFER)
895 DSSERR("can't get VDDA_DAC regulator\n");
896 goto err_free;
897 }
898
920 r = venc_get_clocks(venc); 899 r = venc_get_clocks(venc);
921 if (r) 900 if (r)
922 goto err_free; 901 goto err_free;
923 902
924 pm_runtime_enable(&pdev->dev); 903 r = venc_probe_of(venc);
925
926 r = venc_runtime_get(venc);
927 if (r) 904 if (r)
928 goto err_runtime_get; 905 goto err_free;
929
930 rev_id = (u8)(venc_read_reg(venc, VENC_REV_ID) & 0xff);
931 dev_dbg(&pdev->dev, "OMAP VENC rev %d\n", rev_id);
932
933 venc_runtime_put(venc);
934 906
935 r = venc_probe_of(venc); 907 pm_runtime_enable(&pdev->dev);
936 if (r) {
937 DSSERR("Invalid DT data\n");
938 goto err_probe_of;
939 }
940 908
941 venc->debugfs = dss_debugfs_create_file(dss, "venc", venc_dump_regs, 909 r = venc_init_output(venc);
942 venc); 910 if (r)
911 goto err_pm_disable;
943 912
944 venc_init_output(venc); 913 r = component_add(&pdev->dev, &venc_component_ops);
914 if (r)
915 goto err_uninit_output;
945 916
946 return 0; 917 return 0;
947 918
948err_probe_of: 919err_uninit_output:
949err_runtime_get: 920 venc_uninit_output(venc);
921err_pm_disable:
950 pm_runtime_disable(&pdev->dev); 922 pm_runtime_disable(&pdev->dev);
951err_free: 923err_free:
952 kfree(venc); 924 kfree(venc);
953 return r; 925 return r;
954} 926}
955 927
956static void venc_unbind(struct device *dev, struct device *master, void *data) 928static int venc_remove(struct platform_device *pdev)
957{ 929{
958 struct venc_device *venc = dev_get_drvdata(dev); 930 struct venc_device *venc = platform_get_drvdata(pdev);
959 931
960 dss_debugfs_remove_file(venc->debugfs); 932 component_del(&pdev->dev, &venc_component_ops);
961 933
962 venc_uninit_output(venc); 934 venc_uninit_output(venc);
963 935
964 pm_runtime_disable(dev); 936 pm_runtime_disable(&pdev->dev);
965 937
966 kfree(venc); 938 kfree(venc);
967}
968
969static const struct component_ops venc_component_ops = {
970 .bind = venc_bind,
971 .unbind = venc_unbind,
972};
973
974static int venc_probe(struct platform_device *pdev)
975{
976 return component_add(&pdev->dev, &venc_component_ops);
977}
978
979static int venc_remove(struct platform_device *pdev)
980{
981 component_del(&pdev->dev, &venc_component_ops);
982 return 0; 939 return 0;
983} 940}
984 941
diff --git a/drivers/gpu/drm/omapdrm/omap_connector.c b/drivers/gpu/drm/omapdrm/omap_connector.c
index 2ddb856666c4..98f5ca29444a 100644
--- a/drivers/gpu/drm/omapdrm/omap_connector.c
+++ b/drivers/gpu/drm/omapdrm/omap_connector.c
@@ -29,10 +29,28 @@
29 29
30struct omap_connector { 30struct omap_connector {
31 struct drm_connector base; 31 struct drm_connector base;
32 struct omap_dss_device *dssdev; 32 struct omap_dss_device *output;
33 struct omap_dss_device *display;
34 struct omap_dss_device *hpd;
33 bool hdmi_mode; 35 bool hdmi_mode;
34}; 36};
35 37
38static void omap_connector_hpd_notify(struct drm_connector *connector,
39 struct omap_dss_device *src,
40 enum drm_connector_status status)
41{
42 if (status == connector_status_disconnected) {
43 /*
44 * If the source is an HDMI encoder, notify it of disconnection.
45 * This is required to let the HDMI encoder reset any internal
46 * state related to connection status, such as the CEC address.
47 */
48 if (src && src->type == OMAP_DISPLAY_TYPE_HDMI &&
49 src->ops->hdmi.lost_hotplug)
50 src->ops->hdmi.lost_hotplug(src);
51 }
52}
53
36static void omap_connector_hpd_cb(void *cb_data, 54static void omap_connector_hpd_cb(void *cb_data,
37 enum drm_connector_status status) 55 enum drm_connector_status status)
38{ 56{
@@ -46,8 +64,31 @@ static void omap_connector_hpd_cb(void *cb_data,
46 connector->status = status; 64 connector->status = status;
47 mutex_unlock(&dev->mode_config.mutex); 65 mutex_unlock(&dev->mode_config.mutex);
48 66
49 if (old_status != status) 67 if (old_status == status)
50 drm_kms_helper_hotplug_event(dev); 68 return;
69
70 omap_connector_hpd_notify(connector, omap_connector->hpd, status);
71
72 drm_kms_helper_hotplug_event(dev);
73}
74
75void omap_connector_enable_hpd(struct drm_connector *connector)
76{
77 struct omap_connector *omap_connector = to_omap_connector(connector);
78 struct omap_dss_device *hpd = omap_connector->hpd;
79
80 if (hpd)
81 hpd->ops->register_hpd_cb(hpd, omap_connector_hpd_cb,
82 omap_connector);
83}
84
85void omap_connector_disable_hpd(struct drm_connector *connector)
86{
87 struct omap_connector *omap_connector = to_omap_connector(connector);
88 struct omap_dss_device *hpd = omap_connector->hpd;
89
90 if (hpd)
91 hpd->ops->unregister_hpd_cb(hpd);
51} 92}
52 93
53bool omap_connector_get_hdmi_mode(struct drm_connector *connector) 94bool omap_connector_get_hdmi_mode(struct drm_connector *connector)
@@ -57,120 +98,179 @@ bool omap_connector_get_hdmi_mode(struct drm_connector *connector)
57 return omap_connector->hdmi_mode; 98 return omap_connector->hdmi_mode;
58} 99}
59 100
101static struct omap_dss_device *
102omap_connector_find_device(struct drm_connector *connector,
103 enum omap_dss_device_ops_flag op)
104{
105 struct omap_connector *omap_connector = to_omap_connector(connector);
106 struct omap_dss_device *dssdev;
107
108 for (dssdev = omap_connector->display; dssdev; dssdev = dssdev->src) {
109 if (dssdev->ops_flags & op)
110 return dssdev;
111 }
112
113 return NULL;
114}
115
60static enum drm_connector_status omap_connector_detect( 116static enum drm_connector_status omap_connector_detect(
61 struct drm_connector *connector, bool force) 117 struct drm_connector *connector, bool force)
62{ 118{
63 struct omap_connector *omap_connector = to_omap_connector(connector); 119 struct omap_connector *omap_connector = to_omap_connector(connector);
64 struct omap_dss_device *dssdev = omap_connector->dssdev; 120 struct omap_dss_device *dssdev;
65 struct omap_dss_driver *dssdrv = dssdev->driver; 121 enum drm_connector_status status;
66 enum drm_connector_status ret; 122
67 123 dssdev = omap_connector_find_device(connector,
68 if (dssdrv->detect) { 124 OMAP_DSS_DEVICE_OP_DETECT);
69 if (dssdrv->detect(dssdev)) 125
70 ret = connector_status_connected; 126 if (dssdev) {
71 else 127 status = dssdev->ops->detect(dssdev)
72 ret = connector_status_disconnected; 128 ? connector_status_connected
73 } else if (dssdev->type == OMAP_DISPLAY_TYPE_DPI || 129 : connector_status_disconnected;
74 dssdev->type == OMAP_DISPLAY_TYPE_DBI || 130
75 dssdev->type == OMAP_DISPLAY_TYPE_SDI || 131 omap_connector_hpd_notify(connector, dssdev->src, status);
76 dssdev->type == OMAP_DISPLAY_TYPE_DSI) {
77 ret = connector_status_connected;
78 } else { 132 } else {
79 ret = connector_status_unknown; 133 switch (omap_connector->display->type) {
134 case OMAP_DISPLAY_TYPE_DPI:
135 case OMAP_DISPLAY_TYPE_DBI:
136 case OMAP_DISPLAY_TYPE_SDI:
137 case OMAP_DISPLAY_TYPE_DSI:
138 status = connector_status_connected;
139 break;
140 default:
141 status = connector_status_unknown;
142 break;
143 }
80 } 144 }
81 145
82 VERB("%s: %d (force=%d)", omap_connector->dssdev->name, ret, force); 146 VERB("%s: %d (force=%d)", omap_connector->display->name, status, force);
83 147
84 return ret; 148 return status;
85} 149}
86 150
87static void omap_connector_destroy(struct drm_connector *connector) 151static void omap_connector_destroy(struct drm_connector *connector)
88{ 152{
89 struct omap_connector *omap_connector = to_omap_connector(connector); 153 struct omap_connector *omap_connector = to_omap_connector(connector);
90 struct omap_dss_device *dssdev = omap_connector->dssdev;
91 154
92 DBG("%s", omap_connector->dssdev->name); 155 DBG("%s", omap_connector->display->name);
93 if (connector->polled == DRM_CONNECTOR_POLL_HPD && 156
94 dssdev->driver->unregister_hpd_cb) { 157 if (omap_connector->hpd) {
95 dssdev->driver->unregister_hpd_cb(dssdev); 158 struct omap_dss_device *hpd = omap_connector->hpd;
159
160 hpd->ops->unregister_hpd_cb(hpd);
161 omapdss_device_put(hpd);
162 omap_connector->hpd = NULL;
96 } 163 }
164
97 drm_connector_unregister(connector); 165 drm_connector_unregister(connector);
98 drm_connector_cleanup(connector); 166 drm_connector_cleanup(connector);
99 kfree(omap_connector); 167 kfree(omap_connector);
100 168
101 omap_dss_put_device(dssdev); 169 omapdss_device_put(omap_connector->output);
170 omapdss_device_put(omap_connector->display);
102} 171}
103 172
104#define MAX_EDID 512 173#define MAX_EDID 512
105 174
106static int omap_connector_get_modes(struct drm_connector *connector) 175static int omap_connector_get_modes_edid(struct drm_connector *connector,
176 struct omap_dss_device *dssdev)
107{ 177{
108 struct omap_connector *omap_connector = to_omap_connector(connector); 178 struct omap_connector *omap_connector = to_omap_connector(connector);
109 struct omap_dss_device *dssdev = omap_connector->dssdev; 179 enum drm_connector_status status;
110 struct omap_dss_driver *dssdrv = dssdev->driver; 180 void *edid;
111 struct drm_device *dev = connector->dev; 181 int n;
112 int n = 0;
113 182
114 DBG("%s", omap_connector->dssdev->name); 183 status = omap_connector_detect(connector, false);
184 if (status != connector_status_connected)
185 goto no_edid;
115 186
116 /* if display exposes EDID, then we parse that in the normal way to 187 edid = kzalloc(MAX_EDID, GFP_KERNEL);
117 * build table of supported modes.. otherwise (ie. fixed resolution 188 if (!edid)
118 * LCD panels) we just return a single mode corresponding to the 189 goto no_edid;
119 * currently configured timings:
120 */
121 if (dssdrv->read_edid) {
122 void *edid = kzalloc(MAX_EDID, GFP_KERNEL);
123
124 if (!edid)
125 return 0;
126
127 if ((dssdrv->read_edid(dssdev, edid, MAX_EDID) > 0) &&
128 drm_edid_is_valid(edid)) {
129 drm_connector_update_edid_property(
130 connector, edid);
131 n = drm_add_edid_modes(connector, edid);
132
133 omap_connector->hdmi_mode =
134 drm_detect_hdmi_monitor(edid);
135 } else {
136 drm_connector_update_edid_property(
137 connector, NULL);
138 }
139 190
191 if (dssdev->ops->read_edid(dssdev, edid, MAX_EDID) <= 0 ||
192 !drm_edid_is_valid(edid)) {
140 kfree(edid); 193 kfree(edid);
141 } else { 194 goto no_edid;
142 struct drm_display_mode *mode = drm_mode_create(dev); 195 }
143 struct videomode vm = {0};
144 196
145 if (!mode) 197 drm_connector_update_edid_property(connector, edid);
146 return 0; 198 n = drm_add_edid_modes(connector, edid);
147 199
148 dssdrv->get_timings(dssdev, &vm); 200 omap_connector->hdmi_mode = drm_detect_hdmi_monitor(edid);
149 201
150 drm_display_mode_from_videomode(&vm, mode); 202 kfree(edid);
203 return n;
151 204
152 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; 205no_edid:
153 drm_mode_set_name(mode); 206 drm_connector_update_edid_property(connector, NULL);
154 drm_mode_probed_add(connector, mode); 207 return 0;
208}
155 209
156 if (dssdrv->get_size) { 210static int omap_connector_get_modes(struct drm_connector *connector)
157 dssdrv->get_size(dssdev, 211{
212 struct omap_connector *omap_connector = to_omap_connector(connector);
213 struct omap_dss_device *dssdev;
214 struct drm_display_mode *mode;
215 struct videomode vm = {0};
216
217 DBG("%s", omap_connector->display->name);
218
219 /*
220 * If display exposes EDID, then we parse that in the normal way to
221 * build table of supported modes.
222 */
223 dssdev = omap_connector_find_device(connector,
224 OMAP_DSS_DEVICE_OP_EDID);
225 if (dssdev)
226 return omap_connector_get_modes_edid(connector, dssdev);
227
228 /*
229 * Otherwise we have either a fixed resolution panel or an output that
230 * doesn't support modes discovery (e.g. DVI or VGA with the DDC bus
231 * unconnected, or analog TV). Start by querying the size.
232 */
233 dssdev = omap_connector->display;
234 if (dssdev->driver && dssdev->driver->get_size)
235 dssdev->driver->get_size(dssdev,
158 &connector->display_info.width_mm, 236 &connector->display_info.width_mm,
159 &connector->display_info.height_mm); 237 &connector->display_info.height_mm);
160 }
161 238
162 n = 1; 239 /*
240 * Iterate over the pipeline to find the first device that can provide
241 * timing information. If we can't find any, we just let the KMS core
242 * add the default modes.
243 */
244 for (dssdev = omap_connector->display; dssdev; dssdev = dssdev->src) {
245 if (dssdev->ops->get_timings)
246 break;
163 } 247 }
248 if (!dssdev)
249 return 0;
164 250
165 return n; 251 /* Add a single mode corresponding to the fixed panel timings. */
252 mode = drm_mode_create(connector->dev);
253 if (!mode)
254 return 0;
255
256 dssdev->ops->get_timings(dssdev, &vm);
257
258 drm_display_mode_from_videomode(&vm, mode);
259
260 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
261 drm_mode_set_name(mode);
262 drm_mode_probed_add(connector, mode);
263
264 return 1;
166} 265}
167 266
168static int omap_connector_mode_valid(struct drm_connector *connector, 267static int omap_connector_mode_valid(struct drm_connector *connector,
169 struct drm_display_mode *mode) 268 struct drm_display_mode *mode)
170{ 269{
171 struct omap_connector *omap_connector = to_omap_connector(connector); 270 struct omap_connector *omap_connector = to_omap_connector(connector);
172 struct omap_dss_device *dssdev = omap_connector->dssdev; 271 enum omap_channel channel = omap_connector->output->dispc_channel;
173 struct omap_dss_driver *dssdrv = dssdev->driver; 272 struct omap_drm_private *priv = connector->dev->dev_private;
273 struct omap_dss_device *dssdev;
174 struct videomode vm = {0}; 274 struct videomode vm = {0};
175 struct drm_device *dev = connector->dev; 275 struct drm_device *dev = connector->dev;
176 struct drm_display_mode *new_mode; 276 struct drm_display_mode *new_mode;
@@ -179,44 +279,31 @@ static int omap_connector_mode_valid(struct drm_connector *connector,
179 drm_display_mode_to_videomode(mode, &vm); 279 drm_display_mode_to_videomode(mode, &vm);
180 mode->vrefresh = drm_mode_vrefresh(mode); 280 mode->vrefresh = drm_mode_vrefresh(mode);
181 281
182 /* 282 r = priv->dispc_ops->mgr_check_timings(priv->dispc, channel, &vm);
183 * if the panel driver doesn't have a check_timings, it's most likely 283 if (r)
184 * a fixed resolution panel, check if the timings match with the 284 goto done;
185 * panel's timings
186 */
187 if (dssdrv->check_timings) {
188 r = dssdrv->check_timings(dssdev, &vm);
189 } else {
190 struct videomode t = {0};
191 285
192 dssdrv->get_timings(dssdev, &t); 286 for (dssdev = omap_connector->output; dssdev; dssdev = dssdev->next) {
287 if (!dssdev->ops->check_timings)
288 continue;
193 289
194 /* 290 r = dssdev->ops->check_timings(dssdev, &vm);
195 * Ignore the flags, as we don't get them from 291 if (r)
196 * drm_display_mode_to_videomode. 292 goto done;
197 */
198 t.flags = 0;
199
200 if (memcmp(&vm, &t, sizeof(vm)))
201 r = -EINVAL;
202 else
203 r = 0;
204 } 293 }
205 294
206 if (!r) { 295 /* check if vrefresh is still valid */
207 /* check if vrefresh is still valid */ 296 new_mode = drm_mode_duplicate(dev, mode);
208 new_mode = drm_mode_duplicate(dev, mode); 297 if (!new_mode)
298 return MODE_BAD;
209 299
210 if (!new_mode) 300 new_mode->clock = vm.pixelclock / 1000;
211 return MODE_BAD; 301 new_mode->vrefresh = 0;
212 302 if (mode->vrefresh == drm_mode_vrefresh(new_mode))
213 new_mode->clock = vm.pixelclock / 1000; 303 ret = MODE_OK;
214 new_mode->vrefresh = 0; 304 drm_mode_destroy(dev, new_mode);
215 if (mode->vrefresh == drm_mode_vrefresh(new_mode))
216 ret = MODE_OK;
217 drm_mode_destroy(dev, new_mode);
218 }
219 305
306done:
220 DBG("connector: mode %s: " 307 DBG("connector: mode %s: "
221 "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x", 308 "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
222 (ret == MODE_OK) ? "valid" : "invalid", 309 (ret == MODE_OK) ? "valid" : "invalid",
@@ -243,52 +330,72 @@ static const struct drm_connector_helper_funcs omap_connector_helper_funcs = {
243 .mode_valid = omap_connector_mode_valid, 330 .mode_valid = omap_connector_mode_valid,
244}; 331};
245 332
333static int omap_connector_get_type(struct omap_dss_device *display)
334{
335 switch (display->type) {
336 case OMAP_DISPLAY_TYPE_HDMI:
337 return DRM_MODE_CONNECTOR_HDMIA;
338 case OMAP_DISPLAY_TYPE_DVI:
339 return DRM_MODE_CONNECTOR_DVID;
340 case OMAP_DISPLAY_TYPE_DSI:
341 return DRM_MODE_CONNECTOR_DSI;
342 case OMAP_DISPLAY_TYPE_DPI:
343 case OMAP_DISPLAY_TYPE_DBI:
344 return DRM_MODE_CONNECTOR_DPI;
345 case OMAP_DISPLAY_TYPE_VENC:
346 /* TODO: This could also be composite */
347 return DRM_MODE_CONNECTOR_SVIDEO;
348 case OMAP_DISPLAY_TYPE_SDI:
349 return DRM_MODE_CONNECTOR_LVDS;
350 default:
351 return DRM_MODE_CONNECTOR_Unknown;
352 }
353}
354
246/* initialize connector */ 355/* initialize connector */
247struct drm_connector *omap_connector_init(struct drm_device *dev, 356struct drm_connector *omap_connector_init(struct drm_device *dev,
248 int connector_type, struct omap_dss_device *dssdev, 357 struct omap_dss_device *output,
249 struct drm_encoder *encoder) 358 struct omap_dss_device *display,
359 struct drm_encoder *encoder)
250{ 360{
251 struct drm_connector *connector = NULL; 361 struct drm_connector *connector = NULL;
252 struct omap_connector *omap_connector; 362 struct omap_connector *omap_connector;
253 bool hpd_supported = false; 363 struct omap_dss_device *dssdev;
254
255 DBG("%s", dssdev->name);
256 364
257 omap_dss_get_device(dssdev); 365 DBG("%s", display->name);
258 366
259 omap_connector = kzalloc(sizeof(*omap_connector), GFP_KERNEL); 367 omap_connector = kzalloc(sizeof(*omap_connector), GFP_KERNEL);
260 if (!omap_connector) 368 if (!omap_connector)
261 goto fail; 369 goto fail;
262 370
263 omap_connector->dssdev = dssdev; 371 omap_connector->output = omapdss_device_get(output);
372 omap_connector->display = omapdss_device_get(display);
264 373
265 connector = &omap_connector->base; 374 connector = &omap_connector->base;
375 connector->interlace_allowed = 1;
376 connector->doublescan_allowed = 0;
266 377
267 drm_connector_init(dev, connector, &omap_connector_funcs, 378 drm_connector_init(dev, connector, &omap_connector_funcs,
268 connector_type); 379 omap_connector_get_type(display));
269 drm_connector_helper_add(connector, &omap_connector_helper_funcs); 380 drm_connector_helper_add(connector, &omap_connector_helper_funcs);
270 381
271 if (dssdev->driver->register_hpd_cb) { 382 /*
272 int ret = dssdev->driver->register_hpd_cb(dssdev, 383 * Initialize connector status handling. First try to find a device that
273 omap_connector_hpd_cb, 384 * supports hot-plug reporting. If it fails, fall back to a device that
274 omap_connector); 385 * support polling. If that fails too, we don't support hot-plug
275 if (!ret) 386 * detection at all.
276 hpd_supported = true; 387 */
277 else if (ret != -ENOTSUPP) 388 dssdev = omap_connector_find_device(connector, OMAP_DSS_DEVICE_OP_HPD);
278 DBG("%s: Failed to register HPD callback (%d).", 389 if (dssdev) {
279 dssdev->name, ret); 390 omap_connector->hpd = omapdss_device_get(dssdev);
280 }
281
282 if (hpd_supported)
283 connector->polled = DRM_CONNECTOR_POLL_HPD; 391 connector->polled = DRM_CONNECTOR_POLL_HPD;
284 else if (dssdev->driver->detect) 392 } else {
285 connector->polled = DRM_CONNECTOR_POLL_CONNECT | 393 dssdev = omap_connector_find_device(connector,
286 DRM_CONNECTOR_POLL_DISCONNECT; 394 OMAP_DSS_DEVICE_OP_DETECT);
287 else 395 if (dssdev)
288 connector->polled = 0; 396 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
289 397 DRM_CONNECTOR_POLL_DISCONNECT;
290 connector->interlace_allowed = 1; 398 }
291 connector->doublescan_allowed = 0;
292 399
293 return connector; 400 return connector;
294 401
diff --git a/drivers/gpu/drm/omapdrm/omap_connector.h b/drivers/gpu/drm/omapdrm/omap_connector.h
index 98bbc779b302..854099801649 100644
--- a/drivers/gpu/drm/omapdrm/omap_connector.h
+++ b/drivers/gpu/drm/omapdrm/omap_connector.h
@@ -28,10 +28,13 @@ struct drm_encoder;
28struct omap_dss_device; 28struct omap_dss_device;
29 29
30struct drm_connector *omap_connector_init(struct drm_device *dev, 30struct drm_connector *omap_connector_init(struct drm_device *dev,
31 int connector_type, struct omap_dss_device *dssdev, 31 struct omap_dss_device *output,
32 struct drm_encoder *encoder); 32 struct omap_dss_device *display,
33 struct drm_encoder *encoder);
33struct drm_encoder *omap_connector_attached_encoder( 34struct drm_encoder *omap_connector_attached_encoder(
34 struct drm_connector *connector); 35 struct drm_connector *connector);
35bool omap_connector_get_hdmi_mode(struct drm_connector *connector); 36bool omap_connector_get_hdmi_mode(struct drm_connector *connector);
37void omap_connector_enable_hpd(struct drm_connector *connector);
38void omap_connector_disable_hpd(struct drm_connector *connector);
36 39
37#endif /* __OMAPDRM_CONNECTOR_H__ */ 40#endif /* __OMAPDRM_CONNECTOR_H__ */
diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c
index 6c4d40b824e4..62928ec0e7db 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.c
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
@@ -41,6 +41,7 @@ struct omap_crtc {
41 struct drm_crtc base; 41 struct drm_crtc base;
42 42
43 const char *name; 43 const char *name;
44 struct omap_drm_pipeline *pipe;
44 enum omap_channel channel; 45 enum omap_channel channel;
45 46
46 struct videomode vm; 47 struct videomode vm;
@@ -108,38 +109,7 @@ int omap_crtc_wait_pending(struct drm_crtc *crtc)
108 * job of sequencing the setup of the video pipe in the proper order 109 * job of sequencing the setup of the video pipe in the proper order
109 */ 110 */
110 111
111/* ovl-mgr-id -> crtc */
112static struct omap_crtc *omap_crtcs[8];
113static struct omap_dss_device *omap_crtc_output[8];
114
115/* we can probably ignore these until we support command-mode panels: */ 112/* we can probably ignore these until we support command-mode panels: */
116static int omap_crtc_dss_connect(struct omap_drm_private *priv,
117 enum omap_channel channel,
118 struct omap_dss_device *dst)
119{
120 const struct dispc_ops *dispc_ops = priv->dispc_ops;
121 struct dispc_device *dispc = priv->dispc;
122
123 if (omap_crtc_output[channel])
124 return -EINVAL;
125
126 if (!(dispc_ops->mgr_get_supported_outputs(dispc, channel) & dst->id))
127 return -EINVAL;
128
129 omap_crtc_output[channel] = dst;
130 dst->dispc_channel_connected = true;
131
132 return 0;
133}
134
135static void omap_crtc_dss_disconnect(struct omap_drm_private *priv,
136 enum omap_channel channel,
137 struct omap_dss_device *dst)
138{
139 omap_crtc_output[channel] = NULL;
140 dst->dispc_channel_connected = false;
141}
142
143static void omap_crtc_dss_start_update(struct omap_drm_private *priv, 113static void omap_crtc_dss_start_update(struct omap_drm_private *priv,
144 enum omap_channel channel) 114 enum omap_channel channel)
145{ 115{
@@ -159,7 +129,7 @@ static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
159 if (WARN_ON(omap_crtc->enabled == enable)) 129 if (WARN_ON(omap_crtc->enabled == enable))
160 return; 130 return;
161 131
162 if (omap_crtc_output[channel]->output_type == OMAP_DISPLAY_TYPE_HDMI) { 132 if (omap_crtc->pipe->output->output_type == OMAP_DISPLAY_TYPE_HDMI) {
163 priv->dispc_ops->mgr_enable(priv->dispc, channel, enable); 133 priv->dispc_ops->mgr_enable(priv->dispc, channel, enable);
164 omap_crtc->enabled = enable; 134 omap_crtc->enabled = enable;
165 return; 135 return;
@@ -215,7 +185,8 @@ static void omap_crtc_set_enabled(struct drm_crtc *crtc, bool enable)
215static int omap_crtc_dss_enable(struct omap_drm_private *priv, 185static int omap_crtc_dss_enable(struct omap_drm_private *priv,
216 enum omap_channel channel) 186 enum omap_channel channel)
217{ 187{
218 struct omap_crtc *omap_crtc = omap_crtcs[channel]; 188 struct drm_crtc *crtc = priv->channels[channel]->crtc;
189 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
219 190
220 priv->dispc_ops->mgr_set_timings(priv->dispc, omap_crtc->channel, 191 priv->dispc_ops->mgr_set_timings(priv->dispc, omap_crtc->channel,
221 &omap_crtc->vm); 192 &omap_crtc->vm);
@@ -227,7 +198,8 @@ static int omap_crtc_dss_enable(struct omap_drm_private *priv,
227static void omap_crtc_dss_disable(struct omap_drm_private *priv, 198static void omap_crtc_dss_disable(struct omap_drm_private *priv,
228 enum omap_channel channel) 199 enum omap_channel channel)
229{ 200{
230 struct omap_crtc *omap_crtc = omap_crtcs[channel]; 201 struct drm_crtc *crtc = priv->channels[channel]->crtc;
202 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
231 203
232 omap_crtc_set_enabled(&omap_crtc->base, false); 204 omap_crtc_set_enabled(&omap_crtc->base, false);
233} 205}
@@ -236,7 +208,9 @@ static void omap_crtc_dss_set_timings(struct omap_drm_private *priv,
236 enum omap_channel channel, 208 enum omap_channel channel,
237 const struct videomode *vm) 209 const struct videomode *vm)
238{ 210{
239 struct omap_crtc *omap_crtc = omap_crtcs[channel]; 211 struct drm_crtc *crtc = priv->channels[channel]->crtc;
212 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
213
240 DBG("%s", omap_crtc->name); 214 DBG("%s", omap_crtc->name);
241 omap_crtc->vm = *vm; 215 omap_crtc->vm = *vm;
242} 216}
@@ -245,7 +219,8 @@ static void omap_crtc_dss_set_lcd_config(struct omap_drm_private *priv,
245 enum omap_channel channel, 219 enum omap_channel channel,
246 const struct dss_lcd_mgr_config *config) 220 const struct dss_lcd_mgr_config *config)
247{ 221{
248 struct omap_crtc *omap_crtc = omap_crtcs[channel]; 222 struct drm_crtc *crtc = priv->channels[channel]->crtc;
223 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
249 224
250 DBG("%s", omap_crtc->name); 225 DBG("%s", omap_crtc->name);
251 priv->dispc_ops->mgr_set_lcd_config(priv->dispc, omap_crtc->channel, 226 priv->dispc_ops->mgr_set_lcd_config(priv->dispc, omap_crtc->channel,
@@ -266,8 +241,6 @@ static void omap_crtc_dss_unregister_framedone(
266} 241}
267 242
268static const struct dss_mgr_ops mgr_ops = { 243static const struct dss_mgr_ops mgr_ops = {
269 .connect = omap_crtc_dss_connect,
270 .disconnect = omap_crtc_dss_disconnect,
271 .start_update = omap_crtc_dss_start_update, 244 .start_update = omap_crtc_dss_start_update,
272 .enable = omap_crtc_dss_enable, 245 .enable = omap_crtc_dss_enable,
273 .disable = omap_crtc_dss_disable, 246 .disable = omap_crtc_dss_disable,
@@ -447,11 +420,6 @@ static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
447{ 420{
448 struct omap_crtc *omap_crtc = to_omap_crtc(crtc); 421 struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
449 struct drm_display_mode *mode = &crtc->state->adjusted_mode; 422 struct drm_display_mode *mode = &crtc->state->adjusted_mode;
450 struct omap_drm_private *priv = crtc->dev->dev_private;
451 const u32 flags_mask = DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_DE_LOW |
452 DISPLAY_FLAGS_PIXDATA_POSEDGE | DISPLAY_FLAGS_PIXDATA_NEGEDGE |
453 DISPLAY_FLAGS_SYNC_POSEDGE | DISPLAY_FLAGS_SYNC_NEGEDGE;
454 unsigned int i;
455 423
456 DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x", 424 DBG("%s: set mode: %d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x",
457 omap_crtc->name, mode->base.id, mode->name, 425 omap_crtc->name, mode->base.id, mode->name,
@@ -461,38 +429,6 @@ static void omap_crtc_mode_set_nofb(struct drm_crtc *crtc)
461 mode->type, mode->flags); 429 mode->type, mode->flags);
462 430
463 drm_display_mode_to_videomode(mode, &omap_crtc->vm); 431 drm_display_mode_to_videomode(mode, &omap_crtc->vm);
464
465 /*
466 * HACK: This fixes the vm flags.
467 * struct drm_display_mode does not contain the VSYNC/HSYNC/DE flags
468 * and they get lost when converting back and forth between
469 * struct drm_display_mode and struct videomode. The hack below
470 * goes and fetches the missing flags from the panel drivers.
471 *
472 * Correct solution would be to use DRM's bus-flags, but that's not
473 * easily possible before the omapdrm's panel/encoder driver model
474 * has been changed to the DRM model.
475 */
476
477 for (i = 0; i < priv->num_encoders; ++i) {
478 struct drm_encoder *encoder = priv->encoders[i];
479
480 if (encoder->crtc == crtc) {
481 struct omap_dss_device *dssdev;
482
483 dssdev = omap_encoder_get_dssdev(encoder);
484
485 if (dssdev) {
486 struct videomode vm = {0};
487
488 dssdev->driver->get_timings(dssdev, &vm);
489
490 omap_crtc->vm.flags |= vm.flags & flags_mask;
491 }
492
493 break;
494 }
495 }
496} 432}
497 433
498static int omap_crtc_atomic_check(struct drm_crtc *crtc, 434static int omap_crtc_atomic_check(struct drm_crtc *crtc,
@@ -681,37 +617,29 @@ static const char *channel_names[] = {
681 617
682void omap_crtc_pre_init(struct omap_drm_private *priv) 618void omap_crtc_pre_init(struct omap_drm_private *priv)
683{ 619{
684 memset(omap_crtcs, 0, sizeof(omap_crtcs)); 620 dss_install_mgr_ops(priv->dss, &mgr_ops, priv);
685
686 dss_install_mgr_ops(&mgr_ops, priv);
687} 621}
688 622
689void omap_crtc_pre_uninit(void) 623void omap_crtc_pre_uninit(struct omap_drm_private *priv)
690{ 624{
691 dss_uninstall_mgr_ops(); 625 dss_uninstall_mgr_ops(priv->dss);
692} 626}
693 627
694/* initialize crtc */ 628/* initialize crtc */
695struct drm_crtc *omap_crtc_init(struct drm_device *dev, 629struct drm_crtc *omap_crtc_init(struct drm_device *dev,
696 struct drm_plane *plane, struct omap_dss_device *dssdev) 630 struct omap_drm_pipeline *pipe,
631 struct drm_plane *plane)
697{ 632{
698 struct omap_drm_private *priv = dev->dev_private; 633 struct omap_drm_private *priv = dev->dev_private;
699 struct drm_crtc *crtc = NULL; 634 struct drm_crtc *crtc = NULL;
700 struct omap_crtc *omap_crtc; 635 struct omap_crtc *omap_crtc;
701 enum omap_channel channel; 636 enum omap_channel channel;
702 struct omap_dss_device *out;
703 int ret; 637 int ret;
704 638
705 out = omapdss_find_output_from_display(dssdev); 639 channel = pipe->output->dispc_channel;
706 channel = out->dispc_channel;
707 omap_dss_put_device(out);
708 640
709 DBG("%s", channel_names[channel]); 641 DBG("%s", channel_names[channel]);
710 642
711 /* Multiple displays on same channel is not allowed */
712 if (WARN_ON(omap_crtcs[channel] != NULL))
713 return ERR_PTR(-EINVAL);
714
715 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL); 643 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
716 if (!omap_crtc) 644 if (!omap_crtc)
717 return ERR_PTR(-ENOMEM); 645 return ERR_PTR(-ENOMEM);
@@ -720,6 +648,7 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
720 648
721 init_waitqueue_head(&omap_crtc->pending_wait); 649 init_waitqueue_head(&omap_crtc->pending_wait);
722 650
651 omap_crtc->pipe = pipe;
723 omap_crtc->channel = channel; 652 omap_crtc->channel = channel;
724 omap_crtc->name = channel_names[channel]; 653 omap_crtc->name = channel_names[channel];
725 654
@@ -727,7 +656,7 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
727 &omap_crtc_funcs, NULL); 656 &omap_crtc_funcs, NULL);
728 if (ret < 0) { 657 if (ret < 0) {
729 dev_err(dev->dev, "%s(): could not init crtc for: %s\n", 658 dev_err(dev->dev, "%s(): could not init crtc for: %s\n",
730 __func__, dssdev->name); 659 __func__, pipe->display->name);
731 kfree(omap_crtc); 660 kfree(omap_crtc);
732 return ERR_PTR(ret); 661 return ERR_PTR(ret);
733 } 662 }
@@ -750,7 +679,5 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
750 679
751 omap_plane_install_properties(crtc->primary, &crtc->base); 680 omap_plane_install_properties(crtc->primary, &crtc->base);
752 681
753 omap_crtcs[channel] = omap_crtc;
754
755 return crtc; 682 return crtc;
756} 683}
diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.h b/drivers/gpu/drm/omapdrm/omap_crtc.h
index eaab2d7f0324..d9de437ba9dd 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.h
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.h
@@ -27,15 +27,17 @@ enum omap_channel;
27struct drm_crtc; 27struct drm_crtc;
28struct drm_device; 28struct drm_device;
29struct drm_plane; 29struct drm_plane;
30struct omap_drm_pipeline;
30struct omap_dss_device; 31struct omap_dss_device;
31struct videomode; 32struct videomode;
32 33
33struct videomode *omap_crtc_timings(struct drm_crtc *crtc); 34struct videomode *omap_crtc_timings(struct drm_crtc *crtc);
34enum omap_channel omap_crtc_channel(struct drm_crtc *crtc); 35enum omap_channel omap_crtc_channel(struct drm_crtc *crtc);
35void omap_crtc_pre_init(struct omap_drm_private *priv); 36void omap_crtc_pre_init(struct omap_drm_private *priv);
36void omap_crtc_pre_uninit(void); 37void omap_crtc_pre_uninit(struct omap_drm_private *priv);
37struct drm_crtc *omap_crtc_init(struct drm_device *dev, 38struct drm_crtc *omap_crtc_init(struct drm_device *dev,
38 struct drm_plane *plane, struct omap_dss_device *dssdev); 39 struct omap_drm_pipeline *pipe,
40 struct drm_plane *plane);
39int omap_crtc_wait_pending(struct drm_crtc *crtc); 41int omap_crtc_wait_pending(struct drm_crtc *crtc);
40void omap_crtc_error_irq(struct drm_crtc *crtc, u32 irqstatus); 42void omap_crtc_error_irq(struct drm_crtc *crtc, u32 irqstatus);
41void omap_crtc_vblank_irq(struct drm_crtc *crtc); 43void omap_crtc_vblank_irq(struct drm_crtc *crtc);
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
index 1b6601e9b107..5f98506ac2c5 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -15,6 +15,8 @@
15 * this program. If not, see <http://www.gnu.org/licenses/>. 15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18#include <linux/of.h>
19#include <linux/sort.h>
18#include <linux/sys_soc.h> 20#include <linux/sys_soc.h>
19 21
20#include <drm/drm_atomic.h> 22#include <drm/drm_atomic.h>
@@ -127,55 +129,92 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = {
127 .atomic_commit = drm_atomic_helper_commit, 129 .atomic_commit = drm_atomic_helper_commit,
128}; 130};
129 131
130static int get_connector_type(struct omap_dss_device *dssdev) 132static void omap_disconnect_pipelines(struct drm_device *ddev)
131{ 133{
132 switch (dssdev->type) { 134 struct omap_drm_private *priv = ddev->dev_private;
133 case OMAP_DISPLAY_TYPE_HDMI: 135 unsigned int i;
134 return DRM_MODE_CONNECTOR_HDMIA; 136
135 case OMAP_DISPLAY_TYPE_DVI: 137 for (i = 0; i < priv->num_pipes; i++) {
136 return DRM_MODE_CONNECTOR_DVID; 138 struct omap_drm_pipeline *pipe = &priv->pipes[i];
137 case OMAP_DISPLAY_TYPE_DSI: 139
138 return DRM_MODE_CONNECTOR_DSI; 140 omapdss_device_disconnect(NULL, pipe->output);
139 case OMAP_DISPLAY_TYPE_DPI: 141
140 case OMAP_DISPLAY_TYPE_DBI: 142 omapdss_device_put(pipe->output);
141 return DRM_MODE_CONNECTOR_DPI; 143 omapdss_device_put(pipe->display);
142 case OMAP_DISPLAY_TYPE_VENC: 144 pipe->output = NULL;
143 /* TODO: This could also be composite */ 145 pipe->display = NULL;
144 return DRM_MODE_CONNECTOR_SVIDEO;
145 case OMAP_DISPLAY_TYPE_SDI:
146 return DRM_MODE_CONNECTOR_LVDS;
147 default:
148 return DRM_MODE_CONNECTOR_Unknown;
149 } 146 }
147
148 memset(&priv->channels, 0, sizeof(priv->channels));
149
150 priv->num_pipes = 0;
150} 151}
151 152
152static void omap_disconnect_dssdevs(void) 153static int omap_compare_pipes(const void *a, const void *b)
153{ 154{
154 struct omap_dss_device *dssdev = NULL; 155 const struct omap_drm_pipeline *pipe1 = a;
156 const struct omap_drm_pipeline *pipe2 = b;
155 157
156 for_each_dss_dev(dssdev) 158 if (pipe1->display->alias_id > pipe2->display->alias_id)
157 dssdev->driver->disconnect(dssdev); 159 return 1;
160 else if (pipe1->display->alias_id < pipe2->display->alias_id)
161 return -1;
162 return 0;
158} 163}
159 164
160static int omap_connect_dssdevs(void) 165static int omap_connect_pipelines(struct drm_device *ddev)
161{ 166{
167 struct omap_drm_private *priv = ddev->dev_private;
168 struct omap_dss_device *output = NULL;
169 unsigned int i;
162 int r; 170 int r;
163 struct omap_dss_device *dssdev = NULL;
164 171
165 if (!omapdss_stack_is_ready()) 172 if (!omapdss_stack_is_ready())
166 return -EPROBE_DEFER; 173 return -EPROBE_DEFER;
167 174
168 for_each_dss_dev(dssdev) { 175 for_each_dss_output(output) {
169 r = dssdev->driver->connect(dssdev); 176 r = omapdss_device_connect(priv->dss, NULL, output);
170 if (r == -EPROBE_DEFER) { 177 if (r == -EPROBE_DEFER) {
171 omap_dss_put_device(dssdev); 178 omapdss_device_put(output);
172 goto cleanup; 179 goto cleanup;
173 } else if (r) { 180 } else if (r) {
174 dev_warn(dssdev->dev, "could not connect display: %s\n", 181 dev_warn(output->dev, "could not connect output %s\n",
175 dssdev->name); 182 output->name);
183 } else {
184 struct omap_drm_pipeline *pipe;
185
186 pipe = &priv->pipes[priv->num_pipes++];
187 pipe->output = omapdss_device_get(output);
188 pipe->display = omapdss_display_get(output);
189
190 if (priv->num_pipes == ARRAY_SIZE(priv->pipes)) {
191 /* To balance the 'for_each_dss_output' loop */
192 omapdss_device_put(output);
193 break;
194 }
176 } 195 }
177 } 196 }
178 197
198 /* Sort the list by DT aliases */
199 sort(priv->pipes, priv->num_pipes, sizeof(priv->pipes[0]),
200 omap_compare_pipes, NULL);
201
202 /*
203 * Populate the pipeline lookup table by DISPC channel. Only one display
204 * is allowed per channel.
205 */
206 for (i = 0; i < priv->num_pipes; ++i) {
207 struct omap_drm_pipeline *pipe = &priv->pipes[i];
208 enum omap_channel channel = pipe->output->dispc_channel;
209
210 if (WARN_ON(priv->channels[channel] != NULL)) {
211 r = -EINVAL;
212 goto cleanup;
213 }
214
215 priv->channels[channel] = pipe;
216 }
217
179 return 0; 218 return 0;
180 219
181cleanup: 220cleanup:
@@ -183,7 +222,7 @@ cleanup:
183 * if we are deferring probe, we disconnect the devices we previously 222 * if we are deferring probe, we disconnect the devices we previously
184 * connected 223 * connected
185 */ 224 */
186 omap_disconnect_dssdevs(); 225 omap_disconnect_pipelines(ddev);
187 226
188 return r; 227 return r;
189} 228}
@@ -204,10 +243,9 @@ static int omap_modeset_init_properties(struct drm_device *dev)
204static int omap_modeset_init(struct drm_device *dev) 243static int omap_modeset_init(struct drm_device *dev)
205{ 244{
206 struct omap_drm_private *priv = dev->dev_private; 245 struct omap_drm_private *priv = dev->dev_private;
207 struct omap_dss_device *dssdev = NULL;
208 int num_ovls = priv->dispc_ops->get_num_ovls(priv->dispc); 246 int num_ovls = priv->dispc_ops->get_num_ovls(priv->dispc);
209 int num_mgrs = priv->dispc_ops->get_num_mgrs(priv->dispc); 247 int num_mgrs = priv->dispc_ops->get_num_mgrs(priv->dispc);
210 int num_crtcs, crtc_idx, plane_idx; 248 unsigned int i;
211 int ret; 249 int ret;
212 u32 plane_crtc_mask; 250 u32 plane_crtc_mask;
213 251
@@ -225,87 +263,62 @@ static int omap_modeset_init(struct drm_device *dev)
225 * configuration does not match the expectations or exceeds 263 * configuration does not match the expectations or exceeds
226 * the available resources, the configuration is rejected. 264 * the available resources, the configuration is rejected.
227 */ 265 */
228 num_crtcs = 0; 266 if (priv->num_pipes > num_mgrs || priv->num_pipes > num_ovls) {
229 for_each_dss_dev(dssdev)
230 if (omapdss_device_is_connected(dssdev))
231 num_crtcs++;
232
233 if (num_crtcs > num_mgrs || num_crtcs > num_ovls ||
234 num_crtcs > ARRAY_SIZE(priv->crtcs) ||
235 num_crtcs > ARRAY_SIZE(priv->planes) ||
236 num_crtcs > ARRAY_SIZE(priv->encoders) ||
237 num_crtcs > ARRAY_SIZE(priv->connectors)) {
238 dev_err(dev->dev, "%s(): Too many connected displays\n", 267 dev_err(dev->dev, "%s(): Too many connected displays\n",
239 __func__); 268 __func__);
240 return -EINVAL; 269 return -EINVAL;
241 } 270 }
242 271
243 /* All planes can be put to any CRTC */ 272 /* Create all planes first. They can all be put to any CRTC. */
244 plane_crtc_mask = (1 << num_crtcs) - 1; 273 plane_crtc_mask = (1 << priv->num_pipes) - 1;
274
275 for (i = 0; i < num_ovls; i++) {
276 enum drm_plane_type type = i < priv->num_pipes
277 ? DRM_PLANE_TYPE_PRIMARY
278 : DRM_PLANE_TYPE_OVERLAY;
279 struct drm_plane *plane;
280
281 if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)))
282 return -EINVAL;
283
284 plane = omap_plane_init(dev, i, type, plane_crtc_mask);
285 if (IS_ERR(plane))
286 return PTR_ERR(plane);
245 287
246 dssdev = NULL; 288 priv->planes[priv->num_planes++] = plane;
289 }
247 290
248 crtc_idx = 0; 291 /* Create the CRTCs, encoders and connectors. */
249 plane_idx = 0; 292 for (i = 0; i < priv->num_pipes; i++) {
250 for_each_dss_dev(dssdev) { 293 struct omap_drm_pipeline *pipe = &priv->pipes[i];
294 struct omap_dss_device *display = pipe->display;
251 struct drm_connector *connector; 295 struct drm_connector *connector;
252 struct drm_encoder *encoder; 296 struct drm_encoder *encoder;
253 struct drm_plane *plane;
254 struct drm_crtc *crtc; 297 struct drm_crtc *crtc;
255 298
256 if (!omapdss_device_is_connected(dssdev)) 299 encoder = omap_encoder_init(dev, pipe->output, display);
257 continue;
258
259 encoder = omap_encoder_init(dev, dssdev);
260 if (!encoder) 300 if (!encoder)
261 return -ENOMEM; 301 return -ENOMEM;
262 302
263 connector = omap_connector_init(dev, 303 connector = omap_connector_init(dev, pipe->output, display,
264 get_connector_type(dssdev), dssdev, encoder); 304 encoder);
265 if (!connector) 305 if (!connector)
266 return -ENOMEM; 306 return -ENOMEM;
267 307
268 plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_PRIMARY, 308 crtc = omap_crtc_init(dev, pipe, priv->planes[i]);
269 plane_crtc_mask);
270 if (IS_ERR(plane))
271 return PTR_ERR(plane);
272
273 crtc = omap_crtc_init(dev, plane, dssdev);
274 if (IS_ERR(crtc)) 309 if (IS_ERR(crtc))
275 return PTR_ERR(crtc); 310 return PTR_ERR(crtc);
276 311
277 drm_connector_attach_encoder(connector, encoder); 312 drm_connector_attach_encoder(connector, encoder);
278 encoder->possible_crtcs = (1 << crtc_idx); 313 encoder->possible_crtcs = 1 << i;
279
280 priv->crtcs[priv->num_crtcs++] = crtc;
281 priv->planes[priv->num_planes++] = plane;
282 priv->encoders[priv->num_encoders++] = encoder;
283 priv->connectors[priv->num_connectors++] = connector;
284 314
285 plane_idx++; 315 pipe->crtc = crtc;
286 crtc_idx++; 316 pipe->encoder = encoder;
317 pipe->connector = connector;
287 } 318 }
288 319
289 /* 320 DBG("registered %u planes, %u crtcs/encoders/connectors\n",
290 * Create normal planes for the remaining overlays: 321 priv->num_planes, priv->num_pipes);
291 */
292 for (; plane_idx < num_ovls; plane_idx++) {
293 struct drm_plane *plane;
294
295 if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)))
296 return -EINVAL;
297
298 plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_OVERLAY,
299 plane_crtc_mask);
300 if (IS_ERR(plane))
301 return PTR_ERR(plane);
302
303 priv->planes[priv->num_planes++] = plane;
304 }
305
306 DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n",
307 priv->num_planes, priv->num_crtcs, priv->num_encoders,
308 priv->num_connectors);
309 322
310 dev->mode_config.min_width = 8; 323 dev->mode_config.min_width = 8;
311 dev->mode_config.min_height = 2; 324 dev->mode_config.min_height = 2;
@@ -335,27 +348,25 @@ static int omap_modeset_init(struct drm_device *dev)
335/* 348/*
336 * Enable the HPD in external components if supported 349 * Enable the HPD in external components if supported
337 */ 350 */
338static void omap_modeset_enable_external_hpd(void) 351static void omap_modeset_enable_external_hpd(struct drm_device *ddev)
339{ 352{
340 struct omap_dss_device *dssdev = NULL; 353 struct omap_drm_private *priv = ddev->dev_private;
354 int i;
341 355
342 for_each_dss_dev(dssdev) { 356 for (i = 0; i < priv->num_pipes; i++)
343 if (dssdev->driver->enable_hpd) 357 omap_connector_enable_hpd(priv->pipes[i].connector);
344 dssdev->driver->enable_hpd(dssdev);
345 }
346} 358}
347 359
348/* 360/*
349 * Disable the HPD in external components if supported 361 * Disable the HPD in external components if supported
350 */ 362 */
351static void omap_modeset_disable_external_hpd(void) 363static void omap_modeset_disable_external_hpd(struct drm_device *ddev)
352{ 364{
353 struct omap_dss_device *dssdev = NULL; 365 struct omap_drm_private *priv = ddev->dev_private;
366 int i;
354 367
355 for_each_dss_dev(dssdev) { 368 for (i = 0; i < priv->num_pipes; i++)
356 if (dssdev->driver->disable_hpd) 369 omap_connector_disable_hpd(priv->pipes[i].connector);
357 dssdev->driver->disable_hpd(dssdev);
358 }
359} 370}
360 371
361/* 372/*
@@ -525,6 +536,14 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
525 536
526 DBG("%s", dev_name(dev)); 537 DBG("%s", dev_name(dev));
527 538
539 /* Allocate and initialize the DRM device. */
540 ddev = drm_dev_alloc(&omap_drm_driver, dev);
541 if (IS_ERR(ddev))
542 return PTR_ERR(ddev);
543
544 priv->ddev = ddev;
545 ddev->dev_private = priv;
546
528 priv->dev = dev; 547 priv->dev = dev;
529 priv->dss = omapdss_get_dss(); 548 priv->dss = omapdss_get_dss();
530 priv->dispc = dispc_get_dispc(priv->dss); 549 priv->dispc = dispc_get_dispc(priv->dss);
@@ -532,7 +551,7 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
532 551
533 omap_crtc_pre_init(priv); 552 omap_crtc_pre_init(priv);
534 553
535 ret = omap_connect_dssdevs(); 554 ret = omap_connect_pipelines(ddev);
536 if (ret) 555 if (ret)
537 goto err_crtc_uninit; 556 goto err_crtc_uninit;
538 557
@@ -543,16 +562,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
543 mutex_init(&priv->list_lock); 562 mutex_init(&priv->list_lock);
544 INIT_LIST_HEAD(&priv->obj_list); 563 INIT_LIST_HEAD(&priv->obj_list);
545 564
546 /* Allocate and initialize the DRM device. */
547 ddev = drm_dev_alloc(&omap_drm_driver, priv->dev);
548 if (IS_ERR(ddev)) {
549 ret = PTR_ERR(ddev);
550 goto err_destroy_wq;
551 }
552
553 priv->ddev = ddev;
554 ddev->dev_private = priv;
555
556 /* Get memory bandwidth limits */ 565 /* Get memory bandwidth limits */
557 if (priv->dispc_ops->get_memory_bandwidth_limit) 566 if (priv->dispc_ops->get_memory_bandwidth_limit)
558 priv->max_bandwidth = 567 priv->max_bandwidth =
@@ -563,23 +572,23 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
563 ret = omap_modeset_init(ddev); 572 ret = omap_modeset_init(ddev);
564 if (ret) { 573 if (ret) {
565 dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret); 574 dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
566 goto err_free_drm_dev; 575 goto err_gem_deinit;
567 } 576 }
568 577
569 /* Initialize vblank handling, start with all CRTCs disabled. */ 578 /* Initialize vblank handling, start with all CRTCs disabled. */
570 ret = drm_vblank_init(ddev, priv->num_crtcs); 579 ret = drm_vblank_init(ddev, priv->num_pipes);
571 if (ret) { 580 if (ret) {
572 dev_err(priv->dev, "could not init vblank\n"); 581 dev_err(priv->dev, "could not init vblank\n");
573 goto err_cleanup_modeset; 582 goto err_cleanup_modeset;
574 } 583 }
575 584
576 for (i = 0; i < priv->num_crtcs; i++) 585 for (i = 0; i < priv->num_pipes; i++)
577 drm_crtc_vblank_off(priv->crtcs[i]); 586 drm_crtc_vblank_off(priv->pipes[i].crtc);
578 587
579 omap_fbdev_init(ddev); 588 omap_fbdev_init(ddev);
580 589
581 drm_kms_helper_poll_init(ddev); 590 drm_kms_helper_poll_init(ddev);
582 omap_modeset_enable_external_hpd(); 591 omap_modeset_enable_external_hpd(ddev);
583 592
584 /* 593 /*
585 * Register the DRM device with the core and the connectors with 594 * Register the DRM device with the core and the connectors with
@@ -592,21 +601,20 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
592 return 0; 601 return 0;
593 602
594err_cleanup_helpers: 603err_cleanup_helpers:
595 omap_modeset_disable_external_hpd(); 604 omap_modeset_disable_external_hpd(ddev);
596 drm_kms_helper_poll_fini(ddev); 605 drm_kms_helper_poll_fini(ddev);
597 606
598 omap_fbdev_fini(ddev); 607 omap_fbdev_fini(ddev);
599err_cleanup_modeset: 608err_cleanup_modeset:
600 drm_mode_config_cleanup(ddev); 609 drm_mode_config_cleanup(ddev);
601 omap_drm_irq_uninstall(ddev); 610 omap_drm_irq_uninstall(ddev);
602err_free_drm_dev: 611err_gem_deinit:
603 omap_gem_deinit(ddev); 612 omap_gem_deinit(ddev);
604 drm_dev_unref(ddev);
605err_destroy_wq:
606 destroy_workqueue(priv->wq); 613 destroy_workqueue(priv->wq);
607 omap_disconnect_dssdevs(); 614 omap_disconnect_pipelines(ddev);
608err_crtc_uninit: 615err_crtc_uninit:
609 omap_crtc_pre_uninit(); 616 omap_crtc_pre_uninit(priv);
617 drm_dev_unref(ddev);
610 return ret; 618 return ret;
611} 619}
612 620
@@ -618,7 +626,7 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
618 626
619 drm_dev_unregister(ddev); 627 drm_dev_unregister(ddev);
620 628
621 omap_modeset_disable_external_hpd(); 629 omap_modeset_disable_external_hpd(ddev);
622 drm_kms_helper_poll_fini(ddev); 630 drm_kms_helper_poll_fini(ddev);
623 631
624 omap_fbdev_fini(ddev); 632 omap_fbdev_fini(ddev);
@@ -630,12 +638,12 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
630 omap_drm_irq_uninstall(ddev); 638 omap_drm_irq_uninstall(ddev);
631 omap_gem_deinit(ddev); 639 omap_gem_deinit(ddev);
632 640
633 drm_dev_unref(ddev);
634
635 destroy_workqueue(priv->wq); 641 destroy_workqueue(priv->wq);
636 642
637 omap_disconnect_dssdevs(); 643 omap_disconnect_pipelines(ddev);
638 omap_crtc_pre_uninit(); 644 omap_crtc_pre_uninit(priv);
645
646 drm_dev_unref(ddev);
639} 647}
640 648
641static int pdev_probe(struct platform_device *pdev) 649static int pdev_probe(struct platform_device *pdev)
@@ -677,36 +685,36 @@ static int pdev_remove(struct platform_device *pdev)
677} 685}
678 686
679#ifdef CONFIG_PM_SLEEP 687#ifdef CONFIG_PM_SLEEP
680static int omap_drm_suspend_all_displays(void) 688static int omap_drm_suspend_all_displays(struct drm_device *ddev)
681{ 689{
682 struct omap_dss_device *dssdev = NULL; 690 struct omap_drm_private *priv = ddev->dev_private;
691 int i;
683 692
684 for_each_dss_dev(dssdev) { 693 for (i = 0; i < priv->num_pipes; i++) {
685 if (!dssdev->driver) 694 struct omap_dss_device *display = priv->pipes[i].display;
686 continue;
687 695
688 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { 696 if (display->state == OMAP_DSS_DISPLAY_ACTIVE) {
689 dssdev->driver->disable(dssdev); 697 display->ops->disable(display);
690 dssdev->activate_after_resume = true; 698 display->activate_after_resume = true;
691 } else { 699 } else {
692 dssdev->activate_after_resume = false; 700 display->activate_after_resume = false;
693 } 701 }
694 } 702 }
695 703
696 return 0; 704 return 0;
697} 705}
698 706
699static int omap_drm_resume_all_displays(void) 707static int omap_drm_resume_all_displays(struct drm_device *ddev)
700{ 708{
701 struct omap_dss_device *dssdev = NULL; 709 struct omap_drm_private *priv = ddev->dev_private;
710 int i;
702 711
703 for_each_dss_dev(dssdev) { 712 for (i = 0; i < priv->num_pipes; i++) {
704 if (!dssdev->driver) 713 struct omap_dss_device *display = priv->pipes[i].display;
705 continue;
706 714
707 if (dssdev->activate_after_resume) { 715 if (display->activate_after_resume) {
708 dssdev->driver->enable(dssdev); 716 display->ops->enable(display);
709 dssdev->activate_after_resume = false; 717 display->activate_after_resume = false;
710 } 718 }
711 } 719 }
712 720
@@ -721,7 +729,7 @@ static int omap_drm_suspend(struct device *dev)
721 drm_kms_helper_poll_disable(drm_dev); 729 drm_kms_helper_poll_disable(drm_dev);
722 730
723 drm_modeset_lock_all(drm_dev); 731 drm_modeset_lock_all(drm_dev);
724 omap_drm_suspend_all_displays(); 732 omap_drm_suspend_all_displays(drm_dev);
725 drm_modeset_unlock_all(drm_dev); 733 drm_modeset_unlock_all(drm_dev);
726 734
727 return 0; 735 return 0;
@@ -733,7 +741,7 @@ static int omap_drm_resume(struct device *dev)
733 struct drm_device *drm_dev = priv->ddev; 741 struct drm_device *drm_dev = priv->ddev;
734 742
735 drm_modeset_lock_all(drm_dev); 743 drm_modeset_lock_all(drm_dev);
736 omap_drm_resume_all_displays(); 744 omap_drm_resume_all_displays(drm_dev);
737 drm_modeset_unlock_all(drm_dev); 745 drm_modeset_unlock_all(drm_dev);
738 746
739 drm_kms_helper_poll_enable(drm_dev); 747 drm_kms_helper_poll_enable(drm_dev);
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h
index f27c8e216adf..bd7f2c227a25 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.h
+++ b/drivers/gpu/drm/omapdrm/omap_drv.h
@@ -45,6 +45,14 @@
45 45
46struct omap_drm_usergart; 46struct omap_drm_usergart;
47 47
48struct omap_drm_pipeline {
49 struct drm_crtc *crtc;
50 struct drm_encoder *encoder;
51 struct drm_connector *connector;
52 struct omap_dss_device *output;
53 struct omap_dss_device *display;
54};
55
48struct omap_drm_private { 56struct omap_drm_private {
49 struct drm_device *ddev; 57 struct drm_device *ddev;
50 struct device *dev; 58 struct device *dev;
@@ -54,18 +62,13 @@ struct omap_drm_private {
54 struct dispc_device *dispc; 62 struct dispc_device *dispc;
55 const struct dispc_ops *dispc_ops; 63 const struct dispc_ops *dispc_ops;
56 64
57 unsigned int num_crtcs; 65 unsigned int num_pipes;
58 struct drm_crtc *crtcs[8]; 66 struct omap_drm_pipeline pipes[8];
67 struct omap_drm_pipeline *channels[8];
59 68
60 unsigned int num_planes; 69 unsigned int num_planes;
61 struct drm_plane *planes[8]; 70 struct drm_plane *planes[8];
62 71
63 unsigned int num_encoders;
64 struct drm_encoder *encoders[8];
65
66 unsigned int num_connectors;
67 struct drm_connector *connectors[8];
68
69 struct drm_fb_helper *fbdev; 72 struct drm_fb_helper *fbdev;
70 73
71 struct workqueue_struct *wq; 74 struct workqueue_struct *wq;
diff --git a/drivers/gpu/drm/omapdrm/omap_encoder.c b/drivers/gpu/drm/omapdrm/omap_encoder.c
index fcdf4b0a8eec..452e625f6ce3 100644
--- a/drivers/gpu/drm/omapdrm/omap_encoder.c
+++ b/drivers/gpu/drm/omapdrm/omap_encoder.c
@@ -36,16 +36,10 @@
36 */ 36 */
37struct omap_encoder { 37struct omap_encoder {
38 struct drm_encoder base; 38 struct drm_encoder base;
39 struct omap_dss_device *dssdev; 39 struct omap_dss_device *output;
40 struct omap_dss_device *display;
40}; 41};
41 42
42struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder)
43{
44 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
45
46 return omap_encoder->dssdev;
47}
48
49static void omap_encoder_destroy(struct drm_encoder *encoder) 43static void omap_encoder_destroy(struct drm_encoder *encoder)
50{ 44{
51 struct omap_encoder *omap_encoder = to_omap_encoder(encoder); 45 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
@@ -59,16 +53,65 @@ static const struct drm_encoder_funcs omap_encoder_funcs = {
59}; 53};
60 54
61static void omap_encoder_mode_set(struct drm_encoder *encoder, 55static void omap_encoder_mode_set(struct drm_encoder *encoder,
62 struct drm_display_mode *mode, 56 struct drm_display_mode *mode,
63 struct drm_display_mode *adjusted_mode) 57 struct drm_display_mode *adjusted_mode)
64{ 58{
65 struct drm_device *dev = encoder->dev; 59 struct drm_device *dev = encoder->dev;
66 struct omap_encoder *omap_encoder = to_omap_encoder(encoder); 60 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
67 struct omap_dss_device *dssdev = omap_encoder->dssdev;
68 struct drm_connector *connector; 61 struct drm_connector *connector;
62 struct omap_dss_device *dssdev;
63 struct videomode vm = { 0 };
69 bool hdmi_mode; 64 bool hdmi_mode;
70 int r; 65 int r;
71 66
67 drm_display_mode_to_videomode(adjusted_mode, &vm);
68
69 /*
70 * HACK: This fixes the vm flags.
71 * struct drm_display_mode does not contain the VSYNC/HSYNC/DE flags and
72 * they get lost when converting back and forth between struct
73 * drm_display_mode and struct videomode. The hack below goes and
74 * fetches the missing flags.
75 *
76 * A better solution is to use DRM's bus-flags through the whole driver.
77 */
78 for (dssdev = omap_encoder->output; dssdev; dssdev = dssdev->next) {
79 unsigned long bus_flags = dssdev->bus_flags;
80
81 if (!(vm.flags & (DISPLAY_FLAGS_DE_LOW |
82 DISPLAY_FLAGS_DE_HIGH))) {
83 if (bus_flags & DRM_BUS_FLAG_DE_LOW)
84 vm.flags |= DISPLAY_FLAGS_DE_LOW;
85 else if (bus_flags & DRM_BUS_FLAG_DE_HIGH)
86 vm.flags |= DISPLAY_FLAGS_DE_HIGH;
87 }
88
89 if (!(vm.flags & (DISPLAY_FLAGS_PIXDATA_POSEDGE |
90 DISPLAY_FLAGS_PIXDATA_NEGEDGE))) {
91 if (bus_flags & DRM_BUS_FLAG_PIXDATA_POSEDGE)
92 vm.flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
93 else if (bus_flags & DRM_BUS_FLAG_PIXDATA_NEGEDGE)
94 vm.flags |= DISPLAY_FLAGS_PIXDATA_NEGEDGE;
95 }
96
97 if (!(vm.flags & (DISPLAY_FLAGS_SYNC_POSEDGE |
98 DISPLAY_FLAGS_SYNC_NEGEDGE))) {
99 if (bus_flags & DRM_BUS_FLAG_SYNC_POSEDGE)
100 vm.flags |= DISPLAY_FLAGS_SYNC_POSEDGE;
101 else if (bus_flags & DRM_BUS_FLAG_SYNC_NEGEDGE)
102 vm.flags |= DISPLAY_FLAGS_SYNC_NEGEDGE;
103 }
104 }
105
106 /* Set timings for all devices in the display pipeline. */
107 dss_mgr_set_timings(omap_encoder->output, &vm);
108
109 for (dssdev = omap_encoder->output; dssdev; dssdev = dssdev->next) {
110 if (dssdev->ops->set_timings)
111 dssdev->ops->set_timings(dssdev, &vm);
112 }
113
114 /* Set the HDMI mode and HDMI infoframe if applicable. */
72 hdmi_mode = false; 115 hdmi_mode = false;
73 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 116 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
74 if (connector->encoder == encoder) { 117 if (connector->encoder == encoder) {
@@ -77,73 +120,36 @@ static void omap_encoder_mode_set(struct drm_encoder *encoder,
77 } 120 }
78 } 121 }
79 122
80 if (dssdev->driver->set_hdmi_mode) 123 dssdev = omap_encoder->output;
81 dssdev->driver->set_hdmi_mode(dssdev, hdmi_mode); 124
125 if (dssdev->ops->hdmi.set_hdmi_mode)
126 dssdev->ops->hdmi.set_hdmi_mode(dssdev, hdmi_mode);
82 127
83 if (hdmi_mode && dssdev->driver->set_hdmi_infoframe) { 128 if (hdmi_mode && dssdev->ops->hdmi.set_infoframe) {
84 struct hdmi_avi_infoframe avi; 129 struct hdmi_avi_infoframe avi;
85 130
86 r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode, 131 r = drm_hdmi_avi_infoframe_from_display_mode(&avi, adjusted_mode,
87 false); 132 false);
88 if (r == 0) 133 if (r == 0)
89 dssdev->driver->set_hdmi_infoframe(dssdev, &avi); 134 dssdev->ops->hdmi.set_infoframe(dssdev, &avi);
90 } 135 }
91} 136}
92 137
93static void omap_encoder_disable(struct drm_encoder *encoder) 138static void omap_encoder_disable(struct drm_encoder *encoder)
94{ 139{
95 struct omap_encoder *omap_encoder = to_omap_encoder(encoder); 140 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
96 struct omap_dss_device *dssdev = omap_encoder->dssdev; 141 struct omap_dss_device *dssdev = omap_encoder->display;
97 struct omap_dss_driver *dssdrv = dssdev->driver;
98 142
99 dssdrv->disable(dssdev); 143 dssdev->ops->disable(dssdev);
100}
101
102static int omap_encoder_update(struct drm_encoder *encoder,
103 enum omap_channel channel,
104 struct videomode *vm)
105{
106 struct drm_device *dev = encoder->dev;
107 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
108 struct omap_dss_device *dssdev = omap_encoder->dssdev;
109 struct omap_dss_driver *dssdrv = dssdev->driver;
110 int ret;
111
112 if (dssdrv->check_timings) {
113 ret = dssdrv->check_timings(dssdev, vm);
114 } else {
115 struct videomode t = {0};
116
117 dssdrv->get_timings(dssdev, &t);
118
119 if (memcmp(vm, &t, sizeof(*vm)))
120 ret = -EINVAL;
121 else
122 ret = 0;
123 }
124
125 if (ret) {
126 dev_err(dev->dev, "could not set timings: %d\n", ret);
127 return ret;
128 }
129
130 if (dssdrv->set_timings)
131 dssdrv->set_timings(dssdev, vm);
132
133 return 0;
134} 144}
135 145
136static void omap_encoder_enable(struct drm_encoder *encoder) 146static void omap_encoder_enable(struct drm_encoder *encoder)
137{ 147{
138 struct omap_encoder *omap_encoder = to_omap_encoder(encoder); 148 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
139 struct omap_dss_device *dssdev = omap_encoder->dssdev; 149 struct omap_dss_device *dssdev = omap_encoder->display;
140 struct omap_dss_driver *dssdrv = dssdev->driver;
141 int r; 150 int r;
142 151
143 omap_encoder_update(encoder, omap_crtc_channel(encoder->crtc), 152 r = dssdev->ops->enable(dssdev);
144 omap_crtc_timings(encoder->crtc));
145
146 r = dssdrv->enable(dssdev);
147 if (r) 153 if (r)
148 dev_err(encoder->dev->dev, 154 dev_err(encoder->dev->dev,
149 "Failed to enable display '%s': %d\n", 155 "Failed to enable display '%s': %d\n",
@@ -154,7 +160,36 @@ static int omap_encoder_atomic_check(struct drm_encoder *encoder,
154 struct drm_crtc_state *crtc_state, 160 struct drm_crtc_state *crtc_state,
155 struct drm_connector_state *conn_state) 161 struct drm_connector_state *conn_state)
156{ 162{
157 return 0; 163 struct omap_encoder *omap_encoder = to_omap_encoder(encoder);
164 enum omap_channel channel = omap_encoder->output->dispc_channel;
165 struct drm_device *dev = encoder->dev;
166 struct omap_drm_private *priv = dev->dev_private;
167 struct omap_dss_device *dssdev;
168 struct videomode vm = { 0 };
169 int ret;
170
171 drm_display_mode_to_videomode(&crtc_state->mode, &vm);
172
173 ret = priv->dispc_ops->mgr_check_timings(priv->dispc, channel, &vm);
174 if (ret)
175 goto done;
176
177 for (dssdev = omap_encoder->output; dssdev; dssdev = dssdev->next) {
178 if (!dssdev->ops->check_timings)
179 continue;
180
181 ret = dssdev->ops->check_timings(dssdev, &vm);
182 if (ret)
183 goto done;
184 }
185
186 drm_display_mode_from_videomode(&vm, &crtc_state->adjusted_mode);
187
188done:
189 if (ret)
190 dev_err(dev->dev, "invalid timings: %d\n", ret);
191
192 return ret;
158} 193}
159 194
160static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = { 195static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
@@ -166,7 +201,8 @@ static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs = {
166 201
167/* initialize encoder */ 202/* initialize encoder */
168struct drm_encoder *omap_encoder_init(struct drm_device *dev, 203struct drm_encoder *omap_encoder_init(struct drm_device *dev,
169 struct omap_dss_device *dssdev) 204 struct omap_dss_device *output,
205 struct omap_dss_device *display)
170{ 206{
171 struct drm_encoder *encoder = NULL; 207 struct drm_encoder *encoder = NULL;
172 struct omap_encoder *omap_encoder; 208 struct omap_encoder *omap_encoder;
@@ -175,7 +211,8 @@ struct drm_encoder *omap_encoder_init(struct drm_device *dev,
175 if (!omap_encoder) 211 if (!omap_encoder)
176 goto fail; 212 goto fail;
177 213
178 omap_encoder->dssdev = dssdev; 214 omap_encoder->output = output;
215 omap_encoder->display = display;
179 216
180 encoder = &omap_encoder->base; 217 encoder = &omap_encoder->base;
181 218
diff --git a/drivers/gpu/drm/omapdrm/omap_encoder.h b/drivers/gpu/drm/omapdrm/omap_encoder.h
index d2f308bec494..a7b5dde63ecb 100644
--- a/drivers/gpu/drm/omapdrm/omap_encoder.h
+++ b/drivers/gpu/drm/omapdrm/omap_encoder.h
@@ -25,9 +25,7 @@ struct drm_encoder;
25struct omap_dss_device; 25struct omap_dss_device;
26 26
27struct drm_encoder *omap_encoder_init(struct drm_device *dev, 27struct drm_encoder *omap_encoder_init(struct drm_device *dev,
28 struct omap_dss_device *dssdev); 28 struct omap_dss_device *output,
29 29 struct omap_dss_device *display);
30/* map crtc to vblank mask */
31struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder);
32 30
33#endif /* __OMAPDRM_ENCODER_H__ */ 31#endif /* __OMAPDRM_ENCODER_H__ */
diff --git a/drivers/gpu/drm/omapdrm/omap_fbdev.c b/drivers/gpu/drm/omapdrm/omap_fbdev.c
index d958cc813a94..b445309b0143 100644
--- a/drivers/gpu/drm/omapdrm/omap_fbdev.c
+++ b/drivers/gpu/drm/omapdrm/omap_fbdev.c
@@ -243,7 +243,7 @@ void omap_fbdev_init(struct drm_device *dev)
243 struct drm_fb_helper *helper; 243 struct drm_fb_helper *helper;
244 int ret = 0; 244 int ret = 0;
245 245
246 if (!priv->num_crtcs || !priv->num_connectors) 246 if (!priv->num_pipes)
247 return; 247 return;
248 248
249 fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); 249 fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
@@ -256,7 +256,7 @@ void omap_fbdev_init(struct drm_device *dev)
256 256
257 drm_fb_helper_prepare(dev, helper, &omap_fb_helper_funcs); 257 drm_fb_helper_prepare(dev, helper, &omap_fb_helper_funcs);
258 258
259 ret = drm_fb_helper_init(dev, helper, priv->num_connectors); 259 ret = drm_fb_helper_init(dev, helper, priv->num_pipes);
260 if (ret) 260 if (ret)
261 goto fail; 261 goto fail;
262 262
diff --git a/drivers/gpu/drm/omapdrm/omap_irq.c b/drivers/gpu/drm/omapdrm/omap_irq.c
index c85115049f86..329ad26d6d50 100644
--- a/drivers/gpu/drm/omapdrm/omap_irq.c
+++ b/drivers/gpu/drm/omapdrm/omap_irq.c
@@ -206,8 +206,8 @@ static irqreturn_t omap_irq_handler(int irq, void *arg)
206 206
207 VERB("irqs: %08x", irqstatus); 207 VERB("irqs: %08x", irqstatus);
208 208
209 for (id = 0; id < priv->num_crtcs; id++) { 209 for (id = 0; id < priv->num_pipes; id++) {
210 struct drm_crtc *crtc = priv->crtcs[id]; 210 struct drm_crtc *crtc = priv->pipes[id].crtc;
211 enum omap_channel channel = omap_crtc_channel(crtc); 211 enum omap_channel channel = omap_crtc_channel(crtc);
212 212
213 if (irqstatus & priv->dispc_ops->mgr_get_vsync_irq(priv->dispc, channel)) { 213 if (irqstatus & priv->dispc_ops->mgr_get_vsync_irq(priv->dispc, channel)) {