blob: 01da624d29c0a8ff26b1bd289e9eefa41b6aef26 [file] [log] [blame]
Mario Scheithauer5716b4c2018-11-14 13:27:05 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014-2017 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <console/console.h>
17#include <lib.h>
18#include <hwilib.h>
19#include <device/i2c_simple.h>
20#include <variant/ptn3460.h>
21
22/**
23 * This function sets up the DP2LVDS-converter to be used with the appropriate
24 * lcd panel.
25 *
26 * @param *hwi_block Filename in CBFS of the block to use as HW-Info.
27 * @return 0 on success or HWI-Data/PTN error code.
28 */
29int ptn3460_init(const char *hwi_block)
30{
31 struct ptn_3460_config cfg;
32 int status;
33 uint8_t disp_con = 0, color_depth = 0;
34 uint8_t edid_data[PTN_EDID_LEN];
35 int i;
36
37 if (!hwi_block || hwilib_find_blocks(hwi_block) != CB_SUCCESS) {
38 printk(BIOS_ERR, "LCD: Info block \"%s\" not found!\n",
39 hwi_block);
40 return 1;
41 }
42 /* Get all needed information from hwinfo block. */
43 if (hwilib_get_field(Edid, edid_data, sizeof(edid_data)) !=
44 sizeof(edid_data)) {
45 printk(BIOS_ERR, "LCD: No EDID data available in %s\n",
46 hwi_block);
47 return 1;
48 }
49 if ((hwilib_get_field(PF_DisplCon, &disp_con, sizeof(disp_con)) !=
50 sizeof(disp_con))) {
51 printk(BIOS_ERR, "LCD: Missing panel features from %s\n",
52 hwi_block);
53 return 1;
54 }
55 if (hwilib_get_field(PF_Color_Depth, &color_depth, sizeof(color_depth))
56 != sizeof(color_depth)) {
57 printk(BIOS_ERR, "LCD: Missing panel features from %s\n",
58 hwi_block);
59 return 1;
60 }
61 /*
62 * Here, all the desired information for setting up DP2LVDS converter
63 * is present. Inside the converter, table 6 will be used for the
64 * timings.
65 */
66 status = ptn3460_write_edid(6, edid_data);
67 if (status)
68 return status;
69 /* Select this table to be emulated. */
70 ptn_select_edid(6);
71 /* Read PTN configuration data. */
72 status = i2c_read_bytes(PTN_I2C_CONTROLLER, PTN_SLAVE_ADR,
73 PTN_CONFIG_OFF, (uint8_t *)&cfg,
74 sizeof(cfg));
75 if (status)
76 return (PTN_BUS_ERROR | status);
77 /* Set up configuration data according to the hwinfo block we get. */
78 cfg.dp_interface_ctrl = 0;
79 cfg.lvds_interface_ctrl1 = 0x00;
80 if (disp_con == PF_DISPLCON_LVDS_DUAL)
81 /* Turn on dual LVDS lane and clock. */
82 cfg.lvds_interface_ctrl1 |= 0x0b;
83 if (color_depth == PF_COLOR_DEPTH_6BIT)
84 /* Use 18 bits per pixel. */
85 cfg.lvds_interface_ctrl1 |= 0x20;
86
87 /* 1 % clock spreading, 300 mV LVDS swing. */
88 cfg.lvds_interface_ctrl2 = 0x13;
89 /* No LVDS signal swap. */
90 cfg.lvds_interface_ctrl3 = 0x00;
91 /* Delay T2 (VDD to LVDS active) by 16 ms. */
92 cfg.t2_delay = 1;
93 /* 250 ms from LVDS to backlight active. */
94 cfg.t3_timing = 10;
95 /* 1 second re-power delay. */
96 cfg.t12_timing = 20;
97 /* 150 ms backlight off to LVDS inactive. */
98 cfg.t4_timing = 3;
99 /* Delay T5 (LVDS to VDD inactive) by 16 ms. */
100 cfg.t5_delay = 1;
101 /* Enable backlight control. */
102 cfg.backlight_ctrl = 0;
103
104 /* Write back configuration data to PTN3460. */
105 for (i = 0; i < sizeof(struct ptn_3460_config); i++) {
106 status = i2c_writeb(PTN_I2C_CONTROLLER, PTN_SLAVE_ADR,
107 PTN_CONFIG_OFF+i,
108 *(((uint8_t *)&cfg)+i));
109 if (status)
110 return (PTN_BUS_ERROR | status);
111 }
112
Mario Scheithauer5716b4c2018-11-14 13:27:05 +0100113 return PTN_NO_ERROR;
114}
115
116/**
117 * This function writes one Extended Display Identification Data (EDID)
118 * structure to PTN3460.
119 *
120 * @param edid_num Number of EDID that must be written (0..6).
121 * @param *data Pointer to a buffer where data to write is stored in.
122 * @return 0 on success or error code.
123 */
124int ptn3460_write_edid(uint8_t edid_num, const uint8_t data[PTN_EDID_LEN])
125{
126 int status;
127 int i;
128
129 if (edid_num > PTN_MAX_EDID_NUM)
130 return PTN_INVALID_EDID;
131
132 /* First enable access to the desired EDID table. */
133 status = i2c_writeb(PTN_I2C_CONTROLLER, PTN_SLAVE_ADR,
134 PTN_CONFIG_OFF + 5, edid_num);
135 if (status)
136 return (PTN_BUS_ERROR | status);
137
138 /* Now we can simply write EDID-data to ptn3460. */
139 for (i = 0; i < PTN_EDID_LEN; i++) {
140 status = i2c_writeb(PTN_I2C_CONTROLLER, PTN_SLAVE_ADR,
141 PTN_EDID_OFF + i, data[i]);
142 if (status)
143 return (PTN_BUS_ERROR | status);
144 }
145
146 return PTN_NO_ERROR;
147}
148
149/**
150 * This function selects one of 7 EDID-tables inside PTN3460 which should be
151 * emulated on DisplayPort and turn emulation ON.
152 *
153 * @param edid_num Number of EDID to emulate (0..6).
154 * @return 0 on success or error code.
155 */
156int ptn_select_edid(uint8_t edid_num)
157{
158 int status;
159 uint8_t val;
160
161 if (edid_num > PTN_MAX_EDID_NUM)
162 return PTN_INVALID_EDID;
163 /* Enable emulation of the desired EDID table. */
164 val = (edid_num << 1) | 1;
165 status = i2c_writeb(PTN_I2C_CONTROLLER, PTN_SLAVE_ADR,
166 PTN_CONFIG_OFF + 4, val);
167 if (status)
168 return (PTN_BUS_ERROR | status);
169 else
170 return PTN_NO_ERROR;
171}