Home | History | Annotate | Line # | Download | only in therm
      1 /*	$NetBSD: nouveau_nvkm_subdev_therm_gm107.c,v 1.3 2021/12/18 23:45:41 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2014 Martin Peres
      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: Martin Peres
     25  */
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_therm_gm107.c,v 1.3 2021/12/18 23:45:41 riastradh Exp $");
     28 
     29 #include "priv.h"
     30 
     31 static int
     32 gm107_fan_pwm_ctrl(struct nvkm_therm *therm, int line, bool enable)
     33 {
     34 	/* nothing to do, it seems hardwired */
     35 	return 0;
     36 }
     37 
     38 static int
     39 gm107_fan_pwm_get(struct nvkm_therm *therm, int line, u32 *divs, u32 *duty)
     40 {
     41 	struct nvkm_device *device = therm->subdev.device;
     42 	*divs = nvkm_rd32(device, 0x10eb20) & 0x1fff;
     43 	*duty = nvkm_rd32(device, 0x10eb24) & 0x1fff;
     44 	return 0;
     45 }
     46 
     47 static int
     48 gm107_fan_pwm_set(struct nvkm_therm *therm, int line, u32 divs, u32 duty)
     49 {
     50 	struct nvkm_device *device = therm->subdev.device;
     51 	nvkm_mask(device, 0x10eb10, 0x1fff, divs); /* keep the high bits */
     52 	nvkm_wr32(device, 0x10eb14, duty | 0x80000000);
     53 	return 0;
     54 }
     55 
     56 static int
     57 gm107_fan_pwm_clock(struct nvkm_therm *therm, int line)
     58 {
     59 	return therm->subdev.device->crystal * 1000;
     60 }
     61 
     62 static const struct nvkm_therm_func
     63 gm107_therm = {
     64 	.init = gf119_therm_init,
     65 	.fini = g84_therm_fini,
     66 	.pwm_ctrl = gm107_fan_pwm_ctrl,
     67 	.pwm_get = gm107_fan_pwm_get,
     68 	.pwm_set = gm107_fan_pwm_set,
     69 	.pwm_clock = gm107_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 gm107_therm_new(struct nvkm_device *device, int index,
     77 		struct nvkm_therm **ptherm)
     78 {
     79 	return nvkm_therm_new_(&gm107_therm, device, index, ptherm);
     80 }
     81