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 | be40eec | 2014-07-04 13:37:15 +0530 | [diff] [blame] | 37 | #include <linux/mfd/syscon.h> |
| 38 | #include <linux/regmap.h> |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 39 | #include <linux/of.h> |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 40 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | cb17a4a | 2015-02-25 12:08:14 +0200 | [diff] [blame] | 41 | #include <linux/suspend.h> |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 42 | #include <linux/component.h> |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 43 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 44 | #include <video/omapdss.h> |
Tony Lindgren | 2c799ce | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 45 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 46 | #include "dss.h" |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 47 | #include "dss_features.h" |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 48 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 49 | #define DSS_SZ_REGS SZ_512 |
| 50 | |
| 51 | struct dss_reg { |
| 52 | u16 idx; |
| 53 | }; |
| 54 | |
| 55 | #define DSS_REG(idx) ((const struct dss_reg) { idx }) |
| 56 | |
| 57 | #define DSS_REVISION DSS_REG(0x0000) |
| 58 | #define DSS_SYSCONFIG DSS_REG(0x0010) |
| 59 | #define DSS_SYSSTATUS DSS_REG(0x0014) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 60 | #define DSS_CONTROL DSS_REG(0x0040) |
| 61 | #define DSS_SDI_CONTROL DSS_REG(0x0044) |
| 62 | #define DSS_PLL_CONTROL DSS_REG(0x0048) |
| 63 | #define DSS_SDI_STATUS DSS_REG(0x005C) |
| 64 | |
| 65 | #define REG_GET(idx, start, end) \ |
| 66 | FLD_GET(dss_read_reg(idx), start, end) |
| 67 | |
| 68 | #define REG_FLD_MOD(idx, val, start, end) \ |
| 69 | dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end)) |
| 70 | |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 71 | struct dss_features { |
| 72 | u8 fck_div_max; |
| 73 | u8 dss_fck_multiplier; |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 74 | const char *parent_clk_name; |
Tomi Valkeinen | 234f9a2 | 2014-12-11 15:59:31 +0200 | [diff] [blame] | 75 | const enum omap_display_type *ports; |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 76 | int num_ports; |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 77 | int (*dpi_select_source)(int port, enum omap_channel channel); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 78 | }; |
| 79 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 80 | static struct { |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 81 | struct platform_device *pdev; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 82 | void __iomem *base; |
Tomi Valkeinen | be40eec | 2014-07-04 13:37:15 +0530 | [diff] [blame] | 83 | struct regmap *syscon_pll_ctrl; |
| 84 | u32 syscon_pll_ctrl_offset; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 85 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 86 | struct clk *parent_clk; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 87 | struct clk *dss_clk; |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 88 | unsigned long dss_clk_rate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 89 | |
| 90 | unsigned long cache_req_pck; |
| 91 | unsigned long cache_prate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 92 | struct dispc_clock_info cache_dispc_cinfo; |
| 93 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 94 | enum dss_clk_source dsi_clk_source[MAX_NUM_DSI]; |
| 95 | enum dss_clk_source dispc_clk_source; |
| 96 | enum dss_clk_source lcd_clk_source[MAX_DSS_LCD_MANAGERS]; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 97 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 98 | bool ctx_valid; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 99 | u32 ctx[DSS_SZ_REGS / sizeof(u32)]; |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 100 | |
| 101 | const struct dss_features *feat; |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 102 | |
| 103 | struct dss_pll *video1_pll; |
| 104 | struct dss_pll *video2_pll; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 105 | } dss; |
| 106 | |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 107 | static const char * const dss_generic_clk_source_names[] = { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 108 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC] = "DSI_PLL_HSDIV_DISPC", |
| 109 | [OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI] = "DSI_PLL_HSDIV_DSI", |
| 110 | [OMAP_DSS_CLK_SRC_FCK] = "DSS_FCK", |
Tomi Valkeinen | 901e5fe | 2011-11-30 17:34:52 +0200 | [diff] [blame] | 111 | [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC] = "DSI_PLL2_HSDIV_DISPC", |
| 112 | [OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI] = "DSI_PLL2_HSDIV_DSI", |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 113 | }; |
| 114 | |
Tomi Valkeinen | f99467b | 2015-06-04 12:35:42 +0300 | [diff] [blame] | 115 | static bool dss_initialized; |
| 116 | |
| 117 | bool omapdss_is_initialized(void) |
| 118 | { |
| 119 | return dss_initialized; |
| 120 | } |
| 121 | EXPORT_SYMBOL(omapdss_is_initialized); |
| 122 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 123 | static inline void dss_write_reg(const struct dss_reg idx, u32 val) |
| 124 | { |
| 125 | __raw_writel(val, dss.base + idx.idx); |
| 126 | } |
| 127 | |
| 128 | static inline u32 dss_read_reg(const struct dss_reg idx) |
| 129 | { |
| 130 | return __raw_readl(dss.base + idx.idx); |
| 131 | } |
| 132 | |
| 133 | #define SR(reg) \ |
| 134 | dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg) |
| 135 | #define RR(reg) \ |
| 136 | dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)]) |
| 137 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 138 | static void dss_save_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_save_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 141 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 142 | SR(CONTROL); |
| 143 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 144 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 145 | OMAP_DISPLAY_TYPE_SDI) { |
| 146 | SR(SDI_CONTROL); |
| 147 | SR(PLL_CONTROL); |
| 148 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 149 | |
| 150 | dss.ctx_valid = true; |
| 151 | |
| 152 | DSSDBG("context saved\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 155 | static void dss_restore_context(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 156 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 157 | DSSDBG("dss_restore_context\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 158 | |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 159 | if (!dss.ctx_valid) |
| 160 | return; |
| 161 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 162 | RR(CONTROL); |
| 163 | |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 164 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 165 | OMAP_DISPLAY_TYPE_SDI) { |
| 166 | RR(SDI_CONTROL); |
| 167 | RR(PLL_CONTROL); |
| 168 | } |
Tomi Valkeinen | 69f0605 | 2011-06-01 15:56:39 +0300 | [diff] [blame] | 169 | |
| 170 | DSSDBG("context restored\n"); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #undef SR |
| 174 | #undef RR |
| 175 | |
Tomi Valkeinen | be40eec | 2014-07-04 13:37:15 +0530 | [diff] [blame] | 176 | void dss_ctrl_pll_enable(enum dss_pll_id pll_id, bool enable) |
| 177 | { |
| 178 | unsigned shift; |
| 179 | unsigned val; |
| 180 | |
| 181 | if (!dss.syscon_pll_ctrl) |
| 182 | return; |
| 183 | |
| 184 | val = !enable; |
| 185 | |
| 186 | switch (pll_id) { |
| 187 | case DSS_PLL_VIDEO1: |
| 188 | shift = 0; |
| 189 | break; |
| 190 | case DSS_PLL_VIDEO2: |
| 191 | shift = 1; |
| 192 | break; |
| 193 | case DSS_PLL_HDMI: |
| 194 | shift = 2; |
| 195 | break; |
| 196 | default: |
| 197 | DSSERR("illegal DSS PLL ID %d\n", pll_id); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | regmap_update_bits(dss.syscon_pll_ctrl, dss.syscon_pll_ctrl_offset, |
| 202 | 1 << shift, val << shift); |
| 203 | } |
| 204 | |
| 205 | void dss_ctrl_pll_set_control_mux(enum dss_pll_id pll_id, |
| 206 | enum omap_channel channel) |
| 207 | { |
| 208 | unsigned shift, val; |
| 209 | |
| 210 | if (!dss.syscon_pll_ctrl) |
| 211 | return; |
| 212 | |
| 213 | switch (channel) { |
| 214 | case OMAP_DSS_CHANNEL_LCD: |
| 215 | shift = 3; |
| 216 | |
| 217 | switch (pll_id) { |
| 218 | case DSS_PLL_VIDEO1: |
| 219 | val = 0; break; |
| 220 | case DSS_PLL_HDMI: |
| 221 | val = 1; break; |
| 222 | default: |
| 223 | DSSERR("error in PLL mux config for LCD\n"); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | break; |
| 228 | case OMAP_DSS_CHANNEL_LCD2: |
| 229 | shift = 5; |
| 230 | |
| 231 | switch (pll_id) { |
| 232 | case DSS_PLL_VIDEO1: |
| 233 | val = 0; break; |
| 234 | case DSS_PLL_VIDEO2: |
| 235 | val = 1; break; |
| 236 | case DSS_PLL_HDMI: |
| 237 | val = 2; break; |
| 238 | default: |
| 239 | DSSERR("error in PLL mux config for LCD2\n"); |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | break; |
| 244 | case OMAP_DSS_CHANNEL_LCD3: |
| 245 | shift = 7; |
| 246 | |
| 247 | switch (pll_id) { |
| 248 | case DSS_PLL_VIDEO1: |
| 249 | val = 1; break; |
| 250 | case DSS_PLL_VIDEO2: |
| 251 | val = 0; break; |
| 252 | case DSS_PLL_HDMI: |
| 253 | val = 2; break; |
| 254 | default: |
| 255 | DSSERR("error in PLL mux config for LCD3\n"); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | break; |
| 260 | default: |
| 261 | DSSERR("error in PLL mux config\n"); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | regmap_update_bits(dss.syscon_pll_ctrl, dss.syscon_pll_ctrl_offset, |
| 266 | 0x3 << shift, val << shift); |
| 267 | } |
| 268 | |
Archit Taneja | 889b4fd | 2012-07-20 17:18:49 +0530 | [diff] [blame] | 269 | void dss_sdi_init(int datapairs) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 270 | { |
| 271 | u32 l; |
| 272 | |
| 273 | BUG_ON(datapairs > 3 || datapairs < 1); |
| 274 | |
| 275 | l = dss_read_reg(DSS_SDI_CONTROL); |
| 276 | l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */ |
| 277 | l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */ |
| 278 | l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */ |
| 279 | dss_write_reg(DSS_SDI_CONTROL, l); |
| 280 | |
| 281 | l = dss_read_reg(DSS_PLL_CONTROL); |
| 282 | l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */ |
| 283 | l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */ |
| 284 | l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */ |
| 285 | dss_write_reg(DSS_PLL_CONTROL, l); |
| 286 | } |
| 287 | |
| 288 | int dss_sdi_enable(void) |
| 289 | { |
| 290 | unsigned long timeout; |
| 291 | |
| 292 | dispc_pck_free_enable(1); |
| 293 | |
| 294 | /* Reset SDI PLL */ |
| 295 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */ |
| 296 | udelay(1); /* wait 2x PCLK */ |
| 297 | |
| 298 | /* Lock SDI PLL */ |
| 299 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */ |
| 300 | |
| 301 | /* Waiting for PLL lock request to complete */ |
| 302 | timeout = jiffies + msecs_to_jiffies(500); |
| 303 | while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) { |
| 304 | if (time_after_eq(jiffies, timeout)) { |
| 305 | DSSERR("PLL lock request timed out\n"); |
| 306 | goto err1; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* Clearing PLL_GO bit */ |
| 311 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28); |
| 312 | |
| 313 | /* Waiting for PLL to lock */ |
| 314 | timeout = jiffies + msecs_to_jiffies(500); |
| 315 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) { |
| 316 | if (time_after_eq(jiffies, timeout)) { |
| 317 | DSSERR("PLL lock timed out\n"); |
| 318 | goto err1; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | dispc_lcd_enable_signal(1); |
| 323 | |
| 324 | /* Waiting for SDI reset to complete */ |
| 325 | timeout = jiffies + msecs_to_jiffies(500); |
| 326 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) { |
| 327 | if (time_after_eq(jiffies, timeout)) { |
| 328 | DSSERR("SDI reset timed out\n"); |
| 329 | goto err2; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return 0; |
| 334 | |
| 335 | err2: |
| 336 | dispc_lcd_enable_signal(0); |
| 337 | err1: |
| 338 | /* Reset SDI PLL */ |
| 339 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 340 | |
| 341 | dispc_pck_free_enable(0); |
| 342 | |
| 343 | return -ETIMEDOUT; |
| 344 | } |
| 345 | |
| 346 | void dss_sdi_disable(void) |
| 347 | { |
| 348 | dispc_lcd_enable_signal(0); |
| 349 | |
| 350 | dispc_pck_free_enable(0); |
| 351 | |
| 352 | /* Reset SDI PLL */ |
| 353 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ |
| 354 | } |
| 355 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 356 | const char *dss_get_generic_clk_source_name(enum dss_clk_source clk_src) |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 357 | { |
Taneja, Archit | 235e7db | 2011-03-14 23:28:21 -0500 | [diff] [blame] | 358 | return dss_generic_clk_source_names[clk_src]; |
Archit Taneja | 067a57e | 2011-03-02 11:57:25 +0530 | [diff] [blame] | 359 | } |
| 360 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 361 | void dss_dump_clocks(struct seq_file *s) |
| 362 | { |
Tomi Valkeinen | 0acf659 | 2011-03-14 07:28:57 -0500 | [diff] [blame] | 363 | const char *fclk_name, *fclk_real_name; |
| 364 | unsigned long fclk_rate; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 365 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 366 | if (dss_runtime_get()) |
| 367 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 368 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 369 | seq_printf(s, "- DSS -\n"); |
| 370 | |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 371 | fclk_name = dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_FCK); |
| 372 | 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] | 373 | fclk_rate = clk_get_rate(dss.dss_clk); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 374 | |
Tomi Valkeinen | 9c15d76 | 2013-11-01 11:36:10 +0200 | [diff] [blame] | 375 | seq_printf(s, "%s (%s) = %lu\n", |
| 376 | fclk_name, fclk_real_name, |
| 377 | fclk_rate); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 378 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 379 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 382 | static void dss_dump_regs(struct seq_file *s) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 383 | { |
| 384 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r)) |
| 385 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 386 | if (dss_runtime_get()) |
| 387 | return; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 388 | |
| 389 | DUMPREG(DSS_REVISION); |
| 390 | DUMPREG(DSS_SYSCONFIG); |
| 391 | DUMPREG(DSS_SYSSTATUS); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 392 | DUMPREG(DSS_CONTROL); |
Tomi Valkeinen | 6ec549e | 2011-02-24 14:18:50 +0200 | [diff] [blame] | 393 | |
| 394 | if (dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_LCD) & |
| 395 | OMAP_DISPLAY_TYPE_SDI) { |
| 396 | DUMPREG(DSS_SDI_CONTROL); |
| 397 | DUMPREG(DSS_PLL_CONTROL); |
| 398 | DUMPREG(DSS_SDI_STATUS); |
| 399 | } |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 400 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 401 | dss_runtime_put(); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 402 | #undef DUMPREG |
| 403 | } |
| 404 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 405 | static void dss_select_dispc_clk_source(enum dss_clk_source clk_src) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 406 | { |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 407 | int b; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 408 | u8 start, end; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 409 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 410 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 411 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 412 | b = 0; |
| 413 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 414 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 415 | b = 1; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 416 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 417 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
| 418 | b = 2; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 419 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 420 | default: |
| 421 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 422 | return; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 423 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 424 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 425 | dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end); |
| 426 | |
| 427 | REG_FLD_MOD(DSS_CONTROL, b, start, end); /* DISPC_CLK_SWITCH */ |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 428 | |
| 429 | dss.dispc_clk_source = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 432 | void dss_select_dsi_clk_source(int dsi_module, |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 433 | enum dss_clk_source clk_src) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 434 | { |
Archit Taneja | a2e5d82 | 2012-05-07 16:51:35 +0530 | [diff] [blame] | 435 | int b, pos; |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 436 | |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 437 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 438 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 439 | b = 0; |
| 440 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 441 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI: |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 442 | BUG_ON(dsi_module != 0); |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 443 | b = 1; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 444 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 445 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI: |
| 446 | BUG_ON(dsi_module != 1); |
| 447 | b = 1; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 448 | break; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 449 | default: |
| 450 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 451 | return; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 452 | } |
Tomi Valkeinen | e406f90 | 2010-06-09 15:28:12 +0300 | [diff] [blame] | 453 | |
Archit Taneja | a2e5d82 | 2012-05-07 16:51:35 +0530 | [diff] [blame] | 454 | pos = dsi_module == 0 ? 1 : 10; |
| 455 | REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */ |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 456 | |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 457 | dss.dsi_clk_source[dsi_module] = clk_src; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 460 | void dss_select_lcd_clk_source(enum omap_channel channel, |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 461 | enum dss_clk_source clk_src) |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 462 | { |
| 463 | int b, ix, pos; |
| 464 | |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 465 | if (!dss_has_feature(FEAT_LCD_CLK_SRC)) { |
| 466 | dss_select_dispc_clk_source(clk_src); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 467 | return; |
Tomi Valkeinen | a5b8399 | 2012-10-22 16:58:36 +0300 | [diff] [blame] | 468 | } |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 469 | |
| 470 | switch (clk_src) { |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 471 | case OMAP_DSS_CLK_SRC_FCK: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 472 | b = 0; |
| 473 | break; |
Archit Taneja | 89a35e5 | 2011-04-12 13:52:23 +0530 | [diff] [blame] | 474 | case OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC: |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 475 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD); |
| 476 | b = 1; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 477 | break; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 478 | case OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC: |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 479 | BUG_ON(channel != OMAP_DSS_CHANNEL_LCD2 && |
| 480 | channel != OMAP_DSS_CHANNEL_LCD3); |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 481 | b = 1; |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 482 | break; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 483 | default: |
| 484 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 485 | return; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 486 | } |
| 487 | |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 488 | pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 489 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 12 : 19); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 490 | REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* LCDx_CLK_SWITCH */ |
| 491 | |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 492 | ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 493 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 494 | dss.lcd_clk_source[ix] = clk_src; |
| 495 | } |
| 496 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 497 | enum dss_clk_source dss_get_dispc_clk_source(void) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 498 | { |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 499 | return dss.dispc_clk_source; |
| 500 | } |
| 501 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 502 | enum dss_clk_source dss_get_dsi_clk_source(int dsi_module) |
Tomi Valkeinen | 2f18c4d | 2010-01-08 18:00:36 +0200 | [diff] [blame] | 503 | { |
Archit Taneja | 5a8b572 | 2011-05-12 17:26:29 +0530 | [diff] [blame] | 504 | return dss.dsi_clk_source[dsi_module]; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame^] | 507 | enum dss_clk_source dss_get_lcd_clk_source(enum omap_channel channel) |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 508 | { |
Archit Taneja | 89976f2 | 2011-03-31 13:23:35 +0530 | [diff] [blame] | 509 | if (dss_has_feature(FEAT_LCD_CLK_SRC)) { |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 510 | int ix = channel == OMAP_DSS_CHANNEL_LCD ? 0 : |
| 511 | (channel == OMAP_DSS_CHANNEL_LCD2 ? 1 : 2); |
Archit Taneja | 89976f2 | 2011-03-31 13:23:35 +0530 | [diff] [blame] | 512 | return dss.lcd_clk_source[ix]; |
| 513 | } else { |
| 514 | /* LCD_CLK source is the same as DISPC_FCLK source for |
| 515 | * OMAP2 and OMAP3 */ |
| 516 | return dss.dispc_clk_source; |
| 517 | } |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 518 | } |
| 519 | |
Tomi Valkeinen | 688af02 | 2013-10-31 16:41:57 +0200 | [diff] [blame] | 520 | bool dss_div_calc(unsigned long pck, unsigned long fck_min, |
| 521 | dss_div_calc_func func, void *data) |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 522 | { |
| 523 | int fckd, fckd_start, fckd_stop; |
| 524 | unsigned long fck; |
| 525 | unsigned long fck_hw_max; |
| 526 | unsigned long fckd_hw_max; |
| 527 | unsigned long prate; |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 528 | unsigned m; |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 529 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 530 | fck_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 531 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 532 | if (dss.parent_clk == NULL) { |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 533 | unsigned pckd; |
| 534 | |
| 535 | pckd = fck_hw_max / pck; |
| 536 | |
| 537 | fck = pck * pckd; |
| 538 | |
| 539 | fck = clk_round_rate(dss.dss_clk, fck); |
| 540 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 541 | return func(fck, data); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 542 | } |
| 543 | |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 544 | fckd_hw_max = dss.feat->fck_div_max; |
| 545 | |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 546 | m = dss.feat->dss_fck_multiplier; |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 547 | prate = clk_get_rate(dss.parent_clk); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 548 | |
| 549 | fck_min = fck_min ? fck_min : 1; |
| 550 | |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 551 | fckd_start = min(prate * m / fck_min, fckd_hw_max); |
| 552 | fckd_stop = max(DIV_ROUND_UP(prate * m, fck_hw_max), 1ul); |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 553 | |
| 554 | for (fckd = fckd_start; fckd >= fckd_stop; --fckd) { |
Tomi Valkeinen | d0e224f | 2014-02-13 11:36:22 +0200 | [diff] [blame] | 555 | fck = DIV_ROUND_UP(prate, fckd) * m; |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 556 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 557 | if (func(fck, data)) |
Tomi Valkeinen | 4341782 | 2013-03-05 16:34:05 +0200 | [diff] [blame] | 558 | return true; |
| 559 | } |
| 560 | |
| 561 | return false; |
| 562 | } |
| 563 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 564 | int dss_set_fck_rate(unsigned long rate) |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 565 | { |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 566 | int r; |
| 567 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 568 | DSSDBG("set fck to %lu\n", rate); |
| 569 | |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 570 | r = clk_set_rate(dss.dss_clk, rate); |
| 571 | if (r) |
| 572 | return r; |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 573 | |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 574 | dss.dss_clk_rate = clk_get_rate(dss.dss_clk); |
| 575 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 576 | WARN_ONCE(dss.dss_clk_rate != rate, |
Tomi Valkeinen | 648a55e | 2013-04-10 14:47:38 +0300 | [diff] [blame] | 577 | "clk rate mismatch: %lu != %lu", dss.dss_clk_rate, |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 578 | rate); |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 583 | unsigned long dss_get_dispc_clk_rate(void) |
| 584 | { |
| 585 | return dss.dss_clk_rate; |
| 586 | } |
| 587 | |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 588 | static int dss_setup_default_clock(void) |
| 589 | { |
| 590 | unsigned long max_dss_fck, prate; |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 591 | unsigned long fck; |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 592 | unsigned fck_div; |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 593 | int r; |
| 594 | |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 595 | max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 596 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 597 | if (dss.parent_clk == NULL) { |
| 598 | fck = clk_round_rate(dss.dss_clk, max_dss_fck); |
| 599 | } else { |
| 600 | prate = clk_get_rate(dss.parent_clk); |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 601 | |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 602 | fck_div = DIV_ROUND_UP(prate * dss.feat->dss_fck_multiplier, |
| 603 | max_dss_fck); |
Tomi Valkeinen | d0e224f | 2014-02-13 11:36:22 +0200 | [diff] [blame] | 604 | fck = DIV_ROUND_UP(prate, fck_div) * dss.feat->dss_fck_multiplier; |
Tomi Valkeinen | fc1fe6e | 2013-10-31 16:42:13 +0200 | [diff] [blame] | 605 | } |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 606 | |
Tomi Valkeinen | d0f58bd | 2013-10-31 14:44:23 +0200 | [diff] [blame] | 607 | r = dss_set_fck_rate(fck); |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 608 | if (r) |
| 609 | return r; |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Tomi Valkeinen | 559d670 | 2009-11-03 11:23:50 +0200 | [diff] [blame] | 614 | void dss_set_venc_output(enum omap_dss_venc_type type) |
| 615 | { |
| 616 | int l = 0; |
| 617 | |
| 618 | if (type == OMAP_DSS_VENC_TYPE_COMPOSITE) |
| 619 | l = 0; |
| 620 | else if (type == OMAP_DSS_VENC_TYPE_SVIDEO) |
| 621 | l = 1; |
| 622 | else |
| 623 | BUG(); |
| 624 | |
| 625 | /* venc out selection. 0 = comp, 1 = svideo */ |
| 626 | REG_FLD_MOD(DSS_CONTROL, l, 6, 6); |
| 627 | } |
| 628 | |
| 629 | void dss_set_dac_pwrdn_bgz(bool enable) |
| 630 | { |
| 631 | REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */ |
| 632 | } |
| 633 | |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 634 | 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] | 635 | { |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 636 | enum omap_display_type dp; |
| 637 | dp = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT); |
| 638 | |
| 639 | /* Complain about invalid selections */ |
| 640 | WARN_ON((src == DSS_VENC_TV_CLK) && !(dp & OMAP_DISPLAY_TYPE_VENC)); |
| 641 | WARN_ON((src == DSS_HDMI_M_PCLK) && !(dp & OMAP_DISPLAY_TYPE_HDMI)); |
| 642 | |
| 643 | /* Select only if we have options */ |
| 644 | if ((dp & OMAP_DISPLAY_TYPE_VENC) && (dp & OMAP_DISPLAY_TYPE_HDMI)) |
| 645 | REG_FLD_MOD(DSS_CONTROL, src, 15, 15); /* VENC_HDMI_SWITCH */ |
Mythri P K | 7ed024a | 2011-03-09 16:31:38 +0530 | [diff] [blame] | 646 | } |
| 647 | |
Tomi Valkeinen | 4a61e26 | 2011-08-31 14:33:31 +0300 | [diff] [blame] | 648 | enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void) |
| 649 | { |
| 650 | enum omap_display_type displays; |
| 651 | |
| 652 | displays = dss_feat_get_supported_displays(OMAP_DSS_CHANNEL_DIGIT); |
| 653 | if ((displays & OMAP_DISPLAY_TYPE_HDMI) == 0) |
| 654 | return DSS_VENC_TV_CLK; |
| 655 | |
Ricardo Neri | 8aa2eed | 2012-08-01 07:56:40 -0500 | [diff] [blame] | 656 | if ((displays & OMAP_DISPLAY_TYPE_VENC) == 0) |
| 657 | return DSS_HDMI_M_PCLK; |
| 658 | |
Tomi Valkeinen | 4a61e26 | 2011-08-31 14:33:31 +0300 | [diff] [blame] | 659 | return REG_GET(DSS_CONTROL, 15, 15); |
| 660 | } |
| 661 | |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 662 | static int dss_dpi_select_source_omap2_omap3(int port, enum omap_channel channel) |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 663 | { |
| 664 | if (channel != OMAP_DSS_CHANNEL_LCD) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 670 | static int dss_dpi_select_source_omap4(int port, enum omap_channel channel) |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 671 | { |
| 672 | int val; |
| 673 | |
| 674 | switch (channel) { |
| 675 | case OMAP_DSS_CHANNEL_LCD2: |
| 676 | val = 0; |
| 677 | break; |
| 678 | case OMAP_DSS_CHANNEL_DIGIT: |
| 679 | val = 1; |
| 680 | break; |
| 681 | default: |
| 682 | return -EINVAL; |
| 683 | } |
| 684 | |
| 685 | REG_FLD_MOD(DSS_CONTROL, val, 17, 17); |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 690 | static int dss_dpi_select_source_omap5(int port, enum omap_channel channel) |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 691 | { |
| 692 | int val; |
| 693 | |
| 694 | switch (channel) { |
| 695 | case OMAP_DSS_CHANNEL_LCD: |
| 696 | val = 1; |
| 697 | break; |
| 698 | case OMAP_DSS_CHANNEL_LCD2: |
| 699 | val = 2; |
| 700 | break; |
| 701 | case OMAP_DSS_CHANNEL_LCD3: |
| 702 | val = 3; |
| 703 | break; |
| 704 | case OMAP_DSS_CHANNEL_DIGIT: |
| 705 | val = 0; |
| 706 | break; |
| 707 | default: |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | |
| 711 | REG_FLD_MOD(DSS_CONTROL, val, 17, 16); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
Tomi Valkeinen | 6d81788 | 2014-12-31 11:23:31 +0200 | [diff] [blame] | 716 | static int dss_dpi_select_source_dra7xx(int port, enum omap_channel channel) |
| 717 | { |
| 718 | switch (port) { |
| 719 | case 0: |
| 720 | return dss_dpi_select_source_omap5(port, channel); |
| 721 | case 1: |
| 722 | if (channel != OMAP_DSS_CHANNEL_LCD2) |
| 723 | return -EINVAL; |
| 724 | break; |
| 725 | case 2: |
| 726 | if (channel != OMAP_DSS_CHANNEL_LCD3) |
| 727 | return -EINVAL; |
| 728 | break; |
| 729 | default: |
| 730 | return -EINVAL; |
| 731 | } |
| 732 | |
| 733 | return 0; |
| 734 | } |
| 735 | |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 736 | int dss_dpi_select_source(int port, enum omap_channel channel) |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 737 | { |
Archit Taneja | 064c2a4 | 2014-04-23 18:00:18 +0530 | [diff] [blame] | 738 | return dss.feat->dpi_select_source(port, channel); |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 739 | } |
| 740 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 741 | static int dss_get_clocks(void) |
| 742 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 743 | struct clk *clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 744 | |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 745 | clk = devm_clk_get(&dss.pdev->dev, "fck"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 746 | if (IS_ERR(clk)) { |
| 747 | DSSERR("can't get clock fck\n"); |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 748 | return PTR_ERR(clk); |
Semwal, Sumit | a1a0dcc | 2011-03-01 02:42:14 -0600 | [diff] [blame] | 749 | } |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 750 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 751 | dss.dss_clk = clk; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 752 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 753 | if (dss.feat->parent_clk_name) { |
| 754 | clk = clk_get(NULL, dss.feat->parent_clk_name); |
Aaro Koskinen | 8ad9375 | 2012-11-21 21:48:51 +0200 | [diff] [blame] | 755 | if (IS_ERR(clk)) { |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 756 | DSSERR("Failed to get %s\n", dss.feat->parent_clk_name); |
Archit Taneja | b2c9c8e | 2013-04-08 11:55:00 +0300 | [diff] [blame] | 757 | return PTR_ERR(clk); |
Aaro Koskinen | 8ad9375 | 2012-11-21 21:48:51 +0200 | [diff] [blame] | 758 | } |
| 759 | } else { |
| 760 | clk = NULL; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 761 | } |
| 762 | |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 763 | dss.parent_clk = clk; |
Tomi Valkeinen | 94c042c | 2011-05-16 13:43:04 +0300 | [diff] [blame] | 764 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 765 | return 0; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static void dss_put_clocks(void) |
| 769 | { |
Tomi Valkeinen | 64ad846 | 2013-11-01 11:38:04 +0200 | [diff] [blame] | 770 | if (dss.parent_clk) |
| 771 | clk_put(dss.parent_clk); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 774 | int dss_runtime_get(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 775 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 776 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 777 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 778 | DSSDBG("dss_runtime_get\n"); |
| 779 | |
| 780 | r = pm_runtime_get_sync(&dss.pdev->dev); |
| 781 | WARN_ON(r < 0); |
| 782 | return r < 0 ? r : 0; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 785 | void dss_runtime_put(void) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 786 | { |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 787 | int r; |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 788 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 789 | DSSDBG("dss_runtime_put\n"); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 790 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 791 | r = pm_runtime_put_sync(&dss.pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 792 | WARN_ON(r < 0 && r != -ENOSYS && r != -EBUSY); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 795 | /* DEBUGFS */ |
Chandrabhanu Mahapatra | 1b3bcb3 | 2012-09-29 11:25:42 +0530 | [diff] [blame] | 796 | #if defined(CONFIG_OMAP2_DSS_DEBUGFS) |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 797 | void dss_debug_dump_clocks(struct seq_file *s) |
| 798 | { |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 799 | dss_dump_clocks(s); |
| 800 | dispc_dump_clocks(s); |
| 801 | #ifdef CONFIG_OMAP2_DSS_DSI |
| 802 | dsi_dump_clocks(s); |
| 803 | #endif |
| 804 | } |
| 805 | #endif |
| 806 | |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 807 | |
Tomi Valkeinen | 234f9a2 | 2014-12-11 15:59:31 +0200 | [diff] [blame] | 808 | static const enum omap_display_type omap2plus_ports[] = { |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 809 | OMAP_DISPLAY_TYPE_DPI, |
| 810 | }; |
| 811 | |
Tomi Valkeinen | 234f9a2 | 2014-12-11 15:59:31 +0200 | [diff] [blame] | 812 | static const enum omap_display_type omap34xx_ports[] = { |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 813 | OMAP_DISPLAY_TYPE_DPI, |
| 814 | OMAP_DISPLAY_TYPE_SDI, |
| 815 | }; |
| 816 | |
Tomi Valkeinen | 6d81788 | 2014-12-31 11:23:31 +0200 | [diff] [blame] | 817 | static const enum omap_display_type dra7xx_ports[] = { |
| 818 | OMAP_DISPLAY_TYPE_DPI, |
| 819 | OMAP_DISPLAY_TYPE_DPI, |
| 820 | OMAP_DISPLAY_TYPE_DPI, |
| 821 | }; |
| 822 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 823 | static const struct dss_features omap24xx_dss_feats = { |
Tomi Valkeinen | 6e555e2 | 2013-11-01 11:26:43 +0200 | [diff] [blame] | 824 | /* |
| 825 | * fck div max is really 16, but the divider range has gaps. The range |
| 826 | * from 1 to 6 has no gaps, so let's use that as a max. |
| 827 | */ |
| 828 | .fck_div_max = 6, |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 829 | .dss_fck_multiplier = 2, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 830 | .parent_clk_name = "core_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 831 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 832 | .ports = omap2plus_ports, |
| 833 | .num_ports = ARRAY_SIZE(omap2plus_ports), |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 834 | }; |
| 835 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 836 | static const struct dss_features omap34xx_dss_feats = { |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 837 | .fck_div_max = 16, |
| 838 | .dss_fck_multiplier = 2, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 839 | .parent_clk_name = "dpll4_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 840 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 841 | .ports = omap34xx_ports, |
| 842 | .num_ports = ARRAY_SIZE(omap34xx_ports), |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 843 | }; |
| 844 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 845 | static const struct dss_features omap3630_dss_feats = { |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 846 | .fck_div_max = 32, |
| 847 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 848 | .parent_clk_name = "dpll4_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 849 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 850 | .ports = omap2plus_ports, |
| 851 | .num_ports = ARRAY_SIZE(omap2plus_ports), |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 852 | }; |
| 853 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 854 | static const struct dss_features omap44xx_dss_feats = { |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 855 | .fck_div_max = 32, |
| 856 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 857 | .parent_clk_name = "dpll_per_x2_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 858 | .dpi_select_source = &dss_dpi_select_source_omap4, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 859 | .ports = omap2plus_ports, |
| 860 | .num_ports = ARRAY_SIZE(omap2plus_ports), |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 861 | }; |
| 862 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 863 | static const struct dss_features omap54xx_dss_feats = { |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 864 | .fck_div_max = 64, |
| 865 | .dss_fck_multiplier = 1, |
Tomi Valkeinen | ada9443 | 2013-10-31 16:06:38 +0200 | [diff] [blame] | 866 | .parent_clk_name = "dpll_per_x2_ck", |
Tomi Valkeinen | de09e45 | 2012-09-21 12:09:54 +0300 | [diff] [blame] | 867 | .dpi_select_source = &dss_dpi_select_source_omap5, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 868 | .ports = omap2plus_ports, |
| 869 | .num_ports = ARRAY_SIZE(omap2plus_ports), |
Tomi Valkeinen | 84273a9 | 2012-09-21 12:03:31 +0300 | [diff] [blame] | 870 | }; |
| 871 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 872 | static const struct dss_features am43xx_dss_feats = { |
Sathya Prakash M R | d6279d4 | 2014-03-24 16:31:51 +0530 | [diff] [blame] | 873 | .fck_div_max = 0, |
| 874 | .dss_fck_multiplier = 0, |
| 875 | .parent_clk_name = NULL, |
| 876 | .dpi_select_source = &dss_dpi_select_source_omap2_omap3, |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 877 | .ports = omap2plus_ports, |
| 878 | .num_ports = ARRAY_SIZE(omap2plus_ports), |
Sathya Prakash M R | d6279d4 | 2014-03-24 16:31:51 +0530 | [diff] [blame] | 879 | }; |
| 880 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 881 | static const struct dss_features dra7xx_dss_feats = { |
Tomi Valkeinen | 6d81788 | 2014-12-31 11:23:31 +0200 | [diff] [blame] | 882 | .fck_div_max = 64, |
| 883 | .dss_fck_multiplier = 1, |
| 884 | .parent_clk_name = "dpll_per_x2_ck", |
| 885 | .dpi_select_source = &dss_dpi_select_source_dra7xx, |
| 886 | .ports = dra7xx_ports, |
| 887 | .num_ports = ARRAY_SIZE(dra7xx_ports), |
| 888 | }; |
| 889 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 890 | static int dss_init_features(struct platform_device *pdev) |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 891 | { |
| 892 | const struct dss_features *src; |
| 893 | struct dss_features *dst; |
| 894 | |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 895 | dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 896 | if (!dst) { |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 897 | dev_err(&pdev->dev, "Failed to allocate local DSS Features\n"); |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 898 | return -ENOMEM; |
| 899 | } |
| 900 | |
Tomi Valkeinen | b2c7d54 | 2012-10-18 13:46:29 +0300 | [diff] [blame] | 901 | switch (omapdss_get_version()) { |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 902 | case OMAPDSS_VER_OMAP24xx: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 903 | src = &omap24xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 907 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 908 | case OMAPDSS_VER_AM35xx: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 909 | src = &omap34xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case OMAPDSS_VER_OMAP3630: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 913 | src = &omap3630_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case OMAPDSS_VER_OMAP4430_ES1: |
| 917 | case OMAPDSS_VER_OMAP4430_ES2: |
| 918 | case OMAPDSS_VER_OMAP4: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 919 | src = &omap44xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case OMAPDSS_VER_OMAP5: |
Archit Taneja | 2336283 | 2012-04-08 16:47:01 +0530 | [diff] [blame] | 923 | src = &omap54xx_dss_feats; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 924 | break; |
| 925 | |
Sathya Prakash M R | d6279d4 | 2014-03-24 16:31:51 +0530 | [diff] [blame] | 926 | case OMAPDSS_VER_AM43xx: |
| 927 | src = &am43xx_dss_feats; |
| 928 | break; |
| 929 | |
Tomi Valkeinen | 6d81788 | 2014-12-31 11:23:31 +0200 | [diff] [blame] | 930 | case OMAPDSS_VER_DRA7xx: |
| 931 | src = &dra7xx_dss_feats; |
| 932 | break; |
| 933 | |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 934 | default: |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 935 | return -ENODEV; |
Tomi Valkeinen | bd81ed0 | 2012-09-28 12:56:00 +0300 | [diff] [blame] | 936 | } |
Chandrabhanu Mahapatra | 185bae1 | 2012-07-11 18:36:18 +0530 | [diff] [blame] | 937 | |
| 938 | memcpy(dst, src, sizeof(*dst)); |
| 939 | dss.feat = dst; |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 944 | static int dss_init_ports(struct platform_device *pdev) |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 945 | { |
| 946 | struct device_node *parent = pdev->dev.of_node; |
| 947 | struct device_node *port; |
| 948 | int r; |
| 949 | |
| 950 | if (parent == NULL) |
| 951 | return 0; |
| 952 | |
| 953 | port = omapdss_of_get_next_port(parent, NULL); |
Archit Taneja | 0059277 | 2014-05-08 14:45:12 +0530 | [diff] [blame] | 954 | if (!port) |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 955 | return 0; |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 956 | |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 957 | if (dss.feat->num_ports == 0) |
| 958 | return 0; |
| 959 | |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 960 | do { |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 961 | enum omap_display_type port_type; |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 962 | u32 reg; |
| 963 | |
| 964 | r = of_property_read_u32(port, "reg", ®); |
| 965 | if (r) |
| 966 | reg = 0; |
| 967 | |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 968 | if (reg >= dss.feat->num_ports) |
| 969 | continue; |
| 970 | |
| 971 | port_type = dss.feat->ports[reg]; |
| 972 | |
| 973 | switch (port_type) { |
| 974 | case OMAP_DISPLAY_TYPE_DPI: |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 975 | dpi_init_port(pdev, port); |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 976 | break; |
| 977 | case OMAP_DISPLAY_TYPE_SDI: |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 978 | sdi_init_port(pdev, port); |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 979 | break; |
| 980 | default: |
| 981 | break; |
| 982 | } |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 983 | } while ((port = omapdss_of_get_next_port(parent, port)) != NULL); |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 988 | static void dss_uninit_ports(struct platform_device *pdev) |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 989 | { |
Archit Taneja | 80eb675 | 2014-06-02 14:11:51 +0530 | [diff] [blame] | 990 | struct device_node *parent = pdev->dev.of_node; |
| 991 | struct device_node *port; |
| 992 | |
| 993 | if (parent == NULL) |
| 994 | return; |
| 995 | |
| 996 | port = omapdss_of_get_next_port(parent, NULL); |
| 997 | if (!port) |
| 998 | return; |
| 999 | |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 1000 | if (dss.feat->num_ports == 0) |
| 1001 | return; |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1002 | |
Archit Taneja | 387ce9f | 2014-05-22 17:01:57 +0530 | [diff] [blame] | 1003 | do { |
| 1004 | enum omap_display_type port_type; |
| 1005 | u32 reg; |
| 1006 | int r; |
| 1007 | |
| 1008 | r = of_property_read_u32(port, "reg", ®); |
| 1009 | if (r) |
| 1010 | reg = 0; |
| 1011 | |
| 1012 | if (reg >= dss.feat->num_ports) |
| 1013 | continue; |
| 1014 | |
| 1015 | port_type = dss.feat->ports[reg]; |
| 1016 | |
| 1017 | switch (port_type) { |
| 1018 | case OMAP_DISPLAY_TYPE_DPI: |
| 1019 | dpi_uninit_port(port); |
| 1020 | break; |
| 1021 | case OMAP_DISPLAY_TYPE_SDI: |
| 1022 | sdi_uninit_port(port); |
| 1023 | break; |
| 1024 | default: |
| 1025 | break; |
| 1026 | } |
| 1027 | } while ((port = omapdss_of_get_next_port(parent, port)) != NULL); |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1030 | static int dss_video_pll_probe(struct platform_device *pdev) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1031 | { |
Tomi Valkeinen | be40eec | 2014-07-04 13:37:15 +0530 | [diff] [blame] | 1032 | struct device_node *np = pdev->dev.of_node; |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1033 | struct regulator *pll_regulator; |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1034 | int r; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1035 | |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1036 | if (!np) |
| 1037 | return 0; |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1038 | |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1039 | if (of_property_read_bool(np, "syscon-pll-ctrl")) { |
Tomi Valkeinen | be40eec | 2014-07-04 13:37:15 +0530 | [diff] [blame] | 1040 | dss.syscon_pll_ctrl = syscon_regmap_lookup_by_phandle(np, |
| 1041 | "syscon-pll-ctrl"); |
| 1042 | if (IS_ERR(dss.syscon_pll_ctrl)) { |
| 1043 | dev_err(&pdev->dev, |
| 1044 | "failed to get syscon-pll-ctrl regmap\n"); |
| 1045 | return PTR_ERR(dss.syscon_pll_ctrl); |
| 1046 | } |
| 1047 | |
| 1048 | if (of_property_read_u32_index(np, "syscon-pll-ctrl", 1, |
| 1049 | &dss.syscon_pll_ctrl_offset)) { |
| 1050 | dev_err(&pdev->dev, |
| 1051 | "failed to get syscon-pll-ctrl offset\n"); |
| 1052 | return -EINVAL; |
| 1053 | } |
| 1054 | } |
| 1055 | |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1056 | pll_regulator = devm_regulator_get(&pdev->dev, "vdda_video"); |
| 1057 | if (IS_ERR(pll_regulator)) { |
| 1058 | r = PTR_ERR(pll_regulator); |
| 1059 | |
| 1060 | switch (r) { |
| 1061 | case -ENOENT: |
| 1062 | pll_regulator = NULL; |
| 1063 | break; |
| 1064 | |
| 1065 | case -EPROBE_DEFER: |
| 1066 | return -EPROBE_DEFER; |
| 1067 | |
| 1068 | default: |
| 1069 | DSSERR("can't get DPLL VDDA regulator\n"); |
| 1070 | return r; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | if (of_property_match_string(np, "reg-names", "pll1") >= 0) { |
| 1075 | dss.video1_pll = dss_video_pll_init(pdev, 0, pll_regulator); |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1076 | if (IS_ERR(dss.video1_pll)) |
| 1077 | return PTR_ERR(dss.video1_pll); |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | if (of_property_match_string(np, "reg-names", "pll2") >= 0) { |
| 1081 | dss.video2_pll = dss_video_pll_init(pdev, 1, pll_regulator); |
| 1082 | if (IS_ERR(dss.video2_pll)) { |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1083 | dss_video_pll_uninit(dss.video1_pll); |
| 1084 | return PTR_ERR(dss.video2_pll); |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | /* DSS HW IP initialisation */ |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1092 | static int dss_bind(struct device *dev) |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1093 | { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1094 | struct platform_device *pdev = to_platform_device(dev); |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1095 | struct resource *dss_mem; |
| 1096 | u32 rev; |
| 1097 | int r; |
| 1098 | |
| 1099 | dss.pdev = pdev; |
| 1100 | |
| 1101 | r = dss_init_features(dss.pdev); |
| 1102 | if (r) |
| 1103 | return r; |
| 1104 | |
| 1105 | dss_mem = platform_get_resource(dss.pdev, IORESOURCE_MEM, 0); |
| 1106 | if (!dss_mem) { |
| 1107 | DSSERR("can't get IORESOURCE_MEM DSS\n"); |
| 1108 | return -EINVAL; |
| 1109 | } |
| 1110 | |
| 1111 | dss.base = devm_ioremap(&pdev->dev, dss_mem->start, |
| 1112 | resource_size(dss_mem)); |
| 1113 | if (!dss.base) { |
| 1114 | DSSERR("can't ioremap DSS\n"); |
| 1115 | return -ENOMEM; |
| 1116 | } |
| 1117 | |
| 1118 | r = dss_get_clocks(); |
| 1119 | if (r) |
| 1120 | return r; |
| 1121 | |
| 1122 | r = dss_setup_default_clock(); |
| 1123 | if (r) |
| 1124 | goto err_setup_clocks; |
| 1125 | |
| 1126 | r = dss_video_pll_probe(pdev); |
| 1127 | if (r) |
| 1128 | goto err_pll_init; |
| 1129 | |
Tomi Valkeinen | f5a1a1f8 | 2015-06-04 13:06:37 +0300 | [diff] [blame] | 1130 | r = dss_init_ports(pdev); |
| 1131 | if (r) |
| 1132 | goto err_init_ports; |
| 1133 | |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1134 | pm_runtime_enable(&pdev->dev); |
| 1135 | |
| 1136 | r = dss_runtime_get(); |
| 1137 | if (r) |
| 1138 | goto err_runtime_get; |
| 1139 | |
| 1140 | dss.dss_clk_rate = clk_get_rate(dss.dss_clk); |
| 1141 | |
| 1142 | /* Select DPLL */ |
| 1143 | REG_FLD_MOD(DSS_CONTROL, 0, 0, 0); |
| 1144 | |
| 1145 | dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); |
| 1146 | |
| 1147 | #ifdef CONFIG_OMAP2_DSS_VENC |
| 1148 | REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */ |
| 1149 | REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */ |
| 1150 | REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */ |
| 1151 | #endif |
| 1152 | dss.dsi_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 1153 | dss.dsi_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
| 1154 | dss.dispc_clk_source = OMAP_DSS_CLK_SRC_FCK; |
| 1155 | dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; |
| 1156 | dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; |
| 1157 | |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 1158 | rev = dss_read_reg(DSS_REVISION); |
| 1159 | printk(KERN_INFO "OMAP DSS rev %d.%d\n", |
| 1160 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 1161 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1162 | dss_runtime_put(); |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 1163 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1164 | r = component_bind_all(&pdev->dev, NULL); |
| 1165 | if (r) |
| 1166 | goto err_component; |
| 1167 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 1168 | dss_debugfs_create_file("dss", dss_dump_regs); |
| 1169 | |
Tomi Valkeinen | cb17a4a | 2015-02-25 12:08:14 +0200 | [diff] [blame] | 1170 | pm_set_vt_switch(0); |
| 1171 | |
Tomi Valkeinen | f99467b | 2015-06-04 12:35:42 +0300 | [diff] [blame] | 1172 | dss_initialized = true; |
| 1173 | |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 1174 | return 0; |
Tomi Valkeinen | a57dd4f | 2012-02-20 16:57:37 +0200 | [diff] [blame] | 1175 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1176 | err_component: |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1177 | err_runtime_get: |
| 1178 | pm_runtime_disable(&pdev->dev); |
Tomi Valkeinen | f5a1a1f8 | 2015-06-04 13:06:37 +0300 | [diff] [blame] | 1179 | dss_uninit_ports(pdev); |
| 1180 | err_init_ports: |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1181 | if (dss.video1_pll) |
| 1182 | dss_video_pll_uninit(dss.video1_pll); |
| 1183 | |
| 1184 | if (dss.video2_pll) |
| 1185 | dss_video_pll_uninit(dss.video2_pll); |
Tomi Valkeinen | 7e328f5 | 2015-06-04 13:02:52 +0300 | [diff] [blame] | 1186 | err_pll_init: |
Tomi Valkeinen | 13a1a2b | 2012-10-22 16:35:41 +0300 | [diff] [blame] | 1187 | err_setup_clocks: |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 1188 | dss_put_clocks(); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1189 | return r; |
| 1190 | } |
| 1191 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1192 | static void dss_unbind(struct device *dev) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1193 | { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1194 | struct platform_device *pdev = to_platform_device(dev); |
| 1195 | |
Tomi Valkeinen | f99467b | 2015-06-04 12:35:42 +0300 | [diff] [blame] | 1196 | dss_initialized = false; |
| 1197 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1198 | component_unbind_all(&pdev->dev, NULL); |
| 1199 | |
Tomi Valkeinen | 9976754 | 2014-07-04 13:38:27 +0530 | [diff] [blame] | 1200 | if (dss.video1_pll) |
| 1201 | dss_video_pll_uninit(dss.video1_pll); |
| 1202 | |
| 1203 | if (dss.video2_pll) |
| 1204 | dss_video_pll_uninit(dss.video2_pll); |
| 1205 | |
Archit Taneja | 2ac6a1a | 2014-06-01 12:47:44 +0530 | [diff] [blame] | 1206 | dss_uninit_ports(pdev); |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1207 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1208 | pm_runtime_disable(&pdev->dev); |
Senthilvadivu Guruswamy | 8b9cb3a | 2011-01-24 06:21:58 +0000 | [diff] [blame] | 1209 | |
| 1210 | dss_put_clocks(); |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1211 | } |
Tomi Valkeinen | b98482e | 2011-05-16 13:52:51 +0300 | [diff] [blame] | 1212 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1213 | static const struct component_master_ops dss_component_ops = { |
| 1214 | .bind = dss_bind, |
| 1215 | .unbind = dss_unbind, |
| 1216 | }; |
| 1217 | |
| 1218 | static int dss_component_compare(struct device *dev, void *data) |
| 1219 | { |
| 1220 | struct device *child = data; |
| 1221 | return dev == child; |
| 1222 | } |
| 1223 | |
| 1224 | static int dss_add_child_component(struct device *dev, void *data) |
| 1225 | { |
| 1226 | struct component_match **match = data; |
| 1227 | |
Tomi Valkeinen | 0438ec9 | 2015-06-30 12:23:45 +0300 | [diff] [blame] | 1228 | /* |
| 1229 | * HACK |
| 1230 | * We don't have a working driver for rfbi, so skip it here always. |
| 1231 | * Otherwise dss will never get probed successfully, as it will wait |
| 1232 | * for rfbi to get probed. |
| 1233 | */ |
| 1234 | if (strstr(dev_name(dev), "rfbi")) |
| 1235 | return 0; |
| 1236 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1237 | component_match_add(dev->parent, match, dss_component_compare, dev); |
| 1238 | |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int dss_probe(struct platform_device *pdev) |
| 1243 | { |
| 1244 | struct component_match *match = NULL; |
| 1245 | int r; |
| 1246 | |
| 1247 | /* add all the child devices as components */ |
| 1248 | device_for_each_child(&pdev->dev, &match, dss_add_child_component); |
| 1249 | |
| 1250 | r = component_master_add_with_match(&pdev->dev, &dss_component_ops, match); |
| 1251 | if (r) |
| 1252 | return r; |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int dss_remove(struct platform_device *pdev) |
| 1258 | { |
| 1259 | component_master_del(&pdev->dev, &dss_component_ops); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1260 | return 0; |
| 1261 | } |
| 1262 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1263 | static int dss_runtime_suspend(struct device *dev) |
| 1264 | { |
| 1265 | dss_save_context(); |
Tomi Valkeinen | a8081d3 | 2012-03-08 12:52:38 +0200 | [diff] [blame] | 1266 | dss_set_min_bus_tput(dev, 0); |
Dave Gerlach | 5038bb8 | 2014-10-31 16:28:57 -0500 | [diff] [blame] | 1267 | |
| 1268 | pinctrl_pm_select_sleep_state(dev); |
| 1269 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int dss_runtime_resume(struct device *dev) |
| 1274 | { |
Tomi Valkeinen | a8081d3 | 2012-03-08 12:52:38 +0200 | [diff] [blame] | 1275 | int r; |
Dave Gerlach | 5038bb8 | 2014-10-31 16:28:57 -0500 | [diff] [blame] | 1276 | |
| 1277 | pinctrl_pm_select_default_state(dev); |
| 1278 | |
Tomi Valkeinen | a8081d3 | 2012-03-08 12:52:38 +0200 | [diff] [blame] | 1279 | /* |
| 1280 | * Set an arbitrarily high tput request to ensure OPP100. |
| 1281 | * What we should really do is to make a request to stay in OPP100, |
| 1282 | * without any tput requirements, but that is not currently possible |
| 1283 | * via the PM layer. |
| 1284 | */ |
| 1285 | |
| 1286 | r = dss_set_min_bus_tput(dev, 1000000000); |
| 1287 | if (r) |
| 1288 | return r; |
| 1289 | |
Tomi Valkeinen | 3902071 | 2011-05-26 14:54:05 +0300 | [diff] [blame] | 1290 | dss_restore_context(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static const struct dev_pm_ops dss_pm_ops = { |
| 1295 | .runtime_suspend = dss_runtime_suspend, |
| 1296 | .runtime_resume = dss_runtime_resume, |
| 1297 | }; |
| 1298 | |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1299 | static const struct of_device_id dss_of_match[] = { |
| 1300 | { .compatible = "ti,omap2-dss", }, |
| 1301 | { .compatible = "ti,omap3-dss", }, |
| 1302 | { .compatible = "ti,omap4-dss", }, |
Tomi Valkeinen | 2e7e6b6 | 2014-04-16 13:16:43 +0300 | [diff] [blame] | 1303 | { .compatible = "ti,omap5-dss", }, |
Tomi Valkeinen | 6d81788 | 2014-12-31 11:23:31 +0200 | [diff] [blame] | 1304 | { .compatible = "ti,dra7-dss", }, |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1305 | {}, |
| 1306 | }; |
| 1307 | |
| 1308 | MODULE_DEVICE_TABLE(of, dss_of_match); |
| 1309 | |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1310 | static struct platform_driver omap_dsshw_driver = { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1311 | .probe = dss_probe, |
| 1312 | .remove = dss_remove, |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1313 | .driver = { |
| 1314 | .name = "omapdss_dss", |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1315 | .pm = &dss_pm_ops, |
Tomi Valkeinen | 2ecef24 | 2013-12-16 15:13:24 +0200 | [diff] [blame] | 1316 | .of_match_table = dss_of_match, |
Tomi Valkeinen | 422ccbd | 2014-10-16 09:54:25 +0300 | [diff] [blame] | 1317 | .suppress_bind_attrs = true, |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1318 | }, |
| 1319 | }; |
| 1320 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1321 | int __init dss_init_platform_driver(void) |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1322 | { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 1323 | return platform_driver_register(&omap_dsshw_driver); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | void dss_uninit_platform_driver(void) |
| 1327 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 1328 | platform_driver_unregister(&omap_dsshw_driver); |
Senthilvadivu Guruswamy | 96c401b | 2011-01-24 06:21:57 +0000 | [diff] [blame] | 1329 | } |