2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-08-08 14:03:29 +00:00
|
|
|
/*
|
|
|
|
* (C) 2015 Hans de Goede <hdegoede@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for the ANX9804 bridge chip, which can take pixel data coming
|
|
|
|
* from a parallel LCD interface and translate it on the flight into a DP
|
|
|
|
* interface for driving eDP TFT displays.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <i2c.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2017-09-21 06:29:08 +00:00
|
|
|
#include "anx98xx-edp.h"
|
2015-08-08 14:03:29 +00:00
|
|
|
#include "anx9804.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* anx9804_init() - Init anx9804 parallel lcd to edp bridge chip
|
|
|
|
*
|
|
|
|
* This function will init an anx9804 parallel lcd to dp bridge chip
|
|
|
|
* using the passed in parameters.
|
|
|
|
*
|
2021-10-08 05:17:24 +00:00
|
|
|
* @i2c_bus: Device of the i2c bus to which the anx9804 is connected.
|
2015-08-08 14:03:29 +00:00
|
|
|
* @lanes: Number of displayport lanes to use
|
|
|
|
* @data_rate: Register value for the bandwidth reg 0x06: 1.62G, 0x0a: 2.7G
|
|
|
|
* @bpp: Bits per pixel, must be 18 or 24
|
|
|
|
*/
|
2021-10-08 05:17:24 +00:00
|
|
|
void anx9804_init(struct udevice *i2c_bus, u8 lanes, u8 data_rate, int bpp)
|
2015-08-08 14:03:29 +00:00
|
|
|
{
|
2021-10-08 05:17:24 +00:00
|
|
|
struct udevice *chip0, *chip1;
|
|
|
|
int c, colordepth, i, ret;
|
2015-08-08 14:03:29 +00:00
|
|
|
|
2021-10-08 05:17:24 +00:00
|
|
|
ret = i2c_get_chip(i2c_bus, 0x38, 1, &chip0);
|
|
|
|
if (ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = i2c_get_chip(i2c_bus, 0x39, 1, &chip1);
|
|
|
|
if (ret)
|
|
|
|
return;
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
if (bpp == 18)
|
|
|
|
colordepth = 0x00; /* 6 bit */
|
|
|
|
else
|
|
|
|
colordepth = 0x10; /* 8 bit */
|
|
|
|
|
|
|
|
/* Reset */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_RST_CTRL_REG, 1);
|
2015-08-08 14:03:29 +00:00
|
|
|
mdelay(100);
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_RST_CTRL_REG, 0);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Write 0 to the powerdown reg (powerup everything) */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_POWERD_CTRL_REG, 0);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
2021-10-08 05:17:24 +00:00
|
|
|
c = dm_i2c_reg_read(chip1, ANX9804_DEV_IDH_REG);
|
2015-08-08 14:03:29 +00:00
|
|
|
if (c != 0x98) {
|
|
|
|
printf("Error anx9804 chipid mismatch\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++) {
|
2021-10-08 05:17:24 +00:00
|
|
|
c = dm_i2c_reg_read(chip0, ANX9804_SYS_CTRL2_REG);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL2_REG, c);
|
|
|
|
c = dm_i2c_reg_read(chip0, ANX9804_SYS_CTRL2_REG);
|
2015-08-08 14:03:29 +00:00
|
|
|
if ((c & ANX9804_SYS_CTRL2_CHA_STA) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
mdelay(5);
|
|
|
|
}
|
|
|
|
if (i == 100)
|
|
|
|
printf("Error anx9804 clock is not stable\n");
|
|
|
|
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_VID_CTRL2_REG, colordepth);
|
2021-09-27 15:42:38 +00:00
|
|
|
|
2015-08-08 14:03:29 +00:00
|
|
|
/* Set a bunch of analog related register values */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_PLL_CTRL_REG, 0x07);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL3, 0x19);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_PLL_CTRL3, 0xd9);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG, ANX9804_RST_CTRL2_AC_MODE);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_ANALOG_DEBUG_REG1, 0xf0);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_ANALOG_DEBUG_REG3, 0x99);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL1, 0x7b);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_LINK_DEBUG_REG, 0x30);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL, 0x06);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Force HPD */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL3_REG,
|
|
|
|
ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Power up and configure lanes */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_ANALOG_POWER_DOWN_REG, 0x00);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE0_SET_REG, 0x00);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE1_SET_REG, 0x00);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE2_SET_REG, 0x00);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE3_SET_REG, 0x00);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Reset AUX CH */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG,
|
|
|
|
ANX9804_RST_CTRL2_AC_MODE | ANX9804_RST_CTRL2_AUX);
|
|
|
|
dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG,
|
|
|
|
ANX9804_RST_CTRL2_AC_MODE);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Powerdown audio and some other unused bits */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_POWERD_CTRL_REG, ANX9804_POWERD_AUDIO);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_HDCP_CONTROL_0_REG, 0x00);
|
|
|
|
dm_i2c_reg_write(chip0, 0xa7, 0x00);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
|
|
|
/* Set data-rate / lanes */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_LINK_BW_SET_REG, data_rate);
|
|
|
|
dm_i2c_reg_write(chip0, ANX9804_LANE_COUNT_SET_REG, lanes);
|
2015-08-08 14:03:29 +00:00
|
|
|
|
2021-09-27 15:42:38 +00:00
|
|
|
/* Link training */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_LINK_TRAINING_CTRL_REG,
|
|
|
|
ANX9804_LINK_TRAINING_CTRL_EN);
|
2015-08-08 14:03:29 +00:00
|
|
|
mdelay(5);
|
|
|
|
for (i = 0; i < 100; i++) {
|
2021-10-08 05:17:24 +00:00
|
|
|
c = dm_i2c_reg_read(chip0, ANX9804_LINK_TRAINING_CTRL_REG);
|
2015-08-08 14:03:29 +00:00
|
|
|
if ((c & 0x01) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
mdelay(5);
|
|
|
|
}
|
|
|
|
if(i == 100) {
|
|
|
|
printf("Error anx9804 link training timeout\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip1, ANX9804_VID_CTRL1_REG,
|
|
|
|
ANX9804_VID_CTRL1_VID_EN | ANX9804_VID_CTRL1_EDGE);
|
2015-08-08 14:03:29 +00:00
|
|
|
/* Force stream valid */
|
2021-10-08 05:17:24 +00:00
|
|
|
dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL3_REG,
|
|
|
|
ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL |
|
|
|
|
ANX9804_SYS_CTRL3_F_VALID | ANX9804_SYS_CTRL3_VALID_CTRL);
|
2015-08-08 14:03:29 +00:00
|
|
|
}
|