Merge tag 'arc-v3.13-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-drm-fsl-dcu.git] / drivers / gpu / drm / nouveau / core / include / subdev / clock.h
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
18         nv_clk_src_host,
19
20         nv_clk_src_sppll0,
21         nv_clk_src_sppll1,
22
23         nv_clk_src_mpllsrcref,
24         nv_clk_src_mpllsrc,
25         nv_clk_src_mpll,
26         nv_clk_src_mdiv,
27
28         nv_clk_src_core,
29         nv_clk_src_shader,
30
31         nv_clk_src_mem,
32
33         nv_clk_src_gpc,
34         nv_clk_src_rop,
35         nv_clk_src_hubk01,
36         nv_clk_src_hubk06,
37         nv_clk_src_hubk07,
38         nv_clk_src_copy,
39         nv_clk_src_daemon,
40         nv_clk_src_disp,
41         nv_clk_src_vdec,
42
43         nv_clk_src_dom6,
44
45         nv_clk_src_max,
46 };
47
48 struct nouveau_cstate {
49         struct list_head head;
50         u8  voltage;
51         u32 domain[nv_clk_src_max];
52 };
53
54 struct nouveau_pstate {
55         struct list_head head;
56         struct list_head list; /* c-states */
57         struct nouveau_cstate base;
58         u8 pstate;
59         u8 fanspeed;
60 };
61
62 struct nouveau_clock {
63         struct nouveau_subdev base;
64
65         struct nouveau_clocks *domains;
66         struct nouveau_pstate bstate;
67
68         struct list_head states;
69         int state_nr;
70
71         int pstate; /* current */
72         int ustate; /* user-requested (-1 disabled, -2 perfmon) */
73         int astate; /* perfmon adjustment (base) */
74         int tstate; /* thermal adjustment (max-) */
75         int dstate; /* display adjustment (min+) */
76
77         int  (*read)(struct nouveau_clock *, enum nv_clk_src);
78         int  (*calc)(struct nouveau_clock *, struct nouveau_cstate *);
79         int  (*prog)(struct nouveau_clock *);
80         void (*tidy)(struct nouveau_clock *);
81
82         /*XXX: die, these are here *only* to support the completely
83          *     bat-shit insane what-was-nouveau_hw.c code
84          */
85         int (*pll_calc)(struct nouveau_clock *, struct nvbios_pll *,
86                         int clk, struct nouveau_pll_vals *pv);
87         int (*pll_prog)(struct nouveau_clock *, u32 reg1,
88                         struct nouveau_pll_vals *pv);
89 };
90
91 static inline struct nouveau_clock *
92 nouveau_clock(void *obj)
93 {
94         return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_CLOCK];
95 }
96
97 struct nouveau_clocks {
98         enum nv_clk_src name;
99         u8 bios; /* 0xff for none */
100 #define NVKM_CLK_DOM_FLAG_CORE 0x01
101         u8 flags;
102         const char *mname;
103         int mdiv;
104 };
105
106 #define nouveau_clock_create(p,e,o,i,d)                                        \
107         nouveau_clock_create_((p), (e), (o), (i), sizeof(**d), (void **)d)
108 #define nouveau_clock_destroy(p) ({                                            \
109         struct nouveau_clock *clk = (p);                                       \
110         _nouveau_clock_dtor(nv_object(clk));                                   \
111 })
112 #define nouveau_clock_init(p) ({                                               \
113         struct nouveau_clock *clk = (p);                                       \
114         _nouveau_clock_init(nv_object(clk));                                   \
115 })
116 #define nouveau_clock_fini(p,s)                                                \
117         nouveau_subdev_fini(&(p)->base, (s))
118
119 int  nouveau_clock_create_(struct nouveau_object *, struct nouveau_object *,
120                            struct nouveau_oclass *,
121                            struct nouveau_clocks *, int, void **);
122 void _nouveau_clock_dtor(struct nouveau_object *);
123 int _nouveau_clock_init(struct nouveau_object *);
124 #define _nouveau_clock_fini _nouveau_subdev_fini
125
126 extern struct nouveau_oclass nv04_clock_oclass;
127 extern struct nouveau_oclass nv40_clock_oclass;
128 extern struct nouveau_oclass *nv50_clock_oclass;
129 extern struct nouveau_oclass *nv84_clock_oclass;
130 extern struct nouveau_oclass nva3_clock_oclass;
131 extern struct nouveau_oclass nvc0_clock_oclass;
132 extern struct nouveau_oclass nve0_clock_oclass;
133
134 int nv04_clock_pll_set(struct nouveau_clock *, u32 type, u32 freq);
135 int nv04_clock_pll_calc(struct nouveau_clock *, struct nvbios_pll *,
136                         int clk, struct nouveau_pll_vals *);
137 int nv04_clock_pll_prog(struct nouveau_clock *, u32 reg1,
138                         struct nouveau_pll_vals *);
139 int nva3_clock_pll_calc(struct nouveau_clock *, struct nvbios_pll *,
140                         int clk, struct nouveau_pll_vals *);
141
142 int nouveau_clock_ustate(struct nouveau_clock *, int req);
143 int nouveau_clock_astate(struct nouveau_clock *, int req, int rel);
144 int nouveau_clock_dstate(struct nouveau_clock *, int req, int rel);
145 int nouveau_clock_tstate(struct nouveau_clock *, int req, int rel);
146
147 #endif