hdmi.h 5.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __HDMI_CONNECTOR_H__
#define __HDMI_CONNECTOR_H__

#include <linux/i2c.h>
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
R
Rob Clark 已提交
25
#include <linux/hdmi.h>
26 27 28 29

#include "msm_drv.h"
#include "hdmi.xml.h"

30
#define HDMI_MAX_NUM_GPIO	6
31 32

struct hdmi_phy;
33
struct hdmi_platform_config;
34

35 36 37 38 39 40 41
struct hdmi_gpio_data {
	int num;
	bool output;
	int value;
	const char *label;
};

R
Rob Clark 已提交
42 43 44 45 46 47
struct hdmi_audio {
	bool enabled;
	struct hdmi_audio_infoframe infoframe;
	int rate;
};

48 49
struct hdmi_hdcp_ctrl;

50 51 52 53
struct hdmi {
	struct drm_device *dev;
	struct platform_device *pdev;

54
	const struct hdmi_platform_config *config;
55

R
Rob Clark 已提交
56 57 58 59 60 61 62
	/* audio state: */
	struct hdmi_audio audio;

	/* video state: */
	bool power_on;
	unsigned long int pixclock;

63
	void __iomem *mmio;
64 65
	void __iomem *qfprom_mmio;
	phys_addr_t mmio_phy_addr;
66

67 68 69 70
	struct regulator **hpd_regs;
	struct regulator **pwr_regs;
	struct clk **hpd_clks;
	struct clk **pwr_clks;
71 72

	struct hdmi_phy *phy;
73 74
	struct device *phy_dev;

75 76
	struct i2c_adapter *i2c;
	struct drm_connector *connector;
R
Rob Clark 已提交
77 78 79 80
	struct drm_bridge *bridge;

	/* the encoder we are hooked to (outside of hdmi block) */
	struct drm_encoder *encoder;
81 82 83 84

	bool hdmi_mode;               /* are we in hdmi mode? */

	int irq;
85 86 87 88 89 90 91 92 93 94 95 96
	struct workqueue_struct *workq;

	struct hdmi_hdcp_ctrl *hdcp_ctrl;

	/*
	* spinlock to protect registers shared by different execution
	* REG_HDMI_CTRL
	* REG_HDMI_DDC_ARBITRATION
	* REG_HDMI_HDCP_INT_CTRL
	* REG_HDMI_HPD_CTRL
	*/
	spinlock_t reg_lock;
97 98 99 100
};

/* platform config data (ie. from DT, or pdata) */
struct hdmi_platform_config {
101
	const char *mmio_name;
102
	const char *qfprom_mmio_name;
103 104 105 106 107 108 109 110 111 112 113

	/* regulators that need to be on for hpd: */
	const char **hpd_reg_names;
	int hpd_reg_cnt;

	/* regulators that need to be on for screen pwr: */
	const char **pwr_reg_names;
	int pwr_reg_cnt;

	/* clks that need to be on for hpd: */
	const char **hpd_clk_names;
114
	const long unsigned *hpd_freq;
115 116 117 118 119 120 121
	int hpd_clk_cnt;

	/* clks that need to be on for screen pwr (ie pixel clk): */
	const char **pwr_clk_names;
	int pwr_clk_cnt;

	/* gpio's: */
122
	struct hdmi_gpio_data gpios[HDMI_MAX_NUM_GPIO];
123 124
};

A
Arnd Bergmann 已提交
125
void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on);
126 127 128 129 130 131 132 133 134 135 136

static inline void hdmi_write(struct hdmi *hdmi, u32 reg, u32 data)
{
	msm_writel(data, hdmi->mmio + reg);
}

static inline u32 hdmi_read(struct hdmi *hdmi, u32 reg)
{
	return msm_readl(hdmi->mmio + reg);
}

137 138 139 140 141
static inline u32 hdmi_qfprom_read(struct hdmi *hdmi, u32 reg)
{
	return msm_readl(hdmi->qfprom_mmio + reg);
}

142
/*
143
 * hdmi phy:
144 145
 */

146 147 148 149
enum hdmi_phy_type {
	MSM_HDMI_PHY_8x60,
	MSM_HDMI_PHY_8960,
	MSM_HDMI_PHY_8x74,
150
	MSM_HDMI_PHY_8996,
151 152 153 154 155 156 157 158 159 160 161 162 163
	MSM_HDMI_PHY_MAX,
};

