summaryrefslogtreecommitdiff
path: root/drivers/video/mcde/display-sony_acx424akp_dsi.c
blob: 3cad2b9718edc0dd6f01ffd621ed675821f20803 (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * ST-Ericsson MCDE Sony acx424akp 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-sony_acx424akp_dsi.h>

static int display_read_deviceid(struct mcde_display_device *dev, u16 *id)
{
	struct mcde_chnl_state *chnl;

	u8  id1, id2, id3;
	int len = 1;
	int ret = 0;
	int readret = 0;

	dev_dbg(&dev->dev, "%s: Read device id of the display\n", __func__);

	/* Acquire MCDE resources */
	chnl = mcde_chnl_get(dev->chnl_id, dev->fifo, dev->port);
	if (IS_ERR(chnl)) {
		ret = PTR_ERR(chnl);
		dev_warn(&dev->dev, "Failed to acquire MCDE channel\n");
		goto out;
	}

	/* plugnplay: use registers DA, DBh and DCh to detect display */
	readret = mcde_dsi_dcs_read(chnl, 0xDA, (u32 *)&id1, &len);
	if (!readret)
		readret = mcde_dsi_dcs_read(chnl, 0xDB, (u32 *)&id2, &len);
	if (!readret)
		readret = mcde_dsi_dcs_read(chnl, 0xDC, (u32 *)&id3, &len);

	if (readret) {
		dev_info(&dev->dev,
			"mcde_dsi_dcs_read failed to read display ID\n");
		goto read_fail;
	}

	*id = (id3 << 8) | id2;
read_fail:
	/* close  MCDE channel */
	mcde_chnl_put(chnl);
out:
	return 0;
}

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

	dev_dbg(&dev->dev, "%s: Reset & power on sony 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(pdata->reset_gpio, pdata->reset_high);
	msleep(pdata->reset_delay);	/* as per sony lcd spec */
	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, !pdata->reset_high);
	msleep(pdata->reset_low_delay);	/* as per sony lcd spec */
	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, pdata->reset_high);
	msleep(pdata->reset_delay);	/* as per sony lcd spec */

	return 0;
}

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

	dev_dbg(&dev->dev, "%s:Reset & power off sony 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 sony_acx424akp_set_scan_mode(struct mcde_display_device *ddev,
		enum mcde_display_power_mode power_mode)
{
	int ret = 0;
	u8 param[MCDE_MAX_DSI_DIRECT_CMD_WRITE];

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

	/* 180 rotation for SONY ACX424AKP display */
	if (ddev->power_mode == MCDE_DISPLAY_PM_STANDBY) {
		param[0] = 0xAA;
		ret = mcde_dsi_dcs_write(ddev->chnl_state, 0xf3, param, 1);
		if (ret)
			return ret;

		param[0] = 0x00;
		param[1] = 0x00;
		ret = mcde_dsi_generic_write(ddev->chnl_state, param, 3);
		if (ret)
			return ret;

		param[0] = 0xC9;
		param[1] = 0x01;
		ret = mcde_dsi_generic_write(ddev->chnl_state, param, 3);
		if (ret)
			return ret;

		param[0] = 0xA2;
		param[1] = 0x00;
		ret = mcde_dsi_generic_write(ddev->chnl_state, param, 3);
		if (ret)
			return ret;

		param[0] = 0xFF;
		param[1] = 0xAA;
		ret = mcde_dsi_generic_write(ddev->chnl_state, param, 3);
		if (ret)
			return ret;
	}
	return ret;
}

static int sony_acx424akp_set_power_mode(struct mcde_display_device *ddev,
	enum mcde_display_power_mode power_mode)
{
	int ret = 0;
	struct mcde_display_sony_acx424akp_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);
	ret = sony_acx424akp_set_scan_mode(ddev, power_mode);

	return ret;
}

static int __devinit sony_acx424akp_probe(struct mcde_display_device *dev)
{
	int ret = 0;
	u16 id;
	struct mcde_display_sony_acx424akp_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->sony_acx424akp_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(NULL,
				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;
			}
			regulator_set_voltage(pdata->regulator,
					pdata->min_supply_voltage,
					pdata->max_supply_voltage);
			/*
			* 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->platform_enable = sony_acx424akp_platform_enable,
	dev->platform_disable = sony_acx424akp_platform_disable,
	dev->set_power_mode = sony_acx424akp_set_power_mode;

	ret = display_read_deviceid(dev, &id);

	switch (id) {
	case DISPLAY_SONY_ACX424AKP:
		pdata->disp_panel = DISPLAY_SONY_ACX424AKP;
		dev_info(&dev->dev, "Sony ACX424AKP display (ID 0x%.4X) \
								probed\n", id);
		goto out;

	default:
		pdata->disp_panel = DISPLAY_NONE;
		dev_warn(&dev->dev, "Display not recognized\n");
		break;
	}

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

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

	dev->set_power_mode(dev, MCDE_DISPLAY_PM_OFF);

	if (!pdata->sony_acx424akp_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 sony_acx424akp_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 sony_acx424akp_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 sony_acx424akp_driver = {
	.probe	= sony_acx424akp_probe,
	.remove = sony_acx424akp_remove,
#if !defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_PM)
	.suspend = sony_acx424akp_suspend,
	.resume = sony_acx424akp_resume,
#else
	.suspend = NULL,
	.resume = NULL,
#endif
	.driver = {
		.name	= "mcde_disp_sony_acx424akp",
	},
};

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

	return mcde_display_driver_register(&sony_acx424akp_driver);
}
module_init(mcde_display_sony_acx424akp_init);

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

	mcde_display_driver_unregister(&sony_acx424akp_driver);
}
module_exit(mcde_display_sony_acx424akp_exit);

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