• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __NOUVEAU_CLOCK_H__
2 #define __NOUVEAU_CLOCK_H__
3 
4 #include <core/device.h>
5 #include <core/subdev.h>
6 
7 struct nouveau_pll_vals;
8 struct nvbios_pll;
9 
10 enum nv_clk_src {
11 	nv_clk_src_crystal,
12 	nv_clk_src_href,
13 
14 	nv_clk_src_hclk,
15 	nv_clk_src_hclkm3,
16 	nv_clk_src_hclkm3d2,
17 	nv_clk_src_hclkm2d3, /* NVAA */
18 	nv_clk_src_hclkm4, /* NVAA */
19 	nv_clk_src_cclk, /* NVAA */
20 
21 	nv_clk_src_host,
22 
23 	nv_clk_src_sppll0,
24 	nv_clk_src_sppll1,
25 
26 	nv_clk_src_mpllsrcref,
27 	nv_clk_src_mpllsrc,
28 	nv_clk_src_mpll,
29 	nv_clk_src_mdiv,
30 
31 	nv_clk_src_core,
32 	nv_clk_src_core_intm,
33 	nv_clk_src_shader,
34 
35 	nv_clk_src_mem,
36 
37 	nv_clk_src_gpc,
38 	nv_clk_src_rop,
39 	nv_clk_src_hubk01,
40 	nv_clk_src_hubk06,
41 	nv_clk_src_hubk07,
42 	nv_clk_src_copy,
43 	nv_clk_src_daemon,
44 	nv_clk_src_disp,
45 	nv_clk_src_vdec,
46 
47 	nv_clk_src_dom6,
48 
49 	nv_clk_src_max,
50 };
51 
52 struct nouveau_cstate {
53 	struct list_head head;
54 	u8  voltage;
55 	u32 domain[nv_clk_src_max];
56 };
57 
58 struct nouveau_pstate {
59 	struct list_head head;
60 	struct list_head list; /* c-states */
61 	struct nouveau_cstate base;
62 	u8 pstate;
63 	u8 fanspeed;
64 };
65 
66 struct nouveau_clock {
67 	struct nouveau_subdev base;
68 
69 	struct nouveau_clocks *domains;
70 	struct nouveau_pstate bstate;
71 
72 	struct list_head states;
73 	int state_nr;
74 
75 	struct work_struct work;
76 	wait_queue_head_t wait;
77 	atomic_t waiting;
78 
79 	struct nvkm_notify pwrsrc_ntfy;
80 	int pwrsrc;
81 	int pstate; /* current */
82 	int ustate_ac; /* user-requested (-1 disabled, -2 perfmon) */
83 	int ustate_dc; /* user-requested (-1 disabled, -2 perfmon) */
84 	int astate; /* perfmon adjustment (base) */
85 	int tstate; /* thermal adjustment (max-) */
86 	int dstate; /* display adjustment (min+) */
87 
88 	bool allow_reclock;
89 
90 	int  (*read)(struct nouveau_clock *, enum nv_clk_src);
91 	int  (*calc)(struct nouveau_clock *, struct nouveau_cstate *);
92 	int  (*prog)(struct nouveau_clock *);
93 	void (*tidy)(struct nouveau_clock *);
94 
95 	/*XXX: die, these are here *only* to support the completely
96 	 *     bat-shit insane what-was-nouveau_hw.c code
97 	 */
98 	int (*pll_calc)(struct nouveau_clock *, struct nvbios_pll *,
99 			int clk, struct nouveau_pll_vals *pv);
100 	int (*pll_prog)(struct nouveau_clock *, u32 reg1,
101 			struct nouveau_pll_vals *pv);
102 };
103 
104 static inline struct nouveau_clock *
nouveau_clock(void * obj)105 nouveau_clock(void *obj)
106 {
107 	return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_CLOCK];
108 }
109 
110 struct nouveau_clocks {
111 	enum nv_clk_src name;
112 	u8 bios; /* 0xff for none */
113 #define NVKM_CLK_DOM_FLAG_CORE 0x01
114 	u8 flags;
115 	const char *mname;
116 	int mdiv;
117 };
118 
119 #define nouveau_clock_create(p,e,o,i,r,s,n,d)                                  \
120 	nouveau_clock_create_((p), (e), (o), (i), (r), (s), (n), sizeof(**d),  \
121 			      (void **)d)
122 #define nouveau_clock_destroy(p) ({                                            \
123 	struct nouveau_clock *clk = (p);                                       \
124 	_nouveau_clock_dtor(nv_object(clk));                                   \
125 })
126 #define nouveau_clock_init(p) ({                                               \
127 	struct nouveau_clock *clk = (p);                                       \
128 	_nouveau_clock_init(nv_object(clk));                                   \
129 })
130 #define nouveau_clock_fini(p,s) ({                                             \
131 	struct nouveau_clock *clk = (p);                                       \
132 	_nouveau_clock_fini(nv_object(clk), (s));                              \
133 })
134 
135 int  nouveau_clock_create_(struct nouveau_object *, struct nouveau_object *,
136 			   struct nouveau_oclass *,
137 			   struct nouveau_clocks *, struct nouveau_pstate *,
138 			   int, bool, int, void **);
139 void _nouveau_clock_dtor(struct nouveau_object *);
140 int  _nouveau_clock_init(struct nouveau_object *);
141 int  _nouveau_clock_fini(struct nouveau_object *, bool);
142 
143 extern struct nouveau_oclass nv04_clock_oclass;
144 extern struct nouveau_oclass nv40_clock_oclass;
145 extern struct nouveau_oclass *nv50_clock_oclass;
146 extern struct nouveau_oclass *nv84_clock_oclass;
147 extern struct nouveau_oclass *nvaa_clock_oclass;
148 extern struct nouveau_oclass nva3_clock_oclass;
149 extern struct nouveau_oclass nvc0_clock_oclass;
150 extern struct nouveau_oclass nve0_clock_oclass;
151 extern struct nouveau_oclass gk20a_clock_oclass;
152 
153 int nv04_clock_pll_set(struct nouveau_clock *, u32 type, u32 freq);
154 int nv04_clock_pll_calc(struct nouveau_clock *, struct nvbios_pll *,
155 			int clk, struct nouveau_pll_vals *);
156 int nv04_clock_pll_prog(struct nouveau_clock *, u32 reg1,
157 			struct nouveau_pll_vals *);
158 int nva3_clock_pll_calc(struct nouveau_clock *, struct nvbios_pll *,
159 			int clk, struct nouveau_pll_vals *);
160 
161 int nouveau_clock_ustate(struct nouveau_clock *, int req, int pwr);
162 int nouveau_clock_astate(struct nouveau_clock *, int req, int rel);
163 int nouveau_clock_dstate(struct nouveau_clock *, int req, int rel);
164 int nouveau_clock_tstate(struct nouveau_clock *, int req, int rel);
165 
166 #endif
167