2 * T1042 platform DIU operation
4 * Copyright 2014 Freescale Semiconductor Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
13 #include <linux/kernel.h>
15 #include <linux/of_address.h>
17 #include <sysdev/fsl_soc.h>
19 /*DIU Pixel ClockCR offset in scfg*/
20 #define CCSR_SCFG_PIXCLKCR 0x28
22 /* DIU Pixel Clock bits of the PIXCLKCR */
23 #define PIXCLKCR_PXCKEN 0x80000000
24 #define PIXCLKCR_PXCKINV 0x40000000
25 #define PIXCLKCR_PXCKDLY 0x0000FF00
26 #define PIXCLKCR_PXCLK_MASK 0x00FF0000
28 /* Some CPLD register definitions */
29 #define CPLD_DIUCSR 0x16
30 #define CPLD_DIUCSR_DVIEN 0x80
31 #define CPLD_DIUCSR_BACKLIGHT 0x0f
33 struct device_node *cpld_node;
36 * t1042rdb_set_monitor_port: switch the output to a different monitor port
38 static void t1042rdb_set_monitor_port(enum fsl_diu_monitor_port port)
40 static void __iomem *cpld_base;
42 cpld_base = of_iomap(cpld_node, 0);
44 pr_err("%s: Could not map cpld registers\n", __func__);
49 case FSL_DIU_PORT_DVI:
50 /* Enable the DVI(HDMI) port, disable the DFP and
53 clrbits8(cpld_base + CPLD_DIUCSR, CPLD_DIUCSR_DVIEN);
55 case FSL_DIU_PORT_LVDS:
57 * LVDS also needs backlight enabled, otherwise the display
60 /* Enable the DFP port, disable the DVI*/
61 setbits8(cpld_base + CPLD_DIUCSR, 0x01 << 8);
62 setbits8(cpld_base + CPLD_DIUCSR, 0x01 << 4);
63 setbits8(cpld_base + CPLD_DIUCSR, CPLD_DIUCSR_BACKLIGHT);
66 pr_err("%s: Unsupported monitor port %i\n", __func__, port);
71 of_node_put(cpld_node);
75 * t1042rdb_set_pixel_clock: program the DIU's clock
76 * @pixclock: pixel clock in ps (pico seconds)
78 static void t1042rdb_set_pixel_clock(unsigned int pixclock)
80 struct device_node *scfg_np;
86 scfg_np = of_find_compatible_node(NULL, NULL, "fsl,t1040-scfg");
88 pr_err("%s: Missing scfg node. Can not display video.\n",
93 scfg = of_iomap(scfg_np, 0);
96 pr_err("%s: Could not map device. Can not display video.\n",
101 /* Convert pixclock into frequency */
102 temp = 1000000000000ULL;
103 do_div(temp, pixclock);
107 * 'pxclk' is the ratio of the platform clock to the pixel clock.
108 * This number is programmed into the PIXCLKCR register, and the valid
109 * range of values is 2-255.
111 pxclk = DIV_ROUND_CLOSEST(fsl_get_sys_freq(), freq);
112 pxclk = clamp_t(u32, pxclk, 2, 255);
114 /* Disable the pixel clock, and set it to non-inverted and no delay */
115 clrbits32(scfg + CCSR_SCFG_PIXCLKCR,
116 PIXCLKCR_PXCKEN | PIXCLKCR_PXCKDLY | PIXCLKCR_PXCLK_MASK);
118 /* Enable the clock and set the pxclk */
119 setbits32(scfg + CCSR_SCFG_PIXCLKCR, PIXCLKCR_PXCKEN | (pxclk << 16));
125 * t1042rdb_valid_monitor_port: set the monitor port for sysfs
127 static enum fsl_diu_monitor_port
128 t1042rdb_valid_monitor_port(enum fsl_diu_monitor_port port)
131 case FSL_DIU_PORT_DVI:
132 case FSL_DIU_PORT_LVDS:
135 return FSL_DIU_PORT_DVI; /* Dual-link LVDS is not supported */
139 static int __init t1042rdb_diu_init(void)
141 cpld_node = of_find_compatible_node(NULL, NULL, "fsl,t1042rdb-cpld");
145 diu_ops.set_monitor_port = t1042rdb_set_monitor_port;
146 diu_ops.set_pixel_clock = t1042rdb_set_pixel_clock;
147 diu_ops.valid_monitor_port = t1042rdb_valid_monitor_port;
152 early_initcall(t1042rdb_diu_init);