Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs
0023  */
0024 #include "priv.h"
0025 
0026 #include <subdev/gpio.h>
0027 
0028 int
0029 gt215_therm_fan_sense(struct nvkm_therm *therm)
0030 {
0031     struct nvkm_device *device = therm->subdev.device;
0032     u32 tach = nvkm_rd32(device, 0x00e728) & 0x0000ffff;
0033     u32 ctrl = nvkm_rd32(device, 0x00e720);
0034     if (ctrl & 0x00000001)
0035         return tach * 60 / 2;
0036     return -ENODEV;
0037 }
0038 
0039 static void
0040 gt215_therm_init(struct nvkm_therm *therm)
0041 {
0042     struct nvkm_device *device = therm->subdev.device;
0043     struct dcb_gpio_func *tach = &therm->fan->tach;
0044 
0045     g84_sensor_setup(therm);
0046 
0047     /* enable fan tach, count revolutions per-second */
0048     nvkm_mask(device, 0x00e720, 0x00000003, 0x00000002);
0049     if (tach->func != DCB_GPIO_UNUSED) {
0050         nvkm_wr32(device, 0x00e724, device->crystal * 1000);
0051         nvkm_mask(device, 0x00e720, 0x001f0000, tach->line << 16);
0052         nvkm_mask(device, 0x00e720, 0x00000001, 0x00000001);
0053     }
0054     nvkm_mask(device, 0x00e720, 0x00000002, 0x00000000);
0055 }
0056 
0057 static const struct nvkm_therm_func
0058 gt215_therm = {
0059     .init = gt215_therm_init,
0060     .fini = g84_therm_fini,
0061     .pwm_ctrl = nv50_fan_pwm_ctrl,
0062     .pwm_get = nv50_fan_pwm_get,
0063     .pwm_set = nv50_fan_pwm_set,
0064     .pwm_clock = nv50_fan_pwm_clock,
0065     .temp_get = g84_temp_get,
0066     .fan_sense = gt215_therm_fan_sense,
0067     .program_alarms = nvkm_therm_program_alarms_polling,
0068 };
0069 
0070 int
0071 gt215_therm_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0072         struct nvkm_therm **ptherm)
0073 {
0074     return nvkm_therm_new_(&gt215_therm, device, type, inst, ptherm);
0075 }