blob: 39cc274e21299d943a74e91558e6927214b0b810 [file] [log] [blame]
Uwe Poechee7a68242022-06-20 14:45:22 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
4#include <device/device.h>
5#include <drivers/i2c/ptn3460/ptn3460.h>
6#include <hwilib.h>
7#include <types.h>
8
Jan Samek6ea58342023-01-18 11:59:14 +01009/** \brief This function provides EDID data to the driver for DP2LVDS Bridge (PTN3460).
10 * @param edid_data pointer to EDID data in driver
11 * @return CB_SUCCESS on successful EDID data retrieval, CB_ERR otherwise
12 */
Jan Samek671cd1d2023-01-27 11:02:20 +010013enum cb_err mb_get_edid(uint8_t edid_data[PTN_EDID_LEN])
Uwe Poechee7a68242022-06-20 14:45:22 +020014{
15 const char *hwi_block = "hwinfo.hex";
16
17 if (hwilib_find_blocks(hwi_block) != CB_SUCCESS) {
18 printk(BIOS_ERR, "LCD: Info block \"%s\" not found!\n", hwi_block);
19 return CB_ERR;
20 }
21
22 /* Get EDID data from hwinfo block */
23 if (hwilib_get_field(Edid, edid_data, PTN_EDID_LEN) != PTN_EDID_LEN) {
24 printk(BIOS_ERR, "LCD: No EDID data available in %s\n", hwi_block);
25 return CB_ERR;
26 }
27 return CB_SUCCESS;
28}
29
30/** \brief This function provides EDID block [0..6] to the driver for DP2LVDS Bridge (PTN3460)
31 * which has to be used.
Jan Samek6ea58342023-01-18 11:59:14 +010032 * @return Index of the EDID slot selected for EDID emulation
33 */
Uwe Poechee7a68242022-06-20 14:45:22 +020034uint8_t mb_select_edid_table(void)
35{
36 return 6; /* With this mainboard we use EDID block 6 for emulation in PTN3460. */
37}
38
Jan Samek6ea58342023-01-18 11:59:14 +010039/** \brief Function to enable mainboard to adjust the config data of PTN3460. For reference,
40 * see NXP document AN11128 - PTN3460 Programming guide.
41 * @param *cfg_ptr Pointer to the PTN config structure to modify
Jan Samek79312af2023-01-18 13:28:50 +010042 * @return CB_SUCCESS if data was modified and needs to be updated; CB_ERR on error
Jan Samek6ea58342023-01-18 11:59:14 +010043 */
Jan Samek79312af2023-01-18 13:28:50 +010044enum cb_err mb_adjust_cfg(struct ptn_3460_config *cfg)
Uwe Poechee7a68242022-06-20 14:45:22 +020045{
46 const char *hwi_block = "hwinfo.hex";
47 uint8_t disp_con = 0, color_depth = 0;
48
Jan Samek6ea58342023-01-18 11:59:14 +010049 /* Get display-specific configuration from hwinfo. */
Uwe Poechee7a68242022-06-20 14:45:22 +020050 if (hwilib_find_blocks(hwi_block) != CB_SUCCESS) {
51 printk(BIOS_ERR, "LCD: Info block \"%s\" not found!\n", hwi_block);
Jan Samek79312af2023-01-18 13:28:50 +010052 return CB_ERR;
Uwe Poechee7a68242022-06-20 14:45:22 +020053 }
Uwe Poechee7a68242022-06-20 14:45:22 +020054 if (hwilib_get_field(PF_DisplCon, &disp_con, sizeof(disp_con)) != sizeof(disp_con)) {
55 printk(BIOS_ERR, "LCD: Missing panel features from %s\n", hwi_block);
Jan Samek79312af2023-01-18 13:28:50 +010056 return CB_ERR;
Uwe Poechee7a68242022-06-20 14:45:22 +020057 }
58 if (hwilib_get_field(PF_Color_Depth, &color_depth,
59 sizeof(color_depth)) != sizeof(color_depth)) {
60 printk(BIOS_ERR, "LCD: Missing panel features from %s\n", hwi_block);
Jan Samek79312af2023-01-18 13:28:50 +010061 return CB_ERR;
Uwe Poechee7a68242022-06-20 14:45:22 +020062 }
Jan Samek6ea58342023-01-18 11:59:14 +010063
64 /* Set up PTN3460 registers based on hwinfo and fixed board-specific parameters: */
65 /* Use 2 lanes for eDP, no P/N swapping, no ASSR, allow both HBR and RBR modes. */
Uwe Poechee7a68242022-06-20 14:45:22 +020066 cfg->dp_interface_ctrl = 0x00;
Jan Samek6ea58342023-01-18 11:59:14 +010067 /* Use odd bus for LVDS clock distribution only. */
Uwe Poechee7a68242022-06-20 14:45:22 +020068 cfg->lvds_interface_ctrl1 = 0x01;
69 if (disp_con == PF_DISPLCON_LVDS_DUAL) {
70 /* Turn on dual LVDS lane and clock. */
71 cfg->lvds_interface_ctrl1 |= 0x0b;
72 }
73 if (color_depth == PF_COLOR_DEPTH_6BIT) {
74 /* Use 18 bits per pixel. */
75 cfg->lvds_interface_ctrl1 |= 0x20;
76 }
Jan Samek6ea58342023-01-18 11:59:14 +010077 /* No clock spreading, 300 mV LVDS swing */
Uwe Poechee7a68242022-06-20 14:45:22 +020078 cfg->lvds_interface_ctrl2 = 0x03;
79 /* Swap LVDS lanes (N vs. P). */
80 cfg->lvds_interface_ctrl3 = 0x04;
Jan Samek6ea58342023-01-18 11:59:14 +010081 /* Enable VDD to LVDS active delay. */
82 cfg->t2_delay = 0x01;
83 /* LVDS to backlight active delay: 500 ms */
84 cfg->t3_timing = 0x0a;
85 /* Minimum re-power delay: 1 s */
86 cfg->t12_timing = 0x14;
87 /* Backlight off to LVDS inactive delay: 150 ms */
88 cfg->t4_timing = 0x03;
89 /* Enable LVDS to VDD inactive delay. */
90 cfg->t5_delay = 0x01;
Uwe Poechee7a68242022-06-20 14:45:22 +020091 /* Enable backlight control. */
Jan Samek6ea58342023-01-18 11:59:14 +010092 cfg->backlight_ctrl = 0x00;
Uwe Poechee7a68242022-06-20 14:45:22 +020093
Jan Samek79312af2023-01-18 13:28:50 +010094 return CB_SUCCESS;
Uwe Poechee7a68242022-06-20 14:45:22 +020095}