aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/tegra/mipi-phy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/tegra/mipi-phy.c')
-rw-r--r--drivers/gpu/drm/tegra/mipi-phy.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/drivers/gpu/drm/tegra/mipi-phy.c b/drivers/gpu/drm/tegra/mipi-phy.c
new file mode 100644
index 000000000000..1d2ad267cfce
--- /dev/null
+++ b/drivers/gpu/drm/tegra/mipi-phy.c
@@ -0,0 +1,137 @@
1/*
2 * Copyright (C) 2013 NVIDIA Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <linux/kernel.h>
24
25#include "mipi-phy.h"
26
27/*
28 * Default D-PHY timings based on MIPI D-PHY specification. Derived from
29 * the valid ranges specified in Section 5.9 of the D-PHY specification
30 * with minor adjustments.
31 */
32int mipi_dphy_timing_get_default(struct mipi_dphy_timing *timing,
33 unsigned long period)
34{
35 timing->clkmiss = 0;
36 timing->clkpost = 70 + 52 * period;
37 timing->clkpre = 8;
38 timing->clkprepare = 65;
39 timing->clksettle = 95;
40 timing->clktermen = 0;
41 timing->clktrail = 80;
42 timing->clkzero = 260;
43 timing->dtermen = 0;
44 timing->eot = 0;
45 timing->hsexit = 120;
46 timing->hsprepare = 65 + 5 * period;
47 timing->hszero = 145 + 5 * period;
48 timing->hssettle = 85 + 6 * period;
49 timing->hsskip = 40;
50 timing->hstrail = max(8 * period, 60 + 4 * period);
51 timing->init = 100000;
52 timing->lpx = 60;
53 timing->taget = 5 * timing->lpx;
54 timing->tago = 4 * timing->lpx;
55 timing->tasure = 2 * timing->lpx;
56 timing->wakeup = 1000000;
57
58 return 0;
59}
60
61/*
62 * Validate D-PHY timing according to MIPI Alliance Specification for D-PHY,
63 * Section 5.9 "Global Operation Timing Parameters".
64 */
65int mipi_dphy_timing_validate(struct mipi_dphy_timing *timing,
66 unsigned long period)
67{
68 if (timing->clkmiss > 60)
69 return -EINVAL;
70
71 if (timing->clkpost < (60 + 52 * period))
72 return -EINVAL;
73
74 if (timing->clkpre < 8)
75 return -EINVAL;
76
77 if (timing->clkprepare < 38 || timing->clkprepare > 95)
78 return -EINVAL;
79
80 if (timing->clksettle < 95 || timing->clksettle > 300)
81 return -EINVAL;
82
83 if (timing->clktermen > 38)
84 return -EINVAL;
85
86 if (timing->clktrail < 60)
87 return -EINVAL;
88
89 if (timing->clkprepare + timing->clkzero < 300)
90 return -EINVAL;
91
92 if (timing->dtermen > 35 + 4 * period)
93 return -EINVAL;
94
95 if (timing->eot > 105 + 12 * period)
96 return -EINVAL;
97
98 if (timing->hsexit < 100)
99 return -EINVAL;
100
101 if (timing->hsprepare < 40 + 4 * period ||
102 timing->hsprepare > 85 + 6 * period)
103 return -EINVAL;
104
105 if (timing->hsprepare + timing->hszero < 145 + 10 * period)
106 return -EINVAL;
107
108 if ((timing->hssettle < 85 + 6 * period) ||
109 (timing->hssettle > 145 + 10 * period))
110 return -EINVAL;
111
112 if (timing->hsskip < 40 || timing->hsskip > 55 + 4 * period)
113 return -EINVAL;
114
115 if (timing->hstrail < max(8 * period, 60 + 4 * period))
116 return -EINVAL;
117
118 if (timing->init < 100000)
119 return -EINVAL;
120
121 if (timing->lpx < 50)
122 return -EINVAL;
123
124 if (timing->taget != 5 * timing->lpx)
125 return -EINVAL;
126
127 if (timing->tago != 4 * timing->lpx)
128 return -EINVAL;
129
130 if (timing->tasure < timing->lpx || timing->tasure > 2 * timing->lpx)
131 return -EINVAL;
132
133 if (timing->wakeup < 1000000)
134 return -EINVAL;
135
136 return 0;
137}