xref: /linux/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c (revision 2b2dbc2f94e55c940e1eed70706f363aa94373b0)
162a8a094STuomas Tynkkynen /*
262a8a094STuomas Tynkkynen  * Tegra124 DFLL FCPU clock source driver
362a8a094STuomas Tynkkynen  *
4b0dcfb78SPeter De Schrijver  * Copyright (C) 2012-2019 NVIDIA Corporation.  All rights reserved.
562a8a094STuomas Tynkkynen  *
662a8a094STuomas Tynkkynen  * Aleksandr Frid <afrid@nvidia.com>
762a8a094STuomas Tynkkynen  * Paul Walmsley <pwalmsley@nvidia.com>
862a8a094STuomas Tynkkynen  *
962a8a094STuomas Tynkkynen  * This program is free software; you can redistribute it and/or modify
1062a8a094STuomas Tynkkynen  * it under the terms of the GNU General Public License version 2 as
1162a8a094STuomas Tynkkynen  * published by the Free Software Foundation.
1262a8a094STuomas Tynkkynen  *
1362a8a094STuomas Tynkkynen  * This program is distributed in the hope that it will be useful, but WITHOUT
1462a8a094STuomas Tynkkynen  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1562a8a094STuomas Tynkkynen  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1662a8a094STuomas Tynkkynen  * more details.
1762a8a094STuomas Tynkkynen  *
1862a8a094STuomas Tynkkynen  */
1962a8a094STuomas Tynkkynen 
2062a8a094STuomas Tynkkynen #include <linux/cpu.h>
2162a8a094STuomas Tynkkynen #include <linux/err.h>
2262a8a094STuomas Tynkkynen #include <linux/kernel.h>
2333996b02SPaul Gortmaker #include <linux/init.h>
24b0dcfb78SPeter De Schrijver #include <linux/of_device.h>
2562a8a094STuomas Tynkkynen #include <linux/platform_device.h>
26b3cf8d06SJoseph Lo #include <linux/regulator/consumer.h>
2762a8a094STuomas Tynkkynen #include <soc/tegra/fuse.h>
2862a8a094STuomas Tynkkynen 
2962a8a094STuomas Tynkkynen #include "clk.h"
3062a8a094STuomas Tynkkynen #include "clk-dfll.h"
3162a8a094STuomas Tynkkynen #include "cvb.h"
3262a8a094STuomas Tynkkynen 
33b0dcfb78SPeter De Schrijver struct dfll_fcpu_data {
34b0dcfb78SPeter De Schrijver 	const unsigned long *cpu_max_freq_table;
35b0dcfb78SPeter De Schrijver 	unsigned int cpu_max_freq_table_size;
36b0dcfb78SPeter De Schrijver 	const struct cvb_table *cpu_cvb_tables;
37b0dcfb78SPeter De Schrijver 	unsigned int cpu_cvb_tables_size;
38b0dcfb78SPeter De Schrijver };
39b0dcfb78SPeter De Schrijver 
4062a8a094STuomas Tynkkynen /* Maximum CPU frequency, indexed by CPU speedo id */
41b0dcfb78SPeter De Schrijver static const unsigned long tegra124_cpu_max_freq_table[] = {
4262a8a094STuomas Tynkkynen 	[0] = 2014500000UL,
4362a8a094STuomas Tynkkynen 	[1] = 2320500000UL,
4462a8a094STuomas Tynkkynen 	[2] = 2116500000UL,
4562a8a094STuomas Tynkkynen 	[3] = 2524500000UL,
4662a8a094STuomas Tynkkynen };
4762a8a094STuomas Tynkkynen 
4862a8a094STuomas Tynkkynen static const struct cvb_table tegra124_cpu_cvb_tables[] = {
4962a8a094STuomas Tynkkynen 	{
5062a8a094STuomas Tynkkynen 		.speedo_id = -1,
5162a8a094STuomas Tynkkynen 		.process_id = -1,
5262a8a094STuomas Tynkkynen 		.min_millivolts = 900,
5362a8a094STuomas Tynkkynen 		.max_millivolts = 1260,
5462a8a094STuomas Tynkkynen 		.speedo_scale = 100,
5562a8a094STuomas Tynkkynen 		.voltage_scale = 1000,
56e8f6a68cSThierry Reding 		.entries = {
5762a8a094STuomas Tynkkynen 			{  204000000UL, { 1112619, -29295, 402 } },
5862a8a094STuomas Tynkkynen 			{  306000000UL, { 1150460, -30585, 402 } },
5962a8a094STuomas Tynkkynen 			{  408000000UL, { 1190122, -31865, 402 } },
6062a8a094STuomas Tynkkynen 			{  510000000UL, { 1231606, -33155, 402 } },
6162a8a094STuomas Tynkkynen 			{  612000000UL, { 1274912, -34435, 402 } },
6262a8a094STuomas Tynkkynen 			{  714000000UL, { 1320040, -35725, 402 } },
6362a8a094STuomas Tynkkynen 			{  816000000UL, { 1366990, -37005, 402 } },
6462a8a094STuomas Tynkkynen 			{  918000000UL, { 1415762, -38295, 402 } },
6562a8a094STuomas Tynkkynen 			{ 1020000000UL, { 1466355, -39575, 402 } },
6662a8a094STuomas Tynkkynen 			{ 1122000000UL, { 1518771, -40865, 402 } },
6762a8a094STuomas Tynkkynen 			{ 1224000000UL, { 1573009, -42145, 402 } },
6862a8a094STuomas Tynkkynen 			{ 1326000000UL, { 1629068, -43435, 402 } },
6962a8a094STuomas Tynkkynen 			{ 1428000000UL, { 1686950, -44715, 402 } },
7062a8a094STuomas Tynkkynen 			{ 1530000000UL, { 1746653, -46005, 402 } },
7162a8a094STuomas Tynkkynen 			{ 1632000000UL, { 1808179, -47285, 402 } },
7262a8a094STuomas Tynkkynen 			{ 1734000000UL, { 1871526, -48575, 402 } },
7362a8a094STuomas Tynkkynen 			{ 1836000000UL, { 1936696, -49855, 402 } },
7462a8a094STuomas Tynkkynen 			{ 1938000000UL, { 2003687, -51145, 402 } },
7562a8a094STuomas Tynkkynen 			{ 2014500000UL, { 2054787, -52095, 402 } },
7662a8a094STuomas Tynkkynen 			{ 2116500000UL, { 2124957, -53385, 402 } },
7762a8a094STuomas Tynkkynen 			{ 2218500000UL, { 2196950, -54665, 402 } },
7862a8a094STuomas Tynkkynen 			{ 2320500000UL, { 2270765, -55955, 402 } },
7962a8a094STuomas Tynkkynen 			{ 2422500000UL, { 2346401, -57235, 402 } },
8062a8a094STuomas Tynkkynen 			{ 2524500000UL, { 2437299, -58535, 402 } },
812690e912SThierry Reding 			{          0UL, {       0,      0,   0 } },
8262a8a094STuomas Tynkkynen 		},
8362a8a094STuomas Tynkkynen 		.cpu_dfll_data = {
8462a8a094STuomas Tynkkynen 			.tune0_low = 0x005020ff,
8562a8a094STuomas Tynkkynen 			.tune0_high = 0x005040ff,
8662a8a094STuomas Tynkkynen 			.tune1 = 0x00000060,
8762a8a094STuomas Tynkkynen 		}
8862a8a094STuomas Tynkkynen 	},
8962a8a094STuomas Tynkkynen };
9062a8a094STuomas Tynkkynen 
91*2b2dbc2fSJoseph Lo static const unsigned long tegra210_cpu_max_freq_table[] = {
92*2b2dbc2fSJoseph Lo 	[0] = 1912500000UL,
93*2b2dbc2fSJoseph Lo 	[1] = 1912500000UL,
94*2b2dbc2fSJoseph Lo 	[2] = 2218500000UL,
95*2b2dbc2fSJoseph Lo 	[3] = 1785000000UL,
96*2b2dbc2fSJoseph Lo 	[4] = 1632000000UL,
97*2b2dbc2fSJoseph Lo 	[5] = 1912500000UL,
98*2b2dbc2fSJoseph Lo 	[6] = 2014500000UL,
99*2b2dbc2fSJoseph Lo 	[7] = 1734000000UL,
100*2b2dbc2fSJoseph Lo 	[8] = 1683000000UL,
101*2b2dbc2fSJoseph Lo 	[9] = 1555500000UL,
102*2b2dbc2fSJoseph Lo 	[10] = 1504500000UL,
103*2b2dbc2fSJoseph Lo };
104*2b2dbc2fSJoseph Lo 
105*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE \
106*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
107*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
108*2b2dbc2fSJoseph Lo 	.entries = {		\
109*2b2dbc2fSJoseph Lo 		{  204000000UL,	{ 1007452, -23865, 370 } }, \
110*2b2dbc2fSJoseph Lo 		{  306000000UL,	{ 1052709, -24875, 370 } }, \
111*2b2dbc2fSJoseph Lo 		{  408000000UL,	{ 1099069, -25895, 370 } }, \
112*2b2dbc2fSJoseph Lo 		{  510000000UL,	{ 1146534, -26905, 370 } }, \
113*2b2dbc2fSJoseph Lo 		{  612000000UL,	{ 1195102, -27915, 370 } }, \
114*2b2dbc2fSJoseph Lo 		{  714000000UL,	{ 1244773, -28925, 370 } }, \
115*2b2dbc2fSJoseph Lo 		{  816000000UL,	{ 1295549, -29935, 370 } }, \
116*2b2dbc2fSJoseph Lo 		{  918000000UL,	{ 1347428, -30955, 370 } }, \
117*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1400411, -31965, 370 } }, \
118*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1454497, -32975, 370 } }, \
119*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1509687, -33985, 370 } }, \
120*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1565981, -35005, 370 } }, \
121*2b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1623379, -36015, 370 } }, \
122*2b2dbc2fSJoseph Lo 		{ 1530000000UL,	{ 1681880, -37025, 370 } }, \
123*2b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 1741485, -38035, 370 } }, \
124*2b2dbc2fSJoseph Lo 		{ 1734000000UL,	{ 1802194, -39055, 370 } }, \
125*2b2dbc2fSJoseph Lo 		{ 1836000000UL,	{ 1864006, -40065, 370 } }, \
126*2b2dbc2fSJoseph Lo 		{ 1912500000UL,	{ 1910780, -40815, 370 } }, \
127*2b2dbc2fSJoseph Lo 		{ 2014500000UL,	{ 1227000,      0,   0 } }, \
128*2b2dbc2fSJoseph Lo 		{ 2218500000UL,	{ 1227000,      0,   0 } }, \
129*2b2dbc2fSJoseph Lo 		{          0UL,	{       0,      0,   0 } }, \
130*2b2dbc2fSJoseph Lo 	}
131*2b2dbc2fSJoseph Lo 
132*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_XA \
133*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
134*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
135*2b2dbc2fSJoseph Lo 	.entries = {		\
136*2b2dbc2fSJoseph Lo 		{  204000000UL,	{ 1250024, -39785, 565 } }, \
137*2b2dbc2fSJoseph Lo 		{  306000000UL,	{ 1297556, -41145, 565 } }, \
138*2b2dbc2fSJoseph Lo 		{  408000000UL,	{ 1346718, -42505, 565 } }, \
139*2b2dbc2fSJoseph Lo 		{  510000000UL,	{ 1397511, -43855, 565 } }, \
140*2b2dbc2fSJoseph Lo 		{  612000000UL,	{ 1449933, -45215, 565 } }, \
141*2b2dbc2fSJoseph Lo 		{  714000000UL,	{ 1503986, -46575, 565 } }, \
142*2b2dbc2fSJoseph Lo 		{  816000000UL,	{ 1559669, -47935, 565 } }, \
143*2b2dbc2fSJoseph Lo 		{  918000000UL,	{ 1616982, -49295, 565 } }, \
144*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1675926, -50645, 565 } }, \
145*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1736500, -52005, 565 } }, \
146*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1798704, -53365, 565 } }, \
147*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1862538, -54725, 565 } }, \
148*2b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1928003, -56085, 565 } }, \
149*2b2dbc2fSJoseph Lo 		{ 1530000000UL,	{ 1995097, -57435, 565 } }, \
150*2b2dbc2fSJoseph Lo 		{ 1606500000UL,	{ 2046149, -58445, 565 } }, \
151*2b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 2063822, -58795, 565 } }, \
152*2b2dbc2fSJoseph Lo 		{          0UL,	{       0,      0,   0 } }, \
153*2b2dbc2fSJoseph Lo 	}
154*2b2dbc2fSJoseph Lo 
155*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM1 \
156*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
157*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
158*2b2dbc2fSJoseph Lo 	.entries = {		\
159*2b2dbc2fSJoseph Lo 		{  204000000UL,	{  734429, 0, 0 } }, \
160*2b2dbc2fSJoseph Lo 		{  306000000UL,	{  768191, 0, 0 } }, \
161*2b2dbc2fSJoseph Lo 		{  408000000UL,	{  801953, 0, 0 } }, \
162*2b2dbc2fSJoseph Lo 		{  510000000UL,	{  835715, 0, 0 } }, \
163*2b2dbc2fSJoseph Lo 		{  612000000UL,	{  869477, 0, 0 } }, \
164*2b2dbc2fSJoseph Lo 		{  714000000UL,	{  903239, 0, 0 } }, \
165*2b2dbc2fSJoseph Lo 		{  816000000UL,	{  937001, 0, 0 } }, \
166*2b2dbc2fSJoseph Lo 		{  918000000UL,	{  970763, 0, 0 } }, \
167*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1004525, 0, 0 } }, \
168*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1038287, 0, 0 } }, \
169*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1072049, 0, 0 } }, \
170*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1105811, 0, 0 } }, \
171*2b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1130000, 0, 0 } }, \
172*2b2dbc2fSJoseph Lo 		{ 1555500000UL,	{ 1130000, 0, 0 } }, \
173*2b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 1170000, 0, 0 } }, \
174*2b2dbc2fSJoseph Lo 		{ 1734000000UL,	{ 1227500, 0, 0 } }, \
175*2b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
176*2b2dbc2fSJoseph Lo 	}
177*2b2dbc2fSJoseph Lo 
178*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM2 \
179*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
180*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
181*2b2dbc2fSJoseph Lo 	.entries = {		\
182*2b2dbc2fSJoseph Lo 		{  204000000UL,	{  742283, 0, 0 } }, \
183*2b2dbc2fSJoseph Lo 		{  306000000UL,	{  776249, 0, 0 } }, \
184*2b2dbc2fSJoseph Lo 		{  408000000UL,	{  810215, 0, 0 } }, \
185*2b2dbc2fSJoseph Lo 		{  510000000UL,	{  844181, 0, 0 } }, \
186*2b2dbc2fSJoseph Lo 		{  612000000UL,	{  878147, 0, 0 } }, \
187*2b2dbc2fSJoseph Lo 		{  714000000UL,	{  912113, 0, 0 } }, \
188*2b2dbc2fSJoseph Lo 		{  816000000UL,	{  946079, 0, 0 } }, \
189*2b2dbc2fSJoseph Lo 		{  918000000UL,	{  980045, 0, 0 } }, \
190*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1014011, 0, 0 } }, \
191*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1047977, 0, 0 } }, \
192*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1081943, 0, 0 } }, \
193*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1090000, 0, 0 } }, \
194*2b2dbc2fSJoseph Lo 		{ 1479000000UL,	{ 1090000, 0, 0 } }, \
195*2b2dbc2fSJoseph Lo 		{ 1555500000UL,	{ 1162000, 0, 0 } }, \
196*2b2dbc2fSJoseph Lo 		{ 1683000000UL,	{ 1195000, 0, 0 } }, \
197*2b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
198*2b2dbc2fSJoseph Lo 	}
199*2b2dbc2fSJoseph Lo 
200*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM2_JOINT_RAIL \
201*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
202*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
203*2b2dbc2fSJoseph Lo 	.entries = {		\
204*2b2dbc2fSJoseph Lo 		{  204000000UL,	{  742283, 0, 0 } }, \
205*2b2dbc2fSJoseph Lo 		{  306000000UL,	{  776249, 0, 0 } }, \
206*2b2dbc2fSJoseph Lo 		{  408000000UL,	{  810215, 0, 0 } }, \
207*2b2dbc2fSJoseph Lo 		{  510000000UL,	{  844181, 0, 0 } }, \
208*2b2dbc2fSJoseph Lo 		{  612000000UL,	{  878147, 0, 0 } }, \
209*2b2dbc2fSJoseph Lo 		{  714000000UL,	{  912113, 0, 0 } }, \
210*2b2dbc2fSJoseph Lo 		{  816000000UL,	{  946079, 0, 0 } }, \
211*2b2dbc2fSJoseph Lo 		{  918000000UL,	{  980045, 0, 0 } }, \
212*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1014011, 0, 0 } }, \
213*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1047977, 0, 0 } }, \
214*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1081943, 0, 0 } }, \
215*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1090000, 0, 0 } }, \
216*2b2dbc2fSJoseph Lo 		{ 1479000000UL,	{ 1090000, 0, 0 } }, \
217*2b2dbc2fSJoseph Lo 		{ 1504500000UL,	{ 1120000, 0, 0 } }, \
218*2b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
219*2b2dbc2fSJoseph Lo 	}
220*2b2dbc2fSJoseph Lo 
221*2b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_ODN \
222*2b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
223*2b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
224*2b2dbc2fSJoseph Lo 	.entries = {		\
225*2b2dbc2fSJoseph Lo 		{  204000000UL,	{  721094, 0, 0 } }, \
226*2b2dbc2fSJoseph Lo 		{  306000000UL,	{  754040, 0, 0 } }, \
227*2b2dbc2fSJoseph Lo 		{  408000000UL,	{  786986, 0, 0 } }, \
228*2b2dbc2fSJoseph Lo 		{  510000000UL,	{  819932, 0, 0 } }, \
229*2b2dbc2fSJoseph Lo 		{  612000000UL,	{  852878, 0, 0 } }, \
230*2b2dbc2fSJoseph Lo 		{  714000000UL,	{  885824, 0, 0 } }, \
231*2b2dbc2fSJoseph Lo 		{  816000000UL,	{  918770, 0, 0 } }, \
232*2b2dbc2fSJoseph Lo 		{  918000000UL,	{  915716, 0, 0 } }, \
233*2b2dbc2fSJoseph Lo 		{ 1020000000UL,	{  984662, 0, 0 } }, \
234*2b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1017608, 0, 0 } }, \
235*2b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1050554, 0, 0 } }, \
236*2b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1083500, 0, 0 } }, \
237*2b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1116446, 0, 0 } }, \
238*2b2dbc2fSJoseph Lo 		{ 1581000000UL,	{ 1130000, 0, 0 } }, \
239*2b2dbc2fSJoseph Lo 		{ 1683000000UL,	{ 1168000, 0, 0 } }, \
240*2b2dbc2fSJoseph Lo 		{ 1785000000UL,	{ 1227500, 0, 0 } }, \
241*2b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
242*2b2dbc2fSJoseph Lo 	}
243*2b2dbc2fSJoseph Lo 
244*2b2dbc2fSJoseph Lo struct cvb_table tegra210_cpu_cvb_tables[] = {
245*2b2dbc2fSJoseph Lo 	{
246*2b2dbc2fSJoseph Lo 		.speedo_id = 10,
247*2b2dbc2fSJoseph Lo 		.process_id = 0,
248*2b2dbc2fSJoseph Lo 		.min_millivolts = 840,
249*2b2dbc2fSJoseph Lo 		.max_millivolts = 1120,
250*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2_JOINT_RAIL,
251*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
252*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
253*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
254*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
255*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
256*2b2dbc2fSJoseph Lo 		}
257*2b2dbc2fSJoseph Lo 	},
258*2b2dbc2fSJoseph Lo 	{
259*2b2dbc2fSJoseph Lo 		.speedo_id = 10,
260*2b2dbc2fSJoseph Lo 		.process_id = 1,
261*2b2dbc2fSJoseph Lo 		.min_millivolts = 840,
262*2b2dbc2fSJoseph Lo 		.max_millivolts = 1120,
263*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2_JOINT_RAIL,
264*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
265*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
266*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
267*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
268*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
269*2b2dbc2fSJoseph Lo 		}
270*2b2dbc2fSJoseph Lo 	},
271*2b2dbc2fSJoseph Lo 	{
272*2b2dbc2fSJoseph Lo 		.speedo_id = 9,
273*2b2dbc2fSJoseph Lo 		.process_id = 0,
274*2b2dbc2fSJoseph Lo 		.min_millivolts = 900,
275*2b2dbc2fSJoseph Lo 		.max_millivolts = 1162,
276*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
277*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
278*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
279*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
280*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
281*2b2dbc2fSJoseph Lo 		}
282*2b2dbc2fSJoseph Lo 	},
283*2b2dbc2fSJoseph Lo 	{
284*2b2dbc2fSJoseph Lo 		.speedo_id = 9,
285*2b2dbc2fSJoseph Lo 		.process_id = 1,
286*2b2dbc2fSJoseph Lo 		.min_millivolts = 900,
287*2b2dbc2fSJoseph Lo 		.max_millivolts = 1162,
288*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
289*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
290*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
291*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
292*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
293*2b2dbc2fSJoseph Lo 		}
294*2b2dbc2fSJoseph Lo 	},
295*2b2dbc2fSJoseph Lo 	{
296*2b2dbc2fSJoseph Lo 		.speedo_id = 8,
297*2b2dbc2fSJoseph Lo 		.process_id = 0,
298*2b2dbc2fSJoseph Lo 		.min_millivolts = 900,
299*2b2dbc2fSJoseph Lo 		.max_millivolts = 1195,
300*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
301*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
302*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
303*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
304*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
305*2b2dbc2fSJoseph Lo 		}
306*2b2dbc2fSJoseph Lo 	},
307*2b2dbc2fSJoseph Lo 	{
308*2b2dbc2fSJoseph Lo 		.speedo_id = 8,
309*2b2dbc2fSJoseph Lo 		.process_id = 1,
310*2b2dbc2fSJoseph Lo 		.min_millivolts = 900,
311*2b2dbc2fSJoseph Lo 		.max_millivolts = 1195,
312*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
313*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
314*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
315*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
316*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
317*2b2dbc2fSJoseph Lo 		}
318*2b2dbc2fSJoseph Lo 	},
319*2b2dbc2fSJoseph Lo 	{
320*2b2dbc2fSJoseph Lo 		.speedo_id = 7,
321*2b2dbc2fSJoseph Lo 		.process_id = 0,
322*2b2dbc2fSJoseph Lo 		.min_millivolts = 841,
323*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
324*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM1,
325*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
326*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
327*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
328*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
329*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
330*2b2dbc2fSJoseph Lo 		}
331*2b2dbc2fSJoseph Lo 	},
332*2b2dbc2fSJoseph Lo 	{
333*2b2dbc2fSJoseph Lo 		.speedo_id = 7,
334*2b2dbc2fSJoseph Lo 		.process_id = 1,
335*2b2dbc2fSJoseph Lo 		.min_millivolts = 841,
336*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
337*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM1,
338*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
339*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
340*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
341*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
342*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
343*2b2dbc2fSJoseph Lo 		}
344*2b2dbc2fSJoseph Lo 	},
345*2b2dbc2fSJoseph Lo 	{
346*2b2dbc2fSJoseph Lo 		.speedo_id = 6,
347*2b2dbc2fSJoseph Lo 		.process_id = 0,
348*2b2dbc2fSJoseph Lo 		.min_millivolts = 870,
349*2b2dbc2fSJoseph Lo 		.max_millivolts = 1150,
350*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
351*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
352*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
353*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
354*2b2dbc2fSJoseph Lo 		}
355*2b2dbc2fSJoseph Lo 	},
356*2b2dbc2fSJoseph Lo 	{
357*2b2dbc2fSJoseph Lo 		.speedo_id = 6,
358*2b2dbc2fSJoseph Lo 		.process_id = 1,
359*2b2dbc2fSJoseph Lo 		.min_millivolts = 870,
360*2b2dbc2fSJoseph Lo 		.max_millivolts = 1150,
361*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
362*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
363*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
364*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
365*2b2dbc2fSJoseph Lo 		}
366*2b2dbc2fSJoseph Lo 	},
367*2b2dbc2fSJoseph Lo 	{
368*2b2dbc2fSJoseph Lo 		.speedo_id = 5,
369*2b2dbc2fSJoseph Lo 		.process_id = 0,
370*2b2dbc2fSJoseph Lo 		.min_millivolts = 818,
371*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
372*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
373*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
374*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
375*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
376*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
377*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
378*2b2dbc2fSJoseph Lo 		}
379*2b2dbc2fSJoseph Lo 	},
380*2b2dbc2fSJoseph Lo 	{
381*2b2dbc2fSJoseph Lo 		.speedo_id = 5,
382*2b2dbc2fSJoseph Lo 		.process_id = 1,
383*2b2dbc2fSJoseph Lo 		.min_millivolts = 818,
384*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
385*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
386*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
387*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
388*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
389*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
390*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
391*2b2dbc2fSJoseph Lo 		}
392*2b2dbc2fSJoseph Lo 	},
393*2b2dbc2fSJoseph Lo 	{
394*2b2dbc2fSJoseph Lo 		.speedo_id = 4,
395*2b2dbc2fSJoseph Lo 		.process_id = -1,
396*2b2dbc2fSJoseph Lo 		.min_millivolts = 918,
397*2b2dbc2fSJoseph Lo 		.max_millivolts = 1113,
398*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_XA,
399*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
400*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
401*2b2dbc2fSJoseph Lo 			.tune1 = 0x17711BD,
402*2b2dbc2fSJoseph Lo 		}
403*2b2dbc2fSJoseph Lo 	},
404*2b2dbc2fSJoseph Lo 	{
405*2b2dbc2fSJoseph Lo 		.speedo_id = 3,
406*2b2dbc2fSJoseph Lo 		.process_id = 0,
407*2b2dbc2fSJoseph Lo 		.min_millivolts = 825,
408*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
409*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_ODN,
410*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
411*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
412*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
413*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
414*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
415*2b2dbc2fSJoseph Lo 		}
416*2b2dbc2fSJoseph Lo 	},
417*2b2dbc2fSJoseph Lo 	{
418*2b2dbc2fSJoseph Lo 		.speedo_id = 3,
419*2b2dbc2fSJoseph Lo 		.process_id = 1,
420*2b2dbc2fSJoseph Lo 		.min_millivolts = 825,
421*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
422*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_ODN,
423*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
424*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
425*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
426*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
427*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
428*2b2dbc2fSJoseph Lo 		}
429*2b2dbc2fSJoseph Lo 	},
430*2b2dbc2fSJoseph Lo 	{
431*2b2dbc2fSJoseph Lo 		.speedo_id = 2,
432*2b2dbc2fSJoseph Lo 		.process_id = 0,
433*2b2dbc2fSJoseph Lo 		.min_millivolts = 870,
434*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
435*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
436*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
437*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
438*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
439*2b2dbc2fSJoseph Lo 		}
440*2b2dbc2fSJoseph Lo 	},
441*2b2dbc2fSJoseph Lo 	{
442*2b2dbc2fSJoseph Lo 		.speedo_id = 2,
443*2b2dbc2fSJoseph Lo 		.process_id = 1,
444*2b2dbc2fSJoseph Lo 		.min_millivolts = 870,
445*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
446*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
447*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
448*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
449*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
450*2b2dbc2fSJoseph Lo 		}
451*2b2dbc2fSJoseph Lo 	},
452*2b2dbc2fSJoseph Lo 	{
453*2b2dbc2fSJoseph Lo 		.speedo_id = 1,
454*2b2dbc2fSJoseph Lo 		.process_id = 0,
455*2b2dbc2fSJoseph Lo 		.min_millivolts = 837,
456*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
457*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
458*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
459*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
460*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
461*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
462*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
463*2b2dbc2fSJoseph Lo 		}
464*2b2dbc2fSJoseph Lo 	},
465*2b2dbc2fSJoseph Lo 	{
466*2b2dbc2fSJoseph Lo 		.speedo_id = 1,
467*2b2dbc2fSJoseph Lo 		.process_id = 1,
468*2b2dbc2fSJoseph Lo 		.min_millivolts = 837,
469*2b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
470*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
471*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
472*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
473*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
474*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
475*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
476*2b2dbc2fSJoseph Lo 		}
477*2b2dbc2fSJoseph Lo 	},
478*2b2dbc2fSJoseph Lo 	{
479*2b2dbc2fSJoseph Lo 		.speedo_id = 0,
480*2b2dbc2fSJoseph Lo 		.process_id = 0,
481*2b2dbc2fSJoseph Lo 		.min_millivolts = 850,
482*2b2dbc2fSJoseph Lo 		.max_millivolts = 1170,
483*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
484*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
485*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
486*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
487*2b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
488*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
489*2b2dbc2fSJoseph Lo 		}
490*2b2dbc2fSJoseph Lo 	},
491*2b2dbc2fSJoseph Lo 	{
492*2b2dbc2fSJoseph Lo 		.speedo_id = 0,
493*2b2dbc2fSJoseph Lo 		.process_id = 1,
494*2b2dbc2fSJoseph Lo 		.min_millivolts = 850,
495*2b2dbc2fSJoseph Lo 		.max_millivolts = 1170,
496*2b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
497*2b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
498*2b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
499*2b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
500*2b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
501*2b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
502*2b2dbc2fSJoseph Lo 		}
503*2b2dbc2fSJoseph Lo 	},
504*2b2dbc2fSJoseph Lo };
505*2b2dbc2fSJoseph Lo 
506b0dcfb78SPeter De Schrijver static const struct dfll_fcpu_data tegra124_dfll_fcpu_data = {
507b0dcfb78SPeter De Schrijver 	.cpu_max_freq_table = tegra124_cpu_max_freq_table,
508b0dcfb78SPeter De Schrijver 	.cpu_max_freq_table_size = ARRAY_SIZE(tegra124_cpu_max_freq_table),
509b0dcfb78SPeter De Schrijver 	.cpu_cvb_tables = tegra124_cpu_cvb_tables,
510b0dcfb78SPeter De Schrijver 	.cpu_cvb_tables_size = ARRAY_SIZE(tegra124_cpu_cvb_tables)
511b0dcfb78SPeter De Schrijver };
512b0dcfb78SPeter De Schrijver 
513*2b2dbc2fSJoseph Lo static const struct dfll_fcpu_data tegra210_dfll_fcpu_data = {
514*2b2dbc2fSJoseph Lo 	.cpu_max_freq_table = tegra210_cpu_max_freq_table,
515*2b2dbc2fSJoseph Lo 	.cpu_max_freq_table_size = ARRAY_SIZE(tegra210_cpu_max_freq_table),
516*2b2dbc2fSJoseph Lo 	.cpu_cvb_tables = tegra210_cpu_cvb_tables,
517*2b2dbc2fSJoseph Lo 	.cpu_cvb_tables_size = ARRAY_SIZE(tegra210_cpu_cvb_tables),
518*2b2dbc2fSJoseph Lo };
519*2b2dbc2fSJoseph Lo 
520b0dcfb78SPeter De Schrijver static const struct of_device_id tegra124_dfll_fcpu_of_match[] = {
521b0dcfb78SPeter De Schrijver 	{
522b0dcfb78SPeter De Schrijver 		.compatible = "nvidia,tegra124-dfll",
523b0dcfb78SPeter De Schrijver 		.data = &tegra124_dfll_fcpu_data,
524b0dcfb78SPeter De Schrijver 	},
525*2b2dbc2fSJoseph Lo 	{
526*2b2dbc2fSJoseph Lo 		.compatible = "nvidia,tegra210-dfll",
527*2b2dbc2fSJoseph Lo 		.data = &tegra210_dfll_fcpu_data
528*2b2dbc2fSJoseph Lo 	},
529b0dcfb78SPeter De Schrijver 	{ },
530b0dcfb78SPeter De Schrijver };
531b0dcfb78SPeter De Schrijver 
532b3cf8d06SJoseph Lo static void get_alignment_from_dt(struct device *dev,
533b3cf8d06SJoseph Lo 				  struct rail_alignment *align)
534b3cf8d06SJoseph Lo {
535b3cf8d06SJoseph Lo 	if (of_property_read_u32(dev->of_node,
536b3cf8d06SJoseph Lo 				 "nvidia,pwm-voltage-step-microvolts",
537b3cf8d06SJoseph Lo 				 &align->step_uv))
538b3cf8d06SJoseph Lo 		align->step_uv = 0;
539b3cf8d06SJoseph Lo 
540b3cf8d06SJoseph Lo 	if (of_property_read_u32(dev->of_node,
541b3cf8d06SJoseph Lo 				 "nvidia,pwm-min-microvolts",
542b3cf8d06SJoseph Lo 				 &align->offset_uv))
543b3cf8d06SJoseph Lo 		align->offset_uv = 0;
544b3cf8d06SJoseph Lo }
545b3cf8d06SJoseph Lo 
546b3cf8d06SJoseph Lo static int get_alignment_from_regulator(struct device *dev,
547b3cf8d06SJoseph Lo 					 struct rail_alignment *align)
548b3cf8d06SJoseph Lo {
549b3cf8d06SJoseph Lo 	struct regulator *reg = devm_regulator_get(dev, "vdd-cpu");
550b3cf8d06SJoseph Lo 
551b3cf8d06SJoseph Lo 	if (IS_ERR(reg))
552b3cf8d06SJoseph Lo 		return PTR_ERR(reg);
553b3cf8d06SJoseph Lo 
554b3cf8d06SJoseph Lo 	align->offset_uv = regulator_list_voltage(reg, 0);
555b3cf8d06SJoseph Lo 	align->step_uv = regulator_get_linear_step(reg);
556b3cf8d06SJoseph Lo 
557b3cf8d06SJoseph Lo 	devm_regulator_put(reg);
558b3cf8d06SJoseph Lo 
559b3cf8d06SJoseph Lo 	return 0;
560b3cf8d06SJoseph Lo }
561b3cf8d06SJoseph Lo 
56262a8a094STuomas Tynkkynen static int tegra124_dfll_fcpu_probe(struct platform_device *pdev)
56362a8a094STuomas Tynkkynen {
564f7c42d98SThierry Reding 	int process_id, speedo_id, speedo_value, err;
56562a8a094STuomas Tynkkynen 	struct tegra_dfll_soc_data *soc;
566b0dcfb78SPeter De Schrijver 	const struct dfll_fcpu_data *fcpu_data;
567b3cf8d06SJoseph Lo 	struct rail_alignment align;
568b0dcfb78SPeter De Schrijver 
569b0dcfb78SPeter De Schrijver 	fcpu_data = of_device_get_match_data(&pdev->dev);
570b0dcfb78SPeter De Schrijver 	if (!fcpu_data)
571b0dcfb78SPeter De Schrijver 		return -ENODEV;
57262a8a094STuomas Tynkkynen 
57362a8a094STuomas Tynkkynen 	process_id = tegra_sku_info.cpu_process_id;
57462a8a094STuomas Tynkkynen 	speedo_id = tegra_sku_info.cpu_speedo_id;
57562a8a094STuomas Tynkkynen 	speedo_value = tegra_sku_info.cpu_speedo_value;
57662a8a094STuomas Tynkkynen 
577b0dcfb78SPeter De Schrijver 	if (speedo_id >= fcpu_data->cpu_max_freq_table_size) {
57862a8a094STuomas Tynkkynen 		dev_err(&pdev->dev, "unknown max CPU freq for speedo_id=%d\n",
57962a8a094STuomas Tynkkynen 			speedo_id);
58062a8a094STuomas Tynkkynen 		return -ENODEV;
58162a8a094STuomas Tynkkynen 	}
58262a8a094STuomas Tynkkynen 
58362a8a094STuomas Tynkkynen 	soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL);
58462a8a094STuomas Tynkkynen 	if (!soc)
58562a8a094STuomas Tynkkynen 		return -ENOMEM;
58662a8a094STuomas Tynkkynen 
58762a8a094STuomas Tynkkynen 	soc->dev = get_cpu_device(0);
58862a8a094STuomas Tynkkynen 	if (!soc->dev) {
58962a8a094STuomas Tynkkynen 		dev_err(&pdev->dev, "no CPU0 device\n");
59062a8a094STuomas Tynkkynen 		return -ENODEV;
59162a8a094STuomas Tynkkynen 	}
59262a8a094STuomas Tynkkynen 
593b3cf8d06SJoseph Lo 	if (of_property_read_bool(pdev->dev.of_node, "nvidia,pwm-to-pmic")) {
594b3cf8d06SJoseph Lo 		get_alignment_from_dt(&pdev->dev, &align);
595b3cf8d06SJoseph Lo 	} else {
596b3cf8d06SJoseph Lo 		err = get_alignment_from_regulator(&pdev->dev, &align);
597b3cf8d06SJoseph Lo 		if (err)
598b3cf8d06SJoseph Lo 			return err;
599b3cf8d06SJoseph Lo 	}
600b3cf8d06SJoseph Lo 
601b0dcfb78SPeter De Schrijver 	soc->max_freq = fcpu_data->cpu_max_freq_table[speedo_id];
602f7c42d98SThierry Reding 
603b0dcfb78SPeter De Schrijver 	soc->cvb = tegra_cvb_add_opp_table(soc->dev, fcpu_data->cpu_cvb_tables,
604b0dcfb78SPeter De Schrijver 					   fcpu_data->cpu_cvb_tables_size,
605b3cf8d06SJoseph Lo 					   &align, process_id, speedo_id,
606b3cf8d06SJoseph Lo 					   speedo_value, soc->max_freq);
607b3cf8d06SJoseph Lo 	soc->alignment = align;
608b3cf8d06SJoseph Lo 
60927ed2f7eSThierry Reding 	if (IS_ERR(soc->cvb)) {
61027ed2f7eSThierry Reding 		dev_err(&pdev->dev, "couldn't add OPP table: %ld\n",
61127ed2f7eSThierry Reding 			PTR_ERR(soc->cvb));
61227ed2f7eSThierry Reding 		return PTR_ERR(soc->cvb);
61362a8a094STuomas Tynkkynen 	}
61462a8a094STuomas Tynkkynen 
615f7c42d98SThierry Reding 	err = tegra_dfll_register(pdev, soc);
616f7c42d98SThierry Reding 	if (err < 0) {
617f7c42d98SThierry Reding 		tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
618f7c42d98SThierry Reding 		return err;
619f7c42d98SThierry Reding 	}
62062a8a094STuomas Tynkkynen 
621f7c42d98SThierry Reding 	return 0;
622f7c42d98SThierry Reding }
623f7c42d98SThierry Reding 
624f7c42d98SThierry Reding static int tegra124_dfll_fcpu_remove(struct platform_device *pdev)
625f7c42d98SThierry Reding {
6261752c9eeSNicolin Chen 	struct tegra_dfll_soc_data *soc;
627f7c42d98SThierry Reding 
6281752c9eeSNicolin Chen 	soc = tegra_dfll_unregister(pdev);
6291752c9eeSNicolin Chen 	if (IS_ERR(soc))
6301752c9eeSNicolin Chen 		dev_err(&pdev->dev, "failed to unregister DFLL: %ld\n",
6311752c9eeSNicolin Chen 			PTR_ERR(soc));
632f7c42d98SThierry Reding 
633f7c42d98SThierry Reding 	tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
634f7c42d98SThierry Reding 
635f7c42d98SThierry Reding 	return 0;
63662a8a094STuomas Tynkkynen }
63762a8a094STuomas Tynkkynen 
63862a8a094STuomas Tynkkynen static const struct dev_pm_ops tegra124_dfll_pm_ops = {
63962a8a094STuomas Tynkkynen 	SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend,
64062a8a094STuomas Tynkkynen 			   tegra_dfll_runtime_resume, NULL)
64162a8a094STuomas Tynkkynen };
64262a8a094STuomas Tynkkynen 
64362a8a094STuomas Tynkkynen static struct platform_driver tegra124_dfll_fcpu_driver = {
64462a8a094STuomas Tynkkynen 	.probe = tegra124_dfll_fcpu_probe,
645f7c42d98SThierry Reding 	.remove = tegra124_dfll_fcpu_remove,
64662a8a094STuomas Tynkkynen 	.driver = {
64762a8a094STuomas Tynkkynen 		.name = "tegra124-dfll",
64862a8a094STuomas Tynkkynen 		.of_match_table = tegra124_dfll_fcpu_of_match,
64962a8a094STuomas Tynkkynen 		.pm = &tegra124_dfll_pm_ops,
65062a8a094STuomas Tynkkynen 	},
65162a8a094STuomas Tynkkynen };
6526f877e79SWei Yongjun builtin_platform_driver(tegra124_dfll_fcpu_driver);
653