diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2012-07-31 02:16:21 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2012-10-02 23:12:59 -0400 |
commit | 77145f1cbdf8d28b46ff8070ca749bad821e0774 (patch) | |
tree | b496d5d69ce4f5753028b07b09d8cf12025310f2 /drivers/gpu/drm/nouveau/nouveau_pm.c | |
parent | 2094dd82eddc468b53ee99d92c38b23a65efac03 (diff) |
drm/nouveau: port remainder of drm code, and rip out compat layer
v2: Ben Skeggs <bskeggs@redhat.com>
- fill in nouveau_pm.dev to prevent oops
- fix ppc issues (build + OF shadow)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_pm.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_pm.c | 254 |
1 files changed, 160 insertions, 94 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c index 539e81c416cd..3c55ec2366d3 100644 --- a/drivers/gpu/drm/nouveau/nouveau_pm.c +++ b/drivers/gpu/drm/nouveau/nouveau_pm.c | |||
@@ -22,12 +22,6 @@ | |||
22 | * Authors: Ben Skeggs | 22 | * Authors: Ben Skeggs |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "drmP.h" | ||
26 | |||
27 | #include "nouveau_drv.h" | ||
28 | #include "nouveau_pm.h" | ||
29 | #include <subdev/bios/gpio.h> | ||
30 | |||
31 | #ifdef CONFIG_ACPI | 25 | #ifdef CONFIG_ACPI |
32 | #include <linux/acpi.h> | 26 | #include <linux/acpi.h> |
33 | #endif | 27 | #endif |
@@ -35,29 +29,48 @@ | |||
35 | #include <linux/hwmon.h> | 29 | #include <linux/hwmon.h> |
36 | #include <linux/hwmon-sysfs.h> | 30 | #include <linux/hwmon-sysfs.h> |
37 | 31 | ||
32 | #include "drmP.h" | ||
33 | |||
34 | #include "nouveau_drm.h" | ||
35 | #include "nouveau_pm.h" | ||
36 | |||
37 | #include <subdev/bios/gpio.h> | ||
38 | #include <subdev/gpio.h> | ||
39 | #include <subdev/timer.h> | ||
40 | |||
41 | MODULE_PARM_DESC(perflvl, "Performance level (default: boot)"); | ||
42 | static char *nouveau_perflvl; | ||
43 | module_param_named(perflvl, nouveau_perflvl, charp, 0400); | ||
44 | |||
45 | MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)"); | ||
46 | static int nouveau_perflvl_wr; | ||
47 | module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400); | ||
48 | |||
38 | static int | 49 | static int |
39 | nouveau_pwmfan_get(struct drm_device *dev) | 50 | nouveau_pwmfan_get(struct drm_device *dev) |
40 | { | 51 | { |
41 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 52 | struct nouveau_pm *pm = nouveau_pm(dev); |
42 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 53 | struct nouveau_drm *drm = nouveau_drm(dev); |
43 | struct dcb_gpio_func gpio; | 54 | struct nouveau_device *device = nv_device(drm->device); |
55 | struct nouveau_gpio *gpio = nouveau_gpio(device); | ||
56 | struct dcb_gpio_func func; | ||
44 | u32 divs, duty; | 57 | u32 divs, duty; |
45 | int ret; | 58 | int ret; |
46 | 59 | ||
47 | if (!pm->pwm_get) | 60 | if (!pm->pwm_get) |
48 | return -ENODEV; | 61 | return -ENODEV; |
49 | 62 | ||
50 | ret = nouveau_gpio_find(dev, 0, DCB_GPIO_PWM_FAN, 0xff, &gpio); | 63 | ret = gpio->find(gpio, 0, DCB_GPIO_PWM_FAN, 0xff, &func); |
51 | if (ret == 0) { | 64 | if (ret == 0) { |
52 | ret = pm->pwm_get(dev, gpio.line, &divs, &duty); | 65 | ret = pm->pwm_get(dev, func.line, &divs, &duty); |
53 | if (ret == 0 && divs) { | 66 | if (ret == 0 && divs) { |
54 | divs = max(divs, duty); | 67 | divs = max(divs, duty); |
55 | if (dev_priv->card_type <= NV_40 || (gpio.log[0] & 1)) | 68 | if (device->card_type <= NV_40 || (func.log[0] & 1)) |
56 | duty = divs - duty; | 69 | duty = divs - duty; |
57 | return (duty * 100) / divs; | 70 | return (duty * 100) / divs; |
58 | } | 71 | } |
59 | 72 | ||
60 | return nouveau_gpio_func_get(dev, gpio.func) * 100; | 73 | return gpio->get(gpio, 0, func.func, func.line) * 100; |
61 | } | 74 | } |
62 | 75 | ||
63 | return -ENODEV; | 76 | return -ENODEV; |
@@ -66,30 +79,32 @@ nouveau_pwmfan_get(struct drm_device *dev) | |||
66 | static int | 79 | static int |
67 | nouveau_pwmfan_set(struct drm_device *dev, int percent) | 80 | nouveau_pwmfan_set(struct drm_device *dev, int percent) |
68 | { | 81 | { |
69 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 82 | struct nouveau_pm *pm = nouveau_pm(dev); |
70 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 83 | struct nouveau_drm *drm = nouveau_drm(dev); |
71 | struct dcb_gpio_func gpio; | 84 | struct nouveau_device *device = nv_device(drm->device); |
85 | struct nouveau_gpio *gpio = nouveau_gpio(device); | ||
86 | struct dcb_gpio_func func; | ||
72 | u32 divs, duty; | 87 | u32 divs, duty; |
73 | int ret; | 88 | int ret; |
74 | 89 | ||
75 | if (!pm->pwm_set) | 90 | if (!pm->pwm_set) |
76 | return -ENODEV; | 91 | return -ENODEV; |
77 | 92 | ||
78 | ret = nouveau_gpio_find(dev, 0, DCB_GPIO_PWM_FAN, 0xff, &gpio); | 93 | ret = gpio->find(gpio, 0, DCB_GPIO_PWM_FAN, 0xff, &func); |
79 | if (ret == 0) { | 94 | if (ret == 0) { |
80 | divs = pm->fan.pwm_divisor; | 95 | divs = pm->fan.pwm_divisor; |
81 | if (pm->fan.pwm_freq) { | 96 | if (pm->fan.pwm_freq) { |
82 | /*XXX: PNVIO clock more than likely... */ | 97 | /*XXX: PNVIO clock more than likely... */ |
83 | divs = 135000 / pm->fan.pwm_freq; | 98 | divs = 135000 / pm->fan.pwm_freq; |
84 | if (dev_priv->chipset < 0xa3) | 99 | if (nv_device(drm->device)->chipset < 0xa3) |
85 | divs /= 4; | 100 | divs /= 4; |
86 | } | 101 | } |
87 | 102 | ||
88 | duty = ((divs * percent) + 99) / 100; | 103 | duty = ((divs * percent) + 99) / 100; |
89 | if (dev_priv->card_type <= NV_40 || (gpio.log[0] & 1)) | 104 | if (device->card_type <= NV_40 || (func.log[0] & 1)) |
90 | duty = divs - duty; | 105 | duty = divs - duty; |
91 | 106 | ||
92 | ret = pm->pwm_set(dev, gpio.line, divs, duty); | 107 | ret = pm->pwm_set(dev, func.line, divs, duty); |
93 | if (!ret) | 108 | if (!ret) |
94 | pm->fan.percent = percent; | 109 | pm->fan.percent = percent; |
95 | return ret; | 110 | return ret; |
@@ -102,8 +117,8 @@ static int | |||
102 | nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, | 117 | nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, |
103 | struct nouveau_pm_level *a, struct nouveau_pm_level *b) | 118 | struct nouveau_pm_level *a, struct nouveau_pm_level *b) |
104 | { | 119 | { |
105 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 120 | struct nouveau_drm *drm = nouveau_drm(dev); |
106 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 121 | struct nouveau_pm *pm = nouveau_pm(dev); |
107 | int ret; | 122 | int ret; |
108 | 123 | ||
109 | /*XXX: not on all boards, we should control based on temperature | 124 | /*XXX: not on all boards, we should control based on temperature |
@@ -113,7 +128,7 @@ nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, | |||
113 | if (a->fanspeed && b->fanspeed && b->fanspeed > a->fanspeed) { | 128 | if (a->fanspeed && b->fanspeed && b->fanspeed > a->fanspeed) { |
114 | ret = nouveau_pwmfan_set(dev, perflvl->fanspeed); | 129 | ret = nouveau_pwmfan_set(dev, perflvl->fanspeed); |
115 | if (ret && ret != -ENODEV) { | 130 | if (ret && ret != -ENODEV) { |
116 | NV_ERROR(dev, "fanspeed set failed: %d\n", ret); | 131 | NV_ERROR(drm, "fanspeed set failed: %d\n", ret); |
117 | return ret; | 132 | return ret; |
118 | } | 133 | } |
119 | } | 134 | } |
@@ -122,7 +137,7 @@ nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, | |||
122 | if (perflvl->volt_min && b->volt_min > a->volt_min) { | 137 | if (perflvl->volt_min && b->volt_min > a->volt_min) { |
123 | ret = pm->voltage_set(dev, perflvl->volt_min); | 138 | ret = pm->voltage_set(dev, perflvl->volt_min); |
124 | if (ret) { | 139 | if (ret) { |
125 | NV_ERROR(dev, "voltage set failed: %d\n", ret); | 140 | NV_ERROR(drm, "voltage set failed: %d\n", ret); |
126 | return ret; | 141 | return ret; |
127 | } | 142 | } |
128 | } | 143 | } |
@@ -134,8 +149,7 @@ nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, | |||
134 | static int | 149 | static int |
135 | nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl) | 150 | nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
136 | { | 151 | { |
137 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 152 | struct nouveau_pm *pm = nouveau_pm(dev); |
138 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
139 | void *state; | 153 | void *state; |
140 | int ret; | 154 | int ret; |
141 | 155 | ||
@@ -171,8 +185,9 @@ error: | |||
171 | void | 185 | void |
172 | nouveau_pm_trigger(struct drm_device *dev) | 186 | nouveau_pm_trigger(struct drm_device *dev) |
173 | { | 187 | { |
174 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 188 | struct nouveau_drm *drm = nouveau_drm(dev); |
175 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 189 | struct nouveau_timer *ptimer = nouveau_timer(drm->device); |
190 | struct nouveau_pm *pm = nouveau_pm(dev); | ||
176 | struct nouveau_pm_profile *profile = NULL; | 191 | struct nouveau_pm_profile *profile = NULL; |
177 | struct nouveau_pm_level *perflvl = NULL; | 192 | struct nouveau_pm_level *perflvl = NULL; |
178 | int ret; | 193 | int ret; |
@@ -194,23 +209,22 @@ nouveau_pm_trigger(struct drm_device *dev) | |||
194 | 209 | ||
195 | /* change perflvl, if necessary */ | 210 | /* change perflvl, if necessary */ |
196 | if (perflvl != pm->cur) { | 211 | if (perflvl != pm->cur) { |
197 | u64 time0 = nv_timer_read(dev); | 212 | u64 time0 = ptimer->read(ptimer); |
198 | 213 | ||
199 | NV_INFO(dev, "setting performance level: %d", perflvl->id); | 214 | NV_INFO(drm, "setting performance level: %d", perflvl->id); |
200 | ret = nouveau_pm_perflvl_set(dev, perflvl); | 215 | ret = nouveau_pm_perflvl_set(dev, perflvl); |
201 | if (ret) | 216 | if (ret) |
202 | NV_INFO(dev, "> reclocking failed: %d\n\n", ret); | 217 | NV_INFO(drm, "> reclocking failed: %d\n\n", ret); |
203 | 218 | ||
204 | NV_INFO(dev, "> reclocking took %lluns\n\n", | 219 | NV_INFO(drm, "> reclocking took %lluns\n\n", |
205 | nv_timer_read(dev) - time0); | 220 | ptimer->read(ptimer) - time0); |
206 | } | 221 | } |
207 | } | 222 | } |
208 | 223 | ||
209 | static struct nouveau_pm_profile * | 224 | static struct nouveau_pm_profile * |
210 | profile_find(struct drm_device *dev, const char *string) | 225 | profile_find(struct drm_device *dev, const char *string) |
211 | { | 226 | { |
212 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 227 | struct nouveau_pm *pm = nouveau_pm(dev); |
213 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
214 | struct nouveau_pm_profile *profile; | 228 | struct nouveau_pm_profile *profile; |
215 | 229 | ||
216 | list_for_each_entry(profile, &pm->profiles, head) { | 230 | list_for_each_entry(profile, &pm->profiles, head) { |
@@ -224,8 +238,7 @@ profile_find(struct drm_device *dev, const char *string) | |||
224 | static int | 238 | static int |
225 | nouveau_pm_profile_set(struct drm_device *dev, const char *profile) | 239 | nouveau_pm_profile_set(struct drm_device *dev, const char *profile) |
226 | { | 240 | { |
227 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 241 | struct nouveau_pm *pm = nouveau_pm(dev); |
228 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
229 | struct nouveau_pm_profile *ac = NULL, *dc = NULL; | 242 | struct nouveau_pm_profile *ac = NULL, *dc = NULL; |
230 | char string[16], *cur = string, *ptr; | 243 | char string[16], *cur = string, *ptr; |
231 | 244 | ||
@@ -278,8 +291,7 @@ const struct nouveau_pm_profile_func nouveau_pm_static_profile_func = { | |||
278 | static int | 291 | static int |
279 | nouveau_pm_perflvl_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) | 292 | nouveau_pm_perflvl_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
280 | { | 293 | { |
281 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 294 | struct nouveau_pm *pm = nouveau_pm(dev); |
282 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
283 | int ret; | 295 | int ret; |
284 | 296 | ||
285 | memset(perflvl, 0, sizeof(*perflvl)); | 297 | memset(perflvl, 0, sizeof(*perflvl)); |
@@ -361,8 +373,7 @@ static ssize_t | |||
361 | nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf) | 373 | nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf) |
362 | { | 374 | { |
363 | struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); | 375 | struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); |
364 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 376 | struct nouveau_pm *pm = nouveau_pm(dev); |
365 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
366 | struct nouveau_pm_level cur; | 377 | struct nouveau_pm_level cur; |
367 | int len = PAGE_SIZE, ret; | 378 | int len = PAGE_SIZE, ret; |
368 | char *ptr = buf; | 379 | char *ptr = buf; |
@@ -397,8 +408,8 @@ static DEVICE_ATTR(performance_level, S_IRUGO | S_IWUSR, | |||
397 | static int | 408 | static int |
398 | nouveau_sysfs_init(struct drm_device *dev) | 409 | nouveau_sysfs_init(struct drm_device *dev) |
399 | { | 410 | { |
400 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 411 | struct nouveau_drm *drm = nouveau_drm(dev); |
401 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 412 | struct nouveau_pm *pm = nouveau_pm(dev); |
402 | struct device *d = &dev->pdev->dev; | 413 | struct device *d = &dev->pdev->dev; |
403 | int ret, i; | 414 | int ret, i; |
404 | 415 | ||
@@ -417,7 +428,7 @@ nouveau_sysfs_init(struct drm_device *dev) | |||
417 | 428 | ||
418 | ret = device_create_file(d, &perflvl->dev_attr); | 429 | ret = device_create_file(d, &perflvl->dev_attr); |
419 | if (ret) { | 430 | if (ret) { |
420 | NV_ERROR(dev, "failed pervlvl %d sysfs: %d\n", | 431 | NV_ERROR(drm, "failed pervlvl %d sysfs: %d\n", |
421 | perflvl->id, i); | 432 | perflvl->id, i); |
422 | perflvl->dev_attr.attr.name = NULL; | 433 | perflvl->dev_attr.attr.name = NULL; |
423 | nouveau_pm_fini(dev); | 434 | nouveau_pm_fini(dev); |
@@ -431,8 +442,7 @@ nouveau_sysfs_init(struct drm_device *dev) | |||
431 | static void | 442 | static void |
432 | nouveau_sysfs_fini(struct drm_device *dev) | 443 | nouveau_sysfs_fini(struct drm_device *dev) |
433 | { | 444 | { |
434 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 445 | struct nouveau_pm *pm = nouveau_pm(dev); |
435 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
436 | struct device *d = &dev->pdev->dev; | 446 | struct device *d = &dev->pdev->dev; |
437 | int i; | 447 | int i; |
438 | 448 | ||
@@ -452,8 +462,7 @@ static ssize_t | |||
452 | nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) | 462 | nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) |
453 | { | 463 | { |
454 | struct drm_device *dev = dev_get_drvdata(d); | 464 | struct drm_device *dev = dev_get_drvdata(d); |
455 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 465 | struct nouveau_pm *pm = nouveau_pm(dev); |
456 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
457 | 466 | ||
458 | return snprintf(buf, PAGE_SIZE, "%d\n", pm->temp_get(dev)*1000); | 467 | return snprintf(buf, PAGE_SIZE, "%d\n", pm->temp_get(dev)*1000); |
459 | } | 468 | } |
@@ -464,8 +473,7 @@ static ssize_t | |||
464 | nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) | 473 | nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) |
465 | { | 474 | { |
466 | struct drm_device *dev = dev_get_drvdata(d); | 475 | struct drm_device *dev = dev_get_drvdata(d); |
467 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 476 | struct nouveau_pm *pm = nouveau_pm(dev); |
468 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
469 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; | 477 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; |
470 | 478 | ||
471 | return snprintf(buf, PAGE_SIZE, "%d\n", temp->down_clock*1000); | 479 | return snprintf(buf, PAGE_SIZE, "%d\n", temp->down_clock*1000); |
@@ -475,8 +483,7 @@ nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, | |||
475 | const char *buf, size_t count) | 483 | const char *buf, size_t count) |
476 | { | 484 | { |
477 | struct drm_device *dev = dev_get_drvdata(d); | 485 | struct drm_device *dev = dev_get_drvdata(d); |
478 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 486 | struct nouveau_pm *pm = nouveau_pm(dev); |
479 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
480 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; | 487 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; |
481 | long value; | 488 | long value; |
482 | 489 | ||
@@ -498,8 +505,7 @@ nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a, | |||
498 | char *buf) | 505 | char *buf) |
499 | { | 506 | { |
500 | struct drm_device *dev = dev_get_drvdata(d); | 507 | struct drm_device *dev = dev_get_drvdata(d); |
501 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 508 | struct nouveau_pm *pm = nouveau_pm(dev); |
502 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
503 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; | 509 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; |
504 | 510 | ||
505 | return snprintf(buf, PAGE_SIZE, "%d\n", temp->critical*1000); | 511 | return snprintf(buf, PAGE_SIZE, "%d\n", temp->critical*1000); |
@@ -510,8 +516,7 @@ nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a, | |||
510 | size_t count) | 516 | size_t count) |
511 | { | 517 | { |
512 | struct drm_device *dev = dev_get_drvdata(d); | 518 | struct drm_device *dev = dev_get_drvdata(d); |
513 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 519 | struct nouveau_pm *pm = nouveau_pm(dev); |
514 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
515 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; | 520 | struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp; |
516 | long value; | 521 | long value; |
517 | 522 | ||
@@ -552,28 +557,32 @@ nouveau_hwmon_show_fan0_input(struct device *d, struct device_attribute *attr, | |||
552 | char *buf) | 557 | char *buf) |
553 | { | 558 | { |
554 | struct drm_device *dev = dev_get_drvdata(d); | 559 | struct drm_device *dev = dev_get_drvdata(d); |
560 | struct nouveau_drm *drm = nouveau_drm(dev); | ||
561 | struct nouveau_timer *ptimer = nouveau_timer(drm->device); | ||
562 | struct nouveau_gpio *gpio = nouveau_gpio(drm->device); | ||
563 | struct dcb_gpio_func func; | ||
555 | u32 cycles, cur, prev; | 564 | u32 cycles, cur, prev; |
556 | u64 start; | 565 | u64 start; |
557 | 566 | ||
558 | if (!nouveau_gpio_func_valid(dev, DCB_GPIO_FAN_SENSE)) | 567 | if (gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func)) |
559 | return -ENODEV; | 568 | return -ENODEV; |
560 | 569 | ||
561 | /* Monitor the GPIO input 0x3b for 250ms. | 570 | /* Monitor the GPIO input 0x3b for 250ms. |
562 | * When the fan spins, it changes the value of GPIO FAN_SENSE. | 571 | * When the fan spins, it changes the value of GPIO FAN_SENSE. |
563 | * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation. | 572 | * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation. |
564 | */ | 573 | */ |
565 | start = nv_timer_read(dev); | 574 | start = ptimer->read(ptimer); |
566 | prev = nouveau_gpio_func_get(dev, DCB_GPIO_FAN_SENSE); | 575 | prev = gpio->get(gpio, 0, func.func, func.line); |
567 | cycles = 0; | 576 | cycles = 0; |
568 | do { | 577 | do { |
569 | cur = nouveau_gpio_func_get(dev, DCB_GPIO_FAN_SENSE); | 578 | cur = gpio->get(gpio, 0, func.func, func.line); |
570 | if (prev != cur) { | 579 | if (prev != cur) { |
571 | cycles++; | 580 | cycles++; |
572 | prev = cur; | 581 | prev = cur; |
573 | } | 582 | } |
574 | 583 | ||
575 | usleep_range(500, 1000); /* supports 0 < rpm < 7500 */ | 584 | usleep_range(500, 1000); /* supports 0 < rpm < 7500 */ |
576 | } while (nv_timer_read(dev) - start < 250000000); | 585 | } while (ptimer->read(ptimer) - start < 250000000); |
577 | 586 | ||
578 | /* interpolate to get rpm */ | 587 | /* interpolate to get rpm */ |
579 | return sprintf(buf, "%i\n", cycles / 4 * 4 * 60); | 588 | return sprintf(buf, "%i\n", cycles / 4 * 4 * 60); |
@@ -599,8 +608,7 @@ nouveau_hwmon_set_pwm0(struct device *d, struct device_attribute *a, | |||
599 | const char *buf, size_t count) | 608 | const char *buf, size_t count) |
600 | { | 609 | { |
601 | struct drm_device *dev = dev_get_drvdata(d); | 610 | struct drm_device *dev = dev_get_drvdata(d); |
602 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 611 | struct nouveau_pm *pm = nouveau_pm(dev); |
603 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
604 | int ret = -ENODEV; | 612 | int ret = -ENODEV; |
605 | long value; | 613 | long value; |
606 | 614 | ||
@@ -631,8 +639,7 @@ nouveau_hwmon_get_pwm0_min(struct device *d, | |||
631 | struct device_attribute *a, char *buf) | 639 | struct device_attribute *a, char *buf) |
632 | { | 640 | { |
633 | struct drm_device *dev = dev_get_drvdata(d); | 641 | struct drm_device *dev = dev_get_drvdata(d); |
634 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 642 | struct nouveau_pm *pm = nouveau_pm(dev); |
635 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
636 | 643 | ||
637 | return sprintf(buf, "%i\n", pm->fan.min_duty); | 644 | return sprintf(buf, "%i\n", pm->fan.min_duty); |
638 | } | 645 | } |
@@ -642,8 +649,7 @@ nouveau_hwmon_set_pwm0_min(struct device *d, struct device_attribute *a, | |||
642 | const char *buf, size_t count) | 649 | const char *buf, size_t count) |
643 | { | 650 | { |
644 | struct drm_device *dev = dev_get_drvdata(d); | 651 | struct drm_device *dev = dev_get_drvdata(d); |
645 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 652 | struct nouveau_pm *pm = nouveau_pm(dev); |
646 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
647 | long value; | 653 | long value; |
648 | 654 | ||
649 | if (kstrtol(buf, 10, &value) == -EINVAL) | 655 | if (kstrtol(buf, 10, &value) == -EINVAL) |
@@ -672,8 +678,7 @@ nouveau_hwmon_get_pwm0_max(struct device *d, | |||
672 | struct device_attribute *a, char *buf) | 678 | struct device_attribute *a, char *buf) |
673 | { | 679 | { |
674 | struct drm_device *dev = dev_get_drvdata(d); | 680 | struct drm_device *dev = dev_get_drvdata(d); |
675 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 681 | struct nouveau_pm *pm = nouveau_pm(dev); |
676 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
677 | 682 | ||
678 | return sprintf(buf, "%i\n", pm->fan.max_duty); | 683 | return sprintf(buf, "%i\n", pm->fan.max_duty); |
679 | } | 684 | } |
@@ -683,8 +688,7 @@ nouveau_hwmon_set_pwm0_max(struct device *d, struct device_attribute *a, | |||
683 | const char *buf, size_t count) | 688 | const char *buf, size_t count) |
684 | { | 689 | { |
685 | struct drm_device *dev = dev_get_drvdata(d); | 690 | struct drm_device *dev = dev_get_drvdata(d); |
686 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 691 | struct nouveau_pm *pm = nouveau_pm(dev); |
687 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
688 | long value; | 692 | long value; |
689 | 693 | ||
690 | if (kstrtol(buf, 10, &value) == -EINVAL) | 694 | if (kstrtol(buf, 10, &value) == -EINVAL) |
@@ -741,8 +745,11 @@ static const struct attribute_group hwmon_pwm_fan_attrgroup = { | |||
741 | static int | 745 | static int |
742 | nouveau_hwmon_init(struct drm_device *dev) | 746 | nouveau_hwmon_init(struct drm_device *dev) |
743 | { | 747 | { |
744 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 748 | struct nouveau_pm *pm = nouveau_pm(dev); |
745 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 749 | struct nouveau_drm *drm = nouveau_drm(dev); |
750 | struct nouveau_gpio *gpio = nouveau_gpio(drm->device); | ||
751 | struct dcb_gpio_func func; | ||
752 | |||
746 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) | 753 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) |
747 | struct device *hwmon_dev; | 754 | struct device *hwmon_dev; |
748 | int ret = 0; | 755 | int ret = 0; |
@@ -753,8 +760,7 @@ nouveau_hwmon_init(struct drm_device *dev) | |||
753 | hwmon_dev = hwmon_device_register(&dev->pdev->dev); | 760 | hwmon_dev = hwmon_device_register(&dev->pdev->dev); |
754 | if (IS_ERR(hwmon_dev)) { | 761 | if (IS_ERR(hwmon_dev)) { |
755 | ret = PTR_ERR(hwmon_dev); | 762 | ret = PTR_ERR(hwmon_dev); |
756 | NV_ERROR(dev, | 763 | NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret); |
757 | "Unable to register hwmon device: %d\n", ret); | ||
758 | return ret; | 764 | return ret; |
759 | } | 765 | } |
760 | dev_set_drvdata(hwmon_dev, dev); | 766 | dev_set_drvdata(hwmon_dev, dev); |
@@ -778,7 +784,7 @@ nouveau_hwmon_init(struct drm_device *dev) | |||
778 | } | 784 | } |
779 | 785 | ||
780 | /* if the card can read the fan rpm */ | 786 | /* if the card can read the fan rpm */ |
781 | if (nouveau_gpio_func_valid(dev, DCB_GPIO_FAN_SENSE)) { | 787 | if (!gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func)) { |
782 | ret = sysfs_create_group(&dev->pdev->dev.kobj, | 788 | ret = sysfs_create_group(&dev->pdev->dev.kobj, |
783 | &hwmon_fan_rpm_attrgroup); | 789 | &hwmon_fan_rpm_attrgroup); |
784 | if (ret) | 790 | if (ret) |
@@ -790,7 +796,7 @@ nouveau_hwmon_init(struct drm_device *dev) | |||
790 | return 0; | 796 | return 0; |
791 | 797 | ||
792 | error: | 798 | error: |
793 | NV_ERROR(dev, "Unable to create some hwmon sysfs files: %d\n", ret); | 799 | NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret); |
794 | hwmon_device_unregister(hwmon_dev); | 800 | hwmon_device_unregister(hwmon_dev); |
795 | pm->hwmon = NULL; | 801 | pm->hwmon = NULL; |
796 | return ret; | 802 | return ret; |
@@ -804,8 +810,7 @@ static void | |||
804 | nouveau_hwmon_fini(struct drm_device *dev) | 810 | nouveau_hwmon_fini(struct drm_device *dev) |
805 | { | 811 | { |
806 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) | 812 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) |
807 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 813 | struct nouveau_pm *pm = nouveau_pm(dev); |
808 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
809 | 814 | ||
810 | if (pm->hwmon) { | 815 | if (pm->hwmon) { |
811 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); | 816 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); |
@@ -823,16 +828,15 @@ nouveau_hwmon_fini(struct drm_device *dev) | |||
823 | static int | 828 | static int |
824 | nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data) | 829 | nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data) |
825 | { | 830 | { |
826 | struct drm_nouveau_private *dev_priv = | 831 | struct nouveau_pm *pm = container_of(nb, struct nouveau_pm, acpi_nb); |
827 | container_of(nb, struct drm_nouveau_private, engine.pm.acpi_nb); | 832 | struct nouveau_drm *drm = nouveau_drm(pm->dev); |
828 | struct drm_device *dev = dev_priv->dev; | ||
829 | struct acpi_bus_event *entry = (struct acpi_bus_event *)data; | 833 | struct acpi_bus_event *entry = (struct acpi_bus_event *)data; |
830 | 834 | ||
831 | if (strcmp(entry->device_class, "ac_adapter") == 0) { | 835 | if (strcmp(entry->device_class, "ac_adapter") == 0) { |
832 | bool ac = power_supply_is_system_supplied(); | 836 | bool ac = power_supply_is_system_supplied(); |
833 | 837 | ||
834 | NV_DEBUG(dev, "power supply changed: %s\n", ac ? "AC" : "DC"); | 838 | NV_DEBUG(drm, "power supply changed: %s\n", ac ? "AC" : "DC"); |
835 | nouveau_pm_trigger(dev); | 839 | nouveau_pm_trigger(pm->dev); |
836 | } | 840 | } |
837 | 841 | ||
838 | return NOTIFY_OK; | 842 | return NOTIFY_OK; |
@@ -842,11 +846,72 @@ nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data) | |||
842 | int | 846 | int |
843 | nouveau_pm_init(struct drm_device *dev) | 847 | nouveau_pm_init(struct drm_device *dev) |
844 | { | 848 | { |
845 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 849 | struct nouveau_device *device = nouveau_dev(dev); |
846 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 850 | struct nouveau_drm *drm = nouveau_drm(dev); |
851 | struct nouveau_pm *pm; | ||
847 | char info[256]; | 852 | char info[256]; |
848 | int ret, i; | 853 | int ret, i; |
849 | 854 | ||
855 | pm = drm->pm = kzalloc(sizeof(*pm), GFP_KERNEL); | ||
856 | if (!pm) | ||
857 | return -ENOMEM; | ||
858 | |||
859 | pm->dev = dev; | ||
860 | |||
861 | if (device->card_type < NV_40) { | ||
862 | pm->clocks_get = nv04_pm_clocks_get; | ||
863 | pm->clocks_pre = nv04_pm_clocks_pre; | ||
864 | pm->clocks_set = nv04_pm_clocks_set; | ||
865 | if (nouveau_gpio(drm->device)) { | ||
866 | pm->voltage_get = nouveau_voltage_gpio_get; | ||
867 | pm->voltage_set = nouveau_voltage_gpio_set; | ||
868 | } | ||
869 | } else | ||
870 | if (device->card_type < NV_50) { | ||
871 | pm->clocks_get = nv40_pm_clocks_get; | ||
872 | pm->clocks_pre = nv40_pm_clocks_pre; | ||
873 | pm->clocks_set = nv40_pm_clocks_set; | ||
874 | pm->voltage_get = nouveau_voltage_gpio_get; | ||
875 | pm->voltage_set = nouveau_voltage_gpio_set; | ||
876 | pm->temp_get = nv40_temp_get; | ||
877 | pm->pwm_get = nv40_pm_pwm_get; | ||
878 | pm->pwm_set = nv40_pm_pwm_set; | ||
879 | } else | ||
880 | if (device->card_type < NV_C0) { | ||
881 | if (device->chipset < 0xa3 || | ||
882 | device->chipset == 0xaa || | ||
883 | device->chipset == 0xac) { | ||
884 | pm->clocks_get = nv50_pm_clocks_get; | ||
885 | pm->clocks_pre = nv50_pm_clocks_pre; | ||
886 | pm->clocks_set = nv50_pm_clocks_set; | ||
887 | } else { | ||
888 | pm->clocks_get = nva3_pm_clocks_get; | ||
889 | pm->clocks_pre = nva3_pm_clocks_pre; | ||
890 | pm->clocks_set = nva3_pm_clocks_set; | ||
891 | } | ||
892 | pm->voltage_get = nouveau_voltage_gpio_get; | ||
893 | pm->voltage_set = nouveau_voltage_gpio_set; | ||
894 | if (device->chipset == 0x50) | ||
895 | pm->temp_get = nv40_temp_get; | ||
896 | else | ||
897 | pm->temp_get = nv84_temp_get; | ||
898 | pm->pwm_get = nv50_pm_pwm_get; | ||
899 | pm->pwm_set = nv50_pm_pwm_set; | ||
900 | } else | ||
901 | if (device->card_type < NV_E0) { | ||
902 | pm->clocks_get = nvc0_pm_clocks_get; | ||
903 | pm->clocks_pre = nvc0_pm_clocks_pre; | ||
904 | pm->clocks_set = nvc0_pm_clocks_set; | ||
905 | pm->voltage_get = nouveau_voltage_gpio_get; | ||
906 | pm->voltage_set = nouveau_voltage_gpio_set; | ||
907 | pm->temp_get = nv84_temp_get; | ||
908 | if (device->card_type < NV_D0) { | ||
909 | pm->pwm_get = nv50_pm_pwm_get; | ||
910 | pm->pwm_set = nv50_pm_pwm_set; | ||
911 | } | ||
912 | } | ||
913 | |||
914 | |||
850 | /* parse aux tables from vbios */ | 915 | /* parse aux tables from vbios */ |
851 | nouveau_volt_init(dev); | 916 | nouveau_volt_init(dev); |
852 | nouveau_temp_init(dev); | 917 | nouveau_temp_init(dev); |
@@ -854,7 +919,7 @@ nouveau_pm_init(struct drm_device *dev) | |||
854 | /* determine current ("boot") performance level */ | 919 | /* determine current ("boot") performance level */ |
855 | ret = nouveau_pm_perflvl_get(dev, &pm->boot); | 920 | ret = nouveau_pm_perflvl_get(dev, &pm->boot); |
856 | if (ret) { | 921 | if (ret) { |
857 | NV_ERROR(dev, "failed to determine boot perflvl\n"); | 922 | NV_ERROR(drm, "failed to determine boot perflvl\n"); |
858 | return ret; | 923 | return ret; |
859 | } | 924 | } |
860 | 925 | ||
@@ -874,14 +939,14 @@ nouveau_pm_init(struct drm_device *dev) | |||
874 | nouveau_perf_init(dev); | 939 | nouveau_perf_init(dev); |
875 | 940 | ||
876 | /* display available performance levels */ | 941 | /* display available performance levels */ |
877 | NV_INFO(dev, "%d available performance level(s)\n", pm->nr_perflvl); | 942 | NV_INFO(drm, "%d available performance level(s)\n", pm->nr_perflvl); |
878 | for (i = 0; i < pm->nr_perflvl; i++) { | 943 | for (i = 0; i < pm->nr_perflvl; i++) { |
879 | nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info)); | 944 | nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info)); |
880 | NV_INFO(dev, "%d:%s", pm->perflvl[i].id, info); | 945 | NV_INFO(drm, "%d:%s", pm->perflvl[i].id, info); |
881 | } | 946 | } |
882 | 947 | ||
883 | nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info)); | 948 | nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info)); |
884 | NV_INFO(dev, "c:%s", info); | 949 | NV_INFO(drm, "c:%s", info); |
885 | 950 | ||
886 | /* switch performance levels now if requested */ | 951 | /* switch performance levels now if requested */ |
887 | if (nouveau_perflvl != NULL) | 952 | if (nouveau_perflvl != NULL) |
@@ -903,8 +968,7 @@ nouveau_pm_init(struct drm_device *dev) | |||
903 | void | 968 | void |
904 | nouveau_pm_fini(struct drm_device *dev) | 969 | nouveau_pm_fini(struct drm_device *dev) |
905 | { | 970 | { |
906 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 971 | struct nouveau_pm *pm = nouveau_pm(dev); |
907 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
908 | struct nouveau_pm_profile *profile, *tmp; | 972 | struct nouveau_pm_profile *profile, *tmp; |
909 | 973 | ||
910 | list_for_each_entry_safe(profile, tmp, &pm->profiles, head) { | 974 | list_for_each_entry_safe(profile, tmp, &pm->profiles, head) { |
@@ -924,13 +988,15 @@ nouveau_pm_fini(struct drm_device *dev) | |||
924 | #endif | 988 | #endif |
925 | nouveau_hwmon_fini(dev); | 989 | nouveau_hwmon_fini(dev); |
926 | nouveau_sysfs_fini(dev); | 990 | nouveau_sysfs_fini(dev); |
991 | |||
992 | nouveau_drm(dev)->pm = NULL; | ||
993 | kfree(pm); | ||
927 | } | 994 | } |
928 | 995 | ||
929 | void | 996 | void |
930 | nouveau_pm_resume(struct drm_device *dev) | 997 | nouveau_pm_resume(struct drm_device *dev) |
931 | { | 998 | { |
932 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 999 | struct nouveau_pm *pm = nouveau_pm(dev); |
933 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
934 | struct nouveau_pm_level *perflvl; | 1000 | struct nouveau_pm_level *perflvl; |
935 | 1001 | ||
936 | if (!pm->cur || pm->cur == &pm->boot) | 1002 | if (!pm->cur || pm->cur == &pm->boot) |