Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HDMI driver for OMAP5 |
| 3 | * |
| 4 | * Copyright (C) 2014 Texas Instruments Incorporated |
| 5 | * |
| 6 | * Authors: |
| 7 | * Yong Zhi |
| 8 | * Mythri pk |
| 9 | * Archit Taneja <archit@ti.com> |
| 10 | * Tomi Valkeinen <tomi.valkeinen@ti.com> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published by |
| 14 | * the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 19 | * more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | */ |
| 24 | |
| 25 | #define DSS_SUBSYS_NAME "HDMI" |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/err.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/mutex.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/platform_device.h> |
| 36 | #include <linux/pm_runtime.h> |
| 37 | #include <linux/clk.h> |
| 38 | #include <linux/gpio.h> |
| 39 | #include <linux/regulator/consumer.h> |
| 40 | #include <video/omapdss.h> |
| 41 | |
| 42 | #include "hdmi5_core.h" |
| 43 | #include "dss.h" |
| 44 | #include "dss_features.h" |
| 45 | |
| 46 | static struct { |
| 47 | struct mutex lock; |
| 48 | struct platform_device *pdev; |
| 49 | |
| 50 | struct hdmi_wp_data wp; |
| 51 | struct hdmi_pll_data pll; |
| 52 | struct hdmi_phy_data phy; |
| 53 | struct hdmi_core_data core; |
| 54 | |
| 55 | struct hdmi_config cfg; |
| 56 | |
| 57 | struct clk *sys_clk; |
| 58 | struct regulator *vdda_reg; |
| 59 | |
| 60 | bool core_enabled; |
| 61 | |
| 62 | struct omap_dss_device output; |
| 63 | } hdmi; |
| 64 | |
| 65 | static int hdmi_runtime_get(void) |
| 66 | { |
| 67 | int r; |
| 68 | |
| 69 | DSSDBG("hdmi_runtime_get\n"); |
| 70 | |
| 71 | r = pm_runtime_get_sync(&hdmi.pdev->dev); |
| 72 | WARN_ON(r < 0); |
| 73 | if (r < 0) |
| 74 | return r; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | static void hdmi_runtime_put(void) |
| 80 | { |
| 81 | int r; |
| 82 | |
| 83 | DSSDBG("hdmi_runtime_put\n"); |
| 84 | |
| 85 | r = pm_runtime_put_sync(&hdmi.pdev->dev); |
| 86 | WARN_ON(r < 0 && r != -ENOSYS); |
| 87 | } |
| 88 | |
| 89 | static irqreturn_t hdmi_irq_handler(int irq, void *data) |
| 90 | { |
| 91 | struct hdmi_wp_data *wp = data; |
| 92 | u32 irqstatus; |
| 93 | |
| 94 | irqstatus = hdmi_wp_get_irqstatus(wp); |
| 95 | hdmi_wp_set_irqstatus(wp, irqstatus); |
| 96 | |
| 97 | if ((irqstatus & HDMI_IRQ_LINK_CONNECT) && |
| 98 | irqstatus & HDMI_IRQ_LINK_DISCONNECT) { |
| 99 | u32 v; |
| 100 | /* |
| 101 | * If we get both connect and disconnect interrupts at the same |
| 102 | * time, turn off the PHY, clear interrupts, and restart, which |
| 103 | * raises connect interrupt if a cable is connected, or nothing |
| 104 | * if cable is not connected. |
| 105 | */ |
| 106 | |
| 107 | hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF); |
| 108 | |
| 109 | /* |
| 110 | * We always get bogus CONNECT & DISCONNECT interrupts when |
| 111 | * setting the PHY to LDOON. To ignore those, we force the RXDET |
| 112 | * line to 0 until the PHY power state has been changed. |
| 113 | */ |
| 114 | v = hdmi_read_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL); |
| 115 | v = FLD_MOD(v, 1, 15, 15); /* FORCE_RXDET_HIGH */ |
| 116 | v = FLD_MOD(v, 0, 14, 7); /* RXDET_LINE */ |
| 117 | hdmi_write_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, v); |
| 118 | |
| 119 | hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT | |
| 120 | HDMI_IRQ_LINK_DISCONNECT); |
| 121 | |
| 122 | hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); |
| 123 | |
| 124 | REG_FLD_MOD(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, 0, 15, 15); |
| 125 | |
| 126 | } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) { |
| 127 | hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON); |
| 128 | } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) { |
| 129 | hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON); |
| 130 | } |
| 131 | |
| 132 | return IRQ_HANDLED; |
| 133 | } |
| 134 | |
| 135 | static int hdmi_init_regulator(void) |
| 136 | { |
| 137 | int r; |
| 138 | struct regulator *reg; |
| 139 | |
| 140 | if (hdmi.vdda_reg != NULL) |
| 141 | return 0; |
| 142 | |
| 143 | reg = devm_regulator_get(&hdmi.pdev->dev, "vdda"); |
| 144 | if (IS_ERR(reg)) { |
| 145 | DSSERR("can't get VDDA regulator\n"); |
| 146 | return PTR_ERR(reg); |
| 147 | } |
| 148 | |
| 149 | if (regulator_can_change_voltage(reg)) { |
| 150 | r = regulator_set_voltage(reg, 1800000, 1800000); |
| 151 | if (r) { |
| 152 | devm_regulator_put(reg); |
| 153 | DSSWARN("can't set the regulator voltage\n"); |
| 154 | return r; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | hdmi.vdda_reg = reg; |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int hdmi_power_on_core(struct omap_dss_device *dssdev) |
| 164 | { |
| 165 | int r; |
| 166 | |
| 167 | r = regulator_enable(hdmi.vdda_reg); |
| 168 | if (r) |
| 169 | return r; |
| 170 | |
| 171 | r = hdmi_runtime_get(); |
| 172 | if (r) |
| 173 | goto err_runtime_get; |
| 174 | |
| 175 | /* Make selection of HDMI in DSS */ |
| 176 | dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK); |
| 177 | |
| 178 | hdmi.core_enabled = true; |
| 179 | |
| 180 | return 0; |
| 181 | |
| 182 | err_runtime_get: |
| 183 | regulator_disable(hdmi.vdda_reg); |
| 184 | |
| 185 | return r; |
| 186 | } |
| 187 | |
| 188 | static void hdmi_power_off_core(struct omap_dss_device *dssdev) |
| 189 | { |
| 190 | hdmi.core_enabled = false; |
| 191 | |
| 192 | hdmi_runtime_put(); |
| 193 | regulator_disable(hdmi.vdda_reg); |
| 194 | } |
| 195 | |
| 196 | static int hdmi_power_on_full(struct omap_dss_device *dssdev) |
| 197 | { |
| 198 | int r; |
| 199 | struct omap_video_timings *p; |
| 200 | struct omap_overlay_manager *mgr = hdmi.output.manager; |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 201 | |
| 202 | r = hdmi_power_on_core(dssdev); |
| 203 | if (r) |
| 204 | return r; |
| 205 | |
| 206 | p = &hdmi.cfg.timings; |
| 207 | |
| 208 | DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res); |
| 209 | |
Tomi Valkeinen | 33f1312 | 2014-09-15 15:40:47 +0300 | [diff] [blame] | 210 | hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), p->pixelclock); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 211 | |
| 212 | /* disable and clear irqs */ |
| 213 | hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff); |
| 214 | hdmi_wp_set_irqstatus(&hdmi.wp, |
| 215 | hdmi_wp_get_irqstatus(&hdmi.wp)); |
| 216 | |
Tomi Valkeinen | 03aafa2 | 2014-10-16 15:31:38 +0300 | [diff] [blame] | 217 | r = hdmi_pll_enable(&hdmi.pll); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 218 | if (r) { |
Tomi Valkeinen | c2fbd06 | 2014-10-16 16:01:51 +0300 | [diff] [blame^] | 219 | DSSERR("Failed to enable PLL\n"); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 220 | goto err_pll_enable; |
| 221 | } |
| 222 | |
Tomi Valkeinen | c2fbd06 | 2014-10-16 16:01:51 +0300 | [diff] [blame^] | 223 | r = hdmi_pll_set_config(&hdmi.pll); |
| 224 | if (r) { |
| 225 | DSSERR("Failed to configure PLL\n"); |
| 226 | goto err_pll_cfg; |
| 227 | } |
| 228 | |
Tomi Valkeinen | 33f1312 | 2014-09-15 15:40:47 +0300 | [diff] [blame] | 229 | r = hdmi_phy_configure(&hdmi.phy, hdmi.pll.info.clkdco, |
| 230 | hdmi.pll.info.clkout); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 231 | if (r) { |
| 232 | DSSDBG("Failed to start PHY\n"); |
| 233 | goto err_phy_cfg; |
| 234 | } |
| 235 | |
| 236 | r = hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_LDOON); |
| 237 | if (r) |
| 238 | goto err_phy_pwr; |
| 239 | |
| 240 | hdmi5_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg); |
| 241 | |
| 242 | /* bypass TV gamma table */ |
| 243 | dispc_enable_gamma_table(0); |
| 244 | |
| 245 | /* tv size */ |
| 246 | dss_mgr_set_timings(mgr, p); |
| 247 | |
| 248 | r = hdmi_wp_video_start(&hdmi.wp); |
| 249 | if (r) |
| 250 | goto err_vid_enable; |
| 251 | |
| 252 | r = dss_mgr_enable(mgr); |
| 253 | if (r) |
| 254 | goto err_mgr_enable; |
| 255 | |
| 256 | hdmi_wp_set_irqenable(&hdmi.wp, |
| 257 | HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT); |
| 258 | |
| 259 | return 0; |
| 260 | |
| 261 | err_mgr_enable: |
| 262 | hdmi_wp_video_stop(&hdmi.wp); |
| 263 | err_vid_enable: |
| 264 | hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF); |
| 265 | err_phy_pwr: |
| 266 | err_phy_cfg: |
Tomi Valkeinen | c2fbd06 | 2014-10-16 16:01:51 +0300 | [diff] [blame^] | 267 | err_pll_cfg: |
Tomi Valkeinen | 03aafa2 | 2014-10-16 15:31:38 +0300 | [diff] [blame] | 268 | hdmi_pll_disable(&hdmi.pll); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 269 | err_pll_enable: |
| 270 | hdmi_power_off_core(dssdev); |
| 271 | return -EIO; |
| 272 | } |
| 273 | |
| 274 | static void hdmi_power_off_full(struct omap_dss_device *dssdev) |
| 275 | { |
| 276 | struct omap_overlay_manager *mgr = hdmi.output.manager; |
| 277 | |
| 278 | hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff); |
| 279 | |
| 280 | dss_mgr_disable(mgr); |
| 281 | |
| 282 | hdmi_wp_video_stop(&hdmi.wp); |
| 283 | |
| 284 | hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF); |
| 285 | |
Tomi Valkeinen | 03aafa2 | 2014-10-16 15:31:38 +0300 | [diff] [blame] | 286 | hdmi_pll_disable(&hdmi.pll); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 287 | |
| 288 | hdmi_power_off_core(dssdev); |
| 289 | } |
| 290 | |
| 291 | static int hdmi_display_check_timing(struct omap_dss_device *dssdev, |
| 292 | struct omap_video_timings *timings) |
| 293 | { |
| 294 | struct omap_dss_device *out = &hdmi.output; |
| 295 | |
Tomi Valkeinen | 31dd0f4 | 2014-09-16 12:46:33 +0300 | [diff] [blame] | 296 | /* TODO: proper interlace support */ |
| 297 | if (timings->interlace) |
| 298 | return -EINVAL; |
| 299 | |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 300 | if (!dispc_mgr_timings_ok(out->dispc_channel, timings)) |
| 301 | return -EINVAL; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static void hdmi_display_set_timing(struct omap_dss_device *dssdev, |
| 307 | struct omap_video_timings *timings) |
| 308 | { |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 309 | mutex_lock(&hdmi.lock); |
| 310 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 311 | hdmi.cfg.timings = *timings; |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 312 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 313 | dispc_set_tv_pclk(timings->pixelclock); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 314 | |
| 315 | mutex_unlock(&hdmi.lock); |
| 316 | } |
| 317 | |
| 318 | static void hdmi_display_get_timings(struct omap_dss_device *dssdev, |
| 319 | struct omap_video_timings *timings) |
| 320 | { |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 321 | *timings = hdmi.cfg.timings; |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void hdmi_dump_regs(struct seq_file *s) |
| 325 | { |
| 326 | mutex_lock(&hdmi.lock); |
| 327 | |
| 328 | if (hdmi_runtime_get()) { |
| 329 | mutex_unlock(&hdmi.lock); |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | hdmi_wp_dump(&hdmi.wp, s); |
| 334 | hdmi_pll_dump(&hdmi.pll, s); |
| 335 | hdmi_phy_dump(&hdmi.phy, s); |
| 336 | hdmi5_core_dump(&hdmi.core, s); |
| 337 | |
| 338 | hdmi_runtime_put(); |
| 339 | mutex_unlock(&hdmi.lock); |
| 340 | } |
| 341 | |
| 342 | static int read_edid(u8 *buf, int len) |
| 343 | { |
| 344 | int r; |
| 345 | int idlemode; |
| 346 | |
| 347 | mutex_lock(&hdmi.lock); |
| 348 | |
| 349 | r = hdmi_runtime_get(); |
| 350 | BUG_ON(r); |
| 351 | |
| 352 | idlemode = REG_GET(hdmi.wp.base, HDMI_WP_SYSCONFIG, 3, 2); |
| 353 | /* No-idle mode */ |
| 354 | REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2); |
| 355 | |
| 356 | r = hdmi5_read_edid(&hdmi.core, buf, len); |
| 357 | |
| 358 | REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, idlemode, 3, 2); |
| 359 | |
| 360 | hdmi_runtime_put(); |
| 361 | mutex_unlock(&hdmi.lock); |
| 362 | |
| 363 | return r; |
| 364 | } |
| 365 | |
| 366 | static int hdmi_display_enable(struct omap_dss_device *dssdev) |
| 367 | { |
| 368 | struct omap_dss_device *out = &hdmi.output; |
| 369 | int r = 0; |
| 370 | |
| 371 | DSSDBG("ENTER hdmi_display_enable\n"); |
| 372 | |
| 373 | mutex_lock(&hdmi.lock); |
| 374 | |
| 375 | if (out == NULL || out->manager == NULL) { |
| 376 | DSSERR("failed to enable display: no output/manager\n"); |
| 377 | r = -ENODEV; |
| 378 | goto err0; |
| 379 | } |
| 380 | |
| 381 | r = hdmi_power_on_full(dssdev); |
| 382 | if (r) { |
| 383 | DSSERR("failed to power on device\n"); |
| 384 | goto err0; |
| 385 | } |
| 386 | |
| 387 | mutex_unlock(&hdmi.lock); |
| 388 | return 0; |
| 389 | |
| 390 | err0: |
| 391 | mutex_unlock(&hdmi.lock); |
| 392 | return r; |
| 393 | } |
| 394 | |
| 395 | static void hdmi_display_disable(struct omap_dss_device *dssdev) |
| 396 | { |
| 397 | DSSDBG("Enter hdmi_display_disable\n"); |
| 398 | |
| 399 | mutex_lock(&hdmi.lock); |
| 400 | |
| 401 | hdmi_power_off_full(dssdev); |
| 402 | |
| 403 | mutex_unlock(&hdmi.lock); |
| 404 | } |
| 405 | |
| 406 | static int hdmi_core_enable(struct omap_dss_device *dssdev) |
| 407 | { |
| 408 | int r = 0; |
| 409 | |
| 410 | DSSDBG("ENTER omapdss_hdmi_core_enable\n"); |
| 411 | |
| 412 | mutex_lock(&hdmi.lock); |
| 413 | |
| 414 | r = hdmi_power_on_core(dssdev); |
| 415 | if (r) { |
| 416 | DSSERR("failed to power on device\n"); |
| 417 | goto err0; |
| 418 | } |
| 419 | |
| 420 | mutex_unlock(&hdmi.lock); |
| 421 | return 0; |
| 422 | |
| 423 | err0: |
| 424 | mutex_unlock(&hdmi.lock); |
| 425 | return r; |
| 426 | } |
| 427 | |
| 428 | static void hdmi_core_disable(struct omap_dss_device *dssdev) |
| 429 | { |
| 430 | DSSDBG("Enter omapdss_hdmi_core_disable\n"); |
| 431 | |
| 432 | mutex_lock(&hdmi.lock); |
| 433 | |
| 434 | hdmi_power_off_core(dssdev); |
| 435 | |
| 436 | mutex_unlock(&hdmi.lock); |
| 437 | } |
| 438 | |
| 439 | static int hdmi_get_clocks(struct platform_device *pdev) |
| 440 | { |
| 441 | struct clk *clk; |
| 442 | |
| 443 | clk = devm_clk_get(&pdev->dev, "sys_clk"); |
| 444 | if (IS_ERR(clk)) { |
| 445 | DSSERR("can't get sys_clk\n"); |
| 446 | return PTR_ERR(clk); |
| 447 | } |
| 448 | |
| 449 | hdmi.sys_clk = clk; |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static int hdmi_connect(struct omap_dss_device *dssdev, |
| 455 | struct omap_dss_device *dst) |
| 456 | { |
| 457 | struct omap_overlay_manager *mgr; |
| 458 | int r; |
| 459 | |
| 460 | r = hdmi_init_regulator(); |
| 461 | if (r) |
| 462 | return r; |
| 463 | |
| 464 | mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel); |
| 465 | if (!mgr) |
| 466 | return -ENODEV; |
| 467 | |
| 468 | r = dss_mgr_connect(mgr, dssdev); |
| 469 | if (r) |
| 470 | return r; |
| 471 | |
| 472 | r = omapdss_output_set_device(dssdev, dst); |
| 473 | if (r) { |
| 474 | DSSERR("failed to connect output to new device: %s\n", |
| 475 | dst->name); |
| 476 | dss_mgr_disconnect(mgr, dssdev); |
| 477 | return r; |
| 478 | } |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | static void hdmi_disconnect(struct omap_dss_device *dssdev, |
| 484 | struct omap_dss_device *dst) |
| 485 | { |
| 486 | WARN_ON(dst != dssdev->dst); |
| 487 | |
| 488 | if (dst != dssdev->dst) |
| 489 | return; |
| 490 | |
| 491 | omapdss_output_unset_device(dssdev); |
| 492 | |
| 493 | if (dssdev->manager) |
| 494 | dss_mgr_disconnect(dssdev->manager, dssdev); |
| 495 | } |
| 496 | |
| 497 | static int hdmi_read_edid(struct omap_dss_device *dssdev, |
| 498 | u8 *edid, int len) |
| 499 | { |
| 500 | bool need_enable; |
| 501 | int r; |
| 502 | |
| 503 | need_enable = hdmi.core_enabled == false; |
| 504 | |
| 505 | if (need_enable) { |
| 506 | r = hdmi_core_enable(dssdev); |
| 507 | if (r) |
| 508 | return r; |
| 509 | } |
| 510 | |
| 511 | r = read_edid(edid, len); |
| 512 | |
| 513 | if (need_enable) |
| 514 | hdmi_core_disable(dssdev); |
| 515 | |
| 516 | return r; |
| 517 | } |
| 518 | |
| 519 | #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO) |
| 520 | static int hdmi_audio_enable(struct omap_dss_device *dssdev) |
| 521 | { |
| 522 | int r; |
| 523 | |
| 524 | mutex_lock(&hdmi.lock); |
| 525 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 526 | if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) { |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 527 | r = -EPERM; |
| 528 | goto err; |
| 529 | } |
| 530 | |
| 531 | r = hdmi_wp_audio_enable(&hdmi.wp, true); |
| 532 | if (r) |
| 533 | goto err; |
| 534 | |
| 535 | mutex_unlock(&hdmi.lock); |
| 536 | return 0; |
| 537 | |
| 538 | err: |
| 539 | mutex_unlock(&hdmi.lock); |
| 540 | return r; |
| 541 | } |
| 542 | |
| 543 | static void hdmi_audio_disable(struct omap_dss_device *dssdev) |
| 544 | { |
| 545 | hdmi_wp_audio_enable(&hdmi.wp, false); |
| 546 | } |
| 547 | |
| 548 | static int hdmi_audio_start(struct omap_dss_device *dssdev) |
| 549 | { |
| 550 | return hdmi_wp_audio_core_req_enable(&hdmi.wp, true); |
| 551 | } |
| 552 | |
| 553 | static void hdmi_audio_stop(struct omap_dss_device *dssdev) |
| 554 | { |
| 555 | hdmi_wp_audio_core_req_enable(&hdmi.wp, false); |
| 556 | } |
| 557 | |
| 558 | static bool hdmi_audio_supported(struct omap_dss_device *dssdev) |
| 559 | { |
| 560 | bool r; |
| 561 | |
| 562 | mutex_lock(&hdmi.lock); |
| 563 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 564 | r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 565 | |
| 566 | mutex_unlock(&hdmi.lock); |
| 567 | return r; |
| 568 | } |
| 569 | |
| 570 | static int hdmi_audio_config(struct omap_dss_device *dssdev, |
| 571 | struct omap_dss_audio *audio) |
| 572 | { |
| 573 | int r; |
| 574 | u32 pclk = hdmi.cfg.timings.pixelclock; |
| 575 | |
| 576 | mutex_lock(&hdmi.lock); |
| 577 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 578 | if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) { |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 579 | r = -EPERM; |
| 580 | goto err; |
| 581 | } |
| 582 | |
| 583 | r = hdmi5_audio_config(&hdmi.core, &hdmi.wp, audio, pclk); |
| 584 | if (r) |
| 585 | goto err; |
| 586 | |
| 587 | mutex_unlock(&hdmi.lock); |
| 588 | return 0; |
| 589 | |
| 590 | err: |
| 591 | mutex_unlock(&hdmi.lock); |
| 592 | return r; |
| 593 | } |
| 594 | #else |
| 595 | static int hdmi_audio_enable(struct omap_dss_device *dssdev) |
| 596 | { |
| 597 | return -EPERM; |
| 598 | } |
| 599 | |
| 600 | static void hdmi_audio_disable(struct omap_dss_device *dssdev) |
| 601 | { |
| 602 | } |
| 603 | |
| 604 | static int hdmi_audio_start(struct omap_dss_device *dssdev) |
| 605 | { |
| 606 | return -EPERM; |
| 607 | } |
| 608 | |
| 609 | static void hdmi_audio_stop(struct omap_dss_device *dssdev) |
| 610 | { |
| 611 | } |
| 612 | |
| 613 | static bool hdmi_audio_supported(struct omap_dss_device *dssdev) |
| 614 | { |
| 615 | return false; |
| 616 | } |
| 617 | |
| 618 | static int hdmi_audio_config(struct omap_dss_device *dssdev, |
| 619 | struct omap_dss_audio *audio) |
| 620 | { |
| 621 | return -EPERM; |
| 622 | } |
| 623 | #endif |
| 624 | |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 625 | static int hdmi_set_infoframe(struct omap_dss_device *dssdev, |
| 626 | const struct hdmi_avi_infoframe *avi) |
| 627 | { |
| 628 | hdmi.cfg.infoframe = *avi; |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev, |
| 633 | bool hdmi_mode) |
| 634 | { |
| 635 | hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI; |
| 636 | return 0; |
| 637 | } |
| 638 | |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 639 | static const struct omapdss_hdmi_ops hdmi_ops = { |
| 640 | .connect = hdmi_connect, |
| 641 | .disconnect = hdmi_disconnect, |
| 642 | |
| 643 | .enable = hdmi_display_enable, |
| 644 | .disable = hdmi_display_disable, |
| 645 | |
| 646 | .check_timings = hdmi_display_check_timing, |
| 647 | .set_timings = hdmi_display_set_timing, |
| 648 | .get_timings = hdmi_display_get_timings, |
| 649 | |
| 650 | .read_edid = hdmi_read_edid, |
Tomi Valkeinen | 769dcb1 | 2014-06-18 14:21:55 +0300 | [diff] [blame] | 651 | .set_infoframe = hdmi_set_infoframe, |
| 652 | .set_hdmi_mode = hdmi_set_hdmi_mode, |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 653 | |
| 654 | .audio_enable = hdmi_audio_enable, |
| 655 | .audio_disable = hdmi_audio_disable, |
| 656 | .audio_start = hdmi_audio_start, |
| 657 | .audio_stop = hdmi_audio_stop, |
| 658 | .audio_supported = hdmi_audio_supported, |
| 659 | .audio_config = hdmi_audio_config, |
| 660 | }; |
| 661 | |
| 662 | static void hdmi_init_output(struct platform_device *pdev) |
| 663 | { |
| 664 | struct omap_dss_device *out = &hdmi.output; |
| 665 | |
| 666 | out->dev = &pdev->dev; |
| 667 | out->id = OMAP_DSS_OUTPUT_HDMI; |
| 668 | out->output_type = OMAP_DISPLAY_TYPE_HDMI; |
| 669 | out->name = "hdmi.0"; |
| 670 | out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT; |
| 671 | out->ops.hdmi = &hdmi_ops; |
| 672 | out->owner = THIS_MODULE; |
| 673 | |
| 674 | omapdss_register_output(out); |
| 675 | } |
| 676 | |
| 677 | static void __exit hdmi_uninit_output(struct platform_device *pdev) |
| 678 | { |
| 679 | struct omap_dss_device *out = &hdmi.output; |
| 680 | |
| 681 | omapdss_unregister_output(out); |
| 682 | } |
| 683 | |
| 684 | static int hdmi_probe_of(struct platform_device *pdev) |
| 685 | { |
| 686 | struct device_node *node = pdev->dev.of_node; |
| 687 | struct device_node *ep; |
| 688 | int r; |
| 689 | |
| 690 | ep = omapdss_of_get_first_endpoint(node); |
| 691 | if (!ep) |
| 692 | return 0; |
| 693 | |
| 694 | r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy); |
| 695 | if (r) |
| 696 | goto err; |
| 697 | |
| 698 | of_node_put(ep); |
| 699 | return 0; |
| 700 | |
| 701 | err: |
| 702 | of_node_put(ep); |
| 703 | return r; |
| 704 | } |
| 705 | |
| 706 | /* HDMI HW IP initialisation */ |
| 707 | static int omapdss_hdmihw_probe(struct platform_device *pdev) |
| 708 | { |
| 709 | int r; |
| 710 | int irq; |
| 711 | |
| 712 | hdmi.pdev = pdev; |
| 713 | |
| 714 | mutex_init(&hdmi.lock); |
| 715 | |
| 716 | if (pdev->dev.of_node) { |
| 717 | r = hdmi_probe_of(pdev); |
| 718 | if (r) |
| 719 | return r; |
| 720 | } |
| 721 | |
| 722 | r = hdmi_wp_init(pdev, &hdmi.wp); |
| 723 | if (r) |
| 724 | return r; |
| 725 | |
Tomi Valkeinen | 03aafa2 | 2014-10-16 15:31:38 +0300 | [diff] [blame] | 726 | r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp); |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 727 | if (r) |
| 728 | return r; |
| 729 | |
| 730 | r = hdmi_phy_init(pdev, &hdmi.phy); |
| 731 | if (r) |
| 732 | return r; |
| 733 | |
| 734 | r = hdmi5_core_init(pdev, &hdmi.core); |
| 735 | if (r) |
| 736 | return r; |
| 737 | |
| 738 | r = hdmi_get_clocks(pdev); |
| 739 | if (r) { |
| 740 | DSSERR("can't get clocks\n"); |
| 741 | return r; |
| 742 | } |
| 743 | |
| 744 | irq = platform_get_irq(pdev, 0); |
| 745 | if (irq < 0) { |
| 746 | DSSERR("platform_get_irq failed\n"); |
| 747 | return -ENODEV; |
| 748 | } |
| 749 | |
| 750 | r = devm_request_threaded_irq(&pdev->dev, irq, |
| 751 | NULL, hdmi_irq_handler, |
| 752 | IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp); |
| 753 | if (r) { |
| 754 | DSSERR("HDMI IRQ request failed\n"); |
| 755 | return r; |
| 756 | } |
| 757 | |
| 758 | pm_runtime_enable(&pdev->dev); |
| 759 | |
| 760 | hdmi_init_output(pdev); |
| 761 | |
| 762 | dss_debugfs_create_file("hdmi", hdmi_dump_regs); |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | static int __exit omapdss_hdmihw_remove(struct platform_device *pdev) |
| 768 | { |
| 769 | hdmi_uninit_output(pdev); |
| 770 | |
| 771 | pm_runtime_disable(&pdev->dev); |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static int hdmi_runtime_suspend(struct device *dev) |
| 777 | { |
| 778 | clk_disable_unprepare(hdmi.sys_clk); |
| 779 | |
| 780 | dispc_runtime_put(); |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static int hdmi_runtime_resume(struct device *dev) |
| 786 | { |
| 787 | int r; |
| 788 | |
| 789 | r = dispc_runtime_get(); |
| 790 | if (r < 0) |
| 791 | return r; |
| 792 | |
| 793 | clk_prepare_enable(hdmi.sys_clk); |
| 794 | |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | static const struct dev_pm_ops hdmi_pm_ops = { |
| 799 | .runtime_suspend = hdmi_runtime_suspend, |
| 800 | .runtime_resume = hdmi_runtime_resume, |
| 801 | }; |
| 802 | |
| 803 | static const struct of_device_id hdmi_of_match[] = { |
| 804 | { .compatible = "ti,omap5-hdmi", }, |
| 805 | {}, |
| 806 | }; |
| 807 | |
| 808 | static struct platform_driver omapdss_hdmihw_driver = { |
| 809 | .probe = omapdss_hdmihw_probe, |
| 810 | .remove = __exit_p(omapdss_hdmihw_remove), |
| 811 | .driver = { |
| 812 | .name = "omapdss_hdmi5", |
| 813 | .owner = THIS_MODULE, |
| 814 | .pm = &hdmi_pm_ops, |
| 815 | .of_match_table = hdmi_of_match, |
Tomi Valkeinen | 422ccbd | 2014-10-16 09:54:25 +0300 | [diff] [blame] | 816 | .suppress_bind_attrs = true, |
Tomi Valkeinen | f5bab22 | 2014-03-13 12:44:14 +0200 | [diff] [blame] | 817 | }, |
| 818 | }; |
| 819 | |
| 820 | int __init hdmi5_init_platform_driver(void) |
| 821 | { |
| 822 | return platform_driver_register(&omapdss_hdmihw_driver); |
| 823 | } |
| 824 | |
| 825 | void __exit hdmi5_uninit_platform_driver(void) |
| 826 | { |
| 827 | platform_driver_unregister(&omapdss_hdmihw_driver); |
| 828 | } |