.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License version 2 and |
---|
6 | | - * only version 2 as published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | 4 | */ |
---|
13 | 5 | |
---|
14 | 6 | #include <linux/platform_device.h> |
---|
.. | .. |
---|
153 | 145 | { |
---|
154 | 146 | const unsigned long bit_rate = clk_req->bitclk_rate; |
---|
155 | 147 | const unsigned long esc_rate = clk_req->escclk_rate; |
---|
156 | | - s32 ui, ui_x8, lpx; |
---|
| 148 | + s32 ui, ui_x8; |
---|
157 | 149 | s32 tmax, tmin; |
---|
158 | 150 | s32 pcnt0 = 50; |
---|
159 | 151 | s32 pcnt1 = 50; |
---|
.. | .. |
---|
183 | 175 | |
---|
184 | 176 | ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000); |
---|
185 | 177 | ui_x8 = ui << 3; |
---|
186 | | - lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000); |
---|
187 | 178 | |
---|
188 | 179 | temp = S_DIV_ROUND_UP(38 * coeff - val_ckln * ui, ui_x8); |
---|
189 | 180 | tmin = max_t(s32, temp, 0); |
---|
.. | .. |
---|
270 | 261 | { |
---|
271 | 262 | const unsigned long bit_rate = clk_req->bitclk_rate; |
---|
272 | 263 | const unsigned long esc_rate = clk_req->escclk_rate; |
---|
273 | | - s32 ui, ui_x8, lpx; |
---|
| 264 | + s32 ui, ui_x8; |
---|
274 | 265 | s32 tmax, tmin; |
---|
275 | 266 | s32 pcnt0 = 50; |
---|
276 | 267 | s32 pcnt1 = 50; |
---|
.. | .. |
---|
292 | 283 | |
---|
293 | 284 | ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000); |
---|
294 | 285 | ui_x8 = ui << 3; |
---|
295 | | - lpx = mult_frac(NSEC_PER_MSEC, coeff, esc_rate / 1000); |
---|
296 | 286 | |
---|
297 | 287 | temp = S_DIV_ROUND_UP(38 * coeff, ui_x8); |
---|
298 | 288 | tmin = max_t(s32, temp, 0); |
---|
.. | .. |
---|
355 | 345 | } else { |
---|
356 | 346 | timing->shared_timings.clk_pre = |
---|
357 | 347 | linear_inter(tmax, tmin, pcnt2, 0, false); |
---|
358 | | - timing->shared_timings.clk_pre_inc_by_2 = 0; |
---|
| 348 | + timing->shared_timings.clk_pre_inc_by_2 = 0; |
---|
359 | 349 | } |
---|
360 | 350 | |
---|
361 | 351 | timing->ta_go = 3; |
---|
.. | .. |
---|
370 | 360 | timing->hs_rqst, timing->hs_rqst_ckln, timing->hs_halfbyte_en, |
---|
371 | 361 | timing->hs_halfbyte_en_ckln, timing->hs_prep_dly, |
---|
372 | 362 | timing->hs_prep_dly_ckln); |
---|
| 363 | + |
---|
| 364 | + return 0; |
---|
| 365 | +} |
---|
| 366 | + |
---|
| 367 | +int msm_dsi_dphy_timing_calc_v4(struct msm_dsi_dphy_timing *timing, |
---|
| 368 | + struct msm_dsi_phy_clk_request *clk_req) |
---|
| 369 | +{ |
---|
| 370 | + const unsigned long bit_rate = clk_req->bitclk_rate; |
---|
| 371 | + const unsigned long esc_rate = clk_req->escclk_rate; |
---|
| 372 | + s32 ui, ui_x8; |
---|
| 373 | + s32 tmax, tmin; |
---|
| 374 | + s32 pcnt_clk_prep = 50; |
---|
| 375 | + s32 pcnt_clk_zero = 2; |
---|
| 376 | + s32 pcnt_clk_trail = 30; |
---|
| 377 | + s32 pcnt_hs_prep = 50; |
---|
| 378 | + s32 pcnt_hs_zero = 10; |
---|
| 379 | + s32 pcnt_hs_trail = 30; |
---|
| 380 | + s32 pcnt_hs_exit = 10; |
---|
| 381 | + s32 coeff = 1000; /* Precision, should avoid overflow */ |
---|
| 382 | + s32 hb_en; |
---|
| 383 | + s32 temp; |
---|
| 384 | + |
---|
| 385 | + if (!bit_rate || !esc_rate) |
---|
| 386 | + return -EINVAL; |
---|
| 387 | + |
---|
| 388 | + hb_en = 0; |
---|
| 389 | + |
---|
| 390 | + ui = mult_frac(NSEC_PER_MSEC, coeff, bit_rate / 1000); |
---|
| 391 | + ui_x8 = ui << 3; |
---|
| 392 | + |
---|
| 393 | + /* TODO: verify these calculations against latest downstream driver |
---|
| 394 | + * everything except clk_post/clk_pre uses calculations from v3 based |
---|
| 395 | + * on the downstream driver having the same calculations for v3 and v4 |
---|
| 396 | + */ |
---|
| 397 | + |
---|
| 398 | + temp = S_DIV_ROUND_UP(38 * coeff, ui_x8); |
---|
| 399 | + tmin = max_t(s32, temp, 0); |
---|
| 400 | + temp = (95 * coeff) / ui_x8; |
---|
| 401 | + tmax = max_t(s32, temp, 0); |
---|
| 402 | + timing->clk_prepare = linear_inter(tmax, tmin, pcnt_clk_prep, 0, false); |
---|
| 403 | + |
---|
| 404 | + temp = 300 * coeff - (timing->clk_prepare << 3) * ui; |
---|
| 405 | + tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1; |
---|
| 406 | + tmax = (tmin > 255) ? 511 : 255; |
---|
| 407 | + timing->clk_zero = linear_inter(tmax, tmin, pcnt_clk_zero, 0, false); |
---|
| 408 | + |
---|
| 409 | + tmin = DIV_ROUND_UP(60 * coeff + 3 * ui, ui_x8); |
---|
| 410 | + temp = 105 * coeff + 12 * ui - 20 * coeff; |
---|
| 411 | + tmax = (temp + 3 * ui) / ui_x8; |
---|
| 412 | + timing->clk_trail = linear_inter(tmax, tmin, pcnt_clk_trail, 0, false); |
---|
| 413 | + |
---|
| 414 | + temp = S_DIV_ROUND_UP(40 * coeff + 4 * ui, ui_x8); |
---|
| 415 | + tmin = max_t(s32, temp, 0); |
---|
| 416 | + temp = (85 * coeff + 6 * ui) / ui_x8; |
---|
| 417 | + tmax = max_t(s32, temp, 0); |
---|
| 418 | + timing->hs_prepare = linear_inter(tmax, tmin, pcnt_hs_prep, 0, false); |
---|
| 419 | + |
---|
| 420 | + temp = 145 * coeff + 10 * ui - (timing->hs_prepare << 3) * ui; |
---|
| 421 | + tmin = S_DIV_ROUND_UP(temp, ui_x8) - 1; |
---|
| 422 | + tmax = 255; |
---|
| 423 | + timing->hs_zero = linear_inter(tmax, tmin, pcnt_hs_zero, 0, false); |
---|
| 424 | + |
---|
| 425 | + tmin = DIV_ROUND_UP(60 * coeff + 4 * ui, ui_x8) - 1; |
---|
| 426 | + temp = 105 * coeff + 12 * ui - 20 * coeff; |
---|
| 427 | + tmax = (temp / ui_x8) - 1; |
---|
| 428 | + timing->hs_trail = linear_inter(tmax, tmin, pcnt_hs_trail, 0, false); |
---|
| 429 | + |
---|
| 430 | + temp = 50 * coeff + ((hb_en << 2) - 8) * ui; |
---|
| 431 | + timing->hs_rqst = S_DIV_ROUND_UP(temp, ui_x8); |
---|
| 432 | + |
---|
| 433 | + tmin = DIV_ROUND_UP(100 * coeff, ui_x8) - 1; |
---|
| 434 | + tmax = 255; |
---|
| 435 | + timing->hs_exit = linear_inter(tmax, tmin, pcnt_hs_exit, 0, false); |
---|
| 436 | + |
---|
| 437 | + /* recommended min |
---|
| 438 | + * = roundup((mipi_min_ns + t_hs_trail_ns)/(16*bit_clk_ns), 0) - 1 |
---|
| 439 | + */ |
---|
| 440 | + temp = 60 * coeff + 52 * ui + + (timing->hs_trail + 1) * ui_x8; |
---|
| 441 | + tmin = DIV_ROUND_UP(temp, 16 * ui) - 1; |
---|
| 442 | + tmax = 255; |
---|
| 443 | + timing->shared_timings.clk_post = linear_inter(tmax, tmin, 5, 0, false); |
---|
| 444 | + |
---|
| 445 | + /* recommended min |
---|
| 446 | + * val1 = (tlpx_ns + clk_prepare_ns + clk_zero_ns + hs_rqst_ns) |
---|
| 447 | + * val2 = (16 * bit_clk_ns) |
---|
| 448 | + * final = roundup(val1/val2, 0) - 1 |
---|
| 449 | + */ |
---|
| 450 | + temp = 52 * coeff + (timing->clk_prepare + timing->clk_zero + 1) * ui_x8 + 54 * coeff; |
---|
| 451 | + tmin = DIV_ROUND_UP(temp, 16 * ui) - 1; |
---|
| 452 | + tmax = 255; |
---|
| 453 | + timing->shared_timings.clk_pre = DIV_ROUND_UP((tmax - tmin) * 125, 10000) + tmin; |
---|
| 454 | + |
---|
| 455 | + DBG("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d", |
---|
| 456 | + timing->shared_timings.clk_pre, timing->shared_timings.clk_post, |
---|
| 457 | + timing->clk_zero, timing->clk_trail, timing->clk_prepare, timing->hs_exit, |
---|
| 458 | + timing->hs_zero, timing->hs_prepare, timing->hs_trail, timing->hs_rqst); |
---|
373 | 459 | |
---|
374 | 460 | return 0; |
---|
375 | 461 | } |
---|
.. | .. |
---|
404 | 490 | |
---|
405 | 491 | ret = devm_regulator_bulk_get(dev, num, s); |
---|
406 | 492 | if (ret < 0) { |
---|
407 | | - dev_err(dev, "%s: failed to init regulator, ret=%d\n", |
---|
408 | | - __func__, ret); |
---|
| 493 | + if (ret != -EPROBE_DEFER) { |
---|
| 494 | + DRM_DEV_ERROR(dev, |
---|
| 495 | + "%s: failed to init regulator, ret=%d\n", |
---|
| 496 | + __func__, ret); |
---|
| 497 | + } |
---|
| 498 | + |
---|
409 | 499 | return ret; |
---|
410 | 500 | } |
---|
411 | 501 | |
---|
.. | .. |
---|
441 | 531 | ret = regulator_set_load(s[i].consumer, |
---|
442 | 532 | regs[i].enable_load); |
---|
443 | 533 | if (ret < 0) { |
---|
444 | | - dev_err(dev, |
---|
| 534 | + DRM_DEV_ERROR(dev, |
---|
445 | 535 | "regulator %d set op mode failed, %d\n", |
---|
446 | 536 | i, ret); |
---|
447 | 537 | goto fail; |
---|
.. | .. |
---|
451 | 541 | |
---|
452 | 542 | ret = regulator_bulk_enable(num, s); |
---|
453 | 543 | if (ret < 0) { |
---|
454 | | - dev_err(dev, "regulator enable failed, %d\n", ret); |
---|
| 544 | + DRM_DEV_ERROR(dev, "regulator enable failed, %d\n", ret); |
---|
455 | 545 | goto fail; |
---|
456 | 546 | } |
---|
457 | 547 | |
---|
.. | .. |
---|
472 | 562 | |
---|
473 | 563 | ret = clk_prepare_enable(phy->ahb_clk); |
---|
474 | 564 | if (ret) { |
---|
475 | | - dev_err(dev, "%s: can't enable ahb clk, %d\n", __func__, ret); |
---|
| 565 | + DRM_DEV_ERROR(dev, "%s: can't enable ahb clk, %d\n", __func__, ret); |
---|
476 | 566 | pm_runtime_put_sync(dev); |
---|
477 | 567 | } |
---|
478 | 568 | |
---|
.. | .. |
---|
489 | 579 | #ifdef CONFIG_DRM_MSM_DSI_28NM_PHY |
---|
490 | 580 | { .compatible = "qcom,dsi-phy-28nm-hpm", |
---|
491 | 581 | .data = &dsi_phy_28nm_hpm_cfgs }, |
---|
| 582 | + { .compatible = "qcom,dsi-phy-28nm-hpm-fam-b", |
---|
| 583 | + .data = &dsi_phy_28nm_hpm_famb_cfgs }, |
---|
492 | 584 | { .compatible = "qcom,dsi-phy-28nm-lp", |
---|
493 | 585 | .data = &dsi_phy_28nm_lp_cfgs }, |
---|
494 | 586 | #endif |
---|
.. | .. |
---|
503 | 595 | #ifdef CONFIG_DRM_MSM_DSI_14NM_PHY |
---|
504 | 596 | { .compatible = "qcom,dsi-phy-14nm", |
---|
505 | 597 | .data = &dsi_phy_14nm_cfgs }, |
---|
| 598 | + { .compatible = "qcom,dsi-phy-14nm-660", |
---|
| 599 | + .data = &dsi_phy_14nm_660_cfgs }, |
---|
506 | 600 | #endif |
---|
507 | 601 | #ifdef CONFIG_DRM_MSM_DSI_10NM_PHY |
---|
508 | 602 | { .compatible = "qcom,dsi-phy-10nm", |
---|
509 | 603 | .data = &dsi_phy_10nm_cfgs }, |
---|
| 604 | + { .compatible = "qcom,dsi-phy-10nm-8998", |
---|
| 605 | + .data = &dsi_phy_10nm_8998_cfgs }, |
---|
| 606 | +#endif |
---|
| 607 | +#ifdef CONFIG_DRM_MSM_DSI_7NM_PHY |
---|
| 608 | + { .compatible = "qcom,dsi-phy-7nm", |
---|
| 609 | + .data = &dsi_phy_7nm_cfgs }, |
---|
| 610 | + { .compatible = "qcom,dsi-phy-7nm-8150", |
---|
| 611 | + .data = &dsi_phy_7nm_8150_cfgs }, |
---|
510 | 612 | #endif |
---|
511 | 613 | {} |
---|
512 | 614 | }; |
---|
.. | .. |
---|
543 | 645 | phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator", |
---|
544 | 646 | "DSI_PHY_REG"); |
---|
545 | 647 | if (IS_ERR(phy->reg_base)) { |
---|
546 | | - dev_err(&pdev->dev, "%s: failed to map phy regulator base\n", |
---|
| 648 | + DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy regulator base\n", |
---|
547 | 649 | __func__); |
---|
548 | 650 | ret = -ENOMEM; |
---|
549 | 651 | goto fail; |
---|
.. | .. |
---|
574 | 676 | phy->id = dsi_phy_get_id(phy); |
---|
575 | 677 | if (phy->id < 0) { |
---|
576 | 678 | ret = phy->id; |
---|
577 | | - dev_err(dev, "%s: couldn't identify PHY index, %d\n", |
---|
| 679 | + DRM_DEV_ERROR(dev, "%s: couldn't identify PHY index, %d\n", |
---|
578 | 680 | __func__, ret); |
---|
579 | 681 | goto fail; |
---|
580 | 682 | } |
---|
.. | .. |
---|
584 | 686 | |
---|
585 | 687 | phy->base = msm_ioremap(pdev, "dsi_phy", "DSI_PHY"); |
---|
586 | 688 | if (IS_ERR(phy->base)) { |
---|
587 | | - dev_err(dev, "%s: failed to map phy base\n", __func__); |
---|
| 689 | + DRM_DEV_ERROR(dev, "%s: failed to map phy base\n", __func__); |
---|
588 | 690 | ret = -ENOMEM; |
---|
589 | 691 | goto fail; |
---|
590 | 692 | } |
---|
591 | 693 | |
---|
592 | 694 | ret = dsi_phy_regulator_init(phy); |
---|
593 | | - if (ret) { |
---|
594 | | - dev_err(dev, "%s: failed to init regulator\n", __func__); |
---|
| 695 | + if (ret) |
---|
595 | 696 | goto fail; |
---|
596 | | - } |
---|
597 | 697 | |
---|
598 | 698 | phy->ahb_clk = msm_clk_get(pdev, "iface"); |
---|
599 | 699 | if (IS_ERR(phy->ahb_clk)) { |
---|
600 | | - dev_err(dev, "%s: Unable to get ahb clk\n", __func__); |
---|
| 700 | + DRM_DEV_ERROR(dev, "%s: Unable to get ahb clk\n", __func__); |
---|
601 | 701 | ret = PTR_ERR(phy->ahb_clk); |
---|
602 | 702 | goto fail; |
---|
603 | 703 | } |
---|
.. | .. |
---|
616 | 716 | goto fail; |
---|
617 | 717 | |
---|
618 | 718 | phy->pll = msm_dsi_pll_init(pdev, phy->cfg->type, phy->id); |
---|
619 | | - if (IS_ERR_OR_NULL(phy->pll)) |
---|
620 | | - dev_info(dev, |
---|
| 719 | + if (IS_ERR_OR_NULL(phy->pll)) { |
---|
| 720 | + DRM_DEV_INFO(dev, |
---|
621 | 721 | "%s: pll init failed: %ld, need separate pll clk driver\n", |
---|
622 | 722 | __func__, PTR_ERR(phy->pll)); |
---|
| 723 | + phy->pll = NULL; |
---|
| 724 | + } |
---|
623 | 725 | |
---|
624 | 726 | dsi_phy_disable_resource(phy); |
---|
625 | 727 | |
---|
.. | .. |
---|
677 | 779 | |
---|
678 | 780 | ret = dsi_phy_enable_resource(phy); |
---|
679 | 781 | if (ret) { |
---|
680 | | - dev_err(dev, "%s: resource enable failed, %d\n", |
---|
| 782 | + DRM_DEV_ERROR(dev, "%s: resource enable failed, %d\n", |
---|
681 | 783 | __func__, ret); |
---|
682 | 784 | goto res_en_fail; |
---|
683 | 785 | } |
---|
684 | 786 | |
---|
685 | 787 | ret = dsi_phy_regulator_enable(phy); |
---|
686 | 788 | if (ret) { |
---|
687 | | - dev_err(dev, "%s: regulator enable failed, %d\n", |
---|
| 789 | + DRM_DEV_ERROR(dev, "%s: regulator enable failed, %d\n", |
---|
688 | 790 | __func__, ret); |
---|
689 | 791 | goto reg_en_fail; |
---|
690 | 792 | } |
---|
691 | 793 | |
---|
692 | 794 | ret = phy->cfg->ops.enable(phy, src_pll_id, clk_req); |
---|
693 | 795 | if (ret) { |
---|
694 | | - dev_err(dev, "%s: phy enable failed, %d\n", __func__, ret); |
---|
| 796 | + DRM_DEV_ERROR(dev, "%s: phy enable failed, %d\n", __func__, ret); |
---|
695 | 797 | goto phy_en_fail; |
---|
696 | 798 | } |
---|
697 | 799 | |
---|
.. | .. |
---|
704 | 806 | if (phy->usecase != MSM_DSI_PHY_SLAVE) { |
---|
705 | 807 | ret = msm_dsi_pll_restore_state(phy->pll); |
---|
706 | 808 | if (ret) { |
---|
707 | | - dev_err(dev, "%s: failed to restore pll state, %d\n", |
---|
| 809 | + DRM_DEV_ERROR(dev, "%s: failed to restore pll state, %d\n", |
---|
708 | 810 | __func__, ret); |
---|
709 | 811 | goto pll_restor_fail; |
---|
710 | 812 | } |
---|