| 1 |
|
| 2 |
|
| 3 |
#include <boardid.h> |
| 4 |
#include <bootmode.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <delay.h> |
| 7 |
#include <device/device.h> |
| 8 |
#include <drivers/parade/ps8640/ps8640.h> |
| 9 |
#include <edid.h> |
| 10 |
#include <gpio.h> |
| 11 |
#include <soc/da9212.h> |
| 12 |
#include <soc/ddp.h> |
| 13 |
#include <soc/dsi.h> |
| 14 |
#include <soc/i2c.h> |
| 15 |
#include <soc/mt6311.h> |
| 16 |
#include <soc/mt6391.h> |
| 17 |
#include <soc/mtcmos.h> |
| 18 |
#include <soc/pll.h> |
| 19 |
#include <soc/usb.h> |
| 20 |
#include <framebuffer_info.h> |
| 21 |
|
| 22 |
enum { |
| 23 |
CODEC_I2C_BUS = 0, |
| 24 |
EXT_BUCK_I2C_BUS = 1, |
| 25 |
}; |
| 26 |
|
| 27 |
static void configure_ext_buck(void) |
| 28 |
{ |
| 29 |
mtk_i2c_bus_init(EXT_BUCK_I2C_BUS, I2C_SPEED_FAST); |
| 30 |
|
| 31 |
switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) { |
| 32 |
case 3: |
| 33 |
case 4: |
| 34 |
|
| 35 |
gpio_output(GPIO(EINT15), 1); |
| 36 |
udelay(500); |
| 37 |
mt6311_probe(EXT_BUCK_I2C_BUS); |
| 38 |
break; |
| 39 |
case 2: |
| 40 |
default: |
| 41 |
|
| 42 |
mt6391_gpio_output(MT6391_KP_ROW3, 1); |
| 43 |
mt6391_gpio_output(MT6391_KP_ROW4, 1); |
| 44 |
udelay(500); |
| 45 |
da9212_probe(EXT_BUCK_I2C_BUS); |
| 46 |
break; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
static void configure_touchscreen(void) |
| 51 |
{ |
| 52 |
|
| 53 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT >= 7) { |
| 54 |
gpio_output(GPIO(PCM_SYNC), 0); |
| 55 |
udelay(500); |
| 56 |
gpio_output(GPIO(PCM_SYNC), 1); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
static void configure_audio(void) |
| 61 |
{ |
| 62 |
mtcmos_audio_power_on(); |
| 63 |
|
| 64 |
|
| 65 |
mt6391_configure_ldo(LDO_VCAMD, LDO_1P8); |
| 66 |
|
| 67 |
mdelay(1); |
| 68 |
|
| 69 |
mt6391_configure_ldo(LDO_VCAMA, LDO_1P8); |
| 70 |
|
| 71 |
|
| 72 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5) |
| 73 |
gpio_output(GPIO(LCM_RST), 1); |
| 74 |
|
| 75 |
|
| 76 |
gpio_set_mode(GPIO(I2S0_LRCK), PAD_I2S0_LRCK_FUNC_I2S1_WS); |
| 77 |
gpio_set_mode(GPIO(I2S0_BCK), PAD_I2S0_BCK_FUNC_I2S1_BCK); |
| 78 |
gpio_set_mode(GPIO(I2S0_MCK), PAD_I2S0_MCK_FUNC_I2S1_MCK); |
| 79 |
gpio_set_mode(GPIO(I2S0_DATA0), PAD_I2S0_DATA0_FUNC_I2S1_DO_1); |
| 80 |
gpio_set_mode(GPIO(I2S0_DATA1), PAD_I2S0_DATA1_FUNC_I2S2_DI_2); |
| 81 |
|
| 82 |
mt6391_gpio_output(MT6391_KP_COL4, 1); |
| 83 |
|
| 84 |
switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) { |
| 85 |
case 2: |
| 86 |
case 3: |
| 87 |
case 4: |
| 88 |
mt6391_gpio_output(MT6391_KP_COL5, 1); |
| 89 |
break; |
| 90 |
case 5: |
| 91 |
case 6: |
| 92 |
gpio_set_mode(GPIO(UCTS0), PAD_UCTS0_FUNC_I2S2_DI_1); |
| 93 |
mt6391_gpio_output(MT6391_KP_COL5, 1); |
| 94 |
break; |
| 95 |
default: |
| 96 |
break; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
mtk_i2c_bus_init(CODEC_I2C_BUS, I2C_SPEED_FAST); |
| 101 |
|
| 102 |
|
| 103 |
mt_pll_set_aud_div(48 * KHz); |
| 104 |
} |
| 105 |
|
| 106 |
static void configure_usb(void) |
| 107 |
{ |
| 108 |
setup_usb_host(); |
| 109 |
|
| 110 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 3) { |
| 111 |
|
| 112 |
gpio_input_pullup(GPIO(MSDC3_DSL)); |
| 113 |
|
| 114 |
gpio_output(GPIO(CM2MCLK), 1); |
| 115 |
|
| 116 |
gpio_input_pullup(GPIO(CMPCLK)); |
| 117 |
|
| 118 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 7) |
| 119 |
gpio_input_pullup(GPIO(PCM_SYNC)); |
| 120 |
} |
| 121 |
|
| 122 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4 && |
| 123 |
board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 7) |
| 124 |
{ |
| 125 |
|
| 126 |
gpio_input_pullup(GPIO(UCTS2)); |
| 127 |
|
| 128 |
gpio_input_pullup(GPIO(AUD_DAT_MISO)); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
static void configure_usb_hub(void) |
| 133 |
{ |
| 134 |
|
| 135 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4) |
| 136 |
gpio_output(GPIO(UTXD3), 1); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
static void configure_backlight(void) |
| 141 |
{ |
| 142 |
|
| 143 |
switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) { |
| 144 |
case 3: |
| 145 |
gpio_output(GPIO(UCTS2), 0); |
| 146 |
break; |
| 147 |
case 4: |
| 148 |
gpio_output(GPIO(SRCLKENAI), 0); |
| 149 |
break; |
| 150 |
default: |
| 151 |
gpio_output(GPIO(UTXD2), 0); |
| 152 |
break; |
| 153 |
} |
| 154 |
|
| 155 |
gpio_output(GPIO(DISP_PWM0), 0); |
| 156 |
gpio_output(GPIO(PCM_TX), 0); |
| 157 |
} |
| 158 |
|
| 159 |
static void configure_display(void) |
| 160 |
{ |
| 161 |
|
| 162 |
gpio_output(GPIO(CMMCLK), 1); |
| 163 |
|
| 164 |
mt6391_configure_ldo(LDO_VGP2, LDO_3P3); |
| 165 |
gpio_output(GPIO(URTS0), 0); |
| 166 |
|
| 167 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT == 4) |
| 168 |
gpio_output(GPIO(SRCLKENAI2), 1); |
| 169 |
else |
| 170 |
gpio_output(GPIO(URTS2), 1); |
| 171 |
|
| 172 |
mdelay(2); |
| 173 |
|
| 174 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4) |
| 175 |
gpio_output(GPIO(LCM_RST), 1); |
| 176 |
else |
| 177 |
gpio_output(GPIO(UCTS0), 1); |
| 178 |
gpio_output(GPIO(PCM_CLK), 1); |
| 179 |
gpio_output(GPIO(URTS0), 1); |
| 180 |
|
| 181 |
udelay(100); |
| 182 |
} |
| 183 |
|
| 184 |
static int read_edid_from_ps8640(struct edid *edid) |
| 185 |
{ |
| 186 |
u8 i2c_bus, i2c_addr; |
| 187 |
|
| 188 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 6) { |
| 189 |
i2c_bus = 0; |
| 190 |
i2c_addr = 0x8; |
| 191 |
} else { |
| 192 |
i2c_bus = 4; |
| 193 |
i2c_addr = 0x18; |
| 194 |
} |
| 195 |
|
| 196 |
mtk_i2c_bus_init(i2c_bus, I2C_SPEED_FAST); |
| 197 |
|
| 198 |
ps8640_init(i2c_bus, i2c_addr); |
| 199 |
if (ps8640_get_edid(i2c_bus, i2c_addr, edid)) { |
| 200 |
printk(BIOS_ERR, "Can't get panel's edid\n"); |
| 201 |
return -1; |
| 202 |
} |
| 203 |
|
| 204 |
return 0; |
| 205 |
} |
| 206 |
|
| 207 |
static void display_startup(void) |
| 208 |
{ |
| 209 |
struct edid edid; |
| 210 |
int ret; |
| 211 |
u32 mipi_dsi_flags; |
| 212 |
|
| 213 |
if (read_edid_from_ps8640(&edid) < 0) |
| 214 |
return; |
| 215 |
|
| 216 |
mipi_dsi_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE; |
| 217 |
edid_set_framebuffer_bits_per_pixel(&edid, 32, 0); |
| 218 |
|
| 219 |
mtk_ddp_init(); |
| 220 |
ret = mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid, NULL); |
| 221 |
if (ret < 0) { |
| 222 |
printk(BIOS_ERR, "dsi init fail\n"); |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
mtk_ddp_mode_set(&edid); |
| 227 |
fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0); |
| 228 |
} |
| 229 |
|
| 230 |
static void mainboard_init(struct device *dev) |
| 231 |
{ |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5) |
| 236 |
mt6391_gpio_output(MT6391_KP_ROW2, 1); |
| 237 |
|
| 238 |
|
| 239 |
gpio_input_pullup(GPIO(EINT1)); |
| 240 |
|
| 241 |
configure_audio(); |
| 242 |
|
| 243 |
|
| 244 |
mtk_dsi_pin_drv_ctrl(); |
| 245 |
|
| 246 |
if (display_init_required()) { |
| 247 |
mtcmos_display_power_on(); |
| 248 |
configure_backlight(); |
| 249 |
configure_display(); |
| 250 |
display_startup(); |
| 251 |
} else { |
| 252 |
printk(BIOS_INFO, "Skipping display init.\n"); |
| 253 |
} |
| 254 |
configure_usb(); |
| 255 |
configure_usb_hub(); |
| 256 |
configure_ext_buck(); |
| 257 |
configure_touchscreen(); |
| 258 |
} |
| 259 |
|
| 260 |
static void mainboard_enable(struct device *dev) |
| 261 |
{ |
| 262 |
dev->ops->init = &mainboard_init; |
| 263 |
} |
| 264 |
|
| 265 |
struct chip_operations mainboard_ops = { |
| 266 |
.enable_dev = mainboard_enable, |
| 267 |
}; |