Commit | Line | Data |
---|---|---|
aa1b9b48 MP |
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 <core/object.h> | |
26 | #include <core/device.h> | |
27 | ||
28 | #include <subdev/bios.h> | |
29 | ||
30 | #include "priv.h" | |
31 | ||
32 | int | |
33 | nouveau_therm_attr_get(struct nouveau_therm *therm, | |
34 | enum nouveau_therm_attr_type type) | |
35 | { | |
36 | struct nouveau_therm_priv *priv = (void *)therm; | |
37 | ||
38 | switch (type) { | |
39 | case NOUVEAU_THERM_ATTR_FAN_MIN_DUTY: | |
9c3bd3a5 | 40 | return priv->fan->bios.min_duty; |
aa1b9b48 | 41 | case NOUVEAU_THERM_ATTR_FAN_MAX_DUTY: |
9c3bd3a5 | 42 | return priv->fan->bios.max_duty; |
2f951a5d | 43 | case NOUVEAU_THERM_ATTR_FAN_MODE: |
9c3bd3a5 | 44 | return priv->fan->mode; |
aa1b9b48 MP |
45 | case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST: |
46 | return priv->bios_sensor.thrs_fan_boost.temp; | |
47 | case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST: | |
48 | return priv->bios_sensor.thrs_fan_boost.hysteresis; | |
49 | case NOUVEAU_THERM_ATTR_THRS_DOWN_CLK: | |
50 | return priv->bios_sensor.thrs_down_clock.temp; | |
51 | case NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST: | |
52 | return priv->bios_sensor.thrs_down_clock.hysteresis; | |
53 | case NOUVEAU_THERM_ATTR_THRS_CRITICAL: | |
54 | return priv->bios_sensor.thrs_critical.temp; | |
55 | case NOUVEAU_THERM_ATTR_THRS_CRITICAL_HYST: | |
56 | return priv->bios_sensor.thrs_critical.hysteresis; | |
57 | case NOUVEAU_THERM_ATTR_THRS_SHUTDOWN: | |
58 | return priv->bios_sensor.thrs_shutdown.temp; | |
59 | case NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST: | |
60 | return priv->bios_sensor.thrs_shutdown.hysteresis; | |
61 | } | |
62 | ||
63 | return -EINVAL; | |
64 | } | |
65 | ||
66 | int | |
67 | nouveau_therm_attr_set(struct nouveau_therm *therm, | |
68 | enum nouveau_therm_attr_type type, int value) | |
69 | { | |
70 | struct nouveau_therm_priv *priv = (void *)therm; | |
71 | ||
72 | switch (type) { | |
73 | case NOUVEAU_THERM_ATTR_FAN_MIN_DUTY: | |
74 | if (value < 0) | |
75 | value = 0; | |
9c3bd3a5 BS |
76 | if (value > priv->fan->bios.max_duty) |
77 | value = priv->fan->bios.max_duty; | |
78 | priv->fan->bios.min_duty = value; | |
aa1b9b48 MP |
79 | return 0; |
80 | case NOUVEAU_THERM_ATTR_FAN_MAX_DUTY: | |
81 | if (value < 0) | |
82 | value = 0; | |
9c3bd3a5 BS |
83 | if (value < priv->fan->bios.min_duty) |
84 | value = priv->fan->bios.min_duty; | |
85 | priv->fan->bios.max_duty = value; | |
aa1b9b48 | 86 | return 0; |
2f951a5d MP |
87 | case NOUVEAU_THERM_ATTR_FAN_MODE: |
88 | return nouveau_therm_fan_set_mode(therm, value); | |
aa1b9b48 MP |
89 | case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST: |
90 | priv->bios_sensor.thrs_fan_boost.temp = value; | |
91 | return 0; | |
92 | case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST_HYST: | |
93 | priv->bios_sensor.thrs_fan_boost.hysteresis = value; | |
94 | return 0; | |
95 | case NOUVEAU_THERM_ATTR_THRS_DOWN_CLK: | |
96 | priv->bios_sensor.thrs_down_clock.temp = value; | |
97 | return 0; | |
98 | case NOUVEAU_THERM_ATTR_THRS_DOWN_CLK_HYST: | |
99 | priv->bios_sensor.thrs_down_clock.hysteresis = value; | |
100 | return 0; | |
101 | case NOUVEAU_THERM_ATTR_THRS_CRITICAL: | |
102 | priv->bios_sensor.thrs_critical.temp = value; | |
103 | return 0; | |
104 | case NOUVEAU_THERM_ATTR_THRS_CRITICAL_HYST: | |
105 | priv->bios_sensor.thrs_critical.hysteresis = value; | |
106 | return 0; | |
107 | case NOUVEAU_THERM_ATTR_THRS_SHUTDOWN: | |
108 | priv->bios_sensor.thrs_shutdown.temp = value; | |
109 | return 0; | |
110 | case NOUVEAU_THERM_ATTR_THRS_SHUTDOWN_HYST: | |
111 | priv->bios_sensor.thrs_shutdown.hysteresis = value; | |
112 | return 0; | |
113 | } | |
114 | ||
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | int | |
5f066c32 | 119 | _nouveau_therm_init(struct nouveau_object *object) |
aa1b9b48 MP |
120 | { |
121 | struct nouveau_therm *therm = (void *)object; | |
122 | struct nouveau_therm_priv *priv = (void *)therm; | |
123 | int ret; | |
124 | ||
125 | ret = nouveau_subdev_init(&therm->base); | |
126 | if (ret) | |
127 | return ret; | |
128 | ||
9c3bd3a5 BS |
129 | if (priv->fan->percent >= 0) |
130 | therm->fan_set(therm, priv->fan->percent); | |
aa1b9b48 MP |
131 | |
132 | return 0; | |
133 | } | |
134 | ||
135 | int | |
5f066c32 | 136 | _nouveau_therm_fini(struct nouveau_object *object, bool suspend) |
aa1b9b48 MP |
137 | { |
138 | struct nouveau_therm *therm = (void *)object; | |
139 | struct nouveau_therm_priv *priv = (void *)therm; | |
140 | ||
9c3bd3a5 | 141 | priv->fan->percent = therm->fan_get(therm); |
aa1b9b48 MP |
142 | |
143 | return nouveau_subdev_fini(&therm->base, suspend); | |
144 | } | |
5f066c32 BS |
145 | |
146 | int | |
147 | nouveau_therm_create_(struct nouveau_object *parent, | |
148 | struct nouveau_object *engine, | |
149 | struct nouveau_oclass *oclass, | |
150 | int length, void **pobject) | |
151 | { | |
152 | struct nouveau_therm_priv *priv; | |
153 | int ret; | |
154 | ||
155 | ret = nouveau_subdev_create_(parent, engine, oclass, 0, "PTHERM", | |
156 | "therm", length, pobject); | |
157 | priv = *pobject; | |
158 | if (ret) | |
159 | return ret; | |
160 | ||
5f066c32 BS |
161 | priv->base.fan_get = nouveau_therm_fan_user_get; |
162 | priv->base.fan_set = nouveau_therm_fan_user_set; | |
163 | priv->base.fan_sense = nouveau_therm_fan_sense; | |
164 | priv->base.attr_get = nouveau_therm_attr_get; | |
165 | priv->base.attr_set = nouveau_therm_attr_set; | |
166 | return 0; | |
167 | } | |
9c3bd3a5 BS |
168 | |
169 | int | |
170 | nouveau_therm_preinit(struct nouveau_therm *therm) | |
171 | { | |
172 | nouveau_therm_ic_ctor(therm); | |
173 | nouveau_therm_sensor_ctor(therm); | |
174 | nouveau_therm_fan_ctor(therm); | |
175 | return 0; | |
176 | } | |
177 | ||
178 | void | |
179 | _nouveau_therm_dtor(struct nouveau_object *object) | |
180 | { | |
181 | struct nouveau_therm_priv *priv = (void *)object; | |
182 | kfree(priv->fan); | |
183 | nouveau_subdev_destroy(&priv->base.base); | |
184 | } |