Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/dss.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * Some code and ideas taken from drivers/video/omap/ driver |
| 8 | * by Imre Deak. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #define DSS_SUBSYS_NAME "DSS" |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/io.h> |
Paul Gortmaker | a8a3593 | 2011-07-10 13:20:26 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 28 | #include <linux/err.h> |
| 29 | #include <linux/delay.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 30 | #include <linux/seq_file.h> |
| 31 | #include <linux/clk.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 34 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 35 | #include <video/omapdss.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 36 | |
| 37 | #include <plat/cpu.h> |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 38 | #include <plat/clock.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 39 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 40 | #include "dss.h" |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 41 | #include "dss_features.h" |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 42 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 43 | #define DSS_SZ_REGS SZ_512 |
| 44 | |
| 45 | struct dss_reg { |
| 46 | u16 idx; |
| 47 | }; |
| 48 | |
| 49 | #define DSS_REG(idx) ((const struct dss_reg) { idx }) |
| 50 | |
| 51 | #define DSS_REVISION DSS_REG(0x0000) |
| 52 | #define DSS_SYSCONFIG DSS_REG(0x0010) |
| 53 | #define DSS_SYSSTATUS DSS_REG(0x0014) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 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) |
| 58 | |
| 59 | #define REG_GET(idx, start, end) \ |
| 60 | FLD_GET(dss_read_reg(idx), start, end) |
| 61 | |
| 62 | #define REG_FLD_MOD(idx, val, start, end) \ |
| 63 | dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end)) |
| 64 | |
| 65 | static struct { |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 66 | struct platform_device *pdev; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 67 | void __iomem *base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 68 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 69 | struct clk *dpll4_m4_ck; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 70 | struct clk *dss_clk; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 71 | |
| 72 | unsigned long cache_req_pck; |
| 73 | unsigned long cache_prate; |
| 74 | struct dss_clock_info cache_dss_cinfo; |
| 75 | struct dispc_clock_info cache_dispc_cinfo; |
| 76 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 77 | enum omap_dss_clk_source dsi_clk_source[MAX_NUM_DSI]; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 78 | enum omap_dss_clk_source dispc_clk_source; |
| 79 | enum omap_dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS]; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 80 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 81 | bool ctx_valid; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 82 | u32 ctx[DSS_SZ_REGS / sizeof(u32)]; |
| 83 | } dss; |
| 84 | |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 85 | static const char * const dss_generic_clk_source_names[] = { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 86 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI_PLL_HSDIV_DISPC", |
| 87 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI_PLL_HSDIV_DSI", |
| 88 | [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCK", |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 89 | }; |
| 90 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 91 | static inline void dss_write_reg(const struct dss_reg idx, u32 val) |
| 92 | { |
| 93 | __raw_writel(val, dss.base + idx.idx); |
| 94 | } |
| 95 | |
| 96 | static inline u32 dss_read_reg(const struct dss_reg idx) |
| 97 | { |
| 98 | return __raw_readl(dss.base + idx.idx); |
| 99 | } |
| 100 | |
| 101 | #define SR(reg) \ |
| 102 | dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg) |
| 103 | #define RR(reg) \ |
| 104 | dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)]) |
| 105 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 106 | static void dss_save_context(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 107 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 108 | DSSDBG("dss_save_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 109 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 110 | SR(CONTROL); |
| 111 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 112 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 113 | OMAP_DISPLAY_TYPE_SDI) { |
| 114 | SR(SDI_CONTROL); |
| 115 | SR(PLL_CONTROL); |
| 116 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 117 | |
| 118 | dss.ctx_valid = true; |
| 119 | |
| 120 | DSSDBG("context saved\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 123 | static void dss_restore_context(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 124 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 125 | DSSDBG("dss_restore_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 126 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 127 | if (!dss.ctx_valid) |
| 128 | return; |
| 129 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 130 | RR(CONTROL); |
| 131 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 132 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 133 | OMAP_DISPLAY_TYPE_SDI) { |
| 134 | RR(SDI_CONTROL); |
| 135 | RR(PLL_CONTROL); |
| 136 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 137 | |
| 138 | DSSDBG("context restored\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | #undef SR |
| 142 | #undef RR |
| 143 | |
| 144 | void dss_sdi_init(u8 datapairs) |
| 145 | { |
| 146 | u32 l; |
| 147 | |
| 148 | BUG_ON(datapairs > 3 || datapairs < 1); |
| 149 | |
| 150 | l = dss_read_reg(DSS_SDI_CONTROL); |
| 151 | l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */ |
| 152 | l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */ |
| 153 | l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */ |
| 154 | dss_write_reg(DSS_SDI_CONTROL, l); |
| 155 | |
| 156 | l = dss_read_reg(DSS_PLL_CONTROL); |
| 157 | l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */ |
| 158 | l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */ |
| 159 | l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */ |
| 160 | dss_write_reg(DSS_PLL_CONTROL, l); |
| 161 | } |
| 162 | |
| 163 | int dss_sdi_enable(void) |
| 164 | { |
| 165 | unsigned long timeout; |
| 166 | |
| 167 | dispc_pck_free_enable(1); |
| 168 | |
| 169 | /* Reset SDI PLL */ |
| 170 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */ |
| 171 | udelay(1); /* wait 2x PCLK */ |
| 172 | |
| 173 | /* Lock SDI PLL */ |
| 174 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */ |
| 175 | |
| 176 | /* Waiting for PLL lock request to complete */ |
| 177 | timeout = jiffies + msecs_to_jiffies(500); |
| 178 | while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) { |
| 179 | if (time_after_eq(jiffies, timeout)) { |
| 180 | DSSERR("PLL lock request timed out\n"); |
| 181 | goto err1; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* Clearing PLL_GO bit */ |
| 186 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28); |
| 187 | |
| 188 | /* Waiting for PLL to lock */ |
| 189 | timeout = jiffies + msecs_to_jiffies(500); |
| 190 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) { |
| 191 | if (time_after_eq(jiffies, timeout)) { |
| 192 | DSSERR("PLL lock timed out\n"); |
| 193 | goto err1; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | dispc_lcd_enable_signal(1); |
| 198 | |
| 199 | /* Waiting for SDI reset to complete */ |
| 200 | timeout = jiffies + msecs_to_jiffies(500); |
| 201 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) { |
| 202 | if (time_after_eq(jiffies, timeout)) { |
| 203 | DSSERR("SDI reset timed out\n"); |
| 204 | goto err2; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | |
| 210 | err2: |
| 211 | dispc_lcd_enable_signal(0); |
| 212 | err1: |
| 213 | /* Reset SDI PLL */ |
| 214 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 215 | |
| 216 | dispc_pck_free_enable(0); |
| 217 | |
| 218 | return -ETIMEDOUT; |
| 219 | } |
| 220 | |
| 221 | void dss_sdi_disable(void) |
| 222 | { |
| 223 | dispc_lcd_enable_signal(0); |
| 224 | |
| 225 | dispc_pck_free_enable(0); |
| 226 | |
| 227 | /* Reset SDI PLL */ |
| 228 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 229 | } |
| 230 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 231 | const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 232 | { |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 233 | return dss_generic_clk_source_names[clk_src]; |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 234 | } |
| 235 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 236 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 237 | void dss_dump_clocks(struct seq_file *s) |
| 238 | { |
| 239 | unsigned long dpll4_ck_rate; |
| 240 | unsigned long dpll4_m4_ck_rate; |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 241 | const char *fclk_name, *fclk_real_name; |
| 242 | unsigned long fclk_rate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 243 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 244 | if (dss_runtime_get()) |
| 245 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 246 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 247 | seq_printf(s, "- DSS -\n"); |
| 248 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 249 | fclk_name = dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK); |
| 250 | fclk_real_name = dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_FCK); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 251 | fclk_rate = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 252 | |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 253 | if (dss.dpll4_m4_ck) { |
| 254 | dpll4_ck_rate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); |
| 255 | dpll4_m4_ck_rate = clk_get_rate(dss.dpll4_m4_ck); |
| 256 | |
| 257 | seq_printf(s, "dpll4_ck %lu\n", dpll4_ck_rate); |
| 258 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 259 | if (cpu_is_omap3630() || cpu_is_omap44xx()) |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 260 | seq_printf(s, "%s (%s) = %lu / %lu = %lu\n", |
| 261 | fclk_name, fclk_real_name, |
| 262 | dpll4_ck_rate, |
| 263 | dpll4_ck_rate / dpll4_m4_ck_rate, |
| 264 | fclk_rate); |
| 265 | else |
| 266 | seq_printf(s, "%s (%s) = %lu / %lu * 2 = %lu\n", |
| 267 | fclk_name, fclk_real_name, |
| 268 | dpll4_ck_rate, |
| 269 | dpll4_ck_rate / dpll4_m4_ck_rate, |
| 270 | fclk_rate); |
| 271 | } else { |
| 272 | seq_printf(s, "%s (%s) = %lu\n", |
| 273 | fclk_name, fclk_real_name, |
| 274 | fclk_rate); |
| 275 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 276 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 277 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void dss_dump_regs(struct seq_file *s) |
| 281 | { |
| 282 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r)) |
| 283 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 284 | if (dss_runtime_get()) |
| 285 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 286 | |
| 287 | DUMPREG(DSS_REVISION); |
| 288 | DUMPREG(DSS_SYSCONFIG); |
| 289 | DUMPREG(DSS_SYSSTATUS); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 290 | DUMPREG(DSS_CONTROL); |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 291 | |
| 292 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 293 | OMAP_DISPLAY_TYPE_SDI) { |
| 294 | DUMPREG(DSS_SDI_CONTROL); |
| 295 | DUMPREG(DSS_PLL_CONTROL); |
| 296 | DUMPREG(DSS_SDI_STATUS); |
| 297 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 298 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 299 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 300 | #undef DUMPREG |
| 301 | } |
| 302 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 303 | void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 304 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 305 | struct platform_device *dsidev; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 306 | int b; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 307 | u8 start, end; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 308 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 309 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 310 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 311 | b = 0; |
| 312 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 313 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 314 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 315 | dsidev = dsi_get_dsidev_from_id(0); |
| 316 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 317 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 318 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
| 319 | b = 2; |
| 320 | dsidev = dsi_get_dsidev_from_id(1); |
| 321 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
| 322 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 323 | default: |
| 324 | BUG(); |
| 325 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 326 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 327 | dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end); |
| 328 | |
| 329 | REG_FLD_MOD(DSS_CONTROL, b, start, end); /* DISPC_CLK_SWITCH */ |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 330 | |
| 331 | dss.dispc_clk_source = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 332 | } |
| 333 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 334 | void dss_select_dsi_clk_source(int dsi_module, |
| 335 | enum omap_dss_clk_source clk_src) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 336 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 337 | struct platform_device *dsidev; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 338 | int b; |
| 339 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 340 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 341 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 342 | b = 0; |
| 343 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 344 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI: |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 345 | BUG_ON(dsi_module != 0); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 346 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 347 | dsidev = dsi_get_dsidev_from_id(0); |
| 348 | dsi_wait_pll_hsdiv_dsi_active(dsidev); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 349 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 350 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI: |
| 351 | BUG_ON(dsi_module != 1); |
| 352 | b = 1; |
| 353 | dsidev = dsi_get_dsidev_from_id(1); |
| 354 | dsi_wait_pll_hsdiv_dsi_active(dsidev); |
| 355 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 356 | default: |
| 357 | BUG(); |
| 358 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 359 | |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 360 | REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */ |
| 361 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 362 | dss.dsi_clk_source[dsi_module] = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 365 | void dss_select_lcd_clk_source(enum omap_channel channel, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 366 | enum omap_dss_clk_source clk_src) |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 367 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 368 | struct platform_device *dsidev; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 369 | int b, ix, pos; |
| 370 | |
| 371 | if (!dss_has_feature(FEAT_LCD_CLK_SRC)) |
| 372 | return; |
| 373 | |
| 374 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 375 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 376 | b = 0; |
| 377 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 378 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 379 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD); |
| 380 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 381 | dsidev = dsi_get_dsidev_from_id(0); |
| 382 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 383 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 384 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
| 385 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD2); |
| 386 | b = 1; |
| 387 | dsidev = dsi_get_dsidev_from_id(1); |
| 388 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
| 389 | break; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 390 | default: |
| 391 | BUG(); |
| 392 | } |
| 393 | |
| 394 | pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 12; |
| 395 | REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* LCDx_CLK_SWITCH */ |
| 396 | |
| 397 | ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 1; |
| 398 | dss.lcd_clk_source[ix] = clk_src; |
| 399 | } |
| 400 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 401 | enum omap_dss_clk_source dss_get_dispc_clk_source(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 402 | { |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 403 | return dss.dispc_clk_source; |
| 404 | } |
| 405 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 406 | enum omap_dss_clk_source dss_get_dsi_clk_source(int dsi_module) |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 407 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 408 | return dss.dsi_clk_source[dsi_module]; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 409 | } |
| 410 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 411 | enum omap_dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel) |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 412 | { |
Archit Taneja | 89976f2 | 2011-03-31 13:23:35 +0530 | [diff] [blame] | 413 | if (dss_has_feature(FEAT_LCD_CLK_SRC)) { |
| 414 | int ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 1; |
| 415 | return dss.lcd_clk_source[ix]; |
| 416 | } else { |
| 417 | /* LCD_CLK source is the same as DISPC_FCLK source for |
| 418 | * OMAP2 and OMAP3 */ |
| 419 | return dss.dispc_clk_source; |
| 420 | } |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 421 | } |
| 422 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 423 | /* calculate clock rates using dividers in cinfo */ |
| 424 | int dss_calc_clock_rates(struct dss_clock_info *cinfo) |
| 425 | { |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 426 | if (dss.dpll4_m4_ck) { |
| 427 | unsigned long prate; |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 428 | u16 fck_div_max = 16; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 429 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 430 | if (cpu_is_omap3630() || cpu_is_omap44xx()) |
| 431 | fck_div_max = 32; |
| 432 | |
| 433 | if (cinfo->fck_div > fck_div_max || cinfo->fck_div == 0) |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 434 | return -EINVAL; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 435 | |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 436 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 437 | |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 438 | cinfo->fck = prate / cinfo->fck_div; |
| 439 | } else { |
| 440 | if (cinfo->fck_div != 0) |
| 441 | return -EINVAL; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 442 | cinfo->fck = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 443 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | int dss_set_clock_div(struct dss_clock_info *cinfo) |
| 449 | { |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 450 | if (dss.dpll4_m4_ck) { |
| 451 | unsigned long prate; |
| 452 | int r; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 453 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 454 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); |
| 455 | DSSDBG("dpll4_m4 = %ld\n", prate); |
| 456 | |
| 457 | r = clk_set_rate(dss.dpll4_m4_ck, prate / cinfo->fck_div); |
| 458 | if (r) |
| 459 | return r; |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 460 | } else { |
| 461 | if (cinfo->fck_div != 0) |
| 462 | return -EINVAL; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | DSSDBG("fck = %ld (%d)\n", cinfo->fck, cinfo->fck_div); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | int dss_get_clock_div(struct dss_clock_info *cinfo) |
| 471 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 472 | cinfo->fck = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 473 | |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 474 | if (dss.dpll4_m4_ck) { |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 475 | unsigned long prate; |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 476 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 477 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 478 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 479 | if (cpu_is_omap3630() || cpu_is_omap44xx()) |
Kishore Y | ac01bb7 | 2010-04-25 16:27:19 +0530 | [diff] [blame] | 480 | cinfo->fck_div = prate / (cinfo->fck); |
| 481 | else |
| 482 | cinfo->fck_div = prate / (cinfo->fck / 2); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 483 | } else { |
| 484 | cinfo->fck_div = 0; |
| 485 | } |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | unsigned long dss_get_dpll4_rate(void) |
| 491 | { |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 492 | if (dss.dpll4_m4_ck) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 493 | return clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); |
| 494 | else |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | int dss_calc_clock_div(bool is_tft, unsigned long req_pck, |
| 499 | struct dss_clock_info *dss_cinfo, |
| 500 | struct dispc_clock_info *dispc_cinfo) |
| 501 | { |
| 502 | unsigned long prate; |
| 503 | struct dss_clock_info best_dss; |
| 504 | struct dispc_clock_info best_dispc; |
| 505 | |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 506 | unsigned long fck, max_dss_fck; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 507 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 508 | u16 fck_div, fck_div_max = 16; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 509 | |
| 510 | int match = 0; |
| 511 | int min_fck_per_pck; |
| 512 | |
| 513 | prate = dss_get_dpll4_rate(); |
| 514 | |
Taneja, Archit | 31ef823 | 2011-03-14 23:28:22 -0500 | [diff] [blame] | 515 | max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 516 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 517 | fck = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 518 | if (req_pck == dss.cache_req_pck && |
| 519 | ((cpu_is_omap34xx() && prate == dss.cache_prate) || |
| 520 | dss.cache_dss_cinfo.fck == fck)) { |
| 521 | DSSDBG("dispc clock info found from cache.\n"); |
| 522 | *dss_cinfo = dss.cache_dss_cinfo; |
| 523 | *dispc_cinfo = dss.cache_dispc_cinfo; |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK; |
| 528 | |
| 529 | if (min_fck_per_pck && |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 530 | req_pck * min_fck_per_pck > max_dss_fck) { |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 531 | DSSERR("Requested pixel clock not possible with the current " |
| 532 | "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning " |
| 533 | "the constraint off.\n"); |
| 534 | min_fck_per_pck = 0; |
| 535 | } |
| 536 | |
| 537 | retry: |
| 538 | memset(&best_dss, 0, sizeof(best_dss)); |
| 539 | memset(&best_dispc, 0, sizeof(best_dispc)); |
| 540 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 541 | if (dss.dpll4_m4_ck == NULL) { |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 542 | struct dispc_clock_info cur_dispc; |
| 543 | /* XXX can we change the clock on omap2? */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 544 | fck = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 545 | fck_div = 1; |
| 546 | |
| 547 | dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc); |
| 548 | match = 1; |
| 549 | |
| 550 | best_dss.fck = fck; |
| 551 | best_dss.fck_div = fck_div; |
| 552 | |
| 553 | best_dispc = cur_dispc; |
| 554 | |
| 555 | goto found; |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 556 | } else { |
| 557 | if (cpu_is_omap3630() || cpu_is_omap44xx()) |
| 558 | fck_div_max = 32; |
| 559 | |
| 560 | for (fck_div = fck_div_max; fck_div > 0; --fck_div) { |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 561 | struct dispc_clock_info cur_dispc; |
| 562 | |
Murthy, Raghuveer | 2de1108 | 2011-03-14 07:28:58 -0500 | [diff] [blame] | 563 | if (fck_div_max == 32) |
Kishore Y | ac01bb7 | 2010-04-25 16:27:19 +0530 | [diff] [blame] | 564 | fck = prate / fck_div; |
| 565 | else |
| 566 | fck = prate / fck_div * 2; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 567 | |
Archit Taneja | 819d807 | 2011-03-01 11:54:00 +0530 | [diff] [blame] | 568 | if (fck > max_dss_fck) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 569 | continue; |
| 570 | |
| 571 | if (min_fck_per_pck && |
| 572 | fck < req_pck * min_fck_per_pck) |
| 573 | continue; |
| 574 | |
| 575 | match = 1; |
| 576 | |
| 577 | dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc); |
| 578 | |
| 579 | if (abs(cur_dispc.pck - req_pck) < |
| 580 | abs(best_dispc.pck - req_pck)) { |
| 581 | |
| 582 | best_dss.fck = fck; |
| 583 | best_dss.fck_div = fck_div; |
| 584 | |
| 585 | best_dispc = cur_dispc; |
| 586 | |
| 587 | if (cur_dispc.pck == req_pck) |
| 588 | goto found; |
| 589 | } |
| 590 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | found: |
| 594 | if (!match) { |
| 595 | if (min_fck_per_pck) { |
| 596 | DSSERR("Could not find suitable clock settings.\n" |
| 597 | "Turning FCK/PCK constraint off and" |
| 598 | "trying again.\n"); |
| 599 | min_fck_per_pck = 0; |
| 600 | goto retry; |
| 601 | } |
| 602 | |
| 603 | DSSERR("Could not find suitable clock settings.\n"); |
| 604 | |
| 605 | return -EINVAL; |
| 606 | } |
| 607 | |
| 608 | if (dss_cinfo) |
| 609 | *dss_cinfo = best_dss; |
| 610 | if (dispc_cinfo) |
| 611 | *dispc_cinfo = best_dispc; |
| 612 | |
| 613 | dss.cache_req_pck = req_pck; |
| 614 | dss.cache_prate = prate; |
| 615 | dss.cache_dss_cinfo = best_dss; |
| 616 | dss.cache_dispc_cinfo = best_dispc; |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 621 | void dss_set_venc_output(enum omap_dss_venc_type type) |
| 622 | { |
| 623 | int l = 0; |
| 624 | |
| 625 | if (type == OMAP_DSS_VENC_TYPE_COMPOSITE) |
| 626 | l = 0; |
| 627 | else if (type == OMAP_DSS_VENC_TYPE_SVIDEO) |
| 628 | l = 1; |
| 629 | else |
| 630 | BUG(); |
| 631 | |
| 632 | /* venc out selection. 0 = comp, 1 = svideo */ |
| 633 | REG_FLD_MOD(DSS_CONTROL, l, 6, 6); |
| 634 | } |
| 635 | |
| 636 | void dss_set_dac_pwrdn_bgz(bool enable) |
| 637 | { |
| 638 | REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */ |
| 639 | } |
| 640 | |
Mythri P K | 7ed024a | 2011-03-09 16:31:38 +0530 | [diff] [blame] | 641 | void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select hdmi) |
| 642 | { |
| 643 | REG_FLD_MOD(DSS_CONTROL, hdmi, 15, 15); /* VENC_HDMI_SWITCH */ |
| 644 | } |
| 645 | |
Tomi Valkeinen | 4a61e26 | 2011-08-31 14:33:31 +0300 | [diff] [blame] | 646 | enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void) |
| 647 | { |
| 648 | enum omap_display_type displays; |
| 649 | |
| 650 | displays = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT); |
| 651 | if ((displays & OMAP_DISPLAY_TYPE_HDMI) == 0) |
| 652 | return DSS_VENC_TV_CLK; |
| 653 | |
| 654 | return REG_GET(DSS_CONTROL, 15, 15); |
| 655 | } |
| 656 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 657 | static int dss_get_clocks(void) |
| 658 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 659 | struct clk *clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 660 | int r; |
| 661 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 662 | clk = clk_get(&dss.pdev->dev, "fck"); |
| 663 | if (IS_ERR(clk)) { |
| 664 | DSSERR("can't get clock fck\n"); |
| 665 | r = PTR_ERR(clk); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 666 | goto err; |
Semwal, Sumit | a1a0dcc | 2011-03-01 02:42:14 -0600 | [diff] [blame] | 667 | } |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 668 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 669 | dss.dss_clk = clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 670 | |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 671 | if (cpu_is_omap34xx()) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 672 | clk = clk_get(NULL, "dpll4_m4_ck"); |
| 673 | if (IS_ERR(clk)) { |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 674 | DSSERR("Failed to get dpll4_m4_ck\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 675 | r = PTR_ERR(clk); |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 676 | goto err; |
| 677 | } |
| 678 | } else if (cpu_is_omap44xx()) { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 679 | clk = clk_get(NULL, "dpll_per_m5x2_ck"); |
| 680 | if (IS_ERR(clk)) { |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 681 | DSSERR("Failed to get dpll_per_m5x2_ck\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 682 | r = PTR_ERR(clk); |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 683 | goto err; |
| 684 | } |
| 685 | } else { /* omap24xx */ |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 686 | clk = NULL; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 687 | } |
| 688 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 689 | dss.dpll4_m4_ck = clk; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 690 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 691 | return 0; |
| 692 | |
| 693 | err: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 694 | if (dss.dss_clk) |
| 695 | clk_put(dss.dss_clk); |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 696 | if (dss.dpll4_m4_ck) |
| 697 | clk_put(dss.dpll4_m4_ck); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 698 | |
| 699 | return r; |
| 700 | } |
| 701 | |
| 702 | static void dss_put_clocks(void) |
| 703 | { |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 704 | if (dss.dpll4_m4_ck) |
| 705 | clk_put(dss.dpll4_m4_ck); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 706 | clk_put(dss.dss_clk); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 709 | int dss_runtime_get(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 710 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 711 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 712 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 713 | DSSDBG("dss_runtime_get\n"); |
| 714 | |
| 715 | r = pm_runtime_get_sync(&dss.pdev->dev); |
| 716 | WARN_ON(r < 0); |
| 717 | return r < 0 ? r : 0; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 720 | void dss_runtime_put(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 721 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 722 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 723 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 724 | DSSDBG("dss_runtime_put\n"); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 725 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 726 | r = pm_runtime_put_sync(&dss.pdev->dev); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 727 | WARN_ON(r < 0); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 730 | /* DEBUGFS */ |
| 731 | #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT) |
| 732 | void dss_debug_dump_clocks(struct seq_file *s) |
| 733 | { |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 734 | dss_dump_clocks(s); |
| 735 | dispc_dump_clocks(s); |
| 736 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 737 | dsi_dump_clocks(s); |
| 738 | #endif |
| 739 | } |
| 740 | #endif |
| 741 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 742 | /* DSS HW IP initialisation */ |
| 743 | static int omap_dsshw_probe(struct platform_device *pdev) |
| 744 | { |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 745 | struct resource *dss_mem; |
| 746 | u32 rev; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 747 | int r; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 748 | |
| 749 | dss.pdev = pdev; |
| 750 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 751 | dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0); |
| 752 | if (!dss_mem) { |
| 753 | DSSERR("can't get IORESOURCE_MEM DSS\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 754 | return -EINVAL; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 755 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 756 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 757 | dss.base = devm_ioremap(&pdev->dev, dss_mem->start, |
| 758 | resource_size(dss_mem)); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 759 | if (!dss.base) { |
| 760 | DSSERR("can't ioremap DSS\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 761 | return -ENOMEM; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 762 | } |
| 763 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 764 | r = dss_get_clocks(); |
| 765 | if (r) |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 766 | return r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 767 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 768 | pm_runtime_enable(&pdev->dev); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 769 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 770 | r = dss_runtime_get(); |
| 771 | if (r) |
| 772 | goto err_runtime_get; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 773 | |
| 774 | /* Select DPLL */ |
| 775 | REG_FLD_MOD(DSS_CONTROL, 0, 0, 0); |
| 776 | |
| 777 | #ifdef CONFIG_OMAP2_DSS_VENC |
| 778 | REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */ |
| 779 | REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */ |
| 780 | REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */ |
| 781 | #endif |
| 782 | dss.dsi_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 783 | dss.dsi_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
| 784 | dss.dispc_clk_source = OMAP_DSS_CLK_SRC_FCK; |
| 785 | dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 786 | dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 787 | |
Tomi Valkeinen | 587b5e8 | 2011-03-02 12:47:54 +0200 | [diff] [blame] | 788 | r = dpi_init(); |
| 789 | if (r) { |
| 790 | DSSERR("Failed to initialize DPI\n"); |
| 791 | goto err_dpi; |
| 792 | } |
| 793 | |
| 794 | r = sdi_init(); |
| 795 | if (r) { |
| 796 | DSSERR("Failed to initialize SDI\n"); |
| 797 | goto err_sdi; |
| 798 | } |
| 799 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 800 | rev = dss_read_reg(DSS_REVISION); |
| 801 | printk(KERN_INFO "OMAP DSS rev %d.%d\n", |
| 802 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 803 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 804 | dss_runtime_put(); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 805 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 806 | return 0; |
Tomi Valkeinen | 587b5e8 | 2011-03-02 12:47:54 +0200 | [diff] [blame] | 807 | err_sdi: |
| 808 | dpi_exit(); |
| 809 | err_dpi: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 810 | dss_runtime_put(); |
| 811 | err_runtime_get: |
| 812 | pm_runtime_disable(&pdev->dev); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 813 | dss_put_clocks(); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 814 | return r; |
| 815 | } |
| 816 | |
| 817 | static int omap_dsshw_remove(struct platform_device *pdev) |
| 818 | { |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 819 | dpi_exit(); |
| 820 | sdi_exit(); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 821 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 822 | pm_runtime_disable(&pdev->dev); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 823 | |
| 824 | dss_put_clocks(); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 825 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 826 | return 0; |
| 827 | } |
| 828 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 829 | static int dss_runtime_suspend(struct device *dev) |
| 830 | { |
| 831 | dss_save_context(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static int dss_runtime_resume(struct device *dev) |
| 836 | { |
Tomi Valkeinen | 3902071 | 2011-05-26 14:54:05 +0300 | [diff] [blame] | 837 | dss_restore_context(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static const struct dev_pm_ops dss_pm_ops = { |
| 842 | .runtime_suspend = dss_runtime_suspend, |
| 843 | .runtime_resume = dss_runtime_resume, |
| 844 | }; |
| 845 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 846 | static struct platform_driver omap_dsshw_driver = { |
| 847 | .probe = omap_dsshw_probe, |
| 848 | .remove = omap_dsshw_remove, |
| 849 | .driver = { |
| 850 | .name = "omapdss_dss", |
| 851 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 852 | .pm = &dss_pm_ops, |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 853 | }, |
| 854 | }; |
| 855 | |
| 856 | int dss_init_platform_driver(void) |
| 857 | { |
| 858 | return platform_driver_register(&omap_dsshw_driver); |
| 859 | } |
| 860 | |
| 861 | void dss_uninit_platform_driver(void) |
| 862 | { |
| 863 | return platform_driver_unregister(&omap_dsshw_driver); |
| 864 | } |