aboutsummaryrefslogtreecommitdiff
path: root/drivers/video/mcde/display-generic_dsi.c
blob: 15b8ccec59a61f4079ef0009f40f13375ad200bb (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
/*
 * 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 <video/mcde_display.h>
#include <video/mcde_display-generic_dsi.h>

static int generic_platform_enable(struct mcde_display_device *dev)
{
	int ret = 0;
	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) {
		ret = regulator_enable(pdata->regulator);
		if (ret < 0) {
			dev_err(&dev->dev, "%s:Failed to enable regulator\n"
				, __func__);
			goto out;
		}
	}
	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, pdata->reset_high);
	mdelay(pdata->reset_delay);
	if (pdata->reset_gpio)
		gpio_set_value(pdata->reset_gpio, !pdata->reset_high);
out:
	return ret;
}

static int generic_platform_disable(struct mcde_display_device *dev)
{
	int ret = 0;
	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) {
		ret = regulator_disable(pdata->regulator);
		if (ret < 0)
			dev_err(&dev->dev, "%s:Failed to disable regulator\n"
				, __func__);
	}
	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__);
		ret = -EINVAL;
		goto no_pdata;
	}

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

	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(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;
				}
			}
		}
		dev->platform_enable = generic_platform_enable;
		dev->platform_disable = generic_platform_disable;
	}

	/* 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_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:
invalid_port_type:
no_pdata:
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) {
		if (pdata->regulator)
			regulator_put(pdata->regulator);
		if (pdata->reset_gpio) {
			gpio_direction_input(pdata->reset_gpio);
			gpio_free(pdata->reset_gpio);
		}
	}

	return 0;
}

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__);
	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;
}

static struct mcde_display_driver generic_driver = {
	.probe	= generic_probe,
	.remove = generic_remove,
	.suspend = generic_suspend,
	.resume = generic_resume,
	.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");