Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) 2015 Hans de Goede <hdegoede@redhat.com> |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Support for the ANX9804 bridge chip, which can take pixel data coming |
| 8 | * from a parallel LCD interface and translate it on the flight into a DP |
| 9 | * interface for driving eDP TFT displays. |
| 10 | */ |
| 11 | |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 12 | #include <i2c.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Vasily Khoruzhick | 37ae5b0 | 2017-09-20 23:29:08 -0700 | [diff] [blame] | 14 | #include "anx98xx-edp.h" |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 15 | #include "anx9804.h" |
| 16 | |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 17 | /** |
| 18 | * anx9804_init() - Init anx9804 parallel lcd to edp bridge chip |
| 19 | * |
| 20 | * This function will init an anx9804 parallel lcd to dp bridge chip |
| 21 | * using the passed in parameters. |
| 22 | * |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 23 | * @i2c_bus: Device of the i2c bus to which the anx9804 is connected. |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 24 | * @lanes: Number of displayport lanes to use |
| 25 | * @data_rate: Register value for the bandwidth reg 0x06: 1.62G, 0x0a: 2.7G |
| 26 | * @bpp: Bits per pixel, must be 18 or 24 |
| 27 | */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 28 | void anx9804_init(struct udevice *i2c_bus, u8 lanes, u8 data_rate, int bpp) |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 29 | { |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 30 | struct udevice *chip0, *chip1; |
| 31 | int c, colordepth, i, ret; |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 32 | |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 33 | ret = i2c_get_chip(i2c_bus, 0x38, 1, &chip0); |
| 34 | if (ret) |
| 35 | return; |
| 36 | |
| 37 | ret = i2c_get_chip(i2c_bus, 0x39, 1, &chip1); |
| 38 | if (ret) |
| 39 | return; |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 40 | |
| 41 | if (bpp == 18) |
| 42 | colordepth = 0x00; /* 6 bit */ |
| 43 | else |
| 44 | colordepth = 0x10; /* 8 bit */ |
| 45 | |
| 46 | /* Reset */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 47 | dm_i2c_reg_write(chip1, ANX9804_RST_CTRL_REG, 1); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 48 | mdelay(100); |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 49 | dm_i2c_reg_write(chip1, ANX9804_RST_CTRL_REG, 0); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 50 | |
| 51 | /* Write 0 to the powerdown reg (powerup everything) */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 52 | dm_i2c_reg_write(chip1, ANX9804_POWERD_CTRL_REG, 0); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 53 | |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 54 | c = dm_i2c_reg_read(chip1, ANX9804_DEV_IDH_REG); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 55 | if (c != 0x98) { |
| 56 | printf("Error anx9804 chipid mismatch\n"); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 57 | return; |
| 58 | } |
| 59 | |
| 60 | for (i = 0; i < 100; i++) { |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 61 | c = dm_i2c_reg_read(chip0, ANX9804_SYS_CTRL2_REG); |
| 62 | dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL2_REG, c); |
| 63 | c = dm_i2c_reg_read(chip0, ANX9804_SYS_CTRL2_REG); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 64 | if ((c & ANX9804_SYS_CTRL2_CHA_STA) == 0) |
| 65 | break; |
| 66 | |
| 67 | mdelay(5); |
| 68 | } |
| 69 | if (i == 100) |
| 70 | printf("Error anx9804 clock is not stable\n"); |
| 71 | |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 72 | dm_i2c_reg_write(chip1, ANX9804_VID_CTRL2_REG, colordepth); |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 73 | |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 74 | /* Set a bunch of analog related register values */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 75 | dm_i2c_reg_write(chip0, ANX9804_PLL_CTRL_REG, 0x07); |
| 76 | dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL3, 0x19); |
| 77 | dm_i2c_reg_write(chip1, ANX9804_PLL_CTRL3, 0xd9); |
| 78 | dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG, ANX9804_RST_CTRL2_AC_MODE); |
| 79 | dm_i2c_reg_write(chip1, ANX9804_ANALOG_DEBUG_REG1, 0xf0); |
| 80 | dm_i2c_reg_write(chip1, ANX9804_ANALOG_DEBUG_REG3, 0x99); |
| 81 | dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL1, 0x7b); |
| 82 | dm_i2c_reg_write(chip0, ANX9804_LINK_DEBUG_REG, 0x30); |
| 83 | dm_i2c_reg_write(chip1, ANX9804_PLL_FILTER_CTRL, 0x06); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 84 | |
| 85 | /* Force HPD */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 86 | dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL3_REG, |
| 87 | ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 88 | |
| 89 | /* Power up and configure lanes */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 90 | dm_i2c_reg_write(chip0, ANX9804_ANALOG_POWER_DOWN_REG, 0x00); |
| 91 | dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE0_SET_REG, 0x00); |
| 92 | dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE1_SET_REG, 0x00); |
| 93 | dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE2_SET_REG, 0x00); |
| 94 | dm_i2c_reg_write(chip0, ANX9804_TRAINING_LANE3_SET_REG, 0x00); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 95 | |
| 96 | /* Reset AUX CH */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 97 | dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG, |
| 98 | ANX9804_RST_CTRL2_AC_MODE | ANX9804_RST_CTRL2_AUX); |
| 99 | dm_i2c_reg_write(chip1, ANX9804_RST_CTRL2_REG, |
| 100 | ANX9804_RST_CTRL2_AC_MODE); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 101 | |
| 102 | /* Powerdown audio and some other unused bits */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 103 | dm_i2c_reg_write(chip1, ANX9804_POWERD_CTRL_REG, ANX9804_POWERD_AUDIO); |
| 104 | dm_i2c_reg_write(chip0, ANX9804_HDCP_CONTROL_0_REG, 0x00); |
| 105 | dm_i2c_reg_write(chip0, 0xa7, 0x00); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 106 | |
| 107 | /* Set data-rate / lanes */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 108 | dm_i2c_reg_write(chip0, ANX9804_LINK_BW_SET_REG, data_rate); |
| 109 | dm_i2c_reg_write(chip0, ANX9804_LANE_COUNT_SET_REG, lanes); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 110 | |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 111 | /* Link training */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 112 | dm_i2c_reg_write(chip0, ANX9804_LINK_TRAINING_CTRL_REG, |
| 113 | ANX9804_LINK_TRAINING_CTRL_EN); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 114 | mdelay(5); |
| 115 | for (i = 0; i < 100; i++) { |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 116 | c = dm_i2c_reg_read(chip0, ANX9804_LINK_TRAINING_CTRL_REG); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 117 | if ((c & 0x01) == 0) |
| 118 | break; |
| 119 | |
| 120 | mdelay(5); |
| 121 | } |
| 122 | if(i == 100) { |
| 123 | printf("Error anx9804 link training timeout\n"); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
| 127 | /* Enable */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 128 | dm_i2c_reg_write(chip1, ANX9804_VID_CTRL1_REG, |
| 129 | ANX9804_VID_CTRL1_VID_EN | ANX9804_VID_CTRL1_EDGE); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 130 | /* Force stream valid */ |
Samuel Holland | 75fe0f4 | 2021-10-08 00:17:24 -0500 | [diff] [blame] | 131 | dm_i2c_reg_write(chip0, ANX9804_SYS_CTRL3_REG, |
| 132 | ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL | |
| 133 | ANX9804_SYS_CTRL3_F_VALID | ANX9804_SYS_CTRL3_VALID_CTRL); |
Hans de Goede | dfc1efe | 2015-08-08 16:03:29 +0200 | [diff] [blame] | 134 | } |