blob: b1c4e0100c4e87dcd4d6105deeb4510667f86001 [file] [log] [blame]
Jan Samekd6244532022-12-02 12:44:24 +01001/* 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 Samekd6244532022-12-02 12:44:24 +010013enum cb_err mb_get_edid(uint8_t edid_data[0x80])
14{
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 */
Jan Samekd6244532022-12-02 12:44:24 +010034uint8_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 Samekd6244532022-12-02 12:44:24 +010042 * @return -1 on error; PTN_CFG_MODIFIED if data was modified and needs to be updated.
Jan Samek6ea58342023-01-18 11:59:14 +010043 */
Jan Samekd6244532022-12-02 12:44:24 +010044int mb_adjust_cfg(struct ptn_3460_config *cfg)
45{
46 const char *hwi_block = "hwinfo.hex";
47 uint8_t disp_con = 0, color_depth = 0;
48
49 /* Get display-specific configuration from hwinfo. */
50 if (hwilib_find_blocks(hwi_block) != CB_SUCCESS) {
51 printk(BIOS_ERR, "LCD: Info block \"%s\" not found!\n", hwi_block);
52 return -1;
53 }
54 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);
56 return -1;
57 }
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);
61 return -1;
62 }
63
Jan Samek6ea58342023-01-18 11:59:14 +010064 /* 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. */
Jan Samekd6244532022-12-02 12:44:24 +010066 cfg->dp_interface_ctrl = 0x00;
Jan Samek6ea58342023-01-18 11:59:14 +010067 /* Use odd bus for LVDS clock distribution only. */
Jan Samekd6244532022-12-02 12:44:24 +010068 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 LVDS clock spreading, 300 mV LVDS swing */
Jan Samekd6244532022-12-02 12:44:24 +010078 cfg->lvds_interface_ctrl2 = 0x03;
Jan Samek6ea58342023-01-18 11:59:14 +010079 /* No LVDS lane/channel swapping */
Jan Samekd6244532022-12-02 12:44:24 +010080 cfg->lvds_interface_ctrl3 = 0x00;
Jan Samek6ea58342023-01-18 11:59:14 +010081 /* Enable VDD to LVDS active delay. */
Jan Samekd6244532022-12-02 12:44:24 +010082 cfg->t2_delay = 0x01;
Jan Samek6ea58342023-01-18 11:59:14 +010083 /* LVDS to backlight active delay: 200 ms */
Jan Samekd6244532022-12-02 12:44:24 +010084 cfg->t3_timing = 0x04;
85 /* Minimum re-power delay: 500 ms */
86 cfg->t12_timing = 0x0a;
Jan Samek6ea58342023-01-18 11:59:14 +010087 /* Backlight off to LVDS inactive delay: 200 ms */
Jan Samekd6244532022-12-02 12:44:24 +010088 cfg->t4_timing = 0x04;
89 /* Enable LVDS to VDD inactive delay. */
90 cfg->t5_delay = 0x01;
91 /* Enable backlight control. */
92 cfg->backlight_ctrl = 0x00;
93
94 return PTN_CFG_MODIFIED;
95}