Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | * hdmi.c |
| 3 | * |
| 4 | * HDMI interface DSS driver setting for TI's OMAP4 family of processor. |
| 5 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Authors: Yong Zhi |
| 7 | * Mythri pk <mythripk@ti.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as published by |
| 11 | * the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #define DSS_SUBSYS_NAME "HDMI" |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/mutex.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/string.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
| 34 | #include <linux/clk.h> |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 35 | #include <linux/gpio.h> |
Tomi Valkeinen | 1748694 | 2012-08-15 15:55:04 +0300 | [diff] [blame] | 36 | #include <linux/regulator/consumer.h> |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 37 | #include <video/omapdss.h> |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 38 | |
Mythri P K | 94c5298 | 2011-09-08 19:06:21 +0530 | [diff] [blame] | 39 | #include "ti_hdmi.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 40 | #include "dss.h" |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 41 | #include "dss_features.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 42 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 43 | #define HDMI_WP 0x0 |
| 44 | #define HDMI_CORE_SYS 0x400 |
| 45 | #define HDMI_CORE_AV 0x900 |
| 46 | #define HDMI_PLLCTRL 0x200 |
| 47 | #define HDMI_PHY 0x300 |
| 48 | |
Mythri P K | 7c1f1ec | 2011-09-08 19:06:22 +0530 | [diff] [blame] | 49 | /* HDMI EDID Length move this */ |
| 50 | #define HDMI_EDID_MAX_LENGTH 256 |
| 51 | #define EDID_TIMING_DESCRIPTOR_SIZE 0x12 |
| 52 | #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36 |
| 53 | #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80 |
| 54 | #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4 |
| 55 | #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4 |
| 56 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 57 | #define HDMI_DEFAULT_REGN 16 |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 58 | #define HDMI_DEFAULT_REGM2 1 |
| 59 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 60 | static struct { |
| 61 | struct mutex lock; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 62 | struct platform_device *pdev; |
Ricardo Neri | 14840b9 | 2012-11-06 00:19:17 -0600 | [diff] [blame] | 63 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
| 64 | struct platform_device *audio_pdev; |
| 65 | #endif |
Ricardo Neri | 66a06b0 | 2012-11-06 00:19:14 -0600 | [diff] [blame] | 66 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 67 | struct hdmi_ip_data ip_data; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 68 | |
| 69 | struct clk *sys_clk; |
Tomi Valkeinen | 1748694 | 2012-08-15 15:55:04 +0300 | [diff] [blame] | 70 | struct regulator *vdda_hdmi_dac_reg; |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 71 | |
| 72 | int ct_cp_hpd_gpio; |
| 73 | int ls_oe_gpio; |
| 74 | int hpd_gpio; |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 75 | |
| 76 | struct omap_dss_output output; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 77 | } hdmi; |
| 78 | |
| 79 | /* |
| 80 | * Logic for the below structure : |
| 81 | * user enters the CEA or VESA timings by specifying the HDMI/DVI code. |
| 82 | * There is a correspondence between CEA/VESA timing and code, please |
| 83 | * refer to section 6.3 in HDMI 1.3 specification for timing code. |
| 84 | * |
| 85 | * In the below structure, cea_vesa_timings corresponds to all OMAP4 |
| 86 | * supported CEA and VESA timing values.code_cea corresponds to the CEA |
| 87 | * code, It is used to get the timing from cea_vesa_timing array.Similarly |
| 88 | * with code_vesa. Code_index is used for back mapping, that is once EDID |
| 89 | * is read from the TV, EDID is parsed to find the timing values and then |
| 90 | * map it to corresponding CEA or VESA index. |
| 91 | */ |
| 92 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 93 | static const struct hdmi_config cea_timings[] = { |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 94 | { |
| 95 | { 640, 480, 25200, 96, 16, 48, 2, 10, 33, |
| 96 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 97 | false, }, |
| 98 | { 1, HDMI_HDMI }, |
| 99 | }, |
| 100 | { |
| 101 | { 720, 480, 27027, 62, 16, 60, 6, 9, 30, |
| 102 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 103 | false, }, |
| 104 | { 2, HDMI_HDMI }, |
| 105 | }, |
| 106 | { |
| 107 | { 1280, 720, 74250, 40, 110, 220, 5, 5, 20, |
| 108 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 109 | false, }, |
| 110 | { 4, HDMI_HDMI }, |
| 111 | }, |
| 112 | { |
| 113 | { 1920, 540, 74250, 44, 88, 148, 5, 2, 15, |
| 114 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 115 | true, }, |
| 116 | { 5, HDMI_HDMI }, |
| 117 | }, |
| 118 | { |
| 119 | { 1440, 240, 27027, 124, 38, 114, 3, 4, 15, |
| 120 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 121 | true, }, |
| 122 | { 6, HDMI_HDMI }, |
| 123 | }, |
| 124 | { |
| 125 | { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36, |
| 126 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 127 | false, }, |
| 128 | { 16, HDMI_HDMI }, |
| 129 | }, |
| 130 | { |
| 131 | { 720, 576, 27000, 64, 12, 68, 5, 5, 39, |
| 132 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 133 | false, }, |
| 134 | { 17, HDMI_HDMI }, |
| 135 | }, |
| 136 | { |
| 137 | { 1280, 720, 74250, 40, 440, 220, 5, 5, 20, |
| 138 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 139 | false, }, |
| 140 | { 19, HDMI_HDMI }, |
| 141 | }, |
| 142 | { |
| 143 | { 1920, 540, 74250, 44, 528, 148, 5, 2, 15, |
| 144 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 145 | true, }, |
| 146 | { 20, HDMI_HDMI }, |
| 147 | }, |
| 148 | { |
| 149 | { 1440, 288, 27000, 126, 24, 138, 3, 2, 19, |
| 150 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 151 | true, }, |
| 152 | { 21, HDMI_HDMI }, |
| 153 | }, |
| 154 | { |
| 155 | { 1440, 576, 54000, 128, 24, 136, 5, 5, 39, |
| 156 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 157 | false, }, |
| 158 | { 29, HDMI_HDMI }, |
| 159 | }, |
| 160 | { |
| 161 | { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36, |
| 162 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 163 | false, }, |
| 164 | { 31, HDMI_HDMI }, |
| 165 | }, |
| 166 | { |
| 167 | { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36, |
| 168 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 169 | false, }, |
| 170 | { 32, HDMI_HDMI }, |
| 171 | }, |
| 172 | { |
| 173 | { 2880, 480, 108108, 248, 64, 240, 6, 9, 30, |
| 174 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 175 | false, }, |
| 176 | { 35, HDMI_HDMI }, |
| 177 | }, |
| 178 | { |
| 179 | { 2880, 576, 108000, 256, 48, 272, 5, 5, 39, |
| 180 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 181 | false, }, |
| 182 | { 37, HDMI_HDMI }, |
| 183 | }, |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 184 | }; |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 185 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 186 | static const struct hdmi_config vesa_timings[] = { |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame] | 187 | /* VESA From Here */ |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 188 | { |
| 189 | { 640, 480, 25175, 96, 16, 48, 2, 11, 31, |
| 190 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 191 | false, }, |
| 192 | { 4, HDMI_DVI }, |
| 193 | }, |
| 194 | { |
| 195 | { 800, 600, 40000, 128, 40, 88, 4, 1, 23, |
| 196 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 197 | false, }, |
| 198 | { 9, HDMI_DVI }, |
| 199 | }, |
| 200 | { |
| 201 | { 848, 480, 33750, 112, 16, 112, 8, 6, 23, |
| 202 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 203 | false, }, |
| 204 | { 0xE, HDMI_DVI }, |
| 205 | }, |
| 206 | { |
| 207 | { 1280, 768, 79500, 128, 64, 192, 7, 3, 20, |
| 208 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 209 | false, }, |
| 210 | { 0x17, HDMI_DVI }, |
| 211 | }, |
| 212 | { |
| 213 | { 1280, 800, 83500, 128, 72, 200, 6, 3, 22, |
| 214 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 215 | false, }, |
| 216 | { 0x1C, HDMI_DVI }, |
| 217 | }, |
| 218 | { |
| 219 | { 1360, 768, 85500, 112, 64, 256, 6, 3, 18, |
| 220 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 221 | false, }, |
| 222 | { 0x27, HDMI_DVI }, |
| 223 | }, |
| 224 | { |
| 225 | { 1280, 960, 108000, 112, 96, 312, 3, 1, 36, |
| 226 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 227 | false, }, |
| 228 | { 0x20, HDMI_DVI }, |
| 229 | }, |
| 230 | { |
| 231 | { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38, |
| 232 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 233 | false, }, |
| 234 | { 0x23, HDMI_DVI }, |
| 235 | }, |
| 236 | { |
| 237 | { 1024, 768, 65000, 136, 24, 160, 6, 3, 29, |
| 238 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 239 | false, }, |
| 240 | { 0x10, HDMI_DVI }, |
| 241 | }, |
| 242 | { |
| 243 | { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32, |
| 244 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 245 | false, }, |
| 246 | { 0x2A, HDMI_DVI }, |
| 247 | }, |
| 248 | { |
| 249 | { 1440, 900, 106500, 152, 80, 232, 6, 3, 25, |
| 250 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 251 | false, }, |
| 252 | { 0x2F, HDMI_DVI }, |
| 253 | }, |
| 254 | { |
| 255 | { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30, |
| 256 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 257 | false, }, |
| 258 | { 0x3A, HDMI_DVI }, |
| 259 | }, |
| 260 | { |
| 261 | { 1366, 768, 85500, 143, 70, 213, 3, 3, 24, |
| 262 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 263 | false, }, |
| 264 | { 0x51, HDMI_DVI }, |
| 265 | }, |
| 266 | { |
| 267 | { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36, |
| 268 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 269 | false, }, |
| 270 | { 0x52, HDMI_DVI }, |
| 271 | }, |
| 272 | { |
| 273 | { 1280, 768, 68250, 32, 48, 80, 7, 3, 12, |
| 274 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 275 | false, }, |
| 276 | { 0x16, HDMI_DVI }, |
| 277 | }, |
| 278 | { |
| 279 | { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23, |
| 280 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 281 | false, }, |
| 282 | { 0x29, HDMI_DVI }, |
| 283 | }, |
| 284 | { |
| 285 | { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21, |
| 286 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 287 | false, }, |
| 288 | { 0x39, HDMI_DVI }, |
| 289 | }, |
| 290 | { |
| 291 | { 1280, 800, 79500, 32, 48, 80, 6, 3, 14, |
| 292 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 293 | false, }, |
| 294 | { 0x1B, HDMI_DVI }, |
| 295 | }, |
| 296 | { |
| 297 | { 1280, 720, 74250, 40, 110, 220, 5, 5, 20, |
| 298 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 299 | false, }, |
| 300 | { 0x55, HDMI_DVI }, |
| 301 | }, |
Tomi Valkeinen | 7a7ce2c | 2012-10-24 11:55:39 +0300 | [diff] [blame] | 302 | { |
| 303 | { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26, |
| 304 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 305 | false, }, |
| 306 | { 0x44, HDMI_DVI }, |
| 307 | }, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 308 | }; |
| 309 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 310 | static int hdmi_runtime_get(void) |
| 311 | { |
| 312 | int r; |
| 313 | |
| 314 | DSSDBG("hdmi_runtime_get\n"); |
| 315 | |
| 316 | r = pm_runtime_get_sync(&hdmi.pdev->dev); |
| 317 | WARN_ON(r < 0); |
Archit Taneja | a247ce78 | 2012-02-10 11:45:52 +0530 | [diff] [blame] | 318 | if (r < 0) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 319 | return r; |
Archit Taneja | a247ce78 | 2012-02-10 11:45:52 +0530 | [diff] [blame] | 320 | |
| 321 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void hdmi_runtime_put(void) |
| 325 | { |
| 326 | int r; |
| 327 | |
| 328 | DSSDBG("hdmi_runtime_put\n"); |
| 329 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 330 | r = pm_runtime_put_sync(&hdmi.pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 331 | WARN_ON(r < 0 && r != -ENOSYS); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 332 | } |
| 333 | |
Tomi Valkeinen | 9d8232a | 2012-03-01 16:58:39 +0200 | [diff] [blame] | 334 | static int __init hdmi_init_display(struct omap_dss_device *dssdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 335 | { |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 336 | int r; |
| 337 | |
| 338 | struct gpio gpios[] = { |
| 339 | { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" }, |
| 340 | { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" }, |
| 341 | { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" }, |
| 342 | }; |
| 343 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 344 | DSSDBG("init_display\n"); |
| 345 | |
Tomi Valkeinen | b2c7d54 | 2012-10-18 13:46:29 +0300 | [diff] [blame] | 346 | dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version()); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 347 | |
Tomi Valkeinen | 1748694 | 2012-08-15 15:55:04 +0300 | [diff] [blame] | 348 | if (hdmi.vdda_hdmi_dac_reg == NULL) { |
| 349 | struct regulator *reg; |
| 350 | |
| 351 | reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac"); |
| 352 | |
Tomi Valkeinen | 76eed4b | 2012-11-05 13:41:25 +0200 | [diff] [blame^] | 353 | /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */ |
| 354 | if (IS_ERR(reg)) |
| 355 | reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC"); |
| 356 | |
Tomi Valkeinen | 1748694 | 2012-08-15 15:55:04 +0300 | [diff] [blame] | 357 | if (IS_ERR(reg)) { |
| 358 | DSSERR("can't get VDDA_HDMI_DAC regulator\n"); |
| 359 | return PTR_ERR(reg); |
| 360 | } |
| 361 | |
| 362 | hdmi.vdda_hdmi_dac_reg = reg; |
| 363 | } |
| 364 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 365 | r = gpio_request_array(gpios, ARRAY_SIZE(gpios)); |
| 366 | if (r) |
| 367 | return r; |
| 368 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
Ricardo Neri | 3758476 | 2012-11-06 21:37:14 -0600 | [diff] [blame] | 372 | static void hdmi_uninit_display(struct omap_dss_device *dssdev) |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 373 | { |
| 374 | DSSDBG("uninit_display\n"); |
| 375 | |
| 376 | gpio_free(hdmi.ct_cp_hpd_gpio); |
| 377 | gpio_free(hdmi.ls_oe_gpio); |
| 378 | gpio_free(hdmi.hpd_gpio); |
| 379 | } |
| 380 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 381 | static const struct hdmi_config *hdmi_find_timing( |
| 382 | const struct hdmi_config *timings_arr, |
| 383 | int len) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 384 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 385 | int i; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 386 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 387 | for (i = 0; i < len; i++) { |
Mythri P K | 9e4ed60 | 2012-01-06 17:52:10 +0530 | [diff] [blame] | 388 | if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code) |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 389 | return &timings_arr[i]; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 390 | } |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 391 | return NULL; |
| 392 | } |
| 393 | |
| 394 | static const struct hdmi_config *hdmi_get_timings(void) |
| 395 | { |
| 396 | const struct hdmi_config *arr; |
| 397 | int len; |
| 398 | |
Mythri P K | 9e4ed60 | 2012-01-06 17:52:10 +0530 | [diff] [blame] | 399 | if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 400 | arr = vesa_timings; |
| 401 | len = ARRAY_SIZE(vesa_timings); |
| 402 | } else { |
| 403 | arr = cea_timings; |
| 404 | len = ARRAY_SIZE(cea_timings); |
| 405 | } |
| 406 | |
| 407 | return hdmi_find_timing(arr, len); |
| 408 | } |
| 409 | |
| 410 | static bool hdmi_timings_compare(struct omap_video_timings *timing1, |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 411 | const struct omap_video_timings *timing2) |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 412 | { |
| 413 | int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync; |
| 414 | |
Tomi Valkeinen | f236b89 | 2012-10-24 11:55:54 +0300 | [diff] [blame] | 415 | if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) == |
| 416 | DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) && |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 417 | (timing2->x_res == timing1->x_res) && |
| 418 | (timing2->y_res == timing1->y_res)) { |
| 419 | |
| 420 | timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp; |
| 421 | timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp; |
| 422 | timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp; |
| 423 | timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp; |
| 424 | |
| 425 | DSSDBG("timing1_hsync = %d timing1_vsync = %d"\ |
| 426 | "timing2_hsync = %d timing2_vsync = %d\n", |
| 427 | timing1_hsync, timing1_vsync, |
| 428 | timing2_hsync, timing2_vsync); |
| 429 | |
| 430 | if ((timing1_hsync == timing2_hsync) && |
| 431 | (timing1_vsync == timing2_vsync)) { |
| 432 | return true; |
| 433 | } |
| 434 | } |
| 435 | return false; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing) |
| 439 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 440 | int i; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 441 | struct hdmi_cm cm = {-1}; |
| 442 | DSSDBG("hdmi_get_code\n"); |
| 443 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 444 | for (i = 0; i < ARRAY_SIZE(cea_timings); i++) { |
| 445 | if (hdmi_timings_compare(timing, &cea_timings[i].timings)) { |
| 446 | cm = cea_timings[i].cm; |
| 447 | goto end; |
| 448 | } |
| 449 | } |
| 450 | for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) { |
| 451 | if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) { |
| 452 | cm = vesa_timings[i].cm; |
| 453 | goto end; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 457 | end: return cm; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 458 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 459 | } |
| 460 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 461 | unsigned long hdmi_get_pixel_clock(void) |
| 462 | { |
| 463 | /* HDMI Pixel Clock in Mhz */ |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame] | 464 | return hdmi.ip_data.cfg.timings.pixel_clock * 1000; |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 465 | } |
| 466 | |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 467 | static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy, |
| 468 | struct hdmi_pll_info *pi) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 469 | { |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 470 | unsigned long clkin, refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 471 | u32 mf; |
| 472 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 473 | clkin = clk_get_rate(hdmi.sys_clk) / 10000; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 474 | /* |
| 475 | * Input clock is predivided by N + 1 |
| 476 | * out put of which is reference clk |
| 477 | */ |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 478 | if (dssdev->clocks.hdmi.regn == 0) |
| 479 | pi->regn = HDMI_DEFAULT_REGN; |
| 480 | else |
| 481 | pi->regn = dssdev->clocks.hdmi.regn; |
| 482 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 483 | refclk = clkin / pi->regn; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 484 | |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 485 | if (dssdev->clocks.hdmi.regm2 == 0) |
| 486 | pi->regm2 = HDMI_DEFAULT_REGM2; |
| 487 | else |
| 488 | pi->regm2 = dssdev->clocks.hdmi.regm2; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 489 | |
| 490 | /* |
Mythri P K | dd2116a | 2012-02-21 12:10:58 +0530 | [diff] [blame] | 491 | * multiplier is pixel_clk/ref_clk |
| 492 | * Multiplying by 100 to avoid fractional part removal |
| 493 | */ |
| 494 | pi->regm = phy * pi->regm2 / refclk; |
| 495 | |
| 496 | /* |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 497 | * fractional multiplier is remainder of the difference between |
| 498 | * multiplier and actual phy(required pixel clock thus should be |
| 499 | * multiplied by 2^18(262144) divided by the reference clock |
| 500 | */ |
Mythri P K | dd2116a | 2012-02-21 12:10:58 +0530 | [diff] [blame] | 501 | mf = (phy - pi->regm / pi->regm2 * refclk) * 262144; |
| 502 | pi->regmf = pi->regm2 * mf / refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * Dcofreq should be set to 1 if required pixel clock |
| 506 | * is greater than 1000MHz |
| 507 | */ |
| 508 | pi->dcofreq = phy > 1000 * 100; |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 509 | pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 510 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 511 | /* Set the reference clock to sysclk reference */ |
| 512 | pi->refsel = HDMI_REFSEL_SYSCLK; |
| 513 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 514 | DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf); |
| 515 | DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd); |
| 516 | } |
| 517 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 518 | static int hdmi_power_on_core(struct omap_dss_device *dssdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 519 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 520 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 521 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 522 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 1); |
| 523 | gpio_set_value(hdmi.ls_oe_gpio, 1); |
| 524 | |
Tomi Valkeinen | a84b20654b | 2012-04-26 14:58:41 +0300 | [diff] [blame] | 525 | /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */ |
| 526 | udelay(300); |
| 527 | |
Tomi Valkeinen | 1748694 | 2012-08-15 15:55:04 +0300 | [diff] [blame] | 528 | r = regulator_enable(hdmi.vdda_hdmi_dac_reg); |
| 529 | if (r) |
| 530 | goto err_vdac_enable; |
| 531 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 532 | r = hdmi_runtime_get(); |
| 533 | if (r) |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 534 | goto err_runtime_get; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 535 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 536 | /* Make selection of HDMI in DSS */ |
| 537 | dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); |
| 538 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 539 | return 0; |
| 540 | |
| 541 | err_runtime_get: |
| 542 | regulator_disable(hdmi.vdda_hdmi_dac_reg); |
| 543 | err_vdac_enable: |
| 544 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 0); |
| 545 | gpio_set_value(hdmi.ls_oe_gpio, 0); |
| 546 | return r; |
| 547 | } |
| 548 | |
| 549 | static void hdmi_power_off_core(struct omap_dss_device *dssdev) |
| 550 | { |
| 551 | hdmi_runtime_put(); |
| 552 | regulator_disable(hdmi.vdda_hdmi_dac_reg); |
| 553 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 0); |
| 554 | gpio_set_value(hdmi.ls_oe_gpio, 0); |
| 555 | } |
| 556 | |
| 557 | static int hdmi_power_on_full(struct omap_dss_device *dssdev) |
| 558 | { |
| 559 | int r; |
| 560 | struct omap_video_timings *p; |
| 561 | struct omap_overlay_manager *mgr = dssdev->output->manager; |
| 562 | unsigned long phy; |
| 563 | |
| 564 | r = hdmi_power_on_core(dssdev); |
| 565 | if (r) |
| 566 | return r; |
| 567 | |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 568 | dss_mgr_disable(mgr); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 569 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 570 | p = &hdmi.ip_data.cfg.timings; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 571 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 572 | DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 573 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 574 | phy = p->pixel_clock; |
| 575 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 576 | hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 577 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 578 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 579 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 580 | /* config the PLL and PHY hdmi_set_pll_pwrfirst */ |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 581 | r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 582 | if (r) { |
| 583 | DSSDBG("Failed to lock PLL\n"); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 584 | goto err_pll_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 585 | } |
| 586 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 587 | r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 588 | if (r) { |
| 589 | DSSDBG("Failed to start PHY\n"); |
Ricardo Neri | d3b4aa5 | 2012-07-30 19:12:02 -0500 | [diff] [blame] | 590 | goto err_phy_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 591 | } |
| 592 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 593 | hdmi.ip_data.ops->video_configure(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 594 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 595 | /* bypass TV gamma table */ |
| 596 | dispc_enable_gamma_table(0); |
| 597 | |
| 598 | /* tv size */ |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 599 | dss_mgr_set_timings(mgr, p); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 600 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 601 | r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data); |
| 602 | if (r) |
| 603 | goto err_vid_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 604 | |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 605 | r = dss_mgr_enable(mgr); |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 606 | if (r) |
| 607 | goto err_mgr_enable; |
Tomi Valkeinen | 3870c90 | 2011-08-31 14:47:11 +0300 | [diff] [blame] | 608 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 609 | return 0; |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 610 | |
| 611 | err_mgr_enable: |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 612 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
| 613 | err_vid_enable: |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 614 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
Ricardo Neri | d3b4aa5 | 2012-07-30 19:12:02 -0500 | [diff] [blame] | 615 | err_phy_enable: |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 616 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 617 | err_pll_enable: |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 618 | hdmi_power_off_core(dssdev); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 619 | return -EIO; |
| 620 | } |
| 621 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 622 | static void hdmi_power_off_full(struct omap_dss_device *dssdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 623 | { |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 624 | struct omap_overlay_manager *mgr = dssdev->output->manager; |
| 625 | |
| 626 | dss_mgr_disable(mgr); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 627 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 628 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 629 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
| 630 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 631 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 632 | hdmi_power_off_core(dssdev); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev, |
| 636 | struct omap_video_timings *timings) |
| 637 | { |
| 638 | struct hdmi_cm cm; |
| 639 | |
| 640 | cm = hdmi_get_code(timings); |
| 641 | if (cm.code == -1) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 642 | return -EINVAL; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | |
| 647 | } |
| 648 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 649 | void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev, |
| 650 | struct omap_video_timings *timings) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 651 | { |
| 652 | struct hdmi_cm cm; |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 653 | const struct hdmi_config *t; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 654 | |
Archit Taneja | ed1aa90 | 2012-08-15 00:40:31 +0530 | [diff] [blame] | 655 | mutex_lock(&hdmi.lock); |
| 656 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 657 | cm = hdmi_get_code(timings); |
| 658 | hdmi.ip_data.cfg.cm = cm; |
| 659 | |
| 660 | t = hdmi_get_timings(); |
| 661 | if (t != NULL) |
| 662 | hdmi.ip_data.cfg = *t; |
Tomi Valkeinen | fa70dc5 | 2011-08-22 14:57:33 +0300 | [diff] [blame] | 663 | |
Archit Taneja | ed1aa90 | 2012-08-15 00:40:31 +0530 | [diff] [blame] | 664 | mutex_unlock(&hdmi.lock); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 665 | } |
| 666 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 667 | static void hdmi_dump_regs(struct seq_file *s) |
Mythri P K | 162874d | 2011-09-22 13:37:45 +0530 | [diff] [blame] | 668 | { |
| 669 | mutex_lock(&hdmi.lock); |
| 670 | |
Wei Yongjun | f8fb7d7 | 2012-10-21 20:54:26 +0800 | [diff] [blame] | 671 | if (hdmi_runtime_get()) { |
| 672 | mutex_unlock(&hdmi.lock); |
Mythri P K | 162874d | 2011-09-22 13:37:45 +0530 | [diff] [blame] | 673 | return; |
Wei Yongjun | f8fb7d7 | 2012-10-21 20:54:26 +0800 | [diff] [blame] | 674 | } |
Mythri P K | 162874d | 2011-09-22 13:37:45 +0530 | [diff] [blame] | 675 | |
| 676 | hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s); |
| 677 | hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s); |
| 678 | hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s); |
| 679 | hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s); |
| 680 | |
| 681 | hdmi_runtime_put(); |
| 682 | mutex_unlock(&hdmi.lock); |
| 683 | } |
| 684 | |
Tomi Valkeinen | 4702456 | 2011-08-25 17:12:56 +0300 | [diff] [blame] | 685 | int omapdss_hdmi_read_edid(u8 *buf, int len) |
| 686 | { |
| 687 | int r; |
| 688 | |
| 689 | mutex_lock(&hdmi.lock); |
| 690 | |
| 691 | r = hdmi_runtime_get(); |
| 692 | BUG_ON(r); |
| 693 | |
| 694 | r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len); |
| 695 | |
| 696 | hdmi_runtime_put(); |
| 697 | mutex_unlock(&hdmi.lock); |
| 698 | |
| 699 | return r; |
| 700 | } |
| 701 | |
Tomi Valkeinen | 759593f | 2011-08-29 18:10:20 +0300 | [diff] [blame] | 702 | bool omapdss_hdmi_detect(void) |
| 703 | { |
| 704 | int r; |
| 705 | |
| 706 | mutex_lock(&hdmi.lock); |
| 707 | |
| 708 | r = hdmi_runtime_get(); |
| 709 | BUG_ON(r); |
| 710 | |
| 711 | r = hdmi.ip_data.ops->detect(&hdmi.ip_data); |
| 712 | |
| 713 | hdmi_runtime_put(); |
| 714 | mutex_unlock(&hdmi.lock); |
| 715 | |
| 716 | return r == 1; |
| 717 | } |
| 718 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 719 | int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev) |
| 720 | { |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 721 | struct omap_dss_output *out = dssdev->output; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 722 | int r = 0; |
| 723 | |
| 724 | DSSDBG("ENTER hdmi_display_enable\n"); |
| 725 | |
| 726 | mutex_lock(&hdmi.lock); |
| 727 | |
Archit Taneja | cea87b9 | 2012-09-07 17:56:20 +0530 | [diff] [blame] | 728 | if (out == NULL || out->manager == NULL) { |
| 729 | DSSERR("failed to enable display: no output/manager\n"); |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 730 | r = -ENODEV; |
| 731 | goto err0; |
| 732 | } |
| 733 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 734 | hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio; |
Tomi Valkeinen | c49d005 | 2012-01-17 11:09:57 +0200 | [diff] [blame] | 735 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 736 | r = omap_dss_start_device(dssdev); |
| 737 | if (r) { |
| 738 | DSSERR("failed to start device\n"); |
| 739 | goto err0; |
| 740 | } |
| 741 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 742 | r = hdmi_power_on_full(dssdev); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 743 | if (r) { |
| 744 | DSSERR("failed to power on device\n"); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 745 | goto err1; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | mutex_unlock(&hdmi.lock); |
| 749 | return 0; |
| 750 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 751 | err1: |
| 752 | omap_dss_stop_device(dssdev); |
| 753 | err0: |
| 754 | mutex_unlock(&hdmi.lock); |
| 755 | return r; |
| 756 | } |
| 757 | |
| 758 | void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev) |
| 759 | { |
| 760 | DSSDBG("Enter hdmi_display_disable\n"); |
| 761 | |
| 762 | mutex_lock(&hdmi.lock); |
| 763 | |
Tomi Valkeinen | bb426fc9 | 2012-10-19 17:42:10 +0300 | [diff] [blame] | 764 | hdmi_power_off_full(dssdev); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 765 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 766 | omap_dss_stop_device(dssdev); |
| 767 | |
| 768 | mutex_unlock(&hdmi.lock); |
| 769 | } |
| 770 | |
Tomi Valkeinen | 4489823 | 2012-10-19 17:42:27 +0300 | [diff] [blame] | 771 | int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev) |
| 772 | { |
| 773 | int r = 0; |
| 774 | |
| 775 | DSSDBG("ENTER omapdss_hdmi_core_enable\n"); |
| 776 | |
| 777 | mutex_lock(&hdmi.lock); |
| 778 | |
| 779 | hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio; |
| 780 | |
| 781 | r = hdmi_power_on_core(dssdev); |
| 782 | if (r) { |
| 783 | DSSERR("failed to power on device\n"); |
| 784 | goto err0; |
| 785 | } |
| 786 | |
| 787 | mutex_unlock(&hdmi.lock); |
| 788 | return 0; |
| 789 | |
| 790 | err0: |
| 791 | mutex_unlock(&hdmi.lock); |
| 792 | return r; |
| 793 | } |
| 794 | |
| 795 | void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev) |
| 796 | { |
| 797 | DSSDBG("Enter omapdss_hdmi_core_disable\n"); |
| 798 | |
| 799 | mutex_lock(&hdmi.lock); |
| 800 | |
| 801 | hdmi_power_off_core(dssdev); |
| 802 | |
| 803 | mutex_unlock(&hdmi.lock); |
| 804 | } |
| 805 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 806 | static int hdmi_get_clocks(struct platform_device *pdev) |
| 807 | { |
| 808 | struct clk *clk; |
| 809 | |
| 810 | clk = clk_get(&pdev->dev, "sys_clk"); |
| 811 | if (IS_ERR(clk)) { |
| 812 | DSSERR("can't get sys_clk\n"); |
| 813 | return PTR_ERR(clk); |
| 814 | } |
| 815 | |
| 816 | hdmi.sys_clk = clk; |
| 817 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static void hdmi_put_clocks(void) |
| 822 | { |
| 823 | if (hdmi.sys_clk) |
| 824 | clk_put(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 825 | } |
| 826 | |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 827 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
Ricardo Neri | 14840b9 | 2012-11-06 00:19:17 -0600 | [diff] [blame] | 828 | static int hdmi_probe_audio(struct platform_device *pdev) |
| 829 | { |
| 830 | struct resource *res; |
| 831 | struct platform_device *aud_pdev; |
| 832 | u32 port_offset, port_size; |
| 833 | struct resource aud_res[2] = { |
| 834 | DEFINE_RES_MEM(-1, -1), |
| 835 | DEFINE_RES_DMA(-1), |
| 836 | }; |
| 837 | |
| 838 | res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0); |
| 839 | if (!res) { |
| 840 | DSSERR("can't get IORESOURCE_MEM HDMI\n"); |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | |
| 844 | /* |
| 845 | * Pass DMA audio port to audio drivers. |
| 846 | * Audio drivers should not ioremap it. |
| 847 | */ |
| 848 | hdmi.ip_data.ops->audio_get_dma_port(&port_offset, &port_size); |
| 849 | |
| 850 | aud_res[0].start = res->start + port_offset; |
| 851 | aud_res[0].end = aud_res[0].start + port_size - 1; |
| 852 | |
| 853 | res = platform_get_resource(hdmi.pdev, IORESOURCE_DMA, 0); |
| 854 | if (!res) { |
| 855 | DSSERR("can't get IORESOURCE_DMA HDMI\n"); |
| 856 | return -EINVAL; |
| 857 | } |
| 858 | |
| 859 | /* Pass the audio DMA request resource to audio drivers. */ |
| 860 | aud_res[1].start = res->start; |
| 861 | |
| 862 | /* create platform device for HDMI audio driver */ |
| 863 | aud_pdev = platform_device_register_simple("omap_hdmi_audio", |
| 864 | pdev->id, aud_res, |
| 865 | ARRAY_SIZE(aud_res)); |
| 866 | if (IS_ERR(aud_pdev)) { |
| 867 | DSSERR("Can't instantiate hdmi-audio\n"); |
| 868 | return -ENODEV; |
| 869 | } |
| 870 | |
| 871 | hdmi.audio_pdev = aud_pdev; |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 876 | int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts) |
| 877 | { |
| 878 | u32 deep_color; |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 879 | bool deep_color_correct = false; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 880 | u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock; |
| 881 | |
| 882 | if (n == NULL || cts == NULL) |
| 883 | return -EINVAL; |
| 884 | |
| 885 | /* TODO: When implemented, query deep color mode here. */ |
| 886 | deep_color = 100; |
| 887 | |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 888 | /* |
| 889 | * When using deep color, the default N value (as in the HDMI |
| 890 | * specification) yields to an non-integer CTS. Hence, we |
| 891 | * modify it while keeping the restrictions described in |
| 892 | * section 7.2.1 of the HDMI 1.4a specification. |
| 893 | */ |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 894 | switch (sample_freq) { |
| 895 | case 32000: |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 896 | case 48000: |
| 897 | case 96000: |
| 898 | case 192000: |
| 899 | if (deep_color == 125) |
| 900 | if (pclk == 27027 || pclk == 74250) |
| 901 | deep_color_correct = true; |
| 902 | if (deep_color == 150) |
| 903 | if (pclk == 27027) |
| 904 | deep_color_correct = true; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 905 | break; |
| 906 | case 44100: |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 907 | case 88200: |
| 908 | case 176400: |
| 909 | if (deep_color == 125) |
| 910 | if (pclk == 27027) |
| 911 | deep_color_correct = true; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 912 | break; |
| 913 | default: |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 914 | return -EINVAL; |
| 915 | } |
| 916 | |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 917 | if (deep_color_correct) { |
| 918 | switch (sample_freq) { |
| 919 | case 32000: |
| 920 | *n = 8192; |
| 921 | break; |
| 922 | case 44100: |
| 923 | *n = 12544; |
| 924 | break; |
| 925 | case 48000: |
| 926 | *n = 8192; |
| 927 | break; |
| 928 | case 88200: |
| 929 | *n = 25088; |
| 930 | break; |
| 931 | case 96000: |
| 932 | *n = 16384; |
| 933 | break; |
| 934 | case 176400: |
| 935 | *n = 50176; |
| 936 | break; |
| 937 | case 192000: |
| 938 | *n = 32768; |
| 939 | break; |
| 940 | default: |
| 941 | return -EINVAL; |
| 942 | } |
| 943 | } else { |
| 944 | switch (sample_freq) { |
| 945 | case 32000: |
| 946 | *n = 4096; |
| 947 | break; |
| 948 | case 44100: |
| 949 | *n = 6272; |
| 950 | break; |
| 951 | case 48000: |
| 952 | *n = 6144; |
| 953 | break; |
| 954 | case 88200: |
| 955 | *n = 12544; |
| 956 | break; |
| 957 | case 96000: |
| 958 | *n = 12288; |
| 959 | break; |
| 960 | case 176400: |
| 961 | *n = 25088; |
| 962 | break; |
| 963 | case 192000: |
| 964 | *n = 24576; |
| 965 | break; |
| 966 | default: |
| 967 | return -EINVAL; |
| 968 | } |
| 969 | } |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 970 | /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */ |
| 971 | *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10); |
| 972 | |
| 973 | return 0; |
| 974 | } |
Ricardo Neri | f3a97491 | 2012-05-09 21:09:50 -0500 | [diff] [blame] | 975 | |
| 976 | int hdmi_audio_enable(void) |
| 977 | { |
| 978 | DSSDBG("audio_enable\n"); |
| 979 | |
| 980 | return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data); |
| 981 | } |
| 982 | |
| 983 | void hdmi_audio_disable(void) |
| 984 | { |
| 985 | DSSDBG("audio_disable\n"); |
| 986 | |
| 987 | hdmi.ip_data.ops->audio_disable(&hdmi.ip_data); |
| 988 | } |
| 989 | |
| 990 | int hdmi_audio_start(void) |
| 991 | { |
| 992 | DSSDBG("audio_start\n"); |
| 993 | |
| 994 | return hdmi.ip_data.ops->audio_start(&hdmi.ip_data); |
| 995 | } |
| 996 | |
| 997 | void hdmi_audio_stop(void) |
| 998 | { |
| 999 | DSSDBG("audio_stop\n"); |
| 1000 | |
| 1001 | hdmi.ip_data.ops->audio_stop(&hdmi.ip_data); |
| 1002 | } |
| 1003 | |
| 1004 | bool hdmi_mode_has_audio(void) |
| 1005 | { |
| 1006 | if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI) |
| 1007 | return true; |
| 1008 | else |
| 1009 | return false; |
| 1010 | } |
| 1011 | |
| 1012 | int hdmi_audio_config(struct omap_dss_audio *audio) |
| 1013 | { |
| 1014 | return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio); |
| 1015 | } |
| 1016 | |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 1017 | #endif |
| 1018 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1019 | static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev) |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1020 | { |
| 1021 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
Tomi Valkeinen | 2bbcce5 | 2012-10-29 12:40:46 +0200 | [diff] [blame] | 1022 | const char *def_disp_name = omapdss_get_default_display_name(); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1023 | struct omap_dss_device *def_dssdev; |
| 1024 | int i; |
| 1025 | |
| 1026 | def_dssdev = NULL; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1027 | |
| 1028 | for (i = 0; i < pdata->num_devices; ++i) { |
| 1029 | struct omap_dss_device *dssdev = pdata->devices[i]; |
| 1030 | |
| 1031 | if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI) |
| 1032 | continue; |
| 1033 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1034 | if (def_dssdev == NULL) |
| 1035 | def_dssdev = dssdev; |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 1036 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1037 | if (def_disp_name != NULL && |
| 1038 | strcmp(dssdev->name, def_disp_name) == 0) { |
| 1039 | def_dssdev = dssdev; |
| 1040 | break; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1041 | } |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1042 | } |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1043 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1044 | return def_dssdev; |
| 1045 | } |
| 1046 | |
| 1047 | static void __init hdmi_probe_pdata(struct platform_device *pdev) |
| 1048 | { |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1049 | struct omap_dss_device *plat_dssdev; |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1050 | struct omap_dss_device *dssdev; |
| 1051 | struct omap_dss_hdmi_data *priv; |
| 1052 | int r; |
| 1053 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1054 | plat_dssdev = hdmi_find_dssdev(pdev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1055 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1056 | if (!plat_dssdev) |
| 1057 | return; |
| 1058 | |
| 1059 | dssdev = dss_alloc_and_init_device(&pdev->dev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1060 | if (!dssdev) |
| 1061 | return; |
| 1062 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1063 | dss_copy_device_pdata(dssdev, plat_dssdev); |
| 1064 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1065 | priv = dssdev->data; |
| 1066 | |
| 1067 | hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio; |
| 1068 | hdmi.ls_oe_gpio = priv->ls_oe_gpio; |
| 1069 | hdmi.hpd_gpio = priv->hpd_gpio; |
| 1070 | |
Tomi Valkeinen | bcb226a | 2012-09-07 15:21:36 +0300 | [diff] [blame] | 1071 | dssdev->channel = OMAP_DSS_CHANNEL_DIGIT; |
| 1072 | |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1073 | r = hdmi_init_display(dssdev); |
| 1074 | if (r) { |
| 1075 | DSSERR("device %s init failed: %d\n", dssdev->name, r); |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1076 | dss_put_device(dssdev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1080 | r = dss_add_device(dssdev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1081 | if (r) { |
| 1082 | DSSERR("device %s register failed: %d\n", dssdev->name, r); |
Ricardo Neri | d18bc45 | 2012-11-06 00:19:15 -0600 | [diff] [blame] | 1083 | hdmi_uninit_display(dssdev); |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1084 | dss_put_device(dssdev); |
Tomi Valkeinen | 1521653 | 2012-09-06 14:29:31 +0300 | [diff] [blame] | 1085 | return; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 1089 | static void __init hdmi_init_output(struct platform_device *pdev) |
| 1090 | { |
| 1091 | struct omap_dss_output *out = &hdmi.output; |
| 1092 | |
| 1093 | out->pdev = pdev; |
| 1094 | out->id = OMAP_DSS_OUTPUT_HDMI; |
| 1095 | out->type = OMAP_DISPLAY_TYPE_HDMI; |
| 1096 | |
| 1097 | dss_register_output(out); |
| 1098 | } |
| 1099 | |
| 1100 | static void __exit hdmi_uninit_output(struct platform_device *pdev) |
| 1101 | { |
| 1102 | struct omap_dss_output *out = &hdmi.output; |
| 1103 | |
| 1104 | dss_unregister_output(out); |
| 1105 | } |
| 1106 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1107 | /* HDMI HW IP initialisation */ |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1108 | static int __init omapdss_hdmihw_probe(struct platform_device *pdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1109 | { |
Ricardo Neri | af23cb3 | 2012-11-06 00:19:11 -0600 | [diff] [blame] | 1110 | struct resource *res; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1111 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1112 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1113 | hdmi.pdev = pdev; |
| 1114 | |
| 1115 | mutex_init(&hdmi.lock); |
Ricardo Neri | 66a06b0 | 2012-11-06 00:19:14 -0600 | [diff] [blame] | 1116 | mutex_init(&hdmi.ip_data.lock); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1117 | |
Ricardo Neri | af23cb3 | 2012-11-06 00:19:11 -0600 | [diff] [blame] | 1118 | res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0); |
| 1119 | if (!res) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1120 | DSSERR("can't get IORESOURCE_MEM HDMI\n"); |
| 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
| 1124 | /* Base address taken from platform */ |
Ricardo Neri | 47e443b | 2012-11-06 00:19:12 -0600 | [diff] [blame] | 1125 | hdmi.ip_data.base_wp = devm_request_and_ioremap(&pdev->dev, res); |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 1126 | if (!hdmi.ip_data.base_wp) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1127 | DSSERR("can't ioremap WP\n"); |
| 1128 | return -ENOMEM; |
| 1129 | } |
| 1130 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1131 | r = hdmi_get_clocks(pdev); |
| 1132 | if (r) { |
Ricardo Neri | 47e443b | 2012-11-06 00:19:12 -0600 | [diff] [blame] | 1133 | DSSERR("can't get clocks\n"); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1134 | return r; |
| 1135 | } |
| 1136 | |
| 1137 | pm_runtime_enable(&pdev->dev); |
| 1138 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 1139 | hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS; |
| 1140 | hdmi.ip_data.core_av_offset = HDMI_CORE_AV; |
| 1141 | hdmi.ip_data.pll_offset = HDMI_PLLCTRL; |
| 1142 | hdmi.ip_data.phy_offset = HDMI_PHY; |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 1143 | |
Ricardo Neri | 66a06b0 | 2012-11-06 00:19:14 -0600 | [diff] [blame] | 1144 | r = hdmi_panel_init(); |
| 1145 | if (r) { |
| 1146 | DSSERR("can't init panel\n"); |
| 1147 | goto err_panel_init; |
| 1148 | } |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1149 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 1150 | dss_debugfs_create_file("hdmi", hdmi_dump_regs); |
| 1151 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 1152 | hdmi_init_output(pdev); |
| 1153 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 1154 | hdmi_probe_pdata(pdev); |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 1155 | |
Ricardo Neri | 14840b9 | 2012-11-06 00:19:17 -0600 | [diff] [blame] | 1156 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
| 1157 | r = hdmi_probe_audio(pdev); |
| 1158 | if (r) |
| 1159 | DSSWARN("could not create platform device for audio"); |
| 1160 | #endif |
| 1161 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1162 | return 0; |
Ricardo Neri | 66a06b0 | 2012-11-06 00:19:14 -0600 | [diff] [blame] | 1163 | |
| 1164 | err_panel_init: |
| 1165 | hdmi_put_clocks(); |
| 1166 | return r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1167 | } |
| 1168 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 1169 | static int __exit hdmi_remove_child(struct device *dev, void *data) |
| 1170 | { |
| 1171 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 1172 | hdmi_uninit_display(dssdev); |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1176 | static int __exit omapdss_hdmihw_remove(struct platform_device *pdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1177 | { |
Ricardo Neri | 14840b9 | 2012-11-06 00:19:17 -0600 | [diff] [blame] | 1178 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
| 1179 | if (hdmi.audio_pdev != NULL) |
| 1180 | platform_device_unregister(hdmi.audio_pdev); |
| 1181 | #endif |
| 1182 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame] | 1183 | device_for_each_child(&pdev->dev, NULL, hdmi_remove_child); |
| 1184 | |
Tomi Valkeinen | 5274484 | 2012-09-10 13:58:29 +0300 | [diff] [blame] | 1185 | dss_unregister_child_devices(&pdev->dev); |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 1186 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1187 | hdmi_panel_exit(); |
| 1188 | |
Archit Taneja | 81b87f5 | 2012-09-26 16:30:49 +0530 | [diff] [blame] | 1189 | hdmi_uninit_output(pdev); |
| 1190 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1191 | pm_runtime_disable(&pdev->dev); |
| 1192 | |
| 1193 | hdmi_put_clocks(); |
| 1194 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
| 1197 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1198 | static int hdmi_runtime_suspend(struct device *dev) |
| 1199 | { |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1200 | clk_disable_unprepare(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1201 | |
| 1202 | dispc_runtime_put(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | static int hdmi_runtime_resume(struct device *dev) |
| 1208 | { |
| 1209 | int r; |
| 1210 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1211 | r = dispc_runtime_get(); |
| 1212 | if (r < 0) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 1213 | return r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1214 | |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1215 | clk_prepare_enable(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1216 | |
| 1217 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | static const struct dev_pm_ops hdmi_pm_ops = { |
| 1221 | .runtime_suspend = hdmi_runtime_suspend, |
| 1222 | .runtime_resume = hdmi_runtime_resume, |
| 1223 | }; |
| 1224 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1225 | static struct platform_driver omapdss_hdmihw_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1226 | .remove = __exit_p(omapdss_hdmihw_remove), |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1227 | .driver = { |
| 1228 | .name = "omapdss_hdmi", |
| 1229 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1230 | .pm = &hdmi_pm_ops, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1231 | }, |
| 1232 | }; |
| 1233 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1234 | int __init hdmi_init_platform_driver(void) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1235 | { |
Tomi Valkeinen | 61055d4 | 2012-03-07 12:53:38 +0200 | [diff] [blame] | 1236 | return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1237 | } |
| 1238 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1239 | void __exit hdmi_uninit_platform_driver(void) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1240 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 1241 | platform_driver_unregister(&omapdss_hdmihw_driver); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1242 | } |