aboutsummaryrefslogtreecommitdiff
path: root/src/mainboard/google/asurada/regulator.c
blob: b06388dc6648d95f7bfb1c60d21ce44357e11d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* SPDX-License-Identifier: GPL-2.0-only */

#include <console/console.h>
#include <ec/google/chromeec/ec.h>
#include <soc/mt6359p.h>
#include <soc/mt6360.h>
#include <soc/regulator.h>

static int get_mt6360_regulator_id(enum mtk_regulator regulator)
{
	switch (regulator) {
	case MTK_REGULATOR_VDD2:
		return MT6360_BUCK1;
	case MTK_REGULATOR_VDDQ:
		return MT6360_LDO7;
	case MTK_REGULATOR_VMDDR:
		return MT6360_LDO6;
	default:
		break;
	}

	return -1;
}

static int get_mt6359p_regulator_id(enum mtk_regulator regulator)
{
	switch (regulator) {
	case MTK_REGULATOR_VCORE:
		return MT6359P_GPU11;
	default:
		break;
	}

	return -1;
}

void mainboard_set_regulator_vol(enum mtk_regulator regulator,
				 uint32_t voltage_uv)
{
	/*
	 * Handle the regulator that does not have a regulator ID
	 * in its underlying implementation.
	 */
	if (regulator == MTK_REGULATOR_VDD1) {
		mt6359p_set_vm18_voltage(voltage_uv);
		return;
	}

	int id;

	id = get_mt6360_regulator_id(regulator);
	if (id >= 0) {
		uint32_t voltage_mv = voltage_uv / 1000;
		google_chromeec_regulator_set_voltage(id, voltage_mv, voltage_mv);
		return;
	}

	id = get_mt6359p_regulator_id(regulator);
	if (id >= 0) {
		mt6359p_buck_set_voltage(id, voltage_uv);
		return;
	}

	printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);
}

uint32_t mainboard_get_regulator_vol(enum mtk_regulator regulator)
{
	/*
	 * Handle the regulator that does not have a regulator ID
	 * in its underlying implementation.
	 */
	if (regulator == MTK_REGULATOR_VDD1)
		return mt6359p_get_vm18_voltage();

	int id;

	id = get_mt6360_regulator_id(regulator);
	if (id >= 0) {
		uint32_t voltage_mv = 0;
		google_chromeec_regulator_get_voltage(id, &voltage_mv);
		return voltage_mv * 1000;
	}

	id = get_mt6359p_regulator_id(regulator);
	if (id >= 0)
		return mt6359p_buck_get_voltage(id);

	printk(BIOS_WARNING, "Invalid regulator ID: %d\n", regulator);

	return 0;
}