Home | History | Annotate | Line # | Download | only in therm
      1 /*	$NetBSD: nouveau_nvkm_subdev_therm_gt215.c,v 1.4 2021/12/19 10:51:59 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2012 Red Hat Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: Ben Skeggs
     25  */
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_therm_gt215.c,v 1.4 2021/12/19 10:51:59 riastradh Exp $");
     28 
     29 #include "priv.h"
     30 
     31 #include <subdev/gpio.h>
     32 
     33 int
     34 gt215_therm_fan_sense(struct nvkm_therm *therm)
     35 {
     36 	struct nvkm_device *device = therm->subdev.device;
     37 	u32 tach = nvkm_rd32(device, 0x00e728) & 0x0000ffff;
     38 	u32 ctrl = nvkm_rd32(device, 0x00e720);
     39 	if (ctrl & 0x00000001)
     40 		return tach * 60 / 2;
     41 	return -ENODEV;
     42 }
     43 
     44 static void
     45 gt215_therm_init(struct nvkm_therm *therm)
     46 {
     47 	struct nvkm_device *device = therm->subdev.device;
     48 	struct dcb_gpio_func *tach = &therm->fan->tach;
     49 
     50 	g84_sensor_setup(therm);
     51 
     52 	/* enable fan tach, count revolutions per-second */
     53 	nvkm_mask(device, 0x00e720, 0x00000003, 0x00000002);
     54 	if (tach->func != DCB_GPIO_UNUSED) {
     55 		nvkm_wr32(device, 0x00e724, device->crystal * 1000);
     56 		nvkm_mask(device, 0x00e720, 0x001f0000, tach->line << 16);
     57 		nvkm_mask(device, 0x00e720, 0x00000001, 0x00000001);
     58 	}
     59 	nvkm_mask(device, 0x00e720, 0x00000002, 0x00000000);
     60 }
     61 
     62 static const struct nvkm_therm_func
     63 gt215_therm = {
     64 	.init = gt215_therm_init,
     65 	.fini = g84_therm_fini,
     66 	.pwm_ctrl = nv50_fan_pwm_ctrl,
     67 	.pwm_get = nv50_fan_pwm_get,
     68 	.pwm_set = nv50_fan_pwm_set,
     69 	.pwm_clock = nv50_fan_pwm_clock,
     70 	.temp_get = g84_temp_get,
     71 	.fan_sense = gt215_therm_fan_sense,
     72 	.program_alarms = nvkm_therm_program_alarms_polling,
     73 };
     74 
     75 int
     76 gt215_therm_new(struct nvkm_device *device, int index,
     77 	       struct nvkm_therm **ptherm)
     78 {
     79 	return nvkm_therm_new_(&gt215_therm, device, index, ptherm);
     80 }
     81