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 | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 36 | #include <video/omapdss.h> |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 37 | |
Mythri P K | 94c5298 | 2011-09-08 19:06:21 +0530 | [diff] [blame] | 38 | #include "ti_hdmi.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 39 | #include "dss.h" |
Ricardo Neri | ad44cc3 | 2011-05-18 22:31:56 -0500 | [diff] [blame] | 40 | #include "dss_features.h" |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 41 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 42 | #define HDMI_WP 0x0 |
| 43 | #define HDMI_CORE_SYS 0x400 |
| 44 | #define HDMI_CORE_AV 0x900 |
| 45 | #define HDMI_PLLCTRL 0x200 |
| 46 | #define HDMI_PHY 0x300 |
| 47 | |
Mythri P K | 7c1f1ec | 2011-09-08 19:06:22 +0530 | [diff] [blame] | 48 | /* HDMI EDID Length move this */ |
| 49 | #define HDMI_EDID_MAX_LENGTH 256 |
| 50 | #define EDID_TIMING_DESCRIPTOR_SIZE 0x12 |
| 51 | #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36 |
| 52 | #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80 |
| 53 | #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4 |
| 54 | #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4 |
| 55 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 56 | #define HDMI_DEFAULT_REGN 16 |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 57 | #define HDMI_DEFAULT_REGM2 1 |
| 58 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 59 | static struct { |
| 60 | struct mutex lock; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 61 | struct platform_device *pdev; |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 62 | struct hdmi_ip_data ip_data; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 63 | |
| 64 | struct clk *sys_clk; |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 65 | |
| 66 | int ct_cp_hpd_gpio; |
| 67 | int ls_oe_gpio; |
| 68 | int hpd_gpio; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 69 | } hdmi; |
| 70 | |
| 71 | /* |
| 72 | * Logic for the below structure : |
| 73 | * user enters the CEA or VESA timings by specifying the HDMI/DVI code. |
| 74 | * There is a correspondence between CEA/VESA timing and code, please |
| 75 | * refer to section 6.3 in HDMI 1.3 specification for timing code. |
| 76 | * |
| 77 | * In the below structure, cea_vesa_timings corresponds to all OMAP4 |
| 78 | * supported CEA and VESA timing values.code_cea corresponds to the CEA |
| 79 | * code, It is used to get the timing from cea_vesa_timing array.Similarly |
| 80 | * with code_vesa. Code_index is used for back mapping, that is once EDID |
| 81 | * is read from the TV, EDID is parsed to find the timing values and then |
| 82 | * map it to corresponding CEA or VESA index. |
| 83 | */ |
| 84 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 85 | static const struct hdmi_config cea_timings[] = { |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 86 | { |
| 87 | { 640, 480, 25200, 96, 16, 48, 2, 10, 33, |
| 88 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 89 | false, }, |
| 90 | { 1, HDMI_HDMI }, |
| 91 | }, |
| 92 | { |
| 93 | { 720, 480, 27027, 62, 16, 60, 6, 9, 30, |
| 94 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 95 | false, }, |
| 96 | { 2, HDMI_HDMI }, |
| 97 | }, |
| 98 | { |
| 99 | { 1280, 720, 74250, 40, 110, 220, 5, 5, 20, |
| 100 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 101 | false, }, |
| 102 | { 4, HDMI_HDMI }, |
| 103 | }, |
| 104 | { |
| 105 | { 1920, 540, 74250, 44, 88, 148, 5, 2, 15, |
| 106 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 107 | true, }, |
| 108 | { 5, HDMI_HDMI }, |
| 109 | }, |
| 110 | { |
| 111 | { 1440, 240, 27027, 124, 38, 114, 3, 4, 15, |
| 112 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 113 | true, }, |
| 114 | { 6, HDMI_HDMI }, |
| 115 | }, |
| 116 | { |
| 117 | { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36, |
| 118 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 119 | false, }, |
| 120 | { 16, HDMI_HDMI }, |
| 121 | }, |
| 122 | { |
| 123 | { 720, 576, 27000, 64, 12, 68, 5, 5, 39, |
| 124 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 125 | false, }, |
| 126 | { 17, HDMI_HDMI }, |
| 127 | }, |
| 128 | { |
| 129 | { 1280, 720, 74250, 40, 440, 220, 5, 5, 20, |
| 130 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 131 | false, }, |
| 132 | { 19, HDMI_HDMI }, |
| 133 | }, |
| 134 | { |
| 135 | { 1920, 540, 74250, 44, 528, 148, 5, 2, 15, |
| 136 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 137 | true, }, |
| 138 | { 20, HDMI_HDMI }, |
| 139 | }, |
| 140 | { |
| 141 | { 1440, 288, 27000, 126, 24, 138, 3, 2, 19, |
| 142 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 143 | true, }, |
| 144 | { 21, HDMI_HDMI }, |
| 145 | }, |
| 146 | { |
| 147 | { 1440, 576, 54000, 128, 24, 136, 5, 5, 39, |
| 148 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 149 | false, }, |
| 150 | { 29, HDMI_HDMI }, |
| 151 | }, |
| 152 | { |
| 153 | { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36, |
| 154 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 155 | false, }, |
| 156 | { 31, HDMI_HDMI }, |
| 157 | }, |
| 158 | { |
| 159 | { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36, |
| 160 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 161 | false, }, |
| 162 | { 32, HDMI_HDMI }, |
| 163 | }, |
| 164 | { |
| 165 | { 2880, 480, 108108, 248, 64, 240, 6, 9, 30, |
| 166 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 167 | false, }, |
| 168 | { 35, HDMI_HDMI }, |
| 169 | }, |
| 170 | { |
| 171 | { 2880, 576, 108000, 256, 48, 272, 5, 5, 39, |
| 172 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 173 | false, }, |
| 174 | { 37, HDMI_HDMI }, |
| 175 | }, |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 176 | }; |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 177 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 178 | static const struct hdmi_config vesa_timings[] = { |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame] | 179 | /* VESA From Here */ |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 180 | { |
| 181 | { 640, 480, 25175, 96, 16, 48, 2, 11, 31, |
| 182 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 183 | false, }, |
| 184 | { 4, HDMI_DVI }, |
| 185 | }, |
| 186 | { |
| 187 | { 800, 600, 40000, 128, 40, 88, 4, 1, 23, |
| 188 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 189 | false, }, |
| 190 | { 9, HDMI_DVI }, |
| 191 | }, |
| 192 | { |
| 193 | { 848, 480, 33750, 112, 16, 112, 8, 6, 23, |
| 194 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 195 | false, }, |
| 196 | { 0xE, HDMI_DVI }, |
| 197 | }, |
| 198 | { |
| 199 | { 1280, 768, 79500, 128, 64, 192, 7, 3, 20, |
| 200 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 201 | false, }, |
| 202 | { 0x17, HDMI_DVI }, |
| 203 | }, |
| 204 | { |
| 205 | { 1280, 800, 83500, 128, 72, 200, 6, 3, 22, |
| 206 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 207 | false, }, |
| 208 | { 0x1C, HDMI_DVI }, |
| 209 | }, |
| 210 | { |
| 211 | { 1360, 768, 85500, 112, 64, 256, 6, 3, 18, |
| 212 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 213 | false, }, |
| 214 | { 0x27, HDMI_DVI }, |
| 215 | }, |
| 216 | { |
| 217 | { 1280, 960, 108000, 112, 96, 312, 3, 1, 36, |
| 218 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 219 | false, }, |
| 220 | { 0x20, HDMI_DVI }, |
| 221 | }, |
| 222 | { |
| 223 | { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38, |
| 224 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 225 | false, }, |
| 226 | { 0x23, HDMI_DVI }, |
| 227 | }, |
| 228 | { |
| 229 | { 1024, 768, 65000, 136, 24, 160, 6, 3, 29, |
| 230 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW, |
| 231 | false, }, |
| 232 | { 0x10, HDMI_DVI }, |
| 233 | }, |
| 234 | { |
| 235 | { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32, |
| 236 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 237 | false, }, |
| 238 | { 0x2A, HDMI_DVI }, |
| 239 | }, |
| 240 | { |
| 241 | { 1440, 900, 106500, 152, 80, 232, 6, 3, 25, |
| 242 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 243 | false, }, |
| 244 | { 0x2F, HDMI_DVI }, |
| 245 | }, |
| 246 | { |
| 247 | { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30, |
| 248 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW, |
| 249 | false, }, |
| 250 | { 0x3A, HDMI_DVI }, |
| 251 | }, |
| 252 | { |
| 253 | { 1366, 768, 85500, 143, 70, 213, 3, 3, 24, |
| 254 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 255 | false, }, |
| 256 | { 0x51, HDMI_DVI }, |
| 257 | }, |
| 258 | { |
| 259 | { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36, |
| 260 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 261 | false, }, |
| 262 | { 0x52, HDMI_DVI }, |
| 263 | }, |
| 264 | { |
| 265 | { 1280, 768, 68250, 32, 48, 80, 7, 3, 12, |
| 266 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 267 | false, }, |
| 268 | { 0x16, HDMI_DVI }, |
| 269 | }, |
| 270 | { |
| 271 | { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23, |
| 272 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 273 | false, }, |
| 274 | { 0x29, HDMI_DVI }, |
| 275 | }, |
| 276 | { |
| 277 | { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21, |
| 278 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 279 | false, }, |
| 280 | { 0x39, HDMI_DVI }, |
| 281 | }, |
| 282 | { |
| 283 | { 1280, 800, 79500, 32, 48, 80, 6, 3, 14, |
| 284 | OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH, |
| 285 | false, }, |
| 286 | { 0x1B, HDMI_DVI }, |
| 287 | }, |
| 288 | { |
| 289 | { 1280, 720, 74250, 40, 110, 220, 5, 5, 20, |
| 290 | OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH, |
| 291 | false, }, |
| 292 | { 0x55, HDMI_DVI }, |
| 293 | }, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 294 | }; |
| 295 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 296 | static int hdmi_runtime_get(void) |
| 297 | { |
| 298 | int r; |
| 299 | |
| 300 | DSSDBG("hdmi_runtime_get\n"); |
| 301 | |
| 302 | r = pm_runtime_get_sync(&hdmi.pdev->dev); |
| 303 | WARN_ON(r < 0); |
Archit Taneja | a247ce78 | 2012-02-10 11:45:52 +0530 | [diff] [blame] | 304 | if (r < 0) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 305 | return r; |
Archit Taneja | a247ce78 | 2012-02-10 11:45:52 +0530 | [diff] [blame] | 306 | |
| 307 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void hdmi_runtime_put(void) |
| 311 | { |
| 312 | int r; |
| 313 | |
| 314 | DSSDBG("hdmi_runtime_put\n"); |
| 315 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 316 | r = pm_runtime_put_sync(&hdmi.pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 317 | WARN_ON(r < 0 && r != -ENOSYS); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 318 | } |
| 319 | |
Tomi Valkeinen | 9d8232a | 2012-03-01 16:58:39 +0200 | [diff] [blame] | 320 | static int __init hdmi_init_display(struct omap_dss_device *dssdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 321 | { |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 322 | int r; |
| 323 | |
| 324 | struct gpio gpios[] = { |
| 325 | { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" }, |
| 326 | { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" }, |
| 327 | { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" }, |
| 328 | }; |
| 329 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 330 | DSSDBG("init_display\n"); |
| 331 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 332 | dss_init_hdmi_ip_ops(&hdmi.ip_data); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 333 | |
| 334 | r = gpio_request_array(gpios, ARRAY_SIZE(gpios)); |
| 335 | if (r) |
| 336 | return r; |
| 337 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 341 | static void __exit hdmi_uninit_display(struct omap_dss_device *dssdev) |
| 342 | { |
| 343 | DSSDBG("uninit_display\n"); |
| 344 | |
| 345 | gpio_free(hdmi.ct_cp_hpd_gpio); |
| 346 | gpio_free(hdmi.ls_oe_gpio); |
| 347 | gpio_free(hdmi.hpd_gpio); |
| 348 | } |
| 349 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 350 | static const struct hdmi_config *hdmi_find_timing( |
| 351 | const struct hdmi_config *timings_arr, |
| 352 | int len) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 353 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 354 | int i; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 355 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 356 | for (i = 0; i < len; i++) { |
Mythri P K | 9e4ed60 | 2012-01-06 17:52:10 +0530 | [diff] [blame] | 357 | 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] | 358 | return &timings_arr[i]; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 359 | } |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 360 | return NULL; |
| 361 | } |
| 362 | |
| 363 | static const struct hdmi_config *hdmi_get_timings(void) |
| 364 | { |
| 365 | const struct hdmi_config *arr; |
| 366 | int len; |
| 367 | |
Mythri P K | 9e4ed60 | 2012-01-06 17:52:10 +0530 | [diff] [blame] | 368 | if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 369 | arr = vesa_timings; |
| 370 | len = ARRAY_SIZE(vesa_timings); |
| 371 | } else { |
| 372 | arr = cea_timings; |
| 373 | len = ARRAY_SIZE(cea_timings); |
| 374 | } |
| 375 | |
| 376 | return hdmi_find_timing(arr, len); |
| 377 | } |
| 378 | |
| 379 | static bool hdmi_timings_compare(struct omap_video_timings *timing1, |
Archit Taneja | cc937e5 | 2012-06-24 13:08:10 +0530 | [diff] [blame] | 380 | const struct omap_video_timings *timing2) |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 381 | { |
| 382 | int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync; |
| 383 | |
| 384 | if ((timing2->pixel_clock == timing1->pixel_clock) && |
| 385 | (timing2->x_res == timing1->x_res) && |
| 386 | (timing2->y_res == timing1->y_res)) { |
| 387 | |
| 388 | timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp; |
| 389 | timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp; |
| 390 | timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp; |
| 391 | timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp; |
| 392 | |
| 393 | DSSDBG("timing1_hsync = %d timing1_vsync = %d"\ |
| 394 | "timing2_hsync = %d timing2_vsync = %d\n", |
| 395 | timing1_hsync, timing1_vsync, |
| 396 | timing2_hsync, timing2_vsync); |
| 397 | |
| 398 | if ((timing1_hsync == timing2_hsync) && |
| 399 | (timing1_vsync == timing2_vsync)) { |
| 400 | return true; |
| 401 | } |
| 402 | } |
| 403 | return false; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing) |
| 407 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 408 | int i; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 409 | struct hdmi_cm cm = {-1}; |
| 410 | DSSDBG("hdmi_get_code\n"); |
| 411 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 412 | for (i = 0; i < ARRAY_SIZE(cea_timings); i++) { |
| 413 | if (hdmi_timings_compare(timing, &cea_timings[i].timings)) { |
| 414 | cm = cea_timings[i].cm; |
| 415 | goto end; |
| 416 | } |
| 417 | } |
| 418 | for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) { |
| 419 | if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) { |
| 420 | cm = vesa_timings[i].cm; |
| 421 | goto end; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 425 | end: return cm; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 426 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 427 | } |
| 428 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 429 | unsigned long hdmi_get_pixel_clock(void) |
| 430 | { |
| 431 | /* HDMI Pixel Clock in Mhz */ |
Mythri P K | a05ce78 | 2012-01-06 17:52:08 +0530 | [diff] [blame] | 432 | return hdmi.ip_data.cfg.timings.pixel_clock * 1000; |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 433 | } |
| 434 | |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 435 | static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy, |
| 436 | struct hdmi_pll_info *pi) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 437 | { |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 438 | unsigned long clkin, refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 439 | u32 mf; |
| 440 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 441 | clkin = clk_get_rate(hdmi.sys_clk) / 10000; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 442 | /* |
| 443 | * Input clock is predivided by N + 1 |
| 444 | * out put of which is reference clk |
| 445 | */ |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 446 | if (dssdev->clocks.hdmi.regn == 0) |
| 447 | pi->regn = HDMI_DEFAULT_REGN; |
| 448 | else |
| 449 | pi->regn = dssdev->clocks.hdmi.regn; |
| 450 | |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 451 | refclk = clkin / pi->regn; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 452 | |
Tomi Valkeinen | 8d88767a | 2011-08-22 13:02:52 +0300 | [diff] [blame] | 453 | if (dssdev->clocks.hdmi.regm2 == 0) |
| 454 | pi->regm2 = HDMI_DEFAULT_REGM2; |
| 455 | else |
| 456 | pi->regm2 = dssdev->clocks.hdmi.regm2; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 457 | |
| 458 | /* |
Mythri P K | dd2116a | 2012-02-21 12:10:58 +0530 | [diff] [blame] | 459 | * multiplier is pixel_clk/ref_clk |
| 460 | * Multiplying by 100 to avoid fractional part removal |
| 461 | */ |
| 462 | pi->regm = phy * pi->regm2 / refclk; |
| 463 | |
| 464 | /* |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 465 | * fractional multiplier is remainder of the difference between |
| 466 | * multiplier and actual phy(required pixel clock thus should be |
| 467 | * multiplied by 2^18(262144) divided by the reference clock |
| 468 | */ |
Mythri P K | dd2116a | 2012-02-21 12:10:58 +0530 | [diff] [blame] | 469 | mf = (phy - pi->regm / pi->regm2 * refclk) * 262144; |
| 470 | pi->regmf = pi->regm2 * mf / refclk; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 471 | |
| 472 | /* |
| 473 | * Dcofreq should be set to 1 if required pixel clock |
| 474 | * is greater than 1000MHz |
| 475 | */ |
| 476 | pi->dcofreq = phy > 1000 * 100; |
Tomi Valkeinen | b44e458 | 2011-08-22 13:16:24 +0300 | [diff] [blame] | 477 | pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 478 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 479 | /* Set the reference clock to sysclk reference */ |
| 480 | pi->refsel = HDMI_REFSEL_SYSCLK; |
| 481 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 482 | DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf); |
| 483 | DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd); |
| 484 | } |
| 485 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 486 | static int hdmi_power_on(struct omap_dss_device *dssdev) |
| 487 | { |
Mythri P K | 46095b2 | 2012-01-06 17:52:09 +0530 | [diff] [blame] | 488 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 489 | struct omap_video_timings *p; |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 490 | unsigned long phy; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 491 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 492 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 1); |
| 493 | gpio_set_value(hdmi.ls_oe_gpio, 1); |
| 494 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 495 | r = hdmi_runtime_get(); |
| 496 | if (r) |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 497 | goto err_runtime_get; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 498 | |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 499 | dss_mgr_disable(dssdev->manager); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 500 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 501 | p = &hdmi.ip_data.cfg.timings; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 502 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 503 | 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] | 504 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 505 | phy = p->pixel_clock; |
| 506 | |
Mythri P K | 7b27da5 | 2011-09-08 19:06:19 +0530 | [diff] [blame] | 507 | hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 508 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 509 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 510 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 511 | /* config the PLL and PHY hdmi_set_pll_pwrfirst */ |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 512 | r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 513 | if (r) { |
| 514 | DSSDBG("Failed to lock PLL\n"); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 515 | goto err_pll_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 516 | } |
| 517 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 518 | r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 519 | if (r) { |
| 520 | DSSDBG("Failed to start PHY\n"); |
Ricardo Neri | d3b4aa5 | 2012-07-30 19:12:02 -0500 | [diff] [blame] | 521 | goto err_phy_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 522 | } |
| 523 | |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 524 | hdmi.ip_data.ops->video_configure(&hdmi.ip_data); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 525 | |
| 526 | /* Make selection of HDMI in DSS */ |
| 527 | dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); |
| 528 | |
| 529 | /* Select the dispc clock source as PRCM clock, to ensure that it is not |
| 530 | * DSI PLL source as the clock selected by DSI PLL might not be |
| 531 | * sufficient for the resolution selected / that can be changed |
| 532 | * dynamically by user. This can be moved to single location , say |
| 533 | * Boardfile. |
| 534 | */ |
Archit Taneja | 6cb07b2 | 2011-04-12 13:52:25 +0530 | [diff] [blame] | 535 | dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 536 | |
| 537 | /* bypass TV gamma table */ |
| 538 | dispc_enable_gamma_table(0); |
| 539 | |
| 540 | /* tv size */ |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 541 | dss_mgr_set_timings(dssdev->manager, p); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 542 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 543 | r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data); |
| 544 | if (r) |
| 545 | goto err_vid_enable; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 546 | |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 547 | r = dss_mgr_enable(dssdev->manager); |
| 548 | if (r) |
| 549 | goto err_mgr_enable; |
Tomi Valkeinen | 3870c90 | 2011-08-31 14:47:11 +0300 | [diff] [blame] | 550 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 551 | return 0; |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 552 | |
| 553 | err_mgr_enable: |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 554 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
| 555 | err_vid_enable: |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 556 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
Ricardo Neri | d3b4aa5 | 2012-07-30 19:12:02 -0500 | [diff] [blame] | 557 | err_phy_enable: |
Tomi Valkeinen | 33ca237 | 2011-11-21 13:42:58 +0200 | [diff] [blame] | 558 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 559 | err_pll_enable: |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 560 | hdmi_runtime_put(); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 561 | err_runtime_get: |
| 562 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 0); |
| 563 | gpio_set_value(hdmi.ls_oe_gpio, 0); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 564 | return -EIO; |
| 565 | } |
| 566 | |
| 567 | static void hdmi_power_off(struct omap_dss_device *dssdev) |
| 568 | { |
Tomi Valkeinen | 7797c6d | 2011-11-04 10:22:46 +0200 | [diff] [blame] | 569 | dss_mgr_disable(dssdev->manager); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 570 | |
Ricardo Neri | c0456be | 2012-04-27 13:48:45 -0500 | [diff] [blame] | 571 | hdmi.ip_data.ops->video_disable(&hdmi.ip_data); |
Mythri P K | 60634a2 | 2011-09-08 19:06:26 +0530 | [diff] [blame] | 572 | hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); |
| 573 | hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 574 | hdmi_runtime_put(); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 575 | |
| 576 | gpio_set_value(hdmi.ct_cp_hpd_gpio, 0); |
| 577 | gpio_set_value(hdmi.ls_oe_gpio, 0); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev, |
| 581 | struct omap_video_timings *timings) |
| 582 | { |
| 583 | struct hdmi_cm cm; |
| 584 | |
| 585 | cm = hdmi_get_code(timings); |
| 586 | if (cm.code == -1) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | return 0; |
| 591 | |
| 592 | } |
| 593 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 594 | void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev, |
| 595 | struct omap_video_timings *timings) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 596 | { |
| 597 | struct hdmi_cm cm; |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 598 | const struct hdmi_config *t; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 599 | |
Archit Taneja | ed1aa90 | 2012-08-15 00:40:31 +0530 | [diff] [blame] | 600 | mutex_lock(&hdmi.lock); |
| 601 | |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 602 | cm = hdmi_get_code(timings); |
| 603 | hdmi.ip_data.cfg.cm = cm; |
| 604 | |
| 605 | t = hdmi_get_timings(); |
| 606 | if (t != NULL) |
| 607 | hdmi.ip_data.cfg = *t; |
Tomi Valkeinen | fa70dc5 | 2011-08-22 14:57:33 +0300 | [diff] [blame] | 608 | |
| 609 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { |
| 610 | int r; |
| 611 | |
| 612 | hdmi_power_off(dssdev); |
| 613 | |
| 614 | r = hdmi_power_on(dssdev); |
| 615 | if (r) |
| 616 | DSSERR("failed to power on device\n"); |
Archit Taneja | fcc3661 | 2012-05-03 20:03:11 +0530 | [diff] [blame] | 617 | } else { |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 618 | dss_mgr_set_timings(dssdev->manager, &t->timings); |
Tomi Valkeinen | fa70dc5 | 2011-08-22 14:57:33 +0300 | [diff] [blame] | 619 | } |
Archit Taneja | ed1aa90 | 2012-08-15 00:40:31 +0530 | [diff] [blame] | 620 | |
| 621 | mutex_unlock(&hdmi.lock); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 622 | } |
| 623 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 624 | static void hdmi_dump_regs(struct seq_file *s) |
Mythri P K | 162874d | 2011-09-22 13:37:45 +0530 | [diff] [blame] | 625 | { |
| 626 | mutex_lock(&hdmi.lock); |
| 627 | |
| 628 | if (hdmi_runtime_get()) |
| 629 | return; |
| 630 | |
| 631 | hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s); |
| 632 | hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s); |
| 633 | hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s); |
| 634 | hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s); |
| 635 | |
| 636 | hdmi_runtime_put(); |
| 637 | mutex_unlock(&hdmi.lock); |
| 638 | } |
| 639 | |
Tomi Valkeinen | 4702456 | 2011-08-25 17:12:56 +0300 | [diff] [blame] | 640 | int omapdss_hdmi_read_edid(u8 *buf, int len) |
| 641 | { |
| 642 | int r; |
| 643 | |
| 644 | mutex_lock(&hdmi.lock); |
| 645 | |
| 646 | r = hdmi_runtime_get(); |
| 647 | BUG_ON(r); |
| 648 | |
| 649 | r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len); |
| 650 | |
| 651 | hdmi_runtime_put(); |
| 652 | mutex_unlock(&hdmi.lock); |
| 653 | |
| 654 | return r; |
| 655 | } |
| 656 | |
Tomi Valkeinen | 759593f | 2011-08-29 18:10:20 +0300 | [diff] [blame] | 657 | bool omapdss_hdmi_detect(void) |
| 658 | { |
| 659 | int r; |
| 660 | |
| 661 | mutex_lock(&hdmi.lock); |
| 662 | |
| 663 | r = hdmi_runtime_get(); |
| 664 | BUG_ON(r); |
| 665 | |
| 666 | r = hdmi.ip_data.ops->detect(&hdmi.ip_data); |
| 667 | |
| 668 | hdmi_runtime_put(); |
| 669 | mutex_unlock(&hdmi.lock); |
| 670 | |
| 671 | return r == 1; |
| 672 | } |
| 673 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 674 | int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev) |
| 675 | { |
| 676 | int r = 0; |
| 677 | |
| 678 | DSSDBG("ENTER hdmi_display_enable\n"); |
| 679 | |
| 680 | mutex_lock(&hdmi.lock); |
| 681 | |
Tomi Valkeinen | 05e1d60 | 2011-06-23 16:38:21 +0300 | [diff] [blame] | 682 | if (dssdev->manager == NULL) { |
| 683 | DSSERR("failed to enable display: no manager\n"); |
| 684 | r = -ENODEV; |
| 685 | goto err0; |
| 686 | } |
| 687 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 688 | hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio; |
Tomi Valkeinen | c49d005 | 2012-01-17 11:09:57 +0200 | [diff] [blame] | 689 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 690 | r = omap_dss_start_device(dssdev); |
| 691 | if (r) { |
| 692 | DSSERR("failed to start device\n"); |
| 693 | goto err0; |
| 694 | } |
| 695 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 696 | r = hdmi_power_on(dssdev); |
| 697 | if (r) { |
| 698 | DSSERR("failed to power on device\n"); |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 699 | goto err1; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | mutex_unlock(&hdmi.lock); |
| 703 | return 0; |
| 704 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 705 | err1: |
| 706 | omap_dss_stop_device(dssdev); |
| 707 | err0: |
| 708 | mutex_unlock(&hdmi.lock); |
| 709 | return r; |
| 710 | } |
| 711 | |
| 712 | void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev) |
| 713 | { |
| 714 | DSSDBG("Enter hdmi_display_disable\n"); |
| 715 | |
| 716 | mutex_lock(&hdmi.lock); |
| 717 | |
| 718 | hdmi_power_off(dssdev); |
| 719 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 720 | omap_dss_stop_device(dssdev); |
| 721 | |
| 722 | mutex_unlock(&hdmi.lock); |
| 723 | } |
| 724 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 725 | static int hdmi_get_clocks(struct platform_device *pdev) |
| 726 | { |
| 727 | struct clk *clk; |
| 728 | |
| 729 | clk = clk_get(&pdev->dev, "sys_clk"); |
| 730 | if (IS_ERR(clk)) { |
| 731 | DSSERR("can't get sys_clk\n"); |
| 732 | return PTR_ERR(clk); |
| 733 | } |
| 734 | |
| 735 | hdmi.sys_clk = clk; |
| 736 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static void hdmi_put_clocks(void) |
| 741 | { |
| 742 | if (hdmi.sys_clk) |
| 743 | clk_put(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 744 | } |
| 745 | |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 746 | #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO) |
| 747 | int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts) |
| 748 | { |
| 749 | u32 deep_color; |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 750 | bool deep_color_correct = false; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 751 | u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock; |
| 752 | |
| 753 | if (n == NULL || cts == NULL) |
| 754 | return -EINVAL; |
| 755 | |
| 756 | /* TODO: When implemented, query deep color mode here. */ |
| 757 | deep_color = 100; |
| 758 | |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 759 | /* |
| 760 | * When using deep color, the default N value (as in the HDMI |
| 761 | * specification) yields to an non-integer CTS. Hence, we |
| 762 | * modify it while keeping the restrictions described in |
| 763 | * section 7.2.1 of the HDMI 1.4a specification. |
| 764 | */ |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 765 | switch (sample_freq) { |
| 766 | case 32000: |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 767 | case 48000: |
| 768 | case 96000: |
| 769 | case 192000: |
| 770 | if (deep_color == 125) |
| 771 | if (pclk == 27027 || pclk == 74250) |
| 772 | deep_color_correct = true; |
| 773 | if (deep_color == 150) |
| 774 | if (pclk == 27027) |
| 775 | deep_color_correct = true; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 776 | break; |
| 777 | case 44100: |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 778 | case 88200: |
| 779 | case 176400: |
| 780 | if (deep_color == 125) |
| 781 | if (pclk == 27027) |
| 782 | deep_color_correct = true; |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 783 | break; |
| 784 | default: |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 785 | return -EINVAL; |
| 786 | } |
| 787 | |
Ricardo Neri | 25a6535 | 2012-03-23 15:49:02 -0600 | [diff] [blame] | 788 | if (deep_color_correct) { |
| 789 | switch (sample_freq) { |
| 790 | case 32000: |
| 791 | *n = 8192; |
| 792 | break; |
| 793 | case 44100: |
| 794 | *n = 12544; |
| 795 | break; |
| 796 | case 48000: |
| 797 | *n = 8192; |
| 798 | break; |
| 799 | case 88200: |
| 800 | *n = 25088; |
| 801 | break; |
| 802 | case 96000: |
| 803 | *n = 16384; |
| 804 | break; |
| 805 | case 176400: |
| 806 | *n = 50176; |
| 807 | break; |
| 808 | case 192000: |
| 809 | *n = 32768; |
| 810 | break; |
| 811 | default: |
| 812 | return -EINVAL; |
| 813 | } |
| 814 | } else { |
| 815 | switch (sample_freq) { |
| 816 | case 32000: |
| 817 | *n = 4096; |
| 818 | break; |
| 819 | case 44100: |
| 820 | *n = 6272; |
| 821 | break; |
| 822 | case 48000: |
| 823 | *n = 6144; |
| 824 | break; |
| 825 | case 88200: |
| 826 | *n = 12544; |
| 827 | break; |
| 828 | case 96000: |
| 829 | *n = 12288; |
| 830 | break; |
| 831 | case 176400: |
| 832 | *n = 25088; |
| 833 | break; |
| 834 | case 192000: |
| 835 | *n = 24576; |
| 836 | break; |
| 837 | default: |
| 838 | return -EINVAL; |
| 839 | } |
| 840 | } |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 841 | /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */ |
| 842 | *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10); |
| 843 | |
| 844 | return 0; |
| 845 | } |
Ricardo Neri | f3a97491 | 2012-05-09 21:09:50 -0500 | [diff] [blame] | 846 | |
| 847 | int hdmi_audio_enable(void) |
| 848 | { |
| 849 | DSSDBG("audio_enable\n"); |
| 850 | |
| 851 | return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data); |
| 852 | } |
| 853 | |
| 854 | void hdmi_audio_disable(void) |
| 855 | { |
| 856 | DSSDBG("audio_disable\n"); |
| 857 | |
| 858 | hdmi.ip_data.ops->audio_disable(&hdmi.ip_data); |
| 859 | } |
| 860 | |
| 861 | int hdmi_audio_start(void) |
| 862 | { |
| 863 | DSSDBG("audio_start\n"); |
| 864 | |
| 865 | return hdmi.ip_data.ops->audio_start(&hdmi.ip_data); |
| 866 | } |
| 867 | |
| 868 | void hdmi_audio_stop(void) |
| 869 | { |
| 870 | DSSDBG("audio_stop\n"); |
| 871 | |
| 872 | hdmi.ip_data.ops->audio_stop(&hdmi.ip_data); |
| 873 | } |
| 874 | |
| 875 | bool hdmi_mode_has_audio(void) |
| 876 | { |
| 877 | if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI) |
| 878 | return true; |
| 879 | else |
| 880 | return false; |
| 881 | } |
| 882 | |
| 883 | int hdmi_audio_config(struct omap_dss_audio *audio) |
| 884 | { |
| 885 | return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio); |
| 886 | } |
| 887 | |
Ricardo Neri | 3554762 | 2012-03-20 21:02:01 -0600 | [diff] [blame] | 888 | #endif |
| 889 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 890 | static void __init hdmi_probe_pdata(struct platform_device *pdev) |
| 891 | { |
| 892 | struct omap_dss_board_info *pdata = pdev->dev.platform_data; |
| 893 | int r, i; |
| 894 | |
| 895 | for (i = 0; i < pdata->num_devices; ++i) { |
| 896 | struct omap_dss_device *dssdev = pdata->devices[i]; |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 897 | struct omap_dss_hdmi_data *priv = dssdev->data; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 898 | |
| 899 | if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI) |
| 900 | continue; |
| 901 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 902 | hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio; |
| 903 | hdmi.ls_oe_gpio = priv->ls_oe_gpio; |
| 904 | hdmi.hpd_gpio = priv->hpd_gpio; |
| 905 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 906 | r = hdmi_init_display(dssdev); |
| 907 | if (r) { |
| 908 | DSSERR("device %s init failed: %d\n", dssdev->name, r); |
| 909 | continue; |
| 910 | } |
| 911 | |
| 912 | r = omap_dss_register_device(dssdev, &pdev->dev, i); |
| 913 | if (r) |
| 914 | DSSERR("device %s register failed: %d\n", |
| 915 | dssdev->name, r); |
| 916 | } |
| 917 | } |
| 918 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 919 | /* HDMI HW IP initialisation */ |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 920 | static int __init omapdss_hdmihw_probe(struct platform_device *pdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 921 | { |
| 922 | struct resource *hdmi_mem; |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 923 | int r; |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 924 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 925 | hdmi.pdev = pdev; |
| 926 | |
| 927 | mutex_init(&hdmi.lock); |
| 928 | |
| 929 | hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0); |
| 930 | if (!hdmi_mem) { |
| 931 | DSSERR("can't get IORESOURCE_MEM HDMI\n"); |
| 932 | return -EINVAL; |
| 933 | } |
| 934 | |
| 935 | /* Base address taken from platform */ |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 936 | hdmi.ip_data.base_wp = ioremap(hdmi_mem->start, |
| 937 | resource_size(hdmi_mem)); |
| 938 | if (!hdmi.ip_data.base_wp) { |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 939 | DSSERR("can't ioremap WP\n"); |
| 940 | return -ENOMEM; |
| 941 | } |
| 942 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 943 | r = hdmi_get_clocks(pdev); |
| 944 | if (r) { |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 945 | iounmap(hdmi.ip_data.base_wp); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 946 | return r; |
| 947 | } |
| 948 | |
| 949 | pm_runtime_enable(&pdev->dev); |
| 950 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 951 | hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS; |
| 952 | hdmi.ip_data.core_av_offset = HDMI_CORE_AV; |
| 953 | hdmi.ip_data.pll_offset = HDMI_PLLCTRL; |
| 954 | hdmi.ip_data.phy_offset = HDMI_PHY; |
Archit Taneja | 7849398 | 2012-08-08 16:50:42 +0530 | [diff] [blame] | 955 | |
Jassi Brar | 3a5383a | 2012-06-27 19:34:56 +0530 | [diff] [blame] | 956 | mutex_init(&hdmi.ip_data.lock); |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 957 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 958 | hdmi_panel_init(); |
| 959 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 960 | dss_debugfs_create_file("hdmi", hdmi_dump_regs); |
| 961 | |
Tomi Valkeinen | 38f3daf | 2012-05-02 14:55:12 +0300 | [diff] [blame] | 962 | hdmi_probe_pdata(pdev); |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 963 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 964 | return 0; |
| 965 | } |
| 966 | |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 967 | static int __exit hdmi_remove_child(struct device *dev, void *data) |
| 968 | { |
| 969 | struct omap_dss_device *dssdev = to_dss_device(dev); |
| 970 | hdmi_uninit_display(dssdev); |
| 971 | return 0; |
| 972 | } |
| 973 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 974 | static int __exit omapdss_hdmihw_remove(struct platform_device *pdev) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 975 | { |
Tomi Valkeinen | cca3501 | 2012-04-26 14:48:32 +0300 | [diff] [blame^] | 976 | device_for_each_child(&pdev->dev, NULL, hdmi_remove_child); |
| 977 | |
Tomi Valkeinen | 35deca3 | 2012-03-01 15:45:53 +0200 | [diff] [blame] | 978 | omap_dss_unregister_child_devices(&pdev->dev); |
| 979 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 980 | hdmi_panel_exit(); |
| 981 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 982 | pm_runtime_disable(&pdev->dev); |
| 983 | |
| 984 | hdmi_put_clocks(); |
| 985 | |
Mythri P K | 95a8aeb | 2011-09-08 19:06:18 +0530 | [diff] [blame] | 986 | iounmap(hdmi.ip_data.base_wp); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 991 | static int hdmi_runtime_suspend(struct device *dev) |
| 992 | { |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 993 | clk_disable_unprepare(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 994 | |
| 995 | dispc_runtime_put(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | static int hdmi_runtime_resume(struct device *dev) |
| 1001 | { |
| 1002 | int r; |
| 1003 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1004 | r = dispc_runtime_get(); |
| 1005 | if (r < 0) |
Tomi Valkeinen | 852f083 | 2012-02-17 17:58:04 +0200 | [diff] [blame] | 1006 | return r; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1007 | |
Rajendra Nayak | f11766d | 2012-06-27 14:21:26 +0530 | [diff] [blame] | 1008 | clk_prepare_enable(hdmi.sys_clk); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1009 | |
| 1010 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | static const struct dev_pm_ops hdmi_pm_ops = { |
| 1014 | .runtime_suspend = hdmi_runtime_suspend, |
| 1015 | .runtime_resume = hdmi_runtime_resume, |
| 1016 | }; |
| 1017 | |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1018 | static struct platform_driver omapdss_hdmihw_driver = { |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1019 | .remove = __exit_p(omapdss_hdmihw_remove), |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1020 | .driver = { |
| 1021 | .name = "omapdss_hdmi", |
| 1022 | .owner = THIS_MODULE, |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 1023 | .pm = &hdmi_pm_ops, |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1024 | }, |
| 1025 | }; |
| 1026 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1027 | int __init hdmi_init_platform_driver(void) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1028 | { |
Tomi Valkeinen | 61055d4 | 2012-03-07 12:53:38 +0200 | [diff] [blame] | 1029 | return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1030 | } |
| 1031 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 1032 | void __exit hdmi_uninit_platform_driver(void) |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1033 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 1034 | platform_driver_unregister(&omapdss_hdmihw_driver); |
Mythri P K | c3198a5 | 2011-03-12 12:04:27 +0530 | [diff] [blame] | 1035 | } |