1 /* 2 * Copyright 2012 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: Ben Skeggs 23 */ 24 #include "priv.h" 25 26 #include <subdev/gpio.h> 27 28 struct gt215_therm_priv { 29 struct nvkm_therm_priv base; 30 }; 31 32 int 33 gt215_therm_fan_sense(struct nvkm_therm *therm) 34 { 35 u32 tach = nv_rd32(therm, 0x00e728) & 0x0000ffff; 36 u32 ctrl = nv_rd32(therm, 0x00e720); 37 if (ctrl & 0x00000001) 38 return tach * 60 / 2; 39 return -ENODEV; 40 } 41 42 static int 43 gt215_therm_init(struct nvkm_object *object) 44 { 45 struct gt215_therm_priv *priv = (void *)object; 46 struct dcb_gpio_func *tach = &priv->base.fan->tach; 47 int ret; 48 49 ret = nvkm_therm_init(&priv->base.base); 50 if (ret) 51 return ret; 52 53 g84_sensor_setup(&priv->base.base); 54 55 /* enable fan tach, count revolutions per-second */ 56 nv_mask(priv, 0x00e720, 0x00000003, 0x00000002); 57 if (tach->func != DCB_GPIO_UNUSED) { 58 nv_wr32(priv, 0x00e724, nv_device(priv)->crystal * 1000); 59 nv_mask(priv, 0x00e720, 0x001f0000, tach->line << 16); 60 nv_mask(priv, 0x00e720, 0x00000001, 0x00000001); 61 } 62 nv_mask(priv, 0x00e720, 0x00000002, 0x00000000); 63 64 return 0; 65 } 66 67 static int 68 gt215_therm_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 69 struct nvkm_oclass *oclass, void *data, u32 size, 70 struct nvkm_object **pobject) 71 { 72 struct gt215_therm_priv *priv; 73 int ret; 74 75 ret = nvkm_therm_create(parent, engine, oclass, &priv); 76 *pobject = nv_object(priv); 77 if (ret) 78 return ret; 79 80 priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl; 81 priv->base.base.pwm_get = nv50_fan_pwm_get; 82 priv->base.base.pwm_set = nv50_fan_pwm_set; 83 priv->base.base.pwm_clock = nv50_fan_pwm_clock; 84 priv->base.base.temp_get = g84_temp_get; 85 priv->base.base.fan_sense = gt215_therm_fan_sense; 86 priv->base.sensor.program_alarms = nvkm_therm_program_alarms_polling; 87 return nvkm_therm_preinit(&priv->base.base); 88 } 89 90 struct nvkm_oclass 91 gt215_therm_oclass = { 92 .handle = NV_SUBDEV(THERM, 0xa3), 93 .ofuncs = &(struct nvkm_ofuncs) { 94 .ctor = gt215_therm_ctor, 95 .dtor = _nvkm_therm_dtor, 96 .init = gt215_therm_init, 97 .fini = g84_therm_fini, 98 }, 99 }; 100