summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/msm/hdmi/hdmi.c
blob: 12ecfb928f753ffe50719a93615e7221f5a4546e (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 * 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/>.
 */

#include "hdmi.h"

static struct platform_device *hdmi_pdev;

void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
{
	uint32_t ctrl = 0;

	if (power_on) {
		ctrl |= HDMI_CTRL_ENABLE;
		if (!hdmi->hdmi_mode) {
			ctrl |= HDMI_CTRL_HDMI;
			hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
			ctrl &= ~HDMI_CTRL_HDMI;
		} else {
			ctrl |= HDMI_CTRL_HDMI;
		}
	} else {
		ctrl = HDMI_CTRL_HDMI;
	}

	hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
	DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
			power_on ? "Enable" : "Disable", ctrl);
}

static irqreturn_t hdmi_irq(int irq, void *dev_id)
{
	struct hdmi *hdmi = dev_id;

	/* Process HPD: */
	hdmi_connector_irq(hdmi->connector);

	/* Process DDC: */
	hdmi_i2c_irq(hdmi->i2c);

	/* TODO audio.. */

	return IRQ_HANDLED;
}

void hdmi_destroy(struct hdmi *hdmi)
{
	struct hdmi_phy *phy = hdmi->phy;

	if (phy)
		phy->funcs->destroy(phy);

	if (hdmi->i2c)
		hdmi_i2c_destroy(hdmi->i2c);

	put_device(&hdmi->pdev->dev);
}

/* initialize connector */
int hdmi_init(struct hdmi *hdmi, struct drm_device *dev,
		struct drm_connector *connector)
{
	struct platform_device *pdev = hdmi_pdev;
	struct hdmi_platform_config *config;
	int ret;

	if (!pdev) {
		dev_err(dev->dev, "no hdmi device\n");
		ret = -ENXIO;
		goto fail;
	}

	config = pdev->dev.platform_data;

	get_device(&pdev->dev);

	hdmi->dev = dev;
	hdmi->pdev = pdev;
	hdmi->connector = connector;

	/* not sure about which phy maps to which msm.. probably I miss some */
	if (config->phy_init)
		hdmi->phy = config->phy_init(hdmi);
	else
		hdmi->phy = ERR_PTR(-ENXIO);

	if (IS_ERR(hdmi->phy)) {
		ret = PTR_ERR(hdmi->phy);
		dev_err(dev->dev, "failed to load phy: %d\n", ret);
		hdmi->phy = NULL;
		goto fail;
	}

	hdmi->mmio = msm_ioremap(pdev, "hdmi_msm_hdmi_addr", "HDMI");
	if (IS_ERR(hdmi->mmio)) {
		ret = PTR_ERR(hdmi->mmio);
		goto fail;
	}

	hdmi->mvs = devm_regulator_get(&pdev->dev, "8901_hdmi_mvs");
	if (IS_ERR(hdmi->mvs))
		hdmi->mvs = devm_regulator_get(&pdev->dev, "hdmi_mvs");
	if (IS_ERR(hdmi->mvs)) {
		ret = PTR_ERR(hdmi->mvs);
		dev_err(dev->dev, "failed to get mvs regulator: %d\n", ret);
		goto fail;
	}

	hdmi->mpp0 = devm_regulator_get(&pdev->dev, "8901_mpp0");
	if (IS_ERR(hdmi->mpp0))
		hdmi->mpp0 = NULL;

	hdmi->clk = devm_clk_get(&pdev->dev, "core_clk");
	if (IS_ERR(hdmi->clk)) {
		ret = PTR_ERR(hdmi->clk);
		dev_err(dev->dev, "failed to get 'clk': %d\n", ret);
		goto fail;
	}

	hdmi->m_pclk = devm_clk_get(&pdev->dev, "master_iface_clk");
	if (IS_ERR(hdmi->m_pclk)) {
		ret = PTR_ERR(hdmi->m_pclk);
		dev_err(dev->dev, "failed to get 'm_pclk': %d\n", ret);
		goto fail;
	}

	hdmi->s_pclk = devm_clk_get(&pdev->dev, "slave_iface_clk");
	if (IS_ERR(hdmi->s_pclk)) {
		ret = PTR_ERR(hdmi->s_pclk);
		dev_err(dev->dev, "failed to get 's_pclk': %d\n", ret);
		goto fail;
	}

	hdmi->i2c = hdmi_i2c_init(hdmi);
	if (IS_ERR(hdmi->i2c)) {
		ret = PTR_ERR(hdmi->i2c);
		dev_err(dev->dev, "failed to get i2c: %d\n", ret);
		hdmi->i2c = NULL;
		goto fail;
	}

	hdmi->irq = platform_get_irq(pdev, 0);
	if (hdmi->irq < 0) {
		ret = hdmi->irq;
		dev_err(dev->dev, "failed to get irq: %d\n", ret);
		goto fail;
	}

	ret = devm_request_threaded_irq(&pdev->dev, hdmi->irq,
			NULL, hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
			"hdmi_isr", hdmi);
	if (ret < 0) {
		dev_err(dev->dev, "failed to request IRQ%u: %d\n",
				hdmi->irq, ret);
		goto fail;
	}

	return 0;

fail:
	if (hdmi)
		hdmi_destroy(hdmi);

	return ret;
}

/*
 * The hdmi device:
 */

static int hdmi_dev_probe(struct platform_device *pdev)
{
	static struct hdmi_platform_config config = {};
#ifdef CONFIG_OF
	/* TODO */
#else
	if (cpu_is_apq8064()) {
		config.phy_init      = hdmi_phy_8960_init;
		config.ddc_clk_gpio  = 70;
		config.ddc_data_gpio = 71;
		config.hpd_gpio      = 72;
		config.pmic_gpio     = 13 + NR_GPIO_IRQS;
	} else if (cpu_is_msm8960()) {
		config.phy_init      = hdmi_phy_8960_init;
		config.ddc_clk_gpio  = 100;
		config.ddc_data_gpio = 101;
		config.hpd_gpio      = 102;
		config.pmic_gpio     = -1;
	} else if (cpu_is_msm8x60()) {
		config.phy_init      = hdmi_phy_8x60_init;
		config.ddc_clk_gpio  = 170;
		config.ddc_data_gpio = 171;
		config.hpd_gpio      = 172;
		config.pmic_gpio     = -1;
	}
#endif
	pdev->dev.platform_data = &config;
	hdmi_pdev = pdev;
	return 0;
}

static int hdmi_dev_remove(struct platform_device *pdev)
{
	hdmi_pdev = NULL;
	return 0;
}

static struct platform_driver hdmi_driver = {
	.probe = hdmi_dev_probe,
	.remove = hdmi_dev_remove,
	.driver.name = "hdmi_msm",
};

void __init hdmi_register(void)
{
	platform_driver_register(&hdmi_driver);
}

void __exit hdmi_unregister(void)
{
	platform_driver_unregister(&hdmi_driver);
}
OpenPOWER on IntegriCloud