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
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <assert.h>
#include <boardid.h>
#include <bootmode.h>
#include <cbfs.h>
#include <console/console.h>
#include <delay.h>
#include <device/device.h>
#include <ec/google/chromeec/ec.h>
#include <edid.h>
#include <framebuffer_info.h>
#include <gpio.h>
#include <identity.h>
#include <soc/bl31.h>
#include <soc/ddp.h>
#include <soc/dsi.h>
#include <soc/mmu_operations.h>
#include <soc/mtcmos.h>
#include <soc/spm.h>
#include <soc/usb.h>
#include <stdio.h>
#include "gpio.h"
#include "panel.h"
static void configure_emmc(void)
{
const gpio_t emmc_pin[] = {
GPIO(MSDC0_DAT0), GPIO(MSDC0_DAT1),
GPIO(MSDC0_DAT2), GPIO(MSDC0_DAT3),
GPIO(MSDC0_DAT4), GPIO(MSDC0_DAT5),
GPIO(MSDC0_DAT6), GPIO(MSDC0_DAT7),
GPIO(MSDC0_CMD), GPIO(MSDC0_RSTB),
};
for (size_t i = 0; i < ARRAY_SIZE(emmc_pin); i++)
gpio_set_pull(emmc_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP);
}
static void configure_usb(void)
{
setup_usb_host();
}
static void configure_audio(void)
{
/* Audio PWR*/
mtcmos_audio_power_on();
/* SoC I2S */
gpio_set_mode(GPIO(CAM_RST0), PAD_CAM_RST0_FUNC_I2S2_LRCK);
gpio_set_mode(GPIO(CAM_PDN1), PAD_CAM_PDN1_FUNC_I2S2_BCK);
gpio_set_mode(GPIO(CAM_PDN0), PAD_CAM_PDN0_FUNC_I2S2_MCK);
gpio_set_mode(GPIO(EINT3), PAD_EINT3_FUNC_I2S3_DO);
}
static void configure_ec(void)
{
/* EC may need SKU ID to identify if it is clamshell or convertible. */
if (CONFIG(BOARD_GOOGLE_JACUZZI_COMMON))
google_chromeec_set_sku_id(sku_id());
}
/* Default implementation for boards without panels defined yet. */
struct panel_description __weak *get_panel_description(int panel_id)
{
printk(BIOS_ERR, "%s: ERROR: No panels defined for board: %s.\n",
__func__, mainboard_part_number);
return NULL;
}
/* Set up backlight control pins as output pin and power-off by default */
static void configure_panel_backlight(void)
{
gpio_output(GPIO(PERIPHERAL_EN13), 0);
gpio_output(GPIO(DISP_PWM), 0);
}
static void power_on_panel(struct panel_description *panel)
{
if (panel->power_on) {
panel->power_on();
return;
}
/* Default power sequence for most panels. */
gpio_output(GPIO_LCM_RST_1V8, 0);
gpio_output(GPIO_PPVARP_LCD_EN, 1);
gpio_output(GPIO_PPVARN_LCD_EN, 1);
gpio_output(GPIO_PP1800_LCM_EN, 1);
gpio_output(GPIO_PP3300_LCM_EN, 1);
mdelay(15);
gpio_output(GPIO_LCM_RST_1V8, 1);
mdelay(6);
}
struct panel_description *get_panel_from_cbfs(struct panel_description *desc)
{
/* The CBFS name will be panel-{MANUFACTURER}-${PANEL_NAME},
* where MANUFACTURER is 3 characters and PANEL_NAME is usually
* 13 characters.
*/
char cbfs_name[64];
static union {
u8 raw[4 * 1024]; /* Most panels only need < 2K. */
struct panel_serializable_data s;
} buffer;
if (!desc->name)
return NULL;
snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name);
if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer)))
desc->s = &buffer.s;
else
printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name);
return desc->s ? desc : NULL;
}
static struct panel_description *get_active_panel(void)
{
/* TODO(hungte) Create a dedicated panel_id() in board_id.c */
int panel_id = sku_id() >> 4 & 0x0F;
struct panel_description *panel = get_panel_description(panel_id);
if (!panel) {
printk(BIOS_ERR, "%s: Panel %d is not supported.\n",
__func__, panel_id);
return NULL;
}
assert(panel->s);
const struct edid *edid = &panel->s->edid;
const char *name = edid->ascii_string;
if (name[0] == '\0')
name = "unknown name";
printk(BIOS_INFO, "%s: Found ID %d: '%s %s' %dx%d@%dHz\n", __func__,
panel_id, edid->manufacturer_name, name, edid->mode.ha,
edid->mode.va, edid->mode.refresh);
return panel;
}
static bool configure_display(void)
{
struct panel_description *panel = get_active_panel();
if (!panel)
return false;
mtcmos_display_power_on();
mtcmos_protect_display_bus();
configure_panel_backlight();
power_on_panel(panel);
struct edid *edid = &panel->s->edid;
edid_set_framebuffer_bits_per_pixel(edid, 32, 0);
mtk_ddp_init();
u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO |
MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
MIPI_DSI_MODE_LPM);
if (CONFIG(DRIVER_ANALOGIX_ANX7625))
mipi_dsi_flags |= MIPI_DSI_MODE_EOT_PACKET |
MIPI_DSI_MODE_LINE_END;
if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, edid,
panel->s->init) < 0) {
printk(BIOS_ERR, "%s: Failed in DSI init.\n", __func__);
return false;
}
if (panel->post_power_on)
panel->post_power_on();
mtk_ddp_mode_set(edid);
struct fb_info *info = fb_new_framebuffer_info_from_edid(edid, 0);
if (info)
fb_set_orientation(info, panel->orientation);
return true;
}
static void mainboard_init(struct device *dev)
{
if (display_init_required()) {
printk(BIOS_INFO, "%s: Starting display init.\n", __func__);
if (!configure_display())
printk(BIOS_ERR, "%s: Failed to init display.\n",
__func__);
} else {
printk(BIOS_INFO, "%s: Skipped display init.\n", __func__);
}
configure_emmc();
configure_usb();
configure_audio();
configure_ec();
if (spm_init())
printk(BIOS_ERR,
"SPM initialization failed, suspend/resume may fail.\n");
if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
register_reset_to_bl31(GPIO_RESET.id, true);
}
static void mainboard_enable(struct device *dev)
{
dev->ops->init = &mainboard_init;
}
struct chip_operations mainboard_ops = {
.enable_dev = mainboard_enable,
};
|