xref: /openbmc/linux/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h (revision e8254a8e)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef __DSI_PHY_H__
7 #define __DSI_PHY_H__
8 
9 #include <linux/clk-provider.h>
10 #include <linux/delay.h>
11 #include <linux/regulator/consumer.h>
12 
13 #include "dsi.h"
14 
15 #define dsi_phy_read(offset) msm_readl((offset))
16 #define dsi_phy_write(offset, data) msm_writel((data), (offset))
17 #define dsi_phy_write_udelay(offset, data, delay_us) { msm_writel((data), (offset)); udelay(delay_us); }
18 #define dsi_phy_write_ndelay(offset, data, delay_ns) { msm_writel((data), (offset)); ndelay(delay_ns); }
19 
20 struct msm_dsi_phy_ops {
21 	int (*pll_init)(struct msm_dsi_phy *phy);
22 	int (*enable)(struct msm_dsi_phy *phy,
23 			struct msm_dsi_phy_clk_request *clk_req);
24 	void (*disable)(struct msm_dsi_phy *phy);
25 	void (*save_pll_state)(struct msm_dsi_phy *phy);
26 	int (*restore_pll_state)(struct msm_dsi_phy *phy);
27 	bool (*set_continuous_clock)(struct msm_dsi_phy *phy, bool enable);
28 	int (*parse_dt_properties)(struct msm_dsi_phy *phy);
29 };
30 
31 struct msm_dsi_phy_cfg {
32 	const struct regulator_bulk_data *regulator_data;
33 	int num_regulators;
34 	struct msm_dsi_phy_ops ops;
35 
36 	unsigned long	min_pll_rate;
37 	unsigned long	max_pll_rate;
38 
39 	const resource_size_t io_start[DSI_MAX];
40 	const int num_dsi_phy;
41 	const int quirks;
42 	bool has_phy_regulator;
43 	bool has_phy_lane;
44 };
45 
46 extern const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_cfgs;
47 extern const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_famb_cfgs;
48 extern const struct msm_dsi_phy_cfg dsi_phy_28nm_lp_cfgs;
49 extern const struct msm_dsi_phy_cfg dsi_phy_20nm_cfgs;
50 extern const struct msm_dsi_phy_cfg dsi_phy_28nm_8960_cfgs;
51 extern const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs;
52 extern const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs;
53 extern const struct msm_dsi_phy_cfg dsi_phy_14nm_2290_cfgs;
54 extern const struct msm_dsi_phy_cfg dsi_phy_14nm_8953_cfgs;
55 extern const struct msm_dsi_phy_cfg dsi_phy_10nm_cfgs;
56 extern const struct msm_dsi_phy_cfg dsi_phy_10nm_8998_cfgs;
57 extern const struct msm_dsi_phy_cfg dsi_phy_7nm_cfgs;
58 extern const struct msm_dsi_phy_cfg dsi_phy_7nm_8150_cfgs;
59 extern const struct msm_dsi_phy_cfg dsi_phy_7nm_7280_cfgs;
60 
61 struct msm_dsi_dphy_timing {
62 	u32 clk_zero;
63 	u32 clk_trail;
64 	u32 clk_prepare;
65 	u32 hs_exit;
66 	u32 hs_zero;
67 	u32 hs_prepare;
68 	u32 hs_trail;
69 	u32 hs_rqst;
70 	u32 ta_go;
71 	u32 ta_sure;
72 	u32 ta_get;
73 
74 	struct msm_dsi_phy_shared_timings shared_timings;
75 
76 	/* For PHY v2 only */
77 	u32 hs_rqst_ckln;
78 	u32 hs_prep_dly;
79 	u32 hs_prep_dly_ckln;
80 	u8 hs_halfbyte_en;
81 	u8 hs_halfbyte_en_ckln;
82 };
83 
84 #define DSI_BYTE_PLL_CLK		0
85 #define DSI_PIXEL_PLL_CLK		1
86 #define NUM_PROVIDED_CLKS		2
87 
88 #define DSI_LANE_MAX			5
89 
90 struct msm_dsi_phy {
91 	struct platform_device *pdev;
92 	void __iomem *base;
93 	void __iomem *pll_base;
94 	void __iomem *reg_base;
95 	void __iomem *lane_base;
96 	phys_addr_t base_size;
97 	phys_addr_t pll_size;
98 	phys_addr_t reg_size;
99 	phys_addr_t lane_size;
100 	int id;
101 
102 	struct clk *ahb_clk;
103 	struct regulator_bulk_data *supplies;
104 
105 	struct msm_dsi_dphy_timing timing;
106 	const struct msm_dsi_phy_cfg *cfg;
107 	void *tuning_cfg;
108 
109 	enum msm_dsi_phy_usecase usecase;
110 	bool regulator_ldo_mode;
111 	bool cphy_mode;
112 
113 	struct clk_hw *vco_hw;
114 	bool pll_on;
115 
116 	struct clk_hw_onecell_data *provided_clocks;
117 
118 	bool state_saved;
119 };
120 
121 /*
122  * PHY internal functions
123  */
124 int msm_dsi_dphy_timing_calc(struct msm_dsi_dphy_timing *timing,
125 			     struct msm_dsi_phy_clk_request *clk_req);
126 int msm_dsi_dphy_timing_calc_v2(struct msm_dsi_dphy_timing *timing,
127 				struct msm_dsi_phy_clk_request *clk_req);
128 int msm_dsi_dphy_timing_calc_v3(struct msm_dsi_dphy_timing *timing,
129 				struct msm_dsi_phy_clk_request *clk_req);
130 int msm_dsi_dphy_timing_calc_v4(struct msm_dsi_dphy_timing *timing,
131 				struct msm_dsi_phy_clk_request *clk_req);
132 int msm_dsi_cphy_timing_calc_v4(struct msm_dsi_dphy_timing *timing,
133 				struct msm_dsi_phy_clk_request *clk_req);
134 
135 #endif /* __DSI_PHY_H__ */
136