aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMartin Peres <martin.peres@labri.fr>2012-09-02 19:37:02 -0400
committerBen Skeggs <bskeggs@redhat.com>2013-02-20 01:00:19 -0500
commit0cbf83bbe524d6014daf11005b99084d50489b80 (patch)
tree13986fb3fee9dc5ff8c2ac72dc38fddb01ab7532 /drivers
parent9c3bd3a53129639f10e129b007862340dba16a09 (diff)
drm/nouveau/fan: add toggle fan support
v2: change percent from int to atomic_t v3: random fixes v4 (Ben Skeggs): - adapted for split-out fan-control "protocol" structure - removed need for timer resched - support for forcing 'toggle' control on PWM boards Signed-off-by: Ben Skeggs <bskeggs@redhat.com> Signed-off-by: Martin Peres <martin.peres@labri.fr>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/nouveau/Makefile1
-rw-r--r--drivers/gpu/drm/nouveau/core/include/subdev/timer.h8
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/fan.c11
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/fantog.c117
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/priv.h2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/timer/nv04.c2
6 files changed, 132 insertions, 9 deletions
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile
index c58d66cbef4c..21c5d9a9806e 100644
--- a/drivers/gpu/drm/nouveau/Makefile
+++ b/drivers/gpu/drm/nouveau/Makefile
@@ -108,6 +108,7 @@ nouveau-y += core/subdev/therm/base.o
108nouveau-y += core/subdev/therm/fan.o 108nouveau-y += core/subdev/therm/fan.o
109nouveau-y += core/subdev/therm/fannil.o 109nouveau-y += core/subdev/therm/fannil.o
110nouveau-y += core/subdev/therm/fanpwm.o 110nouveau-y += core/subdev/therm/fanpwm.o
111nouveau-y += core/subdev/therm/fantog.o
111nouveau-y += core/subdev/therm/ic.o 112nouveau-y += core/subdev/therm/ic.o
112nouveau-y += core/subdev/therm/temp.o 113nouveau-y += core/subdev/therm/temp.o
113nouveau-y += core/subdev/therm/nv40.o 114nouveau-y += core/subdev/therm/nv40.o
diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/timer.h b/drivers/gpu/drm/nouveau/core/include/subdev/timer.h
index c24ec8ab3db4..e465d158d352 100644
--- a/drivers/gpu/drm/nouveau/core/include/subdev/timer.h
+++ b/drivers/gpu/drm/nouveau/core/include/subdev/timer.h
@@ -10,6 +10,14 @@ struct nouveau_alarm {
10 void (*func)(struct nouveau_alarm *); 10 void (*func)(struct nouveau_alarm *);
11}; 11};
12 12
13static inline void
14nouveau_alarm_init(struct nouveau_alarm *alarm,
15 void (*func)(struct nouveau_alarm *))
16{
17 INIT_LIST_HEAD(&alarm->head);
18 alarm->func = func;
19}
20
13bool nouveau_timer_wait_eq(void *, u64 nsec, u32 addr, u32 mask, u32 data); 21bool nouveau_timer_wait_eq(void *, u64 nsec, u32 addr, u32 mask, u32 data);
14bool nouveau_timer_wait_ne(void *, u64 nsec, u32 addr, u32 mask, u32 data); 22bool nouveau_timer_wait_ne(void *, u64 nsec, u32 addr, u32 mask, u32 data);
15bool nouveau_timer_wait_cb(void *, u64 nsec, bool (*func)(void *), void *data); 23bool nouveau_timer_wait_cb(void *, u64 nsec, bool (*func)(void *), void *data);
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
index e2fbddd56673..aed72a2d9198 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
@@ -149,7 +149,6 @@ nouveau_therm_fan_set_defaults(struct nouveau_therm *therm)
149 priv->fan->bios.max_duty = 100; 149 priv->fan->bios.max_duty = 100;
150} 150}
151 151
152
153static void 152static void
154nouveau_therm_fan_safety_checks(struct nouveau_therm *therm) 153nouveau_therm_fan_safety_checks(struct nouveau_therm *therm)
155{ 154{
@@ -164,11 +163,6 @@ nouveau_therm_fan_safety_checks(struct nouveau_therm *therm)
164 priv->fan->bios.min_duty = priv->fan->bios.max_duty; 163 priv->fan->bios.min_duty = priv->fan->bios.max_duty;
165} 164}
166 165
167int nouveau_fan_pwm_clock_dummy(struct nouveau_therm *therm)
168{
169 return 1;
170}
171
172int 166int
173nouveau_therm_fan_ctor(struct nouveau_therm *therm) 167nouveau_therm_fan_ctor(struct nouveau_therm *therm)
174{ 168{
@@ -182,7 +176,9 @@ nouveau_therm_fan_ctor(struct nouveau_therm *therm)
182 ret = gpio->find(gpio, 0, DCB_GPIO_PWM_FAN, 0xff, &func); 176 ret = gpio->find(gpio, 0, DCB_GPIO_PWM_FAN, 0xff, &func);
183 if (ret == 0) 177 if (ret == 0)
184 ret = nouveau_fanpwm_create(therm, &func); 178 ret = nouveau_fanpwm_create(therm, &func);
185 if (ret) 179 if (ret != 0)
180 ret = nouveau_fantog_create(therm, &func);
181 if (ret != 0)
186 ret = nouveau_fannil_create(therm); 182 ret = nouveau_fannil_create(therm);
187 if (ret) 183 if (ret)
188 return ret; 184 return ret;
@@ -202,6 +198,5 @@ nouveau_therm_fan_ctor(struct nouveau_therm *therm)
202 nouveau_therm_fan_safety_checks(therm); 198 nouveau_therm_fan_safety_checks(therm);
203 199
204 nouveau_therm_fan_set_mode(therm, FAN_CONTROL_NONE); 200 nouveau_therm_fan_set_mode(therm, FAN_CONTROL_NONE);
205
206 return 0; 201 return 0;
207} 202}
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/fantog.c b/drivers/gpu/drm/nouveau/core/subdev/therm/fantog.c
new file mode 100644
index 000000000000..b08e4e2b33e6
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/fantog.c
@@ -0,0 +1,117 @@
1/*
2 * Copyright 2012 The Nouveau community
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: Martin Peres
23 */
24
25#include "priv.h"
26
27#include <core/object.h>
28#include <core/device.h>
29
30#include <subdev/gpio.h>
31#include <subdev/timer.h>
32
33struct nouveau_fantog_priv {
34 struct nouveau_fan base;
35 struct nouveau_therm *parent;
36 struct nouveau_alarm alarm;
37 spinlock_t lock;
38 u32 period_us;
39 u32 percent;
40 struct dcb_gpio_func func;
41};
42
43static void
44nouveau_fantog_update(struct nouveau_fantog_priv *priv, int percent)
45{
46 struct nouveau_therm_priv *tpriv = (void *)priv->parent;
47 struct nouveau_timer *ptimer = nouveau_timer(tpriv);
48 struct nouveau_gpio *gpio = nouveau_gpio(tpriv);
49 unsigned long flags;
50 int duty;
51
52 spin_lock_irqsave(&priv->lock, flags);
53 if (percent < 0)
54 percent = priv->percent;
55 priv->percent = percent;
56
57 duty = !gpio->get(gpio, 0, DCB_GPIO_PWM_FAN, 0xff);
58 gpio->set(gpio, 0, DCB_GPIO_PWM_FAN, 0xff, duty);
59
60 if (list_empty(&priv->alarm.head) && percent != (duty * 100)) {
61 u64 next_change = (percent * priv->period_us) / 100;
62 if (!duty)
63 next_change = priv->period_us - next_change;
64 ptimer->alarm(ptimer, next_change * 1000, &priv->alarm);
65 }
66 spin_unlock_irqrestore(&priv->lock, flags);
67}
68
69static void
70nouveau_fantog_alarm(struct nouveau_alarm *alarm)
71{
72 struct nouveau_fantog_priv *priv =
73 container_of(alarm, struct nouveau_fantog_priv, alarm);
74 nouveau_fantog_update(priv, -1);
75}
76
77static int
78nouveau_fantog_get(struct nouveau_therm *therm)
79{
80 struct nouveau_therm_priv *tpriv = (void *)therm;
81 struct nouveau_fantog_priv *priv = (void *)tpriv->fan;
82 return priv->percent;
83}
84
85int
86nouveau_fantog_set(struct nouveau_therm *therm, int percent)
87{
88 struct nouveau_therm_priv *tpriv = (void *)therm;
89 struct nouveau_fantog_priv *priv = (void *)tpriv->fan;
90 if (therm->pwm_ctrl)
91 therm->pwm_ctrl(therm, priv->func.line, false);
92 nouveau_fantog_update(priv, percent);
93 return 0;
94}
95
96int
97nouveau_fantog_create(struct nouveau_therm *therm, struct dcb_gpio_func *func)
98{
99 struct nouveau_therm_priv *tpriv = (void *)therm;
100 struct nouveau_fantog_priv *priv;
101
102 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
103 tpriv->fan = &priv->base;
104 if (!priv)
105 return -ENOMEM;
106
107 priv->parent = therm;
108 priv->base.type = "toggle";
109 priv->base.get = nouveau_fantog_get;
110 priv->base.set = nouveau_fantog_set;
111 nouveau_alarm_init(&priv->alarm, nouveau_fantog_alarm);
112 priv->period_us = 100000; /* 10Hz */
113 priv->percent = 100;
114 priv->func = *func;
115 spin_lock_init(&priv->lock);
116 return 0;
117}
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
index fa939323a512..34c85e62685d 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
@@ -31,6 +31,7 @@
31#include <subdev/bios/gpio.h> 31#include <subdev/bios/gpio.h>
32#include <subdev/bios/perf.h> 32#include <subdev/bios/perf.h>
33#include <subdev/bios/therm.h> 33#include <subdev/bios/therm.h>
34#include <subdev/timer.h>
34 35
35struct nouveau_fan { 36struct nouveau_fan {
36 const char *type; 37 const char *type;
@@ -89,6 +90,7 @@ int nv50_temp_get(struct nouveau_therm *therm);
89int nva3_therm_fan_sense(struct nouveau_therm *); 90int nva3_therm_fan_sense(struct nouveau_therm *);
90 91
91int nouveau_fanpwm_create(struct nouveau_therm *, struct dcb_gpio_func *); 92int nouveau_fanpwm_create(struct nouveau_therm *, struct dcb_gpio_func *);
93int nouveau_fantog_create(struct nouveau_therm *, struct dcb_gpio_func *);
92int nouveau_fannil_create(struct nouveau_therm *); 94int nouveau_fannil_create(struct nouveau_therm *);
93 95
94#endif 96#endif
diff --git a/drivers/gpu/drm/nouveau/core/subdev/timer/nv04.c b/drivers/gpu/drm/nouveau/core/subdev/timer/nv04.c
index c26ca9bef671..8e1bae4f12e8 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/timer/nv04.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/timer/nv04.c
@@ -79,7 +79,7 @@ nv04_timer_alarm_trigger(struct nouveau_timer *ptimer)
79 79
80 /* execute any pending alarm handlers */ 80 /* execute any pending alarm handlers */
81 list_for_each_entry_safe(alarm, atemp, &exec, head) { 81 list_for_each_entry_safe(alarm, atemp, &exec, head) {
82 list_del(&alarm->head); 82 list_del_init(&alarm->head);
83 alarm->func(alarm); 83 alarm->func(alarm);
84 } 84 }
85} 85}