| 1 | #ifndef __NVTHERM_PRIV_H__ |
| 2 | #define __NVTHERM_PRIV_H__ |
| 3 | |
| 4 | /* |
| 5 | * Copyright 2012 The Nouveau community |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 21 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 | * OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | * Authors: Martin Peres |
| 26 | */ |
| 27 | |
| 28 | #include <subdev/therm.h> |
| 29 | |
| 30 | #include <subdev/bios/extdev.h> |
| 31 | #include <subdev/bios/gpio.h> |
| 32 | #include <subdev/bios/perf.h> |
| 33 | #include <subdev/bios/therm.h> |
| 34 | #include <subdev/timer.h> |
| 35 | |
| 36 | struct nouveau_fan { |
| 37 | struct nouveau_therm *parent; |
| 38 | const char *type; |
| 39 | |
| 40 | struct nvbios_therm_fan bios; |
| 41 | struct nvbios_perf_fan perf; |
| 42 | |
| 43 | struct nouveau_alarm alarm; |
| 44 | spinlock_t lock; |
| 45 | int percent; |
| 46 | |
| 47 | int (*get)(struct nouveau_therm *therm); |
| 48 | int (*set)(struct nouveau_therm *therm, int percent); |
| 49 | |
| 50 | struct dcb_gpio_func tach; |
| 51 | }; |
| 52 | |
| 53 | enum nouveau_therm_thrs_direction { |
| 54 | NOUVEAU_THERM_THRS_FALLING = 0, |
| 55 | NOUVEAU_THERM_THRS_RISING = 1 |
| 56 | }; |
| 57 | |
| 58 | enum nouveau_therm_thrs_state { |
| 59 | NOUVEAU_THERM_THRS_LOWER = 0, |
| 60 | NOUVEAU_THERM_THRS_HIGHER = 1 |
| 61 | }; |
| 62 | |
| 63 | enum nouveau_therm_thrs { |
| 64 | NOUVEAU_THERM_THRS_FANBOOST = 0, |
| 65 | NOUVEAU_THERM_THRS_DOWNCLOCK = 1, |
| 66 | NOUVEAU_THERM_THRS_CRITICAL = 2, |
| 67 | NOUVEAU_THERM_THRS_SHUTDOWN = 3, |
| 68 | NOUVEAU_THERM_THRS_NR |
| 69 | }; |
| 70 | |
| 71 | struct nouveau_therm_priv { |
| 72 | struct nouveau_therm base; |
| 73 | |
| 74 | /* automatic thermal management */ |
| 75 | struct nouveau_alarm alarm; |
| 76 | spinlock_t lock; |
| 77 | struct nouveau_therm_trip_point *last_trip; |
| 78 | int mode; |
| 79 | int cstate; |
| 80 | int suspend; |
| 81 | |
| 82 | /* bios */ |
| 83 | struct nvbios_therm_sensor bios_sensor; |
| 84 | |
| 85 | /* fan priv */ |
| 86 | struct nouveau_fan *fan; |
| 87 | |
| 88 | /* alarms priv */ |
| 89 | struct { |
| 90 | spinlock_t alarm_program_lock; |
| 91 | struct nouveau_alarm therm_poll_alarm; |
| 92 | enum nouveau_therm_thrs_state alarm_state[NOUVEAU_THERM_THRS_NR]; |
| 93 | void (*program_alarms)(struct nouveau_therm *); |
| 94 | } sensor; |
| 95 | |
| 96 | /* what should be done if the card overheats */ |
| 97 | struct { |
| 98 | void (*downclock)(struct nouveau_therm *, bool active); |
| 99 | void (*pause)(struct nouveau_therm *, bool active); |
| 100 | } emergency; |
| 101 | |
| 102 | /* ic */ |
| 103 | struct i2c_client *ic; |
| 104 | }; |
| 105 | |
| 106 | int nouveau_therm_fan_mode(struct nouveau_therm *therm, int mode); |
| 107 | int nouveau_therm_attr_get(struct nouveau_therm *therm, |
| 108 | enum nouveau_therm_attr_type type); |
| 109 | int nouveau_therm_attr_set(struct nouveau_therm *therm, |
| 110 | enum nouveau_therm_attr_type type, int value); |
| 111 | |
| 112 | void nouveau_therm_ic_ctor(struct nouveau_therm *therm); |
| 113 | |
| 114 | int nouveau_therm_sensor_ctor(struct nouveau_therm *therm); |
| 115 | |
| 116 | int nouveau_therm_fan_ctor(struct nouveau_therm *therm); |
| 117 | int nouveau_therm_fan_init(struct nouveau_therm *therm); |
| 118 | int nouveau_therm_fan_fini(struct nouveau_therm *therm, bool suspend); |
| 119 | int nouveau_therm_fan_get(struct nouveau_therm *therm); |
| 120 | int nouveau_therm_fan_set(struct nouveau_therm *therm, bool now, int percent); |
| 121 | int nouveau_therm_fan_user_get(struct nouveau_therm *therm); |
| 122 | int nouveau_therm_fan_user_set(struct nouveau_therm *therm, int percent); |
| 123 | |
| 124 | int nouveau_therm_fan_sense(struct nouveau_therm *therm); |
| 125 | |
| 126 | int nouveau_therm_preinit(struct nouveau_therm *); |
| 127 | |
| 128 | int nouveau_therm_sensor_init(struct nouveau_therm *therm); |
| 129 | int nouveau_therm_sensor_fini(struct nouveau_therm *therm, bool suspend); |
| 130 | void nouveau_therm_sensor_preinit(struct nouveau_therm *); |
| 131 | void nouveau_therm_sensor_set_threshold_state(struct nouveau_therm *therm, |
| 132 | enum nouveau_therm_thrs thrs, |
| 133 | enum nouveau_therm_thrs_state st); |
| 134 | enum nouveau_therm_thrs_state |
| 135 | nouveau_therm_sensor_get_threshold_state(struct nouveau_therm *therm, |
| 136 | enum nouveau_therm_thrs thrs); |
| 137 | void nouveau_therm_sensor_event(struct nouveau_therm *therm, |
| 138 | enum nouveau_therm_thrs thrs, |
| 139 | enum nouveau_therm_thrs_direction dir); |
| 140 | void nouveau_therm_program_alarms_polling(struct nouveau_therm *therm); |
| 141 | |
| 142 | void nv40_therm_intr(struct nouveau_subdev *); |
| 143 | int nv50_fan_pwm_ctrl(struct nouveau_therm *, int, bool); |
| 144 | int nv50_fan_pwm_get(struct nouveau_therm *, int, u32 *, u32 *); |
| 145 | int nv50_fan_pwm_set(struct nouveau_therm *, int, u32, u32); |
| 146 | int nv50_fan_pwm_clock(struct nouveau_therm *, int); |
| 147 | int nv84_temp_get(struct nouveau_therm *therm); |
| 148 | int nv84_therm_fini(struct nouveau_object *object, bool suspend); |
| 149 | |
| 150 | int nva3_therm_fan_sense(struct nouveau_therm *); |
| 151 | |
| 152 | int nouveau_fanpwm_create(struct nouveau_therm *, struct dcb_gpio_func *); |
| 153 | int nouveau_fantog_create(struct nouveau_therm *, struct dcb_gpio_func *); |
| 154 | int nouveau_fannil_create(struct nouveau_therm *); |
| 155 | |
| 156 | #endif |
| 157 | |