2 * Copyright (C) 2013 NVIDIA Corporation
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.
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
23 #include <linux/errno.h>
24 #include <linux/kernel.h>
29 * Default D-PHY timings based on MIPI D-PHY specification. Derived from
30 * the valid ranges specified in Section 5.9 of the D-PHY specification
31 * with minor adjustments.
33 int mipi_dphy_timing_get_default(struct mipi_dphy_timing
*timing
,
37 timing
->clkpost
= 70 + 52 * period
;
39 timing
->clkprepare
= 65;
40 timing
->clksettle
= 95;
41 timing
->clktermen
= 0;
42 timing
->clktrail
= 80;
43 timing
->clkzero
= 260;
47 timing
->hsprepare
= 65 + 5 * period
;
48 timing
->hszero
= 145 + 5 * period
;
49 timing
->hssettle
= 85 + 6 * period
;
51 timing
->hstrail
= max(8 * period
, 60 + 4 * period
);
52 timing
->init
= 100000;
54 timing
->taget
= 5 * timing
->lpx
;
55 timing
->tago
= 4 * timing
->lpx
;
56 timing
->tasure
= 2 * timing
->lpx
;
57 timing
->wakeup
= 1000000;
63 * Validate D-PHY timing according to MIPI Alliance Specification for D-PHY,
64 * Section 5.9 "Global Operation Timing Parameters".
66 int mipi_dphy_timing_validate(struct mipi_dphy_timing
*timing
,
69 if (timing
->clkmiss
> 60)
72 if (timing
->clkpost
< (60 + 52 * period
))
75 if (timing
->clkpre
< 8)
78 if (timing
->clkprepare
< 38 || timing
->clkprepare
> 95)
81 if (timing
->clksettle
< 95 || timing
->clksettle
> 300)
84 if (timing
->clktermen
> 38)
87 if (timing
->clktrail
< 60)
90 if (timing
->clkprepare
+ timing
->clkzero
< 300)
93 if (timing
->dtermen
> 35 + 4 * period
)
96 if (timing
->eot
> 105 + 12 * period
)
99 if (timing
->hsexit
< 100)
102 if (timing
->hsprepare
< 40 + 4 * period
||
103 timing
->hsprepare
> 85 + 6 * period
)
106 if (timing
->hsprepare
+ timing
->hszero
< 145 + 10 * period
)
109 if ((timing
->hssettle
< 85 + 6 * period
) ||
110 (timing
->hssettle
> 145 + 10 * period
))
113 if (timing
->hsskip
< 40 || timing
->hsskip
> 55 + 4 * period
)
116 if (timing
->hstrail
< max(8 * period
, 60 + 4 * period
))
119 if (timing
->init
< 100000)
122 if (timing
->lpx
< 50)
125 if (timing
->taget
!= 5 * timing
->lpx
)
128 if (timing
->tago
!= 4 * timing
->lpx
)
131 if (timing
->tasure
< timing
->lpx
|| timing
->tasure
> 2 * timing
->lpx
)
134 if (timing
->wakeup
< 1000000)