diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2011-06-18 11:44:36 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2011-09-20 02:03:16 -0400 |
commit | 354d0781e5cef1f227ee3064cb65053365177d3b (patch) | |
tree | 37e7604dc519824ff9f5ac985ade470b3caf7d2b /drivers/gpu/drm/nouveau | |
parent | d0f67a48f47a1874622418ba6bc2c45935b01b36 (diff) |
drm/nvc0/pm: initial implementation of clocks_get()
Not too certain on memory clock yet, but it gets the right numbers for
each perflvl on my NVC0.
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau')
-rw-r--r-- | drivers/gpu/drm/nouveau/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_pm.h | 3 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_state.c | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nvc0_pm.c | 145 |
4 files changed, 150 insertions, 1 deletions
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile index 0583677e4581..88213b532bdc 100644 --- a/drivers/gpu/drm/nouveau/Makefile +++ b/drivers/gpu/drm/nouveau/Makefile | |||
@@ -30,7 +30,7 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_channel.o nouveau_mem.o \ | |||
30 | nv04_fbcon.o nv50_fbcon.o nvc0_fbcon.o \ | 30 | nv04_fbcon.o nv50_fbcon.o nvc0_fbcon.o \ |
31 | nv10_gpio.o nv50_gpio.o \ | 31 | nv10_gpio.o nv50_gpio.o \ |
32 | nv50_calc.o \ | 32 | nv50_calc.o \ |
33 | nv04_pm.o nv50_pm.o nva3_pm.o \ | 33 | nv04_pm.o nv50_pm.o nva3_pm.o nvc0_pm.o \ |
34 | nv50_vram.o nvc0_vram.o \ | 34 | nv50_vram.o nvc0_vram.o \ |
35 | nv50_vm.o nvc0_vm.o | 35 | nv50_vm.o nvc0_vm.o |
36 | 36 | ||
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.h b/drivers/gpu/drm/nouveau/nouveau_pm.h index 884bb7f90a18..f519883d9a43 100644 --- a/drivers/gpu/drm/nouveau/nouveau_pm.h +++ b/drivers/gpu/drm/nouveau/nouveau_pm.h | |||
@@ -63,6 +63,9 @@ int nva3_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); | |||
63 | void *nva3_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); | 63 | void *nva3_pm_clocks_pre(struct drm_device *, struct nouveau_pm_level *); |
64 | void nva3_pm_clocks_set(struct drm_device *, void *); | 64 | void nva3_pm_clocks_set(struct drm_device *, void *); |
65 | 65 | ||
66 | /* nvc0_pm.c */ | ||
67 | int nvc0_pm_clocks_get(struct drm_device *, struct nouveau_pm_level *); | ||
68 | |||
66 | /* nouveau_temp.c */ | 69 | /* nouveau_temp.c */ |
67 | void nouveau_temp_init(struct drm_device *dev); | 70 | void nouveau_temp_init(struct drm_device *dev); |
68 | void nouveau_temp_fini(struct drm_device *dev); | 71 | void nouveau_temp_fini(struct drm_device *dev); |
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c index 8dc73b6b8138..109f0d984615 100644 --- a/drivers/gpu/drm/nouveau/nouveau_state.c +++ b/drivers/gpu/drm/nouveau/nouveau_state.c | |||
@@ -422,6 +422,7 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev) | |||
422 | engine->vram.put = nv50_vram_del; | 422 | engine->vram.put = nv50_vram_del; |
423 | engine->vram.flags_valid = nvc0_vram_flags_valid; | 423 | engine->vram.flags_valid = nvc0_vram_flags_valid; |
424 | engine->pm.temp_get = nv84_temp_get; | 424 | engine->pm.temp_get = nv84_temp_get; |
425 | engine->pm.clocks_get = nvc0_pm_clocks_get; | ||
425 | engine->pm.voltage_get = nouveau_voltage_gpio_get; | 426 | engine->pm.voltage_get = nouveau_voltage_gpio_get; |
426 | engine->pm.voltage_set = nouveau_voltage_gpio_set; | 427 | engine->pm.voltage_set = nouveau_voltage_gpio_set; |
427 | break; | 428 | break; |
diff --git a/drivers/gpu/drm/nouveau/nvc0_pm.c b/drivers/gpu/drm/nouveau/nvc0_pm.c new file mode 100644 index 000000000000..aff4426b2408 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nvc0_pm.c | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | * Copyright 2011 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 | */ | ||
24 | |||
25 | #include "drmP.h" | ||
26 | #include "nouveau_drv.h" | ||
27 | #include "nouveau_bios.h" | ||
28 | #include "nouveau_pm.h" | ||
29 | |||
30 | static u32 read_div(struct drm_device *, int, u32, u32); | ||
31 | static u32 read_pll(struct drm_device *, u32); | ||
32 | |||
33 | static u32 | ||
34 | read_vco(struct drm_device *dev, u32 dsrc) | ||
35 | { | ||
36 | u32 ssrc = nv_rd32(dev, dsrc); | ||
37 | if (!(ssrc & 0x00000100)) | ||
38 | return read_pll(dev, 0x00e800); | ||
39 | return read_pll(dev, 0x00e820); | ||
40 | } | ||
41 | |||
42 | static u32 | ||
43 | read_pll(struct drm_device *dev, u32 pll) | ||
44 | { | ||
45 | u32 coef = nv_rd32(dev, pll + 4); | ||
46 | u32 P = (coef & 0x003f0000) >> 16; | ||
47 | u32 N = (coef & 0x0000ff00) >> 8; | ||
48 | u32 M = (coef & 0x000000ff) >> 0; | ||
49 | u32 sclk, doff; | ||
50 | |||
51 | switch (pll & 0xfff000) { | ||
52 | case 0x00e000: | ||
53 | sclk = 27000; | ||
54 | P = 1; | ||
55 | break; | ||
56 | case 0x137000: | ||
57 | doff = (pll - 0x137000) / 0x20; | ||
58 | sclk = read_div(dev, doff, 0x137120, 0x137140); | ||
59 | break; | ||
60 | case 0x132000: | ||
61 | switch (pll) { | ||
62 | case 0x132000: | ||
63 | sclk = read_pll(dev, 0x132020); | ||
64 | break; | ||
65 | case 0x132020: | ||
66 | sclk = read_div(dev, 0, 0x137320, 0x137330); | ||
67 | break; | ||
68 | default: | ||
69 | return 0; | ||
70 | } | ||
71 | break; | ||
72 | default: | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | return sclk * N / M / P; | ||
77 | } | ||
78 | |||
79 | static u32 | ||
80 | read_div(struct drm_device *dev, int doff, u32 dsrc, u32 dctl) | ||
81 | { | ||
82 | u32 ssrc = nv_rd32(dev, dsrc + (doff * 4)); | ||
83 | u32 sctl = nv_rd32(dev, dctl + (doff * 4)); | ||
84 | |||
85 | switch (ssrc & 0x00000003) { | ||
86 | case 0: | ||
87 | if ((ssrc & 0x00030000) != 0x00030000) | ||
88 | return 27000; | ||
89 | return 108000; | ||
90 | case 2: | ||
91 | return 100000; | ||
92 | case 3: | ||
93 | if (sctl & 0x80000000) { | ||
94 | u32 sclk = read_vco(dev, dsrc); | ||
95 | u32 sdiv = (sctl & 0x0000003f) + 2; | ||
96 | return (sclk * 2) / sdiv; | ||
97 | } | ||
98 | |||
99 | return read_vco(dev, dsrc); | ||
100 | default: | ||
101 | return 0; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static u32 | ||
106 | read_mem(struct drm_device *dev) | ||
107 | { | ||
108 | u32 ssel = nv_rd32(dev, 0x1373f0); | ||
109 | if (ssel & 0x00000001) | ||
110 | return read_div(dev, 0, 0x137300, 0x137310); | ||
111 | return read_pll(dev, 0x132000); | ||
112 | } | ||
113 | |||
114 | static u32 | ||
115 | read_clk(struct drm_device *dev, int clk) | ||
116 | { | ||
117 | u32 sctl = nv_rd32(dev, 0x137250 + (clk * 4)); | ||
118 | u32 ssel = nv_rd32(dev, 0x137100); | ||
119 | u32 sclk, sdiv; | ||
120 | |||
121 | if (ssel & (1 << clk)) { | ||
122 | if (clk < 7) | ||
123 | sclk = read_pll(dev, 0x137000 + (clk * 0x20)); | ||
124 | else | ||
125 | sclk = read_pll(dev, 0x1370e0); | ||
126 | sdiv = ((sctl & 0x00003f00) >> 8) + 2; | ||
127 | } else { | ||
128 | sclk = read_div(dev, clk, 0x137160, 0x1371d0); | ||
129 | sdiv = ((sctl & 0x0000003f) >> 0) + 2; | ||
130 | } | ||
131 | |||
132 | if (sctl & 0x80000000) | ||
133 | return (sclk * 2) / sdiv; | ||
134 | return sclk; | ||
135 | } | ||
136 | |||
137 | int | ||
138 | nvc0_pm_clocks_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) | ||
139 | { | ||
140 | perflvl->shader = read_clk(dev, 0x00); | ||
141 | perflvl->core = perflvl->shader / 2; | ||
142 | perflvl->memory = read_mem(dev); | ||
143 | perflvl->vdec = read_clk(dev, 0x0e); | ||
144 | return 0; | ||
145 | } | ||