blob: f2139fd00546ff7420b42d8833dd893dc6365123 [file] [log] [blame]
Fuchsia firmware teamd2ca3282021-02-11 11:07:21 -08001
2/*
3 * board/amlogic/txl_skt_v1/firmware/power.c
4 *
5 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20*/
21
22#include "config.h"
23#include <serial.h>
24//#include <stdio.h>
25
26#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
27
28static int pwm_voltage_table[][2] = {
29 { 0x1c0000, 860},
30 { 0x1b0001, 870},
31 { 0x1a0002, 880},
32 { 0x190003, 890},
33 { 0x180004, 900},
34 { 0x170005, 910},
35 { 0x160006, 920},
36 { 0x150007, 930},
37 { 0x140008, 940},
38 { 0x130009, 950},
39 { 0x12000a, 960},
40 { 0x11000b, 970},
41 { 0x10000c, 980},
42 { 0x0f000d, 990},
43 { 0x0e000e, 1000},
44 { 0x0d000f, 1010},
45 { 0x0c0010, 1020},
46 { 0x0b0011, 1030},
47 { 0x0a0012, 1040},
48 { 0x090013, 1050},
49 { 0x080014, 1060},
50 { 0x070015, 1070},
51 { 0x060016, 1080},
52 { 0x050017, 1090},
53 { 0x040018, 1100},
54 { 0x030019, 1110},
55 { 0x02001a, 1120},
56 { 0x01001b, 1130},
57 { 0x00001c, 1140}
58};
59static int pwm_voltage_table_ee[][2] = {
60 { 0x1c0000, 810},
61 { 0x1b0001, 820},
62 { 0x1a0002, 830},
63 { 0x190003, 840},
64 { 0x180004, 850},
65 { 0x170005, 860},
66 { 0x160006, 870},
67 { 0x150007, 880},
68 { 0x140008, 890},
69 { 0x130009, 900},
70 { 0x12000a, 910},
71 { 0x11000b, 920},
72 { 0x10000c, 930},
73 { 0x0f000d, 940},
74 { 0x0e000e, 950},
75 { 0x0d000f, 960},
76 { 0x0c0010, 970},
77 { 0x0b0011, 980},
78 { 0x0a0012, 990},
79 { 0x090013, 1000},
80 { 0x080014, 1010},
81 { 0x070015, 1020},
82 { 0x060016, 1030},
83 { 0x050017, 1040},
84 { 0x040018, 1050},
85 { 0x030019, 1060},
86 { 0x02001a, 1070},
87 { 0x01001b, 1080},
88 { 0x00001c, 1090}
89};
90
91enum pwm_id {
92 pwm_ao_b=0,
93 pwm_ao_d,
94};
95
96void pwm_init(int id)
97{
98 unsigned int reg;
99
100 /*
101 * TODO: support more pwm controllers, right now only support
102 */
103
104 switch (id) {
105 case pwm_ao_d:
106 reg = readl(AO_PWM_MISC_REG_CD);
107 reg &= ~(0x7f << 16);
108 reg |= ((1 << 23) | (1 << 1));
109 writel(reg, AO_PWM_MISC_REG_CD);
110 /*
111 * default set to max voltage
112 */
113 reg = readl(AO_RTI_PINMUX_REG1);
114 reg &= ~(0xf << 4);
115 writel(reg | (0x3 << 4), AO_RTI_PINMUX_REG1);
116 break;
117
118 case pwm_ao_b:
119 reg = readl(AO_PWM_MISC_REG_AB);
120 reg &= ~(0x7f << 16);
121 reg |= ((1 << 23) | (1 << 1));
122 writel(reg, AO_PWM_MISC_REG_AB);
123 /*
124 * default set to max voltage
125 */
126 reg = readl(AO_RTI_PINMUX_REG0);
127 reg &= ~(0xf << 8);
128 writel(reg | (0x3 << 8), AO_RTI_PINMUX_REG0);
129 break;
130 default:
131 break;
132 }
133
134 _udelay(200);
135}
136
137void pwm_set_voltage(unsigned int id, unsigned int voltage)
138{
139 int to;
140
141 switch (id) {
142 case pwm_ao_b:
143 for (to = 0; to < ARRAY_SIZE(pwm_voltage_table); to++) {
144 if (pwm_voltage_table[to][1] >= voltage) {
145 break;
146 }
147 }
148 if (to >= ARRAY_SIZE(pwm_voltage_table)) {
149 to = ARRAY_SIZE(pwm_voltage_table) - 1;
150 }
151 writel(pwm_voltage_table[to][0],AO_PWM_PWM_B);
152 break;
153 case pwm_ao_d:
154 for (to = 0; to < ARRAY_SIZE(pwm_voltage_table_ee); to++) {
155 if (pwm_voltage_table_ee[to][1] >= voltage) {
156 break;
157 }
158 }
159 if (to >= ARRAY_SIZE(pwm_voltage_table_ee)) {
160 to = ARRAY_SIZE(pwm_voltage_table_ee) - 1;
161 }
162 writel(pwm_voltage_table_ee[to][0],AO_PWM_PWM_D);
163 break;
164 default:
165 break;
166 }
167 _udelay(200);
168}
169
170void power_init(int mode)
171{
172 unsigned int reg;
173 serial_puts("set vcck to ");
174 serial_put_dec(CONFIG_VCCK_INIT_VOLTAGE);
175 serial_puts(" mv\n");
176 pwm_set_voltage(pwm_ao_b, CONFIG_VCCK_INIT_VOLTAGE);
177 serial_puts("set vddee to ");
178 serial_put_dec(CONFIG_VDDEE_INIT_VOLTAGE);
179 serial_puts(" mv\n");
180 pwm_set_voltage(pwm_ao_d, CONFIG_VDDEE_INIT_VOLTAGE);
181 pwm_init(pwm_ao_b);
182 pwm_init(pwm_ao_d);
183}