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> |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 26 | #include <linux/module.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 27 | #include <linux/io.h> |
Paul Gortmaker | a8a3593 | 2011-07-10 13:20:26 -0400 | [diff] [blame] | 28 | #include <linux/export.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 29 | #include <linux/err.h> |
| 30 | #include <linux/delay.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 31 | #include <linux/seq_file.h> |
| 32 | #include <linux/clk.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 34 | #include <linux/pm_runtime.h> |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 35 | #include <linux/gfp.h> |
Tomi Valkeinen | 33366d0 | 2012-09-28 13:54:35 +0300 | [diff] [blame] | 36 | #include <linux/sizes.h> |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 37 | #include <linux/of.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 38 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 39 | #include <video/omapdss.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 40 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 41 | #include "dss.h" |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 42 | #include "dss_features.h" |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 43 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 44 | #define DSS_SZ_REGS SZ_512 |
| 45 | |
| 46 | struct dss_reg { |
| 47 | u16 idx; |
| 48 | }; |
| 49 | |
| 50 | #define DSS_REG(idx) ((const struct dss_reg) { idx }) |
| 51 | |
| 52 | #define DSS_REVISION DSS_REG(0x0000) |
| 53 | #define DSS_SYSCONFIG DSS_REG(0x0010) |
| 54 | #define DSS_SYSSTATUS DSS_REG(0x0014) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 55 | #define DSS_CONTROL DSS_REG(0x0040) |
| 56 | #define DSS_SDI_CONTROL DSS_REG(0x0044) |
| 57 | #define DSS_PLL_CONTROL DSS_REG(0x0048) |
| 58 | #define DSS_SDI_STATUS DSS_REG(0x005C) |
| 59 | |
| 60 | #define REG_GET(idx, start, end) \ |
| 61 | FLD_GET(dss_read_reg(idx), start, end) |
| 62 | |
| 63 | #define REG_FLD_MOD(idx, val, start, end) \ |
| 64 | dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end)) |
| 65 | |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 66 | static int dss_runtime_get(void); |
| 67 | static void dss_runtime_put(void); |
| 68 | |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 69 | struct dss_features { |
| 70 | u8 fck_div_max; |
| 71 | u8 dss_fck_multiplier; |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 72 | const char *parent_clk_name; |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 73 | int (*dpi_select_source)(enum omap_channel channel); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 74 | }; |
| 75 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 76 | static struct { |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 77 | struct platform_device *pdev; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 78 | void __iomem *base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 79 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 80 | struct clk *parent_clk; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 81 | struct clk *dss_clk; |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 82 | unsigned long dss_clk_rate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 83 | |
| 84 | unsigned long cache_req_pck; |
| 85 | unsigned long cache_prate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 86 | struct dispc_clock_info cache_dispc_cinfo; |
| 87 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 88 | enum omap_dss_clk_source dsi_clk_source[MAX_NUM_DSI]; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 89 | enum omap_dss_clk_source dispc_clk_source; |
| 90 | enum omap_dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS]; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 91 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 92 | bool ctx_valid; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 93 | u32 ctx[DSS_SZ_REGS / sizeof(u32)]; |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 94 | |
| 95 | const struct dss_features *feat; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 96 | } dss; |
| 97 | |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 98 | static const char * const dss_generic_clk_source_names[] = { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 99 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI_PLL_HSDIV_DISPC", |
| 100 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI_PLL_HSDIV_DSI", |
| 101 | [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCK", |
Tomi Valkeinen | 901e5fe | 2011-11-30 17:34:52 +0200 | [diff] [blame] | 102 | [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC] = "DSI_PLL2_HSDIV_DISPC", |
| 103 | [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI] = "DSI_PLL2_HSDIV_DSI", |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 104 | }; |
| 105 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 106 | static inline void dss_write_reg(const struct dss_reg idx, u32 val) |
| 107 | { |
| 108 | __raw_writel(val, dss.base + idx.idx); |
| 109 | } |
| 110 | |
| 111 | static inline u32 dss_read_reg(const struct dss_reg idx) |
| 112 | { |
| 113 | return __raw_readl(dss.base + idx.idx); |
| 114 | } |
| 115 | |
| 116 | #define SR(reg) \ |
| 117 | dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg) |
| 118 | #define RR(reg) \ |
| 119 | dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)]) |
| 120 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 121 | static void dss_save_context(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 122 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 123 | DSSDBG("dss_save_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 124 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 125 | SR(CONTROL); |
| 126 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 127 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 128 | OMAP_DISPLAY_TYPE_SDI) { |
| 129 | SR(SDI_CONTROL); |
| 130 | SR(PLL_CONTROL); |
| 131 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 132 | |
| 133 | dss.ctx_valid = true; |
| 134 | |
| 135 | DSSDBG("context saved\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 138 | static void dss_restore_context(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 139 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 140 | DSSDBG("dss_restore_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 141 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 142 | if (!dss.ctx_valid) |
| 143 | return; |
| 144 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 145 | RR(CONTROL); |
| 146 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 147 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 148 | OMAP_DISPLAY_TYPE_SDI) { |
| 149 | RR(SDI_CONTROL); |
| 150 | RR(PLL_CONTROL); |
| 151 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 152 | |
| 153 | DSSDBG("context restored\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | #undef SR |
| 157 | #undef RR |
| 158 | |
Archit Taneja | 889b4fd | 2012-07-20 17:18:49 +0530 | [diff] [blame] | 159 | void dss_sdi_init(int datapairs) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 160 | { |
| 161 | u32 l; |
| 162 | |
| 163 | BUG_ON(datapairs > 3 || datapairs < 1); |
| 164 | |
| 165 | l = dss_read_reg(DSS_SDI_CONTROL); |
| 166 | l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */ |
| 167 | l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */ |
| 168 | l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */ |
| 169 | dss_write_reg(DSS_SDI_CONTROL, l); |
| 170 | |
| 171 | l = dss_read_reg(DSS_PLL_CONTROL); |
| 172 | l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */ |
| 173 | l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */ |
| 174 | l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */ |
| 175 | dss_write_reg(DSS_PLL_CONTROL, l); |
| 176 | } |
| 177 | |
| 178 | int dss_sdi_enable(void) |
| 179 | { |
| 180 | unsigned long timeout; |
| 181 | |
| 182 | dispc_pck_free_enable(1); |
| 183 | |
| 184 | /* Reset SDI PLL */ |
| 185 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */ |
| 186 | udelay(1); /* wait 2x PCLK */ |
| 187 | |
| 188 | /* Lock SDI PLL */ |
| 189 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */ |
| 190 | |
| 191 | /* Waiting for PLL lock request to complete */ |
| 192 | timeout = jiffies + msecs_to_jiffies(500); |
| 193 | while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) { |
| 194 | if (time_after_eq(jiffies, timeout)) { |
| 195 | DSSERR("PLL lock request timed out\n"); |
| 196 | goto err1; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /* Clearing PLL_GO bit */ |
| 201 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28); |
| 202 | |
| 203 | /* Waiting for PLL to lock */ |
| 204 | timeout = jiffies + msecs_to_jiffies(500); |
| 205 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) { |
| 206 | if (time_after_eq(jiffies, timeout)) { |
| 207 | DSSERR("PLL lock timed out\n"); |
| 208 | goto err1; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | dispc_lcd_enable_signal(1); |
| 213 | |
| 214 | /* Waiting for SDI reset to complete */ |
| 215 | timeout = jiffies + msecs_to_jiffies(500); |
| 216 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) { |
| 217 | if (time_after_eq(jiffies, timeout)) { |
| 218 | DSSERR("SDI reset timed out\n"); |
| 219 | goto err2; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return 0; |
| 224 | |
| 225 | err2: |
| 226 | dispc_lcd_enable_signal(0); |
| 227 | err1: |
| 228 | /* Reset SDI PLL */ |
| 229 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 230 | |
| 231 | dispc_pck_free_enable(0); |
| 232 | |
| 233 | return -ETIMEDOUT; |
| 234 | } |
| 235 | |
| 236 | void dss_sdi_disable(void) |
| 237 | { |
| 238 | dispc_lcd_enable_signal(0); |
| 239 | |
| 240 | dispc_pck_free_enable(0); |
| 241 | |
| 242 | /* Reset SDI PLL */ |
| 243 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 244 | } |
| 245 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 246 | 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] | 247 | { |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 248 | return dss_generic_clk_source_names[clk_src]; |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 249 | } |
| 250 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 251 | void dss_dump_clocks(struct seq_file *s) |
| 252 | { |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 253 | const char *fclk_name, *fclk_real_name; |
| 254 | unsigned long fclk_rate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 255 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 256 | if (dss_runtime_get()) |
| 257 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 258 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 259 | seq_printf(s, "- DSS -\n"); |
| 260 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 261 | fclk_name = dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK); |
| 262 | 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] | 263 | fclk_rate = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 264 | |
Tomi Valkeinen | 9c15d76 | 2013-11-01 11:36:10 +0200 | [diff] [blame] | 265 | seq_printf(s, "%s (%s) = %lu\n", |
| 266 | fclk_name, fclk_real_name, |
| 267 | fclk_rate); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 268 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 269 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 272 | static void dss_dump_regs(struct seq_file *s) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 273 | { |
| 274 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r)) |
| 275 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 276 | if (dss_runtime_get()) |
| 277 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 278 | |
| 279 | DUMPREG(DSS_REVISION); |
| 280 | DUMPREG(DSS_SYSCONFIG); |
| 281 | DUMPREG(DSS_SYSSTATUS); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 282 | DUMPREG(DSS_CONTROL); |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 283 | |
| 284 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 285 | OMAP_DISPLAY_TYPE_SDI) { |
| 286 | DUMPREG(DSS_SDI_CONTROL); |
| 287 | DUMPREG(DSS_PLL_CONTROL); |
| 288 | DUMPREG(DSS_SDI_STATUS); |
| 289 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 290 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 291 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 292 | #undef DUMPREG |
| 293 | } |
| 294 | |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 295 | static 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] | 296 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 297 | struct platform_device *dsidev; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 298 | int b; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 299 | u8 start, end; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 300 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 301 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 302 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 303 | b = 0; |
| 304 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 305 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 306 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 307 | dsidev = dsi_get_dsidev_from_id(0); |
| 308 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 309 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 310 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
| 311 | b = 2; |
| 312 | dsidev = dsi_get_dsidev_from_id(1); |
| 313 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
| 314 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 315 | default: |
| 316 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 317 | return; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 318 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 319 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 320 | dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end); |
| 321 | |
| 322 | REG_FLD_MOD(DSS_CONTROL, b, start, end); /* DISPC_CLK_SWITCH */ |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 323 | |
| 324 | dss.dispc_clk_source = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 327 | void dss_select_dsi_clk_source(int dsi_module, |
| 328 | enum omap_dss_clk_source clk_src) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 329 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 330 | struct platform_device *dsidev; |
Archit Taneja | a2e5d82 | 2012-05-07 16:51:35 +0530 | [diff] [blame] | 331 | int b, pos; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 332 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 333 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 334 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 335 | b = 0; |
| 336 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 337 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI: |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 338 | BUG_ON(dsi_module != 0); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 339 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 340 | dsidev = dsi_get_dsidev_from_id(0); |
| 341 | dsi_wait_pll_hsdiv_dsi_active(dsidev); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 342 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 343 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI: |
| 344 | BUG_ON(dsi_module != 1); |
| 345 | b = 1; |
| 346 | dsidev = dsi_get_dsidev_from_id(1); |
| 347 | dsi_wait_pll_hsdiv_dsi_active(dsidev); |
| 348 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 349 | default: |
| 350 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 351 | return; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 352 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 353 | |
Archit Taneja | a2e5d82 | 2012-05-07 16:51:35 +0530 | [diff] [blame] | 354 | pos = dsi_module == 0 ? 1 : 10; |
| 355 | REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */ |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 356 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 357 | dss.dsi_clk_source[dsi_module] = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 360 | void dss_select_lcd_clk_source(enum omap_channel channel, |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 361 | enum omap_dss_clk_source clk_src) |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 362 | { |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 363 | struct platform_device *dsidev; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 364 | int b, ix, pos; |
| 365 | |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 366 | if (!dss_has_feature(FEAT_LCD_CLK_SRC)) { |
| 367 | dss_select_dispc_clk_source(clk_src); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 368 | return; |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 369 | } |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 370 | |
| 371 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 372 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 373 | b = 0; |
| 374 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 375 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 376 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD); |
| 377 | b = 1; |
Archit Taneja | a72b64b | 2011-05-12 17:26:26 +0530 | [diff] [blame] | 378 | dsidev = dsi_get_dsidev_from_id(0); |
| 379 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 380 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 381 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 382 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD2 && |
| 383 | channel != OMAP_DSS_CHANNEL_LCD3); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 384 | b = 1; |
| 385 | dsidev = dsi_get_dsidev_from_id(1); |
| 386 | dsi_wait_pll_hsdiv_dispc_active(dsidev); |
| 387 | break; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 388 | default: |
| 389 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 390 | return; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 391 | } |
| 392 | |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 393 | pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 394 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 12 : 19); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 395 | REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* LCDx_CLK_SWITCH */ |
| 396 | |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 397 | ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 398 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 399 | dss.lcd_clk_source[ix] = clk_src; |
| 400 | } |
| 401 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 402 | enum omap_dss_clk_source dss_get_dispc_clk_source(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 403 | { |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 404 | return dss.dispc_clk_source; |
| 405 | } |
| 406 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 407 | 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] | 408 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 409 | return dss.dsi_clk_source[dsi_module]; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 412 | 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] | 413 | { |
Archit Taneja | 89976f2 | 2011-03-31 13:23:35 +0530 | [diff] [blame] | 414 | if (dss_has_feature(FEAT_LCD_CLK_SRC)) { |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 415 | int ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 416 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2); |
Archit Taneja | 89976f2 | 2011-03-31 13:23:35 +0530 | [diff] [blame] | 417 | return dss.lcd_clk_source[ix]; |
| 418 | } else { |
| 419 | /* LCD_CLK source is the same as DISPC_FCLK source for |
| 420 | * OMAP2 and OMAP3 */ |
| 421 | return dss.dispc_clk_source; |
| 422 | } |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 423 | } |
| 424 | |
Tomi Valkeinen | 688af02 | 2013-10-31 16:41:57 +0200 | [diff] [blame] | 425 | bool dss_div_calc(unsigned long pck, unsigned long fck_min, |
| 426 | dss_div_calc_func func, void *data) |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 427 | { |
| 428 | int fckd, fckd_start, fckd_stop; |
| 429 | unsigned long fck; |
| 430 | unsigned long fck_hw_max; |
| 431 | unsigned long fckd_hw_max; |
| 432 | unsigned long prate; |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 433 | unsigned m; |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 434 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 435 | fck_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 436 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 437 | if (dss.parent_clk == NULL) { |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 438 | unsigned pckd; |
| 439 | |
| 440 | pckd = fck_hw_max / pck; |
| 441 | |
| 442 | fck = pck * pckd; |
| 443 | |
| 444 | fck = clk_round_rate(dss.dss_clk, fck); |
| 445 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 446 | return func(fck, data); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 447 | } |
| 448 | |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 449 | fckd_hw_max = dss.feat->fck_div_max; |
| 450 | |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 451 | m = dss.feat->dss_fck_multiplier; |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 452 | prate = clk_get_rate(dss.parent_clk); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 453 | |
| 454 | fck_min = fck_min ? fck_min : 1; |
| 455 | |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 456 | fckd_start = min(prate * m / fck_min, fckd_hw_max); |
| 457 | fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 458 | |
| 459 | for (fckd = fckd_start; fckd >= fckd_stop; --fckd) { |
Tomi Valkeinen | d0e224f | 2014-02-13 11:36:22 +0200 | [diff] [blame] | 460 | fck = DIV_ROUND_UP(prate, fckd) * m; |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 461 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 462 | if (func(fck, data)) |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 463 | return true; |
| 464 | } |
| 465 | |
| 466 | return false; |
| 467 | } |
| 468 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 469 | int dss_set_fck_rate(unsigned long rate) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 470 | { |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 471 | int r; |
| 472 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 473 | DSSDBG("set fck to %lu\n", rate); |
| 474 | |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 475 | r = clk_set_rate(dss.dss_clk, rate); |
| 476 | if (r) |
| 477 | return r; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 478 | |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 479 | dss.dss_clk_rate = clk_get_rate(dss.dss_clk); |
| 480 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 481 | WARN_ONCE(dss.dss_clk_rate != rate, |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 482 | "clk rate mismatch: %lu != %lu", dss.dss_clk_rate, |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 483 | rate); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 488 | unsigned long dss_get_dispc_clk_rate(void) |
| 489 | { |
| 490 | return dss.dss_clk_rate; |
| 491 | } |
| 492 | |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 493 | static int dss_setup_default_clock(void) |
| 494 | { |
| 495 | unsigned long max_dss_fck, prate; |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 496 | unsigned long fck; |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 497 | unsigned fck_div; |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 498 | int r; |
| 499 | |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 500 | max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 501 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 502 | if (dss.parent_clk == NULL) { |
| 503 | fck = clk_round_rate(dss.dss_clk, max_dss_fck); |
| 504 | } else { |
| 505 | prate = clk_get_rate(dss.parent_clk); |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 506 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 507 | fck_div = DIV_ROUND_UP(prate * dss.feat->dss_fck_multiplier, |
| 508 | max_dss_fck); |
Tomi Valkeinen | d0e224f | 2014-02-13 11:36:22 +0200 | [diff] [blame] | 509 | fck = DIV_ROUND_UP(prate, fck_div) * dss.feat->dss_fck_multiplier; |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 510 | } |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 511 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 512 | r = dss_set_fck_rate(fck); |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 513 | if (r) |
| 514 | return r; |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 519 | void dss_set_venc_output(enum omap_dss_venc_type type) |
| 520 | { |
| 521 | int l = 0; |
| 522 | |
| 523 | if (type == OMAP_DSS_VENC_TYPE_COMPOSITE) |
| 524 | l = 0; |
| 525 | else if (type == OMAP_DSS_VENC_TYPE_SVIDEO) |
| 526 | l = 1; |
| 527 | else |
| 528 | BUG(); |
| 529 | |
| 530 | /* venc out selection. 0 = comp, 1 = svideo */ |
| 531 | REG_FLD_MOD(DSS_CONTROL, l, 6, 6); |
| 532 | } |
| 533 | |
| 534 | void dss_set_dac_pwrdn_bgz(bool enable) |
| 535 | { |
| 536 | REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */ |
| 537 | } |
| 538 | |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 539 | void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select src) |
Mythri P K | 7ed024a | 2011-03-09 16:31:38 +0530 | [diff] [blame] | 540 | { |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 541 | enum omap_display_type dp; |
| 542 | dp = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT); |
| 543 | |
| 544 | /* Complain about invalid selections */ |
| 545 | WARN_ON((src == DSS_VENC_TV_CLK) && !(dp & OMAP_DISPLAY_TYPE_VENC)); |
| 546 | WARN_ON((src == DSS_HDMI_M_PCLK) && !(dp & OMAP_DISPLAY_TYPE_HDMI)); |
| 547 | |
| 548 | /* Select only if we have options */ |
| 549 | if ((dp & OMAP_DISPLAY_TYPE_VENC) && (dp & OMAP_DISPLAY_TYPE_HDMI)) |
| 550 | REG_FLD_MOD(DSS_CONTROL, src, 15, 15); /* VENC_HDMI_SWITCH */ |
Mythri P K | 7ed024a | 2011-03-09 16:31:38 +0530 | [diff] [blame] | 551 | } |
| 552 | |
Tomi Valkeinen | 4a61e26 | 2011-08-31 14:33:31 +0300 | [diff] [blame] | 553 | enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void) |
| 554 | { |
| 555 | enum omap_display_type displays; |
| 556 | |
| 557 | displays = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT); |
| 558 | if ((displays & OMAP_DISPLAY_TYPE_HDMI) == 0) |
| 559 | return DSS_VENC_TV_CLK; |
| 560 | |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 561 | if ((displays & OMAP_DISPLAY_TYPE_VENC) == 0) |
| 562 | return DSS_HDMI_M_PCLK; |
| 563 | |
Tomi Valkeinen | 4a61e26 | 2011-08-31 14:33:31 +0300 | [diff] [blame] | 564 | return REG_GET(DSS_CONTROL, 15, 15); |
| 565 | } |
| 566 | |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 567 | static int dss_dpi_select_source_omap2_omap3(enum omap_channel channel) |
| 568 | { |
| 569 | if (channel != OMAP_DSS_CHANNEL_LCD) |
| 570 | return -EINVAL; |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int dss_dpi_select_source_omap4(enum omap_channel channel) |
| 576 | { |
| 577 | int val; |
| 578 | |
| 579 | switch (channel) { |
| 580 | case OMAP_DSS_CHANNEL_LCD2: |
| 581 | val = 0; |
| 582 | break; |
| 583 | case OMAP_DSS_CHANNEL_DIGIT: |
| 584 | val = 1; |
| 585 | break; |
| 586 | default: |
| 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | REG_FLD_MOD(DSS_CONTROL, val, 17, 17); |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int dss_dpi_select_source_omap5(enum omap_channel channel) |
| 596 | { |
| 597 | int val; |
| 598 | |
| 599 | switch (channel) { |
| 600 | case OMAP_DSS_CHANNEL_LCD: |
| 601 | val = 1; |
| 602 | break; |
| 603 | case OMAP_DSS_CHANNEL_LCD2: |
| 604 | val = 2; |
| 605 | break; |
| 606 | case OMAP_DSS_CHANNEL_LCD3: |
| 607 | val = 3; |
| 608 | break; |
| 609 | case OMAP_DSS_CHANNEL_DIGIT: |
| 610 | val = 0; |
| 611 | break; |
| 612 | default: |
| 613 | return -EINVAL; |
| 614 | } |
| 615 | |
| 616 | REG_FLD_MOD(DSS_CONTROL, val, 17, 16); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | int dss_dpi_select_source(enum omap_channel channel) |
| 622 | { |
| 623 | return dss.feat->dpi_select_source(channel); |
| 624 | } |
| 625 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 626 | static int dss_get_clocks(void) |
| 627 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 628 | struct clk *clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 629 | |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 630 | clk = devm_clk_get(&dss.pdev->dev, "fck"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 631 | if (IS_ERR(clk)) { |
| 632 | DSSERR("can't get clock fck\n"); |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 633 | return PTR_ERR(clk); |
Semwal, Sumit | a1a0dcc | 2011-03-01 02:42:14 -0600 | [diff] [blame] | 634 | } |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 635 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 636 | dss.dss_clk = clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 637 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 638 | if (dss.feat->parent_clk_name) { |
| 639 | clk = clk_get(NULL, dss.feat->parent_clk_name); |
Aaro Koskinen | 8ad9375 | 2012-11-21 21:48:51 +0200 | [diff] [blame] | 640 | if (IS_ERR(clk)) { |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 641 | DSSERR("Failed to get %s\n", dss.feat->parent_clk_name); |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 642 | return PTR_ERR(clk); |
Aaro Koskinen | 8ad9375 | 2012-11-21 21:48:51 +0200 | [diff] [blame] | 643 | } |
| 644 | } else { |
| 645 | clk = NULL; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 646 | } |
| 647 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 648 | dss.parent_clk = clk; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 649 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 650 | return 0; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void dss_put_clocks(void) |
| 654 | { |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 655 | if (dss.parent_clk) |
| 656 | clk_put(dss.parent_clk); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 659 | static int dss_runtime_get(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 660 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 661 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 662 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 663 | DSSDBG("dss_runtime_get\n"); |
| 664 | |
| 665 | r = pm_runtime_get_sync(&dss.pdev->dev); |
| 666 | WARN_ON(r < 0); |
| 667 | return r < 0 ? r : 0; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 670 | static void dss_runtime_put(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 671 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 672 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 673 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 674 | DSSDBG("dss_runtime_put\n"); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 675 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 676 | r = pm_runtime_put_sync(&dss.pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 677 | WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 680 | /* DEBUGFS */ |
Chandrabhanu Mahapatra | 1b3bcb3 | 2012-09-29 11:25:42 +0530 | [diff] [blame] | 681 | #if defined(CONFIG_OMAP2_DSS_DEBUGFS) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 682 | void dss_debug_dump_clocks(struct seq_file *s) |
| 683 | { |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 684 | dss_dump_clocks(s); |
| 685 | dispc_dump_clocks(s); |
| 686 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 687 | dsi_dump_clocks(s); |
| 688 | #endif |
| 689 | } |
| 690 | #endif |
| 691 | |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 692 | static const struct dss_features omap24xx_dss_feats __initconst = { |
Tomi Valkeinen | 6e555e2 | 2013-11-01 11:26:43 +0200 | [diff] [blame] | 693 | /* |
| 694 | * fck div max is really 16, but the divider range has gaps. The range |
| 695 | * from 1 to 6 has no gaps, so let's use that as a max. |
| 696 | */ |
| 697 | .fck_div_max = 6, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 698 | .dss_fck_multiplier = 2, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 699 | .parent_clk_name = "core_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 700 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | static const struct dss_features omap34xx_dss_feats __initconst = { |
| 704 | .fck_div_max = 16, |
| 705 | .dss_fck_multiplier = 2, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 706 | .parent_clk_name = "dpll4_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 707 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | static const struct dss_features omap3630_dss_feats __initconst = { |
| 711 | .fck_div_max = 32, |
| 712 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 713 | .parent_clk_name = "dpll4_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 714 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 715 | }; |
| 716 | |
| 717 | static const struct dss_features omap44xx_dss_feats __initconst = { |
| 718 | .fck_div_max = 32, |
| 719 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 720 | .parent_clk_name = "dpll_per_x2_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 721 | .dpi_select_source = &dss_dpi_select_source_omap4, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 722 | }; |
| 723 | |
| 724 | static const struct dss_features omap54xx_dss_feats __initconst = { |
| 725 | .fck_div_max = 64, |
| 726 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 727 | .parent_clk_name = "dpll_per_x2_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 728 | .dpi_select_source = &dss_dpi_select_source_omap5, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 729 | }; |
| 730 | |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 731 | static int __init dss_init_features(struct platform_device *pdev) |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 732 | { |
| 733 | const struct dss_features *src; |
| 734 | struct dss_features *dst; |
| 735 | |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 736 | dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 737 | if (!dst) { |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 738 | dev_err(&pdev->dev, "Failed to allocate local DSS Features\n"); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 739 | return -ENOMEM; |
| 740 | } |
| 741 | |
Tomi Valkeinen | b2c7d54 | 2012-10-18 13:46:29 +0300 | [diff] [blame] | 742 | switch (omapdss_get_version()) { |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 743 | case OMAPDSS_VER_OMAP24xx: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 744 | src = &omap24xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 745 | break; |
| 746 | |
| 747 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 748 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 749 | case OMAPDSS_VER_AM35xx: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 750 | src = &omap34xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case OMAPDSS_VER_OMAP3630: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 754 | src = &omap3630_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case OMAPDSS_VER_OMAP4430_ES1: |
| 758 | case OMAPDSS_VER_OMAP4430_ES2: |
| 759 | case OMAPDSS_VER_OMAP4: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 760 | src = &omap44xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case OMAPDSS_VER_OMAP5: |
Archit Taneja | 2336283 | 2012-04-08 16:47:01 +0530 | [diff] [blame] | 764 | src = &omap54xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | default: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 768 | return -ENODEV; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 769 | } |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 770 | |
| 771 | memcpy(dst, src, sizeof(*dst)); |
| 772 | dss.feat = dst; |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
Tomi Valkeinen | 5f0bc7a | 2014-03-20 11:55:02 +0200 | [diff] [blame] | 777 | static int __init dss_init_ports(struct platform_device *pdev) |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 778 | { |
| 779 | struct device_node *parent = pdev->dev.of_node; |
| 780 | struct device_node *port; |
| 781 | int r; |
| 782 | |
| 783 | if (parent == NULL) |
| 784 | return 0; |
| 785 | |
| 786 | port = omapdss_of_get_next_port(parent, NULL); |
| 787 | if (!port) { |
| 788 | #ifdef CONFIG_OMAP2_DSS_DPI |
| 789 | dpi_init_port(pdev, parent); |
| 790 | #endif |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | do { |
| 795 | u32 reg; |
| 796 | |
| 797 | r = of_property_read_u32(port, "reg", ®); |
| 798 | if (r) |
| 799 | reg = 0; |
| 800 | |
| 801 | #ifdef CONFIG_OMAP2_DSS_DPI |
| 802 | if (reg == 0) |
| 803 | dpi_init_port(pdev, port); |
| 804 | #endif |
| 805 | |
| 806 | #ifdef CONFIG_OMAP2_DSS_SDI |
| 807 | if (reg == 1) |
| 808 | sdi_init_port(pdev, port); |
| 809 | #endif |
| 810 | |
| 811 | } while ((port = omapdss_of_get_next_port(parent, port)) != NULL); |
| 812 | |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static void dss_uninit_ports(void) |
| 817 | { |
| 818 | #ifdef CONFIG_OMAP2_DSS_DPI |
| 819 | dpi_uninit_port(); |
| 820 | #endif |
| 821 | |
| 822 | #ifdef CONFIG_OMAP2_DSS_SDI |
| 823 | sdi_uninit_port(); |
| 824 | #endif |
| 825 | } |
| 826 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 827 | /* DSS HW IP initialisation */ |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 828 | static int __init omap_dsshw_probe(struct platform_device *pdev) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 829 | { |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 830 | struct resource *dss_mem; |
| 831 | u32 rev; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 832 | int r; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 833 | |
| 834 | dss.pdev = pdev; |
| 835 | |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 836 | r = dss_init_features(dss.pdev); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 837 | if (r) |
| 838 | return r; |
| 839 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 840 | dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0); |
| 841 | if (!dss_mem) { |
| 842 | DSSERR("can't get IORESOURCE_MEM DSS\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 843 | return -EINVAL; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 844 | } |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 845 | |
Julia Lawall | 6e2a14d | 2012-01-24 14:00:45 +0100 | [diff] [blame] | 846 | dss.base = devm_ioremap(&pdev->dev, dss_mem->start, |
| 847 | resource_size(dss_mem)); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 848 | if (!dss.base) { |
| 849 | DSSERR("can't ioremap DSS\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 850 | return -ENOMEM; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 851 | } |
| 852 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 853 | r = dss_get_clocks(); |
| 854 | if (r) |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 855 | return r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 856 | |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 857 | r = dss_setup_default_clock(); |
| 858 | if (r) |
| 859 | goto err_setup_clocks; |
| 860 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 861 | pm_runtime_enable(&pdev->dev); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 862 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 863 | r = dss_runtime_get(); |
| 864 | if (r) |
| 865 | goto err_runtime_get; |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 866 | |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 867 | dss.dss_clk_rate = clk_get_rate(dss.dss_clk); |
| 868 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 869 | /* Select DPLL */ |
| 870 | REG_FLD_MOD(DSS_CONTROL, 0, 0, 0); |
| 871 | |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 872 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
| 873 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 874 | #ifdef CONFIG_OMAP2_DSS_VENC |
| 875 | REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */ |
| 876 | REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */ |
| 877 | REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */ |
| 878 | #endif |
| 879 | dss.dsi_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 880 | dss.dsi_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
| 881 | dss.dispc_clk_source = OMAP_DSS_CLK_SRC_FCK; |
| 882 | dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 883 | dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 884 | |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 885 | dss_init_ports(pdev); |
| 886 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 887 | rev = dss_read_reg(DSS_REVISION); |
| 888 | printk(KERN_INFO "OMAP DSS rev %d.%d\n", |
| 889 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 890 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 891 | dss_runtime_put(); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 892 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 893 | dss_debugfs_create_file("dss", dss_dump_regs); |
| 894 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 895 | return 0; |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 896 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 897 | err_runtime_get: |
| 898 | pm_runtime_disable(&pdev->dev); |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 899 | err_setup_clocks: |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 900 | dss_put_clocks(); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 901 | return r; |
| 902 | } |
| 903 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 904 | static int __exit omap_dsshw_remove(struct platform_device *pdev) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 905 | { |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 906 | dss_uninit_ports(); |
| 907 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 908 | pm_runtime_disable(&pdev->dev); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 909 | |
| 910 | dss_put_clocks(); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 911 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 912 | return 0; |
| 913 | } |
| 914 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 915 | static int dss_runtime_suspend(struct device *dev) |
| 916 | { |
| 917 | dss_save_context(); |
Tomi Valkeinen | a8081d3 | 2012-03-08 12:52:38 +0200 | [diff] [blame] | 918 | dss_set_min_bus_tput(dev, 0); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | static int dss_runtime_resume(struct device *dev) |
| 923 | { |
Tomi Valkeinen | a8081d3 | 2012-03-08 12:52:38 +0200 | [diff] [blame] | 924 | int r; |
| 925 | /* |
| 926 | * Set an arbitrarily high tput request to ensure OPP100. |
| 927 | * What we should really do is to make a request to stay in OPP100, |
| 928 | * without any tput requirements, but that is not currently possible |
| 929 | * via the PM layer. |
| 930 | */ |
| 931 | |
| 932 | r = dss_set_min_bus_tput(dev, 1000000000); |
| 933 | if (r) |
| 934 | return r; |
| 935 | |
Tomi Valkeinen | 3902071 | 2011-05-26 14:54:05 +0300 | [diff] [blame] | 936 | dss_restore_context(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | static const struct dev_pm_ops dss_pm_ops = { |
| 941 | .runtime_suspend = dss_runtime_suspend, |
| 942 | .runtime_resume = dss_runtime_resume, |
| 943 | }; |
| 944 | |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 945 | static const struct of_device_id dss_of_match[] = { |
| 946 | { .compatible = "ti,omap2-dss", }, |
| 947 | { .compatible = "ti,omap3-dss", }, |
| 948 | { .compatible = "ti,omap4-dss", }, |
| 949 | {}, |
| 950 | }; |
| 951 | |
| 952 | MODULE_DEVICE_TABLE(of, dss_of_match); |
| 953 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 954 | static struct platform_driver omap_dsshw_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 955 | .remove = __exit_p(omap_dsshw_remove), |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 956 | .driver = { |
| 957 | .name = "omapdss_dss", |
| 958 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 959 | .pm = &dss_pm_ops, |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 960 | .of_match_table = dss_of_match, |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 961 | }, |
| 962 | }; |
| 963 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 964 | int __init dss_init_platform_driver(void) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 965 | { |
Tomi Valkeinen | 11436e1 | 2012-03-07 12:53:18 +0200 | [diff] [blame] | 966 | return platform_driver_probe(&omap_dsshw_driver, omap_dsshw_probe); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void dss_uninit_platform_driver(void) |
| 970 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 971 | platform_driver_unregister(&omap_dsshw_driver); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 972 | } |