xref: /openbmc/u-boot/board/gdsys/common/ch7301.c (revision ae485b54)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2014
4  * Dirk Eibach,  Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
5  */
6 
7 /* Chrontel CH7301C DVI Transmitter */
8 
9 #include <common.h>
10 #include <asm/io.h>
11 #include <errno.h>
12 #include <i2c.h>
13 
14 #define CH7301_I2C_ADDR 0x75
15 
16 enum {
17 	CH7301_CM = 0x1c,		/* Clock Mode Register */
18 	CH7301_IC = 0x1d,		/* Input Clock Register */
19 	CH7301_GPIO = 0x1e,		/* GPIO Control Register */
20 	CH7301_IDF = 0x1f,		/* Input Data Format Register */
21 	CH7301_CD = 0x20,		/* Connection Detect Register */
22 	CH7301_DC = 0x21,		/* DAC Control Register */
23 	CH7301_HPD = 0x23,		/* Hot Plug Detection Register */
24 	CH7301_TCTL = 0x31,		/* DVI Control Input Register */
25 	CH7301_TPCP = 0x33,		/* DVI PLL Charge Pump Ctrl Register */
26 	CH7301_TPD = 0x34,		/* DVI PLL Divide Register */
27 	CH7301_TPVT = 0x35,		/* DVI PLL Supply Control Register */
28 	CH7301_TPF = 0x36,		/* DVI PLL Filter Register */
29 	CH7301_TCT = 0x37,		/* DVI Clock Test Register */
30 	CH7301_TSTP = 0x48,		/* Test Pattern Register */
31 	CH7301_PM = 0x49,		/* Power Management register */
32 	CH7301_VID = 0x4a,		/* Version ID Register */
33 	CH7301_DID = 0x4b,		/* Device ID Register */
34 	CH7301_DSP = 0x56,		/* DVI Sync polarity Register */
35 };
36 
37 int ch7301_i2c[] = CONFIG_SYS_CH7301_I2C;
38 
39 int ch7301_probe(unsigned screen, bool power)
40 {
41 	u8 value;
42 
43 	i2c_set_bus_num(ch7301_i2c[screen]);
44 	if (i2c_probe(CH7301_I2C_ADDR))
45 		return -1;
46 
47 	value = i2c_reg_read(CH7301_I2C_ADDR, CH7301_DID);
48 	if (value != 0x17)
49 		return -1;
50 
51 	if (power) {
52 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPCP, 0x08);
53 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPD, 0x16);
54 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_TPF, 0x60);
55 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_DC, 0x09);
56 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_PM, 0xc0);
57 	} else {
58 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_DC, 0x00);
59 		i2c_reg_write(CH7301_I2C_ADDR, CH7301_PM, 0x01);
60 	}
61 
62 	return 0;
63 }
64