]> Git Repo - linux.git/blame - drivers/gpu/drm/omapdrm/dss/dss.c
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / gpu / drm / omapdrm / dss / dss.c
CommitLineData
559d6701 1/*
559d6701 2 * Copyright (C) 2009 Nokia Corporation
6505d75c 3 * Author: Tomi Valkeinen <[email protected]>
559d6701
TV
4 *
5 * Some code and ideas taken from drivers/video/omap/ driver
6 * by Imre Deak.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#define DSS_SUBSYS_NAME "DSS"
22
11765d16 23#include <linux/debugfs.h>
a921c1a8 24#include <linux/dma-mapping.h>
559d6701 25#include <linux/kernel.h>
2ecef246 26#include <linux/module.h>
559d6701 27#include <linux/io.h>
a8a35931 28#include <linux/export.h>
559d6701
TV
29#include <linux/err.h>
30#include <linux/delay.h>
559d6701
TV
31#include <linux/seq_file.h>
32#include <linux/clk.h>
2639d6b9 33#include <linux/pinctrl/consumer.h>
24e6289c 34#include <linux/platform_device.h>
4fbafaf3 35#include <linux/pm_runtime.h>
185bae10 36#include <linux/gfp.h>
33366d0e 37#include <linux/sizes.h>
be40eecf
TV
38#include <linux/mfd/syscon.h>
39#include <linux/regmap.h>
2ecef246 40#include <linux/of.h>
18daeb8e 41#include <linux/of_device.h>
09bffa6e 42#include <linux/of_graph.h>
99767548 43#include <linux/regulator/consumer.h>
cb17a4ae 44#include <linux/suspend.h>
736e60dd 45#include <linux/component.h>
18daeb8e 46#include <linux/sys_soc.h>
559d6701 47
32043da7 48#include "omapdss.h"
559d6701
TV
49#include "dss.h"
50
559d6701
TV
51struct dss_reg {
52 u16 idx;
53};
54
55#define DSS_REG(idx) ((const struct dss_reg) { idx })
56
57#define DSS_REVISION DSS_REG(0x0000)
58#define DSS_SYSCONFIG DSS_REG(0x0010)
59#define DSS_SYSSTATUS DSS_REG(0x0014)
559d6701
TV
60#define DSS_CONTROL DSS_REG(0x0040)
61#define DSS_SDI_CONTROL DSS_REG(0x0044)
62#define DSS_PLL_CONTROL DSS_REG(0x0048)
63#define DSS_SDI_STATUS DSS_REG(0x005C)
64
360c2153
LP
65#define REG_GET(dss, idx, start, end) \
66 FLD_GET(dss_read_reg(dss, idx), start, end)
559d6701 67
360c2153
LP
68#define REG_FLD_MOD(dss, idx, val, start, end) \
69 dss_write_reg(dss, idx, \
70 FLD_MOD(dss_read_reg(dss, idx), val, start, end))
559d6701 71
fecea252 72struct dss_ops {
8aea8e6a
LP
73 int (*dpi_select_source)(struct dss_device *dss, int port,
74 enum omap_channel channel);
75 int (*select_lcd_source)(struct dss_device *dss,
76 enum omap_channel channel,
77 enum dss_clk_source clk_src);
fecea252
LP
78};
79
185bae10 80struct dss_features {
b8dab2bd 81 enum dss_model model;
185bae10 82 u8 fck_div_max;
9f0fbaea 83 unsigned int fck_freq_max;
185bae10 84 u8 dss_fck_multiplier;
64ad846f 85 const char *parent_clk_name;
234f9a22 86 const enum omap_display_type *ports;
387ce9f2 87 int num_ports;
51919572 88 const enum omap_dss_output_id *outputs;
fecea252 89 const struct dss_ops *ops;
6d85d4ad 90 struct dss_reg_field dispc_clk_switch;
4569ab75 91 bool has_lcd_clk_src;
185bae10
CM
92};
93
235e7dba 94static const char * const dss_generic_clk_source_names[] = {
3b63ca75
TV
95 [DSS_CLK_SRC_FCK] = "FCK",
96 [DSS_CLK_SRC_PLL1_1] = "PLL1:1",
97 [DSS_CLK_SRC_PLL1_2] = "PLL1:2",
b5d8c757 98 [DSS_CLK_SRC_PLL1_3] = "PLL1:3",
3b63ca75
TV
99 [DSS_CLK_SRC_PLL2_1] = "PLL2:1",
100 [DSS_CLK_SRC_PLL2_2] = "PLL2:2",
b5d8c757
TV
101 [DSS_CLK_SRC_PLL2_3] = "PLL2:3",
102 [DSS_CLK_SRC_HDMI_PLL] = "HDMI PLL",
067a57e4
AT
103};
104
360c2153
LP
105static inline void dss_write_reg(struct dss_device *dss,
106 const struct dss_reg idx, u32 val)
559d6701 107{
360c2153 108 __raw_writel(val, dss->base + idx.idx);
559d6701
TV
109}
110
360c2153 111static inline u32 dss_read_reg(struct dss_device *dss, const struct dss_reg idx)
559d6701 112{
360c2153 113 return __raw_readl(dss->base + idx.idx);
559d6701
TV
114}
115
360c2153
LP
116#define SR(dss, reg) \
117 dss->ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(dss, DSS_##reg)
118#define RR(dss, reg) \
119 dss_write_reg(dss, DSS_##reg, dss->ctx[(DSS_##reg).idx / sizeof(u32)])
559d6701 120
360c2153 121static void dss_save_context(struct dss_device *dss)
559d6701 122{
4fbafaf3 123 DSSDBG("dss_save_context\n");
559d6701 124
360c2153 125 SR(dss, CONTROL);
559d6701 126
360c2153
LP
127 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
128 SR(dss, SDI_CONTROL);
129 SR(dss, PLL_CONTROL);
6ec549e5 130 }
69f06054 131
360c2153 132 dss->ctx_valid = true;
69f06054
TV
133
134 DSSDBG("context saved\n");
559d6701
TV
135}
136
360c2153 137static void dss_restore_context(struct dss_device *dss)
559d6701 138{
4fbafaf3 139 DSSDBG("dss_restore_context\n");
559d6701 140
360c2153 141 if (!dss->ctx_valid)
69f06054
TV
142 return;
143
360c2153 144 RR(dss, CONTROL);
559d6701 145
360c2153
LP
146 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
147 RR(dss, SDI_CONTROL);
148 RR(dss, PLL_CONTROL);
6ec549e5 149 }
69f06054
TV
150
151 DSSDBG("context restored\n");
559d6701
TV
152}
153
154#undef SR
155#undef RR
156
27260999 157void dss_ctrl_pll_enable(struct dss_pll *pll, bool enable)
be40eecf 158{
d11e5c82
LP
159 unsigned int shift;
160 unsigned int val;
be40eecf 161
27260999 162 if (!pll->dss->syscon_pll_ctrl)
be40eecf
TV
163 return;
164
165 val = !enable;
166
27260999 167 switch (pll->id) {
be40eecf
TV
168 case DSS_PLL_VIDEO1:
169 shift = 0;
170 break;
171 case DSS_PLL_VIDEO2:
172 shift = 1;
173 break;
174 case DSS_PLL_HDMI:
175 shift = 2;
176 break;
177 default:
27260999 178 DSSERR("illegal DSS PLL ID %d\n", pll->id);
be40eecf
TV
179 return;
180 }
181
27260999
LP
182 regmap_update_bits(pll->dss->syscon_pll_ctrl,
183 pll->dss->syscon_pll_ctrl_offset,
184 1 << shift, val << shift);
be40eecf
TV
185}
186
360c2153
LP
187static int dss_ctrl_pll_set_control_mux(struct dss_device *dss,
188 enum dss_clk_source clk_src,
189 enum omap_channel channel)
be40eecf 190{
d11e5c82 191 unsigned int shift, val;
be40eecf 192
360c2153 193 if (!dss->syscon_pll_ctrl)
c63b1ec0 194 return -EINVAL;
be40eecf
TV
195
196 switch (channel) {
197 case OMAP_DSS_CHANNEL_LCD:
198 shift = 3;
199
c63b1ec0
TV
200 switch (clk_src) {
201 case DSS_CLK_SRC_PLL1_1:
be40eecf 202 val = 0; break;
c63b1ec0 203 case DSS_CLK_SRC_HDMI_PLL:
be40eecf
TV
204 val = 1; break;
205 default:
206 DSSERR("error in PLL mux config for LCD\n");
c63b1ec0 207 return -EINVAL;
be40eecf
TV
208 }
209
210 break;
211 case OMAP_DSS_CHANNEL_LCD2:
212 shift = 5;
213
c63b1ec0
TV
214 switch (clk_src) {
215 case DSS_CLK_SRC_PLL1_3:
be40eecf 216 val = 0; break;
c63b1ec0 217 case DSS_CLK_SRC_PLL2_3:
be40eecf 218 val = 1; break;
c63b1ec0 219 case DSS_CLK_SRC_HDMI_PLL:
be40eecf
TV
220 val = 2; break;
221 default:
222 DSSERR("error in PLL mux config for LCD2\n");
c63b1ec0 223 return -EINVAL;
be40eecf
TV
224 }
225
226 break;
227 case OMAP_DSS_CHANNEL_LCD3:
228 shift = 7;
229
c63b1ec0
TV
230 switch (clk_src) {
231 case DSS_CLK_SRC_PLL2_1:
be40eecf 232 val = 0; break;
c63b1ec0
TV
233 case DSS_CLK_SRC_PLL1_3:
234 val = 1; break;
235 case DSS_CLK_SRC_HDMI_PLL:
be40eecf
TV
236 val = 2; break;
237 default:
238 DSSERR("error in PLL mux config for LCD3\n");
c63b1ec0 239 return -EINVAL;
be40eecf
TV
240 }
241
242 break;
243 default:
244 DSSERR("error in PLL mux config\n");
c63b1ec0 245 return -EINVAL;
be40eecf
TV
246 }
247
360c2153 248 regmap_update_bits(dss->syscon_pll_ctrl, dss->syscon_pll_ctrl_offset,
be40eecf 249 0x3 << shift, val << shift);
c63b1ec0
TV
250
251 return 0;
be40eecf
TV
252}
253
d7157dfe 254void dss_sdi_init(struct dss_device *dss, int datapairs)
559d6701
TV
255{
256 u32 l;
257
258 BUG_ON(datapairs > 3 || datapairs < 1);
259
360c2153 260 l = dss_read_reg(dss, DSS_SDI_CONTROL);
559d6701
TV
261 l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */
262 l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */
263 l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */
360c2153 264 dss_write_reg(dss, DSS_SDI_CONTROL, l);
559d6701 265
360c2153 266 l = dss_read_reg(dss, DSS_PLL_CONTROL);
559d6701
TV
267 l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */
268 l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */
269 l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */
360c2153 270 dss_write_reg(dss, DSS_PLL_CONTROL, l);
559d6701
TV
271}
272
d7157dfe 273int dss_sdi_enable(struct dss_device *dss)
559d6701
TV
274{
275 unsigned long timeout;
276
8a7eda76 277 dispc_pck_free_enable(dss->dispc, 1);
559d6701
TV
278
279 /* Reset SDI PLL */
360c2153 280 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */
559d6701
TV
281 udelay(1); /* wait 2x PCLK */
282
283 /* Lock SDI PLL */
360c2153 284 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */
559d6701
TV
285
286 /* Waiting for PLL lock request to complete */
287 timeout = jiffies + msecs_to_jiffies(500);
360c2153 288 while (dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 6)) {
559d6701
TV
289 if (time_after_eq(jiffies, timeout)) {
290 DSSERR("PLL lock request timed out\n");
291 goto err1;
292 }
293 }
294
295 /* Clearing PLL_GO bit */
360c2153 296 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 28, 28);
559d6701
TV
297
298 /* Waiting for PLL to lock */
299 timeout = jiffies + msecs_to_jiffies(500);
360c2153 300 while (!(dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 5))) {
559d6701
TV
301 if (time_after_eq(jiffies, timeout)) {
302 DSSERR("PLL lock timed out\n");
303 goto err1;
304 }
305 }
306
8a7eda76 307 dispc_lcd_enable_signal(dss->dispc, 1);
559d6701
TV
308
309 /* Waiting for SDI reset to complete */
310 timeout = jiffies + msecs_to_jiffies(500);
360c2153 311 while (!(dss_read_reg(dss, DSS_SDI_STATUS) & (1 << 2))) {
559d6701
TV
312 if (time_after_eq(jiffies, timeout)) {
313 DSSERR("SDI reset timed out\n");
314 goto err2;
315 }
316 }
317
318 return 0;
319
320 err2:
8a7eda76 321 dispc_lcd_enable_signal(dss->dispc, 0);
559d6701
TV
322 err1:
323 /* Reset SDI PLL */
360c2153 324 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
559d6701 325
8a7eda76 326 dispc_pck_free_enable(dss->dispc, 0);
559d6701
TV
327
328 return -ETIMEDOUT;
329}
330
d7157dfe 331void dss_sdi_disable(struct dss_device *dss)
559d6701 332{
8a7eda76 333 dispc_lcd_enable_signal(dss->dispc, 0);
559d6701 334
8a7eda76 335 dispc_pck_free_enable(dss->dispc, 0);
559d6701
TV
336
337 /* Reset SDI PLL */
360c2153 338 REG_FLD_MOD(dss, DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */
559d6701
TV
339}
340
407bd564 341const char *dss_get_clk_source_name(enum dss_clk_source clk_src)
067a57e4 342{
235e7dba 343 return dss_generic_clk_source_names[clk_src];
067a57e4
AT
344}
345
360c2153 346static void dss_dump_clocks(struct dss_device *dss, struct seq_file *s)
559d6701 347{
557a1544 348 const char *fclk_name;
0acf659f 349 unsigned long fclk_rate;
559d6701 350
360c2153 351 if (dss_runtime_get(dss))
4fbafaf3 352 return;
559d6701 353
559d6701
TV
354 seq_printf(s, "- DSS -\n");
355
3b63ca75 356 fclk_name = dss_get_clk_source_name(DSS_CLK_SRC_FCK);
360c2153 357 fclk_rate = clk_get_rate(dss->dss_clk);
559d6701 358
557a1544
TV
359 seq_printf(s, "%s = %lu\n",
360 fclk_name,
9c15d762 361 fclk_rate);
559d6701 362
360c2153 363 dss_runtime_put(dss);
559d6701
TV
364}
365
f33656e1 366static int dss_dump_regs(struct seq_file *s, void *p)
559d6701 367{
360c2153
LP
368 struct dss_device *dss = s->private;
369
370#define DUMPREG(dss, r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(dss, r))
559d6701 371
360c2153 372 if (dss_runtime_get(dss))
f33656e1 373 return 0;
559d6701 374
360c2153
LP
375 DUMPREG(dss, DSS_REVISION);
376 DUMPREG(dss, DSS_SYSCONFIG);
377 DUMPREG(dss, DSS_SYSSTATUS);
378 DUMPREG(dss, DSS_CONTROL);
6ec549e5 379
360c2153
LP
380 if (dss->feat->outputs[OMAP_DSS_CHANNEL_LCD] & OMAP_DSS_OUTPUT_SDI) {
381 DUMPREG(dss, DSS_SDI_CONTROL);
382 DUMPREG(dss, DSS_PLL_CONTROL);
383 DUMPREG(dss, DSS_SDI_STATUS);
6ec549e5 384 }
559d6701 385
360c2153 386 dss_runtime_put(dss);
559d6701 387#undef DUMPREG
f33656e1 388 return 0;
559d6701
TV
389}
390
83df2d4e
TV
391static int dss_debug_dump_clocks(struct seq_file *s, void *p)
392{
393 struct dss_device *dss = s->private;
394
395 dss_dump_clocks(dss, s);
396 dispc_dump_clocks(dss->dispc, s);
83df2d4e
TV
397 return 0;
398}
399
c63b1ec0
TV
400static int dss_get_channel_index(enum omap_channel channel)
401{
402 switch (channel) {
403 case OMAP_DSS_CHANNEL_LCD:
404 return 0;
405 case OMAP_DSS_CHANNEL_LCD2:
406 return 1;
407 case OMAP_DSS_CHANNEL_LCD3:
408 return 2;
409 default:
410 WARN_ON(1);
411 return 0;
412 }
413}
414
360c2153
LP
415static void dss_select_dispc_clk_source(struct dss_device *dss,
416 enum dss_clk_source clk_src)
2f18c4d8
TV
417{
418 int b;
419
c63b1ec0
TV
420 /*
421 * We always use PRCM clock as the DISPC func clock, except on DSS3,
422 * where we don't have separate DISPC and LCD clock sources.
423 */
360c2153 424 if (WARN_ON(dss->feat->has_lcd_clk_src && clk_src != DSS_CLK_SRC_FCK))
c63b1ec0
TV
425 return;
426
66534e8e 427 switch (clk_src) {
3b63ca75 428 case DSS_CLK_SRC_FCK:
66534e8e
AT
429 b = 0;
430 break;
3b63ca75 431 case DSS_CLK_SRC_PLL1_1:
66534e8e 432 b = 1;
66534e8e 433 break;
3b63ca75 434 case DSS_CLK_SRC_PLL2_1:
5a8b572d 435 b = 2;
5a8b572d 436 break;
66534e8e
AT
437 default:
438 BUG();
c6eee968 439 return;
66534e8e 440 }
e406f907 441
360c2153
LP
442 REG_FLD_MOD(dss, DSS_CONTROL, b, /* DISPC_CLK_SWITCH */
443 dss->feat->dispc_clk_switch.start,
444 dss->feat->dispc_clk_switch.end);
2f18c4d8 445
360c2153 446 dss->dispc_clk_source = clk_src;
2f18c4d8
TV
447}
448
8aea8e6a
LP
449void dss_select_dsi_clk_source(struct dss_device *dss, int dsi_module,
450 enum dss_clk_source clk_src)
559d6701 451{
a2e5d827 452 int b, pos;
2f18c4d8 453
66534e8e 454 switch (clk_src) {
3b63ca75 455 case DSS_CLK_SRC_FCK:
66534e8e
AT
456 b = 0;
457 break;
3b63ca75 458 case DSS_CLK_SRC_PLL1_2:
5a8b572d 459 BUG_ON(dsi_module != 0);
66534e8e 460 b = 1;
66534e8e 461 break;
3b63ca75 462 case DSS_CLK_SRC_PLL2_2:
5a8b572d
AT
463 BUG_ON(dsi_module != 1);
464 b = 1;
5a8b572d 465 break;
66534e8e
AT
466 default:
467 BUG();
c6eee968 468 return;
66534e8e 469 }
e406f907 470
a2e5d827 471 pos = dsi_module == 0 ? 1 : 10;
360c2153 472 REG_FLD_MOD(dss, DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */
2f18c4d8 473
8aea8e6a 474 dss->dsi_clk_source[dsi_module] = clk_src;
559d6701
TV
475}
476
8aea8e6a
LP
477static int dss_lcd_clk_mux_dra7(struct dss_device *dss,
478 enum omap_channel channel,
479 enum dss_clk_source clk_src)
c63b1ec0
TV
480{
481 const u8 ctrl_bits[] = {
482 [OMAP_DSS_CHANNEL_LCD] = 0,
483 [OMAP_DSS_CHANNEL_LCD2] = 12,
484 [OMAP_DSS_CHANNEL_LCD3] = 19,
485 };
486
487 u8 ctrl_bit = ctrl_bits[channel];
488 int r;
489
490 if (clk_src == DSS_CLK_SRC_FCK) {
491 /* LCDx_CLK_SWITCH */
360c2153 492 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
c63b1ec0
TV
493 return -EINVAL;
494 }
495
360c2153 496 r = dss_ctrl_pll_set_control_mux(dss, clk_src, channel);
c63b1ec0
TV
497 if (r)
498 return r;
499
360c2153 500 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
c63b1ec0
TV
501
502 return 0;
503}
504
8aea8e6a
LP
505static int dss_lcd_clk_mux_omap5(struct dss_device *dss,
506 enum omap_channel channel,
507 enum dss_clk_source clk_src)
c63b1ec0
TV
508{
509 const u8 ctrl_bits[] = {
510 [OMAP_DSS_CHANNEL_LCD] = 0,
511 [OMAP_DSS_CHANNEL_LCD2] = 12,
512 [OMAP_DSS_CHANNEL_LCD3] = 19,
513 };
514 const enum dss_clk_source allowed_plls[] = {
515 [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
516 [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_FCK,
517 [OMAP_DSS_CHANNEL_LCD3] = DSS_CLK_SRC_PLL2_1,
518 };
519
520 u8 ctrl_bit = ctrl_bits[channel];
521
522 if (clk_src == DSS_CLK_SRC_FCK) {
523 /* LCDx_CLK_SWITCH */
360c2153 524 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
c63b1ec0
TV
525 return -EINVAL;
526 }
527
528 if (WARN_ON(allowed_plls[channel] != clk_src))
529 return -EINVAL;
530
360c2153 531 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
c63b1ec0
TV
532
533 return 0;
534}
535
8aea8e6a
LP
536static int dss_lcd_clk_mux_omap4(struct dss_device *dss,
537 enum omap_channel channel,
538 enum dss_clk_source clk_src)
c63b1ec0
TV
539{
540 const u8 ctrl_bits[] = {
541 [OMAP_DSS_CHANNEL_LCD] = 0,
542 [OMAP_DSS_CHANNEL_LCD2] = 12,
543 };
544 const enum dss_clk_source allowed_plls[] = {
545 [OMAP_DSS_CHANNEL_LCD] = DSS_CLK_SRC_PLL1_1,
546 [OMAP_DSS_CHANNEL_LCD2] = DSS_CLK_SRC_PLL2_1,
547 };
548
549 u8 ctrl_bit = ctrl_bits[channel];
550
551 if (clk_src == DSS_CLK_SRC_FCK) {
552 /* LCDx_CLK_SWITCH */
360c2153 553 REG_FLD_MOD(dss, DSS_CONTROL, 0, ctrl_bit, ctrl_bit);
c63b1ec0
TV
554 return 0;
555 }
556
557 if (WARN_ON(allowed_plls[channel] != clk_src))
558 return -EINVAL;
559
360c2153 560 REG_FLD_MOD(dss, DSS_CONTROL, 1, ctrl_bit, ctrl_bit);
c63b1ec0
TV
561
562 return 0;
563}
564
8aea8e6a
LP
565void dss_select_lcd_clk_source(struct dss_device *dss,
566 enum omap_channel channel,
567 enum dss_clk_source clk_src)
ea75159e 568{
c63b1ec0
TV
569 int idx = dss_get_channel_index(channel);
570 int r;
ea75159e 571
8aea8e6a 572 if (!dss->feat->has_lcd_clk_src) {
360c2153 573 dss_select_dispc_clk_source(dss, clk_src);
8aea8e6a 574 dss->lcd_clk_source[idx] = clk_src;
ea75159e 575 return;
a5b8399f 576 }
ea75159e 577
8aea8e6a 578 r = dss->feat->ops->select_lcd_source(dss, channel, clk_src);
c63b1ec0 579 if (r)
c6eee968 580 return;
ea75159e 581
8aea8e6a 582 dss->lcd_clk_source[idx] = clk_src;
ea75159e
AT
583}
584
3cc62aad 585enum dss_clk_source dss_get_dispc_clk_source(struct dss_device *dss)
559d6701 586{
3cc62aad 587 return dss->dispc_clk_source;
559d6701
TV
588}
589
3cc62aad
LP
590enum dss_clk_source dss_get_dsi_clk_source(struct dss_device *dss,
591 int dsi_module)
559d6701 592{
3cc62aad 593 return dss->dsi_clk_source[dsi_module];
559d6701
TV
594}
595
3cc62aad
LP
596enum dss_clk_source dss_get_lcd_clk_source(struct dss_device *dss,
597 enum omap_channel channel)
ea75159e 598{
3cc62aad 599 if (dss->feat->has_lcd_clk_src) {
c63b1ec0 600 int idx = dss_get_channel_index(channel);
3cc62aad 601 return dss->lcd_clk_source[idx];
89976f29
AT
602 } else {
603 /* LCD_CLK source is the same as DISPC_FCLK source for
604 * OMAP2 and OMAP3 */
3cc62aad 605 return dss->dispc_clk_source;
89976f29 606 }
ea75159e
AT
607}
608
60f9c59f
LP
609bool dss_div_calc(struct dss_device *dss, unsigned long pck,
610 unsigned long fck_min, dss_div_calc_func func, void *data)
43417823
TV
611{
612 int fckd, fckd_start, fckd_stop;
613 unsigned long fck;
614 unsigned long fck_hw_max;
615 unsigned long fckd_hw_max;
616 unsigned long prate;
d11e5c82 617 unsigned int m;
43417823 618
60f9c59f 619 fck_hw_max = dss->feat->fck_freq_max;
fc1fe6e7 620
60f9c59f 621 if (dss->parent_clk == NULL) {
d11e5c82 622 unsigned int pckd;
fc1fe6e7
TV
623
624 pckd = fck_hw_max / pck;
625
626 fck = pck * pckd;
627
60f9c59f 628 fck = clk_round_rate(dss->dss_clk, fck);
fc1fe6e7 629
d0f58bd3 630 return func(fck, data);
43417823
TV
631 }
632
60f9c59f 633 fckd_hw_max = dss->feat->fck_div_max;
43417823 634
60f9c59f
LP
635 m = dss->feat->dss_fck_multiplier;
636 prate = clk_get_rate(dss->parent_clk);
43417823
TV
637
638 fck_min = fck_min ? fck_min : 1;
639
648a55e1
TV
640 fckd_start = min(prate * m / fck_min, fckd_hw_max);
641 fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul);
43417823
TV
642
643 for (fckd = fckd_start; fckd >= fckd_stop; --fckd) {
d0e224f9 644 fck = DIV_ROUND_UP(prate, fckd) * m;
43417823 645
d0f58bd3 646 if (func(fck, data))
43417823
TV
647 return true;
648 }
649
650 return false;
651}
652
60f9c59f 653int dss_set_fck_rate(struct dss_device *dss, unsigned long rate)
559d6701 654{
ada9443f 655 int r;
559d6701 656
ada9443f 657 DSSDBG("set fck to %lu\n", rate);
559d6701 658
60f9c59f 659 r = clk_set_rate(dss->dss_clk, rate);
ada9443f
TV
660 if (r)
661 return r;
559d6701 662
60f9c59f 663 dss->dss_clk_rate = clk_get_rate(dss->dss_clk);
5aaee69d 664
60f9c59f
LP
665 WARN_ONCE(dss->dss_clk_rate != rate, "clk rate mismatch: %lu != %lu",
666 dss->dss_clk_rate, rate);
559d6701
TV
667
668 return 0;
669}
670
60f9c59f 671unsigned long dss_get_dispc_clk_rate(struct dss_device *dss)
5aaee69d 672{
60f9c59f 673 return dss->dss_clk_rate;
5aaee69d
TV
674}
675
60f9c59f 676unsigned long dss_get_max_fck_rate(struct dss_device *dss)
9f0fbaea 677{
60f9c59f 678 return dss->feat->fck_freq_max;
9f0fbaea
LP
679}
680
360c2153 681static int dss_setup_default_clock(struct dss_device *dss)
13a1a2b2
TV
682{
683 unsigned long max_dss_fck, prate;
d0f58bd3 684 unsigned long fck;
d11e5c82 685 unsigned int fck_div;
13a1a2b2
TV
686 int r;
687
360c2153 688 max_dss_fck = dss->feat->fck_freq_max;
13a1a2b2 689
360c2153
LP
690 if (dss->parent_clk == NULL) {
691 fck = clk_round_rate(dss->dss_clk, max_dss_fck);
fc1fe6e7 692 } else {
360c2153 693 prate = clk_get_rate(dss->parent_clk);
13a1a2b2 694
360c2153 695 fck_div = DIV_ROUND_UP(prate * dss->feat->dss_fck_multiplier,
fc1fe6e7 696 max_dss_fck);
360c2153
LP
697 fck = DIV_ROUND_UP(prate, fck_div)
698 * dss->feat->dss_fck_multiplier;
fc1fe6e7 699 }
13a1a2b2 700
360c2153 701 r = dss_set_fck_rate(dss, fck);
13a1a2b2
TV
702 if (r)
703 return r;
704
705 return 0;
706}
707
1ef904e1 708void dss_set_venc_output(struct dss_device *dss, enum omap_dss_venc_type type)
559d6701
TV
709{
710 int l = 0;
711
712 if (type == OMAP_DSS_VENC_TYPE_COMPOSITE)
713 l = 0;
714 else if (type == OMAP_DSS_VENC_TYPE_SVIDEO)
715 l = 1;
716 else
717 BUG();
718
719 /* venc out selection. 0 = comp, 1 = svideo */
360c2153 720 REG_FLD_MOD(dss, DSS_CONTROL, l, 6, 6);
559d6701
TV
721}
722
1ef904e1 723void dss_set_dac_pwrdn_bgz(struct dss_device *dss, bool enable)
559d6701 724{
360c2153
LP
725 /* DAC Power-Down Control */
726 REG_FLD_MOD(dss, DSS_CONTROL, enable, 5, 5);
559d6701
TV
727}
728
8aea8e6a
LP
729void dss_select_hdmi_venc_clk_source(struct dss_device *dss,
730 enum dss_hdmi_venc_clk_source_select src)
7ed024aa 731{
24ab1df3
LP
732 enum omap_dss_output_id outputs;
733
8aea8e6a 734 outputs = dss->feat->outputs[OMAP_DSS_CHANNEL_DIGIT];
8aa2eed1
RN
735
736 /* Complain about invalid selections */
24ab1df3
LP
737 WARN_ON((src == DSS_VENC_TV_CLK) && !(outputs & OMAP_DSS_OUTPUT_VENC));
738 WARN_ON((src == DSS_HDMI_M_PCLK) && !(outputs & OMAP_DSS_OUTPUT_HDMI));
8aa2eed1
RN
739
740 /* Select only if we have options */
24ab1df3
LP
741 if ((outputs & OMAP_DSS_OUTPUT_VENC) &&
742 (outputs & OMAP_DSS_OUTPUT_HDMI))
360c2153
LP
743 /* VENC_HDMI_SWITCH */
744 REG_FLD_MOD(dss, DSS_CONTROL, src, 15, 15);
7ed024aa
M
745}
746
8aea8e6a
LP
747static int dss_dpi_select_source_omap2_omap3(struct dss_device *dss, int port,
748 enum omap_channel channel)
de09e455
TV
749{
750 if (channel != OMAP_DSS_CHANNEL_LCD)
751 return -EINVAL;
752
753 return 0;
754}
755
8aea8e6a
LP
756static int dss_dpi_select_source_omap4(struct dss_device *dss, int port,
757 enum omap_channel channel)
de09e455
TV
758{
759 int val;
760
761 switch (channel) {
762 case OMAP_DSS_CHANNEL_LCD2:
763 val = 0;
764 break;
765 case OMAP_DSS_CHANNEL_DIGIT:
766 val = 1;
767 break;
768 default:
769 return -EINVAL;
770 }
771
360c2153 772 REG_FLD_MOD(dss, DSS_CONTROL, val, 17, 17);
de09e455
TV
773
774 return 0;
775}
776
8aea8e6a
LP
777static int dss_dpi_select_source_omap5(struct dss_device *dss, int port,
778 enum omap_channel channel)
de09e455
TV
779{
780 int val;
781
782 switch (channel) {
783 case OMAP_DSS_CHANNEL_LCD:
784 val = 1;
785 break;
786 case OMAP_DSS_CHANNEL_LCD2:
787 val = 2;
788 break;
789 case OMAP_DSS_CHANNEL_LCD3:
790 val = 3;
791 break;
792 case OMAP_DSS_CHANNEL_DIGIT:
793 val = 0;
794 break;
795 default:
796 return -EINVAL;
797 }
798
360c2153 799 REG_FLD_MOD(dss, DSS_CONTROL, val, 17, 16);
de09e455
TV
800
801 return 0;
802}
803
8aea8e6a
LP
804static int dss_dpi_select_source_dra7xx(struct dss_device *dss, int port,
805 enum omap_channel channel)
6d817880
TV
806{
807 switch (port) {
808 case 0:
8aea8e6a 809 return dss_dpi_select_source_omap5(dss, port, channel);
6d817880
TV
810 case 1:
811 if (channel != OMAP_DSS_CHANNEL_LCD2)
812 return -EINVAL;
813 break;
814 case 2:
815 if (channel != OMAP_DSS_CHANNEL_LCD3)
816 return -EINVAL;
817 break;
818 default:
819 return -EINVAL;
820 }
821
822 return 0;
823}
824
8aea8e6a
LP
825int dss_dpi_select_source(struct dss_device *dss, int port,
826 enum omap_channel channel)
de09e455 827{
8aea8e6a 828 return dss->feat->ops->dpi_select_source(dss, port, channel);
de09e455
TV
829}
830
360c2153 831static int dss_get_clocks(struct dss_device *dss)
8b9cb3a8 832{
4fbafaf3 833 struct clk *clk;
8b9cb3a8 834
360c2153 835 clk = devm_clk_get(&dss->pdev->dev, "fck");
4fbafaf3
TV
836 if (IS_ERR(clk)) {
837 DSSERR("can't get clock fck\n");
b2c9c8ee 838 return PTR_ERR(clk);
a1a0dcca 839 }
8b9cb3a8 840
360c2153 841 dss->dss_clk = clk;
8b9cb3a8 842
360c2153
LP
843 if (dss->feat->parent_clk_name) {
844 clk = clk_get(NULL, dss->feat->parent_clk_name);
8ad9375f 845 if (IS_ERR(clk)) {
360c2153
LP
846 DSSERR("Failed to get %s\n",
847 dss->feat->parent_clk_name);
b2c9c8ee 848 return PTR_ERR(clk);
8ad9375f
AK
849 }
850 } else {
851 clk = NULL;
94c042ce
TV
852 }
853
360c2153 854 dss->parent_clk = clk;
94c042ce 855
8b9cb3a8 856 return 0;
8b9cb3a8
SG
857}
858
360c2153 859static void dss_put_clocks(struct dss_device *dss)
8b9cb3a8 860{
360c2153
LP
861 if (dss->parent_clk)
862 clk_put(dss->parent_clk);
8b9cb3a8
SG
863}
864
7b295257 865int dss_runtime_get(struct dss_device *dss)
8b9cb3a8 866{
4fbafaf3 867 int r;
8b9cb3a8 868
4fbafaf3 869 DSSDBG("dss_runtime_get\n");
8b9cb3a8 870
7b295257 871 r = pm_runtime_get_sync(&dss->pdev->dev);
4fbafaf3
TV
872 WARN_ON(r < 0);
873 return r < 0 ? r : 0;
8b9cb3a8
SG
874}
875
7b295257 876void dss_runtime_put(struct dss_device *dss)
8b9cb3a8 877{
4fbafaf3 878 int r;
8b9cb3a8 879
4fbafaf3 880 DSSDBG("dss_runtime_put\n");
8b9cb3a8 881
7b295257 882 r = pm_runtime_put_sync(&dss->pdev->dev);
5be3aebd 883 WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY);
8b9cb3a8
SG
884}
885
7b295257
LP
886struct dss_device *dss_get_device(struct device *dev)
887{
360c2153 888 return dev_get_drvdata(dev);
7b295257
LP
889}
890
8b9cb3a8 891/* DEBUGFS */
1b3bcb33 892#if defined(CONFIG_OMAP2_DSS_DEBUGFS)
360c2153 893static int dss_initialize_debugfs(struct dss_device *dss)
11765d16 894{
1c4b92ee 895 struct dentry *dir;
11765d16 896
1c4b92ee
LP
897 dir = debugfs_create_dir("omapdss", NULL);
898 if (IS_ERR(dir))
899 return PTR_ERR(dir);
900
901 dss->debugfs.root = dir;
11765d16 902
11765d16
LP
903 return 0;
904}
905
1c4b92ee 906static void dss_uninitialize_debugfs(struct dss_device *dss)
11765d16 907{
1c4b92ee 908 debugfs_remove_recursive(dss->debugfs.root);
11765d16
LP
909}
910
f33656e1
LP
911struct dss_debugfs_entry {
912 struct dentry *dentry;
913 int (*show_fn)(struct seq_file *s, void *data);
914 void *data;
915};
916
917static int dss_debug_open(struct inode *inode, struct file *file)
918{
919 struct dss_debugfs_entry *entry = inode->i_private;
920
921 return single_open(file, entry->show_fn, entry->data);
922}
923
924static const struct file_operations dss_debug_fops = {
925 .open = dss_debug_open,
926 .read = seq_read,
927 .llseek = seq_lseek,
928 .release = single_release,
929};
930
1c4b92ee
LP
931struct dss_debugfs_entry *
932dss_debugfs_create_file(struct dss_device *dss, const char *name,
933 int (*show_fn)(struct seq_file *s, void *data),
934 void *data)
11765d16 935{
f33656e1 936 struct dss_debugfs_entry *entry;
11765d16
LP
937 struct dentry *d;
938
f33656e1
LP
939 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
940 if (!entry)
941 return ERR_PTR(-ENOMEM);
942
943 entry->show_fn = show_fn;
944 entry->data = data;
11765d16 945
1c4b92ee 946 d = debugfs_create_file(name, 0444, dss->debugfs.root, entry,
f33656e1
LP
947 &dss_debug_fops);
948 if (IS_ERR(d)) {
949 kfree(entry);
993d52e2 950 return ERR_CAST(d);
f33656e1
LP
951 }
952
953 entry->dentry = d;
954 return entry;
955}
956
957void dss_debugfs_remove_file(struct dss_debugfs_entry *entry)
958{
959 if (IS_ERR_OR_NULL(entry))
960 return;
961
962 debugfs_remove(entry->dentry);
963 kfree(entry);
11765d16 964}
f33656e1 965
11765d16 966#else /* CONFIG_OMAP2_DSS_DEBUGFS */
360c2153 967static inline int dss_initialize_debugfs(struct dss_device *dss)
11765d16
LP
968{
969 return 0;
970}
1c4b92ee 971static inline void dss_uninitialize_debugfs(struct dss_device *dss)
11765d16
LP
972{
973}
974#endif /* CONFIG_OMAP2_DSS_DEBUGFS */
387ce9f2 975
fecea252
LP
976static const struct dss_ops dss_ops_omap2_omap3 = {
977 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
978};
979
980static const struct dss_ops dss_ops_omap4 = {
981 .dpi_select_source = &dss_dpi_select_source_omap4,
982 .select_lcd_source = &dss_lcd_clk_mux_omap4,
983};
984
985static const struct dss_ops dss_ops_omap5 = {
986 .dpi_select_source = &dss_dpi_select_source_omap5,
987 .select_lcd_source = &dss_lcd_clk_mux_omap5,
988};
989
990static const struct dss_ops dss_ops_dra7 = {
991 .dpi_select_source = &dss_dpi_select_source_dra7xx,
992 .select_lcd_source = &dss_lcd_clk_mux_dra7,
993};
994
234f9a22 995static const enum omap_display_type omap2plus_ports[] = {
387ce9f2
AT
996 OMAP_DISPLAY_TYPE_DPI,
997};
998
234f9a22 999static const enum omap_display_type omap34xx_ports[] = {
387ce9f2
AT
1000 OMAP_DISPLAY_TYPE_DPI,
1001 OMAP_DISPLAY_TYPE_SDI,
1002};
1003
6d817880
TV
1004static const enum omap_display_type dra7xx_ports[] = {
1005 OMAP_DISPLAY_TYPE_DPI,
1006 OMAP_DISPLAY_TYPE_DPI,
1007 OMAP_DISPLAY_TYPE_DPI,
1008};
1009
51919572
LP
1010static const enum omap_dss_output_id omap2_dss_supported_outputs[] = {
1011 /* OMAP_DSS_CHANNEL_LCD */
1012 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
1013
1014 /* OMAP_DSS_CHANNEL_DIGIT */
1015 OMAP_DSS_OUTPUT_VENC,
1016};
1017
1018static const enum omap_dss_output_id omap3430_dss_supported_outputs[] = {
1019 /* OMAP_DSS_CHANNEL_LCD */
1020 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1021 OMAP_DSS_OUTPUT_SDI | OMAP_DSS_OUTPUT_DSI1,
1022
1023 /* OMAP_DSS_CHANNEL_DIGIT */
1024 OMAP_DSS_OUTPUT_VENC,
1025};
1026
1027static const enum omap_dss_output_id omap3630_dss_supported_outputs[] = {
1028 /* OMAP_DSS_CHANNEL_LCD */
1029 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1030 OMAP_DSS_OUTPUT_DSI1,
1031
1032 /* OMAP_DSS_CHANNEL_DIGIT */
1033 OMAP_DSS_OUTPUT_VENC,
1034};
1035
1036static const enum omap_dss_output_id am43xx_dss_supported_outputs[] = {
1037 /* OMAP_DSS_CHANNEL_LCD */
1038 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI,
1039};
1040
1041static const enum omap_dss_output_id omap4_dss_supported_outputs[] = {
1042 /* OMAP_DSS_CHANNEL_LCD */
1043 OMAP_DSS_OUTPUT_DBI | OMAP_DSS_OUTPUT_DSI1,
1044
1045 /* OMAP_DSS_CHANNEL_DIGIT */
1046 OMAP_DSS_OUTPUT_VENC | OMAP_DSS_OUTPUT_HDMI,
1047
1048 /* OMAP_DSS_CHANNEL_LCD2 */
1049 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1050 OMAP_DSS_OUTPUT_DSI2,
1051};
1052
1053static const enum omap_dss_output_id omap5_dss_supported_outputs[] = {
1054 /* OMAP_DSS_CHANNEL_LCD */
1055 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1056 OMAP_DSS_OUTPUT_DSI1 | OMAP_DSS_OUTPUT_DSI2,
1057
1058 /* OMAP_DSS_CHANNEL_DIGIT */
1059 OMAP_DSS_OUTPUT_HDMI,
1060
1061 /* OMAP_DSS_CHANNEL_LCD2 */
1062 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1063 OMAP_DSS_OUTPUT_DSI1,
1064
1065 /* OMAP_DSS_CHANNEL_LCD3 */
1066 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
1067 OMAP_DSS_OUTPUT_DSI2,
1068};
1069
ede92695 1070static const struct dss_features omap24xx_dss_feats = {
b8dab2bd 1071 .model = DSS_MODEL_OMAP2,
6e555e27
TV
1072 /*
1073 * fck div max is really 16, but the divider range has gaps. The range
1074 * from 1 to 6 has no gaps, so let's use that as a max.
1075 */
1076 .fck_div_max = 6,
9f0fbaea 1077 .fck_freq_max = 133000000,
84273a95 1078 .dss_fck_multiplier = 2,
ada9443f 1079 .parent_clk_name = "core_ck",
387ce9f2
AT
1080 .ports = omap2plus_ports,
1081 .num_ports = ARRAY_SIZE(omap2plus_ports),
51919572 1082 .outputs = omap2_dss_supported_outputs,
fecea252 1083 .ops = &dss_ops_omap2_omap3,
6d85d4ad 1084 .dispc_clk_switch = { 0, 0 },
4569ab75 1085 .has_lcd_clk_src = false,
84273a95
TV
1086};
1087
ede92695 1088static const struct dss_features omap34xx_dss_feats = {
b8dab2bd 1089 .model = DSS_MODEL_OMAP3,
84273a95 1090 .fck_div_max = 16,
9f0fbaea 1091 .fck_freq_max = 173000000,
84273a95 1092 .dss_fck_multiplier = 2,
ada9443f 1093 .parent_clk_name = "dpll4_ck",
387ce9f2 1094 .ports = omap34xx_ports,
51919572 1095 .outputs = omap3430_dss_supported_outputs,
387ce9f2 1096 .num_ports = ARRAY_SIZE(omap34xx_ports),
fecea252 1097 .ops = &dss_ops_omap2_omap3,
6d85d4ad 1098 .dispc_clk_switch = { 0, 0 },
4569ab75 1099 .has_lcd_clk_src = false,
84273a95
TV
1100};
1101
ede92695 1102static const struct dss_features omap3630_dss_feats = {
b8dab2bd 1103 .model = DSS_MODEL_OMAP3,
84273a95 1104 .fck_div_max = 32,
9f0fbaea 1105 .fck_freq_max = 173000000,
84273a95 1106 .dss_fck_multiplier = 1,
ada9443f 1107 .parent_clk_name = "dpll4_ck",
387ce9f2
AT
1108 .ports = omap2plus_ports,
1109 .num_ports = ARRAY_SIZE(omap2plus_ports),
51919572 1110 .outputs = omap3630_dss_supported_outputs,
fecea252 1111 .ops = &dss_ops_omap2_omap3,
6d85d4ad 1112 .dispc_clk_switch = { 0, 0 },
4569ab75 1113 .has_lcd_clk_src = false,
84273a95
TV
1114};
1115
ede92695 1116static const struct dss_features omap44xx_dss_feats = {
b8dab2bd 1117 .model = DSS_MODEL_OMAP4,
84273a95 1118 .fck_div_max = 32,
9f0fbaea 1119 .fck_freq_max = 186000000,
84273a95 1120 .dss_fck_multiplier = 1,
ada9443f 1121 .parent_clk_name = "dpll_per_x2_ck",
387ce9f2
AT
1122 .ports = omap2plus_ports,
1123 .num_ports = ARRAY_SIZE(omap2plus_ports),
51919572 1124 .outputs = omap4_dss_supported_outputs,
fecea252 1125 .ops = &dss_ops_omap4,
6d85d4ad 1126 .dispc_clk_switch = { 9, 8 },
4569ab75 1127 .has_lcd_clk_src = true,
84273a95
TV
1128};
1129
ede92695 1130static const struct dss_features omap54xx_dss_feats = {
b8dab2bd 1131 .model = DSS_MODEL_OMAP5,
84273a95 1132 .fck_div_max = 64,
9f0fbaea 1133 .fck_freq_max = 209250000,
84273a95 1134 .dss_fck_multiplier = 1,
ada9443f 1135 .parent_clk_name = "dpll_per_x2_ck",
387ce9f2
AT
1136 .ports = omap2plus_ports,
1137 .num_ports = ARRAY_SIZE(omap2plus_ports),
51919572 1138 .outputs = omap5_dss_supported_outputs,
fecea252 1139 .ops = &dss_ops_omap5,
6d85d4ad 1140 .dispc_clk_switch = { 9, 7 },
4569ab75 1141 .has_lcd_clk_src = true,
84273a95
TV
1142};
1143
ede92695 1144static const struct dss_features am43xx_dss_feats = {
b8dab2bd 1145 .model = DSS_MODEL_OMAP3,
d6279d4a 1146 .fck_div_max = 0,
9f0fbaea 1147 .fck_freq_max = 200000000,
d6279d4a
SP
1148 .dss_fck_multiplier = 0,
1149 .parent_clk_name = NULL,
387ce9f2
AT
1150 .ports = omap2plus_ports,
1151 .num_ports = ARRAY_SIZE(omap2plus_ports),
51919572 1152 .outputs = am43xx_dss_supported_outputs,
fecea252 1153 .ops = &dss_ops_omap2_omap3,
6d85d4ad 1154 .dispc_clk_switch = { 0, 0 },
4569ab75 1155 .has_lcd_clk_src = true,
d6279d4a
SP
1156};
1157
ede92695 1158static const struct dss_features dra7xx_dss_feats = {
b8dab2bd 1159 .model = DSS_MODEL_DRA7,
6d817880 1160 .fck_div_max = 64,
9f0fbaea 1161 .fck_freq_max = 209250000,
6d817880
TV
1162 .dss_fck_multiplier = 1,
1163 .parent_clk_name = "dpll_per_x2_ck",
6d817880
TV
1164 .ports = dra7xx_ports,
1165 .num_ports = ARRAY_SIZE(dra7xx_ports),
51919572 1166 .outputs = omap5_dss_supported_outputs,
fecea252 1167 .ops = &dss_ops_dra7,
6d85d4ad 1168 .dispc_clk_switch = { 9, 7 },
4569ab75 1169 .has_lcd_clk_src = true,
6d817880
TV
1170};
1171
360c2153 1172static int dss_init_ports(struct dss_device *dss)
2ecef246 1173{
360c2153 1174 struct platform_device *pdev = dss->pdev;
2ecef246
TV
1175 struct device_node *parent = pdev->dev.of_node;
1176 struct device_node *port;
8023651b
LP
1177 unsigned int i;
1178 int r;
2ecef246 1179
360c2153 1180 for (i = 0; i < dss->feat->num_ports; i++) {
09bffa6e
RH
1181 port = of_graph_get_port_by_id(parent, i);
1182 if (!port)
387ce9f2 1183 continue;
2ecef246 1184
360c2153 1185 switch (dss->feat->ports[i]) {
387ce9f2 1186 case OMAP_DISPLAY_TYPE_DPI:
8023651b
LP
1187 r = dpi_init_port(dss, pdev, port, dss->feat->model);
1188 if (r)
1189 return r;
387ce9f2 1190 break;
8023651b 1191
387ce9f2 1192 case OMAP_DISPLAY_TYPE_SDI:
8023651b
LP
1193 r = sdi_init_port(dss, pdev, port);
1194 if (r)
1195 return r;
387ce9f2 1196 break;
8023651b 1197
387ce9f2
AT
1198 default:
1199 break;
1200 }
09bffa6e 1201 }
2ecef246
TV
1202
1203 return 0;
1204}
1205
360c2153 1206static void dss_uninit_ports(struct dss_device *dss)
2ecef246 1207{
360c2153 1208 struct platform_device *pdev = dss->pdev;
80eb6751
AT
1209 struct device_node *parent = pdev->dev.of_node;
1210 struct device_node *port;
09bffa6e 1211 int i;
80eb6751 1212
360c2153 1213 for (i = 0; i < dss->feat->num_ports; i++) {
09bffa6e
RH
1214 port = of_graph_get_port_by_id(parent, i);
1215 if (!port)
387ce9f2
AT
1216 continue;
1217
360c2153 1218 switch (dss->feat->ports[i]) {
387ce9f2
AT
1219 case OMAP_DISPLAY_TYPE_DPI:
1220 dpi_uninit_port(port);
1221 break;
1222 case OMAP_DISPLAY_TYPE_SDI:
1223 sdi_uninit_port(port);
1224 break;
1225 default:
1226 break;
1227 }
09bffa6e 1228 }
2ecef246
TV
1229}
1230
360c2153 1231static int dss_video_pll_probe(struct dss_device *dss)
7e328f5a 1232{
360c2153 1233 struct platform_device *pdev = dss->pdev;
7e328f5a
TV
1234 struct device_node *np = pdev->dev.of_node;
1235 struct regulator *pll_regulator;
1236 int r;
1237
1238 if (!np)
1239 return 0;
1240
1241 if (of_property_read_bool(np, "syscon-pll-ctrl")) {
360c2153 1242 dss->syscon_pll_ctrl = syscon_regmap_lookup_by_phandle(np,
7e328f5a 1243 "syscon-pll-ctrl");
360c2153 1244 if (IS_ERR(dss->syscon_pll_ctrl)) {
7e328f5a
TV
1245 dev_err(&pdev->dev,
1246 "failed to get syscon-pll-ctrl regmap\n");
360c2153 1247 return PTR_ERR(dss->syscon_pll_ctrl);
7e328f5a
TV
1248 }
1249
1250 if (of_property_read_u32_index(np, "syscon-pll-ctrl", 1,
360c2153 1251 &dss->syscon_pll_ctrl_offset)) {
7e328f5a
TV
1252 dev_err(&pdev->dev,
1253 "failed to get syscon-pll-ctrl offset\n");
1254 return -EINVAL;
1255 }
1256 }
1257
1258 pll_regulator = devm_regulator_get(&pdev->dev, "vdda_video");
1259 if (IS_ERR(pll_regulator)) {
1260 r = PTR_ERR(pll_regulator);
1261
1262 switch (r) {
1263 case -ENOENT:
1264 pll_regulator = NULL;
1265 break;
1266
1267 case -EPROBE_DEFER:
1268 return -EPROBE_DEFER;
1269
1270 default:
1271 DSSERR("can't get DPLL VDDA regulator\n");
1272 return r;
1273 }
1274 }
1275
1276 if (of_property_match_string(np, "reg-names", "pll1") >= 0) {
360c2153
LP
1277 dss->video1_pll = dss_video_pll_init(dss, pdev, 0,
1278 pll_regulator);
1279 if (IS_ERR(dss->video1_pll))
1280 return PTR_ERR(dss->video1_pll);
7e328f5a
TV
1281 }
1282
1283 if (of_property_match_string(np, "reg-names", "pll2") >= 0) {
360c2153
LP
1284 dss->video2_pll = dss_video_pll_init(dss, pdev, 1,
1285 pll_regulator);
1286 if (IS_ERR(dss->video2_pll)) {
1287 dss_video_pll_uninit(dss->video1_pll);
1288 return PTR_ERR(dss->video2_pll);
7e328f5a
TV
1289 }
1290 }
1291
1292 return 0;
1293}
1294
96c401bc 1295/* DSS HW IP initialisation */
18daeb8e
LP
1296static const struct of_device_id dss_of_match[] = {
1297 { .compatible = "ti,omap2-dss", .data = &omap24xx_dss_feats },
1298 { .compatible = "ti,omap3-dss", .data = &omap3630_dss_feats },
1299 { .compatible = "ti,omap4-dss", .data = &omap44xx_dss_feats },
1300 { .compatible = "ti,omap5-dss", .data = &omap54xx_dss_feats },
1301 { .compatible = "ti,dra7-dss", .data = &dra7xx_dss_feats },
1302 {},
1303};
1304MODULE_DEVICE_TABLE(of, dss_of_match);
1305
1306static const struct soc_device_attribute dss_soc_devices[] = {
1307 { .machine = "OMAP3430/3530", .data = &omap34xx_dss_feats },
1308 { .machine = "AM35??", .data = &omap34xx_dss_feats },
1309 { .family = "AM43xx", .data = &am43xx_dss_feats },
1310 { /* sentinel */ }
1311};
1312
736e60dd 1313static int dss_bind(struct device *dev)
96c401bc 1314{
72877cf3 1315 struct dss_device *dss = dev_get_drvdata(dev);
cc1876ce 1316 struct platform_device *drm_pdev;
96c401bc 1317 int r;
96c401bc 1318
215003b4 1319 r = component_bind_all(dev, NULL);
8b9cb3a8 1320 if (r)
cd3b3449 1321 return r;
8b9cb3a8 1322
cb17a4ae
TV
1323 pm_set_vt_switch(0);
1324
72877cf3 1325 omapdss_set_dss(dss);
f99467b3 1326
cc1876ce
JS
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
8b9cb3a8 1335 return 0;
96c401bc
SG
1336}
1337
736e60dd 1338static void dss_unbind(struct device *dev)
96c401bc 1339{
cc1876ce
JS
1340 struct dss_device *dss = dev_get_drvdata(dev);
1341
1342 platform_device_unregister(dss->drm_pdev);
1343
72877cf3 1344 omapdss_set_dss(NULL);
f99467b3 1345
b40d0ed6 1346 component_unbind_all(dev, NULL);
736e60dd
TV
1347}
1348
1349static const struct component_master_ops dss_component_ops = {
1350 .bind = dss_bind,
1351 .unbind = dss_unbind,
1352};
b98482ed 1353
736e60dd
TV
1354static int dss_component_compare(struct device *dev, void *data)
1355{
1356 struct device *child = data;
1357 return dev == child;
1358}
1359
1360static int dss_add_child_component(struct device *dev, void *data)
1361{
1362 struct component_match **match = data;
1363
0438ec90
TV
1364 /*
1365 * HACK
1366 * We don't have a working driver for rfbi, so skip it here always.
1367 * Otherwise dss will never get probed successfully, as it will wait
1368 * for rfbi to get probed.
1369 */
1370 if (strstr(dev_name(dev), "rfbi"))
1371 return 0;
1372
736e60dd
TV
1373 component_match_add(dev->parent, match, dss_component_compare, dev);
1374
1375 return 0;
1376}
1377
7b295257 1378static int dss_probe_hardware(struct dss_device *dss)
215003b4
LP
1379{
1380 u32 rev;
1381 int r;
1382
7b295257 1383 r = dss_runtime_get(dss);
215003b4
LP
1384 if (r)
1385 return r;
1386
7b295257 1387 dss->dss_clk_rate = clk_get_rate(dss->dss_clk);
215003b4
LP
1388
1389 /* Select DPLL */
360c2153 1390 REG_FLD_MOD(dss, DSS_CONTROL, 0, 0, 0);
215003b4 1391
360c2153 1392 dss_select_dispc_clk_source(dss, DSS_CLK_SRC_FCK);
215003b4
LP
1393
1394#ifdef CONFIG_OMAP2_DSS_VENC
360c2153
LP
1395 REG_FLD_MOD(dss, DSS_CONTROL, 1, 4, 4); /* venc dac demen */
1396 REG_FLD_MOD(dss, DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */
1397 REG_FLD_MOD(dss, DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */
215003b4 1398#endif
7b295257
LP
1399 dss->dsi_clk_source[0] = DSS_CLK_SRC_FCK;
1400 dss->dsi_clk_source[1] = DSS_CLK_SRC_FCK;
1401 dss->dispc_clk_source = DSS_CLK_SRC_FCK;
1402 dss->lcd_clk_source[0] = DSS_CLK_SRC_FCK;
1403 dss->lcd_clk_source[1] = DSS_CLK_SRC_FCK;
215003b4 1404
360c2153 1405 rev = dss_read_reg(dss, DSS_REVISION);
215003b4
LP
1406 pr_info("OMAP DSS rev %d.%d\n", FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
1407
7b295257 1408 dss_runtime_put(dss);
215003b4
LP
1409
1410 return 0;
1411}
1412
736e60dd
TV
1413static int dss_probe(struct platform_device *pdev)
1414{
4a9fab3d 1415 const struct soc_device_attribute *soc;
736e60dd 1416 struct component_match *match = NULL;
215003b4 1417 struct resource *dss_mem;
360c2153 1418 struct dss_device *dss;
736e60dd
TV
1419 int r;
1420
360c2153
LP
1421 dss = kzalloc(sizeof(*dss), GFP_KERNEL);
1422 if (!dss)
1423 return -ENOMEM;
1424
1425 dss->pdev = pdev;
1426 platform_set_drvdata(pdev, dss);
4a9fab3d 1427
a921c1a8
LP
1428 r = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
1429 if (r) {
1430 dev_err(&pdev->dev, "Failed to set the DMA mask\n");
360c2153 1431 goto err_free_dss;
a921c1a8
LP
1432 }
1433
4a9fab3d
LP
1434 /*
1435 * The various OMAP3-based SoCs can't be told apart using the compatible
1436 * string, use SoC device matching.
1437 */
1438 soc = soc_device_match(dss_soc_devices);
1439 if (soc)
360c2153 1440 dss->feat = soc->data;
4a9fab3d 1441 else
360c2153 1442 dss->feat = of_match_device(dss_of_match, &pdev->dev)->data;
4a9fab3d 1443
215003b4
LP
1444 /* Map I/O registers, get and setup clocks. */
1445 dss_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
360c2153
LP
1446 dss->base = devm_ioremap_resource(&pdev->dev, dss_mem);
1447 if (IS_ERR(dss->base)) {
1448 r = PTR_ERR(dss->base);
1449 goto err_free_dss;
1450 }
215003b4 1451
360c2153 1452 r = dss_get_clocks(dss);
11765d16 1453 if (r)
360c2153 1454 goto err_free_dss;
11765d16 1455
360c2153 1456 r = dss_setup_default_clock(dss);
215003b4
LP
1457 if (r)
1458 goto err_put_clocks;
1459
1460 /* Setup the video PLLs and the DPI and SDI ports. */
360c2153 1461 r = dss_video_pll_probe(dss);
215003b4
LP
1462 if (r)
1463 goto err_put_clocks;
1464
360c2153 1465 r = dss_init_ports(dss);
215003b4
LP
1466 if (r)
1467 goto err_uninit_plls;
1468
1469 /* Enable runtime PM and probe the hardware. */
1470 pm_runtime_enable(&pdev->dev);
1471
360c2153 1472 r = dss_probe_hardware(dss);
215003b4
LP
1473 if (r)
1474 goto err_pm_runtime_disable;
1475
1476 /* Initialize debugfs. */
360c2153 1477 r = dss_initialize_debugfs(dss);
215003b4
LP
1478 if (r)
1479 goto err_pm_runtime_disable;
1480
1c4b92ee
LP
1481 dss->debugfs.clk = dss_debugfs_create_file(dss, "clk",
1482 dss_debug_dump_clocks, dss);
1483 dss->debugfs.dss = dss_debugfs_create_file(dss, "dss", dss_dump_regs,
f33656e1 1484 dss);
215003b4
LP
1485
1486 /* Add all the child devices as components. */
e0c827ac
LP
1487 r = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
1488 if (r)
1489 goto err_uninit_debugfs;
1490
f13e97cf
LP
1491 omapdss_gather_components(&pdev->dev);
1492
736e60dd
TV
1493 device_for_each_child(&pdev->dev, &match, dss_add_child_component);
1494
1495 r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match);
215003b4 1496 if (r)
e0c827ac 1497 goto err_of_depopulate;
736e60dd
TV
1498
1499 return 0;
215003b4 1500
e0c827ac
LP
1501err_of_depopulate:
1502 of_platform_depopulate(&pdev->dev);
1503
215003b4 1504err_uninit_debugfs:
f33656e1
LP
1505 dss_debugfs_remove_file(dss->debugfs.clk);
1506 dss_debugfs_remove_file(dss->debugfs.dss);
1c4b92ee 1507 dss_uninitialize_debugfs(dss);
215003b4
LP
1508
1509err_pm_runtime_disable:
1510 pm_runtime_disable(&pdev->dev);
360c2153 1511 dss_uninit_ports(dss);
215003b4
LP
1512
1513err_uninit_plls:
360c2153
LP
1514 if (dss->video1_pll)
1515 dss_video_pll_uninit(dss->video1_pll);
1516 if (dss->video2_pll)
1517 dss_video_pll_uninit(dss->video2_pll);
215003b4
LP
1518
1519err_put_clocks:
360c2153
LP
1520 dss_put_clocks(dss);
1521
1522err_free_dss:
1523 kfree(dss);
215003b4
LP
1524
1525 return r;
736e60dd
TV
1526}
1527
1528static int dss_remove(struct platform_device *pdev)
1529{
360c2153
LP
1530 struct dss_device *dss = platform_get_drvdata(pdev);
1531
e0c827ac
LP
1532 of_platform_depopulate(&pdev->dev);
1533
736e60dd 1534 component_master_del(&pdev->dev, &dss_component_ops);
11765d16 1535
f33656e1
LP
1536 dss_debugfs_remove_file(dss->debugfs.clk);
1537 dss_debugfs_remove_file(dss->debugfs.dss);
1c4b92ee 1538 dss_uninitialize_debugfs(dss);
11765d16 1539
215003b4
LP
1540 pm_runtime_disable(&pdev->dev);
1541
360c2153
LP
1542 dss_uninit_ports(dss);
1543
1544 if (dss->video1_pll)
1545 dss_video_pll_uninit(dss->video1_pll);
215003b4 1546
360c2153
LP
1547 if (dss->video2_pll)
1548 dss_video_pll_uninit(dss->video2_pll);
215003b4 1549
360c2153 1550 dss_put_clocks(dss);
215003b4 1551
360c2153 1552 kfree(dss);
215003b4 1553
96c401bc
SG
1554 return 0;
1555}
1556
74592ee7
LP
1557static void dss_shutdown(struct platform_device *pdev)
1558{
1559 struct omap_dss_device *dssdev = NULL;
1560
1561 DSSDBG("shutdown\n");
1562
92ce521a 1563 for_each_dss_display(dssdev) {
74592ee7 1564 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
83910ad3 1565 dssdev->ops->disable(dssdev);
74592ee7
LP
1566 }
1567}
1568
4fbafaf3
TV
1569static int dss_runtime_suspend(struct device *dev)
1570{
360c2153
LP
1571 struct dss_device *dss = dev_get_drvdata(dev);
1572
1573 dss_save_context(dss);
a8081d31 1574 dss_set_min_bus_tput(dev, 0);
5038bb8c
DG
1575
1576 pinctrl_pm_select_sleep_state(dev);
1577
4fbafaf3
TV
1578 return 0;
1579}
1580
1581static int dss_runtime_resume(struct device *dev)
1582{
360c2153 1583 struct dss_device *dss = dev_get_drvdata(dev);
a8081d31 1584 int r;
5038bb8c
DG
1585
1586 pinctrl_pm_select_default_state(dev);
1587
a8081d31
TV
1588 /*
1589 * Set an arbitrarily high tput request to ensure OPP100.
1590 * What we should really do is to make a request to stay in OPP100,
1591 * without any tput requirements, but that is not currently possible
1592 * via the PM layer.
1593 */
1594
1595 r = dss_set_min_bus_tput(dev, 1000000000);
1596 if (r)
1597 return r;
1598
360c2153 1599 dss_restore_context(dss);
4fbafaf3
TV
1600 return 0;
1601}
1602
1603static const struct dev_pm_ops dss_pm_ops = {
1604 .runtime_suspend = dss_runtime_suspend,
1605 .runtime_resume = dss_runtime_resume,
1606};
1607
d66c36a3 1608struct platform_driver omap_dsshw_driver = {
736e60dd
TV
1609 .probe = dss_probe,
1610 .remove = dss_remove,
74592ee7 1611 .shutdown = dss_shutdown,
96c401bc
SG
1612 .driver = {
1613 .name = "omapdss_dss",
4fbafaf3 1614 .pm = &dss_pm_ops,
2ecef246 1615 .of_match_table = dss_of_match,
422ccbd5 1616 .suppress_bind_attrs = true,
96c401bc
SG
1617 },
1618};
This page took 0.830436 seconds and 4 git commands to generate.