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 9 #include <linux/errno.h> 10 #include <linux/kernel.h> 11 12 #include "mipi-phy.h" 13 14 /* 15 * Default D-PHY timings based on MIPI D-PHY specification. Derived from 16 * the valid ranges specified in Section 5.9 of the D-PHY specification 17 * with minor adjustments. 18 */ 19 int mipi_dphy_timing_get_default(struct mipi_dphy_timing *timing, 20 unsigned long period) 21 { 22 timing->clkmiss = 0; 23 timing->clkpost = 70 + 52 * period; 24 timing->clkpre = 8; 25 timing->clkprepare = 65; 26 timing->clksettle = 95; 27 timing->clktermen = 0; 28 timing->clktrail = 80; 29 timing->clkzero = 260; 30 timing->dtermen = 0; 31 timing->eot = 0; 32 timing->hsexit = 120; 33 timing->hsprepare = 65 + 5 * period; 34 timing->hszero = 145 + 5 * period; 35 timing->hssettle = 85 + 6 * period; 36 timing->hsskip = 40; 37 timing->hstrail = max(8 * period, 60 + 4 * period); 38 timing->init = 100000; 39 timing->lpx = 60; 40 timing->taget = 5 * timing->lpx; 41 timing->tago = 4 * timing->lpx; 42 timing->tasure = 2 * timing->lpx; 43 timing->wakeup = 1000000; 44 45 return 0; 46 } 47 48 /* 49 * Validate D-PHY timing according to MIPI Alliance Specification for D-PHY, 50 * Section 5.9 "Global Operation Timing Parameters". 51 */ 52 int mipi_dphy_timing_validate(struct mipi_dphy_timing *timing, 53 unsigned long period) 54 { 55 if (timing->clkmiss > 60) 56 return -EINVAL; 57 58 if (timing->clkpost < (60 + 52 * period)) 59 return -EINVAL; 60 61 if (timing->clkpre < 8) 62 return -EINVAL; 63 64 if (timing->clkprepare < 38 || timing->clkprepare > 95) 65 return -EINVAL; 66 67 if (timing->clksettle < 95 || timing->clksettle > 300) 68 return -EINVAL; 69 70 if (timing->clktermen > 38) 71 return -EINVAL; 72 73 if (timing->clktrail < 60) 74 return -EINVAL; 75 76 if (timing->clkprepare + timing->clkzero < 300) 77 return -EINVAL; 78 79 if (timing->dtermen > 35 + 4 * period) 80 return -EINVAL; 81 82 if (timing->eot > 105 + 12 * period) 83 return -EINVAL; 84 85 if (timing->hsexit < 100) 86 return -EINVAL; 87 88 if (timing->hsprepare < 40 + 4 * period || 89 timing->hsprepare > 85 + 6 * period) 90 return -EINVAL; 91 92 if (timing->hsprepare + timing->hszero < 145 + 10 * period) 93 return -EINVAL; 94 95 if ((timing->hssettle < 85 + 6 * period) || 96 (timing->hssettle > 145 + 10 * period)) 97 return -EINVAL; 98 99 if (timing->hsskip < 40 || timing->hsskip > 55 + 4 * period) 100 return -EINVAL; 101 102 if (timing->hstrail < max(8 * period, 60 + 4 * period)) 103 return -EINVAL; 104 105 if (timing->init < 100000) 106 return -EINVAL; 107 108 if (timing->lpx < 50) 109 return -EINVAL; 110 111 if (timing->taget != 5 * timing->lpx) 112 return -EINVAL; 113 114 if (timing->tago != 4 * timing->lpx) 115 return -EINVAL; 116 117 if (timing->tasure < timing->lpx || timing->tasure > 2 * timing->lpx) 118 return -EINVAL; 119 120 if (timing->wakeup < 1000000) 121 return -EINVAL; 122 123 return 0; 124 } 125