struct hdmi_phy_cfg {
	enum hdmi_phy_type type;
	void (*powerup)(struct hdmi_phy *phy, unsigned long int pixclock);
	void (*powerdown)(struct hdmi_phy *phy);
	const char * const *reg_names;
	int num_regs;
	const char * const *clk_names;
	int num_clks;
};

A
Arnd Bergmann 已提交
164 165 166 167
extern const struct hdmi_phy_cfg msm_hdmi_phy_8x60_cfg;
extern const struct hdmi_phy_cfg msm_hdmi_phy_8960_cfg;
extern const struct hdmi_phy_cfg msm_hdmi_phy_8x74_cfg;
extern const struct hdmi_phy_cfg msm_hdmi_phy_8996_cfg;
168

169
struct hdmi_phy {
170 171 172
	struct platform_device *pdev;
	void __iomem *mmio;
	struct hdmi_phy_cfg *cfg;
173
	const struct hdmi_phy_funcs *funcs;
174 175
	struct regulator **regs;
	struct clk **clks;
176 177
};

178 179 180 181 182 183 184 185 186 187
static inline void hdmi_phy_write(struct hdmi_phy *phy, u32 reg, u32 data)
{
	msm_writel(data, phy->mmio + reg);
}

static inline u32 hdmi_phy_read(struct hdmi_phy *phy, u32 reg)
{
	return msm_readl(phy->mmio + reg);
}

A
Arnd Bergmann 已提交
188 189 190 191 192 193
int msm_hdmi_phy_resource_enable(struct hdmi_phy *phy);
void msm_hdmi_phy_resource_disable(struct hdmi_phy *phy);
void msm_hdmi_phy_powerup(struct hdmi_phy *phy, unsigned long int pixclock);
void msm_hdmi_phy_powerdown(struct hdmi_phy *phy);
void __init msm_hdmi_phy_driver_register(void);
void __exit msm_hdmi_phy_driver_unregister(void);
194

195
#ifdef CONFIG_COMMON_CLK
A
Arnd Bergmann 已提交
196 197
int msm_hdmi_pll_8960_init(struct platform_device *pdev);
int msm_hdmi_pll_8996_init(struct platform_device *pdev);
198
#else
199
static inline int msm_hdmi_pll_8960_init(struct platform_device *pdev)
200 201 202
{
	return -ENODEV;
}
203

A
Arnd Bergmann 已提交
204
static inline int msm_hdmi_pll_8996_init(struct platform_device *pdev)
205 206 207
{
	return -ENODEV;
}
208 209
#endif

R
Rob Clark 已提交
210 211 212 213
/*
 * audio:
 */

A
Arnd Bergmann 已提交
214 215
int msm_hdmi_audio_update(struct hdmi *hdmi);
int msm_hdmi_audio_info_setup(struct hdmi *hdmi, bool enabled,
R
Rob Clark 已提交
216 217
	uint32_t num_of_channels, uint32_t channel_allocation,
	uint32_t level_shift, bool down_mix);
A
Arnd Bergmann 已提交
218
void msm_hdmi_audio_set_sample_rate(struct hdmi *hdmi, int rate);
R
Rob Clark 已提交
219 220


R
Rob Clark 已提交
221 222 223 224
/*
 * hdmi bridge:
 */

A
Arnd Bergmann 已提交
225 226
struct drm_bridge *msm_hdmi_bridge_init(struct hdmi *hdmi);
void msm_hdmi_bridge_destroy(struct drm_bridge *bridge);
R
Rob Clark 已提交
227

228 229 230 231
/*
 * hdmi connector:
 */

A
Arnd Bergmann 已提交
232 233
void msm_hdmi_connector_irq(struct drm_connector *connector);
struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi);
234 235 236 237 238

/*
 * i2c adapter for ddc:
 */

A
Arnd Bergmann 已提交
239 240 241
void msm_hdmi_i2c_irq(struct i2c_adapter *i2c);
void msm_hdmi_i2c_destroy(struct i2c_adapter *i2c);
struct i2c_adapter *msm_hdmi_i2c_init(struct hdmi *hdmi);
242

243 244 245
/*
 * hdcp
 */
A
Arnd Bergmann 已提交
246 247 248 249 250
struct hdmi_hdcp_ctrl *msm_hdmi_hdcp_init(struct hdmi *hdmi);
void msm_hdmi_hdcp_destroy(struct hdmi *hdmi);
void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl *hdcp_ctrl);
void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl *hdcp_ctrl);
void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl *hdcp_ctrl);
251

252
#endif /* __HDMI_CONNECTOR_H__ */