2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
28 struct nv84_therm_priv {
29 struct nouveau_therm_priv base;
33 nv84_temp_get(struct nouveau_therm *therm)
35 return nv_rd32(therm, 0x20400);
39 nv84_therm_program_alarms(struct nouveau_therm *therm)
41 struct nouveau_therm_priv *priv = (void *)therm;
42 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
45 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
47 /* enable RISING and FALLING IRQs for shutdown, THRS 0, 1, 2 and 4 */
48 nv_wr32(therm, 0x20000, 0x000003ff);
50 /* shutdown: The computer should be shutdown when reached */
51 nv_wr32(therm, 0x20484, sensor->thrs_shutdown.hysteresis);
52 nv_wr32(therm, 0x20480, sensor->thrs_shutdown.temp);
54 /* THRS_1 : fan boost*/
55 nv_wr32(therm, 0x204c4, sensor->thrs_fan_boost.temp);
57 /* THRS_2 : critical */
58 nv_wr32(therm, 0x204c0, sensor->thrs_critical.temp);
60 /* THRS_4 : down clock */
61 nv_wr32(therm, 0x20414, sensor->thrs_down_clock.temp);
62 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
65 "Programmed thresholds [ %d(%d), %d(%d), %d(%d), %d(%d) ]\n",
66 sensor->thrs_fan_boost.temp, sensor->thrs_fan_boost.hysteresis,
67 sensor->thrs_down_clock.temp,
68 sensor->thrs_down_clock.hysteresis,
69 sensor->thrs_critical.temp, sensor->thrs_critical.hysteresis,
70 sensor->thrs_shutdown.temp, sensor->thrs_shutdown.hysteresis);
74 /* must be called with alarm_program_lock taken ! */
76 nv84_therm_threshold_hyst_emulation(struct nouveau_therm *therm,
77 uint32_t thrs_reg, u8 status_bit,
78 const struct nvbios_therm_threshold *thrs,
79 enum nouveau_therm_thrs thrs_name)
81 enum nouveau_therm_thrs_direction direction;
82 enum nouveau_therm_thrs_state prev_state, new_state;
85 prev_state = nouveau_therm_sensor_get_threshold_state(therm, thrs_name);
86 temp = nv_rd32(therm, thrs_reg);
88 /* program the next threshold */
89 if (temp == thrs->temp) {
90 nv_wr32(therm, thrs_reg, thrs->temp - thrs->hysteresis);
91 new_state = NOUVEAU_THERM_THRS_HIGHER;
93 nv_wr32(therm, thrs_reg, thrs->temp);
94 new_state = NOUVEAU_THERM_THRS_LOWER;
97 /* fix the state (in case someone reprogrammed the alarms) */
98 cur = therm->temp_get(therm);
99 if (new_state == NOUVEAU_THERM_THRS_LOWER && cur > thrs->temp)
100 new_state = NOUVEAU_THERM_THRS_HIGHER;
101 else if (new_state == NOUVEAU_THERM_THRS_HIGHER &&
102 cur < thrs->temp - thrs->hysteresis)
103 new_state = NOUVEAU_THERM_THRS_LOWER;
104 nouveau_therm_sensor_set_threshold_state(therm, thrs_name, new_state);
106 /* find the direction */
107 if (prev_state < new_state)
108 direction = NOUVEAU_THERM_THRS_RISING;
109 else if (prev_state > new_state)
110 direction = NOUVEAU_THERM_THRS_FALLING;
114 /* advertise a change in direction */
115 nouveau_therm_sensor_event(therm, thrs_name, direction);
119 nv84_therm_intr(struct nouveau_subdev *subdev)
121 struct nouveau_therm *therm = nouveau_therm(subdev);
122 struct nouveau_therm_priv *priv = (void *)therm;
123 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
127 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
129 intr = nv_rd32(therm, 0x20100) & 0x3ff;
131 /* THRS_4: downclock */
133 nv84_therm_threshold_hyst_emulation(therm, 0x20414, 24,
134 &sensor->thrs_down_clock,
135 NOUVEAU_THERM_THRS_DOWNCLOCK);
141 nv84_therm_threshold_hyst_emulation(therm, 0x20480, 20,
142 &sensor->thrs_shutdown,
143 NOUVEAU_THERM_THRS_SHUTDOWN);
147 /* THRS_1 : fan boost */
149 nv84_therm_threshold_hyst_emulation(therm, 0x204c4, 21,
150 &sensor->thrs_fan_boost,
151 NOUVEAU_THERM_THRS_FANBOOST);
155 /* THRS_2 : critical */
157 nv84_therm_threshold_hyst_emulation(therm, 0x204c0, 22,
158 &sensor->thrs_critical,
159 NOUVEAU_THERM_THRS_CRITICAL);
164 nv_error(therm, "unhandled intr 0x%08x\n", intr);
167 nv_wr32(therm, 0x20100, 0xffffffff);
168 nv_wr32(therm, 0x1100, 0x10000); /* PBUS */
170 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
174 nv84_therm_ctor(struct nouveau_object *parent,
175 struct nouveau_object *engine,
176 struct nouveau_oclass *oclass, void *data, u32 size,
177 struct nouveau_object **pobject)
179 struct nv84_therm_priv *priv;
182 ret = nouveau_therm_create(parent, engine, oclass, &priv);
183 *pobject = nv_object(priv);
187 priv->base.base.pwm_ctrl = nv50_fan_pwm_ctrl;
188 priv->base.base.pwm_get = nv50_fan_pwm_get;
189 priv->base.base.pwm_set = nv50_fan_pwm_set;
190 priv->base.base.pwm_clock = nv50_fan_pwm_clock;
191 priv->base.base.temp_get = nv84_temp_get;
192 priv->base.sensor.program_alarms = nv84_therm_program_alarms;
193 nv_subdev(priv)->intr = nv84_therm_intr;
195 /* init the thresholds */
196 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
197 NOUVEAU_THERM_THRS_SHUTDOWN,
198 NOUVEAU_THERM_THRS_LOWER);
199 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
200 NOUVEAU_THERM_THRS_FANBOOST,
201 NOUVEAU_THERM_THRS_LOWER);
202 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
203 NOUVEAU_THERM_THRS_CRITICAL,
204 NOUVEAU_THERM_THRS_LOWER);
205 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
206 NOUVEAU_THERM_THRS_DOWNCLOCK,
207 NOUVEAU_THERM_THRS_LOWER);
209 return nouveau_therm_preinit(&priv->base.base);
213 nv84_therm_fini(struct nouveau_object *object, bool suspend)
215 /* Disable PTherm IRQs */
216 nv_wr32(object, 0x20000, 0x00000000);
218 /* ACK all PTherm IRQs */
219 nv_wr32(object, 0x20100, 0xffffffff);
220 nv_wr32(object, 0x1100, 0x10000); /* PBUS */
222 return _nouveau_therm_fini(object, suspend);
225 struct nouveau_oclass
226 nv84_therm_oclass = {
227 .handle = NV_SUBDEV(THERM, 0x84),
228 .ofuncs = &(struct nouveau_ofuncs) {
229 .ctor = nv84_therm_ctor,
230 .dtor = _nouveau_therm_dtor,
231 .init = _nouveau_therm_init,
232 .fini = nv84_therm_fini,