summaryrefslogtreecommitdiff
path: root/drivers/video/mcde/display-generic_dsi.c
blob: 5e3b38ccba1c2680f4818f692fcac3cd80853489 (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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * ST-Ericsson MCDE generic DCS display driver
 *
 * Author: Marcus Lorentzon <marcus.xm.lorentzon@stericsson.com>
 * for ST-Ericsson.
 *
 * License terms: GNU General Public License (GPL), version 2.
 */

#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/err.h>

#include <video/mcde_display.h>
#include <video/mcde_display-generic_dsi.h>

static int generic_platform_enable(struct mcde_display_device *dev)
{
	struct mcde_display_generic_platform_data *pdata =
		dev->dev.platform_data;

	dev_dbg(&dev->dev, "%s: Reset & power on generic display\n", __func__);

	if (pdata->regulator) {
		if (regulator_enable(pdata->regulator) < 0) {
			dev_err(&dev->dev, "%s:Failed to enable regulator\n"
				, __func__);
			return -EINVAL;
		}
	}
	if (pdata->reset_gpio)
		gpio_set_value_cansleep(pdata->reset_gpio, pdata->reset_high);
	mdelay(pdata->reset_delay);
	if (pdata->reset_gpio)
		gpio_set_value_cansleep(pdata->reset_gpio, !pdata->reset_high);

	return 0;
}

static int generic_platform_disable(struct mcde_display_device *dev)
{
	struct mcde_display_generic_platform_data *pdata =
		dev->dev.platform_data;

	dev_dbg(&dev->dev, "%s:Reset & power off generic display\n", __func__);

	if (pdata->regulator) {
		if (regulator_disable(pdata->regulator) < 0) {
			dev_err(&dev->dev, "%s:Failed to disable regulator\n"
				, __func__);
			return -EINVAL;
		}
	}
	return 0;
}

static int generic_set_power_mode(struct mcde_display_device *ddev,
	enum mcde_display_power_mode power_mode)
{
	int ret = 0;
	struct mcde_display_generic_platform_data *pdata =
		ddev->dev.platform_data;

	dev_dbg(&ddev->dev, "%s:Set Power mode\n", __func__);

	/* OFF -> STANDBY */
	if (ddev->power_mode == MCDE_DISPLAY_PM_OFF &&
		power_mode != MCDE_DISPLAY_PM_OFF) {

		if (ddev->platform_enable) {
			ret = ddev->platform_enable(ddev);
			if (ret)
				return ret;
		}

		ddev->power_mode = MCDE_DISPLAY_PM_STANDBY;
	}

	/* STANDBY -> ON */
	if (ddev->power_mode == MCDE_DISPLAY_PM_STANDBY &&
		power_mode == MCDE_DISPLAY_PM_ON) {

		ret = mcde_dsi_dcs_write(ddev->chnl_state,
		DCS_CMD_EXIT_SLEEP_MODE, NULL, 0);
		if (ret)
			return ret;

		msleep(pdata->sleep_out_delay);

		ret = mcde_dsi_dcs_write(ddev->chnl_state,
			DCS_CMD_SET_DISPLAY_ON, NULL, 0);
		if (ret)
			return ret;

		ddev->power_mode = MCDE_DISPLAY_PM_ON;
		goto set_power_and_exit;
	}
	/* ON -> STANDBY */
	else if (ddev->power_mode == MCDE_DISPLAY_PM_ON &&
		power_mode <= MCDE_DISPLAY_PM_STANDBY) {
		ret = mcde_dsi_dcs_write(ddev->chnl_state,
			DCS_CMD_SET_DISPLAY_OFF, NULL, 0);
		if (ret)
			return ret;

		ret = mcde_dsi_dcs_write(ddev->chnl_state,
			DCS_CMD_ENTER_SLEEP_MODE, NULL, 0);
		if (ret)
			return ret;

		ddev->power_mode = MCDE_DISPLAY_PM_STANDBY;
	}

	/* SLEEP -> OFF */
	if (ddev->power_mode == MCDE_DISPLAY_PM_STANDBY &&
		power_mode == MCDE_DISPLAY_PM_OFF) {
		if (ddev->platform_disable) {
			ret = ddev->platform_disable(ddev);
			if (ret)
				return ret;
		}
		ddev->power_mode = MCDE_DISPLAY_PM_OFF;
	}

set_power_and_exit:
	mcde_chnl_set_power_mode(ddev->chnl_state, ddev->power_mode);

	return ret;
}

static int __devinit generic_probe(struct mcde_display_device *dev)
{
	int ret = 0;
	struct mcde_display_generic_platform_data *pdata =
		dev->dev.platform_data;

	if (pdata == NULL) {
		dev_err(&dev->dev, "%s:Platform data missing\n", __func__);
		return -EINVAL;
	}

	if (dev->port->type != MCDE_PORTTYPE_DSI) {
		dev_err(&dev->dev,
			"%s:Invalid port type %d\n",
			__func__, dev->port->type);
		return -EINVAL;
	}

	if (!dev->platform_enable && !dev->platform_disable) {
		pdata->generic_platform_enable = true;
		if (pdata->reset_gpio) {
			ret = gpio_request(pdata->reset_gpio, NULL);
			if (ret) {
				dev_warn(&dev->dev,
					"%s:Failed to request gpio %d\n",
					__func__, pdata->reset_gpio);
				goto gpio_request_failed;
			}
			gpio_direction_output(pdata->reset_gpio,
				!pdata->reset_high);
		}
		if (pdata->regulator_id) {
			pdata->regulator = regulator_get(&dev->dev,
				pdata->regulator_id);
			if (IS_ERR(pdata->regulator)) {
				ret = PTR_ERR(pdata->regulator);
				dev_warn(&dev->dev,
					"%s:Failed to get regulator '%s'\n",
					__func__, pdata->regulator_id);
				pdata->regulator = NULL;
				goto regulator_get_failed;
			}

			if (regulator_set_voltage(pdata->regulator,
					pdata->min_supply_voltage,
					pdata->max_supply_voltage) < 0) {
				int volt;

				dev_warn(&dev->dev,
					"%s:Failed to set voltage '%s'\n",
					__func__, pdata->regulator_id);
				volt = regulator_get_voltage(pdata->regulator);
				dev_warn(&dev->dev,
					"Voltage:%d\n", volt);
			}

			/*
			* When u-boot has display a startup screen.
			* U-boot has turned on display power however the
			* regulator framework does not know about that
			* This is the case here, the display driver has to
			* enable the regulator for the display.
			*/
			if (dev->power_mode == MCDE_DISPLAY_PM_STANDBY) {
				ret = regulator_enable(pdata->regulator);
				if (ret < 0) {
					dev_err(&dev->dev,
					"%s:Failed to enable regulator\n"
					, __func__);
					goto regulator_enable_failed;
				}
			}
		}
	}

	/* TODO: Remove when DSI send command uses interrupts */
	dev->prepare_for_update = NULL;
	dev->platform_enable = generic_platform_enable,
	dev->platform_disable = generic_platform_disable,
	dev->set_power_mode = generic_set_power_mode;

	dev_info(&dev->dev, "Generic display probed\n");

	goto out;
regulator_enable_failed:
regulator_get_failed:
	if (pdata->generic_platform_enable && pdata->reset_gpio)
		gpio_free(pdata->reset_gpio);
gpio_request_failed:
out:
	return ret;
}

static int __devexit generic_remove(struct mcde_display_device *dev)
{
	struct mcde_display_generic_platform_data *pdata =
		dev->dev.platform_data;

	dev->set_power_mode(dev, MCDE_DISPLAY_PM_OFF);

	if (!pdata->generic_platform_enable)
		return 0;

	if (pdata->regulator)
		regulator_put(pdata->regulator);
	if (pdata->reset_gpio) {
		gpio_direction_input(pdata->reset_gpio);
		gpio_free(pdata->reset_gpio);
	}

	return 0;
}

#if !defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_PM)
static int generic_resume(struct mcde_display_device *ddev)
{
	int ret;

	/* set_power_mode will handle call platform_enable */
	ret = ddev->set_power_mode(ddev, MCDE_DISPLAY_PM_STANDBY);
	if (ret < 0)
		dev_warn(&ddev->dev, "%s:Failed to resume display\n"
			, __func__);
	ddev->set_synchronized_update(ddev,
					ddev->get_synchronized_update(ddev));
	return ret;
}

static int generic_suspend(struct mcde_display_device *ddev, pm_message_t state)
{
	int ret;

	/* set_power_mode will handle call platform_disable */
	ret = ddev->set_power_mode(ddev, MCDE_DISPLAY_PM_OFF);
	if (ret < 0)
		dev_warn(&ddev->dev, "%s:Failed to suspend display\n"
			, __func__);
	return ret;
}
#endif

static struct mcde_display_driver generic_driver = {
	.probe	= generic_probe,
	.remove = generic_remove,
#if !defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_PM)
	.suspend = generic_suspend,
	.resume = generic_resume,
#else
	.suspend = NULL,
	.resume = NULL,
#endif
	.driver = {
		.name	= "mcde_disp_generic",
	},
};

/* Module init */
static int __init mcde_display_generic_init(void)
{
	pr_info("%s\n", __func__);

	return mcde_display_driver_register(&generic_driver);
}
module_init(mcde_display_generic_init);

static void __exit mcde_display_generic_exit(void)
{
	pr_info("%s\n", __func__);

	mcde_display_driver_unregister(&generic_driver);
}
module_exit(mcde_display_generic_exit);

MODULE_AUTHOR("Marcus Lorentzon <marcus.xm.lorentzon@stericsson.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ST-Ericsson MCDE generic DCS display driver");