drivers/pc80/pc: Clean up formatting of PS/2 related ASL code
[coreboot.git] / src / soc / mediatek / common / mt6315.c
blobaebbd4c8a50add7e67e25d36afe067df7281b522
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <delay.h>
5 #include <soc/mt6315.h>
6 #include <soc/pmif.h>
7 #include <soc/pmif_spmi.h>
9 static struct pmif *pmif_arb = NULL;
11 static void mt6315_read(u32 slvid, u32 reg, u32 *data)
13 pmif_arb->read(pmif_arb, slvid, reg, data);
16 static void mt6315_write(u32 slvid, u32 reg, u32 data)
18 pmif_arb->write(pmif_arb, slvid, reg, data);
21 void mt6315_write_field(u32 slvid, u32 reg, u32 val, u32 mask, u32 shift)
23 pmif_arb->write_field(pmif_arb, slvid, reg, val, mask, shift);
26 static void mt6315_wdt_enable(u32 slvid)
28 mt6315_write(slvid, 0x3A9, 0x63);
29 mt6315_write(slvid, 0x3A8, 0x15);
30 mt6315_write(slvid, 0x127, 0x2);
31 mt6315_write(slvid, 0x127, 0x1);
32 mt6315_write(slvid, 0x127, 0x8);
33 udelay(50);
34 mt6315_write(slvid, 0x128, 0x8);
35 mt6315_write(slvid, 0x3A8, 0);
36 mt6315_write(slvid, 0x3A9, 0);
39 void mt6315_buck_set_voltage(u32 slvid, u32 buck_id, u32 buck_uv)
41 unsigned int vol_reg, vol_val;
43 if (!pmif_arb)
44 die("ERROR: pmif_arb not initialized");
46 switch (buck_id) {
47 case MT6315_BUCK_1:
48 vol_reg = MT6315_BUCK_TOP_ELR0;
49 break;
50 case MT6315_BUCK_3:
51 vol_reg = MT6315_BUCK_TOP_ELR3;
52 break;
53 default:
54 die("ERROR: Unknown buck_id %u", buck_id);
55 return;
58 vol_val = buck_uv / 6250;
59 mt6315_write(slvid, vol_reg, vol_val);
62 u32 mt6315_buck_get_voltage(u32 slvid, u32 buck_id)
64 u32 vol_reg, vol;
66 if (!pmif_arb)
67 die("ERROR: pmif_arb not initialized");
69 switch (buck_id) {
70 case MT6315_BUCK_1:
71 vol_reg = MT6315_BUCK_VBUCK1_DBG0;
72 break;
73 case MT6315_BUCK_3:
74 vol_reg = MT6315_BUCK_VBUCK1_DBG3;
75 break;
76 default:
77 die("ERROR: Unknown buck_id %u", buck_id);
78 return 0;
81 mt6315_read(slvid, vol_reg, &vol);
82 return vol * 6250;
85 static void init_pmif_arb(void)
87 if (!pmif_arb) {
88 pmif_arb = get_pmif_controller(PMIF_SPMI, 0);
89 if (!pmif_arb)
90 die("ERROR: No spmi device");
93 if (pmif_arb->is_pmif_init_done(pmif_arb))
94 die("ERROR - Failed to initialize pmif spmi");
97 void mt6315_init(void)
99 size_t i;
101 init_pmif_arb();
103 for (i = 0; i < spmi_dev_cnt; i++)
104 mt6315_wdt_enable(spmi_dev[i].slvid);
106 mt6315_init_setting();