xref: /linux/drivers/gpu/drm/msm/hdmi/hdmi.h (revision a6984a3f9a5aef20c0bb17922c6e9a404ca9ef3a)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2013 Red Hat
4  * Author: Rob Clark <robdclark@gmail.com>
5  */
6 
7 #ifndef __HDMI_CONNECTOR_H__
8 #define __HDMI_CONNECTOR_H__
9 
10 #include <linux/i2c.h>
11 #include <linux/clk.h>
12 #include <linux/platform_device.h>
13 #include <linux/regulator/consumer.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/hdmi.h>
16 
17 #include <drm/drm_bridge.h>
18 
19 #include "msm_drv.h"
20 #include "hdmi.xml.h"
21 
22 struct hdmi_phy;
23 struct hdmi_platform_config;
24 
25 struct hdmi_audio {
26 	bool enabled;
27 	int rate;
28 	int channels;
29 };
30 
31 struct hdmi_hdcp_ctrl;
32 
33 struct hdmi {
34 	struct drm_device *dev;
35 	struct platform_device *pdev;
36 
37 	const struct hdmi_platform_config *config;
38 
39 	/* audio state: */
40 	struct hdmi_audio audio;
41 
42 	/* video state: */
43 	bool power_on;
44 	unsigned long int pixclock;
45 
46 	void __iomem *mmio;
47 	void __iomem *qfprom_mmio;
48 	phys_addr_t mmio_phy_addr;
49 
50 	struct regulator_bulk_data *hpd_regs;
51 	struct regulator_bulk_data *pwr_regs;
52 	struct clk **hpd_clks;
53 	struct clk *extp_clk;
54 
55 	struct gpio_desc *hpd_gpiod;
56 
57 	struct hdmi_phy *phy;
58 	struct device *phy_dev;
59 
60 	struct i2c_adapter *i2c;
61 	struct drm_connector *connector;
62 	struct drm_bridge *bridge;
63 
64 	struct drm_bridge *next_bridge;
65 
66 	/* the encoder we are hooked to (outside of hdmi block) */
67 	struct drm_encoder *encoder;
68 
69 	int irq;
70 	struct workqueue_struct *workq;
71 
72 	struct hdmi_hdcp_ctrl *hdcp_ctrl;
73 
74 	/*
75 	* spinlock to protect registers shared by different execution
76 	* REG_HDMI_CTRL
77 	* REG_HDMI_DDC_ARBITRATION
78 	* REG_HDMI_HDCP_INT_CTRL
79 	* REG_HDMI_HPD_CTRL
80 	*/
81 	spinlock_t reg_lock;
82 };
83 
84 /* platform config data (ie. from DT, or pdata) */
85 struct hdmi_platform_config {
86 	/* regulators that need to be on for hpd: */
87 	const char * const *hpd_reg_names;
88 	int hpd_reg_cnt;
89 
90 	/* regulators that need to be on for screen pwr: */
91 	const char * const *pwr_reg_names;
92 	int pwr_reg_cnt;
93 
94 	/* clks that need to be on for hpd: */
95 	const char * const *hpd_clk_names;
96 	int hpd_clk_cnt;
97 };
98 
99 struct hdmi_bridge {
100 	struct drm_bridge base;
101 	struct hdmi *hdmi;
102 	struct work_struct hpd_work;
103 };
104 #define to_hdmi_bridge(x) container_of(x, struct hdmi_bridge, base)
105 
106 void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
107 
108 static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
109 {
110 	writel(data, hdmi->mmio + reg);
111 }
112 
113 static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
114 {
115 	return readl(hdmi->mmio + reg);
116 }
117 
118 static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
119 {
120 	return readl(hdmi->qfprom_mmio + reg);
121 }
122 
123 /*
124  * hdmi phy:
125  */
126 
127 enum hdmi_phy_type {
128 	MSM_HDMI_PHY_8x60,
129 	MSM_HDMI_PHY_8960,
130 	MSM_HDMI_PHY_8x74,
131 	MSM_HDMI_PHY_8996,
132 	MSM_HDMI_PHY_8998,
133 	MSM_HDMI_PHY_MAX,
134 };
135 
136 struct hdmi_phy_cfg {
137 	enum hdmi_phy_type type;
138 	void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
139 	void (*powerdown)(struct hdmi_phy *phy);
140 	const char * const *reg_names;
141 	int num_regs;
142 	const char * const *clk_names;
143 	int num_clks;
144 };
145 
146 extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
147 extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
148 extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
149 extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
150 extern const struct hdmi_phy_cfg msm_hdmi_phy_8998_cfg;
151 
152 struct hdmi_phy {
153 	struct platform_device *pdev;
154 	void __iomem *mmio;
155 	struct hdmi_phy_cfg *cfg;
156 	const struct hdmi_phy_funcs *funcs;
157 	struct regulator_bulk_data *regs;
158 	struct clk **clks;
159 };
160 
161 static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
162 {
163 	writel(data, phy->mmio + reg);
164 }
165 
166 static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
167 {
168 	return readl(phy->mmio + reg);
169 }
170 
171 int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
172 void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
173 void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
174 void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
175 void __init msm_hdmi_phy_driver_register(void);
176 void __exit msm_hdmi_phy_driver_unregister(void);
177 
178 #ifdef CONFIG_COMMON_CLK
179 int msm_hdmi_pll_8960_init(struct platform_device *pdev);
180 int msm_hdmi_pll_8996_init(struct platform_device *pdev);
181 int msm_hdmi_pll_8998_init(struct platform_device *pdev);
182 #else
183 static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
184 {
185 	return -ENODEV;
186 }
187 
188 static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
189 {
190 	return -ENODEV;
191 }
192 
193 static inline int msm_hdmi_pll_8998_init(struct platform_device *pdev)
194 {
195 	return -ENODEV;
196 }
197 #endif
198 
199 /*
200  * audio:
201  */
202 struct hdmi_codec_daifmt;
203 struct hdmi_codec_params;
204 
205 int msm_hdmi_audio_update(struct hdmi *hdmi);
206 int msm_hdmi_bridge_audio_prepare(struct drm_connector *connector,
207 				  struct drm_bridge *bridge,
208 				  struct hdmi_codec_daifmt *daifmt,
209 				  struct hdmi_codec_params *params);
210 void msm_hdmi_bridge_audio_shutdown(struct drm_connector *connector,
211 				    struct drm_bridge *bridge);
212 
213 /*
214  * hdmi bridge:
215  */
216 
217 int msm_hdmi_bridge_init(struct hdmi *hdmi);
218 
219 void msm_hdmi_hpd_irq(struct drm_bridge *bridge);
220 enum drm_connector_status msm_hdmi_bridge_detect(
221 		struct drm_bridge *bridge);
222 int msm_hdmi_hpd_enable(struct drm_bridge *bridge);
223 void msm_hdmi_hpd_disable(struct hdmi *hdmi);
224 
225 /*
226  * i2c adapter for ddc:
227  */
228 
229 void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
230 void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
231 struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
232 
233 /*
234  * hdcp
235  */
236 #ifdef CONFIG_DRM_MSM_HDMI_HDCP
237 struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
238 void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
239 void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
240 void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
241 void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
242 #else
243 static inline struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi)
244 {
245 	return ERR_PTR(-ENXIO);
246 }
247 static inline void msm_hdmi_hdcp_destroy(struct hdmi *hdmi) {}
248 static inline void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
249 static inline void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
250 static inline void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl) {}
251 #endif
252 
253 #endif /* __HDMI_CONNECTOR_H__ */
254