xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/volt/gm20b.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
171757abfSAlexandre Courbot /*
271757abfSAlexandre Courbot  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
371757abfSAlexandre Courbot  *
471757abfSAlexandre Courbot  * Permission is hereby granted, free of charge, to any person obtaining a
571757abfSAlexandre Courbot  * copy of this software and associated documentation files (the "Software"),
671757abfSAlexandre Courbot  * to deal in the Software without restriction, including without limitation
771757abfSAlexandre Courbot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
871757abfSAlexandre Courbot  * and/or sell copies of the Software, and to permit persons to whom the
971757abfSAlexandre Courbot  * Software is furnished to do so, subject to the following conditions:
1071757abfSAlexandre Courbot  *
1171757abfSAlexandre Courbot  * The above copyright notice and this permission notice shall be included in
1271757abfSAlexandre Courbot  * all copies or substantial portions of the Software.
1371757abfSAlexandre Courbot  *
1471757abfSAlexandre Courbot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1571757abfSAlexandre Courbot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1671757abfSAlexandre Courbot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1771757abfSAlexandre Courbot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1871757abfSAlexandre Courbot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1971757abfSAlexandre Courbot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2071757abfSAlexandre Courbot  * DEALINGS IN THE SOFTWARE.
2171757abfSAlexandre Courbot  */
2271757abfSAlexandre Courbot 
2371757abfSAlexandre Courbot #include "priv.h"
2471757abfSAlexandre Courbot #include "gk20a.h"
2571757abfSAlexandre Courbot 
2671757abfSAlexandre Courbot #include <core/tegra.h>
2771757abfSAlexandre Courbot 
28f3a8b664SBen Skeggs static const struct cvb_coef gm20b_cvb_coef[] = {
2971757abfSAlexandre Courbot 	/* KHz,             c0,      c1,   c2 */
3071757abfSAlexandre Courbot 	/*  76800 */ { 1786666,  -85625, 1632 },
3171757abfSAlexandre Courbot 	/* 153600 */ { 1846729,  -87525, 1632 },
3271757abfSAlexandre Courbot 	/* 230400 */ { 1910480,  -89425, 1632 },
3371757abfSAlexandre Courbot 	/* 307200 */ { 1977920,  -91325, 1632 },
3471757abfSAlexandre Courbot 	/* 384000 */ { 2049049,  -93215, 1632 },
3571757abfSAlexandre Courbot 	/* 460800 */ { 2122872,  -95095, 1632 },
3671757abfSAlexandre Courbot 	/* 537600 */ { 2201331,  -96985, 1632 },
3771757abfSAlexandre Courbot 	/* 614400 */ { 2283479,  -98885, 1632 },
3871757abfSAlexandre Courbot 	/* 691200 */ { 2369315, -100785, 1632 },
3971757abfSAlexandre Courbot 	/* 768000 */ { 2458841, -102685, 1632 },
4071757abfSAlexandre Courbot 	/* 844800 */ { 2550821, -104555, 1632 },
4171757abfSAlexandre Courbot 	/* 921600 */ { 2647676, -106455, 1632 },
4271757abfSAlexandre Courbot };
4371757abfSAlexandre Courbot 
4422b6c9e8SAlexandre Courbot static const struct cvb_coef gm20b_na_cvb_coef[] = {
4522b6c9e8SAlexandre Courbot 	/* KHz,         c0,     c1,   c2,    c3,     c4,   c5 */
4622b6c9e8SAlexandre Courbot 	/*  76800 */ {  814294, 8144, -940, 808, -21583, 226 },
4722b6c9e8SAlexandre Courbot 	/* 153600 */ {  856185, 8144, -940, 808, -21583, 226 },
4822b6c9e8SAlexandre Courbot 	/* 230400 */ {  898077, 8144, -940, 808, -21583, 226 },
4922b6c9e8SAlexandre Courbot 	/* 307200 */ {  939968, 8144, -940, 808, -21583, 226 },
5022b6c9e8SAlexandre Courbot 	/* 384000 */ {  981860, 8144, -940, 808, -21583, 226 },
5122b6c9e8SAlexandre Courbot 	/* 460800 */ { 1023751, 8144, -940, 808, -21583, 226 },
5222b6c9e8SAlexandre Courbot 	/* 537600 */ { 1065642, 8144, -940, 808, -21583, 226 },
5322b6c9e8SAlexandre Courbot 	/* 614400 */ { 1107534, 8144, -940, 808, -21583, 226 },
5422b6c9e8SAlexandre Courbot 	/* 691200 */ { 1149425, 8144, -940, 808, -21583, 226 },
5522b6c9e8SAlexandre Courbot 	/* 768000 */ { 1191317, 8144, -940, 808, -21583, 226 },
5622b6c9e8SAlexandre Courbot 	/* 844800 */ { 1233208, 8144, -940, 808, -21583, 226 },
5722b6c9e8SAlexandre Courbot 	/* 921600 */ { 1275100, 8144, -940, 808, -21583, 226 },
5822b6c9e8SAlexandre Courbot 	/* 998400 */ { 1316991, 8144, -940, 808, -21583, 226 },
5922b6c9e8SAlexandre Courbot };
6022b6c9e8SAlexandre Courbot 
61f3a8b664SBen Skeggs static const u32 speedo_to_vmin[] = {
62791eeea2SAlexandre Courbot 	/*   0,      1,      2,      3,      4, */
63791eeea2SAlexandre Courbot 	950000, 840000, 818750, 840000, 810000,
64791eeea2SAlexandre Courbot };
65791eeea2SAlexandre Courbot 
6671757abfSAlexandre Courbot int
gm20b_volt_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_volt ** pvolt)67*d07be5d7SBen Skeggs gm20b_volt_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
68*d07be5d7SBen Skeggs 	       struct nvkm_volt **pvolt)
6971757abfSAlexandre Courbot {
70791eeea2SAlexandre Courbot 	struct nvkm_device_tegra *tdev = device->func->tegra(device);
7171757abfSAlexandre Courbot 	struct gk20a_volt *volt;
72791eeea2SAlexandre Courbot 	u32 vmin;
73791eeea2SAlexandre Courbot 
74791eeea2SAlexandre Courbot 	if (tdev->gpu_speedo_id >= ARRAY_SIZE(speedo_to_vmin)) {
75791eeea2SAlexandre Courbot 		nvdev_error(device, "unsupported speedo %d\n",
76791eeea2SAlexandre Courbot 			    tdev->gpu_speedo_id);
77791eeea2SAlexandre Courbot 		return -EINVAL;
78791eeea2SAlexandre Courbot 	}
7971757abfSAlexandre Courbot 
8071757abfSAlexandre Courbot 	volt = kzalloc(sizeof(*volt), GFP_KERNEL);
8171757abfSAlexandre Courbot 	if (!volt)
8271757abfSAlexandre Courbot 		return -ENOMEM;
8371757abfSAlexandre Courbot 	*pvolt = &volt->base;
8471757abfSAlexandre Courbot 
85791eeea2SAlexandre Courbot 	vmin = speedo_to_vmin[tdev->gpu_speedo_id];
86791eeea2SAlexandre Courbot 
8722b6c9e8SAlexandre Courbot 	if (tdev->gpu_speedo_id >= 1)
88*d07be5d7SBen Skeggs 		return gk20a_volt_ctor(device, type, inst, gm20b_na_cvb_coef,
8922b6c9e8SAlexandre Courbot 				       ARRAY_SIZE(gm20b_na_cvb_coef), vmin, volt);
9022b6c9e8SAlexandre Courbot 	else
91*d07be5d7SBen Skeggs 		return gk20a_volt_ctor(device, type, inst, gm20b_cvb_coef,
92791eeea2SAlexandre Courbot 				       ARRAY_SIZE(gm20b_cvb_coef), vmin, volt);
9371757abfSAlexandre Courbot }
94