regulator: qcom-smd: Add support for PMA8084
[cascardo/linux.git] / drivers / gpu / drm / nouveau / include / nvkm / core / device.h
1 #ifndef __NVKM_DEVICE_H__
2 #define __NVKM_DEVICE_H__
3 #include <core/event.h>
4 #include <core/object.h>
5
6 enum nvkm_devidx {
7         NVKM_SUBDEV_PCI,
8         NVKM_SUBDEV_VBIOS,
9         NVKM_SUBDEV_DEVINIT,
10         NVKM_SUBDEV_IBUS,
11         NVKM_SUBDEV_GPIO,
12         NVKM_SUBDEV_I2C,
13         NVKM_SUBDEV_FUSE,
14         NVKM_SUBDEV_MXM,
15         NVKM_SUBDEV_MC,
16         NVKM_SUBDEV_BUS,
17         NVKM_SUBDEV_TIMER,
18         NVKM_SUBDEV_FB,
19         NVKM_SUBDEV_LTC,
20         NVKM_SUBDEV_INSTMEM,
21         NVKM_SUBDEV_MMU,
22         NVKM_SUBDEV_BAR,
23         NVKM_SUBDEV_PMU,
24         NVKM_SUBDEV_VOLT,
25         NVKM_SUBDEV_THERM,
26         NVKM_SUBDEV_CLK,
27
28         NVKM_ENGINE_DMAOBJ,
29         NVKM_ENGINE_IFB,
30         NVKM_ENGINE_FIFO,
31         NVKM_ENGINE_SW,
32         NVKM_ENGINE_GR,
33         NVKM_ENGINE_MPEG,
34         NVKM_ENGINE_ME,
35         NVKM_ENGINE_VP,
36         NVKM_ENGINE_CIPHER,
37         NVKM_ENGINE_BSP,
38         NVKM_ENGINE_MSPPP,
39         NVKM_ENGINE_CE0,
40         NVKM_ENGINE_CE1,
41         NVKM_ENGINE_CE2,
42         NVKM_ENGINE_VIC,
43         NVKM_ENGINE_MSENC,
44         NVKM_ENGINE_DISP,
45         NVKM_ENGINE_PM,
46         NVKM_ENGINE_MSVLD,
47         NVKM_ENGINE_SEC,
48         NVKM_ENGINE_MSPDEC,
49
50         NVKM_SUBDEV_NR
51 };
52
53 enum nvkm_device_type {
54         NVKM_DEVICE_PCI,
55         NVKM_DEVICE_AGP,
56         NVKM_DEVICE_PCIE,
57         NVKM_DEVICE_TEGRA,
58 };
59
60 struct nvkm_device {
61         const struct nvkm_device_func *func;
62         const struct nvkm_device_quirk *quirk;
63         struct device *dev;
64         enum nvkm_device_type type;
65         u64 handle;
66         const char *name;
67         const char *cfgopt;
68         const char *dbgopt;
69
70         struct list_head head;
71         struct mutex mutex;
72         int refcount;
73
74         void __iomem *pri;
75
76         struct nvkm_event event;
77
78         u64 disable_mask;
79         u32 debug;
80
81         const struct nvkm_device_chip *chip;
82         enum {
83                 NV_04    = 0x04,
84                 NV_10    = 0x10,
85                 NV_11    = 0x11,
86                 NV_20    = 0x20,
87                 NV_30    = 0x30,
88                 NV_40    = 0x40,
89                 NV_50    = 0x50,
90                 NV_C0    = 0xc0,
91                 NV_E0    = 0xe0,
92                 GM100    = 0x110,
93         } card_type;
94         u32 chipset;
95         u8  chiprev;
96         u32 crystal;
97
98         struct {
99                 struct notifier_block nb;
100         } acpi;
101
102         struct nvkm_bar *bar;
103         struct nvkm_bios *bios;
104         struct nvkm_bus *bus;
105         struct nvkm_clk *clk;
106         struct nvkm_devinit *devinit;
107         struct nvkm_fb *fb;
108         struct nvkm_fuse *fuse;
109         struct nvkm_gpio *gpio;
110         struct nvkm_i2c *i2c;
111         struct nvkm_subdev *ibus;
112         struct nvkm_instmem *imem;
113         struct nvkm_ltc *ltc;
114         struct nvkm_mc *mc;
115         struct nvkm_mmu *mmu;
116         struct nvkm_subdev *mxm;
117         struct nvkm_pci *pci;
118         struct nvkm_pmu *pmu;
119         struct nvkm_therm *therm;
120         struct nvkm_timer *timer;
121         struct nvkm_volt *volt;
122
123         struct nvkm_engine *bsp;
124         struct nvkm_engine *ce[3];
125         struct nvkm_engine *cipher;
126         struct nvkm_disp *disp;
127         struct nvkm_dma *dma;
128         struct nvkm_fifo *fifo;
129         struct nvkm_gr *gr;
130         struct nvkm_engine *ifb;
131         struct nvkm_engine *me;
132         struct nvkm_engine *mpeg;
133         struct nvkm_engine *msenc;
134         struct nvkm_engine *mspdec;
135         struct nvkm_engine *msppp;
136         struct nvkm_engine *msvld;
137         struct nvkm_pm *pm;
138         struct nvkm_engine *sec;
139         struct nvkm_sw *sw;
140         struct nvkm_engine *vic;
141         struct nvkm_engine *vp;
142 };
143
144 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int index);
145 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int index);
146
147 struct nvkm_device_func {
148         struct nvkm_device_pci *(*pci)(struct nvkm_device *);
149         struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
150         void *(*dtor)(struct nvkm_device *);
151         int (*preinit)(struct nvkm_device *);
152         int (*init)(struct nvkm_device *);
153         void (*fini)(struct nvkm_device *, bool suspend);
154         resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
155         resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
156         bool cpu_coherent;
157 };
158
159 struct nvkm_device_quirk {
160         u8 tv_pin_mask;
161         u8 tv_gpio;
162         bool War00C800_0;
163 };
164
165 struct nvkm_device_chip {
166         const char *name;
167
168         int (*bar    )(struct nvkm_device *, int idx, struct nvkm_bar **);
169         int (*bios   )(struct nvkm_device *, int idx, struct nvkm_bios **);
170         int (*bus    )(struct nvkm_device *, int idx, struct nvkm_bus **);
171         int (*clk    )(struct nvkm_device *, int idx, struct nvkm_clk **);
172         int (*devinit)(struct nvkm_device *, int idx, struct nvkm_devinit **);
173         int (*fb     )(struct nvkm_device *, int idx, struct nvkm_fb **);
174         int (*fuse   )(struct nvkm_device *, int idx, struct nvkm_fuse **);
175         int (*gpio   )(struct nvkm_device *, int idx, struct nvkm_gpio **);
176         int (*i2c    )(struct nvkm_device *, int idx, struct nvkm_i2c **);
177         int (*ibus   )(struct nvkm_device *, int idx, struct nvkm_subdev **);
178         int (*imem   )(struct nvkm_device *, int idx, struct nvkm_instmem **);
179         int (*ltc    )(struct nvkm_device *, int idx, struct nvkm_ltc **);
180         int (*mc     )(struct nvkm_device *, int idx, struct nvkm_mc **);
181         int (*mmu    )(struct nvkm_device *, int idx, struct nvkm_mmu **);
182         int (*mxm    )(struct nvkm_device *, int idx, struct nvkm_subdev **);
183         int (*pci    )(struct nvkm_device *, int idx, struct nvkm_pci **);
184         int (*pmu    )(struct nvkm_device *, int idx, struct nvkm_pmu **);
185         int (*therm  )(struct nvkm_device *, int idx, struct nvkm_therm **);
186         int (*timer  )(struct nvkm_device *, int idx, struct nvkm_timer **);
187         int (*volt   )(struct nvkm_device *, int idx, struct nvkm_volt **);
188
189         int (*bsp    )(struct nvkm_device *, int idx, struct nvkm_engine **);
190         int (*ce[3]  )(struct nvkm_device *, int idx, struct nvkm_engine **);
191         int (*cipher )(struct nvkm_device *, int idx, struct nvkm_engine **);
192         int (*disp   )(struct nvkm_device *, int idx, struct nvkm_disp **);
193         int (*dma    )(struct nvkm_device *, int idx, struct nvkm_dma **);
194         int (*fifo   )(struct nvkm_device *, int idx, struct nvkm_fifo **);
195         int (*gr     )(struct nvkm_device *, int idx, struct nvkm_gr **);
196         int (*ifb    )(struct nvkm_device *, int idx, struct nvkm_engine **);
197         int (*me     )(struct nvkm_device *, int idx, struct nvkm_engine **);
198         int (*mpeg   )(struct nvkm_device *, int idx, struct nvkm_engine **);
199         int (*msenc  )(struct nvkm_device *, int idx, struct nvkm_engine **);
200         int (*mspdec )(struct nvkm_device *, int idx, struct nvkm_engine **);
201         int (*msppp  )(struct nvkm_device *, int idx, struct nvkm_engine **);
202         int (*msvld  )(struct nvkm_device *, int idx, struct nvkm_engine **);
203         int (*pm     )(struct nvkm_device *, int idx, struct nvkm_pm **);
204         int (*sec    )(struct nvkm_device *, int idx, struct nvkm_engine **);
205         int (*sw     )(struct nvkm_device *, int idx, struct nvkm_sw **);
206         int (*vic    )(struct nvkm_device *, int idx, struct nvkm_engine **);
207         int (*vp     )(struct nvkm_device *, int idx, struct nvkm_engine **);
208 };
209
210 struct nvkm_device *nvkm_device_find(u64 name);
211 int nvkm_device_list(u64 *name, int size);
212
213 /* privileged register interface accessor macros */
214 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
215 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
216 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
217 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
218 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
219 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
220 #define nvkm_mask(d,a,m,v) ({                                                  \
221         struct nvkm_device *_device = (d);                                     \
222         u32 _addr = (a), _temp = nvkm_rd32(_device, _addr);                    \
223         nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v));                       \
224         _temp;                                                                 \
225 })
226
227 void nvkm_device_del(struct nvkm_device **);
228
229 struct nvkm_device_oclass {
230         int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
231                     void *data, u32 size, struct nvkm_object **);
232         struct nvkm_sclass base;
233 };
234
235 extern const struct nvkm_sclass nvkm_udevice_sclass;
236
237 /* device logging */
238 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
239         struct nvkm_device *_device = (d);                                     \
240         if (_device->debug >= (l))                                             \
241                 dev_##p(_device->dev, f, ##a);                                 \
242 } while(0)
243 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
244 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL,   crit, f, ##a)
245 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR,    err, f, ##a)
246 #define nvdev_warn(d,f,a...)  nvdev_printk((d),  WARN, notice, f, ##a)
247 #define nvdev_info(d,f,a...)  nvdev_printk((d),  INFO,   info, f, ##a)
248 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG,   info, f, ##a)
249 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE,   info, f, ##a)
250 #define nvdev_spam(d,f,a...)  nvdev_printk((d),  SPAM,    dbg, f, ##a)
251 #endif