Linux Audio

Check our new training course

Loading...
v4.6
 
  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 the
 16 * valid ranges specified in Section 6.9, Table 14, Page 40 of the D-PHY
 17 * specification (v1.2) with minor adjustments.
 18 */
 19int 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
 38	/*
 39	 * The MIPI D-PHY specification (Section 6.9, v1.2, Table 14, Page 40)
 40	 * contains this formula as:
 41	 *
 42	 *     T_HS-TRAIL = max(n * 8 * period, 60 + n * 4 * period)
 43	 *
 44	 * where n = 1 for forward-direction HS mode and n = 4 for reverse-
 45	 * direction HS mode. There's only one setting and this function does
 46	 * not parameterize on anything other that period, so this code will
 47	 * assumes that reverse-direction HS mode is supported and uses n = 4.
 48	 */
 49	timing->hstrail = max(4 * 8 * period, 60 + 4 * 4 * period);
 50
 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 D-PHY specification (v1.2, Section
 63 * Section 6.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}
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2013 NVIDIA Corporation
 
 
 
 
  4 */
  5
  6#include <linux/errno.h>
  7#include <linux/kernel.h>
  8
  9#include "mipi-phy.h"
 10
 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 */
 16int 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	/*
 36	 * The MIPI D-PHY specification (Section 6.9, v1.2, Table 14, Page 40)
 37	 * contains this formula as:
 38	 *
 39	 *     T_HS-TRAIL = max(n * 8 * period, 60 + n * 4 * period)
 40	 *
 41	 * where n = 1 for forward-direction HS mode and n = 4 for reverse-
 42	 * direction HS mode. There's only one setting and this function does
 43	 * not parameterize on anything other that period, so this code will
 44	 * assumes that reverse-direction HS mode is supported and uses n = 4.
 45	 */
 46	timing->hstrail = max(4 * 8 * period, 60 + 4 * 4 * period);
 47
 48	timing->init = 100000;
 49	timing->lpx = 60;
 50	timing->taget = 5 * timing->lpx;
 51	timing->tago = 4 * timing->lpx;
 52	timing->tasure = 2 * timing->lpx;
 53	timing->wakeup = 1000000;
 54
 55	return 0;
 56}
 57
 58/*
 59 * Validate D-PHY timing according to MIPI D-PHY specification (v1.2, Section
 60 * Section 6.9 "Global Operation Timing Parameters").
 61 */
 62int mipi_dphy_timing_validate(struct mipi_dphy_timing *timing,
 63			      unsigned long period)
 64{
 65	if (timing->clkmiss > 60)
 66		return -EINVAL;
 67
 68	if (timing->clkpost < (60 + 52 * period))
 69		return -EINVAL;
 70
 71	if (timing->clkpre < 8)
 72		return -EINVAL;
 73
 74	if (timing->clkprepare < 38 || timing->clkprepare > 95)
 75		return -EINVAL;
 76
 77	if (timing->clksettle < 95 || timing->clksettle > 300)
 78		return -EINVAL;
 79
 80	if (timing->clktermen > 38)
 81		return -EINVAL;
 82
 83	if (timing->clktrail < 60)
 84		return -EINVAL;
 85
 86	if (timing->clkprepare + timing->clkzero < 300)
 87		return -EINVAL;
 88
 89	if (timing->dtermen > 35 + 4 * period)
 90		return -EINVAL;
 91
 92	if (timing->eot > 105 + 12 * period)
 93		return -EINVAL;
 94
 95	if (timing->hsexit < 100)
 96		return -EINVAL;
 97
 98	if (timing->hsprepare < 40 + 4 * period ||
 99	    timing->hsprepare > 85 + 6 * period)
100		return -EINVAL;
101
102	if (timing->hsprepare + timing->hszero < 145 + 10 * period)
103		return -EINVAL;
104
105	if ((timing->hssettle < 85 + 6 * period) ||
106	    (timing->hssettle > 145 + 10 * period))
107		return -EINVAL;
108
109	if (timing->hsskip < 40 || timing->hsskip > 55 + 4 * period)
110		return -EINVAL;
111
112	if (timing->hstrail < max(8 * period, 60 + 4 * period))
113		return -EINVAL;
114
115	if (timing->init < 100000)
116		return -EINVAL;
117
118	if (timing->lpx < 50)
119		return -EINVAL;
120
121	if (timing->taget != 5 * timing->lpx)
122		return -EINVAL;
123
124	if (timing->tago != 4 * timing->lpx)
125		return -EINVAL;
126
127	if (timing->tasure < timing->lpx || timing->tasure > 2 * timing->lpx)
128		return -EINVAL;
129
130	if (timing->wakeup < 1000000)
131		return -EINVAL;
132
133	return 0;
134}