blob: 323ff742636eac1c0318f63364a50ae9e1e11e66 [file] [log] [blame]
Angel Ponse67ab182020-04-04 18:51:11 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
henryc.chen7c54d2a2016-03-02 15:49:52 +08003
4#include <console/console.h>
Nico Huber0f2dd1e2017-08-01 14:02:40 +02005#include <device/i2c_simple.h>
henryc.chen7c54d2a2016-03-02 15:49:52 +08006#include <soc/mt6311.h>
7
8enum {
9 MT6311_SLAVE_ADDR = 0x6B,
10};
11
12static u32 get_mt6311_chip_id(uint8_t i2c_num)
13{
14 unsigned char id[2] = {0};
15
16 i2c_read_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_CID,
17 &id[0], 0xFF, 0);
18 i2c_read_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_SWCID,
19 &id[1], 0xFF, 0);
20
21 return (u32)(id[0] << 8 | id[1]);
22}
23
24static void mt6311_hw_init(uint8_t i2c_num)
25{
26 int ret = 0;
27 unsigned char var[3] = {0};
28
29
30 /*
31 * Phase Shedding Trim Software Setting
32 * The phase 2 of MT6311 will enter PWM mode if the threshold is
33 * reached.
34 * The threshold is set according to EFUSE value.
35 */
36 ret |= i2c_read_field(i2c_num, MT6311_SLAVE_ADDR,
37 MT6311_EFUSE_DOUT_56_63, &var[0],
38 0x3, 1);
39 ret |= i2c_read_field(i2c_num, MT6311_SLAVE_ADDR,
40 MT6311_EFUSE_DOUT_56_63, &var[1],
41 0x1, 7);
42 ret |= i2c_read_field(i2c_num, MT6311_SLAVE_ADDR,
43 MT6311_EFUSE_DOUT_64_71, &var[2],
44 0x1, 0);
45
46 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
47 MT6311_VDVFS1_ANA_CON10,
48 var[0] | var[1] << 2 | var[2] << 3, 0xf, 0);
49
50 /* I2C_CONFIG; pushpull setting, Opendrain is '0' */
51 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_TOP_INT_CON,
52 0x1, 0x1, 2);
53 /* RG_WDTRSTB_EN; CC, initial WDRSTB setting. */
54 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_TOP_RST_CON,
55 0x1, 0x1, 5);
56 /* initial INT function */
57 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_GPIO_MODE,
58 0x1, 0x7, 3);
59 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR, MT6311_STRUP_CON5,
60 0, 1 << 2 | 1 << 1 | 1 << 0, 0);
61
62 /* Vo max is 1.15V */
63 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
64 MT6311_STRUP_ANA_CON1, 0x3, 0x3, 5);
65 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
66 MT6311_BUCK_ALL_CON23, 0x1, 0x1, 0);
67 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
68 MT6311_STRUP_ANA_CON2, 0x3, 0x3, 0);
69 /* Suspend HW control from SPM */
70 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
71 MT6311_TOP_CON, 0x1, 0x1, 0);
72 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
73 MT6311_VDVFS11_CON7, 0x1, 0x1, 0);
74 /* default VDVFS power on */
75 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
76 MT6311_VDVFS11_CON9, 0x1, 0x1, 0);
77 /* for DVFS slew rate rising=0.67us */
78 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
79 MT6311_VDVFS11_CON10, 0x1, 0x7f, 0);
80 /* for DVFS slew rate, falling 2.0us */
81 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
82 MT6311_VDVFS11_CON11, 0x5, 0x7f, 0);
83 /* default VDVFS11_VOSEL 1.0V, SW control */
84 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
85 MT6311_VDVFS11_CON12, 0x40, 0x7f, 0);
86 /* default VDVFS11_VOSEL_ON 1.0V, HW control */
87 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
88 MT6311_VDVFS11_CON13, 0x40, 0x7f, 0);
89 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
90 MT6311_VDVFS11_CON14, 0x40, 0x7f, 0);
91 /* for DVFS sof change, falling 50us */
92 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
93 MT6311_VDVFS11_CON19, 0x3, 0x3, 0);
94 /* for DVFS sof change, falling only */
95 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
96 MT6311_VDVFS11_CON19, 0x1, 0x3, 4);
97 /* OFF LDO */
98 ret |= i2c_write_field(i2c_num, MT6311_SLAVE_ADDR,
99 MT6311_LDO_CON3, 0, 0x1, 0);
100
101 if (ret)
102 printk(BIOS_ERR, "ERROR: %s failed\n", __func__);
103}
104
105void mt6311_probe(uint8_t i2c_num)
106{
107 u32 val = 0;
108
109 /* Check device ID is MT6311 */
110 val = get_mt6311_chip_id(i2c_num);
111 printk(BIOS_INFO, "%s: device ID = %#x\n", __func__, val);
112
113 if (val < MT6311_E1_CID_CODE) {
114 printk(BIOS_ERR, "ERROR: unknown MT6311 device_id\n");
115 return;
116 }
117
118 mt6311_hw_init(i2c_num);
119}