Fabian Kunkel | f75c3b4 | 2015-05-25 17:04:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> |
| 5 | * Copyright (C) 2015 BAP - Bruhnspace Advanced Projects |
| 6 | * (Written by Fabian Kunkel <fabi@adv.bruhnspace.com> for BAP) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Fabian Kunkel | f75c3b4 | 2015-05-25 17:04:28 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* Setup only for Fan2 |
| 20 | * Todo: Add support for Fan1 and Fan3 |
| 21 | */ |
| 22 | |
| 23 | #include <arch/io.h> |
| 24 | #include <console/console.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pnp.h> |
| 27 | #include "fintek_internal.h" |
| 28 | #include "chip.h" |
| 29 | |
| 30 | |
| 31 | /* Register addresses */ |
| 32 | // Choose between AMD and Intel |
| 33 | #define HWM_AMD_TSI_ADDR 0x08 |
| 34 | #define HWM_AMD_TSI_CONTROL_REG 0x0A |
| 35 | |
| 36 | // Set temp sensors type |
| 37 | #define TEMP_SENS_TYPE_REG 0x6B |
| 38 | |
| 39 | // FAN prog sel |
| 40 | #define HWM_FAN3_CONTROL 0x9A |
| 41 | #define HWM_FAN_SEL 0x94 |
| 42 | #define HWM_FAN_MODE 0x96 |
| 43 | #define HWM_FAN2_TEMP_MAP_SEL 0xBF |
| 44 | |
| 45 | // Fan 2 - 4 Boundries |
| 46 | #define HWM_FAN2_BOUND1 0xB6 |
| 47 | #define HWM_FAN2_BOUND2 0xB7 |
| 48 | #define HWM_FAN2_BOUND3 0xB8 |
| 49 | #define HWM_FAN2_BOUND4 0xB9 |
| 50 | // Fan 2 - 5 Segment speeds |
| 51 | #define HWM_FAN2_SEG1_SPEED_COUNT 0xBA |
| 52 | #define HWM_FAN2_SEG2_SPEED_COUNT 0xBB |
| 53 | #define HWM_FAN2_SEG3_SPEED_COUNT 0xBC |
| 54 | #define HWM_FAN2_SEG4_SPEED_COUNT 0xBD |
| 55 | #define HWM_FAN2_SEG5_SPEED_COUNT 0xBE |
| 56 | |
| 57 | |
| 58 | void f81866d_hwm_init(struct device *dev) |
| 59 | { |
| 60 | struct resource *res = find_resource(dev, PNP_IDX_IO0); |
| 61 | |
| 62 | if (!res) { |
| 63 | printk(BIOS_WARNING, "Super I/O HWM: No HWM resource found.\n"); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | const struct superio_fintek_f81866d_config *reg = dev->chip_info; |
| 68 | u16 port = res->base; |
| 69 | |
| 70 | pnp_enter_conf_mode(dev); |
| 71 | |
| 72 | /* Use AMD TSI */ |
| 73 | pnp_write_index(port, HWM_AMD_TSI_ADDR, reg->hwm_amd_tsi_addr); |
| 74 | pnp_write_index(port, HWM_AMD_TSI_CONTROL_REG, reg->hwm_amd_tsi_control); |
| 75 | |
| 76 | /* Set temp1 sensor to thermistor */ |
| 77 | pnp_write_index(port, TEMP_SENS_TYPE_REG, reg->hwm_temp_sens_type); |
| 78 | |
| 79 | /* Select FAN Type */ |
| 80 | pnp_write_index(port, HWM_FAN_SEL, reg->hwm_fan_select); |
| 81 | |
| 82 | /* Select FAN Mode*/ |
| 83 | pnp_write_index(port, HWM_FAN_MODE, reg->hwm_fan_mode); |
| 84 | |
| 85 | /* Set Boundries */ |
| 86 | pnp_write_index(port, HWM_FAN2_BOUND1, reg->hwm_fan2_bound1); |
| 87 | pnp_write_index(port, HWM_FAN2_BOUND2, reg->hwm_fan2_bound2); |
| 88 | pnp_write_index(port, HWM_FAN2_BOUND3, reg->hwm_fan2_bound3); |
| 89 | pnp_write_index(port, HWM_FAN2_BOUND4, reg->hwm_fan2_bound4); |
| 90 | |
| 91 | /* Set Speed */ |
| 92 | pnp_write_index(port, HWM_FAN2_SEG1_SPEED_COUNT, reg->hwm_fan2_seg1_speed); |
| 93 | pnp_write_index(port, HWM_FAN2_SEG2_SPEED_COUNT, reg->hwm_fan2_seg2_speed); |
| 94 | pnp_write_index(port, HWM_FAN2_SEG3_SPEED_COUNT, reg->hwm_fan2_seg3_speed); |
| 95 | pnp_write_index(port, HWM_FAN2_SEG4_SPEED_COUNT, reg->hwm_fan2_seg4_speed); |
| 96 | pnp_write_index(port, HWM_FAN2_SEG5_SPEED_COUNT, reg->hwm_fan2_seg5_speed); |
| 97 | |
| 98 | /* Set Fan control freq */ |
| 99 | pnp_write_index(port, HWM_FAN3_CONTROL, reg->hwm_fan3_control); |
| 100 | pnp_write_index(port, HWM_FAN2_TEMP_MAP_SEL, reg->hwm_fan2_temp_map_select); |
| 101 | |
| 102 | pnp_exit_conf_mode(dev); |
| 103 | } |