Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2014 Martin Peres
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: Martin Peres
0023  */
0024 #include <subdev/bios.h>
0025 #include <subdev/bios/bit.h>
0026 #include <subdev/bios/fan.h>
0027 
0028 static u32
0029 nvbios_fan_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0030 {
0031     struct bit_entry bit_P;
0032     u32 fan = 0;
0033 
0034     if (!bit_entry(bios, 'P', &bit_P)) {
0035         if (bit_P.version == 2 && bit_P.length >= 0x5c)
0036             fan = nvbios_rd32(bios, bit_P.offset + 0x58);
0037 
0038         if (fan) {
0039             *ver = nvbios_rd08(bios, fan + 0);
0040             switch (*ver) {
0041             case 0x10:
0042                 *hdr = nvbios_rd08(bios, fan + 1);
0043                 *len = nvbios_rd08(bios, fan + 2);
0044                 *cnt = nvbios_rd08(bios, fan + 3);
0045                 return fan;
0046             default:
0047                 break;
0048             }
0049         }
0050     }
0051 
0052     return 0;
0053 }
0054 
0055 static u32
0056 nvbios_fan_entry(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
0057          u8 *cnt, u8 *len)
0058 {
0059     u32 data = nvbios_fan_table(bios, ver, hdr, cnt, len);
0060     if (data && idx < *cnt)
0061         return data + *hdr + (idx * (*len));
0062     return 0;
0063 }
0064 
0065 u32
0066 nvbios_fan_parse(struct nvkm_bios *bios, struct nvbios_therm_fan *fan)
0067 {
0068     u8 ver, hdr, cnt, len;
0069 
0070     u32 data = nvbios_fan_entry(bios, 0, &ver, &hdr, &cnt, &len);
0071     if (data) {
0072         u8 type = nvbios_rd08(bios, data + 0x00);
0073         switch (type) {
0074         case 0:
0075             fan->type = NVBIOS_THERM_FAN_TOGGLE;
0076             break;
0077         case 1:
0078         case 2:
0079             /* TODO: Understand the difference between the two! */
0080             fan->type = NVBIOS_THERM_FAN_PWM;
0081             break;
0082         default:
0083             fan->type = NVBIOS_THERM_FAN_UNK;
0084         }
0085 
0086         fan->fan_mode = NVBIOS_THERM_FAN_LINEAR;
0087         fan->min_duty = nvbios_rd08(bios, data + 0x02);
0088         fan->max_duty = nvbios_rd08(bios, data + 0x03);
0089 
0090         fan->pwm_freq = nvbios_rd32(bios, data + 0x0b) & 0xffffff;
0091     }
0092 
0093     return data;
0094 }