summaryrefstree
path: root/kernel/techpack/display/msm/dp/dp_pll.h
blob: 87f7619066b3b6c40e88aea28302880c66f454ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
 */

#ifndef __DP_PLL_H
#define __DP_PLL_H

#include <linux/io.h>
#include <linux/clk-provider.h>
#include <linux/of_device.h>
#include "dp_parser.h"
#include "sde_dbg.h"

#define DP_VCO_HSCLK_RATE_1620MHZDIV1000	1620000UL
#define DP_VCO_HSCLK_RATE_2700MHZDIV1000	2700000UL
#define DP_VCO_HSCLK_RATE_5400MHZDIV1000	5400000UL
#define DP_VCO_HSCLK_RATE_8100MHZDIV1000	8100000UL

#define dp_pll_get_base(x) pll->io.x->io.base

#define dp_pll_read(x, offset) ({ \
		readl_relaxed((dp_pll_get_base(x)) + (offset)); \
})

#define dp_pll_write(x, offset, data) ({ \
		DP_DEBUG(#offset", addr=0x%x, val=0x%x\n", \
				(dp_pll_get_base(x)) + (offset), (data)); \
		SDE_EVT32_VERBOSE((dp_pll_get_base(x)) + (offset), (data)); \
		writel_relaxed((data), (dp_pll_get_base(x)) + (offset)); \
})

enum dp_pll_revision {
	DP_PLL_UNKNOWN,
	DP_PLL_5NM_V1,
	DP_PLL_5NM_V2,
};

static inline const char *dp_pll_get_revision(enum dp_pll_revision rev)
{
	switch (rev) {
	case DP_PLL_UNKNOWN:	return "DP_PLL_UNKNOWN";
	case DP_PLL_5NM_V1:	return "DP_PLL_5NM_V1";
	case DP_PLL_5NM_V2:	return "DP_PLL_5NM_V2";
	default:		return "???";
	}
}

struct dp_pll_io {
	struct dp_io_data *dp_phy;
	struct dp_io_data *dp_pll;
	struct dp_io_data *dp_ln_tx0;
	struct dp_io_data *dp_ln_tx1;
	struct dp_io_data *gdsc;
};

struct dp_pll_vco_clk {
	struct clk_hw hw;
	unsigned long	rate;		/* current vco rate */
	u64		min_rate;	/* min vco rate */
	u64		max_rate;	/* max vco rate */
	void		*priv;
};

struct dp_pll {
	/*
	 * target pll revision information
	 */
	u32		revision;

	/*
	 * Certain plls needs to update the same vco rate after resume in
	 * suspend/resume scenario. Cached the vco rate for such plls.
	 */
	unsigned long	vco_cached_rate;

	/*
	 * PLL index if multiple index are available. Eg. in case of
	 * DSI we have 2 plls.
	 */
	uint32_t index;

	bool ssc_en;
	bool bonding_en;

	void *priv;
	struct platform_device *pdev;
	struct dp_parser *parser;
	struct dp_power *power;
	struct dp_aux *aux;
	struct dp_pll_io io;
	struct clk_onecell_data *clk_data;
};

struct dp_pll_db {
	struct dp_pll *pll;

	/* lane and orientation settings */
	u8 lane_cnt;
	u8 orientation;

	/* COM PHY settings */
	u32 hsclk_sel;
	u32 dec_start_mode0;
	u32 div_frac_start1_mode0;
	u32 div_frac_start2_mode0;
	u32 div_frac_start3_mode0;
	u32 integloop_gain0_mode0;
	u32 integloop_gain1_mode0;
	u32 lock_cmp1_mode0;
	u32 lock_cmp2_mode0;
	u32 lock_cmp_en;
	u32 ssc_step_size1_mode0;
	u32 ssc_step_size2_mode0;

	/* PHY vco divider */
	u32 phy_vco_div;
};


static inline struct dp_pll_vco_clk *to_dp_vco_hw(struct clk_hw *hw)
{
	return container_of(hw, struct dp_pll_vco_clk, hw);
}

static inline bool is_gdsc_disabled(struct dp_pll *pll)
{
	return (dp_pll_read(gdsc, 0x0) & BIT(31)) ? false : true;
}

int dp_pll_clock_register_5nm(struct dp_pll *pll);
void dp_pll_clock_unregister_5nm(struct dp_pll *pll);

struct dp_pll_in {
	struct platform_device *pdev;
	struct dp_aux *aux;
	struct dp_parser *parser;
};

struct dp_pll *dp_pll_get(struct dp_pll_in *in);
void dp_pll_put(struct dp_pll *pll);
#endif /* __DP_PLL_H */