| 1 |
|
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <boardid.h> |
| 5 |
#include <bootmode.h> |
| 6 |
#include <cbfs.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <delay.h> |
| 9 |
#include <device/device.h> |
| 10 |
#include <ec/google/chromeec/ec.h> |
| 11 |
#include <edid.h> |
| 12 |
#include <framebuffer_info.h> |
| 13 |
#include <gpio.h> |
| 14 |
#include <identity.h> |
| 15 |
#include <soc/bl31.h> |
| 16 |
#include <soc/ddp.h> |
| 17 |
#include <soc/dsi.h> |
| 18 |
#include <soc/mmu_operations.h> |
| 19 |
#include <soc/mtcmos.h> |
| 20 |
#include <soc/spm.h> |
| 21 |
#include <soc/usb.h> |
| 22 |
#include <stdio.h> |
| 23 |
|
| 24 |
#include "gpio.h" |
| 25 |
#include "panel.h" |
| 26 |
|
| 27 |
static void configure_emmc(void) |
| 28 |
{ |
| 29 |
const gpio_t emmc_pin[] = { |
| 30 |
GPIO(MSDC0_DAT0), GPIO(MSDC0_DAT1), |
| 31 |
GPIO(MSDC0_DAT2), GPIO(MSDC0_DAT3), |
| 32 |
GPIO(MSDC0_DAT4), GPIO(MSDC0_DAT5), |
| 33 |
GPIO(MSDC0_DAT6), GPIO(MSDC0_DAT7), |
| 34 |
GPIO(MSDC0_CMD), GPIO(MSDC0_RSTB), |
| 35 |
}; |
| 36 |
|
| 37 |
for (size_t i = 0; i < ARRAY_SIZE(emmc_pin); i++) |
| 38 |
gpio_set_pull(emmc_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 39 |
} |
| 40 |
|
| 41 |
static void configure_usb(void) |
| 42 |
{ |
| 43 |
setup_usb_host(); |
| 44 |
} |
| 45 |
|
| 46 |
static void configure_audio(void) |
| 47 |
{ |
| 48 |
|
| 49 |
mtcmos_audio_power_on(); |
| 50 |
|
| 51 |
|
| 52 |
gpio_set_mode(GPIO(CAM_RST0), PAD_CAM_RST0_FUNC_I2S2_LRCK); |
| 53 |
gpio_set_mode(GPIO(CAM_PDN1), PAD_CAM_PDN1_FUNC_I2S2_BCK); |
| 54 |
gpio_set_mode(GPIO(CAM_PDN0), PAD_CAM_PDN0_FUNC_I2S2_MCK); |
| 55 |
gpio_set_mode(GPIO(EINT3), PAD_EINT3_FUNC_I2S3_DO); |
| 56 |
} |
| 57 |
|
| 58 |
static void configure_ec(void) |
| 59 |
{ |
| 60 |
|
| 61 |
if (CONFIG(BOARD_GOOGLE_JACUZZI_COMMON)) |
| 62 |
google_chromeec_set_sku_id(sku_id()); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
struct panel_description __weak *get_panel_description(int panel_id) |
| 67 |
{ |
| 68 |
printk(BIOS_ERR, "%s: ERROR: No panels defined for board: %s.\n", |
| 69 |
__func__, mainboard_part_number); |
| 70 |
return NULL; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
static void configure_panel_backlight(void) |
| 75 |
{ |
| 76 |
gpio_output(GPIO(PERIPHERAL_EN13), 0); |
| 77 |
gpio_output(GPIO(DISP_PWM), 0); |
| 78 |
} |
| 79 |
|
| 80 |
static void power_on_panel(struct panel_description *panel) |
| 81 |
{ |
| 82 |
if (panel->power_on) { |
| 83 |
panel->power_on(); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
gpio_output(GPIO_LCM_RST_1V8, 0); |
| 89 |
gpio_output(GPIO_PPVARP_LCD_EN, 1); |
| 90 |
gpio_output(GPIO_PPVARN_LCD_EN, 1); |
| 91 |
gpio_output(GPIO_PP1800_LCM_EN, 1); |
| 92 |
gpio_output(GPIO_PP3300_LCM_EN, 1); |
| 93 |
mdelay(15); |
| 94 |
gpio_output(GPIO_LCM_RST_1V8, 1); |
| 95 |
mdelay(6); |
| 96 |
} |
| 97 |
|
| 98 |
struct panel_description *get_panel_from_cbfs(struct panel_description *desc) |
| 99 |
{ |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
char cbfs_name[64]; |
| 105 |
static union { |
| 106 |
u8 raw[4 * 1024]; |
| 107 |
struct panel_serializable_data s; |
| 108 |
} buffer; |
| 109 |
|
| 110 |
if (!desc->name) |
| 111 |
return NULL; |
| 112 |
|
| 113 |
snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name); |
| 114 |
if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer))) |
| 115 |
desc->s = &buffer.s; |
| 116 |
else |
| 117 |
printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name); |
| 118 |
|
| 119 |
return desc->s ? desc : NULL; |
| 120 |
} |
| 121 |
|
| 122 |
static struct panel_description *get_active_panel(void) |
| 123 |
{ |
| 124 |
|
| 125 |
int panel_id = sku_id() >> 4 & 0x0F; |
| 126 |
|
| 127 |
struct panel_description *panel = get_panel_description(panel_id); |
| 128 |
if (!panel) { |
| 129 |
printk(BIOS_ERR, "%s: Panel %d is not supported.\n", |
| 130 |
__func__, panel_id); |
| 131 |
return NULL; |
| 132 |
} |
| 133 |
assert(panel->s); |
| 134 |
|
| 135 |
const struct edid *edid = &panel->s->edid; |
| 136 |
const char *name = edid->ascii_string; |
| 137 |
if (name[0] == '\0') |
| 138 |
name = "unknown name"; |
| 139 |
printk(BIOS_INFO, "%s: Found ID %d: '%s %s' %dx%d@%dHz\n", __func__, |
| 140 |
panel_id, edid->manufacturer_name, name, edid->mode.ha, |
| 141 |
edid->mode.va, edid->mode.refresh); |
| 142 |
return panel; |
| 143 |
} |
| 144 |
|
| 145 |
static bool configure_display(void) |
| 146 |
{ |
| 147 |
struct panel_description *panel = get_active_panel(); |
| 148 |
if (!panel) |
| 149 |
return false; |
| 150 |
|
| 151 |
mtcmos_display_power_on(); |
| 152 |
mtcmos_protect_display_bus(); |
| 153 |
configure_panel_backlight(); |
| 154 |
power_on_panel(panel); |
| 155 |
|
| 156 |
struct edid *edid = &panel->s->edid; |
| 157 |
edid_set_framebuffer_bits_per_pixel(edid, 32, 0); |
| 158 |
mtk_ddp_init(); |
| 159 |
u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO | |
| 160 |
MIPI_DSI_MODE_VIDEO_SYNC_PULSE | |
| 161 |
MIPI_DSI_MODE_LPM); |
| 162 |
if (CONFIG(DRIVER_ANALOGIX_ANX7625)) |
| 163 |
mipi_dsi_flags |= MIPI_DSI_MODE_EOT_PACKET | |
| 164 |
MIPI_DSI_MODE_LINE_END; |
| 165 |
if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, edid, |
| 166 |
panel->s->init) < 0) { |
| 167 |
printk(BIOS_ERR, "%s: Failed in DSI init.\n", __func__); |
| 168 |
return false; |
| 169 |
} |
| 170 |
|
| 171 |
if (panel->post_power_on) |
| 172 |
panel->post_power_on(); |
| 173 |
|
| 174 |
mtk_ddp_mode_set(edid); |
| 175 |
struct fb_info *info = fb_new_framebuffer_info_from_edid(edid, 0); |
| 176 |
if (info) |
| 177 |
fb_set_orientation(info, panel->orientation); |
| 178 |
|
| 179 |
return true; |
| 180 |
} |
| 181 |
|
| 182 |
static void mainboard_init(struct device *dev) |
| 183 |
{ |
| 184 |
if (display_init_required()) { |
| 185 |
printk(BIOS_INFO, "%s: Starting display init.\n", __func__); |
| 186 |
if (!configure_display()) |
| 187 |
printk(BIOS_ERR, "%s: Failed to init display.\n", |
| 188 |
__func__); |
| 189 |
} else { |
| 190 |
printk(BIOS_INFO, "%s: Skipped display init.\n", __func__); |
| 191 |
} |
| 192 |
|
| 193 |
configure_emmc(); |
| 194 |
configure_usb(); |
| 195 |
configure_audio(); |
| 196 |
configure_ec(); |
| 197 |
if (spm_init()) |
| 198 |
printk(BIOS_ERR, |
| 199 |
"SPM initialization failed, suspend/resume may fail.\n"); |
| 200 |
|
| 201 |
if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 202 |
register_reset_to_bl31(GPIO_RESET.id, true); |
| 203 |
} |
| 204 |
|
| 205 |
static void mainboard_enable(struct device *dev) |
| 206 |
{ |
| 207 |
dev->ops->init = &mainboard_init; |
| 208 |
} |
| 209 |
|
| 210 |
struct chip_operations mainboard_ops = { |
| 211 |
.enable_dev = mainboard_enable, |
| 212 |
}; |