23 #define DSS_SUBSYS_NAME "DSS"
25 #include <linux/kernel.h>
27 #include <linux/export.h>
43 #define DSS_SZ_REGS SZ_512
49 #define DSS_REG(idx) ((const struct dss_reg) { idx })
51 #define DSS_REVISION DSS_REG(0x0000)
52 #define DSS_SYSCONFIG DSS_REG(0x0010)
53 #define DSS_SYSSTATUS DSS_REG(0x0014)
54 #define DSS_CONTROL DSS_REG(0x0040)
55 #define DSS_SDI_CONTROL DSS_REG(0x0044)
56 #define DSS_PLL_CONTROL DSS_REG(0x0048)
57 #define DSS_SDI_STATUS DSS_REG(0x005C)
59 #define REG_GET(idx, start, end) \
60 FLD_GET(dss_read_reg(idx), start, end)
62 #define REG_FLD_MOD(idx, val, start, end) \
63 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
65 static int dss_runtime_get(
void);
66 static void dss_runtime_put(
void);
97 static const char *
const dss_generic_clk_source_names[] = {
114 dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg)
116 dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)])
118 static void dss_save_context(
void)
120 DSSDBG(
"dss_save_context\n");
130 dss.ctx_valid =
true;
132 DSSDBG(
"context saved\n");
135 static void dss_restore_context(
void)
137 DSSDBG(
"dss_restore_context\n");
150 DSSDBG(
"context restored\n");
160 BUG_ON(datapairs > 3 || datapairs < 1);
164 l =
FLD_MOD(l, datapairs-1, 3, 2);
192 DSSERR(
"PLL lock request timed out\n");
204 DSSERR(
"PLL lock timed out\n");
215 DSSERR(
"SDI reset timed out\n");
245 return dss_generic_clk_source_names[
clk_src];
250 unsigned long dpll4_ck_rate;
251 unsigned long dpll4_m4_ck_rate;
252 const char *fclk_name, *fclk_real_name;
253 unsigned long fclk_rate;
255 if (dss_runtime_get())
264 if (dss.dpll4_m4_ck) {
268 seq_printf(s,
"dpll4_ck %lu\n", dpll4_ck_rate);
270 seq_printf(s,
"%s (%s) = %lu / %lu * %d = %lu\n",
271 fclk_name, fclk_real_name, dpll4_ck_rate,
272 dpll4_ck_rate / dpll4_m4_ck_rate,
273 dss.feat->dss_fck_multiplier, fclk_rate);
276 fclk_name, fclk_real_name,
283 static void dss_dump_regs(
struct seq_file *
s)
285 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
287 if (dss_runtime_get())
335 dss.dispc_clk_source =
clk_src;
365 pos = dsi_module == 0 ? 1 : 10;
368 dss.dsi_clk_source[dsi_module] =
clk_src;
408 dss.lcd_clk_source[ix] =
clk_src;
413 return dss.dispc_clk_source;
418 return dss.dsi_clk_source[dsi_module];
426 return dss.lcd_clk_source[ix];
430 return dss.dispc_clk_source;
436 if (dss.dpll4_m4_ck) {
441 DSSDBG(
"dpll4_m4 = %ld\n", prate);
471 unsigned long fck, max_dss_fck;
483 if (req_pck == dss.cache_req_pck && prate == dss.cache_prate &&
484 dss.cache_dss_cinfo.fck == fck) {
485 DSSDBG(
"dispc clock info found from cache.\n");
486 *dss_cinfo = dss.cache_dss_cinfo;
487 *dispc_cinfo = dss.cache_dispc_cinfo;
491 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
493 if (min_fck_per_pck &&
494 req_pck * min_fck_per_pck > max_dss_fck) {
495 DSSERR(
"Requested pixel clock not possible with the current "
496 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
497 "the constraint off.\n");
502 memset(&best_dss, 0,
sizeof(best_dss));
503 memset(&best_dispc, 0,
sizeof(best_dispc));
505 if (dss.dpll4_m4_ck ==
NULL) {
517 best_dispc = cur_dispc;
521 for (fck_div = dss.feat->fck_div_max; fck_div > 0; --fck_div) {
524 fck = prate / fck_div * dss.feat->dss_fck_multiplier;
526 if (fck > max_dss_fck)
529 if (min_fck_per_pck &&
530 fck < req_pck * min_fck_per_pck)
537 if (
abs(cur_dispc.
pck - req_pck) <
538 abs(best_dispc.
pck - req_pck)) {
543 best_dispc = cur_dispc;
545 if (cur_dispc.
pck == req_pck)
553 if (min_fck_per_pck) {
554 DSSERR(
"Could not find suitable clock settings.\n"
555 "Turning FCK/PCK constraint off and"
561 DSSERR(
"Could not find suitable clock settings.\n");
567 *dss_cinfo = best_dss;
569 *dispc_cinfo = best_dispc;
571 dss.cache_req_pck = req_pck;
572 dss.cache_prate =
prate;
573 dss.cache_dss_cinfo = best_dss;
574 dss.cache_dispc_cinfo = best_dispc;
609 if ((dp & OMAP_DISPLAY_TYPE_VENC) && (dp & OMAP_DISPLAY_TYPE_HDMI))
635 static int dss_dpi_select_source_omap4(
enum omap_channel channel)
655 static int dss_dpi_select_source_omap5(
enum omap_channel channel)
683 return dss.feat->dpi_select_source(channel);
686 static int dss_get_clocks(
void)
691 clk =
clk_get(&dss.pdev->dev,
"fck");
693 DSSERR(
"can't get clock fck\n");
700 if (dss.feat->clk_name) {
703 DSSERR(
"Failed to get %s\n", dss.feat->clk_name);
711 dss.dpll4_m4_ck = clk;
724 static void dss_put_clocks(
void)
731 static int dss_runtime_get(
void)
735 DSSDBG(
"dss_runtime_get\n");
737 r = pm_runtime_get_sync(&dss.pdev->dev);
739 return r < 0 ? r : 0;
742 static void dss_runtime_put(
void)
746 DSSDBG(
"dss_runtime_put\n");
748 r = pm_runtime_put_sync(&dss.pdev->dev);
753 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
754 void dss_debug_dump_clocks(
struct seq_file *s)
758 #ifdef CONFIG_OMAP2_DSS_DSI
766 .dss_fck_multiplier = 2,
768 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
771 static const struct dss_features omap34xx_dss_feats __initconst = {
773 .dss_fck_multiplier = 2,
774 .clk_name =
"dpll4_m4_ck",
775 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
778 static const struct dss_features omap3630_dss_feats __initconst = {
780 .dss_fck_multiplier = 1,
781 .clk_name =
"dpll4_m4_ck",
782 .dpi_select_source = &dss_dpi_select_source_omap2_omap3,
785 static const struct dss_features omap44xx_dss_feats __initconst = {
787 .dss_fck_multiplier = 1,
788 .clk_name =
"dpll_per_m5x2_ck",
789 .dpi_select_source = &dss_dpi_select_source_omap4,
792 static const struct dss_features omap54xx_dss_feats __initconst = {
794 .dss_fck_multiplier = 1,
795 .clk_name =
"dpll_per_h12x2_ck",
796 .dpi_select_source = &dss_dpi_select_source_omap5,
806 dev_err(dev,
"Failed to allocate local DSS Features\n");
811 src = &omap24xx_dss_feats;
813 src = &omap3630_dss_feats;
815 src = &omap34xx_dss_feats;
817 src = &omap44xx_dss_feats;
819 src = &omap54xx_dss_feats;
823 memcpy(dst, src,
sizeof(*dst));
838 r = dss_init_features(&dss.pdev->dev);
844 DSSERR(
"can't get IORESOURCE_MEM DSS\n");
849 resource_size(dss_mem));
851 DSSERR(
"can't ioremap DSS\n");
855 r = dss_get_clocks();
861 r = dss_runtime_get();
863 goto err_runtime_get;
868 #ifdef CONFIG_OMAP2_DSS_VENC
890 pm_runtime_disable(&pdev->
dev);
897 pm_runtime_disable(&pdev->
dev);
904 static int dss_runtime_suspend(
struct device *dev)
911 static int dss_runtime_resume(
struct device *dev)
925 dss_restore_context();
930 .runtime_suspend = dss_runtime_suspend,
931 .runtime_resume = dss_runtime_resume,
935 .remove =
__exit_p(omap_dsshw_remove),
937 .name =
"omapdss_dss",