aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm
diff options
context:
space:
mode:
authorMartin Peres <martin.peres@labri.fr>2013-02-23 10:45:51 -0500
committerBen Skeggs <bskeggs@redhat.com>2013-04-26 01:37:35 -0400
commit2f4573679a8159e0c80a5d4f812b778aef9ceb14 (patch)
tree60ac29a003260e0fef86a0c2ae95c3418151965a /drivers/gpu/drm
parent897a6e27fd44573d2f346d9bb122e0e29759952c (diff)
drm/nouveau/therm: split the nv50 and nv84 code
This is needed because temperature management on nv50 can be enabled and it looks about the same as nv40. Signed-off-by: Martin Peres <martin.peres@labri.fr> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm')
-rw-r--r--drivers/gpu/drm/nouveau/Makefile1
-rw-r--r--drivers/gpu/drm/nouveau/core/include/subdev/therm.h1
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/device/nv50.c18
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nv50.c153
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nv84.c221
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nva3.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nvd0.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/priv.h3
9 files changed, 239 insertions, 164 deletions
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile
index 90f9140eeefd..0c65479c1b6f 100644
--- a/drivers/gpu/drm/nouveau/Makefile
+++ b/drivers/gpu/drm/nouveau/Makefile
@@ -126,6 +126,7 @@ nouveau-y += core/subdev/therm/ic.o
126nouveau-y += core/subdev/therm/temp.o 126nouveau-y += core/subdev/therm/temp.o
127nouveau-y += core/subdev/therm/nv40.o 127nouveau-y += core/subdev/therm/nv40.o
128nouveau-y += core/subdev/therm/nv50.o 128nouveau-y += core/subdev/therm/nv50.o
129nouveau-y += core/subdev/therm/nv84.o
129nouveau-y += core/subdev/therm/nva3.o 130nouveau-y += core/subdev/therm/nva3.o
130nouveau-y += core/subdev/therm/nvd0.o 131nouveau-y += core/subdev/therm/nvd0.o
131nouveau-y += core/subdev/timer/base.o 132nouveau-y += core/subdev/timer/base.o
diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
index 0b20fc0d19c1..c075998d82e6 100644
--- a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
+++ b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
@@ -73,6 +73,7 @@ int _nouveau_therm_fini(struct nouveau_object *, bool);
73 73
74extern struct nouveau_oclass nv40_therm_oclass; 74extern struct nouveau_oclass nv40_therm_oclass;
75extern struct nouveau_oclass nv50_therm_oclass; 75extern struct nouveau_oclass nv50_therm_oclass;
76extern struct nouveau_oclass nv84_therm_oclass;
76extern struct nouveau_oclass nva3_therm_oclass; 77extern struct nouveau_oclass nva3_therm_oclass;
77extern struct nouveau_oclass nvd0_therm_oclass; 78extern struct nouveau_oclass nvd0_therm_oclass;
78 79
diff --git a/drivers/gpu/drm/nouveau/core/subdev/device/nv50.c b/drivers/gpu/drm/nouveau/core/subdev/device/nv50.c
index 5ed2fa51ddc2..04b2d75f4643 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/device/nv50.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/device/nv50.c
@@ -83,7 +83,7 @@ nv50_identify(struct nouveau_device *device)
83 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 83 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
84 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass; 84 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass;
85 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 85 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
86 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 86 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
87 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 87 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
88 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 88 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
89 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass; 89 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass;
@@ -109,7 +109,7 @@ nv50_identify(struct nouveau_device *device)
109 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 109 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
110 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass; 110 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass;
111 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 111 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
112 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 112 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
113 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 113 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
114 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 114 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
115 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass; 115 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass;
@@ -135,7 +135,7 @@ nv50_identify(struct nouveau_device *device)
135 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 135 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
136 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass; 136 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass;
137 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 137 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
138 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 138 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
139 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 139 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
140 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 140 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
141 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass; 141 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass;
@@ -161,7 +161,7 @@ nv50_identify(struct nouveau_device *device)
161 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 161 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
162 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass; 162 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass;
163 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 163 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
164 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 164 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
165 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 165 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
166 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 166 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
167 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass; 167 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass;
@@ -187,7 +187,7 @@ nv50_identify(struct nouveau_device *device)
187 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 187 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
188 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass; 188 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass;
189 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 189 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
190 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 190 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
191 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 191 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
192 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 192 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
193 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass; 193 device->oclass[NVDEV_SUBDEV_MC ] = &nv50_mc_oclass;
@@ -213,7 +213,7 @@ nv50_identify(struct nouveau_device *device)
213 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 213 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
214 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass; 214 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass;
215 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 215 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
216 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 216 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
217 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 217 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
218 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 218 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
219 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass; 219 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass;
@@ -239,7 +239,7 @@ nv50_identify(struct nouveau_device *device)
239 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 239 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
240 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass; 240 device->oclass[NVDEV_SUBDEV_I2C ] = &nv50_i2c_oclass;
241 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 241 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
242 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 242 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
243 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 243 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
244 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 244 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
245 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass; 245 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass;
@@ -265,7 +265,7 @@ nv50_identify(struct nouveau_device *device)
265 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 265 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
266 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass; 266 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass;
267 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 267 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
268 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 268 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
269 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 269 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
270 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 270 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
271 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass; 271 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass;
@@ -291,7 +291,7 @@ nv50_identify(struct nouveau_device *device)
291 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass; 291 device->oclass[NVDEV_SUBDEV_GPIO ] = &nv50_gpio_oclass;
292 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass; 292 device->oclass[NVDEV_SUBDEV_I2C ] = &nv94_i2c_oclass;
293 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass; 293 device->oclass[NVDEV_SUBDEV_CLOCK ] = &nv50_clock_oclass;
294 device->oclass[NVDEV_SUBDEV_THERM ] = &nv50_therm_oclass; 294 device->oclass[NVDEV_SUBDEV_THERM ] = &nv84_therm_oclass;
295 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass; 295 device->oclass[NVDEV_SUBDEV_MXM ] = &nv50_mxm_oclass;
296 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass; 296 device->oclass[NVDEV_SUBDEV_DEVINIT] = &nv50_devinit_oclass;
297 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass; 297 device->oclass[NVDEV_SUBDEV_MC ] = &nv98_mc_oclass;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
index a70d1b7e397b..002e51b3af93 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
@@ -165,7 +165,7 @@ nv40_fan_pwm_set(struct nouveau_therm *therm, int line, u32 divs, u32 duty)
165 return 0; 165 return 0;
166} 166}
167 167
168static void 168void
169nv40_therm_intr(struct nouveau_subdev *subdev) 169nv40_therm_intr(struct nouveau_subdev *subdev)
170{ 170{
171 struct nouveau_therm *therm = nouveau_therm(subdev); 171 struct nouveau_therm *therm = nouveau_therm(subdev);
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nv50.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nv50.c
index 86632cbd65ce..37da24a5418b 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/nv50.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nv50.c
@@ -124,141 +124,6 @@ nv50_temp_get(struct nouveau_therm *therm)
124 return nv_rd32(therm, 0x20400); 124 return nv_rd32(therm, 0x20400);
125} 125}
126 126
127static void
128nv50_therm_program_alarms(struct nouveau_therm *therm)
129{
130 struct nouveau_therm_priv *priv = (void *)therm;
131 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
132 unsigned long flags;
133
134 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
135
136 /* enable RISING and FALLING IRQs for shutdown, THRS 0, 1, 2 and 4 */
137 nv_wr32(therm, 0x20000, 0x000003ff);
138
139 /* shutdown: The computer should be shutdown when reached */
140 nv_wr32(therm, 0x20484, sensor->thrs_shutdown.hysteresis);
141 nv_wr32(therm, 0x20480, sensor->thrs_shutdown.temp);
142
143 /* THRS_1 : fan boost*/
144 nv_wr32(therm, 0x204c4, sensor->thrs_fan_boost.temp);
145
146 /* THRS_2 : critical */
147 nv_wr32(therm, 0x204c0, sensor->thrs_critical.temp);
148
149 /* THRS_4 : down clock */
150 nv_wr32(therm, 0x20414, sensor->thrs_down_clock.temp);
151 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
152
153 nv_info(therm,
154 "Programmed thresholds [ %d(%d), %d(%d), %d(%d), %d(%d) ]\n",
155 sensor->thrs_fan_boost.temp, sensor->thrs_fan_boost.hysteresis,
156 sensor->thrs_down_clock.temp,
157 sensor->thrs_down_clock.hysteresis,
158 sensor->thrs_critical.temp, sensor->thrs_critical.hysteresis,
159 sensor->thrs_shutdown.temp, sensor->thrs_shutdown.hysteresis);
160
161}
162
163/* must be called with alarm_program_lock taken ! */
164static void
165nv50_therm_threshold_hyst_emulation(struct nouveau_therm *therm,
166 uint32_t thrs_reg, u8 status_bit,
167 const struct nvbios_therm_threshold *thrs,
168 enum nouveau_therm_thrs thrs_name)
169{
170 enum nouveau_therm_thrs_direction direction;
171 enum nouveau_therm_thrs_state prev_state, new_state;
172 int temp, cur;
173
174 prev_state = nouveau_therm_sensor_get_threshold_state(therm, thrs_name);
175 temp = nv_rd32(therm, thrs_reg);
176
177 /* program the next threshold */
178 if (temp == thrs->temp) {
179 nv_wr32(therm, thrs_reg, thrs->temp - thrs->hysteresis);
180 new_state = NOUVEAU_THERM_THRS_HIGHER;
181 } else {
182 nv_wr32(therm, thrs_reg, thrs->temp);
183 new_state = NOUVEAU_THERM_THRS_LOWER;
184 }
185
186 /* fix the state (in case someone reprogrammed the alarms) */
187 cur = therm->temp_get(therm);
188 if (new_state == NOUVEAU_THERM_THRS_LOWER && cur > thrs->temp)
189 new_state = NOUVEAU_THERM_THRS_HIGHER;
190 else if (new_state == NOUVEAU_THERM_THRS_HIGHER &&
191 cur < thrs->temp - thrs->hysteresis)
192 new_state = NOUVEAU_THERM_THRS_LOWER;
193 nouveau_therm_sensor_set_threshold_state(therm, thrs_name, new_state);
194
195 /* find the direction */
196 if (prev_state < new_state)
197 direction = NOUVEAU_THERM_THRS_RISING;
198 else if (prev_state > new_state)
199 direction = NOUVEAU_THERM_THRS_FALLING;
200 else
201 return;
202
203 /* advertise a change in direction */
204 nouveau_therm_sensor_event(therm, thrs_name, direction);
205}
206
207static void
208nv50_therm_intr(struct nouveau_subdev *subdev)
209{
210 struct nouveau_therm *therm = nouveau_therm(subdev);
211 struct nouveau_therm_priv *priv = (void *)therm;
212 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
213 unsigned long flags;
214 uint32_t intr;
215
216 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
217
218 intr = nv_rd32(therm, 0x20100);
219
220 /* THRS_4: downclock */
221 if (intr & 0x002) {
222 nv50_therm_threshold_hyst_emulation(therm, 0x20414, 24,
223 &sensor->thrs_down_clock,
224 NOUVEAU_THERM_THRS_DOWNCLOCK);
225 intr &= ~0x002;
226 }
227
228 /* shutdown */
229 if (intr & 0x004) {
230 nv50_therm_threshold_hyst_emulation(therm, 0x20480, 20,
231 &sensor->thrs_shutdown,
232 NOUVEAU_THERM_THRS_SHUTDOWN);
233 intr &= ~0x004;
234 }
235
236 /* THRS_1 : fan boost */
237 if (intr & 0x008) {
238 nv50_therm_threshold_hyst_emulation(therm, 0x204c4, 21,
239 &sensor->thrs_fan_boost,
240 NOUVEAU_THERM_THRS_FANBOOST);
241 intr &= ~0x008;
242 }
243
244 /* THRS_2 : critical */
245 if (intr & 0x010) {
246 nv50_therm_threshold_hyst_emulation(therm, 0x204c0, 22,
247 &sensor->thrs_critical,
248 NOUVEAU_THERM_THRS_CRITICAL);
249 intr &= ~0x010;
250 }
251
252 if (intr)
253 nv_error(therm, "unhandled intr 0x%08x\n", intr);
254
255 /* ACK everything */
256 nv_wr32(therm, 0x20100, 0xffffffff);
257 nv_wr32(therm, 0x1100, 0x10000); /* PBUS */
258
259 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
260}
261
262static int 127static int
263nv50_therm_ctor(struct nouveau_object *parent, 128nv50_therm_ctor(struct nouveau_object *parent,
264 struct nouveau_object *engine, 129 struct nouveau_object *engine,
@@ -278,22 +143,8 @@ nv50_therm_ctor(struct nouveau_object *parent,
278 priv->base.base.pwm_set = nv50_fan_pwm_set; 143 priv->base.base.pwm_set = nv50_fan_pwm_set;
279 priv->base.base.pwm_clock = nv50_fan_pwm_clock; 144 priv->base.base.pwm_clock = nv50_fan_pwm_clock;
280 priv->base.base.temp_get = nv50_temp_get; 145 priv->base.base.temp_get = nv50_temp_get;
281 priv->base.sensor.program_alarms = nv50_therm_program_alarms; 146 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling;
282 nv_subdev(priv)->intr = nv50_therm_intr; 147 nv_subdev(priv)->intr = nv40_therm_intr;
283
284 /* init the thresholds */
285 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
286 NOUVEAU_THERM_THRS_SHUTDOWN,
287 NOUVEAU_THERM_THRS_LOWER);
288 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
289 NOUVEAU_THERM_THRS_FANBOOST,
290 NOUVEAU_THERM_THRS_LOWER);
291 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
292 NOUVEAU_THERM_THRS_CRITICAL,
293 NOUVEAU_THERM_THRS_LOWER);
294 nouveau_therm_sensor_set_threshold_state(&priv->base.base,
295 NOUVEAU_THERM_THRS_DOWNCLOCK,
296 NOUVEAU_THERM_THRS_LOWER);
297 148
298 return nouveau_therm_preinit(&priv->base.base); 149 return nouveau_therm_preinit(&priv->base.base);
299} 150}
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nv84.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nv84.c
new file mode 100644
index 000000000000..be486cee2245
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nv84.c
@@ -0,0 +1,221 @@
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 * Martin Peres
24 */
25
26#include "priv.h"
27
28struct nv84_therm_priv {
29 struct nouveau_therm_priv base;
30};
31
32int
33nv84_temp_get(struct nouveau_therm *therm)
34{
35 return nv_rd32(therm, 0x20400);
36}
37
38static void
39nv84_therm_program_alarms(struct nouveau_therm *therm)
40{
41 struct nouveau_therm_priv *priv = (void *)therm;
42 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
43 unsigned long flags;
44
45 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
46
47 /* enable RISING and FALLING IRQs for shutdown, THRS 0, 1, 2 and 4 */
48 nv_wr32(therm, 0x20000, 0x000003ff);
49
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);
53
54 /* THRS_1 : fan boost*/
55 nv_wr32(therm, 0x204c4, sensor->thrs_fan_boost.temp);
56
57 /* THRS_2 : critical */
58 nv_wr32(therm, 0x204c0, sensor->thrs_critical.temp);
59
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);
63
64 nv_info(therm,
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);
71
72}
73
74/* must be called with alarm_program_lock taken ! */
75static void
76nv84_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)
80{
81 enum nouveau_therm_thrs_direction direction;
82 enum nouveau_therm_thrs_state prev_state, new_state;
83 int temp, cur;
84
85 prev_state = nouveau_therm_sensor_get_threshold_state(therm, thrs_name);
86 temp = nv_rd32(therm, thrs_reg);
87
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;
92 } else {
93 nv_wr32(therm, thrs_reg, thrs->temp);
94 new_state = NOUVEAU_THERM_THRS_LOWER;
95 }
96
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);
105
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;
111 else
112 return;
113
114 /* advertise a change in direction */
115 nouveau_therm_sensor_event(therm, thrs_name, direction);
116}
117
118static void
119nv84_therm_intr(struct nouveau_subdev *subdev)
120{
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;
124 unsigned long flags;
125 uint32_t intr;
126
127 spin_lock_irqsave(&priv->sensor.alarm_program_lock, flags);
128
129 intr = nv_rd32(therm, 0x20100);
130
131 /* THRS_4: downclock */
132 if (intr & 0x002) {
133 nv84_therm_threshold_hyst_emulation(therm, 0x20414, 24,
134 &sensor->thrs_down_clock,
135 NOUVEAU_THERM_THRS_DOWNCLOCK);
136 intr &= ~0x002;
137 }
138
139 /* shutdown */
140 if (intr & 0x004) {
141 nv84_therm_threshold_hyst_emulation(therm, 0x20480, 20,
142 &sensor->thrs_shutdown,
143 NOUVEAU_THERM_THRS_SHUTDOWN);
144 intr &= ~0x004;
145 }
146
147 /* THRS_1 : fan boost */
148 if (intr & 0x008) {
149 nv84_therm_threshold_hyst_emulation(therm, 0x204c4, 21,
150 &sensor->thrs_fan_boost,
151 NOUVEAU_THERM_THRS_FANBOOST);
152 intr &= ~0x008;
153 }
154
155 /* THRS_2 : critical */
156 if (intr & 0x010) {
157 nv84_therm_threshold_hyst_emulation(therm, 0x204c0, 22,
158 &sensor->thrs_critical,
159 NOUVEAU_THERM_THRS_CRITICAL);
160 intr &= ~0x010;
161 }
162
163 if (intr)
164 nv_error(therm, "unhandled intr 0x%08x\n", intr);
165
166 /* ACK everything */
167 nv_wr32(therm, 0x20100, 0xffffffff);
168 nv_wr32(therm, 0x1100, 0x10000); /* PBUS */
169
170 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
171}
172
173static int
174nv84_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)
178{
179 struct nv84_therm_priv *priv;
180 int ret;
181
182 ret = nouveau_therm_create(parent, engine, oclass, &priv);
183 *pobject = nv_object(priv);
184 if (ret)
185 return ret;
186
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;
194
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);
208
209 return nouveau_therm_preinit(&priv->base.base);
210}
211
212struct nouveau_oclass
213nv84_therm_oclass = {
214 .handle = NV_SUBDEV(THERM, 0x84),
215 .ofuncs = &(struct nouveau_ofuncs) {
216 .ctor = nv84_therm_ctor,
217 .dtor = _nouveau_therm_dtor,
218 .init = _nouveau_therm_init,
219 .fini = _nouveau_therm_fini,
220 },
221};
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nva3.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nva3.c
index 2dcc5437116a..d11a7c400813 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/nva3.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nva3.c
@@ -81,7 +81,7 @@ nva3_therm_ctor(struct nouveau_object *parent,
81 priv->base.base.pwm_get = nv50_fan_pwm_get; 81 priv->base.base.pwm_get = nv50_fan_pwm_get;
82 priv->base.base.pwm_set = nv50_fan_pwm_set; 82 priv->base.base.pwm_set = nv50_fan_pwm_set;
83 priv->base.base.pwm_clock = nv50_fan_pwm_clock; 83 priv->base.base.pwm_clock = nv50_fan_pwm_clock;
84 priv->base.base.temp_get = nv50_temp_get; 84 priv->base.base.temp_get = nv84_temp_get;
85 priv->base.base.fan_sense = nva3_therm_fan_sense; 85 priv->base.base.fan_sense = nva3_therm_fan_sense;
86 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling; 86 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling;
87 return nouveau_therm_preinit(&priv->base.base); 87 return nouveau_therm_preinit(&priv->base.base);
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nvd0.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nvd0.c
index d7d30ee8332e..54c28bdc4204 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/nvd0.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nvd0.c
@@ -135,7 +135,7 @@ nvd0_therm_ctor(struct nouveau_object *parent,
135 priv->base.base.pwm_get = nvd0_fan_pwm_get; 135 priv->base.base.pwm_get = nvd0_fan_pwm_get;
136 priv->base.base.pwm_set = nvd0_fan_pwm_set; 136 priv->base.base.pwm_set = nvd0_fan_pwm_set;
137 priv->base.base.pwm_clock = nvd0_fan_pwm_clock; 137 priv->base.base.pwm_clock = nvd0_fan_pwm_clock;
138 priv->base.base.temp_get = nv50_temp_get; 138 priv->base.base.temp_get = nv84_temp_get;
139 priv->base.base.fan_sense = nva3_therm_fan_sense; 139 priv->base.base.fan_sense = nva3_therm_fan_sense;
140 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling; 140 priv->base.sensor.program_alarms = nouveau_therm_program_alarms_polling;
141 return nouveau_therm_preinit(&priv->base.base); 141 return nouveau_therm_preinit(&priv->base.base);
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
index 438d9824b774..15ca64e481f1 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
@@ -134,11 +134,12 @@ void nouveau_therm_sensor_event(struct nouveau_therm *therm,
134 enum nouveau_therm_thrs_direction dir); 134 enum nouveau_therm_thrs_direction dir);
135void nouveau_therm_program_alarms_polling(struct nouveau_therm *therm); 135void nouveau_therm_program_alarms_polling(struct nouveau_therm *therm);
136 136
137void nv40_therm_intr(struct nouveau_subdev *);
137int nv50_fan_pwm_ctrl(struct nouveau_therm *, int, bool); 138int nv50_fan_pwm_ctrl(struct nouveau_therm *, int, bool);
138int nv50_fan_pwm_get(struct nouveau_therm *, int, u32 *, u32 *); 139int nv50_fan_pwm_get(struct nouveau_therm *, int, u32 *, u32 *);
139int nv50_fan_pwm_set(struct nouveau_therm *, int, u32, u32); 140int nv50_fan_pwm_set(struct nouveau_therm *, int, u32, u32);
140int nv50_fan_pwm_clock(struct nouveau_therm *); 141int nv50_fan_pwm_clock(struct nouveau_therm *);
141int nv50_temp_get(struct nouveau_therm *therm); 142int nv84_temp_get(struct nouveau_therm *therm);
142 143
143int nva3_therm_fan_sense(struct nouveau_therm *); 144int nva3_therm_fan_sense(struct nouveau_therm *);
144 145