mipi-phy.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2013 NVIDIA Corporation
  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 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/kernel.h>
  10. #include "mipi-phy.h"
  11. /*
  12. * Default D-PHY timings based on MIPI D-PHY specification. Derived from the
  13. * valid ranges specified in Section 6.9, Table 14, Page 40 of the D-PHY
  14. * specification (v1.2) with minor adjustments.
  15. */
  16. int mipi_dphy_timing_get_default(struct mipi_dphy_timing *timing,
  17. unsigned long period)
  18. {
  19. timing->clkmiss = 0;
  20. timing->clkpost = 70 + 52 * period;
  21. timing->clkpre = 8;
  22. timing->clkprepare = 65;
  23. timing->clksettle = 95;
  24. timing->clktermen = 0;
  25. timing->clktrail = 80;
  26. timing->clkzero = 260;
  27. timing->dtermen = 0;
  28. timing->eot = 0;
  29. timing->hsexit = 120;
  30. timing->hsprepare = 65 + 5 * period;
  31. timing->hszero = 145 + 5 * period;
  32. timing->hssettle = 85 + 6 * period;
  33. timing->hsskip = 40;
  34. /*
  35. * The MIPI D-PHY specification (Section 6.9, v1.2, Table 14, Page 40)
  36. * contains this formula as:
  37. *
  38. * T_HS-TRAIL = max(n * 8 * period, 60 + n * 4 * period)
  39. *
  40. * where n = 1 for forward-direction HS mode and n = 4 for reverse-
  41. * direction HS mode. There's only one setting and this function does
  42. * not parameterize on anything other that period, so this code will
  43. * assumes that reverse-direction HS mode is supported and uses n = 4.
  44. */
  45. timing->hstrail = max(4 * 8 * period, 60 + 4 * 4 * period);
  46. timing->init = 100000;
  47. timing->lpx = 60;
  48. timing->taget = 5 * timing->lpx;
  49. timing->tago = 4 * timing->lpx;
  50. timing->tasure = 2 * timing->lpx;
  51. timing->wakeup = 1000000;
  52. return 0;
  53. }
  54. /*
  55. * Validate D-PHY timing according to MIPI D-PHY specification (v1.2, Section
  56. * Section 6.9 "Global Operation Timing Parameters").
  57. */
  58. int mipi_dphy_timing_validate(struct mipi_dphy_timing *timing,
  59. unsigned long period)
  60. {
  61. if (timing->clkmiss > 60)
  62. return -EINVAL;
  63. if (timing->clkpost < (60 + 52 * period))
  64. return -EINVAL;
  65. if (timing->clkpre < 8)
  66. return -EINVAL;
  67. if (timing->clkprepare < 38 || timing->clkprepare > 95)
  68. return -EINVAL;
  69. if (timing->clksettle < 95 || timing->clksettle > 300)
  70. return -EINVAL;
  71. if (timing->clktermen > 38)
  72. return -EINVAL;
  73. if (timing->clktrail < 60)
  74. return -EINVAL;
  75. if (timing->clkprepare + timing->clkzero < 300)
  76. return -EINVAL;
  77. if (timing->dtermen > 35 + 4 * period)
  78. return -EINVAL;
  79. if (timing->eot > 105 + 12 * period)
  80. return -EINVAL;
  81. if (timing->hsexit < 100)
  82. return -EINVAL;
  83. if (timing->hsprepare < 40 + 4 * period ||
  84. timing->hsprepare > 85 + 6 * period)
  85. return -EINVAL;
  86. if (timing->hsprepare + timing->hszero < 145 + 10 * period)
  87. return -EINVAL;
  88. if ((timing->hssettle < 85 + 6 * period) ||
  89. (timing->hssettle > 145 + 10 * period))
  90. return -EINVAL;
  91. if (timing->hsskip < 40 || timing->hsskip > 55 + 4 * period)
  92. return -EINVAL;
  93. if (timing->hstrail < max(8 * period, 60 + 4 * period))
  94. return -EINVAL;
  95. if (timing->init < 100000)
  96. return -EINVAL;
  97. if (timing->lpx < 50)
  98. return -EINVAL;
  99. if (timing->taget != 5 * timing->lpx)
  100. return -EINVAL;
  101. if (timing->tago != 4 * timing->lpx)
  102. return -EINVAL;
  103. if (timing->tasure < timing->lpx || timing->tasure > 2 * timing->lpx)
  104. return -EINVAL;
  105. if (timing->wakeup < 1000000)
  106. return -EINVAL;
  107. return 0;
  108. }