Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 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 | |
Stephen Warren | 81239c6 | 2013-12-18 13:53:33 -0700 | [diff] [blame] | 23 | #include <linux/errno.h> |
Thierry Reding | dec7273 | 2013-09-03 08:45:46 +0200 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | |
| 26 | #include "mipi-phy.h" |
| 27 | |
| 28 | /* |
| 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. |
| 32 | */ |
| 33 | int mipi_dphy_timing_get_default(struct mipi_dphy_timing *timing, |
| 34 | unsigned long period) |
| 35 | { |
| 36 | timing->clkmiss = 0; |
| 37 | timing->clkpost = 70 + 52 * period; |
| 38 | timing->clkpre = 8; |
| 39 | timing->clkprepare = 65; |
| 40 | timing->clksettle = 95; |
| 41 | timing->clktermen = 0; |
| 42 | timing->clktrail = 80; |
| 43 | timing->clkzero = 260; |
| 44 | timing->dtermen = 0; |
| 45 | timing->eot = 0; |
| 46 | timing->hsexit = 120; |
| 47 | timing->hsprepare = 65 + 5 * period; |
| 48 | timing->hszero = 145 + 5 * period; |
| 49 | timing->hssettle = 85 + 6 * period; |
| 50 | timing->hsskip = 40; |
| 51 | timing->hstrail = max(8 * period, 60 + 4 * period); |
| 52 | timing->init = 100000; |
| 53 | timing->lpx = 60; |
| 54 | timing->taget = 5 * timing->lpx; |
| 55 | timing->tago = 4 * timing->lpx; |
| 56 | timing->tasure = 2 * timing->lpx; |
| 57 | timing->wakeup = 1000000; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Validate D-PHY timing according to MIPI Alliance Specification for D-PHY, |
| 64 | * Section 5.9 "Global Operation Timing Parameters". |
| 65 | */ |
| 66 | int mipi_dphy_timing_validate(struct mipi_dphy_timing *timing, |
| 67 | unsigned long period) |
| 68 | { |
| 69 | if (timing->clkmiss > 60) |
| 70 | return -EINVAL; |
| 71 | |
| 72 | if (timing->clkpost < (60 + 52 * period)) |
| 73 | return -EINVAL; |
| 74 | |
| 75 | if (timing->clkpre < 8) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | if (timing->clkprepare < 38 || timing->clkprepare > 95) |
| 79 | return -EINVAL; |
| 80 | |
| 81 | if (timing->clksettle < 95 || timing->clksettle > 300) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | if (timing->clktermen > 38) |
| 85 | return -EINVAL; |
| 86 | |
| 87 | if (timing->clktrail < 60) |
| 88 | return -EINVAL; |
| 89 | |
| 90 | if (timing->clkprepare + timing->clkzero < 300) |
| 91 | return -EINVAL; |
| 92 | |
| 93 | if (timing->dtermen > 35 + 4 * period) |
| 94 | return -EINVAL; |
| 95 | |
| 96 | if (timing->eot > 105 + 12 * period) |
| 97 | return -EINVAL; |
| 98 | |
| 99 | if (timing->hsexit < 100) |
| 100 | return -EINVAL; |
| 101 | |
| 102 | if (timing->hsprepare < 40 + 4 * period || |
| 103 | timing->hsprepare > 85 + 6 * period) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | if (timing->hsprepare + timing->hszero < 145 + 10 * period) |
| 107 | return -EINVAL; |
| 108 | |
| 109 | if ((timing->hssettle < 85 + 6 * period) || |
| 110 | (timing->hssettle > 145 + 10 * period)) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | if (timing->hsskip < 40 || timing->hsskip > 55 + 4 * period) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | if (timing->hstrail < max(8 * period, 60 + 4 * period)) |
| 117 | return -EINVAL; |
| 118 | |
| 119 | if (timing->init < 100000) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | if (timing->lpx < 50) |
| 123 | return -EINVAL; |
| 124 | |
| 125 | if (timing->taget != 5 * timing->lpx) |
| 126 | return -EINVAL; |
| 127 | |
| 128 | if (timing->tago != 4 * timing->lpx) |
| 129 | return -EINVAL; |
| 130 | |
| 131 | if (timing->tasure < timing->lpx || timing->tasure > 2 * timing->lpx) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | if (timing->wakeup < 1000000) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | return 0; |
| 138 | } |