xref: /linux/drivers/clk/tegra/clk-tegra124-dfll-fcpu.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
262a8a094STuomas Tynkkynen /*
362a8a094STuomas Tynkkynen  * Tegra124 DFLL FCPU clock source driver
462a8a094STuomas Tynkkynen  *
5b0dcfb78SPeter De Schrijver  * Copyright (C) 2012-2019 NVIDIA Corporation.  All rights reserved.
662a8a094STuomas Tynkkynen  *
762a8a094STuomas Tynkkynen  * Aleksandr Frid <afrid@nvidia.com>
862a8a094STuomas Tynkkynen  * Paul Walmsley <pwalmsley@nvidia.com>
962a8a094STuomas Tynkkynen  */
1062a8a094STuomas Tynkkynen 
1162a8a094STuomas Tynkkynen #include <linux/cpu.h>
1262a8a094STuomas Tynkkynen #include <linux/err.h>
1362a8a094STuomas Tynkkynen #include <linux/kernel.h>
1433996b02SPaul Gortmaker #include <linux/init.h>
15a96cbb14SRob Herring #include <linux/of.h>
1662a8a094STuomas Tynkkynen #include <linux/platform_device.h>
17b3cf8d06SJoseph Lo #include <linux/regulator/consumer.h>
1862a8a094STuomas Tynkkynen #include <soc/tegra/fuse.h>
1962a8a094STuomas Tynkkynen 
2062a8a094STuomas Tynkkynen #include "clk.h"
2162a8a094STuomas Tynkkynen #include "clk-dfll.h"
2262a8a094STuomas Tynkkynen #include "cvb.h"
2362a8a094STuomas Tynkkynen 
24b0dcfb78SPeter De Schrijver struct dfll_fcpu_data {
25b0dcfb78SPeter De Schrijver 	const unsigned long *cpu_max_freq_table;
26b0dcfb78SPeter De Schrijver 	unsigned int cpu_max_freq_table_size;
27b0dcfb78SPeter De Schrijver 	const struct cvb_table *cpu_cvb_tables;
28b0dcfb78SPeter De Schrijver 	unsigned int cpu_cvb_tables_size;
29b0dcfb78SPeter De Schrijver };
30b0dcfb78SPeter De Schrijver 
3162a8a094STuomas Tynkkynen /* Maximum CPU frequency, indexed by CPU speedo id */
32b0dcfb78SPeter De Schrijver static const unsigned long tegra124_cpu_max_freq_table[] = {
3362a8a094STuomas Tynkkynen 	[0] = 2014500000UL,
3462a8a094STuomas Tynkkynen 	[1] = 2320500000UL,
3562a8a094STuomas Tynkkynen 	[2] = 2116500000UL,
3662a8a094STuomas Tynkkynen 	[3] = 2524500000UL,
3762a8a094STuomas Tynkkynen };
3862a8a094STuomas Tynkkynen 
3962a8a094STuomas Tynkkynen static const struct cvb_table tegra124_cpu_cvb_tables[] = {
4062a8a094STuomas Tynkkynen 	{
4162a8a094STuomas Tynkkynen 		.speedo_id = -1,
4262a8a094STuomas Tynkkynen 		.process_id = -1,
4362a8a094STuomas Tynkkynen 		.min_millivolts = 900,
4462a8a094STuomas Tynkkynen 		.max_millivolts = 1260,
4562a8a094STuomas Tynkkynen 		.speedo_scale = 100,
4662a8a094STuomas Tynkkynen 		.voltage_scale = 1000,
47e8f6a68cSThierry Reding 		.entries = {
4862a8a094STuomas Tynkkynen 			{  204000000UL, { 1112619, -29295, 402 } },
4962a8a094STuomas Tynkkynen 			{  306000000UL, { 1150460, -30585, 402 } },
5062a8a094STuomas Tynkkynen 			{  408000000UL, { 1190122, -31865, 402 } },
5162a8a094STuomas Tynkkynen 			{  510000000UL, { 1231606, -33155, 402 } },
5262a8a094STuomas Tynkkynen 			{  612000000UL, { 1274912, -34435, 402 } },
5362a8a094STuomas Tynkkynen 			{  714000000UL, { 1320040, -35725, 402 } },
5462a8a094STuomas Tynkkynen 			{  816000000UL, { 1366990, -37005, 402 } },
5562a8a094STuomas Tynkkynen 			{  918000000UL, { 1415762, -38295, 402 } },
5662a8a094STuomas Tynkkynen 			{ 1020000000UL, { 1466355, -39575, 402 } },
5762a8a094STuomas Tynkkynen 			{ 1122000000UL, { 1518771, -40865, 402 } },
5862a8a094STuomas Tynkkynen 			{ 1224000000UL, { 1573009, -42145, 402 } },
5962a8a094STuomas Tynkkynen 			{ 1326000000UL, { 1629068, -43435, 402 } },
6062a8a094STuomas Tynkkynen 			{ 1428000000UL, { 1686950, -44715, 402 } },
6162a8a094STuomas Tynkkynen 			{ 1530000000UL, { 1746653, -46005, 402 } },
6262a8a094STuomas Tynkkynen 			{ 1632000000UL, { 1808179, -47285, 402 } },
6362a8a094STuomas Tynkkynen 			{ 1734000000UL, { 1871526, -48575, 402 } },
6462a8a094STuomas Tynkkynen 			{ 1836000000UL, { 1936696, -49855, 402 } },
6562a8a094STuomas Tynkkynen 			{ 1938000000UL, { 2003687, -51145, 402 } },
6662a8a094STuomas Tynkkynen 			{ 2014500000UL, { 2054787, -52095, 402 } },
6762a8a094STuomas Tynkkynen 			{ 2116500000UL, { 2124957, -53385, 402 } },
6862a8a094STuomas Tynkkynen 			{ 2218500000UL, { 2196950, -54665, 402 } },
6962a8a094STuomas Tynkkynen 			{ 2320500000UL, { 2270765, -55955, 402 } },
7062a8a094STuomas Tynkkynen 			{ 2422500000UL, { 2346401, -57235, 402 } },
7162a8a094STuomas Tynkkynen 			{ 2524500000UL, { 2437299, -58535, 402 } },
722690e912SThierry Reding 			{          0UL, {       0,      0,   0 } },
7362a8a094STuomas Tynkkynen 		},
7462a8a094STuomas Tynkkynen 		.cpu_dfll_data = {
7562a8a094STuomas Tynkkynen 			.tune0_low = 0x005020ff,
7662a8a094STuomas Tynkkynen 			.tune0_high = 0x005040ff,
7762a8a094STuomas Tynkkynen 			.tune1 = 0x00000060,
7862a8a094STuomas Tynkkynen 		}
7962a8a094STuomas Tynkkynen 	},
8062a8a094STuomas Tynkkynen };
8162a8a094STuomas Tynkkynen 
822b2dbc2fSJoseph Lo static const unsigned long tegra210_cpu_max_freq_table[] = {
832b2dbc2fSJoseph Lo 	[0] = 1912500000UL,
842b2dbc2fSJoseph Lo 	[1] = 1912500000UL,
852b2dbc2fSJoseph Lo 	[2] = 2218500000UL,
862b2dbc2fSJoseph Lo 	[3] = 1785000000UL,
872b2dbc2fSJoseph Lo 	[4] = 1632000000UL,
882b2dbc2fSJoseph Lo 	[5] = 1912500000UL,
892b2dbc2fSJoseph Lo 	[6] = 2014500000UL,
902b2dbc2fSJoseph Lo 	[7] = 1734000000UL,
912b2dbc2fSJoseph Lo 	[8] = 1683000000UL,
922b2dbc2fSJoseph Lo 	[9] = 1555500000UL,
932b2dbc2fSJoseph Lo 	[10] = 1504500000UL,
942b2dbc2fSJoseph Lo };
952b2dbc2fSJoseph Lo 
962b2dbc2fSJoseph Lo #define CPU_CVB_TABLE \
972b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
982b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
992b2dbc2fSJoseph Lo 	.entries = {		\
1002b2dbc2fSJoseph Lo 		{  204000000UL,	{ 1007452, -23865, 370 } }, \
1012b2dbc2fSJoseph Lo 		{  306000000UL,	{ 1052709, -24875, 370 } }, \
1022b2dbc2fSJoseph Lo 		{  408000000UL,	{ 1099069, -25895, 370 } }, \
1032b2dbc2fSJoseph Lo 		{  510000000UL,	{ 1146534, -26905, 370 } }, \
1042b2dbc2fSJoseph Lo 		{  612000000UL,	{ 1195102, -27915, 370 } }, \
1052b2dbc2fSJoseph Lo 		{  714000000UL,	{ 1244773, -28925, 370 } }, \
1062b2dbc2fSJoseph Lo 		{  816000000UL,	{ 1295549, -29935, 370 } }, \
1072b2dbc2fSJoseph Lo 		{  918000000UL,	{ 1347428, -30955, 370 } }, \
1082b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1400411, -31965, 370 } }, \
1092b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1454497, -32975, 370 } }, \
1102b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1509687, -33985, 370 } }, \
1112b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1565981, -35005, 370 } }, \
1122b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1623379, -36015, 370 } }, \
1132b2dbc2fSJoseph Lo 		{ 1530000000UL,	{ 1681880, -37025, 370 } }, \
1142b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 1741485, -38035, 370 } }, \
1152b2dbc2fSJoseph Lo 		{ 1734000000UL,	{ 1802194, -39055, 370 } }, \
1162b2dbc2fSJoseph Lo 		{ 1836000000UL,	{ 1864006, -40065, 370 } }, \
1172b2dbc2fSJoseph Lo 		{ 1912500000UL,	{ 1910780, -40815, 370 } }, \
1182b2dbc2fSJoseph Lo 		{ 2014500000UL,	{ 1227000,      0,   0 } }, \
1192b2dbc2fSJoseph Lo 		{ 2218500000UL,	{ 1227000,      0,   0 } }, \
1202b2dbc2fSJoseph Lo 		{          0UL,	{       0,      0,   0 } }, \
1212b2dbc2fSJoseph Lo 	}
1222b2dbc2fSJoseph Lo 
1232b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_XA \
1242b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
1252b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
1262b2dbc2fSJoseph Lo 	.entries = {		\
1272b2dbc2fSJoseph Lo 		{  204000000UL,	{ 1250024, -39785, 565 } }, \
1282b2dbc2fSJoseph Lo 		{  306000000UL,	{ 1297556, -41145, 565 } }, \
1292b2dbc2fSJoseph Lo 		{  408000000UL,	{ 1346718, -42505, 565 } }, \
1302b2dbc2fSJoseph Lo 		{  510000000UL,	{ 1397511, -43855, 565 } }, \
1312b2dbc2fSJoseph Lo 		{  612000000UL,	{ 1449933, -45215, 565 } }, \
1322b2dbc2fSJoseph Lo 		{  714000000UL,	{ 1503986, -46575, 565 } }, \
1332b2dbc2fSJoseph Lo 		{  816000000UL,	{ 1559669, -47935, 565 } }, \
1342b2dbc2fSJoseph Lo 		{  918000000UL,	{ 1616982, -49295, 565 } }, \
1352b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1675926, -50645, 565 } }, \
1362b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1736500, -52005, 565 } }, \
1372b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1798704, -53365, 565 } }, \
1382b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1862538, -54725, 565 } }, \
1392b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1928003, -56085, 565 } }, \
1402b2dbc2fSJoseph Lo 		{ 1530000000UL,	{ 1995097, -57435, 565 } }, \
1412b2dbc2fSJoseph Lo 		{ 1606500000UL,	{ 2046149, -58445, 565 } }, \
1422b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 2063822, -58795, 565 } }, \
1432b2dbc2fSJoseph Lo 		{          0UL,	{       0,      0,   0 } }, \
1442b2dbc2fSJoseph Lo 	}
1452b2dbc2fSJoseph Lo 
1462b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM1 \
1472b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
1482b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
1492b2dbc2fSJoseph Lo 	.entries = {		\
1502b2dbc2fSJoseph Lo 		{  204000000UL,	{  734429, 0, 0 } }, \
1512b2dbc2fSJoseph Lo 		{  306000000UL,	{  768191, 0, 0 } }, \
1522b2dbc2fSJoseph Lo 		{  408000000UL,	{  801953, 0, 0 } }, \
1532b2dbc2fSJoseph Lo 		{  510000000UL,	{  835715, 0, 0 } }, \
1542b2dbc2fSJoseph Lo 		{  612000000UL,	{  869477, 0, 0 } }, \
1552b2dbc2fSJoseph Lo 		{  714000000UL,	{  903239, 0, 0 } }, \
1562b2dbc2fSJoseph Lo 		{  816000000UL,	{  937001, 0, 0 } }, \
1572b2dbc2fSJoseph Lo 		{  918000000UL,	{  970763, 0, 0 } }, \
1582b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1004525, 0, 0 } }, \
1592b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1038287, 0, 0 } }, \
1602b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1072049, 0, 0 } }, \
1612b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1105811, 0, 0 } }, \
1622b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1130000, 0, 0 } }, \
1632b2dbc2fSJoseph Lo 		{ 1555500000UL,	{ 1130000, 0, 0 } }, \
1642b2dbc2fSJoseph Lo 		{ 1632000000UL,	{ 1170000, 0, 0 } }, \
1652b2dbc2fSJoseph Lo 		{ 1734000000UL,	{ 1227500, 0, 0 } }, \
1662b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
1672b2dbc2fSJoseph Lo 	}
1682b2dbc2fSJoseph Lo 
1692b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM2 \
1702b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
1712b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
1722b2dbc2fSJoseph Lo 	.entries = {		\
1732b2dbc2fSJoseph Lo 		{  204000000UL,	{  742283, 0, 0 } }, \
1742b2dbc2fSJoseph Lo 		{  306000000UL,	{  776249, 0, 0 } }, \
1752b2dbc2fSJoseph Lo 		{  408000000UL,	{  810215, 0, 0 } }, \
1762b2dbc2fSJoseph Lo 		{  510000000UL,	{  844181, 0, 0 } }, \
1772b2dbc2fSJoseph Lo 		{  612000000UL,	{  878147, 0, 0 } }, \
1782b2dbc2fSJoseph Lo 		{  714000000UL,	{  912113, 0, 0 } }, \
1792b2dbc2fSJoseph Lo 		{  816000000UL,	{  946079, 0, 0 } }, \
1802b2dbc2fSJoseph Lo 		{  918000000UL,	{  980045, 0, 0 } }, \
1812b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1014011, 0, 0 } }, \
1822b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1047977, 0, 0 } }, \
1832b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1081943, 0, 0 } }, \
1842b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1090000, 0, 0 } }, \
1852b2dbc2fSJoseph Lo 		{ 1479000000UL,	{ 1090000, 0, 0 } }, \
1862b2dbc2fSJoseph Lo 		{ 1555500000UL,	{ 1162000, 0, 0 } }, \
1872b2dbc2fSJoseph Lo 		{ 1683000000UL,	{ 1195000, 0, 0 } }, \
1882b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
1892b2dbc2fSJoseph Lo 	}
1902b2dbc2fSJoseph Lo 
1912b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_EUCM2_JOINT_RAIL \
1922b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
1932b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
1942b2dbc2fSJoseph Lo 	.entries = {		\
1952b2dbc2fSJoseph Lo 		{  204000000UL,	{  742283, 0, 0 } }, \
1962b2dbc2fSJoseph Lo 		{  306000000UL,	{  776249, 0, 0 } }, \
1972b2dbc2fSJoseph Lo 		{  408000000UL,	{  810215, 0, 0 } }, \
1982b2dbc2fSJoseph Lo 		{  510000000UL,	{  844181, 0, 0 } }, \
1992b2dbc2fSJoseph Lo 		{  612000000UL,	{  878147, 0, 0 } }, \
2002b2dbc2fSJoseph Lo 		{  714000000UL,	{  912113, 0, 0 } }, \
2012b2dbc2fSJoseph Lo 		{  816000000UL,	{  946079, 0, 0 } }, \
2022b2dbc2fSJoseph Lo 		{  918000000UL,	{  980045, 0, 0 } }, \
2032b2dbc2fSJoseph Lo 		{ 1020000000UL,	{ 1014011, 0, 0 } }, \
2042b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1047977, 0, 0 } }, \
2052b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1081943, 0, 0 } }, \
2062b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1090000, 0, 0 } }, \
2072b2dbc2fSJoseph Lo 		{ 1479000000UL,	{ 1090000, 0, 0 } }, \
2082b2dbc2fSJoseph Lo 		{ 1504500000UL,	{ 1120000, 0, 0 } }, \
2092b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
2102b2dbc2fSJoseph Lo 	}
2112b2dbc2fSJoseph Lo 
2122b2dbc2fSJoseph Lo #define CPU_CVB_TABLE_ODN \
2132b2dbc2fSJoseph Lo 	.speedo_scale = 100,	\
2142b2dbc2fSJoseph Lo 	.voltage_scale = 1000,	\
2152b2dbc2fSJoseph Lo 	.entries = {		\
2162b2dbc2fSJoseph Lo 		{  204000000UL,	{  721094, 0, 0 } }, \
2172b2dbc2fSJoseph Lo 		{  306000000UL,	{  754040, 0, 0 } }, \
2182b2dbc2fSJoseph Lo 		{  408000000UL,	{  786986, 0, 0 } }, \
2192b2dbc2fSJoseph Lo 		{  510000000UL,	{  819932, 0, 0 } }, \
2202b2dbc2fSJoseph Lo 		{  612000000UL,	{  852878, 0, 0 } }, \
2212b2dbc2fSJoseph Lo 		{  714000000UL,	{  885824, 0, 0 } }, \
2222b2dbc2fSJoseph Lo 		{  816000000UL,	{  918770, 0, 0 } }, \
2232b2dbc2fSJoseph Lo 		{  918000000UL,	{  915716, 0, 0 } }, \
2242b2dbc2fSJoseph Lo 		{ 1020000000UL,	{  984662, 0, 0 } }, \
2252b2dbc2fSJoseph Lo 		{ 1122000000UL,	{ 1017608, 0, 0 } }, \
2262b2dbc2fSJoseph Lo 		{ 1224000000UL,	{ 1050554, 0, 0 } }, \
2272b2dbc2fSJoseph Lo 		{ 1326000000UL,	{ 1083500, 0, 0 } }, \
2282b2dbc2fSJoseph Lo 		{ 1428000000UL,	{ 1116446, 0, 0 } }, \
2292b2dbc2fSJoseph Lo 		{ 1581000000UL,	{ 1130000, 0, 0 } }, \
2302b2dbc2fSJoseph Lo 		{ 1683000000UL,	{ 1168000, 0, 0 } }, \
2312b2dbc2fSJoseph Lo 		{ 1785000000UL,	{ 1227500, 0, 0 } }, \
2322b2dbc2fSJoseph Lo 		{          0UL,	{       0, 0, 0 } }, \
2332b2dbc2fSJoseph Lo 	}
2342b2dbc2fSJoseph Lo 
235bb872709SWei Yongjun static struct cvb_table tegra210_cpu_cvb_tables[] = {
2362b2dbc2fSJoseph Lo 	{
2372b2dbc2fSJoseph Lo 		.speedo_id = 10,
2382b2dbc2fSJoseph Lo 		.process_id = 0,
2392b2dbc2fSJoseph Lo 		.min_millivolts = 840,
2402b2dbc2fSJoseph Lo 		.max_millivolts = 1120,
2412b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2_JOINT_RAIL,
2422b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
2432b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
2442b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
2452b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
2462b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
2472b2dbc2fSJoseph Lo 		}
2482b2dbc2fSJoseph Lo 	},
2492b2dbc2fSJoseph Lo 	{
2502b2dbc2fSJoseph Lo 		.speedo_id = 10,
2512b2dbc2fSJoseph Lo 		.process_id = 1,
2522b2dbc2fSJoseph Lo 		.min_millivolts = 840,
2532b2dbc2fSJoseph Lo 		.max_millivolts = 1120,
2542b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2_JOINT_RAIL,
2552b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
2562b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
2572b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
2582b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
2592b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
2602b2dbc2fSJoseph Lo 		}
2612b2dbc2fSJoseph Lo 	},
2622b2dbc2fSJoseph Lo 	{
2632b2dbc2fSJoseph Lo 		.speedo_id = 9,
2642b2dbc2fSJoseph Lo 		.process_id = 0,
2652b2dbc2fSJoseph Lo 		.min_millivolts = 900,
2662b2dbc2fSJoseph Lo 		.max_millivolts = 1162,
2672b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
2682b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
2692b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
2702b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
2712b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
2722b2dbc2fSJoseph Lo 		}
2732b2dbc2fSJoseph Lo 	},
2742b2dbc2fSJoseph Lo 	{
2752b2dbc2fSJoseph Lo 		.speedo_id = 9,
2762b2dbc2fSJoseph Lo 		.process_id = 1,
2772b2dbc2fSJoseph Lo 		.min_millivolts = 900,
2782b2dbc2fSJoseph Lo 		.max_millivolts = 1162,
2792b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
2802b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
2812b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
2822b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
2832b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
2842b2dbc2fSJoseph Lo 		}
2852b2dbc2fSJoseph Lo 	},
2862b2dbc2fSJoseph Lo 	{
2872b2dbc2fSJoseph Lo 		.speedo_id = 8,
2882b2dbc2fSJoseph Lo 		.process_id = 0,
2892b2dbc2fSJoseph Lo 		.min_millivolts = 900,
2902b2dbc2fSJoseph Lo 		.max_millivolts = 1195,
2912b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
2922b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
2932b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
2942b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
2952b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
2962b2dbc2fSJoseph Lo 		}
2972b2dbc2fSJoseph Lo 	},
2982b2dbc2fSJoseph Lo 	{
2992b2dbc2fSJoseph Lo 		.speedo_id = 8,
3002b2dbc2fSJoseph Lo 		.process_id = 1,
3012b2dbc2fSJoseph Lo 		.min_millivolts = 900,
3022b2dbc2fSJoseph Lo 		.max_millivolts = 1195,
3032b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM2,
3042b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3052b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3062b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
3072b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
3082b2dbc2fSJoseph Lo 		}
3092b2dbc2fSJoseph Lo 	},
3102b2dbc2fSJoseph Lo 	{
3112b2dbc2fSJoseph Lo 		.speedo_id = 7,
3122b2dbc2fSJoseph Lo 		.process_id = 0,
3132b2dbc2fSJoseph Lo 		.min_millivolts = 841,
3142b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
3152b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM1,
3162b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3172b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3182b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
3192b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
3202b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
3212b2dbc2fSJoseph Lo 		}
3222b2dbc2fSJoseph Lo 	},
3232b2dbc2fSJoseph Lo 	{
3242b2dbc2fSJoseph Lo 		.speedo_id = 7,
3252b2dbc2fSJoseph Lo 		.process_id = 1,
3262b2dbc2fSJoseph Lo 		.min_millivolts = 841,
3272b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
3282b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_EUCM1,
3292b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3302b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3312b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
3322b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
3332b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
3342b2dbc2fSJoseph Lo 		}
3352b2dbc2fSJoseph Lo 	},
3362b2dbc2fSJoseph Lo 	{
3372b2dbc2fSJoseph Lo 		.speedo_id = 6,
3382b2dbc2fSJoseph Lo 		.process_id = 0,
3392b2dbc2fSJoseph Lo 		.min_millivolts = 870,
3402b2dbc2fSJoseph Lo 		.max_millivolts = 1150,
3412b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
3422b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3432b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3442b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
3452b2dbc2fSJoseph Lo 		}
3462b2dbc2fSJoseph Lo 	},
3472b2dbc2fSJoseph Lo 	{
3482b2dbc2fSJoseph Lo 		.speedo_id = 6,
3492b2dbc2fSJoseph Lo 		.process_id = 1,
3502b2dbc2fSJoseph Lo 		.min_millivolts = 870,
3512b2dbc2fSJoseph Lo 		.max_millivolts = 1150,
3522b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
3532b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3542b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3552b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
3562b2dbc2fSJoseph Lo 		}
3572b2dbc2fSJoseph Lo 	},
3582b2dbc2fSJoseph Lo 	{
3592b2dbc2fSJoseph Lo 		.speedo_id = 5,
3602b2dbc2fSJoseph Lo 		.process_id = 0,
3612b2dbc2fSJoseph Lo 		.min_millivolts = 818,
3622b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
3632b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
3642b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3652b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3662b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
3672b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
3682b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
3692b2dbc2fSJoseph Lo 		}
3702b2dbc2fSJoseph Lo 	},
3712b2dbc2fSJoseph Lo 	{
3722b2dbc2fSJoseph Lo 		.speedo_id = 5,
3732b2dbc2fSJoseph Lo 		.process_id = 1,
3742b2dbc2fSJoseph Lo 		.min_millivolts = 818,
3752b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
3762b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
3772b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3782b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3792b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
3802b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
3812b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
3822b2dbc2fSJoseph Lo 		}
3832b2dbc2fSJoseph Lo 	},
3842b2dbc2fSJoseph Lo 	{
3852b2dbc2fSJoseph Lo 		.speedo_id = 4,
3862b2dbc2fSJoseph Lo 		.process_id = -1,
3872b2dbc2fSJoseph Lo 		.min_millivolts = 918,
3882b2dbc2fSJoseph Lo 		.max_millivolts = 1113,
3892b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_XA,
3902b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
3912b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
3922b2dbc2fSJoseph Lo 			.tune1 = 0x17711BD,
3932b2dbc2fSJoseph Lo 		}
3942b2dbc2fSJoseph Lo 	},
3952b2dbc2fSJoseph Lo 	{
3962b2dbc2fSJoseph Lo 		.speedo_id = 3,
3972b2dbc2fSJoseph Lo 		.process_id = 0,
3982b2dbc2fSJoseph Lo 		.min_millivolts = 825,
3992b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4002b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_ODN,
4012b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4022b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4032b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4042b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
4052b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4062b2dbc2fSJoseph Lo 		}
4072b2dbc2fSJoseph Lo 	},
4082b2dbc2fSJoseph Lo 	{
4092b2dbc2fSJoseph Lo 		.speedo_id = 3,
4102b2dbc2fSJoseph Lo 		.process_id = 1,
4112b2dbc2fSJoseph Lo 		.min_millivolts = 825,
4122b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4132b2dbc2fSJoseph Lo 		CPU_CVB_TABLE_ODN,
4142b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4152b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4162b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4172b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
4182b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4192b2dbc2fSJoseph Lo 		}
4202b2dbc2fSJoseph Lo 	},
4212b2dbc2fSJoseph Lo 	{
4222b2dbc2fSJoseph Lo 		.speedo_id = 2,
4232b2dbc2fSJoseph Lo 		.process_id = 0,
4242b2dbc2fSJoseph Lo 		.min_millivolts = 870,
4252b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4262b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4272b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4282b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4292b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
4302b2dbc2fSJoseph Lo 		}
4312b2dbc2fSJoseph Lo 	},
4322b2dbc2fSJoseph Lo 	{
4332b2dbc2fSJoseph Lo 		.speedo_id = 2,
4342b2dbc2fSJoseph Lo 		.process_id = 1,
4352b2dbc2fSJoseph Lo 		.min_millivolts = 870,
4362b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4372b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4382b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4392b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4402b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
4412b2dbc2fSJoseph Lo 		}
4422b2dbc2fSJoseph Lo 	},
4432b2dbc2fSJoseph Lo 	{
4442b2dbc2fSJoseph Lo 		.speedo_id = 1,
4452b2dbc2fSJoseph Lo 		.process_id = 0,
4462b2dbc2fSJoseph Lo 		.min_millivolts = 837,
4472b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4482b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4492b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4502b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4512b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4522b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
4532b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4542b2dbc2fSJoseph Lo 		}
4552b2dbc2fSJoseph Lo 	},
4562b2dbc2fSJoseph Lo 	{
4572b2dbc2fSJoseph Lo 		.speedo_id = 1,
4582b2dbc2fSJoseph Lo 		.process_id = 1,
4592b2dbc2fSJoseph Lo 		.min_millivolts = 837,
4602b2dbc2fSJoseph Lo 		.max_millivolts = 1227,
4612b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4622b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4632b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4642b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4652b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
4662b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4672b2dbc2fSJoseph Lo 		}
4682b2dbc2fSJoseph Lo 	},
4692b2dbc2fSJoseph Lo 	{
4702b2dbc2fSJoseph Lo 		.speedo_id = 0,
4712b2dbc2fSJoseph Lo 		.process_id = 0,
4722b2dbc2fSJoseph Lo 		.min_millivolts = 850,
4732b2dbc2fSJoseph Lo 		.max_millivolts = 1170,
4742b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4752b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4762b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4772b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4782b2dbc2fSJoseph Lo 			.tune1 = 0x20091d9,
4792b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4802b2dbc2fSJoseph Lo 		}
4812b2dbc2fSJoseph Lo 	},
4822b2dbc2fSJoseph Lo 	{
4832b2dbc2fSJoseph Lo 		.speedo_id = 0,
4842b2dbc2fSJoseph Lo 		.process_id = 1,
4852b2dbc2fSJoseph Lo 		.min_millivolts = 850,
4862b2dbc2fSJoseph Lo 		.max_millivolts = 1170,
4872b2dbc2fSJoseph Lo 		CPU_CVB_TABLE,
4882b2dbc2fSJoseph Lo 		.cpu_dfll_data = {
4892b2dbc2fSJoseph Lo 			.tune0_low = 0xffead0ff,
4902b2dbc2fSJoseph Lo 			.tune0_high = 0xffead0ff,
4912b2dbc2fSJoseph Lo 			.tune1 = 0x25501d0,
4922b2dbc2fSJoseph Lo 			.tune_high_min_millivolts = 864,
4932b2dbc2fSJoseph Lo 		}
4942b2dbc2fSJoseph Lo 	},
4952b2dbc2fSJoseph Lo };
4962b2dbc2fSJoseph Lo 
497b0dcfb78SPeter De Schrijver static const struct dfll_fcpu_data tegra124_dfll_fcpu_data = {
498b0dcfb78SPeter De Schrijver 	.cpu_max_freq_table = tegra124_cpu_max_freq_table,
499b0dcfb78SPeter De Schrijver 	.cpu_max_freq_table_size = ARRAY_SIZE(tegra124_cpu_max_freq_table),
500b0dcfb78SPeter De Schrijver 	.cpu_cvb_tables = tegra124_cpu_cvb_tables,
501b0dcfb78SPeter De Schrijver 	.cpu_cvb_tables_size = ARRAY_SIZE(tegra124_cpu_cvb_tables)
502b0dcfb78SPeter De Schrijver };
503b0dcfb78SPeter De Schrijver 
5042b2dbc2fSJoseph Lo static const struct dfll_fcpu_data tegra210_dfll_fcpu_data = {
5052b2dbc2fSJoseph Lo 	.cpu_max_freq_table = tegra210_cpu_max_freq_table,
5062b2dbc2fSJoseph Lo 	.cpu_max_freq_table_size = ARRAY_SIZE(tegra210_cpu_max_freq_table),
5072b2dbc2fSJoseph Lo 	.cpu_cvb_tables = tegra210_cpu_cvb_tables,
5082b2dbc2fSJoseph Lo 	.cpu_cvb_tables_size = ARRAY_SIZE(tegra210_cpu_cvb_tables),
5092b2dbc2fSJoseph Lo };
5102b2dbc2fSJoseph Lo 
511b0dcfb78SPeter De Schrijver static const struct of_device_id tegra124_dfll_fcpu_of_match[] = {
512b0dcfb78SPeter De Schrijver 	{
513b0dcfb78SPeter De Schrijver 		.compatible = "nvidia,tegra124-dfll",
514b0dcfb78SPeter De Schrijver 		.data = &tegra124_dfll_fcpu_data,
515b0dcfb78SPeter De Schrijver 	},
5162b2dbc2fSJoseph Lo 	{
5172b2dbc2fSJoseph Lo 		.compatible = "nvidia,tegra210-dfll",
5182b2dbc2fSJoseph Lo 		.data = &tegra210_dfll_fcpu_data
5192b2dbc2fSJoseph Lo 	},
520b0dcfb78SPeter De Schrijver 	{ },
521b0dcfb78SPeter De Schrijver };
522b0dcfb78SPeter De Schrijver 
get_alignment_from_dt(struct device * dev,struct rail_alignment * align)523b3cf8d06SJoseph Lo static void get_alignment_from_dt(struct device *dev,
524b3cf8d06SJoseph Lo 				  struct rail_alignment *align)
525b3cf8d06SJoseph Lo {
526b3cf8d06SJoseph Lo 	if (of_property_read_u32(dev->of_node,
527b3cf8d06SJoseph Lo 				 "nvidia,pwm-voltage-step-microvolts",
528b3cf8d06SJoseph Lo 				 &align->step_uv))
529b3cf8d06SJoseph Lo 		align->step_uv = 0;
530b3cf8d06SJoseph Lo 
531b3cf8d06SJoseph Lo 	if (of_property_read_u32(dev->of_node,
532b3cf8d06SJoseph Lo 				 "nvidia,pwm-min-microvolts",
533b3cf8d06SJoseph Lo 				 &align->offset_uv))
534b3cf8d06SJoseph Lo 		align->offset_uv = 0;
535b3cf8d06SJoseph Lo }
536b3cf8d06SJoseph Lo 
get_alignment_from_regulator(struct device * dev,struct rail_alignment * align)537b3cf8d06SJoseph Lo static int get_alignment_from_regulator(struct device *dev,
538b3cf8d06SJoseph Lo 					 struct rail_alignment *align)
539b3cf8d06SJoseph Lo {
5402f0d67bfSAlexandru Ardelean 	struct regulator *reg = regulator_get(dev, "vdd-cpu");
541b3cf8d06SJoseph Lo 
542b3cf8d06SJoseph Lo 	if (IS_ERR(reg))
543b3cf8d06SJoseph Lo 		return PTR_ERR(reg);
544b3cf8d06SJoseph Lo 
545b3cf8d06SJoseph Lo 	align->offset_uv = regulator_list_voltage(reg, 0);
546b3cf8d06SJoseph Lo 	align->step_uv = regulator_get_linear_step(reg);
547b3cf8d06SJoseph Lo 
5482f0d67bfSAlexandru Ardelean 	regulator_put(reg);
549b3cf8d06SJoseph Lo 
550b3cf8d06SJoseph Lo 	return 0;
551b3cf8d06SJoseph Lo }
552b3cf8d06SJoseph Lo 
tegra124_dfll_fcpu_probe(struct platform_device * pdev)55362a8a094STuomas Tynkkynen static int tegra124_dfll_fcpu_probe(struct platform_device *pdev)
55462a8a094STuomas Tynkkynen {
555f7c42d98SThierry Reding 	int process_id, speedo_id, speedo_value, err;
55662a8a094STuomas Tynkkynen 	struct tegra_dfll_soc_data *soc;
557b0dcfb78SPeter De Schrijver 	const struct dfll_fcpu_data *fcpu_data;
558b3cf8d06SJoseph Lo 	struct rail_alignment align;
559b0dcfb78SPeter De Schrijver 
560b0dcfb78SPeter De Schrijver 	fcpu_data = of_device_get_match_data(&pdev->dev);
561b0dcfb78SPeter De Schrijver 	if (!fcpu_data)
562b0dcfb78SPeter De Schrijver 		return -ENODEV;
56362a8a094STuomas Tynkkynen 
56462a8a094STuomas Tynkkynen 	process_id = tegra_sku_info.cpu_process_id;
56562a8a094STuomas Tynkkynen 	speedo_id = tegra_sku_info.cpu_speedo_id;
56662a8a094STuomas Tynkkynen 	speedo_value = tegra_sku_info.cpu_speedo_value;
56762a8a094STuomas Tynkkynen 
568b0dcfb78SPeter De Schrijver 	if (speedo_id >= fcpu_data->cpu_max_freq_table_size) {
56962a8a094STuomas Tynkkynen 		dev_err(&pdev->dev, "unknown max CPU freq for speedo_id=%d\n",
57062a8a094STuomas Tynkkynen 			speedo_id);
57162a8a094STuomas Tynkkynen 		return -ENODEV;
57262a8a094STuomas Tynkkynen 	}
57362a8a094STuomas Tynkkynen 
57462a8a094STuomas Tynkkynen 	soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL);
57562a8a094STuomas Tynkkynen 	if (!soc)
57662a8a094STuomas Tynkkynen 		return -ENOMEM;
57762a8a094STuomas Tynkkynen 
57862a8a094STuomas Tynkkynen 	soc->dev = get_cpu_device(0);
57962a8a094STuomas Tynkkynen 	if (!soc->dev) {
58062a8a094STuomas Tynkkynen 		dev_err(&pdev->dev, "no CPU0 device\n");
58162a8a094STuomas Tynkkynen 		return -ENODEV;
58262a8a094STuomas Tynkkynen 	}
58362a8a094STuomas Tynkkynen 
584b3cf8d06SJoseph Lo 	if (of_property_read_bool(pdev->dev.of_node, "nvidia,pwm-to-pmic")) {
585b3cf8d06SJoseph Lo 		get_alignment_from_dt(&pdev->dev, &align);
586b3cf8d06SJoseph Lo 	} else {
587b3cf8d06SJoseph Lo 		err = get_alignment_from_regulator(&pdev->dev, &align);
588b3cf8d06SJoseph Lo 		if (err)
589b3cf8d06SJoseph Lo 			return err;
590b3cf8d06SJoseph Lo 	}
591f7c42d98SThierry Reding 
592b0dcfb78SPeter De Schrijver 	soc->max_freq = fcpu_data->cpu_max_freq_table[speedo_id];
59362a8a094STuomas Tynkkynen 
594b0dcfb78SPeter De Schrijver 	soc->cvb = tegra_cvb_add_opp_table(soc->dev, fcpu_data->cpu_cvb_tables,
595b0dcfb78SPeter De Schrijver 					   fcpu_data->cpu_cvb_tables_size,
596b3cf8d06SJoseph Lo 					   &align, process_id, speedo_id,
597b3cf8d06SJoseph Lo 					   speedo_value, soc->max_freq);
598b3cf8d06SJoseph Lo 	soc->alignment = align;
599b3cf8d06SJoseph Lo 
60027ed2f7eSThierry Reding 	if (IS_ERR(soc->cvb)) {
60127ed2f7eSThierry Reding 		dev_err(&pdev->dev, "couldn't add OPP table: %ld\n",
60227ed2f7eSThierry Reding 			PTR_ERR(soc->cvb));
60327ed2f7eSThierry Reding 		return PTR_ERR(soc->cvb);
60462a8a094STuomas Tynkkynen 	}
60562a8a094STuomas Tynkkynen 
606f7c42d98SThierry Reding 	err = tegra_dfll_register(pdev, soc);
607f7c42d98SThierry Reding 	if (err < 0) {
608f7c42d98SThierry Reding 		tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
609f7c42d98SThierry Reding 		return err;
610f7c42d98SThierry Reding 	}
61162a8a094STuomas Tynkkynen 
612f7c42d98SThierry Reding 	return 0;
613f7c42d98SThierry Reding }
614f7c42d98SThierry Reding 
tegra124_dfll_fcpu_remove(struct platform_device * pdev)6153fd43a2cSUwe Kleine-König static void tegra124_dfll_fcpu_remove(struct platform_device *pdev)
616f7c42d98SThierry Reding {
6171752c9eeSNicolin Chen 	struct tegra_dfll_soc_data *soc;
618f7c42d98SThierry Reding 
619c73e435eSUwe Kleine-König 	/*
620c73e435eSUwe Kleine-König 	 * Note that exiting early here is dangerous as after this function
621c73e435eSUwe Kleine-König 	 * returns *soc is freed.
622c73e435eSUwe Kleine-König 	 */
6231752c9eeSNicolin Chen 	soc = tegra_dfll_unregister(pdev);
624c73e435eSUwe Kleine-König 	if (IS_ERR(soc))
6253fd43a2cSUwe Kleine-König 		return;
626f7c42d98SThierry Reding 
627f7c42d98SThierry Reding 	tegra_cvb_remove_opp_table(soc->dev, soc->cvb, soc->max_freq);
62862a8a094STuomas Tynkkynen }
62962a8a094STuomas Tynkkynen 
63062a8a094STuomas Tynkkynen static const struct dev_pm_ops tegra124_dfll_pm_ops = {
63162a8a094STuomas Tynkkynen 	SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend,
63262a8a094STuomas Tynkkynen 			   tegra_dfll_runtime_resume, NULL)
633a99d744dSSowjanya Komatineni 	SET_SYSTEM_SLEEP_PM_OPS(tegra_dfll_suspend, tegra_dfll_resume)
63462a8a094STuomas Tynkkynen };
63562a8a094STuomas Tynkkynen 
63662a8a094STuomas Tynkkynen static struct platform_driver tegra124_dfll_fcpu_driver = {
63762a8a094STuomas Tynkkynen 	.probe = tegra124_dfll_fcpu_probe,
638*f00b45dbSUwe Kleine-König 	.remove = tegra124_dfll_fcpu_remove,
63962a8a094STuomas Tynkkynen 	.driver = {
64062a8a094STuomas Tynkkynen 		.name = "tegra124-dfll",
64162a8a094STuomas Tynkkynen 		.of_match_table = tegra124_dfll_fcpu_of_match,
64262a8a094STuomas Tynkkynen 		.pm = &tegra124_dfll_pm_ops,
64362a8a094STuomas Tynkkynen 	},
64462a8a094STuomas Tynkkynen };
6456f877e79SWei Yongjun builtin_platform_driver(tegra124_dfll_fcpu_driver);
646