| 1 |
|
| 2 |
|
| 3 |
#include <bootmode.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <delay.h> |
| 6 |
#include <device/device.h> |
| 7 |
#include <device/mmio.h> |
| 8 |
#include <drivers/analogix/anx7625/anx7625.h> |
| 9 |
#include <edid.h> |
| 10 |
#include <framebuffer_info.h> |
| 11 |
#include <gpio.h> |
| 12 |
#include <soc/bl31.h> |
| 13 |
#include <soc/ddp.h> |
| 14 |
#include <soc/dpm_v1.h> |
| 15 |
#include <soc/dsi.h> |
| 16 |
#include <soc/gpio_common.h> |
| 17 |
#include <soc/i2c.h> |
| 18 |
#include <soc/msdc.h> |
| 19 |
#include <soc/mtcmos.h> |
| 20 |
#include <soc/regulator.h> |
| 21 |
#include <soc/spm.h> |
| 22 |
#include <soc/usb.h> |
| 23 |
|
| 24 |
#include "gpio.h" |
| 25 |
|
| 26 |
#define MSDC0_BASE 0x11f60000 |
| 27 |
#define MSDC0_TOP_BASE 0x11f50000 |
| 28 |
|
| 29 |
#define MSDC0_DRV_MASK 0x3fffffff |
| 30 |
#define MSDC1_DRV_MASK 0x3ffff000 |
| 31 |
#define MSDC0_DRV_VALUE 0x24924924 |
| 32 |
#define MSDC1_DRV_VALUE 0x1b6db000 |
| 33 |
|
| 34 |
#define MSDC1_GPIO_MODE0_BASE 0x10005360 |
| 35 |
#define MSDC1_GPIO_MODE0_MASK 0x77777000 |
| 36 |
#define MSDC1_GPIO_MODE0_VALUE 0x11111000 |
| 37 |
|
| 38 |
#define MSDC1_GPIO_MODE1_BASE 0x10005370 |
| 39 |
#define MSDC1_GPIO_MODE1_MASK 0x7 |
| 40 |
#define MSDC1_GPIO_MODE1_VALUE 0x1 |
| 41 |
|
| 42 |
|
| 43 |
#define GPIO_EDPBRDG_INT_ODL GPIO(EINT6) |
| 44 |
#define GPIO_EDPBRDG_PWREN GPIO(DSI_TE) |
| 45 |
#define GPIO_EDPBRDG_RST_ODL GPIO(LCM_RST) |
| 46 |
#define GPIO_EN_PP3300_EDP_DX GPIO(PERIPHERAL_EN1) |
| 47 |
#define GPIO_EN_PP1800_EDPBRDG_DX GPIO(PERIPHERAL_EN2) |
| 48 |
#define GPIO_EN_PP1000_EDPBRDG GPIO(PERIPHERAL_EN3) |
| 49 |
#define GPIO_EN_PP3300_DISPLAY_DX GPIO(CAM_CLK3) |
| 50 |
#define GPIO_AP_EDP_BKLTEN GPIO(KPROW1) |
| 51 |
#define GPIO_BL_PWM_1V8 GPIO(DISP_PWM) |
| 52 |
|
| 53 |
|
| 54 |
void mtk_dsi_override_phy_timing(struct mtk_phy_timing *timing) |
| 55 |
{ |
| 56 |
timing->da_hs_trail += 9; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
static void configure_backlight_and_bridge(void) |
| 61 |
{ |
| 62 |
|
| 63 |
gpio_output(GPIO_AP_EDP_BKLTEN, 0); |
| 64 |
gpio_output(GPIO_BL_PWM_1V8, 0); |
| 65 |
gpio_output(GPIO_EN_PP3300_DISPLAY_DX, 1); |
| 66 |
|
| 67 |
|
| 68 |
gpio_output(GPIO_EDPBRDG_RST_ODL, 0); |
| 69 |
gpio_output(GPIO_EN_PP1000_EDPBRDG, 1); |
| 70 |
gpio_output(GPIO_EN_PP1800_EDPBRDG_DX, 1); |
| 71 |
gpio_output(GPIO_EN_PP3300_EDP_DX, 1); |
| 72 |
mdelay(14); |
| 73 |
gpio_output(GPIO_EDPBRDG_PWREN, 1); |
| 74 |
mdelay(10); |
| 75 |
gpio_output(GPIO_EDPBRDG_RST_ODL, 1); |
| 76 |
} |
| 77 |
|
| 78 |
static bool configure_display(void) |
| 79 |
{ |
| 80 |
struct edid edid; |
| 81 |
const u8 i2c_bus = 3; |
| 82 |
|
| 83 |
printk(BIOS_INFO, "%s: Starting display init\n", __func__); |
| 84 |
|
| 85 |
configure_backlight_and_bridge(); |
| 86 |
mtk_i2c_bus_init(i2c_bus, I2C_SPEED_FAST); |
| 87 |
|
| 88 |
if (anx7625_init(i2c_bus)) { |
| 89 |
printk(BIOS_ERR, "%s: Can't init ANX7625 bridge\n", __func__); |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
if (anx7625_dp_get_edid(i2c_bus, &edid)) { |
| 94 |
printk(BIOS_ERR, "%s: Can't get panel's edid\n", __func__); |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
const char *name = edid.ascii_string; |
| 99 |
if (name[0] == '\0') |
| 100 |
name = "unknown name"; |
| 101 |
printk(BIOS_INFO, "%s: '%s %s' %dx%d@%dHz\n", __func__, |
| 102 |
edid.manufacturer_name, name, edid.mode.ha, edid.mode.va, |
| 103 |
edid.mode.refresh); |
| 104 |
|
| 105 |
mtcmos_display_power_on(); |
| 106 |
mtcmos_protect_display_bus(); |
| 107 |
|
| 108 |
edid_set_framebuffer_bits_per_pixel(&edid, 32, 0); |
| 109 |
mtk_ddp_init(); |
| 110 |
u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO | |
| 111 |
MIPI_DSI_MODE_VIDEO_SYNC_PULSE | |
| 112 |
MIPI_DSI_MODE_LPM | |
| 113 |
MIPI_DSI_MODE_LINE_END | |
| 114 |
MIPI_DSI_MODE_EOT_PACKET); |
| 115 |
|
| 116 |
if (mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid, NULL) < 0) { |
| 117 |
printk(BIOS_ERR, "%s: Failed in DSI init\n", __func__); |
| 118 |
return false; |
| 119 |
} |
| 120 |
|
| 121 |
if (anx7625_dp_start(i2c_bus, &edid) < 0) { |
| 122 |
printk(BIOS_ERR, "%s: Can't start display via ANX7625\n", __func__); |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
mtk_ddp_mode_set(&edid); |
| 127 |
fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0); |
| 128 |
return true; |
| 129 |
} |
| 130 |
|
| 131 |
static void configure_audio(void) |
| 132 |
{ |
| 133 |
|
| 134 |
mtcmos_audio_power_on(); |
| 135 |
|
| 136 |
|
| 137 |
gpio_set_mode(GPIO(I2S3_MCK), PAD_I2S3_MCK_FUNC_I2S3_MCK); |
| 138 |
gpio_set_mode(GPIO(I2S3_BCK), PAD_I2S3_BCK_FUNC_I2S3_BCK); |
| 139 |
gpio_set_mode(GPIO(I2S3_LRCK), PAD_I2S3_LRCK_FUNC_I2S3_LRCK); |
| 140 |
gpio_set_mode(GPIO(I2S3_DO), PAD_I2S3_DO_FUNC_I2S3_DO); |
| 141 |
} |
| 142 |
|
| 143 |
static void mainboard_init(struct device *dev) |
| 144 |
{ |
| 145 |
mtk_msdc_configure_emmc(true); |
| 146 |
mtk_msdc_configure_sdcard(); |
| 147 |
configure_audio(); |
| 148 |
setup_usb_host(); |
| 149 |
|
| 150 |
if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 151 |
register_reset_to_bl31(GPIO_RESET.id, true); |
| 152 |
|
| 153 |
if (dpm_init()) |
| 154 |
printk(BIOS_ERR, "dpm init fail, system can't do DVFS switch\n"); |
| 155 |
|
| 156 |
if (spm_init()) |
| 157 |
printk(BIOS_ERR, "spm init fail, system suspend may stuck\n"); |
| 158 |
|
| 159 |
if (display_init_required()) |
| 160 |
configure_display(); |
| 161 |
else |
| 162 |
printk(BIOS_INFO, "%s: Skipped display init\n", __func__); |
| 163 |
} |
| 164 |
|
| 165 |
static void mainboard_enable(struct device *dev) |
| 166 |
{ |
| 167 |
dev->ops->init = &mainboard_init; |
| 168 |
} |
| 169 |
|
| 170 |
struct chip_operations mainboard_ops = { |
| 171 |
.enable_dev = mainboard_enable, |
| 172 |
}; |