blob: bcf8d2c7b832ad7bf61287ce512471ec36229732 [file] [log] [blame]
Werner Zehc42a6132015-02-12 12:40:15 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 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.
Werner Zehc42a6132015-02-12 12:40:15 +010014 */
15
16#include <console/console.h>
Werner Zehbf13d3f2016-04-25 12:24:17 +020017#include <hwilib.h>
Ben Gardnerfa6014a2015-12-08 21:20:25 -060018#include "soc/i2c.h"
Werner Zehc42a6132015-02-12 12:40:15 +010019#include "ptn3460.h"
20
21/** \brief This functions sets up the DP2LVDS-converter to be used with the
22 * appropriate lcd panel
Werner Zehbf13d3f2016-04-25 12:24:17 +020023 * @param *hwi_block Filename in CBFS of the block to use as HW-Info
24 * @return 0 on success or error code
Werner Zehc42a6132015-02-12 12:40:15 +010025 */
Werner Zehbf13d3f2016-04-25 12:24:17 +020026int ptn3460_init(char *hwi_block)
Werner Zehc42a6132015-02-12 12:40:15 +010027{
28 struct ptn_3460_config cfg;
29 int status;
Werner Zehbf13d3f2016-04-25 12:24:17 +020030 uint8_t disp_con = 0, color_depth = 0;
31 uint8_t edid_data[0x80];
Werner Zehc42a6132015-02-12 12:40:15 +010032
Werner Zehbf13d3f2016-04-25 12:24:17 +020033 if (!hwi_block || hwilib_find_blocks(hwi_block) != CB_SUCCESS) {
34 printk(BIOS_ERR, "LCD: Info block \"%s\" not found!\n",
35 hwi_block);
36 return 1;
37 }
Werner Zehc42a6132015-02-12 12:40:15 +010038
39 status = i2c_init(PTN_I2C_CONTROLER);
40 if (status)
41 return (PTN_BUS_ERROR | status);
42
Werner Zehbf13d3f2016-04-25 12:24:17 +020043 /* Get all needed information from hwinfo block */
44 if (hwilib_get_field(Edid, edid_data, 0x80) != 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, 1) != 1)) {
50 printk(BIOS_ERR, "LCD: Missing panel features from %s\n",
51 hwi_block);
52 return 1;
53 }
54 if (hwilib_get_field(PF_Color_Depth ,&color_depth, 1) != 1) {
55 printk(BIOS_ERR, "LCD: Missing panel features from %s\n",
56 hwi_block);
57 return 1;
58 }
59 /* Here, all the desired information for setting up DP2LVDS converter*/
60 /* are present. Inside the converter, table 6 will be used for */
61 /* the timings. */
62 if ((status = ptn3460_write_edid(6, edid_data)) != 0)
Werner Zehc42a6132015-02-12 12:40:15 +010063 return status;
64 /* Select this table to be emulated */
65 ptn_select_edid(6);
66 /* Read PTN configuration data */
67 status = i2c_read(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_CONFIG_OFF,
68 (u8*)&cfg, PTN_CONFIG_LEN);
69 if (status)
70 return (PTN_BUS_ERROR | status);
71
Werner Zehbf13d3f2016-04-25 12:24:17 +020072 /* Set up configuration data according to the hwinfo blocks we get */
Werner Zehc42a6132015-02-12 12:40:15 +010073 cfg.dp_interface_ctrl = 0;
74 cfg.lvds_interface_ctrl1 = 0x00;
Werner Zehbf13d3f2016-04-25 12:24:17 +020075 if (disp_con == PF_DISPLCON_LVDS_DUAL)
Werner Zehc42a6132015-02-12 12:40:15 +010076 cfg.lvds_interface_ctrl1 |= 0x0b; /* Turn on dual LVDS lane and clock */
Werner Zehbf13d3f2016-04-25 12:24:17 +020077 if (color_depth == PF_COLOR_DEPTH_6BIT)
Werner Zehc42a6132015-02-12 12:40:15 +010078 cfg.lvds_interface_ctrl1 |= 0x20; /* Use 18 bits per pixel */
79
80 cfg.lvds_interface_ctrl2 = 0x03; /* no clock spreading, 300 mV LVDS swing */
81 cfg.lvds_interface_ctrl3 = 0x00; /* no LVDS signal swap */
82 cfg.t2_delay = 1; /* Delay T2 (VDD to LVDS active) by 16 ms */
Werner Zeh77ba8822016-10-04 11:59:59 +020083 cfg.t3_timing = 10; /* 500 ms from LVDS to backlight active */
Werner Zehc42a6132015-02-12 12:40:15 +010084 cfg.t12_timing = 20; /* 1 second re-power delay */
85 cfg.t4_timing = 3; /* 150 ms backlight off to LVDS inactive */
86 cfg.t5_delay = 1; /* Delay T5 (LVDS to VDD inactive) by 16 ms */
87 cfg.backlight_ctrl = 0; /* Enable backlight control */
88
89 /* Write back configuration data to PTN3460 */
90 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_CONFIG_OFF,
91 (u8*)&cfg, PTN_CONFIG_LEN);
92 if (status)
93 return (PTN_BUS_ERROR | status);
94 else
95 return PTN_NO_ERROR;
96}
97
98/** \brief This functions reads one desired EDID data structure from PTN3460
99 * @param edid_num Number of EDID that must be read (0..6)
100 * @param *data Pointer to a buffer where to store read data
101 * @return 0 on success or error code
102 */
103int ptn3460_read_edid(u8 edid_num, u8 *data)
104{
105 int status;
106
107 if (edid_num > PTN_MAX_EDID_NUM)
108 return PTN_INVALID_EDID;
109 /* First enable access to the desired EDID table */
110 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_CONFIG_OFF + 5,
111 &edid_num, 1);
112 if (status)
113 return (PTN_BUS_ERROR | status);
114
115 /* Now we can simply read back EDID-data */
116 status = i2c_read(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_EDID_OFF,
117 data, PTN_EDID_LEN);
118 if (status)
119 return (PTN_BUS_ERROR | status);
120 else
121 return PTN_NO_ERROR;
122}
123
124/** \brief This functions writes one EDID data structure to PTN3460
125 * @param edid_num Number of EDID that must be written (0..6)
126 * @param *data Pointer to a buffer where data to write is stored in
127 * @return 0 on success or error code
128 */
129int ptn3460_write_edid(u8 edid_num, u8 *data)
130{
131 int status;
132
133 if (edid_num > PTN_MAX_EDID_NUM)
134 return PTN_INVALID_EDID;
135 /* First enable access to the desired EDID table */
136 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_CONFIG_OFF + 5,
137 &edid_num, 1);
138 if (status)
139 return (PTN_BUS_ERROR | status);
140
141 /* Now we can simply write EDID-data to ptn3460 */
142 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_EDID_OFF,
143 data, PTN_EDID_LEN);
144 if (status)
145 return (PTN_BUS_ERROR | status);
146 else
147 return PTN_NO_ERROR;
148}
149
150/** \brief This functions selects one of 7 EDID-tables inside PTN3460
151 * which should be emulated on display port and turn emulation ON
152 * @param edid_num Number of EDID to emulate (0..6)
153 * @return 0 on success or error code
154 */
155int ptn_select_edid (u8 edid_num)
156{
157 int status;
158 u8 val;
159
160 if (edid_num > PTN_MAX_EDID_NUM)
161 return PTN_INVALID_EDID;
162 /* Enable emulation of the desired EDID table */
163 val = (edid_num << 1) | 1;
164 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_CONFIG_OFF + 4,
165 &val, 1);
166 if (status)
167 return (PTN_BUS_ERROR | status);
168 else
169 return PTN_NO_ERROR;
170}
171
172/** \brief This functions performs a flash operation which will write
173 * current configuration table (all the EDID-tables and the
174 * configuration space with a total amount of 1 KByte)
175 * to the internal flash of PTN3460
176 * @param none
177 * @return 0 on success or error code
178 */
179int ptn3460_flash_config(void)
180{
181 int status;
182 struct ptn_3460_flash flash;
183
184 flash.cmd = 0x01; /* perform erase and flash cycle */
185 flash.magic = 0x7845; /* Magic number to protect flash operation */
186 flash.trigger = 0x56; /* This value starts flash operation */
187 status = i2c_write(PTN_I2C_CONTROLER, PTN_SLAVE_ADR, PTN_FLASH_CFG_OFF,
188 (u8*)&flash, PTN_FLASH_CFG_LEN);
189 if (status) {
190 return (PTN_BUS_ERROR | status);
191 } else {
192 /* To ensure the flash operation is finished, we have to wait 300 ms */
193 mdelay(300);
194 return PTN_NO_ERROR;
195 }
196}