summaryrefslogtreecommitdiffstats
path: root/src/soc/nvidia/tegra210/jdi_25x18_display/panel-jdi-lpm102a188a.c
blob: 931f472ac7452694532c2427e2f886d74beb7543 (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
/*
 * This file is part of the coreboot project.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * 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.
 */

#include <console/console.h>
#include <stdint.h>
#include <delay.h>
#include <soc/addressmap.h>
#include <soc/clock.h>
#include <device/device.h>
#include <soc/nvidia/tegra/types.h>
#include <soc/display.h>
#include <soc/mipi_dsi.h>
#include <soc/tegra_dsi.h>

#include "../chip.h"
#include "panel-jdi-lpm102a188a.h"

struct panel_jdi jdi_data[NUM_DSI];

int panel_jdi_prepare(struct panel_jdi *jdi)
{
	int ret;
	u8 data;

	if (jdi->enabled)
		return 0;

	ret = mipi_dsi_dcs_set_column_address(jdi->dsi, 0,
				jdi->mode->xres / 2 - 1); // 2560/2
	if (ret < 0)
		printk(BIOS_ERR, "failed to set column address: %d\n", ret);

	ret = mipi_dsi_dcs_set_column_address(jdi->dsi->slave, 0,
				jdi->mode->xres / 2 - 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set column address: %d\n", ret);

	ret = mipi_dsi_dcs_set_page_address(jdi->dsi, 0,
				jdi->mode->yres - 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set page address: %d\n", ret);

	ret = mipi_dsi_dcs_set_page_address(jdi->dsi->slave, 0,
				jdi->mode->yres - 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set page address: %d\n", ret);

	ret = mipi_dsi_dcs_set_tear_on(jdi->dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set tear on: %d\n", ret);

	ret = mipi_dsi_dcs_set_tear_on(jdi->dsi->slave,
			MIPI_DSI_DCS_TEAR_MODE_VBLANK);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set tear on: %d\n", ret);

	ret = mipi_dsi_dcs_set_address_mode(jdi->dsi, false, false, false,
			false, false, false, false, false);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set address mode: %d\n", ret);

	ret = mipi_dsi_dcs_set_address_mode(jdi->dsi->slave, false, false,
			false, false, false, false, false, false);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set address mode: %d\n", ret);

	ret = mipi_dsi_dcs_set_pixel_format(jdi->dsi, 0x77);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set pixel format: %d\n", ret);

	ret = mipi_dsi_dcs_set_pixel_format(jdi->dsi->slave, 0x77);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set pixel format: %d\n", ret);

	data = 0xFF;
	ret = mipi_dsi_dcs_write(jdi->dsi, 0x51, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x51: %d\n", ret);

	data = 0xFF;
	ret = mipi_dsi_dcs_write(jdi->dsi->slave, 0x51, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x51: %d\n", ret);

	data = 0x24;
	ret = mipi_dsi_dcs_write(jdi->dsi, 0x53, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x53: %d\n", ret);

	data = 0x24;
	ret = mipi_dsi_dcs_write(jdi->dsi->slave, 0x53, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x53: %d\n", ret);

	data = 0x00;
	ret = mipi_dsi_dcs_write(jdi->dsi, 0x55, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x55: %d\n", ret);

	data = 0x00;
	ret = mipi_dsi_dcs_write(jdi->dsi->slave, 0x55, &data, 1);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set 0x55: %d\n", ret);

	ret = mipi_dsi_dcs_exit_sleep_mode(jdi->dsi);
	if (ret < 0)
		printk(BIOS_ERR, "failed to exit sleep mode: %d\n", ret);

	ret = mipi_dsi_dcs_exit_sleep_mode(jdi->dsi->slave);
	if (ret < 0)
		printk(BIOS_ERR, "failed to exit sleep mode: %d\n", ret);
	mdelay(150);

	ret = mipi_dsi_dcs_set_display_on(jdi->dsi);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set display on: %d\n", ret);

	ret = mipi_dsi_dcs_set_display_on(jdi->dsi->slave);
	if (ret < 0)
		printk(BIOS_ERR, "failed to set display on: %d\n", ret);
	mdelay(50);

	jdi->enabled = true;

	return 0;
}

static int panel_jdi_enslave(struct mipi_dsi_device *master,
			struct mipi_dsi_device *slave)
{
	int ret;

	ret = mipi_dsi_attach(master);
	if (ret < 0)
		return ret;

	return ret;
}

static int panel_jdi_liberate(struct mipi_dsi_device *master,
			struct mipi_dsi_device *slave)
{
	int ret;

	ret = mipi_dsi_detach(master);
	if (ret < 0)
		return ret;

	return 0;
}

static const struct mipi_dsi_master_ops panel_jdi_master_ops = {
	.enslave = panel_jdi_enslave,
	.liberate = panel_jdi_liberate,
};

struct panel_jdi *panel_jdi_dsi_probe(struct mipi_dsi_device *dsi)
{
	static int index = 0;
	struct panel_jdi *jdi;
	int ret;

	if (index >= NUM_DSI)
		return (void *)-EPTR;

	jdi = &jdi_data[index++];

	jdi->dsi = dsi;

	dsi->lanes = 4;
	dsi->format = MIPI_DSI_FMT_RGB888;
	dsi->mode_flags = 0;

	if (dsi->master) {
		ret = mipi_dsi_attach(dsi);
		if (ret < 0) {
			printk(BIOS_ERR, "mipi_dsi_attach() failed: %d\n", ret);
			return (void *)-EPTR;
		}

		ret = mipi_dsi_enslave(dsi->master, dsi);
		if (ret < 0) {
			printk(BIOS_ERR, "mipi_dsi_enslave() failed: %d\n",
				ret);
			return (void *)-EPTR;
		}

		return jdi;
	}

	dsi->ops = &panel_jdi_master_ops;

	jdi->enabled = 0;
	jdi->width_mm = 211;
	jdi->height_mm = 148;

	return jdi;
}